aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenis V. Lunev <den@openvz.org>2008-01-10 06:24:11 -0500
committerDavid S. Miller <davem@davemloft.net>2008-01-28 18:01:27 -0500
commit8ad4942cd5bdad4143f7aa1d1bd4f7b2526c19c5 (patch)
tree9fc1c79ae579e20063d577912ad4aeb1aef3ba6d
parent93456b6d7753def8760b423ac6b986eb9d5a4a95 (diff)
[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: Benjamin Thery <benjamin.thery@bull.net> Acked-by: Daniel Lezcano <dlezcano@fr.ibm.com> Signed-off-by: Denis V. Lunev <den@openvz.org> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--include/net/ip_fib.h16
-rw-r--r--net/ipv4/fib_frontend.c24
-rw-r--r--net/ipv4/fib_hash.c4
-rw-r--r--net/ipv4/fib_rules.c12
-rw-r--r--net/ipv4/fib_trie.c8
5 files changed, 32 insertions, 32 deletions
diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
index 249af662e897..dfb95d732aa5 100644
--- a/include/net/ip_fib.h
+++ b/include/net/ip_fib.h
@@ -165,7 +165,7 @@ struct fib_table {
165#define TABLE_LOCAL_INDEX 0 165#define TABLE_LOCAL_INDEX 0
166#define TABLE_MAIN_INDEX 1 166#define TABLE_MAIN_INDEX 1
167 167
168static inline struct fib_table *fib_get_table(u32 id) 168static inline struct fib_table *fib_get_table(struct net *net, u32 id)
169{ 169{
170 struct hlist_head *ptr; 170 struct hlist_head *ptr;
171 171
@@ -175,20 +175,20 @@ static inline struct fib_table *fib_get_table(u32 id)
175 return hlist_entry(ptr->first, struct fib_table, tb_hlist); 175 return hlist_entry(ptr->first, struct fib_table, tb_hlist);
176} 176}
177 177
178static inline struct fib_table *fib_new_table(u32 id) 178static inline struct fib_table *fib_new_table(struct net *net, u32 id)
179{ 179{
180 return fib_get_table(id); 180 return fib_get_table(net, id);
181} 181}
182 182
183static inline int fib_lookup(const struct flowi *flp, struct fib_result *res) 183static inline int fib_lookup(const struct flowi *flp, struct fib_result *res)
184{ 184{
185 struct fib_table *table; 185 struct fib_table *table;
186 186
187 table = fib_get_table(RT_TABLE_LOCAL); 187 table = fib_get_table(&init_net, RT_TABLE_LOCAL);
188 if (!table->tb_lookup(table, flp, res)) 188 if (!table->tb_lookup(table, flp, res))
189 return 0; 189 return 0;
190 190
191 table = fib_get_table(RT_TABLE_MAIN); 191 table = fib_get_table(&init_net, RT_TABLE_MAIN);
192 if (!table->tb_lookup(table, flp, res)) 192 if (!table->tb_lookup(table, flp, res))
193 return 0; 193 return 0;
194 return -ENETUNREACH; 194 return -ENETUNREACH;
@@ -197,7 +197,7 @@ static inline int fib_lookup(const struct flowi *flp, struct fib_result *res)
197static inline void fib_select_default(const struct flowi *flp, 197static inline void fib_select_default(const struct flowi *flp,
198 struct fib_result *res) 198 struct fib_result *res)
199{ 199{
200 struct fib_table *table = fib_get_table(RT_TABLE_MAIN); 200 struct fib_table *table = fib_get_table(&init_net, RT_TABLE_MAIN);
201 if (FIB_RES_GW(*res) && FIB_RES_NH(*res).nh_scope == RT_SCOPE_LINK) 201 if (FIB_RES_GW(*res) && FIB_RES_NH(*res).nh_scope == RT_SCOPE_LINK)
202 table->tb_select_default(table, flp, res); 202 table->tb_select_default(table, flp, res);
203} 203}
@@ -212,8 +212,8 @@ extern u32 fib_rules_tclass(struct fib_result *res);
212 212
213extern int fib_lookup(struct flowi *flp, struct fib_result *res); 213extern int fib_lookup(struct flowi *flp, struct fib_result *res);
214 214
215extern struct fib_table *fib_new_table(u32 id); 215extern struct fib_table *fib_new_table(struct net *net, u32 id);
216extern struct fib_table *fib_get_table(u32 id); 216extern struct fib_table *fib_get_table(struct net *net, u32 id);
217extern void fib_select_default(const struct flowi *flp, struct fib_result *res); 217extern void fib_select_default(const struct flowi *flp, struct fib_result *res);
218 218
219#endif /* CONFIG_IP_MULTIPLE_TABLES */ 219#endif /* CONFIG_IP_MULTIPLE_TABLES */
diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
index 9ff1e6669ef2..7718823711e3 100644
--- a/net/ipv4/fib_frontend.c
+++ b/net/ipv4/fib_frontend.c
@@ -78,14 +78,14 @@ fail:
78} 78}
79#else 79#else
80 80
81struct fib_table *fib_new_table(u32 id) 81struct fib_table *fib_new_table(struct net *net, u32 id)
82{ 82{
83 struct fib_table *tb; 83 struct fib_table *tb;
84 unsigned int h; 84 unsigned int h;
85 85
86 if (id == 0) 86 if (id == 0)
87 id = RT_TABLE_MAIN; 87 id = RT_TABLE_MAIN;
88 tb = fib_get_table(id); 88 tb = fib_get_table(net, id);
89 if (tb) 89 if (tb)
90 return tb; 90 return tb;
91 tb = fib_hash_init(id); 91 tb = fib_hash_init(id);
@@ -96,7 +96,7 @@ struct fib_table *fib_new_table(u32 id)
96 return tb; 96 return tb;
97} 97}
98 98
99struct fib_table *fib_get_table(u32 id) 99struct fib_table *fib_get_table(struct net *net, u32 id)
100{ 100{
101 struct fib_table *tb; 101 struct fib_table *tb;
102 struct hlist_node *node; 102 struct hlist_node *node;
@@ -148,7 +148,7 @@ struct net_device * ip_dev_find(__be32 addr)
148 res.r = NULL; 148 res.r = NULL;
149#endif 149#endif
150 150
151 local_table = fib_get_table(RT_TABLE_LOCAL); 151 local_table = fib_get_table(&init_net, RT_TABLE_LOCAL);
152 if (!local_table || local_table->tb_lookup(local_table, &fl, &res)) 152 if (!local_table || local_table->tb_lookup(local_table, &fl, &res))
153 return NULL; 153 return NULL;
154 if (res.type != RTN_LOCAL) 154 if (res.type != RTN_LOCAL)
@@ -183,7 +183,7 @@ static inline unsigned __inet_dev_addr_type(const struct net_device *dev,
183 res.r = NULL; 183 res.r = NULL;
184#endif 184#endif
185 185
186 local_table = fib_get_table(RT_TABLE_LOCAL); 186 local_table = fib_get_table(&init_net, RT_TABLE_LOCAL);
187 if (local_table) { 187 if (local_table) {
188 ret = RTN_UNICAST; 188 ret = RTN_UNICAST;
189 if (!local_table->tb_lookup(local_table, &fl, &res)) { 189 if (!local_table->tb_lookup(local_table, &fl, &res)) {
@@ -453,13 +453,13 @@ int ip_rt_ioctl(unsigned int cmd, void __user *arg)
453 struct fib_table *tb; 453 struct fib_table *tb;
454 454
455 if (cmd == SIOCDELRT) { 455 if (cmd == SIOCDELRT) {
456 tb = fib_get_table(cfg.fc_table); 456 tb = fib_get_table(&init_net, cfg.fc_table);
457 if (tb) 457 if (tb)
458 err = tb->tb_delete(tb, &cfg); 458 err = tb->tb_delete(tb, &cfg);
459 else 459 else
460 err = -ESRCH; 460 err = -ESRCH;
461 } else { 461 } else {
462 tb = fib_new_table(cfg.fc_table); 462 tb = fib_new_table(&init_net, cfg.fc_table);
463 if (tb) 463 if (tb)
464 err = tb->tb_insert(tb, &cfg); 464 err = tb->tb_insert(tb, &cfg);
465 else 465 else
@@ -573,7 +573,7 @@ static int inet_rtm_delroute(struct sk_buff *skb, struct nlmsghdr* nlh, void *ar
573 if (err < 0) 573 if (err < 0)
574 goto errout; 574 goto errout;
575 575
576 tb = fib_get_table(cfg.fc_table); 576 tb = fib_get_table(net, cfg.fc_table);
577 if (tb == NULL) { 577 if (tb == NULL) {
578 err = -ESRCH; 578 err = -ESRCH;
579 goto errout; 579 goto errout;
@@ -598,7 +598,7 @@ static int inet_rtm_newroute(struct sk_buff *skb, struct nlmsghdr* nlh, void *ar
598 if (err < 0) 598 if (err < 0)
599 goto errout; 599 goto errout;
600 600
601 tb = fib_new_table(cfg.fc_table); 601 tb = fib_new_table(&init_net, cfg.fc_table);
602 if (tb == NULL) { 602 if (tb == NULL) {
603 err = -ENOBUFS; 603 err = -ENOBUFS;
604 goto errout; 604 goto errout;
@@ -671,9 +671,9 @@ static void fib_magic(int cmd, int type, __be32 dst, int dst_len, struct in_ifad
671 }; 671 };
672 672
673 if (type == RTN_UNICAST) 673 if (type == RTN_UNICAST)
674 tb = fib_new_table(RT_TABLE_MAIN); 674 tb = fib_new_table(&init_net, RT_TABLE_MAIN);
675 else 675 else
676 tb = fib_new_table(RT_TABLE_LOCAL); 676 tb = fib_new_table(&init_net, RT_TABLE_LOCAL);
677 677
678 if (tb == NULL) 678 if (tb == NULL)
679 return; 679 return;
@@ -848,7 +848,7 @@ static void nl_fib_input(struct sk_buff *skb)
848 nlh = nlmsg_hdr(skb); 848 nlh = nlmsg_hdr(skb);
849 849
850 frn = (struct fib_result_nl *) NLMSG_DATA(nlh); 850 frn = (struct fib_result_nl *) NLMSG_DATA(nlh);
851 tb = fib_get_table(frn->tb_id_in); 851 tb = fib_get_table(&init_net, frn->tb_id_in);
852 852
853 nl_fib_lookup(frn, tb); 853 nl_fib_lookup(frn, tb);
854 854
diff --git a/net/ipv4/fib_hash.c b/net/ipv4/fib_hash.c
index 694a072d8090..d20ae2e28ab5 100644
--- a/net/ipv4/fib_hash.c
+++ b/net/ipv4/fib_hash.c
@@ -796,7 +796,7 @@ struct fib_iter_state {
796static struct fib_alias *fib_get_first(struct seq_file *seq) 796static struct fib_alias *fib_get_first(struct seq_file *seq)
797{ 797{
798 struct fib_iter_state *iter = seq->private; 798 struct fib_iter_state *iter = seq->private;
799 struct fib_table *main_table = fib_get_table(RT_TABLE_MAIN); 799 struct fib_table *main_table = fib_get_table(&init_net, RT_TABLE_MAIN);
800 struct fn_hash *table = (struct fn_hash *)main_table->tb_data; 800 struct fn_hash *table = (struct fn_hash *)main_table->tb_data;
801 801
802 iter->bucket = 0; 802 iter->bucket = 0;
@@ -937,7 +937,7 @@ static void *fib_seq_start(struct seq_file *seq, loff_t *pos)
937 void *v = NULL; 937 void *v = NULL;
938 938
939 read_lock(&fib_hash_lock); 939 read_lock(&fib_hash_lock);
940 if (fib_get_table(RT_TABLE_MAIN)) 940 if (fib_get_table(&init_net, RT_TABLE_MAIN))
941 v = *pos ? fib_get_idx(seq, *pos - 1) : SEQ_START_TOKEN; 941 v = *pos ? fib_get_idx(seq, *pos - 1) : SEQ_START_TOKEN;
942 return v; 942 return v;
943} 943}
diff --git a/net/ipv4/fib_rules.c b/net/ipv4/fib_rules.c
index 1aae61c8ea6a..49819fe7e4c3 100644
--- a/net/ipv4/fib_rules.c
+++ b/net/ipv4/fib_rules.c
@@ -93,7 +93,7 @@ static int fib4_rule_action(struct fib_rule *rule, struct flowi *flp,
93 goto errout; 93 goto errout;
94 } 94 }
95 95
96 if ((tbl = fib_get_table(rule->table)) == NULL) 96 if ((tbl = fib_get_table(&init_net, rule->table)) == NULL)
97 goto errout; 97 goto errout;
98 98
99 err = tbl->tb_lookup(tbl, flp, (struct fib_result *) arg->result); 99 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 if (res->r && res->r->action == FR_ACT_TO_TBL && 109 if (res->r && res->r->action == FR_ACT_TO_TBL &&
110 FIB_RES_GW(*res) && FIB_RES_NH(*res).nh_scope == RT_SCOPE_LINK) { 110 FIB_RES_GW(*res) && FIB_RES_NH(*res).nh_scope == RT_SCOPE_LINK) {
111 struct fib_table *tb; 111 struct fib_table *tb;
112 if ((tb = fib_get_table(res->r->table)) != NULL) 112 if ((tb = fib_get_table(&init_net, res->r->table)) != NULL)
113 tb->tb_select_default(tb, flp, res); 113 tb->tb_select_default(tb, flp, res);
114 } 114 }
115} 115}
@@ -130,13 +130,13 @@ static int fib4_rule_match(struct fib_rule *rule, struct flowi *fl, int flags)
130 return 1; 130 return 1;
131} 131}
132 132
133static struct fib_table *fib_empty_table(void) 133static struct fib_table *fib_empty_table(struct net *net)
134{ 134{
135 u32 id; 135 u32 id;
136 136
137 for (id = 1; id <= RT_TABLE_MAX; id++) 137 for (id = 1; id <= RT_TABLE_MAX; id++)
138 if (fib_get_table(id) == NULL) 138 if (fib_get_table(net, id) == NULL)
139 return fib_new_table(id); 139 return fib_new_table(net, id);
140 return NULL; 140 return NULL;
141} 141}
142 142
@@ -159,7 +159,7 @@ static int fib4_rule_configure(struct fib_rule *rule, struct sk_buff *skb,
159 if (rule->action == FR_ACT_TO_TBL) { 159 if (rule->action == FR_ACT_TO_TBL) {
160 struct fib_table *table; 160 struct fib_table *table;
161 161
162 table = fib_empty_table(); 162 table = fib_empty_table(&init_net);
163 if (table == NULL) { 163 if (table == NULL) {
164 err = -ENOBUFS; 164 err = -ENOBUFS;
165 goto errout; 165 goto errout;
diff --git a/net/ipv4/fib_trie.c b/net/ipv4/fib_trie.c
index 92b687e6a472..fc0624e6a649 100644
--- a/net/ipv4/fib_trie.c
+++ b/net/ipv4/fib_trie.c
@@ -2167,12 +2167,12 @@ static int fib_triestat_seq_show(struct seq_file *seq, void *v)
2167 struct fib_table *tb; 2167 struct fib_table *tb;
2168 2168
2169 trie_local = NULL; 2169 trie_local = NULL;
2170 tb = fib_get_table(RT_TABLE_LOCAL); 2170 tb = fib_get_table(&init_net, RT_TABLE_LOCAL);
2171 if (tb) 2171 if (tb)
2172 trie_local = (struct trie *) tb->tb_data; 2172 trie_local = (struct trie *) tb->tb_data;
2173 2173
2174 trie_main = NULL; 2174 trie_main = NULL;
2175 tb = fib_get_table(RT_TABLE_MAIN); 2175 tb = fib_get_table(&init_net, RT_TABLE_MAIN);
2176 if (tb) 2176 if (tb)
2177 trie_main = (struct trie *) tb->tb_data; 2177 trie_main = (struct trie *) tb->tb_data;
2178 2178
@@ -2239,12 +2239,12 @@ static void *fib_trie_seq_start(struct seq_file *seq, loff_t *pos)
2239 struct fib_table *tb; 2239 struct fib_table *tb;
2240 2240
2241 if (!iter->trie_local) { 2241 if (!iter->trie_local) {
2242 tb = fib_get_table(RT_TABLE_LOCAL); 2242 tb = fib_get_table(&init_net, RT_TABLE_LOCAL);
2243 if (tb) 2243 if (tb)
2244 iter->trie_local = (struct trie *) tb->tb_data; 2244 iter->trie_local = (struct trie *) tb->tb_data;
2245 } 2245 }
2246 if (!iter->trie_main) { 2246 if (!iter->trie_main) {
2247 tb = fib_get_table(RT_TABLE_MAIN); 2247 tb = fib_get_table(&init_net, RT_TABLE_MAIN);
2248 if (tb) 2248 if (tb)
2249 iter->trie_main = (struct trie *) tb->tb_data; 2249 iter->trie_main = (struct trie *) tb->tb_data;
2250 } 2250 }