From: Laine Stump Date: Wed, 30 Sep 2020 21:56:00 +0000 (-0400) Subject: util: provide non-netlink/libnl alternative for virNetDevGetMaster() X-Git-Tag: v6.9.0-rc1~413 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=49a58cb9c92543a3147096c26b31c6d2a8911def;p=thirdparty%2Flibvirt.git util: provide non-netlink/libnl alternative for virNetDevGetMaster() 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 Reviewed-by: Michal Privoznik --- diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c index 5221bada7b..c43823c747 100644 --- a/src/util/virnetdev.c +++ b/src/util/virnetdev.c @@ -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,