aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv4/ipmr.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/ipv4/ipmr.c')
-rw-r--r--net/ipv4/ipmr.c927
1 files changed, 651 insertions, 276 deletions
diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c
index ec19a890c9a0..45889103b3e2 100644
--- a/net/ipv4/ipmr.c
+++ b/net/ipv4/ipmr.c
@@ -22,7 +22,7 @@
22 * overflow. 22 * overflow.
23 * Carlos Picoto : PIMv1 Support 23 * Carlos Picoto : PIMv1 Support
24 * Pavlin Ivanov Radoslavov: PIMv2 Registers must checksum only PIM header 24 * Pavlin Ivanov Radoslavov: PIMv2 Registers must checksum only PIM header
25 * Relax this requrement to work with older peers. 25 * Relax this requirement to work with older peers.
26 * 26 *
27 */ 27 */
28 28
@@ -63,11 +63,40 @@
63#include <net/ipip.h> 63#include <net/ipip.h>
64#include <net/checksum.h> 64#include <net/checksum.h>
65#include <net/netlink.h> 65#include <net/netlink.h>
66#include <net/fib_rules.h>
66 67
67#if defined(CONFIG_IP_PIMSM_V1) || defined(CONFIG_IP_PIMSM_V2) 68#if defined(CONFIG_IP_PIMSM_V1) || defined(CONFIG_IP_PIMSM_V2)
68#define CONFIG_IP_PIMSM 1 69#define CONFIG_IP_PIMSM 1
69#endif 70#endif
70 71
72struct mr_table {
73 struct list_head list;
74#ifdef CONFIG_NET_NS
75 struct net *net;
76#endif
77 u32 id;
78 struct sock *mroute_sk;
79 struct timer_list ipmr_expire_timer;
80 struct list_head mfc_unres_queue;
81 struct list_head mfc_cache_array[MFC_LINES];
82 struct vif_device vif_table[MAXVIFS];
83 int maxvif;
84 atomic_t cache_resolve_queue_len;
85 int mroute_do_assert;
86 int mroute_do_pim;
87#if defined(CONFIG_IP_PIMSM_V1) || defined(CONFIG_IP_PIMSM_V2)
88 int mroute_reg_vif_num;
89#endif
90};
91
92struct ipmr_rule {
93 struct fib_rule common;
94};
95
96struct ipmr_result {
97 struct mr_table *mrt;
98};
99
71/* Big lock, protecting vif table, mrt cache and mroute socket state. 100/* Big lock, protecting vif table, mrt cache and mroute socket state.
72 Note that the changes are semaphored via rtnl_lock. 101 Note that the changes are semaphored via rtnl_lock.
73 */ 102 */
@@ -78,9 +107,7 @@ static DEFINE_RWLOCK(mrt_lock);
78 * Multicast router control variables 107 * Multicast router control variables
79 */ 108 */
80 109
81#define VIF_EXISTS(_net, _idx) ((_net)->ipv4.vif_table[_idx].dev != NULL) 110#define VIF_EXISTS(_mrt, _idx) ((_mrt)->vif_table[_idx].dev != NULL)
82
83static struct mfc_cache *mfc_unres_queue; /* Queue of unresolved entries */
84 111
85/* Special spinlock for queue of unresolved entries */ 112/* Special spinlock for queue of unresolved entries */
86static DEFINE_SPINLOCK(mfc_unres_lock); 113static DEFINE_SPINLOCK(mfc_unres_lock);
@@ -95,12 +122,215 @@ static DEFINE_SPINLOCK(mfc_unres_lock);
95 122
96static struct kmem_cache *mrt_cachep __read_mostly; 123static struct kmem_cache *mrt_cachep __read_mostly;
97 124
98static int ip_mr_forward(struct sk_buff *skb, struct mfc_cache *cache, int local); 125static struct mr_table *ipmr_new_table(struct net *net, u32 id);
99static int ipmr_cache_report(struct net *net, 126static int ip_mr_forward(struct net *net, struct mr_table *mrt,
127 struct sk_buff *skb, struct mfc_cache *cache,
128 int local);
129static int ipmr_cache_report(struct mr_table *mrt,
100 struct sk_buff *pkt, vifi_t vifi, int assert); 130 struct sk_buff *pkt, vifi_t vifi, int assert);
101static int ipmr_fill_mroute(struct sk_buff *skb, struct mfc_cache *c, struct rtmsg *rtm); 131static int __ipmr_fill_mroute(struct mr_table *mrt, struct sk_buff *skb,
132 struct mfc_cache *c, struct rtmsg *rtm);
133static void ipmr_expire_process(unsigned long arg);
134
135#ifdef CONFIG_IP_MROUTE_MULTIPLE_TABLES
136#define ipmr_for_each_table(mrt, net) \
137 list_for_each_entry_rcu(mrt, &net->ipv4.mr_tables, list)
138
139static struct mr_table *ipmr_get_table(struct net *net, u32 id)
140{
141 struct mr_table *mrt;
142
143 ipmr_for_each_table(mrt, net) {
144 if (mrt->id == id)
145 return mrt;
146 }
147 return NULL;
148}
149
150static int ipmr_fib_lookup(struct net *net, struct flowi *flp,
151 struct mr_table **mrt)
152{
153 struct ipmr_result res;
154 struct fib_lookup_arg arg = { .result = &res, };
155 int err;
156
157 err = fib_rules_lookup(net->ipv4.mr_rules_ops, flp, 0, &arg);
158 if (err < 0)
159 return err;
160 *mrt = res.mrt;
161 return 0;
162}
163
164static int ipmr_rule_action(struct fib_rule *rule, struct flowi *flp,
165 int flags, struct fib_lookup_arg *arg)
166{
167 struct ipmr_result *res = arg->result;
168 struct mr_table *mrt;
102 169
103static struct timer_list ipmr_expire_timer; 170 switch (rule->action) {
171 case FR_ACT_TO_TBL:
172 break;
173 case FR_ACT_UNREACHABLE:
174 return -ENETUNREACH;
175 case FR_ACT_PROHIBIT:
176 return -EACCES;
177 case FR_ACT_BLACKHOLE:
178 default:
179 return -EINVAL;
180 }
181
182 mrt = ipmr_get_table(rule->fr_net, rule->table);
183 if (mrt == NULL)
184 return -EAGAIN;
185 res->mrt = mrt;
186 return 0;
187}
188
189static int ipmr_rule_match(struct fib_rule *rule, struct flowi *fl, int flags)
190{
191 return 1;
192}
193
194static const struct nla_policy ipmr_rule_policy[FRA_MAX + 1] = {
195 FRA_GENERIC_POLICY,
196};
197
198static int ipmr_rule_configure(struct fib_rule *rule, struct sk_buff *skb,
199 struct fib_rule_hdr *frh, struct nlattr **tb)
200{
201 return 0;
202}
203
204static int ipmr_rule_compare(struct fib_rule *rule, struct fib_rule_hdr *frh,
205 struct nlattr **tb)
206{
207 return 1;
208}
209
210static int ipmr_rule_fill(struct fib_rule *rule, struct sk_buff *skb,
211 struct fib_rule_hdr *frh)
212{
213 frh->dst_len = 0;
214 frh->src_len = 0;
215 frh->tos = 0;
216 return 0;
217}
218
219static const struct fib_rules_ops __net_initdata ipmr_rules_ops_template = {
220 .family = RTNL_FAMILY_IPMR,
221 .rule_size = sizeof(struct ipmr_rule),
222 .addr_size = sizeof(u32),
223 .action = ipmr_rule_action,
224 .match = ipmr_rule_match,
225 .configure = ipmr_rule_configure,
226 .compare = ipmr_rule_compare,
227 .default_pref = fib_default_rule_pref,
228 .fill = ipmr_rule_fill,
229 .nlgroup = RTNLGRP_IPV4_RULE,
230 .policy = ipmr_rule_policy,
231 .owner = THIS_MODULE,
232};
233
234static int __net_init ipmr_rules_init(struct net *net)
235{
236 struct fib_rules_ops *ops;
237 struct mr_table *mrt;
238 int err;
239
240 ops = fib_rules_register(&ipmr_rules_ops_template, net);
241 if (IS_ERR(ops))
242 return PTR_ERR(ops);
243
244 INIT_LIST_HEAD(&net->ipv4.mr_tables);
245
246 mrt = ipmr_new_table(net, RT_TABLE_DEFAULT);
247 if (mrt == NULL) {
248 err = -ENOMEM;
249 goto err1;
250 }
251
252 err = fib_default_rule_add(ops, 0x7fff, RT_TABLE_DEFAULT, 0);
253 if (err < 0)
254 goto err2;
255
256 net->ipv4.mr_rules_ops = ops;
257 return 0;
258
259err2:
260 kfree(mrt);
261err1:
262 fib_rules_unregister(ops);
263 return err;
264}
265
266static void __net_exit ipmr_rules_exit(struct net *net)
267{
268 struct mr_table *mrt, *next;
269
270 list_for_each_entry_safe(mrt, next, &net->ipv4.mr_tables, list)
271 kfree(mrt);
272 fib_rules_unregister(net->ipv4.mr_rules_ops);
273}
274#else
275#define ipmr_for_each_table(mrt, net) \
276 for (mrt = net->ipv4.mrt; mrt; mrt = NULL)
277
278static struct mr_table *ipmr_get_table(struct net *net, u32 id)
279{
280 return net->ipv4.mrt;
281}
282
283static int ipmr_fib_lookup(struct net *net, struct flowi *flp,
284 struct mr_table **mrt)
285{
286 *mrt = net->ipv4.mrt;
287 return 0;
288}
289
290static int __net_init ipmr_rules_init(struct net *net)
291{
292 net->ipv4.mrt = ipmr_new_table(net, RT_TABLE_DEFAULT);
293 return net->ipv4.mrt ? 0 : -ENOMEM;
294}
295
296static void __net_exit ipmr_rules_exit(struct net *net)
297{
298 kfree(net->ipv4.mrt);
299}
300#endif
301
302static struct mr_table *ipmr_new_table(struct net *net, u32 id)
303{
304 struct mr_table *mrt;
305 unsigned int i;
306
307 mrt = ipmr_get_table(net, id);
308 if (mrt != NULL)
309 return mrt;
310
311 mrt = kzalloc(sizeof(*mrt), GFP_KERNEL);
312 if (mrt == NULL)
313 return NULL;
314 write_pnet(&mrt->net, net);
315 mrt->id = id;
316
317 /* Forwarding cache */
318 for (i = 0; i < MFC_LINES; i++)
319 INIT_LIST_HEAD(&mrt->mfc_cache_array[i]);
320
321 INIT_LIST_HEAD(&mrt->mfc_unres_queue);
322
323 setup_timer(&mrt->ipmr_expire_timer, ipmr_expire_process,
324 (unsigned long)mrt);
325
326#ifdef CONFIG_IP_PIMSM
327 mrt->mroute_reg_vif_num = -1;
328#endif
329#ifdef CONFIG_IP_MROUTE_MULTIPLE_TABLES
330 list_add_tail_rcu(&mrt->list, &net->ipv4.mr_tables);
331#endif
332 return mrt;
333}
104 334
105/* Service routines creating virtual interfaces: DVMRP tunnels and PIMREG */ 335/* Service routines creating virtual interfaces: DVMRP tunnels and PIMREG */
106 336
@@ -201,12 +431,22 @@ failure:
201static netdev_tx_t reg_vif_xmit(struct sk_buff *skb, struct net_device *dev) 431static netdev_tx_t reg_vif_xmit(struct sk_buff *skb, struct net_device *dev)
202{ 432{
203 struct net *net = dev_net(dev); 433 struct net *net = dev_net(dev);
434 struct mr_table *mrt;
435 struct flowi fl = {
436 .oif = dev->ifindex,
437 .iif = skb->skb_iif,
438 .mark = skb->mark,
439 };
440 int err;
441
442 err = ipmr_fib_lookup(net, &fl, &mrt);
443 if (err < 0)
444 return err;
204 445
205 read_lock(&mrt_lock); 446 read_lock(&mrt_lock);
206 dev->stats.tx_bytes += skb->len; 447 dev->stats.tx_bytes += skb->len;
207 dev->stats.tx_packets++; 448 dev->stats.tx_packets++;
208 ipmr_cache_report(net, skb, net->ipv4.mroute_reg_vif_num, 449 ipmr_cache_report(mrt, skb, mrt->mroute_reg_vif_num, IGMPMSG_WHOLEPKT);
209 IGMPMSG_WHOLEPKT);
210 read_unlock(&mrt_lock); 450 read_unlock(&mrt_lock);
211 kfree_skb(skb); 451 kfree_skb(skb);
212 return NETDEV_TX_OK; 452 return NETDEV_TX_OK;
@@ -226,12 +466,18 @@ static void reg_vif_setup(struct net_device *dev)
226 dev->features |= NETIF_F_NETNS_LOCAL; 466 dev->features |= NETIF_F_NETNS_LOCAL;
227} 467}
228 468
229static struct net_device *ipmr_reg_vif(struct net *net) 469static struct net_device *ipmr_reg_vif(struct net *net, struct mr_table *mrt)
230{ 470{
231 struct net_device *dev; 471 struct net_device *dev;
232 struct in_device *in_dev; 472 struct in_device *in_dev;
473 char name[IFNAMSIZ];
474
475 if (mrt->id == RT_TABLE_DEFAULT)
476 sprintf(name, "pimreg");
477 else
478 sprintf(name, "pimreg%u", mrt->id);
233 479
234 dev = alloc_netdev(0, "pimreg", reg_vif_setup); 480 dev = alloc_netdev(0, name, reg_vif_setup);
235 481
236 if (dev == NULL) 482 if (dev == NULL)
237 return NULL; 483 return NULL;
@@ -276,17 +522,17 @@ failure:
276 * @notify: Set to 1, if the caller is a notifier_call 522 * @notify: Set to 1, if the caller is a notifier_call
277 */ 523 */
278 524
279static int vif_delete(struct net *net, int vifi, int notify, 525static int vif_delete(struct mr_table *mrt, int vifi, int notify,
280 struct list_head *head) 526 struct list_head *head)
281{ 527{
282 struct vif_device *v; 528 struct vif_device *v;
283 struct net_device *dev; 529 struct net_device *dev;
284 struct in_device *in_dev; 530 struct in_device *in_dev;
285 531
286 if (vifi < 0 || vifi >= net->ipv4.maxvif) 532 if (vifi < 0 || vifi >= mrt->maxvif)
287 return -EADDRNOTAVAIL; 533 return -EADDRNOTAVAIL;
288 534
289 v = &net->ipv4.vif_table[vifi]; 535 v = &mrt->vif_table[vifi];
290 536
291 write_lock_bh(&mrt_lock); 537 write_lock_bh(&mrt_lock);
292 dev = v->dev; 538 dev = v->dev;
@@ -298,17 +544,17 @@ static int vif_delete(struct net *net, int vifi, int notify,
298 } 544 }
299 545
300#ifdef CONFIG_IP_PIMSM 546#ifdef CONFIG_IP_PIMSM
301 if (vifi == net->ipv4.mroute_reg_vif_num) 547 if (vifi == mrt->mroute_reg_vif_num)
302 net->ipv4.mroute_reg_vif_num = -1; 548 mrt->mroute_reg_vif_num = -1;
303#endif 549#endif
304 550
305 if (vifi+1 == net->ipv4.maxvif) { 551 if (vifi+1 == mrt->maxvif) {
306 int tmp; 552 int tmp;
307 for (tmp=vifi-1; tmp>=0; tmp--) { 553 for (tmp=vifi-1; tmp>=0; tmp--) {
308 if (VIF_EXISTS(net, tmp)) 554 if (VIF_EXISTS(mrt, tmp))
309 break; 555 break;
310 } 556 }
311 net->ipv4.maxvif = tmp+1; 557 mrt->maxvif = tmp+1;
312 } 558 }
313 559
314 write_unlock_bh(&mrt_lock); 560 write_unlock_bh(&mrt_lock);
@@ -329,7 +575,6 @@ static int vif_delete(struct net *net, int vifi, int notify,
329 575
330static inline void ipmr_cache_free(struct mfc_cache *c) 576static inline void ipmr_cache_free(struct mfc_cache *c)
331{ 577{
332 release_net(mfc_net(c));
333 kmem_cache_free(mrt_cachep, c); 578 kmem_cache_free(mrt_cachep, c);
334} 579}
335 580
@@ -337,13 +582,13 @@ static inline void ipmr_cache_free(struct mfc_cache *c)
337 and reporting error to netlink readers. 582 and reporting error to netlink readers.
338 */ 583 */
339 584
340static void ipmr_destroy_unres(struct mfc_cache *c) 585static void ipmr_destroy_unres(struct mr_table *mrt, struct mfc_cache *c)
341{ 586{
587 struct net *net = read_pnet(&mrt->net);
342 struct sk_buff *skb; 588 struct sk_buff *skb;
343 struct nlmsgerr *e; 589 struct nlmsgerr *e;
344 struct net *net = mfc_net(c);
345 590
346 atomic_dec(&net->ipv4.cache_resolve_queue_len); 591 atomic_dec(&mrt->cache_resolve_queue_len);
347 592
348 while ((skb = skb_dequeue(&c->mfc_un.unres.unresolved))) { 593 while ((skb = skb_dequeue(&c->mfc_un.unres.unresolved))) {
349 if (ip_hdr(skb)->version == 0) { 594 if (ip_hdr(skb)->version == 0) {
@@ -364,42 +609,40 @@ static void ipmr_destroy_unres(struct mfc_cache *c)
364} 609}
365 610
366 611
367/* Single timer process for all the unresolved queue. */ 612/* Timer process for the unresolved queue. */
368 613
369static void ipmr_expire_process(unsigned long dummy) 614static void ipmr_expire_process(unsigned long arg)
370{ 615{
616 struct mr_table *mrt = (struct mr_table *)arg;
371 unsigned long now; 617 unsigned long now;
372 unsigned long expires; 618 unsigned long expires;
373 struct mfc_cache *c, **cp; 619 struct mfc_cache *c, *next;
374 620
375 if (!spin_trylock(&mfc_unres_lock)) { 621 if (!spin_trylock(&mfc_unres_lock)) {
376 mod_timer(&ipmr_expire_timer, jiffies+HZ/10); 622 mod_timer(&mrt->ipmr_expire_timer, jiffies+HZ/10);
377 return; 623 return;
378 } 624 }
379 625
380 if (mfc_unres_queue == NULL) 626 if (list_empty(&mrt->mfc_unres_queue))
381 goto out; 627 goto out;
382 628
383 now = jiffies; 629 now = jiffies;
384 expires = 10*HZ; 630 expires = 10*HZ;
385 cp = &mfc_unres_queue;
386 631
387 while ((c=*cp) != NULL) { 632 list_for_each_entry_safe(c, next, &mrt->mfc_unres_queue, list) {
388 if (time_after(c->mfc_un.unres.expires, now)) { 633 if (time_after(c->mfc_un.unres.expires, now)) {
389 unsigned long interval = c->mfc_un.unres.expires - now; 634 unsigned long interval = c->mfc_un.unres.expires - now;
390 if (interval < expires) 635 if (interval < expires)
391 expires = interval; 636 expires = interval;
392 cp = &c->next;
393 continue; 637 continue;
394 } 638 }
395 639
396 *cp = c->next; 640 list_del(&c->list);
397 641 ipmr_destroy_unres(mrt, c);
398 ipmr_destroy_unres(c);
399 } 642 }
400 643
401 if (mfc_unres_queue != NULL) 644 if (!list_empty(&mrt->mfc_unres_queue))
402 mod_timer(&ipmr_expire_timer, jiffies + expires); 645 mod_timer(&mrt->ipmr_expire_timer, jiffies + expires);
403 646
404out: 647out:
405 spin_unlock(&mfc_unres_lock); 648 spin_unlock(&mfc_unres_lock);
@@ -407,17 +650,17 @@ out:
407 650
408/* Fill oifs list. It is called under write locked mrt_lock. */ 651/* Fill oifs list. It is called under write locked mrt_lock. */
409 652
410static void ipmr_update_thresholds(struct mfc_cache *cache, unsigned char *ttls) 653static void ipmr_update_thresholds(struct mr_table *mrt, struct mfc_cache *cache,
654 unsigned char *ttls)
411{ 655{
412 int vifi; 656 int vifi;
413 struct net *net = mfc_net(cache);
414 657
415 cache->mfc_un.res.minvif = MAXVIFS; 658 cache->mfc_un.res.minvif = MAXVIFS;
416 cache->mfc_un.res.maxvif = 0; 659 cache->mfc_un.res.maxvif = 0;
417 memset(cache->mfc_un.res.ttls, 255, MAXVIFS); 660 memset(cache->mfc_un.res.ttls, 255, MAXVIFS);
418 661
419 for (vifi = 0; vifi < net->ipv4.maxvif; vifi++) { 662 for (vifi = 0; vifi < mrt->maxvif; vifi++) {
420 if (VIF_EXISTS(net, vifi) && 663 if (VIF_EXISTS(mrt, vifi) &&
421 ttls[vifi] && ttls[vifi] < 255) { 664 ttls[vifi] && ttls[vifi] < 255) {
422 cache->mfc_un.res.ttls[vifi] = ttls[vifi]; 665 cache->mfc_un.res.ttls[vifi] = ttls[vifi];
423 if (cache->mfc_un.res.minvif > vifi) 666 if (cache->mfc_un.res.minvif > vifi)
@@ -428,16 +671,17 @@ static void ipmr_update_thresholds(struct mfc_cache *cache, unsigned char *ttls)
428 } 671 }
429} 672}
430 673
431static int vif_add(struct net *net, struct vifctl *vifc, int mrtsock) 674static int vif_add(struct net *net, struct mr_table *mrt,
675 struct vifctl *vifc, int mrtsock)
432{ 676{
433 int vifi = vifc->vifc_vifi; 677 int vifi = vifc->vifc_vifi;
434 struct vif_device *v = &net->ipv4.vif_table[vifi]; 678 struct vif_device *v = &mrt->vif_table[vifi];
435 struct net_device *dev; 679 struct net_device *dev;
436 struct in_device *in_dev; 680 struct in_device *in_dev;
437 int err; 681 int err;
438 682
439 /* Is vif busy ? */ 683 /* Is vif busy ? */
440 if (VIF_EXISTS(net, vifi)) 684 if (VIF_EXISTS(mrt, vifi))
441 return -EADDRINUSE; 685 return -EADDRINUSE;
442 686
443 switch (vifc->vifc_flags) { 687 switch (vifc->vifc_flags) {
@@ -447,9 +691,9 @@ static int vif_add(struct net *net, struct vifctl *vifc, int mrtsock)
447 * Special Purpose VIF in PIM 691 * Special Purpose VIF in PIM
448 * All the packets will be sent to the daemon 692 * All the packets will be sent to the daemon
449 */ 693 */
450 if (net->ipv4.mroute_reg_vif_num >= 0) 694 if (mrt->mroute_reg_vif_num >= 0)
451 return -EADDRINUSE; 695 return -EADDRINUSE;
452 dev = ipmr_reg_vif(net); 696 dev = ipmr_reg_vif(net, mrt);
453 if (!dev) 697 if (!dev)
454 return -ENOBUFS; 698 return -ENOBUFS;
455 err = dev_set_allmulti(dev, 1); 699 err = dev_set_allmulti(dev, 1);
@@ -525,49 +769,47 @@ static int vif_add(struct net *net, struct vifctl *vifc, int mrtsock)
525 v->dev = dev; 769 v->dev = dev;
526#ifdef CONFIG_IP_PIMSM 770#ifdef CONFIG_IP_PIMSM
527 if (v->flags&VIFF_REGISTER) 771 if (v->flags&VIFF_REGISTER)
528 net->ipv4.mroute_reg_vif_num = vifi; 772 mrt->mroute_reg_vif_num = vifi;
529#endif 773#endif
530 if (vifi+1 > net->ipv4.maxvif) 774 if (vifi+1 > mrt->maxvif)
531 net->ipv4.maxvif = vifi+1; 775 mrt->maxvif = vifi+1;
532 write_unlock_bh(&mrt_lock); 776 write_unlock_bh(&mrt_lock);
533 return 0; 777 return 0;
534} 778}
535 779
536static struct mfc_cache *ipmr_cache_find(struct net *net, 780static struct mfc_cache *ipmr_cache_find(struct mr_table *mrt,
537 __be32 origin, 781 __be32 origin,
538 __be32 mcastgrp) 782 __be32 mcastgrp)
539{ 783{
540 int line = MFC_HASH(mcastgrp, origin); 784 int line = MFC_HASH(mcastgrp, origin);
541 struct mfc_cache *c; 785 struct mfc_cache *c;
542 786
543 for (c = net->ipv4.mfc_cache_array[line]; c; c = c->next) { 787 list_for_each_entry(c, &mrt->mfc_cache_array[line], list) {
544 if (c->mfc_origin==origin && c->mfc_mcastgrp==mcastgrp) 788 if (c->mfc_origin == origin && c->mfc_mcastgrp == mcastgrp)
545 break; 789 return c;
546 } 790 }
547 return c; 791 return NULL;
548} 792}
549 793
550/* 794/*
551 * Allocate a multicast cache entry 795 * Allocate a multicast cache entry
552 */ 796 */
553static struct mfc_cache *ipmr_cache_alloc(struct net *net) 797static struct mfc_cache *ipmr_cache_alloc(void)
554{ 798{
555 struct mfc_cache *c = kmem_cache_zalloc(mrt_cachep, GFP_KERNEL); 799 struct mfc_cache *c = kmem_cache_zalloc(mrt_cachep, GFP_KERNEL);
556 if (c == NULL) 800 if (c == NULL)
557 return NULL; 801 return NULL;
558 c->mfc_un.res.minvif = MAXVIFS; 802 c->mfc_un.res.minvif = MAXVIFS;
559 mfc_net_set(c, net);
560 return c; 803 return c;
561} 804}
562 805
563static struct mfc_cache *ipmr_cache_alloc_unres(struct net *net) 806static struct mfc_cache *ipmr_cache_alloc_unres(void)
564{ 807{
565 struct mfc_cache *c = kmem_cache_zalloc(mrt_cachep, GFP_ATOMIC); 808 struct mfc_cache *c = kmem_cache_zalloc(mrt_cachep, GFP_ATOMIC);
566 if (c == NULL) 809 if (c == NULL)
567 return NULL; 810 return NULL;
568 skb_queue_head_init(&c->mfc_un.unres.unresolved); 811 skb_queue_head_init(&c->mfc_un.unres.unresolved);
569 c->mfc_un.unres.expires = jiffies + 10*HZ; 812 c->mfc_un.unres.expires = jiffies + 10*HZ;
570 mfc_net_set(c, net);
571 return c; 813 return c;
572} 814}
573 815
@@ -575,7 +817,8 @@ static struct mfc_cache *ipmr_cache_alloc_unres(struct net *net)
575 * A cache entry has gone into a resolved state from queued 817 * A cache entry has gone into a resolved state from queued
576 */ 818 */
577 819
578static void ipmr_cache_resolve(struct mfc_cache *uc, struct mfc_cache *c) 820static void ipmr_cache_resolve(struct net *net, struct mr_table *mrt,
821 struct mfc_cache *uc, struct mfc_cache *c)
579{ 822{
580 struct sk_buff *skb; 823 struct sk_buff *skb;
581 struct nlmsgerr *e; 824 struct nlmsgerr *e;
@@ -588,7 +831,7 @@ static void ipmr_cache_resolve(struct mfc_cache *uc, struct mfc_cache *c)
588 if (ip_hdr(skb)->version == 0) { 831 if (ip_hdr(skb)->version == 0) {
589 struct nlmsghdr *nlh = (struct nlmsghdr *)skb_pull(skb, sizeof(struct iphdr)); 832 struct nlmsghdr *nlh = (struct nlmsghdr *)skb_pull(skb, sizeof(struct iphdr));
590 833
591 if (ipmr_fill_mroute(skb, c, NLMSG_DATA(nlh)) > 0) { 834 if (__ipmr_fill_mroute(mrt, skb, c, NLMSG_DATA(nlh)) > 0) {
592 nlh->nlmsg_len = (skb_tail_pointer(skb) - 835 nlh->nlmsg_len = (skb_tail_pointer(skb) -
593 (u8 *)nlh); 836 (u8 *)nlh);
594 } else { 837 } else {
@@ -600,9 +843,9 @@ static void ipmr_cache_resolve(struct mfc_cache *uc, struct mfc_cache *c)
600 memset(&e->msg, 0, sizeof(e->msg)); 843 memset(&e->msg, 0, sizeof(e->msg));
601 } 844 }
602 845
603 rtnl_unicast(skb, mfc_net(c), NETLINK_CB(skb).pid); 846 rtnl_unicast(skb, net, NETLINK_CB(skb).pid);
604 } else 847 } else
605 ip_mr_forward(skb, c, 0); 848 ip_mr_forward(net, mrt, skb, c, 0);
606 } 849 }
607} 850}
608 851
@@ -613,7 +856,7 @@ static void ipmr_cache_resolve(struct mfc_cache *uc, struct mfc_cache *c)
613 * Called under mrt_lock. 856 * Called under mrt_lock.
614 */ 857 */
615 858
616static int ipmr_cache_report(struct net *net, 859static int ipmr_cache_report(struct mr_table *mrt,
617 struct sk_buff *pkt, vifi_t vifi, int assert) 860 struct sk_buff *pkt, vifi_t vifi, int assert)
618{ 861{
619 struct sk_buff *skb; 862 struct sk_buff *skb;
@@ -646,7 +889,7 @@ static int ipmr_cache_report(struct net *net,
646 memcpy(msg, skb_network_header(pkt), sizeof(struct iphdr)); 889 memcpy(msg, skb_network_header(pkt), sizeof(struct iphdr));
647 msg->im_msgtype = IGMPMSG_WHOLEPKT; 890 msg->im_msgtype = IGMPMSG_WHOLEPKT;
648 msg->im_mbz = 0; 891 msg->im_mbz = 0;
649 msg->im_vif = net->ipv4.mroute_reg_vif_num; 892 msg->im_vif = mrt->mroute_reg_vif_num;
650 ip_hdr(skb)->ihl = sizeof(struct iphdr) >> 2; 893 ip_hdr(skb)->ihl = sizeof(struct iphdr) >> 2;
651 ip_hdr(skb)->tot_len = htons(ntohs(ip_hdr(pkt)->tot_len) + 894 ip_hdr(skb)->tot_len = htons(ntohs(ip_hdr(pkt)->tot_len) +
652 sizeof(struct iphdr)); 895 sizeof(struct iphdr));
@@ -678,7 +921,7 @@ static int ipmr_cache_report(struct net *net,
678 skb->transport_header = skb->network_header; 921 skb->transport_header = skb->network_header;
679 } 922 }
680 923
681 if (net->ipv4.mroute_sk == NULL) { 924 if (mrt->mroute_sk == NULL) {
682 kfree_skb(skb); 925 kfree_skb(skb);
683 return -EINVAL; 926 return -EINVAL;
684 } 927 }
@@ -686,7 +929,7 @@ static int ipmr_cache_report(struct net *net,
686 /* 929 /*
687 * Deliver to mrouted 930 * Deliver to mrouted
688 */ 931 */
689 ret = sock_queue_rcv_skb(net->ipv4.mroute_sk, skb); 932 ret = sock_queue_rcv_skb(mrt->mroute_sk, skb);
690 if (ret < 0) { 933 if (ret < 0) {
691 if (net_ratelimit()) 934 if (net_ratelimit())
692 printk(KERN_WARNING "mroute: pending queue full, dropping entries.\n"); 935 printk(KERN_WARNING "mroute: pending queue full, dropping entries.\n");
@@ -701,27 +944,29 @@ static int ipmr_cache_report(struct net *net,
701 */ 944 */
702 945
703static int 946static int
704ipmr_cache_unresolved(struct net *net, vifi_t vifi, struct sk_buff *skb) 947ipmr_cache_unresolved(struct mr_table *mrt, vifi_t vifi, struct sk_buff *skb)
705{ 948{
949 bool found = false;
706 int err; 950 int err;
707 struct mfc_cache *c; 951 struct mfc_cache *c;
708 const struct iphdr *iph = ip_hdr(skb); 952 const struct iphdr *iph = ip_hdr(skb);
709 953
710 spin_lock_bh(&mfc_unres_lock); 954 spin_lock_bh(&mfc_unres_lock);
711 for (c=mfc_unres_queue; c; c=c->next) { 955 list_for_each_entry(c, &mrt->mfc_unres_queue, list) {
712 if (net_eq(mfc_net(c), net) && 956 if (c->mfc_mcastgrp == iph->daddr &&
713 c->mfc_mcastgrp == iph->daddr && 957 c->mfc_origin == iph->saddr) {
714 c->mfc_origin == iph->saddr) 958 found = true;
715 break; 959 break;
960 }
716 } 961 }
717 962
718 if (c == NULL) { 963 if (!found) {
719 /* 964 /*
720 * Create a new entry if allowable 965 * Create a new entry if allowable
721 */ 966 */
722 967
723 if (atomic_read(&net->ipv4.cache_resolve_queue_len) >= 10 || 968 if (atomic_read(&mrt->cache_resolve_queue_len) >= 10 ||
724 (c = ipmr_cache_alloc_unres(net)) == NULL) { 969 (c = ipmr_cache_alloc_unres()) == NULL) {
725 spin_unlock_bh(&mfc_unres_lock); 970 spin_unlock_bh(&mfc_unres_lock);
726 971
727 kfree_skb(skb); 972 kfree_skb(skb);
@@ -738,7 +983,7 @@ ipmr_cache_unresolved(struct net *net, vifi_t vifi, struct sk_buff *skb)
738 /* 983 /*
739 * Reflect first query at mrouted. 984 * Reflect first query at mrouted.
740 */ 985 */
741 err = ipmr_cache_report(net, skb, vifi, IGMPMSG_NOCACHE); 986 err = ipmr_cache_report(mrt, skb, vifi, IGMPMSG_NOCACHE);
742 if (err < 0) { 987 if (err < 0) {
743 /* If the report failed throw the cache entry 988 /* If the report failed throw the cache entry
744 out - Brad Parker 989 out - Brad Parker
@@ -750,12 +995,11 @@ ipmr_cache_unresolved(struct net *net, vifi_t vifi, struct sk_buff *skb)
750 return err; 995 return err;
751 } 996 }
752 997
753 atomic_inc(&net->ipv4.cache_resolve_queue_len); 998 atomic_inc(&mrt->cache_resolve_queue_len);
754 c->next = mfc_unres_queue; 999 list_add(&c->list, &mrt->mfc_unres_queue);
755 mfc_unres_queue = c;
756 1000
757 if (atomic_read(&net->ipv4.cache_resolve_queue_len) == 1) 1001 if (atomic_read(&mrt->cache_resolve_queue_len) == 1)
758 mod_timer(&ipmr_expire_timer, c->mfc_un.unres.expires); 1002 mod_timer(&mrt->ipmr_expire_timer, c->mfc_un.unres.expires);
759 } 1003 }
760 1004
761 /* 1005 /*
@@ -777,19 +1021,18 @@ ipmr_cache_unresolved(struct net *net, vifi_t vifi, struct sk_buff *skb)
777 * MFC cache manipulation by user space mroute daemon 1021 * MFC cache manipulation by user space mroute daemon
778 */ 1022 */
779 1023
780static int ipmr_mfc_delete(struct net *net, struct mfcctl *mfc) 1024static int ipmr_mfc_delete(struct mr_table *mrt, struct mfcctl *mfc)
781{ 1025{
782 int line; 1026 int line;
783 struct mfc_cache *c, **cp; 1027 struct mfc_cache *c, *next;
784 1028
785 line = MFC_HASH(mfc->mfcc_mcastgrp.s_addr, mfc->mfcc_origin.s_addr); 1029 line = MFC_HASH(mfc->mfcc_mcastgrp.s_addr, mfc->mfcc_origin.s_addr);
786 1030
787 for (cp = &net->ipv4.mfc_cache_array[line]; 1031 list_for_each_entry_safe(c, next, &mrt->mfc_cache_array[line], list) {
788 (c = *cp) != NULL; cp = &c->next) {
789 if (c->mfc_origin == mfc->mfcc_origin.s_addr && 1032 if (c->mfc_origin == mfc->mfcc_origin.s_addr &&
790 c->mfc_mcastgrp == mfc->mfcc_mcastgrp.s_addr) { 1033 c->mfc_mcastgrp == mfc->mfcc_mcastgrp.s_addr) {
791 write_lock_bh(&mrt_lock); 1034 write_lock_bh(&mrt_lock);
792 *cp = c->next; 1035 list_del(&c->list);
793 write_unlock_bh(&mrt_lock); 1036 write_unlock_bh(&mrt_lock);
794 1037
795 ipmr_cache_free(c); 1038 ipmr_cache_free(c);
@@ -799,27 +1042,30 @@ static int ipmr_mfc_delete(struct net *net, struct mfcctl *mfc)
799 return -ENOENT; 1042 return -ENOENT;
800} 1043}
801 1044
802static int ipmr_mfc_add(struct net *net, struct mfcctl *mfc, int mrtsock) 1045static int ipmr_mfc_add(struct net *net, struct mr_table *mrt,
1046 struct mfcctl *mfc, int mrtsock)
803{ 1047{
1048 bool found = false;
804 int line; 1049 int line;
805 struct mfc_cache *uc, *c, **cp; 1050 struct mfc_cache *uc, *c;
806 1051
807 if (mfc->mfcc_parent >= MAXVIFS) 1052 if (mfc->mfcc_parent >= MAXVIFS)
808 return -ENFILE; 1053 return -ENFILE;
809 1054
810 line = MFC_HASH(mfc->mfcc_mcastgrp.s_addr, mfc->mfcc_origin.s_addr); 1055 line = MFC_HASH(mfc->mfcc_mcastgrp.s_addr, mfc->mfcc_origin.s_addr);
811 1056
812 for (cp = &net->ipv4.mfc_cache_array[line]; 1057 list_for_each_entry(c, &mrt->mfc_cache_array[line], list) {
813 (c = *cp) != NULL; cp = &c->next) {
814 if (c->mfc_origin == mfc->mfcc_origin.s_addr && 1058 if (c->mfc_origin == mfc->mfcc_origin.s_addr &&
815 c->mfc_mcastgrp == mfc->mfcc_mcastgrp.s_addr) 1059 c->mfc_mcastgrp == mfc->mfcc_mcastgrp.s_addr) {
1060 found = true;
816 break; 1061 break;
1062 }
817 } 1063 }
818 1064
819 if (c != NULL) { 1065 if (found) {
820 write_lock_bh(&mrt_lock); 1066 write_lock_bh(&mrt_lock);
821 c->mfc_parent = mfc->mfcc_parent; 1067 c->mfc_parent = mfc->mfcc_parent;
822 ipmr_update_thresholds(c, mfc->mfcc_ttls); 1068 ipmr_update_thresholds(mrt, c, mfc->mfcc_ttls);
823 if (!mrtsock) 1069 if (!mrtsock)
824 c->mfc_flags |= MFC_STATIC; 1070 c->mfc_flags |= MFC_STATIC;
825 write_unlock_bh(&mrt_lock); 1071 write_unlock_bh(&mrt_lock);
@@ -829,43 +1075,42 @@ static int ipmr_mfc_add(struct net *net, struct mfcctl *mfc, int mrtsock)
829 if (!ipv4_is_multicast(mfc->mfcc_mcastgrp.s_addr)) 1075 if (!ipv4_is_multicast(mfc->mfcc_mcastgrp.s_addr))
830 return -EINVAL; 1076 return -EINVAL;
831 1077
832 c = ipmr_cache_alloc(net); 1078 c = ipmr_cache_alloc();
833 if (c == NULL) 1079 if (c == NULL)
834 return -ENOMEM; 1080 return -ENOMEM;
835 1081
836 c->mfc_origin = mfc->mfcc_origin.s_addr; 1082 c->mfc_origin = mfc->mfcc_origin.s_addr;
837 c->mfc_mcastgrp = mfc->mfcc_mcastgrp.s_addr; 1083 c->mfc_mcastgrp = mfc->mfcc_mcastgrp.s_addr;
838 c->mfc_parent = mfc->mfcc_parent; 1084 c->mfc_parent = mfc->mfcc_parent;
839 ipmr_update_thresholds(c, mfc->mfcc_ttls); 1085 ipmr_update_thresholds(mrt, c, mfc->mfcc_ttls);
840 if (!mrtsock) 1086 if (!mrtsock)
841 c->mfc_flags |= MFC_STATIC; 1087 c->mfc_flags |= MFC_STATIC;
842 1088
843 write_lock_bh(&mrt_lock); 1089 write_lock_bh(&mrt_lock);
844 c->next = net->ipv4.mfc_cache_array[line]; 1090 list_add(&c->list, &mrt->mfc_cache_array[line]);
845 net->ipv4.mfc_cache_array[line] = c;
846 write_unlock_bh(&mrt_lock); 1091 write_unlock_bh(&mrt_lock);
847 1092
848 /* 1093 /*
849 * Check to see if we resolved a queued list. If so we 1094 * Check to see if we resolved a queued list. If so we
850 * need to send on the frames and tidy up. 1095 * need to send on the frames and tidy up.
851 */ 1096 */
1097 found = false;
852 spin_lock_bh(&mfc_unres_lock); 1098 spin_lock_bh(&mfc_unres_lock);
853 for (cp = &mfc_unres_queue; (uc=*cp) != NULL; 1099 list_for_each_entry(uc, &mrt->mfc_unres_queue, list) {
854 cp = &uc->next) { 1100 if (uc->mfc_origin == c->mfc_origin &&
855 if (net_eq(mfc_net(uc), net) &&
856 uc->mfc_origin == c->mfc_origin &&
857 uc->mfc_mcastgrp == c->mfc_mcastgrp) { 1101 uc->mfc_mcastgrp == c->mfc_mcastgrp) {
858 *cp = uc->next; 1102 list_del(&uc->list);
859 atomic_dec(&net->ipv4.cache_resolve_queue_len); 1103 atomic_dec(&mrt->cache_resolve_queue_len);
1104 found = true;
860 break; 1105 break;
861 } 1106 }
862 } 1107 }
863 if (mfc_unres_queue == NULL) 1108 if (list_empty(&mrt->mfc_unres_queue))
864 del_timer(&ipmr_expire_timer); 1109 del_timer(&mrt->ipmr_expire_timer);
865 spin_unlock_bh(&mfc_unres_lock); 1110 spin_unlock_bh(&mfc_unres_lock);
866 1111
867 if (uc) { 1112 if (found) {
868 ipmr_cache_resolve(uc, c); 1113 ipmr_cache_resolve(net, mrt, uc, c);
869 ipmr_cache_free(uc); 1114 ipmr_cache_free(uc);
870 } 1115 }
871 return 0; 1116 return 0;
@@ -875,53 +1120,41 @@ static int ipmr_mfc_add(struct net *net, struct mfcctl *mfc, int mrtsock)
875 * Close the multicast socket, and clear the vif tables etc 1120 * Close the multicast socket, and clear the vif tables etc
876 */ 1121 */
877 1122
878static void mroute_clean_tables(struct net *net) 1123static void mroute_clean_tables(struct mr_table *mrt)
879{ 1124{
880 int i; 1125 int i;
881 LIST_HEAD(list); 1126 LIST_HEAD(list);
1127 struct mfc_cache *c, *next;
882 1128
883 /* 1129 /*
884 * Shut down all active vif entries 1130 * Shut down all active vif entries
885 */ 1131 */
886 for (i = 0; i < net->ipv4.maxvif; i++) { 1132 for (i = 0; i < mrt->maxvif; i++) {
887 if (!(net->ipv4.vif_table[i].flags&VIFF_STATIC)) 1133 if (!(mrt->vif_table[i].flags&VIFF_STATIC))
888 vif_delete(net, i, 0, &list); 1134 vif_delete(mrt, i, 0, &list);
889 } 1135 }
890 unregister_netdevice_many(&list); 1136 unregister_netdevice_many(&list);
891 1137
892 /* 1138 /*
893 * Wipe the cache 1139 * Wipe the cache
894 */ 1140 */
895 for (i=0; i<MFC_LINES; i++) { 1141 for (i = 0; i < MFC_LINES; i++) {
896 struct mfc_cache *c, **cp; 1142 list_for_each_entry_safe(c, next, &mrt->mfc_cache_array[i], list) {
897 1143 if (c->mfc_flags&MFC_STATIC)
898 cp = &net->ipv4.mfc_cache_array[i];
899 while ((c = *cp) != NULL) {
900 if (c->mfc_flags&MFC_STATIC) {
901 cp = &c->next;
902 continue; 1144 continue;
903 }
904 write_lock_bh(&mrt_lock); 1145 write_lock_bh(&mrt_lock);
905 *cp = c->next; 1146 list_del(&c->list);
906 write_unlock_bh(&mrt_lock); 1147 write_unlock_bh(&mrt_lock);
907 1148
908 ipmr_cache_free(c); 1149 ipmr_cache_free(c);
909 } 1150 }
910 } 1151 }
911 1152
912 if (atomic_read(&net->ipv4.cache_resolve_queue_len) != 0) { 1153 if (atomic_read(&mrt->cache_resolve_queue_len) != 0) {
913 struct mfc_cache *c, **cp;
914
915 spin_lock_bh(&mfc_unres_lock); 1154 spin_lock_bh(&mfc_unres_lock);
916 cp = &mfc_unres_queue; 1155 list_for_each_entry_safe(c, next, &mrt->mfc_unres_queue, list) {
917 while ((c = *cp) != NULL) { 1156 list_del(&c->list);
918 if (!net_eq(mfc_net(c), net)) { 1157 ipmr_destroy_unres(mrt, c);
919 cp = &c->next;
920 continue;
921 }
922 *cp = c->next;
923
924 ipmr_destroy_unres(c);
925 } 1158 }
926 spin_unlock_bh(&mfc_unres_lock); 1159 spin_unlock_bh(&mfc_unres_lock);
927 } 1160 }
@@ -930,16 +1163,19 @@ static void mroute_clean_tables(struct net *net)
930static void mrtsock_destruct(struct sock *sk) 1163static void mrtsock_destruct(struct sock *sk)
931{ 1164{
932 struct net *net = sock_net(sk); 1165 struct net *net = sock_net(sk);
1166 struct mr_table *mrt;
933 1167
934 rtnl_lock(); 1168 rtnl_lock();
935 if (sk == net->ipv4.mroute_sk) { 1169 ipmr_for_each_table(mrt, net) {
936 IPV4_DEVCONF_ALL(net, MC_FORWARDING)--; 1170 if (sk == mrt->mroute_sk) {
1171 IPV4_DEVCONF_ALL(net, MC_FORWARDING)--;
937 1172
938 write_lock_bh(&mrt_lock); 1173 write_lock_bh(&mrt_lock);
939 net->ipv4.mroute_sk = NULL; 1174 mrt->mroute_sk = NULL;
940 write_unlock_bh(&mrt_lock); 1175 write_unlock_bh(&mrt_lock);
941 1176
942 mroute_clean_tables(net); 1177 mroute_clean_tables(mrt);
1178 }
943 } 1179 }
944 rtnl_unlock(); 1180 rtnl_unlock();
945} 1181}
@@ -957,9 +1193,14 @@ int ip_mroute_setsockopt(struct sock *sk, int optname, char __user *optval, unsi
957 struct vifctl vif; 1193 struct vifctl vif;
958 struct mfcctl mfc; 1194 struct mfcctl mfc;
959 struct net *net = sock_net(sk); 1195 struct net *net = sock_net(sk);
1196 struct mr_table *mrt;
1197
1198 mrt = ipmr_get_table(net, raw_sk(sk)->ipmr_table ? : RT_TABLE_DEFAULT);
1199 if (mrt == NULL)
1200 return -ENOENT;
960 1201
961 if (optname != MRT_INIT) { 1202 if (optname != MRT_INIT) {
962 if (sk != net->ipv4.mroute_sk && !capable(CAP_NET_ADMIN)) 1203 if (sk != mrt->mroute_sk && !capable(CAP_NET_ADMIN))
963 return -EACCES; 1204 return -EACCES;
964 } 1205 }
965 1206
@@ -972,7 +1213,7 @@ int ip_mroute_setsockopt(struct sock *sk, int optname, char __user *optval, unsi
972 return -ENOPROTOOPT; 1213 return -ENOPROTOOPT;
973 1214
974 rtnl_lock(); 1215 rtnl_lock();
975 if (net->ipv4.mroute_sk) { 1216 if (mrt->mroute_sk) {
976 rtnl_unlock(); 1217 rtnl_unlock();
977 return -EADDRINUSE; 1218 return -EADDRINUSE;
978 } 1219 }
@@ -980,7 +1221,7 @@ int ip_mroute_setsockopt(struct sock *sk, int optname, char __user *optval, unsi
980 ret = ip_ra_control(sk, 1, mrtsock_destruct); 1221 ret = ip_ra_control(sk, 1, mrtsock_destruct);
981 if (ret == 0) { 1222 if (ret == 0) {
982 write_lock_bh(&mrt_lock); 1223 write_lock_bh(&mrt_lock);
983 net->ipv4.mroute_sk = sk; 1224 mrt->mroute_sk = sk;
984 write_unlock_bh(&mrt_lock); 1225 write_unlock_bh(&mrt_lock);
985 1226
986 IPV4_DEVCONF_ALL(net, MC_FORWARDING)++; 1227 IPV4_DEVCONF_ALL(net, MC_FORWARDING)++;
@@ -988,7 +1229,7 @@ int ip_mroute_setsockopt(struct sock *sk, int optname, char __user *optval, unsi
988 rtnl_unlock(); 1229 rtnl_unlock();
989 return ret; 1230 return ret;
990 case MRT_DONE: 1231 case MRT_DONE:
991 if (sk != net->ipv4.mroute_sk) 1232 if (sk != mrt->mroute_sk)
992 return -EACCES; 1233 return -EACCES;
993 return ip_ra_control(sk, 0, NULL); 1234 return ip_ra_control(sk, 0, NULL);
994 case MRT_ADD_VIF: 1235 case MRT_ADD_VIF:
@@ -1001,9 +1242,9 @@ int ip_mroute_setsockopt(struct sock *sk, int optname, char __user *optval, unsi
1001 return -ENFILE; 1242 return -ENFILE;
1002 rtnl_lock(); 1243 rtnl_lock();
1003 if (optname == MRT_ADD_VIF) { 1244 if (optname == MRT_ADD_VIF) {
1004 ret = vif_add(net, &vif, sk == net->ipv4.mroute_sk); 1245 ret = vif_add(net, mrt, &vif, sk == mrt->mroute_sk);
1005 } else { 1246 } else {
1006 ret = vif_delete(net, vif.vifc_vifi, 0, NULL); 1247 ret = vif_delete(mrt, vif.vifc_vifi, 0, NULL);
1007 } 1248 }
1008 rtnl_unlock(); 1249 rtnl_unlock();
1009 return ret; 1250 return ret;
@@ -1020,9 +1261,9 @@ int ip_mroute_setsockopt(struct sock *sk, int optname, char __user *optval, unsi
1020 return -EFAULT; 1261 return -EFAULT;
1021 rtnl_lock(); 1262 rtnl_lock();
1022 if (optname == MRT_DEL_MFC) 1263 if (optname == MRT_DEL_MFC)
1023 ret = ipmr_mfc_delete(net, &mfc); 1264 ret = ipmr_mfc_delete(mrt, &mfc);
1024 else 1265 else
1025 ret = ipmr_mfc_add(net, &mfc, sk == net->ipv4.mroute_sk); 1266 ret = ipmr_mfc_add(net, mrt, &mfc, sk == mrt->mroute_sk);
1026 rtnl_unlock(); 1267 rtnl_unlock();
1027 return ret; 1268 return ret;
1028 /* 1269 /*
@@ -1033,7 +1274,7 @@ int ip_mroute_setsockopt(struct sock *sk, int optname, char __user *optval, unsi
1033 int v; 1274 int v;
1034 if (get_user(v,(int __user *)optval)) 1275 if (get_user(v,(int __user *)optval))
1035 return -EFAULT; 1276 return -EFAULT;
1036 net->ipv4.mroute_do_assert = (v) ? 1 : 0; 1277 mrt->mroute_do_assert = (v) ? 1 : 0;
1037 return 0; 1278 return 0;
1038 } 1279 }
1039#ifdef CONFIG_IP_PIMSM 1280#ifdef CONFIG_IP_PIMSM
@@ -1047,14 +1288,35 @@ int ip_mroute_setsockopt(struct sock *sk, int optname, char __user *optval, unsi
1047 1288
1048 rtnl_lock(); 1289 rtnl_lock();
1049 ret = 0; 1290 ret = 0;
1050 if (v != net->ipv4.mroute_do_pim) { 1291 if (v != mrt->mroute_do_pim) {
1051 net->ipv4.mroute_do_pim = v; 1292 mrt->mroute_do_pim = v;
1052 net->ipv4.mroute_do_assert = v; 1293 mrt->mroute_do_assert = v;
1053 } 1294 }
1054 rtnl_unlock(); 1295 rtnl_unlock();
1055 return ret; 1296 return ret;
1056 } 1297 }
1057#endif 1298#endif
1299#ifdef CONFIG_IP_MROUTE_MULTIPLE_TABLES
1300 case MRT_TABLE:
1301 {
1302 u32 v;
1303
1304 if (optlen != sizeof(u32))
1305 return -EINVAL;
1306 if (get_user(v, (u32 __user *)optval))
1307 return -EFAULT;
1308 if (sk == mrt->mroute_sk)
1309 return -EBUSY;
1310
1311 rtnl_lock();
1312 ret = 0;
1313 if (!ipmr_new_table(net, v))
1314 ret = -ENOMEM;
1315 raw_sk(sk)->ipmr_table = v;
1316 rtnl_unlock();
1317 return ret;
1318 }
1319#endif
1058 /* 1320 /*
1059 * Spurious command, or MRT_VERSION which you cannot 1321 * Spurious command, or MRT_VERSION which you cannot
1060 * set. 1322 * set.
@@ -1073,6 +1335,11 @@ int ip_mroute_getsockopt(struct sock *sk, int optname, char __user *optval, int
1073 int olr; 1335 int olr;
1074 int val; 1336 int val;
1075 struct net *net = sock_net(sk); 1337 struct net *net = sock_net(sk);
1338 struct mr_table *mrt;
1339
1340 mrt = ipmr_get_table(net, raw_sk(sk)->ipmr_table ? : RT_TABLE_DEFAULT);
1341 if (mrt == NULL)
1342 return -ENOENT;
1076 1343
1077 if (optname != MRT_VERSION && 1344 if (optname != MRT_VERSION &&
1078#ifdef CONFIG_IP_PIMSM 1345#ifdef CONFIG_IP_PIMSM
@@ -1094,10 +1361,10 @@ int ip_mroute_getsockopt(struct sock *sk, int optname, char __user *optval, int
1094 val = 0x0305; 1361 val = 0x0305;
1095#ifdef CONFIG_IP_PIMSM 1362#ifdef CONFIG_IP_PIMSM
1096 else if (optname == MRT_PIM) 1363 else if (optname == MRT_PIM)
1097 val = net->ipv4.mroute_do_pim; 1364 val = mrt->mroute_do_pim;
1098#endif 1365#endif
1099 else 1366 else
1100 val = net->ipv4.mroute_do_assert; 1367 val = mrt->mroute_do_assert;
1101 if (copy_to_user(optval, &val, olr)) 1368 if (copy_to_user(optval, &val, olr))
1102 return -EFAULT; 1369 return -EFAULT;
1103 return 0; 1370 return 0;
@@ -1114,16 +1381,21 @@ int ipmr_ioctl(struct sock *sk, int cmd, void __user *arg)
1114 struct vif_device *vif; 1381 struct vif_device *vif;
1115 struct mfc_cache *c; 1382 struct mfc_cache *c;
1116 struct net *net = sock_net(sk); 1383 struct net *net = sock_net(sk);
1384 struct mr_table *mrt;
1385
1386 mrt = ipmr_get_table(net, raw_sk(sk)->ipmr_table ? : RT_TABLE_DEFAULT);
1387 if (mrt == NULL)
1388 return -ENOENT;
1117 1389
1118 switch (cmd) { 1390 switch (cmd) {
1119 case SIOCGETVIFCNT: 1391 case SIOCGETVIFCNT:
1120 if (copy_from_user(&vr, arg, sizeof(vr))) 1392 if (copy_from_user(&vr, arg, sizeof(vr)))
1121 return -EFAULT; 1393 return -EFAULT;
1122 if (vr.vifi >= net->ipv4.maxvif) 1394 if (vr.vifi >= mrt->maxvif)
1123 return -EINVAL; 1395 return -EINVAL;
1124 read_lock(&mrt_lock); 1396 read_lock(&mrt_lock);
1125 vif = &net->ipv4.vif_table[vr.vifi]; 1397 vif = &mrt->vif_table[vr.vifi];
1126 if (VIF_EXISTS(net, vr.vifi)) { 1398 if (VIF_EXISTS(mrt, vr.vifi)) {
1127 vr.icount = vif->pkt_in; 1399 vr.icount = vif->pkt_in;
1128 vr.ocount = vif->pkt_out; 1400 vr.ocount = vif->pkt_out;
1129 vr.ibytes = vif->bytes_in; 1401 vr.ibytes = vif->bytes_in;
@@ -1141,7 +1413,7 @@ int ipmr_ioctl(struct sock *sk, int cmd, void __user *arg)
1141 return -EFAULT; 1413 return -EFAULT;
1142 1414
1143 read_lock(&mrt_lock); 1415 read_lock(&mrt_lock);
1144 c = ipmr_cache_find(net, sr.src.s_addr, sr.grp.s_addr); 1416 c = ipmr_cache_find(mrt, sr.src.s_addr, sr.grp.s_addr);
1145 if (c) { 1417 if (c) {
1146 sr.pktcnt = c->mfc_un.res.pkt; 1418 sr.pktcnt = c->mfc_un.res.pkt;
1147 sr.bytecnt = c->mfc_un.res.bytes; 1419 sr.bytecnt = c->mfc_un.res.bytes;
@@ -1164,16 +1436,20 @@ static int ipmr_device_event(struct notifier_block *this, unsigned long event, v
1164{ 1436{
1165 struct net_device *dev = ptr; 1437 struct net_device *dev = ptr;
1166 struct net *net = dev_net(dev); 1438 struct net *net = dev_net(dev);
1439 struct mr_table *mrt;
1167 struct vif_device *v; 1440 struct vif_device *v;
1168 int ct; 1441 int ct;
1169 LIST_HEAD(list); 1442 LIST_HEAD(list);
1170 1443
1171 if (event != NETDEV_UNREGISTER) 1444 if (event != NETDEV_UNREGISTER)
1172 return NOTIFY_DONE; 1445 return NOTIFY_DONE;
1173 v = &net->ipv4.vif_table[0]; 1446
1174 for (ct = 0; ct < net->ipv4.maxvif; ct++, v++) { 1447 ipmr_for_each_table(mrt, net) {
1175 if (v->dev == dev) 1448 v = &mrt->vif_table[0];
1176 vif_delete(net, ct, 1, &list); 1449 for (ct = 0; ct < mrt->maxvif; ct++, v++) {
1450 if (v->dev == dev)
1451 vif_delete(mrt, ct, 1, &list);
1452 }
1177 } 1453 }
1178 unregister_netdevice_many(&list); 1454 unregister_netdevice_many(&list);
1179 return NOTIFY_DONE; 1455 return NOTIFY_DONE;
@@ -1232,11 +1508,11 @@ static inline int ipmr_forward_finish(struct sk_buff *skb)
1232 * Processing handlers for ipmr_forward 1508 * Processing handlers for ipmr_forward
1233 */ 1509 */
1234 1510
1235static void ipmr_queue_xmit(struct sk_buff *skb, struct mfc_cache *c, int vifi) 1511static void ipmr_queue_xmit(struct net *net, struct mr_table *mrt,
1512 struct sk_buff *skb, struct mfc_cache *c, int vifi)
1236{ 1513{
1237 struct net *net = mfc_net(c);
1238 const struct iphdr *iph = ip_hdr(skb); 1514 const struct iphdr *iph = ip_hdr(skb);
1239 struct vif_device *vif = &net->ipv4.vif_table[vifi]; 1515 struct vif_device *vif = &mrt->vif_table[vifi];
1240 struct net_device *dev; 1516 struct net_device *dev;
1241 struct rtable *rt; 1517 struct rtable *rt;
1242 int encap = 0; 1518 int encap = 0;
@@ -1250,7 +1526,7 @@ static void ipmr_queue_xmit(struct sk_buff *skb, struct mfc_cache *c, int vifi)
1250 vif->bytes_out += skb->len; 1526 vif->bytes_out += skb->len;
1251 vif->dev->stats.tx_bytes += skb->len; 1527 vif->dev->stats.tx_bytes += skb->len;
1252 vif->dev->stats.tx_packets++; 1528 vif->dev->stats.tx_packets++;
1253 ipmr_cache_report(net, skb, vifi, IGMPMSG_WHOLEPKT); 1529 ipmr_cache_report(mrt, skb, vifi, IGMPMSG_WHOLEPKT);
1254 goto out_free; 1530 goto out_free;
1255 } 1531 }
1256#endif 1532#endif
@@ -1324,21 +1600,20 @@ static void ipmr_queue_xmit(struct sk_buff *skb, struct mfc_cache *c, int vifi)
1324 * not mrouter) cannot join to more than one interface - it will 1600 * not mrouter) cannot join to more than one interface - it will
1325 * result in receiving multiple packets. 1601 * result in receiving multiple packets.
1326 */ 1602 */
1327 NF_HOOK(PF_INET, NF_INET_FORWARD, skb, skb->dev, dev, 1603 NF_HOOK(NFPROTO_IPV4, NF_INET_FORWARD, skb, skb->dev, dev,
1328 ipmr_forward_finish); 1604 ipmr_forward_finish);
1329 return; 1605 return;
1330 1606
1331out_free: 1607out_free:
1332 kfree_skb(skb); 1608 kfree_skb(skb);
1333 return;
1334} 1609}
1335 1610
1336static int ipmr_find_vif(struct net_device *dev) 1611static int ipmr_find_vif(struct mr_table *mrt, struct net_device *dev)
1337{ 1612{
1338 struct net *net = dev_net(dev);
1339 int ct; 1613 int ct;
1340 for (ct = net->ipv4.maxvif-1; ct >= 0; ct--) { 1614
1341 if (net->ipv4.vif_table[ct].dev == dev) 1615 for (ct = mrt->maxvif-1; ct >= 0; ct--) {
1616 if (mrt->vif_table[ct].dev == dev)
1342 break; 1617 break;
1343 } 1618 }
1344 return ct; 1619 return ct;
@@ -1346,11 +1621,12 @@ static int ipmr_find_vif(struct net_device *dev)
1346 1621
1347/* "local" means that we should preserve one skb (for local delivery) */ 1622/* "local" means that we should preserve one skb (for local delivery) */
1348 1623
1349static int ip_mr_forward(struct sk_buff *skb, struct mfc_cache *cache, int local) 1624static int ip_mr_forward(struct net *net, struct mr_table *mrt,
1625 struct sk_buff *skb, struct mfc_cache *cache,
1626 int local)
1350{ 1627{
1351 int psend = -1; 1628 int psend = -1;
1352 int vif, ct; 1629 int vif, ct;
1353 struct net *net = mfc_net(cache);
1354 1630
1355 vif = cache->mfc_parent; 1631 vif = cache->mfc_parent;
1356 cache->mfc_un.res.pkt++; 1632 cache->mfc_un.res.pkt++;
@@ -1359,7 +1635,7 @@ static int ip_mr_forward(struct sk_buff *skb, struct mfc_cache *cache, int local
1359 /* 1635 /*
1360 * Wrong interface: drop packet and (maybe) send PIM assert. 1636 * Wrong interface: drop packet and (maybe) send PIM assert.
1361 */ 1637 */
1362 if (net->ipv4.vif_table[vif].dev != skb->dev) { 1638 if (mrt->vif_table[vif].dev != skb->dev) {
1363 int true_vifi; 1639 int true_vifi;
1364 1640
1365 if (skb_rtable(skb)->fl.iif == 0) { 1641 if (skb_rtable(skb)->fl.iif == 0) {
@@ -1378,26 +1654,26 @@ static int ip_mr_forward(struct sk_buff *skb, struct mfc_cache *cache, int local
1378 } 1654 }
1379 1655
1380 cache->mfc_un.res.wrong_if++; 1656 cache->mfc_un.res.wrong_if++;
1381 true_vifi = ipmr_find_vif(skb->dev); 1657 true_vifi = ipmr_find_vif(mrt, skb->dev);
1382 1658
1383 if (true_vifi >= 0 && net->ipv4.mroute_do_assert && 1659 if (true_vifi >= 0 && mrt->mroute_do_assert &&
1384 /* pimsm uses asserts, when switching from RPT to SPT, 1660 /* pimsm uses asserts, when switching from RPT to SPT,
1385 so that we cannot check that packet arrived on an oif. 1661 so that we cannot check that packet arrived on an oif.
1386 It is bad, but otherwise we would need to move pretty 1662 It is bad, but otherwise we would need to move pretty
1387 large chunk of pimd to kernel. Ough... --ANK 1663 large chunk of pimd to kernel. Ough... --ANK
1388 */ 1664 */
1389 (net->ipv4.mroute_do_pim || 1665 (mrt->mroute_do_pim ||
1390 cache->mfc_un.res.ttls[true_vifi] < 255) && 1666 cache->mfc_un.res.ttls[true_vifi] < 255) &&
1391 time_after(jiffies, 1667 time_after(jiffies,
1392 cache->mfc_un.res.last_assert + MFC_ASSERT_THRESH)) { 1668 cache->mfc_un.res.last_assert + MFC_ASSERT_THRESH)) {
1393 cache->mfc_un.res.last_assert = jiffies; 1669 cache->mfc_un.res.last_assert = jiffies;
1394 ipmr_cache_report(net, skb, true_vifi, IGMPMSG_WRONGVIF); 1670 ipmr_cache_report(mrt, skb, true_vifi, IGMPMSG_WRONGVIF);
1395 } 1671 }
1396 goto dont_forward; 1672 goto dont_forward;
1397 } 1673 }
1398 1674
1399 net->ipv4.vif_table[vif].pkt_in++; 1675 mrt->vif_table[vif].pkt_in++;
1400 net->ipv4.vif_table[vif].bytes_in += skb->len; 1676 mrt->vif_table[vif].bytes_in += skb->len;
1401 1677
1402 /* 1678 /*
1403 * Forward the frame 1679 * Forward the frame
@@ -1407,7 +1683,8 @@ static int ip_mr_forward(struct sk_buff *skb, struct mfc_cache *cache, int local
1407 if (psend != -1) { 1683 if (psend != -1) {
1408 struct sk_buff *skb2 = skb_clone(skb, GFP_ATOMIC); 1684 struct sk_buff *skb2 = skb_clone(skb, GFP_ATOMIC);
1409 if (skb2) 1685 if (skb2)
1410 ipmr_queue_xmit(skb2, cache, psend); 1686 ipmr_queue_xmit(net, mrt, skb2, cache,
1687 psend);
1411 } 1688 }
1412 psend = ct; 1689 psend = ct;
1413 } 1690 }
@@ -1416,9 +1693,9 @@ static int ip_mr_forward(struct sk_buff *skb, struct mfc_cache *cache, int local
1416 if (local) { 1693 if (local) {
1417 struct sk_buff *skb2 = skb_clone(skb, GFP_ATOMIC); 1694 struct sk_buff *skb2 = skb_clone(skb, GFP_ATOMIC);
1418 if (skb2) 1695 if (skb2)
1419 ipmr_queue_xmit(skb2, cache, psend); 1696 ipmr_queue_xmit(net, mrt, skb2, cache, psend);
1420 } else { 1697 } else {
1421 ipmr_queue_xmit(skb, cache, psend); 1698 ipmr_queue_xmit(net, mrt, skb, cache, psend);
1422 return 0; 1699 return 0;
1423 } 1700 }
1424 } 1701 }
@@ -1439,6 +1716,8 @@ int ip_mr_input(struct sk_buff *skb)
1439 struct mfc_cache *cache; 1716 struct mfc_cache *cache;
1440 struct net *net = dev_net(skb->dev); 1717 struct net *net = dev_net(skb->dev);
1441 int local = skb_rtable(skb)->rt_flags & RTCF_LOCAL; 1718 int local = skb_rtable(skb)->rt_flags & RTCF_LOCAL;
1719 struct mr_table *mrt;
1720 int err;
1442 1721
1443 /* Packet is looped back after forward, it should not be 1722 /* Packet is looped back after forward, it should not be
1444 forwarded second time, but still can be delivered locally. 1723 forwarded second time, but still can be delivered locally.
@@ -1446,6 +1725,10 @@ int ip_mr_input(struct sk_buff *skb)
1446 if (IPCB(skb)->flags&IPSKB_FORWARDED) 1725 if (IPCB(skb)->flags&IPSKB_FORWARDED)
1447 goto dont_forward; 1726 goto dont_forward;
1448 1727
1728 err = ipmr_fib_lookup(net, &skb_rtable(skb)->fl, &mrt);
1729 if (err < 0)
1730 return err;
1731
1449 if (!local) { 1732 if (!local) {
1450 if (IPCB(skb)->opt.router_alert) { 1733 if (IPCB(skb)->opt.router_alert) {
1451 if (ip_call_ra_chain(skb)) 1734 if (ip_call_ra_chain(skb))
@@ -1458,9 +1741,9 @@ int ip_mr_input(struct sk_buff *skb)
1458 that we can forward NO IGMP messages. 1741 that we can forward NO IGMP messages.
1459 */ 1742 */
1460 read_lock(&mrt_lock); 1743 read_lock(&mrt_lock);
1461 if (net->ipv4.mroute_sk) { 1744 if (mrt->mroute_sk) {
1462 nf_reset(skb); 1745 nf_reset(skb);
1463 raw_rcv(net->ipv4.mroute_sk, skb); 1746 raw_rcv(mrt->mroute_sk, skb);
1464 read_unlock(&mrt_lock); 1747 read_unlock(&mrt_lock);
1465 return 0; 1748 return 0;
1466 } 1749 }
@@ -1469,7 +1752,7 @@ int ip_mr_input(struct sk_buff *skb)
1469 } 1752 }
1470 1753
1471 read_lock(&mrt_lock); 1754 read_lock(&mrt_lock);
1472 cache = ipmr_cache_find(net, ip_hdr(skb)->saddr, ip_hdr(skb)->daddr); 1755 cache = ipmr_cache_find(mrt, ip_hdr(skb)->saddr, ip_hdr(skb)->daddr);
1473 1756
1474 /* 1757 /*
1475 * No usable cache entry 1758 * No usable cache entry
@@ -1487,19 +1770,19 @@ int ip_mr_input(struct sk_buff *skb)
1487 skb = skb2; 1770 skb = skb2;
1488 } 1771 }
1489 1772
1490 vif = ipmr_find_vif(skb->dev); 1773 vif = ipmr_find_vif(mrt, skb->dev);
1491 if (vif >= 0) { 1774 if (vif >= 0) {
1492 int err = ipmr_cache_unresolved(net, vif, skb); 1775 int err2 = ipmr_cache_unresolved(mrt, vif, skb);
1493 read_unlock(&mrt_lock); 1776 read_unlock(&mrt_lock);
1494 1777
1495 return err; 1778 return err2;
1496 } 1779 }
1497 read_unlock(&mrt_lock); 1780 read_unlock(&mrt_lock);
1498 kfree_skb(skb); 1781 kfree_skb(skb);
1499 return -ENODEV; 1782 return -ENODEV;
1500 } 1783 }
1501 1784
1502 ip_mr_forward(skb, cache, local); 1785 ip_mr_forward(net, mrt, skb, cache, local);
1503 1786
1504 read_unlock(&mrt_lock); 1787 read_unlock(&mrt_lock);
1505 1788
@@ -1516,11 +1799,11 @@ dont_forward:
1516} 1799}
1517 1800
1518#ifdef CONFIG_IP_PIMSM 1801#ifdef CONFIG_IP_PIMSM
1519static int __pim_rcv(struct sk_buff *skb, unsigned int pimlen) 1802static int __pim_rcv(struct mr_table *mrt, struct sk_buff *skb,
1803 unsigned int pimlen)
1520{ 1804{
1521 struct net_device *reg_dev = NULL; 1805 struct net_device *reg_dev = NULL;
1522 struct iphdr *encap; 1806 struct iphdr *encap;
1523 struct net *net = dev_net(skb->dev);
1524 1807
1525 encap = (struct iphdr *)(skb_transport_header(skb) + pimlen); 1808 encap = (struct iphdr *)(skb_transport_header(skb) + pimlen);
1526 /* 1809 /*
@@ -1535,8 +1818,8 @@ static int __pim_rcv(struct sk_buff *skb, unsigned int pimlen)
1535 return 1; 1818 return 1;
1536 1819
1537 read_lock(&mrt_lock); 1820 read_lock(&mrt_lock);
1538 if (net->ipv4.mroute_reg_vif_num >= 0) 1821 if (mrt->mroute_reg_vif_num >= 0)
1539 reg_dev = net->ipv4.vif_table[net->ipv4.mroute_reg_vif_num].dev; 1822 reg_dev = mrt->vif_table[mrt->mroute_reg_vif_num].dev;
1540 if (reg_dev) 1823 if (reg_dev)
1541 dev_hold(reg_dev); 1824 dev_hold(reg_dev);
1542 read_unlock(&mrt_lock); 1825 read_unlock(&mrt_lock);
@@ -1547,14 +1830,12 @@ static int __pim_rcv(struct sk_buff *skb, unsigned int pimlen)
1547 skb->mac_header = skb->network_header; 1830 skb->mac_header = skb->network_header;
1548 skb_pull(skb, (u8*)encap - skb->data); 1831 skb_pull(skb, (u8*)encap - skb->data);
1549 skb_reset_network_header(skb); 1832 skb_reset_network_header(skb);
1550 skb->dev = reg_dev;
1551 skb->protocol = htons(ETH_P_IP); 1833 skb->protocol = htons(ETH_P_IP);
1552 skb->ip_summed = 0; 1834 skb->ip_summed = 0;
1553 skb->pkt_type = PACKET_HOST; 1835 skb->pkt_type = PACKET_HOST;
1554 skb_dst_drop(skb); 1836
1555 reg_dev->stats.rx_bytes += skb->len; 1837 skb_tunnel_rx(skb, reg_dev);
1556 reg_dev->stats.rx_packets++; 1838
1557 nf_reset(skb);
1558 netif_rx(skb); 1839 netif_rx(skb);
1559 dev_put(reg_dev); 1840 dev_put(reg_dev);
1560 1841
@@ -1571,17 +1852,21 @@ int pim_rcv_v1(struct sk_buff * skb)
1571{ 1852{
1572 struct igmphdr *pim; 1853 struct igmphdr *pim;
1573 struct net *net = dev_net(skb->dev); 1854 struct net *net = dev_net(skb->dev);
1855 struct mr_table *mrt;
1574 1856
1575 if (!pskb_may_pull(skb, sizeof(*pim) + sizeof(struct iphdr))) 1857 if (!pskb_may_pull(skb, sizeof(*pim) + sizeof(struct iphdr)))
1576 goto drop; 1858 goto drop;
1577 1859
1578 pim = igmp_hdr(skb); 1860 pim = igmp_hdr(skb);
1579 1861
1580 if (!net->ipv4.mroute_do_pim || 1862 if (ipmr_fib_lookup(net, &skb_rtable(skb)->fl, &mrt) < 0)
1863 goto drop;
1864
1865 if (!mrt->mroute_do_pim ||
1581 pim->group != PIM_V1_VERSION || pim->code != PIM_V1_REGISTER) 1866 pim->group != PIM_V1_VERSION || pim->code != PIM_V1_REGISTER)
1582 goto drop; 1867 goto drop;
1583 1868
1584 if (__pim_rcv(skb, sizeof(*pim))) { 1869 if (__pim_rcv(mrt, skb, sizeof(*pim))) {
1585drop: 1870drop:
1586 kfree_skb(skb); 1871 kfree_skb(skb);
1587 } 1872 }
@@ -1593,6 +1878,8 @@ drop:
1593static int pim_rcv(struct sk_buff * skb) 1878static int pim_rcv(struct sk_buff * skb)
1594{ 1879{
1595 struct pimreghdr *pim; 1880 struct pimreghdr *pim;
1881 struct net *net = dev_net(skb->dev);
1882 struct mr_table *mrt;
1596 1883
1597 if (!pskb_may_pull(skb, sizeof(*pim) + sizeof(struct iphdr))) 1884 if (!pskb_may_pull(skb, sizeof(*pim) + sizeof(struct iphdr)))
1598 goto drop; 1885 goto drop;
@@ -1604,7 +1891,10 @@ static int pim_rcv(struct sk_buff * skb)
1604 csum_fold(skb_checksum(skb, 0, skb->len, 0)))) 1891 csum_fold(skb_checksum(skb, 0, skb->len, 0))))
1605 goto drop; 1892 goto drop;
1606 1893
1607 if (__pim_rcv(skb, sizeof(*pim))) { 1894 if (ipmr_fib_lookup(net, &skb_rtable(skb)->fl, &mrt) < 0)
1895 goto drop;
1896
1897 if (__pim_rcv(mrt, skb, sizeof(*pim))) {
1608drop: 1898drop:
1609 kfree_skb(skb); 1899 kfree_skb(skb);
1610 } 1900 }
@@ -1612,12 +1902,11 @@ drop:
1612} 1902}
1613#endif 1903#endif
1614 1904
1615static int 1905static int __ipmr_fill_mroute(struct mr_table *mrt, struct sk_buff *skb,
1616ipmr_fill_mroute(struct sk_buff *skb, struct mfc_cache *c, struct rtmsg *rtm) 1906 struct mfc_cache *c, struct rtmsg *rtm)
1617{ 1907{
1618 int ct; 1908 int ct;
1619 struct rtnexthop *nhp; 1909 struct rtnexthop *nhp;
1620 struct net *net = mfc_net(c);
1621 u8 *b = skb_tail_pointer(skb); 1910 u8 *b = skb_tail_pointer(skb);
1622 struct rtattr *mp_head; 1911 struct rtattr *mp_head;
1623 1912
@@ -1625,19 +1914,19 @@ ipmr_fill_mroute(struct sk_buff *skb, struct mfc_cache *c, struct rtmsg *rtm)
1625 if (c->mfc_parent > MAXVIFS) 1914 if (c->mfc_parent > MAXVIFS)
1626 return -ENOENT; 1915 return -ENOENT;
1627 1916
1628 if (VIF_EXISTS(net, c->mfc_parent)) 1917 if (VIF_EXISTS(mrt, c->mfc_parent))
1629 RTA_PUT(skb, RTA_IIF, 4, &net->ipv4.vif_table[c->mfc_parent].dev->ifindex); 1918 RTA_PUT(skb, RTA_IIF, 4, &mrt->vif_table[c->mfc_parent].dev->ifindex);
1630 1919
1631 mp_head = (struct rtattr *)skb_put(skb, RTA_LENGTH(0)); 1920 mp_head = (struct rtattr *)skb_put(skb, RTA_LENGTH(0));
1632 1921
1633 for (ct = c->mfc_un.res.minvif; ct < c->mfc_un.res.maxvif; ct++) { 1922 for (ct = c->mfc_un.res.minvif; ct < c->mfc_un.res.maxvif; ct++) {
1634 if (VIF_EXISTS(net, ct) && c->mfc_un.res.ttls[ct] < 255) { 1923 if (VIF_EXISTS(mrt, ct) && c->mfc_un.res.ttls[ct] < 255) {
1635 if (skb_tailroom(skb) < RTA_ALIGN(RTA_ALIGN(sizeof(*nhp)) + 4)) 1924 if (skb_tailroom(skb) < RTA_ALIGN(RTA_ALIGN(sizeof(*nhp)) + 4))
1636 goto rtattr_failure; 1925 goto rtattr_failure;
1637 nhp = (struct rtnexthop *)skb_put(skb, RTA_ALIGN(sizeof(*nhp))); 1926 nhp = (struct rtnexthop *)skb_put(skb, RTA_ALIGN(sizeof(*nhp)));
1638 nhp->rtnh_flags = 0; 1927 nhp->rtnh_flags = 0;
1639 nhp->rtnh_hops = c->mfc_un.res.ttls[ct]; 1928 nhp->rtnh_hops = c->mfc_un.res.ttls[ct];
1640 nhp->rtnh_ifindex = net->ipv4.vif_table[ct].dev->ifindex; 1929 nhp->rtnh_ifindex = mrt->vif_table[ct].dev->ifindex;
1641 nhp->rtnh_len = sizeof(*nhp); 1930 nhp->rtnh_len = sizeof(*nhp);
1642 } 1931 }
1643 } 1932 }
@@ -1655,11 +1944,16 @@ int ipmr_get_route(struct net *net,
1655 struct sk_buff *skb, struct rtmsg *rtm, int nowait) 1944 struct sk_buff *skb, struct rtmsg *rtm, int nowait)
1656{ 1945{
1657 int err; 1946 int err;
1947 struct mr_table *mrt;
1658 struct mfc_cache *cache; 1948 struct mfc_cache *cache;
1659 struct rtable *rt = skb_rtable(skb); 1949 struct rtable *rt = skb_rtable(skb);
1660 1950
1951 mrt = ipmr_get_table(net, RT_TABLE_DEFAULT);
1952 if (mrt == NULL)
1953 return -ENOENT;
1954
1661 read_lock(&mrt_lock); 1955 read_lock(&mrt_lock);
1662 cache = ipmr_cache_find(net, rt->rt_src, rt->rt_dst); 1956 cache = ipmr_cache_find(mrt, rt->rt_src, rt->rt_dst);
1663 1957
1664 if (cache == NULL) { 1958 if (cache == NULL) {
1665 struct sk_buff *skb2; 1959 struct sk_buff *skb2;
@@ -1673,7 +1967,7 @@ int ipmr_get_route(struct net *net,
1673 } 1967 }
1674 1968
1675 dev = skb->dev; 1969 dev = skb->dev;
1676 if (dev == NULL || (vif = ipmr_find_vif(dev)) < 0) { 1970 if (dev == NULL || (vif = ipmr_find_vif(mrt, dev)) < 0) {
1677 read_unlock(&mrt_lock); 1971 read_unlock(&mrt_lock);
1678 return -ENODEV; 1972 return -ENODEV;
1679 } 1973 }
@@ -1690,24 +1984,107 @@ int ipmr_get_route(struct net *net,
1690 iph->saddr = rt->rt_src; 1984 iph->saddr = rt->rt_src;
1691 iph->daddr = rt->rt_dst; 1985 iph->daddr = rt->rt_dst;
1692 iph->version = 0; 1986 iph->version = 0;
1693 err = ipmr_cache_unresolved(net, vif, skb2); 1987 err = ipmr_cache_unresolved(mrt, vif, skb2);
1694 read_unlock(&mrt_lock); 1988 read_unlock(&mrt_lock);
1695 return err; 1989 return err;
1696 } 1990 }
1697 1991
1698 if (!nowait && (rtm->rtm_flags&RTM_F_NOTIFY)) 1992 if (!nowait && (rtm->rtm_flags&RTM_F_NOTIFY))
1699 cache->mfc_flags |= MFC_NOTIFY; 1993 cache->mfc_flags |= MFC_NOTIFY;
1700 err = ipmr_fill_mroute(skb, cache, rtm); 1994 err = __ipmr_fill_mroute(mrt, skb, cache, rtm);
1701 read_unlock(&mrt_lock); 1995 read_unlock(&mrt_lock);
1702 return err; 1996 return err;
1703} 1997}
1704 1998
1999static int ipmr_fill_mroute(struct mr_table *mrt, struct sk_buff *skb,
2000 u32 pid, u32 seq, struct mfc_cache *c)
2001{
2002 struct nlmsghdr *nlh;
2003 struct rtmsg *rtm;
2004
2005 nlh = nlmsg_put(skb, pid, seq, RTM_NEWROUTE, sizeof(*rtm), NLM_F_MULTI);
2006 if (nlh == NULL)
2007 return -EMSGSIZE;
2008
2009 rtm = nlmsg_data(nlh);
2010 rtm->rtm_family = RTNL_FAMILY_IPMR;
2011 rtm->rtm_dst_len = 32;
2012 rtm->rtm_src_len = 32;
2013 rtm->rtm_tos = 0;
2014 rtm->rtm_table = mrt->id;
2015 NLA_PUT_U32(skb, RTA_TABLE, mrt->id);
2016 rtm->rtm_type = RTN_MULTICAST;
2017 rtm->rtm_scope = RT_SCOPE_UNIVERSE;
2018 rtm->rtm_protocol = RTPROT_UNSPEC;
2019 rtm->rtm_flags = 0;
2020
2021 NLA_PUT_BE32(skb, RTA_SRC, c->mfc_origin);
2022 NLA_PUT_BE32(skb, RTA_DST, c->mfc_mcastgrp);
2023
2024 if (__ipmr_fill_mroute(mrt, skb, c, rtm) < 0)
2025 goto nla_put_failure;
2026
2027 return nlmsg_end(skb, nlh);
2028
2029nla_put_failure:
2030 nlmsg_cancel(skb, nlh);
2031 return -EMSGSIZE;
2032}
2033
2034static int ipmr_rtm_dumproute(struct sk_buff *skb, struct netlink_callback *cb)
2035{
2036 struct net *net = sock_net(skb->sk);
2037 struct mr_table *mrt;
2038 struct mfc_cache *mfc;
2039 unsigned int t = 0, s_t;
2040 unsigned int h = 0, s_h;
2041 unsigned int e = 0, s_e;
2042
2043 s_t = cb->args[0];
2044 s_h = cb->args[1];
2045 s_e = cb->args[2];
2046
2047 read_lock(&mrt_lock);
2048 ipmr_for_each_table(mrt, net) {
2049 if (t < s_t)
2050 goto next_table;
2051 if (t > s_t)
2052 s_h = 0;
2053 for (h = s_h; h < MFC_LINES; h++) {
2054 list_for_each_entry(mfc, &mrt->mfc_cache_array[h], list) {
2055 if (e < s_e)
2056 goto next_entry;
2057 if (ipmr_fill_mroute(mrt, skb,
2058 NETLINK_CB(cb->skb).pid,
2059 cb->nlh->nlmsg_seq,
2060 mfc) < 0)
2061 goto done;
2062next_entry:
2063 e++;
2064 }
2065 e = s_e = 0;
2066 }
2067 s_h = 0;
2068next_table:
2069 t++;
2070 }
2071done:
2072 read_unlock(&mrt_lock);
2073
2074 cb->args[2] = e;
2075 cb->args[1] = h;
2076 cb->args[0] = t;
2077
2078 return skb->len;
2079}
2080
1705#ifdef CONFIG_PROC_FS 2081#ifdef CONFIG_PROC_FS
1706/* 2082/*
1707 * The /proc interfaces to multicast routing /proc/ip_mr_cache /proc/ip_mr_vif 2083 * The /proc interfaces to multicast routing /proc/ip_mr_cache /proc/ip_mr_vif
1708 */ 2084 */
1709struct ipmr_vif_iter { 2085struct ipmr_vif_iter {
1710 struct seq_net_private p; 2086 struct seq_net_private p;
2087 struct mr_table *mrt;
1711 int ct; 2088 int ct;
1712}; 2089};
1713 2090
@@ -1715,11 +2092,13 @@ static struct vif_device *ipmr_vif_seq_idx(struct net *net,
1715 struct ipmr_vif_iter *iter, 2092 struct ipmr_vif_iter *iter,
1716 loff_t pos) 2093 loff_t pos)
1717{ 2094{
1718 for (iter->ct = 0; iter->ct < net->ipv4.maxvif; ++iter->ct) { 2095 struct mr_table *mrt = iter->mrt;
1719 if (!VIF_EXISTS(net, iter->ct)) 2096
2097 for (iter->ct = 0; iter->ct < mrt->maxvif; ++iter->ct) {
2098 if (!VIF_EXISTS(mrt, iter->ct))
1720 continue; 2099 continue;
1721 if (pos-- == 0) 2100 if (pos-- == 0)
1722 return &net->ipv4.vif_table[iter->ct]; 2101 return &mrt->vif_table[iter->ct];
1723 } 2102 }
1724 return NULL; 2103 return NULL;
1725} 2104}
@@ -1727,7 +2106,15 @@ static struct vif_device *ipmr_vif_seq_idx(struct net *net,
1727static void *ipmr_vif_seq_start(struct seq_file *seq, loff_t *pos) 2106static void *ipmr_vif_seq_start(struct seq_file *seq, loff_t *pos)
1728 __acquires(mrt_lock) 2107 __acquires(mrt_lock)
1729{ 2108{
2109 struct ipmr_vif_iter *iter = seq->private;
1730 struct net *net = seq_file_net(seq); 2110 struct net *net = seq_file_net(seq);
2111 struct mr_table *mrt;
2112
2113 mrt = ipmr_get_table(net, RT_TABLE_DEFAULT);
2114 if (mrt == NULL)
2115 return ERR_PTR(-ENOENT);
2116
2117 iter->mrt = mrt;
1731 2118
1732 read_lock(&mrt_lock); 2119 read_lock(&mrt_lock);
1733 return *pos ? ipmr_vif_seq_idx(net, seq->private, *pos - 1) 2120 return *pos ? ipmr_vif_seq_idx(net, seq->private, *pos - 1)
@@ -1738,15 +2125,16 @@ static void *ipmr_vif_seq_next(struct seq_file *seq, void *v, loff_t *pos)
1738{ 2125{
1739 struct ipmr_vif_iter *iter = seq->private; 2126 struct ipmr_vif_iter *iter = seq->private;
1740 struct net *net = seq_file_net(seq); 2127 struct net *net = seq_file_net(seq);
2128 struct mr_table *mrt = iter->mrt;
1741 2129
1742 ++*pos; 2130 ++*pos;
1743 if (v == SEQ_START_TOKEN) 2131 if (v == SEQ_START_TOKEN)
1744 return ipmr_vif_seq_idx(net, iter, 0); 2132 return ipmr_vif_seq_idx(net, iter, 0);
1745 2133
1746 while (++iter->ct < net->ipv4.maxvif) { 2134 while (++iter->ct < mrt->maxvif) {
1747 if (!VIF_EXISTS(net, iter->ct)) 2135 if (!VIF_EXISTS(mrt, iter->ct))
1748 continue; 2136 continue;
1749 return &net->ipv4.vif_table[iter->ct]; 2137 return &mrt->vif_table[iter->ct];
1750 } 2138 }
1751 return NULL; 2139 return NULL;
1752} 2140}
@@ -1759,7 +2147,8 @@ static void ipmr_vif_seq_stop(struct seq_file *seq, void *v)
1759 2147
1760static int ipmr_vif_seq_show(struct seq_file *seq, void *v) 2148static int ipmr_vif_seq_show(struct seq_file *seq, void *v)
1761{ 2149{
1762 struct net *net = seq_file_net(seq); 2150 struct ipmr_vif_iter *iter = seq->private;
2151 struct mr_table *mrt = iter->mrt;
1763 2152
1764 if (v == SEQ_START_TOKEN) { 2153 if (v == SEQ_START_TOKEN) {
1765 seq_puts(seq, 2154 seq_puts(seq,
@@ -1770,7 +2159,7 @@ static int ipmr_vif_seq_show(struct seq_file *seq, void *v)
1770 2159
1771 seq_printf(seq, 2160 seq_printf(seq,
1772 "%2Zd %-10s %8ld %7ld %8ld %7ld %05X %08X %08X\n", 2161 "%2Zd %-10s %8ld %7ld %8ld %7ld %05X %08X %08X\n",
1773 vif - net->ipv4.vif_table, 2162 vif - mrt->vif_table,
1774 name, vif->bytes_in, vif->pkt_in, 2163 name, vif->bytes_in, vif->pkt_in,
1775 vif->bytes_out, vif->pkt_out, 2164 vif->bytes_out, vif->pkt_out,
1776 vif->flags, vif->local, vif->remote); 2165 vif->flags, vif->local, vif->remote);
@@ -1801,7 +2190,8 @@ static const struct file_operations ipmr_vif_fops = {
1801 2190
1802struct ipmr_mfc_iter { 2191struct ipmr_mfc_iter {
1803 struct seq_net_private p; 2192 struct seq_net_private p;
1804 struct mfc_cache **cache; 2193 struct mr_table *mrt;
2194 struct list_head *cache;
1805 int ct; 2195 int ct;
1806}; 2196};
1807 2197
@@ -1809,22 +2199,22 @@ struct ipmr_mfc_iter {
1809static struct mfc_cache *ipmr_mfc_seq_idx(struct net *net, 2199static struct mfc_cache *ipmr_mfc_seq_idx(struct net *net,
1810 struct ipmr_mfc_iter *it, loff_t pos) 2200 struct ipmr_mfc_iter *it, loff_t pos)
1811{ 2201{
2202 struct mr_table *mrt = it->mrt;
1812 struct mfc_cache *mfc; 2203 struct mfc_cache *mfc;
1813 2204
1814 it->cache = net->ipv4.mfc_cache_array;
1815 read_lock(&mrt_lock); 2205 read_lock(&mrt_lock);
1816 for (it->ct = 0; it->ct < MFC_LINES; it->ct++) 2206 for (it->ct = 0; it->ct < MFC_LINES; it->ct++) {
1817 for (mfc = net->ipv4.mfc_cache_array[it->ct]; 2207 it->cache = &mrt->mfc_cache_array[it->ct];
1818 mfc; mfc = mfc->next) 2208 list_for_each_entry(mfc, it->cache, list)
1819 if (pos-- == 0) 2209 if (pos-- == 0)
1820 return mfc; 2210 return mfc;
2211 }
1821 read_unlock(&mrt_lock); 2212 read_unlock(&mrt_lock);
1822 2213
1823 it->cache = &mfc_unres_queue;
1824 spin_lock_bh(&mfc_unres_lock); 2214 spin_lock_bh(&mfc_unres_lock);
1825 for (mfc = mfc_unres_queue; mfc; mfc = mfc->next) 2215 it->cache = &mrt->mfc_unres_queue;
1826 if (net_eq(mfc_net(mfc), net) && 2216 list_for_each_entry(mfc, it->cache, list)
1827 pos-- == 0) 2217 if (pos-- == 0)
1828 return mfc; 2218 return mfc;
1829 spin_unlock_bh(&mfc_unres_lock); 2219 spin_unlock_bh(&mfc_unres_lock);
1830 2220
@@ -1837,7 +2227,13 @@ static void *ipmr_mfc_seq_start(struct seq_file *seq, loff_t *pos)
1837{ 2227{
1838 struct ipmr_mfc_iter *it = seq->private; 2228 struct ipmr_mfc_iter *it = seq->private;
1839 struct net *net = seq_file_net(seq); 2229 struct net *net = seq_file_net(seq);
2230 struct mr_table *mrt;
1840 2231
2232 mrt = ipmr_get_table(net, RT_TABLE_DEFAULT);
2233 if (mrt == NULL)
2234 return ERR_PTR(-ENOENT);
2235
2236 it->mrt = mrt;
1841 it->cache = NULL; 2237 it->cache = NULL;
1842 it->ct = 0; 2238 it->ct = 0;
1843 return *pos ? ipmr_mfc_seq_idx(net, seq->private, *pos - 1) 2239 return *pos ? ipmr_mfc_seq_idx(net, seq->private, *pos - 1)
@@ -1849,37 +2245,36 @@ static void *ipmr_mfc_seq_next(struct seq_file *seq, void *v, loff_t *pos)
1849 struct mfc_cache *mfc = v; 2245 struct mfc_cache *mfc = v;
1850 struct ipmr_mfc_iter *it = seq->private; 2246 struct ipmr_mfc_iter *it = seq->private;
1851 struct net *net = seq_file_net(seq); 2247 struct net *net = seq_file_net(seq);
2248 struct mr_table *mrt = it->mrt;
1852 2249
1853 ++*pos; 2250 ++*pos;
1854 2251
1855 if (v == SEQ_START_TOKEN) 2252 if (v == SEQ_START_TOKEN)
1856 return ipmr_mfc_seq_idx(net, seq->private, 0); 2253 return ipmr_mfc_seq_idx(net, seq->private, 0);
1857 2254
1858 if (mfc->next) 2255 if (mfc->list.next != it->cache)
1859 return mfc->next; 2256 return list_entry(mfc->list.next, struct mfc_cache, list);
1860 2257
1861 if (it->cache == &mfc_unres_queue) 2258 if (it->cache == &mrt->mfc_unres_queue)
1862 goto end_of_list; 2259 goto end_of_list;
1863 2260
1864 BUG_ON(it->cache != net->ipv4.mfc_cache_array); 2261 BUG_ON(it->cache != &mrt->mfc_cache_array[it->ct]);
1865 2262
1866 while (++it->ct < MFC_LINES) { 2263 while (++it->ct < MFC_LINES) {
1867 mfc = net->ipv4.mfc_cache_array[it->ct]; 2264 it->cache = &mrt->mfc_cache_array[it->ct];
1868 if (mfc) 2265 if (list_empty(it->cache))
1869 return mfc; 2266 continue;
2267 return list_first_entry(it->cache, struct mfc_cache, list);
1870 } 2268 }
1871 2269
1872 /* exhausted cache_array, show unresolved */ 2270 /* exhausted cache_array, show unresolved */
1873 read_unlock(&mrt_lock); 2271 read_unlock(&mrt_lock);
1874 it->cache = &mfc_unres_queue; 2272 it->cache = &mrt->mfc_unres_queue;
1875 it->ct = 0; 2273 it->ct = 0;
1876 2274
1877 spin_lock_bh(&mfc_unres_lock); 2275 spin_lock_bh(&mfc_unres_lock);
1878 mfc = mfc_unres_queue; 2276 if (!list_empty(it->cache))
1879 while (mfc && !net_eq(mfc_net(mfc), net)) 2277 return list_first_entry(it->cache, struct mfc_cache, list);
1880 mfc = mfc->next;
1881 if (mfc)
1882 return mfc;
1883 2278
1884 end_of_list: 2279 end_of_list:
1885 spin_unlock_bh(&mfc_unres_lock); 2280 spin_unlock_bh(&mfc_unres_lock);
@@ -1891,18 +2286,17 @@ static void *ipmr_mfc_seq_next(struct seq_file *seq, void *v, loff_t *pos)
1891static void ipmr_mfc_seq_stop(struct seq_file *seq, void *v) 2286static void ipmr_mfc_seq_stop(struct seq_file *seq, void *v)
1892{ 2287{
1893 struct ipmr_mfc_iter *it = seq->private; 2288 struct ipmr_mfc_iter *it = seq->private;
1894 struct net *net = seq_file_net(seq); 2289 struct mr_table *mrt = it->mrt;
1895 2290
1896 if (it->cache == &mfc_unres_queue) 2291 if (it->cache == &mrt->mfc_unres_queue)
1897 spin_unlock_bh(&mfc_unres_lock); 2292 spin_unlock_bh(&mfc_unres_lock);
1898 else if (it->cache == net->ipv4.mfc_cache_array) 2293 else if (it->cache == &mrt->mfc_cache_array[it->ct])
1899 read_unlock(&mrt_lock); 2294 read_unlock(&mrt_lock);
1900} 2295}
1901 2296
1902static int ipmr_mfc_seq_show(struct seq_file *seq, void *v) 2297static int ipmr_mfc_seq_show(struct seq_file *seq, void *v)
1903{ 2298{
1904 int n; 2299 int n;
1905 struct net *net = seq_file_net(seq);
1906 2300
1907 if (v == SEQ_START_TOKEN) { 2301 if (v == SEQ_START_TOKEN) {
1908 seq_puts(seq, 2302 seq_puts(seq,
@@ -1910,20 +2304,21 @@ static int ipmr_mfc_seq_show(struct seq_file *seq, void *v)
1910 } else { 2304 } else {
1911 const struct mfc_cache *mfc = v; 2305 const struct mfc_cache *mfc = v;
1912 const struct ipmr_mfc_iter *it = seq->private; 2306 const struct ipmr_mfc_iter *it = seq->private;
2307 const struct mr_table *mrt = it->mrt;
1913 2308
1914 seq_printf(seq, "%08lX %08lX %-3hd", 2309 seq_printf(seq, "%08X %08X %-3hd",
1915 (unsigned long) mfc->mfc_mcastgrp, 2310 (__force u32) mfc->mfc_mcastgrp,
1916 (unsigned long) mfc->mfc_origin, 2311 (__force u32) mfc->mfc_origin,
1917 mfc->mfc_parent); 2312 mfc->mfc_parent);
1918 2313
1919 if (it->cache != &mfc_unres_queue) { 2314 if (it->cache != &mrt->mfc_unres_queue) {
1920 seq_printf(seq, " %8lu %8lu %8lu", 2315 seq_printf(seq, " %8lu %8lu %8lu",
1921 mfc->mfc_un.res.pkt, 2316 mfc->mfc_un.res.pkt,
1922 mfc->mfc_un.res.bytes, 2317 mfc->mfc_un.res.bytes,
1923 mfc->mfc_un.res.wrong_if); 2318 mfc->mfc_un.res.wrong_if);
1924 for (n = mfc->mfc_un.res.minvif; 2319 for (n = mfc->mfc_un.res.minvif;
1925 n < mfc->mfc_un.res.maxvif; n++ ) { 2320 n < mfc->mfc_un.res.maxvif; n++ ) {
1926 if (VIF_EXISTS(net, n) && 2321 if (VIF_EXISTS(mrt, n) &&
1927 mfc->mfc_un.res.ttls[n] < 255) 2322 mfc->mfc_un.res.ttls[n] < 255)
1928 seq_printf(seq, 2323 seq_printf(seq,
1929 " %2d:%-3d", 2324 " %2d:%-3d",
@@ -1975,27 +2370,11 @@ static const struct net_protocol pim_protocol = {
1975 */ 2370 */
1976static int __net_init ipmr_net_init(struct net *net) 2371static int __net_init ipmr_net_init(struct net *net)
1977{ 2372{
1978 int err = 0; 2373 int err;
1979 2374
1980 net->ipv4.vif_table = kcalloc(MAXVIFS, sizeof(struct vif_device), 2375 err = ipmr_rules_init(net);
1981 GFP_KERNEL); 2376 if (err < 0)
1982 if (!net->ipv4.vif_table) {
1983 err = -ENOMEM;
1984 goto fail; 2377 goto fail;
1985 }
1986
1987 /* Forwarding cache */
1988 net->ipv4.mfc_cache_array = kcalloc(MFC_LINES,
1989 sizeof(struct mfc_cache *),
1990 GFP_KERNEL);
1991 if (!net->ipv4.mfc_cache_array) {
1992 err = -ENOMEM;
1993 goto fail_mfc_cache;
1994 }
1995
1996#ifdef CONFIG_IP_PIMSM
1997 net->ipv4.mroute_reg_vif_num = -1;
1998#endif
1999 2378
2000#ifdef CONFIG_PROC_FS 2379#ifdef CONFIG_PROC_FS
2001 err = -ENOMEM; 2380 err = -ENOMEM;
@@ -2010,10 +2389,8 @@ static int __net_init ipmr_net_init(struct net *net)
2010proc_cache_fail: 2389proc_cache_fail:
2011 proc_net_remove(net, "ip_mr_vif"); 2390 proc_net_remove(net, "ip_mr_vif");
2012proc_vif_fail: 2391proc_vif_fail:
2013 kfree(net->ipv4.mfc_cache_array); 2392 ipmr_rules_exit(net);
2014#endif 2393#endif
2015fail_mfc_cache:
2016 kfree(net->ipv4.vif_table);
2017fail: 2394fail:
2018 return err; 2395 return err;
2019} 2396}
@@ -2024,8 +2401,7 @@ static void __net_exit ipmr_net_exit(struct net *net)
2024 proc_net_remove(net, "ip_mr_cache"); 2401 proc_net_remove(net, "ip_mr_cache");
2025 proc_net_remove(net, "ip_mr_vif"); 2402 proc_net_remove(net, "ip_mr_vif");
2026#endif 2403#endif
2027 kfree(net->ipv4.mfc_cache_array); 2404 ipmr_rules_exit(net);
2028 kfree(net->ipv4.vif_table);
2029} 2405}
2030 2406
2031static struct pernet_operations ipmr_net_ops = { 2407static struct pernet_operations ipmr_net_ops = {
@@ -2048,7 +2424,6 @@ int __init ip_mr_init(void)
2048 if (err) 2424 if (err)
2049 goto reg_pernet_fail; 2425 goto reg_pernet_fail;
2050 2426
2051 setup_timer(&ipmr_expire_timer, ipmr_expire_process, 0);
2052 err = register_netdevice_notifier(&ip_mr_notifier); 2427 err = register_netdevice_notifier(&ip_mr_notifier);
2053 if (err) 2428 if (err)
2054 goto reg_notif_fail; 2429 goto reg_notif_fail;
@@ -2059,6 +2434,7 @@ int __init ip_mr_init(void)
2059 goto add_proto_fail; 2434 goto add_proto_fail;
2060 } 2435 }
2061#endif 2436#endif
2437 rtnl_register(RTNL_FAMILY_IPMR, RTM_GETROUTE, NULL, ipmr_rtm_dumproute);
2062 return 0; 2438 return 0;
2063 2439
2064#ifdef CONFIG_IP_PIMSM_V2 2440#ifdef CONFIG_IP_PIMSM_V2
@@ -2066,7 +2442,6 @@ add_proto_fail:
2066 unregister_netdevice_notifier(&ip_mr_notifier); 2442 unregister_netdevice_notifier(&ip_mr_notifier);
2067#endif 2443#endif
2068reg_notif_fail: 2444reg_notif_fail:
2069 del_timer(&ipmr_expire_timer);
2070 unregister_pernet_subsys(&ipmr_net_ops); 2445 unregister_pernet_subsys(&ipmr_net_ops);
2071reg_pernet_fail: 2446reg_pernet_fail:
2072 kmem_cache_destroy(mrt_cachep); 2447 kmem_cache_destroy(mrt_cachep);