diff options
Diffstat (limited to 'net/ipv6/ip6mr.c')
-rw-r--r-- | net/ipv6/ip6mr.c | 81 |
1 files changed, 55 insertions, 26 deletions
diff --git a/net/ipv6/ip6mr.c b/net/ipv6/ip6mr.c index 14796181e8b5..095bc453ff4c 100644 --- a/net/ipv6/ip6mr.c +++ b/net/ipv6/ip6mr.c | |||
@@ -388,8 +388,8 @@ static int pim6_rcv(struct sk_buff *skb) | |||
388 | skb->ip_summed = 0; | 388 | skb->ip_summed = 0; |
389 | skb->pkt_type = PACKET_HOST; | 389 | skb->pkt_type = PACKET_HOST; |
390 | dst_release(skb->dst); | 390 | dst_release(skb->dst); |
391 | ((struct net_device_stats *)netdev_priv(reg_dev))->rx_bytes += skb->len; | 391 | reg_dev->stats.rx_bytes += skb->len; |
392 | ((struct net_device_stats *)netdev_priv(reg_dev))->rx_packets++; | 392 | reg_dev->stats.rx_packets++; |
393 | skb->dst = NULL; | 393 | skb->dst = NULL; |
394 | nf_reset(skb); | 394 | nf_reset(skb); |
395 | netif_rx(skb); | 395 | netif_rx(skb); |
@@ -409,26 +409,20 @@ static struct inet6_protocol pim6_protocol = { | |||
409 | static int reg_vif_xmit(struct sk_buff *skb, struct net_device *dev) | 409 | static int reg_vif_xmit(struct sk_buff *skb, struct net_device *dev) |
410 | { | 410 | { |
411 | read_lock(&mrt_lock); | 411 | read_lock(&mrt_lock); |
412 | ((struct net_device_stats *)netdev_priv(dev))->tx_bytes += skb->len; | 412 | dev->stats.tx_bytes += skb->len; |
413 | ((struct net_device_stats *)netdev_priv(dev))->tx_packets++; | 413 | dev->stats.tx_packets++; |
414 | ip6mr_cache_report(skb, reg_vif_num, MRT6MSG_WHOLEPKT); | 414 | ip6mr_cache_report(skb, reg_vif_num, MRT6MSG_WHOLEPKT); |
415 | read_unlock(&mrt_lock); | 415 | read_unlock(&mrt_lock); |
416 | kfree_skb(skb); | 416 | kfree_skb(skb); |
417 | return 0; | 417 | return 0; |
418 | } | 418 | } |
419 | 419 | ||
420 | static struct net_device_stats *reg_vif_get_stats(struct net_device *dev) | ||
421 | { | ||
422 | return (struct net_device_stats *)netdev_priv(dev); | ||
423 | } | ||
424 | |||
425 | static void reg_vif_setup(struct net_device *dev) | 420 | static void reg_vif_setup(struct net_device *dev) |
426 | { | 421 | { |
427 | dev->type = ARPHRD_PIMREG; | 422 | dev->type = ARPHRD_PIMREG; |
428 | dev->mtu = 1500 - sizeof(struct ipv6hdr) - 8; | 423 | dev->mtu = 1500 - sizeof(struct ipv6hdr) - 8; |
429 | dev->flags = IFF_NOARP; | 424 | dev->flags = IFF_NOARP; |
430 | dev->hard_start_xmit = reg_vif_xmit; | 425 | dev->hard_start_xmit = reg_vif_xmit; |
431 | dev->get_stats = reg_vif_get_stats; | ||
432 | dev->destructor = free_netdev; | 426 | dev->destructor = free_netdev; |
433 | } | 427 | } |
434 | 428 | ||
@@ -436,9 +430,7 @@ static struct net_device *ip6mr_reg_vif(void) | |||
436 | { | 430 | { |
437 | struct net_device *dev; | 431 | struct net_device *dev; |
438 | 432 | ||
439 | dev = alloc_netdev(sizeof(struct net_device_stats), "pim6reg", | 433 | dev = alloc_netdev(0, "pim6reg", reg_vif_setup); |
440 | reg_vif_setup); | ||
441 | |||
442 | if (dev == NULL) | 434 | if (dev == NULL) |
443 | return NULL; | 435 | return NULL; |
444 | 436 | ||
@@ -451,6 +443,7 @@ static struct net_device *ip6mr_reg_vif(void) | |||
451 | if (dev_open(dev)) | 443 | if (dev_open(dev)) |
452 | goto failure; | 444 | goto failure; |
453 | 445 | ||
446 | dev_hold(dev); | ||
454 | return dev; | 447 | return dev; |
455 | 448 | ||
456 | failure: | 449 | failure: |
@@ -603,6 +596,7 @@ static int mif6_add(struct mif6ctl *vifc, int mrtsock) | |||
603 | int vifi = vifc->mif6c_mifi; | 596 | int vifi = vifc->mif6c_mifi; |
604 | struct mif_device *v = &vif6_table[vifi]; | 597 | struct mif_device *v = &vif6_table[vifi]; |
605 | struct net_device *dev; | 598 | struct net_device *dev; |
599 | int err; | ||
606 | 600 | ||
607 | /* Is vif busy ? */ | 601 | /* Is vif busy ? */ |
608 | if (MIF_EXISTS(vifi)) | 602 | if (MIF_EXISTS(vifi)) |
@@ -620,20 +614,28 @@ static int mif6_add(struct mif6ctl *vifc, int mrtsock) | |||
620 | dev = ip6mr_reg_vif(); | 614 | dev = ip6mr_reg_vif(); |
621 | if (!dev) | 615 | if (!dev) |
622 | return -ENOBUFS; | 616 | return -ENOBUFS; |
617 | err = dev_set_allmulti(dev, 1); | ||
618 | if (err) { | ||
619 | unregister_netdevice(dev); | ||
620 | dev_put(dev); | ||
621 | return err; | ||
622 | } | ||
623 | break; | 623 | break; |
624 | #endif | 624 | #endif |
625 | case 0: | 625 | case 0: |
626 | dev = dev_get_by_index(&init_net, vifc->mif6c_pifi); | 626 | dev = dev_get_by_index(&init_net, vifc->mif6c_pifi); |
627 | if (!dev) | 627 | if (!dev) |
628 | return -EADDRNOTAVAIL; | 628 | return -EADDRNOTAVAIL; |
629 | dev_put(dev); | 629 | err = dev_set_allmulti(dev, 1); |
630 | if (err) { | ||
631 | dev_put(dev); | ||
632 | return err; | ||
633 | } | ||
630 | break; | 634 | break; |
631 | default: | 635 | default: |
632 | return -EINVAL; | 636 | return -EINVAL; |
633 | } | 637 | } |
634 | 638 | ||
635 | dev_set_allmulti(dev, 1); | ||
636 | |||
637 | /* | 639 | /* |
638 | * Fill in the VIF structures | 640 | * Fill in the VIF structures |
639 | */ | 641 | */ |
@@ -652,7 +654,6 @@ static int mif6_add(struct mif6ctl *vifc, int mrtsock) | |||
652 | 654 | ||
653 | /* And finish update writing critical data */ | 655 | /* And finish update writing critical data */ |
654 | write_lock_bh(&mrt_lock); | 656 | write_lock_bh(&mrt_lock); |
655 | dev_hold(dev); | ||
656 | v->dev = dev; | 657 | v->dev = dev; |
657 | #ifdef CONFIG_IPV6_PIMSM_V2 | 658 | #ifdef CONFIG_IPV6_PIMSM_V2 |
658 | if (v->flags & MIFF_REGISTER) | 659 | if (v->flags & MIFF_REGISTER) |
@@ -934,7 +935,7 @@ static int ip6mr_device_event(struct notifier_block *this, | |||
934 | struct mif_device *v; | 935 | struct mif_device *v; |
935 | int ct; | 936 | int ct; |
936 | 937 | ||
937 | if (dev_net(dev) != &init_net) | 938 | if (!net_eq(dev_net(dev), &init_net)) |
938 | return NOTIFY_DONE; | 939 | return NOTIFY_DONE; |
939 | 940 | ||
940 | if (event != NETDEV_UNREGISTER) | 941 | if (event != NETDEV_UNREGISTER) |
@@ -956,23 +957,51 @@ static struct notifier_block ip6_mr_notifier = { | |||
956 | * Setup for IP multicast routing | 957 | * Setup for IP multicast routing |
957 | */ | 958 | */ |
958 | 959 | ||
959 | void __init ip6_mr_init(void) | 960 | int __init ip6_mr_init(void) |
960 | { | 961 | { |
962 | int err; | ||
963 | |||
961 | mrt_cachep = kmem_cache_create("ip6_mrt_cache", | 964 | mrt_cachep = kmem_cache_create("ip6_mrt_cache", |
962 | sizeof(struct mfc6_cache), | 965 | sizeof(struct mfc6_cache), |
963 | 0, SLAB_HWCACHE_ALIGN, | 966 | 0, SLAB_HWCACHE_ALIGN, |
964 | NULL); | 967 | NULL); |
965 | if (!mrt_cachep) | 968 | if (!mrt_cachep) |
966 | panic("cannot allocate ip6_mrt_cache"); | 969 | return -ENOMEM; |
967 | 970 | ||
968 | setup_timer(&ipmr_expire_timer, ipmr_expire_process, 0); | 971 | setup_timer(&ipmr_expire_timer, ipmr_expire_process, 0); |
969 | register_netdevice_notifier(&ip6_mr_notifier); | 972 | err = register_netdevice_notifier(&ip6_mr_notifier); |
973 | if (err) | ||
974 | goto reg_notif_fail; | ||
975 | #ifdef CONFIG_PROC_FS | ||
976 | err = -ENOMEM; | ||
977 | if (!proc_net_fops_create(&init_net, "ip6_mr_vif", 0, &ip6mr_vif_fops)) | ||
978 | goto proc_vif_fail; | ||
979 | if (!proc_net_fops_create(&init_net, "ip6_mr_cache", | ||
980 | 0, &ip6mr_mfc_fops)) | ||
981 | goto proc_cache_fail; | ||
982 | #endif | ||
983 | return 0; | ||
984 | reg_notif_fail: | ||
985 | kmem_cache_destroy(mrt_cachep); | ||
970 | #ifdef CONFIG_PROC_FS | 986 | #ifdef CONFIG_PROC_FS |
971 | proc_net_fops_create(&init_net, "ip6_mr_vif", 0, &ip6mr_vif_fops); | 987 | proc_vif_fail: |
972 | proc_net_fops_create(&init_net, "ip6_mr_cache", 0, &ip6mr_mfc_fops); | 988 | unregister_netdevice_notifier(&ip6_mr_notifier); |
989 | proc_cache_fail: | ||
990 | proc_net_remove(&init_net, "ip6_mr_vif"); | ||
973 | #endif | 991 | #endif |
992 | return err; | ||
974 | } | 993 | } |
975 | 994 | ||
995 | void ip6_mr_cleanup(void) | ||
996 | { | ||
997 | #ifdef CONFIG_PROC_FS | ||
998 | proc_net_remove(&init_net, "ip6_mr_cache"); | ||
999 | proc_net_remove(&init_net, "ip6_mr_vif"); | ||
1000 | #endif | ||
1001 | unregister_netdevice_notifier(&ip6_mr_notifier); | ||
1002 | del_timer(&ipmr_expire_timer); | ||
1003 | kmem_cache_destroy(mrt_cachep); | ||
1004 | } | ||
976 | 1005 | ||
977 | static int ip6mr_mfc_add(struct mf6cctl *mfc, int mrtsock) | 1006 | static int ip6mr_mfc_add(struct mf6cctl *mfc, int mrtsock) |
978 | { | 1007 | { |
@@ -1248,7 +1277,7 @@ int ip6_mroute_setsockopt(struct sock *sk, int optname, char __user *optval, int | |||
1248 | 1277 | ||
1249 | #endif | 1278 | #endif |
1250 | /* | 1279 | /* |
1251 | * Spurious command, or MRT_VERSION which you cannot | 1280 | * Spurious command, or MRT6_VERSION which you cannot |
1252 | * set. | 1281 | * set. |
1253 | */ | 1282 | */ |
1254 | default: | 1283 | default: |
@@ -1377,8 +1406,8 @@ static int ip6mr_forward2(struct sk_buff *skb, struct mfc6_cache *c, int vifi) | |||
1377 | if (vif->flags & MIFF_REGISTER) { | 1406 | if (vif->flags & MIFF_REGISTER) { |
1378 | vif->pkt_out++; | 1407 | vif->pkt_out++; |
1379 | vif->bytes_out += skb->len; | 1408 | vif->bytes_out += skb->len; |
1380 | ((struct net_device_stats *)netdev_priv(vif->dev))->tx_bytes += skb->len; | 1409 | vif->dev->stats.tx_bytes += skb->len; |
1381 | ((struct net_device_stats *)netdev_priv(vif->dev))->tx_packets++; | 1410 | vif->dev->stats.tx_packets++; |
1382 | ip6mr_cache_report(skb, vifi, MRT6MSG_WHOLEPKT); | 1411 | ip6mr_cache_report(skb, vifi, MRT6MSG_WHOLEPKT); |
1383 | kfree_skb(skb); | 1412 | kfree_skb(skb); |
1384 | return 0; | 1413 | return 0; |