Skip to contentSkip to conversation

rtnetlink: honor RTEXT_FILTER_SKIP_STATS in IFLA_STATS

PATCH Superseded Adrian Moreno 4 participants 5 messages Oct 29, 2025 – Nov 3, 2025

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

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
index 8040ff7c356e..aa09d026817b 100644
@@ -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
Reviewed-by on v2 1/1
#1 lore raw
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_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.

Quoted 4 lines

[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/

Reviewed-by on v2 1/1
#2 lore raw
In reply to Adrian Moreno

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_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.

Quoted 4 lines

[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/

maintainer
#3 lore raw
In reply to Adrian Moreno
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.

	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
#4 lore raw
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