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

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

 



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.
---
 src/util/virnetdev.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c
index ee60f09..df48763 100644
--- a/src/util/virnetdev.c
+++ b/src/util/virnetdev.c
@@ -584,6 +584,8 @@ int virNetDevSetNamespace(const char *ifname, pid_t pidInNs)
 {
     int rc;
     char *pid = NULL;
+    char *phy_path = NULL;
+
     const char *argv[] = {
         "ip", "link", "set", ifname, "netns", NULL, NULL
     };
@@ -591,6 +593,35 @@ int virNetDevSetNamespace(const char *ifname, pid_t pidInNs)
     if (virAsprintf(&pid, "%lld", (long long) pidInNs) == -1)
         return -1;
 
+    /* The 802.11 wireless devices only move together with their PHY. */
+    if (virNetDevSysfsFile(&phy_path, ifname, "phy80211/name") >= 0) {
+        int len;
+        char *phy = NULL;
+
+        len = virFileReadAllQuiet(phy_path, 1024, &phy);
+        VIR_FREE(phy_path);
+
+        /* Remove a line break. */
+        if (len > 0)
+            phy[len - 1] = '\0';
+
+        if (len >= 0) {
+            const char *iwargv[] = {
+                "iw", "phy", phy, "set", "netns", NULL, NULL
+            };
+
+            iwargv[5] = pid;
+            rc = virRun(iwargv, NULL);
+
+            VIR_FREE(phy);
+
+            if (rc == 0) {
+                VIR_FREE(pid);
+                return rc;
+            }
+        }
+    }
+
     argv[5] = pid;
     rc = virRun(argv, NULL);
 
-- 
2.1.0

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