From nobody Thu Dec 18 17:55:19 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; dkim=pass; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1741421056; cv=none; d=zohomail.com; s=zohoarc; b=W5UI2S6hGhqTyA9s7yHILN3+87rgRLO2HNrsyF3yAalu9+v0H0ORC8Ds2W3Mufq0khmZV6KPntg1b+KTBwKcJ0eO/Mha8wDnge3DO3PXc/lRTO5U5ZzU3ZLnyYl5piROE2fNttxfWlvoikcdmF4yUFG+ReKz8mP563p9NFWlyfs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1741421056; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Subject:Subject:To:To:Message-Id:Reply-To; bh=wMr8bt3ZSg1euAwCFhidRQi1o0dkFqBp+GDJHI8mtOc=; b=UsEEbF+HIDM2+EpKyv2el8bd6u4ssIezuhYf7Iomy+YIP66n1PnHM2mIvPUeCB3tgFQfLNOdyM94oaxvASMqP6x7J57YNVHRRisbhQYT9ntbSFvEBQ1NiuZj2nvzOPYXgf4E751j9jLQ43a4MzS9A6qJ2nwUTKu1A4H2GOUno5s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1741421056295696.33424093773; Sat, 8 Mar 2025 00:04:16 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 8DCA619F1; Sat, 8 Mar 2025 03:04:15 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 5FFB1199D; Sat, 8 Mar 2025 03:03:06 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 6ADBA18A3; Sat, 8 Mar 2025 03:03:03 -0500 (EST) Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (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 1733918A1 for ; Sat, 8 Mar 2025 03:03:01 -0500 (EST) Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-22403cbb47fso51271585ad.0 for ; Sat, 08 Mar 2025 00:03:01 -0800 (PST) Received: from localhost ([157.82.205.237]) by smtp.gmail.com with UTF8SMTPSA id d2e1a72fcca58-73698514f63sm4645317b3a.143.2025.03.08.00.02.58 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 08 Mar 2025 00:02:59 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1741420980; x=1742025780; darn=lists.libvirt.org; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:from:to:cc:subject:date:message-id:reply-to; bh=wMr8bt3ZSg1euAwCFhidRQi1o0dkFqBp+GDJHI8mtOc=; b=uftLvdVEgjVzL17D7avDnG5iw95BbHkQ+Habq9zzmj5ihgOhJa5nR/EkImlHd7eKa7 GquhXVHxhW40W4CZBBY2TmCRzws8fABD8bPKGYg9+kbjpOo9VbOmiXJV/VdOXdLOlerC Kmc0ZffiEGQ2FOs92jbHBbwkenacE089Xk3XI7CR8DC6O3s15k+s+0k0UGME6f6vgvLr F2R3jmjL/L0Q6OVgdHZutVECkjXpIvTErb2BdZgz6dK7lg72M9DoHS/1Cm7FTSdBLtYz C0xm2NonwbFFUZABvxoJVuyAqeZDbvdcSMBx0RxORdLpSvv7mGABYjUQqdqhEO2wNzvL GUwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741420980; x=1742025780; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=wMr8bt3ZSg1euAwCFhidRQi1o0dkFqBp+GDJHI8mtOc=; b=iYP6DZQSgY0I+H7qs69jKkuOEvxD1pMUF8KMIoRmQY9NwQZ1EUkkLXaqS2/AdFI7zI a3wEWuzYsHppzwbm01Gg3gOoNZLsWszm9u8/1O8ZqHpXTyehduSXuTQ0Q7V51rYmCG8e efBrk3of3Il7RrXt6odmGErrWqWpYJwrOvdPuo/6N8JfN9tWi3jrPqRfWNYdFRcMrP7l Jgl7jl0PnHlHFMMcLDe8AbnQ2V4B4tjrnFBuLGOy6ZpCTMDELTIoHDrNQftddJJMjW6n BhsStUYQ94GjbUjbDeSJz5q6OLrSy90EApcQ5M/vFM3NsekslFGnjmBrgA4YxWXlRJ/a 0whw== X-Forwarded-Encrypted: i=1; AJvYcCV5V+E7OweJgxTQlyMxlzqCH3J4xhwWr2j4cvZm2xCTg1/4z3QpkDFXXHaP6Pr1BuIlqYRxKg==@lists.libvirt.org X-Gm-Message-State: AOJu0YyiBHvUf+/XyIjPvbwTzmfTOJPrqGX/a2p+J/NoXvdunEYQrXYf p64nf57lEKnXWhrP/UR2uKC3aJtJX80CFYfKEQOzowpbiXrsLULpF8xMdtXLwI0= X-Gm-Gg: ASbGncu3ocuWaE+K0to1fZ2v7WA30ko9SOIS2kVTFL3UxhPX0Sn1FVu+yt0aO6LTqcT w7xoQnhi/ZyjA0Lz9ZRw6UqpAtEw9rA8yEeSmlZyp4N6HVnUhed5kFHwxJcbaGXKgpeNI6Sca5A Er+u+Rn+CqGwQhTh2JRViFI0/Gv9C1nZ5C5zhSd8xE0G7imCUt88zUAKf63SwoULlj4hBflWg5Q r1Hgbewkig6B7UTamBLLnz29wC8N2c2vo6Ez9kUxCXllfHzsQ/FDthqJfyWjDLbwfkqpKfkj2km E4fD2553rg/5pjs6PWw3OzhWEDG4JOHeNu0EMK/ta/uF44pg X-Google-Smtp-Source: AGHT+IEHszNiEyL4TfCLdtFgfyRh+jd5UEj+f5YQ2gdNzUMSDjxHkYgULzXVVPZ75YJ8tf7Ga6NLLw== X-Received: by 2002:a05:6a00:cc2:b0:736:6279:ca25 with SMTP id d2e1a72fcca58-736aaaed7admr12603336b3a.24.1741420979717; Sat, 08 Mar 2025 00:02:59 -0800 (PST) From: Akihiko Odaki Date: Sat, 08 Mar 2025 17:02:32 +0900 Subject: [PATCH] util: Require libnl for Linux MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250308-require-v1-1-fe6850bf3f30@daynix.com> X-B4-Tracking: v=1; b=H4sIAJf5y2cC/6tWKk4tykwtVrJSqFYqSi3LLM7MzwNyDHUUlJIzE vPSU3UzU4B8JSMDI1MDYwML3aLUwtLMolRdIwtLSzMzM3PDNMsUJaDqgqLUtMwKsEnRsbW1APR 5WxFZAAAA X-Change-ID: 20250308-require-289966671f9d To: Laine Stump , devel@lists.libvirt.org X-Mailer: b4 0.14.2 Message-ID-Hash: ZJKJFHRSIJUER462G33G3L7Y6I2GKEEM X-Message-ID-Hash: ZJKJFHRSIJUER462G33G3L7Y6I2GKEEM X-MailFrom: akihiko.odaki@daynix.com 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 CC: devel@daynix.com, Akihiko Odaki , 20250307-nl-v1-1-c66fc2bf8703@daynix.com 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-ZohoMail-DKIM: pass (identity @daynix-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1741421059439019000 Builds for Linux without libnl is broken since commit 582f0966f9b9e2148d8887d072364e2a91aed000 so make libnl mandatory for Linux. Another option is to fix such builds, but it can bring more problems than benefits. libnl is available on all supported distributions so the only practical situation to lack libnl is that a developer does not have a development package of libnl installed. Enabling builds in such a situation make developers use builds divergent from CI and end-user scenarios, which has some implications. Builds without libnl lack several features such as SR-IOV, bridge/tap, switchdev, macvlan, veth, and vlan. Some part of libvirt may expect these features are readily available on Linux, and the lack of libnl may cause a build failure like one mentioned earlier or runtime errors even harder to debug. Developers will then be forced to debug such bugs and to choose either fixing the build configuration that has no real user or work around the issue by installing the development package. In any case, the bridge/tap configuration is one of the fundamental features and developers are likely to want libnl for it. Save the potential trouble for developers by requiring libnl for Linux and let Meson direct them to install libnl. Signed-off-by: Akihiko Odaki --- Supersedes: <20250307-nl-v1-1-c66fc2bf8703@daynix.com> ("[PATCH] util: Check libnl function availability") --- libvirt.spec.in | 2 - meson.build | 16 +-- meson_options.txt | 1 - src/util/virnetdev.c | 223 +++++++++++++++--------------------= -- src/util/virnetdevbridge.c | 27 +---- src/util/virnetdevip.c | 230 +++++++++++++++++++----------------= ---- src/util/virnetdevmacvlan.c | 6 +- src/util/virnetdevveth.c | 35 ------ src/util/virnetdevvportprofile.c | 8 +- src/util/virnetlink.c | 8 +- src/util/virnetlink.h | 4 +- tests/virnetdevtest.c | 8 -- 12 files changed, 222 insertions(+), 346 deletions(-) diff --git a/libvirt.spec.in b/libvirt.spec.in index cb41ea1de1c6cd3d3d5f8c810d0df7be4f7d490f..9396029dd394d218f2c1c01740a= d41754786dd04 100644 --- a/libvirt.spec.in +++ b/libvirt.spec.in @@ -1421,7 +1421,6 @@ export SOURCE_DATE_EPOCH=3D$(stat --printf=3D'%Y' %{_= specdir}/libvirt.spec) -Dlibpcap=3Denabled \ %{?arg_nbdkit} \ %{?arg_nbdkit_config_default} \ - -Dlibnl=3Denabled \ -Daudit=3Denabled \ -Ddtrace=3Denabled \ -Dfirewalld=3Denabled \ @@ -1493,7 +1492,6 @@ export SOURCE_DATE_EPOCH=3D$(stat --printf=3D'%Y' %{_= specdir}/libvirt.spec) -Dlibiscsi=3Ddisabled \ -Dnbdkit=3Ddisabled \ -Dnbdkit_config_default=3Ddisabled \ - -Dlibnl=3Ddisabled \ -Dlibpcap=3Ddisabled \ -Dlibssh2=3Ddisabled \ -Dlibssh=3Ddisabled \ diff --git a/meson.build b/meson.build index 2d76a0846c6b94f8d168d25f09dd60954db770cb..fd90bb5b3005ac7ece24da4432f= ad78bdffdefe7 100644 --- a/meson.build +++ b/meson.build @@ -1086,18 +1086,10 @@ endif conf.set10('USE_NBDKIT_DEFAULT', use_nbdkit_default) =20 libnl_version =3D '3.0' -if not get_option('libnl').disabled() and host_machine.system() =3D=3D 'li= nux' - libnl_dep =3D dependency('libnl-3.0', version: '>=3D' + libnl_version, r= equired: get_option('libnl')) - libnl_route_dep =3D dependency('libnl-route-3.0', version: '>=3D' + libn= l_version, required: get_option('libnl')) - - if libnl_dep.found() and libnl_route_dep.found() - libnl_dep =3D declare_dependency( - dependencies: [ libnl_dep, libnl_route_dep ], - ) - conf.set('WITH_LIBNL', 1) - endif -elif get_option('libnl').enabled() - error('libnl can be enabled only on linux') +if host_machine.system() =3D=3D 'linux' + libnl_dep =3D dependency('libnl-3.0', version: '>=3D' + libnl_version) + libnl_route_dep =3D dependency('libnl-route-3.0', version: '>=3D' + libn= l_version) + libnl_dep =3D declare_dependency(dependencies: [ libnl_dep, libnl_route_= dep ]) else libnl_dep =3D dependency('', required: false) endif diff --git a/meson_options.txt b/meson_options.txt index 3dc3e8667bb2cf73d96cd1ebe046590be55a5df8..bbcc13e8d8efa4c56cc3e0dc173= 86ccfd45b2b50 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -30,7 +30,6 @@ option('fuse', type: 'feature', value: 'auto', descriptio= n: 'fuse support') option('glusterfs', type: 'feature', value: 'auto', description: 'glusterf= s support') option('json_c', type: 'feature', value: 'auto', description: 'JSON-C supp= ort') option('libiscsi', type: 'feature', value: 'auto', description: 'libiscsi = support') -option('libnl', type: 'feature', value: 'auto', description: 'libnl suppor= t') option('libpcap', type: 'feature', value: 'auto', description: 'libpcap su= pport') option('libssh', type: 'feature', value: 'auto', description: 'libssh supp= ort') option('libssh2', type: 'feature', value: 'auto', description: 'libssh2 su= pport') diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c index 8ae854245ed99dc1a3aa4c225b614ddbb449caf8..4129768bd42e7b1b2a9e7b24148= 627d1abe5458a 100644 --- a/src/util/virnetdev.c +++ b/src/util/virnetdev.c @@ -884,7 +884,7 @@ int virNetDevGetIndex(const char *ifname G_GNUC_UNUSED, #endif /* ! SIOCGIFINDEX */ =20 =20 -#if defined(WITH_LIBNL) +#if defined(__linux__) /** * virNetDevGetMaster: * @ifname: name of interface we're interested in @@ -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 @@ -949,7 +926,7 @@ virNetDevGetMaster(const char *ifname G_GNUC_UNUSED, } =20 =20 -#endif /* defined(WITH_LIBNL) */ +#endif /* defined(__linux__) */ =20 =20 #if __linux__ @@ -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,99 +1355,6 @@ virNetDevGetVirtualFunctionInfo(const char *vfname, = char **pfname, return ret; } =20 -#else /* !__linux__ */ -int -virNetDevGetPhysPortID(const char *ifname G_GNUC_UNUSED, - char **physPortID) -{ - /* this actually should never be called, and is just here to - * satisfy the linker. - */ - *physPortID =3D NULL; - return 0; -} - -int -virNetDevGetPhysPortName(const char *ifname G_GNUC_UNUSED, - char **physPortName) -{ - /* this actually should never be called, and is just here to - * satisfy the linker. - */ - *physPortName =3D NULL; - return 0; -} - -int -virNetDevGetVirtualFunctions(const char *pfname G_GNUC_UNUSED, - virPCIVirtualFunctionList **vfs G_GNUC_UNUSED) -{ - virReportSystemError(ENOSYS, "%s", - _("Unable to get virtual functions on this platfo= rm")); - return -1; -} - -int -virNetDevIsVirtualFunction(const char *ifname G_GNUC_UNUSED) -{ - virReportSystemError(ENOSYS, "%s", - _("Unable to check virtual function status on thi= s platform")); - return -1; -} - -int -virNetDevGetVirtualFunctionIndex(const char *pfname G_GNUC_UNUSED, - const char *vfname G_GNUC_UNUSED, - int *vf_index G_GNUC_UNUSED) -{ - virReportSystemError(ENOSYS, "%s", - _("Unable to get virtual function index on this p= latform")); - return -1; -} - -int -virNetDevGetPhysicalFunction(const char *ifname G_GNUC_UNUSED, - char **pfname G_GNUC_UNUSED) -{ - virReportSystemError(ENOSYS, "%s", - _("Unable to get physical function status on this= platform")); - return -1; -} - -int -virNetDevPFGetVF(const char *pfname G_GNUC_UNUSED, - int vf G_GNUC_UNUSED, - char **vfname G_GNUC_UNUSED) -{ - virReportSystemError(ENOSYS, "%s", - _("Unable to get virtual function name on this pl= atform")); - return -1; -} - -int -virNetDevGetVirtualFunctionInfo(const char *vfname G_GNUC_UNUSED, - char **pfname G_GNUC_UNUSED, - int *vf G_GNUC_UNUSED) -{ - virReportSystemError(ENOSYS, "%s", - _("Unable to get virtual function info on this pl= atform")); - return -1; -} - -int -virNetDevSysfsFile(char **pf_sysfs_device_link G_GNUC_UNUSED, - const char *ifname G_GNUC_UNUSED, - const char *file G_GNUC_UNUSED) -{ - virReportSystemError(ENOSYS, "%s", - _("Unable to get sysfs info on this platform")); - return -1; -} - - -#endif /* !__linux__ */ -#if defined(WITH_LIBNL) - =20 static virMacAddr zeroMAC =3D { .addr =3D { 0, 0, 0, 0, 0, 0 } }; =20 @@ -2379,8 +2260,94 @@ virNetDevSetNetConfig(const char *linkdev, int vf, return 0; } =20 +#else /* !__linux__ */ +int +virNetDevGetPhysPortID(const char *ifname G_GNUC_UNUSED, + char **physPortID) +{ + /* this actually should never be called, and is just here to + * satisfy the linker. + */ + *physPortID =3D NULL; + return 0; +} + +int +virNetDevGetPhysPortName(const char *ifname G_GNUC_UNUSED, + char **physPortName) +{ + /* this actually should never be called, and is just here to + * satisfy the linker. + */ + *physPortName =3D NULL; + return 0; +} + +int +virNetDevGetVirtualFunctions(const char *pfname G_GNUC_UNUSED, + virPCIVirtualFunctionList **vfs G_GNUC_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Unable to get virtual functions on this platfo= rm")); + return -1; +} + +int +virNetDevIsVirtualFunction(const char *ifname G_GNUC_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Unable to check virtual function status on thi= s platform")); + return -1; +} + +int +virNetDevGetVirtualFunctionIndex(const char *pfname G_GNUC_UNUSED, + const char *vfname G_GNUC_UNUSED, + int *vf_index G_GNUC_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Unable to get virtual function index on this p= latform")); + return -1; +} + +int +virNetDevGetPhysicalFunction(const char *ifname G_GNUC_UNUSED, + char **pfname G_GNUC_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Unable to get physical function status on this= platform")); + return -1; +} =20 -#else /* defined(WITH_LIBNL) */ +int +virNetDevPFGetVF(const char *pfname G_GNUC_UNUSED, + int vf G_GNUC_UNUSED, + char **vfname G_GNUC_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Unable to get virtual function name on this pl= atform")); + return -1; +} + +int +virNetDevGetVirtualFunctionInfo(const char *vfname G_GNUC_UNUSED, + char **pfname G_GNUC_UNUSED, + int *vf G_GNUC_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Unable to get virtual function info on this pl= atform")); + return -1; +} + +int +virNetDevSysfsFile(char **pf_sysfs_device_link G_GNUC_UNUSED, + const char *ifname G_GNUC_UNUSED, + const char *file G_GNUC_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Unable to get sysfs info on this platform")); + return -1; +} =20 =20 int @@ -2477,7 +2444,7 @@ virNetDevSetVfConfig(const char *ifname G_GNUC_UNUSED, } =20 =20 -#endif /* defined(WITH_LIBNL) */ +#endif /* defined(__linux__) */ =20 VIR_ENUM_IMPL(virNetDevIfState, VIR_NETDEV_IF_STATE_LAST, @@ -3095,8 +3062,6 @@ virNetDevGetEthtoolFeatures(const char *ifname, } =20 =20 -# if defined(WITH_LIBNL) - /** * virNetDevGetFamilyId: * This function supplies the devlink family id @@ -3237,14 +3202,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 c79d0c79b7b16a0a070b5013ed7df9d0a63b1c38..45f8dd7e15286b875f5b54ad147= b32323886e1f0 100644 --- a/src/util/virnetdevbridge.c +++ b/src/util/virnetdevbridge.c @@ -30,9 +30,7 @@ #endif =20 #ifdef __linux__ -# if defined(WITH_LIBNL) -# include "virnetlink.h" -# endif +# include "virnetlink.h" # include # include /* HZ */ # include @@ -479,7 +477,7 @@ virNetDevBridgeCreateWithIoctl(const char *brname, } #endif =20 -#if defined(WITH_LIBNL) +#if defined(__linux__) int virNetDevBridgeCreate(const char *brname, const virMacAddr *mac) @@ -509,15 +507,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, @@ -590,7 +579,7 @@ virNetDevBridgeDeleteWithIoctl(const char *brname) #endif =20 =20 -#if defined(WITH_LIBNL) +#if defined(__linux__) int virNetDevBridgeDelete(const char *brname) { @@ -606,14 +595,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) @@ -1020,7 +1001,7 @@ virNetDevBridgeSetVlanFiltering(const char *brname G_= GNUC_UNUSED, #endif =20 =20 -#if defined(WITH_LIBNL) +#if defined(__linux__) =20 # ifndef NTF_SELF # define NTF_SELF 0x02 diff --git a/src/util/virnetdevip.c b/src/util/virnetdevip.c index f365c1999c3d358a6a7b56ebda9f318c25fe96fd..acb0f41321b3d1d0f83fcf808ea= 9f95ffd9ddd46 100644 --- a/src/util/virnetdevip.c +++ b/src/util/virnetdevip.c @@ -52,7 +52,7 @@ =20 VIR_LOG_INIT("util.netdevip"); =20 -#if defined(WITH_LIBNL) +#if defined(__linux__) =20 static int virNetDevGetIPAddressBinary(virSocketAddr *addr, void **data, size_t *len) @@ -361,7 +361,118 @@ virNetDevIPRouteAdd(const char *ifname, } =20 =20 -#else /* defined(WITH_LIBNL) */ +static int +virNetDevIPGetAcceptRA(const char *ifname) +{ + g_autofree char *path =3D NULL; + g_autofree char *buf =3D NULL; + char *suffix; + int accept_ra =3D -1; + + path =3D g_strdup_printf("/proc/sys/net/ipv6/conf/%s/accept_ra", + ifname ? ifname : "all"); + + if ((virFileReadAll(path, 512, &buf) < 0) || + (virStrToLong_i(buf, &suffix, 10, &accept_ra) < 0)) + return -1; + + return accept_ra; +} + +/** + * virNetDevIPCheckIPv6Forwarding + * + * This function checks if IPv6 routes have the RTF_ADDRCONF flag set, + * indicating they have been created by the kernel's RA configuration + * handling. These routes are subject to being flushed when ipv6 + * forwarding is enabled unless accept_ra is explicitly set to "2". + * This will most likely result in ipv6 networking being broken. + * + * Returns: true if it is safe to enable forwarding, or false if + * breakable routes are found. + * + **/ +bool +virNetDevIPCheckIPv6Forwarding(void) +{ + int len; + char *cur; + g_autofree char *buf =3D NULL; + /* lines are 150 chars */ + enum {MAX_ROUTE_SIZE =3D 150*1000000}; + + /* This is /proc/sys/net/ipv6/conf/all/accept_ra */ + int all_accept_ra =3D virNetDevIPGetAcceptRA(NULL); + + /* Read ipv6 routes */ + if ((len =3D virFileReadAll(PROC_NET_IPV6_ROUTE, + MAX_ROUTE_SIZE, &buf)) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unable to read %1$s for ipv6 forwarding checks"), + PROC_NET_IPV6_ROUTE); + return false; + } + + /* Dropping the last character to stop the loop */ + if (len > 0) + buf[len-1] =3D '\0'; + + cur =3D buf; + while (cur) { + char route[33], flags[9], iface[9]; + unsigned int flags_val; + char *iface_val; + int num; + char *nl =3D strchr(cur, '\n'); + + if (nl) + *nl++ =3D '\0'; + + num =3D sscanf(cur, "%32s %*s %*s %*s %*s %*s %*s %*s %8s %8s", + route, flags, iface); + + cur =3D nl; + if (num !=3D 3) { + VIR_DEBUG("Failed to parse route line: %s", cur); + continue; + } + + if (virStrToLong_ui(flags, NULL, 16, &flags_val)) { + VIR_DEBUG("Failed to parse flags: %s", flags); + continue; + } + + /* This is right justified, strip leading spaces */ + iface_val =3D &iface[0]; + while (*iface_val && g_ascii_isspace(*iface_val)) + iface_val++; + + VIR_DEBUG("%s iface %s flags %s : RTF_ADDRCONF %sset", + route, iface_val, flags, + (flags_val & RTF_ADDRCONF ? "" : "not ")); + + if (flags_val & RTF_ADDRCONF) { + int ret =3D virNetDevIPGetAcceptRA(iface_val); + VIR_DEBUG("%s reports accept_ra of %d", + iface_val, ret); + /* If the interface for this autoconfigured route + * has accept_ra =3D=3D 1, or it is default and the "all" + * value of accept_ra =3D=3D 1, it will be subject to + * flushing if forwarding is enabled. + */ + if (ret =3D=3D 1 || (ret =3D=3D 0 && all_accept_ra =3D=3D 1)) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Check the host setup: interface %1$s has= kernel autoconfigured IPv6 routes and enabling forwarding without accept_r= a set to 2 will cause the kernel to flush them, breaking networking."), + iface_val); + return false; + } + } + } + return true; +} + + +#else /* defined(__linux__) */ =20 =20 int @@ -482,121 +593,6 @@ virNetDevIPRouteAdd(const char *ifname, return 0; } =20 -#endif /* defined(HAVE_LIBNL) */ - - -#if defined(__linux__) - -static int -virNetDevIPGetAcceptRA(const char *ifname) -{ - g_autofree char *path =3D NULL; - g_autofree char *buf =3D NULL; - char *suffix; - int accept_ra =3D -1; - - path =3D g_strdup_printf("/proc/sys/net/ipv6/conf/%s/accept_ra", - ifname ? ifname : "all"); - - if ((virFileReadAll(path, 512, &buf) < 0) || - (virStrToLong_i(buf, &suffix, 10, &accept_ra) < 0)) - return -1; - - return accept_ra; -} - -/** - * virNetDevIPCheckIPv6Forwarding - * - * This function checks if IPv6 routes have the RTF_ADDRCONF flag set, - * indicating they have been created by the kernel's RA configuration - * handling. These routes are subject to being flushed when ipv6 - * forwarding is enabled unless accept_ra is explicitly set to "2". - * This will most likely result in ipv6 networking being broken. - * - * Returns: true if it is safe to enable forwarding, or false if - * breakable routes are found. - * - **/ -bool -virNetDevIPCheckIPv6Forwarding(void) -{ - int len; - char *cur; - g_autofree char *buf =3D NULL; - /* lines are 150 chars */ - enum {MAX_ROUTE_SIZE =3D 150*1000000}; - - /* This is /proc/sys/net/ipv6/conf/all/accept_ra */ - int all_accept_ra =3D virNetDevIPGetAcceptRA(NULL); - - /* Read ipv6 routes */ - if ((len =3D virFileReadAll(PROC_NET_IPV6_ROUTE, - MAX_ROUTE_SIZE, &buf)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Unable to read %1$s for ipv6 forwarding checks"), - PROC_NET_IPV6_ROUTE); - return false; - } - - /* Dropping the last character to stop the loop */ - if (len > 0) - buf[len-1] =3D '\0'; - - cur =3D buf; - while (cur) { - char route[33], flags[9], iface[9]; - unsigned int flags_val; - char *iface_val; - int num; - char *nl =3D strchr(cur, '\n'); - - if (nl) - *nl++ =3D '\0'; - - num =3D sscanf(cur, "%32s %*s %*s %*s %*s %*s %*s %*s %8s %8s", - route, flags, iface); - - cur =3D nl; - if (num !=3D 3) { - VIR_DEBUG("Failed to parse route line: %s", cur); - continue; - } - - if (virStrToLong_ui(flags, NULL, 16, &flags_val)) { - VIR_DEBUG("Failed to parse flags: %s", flags); - continue; - } - - /* This is right justified, strip leading spaces */ - iface_val =3D &iface[0]; - while (*iface_val && g_ascii_isspace(*iface_val)) - iface_val++; - - VIR_DEBUG("%s iface %s flags %s : RTF_ADDRCONF %sset", - route, iface_val, flags, - (flags_val & RTF_ADDRCONF ? "" : "not ")); - - if (flags_val & RTF_ADDRCONF) { - int ret =3D virNetDevIPGetAcceptRA(iface_val); - VIR_DEBUG("%s reports accept_ra of %d", - iface_val, ret); - /* If the interface for this autoconfigured route - * has accept_ra =3D=3D 1, or it is default and the "all" - * value of accept_ra =3D=3D 1, it will be subject to - * flushing if forwarding is enabled. - */ - if (ret =3D=3D 1 || (ret =3D=3D 0 && all_accept_ra =3D=3D 1)) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Check the host setup: interface %1$s has= kernel autoconfigured IPv6 routes and enabling forwarding without accept_r= a set to 2 will cause the kernel to flush them, breaking networking."), - iface_val); - return false; - } - } - } - return true; -} -#else =20 bool virNetDevIPCheckIPv6Forwarding(void) diff --git a/src/util/virnetdevmacvlan.c b/src/util/virnetdevmacvlan.c index cde9d70eefd047dc5c16056f6697cf4d05bc0795..c8a7a92eb6d8bedc3b1a838ac86= 7e9b104cc5cb0 100644 --- a/src/util/virnetdevmacvlan.c +++ b/src/util/virnetdevmacvlan.c @@ -35,7 +35,7 @@ VIR_ENUM_IMPL(virNetDevMacVLanMode, "passthrough", ); =20 -#if defined(WITH_LIBNL) +#if defined(__linux__) # include =20 # include @@ -859,7 +859,7 @@ int virNetDevMacVLanRestartWithVPortProfile(const char = *cr_ifname, =20 } =20 -#else /* ! WITH_LIBNL */ +#else /* ! __linux__ */ bool virNetDevMacVLanIsMacvtap(const char *ifname G_GNUC_UNUSED) { virReportSystemError(ENOSYS, "%s", @@ -959,4 +959,4 @@ int virNetDevMacVLanVPortProfileRegisterCallback(const = char *ifname G_GNUC_UNUSE _("Cannot create macvlan devices on this platform= ")); return -1; } -#endif /* ! WITH_LIBNL */ +#endif /* ! __linux__ */ diff --git a/src/util/virnetdevveth.c b/src/util/virnetdevveth.c index 4365345664c50f47680d5fdb74d616ac989a57c9..7c4a36d3d54c4da34cb2049966d= 142f1b6974278 100644 --- a/src/util/virnetdevveth.c +++ b/src/util/virnetdevveth.c @@ -32,7 +32,6 @@ VIR_LOG_INIT("util.netdevveth"); =20 =20 -#if defined(WITH_LIBNL) static int virNetDevVethCreateInternal(const char *veth1, const char *veth2) { @@ -56,40 +55,6 @@ virNetDevVethDeleteInternal(const char *veth) { return virNetlinkDelLink(veth, NULL); } -#else -static int -virNetDevVethCreateInternal(const char *veth1, const char *veth2) -{ - g_autoptr(virCommand) cmd =3D virCommandNew("ip"); - virCommandAddArgList(cmd, "link", "add", veth1, "type", "veth", - "peer", "name", veth2, NULL); - - return virCommandRun(cmd, NULL); -} - -static int -virNetDevVethDeleteInternal(const char *veth) -{ - int status; - g_autoptr(virCommand) cmd =3D virCommandNewArgList("ip", "link", - "del", veth, NULL); - - if (virCommandRun(cmd, &status) < 0) - return -1; - - if (status !=3D 0) { - if (!virNetDevExists(veth)) { - VIR_DEBUG("Device %s already deleted (by kernel namespace clea= nup)", veth); - return 0; - } - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Failed to delete veth device %1$s"), veth); - return -1; - } - - return 0; -} -#endif /* WITH_LIBNL */ =20 /** * virNetDevVethCreate: diff --git a/src/util/virnetdevvportprofile.c b/src/util/virnetdevvportprof= ile.c index c755fa79ec02e0e77b06bf6a3b6f42e24421e7dc..26be6e91319b98539927e607959= 6b976af207642 100644 --- a/src/util/virnetdevvportprofile.c +++ b/src/util/virnetdevvportprofile.c @@ -46,7 +46,7 @@ VIR_ENUM_IMPL(virNetDevVPortProfileOp, "no-op", ); =20 -#if defined(WITH_LIBNL) +#if defined(__linux__) =20 # include =20 @@ -446,7 +446,7 @@ int virNetDevVPortProfileMerge3(virNetDevVPortProfile *= *result, } =20 =20 -#if defined(WITH_LIBNL) +#if defined(__linux__) =20 static struct nla_policy ifla_port_policy[IFLA_PORT_MAX + 1] =3D { @@ -1327,7 +1327,7 @@ virNetDevVPortProfileDisassociate(const char *macvtap= _ifname, return rc; } =20 -#else /* !WITH_LIBNL */ +#else /* !__linux__ */ int virNetDevVPortProfileAssociate(const char *macvtap_ifname G_GNUC_UNUSE= D, const virNetDevVPortProfile *virtPort G= _GNUC_UNUSED, const virMacAddr *macvtap_macaddr G_GNU= C_UNUSED, @@ -1353,4 +1353,4 @@ int virNetDevVPortProfileDisassociate(const char *mac= vtap_ifname G_GNUC_UNUSED, _("Virtual port profile association not supported= on this platform")); return -1; } -#endif /* !WITH_LIBNL */ +#endif /* !__linux__ */ diff --git a/src/util/virnetlink.c b/src/util/virnetlink.c index 206646d9d794d833de90266d4ab7cec015552137..0bb0ef23da28f2810d4e31c1bf9= 017545f11d0b9 100644 --- a/src/util/virnetlink.c +++ b/src/util/virnetlink.c @@ -37,7 +37,7 @@ VIR_LOG_INIT("util.netlink"); =20 #define NETLINK_ACK_TIMEOUT_S (2*1000) =20 -#if defined(WITH_LIBNL) +#if defined(__linux__) =20 # include =20 @@ -1267,11 +1267,7 @@ virNetlinkEventRemoveClient(int watch, const virMacA= ddr *macaddr, =20 #else =20 -# 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 =20 int virNetlinkStartup(void) @@ -1435,4 +1431,4 @@ virNetlinkGetErrorCode(struct nlmsghdr *resp G_GNUC_U= NUSED, return -EINVAL; } =20 -#endif /* WITH_LIBNL */ +#endif /* __linux__ */ diff --git a/src/util/virnetlink.h b/src/util/virnetlink.h index 327fb426a1d898398a60e46d3ee8fc554a2db548..56ee48161ada307e8af0bd2d4b8= d7497a43e075c 100644 --- a/src/util/virnetlink.h +++ b/src/util/virnetlink.h @@ -22,7 +22,7 @@ #include "internal.h" #include "virmacaddr.h" =20 -#if defined(WITH_LIBNL) +#if defined(__linux__) =20 # include # include @@ -41,7 +41,7 @@ struct sockaddr_nl; struct nlattr; struct nlmsghdr; =20 -#endif /* WITH_LIBNL */ +#endif /* __linux__ */ =20 int virNetlinkStartup(void); void virNetlinkShutdown(void); diff --git a/tests/virnetdevtest.c b/tests/virnetdevtest.c index 42f1a74ee9ad66f40150920670a4f71518c9d610..99cf347934911aa4ae40bf61145= e7817efbee97b 100644 --- a/tests/virnetdevtest.c +++ b/tests/virnetdevtest.c @@ -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 --- base-commit: e5299ddf86121d3c792ca271ffcb54900eb19dc3 change-id: 20250308-require-289966671f9d Best regards, --=20 Akihiko Odaki