]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: provide non-netlink/libnl alternative for virNetDevGetMaster()
authorLaine Stump <laine@redhat.com>
Wed, 30 Sep 2020 21:56:00 +0000 (17:56 -0400)
committerLaine Stump <laine@redhat.com>
Thu, 1 Oct 2020 18:02:34 +0000 (14:02 -0400)
Lack of this one function (which is called for each active tap device
every time libvirtd is started) is the one thing preventing a
"WITHOUT_LIBNL" build of libvirt from being useful. With this
alternate implementation, guests using standard tap devices will work
properly even when libvirt is built without libnl support.

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/util/virnetdev.c

index 5221bada7b44a6bd9fc32811d8ca1c1860d3ec12..c43823c7471234f168da7a0247521daeae5cfab1 100644 (file)
@@ -915,9 +915,30 @@ virNetDevGetMaster(const char *ifname, char **master)
     return 0;
 }
 
+#elif defined(__linux__)
 
-#else
+/* libnl isn't available, so we can't use netlink.
+ * Fall back to using sysfs
+ */
+int
+virNetDevGetMaster(const char *ifname, char **master)
+{
+    g_autofree char *path = NULL;
+    g_autofree char *canonical = NULL;
+
+    if (virNetDevSysfsFile(&path, ifname, "master") < 0)
+        return -1;
 
+    if (!(canonical = virFileCanonicalizePath(path)))
+        return -1;
+
+    *master = g_path_get_basename(canonical);
+
+    VIR_DEBUG("IFLA_MASTER for %s is %s", ifname, *master ? *master : "(none)");
+    return 0;
+}
+
+#else
 
 int
 virNetDevGetMaster(const char *ifname G_GNUC_UNUSED,