ipv4: Remove netns argument from fib_table_lookup()
Subsystems (5)
Ido Schimmel
maintainercover ipv4: Remove netns argument from fib_table_lookup()
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. As noted by Paolo [1], the function is called in the data path where the additional argument is unnecessary overhead, as the namespace is only needed when the tracepoint is enabled.
This patchset stores the namespace in the FIB table instead and passes it from there to the tracepoint, so that the namespace is only read when the tracepoint is enabled. The tracepoint itself is unchanged.
Patch #1 stores the namespace in the FIB table.
Patch #2 passes the namespace from the FIB table to the tracepoint and reverts the signature of fib_table_lookup() and its callers to what they were before the above commit.
No functional changes intended.
[1] https://lore.kernel.org/netdev/[email protected]/
Ido Schimmel (2):
ipv4: Store netns in FIB table
ipv4: Do not pass netns to fib_table_lookup()
include/net/ip_fib.h | 16 ++++++++-------- net/core/filter.c | 2 +- net/ipv4/devinet.c | 3 +-- net/ipv4/fib_frontend.c | 12 +++++------- net/ipv4/fib_rules.c | 2 +- net/ipv4/fib_semantics.c | 2 +- net/ipv4/fib_trie.c | 22 +++++++++++++--------- 7 files changed, 30 insertions(+), 29 deletions(-)
Signature · 1 line
2.56.0
Ido Schimmel
maintainerPATCH 1/2 ipv4: Store netns in FIB table
The next patch will stop passing the network namespace to fib_table_lookup() and instead pass the namespace from the FIB table to the fib_table_lookup tracepoint. As a preparation, store the namespace in the FIB table when the table is created.
The FIB table structure grows from 48 bytes to 56 bytes and still fits in a single cache line.
No functional changes intended.
--- include/net/ip_fib.h | 4 +++- net/ipv4/fib_frontend.c | 6 +++--- net/ipv4/fib_trie.c | 6 ++++-- 3 files changed, 10 insertions(+), 6 deletions(-)
include/net/ip_fib.h +3 -1
@@ -258,6 +258,7 @@ struct fib_table {struct hlist_node tb_hlist;u32 tb_id;int tb_num_default; +struct net *tb_net;struct rcu_head rcu;unsigned long *tb_data;unsigned long __data[];
@@ -593,7 +594,8 @@ void fib_nh_common_release(struct fib_nh_common *nhc);/* Exported by fib_trie.c */ void fib_alias_hw_flags_set (struct net *net,const struct fib_rt_info *fri);void fib_trie_init (void ); -struct fib_table *fib_trie_table (u32 id,struct fib_table *alias); +struct fib_table *fib_trie_table (struct net *net,u32 id, +struct fib_table *alias);bool fib_lookup_good_nhc (const struct fib_nh_common *nhc,int fib_flags,const struct flowi4 *flp);
net/ipv4/fib_frontend.c +3 -3
@@ -54,11 +54,11 @@ static int __net_init fib4_rules_init(struct net *net) {struct fib_table *local_table, *main_table; - main_table =fib_trie_table (RT_TABLE_MAIN ,NULL ); + main_table =fib_trie_table (net,RT_TABLE_MAIN ,NULL );if (!main_table)return -ENOMEM ; - local_table =fib_trie_table (RT_TABLE_LOCAL , main_table); + local_table =fib_trie_table (net,RT_TABLE_LOCAL , main_table);if (!local_table) goto fail;
@@ -91,7 +91,7 @@ struct fib_table *fib_new_table(struct net *net, u32 id)if (id ==RT_TABLE_LOCAL && !net->ipv4.fib_has_custom_rules) alias =fib_new_table (net,RT_TABLE_MAIN ); - new_tb =fib_trie_table (id, alias); + new_tb =fib_trie_table (net, id, alias);if (!new_tb)return NULL ;
net/ipv4/fib_trie.c +4 -2
@@ -1881,7 +1881,7 @@ struct fib_table *fib_trie_unmerge(struct fib_table *oldtb)if (oldtb->tb_data == oldtb->__data)return oldtb; - local_tb =fib_trie_table (RT_TABLE_LOCAL ,NULL ); + local_tb =fib_trie_table (oldtb->tb_net,RT_TABLE_LOCAL ,NULL );if (!local_tb)return NULL ;
@@ -2378,7 +2378,8 @@ void __init fib_trie_init(void) 0, SLAB_PANIC | SLAB_ACCOUNT, NULL); } -struct fib_table *fib_trie_table (u32 id,struct fib_table *alias) +struct fib_table *fib_trie_table (struct net *net,u32 id, +struct fib_table *alias) {struct fib_table *tb;struct trie *t;
@@ -2391,6 +2392,7 @@ struct fib_table *fib_trie_table(u32 id, struct fib_table *alias)if (!tb)return NULL ; + tb->tb_net = net; tb->tb_id = id; tb->tb_num_default =0 ; tb->tb_data = (alias ? alias->__data : tb->__data);
Signature · 1 line
2.56.0
Re: [PATCH net-next 1/2] ipv4: Store netns in FIB table
Quoted 10 lines · Ido Schimmel
The next patch will stop passing the network namespace to
fib_table_lookup()and instead pass the namespace from the FIB table to thefib_table_lookuptracepoint. As a preparation, store the namespace in the FIB table when the table is created.The FIB table structure grows from 48 bytes to 56 bytes and still fits in a single cache line.
No functional changes intended.
Quoted 8 lines
Assisted-by LLMSigned-off-by Ido Schimmel <[email protected]>--- include/net/ip_fib.h | 4 +++- net/ipv4/fib_frontend.c | 6 +++--- net/ipv4/fib_trie.c | 6 ++++-- 3 files changed, 10 insertions(+), 6 deletions(-)
Ido Schimmel
maintainerPATCH 2/2 ipv4: Do not pass netns to fib_table_lookup()
In reply to Ido SchimmelCommit 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.
--- 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(-)
include/net/ip_fib.h +5 -7
@@ -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 ;
net/core/filter.c +1 -1
@@ -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;
net/ipv4/devinet.c +1 -2
@@ -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 {
net/ipv4/fib_frontend.c +2 -4
@@ -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;
net/ipv4/fib_rules.c +1 -1
@@ -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);
net/ipv4/fib_semantics.c +1 -1
@@ -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 );
net/ipv4/fib_trie.c +9 -7
@@ -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; }
Signature · 1 line
2.56.0
Re: [PATCH net-next 2/2] ipv4: Do not pass netns to fib_table_lookup()
Quoted 19 lines · Ido Schimmel
Commit
c436a624f89e("ipv4: Pass netns tofib_table_lookup()") added the network namespace as an argument offib_table_lookup()so that it could be passed to thefib_table_lookuptracepoint. 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 <[email protected]>Assisted-by LLMSigned-off-by Ido Schimmel <[email protected]>
Quoted 10 lines
--- 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(-)
Quoted 17 lines · Ido Schimmel
Commit
c436a624f89e("ipv4: Pass netns tofib_table_lookup()") added the network namespace as an argument offib_table_lookup()so that it could be passed to thefib_table_lookuptracepoint. As noted by Paolo [1], the function is called in the data path where the additional argument is unnecessary overhead, as the namespace is only needed when the tracepoint is enabled.This patchset stores the namespace in the FIB table instead and passes it from there to the tracepoint, so that the namespace is only read when the tracepoint is enabled. The tracepoint itself is unchanged.
Patch #1 stores the namespace in the FIB table.
Patch #2 passes the namespace from the FIB table to the tracepoint and reverts the signature of
fib_table_lookup()and its callers to what they were before the above commit.
Quoted 7 lines
No functional changes intended.
[1] https://lore.kernel.org/netdev/[email protected]/
Ido Schimmel (2):
ipv4: Store netns in FIB table
ipv4: Do not pass netns tofib_table_lookup()
For the series:
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 8 lines · On Wed, 14 Oct 2026 11:26:10 +0300 you wrote:
Commit
c436a624f89e("ipv4: Pass netns tofib_table_lookup()") added the network namespace as an argument offib_table_lookup()so that it could be passed to thefib_table_lookuptracepoint. As noted by Paolo [1], the function is called in the data path where the additional argument is unnecessary overhead, as the namespace is only needed when the tracepoint is enabled.[...]
Here is the summary with links:
- [net-next,1/2] ipv4: Store netns in FIB table
https://git.kernel.org/netdev/net-next/c/1b82d5ce3ba9 - [net-next,2/2] ipv4: Do not pass netns to fib_table_lookup() https://git.kernel.org/netdev/net-next/c/a25a51258acf
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html