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