diff options
Diffstat (limited to 'net/ipv4/ipmr.c')
-rw-r--r-- | net/ipv4/ipmr.c | 514 |
1 files changed, 307 insertions, 207 deletions
diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c index 14666449dc1c..c43ec2d51ce2 100644 --- a/net/ipv4/ipmr.c +++ b/net/ipv4/ipmr.c | |||
@@ -67,9 +67,6 @@ | |||
67 | #define CONFIG_IP_PIMSM 1 | 67 | #define CONFIG_IP_PIMSM 1 |
68 | #endif | 68 | #endif |
69 | 69 | ||
70 | static struct sock *mroute_socket; | ||
71 | |||
72 | |||
73 | /* Big lock, protecting vif table, mrt cache and mroute socket state. | 70 | /* Big lock, protecting vif table, mrt cache and mroute socket state. |
74 | Note that the changes are semaphored via rtnl_lock. | 71 | Note that the changes are semaphored via rtnl_lock. |
75 | */ | 72 | */ |
@@ -80,18 +77,9 @@ static DEFINE_RWLOCK(mrt_lock); | |||
80 | * Multicast router control variables | 77 | * Multicast router control variables |
81 | */ | 78 | */ |
82 | 79 | ||
83 | static struct vif_device vif_table[MAXVIFS]; /* Devices */ | 80 | #define VIF_EXISTS(_net, _idx) ((_net)->ipv4.vif_table[_idx].dev != NULL) |
84 | static int maxvif; | ||
85 | |||
86 | #define VIF_EXISTS(idx) (vif_table[idx].dev != NULL) | ||
87 | |||
88 | static int mroute_do_assert; /* Set in PIM assert */ | ||
89 | static int mroute_do_pim; | ||
90 | |||
91 | static struct mfc_cache *mfc_cache_array[MFC_LINES]; /* Forwarding cache */ | ||
92 | 81 | ||
93 | static struct mfc_cache *mfc_unres_queue; /* Queue of unresolved entries */ | 82 | static struct mfc_cache *mfc_unres_queue; /* Queue of unresolved entries */ |
94 | static atomic_t cache_resolve_queue_len; /* Size of unresolved */ | ||
95 | 83 | ||
96 | /* Special spinlock for queue of unresolved entries */ | 84 | /* Special spinlock for queue of unresolved entries */ |
97 | static DEFINE_SPINLOCK(mfc_unres_lock); | 85 | static DEFINE_SPINLOCK(mfc_unres_lock); |
@@ -107,22 +95,21 @@ static DEFINE_SPINLOCK(mfc_unres_lock); | |||
107 | static struct kmem_cache *mrt_cachep __read_mostly; | 95 | static struct kmem_cache *mrt_cachep __read_mostly; |
108 | 96 | ||
109 | static int ip_mr_forward(struct sk_buff *skb, struct mfc_cache *cache, int local); | 97 | static int ip_mr_forward(struct sk_buff *skb, struct mfc_cache *cache, int local); |
110 | static int ipmr_cache_report(struct sk_buff *pkt, vifi_t vifi, int assert); | 98 | static int ipmr_cache_report(struct net *net, |
99 | struct sk_buff *pkt, vifi_t vifi, int assert); | ||
111 | static int ipmr_fill_mroute(struct sk_buff *skb, struct mfc_cache *c, struct rtmsg *rtm); | 100 | static int ipmr_fill_mroute(struct sk_buff *skb, struct mfc_cache *c, struct rtmsg *rtm); |
112 | 101 | ||
113 | #ifdef CONFIG_IP_PIMSM_V2 | ||
114 | static struct net_protocol pim_protocol; | ||
115 | #endif | ||
116 | |||
117 | static struct timer_list ipmr_expire_timer; | 102 | static struct timer_list ipmr_expire_timer; |
118 | 103 | ||
119 | /* Service routines creating virtual interfaces: DVMRP tunnels and PIMREG */ | 104 | /* Service routines creating virtual interfaces: DVMRP tunnels and PIMREG */ |
120 | 105 | ||
121 | static void ipmr_del_tunnel(struct net_device *dev, struct vifctl *v) | 106 | static void ipmr_del_tunnel(struct net_device *dev, struct vifctl *v) |
122 | { | 107 | { |
108 | struct net *net = dev_net(dev); | ||
109 | |||
123 | dev_close(dev); | 110 | dev_close(dev); |
124 | 111 | ||
125 | dev = __dev_get_by_name(&init_net, "tunl0"); | 112 | dev = __dev_get_by_name(net, "tunl0"); |
126 | if (dev) { | 113 | if (dev) { |
127 | const struct net_device_ops *ops = dev->netdev_ops; | 114 | const struct net_device_ops *ops = dev->netdev_ops; |
128 | struct ifreq ifr; | 115 | struct ifreq ifr; |
@@ -148,11 +135,11 @@ static void ipmr_del_tunnel(struct net_device *dev, struct vifctl *v) | |||
148 | } | 135 | } |
149 | 136 | ||
150 | static | 137 | static |
151 | struct net_device *ipmr_new_tunnel(struct vifctl *v) | 138 | struct net_device *ipmr_new_tunnel(struct net *net, struct vifctl *v) |
152 | { | 139 | { |
153 | struct net_device *dev; | 140 | struct net_device *dev; |
154 | 141 | ||
155 | dev = __dev_get_by_name(&init_net, "tunl0"); | 142 | dev = __dev_get_by_name(net, "tunl0"); |
156 | 143 | ||
157 | if (dev) { | 144 | if (dev) { |
158 | const struct net_device_ops *ops = dev->netdev_ops; | 145 | const struct net_device_ops *ops = dev->netdev_ops; |
@@ -181,7 +168,8 @@ struct net_device *ipmr_new_tunnel(struct vifctl *v) | |||
181 | 168 | ||
182 | dev = NULL; | 169 | dev = NULL; |
183 | 170 | ||
184 | if (err == 0 && (dev = __dev_get_by_name(&init_net, p.name)) != NULL) { | 171 | if (err == 0 && |
172 | (dev = __dev_get_by_name(net, p.name)) != NULL) { | ||
185 | dev->flags |= IFF_MULTICAST; | 173 | dev->flags |= IFF_MULTICAST; |
186 | 174 | ||
187 | in_dev = __in_dev_get_rtnl(dev); | 175 | in_dev = __in_dev_get_rtnl(dev); |
@@ -209,17 +197,18 @@ failure: | |||
209 | 197 | ||
210 | #ifdef CONFIG_IP_PIMSM | 198 | #ifdef CONFIG_IP_PIMSM |
211 | 199 | ||
212 | static int reg_vif_num = -1; | 200 | static netdev_tx_t reg_vif_xmit(struct sk_buff *skb, struct net_device *dev) |
213 | |||
214 | static int reg_vif_xmit(struct sk_buff *skb, struct net_device *dev) | ||
215 | { | 201 | { |
202 | struct net *net = dev_net(dev); | ||
203 | |||
216 | read_lock(&mrt_lock); | 204 | read_lock(&mrt_lock); |
217 | dev->stats.tx_bytes += skb->len; | 205 | dev->stats.tx_bytes += skb->len; |
218 | dev->stats.tx_packets++; | 206 | dev->stats.tx_packets++; |
219 | ipmr_cache_report(skb, reg_vif_num, IGMPMSG_WHOLEPKT); | 207 | ipmr_cache_report(net, skb, net->ipv4.mroute_reg_vif_num, |
208 | IGMPMSG_WHOLEPKT); | ||
220 | read_unlock(&mrt_lock); | 209 | read_unlock(&mrt_lock); |
221 | kfree_skb(skb); | 210 | kfree_skb(skb); |
222 | return 0; | 211 | return NETDEV_TX_OK; |
223 | } | 212 | } |
224 | 213 | ||
225 | static const struct net_device_ops reg_vif_netdev_ops = { | 214 | static const struct net_device_ops reg_vif_netdev_ops = { |
@@ -233,9 +222,10 @@ static void reg_vif_setup(struct net_device *dev) | |||
233 | dev->flags = IFF_NOARP; | 222 | dev->flags = IFF_NOARP; |
234 | dev->netdev_ops = ®_vif_netdev_ops, | 223 | dev->netdev_ops = ®_vif_netdev_ops, |
235 | dev->destructor = free_netdev; | 224 | dev->destructor = free_netdev; |
225 | dev->features |= NETIF_F_NETNS_LOCAL; | ||
236 | } | 226 | } |
237 | 227 | ||
238 | static struct net_device *ipmr_reg_vif(void) | 228 | static struct net_device *ipmr_reg_vif(struct net *net) |
239 | { | 229 | { |
240 | struct net_device *dev; | 230 | struct net_device *dev; |
241 | struct in_device *in_dev; | 231 | struct in_device *in_dev; |
@@ -245,6 +235,8 @@ static struct net_device *ipmr_reg_vif(void) | |||
245 | if (dev == NULL) | 235 | if (dev == NULL) |
246 | return NULL; | 236 | return NULL; |
247 | 237 | ||
238 | dev_net_set(dev, net); | ||
239 | |||
248 | if (register_netdevice(dev)) { | 240 | if (register_netdevice(dev)) { |
249 | free_netdev(dev); | 241 | free_netdev(dev); |
250 | return NULL; | 242 | return NULL; |
@@ -283,16 +275,16 @@ failure: | |||
283 | * @notify: Set to 1, if the caller is a notifier_call | 275 | * @notify: Set to 1, if the caller is a notifier_call |
284 | */ | 276 | */ |
285 | 277 | ||
286 | static int vif_delete(int vifi, int notify) | 278 | static int vif_delete(struct net *net, int vifi, int notify) |
287 | { | 279 | { |
288 | struct vif_device *v; | 280 | struct vif_device *v; |
289 | struct net_device *dev; | 281 | struct net_device *dev; |
290 | struct in_device *in_dev; | 282 | struct in_device *in_dev; |
291 | 283 | ||
292 | if (vifi < 0 || vifi >= maxvif) | 284 | if (vifi < 0 || vifi >= net->ipv4.maxvif) |
293 | return -EADDRNOTAVAIL; | 285 | return -EADDRNOTAVAIL; |
294 | 286 | ||
295 | v = &vif_table[vifi]; | 287 | v = &net->ipv4.vif_table[vifi]; |
296 | 288 | ||
297 | write_lock_bh(&mrt_lock); | 289 | write_lock_bh(&mrt_lock); |
298 | dev = v->dev; | 290 | dev = v->dev; |
@@ -304,17 +296,17 @@ static int vif_delete(int vifi, int notify) | |||
304 | } | 296 | } |
305 | 297 | ||
306 | #ifdef CONFIG_IP_PIMSM | 298 | #ifdef CONFIG_IP_PIMSM |
307 | if (vifi == reg_vif_num) | 299 | if (vifi == net->ipv4.mroute_reg_vif_num) |
308 | reg_vif_num = -1; | 300 | net->ipv4.mroute_reg_vif_num = -1; |
309 | #endif | 301 | #endif |
310 | 302 | ||
311 | if (vifi+1 == maxvif) { | 303 | if (vifi+1 == net->ipv4.maxvif) { |
312 | int tmp; | 304 | int tmp; |
313 | for (tmp=vifi-1; tmp>=0; tmp--) { | 305 | for (tmp=vifi-1; tmp>=0; tmp--) { |
314 | if (VIF_EXISTS(tmp)) | 306 | if (VIF_EXISTS(net, tmp)) |
315 | break; | 307 | break; |
316 | } | 308 | } |
317 | maxvif = tmp+1; | 309 | net->ipv4.maxvif = tmp+1; |
318 | } | 310 | } |
319 | 311 | ||
320 | write_unlock_bh(&mrt_lock); | 312 | write_unlock_bh(&mrt_lock); |
@@ -333,6 +325,12 @@ static int vif_delete(int vifi, int notify) | |||
333 | return 0; | 325 | return 0; |
334 | } | 326 | } |
335 | 327 | ||
328 | static inline void ipmr_cache_free(struct mfc_cache *c) | ||
329 | { | ||
330 | release_net(mfc_net(c)); | ||
331 | kmem_cache_free(mrt_cachep, c); | ||
332 | } | ||
333 | |||
336 | /* Destroy an unresolved cache entry, killing queued skbs | 334 | /* Destroy an unresolved cache entry, killing queued skbs |
337 | and reporting error to netlink readers. | 335 | and reporting error to netlink readers. |
338 | */ | 336 | */ |
@@ -341,8 +339,9 @@ static void ipmr_destroy_unres(struct mfc_cache *c) | |||
341 | { | 339 | { |
342 | struct sk_buff *skb; | 340 | struct sk_buff *skb; |
343 | struct nlmsgerr *e; | 341 | struct nlmsgerr *e; |
342 | struct net *net = mfc_net(c); | ||
344 | 343 | ||
345 | atomic_dec(&cache_resolve_queue_len); | 344 | atomic_dec(&net->ipv4.cache_resolve_queue_len); |
346 | 345 | ||
347 | while ((skb = skb_dequeue(&c->mfc_un.unres.unresolved))) { | 346 | while ((skb = skb_dequeue(&c->mfc_un.unres.unresolved))) { |
348 | if (ip_hdr(skb)->version == 0) { | 347 | if (ip_hdr(skb)->version == 0) { |
@@ -354,12 +353,12 @@ static void ipmr_destroy_unres(struct mfc_cache *c) | |||
354 | e->error = -ETIMEDOUT; | 353 | e->error = -ETIMEDOUT; |
355 | memset(&e->msg, 0, sizeof(e->msg)); | 354 | memset(&e->msg, 0, sizeof(e->msg)); |
356 | 355 | ||
357 | rtnl_unicast(skb, &init_net, NETLINK_CB(skb).pid); | 356 | rtnl_unicast(skb, net, NETLINK_CB(skb).pid); |
358 | } else | 357 | } else |
359 | kfree_skb(skb); | 358 | kfree_skb(skb); |
360 | } | 359 | } |
361 | 360 | ||
362 | kmem_cache_free(mrt_cachep, c); | 361 | ipmr_cache_free(c); |
363 | } | 362 | } |
364 | 363 | ||
365 | 364 | ||
@@ -376,7 +375,7 @@ static void ipmr_expire_process(unsigned long dummy) | |||
376 | return; | 375 | return; |
377 | } | 376 | } |
378 | 377 | ||
379 | if (atomic_read(&cache_resolve_queue_len) == 0) | 378 | if (mfc_unres_queue == NULL) |
380 | goto out; | 379 | goto out; |
381 | 380 | ||
382 | now = jiffies; | 381 | now = jiffies; |
@@ -397,7 +396,7 @@ static void ipmr_expire_process(unsigned long dummy) | |||
397 | ipmr_destroy_unres(c); | 396 | ipmr_destroy_unres(c); |
398 | } | 397 | } |
399 | 398 | ||
400 | if (atomic_read(&cache_resolve_queue_len)) | 399 | if (mfc_unres_queue != NULL) |
401 | mod_timer(&ipmr_expire_timer, jiffies + expires); | 400 | mod_timer(&ipmr_expire_timer, jiffies + expires); |
402 | 401 | ||
403 | out: | 402 | out: |
@@ -409,13 +408,15 @@ out: | |||
409 | static void ipmr_update_thresholds(struct mfc_cache *cache, unsigned char *ttls) | 408 | static void ipmr_update_thresholds(struct mfc_cache *cache, unsigned char *ttls) |
410 | { | 409 | { |
411 | int vifi; | 410 | int vifi; |
411 | struct net *net = mfc_net(cache); | ||
412 | 412 | ||
413 | cache->mfc_un.res.minvif = MAXVIFS; | 413 | cache->mfc_un.res.minvif = MAXVIFS; |
414 | cache->mfc_un.res.maxvif = 0; | 414 | cache->mfc_un.res.maxvif = 0; |
415 | memset(cache->mfc_un.res.ttls, 255, MAXVIFS); | 415 | memset(cache->mfc_un.res.ttls, 255, MAXVIFS); |
416 | 416 | ||
417 | for (vifi=0; vifi<maxvif; vifi++) { | 417 | for (vifi = 0; vifi < net->ipv4.maxvif; vifi++) { |
418 | if (VIF_EXISTS(vifi) && ttls[vifi] && ttls[vifi] < 255) { | 418 | if (VIF_EXISTS(net, vifi) && |
419 | ttls[vifi] && ttls[vifi] < 255) { | ||
419 | cache->mfc_un.res.ttls[vifi] = ttls[vifi]; | 420 | cache->mfc_un.res.ttls[vifi] = ttls[vifi]; |
420 | if (cache->mfc_un.res.minvif > vifi) | 421 | if (cache->mfc_un.res.minvif > vifi) |
421 | cache->mfc_un.res.minvif = vifi; | 422 | cache->mfc_un.res.minvif = vifi; |
@@ -425,16 +426,16 @@ static void ipmr_update_thresholds(struct mfc_cache *cache, unsigned char *ttls) | |||
425 | } | 426 | } |
426 | } | 427 | } |
427 | 428 | ||
428 | static int vif_add(struct vifctl *vifc, int mrtsock) | 429 | static int vif_add(struct net *net, struct vifctl *vifc, int mrtsock) |
429 | { | 430 | { |
430 | int vifi = vifc->vifc_vifi; | 431 | int vifi = vifc->vifc_vifi; |
431 | struct vif_device *v = &vif_table[vifi]; | 432 | struct vif_device *v = &net->ipv4.vif_table[vifi]; |
432 | struct net_device *dev; | 433 | struct net_device *dev; |
433 | struct in_device *in_dev; | 434 | struct in_device *in_dev; |
434 | int err; | 435 | int err; |
435 | 436 | ||
436 | /* Is vif busy ? */ | 437 | /* Is vif busy ? */ |
437 | if (VIF_EXISTS(vifi)) | 438 | if (VIF_EXISTS(net, vifi)) |
438 | return -EADDRINUSE; | 439 | return -EADDRINUSE; |
439 | 440 | ||
440 | switch (vifc->vifc_flags) { | 441 | switch (vifc->vifc_flags) { |
@@ -444,9 +445,9 @@ static int vif_add(struct vifctl *vifc, int mrtsock) | |||
444 | * Special Purpose VIF in PIM | 445 | * Special Purpose VIF in PIM |
445 | * All the packets will be sent to the daemon | 446 | * All the packets will be sent to the daemon |
446 | */ | 447 | */ |
447 | if (reg_vif_num >= 0) | 448 | if (net->ipv4.mroute_reg_vif_num >= 0) |
448 | return -EADDRINUSE; | 449 | return -EADDRINUSE; |
449 | dev = ipmr_reg_vif(); | 450 | dev = ipmr_reg_vif(net); |
450 | if (!dev) | 451 | if (!dev) |
451 | return -ENOBUFS; | 452 | return -ENOBUFS; |
452 | err = dev_set_allmulti(dev, 1); | 453 | err = dev_set_allmulti(dev, 1); |
@@ -458,7 +459,7 @@ static int vif_add(struct vifctl *vifc, int mrtsock) | |||
458 | break; | 459 | break; |
459 | #endif | 460 | #endif |
460 | case VIFF_TUNNEL: | 461 | case VIFF_TUNNEL: |
461 | dev = ipmr_new_tunnel(vifc); | 462 | dev = ipmr_new_tunnel(net, vifc); |
462 | if (!dev) | 463 | if (!dev) |
463 | return -ENOBUFS; | 464 | return -ENOBUFS; |
464 | err = dev_set_allmulti(dev, 1); | 465 | err = dev_set_allmulti(dev, 1); |
@@ -469,7 +470,7 @@ static int vif_add(struct vifctl *vifc, int mrtsock) | |||
469 | } | 470 | } |
470 | break; | 471 | break; |
471 | case 0: | 472 | case 0: |
472 | dev = ip_dev_find(&init_net, vifc->vifc_lcl_addr.s_addr); | 473 | dev = ip_dev_find(net, vifc->vifc_lcl_addr.s_addr); |
473 | if (!dev) | 474 | if (!dev) |
474 | return -EADDRNOTAVAIL; | 475 | return -EADDRNOTAVAIL; |
475 | err = dev_set_allmulti(dev, 1); | 476 | err = dev_set_allmulti(dev, 1); |
@@ -510,20 +511,22 @@ static int vif_add(struct vifctl *vifc, int mrtsock) | |||
510 | v->dev = dev; | 511 | v->dev = dev; |
511 | #ifdef CONFIG_IP_PIMSM | 512 | #ifdef CONFIG_IP_PIMSM |
512 | if (v->flags&VIFF_REGISTER) | 513 | if (v->flags&VIFF_REGISTER) |
513 | reg_vif_num = vifi; | 514 | net->ipv4.mroute_reg_vif_num = vifi; |
514 | #endif | 515 | #endif |
515 | if (vifi+1 > maxvif) | 516 | if (vifi+1 > net->ipv4.maxvif) |
516 | maxvif = vifi+1; | 517 | net->ipv4.maxvif = vifi+1; |
517 | write_unlock_bh(&mrt_lock); | 518 | write_unlock_bh(&mrt_lock); |
518 | return 0; | 519 | return 0; |
519 | } | 520 | } |
520 | 521 | ||
521 | static struct mfc_cache *ipmr_cache_find(__be32 origin, __be32 mcastgrp) | 522 | static struct mfc_cache *ipmr_cache_find(struct net *net, |
523 | __be32 origin, | ||
524 | __be32 mcastgrp) | ||
522 | { | 525 | { |
523 | int line = MFC_HASH(mcastgrp, origin); | 526 | int line = MFC_HASH(mcastgrp, origin); |
524 | struct mfc_cache *c; | 527 | struct mfc_cache *c; |
525 | 528 | ||
526 | for (c=mfc_cache_array[line]; c; c = c->next) { | 529 | for (c = net->ipv4.mfc_cache_array[line]; c; c = c->next) { |
527 | if (c->mfc_origin==origin && c->mfc_mcastgrp==mcastgrp) | 530 | if (c->mfc_origin==origin && c->mfc_mcastgrp==mcastgrp) |
528 | break; | 531 | break; |
529 | } | 532 | } |
@@ -533,22 +536,24 @@ static struct mfc_cache *ipmr_cache_find(__be32 origin, __be32 mcastgrp) | |||
533 | /* | 536 | /* |
534 | * Allocate a multicast cache entry | 537 | * Allocate a multicast cache entry |
535 | */ | 538 | */ |
536 | static struct mfc_cache *ipmr_cache_alloc(void) | 539 | static struct mfc_cache *ipmr_cache_alloc(struct net *net) |
537 | { | 540 | { |
538 | struct mfc_cache *c = kmem_cache_zalloc(mrt_cachep, GFP_KERNEL); | 541 | struct mfc_cache *c = kmem_cache_zalloc(mrt_cachep, GFP_KERNEL); |
539 | if (c == NULL) | 542 | if (c == NULL) |
540 | return NULL; | 543 | return NULL; |
541 | c->mfc_un.res.minvif = MAXVIFS; | 544 | c->mfc_un.res.minvif = MAXVIFS; |
545 | mfc_net_set(c, net); | ||
542 | return c; | 546 | return c; |
543 | } | 547 | } |
544 | 548 | ||
545 | static struct mfc_cache *ipmr_cache_alloc_unres(void) | 549 | static struct mfc_cache *ipmr_cache_alloc_unres(struct net *net) |
546 | { | 550 | { |
547 | struct mfc_cache *c = kmem_cache_zalloc(mrt_cachep, GFP_ATOMIC); | 551 | struct mfc_cache *c = kmem_cache_zalloc(mrt_cachep, GFP_ATOMIC); |
548 | if (c == NULL) | 552 | if (c == NULL) |
549 | return NULL; | 553 | return NULL; |
550 | skb_queue_head_init(&c->mfc_un.unres.unresolved); | 554 | skb_queue_head_init(&c->mfc_un.unres.unresolved); |
551 | c->mfc_un.unres.expires = jiffies + 10*HZ; | 555 | c->mfc_un.unres.expires = jiffies + 10*HZ; |
556 | mfc_net_set(c, net); | ||
552 | return c; | 557 | return c; |
553 | } | 558 | } |
554 | 559 | ||
@@ -581,7 +586,7 @@ static void ipmr_cache_resolve(struct mfc_cache *uc, struct mfc_cache *c) | |||
581 | memset(&e->msg, 0, sizeof(e->msg)); | 586 | memset(&e->msg, 0, sizeof(e->msg)); |
582 | } | 587 | } |
583 | 588 | ||
584 | rtnl_unicast(skb, &init_net, NETLINK_CB(skb).pid); | 589 | rtnl_unicast(skb, mfc_net(c), NETLINK_CB(skb).pid); |
585 | } else | 590 | } else |
586 | ip_mr_forward(skb, c, 0); | 591 | ip_mr_forward(skb, c, 0); |
587 | } | 592 | } |
@@ -594,7 +599,8 @@ static void ipmr_cache_resolve(struct mfc_cache *uc, struct mfc_cache *c) | |||
594 | * Called under mrt_lock. | 599 | * Called under mrt_lock. |
595 | */ | 600 | */ |
596 | 601 | ||
597 | static int ipmr_cache_report(struct sk_buff *pkt, vifi_t vifi, int assert) | 602 | static int ipmr_cache_report(struct net *net, |
603 | struct sk_buff *pkt, vifi_t vifi, int assert) | ||
598 | { | 604 | { |
599 | struct sk_buff *skb; | 605 | struct sk_buff *skb; |
600 | const int ihl = ip_hdrlen(pkt); | 606 | const int ihl = ip_hdrlen(pkt); |
@@ -626,7 +632,7 @@ static int ipmr_cache_report(struct sk_buff *pkt, vifi_t vifi, int assert) | |||
626 | memcpy(msg, skb_network_header(pkt), sizeof(struct iphdr)); | 632 | memcpy(msg, skb_network_header(pkt), sizeof(struct iphdr)); |
627 | msg->im_msgtype = IGMPMSG_WHOLEPKT; | 633 | msg->im_msgtype = IGMPMSG_WHOLEPKT; |
628 | msg->im_mbz = 0; | 634 | msg->im_mbz = 0; |
629 | msg->im_vif = reg_vif_num; | 635 | msg->im_vif = net->ipv4.mroute_reg_vif_num; |
630 | ip_hdr(skb)->ihl = sizeof(struct iphdr) >> 2; | 636 | ip_hdr(skb)->ihl = sizeof(struct iphdr) >> 2; |
631 | ip_hdr(skb)->tot_len = htons(ntohs(ip_hdr(pkt)->tot_len) + | 637 | ip_hdr(skb)->tot_len = htons(ntohs(ip_hdr(pkt)->tot_len) + |
632 | sizeof(struct iphdr)); | 638 | sizeof(struct iphdr)); |
@@ -644,7 +650,7 @@ static int ipmr_cache_report(struct sk_buff *pkt, vifi_t vifi, int assert) | |||
644 | ip_hdr(skb)->protocol = 0; /* Flag to the kernel this is a route add */ | 650 | ip_hdr(skb)->protocol = 0; /* Flag to the kernel this is a route add */ |
645 | msg = (struct igmpmsg *)skb_network_header(skb); | 651 | msg = (struct igmpmsg *)skb_network_header(skb); |
646 | msg->im_vif = vifi; | 652 | msg->im_vif = vifi; |
647 | skb->dst = dst_clone(pkt->dst); | 653 | skb_dst_set(skb, dst_clone(skb_dst(pkt))); |
648 | 654 | ||
649 | /* | 655 | /* |
650 | * Add our header | 656 | * Add our header |
@@ -658,7 +664,7 @@ static int ipmr_cache_report(struct sk_buff *pkt, vifi_t vifi, int assert) | |||
658 | skb->transport_header = skb->network_header; | 664 | skb->transport_header = skb->network_header; |
659 | } | 665 | } |
660 | 666 | ||
661 | if (mroute_socket == NULL) { | 667 | if (net->ipv4.mroute_sk == NULL) { |
662 | kfree_skb(skb); | 668 | kfree_skb(skb); |
663 | return -EINVAL; | 669 | return -EINVAL; |
664 | } | 670 | } |
@@ -666,7 +672,8 @@ static int ipmr_cache_report(struct sk_buff *pkt, vifi_t vifi, int assert) | |||
666 | /* | 672 | /* |
667 | * Deliver to mrouted | 673 | * Deliver to mrouted |
668 | */ | 674 | */ |
669 | if ((ret = sock_queue_rcv_skb(mroute_socket, skb))<0) { | 675 | ret = sock_queue_rcv_skb(net->ipv4.mroute_sk, skb); |
676 | if (ret < 0) { | ||
670 | if (net_ratelimit()) | 677 | if (net_ratelimit()) |
671 | printk(KERN_WARNING "mroute: pending queue full, dropping entries.\n"); | 678 | printk(KERN_WARNING "mroute: pending queue full, dropping entries.\n"); |
672 | kfree_skb(skb); | 679 | kfree_skb(skb); |
@@ -680,7 +687,7 @@ static int ipmr_cache_report(struct sk_buff *pkt, vifi_t vifi, int assert) | |||
680 | */ | 687 | */ |
681 | 688 | ||
682 | static int | 689 | static int |
683 | ipmr_cache_unresolved(vifi_t vifi, struct sk_buff *skb) | 690 | ipmr_cache_unresolved(struct net *net, vifi_t vifi, struct sk_buff *skb) |
684 | { | 691 | { |
685 | int err; | 692 | int err; |
686 | struct mfc_cache *c; | 693 | struct mfc_cache *c; |
@@ -688,7 +695,8 @@ ipmr_cache_unresolved(vifi_t vifi, struct sk_buff *skb) | |||
688 | 695 | ||
689 | spin_lock_bh(&mfc_unres_lock); | 696 | spin_lock_bh(&mfc_unres_lock); |
690 | for (c=mfc_unres_queue; c; c=c->next) { | 697 | for (c=mfc_unres_queue; c; c=c->next) { |
691 | if (c->mfc_mcastgrp == iph->daddr && | 698 | if (net_eq(mfc_net(c), net) && |
699 | c->mfc_mcastgrp == iph->daddr && | ||
692 | c->mfc_origin == iph->saddr) | 700 | c->mfc_origin == iph->saddr) |
693 | break; | 701 | break; |
694 | } | 702 | } |
@@ -698,8 +706,8 @@ ipmr_cache_unresolved(vifi_t vifi, struct sk_buff *skb) | |||
698 | * Create a new entry if allowable | 706 | * Create a new entry if allowable |
699 | */ | 707 | */ |
700 | 708 | ||
701 | if (atomic_read(&cache_resolve_queue_len) >= 10 || | 709 | if (atomic_read(&net->ipv4.cache_resolve_queue_len) >= 10 || |
702 | (c=ipmr_cache_alloc_unres())==NULL) { | 710 | (c = ipmr_cache_alloc_unres(net)) == NULL) { |
703 | spin_unlock_bh(&mfc_unres_lock); | 711 | spin_unlock_bh(&mfc_unres_lock); |
704 | 712 | ||
705 | kfree_skb(skb); | 713 | kfree_skb(skb); |
@@ -716,18 +724,19 @@ ipmr_cache_unresolved(vifi_t vifi, struct sk_buff *skb) | |||
716 | /* | 724 | /* |
717 | * Reflect first query at mrouted. | 725 | * Reflect first query at mrouted. |
718 | */ | 726 | */ |
719 | if ((err = ipmr_cache_report(skb, vifi, IGMPMSG_NOCACHE))<0) { | 727 | err = ipmr_cache_report(net, skb, vifi, IGMPMSG_NOCACHE); |
728 | if (err < 0) { | ||
720 | /* If the report failed throw the cache entry | 729 | /* If the report failed throw the cache entry |
721 | out - Brad Parker | 730 | out - Brad Parker |
722 | */ | 731 | */ |
723 | spin_unlock_bh(&mfc_unres_lock); | 732 | spin_unlock_bh(&mfc_unres_lock); |
724 | 733 | ||
725 | kmem_cache_free(mrt_cachep, c); | 734 | ipmr_cache_free(c); |
726 | kfree_skb(skb); | 735 | kfree_skb(skb); |
727 | return err; | 736 | return err; |
728 | } | 737 | } |
729 | 738 | ||
730 | atomic_inc(&cache_resolve_queue_len); | 739 | atomic_inc(&net->ipv4.cache_resolve_queue_len); |
731 | c->next = mfc_unres_queue; | 740 | c->next = mfc_unres_queue; |
732 | mfc_unres_queue = c; | 741 | mfc_unres_queue = c; |
733 | 742 | ||
@@ -753,35 +762,37 @@ ipmr_cache_unresolved(vifi_t vifi, struct sk_buff *skb) | |||
753 | * MFC cache manipulation by user space mroute daemon | 762 | * MFC cache manipulation by user space mroute daemon |
754 | */ | 763 | */ |
755 | 764 | ||
756 | static int ipmr_mfc_delete(struct mfcctl *mfc) | 765 | static int ipmr_mfc_delete(struct net *net, struct mfcctl *mfc) |
757 | { | 766 | { |
758 | int line; | 767 | int line; |
759 | struct mfc_cache *c, **cp; | 768 | struct mfc_cache *c, **cp; |
760 | 769 | ||
761 | line = MFC_HASH(mfc->mfcc_mcastgrp.s_addr, mfc->mfcc_origin.s_addr); | 770 | line = MFC_HASH(mfc->mfcc_mcastgrp.s_addr, mfc->mfcc_origin.s_addr); |
762 | 771 | ||
763 | for (cp=&mfc_cache_array[line]; (c=*cp) != NULL; cp = &c->next) { | 772 | for (cp = &net->ipv4.mfc_cache_array[line]; |
773 | (c = *cp) != NULL; cp = &c->next) { | ||
764 | if (c->mfc_origin == mfc->mfcc_origin.s_addr && | 774 | if (c->mfc_origin == mfc->mfcc_origin.s_addr && |
765 | c->mfc_mcastgrp == mfc->mfcc_mcastgrp.s_addr) { | 775 | c->mfc_mcastgrp == mfc->mfcc_mcastgrp.s_addr) { |
766 | write_lock_bh(&mrt_lock); | 776 | write_lock_bh(&mrt_lock); |
767 | *cp = c->next; | 777 | *cp = c->next; |
768 | write_unlock_bh(&mrt_lock); | 778 | write_unlock_bh(&mrt_lock); |
769 | 779 | ||
770 | kmem_cache_free(mrt_cachep, c); | 780 | ipmr_cache_free(c); |
771 | return 0; | 781 | return 0; |
772 | } | 782 | } |
773 | } | 783 | } |
774 | return -ENOENT; | 784 | return -ENOENT; |
775 | } | 785 | } |
776 | 786 | ||
777 | static int ipmr_mfc_add(struct mfcctl *mfc, int mrtsock) | 787 | static int ipmr_mfc_add(struct net *net, struct mfcctl *mfc, int mrtsock) |
778 | { | 788 | { |
779 | int line; | 789 | int line; |
780 | struct mfc_cache *uc, *c, **cp; | 790 | struct mfc_cache *uc, *c, **cp; |
781 | 791 | ||
782 | line = MFC_HASH(mfc->mfcc_mcastgrp.s_addr, mfc->mfcc_origin.s_addr); | 792 | line = MFC_HASH(mfc->mfcc_mcastgrp.s_addr, mfc->mfcc_origin.s_addr); |
783 | 793 | ||
784 | for (cp=&mfc_cache_array[line]; (c=*cp) != NULL; cp = &c->next) { | 794 | for (cp = &net->ipv4.mfc_cache_array[line]; |
795 | (c = *cp) != NULL; cp = &c->next) { | ||
785 | if (c->mfc_origin == mfc->mfcc_origin.s_addr && | 796 | if (c->mfc_origin == mfc->mfcc_origin.s_addr && |
786 | c->mfc_mcastgrp == mfc->mfcc_mcastgrp.s_addr) | 797 | c->mfc_mcastgrp == mfc->mfcc_mcastgrp.s_addr) |
787 | break; | 798 | break; |
@@ -800,7 +811,7 @@ static int ipmr_mfc_add(struct mfcctl *mfc, int mrtsock) | |||
800 | if (!ipv4_is_multicast(mfc->mfcc_mcastgrp.s_addr)) | 811 | if (!ipv4_is_multicast(mfc->mfcc_mcastgrp.s_addr)) |
801 | return -EINVAL; | 812 | return -EINVAL; |
802 | 813 | ||
803 | c = ipmr_cache_alloc(); | 814 | c = ipmr_cache_alloc(net); |
804 | if (c == NULL) | 815 | if (c == NULL) |
805 | return -ENOMEM; | 816 | return -ENOMEM; |
806 | 817 | ||
@@ -812,8 +823,8 @@ static int ipmr_mfc_add(struct mfcctl *mfc, int mrtsock) | |||
812 | c->mfc_flags |= MFC_STATIC; | 823 | c->mfc_flags |= MFC_STATIC; |
813 | 824 | ||
814 | write_lock_bh(&mrt_lock); | 825 | write_lock_bh(&mrt_lock); |
815 | c->next = mfc_cache_array[line]; | 826 | c->next = net->ipv4.mfc_cache_array[line]; |
816 | mfc_cache_array[line] = c; | 827 | net->ipv4.mfc_cache_array[line] = c; |
817 | write_unlock_bh(&mrt_lock); | 828 | write_unlock_bh(&mrt_lock); |
818 | 829 | ||
819 | /* | 830 | /* |
@@ -823,19 +834,21 @@ static int ipmr_mfc_add(struct mfcctl *mfc, int mrtsock) | |||
823 | spin_lock_bh(&mfc_unres_lock); | 834 | spin_lock_bh(&mfc_unres_lock); |
824 | for (cp = &mfc_unres_queue; (uc=*cp) != NULL; | 835 | for (cp = &mfc_unres_queue; (uc=*cp) != NULL; |
825 | cp = &uc->next) { | 836 | cp = &uc->next) { |
826 | if (uc->mfc_origin == c->mfc_origin && | 837 | if (net_eq(mfc_net(uc), net) && |
838 | uc->mfc_origin == c->mfc_origin && | ||
827 | uc->mfc_mcastgrp == c->mfc_mcastgrp) { | 839 | uc->mfc_mcastgrp == c->mfc_mcastgrp) { |
828 | *cp = uc->next; | 840 | *cp = uc->next; |
829 | if (atomic_dec_and_test(&cache_resolve_queue_len)) | 841 | atomic_dec(&net->ipv4.cache_resolve_queue_len); |
830 | del_timer(&ipmr_expire_timer); | ||
831 | break; | 842 | break; |
832 | } | 843 | } |
833 | } | 844 | } |
845 | if (mfc_unres_queue == NULL) | ||
846 | del_timer(&ipmr_expire_timer); | ||
834 | spin_unlock_bh(&mfc_unres_lock); | 847 | spin_unlock_bh(&mfc_unres_lock); |
835 | 848 | ||
836 | if (uc) { | 849 | if (uc) { |
837 | ipmr_cache_resolve(uc, c); | 850 | ipmr_cache_resolve(uc, c); |
838 | kmem_cache_free(mrt_cachep, uc); | 851 | ipmr_cache_free(uc); |
839 | } | 852 | } |
840 | return 0; | 853 | return 0; |
841 | } | 854 | } |
@@ -844,16 +857,16 @@ static int ipmr_mfc_add(struct mfcctl *mfc, int mrtsock) | |||
844 | * Close the multicast socket, and clear the vif tables etc | 857 | * Close the multicast socket, and clear the vif tables etc |
845 | */ | 858 | */ |
846 | 859 | ||
847 | static void mroute_clean_tables(struct sock *sk) | 860 | static void mroute_clean_tables(struct net *net) |
848 | { | 861 | { |
849 | int i; | 862 | int i; |
850 | 863 | ||
851 | /* | 864 | /* |
852 | * Shut down all active vif entries | 865 | * Shut down all active vif entries |
853 | */ | 866 | */ |
854 | for (i=0; i<maxvif; i++) { | 867 | for (i = 0; i < net->ipv4.maxvif; i++) { |
855 | if (!(vif_table[i].flags&VIFF_STATIC)) | 868 | if (!(net->ipv4.vif_table[i].flags&VIFF_STATIC)) |
856 | vif_delete(i, 0); | 869 | vif_delete(net, i, 0); |
857 | } | 870 | } |
858 | 871 | ||
859 | /* | 872 | /* |
@@ -862,7 +875,7 @@ static void mroute_clean_tables(struct sock *sk) | |||
862 | for (i=0; i<MFC_LINES; i++) { | 875 | for (i=0; i<MFC_LINES; i++) { |
863 | struct mfc_cache *c, **cp; | 876 | struct mfc_cache *c, **cp; |
864 | 877 | ||
865 | cp = &mfc_cache_array[i]; | 878 | cp = &net->ipv4.mfc_cache_array[i]; |
866 | while ((c = *cp) != NULL) { | 879 | while ((c = *cp) != NULL) { |
867 | if (c->mfc_flags&MFC_STATIC) { | 880 | if (c->mfc_flags&MFC_STATIC) { |
868 | cp = &c->next; | 881 | cp = &c->next; |
@@ -872,22 +885,23 @@ static void mroute_clean_tables(struct sock *sk) | |||
872 | *cp = c->next; | 885 | *cp = c->next; |
873 | write_unlock_bh(&mrt_lock); | 886 | write_unlock_bh(&mrt_lock); |
874 | 887 | ||
875 | kmem_cache_free(mrt_cachep, c); | 888 | ipmr_cache_free(c); |
876 | } | 889 | } |
877 | } | 890 | } |
878 | 891 | ||
879 | if (atomic_read(&cache_resolve_queue_len) != 0) { | 892 | if (atomic_read(&net->ipv4.cache_resolve_queue_len) != 0) { |
880 | struct mfc_cache *c; | 893 | struct mfc_cache *c, **cp; |
881 | 894 | ||
882 | spin_lock_bh(&mfc_unres_lock); | 895 | spin_lock_bh(&mfc_unres_lock); |
883 | while (mfc_unres_queue != NULL) { | 896 | cp = &mfc_unres_queue; |
884 | c = mfc_unres_queue; | 897 | while ((c = *cp) != NULL) { |
885 | mfc_unres_queue = c->next; | 898 | if (!net_eq(mfc_net(c), net)) { |
886 | spin_unlock_bh(&mfc_unres_lock); | 899 | cp = &c->next; |
900 | continue; | ||
901 | } | ||
902 | *cp = c->next; | ||
887 | 903 | ||
888 | ipmr_destroy_unres(c); | 904 | ipmr_destroy_unres(c); |
889 | |||
890 | spin_lock_bh(&mfc_unres_lock); | ||
891 | } | 905 | } |
892 | spin_unlock_bh(&mfc_unres_lock); | 906 | spin_unlock_bh(&mfc_unres_lock); |
893 | } | 907 | } |
@@ -895,15 +909,17 @@ static void mroute_clean_tables(struct sock *sk) | |||
895 | 909 | ||
896 | static void mrtsock_destruct(struct sock *sk) | 910 | static void mrtsock_destruct(struct sock *sk) |
897 | { | 911 | { |
912 | struct net *net = sock_net(sk); | ||
913 | |||
898 | rtnl_lock(); | 914 | rtnl_lock(); |
899 | if (sk == mroute_socket) { | 915 | if (sk == net->ipv4.mroute_sk) { |
900 | IPV4_DEVCONF_ALL(sock_net(sk), MC_FORWARDING)--; | 916 | IPV4_DEVCONF_ALL(net, MC_FORWARDING)--; |
901 | 917 | ||
902 | write_lock_bh(&mrt_lock); | 918 | write_lock_bh(&mrt_lock); |
903 | mroute_socket = NULL; | 919 | net->ipv4.mroute_sk = NULL; |
904 | write_unlock_bh(&mrt_lock); | 920 | write_unlock_bh(&mrt_lock); |
905 | 921 | ||
906 | mroute_clean_tables(sk); | 922 | mroute_clean_tables(net); |
907 | } | 923 | } |
908 | rtnl_unlock(); | 924 | rtnl_unlock(); |
909 | } | 925 | } |
@@ -920,9 +936,10 @@ int ip_mroute_setsockopt(struct sock *sk, int optname, char __user *optval, int | |||
920 | int ret; | 936 | int ret; |
921 | struct vifctl vif; | 937 | struct vifctl vif; |
922 | struct mfcctl mfc; | 938 | struct mfcctl mfc; |
939 | struct net *net = sock_net(sk); | ||
923 | 940 | ||
924 | if (optname != MRT_INIT) { | 941 | if (optname != MRT_INIT) { |
925 | if (sk != mroute_socket && !capable(CAP_NET_ADMIN)) | 942 | if (sk != net->ipv4.mroute_sk && !capable(CAP_NET_ADMIN)) |
926 | return -EACCES; | 943 | return -EACCES; |
927 | } | 944 | } |
928 | 945 | ||
@@ -935,7 +952,7 @@ int ip_mroute_setsockopt(struct sock *sk, int optname, char __user *optval, int | |||
935 | return -ENOPROTOOPT; | 952 | return -ENOPROTOOPT; |
936 | 953 | ||
937 | rtnl_lock(); | 954 | rtnl_lock(); |
938 | if (mroute_socket) { | 955 | if (net->ipv4.mroute_sk) { |
939 | rtnl_unlock(); | 956 | rtnl_unlock(); |
940 | return -EADDRINUSE; | 957 | return -EADDRINUSE; |
941 | } | 958 | } |
@@ -943,15 +960,15 @@ int ip_mroute_setsockopt(struct sock *sk, int optname, char __user *optval, int | |||
943 | ret = ip_ra_control(sk, 1, mrtsock_destruct); | 960 | ret = ip_ra_control(sk, 1, mrtsock_destruct); |
944 | if (ret == 0) { | 961 | if (ret == 0) { |
945 | write_lock_bh(&mrt_lock); | 962 | write_lock_bh(&mrt_lock); |
946 | mroute_socket = sk; | 963 | net->ipv4.mroute_sk = sk; |
947 | write_unlock_bh(&mrt_lock); | 964 | write_unlock_bh(&mrt_lock); |
948 | 965 | ||
949 | IPV4_DEVCONF_ALL(sock_net(sk), MC_FORWARDING)++; | 966 | IPV4_DEVCONF_ALL(net, MC_FORWARDING)++; |
950 | } | 967 | } |
951 | rtnl_unlock(); | 968 | rtnl_unlock(); |
952 | return ret; | 969 | return ret; |
953 | case MRT_DONE: | 970 | case MRT_DONE: |
954 | if (sk != mroute_socket) | 971 | if (sk != net->ipv4.mroute_sk) |
955 | return -EACCES; | 972 | return -EACCES; |
956 | return ip_ra_control(sk, 0, NULL); | 973 | return ip_ra_control(sk, 0, NULL); |
957 | case MRT_ADD_VIF: | 974 | case MRT_ADD_VIF: |
@@ -964,9 +981,9 @@ int ip_mroute_setsockopt(struct sock *sk, int optname, char __user *optval, int | |||
964 | return -ENFILE; | 981 | return -ENFILE; |
965 | rtnl_lock(); | 982 | rtnl_lock(); |
966 | if (optname == MRT_ADD_VIF) { | 983 | if (optname == MRT_ADD_VIF) { |
967 | ret = vif_add(&vif, sk==mroute_socket); | 984 | ret = vif_add(net, &vif, sk == net->ipv4.mroute_sk); |
968 | } else { | 985 | } else { |
969 | ret = vif_delete(vif.vifc_vifi, 0); | 986 | ret = vif_delete(net, vif.vifc_vifi, 0); |
970 | } | 987 | } |
971 | rtnl_unlock(); | 988 | rtnl_unlock(); |
972 | return ret; | 989 | return ret; |
@@ -983,9 +1000,9 @@ int ip_mroute_setsockopt(struct sock *sk, int optname, char __user *optval, int | |||
983 | return -EFAULT; | 1000 | return -EFAULT; |
984 | rtnl_lock(); | 1001 | rtnl_lock(); |
985 | if (optname == MRT_DEL_MFC) | 1002 | if (optname == MRT_DEL_MFC) |
986 | ret = ipmr_mfc_delete(&mfc); | 1003 | ret = ipmr_mfc_delete(net, &mfc); |
987 | else | 1004 | else |
988 | ret = ipmr_mfc_add(&mfc, sk==mroute_socket); | 1005 | ret = ipmr_mfc_add(net, &mfc, sk == net->ipv4.mroute_sk); |
989 | rtnl_unlock(); | 1006 | rtnl_unlock(); |
990 | return ret; | 1007 | return ret; |
991 | /* | 1008 | /* |
@@ -996,7 +1013,7 @@ int ip_mroute_setsockopt(struct sock *sk, int optname, char __user *optval, int | |||
996 | int v; | 1013 | int v; |
997 | if (get_user(v,(int __user *)optval)) | 1014 | if (get_user(v,(int __user *)optval)) |
998 | return -EFAULT; | 1015 | return -EFAULT; |
999 | mroute_do_assert=(v)?1:0; | 1016 | net->ipv4.mroute_do_assert = (v) ? 1 : 0; |
1000 | return 0; | 1017 | return 0; |
1001 | } | 1018 | } |
1002 | #ifdef CONFIG_IP_PIMSM | 1019 | #ifdef CONFIG_IP_PIMSM |
@@ -1010,19 +1027,9 @@ int ip_mroute_setsockopt(struct sock *sk, int optname, char __user *optval, int | |||
1010 | 1027 | ||
1011 | rtnl_lock(); | 1028 | rtnl_lock(); |
1012 | ret = 0; | 1029 | ret = 0; |
1013 | if (v != mroute_do_pim) { | 1030 | if (v != net->ipv4.mroute_do_pim) { |
1014 | mroute_do_pim = v; | 1031 | net->ipv4.mroute_do_pim = v; |
1015 | mroute_do_assert = v; | 1032 | net->ipv4.mroute_do_assert = v; |
1016 | #ifdef CONFIG_IP_PIMSM_V2 | ||
1017 | if (mroute_do_pim) | ||
1018 | ret = inet_add_protocol(&pim_protocol, | ||
1019 | IPPROTO_PIM); | ||
1020 | else | ||
1021 | ret = inet_del_protocol(&pim_protocol, | ||
1022 | IPPROTO_PIM); | ||
1023 | if (ret < 0) | ||
1024 | ret = -EAGAIN; | ||
1025 | #endif | ||
1026 | } | 1033 | } |
1027 | rtnl_unlock(); | 1034 | rtnl_unlock(); |
1028 | return ret; | 1035 | return ret; |
@@ -1045,6 +1052,7 @@ int ip_mroute_getsockopt(struct sock *sk, int optname, char __user *optval, int | |||
1045 | { | 1052 | { |
1046 | int olr; | 1053 | int olr; |
1047 | int val; | 1054 | int val; |
1055 | struct net *net = sock_net(sk); | ||
1048 | 1056 | ||
1049 | if (optname != MRT_VERSION && | 1057 | if (optname != MRT_VERSION && |
1050 | #ifdef CONFIG_IP_PIMSM | 1058 | #ifdef CONFIG_IP_PIMSM |
@@ -1066,10 +1074,10 @@ int ip_mroute_getsockopt(struct sock *sk, int optname, char __user *optval, int | |||
1066 | val = 0x0305; | 1074 | val = 0x0305; |
1067 | #ifdef CONFIG_IP_PIMSM | 1075 | #ifdef CONFIG_IP_PIMSM |
1068 | else if (optname == MRT_PIM) | 1076 | else if (optname == MRT_PIM) |
1069 | val = mroute_do_pim; | 1077 | val = net->ipv4.mroute_do_pim; |
1070 | #endif | 1078 | #endif |
1071 | else | 1079 | else |
1072 | val = mroute_do_assert; | 1080 | val = net->ipv4.mroute_do_assert; |
1073 | if (copy_to_user(optval, &val, olr)) | 1081 | if (copy_to_user(optval, &val, olr)) |
1074 | return -EFAULT; | 1082 | return -EFAULT; |
1075 | return 0; | 1083 | return 0; |
@@ -1085,16 +1093,17 @@ int ipmr_ioctl(struct sock *sk, int cmd, void __user *arg) | |||
1085 | struct sioc_vif_req vr; | 1093 | struct sioc_vif_req vr; |
1086 | struct vif_device *vif; | 1094 | struct vif_device *vif; |
1087 | struct mfc_cache *c; | 1095 | struct mfc_cache *c; |
1096 | struct net *net = sock_net(sk); | ||
1088 | 1097 | ||
1089 | switch (cmd) { | 1098 | switch (cmd) { |
1090 | case SIOCGETVIFCNT: | 1099 | case SIOCGETVIFCNT: |
1091 | if (copy_from_user(&vr, arg, sizeof(vr))) | 1100 | if (copy_from_user(&vr, arg, sizeof(vr))) |
1092 | return -EFAULT; | 1101 | return -EFAULT; |
1093 | if (vr.vifi >= maxvif) | 1102 | if (vr.vifi >= net->ipv4.maxvif) |
1094 | return -EINVAL; | 1103 | return -EINVAL; |
1095 | read_lock(&mrt_lock); | 1104 | read_lock(&mrt_lock); |
1096 | vif=&vif_table[vr.vifi]; | 1105 | vif = &net->ipv4.vif_table[vr.vifi]; |
1097 | if (VIF_EXISTS(vr.vifi)) { | 1106 | if (VIF_EXISTS(net, vr.vifi)) { |
1098 | vr.icount = vif->pkt_in; | 1107 | vr.icount = vif->pkt_in; |
1099 | vr.ocount = vif->pkt_out; | 1108 | vr.ocount = vif->pkt_out; |
1100 | vr.ibytes = vif->bytes_in; | 1109 | vr.ibytes = vif->bytes_in; |
@@ -1112,7 +1121,7 @@ int ipmr_ioctl(struct sock *sk, int cmd, void __user *arg) | |||
1112 | return -EFAULT; | 1121 | return -EFAULT; |
1113 | 1122 | ||
1114 | read_lock(&mrt_lock); | 1123 | read_lock(&mrt_lock); |
1115 | c = ipmr_cache_find(sr.src.s_addr, sr.grp.s_addr); | 1124 | c = ipmr_cache_find(net, sr.src.s_addr, sr.grp.s_addr); |
1116 | if (c) { | 1125 | if (c) { |
1117 | sr.pktcnt = c->mfc_un.res.pkt; | 1126 | sr.pktcnt = c->mfc_un.res.pkt; |
1118 | sr.bytecnt = c->mfc_un.res.bytes; | 1127 | sr.bytecnt = c->mfc_un.res.bytes; |
@@ -1134,18 +1143,19 @@ int ipmr_ioctl(struct sock *sk, int cmd, void __user *arg) | |||
1134 | static int ipmr_device_event(struct notifier_block *this, unsigned long event, void *ptr) | 1143 | static int ipmr_device_event(struct notifier_block *this, unsigned long event, void *ptr) |
1135 | { | 1144 | { |
1136 | struct net_device *dev = ptr; | 1145 | struct net_device *dev = ptr; |
1146 | struct net *net = dev_net(dev); | ||
1137 | struct vif_device *v; | 1147 | struct vif_device *v; |
1138 | int ct; | 1148 | int ct; |
1139 | 1149 | ||
1140 | if (!net_eq(dev_net(dev), &init_net)) | 1150 | if (!net_eq(dev_net(dev), net)) |
1141 | return NOTIFY_DONE; | 1151 | return NOTIFY_DONE; |
1142 | 1152 | ||
1143 | if (event != NETDEV_UNREGISTER) | 1153 | if (event != NETDEV_UNREGISTER) |
1144 | return NOTIFY_DONE; | 1154 | return NOTIFY_DONE; |
1145 | v=&vif_table[0]; | 1155 | v = &net->ipv4.vif_table[0]; |
1146 | for (ct=0; ct<maxvif; ct++,v++) { | 1156 | for (ct = 0; ct < net->ipv4.maxvif; ct++, v++) { |
1147 | if (v->dev == dev) | 1157 | if (v->dev == dev) |
1148 | vif_delete(ct, 1); | 1158 | vif_delete(net, ct, 1); |
1149 | } | 1159 | } |
1150 | return NOTIFY_DONE; | 1160 | return NOTIFY_DONE; |
1151 | } | 1161 | } |
@@ -1180,7 +1190,7 @@ static void ip_encap(struct sk_buff *skb, __be32 saddr, __be32 daddr) | |||
1180 | iph->protocol = IPPROTO_IPIP; | 1190 | iph->protocol = IPPROTO_IPIP; |
1181 | iph->ihl = 5; | 1191 | iph->ihl = 5; |
1182 | iph->tot_len = htons(skb->len); | 1192 | iph->tot_len = htons(skb->len); |
1183 | ip_select_ident(iph, skb->dst, NULL); | 1193 | ip_select_ident(iph, skb_dst(skb), NULL); |
1184 | ip_send_check(iph); | 1194 | ip_send_check(iph); |
1185 | 1195 | ||
1186 | memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt)); | 1196 | memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt)); |
@@ -1191,7 +1201,7 @@ static inline int ipmr_forward_finish(struct sk_buff *skb) | |||
1191 | { | 1201 | { |
1192 | struct ip_options * opt = &(IPCB(skb)->opt); | 1202 | struct ip_options * opt = &(IPCB(skb)->opt); |
1193 | 1203 | ||
1194 | IP_INC_STATS_BH(dev_net(skb->dst->dev), IPSTATS_MIB_OUTFORWDATAGRAMS); | 1204 | IP_INC_STATS_BH(dev_net(skb_dst(skb)->dev), IPSTATS_MIB_OUTFORWDATAGRAMS); |
1195 | 1205 | ||
1196 | if (unlikely(opt->optlen)) | 1206 | if (unlikely(opt->optlen)) |
1197 | ip_forward_options(skb); | 1207 | ip_forward_options(skb); |
@@ -1205,8 +1215,9 @@ static inline int ipmr_forward_finish(struct sk_buff *skb) | |||
1205 | 1215 | ||
1206 | static void ipmr_queue_xmit(struct sk_buff *skb, struct mfc_cache *c, int vifi) | 1216 | static void ipmr_queue_xmit(struct sk_buff *skb, struct mfc_cache *c, int vifi) |
1207 | { | 1217 | { |
1218 | struct net *net = mfc_net(c); | ||
1208 | const struct iphdr *iph = ip_hdr(skb); | 1219 | const struct iphdr *iph = ip_hdr(skb); |
1209 | struct vif_device *vif = &vif_table[vifi]; | 1220 | struct vif_device *vif = &net->ipv4.vif_table[vifi]; |
1210 | struct net_device *dev; | 1221 | struct net_device *dev; |
1211 | struct rtable *rt; | 1222 | struct rtable *rt; |
1212 | int encap = 0; | 1223 | int encap = 0; |
@@ -1220,9 +1231,8 @@ static void ipmr_queue_xmit(struct sk_buff *skb, struct mfc_cache *c, int vifi) | |||
1220 | vif->bytes_out += skb->len; | 1231 | vif->bytes_out += skb->len; |
1221 | vif->dev->stats.tx_bytes += skb->len; | 1232 | vif->dev->stats.tx_bytes += skb->len; |
1222 | vif->dev->stats.tx_packets++; | 1233 | vif->dev->stats.tx_packets++; |
1223 | ipmr_cache_report(skb, vifi, IGMPMSG_WHOLEPKT); | 1234 | ipmr_cache_report(net, skb, vifi, IGMPMSG_WHOLEPKT); |
1224 | kfree_skb(skb); | 1235 | goto out_free; |
1225 | return; | ||
1226 | } | 1236 | } |
1227 | #endif | 1237 | #endif |
1228 | 1238 | ||
@@ -1233,7 +1243,7 @@ static void ipmr_queue_xmit(struct sk_buff *skb, struct mfc_cache *c, int vifi) | |||
1233 | .saddr = vif->local, | 1243 | .saddr = vif->local, |
1234 | .tos = RT_TOS(iph->tos) } }, | 1244 | .tos = RT_TOS(iph->tos) } }, |
1235 | .proto = IPPROTO_IPIP }; | 1245 | .proto = IPPROTO_IPIP }; |
1236 | if (ip_route_output_key(&init_net, &rt, &fl)) | 1246 | if (ip_route_output_key(net, &rt, &fl)) |
1237 | goto out_free; | 1247 | goto out_free; |
1238 | encap = sizeof(struct iphdr); | 1248 | encap = sizeof(struct iphdr); |
1239 | } else { | 1249 | } else { |
@@ -1242,7 +1252,7 @@ static void ipmr_queue_xmit(struct sk_buff *skb, struct mfc_cache *c, int vifi) | |||
1242 | { .daddr = iph->daddr, | 1252 | { .daddr = iph->daddr, |
1243 | .tos = RT_TOS(iph->tos) } }, | 1253 | .tos = RT_TOS(iph->tos) } }, |
1244 | .proto = IPPROTO_IPIP }; | 1254 | .proto = IPPROTO_IPIP }; |
1245 | if (ip_route_output_key(&init_net, &rt, &fl)) | 1255 | if (ip_route_output_key(net, &rt, &fl)) |
1246 | goto out_free; | 1256 | goto out_free; |
1247 | } | 1257 | } |
1248 | 1258 | ||
@@ -1269,8 +1279,8 @@ static void ipmr_queue_xmit(struct sk_buff *skb, struct mfc_cache *c, int vifi) | |||
1269 | vif->pkt_out++; | 1279 | vif->pkt_out++; |
1270 | vif->bytes_out += skb->len; | 1280 | vif->bytes_out += skb->len; |
1271 | 1281 | ||
1272 | dst_release(skb->dst); | 1282 | skb_dst_drop(skb); |
1273 | skb->dst = &rt->u.dst; | 1283 | skb_dst_set(skb, &rt->u.dst); |
1274 | ip_decrease_ttl(ip_hdr(skb)); | 1284 | ip_decrease_ttl(ip_hdr(skb)); |
1275 | 1285 | ||
1276 | /* FIXME: forward and output firewalls used to be called here. | 1286 | /* FIXME: forward and output firewalls used to be called here. |
@@ -1306,9 +1316,10 @@ out_free: | |||
1306 | 1316 | ||
1307 | static int ipmr_find_vif(struct net_device *dev) | 1317 | static int ipmr_find_vif(struct net_device *dev) |
1308 | { | 1318 | { |
1319 | struct net *net = dev_net(dev); | ||
1309 | int ct; | 1320 | int ct; |
1310 | for (ct=maxvif-1; ct>=0; ct--) { | 1321 | for (ct = net->ipv4.maxvif-1; ct >= 0; ct--) { |
1311 | if (vif_table[ct].dev == dev) | 1322 | if (net->ipv4.vif_table[ct].dev == dev) |
1312 | break; | 1323 | break; |
1313 | } | 1324 | } |
1314 | return ct; | 1325 | return ct; |
@@ -1320,6 +1331,7 @@ static int ip_mr_forward(struct sk_buff *skb, struct mfc_cache *cache, int local | |||
1320 | { | 1331 | { |
1321 | int psend = -1; | 1332 | int psend = -1; |
1322 | int vif, ct; | 1333 | int vif, ct; |
1334 | struct net *net = mfc_net(cache); | ||
1323 | 1335 | ||
1324 | vif = cache->mfc_parent; | 1336 | vif = cache->mfc_parent; |
1325 | cache->mfc_un.res.pkt++; | 1337 | cache->mfc_un.res.pkt++; |
@@ -1328,10 +1340,10 @@ static int ip_mr_forward(struct sk_buff *skb, struct mfc_cache *cache, int local | |||
1328 | /* | 1340 | /* |
1329 | * Wrong interface: drop packet and (maybe) send PIM assert. | 1341 | * Wrong interface: drop packet and (maybe) send PIM assert. |
1330 | */ | 1342 | */ |
1331 | if (vif_table[vif].dev != skb->dev) { | 1343 | if (net->ipv4.vif_table[vif].dev != skb->dev) { |
1332 | int true_vifi; | 1344 | int true_vifi; |
1333 | 1345 | ||
1334 | if (skb->rtable->fl.iif == 0) { | 1346 | if (skb_rtable(skb)->fl.iif == 0) { |
1335 | /* It is our own packet, looped back. | 1347 | /* It is our own packet, looped back. |
1336 | Very complicated situation... | 1348 | Very complicated situation... |
1337 | 1349 | ||
@@ -1349,23 +1361,24 @@ static int ip_mr_forward(struct sk_buff *skb, struct mfc_cache *cache, int local | |||
1349 | cache->mfc_un.res.wrong_if++; | 1361 | cache->mfc_un.res.wrong_if++; |
1350 | true_vifi = ipmr_find_vif(skb->dev); | 1362 | true_vifi = ipmr_find_vif(skb->dev); |
1351 | 1363 | ||
1352 | if (true_vifi >= 0 && mroute_do_assert && | 1364 | if (true_vifi >= 0 && net->ipv4.mroute_do_assert && |
1353 | /* pimsm uses asserts, when switching from RPT to SPT, | 1365 | /* pimsm uses asserts, when switching from RPT to SPT, |
1354 | so that we cannot check that packet arrived on an oif. | 1366 | so that we cannot check that packet arrived on an oif. |
1355 | It is bad, but otherwise we would need to move pretty | 1367 | It is bad, but otherwise we would need to move pretty |
1356 | large chunk of pimd to kernel. Ough... --ANK | 1368 | large chunk of pimd to kernel. Ough... --ANK |
1357 | */ | 1369 | */ |
1358 | (mroute_do_pim || cache->mfc_un.res.ttls[true_vifi] < 255) && | 1370 | (net->ipv4.mroute_do_pim || |
1371 | cache->mfc_un.res.ttls[true_vifi] < 255) && | ||
1359 | time_after(jiffies, | 1372 | time_after(jiffies, |
1360 | cache->mfc_un.res.last_assert + MFC_ASSERT_THRESH)) { | 1373 | cache->mfc_un.res.last_assert + MFC_ASSERT_THRESH)) { |
1361 | cache->mfc_un.res.last_assert = jiffies; | 1374 | cache->mfc_un.res.last_assert = jiffies; |
1362 | ipmr_cache_report(skb, true_vifi, IGMPMSG_WRONGVIF); | 1375 | ipmr_cache_report(net, skb, true_vifi, IGMPMSG_WRONGVIF); |
1363 | } | 1376 | } |
1364 | goto dont_forward; | 1377 | goto dont_forward; |
1365 | } | 1378 | } |
1366 | 1379 | ||
1367 | vif_table[vif].pkt_in++; | 1380 | net->ipv4.vif_table[vif].pkt_in++; |
1368 | vif_table[vif].bytes_in += skb->len; | 1381 | net->ipv4.vif_table[vif].bytes_in += skb->len; |
1369 | 1382 | ||
1370 | /* | 1383 | /* |
1371 | * Forward the frame | 1384 | * Forward the frame |
@@ -1405,7 +1418,8 @@ dont_forward: | |||
1405 | int ip_mr_input(struct sk_buff *skb) | 1418 | int ip_mr_input(struct sk_buff *skb) |
1406 | { | 1419 | { |
1407 | struct mfc_cache *cache; | 1420 | struct mfc_cache *cache; |
1408 | int local = skb->rtable->rt_flags&RTCF_LOCAL; | 1421 | struct net *net = dev_net(skb->dev); |
1422 | int local = skb_rtable(skb)->rt_flags & RTCF_LOCAL; | ||
1409 | 1423 | ||
1410 | /* Packet is looped back after forward, it should not be | 1424 | /* Packet is looped back after forward, it should not be |
1411 | forwarded second time, but still can be delivered locally. | 1425 | forwarded second time, but still can be delivered locally. |
@@ -1425,9 +1439,9 @@ int ip_mr_input(struct sk_buff *skb) | |||
1425 | that we can forward NO IGMP messages. | 1439 | that we can forward NO IGMP messages. |
1426 | */ | 1440 | */ |
1427 | read_lock(&mrt_lock); | 1441 | read_lock(&mrt_lock); |
1428 | if (mroute_socket) { | 1442 | if (net->ipv4.mroute_sk) { |
1429 | nf_reset(skb); | 1443 | nf_reset(skb); |
1430 | raw_rcv(mroute_socket, skb); | 1444 | raw_rcv(net->ipv4.mroute_sk, skb); |
1431 | read_unlock(&mrt_lock); | 1445 | read_unlock(&mrt_lock); |
1432 | return 0; | 1446 | return 0; |
1433 | } | 1447 | } |
@@ -1436,7 +1450,7 @@ int ip_mr_input(struct sk_buff *skb) | |||
1436 | } | 1450 | } |
1437 | 1451 | ||
1438 | read_lock(&mrt_lock); | 1452 | read_lock(&mrt_lock); |
1439 | cache = ipmr_cache_find(ip_hdr(skb)->saddr, ip_hdr(skb)->daddr); | 1453 | cache = ipmr_cache_find(net, ip_hdr(skb)->saddr, ip_hdr(skb)->daddr); |
1440 | 1454 | ||
1441 | /* | 1455 | /* |
1442 | * No usable cache entry | 1456 | * No usable cache entry |
@@ -1456,7 +1470,7 @@ int ip_mr_input(struct sk_buff *skb) | |||
1456 | 1470 | ||
1457 | vif = ipmr_find_vif(skb->dev); | 1471 | vif = ipmr_find_vif(skb->dev); |
1458 | if (vif >= 0) { | 1472 | if (vif >= 0) { |
1459 | int err = ipmr_cache_unresolved(vif, skb); | 1473 | int err = ipmr_cache_unresolved(net, vif, skb); |
1460 | read_unlock(&mrt_lock); | 1474 | read_unlock(&mrt_lock); |
1461 | 1475 | ||
1462 | return err; | 1476 | return err; |
@@ -1487,6 +1501,7 @@ static int __pim_rcv(struct sk_buff *skb, unsigned int pimlen) | |||
1487 | { | 1501 | { |
1488 | struct net_device *reg_dev = NULL; | 1502 | struct net_device *reg_dev = NULL; |
1489 | struct iphdr *encap; | 1503 | struct iphdr *encap; |
1504 | struct net *net = dev_net(skb->dev); | ||
1490 | 1505 | ||
1491 | encap = (struct iphdr *)(skb_transport_header(skb) + pimlen); | 1506 | encap = (struct iphdr *)(skb_transport_header(skb) + pimlen); |
1492 | /* | 1507 | /* |
@@ -1501,8 +1516,8 @@ static int __pim_rcv(struct sk_buff *skb, unsigned int pimlen) | |||
1501 | return 1; | 1516 | return 1; |
1502 | 1517 | ||
1503 | read_lock(&mrt_lock); | 1518 | read_lock(&mrt_lock); |
1504 | if (reg_vif_num >= 0) | 1519 | if (net->ipv4.mroute_reg_vif_num >= 0) |
1505 | reg_dev = vif_table[reg_vif_num].dev; | 1520 | reg_dev = net->ipv4.vif_table[net->ipv4.mroute_reg_vif_num].dev; |
1506 | if (reg_dev) | 1521 | if (reg_dev) |
1507 | dev_hold(reg_dev); | 1522 | dev_hold(reg_dev); |
1508 | read_unlock(&mrt_lock); | 1523 | read_unlock(&mrt_lock); |
@@ -1517,8 +1532,7 @@ static int __pim_rcv(struct sk_buff *skb, unsigned int pimlen) | |||
1517 | skb->protocol = htons(ETH_P_IP); | 1532 | skb->protocol = htons(ETH_P_IP); |
1518 | skb->ip_summed = 0; | 1533 | skb->ip_summed = 0; |
1519 | skb->pkt_type = PACKET_HOST; | 1534 | skb->pkt_type = PACKET_HOST; |
1520 | dst_release(skb->dst); | 1535 | skb_dst_drop(skb); |
1521 | skb->dst = NULL; | ||
1522 | reg_dev->stats.rx_bytes += skb->len; | 1536 | reg_dev->stats.rx_bytes += skb->len; |
1523 | reg_dev->stats.rx_packets++; | 1537 | reg_dev->stats.rx_packets++; |
1524 | nf_reset(skb); | 1538 | nf_reset(skb); |
@@ -1537,13 +1551,14 @@ static int __pim_rcv(struct sk_buff *skb, unsigned int pimlen) | |||
1537 | int pim_rcv_v1(struct sk_buff * skb) | 1551 | int pim_rcv_v1(struct sk_buff * skb) |
1538 | { | 1552 | { |
1539 | struct igmphdr *pim; | 1553 | struct igmphdr *pim; |
1554 | struct net *net = dev_net(skb->dev); | ||
1540 | 1555 | ||
1541 | if (!pskb_may_pull(skb, sizeof(*pim) + sizeof(struct iphdr))) | 1556 | if (!pskb_may_pull(skb, sizeof(*pim) + sizeof(struct iphdr))) |
1542 | goto drop; | 1557 | goto drop; |
1543 | 1558 | ||
1544 | pim = igmp_hdr(skb); | 1559 | pim = igmp_hdr(skb); |
1545 | 1560 | ||
1546 | if (!mroute_do_pim || | 1561 | if (!net->ipv4.mroute_do_pim || |
1547 | pim->group != PIM_V1_VERSION || pim->code != PIM_V1_REGISTER) | 1562 | pim->group != PIM_V1_VERSION || pim->code != PIM_V1_REGISTER) |
1548 | goto drop; | 1563 | goto drop; |
1549 | 1564 | ||
@@ -1583,7 +1598,8 @@ ipmr_fill_mroute(struct sk_buff *skb, struct mfc_cache *c, struct rtmsg *rtm) | |||
1583 | { | 1598 | { |
1584 | int ct; | 1599 | int ct; |
1585 | struct rtnexthop *nhp; | 1600 | struct rtnexthop *nhp; |
1586 | struct net_device *dev = vif_table[c->mfc_parent].dev; | 1601 | struct net *net = mfc_net(c); |
1602 | struct net_device *dev = net->ipv4.vif_table[c->mfc_parent].dev; | ||
1587 | u8 *b = skb_tail_pointer(skb); | 1603 | u8 *b = skb_tail_pointer(skb); |
1588 | struct rtattr *mp_head; | 1604 | struct rtattr *mp_head; |
1589 | 1605 | ||
@@ -1599,7 +1615,7 @@ ipmr_fill_mroute(struct sk_buff *skb, struct mfc_cache *c, struct rtmsg *rtm) | |||
1599 | nhp = (struct rtnexthop *)skb_put(skb, RTA_ALIGN(sizeof(*nhp))); | 1615 | nhp = (struct rtnexthop *)skb_put(skb, RTA_ALIGN(sizeof(*nhp))); |
1600 | nhp->rtnh_flags = 0; | 1616 | nhp->rtnh_flags = 0; |
1601 | nhp->rtnh_hops = c->mfc_un.res.ttls[ct]; | 1617 | nhp->rtnh_hops = c->mfc_un.res.ttls[ct]; |
1602 | nhp->rtnh_ifindex = vif_table[ct].dev->ifindex; | 1618 | nhp->rtnh_ifindex = net->ipv4.vif_table[ct].dev->ifindex; |
1603 | nhp->rtnh_len = sizeof(*nhp); | 1619 | nhp->rtnh_len = sizeof(*nhp); |
1604 | } | 1620 | } |
1605 | } | 1621 | } |
@@ -1613,14 +1629,15 @@ rtattr_failure: | |||
1613 | return -EMSGSIZE; | 1629 | return -EMSGSIZE; |
1614 | } | 1630 | } |
1615 | 1631 | ||
1616 | int ipmr_get_route(struct sk_buff *skb, struct rtmsg *rtm, int nowait) | 1632 | int ipmr_get_route(struct net *net, |
1633 | struct sk_buff *skb, struct rtmsg *rtm, int nowait) | ||
1617 | { | 1634 | { |
1618 | int err; | 1635 | int err; |
1619 | struct mfc_cache *cache; | 1636 | struct mfc_cache *cache; |
1620 | struct rtable *rt = skb->rtable; | 1637 | struct rtable *rt = skb_rtable(skb); |
1621 | 1638 | ||
1622 | read_lock(&mrt_lock); | 1639 | read_lock(&mrt_lock); |
1623 | cache = ipmr_cache_find(rt->rt_src, rt->rt_dst); | 1640 | cache = ipmr_cache_find(net, rt->rt_src, rt->rt_dst); |
1624 | 1641 | ||
1625 | if (cache == NULL) { | 1642 | if (cache == NULL) { |
1626 | struct sk_buff *skb2; | 1643 | struct sk_buff *skb2; |
@@ -1651,7 +1668,7 @@ int ipmr_get_route(struct sk_buff *skb, struct rtmsg *rtm, int nowait) | |||
1651 | iph->saddr = rt->rt_src; | 1668 | iph->saddr = rt->rt_src; |
1652 | iph->daddr = rt->rt_dst; | 1669 | iph->daddr = rt->rt_dst; |
1653 | iph->version = 0; | 1670 | iph->version = 0; |
1654 | err = ipmr_cache_unresolved(vif, skb2); | 1671 | err = ipmr_cache_unresolved(net, vif, skb2); |
1655 | read_unlock(&mrt_lock); | 1672 | read_unlock(&mrt_lock); |
1656 | return err; | 1673 | return err; |
1657 | } | 1674 | } |
@@ -1668,17 +1685,19 @@ int ipmr_get_route(struct sk_buff *skb, struct rtmsg *rtm, int nowait) | |||
1668 | * The /proc interfaces to multicast routing /proc/ip_mr_cache /proc/ip_mr_vif | 1685 | * The /proc interfaces to multicast routing /proc/ip_mr_cache /proc/ip_mr_vif |
1669 | */ | 1686 | */ |
1670 | struct ipmr_vif_iter { | 1687 | struct ipmr_vif_iter { |
1688 | struct seq_net_private p; | ||
1671 | int ct; | 1689 | int ct; |
1672 | }; | 1690 | }; |
1673 | 1691 | ||
1674 | static struct vif_device *ipmr_vif_seq_idx(struct ipmr_vif_iter *iter, | 1692 | static struct vif_device *ipmr_vif_seq_idx(struct net *net, |
1693 | struct ipmr_vif_iter *iter, | ||
1675 | loff_t pos) | 1694 | loff_t pos) |
1676 | { | 1695 | { |
1677 | for (iter->ct = 0; iter->ct < maxvif; ++iter->ct) { | 1696 | for (iter->ct = 0; iter->ct < net->ipv4.maxvif; ++iter->ct) { |
1678 | if (!VIF_EXISTS(iter->ct)) | 1697 | if (!VIF_EXISTS(net, iter->ct)) |
1679 | continue; | 1698 | continue; |
1680 | if (pos-- == 0) | 1699 | if (pos-- == 0) |
1681 | return &vif_table[iter->ct]; | 1700 | return &net->ipv4.vif_table[iter->ct]; |
1682 | } | 1701 | } |
1683 | return NULL; | 1702 | return NULL; |
1684 | } | 1703 | } |
@@ -1686,23 +1705,26 @@ static struct vif_device *ipmr_vif_seq_idx(struct ipmr_vif_iter *iter, | |||
1686 | static void *ipmr_vif_seq_start(struct seq_file *seq, loff_t *pos) | 1705 | static void *ipmr_vif_seq_start(struct seq_file *seq, loff_t *pos) |
1687 | __acquires(mrt_lock) | 1706 | __acquires(mrt_lock) |
1688 | { | 1707 | { |
1708 | struct net *net = seq_file_net(seq); | ||
1709 | |||
1689 | read_lock(&mrt_lock); | 1710 | read_lock(&mrt_lock); |
1690 | return *pos ? ipmr_vif_seq_idx(seq->private, *pos - 1) | 1711 | return *pos ? ipmr_vif_seq_idx(net, seq->private, *pos - 1) |
1691 | : SEQ_START_TOKEN; | 1712 | : SEQ_START_TOKEN; |
1692 | } | 1713 | } |
1693 | 1714 | ||
1694 | static void *ipmr_vif_seq_next(struct seq_file *seq, void *v, loff_t *pos) | 1715 | static void *ipmr_vif_seq_next(struct seq_file *seq, void *v, loff_t *pos) |
1695 | { | 1716 | { |
1696 | struct ipmr_vif_iter *iter = seq->private; | 1717 | struct ipmr_vif_iter *iter = seq->private; |
1718 | struct net *net = seq_file_net(seq); | ||
1697 | 1719 | ||
1698 | ++*pos; | 1720 | ++*pos; |
1699 | if (v == SEQ_START_TOKEN) | 1721 | if (v == SEQ_START_TOKEN) |
1700 | return ipmr_vif_seq_idx(iter, 0); | 1722 | return ipmr_vif_seq_idx(net, iter, 0); |
1701 | 1723 | ||
1702 | while (++iter->ct < maxvif) { | 1724 | while (++iter->ct < net->ipv4.maxvif) { |
1703 | if (!VIF_EXISTS(iter->ct)) | 1725 | if (!VIF_EXISTS(net, iter->ct)) |
1704 | continue; | 1726 | continue; |
1705 | return &vif_table[iter->ct]; | 1727 | return &net->ipv4.vif_table[iter->ct]; |
1706 | } | 1728 | } |
1707 | return NULL; | 1729 | return NULL; |
1708 | } | 1730 | } |
@@ -1715,6 +1737,8 @@ static void ipmr_vif_seq_stop(struct seq_file *seq, void *v) | |||
1715 | 1737 | ||
1716 | static int ipmr_vif_seq_show(struct seq_file *seq, void *v) | 1738 | static int ipmr_vif_seq_show(struct seq_file *seq, void *v) |
1717 | { | 1739 | { |
1740 | struct net *net = seq_file_net(seq); | ||
1741 | |||
1718 | if (v == SEQ_START_TOKEN) { | 1742 | if (v == SEQ_START_TOKEN) { |
1719 | seq_puts(seq, | 1743 | seq_puts(seq, |
1720 | "Interface BytesIn PktsIn BytesOut PktsOut Flags Local Remote\n"); | 1744 | "Interface BytesIn PktsIn BytesOut PktsOut Flags Local Remote\n"); |
@@ -1724,7 +1748,7 @@ static int ipmr_vif_seq_show(struct seq_file *seq, void *v) | |||
1724 | 1748 | ||
1725 | seq_printf(seq, | 1749 | seq_printf(seq, |
1726 | "%2Zd %-10s %8ld %7ld %8ld %7ld %05X %08X %08X\n", | 1750 | "%2Zd %-10s %8ld %7ld %8ld %7ld %05X %08X %08X\n", |
1727 | vif - vif_table, | 1751 | vif - net->ipv4.vif_table, |
1728 | name, vif->bytes_in, vif->pkt_in, | 1752 | name, vif->bytes_in, vif->pkt_in, |
1729 | vif->bytes_out, vif->pkt_out, | 1753 | vif->bytes_out, vif->pkt_out, |
1730 | vif->flags, vif->local, vif->remote); | 1754 | vif->flags, vif->local, vif->remote); |
@@ -1741,8 +1765,8 @@ static const struct seq_operations ipmr_vif_seq_ops = { | |||
1741 | 1765 | ||
1742 | static int ipmr_vif_open(struct inode *inode, struct file *file) | 1766 | static int ipmr_vif_open(struct inode *inode, struct file *file) |
1743 | { | 1767 | { |
1744 | return seq_open_private(file, &ipmr_vif_seq_ops, | 1768 | return seq_open_net(inode, file, &ipmr_vif_seq_ops, |
1745 | sizeof(struct ipmr_vif_iter)); | 1769 | sizeof(struct ipmr_vif_iter)); |
1746 | } | 1770 | } |
1747 | 1771 | ||
1748 | static const struct file_operations ipmr_vif_fops = { | 1772 | static const struct file_operations ipmr_vif_fops = { |
@@ -1750,23 +1774,26 @@ static const struct file_operations ipmr_vif_fops = { | |||
1750 | .open = ipmr_vif_open, | 1774 | .open = ipmr_vif_open, |
1751 | .read = seq_read, | 1775 | .read = seq_read, |
1752 | .llseek = seq_lseek, | 1776 | .llseek = seq_lseek, |
1753 | .release = seq_release_private, | 1777 | .release = seq_release_net, |
1754 | }; | 1778 | }; |
1755 | 1779 | ||
1756 | struct ipmr_mfc_iter { | 1780 | struct ipmr_mfc_iter { |
1781 | struct seq_net_private p; | ||
1757 | struct mfc_cache **cache; | 1782 | struct mfc_cache **cache; |
1758 | int ct; | 1783 | int ct; |
1759 | }; | 1784 | }; |
1760 | 1785 | ||
1761 | 1786 | ||
1762 | static struct mfc_cache *ipmr_mfc_seq_idx(struct ipmr_mfc_iter *it, loff_t pos) | 1787 | static struct mfc_cache *ipmr_mfc_seq_idx(struct net *net, |
1788 | struct ipmr_mfc_iter *it, loff_t pos) | ||
1763 | { | 1789 | { |
1764 | struct mfc_cache *mfc; | 1790 | struct mfc_cache *mfc; |
1765 | 1791 | ||
1766 | it->cache = mfc_cache_array; | 1792 | it->cache = net->ipv4.mfc_cache_array; |
1767 | read_lock(&mrt_lock); | 1793 | read_lock(&mrt_lock); |
1768 | for (it->ct = 0; it->ct < MFC_LINES; it->ct++) | 1794 | for (it->ct = 0; it->ct < MFC_LINES; it->ct++) |
1769 | for (mfc = mfc_cache_array[it->ct]; mfc; mfc = mfc->next) | 1795 | for (mfc = net->ipv4.mfc_cache_array[it->ct]; |
1796 | mfc; mfc = mfc->next) | ||
1770 | if (pos-- == 0) | 1797 | if (pos-- == 0) |
1771 | return mfc; | 1798 | return mfc; |
1772 | read_unlock(&mrt_lock); | 1799 | read_unlock(&mrt_lock); |
@@ -1774,7 +1801,8 @@ static struct mfc_cache *ipmr_mfc_seq_idx(struct ipmr_mfc_iter *it, loff_t pos) | |||
1774 | it->cache = &mfc_unres_queue; | 1801 | it->cache = &mfc_unres_queue; |
1775 | spin_lock_bh(&mfc_unres_lock); | 1802 | spin_lock_bh(&mfc_unres_lock); |
1776 | for (mfc = mfc_unres_queue; mfc; mfc = mfc->next) | 1803 | for (mfc = mfc_unres_queue; mfc; mfc = mfc->next) |
1777 | if (pos-- == 0) | 1804 | if (net_eq(mfc_net(mfc), net) && |
1805 | pos-- == 0) | ||
1778 | return mfc; | 1806 | return mfc; |
1779 | spin_unlock_bh(&mfc_unres_lock); | 1807 | spin_unlock_bh(&mfc_unres_lock); |
1780 | 1808 | ||
@@ -1786,9 +1814,11 @@ static struct mfc_cache *ipmr_mfc_seq_idx(struct ipmr_mfc_iter *it, loff_t pos) | |||
1786 | static void *ipmr_mfc_seq_start(struct seq_file *seq, loff_t *pos) | 1814 | static void *ipmr_mfc_seq_start(struct seq_file *seq, loff_t *pos) |
1787 | { | 1815 | { |
1788 | struct ipmr_mfc_iter *it = seq->private; | 1816 | struct ipmr_mfc_iter *it = seq->private; |
1817 | struct net *net = seq_file_net(seq); | ||
1818 | |||
1789 | it->cache = NULL; | 1819 | it->cache = NULL; |
1790 | it->ct = 0; | 1820 | it->ct = 0; |
1791 | return *pos ? ipmr_mfc_seq_idx(seq->private, *pos - 1) | 1821 | return *pos ? ipmr_mfc_seq_idx(net, seq->private, *pos - 1) |
1792 | : SEQ_START_TOKEN; | 1822 | : SEQ_START_TOKEN; |
1793 | } | 1823 | } |
1794 | 1824 | ||
@@ -1796,11 +1826,12 @@ static void *ipmr_mfc_seq_next(struct seq_file *seq, void *v, loff_t *pos) | |||
1796 | { | 1826 | { |
1797 | struct mfc_cache *mfc = v; | 1827 | struct mfc_cache *mfc = v; |
1798 | struct ipmr_mfc_iter *it = seq->private; | 1828 | struct ipmr_mfc_iter *it = seq->private; |
1829 | struct net *net = seq_file_net(seq); | ||
1799 | 1830 | ||
1800 | ++*pos; | 1831 | ++*pos; |
1801 | 1832 | ||
1802 | if (v == SEQ_START_TOKEN) | 1833 | if (v == SEQ_START_TOKEN) |
1803 | return ipmr_mfc_seq_idx(seq->private, 0); | 1834 | return ipmr_mfc_seq_idx(net, seq->private, 0); |
1804 | 1835 | ||
1805 | if (mfc->next) | 1836 | if (mfc->next) |
1806 | return mfc->next; | 1837 | return mfc->next; |
@@ -1808,10 +1839,10 @@ static void *ipmr_mfc_seq_next(struct seq_file *seq, void *v, loff_t *pos) | |||
1808 | if (it->cache == &mfc_unres_queue) | 1839 | if (it->cache == &mfc_unres_queue) |
1809 | goto end_of_list; | 1840 | goto end_of_list; |
1810 | 1841 | ||
1811 | BUG_ON(it->cache != mfc_cache_array); | 1842 | BUG_ON(it->cache != net->ipv4.mfc_cache_array); |
1812 | 1843 | ||
1813 | while (++it->ct < MFC_LINES) { | 1844 | while (++it->ct < MFC_LINES) { |
1814 | mfc = mfc_cache_array[it->ct]; | 1845 | mfc = net->ipv4.mfc_cache_array[it->ct]; |
1815 | if (mfc) | 1846 | if (mfc) |
1816 | return mfc; | 1847 | return mfc; |
1817 | } | 1848 | } |
@@ -1823,6 +1854,8 @@ static void *ipmr_mfc_seq_next(struct seq_file *seq, void *v, loff_t *pos) | |||
1823 | 1854 | ||
1824 | spin_lock_bh(&mfc_unres_lock); | 1855 | spin_lock_bh(&mfc_unres_lock); |
1825 | mfc = mfc_unres_queue; | 1856 | mfc = mfc_unres_queue; |
1857 | while (mfc && !net_eq(mfc_net(mfc), net)) | ||
1858 | mfc = mfc->next; | ||
1826 | if (mfc) | 1859 | if (mfc) |
1827 | return mfc; | 1860 | return mfc; |
1828 | 1861 | ||
@@ -1836,16 +1869,18 @@ static void *ipmr_mfc_seq_next(struct seq_file *seq, void *v, loff_t *pos) | |||
1836 | static void ipmr_mfc_seq_stop(struct seq_file *seq, void *v) | 1869 | static void ipmr_mfc_seq_stop(struct seq_file *seq, void *v) |
1837 | { | 1870 | { |
1838 | struct ipmr_mfc_iter *it = seq->private; | 1871 | struct ipmr_mfc_iter *it = seq->private; |
1872 | struct net *net = seq_file_net(seq); | ||
1839 | 1873 | ||
1840 | if (it->cache == &mfc_unres_queue) | 1874 | if (it->cache == &mfc_unres_queue) |
1841 | spin_unlock_bh(&mfc_unres_lock); | 1875 | spin_unlock_bh(&mfc_unres_lock); |
1842 | else if (it->cache == mfc_cache_array) | 1876 | else if (it->cache == net->ipv4.mfc_cache_array) |
1843 | read_unlock(&mrt_lock); | 1877 | read_unlock(&mrt_lock); |
1844 | } | 1878 | } |
1845 | 1879 | ||
1846 | static int ipmr_mfc_seq_show(struct seq_file *seq, void *v) | 1880 | static int ipmr_mfc_seq_show(struct seq_file *seq, void *v) |
1847 | { | 1881 | { |
1848 | int n; | 1882 | int n; |
1883 | struct net *net = seq_file_net(seq); | ||
1849 | 1884 | ||
1850 | if (v == SEQ_START_TOKEN) { | 1885 | if (v == SEQ_START_TOKEN) { |
1851 | seq_puts(seq, | 1886 | seq_puts(seq, |
@@ -1866,9 +1901,9 @@ static int ipmr_mfc_seq_show(struct seq_file *seq, void *v) | |||
1866 | mfc->mfc_un.res.wrong_if); | 1901 | mfc->mfc_un.res.wrong_if); |
1867 | for (n = mfc->mfc_un.res.minvif; | 1902 | for (n = mfc->mfc_un.res.minvif; |
1868 | n < mfc->mfc_un.res.maxvif; n++ ) { | 1903 | n < mfc->mfc_un.res.maxvif; n++ ) { |
1869 | if (VIF_EXISTS(n) | 1904 | if (VIF_EXISTS(net, n) && |
1870 | && mfc->mfc_un.res.ttls[n] < 255) | 1905 | mfc->mfc_un.res.ttls[n] < 255) |
1871 | seq_printf(seq, | 1906 | seq_printf(seq, |
1872 | " %2d:%-3d", | 1907 | " %2d:%-3d", |
1873 | n, mfc->mfc_un.res.ttls[n]); | 1908 | n, mfc->mfc_un.res.ttls[n]); |
1874 | } | 1909 | } |
@@ -1892,8 +1927,8 @@ static const struct seq_operations ipmr_mfc_seq_ops = { | |||
1892 | 1927 | ||
1893 | static int ipmr_mfc_open(struct inode *inode, struct file *file) | 1928 | static int ipmr_mfc_open(struct inode *inode, struct file *file) |
1894 | { | 1929 | { |
1895 | return seq_open_private(file, &ipmr_mfc_seq_ops, | 1930 | return seq_open_net(inode, file, &ipmr_mfc_seq_ops, |
1896 | sizeof(struct ipmr_mfc_iter)); | 1931 | sizeof(struct ipmr_mfc_iter)); |
1897 | } | 1932 | } |
1898 | 1933 | ||
1899 | static const struct file_operations ipmr_mfc_fops = { | 1934 | static const struct file_operations ipmr_mfc_fops = { |
@@ -1901,13 +1936,14 @@ static const struct file_operations ipmr_mfc_fops = { | |||
1901 | .open = ipmr_mfc_open, | 1936 | .open = ipmr_mfc_open, |
1902 | .read = seq_read, | 1937 | .read = seq_read, |
1903 | .llseek = seq_lseek, | 1938 | .llseek = seq_lseek, |
1904 | .release = seq_release_private, | 1939 | .release = seq_release_net, |
1905 | }; | 1940 | }; |
1906 | #endif | 1941 | #endif |
1907 | 1942 | ||
1908 | #ifdef CONFIG_IP_PIMSM_V2 | 1943 | #ifdef CONFIG_IP_PIMSM_V2 |
1909 | static struct net_protocol pim_protocol = { | 1944 | static const struct net_protocol pim_protocol = { |
1910 | .handler = pim_rcv, | 1945 | .handler = pim_rcv, |
1946 | .netns_ok = 1, | ||
1911 | }; | 1947 | }; |
1912 | #endif | 1948 | #endif |
1913 | 1949 | ||
@@ -1915,6 +1951,65 @@ static struct net_protocol pim_protocol = { | |||
1915 | /* | 1951 | /* |
1916 | * Setup for IP multicast routing | 1952 | * Setup for IP multicast routing |
1917 | */ | 1953 | */ |
1954 | static int __net_init ipmr_net_init(struct net *net) | ||
1955 | { | ||
1956 | int err = 0; | ||
1957 | |||
1958 | net->ipv4.vif_table = kcalloc(MAXVIFS, sizeof(struct vif_device), | ||
1959 | GFP_KERNEL); | ||
1960 | if (!net->ipv4.vif_table) { | ||
1961 | err = -ENOMEM; | ||
1962 | goto fail; | ||
1963 | } | ||
1964 | |||
1965 | /* Forwarding cache */ | ||
1966 | net->ipv4.mfc_cache_array = kcalloc(MFC_LINES, | ||
1967 | sizeof(struct mfc_cache *), | ||
1968 | GFP_KERNEL); | ||
1969 | if (!net->ipv4.mfc_cache_array) { | ||
1970 | err = -ENOMEM; | ||
1971 | goto fail_mfc_cache; | ||
1972 | } | ||
1973 | |||
1974 | #ifdef CONFIG_IP_PIMSM | ||
1975 | net->ipv4.mroute_reg_vif_num = -1; | ||
1976 | #endif | ||
1977 | |||
1978 | #ifdef CONFIG_PROC_FS | ||
1979 | err = -ENOMEM; | ||
1980 | if (!proc_net_fops_create(net, "ip_mr_vif", 0, &ipmr_vif_fops)) | ||
1981 | goto proc_vif_fail; | ||
1982 | if (!proc_net_fops_create(net, "ip_mr_cache", 0, &ipmr_mfc_fops)) | ||
1983 | goto proc_cache_fail; | ||
1984 | #endif | ||
1985 | return 0; | ||
1986 | |||
1987 | #ifdef CONFIG_PROC_FS | ||
1988 | proc_cache_fail: | ||
1989 | proc_net_remove(net, "ip_mr_vif"); | ||
1990 | proc_vif_fail: | ||
1991 | kfree(net->ipv4.mfc_cache_array); | ||
1992 | #endif | ||
1993 | fail_mfc_cache: | ||
1994 | kfree(net->ipv4.vif_table); | ||
1995 | fail: | ||
1996 | return err; | ||
1997 | } | ||
1998 | |||
1999 | static void __net_exit ipmr_net_exit(struct net *net) | ||
2000 | { | ||
2001 | #ifdef CONFIG_PROC_FS | ||
2002 | proc_net_remove(net, "ip_mr_cache"); | ||
2003 | proc_net_remove(net, "ip_mr_vif"); | ||
2004 | #endif | ||
2005 | kfree(net->ipv4.mfc_cache_array); | ||
2006 | kfree(net->ipv4.vif_table); | ||
2007 | } | ||
2008 | |||
2009 | static struct pernet_operations ipmr_net_ops = { | ||
2010 | .init = ipmr_net_init, | ||
2011 | .exit = ipmr_net_exit, | ||
2012 | }; | ||
1918 | 2013 | ||
1919 | int __init ip_mr_init(void) | 2014 | int __init ip_mr_init(void) |
1920 | { | 2015 | { |
@@ -1927,26 +2022,31 @@ int __init ip_mr_init(void) | |||
1927 | if (!mrt_cachep) | 2022 | if (!mrt_cachep) |
1928 | return -ENOMEM; | 2023 | return -ENOMEM; |
1929 | 2024 | ||
2025 | err = register_pernet_subsys(&ipmr_net_ops); | ||
2026 | if (err) | ||
2027 | goto reg_pernet_fail; | ||
2028 | |||
1930 | setup_timer(&ipmr_expire_timer, ipmr_expire_process, 0); | 2029 | setup_timer(&ipmr_expire_timer, ipmr_expire_process, 0); |
1931 | err = register_netdevice_notifier(&ip_mr_notifier); | 2030 | err = register_netdevice_notifier(&ip_mr_notifier); |
1932 | if (err) | 2031 | if (err) |
1933 | goto reg_notif_fail; | 2032 | goto reg_notif_fail; |
1934 | #ifdef CONFIG_PROC_FS | 2033 | #ifdef CONFIG_IP_PIMSM_V2 |
1935 | err = -ENOMEM; | 2034 | if (inet_add_protocol(&pim_protocol, IPPROTO_PIM) < 0) { |
1936 | if (!proc_net_fops_create(&init_net, "ip_mr_vif", 0, &ipmr_vif_fops)) | 2035 | printk(KERN_ERR "ip_mr_init: can't add PIM protocol\n"); |
1937 | goto proc_vif_fail; | 2036 | err = -EAGAIN; |
1938 | if (!proc_net_fops_create(&init_net, "ip_mr_cache", 0, &ipmr_mfc_fops)) | 2037 | goto add_proto_fail; |
1939 | goto proc_cache_fail; | 2038 | } |
1940 | #endif | 2039 | #endif |
1941 | return 0; | 2040 | return 0; |
1942 | #ifdef CONFIG_PROC_FS | 2041 | |
1943 | proc_cache_fail: | 2042 | #ifdef CONFIG_IP_PIMSM_V2 |
1944 | proc_net_remove(&init_net, "ip_mr_vif"); | 2043 | add_proto_fail: |
1945 | proc_vif_fail: | ||
1946 | unregister_netdevice_notifier(&ip_mr_notifier); | 2044 | unregister_netdevice_notifier(&ip_mr_notifier); |
1947 | #endif | 2045 | #endif |
1948 | reg_notif_fail: | 2046 | reg_notif_fail: |
1949 | del_timer(&ipmr_expire_timer); | 2047 | del_timer(&ipmr_expire_timer); |
2048 | unregister_pernet_subsys(&ipmr_net_ops); | ||
2049 | reg_pernet_fail: | ||
1950 | kmem_cache_destroy(mrt_cachep); | 2050 | kmem_cache_destroy(mrt_cachep); |
1951 | return err; | 2051 | return err; |
1952 | } | 2052 | } |