aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv6/ip6mr.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/ipv6/ip6mr.c')
-rw-r--r--net/ipv6/ip6mr.c953
1 files changed, 682 insertions, 271 deletions
diff --git a/net/ipv6/ip6mr.c b/net/ipv6/ip6mr.c
index 52e0f74fdfe0..66078dad7fe8 100644
--- a/net/ipv6/ip6mr.c
+++ b/net/ipv6/ip6mr.c
@@ -33,6 +33,7 @@
33#include <linux/proc_fs.h> 33#include <linux/proc_fs.h>
34#include <linux/seq_file.h> 34#include <linux/seq_file.h>
35#include <linux/init.h> 35#include <linux/init.h>
36#include <linux/slab.h>
36#include <net/protocol.h> 37#include <net/protocol.h>
37#include <linux/skbuff.h> 38#include <linux/skbuff.h>
38#include <net/sock.h> 39#include <net/sock.h>
@@ -41,6 +42,7 @@
41#include <linux/if_arp.h> 42#include <linux/if_arp.h>
42#include <net/checksum.h> 43#include <net/checksum.h>
43#include <net/netlink.h> 44#include <net/netlink.h>
45#include <net/fib_rules.h>
44 46
45#include <net/ipv6.h> 47#include <net/ipv6.h>
46#include <net/ip6_route.h> 48#include <net/ip6_route.h>
@@ -50,6 +52,34 @@
50#include <linux/netfilter_ipv6.h> 52#include <linux/netfilter_ipv6.h>
51#include <net/ip6_checksum.h> 53#include <net/ip6_checksum.h>
52 54
55struct mr6_table {
56 struct list_head list;
57#ifdef CONFIG_NET_NS
58 struct net *net;
59#endif
60 u32 id;
61 struct sock *mroute6_sk;
62 struct timer_list ipmr_expire_timer;
63 struct list_head mfc6_unres_queue;
64 struct list_head mfc6_cache_array[MFC6_LINES];
65 struct mif_device vif6_table[MAXMIFS];
66 int maxvif;
67 atomic_t cache_resolve_queue_len;
68 int mroute_do_assert;
69 int mroute_do_pim;
70#ifdef CONFIG_IPV6_PIMSM_V2
71 int mroute_reg_vif_num;
72#endif
73};
74
75struct ip6mr_rule {
76 struct fib_rule common;
77};
78
79struct ip6mr_result {
80 struct mr6_table *mrt;
81};
82
53/* Big lock, protecting vif table, mrt cache and mroute socket state. 83/* Big lock, protecting vif table, mrt cache and mroute socket state.
54 Note that the changes are semaphored via rtnl_lock. 84 Note that the changes are semaphored via rtnl_lock.
55 */ 85 */
@@ -60,9 +90,7 @@ static DEFINE_RWLOCK(mrt_lock);
60 * Multicast router control variables 90 * Multicast router control variables
61 */ 91 */
62 92
63#define MIF_EXISTS(_net, _idx) ((_net)->ipv6.vif6_table[_idx].dev != NULL) 93#define MIF_EXISTS(_mrt, _idx) ((_mrt)->vif6_table[_idx].dev != NULL)
64
65static struct mfc6_cache *mfc_unres_queue; /* Queue of unresolved entries */
66 94
67/* Special spinlock for queue of unresolved entries */ 95/* Special spinlock for queue of unresolved entries */
68static DEFINE_SPINLOCK(mfc_unres_lock); 96static DEFINE_SPINLOCK(mfc_unres_lock);
@@ -77,20 +105,235 @@ static DEFINE_SPINLOCK(mfc_unres_lock);
77 105
78static struct kmem_cache *mrt_cachep __read_mostly; 106static struct kmem_cache *mrt_cachep __read_mostly;
79 107
80static int ip6_mr_forward(struct sk_buff *skb, struct mfc6_cache *cache); 108static struct mr6_table *ip6mr_new_table(struct net *net, u32 id);
81static int ip6mr_cache_report(struct net *net, struct sk_buff *pkt, 109static void ip6mr_free_table(struct mr6_table *mrt);
110
111static int ip6_mr_forward(struct net *net, struct mr6_table *mrt,
112 struct sk_buff *skb, struct mfc6_cache *cache);
113static int ip6mr_cache_report(struct mr6_table *mrt, struct sk_buff *pkt,
82 mifi_t mifi, int assert); 114 mifi_t mifi, int assert);
83static int ip6mr_fill_mroute(struct sk_buff *skb, struct mfc6_cache *c, struct rtmsg *rtm); 115static int __ip6mr_fill_mroute(struct mr6_table *mrt, struct sk_buff *skb,
84static void mroute_clean_tables(struct net *net); 116 struct mfc6_cache *c, struct rtmsg *rtm);
117static int ip6mr_rtm_dumproute(struct sk_buff *skb,
118 struct netlink_callback *cb);
119static void mroute_clean_tables(struct mr6_table *mrt);
120static void ipmr_expire_process(unsigned long arg);
121
122#ifdef CONFIG_IPV6_MROUTE_MULTIPLE_TABLES
123#define ip6mr_for_each_table(mrt, net) \
124 list_for_each_entry_rcu(mrt, &net->ipv6.mr6_tables, list)
125
126static struct mr6_table *ip6mr_get_table(struct net *net, u32 id)
127{
128 struct mr6_table *mrt;
129
130 ip6mr_for_each_table(mrt, net) {
131 if (mrt->id == id)
132 return mrt;
133 }
134 return NULL;
135}
136
137static int ip6mr_fib_lookup(struct net *net, struct flowi *flp,
138 struct mr6_table **mrt)
139{
140 struct ip6mr_result res;
141 struct fib_lookup_arg arg = { .result = &res, };
142 int err;
143
144 err = fib_rules_lookup(net->ipv6.mr6_rules_ops, flp, 0, &arg);
145 if (err < 0)
146 return err;
147 *mrt = res.mrt;
148 return 0;
149}
150
151static int ip6mr_rule_action(struct fib_rule *rule, struct flowi *flp,
152 int flags, struct fib_lookup_arg *arg)
153{
154 struct ip6mr_result *res = arg->result;
155 struct mr6_table *mrt;
156
157 switch (rule->action) {
158 case FR_ACT_TO_TBL:
159 break;
160 case FR_ACT_UNREACHABLE:
161 return -ENETUNREACH;
162 case FR_ACT_PROHIBIT:
163 return -EACCES;
164 case FR_ACT_BLACKHOLE:
165 default:
166 return -EINVAL;
167 }
168
169 mrt = ip6mr_get_table(rule->fr_net, rule->table);
170 if (mrt == NULL)
171 return -EAGAIN;
172 res->mrt = mrt;
173 return 0;
174}
175
176static int ip6mr_rule_match(struct fib_rule *rule, struct flowi *flp, int flags)
177{
178 return 1;
179}
85 180
86static struct timer_list ipmr_expire_timer; 181static const struct nla_policy ip6mr_rule_policy[FRA_MAX + 1] = {
182 FRA_GENERIC_POLICY,
183};
87 184
185static int ip6mr_rule_configure(struct fib_rule *rule, struct sk_buff *skb,
186 struct fib_rule_hdr *frh, struct nlattr **tb)
187{
188 return 0;
189}
190
191static int ip6mr_rule_compare(struct fib_rule *rule, struct fib_rule_hdr *frh,
192 struct nlattr **tb)
193{
194 return 1;
195}
196
197static int ip6mr_rule_fill(struct fib_rule *rule, struct sk_buff *skb,
198 struct fib_rule_hdr *frh)
199{
200 frh->dst_len = 0;
201 frh->src_len = 0;
202 frh->tos = 0;
203 return 0;
204}
205
206static const struct fib_rules_ops __net_initdata ip6mr_rules_ops_template = {
207 .family = RTNL_FAMILY_IP6MR,
208 .rule_size = sizeof(struct ip6mr_rule),
209 .addr_size = sizeof(struct in6_addr),
210 .action = ip6mr_rule_action,
211 .match = ip6mr_rule_match,
212 .configure = ip6mr_rule_configure,
213 .compare = ip6mr_rule_compare,
214 .default_pref = fib_default_rule_pref,
215 .fill = ip6mr_rule_fill,
216 .nlgroup = RTNLGRP_IPV6_RULE,
217 .policy = ip6mr_rule_policy,
218 .owner = THIS_MODULE,
219};
220
221static int __net_init ip6mr_rules_init(struct net *net)
222{
223 struct fib_rules_ops *ops;
224 struct mr6_table *mrt;
225 int err;
226
227 ops = fib_rules_register(&ip6mr_rules_ops_template, net);
228 if (IS_ERR(ops))
229 return PTR_ERR(ops);
230
231 INIT_LIST_HEAD(&net->ipv6.mr6_tables);
232
233 mrt = ip6mr_new_table(net, RT6_TABLE_DFLT);
234 if (mrt == NULL) {
235 err = -ENOMEM;
236 goto err1;
237 }
238
239 err = fib_default_rule_add(ops, 0x7fff, RT6_TABLE_DFLT, 0);
240 if (err < 0)
241 goto err2;
242
243 net->ipv6.mr6_rules_ops = ops;
244 return 0;
245
246err2:
247 kfree(mrt);
248err1:
249 fib_rules_unregister(ops);
250 return err;
251}
252
253static void __net_exit ip6mr_rules_exit(struct net *net)
254{
255 struct mr6_table *mrt, *next;
256
257 list_for_each_entry_safe(mrt, next, &net->ipv6.mr6_tables, list) {
258 list_del(&mrt->list);
259 ip6mr_free_table(mrt);
260 }
261 fib_rules_unregister(net->ipv6.mr6_rules_ops);
262}
263#else
264#define ip6mr_for_each_table(mrt, net) \
265 for (mrt = net->ipv6.mrt6; mrt; mrt = NULL)
266
267static struct mr6_table *ip6mr_get_table(struct net *net, u32 id)
268{
269 return net->ipv6.mrt6;
270}
271
272static int ip6mr_fib_lookup(struct net *net, struct flowi *flp,
273 struct mr6_table **mrt)
274{
275 *mrt = net->ipv6.mrt6;
276 return 0;
277}
278
279static int __net_init ip6mr_rules_init(struct net *net)
280{
281 net->ipv6.mrt6 = ip6mr_new_table(net, RT6_TABLE_DFLT);
282 return net->ipv6.mrt6 ? 0 : -ENOMEM;
283}
284
285static void __net_exit ip6mr_rules_exit(struct net *net)
286{
287 ip6mr_free_table(net->ipv6.mrt6);
288}
289#endif
290
291static struct mr6_table *ip6mr_new_table(struct net *net, u32 id)
292{
293 struct mr6_table *mrt;
294 unsigned int i;
295
296 mrt = ip6mr_get_table(net, id);
297 if (mrt != NULL)
298 return mrt;
299
300 mrt = kzalloc(sizeof(*mrt), GFP_KERNEL);
301 if (mrt == NULL)
302 return NULL;
303 mrt->id = id;
304 write_pnet(&mrt->net, net);
305
306 /* Forwarding cache */
307 for (i = 0; i < MFC6_LINES; i++)
308 INIT_LIST_HEAD(&mrt->mfc6_cache_array[i]);
309
310 INIT_LIST_HEAD(&mrt->mfc6_unres_queue);
311
312 setup_timer(&mrt->ipmr_expire_timer, ipmr_expire_process,
313 (unsigned long)mrt);
314
315#ifdef CONFIG_IPV6_PIMSM_V2
316 mrt->mroute_reg_vif_num = -1;
317#endif
318#ifdef CONFIG_IPV6_MROUTE_MULTIPLE_TABLES
319 list_add_tail_rcu(&mrt->list, &net->ipv6.mr6_tables);
320#endif
321 return mrt;
322}
323
324static void ip6mr_free_table(struct mr6_table *mrt)
325{
326 del_timer(&mrt->ipmr_expire_timer);
327 mroute_clean_tables(mrt);
328 kfree(mrt);
329}
88 330
89#ifdef CONFIG_PROC_FS 331#ifdef CONFIG_PROC_FS
90 332
91struct ipmr_mfc_iter { 333struct ipmr_mfc_iter {
92 struct seq_net_private p; 334 struct seq_net_private p;
93 struct mfc6_cache **cache; 335 struct mr6_table *mrt;
336 struct list_head *cache;
94 int ct; 337 int ct;
95}; 338};
96 339
@@ -98,22 +341,22 @@ struct ipmr_mfc_iter {
98static struct mfc6_cache *ipmr_mfc_seq_idx(struct net *net, 341static struct mfc6_cache *ipmr_mfc_seq_idx(struct net *net,
99 struct ipmr_mfc_iter *it, loff_t pos) 342 struct ipmr_mfc_iter *it, loff_t pos)
100{ 343{
344 struct mr6_table *mrt = it->mrt;
101 struct mfc6_cache *mfc; 345 struct mfc6_cache *mfc;
102 346
103 it->cache = net->ipv6.mfc6_cache_array;
104 read_lock(&mrt_lock); 347 read_lock(&mrt_lock);
105 for (it->ct = 0; it->ct < MFC6_LINES; it->ct++) 348 for (it->ct = 0; it->ct < MFC6_LINES; it->ct++) {
106 for (mfc = net->ipv6.mfc6_cache_array[it->ct]; 349 it->cache = &mrt->mfc6_cache_array[it->ct];
107 mfc; mfc = mfc->next) 350 list_for_each_entry(mfc, it->cache, list)
108 if (pos-- == 0) 351 if (pos-- == 0)
109 return mfc; 352 return mfc;
353 }
110 read_unlock(&mrt_lock); 354 read_unlock(&mrt_lock);
111 355
112 it->cache = &mfc_unres_queue;
113 spin_lock_bh(&mfc_unres_lock); 356 spin_lock_bh(&mfc_unres_lock);
114 for (mfc = mfc_unres_queue; mfc; mfc = mfc->next) 357 it->cache = &mrt->mfc6_unres_queue;
115 if (net_eq(mfc6_net(mfc), net) && 358 list_for_each_entry(mfc, it->cache, list)
116 pos-- == 0) 359 if (pos-- == 0)
117 return mfc; 360 return mfc;
118 spin_unlock_bh(&mfc_unres_lock); 361 spin_unlock_bh(&mfc_unres_lock);
119 362
@@ -121,15 +364,13 @@ static struct mfc6_cache *ipmr_mfc_seq_idx(struct net *net,
121 return NULL; 364 return NULL;
122} 365}
123 366
124
125
126
127/* 367/*
128 * The /proc interfaces to multicast routing /proc/ip6_mr_cache /proc/ip6_mr_vif 368 * The /proc interfaces to multicast routing /proc/ip6_mr_cache /proc/ip6_mr_vif
129 */ 369 */
130 370
131struct ipmr_vif_iter { 371struct ipmr_vif_iter {
132 struct seq_net_private p; 372 struct seq_net_private p;
373 struct mr6_table *mrt;
133 int ct; 374 int ct;
134}; 375};
135 376
@@ -137,11 +378,13 @@ static struct mif_device *ip6mr_vif_seq_idx(struct net *net,
137 struct ipmr_vif_iter *iter, 378 struct ipmr_vif_iter *iter,
138 loff_t pos) 379 loff_t pos)
139{ 380{
140 for (iter->ct = 0; iter->ct < net->ipv6.maxvif; ++iter->ct) { 381 struct mr6_table *mrt = iter->mrt;
141 if (!MIF_EXISTS(net, iter->ct)) 382
383 for (iter->ct = 0; iter->ct < mrt->maxvif; ++iter->ct) {
384 if (!MIF_EXISTS(mrt, iter->ct))
142 continue; 385 continue;
143 if (pos-- == 0) 386 if (pos-- == 0)
144 return &net->ipv6.vif6_table[iter->ct]; 387 return &mrt->vif6_table[iter->ct];
145 } 388 }
146 return NULL; 389 return NULL;
147} 390}
@@ -149,7 +392,15 @@ static struct mif_device *ip6mr_vif_seq_idx(struct net *net,
149static void *ip6mr_vif_seq_start(struct seq_file *seq, loff_t *pos) 392static void *ip6mr_vif_seq_start(struct seq_file *seq, loff_t *pos)
150 __acquires(mrt_lock) 393 __acquires(mrt_lock)
151{ 394{
395 struct ipmr_vif_iter *iter = seq->private;
152 struct net *net = seq_file_net(seq); 396 struct net *net = seq_file_net(seq);
397 struct mr6_table *mrt;
398
399 mrt = ip6mr_get_table(net, RT6_TABLE_DFLT);
400 if (mrt == NULL)
401 return ERR_PTR(-ENOENT);
402
403 iter->mrt = mrt;
153 404
154 read_lock(&mrt_lock); 405 read_lock(&mrt_lock);
155 return *pos ? ip6mr_vif_seq_idx(net, seq->private, *pos - 1) 406 return *pos ? ip6mr_vif_seq_idx(net, seq->private, *pos - 1)
@@ -160,15 +411,16 @@ static void *ip6mr_vif_seq_next(struct seq_file *seq, void *v, loff_t *pos)
160{ 411{
161 struct ipmr_vif_iter *iter = seq->private; 412 struct ipmr_vif_iter *iter = seq->private;
162 struct net *net = seq_file_net(seq); 413 struct net *net = seq_file_net(seq);
414 struct mr6_table *mrt = iter->mrt;
163 415
164 ++*pos; 416 ++*pos;
165 if (v == SEQ_START_TOKEN) 417 if (v == SEQ_START_TOKEN)
166 return ip6mr_vif_seq_idx(net, iter, 0); 418 return ip6mr_vif_seq_idx(net, iter, 0);
167 419
168 while (++iter->ct < net->ipv6.maxvif) { 420 while (++iter->ct < mrt->maxvif) {
169 if (!MIF_EXISTS(net, iter->ct)) 421 if (!MIF_EXISTS(mrt, iter->ct))
170 continue; 422 continue;
171 return &net->ipv6.vif6_table[iter->ct]; 423 return &mrt->vif6_table[iter->ct];
172 } 424 }
173 return NULL; 425 return NULL;
174} 426}
@@ -181,7 +433,8 @@ static void ip6mr_vif_seq_stop(struct seq_file *seq, void *v)
181 433
182static int ip6mr_vif_seq_show(struct seq_file *seq, void *v) 434static int ip6mr_vif_seq_show(struct seq_file *seq, void *v)
183{ 435{
184 struct net *net = seq_file_net(seq); 436 struct ipmr_vif_iter *iter = seq->private;
437 struct mr6_table *mrt = iter->mrt;
185 438
186 if (v == SEQ_START_TOKEN) { 439 if (v == SEQ_START_TOKEN) {
187 seq_puts(seq, 440 seq_puts(seq,
@@ -192,7 +445,7 @@ static int ip6mr_vif_seq_show(struct seq_file *seq, void *v)
192 445
193 seq_printf(seq, 446 seq_printf(seq,
194 "%2td %-10s %8ld %7ld %8ld %7ld %05X\n", 447 "%2td %-10s %8ld %7ld %8ld %7ld %05X\n",
195 vif - net->ipv6.vif6_table, 448 vif - mrt->vif6_table,
196 name, vif->bytes_in, vif->pkt_in, 449 name, vif->bytes_in, vif->pkt_in,
197 vif->bytes_out, vif->pkt_out, 450 vif->bytes_out, vif->pkt_out,
198 vif->flags); 451 vif->flags);
@@ -223,8 +476,15 @@ static const struct file_operations ip6mr_vif_fops = {
223 476
224static void *ipmr_mfc_seq_start(struct seq_file *seq, loff_t *pos) 477static void *ipmr_mfc_seq_start(struct seq_file *seq, loff_t *pos)
225{ 478{
479 struct ipmr_mfc_iter *it = seq->private;
226 struct net *net = seq_file_net(seq); 480 struct net *net = seq_file_net(seq);
481 struct mr6_table *mrt;
482
483 mrt = ip6mr_get_table(net, RT6_TABLE_DFLT);
484 if (mrt == NULL)
485 return ERR_PTR(-ENOENT);
227 486
487 it->mrt = mrt;
228 return *pos ? ipmr_mfc_seq_idx(net, seq->private, *pos - 1) 488 return *pos ? ipmr_mfc_seq_idx(net, seq->private, *pos - 1)
229 : SEQ_START_TOKEN; 489 : SEQ_START_TOKEN;
230} 490}
@@ -234,35 +494,36 @@ static void *ipmr_mfc_seq_next(struct seq_file *seq, void *v, loff_t *pos)
234 struct mfc6_cache *mfc = v; 494 struct mfc6_cache *mfc = v;
235 struct ipmr_mfc_iter *it = seq->private; 495 struct ipmr_mfc_iter *it = seq->private;
236 struct net *net = seq_file_net(seq); 496 struct net *net = seq_file_net(seq);
497 struct mr6_table *mrt = it->mrt;
237 498
238 ++*pos; 499 ++*pos;
239 500
240 if (v == SEQ_START_TOKEN) 501 if (v == SEQ_START_TOKEN)
241 return ipmr_mfc_seq_idx(net, seq->private, 0); 502 return ipmr_mfc_seq_idx(net, seq->private, 0);
242 503
243 if (mfc->next) 504 if (mfc->list.next != it->cache)
244 return mfc->next; 505 return list_entry(mfc->list.next, struct mfc6_cache, list);
245 506
246 if (it->cache == &mfc_unres_queue) 507 if (it->cache == &mrt->mfc6_unres_queue)
247 goto end_of_list; 508 goto end_of_list;
248 509
249 BUG_ON(it->cache != net->ipv6.mfc6_cache_array); 510 BUG_ON(it->cache != &mrt->mfc6_cache_array[it->ct]);
250 511
251 while (++it->ct < MFC6_LINES) { 512 while (++it->ct < MFC6_LINES) {
252 mfc = net->ipv6.mfc6_cache_array[it->ct]; 513 it->cache = &mrt->mfc6_cache_array[it->ct];
253 if (mfc) 514 if (list_empty(it->cache))
254 return mfc; 515 continue;
516 return list_first_entry(it->cache, struct mfc6_cache, list);
255 } 517 }
256 518
257 /* exhausted cache_array, show unresolved */ 519 /* exhausted cache_array, show unresolved */
258 read_unlock(&mrt_lock); 520 read_unlock(&mrt_lock);
259 it->cache = &mfc_unres_queue; 521 it->cache = &mrt->mfc6_unres_queue;
260 it->ct = 0; 522 it->ct = 0;
261 523
262 spin_lock_bh(&mfc_unres_lock); 524 spin_lock_bh(&mfc_unres_lock);
263 mfc = mfc_unres_queue; 525 if (!list_empty(it->cache))
264 if (mfc) 526 return list_first_entry(it->cache, struct mfc6_cache, list);
265 return mfc;
266 527
267 end_of_list: 528 end_of_list:
268 spin_unlock_bh(&mfc_unres_lock); 529 spin_unlock_bh(&mfc_unres_lock);
@@ -274,18 +535,17 @@ static void *ipmr_mfc_seq_next(struct seq_file *seq, void *v, loff_t *pos)
274static void ipmr_mfc_seq_stop(struct seq_file *seq, void *v) 535static void ipmr_mfc_seq_stop(struct seq_file *seq, void *v)
275{ 536{
276 struct ipmr_mfc_iter *it = seq->private; 537 struct ipmr_mfc_iter *it = seq->private;
277 struct net *net = seq_file_net(seq); 538 struct mr6_table *mrt = it->mrt;
278 539
279 if (it->cache == &mfc_unres_queue) 540 if (it->cache == &mrt->mfc6_unres_queue)
280 spin_unlock_bh(&mfc_unres_lock); 541 spin_unlock_bh(&mfc_unres_lock);
281 else if (it->cache == net->ipv6.mfc6_cache_array) 542 else if (it->cache == mrt->mfc6_cache_array)
282 read_unlock(&mrt_lock); 543 read_unlock(&mrt_lock);
283} 544}
284 545
285static int ipmr_mfc_seq_show(struct seq_file *seq, void *v) 546static int ipmr_mfc_seq_show(struct seq_file *seq, void *v)
286{ 547{
287 int n; 548 int n;
288 struct net *net = seq_file_net(seq);
289 549
290 if (v == SEQ_START_TOKEN) { 550 if (v == SEQ_START_TOKEN) {
291 seq_puts(seq, 551 seq_puts(seq,
@@ -295,19 +555,20 @@ static int ipmr_mfc_seq_show(struct seq_file *seq, void *v)
295 } else { 555 } else {
296 const struct mfc6_cache *mfc = v; 556 const struct mfc6_cache *mfc = v;
297 const struct ipmr_mfc_iter *it = seq->private; 557 const struct ipmr_mfc_iter *it = seq->private;
558 struct mr6_table *mrt = it->mrt;
298 559
299 seq_printf(seq, "%pI6 %pI6 %-3hd", 560 seq_printf(seq, "%pI6 %pI6 %-3hd",
300 &mfc->mf6c_mcastgrp, &mfc->mf6c_origin, 561 &mfc->mf6c_mcastgrp, &mfc->mf6c_origin,
301 mfc->mf6c_parent); 562 mfc->mf6c_parent);
302 563
303 if (it->cache != &mfc_unres_queue) { 564 if (it->cache != &mrt->mfc6_unres_queue) {
304 seq_printf(seq, " %8lu %8lu %8lu", 565 seq_printf(seq, " %8lu %8lu %8lu",
305 mfc->mfc_un.res.pkt, 566 mfc->mfc_un.res.pkt,
306 mfc->mfc_un.res.bytes, 567 mfc->mfc_un.res.bytes,
307 mfc->mfc_un.res.wrong_if); 568 mfc->mfc_un.res.wrong_if);
308 for (n = mfc->mfc_un.res.minvif; 569 for (n = mfc->mfc_un.res.minvif;
309 n < mfc->mfc_un.res.maxvif; n++) { 570 n < mfc->mfc_un.res.maxvif; n++) {
310 if (MIF_EXISTS(net, n) && 571 if (MIF_EXISTS(mrt, n) &&
311 mfc->mfc_un.res.ttls[n] < 255) 572 mfc->mfc_un.res.ttls[n] < 255)
312 seq_printf(seq, 573 seq_printf(seq,
313 " %2d:%-3d", 574 " %2d:%-3d",
@@ -354,7 +615,12 @@ static int pim6_rcv(struct sk_buff *skb)
354 struct ipv6hdr *encap; 615 struct ipv6hdr *encap;
355 struct net_device *reg_dev = NULL; 616 struct net_device *reg_dev = NULL;
356 struct net *net = dev_net(skb->dev); 617 struct net *net = dev_net(skb->dev);
357 int reg_vif_num = net->ipv6.mroute_reg_vif_num; 618 struct mr6_table *mrt;
619 struct flowi fl = {
620 .iif = skb->dev->ifindex,
621 .mark = skb->mark,
622 };
623 int reg_vif_num;
358 624
359 if (!pskb_may_pull(skb, sizeof(*pim) + sizeof(*encap))) 625 if (!pskb_may_pull(skb, sizeof(*pim) + sizeof(*encap)))
360 goto drop; 626 goto drop;
@@ -377,9 +643,13 @@ static int pim6_rcv(struct sk_buff *skb)
377 ntohs(encap->payload_len) + sizeof(*pim) > skb->len) 643 ntohs(encap->payload_len) + sizeof(*pim) > skb->len)
378 goto drop; 644 goto drop;
379 645
646 if (ip6mr_fib_lookup(net, &fl, &mrt) < 0)
647 goto drop;
648 reg_vif_num = mrt->mroute_reg_vif_num;
649
380 read_lock(&mrt_lock); 650 read_lock(&mrt_lock);
381 if (reg_vif_num >= 0) 651 if (reg_vif_num >= 0)
382 reg_dev = net->ipv6.vif6_table[reg_vif_num].dev; 652 reg_dev = mrt->vif6_table[reg_vif_num].dev;
383 if (reg_dev) 653 if (reg_dev)
384 dev_hold(reg_dev); 654 dev_hold(reg_dev);
385 read_unlock(&mrt_lock); 655 read_unlock(&mrt_lock);
@@ -390,14 +660,12 @@ static int pim6_rcv(struct sk_buff *skb)
390 skb->mac_header = skb->network_header; 660 skb->mac_header = skb->network_header;
391 skb_pull(skb, (u8 *)encap - skb->data); 661 skb_pull(skb, (u8 *)encap - skb->data);
392 skb_reset_network_header(skb); 662 skb_reset_network_header(skb);
393 skb->dev = reg_dev;
394 skb->protocol = htons(ETH_P_IPV6); 663 skb->protocol = htons(ETH_P_IPV6);
395 skb->ip_summed = 0; 664 skb->ip_summed = 0;
396 skb->pkt_type = PACKET_HOST; 665 skb->pkt_type = PACKET_HOST;
397 skb_dst_drop(skb); 666
398 reg_dev->stats.rx_bytes += skb->len; 667 skb_tunnel_rx(skb, reg_dev);
399 reg_dev->stats.rx_packets++; 668
400 nf_reset(skb);
401 netif_rx(skb); 669 netif_rx(skb);
402 dev_put(reg_dev); 670 dev_put(reg_dev);
403 return 0; 671 return 0;
@@ -416,12 +684,22 @@ static netdev_tx_t reg_vif_xmit(struct sk_buff *skb,
416 struct net_device *dev) 684 struct net_device *dev)
417{ 685{
418 struct net *net = dev_net(dev); 686 struct net *net = dev_net(dev);
687 struct mr6_table *mrt;
688 struct flowi fl = {
689 .oif = dev->ifindex,
690 .iif = skb->skb_iif,
691 .mark = skb->mark,
692 };
693 int err;
694
695 err = ip6mr_fib_lookup(net, &fl, &mrt);
696 if (err < 0)
697 return err;
419 698
420 read_lock(&mrt_lock); 699 read_lock(&mrt_lock);
421 dev->stats.tx_bytes += skb->len; 700 dev->stats.tx_bytes += skb->len;
422 dev->stats.tx_packets++; 701 dev->stats.tx_packets++;
423 ip6mr_cache_report(net, skb, net->ipv6.mroute_reg_vif_num, 702 ip6mr_cache_report(mrt, skb, mrt->mroute_reg_vif_num, MRT6MSG_WHOLEPKT);
424 MRT6MSG_WHOLEPKT);
425 read_unlock(&mrt_lock); 703 read_unlock(&mrt_lock);
426 kfree_skb(skb); 704 kfree_skb(skb);
427 return NETDEV_TX_OK; 705 return NETDEV_TX_OK;
@@ -441,11 +719,17 @@ static void reg_vif_setup(struct net_device *dev)
441 dev->features |= NETIF_F_NETNS_LOCAL; 719 dev->features |= NETIF_F_NETNS_LOCAL;
442} 720}
443 721
444static struct net_device *ip6mr_reg_vif(struct net *net) 722static struct net_device *ip6mr_reg_vif(struct net *net, struct mr6_table *mrt)
445{ 723{
446 struct net_device *dev; 724 struct net_device *dev;
725 char name[IFNAMSIZ];
447 726
448 dev = alloc_netdev(0, "pim6reg", reg_vif_setup); 727 if (mrt->id == RT6_TABLE_DFLT)
728 sprintf(name, "pim6reg");
729 else
730 sprintf(name, "pim6reg%u", mrt->id);
731
732 dev = alloc_netdev(0, name, reg_vif_setup);
449 if (dev == NULL) 733 if (dev == NULL)
450 return NULL; 734 return NULL;
451 735
@@ -477,15 +761,16 @@ failure:
477 * Delete a VIF entry 761 * Delete a VIF entry
478 */ 762 */
479 763
480static int mif6_delete(struct net *net, int vifi, struct list_head *head) 764static int mif6_delete(struct mr6_table *mrt, int vifi, struct list_head *head)
481{ 765{
482 struct mif_device *v; 766 struct mif_device *v;
483 struct net_device *dev; 767 struct net_device *dev;
484 struct inet6_dev *in6_dev; 768 struct inet6_dev *in6_dev;
485 if (vifi < 0 || vifi >= net->ipv6.maxvif) 769
770 if (vifi < 0 || vifi >= mrt->maxvif)
486 return -EADDRNOTAVAIL; 771 return -EADDRNOTAVAIL;
487 772
488 v = &net->ipv6.vif6_table[vifi]; 773 v = &mrt->vif6_table[vifi];
489 774
490 write_lock_bh(&mrt_lock); 775 write_lock_bh(&mrt_lock);
491 dev = v->dev; 776 dev = v->dev;
@@ -497,17 +782,17 @@ static int mif6_delete(struct net *net, int vifi, struct list_head *head)
497 } 782 }
498 783
499#ifdef CONFIG_IPV6_PIMSM_V2 784#ifdef CONFIG_IPV6_PIMSM_V2
500 if (vifi == net->ipv6.mroute_reg_vif_num) 785 if (vifi == mrt->mroute_reg_vif_num)
501 net->ipv6.mroute_reg_vif_num = -1; 786 mrt->mroute_reg_vif_num = -1;
502#endif 787#endif
503 788
504 if (vifi + 1 == net->ipv6.maxvif) { 789 if (vifi + 1 == mrt->maxvif) {
505 int tmp; 790 int tmp;
506 for (tmp = vifi - 1; tmp >= 0; tmp--) { 791 for (tmp = vifi - 1; tmp >= 0; tmp--) {
507 if (MIF_EXISTS(net, tmp)) 792 if (MIF_EXISTS(mrt, tmp))
508 break; 793 break;
509 } 794 }
510 net->ipv6.maxvif = tmp + 1; 795 mrt->maxvif = tmp + 1;
511 } 796 }
512 797
513 write_unlock_bh(&mrt_lock); 798 write_unlock_bh(&mrt_lock);
@@ -527,7 +812,6 @@ static int mif6_delete(struct net *net, int vifi, struct list_head *head)
527 812
528static inline void ip6mr_cache_free(struct mfc6_cache *c) 813static inline void ip6mr_cache_free(struct mfc6_cache *c)
529{ 814{
530 release_net(mfc6_net(c));
531 kmem_cache_free(mrt_cachep, c); 815 kmem_cache_free(mrt_cachep, c);
532} 816}
533 817
@@ -535,12 +819,12 @@ static inline void ip6mr_cache_free(struct mfc6_cache *c)
535 and reporting error to netlink readers. 819 and reporting error to netlink readers.
536 */ 820 */
537 821
538static void ip6mr_destroy_unres(struct mfc6_cache *c) 822static void ip6mr_destroy_unres(struct mr6_table *mrt, struct mfc6_cache *c)
539{ 823{
824 struct net *net = read_pnet(&mrt->net);
540 struct sk_buff *skb; 825 struct sk_buff *skb;
541 struct net *net = mfc6_net(c);
542 826
543 atomic_dec(&net->ipv6.cache_resolve_queue_len); 827 atomic_dec(&mrt->cache_resolve_queue_len);
544 828
545 while((skb = skb_dequeue(&c->mfc_un.unres.unresolved)) != NULL) { 829 while((skb = skb_dequeue(&c->mfc_un.unres.unresolved)) != NULL) {
546 if (ipv6_hdr(skb)->version == 0) { 830 if (ipv6_hdr(skb)->version == 0) {
@@ -558,60 +842,59 @@ static void ip6mr_destroy_unres(struct mfc6_cache *c)
558} 842}
559 843
560 844
561/* Single timer process for all the unresolved queue. */ 845/* Timer process for all the unresolved queue. */
562 846
563static void ipmr_do_expire_process(unsigned long dummy) 847static void ipmr_do_expire_process(struct mr6_table *mrt)
564{ 848{
565 unsigned long now = jiffies; 849 unsigned long now = jiffies;
566 unsigned long expires = 10 * HZ; 850 unsigned long expires = 10 * HZ;
567 struct mfc6_cache *c, **cp; 851 struct mfc6_cache *c, *next;
568 852
569 cp = &mfc_unres_queue; 853 list_for_each_entry_safe(c, next, &mrt->mfc6_unres_queue, list) {
570
571 while ((c = *cp) != NULL) {
572 if (time_after(c->mfc_un.unres.expires, now)) { 854 if (time_after(c->mfc_un.unres.expires, now)) {
573 /* not yet... */ 855 /* not yet... */
574 unsigned long interval = c->mfc_un.unres.expires - now; 856 unsigned long interval = c->mfc_un.unres.expires - now;
575 if (interval < expires) 857 if (interval < expires)
576 expires = interval; 858 expires = interval;
577 cp = &c->next;
578 continue; 859 continue;
579 } 860 }
580 861
581 *cp = c->next; 862 list_del(&c->list);
582 ip6mr_destroy_unres(c); 863 ip6mr_destroy_unres(mrt, c);
583 } 864 }
584 865
585 if (mfc_unres_queue != NULL) 866 if (!list_empty(&mrt->mfc6_unres_queue))
586 mod_timer(&ipmr_expire_timer, jiffies + expires); 867 mod_timer(&mrt->ipmr_expire_timer, jiffies + expires);
587} 868}
588 869
589static void ipmr_expire_process(unsigned long dummy) 870static void ipmr_expire_process(unsigned long arg)
590{ 871{
872 struct mr6_table *mrt = (struct mr6_table *)arg;
873
591 if (!spin_trylock(&mfc_unres_lock)) { 874 if (!spin_trylock(&mfc_unres_lock)) {
592 mod_timer(&ipmr_expire_timer, jiffies + 1); 875 mod_timer(&mrt->ipmr_expire_timer, jiffies + 1);
593 return; 876 return;
594 } 877 }
595 878
596 if (mfc_unres_queue != NULL) 879 if (!list_empty(&mrt->mfc6_unres_queue))
597 ipmr_do_expire_process(dummy); 880 ipmr_do_expire_process(mrt);
598 881
599 spin_unlock(&mfc_unres_lock); 882 spin_unlock(&mfc_unres_lock);
600} 883}
601 884
602/* Fill oifs list. It is called under write locked mrt_lock. */ 885/* Fill oifs list. It is called under write locked mrt_lock. */
603 886
604static void ip6mr_update_thresholds(struct mfc6_cache *cache, unsigned char *ttls) 887static void ip6mr_update_thresholds(struct mr6_table *mrt, struct mfc6_cache *cache,
888 unsigned char *ttls)
605{ 889{
606 int vifi; 890 int vifi;
607 struct net *net = mfc6_net(cache);
608 891
609 cache->mfc_un.res.minvif = MAXMIFS; 892 cache->mfc_un.res.minvif = MAXMIFS;
610 cache->mfc_un.res.maxvif = 0; 893 cache->mfc_un.res.maxvif = 0;
611 memset(cache->mfc_un.res.ttls, 255, MAXMIFS); 894 memset(cache->mfc_un.res.ttls, 255, MAXMIFS);
612 895
613 for (vifi = 0; vifi < net->ipv6.maxvif; vifi++) { 896 for (vifi = 0; vifi < mrt->maxvif; vifi++) {
614 if (MIF_EXISTS(net, vifi) && 897 if (MIF_EXISTS(mrt, vifi) &&
615 ttls[vifi] && ttls[vifi] < 255) { 898 ttls[vifi] && ttls[vifi] < 255) {
616 cache->mfc_un.res.ttls[vifi] = ttls[vifi]; 899 cache->mfc_un.res.ttls[vifi] = ttls[vifi];
617 if (cache->mfc_un.res.minvif > vifi) 900 if (cache->mfc_un.res.minvif > vifi)
@@ -622,16 +905,17 @@ static void ip6mr_update_thresholds(struct mfc6_cache *cache, unsigned char *ttl
622 } 905 }
623} 906}
624 907
625static int mif6_add(struct net *net, struct mif6ctl *vifc, int mrtsock) 908static int mif6_add(struct net *net, struct mr6_table *mrt,
909 struct mif6ctl *vifc, int mrtsock)
626{ 910{
627 int vifi = vifc->mif6c_mifi; 911 int vifi = vifc->mif6c_mifi;
628 struct mif_device *v = &net->ipv6.vif6_table[vifi]; 912 struct mif_device *v = &mrt->vif6_table[vifi];
629 struct net_device *dev; 913 struct net_device *dev;
630 struct inet6_dev *in6_dev; 914 struct inet6_dev *in6_dev;
631 int err; 915 int err;
632 916
633 /* Is vif busy ? */ 917 /* Is vif busy ? */
634 if (MIF_EXISTS(net, vifi)) 918 if (MIF_EXISTS(mrt, vifi))
635 return -EADDRINUSE; 919 return -EADDRINUSE;
636 920
637 switch (vifc->mif6c_flags) { 921 switch (vifc->mif6c_flags) {
@@ -641,9 +925,9 @@ static int mif6_add(struct net *net, struct mif6ctl *vifc, int mrtsock)
641 * Special Purpose VIF in PIM 925 * Special Purpose VIF in PIM
642 * All the packets will be sent to the daemon 926 * All the packets will be sent to the daemon
643 */ 927 */
644 if (net->ipv6.mroute_reg_vif_num >= 0) 928 if (mrt->mroute_reg_vif_num >= 0)
645 return -EADDRINUSE; 929 return -EADDRINUSE;
646 dev = ip6mr_reg_vif(net); 930 dev = ip6mr_reg_vif(net, mrt);
647 if (!dev) 931 if (!dev)
648 return -ENOBUFS; 932 return -ENOBUFS;
649 err = dev_set_allmulti(dev, 1); 933 err = dev_set_allmulti(dev, 1);
@@ -693,50 +977,48 @@ static int mif6_add(struct net *net, struct mif6ctl *vifc, int mrtsock)
693 v->dev = dev; 977 v->dev = dev;
694#ifdef CONFIG_IPV6_PIMSM_V2 978#ifdef CONFIG_IPV6_PIMSM_V2
695 if (v->flags & MIFF_REGISTER) 979 if (v->flags & MIFF_REGISTER)
696 net->ipv6.mroute_reg_vif_num = vifi; 980 mrt->mroute_reg_vif_num = vifi;
697#endif 981#endif
698 if (vifi + 1 > net->ipv6.maxvif) 982 if (vifi + 1 > mrt->maxvif)
699 net->ipv6.maxvif = vifi + 1; 983 mrt->maxvif = vifi + 1;
700 write_unlock_bh(&mrt_lock); 984 write_unlock_bh(&mrt_lock);
701 return 0; 985 return 0;
702} 986}
703 987
704static struct mfc6_cache *ip6mr_cache_find(struct net *net, 988static struct mfc6_cache *ip6mr_cache_find(struct mr6_table *mrt,
705 struct in6_addr *origin, 989 struct in6_addr *origin,
706 struct in6_addr *mcastgrp) 990 struct in6_addr *mcastgrp)
707{ 991{
708 int line = MFC6_HASH(mcastgrp, origin); 992 int line = MFC6_HASH(mcastgrp, origin);
709 struct mfc6_cache *c; 993 struct mfc6_cache *c;
710 994
711 for (c = net->ipv6.mfc6_cache_array[line]; c; c = c->next) { 995 list_for_each_entry(c, &mrt->mfc6_cache_array[line], list) {
712 if (ipv6_addr_equal(&c->mf6c_origin, origin) && 996 if (ipv6_addr_equal(&c->mf6c_origin, origin) &&
713 ipv6_addr_equal(&c->mf6c_mcastgrp, mcastgrp)) 997 ipv6_addr_equal(&c->mf6c_mcastgrp, mcastgrp))
714 break; 998 return c;
715 } 999 }
716 return c; 1000 return NULL;
717} 1001}
718 1002
719/* 1003/*
720 * Allocate a multicast cache entry 1004 * Allocate a multicast cache entry
721 */ 1005 */
722static struct mfc6_cache *ip6mr_cache_alloc(struct net *net) 1006static struct mfc6_cache *ip6mr_cache_alloc(void)
723{ 1007{
724 struct mfc6_cache *c = kmem_cache_zalloc(mrt_cachep, GFP_KERNEL); 1008 struct mfc6_cache *c = kmem_cache_zalloc(mrt_cachep, GFP_KERNEL);
725 if (c == NULL) 1009 if (c == NULL)
726 return NULL; 1010 return NULL;
727 c->mfc_un.res.minvif = MAXMIFS; 1011 c->mfc_un.res.minvif = MAXMIFS;
728 mfc6_net_set(c, net);
729 return c; 1012 return c;
730} 1013}
731 1014
732static struct mfc6_cache *ip6mr_cache_alloc_unres(struct net *net) 1015static struct mfc6_cache *ip6mr_cache_alloc_unres(void)
733{ 1016{
734 struct mfc6_cache *c = kmem_cache_zalloc(mrt_cachep, GFP_ATOMIC); 1017 struct mfc6_cache *c = kmem_cache_zalloc(mrt_cachep, GFP_ATOMIC);
735 if (c == NULL) 1018 if (c == NULL)
736 return NULL; 1019 return NULL;
737 skb_queue_head_init(&c->mfc_un.unres.unresolved); 1020 skb_queue_head_init(&c->mfc_un.unres.unresolved);
738 c->mfc_un.unres.expires = jiffies + 10 * HZ; 1021 c->mfc_un.unres.expires = jiffies + 10 * HZ;
739 mfc6_net_set(c, net);
740 return c; 1022 return c;
741} 1023}
742 1024
@@ -744,7 +1026,8 @@ static struct mfc6_cache *ip6mr_cache_alloc_unres(struct net *net)
744 * A cache entry has gone into a resolved state from queued 1026 * A cache entry has gone into a resolved state from queued
745 */ 1027 */
746 1028
747static void ip6mr_cache_resolve(struct mfc6_cache *uc, struct mfc6_cache *c) 1029static void ip6mr_cache_resolve(struct net *net, struct mr6_table *mrt,
1030 struct mfc6_cache *uc, struct mfc6_cache *c)
748{ 1031{
749 struct sk_buff *skb; 1032 struct sk_buff *skb;
750 1033
@@ -757,7 +1040,7 @@ static void ip6mr_cache_resolve(struct mfc6_cache *uc, struct mfc6_cache *c)
757 int err; 1040 int err;
758 struct nlmsghdr *nlh = (struct nlmsghdr *)skb_pull(skb, sizeof(struct ipv6hdr)); 1041 struct nlmsghdr *nlh = (struct nlmsghdr *)skb_pull(skb, sizeof(struct ipv6hdr));
759 1042
760 if (ip6mr_fill_mroute(skb, c, NLMSG_DATA(nlh)) > 0) { 1043 if (__ip6mr_fill_mroute(mrt, skb, c, NLMSG_DATA(nlh)) > 0) {
761 nlh->nlmsg_len = skb_tail_pointer(skb) - (u8 *)nlh; 1044 nlh->nlmsg_len = skb_tail_pointer(skb) - (u8 *)nlh;
762 } else { 1045 } else {
763 nlh->nlmsg_type = NLMSG_ERROR; 1046 nlh->nlmsg_type = NLMSG_ERROR;
@@ -765,9 +1048,9 @@ static void ip6mr_cache_resolve(struct mfc6_cache *uc, struct mfc6_cache *c)
765 skb_trim(skb, nlh->nlmsg_len); 1048 skb_trim(skb, nlh->nlmsg_len);
766 ((struct nlmsgerr *)NLMSG_DATA(nlh))->error = -EMSGSIZE; 1049 ((struct nlmsgerr *)NLMSG_DATA(nlh))->error = -EMSGSIZE;
767 } 1050 }
768 err = rtnl_unicast(skb, mfc6_net(uc), NETLINK_CB(skb).pid); 1051 err = rtnl_unicast(skb, net, NETLINK_CB(skb).pid);
769 } else 1052 } else
770 ip6_mr_forward(skb, c); 1053 ip6_mr_forward(net, mrt, skb, c);
771 } 1054 }
772} 1055}
773 1056
@@ -778,8 +1061,8 @@ static void ip6mr_cache_resolve(struct mfc6_cache *uc, struct mfc6_cache *c)
778 * Called under mrt_lock. 1061 * Called under mrt_lock.
779 */ 1062 */
780 1063
781static int ip6mr_cache_report(struct net *net, struct sk_buff *pkt, mifi_t mifi, 1064static int ip6mr_cache_report(struct mr6_table *mrt, struct sk_buff *pkt,
782 int assert) 1065 mifi_t mifi, int assert)
783{ 1066{
784 struct sk_buff *skb; 1067 struct sk_buff *skb;
785 struct mrt6msg *msg; 1068 struct mrt6msg *msg;
@@ -815,7 +1098,7 @@ static int ip6mr_cache_report(struct net *net, struct sk_buff *pkt, mifi_t mifi,
815 msg = (struct mrt6msg *)skb_transport_header(skb); 1098 msg = (struct mrt6msg *)skb_transport_header(skb);
816 msg->im6_mbz = 0; 1099 msg->im6_mbz = 0;
817 msg->im6_msgtype = MRT6MSG_WHOLEPKT; 1100 msg->im6_msgtype = MRT6MSG_WHOLEPKT;
818 msg->im6_mif = net->ipv6.mroute_reg_vif_num; 1101 msg->im6_mif = mrt->mroute_reg_vif_num;
819 msg->im6_pad = 0; 1102 msg->im6_pad = 0;
820 ipv6_addr_copy(&msg->im6_src, &ipv6_hdr(pkt)->saddr); 1103 ipv6_addr_copy(&msg->im6_src, &ipv6_hdr(pkt)->saddr);
821 ipv6_addr_copy(&msg->im6_dst, &ipv6_hdr(pkt)->daddr); 1104 ipv6_addr_copy(&msg->im6_dst, &ipv6_hdr(pkt)->daddr);
@@ -850,7 +1133,7 @@ static int ip6mr_cache_report(struct net *net, struct sk_buff *pkt, mifi_t mifi,
850 skb->ip_summed = CHECKSUM_UNNECESSARY; 1133 skb->ip_summed = CHECKSUM_UNNECESSARY;
851 } 1134 }
852 1135
853 if (net->ipv6.mroute6_sk == NULL) { 1136 if (mrt->mroute6_sk == NULL) {
854 kfree_skb(skb); 1137 kfree_skb(skb);
855 return -EINVAL; 1138 return -EINVAL;
856 } 1139 }
@@ -858,7 +1141,7 @@ static int ip6mr_cache_report(struct net *net, struct sk_buff *pkt, mifi_t mifi,
858 /* 1141 /*
859 * Deliver to user space multicast routing algorithms 1142 * Deliver to user space multicast routing algorithms
860 */ 1143 */
861 ret = sock_queue_rcv_skb(net->ipv6.mroute6_sk, skb); 1144 ret = sock_queue_rcv_skb(mrt->mroute6_sk, skb);
862 if (ret < 0) { 1145 if (ret < 0) {
863 if (net_ratelimit()) 1146 if (net_ratelimit())
864 printk(KERN_WARNING "mroute6: pending queue full, dropping entries.\n"); 1147 printk(KERN_WARNING "mroute6: pending queue full, dropping entries.\n");
@@ -873,26 +1156,28 @@ static int ip6mr_cache_report(struct net *net, struct sk_buff *pkt, mifi_t mifi,
873 */ 1156 */
874 1157
875static int 1158static int
876ip6mr_cache_unresolved(struct net *net, mifi_t mifi, struct sk_buff *skb) 1159ip6mr_cache_unresolved(struct mr6_table *mrt, mifi_t mifi, struct sk_buff *skb)
877{ 1160{
1161 bool found = false;
878 int err; 1162 int err;
879 struct mfc6_cache *c; 1163 struct mfc6_cache *c;
880 1164
881 spin_lock_bh(&mfc_unres_lock); 1165 spin_lock_bh(&mfc_unres_lock);
882 for (c = mfc_unres_queue; c; c = c->next) { 1166 list_for_each_entry(c, &mrt->mfc6_unres_queue, list) {
883 if (net_eq(mfc6_net(c), net) && 1167 if (ipv6_addr_equal(&c->mf6c_mcastgrp, &ipv6_hdr(skb)->daddr) &&
884 ipv6_addr_equal(&c->mf6c_mcastgrp, &ipv6_hdr(skb)->daddr) && 1168 ipv6_addr_equal(&c->mf6c_origin, &ipv6_hdr(skb)->saddr)) {
885 ipv6_addr_equal(&c->mf6c_origin, &ipv6_hdr(skb)->saddr)) 1169 found = true;
886 break; 1170 break;
1171 }
887 } 1172 }
888 1173
889 if (c == NULL) { 1174 if (!found) {
890 /* 1175 /*
891 * Create a new entry if allowable 1176 * Create a new entry if allowable
892 */ 1177 */
893 1178
894 if (atomic_read(&net->ipv6.cache_resolve_queue_len) >= 10 || 1179 if (atomic_read(&mrt->cache_resolve_queue_len) >= 10 ||
895 (c = ip6mr_cache_alloc_unres(net)) == NULL) { 1180 (c = ip6mr_cache_alloc_unres()) == NULL) {
896 spin_unlock_bh(&mfc_unres_lock); 1181 spin_unlock_bh(&mfc_unres_lock);
897 1182
898 kfree_skb(skb); 1183 kfree_skb(skb);
@@ -909,7 +1194,7 @@ ip6mr_cache_unresolved(struct net *net, mifi_t mifi, struct sk_buff *skb)
909 /* 1194 /*
910 * Reflect first query at pim6sd 1195 * Reflect first query at pim6sd
911 */ 1196 */
912 err = ip6mr_cache_report(net, skb, mifi, MRT6MSG_NOCACHE); 1197 err = ip6mr_cache_report(mrt, skb, mifi, MRT6MSG_NOCACHE);
913 if (err < 0) { 1198 if (err < 0) {
914 /* If the report failed throw the cache entry 1199 /* If the report failed throw the cache entry
915 out - Brad Parker 1200 out - Brad Parker
@@ -921,11 +1206,10 @@ ip6mr_cache_unresolved(struct net *net, mifi_t mifi, struct sk_buff *skb)
921 return err; 1206 return err;
922 } 1207 }
923 1208
924 atomic_inc(&net->ipv6.cache_resolve_queue_len); 1209 atomic_inc(&mrt->cache_resolve_queue_len);
925 c->next = mfc_unres_queue; 1210 list_add(&c->list, &mrt->mfc6_unres_queue);
926 mfc_unres_queue = c;
927 1211
928 ipmr_do_expire_process(1); 1212 ipmr_do_expire_process(mrt);
929 } 1213 }
930 1214
931 /* 1215 /*
@@ -947,19 +1231,18 @@ ip6mr_cache_unresolved(struct net *net, mifi_t mifi, struct sk_buff *skb)
947 * MFC6 cache manipulation by user space 1231 * MFC6 cache manipulation by user space
948 */ 1232 */
949 1233
950static int ip6mr_mfc_delete(struct net *net, struct mf6cctl *mfc) 1234static int ip6mr_mfc_delete(struct mr6_table *mrt, struct mf6cctl *mfc)
951{ 1235{
952 int line; 1236 int line;
953 struct mfc6_cache *c, **cp; 1237 struct mfc6_cache *c, *next;
954 1238
955 line = MFC6_HASH(&mfc->mf6cc_mcastgrp.sin6_addr, &mfc->mf6cc_origin.sin6_addr); 1239 line = MFC6_HASH(&mfc->mf6cc_mcastgrp.sin6_addr, &mfc->mf6cc_origin.sin6_addr);
956 1240
957 for (cp = &net->ipv6.mfc6_cache_array[line]; 1241 list_for_each_entry_safe(c, next, &mrt->mfc6_cache_array[line], list) {
958 (c = *cp) != NULL; cp = &c->next) {
959 if (ipv6_addr_equal(&c->mf6c_origin, &mfc->mf6cc_origin.sin6_addr) && 1242 if (ipv6_addr_equal(&c->mf6c_origin, &mfc->mf6cc_origin.sin6_addr) &&
960 ipv6_addr_equal(&c->mf6c_mcastgrp, &mfc->mf6cc_mcastgrp.sin6_addr)) { 1243 ipv6_addr_equal(&c->mf6c_mcastgrp, &mfc->mf6cc_mcastgrp.sin6_addr)) {
961 write_lock_bh(&mrt_lock); 1244 write_lock_bh(&mrt_lock);
962 *cp = c->next; 1245 list_del(&c->list);
963 write_unlock_bh(&mrt_lock); 1246 write_unlock_bh(&mrt_lock);
964 1247
965 ip6mr_cache_free(c); 1248 ip6mr_cache_free(c);
@@ -974,6 +1257,7 @@ static int ip6mr_device_event(struct notifier_block *this,
974{ 1257{
975 struct net_device *dev = ptr; 1258 struct net_device *dev = ptr;
976 struct net *net = dev_net(dev); 1259 struct net *net = dev_net(dev);
1260 struct mr6_table *mrt;
977 struct mif_device *v; 1261 struct mif_device *v;
978 int ct; 1262 int ct;
979 LIST_HEAD(list); 1263 LIST_HEAD(list);
@@ -981,10 +1265,12 @@ static int ip6mr_device_event(struct notifier_block *this,
981 if (event != NETDEV_UNREGISTER) 1265 if (event != NETDEV_UNREGISTER)
982 return NOTIFY_DONE; 1266 return NOTIFY_DONE;
983 1267
984 v = &net->ipv6.vif6_table[0]; 1268 ip6mr_for_each_table(mrt, net) {
985 for (ct = 0; ct < net->ipv6.maxvif; ct++, v++) { 1269 v = &mrt->vif6_table[0];
986 if (v->dev == dev) 1270 for (ct = 0; ct < mrt->maxvif; ct++, v++) {
987 mif6_delete(net, ct, &list); 1271 if (v->dev == dev)
1272 mif6_delete(mrt, ct, &list);
1273 }
988 } 1274 }
989 unregister_netdevice_many(&list); 1275 unregister_netdevice_many(&list);
990 1276
@@ -1001,26 +1287,11 @@ static struct notifier_block ip6_mr_notifier = {
1001 1287
1002static int __net_init ip6mr_net_init(struct net *net) 1288static int __net_init ip6mr_net_init(struct net *net)
1003{ 1289{
1004 int err = 0; 1290 int err;
1005 net->ipv6.vif6_table = kcalloc(MAXMIFS, sizeof(struct mif_device),
1006 GFP_KERNEL);
1007 if (!net->ipv6.vif6_table) {
1008 err = -ENOMEM;
1009 goto fail;
1010 }
1011
1012 /* Forwarding cache */
1013 net->ipv6.mfc6_cache_array = kcalloc(MFC6_LINES,
1014 sizeof(struct mfc6_cache *),
1015 GFP_KERNEL);
1016 if (!net->ipv6.mfc6_cache_array) {
1017 err = -ENOMEM;
1018 goto fail_mfc6_cache;
1019 }
1020 1291
1021#ifdef CONFIG_IPV6_PIMSM_V2 1292 err = ip6mr_rules_init(net);
1022 net->ipv6.mroute_reg_vif_num = -1; 1293 if (err < 0)
1023#endif 1294 goto fail;
1024 1295
1025#ifdef CONFIG_PROC_FS 1296#ifdef CONFIG_PROC_FS
1026 err = -ENOMEM; 1297 err = -ENOMEM;
@@ -1029,16 +1300,15 @@ static int __net_init ip6mr_net_init(struct net *net)
1029 if (!proc_net_fops_create(net, "ip6_mr_cache", 0, &ip6mr_mfc_fops)) 1300 if (!proc_net_fops_create(net, "ip6_mr_cache", 0, &ip6mr_mfc_fops))
1030 goto proc_cache_fail; 1301 goto proc_cache_fail;
1031#endif 1302#endif
1303
1032 return 0; 1304 return 0;
1033 1305
1034#ifdef CONFIG_PROC_FS 1306#ifdef CONFIG_PROC_FS
1035proc_cache_fail: 1307proc_cache_fail:
1036 proc_net_remove(net, "ip6_mr_vif"); 1308 proc_net_remove(net, "ip6_mr_vif");
1037proc_vif_fail: 1309proc_vif_fail:
1038 kfree(net->ipv6.mfc6_cache_array); 1310 ip6mr_rules_exit(net);
1039#endif 1311#endif
1040fail_mfc6_cache:
1041 kfree(net->ipv6.vif6_table);
1042fail: 1312fail:
1043 return err; 1313 return err;
1044} 1314}
@@ -1049,9 +1319,7 @@ static void __net_exit ip6mr_net_exit(struct net *net)
1049 proc_net_remove(net, "ip6_mr_cache"); 1319 proc_net_remove(net, "ip6_mr_cache");
1050 proc_net_remove(net, "ip6_mr_vif"); 1320 proc_net_remove(net, "ip6_mr_vif");
1051#endif 1321#endif
1052 mroute_clean_tables(net); 1322 ip6mr_rules_exit(net);
1053 kfree(net->ipv6.mfc6_cache_array);
1054 kfree(net->ipv6.vif6_table);
1055} 1323}
1056 1324
1057static struct pernet_operations ip6mr_net_ops = { 1325static struct pernet_operations ip6mr_net_ops = {
@@ -1074,7 +1342,6 @@ int __init ip6_mr_init(void)
1074 if (err) 1342 if (err)
1075 goto reg_pernet_fail; 1343 goto reg_pernet_fail;
1076 1344
1077 setup_timer(&ipmr_expire_timer, ipmr_expire_process, 0);
1078 err = register_netdevice_notifier(&ip6_mr_notifier); 1345 err = register_netdevice_notifier(&ip6_mr_notifier);
1079 if (err) 1346 if (err)
1080 goto reg_notif_fail; 1347 goto reg_notif_fail;
@@ -1085,13 +1352,13 @@ int __init ip6_mr_init(void)
1085 goto add_proto_fail; 1352 goto add_proto_fail;
1086 } 1353 }
1087#endif 1354#endif
1355 rtnl_register(RTNL_FAMILY_IP6MR, RTM_GETROUTE, NULL, ip6mr_rtm_dumproute);
1088 return 0; 1356 return 0;
1089#ifdef CONFIG_IPV6_PIMSM_V2 1357#ifdef CONFIG_IPV6_PIMSM_V2
1090add_proto_fail: 1358add_proto_fail:
1091 unregister_netdevice_notifier(&ip6_mr_notifier); 1359 unregister_netdevice_notifier(&ip6_mr_notifier);
1092#endif 1360#endif
1093reg_notif_fail: 1361reg_notif_fail:
1094 del_timer(&ipmr_expire_timer);
1095 unregister_pernet_subsys(&ip6mr_net_ops); 1362 unregister_pernet_subsys(&ip6mr_net_ops);
1096reg_pernet_fail: 1363reg_pernet_fail:
1097 kmem_cache_destroy(mrt_cachep); 1364 kmem_cache_destroy(mrt_cachep);
@@ -1101,18 +1368,22 @@ reg_pernet_fail:
1101void ip6_mr_cleanup(void) 1368void ip6_mr_cleanup(void)
1102{ 1369{
1103 unregister_netdevice_notifier(&ip6_mr_notifier); 1370 unregister_netdevice_notifier(&ip6_mr_notifier);
1104 del_timer(&ipmr_expire_timer);
1105 unregister_pernet_subsys(&ip6mr_net_ops); 1371 unregister_pernet_subsys(&ip6mr_net_ops);
1106 kmem_cache_destroy(mrt_cachep); 1372 kmem_cache_destroy(mrt_cachep);
1107} 1373}
1108 1374
1109static int ip6mr_mfc_add(struct net *net, struct mf6cctl *mfc, int mrtsock) 1375static int ip6mr_mfc_add(struct net *net, struct mr6_table *mrt,
1376 struct mf6cctl *mfc, int mrtsock)
1110{ 1377{
1378 bool found = false;
1111 int line; 1379 int line;
1112 struct mfc6_cache *uc, *c, **cp; 1380 struct mfc6_cache *uc, *c;
1113 unsigned char ttls[MAXMIFS]; 1381 unsigned char ttls[MAXMIFS];
1114 int i; 1382 int i;
1115 1383
1384 if (mfc->mf6cc_parent >= MAXMIFS)
1385 return -ENFILE;
1386
1116 memset(ttls, 255, MAXMIFS); 1387 memset(ttls, 255, MAXMIFS);
1117 for (i = 0; i < MAXMIFS; i++) { 1388 for (i = 0; i < MAXMIFS; i++) {
1118 if (IF_ISSET(i, &mfc->mf6cc_ifset)) 1389 if (IF_ISSET(i, &mfc->mf6cc_ifset))
@@ -1122,17 +1393,18 @@ static int ip6mr_mfc_add(struct net *net, struct mf6cctl *mfc, int mrtsock)
1122 1393
1123 line = MFC6_HASH(&mfc->mf6cc_mcastgrp.sin6_addr, &mfc->mf6cc_origin.sin6_addr); 1394 line = MFC6_HASH(&mfc->mf6cc_mcastgrp.sin6_addr, &mfc->mf6cc_origin.sin6_addr);
1124 1395
1125 for (cp = &net->ipv6.mfc6_cache_array[line]; 1396 list_for_each_entry(c, &mrt->mfc6_cache_array[line], list) {
1126 (c = *cp) != NULL; cp = &c->next) {
1127 if (ipv6_addr_equal(&c->mf6c_origin, &mfc->mf6cc_origin.sin6_addr) && 1397 if (ipv6_addr_equal(&c->mf6c_origin, &mfc->mf6cc_origin.sin6_addr) &&
1128 ipv6_addr_equal(&c->mf6c_mcastgrp, &mfc->mf6cc_mcastgrp.sin6_addr)) 1398 ipv6_addr_equal(&c->mf6c_mcastgrp, &mfc->mf6cc_mcastgrp.sin6_addr)) {
1399 found = true;
1129 break; 1400 break;
1401 }
1130 } 1402 }
1131 1403
1132 if (c != NULL) { 1404 if (found) {
1133 write_lock_bh(&mrt_lock); 1405 write_lock_bh(&mrt_lock);
1134 c->mf6c_parent = mfc->mf6cc_parent; 1406 c->mf6c_parent = mfc->mf6cc_parent;
1135 ip6mr_update_thresholds(c, ttls); 1407 ip6mr_update_thresholds(mrt, c, ttls);
1136 if (!mrtsock) 1408 if (!mrtsock)
1137 c->mfc_flags |= MFC_STATIC; 1409 c->mfc_flags |= MFC_STATIC;
1138 write_unlock_bh(&mrt_lock); 1410 write_unlock_bh(&mrt_lock);
@@ -1142,43 +1414,42 @@ static int ip6mr_mfc_add(struct net *net, struct mf6cctl *mfc, int mrtsock)
1142 if (!ipv6_addr_is_multicast(&mfc->mf6cc_mcastgrp.sin6_addr)) 1414 if (!ipv6_addr_is_multicast(&mfc->mf6cc_mcastgrp.sin6_addr))
1143 return -EINVAL; 1415 return -EINVAL;
1144 1416
1145 c = ip6mr_cache_alloc(net); 1417 c = ip6mr_cache_alloc();
1146 if (c == NULL) 1418 if (c == NULL)
1147 return -ENOMEM; 1419 return -ENOMEM;
1148 1420
1149 c->mf6c_origin = mfc->mf6cc_origin.sin6_addr; 1421 c->mf6c_origin = mfc->mf6cc_origin.sin6_addr;
1150 c->mf6c_mcastgrp = mfc->mf6cc_mcastgrp.sin6_addr; 1422 c->mf6c_mcastgrp = mfc->mf6cc_mcastgrp.sin6_addr;
1151 c->mf6c_parent = mfc->mf6cc_parent; 1423 c->mf6c_parent = mfc->mf6cc_parent;
1152 ip6mr_update_thresholds(c, ttls); 1424 ip6mr_update_thresholds(mrt, c, ttls);
1153 if (!mrtsock) 1425 if (!mrtsock)
1154 c->mfc_flags |= MFC_STATIC; 1426 c->mfc_flags |= MFC_STATIC;
1155 1427
1156 write_lock_bh(&mrt_lock); 1428 write_lock_bh(&mrt_lock);
1157 c->next = net->ipv6.mfc6_cache_array[line]; 1429 list_add(&c->list, &mrt->mfc6_cache_array[line]);
1158 net->ipv6.mfc6_cache_array[line] = c;
1159 write_unlock_bh(&mrt_lock); 1430 write_unlock_bh(&mrt_lock);
1160 1431
1161 /* 1432 /*
1162 * Check to see if we resolved a queued list. If so we 1433 * Check to see if we resolved a queued list. If so we
1163 * need to send on the frames and tidy up. 1434 * need to send on the frames and tidy up.
1164 */ 1435 */
1436 found = false;
1165 spin_lock_bh(&mfc_unres_lock); 1437 spin_lock_bh(&mfc_unres_lock);
1166 for (cp = &mfc_unres_queue; (uc = *cp) != NULL; 1438 list_for_each_entry(uc, &mrt->mfc6_unres_queue, list) {
1167 cp = &uc->next) { 1439 if (ipv6_addr_equal(&uc->mf6c_origin, &c->mf6c_origin) &&
1168 if (net_eq(mfc6_net(uc), net) &&
1169 ipv6_addr_equal(&uc->mf6c_origin, &c->mf6c_origin) &&
1170 ipv6_addr_equal(&uc->mf6c_mcastgrp, &c->mf6c_mcastgrp)) { 1440 ipv6_addr_equal(&uc->mf6c_mcastgrp, &c->mf6c_mcastgrp)) {
1171 *cp = uc->next; 1441 list_del(&uc->list);
1172 atomic_dec(&net->ipv6.cache_resolve_queue_len); 1442 atomic_dec(&mrt->cache_resolve_queue_len);
1443 found = true;
1173 break; 1444 break;
1174 } 1445 }
1175 } 1446 }
1176 if (mfc_unres_queue == NULL) 1447 if (list_empty(&mrt->mfc6_unres_queue))
1177 del_timer(&ipmr_expire_timer); 1448 del_timer(&mrt->ipmr_expire_timer);
1178 spin_unlock_bh(&mfc_unres_lock); 1449 spin_unlock_bh(&mfc_unres_lock);
1179 1450
1180 if (uc) { 1451 if (found) {
1181 ip6mr_cache_resolve(uc, c); 1452 ip6mr_cache_resolve(net, mrt, uc, c);
1182 ip6mr_cache_free(uc); 1453 ip6mr_cache_free(uc);
1183 } 1454 }
1184 return 0; 1455 return 0;
@@ -1188,17 +1459,18 @@ static int ip6mr_mfc_add(struct net *net, struct mf6cctl *mfc, int mrtsock)
1188 * Close the multicast socket, and clear the vif tables etc 1459 * Close the multicast socket, and clear the vif tables etc
1189 */ 1460 */
1190 1461
1191static void mroute_clean_tables(struct net *net) 1462static void mroute_clean_tables(struct mr6_table *mrt)
1192{ 1463{
1193 int i; 1464 int i;
1194 LIST_HEAD(list); 1465 LIST_HEAD(list);
1466 struct mfc6_cache *c, *next;
1195 1467
1196 /* 1468 /*
1197 * Shut down all active vif entries 1469 * Shut down all active vif entries
1198 */ 1470 */
1199 for (i = 0; i < net->ipv6.maxvif; i++) { 1471 for (i = 0; i < mrt->maxvif; i++) {
1200 if (!(net->ipv6.vif6_table[i].flags & VIFF_STATIC)) 1472 if (!(mrt->vif6_table[i].flags & VIFF_STATIC))
1201 mif6_delete(net, i, &list); 1473 mif6_delete(mrt, i, &list);
1202 } 1474 }
1203 unregister_netdevice_many(&list); 1475 unregister_netdevice_many(&list);
1204 1476
@@ -1206,48 +1478,36 @@ static void mroute_clean_tables(struct net *net)
1206 * Wipe the cache 1478 * Wipe the cache
1207 */ 1479 */
1208 for (i = 0; i < MFC6_LINES; i++) { 1480 for (i = 0; i < MFC6_LINES; i++) {
1209 struct mfc6_cache *c, **cp; 1481 list_for_each_entry_safe(c, next, &mrt->mfc6_cache_array[i], list) {
1210 1482 if (c->mfc_flags & MFC_STATIC)
1211 cp = &net->ipv6.mfc6_cache_array[i];
1212 while ((c = *cp) != NULL) {
1213 if (c->mfc_flags & MFC_STATIC) {
1214 cp = &c->next;
1215 continue; 1483 continue;
1216 }
1217 write_lock_bh(&mrt_lock); 1484 write_lock_bh(&mrt_lock);
1218 *cp = c->next; 1485 list_del(&c->list);
1219 write_unlock_bh(&mrt_lock); 1486 write_unlock_bh(&mrt_lock);
1220 1487
1221 ip6mr_cache_free(c); 1488 ip6mr_cache_free(c);
1222 } 1489 }
1223 } 1490 }
1224 1491
1225 if (atomic_read(&net->ipv6.cache_resolve_queue_len) != 0) { 1492 if (atomic_read(&mrt->cache_resolve_queue_len) != 0) {
1226 struct mfc6_cache *c, **cp;
1227
1228 spin_lock_bh(&mfc_unres_lock); 1493 spin_lock_bh(&mfc_unres_lock);
1229 cp = &mfc_unres_queue; 1494 list_for_each_entry_safe(c, next, &mrt->mfc6_unres_queue, list) {
1230 while ((c = *cp) != NULL) { 1495 list_del(&c->list);
1231 if (!net_eq(mfc6_net(c), net)) { 1496 ip6mr_destroy_unres(mrt, c);
1232 cp = &c->next;
1233 continue;
1234 }
1235 *cp = c->next;
1236 ip6mr_destroy_unres(c);
1237 } 1497 }
1238 spin_unlock_bh(&mfc_unres_lock); 1498 spin_unlock_bh(&mfc_unres_lock);
1239 } 1499 }
1240} 1500}
1241 1501
1242static int ip6mr_sk_init(struct sock *sk) 1502static int ip6mr_sk_init(struct mr6_table *mrt, struct sock *sk)
1243{ 1503{
1244 int err = 0; 1504 int err = 0;
1245 struct net *net = sock_net(sk); 1505 struct net *net = sock_net(sk);
1246 1506
1247 rtnl_lock(); 1507 rtnl_lock();
1248 write_lock_bh(&mrt_lock); 1508 write_lock_bh(&mrt_lock);
1249 if (likely(net->ipv6.mroute6_sk == NULL)) { 1509 if (likely(mrt->mroute6_sk == NULL)) {
1250 net->ipv6.mroute6_sk = sk; 1510 mrt->mroute6_sk = sk;
1251 net->ipv6.devconf_all->mc_forwarding++; 1511 net->ipv6.devconf_all->mc_forwarding++;
1252 } 1512 }
1253 else 1513 else
@@ -1261,24 +1521,43 @@ static int ip6mr_sk_init(struct sock *sk)
1261 1521
1262int ip6mr_sk_done(struct sock *sk) 1522int ip6mr_sk_done(struct sock *sk)
1263{ 1523{
1264 int err = 0; 1524 int err = -EACCES;
1265 struct net *net = sock_net(sk); 1525 struct net *net = sock_net(sk);
1526 struct mr6_table *mrt;
1266 1527
1267 rtnl_lock(); 1528 rtnl_lock();
1268 if (sk == net->ipv6.mroute6_sk) { 1529 ip6mr_for_each_table(mrt, net) {
1269 write_lock_bh(&mrt_lock); 1530 if (sk == mrt->mroute6_sk) {
1270 net->ipv6.mroute6_sk = NULL; 1531 write_lock_bh(&mrt_lock);
1271 net->ipv6.devconf_all->mc_forwarding--; 1532 mrt->mroute6_sk = NULL;
1272 write_unlock_bh(&mrt_lock); 1533 net->ipv6.devconf_all->mc_forwarding--;
1534 write_unlock_bh(&mrt_lock);
1273 1535
1274 mroute_clean_tables(net); 1536 mroute_clean_tables(mrt);
1275 } else 1537 err = 0;
1276 err = -EACCES; 1538 break;
1539 }
1540 }
1277 rtnl_unlock(); 1541 rtnl_unlock();
1278 1542
1279 return err; 1543 return err;
1280} 1544}
1281 1545
1546struct sock *mroute6_socket(struct net *net, struct sk_buff *skb)
1547{
1548 struct mr6_table *mrt;
1549 struct flowi fl = {
1550 .iif = skb->skb_iif,
1551 .oif = skb->dev->ifindex,
1552 .mark = skb->mark,
1553 };
1554
1555 if (ip6mr_fib_lookup(net, &fl, &mrt) < 0)
1556 return NULL;
1557
1558 return mrt->mroute6_sk;
1559}
1560
1282/* 1561/*
1283 * Socket options and virtual interface manipulation. The whole 1562 * Socket options and virtual interface manipulation. The whole
1284 * virtual interface system is a complete heap, but unfortunately 1563 * virtual interface system is a complete heap, but unfortunately
@@ -1293,9 +1572,14 @@ int ip6_mroute_setsockopt(struct sock *sk, int optname, char __user *optval, uns
1293 struct mf6cctl mfc; 1572 struct mf6cctl mfc;
1294 mifi_t mifi; 1573 mifi_t mifi;
1295 struct net *net = sock_net(sk); 1574 struct net *net = sock_net(sk);
1575 struct mr6_table *mrt;
1576
1577 mrt = ip6mr_get_table(net, raw6_sk(sk)->ip6mr_table ? : RT6_TABLE_DFLT);
1578 if (mrt == NULL)
1579 return -ENOENT;
1296 1580
1297 if (optname != MRT6_INIT) { 1581 if (optname != MRT6_INIT) {
1298 if (sk != net->ipv6.mroute6_sk && !capable(CAP_NET_ADMIN)) 1582 if (sk != mrt->mroute6_sk && !capable(CAP_NET_ADMIN))
1299 return -EACCES; 1583 return -EACCES;
1300 } 1584 }
1301 1585
@@ -1307,7 +1591,7 @@ int ip6_mroute_setsockopt(struct sock *sk, int optname, char __user *optval, uns
1307 if (optlen < sizeof(int)) 1591 if (optlen < sizeof(int))
1308 return -EINVAL; 1592 return -EINVAL;
1309 1593
1310 return ip6mr_sk_init(sk); 1594 return ip6mr_sk_init(mrt, sk);
1311 1595
1312 case MRT6_DONE: 1596 case MRT6_DONE:
1313 return ip6mr_sk_done(sk); 1597 return ip6mr_sk_done(sk);
@@ -1320,7 +1604,7 @@ int ip6_mroute_setsockopt(struct sock *sk, int optname, char __user *optval, uns
1320 if (vif.mif6c_mifi >= MAXMIFS) 1604 if (vif.mif6c_mifi >= MAXMIFS)
1321 return -ENFILE; 1605 return -ENFILE;
1322 rtnl_lock(); 1606 rtnl_lock();
1323 ret = mif6_add(net, &vif, sk == net->ipv6.mroute6_sk); 1607 ret = mif6_add(net, mrt, &vif, sk == mrt->mroute6_sk);
1324 rtnl_unlock(); 1608 rtnl_unlock();
1325 return ret; 1609 return ret;
1326 1610
@@ -1330,7 +1614,7 @@ int ip6_mroute_setsockopt(struct sock *sk, int optname, char __user *optval, uns
1330 if (copy_from_user(&mifi, optval, sizeof(mifi_t))) 1614 if (copy_from_user(&mifi, optval, sizeof(mifi_t)))
1331 return -EFAULT; 1615 return -EFAULT;
1332 rtnl_lock(); 1616 rtnl_lock();
1333 ret = mif6_delete(net, mifi, NULL); 1617 ret = mif6_delete(mrt, mifi, NULL);
1334 rtnl_unlock(); 1618 rtnl_unlock();
1335 return ret; 1619 return ret;
1336 1620
@@ -1346,10 +1630,9 @@ int ip6_mroute_setsockopt(struct sock *sk, int optname, char __user *optval, uns
1346 return -EFAULT; 1630 return -EFAULT;
1347 rtnl_lock(); 1631 rtnl_lock();
1348 if (optname == MRT6_DEL_MFC) 1632 if (optname == MRT6_DEL_MFC)
1349 ret = ip6mr_mfc_delete(net, &mfc); 1633 ret = ip6mr_mfc_delete(mrt, &mfc);
1350 else 1634 else
1351 ret = ip6mr_mfc_add(net, &mfc, 1635 ret = ip6mr_mfc_add(net, mrt, &mfc, sk == mrt->mroute6_sk);
1352 sk == net->ipv6.mroute6_sk);
1353 rtnl_unlock(); 1636 rtnl_unlock();
1354 return ret; 1637 return ret;
1355 1638
@@ -1361,7 +1644,7 @@ int ip6_mroute_setsockopt(struct sock *sk, int optname, char __user *optval, uns
1361 int v; 1644 int v;
1362 if (get_user(v, (int __user *)optval)) 1645 if (get_user(v, (int __user *)optval))
1363 return -EFAULT; 1646 return -EFAULT;
1364 net->ipv6.mroute_do_assert = !!v; 1647 mrt->mroute_do_assert = !!v;
1365 return 0; 1648 return 0;
1366 } 1649 }
1367 1650
@@ -1374,15 +1657,36 @@ int ip6_mroute_setsockopt(struct sock *sk, int optname, char __user *optval, uns
1374 v = !!v; 1657 v = !!v;
1375 rtnl_lock(); 1658 rtnl_lock();
1376 ret = 0; 1659 ret = 0;
1377 if (v != net->ipv6.mroute_do_pim) { 1660 if (v != mrt->mroute_do_pim) {
1378 net->ipv6.mroute_do_pim = v; 1661 mrt->mroute_do_pim = v;
1379 net->ipv6.mroute_do_assert = v; 1662 mrt->mroute_do_assert = v;
1380 } 1663 }
1381 rtnl_unlock(); 1664 rtnl_unlock();
1382 return ret; 1665 return ret;
1383 } 1666 }
1384 1667
1385#endif 1668#endif
1669#ifdef CONFIG_IPV6_MROUTE_MULTIPLE_TABLES
1670 case MRT6_TABLE:
1671 {
1672 u32 v;
1673
1674 if (optlen != sizeof(u32))
1675 return -EINVAL;
1676 if (get_user(v, (u32 __user *)optval))
1677 return -EFAULT;
1678 if (sk == mrt->mroute6_sk)
1679 return -EBUSY;
1680
1681 rtnl_lock();
1682 ret = 0;
1683 if (!ip6mr_new_table(net, v))
1684 ret = -ENOMEM;
1685 raw6_sk(sk)->ip6mr_table = v;
1686 rtnl_unlock();
1687 return ret;
1688 }
1689#endif
1386 /* 1690 /*
1387 * Spurious command, or MRT6_VERSION which you cannot 1691 * Spurious command, or MRT6_VERSION which you cannot
1388 * set. 1692 * set.
@@ -1402,6 +1706,11 @@ int ip6_mroute_getsockopt(struct sock *sk, int optname, char __user *optval,
1402 int olr; 1706 int olr;
1403 int val; 1707 int val;
1404 struct net *net = sock_net(sk); 1708 struct net *net = sock_net(sk);
1709 struct mr6_table *mrt;
1710
1711 mrt = ip6mr_get_table(net, raw6_sk(sk)->ip6mr_table ? : RT6_TABLE_DFLT);
1712 if (mrt == NULL)
1713 return -ENOENT;
1405 1714
1406 switch (optname) { 1715 switch (optname) {
1407 case MRT6_VERSION: 1716 case MRT6_VERSION:
@@ -1409,11 +1718,11 @@ int ip6_mroute_getsockopt(struct sock *sk, int optname, char __user *optval,
1409 break; 1718 break;
1410#ifdef CONFIG_IPV6_PIMSM_V2 1719#ifdef CONFIG_IPV6_PIMSM_V2
1411 case MRT6_PIM: 1720 case MRT6_PIM:
1412 val = net->ipv6.mroute_do_pim; 1721 val = mrt->mroute_do_pim;
1413 break; 1722 break;
1414#endif 1723#endif
1415 case MRT6_ASSERT: 1724 case MRT6_ASSERT:
1416 val = net->ipv6.mroute_do_assert; 1725 val = mrt->mroute_do_assert;
1417 break; 1726 break;
1418 default: 1727 default:
1419 return -ENOPROTOOPT; 1728 return -ENOPROTOOPT;
@@ -1444,16 +1753,21 @@ int ip6mr_ioctl(struct sock *sk, int cmd, void __user *arg)
1444 struct mif_device *vif; 1753 struct mif_device *vif;
1445 struct mfc6_cache *c; 1754 struct mfc6_cache *c;
1446 struct net *net = sock_net(sk); 1755 struct net *net = sock_net(sk);
1756 struct mr6_table *mrt;
1757
1758 mrt = ip6mr_get_table(net, raw6_sk(sk)->ip6mr_table ? : RT6_TABLE_DFLT);
1759 if (mrt == NULL)
1760 return -ENOENT;
1447 1761
1448 switch (cmd) { 1762 switch (cmd) {
1449 case SIOCGETMIFCNT_IN6: 1763 case SIOCGETMIFCNT_IN6:
1450 if (copy_from_user(&vr, arg, sizeof(vr))) 1764 if (copy_from_user(&vr, arg, sizeof(vr)))
1451 return -EFAULT; 1765 return -EFAULT;
1452 if (vr.mifi >= net->ipv6.maxvif) 1766 if (vr.mifi >= mrt->maxvif)
1453 return -EINVAL; 1767 return -EINVAL;
1454 read_lock(&mrt_lock); 1768 read_lock(&mrt_lock);
1455 vif = &net->ipv6.vif6_table[vr.mifi]; 1769 vif = &mrt->vif6_table[vr.mifi];
1456 if (MIF_EXISTS(net, vr.mifi)) { 1770 if (MIF_EXISTS(mrt, vr.mifi)) {
1457 vr.icount = vif->pkt_in; 1771 vr.icount = vif->pkt_in;
1458 vr.ocount = vif->pkt_out; 1772 vr.ocount = vif->pkt_out;
1459 vr.ibytes = vif->bytes_in; 1773 vr.ibytes = vif->bytes_in;
@@ -1471,7 +1785,7 @@ int ip6mr_ioctl(struct sock *sk, int cmd, void __user *arg)
1471 return -EFAULT; 1785 return -EFAULT;
1472 1786
1473 read_lock(&mrt_lock); 1787 read_lock(&mrt_lock);
1474 c = ip6mr_cache_find(net, &sr.src.sin6_addr, &sr.grp.sin6_addr); 1788 c = ip6mr_cache_find(mrt, &sr.src.sin6_addr, &sr.grp.sin6_addr);
1475 if (c) { 1789 if (c) {
1476 sr.pktcnt = c->mfc_un.res.pkt; 1790 sr.pktcnt = c->mfc_un.res.pkt;
1477 sr.bytecnt = c->mfc_un.res.bytes; 1791 sr.bytecnt = c->mfc_un.res.bytes;
@@ -1501,11 +1815,11 @@ static inline int ip6mr_forward2_finish(struct sk_buff *skb)
1501 * Processing handlers for ip6mr_forward 1815 * Processing handlers for ip6mr_forward
1502 */ 1816 */
1503 1817
1504static int ip6mr_forward2(struct sk_buff *skb, struct mfc6_cache *c, int vifi) 1818static int ip6mr_forward2(struct net *net, struct mr6_table *mrt,
1819 struct sk_buff *skb, struct mfc6_cache *c, int vifi)
1505{ 1820{
1506 struct ipv6hdr *ipv6h; 1821 struct ipv6hdr *ipv6h;
1507 struct net *net = mfc6_net(c); 1822 struct mif_device *vif = &mrt->vif6_table[vifi];
1508 struct mif_device *vif = &net->ipv6.vif6_table[vifi];
1509 struct net_device *dev; 1823 struct net_device *dev;
1510 struct dst_entry *dst; 1824 struct dst_entry *dst;
1511 struct flowi fl; 1825 struct flowi fl;
@@ -1519,7 +1833,7 @@ static int ip6mr_forward2(struct sk_buff *skb, struct mfc6_cache *c, int vifi)
1519 vif->bytes_out += skb->len; 1833 vif->bytes_out += skb->len;
1520 vif->dev->stats.tx_bytes += skb->len; 1834 vif->dev->stats.tx_bytes += skb->len;
1521 vif->dev->stats.tx_packets++; 1835 vif->dev->stats.tx_packets++;
1522 ip6mr_cache_report(net, skb, vifi, MRT6MSG_WHOLEPKT); 1836 ip6mr_cache_report(mrt, skb, vifi, MRT6MSG_WHOLEPKT);
1523 goto out_free; 1837 goto out_free;
1524 } 1838 }
1525#endif 1839#endif
@@ -1566,7 +1880,7 @@ static int ip6mr_forward2(struct sk_buff *skb, struct mfc6_cache *c, int vifi)
1566 1880
1567 IP6CB(skb)->flags |= IP6SKB_FORWARDED; 1881 IP6CB(skb)->flags |= IP6SKB_FORWARDED;
1568 1882
1569 return NF_HOOK(PF_INET6, NF_INET_FORWARD, skb, skb->dev, dev, 1883 return NF_HOOK(NFPROTO_IPV6, NF_INET_FORWARD, skb, skb->dev, dev,
1570 ip6mr_forward2_finish); 1884 ip6mr_forward2_finish);
1571 1885
1572out_free: 1886out_free:
@@ -1574,22 +1888,22 @@ out_free:
1574 return 0; 1888 return 0;
1575} 1889}
1576 1890
1577static int ip6mr_find_vif(struct net_device *dev) 1891static int ip6mr_find_vif(struct mr6_table *mrt, struct net_device *dev)
1578{ 1892{
1579 struct net *net = dev_net(dev);
1580 int ct; 1893 int ct;
1581 for (ct = net->ipv6.maxvif - 1; ct >= 0; ct--) { 1894
1582 if (net->ipv6.vif6_table[ct].dev == dev) 1895 for (ct = mrt->maxvif - 1; ct >= 0; ct--) {
1896 if (mrt->vif6_table[ct].dev == dev)
1583 break; 1897 break;
1584 } 1898 }
1585 return ct; 1899 return ct;
1586} 1900}
1587 1901
1588static int ip6_mr_forward(struct sk_buff *skb, struct mfc6_cache *cache) 1902static int ip6_mr_forward(struct net *net, struct mr6_table *mrt,
1903 struct sk_buff *skb, struct mfc6_cache *cache)
1589{ 1904{
1590 int psend = -1; 1905 int psend = -1;
1591 int vif, ct; 1906 int vif, ct;
1592 struct net *net = mfc6_net(cache);
1593 1907
1594 vif = cache->mf6c_parent; 1908 vif = cache->mf6c_parent;
1595 cache->mfc_un.res.pkt++; 1909 cache->mfc_un.res.pkt++;
@@ -1598,30 +1912,30 @@ static int ip6_mr_forward(struct sk_buff *skb, struct mfc6_cache *cache)
1598 /* 1912 /*
1599 * Wrong interface: drop packet and (maybe) send PIM assert. 1913 * Wrong interface: drop packet and (maybe) send PIM assert.
1600 */ 1914 */
1601 if (net->ipv6.vif6_table[vif].dev != skb->dev) { 1915 if (mrt->vif6_table[vif].dev != skb->dev) {
1602 int true_vifi; 1916 int true_vifi;
1603 1917
1604 cache->mfc_un.res.wrong_if++; 1918 cache->mfc_un.res.wrong_if++;
1605 true_vifi = ip6mr_find_vif(skb->dev); 1919 true_vifi = ip6mr_find_vif(mrt, skb->dev);
1606 1920
1607 if (true_vifi >= 0 && net->ipv6.mroute_do_assert && 1921 if (true_vifi >= 0 && mrt->mroute_do_assert &&
1608 /* pimsm uses asserts, when switching from RPT to SPT, 1922 /* pimsm uses asserts, when switching from RPT to SPT,
1609 so that we cannot check that packet arrived on an oif. 1923 so that we cannot check that packet arrived on an oif.
1610 It is bad, but otherwise we would need to move pretty 1924 It is bad, but otherwise we would need to move pretty
1611 large chunk of pimd to kernel. Ough... --ANK 1925 large chunk of pimd to kernel. Ough... --ANK
1612 */ 1926 */
1613 (net->ipv6.mroute_do_pim || 1927 (mrt->mroute_do_pim ||
1614 cache->mfc_un.res.ttls[true_vifi] < 255) && 1928 cache->mfc_un.res.ttls[true_vifi] < 255) &&
1615 time_after(jiffies, 1929 time_after(jiffies,
1616 cache->mfc_un.res.last_assert + MFC_ASSERT_THRESH)) { 1930 cache->mfc_un.res.last_assert + MFC_ASSERT_THRESH)) {
1617 cache->mfc_un.res.last_assert = jiffies; 1931 cache->mfc_un.res.last_assert = jiffies;
1618 ip6mr_cache_report(net, skb, true_vifi, MRT6MSG_WRONGMIF); 1932 ip6mr_cache_report(mrt, skb, true_vifi, MRT6MSG_WRONGMIF);
1619 } 1933 }
1620 goto dont_forward; 1934 goto dont_forward;
1621 } 1935 }
1622 1936
1623 net->ipv6.vif6_table[vif].pkt_in++; 1937 mrt->vif6_table[vif].pkt_in++;
1624 net->ipv6.vif6_table[vif].bytes_in += skb->len; 1938 mrt->vif6_table[vif].bytes_in += skb->len;
1625 1939
1626 /* 1940 /*
1627 * Forward the frame 1941 * Forward the frame
@@ -1631,13 +1945,13 @@ static int ip6_mr_forward(struct sk_buff *skb, struct mfc6_cache *cache)
1631 if (psend != -1) { 1945 if (psend != -1) {
1632 struct sk_buff *skb2 = skb_clone(skb, GFP_ATOMIC); 1946 struct sk_buff *skb2 = skb_clone(skb, GFP_ATOMIC);
1633 if (skb2) 1947 if (skb2)
1634 ip6mr_forward2(skb2, cache, psend); 1948 ip6mr_forward2(net, mrt, skb2, cache, psend);
1635 } 1949 }
1636 psend = ct; 1950 psend = ct;
1637 } 1951 }
1638 } 1952 }
1639 if (psend != -1) { 1953 if (psend != -1) {
1640 ip6mr_forward2(skb, cache, psend); 1954 ip6mr_forward2(net, mrt, skb, cache, psend);
1641 return 0; 1955 return 0;
1642 } 1956 }
1643 1957
@@ -1655,9 +1969,19 @@ int ip6_mr_input(struct sk_buff *skb)
1655{ 1969{
1656 struct mfc6_cache *cache; 1970 struct mfc6_cache *cache;
1657 struct net *net = dev_net(skb->dev); 1971 struct net *net = dev_net(skb->dev);
1972 struct mr6_table *mrt;
1973 struct flowi fl = {
1974 .iif = skb->dev->ifindex,
1975 .mark = skb->mark,
1976 };
1977 int err;
1978
1979 err = ip6mr_fib_lookup(net, &fl, &mrt);
1980 if (err < 0)
1981 return err;
1658 1982
1659 read_lock(&mrt_lock); 1983 read_lock(&mrt_lock);
1660 cache = ip6mr_cache_find(net, 1984 cache = ip6mr_cache_find(mrt,
1661 &ipv6_hdr(skb)->saddr, &ipv6_hdr(skb)->daddr); 1985 &ipv6_hdr(skb)->saddr, &ipv6_hdr(skb)->daddr);
1662 1986
1663 /* 1987 /*
@@ -1666,9 +1990,9 @@ int ip6_mr_input(struct sk_buff *skb)
1666 if (cache == NULL) { 1990 if (cache == NULL) {
1667 int vif; 1991 int vif;
1668 1992
1669 vif = ip6mr_find_vif(skb->dev); 1993 vif = ip6mr_find_vif(mrt, skb->dev);
1670 if (vif >= 0) { 1994 if (vif >= 0) {
1671 int err = ip6mr_cache_unresolved(net, vif, skb); 1995 int err = ip6mr_cache_unresolved(mrt, vif, skb);
1672 read_unlock(&mrt_lock); 1996 read_unlock(&mrt_lock);
1673 1997
1674 return err; 1998 return err;
@@ -1678,7 +2002,7 @@ int ip6_mr_input(struct sk_buff *skb)
1678 return -ENODEV; 2002 return -ENODEV;
1679 } 2003 }
1680 2004
1681 ip6_mr_forward(skb, cache); 2005 ip6_mr_forward(net, mrt, skb, cache);
1682 2006
1683 read_unlock(&mrt_lock); 2007 read_unlock(&mrt_lock);
1684 2008
@@ -1686,29 +2010,31 @@ int ip6_mr_input(struct sk_buff *skb)
1686} 2010}
1687 2011
1688 2012
1689static int 2013static int __ip6mr_fill_mroute(struct mr6_table *mrt, struct sk_buff *skb,
1690ip6mr_fill_mroute(struct sk_buff *skb, struct mfc6_cache *c, struct rtmsg *rtm) 2014 struct mfc6_cache *c, struct rtmsg *rtm)
1691{ 2015{
1692 int ct; 2016 int ct;
1693 struct rtnexthop *nhp; 2017 struct rtnexthop *nhp;
1694 struct net *net = mfc6_net(c);
1695 struct net_device *dev = net->ipv6.vif6_table[c->mf6c_parent].dev;
1696 u8 *b = skb_tail_pointer(skb); 2018 u8 *b = skb_tail_pointer(skb);
1697 struct rtattr *mp_head; 2019 struct rtattr *mp_head;
1698 2020
1699 if (dev) 2021 /* If cache is unresolved, don't try to parse IIF and OIF */
1700 RTA_PUT(skb, RTA_IIF, 4, &dev->ifindex); 2022 if (c->mf6c_parent >= MAXMIFS)
2023 return -ENOENT;
2024
2025 if (MIF_EXISTS(mrt, c->mf6c_parent))
2026 RTA_PUT(skb, RTA_IIF, 4, &mrt->vif6_table[c->mf6c_parent].dev->ifindex);
1701 2027
1702 mp_head = (struct rtattr *)skb_put(skb, RTA_LENGTH(0)); 2028 mp_head = (struct rtattr *)skb_put(skb, RTA_LENGTH(0));
1703 2029
1704 for (ct = c->mfc_un.res.minvif; ct < c->mfc_un.res.maxvif; ct++) { 2030 for (ct = c->mfc_un.res.minvif; ct < c->mfc_un.res.maxvif; ct++) {
1705 if (c->mfc_un.res.ttls[ct] < 255) { 2031 if (MIF_EXISTS(mrt, ct) && c->mfc_un.res.ttls[ct] < 255) {
1706 if (skb_tailroom(skb) < RTA_ALIGN(RTA_ALIGN(sizeof(*nhp)) + 4)) 2032 if (skb_tailroom(skb) < RTA_ALIGN(RTA_ALIGN(sizeof(*nhp)) + 4))
1707 goto rtattr_failure; 2033 goto rtattr_failure;
1708 nhp = (struct rtnexthop *)skb_put(skb, RTA_ALIGN(sizeof(*nhp))); 2034 nhp = (struct rtnexthop *)skb_put(skb, RTA_ALIGN(sizeof(*nhp)));
1709 nhp->rtnh_flags = 0; 2035 nhp->rtnh_flags = 0;
1710 nhp->rtnh_hops = c->mfc_un.res.ttls[ct]; 2036 nhp->rtnh_hops = c->mfc_un.res.ttls[ct];
1711 nhp->rtnh_ifindex = net->ipv6.vif6_table[ct].dev->ifindex; 2037 nhp->rtnh_ifindex = mrt->vif6_table[ct].dev->ifindex;
1712 nhp->rtnh_len = sizeof(*nhp); 2038 nhp->rtnh_len = sizeof(*nhp);
1713 } 2039 }
1714 } 2040 }
@@ -1726,11 +2052,16 @@ int ip6mr_get_route(struct net *net,
1726 struct sk_buff *skb, struct rtmsg *rtm, int nowait) 2052 struct sk_buff *skb, struct rtmsg *rtm, int nowait)
1727{ 2053{
1728 int err; 2054 int err;
2055 struct mr6_table *mrt;
1729 struct mfc6_cache *cache; 2056 struct mfc6_cache *cache;
1730 struct rt6_info *rt = (struct rt6_info *)skb_dst(skb); 2057 struct rt6_info *rt = (struct rt6_info *)skb_dst(skb);
1731 2058
2059 mrt = ip6mr_get_table(net, RT6_TABLE_DFLT);
2060 if (mrt == NULL)
2061 return -ENOENT;
2062
1732 read_lock(&mrt_lock); 2063 read_lock(&mrt_lock);
1733 cache = ip6mr_cache_find(net, &rt->rt6i_src.addr, &rt->rt6i_dst.addr); 2064 cache = ip6mr_cache_find(mrt, &rt->rt6i_src.addr, &rt->rt6i_dst.addr);
1734 2065
1735 if (!cache) { 2066 if (!cache) {
1736 struct sk_buff *skb2; 2067 struct sk_buff *skb2;
@@ -1744,7 +2075,7 @@ int ip6mr_get_route(struct net *net,
1744 } 2075 }
1745 2076
1746 dev = skb->dev; 2077 dev = skb->dev;
1747 if (dev == NULL || (vif = ip6mr_find_vif(dev)) < 0) { 2078 if (dev == NULL || (vif = ip6mr_find_vif(mrt, dev)) < 0) {
1748 read_unlock(&mrt_lock); 2079 read_unlock(&mrt_lock);
1749 return -ENODEV; 2080 return -ENODEV;
1750 } 2081 }
@@ -1773,7 +2104,7 @@ int ip6mr_get_route(struct net *net,
1773 ipv6_addr_copy(&iph->saddr, &rt->rt6i_src.addr); 2104 ipv6_addr_copy(&iph->saddr, &rt->rt6i_src.addr);
1774 ipv6_addr_copy(&iph->daddr, &rt->rt6i_dst.addr); 2105 ipv6_addr_copy(&iph->daddr, &rt->rt6i_dst.addr);
1775 2106
1776 err = ip6mr_cache_unresolved(net, vif, skb2); 2107 err = ip6mr_cache_unresolved(mrt, vif, skb2);
1777 read_unlock(&mrt_lock); 2108 read_unlock(&mrt_lock);
1778 2109
1779 return err; 2110 return err;
@@ -1782,8 +2113,88 @@ int ip6mr_get_route(struct net *net,
1782 if (!nowait && (rtm->rtm_flags&RTM_F_NOTIFY)) 2113 if (!nowait && (rtm->rtm_flags&RTM_F_NOTIFY))
1783 cache->mfc_flags |= MFC_NOTIFY; 2114 cache->mfc_flags |= MFC_NOTIFY;
1784 2115
1785 err = ip6mr_fill_mroute(skb, cache, rtm); 2116 err = __ip6mr_fill_mroute(mrt, skb, cache, rtm);
1786 read_unlock(&mrt_lock); 2117 read_unlock(&mrt_lock);
1787 return err; 2118 return err;
1788} 2119}
1789 2120
2121static int ip6mr_fill_mroute(struct mr6_table *mrt, struct sk_buff *skb,
2122 u32 pid, u32 seq, struct mfc6_cache *c)
2123{
2124 struct nlmsghdr *nlh;
2125 struct rtmsg *rtm;
2126
2127 nlh = nlmsg_put(skb, pid, seq, RTM_NEWROUTE, sizeof(*rtm), NLM_F_MULTI);
2128 if (nlh == NULL)
2129 return -EMSGSIZE;
2130
2131 rtm = nlmsg_data(nlh);
2132 rtm->rtm_family = RTNL_FAMILY_IPMR;
2133 rtm->rtm_dst_len = 128;
2134 rtm->rtm_src_len = 128;
2135 rtm->rtm_tos = 0;
2136 rtm->rtm_table = mrt->id;
2137 NLA_PUT_U32(skb, RTA_TABLE, mrt->id);
2138 rtm->rtm_scope = RT_SCOPE_UNIVERSE;
2139 rtm->rtm_protocol = RTPROT_UNSPEC;
2140 rtm->rtm_flags = 0;
2141
2142 NLA_PUT(skb, RTA_SRC, 16, &c->mf6c_origin);
2143 NLA_PUT(skb, RTA_DST, 16, &c->mf6c_mcastgrp);
2144
2145 if (__ip6mr_fill_mroute(mrt, skb, c, rtm) < 0)
2146 goto nla_put_failure;
2147
2148 return nlmsg_end(skb, nlh);
2149
2150nla_put_failure:
2151 nlmsg_cancel(skb, nlh);
2152 return -EMSGSIZE;
2153}
2154
2155static int ip6mr_rtm_dumproute(struct sk_buff *skb, struct netlink_callback *cb)
2156{
2157 struct net *net = sock_net(skb->sk);
2158 struct mr6_table *mrt;
2159 struct mfc6_cache *mfc;
2160 unsigned int t = 0, s_t;
2161 unsigned int h = 0, s_h;
2162 unsigned int e = 0, s_e;
2163
2164 s_t = cb->args[0];
2165 s_h = cb->args[1];
2166 s_e = cb->args[2];
2167
2168 read_lock(&mrt_lock);
2169 ip6mr_for_each_table(mrt, net) {
2170 if (t < s_t)
2171 goto next_table;
2172 if (t > s_t)
2173 s_h = 0;
2174 for (h = s_h; h < MFC6_LINES; h++) {
2175 list_for_each_entry(mfc, &mrt->mfc6_cache_array[h], list) {
2176 if (e < s_e)
2177 goto next_entry;
2178 if (ip6mr_fill_mroute(mrt, skb,
2179 NETLINK_CB(cb->skb).pid,
2180 cb->nlh->nlmsg_seq,
2181 mfc) < 0)
2182 goto done;
2183next_entry:
2184 e++;
2185 }
2186 e = s_e = 0;
2187 }
2188 s_h = 0;
2189next_table:
2190 t++;
2191 }
2192done:
2193 read_unlock(&mrt_lock);
2194
2195 cb->args[2] = e;
2196 cb->args[1] = h;
2197 cb->args[0] = t;
2198
2199 return skb->len;
2200}