Commit 8ad4942c authored by Denis V. Lunev's avatar Denis V. Lunev Committed by David S. Miller

[NETNS]: Add netns parameter to fib_get_table/fib_new_table.

This patch extends the fib_get_table and the fib_new_table functions
with the network namespace pointer. That will allow to access the
table relatively from the network namespace.
Acked-by: default avatarBenjamin Thery <benjamin.thery@bull.net>
Acked-by: default avatarDaniel Lezcano <dlezcano@fr.ibm.com>
Signed-off-by: default avatarDenis V. Lunev <den@openvz.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 93456b6d
...@@ -165,7 +165,7 @@ struct fib_table { ...@@ -165,7 +165,7 @@ struct fib_table {
#define TABLE_LOCAL_INDEX 0 #define TABLE_LOCAL_INDEX 0
#define TABLE_MAIN_INDEX 1 #define TABLE_MAIN_INDEX 1
static inline struct fib_table *fib_get_table(u32 id) static inline struct fib_table *fib_get_table(struct net *net, u32 id)
{ {
struct hlist_head *ptr; struct hlist_head *ptr;
...@@ -175,20 +175,20 @@ static inline struct fib_table *fib_get_table(u32 id) ...@@ -175,20 +175,20 @@ static inline struct fib_table *fib_get_table(u32 id)
return hlist_entry(ptr->first, struct fib_table, tb_hlist); return hlist_entry(ptr->first, struct fib_table, tb_hlist);
} }
static inline struct fib_table *fib_new_table(u32 id) static inline struct fib_table *fib_new_table(struct net *net, u32 id)
{ {
return fib_get_table(id); return fib_get_table(net, id);
} }
static inline int fib_lookup(const struct flowi *flp, struct fib_result *res) static inline int fib_lookup(const struct flowi *flp, struct fib_result *res)
{ {
struct fib_table *table; struct fib_table *table;
table = fib_get_table(RT_TABLE_LOCAL); table = fib_get_table(&init_net, RT_TABLE_LOCAL);
if (!table->tb_lookup(table, flp, res)) if (!table->tb_lookup(table, flp, res))
return 0; return 0;
table = fib_get_table(RT_TABLE_MAIN); table = fib_get_table(&init_net, RT_TABLE_MAIN);
if (!table->tb_lookup(table, flp, res)) if (!table->tb_lookup(table, flp, res))
return 0; return 0;
return -ENETUNREACH; return -ENETUNREACH;
...@@ -197,7 +197,7 @@ static inline int fib_lookup(const struct flowi *flp, struct fib_result *res) ...@@ -197,7 +197,7 @@ static inline int fib_lookup(const struct flowi *flp, struct fib_result *res)
static inline void fib_select_default(const struct flowi *flp, static inline void fib_select_default(const struct flowi *flp,
struct fib_result *res) struct fib_result *res)
{ {
struct fib_table *table = fib_get_table(RT_TABLE_MAIN); struct fib_table *table = fib_get_table(&init_net, RT_TABLE_MAIN);
if (FIB_RES_GW(*res) && FIB_RES_NH(*res).nh_scope == RT_SCOPE_LINK) if (FIB_RES_GW(*res) && FIB_RES_NH(*res).nh_scope == RT_SCOPE_LINK)
table->tb_select_default(table, flp, res); table->tb_select_default(table, flp, res);
} }
...@@ -212,8 +212,8 @@ extern u32 fib_rules_tclass(struct fib_result *res); ...@@ -212,8 +212,8 @@ extern u32 fib_rules_tclass(struct fib_result *res);
extern int fib_lookup(struct flowi *flp, struct fib_result *res); extern int fib_lookup(struct flowi *flp, struct fib_result *res);
extern struct fib_table *fib_new_table(u32 id); extern struct fib_table *fib_new_table(struct net *net, u32 id);
extern struct fib_table *fib_get_table(u32 id); extern struct fib_table *fib_get_table(struct net *net, u32 id);
extern void fib_select_default(const struct flowi *flp, struct fib_result *res); extern void fib_select_default(const struct flowi *flp, struct fib_result *res);
#endif /* CONFIG_IP_MULTIPLE_TABLES */ #endif /* CONFIG_IP_MULTIPLE_TABLES */
......
...@@ -78,14 +78,14 @@ static int __net_init fib4_rules_init(struct net *net) ...@@ -78,14 +78,14 @@ static int __net_init fib4_rules_init(struct net *net)
} }
#else #else
struct fib_table *fib_new_table(u32 id) struct fib_table *fib_new_table(struct net *net, u32 id)
{ {
struct fib_table *tb; struct fib_table *tb;
unsigned int h; unsigned int h;
if (id == 0) if (id == 0)
id = RT_TABLE_MAIN; id = RT_TABLE_MAIN;
tb = fib_get_table(id); tb = fib_get_table(net, id);
if (tb) if (tb)
return tb; return tb;
tb = fib_hash_init(id); tb = fib_hash_init(id);
...@@ -96,7 +96,7 @@ struct fib_table *fib_new_table(u32 id) ...@@ -96,7 +96,7 @@ struct fib_table *fib_new_table(u32 id)
return tb; return tb;
} }
struct fib_table *fib_get_table(u32 id) struct fib_table *fib_get_table(struct net *net, u32 id)
{ {
struct fib_table *tb; struct fib_table *tb;
struct hlist_node *node; struct hlist_node *node;
...@@ -148,7 +148,7 @@ struct net_device * ip_dev_find(__be32 addr) ...@@ -148,7 +148,7 @@ struct net_device * ip_dev_find(__be32 addr)
res.r = NULL; res.r = NULL;
#endif #endif
local_table = fib_get_table(RT_TABLE_LOCAL); local_table = fib_get_table(&init_net, RT_TABLE_LOCAL);
if (!local_table || local_table->tb_lookup(local_table, &fl, &res)) if (!local_table || local_table->tb_lookup(local_table, &fl, &res))
return NULL; return NULL;
if (res.type != RTN_LOCAL) if (res.type != RTN_LOCAL)
...@@ -183,7 +183,7 @@ static inline unsigned __inet_dev_addr_type(const struct net_device *dev, ...@@ -183,7 +183,7 @@ static inline unsigned __inet_dev_addr_type(const struct net_device *dev,
res.r = NULL; res.r = NULL;
#endif #endif
local_table = fib_get_table(RT_TABLE_LOCAL); local_table = fib_get_table(&init_net, RT_TABLE_LOCAL);
if (local_table) { if (local_table) {
ret = RTN_UNICAST; ret = RTN_UNICAST;
if (!local_table->tb_lookup(local_table, &fl, &res)) { if (!local_table->tb_lookup(local_table, &fl, &res)) {
...@@ -453,13 +453,13 @@ int ip_rt_ioctl(unsigned int cmd, void __user *arg) ...@@ -453,13 +453,13 @@ int ip_rt_ioctl(unsigned int cmd, void __user *arg)
struct fib_table *tb; struct fib_table *tb;
if (cmd == SIOCDELRT) { if (cmd == SIOCDELRT) {
tb = fib_get_table(cfg.fc_table); tb = fib_get_table(&init_net, cfg.fc_table);
if (tb) if (tb)
err = tb->tb_delete(tb, &cfg); err = tb->tb_delete(tb, &cfg);
else else
err = -ESRCH; err = -ESRCH;
} else { } else {
tb = fib_new_table(cfg.fc_table); tb = fib_new_table(&init_net, cfg.fc_table);
if (tb) if (tb)
err = tb->tb_insert(tb, &cfg); err = tb->tb_insert(tb, &cfg);
else else
...@@ -573,7 +573,7 @@ static int inet_rtm_delroute(struct sk_buff *skb, struct nlmsghdr* nlh, void *ar ...@@ -573,7 +573,7 @@ static int inet_rtm_delroute(struct sk_buff *skb, struct nlmsghdr* nlh, void *ar
if (err < 0) if (err < 0)
goto errout; goto errout;
tb = fib_get_table(cfg.fc_table); tb = fib_get_table(net, cfg.fc_table);
if (tb == NULL) { if (tb == NULL) {
err = -ESRCH; err = -ESRCH;
goto errout; goto errout;
...@@ -598,7 +598,7 @@ static int inet_rtm_newroute(struct sk_buff *skb, struct nlmsghdr* nlh, void *ar ...@@ -598,7 +598,7 @@ static int inet_rtm_newroute(struct sk_buff *skb, struct nlmsghdr* nlh, void *ar
if (err < 0) if (err < 0)
goto errout; goto errout;
tb = fib_new_table(cfg.fc_table); tb = fib_new_table(&init_net, cfg.fc_table);
if (tb == NULL) { if (tb == NULL) {
err = -ENOBUFS; err = -ENOBUFS;
goto errout; goto errout;
...@@ -671,9 +671,9 @@ static void fib_magic(int cmd, int type, __be32 dst, int dst_len, struct in_ifad ...@@ -671,9 +671,9 @@ static void fib_magic(int cmd, int type, __be32 dst, int dst_len, struct in_ifad
}; };
if (type == RTN_UNICAST) if (type == RTN_UNICAST)
tb = fib_new_table(RT_TABLE_MAIN); tb = fib_new_table(&init_net, RT_TABLE_MAIN);
else else
tb = fib_new_table(RT_TABLE_LOCAL); tb = fib_new_table(&init_net, RT_TABLE_LOCAL);
if (tb == NULL) if (tb == NULL)
return; return;
...@@ -848,7 +848,7 @@ static void nl_fib_input(struct sk_buff *skb) ...@@ -848,7 +848,7 @@ static void nl_fib_input(struct sk_buff *skb)
nlh = nlmsg_hdr(skb); nlh = nlmsg_hdr(skb);
frn = (struct fib_result_nl *) NLMSG_DATA(nlh); frn = (struct fib_result_nl *) NLMSG_DATA(nlh);
tb = fib_get_table(frn->tb_id_in); tb = fib_get_table(&init_net, frn->tb_id_in);
nl_fib_lookup(frn, tb); nl_fib_lookup(frn, tb);
......
...@@ -796,7 +796,7 @@ struct fib_iter_state { ...@@ -796,7 +796,7 @@ struct fib_iter_state {
static struct fib_alias *fib_get_first(struct seq_file *seq) static struct fib_alias *fib_get_first(struct seq_file *seq)
{ {
struct fib_iter_state *iter = seq->private; struct fib_iter_state *iter = seq->private;
struct fib_table *main_table = fib_get_table(RT_TABLE_MAIN); struct fib_table *main_table = fib_get_table(&init_net, RT_TABLE_MAIN);
struct fn_hash *table = (struct fn_hash *)main_table->tb_data; struct fn_hash *table = (struct fn_hash *)main_table->tb_data;
iter->bucket = 0; iter->bucket = 0;
...@@ -937,7 +937,7 @@ static void *fib_seq_start(struct seq_file *seq, loff_t *pos) ...@@ -937,7 +937,7 @@ static void *fib_seq_start(struct seq_file *seq, loff_t *pos)
void *v = NULL; void *v = NULL;
read_lock(&fib_hash_lock); read_lock(&fib_hash_lock);
if (fib_get_table(RT_TABLE_MAIN)) if (fib_get_table(&init_net, RT_TABLE_MAIN))
v = *pos ? fib_get_idx(seq, *pos - 1) : SEQ_START_TOKEN; v = *pos ? fib_get_idx(seq, *pos - 1) : SEQ_START_TOKEN;
return v; return v;
} }
......
...@@ -93,7 +93,7 @@ static int fib4_rule_action(struct fib_rule *rule, struct flowi *flp, ...@@ -93,7 +93,7 @@ static int fib4_rule_action(struct fib_rule *rule, struct flowi *flp,
goto errout; goto errout;
} }
if ((tbl = fib_get_table(rule->table)) == NULL) if ((tbl = fib_get_table(&init_net, rule->table)) == NULL)
goto errout; goto errout;
err = tbl->tb_lookup(tbl, flp, (struct fib_result *) arg->result); err = tbl->tb_lookup(tbl, flp, (struct fib_result *) arg->result);
...@@ -109,7 +109,7 @@ void fib_select_default(const struct flowi *flp, struct fib_result *res) ...@@ -109,7 +109,7 @@ void fib_select_default(const struct flowi *flp, struct fib_result *res)
if (res->r && res->r->action == FR_ACT_TO_TBL && if (res->r && res->r->action == FR_ACT_TO_TBL &&
FIB_RES_GW(*res) && FIB_RES_NH(*res).nh_scope == RT_SCOPE_LINK) { FIB_RES_GW(*res) && FIB_RES_NH(*res).nh_scope == RT_SCOPE_LINK) {
struct fib_table *tb; struct fib_table *tb;
if ((tb = fib_get_table(res->r->table)) != NULL) if ((tb = fib_get_table(&init_net, res->r->table)) != NULL)
tb->tb_select_default(tb, flp, res); tb->tb_select_default(tb, flp, res);
} }
} }
...@@ -130,13 +130,13 @@ static int fib4_rule_match(struct fib_rule *rule, struct flowi *fl, int flags) ...@@ -130,13 +130,13 @@ static int fib4_rule_match(struct fib_rule *rule, struct flowi *fl, int flags)
return 1; return 1;
} }
static struct fib_table *fib_empty_table(void) static struct fib_table *fib_empty_table(struct net *net)
{ {
u32 id; u32 id;
for (id = 1; id <= RT_TABLE_MAX; id++) for (id = 1; id <= RT_TABLE_MAX; id++)
if (fib_get_table(id) == NULL) if (fib_get_table(net, id) == NULL)
return fib_new_table(id); return fib_new_table(net, id);
return NULL; return NULL;
} }
...@@ -159,7 +159,7 @@ static int fib4_rule_configure(struct fib_rule *rule, struct sk_buff *skb, ...@@ -159,7 +159,7 @@ static int fib4_rule_configure(struct fib_rule *rule, struct sk_buff *skb,
if (rule->action == FR_ACT_TO_TBL) { if (rule->action == FR_ACT_TO_TBL) {
struct fib_table *table; struct fib_table *table;
table = fib_empty_table(); table = fib_empty_table(&init_net);
if (table == NULL) { if (table == NULL) {
err = -ENOBUFS; err = -ENOBUFS;
goto errout; goto errout;
......
...@@ -2167,12 +2167,12 @@ static int fib_triestat_seq_show(struct seq_file *seq, void *v) ...@@ -2167,12 +2167,12 @@ static int fib_triestat_seq_show(struct seq_file *seq, void *v)
struct fib_table *tb; struct fib_table *tb;
trie_local = NULL; trie_local = NULL;
tb = fib_get_table(RT_TABLE_LOCAL); tb = fib_get_table(&init_net, RT_TABLE_LOCAL);
if (tb) if (tb)
trie_local = (struct trie *) tb->tb_data; trie_local = (struct trie *) tb->tb_data;
trie_main = NULL; trie_main = NULL;
tb = fib_get_table(RT_TABLE_MAIN); tb = fib_get_table(&init_net, RT_TABLE_MAIN);
if (tb) if (tb)
trie_main = (struct trie *) tb->tb_data; trie_main = (struct trie *) tb->tb_data;
...@@ -2239,12 +2239,12 @@ static void *fib_trie_seq_start(struct seq_file *seq, loff_t *pos) ...@@ -2239,12 +2239,12 @@ static void *fib_trie_seq_start(struct seq_file *seq, loff_t *pos)
struct fib_table *tb; struct fib_table *tb;
if (!iter->trie_local) { if (!iter->trie_local) {
tb = fib_get_table(RT_TABLE_LOCAL); tb = fib_get_table(&init_net, RT_TABLE_LOCAL);
if (tb) if (tb)
iter->trie_local = (struct trie *) tb->tb_data; iter->trie_local = (struct trie *) tb->tb_data;
} }
if (!iter->trie_main) { if (!iter->trie_main) {
tb = fib_get_table(RT_TABLE_MAIN); tb = fib_get_table(&init_net, RT_TABLE_MAIN);
if (tb) if (tb)
iter->trie_main = (struct trie *) tb->tb_data; iter->trie_main = (struct trie *) tb->tb_data;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment