mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 11:31:16 +00:00
network: Use 'switch' control statement with virNetworkForwardType enum
With 'switch' we can utilize the compile time enum checks which we can't rely on with plain 'if' conditions. Signed-off-by: Shi Lei <shilei.massclouds@gmx.com> Reviewed-by: Erik Skultety <eskultet@redhat.com>
This commit is contained in:
parent
a1450d774f
commit
7564daca8a
@ -29975,40 +29975,49 @@ virDomainNetResolveActualType(virDomainNetDefPtr iface)
|
||||
if (!(def = virNetworkDefParseString(xml)))
|
||||
goto cleanup;
|
||||
|
||||
if ((def->forward.type == VIR_NETWORK_FORWARD_NONE) ||
|
||||
(def->forward.type == VIR_NETWORK_FORWARD_NAT) ||
|
||||
(def->forward.type == VIR_NETWORK_FORWARD_ROUTE) ||
|
||||
(def->forward.type == VIR_NETWORK_FORWARD_OPEN)) {
|
||||
switch ((virNetworkForwardType) 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 = VIR_DOMAIN_NET_TYPE_NETWORK;
|
||||
break;
|
||||
|
||||
} else if ((def->forward.type == VIR_NETWORK_FORWARD_BRIDGE) &&
|
||||
def->bridge) {
|
||||
|
||||
/* <forward type='bridge'/> <bridge name='xxx'/>
|
||||
* is VIR_DOMAIN_NET_TYPE_BRIDGE
|
||||
*/
|
||||
|
||||
ret = VIR_DOMAIN_NET_TYPE_BRIDGE;
|
||||
|
||||
} else if (def->forward.type == VIR_NETWORK_FORWARD_HOSTDEV) {
|
||||
|
||||
case VIR_NETWORK_FORWARD_HOSTDEV:
|
||||
ret = VIR_DOMAIN_NET_TYPE_HOSTDEV;
|
||||
break;
|
||||
|
||||
} else if ((def->forward.type == VIR_NETWORK_FORWARD_BRIDGE) ||
|
||||
(def->forward.type == VIR_NETWORK_FORWARD_PRIVATE) ||
|
||||
(def->forward.type == VIR_NETWORK_FORWARD_VEPA) ||
|
||||
(def->forward.type == VIR_NETWORK_FORWARD_PASSTHROUGH)) {
|
||||
case VIR_NETWORK_FORWARD_BRIDGE:
|
||||
if (def->bridge) {
|
||||
/* <forward type='bridge'/> <bridge name='xxx'/>
|
||||
* is VIR_DOMAIN_NET_TYPE_BRIDGE
|
||||
*/
|
||||
ret = VIR_DOMAIN_NET_TYPE_BRIDGE;
|
||||
break;
|
||||
}
|
||||
|
||||
/* intentionally fall through to the direct case for
|
||||
* VIR_NETWORK_FORWARD_BRIDGE with no bridge device defined
|
||||
*/
|
||||
ATTRIBUTE_FALLTHROUGH;
|
||||
|
||||
case VIR_NETWORK_FORWARD_PRIVATE:
|
||||
case VIR_NETWORK_FORWARD_VEPA:
|
||||
case VIR_NETWORK_FORWARD_PASSTHROUGH:
|
||||
/* <forward type='bridge|private|vepa|passthrough'> are all
|
||||
* VIR_DOMAIN_NET_TYPE_DIRECT.
|
||||
*/
|
||||
|
||||
ret = VIR_DOMAIN_NET_TYPE_DIRECT;
|
||||
break;
|
||||
|
||||
case VIR_NETWORK_FORWARD_LAST:
|
||||
default:
|
||||
virReportEnumRangeError(virNetworkForwardType, def->forward.type);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
cleanup:
|
||||
|
@ -1874,7 +1874,7 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt)
|
||||
/* Validate some items in the main NetworkDef that need to align
|
||||
* with the chosen forward mode.
|
||||
*/
|
||||
switch (def->forward.type) {
|
||||
switch ((virNetworkForwardType) def->forward.type) {
|
||||
case VIR_NETWORK_FORWARD_NONE:
|
||||
break;
|
||||
|
||||
@ -1955,21 +1955,40 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt)
|
||||
goto error;
|
||||
}
|
||||
break;
|
||||
|
||||
case VIR_NETWORK_FORWARD_LAST:
|
||||
default:
|
||||
virReportEnumRangeError(virNetworkForwardType, def->forward.type);
|
||||
goto error;
|
||||
}
|
||||
|
||||
VIR_FREE(stp);
|
||||
|
||||
if (def->mtu &&
|
||||
(def->forward.type != VIR_NETWORK_FORWARD_NONE &&
|
||||
def->forward.type != VIR_NETWORK_FORWARD_NAT &&
|
||||
def->forward.type != VIR_NETWORK_FORWARD_ROUTE &&
|
||||
def->forward.type != 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 ((virNetworkForwardType) def->forward.type) {
|
||||
case VIR_NETWORK_FORWARD_NONE:
|
||||
case VIR_NETWORK_FORWARD_NAT:
|
||||
case VIR_NETWORK_FORWARD_ROUTE:
|
||||
case VIR_NETWORK_FORWARD_OPEN:
|
||||
break;
|
||||
|
||||
case VIR_NETWORK_FORWARD_BRIDGE:
|
||||
case VIR_NETWORK_FORWARD_PRIVATE:
|
||||
case VIR_NETWORK_FORWARD_VEPA:
|
||||
case VIR_NETWORK_FORWARD_PASSTHROUGH:
|
||||
case VIR_NETWORK_FORWARD_HOSTDEV:
|
||||
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;
|
||||
|
||||
case VIR_NETWORK_FORWARD_LAST:
|
||||
default:
|
||||
virReportEnumRangeError(virNetworkForwardType, def->forward.type);
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
|
||||
/* Extract custom metadata */
|
||||
@ -2349,6 +2368,7 @@ virNetworkDefFormatBuf(virBufferPtr buf,
|
||||
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
||||
size_t i;
|
||||
bool shortforward;
|
||||
bool hasbridge = false;
|
||||
|
||||
virBufferAddLit(buf, "<network");
|
||||
if (!(flags & VIR_NETWORK_XML_INACTIVE) && (def->connections > 0))
|
||||
@ -2469,22 +2489,33 @@ virNetworkDefFormatBuf(virBufferPtr buf,
|
||||
virBufferAddLit(buf, "</forward>\n");
|
||||
}
|
||||
|
||||
switch ((virNetworkForwardType) def->forward.type) {
|
||||
case VIR_NETWORK_FORWARD_NONE:
|
||||
case VIR_NETWORK_FORWARD_NAT:
|
||||
case VIR_NETWORK_FORWARD_ROUTE:
|
||||
case VIR_NETWORK_FORWARD_OPEN:
|
||||
hasbridge = true;
|
||||
break;
|
||||
|
||||
if (def->forward.type == VIR_NETWORK_FORWARD_NONE ||
|
||||
def->forward.type == VIR_NETWORK_FORWARD_NAT ||
|
||||
def->forward.type == VIR_NETWORK_FORWARD_ROUTE ||
|
||||
def->forward.type == VIR_NETWORK_FORWARD_OPEN ||
|
||||
def->bridge || def->macTableManager) {
|
||||
case VIR_NETWORK_FORWARD_BRIDGE:
|
||||
case VIR_NETWORK_FORWARD_PRIVATE:
|
||||
case VIR_NETWORK_FORWARD_VEPA:
|
||||
case VIR_NETWORK_FORWARD_PASSTHROUGH:
|
||||
case VIR_NETWORK_FORWARD_HOSTDEV:
|
||||
break;
|
||||
|
||||
case VIR_NETWORK_FORWARD_LAST:
|
||||
default:
|
||||
virReportEnumRangeError(virNetworkForwardType, def->forward.type);
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (hasbridge || def->bridge || def->macTableManager) {
|
||||
virBufferAddLit(buf, "<bridge");
|
||||
virBufferEscapeString(buf, " name='%s'", def->bridge);
|
||||
if (def->forward.type == VIR_NETWORK_FORWARD_NONE ||
|
||||
def->forward.type == VIR_NETWORK_FORWARD_NAT ||
|
||||
def->forward.type == VIR_NETWORK_FORWARD_ROUTE ||
|
||||
def->forward.type == VIR_NETWORK_FORWARD_OPEN) {
|
||||
if (hasbridge)
|
||||
virBufferAsprintf(buf, " stp='%s' delay='%ld'",
|
||||
def->stp ? "on" : "off", def->delay);
|
||||
}
|
||||
if (def->macTableManager) {
|
||||
virBufferAsprintf(buf, " macTableManager='%s'",
|
||||
virNetworkBridgeMACTableManagerTypeToString(def->macTableManager));
|
||||
|
@ -1009,19 +1009,31 @@ virNetworkLoadConfig(virNetworkObjListPtr nets,
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (def->forward.type == VIR_NETWORK_FORWARD_NONE ||
|
||||
def->forward.type == VIR_NETWORK_FORWARD_NAT ||
|
||||
def->forward.type == VIR_NETWORK_FORWARD_ROUTE ||
|
||||
def->forward.type == VIR_NETWORK_FORWARD_OPEN) {
|
||||
|
||||
switch ((virNetworkForwardType) 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;
|
||||
|
||||
case VIR_NETWORK_FORWARD_BRIDGE:
|
||||
case VIR_NETWORK_FORWARD_PRIVATE:
|
||||
case VIR_NETWORK_FORWARD_VEPA:
|
||||
case VIR_NETWORK_FORWARD_PASSTHROUGH:
|
||||
case VIR_NETWORK_FORWARD_HOSTDEV:
|
||||
/* Throw away MAC address for other forward types,
|
||||
* which could have been generated by older libvirt RPMs */
|
||||
def->mac_specified = false;
|
||||
break;
|
||||
|
||||
case VIR_NETWORK_FORWARD_LAST:
|
||||
default:
|
||||
virReportEnumRangeError(virNetworkForwardType, def->forward.type);
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (!(obj = virNetworkObjAssignDef(nets, def, 0)))
|
||||
|
@ -326,12 +326,27 @@ esxNetworkDefineXML(virConnectPtr conn, const char *xml)
|
||||
}
|
||||
|
||||
/* FIXME: Add support for NAT */
|
||||
if (def->forward.type != VIR_NETWORK_FORWARD_NONE &&
|
||||
def->forward.type != VIR_NETWORK_FORWARD_BRIDGE) {
|
||||
switch ((virNetworkForwardType) def->forward.type) {
|
||||
case VIR_NETWORK_FORWARD_NONE:
|
||||
case VIR_NETWORK_FORWARD_BRIDGE:
|
||||
break;
|
||||
|
||||
case VIR_NETWORK_FORWARD_NAT:
|
||||
case VIR_NETWORK_FORWARD_ROUTE:
|
||||
case VIR_NETWORK_FORWARD_OPEN:
|
||||
case VIR_NETWORK_FORWARD_PRIVATE:
|
||||
case VIR_NETWORK_FORWARD_VEPA:
|
||||
case VIR_NETWORK_FORWARD_PASSTHROUGH:
|
||||
case VIR_NETWORK_FORWARD_HOSTDEV:
|
||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||
_("Unsupported forward mode '%s'"),
|
||||
virNetworkForwardTypeToString(def->forward.type));
|
||||
goto cleanup;
|
||||
|
||||
case VIR_NETWORK_FORWARD_LAST:
|
||||
default:
|
||||
virReportEnumRangeError(virNetworkForwardType, def->forward.type);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
/* Verify that specified HostPortGroups don't exist already */
|
||||
|
@ -2369,6 +2369,7 @@ virNetDevMacVLanCreate;
|
||||
virNetDevMacVLanCreateWithVPortProfile;
|
||||
virNetDevMacVLanDelete;
|
||||
virNetDevMacVLanDeleteWithVPortProfile;
|
||||
virNetDevMacVLanModeTypeFromString;
|
||||
virNetDevMacVLanReleaseName;
|
||||
virNetDevMacVLanReserveName;
|
||||
virNetDevMacVLanRestartWithVPortProfile;
|
||||
|
@ -446,7 +446,7 @@ networkUpdateState(virNetworkObjPtr obj,
|
||||
}
|
||||
def = virNetworkObjGetDef(obj);
|
||||
|
||||
switch (def->forward.type) {
|
||||
switch ((virNetworkForwardType) def->forward.type) {
|
||||
case VIR_NETWORK_FORWARD_NONE:
|
||||
case VIR_NETWORK_FORWARD_NAT:
|
||||
case VIR_NETWORK_FORWARD_ROUTE:
|
||||
@ -485,6 +485,11 @@ networkUpdateState(virNetworkObjPtr obj,
|
||||
case VIR_NETWORK_FORWARD_HOSTDEV:
|
||||
/* so far no extra checks */
|
||||
break;
|
||||
|
||||
case VIR_NETWORK_FORWARD_LAST:
|
||||
default:
|
||||
virReportEnumRangeError(virNetworkForwardType, def->forward.type);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
/* Try and read dnsmasq/radvd pids of active networks */
|
||||
@ -2088,20 +2093,37 @@ networkRefreshDaemonsHelper(virNetworkObjPtr obj,
|
||||
|
||||
virObjectLock(obj);
|
||||
def = virNetworkObjGetDef(obj);
|
||||
if (virNetworkObjIsActive(obj) &&
|
||||
((def->forward.type == VIR_NETWORK_FORWARD_NONE) ||
|
||||
(def->forward.type == VIR_NETWORK_FORWARD_NAT) ||
|
||||
(def->forward.type == VIR_NETWORK_FORWARD_ROUTE) ||
|
||||
(def->forward.type == 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 ((virNetworkForwardType) 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;
|
||||
|
||||
case VIR_NETWORK_FORWARD_BRIDGE:
|
||||
case VIR_NETWORK_FORWARD_PRIVATE:
|
||||
case VIR_NETWORK_FORWARD_VEPA:
|
||||
case VIR_NETWORK_FORWARD_PASSTHROUGH:
|
||||
case VIR_NETWORK_FORWARD_HOSTDEV:
|
||||
break;
|
||||
|
||||
case VIR_NETWORK_FORWARD_LAST:
|
||||
default:
|
||||
virReportEnumRangeError(virNetworkForwardType, def->forward.type);
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
cleanup:
|
||||
virObjectUnlock(obj);
|
||||
return 0;
|
||||
}
|
||||
@ -2128,20 +2150,36 @@ networkReloadFirewallRulesHelper(virNetworkObjPtr obj,
|
||||
|
||||
virObjectLock(obj);
|
||||
def = virNetworkObjGetDef(obj);
|
||||
if (virNetworkObjIsActive(obj) &&
|
||||
((def->forward.type == VIR_NETWORK_FORWARD_NONE) ||
|
||||
(def->forward.type == VIR_NETWORK_FORWARD_NAT) ||
|
||||
(def->forward.type == 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='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 ((virNetworkForwardType) 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='open', doesn't need this because it
|
||||
* has no iptables rules.
|
||||
*/
|
||||
networkRemoveFirewallRules(def);
|
||||
ignore_value(networkAddFirewallRules(def));
|
||||
break;
|
||||
|
||||
case VIR_NETWORK_FORWARD_OPEN:
|
||||
case VIR_NETWORK_FORWARD_BRIDGE:
|
||||
case VIR_NETWORK_FORWARD_PRIVATE:
|
||||
case VIR_NETWORK_FORWARD_VEPA:
|
||||
case VIR_NETWORK_FORWARD_PASSTHROUGH:
|
||||
case VIR_NETWORK_FORWARD_HOSTDEV:
|
||||
break;
|
||||
|
||||
case VIR_NETWORK_FORWARD_LAST:
|
||||
default:
|
||||
virReportEnumRangeError(virNetworkForwardType, def->forward.type);
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
cleanup:
|
||||
virObjectUnlock(obj);
|
||||
return 0;
|
||||
}
|
||||
@ -2687,7 +2725,7 @@ networkCreateInterfacePool(virNetworkDefPtr netdef)
|
||||
virNetworkForwardIfDefPtr thisIf
|
||||
= &netdef->forward.ifs[netdef->forward.nifs];
|
||||
|
||||
switch (netdef->forward.type) {
|
||||
switch ((virNetworkForwardType) netdef->forward.type) {
|
||||
case VIR_NETWORK_FORWARD_BRIDGE:
|
||||
case VIR_NETWORK_FORWARD_PRIVATE:
|
||||
case VIR_NETWORK_FORWARD_VEPA:
|
||||
@ -2719,9 +2757,13 @@ networkCreateInterfacePool(virNetworkDefPtr netdef)
|
||||
case VIR_NETWORK_FORWARD_NAT:
|
||||
case VIR_NETWORK_FORWARD_ROUTE:
|
||||
case VIR_NETWORK_FORWARD_OPEN:
|
||||
case VIR_NETWORK_FORWARD_LAST:
|
||||
/* by definition these will never be encountered here */
|
||||
break;
|
||||
|
||||
case VIR_NETWORK_FORWARD_LAST:
|
||||
default:
|
||||
virReportEnumRangeError(virNetworkForwardType, netdef->forward.type);
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
@ -2811,7 +2853,7 @@ networkStartNetwork(virNetworkDriverStatePtr driver,
|
||||
VIR_HOOK_SUBOP_BEGIN) < 0)
|
||||
goto cleanup;
|
||||
|
||||
switch (def->forward.type) {
|
||||
switch ((virNetworkForwardType) def->forward.type) {
|
||||
|
||||
case VIR_NETWORK_FORWARD_NONE:
|
||||
case VIR_NETWORK_FORWARD_NAT:
|
||||
@ -2840,6 +2882,11 @@ networkStartNetwork(virNetworkDriverStatePtr driver,
|
||||
if (networkStartNetworkExternal(obj) < 0)
|
||||
goto cleanup;
|
||||
break;
|
||||
|
||||
case VIR_NETWORK_FORWARD_LAST:
|
||||
default:
|
||||
virReportEnumRangeError(virNetworkForwardType, def->forward.type);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
/* finally we can call the 'started' hook script if any */
|
||||
@ -2893,7 +2940,7 @@ networkShutdownNetwork(virNetworkDriverStatePtr driver,
|
||||
unlink(stateFile);
|
||||
VIR_FREE(stateFile);
|
||||
|
||||
switch (def->forward.type) {
|
||||
switch ((virNetworkForwardType) def->forward.type) {
|
||||
|
||||
case VIR_NETWORK_FORWARD_NONE:
|
||||
case VIR_NETWORK_FORWARD_NAT:
|
||||
@ -2919,6 +2966,11 @@ networkShutdownNetwork(virNetworkDriverStatePtr driver,
|
||||
case VIR_NETWORK_FORWARD_HOSTDEV:
|
||||
ret = networkShutdownNetworkExternal(obj);
|
||||
break;
|
||||
|
||||
case VIR_NETWORK_FORWARD_LAST:
|
||||
default:
|
||||
virReportEnumRangeError(virNetworkForwardType, def->forward.type);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* now that we know it's stopped call the hook if present */
|
||||
@ -3273,11 +3325,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 == VIR_NETWORK_FORWARD_NONE ||
|
||||
def->forward.type == VIR_NETWORK_FORWARD_NAT ||
|
||||
def->forward.type == VIR_NETWORK_FORWARD_ROUTE ||
|
||||
def->forward.type == VIR_NETWORK_FORWARD_OPEN) {
|
||||
|
||||
switch ((virNetworkForwardType) 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 +3337,13 @@ networkValidate(virNetworkDriverStatePtr driver,
|
||||
return -1;
|
||||
|
||||
virNetworkSetBridgeMacAddr(def);
|
||||
} else {
|
||||
break;
|
||||
|
||||
case VIR_NETWORK_FORWARD_BRIDGE:
|
||||
case VIR_NETWORK_FORWARD_PRIVATE:
|
||||
case VIR_NETWORK_FORWARD_VEPA:
|
||||
case VIR_NETWORK_FORWARD_PASSTHROUGH:
|
||||
case VIR_NETWORK_FORWARD_HOSTDEV:
|
||||
/* 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 +3389,12 @@ networkValidate(virNetworkDriverStatePtr driver,
|
||||
return -1;
|
||||
}
|
||||
bandwidthAllowed = false;
|
||||
break;
|
||||
|
||||
case VIR_NETWORK_FORWARD_LAST:
|
||||
default:
|
||||
virReportEnumRangeError(virNetworkForwardType, def->forward.type);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* we support configs with a single PF defined:
|
||||
@ -3755,9 +3819,10 @@ networkUpdate(virNetworkPtr net,
|
||||
/* Take care of anything that must be done before updating the
|
||||
* live NetworkDef.
|
||||
*/
|
||||
if (def->forward.type == VIR_NETWORK_FORWARD_NONE ||
|
||||
def->forward.type == VIR_NETWORK_FORWARD_NAT ||
|
||||
def->forward.type == VIR_NETWORK_FORWARD_ROUTE) {
|
||||
switch ((virNetworkForwardType) 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 +3833,26 @@ networkUpdate(virNetworkPtr net,
|
||||
* old rules (and remember to load new ones after the
|
||||
* update).
|
||||
*/
|
||||
if (def->forward.type != VIR_NETWORK_FORWARD_OPEN) {
|
||||
networkRemoveFirewallRules(def);
|
||||
needFirewallRefresh = true;
|
||||
}
|
||||
networkRemoveFirewallRules(def);
|
||||
needFirewallRefresh = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case VIR_NETWORK_FORWARD_OPEN:
|
||||
case VIR_NETWORK_FORWARD_BRIDGE:
|
||||
case VIR_NETWORK_FORWARD_PRIVATE:
|
||||
case VIR_NETWORK_FORWARD_VEPA:
|
||||
case VIR_NETWORK_FORWARD_PASSTHROUGH:
|
||||
case VIR_NETWORK_FORWARD_HOSTDEV:
|
||||
break;
|
||||
|
||||
case VIR_NETWORK_FORWARD_LAST:
|
||||
default:
|
||||
virReportEnumRangeError(virNetworkForwardType, def->forward.type);
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
@ -4440,10 +4517,11 @@ networkAllocateActualDevice(virDomainDefPtr dom,
|
||||
iface->data.network.actual->trustGuestRxFilters
|
||||
= netdef->trustGuestRxFilters;
|
||||
|
||||
if ((netdef->forward.type == VIR_NETWORK_FORWARD_NONE) ||
|
||||
(netdef->forward.type == VIR_NETWORK_FORWARD_NAT) ||
|
||||
(netdef->forward.type == VIR_NETWORK_FORWARD_ROUTE) ||
|
||||
(netdef->forward.type == VIR_NETWORK_FORWARD_OPEN)) {
|
||||
switch ((virNetworkForwardType) 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 +4541,9 @@ networkAllocateActualDevice(virDomainDefPtr dom,
|
||||
|
||||
if (networkPlugBandwidth(obj, iface) < 0)
|
||||
goto error;
|
||||
break;
|
||||
|
||||
} else if ((netdef->forward.type == VIR_NETWORK_FORWARD_BRIDGE) &&
|
||||
netdef->bridge) {
|
||||
|
||||
/* <forward type='bridge'/> <bridge name='xxx'/>
|
||||
* is VIR_DOMAIN_NET_TYPE_BRIDGE
|
||||
*/
|
||||
|
||||
iface->data.network.actual->type = actualType = 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
|
||||
= 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) {
|
||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||
_("<virtualport type='%s'> not supported for network "
|
||||
"'%s' which uses a bridge device"),
|
||||
virNetDevVPortTypeToString(virtport->virtPortType),
|
||||
netdef->name);
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
|
||||
} else if (netdef->forward.type == VIR_NETWORK_FORWARD_HOSTDEV) {
|
||||
|
||||
case VIR_NETWORK_FORWARD_HOSTDEV: {
|
||||
virDomainHostdevSubsysPCIBackendType backend;
|
||||
|
||||
iface->data.network.actual->type = actualType = VIR_DOMAIN_NET_TYPE_HOSTDEV;
|
||||
@ -4575,32 +4616,67 @@ networkAllocateActualDevice(virDomainDefPtr dom,
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
} else if ((netdef->forward.type == VIR_NETWORK_FORWARD_BRIDGE) ||
|
||||
(netdef->forward.type == VIR_NETWORK_FORWARD_PRIVATE) ||
|
||||
(netdef->forward.type == VIR_NETWORK_FORWARD_VEPA) ||
|
||||
(netdef->forward.type == VIR_NETWORK_FORWARD_PASSTHROUGH)) {
|
||||
case VIR_NETWORK_FORWARD_BRIDGE:
|
||||
if (netdef->bridge) {
|
||||
/* <forward type='bridge'/> <bridge name='xxx'/>
|
||||
* is VIR_DOMAIN_NET_TYPE_BRIDGE
|
||||
*/
|
||||
|
||||
iface->data.network.actual->type = actualType = 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
|
||||
= 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) {
|
||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||
_("<virtualport type='%s'> not supported for network "
|
||||
"'%s' which uses a bridge device"),
|
||||
virNetDevVPortTypeToString(virtport->virtPortType),
|
||||
netdef->name);
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
/* intentionally fall through to the direct case for
|
||||
* VIR_NETWORK_FORWARD_BRIDGE with no bridge device defined
|
||||
*/
|
||||
ATTRIBUTE_FALLTHROUGH;
|
||||
|
||||
case VIR_NETWORK_FORWARD_PRIVATE:
|
||||
case VIR_NETWORK_FORWARD_VEPA:
|
||||
case VIR_NETWORK_FORWARD_PASSTHROUGH:
|
||||
/* <forward type='bridge|private|vepa|passthrough'> are all
|
||||
* VIR_DOMAIN_NET_TYPE_DIRECT.
|
||||
*/
|
||||
|
||||
/* Set type=direct and appropriate <source mode='xxx'/> */
|
||||
iface->data.network.actual->type = actualType = VIR_DOMAIN_NET_TYPE_DIRECT;
|
||||
switch (netdef->forward.type) {
|
||||
case VIR_NETWORK_FORWARD_BRIDGE:
|
||||
iface->data.network.actual->data.direct.mode = VIR_NETDEV_MACVLAN_MODE_BRIDGE;
|
||||
break;
|
||||
case VIR_NETWORK_FORWARD_PRIVATE:
|
||||
iface->data.network.actual->data.direct.mode = VIR_NETDEV_MACVLAN_MODE_PRIVATE;
|
||||
break;
|
||||
case VIR_NETWORK_FORWARD_VEPA:
|
||||
iface->data.network.actual->data.direct.mode = VIR_NETDEV_MACVLAN_MODE_VEPA;
|
||||
break;
|
||||
case VIR_NETWORK_FORWARD_PASSTHROUGH:
|
||||
iface->data.network.actual->data.direct.mode = VIR_NETDEV_MACVLAN_MODE_PASSTHRU;
|
||||
break;
|
||||
}
|
||||
|
||||
/* NO need to check the value returned from virNetDevMacVLanModeTypeFromString
|
||||
* it must be valid for these forward type(bridge|private|vepa|passthrough)
|
||||
*/
|
||||
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
|
||||
@ -4680,6 +4756,12 @@ networkAllocateActualDevice(virDomainDefPtr dom,
|
||||
dev->device.dev) < 0)
|
||||
goto error;
|
||||
}
|
||||
break;
|
||||
|
||||
case VIR_NETWORK_FORWARD_LAST:
|
||||
default:
|
||||
virReportEnumRangeError(virNetworkForwardType, netdef->forward.type);
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (virNetworkObjMacMgrAdd(obj, driver->dnsmasqStateDir,
|
||||
@ -5037,13 +5119,27 @@ networkReleaseActualDevice(virDomainDefPtr dom,
|
||||
}
|
||||
netdef = virNetworkObjGetDef(obj);
|
||||
|
||||
if (iface->data.network.actual &&
|
||||
(netdef->forward.type == VIR_NETWORK_FORWARD_NONE ||
|
||||
netdef->forward.type == VIR_NETWORK_FORWARD_NAT ||
|
||||
netdef->forward.type == VIR_NETWORK_FORWARD_ROUTE ||
|
||||
netdef->forward.type == VIR_NETWORK_FORWARD_OPEN) &&
|
||||
networkUnplugBandwidth(obj, iface) < 0)
|
||||
switch ((virNetworkForwardType) 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, iface) < 0)
|
||||
goto error;
|
||||
break;
|
||||
|
||||
case VIR_NETWORK_FORWARD_BRIDGE:
|
||||
case VIR_NETWORK_FORWARD_PRIVATE:
|
||||
case VIR_NETWORK_FORWARD_VEPA:
|
||||
case VIR_NETWORK_FORWARD_PASSTHROUGH:
|
||||
case VIR_NETWORK_FORWARD_HOSTDEV:
|
||||
break;
|
||||
|
||||
case VIR_NETWORK_FORWARD_LAST:
|
||||
default:
|
||||
virReportEnumRangeError(virNetworkForwardType, netdef->forward.type);
|
||||
goto error;
|
||||
}
|
||||
|
||||
if ((!iface->data.network.actual) ||
|
||||
((actualType != VIR_DOMAIN_NET_TYPE_DIRECT) &&
|
||||
|
@ -4545,7 +4545,7 @@ qemuProcessGetNetworkAddress(const char *netname,
|
||||
if (!netdef)
|
||||
goto cleanup;
|
||||
|
||||
switch (netdef->forward.type) {
|
||||
switch ((virNetworkForwardType) netdef->forward.type) {
|
||||
case VIR_NETWORK_FORWARD_NONE:
|
||||
case VIR_NETWORK_FORWARD_NAT:
|
||||
case VIR_NETWORK_FORWARD_ROUTE:
|
||||
@ -4582,6 +4582,14 @@ qemuProcessGetNetworkAddress(const char *netname,
|
||||
goto cleanup;
|
||||
}
|
||||
break;
|
||||
|
||||
case VIR_NETWORK_FORWARD_HOSTDEV:
|
||||
break;
|
||||
|
||||
case VIR_NETWORK_FORWARD_LAST:
|
||||
default:
|
||||
virReportEnumRangeError(virNetworkForwardType, netdef->forward.type);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (dev_name) {
|
||||
|
Loading…
Reference in New Issue
Block a user