From a25a51258acf916545989ed162a34a3a8cb526de Mon Sep 17 00:00:00 2001 From: Ido Schimmel Date: Wed, 14 Oct 2026 11:26:12 +0300 Subject: [PATCH] ipv4: Do not pass netns to fib_table_lookup() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Commit c436a624f89e ("ipv4: Pass netns to fib_table_lookup()") added the network namespace as an argument of fib_table_lookup() so that it could be passed to the fib_table_lookup tracepoint. However, the function is called in the data path and the namespace is only needed when the tracepoint is enabled, so the additional argument is unnecessary overhead. Instead, pass the namespace that is now stored in the FIB table to the tracepoint. This way, the namespace is only read when the tracepoint is enabled. Revert the signature of fib_table_lookup() and its callers to what they were before the above commit. The tracepoint itself is unchanged. No functional changes intended. Suggested-by: Paolo Abeni Link: https://lore.kernel.org/netdev/43857d08-c4f4-44ce-a0b3-0e7fcc56bf90@redhat.com/ Signed-off-by: Ido Schimmel Tested-by: Björn Töpel Reviewed-by: Björn Töpel Reviewed-by: David Ahern Link: https://patch.msgid.link/20261014082612.1280756-3-idosch@nvidia.com Signed-off-by: Jakub Kicinski --- include/net/ip_fib.h | 12 +++++------- net/core/filter.c | 2 +- net/ipv4/devinet.c | 3 +-- net/ipv4/fib_frontend.c | 6 ++---- net/ipv4/fib_rules.c | 2 +- net/ipv4/fib_semantics.c | 2 +- net/ipv4/fib_trie.c | 16 +++++++++------- 7 files changed, 20 insertions(+), 23 deletions(-) diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h index 033ed8fce35e..92f4eb8b86d7 100644 --- a/include/net/ip_fib.h +++ b/include/net/ip_fib.h @@ -276,9 +276,8 @@ struct fib_dump_filter { struct net_device *dev; }; -int fib_table_lookup(struct net *net, struct fib_table *tb, - const struct flowi4 *flp, struct fib_result *res, - int fib_flags); +int fib_table_lookup(struct fib_table *tb, const struct flowi4 *flp, + struct fib_result *res, int fib_flags); int fib_table_insert(struct net *, struct fib_table *, struct fib_config *, struct netlink_ext_ack *extack); int fib_table_delete(struct net *, struct fib_table *, struct fib_config *, @@ -325,8 +324,7 @@ static inline int fib_lookup(struct net *net, const struct flowi4 *flp, tb = fib_get_table(net, RT_TABLE_MAIN); if (tb) - err = fib_table_lookup(net, tb, flp, res, - flags | FIB_LOOKUP_NOREF); + err = fib_table_lookup(tb, flp, res, flags | FIB_LOOKUP_NOREF); if (err == -EAGAIN) err = -ENETUNREACH; @@ -390,14 +388,14 @@ static inline int fib_lookup(struct net *net, struct flowi4 *flp, tb = rcu_dereference_rtnl(net->ipv4.fib_main); if (tb) - err = fib_table_lookup(net, tb, flp, res, flags); + err = fib_table_lookup(tb, flp, res, flags); if (err != -EAGAIN) goto out; tb = rcu_dereference_rtnl(net->ipv4.fib_default); if (tb) - err = fib_table_lookup(net, tb, flp, res, flags); + err = fib_table_lookup(tb, flp, res, flags); if (err == -EAGAIN) err = -ENETUNREACH; diff --git a/net/core/filter.c b/net/core/filter.c index 3ee1a093337e..70dc621672f2 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -6413,7 +6413,7 @@ static int bpf_ipv4_fib_lookup(struct net *net, struct bpf_fib_lookup *params, if (unlikely(!tb)) return BPF_FIB_LKUP_RET_NOT_FWDED; - err = fib_table_lookup(net, tb, &fl4, &res, FIB_LOOKUP_NOREF); + err = fib_table_lookup(tb, &fl4, &res, FIB_LOOKUP_NOREF); } else { if (flags & BPF_FIB_LOOKUP_MARK) fl4.flowi4_mark = params->mark; diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c index c106d56eb2f7..2ed4c706ca9e 100644 --- a/net/ipv4/devinet.c +++ b/net/ipv4/devinet.c @@ -157,8 +157,7 @@ struct net_device *__ip_dev_find(struct net *net, __be32 addr, bool devref) */ local = fib_get_table(net, RT_TABLE_LOCAL); if (local && - !fib_table_lookup(net, local, &fl4, &res, - FIB_LOOKUP_NOREF) && + !fib_table_lookup(local, &fl4, &res, FIB_LOOKUP_NOREF) && res.type == RTN_LOCAL) result = FIB_RES_DEV(res); } else { diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c index 97acfb35fb12..8c123b111b3d 100644 --- a/net/ipv4/fib_frontend.c +++ b/net/ipv4/fib_frontend.c @@ -243,8 +243,7 @@ static inline unsigned int __inet_dev_addr_type(struct net *net, table = fib_get_table(net, tb_id); if (table) { ret = RTN_UNICAST; - if (!fib_table_lookup(net, table, &fl4, &res, - FIB_LOOKUP_NOREF)) { + if (!fib_table_lookup(table, &fl4, &res, FIB_LOOKUP_NOREF)) { struct fib_nh_common *nhc = fib_info_nhc(res.fi, 0); if (!dev || dev == nhc->nhc_dev) @@ -1401,8 +1400,7 @@ static void nl_fib_lookup(struct net *net, struct fib_result_nl *frn) local_bh_disable(); frn->tb_id = tb->tb_id; - frn->err = fib_table_lookup(net, tb, &fl4, &res, - FIB_LOOKUP_NOREF); + frn->err = fib_table_lookup(tb, &fl4, &res, FIB_LOOKUP_NOREF); if (!frn->err) { frn->prefixlen = res.prefixlen; diff --git a/net/ipv4/fib_rules.c b/net/ipv4/fib_rules.c index 28ba35125383..060501b376a8 100644 --- a/net/ipv4/fib_rules.c +++ b/net/ipv4/fib_rules.c @@ -136,7 +136,7 @@ INDIRECT_CALLABLE_SCOPE int fib4_rule_action(struct fib_rule *rule, tb_id = fib_rule_get_table(rule, arg); tbl = fib_get_table(rule->fr_net, tb_id); if (tbl) - err = fib_table_lookup(rule->fr_net, tbl, &flp->u.ip4, + err = fib_table_lookup(tbl, &flp->u.ip4, (struct fib_result *)arg->result, arg->flags); diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c index 20da68240f61..db030bc26b6d 100644 --- a/net/ipv4/fib_semantics.c +++ b/net/ipv4/fib_semantics.c @@ -1224,7 +1224,7 @@ static int fib_check_nh_v4_gw(struct net *net, struct fib_nh *nh, u32 table, tbl = fib_get_table(net, table); if (tbl) - err = fib_table_lookup(net, tbl, &fl4, &res, + err = fib_table_lookup(tbl, &fl4, &res, FIB_LOOKUP_IGNORE_LINKSTATE | FIB_LOOKUP_NOREF); diff --git a/net/ipv4/fib_trie.c b/net/ipv4/fib_trie.c index 3bc8247b3d75..be1e40780ad7 100644 --- a/net/ipv4/fib_trie.c +++ b/net/ipv4/fib_trie.c @@ -1415,9 +1415,8 @@ bool fib_lookup_good_nhc(const struct fib_nh_common *nhc, int fib_flags, } /* should be called with rcu_read_lock */ -int fib_table_lookup(struct net *net, struct fib_table *tb, - const struct flowi4 *flp, struct fib_result *res, - int fib_flags) +int fib_table_lookup(struct fib_table *tb, const struct flowi4 *flp, + struct fib_result *res, int fib_flags) { struct trie *t = (struct trie *) tb->tb_data; #ifdef CONFIG_IP_FIB_TRIE_STATS @@ -1434,7 +1433,8 @@ int fib_table_lookup(struct net *net, struct fib_table *tb, n = get_child_rcu(pn, cindex); if (!n) { - trace_fib_table_lookup(tb->tb_id, flp, NULL, -EAGAIN, net); + trace_fib_table_lookup(tb->tb_id, flp, NULL, -EAGAIN, + tb->tb_net); return -EAGAIN; } @@ -1522,7 +1522,7 @@ int fib_table_lookup(struct net *net, struct fib_table *tb, if (IS_TRIE(pn)) { trace_fib_table_lookup(tb->tb_id, flp, NULL, -EAGAIN, - net); + tb->tb_net); return -EAGAIN; } #ifdef CONFIG_IP_FIB_TRIE_STATS @@ -1569,7 +1569,8 @@ int fib_table_lookup(struct net *net, struct fib_table *tb, #ifdef CONFIG_IP_FIB_TRIE_STATS this_cpu_inc(stats->semantic_match_passed); #endif - trace_fib_table_lookup(tb->tb_id, flp, NULL, err, net); + trace_fib_table_lookup(tb->tb_id, flp, NULL, err, + tb->tb_net); return err; } if (fi->fib_flags & RTNH_F_DEAD) @@ -1610,7 +1611,8 @@ int fib_table_lookup(struct net *net, struct fib_table *tb, #ifdef CONFIG_IP_FIB_TRIE_STATS this_cpu_inc(stats->semantic_match_passed); #endif - trace_fib_table_lookup(tb->tb_id, flp, nhc, err, net); + trace_fib_table_lookup(tb->tb_id, flp, nhc, err, + tb->tb_net); return err; }