* [PATCH] ipc: linux: filter netdevices kernel-side
@ 2025-09-05 19:51 Asbjørn Sloth Tønnesen
0 siblings, 0 replies; only message in thread
From: Asbjørn Sloth Tønnesen @ 2025-09-05 19:51 UTC (permalink / raw)
To: Jason A. Donenfeld; +Cc: Asbjørn Sloth Tønnesen, wireguard
Tell the kernel that we are only interested in wireguard
netdevices, so that the kernel don't have to tells us about
all the other netdevices.
Tested with 10000 netdevices (common with ISP BNG setups),
out of which 1 was a 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
Signed-off-by: Asbjørn Sloth Tønnesen <wireguard@asbjorn.st>
---
NB: Since this email has been on the list a long-time, then
maybe it will avoid moderation.
src/ipc-linux.h | 6 ++++++
1 file changed, 6 insertions(+)
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.51.0
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2025-09-05 19:54 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-09-05 19:51 [PATCH] ipc: linux: filter netdevices kernel-side Asbjørn Sloth Tønnesen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).