Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.zx2c4.com (lists.zx2c4.com [165.227.139.114]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C6157106ACEE for ; Thu, 12 Mar 2026 21:44:47 +0000 (UTC) Received: by lists.zx2c4.com (OpenSMTPD) with ESMTP id f436a991; Thu, 12 Mar 2026 21:44:46 +0000 (UTC) Received: from mail1.fiberby.net (mail1.fiberby.net [193.104.135.124]) by lists.zx2c4.com (OpenSMTPD) with ESMTPS id 08e23ae7 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Thu, 12 Mar 2026 21:44:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fiberby.net; s=202008; t=1773351877; bh=rgWAIQk0thXBLObYbgJRD6jXe739ylGLKwWMHGlZXFs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EhZ57ICYlpVFZydYU4y1OMj15Xk4Vhwg++odFUnrhIBKgFNCJpLiAlaBTEBWk0Nx2 W8wivyRlFkTSKR/g90B5vrQ1g+lgICzp9PmUjo5++r8XmXhlgUpaWWNj3aTOkAa9hK 0sDmAhJT1yubsh+shR0TMc6G3yxsK427PWIJYMd/KqbqIWFPmXPH0T1lS355FEXgTc cwv2K5yOhwpQe8jD0J3nki0Ow5DLxvRfZw09poofEhCPvE8ljNVHwbwdZTkXnnIEUb Rno5cqNVPir1skOMGU6KF9UYFDmhM6Rb6vcReUHDqKvq5nlouKwnvBr/XrsmF/igS8 vWEyYMcLIHM2g== Received: from x201s (193-104-135-243.ip4.fiberby.net [193.104.135.243]) by mail1.fiberby.net (Postfix) with ESMTPSA id 7454A600FC; Thu, 12 Mar 2026 21:44:37 +0000 (UTC) Received: by x201s (Postfix, from userid 1000) id AEF84202015; Thu, 12 Mar 2026 21:44:20 +0000 (UTC) From: =?UTF-8?q?Asbj=C3=B8rn=20Sloth=20T=C3=B8nnesen?= To: "Jason A . Donenfeld" Cc: =?UTF-8?q?Asbj=C3=B8rn=20Sloth=20T=C3=B8nnesen?= , wireguard@lists.zx2c4.com Subject: [PATCH wireguard-tools v4 1/3] ipc: linux: filter netdevices kernel-side Date: Thu, 12 Mar 2026 21:43:59 +0000 Message-ID: <20260312214405.589127-2-ast@fiberby.net> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260312214405.589127-1-ast@fiberby.net> References: <20260312214405.589127-1-ast@fiberby.net> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: wireguard@lists.zx2c4.com X-Mailman-Version: 2.1.30rc1 Precedence: list List-Id: Development discussion of WireGuard List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: wireguard-bounces@lists.zx2c4.com Sender: "WireGuard" Tell the kernel that we are only interested in wireguard netdevices, so the kernel don't have to dump all the other netdevices. Kernel-side support for this was added in Linux v4.6 in commit dc599f76c22b ("net: Add support for filtering link dump by master device and kind"). Tested with 10000 netdevices (common with ISP BNG setups), and a single wireguard netdevice. Baseline: # time ./src/wg show real 0m0.342s user 0m0.013s sys 0m0.290s With patch: # time ./src/wg show real 0m0.006s user 0m0.000s sys 0m0.005s Despite the subject prefix, this patch also applies to the embeddable C library, so the two implementations stay in sync. Signed-off-by: Asbjørn Sloth Tønnesen --- contrib/embeddable-wg-library/wireguard.c | 6 ++++++ src/ipc-linux.h | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/contrib/embeddable-wg-library/wireguard.c b/contrib/embeddable-wg-library/wireguard.c index 4941549..7ac0d6c 100644 --- a/contrib/embeddable-wg-library/wireguard.c +++ b/contrib/embeddable-wg-library/wireguard.c @@ -943,6 +943,7 @@ static int fetch_device_names(struct string_list *list) int ret = 0; struct nlmsghdr *nlh; struct ifinfomsg *ifm; + struct nlattr *linkinfo_nest; ret = -ENOMEM; rtnl_buffer = calloc(mnl_ideal_socket_buffer_size(), 1); @@ -968,6 +969,11 @@ static int fetch_device_names(struct string_list *list) nlh->nlmsg_seq = seq; ifm = mnl_nlmsg_put_extra_header(nlh, sizeof(*ifm)); ifm->ifi_family = AF_UNSPEC; + + linkinfo_nest = mnl_attr_nest_start(nlh, IFLA_LINKINFO); + mnl_attr_put_strz(nlh, IFLA_INFO_KIND, WG_GENL_NAME); + mnl_attr_nest_end(nlh, linkinfo_nest); + message_len = nlh->nlmsg_len; if (mnl_socket_sendto(nl, rtnl_buffer, message_len) < 0) { diff --git a/src/ipc-linux.h b/src/ipc-linux.h index 01247f1..c56fede 100644 --- a/src/ipc-linux.h +++ b/src/ipc-linux.h @@ -80,6 +80,7 @@ static int kernel_get_wireguard_interfaces(struct string_list *list) int ret = 0; struct nlmsghdr *nlh; struct ifinfomsg *ifm; + struct nlattr *linkinfo_nest; ret = -ENOMEM; rtnl_buffer = calloc(SOCKET_BUFFER_SIZE, 1); @@ -105,6 +106,11 @@ static int kernel_get_wireguard_interfaces(struct string_list *list) nlh->nlmsg_seq = seq; ifm = mnl_nlmsg_put_extra_header(nlh, sizeof(*ifm)); ifm->ifi_family = AF_UNSPEC; + + linkinfo_nest = mnl_attr_nest_start(nlh, IFLA_LINKINFO); + mnl_attr_put_strz(nlh, IFLA_INFO_KIND, WG_GENL_NAME); + mnl_attr_nest_end(nlh, linkinfo_nest); + message_len = nlh->nlmsg_len; if (mnl_socket_sendto(nl, rtnl_buffer, message_len) < 0) { -- 2.53.0