Builds for Linux without libnl is broken since commit 582f0966f9b9e2148d8887d072364e2a91aed000 because src/util/virnetdevbridge.c refers to virNetlinkBridgeVlanFilterSet(). A fundamental problem here is that nobody tests such builds. Netlink is a critical part of Linux networking so developers may assume it is readily available, but the libnl dependency check breaks this assumption. Builds without libnl also lack several networking features such as SR-IOV, bridge/tap, switchdev, macvlan, veth, and vlan. This may also contradict with exceptations made by other networking code of libvirt or users. Remove libnl checks specific to Linux to avoid such a problem in libvirt's networking code. More concretely, find patterns like following: #ifdef __linux__ A #ifdef WITH_LIBNL B #endif C #endif And replace them with: #ifdef WITH_LIBNL A B C #endif There are also patterns like following: #ifdef WITH_LIBNL A #elif defined(__linux__) B #endif Replace them with: #ifdef WITH_LIBNL A #endif This change will make less networking features available. Anyone who want these features should enable libnl for the better tested code. It still does not require libnl to build because the client code and some drivers do not need libvirt to configure networking at all. Signed-off-by: Akihiko Odaki <akihiko.odaki@xxxxxxxxxx> --- src/util/virnetdev.c | 44 ++++---------------------------------------- src/util/virnetdevbridge.c | 33 +++++---------------------------- tests/virnetdevtest.c | 10 +--------- 3 files changed, 10 insertions(+), 77 deletions(-) diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c index 8ae854245e..7ea029be9e 100644 --- a/src/util/virnetdev.c +++ b/src/util/virnetdev.c @@ -914,29 +914,6 @@ virNetDevGetMaster(const char *ifname, char **master) return 0; } -#elif defined(__linux__) - -/* 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 @@ -1059,7 +1036,7 @@ int virNetDevValidateConfig(const char *ifname G_GNUC_UNUSED, #endif -#ifdef __linux__ +#ifdef WITH_LIBNL int virNetDevSysfsFile(char **pf_sysfs_device_link, const char *ifname, @@ -1079,8 +1056,6 @@ virNetDevSysfsDeviceFile(char **pf_sysfs_device_link, const char *ifname, } -# if defined(WITH_LIBNL) - /** * Determine if the device path specified in devpath is a PCI Device * by resolving the 'subsystem'-link in devpath and looking for @@ -1133,7 +1108,6 @@ virNetDevGetPCIDevice(const char *devName) return virPCIDeviceNew(vfPCIAddr); } -# endif /* A wrapper to get content of file from ifname SYSFS_NET_DIR @@ -1381,7 +1355,7 @@ virNetDevGetVirtualFunctionInfo(const char *vfname, char **pfname, return ret; } -#else /* !__linux__ */ +#else /* !WITH_LIBNL */ int virNetDevGetPhysPortID(const char *ifname G_GNUC_UNUSED, char **physPortID) @@ -1471,7 +1445,7 @@ virNetDevSysfsFile(char **pf_sysfs_device_link G_GNUC_UNUSED, } -#endif /* !__linux__ */ +#endif /* !WITH_LIBNL */ #if defined(WITH_LIBNL) @@ -2938,7 +2912,7 @@ int virNetDevGetRxFilter(const char *ifname, return ret; } -#if __linux__ +#ifdef WITH_LIBNL /** * virNetDevRDMAFeature @@ -3095,8 +3069,6 @@ virNetDevGetEthtoolFeatures(const char *ifname, } -# if defined(WITH_LIBNL) - /** * virNetDevGetFamilyId: * This function supplies the devlink family id @@ -3237,14 +3209,6 @@ virNetDevSwitchdevFeature(const char *ifname, nlmsg_free(nl_msg); return ret; } -# else -static int -virNetDevSwitchdevFeature(const char *ifname G_GNUC_UNUSED, - virBitmap **out G_GNUC_UNUSED) -{ - return 0; -} -# endif /** diff --git a/src/util/virnetdevbridge.c b/src/util/virnetdevbridge.c index c79d0c79b7..0af7a8d286 100644 --- a/src/util/virnetdevbridge.c +++ b/src/util/virnetdevbridge.c @@ -30,9 +30,7 @@ #endif #ifdef __linux__ -# if defined(WITH_LIBNL) -# include "virnetlink.h" -# endif +# include "virnetlink.h" # include <linux/sockios.h> # include <linux/param.h> /* HZ */ # include <linux/in6.h> @@ -185,7 +183,7 @@ static int virNetDevBridgeGet(const char *brname, } #endif /* __linux__ */ -#if defined(__linux__) +#if defined(WITH_LIBNL) static int virNetDevBridgePortSet(const char *brname, const char *ifname, @@ -450,7 +448,7 @@ virNetDevBridgePortSetIsolated(const char *brname G_GNUC_UNUSED, * * Returns 0 in case of success or -1 on failure */ -#if defined(WITH_STRUCT_IFREQ) && defined(SIOCBRADDBR) +#if defined(WITH_STRUCT_IFREQ) && defined(SIOCBRADDBR) && defined(WITH_LIBNL) static int virNetDevBridgeCreateWithIoctl(const char *brname, const virMacAddr *mac) @@ -477,9 +475,7 @@ virNetDevBridgeCreateWithIoctl(const char *brname, return 0; } -#endif -#if defined(WITH_LIBNL) int virNetDevBridgeCreate(const char *brname, const virMacAddr *mac) @@ -509,15 +505,6 @@ virNetDevBridgeCreate(const char *brname, } -#elif defined(WITH_STRUCT_IFREQ) && defined(SIOCBRADDBR) -int -virNetDevBridgeCreate(const char *brname, - const virMacAddr *mac) -{ - return virNetDevBridgeCreateWithIoctl(brname, mac); -} - - #elif defined(WITH_STRUCT_IFREQ) && defined(SIOCIFCREATE2) int virNetDevBridgeCreate(const char *brname, @@ -568,7 +555,7 @@ virNetDevBridgeCreate(const char *brname, * * Returns 0 in case of success or an errno code in case of failure. */ -#if defined(WITH_STRUCT_IFREQ) && defined(SIOCBRDELBR) +#if defined(WITH_STRUCT_IFREQ) && defined(SIOCBRDELBR) && defined(WITH_LIBNL) static int virNetDevBridgeDeleteWithIoctl(const char *brname) { @@ -587,10 +574,8 @@ virNetDevBridgeDeleteWithIoctl(const char *brname) return 0; } -#endif -#if defined(WITH_LIBNL) int virNetDevBridgeDelete(const char *brname) { @@ -606,14 +591,6 @@ virNetDevBridgeDelete(const char *brname) } -#elif defined(WITH_STRUCT_IFREQ) && defined(SIOCBRDELBR) -int -virNetDevBridgeDelete(const char *brname) -{ - return virNetDevBridgeDeleteWithIoctl(brname); -} - - #elif defined(WITH_STRUCT_IFREQ) && defined(SIOCIFDESTROY) int virNetDevBridgeDelete(const char *brname) @@ -651,7 +628,7 @@ int virNetDevBridgeDelete(const char *brname G_GNUC_UNUSED) * * Returns 0 in case of success or an errno code in case of failure. */ -#if defined(WITH_STRUCT_IFREQ) && defined(SIOCBRADDIF) +#if defined(WITH_STRUCT_IFREQ) && defined(SIOCBRADDIF) && defined(WITH_LIBNL) int virNetDevBridgeAddPort(const char *brname, const char *ifname, const virNetDevVlan *virtVlan) diff --git a/tests/virnetdevtest.c b/tests/virnetdevtest.c index 42f1a74ee9..bc1b759502 100644 --- a/tests/virnetdevtest.c +++ b/tests/virnetdevtest.c @@ -23,7 +23,7 @@ #define LIBVIRT_VIRNETDEVPRIV_H_ALLOW -#ifdef __linux__ +#ifdef WITH_LIBNL # include "virmock.h" # include "virnetdevpriv.h" @@ -63,8 +63,6 @@ testVirNetDevGetLinkInfo(const void *opaque) return 0; } -# if defined(WITH_LIBNL) - int (*real_virNetDevSendVfSetLinkRequest)(const char *ifname, int vfInfoType, @@ -301,8 +299,6 @@ testVirNetDevSetVfConfig(const void *opaque G_GNUC_UNUSED) return 0; } -# endif /* defined(WITH_LIBNL) */ - static int mymain(void) { @@ -320,8 +316,6 @@ mymain(void) DO_TEST_LINK("lo", VIR_NETDEV_IF_STATE_UNKNOWN, 0); DO_TEST_LINK("eth0-broken", VIR_NETDEV_IF_STATE_DOWN, 0); -# if defined(WITH_LIBNL) - if (virTestRun("Set VF MAC", testVirNetDevSetVfMac, NULL) < 0) ret = -1; if (virTestRun("Set VF MAC: missing MAC pointer", testVirNetDevSetVfMissingMac, NULL) < 0) @@ -331,8 +325,6 @@ mymain(void) if (virTestRun("Set VF Config", testVirNetDevSetVfConfig, NULL) < 0) ret = -1; -# endif /* defined(WITH_LIBNL) */ - return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; } -- 2.48.1