[libvirt] [PATCH v4 03/17] LXC: set IP addresses to veth devices in the container
Dmitry Guryanov
dguryanov at parallels.com
Tue Dec 2 13:57:12 UTC 2014
On Thursday 13 November 2014 10:33:02 Cédric Bosdonnat wrote:
> Uses the new virDomainNetDef ips to set the IP addresses on the network
> interfaces in the container.
> ---
> src/lxc/lxc_container.c | 19 ++++++++++++++++++-
> 1 file changed, 18 insertions(+), 1 deletion(-)
>
> diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c
> index 8aba3ba..4aeb19c 100644
> --- a/src/lxc/lxc_container.c
> +++ b/src/lxc/lxc_container.c
> @@ -496,7 +496,7 @@ static int
> lxcContainerRenameAndEnableInterfaces(virDomainDefPtr vmDef, char **veths)
> {
> int rc = 0;
> - size_t i;
> + size_t i, j;
> char *newname = NULL;
> virDomainNetDefPtr netDef;
> bool privNet = vmDef->features[VIR_DOMAIN_FEATURE_PRIVNET] ==
> @@ -517,6 +517,23 @@ static int
> lxcContainerRenameAndEnableInterfaces(virDomainDefPtr vmDef, if (rc < 0)
> goto error_out;
>
> + for (j = 0; j < netDef->nips; j++) {
> + virDomainNetIpDefPtr ip = netDef->ips[j];
> + unsigned int prefix = (ip->prefix > 0) ? ip->prefix : 24;
Why is default prefix hardcoded here? I think we should add a constant for it
in some common header file.
> + char *ipStr = virSocketAddrFormat(&ip->address);
> +
> + VIR_DEBUG("Adding IP address '%s/%u' to '%s'",
> + ipStr, ip->prefix, newname);
> + if (virNetDevSetIPv4Address(newname, &ip->address, prefix) < 0)
> { + virReportError(VIR_ERR_SYSTEM_ERROR,
> + _("Failed to set IP address '%s' on %s"),
> + ipStr, newname);
> + VIR_FREE(ipStr);
> + goto error_out;
> + }
> + VIR_FREE(ipStr);
> + }
> +
> VIR_DEBUG("Enabling %s", newname);
> rc = virNetDevSetOnline(newname, true);
> if (rc < 0)
--
Dmitry Guryanov
More information about the libvir-list
mailing list