[lxc-devel] [PATCH] lxc: let lxc-start support wlan phys

Serge Hallyn serge.hallyn at ubuntu.com
Tue Dec 1 15:18:08 UTC 2015


Quoting fupan.li at windriver.com (fupan.li at windriver.com):
> From: fli <fupan.li at windriver.com>
> 
> The commit: e5848d395cb <netdev_move_by_index: support wlan> only
> made netdev_move_by_name support wlan, instead of netdev_move_by_index.
> 
> Given netdev_move_by_name is a wrapper of netdev_move_by_index, so here
> replacing all of the call to lxc_netdev_move_by_index with lxc_netdev_move_by_name
> to let lxc-start support wlan phys.
> 
> Signed-off-by: fupan li <fupan.li at windriver.com>

Acked-by: Serge E. Hallyn <serge.hallyn at ubuntu.com>

We might want to mark move_by_index static and put in a comment saying
this is now only meant to be used by move_by_name.  Maybe even rename
lxc_netdev_move_by_index to just do_move_by_index(), then make a new
lxc_netdev_move_by_index() function which does the if_indextoname()
which the callers are now doing themselves.

> ---
>  src/lxc/conf.c | 20 ++++++++++++++++----
>  1 file changed, 16 insertions(+), 4 deletions(-)
> 
> diff --git a/src/lxc/conf.c b/src/lxc/conf.c
> index 142444e..2ebf876 100644
> --- a/src/lxc/conf.c
> +++ b/src/lxc/conf.c
> @@ -2623,6 +2623,7 @@ void restore_phys_nics_to_netns(int netnsfd, struct lxc_conf *conf)
>  {
>  	int i, ret, oldfd;
>  	char path[MAXPATHLEN];
> +	char ifname[IFNAMSIZ]; 
>  
>  	if (netnsfd < 0)
>  		return;
> @@ -2643,9 +2644,13 @@ void restore_phys_nics_to_netns(int netnsfd, struct lxc_conf *conf)
>  	}
>  	for (i=0; i<conf->num_savednics; i++) {
>  		struct saved_nic *s = &conf->saved_nics[i];
> -		if (lxc_netdev_move_by_index(s->ifindex, 1, NULL))
> -			WARN("Error moving nic index:%d back to host netns",
> -					s->ifindex);
> +		/* retrieve the name of the interface */
> +		if (!if_indextoname(s->ifindex, ifname)) {
> +			WARN("no interface corresponding to index '%d'", s->ifindex);
> +			continue;
> +		}
> +		if (lxc_netdev_move_by_name(ifname, 1, NULL))
> +			WARN("Error moving nic name:%s back to host netns", ifname);
>  	}
>  	if (setns(oldfd, 0) != 0)
>  		SYSERROR("Failed to re-enter monitor's netns");
> @@ -3225,6 +3230,7 @@ int lxc_assign_network(struct lxc_list *network, pid_t pid)
>  {
>  	struct lxc_list *iterator;
>  	struct lxc_netdev *netdev;
> +	char ifname[IFNAMSIZ];
>  	int am_root = (getuid() == 0);
>  	int err;
>  
> @@ -3245,7 +3251,13 @@ int lxc_assign_network(struct lxc_list *network, pid_t pid)
>  		if (!netdev->ifindex)
>  			continue;
>  
> -		err = lxc_netdev_move_by_index(netdev->ifindex, pid, NULL);
> +		/* retrieve the name of the interface */
> +		if (!if_indextoname(netdev->ifindex, ifname)) {
> +			ERROR("no interface corresponding to index '%d'", netdev->ifindex);
> +			return -1;
> +		}
> +
> +		err = lxc_netdev_move_by_name(ifname, pid, NULL);
>  		if (err) {
>  			ERROR("failed to move '%s' to the container : %s",
>  			      netdev->link, strerror(-err));
> -- 
> 1.9.1
> 
> _______________________________________________
> lxc-devel mailing list
> lxc-devel at lists.linuxcontainers.org
> http://lists.linuxcontainers.org/listinfo/lxc-devel


More information about the lxc-devel mailing list