summaryrefslogtreecommitdiff
path: root/net/core/rtnetlink.c
diff options
context:
space:
mode:
authorEric Dumazet <edumazet@google.com>2026-05-11 07:02:44 +0000
committerJakub Kicinski <kuba@kernel.org>2026-05-12 18:30:26 -0700
commitb588019e85f490696bf19f0747e93f14b1563927 (patch)
tree69616dcd4929fdcd3e3e65bf7d2324210e4639c3 /net/core/rtnetlink.c
parent9edbdd2c9d02667b3953997440036ea2ba932b4d (diff)
downloadlinux-next-b588019e85f490696bf19f0747e93f14b1563927.tar.gz
linux-next-b588019e85f490696bf19f0747e93f14b1563927.zip
rtnetlink: add RTEXT_FILTER_NAME_ONLY support
iproute2 can spend considerable amount of time in ll_init_map() or ll_link_get() to dump verbose netdev attributes, contributing to RTNL pressure. Add RTEXT_FILTER_NAME_ONLY new flag so that rtnl_fill_ifinfo() limits its output to: - struct nlmsghdr - IFLA_IFNAME - IFLA_PROP_LIST (alternate names) We can later avoid using RTNL when RTEXT_FILTER_NAME_ONLY is requested, as none of these attributes need RTNL. Signed-off-by: Eric Dumazet <edumazet@google.com> Reviewed-by: Kuniyuki Iwashima <kuniyu@google.com> Link: https://patch.msgid.link/20260511070244.971028-1-edumazet@google.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Diffstat (limited to 'net/core/rtnetlink.c')
-rw-r--r--net/core/rtnetlink.c31
1 files changed, 22 insertions, 9 deletions
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index df042da422ef..70fde922b371 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -1295,7 +1295,12 @@ static noinline size_t if_nlmsg_size(const struct net_device *dev,
size = NLMSG_ALIGN(sizeof(struct ifinfomsg))
+ nla_total_size(IFNAMSIZ) /* IFLA_IFNAME */
- + nla_total_size(IFALIASZ) /* IFLA_IFALIAS */
+ + rtnl_prop_list_size(dev);
+
+ if (ext_filter_mask & RTEXT_FILTER_NAME_ONLY)
+ return size;
+
+ size += nla_total_size(IFALIASZ) /* IFLA_IFALIAS */
+ nla_total_size(IFNAMSIZ) /* IFLA_QDISC */
+ nla_total_size_64bit(sizeof(struct rtnl_link_ifmap))
+ nla_total_size(MAX_ADDR_LEN) /* IFLA_ADDRESS */
@@ -1342,7 +1347,6 @@ static noinline size_t if_nlmsg_size(const struct net_device *dev,
+ nla_total_size(4) /* IFLA_CARRIER_DOWN_COUNT */
+ nla_total_size(4) /* IFLA_MIN_MTU */
+ nla_total_size(4) /* IFLA_MAX_MTU */
- + rtnl_prop_list_size(dev)
+ nla_total_size(MAX_ADDR_LEN) /* IFLA_PERM_ADDRESS */
+ rtnl_devlink_port_size(dev)
+ rtnl_dpll_pin_size(dev)
@@ -1941,15 +1945,18 @@ static int rtnl_fill_alt_ifnames(struct sk_buff *skb,
struct netdev_name_node *name_node;
int count = 0;
+ rcu_read_lock();
list_for_each_entry_rcu(name_node, &dev->name_node->list, list) {
- if (nla_put_string(skb, IFLA_ALT_IFNAME, name_node->name))
+ if (nla_put_string(skb, IFLA_ALT_IFNAME, name_node->name)) {
+ rcu_read_unlock();
return -EMSGSIZE;
+ }
count++;
}
+ rcu_read_unlock();
return count;
}
-/* RCU protected. */
static int rtnl_fill_prop_list(struct sk_buff *skb,
const struct net_device *dev)
{
@@ -2072,13 +2079,20 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb,
ifm->ifi_flags = netif_get_flags(dev);
ifm->ifi_change = change;
- if (tgt_netnsid >= 0 && nla_put_s32(skb, IFLA_TARGET_NETNSID, tgt_netnsid))
- goto nla_put_failure;
-
netdev_copy_name(dev, devname);
if (nla_put_string(skb, IFLA_IFNAME, devname))
goto nla_put_failure;
+ if (rtnl_fill_prop_list(skb, dev))
+ goto nla_put_failure;
+
+ if (ext_filter_mask & RTEXT_FILTER_NAME_ONLY)
+ goto end;
+
+ if (tgt_netnsid >= 0 &&
+ nla_put_s32(skb, IFLA_TARGET_NETNSID, tgt_netnsid))
+ goto nla_put_failure;
+
if (nla_put_u32(skb, IFLA_TXQLEN, READ_ONCE(dev->tx_queue_len)) ||
nla_put_u8(skb, IFLA_OPERSTATE,
netif_running(dev) ? READ_ONCE(dev->operstate) :
@@ -2191,8 +2205,6 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb,
goto nla_put_failure_rcu;
if (rtnl_fill_link_ifmap(skb, dev))
goto nla_put_failure_rcu;
- if (rtnl_fill_prop_list(skb, dev))
- goto nla_put_failure_rcu;
rcu_read_unlock();
if (dev->dev.parent &&
@@ -2211,6 +2223,7 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb,
if (rtnl_fill_dpll_pin(skb, dev))
goto nla_put_failure;
+end:
nlmsg_end(skb, nlh);
return 0;