rtnetlink: honor RTEXT_FILTER_SKIP_STATS in IFLA_STATS
Subsystems (2)
PATCH v3 1/1 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/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
--- net/core/rtnetlink.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
net/core/rtnetlink.c +11 -4
@@ -1270,13 +1270,13 @@ static size_t rtnl_dpll_pin_size(const struct net_device *dev) static noinline size_t if_nlmsg_size(const struct net_device *dev,u32 ext_filter_mask) { -return NLMSG_ALIGN (sizeof (struct ifinfomsg )) +size_t size; + + size =NLMSG_ALIGN (sizeof (struct ifinfomsg )) +nla_total_size (IFNAMSIZ )/* IFLA_IFNAME */ +nla_total_size (IFALIASZ )/* IFLA_IFALIAS */ +nla_total_size (IFNAMSIZ )/* IFLA_QDISC */ +nla_total_size_64bit (sizeof (struct rtnl_link_ifmap )) - +nla_total_size (sizeof (struct rtnl_link_stats )) - +nla_total_size_64bit (sizeof (struct rtnl_link_stats64 )) +nla_total_size (MAX_ADDR_LEN )/* IFLA_ADDRESS */ +nla_total_size (MAX_ADDR_LEN )/* IFLA_BROADCAST */ +nla_total_size (4 )/* IFLA_TXQLEN */
@@ -1329,6 +1329,12 @@ static noinline size_t if_nlmsg_size(const struct net_device *dev, +nla_total_size (2 )/* IFLA_HEADROOM */ +nla_total_size (2 )/* IFLA_TAILROOM */ +0 ; + +if (!(ext_filter_mask &RTEXT_FILTER_SKIP_STATS )) + size +=nla_total_size (sizeof (struct rtnl_link_stats )) + +nla_total_size_64bit (sizeof (struct rtnl_link_stats64 )); + +return size; }static int rtnl_vf_ports_fill (struct sk_buff *skb,struct net_device *dev)
@@ -2123,7 +2129,8 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb,if (rtnl_phys_switch_id_fill (skb, dev)) goto nla_put_failure; -if (rtnl_fill_stats (skb, dev)) +if (!(ext_filter_mask &RTEXT_FILTER_SKIP_STATS ) && +rtnl_fill_stats (skb, dev)) goto nla_put_failure;if (rtnl_fill_vf (skb, dev, ext_filter_mask))
Signature · 1 line
2.51.1
Quoted 13 lines · Adrian Moreno
Gathering interface statistics can be a relatively expensive operation on certain systems as it requires iterating over all the cpus.
RTEXT_FILTER_SKIP_STATSwas first introduced [1] to skipAF_INET6statistics from interface dumps and it was then extended [2] to also excludeIFLA_VF_INFO.The semantics of the flag does not seem to be limited to
AF_INETor 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 useRTEXT_FILTER_SKIP_STATSto also affectIFLA_STATS.
Quoted 4 lines
[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/Signed-off-by Adrian Moreno <[email protected]>
Eric Dumazet
Reviewed-byQuoted 16 lines · Toke Høiland-Jørgensen
Quoted 13 lines · Adrian Moreno
Gathering interface statistics can be a relatively expensive operation on certain systems as it requires iterating over all the cpus.
RTEXT_FILTER_SKIP_STATSwas first introduced [1] to skipAF_INET6statistics from interface dumps and it was then extended [2] to also excludeIFLA_VF_INFO.The semantics of the flag does not seem to be limited to
AF_INETor 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 useRTEXT_FILTER_SKIP_STATSto also affectIFLA_STATS.
Quoted 6 lines
Quoted 4 lines
[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/Signed-off-by Adrian Moreno <[email protected]>Reviewed-by Toke Høiland-Jørgensen <[email protected]>
Le 03/11/2025 à 16:40, Adrian Moreno a écrit :
Quoted 13 lines
Gathering interface statistics can be a relatively expensive operation on certain systems as it requires iterating over all the cpus.
RTEXT_FILTER_SKIP_STATSwas first introduced [1] to skipAF_INET6statistics from interface dumps and it was then extended [2] to also excludeIFLA_VF_INFO.The semantics of the flag does not seem to be limited to
AF_INETor 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 useRTEXT_FILTER_SKIP_STATSto also affectIFLA_STATS.
Quoted 4 lines
[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/Signed-off-by Adrian Moreno <[email protected]>
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 8 lines · On Mon, 3 Nov 2025 16:40:04 +0100 you wrote:
Gathering interface statistics can be a relatively expensive operation on certain systems as it requires iterating over all the cpus.
RTEXT_FILTER_SKIP_STATSwas first introduced [1] to skipAF_INET6statistics from interface dumps and it was then extended [2] to also excludeIFLA_VF_INFO.[...]
Here is the summary with links:
- [net-next,v3] rtnetlink: honor RTEXT_FILTER_SKIP_STATS in IFLA_STATS
https://git.kernel.org/netdev/net-next/c/105bae321862
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html