The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/lxc/pull/3107

This e-mail was sent by the LXC bot, direct replies will not reach the author
unless they happen to be subscribed to this list.

=== Description (from pull-request) ===
lxccontainer: do_lxcapi_detach_interface to support detaching wlan devices.

Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com>
From 4a88cd3d5066a71244fb2b9595825c6164010980 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parr...@canonical.com>
Date: Fri, 26 Jul 2019 16:14:18 +0100
Subject: [PATCH] lxccontainer: do_lxcapi_detach_interface to support detaching
 wlan devices

Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com>
---
 src/lxc/attach.c       |  2 +-
 src/lxc/attach.h       |  2 ++
 src/lxc/lxccontainer.c | 10 +++++++++-
 src/lxc/network.c      |  4 ++--
 src/lxc/network.h      |  4 ++++
 5 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/src/lxc/attach.c b/src/lxc/attach.c
index 867aa91c0d..f63331edec 100644
--- a/src/lxc/attach.c
+++ b/src/lxc/attach.c
@@ -213,7 +213,7 @@ static int lxc_attach_to_ns(pid_t pid, struct 
lxc_proc_context_info *ctx)
        return 0;
 }
 
-static int lxc_attach_remount_sys_proc(void)
+int lxc_attach_remount_sys_proc(void)
 {
        int ret;
 
diff --git a/src/lxc/attach.h b/src/lxc/attach.h
index c576aa9fca..ce7c461b33 100644
--- a/src/lxc/attach.h
+++ b/src/lxc/attach.h
@@ -45,4 +45,6 @@ extern int lxc_attach(struct lxc_container *container,
                      lxc_attach_exec_t exec_function, void *exec_payload,
                      lxc_attach_options_t *options, pid_t *attached_process);
 
+extern int lxc_attach_remount_sys_proc(void);
+
 #endif /* __LXC_ATTACH_H */
diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c
index d8efdc41c6..4f8f1a90f3 100644
--- a/src/lxc/lxccontainer.c
+++ b/src/lxc/lxccontainer.c
@@ -4793,6 +4793,7 @@ static bool do_lxcapi_detach_interface(struct 
lxc_container *c,
 {
        int ret;
        pid_t pid, pid_outside;
+       __do_free char *physname = NULL;
 
        /*
         * TODO - if this is a physical device, then we need am_host_unpriv.
@@ -4843,7 +4844,14 @@ static bool do_lxcapi_detach_interface(struct 
lxc_container *c,
                        }
                }
 
-               ret = lxc_netdev_move_by_name(ifname, pid_outside, dst_ifname);
+               /* remount /sys so is_wlan() can check if this device is a wlan 
device. */
+               lxc_attach_remount_sys_proc();
+               physname = is_wlan(ifname);
+               if (physname)
+                       ret = lxc_netdev_move_wlan(physname, ifname, 
pid_outside, dst_ifname);
+               else
+                       ret = lxc_netdev_move_by_name(ifname, pid_outside, 
dst_ifname);
+
                /* -EINVAL means there is no netdev named as ifname. */
                if (ret < 0) {
                        if (ret == -EINVAL)
diff --git a/src/lxc/network.c b/src/lxc/network.c
index 7684f95918..65727f6b5a 100644
--- a/src/lxc/network.c
+++ b/src/lxc/network.c
@@ -1172,7 +1172,7 @@ int lxc_netdev_move_by_index(int ifindex, pid_t pid, 
const char *ifname)
  * will be passed to lxc_netdev_move_wlan() which will free it when done.
  */
 #define PHYSNAME "/sys/class/net/%s/phy80211/name"
-static char *is_wlan(const char *ifname)
+char *is_wlan(const char *ifname)
 {
        __do_free char *path = NULL;
        int i, ret;
@@ -1245,7 +1245,7 @@ static int lxc_netdev_rename_by_name_in_netns(pid_t pid, 
const char *old,
        _exit(lxc_netdev_rename_by_name(old, new));
 }
 
-static int lxc_netdev_move_wlan(char *physname, const char *ifname, pid_t pid,
+int lxc_netdev_move_wlan(char *physname, const char *ifname, pid_t pid,
                                const char *newname)
 {
        __do_free char *cmd = NULL;
diff --git a/src/lxc/network.h b/src/lxc/network.h
index acfd8a0532..8a86768d9e 100644
--- a/src/lxc/network.h
+++ b/src/lxc/network.h
@@ -293,4 +293,8 @@ extern int lxc_netns_set_nsid(int netns_fd);
 extern int lxc_netns_get_nsid(__s32 fd);
 extern int lxc_create_network(struct lxc_handler *handler);
 
+extern char *is_wlan(const char *ifname);
+extern int lxc_netdev_move_wlan(char *physname, const char *ifname, pid_t pid,
+                               const char *newname);
+
 #endif /* __LXC_NETWORK_H */
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to