Discussion:
[libvirt] [PATCH 08/28] lxc: use correct prefix when setting veth IP address
Laine Stump
2016-06-22 17:37:07 UTC
Permalink
Commit c9a641 (first appearred in 1.2.12) added support for setting
the guest-side IP address of veth devices in lxc domains.
Unfortunately, it hardcoded the assumption that the proper prefix for
any IP address with no explicit prefix in the config should be "24";
that is only correct for class C IPv4 addresses, but not for any other
IPv4 address, nor for any IPv6 address.

The good news is that there is already a function in libvirt that will
determine the proper default prefix for any IP address. This patch
replaces the use of the ill-fated VIR_SOCKET_ADDR_DEFAULT_PREFIX with
calls to virSocketAddrGetIPPrefix().
---
src/lxc/lxc_container.c | 17 ++++++++++++-----
src/util/virsocketaddr.h | 1 -
2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c
index 3d9e28b..304aa86 100644
--- a/src/lxc/lxc_container.c
+++ b/src/lxc/lxc_container.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2008-2015 Red Hat, Inc.
+ * Copyright (C) 2008-2016 Red Hat, Inc.
* Copyright (C) 2008 IBM Corp.
* Copyright (c) 2015 SUSE LINUX Products GmbH, Nuernberg, Germany.
*
@@ -514,12 +514,19 @@ static int lxcContainerRenameAndEnableInterfaces(virDomainDefPtr vmDef,

for (j = 0; j < netDef->nips; j++) {
virDomainNetIPDefPtr ip = netDef->ips[j];
- unsigned int prefix = (ip->prefix > 0) ? ip->prefix :
- VIR_SOCKET_ADDR_DEFAULT_PREFIX;
+ int prefix;
char *ipStr = virSocketAddrFormat(&ip->address);

- VIR_DEBUG("Adding IP address '%s/%u' to '%s'",
- ipStr, ip->prefix, newname);
+ if ((prefix = virSocketAddrGetIPPrefix(&ip->address,
+ NULL, ip->prefix)) < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Failed to determine prefix for IP address '%s'"),
+ ipStr);
+ goto error_out;
+ }
+
+ VIR_DEBUG("Adding IP address '%s/%d' to '%s'",
+ ipStr, prefix, newname);
if (virNetDevSetIPAddress(newname, &ip->address, NULL, prefix) < 0) {
virReportError(VIR_ERR_SYSTEM_ERROR,
_("Failed to set IP address '%s' on %s"),
diff --git a/src/util/virsocketaddr.h b/src/util/virsocketaddr.h
index 990e31c..7ee993b 100644
--- a/src/util/virsocketaddr.h
+++ b/src/util/virsocketaddr.h
@@ -54,7 +54,6 @@ typedef struct {
# define VIR_SOCKET_ADDR_FAMILY(s) \
((s)->data.sa.sa_family)

-# define VIR_SOCKET_ADDR_DEFAULT_PREFIX 24
# define VIR_SOCKET_ADDR_IPV4_ALL "0.0.0.0"
# define VIR_SOCKET_ADDR_IPV6_ALL "::"
--
2.5.5
Laine Stump
2016-06-22 17:37:10 UTC
Permalink
in qemuConnectDomainXMLToNative. This function was only accounting for
about 1/10 of all the allocated items in the NetDef prior to memseting
it to all 0's. On top of that, it was going to great pains to learn
the name of the bridge device, but then never doing anything useful
with it (just putting it into data.ethernet.dev, which is *never* used
when building a qemu commandline). (I think this again all started off
as code with good intentions, but it was never completed, and instead
was just Frankensteinically cargo-culted into the odd mish mash we
have today).

The resulting code is much simpler, produces exactly the same output,
and doesn't leak memory.
---
src/qemu/qemu_driver.c | 56 ++++++--------------------------------------------
1 file changed, 6 insertions(+), 50 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 517d0b8..4a8cb7a 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -6987,62 +6987,18 @@ static char *qemuConnectDomainXMLToNative(virConnectPtr conn,
unsigned int bootIndex = net->info.bootIndex;
char *model = net->model;
virMacAddr mac = net->mac;
+ char *script = net->script;

- if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK) {
- int actualType = virDomainNetGetActualType(net);
- const char *brname;
-
- VIR_FREE(net->data.network.name);
- VIR_FREE(net->data.network.portgroup);
- if ((actualType == VIR_DOMAIN_NET_TYPE_BRIDGE) &&
- (brname = virDomainNetGetActualBridgeName(net))) {
-
- char *brnamecopy;
-
- if (VIR_STRDUP(brnamecopy, brname) < 0)
- goto cleanup;
-
- virDomainActualNetDefFree(net->data.network.actual);
-
- memset(net, 0, sizeof(*net));
-
- net->type = VIR_DOMAIN_NET_TYPE_ETHERNET;
- net->script = NULL;
- net->data.ethernet.dev = brnamecopy;
- } else {
- /* actualType is either NETWORK or DIRECT. In either
- * case, the best we can do is NULL everything out.
- */
- virDomainActualNetDefFree(net->data.network.actual);
- memset(net, 0, sizeof(*net));
-
- net->type = VIR_DOMAIN_NET_TYPE_ETHERNET;
- net->script = NULL;
- net->data.ethernet.dev = NULL;
- }
- } else if (net->type == VIR_DOMAIN_NET_TYPE_DIRECT) {
- VIR_FREE(net->data.direct.linkdev);
+ net->model = NULL;
+ net->script = NULL;

- memset(net, 0, sizeof(*net));
-
- net->type = VIR_DOMAIN_NET_TYPE_ETHERNET;
- net->script = NULL;
- net->data.ethernet.dev = NULL;
- } else if (net->type == VIR_DOMAIN_NET_TYPE_BRIDGE) {
- char *script = net->script;
- char *brname = net->data.bridge.brname;
-
- memset(net, 0, sizeof(*net));
-
- net->type = VIR_DOMAIN_NET_TYPE_ETHERNET;
- net->script = script;
- net->data.ethernet.dev = brname;
- }
+ virDomainNetDefClear(net);

- VIR_FREE(net->virtPortProfile);
+ net->type = VIR_DOMAIN_NET_TYPE_ETHERNET;
net->info.bootIndex = bootIndex;
net->model = model;
net->mac = mac;
+ net->script = script;
}

if (!(cmd = qemuProcessCreatePretendCmd(conn, driver, vm, NULL,
--
2.5.5
John Ferlan
2016-06-23 21:59:43 UTC
Permalink
Post by Laine Stump
in qemuConnectDomainXMLToNative. This function was only accounting for
about 1/10 of all the allocated items in the NetDef prior to memseting
it to all 0's. On top of that, it was going to great pains to learn
the name of the bridge device, but then never doing anything useful
with it (just putting it into data.ethernet.dev, which is *never* used
when building a qemu commandline). (I think this again all started off
as code with good intentions, but it was never completed, and instead
was just Frankensteinically cargo-culted into the odd mish mash we
have today).
The resulting code is much simpler, produces exactly the same output,
and doesn't leak memory.
---
src/qemu/qemu_driver.c | 56 ++++++--------------------------------------------
1 file changed, 6 insertions(+), 50 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 517d0b8..4a8cb7a 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -6987,62 +6987,18 @@ static char *qemuConnectDomainXMLToNative(virConnectPtr conn,
unsigned int bootIndex = net->info.bootIndex;
char *model = net->model;
virMacAddr mac = net->mac;
+ char *script = net->script;
Based on 3 spots below where net->script was set to NULL, should this
only be set when "(net->type == VIR_DOMAIN_NET_TYPE_BRIDGE)" ?
Post by Laine Stump
- if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK) {
- int actualType = virDomainNetGetActualType(net);
- const char *brname;
-
- VIR_FREE(net->data.network.name);
- VIR_FREE(net->data.network.portgroup);
- if ((actualType == VIR_DOMAIN_NET_TYPE_BRIDGE) &&
- (brname = virDomainNetGetActualBridgeName(net))) {
-
- char *brnamecopy;
-
- if (VIR_STRDUP(brnamecopy, brname) < 0)
- goto cleanup;
-
- virDomainActualNetDefFree(net->data.network.actual);
-
- memset(net, 0, sizeof(*net));
-
- net->type = VIR_DOMAIN_NET_TYPE_ETHERNET;
- net->script = NULL;
^^^
Post by Laine Stump
- net->data.ethernet.dev = brnamecopy;
- } else {
- /* actualType is either NETWORK or DIRECT. In either
- * case, the best we can do is NULL everything out.
- */
- virDomainActualNetDefFree(net->data.network.actual);
- memset(net, 0, sizeof(*net));
-
- net->type = VIR_DOMAIN_NET_TYPE_ETHERNET;
- net->script = NULL;
^^^
Post by Laine Stump
- net->data.ethernet.dev = NULL;
- }
- } else if (net->type == VIR_DOMAIN_NET_TYPE_DIRECT) {
- VIR_FREE(net->data.direct.linkdev);
+ net->model = NULL;
+ net->script = NULL;
- memset(net, 0, sizeof(*net));
-
- net->type = VIR_DOMAIN_NET_TYPE_ETHERNET;
- net->script = NULL;
^^^

ACK - whichever way you go with that 'script' setting. I figure you know
the best answer to my question


John
Post by Laine Stump
- net->data.ethernet.dev = NULL;
- } else if (net->type == VIR_DOMAIN_NET_TYPE_BRIDGE) {
- char *script = net->script;
- char *brname = net->data.bridge.brname;
-
- memset(net, 0, sizeof(*net));
-
- net->type = VIR_DOMAIN_NET_TYPE_ETHERNET;
- net->script = script;
- net->data.ethernet.dev = brname;
- }
+ virDomainNetDefClear(net);
- VIR_FREE(net->virtPortProfile);
+ net->type = VIR_DOMAIN_NET_TYPE_ETHERNET;
net->info.bootIndex = bootIndex;
net->model = model;
net->mac = mac;
+ net->script = script;
}
if (!(cmd = qemuProcessCreatePretendCmd(conn, driver, vm, NULL,
Laine Stump
2016-06-24 19:27:24 UTC
Permalink
Post by John Ferlan
Post by Laine Stump
in qemuConnectDomainXMLToNative. This function was only accounting for
about 1/10 of all the allocated items in the NetDef prior to memseting
it to all 0's. On top of that, it was going to great pains to learn
the name of the bridge device, but then never doing anything useful
with it (just putting it into data.ethernet.dev, which is *never* used
when building a qemu commandline). (I think this again all started off
as code with good intentions, but it was never completed, and instead
was just Frankensteinically cargo-culted into the odd mish mash we
have today).
The resulting code is much simpler, produces exactly the same output,
and doesn't leak memory.
---
src/qemu/qemu_driver.c | 56 ++++++--------------------------------------------
1 file changed, 6 insertions(+), 50 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 517d0b8..4a8cb7a 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -6987,62 +6987,18 @@ static char *qemuConnectDomainXMLToNative(virConnectPtr conn,
unsigned int bootIndex = net->info.bootIndex;
char *model = net->model;
virMacAddr mac = net->mac;
+ char *script = net->script;
Based on 3 spots below where net->script was set to NULL, should this
only be set when "(net->type == VIR_DOMAIN_NET_TYPE_BRIDGE)" ?
Actually I think that since it's in the common part of the object (and
not in the bridge-specific part) that it should just *always* be saved
and re-set. I'll do that before I push.
Post by John Ferlan
Post by Laine Stump
- if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK) {
- int actualType = virDomainNetGetActualType(net);
- const char *brname;
-
- VIR_FREE(net->data.network.name);
- VIR_FREE(net->data.network.portgroup);
- if ((actualType == VIR_DOMAIN_NET_TYPE_BRIDGE) &&
- (brname = virDomainNetGetActualBridgeName(net))) {
-
- char *brnamecopy;
-
- if (VIR_STRDUP(brnamecopy, brname) < 0)
- goto cleanup;
-
- virDomainActualNetDefFree(net->data.network.actual);
-
- memset(net, 0, sizeof(*net));
-
- net->type = VIR_DOMAIN_NET_TYPE_ETHERNET;
- net->script = NULL;
^^^
Post by Laine Stump
- net->data.ethernet.dev = brnamecopy;
- } else {
- /* actualType is either NETWORK or DIRECT. In either
- * case, the best we can do is NULL everything out.
- */
- virDomainActualNetDefFree(net->data.network.actual);
- memset(net, 0, sizeof(*net));
-
- net->type = VIR_DOMAIN_NET_TYPE_ETHERNET;
- net->script = NULL;
^^^
Post by Laine Stump
- net->data.ethernet.dev = NULL;
- }
- } else if (net->type == VIR_DOMAIN_NET_TYPE_DIRECT) {
- VIR_FREE(net->data.direct.linkdev);
+ net->model = NULL;
+ net->script = NULL;
- memset(net, 0, sizeof(*net));
-
- net->type = VIR_DOMAIN_NET_TYPE_ETHERNET;
- net->script = NULL;
^^^
ACK - whichever way you go with that 'script' setting. I figure you know
the best answer to my question
John
Post by Laine Stump
- net->data.ethernet.dev = NULL;
- } else if (net->type == VIR_DOMAIN_NET_TYPE_BRIDGE) {
- char *script = net->script;
- char *brname = net->data.bridge.brname;
-
- memset(net, 0, sizeof(*net));
-
- net->type = VIR_DOMAIN_NET_TYPE_ETHERNET;
- net->script = script;
- net->data.ethernet.dev = brname;
- }
+ virDomainNetDefClear(net);
- VIR_FREE(net->virtPortProfile);
+ net->type = VIR_DOMAIN_NET_TYPE_ETHERNET;
net->info.bootIndex = bootIndex;
net->model = model;
net->mac = mac;
+ net->script = script;
}
if (!(cmd = qemuProcessCreatePretendCmd(conn, driver, vm, NULL,
Laine Stump
2016-06-24 20:04:55 UTC
Permalink
Post by Laine Stump
Post by John Ferlan
Post by Laine Stump
in qemuConnectDomainXMLToNative. This function was only accounting for
about 1/10 of all the allocated items in the NetDef prior to memseting
it to all 0's. On top of that, it was going to great pains to learn
the name of the bridge device, but then never doing anything useful
with it (just putting it into data.ethernet.dev, which is *never* used
when building a qemu commandline). (I think this again all started off
as code with good intentions, but it was never completed, and instead
was just Frankensteinically cargo-culted into the odd mish mash we
have today).
The resulting code is much simpler, produces exactly the same output,
and doesn't leak memory.
---
src/qemu/qemu_driver.c | 56
++++++--------------------------------------------
1 file changed, 6 insertions(+), 50 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 517d0b8..4a8cb7a 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -6987,62 +6987,18 @@ static char
*qemuConnectDomainXMLToNative(virConnectPtr conn,
unsigned int bootIndex = net->info.bootIndex;
char *model = net->model;
virMacAddr mac = net->mac;
+ char *script = net->script;
Based on 3 spots below where net->script was set to NULL, should this
only be set when "(net->type == VIR_DOMAIN_NET_TYPE_BRIDGE)" ?
Actually I think that since it's in the common part of the object (and
not in the bridge-specific part) that it should just *always* be saved
and re-set. I'll do that before I push.
derp. That's the way I'd already done it, I just forgot and didn't look
carefully.

So the reason I think this way is that it's a valid pointer no matter
what the value of net->type (since it's set to NULL for those types that
don't allow it), so it doesn't hurt anything to do it in all cases, and
it could always be an advantage if some other network type starts
supporting script (which is *never* going to happen).
Laine Stump
2016-06-22 17:37:03 UTC
Permalink
Rearrange this function to be better organized and more correct:

* the error codes were changed from the incorrect INVALID_ARG to
XML_ERROR

* prefix still isn't required, but if present it must be valid or an
error will be logged.

* don't emit a debug log just because prefix is missing - this
is valid.

* group everything related to setting prefix in one place rather than
scattered through the function.
---
src/conf/domain_conf.c | 25 +++++++++++++++----------
1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index e57655e..c5b4815 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -6115,15 +6115,9 @@ virDomainNetIPParseXML(xmlNodePtr node)
int family = AF_UNSPEC;
char *address = NULL;

- if (!(prefixStr = virXMLPropString(node, "prefix")) ||
- (virStrToLong_ui(prefixStr, NULL, 10, &prefixValue) < 0)) {
- // Don't shout, as some old config may not have a prefix
- VIR_DEBUG("Missing or invalid network prefix");
- }
-
if (!(address = virXMLPropString(node, "address"))) {
- virReportError(VIR_ERR_INVALID_ARG, "%s",
- _("Missing network address"));
+ virReportError(VIR_ERR_XML_ERROR, "%s",
+ _("Missing required address in <ip>"));
goto cleanup;
}

@@ -6139,11 +6133,22 @@ virDomainNetIPParseXML(xmlNodePtr node)
goto cleanup;

if (virSocketAddrParse(&ip->address, address, family) < 0) {
- virReportError(VIR_ERR_INVALID_ARG,
- _("Failed to parse IP address: '%s'"),
+ virReportError(VIR_ERR_XML_ERROR,
+ _("Invalid address '%s' in <ip>"),
address);
goto cleanup;
}
+
+ prefixStr = virXMLPropString(node, "prefix");
+ if (prefixStr &&
+ ((virStrToLong_ui(prefixStr, NULL, 10, &prefixValue) < 0) ||
+ (family == AF_INET6 && prefixValue > 128) ||
+ (family == AF_INET && prefixValue > 32))) {
+ virReportError(VIR_ERR_XML_ERROR,
+ _("Invalid prefix value '%s' in <ip>"),
+ prefixStr);
+ goto cleanup;
+ }
ip->prefix = prefixValue;

ret = ip;
--
2.5.5
John Ferlan
2016-06-23 20:35:13 UTC
Permalink
Post by Laine Stump
* the error codes were changed from the incorrect INVALID_ARG to
XML_ERROR
* prefix still isn't required, but if present it must be valid or an
error will be logged.
* don't emit a debug log just because prefix is missing - this
is valid.
* group everything related to setting prefix in one place rather than
scattered through the function.
---
src/conf/domain_conf.c | 25 +++++++++++++++----------
1 file changed, 15 insertions(+), 10 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index e57655e..c5b4815 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -6115,15 +6115,9 @@ virDomainNetIPParseXML(xmlNodePtr node)
int family = AF_UNSPEC;
char *address = NULL;
- if (!(prefixStr = virXMLPropString(node, "prefix")) ||
- (virStrToLong_ui(prefixStr, NULL, 10, &prefixValue) < 0)) {
- // Don't shout, as some old config may not have a prefix
- VIR_DEBUG("Missing or invalid network prefix");
- }
-
if (!(address = virXMLPropString(node, "address"))) {
- virReportError(VIR_ERR_INVALID_ARG, "%s",
- _("Missing network address"));
+ virReportError(VIR_ERR_XML_ERROR, "%s",
+ _("Missing required address in <ip>"));
goto cleanup;
}
@@ -6139,11 +6133,22 @@ virDomainNetIPParseXML(xmlNodePtr node)
goto cleanup;
if (virSocketAddrParse(&ip->address, address, family) < 0) {
- virReportError(VIR_ERR_INVALID_ARG,
- _("Failed to parse IP address: '%s'"),
+ virReportError(VIR_ERR_XML_ERROR,
+ _("Invalid address '%s' in <ip>"),
address);
goto cleanup;
}
+
+ prefixStr = virXMLPropString(node, "prefix");
+ if (prefixStr &&
+ ((virStrToLong_ui(prefixStr, NULL, 10, &prefixValue) < 0) ||
+ (family == AF_INET6 && prefixValue > 128) ||
+ (family == AF_INET && prefixValue > 32))) {
+ virReportError(VIR_ERR_XML_ERROR,
+ _("Invalid prefix value '%s' in <ip>"),
+ prefixStr);
+ goto cleanup;
+ }
I fear the answer to this question, but I'll ask it... Can a domain that
running today with an incorrect prefixValue?

If I'm reading things correct, it would have been assigned a value of 0,
but could still be running. On libvirtd restart with this change could
that domain 'disappear' because of this "parse" error.

ACK in principle, but you may need to move that check to the "Validate"
callback code path depending on how you answer the question.

John
Post by Laine Stump
ip->prefix = prefixValue;
ret = ip;
Laine Stump
2016-06-22 17:37:17 UTC
Permalink
libvirt's qemu driver doesn't have direct access to the config on the
guest side of a network interface, and currently doesn't have any
method in place to even inform the guest of the desired config. In the
future, an unenforceable attempt to set the guest-side IP info could
be made by adding a static host entry to the appropriate dnsmasq
configuration (or changing the default dhcp client address on the qemu
commandline for type='user' interfaces), or enhancing the guest agent
to allow setting an IP address, but for now it can't have any effect,
and we don't want to give the illusion that it does.

To prevent the "disappearance" of any existing configs with ip
address/route info (due to parser failure), this check is added in the
newly implemented qemuDomainDeviceDefValidate(), which is only called
when a domain is defined or started, *not* when it is reread from disk
at libvirtd startup.
---
src/qemu/qemu_domain.c | 34 ++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index e3267e4..1fca13f 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -2204,6 +2204,38 @@ qemuDomainDefValidate(const virDomainDef *def,
}


+static int
+qemuDomainDeviceDefValidate(const virDomainDeviceDef *dev,
+ const virDomainDef *def ATTRIBUTE_UNUSED,
+ void *opaque)
+{
+ virQEMUDriverPtr driver = opaque;
+ virQEMUCapsPtr qemuCaps = NULL;
+ virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
+ int ret = -1;
+
+ qemuCaps = virQEMUCapsCacheLookup(driver->qemuCapsCache, def->emulator);
+
+ if (dev->type == VIR_DOMAIN_DEVICE_NET) {
+ const virDomainNetDef *net = dev->data.net;
+
+ if (net->guestIP.nroutes || net->guestIP.nips) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+ _("Invalid attempt to set network interface "
+ "guest-side IP route and/or address info, "
+ "not supported by QEMU"));
+ goto cleanup;
+ }
+ }
+
+ ret = 0;
+ cleanup:
+ virObjectUnref(qemuCaps);
+ virObjectUnref(cfg);
+ return ret;
+}
+
+
static const char *
qemuDomainDefaultNetModel(const virDomainDef *def,
virQEMUCapsPtr qemuCaps)
@@ -2456,6 +2488,8 @@ virDomainDefParserConfig virQEMUDriverDomainDefParserConfig = {
.domainPostParseCallback = qemuDomainDefPostParse,
.assignAddressesCallback = qemuDomainDefAssignAddresses,
.domainValidateCallback = qemuDomainDefValidate,
+ .deviceValidateCallback = qemuDomainDeviceDefValidate,
+
.features = VIR_DOMAIN_DEF_FEATURE_MEMORY_HOTPLUG |
VIR_DOMAIN_DEF_FEATURE_OFFLINE_VCPUPIN
};
--
2.5.5
John Ferlan
2016-06-24 12:01:40 UTC
Permalink
Post by Laine Stump
libvirt's qemu driver doesn't have direct access to the config on the
guest side of a network interface, and currently doesn't have any
method in place to even inform the guest of the desired config. In the
future, an unenforceable attempt to set the guest-side IP info could
be made by adding a static host entry to the appropriate dnsmasq
configuration (or changing the default dhcp client address on the qemu
commandline for type='user' interfaces), or enhancing the guest agent
to allow setting an IP address, but for now it can't have any effect,
and we don't want to give the illusion that it does.
To prevent the "disappearance" of any existing configs with ip
address/route info (due to parser failure), this check is added in the
newly implemented qemuDomainDeviceDefValidate(), which is only called
when a domain is defined or started, *not* when it is reread from disk
at libvirtd startup.
---
src/qemu/qemu_domain.c | 34 ++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
ACK

John
Laine Stump
2016-06-22 17:37:05 UTC
Permalink
There are times when we don't have a netmask pointer to give to
virSocketAddrGetIPPrefix() (e.g. the IP addresses in domain interfaces
only have a prefix, no netmask), but it would have caused a segv if we
called it with NULL instead of a pointer to a netmask. This patch
qualifies the code that would use the netmask or address pointers to
check for NULL first.
---
src/util/virsocketaddr.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/util/virsocketaddr.c b/src/util/virsocketaddr.c
index 12fe96a..33b1e9e 100644
--- a/src/util/virsocketaddr.c
+++ b/src/util/virsocketaddr.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009-2015 Red Hat, Inc.
+ * Copyright (C) 2009-2016 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -1026,9 +1026,9 @@ virSocketAddrGetIPPrefix(const virSocketAddr *address,
{
if (prefix > 0) {
return prefix;
- } else if (VIR_SOCKET_ADDR_VALID(netmask)) {
+ } else if (netmask && VIR_SOCKET_ADDR_VALID(netmask)) {
return virSocketAddrGetNumNetmaskBits(netmask);
- } else if (VIR_SOCKET_ADDR_IS_FAMILY(address, AF_INET)) {
+ } else if (address && VIR_SOCKET_ADDR_IS_FAMILY(address, AF_INET)) {
/* Return the natural prefix for the network's ip address.
* On Linux we could use the IN_CLASSx() macros, but those
* aren't guaranteed on all platforms, so we just deal with
@@ -1053,7 +1053,7 @@ virSocketAddrGetIPPrefix(const virSocketAddr *address,
return 24;
}
return -1;
- } else if (VIR_SOCKET_ADDR_IS_FAMILY(address, AF_INET6)) {
+ } else if (address && VIR_SOCKET_ADDR_IS_FAMILY(address, AF_INET6)) {
if (virSocketAddrIsWildcard(address))
return 0;
return 64;
--
2.5.5
John Ferlan
2016-06-23 21:03:16 UTC
Permalink
Post by Laine Stump
There are times when we don't have a netmask pointer to give to
virSocketAddrGetIPPrefix() (e.g. the IP addresses in domain interfaces
only have a prefix, no netmask), but it would have caused a segv if we
called it with NULL instead of a pointer to a netmask. This patch
qualifies the code that would use the netmask or address pointers to
check for NULL first.
---
src/util/virsocketaddr.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
According to how I read the commit message, "today" it could only be
possible to have a NULL netmask if prefix was set.

If prefix was set, then the following code returns prefix immediately.

So I don't have anything against the extra checks - perhaps a few extra
words either in comments or commit regarding is something existing or
something that could be a truism in the future where prefix == 0 and
either netmask or address is NULL.

Of course I have a feeling I'm being set up for something soon ;-)

ACK -

John
Post by Laine Stump
diff --git a/src/util/virsocketaddr.c b/src/util/virsocketaddr.c
index 12fe96a..33b1e9e 100644
--- a/src/util/virsocketaddr.c
+++ b/src/util/virsocketaddr.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009-2015 Red Hat, Inc.
+ * Copyright (C) 2009-2016 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -1026,9 +1026,9 @@ virSocketAddrGetIPPrefix(const virSocketAddr *address,
{
if (prefix > 0) {
return prefix;
- } else if (VIR_SOCKET_ADDR_VALID(netmask)) {
+ } else if (netmask && VIR_SOCKET_ADDR_VALID(netmask)) {
return virSocketAddrGetNumNetmaskBits(netmask);
- } else if (VIR_SOCKET_ADDR_IS_FAMILY(address, AF_INET)) {
+ } else if (address && VIR_SOCKET_ADDR_IS_FAMILY(address, AF_INET)) {
/* Return the natural prefix for the network's ip address.
* On Linux we could use the IN_CLASSx() macros, but those
* aren't guaranteed on all platforms, so we just deal with
@@ -1053,7 +1053,7 @@ virSocketAddrGetIPPrefix(const virSocketAddr *address,
return 24;
}
return -1;
- } else if (VIR_SOCKET_ADDR_IS_FAMILY(address, AF_INET6)) {
+ } else if (address && VIR_SOCKET_ADDR_IS_FAMILY(address, AF_INET6)) {
if (virSocketAddrIsWildcard(address))
return 0;
return 64;
Laine Stump
2016-06-22 17:37:04 UTC
Permalink
Now that we can include <interface type='ethernet'> in tests, we could
almost test XML that has an <ip> element in an interface. Except that
the test fails when it tries to actually set the IP address for the
interface's tap device. This patch mocks virNetDevSetIPAddress() to
just return success.
---
tests/qemuxml2argvmock.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/tests/qemuxml2argvmock.c b/tests/qemuxml2argvmock.c
index c6a1f98..b99496a 100644
--- a/tests/qemuxml2argvmock.c
+++ b/tests/qemuxml2argvmock.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2014 Red Hat, Inc.
+ * Copyright (C) 2014-2016 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -127,6 +127,14 @@ virNetDevSetMAC(const char *ifname ATTRIBUTE_UNUSED,
return 0;
}

+int virNetDevSetIPAddress(const char *ifname ATTRIBUTE_UNUSED,
+ virSocketAddr *addr ATTRIBUTE_UNUSED,
+ virSocketAddr *peer ATTRIBUTE_UNUSED,
+ unsigned int prefix ATTRIBUTE_UNUSED)
+{
+ return 0;
+}
+
int
virNetDevSetOnline(const char *ifname ATTRIBUTE_UNUSED,
bool online ATTRIBUTE_UNUSED)
--
2.5.5
John Ferlan
2016-06-23 20:37:28 UTC
Permalink
Post by Laine Stump
Now that we can include <interface type='ethernet'> in tests, we could
almost test XML that has an <ip> element in an interface. Except that
the test fails when it tries to actually set the IP address for the
interface's tap device. This patch mocks virNetDevSetIPAddress() to
just return success.
---
tests/qemuxml2argvmock.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
ACK

John
Laine Stump
2016-06-22 17:37:14 UTC
Permalink
There are currently two places in the domain where this combination is
used, and there is about to be another. This patch puts them together
for brevity and uniformity.

As with the newly-renamed virNetDevIPAddr and virNetDevIPRoute
objects, the new virNetDevIPInfo object will need to be accessed by a
utility function that calls low level Netlink functions (so we don't
want it to be in the conf directory) and will be called from multiple
hypervisor drivers (so it can't be in any hypervisor directory); the
most appropriate place is thus once again the util directory.

The parse and format functions are in conf/domain_conf.c because only
the domain XML (i.e. *not* the network XML) has this exact combination
of IP addresses plus routes. They will end up being static, but since
they aren't being called yet, they are declared right before their
definition to avoid a "defined but not used" compile error. That will
be changed to static once they are in use. Likewise
virDomainNetIPInfoFormat() will end up being the only caller to
virDomainNetRoutesFormat() and virDomainNetIPsFormat(), so it will
just subsume those functions, but we can't do that until they are no
longer called.

(It would have been nice to include the interface name within the
virNetDevIPInfo object (with a slight name change), but that can't
be done cleanly, because in each case the interface name is provided
in a different place in the XML relative to the routes and IP
addresses, so putting it in this object would actually make the code
more confused rather than simpler).
---
docs/schemas/domaincommon.rng | 27 +++++++++++++++++
src/conf/domain_conf.c | 68 +++++++++++++++++++++++++++++++++++++++++++
src/libvirt_private.syms | 1 +
src/util/virnetdevip.c | 16 ++++++++++
src/util/virnetdevip.h | 11 +++++++
5 files changed, 123 insertions(+)

diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index b81b558..ab89dab 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -2629,6 +2629,33 @@
</optional>
</interleave>
</define>
+
+ <!--
+ All ip-related info for either the host or guest side of an interface
+ -->
+ <define name="interface-ip-info">
+ <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>
+ <zeroOrMore>
+ <ref name="route"/>
+ </zeroOrMore>
+ </define>
<!--
An emulator description is just a path to the binary used for the task
-->
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index f380271..548c750 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -6173,6 +6173,58 @@ virDomainNetIPParseXML(xmlNodePtr node)
return ret;
}

+
+/* fill in a virNetDevIPInfoPtr from the <route> and <ip>
+ * elements found in the given XML context.
+ *
+ * return 0 on success (including none found) and -1 on failure.
+ */
+int
+virDomainNetIPInfoParseXML(const char *source,
+ xmlXPathContextPtr ctxt,
+ virNetDevIPInfoPtr def);
+int
+virDomainNetIPInfoParseXML(const char *source,
+ xmlXPathContextPtr ctxt,
+ virNetDevIPInfoPtr def)
+
+{
+ xmlNodePtr *nodes = NULL;
+ virNetDevIPAddrPtr ip = NULL;
+ virNetDevIPRoutePtr route = NULL;
+ int nnodes;
+ int ret = -1;
+ size_t i;
+
+ if ((nnodes = virXPathNodeSet("./ip", ctxt, &nodes)) < 0)
+ goto cleanup;
+
+ for (i = 0; i < nnodes; i++) {
+ if (!(ip = virDomainNetIPParseXML(nodes[i])) ||
+ VIR_APPEND_ELEMENT(def->ips, def->nips, ip) < 0)
+ goto cleanup;
+ }
+ VIR_FREE(nodes);
+
+ if ((nnodes = virXPathNodeSet("./route", ctxt, &nodes)) < 0)
+ goto cleanup;
+
+ for (i = 0; i < nnodes; i++) {
+ if (!(route = virNetDevIPRouteParseXML(source, nodes[i], ctxt)) ||
+ VIR_APPEND_ELEMENT(def->routes, def->nroutes, route) < 0)
+ goto cleanup;
+ }
+
+ ret = 0;
+ cleanup:
+ if (ret < 0)
+ virNetDevIPInfoClear(def);
+ VIR_FREE(ip);
+ virNetDevIPRouteFree(route);
+ VIR_FREE(nodes);
+ return ret;
+}
+
static int
virDomainHostdevDefParseXMLCaps(xmlNodePtr node ATTRIBUTE_UNUSED,
xmlXPathContextPtr ctxt,
@@ -20311,6 +20363,22 @@ virDomainNetRoutesFormat(virBufferPtr buf,
return 0;
}

+
+int
+virDomainNetIPInfoFormat(virBufferPtr buf,
+ virNetDevIPInfoPtr def);
+int
+virDomainNetIPInfoFormat(virBufferPtr buf,
+ virNetDevIPInfoPtr def)
+{
+ if (virDomainNetIPsFormat(buf, def->ips, def->nips) < 0)
+ return -1;
+ if (virDomainNetRoutesFormat(buf, def->routes, def->nroutes) < 0)
+ return -1;
+ return 0;
+}
+
+
static int
virDomainHostdevDefFormatSubsys(virBufferPtr buf,
virDomainHostdevDefPtr def,
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 151cf9f..f6c3d45 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1925,6 +1925,7 @@ virNetDevBridgeSetVlanFiltering;
virNetDevIPAddrAdd;
virNetDevIPAddrDel;
virNetDevIPAddrGet;
+virNetDevIPInfoClear;
virNetDevIPRouteAdd;
virNetDevIPRouteFree;
virNetDevIPRouteGetAddress;
diff --git a/src/util/virnetdevip.c b/src/util/virnetdevip.c
index 619f926..376d4ad 100644
--- a/src/util/virnetdevip.c
+++ b/src/util/virnetdevip.c
@@ -845,3 +845,19 @@ virNetDevIPRouteGetGateway(virNetDevIPRoutePtr def)
return &def->gateway;
return NULL;
}
+
+/* manipulating the virNetDevIPInfo object */
+
+void
+virNetDevIPInfoClear(virNetDevIPInfoPtr ip)
+{
+ size_t i;
+
+ for (i = 0; i < ip->nips; i++)
+ VIR_FREE(ip->ips[i]);
+ VIR_FREE(ip->ips);
+
+ for (i = 0; i < ip->nroutes; i++)
+ virNetDevIPRouteFree(ip->routes[i]);
+ VIR_FREE(ip->routes);
+}
diff --git a/src/util/virnetdevip.h b/src/util/virnetdevip.h
index 7a07b73..be41636 100644
--- a/src/util/virnetdevip.h
+++ b/src/util/virnetdevip.h
@@ -47,6 +47,14 @@ typedef struct {
virSocketAddr gateway; /* gateway IP address for ip-route */
} virNetDevIPRoute, *virNetDevIPRoutePtr;

+/* A full set of all IP config info for a network device */
+typedef struct {
+ size_t nips;
+ virNetDevIPAddrPtr *ips;
+ size_t nroutes;
+ virNetDevIPRoutePtr *routes;
+} virNetDevIPInfo, *virNetDevIPInfoPtr;
+
/* manipulating/querying the netdev */
int virNetDevIPAddrAdd(const char *ifname,
virSocketAddr *addr,
@@ -76,4 +84,7 @@ int virNetDevIPRouteGetPrefix(virNetDevIPRoutePtr def);
unsigned int virNetDevIPRouteGetMetric(virNetDevIPRoutePtr def);
virSocketAddrPtr virNetDevIPRouteGetGateway(virNetDevIPRoutePtr def);

+/* virNetDevIPInfo object */
+void virNetDevIPInfoClear(virNetDevIPInfoPtr ip);
+
#endif /* __VIR_NETDEVIP_H__ */
--
2.5.5
John Ferlan
2016-06-24 11:44:38 UTC
Permalink
Post by Laine Stump
There are currently two places in the domain where this combination is
used, and there is about to be another. This patch puts them together
for brevity and uniformity.
As with the newly-renamed virNetDevIPAddr and virNetDevIPRoute
objects, the new virNetDevIPInfo object will need to be accessed by a
utility function that calls low level Netlink functions (so we don't
want it to be in the conf directory) and will be called from multiple
hypervisor drivers (so it can't be in any hypervisor directory); the
most appropriate place is thus once again the util directory.
The parse and format functions are in conf/domain_conf.c because only
the domain XML (i.e. *not* the network XML) has this exact combination
of IP addresses plus routes. They will end up being static, but since
they aren't being called yet, they are declared right before their
definition to avoid a "defined but not used" compile error. That will
be changed to static once they are in use. Likewise
virDomainNetIPInfoFormat() will end up being the only caller to
virDomainNetRoutesFormat() and virDomainNetIPsFormat(), so it will
just subsume those functions, but we can't do that until they are no
longer called.
(It would have been nice to include the interface name within the
virNetDevIPInfo object (with a slight name change), but that can't
be done cleanly, because in each case the interface name is provided
in a different place in the XML relative to the routes and IP
addresses, so putting it in this object would actually make the code
more confused rather than simpler).
---
docs/schemas/domaincommon.rng | 27 +++++++++++++++++
src/conf/domain_conf.c | 68 +++++++++++++++++++++++++++++++++++++++++++
src/libvirt_private.syms | 1 +
src/util/virnetdevip.c | 16 ++++++++++
src/util/virnetdevip.h | 11 +++++++
5 files changed, 123 insertions(+)
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index b81b558..ab89dab 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -2629,6 +2629,33 @@
</optional>
</interleave>
</define>
+
+ <!--
+ All ip-related info for either the host or guest side of an interface
+ -->
+ <define name="interface-ip-info">
+ <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>
+ <zeroOrMore>
+ <ref name="route"/>
+ </zeroOrMore>
+ </define>
<!--
An emulator description is just a path to the binary used for the task
-->
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index f380271..548c750 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -6173,6 +6173,58 @@ virDomainNetIPParseXML(xmlNodePtr node)
return ret;
}
+
+/* fill in a virNetDevIPInfoPtr from the <route> and <ip>
+ * elements found in the given XML context.
+ *
+ * return 0 on success (including none found) and -1 on failure.
+ */
+int
+virDomainNetIPInfoParseXML(const char *source,
+ xmlXPathContextPtr ctxt,
+ virNetDevIPInfoPtr def);
Why? If it needs to be "higher" to avoid the forward reference for
future callers, then so be it.
Post by Laine Stump
+int
static int
Post by Laine Stump
+virDomainNetIPInfoParseXML(const char *source,
+ xmlXPathContextPtr ctxt,
+ virNetDevIPInfoPtr def)
+
+{
+ xmlNodePtr *nodes = NULL;
+ virNetDevIPAddrPtr ip = NULL;
+ virNetDevIPRoutePtr route = NULL;
+ int nnodes;
+ int ret = -1;
+ size_t i;
+
+ if ((nnodes = virXPathNodeSet("./ip", ctxt, &nodes)) < 0)
+ goto cleanup;
+
+ for (i = 0; i < nnodes; i++) {
+ if (!(ip = virDomainNetIPParseXML(nodes[i])) ||
+ VIR_APPEND_ELEMENT(def->ips, def->nips, ip) < 0)
+ goto cleanup;
+ }
+ VIR_FREE(nodes);
+
+ if ((nnodes = virXPathNodeSet("./route", ctxt, &nodes)) < 0)
+ goto cleanup;
+
+ for (i = 0; i < nnodes; i++) {
+ if (!(route = virNetDevIPRouteParseXML(source, nodes[i], ctxt)) ||
+ VIR_APPEND_ELEMENT(def->routes, def->nroutes, route) < 0)
+ goto cleanup;
+ }
+
+ ret = 0;
+ if (ret < 0)
+ virNetDevIPInfoClear(def);
+ VIR_FREE(ip);
Seeing just VIR_FREE(ip) made me go look at how it was allocated - guess
I was (now) concerned that something would be allocated into ip that
wasn't free'd properly (eg. no virNetDevIPFree() API ...

Anyway, the ip->address is written with the result of a getaddrinfo in
virSocketAddrParseInternal, which when free'd should be done by
freeaddrinfo, right?

I think this is existing, but fixable... at some point in time.
Post by Laine Stump
+ virNetDevIPRouteFree(route);
+ VIR_FREE(nodes);
+ return ret;
+}
+
static int
virDomainHostdevDefParseXMLCaps(xmlNodePtr node ATTRIBUTE_UNUSED,
xmlXPathContextPtr ctxt,
@@ -20311,6 +20363,22 @@ virDomainNetRoutesFormat(virBufferPtr buf,
return 0;
}
+
+int
+virDomainNetIPInfoFormat(virBufferPtr buf,
+ virNetDevIPInfoPtr def);
Same complaint.
Post by Laine Stump
+int
static int


ACK with the forward ref and static int used. I think you need a "new"
patch at some point in time to handle the getaddrinfo/freeaddrinfo...

John
Post by Laine Stump
+virDomainNetIPInfoFormat(virBufferPtr buf,
+ virNetDevIPInfoPtr def)
+{
+ if (virDomainNetIPsFormat(buf, def->ips, def->nips) < 0)
+ return -1;
+ if (virDomainNetRoutesFormat(buf, def->routes, def->nroutes) < 0)
+ return -1;
+ return 0;
+}
+
+
static int
virDomainHostdevDefFormatSubsys(virBufferPtr buf,
virDomainHostdevDefPtr def,
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 151cf9f..f6c3d45 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1925,6 +1925,7 @@ virNetDevBridgeSetVlanFiltering;
virNetDevIPAddrAdd;
virNetDevIPAddrDel;
virNetDevIPAddrGet;
+virNetDevIPInfoClear;
virNetDevIPRouteAdd;
virNetDevIPRouteFree;
virNetDevIPRouteGetAddress;
diff --git a/src/util/virnetdevip.c b/src/util/virnetdevip.c
index 619f926..376d4ad 100644
--- a/src/util/virnetdevip.c
+++ b/src/util/virnetdevip.c
@@ -845,3 +845,19 @@ virNetDevIPRouteGetGateway(virNetDevIPRoutePtr def)
return &def->gateway;
return NULL;
}
+
+/* manipulating the virNetDevIPInfo object */
+
+void
+virNetDevIPInfoClear(virNetDevIPInfoPtr ip)
+{
+ size_t i;
+
+ for (i = 0; i < ip->nips; i++)
+ VIR_FREE(ip->ips[i]);
+ VIR_FREE(ip->ips);
+
+ for (i = 0; i < ip->nroutes; i++)
+ virNetDevIPRouteFree(ip->routes[i]);
+ VIR_FREE(ip->routes);
+}
diff --git a/src/util/virnetdevip.h b/src/util/virnetdevip.h
index 7a07b73..be41636 100644
--- a/src/util/virnetdevip.h
+++ b/src/util/virnetdevip.h
@@ -47,6 +47,14 @@ typedef struct {
virSocketAddr gateway; /* gateway IP address for ip-route */
} virNetDevIPRoute, *virNetDevIPRoutePtr;
+/* A full set of all IP config info for a network device */
+typedef struct {
+ size_t nips;
+ virNetDevIPAddrPtr *ips;
+ size_t nroutes;
+ virNetDevIPRoutePtr *routes;
+} virNetDevIPInfo, *virNetDevIPInfoPtr;
+
/* manipulating/querying the netdev */
int virNetDevIPAddrAdd(const char *ifname,
virSocketAddr *addr,
@@ -76,4 +84,7 @@ int virNetDevIPRouteGetPrefix(virNetDevIPRoutePtr def);
unsigned int virNetDevIPRouteGetMetric(virNetDevIPRoutePtr def);
virSocketAddrPtr virNetDevIPRouteGetGateway(virNetDevIPRoutePtr def);
+/* virNetDevIPInfo object */
+void virNetDevIPInfoClear(virNetDevIPInfoPtr ip);
+
#endif /* __VIR_NETDEVIP_H__ */
John Ferlan
2016-06-24 12:04:07 UTC
Permalink
[...]

The second cup of caffeine finally started flowing through the veins...
and of course I'm on patch 19...

use

static int ATTRIBUTE_UNUSED
virDomainxxx()
Post by John Ferlan
Post by Laine Stump
+
+/* fill in a virNetDevIPInfoPtr from the <route> and <ip>
+ * elements found in the given XML context.
+ *
+ * return 0 on success (including none found) and -1 on failure.
+ */
+int
+virDomainNetIPInfoParseXML(const char *source,
+ xmlXPathContextPtr ctxt,
+ virNetDevIPInfoPtr def);
Why? If it needs to be "higher" to avoid the forward reference for
future callers, then so be it.
Post by Laine Stump
+int
static int
Post by Laine Stump
+virDomainNetIPInfoParseXML(const char *source,
+ xmlXPathContextPtr ctxt,
+ virNetDevIPInfoPtr def)
+
+{
+ xmlNodePtr *nodes = NULL;
+ virNetDevIPAddrPtr ip = NULL;
+ virNetDevIPRoutePtr route = NULL;
+ int nnodes;
+ int ret = -1;
+ size_t i;
+
+ if ((nnodes = virXPathNodeSet("./ip", ctxt, &nodes)) < 0)
+ goto cleanup;
+
+ for (i = 0; i < nnodes; i++) {
+ if (!(ip = virDomainNetIPParseXML(nodes[i])) ||
+ VIR_APPEND_ELEMENT(def->ips, def->nips, ip) < 0)
+ goto cleanup;
+ }
+ VIR_FREE(nodes);
+
+ if ((nnodes = virXPathNodeSet("./route", ctxt, &nodes)) < 0)
+ goto cleanup;
+
+ for (i = 0; i < nnodes; i++) {
+ if (!(route = virNetDevIPRouteParseXML(source, nodes[i], ctxt)) ||
+ VIR_APPEND_ELEMENT(def->routes, def->nroutes, route) < 0)
+ goto cleanup;
+ }
+
+ ret = 0;
+ if (ret < 0)
+ virNetDevIPInfoClear(def);
+ VIR_FREE(ip);
Seeing just VIR_FREE(ip) made me go look at how it was allocated - guess
I was (now) concerned that something would be allocated into ip that
wasn't free'd properly (eg. no virNetDevIPFree() API ...
Anyway, the ip->address is written with the result of a getaddrinfo in
virSocketAddrParseInternal, which when free'd should be done by
freeaddrinfo, right?
I think this is existing, but fixable... at some point in time.
Post by Laine Stump
+ virNetDevIPRouteFree(route);
+ VIR_FREE(nodes);
+ return ret;
+}
+
static int
virDomainHostdevDefParseXMLCaps(xmlNodePtr node ATTRIBUTE_UNUSED,
xmlXPathContextPtr ctxt,
@@ -20311,6 +20363,22 @@ virDomainNetRoutesFormat(virBufferPtr buf,
return 0;
}
+
+int
+virDomainNetIPInfoFormat(virBufferPtr buf,
+ virNetDevIPInfoPtr def);
Same complaint.
Post by Laine Stump
+int
static int
ACK with the forward ref and static int used. I think you need a "new"
patch at some point in time to handle the getaddrinfo/freeaddrinfo...
John
Post by Laine Stump
+virDomainNetIPInfoFormat(virBufferPtr buf,
+ virNetDevIPInfoPtr def)
+{
+ if (virDomainNetIPsFormat(buf, def->ips, def->nips) < 0)
+ return -1;
+ if (virDomainNetRoutesFormat(buf, def->routes, def->nroutes) < 0)
+ return -1;
+ return 0;
+}
+
+
static int
virDomainHostdevDefFormatSubsys(virBufferPtr buf,
virDomainHostdevDefPtr def,
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 151cf9f..f6c3d45 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1925,6 +1925,7 @@ virNetDevBridgeSetVlanFiltering;
virNetDevIPAddrAdd;
virNetDevIPAddrDel;
virNetDevIPAddrGet;
+virNetDevIPInfoClear;
virNetDevIPRouteAdd;
virNetDevIPRouteFree;
virNetDevIPRouteGetAddress;
diff --git a/src/util/virnetdevip.c b/src/util/virnetdevip.c
index 619f926..376d4ad 100644
--- a/src/util/virnetdevip.c
+++ b/src/util/virnetdevip.c
@@ -845,3 +845,19 @@ virNetDevIPRouteGetGateway(virNetDevIPRoutePtr def)
return &def->gateway;
return NULL;
}
+
+/* manipulating the virNetDevIPInfo object */
+
+void
+virNetDevIPInfoClear(virNetDevIPInfoPtr ip)
+{
+ size_t i;
+
+ for (i = 0; i < ip->nips; i++)
+ VIR_FREE(ip->ips[i]);
+ VIR_FREE(ip->ips);
+
+ for (i = 0; i < ip->nroutes; i++)
+ virNetDevIPRouteFree(ip->routes[i]);
+ VIR_FREE(ip->routes);
+}
diff --git a/src/util/virnetdevip.h b/src/util/virnetdevip.h
index 7a07b73..be41636 100644
--- a/src/util/virnetdevip.h
+++ b/src/util/virnetdevip.h
@@ -47,6 +47,14 @@ typedef struct {
virSocketAddr gateway; /* gateway IP address for ip-route */
} virNetDevIPRoute, *virNetDevIPRoutePtr;
+/* A full set of all IP config info for a network device */
+typedef struct {
+ size_t nips;
+ virNetDevIPAddrPtr *ips;
+ size_t nroutes;
+ virNetDevIPRoutePtr *routes;
+} virNetDevIPInfo, *virNetDevIPInfoPtr;
+
/* manipulating/querying the netdev */
int virNetDevIPAddrAdd(const char *ifname,
virSocketAddr *addr,
@@ -76,4 +84,7 @@ int virNetDevIPRouteGetPrefix(virNetDevIPRoutePtr def);
unsigned int virNetDevIPRouteGetMetric(virNetDevIPRoutePtr def);
virSocketAddrPtr virNetDevIPRouteGetGateway(virNetDevIPRoutePtr def);
+/* virNetDevIPInfo object */
+void virNetDevIPInfoClear(virNetDevIPInfoPtr ip);
+
#endif /* __VIR_NETDEVIP_H__ */
--
libvir-list mailing list
https://www.redhat.com/mailman/listinfo/libvir-list
Laine Stump
2016-06-26 20:56:42 UTC
Permalink
Post by John Ferlan
[...]
The second cup of caffeine finally started flowing through the veins...
and of course I'm on patch 19...
use
static int ATTRIBUTE_UNUSED
virDomainxxx()
Of course! I too was too sleep deprived to consider that might work for
a static function as well.
Laine Stump
2016-06-22 17:37:01 UTC
Permalink
These had been declared in conf/device_conf.h, but then used in
util/virnetdev.c, meaning that we had to #include conf/device_conf.h
in virnetdev.c (which we have for a long time said shouldn't be done.

This caused a bigger problem when I tried to #include util/virnetdev.h
in a file in src/conf (which is allowed) - for some reason the
"device_conf.h: File not found" error.

The solution is to move the data types and functions used in util
sources from conf to util. Some names were adjusted during the move
("virInterface" --> "virNetDevIf", and "VIR_INTERFACE" -->
"VIR_NETDEV_IF")
---
src/conf/device_conf.c | 31 ++++---------------------------
src/conf/device_conf.h | 44 +++-----------------------------------------
src/conf/domain_conf.c | 1 +
src/conf/interface_conf.h | 2 +-
src/conf/node_device_conf.h | 2 +-
src/libvirt_private.syms | 6 ++++--
src/util/virnetdev.c | 31 +++++++++++++++++++++++++++----
src/util/virnetdev.h | 40 ++++++++++++++++++++++++++++++++++++++--
tests/virnetdevtest.c | 14 +++++++-------
9 files changed, 86 insertions(+), 85 deletions(-)

diff --git a/src/conf/device_conf.c b/src/conf/device_conf.c
index 4280513..f58b9d0 100644
--- a/src/conf/device_conf.c
+++ b/src/conf/device_conf.c
@@ -32,29 +32,6 @@

#define VIR_FROM_THIS VIR_FROM_DEVICE

-VIR_ENUM_IMPL(virInterfaceState,
- VIR_INTERFACE_STATE_LAST,
- "" /* value of zero means no state */,
- "unknown", "notpresent",
- "down", "lowerlayerdown",
- "testing", "dormant", "up")
-
-VIR_ENUM_IMPL(virNetDevFeature,
- VIR_NET_DEV_FEAT_LAST,
- "rx",
- "tx",
- "sg",
- "tso",
- "gso",
- "gro",
- "lro",
- "rxvlan",
- "txvlan",
- "ntuple",
- "rxhash",
- "rdma",
- "txudptnl")
-
int virPCIDeviceAddressIsValid(virPCIDeviceAddressPtr addr,
bool report)
{
@@ -196,7 +173,7 @@ virPCIDeviceAddressEqual(virPCIDeviceAddress *addr1,

int
virInterfaceLinkParseXML(xmlNodePtr node,
- virInterfaceLinkPtr lnk)
+ virNetDevIfLinkPtr lnk)
{
int ret = -1;
char *stateStr, *speedStr;
@@ -206,7 +183,7 @@ virInterfaceLinkParseXML(xmlNodePtr node,
speedStr = virXMLPropString(node, "speed");

if (stateStr) {
- if ((state = virInterfaceStateTypeFromString(stateStr)) < 0) {
+ if ((state = virNetDevIfStateTypeFromString(stateStr)) < 0) {
virReportError(VIR_ERR_XML_ERROR,
_("unknown link state: %s"),
stateStr);
@@ -232,7 +209,7 @@ virInterfaceLinkParseXML(xmlNodePtr node,

int
virInterfaceLinkFormat(virBufferPtr buf,
- const virInterfaceLink *lnk)
+ const virNetDevIfLink *lnk)
{
if (!lnk->speed && !lnk->state) {
/* If there's nothing to format, return early. */
@@ -244,7 +221,7 @@ virInterfaceLinkFormat(virBufferPtr buf,
virBufferAsprintf(buf, " speed='%u'", lnk->speed);
if (lnk->state)
virBufferAsprintf(buf, " state='%s'",
- virInterfaceStateTypeToString(lnk->state));
+ virNetDevIfStateTypeToString(lnk->state));
virBufferAddLit(buf, "/>\n");
return 0;
}
diff --git a/src/conf/device_conf.h b/src/conf/device_conf.h
index 847564b..fdd7c3c 100644
--- a/src/conf/device_conf.h
+++ b/src/conf/device_conf.h
@@ -32,45 +32,7 @@
# include "virthread.h"
# include "virbuffer.h"
# include "virpci.h"
-
-typedef enum {
- VIR_INTERFACE_STATE_UNKNOWN = 1,
- VIR_INTERFACE_STATE_NOT_PRESENT,
- VIR_INTERFACE_STATE_DOWN,
- VIR_INTERFACE_STATE_LOWER_LAYER_DOWN,
- VIR_INTERFACE_STATE_TESTING,
- VIR_INTERFACE_STATE_DORMANT,
- VIR_INTERFACE_STATE_UP,
- VIR_INTERFACE_STATE_LAST
-} virInterfaceState;
-
-VIR_ENUM_DECL(virInterfaceState)
-
-typedef struct _virInterfaceLink virInterfaceLink;
-typedef virInterfaceLink *virInterfaceLinkPtr;
-struct _virInterfaceLink {
- virInterfaceState state; /* link state */
- unsigned int speed; /* link speed in Mbits per second */
-};
-
-typedef enum {
- VIR_NET_DEV_FEAT_GRXCSUM,
- VIR_NET_DEV_FEAT_GTXCSUM,
- VIR_NET_DEV_FEAT_GSG,
- VIR_NET_DEV_FEAT_GTSO,
- VIR_NET_DEV_FEAT_GGSO,
- VIR_NET_DEV_FEAT_GGRO,
- VIR_NET_DEV_FEAT_LRO,
- VIR_NET_DEV_FEAT_RXVLAN,
- VIR_NET_DEV_FEAT_TXVLAN,
- VIR_NET_DEV_FEAT_NTUPLE,
- VIR_NET_DEV_FEAT_RXHASH,
- VIR_NET_DEV_FEAT_RDMA,
- VIR_NET_DEV_FEAT_TXUDPTNL,
- VIR_NET_DEV_FEAT_LAST
-} virNetDevFeature;
-
-VIR_ENUM_DECL(virNetDevFeature)
+# include "virnetdev.h"

typedef enum {
VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE,
@@ -216,9 +178,9 @@ bool virPCIDeviceAddressEqual(virPCIDeviceAddress *addr1,
virPCIDeviceAddress *addr2);

int virInterfaceLinkParseXML(xmlNodePtr node,
- virInterfaceLinkPtr lnk);
+ virNetDevIfLinkPtr lnk);

int virInterfaceLinkFormat(virBufferPtr buf,
- const virInterfaceLink *lnk);
+ const virNetDevIfLink *lnk);

#endif /* __DEVICE_CONF_H__ */
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 75ad03f..8ff836c 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -53,6 +53,7 @@
#include "network_conf.h"
#include "virtpm.h"
#include "virstring.h"
+#include "virnetdev.h"

#define VIR_FROM_THIS VIR_FROM_DOMAIN

diff --git a/src/conf/interface_conf.h b/src/conf/interface_conf.h
index ac212fb..5cabec7 100644
--- a/src/conf/interface_conf.h
+++ b/src/conf/interface_conf.h
@@ -147,7 +147,7 @@ struct _virInterfaceDef {
char *name; /* interface name */
unsigned int mtu; /* maximum transmit size in byte */
char *mac; /* MAC address */
- virInterfaceLink lnk; /* interface link info */
+ virNetDevIfLink lnk; /* interface link info */

virInterfaceStartMode startmode; /* how it is started */

diff --git a/src/conf/node_device_conf.h b/src/conf/node_device_conf.h
index be6dd5e..9e3e6fe 100644
--- a/src/conf/node_device_conf.h
+++ b/src/conf/node_device_conf.h
@@ -140,7 +140,7 @@ typedef struct _virNodeDevCapData {
char *address;
unsigned int address_len;
char *ifname;
- virInterfaceLink lnk;
+ virNetDevIfLink lnk;
virNodeDevNetCapType subtype; /* LAST -> no subtype */
virBitmapPtr features; /* enum virNetDevFeature */
} net;
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 00fa673..df2dfc3 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -78,8 +78,6 @@ virCPUModeTypeToString;
# conf/device_conf.h
virInterfaceLinkFormat;
virInterfaceLinkParseXML;
-virInterfaceStateTypeFromString;
-virInterfaceStateTypeToString;
virPCIDeviceAddressEqual;
virPCIDeviceAddressFormat;
virPCIDeviceAddressIsValid;
@@ -1855,6 +1853,8 @@ virNetDevAddRoute;
virNetDevClearIPAddress;
virNetDevDelMulti;
virNetDevExists;
+virNetDevFeatureTypeFromString;
+virNetDevFeatureTypeToString;
virNetDevGetFeatures;
virNetDevGetIndex;
virNetDevGetIPAddress;
@@ -1871,6 +1871,8 @@ virNetDevGetVirtualFunctionIndex;
virNetDevGetVirtualFunctionInfo;
virNetDevGetVirtualFunctions;
virNetDevGetVLanID;
+virNetDevIfStateTypeFromString;
+virNetDevIfStateTypeToString;
virNetDevIsVirtualFunction;
virNetDevReplaceMacAddress;
virNetDevReplaceNetConfig;
diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c
index 4cd51cb..fb71c7b 100644
--- a/src/util/virnetdev.c
+++ b/src/util/virnetdev.c
@@ -2547,10 +2547,33 @@ virNetDevRestoreNetConfig(const char *linkdev ATTRIBUTE_UNUSED,

#endif /* defined(__linux__) && defined(HAVE_LIBNL) */

+VIR_ENUM_IMPL(virNetDevIfState,
+ VIR_NETDEV_IF_STATE_LAST,
+ "" /* value of zero means no state */,
+ "unknown", "notpresent",
+ "down", "lowerlayerdown",
+ "testing", "dormant", "up")
+
+VIR_ENUM_IMPL(virNetDevFeature,
+ VIR_NET_DEV_FEAT_LAST,
+ "rx",
+ "tx",
+ "sg",
+ "tso",
+ "gso",
+ "gro",
+ "lro",
+ "rxvlan",
+ "txvlan",
+ "ntuple",
+ "rxhash",
+ "rdma",
+ "txudptnl")
+
#ifdef __linux__
int
virNetDevGetLinkInfo(const char *ifname,
- virInterfaceLinkPtr lnk)
+ virNetDevIfLinkPtr lnk)
{
int ret = -1;
char *path = NULL;
@@ -2580,7 +2603,7 @@ virNetDevGetLinkInfo(const char *ifname,

/* We shouldn't allow 0 here, because
* virInterfaceState enum starts from 1. */
- if ((tmp_state = virInterfaceStateTypeFromString(buf)) <= 0) {
+ if ((tmp_state = virNetDevIfStateTypeFromString(buf)) <= 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Unable to parse: %s"),
buf);
@@ -2593,7 +2616,7 @@ virNetDevGetLinkInfo(const char *ifname,
* report several misleading values. While igb reports 65535, realtek goes
* with 10. To avoid muddying XML with insane values, don't report link
* speed if that's the case. */
- if (lnk->state != VIR_INTERFACE_STATE_UP) {
+ if (lnk->state != VIR_NETDEV_IF_STATE_UP) {
lnk->speed = 0;
ret = 0;
goto cleanup;
@@ -2638,7 +2661,7 @@ virNetDevGetLinkInfo(const char *ifname,

int
virNetDevGetLinkInfo(const char *ifname,
- virInterfaceLinkPtr lnk)
+ virNetDevIfLinkPtr lnk)
{
/* Port me */
VIR_DEBUG("Getting link info on %s is not implemented on this platform",
diff --git a/src/util/virnetdev.h b/src/util/virnetdev.h
index 522536f..849f8e7 100644
--- a/src/util/virnetdev.h
+++ b/src/util/virnetdev.h
@@ -30,7 +30,6 @@
# include "virmacaddr.h"
# include "virpci.h"
# include "virnetdevvlan.h"
-# include "device_conf.h"

# ifdef HAVE_STRUCT_IFREQ
typedef struct ifreq virIfreq;
@@ -74,6 +73,43 @@ struct _virNetDevRxFilter {
} vlan;
};

+typedef enum {
+ VIR_NETDEV_IF_STATE_UNKNOWN = 1,
+ VIR_NETDEV_IF_STATE_NOT_PRESENT,
+ VIR_NETDEV_IF_STATE_DOWN,
+ VIR_NETDEV_IF_STATE_LOWER_LAYER_DOWN,
+ VIR_NETDEV_IF_STATE_TESTING,
+ VIR_NETDEV_IF_STATE_DORMANT,
+ VIR_NETDEV_IF_STATE_UP,
+ VIR_NETDEV_IF_STATE_LAST
+} virNetDevIfState;
+
+VIR_ENUM_DECL(virNetDevIfState)
+
+typedef struct {
+ virNetDevIfState state; /* link state */
+ unsigned int speed; /* link speed in Mbits per second */
+} virNetDevIfLink, *virNetDevIfLinkPtr;
+
+typedef enum {
+ VIR_NET_DEV_FEAT_GRXCSUM,
+ VIR_NET_DEV_FEAT_GTXCSUM,
+ VIR_NET_DEV_FEAT_GSG,
+ VIR_NET_DEV_FEAT_GTSO,
+ VIR_NET_DEV_FEAT_GGSO,
+ VIR_NET_DEV_FEAT_GGRO,
+ VIR_NET_DEV_FEAT_LRO,
+ VIR_NET_DEV_FEAT_RXVLAN,
+ VIR_NET_DEV_FEAT_TXVLAN,
+ VIR_NET_DEV_FEAT_NTUPLE,
+ VIR_NET_DEV_FEAT_RXHASH,
+ VIR_NET_DEV_FEAT_RDMA,
+ VIR_NET_DEV_FEAT_TXUDPTNL,
+ VIR_NET_DEV_FEAT_LAST
+} virNetDevFeature;
+
+VIR_ENUM_DECL(virNetDevFeature)
+
int virNetDevSetupControl(const char *ifname,
virIfreq *ifr)
ATTRIBUTE_RETURN_CHECK;
@@ -187,7 +223,7 @@ int virNetDevGetFeatures(const char *ifname,
ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;

int virNetDevGetLinkInfo(const char *ifname,
- virInterfaceLinkPtr lnk)
+ virNetDevIfLinkPtr lnk)
ATTRIBUTE_NONNULL(1);

virNetDevRxFilterPtr virNetDevRxFilterNew(void)
diff --git a/tests/virnetdevtest.c b/tests/virnetdevtest.c
index 3987a8a..7c8a03f 100644
--- a/tests/virnetdevtest.c
+++ b/tests/virnetdevtest.c
@@ -30,7 +30,7 @@

struct testVirNetDevGetLinkInfoData {
const char *ifname; /* ifname to get info on */
- virInterfaceState state; /* expected state */
+ virNetDevIfState state; /* expected state */
unsigned int speed; /* expected speed */
};

@@ -39,7 +39,7 @@ testVirNetDevGetLinkInfo(const void *opaque)
{
int ret = -1;
const struct testVirNetDevGetLinkInfoData *data = opaque;
- virInterfaceLink lnk;
+ virNetDevIfLink lnk;

if (virNetDevGetLinkInfo(data->ifname, &lnk) < 0)
goto cleanup;
@@ -47,8 +47,8 @@ testVirNetDevGetLinkInfo(const void *opaque)
if (lnk.state != data->state) {
fprintf(stderr,
"Fetched link state (%s) doesn't match the expected one (%s)",
- virInterfaceStateTypeToString(lnk.state),
- virInterfaceStateTypeToString(data->state));
+ virNetDevIfStateTypeToString(lnk.state),
+ virNetDevIfStateTypeToString(data->state));
goto cleanup;
}

@@ -77,9 +77,9 @@ mymain(void)
ret = -1; \
} while (0)

- DO_TEST_LINK("eth0", VIR_INTERFACE_STATE_UP, 1000);
- DO_TEST_LINK("lo", VIR_INTERFACE_STATE_UNKNOWN, 0);
- DO_TEST_LINK("eth0-broken", VIR_INTERFACE_STATE_DOWN, 0);
+ DO_TEST_LINK("eth0", VIR_NETDEV_IF_STATE_UP, 1000);
+ DO_TEST_LINK("lo", VIR_NETDEV_IF_STATE_UNKNOWN, 0);
+ DO_TEST_LINK("eth0-broken", VIR_NETDEV_IF_STATE_DOWN, 0);

return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}
--
2.5.5
John Ferlan
2016-06-23 20:04:03 UTC
Permalink
Post by Laine Stump
These had been declared in conf/device_conf.h, but then used in
util/virnetdev.c, meaning that we had to #include conf/device_conf.h
in virnetdev.c (which we have for a long time said shouldn't be done.
This caused a bigger problem when I tried to #include util/virnetdev.h
in a file in src/conf (which is allowed) - for some reason the
"device_conf.h: File not found" error.
The solution is to move the data types and functions used in util
sources from conf to util. Some names were adjusted during the move
("virInterface" --> "virNetDevIf", and "VIR_INTERFACE" -->
"VIR_NETDEV_IF")
---
src/conf/device_conf.c | 31 ++++---------------------------
src/conf/device_conf.h | 44 +++-----------------------------------------
src/conf/domain_conf.c | 1 +
src/conf/interface_conf.h | 2 +-
src/conf/node_device_conf.h | 2 +-
src/libvirt_private.syms | 6 ++++--
src/util/virnetdev.c | 31 +++++++++++++++++++++++++++----
src/util/virnetdev.h | 40 ++++++++++++++++++++++++++++++++++++++--
tests/virnetdevtest.c | 14 +++++++-------
9 files changed, 86 insertions(+), 85 deletions(-)
New names seem reasonable to me -

ACK

John
Laine Stump
2016-06-22 17:37:08 UTC
Permalink
We need to clear these out without freeing the object completely.
---
src/conf/domain_conf.c | 14 +++++++++++++-
src/conf/domain_conf.h | 1 +
src/libvirt_private.syms | 1 +
3 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index c5b4815..899b6af 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -1737,7 +1737,8 @@ virDomainActualNetDefFree(virDomainActualNetDefPtr def)
VIR_FREE(def);
}

-void virDomainNetDefFree(virDomainNetDefPtr def)
+void
+virDomainNetDefClear(virDomainNetDefPtr def)
{
size_t i;

@@ -1753,6 +1754,7 @@ void virDomainNetDefFree(virDomainNetDefPtr def)

case VIR_DOMAIN_NET_TYPE_VHOSTUSER:
virDomainChrSourceDefFree(def->data.vhostuser);
+ def->data.vhostuser = NULL;
break;

case VIR_DOMAIN_NET_TYPE_SERVER:
@@ -1767,6 +1769,7 @@ void virDomainNetDefFree(virDomainNetDefPtr def)
VIR_FREE(def->data.network.name);
VIR_FREE(def->data.network.portgroup);
virDomainActualNetDefFree(def->data.network.actual);
+ def->data.network.actual = NULL;
break;

case VIR_DOMAIN_NET_TYPE_BRIDGE:
@@ -1811,10 +1814,19 @@ void virDomainNetDefFree(virDomainNetDefPtr def)

VIR_FREE(def->filter);
virNWFilterHashTableFree(def->filterparams);
+ def->filterparams = NULL;

virNetDevBandwidthFree(def->bandwidth);
+ def->bandwidth = NULL;
virNetDevVlanClear(&def->vlan);
+}

+void
+virDomainNetDefFree(virDomainNetDefPtr def)
+{
+ if (!def)
+ return;
+ virDomainNetDefClear(def);
VIR_FREE(def);
}

diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 8529a78..b9dc174 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2492,6 +2492,7 @@ virDomainControllerDefPtr
virDomainControllerDefNew(virDomainControllerType type);
void virDomainFSDefFree(virDomainFSDefPtr def);
void virDomainActualNetDefFree(virDomainActualNetDefPtr def);
+void virDomainNetDefClear(virDomainNetDefPtr def);
void virDomainNetDefFree(virDomainNetDefPtr def);
void virDomainSmartcardDefFree(virDomainSmartcardDefPtr def);
void virDomainChrDefFree(virDomainChrDefPtr def);
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 36e3901..807ffce 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -372,6 +372,7 @@ virDomainMemoryFindInactiveByDef;
virDomainMemoryInsert;
virDomainMemoryRemove;
virDomainNetAppendIPAddress;
+virDomainNetDefClear;
virDomainNetDefFormat;
virDomainNetDefFree;
virDomainNetFind;
--
2.5.5
John Ferlan
2016-06-23 21:41:45 UTC
Permalink
Post by Laine Stump
We need to clear these out without freeing the object completely.
---
src/conf/domain_conf.c | 14 +++++++++++++-
src/conf/domain_conf.h | 1 +
src/libvirt_private.syms | 1 +
3 files changed, 15 insertions(+), 1 deletion(-)
ACK

John
Laine Stump
2016-06-22 17:37:20 UTC
Permalink
This patch takes the code out of
lxcContainerRenameAndEnableInterfaces() that adds all IP addresses and
IP routes to the interface, and puts it into a utility function
virNetDevIPInfoAddToDev() in virnetdevip.c so that it can be used by
anyone.

One small change in functionality -
lxcContainerRenameAndEnableInterfaces() previously would add all IP
addresses to the interface while it was still offline, then set the
interface online, and then add the routes. Because I don't want the
utility function to set the interface online, I've moved this up so
the interface is first set online, then IP addresses and routes are
added. This is the same order that the network service from
initscripts (in ifup-ether) does it, so it shouldn't pose any problem
(and hasn't, in the tests that I've run).
---
src/libvirt_private.syms | 1 +
src/lxc/lxc_container.c | 46 +++++++++----------------------------
src/util/virnetdevip.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++
src/util/virnetdevip.h | 2 ++
4 files changed, 74 insertions(+), 35 deletions(-)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index f6c3d45..a7f62f8 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1925,6 +1925,7 @@ virNetDevBridgeSetVlanFiltering;
virNetDevIPAddrAdd;
virNetDevIPAddrDel;
virNetDevIPAddrGet;
+virNetDevIPInfoAddToDev;
virNetDevIPInfoClear;
virNetDevIPRouteAdd;
virNetDevIPRouteFree;
diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c
index 09ad8cb..916a37b 100644
--- a/src/lxc/lxc_container.c
+++ b/src/lxc/lxc_container.c
@@ -490,7 +490,7 @@ lxcContainerRenameAndEnableInterfaces(virDomainDefPtr vmDef,
char **veths)
{
int ret = -1;
- size_t i, j;
+ size_t i;
const char *newname;
virDomainNetDefPtr netDef;
bool privNet = vmDef->features[VIR_DOMAIN_FEATURE_PRIVNET] ==
@@ -509,52 +509,28 @@ lxcContainerRenameAndEnableInterfaces(virDomainDefPtr vmDef,

VIR_DEBUG("Renaming %s to %s", veths[i], newname);
if (virNetDevSetName(veths[i], newname) < 0)
- goto cleanup;
-
- for (j = 0; j < netDef->guestIP.nips; j++) {
- virNetDevIPAddrPtr ip = netDef->guestIP.ips[j];
- int prefix;
- char *ipStr = virSocketAddrFormat(&ip->address);
-
- if ((prefix = virSocketAddrGetIPPrefix(&ip->address,
- NULL, ip->prefix)) < 0) {
- ipStr = virSocketAddrFormat(&ip->address);
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("Failed to determine prefix for IP address '%s'"),
- ipStr);
- VIR_FREE(ipStr);
- goto cleanup;
- }
-
- if (virNetDevIPAddrAdd(newname, &ip->address, NULL, prefix) < 0)
- goto cleanup;
- }
+ goto cleanup;

+ /* Only enable this device if there is a reason to do so (either
+ * at least one IP was specified, or link state was set to up in
+ * the config)
+ */
if (netDef->guestIP.nips ||
netDef->linkstate == VIR_DOMAIN_NET_INTERFACE_LINK_STATE_UP) {
VIR_DEBUG("Enabling %s", newname);
if (virNetDevSetOnline(newname, true) < 0)
goto cleanup;
-
- /* Set the routes */
- for (j = 0; j < netDef->guestIP.nroutes; j++) {
- virNetDevIPRoutePtr route = netDef->guestIP.routes[j];
-
- if (virNetDevIPRouteAdd(newname,
- virNetDevIPRouteGetAddress(route),
- virNetDevIPRouteGetPrefix(route),
- virNetDevIPRouteGetGateway(route),
- virNetDevIPRouteGetMetric(route)) < 0) {
- goto cleanup;
- }
- }
}
+
+ /* set IP addresses and routes */
+ if (virNetDevIPInfoAddToDev(newname, &netDef->guestIP) < 0)
+ goto cleanup;
}

/* enable lo device only if there were other net devices */
if ((veths || privNet) &&
virNetDevSetOnline("lo", true) < 0)
- goto cleanup;
+ goto cleanup;

ret = 0;
cleanup:
diff --git a/src/util/virnetdevip.c b/src/util/virnetdevip.c
index dad342f..dad2a78 100644
--- a/src/util/virnetdevip.c
+++ b/src/util/virnetdevip.c
@@ -885,3 +885,63 @@ virNetDevIPInfoClear(virNetDevIPInfoPtr ip)
virNetDevIPRouteFree(ip->routes[i]);
VIR_FREE(ip->routes);
}
+
+
+/**
+ * virNetDevIPInfoAddToDev:
+ * @ifname: name of device to operate on
+ * @ipInfo: list of routes and IP addresses to add to this device
+ *
+ * All IP routes and IP addresses in ipInfo are added to the named device.
+ *
+ * Returns: 0 on success, -1 (and error reported) on failure.
+ */
+int
+virNetDevIPInfoAddToDev(const char *ifname,
+ virNetDevIPInfo const *ipInfo)
+{
+ int ret = -1;
+ size_t i;
+ char *ipStr = NULL;
+ int prefix;
+
+ /* add all IP addresses */
+ for (i = 0; i < ipInfo->nips; i++) {
+ virNetDevIPAddrPtr ip = ipInfo->ips[i];
+
+ ipStr = virSocketAddrFormat(&ip->address);
+ if ((prefix = virSocketAddrGetIPPrefix(&ip->address,
+ NULL, ip->prefix)) < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Failed to determine prefix for IP address '%s'"),
+ ipStr);
+ goto cleanup;
+ }
+ if (virNetDevIPAddrAdd(ifname, &ip->address, NULL, prefix) < 0)
+ goto cleanup;
+ VIR_FREE(ipStr);
+ }
+
+ /* add all routes */
+ for (i = 0; i < ipInfo->nroutes; i++) {
+ virNetDevIPRoutePtr route = ipInfo->routes[i];
+
+ ipStr = virSocketAddrFormat(&route->address);
+ if ((prefix = virNetDevIPRouteGetPrefix(route)) < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Failed to determine prefix for route with destination '%s'"),
+ ipStr);
+ goto cleanup;
+ }
+ if (virNetDevIPRouteAdd(ifname, &route->address, prefix,
+ &route->gateway,
+ virNetDevIPRouteGetMetric(route)) < 0)
+ goto cleanup;
+ VIR_FREE(ipStr);
+ }
+
+ ret = 0;
+ cleanup:
+ VIR_FREE(ipStr);
+ return ret;
+}
diff --git a/src/util/virnetdevip.h b/src/util/virnetdevip.h
index be41636..66c5c00 100644
--- a/src/util/virnetdevip.h
+++ b/src/util/virnetdevip.h
@@ -86,5 +86,7 @@ virSocketAddrPtr virNetDevIPRouteGetGateway(virNetDevIPRoutePtr def);

/* virNetDevIPInfo object */
void virNetDevIPInfoClear(virNetDevIPInfoPtr ip);
+int virNetDevIPInfoAddToDev(const char *ifname,
+ virNetDevIPInfo const *ipInfo);

#endif /* __VIR_NETDEVIP_H__ */
--
2.5.5
John Ferlan
2016-06-24 12:54:02 UTC
Permalink
Post by Laine Stump
This patch takes the code out of
lxcContainerRenameAndEnableInterfaces() that adds all IP addresses and
IP routes to the interface, and puts it into a utility function
virNetDevIPInfoAddToDev() in virnetdevip.c so that it can be used by
anyone.
One small change in functionality -
lxcContainerRenameAndEnableInterfaces() previously would add all IP
addresses to the interface while it was still offline, then set the
interface online, and then add the routes. Because I don't want the
utility function to set the interface online, I've moved this up so
the interface is first set online, then IP addresses and routes are
added. This is the same order that the network service from
initscripts (in ifup-ether) does it, so it shouldn't pose any problem
(and hasn't, in the tests that I've run).
Saw that - was wondering, then I read the commit message. Fine by me...
Post by Laine Stump
---
src/libvirt_private.syms | 1 +
src/lxc/lxc_container.c | 46 +++++++++----------------------------
src/util/virnetdevip.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++
src/util/virnetdevip.h | 2 ++
4 files changed, 74 insertions(+), 35 deletions(-)
Funny/Ironic - this patch fixes the Coverity error I noted in the
previous patch for lxcContainerRenameAndEnableInterfaces

NIT: See below - for virnetipdev.h minor nit.

ACK

John

[...]
Post by Laine Stump
diff --git a/src/util/virnetdevip.h b/src/util/virnetdevip.h
index be41636..66c5c00 100644
--- a/src/util/virnetdevip.h
+++ b/src/util/virnetdevip.h
@@ -86,5 +86,7 @@ virSocketAddrPtr virNetDevIPRouteGetGateway(virNetDevIPRoutePtr def);
/* virNetDevIPInfo object */
void virNetDevIPInfoClear(virNetDevIPInfoPtr ip);
+int virNetDevIPInfoAddToDev(const char *ifname,
^^
Post by Laine Stump
+ virNetDevIPInfo const *ipInfo);
There one extraneous space here... don't forget to align the argument
then too.
Post by Laine Stump
#endif /* __VIR_NETDEVIP_H__ */
Laine Stump
2016-06-22 17:37:25 UTC
Permalink
This will apply to any IP address setting that uses
virNetDevIPInfoAddToDev() (which so far is only the guest-side of LXC
type='ethernet' interfaces).
---
src/util/virnetdevip.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/util/virnetdevip.c b/src/util/virnetdevip.c
index 5daeed5..36de9fb 100644
--- a/src/util/virnetdevip.c
+++ b/src/util/virnetdevip.c
@@ -941,7 +941,7 @@ virNetDevIPInfoAddToDev(const char *ifname,
ipStr);
goto cleanup;
}
- if (virNetDevIPAddrAdd(ifname, &ip->address, NULL, prefix) < 0)
+ if (virNetDevIPAddrAdd(ifname, &ip->address, &ip->peer, prefix) < 0)
goto cleanup;
VIR_FREE(ipStr);
}
--
2.5.5
John Ferlan
2016-06-24 13:52:43 UTC
Permalink
Post by Laine Stump
This will apply to any IP address setting that uses
virNetDevIPInfoAddToDev() (which so far is only the guest-side of LXC
type='ethernet' interfaces).
---
src/util/virnetdevip.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Seems reasonable...

ACK

John
Laine Stump
2016-06-22 17:37:18 UTC
Permalink
virDomainNetIPInfoFormat() and virDomainNetIPInfoParseXML() were
previously defined as global functions (but declared in the .c file
directly above their definition) to avoid the "static function defined
but not called" error during compile. Now that both are used, they can
be properly defined as static functions. And since
virDomainNetIPInfoFormat() is now the only caller of
virDomainNetIPsFormat() and virDomainNetRoutesFormat(), those two
functions can simply be subsumed into virDomainNetIPInfoFormat().
---
src/conf/domain_conf.c | 46 ++++++++++------------------------------------
1 file changed, 10 insertions(+), 36 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 9dcfb57..df52ac9 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -6163,11 +6163,7 @@ virDomainNetIPParseXML(xmlNodePtr node)
*
* return 0 on success (including none found) and -1 on failure.
*/
-int
-virDomainNetIPInfoParseXML(const char *source,
- xmlXPathContextPtr ctxt,
- virNetDevIPInfoPtr def);
-int
+static int
virDomainNetIPInfoParseXML(const char *source,
xmlXPathContextPtr ctxt,
virNetDevIPInfoPtr def)
@@ -20232,14 +20228,16 @@ virDomainFSDefFormat(virBufferPtr buf,
return 0;
}

+
static int
-virDomainNetIPsFormat(virBufferPtr buf, virNetDevIPAddrPtr *ips, size_t nips)
+virDomainNetIPInfoFormat(virBufferPtr buf,
+ virNetDevIPInfoPtr def)
{
size_t i;

/* Output IP addresses */
- for (i = 0; i < nips; i++) {
- virSocketAddrPtr address = &ips[i]->address;
+ for (i = 0; i < def->nips; i++) {
+ virSocketAddrPtr address = &def->ips[i]->address;
char *ipStr = virSocketAddrFormat(address);
const char *familyStr = NULL;

@@ -20254,42 +20252,18 @@ virDomainNetIPsFormat(virBufferPtr buf, virNetDevIPAddrPtr *ips, size_t nips)
VIR_FREE(ipStr);
if (familyStr)
virBufferAsprintf(buf, " family='%s'", familyStr);
- if (ips[i]->prefix != 0)
- virBufferAsprintf(buf, " prefix='%u'", ips[i]->prefix);
+ if (def->ips[i]->prefix)
+ virBufferAsprintf(buf, " prefix='%u'", def->ips[i]->prefix);
virBufferAddLit(buf, "/>\n");
}
- return 0;
-}
-
-static int
-virDomainNetRoutesFormat(virBufferPtr buf,
- virNetDevIPRoutePtr *routes,
- size_t nroutes)
-{
- size_t i;

- for (i = 0; i < nroutes; i++)
- if (virNetDevIPRouteFormat(buf, routes[i]) < 0)
+ for (i = 0; i < def->nroutes; i++)
+ if (virNetDevIPRouteFormat(buf, def->routes[i]) < 0)
return -1;
return 0;
}


-int
-virDomainNetIPInfoFormat(virBufferPtr buf,
- virNetDevIPInfoPtr def);
-int
-virDomainNetIPInfoFormat(virBufferPtr buf,
- virNetDevIPInfoPtr def)
-{
- if (virDomainNetIPsFormat(buf, def->ips, def->nips) < 0)
- return -1;
- if (virDomainNetRoutesFormat(buf, def->routes, def->nroutes) < 0)
- return -1;
- return 0;
-}
-
-
static int
virDomainHostdevDefFormatSubsys(virBufferPtr buf,
virDomainHostdevDefPtr def,
--
2.5.5
John Ferlan
2016-06-24 12:08:44 UTC
Permalink
Post by Laine Stump
virDomainNetIPInfoFormat() and virDomainNetIPInfoParseXML() were
previously defined as global functions (but declared in the .c file
directly above their definition) to avoid the "static function defined
but not called" error during compile. Now that both are used, they can
be properly defined as static functions. And since
virDomainNetIPInfoFormat() is now the only caller of
virDomainNetIPsFormat() and virDomainNetRoutesFormat(), those two
functions can simply be subsumed into virDomainNetIPInfoFormat().
---
src/conf/domain_conf.c | 46 ++++++++++------------------------------------
1 file changed, 10 insertions(+), 36 deletions(-)
See my follow up to other patch - using the ATTRIBUTE_UNUSED for an
unused static function is something I've done in the past.

That then just turns this patch into a "merge" of the Format functions
(and reduces the commit message a bit).

ACK with the adjustments...

John
Laine Stump
2016-06-22 17:37:11 UTC
Permalink
When support for <interface type='ethernet'> was added in commit
9a4b705f back in 2010, it erroneously looked at <source dev='blah'/>
for a user-specified guest-side interface name. This was never
documented though. (that attribute already existed at the time in the
data.ethernet union member of virDomainNetDef, but apparently had no
practical use - it was only used as a storage place for a NetDef's
bridge name during qemuDomainXMLToNative(), but even then that was
never used for anything).

When support for similar guest-side device naming was added to the lxc
driver several years later, it was put in a new subelement <guest
dev='blah'/>.

In the intervening years, since there was no validation that
ethernet.dev was NULL in the other drivers that didn't actually use
it, innocent souls who were adding other features assuming they needed
to account for non-NULL ethernet.dev when really they didn't, so
little bits of the usual pointless cargo-cult code showed up.

This patch not only switches the openvz driver to use the documented
<guest dev='blah'/> notation for naming the guest-side device (just in
case anyone is still using the openvz driver), and logs an error if
anyone tries to set <source dev='blah'/> for a type='ethernet'
interface, it also removes the cargo-cult uses of ethernet.dev and
<source dev='blah'/>, and eliminates if from the RNG and from
virDomainNetDef.

NB: I decided on this course of action after mentioning the
inconsistency here:

https://www.redhat.com/archives/libvir-list/2016-May/msg02038.html

and getting encouragement do eliminate it in a later IRC discussion
with danpb.
---
docs/schemas/domaincommon.rng | 3 ---
src/conf/domain_conf.c | 32 +++++++++++++++++++---------
src/conf/domain_conf.h | 1 -
src/openvz/openvz_driver.c | 5 ++---
src/qemu/qemu_hotplug.c | 6 +-----
tests/xml2sexprdata/xml2sexpr-net-routed.xml | 1 -
6 files changed, 25 insertions(+), 23 deletions(-)

diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 162c2e0..b81b558 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -2142,9 +2142,6 @@
<interleave>
<optional>
<element name="source">
- <attribute name="dev">
- <ref name="deviceName"/>
- </attribute>
<empty/>
</element>
</optional>
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 899b6af..4802e03 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -1749,7 +1749,6 @@ virDomainNetDefClear(virDomainNetDefPtr def)

switch (def->type) {
case VIR_DOMAIN_NET_TYPE_ETHERNET:
- VIR_FREE(def->data.ethernet.dev);
break;

case VIR_DOMAIN_NET_TYPE_VHOSTUSER:
@@ -9004,12 +9003,31 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
def->type == VIR_DOMAIN_NET_TYPE_BRIDGE &&
xmlStrEqual(cur->name, BAD_CAST "source")) {
bridge = virXMLPropString(cur, "bridge");
- } else if (!dev &&
- (def->type == VIR_DOMAIN_NET_TYPE_ETHERNET ||
- def->type == VIR_DOMAIN_NET_TYPE_DIRECT) &&
+ } else if (!dev && def->type == VIR_DOMAIN_NET_TYPE_DIRECT &&
xmlStrEqual(cur->name, BAD_CAST "source")) {
dev = virXMLPropString(cur, "dev");
mode = virXMLPropString(cur, "mode");
+ } else if (!dev && def->type == VIR_DOMAIN_NET_TYPE_ETHERNET &&
+ xmlStrEqual(cur->name, BAD_CAST "source")) {
+ /* This clause is only necessary because from 2010 to
+ * 2016 it was possible (but never documented) to
+ * configure the name of the guest-side interface of
+ * an openvz domain with <source dev='blah'/>. That
+ * was blatant misuse of <source>, so was likely
+ * (hopefully) never used, but just in case there was
+ * somebody using it, we need to generate an error. If
+ * the openvz driver is ever deprecated, this clause
+ * can be removed from here.
+ */
+ if ((dev = virXMLPropString(cur, "dev"))) {
+ virReportError(VIR_ERR_XML_ERROR,
+ _("Invalid attempt to set <interface type='ethernet'> "
+ "device name with <source dev='%s'/>. "
+ "Use <target dev='%s'/> (for host-side) "
+ "or <guest dev='%s'/> (for guest-side) instead."),
+ dev, dev, dev);
+ goto error;
+ }
} else if (!vhostuser_path && !vhostuser_mode && !vhostuser_type
&& def->type == VIR_DOMAIN_NET_TYPE_VHOSTUSER &&
xmlStrEqual(cur->name, BAD_CAST "source")) {
@@ -9260,10 +9278,6 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
break;

case VIR_DOMAIN_NET_TYPE_ETHERNET:
- if (dev != NULL) {
- def->data.ethernet.dev = dev;
- dev = NULL;
- }
break;

case VIR_DOMAIN_NET_TYPE_BRIDGE:
@@ -20787,8 +20801,6 @@ virDomainNetDefFormat(virBufferPtr buf,
break;

case VIR_DOMAIN_NET_TYPE_ETHERNET:
- virBufferEscapeString(buf, "<source dev='%s'/>\n",
- def->data.ethernet.dev);
break;

case VIR_DOMAIN_NET_TYPE_VHOSTUSER:
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index b9dc174..e93bd5c 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -931,7 +931,6 @@ struct _virDomainNetDef {
} backend;
union {
struct {
- char *dev;
} ethernet;
virDomainChrSourceDefPtr vhostuser;
struct {
diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c
index b66883f..b114246 100644
--- a/src/openvz/openvz_driver.c
+++ b/src/openvz/openvz_driver.c
@@ -862,9 +862,8 @@ openvzDomainSetNetwork(virConnectPtr conn, const char *vpsid,

/* if net is ethernet and the user has specified guest interface name,
* let's use it; otherwise generate a new one */
- if (net->type == VIR_DOMAIN_NET_TYPE_ETHERNET &&
- net->data.ethernet.dev != NULL) {
- if (VIR_STRDUP(guest_ifname, net->data.ethernet.dev) == -1)
+ if (net->ifname_guest) {
+ if (VIR_STRDUP(guest_ifname, net->ifname_guest) < 0)
goto cleanup;
} else {
guest_ifname = openvzGenerateContainerVethName(veid);
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index f695903..e0b8230 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -2345,11 +2345,7 @@ qemuDomainChangeNet(virQEMUDriverPtr driver,
break;

case VIR_DOMAIN_NET_TYPE_ETHERNET:
- if (STRNEQ_NULLABLE(olddev->data.ethernet.dev,
- newdev->data.ethernet.dev)) {
- needReconnect = true;
- }
- break;
+ break;

case VIR_DOMAIN_NET_TYPE_SERVER:
case VIR_DOMAIN_NET_TYPE_CLIENT:
diff --git a/tests/xml2sexprdata/xml2sexpr-net-routed.xml b/tests/xml2sexprdata/xml2sexpr-net-routed.xml
index f34dbaa..2adc3a7 100644
--- a/tests/xml2sexprdata/xml2sexpr-net-routed.xml
+++ b/tests/xml2sexprdata/xml2sexpr-net-routed.xml
@@ -20,7 +20,6 @@
<interface type="ethernet">
<mac address="00:11:22:33:44:55"/>
<ip address="172.14.5.6"/>
- <source dev="eth3"/>
<script path="vif-routed"/>
<target dev="vif4.0"/>
</interface>
--
2.5.5
John Ferlan
2016-06-23 22:14:57 UTC
Permalink
Post by Laine Stump
When support for <interface type='ethernet'> was added in commit
9a4b705f back in 2010, it erroneously looked at <source dev='blah'/>
for a user-specified guest-side interface name. This was never
documented though. (that attribute already existed at the time in the
data.ethernet union member of virDomainNetDef, but apparently had no
practical use - it was only used as a storage place for a NetDef's
bridge name during qemuDomainXMLToNative(), but even then that was
never used for anything).
When support for similar guest-side device naming was added to the lxc
driver several years later, it was put in a new subelement <guest
dev='blah'/>.
In the intervening years, since there was no validation that
ethernet.dev was NULL in the other drivers that didn't actually use
it, innocent souls who were adding other features assuming they needed
to account for non-NULL ethernet.dev when really they didn't, so
little bits of the usual pointless cargo-cult code showed up.
This patch not only switches the openvz driver to use the documented
<guest dev='blah'/> notation for naming the guest-side device (just in
case anyone is still using the openvz driver), and logs an error if
anyone tries to set <source dev='blah'/> for a type='ethernet'
interface, it also removes the cargo-cult uses of ethernet.dev and
<source dev='blah'/>, and eliminates if from the RNG and from
virDomainNetDef.
NB: I decided on this course of action after mentioning the
https://www.redhat.com/archives/libvir-list/2016-May/msg02038.html
and getting encouragement do eliminate it in a later IRC discussion
with danpb.
---
docs/schemas/domaincommon.rng | 3 ---
src/conf/domain_conf.c | 32 +++++++++++++++++++---------
src/conf/domain_conf.h | 1 -
src/openvz/openvz_driver.c | 5 ++---
src/qemu/qemu_hotplug.c | 6 +-----
tests/xml2sexprdata/xml2sexpr-net-routed.xml | 1 -
6 files changed, 25 insertions(+), 23 deletions(-)
I'll be impressed if someone finds your needle-in-the-haystack message
in virDomainNetDefParseXML regarding openvz driver and deprecation. My
only words of wisdom there are - could it cause a guest to disappear now
that previously was visible? I'm all for keeping it as written here
though, but there could be someone else needing some TUMS.
Post by Laine Stump
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 162c2e0..b81b558 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -2142,9 +2142,6 @@
<interleave>
<optional>
<element name="source">
- <attribute name="dev">
- <ref name="deviceName"/>
- </attribute>
<empty/>
</element>
</optional>
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 899b6af..4802e03 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -1749,7 +1749,6 @@ virDomainNetDefClear(virDomainNetDefPtr def)
switch (def->type) {
- VIR_FREE(def->data.ethernet.dev);
break;
@@ -9004,12 +9003,31 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
def->type == VIR_DOMAIN_NET_TYPE_BRIDGE &&
xmlStrEqual(cur->name, BAD_CAST "source")) {
bridge = virXMLPropString(cur, "bridge");
- } else if (!dev &&
- (def->type == VIR_DOMAIN_NET_TYPE_ETHERNET ||
- def->type == VIR_DOMAIN_NET_TYPE_DIRECT) &&
+ } else if (!dev && def->type == VIR_DOMAIN_NET_TYPE_DIRECT &&
xmlStrEqual(cur->name, BAD_CAST "source")) {
dev = virXMLPropString(cur, "dev");
mode = virXMLPropString(cur, "mode");
+ } else if (!dev && def->type == VIR_DOMAIN_NET_TYPE_ETHERNET &&
+ xmlStrEqual(cur->name, BAD_CAST "source")) {
+ /* This clause is only necessary because from 2010 to
+ * 2016 it was possible (but never documented) to
+ * configure the name of the guest-side interface of
+ * an openvz domain with <source dev='blah'/>. That
+ * was blatant misuse of <source>, so was likely
+ * (hopefully) never used, but just in case there was
+ * somebody using it, we need to generate an error. If
+ * the openvz driver is ever deprecated, this clause
+ * can be removed from here.
+ */
+ if ((dev = virXMLPropString(cur, "dev"))) {
+ virReportError(VIR_ERR_XML_ERROR,
+ _("Invalid attempt to set <interface type='ethernet'> "
+ "device name with <source dev='%s'/>. "
+ "Use <target dev='%s'/> (for host-side) "
+ "or <guest dev='%s'/> (for guest-side) instead."),
+ dev, dev, dev);
+ goto error;
+ }
} else if (!vhostuser_path && !vhostuser_mode && !vhostuser_type
&& def->type == VIR_DOMAIN_NET_TYPE_VHOSTUSER &&
xmlStrEqual(cur->name, BAD_CAST "source")) {
@@ -9260,10 +9278,6 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
break;
- if (dev != NULL) {
- def->data.ethernet.dev = dev;
- dev = NULL;
- }
break;
@@ -20787,8 +20801,6 @@ virDomainNetDefFormat(virBufferPtr buf,
break;
- virBufferEscapeString(buf, "<source dev='%s'/>\n",
- def->data.ethernet.dev);
break;
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index b9dc174..e93bd5c 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -931,7 +931,6 @@ struct _virDomainNetDef {
} backend;
union {
struct {
- char *dev;
} ethernet;
So an empty ethernet struct is OK?

If this was removed, then the RNG would need adjustment as well.
Post by Laine Stump
virDomainChrSourceDefPtr vhostuser;
struct {
diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c
index b66883f..b114246 100644
--- a/src/openvz/openvz_driver.c
+++ b/src/openvz/openvz_driver.c
@@ -862,9 +862,8 @@ openvzDomainSetNetwork(virConnectPtr conn, const char *vpsid,
/* if net is ethernet and the user has specified guest interface name,
* let's use it; otherwise generate a new one */
- if (net->type == VIR_DOMAIN_NET_TYPE_ETHERNET &&
- net->data.ethernet.dev != NULL) {
- if (VIR_STRDUP(guest_ifname, net->data.ethernet.dev) == -1)
+ if (net->ifname_guest) {
+ if (VIR_STRDUP(guest_ifname, net->ifname_guest) < 0)
I believe VIR_STRDUP does the right thing, no need for the "if ()"

virStrdup()

*dest = NULL;
if (!src)
return 0;
Post by Laine Stump
goto cleanup;
} else {
guest_ifname = openvzGenerateContainerVethName(veid);
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index f695903..e0b8230 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -2345,11 +2345,7 @@ qemuDomainChangeNet(virQEMUDriverPtr driver,
break;
You could move this up with the VIR_DOMAIN_NET_TYPE_USER since both just
break; - your call on that.


ACK in principle... Although I don't think you need that ethernet struct
any more.


John
Post by Laine Stump
- if (STRNEQ_NULLABLE(olddev->data.ethernet.dev,
- newdev->data.ethernet.dev)) {
- needReconnect = true;
- }
- break;
+ break;
diff --git a/tests/xml2sexprdata/xml2sexpr-net-routed.xml b/tests/xml2sexprdata/xml2sexpr-net-routed.xml
index f34dbaa..2adc3a7 100644
--- a/tests/xml2sexprdata/xml2sexpr-net-routed.xml
+++ b/tests/xml2sexprdata/xml2sexpr-net-routed.xml
@@ -20,7 +20,6 @@
<interface type="ethernet">
<mac address="00:11:22:33:44:55"/>
<ip address="172.14.5.6"/>
- <source dev="eth3"/>
<script path="vif-routed"/>
<target dev="vif4.0"/>
</interface>
Laine Stump
2016-06-24 19:35:42 UTC
Permalink
Post by John Ferlan
Post by Laine Stump
When support for <interface type='ethernet'> was added in commit
9a4b705f back in 2010, it erroneously looked at <source dev='blah'/>
for a user-specified guest-side interface name. This was never
documented though. (that attribute already existed at the time in the
data.ethernet union member of virDomainNetDef, but apparently had no
practical use - it was only used as a storage place for a NetDef's
bridge name during qemuDomainXMLToNative(), but even then that was
never used for anything).
When support for similar guest-side device naming was added to the lxc
driver several years later, it was put in a new subelement <guest
dev='blah'/>.
In the intervening years, since there was no validation that
ethernet.dev was NULL in the other drivers that didn't actually use
it, innocent souls who were adding other features assuming they needed
to account for non-NULL ethernet.dev when really they didn't, so
little bits of the usual pointless cargo-cult code showed up.
This patch not only switches the openvz driver to use the documented
<guest dev='blah'/> notation for naming the guest-side device (just in
case anyone is still using the openvz driver), and logs an error if
anyone tries to set <source dev='blah'/> for a type='ethernet'
interface, it also removes the cargo-cult uses of ethernet.dev and
<source dev='blah'/>, and eliminates if from the RNG and from
virDomainNetDef.
NB: I decided on this course of action after mentioning the
https://www.redhat.com/archives/libvir-list/2016-May/msg02038.html
and getting encouragement do eliminate it in a later IRC discussion
with danpb.
---
docs/schemas/domaincommon.rng | 3 ---
src/conf/domain_conf.c | 32 +++++++++++++++++++---------
src/conf/domain_conf.h | 1 -
src/openvz/openvz_driver.c | 5 ++---
src/qemu/qemu_hotplug.c | 6 +-----
tests/xml2sexprdata/xml2sexpr-net-routed.xml | 1 -
6 files changed, 25 insertions(+), 23 deletions(-)
I'll be impressed if someone finds your needle-in-the-haystack message
in virDomainNetDefParseXML regarding openvz driver and deprecation. My
only words of wisdom there are - could it cause a guest to disappear now
that previously was visible? I'm all for keeping it as written here
though, but there could be someone else needing some TUMS.
Post by Laine Stump
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 162c2e0..b81b558 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -2142,9 +2142,6 @@
<interleave>
<optional>
<element name="source">
- <attribute name="dev">
- <ref name="deviceName"/>
- </attribute>
<empty/>
</element>
</optional>
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 899b6af..4802e03 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -1749,7 +1749,6 @@ virDomainNetDefClear(virDomainNetDefPtr def)
switch (def->type) {
- VIR_FREE(def->data.ethernet.dev);
break;
@@ -9004,12 +9003,31 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
def->type == VIR_DOMAIN_NET_TYPE_BRIDGE &&
xmlStrEqual(cur->name, BAD_CAST "source")) {
bridge = virXMLPropString(cur, "bridge");
- } else if (!dev &&
- (def->type == VIR_DOMAIN_NET_TYPE_ETHERNET ||
- def->type == VIR_DOMAIN_NET_TYPE_DIRECT) &&
+ } else if (!dev && def->type == VIR_DOMAIN_NET_TYPE_DIRECT &&
xmlStrEqual(cur->name, BAD_CAST "source")) {
dev = virXMLPropString(cur, "dev");
mode = virXMLPropString(cur, "mode");
+ } else if (!dev && def->type == VIR_DOMAIN_NET_TYPE_ETHERNET &&
+ xmlStrEqual(cur->name, BAD_CAST "source")) {
+ /* This clause is only necessary because from 2010 to
+ * 2016 it was possible (but never documented) to
+ * configure the name of the guest-side interface of
+ * an openvz domain with <source dev='blah'/>. That
+ * was blatant misuse of <source>, so was likely
+ * (hopefully) never used, but just in case there was
+ * somebody using it, we need to generate an error. If
+ * the openvz driver is ever deprecated, this clause
+ * can be removed from here.
+ */
+ if ((dev = virXMLPropString(cur, "dev"))) {
+ virReportError(VIR_ERR_XML_ERROR,
+ _("Invalid attempt to set <interface type='ethernet'> "
+ "device name with <source dev='%s'/>. "
+ "Use <target dev='%s'/> (for host-side) "
+ "or <guest dev='%s'/> (for guest-side) instead."),
+ dev, dev, dev);
+ goto error;
+ }
} else if (!vhostuser_path && !vhostuser_mode && !vhostuser_type
&& def->type == VIR_DOMAIN_NET_TYPE_VHOSTUSER &&
xmlStrEqual(cur->name, BAD_CAST "source")) {
@@ -9260,10 +9278,6 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
break;
- if (dev != NULL) {
- def->data.ethernet.dev = dev;
- dev = NULL;
- }
break;
@@ -20787,8 +20801,6 @@ virDomainNetDefFormat(virBufferPtr buf,
break;
- virBufferEscapeString(buf, "<source dev='%s'/>\n",
- def->data.ethernet.dev);
break;
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index b9dc174..e93bd5c 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -931,7 +931,6 @@ struct _virDomainNetDef {
} backend;
union {
struct {
- char *dev;
} ethernet;
So an empty ethernet struct is OK?
Yep. And I had plans to use it again later (see below)
Post by John Ferlan
If this was removed, then the RNG would need adjustment as well.
Look up above. dev was removed from <source> for type ethernet (but
<source> was left in the RNG, because I *will* be using that)
Post by John Ferlan
Post by Laine Stump
virDomainChrSourceDefPtr vhostuser;
struct {
diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c
index b66883f..b114246 100644
--- a/src/openvz/openvz_driver.c
+++ b/src/openvz/openvz_driver.c
@@ -862,9 +862,8 @@ openvzDomainSetNetwork(virConnectPtr conn, const char *vpsid,
/* if net is ethernet and the user has specified guest interface name,
* let's use it; otherwise generate a new one */
- if (net->type == VIR_DOMAIN_NET_TYPE_ETHERNET &&
- net->data.ethernet.dev != NULL) {
- if (VIR_STRDUP(guest_ifname, net->data.ethernet.dev) == -1)
+ if (net->ifname_guest) {
+ if (VIR_STRDUP(guest_ifname, net->ifname_guest) < 0)
I believe VIR_STRDUP does the right thing, no need for the "if ()"
virStrdup()
*dest = NULL;
if (!src)
return 0;
Nice! I'll do that.
Post by John Ferlan
Post by Laine Stump
goto cleanup;
} else {
guest_ifname = openvzGenerateContainerVethName(veid);
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index f695903..e0b8230 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -2345,11 +2345,7 @@ qemuDomainChangeNet(virQEMUDriverPtr driver,
break;
You could move this up with the VIR_DOMAIN_NET_TYPE_USER since both just
break; - your call on that.
When I wrote this patch, I was intending that something new would be
added into the ethernet struct of the union in a followup patch, so I
left all of the *_ETHERNET things in place (and also the ethernet struct
itself). I later changed my mind at the last minute and decided that the
new item (hostIP) should be in the common part of the object rather than
in the ethernet-specific part of the union, so these switch cases and
the struct in the union remain unused for now. I wanted to leave them
that way in case there was any sentiment toward keeping hostIP exclusive
to the ethernet part of the union.
Post by John Ferlan
ACK in principle... Although I don't think you need that ethernet struct
any more.
John
Post by Laine Stump
- if (STRNEQ_NULLABLE(olddev->data.ethernet.dev,
- newdev->data.ethernet.dev)) {
- needReconnect = true;
- }
- break;
+ break;
diff --git a/tests/xml2sexprdata/xml2sexpr-net-routed.xml b/tests/xml2sexprdata/xml2sexpr-net-routed.xml
index f34dbaa..2adc3a7 100644
--- a/tests/xml2sexprdata/xml2sexpr-net-routed.xml
+++ b/tests/xml2sexprdata/xml2sexpr-net-routed.xml
@@ -20,7 +20,6 @@
<interface type="ethernet">
<mac address="00:11:22:33:44:55"/>
<ip address="172.14.5.6"/>
- <source dev="eth3"/>
<script path="vif-routed"/>
<target dev="vif4.0"/>
</interface>
Laine Stump
2016-06-24 20:10:20 UTC
Permalink
Post by Laine Stump
Post by John Ferlan
Post by Laine Stump
When support for <interface type='ethernet'> was added in commit
9a4b705f back in 2010, it erroneously looked at <source dev='blah'/>
for a user-specified guest-side interface name. This was never
documented though. (that attribute already existed at the time in the
data.ethernet union member of virDomainNetDef, but apparently had no
practical use - it was only used as a storage place for a NetDef's
bridge name during qemuDomainXMLToNative(), but even then that was
never used for anything).
When support for similar guest-side device naming was added to the lxc
driver several years later, it was put in a new subelement <guest
dev='blah'/>.
In the intervening years, since there was no validation that
ethernet.dev was NULL in the other drivers that didn't actually use
it, innocent souls who were adding other features assuming they needed
to account for non-NULL ethernet.dev when really they didn't, so
little bits of the usual pointless cargo-cult code showed up.
This patch not only switches the openvz driver to use the documented
<guest dev='blah'/> notation for naming the guest-side device (just in
case anyone is still using the openvz driver), and logs an error if
anyone tries to set <source dev='blah'/> for a type='ethernet'
interface, it also removes the cargo-cult uses of ethernet.dev and
<source dev='blah'/>, and eliminates if from the RNG and from
virDomainNetDef.
NB: I decided on this course of action after mentioning the
https://www.redhat.com/archives/libvir-list/2016-May/msg02038.html
and getting encouragement do eliminate it in a later IRC discussion
with danpb.
---
docs/schemas/domaincommon.rng | 3 ---
src/conf/domain_conf.c | 32
+++++++++++++++++++---------
src/conf/domain_conf.h | 1 -
src/openvz/openvz_driver.c | 5 ++---
src/qemu/qemu_hotplug.c | 6 +-----
tests/xml2sexprdata/xml2sexpr-net-routed.xml | 1 -
6 files changed, 25 insertions(+), 23 deletions(-)
I'll be impressed if someone finds your needle-in-the-haystack message
in virDomainNetDefParseXML regarding openvz driver and deprecation. My
only words of wisdom there are - could it cause a guest to disappear now
that previously was visible? I'm all for keeping it as written here
though, but there could be someone else needing some TUMS.
Post by Laine Stump
diff --git a/docs/schemas/domaincommon.rng
b/docs/schemas/domaincommon.rng
index 162c2e0..b81b558 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -2142,9 +2142,6 @@
<interleave>
<optional>
<element name="source">
- <attribute name="dev">
- <ref name="deviceName"/>
- </attribute>
<empty/>
</element>
</optional>
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 899b6af..4802e03 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -1749,7 +1749,6 @@ virDomainNetDefClear(virDomainNetDefPtr def)
switch (def->type) {
- VIR_FREE(def->data.ethernet.dev);
break;
@@ -9004,12 +9003,31 @@
virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
def->type == VIR_DOMAIN_NET_TYPE_BRIDGE &&
xmlStrEqual(cur->name, BAD_CAST "source")) {
bridge = virXMLPropString(cur, "bridge");
- } else if (!dev &&
- (def->type == VIR_DOMAIN_NET_TYPE_ETHERNET ||
- def->type == VIR_DOMAIN_NET_TYPE_DIRECT) &&
+ } else if (!dev && def->type ==
VIR_DOMAIN_NET_TYPE_DIRECT &&
xmlStrEqual(cur->name, BAD_CAST "source")) {
dev = virXMLPropString(cur, "dev");
mode = virXMLPropString(cur, "mode");
+ } else if (!dev && def->type ==
VIR_DOMAIN_NET_TYPE_ETHERNET &&
+ xmlStrEqual(cur->name, BAD_CAST "source")) {
+ /* This clause is only necessary because from 2010 to
+ * 2016 it was possible (but never documented) to
+ * configure the name of the guest-side interface of
+ * an openvz domain with <source dev='blah'/>. That
+ * was blatant misuse of <source>, so was likely
+ * (hopefully) never used, but just in case there was
+ * somebody using it, we need to generate an error. If
+ * the openvz driver is ever deprecated, this clause
+ * can be removed from here.
+ */
+ if ((dev = virXMLPropString(cur, "dev"))) {
+ virReportError(VIR_ERR_XML_ERROR,
+ _("Invalid attempt to set
<interface type='ethernet'> "
+ "device name with <source dev='%s'/>. "
+ "Use <target dev='%s'/> (for host-side) "
+ "or <guest dev='%s'/> (for
guest-side) instead."),
+ dev, dev, dev);
+ goto error;
+ }
} else if (!vhostuser_path && !vhostuser_mode && !vhostuser_type
&& def->type ==
VIR_DOMAIN_NET_TYPE_VHOSTUSER &&
xmlStrEqual(cur->name, BAD_CAST "source")) {
@@ -9260,10 +9278,6 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
break;
- if (dev != NULL) {
- def->data.ethernet.dev = dev;
- dev = NULL;
- }
break;
@@ -20787,8 +20801,6 @@ virDomainNetDefFormat(virBufferPtr buf,
break;
- virBufferEscapeString(buf, "<source dev='%s'/>\n",
- def->data.ethernet.dev);
break;
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index b9dc174..e93bd5c 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -931,7 +931,6 @@ struct _virDomainNetDef {
} backend;
union {
struct {
- char *dev;
} ethernet;
So an empty ethernet struct is OK?
Yep. And I had plans to use it again later (see below)
Okay, I decided to remove it after all since I don't need it. If someone
needs it in the future they can add it back.
Post by Laine Stump
Post by John Ferlan
If this was removed, then the RNG would need adjustment as well.
Look up above. dev was removed from <source> for type ethernet (but
<source> was left in the RNG, because I *will* be using that)
Post by John Ferlan
Post by Laine Stump
virDomainChrSourceDefPtr vhostuser;
struct {
diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c
index b66883f..b114246 100644
--- a/src/openvz/openvz_driver.c
+++ b/src/openvz/openvz_driver.c
@@ -862,9 +862,8 @@ openvzDomainSetNetwork(virConnectPtr conn, const char *vpsid,
/* if net is ethernet and the user has specified guest interface name,
* let's use it; otherwise generate a new one */
- if (net->type == VIR_DOMAIN_NET_TYPE_ETHERNET &&
- net->data.ethernet.dev != NULL) {
- if (VIR_STRDUP(guest_ifname, net->data.ethernet.dev) == -1)
+ if (net->ifname_guest) {
+ if (VIR_STRDUP(guest_ifname, net->ifname_guest) < 0)
I believe VIR_STRDUP does the right thing, no need for the "if ()"
virStrdup()
*dest = NULL;
if (!src)
return 0;
Nice! I'll do that.
Well, except that I set guest_ifname in a different manner in the else
clause of the if (net->ifname_guest), so it's really more clear if I
leave it as is.
Post by Laine Stump
Post by John Ferlan
Post by Laine Stump
goto cleanup;
} else {
guest_ifname = openvzGenerateContainerVethName(veid);
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index f695903..e0b8230 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -2345,11 +2345,7 @@ qemuDomainChangeNet(virQEMUDriverPtr driver,
break;
You could move this up with the VIR_DOMAIN_NET_TYPE_USER since both just
break; - your call on that.
When I wrote this patch, I was intending that something new would be
added into the ethernet struct of the union in a followup patch, so I
left all of the *_ETHERNET things in place (and also the ethernet
struct itself). I later changed my mind at the last minute and decided
that the new item (hostIP) should be in the common part of the object
rather than in the ethernet-specific part of the union, so these
switch cases and the struct in the union remain unused for now. I
wanted to leave them that way in case there was any sentiment toward
keeping hostIP exclusive to the ethernet part of the union.
...and now I've decided to merge them all in with the other NOP cases.
Post by Laine Stump
Post by John Ferlan
ACK in principle... Although I don't think you need that ethernet struct
any more.
John
Post by Laine Stump
- if (STRNEQ_NULLABLE(olddev->data.ethernet.dev,
- newdev->data.ethernet.dev)) {
- needReconnect = true;
- }
- break;
+ break;
diff --git a/tests/xml2sexprdata/xml2sexpr-net-routed.xml
b/tests/xml2sexprdata/xml2sexpr-net-routed.xml
index f34dbaa..2adc3a7 100644
--- a/tests/xml2sexprdata/xml2sexpr-net-routed.xml
+++ b/tests/xml2sexprdata/xml2sexpr-net-routed.xml
@@ -20,7 +20,6 @@
<interface type="ethernet">
<mac address="00:11:22:33:44:55"/>
<ip address="172.14.5.6"/>
- <source dev="eth3"/>
<script path="vif-routed"/>
<target dev="vif4.0"/>
</interface>
--
libvir-list mailing list
https://www.redhat.com/mailman/listinfo/libvir-list
Laine Stump
2016-06-22 17:37:16 UTC
Permalink
All the same information was already there, just in slightly different
places in the virDomainNetDef.
---
docs/schemas/domaincommon.rng | 22 +------------------
src/conf/domain_conf.c | 50 ++++++-------------------------------------
src/conf/domain_conf.h | 7 ++----
src/libxl/libxl_conf.c | 10 ++++-----
src/libxl/libxl_domain.c | 2 +-
src/lxc/lxc_container.c | 10 ++++-----
src/lxc/lxc_native.c | 12 +++++------
src/openvz/openvz_driver.c | 10 ++++-----
src/uml/uml_conf.c | 4 ++--
src/vbox/vbox_common.c | 6 +++---
src/vz/vz_sdk.c | 2 +-
src/xenconfig/xen_common.c | 12 +++++------
src/xenconfig/xen_sxpr.c | 12 +++++------
13 files changed, 49 insertions(+), 110 deletions(-)

diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 38590a6..563cb3c 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -2420,27 +2420,7 @@
<empty/>
</element>
</optional>
- <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>
- <zeroOrMore>
- <ref name="route"/>
- </zeroOrMore>
+ <ref name="interface-ip-info"/>
<optional>
<element name="script">
<attribute name="path">
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 7072f86..9dcfb57 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -1740,8 +1740,6 @@ virDomainActualNetDefFree(virDomainActualNetDefPtr def)
void
virDomainNetDefClear(virDomainNetDefPtr def)
{
- size_t i;
-
if (!def)
return;

@@ -1801,14 +1799,7 @@ virDomainNetDefClear(virDomainNetDefPtr def)
VIR_FREE(def->ifname_guest);
VIR_FREE(def->ifname_guest_actual);

- for (i = 0; i < def->nips; i++)
- VIR_FREE(def->ips[i]);
- VIR_FREE(def->ips);
-
- for (i = 0; i < def->nroutes; i++)
- virNetDevIPRouteFree(def->routes[i]);
- VIR_FREE(def->routes);
-
+ virNetDevIPInfoClear(&def->guestIP);
virDomainDeviceInfoClear(&def->info);

VIR_FREE(def->filter);
@@ -8890,7 +8881,7 @@ virDomainNetAppendIPAddress(virDomainNetDefPtr def,
goto error;
ipDef->prefix = prefix;

- if (VIR_APPEND_ELEMENT(def->ips, def->nips, ipDef) < 0)
+ if (VIR_APPEND_ELEMENT(def->guestIP.ips, def->guestIP.nips, ipDef) < 0)
goto error;

return 0;
@@ -8952,11 +8943,6 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
virDomainActualNetDefPtr actual = NULL;
xmlNodePtr oldnode = ctxt->node;
int ret, val;
- size_t i;
- size_t nips = 0;
- virNetDevIPAddrPtr *ips = NULL;
- size_t nroutes = 0;
- virNetDevIPRoutePtr *routes = NULL;

if (VIR_ALLOC(def) < 0)
return NULL;
@@ -9072,24 +9058,6 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
localport = virXPathString("string(./local/@port)", ctxt);
ctxt->node = tmpnode;
}
- } else if (xmlStrEqual(cur->name, BAD_CAST "ip")) {
- virNetDevIPAddrPtr ip = NULL;
-
- if (!(ip = virDomainNetIPParseXML(cur)))
- goto error;
-
- if (VIR_APPEND_ELEMENT(ips, nips, ip) < 0)
- goto error;
- } else if (xmlStrEqual(cur->name, BAD_CAST "route")) {
- virNetDevIPRoutePtr route = NULL;
- if (!(route = virNetDevIPRouteParseXML(_("Domain interface"),
- cur, ctxt)))
- goto error;
-
- if (VIR_APPEND_ELEMENT(routes, nroutes, route) < 0) {
- virNetDevIPRouteFree(route);
- goto error;
- }
} else if (!ifname &&
xmlStrEqual(cur->name, BAD_CAST "target")) {
ifname = virXMLPropString(cur, "dev");
@@ -9412,12 +9380,9 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
break;
}

- for (i = 0; i < nips; i++) {
- if (VIR_APPEND_ELEMENT(def->ips, def->nips, ips[i]) < 0)
- goto error;
- }
- def->nroutes = nroutes;
- def->routes = routes;
+ if (virDomainNetIPInfoParseXML(_("guest interface"),
+ ctxt, &def->guestIP) < 0)
+ goto error;

if (script != NULL) {
def->script = script;
@@ -9699,7 +9664,6 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
VIR_FREE(addrtype);
VIR_FREE(domain_name);
VIR_FREE(trustGuestRxFilters);
- VIR_FREE(ips);
VIR_FREE(vhost_path);
VIR_FREE(localaddr);
VIR_FREE(localport);
@@ -20891,9 +20855,7 @@ virDomainNetDefFormat(virBufferPtr buf,
return -1;
}

- if (virDomainNetIPsFormat(buf, def->ips, def->nips) < 0)
- return -1;
- if (virDomainNetRoutesFormat(buf, def->routes, def->nroutes) < 0)
+ if (virDomainNetIPInfoFormat(buf, &def->guestIP) < 0)
return -1;

virBufferEscapeString(buf, "<script path='%s'/>\n",
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 0c723de..0df5579 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -966,8 +966,9 @@ struct _virDomainNetDef {
char *script;
char *domain_name; /* backend domain name */
char *ifname;
- char *ifname_guest;
char *ifname_guest_actual;
+ char *ifname_guest;
+ virNetDevIPInfo guestIP;
virDomainDeviceInfo info;
char *filter;
virNWFilterHashTablePtr filterparams;
@@ -975,10 +976,6 @@ struct _virDomainNetDef {
virNetDevVlan vlan;
int trustGuestRxFilters; /* enum virTristateBool */
int linkstate;
- size_t nips;
- virNetDevIPAddrPtr *ips;
- size_t nroutes;
- virNetDevIPRoutePtr *routes;
};

/* Used for prefix of ifname of any network name generated dynamically
diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c
index 5989819..eb10156 100644
--- a/src/libxl/libxl_conf.c
+++ b/src/libxl/libxl_conf.c
@@ -1,7 +1,7 @@
/*
* libxl_conf.c: libxl configuration management
*
- * Copyright (C) 2012-2014 Red Hat, Inc.
+ * Copyright (C) 2012-2014, 2016 Red Hat, Inc.
* Copyright (c) 2011-2013 SUSE LINUX Products GmbH, Nuernberg, Germany.
* Copyright (C) 2011 Univention GmbH.
*
@@ -908,8 +908,8 @@ libxlMakeNic(virDomainDefPtr def,
case VIR_DOMAIN_NET_TYPE_ETHERNET:
if (VIR_STRDUP(x_nic->script, l_nic->script) < 0)
goto cleanup;
- if (l_nic->nips > 0) {
- x_nic->ip = virSocketAddrFormat(&l_nic->ips[0]->address);
+ if (l_nic->guestIP.nips > 0) {
+ x_nic->ip = virSocketAddrFormat(&l_nic->guestIP.ips[0]->address);
if (!x_nic->ip)
goto cleanup;
}
@@ -924,8 +924,8 @@ libxlMakeNic(virDomainDefPtr def,
goto cleanup;
}

- if (l_nic->nips > 0) {
- x_nic->ip = virSocketAddrFormat(&l_nic->ips[0]->address);
+ if (l_nic->guestIP.nips > 0) {
+ x_nic->ip = virSocketAddrFormat(&l_nic->guestIP.ips[0]->address);
if (!x_nic->ip)
goto cleanup;
}
diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c
index 221af87..6f76cae 100644
--- a/src/libxl/libxl_domain.c
+++ b/src/libxl/libxl_domain.c
@@ -296,7 +296,7 @@ libxlDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
(dev->data.net->type == VIR_DOMAIN_NET_TYPE_BRIDGE ||
dev->data.net->type == VIR_DOMAIN_NET_TYPE_ETHERNET ||
dev->data.net->type == VIR_DOMAIN_NET_TYPE_NETWORK)) {
- if (dev->data.net->nips > 1) {
+ if (dev->data.net->guestIP.nips > 1) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("multiple IP addresses not supported on device type %s"),
virDomainNetTypeToString(dev->data.net->type));
diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c
index 1000d88..a5ced92 100644
--- a/src/lxc/lxc_container.c
+++ b/src/lxc/lxc_container.c
@@ -512,8 +512,8 @@ static int lxcContainerRenameAndEnableInterfaces(virDomainDefPtr vmDef,
if (rc < 0)
goto error_out;

- for (j = 0; j < netDef->nips; j++) {
- virNetDevIPAddrPtr ip = netDef->ips[j];
+ for (j = 0; j < netDef->guestIP.nips; j++) {
+ virNetDevIPAddrPtr ip = netDef->guestIP.ips[j];
int prefix;
char *ipStr = virSocketAddrFormat(&ip->address);

@@ -537,7 +537,7 @@ static int lxcContainerRenameAndEnableInterfaces(virDomainDefPtr vmDef,
VIR_FREE(ipStr);
}

- if (netDef->nips ||
+ if (netDef->guestIP.nips ||
netDef->linkstate == VIR_DOMAIN_NET_INTERFACE_LINK_STATE_UP) {
VIR_DEBUG("Enabling %s", newname);
rc = virNetDevSetOnline(newname, true);
@@ -545,8 +545,8 @@ static int lxcContainerRenameAndEnableInterfaces(virDomainDefPtr vmDef,
goto error_out;

/* Set the routes */
- for (j = 0; j < netDef->nroutes; j++) {
- virNetDevIPRoutePtr route = netDef->routes[j];
+ for (j = 0; j < netDef->guestIP.nroutes; j++) {
+ virNetDevIPRoutePtr route = netDef->guestIP.routes[j];

if (virNetDevIPRouteAdd(newname,
virNetDevIPRouteGetAddress(route),
diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c
index f074f03..e1dde3a 100644
--- a/src/lxc/lxc_native.c
+++ b/src/lxc/lxc_native.c
@@ -522,19 +522,19 @@ lxcAddNetworkDefinition(lxcNetworkParseData *data)
data->name)))
goto error;

- net->ips = data->ips;
- net->nips = data->nips;
+ net->guestIP.ips = data->ips;
+ net->guestIP.nips = data->nips;

if (data->gateway_ipv4 &&
lxcAddNetworkRouteDefinition(data->gateway_ipv4, AF_INET,
- &net->routes,
- &net->nroutes) < 0)
+ &net->guestIP.routes,
+ &net->guestIP.nroutes) < 0)
goto error;

if (data->gateway_ipv6 &&
lxcAddNetworkRouteDefinition(data->gateway_ipv6, AF_INET6,
- &net->routes,
- &net->nroutes) < 0)
+ &net->guestIP.routes,
+ &net->guestIP.nroutes) < 0)
goto error;

if (VIR_EXPAND_N(data->def->nets, data->def->nnets, 1) < 0)
diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c
index b114246..48c264b 100644
--- a/src/openvz/openvz_driver.c
+++ b/src/openvz/openvz_driver.c
@@ -1,7 +1,7 @@
/*
* openvz_driver.c: core driver methods for managing OpenVZ VEs
*
- * Copyright (C) 2010-2015 Red Hat, Inc.
+ * Copyright (C) 2010-2016 Red Hat, Inc.
* Copyright (C) 2006, 2007 Binary Karma
* Copyright (C) 2006 Shuveb Hussain
* Copyright (C) 2007 Anoop Joe Cyriac
@@ -856,7 +856,7 @@ openvzDomainSetNetwork(virConnectPtr conn, const char *vpsid,

if (net->type == VIR_DOMAIN_NET_TYPE_BRIDGE ||
(net->type == VIR_DOMAIN_NET_TYPE_ETHERNET &&
- net->nips == 0)) {
+ net->guestIP.nips == 0)) {
virBuffer buf = VIR_BUFFER_INITIALIZER;
int veid = openvzGetVEID(vpsid);

@@ -906,12 +906,12 @@ openvzDomainSetNetwork(virConnectPtr conn, const char *vpsid,
virCommandAddArg(cmd, "--netif_add");
virCommandAddArgBuffer(cmd, &buf);
} else if (net->type == VIR_DOMAIN_NET_TYPE_ETHERNET &&
- net->nips > 0) {
+ net->guestIP.nips > 0) {
size_t i;

/* --ipadd ip */
- for (i = 0; i < net->nips; i++) {
- char *ipStr = virSocketAddrFormat(&net->ips[i]->address);
+ for (i = 0; i < net->guestIP.nips; i++) {
+ char *ipStr = virSocketAddrFormat(&net->guestIP.ips[i]->address);
if (!ipStr)
goto cleanup;
virCommandAddArgList(cmd, "--ipadd", ipStr, NULL);
diff --git a/src/uml/uml_conf.c b/src/uml/uml_conf.c
index a97ae64..dc68203 100644
--- a/src/uml/uml_conf.c
+++ b/src/uml/uml_conf.c
@@ -1,7 +1,7 @@
/*
* uml_conf.c: UML driver configuration
*
- * Copyright (C) 2006-2014 Red Hat, Inc.
+ * Copyright (C) 2006-2014, 2016 Red Hat, Inc.
* Copyright (C) 2006 Daniel P. Berrange
*
* This library is free software; you can redistribute it and/or
@@ -173,7 +173,7 @@ umlBuildCommandLineNet(virConnectPtr conn,
virBufferAddLit(&buf, "tuntap,");
if (def->ifname)
virBufferAdd(&buf, def->ifname, -1);
- if (def->nips > 0) {
+ if (def->guestIP.nips > 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("IP address not supported for ethernet interface"));
goto error;
diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 6dd5b9c..8e49268 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -1313,11 +1313,11 @@ vboxAttachNetwork(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine)
} else if (def->nets[i]->type == VIR_DOMAIN_NET_TYPE_BRIDGE) {
VIR_DEBUG("NIC(%zu): brname: %s", i, def->nets[i]->data.bridge.brname);
VIR_DEBUG("NIC(%zu): script: %s", i, def->nets[i]->script);
- if (def->nets[i]->nips == 1) {
- char *ipStr = virSocketAddrFormat(&def->nets[i]->ips[0]->address);
+ if (def->nets[i]->guestIP.nips == 1) {
+ char *ipStr = virSocketAddrFormat(&def->nets[i]->guestIP.ips[0]->address);
VIR_DEBUG("NIC(%zu): ipaddr: %s", i, ipStr);
VIR_FREE(ipStr);
- } else if (def->nets[i]->nips > 1) {
+ } else if (def->nets[i]->guestIP.nips > 1) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Driver does not support setting multiple IP addresses"));
return -1;
diff --git a/src/vz/vz_sdk.c b/src/vz/vz_sdk.c
index cb06240..5c92f97 100644
--- a/src/vz/vz_sdk.c
+++ b/src/vz/vz_sdk.c
@@ -2566,7 +2566,7 @@ static int prlsdkCheckNetUnsupportedParams(virDomainNetDefPtr net)
return -1;
}

- if (net->ifname_guest) {
+ if (net->guestIf.name) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Setting guest interface name is not "
"supported by vz driver."));
diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c
index 2fe29fd..f62a5b1 100644
--- a/src/xenconfig/xen_common.c
+++ b/src/xenconfig/xen_common.c
@@ -1153,11 +1153,11 @@ xenFormatNet(virConnectPtr conn,
switch (net->type) {
case VIR_DOMAIN_NET_TYPE_BRIDGE:
virBufferAsprintf(&buf, ",bridge=%s", net->data.bridge.brname);
- if (net->nips == 1) {
- char *ipStr = virSocketAddrFormat(&net->ips[0]->address);
+ if (net->guestIP.nips == 1) {
+ char *ipStr = virSocketAddrFormat(&net->guestIP.ips[0]->address);
virBufferAsprintf(&buf, ",ip=%s", ipStr);
VIR_FREE(ipStr);
- } else if (net->nips > 1) {
+ } else if (net->guestIP.nips > 1) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Driver does not support setting multiple IP addresses"));
goto cleanup;
@@ -1168,11 +1168,11 @@ xenFormatNet(virConnectPtr conn,
case VIR_DOMAIN_NET_TYPE_ETHERNET:
if (net->script)
virBufferAsprintf(&buf, ",script=%s", net->script);
- if (net->nips == 1) {
- char *ipStr = virSocketAddrFormat(&net->ips[0]->address);
+ if (net->guestIP.nips == 1) {
+ char *ipStr = virSocketAddrFormat(&net->guestIP.ips[0]->address);
virBufferAsprintf(&buf, ",ip=%s", ipStr);
VIR_FREE(ipStr);
- } else if (net->nips > 1) {
+ } else if (net->guestIP.nips > 1) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Driver does not support setting multiple IP addresses"));
goto cleanup;
diff --git a/src/xenconfig/xen_sxpr.c b/src/xenconfig/xen_sxpr.c
index 21de1a2..ea6c177 100644
--- a/src/xenconfig/xen_sxpr.c
+++ b/src/xenconfig/xen_sxpr.c
@@ -1875,11 +1875,11 @@ xenFormatSxprNet(virConnectPtr conn,
script = def->script;

virBufferEscapeSexpr(buf, "(script '%s')", script);
- if (def->nips == 1) {
- char *ipStr = virSocketAddrFormat(&def->ips[0]->address);
+ if (def->guestIP.nips == 1) {
+ char *ipStr = virSocketAddrFormat(&def->guestIP.ips[0]->address);
virBufferEscapeSexpr(buf, "(ip '%s')", ipStr);
VIR_FREE(ipStr);
- } else if (def->nips > 1) {
+ } else if (def->guestIP.nips > 1) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Driver does not support setting multiple IP addresses"));
return -1;
@@ -1916,11 +1916,11 @@ xenFormatSxprNet(virConnectPtr conn,
if (def->script)
virBufferEscapeSexpr(buf, "(script '%s')",
def->script);
- if (def->nips == 1) {
- char *ipStr = virSocketAddrFormat(&def->ips[0]->address);
+ if (def->guestIP.nips == 1) {
+ char *ipStr = virSocketAddrFormat(&def->guestIP.ips[0]->address);
virBufferEscapeSexpr(buf, "(ip '%s')", ipStr);
VIR_FREE(ipStr);
- } else if (def->nips > 1) {
+ } else if (def->guestIP.nips > 1) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Driver does not support setting multiple IP addresses"));
return -1;
--
2.5.5
John Ferlan
2016-06-24 11:57:25 UTC
Permalink
Post by Laine Stump
All the same information was already there, just in slightly different
places in the virDomainNetDef.
---
docs/schemas/domaincommon.rng | 22 +------------------
src/conf/domain_conf.c | 50 ++++++-------------------------------------
src/conf/domain_conf.h | 7 ++----
src/libxl/libxl_conf.c | 10 ++++-----
src/libxl/libxl_domain.c | 2 +-
src/lxc/lxc_container.c | 10 ++++-----
src/lxc/lxc_native.c | 12 +++++------
src/openvz/openvz_driver.c | 10 ++++-----
src/uml/uml_conf.c | 4 ++--
src/vbox/vbox_common.c | 6 +++---
src/vz/vz_sdk.c | 2 +-
src/xenconfig/xen_common.c | 12 +++++------
src/xenconfig/xen_sxpr.c | 12 +++++------
13 files changed, 49 insertions(+), 110 deletions(-)
ACK

John
Laine Stump
2016-06-22 17:37:00 UTC
Permalink
virNetDevLinkDump should have been in virnetlink.c, but that file
didn't exist yet when the function was created. It didn't really
matter until now - I found that having virnetlink.h included by
virnetdev.h caused build problems when trying to #include virnetdev.h
in a .c file in src/conf (due to missing directory in -I). Rather than
fix that to further institutionalize the incorrect placement of this
one function, this patch moves the function.
---
src/libvirt_private.syms | 2 +-
src/util/virnetdev.c | 134 +-------------------------------------
src/util/virnetdev.h | 6 --
src/util/virnetdevvportprofile.c | 4 +-
src/util/virnetlink.c | 135 +++++++++++++++++++++++++++++++++++++++
src/util/virnetlink.h | 5 ++
6 files changed, 145 insertions(+), 141 deletions(-)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 501c23e..00fa673 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1872,7 +1872,6 @@ virNetDevGetVirtualFunctionInfo;
virNetDevGetVirtualFunctions;
virNetDevGetVLanID;
virNetDevIsVirtualFunction;
-virNetDevLinkDump;
virNetDevReplaceMacAddress;
virNetDevReplaceNetConfig;
virNetDevRestoreMacAddress;
@@ -1986,6 +1985,7 @@ virNetDevVPortProfileOpTypeToString;
# util/virnetlink.h
virNetlinkCommand;
virNetlinkDelLink;
+virNetlinkDumpLink;
virNetlinkEventAddClient;
virNetlinkEventRemoveClient;
virNetlinkEventServiceIsRunning;
diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c
index 5a4ccc6..4cd51cb 100644
--- a/src/util/virnetdev.c
+++ b/src/util/virnetdev.c
@@ -23,6 +23,7 @@
#include <config.h>

#include "virnetdev.h"
+#include "virnetlink.h"
#include "virmacaddr.h"
#include "virfile.h"
#include "virerror.h"
@@ -2086,124 +2087,6 @@ static struct nla_policy ifla_vf_policy[IFLA_VF_MAX+1] = {
.maxlen = sizeof(struct ifla_vf_vlan) },
};

-/**
- * virNetDevLinkDump:
- *
- * @ifname: The name of the interface; only use if ifindex <= 0
- * @ifindex: The interface index; may be <= 0 if ifname is given
- * @data: Gets a pointer to the raw data from netlink.
- MUST BE FREED BY CALLER!
- * @nlattr: Pointer to a pointer of netlink attributes that will contain
- * the results
- * @src_pid: pid used for nl_pid of the local end of the netlink message
- * (0 == "use getpid()")
- * @dst_pid: pid of destination nl_pid if the kernel
- * is not the target of the netlink message but it is to be
- * sent to another process (0 if sending to the kernel)
- *
- * Get information from netlink about an interface given its name or index.
- *
- * Returns 0 on success, -1 on fatal error.
- */
-int
-virNetDevLinkDump(const char *ifname, int ifindex,
- void **nlData, struct nlattr **tb,
- uint32_t src_pid, uint32_t dst_pid)
-{
- int rc = -1;
- struct nlmsghdr *resp = NULL;
- struct nlmsgerr *err;
- struct ifinfomsg ifinfo = {
- .ifi_family = AF_UNSPEC,
- .ifi_index = ifindex
- };
- unsigned int recvbuflen;
- struct nl_msg *nl_msg;
-
- if (ifname && ifindex <= 0 && virNetDevGetIndex(ifname, &ifindex) < 0)
- return -1;
-
- ifinfo.ifi_index = ifindex;
-
- nl_msg = nlmsg_alloc_simple(RTM_GETLINK, NLM_F_REQUEST);
- if (!nl_msg) {
- virReportOOMError();
- return -1;
- }
-
- if (nlmsg_append(nl_msg, &ifinfo, sizeof(ifinfo), NLMSG_ALIGNTO) < 0)
- goto buffer_too_small;
-
- if (ifname) {
- if (nla_put(nl_msg, IFLA_IFNAME, strlen(ifname)+1, ifname) < 0)
- goto buffer_too_small;
- }
-
-# ifdef RTEXT_FILTER_VF
- /* if this filter exists in the kernel's netlink implementation,
- * we need to set it, otherwise the response message will not
- * contain the IFLA_VFINFO_LIST that we're looking for.
- */
- {
- uint32_t ifla_ext_mask = RTEXT_FILTER_VF;
-
- if (nla_put(nl_msg, IFLA_EXT_MASK,
- sizeof(ifla_ext_mask), &ifla_ext_mask) < 0) {
- goto buffer_too_small;
- }
- }
-# endif
-
- if (virNetlinkCommand(nl_msg, &resp, &recvbuflen,
- src_pid, dst_pid, NETLINK_ROUTE, 0) < 0)
- goto cleanup;
-
- if (recvbuflen < NLMSG_LENGTH(0) || resp == NULL)
- goto malformed_resp;
-
- switch (resp->nlmsg_type) {
- case NLMSG_ERROR:
- err = (struct nlmsgerr *)NLMSG_DATA(resp);
- if (resp->nlmsg_len < NLMSG_LENGTH(sizeof(*err)))
- goto malformed_resp;
-
- if (err->error) {
- virReportSystemError(-err->error,
- _("error dumping %s (%d) interface"),
- ifname, ifindex);
- goto cleanup;
- }
- break;
-
- case GENL_ID_CTRL:
- case NLMSG_DONE:
- rc = nlmsg_parse(resp, sizeof(struct ifinfomsg),
- tb, IFLA_MAX, NULL);
- if (rc < 0)
- goto malformed_resp;
- break;
-
- default:
- goto malformed_resp;
- }
- rc = 0;
- cleanup:
- nlmsg_free(nl_msg);
- if (rc < 0)
- VIR_FREE(resp);
- *nlData = resp;
- return rc;
-
- malformed_resp:
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("malformed netlink response message"));
- goto cleanup;
-
- buffer_too_small:
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("allocated netlink buffer is too small"));
- goto cleanup;
-}

static int
virNetDevSetVfConfig(const char *ifname, int ifindex, int vf,
@@ -2398,7 +2281,7 @@ virNetDevGetVfConfig(const char *ifname, int vf, virMacAddrPtr mac,
struct nlattr *tb[IFLA_MAX + 1] = {NULL, };
int ifindex = -1;

- rc = virNetDevLinkDump(ifname, ifindex, &nlData, tb, 0, 0);
+ rc = virNetlinkDumpLink(ifname, ifindex, &nlData, tb, 0, 0);
if (rc < 0)
goto cleanup;

@@ -2640,19 +2523,6 @@ virNetDevRestoreNetConfig(const char *linkdev, int vf, const char *stateDir)
#else /* defined(__linux__) && defined(HAVE_LIBNL) */

int
-virNetDevLinkDump(const char *ifname ATTRIBUTE_UNUSED,
- int ifindex ATTRIBUTE_UNUSED,
- void **nlData ATTRIBUTE_UNUSED,
- struct nlattr **tb ATTRIBUTE_UNUSED,
- uint32_t src_pid ATTRIBUTE_UNUSED,
- uint32_t dst_pid ATTRIBUTE_UNUSED)
-{
- virReportSystemError(ENOSYS, "%s",
- _("Unable to dump link info on this platform"));
- return -1;
-}
-
-int
virNetDevReplaceNetConfig(const char *linkdev ATTRIBUTE_UNUSED,
int vf ATTRIBUTE_UNUSED,
const virMacAddr *macaddress ATTRIBUTE_UNUSED,
diff --git a/src/util/virnetdev.h b/src/util/virnetdev.h
index cbe7938..522536f 100644
--- a/src/util/virnetdev.h
+++ b/src/util/virnetdev.h
@@ -27,7 +27,6 @@

# include "virbitmap.h"
# include "virsocketaddr.h"
-# include "virnetlink.h"
# include "virmacaddr.h"
# include "virpci.h"
# include "virnetdevvlan.h"
@@ -170,11 +169,6 @@ int virNetDevGetVirtualFunctions(const char *pfname,
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3)
ATTRIBUTE_NONNULL(4) ATTRIBUTE_NONNULL(5) ATTRIBUTE_RETURN_CHECK;

-int virNetDevLinkDump(const char *ifname, int ifindex,
- void **nlData, struct nlattr **tb,
- uint32_t src_pid, uint32_t dst_pid)
- ATTRIBUTE_RETURN_CHECK;
-
int virNetDevReplaceNetConfig(const char *linkdev, int vf,
const virMacAddr *macaddress,
virNetDevVlanPtr vlan,
diff --git a/src/util/virnetdevvportprofile.c b/src/util/virnetdevvportprofile.c
index 8100656..db495a7 100644
--- a/src/util/virnetdevvportprofile.c
+++ b/src/util/virnetdevvportprofile.c
@@ -880,7 +880,7 @@ virNetDevVPortProfileGetNthParent(const char *ifname, int ifindex, unsigned int

while (!end && i <= nthParent) {
VIR_FREE(nlData);
- rc = virNetDevLinkDump(ifname, ifindex, &nlData, tb, 0, 0);
+ rc = virNetlinkDumpLink(ifname, ifindex, &nlData, tb, 0, 0);
if (rc < 0)
break;

@@ -964,7 +964,7 @@ virNetDevVPortProfileOpCommon(const char *ifname, int ifindex,

while (--repeats >= 0) {
VIR_FREE(nlData);
- rc = virNetDevLinkDump(NULL, ifindex, &nlData, tb, src_pid, dst_pid);
+ rc = virNetlinkDumpLink(NULL, ifindex, &nlData, tb, src_pid, dst_pid);
if (rc < 0)
goto cleanup;

diff --git a/src/util/virnetlink.c b/src/util/virnetlink.c
index 513f36e..a5d10fa 100644
--- a/src/util/virnetlink.c
+++ b/src/util/virnetlink.c
@@ -36,6 +36,7 @@
#include <sys/socket.h>

#include "virnetlink.h"
+#include "virnetdev.h"
#include "virlog.h"
#include "viralloc.h"
#include "virthread.h"
@@ -316,6 +317,126 @@ int virNetlinkCommand(struct nl_msg *nl_msg,


/**
+ * virNetlinkDumpLink:
+ *
+ * @ifname: The name of the interface; only use if ifindex <= 0
+ * @ifindex: The interface index; may be <= 0 if ifname is given
+ * @data: Gets a pointer to the raw data from netlink.
+ MUST BE FREED BY CALLER!
+ * @nlattr: Pointer to a pointer of netlink attributes that will contain
+ * the results
+ * @src_pid: pid used for nl_pid of the local end of the netlink message
+ * (0 == "use getpid()")
+ * @dst_pid: pid of destination nl_pid if the kernel
+ * is not the target of the netlink message but it is to be
+ * sent to another process (0 if sending to the kernel)
+ *
+ * Get information from netlink about an interface given its name or index.
+ *
+ * Returns 0 on success, -1 on fatal error.
+ */
+int
+virNetlinkDumpLink(const char *ifname, int ifindex,
+ void **nlData, struct nlattr **tb,
+ uint32_t src_pid, uint32_t dst_pid)
+{
+ int rc = -1;
+ struct nlmsghdr *resp = NULL;
+ struct nlmsgerr *err;
+ struct ifinfomsg ifinfo = {
+ .ifi_family = AF_UNSPEC,
+ .ifi_index = ifindex
+ };
+ unsigned int recvbuflen;
+ struct nl_msg *nl_msg;
+
+ if (ifname && ifindex <= 0 && virNetDevGetIndex(ifname, &ifindex) < 0)
+ return -1;
+
+ ifinfo.ifi_index = ifindex;
+
+ nl_msg = nlmsg_alloc_simple(RTM_GETLINK, NLM_F_REQUEST);
+ if (!nl_msg) {
+ virReportOOMError();
+ return -1;
+ }
+
+ if (nlmsg_append(nl_msg, &ifinfo, sizeof(ifinfo), NLMSG_ALIGNTO) < 0)
+ goto buffer_too_small;
+
+ if (ifname) {
+ if (nla_put(nl_msg, IFLA_IFNAME, strlen(ifname)+1, ifname) < 0)
+ goto buffer_too_small;
+ }
+
+# ifdef RTEXT_FILTER_VF
+ /* if this filter exists in the kernel's netlink implementation,
+ * we need to set it, otherwise the response message will not
+ * contain the IFLA_VFINFO_LIST that we're looking for.
+ */
+ {
+ uint32_t ifla_ext_mask = RTEXT_FILTER_VF;
+
+ if (nla_put(nl_msg, IFLA_EXT_MASK,
+ sizeof(ifla_ext_mask), &ifla_ext_mask) < 0) {
+ goto buffer_too_small;
+ }
+ }
+# endif
+
+ if (virNetlinkCommand(nl_msg, &resp, &recvbuflen,
+ src_pid, dst_pid, NETLINK_ROUTE, 0) < 0)
+ goto cleanup;
+
+ if (recvbuflen < NLMSG_LENGTH(0) || resp == NULL)
+ goto malformed_resp;
+
+ switch (resp->nlmsg_type) {
+ case NLMSG_ERROR:
+ err = (struct nlmsgerr *)NLMSG_DATA(resp);
+ if (resp->nlmsg_len < NLMSG_LENGTH(sizeof(*err)))
+ goto malformed_resp;
+
+ if (err->error) {
+ virReportSystemError(-err->error,
+ _("error dumping %s (%d) interface"),
+ ifname, ifindex);
+ goto cleanup;
+ }
+ break;
+
+ case GENL_ID_CTRL:
+ case NLMSG_DONE:
+ rc = nlmsg_parse(resp, sizeof(struct ifinfomsg),
+ tb, IFLA_MAX, NULL);
+ if (rc < 0)
+ goto malformed_resp;
+ break;
+
+ default:
+ goto malformed_resp;
+ }
+ rc = 0;
+ cleanup:
+ nlmsg_free(nl_msg);
+ if (rc < 0)
+ VIR_FREE(resp);
+ *nlData = resp;
+ return rc;
+
+ malformed_resp:
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("malformed netlink response message"));
+ goto cleanup;
+
+ buffer_too_small:
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("allocated netlink buffer is too small"));
+ goto cleanup;
+}
+
+
+/**
* virNetlinkDelLink:
*
* @ifname: Name of the link
@@ -923,6 +1044,20 @@ int virNetlinkCommand(struct nl_msg *nl_msg ATTRIBUTE_UNUSED,


int
+virNetlinkDumpLink(const char *ifname ATTRIBUTE_UNUSED,
+ int ifindex ATTRIBUTE_UNUSED,
+ void **nlData ATTRIBUTE_UNUSED,
+ struct nlattr **tb ATTRIBUTE_UNUSED,
+ uint32_t src_pid ATTRIBUTE_UNUSED,
+ uint32_t dst_pid ATTRIBUTE_UNUSED)
+{
+ virReportSystemError(ENOSYS, "%s",
+ _("Unable to dump link info on this platform"));
+ return -1;
+}
+
+
+int
virNetlinkDelLink(const char *ifname ATTRIBUTE_UNUSED,
virNetlinkDelLinkFallback fallback ATTRIBUTE_UNUSED)
{
diff --git a/src/util/virnetlink.h b/src/util/virnetlink.h
index 0664a7a..11e817c 100644
--- a/src/util/virnetlink.h
+++ b/src/util/virnetlink.h
@@ -58,6 +58,11 @@ int virNetlinkDelLink(const char *ifname, virNetlinkDelLinkFallback fallback);

int virNetlinkGetErrorCode(struct nlmsghdr *resp, unsigned int recvbuflen);

+int virNetlinkDumpLink(const char *ifname, int ifindex,
+ void **nlData, struct nlattr **tb,
+ uint32_t src_pid, uint32_t dst_pid)
+ ATTRIBUTE_RETURN_CHECK;
+
typedef void (*virNetlinkEventHandleCallback)(struct nlmsghdr *,
unsigned int length,
struct sockaddr_nl *peer,
--
2.5.5
John Ferlan
2016-06-23 20:02:28 UTC
Permalink
Post by Laine Stump
virNetDevLinkDump should have been in virnetlink.c, but that file
didn't exist yet when the function was created. It didn't really
matter until now - I found that having virnetlink.h included by
virnetdev.h caused build problems when trying to #include virnetdev.h
in a .c file in src/conf (due to missing directory in -I). Rather than
fix that to further institutionalize the incorrect placement of this
one function, this patch moves the function.
---
src/libvirt_private.syms | 2 +-
src/util/virnetdev.c | 134 +-------------------------------------
src/util/virnetdev.h | 6 --
src/util/virnetdevvportprofile.c | 4 +-
src/util/virnetlink.c | 135 +++++++++++++++++++++++++++++++++++++++
src/util/virnetlink.h | 5 ++
6 files changed, 145 insertions(+), 141 deletions(-)
Let's see if I can clear a few off the starboard side... Start getting
some of these in before something else changes that causes a ripple effect.

ACK

John
Laine Stump
2016-06-22 17:37:27 UTC
Permalink
For type='ethernet' interfaces only.
---
src/qemu/qemu_interface.c | 6 ++-
.../qemuxml2argv-net-eth-hostip.args | 23 +++++++++++
.../qemuxml2argv-net-eth-hostip.xml | 39 +++++++++++++++++++
tests/qemuxml2argvtest.c | 1 +
.../qemuxml2xmlout-net-eth-hostip.xml | 44 ++++++++++++++++++++++
tests/qemuxml2xmltest.c | 1 +
6 files changed, 113 insertions(+), 1 deletion(-)
create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-net-eth-hostip.args
create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-net-eth-hostip.xml
create mode 100644 tests/qemuxml2xmloutdata/qemuxml2xmlout-net-eth-hostip.xml

diff --git a/src/qemu/qemu_interface.c b/src/qemu/qemu_interface.c
index b48ae50..e637d21 100644
--- a/src/qemu/qemu_interface.c
+++ b/src/qemu/qemu_interface.c
@@ -196,8 +196,12 @@ qemuInterfaceStopDevice(virDomainNetDefPtr net)
break;
}

- case VIR_DOMAIN_NET_TYPE_USER:
case VIR_DOMAIN_NET_TYPE_ETHERNET:
+ if (virNetDevIPInfoAddToDev(net->ifname, &net->hostIP) < 0)
+ goto cleanup;
+ break;
+
+ case VIR_DOMAIN_NET_TYPE_USER:
case VIR_DOMAIN_NET_TYPE_VHOSTUSER:
case VIR_DOMAIN_NET_TYPE_SERVER:
case VIR_DOMAIN_NET_TYPE_CLIENT:
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-net-eth-hostip.args b/tests/qemuxml2argvdata/qemuxml2argv-net-eth-hostip.args
new file mode 100644
index 0000000..b96c933
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-net-eth-hostip.args
@@ -0,0 +1,23 @@
+LC_ALL=C \
+PATH=/bin \
+HOME=/home/test \
+USER=test \
+LOGNAME=test \
+QEMU_AUDIO_DRV=none \
+/usr/bin/qemu \
+-name QEMUGuest1 \
+-S \
+-M pc \
+-m 214 \
+-smp 1 \
+-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
+-nographic \
+-nodefaults \
+-monitor unix:/tmp/lib/domain--1-QEMUGuest1/monitor.sock,server,nowait \
+-no-acpi \
+-boot c \
+-usb \
+-drive file=/dev/HostVG/QEMUGuest1,format=raw,if=none,id=drive-ide0-0-0 \
+-device ide-drive,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0 \
+-device rtl8139,vlan=0,id=net0,mac=00:11:22:33:44:55,bus=pci.0,addr=0x3 \
+-net tap,fd=3,vlan=0,name=hostnet0
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-net-eth-hostip.xml b/tests/qemuxml2argvdata/qemuxml2argv-net-eth-hostip.xml
new file mode 100644
index 0000000..6d08e82
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-net-eth-hostip.xml
@@ -0,0 +1,39 @@
+<domain type='qemu'>
+ <name>QEMUGuest1</name>
+ <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+ <memory unit='KiB'>219100</memory>
+ <currentMemory unit='KiB'>219100</currentMemory>
+ <vcpu placement='static'>1</vcpu>
+ <os>
+ <type arch='i686' machine='pc'>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</emulator>
+ <disk type='block' device='disk'>
+ <driver name='qemu' type='raw'/>
+ <source dev='/dev/HostVG/QEMUGuest1'/>
+ <target dev='hda' bus='ide'/>
+ <address type='drive' controller='0' bus='0' target='0' unit='0'/>
+ </disk>
+ <controller type='usb' index='0'/>
+ <controller type='ide' index='0'/>
+ <controller type='pci' index='0' model='pci-root'/>
+ <interface type='ethernet'>
+ <mac address='00:11:22:33:44:55'/>
+ <source>
+ <ip address='192.168.125.1' family='ipv4' prefix='24' peer='192.168.125.2'/>
+ <route family='ipv4' address='10.20.0.0' prefix='16' gateway='192.168.125.2'/>
+ </source>
+ <script path='/etc/qemu-ifup'/>
+ <model type='rtl8139'/>
+ </interface>
+ <input type='mouse' bus='ps2'/>
+ <input type='keyboard' bus='ps2'/>
+ <memballoon model='none'/>
+ </devices>
+</domain>
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index d882f11..684093b 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -1011,6 +1011,7 @@ mymain(void)
DO_TEST("net-eth", NONE);
DO_TEST("net-eth-ifname", NONE);
DO_TEST("net-eth-names", NONE);
+ DO_TEST("net-eth-hostip", NONE);
DO_TEST("net-client", NONE);
DO_TEST("net-server", NONE);
DO_TEST("net-mcast", NONE);
diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-net-eth-hostip.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-net-eth-hostip.xml
new file mode 100644
index 0000000..856b35b
--- /dev/null
+++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-net-eth-hostip.xml
@@ -0,0 +1,44 @@
+<domain type='qemu'>
+ <name>QEMUGuest1</name>
+ <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+ <memory unit='KiB'>219100</memory>
+ <currentMemory unit='KiB'>219100</currentMemory>
+ <vcpu placement='static'>1</vcpu>
+ <os>
+ <type arch='i686' machine='pc'>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</emulator>
+ <disk type='block' device='disk'>
+ <driver name='qemu' type='raw'/>
+ <source dev='/dev/HostVG/QEMUGuest1'/>
+ <target dev='hda' bus='ide'/>
+ <address type='drive' controller='0' bus='0' target='0' unit='0'/>
+ </disk>
+ <controller type='usb' index='0'>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
+ </controller>
+ <controller type='ide' index='0'>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
+ </controller>
+ <controller type='pci' index='0' model='pci-root'/>
+ <interface type='ethernet'>
+ <mac address='00:11:22:33:44:55'/>
+ <source>
+ <ip address='192.168.125.1' family='ipv4' prefix='24' peer='192.168.125.2'/>
+ <route family='ipv4' address='10.20.0.0' prefix='16' gateway='192.168.125.2'/>
+ </source>
+ <script path='/etc/qemu-ifup'/>
+ <model type='rtl8139'/>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
+ </interface>
+ <input type='mouse' bus='ps2'/>
+ <input type='keyboard' bus='ps2'/>
+ <memballoon model='none'/>
+ </devices>
+</domain>
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
index 7db9cb7..29a29c5 100644
--- a/tests/qemuxml2xmltest.c
+++ b/tests/qemuxml2xmltest.c
@@ -464,6 +464,7 @@ mymain(void)
DO_TEST("net-virtio-disable-offloads");
DO_TEST("net-eth");
DO_TEST("net-eth-ifname");
+ DO_TEST("net-eth-hostip");
DO_TEST("net-virtio-network-portgroup");
DO_TEST("net-hostdev");
DO_TEST("net-hostdev-vfio");
--
2.5.5
John Ferlan
2016-06-24 13:58:07 UTC
Permalink
Post by Laine Stump
For type='ethernet' interfaces only.
---
src/qemu/qemu_interface.c | 6 ++-
.../qemuxml2argv-net-eth-hostip.args | 23 +++++++++++
.../qemuxml2argv-net-eth-hostip.xml | 39 +++++++++++++++++++
tests/qemuxml2argvtest.c | 1 +
.../qemuxml2xmlout-net-eth-hostip.xml | 44 ++++++++++++++++++++++
tests/qemuxml2xmltest.c | 1 +
6 files changed, 113 insertions(+), 1 deletion(-)
create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-net-eth-hostip.args
create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-net-eth-hostip.xml
create mode 100644 tests/qemuxml2xmloutdata/qemuxml2xmlout-net-eth-hostip.xml
ACK

John
Laine Stump
2016-06-22 17:37:09 UTC
Permalink
This patch removes the expanded and duplicated code that all sprung
out of two well-intentioned-but-useless settings of
net->data.(bridge|ethernet).ipaddr.

qemu has never supported even a single IP address in the interface
config, much less a list of them. All of the instances of "clearing
out the IP addresses" that are now in this function originated with
commit d8dbd6 "Basic domain XML conversions for Xen/QEMU drivers" in
May 2009, but even then the single "ipaddr" in the struct for
type='ethernet' and type='bridge' wasn't used in the qemu driver (only
in xen and openvz). Since then anyone who added a new interface type
also tacked on another unnecessary clearing of ipaddr, and when it was
made into a list of IPs (so far supported only by the LXC driver) this
simple setting was turned into a loop (well, multiple loops) to clear
them all.
---
src/qemu/qemu_driver.c | 20 --------------------
1 file changed, 20 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 294a1b0..517d0b8 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -6998,7 +6998,6 @@ static char *qemuConnectDomainXMLToNative(virConnectPtr conn,
(brname = virDomainNetGetActualBridgeName(net))) {

char *brnamecopy;
- size_t j;

if (VIR_STRDUP(brnamecopy, brname) < 0)
goto cleanup;
@@ -7010,29 +7009,18 @@ static char *qemuConnectDomainXMLToNative(virConnectPtr conn,
net->type = VIR_DOMAIN_NET_TYPE_ETHERNET;
net->script = NULL;
net->data.ethernet.dev = brnamecopy;
- for (j = 0; j < net->nips; j++)
- VIR_FREE(net->ips[j]);
- VIR_FREE(net->ips);
- net->nips = 0;
-
} else {
/* actualType is either NETWORK or DIRECT. In either
* case, the best we can do is NULL everything out.
*/
- size_t j;
virDomainActualNetDefFree(net->data.network.actual);
memset(net, 0, sizeof(*net));

net->type = VIR_DOMAIN_NET_TYPE_ETHERNET;
net->script = NULL;
net->data.ethernet.dev = NULL;
- for (j = 0; j < net->nips; j++)
- VIR_FREE(net->ips[j]);
- VIR_FREE(net->ips);
- net->nips = 0;
}
} else if (net->type == VIR_DOMAIN_NET_TYPE_DIRECT) {
- size_t j;
VIR_FREE(net->data.direct.linkdev);

memset(net, 0, sizeof(*net));
@@ -7040,23 +7028,15 @@ static char *qemuConnectDomainXMLToNative(virConnectPtr conn,
net->type = VIR_DOMAIN_NET_TYPE_ETHERNET;
net->script = NULL;
net->data.ethernet.dev = NULL;
- for (j = 0; j < net->nips; j++)
- VIR_FREE(net->ips[j]);
- VIR_FREE(net->ips);
- net->nips = 0;
} else if (net->type == VIR_DOMAIN_NET_TYPE_BRIDGE) {
char *script = net->script;
char *brname = net->data.bridge.brname;
- size_t nips = net->nips;
- virDomainNetIPDefPtr *ips = net->ips;

memset(net, 0, sizeof(*net));

net->type = VIR_DOMAIN_NET_TYPE_ETHERNET;
net->script = script;
net->data.ethernet.dev = brname;
- net->nips = nips;
- net->ips = ips;
}

VIR_FREE(net->virtPortProfile);
--
2.5.5
John Ferlan
2016-06-23 21:53:12 UTC
Permalink
Post by Laine Stump
This patch removes the expanded and duplicated code that all sprung
out of two well-intentioned-but-useless settings of
net->data.(bridge|ethernet).ipaddr.
qemu has never supported even a single IP address in the interface
config, much less a list of them. All of the instances of "clearing
out the IP addresses" that are now in this function originated with
commit d8dbd6 "Basic domain XML conversions for Xen/QEMU drivers" in
May 2009, but even then the single "ipaddr" in the struct for
type='ethernet' and type='bridge' wasn't used in the qemu driver (only
in xen and openvz). Since then anyone who added a new interface type
also tacked on another unnecessary clearing of ipaddr, and when it was
made into a list of IPs (so far supported only by the LXC driver) this
simple setting was turned into a loop (well, multiple loops) to clear
them all.
---
src/qemu/qemu_driver.c | 20 --------------------
1 file changed, 20 deletions(-)
Seems like a reasonable explanation


ACK -

John
Laine Stump
2016-06-22 17:37:24 UTC
Permalink
This is non-intuitively placed as a sub-element of <target>, because
it will be used to configure the interface that is named in <target
dev='x'/> (which is the interface on the host-side). (The
already-existing configuration for the guest-side of interfaces is in
subelements directly under <interface>):

<interface type='ethernet'>
<mac address='00:16:3e:0f:ef:8a'/>
<source>
<ip address='192.168.122.12' family='ipv4'
prefix='24' peer='192.168.122.1'/>
<ip address='192.168.122.13' family='ipv4' prefix='24'/>
<route family='ipv4' address='0.0.0.0'
gateway='192.168.122.1'/>
<route family='ipv4' address='192.168.124.0' prefix='24'
gateway='192.168.124.1'/>
</source>
</interface>

In practice, this will likely only be useful for type='ethernet', so
its presence in any other type of interface is currently forbidden in
the generic device Validate function (but it's been put into the
general population of virDomainNetDef rather than the
ethernet-specific union member so that 1) we can more easily add the
capability to other types, and 2) we can retain the info when set to
an invalid interface type all the way through to validation and report
a proper error, rather than just ignoring it (which is currently what
happens for many other type-specific settings).
---
docs/formatdomain.html.in | 26 ++++++++
docs/schemas/domaincommon.rng | 3 +-
src/conf/domain_conf.c | 97 ++++++++++++++++++++++------
src/conf/domain_conf.h | 3 +-
tests/lxcxml2xmldata/lxc-ethernet-hostip.xml | 44 +++++++++++++
tests/lxcxml2xmltest.c | 1 +
6 files changed, 152 insertions(+), 22 deletions(-)
create mode 100644 tests/lxcxml2xmldata/lxc-ethernet-hostip.xml

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 2466df7..bb1c079 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -5012,6 +5012,32 @@ qemu-kvm -net nic,model=? /dev/null
definitions</a>. This is used by the LXC driver.
</p>

+<pre>
+ ...
+ &lt;devices&gt;
+ &lt;interface type='ethernet'&gt;
+ <b>&lt;source/&gt;</b>
+ <b>&lt;ip address='192.168.123.1' prefix='24'/&gt;</b>
+ <b>&lt;ip address='10.0.0.10' prefix='24' peer='192.168.122.5'/&gt;</b>
+ <b>&lt;route family='ipv4' address='192.168.42.0' prefix='24' gateway='192.168.123.4'/&gt;</b>
+ <b>&lt;source/&gt;</b>
+ ...
+ &lt;/interface&gt;
+ ...
+ &lt;/devices&gt;
+ ...
+</pre>
+
+ <p>
+ <span class="since">Since 2.0.0</span> network devices of type
+ "ethernet" can optionally be provided one or more IP addresses
+ and one or more routes to set on the <b>host</b> side of the
+ network device. These are configured as subelements of
+ the <code>&lt;source&gt;</code> element of the interface, and
+ have the same attributes as the similarly named elements used to
+ configure the guest side of the interface (described above).
+ </p>
+
<h5><a name="elementVhostuser">vhost-user interface</a></h5>

<p>
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 2d12da9..964ff92 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -2142,7 +2142,7 @@
<interleave>
<optional>
<element name="source">
- <empty/>
+ <ref name="interface-ip-info"/>
</element>
</optional>
<ref name="interface-options"/>
@@ -2392,7 +2392,6 @@
<attribute name="dev">
<ref name="deviceName"/>
</attribute>
- <empty/>
</element>
</optional>
<optional>
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index ad2d983..c2e6663 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -1800,6 +1800,7 @@ virDomainNetDefClear(virDomainNetDefPtr def)
VIR_FREE(def->ifname_guest_actual);

virNetDevIPInfoClear(&def->guestIP);
+ virNetDevIPInfoClear(&def->hostIP);
virDomainDeviceInfoClear(&def->info);

VIR_FREE(def->filter);
@@ -4610,6 +4611,23 @@ virDomainRedirdevDefValidate(const virDomainDef *def,


static int
+virDomainNetDefValidate(const virDomainNetDef *net)
+{
+ if ((net->hostIP.nroutes || net->hostIP.nips) &&
+ net->type != VIR_DOMAIN_NET_TYPE_ETHERNET) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("Invalid attempt to set network interface "
+ "host-side IP route and/or address info on "
+ "interface of type '%s'. This is only supported "
+ "on interfaces of type 'ethernet'"),
+ virDomainNetTypeToString(net->type));
+ return -1;
+ }
+ return 0;
+}
+
+
+static int
virDomainDeviceDefValidateInternal(const virDomainDeviceDef *dev,
const virDomainDef *def)
{
@@ -4620,9 +4638,11 @@ virDomainDeviceDefValidateInternal(const virDomainDeviceDef *dev,
case VIR_DOMAIN_DEVICE_REDIRDEV:
return virDomainRedirdevDefValidate(def, dev->data.redirdev);

+ case VIR_DOMAIN_DEVICE_NET:
+ return virDomainNetDefValidate(dev->data.net);
+
case VIR_DOMAIN_DEVICE_LEASE:
case VIR_DOMAIN_DEVICE_FS:
- case VIR_DOMAIN_DEVICE_NET:
case VIR_DOMAIN_DEVICE_INPUT:
case VIR_DOMAIN_DEVICE_SOUND:
case VIR_DOMAIN_DEVICE_VIDEO:
@@ -8977,6 +8997,15 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
cur = node->children;
while (cur != NULL) {
if (cur->type == XML_ELEMENT_NODE) {
+ if (xmlStrEqual(cur->name, BAD_CAST "source")) {
+ xmlNodePtr tmpnode = ctxt->node;
+
+ ctxt->node = cur;
+ if (virDomainNetIPInfoParseXML(_("interface host IP"),
+ ctxt, &def->hostIP) < 0)
+ goto error;
+ ctxt->node = tmpnode;
+ }
if (!macaddr && xmlStrEqual(cur->name, BAD_CAST "mac")) {
macaddr = virXMLPropString(cur, "address");
} else if (!network &&
@@ -20682,6 +20711,7 @@ virDomainNetDefFormat(virBufferPtr buf,
{
unsigned int actualType = virDomainNetGetActualType(def);
bool publicActual = false;
+ int sourceLines = 0;
const char *typeStr;
virDomainHostdevDefPtr hostdef = NULL;
char macstr[VIR_MAC_STRING_BUFLEN];
@@ -20751,15 +20781,7 @@ virDomainNetDefFormat(virBufferPtr buf,
def->data.network.name);
virBufferEscapeString(buf, " portgroup='%s'",
def->data.network.portgroup);
- virBufferAddLit(buf, "/>\n");
-
- /* ONLY for internal status storage - format the ActualNetDef
- * as a subelement of <interface> so that no persistent config
- * data is overwritten.
- */
- if ((flags & VIR_DOMAIN_DEF_FORMAT_ACTUAL_NET) &&
- (virDomainActualNetDefFormat(buf, def, flags) < 0))
- return -1;
+ sourceLines++;
break;

case VIR_DOMAIN_NET_TYPE_ETHERNET:
@@ -20773,13 +20795,16 @@ virDomainNetDefFormat(virBufferPtr buf,
virBufferAsprintf(buf, " mode='%s'",
def->data.vhostuser->data.nix.listen ?
"server" : "client");
- virBufferAddLit(buf, "/>\n");
+ sourceLines++;
}
break;

case VIR_DOMAIN_NET_TYPE_BRIDGE:
- virBufferEscapeString(buf, "<source bridge='%s'/>\n",
- def->data.bridge.brname);
+ if (def->data.bridge.brname) {
+ virBufferEscapeString(buf, "<source bridge='%s'",
+ def->data.bridge.brname);
+ sourceLines++;
+ }
break;

case VIR_DOMAIN_NET_TYPE_SERVER:
@@ -20794,25 +20819,25 @@ virDomainNetDefFormat(virBufferPtr buf,
virBufferAsprintf(buf, "<source port='%d'",
def->data.socket.port);
}
+ sourceLines++;

- if (def->type != VIR_DOMAIN_NET_TYPE_UDP) {
- virBufferAddLit(buf, "/>\n");
+ if (def->type != VIR_DOMAIN_NET_TYPE_UDP)
break;
- }

virBufferAddLit(buf, ">\n");
+ sourceLines++;
virBufferAdjustIndent(buf, 2);

virBufferAsprintf(buf, "<local address='%s' port='%d'/>\n",
def->data.socket.localaddr,
def->data.socket.localport);
virBufferAdjustIndent(buf, -2);
- virBufferAddLit(buf, "</source>\n");
break;

case VIR_DOMAIN_NET_TYPE_INTERNAL:
- virBufferEscapeString(buf, "<source name='%s'/>\n",
+ virBufferEscapeString(buf, "<source name='%s'",
def->data.internal.name);
+ sourceLines++;
break;

case VIR_DOMAIN_NET_TYPE_DIRECT:
@@ -20820,7 +20845,7 @@ virDomainNetDefFormat(virBufferPtr buf,
def->data.direct.linkdev);
virBufferAsprintf(buf, " mode='%s'",
virNetDevMacVLanModeTypeToString(def->data.direct.mode));
- virBufferAddLit(buf, "/>\n");
+ sourceLines++;
break;

case VIR_DOMAIN_NET_TYPE_HOSTDEV:
@@ -20835,12 +20860,44 @@ virDomainNetDefFormat(virBufferPtr buf,
break;
}

+ /* if sourceLines == 0 - no <source> info at all so far
+ * sourceLines == 1 - first line writte, no terminating ">"
+ * sourceLines > 1 - multiple lines, including subelements
+ */
+ if (def->hostIP.nips || def->hostIP.nroutes) {
+ if (sourceLines == 0) {
+ virBufferAddLit(buf, "<source>\n");
+ sourceLines += 2;
+ } else if (sourceLines == 1) {
+ virBufferAddLit(buf, ">\n");
+ sourceLines++;
+ }
+ virBufferAdjustIndent(buf, 2);
+ if (virDomainNetIPInfoFormat(buf, &def->hostIP) < 0)
+ return -1;
+ virBufferAdjustIndent(buf, -2);
+ }
+ if (sourceLines == 1)
+ virBufferAddLit(buf, "/>\n");
+ else if (sourceLines > 1)
+ virBufferAddLit(buf, "</source>\n");
+
if (virNetDevVlanFormat(&def->vlan, buf) < 0)
return -1;
if (virNetDevVPortProfileFormat(def->virtPortProfile, buf) < 0)
return -1;
if (virNetDevBandwidthFormat(def->bandwidth, buf) < 0)
return -1;
+
+ /* ONLY for internal status storage - format the ActualNetDef
+ * as a subelement of <interface> so that no persistent config
+ * data is overwritten.
+ */
+ if (def->type == VIR_DOMAIN_NET_TYPE_NETWORK &&
+ (flags & VIR_DOMAIN_DEF_FORMAT_ACTUAL_NET) &&
+ (virDomainActualNetDefFormat(buf, def, flags) < 0))
+ return -1;
+
}

if (virDomainNetIPInfoFormat(buf, &def->guestIP) < 0)
@@ -20849,6 +20906,7 @@ virDomainNetDefFormat(virBufferPtr buf,
virBufferEscapeString(buf, "<script path='%s'/>\n",
def->script);
virBufferEscapeString(buf, "<backenddomain name='%s'/>\n", def->domain_name);
+
if (def->ifname &&
!((flags & VIR_DOMAIN_DEF_FORMAT_INACTIVE) &&
(STRPREFIX(def->ifname, VIR_NET_GENERATED_PREFIX) ||
@@ -20856,6 +20914,7 @@ virDomainNetDefFormat(virBufferPtr buf,
/* Skip auto-generated target names for inactive config. */
virBufferEscapeString(buf, "<target dev='%s'/>\n", def->ifname);
}
+
if (def->ifname_guest || def->ifname_guest_actual) {
virBufferAddLit(buf, "<guest");
/* Skip auto-generated target names for inactive config. */
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 7ff966f..8f6c24a 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -966,7 +966,8 @@ struct _virDomainNetDef {
} tune;
char *script;
char *domain_name; /* backend domain name */
- char *ifname;
+ char *ifname; /* interface name on the host (<target dev='x'/>) */
+ virNetDevIPInfo hostIP;
char *ifname_guest_actual;
char *ifname_guest;
virNetDevIPInfo guestIP;
diff --git a/tests/lxcxml2xmldata/lxc-ethernet-hostip.xml b/tests/lxcxml2xmldata/lxc-ethernet-hostip.xml
new file mode 100644
index 0000000..ce455f7
--- /dev/null
+++ b/tests/lxcxml2xmldata/lxc-ethernet-hostip.xml
@@ -0,0 +1,44 @@
+<domain type='lxc'>
+ <name>8675309</name>
+ <uuid>e21987a5-e98e-9c99-0e35-803e4d9ad1fe</uuid>
+ <memory unit='KiB'>1048576</memory>
+ <currentMemory unit='KiB'>1048576</currentMemory>
+ <vcpu placement='static'>1</vcpu>
+ <resource>
+ <partition>/machine</partition>
+ </resource>
+ <os>
+ <type arch='x86_64'>exe</type>
+ <init>/sbin/init</init>
+ </os>
+ <idmap>
+ <uid start='0' target='100000' count='100000'/>
+ <gid start='0' target='100000' count='100000'/>
+ </idmap>
+ <clock offset='utc'/>
+ <on_poweroff>destroy</on_poweroff>
+ <on_reboot>restart</on_reboot>
+ <on_crash>restart</on_crash>
+ <devices>
+ <emulator>/usr/libexec/libvirt_lxc</emulator>
+ <filesystem type='mount' accessmode='passthrough'>
+ <source dir='/mach/8675309'/>
+ <target dir='/'/>
+ </filesystem>
+ <interface type='ethernet'>
+ <mac address='00:16:3e:0f:ef:8a'/>
+ <source>
+ <ip address='192.168.122.12' family='ipv4' prefix='24' peer='192.168.122.1'/>
+ <ip address='192.168.122.13' family='ipv4' prefix='24'/>
+ <route family='ipv4' address='0.0.0.0' gateway='192.168.122.1'/>
+ <route family='ipv4' address='192.168.124.0' prefix='24' gateway='192.168.124.1'/>
+ </source>
+ <ip address='192.168.122.1' family='ipv4' prefix='32' peer='192.168.122.12'/>
+ <guest dev='eth2'/>
+ </interface>
+ <console type='pty'>
+ <target type='lxc' port='0'/>
+ </console>
+ </devices>
+ <seclabel type='none'/>
+</domain>
diff --git a/tests/lxcxml2xmltest.c b/tests/lxcxml2xmltest.c
index 1b16088..2f7f779 100644
--- a/tests/lxcxml2xmltest.c
+++ b/tests/lxcxml2xmltest.c
@@ -95,6 +95,7 @@ mymain(void)
DO_TEST("capabilities");
DO_TEST("sharenet");
DO_TEST("ethernet");
+ DO_TEST("ethernet-hostip");
DO_TEST_FULL("filesystem-root", 0, false,
VIR_DOMAIN_DEF_PARSE_SKIP_OSTYPE_CHECKS);
--
2.5.5
John Ferlan
2016-06-24 13:48:26 UTC
Permalink
Post by Laine Stump
This is non-intuitively placed as a sub-element of <target>, because
it will be used to configure the interface that is named in <target
dev='x'/> (which is the interface on the host-side). (The
already-existing configuration for the guest-side of interfaces is in
<interface type='ethernet'>
<mac address='00:16:3e:0f:ef:8a'/>
<source>
<ip address='192.168.122.12' family='ipv4'
prefix='24' peer='192.168.122.1'/>
<ip address='192.168.122.13' family='ipv4' prefix='24'/>
<route family='ipv4' address='0.0.0.0'
gateway='192.168.122.1'/>
<route family='ipv4' address='192.168.124.0' prefix='24'
gateway='192.168.124.1'/>
</source>
</interface>
In practice, this will likely only be useful for type='ethernet', so
its presence in any other type of interface is currently forbidden in
the generic device Validate function (but it's been put into the
general population of virDomainNetDef rather than the
ethernet-specific union member so that 1) we can more easily add the
capability to other types, and 2) we can retain the info when set to
an invalid interface type all the way through to validation and report
a proper error, rather than just ignoring it (which is currently what
happens for many other type-specific settings).
---
docs/formatdomain.html.in | 26 ++++++++
docs/schemas/domaincommon.rng | 3 +-
src/conf/domain_conf.c | 97 ++++++++++++++++++++++------
src/conf/domain_conf.h | 3 +-
tests/lxcxml2xmldata/lxc-ethernet-hostip.xml | 44 +++++++++++++
tests/lxcxml2xmltest.c | 1 +
6 files changed, 152 insertions(+), 22 deletions(-)
create mode 100644 tests/lxcxml2xmldata/lxc-ethernet-hostip.xml
diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 2466df7..bb1c079 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -5012,6 +5012,32 @@ qemu-kvm -net nic,model=? /dev/null
definitions</a>. This is used by the LXC driver.
</p>
+<pre>
+ ...
+ ...
+ ...
+ ...
+</pre>
+
+ <p>
+ <span class="since">Since 2.0.0</span> network devices of type
+ "ethernet" can optionally be provided one or more IP addresses
+ and one or more routes to set on the <b>host</b> side of the
+ network device. These are configured as subelements of
+ have the same attributes as the similarly named elements used to
+ configure the guest side of the interface (described above).
+ </p>
+
<h5><a name="elementVhostuser">vhost-user interface</a></h5>
<p>
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 2d12da9..964ff92 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -2142,7 +2142,7 @@
<interleave>
<optional>
<element name="source">
- <empty/>
+ <ref name="interface-ip-info"/>
</element>
</optional>
<ref name="interface-options"/>
@@ -2392,7 +2392,6 @@
<attribute name="dev">
<ref name="deviceName"/>
</attribute>
- <empty/>
</element>
</optional>
<optional>
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index ad2d983..c2e6663 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -1800,6 +1800,7 @@ virDomainNetDefClear(virDomainNetDefPtr def)
VIR_FREE(def->ifname_guest_actual);
virNetDevIPInfoClear(&def->guestIP);
+ virNetDevIPInfoClear(&def->hostIP);
virDomainDeviceInfoClear(&def->info);
VIR_FREE(def->filter);
@@ -4610,6 +4611,23 @@ virDomainRedirdevDefValidate(const virDomainDef *def,
static int
+virDomainNetDefValidate(const virDomainNetDef *net)
+{
+ if ((net->hostIP.nroutes || net->hostIP.nips) &&
+ net->type != VIR_DOMAIN_NET_TYPE_ETHERNET) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("Invalid attempt to set network interface "
+ "host-side IP route and/or address info on "
+ "interface of type '%s'. This is only supported "
+ "on interfaces of type 'ethernet'"),
+ virDomainNetTypeToString(net->type));
+ return -1;
+ }
+ return 0;
+}
It seems as though you are *adding* a new element - thus, this could not
be present on a currently running domain, so wouldn't the "more correct"
placement be the PostParse API's ?
Post by Laine Stump
+
+
+static int
virDomainDeviceDefValidateInternal(const virDomainDeviceDef *dev,
const virDomainDef *def)
{
@@ -4620,9 +4638,11 @@ virDomainDeviceDefValidateInternal(const virDomainDeviceDef *dev,
return virDomainRedirdevDefValidate(def, dev->data.redirdev);
+ return virDomainNetDefValidate(dev->data.net);
+
@@ -8977,6 +8997,15 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
cur = node->children;
while (cur != NULL) {
if (cur->type == XML_ELEMENT_NODE) {
+ if (xmlStrEqual(cur->name, BAD_CAST "source")) {
+ xmlNodePtr tmpnode = ctxt->node;
+
+ ctxt->node = cur;
+ if (virDomainNetIPInfoParseXML(_("interface host IP"),
+ ctxt, &def->hostIP) < 0)
+ goto error;
+ ctxt->node = tmpnode;
+ }
if (!macaddr && xmlStrEqual(cur->name, BAD_CAST "mac")) {
macaddr = virXMLPropString(cur, "address");
} else if (!network &&
@@ -20682,6 +20711,7 @@ virDomainNetDefFormat(virBufferPtr buf,
{
unsigned int actualType = virDomainNetGetActualType(def);
bool publicActual = false;
+ int sourceLines = 0;
const char *typeStr;
virDomainHostdevDefPtr hostdef = NULL;
char macstr[VIR_MAC_STRING_BUFLEN];
@@ -20751,15 +20781,7 @@ virDomainNetDefFormat(virBufferPtr buf,
def->data.network.name);
virBufferEscapeString(buf, " portgroup='%s'",
def->data.network.portgroup);
- virBufferAddLit(buf, "/>\n");
-
- /* ONLY for internal status storage - format the ActualNetDef
- * as a subelement of <interface> so that no persistent config
- * data is overwritten.
- */
- if ((flags & VIR_DOMAIN_DEF_FORMAT_ACTUAL_NET) &&
- (virDomainActualNetDefFormat(buf, def, flags) < 0))
- return -1;
+ sourceLines++;
All these sourceLines++ probably could have been their own patch...
Adding the hostIP's separately. Mixing the two is was a bit tough to
read and understand...
Post by Laine Stump
break;
@@ -20773,13 +20795,16 @@ virDomainNetDefFormat(virBufferPtr buf,
virBufferAsprintf(buf, " mode='%s'",
def->data.vhostuser->data.nix.listen ?
"server" : "client");
- virBufferAddLit(buf, "/>\n");
+ sourceLines++;
}
break;
- virBufferEscapeString(buf, "<source bridge='%s'/>\n",
- def->data.bridge.brname);
+ if (def->data.bridge.brname) {
This alone seems line a separate patch... But then again there's already
sooooo many....
Post by Laine Stump
+ virBufferEscapeString(buf, "<source bridge='%s'",
+ def->data.bridge.brname);
+ sourceLines++;
+ }
break;
@@ -20794,25 +20819,25 @@ virDomainNetDefFormat(virBufferPtr buf,
virBufferAsprintf(buf, "<source port='%d'",
def->data.socket.port);
}
+ sourceLines++;
- if (def->type != VIR_DOMAIN_NET_TYPE_UDP) {
- virBufferAddLit(buf, "/>\n");
+ if (def->type != VIR_DOMAIN_NET_TYPE_UDP)
break;
- }
virBufferAddLit(buf, ">\n");
+ sourceLines++;
virBufferAdjustIndent(buf, 2);
virBufferAsprintf(buf, "<local address='%s' port='%d'/>\n",
def->data.socket.localaddr,
def->data.socket.localport);
virBufferAdjustIndent(buf, -2);
- virBufferAddLit(buf, "</source>\n");
break;
- virBufferEscapeString(buf, "<source name='%s'/>\n",
+ virBufferEscapeString(buf, "<source name='%s'",
def->data.internal.name);
+ sourceLines++;
break;
@@ -20820,7 +20845,7 @@ virDomainNetDefFormat(virBufferPtr buf,
def->data.direct.linkdev);
virBufferAsprintf(buf, " mode='%s'",
virNetDevMacVLanModeTypeToString(def->data.direct.mode));
- virBufferAddLit(buf, "/>\n");
+ sourceLines++;
break;
@@ -20835,12 +20860,44 @@ virDomainNetDefFormat(virBufferPtr buf,
break;
}
+ /* if sourceLines == 0 - no <source> info at all so far
+ * sourceLines == 1 - first line writte, no terminating ">"
s/writte/written


I think the Validate should be a PostParse - your thoughts... The
'contents' of the change are ACKable, I just think the placement is a
bit off. Then of course there's the whole doing multiple things here
(there could conceivably be 3 patches out of this).

I "assume" there are other XML2XML tests that ensure all the following
magic is correct since you added one for the new data...

John
Post by Laine Stump
+ * sourceLines > 1 - multiple lines, including subelements
+ */
+ if (def->hostIP.nips || def->hostIP.nroutes) {
+ if (sourceLines == 0) {
+ virBufferAddLit(buf, "<source>\n");
+ sourceLines += 2;
+ } else if (sourceLines == 1) {
+ virBufferAddLit(buf, ">\n");
+ sourceLines++;
+ }
+ virBufferAdjustIndent(buf, 2);
+ if (virDomainNetIPInfoFormat(buf, &def->hostIP) < 0)
+ return -1;
+ virBufferAdjustIndent(buf, -2);
+ }
+ if (sourceLines == 1)
+ virBufferAddLit(buf, "/>\n");
+ else if (sourceLines > 1)
+ virBufferAddLit(buf, "</source>\n");
+
if (virNetDevVlanFormat(&def->vlan, buf) < 0)
return -1;
if (virNetDevVPortProfileFormat(def->virtPortProfile, buf) < 0)
return -1;
if (virNetDevBandwidthFormat(def->bandwidth, buf) < 0)
return -1;
+
+ /* ONLY for internal status storage - format the ActualNetDef
+ * as a subelement of <interface> so that no persistent config
+ * data is overwritten.
+ */
+ if (def->type == VIR_DOMAIN_NET_TYPE_NETWORK &&
+ (flags & VIR_DOMAIN_DEF_FORMAT_ACTUAL_NET) &&
+ (virDomainActualNetDefFormat(buf, def, flags) < 0))
+ return -1;
+
}
Laine Stump
2016-06-24 15:19:05 UTC
Permalink
Post by John Ferlan
Post by Laine Stump
This is non-intuitively placed as a sub-element of <target>, because
it will be used to configure the interface that is named in <target
dev='x'/> (which is the interface on the host-side). (The
already-existing configuration for the guest-side of interfaces is in
<interface type='ethernet'>
<mac address='00:16:3e:0f:ef:8a'/>
<source>
<ip address='192.168.122.12' family='ipv4'
prefix='24' peer='192.168.122.1'/>
<ip address='192.168.122.13' family='ipv4' prefix='24'/>
<route family='ipv4' address='0.0.0.0'
gateway='192.168.122.1'/>
<route family='ipv4' address='192.168.124.0' prefix='24'
gateway='192.168.124.1'/>
</source>
</interface>
In practice, this will likely only be useful for type='ethernet', so
its presence in any other type of interface is currently forbidden in
the generic device Validate function (but it's been put into the
general population of virDomainNetDef rather than the
ethernet-specific union member so that 1) we can more easily add the
capability to other types, and 2) we can retain the info when set to
an invalid interface type all the way through to validation and report
a proper error, rather than just ignoring it (which is currently what
happens for many other type-specific settings).
---
docs/formatdomain.html.in | 26 ++++++++
docs/schemas/domaincommon.rng | 3 +-
src/conf/domain_conf.c | 97 ++++++++++++++++++++++------
src/conf/domain_conf.h | 3 +-
tests/lxcxml2xmldata/lxc-ethernet-hostip.xml | 44 +++++++++++++
tests/lxcxml2xmltest.c | 1 +
6 files changed, 152 insertions(+), 22 deletions(-)
create mode 100644 tests/lxcxml2xmldata/lxc-ethernet-hostip.xml
diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 2466df7..bb1c079 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -5012,6 +5012,32 @@ qemu-kvm -net nic,model=? /dev/null
definitions</a>. This is used by the LXC driver.
</p>
+<pre>
+ ...
+ ...
+ ...
+ ...
+</pre>
+
+ <p>
+ <span class="since">Since 2.0.0</span> network devices of type
+ "ethernet" can optionally be provided one or more IP addresses
+ and one or more routes to set on the <b>host</b> side of the
+ network device. These are configured as subelements of
+ have the same attributes as the similarly named elements used to
+ configure the guest side of the interface (described above).
+ </p>
+
<h5><a name="elementVhostuser">vhost-user interface</a></h5>
<p>
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 2d12da9..964ff92 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -2142,7 +2142,7 @@
<interleave>
<optional>
<element name="source">
- <empty/>
+ <ref name="interface-ip-info"/>
</element>
</optional>
<ref name="interface-options"/>
@@ -2392,7 +2392,6 @@
<attribute name="dev">
<ref name="deviceName"/>
</attribute>
- <empty/>
</element>
</optional>
<optional>
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index ad2d983..c2e6663 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -1800,6 +1800,7 @@ virDomainNetDefClear(virDomainNetDefPtr def)
VIR_FREE(def->ifname_guest_actual);
virNetDevIPInfoClear(&def->guestIP);
+ virNetDevIPInfoClear(&def->hostIP);
virDomainDeviceInfoClear(&def->info);
VIR_FREE(def->filter);
@@ -4610,6 +4611,23 @@ virDomainRedirdevDefValidate(const virDomainDef *def,
static int
+virDomainNetDefValidate(const virDomainNetDef *net)
+{
+ if ((net->hostIP.nroutes || net->hostIP.nips) &&
+ net->type != VIR_DOMAIN_NET_TYPE_ETHERNET) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("Invalid attempt to set network interface "
+ "host-side IP route and/or address info on "
+ "interface of type '%s'. This is only supported "
+ "on interfaces of type 'ethernet'"),
+ virDomainNetTypeToString(net->type));
+ return -1;
+ }
+ return 0;
+}
It seems as though you are *adding* a new element - thus, this could not
be present on a currently running domain, so wouldn't the "more correct"
placement be the PostParse API's ?
I don't think we're losing any functionality by putting it here (other
than that if someone edits the config files directly on disk and then
restart libvirtd they won't see an error; but then they'll be getting
what they deserve). And I think its function fits better with the
Validate function than with the PostParse callback (which admittedly
does have some validating done in it, but that's just because the
Validate callbacks are a fairly recent addition.

In general, I think anything that is just validating the data in a
domain as a whole should be done in the Validate callbacks, and things
that modify the domain or devices should be in the postparse callbacks.
Eventually pure validation should migrate, and for now at least new
stuff should be added in that way. (Note that I still think that basic
validation that doesn't require knowledge of any other part of the XML
should still be done directly in the parse (numeric ranges, etc;
basically anything that is described in the RNG).
Post by John Ferlan
Post by Laine Stump
+
+
+static int
virDomainDeviceDefValidateInternal(const virDomainDeviceDef *dev,
const virDomainDef *def)
{
@@ -4620,9 +4638,11 @@ virDomainDeviceDefValidateInternal(const virDomainDeviceDef *dev,
return virDomainRedirdevDefValidate(def, dev->data.redirdev);
+ return virDomainNetDefValidate(dev->data.net);
+
@@ -8977,6 +8997,15 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
cur = node->children;
while (cur != NULL) {
if (cur->type == XML_ELEMENT_NODE) {
+ if (xmlStrEqual(cur->name, BAD_CAST "source")) {
+ xmlNodePtr tmpnode = ctxt->node;
+
+ ctxt->node = cur;
+ if (virDomainNetIPInfoParseXML(_("interface host IP"),
+ ctxt, &def->hostIP) < 0)
+ goto error;
+ ctxt->node = tmpnode;
+ }
if (!macaddr && xmlStrEqual(cur->name, BAD_CAST "mac")) {
macaddr = virXMLPropString(cur, "address");
} else if (!network &&
@@ -20682,6 +20711,7 @@ virDomainNetDefFormat(virBufferPtr buf,
{
unsigned int actualType = virDomainNetGetActualType(def);
bool publicActual = false;
+ int sourceLines = 0;
const char *typeStr;
virDomainHostdevDefPtr hostdef = NULL;
char macstr[VIR_MAC_STRING_BUFLEN];
@@ -20751,15 +20781,7 @@ virDomainNetDefFormat(virBufferPtr buf,
def->data.network.name);
virBufferEscapeString(buf, " portgroup='%s'",
def->data.network.portgroup);
- virBufferAddLit(buf, "/>\n");
-
- /* ONLY for internal status storage - format the ActualNetDef
- * as a subelement of <interface> so that no persistent config
- * data is overwritten.
- */
- if ((flags & VIR_DOMAIN_DEF_FORMAT_ACTUAL_NET) &&
- (virDomainActualNetDefFormat(buf, def, flags) < 0))
- return -1;
+ sourceLines++;
All these sourceLines++ probably could have been their own patch...
Adding the hostIP's separately. Mixing the two is was a bit tough to
read and understand...
The further along I got with this, the more I came to think the same
thing, but I was already up to patch 25 and too deep into this one to
want to back it out and re-do in steps...
Post by John Ferlan
Post by Laine Stump
break;
@@ -20773,13 +20795,16 @@ virDomainNetDefFormat(virBufferPtr buf,
virBufferAsprintf(buf, " mode='%s'",
def->data.vhostuser->data.nix.listen ?
"server" : "client");
- virBufferAddLit(buf, "/>\n");
+ sourceLines++;
}
break;
- virBufferEscapeString(buf, "<source bridge='%s'/>\n",
- def->data.bridge.brname);
+ if (def->data.bridge.brname) {
This alone seems line a separate patch... But then again there's already
sooooo many....
The reason that extra if() was needed is that virBufferEscapeString()
will emit nothing if the argument is NULL, but in our case we only want
to increment sourceLines if something was printed. (This was caught by a
unit test, btw).
Post by John Ferlan
Post by Laine Stump
+ virBufferEscapeString(buf, "<source bridge='%s'",
+ def->data.bridge.brname);
+ sourceLines++;
+ }
break;
@@ -20794,25 +20819,25 @@ virDomainNetDefFormat(virBufferPtr buf,
virBufferAsprintf(buf, "<source port='%d'",
def->data.socket.port);
}
+ sourceLines++;
- if (def->type != VIR_DOMAIN_NET_TYPE_UDP) {
- virBufferAddLit(buf, "/>\n");
+ if (def->type != VIR_DOMAIN_NET_TYPE_UDP)
break;
- }
virBufferAddLit(buf, ">\n");
+ sourceLines++;
virBufferAdjustIndent(buf, 2);
virBufferAsprintf(buf, "<local address='%s' port='%d'/>\n",
def->data.socket.localaddr,
def->data.socket.localport);
virBufferAdjustIndent(buf, -2);
- virBufferAddLit(buf, "</source>\n");
break;
- virBufferEscapeString(buf, "<source name='%s'/>\n",
+ virBufferEscapeString(buf, "<source name='%s'",
def->data.internal.name);
+ sourceLines++;
break;
@@ -20820,7 +20845,7 @@ virDomainNetDefFormat(virBufferPtr buf,
def->data.direct.linkdev);
virBufferAsprintf(buf, " mode='%s'",
virNetDevMacVLanModeTypeToString(def->data.direct.mode));
- virBufferAddLit(buf, "/>\n");
+ sourceLines++;
break;
@@ -20835,12 +20860,44 @@ virDomainNetDefFormat(virBufferPtr buf,
break;
}
+ /* if sourceLines == 0 - no <source> info at all so far
+ * sourceLines == 1 - first line writte, no terminating ">"
s/writte/written
I think the Validate should be a PostParse - your thoughts...
See above. I think you're just resistent to change :-P
Post by John Ferlan
The
'contents' of the change are ACKable, I just think the placement is a
bit off. Then of course there's the whole doing multiple things here
(there could conceivably be 3 patches out of this).
I "assume" there are other XML2XML tests that ensure all the following
magic is correct since you added one for the new data...
Yes. The unit tests caught problems with it initially, so they are there.
John Ferlan
2016-06-24 17:20:11 UTC
Permalink
[...]
Post by Laine Stump
Post by John Ferlan
Post by Laine Stump
+virDomainNetDefValidate(const virDomainNetDef *net)
+{
+ if ((net->hostIP.nroutes || net->hostIP.nips) &&
+ net->type != VIR_DOMAIN_NET_TYPE_ETHERNET) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("Invalid attempt to set network interface "
+ "host-side IP route and/or address info on "
+ "interface of type '%s'. This is only supported "
+ "on interfaces of type 'ethernet'"),
+ virDomainNetTypeToString(net->type));
+ return -1;
+ }
+ return 0;
+}
It seems as though you are *adding* a new element - thus, this could not
be present on a currently running domain, so wouldn't the "more correct"
placement be the PostParse API's ?
I don't think we're losing any functionality by putting it here (other
than that if someone edits the config files directly on disk and then
restart libvirtd they won't see an error; but then they'll be getting
what they deserve). And I think its function fits better with the
Validate function than with the PostParse callback (which admittedly
does have some validating done in it, but that's just because the
Validate callbacks are a fairly recent addition.
In general, I think anything that is just validating the data in a
domain as a whole should be done in the Validate callbacks, and things
that modify the domain or devices should be in the postparse callbacks.
Eventually pure validation should migrate, and for now at least new
stuff should be added in that way. (Note that I still think that basic
validation that doesn't require knowledge of any other part of the XML
should still be done directly in the parse (numeric ranges, etc;
basically anything that is described in the RNG).
That's fine - keep it here.
[...]
Post by Laine Stump
Post by John Ferlan
Post by Laine Stump
+ /* if sourceLines == 0 - no <source> info at all so far
+ * sourceLines == 1 - first line writte, no terminating ">"
s/writte/written
I think the Validate should be a PostParse - your thoughts...
See above. I think you're just resistent to change :-P
By patch 25 I'm surprised I even noticed it.

Explanation accepted - ACK

John

Anyone less resistant to change can always move it later.
Post by Laine Stump
Post by John Ferlan
The
'contents' of the change are ACKable, I just think the placement is a
bit off. Then of course there's the whole doing multiple things here
(there could conceivably be 3 patches out of this).
I "assume" there are other XML2XML tests that ensure all the following
magic is correct since you added one for the new data...
Yes. The unit tests caught problems with it initially, so they are there.
Laine Stump
2016-06-22 17:37:06 UTC
Permalink
lxcContainerRenameAndEnableInterfaces() isn't making a copy of the
interface's ifname_guest (into newname), it's just copying the pointer
to it. This means that when it later calls VIR_FREE(newname), it's
actually freeing up (and fortunately NULLing out, so at least we don't
try to access free'd memory) netDef->ifname_guest.
---
src/lxc/lxc_container.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c
index 531bbd5..3d9e28b 100644
--- a/src/lxc/lxc_container.c
+++ b/src/lxc/lxc_container.c
@@ -490,7 +490,7 @@ static int lxcContainerRenameAndEnableInterfaces(virDomainDefPtr vmDef,
{
int rc = 0;
size_t i, j;
- char *newname = NULL;
+ const char *newname;
char *toStr = NULL;
char *viaStr = NULL;
virDomainNetDefPtr netDef;
@@ -552,8 +552,6 @@ static int lxcContainerRenameAndEnableInterfaces(virDomainDefPtr vmDef,
VIR_FREE(viaStr);
}
}
-
- VIR_FREE(newname);
}

/* enable lo device only if there were other net devices */
@@ -563,7 +561,6 @@ static int lxcContainerRenameAndEnableInterfaces(virDomainDefPtr vmDef,
error_out:
VIR_FREE(toStr);
VIR_FREE(viaStr);
- VIR_FREE(newname);
return rc;
}
--
2.5.5
John Ferlan
2016-06-23 21:24:24 UTC
Permalink
Post by Laine Stump
lxcContainerRenameAndEnableInterfaces() isn't making a copy of the
interface's ifname_guest (into newname), it's just copying the pointer
to it. This means that when it later calls VIR_FREE(newname), it's
actually freeing up (and fortunately NULLing out, so at least we don't
try to access free'd memory) netDef->ifname_guest.
---
src/lxc/lxc_container.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
ACK

John
Laine Stump
2016-06-22 17:37:19 UTC
Permalink
It makes more sense to have the logging at the lower level so other
callers can share the goodness.

While removing so much stuff from / touching so many lines in
lxcContainerRenameAndEnableInterfaces() (which used to have this
debug/error logging), label names were changed and it was updated to
use the now-more-common method of initializing ret to -1 (failure),
then setting to 0 right before the cleanup label.
---
src/lxc/lxc_container.c | 60 +++++++++++++++++++++----------------------------
src/util/virnetdevip.c | 32 ++++++++++++++++++++++----
2 files changed, 53 insertions(+), 39 deletions(-)

diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c
index a5ced92..09ad8cb 100644
--- a/src/lxc/lxc_container.c
+++ b/src/lxc/lxc_container.c
@@ -484,33 +484,32 @@ lxcContainerGetNetDef(virDomainDefPtr vmDef, const char *devName)
*
* Returns 0 on success or nonzero in case of error
*/
-static int lxcContainerRenameAndEnableInterfaces(virDomainDefPtr vmDef,
- size_t nveths,
- char **veths)
+static int
+lxcContainerRenameAndEnableInterfaces(virDomainDefPtr vmDef,
+ size_t nveths,
+ char **veths)
{
- int rc = 0;
+ int ret = -1;
size_t i, j;
const char *newname;
- char *toStr = NULL;
- char *viaStr = NULL;
virDomainNetDefPtr netDef;
bool privNet = vmDef->features[VIR_DOMAIN_FEATURE_PRIVNET] ==
VIR_TRISTATE_SWITCH_ON;

for (i = 0; i < nveths; i++) {
if (!(netDef = lxcContainerGetNetDef(vmDef, veths[i])))
- return -1;
+ goto cleanup;

newname = netDef->ifname_guest;
if (!newname) {
- rc = -1;
- goto error_out;
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("Missing device name for container-side veth"));
+ goto cleanup;
}

VIR_DEBUG("Renaming %s to %s", veths[i], newname);
- rc = virNetDevSetName(veths[i], newname);
- if (rc < 0)
- goto error_out;
+ if (virNetDevSetName(veths[i], newname) < 0)
+ goto cleanup;

for (j = 0; j < netDef->guestIP.nips; j++) {
virNetDevIPAddrPtr ip = netDef->guestIP.ips[j];
@@ -519,30 +518,23 @@ static int lxcContainerRenameAndEnableInterfaces(virDomainDefPtr vmDef,

if ((prefix = virSocketAddrGetIPPrefix(&ip->address,
NULL, ip->prefix)) < 0) {
+ ipStr = virSocketAddrFormat(&ip->address);
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Failed to determine prefix for IP address '%s'"),
ipStr);
- goto error_out;
- }
-
- VIR_DEBUG("Adding IP address '%s/%d' to '%s'",
- ipStr, prefix, newname);
- if (virNetDevIPAddrAdd(newname, &ip->address, NULL, prefix) < 0) {
- virReportError(VIR_ERR_SYSTEM_ERROR,
- _("Failed to set IP address '%s' on %s"),
- ipStr, newname);
VIR_FREE(ipStr);
- goto error_out;
+ goto cleanup;
}
- VIR_FREE(ipStr);
+
+ if (virNetDevIPAddrAdd(newname, &ip->address, NULL, prefix) < 0)
+ goto cleanup;
}

if (netDef->guestIP.nips ||
netDef->linkstate == VIR_DOMAIN_NET_INTERFACE_LINK_STATE_UP) {
VIR_DEBUG("Enabling %s", newname);
- rc = virNetDevSetOnline(newname, true);
- if (rc < 0)
- goto error_out;
+ if (virNetDevSetOnline(newname, true) < 0)
+ goto cleanup;

/* Set the routes */
for (j = 0; j < netDef->guestIP.nroutes; j++) {
@@ -553,22 +545,20 @@ static int lxcContainerRenameAndEnableInterfaces(virDomainDefPtr vmDef,
virNetDevIPRouteGetPrefix(route),
virNetDevIPRouteGetGateway(route),
virNetDevIPRouteGetMetric(route)) < 0) {
- goto error_out;
+ goto cleanup;
}
- VIR_FREE(toStr);
- VIR_FREE(viaStr);
}
}
}

/* enable lo device only if there were other net devices */
- if (veths || privNet)
- rc = virNetDevSetOnline("lo", true);
+ if ((veths || privNet) &&
+ virNetDevSetOnline("lo", true) < 0)
+ goto cleanup;

- error_out:
- VIR_FREE(toStr);
- VIR_FREE(viaStr);
- return rc;
+ ret = 0;
+ cleanup:
+ return ret;
}


diff --git a/src/util/virnetdevip.c b/src/util/virnetdevip.c
index 376d4ad..dad342f 100644
--- a/src/util/virnetdevip.c
+++ b/src/util/virnetdevip.c
@@ -173,6 +173,13 @@ virNetDevIPAddrAdd(const char *ifname,
struct nl_msg *nlmsg = NULL;
struct nlmsghdr *resp = NULL;
unsigned int recvbuflen;
+ char *ipStr = NULL;
+ char *peerStr = NULL;
+ char *bcastStr = NULL;
+
+ ipStr = virSocketAddrFormat(addr);
+ if (peer && VIR_SOCKET_ADDR_VALID(peer))
+ peerStr = virSocketAddrFormat(peer);

/* The caller needs to provide a correct address */
if (VIR_SOCKET_ADDR_FAMILY(addr) == AF_INET &&
@@ -181,28 +188,45 @@ virNetDevIPAddrAdd(const char *ifname,
if (VIR_ALLOC(broadcast) < 0)
return -1;

- if (virSocketAddrBroadcastByPrefix(addr, prefix, broadcast) < 0)
+ if (virSocketAddrBroadcastByPrefix(addr, prefix, broadcast) < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Failed to determine broadcast address for '%s/%d'"),
+ ipStr, prefix);
goto cleanup;
+ }
+ bcastStr = virSocketAddrFormat(broadcast);
}

+ VIR_DEBUG("Adding IP address %s/%d%s%s%s%s to %s", ipStr, prefix,
+ peerStr ? " peer " : "", peerStr ? peerStr : "",
+ bcastStr ? " bcast " : "", bcastStr ? bcastStr : "",
+ ifname);
+
if (!(nlmsg = virNetDevCreateNetlinkAddressMessage(RTM_NEWADDR, ifname,
addr, prefix,
broadcast, peer)))
goto cleanup;

- if (virNetlinkCommand(nlmsg, &resp, &recvbuflen, 0, 0,
- NETLINK_ROUTE, 0) < 0)
+ if (virNetlinkCommand(nlmsg, &resp, &recvbuflen,
+ 0, 0, NETLINK_ROUTE, 0) < 0)
goto cleanup;


if (virNetlinkGetErrorCode(resp, recvbuflen) < 0) {
virReportError(VIR_ERR_SYSTEM_ERROR,
- _("Error adding IP address to %s"), ifname);
+ _("Failed to add IP address %s/%d%s%s%s%s to %s"),
+ ipStr, prefix,
+ peerStr ? " peer " : "", peerStr ? peerStr : "",
+ bcastStr ? " bcast " : "", bcastStr ? bcastStr : "",
+ ifname);
goto cleanup;
}

ret = 0;
cleanup:
+ VIR_FREE(ipStr);
+ VIR_FREE(peerStr);
+ VIR_FREE(bcastStr);
nlmsg_free(nlmsg);
VIR_FREE(resp);
VIR_FREE(broadcast);
--
2.5.5
John Ferlan
2016-06-24 12:43:17 UTC
Permalink
Post by Laine Stump
It makes more sense to have the logging at the lower level so other
callers can share the goodness.
While removing so much stuff from / touching so many lines in
lxcContainerRenameAndEnableInterfaces() (which used to have this
debug/error logging), label names were changed and it was updated to
use the now-more-common method of initializing ret to -1 (failure),
then setting to 0 right before the cleanup label.
---
src/lxc/lxc_container.c | 60 +++++++++++++++++++++----------------------------
src/util/virnetdevip.c | 32 ++++++++++++++++++++++----
2 files changed, 53 insertions(+), 39 deletions(-)
diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c
index a5ced92..09ad8cb 100644
--- a/src/lxc/lxc_container.c
+++ b/src/lxc/lxc_container.c
@@ -484,33 +484,32 @@ lxcContainerGetNetDef(virDomainDefPtr vmDef, const char *devName)
*
* Returns 0 on success or nonzero in case of error
*/
-static int lxcContainerRenameAndEnableInterfaces(virDomainDefPtr vmDef,
- size_t nveths,
- char **veths)
+static int
+lxcContainerRenameAndEnableInterfaces(virDomainDefPtr vmDef,
+ size_t nveths,
+ char **veths)
{
- int rc = 0;
+ int ret = -1;
size_t i, j;
const char *newname;
- char *toStr = NULL;
- char *viaStr = NULL;
virDomainNetDefPtr netDef;
bool privNet = vmDef->features[VIR_DOMAIN_FEATURE_PRIVNET] ==
VIR_TRISTATE_SWITCH_ON;
for (i = 0; i < nveths; i++) {
if (!(netDef = lxcContainerGetNetDef(vmDef, veths[i])))
- return -1;
+ goto cleanup;
newname = netDef->ifname_guest;
if (!newname) {
- rc = -1;
- goto error_out;
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("Missing device name for container-side veth"));
+ goto cleanup;
}
VIR_DEBUG("Renaming %s to %s", veths[i], newname);
- rc = virNetDevSetName(veths[i], newname);
- if (rc < 0)
- goto error_out;
+ if (virNetDevSetName(veths[i], newname) < 0)
+ goto cleanup;
for (j = 0; j < netDef->guestIP.nips; j++) {
virNetDevIPAddrPtr ip = netDef->guestIP.ips[j];
@@ -519,30 +518,23 @@ static int lxcContainerRenameAndEnableInterfaces(virDomainDefPtr vmDef,
if ((prefix = virSocketAddrGetIPPrefix(&ip->address,
NULL, ip->prefix)) < 0) {
+ ipStr = virSocketAddrFormat(&ip->address);
Coverity complains here that ipStr is overwritten (from 4 lines up -
char *ipStr = virSocketAddrFormat(&ip->address);)

It seems the first one is duplicitous.
Post by Laine Stump
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Failed to determine prefix for IP address '%s'"),
ipStr);
- goto error_out;
- }
-
- VIR_DEBUG("Adding IP address '%s/%d' to '%s'",
- ipStr, prefix, newname);
- if (virNetDevIPAddrAdd(newname, &ip->address, NULL, prefix) < 0) {
- virReportError(VIR_ERR_SYSTEM_ERROR,
- _("Failed to set IP address '%s' on %s"),
- ipStr, newname);
VIR_FREE(ipStr);
- goto error_out;
+ goto cleanup;
}
- VIR_FREE(ipStr);
+
+ if (virNetDevIPAddrAdd(newname, &ip->address, NULL, prefix) < 0)
+ goto cleanup;
}
if (netDef->guestIP.nips ||
netDef->linkstate == VIR_DOMAIN_NET_INTERFACE_LINK_STATE_UP) {
VIR_DEBUG("Enabling %s", newname);
- rc = virNetDevSetOnline(newname, true);
- if (rc < 0)
- goto error_out;
+ if (virNetDevSetOnline(newname, true) < 0)
+ goto cleanup;
/* Set the routes */
for (j = 0; j < netDef->guestIP.nroutes; j++) {
@@ -553,22 +545,20 @@ static int lxcContainerRenameAndEnableInterfaces(virDomainDefPtr vmDef,
virNetDevIPRouteGetPrefix(route),
virNetDevIPRouteGetGateway(route),
virNetDevIPRouteGetMetric(route)) < 0) {
- goto error_out;
+ goto cleanup;
}
- VIR_FREE(toStr);
- VIR_FREE(viaStr);
Hmm... Seems commit id 'a117652917e' forgot about 'em....
Post by Laine Stump
}
}
}
/* enable lo device only if there were other net devices */
- if (veths || privNet)
- rc = virNetDevSetOnline("lo", true);
+ if ((veths || privNet) &&
+ virNetDevSetOnline("lo", true) < 0)
+ goto cleanup;
- VIR_FREE(toStr);
- VIR_FREE(viaStr);
- return rc;
+ ret = 0;
+ return ret;
}
diff --git a/src/util/virnetdevip.c b/src/util/virnetdevip.c
index 376d4ad..dad342f 100644
--- a/src/util/virnetdevip.c
+++ b/src/util/virnetdevip.c
@@ -173,6 +173,13 @@ virNetDevIPAddrAdd(const char *ifname,
struct nl_msg *nlmsg = NULL;
struct nlmsghdr *resp = NULL;
unsigned int recvbuflen;
+ char *ipStr = NULL;
+ char *peerStr = NULL;
+ char *bcastStr = NULL;
+
+ ipStr = virSocketAddrFormat(addr);
Note - no check if ipStr is NULL...
Post by Laine Stump
+ if (peer && VIR_SOCKET_ADDR_VALID(peer))
+ peerStr = virSocketAddrFormat(peer);
/* The caller needs to provide a correct address */
if (VIR_SOCKET_ADDR_FAMILY(addr) == AF_INET &&
@@ -181,28 +188,45 @@ virNetDevIPAddrAdd(const char *ifname,
if (VIR_ALLOC(broadcast) < 0)
return -1;
Coverity let me know this causes ipStr to be leaked. Probably similar
for peerStr too, but Coverity didn't note that one.
Post by Laine Stump
- if (virSocketAddrBroadcastByPrefix(addr, prefix, broadcast) < 0)
+ if (virSocketAddrBroadcastByPrefix(addr, prefix, broadcast) < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Failed to determine broadcast address for '%s/%d'"),
+ ipStr, prefix);
goto cleanup;
+ }
+ bcastStr = virSocketAddrFormat(broadcast);
}
+ VIR_DEBUG("Adding IP address %s/%d%s%s%s%s to %s", ipStr, prefix,
+ peerStr ? " peer " : "", peerStr ? peerStr : "",
+ bcastStr ? " bcast " : "", bcastStr ? bcastStr : "",
+ ifname);
+
NULLSTR() or perhaps EMPTYSTR()? For ipStr, peerStr, and bcastStr...

In any case, since ipStr could be NULL it needs the similar check
Post by Laine Stump
if (!(nlmsg = virNetDevCreateNetlinkAddressMessage(RTM_NEWADDR, ifname,
addr, prefix,
broadcast, peer)))
goto cleanup;
- if (virNetlinkCommand(nlmsg, &resp, &recvbuflen, 0, 0,
- NETLINK_ROUTE, 0) < 0)
+ if (virNetlinkCommand(nlmsg, &resp, &recvbuflen,
+ 0, 0, NETLINK_ROUTE, 0) < 0)
goto cleanup;
if (virNetlinkGetErrorCode(resp, recvbuflen) < 0) {
virReportError(VIR_ERR_SYSTEM_ERROR,
- _("Error adding IP address to %s"), ifname);
+ _("Failed to add IP address %s/%d%s%s%s%s to %s"),
+ ipStr, prefix,
+ peerStr ? " peer " : "", peerStr ? peerStr : "",
+ bcastStr ? " bcast " : "", bcastStr ? bcastStr : "",
+ ifname);
Similar comment regarding ipStr, peerStr, and bcastStr usage

ACK with the adjustments,

John
Post by Laine Stump
goto cleanup;
}
ret = 0;
+ VIR_FREE(ipStr);
+ VIR_FREE(peerStr);
+ VIR_FREE(bcastStr);
nlmsg_free(nlmsg);
VIR_FREE(resp);
VIR_FREE(broadcast);
Laine Stump
2016-06-24 19:55:15 UTC
Permalink
Post by John Ferlan
Post by Laine Stump
It makes more sense to have the logging at the lower level so other
callers can share the goodness.
While removing so much stuff from / touching so many lines in
lxcContainerRenameAndEnableInterfaces() (which used to have this
debug/error logging), label names were changed and it was updated to
use the now-more-common method of initializing ret to -1 (failure),
then setting to 0 right before the cleanup label.
---
src/lxc/lxc_container.c | 60 +++++++++++++++++++++----------------------------
src/util/virnetdevip.c | 32 ++++++++++++++++++++++----
2 files changed, 53 insertions(+), 39 deletions(-)
diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c
index a5ced92..09ad8cb 100644
--- a/src/lxc/lxc_container.c
+++ b/src/lxc/lxc_container.c
@@ -484,33 +484,32 @@ lxcContainerGetNetDef(virDomainDefPtr vmDef, const char *devName)
*
* Returns 0 on success or nonzero in case of error
*/
-static int lxcContainerRenameAndEnableInterfaces(virDomainDefPtr vmDef,
- size_t nveths,
- char **veths)
+static int
+lxcContainerRenameAndEnableInterfaces(virDomainDefPtr vmDef,
+ size_t nveths,
+ char **veths)
{
- int rc = 0;
+ int ret = -1;
size_t i, j;
const char *newname;
- char *toStr = NULL;
- char *viaStr = NULL;
virDomainNetDefPtr netDef;
bool privNet = vmDef->features[VIR_DOMAIN_FEATURE_PRIVNET] ==
VIR_TRISTATE_SWITCH_ON;
for (i = 0; i < nveths; i++) {
if (!(netDef = lxcContainerGetNetDef(vmDef, veths[i])))
- return -1;
+ goto cleanup;
newname = netDef->ifname_guest;
if (!newname) {
- rc = -1;
- goto error_out;
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("Missing device name for container-side veth"));
+ goto cleanup;
}
VIR_DEBUG("Renaming %s to %s", veths[i], newname);
- rc = virNetDevSetName(veths[i], newname);
- if (rc < 0)
- goto error_out;
+ if (virNetDevSetName(veths[i], newname) < 0)
+ goto cleanup;
for (j = 0; j < netDef->guestIP.nips; j++) {
virNetDevIPAddrPtr ip = netDef->guestIP.ips[j];
@@ -519,30 +518,23 @@ static int lxcContainerRenameAndEnableInterfaces(virDomainDefPtr vmDef,
if ((prefix = virSocketAddrGetIPPrefix(&ip->address,
NULL, ip->prefix)) < 0) {
+ ipStr = virSocketAddrFormat(&ip->address);
Coverity complains here that ipStr is overwritten (from 4 lines up -
char *ipStr = virSocketAddrFormat(&ip->address);)
It seems the first one is duplicitous.
This is just a re-hash of the missing VIR_FREE(ipStr) you found earlier.
I think all of these were caused by me messing up merge conflict
resolution when I re-ordered the patches - this code is actually
eliminate a patch or two later and replaced with a new function that (I
think - going to recheck) is correct.
Post by John Ferlan
Post by Laine Stump
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Failed to determine prefix for IP address '%s'"),
ipStr);
- goto error_out;
- }
-
- VIR_DEBUG("Adding IP address '%s/%d' to '%s'",
- ipStr, prefix, newname);
- if (virNetDevIPAddrAdd(newname, &ip->address, NULL, prefix) < 0) {
- virReportError(VIR_ERR_SYSTEM_ERROR,
- _("Failed to set IP address '%s' on %s"),
- ipStr, newname);
VIR_FREE(ipStr);
- goto error_out;
+ goto cleanup;
}
- VIR_FREE(ipStr);
+
+ if (virNetDevIPAddrAdd(newname, &ip->address, NULL, prefix) < 0)
+ goto cleanup;
}
if (netDef->guestIP.nips ||
netDef->linkstate == VIR_DOMAIN_NET_INTERFACE_LINK_STATE_UP) {
VIR_DEBUG("Enabling %s", newname);
- rc = virNetDevSetOnline(newname, true);
- if (rc < 0)
- goto error_out;
+ if (virNetDevSetOnline(newname, true) < 0)
+ goto cleanup;
/* Set the routes */
for (j = 0; j < netDef->guestIP.nroutes; j++) {
@@ -553,22 +545,20 @@ static int lxcContainerRenameAndEnableInterfaces(virDomainDefPtr vmDef,
virNetDevIPRouteGetPrefix(route),
virNetDevIPRouteGetGateway(route),
virNetDevIPRouteGetMetric(route)) < 0) {
- goto error_out;
+ goto cleanup;
}
- VIR_FREE(toStr);
- VIR_FREE(viaStr);
Hmm... Seems commit id 'a117652917e' forgot about 'em....
Yeah. My guess is that he was planning to output debug info to the log,
then never got around to it. Since the new functions that will replace
this are logging stuff, I just removed them.
Post by John Ferlan
Post by Laine Stump
}
}
}
/* enable lo device only if there were other net devices */
- if (veths || privNet)
- rc = virNetDevSetOnline("lo", true);
+ if ((veths || privNet) &&
+ virNetDevSetOnline("lo", true) < 0)
+ goto cleanup;
- VIR_FREE(toStr);
- VIR_FREE(viaStr);
- return rc;
+ ret = 0;
+ return ret;
}
diff --git a/src/util/virnetdevip.c b/src/util/virnetdevip.c
index 376d4ad..dad342f 100644
--- a/src/util/virnetdevip.c
+++ b/src/util/virnetdevip.c
@@ -173,6 +173,13 @@ virNetDevIPAddrAdd(const char *ifname,
struct nl_msg *nlmsg = NULL;
struct nlmsghdr *resp = NULL;
unsigned int recvbuflen;
+ char *ipStr = NULL;
+ char *peerStr = NULL;
+ char *bcastStr = NULL;
+
+ ipStr = virSocketAddrFormat(addr);
Note - no check if ipStr is NULL...
Post by Laine Stump
+ if (peer && VIR_SOCKET_ADDR_VALID(peer))
+ peerStr = virSocketAddrFormat(peer);
/* The caller needs to provide a correct address */
if (VIR_SOCKET_ADDR_FAMILY(addr) == AF_INET &&
@@ -181,28 +188,45 @@ virNetDevIPAddrAdd(const char *ifname,
if (VIR_ALLOC(broadcast) < 0)
return -1;
Coverity let me know this causes ipStr to be leaked. Probably similar
for peerStr too, but Coverity didn't note that one.
Post by Laine Stump
- if (virSocketAddrBroadcastByPrefix(addr, prefix, broadcast) < 0)
+ if (virSocketAddrBroadcastByPrefix(addr, prefix, broadcast) < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Failed to determine broadcast address for '%s/%d'"),
+ ipStr, prefix);
goto cleanup;
+ }
+ bcastStr = virSocketAddrFormat(broadcast);
}
+ VIR_DEBUG("Adding IP address %s/%d%s%s%s%s to %s", ipStr, prefix,
+ peerStr ? " peer " : "", peerStr ? peerStr : "",
+ bcastStr ? " bcast " : "", bcastStr ? bcastStr : "",
+ ifname);
+
NULLSTR() or perhaps EMPTYSTR()? For ipStr, peerStr, and bcastStr...
In any case, since ipStr could be NULL it needs the similar check
Yep. I'll do that.
Post by John Ferlan
Post by Laine Stump
if (!(nlmsg = virNetDevCreateNetlinkAddressMessage(RTM_NEWADDR, ifname,
addr, prefix,
broadcast, peer)))
goto cleanup;
- if (virNetlinkCommand(nlmsg, &resp, &recvbuflen, 0, 0,
- NETLINK_ROUTE, 0) < 0)
+ if (virNetlinkCommand(nlmsg, &resp, &recvbuflen,
+ 0, 0, NETLINK_ROUTE, 0) < 0)
goto cleanup;
if (virNetlinkGetErrorCode(resp, recvbuflen) < 0) {
virReportError(VIR_ERR_SYSTEM_ERROR,
- _("Error adding IP address to %s"), ifname);
+ _("Failed to add IP address %s/%d%s%s%s%s to %s"),
+ ipStr, prefix,
+ peerStr ? " peer " : "", peerStr ? peerStr : "",
+ bcastStr ? " bcast " : "", bcastStr ? bcastStr : "",
+ ifname);
Similar comment regarding ipStr, peerStr, and bcastStr usage
And that.
Post by John Ferlan
ACK with the adjustments,
John
Post by Laine Stump
goto cleanup;
}
ret = 0;
+ VIR_FREE(ipStr);
+ VIR_FREE(peerStr);
+ VIR_FREE(bcastStr);
nlmsg_free(nlmsg);
VIR_FREE(resp);
VIR_FREE(broadcast);
Laine Stump
2016-06-26 21:20:57 UTC
Permalink
Post by Laine Stump
Post by John Ferlan
Post by Laine Stump
+ VIR_DEBUG("Adding IP address %s/%d%s%s%s%s to %s", ipStr, prefix,
+ peerStr ? " peer " : "", peerStr ? peerStr : "",
+ bcastStr ? " bcast " : "", bcastStr ? bcastStr : "",
+ ifname);
+
NULLSTR() or perhaps EMPTYSTR()? For ipStr, peerStr, and bcastStr...
In any case, since ipStr could be NULL it needs the similar check
Yep. I'll do that.
Actually, neither NULLSTR() nor EMPTYSTR() does what is needed, as the
former inserts "<null>" and the latter inserts "-", while I want it to
insert "". I will do it for ipStr though, just on the off chance that
virSocketAddrFormat() gets an OOM or some other strange error.
(Practically speaking glibc would put "(null)" into the string in that
case, but just in case someone isn't using glibc...)
Laine Stump
2016-06-22 17:37:23 UTC
Permalink
From: Vasiliy Tolstov <***@selfip.ru>

The peer attribute is used to set the property of the same name in the
interface IP info:

<interface type='ethernet'>
...
<ip family='ipv4' address='192.168.122.5'
prefix='32' peer='192.168.122.6'/>
...
</interface>

Note that this element is used to set the IP information on the
*guest* side interface, not the host side interface - that will be
supported in an upcoming patch.

(This is an updated *re*-commit of commit 690969af, which was
subsequently reverted in commit 1d14b13f).

Signed-off-by: Vasiliy Tolstov <***@selfip.ru>
Signed-off-by: Laine Stump <***@laine.org>
---
docs/formatdomain.html.in | 40 +++++++++++++++++++++++++---------------
docs/schemas/domaincommon.rng | 5 +++++
src/conf/domain_conf.c | 16 +++++++++++++++-
src/conf/domain_conf.h | 1 +
src/util/virnetdevip.h | 5 +++--
5 files changed, 49 insertions(+), 18 deletions(-)

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index f660aa6..2466df7 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -4967,6 +4967,7 @@ qemu-kvm -net nic,model=? /dev/null
&lt;source network='default'/&gt;
&lt;target dev='vnet0'/&gt; <b>&lt;ip address='192.168.122.5' prefix='24'/&gt;</b>
+ <b>&lt;ip address='192.168.122.5' prefix='24' peer='10.0.0.10'/&gt;</b> <b>&lt;route family='ipv4' address='192.168.122.0' prefix='24' gateway='192.168.122.1'/&gt;</b> <b>&lt;route family='ipv4' address='192.168.122.8' gateway='192.168.122.1'/&gt;</b>
&lt;/interface&gt;
@@ -4985,21 +4986,30 @@ qemu-kvm -net nic,model=? /dev/null
</pre>

<p>
- <span class="since">Since 1.2.12</span> the network devices and host devices
- with network capabilities can be provided zero or more IP addresses to set
- on the target device. Note that some hypervisors or network device types
- will simply ignore them or only use the first one. The <code>family</code>
- attribute can be set to either <code>ipv4</code> or <code>ipv6</code>, the
- <code>address</code> attribute holds the IP address. The <code>prefix</code>
- is not mandatory since some hypervisors do not handle it.
- </p>
-
- <p>
- <span class="since">Since 1.2.12</span> route elements can also be added
- to define the network routes to use for the network device. The attributes
- of this element are described in the documentation for the <code>route</code>
- element in <a href="formatnetwork.html#elementsStaticroute">network definitions</a>.
- This is only used by the LXC driver.
+ <span class="since">Since 1.2.12</span> network devices and
+ hostdev devices with network capabilities can optionally be provided
+ one or more IP addresses to set on the network device in the
+ guest. Note that some hypervisors or network device types will
+ simply ignore them or only use the first one.
+ The <code>family</code> attribute can be set to
+ either <code>ipv4</code> or <code>ipv6</code>, and the
+ <code>address</code> attribute contains the IP address. The
+ optional <code>prefix</code> is the number of 1 bits in the
+ netmask, and will be automatically set if not specified - for
+ IPv4 the default prefix is determined according to the network
+ "class" (A, B, or C - see RFC870), and for IPv6 the default
+ prefix is 64. The optional <code>peer</code> attribute holds the
+ IP address of the other end of a point-to-point network
+ device <span class="since">(since 2.0.0)</span>.
+ </p>
+
+ <p>
+ <span class="since">Since 1.2.12</span> route elements can also be
+ added to define IP routes to add in the guest. The attributes of
+ this element are described in the documentation for
+ the <code>route</code> element
+ in <a href="formatnetwork.html#elementsStaticroute">network
+ definitions</a>. This is used by the LXC driver.
</p>

<h5><a name="elementVhostuser">vhost-user interface</a></h5>
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 563cb3c..2d12da9 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -2629,6 +2629,11 @@
<ref name="ipPrefix"/>
</attribute>
</optional>
+ <optional>
+ <attribute name="peer">
+ <ref name="ipAddr"/>
+ </attribute>
+ </optional>
<empty/>
</element>
</zeroOrMore>
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index df52ac9..ad2d983 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -6108,7 +6108,7 @@ virDomainNetIPParseXML(xmlNodePtr node)
unsigned int prefixValue = 0;
char *familyStr = NULL;
int family = AF_UNSPEC;
- char *address = NULL;
+ char *address = NULL, *peer = NULL;

if (!(address = virXMLPropString(node, "address"))) {
virReportError(VIR_ERR_XML_ERROR, "%s",
@@ -6146,6 +6146,13 @@ virDomainNetIPParseXML(xmlNodePtr node)
}
ip->prefix = prefixValue;

+ if ((peer = virXMLPropString(node, "peer")) != NULL &&
+ virSocketAddrParse(&ip->peer, peer, family) < 0) {
+ virReportError(VIR_ERR_INVALID_ARG,
+ _("Invalid peer '%s' in <ip>"), peer);
+ goto cleanup;
+ }
+
ret = ip;
ip = NULL;

@@ -6153,6 +6160,7 @@ virDomainNetIPParseXML(xmlNodePtr node)
VIR_FREE(prefixStr);
VIR_FREE(familyStr);
VIR_FREE(address);
+ VIR_FREE(peer);
VIR_FREE(ip);
return ret;
}
@@ -20254,6 +20262,12 @@ virDomainNetIPInfoFormat(virBufferPtr buf,
virBufferAsprintf(buf, " family='%s'", familyStr);
if (def->ips[i]->prefix)
virBufferAsprintf(buf, " prefix='%u'", def->ips[i]->prefix);
+ if (VIR_SOCKET_ADDR_VALID(&def->ips[i]->peer)) {
+ if (!(ipStr = virSocketAddrFormat(&def->ips[i]->peer)))
+ return -1;
+ virBufferAsprintf(buf, " peer='%s'", ipStr);
+ VIR_FREE(ipStr);
+ }
virBufferAddLit(buf, "/>\n");
}

diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 0df5579..7ff966f 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -383,6 +383,7 @@ typedef enum {
VIR_DOMAIN_HOSTDEV_CAPS_TYPE_LAST
} virDomainHostdevCapsType;

+
typedef struct _virDomainHostdevCaps virDomainHostdevCaps;
typedef virDomainHostdevCaps *virDomainHostdevCapsPtr;
struct _virDomainHostdevCaps {
diff --git a/src/util/virnetdevip.h b/src/util/virnetdevip.h
index 66c5c00..3b9b3e0 100644
--- a/src/util/virnetdevip.h
+++ b/src/util/virnetdevip.h
@@ -26,8 +26,9 @@
# include "virsocketaddr.h"

typedef struct {
- virSocketAddr address; /* ipv4 or ipv6 address */
- unsigned int prefix; /* number of 1 bits in the net mask */
+ virSocketAddr address; /* ipv4 or ipv6 address */
+ virSocketAddr peer; /* ipv4 or ipv6 address of peer */
+ unsigned int prefix; /* number of 1 bits in the netmask */
} virNetDevIPAddr, *virNetDevIPAddrPtr;

typedef struct {
--
2.5.5
John Ferlan
2016-06-24 13:29:46 UTC
Permalink
Post by Laine Stump
The peer attribute is used to set the property of the same name in the
<interface type='ethernet'>
...
<ip family='ipv4' address='192.168.122.5'
prefix='32' peer='192.168.122.6'/>
...
</interface>
Note that this element is used to set the IP information on the
*guest* side interface, not the host side interface - that will be
supported in an upcoming patch.
(This is an updated *re*-commit of commit 690969af, which was
subsequently reverted in commit 1d14b13f).
---
docs/formatdomain.html.in | 40 +++++++++++++++++++++++++---------------
docs/schemas/domaincommon.rng | 5 +++++
src/conf/domain_conf.c | 16 +++++++++++++++-
src/conf/domain_conf.h | 1 +
src/util/virnetdevip.h | 5 +++--
5 files changed, 49 insertions(+), 18 deletions(-)
It seems an earlier comment I made about freeaddrinfo for the
corresponding getaddrinfo becomes even more important now... So
somewhere between there and this patch, I think you need to generate a
Free API for virNetDevIPAddrPtr

Then everywhere that current just does a VIR_FREE(ip) should call it...
Thus this change "gets it" for free - well mostly free, you'd have to
add the freeaddrinfo() for the 'peer' as well as the 'address'

Of course I could be wrong and I'm sure you'll let me know ;-)
Post by Laine Stump
diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index f660aa6..2466df7 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -4967,6 +4967,7 @@ qemu-kvm -net nic,model=? /dev/null
@@ -4985,21 +4986,30 @@ qemu-kvm -net nic,model=? /dev/null
</pre>
<p>
- <span class="since">Since 1.2.12</span> the network devices and host devices
- with network capabilities can be provided zero or more IP addresses to set
- on the target device. Note that some hypervisors or network device types
- will simply ignore them or only use the first one. The <code>family</code>
- attribute can be set to either <code>ipv4</code> or <code>ipv6</code>, the
- <code>address</code> attribute holds the IP address. The <code>prefix</code>
- is not mandatory since some hypervisors do not handle it.
- </p>
-
- <p>
- <span class="since">Since 1.2.12</span> route elements can also be added
- to define the network routes to use for the network device. The attributes
- of this element are described in the documentation for the <code>route</code>
- element in <a href="formatnetwork.html#elementsStaticroute">network definitions</a>.
- This is only used by the LXC driver.
+ <span class="since">Since 1.2.12</span> network devices and
+ hostdev devices with network capabilities can optionally be provided
+ one or more IP addresses to set on the network device in the
+ guest. Note that some hypervisors or network device types will
+ simply ignore them or only use the first one.
+ The <code>family</code> attribute can be set to
+ either <code>ipv4</code> or <code>ipv6</code>, and the
+ <code>address</code> attribute contains the IP address. The
+ optional <code>prefix</code> is the number of 1 bits in the
+ netmask, and will be automatically set if not specified - for
+ IPv4 the default prefix is determined according to the network
+ "class" (A, B, or C - see RFC870), and for IPv6 the default
+ prefix is 64. The optional <code>peer</code> attribute holds the
+ IP address of the other end of a point-to-point network
+ device <span class="since">(since 2.0.0)</span>.
+ </p>
+
+ <p>
+ <span class="since">Since 1.2.12</span> route elements can also be
+ added to define IP routes to add in the guest. The attributes of
+ this element are described in the documentation for
+ the <code>route</code> element
+ in <a href="formatnetwork.html#elementsStaticroute">network
+ definitions</a>. This is used by the LXC driver.
</p>
<h5><a name="elementVhostuser">vhost-user interface</a></h5>
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 563cb3c..2d12da9 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -2629,6 +2629,11 @@
<ref name="ipPrefix"/>
</attribute>
</optional>
+ <optional>
+ <attribute name="peer">
+ <ref name="ipAddr"/>
+ </attribute>
+ </optional>
<empty/>
</element>
</zeroOrMore>
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index df52ac9..ad2d983 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -6108,7 +6108,7 @@ virDomainNetIPParseXML(xmlNodePtr node)
unsigned int prefixValue = 0;
char *familyStr = NULL;
int family = AF_UNSPEC;
- char *address = NULL;
+ char *address = NULL, *peer = NULL;
if (!(address = virXMLPropString(node, "address"))) {
virReportError(VIR_ERR_XML_ERROR, "%s",
@@ -6146,6 +6146,13 @@ virDomainNetIPParseXML(xmlNodePtr node)
}
ip->prefix = prefixValue;
+ if ((peer = virXMLPropString(node, "peer")) != NULL &&
+ virSocketAddrParse(&ip->peer, peer, family) < 0) {
+ virReportError(VIR_ERR_INVALID_ARG,
+ _("Invalid peer '%s' in <ip>"), peer);
+ goto cleanup;
+ }
+
ret = ip;
ip = NULL;
@@ -6153,6 +6160,7 @@ virDomainNetIPParseXML(xmlNodePtr node)
VIR_FREE(prefixStr);
VIR_FREE(familyStr);
VIR_FREE(address);
+ VIR_FREE(peer);
VIR_FREE(ip);
return ret;
}
@@ -20254,6 +20262,12 @@ virDomainNetIPInfoFormat(virBufferPtr buf,
virBufferAsprintf(buf, " family='%s'", familyStr);
if (def->ips[i]->prefix)
virBufferAsprintf(buf, " prefix='%u'", def->ips[i]->prefix);
+ if (VIR_SOCKET_ADDR_VALID(&def->ips[i]->peer)) {
+ if (!(ipStr = virSocketAddrFormat(&def->ips[i]->peer)))
+ return -1;
+ virBufferAsprintf(buf, " peer='%s'", ipStr);
+ VIR_FREE(ipStr);
+ }
virBufferAddLit(buf, "/>\n");
}
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 0df5579..7ff966f 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -383,6 +383,7 @@ typedef enum {
VIR_DOMAIN_HOSTDEV_CAPS_TYPE_LAST
} virDomainHostdevCapsType;
+
Spurious change that can be dropped.

This change is ACK'able with the mentioned adjustments (whether you want
to repost stuff or not is your call).

John
Post by Laine Stump
typedef struct _virDomainHostdevCaps virDomainHostdevCaps;
typedef virDomainHostdevCaps *virDomainHostdevCapsPtr;
struct _virDomainHostdevCaps {
diff --git a/src/util/virnetdevip.h b/src/util/virnetdevip.h
index 66c5c00..3b9b3e0 100644
--- a/src/util/virnetdevip.h
+++ b/src/util/virnetdevip.h
@@ -26,8 +26,9 @@
# include "virsocketaddr.h"
typedef struct {
- virSocketAddr address; /* ipv4 or ipv6 address */
- unsigned int prefix; /* number of 1 bits in the net mask */
+ virSocketAddr address; /* ipv4 or ipv6 address */
+ virSocketAddr peer; /* ipv4 or ipv6 address of peer */
+ unsigned int prefix; /* number of 1 bits in the netmask */
} virNetDevIPAddr, *virNetDevIPAddrPtr;
typedef struct {
Laine Stump
2016-06-24 19:59:46 UTC
Permalink
Post by John Ferlan
Post by Laine Stump
The peer attribute is used to set the property of the same name in the
<interface type='ethernet'>
...
<ip family='ipv4' address='192.168.122.5'
prefix='32' peer='192.168.122.6'/>
...
</interface>
Note that this element is used to set the IP information on the
*guest* side interface, not the host side interface - that will be
supported in an upcoming patch.
(This is an updated *re*-commit of commit 690969af, which was
subsequently reverted in commit 1d14b13f).
---
docs/formatdomain.html.in | 40 +++++++++++++++++++++++++---------------
docs/schemas/domaincommon.rng | 5 +++++
src/conf/domain_conf.c | 16 +++++++++++++++-
src/conf/domain_conf.h | 1 +
src/util/virnetdevip.h | 5 +++--
5 files changed, 49 insertions(+), 18 deletions(-)
It seems an earlier comment I made about freeaddrinfo for the
corresponding getaddrinfo becomes even more important now... So
somewhere between there and this patch, I think you need to generate a
Free API for virNetDevIPAddrPtr
Then everywhere that current just does a VIR_FREE(ip) should call it...
Thus this change "gets it" for free - well mostly free, you'd have to
add the freeaddrinfo() for the 'peer' as well as the 'address'
Of course I could be wrong and I'm sure you'll let me know ;-)
Yep. We already talked about this in IRC. the virNetDevIPAddr doesn't
contain the info returned from getaddrinfo. virSocketAddrParseInternal
(that's who calls getaddrinfo) is called by two other functions, and
both of those functions copy out the important stuff from getaddrinfo,
then call freeaddrinfo. So everything is correct.
Post by John Ferlan
Post by Laine Stump
diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index f660aa6..2466df7 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -4967,6 +4967,7 @@ qemu-kvm -net nic,model=? /dev/null
@@ -4985,21 +4986,30 @@ qemu-kvm -net nic,model=? /dev/null
</pre>
<p>
- <span class="since">Since 1.2.12</span> the network devices and host devices
- with network capabilities can be provided zero or more IP addresses to set
- on the target device. Note that some hypervisors or network device types
- will simply ignore them or only use the first one. The <code>family</code>
- attribute can be set to either <code>ipv4</code> or <code>ipv6</code>, the
- <code>address</code> attribute holds the IP address. The <code>prefix</code>
- is not mandatory since some hypervisors do not handle it.
- </p>
-
- <p>
- <span class="since">Since 1.2.12</span> route elements can also be added
- to define the network routes to use for the network device. The attributes
- of this element are described in the documentation for the <code>route</code>
- element in <a href="formatnetwork.html#elementsStaticroute">network definitions</a>.
- This is only used by the LXC driver.
+ <span class="since">Since 1.2.12</span> network devices and
+ hostdev devices with network capabilities can optionally be provided
+ one or more IP addresses to set on the network device in the
+ guest. Note that some hypervisors or network device types will
+ simply ignore them or only use the first one.
+ The <code>family</code> attribute can be set to
+ either <code>ipv4</code> or <code>ipv6</code>, and the
+ <code>address</code> attribute contains the IP address. The
+ optional <code>prefix</code> is the number of 1 bits in the
+ netmask, and will be automatically set if not specified - for
+ IPv4 the default prefix is determined according to the network
+ "class" (A, B, or C - see RFC870), and for IPv6 the default
+ prefix is 64. The optional <code>peer</code> attribute holds the
+ IP address of the other end of a point-to-point network
+ device <span class="since">(since 2.0.0)</span>.
+ </p>
+
+ <p>
+ <span class="since">Since 1.2.12</span> route elements can also be
+ added to define IP routes to add in the guest. The attributes of
+ this element are described in the documentation for
+ the <code>route</code> element
+ in <a href="formatnetwork.html#elementsStaticroute">network
+ definitions</a>. This is used by the LXC driver.
</p>
<h5><a name="elementVhostuser">vhost-user interface</a></h5>
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 563cb3c..2d12da9 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -2629,6 +2629,11 @@
<ref name="ipPrefix"/>
</attribute>
</optional>
+ <optional>
+ <attribute name="peer">
+ <ref name="ipAddr"/>
+ </attribute>
+ </optional>
<empty/>
</element>
</zeroOrMore>
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index df52ac9..ad2d983 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -6108,7 +6108,7 @@ virDomainNetIPParseXML(xmlNodePtr node)
unsigned int prefixValue = 0;
char *familyStr = NULL;
int family = AF_UNSPEC;
- char *address = NULL;
+ char *address = NULL, *peer = NULL;
if (!(address = virXMLPropString(node, "address"))) {
virReportError(VIR_ERR_XML_ERROR, "%s",
@@ -6146,6 +6146,13 @@ virDomainNetIPParseXML(xmlNodePtr node)
}
ip->prefix = prefixValue;
+ if ((peer = virXMLPropString(node, "peer")) != NULL &&
+ virSocketAddrParse(&ip->peer, peer, family) < 0) {
+ virReportError(VIR_ERR_INVALID_ARG,
+ _("Invalid peer '%s' in <ip>"), peer);
+ goto cleanup;
+ }
+
ret = ip;
ip = NULL;
@@ -6153,6 +6160,7 @@ virDomainNetIPParseXML(xmlNodePtr node)
VIR_FREE(prefixStr);
VIR_FREE(familyStr);
VIR_FREE(address);
+ VIR_FREE(peer);
VIR_FREE(ip);
return ret;
}
@@ -20254,6 +20262,12 @@ virDomainNetIPInfoFormat(virBufferPtr buf,
virBufferAsprintf(buf, " family='%s'", familyStr);
if (def->ips[i]->prefix)
virBufferAsprintf(buf, " prefix='%u'", def->ips[i]->prefix);
+ if (VIR_SOCKET_ADDR_VALID(&def->ips[i]->peer)) {
+ if (!(ipStr = virSocketAddrFormat(&def->ips[i]->peer)))
+ return -1;
+ virBufferAsprintf(buf, " peer='%s'", ipStr);
+ VIR_FREE(ipStr);
+ }
virBufferAddLit(buf, "/>\n");
}
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 0df5579..7ff966f 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -383,6 +383,7 @@ typedef enum {
VIR_DOMAIN_HOSTDEV_CAPS_TYPE_LAST
} virDomainHostdevCapsType;
+
Spurious change that can be dropped.
This change is ACK'able with the mentioned adjustments (whether you want
to repost stuff or not is your call).
You mean the extra line in domain_conf.h? :-P (since the other comment
is a non-issue).
Post by John Ferlan
John
Post by Laine Stump
typedef struct _virDomainHostdevCaps virDomainHostdevCaps;
typedef virDomainHostdevCaps *virDomainHostdevCapsPtr;
struct _virDomainHostdevCaps {
diff --git a/src/util/virnetdevip.h b/src/util/virnetdevip.h
index 66c5c00..3b9b3e0 100644
--- a/src/util/virnetdevip.h
+++ b/src/util/virnetdevip.h
@@ -26,8 +26,9 @@
# include "virsocketaddr.h"
typedef struct {
- virSocketAddr address; /* ipv4 or ipv6 address */
- unsigned int prefix; /* number of 1 bits in the net mask */
+ virSocketAddr address; /* ipv4 or ipv6 address */
+ virSocketAddr peer; /* ipv4 or ipv6 address of peer */
+ unsigned int prefix; /* number of 1 bits in the netmask */
} virNetDevIPAddr, *virNetDevIPAddrPtr;
typedef struct {
John Ferlan
2016-06-24 20:40:40 UTC
Permalink
Post by Laine Stump
Post by John Ferlan
Post by Laine Stump
The peer attribute is used to set the property of the same name in the
<interface type='ethernet'>
...
<ip family='ipv4' address='192.168.122.5'
prefix='32' peer='192.168.122.6'/>
...
</interface>
Note that this element is used to set the IP information on the
*guest* side interface, not the host side interface - that will be
supported in an upcoming patch.
(This is an updated *re*-commit of commit 690969af, which was
subsequently reverted in commit 1d14b13f).
---
docs/formatdomain.html.in | 40
+++++++++++++++++++++++++---------------
docs/schemas/domaincommon.rng | 5 +++++
src/conf/domain_conf.c | 16 +++++++++++++++-
src/conf/domain_conf.h | 1 +
src/util/virnetdevip.h | 5 +++--
5 files changed, 49 insertions(+), 18 deletions(-)
It seems an earlier comment I made about freeaddrinfo for the
corresponding getaddrinfo becomes even more important now... So
somewhere between there and this patch, I think you need to generate a
Free API for virNetDevIPAddrPtr
Then everywhere that current just does a VIR_FREE(ip) should call it...
Thus this change "gets it" for free - well mostly free, you'd have to
add the freeaddrinfo() for the 'peer' as well as the 'address'
Of course I could be wrong and I'm sure you'll let me know ;-)
Yep. We already talked about this in IRC. the virNetDevIPAddr doesn't
contain the info returned from getaddrinfo. virSocketAddrParseInternal
(that's who calls getaddrinfo) is called by two other functions, and
both of those functions copy out the important stuff from getaddrinfo,
then call freeaddrinfo. So everything is correct.
Post by John Ferlan
Post by Laine Stump
diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index f660aa6..2466df7 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -4967,6 +4967,7 @@ qemu-kvm -net nic,model=? /dev/null
+ <b>&lt;ip address='192.168.122.5' prefix='24'
<b>&lt;route family='ipv4' address='192.168.122.0'
<b>&lt;route family='ipv4' address='192.168.122.8'
@@ -4985,21 +4986,30 @@ qemu-kvm -net nic,model=? /dev/null
</pre>
<p>
- <span class="since">Since 1.2.12</span> the network devices and host devices
- with network capabilities can be provided zero or more IP addresses to set
- on the target device. Note that some hypervisors or network device types
- will simply ignore them or only use the first one. The
<code>family</code>
- attribute can be set to either <code>ipv4</code> or
<code>ipv6</code>, the
- <code>address</code> attribute holds the IP address. The <code>prefix</code>
- is not mandatory since some hypervisors do not handle it.
- </p>
-
- <p>
- <span class="since">Since 1.2.12</span> route elements can also be added
- to define the network routes to use for the network device. The attributes
- of this element are described in the documentation for the <code>route</code>
- element in <a
href="formatnetwork.html#elementsStaticroute">network definitions</a>.
- This is only used by the LXC driver.
+ <span class="since">Since 1.2.12</span> network devices and
+ hostdev devices with network capabilities can optionally be provided
+ one or more IP addresses to set on the network device in the
+ guest. Note that some hypervisors or network device types will
+ simply ignore them or only use the first one.
+ The <code>family</code> attribute can be set to
+ either <code>ipv4</code> or <code>ipv6</code>, and the
+ <code>address</code> attribute contains the IP address. The
+ optional <code>prefix</code> is the number of 1 bits in the
+ netmask, and will be automatically set if not specified - for
+ IPv4 the default prefix is determined according to the network
+ "class" (A, B, or C - see RFC870), and for IPv6 the default
+ prefix is 64. The optional <code>peer</code> attribute holds the
+ IP address of the other end of a point-to-point network
+ device <span class="since">(since 2.0.0)</span>.
+ </p>
+
+ <p>
+ <span class="since">Since 1.2.12</span> route elements can also be
+ added to define IP routes to add in the guest. The attributes of
+ this element are described in the documentation for
+ the <code>route</code> element
+ in <a href="formatnetwork.html#elementsStaticroute">network
+ definitions</a>. This is used by the LXC driver.
</p>
<h5><a name="elementVhostuser">vhost-user interface</a></h5>
diff --git a/docs/schemas/domaincommon.rng
b/docs/schemas/domaincommon.rng
index 563cb3c..2d12da9 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -2629,6 +2629,11 @@
<ref name="ipPrefix"/>
</attribute>
</optional>
+ <optional>
+ <attribute name="peer">
+ <ref name="ipAddr"/>
+ </attribute>
+ </optional>
<empty/>
</element>
</zeroOrMore>
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index df52ac9..ad2d983 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -6108,7 +6108,7 @@ virDomainNetIPParseXML(xmlNodePtr node)
unsigned int prefixValue = 0;
char *familyStr = NULL;
int family = AF_UNSPEC;
- char *address = NULL;
+ char *address = NULL, *peer = NULL;
if (!(address = virXMLPropString(node, "address"))) {
virReportError(VIR_ERR_XML_ERROR, "%s",
@@ -6146,6 +6146,13 @@ virDomainNetIPParseXML(xmlNodePtr node)
}
ip->prefix = prefixValue;
+ if ((peer = virXMLPropString(node, "peer")) != NULL &&
+ virSocketAddrParse(&ip->peer, peer, family) < 0) {
+ virReportError(VIR_ERR_INVALID_ARG,
+ _("Invalid peer '%s' in <ip>"), peer);
+ goto cleanup;
+ }
+
ret = ip;
ip = NULL;
@@ -6153,6 +6160,7 @@ virDomainNetIPParseXML(xmlNodePtr node)
VIR_FREE(prefixStr);
VIR_FREE(familyStr);
VIR_FREE(address);
+ VIR_FREE(peer);
VIR_FREE(ip);
return ret;
}
@@ -20254,6 +20262,12 @@ virDomainNetIPInfoFormat(virBufferPtr buf,
virBufferAsprintf(buf, " family='%s'", familyStr);
if (def->ips[i]->prefix)
virBufferAsprintf(buf, " prefix='%u'",
def->ips[i]->prefix);
+ if (VIR_SOCKET_ADDR_VALID(&def->ips[i]->peer)) {
+ if (!(ipStr = virSocketAddrFormat(&def->ips[i]->peer)))
+ return -1;
+ virBufferAsprintf(buf, " peer='%s'", ipStr);
+ VIR_FREE(ipStr);
+ }
virBufferAddLit(buf, "/>\n");
}
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 0df5579..7ff966f 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -383,6 +383,7 @@ typedef enum {
VIR_DOMAIN_HOSTDEV_CAPS_TYPE_LAST
} virDomainHostdevCapsType;
+
Spurious change that can be dropped.
This change is ACK'able with the mentioned adjustments (whether you want
to repost stuff or not is your call).
You mean the extra line in domain_conf.h? :-P (since the other comment
is a non-issue).
Yeah - I was probably thinking more about the Free thing, but since
you've pointed out that the freeaddrinfo is done - it's a moot point.

John
Post by Laine Stump
Post by John Ferlan
John
Laine Stump
2016-06-22 17:37:12 UTC
Permalink
This patch splits virnetdev.[ch] into multiple files, with the new
virnetdevip.[ch] containing all the functions related to setting and
retrieving IP-related info for a device (both addresses and routes).
---
po/POTFILES.in | 1 +
src/Makefile.am | 1 +
src/libvirt_private.syms | 13 +-
src/lxc/lxc_container.c | 14 +-
src/network/bridge_driver.c | 15 +-
src/util/virnetdev.c | 711 ----------------------------------------
src/util/virnetdevip.c | 778 ++++++++++++++++++++++++++++++++++++++++++++
src/util/virnetdevip.h | 50 +++
8 files changed, 853 insertions(+), 730 deletions(-)
create mode 100644 src/util/virnetdevip.c
create mode 100644 src/util/virnetdevip.h

diff --git a/po/POTFILES.in b/po/POTFILES.in
index 822cfbc..f27d448 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -213,6 +213,7 @@ src/util/virlog.c
src/util/virnetdev.c
src/util/virnetdevbandwidth.c
src/util/virnetdevbridge.c
+src/util/virnetdevip.c
src/util/virnetdevmacvlan.c
src/util/virnetdevmidonet.c
src/util/virnetdevopenvswitch.c
diff --git a/src/Makefile.am b/src/Makefile.am
index a14cb3f..f56dcc2 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -138,6 +138,7 @@ UTIL_SOURCES = \
util/virnetdev.h util/virnetdev.c \
util/virnetdevbandwidth.h util/virnetdevbandwidth.c \
util/virnetdevbridge.h util/virnetdevbridge.c \
+ util/virnetdevip.h util/virnetdevip.c \
util/virnetdevmacvlan.c util/virnetdevmacvlan.h \
util/virnetdevmidonet.h util/virnetdevmidonet.c \
util/virnetdevopenvswitch.h util/virnetdevopenvswitch.c \
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 807ffce..bd7b730 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1850,15 +1850,12 @@ virMacAddrSetRaw;

# util/virnetdev.h
virNetDevAddMulti;
-virNetDevAddRoute;
-virNetDevClearIPAddress;
virNetDevDelMulti;
virNetDevExists;
virNetDevFeatureTypeFromString;
virNetDevFeatureTypeToString;
virNetDevGetFeatures;
virNetDevGetIndex;
-virNetDevGetIPAddress;
virNetDevGetLinkInfo;
virNetDevGetMAC;
virNetDevGetMTU;
@@ -1884,7 +1881,6 @@ virNetDevRxFilterFree;
virNetDevRxFilterModeTypeFromString;
virNetDevRxFilterModeTypeToString;
virNetDevRxFilterNew;
-virNetDevSetIPAddress;
virNetDevSetMAC;
virNetDevSetMTU;
virNetDevSetMTUFromDevice;
@@ -1897,7 +1893,6 @@ virNetDevSetRcvMulti;
virNetDevSetupControl;
virNetDevSysfsFile;
virNetDevValidateConfig;
-virNetDevWaitDadFinish;


# util/virnetdevbandwidth.h
@@ -1931,6 +1926,14 @@ virNetDevBridgeSetSTPDelay;
virNetDevBridgeSetVlanFiltering;


+# util/virnetdevip.h
+virNetDevIPAddrAdd;
+virNetDevIPAddrDel;
+virNetDevIPAddrGet;
+virNetDevIPRouteAdd;
+virNetDevIPWaitDadFinish;
+
+
# util/virnetdevmacvlan.h
virNetDevMacVLanCreate;
virNetDevMacVLanCreateWithVPortProfile;
diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c
index 304aa86..a95472c 100644
--- a/src/lxc/lxc_container.c
+++ b/src/lxc/lxc_container.c
@@ -66,7 +66,7 @@
#include "virfile.h"
#include "virusb.h"
#include "vircommand.h"
-#include "virnetdev.h"
+#include "virnetdevip.h"
#include "virprocess.h"
#include "virstring.h"

@@ -527,7 +527,7 @@ static int lxcContainerRenameAndEnableInterfaces(virDomainDefPtr vmDef,

VIR_DEBUG("Adding IP address '%s/%d' to '%s'",
ipStr, prefix, newname);
- if (virNetDevSetIPAddress(newname, &ip->address, NULL, prefix) < 0) {
+ if (virNetDevIPAddrAdd(newname, &ip->address, NULL, prefix) < 0) {
virReportError(VIR_ERR_SYSTEM_ERROR,
_("Failed to set IP address '%s' on %s"),
ipStr, newname);
@@ -548,11 +548,11 @@ static int lxcContainerRenameAndEnableInterfaces(virDomainDefPtr vmDef,
for (j = 0; j < netDef->nroutes; j++) {
virNetworkRouteDefPtr route = netDef->routes[j];

- if (virNetDevAddRoute(newname,
- virNetworkRouteDefGetAddress(route),
- virNetworkRouteDefGetPrefix(route),
- virNetworkRouteDefGetGateway(route),
- virNetworkRouteDefGetMetric(route)) < 0) {
+ if (virNetDevIPRouteAdd(newname,
+ virNetworkRouteDefGetAddress(route),
+ virNetworkRouteDefGetPrefix(route),
+ virNetworkRouteDefGetGateway(route),
+ virNetworkRouteDefGetMetric(route)) < 0) {
goto error_out;
}
VIR_FREE(toStr);
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index 130b77d..135f7bd 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -62,10 +62,11 @@
#include "virdnsmasq.h"
#include "configmake.h"
#include "virnetdev.h"
-#include "virpci.h"
+#include "virnetdevip.h"
#include "virnetdevbridge.h"
#include "virnetdevtap.h"
#include "virnetdevvportprofile.h"
+#include "virpci.h"
#include "virdbus.h"
#include "virfile.h"
#include "virstring.h"
@@ -1986,8 +1987,8 @@ networkAddAddrToBridge(virNetworkObjPtr network,
return -1;
}

- if (virNetDevSetIPAddress(network->def->bridge,
- &ipdef->address, NULL, prefix) < 0)
+ if (virNetDevIPAddrAdd(network->def->bridge,
+ &ipdef->address, NULL, prefix) < 0)
return -1;

return 0;
@@ -2034,8 +2035,8 @@ networkAddRouteToBridge(virNetworkObjPtr network,
return -1;
}

- if (virNetDevAddRoute(network->def->bridge, addr,
- prefix, gateway, metric) < 0) {
+ if (virNetDevIPRouteAdd(network->def->bridge, addr,
+ prefix, gateway, metric) < 0) {
return -1;
}
return 0;
@@ -2058,7 +2059,7 @@ networkWaitDadFinish(virNetworkObjPtr network)
goto cleanup;
}

- ret = (naddrs == 0) ? 0 : virNetDevWaitDadFinish(addrs, naddrs);
+ ret = (naddrs == 0) ? 0 : virNetDevIPWaitDadFinish(addrs, naddrs);

cleanup:
VIR_FREE(addrs);
@@ -4769,7 +4770,7 @@ networkGetNetworkAddress(const char *netname, char **netaddr)
}

if (dev_name) {
- if (virNetDevGetIPAddress(dev_name, &addr) < 0)
+ if (virNetDevIPAddrGet(dev_name, &addr) < 0)
goto cleanup;
addrptr = &addr;
}
diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c
index fb71c7b..729c121 100644
--- a/src/util/virnetdev.c
+++ b/src/util/virnetdev.c
@@ -34,10 +34,6 @@
#include "virstring.h"
#include "virutil.h"

-#if HAVE_GETIFADDRS
-# include <ifaddrs.h>
-#endif
-
#include <sys/ioctl.h>
#include <net/if.h>
#include <fcntl.h>
@@ -97,7 +93,6 @@ VIR_LOG_INIT("util.netdev");
# define FEATURE_BIT_IS_SET(blocks, index, field) \
(FEATURE_WORD(blocks, index, field) & FEATURE_FIELD_FLAG(index))
#endif
-#define VIR_DAD_WAIT_TIMEOUT 20 /* seconds */

typedef enum {
VIR_MCAST_TYPE_INDEX_TOKEN,
@@ -1012,712 +1007,6 @@ int virNetDevGetVLanID(const char *ifname ATTRIBUTE_UNUSED,
#endif /* ! SIOCGIFVLAN */


-#if defined(__linux__) && defined(HAVE_LIBNL)
-
-static int
-virNetDevGetIPAddressBinary(virSocketAddr *addr, void **data, size_t *len)
-{
- if (!addr)
- return -1;
-
- switch (VIR_SOCKET_ADDR_FAMILY(addr)) {
- case AF_INET:
- *data = &addr->data.inet4.sin_addr;
- *len = sizeof(struct in_addr);
- break;
- case AF_INET6:
- *data = &addr->data.inet6.sin6_addr;
- *len = sizeof(struct in6_addr);
- break;
- default:
- return -1;
- }
- return 0;
-}
-
-static struct nl_msg *
-virNetDevCreateNetlinkAddressMessage(int messageType,
- const char *ifname,
- virSocketAddr *addr,
- unsigned int prefix,
- virSocketAddr *broadcast,
- virSocketAddr *peer)
-{
- struct nl_msg *nlmsg = NULL;
- struct ifaddrmsg ifa;
- unsigned int ifindex;
- void *addrData = NULL;
- void *peerData = NULL;
- void *broadcastData = NULL;
- size_t addrDataLen;
-
- if (virNetDevGetIPAddressBinary(addr, &addrData, &addrDataLen) < 0)
- return NULL;
-
- if (peer && VIR_SOCKET_ADDR_VALID(peer)) {
- if (virNetDevGetIPAddressBinary(peer, &peerData, &addrDataLen) < 0)
- return NULL;
- } else if (broadcast) {
- if (virNetDevGetIPAddressBinary(broadcast, &broadcastData,
- &addrDataLen) < 0)
- return NULL;
- }
-
- /* Get the interface index */
- if ((ifindex = if_nametoindex(ifname)) == 0)
- return NULL;
-
- if (!(nlmsg = nlmsg_alloc_simple(messageType,
- NLM_F_REQUEST | NLM_F_CREATE | NLM_F_EXCL))) {
- virReportOOMError();
- return NULL;
- }
-
- memset(&ifa, 0, sizeof(ifa));
-
- ifa.ifa_prefixlen = prefix;
- ifa.ifa_family = VIR_SOCKET_ADDR_FAMILY(addr);
- ifa.ifa_index = ifindex;
- ifa.ifa_scope = 0;
-
- if (nlmsg_append(nlmsg, &ifa, sizeof(ifa), NLMSG_ALIGNTO) < 0)
- goto buffer_too_small;
-
- if (nla_put(nlmsg, IFA_LOCAL, addrDataLen, addrData) < 0)
- goto buffer_too_small;
-
- if (peerData) {
- if (nla_put(nlmsg, IFA_ADDRESS, addrDataLen, peerData) < 0)
- goto buffer_too_small;
- }
-
- if (broadcastData) {
- if (nla_put(nlmsg, IFA_BROADCAST, addrDataLen, broadcastData) < 0)
- goto buffer_too_small;
- }
-
- return nlmsg;
-
- buffer_too_small:
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("allocated netlink buffer is too small"));
- nlmsg_free(nlmsg);
- return NULL;
-}
-
-/**
- * virNetDevSetIPAddress:
- * @ifname: the interface name
- * @addr: the IP address (IPv4 or IPv6)
- * @peer: The IP address of peer (IPv4 or IPv6)
- * @prefix: number of 1 bits in the netmask
- *
- * Add an IP address to an interface. This function *does not* remove
- * any previously added IP addresses - that must be done separately with
- * brDelInetAddress.
- *
- * Returns 0 in case of success or -1 in case of error.
- */
-int virNetDevSetIPAddress(const char *ifname,
- virSocketAddr *addr,
- virSocketAddr *peer,
- unsigned int prefix)
-{
- virSocketAddr *broadcast = NULL;
- int ret = -1;
- struct nl_msg *nlmsg = NULL;
- struct nlmsghdr *resp = NULL;
- unsigned int recvbuflen;
-
- /* The caller needs to provide a correct address */
- if (VIR_SOCKET_ADDR_FAMILY(addr) == AF_INET &&
- !(peer && VIR_SOCKET_ADDR_VALID(peer))) {
- /* compute a broadcast address if this is IPv4 */
- if (VIR_ALLOC(broadcast) < 0)
- return -1;
-
- if (virSocketAddrBroadcastByPrefix(addr, prefix, broadcast) < 0)
- goto cleanup;
- }
-
- if (!(nlmsg = virNetDevCreateNetlinkAddressMessage(RTM_NEWADDR, ifname,
- addr, prefix,
- broadcast, peer)))
- goto cleanup;
-
- if (virNetlinkCommand(nlmsg, &resp, &recvbuflen, 0, 0,
- NETLINK_ROUTE, 0) < 0)
- goto cleanup;
-
-
- if (virNetlinkGetErrorCode(resp, recvbuflen) < 0) {
- virReportError(VIR_ERR_SYSTEM_ERROR,
- _("Error adding IP address to %s"), ifname);
- goto cleanup;
- }
-
- ret = 0;
- cleanup:
- nlmsg_free(nlmsg);
- VIR_FREE(resp);
- VIR_FREE(broadcast);
- return ret;
-}
-
-/**
- * virNetDevAddRoute:
- * @ifname: the interface name
- * @addr: the IP network address (IPv4 or IPv6)
- * @prefix: number of 1 bits in the netmask
- * @gateway: via address for route (same as @addr)
- *
- * Add a route for a network IP address to an interface. This function
- * *does not* remove any previously added IP static routes.
- *
- * Returns 0 in case of success or -1 in case of error.
- */
-int
-virNetDevAddRoute(const char *ifname,
- virSocketAddrPtr addr,
- unsigned int prefix,
- virSocketAddrPtr gateway,
- unsigned int metric)
-{
- int ret = -1;
- struct nl_msg *nlmsg = NULL;
- struct nlmsghdr *resp = NULL;
- unsigned int recvbuflen;
- unsigned int ifindex;
- struct rtmsg rtmsg;
- void *gatewayData = NULL;
- void *addrData = NULL;
- size_t addrDataLen;
- int errCode;
- virSocketAddr defaultAddr;
- virSocketAddrPtr actualAddr;
- char *toStr = NULL;
- char *viaStr = NULL;
-
- actualAddr = addr;
-
- /* If we have no valid network address, then use the default one */
- if (!addr || !VIR_SOCKET_ADDR_VALID(addr)) {
- VIR_DEBUG("computing default address");
- int family = VIR_SOCKET_ADDR_FAMILY(gateway);
- if (family == AF_INET) {
- if (virSocketAddrParseIPv4(&defaultAddr, VIR_SOCKET_ADDR_IPV4_ALL) < 0)
- goto cleanup;
- } else {
- if (virSocketAddrParseIPv6(&defaultAddr, VIR_SOCKET_ADDR_IPV6_ALL) < 0)
- goto cleanup;
- }
-
- actualAddr = &defaultAddr;
- }
-
- toStr = virSocketAddrFormat(actualAddr);
- viaStr = virSocketAddrFormat(gateway);
- VIR_DEBUG("Adding route %s/%d via %s", toStr, prefix, viaStr);
-
- if (virNetDevGetIPAddressBinary(actualAddr, &addrData, &addrDataLen) < 0 ||
- virNetDevGetIPAddressBinary(gateway, &gatewayData, &addrDataLen) < 0)
- goto cleanup;
-
- /* Get the interface index */
- if ((ifindex = if_nametoindex(ifname)) == 0)
- goto cleanup;
-
- if (!(nlmsg = nlmsg_alloc_simple(RTM_NEWROUTE,
- NLM_F_REQUEST | NLM_F_CREATE |
- NLM_F_EXCL))) {
- virReportOOMError();
- goto cleanup;
- }
-
- memset(&rtmsg, 0, sizeof(rtmsg));
-
- rtmsg.rtm_family = VIR_SOCKET_ADDR_FAMILY(gateway);
- rtmsg.rtm_table = RT_TABLE_MAIN;
- rtmsg.rtm_scope = RT_SCOPE_UNIVERSE;
- rtmsg.rtm_protocol = RTPROT_BOOT;
- rtmsg.rtm_type = RTN_UNICAST;
- rtmsg.rtm_dst_len = prefix;
-
- if (nlmsg_append(nlmsg, &rtmsg, sizeof(rtmsg), NLMSG_ALIGNTO) < 0)
- goto buffer_too_small;
-
- if (prefix > 0 && nla_put(nlmsg, RTA_DST, addrDataLen, addrData) < 0)
- goto buffer_too_small;
-
- if (nla_put(nlmsg, RTA_GATEWAY, addrDataLen, gatewayData) < 0)
- goto buffer_too_small;
-
- if (nla_put_u32(nlmsg, RTA_OIF, ifindex) < 0)
- goto buffer_too_small;
-
- if (metric > 0 && nla_put_u32(nlmsg, RTA_PRIORITY, metric) < 0)
- goto buffer_too_small;
-
- if (virNetlinkCommand(nlmsg, &resp, &recvbuflen, 0, 0,
- NETLINK_ROUTE, 0) < 0)
- goto cleanup;
-
- if ((errCode = virNetlinkGetErrorCode(resp, recvbuflen)) < 0) {
- virReportSystemError(errCode, _("Error adding route to %s"), ifname);
- goto cleanup;
- }
-
- ret = 0;
- cleanup:
- VIR_FREE(toStr);
- VIR_FREE(viaStr);
- nlmsg_free(nlmsg);
- return ret;
-
- buffer_too_small:
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("allocated netlink buffer is too small"));
- goto cleanup;
-}
-
-/**
- * virNetDevClearIPAddress:
- * @ifname: the interface name
- * @addr: the IP address (IPv4 or IPv6)
- * @prefix: number of 1 bits in the netmask
- *
- * Delete an IP address from an interface.
- *
- * Returns 0 in case of success or -1 in case of error.
- */
-int virNetDevClearIPAddress(const char *ifname,
- virSocketAddr *addr,
- unsigned int prefix)
-{
- int ret = -1;
- struct nl_msg *nlmsg = NULL;
- struct nlmsghdr *resp = NULL;
- unsigned int recvbuflen;
-
- if (!(nlmsg = virNetDevCreateNetlinkAddressMessage(RTM_DELADDR, ifname,
- addr, prefix,
- NULL, NULL)))
- goto cleanup;
-
- if (virNetlinkCommand(nlmsg, &resp, &recvbuflen, 0, 0,
- NETLINK_ROUTE, 0) < 0)
- goto cleanup;
-
- if (virNetlinkGetErrorCode(resp, recvbuflen) < 0) {
- virReportError(VIR_ERR_SYSTEM_ERROR,
- _("Error removing IP address from %s"), ifname);
- goto cleanup;
- }
-
- ret = 0;
- cleanup:
- nlmsg_free(nlmsg);
- VIR_FREE(resp);
- return ret;
-}
-
-/* return true if there is a known address with 'tentative' flag set */
-static bool
-virNetDevParseDadStatus(struct nlmsghdr *nlh, int len,
- virSocketAddrPtr *addrs, size_t count)
-{
- struct ifaddrmsg *ifaddrmsg_ptr;
- unsigned int ifaddrmsg_len;
- struct rtattr *rtattr_ptr;
- size_t i;
- struct in6_addr *addr;
-
- VIR_WARNINGS_NO_CAST_ALIGN
- for (; NLMSG_OK(nlh, len); nlh = NLMSG_NEXT(nlh, len)) {
- VIR_WARNINGS_RESET
- if (NLMSG_PAYLOAD(nlh, 0) < sizeof(struct ifaddrmsg)) {
- /* Message without payload is the last one. */
- break;
- }
-
- ifaddrmsg_ptr = (struct ifaddrmsg *)NLMSG_DATA(nlh);
- if (!(ifaddrmsg_ptr->ifa_flags & IFA_F_TENTATIVE)) {
- /* Not tentative: we are not interested in this entry. */
- continue;
- }
-
- ifaddrmsg_len = IFA_PAYLOAD(nlh);
- VIR_WARNINGS_NO_CAST_ALIGN
- rtattr_ptr = (struct rtattr *) IFA_RTA(ifaddrmsg_ptr);
- for (; RTA_OK(rtattr_ptr, ifaddrmsg_len);
- rtattr_ptr = RTA_NEXT(rtattr_ptr, ifaddrmsg_len)) {
- VIR_WARNINGS_RESET
- if (RTA_PAYLOAD(rtattr_ptr) != sizeof(struct in6_addr)) {
- /* No address: ignore. */
- continue;
- }
-
- /* We check only known addresses. */
- for (i = 0; i < count; i++) {
- addr = &addrs[i]->data.inet6.sin6_addr;
- if (!memcmp(addr, RTA_DATA(rtattr_ptr),
- sizeof(struct in6_addr))) {
- /* We found matching tentative address. */
- return true;
- }
- }
- }
- }
- return false;
-}
-
-/* return after DAD finishes for all known IPv6 addresses or an error */
-int
-virNetDevWaitDadFinish(virSocketAddrPtr *addrs, size_t count)
-{
- struct nl_msg *nlmsg = NULL;
- struct ifaddrmsg ifa;
- struct nlmsghdr *resp = NULL;
- unsigned int recvbuflen;
- int ret = -1;
- bool dad = true;
- time_t max_time = time(NULL) + VIR_DAD_WAIT_TIMEOUT;
-
- if (!(nlmsg = nlmsg_alloc_simple(RTM_GETADDR,
- NLM_F_REQUEST | NLM_F_DUMP))) {
- virReportOOMError();
- return -1;
- }
-
- memset(&ifa, 0, sizeof(ifa));
- /* DAD is for IPv6 adresses only. */
- ifa.ifa_family = AF_INET6;
- if (nlmsg_append(nlmsg, &ifa, sizeof(ifa), NLMSG_ALIGNTO) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("allocated netlink buffer is too small"));
- goto cleanup;
- }
-
- /* Periodically query netlink until DAD finishes on all known addresses. */
- while (dad && time(NULL) < max_time) {
- if (virNetlinkCommand(nlmsg, &resp, &recvbuflen, 0, 0,
- NETLINK_ROUTE, 0) < 0)
- goto cleanup;
-
- if (virNetlinkGetErrorCode(resp, recvbuflen) < 0) {
- virReportError(VIR_ERR_SYSTEM_ERROR, "%s",
- _("error reading DAD state information"));
- goto cleanup;
- }
-
- /* Parse response. */
- dad = virNetDevParseDadStatus(resp, recvbuflen, addrs, count);
- if (dad)
- usleep(1000 * 10);
-
- VIR_FREE(resp);
- }
- /* Check timeout. */
- if (dad) {
- virReportError(VIR_ERR_SYSTEM_ERROR,
- _("Duplicate Address Detection "
- "not finished in %d seconds"), VIR_DAD_WAIT_TIMEOUT);
- } else {
- ret = 0;
- }
-
- cleanup:
- VIR_FREE(resp);
- nlmsg_free(nlmsg);
- return ret;
-}
-
-#else /* defined(__linux__) && defined(HAVE_LIBNL) */
-
-int virNetDevSetIPAddress(const char *ifname,
- virSocketAddr *addr,
- virSocketAddr *peer,
- unsigned int prefix)
-{
- virCommandPtr cmd = NULL;
- char *addrstr = NULL, *bcaststr = NULL, *peerstr = NULL;
- virSocketAddr broadcast;
- int ret = -1;
-
- if (!(addrstr = virSocketAddrFormat(addr)))
- goto cleanup;
-
- if (peer && VIR_SOCKET_ADDR_VALID(peer) && !(peerstr = virSocketAddrFormat(peer)))
- goto cleanup;
-
- /* format up a broadcast address if this is IPv4 */
- if (!peerstr && ((VIR_SOCKET_ADDR_IS_FAMILY(addr, AF_INET)) &&
- ((virSocketAddrBroadcastByPrefix(addr, prefix, &broadcast) < 0) ||
- !(bcaststr = virSocketAddrFormat(&broadcast))))) {
- goto cleanup;
- }
-
-# ifdef IFCONFIG_PATH
- cmd = virCommandNew(IFCONFIG_PATH);
- virCommandAddArg(cmd, ifname);
- if (VIR_SOCKET_ADDR_IS_FAMILY(addr, AF_INET6))
- virCommandAddArg(cmd, "inet6");
- else
- virCommandAddArg(cmd, "inet");
- virCommandAddArgFormat(cmd, "%s/%u", addrstr, prefix);
- if (peerstr)
- virCommandAddArgList(cmd, "pointopoint", peerstr, NULL);
- if (bcaststr)
- virCommandAddArgList(cmd, "broadcast", bcaststr, NULL);
- virCommandAddArg(cmd, "alias");
-# else
- cmd = virCommandNew(IP_PATH);
- virCommandAddArgList(cmd, "addr", "add", NULL);
- virCommandAddArgFormat(cmd, "%s/%u", addrstr, prefix);
- if (peerstr)
- virCommandAddArgList(cmd, "peer", peerstr, NULL);
- if (bcaststr)
- virCommandAddArgList(cmd, "broadcast", bcaststr, NULL);
- virCommandAddArgList(cmd, "dev", ifname, NULL);
-# endif
-
- if (virCommandRun(cmd, NULL) < 0)
- goto cleanup;
-
- ret = 0;
- cleanup:
- VIR_FREE(addrstr);
- VIR_FREE(bcaststr);
- VIR_FREE(peerstr);
- virCommandFree(cmd);
- return ret;
-}
-
-int
-virNetDevAddRoute(const char *ifname,
- virSocketAddrPtr addr,
- unsigned int prefix,
- virSocketAddrPtr gateway,
- unsigned int metric)
-{
- virCommandPtr cmd = NULL;
- char *addrstr = NULL, *gatewaystr = NULL;
- int ret = -1;
-
- if (!(addrstr = virSocketAddrFormat(addr)))
- goto cleanup;
- if (!(gatewaystr = virSocketAddrFormat(gateway)))
- goto cleanup;
- cmd = virCommandNew(IP_PATH);
- virCommandAddArgList(cmd, "route", "add", NULL);
- virCommandAddArgFormat(cmd, "%s/%u", addrstr, prefix);
- virCommandAddArgList(cmd, "via", gatewaystr, "dev", ifname,
- "proto", "static", "metric", NULL);
- virCommandAddArgFormat(cmd, "%u", metric);
-
- if (virCommandRun(cmd, NULL) < 0)
- goto cleanup;
-
- ret = 0;
- cleanup:
- VIR_FREE(addrstr);
- VIR_FREE(gatewaystr);
- virCommandFree(cmd);
- return ret;
-}
-
-int virNetDevClearIPAddress(const char *ifname,
- virSocketAddr *addr,
- unsigned int prefix)
-{
- virCommandPtr cmd = NULL;
- char *addrstr;
- int ret = -1;
-
- if (!(addrstr = virSocketAddrFormat(addr)))
- goto cleanup;
-# ifdef IFCONFIG_PATH
- cmd = virCommandNew(IFCONFIG_PATH);
- virCommandAddArg(cmd, ifname);
- if (VIR_SOCKET_ADDR_IS_FAMILY(addr, AF_INET6))
- virCommandAddArg(cmd, "inet6");
- else
- virCommandAddArg(cmd, "inet");
- virCommandAddArgFormat(cmd, "%s/%u", addrstr, prefix);
- virCommandAddArg(cmd, "-alias");
-# else
- cmd = virCommandNew(IP_PATH);
- virCommandAddArgList(cmd, "addr", "del", NULL);
- virCommandAddArgFormat(cmd, "%s/%u", addrstr, prefix);
- virCommandAddArgList(cmd, "dev", ifname, NULL);
-# endif
-
- if (virCommandRun(cmd, NULL) < 0)
- goto cleanup;
-
- ret = 0;
- cleanup:
- VIR_FREE(addrstr);
- virCommandFree(cmd);
- return ret;
-}
-
-/* return after DAD finishes for all known IPv6 addresses or an error */
-int
-virNetDevWaitDadFinish(virSocketAddrPtr *addrs ATTRIBUTE_UNUSED,
- size_t count ATTRIBUTE_UNUSED)
-{
- virReportSystemError(ENOSYS, "%s",
- _("Unable to wait for IPv6 DAD on this platform"));
- return -1;
-}
-
-#endif /* defined(__linux__) && defined(HAVE_LIBNL) */
-
-/**
- * virNetDevGetIPv4AddressIoctl:
- * @ifname: name of the interface whose IP address we want
- * @addr: filled with the IPv4 address
- *
- * This function gets the IPv4 address for the interface @ifname
- * and stores it in @addr
- *
- * Returns 0 on success, -errno on failure.
- */
-#if defined(SIOCGIFADDR) && defined(HAVE_STRUCT_IFREQ)
-static int
-virNetDevGetIPv4AddressIoctl(const char *ifname,
- virSocketAddrPtr addr)
-{
- int fd = -1;
- int ret = -1;
- struct ifreq ifr;
-
- if ((fd = virNetDevSetupControl(ifname, &ifr)) < 0)
- return -1;
-
- if (ioctl(fd, SIOCGIFADDR, (char *)&ifr) < 0) {
- virReportSystemError(errno,
- _("Unable to get IPv4 address for interface %s via ioctl"),
- ifname);
- goto cleanup;
- }
-
- addr->data.stor.ss_family = AF_INET;
- addr->len = sizeof(addr->data.inet4);
- memcpy(&addr->data.inet4, &ifr.ifr_addr, addr->len);
- ret = 0;
-
- cleanup:
- VIR_FORCE_CLOSE(fd);
- return ret;
-}
-
-#else /* ! SIOCGIFADDR */
-
-static int
-virNetDevGetIPv4AddressIoctl(const char *ifname ATTRIBUTE_UNUSED,
- virSocketAddrPtr addr ATTRIBUTE_UNUSED)
-{
- return -2;
-}
-
-#endif /* ! SIOCGIFADDR */
-
-/**
- * virNetDevGetifaddrsAddress:
- * @ifname: name of the interface whose IP address we want
- * @addr: filled with the IP address
- *
- * This function gets the IP address for the interface @ifname
- * and stores it in @addr
- *
- * Returns 0 on success, -1 on failure, -2 on unsupported.
- */
-#if HAVE_GETIFADDRS
-static int
-virNetDevGetifaddrsAddress(const char *ifname,
- virSocketAddrPtr addr)
-{
- struct ifaddrs *ifap, *ifa;
- int ret = -1;
-
- if (getifaddrs(&ifap) < 0) {
- virReportSystemError(errno,
- _("Could not get interface list for '%s'"),
- ifname);
- return -1;
- }
-
- for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
- int family = ifa->ifa_addr->sa_family;
-
- if (STRNEQ_NULLABLE(ifa->ifa_name, ifname))
- continue;
- if (family != AF_INET6 && family != AF_INET)
- continue;
-
- if (family == AF_INET6) {
- addr->len = sizeof(addr->data.inet6);
- memcpy(&addr->data.inet6, ifa->ifa_addr, addr->len);
- } else {
- addr->len = sizeof(addr->data.inet4);
- memcpy(&addr->data.inet4, ifa->ifa_addr, addr->len);
- }
- addr->data.stor.ss_family = family;
- ret = 0;
- goto cleanup;
- }
-
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("no IP address found for interface '%s'"),
- ifname);
- cleanup:
- freeifaddrs(ifap);
- return ret;
-}
-
-#else /* ! HAVE_GETIFADDRS */
-
-static int
-virNetDevGetifaddrsAddress(const char *ifname ATTRIBUTE_UNUSED,
- virSocketAddrPtr addr ATTRIBUTE_UNUSED)
-{
- return -2;
-}
-
-#endif
-
-/**
- * virNetDevGetIPAddress:
- * @ifname: name of the interface whose IP address we want
- * @addr: filled with the IPv4 address
- *
- * This function gets the IPv4 address for the interface @ifname
- * and stores it in @addr
- *
- * Returns 0 on success, -errno on failure.
- */
-int
-virNetDevGetIPAddress(const char *ifname,
- virSocketAddrPtr addr)
-{
- int ret;
-
- memset(addr, 0, sizeof(*addr));
- addr->data.stor.ss_family = AF_UNSPEC;
-
- if ((ret = virNetDevGetifaddrsAddress(ifname, addr)) != -2)
- return ret;
-
- if ((ret = virNetDevGetIPv4AddressIoctl(ifname, addr)) != -2)
- return ret;
-
- virReportSystemError(ENOSYS, "%s",
- _("Unable to get IP address on this platform"));
- return -1;
-}
-
/**
* virNetDevValidateConfig:
* @ifname: Name of the interface
diff --git a/src/util/virnetdevip.c b/src/util/virnetdevip.c
new file mode 100644
index 0000000..044f2bc
--- /dev/null
+++ b/src/util/virnetdevip.c
@@ -0,0 +1,778 @@
+/*
+ * Copyright (C) 2007-2016 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Mark McLoughlin <***@redhat.com>
+ * Daniel P. Berrange <***@redhat.com>
+ */
+
+#include <config.h>
+
+#include "virnetdevip.h"
+#include "virnetdev.h"
+#include "virnetlink.h"
+#include "virfile.h"
+#include "virerror.h"
+#include "viralloc.h"
+#include "virlog.h"
+#include "virstring.h"
+#include "virutil.h"
+
+#if HAVE_GETIFADDRS
+# include <ifaddrs.h>
+#endif
+
+#include <sys/ioctl.h>
+#include <net/if.h>
+#include <fcntl.h>
+
+#ifdef __linux__
+# include <linux/sockios.h>
+# include <linux/if_vlan.h>
+# define VIR_NETDEV_FAMILY AF_PACKET
+#elif defined(HAVE_STRUCT_IFREQ) && defined(AF_LOCAL)
+# define VIR_NETDEV_FAMILY AF_LOCAL
+#else
+# undef HAVE_STRUCT_IFREQ
+#endif
+
+#define VIR_DAD_WAIT_TIMEOUT 20 /* seconds */
+
+#define VIR_FROM_THIS VIR_FROM_NONE
+
+VIR_LOG_INIT("util.netdevip");
+
+#if defined(__linux__) && defined(HAVE_LIBNL)
+
+static int
+virNetDevGetIPAddressBinary(virSocketAddr *addr, void **data, size_t *len)
+{
+ if (!addr)
+ return -1;
+
+ switch (VIR_SOCKET_ADDR_FAMILY(addr)) {
+ case AF_INET:
+ *data = &addr->data.inet4.sin_addr;
+ *len = sizeof(struct in_addr);
+ break;
+ case AF_INET6:
+ *data = &addr->data.inet6.sin6_addr;
+ *len = sizeof(struct in6_addr);
+ break;
+ default:
+ return -1;
+ }
+ return 0;
+}
+
+static struct nl_msg *
+virNetDevCreateNetlinkAddressMessage(int messageType,
+ const char *ifname,
+ virSocketAddr *addr,
+ unsigned int prefix,
+ virSocketAddr *broadcast,
+ virSocketAddr *peer)
+{
+ struct nl_msg *nlmsg = NULL;
+ struct ifaddrmsg ifa;
+ unsigned int ifindex;
+ void *addrData = NULL;
+ void *peerData = NULL;
+ void *broadcastData = NULL;
+ size_t addrDataLen;
+
+ if (virNetDevGetIPAddressBinary(addr, &addrData, &addrDataLen) < 0)
+ return NULL;
+
+ if (peer && VIR_SOCKET_ADDR_VALID(peer)) {
+ if (virNetDevGetIPAddressBinary(peer, &peerData, &addrDataLen) < 0)
+ return NULL;
+ } else if (broadcast) {
+ if (virNetDevGetIPAddressBinary(broadcast, &broadcastData,
+ &addrDataLen) < 0)
+ return NULL;
+ }
+
+ /* Get the interface index */
+ if ((ifindex = if_nametoindex(ifname)) == 0)
+ return NULL;
+
+ if (!(nlmsg = nlmsg_alloc_simple(messageType,
+ NLM_F_REQUEST | NLM_F_CREATE | NLM_F_EXCL))) {
+ virReportOOMError();
+ return NULL;
+ }
+
+ memset(&ifa, 0, sizeof(ifa));
+
+ ifa.ifa_prefixlen = prefix;
+ ifa.ifa_family = VIR_SOCKET_ADDR_FAMILY(addr);
+ ifa.ifa_index = ifindex;
+ ifa.ifa_scope = 0;
+
+ if (nlmsg_append(nlmsg, &ifa, sizeof(ifa), NLMSG_ALIGNTO) < 0)
+ goto buffer_too_small;
+
+ if (nla_put(nlmsg, IFA_LOCAL, addrDataLen, addrData) < 0)
+ goto buffer_too_small;
+
+ if (peerData) {
+ if (nla_put(nlmsg, IFA_ADDRESS, addrDataLen, peerData) < 0)
+ goto buffer_too_small;
+ }
+
+ if (broadcastData) {
+ if (nla_put(nlmsg, IFA_BROADCAST, addrDataLen, broadcastData) < 0)
+ goto buffer_too_small;
+ }
+
+ return nlmsg;
+
+ buffer_too_small:
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("allocated netlink buffer is too small"));
+ nlmsg_free(nlmsg);
+ return NULL;
+}
+
+/**
+ * virNetDevIPAddrAdd:
+ * @ifname: the interface name
+ * @addr: the IP address (IPv4 or IPv6)
+ * @peer: The IP address of peer (IPv4 or IPv6)
+ * @prefix: number of 1 bits in the netmask
+ *
+ * Add an IP address to an interface. This function *does not* remove
+ * any previously added IP addresses - that must be done separately with
+ * virNetDevIPAddrClear.
+ *
+ * Returns 0 in case of success or -1 in case of error.
+ */
+int
+virNetDevIPAddrAdd(const char *ifname,
+ virSocketAddr *addr,
+ virSocketAddr *peer,
+ unsigned int prefix)
+{
+ virSocketAddr *broadcast = NULL;
+ int ret = -1;
+ struct nl_msg *nlmsg = NULL;
+ struct nlmsghdr *resp = NULL;
+ unsigned int recvbuflen;
+
+ /* The caller needs to provide a correct address */
+ if (VIR_SOCKET_ADDR_FAMILY(addr) == AF_INET &&
+ !(peer && VIR_SOCKET_ADDR_VALID(peer))) {
+ /* compute a broadcast address if this is IPv4 */
+ if (VIR_ALLOC(broadcast) < 0)
+ return -1;
+
+ if (virSocketAddrBroadcastByPrefix(addr, prefix, broadcast) < 0)
+ goto cleanup;
+ }
+
+ if (!(nlmsg = virNetDevCreateNetlinkAddressMessage(RTM_NEWADDR, ifname,
+ addr, prefix,
+ broadcast, peer)))
+ goto cleanup;
+
+ if (virNetlinkCommand(nlmsg, &resp, &recvbuflen, 0, 0,
+ NETLINK_ROUTE, 0) < 0)
+ goto cleanup;
+
+
+ if (virNetlinkGetErrorCode(resp, recvbuflen) < 0) {
+ virReportError(VIR_ERR_SYSTEM_ERROR,
+ _("Error adding IP address to %s"), ifname);
+ goto cleanup;
+ }
+
+ ret = 0;
+ cleanup:
+ nlmsg_free(nlmsg);
+ VIR_FREE(resp);
+ VIR_FREE(broadcast);
+ return ret;
+}
+
+
+/**
+ * virNetDevIPAddrDel:
+ * @ifname: the interface name
+ * @addr: the IP address (IPv4 or IPv6)
+ * @prefix: number of 1 bits in the netmask
+ *
+ * Delete an IP address from an interface.
+ *
+ * Returns 0 in case of success or -1 in case of error.
+ */
+int
+virNetDevIPAddrDel(const char *ifname,
+ virSocketAddr *addr,
+ unsigned int prefix)
+{
+ int ret = -1;
+ struct nl_msg *nlmsg = NULL;
+ struct nlmsghdr *resp = NULL;
+ unsigned int recvbuflen;
+
+ if (!(nlmsg = virNetDevCreateNetlinkAddressMessage(RTM_DELADDR, ifname,
+ addr, prefix,
+ NULL, NULL)))
+ goto cleanup;
+
+ if (virNetlinkCommand(nlmsg, &resp, &recvbuflen, 0, 0,
+ NETLINK_ROUTE, 0) < 0)
+ goto cleanup;
+
+ if (virNetlinkGetErrorCode(resp, recvbuflen) < 0) {
+ virReportError(VIR_ERR_SYSTEM_ERROR,
+ _("Error removing IP address from %s"), ifname);
+ goto cleanup;
+ }
+
+ ret = 0;
+ cleanup:
+ nlmsg_free(nlmsg);
+ VIR_FREE(resp);
+ return ret;
+}
+
+
+/**
+ * virNetDevIPRouteAdd:
+ * @ifname: the interface name
+ * @addr: the IP network address (IPv4 or IPv6)
+ * @prefix: number of 1 bits in the netmask
+ * @gateway: via address for route (same as @addr)
+ *
+ * Add a route for a network IP address to an interface. This function
+ * *does not* remove any previously added IP static routes.
+ *
+ * Returns 0 in case of success or -1 in case of error.
+ */
+int
+virNetDevIPRouteAdd(const char *ifname,
+ virSocketAddrPtr addr,
+ unsigned int prefix,
+ virSocketAddrPtr gateway,
+ unsigned int metric)
+{
+ int ret = -1;
+ struct nl_msg *nlmsg = NULL;
+ struct nlmsghdr *resp = NULL;
+ unsigned int recvbuflen;
+ unsigned int ifindex;
+ struct rtmsg rtmsg;
+ void *gatewayData = NULL;
+ void *addrData = NULL;
+ size_t addrDataLen;
+ int errCode;
+ virSocketAddr defaultAddr;
+ virSocketAddrPtr actualAddr;
+ char *toStr = NULL;
+ char *viaStr = NULL;
+
+ actualAddr = addr;
+
+ /* If we have no valid network address, then use the default one */
+ if (!addr || !VIR_SOCKET_ADDR_VALID(addr)) {
+ VIR_DEBUG("computing default address");
+ int family = VIR_SOCKET_ADDR_FAMILY(gateway);
+ if (family == AF_INET) {
+ if (virSocketAddrParseIPv4(&defaultAddr, VIR_SOCKET_ADDR_IPV4_ALL) < 0)
+ goto cleanup;
+ } else {
+ if (virSocketAddrParseIPv6(&defaultAddr, VIR_SOCKET_ADDR_IPV6_ALL) < 0)
+ goto cleanup;
+ }
+
+ actualAddr = &defaultAddr;
+ }
+
+ toStr = virSocketAddrFormat(actualAddr);
+ viaStr = virSocketAddrFormat(gateway);
+ VIR_DEBUG("Adding route %s/%d via %s", toStr, prefix, viaStr);
+
+ if (virNetDevGetIPAddressBinary(actualAddr, &addrData, &addrDataLen) < 0 ||
+ virNetDevGetIPAddressBinary(gateway, &gatewayData, &addrDataLen) < 0)
+ goto cleanup;
+
+ /* Get the interface index */
+ if ((ifindex = if_nametoindex(ifname)) == 0)
+ goto cleanup;
+
+ if (!(nlmsg = nlmsg_alloc_simple(RTM_NEWROUTE,
+ NLM_F_REQUEST | NLM_F_CREATE |
+ NLM_F_EXCL))) {
+ virReportOOMError();
+ goto cleanup;
+ }
+
+ memset(&rtmsg, 0, sizeof(rtmsg));
+
+ rtmsg.rtm_family = VIR_SOCKET_ADDR_FAMILY(gateway);
+ rtmsg.rtm_table = RT_TABLE_MAIN;
+ rtmsg.rtm_scope = RT_SCOPE_UNIVERSE;
+ rtmsg.rtm_protocol = RTPROT_BOOT;
+ rtmsg.rtm_type = RTN_UNICAST;
+ rtmsg.rtm_dst_len = prefix;
+
+ if (nlmsg_append(nlmsg, &rtmsg, sizeof(rtmsg), NLMSG_ALIGNTO) < 0)
+ goto buffer_too_small;
+
+ if (prefix > 0 && nla_put(nlmsg, RTA_DST, addrDataLen, addrData) < 0)
+ goto buffer_too_small;
+
+ if (nla_put(nlmsg, RTA_GATEWAY, addrDataLen, gatewayData) < 0)
+ goto buffer_too_small;
+
+ if (nla_put_u32(nlmsg, RTA_OIF, ifindex) < 0)
+ goto buffer_too_small;
+
+ if (metric > 0 && nla_put_u32(nlmsg, RTA_PRIORITY, metric) < 0)
+ goto buffer_too_small;
+
+ if (virNetlinkCommand(nlmsg, &resp, &recvbuflen, 0, 0,
+ NETLINK_ROUTE, 0) < 0)
+ goto cleanup;
+
+ if ((errCode = virNetlinkGetErrorCode(resp, recvbuflen)) < 0) {
+ virReportSystemError(errCode, _("Error adding route to %s"), ifname);
+ goto cleanup;
+ }
+
+ ret = 0;
+ cleanup:
+ VIR_FREE(toStr);
+ VIR_FREE(viaStr);
+ nlmsg_free(nlmsg);
+ return ret;
+
+ buffer_too_small:
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("allocated netlink buffer is too small"));
+ goto cleanup;
+}
+
+
+/* return true if there is a known address with 'tentative' flag set */
+static bool
+virNetDevIPParseDadStatus(struct nlmsghdr *nlh, int len,
+ virSocketAddrPtr *addrs, size_t count)
+{
+ struct ifaddrmsg *ifaddrmsg_ptr;
+ unsigned int ifaddrmsg_len;
+ struct rtattr *rtattr_ptr;
+ size_t i;
+ struct in6_addr *addr;
+
+ VIR_WARNINGS_NO_CAST_ALIGN
+ for (; NLMSG_OK(nlh, len); nlh = NLMSG_NEXT(nlh, len)) {
+ VIR_WARNINGS_RESET
+ if (NLMSG_PAYLOAD(nlh, 0) < sizeof(struct ifaddrmsg)) {
+ /* Message without payload is the last one. */
+ break;
+ }
+
+ ifaddrmsg_ptr = (struct ifaddrmsg *)NLMSG_DATA(nlh);
+ if (!(ifaddrmsg_ptr->ifa_flags & IFA_F_TENTATIVE)) {
+ /* Not tentative: we are not interested in this entry. */
+ continue;
+ }
+
+ ifaddrmsg_len = IFA_PAYLOAD(nlh);
+ VIR_WARNINGS_NO_CAST_ALIGN
+ rtattr_ptr = (struct rtattr *) IFA_RTA(ifaddrmsg_ptr);
+ for (; RTA_OK(rtattr_ptr, ifaddrmsg_len);
+ rtattr_ptr = RTA_NEXT(rtattr_ptr, ifaddrmsg_len)) {
+ VIR_WARNINGS_RESET
+ if (RTA_PAYLOAD(rtattr_ptr) != sizeof(struct in6_addr)) {
+ /* No address: ignore. */
+ continue;
+ }
+
+ /* We check only known addresses. */
+ for (i = 0; i < count; i++) {
+ addr = &addrs[i]->data.inet6.sin6_addr;
+ if (!memcmp(addr, RTA_DATA(rtattr_ptr),
+ sizeof(struct in6_addr))) {
+ /* We found matching tentative address. */
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+}
+
+
+/* return after DAD finishes for all known IPv6 addresses or an error */
+int
+virNetDevIPWaitDadFinish(virSocketAddrPtr *addrs, size_t count)
+{
+ struct nl_msg *nlmsg = NULL;
+ struct ifaddrmsg ifa;
+ struct nlmsghdr *resp = NULL;
+ unsigned int recvbuflen;
+ int ret = -1;
+ bool dad = true;
+ time_t max_time = time(NULL) + VIR_DAD_WAIT_TIMEOUT;
+
+ if (!(nlmsg = nlmsg_alloc_simple(RTM_GETADDR,
+ NLM_F_REQUEST | NLM_F_DUMP))) {
+ virReportOOMError();
+ return -1;
+ }
+
+ memset(&ifa, 0, sizeof(ifa));
+ /* DAD is for IPv6 adresses only. */
+ ifa.ifa_family = AF_INET6;
+ if (nlmsg_append(nlmsg, &ifa, sizeof(ifa), NLMSG_ALIGNTO) < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("allocated netlink buffer is too small"));
+ goto cleanup;
+ }
+
+ /* Periodically query netlink until DAD finishes on all known addresses. */
+ while (dad && time(NULL) < max_time) {
+ if (virNetlinkCommand(nlmsg, &resp, &recvbuflen, 0, 0,
+ NETLINK_ROUTE, 0) < 0)
+ goto cleanup;
+
+ if (virNetlinkGetErrorCode(resp, recvbuflen) < 0) {
+ virReportError(VIR_ERR_SYSTEM_ERROR, "%s",
+ _("error reading DAD state information"));
+ goto cleanup;
+ }
+
+ /* Parse response. */
+ dad = virNetDevIPParseDadStatus(resp, recvbuflen, addrs, count);
+ if (dad)
+ usleep(1000 * 10);
+
+ VIR_FREE(resp);
+ }
+ /* Check timeout. */
+ if (dad) {
+ virReportError(VIR_ERR_SYSTEM_ERROR,
+ _("Duplicate Address Detection "
+ "not finished in %d seconds"), VIR_DAD_WAIT_TIMEOUT);
+ } else {
+ ret = 0;
+ }
+
+ cleanup:
+ VIR_FREE(resp);
+ nlmsg_free(nlmsg);
+ return ret;
+}
+
+
+#else /* defined(__linux__) && defined(HAVE_LIBNL) */
+
+
+int
+virNetDevIPAddrAdd(const char *ifname,
+ virSocketAddr *addr,
+ virSocketAddr *peer,
+ unsigned int prefix)
+{
+ virCommandPtr cmd = NULL;
+ char *addrstr = NULL, *bcaststr = NULL, *peerstr = NULL;
+ virSocketAddr broadcast;
+ int ret = -1;
+
+ if (!(addrstr = virSocketAddrFormat(addr)))
+ goto cleanup;
+
+ if (peer && VIR_SOCKET_ADDR_VALID(peer) && !(peerstr = virSocketAddrFormat(peer)))
+ goto cleanup;
+
+ /* format up a broadcast address if this is IPv4 */
+ if (!peerstr && ((VIR_SOCKET_ADDR_IS_FAMILY(addr, AF_INET)) &&
+ ((virSocketAddrBroadcastByPrefix(addr, prefix, &broadcast) < 0) ||
+ !(bcaststr = virSocketAddrFormat(&broadcast))))) {
+ goto cleanup;
+ }
+
+# ifdef IFCONFIG_PATH
+ cmd = virCommandNew(IFCONFIG_PATH);
+ virCommandAddArg(cmd, ifname);
+ if (VIR_SOCKET_ADDR_IS_FAMILY(addr, AF_INET6))
+ virCommandAddArg(cmd, "inet6");
+ else
+ virCommandAddArg(cmd, "inet");
+ virCommandAddArgFormat(cmd, "%s/%u", addrstr, prefix);
+ if (peerstr)
+ virCommandAddArgList(cmd, "pointopoint", peerstr, NULL);
+ if (bcaststr)
+ virCommandAddArgList(cmd, "broadcast", bcaststr, NULL);
+ virCommandAddArg(cmd, "alias");
+# else
+ cmd = virCommandNew(IP_PATH);
+ virCommandAddArgList(cmd, "addr", "add", NULL);
+ virCommandAddArgFormat(cmd, "%s/%u", addrstr, prefix);
+ if (peerstr)
+ virCommandAddArgList(cmd, "peer", peerstr, NULL);
+ if (bcaststr)
+ virCommandAddArgList(cmd, "broadcast", bcaststr, NULL);
+ virCommandAddArgList(cmd, "dev", ifname, NULL);
+# endif
+
+ if (virCommandRun(cmd, NULL) < 0)
+ goto cleanup;
+
+ ret = 0;
+ cleanup:
+ VIR_FREE(addrstr);
+ VIR_FREE(bcaststr);
+ VIR_FREE(peerstr);
+ virCommandFree(cmd);
+ return ret;
+}
+
+
+int
+virNetDevIPAddrDel(const char *ifname,
+ virSocketAddr *addr,
+ unsigned int prefix)
+{
+ virCommandPtr cmd = NULL;
+ char *addrstr;
+ int ret = -1;
+
+ if (!(addrstr = virSocketAddrFormat(addr)))
+ goto cleanup;
+# ifdef IFCONFIG_PATH
+ cmd = virCommandNew(IFCONFIG_PATH);
+ virCommandAddArg(cmd, ifname);
+ if (VIR_SOCKET_ADDR_IS_FAMILY(addr, AF_INET6))
+ virCommandAddArg(cmd, "inet6");
+ else
+ virCommandAddArg(cmd, "inet");
+ virCommandAddArgFormat(cmd, "%s/%u", addrstr, prefix);
+ virCommandAddArg(cmd, "-alias");
+# else
+ cmd = virCommandNew(IP_PATH);
+ virCommandAddArgList(cmd, "addr", "del", NULL);
+ virCommandAddArgFormat(cmd, "%s/%u", addrstr, prefix);
+ virCommandAddArgList(cmd, "dev", ifname, NULL);
+# endif
+
+ if (virCommandRun(cmd, NULL) < 0)
+ goto cleanup;
+
+ ret = 0;
+ cleanup:
+ VIR_FREE(addrstr);
+ virCommandFree(cmd);
+ return ret;
+}
+
+
+int
+virNetDevIPRouteAdd(const char *ifname,
+ virSocketAddrPtr addr,
+ unsigned int prefix,
+ virSocketAddrPtr gateway,
+ unsigned int metric)
+{
+ virCommandPtr cmd = NULL;
+ char *addrstr = NULL, *gatewaystr = NULL;
+ int ret = -1;
+
+ if (!(addrstr = virSocketAddrFormat(addr)))
+ goto cleanup;
+ if (!(gatewaystr = virSocketAddrFormat(gateway)))
+ goto cleanup;
+ cmd = virCommandNew(IP_PATH);
+ virCommandAddArgList(cmd, "route", "add", NULL);
+ virCommandAddArgFormat(cmd, "%s/%u", addrstr, prefix);
+ virCommandAddArgList(cmd, "via", gatewaystr, "dev", ifname,
+ "proto", "static", "metric", NULL);
+ virCommandAddArgFormat(cmd, "%u", metric);
+
+ if (virCommandRun(cmd, NULL) < 0)
+ goto cleanup;
+
+ ret = 0;
+ cleanup:
+ VIR_FREE(addrstr);
+ VIR_FREE(gatewaystr);
+ virCommandFree(cmd);
+ return ret;
+}
+
+
+/* return after DAD finishes for all known IPv6 addresses or an error */
+int
+virNetDevWaitDadFinish(virSocketAddrPtr *addrs ATTRIBUTE_UNUSED,
+ size_t count ATTRIBUTE_UNUSED)
+{
+ virReportSystemError(ENOSYS, "%s",
+ _("Unable to wait for IPv6 DAD on this platform"));
+ return -1;
+}
+
+
+#endif /* defined(__linux__) && defined(HAVE_LIBNL) */
+
+
+/**
+ * virNetDevGetIPv4AddressIoctl:
+ * @ifname: name of the interface whose IP address we want
+ * @addr: filled with the IPv4 address
+ *
+ * This function gets the IPv4 address for the interface @ifname
+ * and stores it in @addr
+ *
+ * Returns 0 on success, -errno on failure.
+ */
+#if defined(SIOCGIFADDR) && defined(HAVE_STRUCT_IFREQ)
+static int
+virNetDevGetIPv4AddressIoctl(const char *ifname,
+ virSocketAddrPtr addr)
+{
+ int fd = -1;
+ int ret = -1;
+ struct ifreq ifr;
+
+ if ((fd = virNetDevSetupControl(ifname, &ifr)) < 0)
+ return -1;
+
+ if (ioctl(fd, SIOCGIFADDR, (char *)&ifr) < 0) {
+ virReportSystemError(errno,
+ _("Unable to get IPv4 address for interface %s via ioctl"),
+ ifname);
+ goto cleanup;
+ }
+
+ addr->data.stor.ss_family = AF_INET;
+ addr->len = sizeof(addr->data.inet4);
+ memcpy(&addr->data.inet4, &ifr.ifr_addr, addr->len);
+ ret = 0;
+
+ cleanup:
+ VIR_FORCE_CLOSE(fd);
+ return ret;
+}
+
+#else /* ! SIOCGIFADDR */
+
+static int
+virNetDevGetIPv4AddressIoctl(const char *ifname ATTRIBUTE_UNUSED,
+ virSocketAddrPtr addr ATTRIBUTE_UNUSED)
+{
+ return -2;
+}
+
+#endif /* ! SIOCGIFADDR */
+
+/**
+ * virNetDevGetifaddrsAddress:
+ * @ifname: name of the interface whose IP address we want
+ * @addr: filled with the IP address
+ *
+ * This function gets the IP address for the interface @ifname
+ * and stores it in @addr
+ *
+ * Returns 0 on success, -1 on failure, -2 on unsupported.
+ */
+#if HAVE_GETIFADDRS
+static int
+virNetDevGetifaddrsAddress(const char *ifname,
+ virSocketAddrPtr addr)
+{
+ struct ifaddrs *ifap, *ifa;
+ int ret = -1;
+
+ if (getifaddrs(&ifap) < 0) {
+ virReportSystemError(errno,
+ _("Could not get interface list for '%s'"),
+ ifname);
+ return -1;
+ }
+
+ for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
+ int family = ifa->ifa_addr->sa_family;
+
+ if (STRNEQ_NULLABLE(ifa->ifa_name, ifname))
+ continue;
+ if (family != AF_INET6 && family != AF_INET)
+ continue;
+
+ if (family == AF_INET6) {
+ addr->len = sizeof(addr->data.inet6);
+ memcpy(&addr->data.inet6, ifa->ifa_addr, addr->len);
+ } else {
+ addr->len = sizeof(addr->data.inet4);
+ memcpy(&addr->data.inet4, ifa->ifa_addr, addr->len);
+ }
+ addr->data.stor.ss_family = family;
+ ret = 0;
+ goto cleanup;
+ }
+
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("no IP address found for interface '%s'"),
+ ifname);
+ cleanup:
+ freeifaddrs(ifap);
+ return ret;
+}
+
+#else /* ! HAVE_GETIFADDRS */
+
+static int
+virNetDevGetifaddrsAddress(const char *ifname ATTRIBUTE_UNUSED,
+ virSocketAddrPtr addr ATTRIBUTE_UNUSED)
+{
+ return -2;
+}
+
+#endif
+
+/**
+ * virNetDevIPIPAddrGet:
+ * @ifname: name of the interface whose IP address we want
+ * @addr: filled with the IPv4 address
+ *
+ * This function gets the IPv4 address for the interface @ifname
+ * and stores it in @addr
+ *
+ * Returns 0 on success, -errno on failure.
+ */
+int
+virNetDevIPAddrGet(const char *ifname,
+ virSocketAddrPtr addr)
+{
+ int ret;
+
+ memset(addr, 0, sizeof(*addr));
+ addr->data.stor.ss_family = AF_UNSPEC;
+
+ if ((ret = virNetDevGetifaddrsAddress(ifname, addr)) != -2)
+ return ret;
+
+ if ((ret = virNetDevGetIPv4AddressIoctl(ifname, addr)) != -2)
+ return ret;
+
+ virReportSystemError(ENOSYS, "%s",
+ _("Unable to get IP address on this platform"));
+ return -1;
+}
diff --git a/src/util/virnetdevip.h b/src/util/virnetdevip.h
new file mode 100644
index 0000000..f60465d
--- /dev/null
+++ b/src/util/virnetdevip.h
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2007-2016 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Mark McLoughlin <***@redhat.com>
+ * Daniel P. Berrange <***@redhat.com>
+ */
+
+#ifndef __VIR_NETDEVIP_H__
+# define __VIR_NETDEVIP_H__
+
+# include "virsocketaddr.h"
+
+/* manipulating/querying the netdev */
+int virNetDevIPAddrAdd(const char *ifname,
+ virSocketAddr *addr,
+ virSocketAddr *peer,
+ unsigned int prefix)
+ ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
+int virNetDevIPRouteAdd(const char *ifname,
+ virSocketAddrPtr addr,
+ unsigned int prefix,
+ virSocketAddrPtr gateway,
+ unsigned int metric)
+ ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(4)
+ ATTRIBUTE_RETURN_CHECK;
+int virNetDevIPAddrDel(const char *ifname,
+ virSocketAddr *addr,
+ unsigned int prefix)
+ ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
+int virNetDevIPAddrGet(const char *ifname, virSocketAddrPtr addr)
+ ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
+int virNetDevIPWaitDadFinish(virSocketAddrPtr *addrs, size_t count)
+ ATTRIBUTE_NONNULL(1);
+
+#endif /* __VIR_NETDEVIP_H__ */
--
2.5.5
John Ferlan
2016-06-23 22:21:57 UTC
Permalink
Post by Laine Stump
This patch splits virnetdev.[ch] into multiple files, with the new
virnetdevip.[ch] containing all the functions related to setting and
retrieving IP-related info for a device (both addresses and routes).
---
po/POTFILES.in | 1 +
src/Makefile.am | 1 +
src/libvirt_private.syms | 13 +-
src/lxc/lxc_container.c | 14 +-
src/network/bridge_driver.c | 15 +-
src/util/virnetdev.c | 711 ----------------------------------------
src/util/virnetdevip.c | 778 ++++++++++++++++++++++++++++++++++++++++++++
src/util/virnetdevip.h | 50 +++
8 files changed, 853 insertions(+), 730 deletions(-)
create mode 100644 src/util/virnetdevip.c
create mode 100644 src/util/virnetdevip.h
Seems to be a very faithful move and rename.

ACK

John
Laine Stump
2016-06-22 17:37:13 UTC
Permalink
These functions all need to be called from a utility function that
must be located in the util directory, so we move them all into
util/virnetdevip.[ch] now that it exists.

Function and struct names were appropriately changed for the new
location, but all code is unchanged aside from motion and renaming.
---
src/conf/domain_conf.c | 36 ++++++-------
src/conf/domain_conf.h | 16 ++----
src/conf/network_conf.c | 16 +++---
src/conf/network_conf.h | 4 +-
src/conf/networkcommon_conf.c | 107 ++++----------------------------------
src/conf/networkcommon_conf.h | 55 +++++++-------------
src/libvirt_private.syms | 16 +++---
src/lxc/lxc_container.c | 12 ++---
src/lxc/lxc_native.c | 12 ++---
src/network/bridge_driver.c | 14 ++---
src/network/bridge_driver_linux.c | 6 +--
src/util/virnetdevip.c | 69 ++++++++++++++++++++++++
src/util/virnetdevip.h | 29 +++++++++++
13 files changed, 191 insertions(+), 201 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 4802e03..f380271 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -1806,7 +1806,7 @@ virDomainNetDefClear(virDomainNetDefPtr def)
VIR_FREE(def->ips);

for (i = 0; i < def->nroutes; i++)
- virNetworkRouteDefFree(def->routes[i]);
+ virNetDevIPRouteFree(def->routes[i]);
VIR_FREE(def->routes);

virDomainDeviceInfoClear(&def->info);
@@ -2214,7 +2214,7 @@ void virDomainHostdevDefClear(virDomainHostdevDefPtr def)
VIR_FREE(def->source.caps.u.net.ips[i]);
VIR_FREE(def->source.caps.u.net.ips);
for (i = 0; i < def->source.caps.u.net.nroutes; i++)
- virNetworkRouteDefFree(def->source.caps.u.net.routes[i]);
+ virNetDevIPRouteFree(def->source.caps.u.net.routes[i]);
VIR_FREE(def->source.caps.u.net.routes);
break;
}
@@ -6115,11 +6115,11 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node,
return ret;
}

-static virDomainNetIPDefPtr
+static virNetDevIPAddrPtr
virDomainNetIPParseXML(xmlNodePtr node)
{
/* Parse the prefix in every case */
- virDomainNetIPDefPtr ip = NULL, ret = NULL;
+ virNetDevIPAddrPtr ip = NULL, ret = NULL;
char *prefixStr = NULL;
unsigned int prefixValue = 0;
char *familyStr = NULL;
@@ -6246,7 +6246,7 @@ virDomainHostdevDefParseXMLCaps(xmlNodePtr node ATTRIBUTE_UNUSED,
if (nipnodes) {
size_t i;
for (i = 0; i < nipnodes; i++) {
- virDomainNetIPDefPtr ip = virDomainNetIPParseXML(ipnodes[i]);
+ virNetDevIPAddrPtr ip = virDomainNetIPParseXML(ipnodes[i]);

if (!ip)
goto error;
@@ -6266,9 +6266,9 @@ virDomainHostdevDefParseXMLCaps(xmlNodePtr node ATTRIBUTE_UNUSED,
if (nroutenodes) {
size_t i;
for (i = 0; i < nroutenodes; i++) {
- virNetworkRouteDefPtr route = NULL;
+ virNetDevIPRoutePtr route = NULL;

- if (!(route = virNetworkRouteDefParseXML(_("Domain hostdev device"),
+ if (!(route = virNetDevIPRouteParseXML(_("Domain hostdev device"),
routenodes[i],
ctxt)))
goto error;
@@ -6276,7 +6276,7 @@ virDomainHostdevDefParseXMLCaps(xmlNodePtr node ATTRIBUTE_UNUSED,

if (VIR_APPEND_ELEMENT(def->source.caps.u.net.routes,
def->source.caps.u.net.nroutes, route) < 0) {
- virNetworkRouteDefFree(route);
+ virNetDevIPRouteFree(route);
goto error;
}
}
@@ -8883,7 +8883,7 @@ virDomainNetAppendIPAddress(virDomainNetDefPtr def,
int family,
unsigned int prefix)
{
- virDomainNetIPDefPtr ipDef = NULL;
+ virNetDevIPAddrPtr ipDef = NULL;
if (VIR_ALLOC(ipDef) < 0)
return -1;

@@ -8955,9 +8955,9 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
int ret, val;
size_t i;
size_t nips = 0;
- virDomainNetIPDefPtr *ips = NULL;
+ virNetDevIPAddrPtr *ips = NULL;
size_t nroutes = 0;
- virNetworkRouteDefPtr *routes = NULL;
+ virNetDevIPRoutePtr *routes = NULL;

if (VIR_ALLOC(def) < 0)
return NULL;
@@ -9074,7 +9074,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
ctxt->node = tmpnode;
}
} else if (xmlStrEqual(cur->name, BAD_CAST "ip")) {
- virDomainNetIPDefPtr ip = NULL;
+ virNetDevIPAddrPtr ip = NULL;

if (!(ip = virDomainNetIPParseXML(cur)))
goto error;
@@ -9082,13 +9082,13 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
if (VIR_APPEND_ELEMENT(ips, nips, ip) < 0)
goto error;
} else if (xmlStrEqual(cur->name, BAD_CAST "route")) {
- virNetworkRouteDefPtr route = NULL;
- if (!(route = virNetworkRouteDefParseXML(_("Domain interface"),
+ virNetDevIPRoutePtr route = NULL;
+ if (!(route = virNetDevIPRouteParseXML(_("Domain interface"),
cur, ctxt)))
goto error;

if (VIR_APPEND_ELEMENT(routes, nroutes, route) < 0) {
- virNetworkRouteDefFree(route);
+ virNetDevIPRouteFree(route);
goto error;
}
} else if (!ifname &&
@@ -20270,7 +20270,7 @@ virDomainFSDefFormat(virBufferPtr buf,
}

static int
-virDomainNetIPsFormat(virBufferPtr buf, virDomainNetIPDefPtr *ips, size_t nips)
+virDomainNetIPsFormat(virBufferPtr buf, virNetDevIPAddrPtr *ips, size_t nips)
{
size_t i;

@@ -20300,13 +20300,13 @@ virDomainNetIPsFormat(virBufferPtr buf, virDomainNetIPDefPtr *ips, size_t nips)

static int
virDomainNetRoutesFormat(virBufferPtr buf,
- virNetworkRouteDefPtr *routes,
+ virNetDevIPRoutePtr *routes,
size_t nroutes)
{
size_t i;

for (i = 0; i < nroutes; i++)
- if (virNetworkRouteDefFormat(buf, routes[i]) < 0)
+ if (virNetDevIPRouteFormat(buf, routes[i]) < 0)
return -1;
return 0;
}
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index e93bd5c..c529b09 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -41,6 +41,7 @@
# include "numa_conf.h"
# include "virnetdevmacvlan.h"
# include "virsysinfo.h"
+# include "virnetdevip.h"
# include "virnetdevvportprofile.h"
# include "virnetdevbandwidth.h"
# include "virnetdevvlan.h"
@@ -382,13 +383,6 @@ typedef enum {
VIR_DOMAIN_HOSTDEV_CAPS_TYPE_LAST
} virDomainHostdevCapsType;

-typedef struct _virDomainNetIPDef virDomainNetIPDef;
-typedef virDomainNetIPDef *virDomainNetIPDefPtr;
-struct _virDomainNetIPDef {
- virSocketAddr address; /* ipv4 or ipv6 address */
- unsigned int prefix; /* number of 1 bits in the net mask */
-};
-
typedef struct _virDomainHostdevCaps virDomainHostdevCaps;
typedef virDomainHostdevCaps *virDomainHostdevCapsPtr;
struct _virDomainHostdevCaps {
@@ -403,9 +397,9 @@ struct _virDomainHostdevCaps {
struct {
char *iface;
size_t nips;
- virDomainNetIPDefPtr *ips;
+ virNetDevIPAddrPtr *ips;
size_t nroutes;
- virNetworkRouteDefPtr *routes;
+ virNetDevIPRoutePtr *routes;
} net;
} u;
};
@@ -985,9 +979,9 @@ struct _virDomainNetDef {
int trustGuestRxFilters; /* enum virTristateBool */
int linkstate;
size_t nips;
- virDomainNetIPDefPtr *ips;
+ virNetDevIPAddrPtr *ips;
size_t nroutes;
- virNetworkRouteDefPtr *routes;
+ virNetDevIPRoutePtr *routes;
};

/* Used for prefix of ifname of any network name generated dynamically
diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index 5ae2bdf..fb2a48d 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -406,7 +406,7 @@ virNetworkDefFree(virNetworkDefPtr def)
VIR_FREE(def->ips);

for (i = 0; i < def->nroutes && def->routes; i++)
- virNetworkRouteDefFree(def->routes[i]);
+ virNetDevIPRouteFree(def->routes[i]);
VIR_FREE(def->routes);

for (i = 0; i < def->nPortGroups && def->portGroups; i++)
@@ -804,7 +804,7 @@ virNetworkDefGetIPByIndex(const virNetworkDef *def,
}

/* return routes[index], or NULL if there aren't enough routes */
-virNetworkRouteDefPtr
+virNetDevIPRoutePtr
virNetworkDefGetRouteByIndex(const virNetworkDef *def,
int family, size_t n)
{
@@ -818,7 +818,7 @@ virNetworkDefGetRouteByIndex(const virNetworkDef *def,

/* find the nth route of type "family" */
for (i = 0; i < def->nroutes; i++) {
- virSocketAddrPtr addr = virNetworkRouteDefGetAddress(def->routes[i]);
+ virSocketAddrPtr addr = virNetDevIPRouteGetAddress(def->routes[i]);
if (VIR_SOCKET_ADDR_IS_FAMILY(addr, family)
&& (n-- <= 0)) {
return def->routes[i];
@@ -2261,9 +2261,9 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt)
goto error;
/* parse each definition */
for (i = 0; i < nRoutes; i++) {
- virNetworkRouteDefPtr route = NULL;
+ virNetDevIPRoutePtr route = NULL;

- if (!(route = virNetworkRouteDefParseXML(def->name,
+ if (!(route = virNetDevIPRouteParseXML(def->name,
routeNodes[i],
ctxt)))
goto error;
@@ -2283,8 +2283,8 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt)
size_t j;
virSocketAddr testAddr, testGw;
bool addrMatch;
- virNetworkRouteDefPtr gwdef = def->routes[i];
- virSocketAddrPtr gateway = virNetworkRouteDefGetGateway(gwdef);
+ virNetDevIPRoutePtr gwdef = def->routes[i];
+ virSocketAddrPtr gateway = virNetDevIPRouteGetGateway(gwdef);
addrMatch = false;
for (j = 0; j < nips; j++) {
virNetworkIPDefPtr def2 = &def->ips[j];
@@ -2876,7 +2876,7 @@ virNetworkDefFormatBuf(virBufferPtr buf,
}

for (i = 0; i < def->nroutes; i++) {
- if (virNetworkRouteDefFormat(buf, def->routes[i]) < 0)
+ if (virNetDevIPRouteFormat(buf, def->routes[i]) < 0)
goto error;
}

diff --git a/src/conf/network_conf.h b/src/conf/network_conf.h
index 18f4d1e..e7ce674 100644
--- a/src/conf/network_conf.h
+++ b/src/conf/network_conf.h
@@ -243,7 +243,7 @@ struct _virNetworkDef {
virNetworkIPDefPtr ips; /* ptr to array of IP addresses on this network */

size_t nroutes;
- virNetworkRouteDefPtr *routes; /* ptr to array of static routes on this interface */
+ virNetDevIPRoutePtr *routes; /* ptr to array of static routes on this interface */

virNetworkDNSDef dns; /* dns related configuration */
virNetDevVPortProfilePtr virtPortProfile;
@@ -354,7 +354,7 @@ virPortGroupDefPtr virPortGroupFindByName(virNetworkDefPtr net,
virNetworkIPDefPtr
virNetworkDefGetIPByIndex(const virNetworkDef *def,
int family, size_t n);
-virNetworkRouteDefPtr
+virNetDevIPRoutePtr
virNetworkDefGetRouteByIndex(const virNetworkDef *def,
int family, size_t n);
int virNetworkIPDefPrefix(const virNetworkIPDef *def);
diff --git a/src/conf/networkcommon_conf.c b/src/conf/networkcommon_conf.c
index 8f9d4b8..12be819 100644
--- a/src/conf/networkcommon_conf.c
+++ b/src/conf/networkcommon_conf.c
@@ -32,34 +32,8 @@

#define VIR_FROM_THIS VIR_FROM_NETWORK

-struct _virNetworkRouteDef {
- char *family; /* ipv4 or ipv6 - default is ipv4 */
- virSocketAddr address; /* Routed Network IP address */
-
- /* One or the other of the following two will be used for a given
- * Network address, but never both. The parser guarantees this.
- * The virSocketAddrGetIPPrefix() can be used to get a
- * valid prefix.
- */
- virSocketAddr netmask; /* ipv4 - either netmask or prefix specified */
- unsigned int prefix; /* ipv6 - only prefix allowed */
- bool has_prefix; /* prefix= was specified */
- unsigned int metric; /* value for metric (defaults to 1) */
- bool has_metric; /* metric= was specified */
- virSocketAddr gateway; /* gateway IP address for ip-route */
-};
-
-void
-virNetworkRouteDefFree(virNetworkRouteDefPtr def)
-{
- if (!def)
- return;
- VIR_FREE(def->family);
- VIR_FREE(def);
-}
-
-virNetworkRouteDefPtr
-virNetworkRouteDefCreate(const char *errorDetail,
+virNetDevIPRoutePtr
+virNetDevIPRouteCreate(const char *errorDetail,
char *family,
const char *address,
const char *netmask,
@@ -69,7 +43,7 @@ virNetworkRouteDefCreate(const char *errorDetail,
unsigned int metric,
bool hasMetric)
{
- virNetworkRouteDefPtr def = NULL;
+ virNetDevIPRoutePtr def = NULL;
virSocketAddr testAddr;

if (VIR_ALLOC(def) < 0)
@@ -242,21 +216,21 @@ virNetworkRouteDefCreate(const char *errorDetail,
return def;

error:
- virNetworkRouteDefFree(def);
+ virNetDevIPRouteFree(def);
return NULL;
}

-virNetworkRouteDefPtr
-virNetworkRouteDefParseXML(const char *errorDetail,
+virNetDevIPRoutePtr
+virNetDevIPRouteParseXML(const char *errorDetail,
xmlNodePtr node,
xmlXPathContextPtr ctxt)
{
/*
- * virNetworkRouteDef object is already allocated as part
+ * virNetDevIPRoute object is already allocated as part
* of an array. On failure clear: it out, but don't free it.
*/

- virNetworkRouteDefPtr def = NULL;
+ virNetDevIPRoutePtr def = NULL;
xmlNodePtr save;
char *family = NULL;
char *address = NULL, *netmask = NULL;
@@ -302,7 +276,7 @@ virNetworkRouteDefParseXML(const char *errorDetail,
}
}

- def = virNetworkRouteDefCreate(errorDetail, family, address, netmask,
+ def = virNetDevIPRouteCreate(errorDetail, family, address, netmask,
gateway, prefix, hasPrefix, metric,
hasMetric);

@@ -316,8 +290,8 @@ virNetworkRouteDefParseXML(const char *errorDetail,
}

int
-virNetworkRouteDefFormat(virBufferPtr buf,
- const virNetworkRouteDef *def)
+virNetDevIPRouteFormat(virBufferPtr buf,
+ const virNetDevIPRoute *def)
{
int result = -1;
char *addr = NULL;
@@ -354,62 +328,3 @@ virNetworkRouteDefFormat(virBufferPtr buf,
cleanup:
return result;
}
-
-virSocketAddrPtr
-virNetworkRouteDefGetAddress(virNetworkRouteDefPtr def)
-{
- if (def)
- return &def->address;
-
- return NULL;
-}
-
-int
-virNetworkRouteDefGetPrefix(virNetworkRouteDefPtr def)
-{
- int prefix = 0;
- virSocketAddr zero;
-
- if (!def)
- return -1;
-
- /* this creates an all-0 address of the appropriate family */
- ignore_value(virSocketAddrParse(&zero,
- (VIR_SOCKET_ADDR_IS_FAMILY(&def->address, AF_INET)
- ? VIR_SOCKET_ADDR_IPV4_ALL
- : VIR_SOCKET_ADDR_IPV6_ALL),
- VIR_SOCKET_ADDR_FAMILY(&def->address)));
-
- if (virSocketAddrEqual(&def->address, &zero)) {
- if (def->has_prefix && def->prefix == 0)
- prefix = 0;
- else if ((VIR_SOCKET_ADDR_IS_FAMILY(&def->netmask, AF_INET) &&
- virSocketAddrEqual(&def->netmask, &zero)))
- prefix = 0;
- else
- prefix = virSocketAddrGetIPPrefix(&def->address, &def->netmask,
- def->prefix);
- } else {
- prefix = virSocketAddrGetIPPrefix(&def->address, &def->netmask,
- def->prefix);
- }
-
- return prefix;
-}
-
-unsigned int
-virNetworkRouteDefGetMetric(virNetworkRouteDefPtr def)
-{
- if (def && def->has_metric && def->metric > 0)
- return def->metric;
-
- return 1;
-}
-
-virSocketAddrPtr
-virNetworkRouteDefGetGateway(virNetworkRouteDefPtr def)
-{
- if (def)
- return &def->gateway;
- return NULL;
-}
diff --git a/src/conf/networkcommon_conf.h b/src/conf/networkcommon_conf.h
index 1500d0f..160f80b 100644
--- a/src/conf/networkcommon_conf.h
+++ b/src/conf/networkcommon_conf.h
@@ -31,42 +31,25 @@
# include "internal.h"
# include "virbuffer.h"
# include "virsocketaddr.h"
-
-typedef struct _virNetworkRouteDef virNetworkRouteDef;
-typedef virNetworkRouteDef *virNetworkRouteDefPtr;
-
-void
-virNetworkRouteDefFree(virNetworkRouteDefPtr def);
-
-virNetworkRouteDefPtr
-virNetworkRouteDefCreate(const char *networkName,
- char *family,
- const char *address,
- const char *netmask,
- const char *gateway,
- unsigned int prefix,
- bool hasPrefix,
- unsigned int metric,
- bool hasMetric);
-
-virNetworkRouteDefPtr
-virNetworkRouteDefParseXML(const char *networkName,
- xmlNodePtr node,
- xmlXPathContextPtr ctxt);
+# include "virnetdevip.h"
+
+virNetDevIPRoutePtr
+virNetDevIPRouteCreate(const char *networkName,
+ char *family,
+ const char *address,
+ const char *netmask,
+ const char *gateway,
+ unsigned int prefix,
+ bool hasPrefix,
+ unsigned int metric,
+ bool hasMetric);
+
+virNetDevIPRoutePtr
+virNetDevIPRouteParseXML(const char *networkName,
+ xmlNodePtr node,
+ xmlXPathContextPtr ctxt);
int
-virNetworkRouteDefFormat(virBufferPtr buf,
- const virNetworkRouteDef *def);
-
-virSocketAddrPtr
-virNetworkRouteDefGetAddress(virNetworkRouteDefPtr def);
-
-int
-virNetworkRouteDefGetPrefix(virNetworkRouteDefPtr def);
-
-unsigned int
-virNetworkRouteDefGetMetric(virNetworkRouteDefPtr def);
-
-virSocketAddrPtr
-virNetworkRouteDefGetGateway(virNetworkRouteDefPtr def);
+virNetDevIPRouteFormat(virBufferPtr buf,
+ const virNetDevIPRoute *def);

#endif /* __NETWORKCOMMON_CONF_H__ */
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index bd7b730..151cf9f 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -644,14 +644,9 @@ virNetworkEventStateRegisterID;


# conf/networkcommon_conf.h
-virNetworkRouteDefCreate;
-virNetworkRouteDefFormat;
-virNetworkRouteDefFree;
-virNetworkRouteDefGetAddress;
-virNetworkRouteDefGetGateway;
-virNetworkRouteDefGetMetric;
-virNetworkRouteDefGetPrefix;
-virNetworkRouteDefParseXML;
+virNetDevIPRouteCreate;
+virNetDevIPRouteFormat;
+virNetDevIPRouteParseXML;


# conf/node_device_conf.h
@@ -1931,6 +1926,11 @@ virNetDevIPAddrAdd;
virNetDevIPAddrDel;
virNetDevIPAddrGet;
virNetDevIPRouteAdd;
+virNetDevIPRouteFree;
+virNetDevIPRouteGetAddress;
+virNetDevIPRouteGetGateway;
+virNetDevIPRouteGetMetric;
+virNetDevIPRouteGetPrefix;
virNetDevIPWaitDadFinish;


diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c
index a95472c..1000d88 100644
--- a/src/lxc/lxc_container.c
+++ b/src/lxc/lxc_container.c
@@ -513,7 +513,7 @@ static int lxcContainerRenameAndEnableInterfaces(virDomainDefPtr vmDef,
goto error_out;

for (j = 0; j < netDef->nips; j++) {
- virDomainNetIPDefPtr ip = netDef->ips[j];
+ virNetDevIPAddrPtr ip = netDef->ips[j];
int prefix;
char *ipStr = virSocketAddrFormat(&ip->address);

@@ -546,13 +546,13 @@ static int lxcContainerRenameAndEnableInterfaces(virDomainDefPtr vmDef,

/* Set the routes */
for (j = 0; j < netDef->nroutes; j++) {
- virNetworkRouteDefPtr route = netDef->routes[j];
+ virNetDevIPRoutePtr route = netDef->routes[j];

if (virNetDevIPRouteAdd(newname,
- virNetworkRouteDefGetAddress(route),
- virNetworkRouteDefGetPrefix(route),
- virNetworkRouteDefGetGateway(route),
- virNetworkRouteDefGetMetric(route)) < 0) {
+ virNetDevIPRouteGetAddress(route),
+ virNetDevIPRouteGetPrefix(route),
+ virNetDevIPRouteGetGateway(route),
+ virNetDevIPRouteGetMetric(route)) < 0) {
goto error_out;
}
VIR_FREE(toStr);
diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c
index 9ad1b08..8294d29 100644
--- a/src/lxc/lxc_native.c
+++ b/src/lxc/lxc_native.c
@@ -419,7 +419,7 @@ typedef struct {
char *macvlanmode;
char *vlanid;
char *name;
- virDomainNetIPDefPtr *ips;
+ virNetDevIPAddrPtr *ips;
size_t nips;
char *gateway_ipv4;
char *gateway_ipv6;
@@ -430,10 +430,10 @@ typedef struct {
static int
lxcAddNetworkRouteDefinition(const char *address,
int family,
- virNetworkRouteDefPtr **routes,
+ virNetDevIPRoutePtr **routes,
size_t *nroutes)
{
- virNetworkRouteDefPtr route = NULL;
+ virNetDevIPRoutePtr route = NULL;
char *familyStr = NULL;
char *zero = NULL;

@@ -444,7 +444,7 @@ lxcAddNetworkRouteDefinition(const char *address,
if (VIR_STRDUP(familyStr, family == AF_INET ? "ipv4" : "ipv6") < 0)
goto error;

- if (!(route = virNetworkRouteDefCreate(_("Domain interface"), familyStr,
+ if (!(route = virNetDevIPRouteCreate(_("Domain interface"), familyStr,
zero, NULL, address, 0, false,
0, false)))
goto error;
@@ -460,7 +460,7 @@ lxcAddNetworkRouteDefinition(const char *address,
error:
VIR_FREE(familyStr);
VIR_FREE(zero);
- virNetworkRouteDefFree(route);
+ virNetDevIPRouteFree(route);
return -1;
}

@@ -601,7 +601,7 @@ lxcNetworkWalkCallback(const char *name, virConfValuePtr value, void *data)
STREQ(name, "lxc.network.ipv6")) {
int family = AF_INET;
char **ipparts = NULL;
- virDomainNetIPDefPtr ip = NULL;
+ virNetDevIPAddrPtr ip = NULL;

if (VIR_ALLOC(ip) < 0)
return -1;
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index 135f7bd..63c6e76 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -2020,12 +2020,12 @@ networkStartHandleMACTableManagerMode(virNetworkObjPtr network,
/* add an IP (static) route to a bridge */
static int
networkAddRouteToBridge(virNetworkObjPtr network,
- virNetworkRouteDefPtr routedef)
+ virNetDevIPRoutePtr routedef)
{
- int prefix = virNetworkRouteDefGetPrefix(routedef);
- unsigned int metric = virNetworkRouteDefGetMetric(routedef);
- virSocketAddrPtr addr = virNetworkRouteDefGetAddress(routedef);
- virSocketAddrPtr gateway = virNetworkRouteDefGetGateway(routedef);
+ int prefix = virNetDevIPRouteGetPrefix(routedef);
+ unsigned int metric = virNetDevIPRouteGetMetric(routedef);
+ virSocketAddrPtr addr = virNetDevIPRouteGetAddress(routedef);
+ virSocketAddrPtr gateway = virNetDevIPRouteGetGateway(routedef);

if (prefix < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -2076,7 +2076,7 @@ networkStartNetworkVirtual(virNetworkDriverStatePtr driver,
bool v4present = false, v6present = false;
virErrorPtr save_err = NULL;
virNetworkIPDefPtr ipdef;
- virNetworkRouteDefPtr routedef;
+ virNetDevIPRoutePtr routedef;
char *macTapIfName = NULL;
int tapfd = -1;

@@ -2171,7 +2171,7 @@ networkStartNetworkVirtual(virNetworkDriverStatePtr driver,
virSocketAddrPtr gateway = NULL;

routedef = network->def->routes[i];
- gateway = virNetworkRouteDefGetGateway(routedef);
+ gateway = virNetDevIPRouteGetGateway(routedef);

/* Add the IP route to the bridge */
/* ignore errors, error msg will be generated */
diff --git a/src/network/bridge_driver_linux.c b/src/network/bridge_driver_linux.c
index b41a1ba..3effcdc 100644
--- a/src/network/bridge_driver_linux.c
+++ b/src/network/bridge_driver_linux.c
@@ -69,7 +69,7 @@ int networkCheckRouteCollision(virNetworkDefPtr def)
char iface[17], dest[128], mask[128];
unsigned int addr_val, mask_val;
virNetworkIPDefPtr ipdef;
- virNetworkRouteDefPtr routedef;
+ virNetDevIPRoutePtr routedef;
int num;
size_t i;

@@ -130,8 +130,8 @@ int networkCheckRouteCollision(virNetworkDefPtr def)
i++) {

virSocketAddr r_mask, r_addr;
- virSocketAddrPtr tmp_addr = virNetworkRouteDefGetAddress(routedef);
- int r_prefix = virNetworkRouteDefGetPrefix(routedef);
+ virSocketAddrPtr tmp_addr = virNetDevIPRouteGetAddress(routedef);
+ int r_prefix = virNetDevIPRouteGetPrefix(routedef);

if (!tmp_addr ||
virSocketAddrMaskByPrefix(tmp_addr, r_prefix, &r_addr) < 0 ||
diff --git a/src/util/virnetdevip.c b/src/util/virnetdevip.c
index 044f2bc..619f926 100644
--- a/src/util/virnetdevip.c
+++ b/src/util/virnetdevip.c
@@ -776,3 +776,72 @@ virNetDevIPAddrGet(const char *ifname,
_("Unable to get IP address on this platform"));
return -1;
}
+
+/* manipulating the virNetDevIPRoute object */
+void
+virNetDevIPRouteFree(virNetDevIPRoutePtr def)
+{
+ if (!def)
+ return;
+ VIR_FREE(def->family);
+ VIR_FREE(def);
+}
+
+virSocketAddrPtr
+virNetDevIPRouteGetAddress(virNetDevIPRoutePtr def)
+{
+ if (def)
+ return &def->address;
+
+ return NULL;
+}
+
+int
+virNetDevIPRouteGetPrefix(virNetDevIPRoutePtr def)
+{
+ int prefix = 0;
+ virSocketAddr zero;
+
+ if (!def)
+ return -1;
+
+ /* this creates an all-0 address of the appropriate family */
+ ignore_value(virSocketAddrParse(&zero,
+ (VIR_SOCKET_ADDR_IS_FAMILY(&def->address, AF_INET)
+ ? VIR_SOCKET_ADDR_IPV4_ALL
+ : VIR_SOCKET_ADDR_IPV6_ALL),
+ VIR_SOCKET_ADDR_FAMILY(&def->address)));
+
+ if (virSocketAddrEqual(&def->address, &zero)) {
+ if (def->has_prefix && def->prefix == 0)
+ prefix = 0;
+ else if ((VIR_SOCKET_ADDR_IS_FAMILY(&def->netmask, AF_INET) &&
+ virSocketAddrEqual(&def->netmask, &zero)))
+ prefix = 0;
+ else
+ prefix = virSocketAddrGetIPPrefix(&def->address, &def->netmask,
+ def->prefix);
+ } else {
+ prefix = virSocketAddrGetIPPrefix(&def->address, &def->netmask,
+ def->prefix);
+ }
+
+ return prefix;
+}
+
+unsigned int
+virNetDevIPRouteGetMetric(virNetDevIPRoutePtr def)
+{
+ if (def && def->has_metric && def->metric > 0)
+ return def->metric;
+
+ return 1;
+}
+
+virSocketAddrPtr
+virNetDevIPRouteGetGateway(virNetDevIPRoutePtr def)
+{
+ if (def)
+ return &def->gateway;
+ return NULL;
+}
diff --git a/src/util/virnetdevip.h b/src/util/virnetdevip.h
index f60465d..7a07b73 100644
--- a/src/util/virnetdevip.h
+++ b/src/util/virnetdevip.h
@@ -25,6 +25,28 @@

# include "virsocketaddr.h"

+typedef struct {
+ virSocketAddr address; /* ipv4 or ipv6 address */
+ unsigned int prefix; /* number of 1 bits in the net mask */
+} virNetDevIPAddr, *virNetDevIPAddrPtr;
+
+typedef struct {
+ char *family; /* ipv4 or ipv6 - default is ipv4 */
+ virSocketAddr address; /* Routed Network IP address */
+
+ /* One or the other of the following two will be used for a given
+ * Network address, but never both. The parser guarantees this.
+ * The virSocketAddrGetIPPrefix() can be used to get a
+ * valid prefix.
+ */
+ virSocketAddr netmask; /* ipv4 - either netmask or prefix specified */
+ unsigned int prefix; /* ipv6 - only prefix allowed */
+ bool has_prefix; /* prefix= was specified */
+ unsigned int metric; /* value for metric (defaults to 1) */
+ bool has_metric; /* metric= was specified */
+ virSocketAddr gateway; /* gateway IP address for ip-route */
+} virNetDevIPRoute, *virNetDevIPRoutePtr;
+
/* manipulating/querying the netdev */
int virNetDevIPAddrAdd(const char *ifname,
virSocketAddr *addr,
@@ -47,4 +69,11 @@ int virNetDevIPAddrGet(const char *ifname, virSocketAddrPtr addr)
int virNetDevIPWaitDadFinish(virSocketAddrPtr *addrs, size_t count)
ATTRIBUTE_NONNULL(1);

+/* virNetDevIPRoute object */
+void virNetDevIPRouteFree(virNetDevIPRoutePtr def);
+virSocketAddrPtr virNetDevIPRouteGetAddress(virNetDevIPRoutePtr def);
+int virNetDevIPRouteGetPrefix(virNetDevIPRoutePtr def);
+unsigned int virNetDevIPRouteGetMetric(virNetDevIPRoutePtr def);
+virSocketAddrPtr virNetDevIPRouteGetGateway(virNetDevIPRoutePtr def);
+
#endif /* __VIR_NETDEVIP_H__ */
--
2.5.5
John Ferlan
2016-06-24 11:11:17 UTC
Permalink
Post by Laine Stump
These functions all need to be called from a utility function that
must be located in the util directory, so we move them all into
util/virnetdevip.[ch] now that it exists.
Function and struct names were appropriately changed for the new
location, but all code is unchanged aside from motion and renaming.
---
src/conf/domain_conf.c | 36 ++++++-------
src/conf/domain_conf.h | 16 ++----
src/conf/network_conf.c | 16 +++---
src/conf/network_conf.h | 4 +-
src/conf/networkcommon_conf.c | 107 ++++----------------------------------
src/conf/networkcommon_conf.h | 55 +++++++-------------
src/libvirt_private.syms | 16 +++---
src/lxc/lxc_container.c | 12 ++---
src/lxc/lxc_native.c | 12 ++---
src/network/bridge_driver.c | 14 ++---
src/network/bridge_driver_linux.c | 6 +--
src/util/virnetdevip.c | 69 ++++++++++++++++++++++++
src/util/virnetdevip.h | 29 +++++++++++
13 files changed, 191 insertions(+), 201 deletions(-)
The one naming thing that "could" have changed as well is to keep the
"Def" portion (virNetDevIPRouteDefFree, virNetDevIPRouteDefParseXML,
virNetDevIPRouteDefFormat, virNetDevIPRouteDefCreate). Generally I'd
say it's a coin flip, but to be consistent since they're handling the
virNetworkRouteDefPtr, then I guess without "knowing" the API names I'd
start searching "NetworkRouteDef{Parse|Format}" in order to find the
code that dealt with it (the libvirt consistency argument).

Maybe they'll happen in a later patch, but why not move the Create,
Parse and Format routines as well? That'd remove networkcommon_conf it
seems. Could really gone for overkill and generated
virnetdeviproute.{h,c} ~/~
Post by Laine Stump
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 4802e03..f380271 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
[...]
Post by Laine Stump
@@ -6266,9 +6266,9 @@ virDomainHostdevDefParseXMLCaps(xmlNodePtr node ATTRIBUTE_UNUSED,
if (nroutenodes) {
size_t i;
for (i = 0; i < nroutenodes; i++) {
- virNetworkRouteDefPtr route = NULL;
+ virNetDevIPRoutePtr route = NULL;
- if (!(route = virNetworkRouteDefParseXML(_("Domain hostdev device"),
+ if (!(route = virNetDevIPRouteParseXML(_("Domain hostdev device"),
routenodes[i],
ctxt)))
The arguments need vertical alignment on line 2 and 3 under the _...

[...]
Post by Laine Stump
@@ -8955,9 +8955,9 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
int ret, val;
size_t i;
size_t nips = 0;
- virDomainNetIPDefPtr *ips = NULL;
+ virNetDevIPAddrPtr *ips = NULL;
size_t nroutes = 0;
- virNetworkRouteDefPtr *routes = NULL;
+ virNetDevIPRoutePtr *routes = NULL;
if (VIR_ALLOC(def) < 0)
return NULL;
@@ -9074,7 +9074,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
ctxt->node = tmpnode;
}
} else if (xmlStrEqual(cur->name, BAD_CAST "ip")) {
- virDomainNetIPDefPtr ip = NULL;
+ virNetDevIPAddrPtr ip = NULL;
if (!(ip = virDomainNetIPParseXML(cur)))
goto error;
@@ -9082,13 +9082,13 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
if (VIR_APPEND_ELEMENT(ips, nips, ip) < 0)
goto error;
} else if (xmlStrEqual(cur->name, BAD_CAST "route")) {
- virNetworkRouteDefPtr route = NULL;
- if (!(route = virNetworkRouteDefParseXML(_("Domain interface"),
+ virNetDevIPRoutePtr route = NULL;
+ if (!(route = virNetDevIPRouteParseXML(_("Domain interface"),
cur, ctxt)))
Vertical alignment...


[...]
Post by Laine Stump
/* Used for prefix of ifname of any network name generated dynamically
diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index 5ae2bdf..fb2a48d 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
[...]
Post by Laine Stump
@@ -2261,9 +2261,9 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt)
goto error;
/* parse each definition */
for (i = 0; i < nRoutes; i++) {
- virNetworkRouteDefPtr route = NULL;
+ virNetDevIPRoutePtr route = NULL;
- if (!(route = virNetworkRouteDefParseXML(def->name,
+ if (!(route = virNetDevIPRouteParseXML(def->name,
routeNodes[i],
ctxt)))
Vertical alignment

[...]
Post by Laine Stump
--- a/src/conf/networkcommon_conf.c
+++ b/src/conf/networkcommon_conf.c
@@ -32,34 +32,8 @@
[...]
Post by Laine Stump
-virNetworkRouteDefPtr
-virNetworkRouteDefCreate(const char *errorDetail,
+virNetDevIPRoutePtr
+virNetDevIPRouteCreate(const char *errorDetail,
char *family,
const char *address,
const char *netmask,
@@ -69,7 +43,7 @@ virNetworkRouteDefCreate(const char *errorDetail,
unsigned int metric,
bool hasMetric)
Vertical alignment
Post by Laine Stump
{
- virNetworkRouteDefPtr def = NULL;
+ virNetDevIPRoutePtr def = NULL;
virSocketAddr testAddr;
if (VIR_ALLOC(def) < 0)
@@ -242,21 +216,21 @@ virNetworkRouteDefCreate(const char *errorDetail,
return def;
- virNetworkRouteDefFree(def);
+ virNetDevIPRouteFree(def);
return NULL;
}
-virNetworkRouteDefPtr
-virNetworkRouteDefParseXML(const char *errorDetail,
+virNetDevIPRoutePtr
+virNetDevIPRouteParseXML(const char *errorDetail,
xmlNodePtr node,
xmlXPathContextPtr ctxt)
Vertical alignment
Post by Laine Stump
{
/*
- * virNetworkRouteDef object is already allocated as part
+ * virNetDevIPRoute object is already allocated as part
* of an array. On failure clear: it out, but don't free it.
*/
- virNetworkRouteDefPtr def = NULL;
+ virNetDevIPRoutePtr def = NULL;
xmlNodePtr save;
char *family = NULL;
char *address = NULL, *netmask = NULL;
@@ -302,7 +276,7 @@ virNetworkRouteDefParseXML(const char *errorDetail,
}
}
- def = virNetworkRouteDefCreate(errorDetail, family, address, netmask,
+ def = virNetDevIPRouteCreate(errorDetail, family, address, netmask,
gateway, prefix, hasPrefix, metric,
hasMetric);
Vertical alignment
Post by Laine Stump
@@ -316,8 +290,8 @@ virNetworkRouteDefParseXML(const char *errorDetail,
}
int
-virNetworkRouteDefFormat(virBufferPtr buf,
- const virNetworkRouteDef *def)
+virNetDevIPRouteFormat(virBufferPtr buf,
+ const virNetDevIPRoute *def)
Vertical alignment


[...]
Post by Laine Stump
diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c
index 9ad1b08..8294d29 100644
--- a/src/lxc/lxc_native.c
+++ b/src/lxc/lxc_native.c
@@ -419,7 +419,7 @@ typedef struct {
char *macvlanmode;
char *vlanid;
char *name;
- virDomainNetIPDefPtr *ips;
+ virNetDevIPAddrPtr *ips;
size_t nips;
char *gateway_ipv4;
char *gateway_ipv6;
@@ -430,10 +430,10 @@ typedef struct {
static int
lxcAddNetworkRouteDefinition(const char *address,
int family,
- virNetworkRouteDefPtr **routes,
+ virNetDevIPRoutePtr **routes,
size_t *nroutes)
{
- virNetworkRouteDefPtr route = NULL;
+ virNetDevIPRoutePtr route = NULL;
char *familyStr = NULL;
char *zero = NULL;
@@ -444,7 +444,7 @@ lxcAddNetworkRouteDefinition(const char *address,
if (VIR_STRDUP(familyStr, family == AF_INET ? "ipv4" : "ipv6") < 0)
goto error;
- if (!(route = virNetworkRouteDefCreate(_("Domain interface"), familyStr,
+ if (!(route = virNetDevIPRouteCreate(_("Domain interface"), familyStr,
zero, NULL, address, 0, false,
0, false)))
Vertical alignment
Post by Laine Stump
goto error;
@@ -460,7 +460,7 @@ lxcAddNetworkRouteDefinition(const char *address,
[...]


ACK - I think the Def should be added back in and the vertical alignment
things fixed. A quick scan from yesterday and I found just one instance
in patch 2, src/conf/interface_conf.c for _virInterfaceDef and the
comment column off by 1 vertical char (no big deal).

John
Laine Stump
2016-06-24 20:23:55 UTC
Permalink
Post by John Ferlan
Post by Laine Stump
These functions all need to be called from a utility function that
must be located in the util directory, so we move them all into
util/virnetdevip.[ch] now that it exists.
Function and struct names were appropriately changed for the new
location, but all code is unchanged aside from motion and renaming.
---
src/conf/domain_conf.c | 36 ++++++-------
src/conf/domain_conf.h | 16 ++----
src/conf/network_conf.c | 16 +++---
src/conf/network_conf.h | 4 +-
src/conf/networkcommon_conf.c | 107 ++++----------------------------------
src/conf/networkcommon_conf.h | 55 +++++++-------------
src/libvirt_private.syms | 16 +++---
src/lxc/lxc_container.c | 12 ++---
src/lxc/lxc_native.c | 12 ++---
src/network/bridge_driver.c | 14 ++---
src/network/bridge_driver_linux.c | 6 +--
src/util/virnetdevip.c | 69 ++++++++++++++++++++++++
src/util/virnetdevip.h | 29 +++++++++++
13 files changed, 191 insertions(+), 201 deletions(-)
The one naming thing that "could" have changed as well is to keep the
"Def" portion (virNetDevIPRouteDefFree, virNetDevIPRouteDefParseXML,
virNetDevIPRouteDefFormat, virNetDevIPRouteDefCreate). Generally I'd
say it's a coin flip, but to be consistent since they're handling the
virNetworkRouteDefPtr, then I guess without "knowing" the API names I'd
start searching "NetworkRouteDef{Parse|Format}" in order to find the
code that dealt with it (the libvirt consistency argument).
But when the structures get below a certain level of complexity (or
maybe it's that they're nested deep enough, dunno), they tend to lose
the Def suffix - virNetDevBandwith, virNetDevVlan virDomainDeviceInfo
virNetDevVPortProfile...
Post by John Ferlan
Maybe they'll happen in a later patch, but why not move the Create,
Parse and Format routines as well?
except that Parse and Format functions are traditionally kept in the
conf directory. As for the Create, I remember thinking about that one,
but on the first glance it just had so much test that it seemed more
like something from the conf directory. Probably not the right choice,
but I can make a patch to move it later.
Post by John Ferlan
That'd remove networkcommon_conf it
seems. Could really gone for overkill and generated
virnetdeviproute.{h,c} ~/~
Yeah, there's a few gigantic files, then several tiny ones. It would be
nice if they were all in the middle somewhere.
Post by John Ferlan
Post by Laine Stump
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 4802e03..f380271 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
[...]
Post by Laine Stump
@@ -6266,9 +6266,9 @@ virDomainHostdevDefParseXMLCaps(xmlNodePtr node ATTRIBUTE_UNUSED,
if (nroutenodes) {
size_t i;
for (i = 0; i < nroutenodes; i++) {
- virNetworkRouteDefPtr route = NULL;
+ virNetDevIPRoutePtr route = NULL;
- if (!(route = virNetworkRouteDefParseXML(_("Domain hostdev device"),
+ if (!(route = virNetDevIPRouteParseXML(_("Domain hostdev device"),
routenodes[i],
ctxt)))
The arguments need vertical alignment on line 2 and 3 under the _...
[...]
Post by Laine Stump
@@ -8955,9 +8955,9 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
int ret, val;
size_t i;
size_t nips = 0;
- virDomainNetIPDefPtr *ips = NULL;
+ virNetDevIPAddrPtr *ips = NULL;
size_t nroutes = 0;
- virNetworkRouteDefPtr *routes = NULL;
+ virNetDevIPRoutePtr *routes = NULL;
if (VIR_ALLOC(def) < 0)
return NULL;
@@ -9074,7 +9074,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
ctxt->node = tmpnode;
}
} else if (xmlStrEqual(cur->name, BAD_CAST "ip")) {
- virDomainNetIPDefPtr ip = NULL;
+ virNetDevIPAddrPtr ip = NULL;
if (!(ip = virDomainNetIPParseXML(cur)))
goto error;
@@ -9082,13 +9082,13 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
if (VIR_APPEND_ELEMENT(ips, nips, ip) < 0)
goto error;
} else if (xmlStrEqual(cur->name, BAD_CAST "route")) {
- virNetworkRouteDefPtr route = NULL;
- if (!(route = virNetworkRouteDefParseXML(_("Domain interface"),
+ virNetDevIPRoutePtr route = NULL;
+ if (!(route = virNetDevIPRouteParseXML(_("Domain interface"),
cur, ctxt)))
Vertical alignment...
[...]
Post by Laine Stump
/* Used for prefix of ifname of any network name generated dynamically
diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index 5ae2bdf..fb2a48d 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
[...]
Post by Laine Stump
@@ -2261,9 +2261,9 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt)
goto error;
/* parse each definition */
for (i = 0; i < nRoutes; i++) {
- virNetworkRouteDefPtr route = NULL;
+ virNetDevIPRoutePtr route = NULL;
- if (!(route = virNetworkRouteDefParseXML(def->name,
+ if (!(route = virNetDevIPRouteParseXML(def->name,
routeNodes[i],
ctxt)))
Vertical alignment
[...]
Post by Laine Stump
--- a/src/conf/networkcommon_conf.c
+++ b/src/conf/networkcommon_conf.c
@@ -32,34 +32,8 @@
[...]
Post by Laine Stump
-virNetworkRouteDefPtr
-virNetworkRouteDefCreate(const char *errorDetail,
+virNetDevIPRoutePtr
+virNetDevIPRouteCreate(const char *errorDetail,
char *family,
const char *address,
const char *netmask,
@@ -69,7 +43,7 @@ virNetworkRouteDefCreate(const char *errorDetail,
unsigned int metric,
bool hasMetric)
Vertical alignment
Post by Laine Stump
{
- virNetworkRouteDefPtr def = NULL;
+ virNetDevIPRoutePtr def = NULL;
virSocketAddr testAddr;
if (VIR_ALLOC(def) < 0)
@@ -242,21 +216,21 @@ virNetworkRouteDefCreate(const char *errorDetail,
return def;
- virNetworkRouteDefFree(def);
+ virNetDevIPRouteFree(def);
return NULL;
}
-virNetworkRouteDefPtr
-virNetworkRouteDefParseXML(const char *errorDetail,
+virNetDevIPRoutePtr
+virNetDevIPRouteParseXML(const char *errorDetail,
xmlNodePtr node,
xmlXPathContextPtr ctxt)
Vertical alignment
Post by Laine Stump
{
/*
- * virNetworkRouteDef object is already allocated as part
+ * virNetDevIPRoute object is already allocated as part
* of an array. On failure clear: it out, but don't free it.
*/
- virNetworkRouteDefPtr def = NULL;
+ virNetDevIPRoutePtr def = NULL;
xmlNodePtr save;
char *family = NULL;
char *address = NULL, *netmask = NULL;
@@ -302,7 +276,7 @@ virNetworkRouteDefParseXML(const char *errorDetail,
}
}
- def = virNetworkRouteDefCreate(errorDetail, family, address, netmask,
+ def = virNetDevIPRouteCreate(errorDetail, family, address, netmask,
gateway, prefix, hasPrefix, metric,
hasMetric);
Vertical alignment
Post by Laine Stump
@@ -316,8 +290,8 @@ virNetworkRouteDefParseXML(const char *errorDetail,
}
int
-virNetworkRouteDefFormat(virBufferPtr buf,
- const virNetworkRouteDef *def)
+virNetDevIPRouteFormat(virBufferPtr buf,
+ const virNetDevIPRoute *def)
Vertical alignment
[...]
Post by Laine Stump
diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c
index 9ad1b08..8294d29 100644
--- a/src/lxc/lxc_native.c
+++ b/src/lxc/lxc_native.c
@@ -419,7 +419,7 @@ typedef struct {
char *macvlanmode;
char *vlanid;
char *name;
- virDomainNetIPDefPtr *ips;
+ virNetDevIPAddrPtr *ips;
size_t nips;
char *gateway_ipv4;
char *gateway_ipv6;
@@ -430,10 +430,10 @@ typedef struct {
static int
lxcAddNetworkRouteDefinition(const char *address,
int family,
- virNetworkRouteDefPtr **routes,
+ virNetDevIPRoutePtr **routes,
size_t *nroutes)
{
- virNetworkRouteDefPtr route = NULL;
+ virNetDevIPRoutePtr route = NULL;
char *familyStr = NULL;
char *zero = NULL;
@@ -444,7 +444,7 @@ lxcAddNetworkRouteDefinition(const char *address,
if (VIR_STRDUP(familyStr, family == AF_INET ? "ipv4" : "ipv6") < 0)
goto error;
- if (!(route = virNetworkRouteDefCreate(_("Domain interface"), familyStr,
+ if (!(route = virNetDevIPRouteCreate(_("Domain interface"), familyStr,
zero, NULL, address, 0, false,
0, false)))
Vertical alignment
Post by Laine Stump
goto error;
@@ -460,7 +460,7 @@ lxcAddNetworkRouteDefinition(const char *address,
[...]
ACK - I think the Def should be added back in and the vertical alignment
things fixed. A quick scan from yesterday and I found just one instance
in patch 2, src/conf/interface_conf.c for _virInterfaceDef and the
comment column off by 1 vertical char (no big deal).
John
John Ferlan
2016-06-24 20:38:27 UTC
Permalink
Post by Laine Stump
Post by John Ferlan
Post by Laine Stump
These functions all need to be called from a utility function that
must be located in the util directory, so we move them all into
util/virnetdevip.[ch] now that it exists.
Function and struct names were appropriately changed for the new
location, but all code is unchanged aside from motion and renaming.
---
src/conf/domain_conf.c | 36 ++++++-------
src/conf/domain_conf.h | 16 ++----
src/conf/network_conf.c | 16 +++---
src/conf/network_conf.h | 4 +-
src/conf/networkcommon_conf.c | 107
++++----------------------------------
src/conf/networkcommon_conf.h | 55 +++++++-------------
src/libvirt_private.syms | 16 +++---
src/lxc/lxc_container.c | 12 ++---
src/lxc/lxc_native.c | 12 ++---
src/network/bridge_driver.c | 14 ++---
src/network/bridge_driver_linux.c | 6 +--
src/util/virnetdevip.c | 69 ++++++++++++++++++++++++
src/util/virnetdevip.h | 29 +++++++++++
13 files changed, 191 insertions(+), 201 deletions(-)
The one naming thing that "could" have changed as well is to keep the
"Def" portion (virNetDevIPRouteDefFree, virNetDevIPRouteDefParseXML,
virNetDevIPRouteDefFormat, virNetDevIPRouteDefCreate). Generally I'd
say it's a coin flip, but to be consistent since they're handling the
virNetworkRouteDefPtr, then I guess without "knowing" the API names I'd
start searching "NetworkRouteDef{Parse|Format}" in order to find the
code that dealt with it (the libvirt consistency argument).
But when the structures get below a certain level of complexity (or
maybe it's that they're nested deep enough, dunno), they tend to lose
the Def suffix - virNetDevBandwith, virNetDevVlan virDomainDeviceInfo
virNetDevVPortProfile...
OK nm then... It was just one of those consistency things.

John
Laine Stump
2016-06-22 17:37:15 UTC
Permalink
a.k.a. <hostdev mode='capabilities' type='net'>.

This replaces the existing nips, ips, nroutes, and routes with a
single virNetDevIPInfo, and simplifies the code by calling that
object's parse/format/clear functions instead of open coding.
---
docs/schemas/domaincommon.rng | 22 +-----------
src/conf/domain_conf.c | 80 ++++++-------------------------------------
src/conf/domain_conf.h | 7 ++--
src/lxc/lxc_controller.c | 2 +-
src/lxc/lxc_native.c | 18 +++++-----
5 files changed, 24 insertions(+), 105 deletions(-)

diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index ab89dab..38590a6 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -4034,27 +4034,7 @@
<ref name="deviceName"/>
</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>
- <zeroOrMore>
- <ref name="route"/>
- </zeroOrMore>
+ <ref name="interface-ip-info"/>
</interleave>
</define>

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 548c750..7072f86 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -2184,8 +2184,6 @@ virDomainHostdevSubsysSCSIiSCSIClear(virDomainHostdevSubsysSCSIiSCSIPtr iscsisrc

void virDomainHostdevDefClear(virDomainHostdevDefPtr def)
{
- size_t i;
-
if (!def)
return;

@@ -2209,13 +2207,8 @@ void virDomainHostdevDefClear(virDomainHostdevDefPtr def)
VIR_FREE(def->source.caps.u.misc.chardev);
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);
- for (i = 0; i < def->source.caps.u.net.nroutes; i++)
- virNetDevIPRouteFree(def->source.caps.u.net.routes[i]);
- VIR_FREE(def->source.caps.u.net.routes);
+ VIR_FREE(def->source.caps.u.net.ifname);
+ virNetDevIPInfoClear(&def->source.caps.u.net.ip);
break;
}
break;
@@ -6232,10 +6225,6 @@ virDomainHostdevDefParseXMLCaps(xmlNodePtr node ATTRIBUTE_UNUSED,
virDomainHostdevDefPtr def)
{
xmlNodePtr sourcenode;
- xmlNodePtr *ipnodes = NULL;
- int nipnodes;
- xmlNodePtr *routenodes = NULL;
- int nroutenodes;
int ret = -1;

/* @type is passed in from the caller rather than read from the
@@ -6284,55 +6273,15 @@ virDomainHostdevDefParseXMLCaps(xmlNodePtr node ATTRIBUTE_UNUSED,
}
break;
case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET:
- if (!(def->source.caps.u.net.iface =
+ if (!(def->source.caps.u.net.ifname =
virXPathString("string(./source/interface[1])", ctxt))) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("Missing <interface> element in hostdev net device"));
goto error;
}
-
- /* Parse possible IP addresses */
- if ((nipnodes = virXPathNodeSet("./ip", ctxt, &ipnodes)) < 0)
+ if (virDomainNetIPInfoParseXML(_("Domain hostdev device"),
+ ctxt, &def->source.caps.u.net.ip) < 0)
goto error;
-
- if (nipnodes) {
- size_t i;
- for (i = 0; i < nipnodes; i++) {
- virNetDevIPAddrPtr 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;
- }
- }
- }
-
- /* Look for possible gateways */
- if ((nroutenodes = virXPathNodeSet("./route", ctxt, &routenodes)) < 0)
- goto error;
-
- if (nroutenodes) {
- size_t i;
- for (i = 0; i < nroutenodes; i++) {
- virNetDevIPRoutePtr route = NULL;
-
- if (!(route = virNetDevIPRouteParseXML(_("Domain hostdev device"),
- routenodes[i],
- ctxt)))
- goto error;
-
-
- if (VIR_APPEND_ELEMENT(def->source.caps.u.net.routes,
- def->source.caps.u.net.nroutes, route) < 0) {
- virNetDevIPRouteFree(route);
- goto error;
- }
- }
- }
break;
default:
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
@@ -6342,8 +6291,6 @@ virDomainHostdevDefParseXMLCaps(xmlNodePtr node ATTRIBUTE_UNUSED,
}
ret = 0;
error:
- VIR_FREE(ipnodes);
- VIR_FREE(routenodes);
return ret;
}

@@ -13722,8 +13669,8 @@ static int
virDomainHostdevMatchCapsNet(virDomainHostdevDefPtr a,
virDomainHostdevDefPtr b)
{
- return STREQ_NULLABLE(a->source.caps.u.net.iface,
- b->source.caps.u.net.iface);
+ return STREQ_NULLABLE(a->source.caps.u.net.ifname,
+ b->source.caps.u.net.ifname);
}


@@ -20519,7 +20466,7 @@ virDomainHostdevDefFormatCaps(virBufferPtr buf,
break;
case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET:
virBufferEscapeString(buf, "<interface>%s</interface>\n",
- def->source.caps.u.net.iface);
+ def->source.caps.u.net.ifname);
break;
default:
virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -20531,14 +20478,9 @@ virDomainHostdevDefFormatCaps(virBufferPtr buf,
virBufferAdjustIndent(buf, -2);
virBufferAddLit(buf, "</source>\n");

- if (def->source.caps.type == VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET) {
- if (virDomainNetIPsFormat(buf, def->source.caps.u.net.ips,
- def->source.caps.u.net.nips) < 0)
- return -1;
- if (virDomainNetRoutesFormat(buf, def->source.caps.u.net.routes,
- def->source.caps.u.net.nroutes) < 0)
- return -1;
- }
+ if (def->source.caps.type == VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET &&
+ virDomainNetIPInfoFormat(buf, &def->source.caps.u.net.ip) < 0)
+ return -1;

return 0;
}
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index c529b09..0c723de 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -395,11 +395,8 @@ struct _virDomainHostdevCaps {
char *chardev;
} misc;
struct {
- char *iface;
- size_t nips;
- virNetDevIPAddrPtr *ips;
- size_t nroutes;
- virNetDevIPRoutePtr *routes;
+ char *ifname;
+ virNetDevIPInfo ip;
} net;
} u;
};
diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c
index 2aee41c..e58ff1b 100644
--- a/src/lxc/lxc_controller.c
+++ b/src/lxc/lxc_controller.c
@@ -1984,7 +1984,7 @@ static int virLXCControllerMoveInterfaces(virLXCControllerPtr ctrl)
if (hdcaps.type != VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET)
continue;

- if (virNetDevSetNamespace(hdcaps.u.net.iface, ctrl->initpid) < 0)
+ if (virNetDevSetNamespace(hdcaps.u.net.ifname, ctrl->initpid) < 0)
return -1;
}

diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c
index 8294d29..f074f03 100644
--- a/src/lxc/lxc_native.c
+++ b/src/lxc/lxc_native.c
@@ -402,7 +402,7 @@ lxcCreateHostdevDef(int mode, int type, const char *data)
hostdev->source.caps.type = type;

if (type == VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET &&
- VIR_STRDUP(hostdev->source.caps.u.net.iface, data) < 0) {
+ VIR_STRDUP(hostdev->source.caps.u.net.ifname, data) < 0) {
virDomainHostdevDefFree(hostdev);
hostdev = NULL;
}
@@ -492,25 +492,25 @@ lxcAddNetworkDefinition(lxcNetworkParseData *data)
/* This still requires the user to manually setup the vlan interface
* on the host */
if (isVlan && data->vlanid) {
- VIR_FREE(hostdev->source.caps.u.net.iface);
- if (virAsprintf(&hostdev->source.caps.u.net.iface,
+ VIR_FREE(hostdev->source.caps.u.net.ifname);
+ if (virAsprintf(&hostdev->source.caps.u.net.ifname,
"%s.%s", data->link, data->vlanid) < 0)
goto error;
}

- hostdev->source.caps.u.net.ips = data->ips;
- hostdev->source.caps.u.net.nips = data->nips;
+ hostdev->source.caps.u.net.ip.ips = data->ips;
+ hostdev->source.caps.u.net.ip.nips = data->nips;

if (data->gateway_ipv4 &&
lxcAddNetworkRouteDefinition(data->gateway_ipv4, AF_INET,
- &hostdev->source.caps.u.net.routes,
- &hostdev->source.caps.u.net.nroutes) < 0)
+ &hostdev->source.caps.u.net.ip.routes,
+ &hostdev->source.caps.u.net.ip.nroutes) < 0)
goto error;

if (data->gateway_ipv6 &&
lxcAddNetworkRouteDefinition(data->gateway_ipv6, AF_INET6,
- &hostdev->source.caps.u.net.routes,
- &hostdev->source.caps.u.net.nroutes) < 0)
+ &hostdev->source.caps.u.net.ip.routes,
+ &hostdev->source.caps.u.net.ip.nroutes) < 0)
goto error;

if (VIR_EXPAND_N(data->def->hostdevs, data->def->nhostdevs, 1) < 0)
--
2.5.5
John Ferlan
2016-06-24 11:49:18 UTC
Permalink
Post by Laine Stump
a.k.a. <hostdev mode='capabilities' type='net'>.
This replaces the existing nips, ips, nroutes, and routes with a
single virNetDevIPInfo, and simplifies the code by calling that
object's parse/format/clear functions instead of open coding.
---
docs/schemas/domaincommon.rng | 22 +-----------
src/conf/domain_conf.c | 80 ++++++-------------------------------------
src/conf/domain_conf.h | 7 ++--
src/lxc/lxc_controller.c | 2 +-
src/lxc/lxc_native.c | 18 +++++-----
5 files changed, 24 insertions(+), 105 deletions(-)
ACK -

John
Laine Stump
2016-06-22 17:37:26 UTC
Permalink
---
src/lxc/lxc_process.c | 8 ++++++++
1 file changed, 8 insertions(+)

diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c
index 07eb22a..28313f0 100644
--- a/src/lxc/lxc_process.c
+++ b/src/lxc/lxc_process.c
@@ -304,6 +304,14 @@ virLXCProcessSetupInterfaceTap(virDomainDefPtr vm,
if (virNetDevSetOnline(parentVeth, true) < 0)
goto cleanup;

+ if (virDomainNetGetActualType(net) == VIR_DOMAIN_NET_TYPE_ETHERNET) {
+ /* Set IP info for the host side, but only if the type is
+ * 'ethernet'.
+ */
+ if (virNetDevIPInfoAddToDev(parentVeth, &net->hostIP) < 0)
+ goto cleanup;
+ }
+
if (net->filter &&
virDomainConfNWFilterInstantiate(vm->uuid, net) < 0)
goto cleanup;
--
2.5.5
John Ferlan
2016-06-24 13:54:35 UTC
Permalink
Post by Laine Stump
---
src/lxc/lxc_process.c | 8 ++++++++
1 file changed, 8 insertions(+)
ACK

John
Laine Stump
2016-06-22 17:37:22 UTC
Permalink
---
src/util/virnetdevip.c | 30 ++++++++++++++++++------------
1 file changed, 18 insertions(+), 12 deletions(-)

diff --git a/src/util/virnetdevip.c b/src/util/virnetdevip.c
index 6889f81..5daeed5 100644
--- a/src/util/virnetdevip.c
+++ b/src/util/virnetdevip.c
@@ -315,7 +315,6 @@ virNetDevIPRouteAdd(const char *ifname,

/* If we have no valid network address, then use the default one */
if (!addr || !VIR_SOCKET_ADDR_VALID(addr)) {
- VIR_DEBUG("computing default address");
int family = VIR_SOCKET_ADDR_FAMILY(gateway);
if (family == AF_INET) {
if (virSocketAddrParseIPv4(&defaultAddr, VIR_SOCKET_ADDR_IPV4_ALL) < 0)
@@ -328,9 +327,11 @@ virNetDevIPRouteAdd(const char *ifname,
actualAddr = &defaultAddr;
}

- toStr = virSocketAddrFormat(actualAddr);
- viaStr = virSocketAddrFormat(gateway);
- VIR_DEBUG("Adding route %s/%d via %s", toStr, prefix, viaStr);
+ if (!(toStr = virSocketAddrFormat(actualAddr)))
+ goto cleanup;
+ if (!(viaStr = virSocketAddrFormat(gateway)))
+ goto cleanup;
+ VIR_DEBUG("Adding route to %s/%u via %s on %s", toStr, prefix, viaStr, ifname);

if (virNetDevGetIPAddressBinary(actualAddr, &addrData, &addrDataLen) < 0 ||
virNetDevGetIPAddressBinary(gateway, &gatewayData, &addrDataLen) < 0)
@@ -376,7 +377,9 @@ virNetDevIPRouteAdd(const char *ifname,
goto cleanup;

if ((errCode = virNetlinkGetErrorCode(resp, recvbuflen)) < 0) {
- virReportSystemError(errCode, _("Error adding route to %s"), ifname);
+ virReportSystemError(errCode,
+ _("Error adding route to %s/%u via %s on %s"),
+ toStr, prefix, viaStr, ifname);
goto cleanup;
}

@@ -617,7 +620,8 @@ virNetDevIPRouteAdd(const char *ifname,
unsigned int metric)
{
virCommandPtr cmd = NULL;
- char *addrstr = NULL, *gatewaystr = NULL;
+ char *toStr = NULL;
+ char *viaStr = NULL;
virSocketAddr defaultAddr;
virSocketAddrPtr actualAddr;
int ret = -1;
@@ -638,14 +642,16 @@ virNetDevIPRouteAdd(const char *ifname,
actualAddr = &defaultAddr;
}

- if (!(addrstr = virSocketAddrFormat(actualAddr)))
+ if (!(toStr = virSocketAddrFormat(actualAddr)))
goto cleanup;
- if (!(gatewaystr = virSocketAddrFormat(gateway)))
+ if (!(viaStr = virSocketAddrFormat(gateway)))
goto cleanup;
+ VIR_DEBUG("Adding route to %s/%u via %s on %s", toStr, prefix, viaStr, ifname);
+
cmd = virCommandNew(IP_PATH);
virCommandAddArgList(cmd, "route", "add", NULL);
- virCommandAddArgFormat(cmd, "%s/%u", addrstr, prefix);
- virCommandAddArgList(cmd, "via", gatewaystr, "dev", ifname,
+ virCommandAddArgFormat(cmd, "%s/%u", toStr, prefix);
+ virCommandAddArgList(cmd, "via", viaStr, "dev", ifname,
"proto", "static", "metric", NULL);
virCommandAddArgFormat(cmd, "%u", metric);

@@ -654,8 +660,8 @@ virNetDevIPRouteAdd(const char *ifname,

ret = 0;
cleanup:
- VIR_FREE(addrstr);
- VIR_FREE(gatewaystr);
+ VIR_FREE(toStr);
+ VIR_FREE(viaStr);
virCommandFree(cmd);
return ret;
}
--
2.5.5
John Ferlan
2016-06-24 13:16:27 UTC
Permalink
Post by Laine Stump
---
src/util/virnetdevip.c | 30 ++++++++++++++++++------------
1 file changed, 18 insertions(+), 12 deletions(-)
diff --git a/src/util/virnetdevip.c b/src/util/virnetdevip.c
index 6889f81..5daeed5 100644
--- a/src/util/virnetdevip.c
+++ b/src/util/virnetdevip.c
@@ -315,7 +315,6 @@ virNetDevIPRouteAdd(const char *ifname,
/* If we have no valid network address, then use the default one */
if (!addr || !VIR_SOCKET_ADDR_VALID(addr)) {
- VIR_DEBUG("computing default address");
int family = VIR_SOCKET_ADDR_FAMILY(gateway);
if (family == AF_INET) {
if (virSocketAddrParseIPv4(&defaultAddr, VIR_SOCKET_ADDR_IPV4_ALL) < 0)
@@ -328,9 +327,11 @@ virNetDevIPRouteAdd(const char *ifname,
actualAddr = &defaultAddr;
}
- toStr = virSocketAddrFormat(actualAddr);
- viaStr = virSocketAddrFormat(gateway);
- VIR_DEBUG("Adding route %s/%d via %s", toStr, prefix, viaStr);
+ if (!(toStr = virSocketAddrFormat(actualAddr)))
+ goto cleanup;
+ if (!(viaStr = virSocketAddrFormat(gateway)))
+ goto cleanup;
+ VIR_DEBUG("Adding route to %s/%u via %s on %s", toStr, prefix, viaStr, ifname);
if (virNetDevGetIPAddressBinary(actualAddr, &addrData, &addrDataLen) < 0 ||
virNetDevGetIPAddressBinary(gateway, &gatewayData, &addrDataLen) < 0)
@@ -376,7 +377,9 @@ virNetDevIPRouteAdd(const char *ifname,
goto cleanup;
if ((errCode = virNetlinkGetErrorCode(resp, recvbuflen)) < 0) {
- virReportSystemError(errCode, _("Error adding route to %s"), ifname);
+ virReportSystemError(errCode,
+ _("Error adding route to %s/%u via %s on %s"),
+ toStr, prefix, viaStr, ifname);
goto cleanup;
}
@@ -617,7 +620,8 @@ virNetDevIPRouteAdd(const char *ifname,
unsigned int metric)
{
virCommandPtr cmd = NULL;
- char *addrstr = NULL, *gatewaystr = NULL;
+ char *toStr = NULL;
+ char *viaStr = NULL;
virSocketAddr defaultAddr;
virSocketAddrPtr actualAddr;
int ret = -1;
@@ -638,14 +642,16 @@ virNetDevIPRouteAdd(const char *ifname,
actualAddr = &defaultAddr;
}
- if (!(addrstr = virSocketAddrFormat(actualAddr)))
+ if (!(toStr = virSocketAddrFormat(actualAddr)))
goto cleanup;
- if (!(gatewaystr = virSocketAddrFormat(gateway)))
+ if (!(viaStr = virSocketAddrFormat(gateway)))
goto cleanup;
+ VIR_DEBUG("Adding route to %s/%u via %s on %s", toStr, prefix, viaStr, ifname);
+
cmd = virCommandNew(IP_PATH);
virCommandAddArgList(cmd, "route", "add", NULL);
- virCommandAddArgFormat(cmd, "%s/%u", addrstr, prefix);
- virCommandAddArgList(cmd, "via", gatewaystr, "dev", ifname,
+ virCommandAddArgFormat(cmd, "%s/%u", toStr, prefix);
+ virCommandAddArgList(cmd, "via", viaStr, "dev", ifname,
"proto", "static", "metric", NULL);
virCommandAddArgFormat(cmd, "%u", metric);
If you add "&exitstatus" as the 2nd parameter to virCommandRun, then you
can also add a message to the virCommandRun failure similar to the error
for the virNetlinkCommand failure.

Additionally adding virCommandSetOutputBuffer and/or
virCommandSetErrorBuffer can really help you become more verbose about
what the failure was.

ACK - with or without the virCommandRun adjustments - just figured I'd
note that this path does have an error path difference w/r/t verbosity
if there's an error that virNetlinkGetErrorCode finds...


John
Post by Laine Stump
@@ -654,8 +660,8 @@ virNetDevIPRouteAdd(const char *ifname,
ret = 0;
- VIR_FREE(addrstr);
- VIR_FREE(gatewaystr);
+ VIR_FREE(toStr);
+ VIR_FREE(viaStr);
virCommandFree(cmd);
return ret;
}
Laine Stump
2016-06-22 17:37:21 UTC
Permalink
The version of virNetDevIPRouteAdd() has a bit of code to create the
appropriate "0.0.0.0" or "::" virSocketAddr when the addr passed in is
NULL or invalid, but the alternate implementation (used on platforms
that don't support libnl) had no such code, making the two
implementations semantically diferent. This patch corrects that
oversight.
---
src/util/virnetdevip.c | 20 +++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/src/util/virnetdevip.c b/src/util/virnetdevip.c
index dad2a78..6889f81 100644
--- a/src/util/virnetdevip.c
+++ b/src/util/virnetdevip.c
@@ -618,9 +618,27 @@ virNetDevIPRouteAdd(const char *ifname,
{
virCommandPtr cmd = NULL;
char *addrstr = NULL, *gatewaystr = NULL;
+ virSocketAddr defaultAddr;
+ virSocketAddrPtr actualAddr;
int ret = -1;

- if (!(addrstr = virSocketAddrFormat(addr)))
+ actualAddr = addr;
+
+ /* If we have no valid network address, then use the default one */
+ if (!addr || !VIR_SOCKET_ADDR_VALID(addr)) {
+ int family = VIR_SOCKET_ADDR_FAMILY(gateway);
+ if (family == AF_INET) {
+ if (virSocketAddrParseIPv4(&defaultAddr, VIR_SOCKET_ADDR_IPV4_ALL) < 0)
+ goto cleanup;
+ } else {
+ if (virSocketAddrParseIPv6(&defaultAddr, VIR_SOCKET_ADDR_IPV6_ALL) < 0)
+ goto cleanup;
+ }
+
+ actualAddr = &defaultAddr;
+ }
+
+ if (!(addrstr = virSocketAddrFormat(actualAddr)))
goto cleanup;
if (!(gatewaystr = virSocketAddrFormat(gateway)))
goto cleanup;
--
2.5.5
John Ferlan
2016-06-24 13:08:41 UTC
Permalink
Post by Laine Stump
The version of virNetDevIPRouteAdd() has a bit of code to create the
appropriate "0.0.0.0" or "::" virSocketAddr when the addr passed in is
NULL or invalid, but the alternate implementation (used on platforms
that don't support libnl) had no such code, making the two
implementations semantically diferent. This patch corrects that
oversight.
---
src/util/virnetdevip.c | 20 +++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)
Seems like a reasonable and nice thing to do ... although you could
have written a helper routine to return the result of
virSocketAddrFormat based on actualAddr... Avoids duplicated code and
the chance that someone only changes one in the future.

Interesting side note - can gateway be invalid and family doesn't have
AF_INET, thus you create an IPv6 default address?

ACK - with the helper routine...

John
Laine Stump
2016-06-26 21:57:29 UTC
Permalink
Post by John Ferlan
Post by Laine Stump
The version of virNetDevIPRouteAdd() has a bit of code to create the
appropriate "0.0.0.0" or "::" virSocketAddr when the addr passed in is
NULL or invalid, but the alternate implementation (used on platforms
that don't support libnl) had no such code, making the two
implementations semantically diferent. This patch corrects that
oversight.
---
src/util/virnetdevip.c | 20 +++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)
Seems like a reasonable and nice thing to do ... although you could
have written a helper routine to return the result of
virSocketAddrFormat based on actualAddr... Avoids duplicated code and
the chance that someone only changes one in the future.
Interesting side note - can gateway be invalid and family doesn't have
AF_INET, thus you create an IPv6 default address?
ACK - with the helper routine...
I don't like the idea of a helper function that may or may not allocate
memory (makes it too easy for the callers to misunderstand), and I'm
thinking it may be better to just make a platform-agnostic
virNetDevIPRouteAdd() that has the common code followed by a call to
virNetDevIPRouteAddInternal() which would be defined different for each
platform. I don't feel like dealing with that right now though (I'd
rather get the rest of these pushed), so I'll drop this patch for now
and come back to it later.

Laine Stump
2016-06-22 17:37:02 UTC
Permalink
I'm tired of mistyping this all the time, so let's do it the same all
the time (similar to how we changed all "Pci" to "PCI" awhile back).

(NB: I've left alone some things in the esx and vbox drivers because
I'm unable to compile them and they weren't obviously *not* a part of
some API. I also didn't change a couple of variables named,
e.g. "somethingIptables", because they were derived from the name of
the "iptables" command)
---
src/conf/domain_conf.c | 24 +++++-----
src/conf/domain_conf.h | 12 ++---
src/conf/interface_conf.c | 38 +++++++--------
src/conf/interface_conf.h | 8 ++--
src/conf/network_conf.c | 80 +++++++++++++++----------------
src/conf/network_conf.h | 20 ++++----
src/conf/networkcommon_conf.c | 6 +--
src/esx/esx_driver.c | 44 ++++++++---------
src/esx/esx_interface_driver.c | 4 +-
src/esx/esx_vi.c | 4 +-
src/esx/esx_vi.h | 2 +-
src/libvirt_private.syms | 10 ++--
src/lxc/lxc_container.c | 2 +-
src/lxc/lxc_native.c | 4 +-
src/network/bridge_driver.c | 74 ++++++++++++++--------------
src/network/bridge_driver_linux.c | 70 +++++++++++++--------------
src/nwfilter/nwfilter_ebiptables_driver.c | 24 +++++-----
src/openvz/openvz_conf.c | 2 +-
src/qemu/qemu_driver.c | 2 +-
src/util/virsocketaddr.c | 4 +-
src/util/virsocketaddr.h | 2 +-
src/vbox/vbox_network.c | 8 ++--
src/xenconfig/xen_common.c | 2 +-
src/xenconfig/xen_sxpr.c | 4 +-
24 files changed, 225 insertions(+), 225 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 8ff836c..e57655e 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -6104,11 +6104,11 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node,
return ret;
}

-static virDomainNetIpDefPtr
-virDomainNetIpParseXML(xmlNodePtr node)
+static virDomainNetIPDefPtr
+virDomainNetIPParseXML(xmlNodePtr node)
{
/* Parse the prefix in every case */
- virDomainNetIpDefPtr ip = NULL, ret = NULL;
+ virDomainNetIPDefPtr ip = NULL, ret = NULL;
char *prefixStr = NULL;
unsigned int prefixValue = 0;
char *familyStr = NULL;
@@ -6230,7 +6230,7 @@ virDomainHostdevDefParseXMLCaps(xmlNodePtr node ATTRIBUTE_UNUSED,
if (nipnodes) {
size_t i;
for (i = 0; i < nipnodes; i++) {
- virDomainNetIpDefPtr ip = virDomainNetIpParseXML(ipnodes[i]);
+ virDomainNetIPDefPtr ip = virDomainNetIPParseXML(ipnodes[i]);

if (!ip)
goto error;
@@ -8862,12 +8862,12 @@ virDomainActualNetDefParseXML(xmlNodePtr node,


int
-virDomainNetAppendIpAddress(virDomainNetDefPtr def,
+virDomainNetAppendIPAddress(virDomainNetDefPtr def,
const char *address,
int family,
unsigned int prefix)
{
- virDomainNetIpDefPtr ipDef = NULL;
+ virDomainNetIPDefPtr ipDef = NULL;
if (VIR_ALLOC(ipDef) < 0)
return -1;

@@ -8939,7 +8939,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
int ret, val;
size_t i;
size_t nips = 0;
- virDomainNetIpDefPtr *ips = NULL;
+ virDomainNetIPDefPtr *ips = NULL;
size_t nroutes = 0;
virNetworkRouteDefPtr *routes = NULL;

@@ -9039,9 +9039,9 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
ctxt->node = tmpnode;
}
} else if (xmlStrEqual(cur->name, BAD_CAST "ip")) {
- virDomainNetIpDefPtr ip = NULL;
+ virDomainNetIPDefPtr ip = NULL;

- if (!(ip = virDomainNetIpParseXML(cur)))
+ if (!(ip = virDomainNetIPParseXML(cur)))
goto error;

if (VIR_APPEND_ELEMENT(ips, nips, ip) < 0)
@@ -20239,7 +20239,7 @@ virDomainFSDefFormat(virBufferPtr buf,
}

static int
-virDomainNetIpsFormat(virBufferPtr buf, virDomainNetIpDefPtr *ips, size_t nips)
+virDomainNetIPsFormat(virBufferPtr buf, virDomainNetIPDefPtr *ips, size_t nips)
{
size_t i;

@@ -20433,7 +20433,7 @@ virDomainHostdevDefFormatCaps(virBufferPtr buf,
virBufferAddLit(buf, "</source>\n");

if (def->source.caps.type == VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET) {
- if (virDomainNetIpsFormat(buf, def->source.caps.u.net.ips,
+ if (virDomainNetIPsFormat(buf, def->source.caps.u.net.ips,
def->source.caps.u.net.nips) < 0)
return -1;
if (virDomainNetRoutesFormat(buf, def->source.caps.u.net.routes,
@@ -20852,7 +20852,7 @@ virDomainNetDefFormat(virBufferPtr buf,
return -1;
}

- if (virDomainNetIpsFormat(buf, def->ips, def->nips) < 0)
+ if (virDomainNetIPsFormat(buf, def->ips, def->nips) < 0)
return -1;
if (virDomainNetRoutesFormat(buf, def->routes, def->nroutes) < 0)
return -1;
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 6e81e52..8529a78 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -382,9 +382,9 @@ typedef enum {
VIR_DOMAIN_HOSTDEV_CAPS_TYPE_LAST
} virDomainHostdevCapsType;

-typedef struct _virDomainNetIpDef virDomainNetIpDef;
-typedef virDomainNetIpDef *virDomainNetIpDefPtr;
-struct _virDomainNetIpDef {
+typedef struct _virDomainNetIPDef virDomainNetIPDef;
+typedef virDomainNetIPDef *virDomainNetIPDefPtr;
+struct _virDomainNetIPDef {
virSocketAddr address; /* ipv4 or ipv6 address */
unsigned int prefix; /* number of 1 bits in the net mask */
};
@@ -403,7 +403,7 @@ struct _virDomainHostdevCaps {
struct {
char *iface;
size_t nips;
- virDomainNetIpDefPtr *ips;
+ virDomainNetIPDefPtr *ips;
size_t nroutes;
virNetworkRouteDefPtr *routes;
} net;
@@ -986,7 +986,7 @@ struct _virDomainNetDef {
int trustGuestRxFilters; /* enum virTristateBool */
int linkstate;
size_t nips;
- virDomainNetIpDefPtr *ips;
+ virDomainNetIPDefPtr *ips;
size_t nroutes;
virNetworkRouteDefPtr *routes;
};
@@ -2775,7 +2775,7 @@ virNetDevBandwidthPtr
virDomainNetGetActualBandwidth(virDomainNetDefPtr iface);
virNetDevVlanPtr virDomainNetGetActualVlan(virDomainNetDefPtr iface);
bool virDomainNetGetActualTrustGuestRxFilters(virDomainNetDefPtr iface);
-int virDomainNetAppendIpAddress(virDomainNetDefPtr def,
+int virDomainNetAppendIPAddress(virDomainNetDefPtr def,
const char *address,
int family,
unsigned int prefix);
diff --git a/src/conf/interface_conf.c b/src/conf/interface_conf.c
index 26e55cc..40f1958 100644
--- a/src/conf/interface_conf.c
+++ b/src/conf/interface_conf.c
@@ -45,7 +45,7 @@ virInterfaceDefDevFormat(virBufferPtr buf, const virInterfaceDef *def,
virInterfaceType parentIfType);

static
-void virInterfaceIpDefFree(virInterfaceIpDefPtr def)
+void virInterfaceIPDefFree(virInterfaceIPDefPtr def)
{
if (def == NULL)
return;
@@ -61,7 +61,7 @@ void virInterfaceProtocolDefFree(virInterfaceProtocolDefPtr def)
if (def == NULL)
return;
for (i = 0; i < def->nips; i++)
- virInterfaceIpDefFree(def->ips[i]);
+ virInterfaceIPDefFree(def->ips[i]);
VIR_FREE(def->ips);
VIR_FREE(def->family);
VIR_FREE(def->gateway);
@@ -281,7 +281,7 @@ virInterfaceDefParseDhcp(virInterfaceProtocolDefPtr def,
}

static int
-virInterfaceDefParseIp(virInterfaceIpDefPtr def,
+virInterfaceDefParseIP(virInterfaceIPDefPtr def,
xmlXPathContextPtr ctxt)
{
int ret = 0;
@@ -310,7 +310,7 @@ virInterfaceDefParseProtoIPv4(virInterfaceProtocolDefPtr def,
{
xmlNodePtr dhcp;
xmlNodePtr *ipNodes = NULL;
- int nIpNodes, ret = -1;
+ int nIPNodes, ret = -1;
size_t i;
char *tmp;

@@ -323,26 +323,26 @@ virInterfaceDefParseProtoIPv4(virInterfaceProtocolDefPtr def,
return -1;
}

- nIpNodes = virXPathNodeSet("./ip", ctxt, &ipNodes);
- if (nIpNodes < 0)
+ nIPNodes = virXPathNodeSet("./ip", ctxt, &ipNodes);
+ if (nIPNodes < 0)
return -1;
if (ipNodes == NULL)
return 0;

- if (VIR_ALLOC_N(def->ips, nIpNodes) < 0)
+ if (VIR_ALLOC_N(def->ips, nIPNodes) < 0)
goto error;

def->nips = 0;
- for (i = 0; i < nIpNodes; i++) {
+ for (i = 0; i < nIPNodes; i++) {

- virInterfaceIpDefPtr ip;
+ virInterfaceIPDefPtr ip;

if (VIR_ALLOC(ip) < 0)
goto error;

ctxt->node = ipNodes[i];
- if (virInterfaceDefParseIp(ip, ctxt) < 0) {
- virInterfaceIpDefFree(ip);
+ if (virInterfaceDefParseIP(ip, ctxt) < 0) {
+ virInterfaceIPDefFree(ip);
goto error;
}
def->ips[def->nips++] = ip;
@@ -361,7 +361,7 @@ virInterfaceDefParseProtoIPv6(virInterfaceProtocolDefPtr def,
{
xmlNodePtr dhcp, autoconf;
xmlNodePtr *ipNodes = NULL;
- int nIpNodes, ret = -1;
+ int nIPNodes, ret = -1;
size_t i;
char *tmp;

@@ -378,26 +378,26 @@ virInterfaceDefParseProtoIPv6(virInterfaceProtocolDefPtr def,
return -1;
}

- nIpNodes = virXPathNodeSet("./ip", ctxt, &ipNodes);
- if (nIpNodes < 0)
+ nIPNodes = virXPathNodeSet("./ip", ctxt, &ipNodes);
+ if (nIPNodes < 0)
return -1;
if (ipNodes == NULL)
return 0;

- if (VIR_ALLOC_N(def->ips, nIpNodes) < 0)
+ if (VIR_ALLOC_N(def->ips, nIPNodes) < 0)
goto error;

def->nips = 0;
- for (i = 0; i < nIpNodes; i++) {
+ for (i = 0; i < nIPNodes; i++) {

- virInterfaceIpDefPtr ip;
+ virInterfaceIPDefPtr ip;

if (VIR_ALLOC(ip) < 0)
goto error;

ctxt->node = ipNodes[i];
- if (virInterfaceDefParseIp(ip, ctxt) < 0) {
- virInterfaceIpDefFree(ip);
+ if (virInterfaceDefParseIP(ip, ctxt) < 0) {
+ virInterfaceIPDefFree(ip);
goto error;
}
def->ips[def->nips++] = ip;
diff --git a/src/conf/interface_conf.h b/src/conf/interface_conf.h
index 5cabec7..2523207 100644
--- a/src/conf/interface_conf.h
+++ b/src/conf/interface_conf.h
@@ -119,9 +119,9 @@ struct _virInterfaceVlanDef {
char *dev_name; /* device name for vlan */
};

-typedef struct _virInterfaceIpDef virInterfaceIpDef;
-typedef virInterfaceIpDef *virInterfaceIpDefPtr;
-struct _virInterfaceIpDef {
+typedef struct _virInterfaceIPDef virInterfaceIPDef;
+typedef virInterfaceIPDef *virInterfaceIPDefPtr;
+struct _virInterfaceIPDef {
char *address; /* ip address */
int prefix; /* ip prefix */
};
@@ -135,7 +135,7 @@ struct _virInterfaceProtocolDef {
int peerdns; /* dhcp peerdns ? */
int autoconf; /* only useful if family is ipv6 */
int nips;
- virInterfaceIpDefPtr *ips; /* ptr to array of ips[nips] */
+ virInterfaceIPDefPtr *ips; /* ptr to array of ips[nips] */
char *gateway; /* route gateway */
};

diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index 02b8cd7..5ae2bdf 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -310,7 +310,7 @@ virNetworkDHCPHostDefClear(virNetworkDHCPHostDefPtr def)
}

static void
-virNetworkIpDefClear(virNetworkIpDefPtr def)
+virNetworkIPDefClear(virNetworkIPDefPtr def)
{
VIR_FREE(def->family);
VIR_FREE(def->ranges);
@@ -402,7 +402,7 @@ virNetworkDefFree(virNetworkDefPtr def)
virNetworkForwardDefClear(&def->forward);

for (i = 0; i < def->nips && def->ips; i++)
- virNetworkIpDefClear(&def->ips[i]);
+ virNetworkIPDefClear(&def->ips[i]);
VIR_FREE(def->ips);

for (i = 0; i < def->nroutes && def->routes; i++)
@@ -780,8 +780,8 @@ void virNetworkRemoveInactive(virNetworkObjListPtr nets,
}

/* return ips[index], or NULL if there aren't enough ips */
-virNetworkIpDefPtr
-virNetworkDefGetIpByIndex(const virNetworkDef *def,
+virNetworkIPDefPtr
+virNetworkDefGetIPByIndex(const virNetworkDef *def,
int family, size_t n)
{
size_t i;
@@ -832,9 +832,9 @@ virNetworkDefGetRouteByIndex(const virNetworkDef *def,
/* return number of 1 bits in netmask for the network's ipAddress,
* or -1 on error
*/
-int virNetworkIpDefPrefix(const virNetworkIpDef *def)
+int virNetworkIPDefPrefix(const virNetworkIPDef *def)
{
- return virSocketAddrGetIpPrefix(&def->address,
+ return virSocketAddrGetIPPrefix(&def->address,
&def->netmask,
def->prefix);
}
@@ -843,7 +843,7 @@ int virNetworkIpDefPrefix(const virNetworkIpDef *def)
* definition, based on either the definition's netmask, or its
* prefix. Return -1 on error (and set the netmask family to AF_UNSPEC)
*/
-int virNetworkIpDefNetmask(const virNetworkIpDef *def,
+int virNetworkIPDefNetmask(const virNetworkIPDef *def,
virSocketAddrPtr netmask)
{
if (VIR_SOCKET_ADDR_IS_FAMILY(&def->netmask, AF_INET)) {
@@ -851,14 +851,14 @@ int virNetworkIpDefNetmask(const virNetworkIpDef *def,
return 0;
}

- return virSocketAddrPrefixToNetmask(virNetworkIpDefPrefix(def), netmask,
+ return virSocketAddrPrefixToNetmask(virNetworkIPDefPrefix(def), netmask,
VIR_SOCKET_ADDR_FAMILY(&def->address));
}


static int
virSocketAddrRangeParseXML(const char *networkName,
- virNetworkIpDefPtr ipdef,
+ virNetworkIPDefPtr ipdef,
xmlNodePtr node,
virSocketAddrRangePtr range)
{
@@ -887,7 +887,7 @@ virSocketAddrRangeParseXML(const char *networkName,

/* do a sanity check of the range */
if (virSocketAddrGetRange(&range->start, &range->end, &ipdef->address,
- virNetworkIpDefPrefix(ipdef)) < 0)
+ virNetworkIPDefPrefix(ipdef)) < 0)
goto cleanup;

ret = 0;
@@ -900,7 +900,7 @@ virSocketAddrRangeParseXML(const char *networkName,

static int
virNetworkDHCPHostDefParseXML(const char *networkName,
- virNetworkIpDefPtr def,
+ virNetworkIPDefPtr def,
xmlNodePtr node,
virNetworkDHCPHostDefPtr host,
bool partialOkay)
@@ -1021,7 +1021,7 @@ virNetworkDHCPHostDefParseXML(const char *networkName,
static int
virNetworkDHCPDefParseXML(const char *networkName,
xmlNodePtr node,
- virNetworkIpDefPtr def)
+ virNetworkIPDefPtr def)
{
int ret = -1;
xmlNodePtr cur;
@@ -1448,10 +1448,10 @@ static int
virNetworkIPDefParseXML(const char *networkName,
xmlNodePtr node,
xmlXPathContextPtr ctxt,
- virNetworkIpDefPtr def)
+ virNetworkIPDefPtr def)
{
/*
- * virNetworkIpDef object is already allocated as part of an array.
+ * virNetworkIPDef object is already allocated as part of an array.
* On failure clear it out, but don't free it.
*/

@@ -1586,7 +1586,7 @@ virNetworkIPDefParseXML(const char *networkName,

cleanup:
if (result < 0)
- virNetworkIpDefClear(def);
+ virNetworkIPDefClear(def);
VIR_FREE(address);
VIR_FREE(netmask);

@@ -2050,7 +2050,7 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt)
xmlNodePtr *ipNodes = NULL;
xmlNodePtr *routeNodes = NULL;
xmlNodePtr *portGroupNodes = NULL;
- int nIps, nPortGroups, nRoutes;
+ int nips, nPortGroups, nRoutes;
xmlNodePtr dnsNode = NULL;
xmlNodePtr virtPortNode = NULL;
xmlNodePtr forwardNode = NULL;
@@ -2227,18 +2227,18 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt)
}
VIR_FREE(portGroupNodes);

- nIps = virXPathNodeSet("./ip", ctxt, &ipNodes);
- if (nIps < 0)
+ nips = virXPathNodeSet("./ip", ctxt, &ipNodes);
+ if (nips < 0)
goto error;

- if (nIps > 0) {
+ if (nips > 0) {
size_t i;

/* allocate array to hold all the addrs */
- if (VIR_ALLOC_N(def->ips, nIps) < 0)
+ if (VIR_ALLOC_N(def->ips, nips) < 0)
goto error;
/* parse each addr */
- for (i = 0; i < nIps; i++) {
+ for (i = 0; i < nips; i++) {
if (virNetworkIPDefParseXML(def->name,
ipNodes[i],
ctxt,
@@ -2278,7 +2278,7 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt)
* is directly reachable from this bridge.
*/
nRoutes = def->nroutes;
- nIps = def->nips;
+ nips = def->nips;
for (i = 0; i < nRoutes; i++) {
size_t j;
virSocketAddr testAddr, testGw;
@@ -2286,13 +2286,13 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt)
virNetworkRouteDefPtr gwdef = def->routes[i];
virSocketAddrPtr gateway = virNetworkRouteDefGetGateway(gwdef);
addrMatch = false;
- for (j = 0; j < nIps; j++) {
- virNetworkIpDefPtr def2 = &def->ips[j];
+ for (j = 0; j < nips; j++) {
+ virNetworkIPDefPtr def2 = &def->ips[j];
if (VIR_SOCKET_ADDR_FAMILY(gateway)
!= VIR_SOCKET_ADDR_FAMILY(&def2->address)) {
continue;
}
- int prefix = virNetworkIpDefPrefix(def2);
+ int prefix = virNetworkIPDefPrefix(def2);
virSocketAddrMaskByPrefix(&def2->address, prefix, &testAddr);
virSocketAddrMaskByPrefix(gateway, prefix, &testGw);
if (VIR_SOCKET_ADDR_VALID(&testAddr) &&
@@ -2544,8 +2544,8 @@ virNetworkDNSDefFormat(virBufferPtr buf,
}

static int
-virNetworkIpDefFormat(virBufferPtr buf,
- const virNetworkIpDef *def)
+virNetworkIPDefFormat(virBufferPtr buf,
+ const virNetworkIPDef *def)
{
int result = -1;

@@ -2871,7 +2871,7 @@ virNetworkDefFormatBuf(virBufferPtr buf,
goto error;

for (i = 0; i < def->nips; i++) {
- if (virNetworkIpDefFormat(buf, &def->ips[i]) < 0)
+ if (virNetworkIPDefFormat(buf, &def->ips[i]) < 0)
goto error;
}

@@ -3467,15 +3467,15 @@ virNetworkDefUpdateIP(virNetworkDefPtr def,
return -1;
}

-static virNetworkIpDefPtr
-virNetworkIpDefByIndex(virNetworkDefPtr def, int parentIndex)
+static virNetworkIPDefPtr
+virNetworkIPDefByIndex(virNetworkDefPtr def, int parentIndex)
{
- virNetworkIpDefPtr ipdef = NULL;
+ virNetworkIPDefPtr ipdef = NULL;
size_t i;

/* first find which ip element's dhcp host list to work on */
if (parentIndex >= 0) {
- ipdef = virNetworkDefGetIpByIndex(def, AF_UNSPEC, parentIndex);
+ ipdef = virNetworkDefGetIPByIndex(def, AF_UNSPEC, parentIndex);
if (!(ipdef)) {
virReportError(VIR_ERR_OPERATION_INVALID,
_("couldn't update dhcp host entry - no <ip> "
@@ -3489,15 +3489,15 @@ virNetworkIpDefByIndex(virNetworkDefPtr def, int parentIndex)
* means the one and only <ip> that has <dhcp> element
*/
for (i = 0;
- (ipdef = virNetworkDefGetIpByIndex(def, AF_UNSPEC, i));
+ (ipdef = virNetworkDefGetIPByIndex(def, AF_UNSPEC, i));
i++) {
if (ipdef->nranges || ipdef->nhosts)
break;
}
if (!ipdef) {
- ipdef = virNetworkDefGetIpByIndex(def, AF_INET, 0);
+ ipdef = virNetworkDefGetIPByIndex(def, AF_INET, 0);
if (!ipdef)
- ipdef = virNetworkDefGetIpByIndex(def, AF_INET6, 0);
+ ipdef = virNetworkDefGetIPByIndex(def, AF_INET6, 0);
}
if (!ipdef) {
virReportError(VIR_ERR_OPERATION_INVALID,
@@ -3510,13 +3510,13 @@ virNetworkIpDefByIndex(virNetworkDefPtr def, int parentIndex)

static int
virNetworkDefUpdateCheckMultiDHCP(virNetworkDefPtr def,
- virNetworkIpDefPtr ipdef)
+ virNetworkIPDefPtr ipdef)
{
int family = VIR_SOCKET_ADDR_FAMILY(&ipdef->address);
size_t i;
- virNetworkIpDefPtr ip;
+ virNetworkIPDefPtr ip;

- for (i = 0; (ip = virNetworkDefGetIpByIndex(def, family, i)); i++) {
+ for (i = 0; (ip = virNetworkDefGetIPByIndex(def, family, i)); i++) {
if (ip != ipdef) {
if (ip->nranges || ip->nhosts) {
virReportError(VIR_ERR_OPERATION_INVALID,
@@ -3541,7 +3541,7 @@ virNetworkDefUpdateIPDHCPHost(virNetworkDefPtr def,
{
size_t i;
int ret = -1;
- virNetworkIpDefPtr ipdef = virNetworkIpDefByIndex(def, parentIndex);
+ virNetworkIPDefPtr ipdef = virNetworkIPDefByIndex(def, parentIndex);
virNetworkDHCPHostDef host;
bool partialOkay = (command == VIR_NETWORK_UPDATE_COMMAND_DELETE);

@@ -3680,7 +3680,7 @@ virNetworkDefUpdateIPDHCPRange(virNetworkDefPtr def,
{
size_t i;
int ret = -1;
- virNetworkIpDefPtr ipdef = virNetworkIpDefByIndex(def, parentIndex);
+ virNetworkIPDefPtr ipdef = virNetworkIPDefByIndex(def, parentIndex);
virSocketAddrRange range;

memset(&range, 0, sizeof(range));
diff --git a/src/conf/network_conf.h b/src/conf/network_conf.h
index 0d34dfe..18f4d1e 100644
--- a/src/conf/network_conf.h
+++ b/src/conf/network_conf.h
@@ -1,7 +1,7 @@
/*
* network_conf.h: network XML handling
*
- * Copyright (C) 2006-2015 Red Hat, Inc.
+ * Copyright (C) 2006-2016 Red Hat, Inc.
* Copyright (C) 2006-2008 Daniel P. Berrange
*
* This library is free software; you can redistribute it and/or
@@ -138,15 +138,15 @@ struct _virNetworkDNSDef {
char **forwarders;
};

-typedef struct _virNetworkIpDef virNetworkIpDef;
-typedef virNetworkIpDef *virNetworkIpDefPtr;
-struct _virNetworkIpDef {
+typedef struct _virNetworkIPDef virNetworkIPDef;
+typedef virNetworkIPDef *virNetworkIPDefPtr;
+struct _virNetworkIPDef {
char *family; /* ipv4 or ipv6 - default is ipv4 */
virSocketAddr address; /* Bridge IP address */

/* One or the other of the following two will be used for a given
* IP address, but never both. The parser guarantees this.
- * Use virNetworkIpDefPrefix/virNetworkIpDefNetmask rather
+ * Use virNetworkIPDefPrefix/virNetworkIPDefNetmask rather
* than accessing the data directly - these utility functions
* will convert one into the other as necessary.
*/
@@ -240,7 +240,7 @@ struct _virNetworkDef {
virNetworkForwardDef forward;

size_t nips;
- virNetworkIpDefPtr ips; /* ptr to array of IP addresses on this network */
+ virNetworkIPDefPtr ips; /* ptr to array of IP addresses on this network */

size_t nroutes;
virNetworkRouteDefPtr *routes; /* ptr to array of static routes on this interface */
@@ -351,14 +351,14 @@ const char * virNetworkDefForwardIf(const virNetworkDef *def, size_t n);
virPortGroupDefPtr virPortGroupFindByName(virNetworkDefPtr net,
const char *portgroup);

-virNetworkIpDefPtr
-virNetworkDefGetIpByIndex(const virNetworkDef *def,
+virNetworkIPDefPtr
+virNetworkDefGetIPByIndex(const virNetworkDef *def,
int family, size_t n);
virNetworkRouteDefPtr
virNetworkDefGetRouteByIndex(const virNetworkDef *def,
int family, size_t n);
-int virNetworkIpDefPrefix(const virNetworkIpDef *def);
-int virNetworkIpDefNetmask(const virNetworkIpDef *def,
+int virNetworkIPDefPrefix(const virNetworkIPDef *def);
+int virNetworkIPDefNetmask(const virNetworkIPDef *def,
virSocketAddrPtr netmask);

int virNetworkSaveXML(const char *configDir,
diff --git a/src/conf/networkcommon_conf.c b/src/conf/networkcommon_conf.c
index 7b7a851..8f9d4b8 100644
--- a/src/conf/networkcommon_conf.c
+++ b/src/conf/networkcommon_conf.c
@@ -38,7 +38,7 @@ struct _virNetworkRouteDef {

/* One or the other of the following two will be used for a given
* Network address, but never both. The parser guarantees this.
- * The virSocketAddrGetIpPrefix() can be used to get a
+ * The virSocketAddrGetIPPrefix() can be used to get a
* valid prefix.
*/
virSocketAddr netmask; /* ipv4 - either netmask or prefix specified */
@@ -387,10 +387,10 @@ virNetworkRouteDefGetPrefix(virNetworkRouteDefPtr def)
virSocketAddrEqual(&def->netmask, &zero)))
prefix = 0;
else
- prefix = virSocketAddrGetIpPrefix(&def->address, &def->netmask,
+ prefix = virSocketAddrGetIPPrefix(&def->address, &def->netmask,
def->prefix);
} else {
- prefix = virSocketAddrGetIpPrefix(&def->address, &def->netmask,
+ prefix = virSocketAddrGetIPPrefix(&def->address, &def->netmask,
def->prefix);
}

diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c
index 60fcac0..eae015a 100644
--- a/src/esx/esx_driver.c
+++ b/src/esx/esx_driver.c
@@ -612,7 +612,7 @@ static int
esxConnectToHost(esxPrivate *priv,
virConnectPtr conn,
virConnectAuthPtr auth,
- char **vCenterIpAddress)
+ char **vCenterIPAddress)
{
int result = -1;
char ipAddress[NI_MAXHOST] = "";
@@ -626,7 +626,7 @@ esxConnectToHost(esxPrivate *priv,
? esxVI_ProductLine_ESX
: esxVI_ProductLine_GSX;

- if (!vCenterIpAddress || *vCenterIpAddress) {
+ if (!vCenterIPAddress || *vCenterIPAddress) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
return -1;
}
@@ -683,7 +683,7 @@ esxConnectToHost(esxPrivate *priv,
&inMaintenanceMode,
esxVI_Occurrence_RequiredItem) < 0 ||
esxVI_GetStringValue(hostSystem, "summary.managementServerIp",
- vCenterIpAddress,
+ vCenterIPAddress,
esxVI_Occurrence_OptionalItem) < 0) {
goto cleanup;
}
@@ -692,7 +692,7 @@ esxConnectToHost(esxPrivate *priv,
if (inMaintenanceMode == esxVI_Boolean_True)
VIR_WARN("The server is in maintenance mode");

- if (VIR_STRDUP(*vCenterIpAddress, *vCenterIpAddress) < 0)
+ if (VIR_STRDUP(*vCenterIPAddress, *vCenterIPAddress) < 0)
goto cleanup;

result = 0;
@@ -714,7 +714,7 @@ esxConnectToVCenter(esxPrivate *priv,
virConnectPtr conn,
virConnectAuthPtr auth,
const char *hostname,
- const char *hostSystemIpAddress)
+ const char *hostSystemIPAddress)
{
int result = -1;
char ipAddress[NI_MAXHOST] = "";
@@ -722,7 +722,7 @@ esxConnectToVCenter(esxPrivate *priv,
char *password = NULL;
char *url = NULL;

- if (!hostSystemIpAddress &&
+ if (!hostSystemIPAddress &&
(!priv->parsedUri->path || STREQ(priv->parsedUri->path, "/"))) {
virReportError(VIR_ERR_INVALID_ARG, "%s",
_("Path has to specify the datacenter and compute resource"));
@@ -770,9 +770,9 @@ esxConnectToVCenter(esxPrivate *priv,
goto cleanup;
}

- if (hostSystemIpAddress) {
+ if (hostSystemIPAddress) {
if (esxVI_Context_LookupManagedObjectsByHostSystemIp
- (priv->vCenter, hostSystemIpAddress) < 0) {
+ (priv->vCenter, hostSystemIPAddress) < 0) {
goto cleanup;
}
} else {
@@ -847,8 +847,8 @@ esxConnectOpen(virConnectPtr conn, virConnectAuthPtr auth,
virDrvOpenStatus result = VIR_DRV_OPEN_ERROR;
char *plus;
esxPrivate *priv = NULL;
- char *potentialVCenterIpAddress = NULL;
- char vCenterIpAddress[NI_MAXHOST] = "";
+ char *potentialVCenterIPAddress = NULL;
+ char vCenterIPAddress[NI_MAXHOST] = "";

virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);

@@ -939,46 +939,46 @@ esxConnectOpen(virConnectPtr conn, virConnectAuthPtr auth,
STRCASEEQ(conn->uri->scheme, "gsx")) {
/* Connect to host */
if (esxConnectToHost(priv, conn, auth,
- &potentialVCenterIpAddress) < 0) {
+ &potentialVCenterIPAddress) < 0) {
goto cleanup;
}

/* Connect to vCenter */
if (priv->parsedUri->vCenter) {
if (STREQ(priv->parsedUri->vCenter, "*")) {
- if (!potentialVCenterIpAddress) {
+ if (!potentialVCenterIPAddress) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("This host is not managed by a vCenter"));
goto cleanup;
}

- if (!virStrcpyStatic(vCenterIpAddress,
- potentialVCenterIpAddress)) {
+ if (!virStrcpyStatic(vCenterIPAddress,
+ potentialVCenterIPAddress)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("vCenter IP address %s too big for destination"),
- potentialVCenterIpAddress);
+ potentialVCenterIPAddress);
goto cleanup;
}
} else {
if (esxUtil_ResolveHostname(priv->parsedUri->vCenter,
- vCenterIpAddress, NI_MAXHOST) < 0) {
+ vCenterIPAddress, NI_MAXHOST) < 0) {
goto cleanup;
}

- if (potentialVCenterIpAddress &&
- STRNEQ(vCenterIpAddress, potentialVCenterIpAddress)) {
+ if (potentialVCenterIPAddress &&
+ STRNEQ(vCenterIPAddress, potentialVCenterIPAddress)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("This host is managed by a vCenter with IP "
"address %s, but a mismachting vCenter '%s' "
"(%s) has been specified"),
- potentialVCenterIpAddress, priv->parsedUri->vCenter,
- vCenterIpAddress);
+ potentialVCenterIPAddress, priv->parsedUri->vCenter,
+ vCenterIPAddress);
goto cleanup;
}
}

if (esxConnectToVCenter(priv, conn, auth,
- vCenterIpAddress,
+ vCenterIPAddress,
priv->host->ipAddress) < 0) {
goto cleanup;
}
@@ -1011,7 +1011,7 @@ esxConnectOpen(virConnectPtr conn, virConnectAuthPtr auth,

cleanup:
esxFreePrivate(&priv);
- VIR_FREE(potentialVCenterIpAddress);
+ VIR_FREE(potentialVCenterIPAddress);

return result;
}
diff --git a/src/esx/esx_interface_driver.c b/src/esx/esx_interface_driver.c
index 58096e8..e3b4116 100644
--- a/src/esx/esx_interface_driver.c
+++ b/src/esx/esx_interface_driver.c
@@ -181,8 +181,8 @@ esxInterfaceGetXMLDesc(virInterfacePtr iface, unsigned int flags)
virInterfaceProtocolDefPtr protocols;
virInterfaceProtocolDef protocol;
virSocketAddr socketAddress;
- virInterfaceIpDefPtr ips;
- virInterfaceIpDef ip;
+ virInterfaceIPDefPtr ips;
+ virInterfaceIPDef ip;

virCheckFlags(VIR_INTERFACE_XML_INACTIVE, NULL);

diff --git a/src/esx/esx_vi.c b/src/esx/esx_vi.c
index bbf3721..a28ac7b 100644
--- a/src/esx/esx_vi.c
+++ b/src/esx/esx_vi.c
@@ -1367,13 +1367,13 @@ esxVI_Context_LookupManagedObjectsByPath(esxVI_Context *ctx, const char *path)

int
esxVI_Context_LookupManagedObjectsByHostSystemIp(esxVI_Context *ctx,
- const char *hostSystemIpAddress)
+ const char *hostSystemIPAddress)
{
int result = -1;
esxVI_ManagedObjectReference *managedObjectReference = NULL;

/* Lookup HostSystem */
- if (esxVI_FindByIp(ctx, NULL, hostSystemIpAddress, esxVI_Boolean_False,
+ if (esxVI_FindByIp(ctx, NULL, hostSystemIPAddress, esxVI_Boolean_False,
&managedObjectReference) < 0 ||
esxVI_LookupHostSystem(ctx, NULL, managedObjectReference, NULL,
&ctx->hostSystem,
diff --git a/src/esx/esx_vi.h b/src/esx/esx_vi.h
index c41541e..7c53f37 100644
--- a/src/esx/esx_vi.h
+++ b/src/esx/esx_vi.h
@@ -220,7 +220,7 @@ int esxVI_Context_Connect(esxVI_Context *ctx, const char *ipAddress,
int esxVI_Context_LookupManagedObjects(esxVI_Context *ctx);
int esxVI_Context_LookupManagedObjectsByPath(esxVI_Context *ctx, const char *path);
int esxVI_Context_LookupManagedObjectsByHostSystemIp(esxVI_Context *ctx,
- const char *hostSystemIpAddress);
+ const char *hostSystemIPAddress);
int esxVI_Context_Execute(esxVI_Context *ctx, const char *methodName,
const char *request, esxVI_Response **response,
esxVI_Occurrence occurrence);
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index df2dfc3..36e3901 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -371,7 +371,7 @@ virDomainMemoryFindByDef;
virDomainMemoryFindInactiveByDef;
virDomainMemoryInsert;
virDomainMemoryRemove;
-virDomainNetAppendIpAddress;
+virDomainNetAppendIPAddress;
virDomainNetDefFormat;
virDomainNetDefFree;
virDomainNetFind;
@@ -597,7 +597,7 @@ virNetworkDefFormat;
virNetworkDefFormatBuf;
virNetworkDefForwardIf;
virNetworkDefFree;
-virNetworkDefGetIpByIndex;
+virNetworkDefGetIPByIndex;
virNetworkDefGetRouteByIndex;
virNetworkDefParseFile;
virNetworkDefParseNode;
@@ -605,8 +605,8 @@ virNetworkDefParseString;
virNetworkDefUpdateSection;
virNetworkDeleteConfig;
virNetworkForwardTypeToString;
-virNetworkIpDefNetmask;
-virNetworkIpDefPrefix;
+virNetworkIPDefNetmask;
+virNetworkIPDefPrefix;
virNetworkLoadAllConfigs;
virNetworkLoadAllState;
virNetworkObjAssignDef;
@@ -2245,7 +2245,7 @@ virSocketAddrCheckNetmask;
virSocketAddrEqual;
virSocketAddrFormat;
virSocketAddrFormatFull;
-virSocketAddrGetIpPrefix;
+virSocketAddrGetIPPrefix;
virSocketAddrGetPort;
virSocketAddrGetRange;
virSocketAddrIsNetmask;
diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c
index 33dcfec..531bbd5 100644
--- a/src/lxc/lxc_container.c
+++ b/src/lxc/lxc_container.c
@@ -513,7 +513,7 @@ static int lxcContainerRenameAndEnableInterfaces(virDomainDefPtr vmDef,
goto error_out;

for (j = 0; j < netDef->nips; j++) {
- virDomainNetIpDefPtr ip = netDef->ips[j];
+ virDomainNetIPDefPtr ip = netDef->ips[j];
unsigned int prefix = (ip->prefix > 0) ? ip->prefix :
VIR_SOCKET_ADDR_DEFAULT_PREFIX;
char *ipStr = virSocketAddrFormat(&ip->address);
diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c
index 7f8e904..9ad1b08 100644
--- a/src/lxc/lxc_native.c
+++ b/src/lxc/lxc_native.c
@@ -419,7 +419,7 @@ typedef struct {
char *macvlanmode;
char *vlanid;
char *name;
- virDomainNetIpDefPtr *ips;
+ virDomainNetIPDefPtr *ips;
size_t nips;
char *gateway_ipv4;
char *gateway_ipv6;
@@ -601,7 +601,7 @@ lxcNetworkWalkCallback(const char *name, virConfValuePtr value, void *data)
STREQ(name, "lxc.network.ipv6")) {
int family = AF_INET;
char **ipparts = NULL;
- virDomainNetIpDefPtr ip = NULL;
+ virDomainNetIPDefPtr ip = NULL;

if (VIR_ALLOC(ip) < 0)
return -1;
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index 7c8d2cc..130b77d 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -872,7 +872,7 @@ networkKillDaemon(pid_t pid, const char *daemonName, const char *networkName)

static int
networkBuildDnsmasqDhcpHostsList(dnsmasqContext *dctx,
- virNetworkIpDefPtr ipdef)
+ virNetworkIPDefPtr ipdef)
{
size_t i;
bool ipv6 = false;
@@ -923,7 +923,7 @@ networkDnsmasqConfContents(virNetworkObjPtr network,
int nbleases = 0;
size_t i;
virNetworkDNSDefPtr dns = &network->def->dns;
- virNetworkIpDefPtr tmpipdef, ipdef, ipv4def, ipv6def;
+ virNetworkIPDefPtr tmpipdef, ipdef, ipv4def, ipv6def;
bool ipv6SLAAC;
char *saddr = NULL, *eaddr = NULL;

@@ -1013,7 +1013,7 @@ networkDnsmasqConfContents(virNetworkObjPtr network,
* So listen on all defined IPv[46] addresses
*/
for (i = 0;
- (tmpipdef = virNetworkDefGetIpByIndex(network->def, AF_UNSPEC, i));
+ (tmpipdef = virNetworkDefGetIPByIndex(network->def, AF_UNSPEC, i));
i++) {
char *ipaddr = virSocketAddrFormat(&tmpipdef->address);

@@ -1123,7 +1123,7 @@ networkDnsmasqConfContents(virNetworkObjPtr network,

/* Find the first dhcp for both IPv4 and IPv6 */
for (i = 0, ipv4def = NULL, ipv6def = NULL, ipv6SLAAC = false;
- (ipdef = virNetworkDefGetIpByIndex(network->def, AF_UNSPEC, i));
+ (ipdef = virNetworkDefGetIPByIndex(network->def, AF_UNSPEC, i));
i++) {
if (VIR_SOCKET_ADDR_IS_FAMILY(&ipdef->address, AF_INET)) {
if (ipdef->nranges || ipdef->nhosts) {
@@ -1181,7 +1181,7 @@ networkDnsmasqConfContents(virNetworkObjPtr network,
while (ipdef) {
int prefix;

- prefix = virNetworkIpDefPrefix(ipdef);
+ prefix = virNetworkIPDefPrefix(ipdef);
if (prefix < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("bridge '%s' has an invalid prefix"),
@@ -1206,7 +1206,7 @@ networkDnsmasqConfContents(virNetworkObjPtr network,
thisRange = virSocketAddrGetRange(&ipdef->ranges[r].start,
&ipdef->ranges[r].end,
&ipdef->address,
- virNetworkIpDefPrefix(ipdef));
+ virNetworkIPDefPrefix(ipdef));
if (thisRange < 0)
goto cleanup;
nbleases += thisRange;
@@ -1287,7 +1287,7 @@ networkDnsmasqConfContents(virNetworkObjPtr network,
virBufferAddLit(&configbuf, "enable-ra\n");
} else {
for (i = 0;
- (ipdef = virNetworkDefGetIpByIndex(network->def, AF_INET6, i));
+ (ipdef = virNetworkDefGetIPByIndex(network->def, AF_INET6, i));
i++) {
if (!(ipdef->nranges || ipdef->nhosts)) {
char *bridgeaddr = virSocketAddrFormat(&ipdef->address);
@@ -1380,7 +1380,7 @@ networkStartDhcpDaemon(virNetworkDriverStatePtr driver,
int ret = -1;
dnsmasqContext *dctx = NULL;

- if (!virNetworkDefGetIpByIndex(network->def, AF_UNSPEC, 0)) {
+ if (!virNetworkDefGetIPByIndex(network->def, AF_UNSPEC, 0)) {
/* no IP addresses, so we don't need to run */
ret = 0;
goto cleanup;
@@ -1457,11 +1457,11 @@ networkRefreshDhcpDaemon(virNetworkDriverStatePtr driver,
{
int ret = -1;
size_t i;
- virNetworkIpDefPtr ipdef, ipv4def, ipv6def;
+ virNetworkIPDefPtr ipdef, ipv4def, ipv6def;
dnsmasqContext *dctx = NULL;

/* if no IP addresses specified, nothing to do */
- if (!virNetworkDefGetIpByIndex(network->def, AF_UNSPEC, 0))
+ if (!virNetworkDefGetIPByIndex(network->def, AF_UNSPEC, 0))
return 0;

/* if there's no running dnsmasq, just start it */
@@ -1480,7 +1480,7 @@ networkRefreshDhcpDaemon(virNetworkDriverStatePtr driver,
*/
ipv4def = NULL;
for (i = 0;
- (ipdef = virNetworkDefGetIpByIndex(network->def, AF_INET, i));
+ (ipdef = virNetworkDefGetIPByIndex(network->def, AF_INET, i));
i++) {
if (!ipv4def && (ipdef->nranges || ipdef->nhosts))
ipv4def = ipdef;
@@ -1488,7 +1488,7 @@ networkRefreshDhcpDaemon(virNetworkDriverStatePtr driver,

ipv6def = NULL;
for (i = 0;
- (ipdef = virNetworkDefGetIpByIndex(network->def, AF_INET6, i));
+ (ipdef = virNetworkDefGetIPByIndex(network->def, AF_INET6, i));
i++) {
if (!ipv6def && (ipdef->nranges || ipdef->nhosts))
ipv6def = ipdef;
@@ -1545,14 +1545,14 @@ networkRadvdConfContents(virNetworkObjPtr network, char **configstr)
virBuffer configbuf = VIR_BUFFER_INITIALIZER;
int ret = -1;
size_t i;
- virNetworkIpDefPtr ipdef;
+ virNetworkIPDefPtr ipdef;
bool v6present = false, dhcp6 = false;

*configstr = NULL;

/* Check if DHCPv6 is needed */
for (i = 0;
- (ipdef = virNetworkDefGetIpByIndex(network->def, AF_INET6, i));
+ (ipdef = virNetworkDefGetIPByIndex(network->def, AF_INET6, i));
i++) {
v6present = true;
if (ipdef->nranges || ipdef->nhosts) {
@@ -1582,12 +1582,12 @@ networkRadvdConfContents(virNetworkObjPtr network, char **configstr)

/* add a section for each IPv6 address in the config */
for (i = 0;
- (ipdef = virNetworkDefGetIpByIndex(network->def, AF_INET6, i));
+ (ipdef = virNetworkDefGetIPByIndex(network->def, AF_INET6, i));
i++) {
int prefix;
char *netaddr;

- prefix = virNetworkIpDefPrefix(ipdef);
+ prefix = virNetworkIPDefPrefix(ipdef);
if (prefix < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("bridge '%s' has an invalid prefix"),
@@ -1677,7 +1677,7 @@ networkStartRadvd(virNetworkDriverStatePtr driver,
goto cleanup;
}

- if (!virNetworkDefGetIpByIndex(network->def, AF_INET6, 0)) {
+ if (!virNetworkDefGetIPByIndex(network->def, AF_INET6, 0)) {
/* no IPv6 addresses, so we don't need to run radvd */
ret = 0;
goto cleanup;
@@ -1775,7 +1775,7 @@ networkRefreshRadvd(virNetworkDriverStatePtr driver,
if (network->radvdPid <= 0 || (kill(network->radvdPid, 0) < 0))
return networkStartRadvd(driver, network);

- if (!virNetworkDefGetIpByIndex(network->def, AF_INET6, 0)) {
+ if (!virNetworkDefGetIPByIndex(network->def, AF_INET6, 0)) {
/* no IPv6 addresses, so we don't need to run radvd */
return 0;
}
@@ -1882,7 +1882,7 @@ networkReloadFirewallRules(virNetworkDriverStatePtr driver)

/* Enable IP Forwarding. Return 0 for success, -1 for failure. */
static int
-networkEnableIpForwarding(bool enableIPv4, bool enableIPv6)
+networkEnableIPForwarding(bool enableIPv4, bool enableIPv6)
{
int ret = 0;
#ifdef HAVE_SYSCTLBYNAME
@@ -1909,7 +1909,7 @@ networkSetIPv6Sysctls(virNetworkObjPtr network)
{
char *field = NULL;
int ret = -1;
- bool enableIPv6 = !!virNetworkDefGetIpByIndex(network->def, AF_INET6, 0);
+ bool enableIPv6 = !!virNetworkDefGetIPByIndex(network->def, AF_INET6, 0);

/* set disable_ipv6 if there are no ipv6 addresses defined for the
* network. But also unset it if there *are* ipv6 addresses, as we
@@ -1975,9 +1975,9 @@ networkSetIPv6Sysctls(virNetworkObjPtr network)
/* add an IP address to a bridge */
static int
networkAddAddrToBridge(virNetworkObjPtr network,
- virNetworkIpDefPtr ipdef)
+ virNetworkIPDefPtr ipdef)
{
- int prefix = virNetworkIpDefPrefix(ipdef);
+ int prefix = virNetworkIPDefPrefix(ipdef);

if (prefix < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -2044,14 +2044,14 @@ networkAddRouteToBridge(virNetworkObjPtr network,
static int
networkWaitDadFinish(virNetworkObjPtr network)
{
- virNetworkIpDefPtr ipdef;
+ virNetworkIPDefPtr ipdef;
virSocketAddrPtr *addrs = NULL, addr = NULL;
size_t naddrs = 0;
int ret = -1;

VIR_DEBUG("Begin waiting for IPv6 DAD on network %s", network->def->name);

- while ((ipdef = virNetworkDefGetIpByIndex(network->def,
+ while ((ipdef = virNetworkDefGetIPByIndex(network->def,
AF_INET6, naddrs))) {
addr = &ipdef->address;
if (VIR_APPEND_ELEMENT_COPY(addrs, naddrs, addr) < 0)
@@ -2074,7 +2074,7 @@ networkStartNetworkVirtual(virNetworkDriverStatePtr driver,
size_t i;
bool v4present = false, v6present = false;
virErrorPtr save_err = NULL;
- virNetworkIpDefPtr ipdef;
+ virNetworkIPDefPtr ipdef;
virNetworkRouteDefPtr routedef;
char *macTapIfName = NULL;
int tapfd = -1;
@@ -2147,7 +2147,7 @@ networkStartNetworkVirtual(virNetworkDriverStatePtr driver,
goto err1;

for (i = 0;
- (ipdef = virNetworkDefGetIpByIndex(network->def, AF_UNSPEC, i));
+ (ipdef = virNetworkDefGetIPByIndex(network->def, AF_UNSPEC, i));
i++) {
if (VIR_SOCKET_ADDR_IS_FAMILY(&ipdef->address, AF_INET))
v4present = true;
@@ -2185,7 +2185,7 @@ networkStartNetworkVirtual(virNetworkDriverStatePtr driver,

/* If forward.type != NONE, turn on global IP forwarding */
if (network->def->forward.type != VIR_NETWORK_FORWARD_NONE &&
- networkEnableIpForwarding(v4present, v6present) < 0) {
+ networkEnableIPForwarding(v4present, v6present) < 0) {
virReportSystemError(errno, "%s",
_("failed to enable IP forwarding"));
goto err3;
@@ -2917,7 +2917,7 @@ networkValidate(virNetworkDriverStatePtr driver,
size_t i, j;
bool vlanUsed, vlanAllowed, badVlanUse = false;
virPortGroupDefPtr defaultPortGroup = NULL;
- virNetworkIpDefPtr ipdef;
+ virNetworkIPDefPtr ipdef;
bool ipv4def = false, ipv6def = false;
bool bandwidthAllowed = true;
bool usesInterface = false, usesAddress = false;
@@ -2949,7 +2949,7 @@ networkValidate(virNetworkDriverStatePtr driver,
virNetworkForwardTypeToString(def->forward.type));
return -1;
}
- if (virNetworkDefGetIpByIndex(def, AF_UNSPEC, 0)) {
+ if (virNetworkDefGetIPByIndex(def, AF_UNSPEC, 0)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Unsupported <ip> element in network %s "
"with forward mode='%s'"),
@@ -3022,7 +3022,7 @@ networkValidate(virNetworkDriverStatePtr driver,
* on one IPv6 address per defined network
*/
for (i = 0;
- (ipdef = virNetworkDefGetIpByIndex(def, AF_UNSPEC, i));
+ (ipdef = virNetworkDefGetIPByIndex(def, AF_UNSPEC, i));
i++) {
if (VIR_SOCKET_ADDR_IS_FAMILY(&ipdef->address, AF_INET)) {
if (ipdef->nranges || ipdef->nhosts) {
@@ -3313,7 +3313,7 @@ networkUpdate(virNetworkPtr net,
virNetworkObjPtr network = NULL;
int isActive, ret = -1;
size_t i;
- virNetworkIpDefPtr ipdef;
+ virNetworkIPDefPtr ipdef;
bool oldDhcpActive = false;
bool needFirewallRefresh = false;

@@ -3330,7 +3330,7 @@ networkUpdate(virNetworkPtr net,

/* see if we are listening for dhcp pre-modification */
for (i = 0;
- (ipdef = virNetworkDefGetIpByIndex(network->def, AF_INET, i));
+ (ipdef = virNetworkDefGetIPByIndex(network->def, AF_INET, i));
i++) {
if (ipdef->nranges || ipdef->nhosts) {
oldDhcpActive = true;
@@ -3425,7 +3425,7 @@ networkUpdate(virNetworkPtr net,
bool newDhcpActive = false;

for (i = 0;
- (ipdef = virNetworkDefGetIpByIndex(network->def, AF_INET, i));
+ (ipdef = virNetworkDefGetIPByIndex(network->def, AF_INET, i));
i++) {
if (ipdef->nranges || ipdef->nhosts) {
newDhcpActive = true;
@@ -3694,7 +3694,7 @@ networkGetDHCPLeases(virNetworkPtr network,
const char *mac_tmp = NULL;
virJSONValuePtr lease_tmp = NULL;
virJSONValuePtr leases_array = NULL;
- virNetworkIpDefPtr ipdef_tmp = NULL;
+ virNetworkIPDefPtr ipdef_tmp = NULL;
virNetworkDHCPLeasePtr lease = NULL;
virNetworkDHCPLeasePtr *leases_ret = NULL;
virNetworkObjPtr obj;
@@ -3801,7 +3801,7 @@ networkGetDHCPLeases(virNetworkPtr network,
}
if (!ipv6 && VIR_SOCKET_ADDR_IS_FAMILY(&ipdef_tmp->address,
AF_INET)) {
- lease->prefix = virSocketAddrGetIpPrefix(&ipdef_tmp->address,
+ lease->prefix = virSocketAddrGetIPPrefix(&ipdef_tmp->address,
&ipdef_tmp->netmask,
ipdef_tmp->prefix);
break;
@@ -4717,7 +4717,7 @@ networkGetNetworkAddress(const char *netname, char **netaddr)
int ret = -1;
virNetworkObjPtr network;
virNetworkDefPtr netdef;
- virNetworkIpDefPtr ipdef;
+ virNetworkIPDefPtr ipdef;
virSocketAddr addr;
virSocketAddrPtr addrptr = NULL;
char *dev_name = NULL;
@@ -4736,7 +4736,7 @@ networkGetNetworkAddress(const char *netname, char **netaddr)
case VIR_NETWORK_FORWARD_NONE:
case VIR_NETWORK_FORWARD_NAT:
case VIR_NETWORK_FORWARD_ROUTE:
- ipdef = virNetworkDefGetIpByIndex(netdef, AF_UNSPEC, 0);
+ ipdef = virNetworkDefGetIPByIndex(netdef, AF_UNSPEC, 0);
if (!ipdef) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("network '%s' doesn't have an IP address"),
diff --git a/src/network/bridge_driver_linux.c b/src/network/bridge_driver_linux.c
index bd7508c..b41a1ba 100644
--- a/src/network/bridge_driver_linux.c
+++ b/src/network/bridge_driver_linux.c
@@ -68,7 +68,7 @@ int networkCheckRouteCollision(virNetworkDefPtr def)
while (cur) {
char iface[17], dest[128], mask[128];
unsigned int addr_val, mask_val;
- virNetworkIpDefPtr ipdef;
+ virNetworkIPDefPtr ipdef;
virNetworkRouteDefPtr routedef;
int num;
size_t i;
@@ -100,13 +100,13 @@ int networkCheckRouteCollision(virNetworkDefPtr def)
addr_val &= mask_val;

for (i = 0;
- (ipdef = virNetworkDefGetIpByIndex(def, AF_INET, i));
+ (ipdef = virNetworkDefGetIPByIndex(def, AF_INET, i));
i++) {

unsigned int net_dest;
virSocketAddr netmask;

- if (virNetworkIpDefNetmask(ipdef, &netmask) < 0) {
+ if (virNetworkIPDefNetmask(ipdef, &netmask) < 0) {
VIR_WARN("Failed to get netmask of '%s'",
def->bridge);
continue;
@@ -165,9 +165,9 @@ static const char networkLocalBroadcast[] = "255.255.255.255/32";
static int
networkAddMasqueradingFirewallRules(virFirewallPtr fw,
virNetworkDefPtr def,
- virNetworkIpDefPtr ipdef)
+ virNetworkIPDefPtr ipdef)
{
- int prefix = virNetworkIpDefPrefix(ipdef);
+ int prefix = virNetworkIPDefPrefix(ipdef);
const char *forwardIf = virNetworkDefForwardIf(def, 0);

if (prefix < 0) {
@@ -279,9 +279,9 @@ networkAddMasqueradingFirewallRules(virFirewallPtr fw,
static int
networkRemoveMasqueradingFirewallRules(virFirewallPtr fw,
virNetworkDefPtr def,
- virNetworkIpDefPtr ipdef)
+ virNetworkIPDefPtr ipdef)
{
- int prefix = virNetworkIpDefPrefix(ipdef);
+ int prefix = virNetworkIPDefPrefix(ipdef);
const char *forwardIf = virNetworkDefForwardIf(def, 0);

if (prefix < 0)
@@ -349,9 +349,9 @@ networkRemoveMasqueradingFirewallRules(virFirewallPtr fw,
static int
networkAddRoutingFirewallRules(virFirewallPtr fw,
virNetworkDefPtr def,
- virNetworkIpDefPtr ipdef)
+ virNetworkIPDefPtr ipdef)
{
- int prefix = virNetworkIpDefPrefix(ipdef);
+ int prefix = virNetworkIPDefPrefix(ipdef);
const char *forwardIf = virNetworkDefForwardIf(def, 0);

if (prefix < 0) {
@@ -384,9 +384,9 @@ networkAddRoutingFirewallRules(virFirewallPtr fw,
static int
networkRemoveRoutingFirewallRules(virFirewallPtr fw,
virNetworkDefPtr def,
- virNetworkIpDefPtr ipdef)
+ virNetworkIPDefPtr ipdef)
{
- int prefix = virNetworkIpDefPrefix(ipdef);
+ int prefix = virNetworkIPDefPrefix(ipdef);
const char *forwardIf = virNetworkDefForwardIf(def, 0);

if (prefix < 0)
@@ -415,12 +415,12 @@ networkAddGeneralIPv4FirewallRules(virFirewallPtr fw,
virNetworkDefPtr def)
{
size_t i;
- virNetworkIpDefPtr ipv4def;
+ virNetworkIPDefPtr ipv4def;

/* First look for first IPv4 address that has dhcp or tftpboot defined. */
/* We support dhcp config on 1 IPv4 interface only. */
for (i = 0;
- (ipv4def = virNetworkDefGetIpByIndex(def, AF_INET, i));
+ (ipv4def = virNetworkDefGetIPByIndex(def, AF_INET, i));
i++) {
if (ipv4def->nranges || ipv4def->nhosts || ipv4def->tftproot)
break;
@@ -452,10 +452,10 @@ networkRemoveGeneralIPv4FirewallRules(virFirewallPtr fw,
virNetworkDefPtr def)
{
size_t i;
- virNetworkIpDefPtr ipv4def;
+ virNetworkIPDefPtr ipv4def;

for (i = 0;
- (ipv4def = virNetworkDefGetIpByIndex(def, AF_INET, i));
+ (ipv4def = virNetworkDefGetIPByIndex(def, AF_INET, i));
i++) {
if (ipv4def->nranges || ipv4def->nhosts || ipv4def->tftproot)
break;
@@ -487,7 +487,7 @@ networkAddGeneralIPv6FirewallRules(virFirewallPtr fw,
virNetworkDefPtr def)
{

- if (!virNetworkDefGetIpByIndex(def, AF_INET6, 0) &&
+ if (!virNetworkDefGetIPByIndex(def, AF_INET6, 0) &&
!def->ipv6nogw) {
return;
}
@@ -499,7 +499,7 @@ networkAddGeneralIPv6FirewallRules(virFirewallPtr fw,
/* Allow traffic between guests on the same bridge */
iptablesAddForwardAllowCross(fw, VIR_FIREWALL_LAYER_IPV6, def->bridge);

- if (virNetworkDefGetIpByIndex(def, AF_INET6, 0)) {
+ if (virNetworkDefGetIPByIndex(def, AF_INET6, 0)) {
/* allow DNS over IPv6 */
iptablesAddTcpInput(fw, VIR_FIREWALL_LAYER_IPV6, def->bridge, 53);
iptablesAddUdpInput(fw, VIR_FIREWALL_LAYER_IPV6, def->bridge, 53);
@@ -511,12 +511,12 @@ static void
networkRemoveGeneralIPv6FirewallRules(virFirewallPtr fw,
virNetworkDefPtr def)
{
- if (!virNetworkDefGetIpByIndex(def, AF_INET6, 0) &&
+ if (!virNetworkDefGetIPByIndex(def, AF_INET6, 0) &&
!def->ipv6nogw) {
return;
}

- if (virNetworkDefGetIpByIndex(def, AF_INET6, 0)) {
+ if (virNetworkDefGetIPByIndex(def, AF_INET6, 0)) {
iptablesRemoveUdpInput(fw, VIR_FIREWALL_LAYER_IPV6, def->bridge, 547);
iptablesRemoveUdpInput(fw, VIR_FIREWALL_LAYER_IPV6, def->bridge, 53);
iptablesRemoveTcpInput(fw, VIR_FIREWALL_LAYER_IPV6, def->bridge, 53);
@@ -553,12 +553,12 @@ networkAddChecksumFirewallRules(virFirewallPtr fw,
virNetworkDefPtr def)
{
size_t i;
- virNetworkIpDefPtr ipv4def;
+ virNetworkIPDefPtr ipv4def;

/* First look for first IPv4 address that has dhcp or tftpboot defined. */
/* We support dhcp config on 1 IPv4 interface only. */
for (i = 0;
- (ipv4def = virNetworkDefGetIpByIndex(def, AF_INET, i));
+ (ipv4def = virNetworkDefGetIPByIndex(def, AF_INET, i));
i++) {
if (ipv4def->nranges || ipv4def->nhosts)
break;
@@ -579,12 +579,12 @@ networkRemoveChecksumFirewallRules(virFirewallPtr fw,
virNetworkDefPtr def)
{
size_t i;
- virNetworkIpDefPtr ipv4def;
+ virNetworkIPDefPtr ipv4def;

/* First look for first IPv4 address that has dhcp or tftpboot defined. */
/* We support dhcp config on 1 IPv4 interface only. */
for (i = 0;
- (ipv4def = virNetworkDefGetIpByIndex(def, AF_INET, i));
+ (ipv4def = virNetworkDefGetIPByIndex(def, AF_INET, i));
i++) {
if (ipv4def->nranges || ipv4def->nhosts)
break;
@@ -596,9 +596,9 @@ networkRemoveChecksumFirewallRules(virFirewallPtr fw,


static int
-networkAddIpSpecificFirewallRules(virFirewallPtr fw,
+networkAddIPSpecificFirewallRules(virFirewallPtr fw,
virNetworkDefPtr def,
- virNetworkIpDefPtr ipdef)
+ virNetworkIPDefPtr ipdef)
{
/* NB: in the case of IPv6, routing rules are added when the
* forward mode is NAT. This is because IPv6 has no NAT.
@@ -617,9 +617,9 @@ networkAddIpSpecificFirewallRules(virFirewallPtr fw,


static int
-networkRemoveIpSpecificFirewallRules(virFirewallPtr fw,
+networkRemoveIPSpecificFirewallRules(virFirewallPtr fw,
virNetworkDefPtr def,
- virNetworkIpDefPtr ipdef)
+ virNetworkIPDefPtr ipdef)
{
if (def->forward.type == VIR_NETWORK_FORWARD_NAT) {
if (VIR_SOCKET_ADDR_IS_FAMILY(&ipdef->address, AF_INET))
@@ -637,7 +637,7 @@ networkRemoveIpSpecificFirewallRules(virFirewallPtr fw,
int networkAddFirewallRules(virNetworkDefPtr def)
{
size_t i;
- virNetworkIpDefPtr ipdef;
+ virNetworkIPDefPtr ipdef;
virFirewallPtr fw = NULL;
int ret = -1;

@@ -648,18 +648,18 @@ int networkAddFirewallRules(virNetworkDefPtr def)
networkAddGeneralFirewallRules(fw, def);

for (i = 0;
- (ipdef = virNetworkDefGetIpByIndex(def, AF_UNSPEC, i));
+ (ipdef = virNetworkDefGetIPByIndex(def, AF_UNSPEC, i));
i++) {
- if (networkAddIpSpecificFirewallRules(fw, def, ipdef) < 0)
+ if (networkAddIPSpecificFirewallRules(fw, def, ipdef) < 0)
goto cleanup;
}

virFirewallStartRollback(fw, 0);

for (i = 0;
- (ipdef = virNetworkDefGetIpByIndex(def, AF_UNSPEC, i));
+ (ipdef = virNetworkDefGetIPByIndex(def, AF_UNSPEC, i));
i++) {
- if (networkRemoveIpSpecificFirewallRules(fw, def, ipdef) < 0)
+ if (networkRemoveIPSpecificFirewallRules(fw, def, ipdef) < 0)
goto cleanup;
}
networkRemoveGeneralFirewallRules(fw, def);
@@ -680,7 +680,7 @@ int networkAddFirewallRules(virNetworkDefPtr def)
void networkRemoveFirewallRules(virNetworkDefPtr def)
{
size_t i;
- virNetworkIpDefPtr ipdef;
+ virNetworkIPDefPtr ipdef;
virFirewallPtr fw = NULL;

fw = virFirewallNew();
@@ -691,9 +691,9 @@ void networkRemoveFirewallRules(virNetworkDefPtr def)
virFirewallStartTransaction(fw, VIR_FIREWALL_TRANSACTION_IGNORE_ERRORS);

for (i = 0;
- (ipdef = virNetworkDefGetIpByIndex(def, AF_UNSPEC, i));
+ (ipdef = virNetworkDefGetIPByIndex(def, AF_UNSPEC, i));
i++) {
- if (networkRemoveIpSpecificFirewallRules(fw, def, ipdef) < 0)
+ if (networkRemoveIPSpecificFirewallRules(fw, def, ipdef) < 0)
goto cleanup;
}
networkRemoveGeneralFirewallRules(fw, def);
diff --git a/src/nwfilter/nwfilter_ebiptables_driver.c b/src/nwfilter/nwfilter_ebiptables_driver.c
index b7be291..0ab7c08 100644
--- a/src/nwfilter/nwfilter_ebiptables_driver.c
+++ b/src/nwfilter/nwfilter_ebiptables_driver.c
@@ -820,7 +820,7 @@ iptablesHandleSrcMacAddr(virFirewallPtr fw,


static int
-iptablesHandleIpHdr(virFirewallPtr fw,
+iptablesHandleIPHdr(virFirewallPtr fw,
virFirewallRulePtr fwrule,
virNWFilterVarCombIterPtr vars,
ipHdrDataDefPtr ipHdr,
@@ -972,7 +972,7 @@ iptablesHandleIpHdr(virFirewallPtr fw,


static int
-iptablesHandleIpHdrAfterStateMatch(virFirewallPtr fw,
+iptablesHandleIPHdrAfterStateMatch(virFirewallPtr fw,
virFirewallRulePtr fwrule,
virNWFilterVarCombIterPtr vars,
ipHdrDataDefPtr ipHdr,
@@ -1200,7 +1200,7 @@ _iptablesCreateRuleInstance(virFirewallPtr fw,
&srcMacSkipped) < 0)
goto cleanup;

- if (iptablesHandleIpHdr(fw, fwrule,
+ if (iptablesHandleIPHdr(fw, fwrule,
vars,
&rule->p.tcpHdrFilter.ipHdr,
directionIn,
@@ -1259,7 +1259,7 @@ _iptablesCreateRuleInstance(virFirewallPtr fw,
&srcMacSkipped) < 0)
goto cleanup;

- if (iptablesHandleIpHdr(fw, fwrule,
+ if (iptablesHandleIPHdr(fw, fwrule,
vars,
&rule->p.udpHdrFilter.ipHdr,
directionIn,
@@ -1289,7 +1289,7 @@ _iptablesCreateRuleInstance(virFirewallPtr fw,
&srcMacSkipped) < 0)
goto cleanup;

- if (iptablesHandleIpHdr(fw, fwrule,
+ if (iptablesHandleIPHdr(fw, fwrule,
vars,
&rule->p.udpliteHdrFilter.ipHdr,
directionIn,
@@ -1314,7 +1314,7 @@ _iptablesCreateRuleInstance(virFirewallPtr fw,
&srcMacSkipped) < 0)
goto cleanup;

- if (iptablesHandleIpHdr(fw, fwrule,
+ if (iptablesHandleIPHdr(fw, fwrule,
vars,
&rule->p.espHdrFilter.ipHdr,
directionIn,
@@ -1339,7 +1339,7 @@ _iptablesCreateRuleInstance(virFirewallPtr fw,
&srcMacSkipped) < 0)
goto cleanup;

- if (iptablesHandleIpHdr(fw, fwrule,
+ if (iptablesHandleIPHdr(fw, fwrule,
vars,
&rule->p.ahHdrFilter.ipHdr,
directionIn,
@@ -1364,7 +1364,7 @@ _iptablesCreateRuleInstance(virFirewallPtr fw,
&srcMacSkipped) < 0)
goto cleanup;

- if (iptablesHandleIpHdr(fw, fwrule,
+ if (iptablesHandleIPHdr(fw, fwrule,
vars,
&rule->p.sctpHdrFilter.ipHdr,
directionIn,
@@ -1400,7 +1400,7 @@ _iptablesCreateRuleInstance(virFirewallPtr fw,
&srcMacSkipped) < 0)
goto cleanup;

- if (iptablesHandleIpHdr(fw, fwrule,
+ if (iptablesHandleIPHdr(fw, fwrule,
vars,
&rule->p.icmpHdrFilter.ipHdr,
directionIn,
@@ -1461,7 +1461,7 @@ _iptablesCreateRuleInstance(virFirewallPtr fw,
&srcMacSkipped) < 0)
goto cleanup;

- if (iptablesHandleIpHdr(fw, fwrule,
+ if (iptablesHandleIPHdr(fw, fwrule,
vars,
&rule->p.igmpHdrFilter.ipHdr,
directionIn,
@@ -1486,7 +1486,7 @@ _iptablesCreateRuleInstance(virFirewallPtr fw,
&srcMacSkipped) < 0)
goto cleanup;

- if (iptablesHandleIpHdr(fw, fwrule,
+ if (iptablesHandleIPHdr(fw, fwrule,
vars,
&rule->p.allHdrFilter.ipHdr,
directionIn,
@@ -1534,7 +1534,7 @@ _iptablesCreateRuleInstance(virFirewallPtr fw,
directionIn,
rule);

- if (iptablesHandleIpHdrAfterStateMatch(fw, fwrule,
+ if (iptablesHandleIPHdrAfterStateMatch(fw, fwrule,
vars,
&rule->p.allHdrFilter.ipHdr,
directionIn) < 0)
diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c
index 820dc22..8c77eff 100644
--- a/src/openvz/openvz_conf.c
+++ b/src/openvz/openvz_conf.c
@@ -220,7 +220,7 @@ openvzReadNetworkConf(virDomainDefPtr def,
goto error;

net->type = VIR_DOMAIN_NET_TYPE_ETHERNET;
- if (virDomainNetAppendIpAddress(net, token, AF_UNSPEC, 0) < 0)
+ if (virDomainNetAppendIPAddress(net, token, AF_UNSPEC, 0) < 0)
goto error;

if (VIR_APPEND_ELEMENT_COPY(def->nets, def->nnets, net) < 0)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index fa05046..294a1b0 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -7048,7 +7048,7 @@ static char *qemuConnectDomainXMLToNative(virConnectPtr conn,
char *script = net->script;
char *brname = net->data.bridge.brname;
size_t nips = net->nips;
- virDomainNetIpDefPtr *ips = net->ips;
+ virDomainNetIPDefPtr *ips = net->ips;

memset(net, 0, sizeof(*net));

diff --git a/src/util/virsocketaddr.c b/src/util/virsocketaddr.c
index 98cb4ca..12fe96a 100644
--- a/src/util/virsocketaddr.c
+++ b/src/util/virsocketaddr.c
@@ -1011,7 +1011,7 @@ virSocketAddrPrefixToNetmask(unsigned int prefix,
}

/**
- * virSocketAddrGetIpPrefix:
+ * virSocketAddrGetIPPrefix:
* @address: network address
* @netmask: netmask for this network
* @prefix: prefix if specified instead of netmask
@@ -1020,7 +1020,7 @@ virSocketAddrPrefixToNetmask(unsigned int prefix,
*/

int
-virSocketAddrGetIpPrefix(const virSocketAddr *address,
+virSocketAddrGetIPPrefix(const virSocketAddr *address,
const virSocketAddr *netmask,
int prefix)
{
diff --git a/src/util/virsocketaddr.h b/src/util/virsocketaddr.h
index c7aaa61..990e31c 100644
--- a/src/util/virsocketaddr.h
+++ b/src/util/virsocketaddr.h
@@ -125,7 +125,7 @@ int virSocketAddrGetNumNetmaskBits(const virSocketAddr *netmask);
int virSocketAddrPrefixToNetmask(unsigned int prefix,
virSocketAddrPtr netmask,
int family);
-int virSocketAddrGetIpPrefix(const virSocketAddr *address,
+int virSocketAddrGetIPPrefix(const virSocketAddr *address,
const virSocketAddr *netmask,
int prefix);
bool virSocketAddrEqual(const virSocketAddr *s1,
diff --git a/src/vbox/vbox_network.c b/src/vbox/vbox_network.c
index 4cfc365..0b944b6 100644
--- a/src/vbox/vbox_network.c
+++ b/src/vbox/vbox_network.c
@@ -376,7 +376,7 @@ vboxNetworkDefineCreateXML(virConnectPtr conn, const char *xml, bool start)
char *networkNameUtf8 = NULL;
IHostNetworkInterface *networkInterface = NULL;
virNetworkDefPtr def = virNetworkDefParseString(xml);
- virNetworkIpDefPtr ipdef = NULL;
+ virNetworkIPDefPtr ipdef = NULL;
unsigned char uuid[VIR_UUID_BUFLEN];
vboxIIDUnion vboxnetiid;
virSocketAddr netmask;
@@ -402,11 +402,11 @@ vboxNetworkDefineCreateXML(virConnectPtr conn, const char *xml, bool start)
* If there weren't any IPv4 addresses, ignore the network (since it's
* required below to have an IPv4 address)
*/
- ipdef = virNetworkDefGetIpByIndex(def, AF_INET, 0);
+ ipdef = virNetworkDefGetIPByIndex(def, AF_INET, 0);
if (!ipdef)
goto cleanup;

- if (virNetworkIpDefNetmask(ipdef, &netmask) < 0)
+ if (virNetworkIPDefNetmask(ipdef, &netmask) < 0)
goto cleanup;

/* the current limitation of hostonly network is that you can't
@@ -762,7 +762,7 @@ static char *vboxNetworkGetXMLDesc(virNetworkPtr network, unsigned int flags)
{
vboxGlobalData *data = network->conn->privateData;
virNetworkDefPtr def = NULL;
- virNetworkIpDefPtr ipdef = NULL;
+ virNetworkIPDefPtr ipdef = NULL;
char *networkNameUtf8 = NULL;
PRUnichar *networkInterfaceNameUtf16 = NULL;
IHostNetworkInterface *networkInterface = NULL;
diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c
index 98a22b8..2fe29fd 100644
--- a/src/xenconfig/xen_common.c
+++ b/src/xenconfig/xen_common.c
@@ -935,7 +935,7 @@ xenParseVif(virConfPtr conf, virDomainDefPtr def, const char *vif_typename)
if (bridge[0] && VIR_STRDUP(net->data.bridge.brname, bridge) < 0)
goto cleanup;
}
- if (ip[0] && virDomainNetAppendIpAddress(net, ip, AF_INET, 0) < 0)
+ if (ip[0] && virDomainNetAppendIPAddress(net, ip, AF_INET, 0) < 0)
goto cleanup;

if (script && script[0] &&
diff --git a/src/xenconfig/xen_sxpr.c b/src/xenconfig/xen_sxpr.c
index 653b7b3..21de1a2 100644
--- a/src/xenconfig/xen_sxpr.c
+++ b/src/xenconfig/xen_sxpr.c
@@ -619,14 +619,14 @@ xenParseSxprNets(virDomainDefPtr def,
VIR_STRDUP(net->script, tmp2) < 0)
goto cleanup;
tmp = sexpr_node(node, "device/vif/ip");
- if (tmp && virDomainNetAppendIpAddress(net, tmp, AF_UNSPEC, 0) < 0)
+ if (tmp && virDomainNetAppendIPAddress(net, tmp, AF_UNSPEC, 0) < 0)
goto cleanup;
} else {
net->type = VIR_DOMAIN_NET_TYPE_ETHERNET;
if (VIR_STRDUP(net->script, tmp2) < 0)
goto cleanup;
tmp = sexpr_node(node, "device/vif/ip");
- if (tmp && virDomainNetAppendIpAddress(net, tmp, AF_UNSPEC, 0) < 0)
+ if (tmp && virDomainNetAppendIPAddress(net, tmp, AF_UNSPEC, 0) < 0)
goto cleanup;
}
--
2.5.5
John Ferlan
2016-06-23 20:25:51 UTC
Permalink
Post by Laine Stump
I'm tired of mistyping this all the time, so let's do it the same all
the time (similar to how we changed all "Pci" to "PCI" awhile back).
(NB: I've left alone some things in the esx and vbox drivers because
I'm unable to compile them and they weren't obviously *not* a part of
some API. I also didn't change a couple of variables named,
e.g. "somethingIptables", because they were derived from the name of
the "iptables" command)
---
src/conf/domain_conf.c | 24 +++++-----
src/conf/domain_conf.h | 12 ++---
src/conf/interface_conf.c | 38 +++++++--------
src/conf/interface_conf.h | 8 ++--
src/conf/network_conf.c | 80 +++++++++++++++----------------
src/conf/network_conf.h | 20 ++++----
src/conf/networkcommon_conf.c | 6 +--
src/esx/esx_driver.c | 44 ++++++++---------
src/esx/esx_interface_driver.c | 4 +-
src/esx/esx_vi.c | 4 +-
src/esx/esx_vi.h | 2 +-
src/libvirt_private.syms | 10 ++--
src/lxc/lxc_container.c | 2 +-
src/lxc/lxc_native.c | 4 +-
src/network/bridge_driver.c | 74 ++++++++++++++--------------
src/network/bridge_driver_linux.c | 70 +++++++++++++--------------
src/nwfilter/nwfilter_ebiptables_driver.c | 24 +++++-----
src/openvz/openvz_conf.c | 2 +-
src/qemu/qemu_driver.c | 2 +-
src/util/virsocketaddr.c | 4 +-
src/util/virsocketaddr.h | 2 +-
src/vbox/vbox_network.c | 8 ++--
src/xenconfig/xen_common.c | 2 +-
src/xenconfig/xen_sxpr.c | 4 +-
24 files changed, 225 insertions(+), 225 deletions(-)
It's a type "A" type change ;-)

I think I am going to need that eye exam after all...

[...]
Post by Laine Stump
diff --git a/src/conf/interface_conf.c b/src/conf/interface_conf.c
index 26e55cc..40f1958 100644
--- a/src/conf/interface_conf.c
+++ b/src/conf/interface_conf.c
@@ -45,7 +45,7 @@ virInterfaceDefDevFormat(virBufferPtr buf, const virInterfaceDef *def,
virInterfaceType parentIfType);
static
-void virInterfaceIpDefFree(virInterfaceIpDefPtr def)
+void virInterfaceIPDefFree(virInterfaceIPDefPtr def)
{
if (def == NULL)
return;
@@ -61,7 +61,7 @@ void virInterfaceProtocolDefFree(virInterfaceProtocolDefPtr def)
if (def == NULL)
return;
for (i = 0; i < def->nips; i++)
- virInterfaceIpDefFree(def->ips[i]);
+ virInterfaceIPDefFree(def->ips[i]);
VIR_FREE(def->ips);
VIR_FREE(def->family);
VIR_FREE(def->gateway);
@@ -281,7 +281,7 @@ virInterfaceDefParseDhcp(virInterfaceProtocolDefPtr def,
}
static int
-virInterfaceDefParseIp(virInterfaceIpDefPtr def,
+virInterfaceDefParseIP(virInterfaceIPDefPtr def,
xmlXPathContextPtr ctxt)
{
int ret = 0;
@@ -310,7 +310,7 @@ virInterfaceDefParseProtoIPv4(virInterfaceProtocolDefPtr def,
{
xmlNodePtr dhcp;
xmlNodePtr *ipNodes = NULL;
- int nIpNodes, ret = -1;
+ int nIPNodes, ret = -1;
You changed a variable name here which while I suppose is correct leads
me to wonder why "ipNodes" wasn't changed as well.

In the long run though, in whatever manner "ip" is used, it should be
consistent between "n[ip|IP]Nodes" and [ip|IP]Nodes... I'd lean towards
ipNodes and nipNodes...
Post by Laine Stump
size_t i;
char *tmp;
@@ -323,26 +323,26 @@ virInterfaceDefParseProtoIPv4(virInterfaceProtocolDefPtr def,
return -1;
}
- nIpNodes = virXPathNodeSet("./ip", ctxt, &ipNodes);
- if (nIpNodes < 0)
+ nIPNodes = virXPathNodeSet("./ip", ctxt, &ipNodes);
+ if (nIPNodes < 0)
return -1;
if (ipNodes == NULL)
return 0;
- if (VIR_ALLOC_N(def->ips, nIpNodes) < 0)
+ if (VIR_ALLOC_N(def->ips, nIPNodes) < 0)
goto error;
def->nips = 0;
- for (i = 0; i < nIpNodes; i++) {
+ for (i = 0; i < nIPNodes; i++) {
- virInterfaceIpDefPtr ip;
+ virInterfaceIPDefPtr ip;
if (VIR_ALLOC(ip) < 0)
goto error;
ctxt->node = ipNodes[i];
- if (virInterfaceDefParseIp(ip, ctxt) < 0) {
- virInterfaceIpDefFree(ip);
+ if (virInterfaceDefParseIP(ip, ctxt) < 0) {
+ virInterfaceIPDefFree(ip);
goto error;
}
def->ips[def->nips++] = ip;
@@ -361,7 +361,7 @@ virInterfaceDefParseProtoIPv6(virInterfaceProtocolDefPtr def,
{
xmlNodePtr dhcp, autoconf;
xmlNodePtr *ipNodes = NULL;
- int nIpNodes, ret = -1;
+ int nIPNodes, ret = -1;
Same here.
Post by Laine Stump
size_t i;
char *tmp;
@@ -378,26 +378,26 @@ virInterfaceDefParseProtoIPv6(virInterfaceProtocolDefPtr def,
return -1;
}
- nIpNodes = virXPathNodeSet("./ip", ctxt, &ipNodes);
- if (nIpNodes < 0)
+ nIPNodes = virXPathNodeSet("./ip", ctxt, &ipNodes);
+ if (nIPNodes < 0)
return -1;
if (ipNodes == NULL)
return 0;
- if (VIR_ALLOC_N(def->ips, nIpNodes) < 0)
+ if (VIR_ALLOC_N(def->ips, nIPNodes) < 0)
goto error;
def->nips = 0;
- for (i = 0; i < nIpNodes; i++) {
+ for (i = 0; i < nIPNodes; i++) {
- virInterfaceIpDefPtr ip;
+ virInterfaceIPDefPtr ip;
if (VIR_ALLOC(ip) < 0)
goto error;
ctxt->node = ipNodes[i];
- if (virInterfaceDefParseIp(ip, ctxt) < 0) {
- virInterfaceIpDefFree(ip);
+ if (virInterfaceDefParseIP(ip, ctxt) < 0) {
+ virInterfaceIPDefFree(ip);
goto error;
}
def->ips[def->nips++] = ip;
[...]
Post by Laine Stump
diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index 02b8cd7..5ae2bdf 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
[...]
Post by Laine Stump
@@ -2050,7 +2050,7 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt)
xmlNodePtr *ipNodes = NULL;
xmlNodePtr *routeNodes = NULL;
xmlNodePtr *portGroupNodes = NULL;
- int nIps, nPortGroups, nRoutes;
+ int nips, nPortGroups, nRoutes;
nips "could be" nipNodes

Your call - since you're here anyway dealing with consistency.

ACK - w/ at least the other one changed - if it causes too much of a
ripple effect later on (I haven't peeked ahead)...

John
Post by Laine Stump
xmlNodePtr dnsNode = NULL;
xmlNodePtr virtPortNode = NULL;
xmlNodePtr forwardNode = NULL;
@@ -2227,18 +2227,18 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt)
}
VIR_FREE(portGroupNodes);
- nIps = virXPathNodeSet("./ip", ctxt, &ipNodes);
- if (nIps < 0)
+ nips = virXPathNodeSet("./ip", ctxt, &ipNodes);
+ if (nips < 0)
goto error;
- if (nIps > 0) {
+ if (nips > 0) {
size_t i;
/* allocate array to hold all the addrs */
- if (VIR_ALLOC_N(def->ips, nIps) < 0)
+ if (VIR_ALLOC_N(def->ips, nips) < 0)
goto error;
/* parse each addr */
- for (i = 0; i < nIps; i++) {
+ for (i = 0; i < nips; i++) {
if (virNetworkIPDefParseXML(def->name,
ipNodes[i],
ctxt,
@@ -2278,7 +2278,7 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt)
* is directly reachable from this bridge.
*/
nRoutes = def->nroutes;
- nIps = def->nips;
+ nips = def->nips;
for (i = 0; i < nRoutes; i++) {
size_t j;
virSocketAddr testAddr, testGw;
@@ -2286,13 +2286,13 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt)
virNetworkRouteDefPtr gwdef = def->routes[i];
virSocketAddrPtr gateway = virNetworkRouteDefGetGateway(gwdef);
addrMatch = false;
- for (j = 0; j < nIps; j++) {
- virNetworkIpDefPtr def2 = &def->ips[j];
+ for (j = 0; j < nips; j++) {
+ virNetworkIPDefPtr def2 = &def->ips[j];
if (VIR_SOCKET_ADDR_FAMILY(gateway)
!= VIR_SOCKET_ADDR_FAMILY(&def2->address)) {
continue;
}
- int prefix = virNetworkIpDefPrefix(def2);
+ int prefix = virNetworkIPDefPrefix(def2);
virSocketAddrMaskByPrefix(&def2->address, prefix, &testAddr);
virSocketAddrMaskByPrefix(gateway, prefix, &testGw);
if (VIR_SOCKET_ADDR_VALID(&testAddr) &&
[...]
Laine Stump
2016-06-24 17:04:52 UTC
Permalink
Post by John Ferlan
Post by Laine Stump
I'm tired of mistyping this all the time, so let's do it the same all
the time (similar to how we changed all "Pci" to "PCI" awhile back).
(NB: I've left alone some things in the esx and vbox drivers because
I'm unable to compile them and they weren't obviously *not* a part of
some API. I also didn't change a couple of variables named,
e.g. "somethingIptables", because they were derived from the name of
the "iptables" command)
---
src/conf/domain_conf.c | 24 +++++-----
src/conf/domain_conf.h | 12 ++---
src/conf/interface_conf.c | 38 +++++++--------
src/conf/interface_conf.h | 8 ++--
src/conf/network_conf.c | 80 +++++++++++++++----------------
src/conf/network_conf.h | 20 ++++----
src/conf/networkcommon_conf.c | 6 +--
src/esx/esx_driver.c | 44 ++++++++---------
src/esx/esx_interface_driver.c | 4 +-
src/esx/esx_vi.c | 4 +-
src/esx/esx_vi.h | 2 +-
src/libvirt_private.syms | 10 ++--
src/lxc/lxc_container.c | 2 +-
src/lxc/lxc_native.c | 4 +-
src/network/bridge_driver.c | 74 ++++++++++++++--------------
src/network/bridge_driver_linux.c | 70 +++++++++++++--------------
src/nwfilter/nwfilter_ebiptables_driver.c | 24 +++++-----
src/openvz/openvz_conf.c | 2 +-
src/qemu/qemu_driver.c | 2 +-
src/util/virsocketaddr.c | 4 +-
src/util/virsocketaddr.h | 2 +-
src/vbox/vbox_network.c | 8 ++--
src/xenconfig/xen_common.c | 2 +-
src/xenconfig/xen_sxpr.c | 4 +-
24 files changed, 225 insertions(+), 225 deletions(-)
It's a type "A" type change ;-)
I think I am going to need that eye exam after all...
[...]
Post by Laine Stump
diff --git a/src/conf/interface_conf.c b/src/conf/interface_conf.c
index 26e55cc..40f1958 100644
--- a/src/conf/interface_conf.c
+++ b/src/conf/interface_conf.c
@@ -45,7 +45,7 @@ virInterfaceDefDevFormat(virBufferPtr buf, const virInterfaceDef *def,
virInterfaceType parentIfType);
static
-void virInterfaceIpDefFree(virInterfaceIpDefPtr def)
+void virInterfaceIPDefFree(virInterfaceIPDefPtr def)
{
if (def == NULL)
return;
@@ -61,7 +61,7 @@ void virInterfaceProtocolDefFree(virInterfaceProtocolDefPtr def)
if (def == NULL)
return;
for (i = 0; i < def->nips; i++)
- virInterfaceIpDefFree(def->ips[i]);
+ virInterfaceIPDefFree(def->ips[i]);
VIR_FREE(def->ips);
VIR_FREE(def->family);
VIR_FREE(def->gateway);
@@ -281,7 +281,7 @@ virInterfaceDefParseDhcp(virInterfaceProtocolDefPtr def,
}
static int
-virInterfaceDefParseIp(virInterfaceIpDefPtr def,
+virInterfaceDefParseIP(virInterfaceIPDefPtr def,
xmlXPathContextPtr ctxt)
{
int ret = 0;
@@ -310,7 +310,7 @@ virInterfaceDefParseProtoIPv4(virInterfaceProtocolDefPtr def,
{
xmlNodePtr dhcp;
xmlNodePtr *ipNodes = NULL;
- int nIpNodes, ret = -1;
+ int nIPNodes, ret = -1;
You changed a variable name here which while I suppose is correct leads
me to wonder why "ipNodes" wasn't changed as well.
In the long run though, in whatever manner "ip" is used, it should be
consistent between "n[ip|IP]Nodes" and [ip|IP]Nodes... I'd lean towards
ipNodes and nipNodes...
I agree with you (although I can't really articulate why). The nIPNodes
was an oversight. I'll fix it before pushing.
Post by John Ferlan
Post by Laine Stump
size_t i;
char *tmp;
@@ -323,26 +323,26 @@ virInterfaceDefParseProtoIPv4(virInterfaceProtocolDefPtr def,
return -1;
}
- nIpNodes = virXPathNodeSet("./ip", ctxt, &ipNodes);
- if (nIpNodes < 0)
+ nIPNodes = virXPathNodeSet("./ip", ctxt, &ipNodes);
+ if (nIPNodes < 0)
return -1;
if (ipNodes == NULL)
return 0;
- if (VIR_ALLOC_N(def->ips, nIpNodes) < 0)
+ if (VIR_ALLOC_N(def->ips, nIPNodes) < 0)
goto error;
def->nips = 0;
- for (i = 0; i < nIpNodes; i++) {
+ for (i = 0; i < nIPNodes; i++) {
- virInterfaceIpDefPtr ip;
+ virInterfaceIPDefPtr ip;
if (VIR_ALLOC(ip) < 0)
goto error;
ctxt->node = ipNodes[i];
- if (virInterfaceDefParseIp(ip, ctxt) < 0) {
- virInterfaceIpDefFree(ip);
+ if (virInterfaceDefParseIP(ip, ctxt) < 0) {
+ virInterfaceIPDefFree(ip);
goto error;
}
def->ips[def->nips++] = ip;
@@ -361,7 +361,7 @@ virInterfaceDefParseProtoIPv6(virInterfaceProtocolDefPtr def,
{
xmlNodePtr dhcp, autoconf;
xmlNodePtr *ipNodes = NULL;
- int nIpNodes, ret = -1;
+ int nIPNodes, ret = -1;
Same here.
Post by Laine Stump
size_t i;
char *tmp;
@@ -378,26 +378,26 @@ virInterfaceDefParseProtoIPv6(virInterfaceProtocolDefPtr def,
return -1;
}
- nIpNodes = virXPathNodeSet("./ip", ctxt, &ipNodes);
- if (nIpNodes < 0)
+ nIPNodes = virXPathNodeSet("./ip", ctxt, &ipNodes);
+ if (nIPNodes < 0)
return -1;
if (ipNodes == NULL)
return 0;
- if (VIR_ALLOC_N(def->ips, nIpNodes) < 0)
+ if (VIR_ALLOC_N(def->ips, nIPNodes) < 0)
goto error;
def->nips = 0;
- for (i = 0; i < nIpNodes; i++) {
+ for (i = 0; i < nIPNodes; i++) {
- virInterfaceIpDefPtr ip;
+ virInterfaceIPDefPtr ip;
if (VIR_ALLOC(ip) < 0)
goto error;
ctxt->node = ipNodes[i];
- if (virInterfaceDefParseIp(ip, ctxt) < 0) {
- virInterfaceIpDefFree(ip);
+ if (virInterfaceDefParseIP(ip, ctxt) < 0) {
+ virInterfaceIPDefFree(ip);
goto error;
}
def->ips[def->nips++] = ip;
[...]
Post by Laine Stump
diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index 02b8cd7..5ae2bdf 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
[...]
Post by Laine Stump
@@ -2050,7 +2050,7 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt)
xmlNodePtr *ipNodes = NULL;
xmlNodePtr *routeNodes = NULL;
xmlNodePtr *portGroupNodes = NULL;
- int nIps, nPortGroups, nRoutes;
+ int nips, nPortGroups, nRoutes;
nips "could be" nipNodes
Your call - since you're here anyway dealing with consistency.
ACK - w/ at least the other one changed - if it causes too much of a
ripple effect later on (I haven't peeked ahead)...
John
Post by Laine Stump
xmlNodePtr dnsNode = NULL;
xmlNodePtr virtPortNode = NULL;
xmlNodePtr forwardNode = NULL;
@@ -2227,18 +2227,18 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt)
}
VIR_FREE(portGroupNodes);
- nIps = virXPathNodeSet("./ip", ctxt, &ipNodes);
- if (nIps < 0)
+ nips = virXPathNodeSet("./ip", ctxt, &ipNodes);
+ if (nips < 0)
goto error;
- if (nIps > 0) {
+ if (nips > 0) {
size_t i;
/* allocate array to hold all the addrs */
- if (VIR_ALLOC_N(def->ips, nIps) < 0)
+ if (VIR_ALLOC_N(def->ips, nips) < 0)
goto error;
/* parse each addr */
- for (i = 0; i < nIps; i++) {
+ for (i = 0; i < nips; i++) {
if (virNetworkIPDefParseXML(def->name,
ipNodes[i],
ctxt,
@@ -2278,7 +2278,7 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt)
* is directly reachable from this bridge.
*/
nRoutes = def->nroutes;
- nIps = def->nips;
+ nips = def->nips;
for (i = 0; i < nRoutes; i++) {
size_t j;
virSocketAddr testAddr, testGw;
@@ -2286,13 +2286,13 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt)
virNetworkRouteDefPtr gwdef = def->routes[i];
virSocketAddrPtr gateway = virNetworkRouteDefGetGateway(gwdef);
addrMatch = false;
- for (j = 0; j < nIps; j++) {
- virNetworkIpDefPtr def2 = &def->ips[j];
+ for (j = 0; j < nips; j++) {
+ virNetworkIPDefPtr def2 = &def->ips[j];
if (VIR_SOCKET_ADDR_FAMILY(gateway)
!= VIR_SOCKET_ADDR_FAMILY(&def2->address)) {
continue;
}
- int prefix = virNetworkIpDefPrefix(def2);
+ int prefix = virNetworkIPDefPrefix(def2);
virSocketAddrMaskByPrefix(&def2->address, prefix, &testAddr);
virSocketAddrMaskByPrefix(gateway, prefix, &testGw);
if (VIR_SOCKET_ADDR_VALID(&testAddr) &&
[...]
John Ferlan
2016-06-23 21:36:42 UTC
Permalink
Post by Laine Stump
Commit c9a641 (first appearred in 1.2.12) added support for setting
the guest-side IP address of veth devices in lxc domains.
Unfortunately, it hardcoded the assumption that the proper prefix for
any IP address with no explicit prefix in the config should be "24";
that is only correct for class C IPv4 addresses, but not for any other
IPv4 address, nor for any IPv6 address.
The good news is that there is already a function in libvirt that will
determine the proper default prefix for any IP address. This patch
replaces the use of the ill-fated VIR_SOCKET_ADDR_DEFAULT_PREFIX with
calls to virSocketAddrGetIPPrefix().
---
src/lxc/lxc_container.c | 17 ++++++++++++-----
src/util/virsocketaddr.h | 1 -
2 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c
index 3d9e28b..304aa86 100644
--- a/src/lxc/lxc_container.c
+++ b/src/lxc/lxc_container.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2008-2015 Red Hat, Inc.
+ * Copyright (C) 2008-2016 Red Hat, Inc.
* Copyright (C) 2008 IBM Corp.
* Copyright (c) 2015 SUSE LINUX Products GmbH, Nuernberg, Germany.
*
@@ -514,12 +514,19 @@ static int lxcContainerRenameAndEnableInterfaces(virDomainDefPtr vmDef,
for (j = 0; j < netDef->nips; j++) {
virDomainNetIPDefPtr ip = netDef->ips[j];
- VIR_SOCKET_ADDR_DEFAULT_PREFIX;
+ int prefix;
char *ipStr = virSocketAddrFormat(&ip->address);
- VIR_DEBUG("Adding IP address '%s/%u' to '%s'",
- ipStr, ip->prefix, newname);
+ if ((prefix = virSocketAddrGetIPPrefix(&ip->address,
+ NULL, ip->prefix)) < 0) {
Oh and here we go call with NULL ...
Post by Laine Stump
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Failed to determine prefix for IP address '%s'"),
+ ipStr);
Coverity determines that ipStr needs to be VIR_FREE()'d here.

ACK w/ the VIR_FREE()

John
Post by Laine Stump
+ goto error_out;
+ }
+
+ VIR_DEBUG("Adding IP address '%s/%d' to '%s'",
+ ipStr, prefix, newname);
if (virNetDevSetIPAddress(newname, &ip->address, NULL, prefix) < 0) {
virReportError(VIR_ERR_SYSTEM_ERROR,
_("Failed to set IP address '%s' on %s"),
diff --git a/src/util/virsocketaddr.h b/src/util/virsocketaddr.h
index 990e31c..7ee993b 100644
--- a/src/util/virsocketaddr.h
+++ b/src/util/virsocketaddr.h
@@ -54,7 +54,6 @@ typedef struct {
# define VIR_SOCKET_ADDR_FAMILY(s) \
((s)->data.sa.sa_family)
-# define VIR_SOCKET_ADDR_DEFAULT_PREFIX 24
# define VIR_SOCKET_ADDR_IPV4_ALL "0.0.0.0"
# define VIR_SOCKET_ADDR_IPV6_ALL "::"
Loading...