[PATCH wireguard-tools v3 2/3] ipc: linux: skip statistics on netdevice listing
Asbjørn Sloth Tønnesen <[email protected]> Fri, 30 Jan 2026 19:10:54 +0000
| Newsgroups | com.zx2c4.lists.wireguard |
|---|---|
| Message-ID | <[email protected]> |
Gathering interface statistics can be a relatively expensive operation
on certain systems as it requires iterating over all the cpus.
This patch instructs the kernel to not include netdevice statistics,
in the netdevice listing.
Kernel-side support for this was added in Linux v4.4 in commit
d5566fd72ec1 ("rtnetlink: RTEXT_FILTER_SKIP_STATS support to avoid
dumping inet/inet6 stats"), this saves 368 bytes of statistics.
In the Linux v6.19 commit 105bae321862 ("rtnetlink: honor
RTEXT_FILTER_SKIP_STATS in IFLA_STATS"), it is expanded to skip more
statistics bringing the savings to 800 bytes per netdevice.
As the minimum kernel version for wireguard-tools is unclear, it's
wrapped in a #ifdef guard. If the minimum version is v4.4+ it can be
removed.
Signed-off-by: Asbjørn Sloth Tønnesen <[email protected]>
---
src/ipc-linux.h | 3 +++
1 file changed, 3 insertions(+)
diff --git a/src/ipc-linux.h b/src/ipc-linux.h
index c56fede..61e2c1a 100644
--- a/src/ipc-linux.h
+++ b/src/ipc-linux.h
@@ -106,6 +106,9 @@ 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;
+#ifdef RTEXT_FILTER_SKIP_STATS
+ mnl_attr_put_u32(nlh, IFLA_EXT_MASK, RTEXT_FILTER_SKIP_STATS);
+#endif
linkinfo_nest = mnl_attr_nest_start(nlh, IFLA_LINKINFO);
mnl_attr_put_strz(nlh, IFLA_INFO_KIND, WG_GENL_NAME);
--
2.51.0