rtnetlink: honor RTEXT_FILTER_SKIP_STATS in IFLA_STATS
Subsystems (2)
PATCH v2 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 | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
net/core/rtnetlink.c +5 -3
@@ -1275,8 +1275,9 @@ static noinline size_t if_nlmsg_size(const struct net_device *dev, +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 )) + + ((ext_filter_mask &RTEXT_FILTER_SKIP_STATS ) ?0 : + (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 */
@@ -2123,7 +2124,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.0
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]>
Le 29/10/2025 à 09:01, 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]>
Jakub Kicinski
maintainerQuoted 4 lines · On Wed, 29 Oct 2025 09:01:52 +0100 Adrian Moreno wrote:
net/core/rtnetlink.c +0
-0@@ -1275,8 +1275,9 @@ static noinline size_t if_nlmsg_size(const struct net_device *dev, +nla_total_size (IFALIASZ )/* IFLA_IFALIAS */
net/core/rtnetlink.c static noinline size_t if_nlmsg_size(const struct net_device *dev, · line 1283
Quoted 10 lines
net/core/rtnetlink.c +3
-2+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 )) + + ((ext_filter_mask &RTEXT_FILTER_SKIP_STATS ) ?0 : + (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 */
Forgive me but now I'm gonna nit pick ;)
Please break this out into a proper if condition.
It's quite hard to read.
size_t size; size = NLMSG_ALIGN(sizeof(struct ifinfomsg)) + /* .. litany .. */ 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;
Signature · 1 line
pw-bot: cr
Quoted 20 lines · Jakub Kicinski
Quoted 4 lines · On Wed, 29 Oct 2025 09:01:52 +0100 Adrian Moreno wrote:
net/core/rtnetlink.c +0
-0@@ -1275,8 +1275,9 @@ static noinline size_t if_nlmsg_size(const struct net_device *dev, +nla_total_size (IFALIASZ )/* IFLA_IFALIAS */ net/core/rtnetlink.c static noinline size_t if_nlmsg_size(const struct net_device *dev, · line 1283
Quoted 10 lines
net/core/rtnetlink.c +3
-2+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 )) + + ((ext_filter_mask &RTEXT_FILTER_SKIP_STATS ) ?0 : + (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 */ Forgive me but now I'm gonna nit pick ;)
Please break this out into a proper if condition.
It's quite hard to read.
Quoted 10 lines
size_t size; size = NLMSG_ALIGN(sizeof(struct ifinfomsg)) + /* .. litany .. */ 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;
Sure, I'll send V3.
Quoted 3 lines
--
pw-bot: cr