From 85f915d8be58dfdbab40cc3e971ea89a76e8d058 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Date: Mon, 3 Sep 2018 17:33:22 +0100 Subject: [PATCH] network: unconditionally merge port profiles MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit All but one of the network types supports port profiles. Rather than duplicating the code to merge profiles 3 times, do it once and then later report an error if used from the wrong place. Reviewed-by: Laine Stump Signed-off-by: Daniel P. Berrangé --- src/network/bridge_driver.c | 54 +++++++++++++++---------------------- 1 file changed, 21 insertions(+), 33 deletions(-) diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index f824b8b4f3..b49558b021 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -4469,6 +4469,18 @@ networkAllocateActualDevice(virNetworkPtr net, iface->data.network.actual->trustGuestRxFilters = netdef->trustGuestRxFilters; + /* merge virtualports from interface, network, and portgroup to + * arrive at actual virtualport to use + */ + if (virNetDevVPortProfileMerge3(&iface->data.network.actual->virtPortProfile, + iface->virtPortProfile, + netdef->virtPortProfile, + portgroup + ? portgroup->virtPortProfile : NULL) < 0) { + goto error; + } + virtport = iface->data.network.actual->virtPortProfile; + switch ((virNetworkForwardType) netdef->forward.type) { case VIR_NETWORK_FORWARD_NONE: case VIR_NETWORK_FORWARD_NAT: @@ -4491,6 +4503,15 @@ networkAllocateActualDevice(virNetworkPtr net, iface->data.network.actual->data.bridge.macTableManager = netdef->macTableManager; + if (virtport) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _(" not supported for network " + "'%s' which uses IP forwarding"), + virNetDevVPortTypeToString(virtport->virtPortType), + netdef->name); + goto error; + } + if (networkPlugBandwidth(obj, iface) < 0) goto error; break; @@ -4543,17 +4564,6 @@ networkAllocateActualDevice(virNetworkPtr net, iface->data.network.actual->data.hostdev.def.source.subsys.u.pci.backend = backend; - /* merge virtualports from interface, network, and portgroup to - * arrive at actual virtualport to use - */ - if (virNetDevVPortProfileMerge3(&iface->data.network.actual->virtPortProfile, - iface->virtPortProfile, - netdef->virtPortProfile, - portgroup - ? portgroup->virtPortProfile : NULL) < 0) { - goto error; - } - virtport = iface->data.network.actual->virtPortProfile; if (virtport) { /* make sure type is supported for hostdev connections */ if (virtport->virtPortType != VIR_NETDEV_VPORT_PROFILE_8021QBG && @@ -4583,17 +4593,6 @@ networkAllocateActualDevice(virNetworkPtr net, iface->data.network.actual->data.bridge.macTableManager = netdef->macTableManager; - /* merge virtualports from interface, network, and portgroup to - * arrive at actual virtualport to use - */ - if (virNetDevVPortProfileMerge3(&iface->data.network.actual->virtPortProfile, - iface->virtPortProfile, - netdef->virtPortProfile, - portgroup - ? portgroup->virtPortProfile : NULL) < 0) { - goto error; - } - virtport = iface->data.network.actual->virtPortProfile; if (virtport) { /* only type='openvswitch' is allowed for bridges */ if (virtport->virtPortType != VIR_NETDEV_VPORT_PROFILE_OPENVSWITCH) { @@ -4632,17 +4631,6 @@ networkAllocateActualDevice(virNetworkPtr net, iface->data.network.actual->data.direct.mode = virNetDevMacVLanModeTypeFromString(virNetworkForwardTypeToString(netdef->forward.type)); - /* merge virtualports from interface, network, and portgroup to - * arrive at actual virtualport to use - */ - if (virNetDevVPortProfileMerge3(&iface->data.network.actual->virtPortProfile, - iface->virtPortProfile, - netdef->virtPortProfile, - portgroup - ? portgroup->virtPortProfile : NULL) < 0) { - goto error; - } - virtport = iface->data.network.actual->virtPortProfile; if (virtport) { /* make sure type is supported for macvtap connections */ if (virtport->virtPortType != VIR_NETDEV_VPORT_PROFILE_8021QBG &&