Thread (6 messages) 6 messages, 3 authors, 12h ago

[PATCH net-next 1/2] ipv4: Store netns in FIB table

flat view
HOTtoday

From: Ido Schimmel <idosch@nvidia.com>
Date: 2026-10-14 08:27:58
Subsystem: networking [general], networking [ipv4/ipv6], the rest · Maintainers: "David S. Miller", Eric Dumazet, Jakub Kicinski, Paolo Abeni, David Ahern, Ido Schimmel, Linus Torvalds

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.

Assisted-by: LLM
Signed-off-by: Ido Schimmel <idosch@nvidia.com>
---
 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(-)
diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
index fb446f01a65d..033ed8fce35e 100644
--- a/include/net/ip_fib.h
+++ b/include/net/ip_fib.h
@@ -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);
 
diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
index c80c1b36f1fd..97acfb35fb12 100644
--- a/net/ipv4/fib_frontend.c
+++ b/net/ipv4/fib_frontend.c
@@ -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;
 
diff --git a/net/ipv4/fib_trie.c b/net/ipv4/fib_trie.c
index 4a800fdf1ad1..3bc8247b3d75 100644
--- a/net/ipv4/fib_trie.c
+++ b/net/ipv4/fib_trie.c
@@ -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);
-- 
2.56.0
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help