From nobody Mon Apr 29 13:23:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1532059290074309.94078376483446; Thu, 19 Jul 2018 21:01:30 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 577F4307D869; Fri, 20 Jul 2018 04:01:21 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D728E608E0; Fri, 20 Jul 2018 04:01:18 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 563264A460; Fri, 20 Jul 2018 04:01:14 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6K41BoA014108 for ; Fri, 20 Jul 2018 00:01:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id 91042177B2; Fri, 20 Jul 2018 04:01:11 +0000 (UTC) Received: from mx1.redhat.com (ext-mx08.extmail.prod.ext.phx2.redhat.com [10.5.110.32]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 82EEA16EC1 for ; Fri, 20 Jul 2018 04:01:08 +0000 (UTC) Received: from mout.gmx.net (mout.gmx.net [212.227.17.21]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2FAB4C057FA8 for ; Fri, 20 Jul 2018 04:01:05 +0000 (UTC) Received: from localhost.localdomain ([58.56.27.130]) by mail.gmx.com (mrgmx102 [212.227.17.174]) with ESMTPSA (Nemesis) id 0LbPza-1gRGvX1zuk-00kyYY; Fri, 20 Jul 2018 06:01:02 +0200 From: Shi Lei To: libvir-list@redhat.com Date: Fri, 20 Jul 2018 12:00:53 +0800 Message-Id: <1532059253-21899-1-git-send-email-shilei.massclouds@gmx.com> X-Provags-ID: V03:K1:sak1tHnDzfZpxZqD+o89vD9aDx0UK8T9Uz7Bf34W5GUSjNw2fvk FFnVmmgX7d8g3kHPLxEvZc2GZjHg38Z2QRSRyJPVWcG6E3iS1dFX0F7uUC8RAqAcSQfqTp7 WUU5+OF6xXNpBobmgX7ttHSLL5c2YO5yQg3AvA+TYh1GnxcfRPu3XvaxD+5AfpIQx7tW23N gOF8Zsc+hzLYfUYx/xETQ== X-UI-Out-Filterresults: notjunk:1;V01:K0:DfWkzbrtbIs=:69KPq/BdJH0EwasRIkYon/ cmyYx9GuIRVistMfpipCxq2BnP5yye/YvftpLBDDu2bXgY+jT/iUoIzNX2x5uqmdaEuvzJnUN n8tzb/V5yX1fSeF3GZvF/NTwJ/1ldbe39yjePWASENOv9hh6Sr32RZzZgZoKxe4o8UmDiNmZN WeBl2N4IJysa3vrZMJIozwFVpe5MrM6BhOxskpeYnUJJWEWyRM33U5XHeQ2eTO999OUXjdjc5 H13iMo3wLNqk2nLIET4jN4galx1EHTiPz2cExt7QreiAg3eTr9PdnBzl8vLi+fqXcZjhgyQyS 99mkZcJowcja8SMvyzsDWHp1SBpIdyfwJtsIqy//7Vwm6sL0c8jFeOj5cQSs35C8GXja8FVBk nKicDESBkPlAwXbo3C8ANDVxatvyckB17200C69TDThGVsPav2buvUN79ilqXOYWr44p2iN9w YT9K46GSCoK20irMwqjZX1NGPSi0fJ37EJuQGeSJWpe7wA2cTDvjUt1kb7qoZueIBBOP3QBQh bzKDRonWKDQkU940Z4jXKrVC5ORnZhSrUXi5L2cAhhYNATeIGk5xIIbIDNC2s0B3mMaZynZsv Jra1pNlOtmhqz/NZCrqerKvnMyOMDHyBXjooI88UQrcYnM/Dt+ldAB/3vRSE4lJ73IRFT/lSY eLbIRA3aMmyxyQiXKNF8xxEzqPvy7gGSBpWTDZcvavYXzlhZZX9qYQmTmjl7i/zRDhKaDbuBR fFh1HKcrbqfZc6TtojSxUf4tz1Eq954qglhFpenqplIp/7NdHIPcaJ67yEI= X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 207 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 20 Jul 2018 04:01:06 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 20 Jul 2018 04:01:06 +0000 (UTC) for IP:'212.227.17.21' DOMAIN:'mout.gmx.net' HELO:'mout.gmx.net' FROM:'shilei.massclouds@gmx.com' RCPT:'' X-RedHat-Spam-Score: -0.7 (FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS) 212.227.17.21 mout.gmx.net 212.227.17.21 mout.gmx.net X-Scanned-By: MIMEDefang 2.78 on 10.5.110.32 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Cc: Shi Lei Subject: [libvirt] [PATCH] replace 'if' type conditions with 'switch' for VIR_NETWORK_FORWARD_* X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Fri, 20 Jul 2018 04:01:27 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Hi, everyone! For VIR_NETWORK_FORWARD_*, I try to replace 'if' type conditions with typed 'switch()'. It might be more clear. Signed-off-by: Shi Lei --- src/conf/domain_conf.c | 46 +++++----- src/conf/network_conf.c | 49 ++++++----- src/conf/virnetworkobj.c | 15 ++-- src/esx/esx_network_driver.c | 8 +- src/network/bridge_driver.c | 203 +++++++++++++++++++++++----------------= ---- 5 files changed, 178 insertions(+), 143 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 178c6d2..c02543f 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -29975,40 +29975,44 @@ virDomainNetResolveActualType(virDomainNetDefPtr = iface) if (!(def =3D virNetworkDefParseString(xml))) goto cleanup; =20 - if ((def->forward.type =3D=3D VIR_NETWORK_FORWARD_NONE) || - (def->forward.type =3D=3D VIR_NETWORK_FORWARD_NAT) || - (def->forward.type =3D=3D VIR_NETWORK_FORWARD_ROUTE) || - (def->forward.type =3D=3D VIR_NETWORK_FORWARD_OPEN)) { + switch (def->forward.type) { + case VIR_NETWORK_FORWARD_NONE: + case VIR_NETWORK_FORWARD_NAT: + case VIR_NETWORK_FORWARD_ROUTE: + case VIR_NETWORK_FORWARD_OPEN: /* for these forward types, the actual net type really *is* * NETWORK; we just keep the info from the portgroup in * iface->data.network.actual */ ret =3D VIR_DOMAIN_NET_TYPE_NETWORK; + break; =20 - } else if ((def->forward.type =3D=3D VIR_NETWORK_FORWARD_BRIDGE) && - def->bridge) { - - /* - * is VIR_DOMAIN_NET_TYPE_BRIDGE - */ - - ret =3D VIR_DOMAIN_NET_TYPE_BRIDGE; - - } else if (def->forward.type =3D=3D VIR_NETWORK_FORWARD_HOSTDEV) { - + case VIR_NETWORK_FORWARD_HOSTDEV: ret =3D VIR_DOMAIN_NET_TYPE_HOSTDEV; + break; + + case VIR_NETWORK_FORWARD_BRIDGE: + if (def->bridge) { + /* + * is VIR_DOMAIN_NET_TYPE_BRIDGE + */ + ret =3D VIR_DOMAIN_NET_TYPE_BRIDGE; + break; + } =20 - } else if ((def->forward.type =3D=3D VIR_NETWORK_FORWARD_BRIDGE) || - (def->forward.type =3D=3D VIR_NETWORK_FORWARD_PRIVATE) || - (def->forward.type =3D=3D VIR_NETWORK_FORWARD_VEPA) || - (def->forward.type =3D=3D VIR_NETWORK_FORWARD_PASSTHROUGH))= { + /* intentionally fall through to the direct case for + * VIR_NETWORK_FORWARD_BRIDGE with no bridge device defined + */ + ATTRIBUTE_FALLTHROUGH; =20 + case VIR_NETWORK_FORWARD_PRIVATE: + case VIR_NETWORK_FORWARD_VEPA: + case VIR_NETWORK_FORWARD_PASSTHROUGH: /* are all * VIR_DOMAIN_NET_TYPE_DIRECT. */ - ret =3D VIR_DOMAIN_NET_TYPE_DIRECT; - + break; } =20 cleanup: diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index 630a87f..bafc1d3 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -1959,17 +1959,22 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt) =20 VIR_FREE(stp); =20 - if (def->mtu && - (def->forward.type !=3D VIR_NETWORK_FORWARD_NONE && - def->forward.type !=3D VIR_NETWORK_FORWARD_NAT && - def->forward.type !=3D VIR_NETWORK_FORWARD_ROUTE && - def->forward.type !=3D VIR_NETWORK_FORWARD_OPEN)) { - virReportError(VIR_ERR_XML_ERROR, - _("mtu size only allowed in open, route, nat, " - "and isolated mode, not in %s (network '%s')"), - virNetworkForwardTypeToString(def->forward.type), - def->name); - goto error; + if (def->mtu) { + switch (def->forward.type) { + case VIR_NETWORK_FORWARD_NONE: + case VIR_NETWORK_FORWARD_NAT: + case VIR_NETWORK_FORWARD_ROUTE: + case VIR_NETWORK_FORWARD_OPEN: + break; + + default: + virReportError(VIR_ERR_XML_ERROR, + _("mtu size only allowed in open, route, nat, " + "and isolated mode, not in %s (network '%s')"= ), + virNetworkForwardTypeToString(def->forward.type= ), + def->name); + goto error; + } } =20 /* Extract custom metadata */ @@ -2349,6 +2354,7 @@ virNetworkDefFormatBuf(virBufferPtr buf, char uuidstr[VIR_UUID_STRING_BUFLEN]; size_t i; bool shortforward; + bool hasbridge =3D false; =20 virBufferAddLit(buf, "connections > 0)) @@ -2469,22 +2475,21 @@ virNetworkDefFormatBuf(virBufferPtr buf, virBufferAddLit(buf, "\n"); } =20 + switch (def->forward.type) { + case VIR_NETWORK_FORWARD_NONE: + case VIR_NETWORK_FORWARD_NAT: + case VIR_NETWORK_FORWARD_ROUTE: + case VIR_NETWORK_FORWARD_OPEN: + hasbridge =3D true; + break; + } =20 - if (def->forward.type =3D=3D VIR_NETWORK_FORWARD_NONE || - def->forward.type =3D=3D VIR_NETWORK_FORWARD_NAT || - def->forward.type =3D=3D VIR_NETWORK_FORWARD_ROUTE || - def->forward.type =3D=3D VIR_NETWORK_FORWARD_OPEN || - def->bridge || def->macTableManager) { - + if (hasbridge || def->bridge || def->macTableManager) { virBufferAddLit(buf, "bridge); - if (def->forward.type =3D=3D VIR_NETWORK_FORWARD_NONE || - def->forward.type =3D=3D VIR_NETWORK_FORWARD_NAT || - def->forward.type =3D=3D VIR_NETWORK_FORWARD_ROUTE || - def->forward.type =3D=3D VIR_NETWORK_FORWARD_OPEN) { + if (hasbridge) virBufferAsprintf(buf, " stp=3D'%s' delay=3D'%ld'", def->stp ? "on" : "off", def->delay); - } if (def->macTableManager) { virBufferAsprintf(buf, " macTableManager=3D'%s'", virNetworkBridgeMACTableManagerTypeToString(d= ef->macTableManager)); diff --git a/src/conf/virnetworkobj.c b/src/conf/virnetworkobj.c index e00c8a7..7706817 100644 --- a/src/conf/virnetworkobj.c +++ b/src/conf/virnetworkobj.c @@ -1009,19 +1009,22 @@ virNetworkLoadConfig(virNetworkObjListPtr nets, goto error; } =20 - if (def->forward.type =3D=3D VIR_NETWORK_FORWARD_NONE || - def->forward.type =3D=3D VIR_NETWORK_FORWARD_NAT || - def->forward.type =3D=3D VIR_NETWORK_FORWARD_ROUTE || - def->forward.type =3D=3D VIR_NETWORK_FORWARD_OPEN) { - + switch (def->forward.type) { + case VIR_NETWORK_FORWARD_NONE: + case VIR_NETWORK_FORWARD_NAT: + case VIR_NETWORK_FORWARD_ROUTE: + case VIR_NETWORK_FORWARD_OPEN: if (!def->mac_specified) { virNetworkSetBridgeMacAddr(def); virNetworkSaveConfig(configDir, def); } - } else { + break; + + default: /* Throw away MAC address for other forward types, * which could have been generated by older libvirt RPMs */ def->mac_specified =3D false; + break; } =20 if (!(obj =3D virNetworkObjAssignDef(nets, def, 0))) diff --git a/src/esx/esx_network_driver.c b/src/esx/esx_network_driver.c index 04118b4..8ea1079 100644 --- a/src/esx/esx_network_driver.c +++ b/src/esx/esx_network_driver.c @@ -326,8 +326,12 @@ esxNetworkDefineXML(virConnectPtr conn, const char *xm= l) } =20 /* FIXME: Add support for NAT */ - if (def->forward.type !=3D VIR_NETWORK_FORWARD_NONE && - def->forward.type !=3D VIR_NETWORK_FORWARD_BRIDGE) { + switch (def->forward.type) { + case VIR_NETWORK_FORWARD_NONE: + case VIR_NETWORK_FORWARD_BRIDGE: + break; + + default: virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Unsupported forward mode '%s'"), virNetworkForwardTypeToString(def->forward.type)); diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index da3c32e..5e885b5 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -2088,19 +2088,22 @@ networkRefreshDaemonsHelper(virNetworkObjPtr obj, =20 virObjectLock(obj); def =3D virNetworkObjGetDef(obj); - if (virNetworkObjIsActive(obj) && - ((def->forward.type =3D=3D VIR_NETWORK_FORWARD_NONE) || - (def->forward.type =3D=3D VIR_NETWORK_FORWARD_NAT) || - (def->forward.type =3D=3D VIR_NETWORK_FORWARD_ROUTE) || - (def->forward.type =3D=3D VIR_NETWORK_FORWARD_OPEN))) { - /* Only the three L3 network types that are configured by - * libvirt will have a dnsmasq or radvd daemon associated - * with them. Here we send a SIGHUP to an existing - * dnsmasq and/or radvd, or restart them if they've - * disappeared. - */ - networkRefreshDhcpDaemon(driver, obj); - networkRefreshRadvd(driver, obj); + if (virNetworkObjIsActive(obj)) { + switch (def->forward.type) { + case VIR_NETWORK_FORWARD_NONE: + case VIR_NETWORK_FORWARD_NAT: + case VIR_NETWORK_FORWARD_ROUTE: + case VIR_NETWORK_FORWARD_OPEN: + /* Only the three L3 network types that are configured by + * libvirt will have a dnsmasq or radvd daemon associated + * with them. Here we send a SIGHUP to an existing + * dnsmasq and/or radvd, or restart them if they've + * disappeared. + */ + networkRefreshDhcpDaemon(driver, obj); + networkRefreshRadvd(driver, obj); + break; + } } virObjectUnlock(obj); return 0; @@ -2128,18 +2131,21 @@ networkReloadFirewallRulesHelper(virNetworkObjPtr o= bj, =20 virObjectLock(obj); def =3D virNetworkObjGetDef(obj); - if (virNetworkObjIsActive(obj) && - ((def->forward.type =3D=3D VIR_NETWORK_FORWARD_NONE) || - (def->forward.type =3D=3D VIR_NETWORK_FORWARD_NAT) || - (def->forward.type =3D=3D VIR_NETWORK_FORWARD_ROUTE))) { - /* Only three of the L3 network types that are configured by - * libvirt need to have iptables rules reloaded. The 4th L3 - * network type, forward=3D'open', doesn't need this because it - * has no iptables rules. - */ - networkRemoveFirewallRules(def); - if (networkAddFirewallRules(def) < 0) { - /* failed to add but already logged */ + if (virNetworkObjIsActive(obj)) { + switch (def->forward.type) { + case VIR_NETWORK_FORWARD_NONE: + case VIR_NETWORK_FORWARD_NAT: + case VIR_NETWORK_FORWARD_ROUTE: + /* Only three of the L3 network types that are configured by + * libvirt need to have iptables rules reloaded. The 4th L3 + * network type, forward=3D'open', doesn't need this because it + * has no iptables rules. + */ + networkRemoveFirewallRules(def); + if (networkAddFirewallRules(def) < 0) { + /* failed to add but already logged */ + } + break; } } virObjectUnlock(obj); @@ -3273,11 +3279,11 @@ networkValidate(virNetworkDriverStatePtr driver, /* Only the three L3 network types that are configured by libvirt * need to have a bridge device name / mac address provided */ - if (def->forward.type =3D=3D VIR_NETWORK_FORWARD_NONE || - def->forward.type =3D=3D VIR_NETWORK_FORWARD_NAT || - def->forward.type =3D=3D VIR_NETWORK_FORWARD_ROUTE || - def->forward.type =3D=3D VIR_NETWORK_FORWARD_OPEN) { - + switch (def->forward.type) { + case VIR_NETWORK_FORWARD_NONE: + case VIR_NETWORK_FORWARD_NAT: + case VIR_NETWORK_FORWARD_ROUTE: + case VIR_NETWORK_FORWARD_OPEN: /* if no bridge name was given in the config, find a name * unused by any other libvirt networks and assign it. */ @@ -3285,7 +3291,9 @@ networkValidate(virNetworkDriverStatePtr driver, return -1; =20 virNetworkSetBridgeMacAddr(def); - } else { + break; + + default: /* They are also the only types that currently support setting * a MAC or IP address for the host-side device (bridge), DNS * configuration, or network-wide bandwidth limits. @@ -3331,6 +3339,7 @@ networkValidate(virNetworkDriverStatePtr driver, return -1; } bandwidthAllowed =3D false; + break; } =20 /* we support configs with a single PF defined: @@ -3755,9 +3764,10 @@ networkUpdate(virNetworkPtr net, /* Take care of anything that must be done before updating the * live NetworkDef. */ - if (def->forward.type =3D=3D VIR_NETWORK_FORWARD_NONE || - def->forward.type =3D=3D VIR_NETWORK_FORWARD_NAT || - def->forward.type =3D=3D VIR_NETWORK_FORWARD_ROUTE) { + switch (def->forward.type) { + case VIR_NETWORK_FORWARD_NONE: + case VIR_NETWORK_FORWARD_NAT: + case VIR_NETWORK_FORWARD_ROUTE: switch (section) { case VIR_NETWORK_SECTION_FORWARD: case VIR_NETWORK_SECTION_FORWARD_INTERFACE: @@ -3768,14 +3778,13 @@ networkUpdate(virNetworkPtr net, * old rules (and remember to load new ones after the * update). */ - if (def->forward.type !=3D VIR_NETWORK_FORWARD_OPEN) { - networkRemoveFirewallRules(def); - needFirewallRefresh =3D true; - } + networkRemoveFirewallRules(def); + needFirewallRefresh =3D true; break; default: break; } + break; } } =20 @@ -4440,10 +4449,11 @@ networkAllocateActualDevice(virDomainDefPtr dom, iface->data.network.actual->trustGuestRxFilters =3D netdef->trustGuestRxFilters; =20 - if ((netdef->forward.type =3D=3D VIR_NETWORK_FORWARD_NONE) || - (netdef->forward.type =3D=3D VIR_NETWORK_FORWARD_NAT) || - (netdef->forward.type =3D=3D VIR_NETWORK_FORWARD_ROUTE) || - (netdef->forward.type =3D=3D VIR_NETWORK_FORWARD_OPEN)) { + switch (netdef->forward.type) { + case VIR_NETWORK_FORWARD_NONE: + case VIR_NETWORK_FORWARD_NAT: + case VIR_NETWORK_FORWARD_ROUTE: + case VIR_NETWORK_FORWARD_OPEN: /* for these forward types, the actual net type really *is* * NETWORK; we just keep the info from the portgroup in * iface->data.network.actual @@ -4463,46 +4473,9 @@ networkAllocateActualDevice(virDomainDefPtr dom, =20 if (networkPlugBandwidth(obj, iface) < 0) goto error; + break; =20 - } else if ((netdef->forward.type =3D=3D VIR_NETWORK_FORWARD_BRIDGE) && - netdef->bridge) { - - /* - * is VIR_DOMAIN_NET_TYPE_BRIDGE - */ - - iface->data.network.actual->type =3D actualType =3D VIR_DOMAIN_NET= _TYPE_BRIDGE; - if (VIR_STRDUP(iface->data.network.actual->data.bridge.brname, - netdef->bridge) < 0) - goto error; - iface->data.network.actual->data.bridge.macTableManager - =3D netdef->macTableManager; - - /* merge virtualports from interface, network, and portgroup to - * arrive at actual virtualport to use - */ - if (virNetDevVPortProfileMerge3(&iface->data.network.actual->virtP= ortProfile, - iface->virtPortProfile, - netdef->virtPortProfile, - portgroup - ? portgroup->virtPortProfile : NUL= L) < 0) { - goto error; - } - virtport =3D iface->data.network.actual->virtPortProfile; - if (virtport) { - /* only type=3D'openvswitch' is allowed for bridges */ - if (virtport->virtPortType !=3D VIR_NETDEV_VPORT_PROFILE_OPENV= SWITCH) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _(" not supported = for network " - "'%s' which uses a bridge device"), - virNetDevVPortTypeToString(virtport->virtPo= rtType), - netdef->name); - goto error; - } - } - - } else if (netdef->forward.type =3D=3D VIR_NETWORK_FORWARD_HOSTDEV) { - + case VIR_NETWORK_FORWARD_HOSTDEV: { virDomainHostdevSubsysPCIBackendType backend; =20 iface->data.network.actual->type =3D actualType =3D VIR_DOMAIN_NET= _TYPE_HOSTDEV; @@ -4575,12 +4548,55 @@ networkAllocateActualDevice(virDomainDefPtr dom, goto error; } } + break; + } + + case VIR_NETWORK_FORWARD_BRIDGE: + if (netdef->bridge) { + /* + * is VIR_DOMAIN_NET_TYPE_BRIDGE + */ + + iface->data.network.actual->type =3D actualType =3D VIR_DOMAIN= _NET_TYPE_BRIDGE; + if (VIR_STRDUP(iface->data.network.actual->data.bridge.brname, + netdef->bridge) < 0) + goto error; + iface->data.network.actual->data.bridge.macTableManager + =3D netdef->macTableManager; + + /* merge virtualports from interface, network, and portgroup to + * arrive at actual virtualport to use + */ + if (virNetDevVPortProfileMerge3(&iface->data.network.actual->v= irtPortProfile, + iface->virtPortProfile, + netdef->virtPortProfile, + portgroup + ? portgroup->virtPortProfile := NULL) < 0) { + goto error; + } + virtport =3D iface->data.network.actual->virtPortProfile; + if (virtport) { + /* only type=3D'openvswitch' is allowed for bridges */ + if (virtport->virtPortType !=3D VIR_NETDEV_VPORT_PROFILE_O= PENVSWITCH) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _(" not suppor= ted for network " + "'%s' which uses a bridge device"), + virNetDevVPortTypeToString(virtport->vi= rtPortType), + netdef->name); + goto error; + } + } + break; + } =20 - } else if ((netdef->forward.type =3D=3D VIR_NETWORK_FORWARD_BRIDGE) || - (netdef->forward.type =3D=3D VIR_NETWORK_FORWARD_PRIVATE) || - (netdef->forward.type =3D=3D VIR_NETWORK_FORWARD_VEPA) || - (netdef->forward.type =3D=3D VIR_NETWORK_FORWARD_PASSTHROUG= H)) { + /* intentionally fall through to the direct case for + * VIR_NETWORK_FORWARD_BRIDGE with no bridge device defined + */ + ATTRIBUTE_FALLTHROUGH; =20 + case VIR_NETWORK_FORWARD_PRIVATE: + case VIR_NETWORK_FORWARD_VEPA: + case VIR_NETWORK_FORWARD_PASSTHROUGH: /* are all * VIR_DOMAIN_NET_TYPE_DIRECT. */ @@ -4680,6 +4696,7 @@ networkAllocateActualDevice(virDomainDefPtr dom, dev->device.dev) < 0) goto error; } + break; } =20 if (virNetworkObjMacMgrAdd(obj, driver->dnsmasqStateDir, @@ -5037,13 +5054,15 @@ networkReleaseActualDevice(virDomainDefPtr dom, } netdef =3D virNetworkObjGetDef(obj); =20 - if (iface->data.network.actual && - (netdef->forward.type =3D=3D VIR_NETWORK_FORWARD_NONE || - netdef->forward.type =3D=3D VIR_NETWORK_FORWARD_NAT || - netdef->forward.type =3D=3D VIR_NETWORK_FORWARD_ROUTE || - netdef->forward.type =3D=3D VIR_NETWORK_FORWARD_OPEN) && - networkUnplugBandwidth(obj, iface) < 0) - goto error; + switch (netdef->forward.type) { + case VIR_NETWORK_FORWARD_NONE: + case VIR_NETWORK_FORWARD_NAT: + case VIR_NETWORK_FORWARD_ROUTE: + case VIR_NETWORK_FORWARD_OPEN: + if (iface->data.network.actual && networkUnplugBandwidth(obj, ifac= e) < 0) + goto error; + break; + } =20 if ((!iface->data.network.actual) || ((actualType !=3D VIR_DOMAIN_NET_TYPE_DIRECT) && --=20 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list