mirror of https://gitee.com/openkylin/libvirt.git
Allow network capabilities hostdev to configure IP addresses
This commit is contained in:
parent
12a75f371c
commit
2811cc611e
|
@ -4330,6 +4330,14 @@ qemu-kvm -net nic,model=? /dev/null
|
|||
<target dev='vnet0'/>
|
||||
<b><ip family='ipv4' address='192.168.122.5' prefix='24'/></b>
|
||||
</interface>
|
||||
...
|
||||
<hostdev mode='capabilities' type='net'>
|
||||
<source>
|
||||
<interface>eth0</interface>
|
||||
</source>
|
||||
<b><ip family='ipv4' address='192.168.122.6' prefix='24'/></b>
|
||||
</hostdev>
|
||||
|
||||
</devices>
|
||||
...
|
||||
</pre>
|
||||
|
|
|
@ -3808,11 +3808,31 @@
|
|||
<attribute name="type">
|
||||
<value>net</value>
|
||||
</attribute>
|
||||
<element name="source">
|
||||
<element name="interface">
|
||||
<ref name="deviceName"/>
|
||||
<interleave>
|
||||
<element name="source">
|
||||
<element name="interface">
|
||||
<ref name="deviceName"/>
|
||||
</element>
|
||||
</element>
|
||||
</element>
|
||||
<zeroOrMore>
|
||||
<element name="ip">
|
||||
<attribute name="address">
|
||||
<ref name="ipAddr"/>
|
||||
</attribute>
|
||||
<optional>
|
||||
<attribute name="family">
|
||||
<ref name="addr-family"/>
|
||||
</attribute>
|
||||
</optional>
|
||||
<optional>
|
||||
<attribute name="prefix">
|
||||
<ref name="ipPrefix"/>
|
||||
</attribute>
|
||||
</optional>
|
||||
<empty/>
|
||||
</element>
|
||||
</zeroOrMore>
|
||||
</interleave>
|
||||
</define>
|
||||
|
||||
<define name="usbproduct">
|
||||
|
|
|
@ -1818,6 +1818,8 @@ virDomainHostdevSubsysSCSIiSCSIClear(virDomainHostdevSubsysSCSIiSCSIPtr iscsisrc
|
|||
|
||||
void virDomainHostdevDefClear(virDomainHostdevDefPtr def)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if (!def)
|
||||
return;
|
||||
|
||||
|
@ -1842,6 +1844,9 @@ void virDomainHostdevDefClear(virDomainHostdevDefPtr def)
|
|||
break;
|
||||
case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET:
|
||||
VIR_FREE(def->source.caps.u.net.iface);
|
||||
for (i = 0; i < def->source.caps.u.net.nips; i++)
|
||||
VIR_FREE(def->source.caps.u.net.ips[i]);
|
||||
VIR_FREE(def->source.caps.u.net.ips);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
@ -4833,6 +4838,8 @@ virDomainHostdevDefParseXMLCaps(xmlNodePtr node ATTRIBUTE_UNUSED,
|
|||
virDomainHostdevDefPtr def)
|
||||
{
|
||||
xmlNodePtr sourcenode;
|
||||
xmlNodePtr *ipnodes = NULL;
|
||||
int nipnodes;
|
||||
int ret = -1;
|
||||
|
||||
/* @type is passed in from the caller rather than read from the
|
||||
|
@ -4887,6 +4894,26 @@ virDomainHostdevDefParseXMLCaps(xmlNodePtr node ATTRIBUTE_UNUSED,
|
|||
_("Missing <interface> element in hostdev net device"));
|
||||
goto error;
|
||||
}
|
||||
|
||||
/* Parse possible IP addresses */
|
||||
if ((nipnodes = virXPathNodeSet("./ip", ctxt, &ipnodes)) < 0)
|
||||
goto error;
|
||||
|
||||
if (nipnodes) {
|
||||
size_t i;
|
||||
for (i = 0; i < nipnodes; i++) {
|
||||
virDomainNetIpDefPtr ip = virDomainNetIpParseXML(ipnodes[i]);
|
||||
|
||||
if (!ip)
|
||||
goto error;
|
||||
|
||||
if (VIR_APPEND_ELEMENT(def->source.caps.u.net.ips,
|
||||
def->source.caps.u.net.nips, ip) < 0) {
|
||||
VIR_FREE(ip);
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||
|
@ -4896,6 +4923,7 @@ virDomainHostdevDefParseXMLCaps(xmlNodePtr node ATTRIBUTE_UNUSED,
|
|||
}
|
||||
ret = 0;
|
||||
error:
|
||||
VIR_FREE(ipnodes);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -17302,6 +17330,12 @@ virDomainHostdevDefFormatCaps(virBufferPtr buf,
|
|||
|
||||
virBufferAdjustIndent(buf, -2);
|
||||
virBufferAddLit(buf, "</source>\n");
|
||||
|
||||
if (def->source.caps.type == VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET) {
|
||||
virDomainNetIpsFormat(buf, def->source.caps.u.net.ips,
|
||||
def->source.caps.u.net.nips);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -498,6 +498,8 @@ struct _virDomainHostdevCaps {
|
|||
} misc;
|
||||
struct {
|
||||
char *iface;
|
||||
size_t nips;
|
||||
virDomainNetIpDefPtr *ips;
|
||||
} net;
|
||||
} u;
|
||||
};
|
||||
|
|
|
@ -35,6 +35,8 @@
|
|||
<source>
|
||||
<interface>eth0</interface>
|
||||
</source>
|
||||
<ip address='192.168.122.2' family='ipv4'/>
|
||||
<ip address='2003:db8:1:0:214:1234:fe0b:3596' family='ipv6' prefix='24'/>
|
||||
</hostdev>
|
||||
</devices>
|
||||
</domain>
|
||||
|
|
Loading…
Reference in New Issue