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.

Signed-off-by: Ido Schimmel <idosch@nvidia.com>
Tested-by: Björn Töpel <bjorn@kernel.org>
Reviewed-by: Björn Töpel <bjorn@kernel.org>
Reviewed-by: David Ahern <dsahern@kernel.org>
Link: https://patch.msgid.link/20261014082612.1280756-2-idosch@nvidia.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
Ido Schimmel 2026-10-14 11:26:11 +03:00 committed by Jakub Kicinski
parent 8b0244ca4f
commit 1b82d5ce3b
3 changed files with 10 additions and 6 deletions

View File

@ -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);

View File

@ -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;

View File

@ -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);