提交 31d95b18 编写于 作者: L Laine Stump

conf: parse/format <port isolated='yes|no'/>

This is a very simple thing to parse and format, but needs to be done
in 4 places, so two trivial utility functions have been made that can
be called from all the higher level parser/formatters:

  <domain><interface>
  <domain><interface><actual> (only in domain status)
  <network>
  <networkport>
Signed-off-by: NLaine Stump <laine@redhat.com>
Reviewed-by: NJán Tomko <jtomko@redhat.com>
上级 a378d8fa
...@@ -3178,6 +3178,9 @@ ...@@ -3178,6 +3178,9 @@
<optional> <optional>
<ref name="vlan"/> <ref name="vlan"/>
</optional> </optional>
<optional>
<ref name="portOptions"/>
</optional>
<optional> <optional>
<element name="teaming"> <element name="teaming">
<choice> <choice>
......
...@@ -332,6 +332,9 @@ ...@@ -332,6 +332,9 @@
<optional> <optional>
<ref name="vlan"/> <ref name="vlan"/>
</optional> </optional>
<optional>
<ref name="portOptions"/>
</optional>
<!-- <ip> element --> <!-- <ip> element -->
<zeroOrMore> <zeroOrMore>
......
...@@ -280,4 +280,15 @@ ...@@ -280,4 +280,15 @@
</attribute> </attribute>
</element> </element>
</define> </define>
<define name="portOptions">
<element name="port">
<optional>
<attribute name="isolated">
<ref name="virYesNo"/>
</attribute>
</optional>
</element>
</define>
</grammar> </grammar>
...@@ -32,6 +32,9 @@ ...@@ -32,6 +32,9 @@
<optional> <optional>
<ref name="vlan"/> <ref name="vlan"/>
</optional> </optional>
<optional>
<ref name="portOptions"/>
</optional>
<optional> <optional>
<ref name="plug"/> <ref name="plug"/>
</optional> </optional>
......
...@@ -11534,6 +11534,9 @@ virDomainActualNetDefParseXML(xmlNodePtr node, ...@@ -11534,6 +11534,9 @@ virDomainActualNetDefParseXML(xmlNodePtr node,
if (vlanNode && virNetDevVlanParse(vlanNode, ctxt, &actual->vlan) < 0) if (vlanNode && virNetDevVlanParse(vlanNode, ctxt, &actual->vlan) < 0)
goto error; goto error;
if (virNetworkPortOptionsParseXML(ctxt, &actual->isolatedPort) < 0)
goto error;
*def = g_steal_pointer(&actual); *def = g_steal_pointer(&actual);
ret = 0; ret = 0;
error: error:
...@@ -12430,6 +12433,9 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt, ...@@ -12430,6 +12433,9 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
goto error; goto error;
} }
if (virNetworkPortOptionsParseXML(ctxt, &def->isolatedPort) < 0)
goto error;
cleanup: cleanup:
virDomainActualNetDefFree(actual); virDomainActualNetDefFree(actual);
virHashFree(filterparams); virHashFree(filterparams);
...@@ -25539,6 +25545,7 @@ virDomainActualNetDefContentsFormat(virBufferPtr buf, ...@@ -25539,6 +25545,7 @@ virDomainActualNetDefContentsFormat(virBufferPtr buf,
return -1; return -1;
if (virNetDevBandwidthFormat(virDomainNetGetActualBandwidth(def), 0, buf) < 0) if (virNetDevBandwidthFormat(virDomainNetGetActualBandwidth(def), 0, buf) < 0)
return -1; return -1;
virNetworkPortOptionsFormat(virDomainNetGetActualPortOptionsIsolated(def), buf);
return 0; return 0;
} }
...@@ -25915,6 +25922,7 @@ virDomainNetDefFormat(virBufferPtr buf, ...@@ -25915,6 +25922,7 @@ virDomainNetDefFormat(virBufferPtr buf,
return -1; return -1;
if (virNetDevBandwidthFormat(def->bandwidth, 0, buf) < 0) if (virNetDevBandwidthFormat(def->bandwidth, 0, buf) < 0)
return -1; return -1;
virNetworkPortOptionsFormat(def->isolatedPort, buf);
/* ONLY for internal status storage - format the ActualNetDef /* ONLY for internal status storage - format the ActualNetDef
* as a subelement of <interface> so that no persistent config * as a subelement of <interface> so that no persistent config
...@@ -29992,6 +30000,17 @@ virDomainNetGetActualVlan(const virDomainNetDef *iface) ...@@ -29992,6 +30000,17 @@ virDomainNetGetActualVlan(const virDomainNetDef *iface)
} }
virTristateBool
virDomainNetGetActualPortOptionsIsolated(const virDomainNetDef *iface)
{
if (iface->type == VIR_DOMAIN_NET_TYPE_NETWORK &&
iface->data.network.actual) {
return iface->data.network.actual->isolatedPort;
}
return iface->isolatedPort;
}
bool bool
virDomainNetGetActualTrustGuestRxFilters(const virDomainNetDef *iface) virDomainNetGetActualTrustGuestRxFilters(const virDomainNetDef *iface)
{ {
......
...@@ -928,6 +928,7 @@ struct _virDomainActualNetDef { ...@@ -928,6 +928,7 @@ struct _virDomainActualNetDef {
virNetDevBandwidthPtr bandwidth; virNetDevBandwidthPtr bandwidth;
virNetDevVlan vlan; virNetDevVlan vlan;
int trustGuestRxFilters; /* enum virTristateBool */ int trustGuestRxFilters; /* enum virTristateBool */
virTristateBool isolatedPort;
unsigned int class_id; /* class ID for bandwidth 'floor' */ unsigned int class_id; /* class ID for bandwidth 'floor' */
}; };
...@@ -1032,6 +1033,7 @@ struct _virDomainNetDef { ...@@ -1032,6 +1033,7 @@ struct _virDomainNetDef {
virNetDevBandwidthPtr bandwidth; virNetDevBandwidthPtr bandwidth;
virNetDevVlan vlan; virNetDevVlan vlan;
int trustGuestRxFilters; /* enum virTristateBool */ int trustGuestRxFilters; /* enum virTristateBool */
virTristateBool isolatedPort;
int linkstate; int linkstate;
unsigned int mtu; unsigned int mtu;
virNetDevCoalescePtr coalesce; virNetDevCoalescePtr coalesce;
...@@ -3239,6 +3241,8 @@ const virNetDevBandwidth * ...@@ -3239,6 +3241,8 @@ const virNetDevBandwidth *
virDomainNetGetActualBandwidth(const virDomainNetDef *iface); virDomainNetGetActualBandwidth(const virDomainNetDef *iface);
const virNetDevVlan *virDomainNetGetActualVlan(const virDomainNetDef *iface); const virNetDevVlan *virDomainNetGetActualVlan(const virDomainNetDef *iface);
bool virDomainNetGetActualTrustGuestRxFilters(const virDomainNetDef *iface); bool virDomainNetGetActualTrustGuestRxFilters(const virDomainNetDef *iface);
virTristateBool
virDomainNetGetActualPortOptionsIsolated(const virDomainNetDef *iface);
const char *virDomainNetGetModelString(const virDomainNetDef *net); const char *virDomainNetGetModelString(const virDomainNetDef *net);
int virDomainNetSetModelString(virDomainNetDefPtr et, int virDomainNetSetModelString(virDomainNetDefPtr et,
const char *model); const char *model);
......
...@@ -1172,6 +1172,26 @@ virNetworkIPDefParseXML(const char *networkName, ...@@ -1172,6 +1172,26 @@ virNetworkIPDefParseXML(const char *networkName,
} }
int
virNetworkPortOptionsParseXML(xmlXPathContextPtr ctxt,
virTristateBool *isolatedPort)
{
g_autofree char *str = NULL;
int tmp = VIR_TRISTATE_BOOL_ABSENT;
if ((str = virXPathString("string(./port/@isolated)", ctxt))) {
if ((tmp = virTristateBoolTypeFromString(str)) <= 0) {
virReportError(VIR_ERR_XML_ERROR,
_("unknown port isolated value '%s'"), str);
return -1;
}
}
*isolatedPort = tmp;
return 0;
}
static int static int
virNetworkPortGroupParseXML(virPortGroupDefPtr def, virNetworkPortGroupParseXML(virPortGroupDefPtr def,
xmlNodePtr node, xmlNodePtr node,
...@@ -1725,6 +1745,9 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt, ...@@ -1725,6 +1745,9 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt,
if (vlanNode && virNetDevVlanParse(vlanNode, ctxt, &def->vlan) < 0) if (vlanNode && virNetDevVlanParse(vlanNode, ctxt, &def->vlan) < 0)
goto error; goto error;
if (virNetworkPortOptionsParseXML(ctxt, &def->isolatedPort) < 0)
goto error;
/* Parse bridge information */ /* Parse bridge information */
def->bridge = virXPathString("string(./bridge[1]/@name)", ctxt); def->bridge = virXPathString("string(./bridge[1]/@name)", ctxt);
def->bridgeZone = virXPathString("string(./bridge[1]/@zone)", ctxt); def->bridgeZone = virXPathString("string(./bridge[1]/@zone)", ctxt);
...@@ -2331,6 +2354,14 @@ virNetworkIPDefFormat(virBufferPtr buf, ...@@ -2331,6 +2354,14 @@ virNetworkIPDefFormat(virBufferPtr buf,
return 0; return 0;
} }
void
virNetworkPortOptionsFormat(virTristateBool isolatedPort,
virBufferPtr buf)
{
if (isolatedPort != VIR_TRISTATE_BOOL_ABSENT)
virBufferAsprintf(buf, "<port isolated='%s'/>\n",
virTristateBoolTypeToString(isolatedPort));
}
static int static int
virPortGroupDefFormat(virBufferPtr buf, virPortGroupDefFormat(virBufferPtr buf,
...@@ -2608,6 +2639,7 @@ virNetworkDefFormatBuf(virBufferPtr buf, ...@@ -2608,6 +2639,7 @@ virNetworkDefFormatBuf(virBufferPtr buf,
return -1; return -1;
if (virNetDevBandwidthFormat(def->bandwidth, 0, buf) < 0) if (virNetDevBandwidthFormat(def->bandwidth, 0, buf) < 0)
return -1; return -1;
virNetworkPortOptionsFormat(def->isolatedPort, buf);
for (i = 0; i < def->nips; i++) { for (i = 0; i < def->nips; i++) {
if (virNetworkIPDefFormat(buf, &def->ips[i]) < 0) if (virNetworkIPDefFormat(buf, &def->ips[i]) < 0)
......
...@@ -272,6 +272,7 @@ struct _virNetworkDef { ...@@ -272,6 +272,7 @@ struct _virNetworkDef {
virNetDevBandwidthPtr bandwidth; virNetDevBandwidthPtr bandwidth;
virNetDevVlan vlan; virNetDevVlan vlan;
int trustGuestRxFilters; /* enum virTristateBool */ int trustGuestRxFilters; /* enum virTristateBool */
virTristateBool isolatedPort;
/* Application-specific custom metadata */ /* Application-specific custom metadata */
xmlNodePtr metadata; xmlNodePtr metadata;
...@@ -377,6 +378,14 @@ virNetworkConfigFile(const char *dir, ...@@ -377,6 +378,14 @@ virNetworkConfigFile(const char *dir,
void void
virNetworkSetBridgeMacAddr(virNetworkDefPtr def); virNetworkSetBridgeMacAddr(virNetworkDefPtr def);
int
virNetworkPortOptionsParseXML(xmlXPathContextPtr ctxt,
virTristateBool *isolatedPort);
void
virNetworkPortOptionsFormat(virTristateBool isolatedPort,
virBufferPtr buf);
VIR_ENUM_DECL(virNetworkForward); VIR_ENUM_DECL(virNetworkForward);
#define VIR_CONNECT_LIST_NETWORKS_FILTERS_ACTIVE \ #define VIR_CONNECT_LIST_NETWORKS_FILTERS_ACTIVE \
......
...@@ -161,6 +161,8 @@ virNetworkPortDefParseXML(xmlXPathContextPtr ctxt) ...@@ -161,6 +161,8 @@ virNetworkPortDefParseXML(xmlXPathContextPtr ctxt)
if (vlanNode && virNetDevVlanParse(vlanNode, ctxt, &def->vlan) < 0) if (vlanNode && virNetDevVlanParse(vlanNode, ctxt, &def->vlan) < 0)
return NULL; return NULL;
if (virNetworkPortOptionsParseXML(ctxt, &def->isolatedPort) < 0)
return NULL;
trustGuestRxFilters trustGuestRxFilters
= virXPathString("string(./rxfilters/@trustGuest)", ctxt); = virXPathString("string(./rxfilters/@trustGuest)", ctxt);
...@@ -360,6 +362,7 @@ virNetworkPortDefFormatBuf(virBufferPtr buf, ...@@ -360,6 +362,7 @@ virNetworkPortDefFormatBuf(virBufferPtr buf,
virNetDevBandwidthFormat(def->bandwidth, def->class_id, buf); virNetDevBandwidthFormat(def->bandwidth, def->class_id, buf);
if (virNetDevVlanFormat(&def->vlan, buf) < 0) if (virNetDevVlanFormat(&def->vlan, buf) < 0)
return -1; return -1;
virNetworkPortOptionsFormat(def->isolatedPort, buf);
if (def->trustGuestRxFilters) if (def->trustGuestRxFilters)
virBufferAsprintf(buf, "<rxfilters trustGuest='%s'/>\n", virBufferAsprintf(buf, "<rxfilters trustGuest='%s'/>\n",
virTristateBoolTypeToString(def->trustGuestRxFilters)); virTristateBoolTypeToString(def->trustGuestRxFilters));
......
...@@ -60,6 +60,7 @@ struct _virNetworkPortDef { ...@@ -60,6 +60,7 @@ struct _virNetworkPortDef {
unsigned int class_id; /* class ID for bandwidth 'floor' */ unsigned int class_id; /* class ID for bandwidth 'floor' */
virNetDevVlan vlan; virNetDevVlan vlan;
int trustGuestRxFilters; /* enum virTristateBool */ int trustGuestRxFilters; /* enum virTristateBool */
virTristateBool isolatedPort;
int plugtype; /* virNetworkPortPlugType */ int plugtype; /* virNetworkPortPlugType */
union { union {
......
...@@ -513,6 +513,7 @@ virDomainNetGetActualBridgeName; ...@@ -513,6 +513,7 @@ virDomainNetGetActualBridgeName;
virDomainNetGetActualDirectDev; virDomainNetGetActualDirectDev;
virDomainNetGetActualDirectMode; virDomainNetGetActualDirectMode;
virDomainNetGetActualHostdev; virDomainNetGetActualHostdev;
virDomainNetGetActualPortOptionsIsolated;
virDomainNetGetActualTrustGuestRxFilters; virDomainNetGetActualTrustGuestRxFilters;
virDomainNetGetActualType; virDomainNetGetActualType;
virDomainNetGetActualVirtPortProfile; virDomainNetGetActualVirtPortProfile;
......
<network>
<name>port-isolation-test</name>
<uuid>81ff0d90-c91e-6742-64da-4a736edb9a9b</uuid>
<bridge name="br0"/>
<forward mode="bridge"/>
<port isolated="yes"/>
</network>
<network>
<name>port-isolation-test</name>
<uuid>81ff0d90-c91e-6742-64da-4a736edb9a9b</uuid>
<forward mode='bridge'/>
<bridge name='br0'/>
<port isolated='yes'/>
</network>
...@@ -160,6 +160,7 @@ mymain(void) ...@@ -160,6 +160,7 @@ mymain(void)
DO_TEST("metadata"); DO_TEST("metadata");
DO_TEST("set-mtu"); DO_TEST("set-mtu");
DO_TEST("dnsmasq-options"); DO_TEST("dnsmasq-options");
DO_TEST("isolated-ports");
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
} }
......
<domain type='qemu'>
<name>q35-test</name>
<uuid>11dbdcdd-4c3b-482b-8903-9bdb8c0a2774</uuid>
<memory unit='KiB'>2097152</memory>
<currentMemory unit='KiB'>2097152</currentMemory>
<vcpu placement='static' cpuset='0-1'>2</vcpu>
<os>
<type arch='x86_64' machine='q35'>hvm</type>
<boot dev='hd'/>
</os>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
<emulator>/usr/bin/qemu-system-x86_64</emulator>
<disk type='block' device='disk'>
<source dev='/dev/HostVG/QEMUGuest1'/>
<target dev='sda' bus='sata'/>
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
</disk>
<controller type='pci' index='0' model='pcie-root'/>
<interface type='network'>
<mac address='52:54:00:d6:c0:0b'/>
<source network='default'/>
<port isolated='yes'/>
<model type='virtio'/>
</interface>
<video>
<model type='qxl' ram='65536' vram='32768' vgamem='8192' heads='1'/>
</video>
<memballoon model='none'/>
</devices>
</domain>
<domain type='qemu'>
<name>q35-test</name>
<uuid>11dbdcdd-4c3b-482b-8903-9bdb8c0a2774</uuid>
<memory unit='KiB'>2097152</memory>
<currentMemory unit='KiB'>2097152</currentMemory>
<vcpu placement='static' cpuset='0-1'>2</vcpu>
<os>
<type arch='x86_64' machine='q35'>hvm</type>
<boot dev='hd'/>
</os>
<cpu mode='custom' match='exact' check='none'>
<model fallback='forbid'>qemu64</model>
</cpu>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
<emulator>/usr/bin/qemu-system-x86_64</emulator>
<disk type='block' device='disk'>
<driver name='qemu' type='raw'/>
<source dev='/dev/HostVG/QEMUGuest1'/>
<target dev='sda' bus='sata'/>
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
</disk>
<controller type='pci' index='0' model='pcie-root'/>
<controller type='usb' index='0' model='qemu-xhci'>
<address type='pci' domain='0x0000' bus='0x02' slot='0x00' function='0x0'/>
</controller>
<controller type='sata' index='0'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x1f' function='0x2'/>
</controller>
<controller type='pci' index='1' model='pcie-root-port'>
<model name='pcie-root-port'/>
<target chassis='1' port='0x10'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0' multifunction='on'/>
</controller>
<controller type='pci' index='2' model='pcie-root-port'>
<model name='pcie-root-port'/>
<target chassis='2' port='0x11'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x1'/>
</controller>
<controller type='pci' index='3' model='pcie-root-port'>
<model name='pcie-root-port'/>
<target chassis='3' port='0x12'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x2'/>
</controller>
<interface type='network'>
<mac address='52:54:00:d6:c0:0b'/>
<source network='default'/>
<port isolated='yes'/>
<model type='virtio'/>
<address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
</interface>
<input type='mouse' bus='ps2'/>
<input type='keyboard' bus='ps2'/>
<video>
<model type='qxl' ram='65536' vram='32768' vgamem='8192' heads='1' primary='yes'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x0'/>
</video>
<memballoon model='none'/>
</devices>
</domain>
...@@ -463,6 +463,7 @@ mymain(void) ...@@ -463,6 +463,7 @@ mymain(void)
DO_TEST("net-virtio-teaming-network", DO_TEST("net-virtio-teaming-network",
QEMU_CAPS_VIRTIO_NET_FAILOVER, QEMU_CAPS_VIRTIO_NET_FAILOVER,
QEMU_CAPS_DEVICE_VFIO_PCI); QEMU_CAPS_DEVICE_VFIO_PCI);
DO_TEST_CAPS_LATEST("net-isolated-port");
DO_TEST("net-hostdev", NONE); DO_TEST("net-hostdev", NONE);
DO_TEST("net-hostdev-bootorder", NONE); DO_TEST("net-hostdev-bootorder", NONE);
DO_TEST("net-hostdev-vfio", QEMU_CAPS_DEVICE_VFIO_PCI); DO_TEST("net-hostdev-vfio", QEMU_CAPS_DEVICE_VFIO_PCI);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册