Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

rtnetlink: honor RTEXT_FILTER_SKIP_STATS in IFLA_STATS

Gathering interface statistics can be a relatively expensive operation
on certain systems as it requires iterating over all the cpus.

RTEXT_FILTER_SKIP_STATS was first introduced [1] to skip AF_INET6
statistics from interface dumps and it was then extended [2] to
also exclude IFLA_VF_INFO.

The semantics of the flag does not seem to be limited to AF_INET
or VF statistics and having a way to query the interface status
(e.g: carrier, address) without retrieving its statistics seems
reasonable. So this patch extends the use RTEXT_FILTER_SKIP_STATS
to also affect IFLA_STATS.

[1] https://lore.kernel.org/all/20150911204848.GC9687@oracle.com/
[2] https://lore.kernel.org/all/20230611105108.122586-1-gal@nvidia.com/

Signed-off-by: Adrian Moreno <amorenoz@redhat.com>
Reviewed-by: Toke Høiland-Jørgensen <toke@redhat.com>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Reviewed-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
Link: https://patch.msgid.link/20251103154006.1189707-1-amorenoz@redhat.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Adrian Moreno and committed by
Jakub Kicinski
105bae32 255d75ef

+11 -4
+11 -4
net/core/rtnetlink.c
··· 1270 1270 static noinline size_t if_nlmsg_size(const struct net_device *dev, 1271 1271 u32 ext_filter_mask) 1272 1272 { 1273 - return NLMSG_ALIGN(sizeof(struct ifinfomsg)) 1273 + size_t size; 1274 + 1275 + size = NLMSG_ALIGN(sizeof(struct ifinfomsg)) 1274 1276 + nla_total_size(IFNAMSIZ) /* IFLA_IFNAME */ 1275 1277 + nla_total_size(IFALIASZ) /* IFLA_IFALIAS */ 1276 1278 + nla_total_size(IFNAMSIZ) /* IFLA_QDISC */ 1277 1279 + nla_total_size_64bit(sizeof(struct rtnl_link_ifmap)) 1278 - + nla_total_size(sizeof(struct rtnl_link_stats)) 1279 - + nla_total_size_64bit(sizeof(struct rtnl_link_stats64)) 1280 1280 + nla_total_size(MAX_ADDR_LEN) /* IFLA_ADDRESS */ 1281 1281 + nla_total_size(MAX_ADDR_LEN) /* IFLA_BROADCAST */ 1282 1282 + nla_total_size(4) /* IFLA_TXQLEN */ ··· 1329 1329 + nla_total_size(2) /* IFLA_HEADROOM */ 1330 1330 + nla_total_size(2) /* IFLA_TAILROOM */ 1331 1331 + 0; 1332 + 1333 + if (!(ext_filter_mask & RTEXT_FILTER_SKIP_STATS)) 1334 + size += nla_total_size(sizeof(struct rtnl_link_stats)) + 1335 + nla_total_size_64bit(sizeof(struct rtnl_link_stats64)); 1336 + 1337 + return size; 1332 1338 } 1333 1339 1334 1340 static int rtnl_vf_ports_fill(struct sk_buff *skb, struct net_device *dev) ··· 2129 2123 if (rtnl_phys_switch_id_fill(skb, dev)) 2130 2124 goto nla_put_failure; 2131 2125 2132 - if (rtnl_fill_stats(skb, dev)) 2126 + if (!(ext_filter_mask & RTEXT_FILTER_SKIP_STATS) && 2127 + rtnl_fill_stats(skb, dev)) 2133 2128 goto nla_put_failure; 2134 2129 2135 2130 if (rtnl_fill_vf(skb, dev, ext_filter_mask))