* [PATCH] net: fib: fix fib_new_table() logical issue
@ 2017-06-21 14:02 yuan linyu
2017-06-21 22:53 ` Cong Wang
0 siblings, 1 reply; 3+ messages in thread
From: yuan linyu @ 2017-06-21 14:02 UTC (permalink / raw)
To: netdev; +Cc: David S . Miller, yuan linyu
From: yuan linyu <Linyu.Yuan@alcatel-sbell.com.cn>
when CONFIG_IP_MULTIPLE_TABLES defined,
if id == RT_TABLE_LOCAL and !net->ipv4.fib_has_custom_rules,
fib_new_table() call itself to get RT_TABLE_MAIN table,
but if RT_TABLE_MAIN table not exist at this point,
this function will become deadloop.
the solution is move RT_TABLE_MAIN table create to per-net init.
and call fib_get_table() to get RT_TABLE_MAIN table.
Signed-off-by: yuan linyu <Linyu.Yuan@alcatel-sbell.com.cn>
---
net/ipv4/fib_frontend.c | 12 ++----------
net/ipv4/fib_rules.c | 11 +++++++++++
2 files changed, 13 insertions(+), 10 deletions(-)
diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
index 4e678fa..4606b4a 100644
--- a/net/ipv4/fib_frontend.c
+++ b/net/ipv4/fib_frontend.c
@@ -87,22 +87,14 @@ struct fib_table *fib_new_table(struct net *net, u32 id)
return tb;
if (id == RT_TABLE_LOCAL && !net->ipv4.fib_has_custom_rules)
- alias = fib_new_table(net, RT_TABLE_MAIN);
+ alias = fib_get_table(net, RT_TABLE_MAIN);
tb = fib_trie_table(id, alias);
if (!tb)
return NULL;
- switch (id) {
- case RT_TABLE_MAIN:
- rcu_assign_pointer(net->ipv4.fib_main, tb);
- break;
- case RT_TABLE_DEFAULT:
+ if (id == RT_TABLE_DEFAULT)
rcu_assign_pointer(net->ipv4.fib_default, tb);
- break;
- default:
- break;
- }
h = id & (FIB_TABLE_HASHSZ - 1);
hlist_add_head_rcu(&tb->tb_hlist, &net->ipv4.fib_table_hash[h]);
diff --git a/net/ipv4/fib_rules.c b/net/ipv4/fib_rules.c
index 778ecf9..a9796ac 100644
--- a/net/ipv4/fib_rules.c
+++ b/net/ipv4/fib_rules.c
@@ -402,8 +402,14 @@ static int fib_default_rules_init(struct fib_rules_ops *ops)
int __net_init fib4_rules_init(struct net *net)
{
int err;
+ unsigned int h;
+ struct fib_table *main_table;
struct fib_rules_ops *ops;
+ main_table = fib_trie_table(RT_TABLE_MAIN, NULL);
+ if (!main_table)
+ return -ENOMEM;
+
ops = fib_rules_register(&fib4_rules_ops_template, net);
if (IS_ERR(ops))
return PTR_ERR(ops);
@@ -413,11 +419,16 @@ int __net_init fib4_rules_init(struct net *net)
goto fail;
net->ipv4.rules_ops = ops;
net->ipv4.fib_has_custom_rules = false;
+
+ rcu_assign_pointer(net->ipv4.fib_main, main_table);
+ h = RT_TABLE_MAIN & (FIB_TABLE_HASHSZ - 1);
+ hlist_add_head_rcu(&main_table->tb_hlist, &net->ipv4.fib_table_hash[h]);
return 0;
fail:
/* also cleans all rules already added */
fib_rules_unregister(ops);
+ fib_free_table(main_table);
return err;
}
--
2.7.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] net: fib: fix fib_new_table() logical issue
2017-06-21 14:02 [PATCH] net: fib: fix fib_new_table() logical issue yuan linyu
@ 2017-06-21 22:53 ` Cong Wang
2017-06-21 23:48 ` YUAN Linyu
0 siblings, 1 reply; 3+ messages in thread
From: Cong Wang @ 2017-06-21 22:53 UTC (permalink / raw)
To: yuan linyu; +Cc: Linux Kernel Network Developers, David S . Miller, yuan linyu
On Wed, Jun 21, 2017 at 7:02 AM, yuan linyu <cugyly@163.com> wrote:
> From: yuan linyu <Linyu.Yuan@alcatel-sbell.com.cn>
>
> when CONFIG_IP_MULTIPLE_TABLES defined,
> if id == RT_TABLE_LOCAL and !net->ipv4.fib_has_custom_rules,
> fib_new_table() call itself to get RT_TABLE_MAIN table,
> but if RT_TABLE_MAIN table not exist at this point,
> this function will become deadloop.
Why deadloop here? If fib_new_table() is called recursively,
then main table is created by fib_trie_table() and we return.
^ permalink raw reply [flat|nested] 3+ messages in thread
* RE: [PATCH] net: fib: fix fib_new_table() logical issue
2017-06-21 22:53 ` Cong Wang
@ 2017-06-21 23:48 ` YUAN Linyu
0 siblings, 0 replies; 3+ messages in thread
From: YUAN Linyu @ 2017-06-21 23:48 UTC (permalink / raw)
To: Cong Wang, yuan linyu; +Cc: Linux Kernel Network Developers, David S . Miller
Sorry, it's not dead loop, I realized it but I tried to send to mail to note it on my phone, it failed.
> -----Original Message-----
> From: Cong Wang [mailto:xiyou.wangcong@gmail.com]
> Sent: Thursday, June 22, 2017 6:54 AM
> To: yuan linyu
> Cc: Linux Kernel Network Developers; David S . Miller; YUAN Linyu
> Subject: Re: [PATCH] net: fib: fix fib_new_table() logical issue
>
> On Wed, Jun 21, 2017 at 7:02 AM, yuan linyu <cugyly@163.com> wrote:
> > From: yuan linyu <Linyu.Yuan@alcatel-sbell.com.cn>
> >
> > when CONFIG_IP_MULTIPLE_TABLES defined,
> > if id == RT_TABLE_LOCAL and !net->ipv4.fib_has_custom_rules,
> > fib_new_table() call itself to get RT_TABLE_MAIN table,
> > but if RT_TABLE_MAIN table not exist at this point,
> > this function will become deadloop.
>
> Why deadloop here? If fib_new_table() is called recursively,
> then main table is created by fib_trie_table() and we return.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-06-21 23:48 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-21 14:02 [PATCH] net: fib: fix fib_new_table() logical issue yuan linyu
2017-06-21 22:53 ` Cong Wang
2017-06-21 23:48 ` YUAN Linyu
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.