[PATCH] lxc: move wireless PHYs to a network namespace

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

 



From: Lubomir Rintel <lkundrak@xxxxx>

The 802.11 interfaces can not be moved by themselves, their Phy has to move too.

If there are other interfaces, they have to move too -- hopefully it's not too
confusing. This is a less-invasive alternative to defining a new hostdev type
for PHYs.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 src/util/virnetdev.c | 39 ++++++++++++++++++++++++++++++++++++---
 1 file changed, 36 insertions(+), 3 deletions(-)

diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c
index a816e5d..21fa9d0 100644
--- a/src/util/virnetdev.c
+++ b/src/util/virnetdev.c
@@ -560,20 +560,53 @@ int virNetDevSetMTUFromDevice(const char *ifname,
  */
 int virNetDevSetNamespace(const char *ifname, pid_t pidInNs)
 {
-    int rc;
+    int ret = -1;
     char *pid = NULL;
+    char *phy = NULL;
+    char *phy_path = NULL;
+    int len;
+
     const char *argv[] = {
         "ip", "link", "set", ifname, "netns", NULL, NULL
     };
 
+    const char *iwargv[] = {
+        "iw", "phy", NULL, "set", "netns", NULL, NULL
+    };
+
     if (virAsprintf(&pid, "%lld", (long long) pidInNs) == -1)
         return -1;
 
     argv[5] = pid;
-    rc = virRun(argv, NULL);
+    if (virRun(argv, NULL) < 0)
+        goto cleanup;
 
+    /* The 802.11 wireless devices only move together with their PHY. */
+    if (virNetDevSysfsFile(&phy_path, ifname, "phy80211/name") < 0)
+        goto cleanup;
+
+    if ((len = virFileReadAllQuiet(phy_path, 1024, &phy) < 0)) {
+        if (errno == ENOENT) {
+            /* Okay, this is not a wireless card. Claim success. */
+            ret = 0;
+        }
+        goto cleanup;
+    }
+
+    /* Remove a line break. */
+    phy[len - 1] = '\0';
+
+    iwargv[2] = phy;
+    iwargv[5] = pid;
+    if (virRun(iwargv, NULL) < 0)
+        goto cleanup;
+
+    ret = 0;
+ cleanup:
+    VIR_FREE(phy_path);
+    VIR_FREE(phy);
     VIR_FREE(pid);
-    return rc;
+    return ret;
 }
 
 #if defined(SIOCSIFNAME) && defined(HAVE_STRUCT_IFREQ)
-- 
2.0.5

--
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]