From nobody Sun Sep 7 23:51:55 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=reject dis=none) header.from=rsg.ci.i.u-tokyo.ac.jp Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1755526507799401.10596269033863; Mon, 18 Aug 2025 07:15:07 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id C1166C2F; Mon, 18 Aug 2025 10:15:06 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 2C5C8C95; Mon, 18 Aug 2025 10:12:15 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 79BE9138D; Tue, 5 Aug 2025 06:57:57 -0400 (EDT) Received: from www3579.sakura.ne.jp (www3579.sakura.ne.jp [49.212.243.89]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 7F8C01385 for ; Tue, 5 Aug 2025 06:57:56 -0400 (EDT) Received: from h205.csg.ci.i.u-tokyo.ac.jp (h205.csg.ci.i.u-tokyo.ac.jp [133.11.54.205]) (authenticated bits=0) by www3579.sakura.ne.jp (8.16.1/8.16.1) with ESMTPSA id 575APt9C013112 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 5 Aug 2025 19:25:59 +0900 (JST) (envelope-from odaki@rsg.ci.i.u-tokyo.ac.jp) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: a=rsa-sha256; bh=H9/9L3VEFnI1eXiLImEjgGJlv3mUcHo8k04KpKS2pW8=; c=relaxed/relaxed; d=rsg.ci.i.u-tokyo.ac.jp; h=From:Date:Subject:Message-Id:To; s=rs20250326; t=1754389559; v=1; b=dkyxY/DfbtfJUp3xIP9YCbP+QSiQ+SFDe7UDB37ac/fINevQySHh+Umu8IgJoS/C U5Hd+lRDHUBKULu+OK1GAB6aRVN11ftLMjcZnYysxIjBTj+qsdf8qyPHDOLDbYj5 bD4QpIwdvLZUovCRWdn80G+ztuXuU5hoQNocVU0DpgQo/hj1c4LrdT0RcpKuXxwe xPvAVgW+jMCYWbIgQ8daPooT8iYy1YTG0VRUbTJgEXR30lYedmWo84X8z0CSA3TR 0bJXGA7++1BysPK3bD4v2PxZ+ya8eM0ucdhxiI728Rj2Ifjm4k1Vb9P3pZRA0uJM Et/Uk/steHTEpJzydZvl9w== From: Akihiko Odaki Date: Tue, 05 Aug 2025 19:25:32 +0900 Subject: [PATCH v2 1/2] Remove libnl checks specific to Linux MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250805-linux-v2-1-63e721bdd97d@rsg.ci.i.u-tokyo.ac.jp> References: <20250805-linux-v2-0-63e721bdd97d@rsg.ci.i.u-tokyo.ac.jp> In-Reply-To: <20250805-linux-v2-0-63e721bdd97d@rsg.ci.i.u-tokyo.ac.jp> To: Laine Stump , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , devel@lists.libvirt.org X-Mailer: b4 0.14.2 X-MailFrom: odaki@rsg.ci.i.u-tokyo.ac.jp X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0 Message-ID-Hash: YWX4FN4YUFJ6GWCV2JULYI5X7VUV75KV X-Message-ID-Hash: YWX4FN4YUFJ6GWCV2JULYI5X7VUV75KV X-Mailman-Approved-At: Mon, 18 Aug 2025 14:12:10 -0400 CC: 20250308-require-v1-1-fe6850bf3f30@daynix.com, Akihiko Odaki X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZM-MESSAGEID: 1755526510309116600 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 --- src/util/virnetdev.c | 44 ++++--------------------------------------= -- src/util/virnetdevbridge.c | 29 ++++------------------------- tests/virnetdevtest.c | 10 +--------- 3 files changed, 9 insertions(+), 74 deletions(-) diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c index 8ae854245ed99dc1a3aa4c225b614ddbb449caf8..7ea029be9e49d7399ae1235ac47= 89cee7add4f70 100644 --- a/src/util/virnetdev.c +++ b/src/util/virnetdev.c @@ -914,29 +914,6 @@ virNetDevGetMaster(const char *ifname, char **master) return 0; } =20 -#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 =3D NULL; - g_autofree char *canonical =3D NULL; - - if (virNetDevSysfsFile(&path, ifname, "master") < 0) - return -1; - - if (!(canonical =3D virFileCanonicalizePath(path))) - return -1; - - *master =3D g_path_get_basename(canonical); - - VIR_DEBUG("IFLA_MASTER for %s is %s", ifname, *master ? *master : "(no= ne)"); - return 0; -} - #else =20 int @@ -1059,7 +1036,7 @@ int virNetDevValidateConfig(const char *ifname G_GNUC= _UNUSED, #endif =20 =20 -#ifdef __linux__ +#ifdef WITH_LIBNL =20 int virNetDevSysfsFile(char **pf_sysfs_device_link, const char *ifname, @@ -1079,8 +1056,6 @@ virNetDevSysfsDeviceFile(char **pf_sysfs_device_link,= const char *ifname, } =20 =20 -# 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) =20 return virPCIDeviceNew(vfPCIAddr); } -# endif =20 =20 /* A wrapper to get content of file from ifname SYSFS_NET_DIR @@ -1381,7 +1355,7 @@ virNetDevGetVirtualFunctionInfo(const char *vfname, c= har **pfname, return ret; } =20 -#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, } =20 =20 -#endif /* !__linux__ */ +#endif /* !WITH_LIBNL */ #if defined(WITH_LIBNL) =20 =20 @@ -2938,7 +2912,7 @@ int virNetDevGetRxFilter(const char *ifname, return ret; } =20 -#if __linux__ +#ifdef WITH_LIBNL =20 /** * virNetDevRDMAFeature @@ -3095,8 +3069,6 @@ virNetDevGetEthtoolFeatures(const char *ifname, } =20 =20 -# 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 =20 =20 /** diff --git a/src/util/virnetdevbridge.c b/src/util/virnetdevbridge.c index 20c7a25585f9e9b0b985780ee62655456f6b05af..12d35737eade0ff692ebe4a28b4= c037abd7f9edd 100644 --- a/src/util/virnetdevbridge.c +++ b/src/util/virnetdevbridge.c @@ -183,7 +183,7 @@ static int virNetDevBridgeGet(const char *brname, } #endif /* __linux__ */ =20 -#if defined(__linux__) +#if defined(WITH_LIBNL) static int virNetDevBridgePortSet(const char *brname, const char *ifname, @@ -448,7 +448,7 @@ virNetDevBridgePortSetIsolated(const char *brname G_GNU= C_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_LIB= NL) static int virNetDevBridgeCreateWithIoctl(const char *brname, const virMacAddr *mac) @@ -475,9 +475,7 @@ virNetDevBridgeCreateWithIoctl(const char *brname, =20 return 0; } -#endif =20 -#if defined(WITH_LIBNL) int virNetDevBridgeCreate(const char *brname, const virMacAddr *mac) @@ -507,15 +505,6 @@ virNetDevBridgeCreate(const char *brname, } =20 =20 -#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, @@ -566,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_LIB= NL) static int virNetDevBridgeDeleteWithIoctl(const char *brname) { @@ -585,10 +574,8 @@ virNetDevBridgeDeleteWithIoctl(const char *brname) =20 return 0; } -#endif =20 =20 -#if defined(WITH_LIBNL) int virNetDevBridgeDelete(const char *brname) { @@ -604,14 +591,6 @@ virNetDevBridgeDelete(const char *brname) } =20 =20 -#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) @@ -649,7 +628,7 @@ int virNetDevBridgeDelete(const char *brname G_GNUC_UNU= SED) * * 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_LIB= NL) int virNetDevBridgeAddPort(const char *brname, const char *ifname, const virNetDevVlan *virtVlan) diff --git a/tests/virnetdevtest.c b/tests/virnetdevtest.c index 42f1a74ee9ad66f40150920670a4f71518c9d610..bc1b759502c0e12cabf995b2828= 91c0feebe2239 100644 --- a/tests/virnetdevtest.c +++ b/tests/virnetdevtest.c @@ -23,7 +23,7 @@ =20 #define LIBVIRT_VIRNETDEVPRIV_H_ALLOW =20 -#ifdef __linux__ +#ifdef WITH_LIBNL =20 # include "virmock.h" # include "virnetdevpriv.h" @@ -63,8 +63,6 @@ testVirNetDevGetLinkInfo(const void *opaque) return 0; } =20 -# if defined(WITH_LIBNL) - int (*real_virNetDevSendVfSetLinkRequest)(const char *ifname, int vfInfoType, @@ -301,8 +299,6 @@ testVirNetDevSetVfConfig(const void *opaque G_GNUC_UNUS= ED) return 0; } =20 -# 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); =20 -# if defined(WITH_LIBNL) - if (virTestRun("Set VF MAC", testVirNetDevSetVfMac, NULL) < 0) ret =3D -1; if (virTestRun("Set VF MAC: missing MAC pointer", testVirNetDevSetVfMi= ssingMac, NULL) < 0) @@ -331,8 +325,6 @@ mymain(void) if (virTestRun("Set VF Config", testVirNetDevSetVfConfig, NULL) < 0) ret =3D -1; =20 -# endif /* defined(WITH_LIBNL) */ - return ret =3D=3D 0 ? EXIT_SUCCESS : EXIT_FAILURE; } =20 --=20 2.50.1 From nobody Sun Sep 7 23:51:55 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=reject dis=none) header.from=rsg.ci.i.u-tokyo.ac.jp Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1755526457500972.3793781798762; Mon, 18 Aug 2025 07:14:17 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id ED632A95; Mon, 18 Aug 2025 10:14:16 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id C235BC86; Mon, 18 Aug 2025 10:12:13 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 1DF501385; Tue, 5 Aug 2025 06:58:00 -0400 (EDT) Received: from www3579.sakura.ne.jp (www3579.sakura.ne.jp [49.212.243.89]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id BB254138F for ; Tue, 5 Aug 2025 06:57:58 -0400 (EDT) Received: from h205.csg.ci.i.u-tokyo.ac.jp (h205.csg.ci.i.u-tokyo.ac.jp [133.11.54.205]) (authenticated bits=0) by www3579.sakura.ne.jp (8.16.1/8.16.1) with ESMTPSA id 575APt9D013112 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 5 Aug 2025 19:25:59 +0900 (JST) (envelope-from odaki@rsg.ci.i.u-tokyo.ac.jp) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: a=rsa-sha256; bh=eewQdbxlNoVu9MQTr5U9eLWz4Hn+QlomMNNCIwHOd2o=; c=relaxed/relaxed; d=rsg.ci.i.u-tokyo.ac.jp; h=From:Date:Subject:Message-Id:To; s=rs20250326; t=1754389559; v=1; b=DX7MasotUmlldkbFj3n9pIXSnqdMHCHADiXarphnD64k94uV48lRpIWWjuOdEsX0 N1amQQs7HQlqKFoPHKZyc2snY9DqexUar9JeQsVnKa7tZYCy5DyEcH5zWSLRhQx6 vCI1dMQj3j38+lQnWl8cR9SlPbRI36pyA4wvytheLYMbpj5MslGhswbjsxtBiItY A3oTo8OM3HBMe3tgV46OFVlr41bV4XnbA5oEIdV/wC5FIb2d3SbLjxWBAtr84Ve0 QQHiwMqmOF8K3bfHCodSriNn9E9HScS3GxpddAHHGUieLQwcS47cgoS22Mbfq8Ju YzyhuixJazYL7aEaufjJpw== From: Akihiko Odaki Date: Tue, 05 Aug 2025 19:25:33 +0900 Subject: [PATCH v2 2/2] virnetlink: Remove stub functions MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250805-linux-v2-2-63e721bdd97d@rsg.ci.i.u-tokyo.ac.jp> References: <20250805-linux-v2-0-63e721bdd97d@rsg.ci.i.u-tokyo.ac.jp> In-Reply-To: <20250805-linux-v2-0-63e721bdd97d@rsg.ci.i.u-tokyo.ac.jp> To: Laine Stump , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , devel@lists.libvirt.org X-Mailer: b4 0.14.2 X-MailFrom: odaki@rsg.ci.i.u-tokyo.ac.jp X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0 Message-ID-Hash: 7ZNQ2XJUSHNBW6LKOLCGY553W5YE2B6P X-Message-ID-Hash: 7ZNQ2XJUSHNBW6LKOLCGY553W5YE2B6P X-Mailman-Approved-At: Mon, 18 Aug 2025 14:12:10 -0400 CC: 20250308-require-v1-1-fe6850bf3f30@daynix.com, Akihiko Odaki X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZM-MESSAGEID: 1755526460864124100 virnetlink provides stub functions when libnl is not available, but this approach caused a few problems: - Commit 582f0966f9b9e2148d8887d072364e2a91aed000 broke builds without libnl for Linux because virNetlinkBridgeVlanFilterSet() lacked a stub. - A call to virNetlinkEventServiceStopAll() stub in src/remote/remote_daemon.c resulted in extra debug logs. Instead of providing stub functions, let callers check the availability of libnl. Callers are also replaced with stub functions in most cases so this approach requires less code and less error-prone. Signed-off-by: Akihiko Odaki --- src/libvirt_libnl.syms | 23 +++++ src/libvirt_private.syms | 19 ---- src/meson.build | 6 ++ src/remote/remote_daemon.c | 10 ++- src/util/meson.build | 5 +- src/util/virarptable.c | 2 +- src/util/virnetlink.c | 216 +++--------------------------------------= ---- src/util/virnetlink.h | 11 +-- 8 files changed, 55 insertions(+), 237 deletions(-) diff --git a/src/libvirt_libnl.syms b/src/libvirt_libnl.syms new file mode 100644 index 0000000000000000000000000000000000000000..091169416be0f452da02cafd479= 2d2ef8084d0a6 --- /dev/null +++ b/src/libvirt_libnl.syms @@ -0,0 +1,23 @@ +# util/virnetlink.h +virNetlinkCommand; +virNetlinkDelLink; +virNetlinkDumpCommand; +virNetlinkDumpLink; +virNetlinkEventAddClient; +virNetlinkEventRemoveClient; +virNetlinkEventServiceIsRunning; +virNetlinkEventServiceLocalPid; +virNetlinkEventServiceStart; +virNetlinkEventServiceStop; +virNetlinkEventServiceStopAll; +virNetlinkGetErrorCode; +virNetlinkGetNeighbor; +virNetlinkNewLink; +virNetlinkShutdown; +virNetlinkStartup; + + +# Let emacs know we want case-insensitive sorting +# Local Variables: +# sort-fold-case: t +# End: diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index b846011f0fc05c3601eda5153d5202fde79253a3..6f0fe999701fab6a7b6878ee495= 9e1c12c072d8f 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3037,25 +3037,6 @@ virNetDevVPortProfileOpTypeFromString; virNetDevVPortProfileOpTypeToString; =20 =20 -# util/virnetlink.h -virNetlinkCommand; -virNetlinkDelLink; -virNetlinkDumpCommand; -virNetlinkDumpLink; -virNetlinkEventAddClient; -virNetlinkEventRemoveClient; -virNetlinkEventServiceIsRunning; -virNetlinkEventServiceLocalPid; -virNetlinkEventServiceStart; -virNetlinkEventServiceStop; -virNetlinkEventServiceStopAll; -virNetlinkGetErrorCode; -virNetlinkGetNeighbor; -virNetlinkNewLink; -virNetlinkShutdown; -virNetlinkStartup; - - # util/virnodesuspend.h virNodeSuspend; virNodeSuspendGetTargetMask; diff --git a/src/meson.build b/src/meson.build index 9a818dab50191ce189d76e150276e63b48a5a65a..3f1e25703fd312e7238063c404f= 11b90521c1456 100644 --- a/src/meson.build +++ b/src/meson.build @@ -131,6 +131,12 @@ else sym_files +=3D 'libvirt_hyperv.syms' endif =20 +if conf.has('WITH_LIBNL') + used_sym_files +=3D 'libvirt_libnl.syms' +else + sym_files +=3D 'libvirt_libnl.syms' +endif + # variables filled by subdirectories =20 libvirt_libs =3D [] diff --git a/src/remote/remote_daemon.c b/src/remote/remote_daemon.c index 1424d4cf5e188a3de32b187cb41306885f1abbb3..83f80c2e264b588eca27ddcb170= ad30ed20368a5 100644 --- a/src/remote/remote_daemon.c +++ b/src/remote/remote_daemon.c @@ -991,10 +991,12 @@ int main(int argc, char **argv) { } umask(old_umask); =20 +#ifdef WITH_LIBNL if (virNetlinkStartup() < 0) { ret =3D VIR_DAEMON_ERR_INIT; goto cleanup; } +#endif =20 if (!(dmn =3D virNetDaemonNew())) { ret =3D VIR_DAEMON_ERR_DRIVER; @@ -1158,7 +1160,7 @@ int main(int argc, char **argv) { goto cleanup; } =20 -#if defined(__linux__) && defined(NETLINK_ROUTE) +#if defined(WITH_LIBNL) && defined(NETLINK_ROUTE) /* Register the netlink event service for NETLINK_ROUTE */ if (virNetlinkEventServiceStart(NETLINK_ROUTE, 0) < 0) { ret =3D VIR_DAEMON_ERR_NETWORK; @@ -1166,7 +1168,7 @@ int main(int argc, char **argv) { } #endif =20 -#if defined(__linux__) && defined(NETLINK_KOBJECT_UEVENT) +#if defined(WITH_LIBNL) && defined(NETLINK_KOBJECT_UEVENT) /* Register the netlink event service for NETLINK_KOBJECT_UEVENT */ if (virNetlinkEventServiceStart(NETLINK_KOBJECT_UEVENT, 1) < 0) { ret =3D VIR_DAEMON_ERR_NETWORK; @@ -1183,7 +1185,9 @@ int main(int argc, char **argv) { 0, "shutdown", NULL, NULL); =20 cleanup: +#ifdef WITH_LIBNL virNetlinkEventServiceStopAll(); +#endif =20 if (g_atomic_int_compare_and_exchange(&driversInitialized, 1, 0)) { /* NB: Possible issue with timing window between driversInitialized @@ -1199,7 +1203,9 @@ int main(int argc, char **argv) { virObjectUnref(srv); virObjectUnref(dmn); =20 +#ifdef WITH_LIBNL virNetlinkShutdown(); +#endif =20 if (pid_file_fd !=3D -1) virPidFileReleasePath(pid_file, pid_file_fd); diff --git a/src/util/meson.build b/src/util/meson.build index 69ef49139a4d69f8b886f5b8bed3d6a5337997aa..992b0441c901c4c1af14ab91b9c= 5f7515d3708e5 100644 --- a/src/util/meson.build +++ b/src/util/meson.build @@ -69,7 +69,6 @@ util_sources =3D [ 'virnetdevveth.c', 'virnetdevvlan.c', 'virnetdevvportprofile.c', - 'virnetlink.c', 'virnodesuspend.c', 'virnuma.c', 'virnvme.c', @@ -112,6 +111,10 @@ util_sources =3D [ 'virxml.c', ] =20 +if conf.has('WITH_LIBNL') + util_sources +=3D 'virnetlink.c' +endif + util_public_sources =3D files( 'virerror.c', 'virevent.c', diff --git a/src/util/virarptable.c b/src/util/virarptable.c index 20d11f97b0b78b53ea532e8b6bde215810af4436..9c132ea0b6dbd6f304ef5e04b20= eac330ce951b1 100644 --- a/src/util/virarptable.c +++ b/src/util/virarptable.c @@ -35,7 +35,7 @@ =20 VIR_LOG_INIT("util.arptable"); =20 -#ifdef __linux__ +#ifdef WITH_LIBNL =20 # define NDA_RTA(r) \ ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct ndmsg)))) diff --git a/src/util/virnetlink.c b/src/util/virnetlink.c index 8f6dd86d0feaeb2d761c1db2a37103b7cb1b9e9d..06dbbb7679c7f8042d0f113ea03= 030366e2331e6 100644 --- a/src/util/virnetlink.c +++ b/src/util/virnetlink.c @@ -37,11 +37,9 @@ VIR_LOG_INIT("util.netlink"); =20 #define NETLINK_ACK_TIMEOUT_S (2*1000) =20 -#if defined(WITH_LIBNL) +#include =20 -# include - -# define NETLINK_MSG_NEST_START(msg, container, attrtype) \ +#define NETLINK_MSG_NEST_START(msg, container, attrtype) \ do { \ container =3D nla_nest_start(msg, attrtype); \ if (!container) { \ @@ -51,7 +49,7 @@ do { \ } \ } while (0) =20 -# define NETLINK_MSG_NEST_END(msg, container) \ +#define NETLINK_MSG_NEST_END(msg, container) \ do { nla_nest_end(msg, container); } while (0) =20 /* @@ -59,7 +57,7 @@ do { nla_nest_end(msg, container); } while (0) * complain about @data not being a pointer type: * error: the address of 'foo' will always evaluate as 'true' [-Werror=3Da= ddress] */ -# define NETLINK_MSG_PUT(msg, attrtype, datalen, data) \ +#define NETLINK_MSG_PUT(msg, attrtype, datalen, data) \ do { \ const void *dataptr =3D data; \ if (dataptr && nla_put(msg, attrtype, datalen, dataptr) < 0) { \ @@ -69,7 +67,7 @@ do { \ } \ } while (0) =20 -# define NETLINK_MSG_APPEND(msg, datalen, dataptr) \ +#define NETLINK_MSG_APPEND(msg, datalen, dataptr) \ do { \ if (nlmsg_append(msg, dataptr, datalen, NLMSG_ALIGNTO) < 0) { \ virReportError(VIR_ERR_INTERNAL_ERROR, "%s", \ @@ -89,9 +87,9 @@ struct virNetlinkEventHandle { int deleted; }; =20 -# define virNetlinkAlloc nl_socket_alloc -# define virNetlinkSetBufferSize nl_socket_set_buffer_size -# define virNetlinkFree nl_socket_free +#define virNetlinkAlloc nl_socket_alloc +#define virNetlinkSetBufferSize nl_socket_set_buffer_size +#define virNetlinkFree nl_socket_free typedef struct nl_sock virNetlinkHandle; =20 G_DEFINE_AUTOPTR_CLEANUP_FUNC(virNetlinkHandle, virNetlinkFree); @@ -120,7 +118,7 @@ static int nextWatch =3D 1; =20 /* Allocate extra slots for virEventPollHandle/virEventPollTimeout records in this multiple */ -# define NETLINK_EVENT_ALLOC_EXTENT 10 +#define NETLINK_EVENT_ALLOC_EXTENT 10 =20 /* Linux kernel supports up to MAX_LINKS (32 at the time) individual * netlink protocols. */ @@ -519,7 +517,7 @@ virNetlinkDumpLink(const char *ifname, int ifindex, if (ifname) NETLINK_MSG_PUT(nl_msg, IFLA_IFNAME, (strlen(ifname) + 1), ifname); =20 -# ifdef RTEXT_FILTER_VF +#ifdef RTEXT_FILTER_VF /* if this filter exists in the kernel's netlink implementation, * we need to set it, otherwise the response message will not * contain the IFLA_VFINFO_LIST that we're looking for. @@ -530,7 +528,7 @@ virNetlinkDumpLink(const char *ifname, int ifindex, NETLINK_MSG_PUT(nl_msg, IFLA_EXT_MASK, sizeof(ifla_ext_mask), &ifla_ext_mask); } -# endif +#endif =20 if (virNetlinkTalk(ifname, nl_msg, src_pid, dst_pid, &resp, &resp_len, &error, NULL) < 0) { @@ -1313,195 +1311,3 @@ virNetlinkEventRemoveClient(int watch, const virMac= Addr *macaddr, =20 return -1; } - -#else - -# if defined(__linux__) -static const char *unsupported =3D N_("libnl was not available at build ti= me"); -# else -static const char *unsupported =3D N_("not supported on non-linux platform= s"); -# endif - -int -virNetlinkStartup(void) -{ - return 0; -} - -void -virNetlinkShutdown(void) -{ - return; -} - -int virNetlinkCommand(struct nl_msg *nl_msg G_GNUC_UNUSED, - struct nlmsghdr **resp G_GNUC_UNUSED, - unsigned int *respbuflen G_GNUC_UNUSED, - uint32_t src_pid G_GNUC_UNUSED, - uint32_t dst_pid G_GNUC_UNUSED, - unsigned int protocol G_GNUC_UNUSED, - unsigned int groups G_GNUC_UNUSED) -{ - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _(unsupported)); - return -1; -} - -int -virNetlinkDumpCommand(struct nl_msg *nl_msg G_GNUC_UNUSED, - virNetlinkDumpCallback callback G_GNUC_UNUSED, - uint32_t src_pid G_GNUC_UNUSED, - uint32_t dst_pid G_GNUC_UNUSED, - unsigned int protocol G_GNUC_UNUSED, - unsigned int groups G_GNUC_UNUSED, - void *opaque G_GNUC_UNUSED) -{ - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _(unsupported)); - return -1; -} - -int -virNetlinkDumpLink(const char *ifname G_GNUC_UNUSED, - int ifindex G_GNUC_UNUSED, - void **nlData G_GNUC_UNUSED, - struct nlattr **tb G_GNUC_UNUSED, - uint32_t src_pid G_GNUC_UNUSED, - uint32_t dst_pid G_GNUC_UNUSED) -{ - virReportSystemError(ENOSYS, "%s", - _("Unable to dump link info on this platform")); - return -1; -} - - -int -virNetlinkDelLink(const char *ifname G_GNUC_UNUSED, - virNetlinkTalkFallback fallback G_GNUC_UNUSED) -{ - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _(unsupported)); - return -1; -} - - -int -virNetlinkNewLink(const char *ifname G_GNUC_UNUSED, - const char *type G_GNUC_UNUSED, - virNetlinkNewLinkData *extra_args G_GNUC_UNUSED, - int *error G_GNUC_UNUSED) -{ - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _(unsupported)); - return -1; -} - - -int -virNetlinkBridgeVlanFilterSet(const char *ifname G_GNUC_UNUSED, - const unsigned short unusedflags G_GNUC_UNUS= ED, - const short vid G_GNUC_UNUSED, - int *error) -{ - *error =3D 0; - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _(unsupported)); - return -1; -} - -int -virNetlinkBridgeVlanFilterDel(const char *ifname G_GNUC_UNUSED, - const short vid G_GNUC_UNUSED, - int *error G_GNUC_UNUSED) -{ - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _(unsupported)); - return -1; -} - -int -virNetlinkGetNeighbor(void **nlData G_GNUC_UNUSED, - uint32_t src_pid G_GNUC_UNUSED, - uint32_t dst_pid G_GNUC_UNUSED) -{ - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _(unsupported)); - return -1; -} - - -/** - * stopNetlinkEventServer: stop the monitor to receive netlink - * messages for libvirtd - */ -int virNetlinkEventServiceStop(unsigned int protocol G_GNUC_UNUSED) -{ - VIR_DEBUG("%s", unsupported); - return 0; -} - -/** - * stopNetlinkEventServerAll: stop all the monitors to receive netlink - * messages for libvirtd - */ -int virNetlinkEventServiceStopAll(void) -{ - VIR_DEBUG("%s", unsupported); - return 0; -} - -/** - * startNetlinkEventServer: start a monitor to receive netlink - * messages for libvirtd - */ -int virNetlinkEventServiceStart(unsigned int protocol G_GNUC_UNUSED, - unsigned int groups G_GNUC_UNUSED) -{ - VIR_DEBUG("%s", unsupported); - return 0; -} - -/** - * virNetlinkEventServiceIsRunning: returns if the netlink event - * service is running. - */ -bool virNetlinkEventServiceIsRunning(unsigned int protocol G_GNUC_UNUSED) -{ - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _(unsupported)); - return false; -} - -int virNetlinkEventServiceLocalPid(unsigned int protocol G_GNUC_UNUSED) -{ - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _(unsupported)); - return -1; -} - -/** - * virNetlinkEventAddClient: register a callback for handling of - * netlink messages - */ -int virNetlinkEventAddClient(virNetlinkEventHandleCallback handleCB G_GNUC= _UNUSED, - virNetlinkEventRemoveCallback removeCB G_GNUC= _UNUSED, - void *opaque G_GNUC_UNUSED, - const virMacAddr *macaddr G_GNUC_UNUSED, - unsigned int protocol G_GNUC_UNUSED) -{ - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _(unsupported)); - return -1; -} - -/** - * virNetlinkEventRemoveClient: unregister a callback from a netlink monit= or - */ -int virNetlinkEventRemoveClient(int watch G_GNUC_UNUSED, - const virMacAddr *macaddr G_GNUC_UNUSED, - unsigned int protocol G_GNUC_UNUSED) -{ - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _(unsupported)); - return -1; -} - - -int -virNetlinkGetErrorCode(struct nlmsghdr *resp G_GNUC_UNUSED, - unsigned int recvbuflen G_GNUC_UNUSED) -{ - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _(unsupported)); - return -EINVAL; -} - -#endif /* WITH_LIBNL */ diff --git a/src/util/virnetlink.h b/src/util/virnetlink.h index 74d4f5b613787b4a501ed48d8386263586e6e683..81c5a380e481dad6c9d879167f0= 618613603acdf 100644 --- a/src/util/virnetlink.h +++ b/src/util/virnetlink.h @@ -34,15 +34,6 @@ struct nl_msg * virNetlinkMsgNew(int nlmsgtype, int nlmsgflags); =20 -#else - -struct nl_msg; -struct sockaddr_nl; -struct nlattr; -struct nlmsghdr; - -#endif /* WITH_LIBNL */ - int virNetlinkStartup(void); void virNetlinkShutdown(void); =20 @@ -143,3 +134,5 @@ int virNetlinkEventAddClient(virNetlinkEventHandleCallb= ack handleCB, */ int virNetlinkEventRemoveClient(int watch, const virMacAddr *macaddr, unsigned int protocol); + +#endif /* WITH_LIBNL */ --=20 2.50.1