Re: [PATCHv3 03/16] LXC: set IP addresses to veth devices in the container

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Oct 10, 2014 at 02:03:55PM +0200, 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 | 24 +++++++++++++++++++++++-
>  1 file changed, 23 insertions(+), 1 deletion(-)
> 
> diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c
> index 2af2674..608d39f 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,28 @@ 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;
> +            virSocketAddr address;
> +            int family = AF_INET;
> +
> +            if (strchr(ip->address, ':'))
> +                family = AF_INET6;
> +
> +            if (virSocketAddrParse(&address, ip->address, family) < 0)
> +                goto error_out;

Hmm, so this again makes me think we should have another patch in the series
just before this, but after the first XML patch, which converts the virDomainConf
to use  virSocketAddr directly. I think it would be good practice for us to extend
the XML to include teh address family too, instead of just doing strchr for ':'
to detect IPv6.

> +
> +            VIR_DEBUG("Adding IP address '%s/%u' to '%s'",
> +                      ip->address, ip->prefix, newname);
> +            if (virNetDevSetIPv4Address(newname, &address, prefix) < 0) {
> +                virReportError(VIR_ERR_SYSTEM_ERROR,
> +                               _("Failed to set IP address '%s' on %s"),
> +                               ip->address, newname);
> +                goto error_out;
> +            }
> +        }
> +

Regards,
Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list





[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]