diff options
Diffstat (limited to 'net')
566 files changed, 16946 insertions, 3216 deletions
diff --git a/net/802/garp.c b/net/802/garp.c index 1dcb0660c49d..941f2a324d3a 100644 --- a/net/802/garp.c +++ b/net/802/garp.c | |||
@@ -14,6 +14,7 @@ | |||
14 | #include <linux/etherdevice.h> | 14 | #include <linux/etherdevice.h> |
15 | #include <linux/rtnetlink.h> | 15 | #include <linux/rtnetlink.h> |
16 | #include <linux/llc.h> | 16 | #include <linux/llc.h> |
17 | #include <linux/slab.h> | ||
17 | #include <net/llc.h> | 18 | #include <net/llc.h> |
18 | #include <net/llc_pdu.h> | 19 | #include <net/llc_pdu.h> |
19 | #include <net/garp.h> | 20 | #include <net/garp.h> |
@@ -575,7 +576,7 @@ int garp_init_applicant(struct net_device *dev, struct garp_application *appl) | |||
575 | if (!app) | 576 | if (!app) |
576 | goto err2; | 577 | goto err2; |
577 | 578 | ||
578 | err = dev_mc_add(dev, appl->proto.group_address, ETH_ALEN, 0); | 579 | err = dev_mc_add(dev, appl->proto.group_address); |
579 | if (err < 0) | 580 | if (err < 0) |
580 | goto err3; | 581 | goto err3; |
581 | 582 | ||
@@ -615,7 +616,7 @@ void garp_uninit_applicant(struct net_device *dev, struct garp_application *appl | |||
615 | garp_pdu_queue(app); | 616 | garp_pdu_queue(app); |
616 | garp_queue_xmit(app); | 617 | garp_queue_xmit(app); |
617 | 618 | ||
618 | dev_mc_delete(dev, appl->proto.group_address, ETH_ALEN, 0); | 619 | dev_mc_del(dev, appl->proto.group_address); |
619 | kfree(app); | 620 | kfree(app); |
620 | garp_release_port(dev); | 621 | garp_release_port(dev); |
621 | } | 622 | } |
diff --git a/net/802/p8022.c b/net/802/p8022.c index 2530f35241cd..7f353c4f437a 100644 --- a/net/802/p8022.c +++ b/net/802/p8022.c | |||
@@ -18,6 +18,7 @@ | |||
18 | #include <linux/module.h> | 18 | #include <linux/module.h> |
19 | #include <linux/netdevice.h> | 19 | #include <linux/netdevice.h> |
20 | #include <linux/skbuff.h> | 20 | #include <linux/skbuff.h> |
21 | #include <linux/slab.h> | ||
21 | #include <net/datalink.h> | 22 | #include <net/datalink.h> |
22 | #include <linux/mm.h> | 23 | #include <linux/mm.h> |
23 | #include <linux/in.h> | 24 | #include <linux/in.h> |
diff --git a/net/802/p8023.c b/net/802/p8023.c index 6ab1835041a7..1256a40da43c 100644 --- a/net/802/p8023.c +++ b/net/802/p8023.c | |||
@@ -18,6 +18,7 @@ | |||
18 | #include <linux/module.h> | 18 | #include <linux/module.h> |
19 | #include <linux/netdevice.h> | 19 | #include <linux/netdevice.h> |
20 | #include <linux/skbuff.h> | 20 | #include <linux/skbuff.h> |
21 | #include <linux/slab.h> | ||
21 | 22 | ||
22 | #include <net/datalink.h> | 23 | #include <net/datalink.h> |
23 | #include <net/p8022.h> | 24 | #include <net/p8022.h> |
diff --git a/net/802/psnap.c b/net/802/psnap.c index 6fea0750662b..21cde8fd5795 100644 --- a/net/802/psnap.c +++ b/net/802/psnap.c | |||
@@ -14,6 +14,7 @@ | |||
14 | #include <linux/module.h> | 14 | #include <linux/module.h> |
15 | #include <linux/netdevice.h> | 15 | #include <linux/netdevice.h> |
16 | #include <linux/skbuff.h> | 16 | #include <linux/skbuff.h> |
17 | #include <linux/slab.h> | ||
17 | #include <net/datalink.h> | 18 | #include <net/datalink.h> |
18 | #include <net/llc.h> | 19 | #include <net/llc.h> |
19 | #include <net/psnap.h> | 20 | #include <net/psnap.h> |
diff --git a/net/802/stp.c b/net/802/stp.c index 0b7a24452d11..53c8f77f0ccd 100644 --- a/net/802/stp.c +++ b/net/802/stp.c | |||
@@ -11,6 +11,7 @@ | |||
11 | #include <linux/skbuff.h> | 11 | #include <linux/skbuff.h> |
12 | #include <linux/etherdevice.h> | 12 | #include <linux/etherdevice.h> |
13 | #include <linux/llc.h> | 13 | #include <linux/llc.h> |
14 | #include <linux/slab.h> | ||
14 | #include <net/llc.h> | 15 | #include <net/llc.h> |
15 | #include <net/llc_pdu.h> | 16 | #include <net/llc_pdu.h> |
16 | #include <net/stp.h> | 17 | #include <net/stp.h> |
diff --git a/net/802/tr.c b/net/802/tr.c index 44acce47fcdc..1c6e596074df 100644 --- a/net/802/tr.c +++ b/net/802/tr.c | |||
@@ -36,6 +36,7 @@ | |||
36 | #include <linux/seq_file.h> | 36 | #include <linux/seq_file.h> |
37 | #include <linux/init.h> | 37 | #include <linux/init.h> |
38 | #include <linux/sysctl.h> | 38 | #include <linux/sysctl.h> |
39 | #include <linux/slab.h> | ||
39 | #include <net/arp.h> | 40 | #include <net/arp.h> |
40 | #include <net/net_namespace.h> | 41 | #include <net/net_namespace.h> |
41 | 42 | ||
diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c index 453512266ea1..3c1c8c14e929 100644 --- a/net/8021q/vlan.c +++ b/net/8021q/vlan.c | |||
@@ -22,6 +22,7 @@ | |||
22 | #include <linux/module.h> | 22 | #include <linux/module.h> |
23 | #include <linux/netdevice.h> | 23 | #include <linux/netdevice.h> |
24 | #include <linux/skbuff.h> | 24 | #include <linux/skbuff.h> |
25 | #include <linux/slab.h> | ||
25 | #include <linux/init.h> | 26 | #include <linux/init.h> |
26 | #include <linux/rculist.h> | 27 | #include <linux/rculist.h> |
27 | #include <net/p8022.h> | 28 | #include <net/p8022.h> |
@@ -356,13 +357,13 @@ static void vlan_sync_address(struct net_device *dev, | |||
356 | * the new address */ | 357 | * the new address */ |
357 | if (compare_ether_addr(vlandev->dev_addr, vlan->real_dev_addr) && | 358 | if (compare_ether_addr(vlandev->dev_addr, vlan->real_dev_addr) && |
358 | !compare_ether_addr(vlandev->dev_addr, dev->dev_addr)) | 359 | !compare_ether_addr(vlandev->dev_addr, dev->dev_addr)) |
359 | dev_unicast_delete(dev, vlandev->dev_addr); | 360 | dev_uc_del(dev, vlandev->dev_addr); |
360 | 361 | ||
361 | /* vlan address was equal to the old address and is different from | 362 | /* vlan address was equal to the old address and is different from |
362 | * the new address */ | 363 | * the new address */ |
363 | if (!compare_ether_addr(vlandev->dev_addr, vlan->real_dev_addr) && | 364 | if (!compare_ether_addr(vlandev->dev_addr, vlan->real_dev_addr) && |
364 | compare_ether_addr(vlandev->dev_addr, dev->dev_addr)) | 365 | compare_ether_addr(vlandev->dev_addr, dev->dev_addr)) |
365 | dev_unicast_add(dev, vlandev->dev_addr); | 366 | dev_uc_add(dev, vlandev->dev_addr); |
366 | 367 | ||
367 | memcpy(vlan->real_dev_addr, dev->dev_addr, ETH_ALEN); | 368 | memcpy(vlan->real_dev_addr, dev->dev_addr, ETH_ALEN); |
368 | } | 369 | } |
@@ -378,6 +379,8 @@ static void vlan_transfer_features(struct net_device *dev, | |||
378 | #if defined(CONFIG_FCOE) || defined(CONFIG_FCOE_MODULE) | 379 | #if defined(CONFIG_FCOE) || defined(CONFIG_FCOE_MODULE) |
379 | vlandev->fcoe_ddp_xid = dev->fcoe_ddp_xid; | 380 | vlandev->fcoe_ddp_xid = dev->fcoe_ddp_xid; |
380 | #endif | 381 | #endif |
382 | vlandev->real_num_tx_queues = dev->real_num_tx_queues; | ||
383 | BUG_ON(vlandev->real_num_tx_queues > vlandev->num_tx_queues); | ||
381 | 384 | ||
382 | if (old_features != vlandev->features) | 385 | if (old_features != vlandev->features) |
383 | netdev_features_change(vlandev); | 386 | netdev_features_change(vlandev); |
@@ -530,6 +533,10 @@ static int vlan_device_event(struct notifier_block *unused, unsigned long event, | |||
530 | } | 533 | } |
531 | unregister_netdevice_many(&list); | 534 | unregister_netdevice_many(&list); |
532 | break; | 535 | break; |
536 | |||
537 | case NETDEV_PRE_TYPE_CHANGE: | ||
538 | /* Forbid underlaying device to change its type. */ | ||
539 | return NOTIFY_BAD; | ||
533 | } | 540 | } |
534 | 541 | ||
535 | out: | 542 | out: |
diff --git a/net/8021q/vlan_core.c b/net/8021q/vlan_core.c index c0316e0ca6e8..c584a0af77d3 100644 --- a/net/8021q/vlan_core.c +++ b/net/8021q/vlan_core.c | |||
@@ -11,7 +11,7 @@ int __vlan_hwaccel_rx(struct sk_buff *skb, struct vlan_group *grp, | |||
11 | if (netpoll_rx(skb)) | 11 | if (netpoll_rx(skb)) |
12 | return NET_RX_DROP; | 12 | return NET_RX_DROP; |
13 | 13 | ||
14 | if (skb_bond_should_drop(skb)) | 14 | if (skb_bond_should_drop(skb, ACCESS_ONCE(skb->dev->master))) |
15 | goto drop; | 15 | goto drop; |
16 | 16 | ||
17 | skb->skb_iif = skb->dev->ifindex; | 17 | skb->skb_iif = skb->dev->ifindex; |
@@ -83,7 +83,7 @@ vlan_gro_common(struct napi_struct *napi, struct vlan_group *grp, | |||
83 | { | 83 | { |
84 | struct sk_buff *p; | 84 | struct sk_buff *p; |
85 | 85 | ||
86 | if (skb_bond_should_drop(skb)) | 86 | if (skb_bond_should_drop(skb, ACCESS_ONCE(skb->dev->master))) |
87 | goto drop; | 87 | goto drop; |
88 | 88 | ||
89 | skb->skb_iif = skb->dev->ifindex; | 89 | skb->skb_iif = skb->dev->ifindex; |
diff --git a/net/8021q/vlan_dev.c b/net/8021q/vlan_dev.c index 9e83272fc5b0..b5249c5fd4d3 100644 --- a/net/8021q/vlan_dev.c +++ b/net/8021q/vlan_dev.c | |||
@@ -21,6 +21,7 @@ | |||
21 | */ | 21 | */ |
22 | 22 | ||
23 | #include <linux/module.h> | 23 | #include <linux/module.h> |
24 | #include <linux/slab.h> | ||
24 | #include <linux/skbuff.h> | 25 | #include <linux/skbuff.h> |
25 | #include <linux/netdevice.h> | 26 | #include <linux/netdevice.h> |
26 | #include <linux/etherdevice.h> | 27 | #include <linux/etherdevice.h> |
@@ -361,6 +362,14 @@ static netdev_tx_t vlan_dev_hwaccel_hard_start_xmit(struct sk_buff *skb, | |||
361 | return ret; | 362 | return ret; |
362 | } | 363 | } |
363 | 364 | ||
365 | static u16 vlan_dev_select_queue(struct net_device *dev, struct sk_buff *skb) | ||
366 | { | ||
367 | struct net_device *rdev = vlan_dev_info(dev)->real_dev; | ||
368 | const struct net_device_ops *ops = rdev->netdev_ops; | ||
369 | |||
370 | return ops->ndo_select_queue(rdev, skb); | ||
371 | } | ||
372 | |||
364 | static int vlan_dev_change_mtu(struct net_device *dev, int new_mtu) | 373 | static int vlan_dev_change_mtu(struct net_device *dev, int new_mtu) |
365 | { | 374 | { |
366 | /* TODO: gotta make sure the underlying layer can handle it, | 375 | /* TODO: gotta make sure the underlying layer can handle it, |
@@ -461,7 +470,7 @@ static int vlan_dev_open(struct net_device *dev) | |||
461 | return -ENETDOWN; | 470 | return -ENETDOWN; |
462 | 471 | ||
463 | if (compare_ether_addr(dev->dev_addr, real_dev->dev_addr)) { | 472 | if (compare_ether_addr(dev->dev_addr, real_dev->dev_addr)) { |
464 | err = dev_unicast_add(real_dev, dev->dev_addr); | 473 | err = dev_uc_add(real_dev, dev->dev_addr); |
465 | if (err < 0) | 474 | if (err < 0) |
466 | goto out; | 475 | goto out; |
467 | } | 476 | } |
@@ -490,7 +499,7 @@ clear_allmulti: | |||
490 | dev_set_allmulti(real_dev, -1); | 499 | dev_set_allmulti(real_dev, -1); |
491 | del_unicast: | 500 | del_unicast: |
492 | if (compare_ether_addr(dev->dev_addr, real_dev->dev_addr)) | 501 | if (compare_ether_addr(dev->dev_addr, real_dev->dev_addr)) |
493 | dev_unicast_delete(real_dev, dev->dev_addr); | 502 | dev_uc_del(real_dev, dev->dev_addr); |
494 | out: | 503 | out: |
495 | netif_carrier_off(dev); | 504 | netif_carrier_off(dev); |
496 | return err; | 505 | return err; |
@@ -505,14 +514,14 @@ static int vlan_dev_stop(struct net_device *dev) | |||
505 | vlan_gvrp_request_leave(dev); | 514 | vlan_gvrp_request_leave(dev); |
506 | 515 | ||
507 | dev_mc_unsync(real_dev, dev); | 516 | dev_mc_unsync(real_dev, dev); |
508 | dev_unicast_unsync(real_dev, dev); | 517 | dev_uc_unsync(real_dev, dev); |
509 | if (dev->flags & IFF_ALLMULTI) | 518 | if (dev->flags & IFF_ALLMULTI) |
510 | dev_set_allmulti(real_dev, -1); | 519 | dev_set_allmulti(real_dev, -1); |
511 | if (dev->flags & IFF_PROMISC) | 520 | if (dev->flags & IFF_PROMISC) |
512 | dev_set_promiscuity(real_dev, -1); | 521 | dev_set_promiscuity(real_dev, -1); |
513 | 522 | ||
514 | if (compare_ether_addr(dev->dev_addr, real_dev->dev_addr)) | 523 | if (compare_ether_addr(dev->dev_addr, real_dev->dev_addr)) |
515 | dev_unicast_delete(real_dev, dev->dev_addr); | 524 | dev_uc_del(real_dev, dev->dev_addr); |
516 | 525 | ||
517 | netif_carrier_off(dev); | 526 | netif_carrier_off(dev); |
518 | return 0; | 527 | return 0; |
@@ -531,13 +540,13 @@ static int vlan_dev_set_mac_address(struct net_device *dev, void *p) | |||
531 | goto out; | 540 | goto out; |
532 | 541 | ||
533 | if (compare_ether_addr(addr->sa_data, real_dev->dev_addr)) { | 542 | if (compare_ether_addr(addr->sa_data, real_dev->dev_addr)) { |
534 | err = dev_unicast_add(real_dev, addr->sa_data); | 543 | err = dev_uc_add(real_dev, addr->sa_data); |
535 | if (err < 0) | 544 | if (err < 0) |
536 | return err; | 545 | return err; |
537 | } | 546 | } |
538 | 547 | ||
539 | if (compare_ether_addr(dev->dev_addr, real_dev->dev_addr)) | 548 | if (compare_ether_addr(dev->dev_addr, real_dev->dev_addr)) |
540 | dev_unicast_delete(real_dev, dev->dev_addr); | 549 | dev_uc_del(real_dev, dev->dev_addr); |
541 | 550 | ||
542 | out: | 551 | out: |
543 | memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN); | 552 | memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN); |
@@ -654,7 +663,7 @@ static void vlan_dev_change_rx_flags(struct net_device *dev, int change) | |||
654 | static void vlan_dev_set_rx_mode(struct net_device *vlan_dev) | 663 | static void vlan_dev_set_rx_mode(struct net_device *vlan_dev) |
655 | { | 664 | { |
656 | dev_mc_sync(vlan_dev_info(vlan_dev)->real_dev, vlan_dev); | 665 | dev_mc_sync(vlan_dev_info(vlan_dev)->real_dev, vlan_dev); |
657 | dev_unicast_sync(vlan_dev_info(vlan_dev)->real_dev, vlan_dev); | 666 | dev_uc_sync(vlan_dev_info(vlan_dev)->real_dev, vlan_dev); |
658 | } | 667 | } |
659 | 668 | ||
660 | /* | 669 | /* |
@@ -688,7 +697,8 @@ static const struct header_ops vlan_header_ops = { | |||
688 | .parse = eth_header_parse, | 697 | .parse = eth_header_parse, |
689 | }; | 698 | }; |
690 | 699 | ||
691 | static const struct net_device_ops vlan_netdev_ops, vlan_netdev_accel_ops; | 700 | static const struct net_device_ops vlan_netdev_ops, vlan_netdev_accel_ops, |
701 | vlan_netdev_ops_sq, vlan_netdev_accel_ops_sq; | ||
692 | 702 | ||
693 | static int vlan_dev_init(struct net_device *dev) | 703 | static int vlan_dev_init(struct net_device *dev) |
694 | { | 704 | { |
@@ -722,11 +732,17 @@ static int vlan_dev_init(struct net_device *dev) | |||
722 | if (real_dev->features & NETIF_F_HW_VLAN_TX) { | 732 | if (real_dev->features & NETIF_F_HW_VLAN_TX) { |
723 | dev->header_ops = real_dev->header_ops; | 733 | dev->header_ops = real_dev->header_ops; |
724 | dev->hard_header_len = real_dev->hard_header_len; | 734 | dev->hard_header_len = real_dev->hard_header_len; |
725 | dev->netdev_ops = &vlan_netdev_accel_ops; | 735 | if (real_dev->netdev_ops->ndo_select_queue) |
736 | dev->netdev_ops = &vlan_netdev_accel_ops_sq; | ||
737 | else | ||
738 | dev->netdev_ops = &vlan_netdev_accel_ops; | ||
726 | } else { | 739 | } else { |
727 | dev->header_ops = &vlan_header_ops; | 740 | dev->header_ops = &vlan_header_ops; |
728 | dev->hard_header_len = real_dev->hard_header_len + VLAN_HLEN; | 741 | dev->hard_header_len = real_dev->hard_header_len + VLAN_HLEN; |
729 | dev->netdev_ops = &vlan_netdev_ops; | 742 | if (real_dev->netdev_ops->ndo_select_queue) |
743 | dev->netdev_ops = &vlan_netdev_ops_sq; | ||
744 | else | ||
745 | dev->netdev_ops = &vlan_netdev_ops; | ||
730 | } | 746 | } |
731 | 747 | ||
732 | if (is_vlan_dev(real_dev)) | 748 | if (is_vlan_dev(real_dev)) |
@@ -865,6 +881,56 @@ static const struct net_device_ops vlan_netdev_accel_ops = { | |||
865 | #endif | 881 | #endif |
866 | }; | 882 | }; |
867 | 883 | ||
884 | static const struct net_device_ops vlan_netdev_ops_sq = { | ||
885 | .ndo_select_queue = vlan_dev_select_queue, | ||
886 | .ndo_change_mtu = vlan_dev_change_mtu, | ||
887 | .ndo_init = vlan_dev_init, | ||
888 | .ndo_uninit = vlan_dev_uninit, | ||
889 | .ndo_open = vlan_dev_open, | ||
890 | .ndo_stop = vlan_dev_stop, | ||
891 | .ndo_start_xmit = vlan_dev_hard_start_xmit, | ||
892 | .ndo_validate_addr = eth_validate_addr, | ||
893 | .ndo_set_mac_address = vlan_dev_set_mac_address, | ||
894 | .ndo_set_rx_mode = vlan_dev_set_rx_mode, | ||
895 | .ndo_set_multicast_list = vlan_dev_set_rx_mode, | ||
896 | .ndo_change_rx_flags = vlan_dev_change_rx_flags, | ||
897 | .ndo_do_ioctl = vlan_dev_ioctl, | ||
898 | .ndo_neigh_setup = vlan_dev_neigh_setup, | ||
899 | .ndo_get_stats = vlan_dev_get_stats, | ||
900 | #if defined(CONFIG_FCOE) || defined(CONFIG_FCOE_MODULE) | ||
901 | .ndo_fcoe_ddp_setup = vlan_dev_fcoe_ddp_setup, | ||
902 | .ndo_fcoe_ddp_done = vlan_dev_fcoe_ddp_done, | ||
903 | .ndo_fcoe_enable = vlan_dev_fcoe_enable, | ||
904 | .ndo_fcoe_disable = vlan_dev_fcoe_disable, | ||
905 | .ndo_fcoe_get_wwn = vlan_dev_fcoe_get_wwn, | ||
906 | #endif | ||
907 | }; | ||
908 | |||
909 | static const struct net_device_ops vlan_netdev_accel_ops_sq = { | ||
910 | .ndo_select_queue = vlan_dev_select_queue, | ||
911 | .ndo_change_mtu = vlan_dev_change_mtu, | ||
912 | .ndo_init = vlan_dev_init, | ||
913 | .ndo_uninit = vlan_dev_uninit, | ||
914 | .ndo_open = vlan_dev_open, | ||
915 | .ndo_stop = vlan_dev_stop, | ||
916 | .ndo_start_xmit = vlan_dev_hwaccel_hard_start_xmit, | ||
917 | .ndo_validate_addr = eth_validate_addr, | ||
918 | .ndo_set_mac_address = vlan_dev_set_mac_address, | ||
919 | .ndo_set_rx_mode = vlan_dev_set_rx_mode, | ||
920 | .ndo_set_multicast_list = vlan_dev_set_rx_mode, | ||
921 | .ndo_change_rx_flags = vlan_dev_change_rx_flags, | ||
922 | .ndo_do_ioctl = vlan_dev_ioctl, | ||
923 | .ndo_neigh_setup = vlan_dev_neigh_setup, | ||
924 | .ndo_get_stats = vlan_dev_get_stats, | ||
925 | #if defined(CONFIG_FCOE) || defined(CONFIG_FCOE_MODULE) | ||
926 | .ndo_fcoe_ddp_setup = vlan_dev_fcoe_ddp_setup, | ||
927 | .ndo_fcoe_ddp_done = vlan_dev_fcoe_ddp_done, | ||
928 | .ndo_fcoe_enable = vlan_dev_fcoe_enable, | ||
929 | .ndo_fcoe_disable = vlan_dev_fcoe_disable, | ||
930 | .ndo_fcoe_get_wwn = vlan_dev_fcoe_get_wwn, | ||
931 | #endif | ||
932 | }; | ||
933 | |||
868 | void vlan_setup(struct net_device *dev) | 934 | void vlan_setup(struct net_device *dev) |
869 | { | 935 | { |
870 | ether_setup(dev); | 936 | ether_setup(dev); |
diff --git a/net/9p/client.c b/net/9p/client.c index 09d4f1e2e4a8..0aa79faa9850 100644 --- a/net/9p/client.c +++ b/net/9p/client.c | |||
@@ -29,6 +29,7 @@ | |||
29 | #include <linux/poll.h> | 29 | #include <linux/poll.h> |
30 | #include <linux/idr.h> | 30 | #include <linux/idr.h> |
31 | #include <linux/mutex.h> | 31 | #include <linux/mutex.h> |
32 | #include <linux/slab.h> | ||
32 | #include <linux/sched.h> | 33 | #include <linux/sched.h> |
33 | #include <linux/uaccess.h> | 34 | #include <linux/uaccess.h> |
34 | #include <net/9p/9p.h> | 35 | #include <net/9p/9p.h> |
@@ -46,6 +47,7 @@ enum { | |||
46 | Opt_msize, | 47 | Opt_msize, |
47 | Opt_trans, | 48 | Opt_trans, |
48 | Opt_legacy, | 49 | Opt_legacy, |
50 | Opt_version, | ||
49 | Opt_err, | 51 | Opt_err, |
50 | }; | 52 | }; |
51 | 53 | ||
@@ -53,9 +55,43 @@ static const match_table_t tokens = { | |||
53 | {Opt_msize, "msize=%u"}, | 55 | {Opt_msize, "msize=%u"}, |
54 | {Opt_legacy, "noextend"}, | 56 | {Opt_legacy, "noextend"}, |
55 | {Opt_trans, "trans=%s"}, | 57 | {Opt_trans, "trans=%s"}, |
58 | {Opt_version, "version=%s"}, | ||
56 | {Opt_err, NULL}, | 59 | {Opt_err, NULL}, |
57 | }; | 60 | }; |
58 | 61 | ||
62 | inline int p9_is_proto_dotl(struct p9_client *clnt) | ||
63 | { | ||
64 | return (clnt->proto_version == p9_proto_2000L); | ||
65 | } | ||
66 | EXPORT_SYMBOL(p9_is_proto_dotl); | ||
67 | |||
68 | inline int p9_is_proto_dotu(struct p9_client *clnt) | ||
69 | { | ||
70 | return (clnt->proto_version == p9_proto_2000u); | ||
71 | } | ||
72 | EXPORT_SYMBOL(p9_is_proto_dotu); | ||
73 | |||
74 | /* Interpret mount option for protocol version */ | ||
75 | static int get_protocol_version(const substring_t *name) | ||
76 | { | ||
77 | int version = -EINVAL; | ||
78 | |||
79 | if (!strncmp("9p2000", name->from, name->to-name->from)) { | ||
80 | version = p9_proto_legacy; | ||
81 | P9_DPRINTK(P9_DEBUG_9P, "Protocol version: Legacy\n"); | ||
82 | } else if (!strncmp("9p2000.u", name->from, name->to-name->from)) { | ||
83 | version = p9_proto_2000u; | ||
84 | P9_DPRINTK(P9_DEBUG_9P, "Protocol version: 9P2000.u\n"); | ||
85 | } else if (!strncmp("9p2000.L", name->from, name->to-name->from)) { | ||
86 | version = p9_proto_2000L; | ||
87 | P9_DPRINTK(P9_DEBUG_9P, "Protocol version: 9P2000.L\n"); | ||
88 | } else { | ||
89 | P9_DPRINTK(P9_DEBUG_ERROR, "Unknown protocol version %s. ", | ||
90 | name->from); | ||
91 | } | ||
92 | return version; | ||
93 | } | ||
94 | |||
59 | static struct p9_req_t * | 95 | static struct p9_req_t * |
60 | p9_client_rpc(struct p9_client *c, int8_t type, const char *fmt, ...); | 96 | p9_client_rpc(struct p9_client *c, int8_t type, const char *fmt, ...); |
61 | 97 | ||
@@ -75,7 +111,7 @@ static int parse_opts(char *opts, struct p9_client *clnt) | |||
75 | int option; | 111 | int option; |
76 | int ret = 0; | 112 | int ret = 0; |
77 | 113 | ||
78 | clnt->dotu = 1; | 114 | clnt->proto_version = p9_proto_2000u; |
79 | clnt->msize = 8192; | 115 | clnt->msize = 8192; |
80 | 116 | ||
81 | if (!opts) | 117 | if (!opts) |
@@ -118,7 +154,13 @@ static int parse_opts(char *opts, struct p9_client *clnt) | |||
118 | } | 154 | } |
119 | break; | 155 | break; |
120 | case Opt_legacy: | 156 | case Opt_legacy: |
121 | clnt->dotu = 0; | 157 | clnt->proto_version = p9_proto_legacy; |
158 | break; | ||
159 | case Opt_version: | ||
160 | ret = get_protocol_version(&args[0]); | ||
161 | if (ret == -EINVAL) | ||
162 | goto free_and_return; | ||
163 | clnt->proto_version = ret; | ||
122 | break; | 164 | break; |
123 | default: | 165 | default: |
124 | continue; | 166 | continue; |
@@ -410,14 +452,15 @@ static int p9_check_errors(struct p9_client *c, struct p9_req_t *req) | |||
410 | int ecode; | 452 | int ecode; |
411 | char *ename; | 453 | char *ename; |
412 | 454 | ||
413 | err = p9pdu_readf(req->rc, c->dotu, "s?d", &ename, &ecode); | 455 | err = p9pdu_readf(req->rc, c->proto_version, "s?d", |
456 | &ename, &ecode); | ||
414 | if (err) { | 457 | if (err) { |
415 | P9_DPRINTK(P9_DEBUG_ERROR, "couldn't parse error%d\n", | 458 | P9_DPRINTK(P9_DEBUG_ERROR, "couldn't parse error%d\n", |
416 | err); | 459 | err); |
417 | return err; | 460 | return err; |
418 | } | 461 | } |
419 | 462 | ||
420 | if (c->dotu) | 463 | if (p9_is_proto_dotu(c)) |
421 | err = -ecode; | 464 | err = -ecode; |
422 | 465 | ||
423 | if (!err || !IS_ERR_VALUE(err)) | 466 | if (!err || !IS_ERR_VALUE(err)) |
@@ -492,7 +535,12 @@ p9_client_rpc(struct p9_client *c, int8_t type, const char *fmt, ...) | |||
492 | 535 | ||
493 | P9_DPRINTK(P9_DEBUG_MUX, "client %p op %d\n", c, type); | 536 | P9_DPRINTK(P9_DEBUG_MUX, "client %p op %d\n", c, type); |
494 | 537 | ||
495 | if (c->status != Connected) | 538 | /* we allow for any status other than disconnected */ |
539 | if (c->status == Disconnected) | ||
540 | return ERR_PTR(-EIO); | ||
541 | |||
542 | /* if status is begin_disconnected we allow only clunk request */ | ||
543 | if ((c->status == BeginDisconnect) && (type != P9_TCLUNK)) | ||
496 | return ERR_PTR(-EIO); | 544 | return ERR_PTR(-EIO); |
497 | 545 | ||
498 | if (signal_pending(current)) { | 546 | if (signal_pending(current)) { |
@@ -515,7 +563,7 @@ p9_client_rpc(struct p9_client *c, int8_t type, const char *fmt, ...) | |||
515 | /* marshall the data */ | 563 | /* marshall the data */ |
516 | p9pdu_prepare(req->tc, tag, type); | 564 | p9pdu_prepare(req->tc, tag, type); |
517 | va_start(ap, fmt); | 565 | va_start(ap, fmt); |
518 | err = p9pdu_vwritef(req->tc, c->dotu, fmt, ap); | 566 | err = p9pdu_vwritef(req->tc, c->proto_version, fmt, ap); |
519 | va_end(ap); | 567 | va_end(ap); |
520 | p9pdu_finalize(req->tc); | 568 | p9pdu_finalize(req->tc); |
521 | 569 | ||
@@ -627,14 +675,31 @@ int p9_client_version(struct p9_client *c) | |||
627 | char *version; | 675 | char *version; |
628 | int msize; | 676 | int msize; |
629 | 677 | ||
630 | P9_DPRINTK(P9_DEBUG_9P, ">>> TVERSION msize %d extended %d\n", | 678 | P9_DPRINTK(P9_DEBUG_9P, ">>> TVERSION msize %d protocol %d\n", |
631 | c->msize, c->dotu); | 679 | c->msize, c->proto_version); |
632 | req = p9_client_rpc(c, P9_TVERSION, "ds", c->msize, | 680 | |
633 | c->dotu ? "9P2000.u" : "9P2000"); | 681 | switch (c->proto_version) { |
682 | case p9_proto_2000L: | ||
683 | req = p9_client_rpc(c, P9_TVERSION, "ds", | ||
684 | c->msize, "9P2000.L"); | ||
685 | break; | ||
686 | case p9_proto_2000u: | ||
687 | req = p9_client_rpc(c, P9_TVERSION, "ds", | ||
688 | c->msize, "9P2000.u"); | ||
689 | break; | ||
690 | case p9_proto_legacy: | ||
691 | req = p9_client_rpc(c, P9_TVERSION, "ds", | ||
692 | c->msize, "9P2000"); | ||
693 | break; | ||
694 | default: | ||
695 | return -EINVAL; | ||
696 | break; | ||
697 | } | ||
698 | |||
634 | if (IS_ERR(req)) | 699 | if (IS_ERR(req)) |
635 | return PTR_ERR(req); | 700 | return PTR_ERR(req); |
636 | 701 | ||
637 | err = p9pdu_readf(req->rc, c->dotu, "ds", &msize, &version); | 702 | err = p9pdu_readf(req->rc, c->proto_version, "ds", &msize, &version); |
638 | if (err) { | 703 | if (err) { |
639 | P9_DPRINTK(P9_DEBUG_9P, "version error %d\n", err); | 704 | P9_DPRINTK(P9_DEBUG_9P, "version error %d\n", err); |
640 | p9pdu_dump(1, req->rc); | 705 | p9pdu_dump(1, req->rc); |
@@ -642,10 +707,12 @@ int p9_client_version(struct p9_client *c) | |||
642 | } | 707 | } |
643 | 708 | ||
644 | P9_DPRINTK(P9_DEBUG_9P, "<<< RVERSION msize %d %s\n", msize, version); | 709 | P9_DPRINTK(P9_DEBUG_9P, "<<< RVERSION msize %d %s\n", msize, version); |
645 | if (!memcmp(version, "9P2000.u", 8)) | 710 | if (!strncmp(version, "9P2000.L", 8)) |
646 | c->dotu = 1; | 711 | c->proto_version = p9_proto_2000L; |
647 | else if (!memcmp(version, "9P2000", 6)) | 712 | else if (!strncmp(version, "9P2000.u", 8)) |
648 | c->dotu = 0; | 713 | c->proto_version = p9_proto_2000u; |
714 | else if (!strncmp(version, "9P2000", 6)) | ||
715 | c->proto_version = p9_proto_legacy; | ||
649 | else { | 716 | else { |
650 | err = -EREMOTEIO; | 717 | err = -EREMOTEIO; |
651 | goto error; | 718 | goto error; |
@@ -700,8 +767,8 @@ struct p9_client *p9_client_create(const char *dev_name, char *options) | |||
700 | goto put_trans; | 767 | goto put_trans; |
701 | } | 768 | } |
702 | 769 | ||
703 | P9_DPRINTK(P9_DEBUG_MUX, "clnt %p trans %p msize %d dotu %d\n", | 770 | P9_DPRINTK(P9_DEBUG_MUX, "clnt %p trans %p msize %d protocol %d\n", |
704 | clnt, clnt->trans_mod, clnt->msize, clnt->dotu); | 771 | clnt, clnt->trans_mod, clnt->msize, clnt->proto_version); |
705 | 772 | ||
706 | err = clnt->trans_mod->create(clnt, dev_name, options); | 773 | err = clnt->trans_mod->create(clnt, dev_name, options); |
707 | if (err) | 774 | if (err) |
@@ -739,8 +806,10 @@ void p9_client_destroy(struct p9_client *clnt) | |||
739 | 806 | ||
740 | v9fs_put_trans(clnt->trans_mod); | 807 | v9fs_put_trans(clnt->trans_mod); |
741 | 808 | ||
742 | list_for_each_entry_safe(fid, fidptr, &clnt->fidlist, flist) | 809 | list_for_each_entry_safe(fid, fidptr, &clnt->fidlist, flist) { |
810 | printk(KERN_INFO "Found fid %d not clunked\n", fid->fid); | ||
743 | p9_fid_destroy(fid); | 811 | p9_fid_destroy(fid); |
812 | } | ||
744 | 813 | ||
745 | if (clnt->fidpool) | 814 | if (clnt->fidpool) |
746 | p9_idpool_destroy(clnt->fidpool); | 815 | p9_idpool_destroy(clnt->fidpool); |
@@ -758,6 +827,13 @@ void p9_client_disconnect(struct p9_client *clnt) | |||
758 | } | 827 | } |
759 | EXPORT_SYMBOL(p9_client_disconnect); | 828 | EXPORT_SYMBOL(p9_client_disconnect); |
760 | 829 | ||
830 | void p9_client_begin_disconnect(struct p9_client *clnt) | ||
831 | { | ||
832 | P9_DPRINTK(P9_DEBUG_9P, "clnt %p\n", clnt); | ||
833 | clnt->status = BeginDisconnect; | ||
834 | } | ||
835 | EXPORT_SYMBOL(p9_client_begin_disconnect); | ||
836 | |||
761 | struct p9_fid *p9_client_attach(struct p9_client *clnt, struct p9_fid *afid, | 837 | struct p9_fid *p9_client_attach(struct p9_client *clnt, struct p9_fid *afid, |
762 | char *uname, u32 n_uname, char *aname) | 838 | char *uname, u32 n_uname, char *aname) |
763 | { | 839 | { |
@@ -784,7 +860,7 @@ struct p9_fid *p9_client_attach(struct p9_client *clnt, struct p9_fid *afid, | |||
784 | goto error; | 860 | goto error; |
785 | } | 861 | } |
786 | 862 | ||
787 | err = p9pdu_readf(req->rc, clnt->dotu, "Q", &qid); | 863 | err = p9pdu_readf(req->rc, clnt->proto_version, "Q", &qid); |
788 | if (err) { | 864 | if (err) { |
789 | p9pdu_dump(1, req->rc); | 865 | p9pdu_dump(1, req->rc); |
790 | p9_free_req(clnt, req); | 866 | p9_free_req(clnt, req); |
@@ -833,7 +909,7 @@ p9_client_auth(struct p9_client *clnt, char *uname, u32 n_uname, char *aname) | |||
833 | goto error; | 909 | goto error; |
834 | } | 910 | } |
835 | 911 | ||
836 | err = p9pdu_readf(req->rc, clnt->dotu, "Q", &qid); | 912 | err = p9pdu_readf(req->rc, clnt->proto_version, "Q", &qid); |
837 | if (err) { | 913 | if (err) { |
838 | p9pdu_dump(1, req->rc); | 914 | p9pdu_dump(1, req->rc); |
839 | p9_free_req(clnt, req); | 915 | p9_free_req(clnt, req); |
@@ -891,7 +967,7 @@ struct p9_fid *p9_client_walk(struct p9_fid *oldfid, int nwname, char **wnames, | |||
891 | goto error; | 967 | goto error; |
892 | } | 968 | } |
893 | 969 | ||
894 | err = p9pdu_readf(req->rc, clnt->dotu, "R", &nwqids, &wqids); | 970 | err = p9pdu_readf(req->rc, clnt->proto_version, "R", &nwqids, &wqids); |
895 | if (err) { | 971 | if (err) { |
896 | p9pdu_dump(1, req->rc); | 972 | p9pdu_dump(1, req->rc); |
897 | p9_free_req(clnt, req); | 973 | p9_free_req(clnt, req); |
@@ -952,7 +1028,7 @@ int p9_client_open(struct p9_fid *fid, int mode) | |||
952 | goto error; | 1028 | goto error; |
953 | } | 1029 | } |
954 | 1030 | ||
955 | err = p9pdu_readf(req->rc, clnt->dotu, "Qd", &qid, &iounit); | 1031 | err = p9pdu_readf(req->rc, clnt->proto_version, "Qd", &qid, &iounit); |
956 | if (err) { | 1032 | if (err) { |
957 | p9pdu_dump(1, req->rc); | 1033 | p9pdu_dump(1, req->rc); |
958 | goto free_and_error; | 1034 | goto free_and_error; |
@@ -997,7 +1073,7 @@ int p9_client_fcreate(struct p9_fid *fid, char *name, u32 perm, int mode, | |||
997 | goto error; | 1073 | goto error; |
998 | } | 1074 | } |
999 | 1075 | ||
1000 | err = p9pdu_readf(req->rc, clnt->dotu, "Qd", &qid, &iounit); | 1076 | err = p9pdu_readf(req->rc, clnt->proto_version, "Qd", &qid, &iounit); |
1001 | if (err) { | 1077 | if (err) { |
1002 | p9pdu_dump(1, req->rc); | 1078 | p9pdu_dump(1, req->rc); |
1003 | goto free_and_error; | 1079 | goto free_and_error; |
@@ -1098,7 +1174,7 @@ p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset, | |||
1098 | goto error; | 1174 | goto error; |
1099 | } | 1175 | } |
1100 | 1176 | ||
1101 | err = p9pdu_readf(req->rc, clnt->dotu, "D", &count, &dataptr); | 1177 | err = p9pdu_readf(req->rc, clnt->proto_version, "D", &count, &dataptr); |
1102 | if (err) { | 1178 | if (err) { |
1103 | p9pdu_dump(1, req->rc); | 1179 | p9pdu_dump(1, req->rc); |
1104 | goto free_and_error; | 1180 | goto free_and_error; |
@@ -1159,7 +1235,7 @@ p9_client_write(struct p9_fid *fid, char *data, const char __user *udata, | |||
1159 | goto error; | 1235 | goto error; |
1160 | } | 1236 | } |
1161 | 1237 | ||
1162 | err = p9pdu_readf(req->rc, clnt->dotu, "d", &count); | 1238 | err = p9pdu_readf(req->rc, clnt->proto_version, "d", &count); |
1163 | if (err) { | 1239 | if (err) { |
1164 | p9pdu_dump(1, req->rc); | 1240 | p9pdu_dump(1, req->rc); |
1165 | goto free_and_error; | 1241 | goto free_and_error; |
@@ -1199,7 +1275,7 @@ struct p9_wstat *p9_client_stat(struct p9_fid *fid) | |||
1199 | goto error; | 1275 | goto error; |
1200 | } | 1276 | } |
1201 | 1277 | ||
1202 | err = p9pdu_readf(req->rc, clnt->dotu, "wS", &ignored, ret); | 1278 | err = p9pdu_readf(req->rc, clnt->proto_version, "wS", &ignored, ret); |
1203 | if (err) { | 1279 | if (err) { |
1204 | p9pdu_dump(1, req->rc); | 1280 | p9pdu_dump(1, req->rc); |
1205 | p9_free_req(clnt, req); | 1281 | p9_free_req(clnt, req); |
@@ -1226,7 +1302,7 @@ error: | |||
1226 | } | 1302 | } |
1227 | EXPORT_SYMBOL(p9_client_stat); | 1303 | EXPORT_SYMBOL(p9_client_stat); |
1228 | 1304 | ||
1229 | static int p9_client_statsize(struct p9_wstat *wst, int optional) | 1305 | static int p9_client_statsize(struct p9_wstat *wst, int proto_version) |
1230 | { | 1306 | { |
1231 | int ret; | 1307 | int ret; |
1232 | 1308 | ||
@@ -1245,7 +1321,7 @@ static int p9_client_statsize(struct p9_wstat *wst, int optional) | |||
1245 | if (wst->muid) | 1321 | if (wst->muid) |
1246 | ret += strlen(wst->muid); | 1322 | ret += strlen(wst->muid); |
1247 | 1323 | ||
1248 | if (optional) { | 1324 | if (proto_version == p9_proto_2000u) { |
1249 | ret += 2+4+4+4; /* extension[s] n_uid[4] n_gid[4] n_muid[4] */ | 1325 | ret += 2+4+4+4; /* extension[s] n_uid[4] n_gid[4] n_muid[4] */ |
1250 | if (wst->extension) | 1326 | if (wst->extension) |
1251 | ret += strlen(wst->extension); | 1327 | ret += strlen(wst->extension); |
@@ -1262,7 +1338,7 @@ int p9_client_wstat(struct p9_fid *fid, struct p9_wstat *wst) | |||
1262 | 1338 | ||
1263 | err = 0; | 1339 | err = 0; |
1264 | clnt = fid->clnt; | 1340 | clnt = fid->clnt; |
1265 | wst->size = p9_client_statsize(wst, clnt->dotu); | 1341 | wst->size = p9_client_statsize(wst, clnt->proto_version); |
1266 | P9_DPRINTK(P9_DEBUG_9P, ">>> TWSTAT fid %d\n", fid->fid); | 1342 | P9_DPRINTK(P9_DEBUG_9P, ">>> TWSTAT fid %d\n", fid->fid); |
1267 | P9_DPRINTK(P9_DEBUG_9P, | 1343 | P9_DPRINTK(P9_DEBUG_9P, |
1268 | " sz=%x type=%x dev=%x qid=%x.%llx.%x\n" | 1344 | " sz=%x type=%x dev=%x qid=%x.%llx.%x\n" |
diff --git a/net/9p/protocol.c b/net/9p/protocol.c index fc70147c771e..e7541d5b0118 100644 --- a/net/9p/protocol.c +++ b/net/9p/protocol.c | |||
@@ -28,6 +28,7 @@ | |||
28 | #include <linux/module.h> | 28 | #include <linux/module.h> |
29 | #include <linux/errno.h> | 29 | #include <linux/errno.h> |
30 | #include <linux/uaccess.h> | 30 | #include <linux/uaccess.h> |
31 | #include <linux/slab.h> | ||
31 | #include <linux/sched.h> | 32 | #include <linux/sched.h> |
32 | #include <linux/types.h> | 33 | #include <linux/types.h> |
33 | #include <net/9p/9p.h> | 34 | #include <net/9p/9p.h> |
@@ -52,7 +53,7 @@ | |||
52 | #endif | 53 | #endif |
53 | 54 | ||
54 | static int | 55 | static int |
55 | p9pdu_writef(struct p9_fcall *pdu, int optional, const char *fmt, ...); | 56 | p9pdu_writef(struct p9_fcall *pdu, int proto_version, const char *fmt, ...); |
56 | 57 | ||
57 | #ifdef CONFIG_NET_9P_DEBUG | 58 | #ifdef CONFIG_NET_9P_DEBUG |
58 | void | 59 | void |
@@ -144,7 +145,8 @@ pdu_write_u(struct p9_fcall *pdu, const char __user *udata, size_t size) | |||
144 | */ | 145 | */ |
145 | 146 | ||
146 | static int | 147 | static int |
147 | p9pdu_vreadf(struct p9_fcall *pdu, int optional, const char *fmt, va_list ap) | 148 | p9pdu_vreadf(struct p9_fcall *pdu, int proto_version, const char *fmt, |
149 | va_list ap) | ||
148 | { | 150 | { |
149 | const char *ptr; | 151 | const char *ptr; |
150 | int errcode = 0; | 152 | int errcode = 0; |
@@ -194,7 +196,8 @@ p9pdu_vreadf(struct p9_fcall *pdu, int optional, const char *fmt, va_list ap) | |||
194 | int16_t len; | 196 | int16_t len; |
195 | int size; | 197 | int size; |
196 | 198 | ||
197 | errcode = p9pdu_readf(pdu, optional, "w", &len); | 199 | errcode = p9pdu_readf(pdu, proto_version, |
200 | "w", &len); | ||
198 | if (errcode) | 201 | if (errcode) |
199 | break; | 202 | break; |
200 | 203 | ||
@@ -217,7 +220,7 @@ p9pdu_vreadf(struct p9_fcall *pdu, int optional, const char *fmt, va_list ap) | |||
217 | struct p9_qid *qid = | 220 | struct p9_qid *qid = |
218 | va_arg(ap, struct p9_qid *); | 221 | va_arg(ap, struct p9_qid *); |
219 | 222 | ||
220 | errcode = p9pdu_readf(pdu, optional, "bdq", | 223 | errcode = p9pdu_readf(pdu, proto_version, "bdq", |
221 | &qid->type, &qid->version, | 224 | &qid->type, &qid->version, |
222 | &qid->path); | 225 | &qid->path); |
223 | } | 226 | } |
@@ -230,7 +233,7 @@ p9pdu_vreadf(struct p9_fcall *pdu, int optional, const char *fmt, va_list ap) | |||
230 | stbuf->n_uid = stbuf->n_gid = stbuf->n_muid = | 233 | stbuf->n_uid = stbuf->n_gid = stbuf->n_muid = |
231 | -1; | 234 | -1; |
232 | errcode = | 235 | errcode = |
233 | p9pdu_readf(pdu, optional, | 236 | p9pdu_readf(pdu, proto_version, |
234 | "wwdQdddqssss?sddd", | 237 | "wwdQdddqssss?sddd", |
235 | &stbuf->size, &stbuf->type, | 238 | &stbuf->size, &stbuf->type, |
236 | &stbuf->dev, &stbuf->qid, | 239 | &stbuf->dev, &stbuf->qid, |
@@ -250,7 +253,7 @@ p9pdu_vreadf(struct p9_fcall *pdu, int optional, const char *fmt, va_list ap) | |||
250 | void **data = va_arg(ap, void **); | 253 | void **data = va_arg(ap, void **); |
251 | 254 | ||
252 | errcode = | 255 | errcode = |
253 | p9pdu_readf(pdu, optional, "d", count); | 256 | p9pdu_readf(pdu, proto_version, "d", count); |
254 | if (!errcode) { | 257 | if (!errcode) { |
255 | *count = | 258 | *count = |
256 | MIN(*count, | 259 | MIN(*count, |
@@ -263,8 +266,8 @@ p9pdu_vreadf(struct p9_fcall *pdu, int optional, const char *fmt, va_list ap) | |||
263 | int16_t *nwname = va_arg(ap, int16_t *); | 266 | int16_t *nwname = va_arg(ap, int16_t *); |
264 | char ***wnames = va_arg(ap, char ***); | 267 | char ***wnames = va_arg(ap, char ***); |
265 | 268 | ||
266 | errcode = | 269 | errcode = p9pdu_readf(pdu, proto_version, |
267 | p9pdu_readf(pdu, optional, "w", nwname); | 270 | "w", nwname); |
268 | if (!errcode) { | 271 | if (!errcode) { |
269 | *wnames = | 272 | *wnames = |
270 | kmalloc(sizeof(char *) * *nwname, | 273 | kmalloc(sizeof(char *) * *nwname, |
@@ -278,7 +281,8 @@ p9pdu_vreadf(struct p9_fcall *pdu, int optional, const char *fmt, va_list ap) | |||
278 | 281 | ||
279 | for (i = 0; i < *nwname; i++) { | 282 | for (i = 0; i < *nwname; i++) { |
280 | errcode = | 283 | errcode = |
281 | p9pdu_readf(pdu, optional, | 284 | p9pdu_readf(pdu, |
285 | proto_version, | ||
282 | "s", | 286 | "s", |
283 | &(*wnames)[i]); | 287 | &(*wnames)[i]); |
284 | if (errcode) | 288 | if (errcode) |
@@ -306,7 +310,7 @@ p9pdu_vreadf(struct p9_fcall *pdu, int optional, const char *fmt, va_list ap) | |||
306 | *wqids = NULL; | 310 | *wqids = NULL; |
307 | 311 | ||
308 | errcode = | 312 | errcode = |
309 | p9pdu_readf(pdu, optional, "w", nwqid); | 313 | p9pdu_readf(pdu, proto_version, "w", nwqid); |
310 | if (!errcode) { | 314 | if (!errcode) { |
311 | *wqids = | 315 | *wqids = |
312 | kmalloc(*nwqid * | 316 | kmalloc(*nwqid * |
@@ -321,7 +325,8 @@ p9pdu_vreadf(struct p9_fcall *pdu, int optional, const char *fmt, va_list ap) | |||
321 | 325 | ||
322 | for (i = 0; i < *nwqid; i++) { | 326 | for (i = 0; i < *nwqid; i++) { |
323 | errcode = | 327 | errcode = |
324 | p9pdu_readf(pdu, optional, | 328 | p9pdu_readf(pdu, |
329 | proto_version, | ||
325 | "Q", | 330 | "Q", |
326 | &(*wqids)[i]); | 331 | &(*wqids)[i]); |
327 | if (errcode) | 332 | if (errcode) |
@@ -336,7 +341,7 @@ p9pdu_vreadf(struct p9_fcall *pdu, int optional, const char *fmt, va_list ap) | |||
336 | } | 341 | } |
337 | break; | 342 | break; |
338 | case '?': | 343 | case '?': |
339 | if (!optional) | 344 | if (proto_version != p9_proto_2000u) |
340 | return 0; | 345 | return 0; |
341 | break; | 346 | break; |
342 | default: | 347 | default: |
@@ -352,7 +357,8 @@ p9pdu_vreadf(struct p9_fcall *pdu, int optional, const char *fmt, va_list ap) | |||
352 | } | 357 | } |
353 | 358 | ||
354 | int | 359 | int |
355 | p9pdu_vwritef(struct p9_fcall *pdu, int optional, const char *fmt, va_list ap) | 360 | p9pdu_vwritef(struct p9_fcall *pdu, int proto_version, const char *fmt, |
361 | va_list ap) | ||
356 | { | 362 | { |
357 | const char *ptr; | 363 | const char *ptr; |
358 | int errcode = 0; | 364 | int errcode = 0; |
@@ -389,7 +395,8 @@ p9pdu_vwritef(struct p9_fcall *pdu, int optional, const char *fmt, va_list ap) | |||
389 | if (sptr) | 395 | if (sptr) |
390 | len = MIN(strlen(sptr), USHORT_MAX); | 396 | len = MIN(strlen(sptr), USHORT_MAX); |
391 | 397 | ||
392 | errcode = p9pdu_writef(pdu, optional, "w", len); | 398 | errcode = p9pdu_writef(pdu, proto_version, |
399 | "w", len); | ||
393 | if (!errcode && pdu_write(pdu, sptr, len)) | 400 | if (!errcode && pdu_write(pdu, sptr, len)) |
394 | errcode = -EFAULT; | 401 | errcode = -EFAULT; |
395 | } | 402 | } |
@@ -398,7 +405,7 @@ p9pdu_vwritef(struct p9_fcall *pdu, int optional, const char *fmt, va_list ap) | |||
398 | const struct p9_qid *qid = | 405 | const struct p9_qid *qid = |
399 | va_arg(ap, const struct p9_qid *); | 406 | va_arg(ap, const struct p9_qid *); |
400 | errcode = | 407 | errcode = |
401 | p9pdu_writef(pdu, optional, "bdq", | 408 | p9pdu_writef(pdu, proto_version, "bdq", |
402 | qid->type, qid->version, | 409 | qid->type, qid->version, |
403 | qid->path); | 410 | qid->path); |
404 | } break; | 411 | } break; |
@@ -406,7 +413,7 @@ p9pdu_vwritef(struct p9_fcall *pdu, int optional, const char *fmt, va_list ap) | |||
406 | const struct p9_wstat *stbuf = | 413 | const struct p9_wstat *stbuf = |
407 | va_arg(ap, const struct p9_wstat *); | 414 | va_arg(ap, const struct p9_wstat *); |
408 | errcode = | 415 | errcode = |
409 | p9pdu_writef(pdu, optional, | 416 | p9pdu_writef(pdu, proto_version, |
410 | "wwdQdddqssss?sddd", | 417 | "wwdQdddqssss?sddd", |
411 | stbuf->size, stbuf->type, | 418 | stbuf->size, stbuf->type, |
412 | stbuf->dev, &stbuf->qid, | 419 | stbuf->dev, &stbuf->qid, |
@@ -421,8 +428,8 @@ p9pdu_vwritef(struct p9_fcall *pdu, int optional, const char *fmt, va_list ap) | |||
421 | int32_t count = va_arg(ap, int32_t); | 428 | int32_t count = va_arg(ap, int32_t); |
422 | const void *data = va_arg(ap, const void *); | 429 | const void *data = va_arg(ap, const void *); |
423 | 430 | ||
424 | errcode = | 431 | errcode = p9pdu_writef(pdu, proto_version, "d", |
425 | p9pdu_writef(pdu, optional, "d", count); | 432 | count); |
426 | if (!errcode && pdu_write(pdu, data, count)) | 433 | if (!errcode && pdu_write(pdu, data, count)) |
427 | errcode = -EFAULT; | 434 | errcode = -EFAULT; |
428 | } | 435 | } |
@@ -431,8 +438,8 @@ p9pdu_vwritef(struct p9_fcall *pdu, int optional, const char *fmt, va_list ap) | |||
431 | int32_t count = va_arg(ap, int32_t); | 438 | int32_t count = va_arg(ap, int32_t); |
432 | const char __user *udata = | 439 | const char __user *udata = |
433 | va_arg(ap, const void __user *); | 440 | va_arg(ap, const void __user *); |
434 | errcode = | 441 | errcode = p9pdu_writef(pdu, proto_version, "d", |
435 | p9pdu_writef(pdu, optional, "d", count); | 442 | count); |
436 | if (!errcode && pdu_write_u(pdu, udata, count)) | 443 | if (!errcode && pdu_write_u(pdu, udata, count)) |
437 | errcode = -EFAULT; | 444 | errcode = -EFAULT; |
438 | } | 445 | } |
@@ -441,14 +448,15 @@ p9pdu_vwritef(struct p9_fcall *pdu, int optional, const char *fmt, va_list ap) | |||
441 | int16_t nwname = va_arg(ap, int); | 448 | int16_t nwname = va_arg(ap, int); |
442 | const char **wnames = va_arg(ap, const char **); | 449 | const char **wnames = va_arg(ap, const char **); |
443 | 450 | ||
444 | errcode = | 451 | errcode = p9pdu_writef(pdu, proto_version, "w", |
445 | p9pdu_writef(pdu, optional, "w", nwname); | 452 | nwname); |
446 | if (!errcode) { | 453 | if (!errcode) { |
447 | int i; | 454 | int i; |
448 | 455 | ||
449 | for (i = 0; i < nwname; i++) { | 456 | for (i = 0; i < nwname; i++) { |
450 | errcode = | 457 | errcode = |
451 | p9pdu_writef(pdu, optional, | 458 | p9pdu_writef(pdu, |
459 | proto_version, | ||
452 | "s", | 460 | "s", |
453 | wnames[i]); | 461 | wnames[i]); |
454 | if (errcode) | 462 | if (errcode) |
@@ -462,14 +470,15 @@ p9pdu_vwritef(struct p9_fcall *pdu, int optional, const char *fmt, va_list ap) | |||
462 | struct p9_qid *wqids = | 470 | struct p9_qid *wqids = |
463 | va_arg(ap, struct p9_qid *); | 471 | va_arg(ap, struct p9_qid *); |
464 | 472 | ||
465 | errcode = | 473 | errcode = p9pdu_writef(pdu, proto_version, "w", |
466 | p9pdu_writef(pdu, optional, "w", nwqid); | 474 | nwqid); |
467 | if (!errcode) { | 475 | if (!errcode) { |
468 | int i; | 476 | int i; |
469 | 477 | ||
470 | for (i = 0; i < nwqid; i++) { | 478 | for (i = 0; i < nwqid; i++) { |
471 | errcode = | 479 | errcode = |
472 | p9pdu_writef(pdu, optional, | 480 | p9pdu_writef(pdu, |
481 | proto_version, | ||
473 | "Q", | 482 | "Q", |
474 | &wqids[i]); | 483 | &wqids[i]); |
475 | if (errcode) | 484 | if (errcode) |
@@ -479,7 +488,7 @@ p9pdu_vwritef(struct p9_fcall *pdu, int optional, const char *fmt, va_list ap) | |||
479 | } | 488 | } |
480 | break; | 489 | break; |
481 | case '?': | 490 | case '?': |
482 | if (!optional) | 491 | if (proto_version != p9_proto_2000u) |
483 | return 0; | 492 | return 0; |
484 | break; | 493 | break; |
485 | default: | 494 | default: |
@@ -494,32 +503,32 @@ p9pdu_vwritef(struct p9_fcall *pdu, int optional, const char *fmt, va_list ap) | |||
494 | return errcode; | 503 | return errcode; |
495 | } | 504 | } |
496 | 505 | ||
497 | int p9pdu_readf(struct p9_fcall *pdu, int optional, const char *fmt, ...) | 506 | int p9pdu_readf(struct p9_fcall *pdu, int proto_version, const char *fmt, ...) |
498 | { | 507 | { |
499 | va_list ap; | 508 | va_list ap; |
500 | int ret; | 509 | int ret; |
501 | 510 | ||
502 | va_start(ap, fmt); | 511 | va_start(ap, fmt); |
503 | ret = p9pdu_vreadf(pdu, optional, fmt, ap); | 512 | ret = p9pdu_vreadf(pdu, proto_version, fmt, ap); |
504 | va_end(ap); | 513 | va_end(ap); |
505 | 514 | ||
506 | return ret; | 515 | return ret; |
507 | } | 516 | } |
508 | 517 | ||
509 | static int | 518 | static int |
510 | p9pdu_writef(struct p9_fcall *pdu, int optional, const char *fmt, ...) | 519 | p9pdu_writef(struct p9_fcall *pdu, int proto_version, const char *fmt, ...) |
511 | { | 520 | { |
512 | va_list ap; | 521 | va_list ap; |
513 | int ret; | 522 | int ret; |
514 | 523 | ||
515 | va_start(ap, fmt); | 524 | va_start(ap, fmt); |
516 | ret = p9pdu_vwritef(pdu, optional, fmt, ap); | 525 | ret = p9pdu_vwritef(pdu, proto_version, fmt, ap); |
517 | va_end(ap); | 526 | va_end(ap); |
518 | 527 | ||
519 | return ret; | 528 | return ret; |
520 | } | 529 | } |
521 | 530 | ||
522 | int p9stat_read(char *buf, int len, struct p9_wstat *st, int dotu) | 531 | int p9stat_read(char *buf, int len, struct p9_wstat *st, int proto_version) |
523 | { | 532 | { |
524 | struct p9_fcall fake_pdu; | 533 | struct p9_fcall fake_pdu; |
525 | int ret; | 534 | int ret; |
@@ -529,7 +538,7 @@ int p9stat_read(char *buf, int len, struct p9_wstat *st, int dotu) | |||
529 | fake_pdu.sdata = buf; | 538 | fake_pdu.sdata = buf; |
530 | fake_pdu.offset = 0; | 539 | fake_pdu.offset = 0; |
531 | 540 | ||
532 | ret = p9pdu_readf(&fake_pdu, dotu, "S", st); | 541 | ret = p9pdu_readf(&fake_pdu, proto_version, "S", st); |
533 | if (ret) { | 542 | if (ret) { |
534 | P9_DPRINTK(P9_DEBUG_9P, "<<< p9stat_read failed: %d\n", ret); | 543 | P9_DPRINTK(P9_DEBUG_9P, "<<< p9stat_read failed: %d\n", ret); |
535 | p9pdu_dump(1, &fake_pdu); | 544 | p9pdu_dump(1, &fake_pdu); |
diff --git a/net/9p/protocol.h b/net/9p/protocol.h index ccde462e7ac5..2431c0f38d56 100644 --- a/net/9p/protocol.h +++ b/net/9p/protocol.h | |||
@@ -25,9 +25,9 @@ | |||
25 | * | 25 | * |
26 | */ | 26 | */ |
27 | 27 | ||
28 | int | 28 | int p9pdu_vwritef(struct p9_fcall *pdu, int proto_version, const char *fmt, |
29 | p9pdu_vwritef(struct p9_fcall *pdu, int optional, const char *fmt, va_list ap); | 29 | va_list ap); |
30 | int p9pdu_readf(struct p9_fcall *pdu, int optional, const char *fmt, ...); | 30 | int p9pdu_readf(struct p9_fcall *pdu, int proto_version, const char *fmt, ...); |
31 | int p9pdu_prepare(struct p9_fcall *pdu, int16_t tag, int8_t type); | 31 | int p9pdu_prepare(struct p9_fcall *pdu, int16_t tag, int8_t type); |
32 | int p9pdu_finalize(struct p9_fcall *pdu); | 32 | int p9pdu_finalize(struct p9_fcall *pdu); |
33 | void p9pdu_dump(int, struct p9_fcall *); | 33 | void p9pdu_dump(int, struct p9_fcall *); |
diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c index 31d0b05582a9..98ce9bcb0e15 100644 --- a/net/9p/trans_fd.c +++ b/net/9p/trans_fd.c | |||
@@ -38,6 +38,7 @@ | |||
38 | #include <linux/idr.h> | 38 | #include <linux/idr.h> |
39 | #include <linux/file.h> | 39 | #include <linux/file.h> |
40 | #include <linux/parser.h> | 40 | #include <linux/parser.h> |
41 | #include <linux/slab.h> | ||
41 | #include <net/9p/9p.h> | 42 | #include <net/9p/9p.h> |
42 | #include <net/9p/client.h> | 43 | #include <net/9p/client.h> |
43 | #include <net/9p/transport.h> | 44 | #include <net/9p/transport.h> |
diff --git a/net/9p/trans_rdma.c b/net/9p/trans_rdma.c index 2c95a89c0f46..041101ab4aa5 100644 --- a/net/9p/trans_rdma.c +++ b/net/9p/trans_rdma.c | |||
@@ -40,6 +40,7 @@ | |||
40 | #include <linux/file.h> | 40 | #include <linux/file.h> |
41 | #include <linux/parser.h> | 41 | #include <linux/parser.h> |
42 | #include <linux/semaphore.h> | 42 | #include <linux/semaphore.h> |
43 | #include <linux/slab.h> | ||
43 | #include <net/9p/9p.h> | 44 | #include <net/9p/9p.h> |
44 | #include <net/9p/client.h> | 45 | #include <net/9p/client.h> |
45 | #include <net/9p/transport.h> | 46 | #include <net/9p/transport.h> |
diff --git a/net/9p/trans_virtio.c b/net/9p/trans_virtio.c index cb50f4ae5eef..7eb78ecc1618 100644 --- a/net/9p/trans_virtio.c +++ b/net/9p/trans_virtio.c | |||
@@ -37,6 +37,7 @@ | |||
37 | #include <linux/inet.h> | 37 | #include <linux/inet.h> |
38 | #include <linux/idr.h> | 38 | #include <linux/idr.h> |
39 | #include <linux/file.h> | 39 | #include <linux/file.h> |
40 | #include <linux/slab.h> | ||
40 | #include <net/9p/9p.h> | 41 | #include <net/9p/9p.h> |
41 | #include <linux/parser.h> | 42 | #include <linux/parser.h> |
42 | #include <net/9p/client.h> | 43 | #include <net/9p/client.h> |
@@ -49,8 +50,6 @@ | |||
49 | 50 | ||
50 | /* a single mutex to manage channel initialization and attachment */ | 51 | /* a single mutex to manage channel initialization and attachment */ |
51 | static DEFINE_MUTEX(virtio_9p_lock); | 52 | static DEFINE_MUTEX(virtio_9p_lock); |
52 | /* global which tracks highest initialized channel */ | ||
53 | static int chan_index; | ||
54 | 53 | ||
55 | /** | 54 | /** |
56 | * struct virtio_chan - per-instance transport information | 55 | * struct virtio_chan - per-instance transport information |
@@ -68,8 +67,7 @@ static int chan_index; | |||
68 | * | 67 | * |
69 | */ | 68 | */ |
70 | 69 | ||
71 | static struct virtio_chan { | 70 | struct virtio_chan { |
72 | bool initialized; | ||
73 | bool inuse; | 71 | bool inuse; |
74 | 72 | ||
75 | spinlock_t lock; | 73 | spinlock_t lock; |
@@ -80,7 +78,17 @@ static struct virtio_chan { | |||
80 | 78 | ||
81 | /* Scatterlist: can be too big for stack. */ | 79 | /* Scatterlist: can be too big for stack. */ |
82 | struct scatterlist sg[VIRTQUEUE_NUM]; | 80 | struct scatterlist sg[VIRTQUEUE_NUM]; |
83 | } channels[MAX_9P_CHAN]; | 81 | |
82 | int tag_len; | ||
83 | /* | ||
84 | * tag name to identify a mount Non-null terminated | ||
85 | */ | ||
86 | char *tag; | ||
87 | |||
88 | struct list_head chan_list; | ||
89 | }; | ||
90 | |||
91 | static struct list_head virtio_chan_list; | ||
84 | 92 | ||
85 | /* How many bytes left in this page. */ | 93 | /* How many bytes left in this page. */ |
86 | static unsigned int rest_of_page(void *data) | 94 | static unsigned int rest_of_page(void *data) |
@@ -213,30 +221,38 @@ p9_virtio_request(struct p9_client *client, struct p9_req_t *req) | |||
213 | return 0; | 221 | return 0; |
214 | } | 222 | } |
215 | 223 | ||
224 | static ssize_t p9_mount_tag_show(struct device *dev, | ||
225 | struct device_attribute *attr, char *buf) | ||
226 | { | ||
227 | struct virtio_chan *chan; | ||
228 | struct virtio_device *vdev; | ||
229 | |||
230 | vdev = dev_to_virtio(dev); | ||
231 | chan = vdev->priv; | ||
232 | |||
233 | return snprintf(buf, chan->tag_len + 1, "%s", chan->tag); | ||
234 | } | ||
235 | |||
236 | static DEVICE_ATTR(mount_tag, 0444, p9_mount_tag_show, NULL); | ||
237 | |||
216 | /** | 238 | /** |
217 | * p9_virtio_probe - probe for existence of 9P virtio channels | 239 | * p9_virtio_probe - probe for existence of 9P virtio channels |
218 | * @vdev: virtio device to probe | 240 | * @vdev: virtio device to probe |
219 | * | 241 | * |
220 | * This probes for existing virtio channels. At present only | 242 | * This probes for existing virtio channels. |
221 | * a single channel is in use, so in the future more work may need | ||
222 | * to be done here. | ||
223 | * | 243 | * |
224 | */ | 244 | */ |
225 | 245 | ||
226 | static int p9_virtio_probe(struct virtio_device *vdev) | 246 | static int p9_virtio_probe(struct virtio_device *vdev) |
227 | { | 247 | { |
248 | __u16 tag_len; | ||
249 | char *tag; | ||
228 | int err; | 250 | int err; |
229 | struct virtio_chan *chan; | 251 | struct virtio_chan *chan; |
230 | int index; | ||
231 | 252 | ||
232 | mutex_lock(&virtio_9p_lock); | 253 | chan = kmalloc(sizeof(struct virtio_chan), GFP_KERNEL); |
233 | index = chan_index++; | 254 | if (!chan) { |
234 | chan = &channels[index]; | 255 | printk(KERN_ERR "9p: Failed to allocate virtio 9P channel\n"); |
235 | mutex_unlock(&virtio_9p_lock); | ||
236 | |||
237 | if (chan_index > MAX_9P_CHAN) { | ||
238 | printk(KERN_ERR "9p: virtio: Maximum channels exceeded\n"); | ||
239 | BUG(); | ||
240 | err = -ENOMEM; | 256 | err = -ENOMEM; |
241 | goto fail; | 257 | goto fail; |
242 | } | 258 | } |
@@ -255,15 +271,37 @@ static int p9_virtio_probe(struct virtio_device *vdev) | |||
255 | sg_init_table(chan->sg, VIRTQUEUE_NUM); | 271 | sg_init_table(chan->sg, VIRTQUEUE_NUM); |
256 | 272 | ||
257 | chan->inuse = false; | 273 | chan->inuse = false; |
258 | chan->initialized = true; | 274 | if (virtio_has_feature(vdev, VIRTIO_9P_MOUNT_TAG)) { |
275 | vdev->config->get(vdev, | ||
276 | offsetof(struct virtio_9p_config, tag_len), | ||
277 | &tag_len, sizeof(tag_len)); | ||
278 | } else { | ||
279 | err = -EINVAL; | ||
280 | goto out_free_vq; | ||
281 | } | ||
282 | tag = kmalloc(tag_len, GFP_KERNEL); | ||
283 | if (!tag) { | ||
284 | err = -ENOMEM; | ||
285 | goto out_free_vq; | ||
286 | } | ||
287 | vdev->config->get(vdev, offsetof(struct virtio_9p_config, tag), | ||
288 | tag, tag_len); | ||
289 | chan->tag = tag; | ||
290 | chan->tag_len = tag_len; | ||
291 | err = sysfs_create_file(&(vdev->dev.kobj), &dev_attr_mount_tag.attr); | ||
292 | if (err) { | ||
293 | kfree(tag); | ||
294 | goto out_free_vq; | ||
295 | } | ||
296 | mutex_lock(&virtio_9p_lock); | ||
297 | list_add_tail(&chan->chan_list, &virtio_chan_list); | ||
298 | mutex_unlock(&virtio_9p_lock); | ||
259 | return 0; | 299 | return 0; |
260 | 300 | ||
261 | out_free_vq: | 301 | out_free_vq: |
262 | vdev->config->del_vqs(vdev); | 302 | vdev->config->del_vqs(vdev); |
303 | kfree(chan); | ||
263 | fail: | 304 | fail: |
264 | mutex_lock(&virtio_9p_lock); | ||
265 | chan_index--; | ||
266 | mutex_unlock(&virtio_9p_lock); | ||
267 | return err; | 305 | return err; |
268 | } | 306 | } |
269 | 307 | ||
@@ -280,35 +318,31 @@ fail: | |||
280 | * We use a simple reference count mechanism to ensure that only a single | 318 | * We use a simple reference count mechanism to ensure that only a single |
281 | * mount has a channel open at a time. | 319 | * mount has a channel open at a time. |
282 | * | 320 | * |
283 | * Bugs: doesn't allow identification of a specific channel | ||
284 | * to allocate, channels are allocated sequentially. This was | ||
285 | * a pragmatic decision to get things rolling, but ideally some | ||
286 | * way of identifying the channel to attach to would be nice | ||
287 | * if we are going to support multiple channels. | ||
288 | * | ||
289 | */ | 321 | */ |
290 | 322 | ||
291 | static int | 323 | static int |
292 | p9_virtio_create(struct p9_client *client, const char *devname, char *args) | 324 | p9_virtio_create(struct p9_client *client, const char *devname, char *args) |
293 | { | 325 | { |
294 | struct virtio_chan *chan = channels; | 326 | struct virtio_chan *chan; |
295 | int index = 0; | 327 | int ret = -ENOENT; |
328 | int found = 0; | ||
296 | 329 | ||
297 | mutex_lock(&virtio_9p_lock); | 330 | mutex_lock(&virtio_9p_lock); |
298 | while (index < MAX_9P_CHAN) { | 331 | list_for_each_entry(chan, &virtio_chan_list, chan_list) { |
299 | if (chan->initialized && !chan->inuse) { | 332 | if (!strncmp(devname, chan->tag, chan->tag_len)) { |
300 | chan->inuse = true; | 333 | if (!chan->inuse) { |
301 | break; | 334 | chan->inuse = true; |
302 | } else { | 335 | found = 1; |
303 | index++; | 336 | break; |
304 | chan = &channels[index]; | 337 | } |
338 | ret = -EBUSY; | ||
305 | } | 339 | } |
306 | } | 340 | } |
307 | mutex_unlock(&virtio_9p_lock); | 341 | mutex_unlock(&virtio_9p_lock); |
308 | 342 | ||
309 | if (index >= MAX_9P_CHAN) { | 343 | if (!found) { |
310 | printk(KERN_ERR "9p: no channels available\n"); | 344 | printk(KERN_ERR "9p: no channels available\n"); |
311 | return -ENODEV; | 345 | return ret; |
312 | } | 346 | } |
313 | 347 | ||
314 | client->trans = (void *)chan; | 348 | client->trans = (void *)chan; |
@@ -329,11 +363,15 @@ static void p9_virtio_remove(struct virtio_device *vdev) | |||
329 | struct virtio_chan *chan = vdev->priv; | 363 | struct virtio_chan *chan = vdev->priv; |
330 | 364 | ||
331 | BUG_ON(chan->inuse); | 365 | BUG_ON(chan->inuse); |
366 | vdev->config->del_vqs(vdev); | ||
367 | |||
368 | mutex_lock(&virtio_9p_lock); | ||
369 | list_del(&chan->chan_list); | ||
370 | mutex_unlock(&virtio_9p_lock); | ||
371 | sysfs_remove_file(&(vdev->dev.kobj), &dev_attr_mount_tag.attr); | ||
372 | kfree(chan->tag); | ||
373 | kfree(chan); | ||
332 | 374 | ||
333 | if (chan->initialized) { | ||
334 | vdev->config->del_vqs(vdev); | ||
335 | chan->initialized = false; | ||
336 | } | ||
337 | } | 375 | } |
338 | 376 | ||
339 | static struct virtio_device_id id_table[] = { | 377 | static struct virtio_device_id id_table[] = { |
@@ -341,13 +379,19 @@ static struct virtio_device_id id_table[] = { | |||
341 | { 0 }, | 379 | { 0 }, |
342 | }; | 380 | }; |
343 | 381 | ||
382 | static unsigned int features[] = { | ||
383 | VIRTIO_9P_MOUNT_TAG, | ||
384 | }; | ||
385 | |||
344 | /* The standard "struct lguest_driver": */ | 386 | /* The standard "struct lguest_driver": */ |
345 | static struct virtio_driver p9_virtio_drv = { | 387 | static struct virtio_driver p9_virtio_drv = { |
346 | .driver.name = KBUILD_MODNAME, | 388 | .feature_table = features, |
347 | .driver.owner = THIS_MODULE, | 389 | .feature_table_size = ARRAY_SIZE(features), |
348 | .id_table = id_table, | 390 | .driver.name = KBUILD_MODNAME, |
349 | .probe = p9_virtio_probe, | 391 | .driver.owner = THIS_MODULE, |
350 | .remove = p9_virtio_remove, | 392 | .id_table = id_table, |
393 | .probe = p9_virtio_probe, | ||
394 | .remove = p9_virtio_remove, | ||
351 | }; | 395 | }; |
352 | 396 | ||
353 | static struct p9_trans_module p9_virtio_trans = { | 397 | static struct p9_trans_module p9_virtio_trans = { |
@@ -364,10 +408,7 @@ static struct p9_trans_module p9_virtio_trans = { | |||
364 | /* The standard init function */ | 408 | /* The standard init function */ |
365 | static int __init p9_virtio_init(void) | 409 | static int __init p9_virtio_init(void) |
366 | { | 410 | { |
367 | int count; | 411 | INIT_LIST_HEAD(&virtio_chan_list); |
368 | |||
369 | for (count = 0; count < MAX_9P_CHAN; count++) | ||
370 | channels[count].initialized = false; | ||
371 | 412 | ||
372 | v9fs_register_trans(&p9_virtio_trans); | 413 | v9fs_register_trans(&p9_virtio_trans); |
373 | return register_virtio_driver(&p9_virtio_drv); | 414 | return register_virtio_driver(&p9_virtio_drv); |
diff --git a/net/9p/util.c b/net/9p/util.c index dc4ec05ad93d..e048701a72d2 100644 --- a/net/9p/util.c +++ b/net/9p/util.c | |||
@@ -30,6 +30,7 @@ | |||
30 | #include <linux/sched.h> | 30 | #include <linux/sched.h> |
31 | #include <linux/parser.h> | 31 | #include <linux/parser.h> |
32 | #include <linux/idr.h> | 32 | #include <linux/idr.h> |
33 | #include <linux/slab.h> | ||
33 | #include <net/9p/9p.h> | 34 | #include <net/9p/9p.h> |
34 | 35 | ||
35 | /** | 36 | /** |
diff --git a/net/Kconfig b/net/Kconfig index 041c35edb763..0d68b40fc0e6 100644 --- a/net/Kconfig +++ b/net/Kconfig | |||
@@ -186,6 +186,7 @@ source "net/sctp/Kconfig" | |||
186 | source "net/rds/Kconfig" | 186 | source "net/rds/Kconfig" |
187 | source "net/tipc/Kconfig" | 187 | source "net/tipc/Kconfig" |
188 | source "net/atm/Kconfig" | 188 | source "net/atm/Kconfig" |
189 | source "net/l2tp/Kconfig" | ||
189 | source "net/802/Kconfig" | 190 | source "net/802/Kconfig" |
190 | source "net/bridge/Kconfig" | 191 | source "net/bridge/Kconfig" |
191 | source "net/dsa/Kconfig" | 192 | source "net/dsa/Kconfig" |
@@ -203,6 +204,11 @@ source "net/ieee802154/Kconfig" | |||
203 | source "net/sched/Kconfig" | 204 | source "net/sched/Kconfig" |
204 | source "net/dcb/Kconfig" | 205 | source "net/dcb/Kconfig" |
205 | 206 | ||
207 | config RPS | ||
208 | boolean | ||
209 | depends on SMP && SYSFS | ||
210 | default y | ||
211 | |||
206 | menu "Network testing" | 212 | menu "Network testing" |
207 | 213 | ||
208 | config NET_PKTGEN | 214 | config NET_PKTGEN |
@@ -275,5 +281,7 @@ source "net/wimax/Kconfig" | |||
275 | 281 | ||
276 | source "net/rfkill/Kconfig" | 282 | source "net/rfkill/Kconfig" |
277 | source "net/9p/Kconfig" | 283 | source "net/9p/Kconfig" |
284 | source "net/caif/Kconfig" | ||
285 | |||
278 | 286 | ||
279 | endif # if NET | 287 | endif # if NET |
diff --git a/net/Makefile b/net/Makefile index 1542e7268a7b..cb7bdc1210cb 100644 --- a/net/Makefile +++ b/net/Makefile | |||
@@ -40,6 +40,7 @@ obj-$(CONFIG_BT) += bluetooth/ | |||
40 | obj-$(CONFIG_SUNRPC) += sunrpc/ | 40 | obj-$(CONFIG_SUNRPC) += sunrpc/ |
41 | obj-$(CONFIG_AF_RXRPC) += rxrpc/ | 41 | obj-$(CONFIG_AF_RXRPC) += rxrpc/ |
42 | obj-$(CONFIG_ATM) += atm/ | 42 | obj-$(CONFIG_ATM) += atm/ |
43 | obj-$(CONFIG_L2TP) += l2tp/ | ||
43 | obj-$(CONFIG_DECNET) += decnet/ | 44 | obj-$(CONFIG_DECNET) += decnet/ |
44 | obj-$(CONFIG_ECONET) += econet/ | 45 | obj-$(CONFIG_ECONET) += econet/ |
45 | obj-$(CONFIG_PHONET) += phonet/ | 46 | obj-$(CONFIG_PHONET) += phonet/ |
@@ -56,6 +57,7 @@ obj-$(CONFIG_NETLABEL) += netlabel/ | |||
56 | obj-$(CONFIG_IUCV) += iucv/ | 57 | obj-$(CONFIG_IUCV) += iucv/ |
57 | obj-$(CONFIG_RFKILL) += rfkill/ | 58 | obj-$(CONFIG_RFKILL) += rfkill/ |
58 | obj-$(CONFIG_NET_9P) += 9p/ | 59 | obj-$(CONFIG_NET_9P) += 9p/ |
60 | obj-$(CONFIG_CAIF) += caif/ | ||
59 | ifneq ($(CONFIG_DCB),) | 61 | ifneq ($(CONFIG_DCB),) |
60 | obj-y += dcb/ | 62 | obj-y += dcb/ |
61 | endif | 63 | endif |
diff --git a/net/appletalk/aarp.c b/net/appletalk/aarp.c index f2b3b56aa779..50dce7981321 100644 --- a/net/appletalk/aarp.c +++ b/net/appletalk/aarp.c | |||
@@ -30,6 +30,7 @@ | |||
30 | */ | 30 | */ |
31 | 31 | ||
32 | #include <linux/if_arp.h> | 32 | #include <linux/if_arp.h> |
33 | #include <linux/slab.h> | ||
33 | #include <net/sock.h> | 34 | #include <net/sock.h> |
34 | #include <net/datalink.h> | 35 | #include <net/datalink.h> |
35 | #include <net/psnap.h> | 36 | #include <net/psnap.h> |
diff --git a/net/appletalk/ddp.c b/net/appletalk/ddp.c index 9fc4da56fb1d..c410b93fda2e 100644 --- a/net/appletalk/ddp.c +++ b/net/appletalk/ddp.c | |||
@@ -57,6 +57,7 @@ | |||
57 | #include <linux/smp_lock.h> | 57 | #include <linux/smp_lock.h> |
58 | #include <linux/termios.h> /* For TIOCOUTQ/INQ */ | 58 | #include <linux/termios.h> /* For TIOCOUTQ/INQ */ |
59 | #include <linux/compat.h> | 59 | #include <linux/compat.h> |
60 | #include <linux/slab.h> | ||
60 | #include <net/datalink.h> | 61 | #include <net/datalink.h> |
61 | #include <net/psnap.h> | 62 | #include <net/psnap.h> |
62 | #include <net/sock.h> | 63 | #include <net/sock.h> |
@@ -781,7 +782,7 @@ static int atif_ioctl(int cmd, void __user *arg) | |||
781 | atrtr_create(&rtdef, dev); | 782 | atrtr_create(&rtdef, dev); |
782 | } | 783 | } |
783 | } | 784 | } |
784 | dev_mc_add(dev, aarp_mcast, 6, 1); | 785 | dev_mc_add_global(dev, aarp_mcast); |
785 | return 0; | 786 | return 0; |
786 | 787 | ||
787 | case SIOCGIFADDR: | 788 | case SIOCGIFADDR: |
diff --git a/net/atm/addr.c b/net/atm/addr.c index cf3ae8b47572..dcda35c66f15 100644 --- a/net/atm/addr.c +++ b/net/atm/addr.c | |||
@@ -4,6 +4,7 @@ | |||
4 | 4 | ||
5 | #include <linux/atm.h> | 5 | #include <linux/atm.h> |
6 | #include <linux/atmdev.h> | 6 | #include <linux/atmdev.h> |
7 | #include <linux/slab.h> | ||
7 | #include <linux/uaccess.h> | 8 | #include <linux/uaccess.h> |
8 | 9 | ||
9 | #include "signaling.h" | 10 | #include "signaling.h" |
diff --git a/net/atm/atm_sysfs.c b/net/atm/atm_sysfs.c index f693b78eb467..799c631f0fed 100644 --- a/net/atm/atm_sysfs.c +++ b/net/atm/atm_sysfs.c | |||
@@ -1,6 +1,7 @@ | |||
1 | /* ATM driver model support. */ | 1 | /* ATM driver model support. */ |
2 | 2 | ||
3 | #include <linux/kernel.h> | 3 | #include <linux/kernel.h> |
4 | #include <linux/slab.h> | ||
4 | #include <linux/init.h> | 5 | #include <linux/init.h> |
5 | #include <linux/kobject.h> | 6 | #include <linux/kobject.h> |
6 | #include <linux/atmdev.h> | 7 | #include <linux/atmdev.h> |
diff --git a/net/atm/br2684.c b/net/atm/br2684.c index 4d64d87e7578..d6c7ceaf13e9 100644 --- a/net/atm/br2684.c +++ b/net/atm/br2684.c | |||
@@ -18,6 +18,7 @@ | |||
18 | #include <linux/rtnetlink.h> | 18 | #include <linux/rtnetlink.h> |
19 | #include <linux/ip.h> | 19 | #include <linux/ip.h> |
20 | #include <linux/uaccess.h> | 20 | #include <linux/uaccess.h> |
21 | #include <linux/slab.h> | ||
21 | #include <net/arp.h> | 22 | #include <net/arp.h> |
22 | #include <linux/atm.h> | 23 | #include <linux/atm.h> |
23 | #include <linux/atmdev.h> | 24 | #include <linux/atmdev.h> |
diff --git a/net/atm/clip.c b/net/atm/clip.c index ebfa022008f7..313aba11316b 100644 --- a/net/atm/clip.c +++ b/net/atm/clip.c | |||
@@ -30,6 +30,7 @@ | |||
30 | #include <linux/seq_file.h> | 30 | #include <linux/seq_file.h> |
31 | #include <linux/rcupdate.h> | 31 | #include <linux/rcupdate.h> |
32 | #include <linux/jhash.h> | 32 | #include <linux/jhash.h> |
33 | #include <linux/slab.h> | ||
33 | #include <net/route.h> /* for struct rtable and routing */ | 34 | #include <net/route.h> /* for struct rtable and routing */ |
34 | #include <net/icmp.h> /* icmp_send */ | 35 | #include <net/icmp.h> /* icmp_send */ |
35 | #include <linux/param.h> /* for HZ */ | 36 | #include <linux/param.h> /* for HZ */ |
diff --git a/net/atm/common.c b/net/atm/common.c index 74d095a081e3..97ed94aa0cbc 100644 --- a/net/atm/common.c +++ b/net/atm/common.c | |||
@@ -18,6 +18,7 @@ | |||
18 | #include <linux/skbuff.h> | 18 | #include <linux/skbuff.h> |
19 | #include <linux/bitops.h> | 19 | #include <linux/bitops.h> |
20 | #include <linux/init.h> | 20 | #include <linux/init.h> |
21 | #include <linux/slab.h> | ||
21 | #include <net/sock.h> /* struct sock */ | 22 | #include <net/sock.h> /* struct sock */ |
22 | #include <linux/uaccess.h> | 23 | #include <linux/uaccess.h> |
23 | #include <linux/poll.h> | 24 | #include <linux/poll.h> |
diff --git a/net/atm/lec.c b/net/atm/lec.c index 5da5753157f9..feeaf5718472 100644 --- a/net/atm/lec.c +++ b/net/atm/lec.c | |||
@@ -6,6 +6,7 @@ | |||
6 | 6 | ||
7 | #define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__ | 7 | #define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__ |
8 | 8 | ||
9 | #include <linux/slab.h> | ||
9 | #include <linux/kernel.h> | 10 | #include <linux/kernel.h> |
10 | #include <linux/bitops.h> | 11 | #include <linux/bitops.h> |
11 | #include <linux/capability.h> | 12 | #include <linux/capability.h> |
diff --git a/net/atm/mpc.c b/net/atm/mpc.c index a6521c8aa88b..436f2e177657 100644 --- a/net/atm/mpc.c +++ b/net/atm/mpc.c | |||
@@ -2,6 +2,7 @@ | |||
2 | 2 | ||
3 | #include <linux/kernel.h> | 3 | #include <linux/kernel.h> |
4 | #include <linux/string.h> | 4 | #include <linux/string.h> |
5 | #include <linux/slab.h> | ||
5 | #include <linux/timer.h> | 6 | #include <linux/timer.h> |
6 | #include <linux/init.h> | 7 | #include <linux/init.h> |
7 | #include <linux/bitops.h> | 8 | #include <linux/bitops.h> |
diff --git a/net/atm/mpoa_caches.c b/net/atm/mpoa_caches.c index 4c141810eb6d..e773d8336918 100644 --- a/net/atm/mpoa_caches.c +++ b/net/atm/mpoa_caches.c | |||
@@ -1,5 +1,6 @@ | |||
1 | #include <linux/types.h> | 1 | #include <linux/types.h> |
2 | #include <linux/atmmpc.h> | 2 | #include <linux/atmmpc.h> |
3 | #include <linux/slab.h> | ||
3 | #include <linux/time.h> | 4 | #include <linux/time.h> |
4 | 5 | ||
5 | #include "mpoa_caches.h" | 6 | #include "mpoa_caches.h" |
diff --git a/net/atm/mpoa_proc.c b/net/atm/mpoa_proc.c index b9bdb98427e4..53e500292271 100644 --- a/net/atm/mpoa_proc.c +++ b/net/atm/mpoa_proc.c | |||
@@ -12,6 +12,7 @@ | |||
12 | #include <linux/uaccess.h> | 12 | #include <linux/uaccess.h> |
13 | #include <linux/atmmpc.h> | 13 | #include <linux/atmmpc.h> |
14 | #include <linux/atm.h> | 14 | #include <linux/atm.h> |
15 | #include <linux/gfp.h> | ||
15 | #include "mpc.h" | 16 | #include "mpc.h" |
16 | #include "mpoa_caches.h" | 17 | #include "mpoa_caches.h" |
17 | 18 | ||
diff --git a/net/atm/pppoatm.c b/net/atm/pppoatm.c index 400839273c67..e49bb6d948a1 100644 --- a/net/atm/pppoatm.c +++ b/net/atm/pppoatm.c | |||
@@ -38,6 +38,7 @@ | |||
38 | #include <linux/module.h> | 38 | #include <linux/module.h> |
39 | #include <linux/init.h> | 39 | #include <linux/init.h> |
40 | #include <linux/skbuff.h> | 40 | #include <linux/skbuff.h> |
41 | #include <linux/slab.h> | ||
41 | #include <linux/atm.h> | 42 | #include <linux/atm.h> |
42 | #include <linux/atmdev.h> | 43 | #include <linux/atmdev.h> |
43 | #include <linux/capability.h> | 44 | #include <linux/capability.h> |
diff --git a/net/atm/proc.c b/net/atm/proc.c index 7a96b2376bd7..6262aeae398e 100644 --- a/net/atm/proc.c +++ b/net/atm/proc.c | |||
@@ -22,6 +22,7 @@ | |||
22 | #include <linux/netdevice.h> | 22 | #include <linux/netdevice.h> |
23 | #include <linux/atmclip.h> | 23 | #include <linux/atmclip.h> |
24 | #include <linux/init.h> /* for __init */ | 24 | #include <linux/init.h> /* for __init */ |
25 | #include <linux/slab.h> | ||
25 | #include <net/net_namespace.h> | 26 | #include <net/net_namespace.h> |
26 | #include <net/atmclip.h> | 27 | #include <net/atmclip.h> |
27 | #include <linux/uaccess.h> | 28 | #include <linux/uaccess.h> |
@@ -406,7 +407,6 @@ EXPORT_SYMBOL(atm_proc_root); | |||
406 | 407 | ||
407 | int atm_proc_dev_register(struct atm_dev *dev) | 408 | int atm_proc_dev_register(struct atm_dev *dev) |
408 | { | 409 | { |
409 | int digits, num; | ||
410 | int error; | 410 | int error; |
411 | 411 | ||
412 | /* No proc info */ | 412 | /* No proc info */ |
@@ -414,16 +414,9 @@ int atm_proc_dev_register(struct atm_dev *dev) | |||
414 | return 0; | 414 | return 0; |
415 | 415 | ||
416 | error = -ENOMEM; | 416 | error = -ENOMEM; |
417 | digits = 0; | 417 | dev->proc_name = kasprintf(GFP_KERNEL, "%s:%d", dev->type, dev->number); |
418 | for (num = dev->number; num; num /= 10) | ||
419 | digits++; | ||
420 | if (!digits) | ||
421 | digits++; | ||
422 | |||
423 | dev->proc_name = kmalloc(strlen(dev->type) + digits + 2, GFP_KERNEL); | ||
424 | if (!dev->proc_name) | 418 | if (!dev->proc_name) |
425 | goto err_out; | 419 | goto err_out; |
426 | sprintf(dev->proc_name, "%s:%d", dev->type, dev->number); | ||
427 | 420 | ||
428 | dev->proc_entry = proc_create_data(dev->proc_name, 0, atm_proc_root, | 421 | dev->proc_entry = proc_create_data(dev->proc_name, 0, atm_proc_root, |
429 | &proc_atm_dev_ops, dev); | 422 | &proc_atm_dev_ops, dev); |
diff --git a/net/atm/raw.c b/net/atm/raw.c index d0c4bd047dc4..b4f7b9ff3c74 100644 --- a/net/atm/raw.c +++ b/net/atm/raw.c | |||
@@ -10,6 +10,7 @@ | |||
10 | #include <linux/kernel.h> | 10 | #include <linux/kernel.h> |
11 | #include <linux/skbuff.h> | 11 | #include <linux/skbuff.h> |
12 | #include <linux/mm.h> | 12 | #include <linux/mm.h> |
13 | #include <linux/slab.h> | ||
13 | 14 | ||
14 | #include "common.h" | 15 | #include "common.h" |
15 | #include "protocols.h" | 16 | #include "protocols.h" |
diff --git a/net/atm/resources.c b/net/atm/resources.c index 90082904f20d..d29e58261511 100644 --- a/net/atm/resources.c +++ b/net/atm/resources.c | |||
@@ -19,6 +19,7 @@ | |||
19 | #include <linux/capability.h> | 19 | #include <linux/capability.h> |
20 | #include <linux/delay.h> | 20 | #include <linux/delay.h> |
21 | #include <linux/mutex.h> | 21 | #include <linux/mutex.h> |
22 | #include <linux/slab.h> | ||
22 | 23 | ||
23 | #include <net/sock.h> /* for struct sock */ | 24 | #include <net/sock.h> /* for struct sock */ |
24 | 25 | ||
diff --git a/net/atm/signaling.c b/net/atm/signaling.c index ad1d28ae512b..6ba6e466ee54 100644 --- a/net/atm/signaling.c +++ b/net/atm/signaling.c | |||
@@ -14,6 +14,7 @@ | |||
14 | #include <linux/atmsvc.h> | 14 | #include <linux/atmsvc.h> |
15 | #include <linux/atmdev.h> | 15 | #include <linux/atmdev.h> |
16 | #include <linux/bitops.h> | 16 | #include <linux/bitops.h> |
17 | #include <linux/slab.h> | ||
17 | 18 | ||
18 | #include "resources.h" | 19 | #include "resources.h" |
19 | #include "signaling.h" | 20 | #include "signaling.h" |
diff --git a/net/ax25/af_ax25.c b/net/ax25/af_ax25.c index a5beedf43e2d..65c5801261f9 100644 --- a/net/ax25/af_ax25.c +++ b/net/ax25/af_ax25.c | |||
@@ -25,6 +25,7 @@ | |||
25 | #include <linux/string.h> | 25 | #include <linux/string.h> |
26 | #include <linux/sockios.h> | 26 | #include <linux/sockios.h> |
27 | #include <linux/net.h> | 27 | #include <linux/net.h> |
28 | #include <linux/slab.h> | ||
28 | #include <net/ax25.h> | 29 | #include <net/ax25.h> |
29 | #include <linux/inet.h> | 30 | #include <linux/inet.h> |
30 | #include <linux/netdevice.h> | 31 | #include <linux/netdevice.h> |
diff --git a/net/ax25/ax25_dev.c b/net/ax25/ax25_dev.c index a7a0e0c9698b..c1cb982f6e86 100644 --- a/net/ax25/ax25_dev.c +++ b/net/ax25/ax25_dev.c | |||
@@ -9,6 +9,7 @@ | |||
9 | #include <linux/errno.h> | 9 | #include <linux/errno.h> |
10 | #include <linux/types.h> | 10 | #include <linux/types.h> |
11 | #include <linux/socket.h> | 11 | #include <linux/socket.h> |
12 | #include <linux/slab.h> | ||
12 | #include <linux/in.h> | 13 | #include <linux/in.h> |
13 | #include <linux/kernel.h> | 14 | #include <linux/kernel.h> |
14 | #include <linux/timer.h> | 15 | #include <linux/timer.h> |
diff --git a/net/ax25/ax25_ds_subr.c b/net/ax25/ax25_ds_subr.c index b5e59787be2f..85816e612dc0 100644 --- a/net/ax25/ax25_ds_subr.c +++ b/net/ax25/ax25_ds_subr.c | |||
@@ -17,6 +17,7 @@ | |||
17 | #include <linux/sockios.h> | 17 | #include <linux/sockios.h> |
18 | #include <linux/spinlock.h> | 18 | #include <linux/spinlock.h> |
19 | #include <linux/net.h> | 19 | #include <linux/net.h> |
20 | #include <linux/gfp.h> | ||
20 | #include <net/ax25.h> | 21 | #include <net/ax25.h> |
21 | #include <linux/inet.h> | 22 | #include <linux/inet.h> |
22 | #include <linux/netdevice.h> | 23 | #include <linux/netdevice.h> |
diff --git a/net/ax25/ax25_iface.c b/net/ax25/ax25_iface.c index 71338f112108..5a0dda8df492 100644 --- a/net/ax25/ax25_iface.c +++ b/net/ax25/ax25_iface.c | |||
@@ -17,6 +17,7 @@ | |||
17 | #include <linux/string.h> | 17 | #include <linux/string.h> |
18 | #include <linux/sockios.h> | 18 | #include <linux/sockios.h> |
19 | #include <linux/net.h> | 19 | #include <linux/net.h> |
20 | #include <linux/slab.h> | ||
20 | #include <net/ax25.h> | 21 | #include <net/ax25.h> |
21 | #include <linux/inet.h> | 22 | #include <linux/inet.h> |
22 | #include <linux/netdevice.h> | 23 | #include <linux/netdevice.h> |
diff --git a/net/ax25/ax25_in.c b/net/ax25/ax25_in.c index de56d3983de0..9bb776541203 100644 --- a/net/ax25/ax25_in.c +++ b/net/ax25/ax25_in.c | |||
@@ -18,6 +18,7 @@ | |||
18 | #include <linux/string.h> | 18 | #include <linux/string.h> |
19 | #include <linux/sockios.h> | 19 | #include <linux/sockios.h> |
20 | #include <linux/net.h> | 20 | #include <linux/net.h> |
21 | #include <linux/slab.h> | ||
21 | #include <net/ax25.h> | 22 | #include <net/ax25.h> |
22 | #include <linux/inet.h> | 23 | #include <linux/inet.h> |
23 | #include <linux/netdevice.h> | 24 | #include <linux/netdevice.h> |
diff --git a/net/ax25/ax25_ip.c b/net/ax25/ax25_ip.c index f047a57aa95c..cf0c47a26530 100644 --- a/net/ax25/ax25_ip.c +++ b/net/ax25/ax25_ip.c | |||
@@ -16,6 +16,7 @@ | |||
16 | #include <linux/string.h> | 16 | #include <linux/string.h> |
17 | #include <linux/sockios.h> | 17 | #include <linux/sockios.h> |
18 | #include <linux/net.h> | 18 | #include <linux/net.h> |
19 | #include <linux/slab.h> | ||
19 | #include <net/ax25.h> | 20 | #include <net/ax25.h> |
20 | #include <linux/inet.h> | 21 | #include <linux/inet.h> |
21 | #include <linux/netdevice.h> | 22 | #include <linux/netdevice.h> |
diff --git a/net/ax25/ax25_out.c b/net/ax25/ax25_out.c index 14912600ec57..37507d806f65 100644 --- a/net/ax25/ax25_out.c +++ b/net/ax25/ax25_out.c | |||
@@ -19,6 +19,7 @@ | |||
19 | #include <linux/sockios.h> | 19 | #include <linux/sockios.h> |
20 | #include <linux/spinlock.h> | 20 | #include <linux/spinlock.h> |
21 | #include <linux/net.h> | 21 | #include <linux/net.h> |
22 | #include <linux/slab.h> | ||
22 | #include <net/ax25.h> | 23 | #include <net/ax25.h> |
23 | #include <linux/inet.h> | 24 | #include <linux/inet.h> |
24 | #include <linux/netdevice.h> | 25 | #include <linux/netdevice.h> |
diff --git a/net/ax25/ax25_route.c b/net/ax25/ax25_route.c index c833ba4c45a5..7805945a5fd6 100644 --- a/net/ax25/ax25_route.c +++ b/net/ax25/ax25_route.c | |||
@@ -23,6 +23,7 @@ | |||
23 | #include <linux/string.h> | 23 | #include <linux/string.h> |
24 | #include <linux/sockios.h> | 24 | #include <linux/sockios.h> |
25 | #include <linux/net.h> | 25 | #include <linux/net.h> |
26 | #include <linux/slab.h> | ||
26 | #include <net/ax25.h> | 27 | #include <net/ax25.h> |
27 | #include <linux/inet.h> | 28 | #include <linux/inet.h> |
28 | #include <linux/netdevice.h> | 29 | #include <linux/netdevice.h> |
diff --git a/net/ax25/ax25_subr.c b/net/ax25/ax25_subr.c index 034aa10a5198..c6715ee4ab8f 100644 --- a/net/ax25/ax25_subr.c +++ b/net/ax25/ax25_subr.c | |||
@@ -18,6 +18,7 @@ | |||
18 | #include <linux/string.h> | 18 | #include <linux/string.h> |
19 | #include <linux/sockios.h> | 19 | #include <linux/sockios.h> |
20 | #include <linux/net.h> | 20 | #include <linux/net.h> |
21 | #include <linux/slab.h> | ||
21 | #include <net/ax25.h> | 22 | #include <net/ax25.h> |
22 | #include <linux/inet.h> | 23 | #include <linux/inet.h> |
23 | #include <linux/netdevice.h> | 24 | #include <linux/netdevice.h> |
diff --git a/net/ax25/ax25_uid.c b/net/ax25/ax25_uid.c index 9f13f6eefcba..d349be9578f5 100644 --- a/net/ax25/ax25_uid.c +++ b/net/ax25/ax25_uid.c | |||
@@ -18,6 +18,7 @@ | |||
18 | #include <linux/sockios.h> | 18 | #include <linux/sockios.h> |
19 | #include <linux/net.h> | 19 | #include <linux/net.h> |
20 | #include <linux/spinlock.h> | 20 | #include <linux/spinlock.h> |
21 | #include <linux/slab.h> | ||
21 | #include <net/ax25.h> | 22 | #include <net/ax25.h> |
22 | #include <linux/inet.h> | 23 | #include <linux/inet.h> |
23 | #include <linux/netdevice.h> | 24 | #include <linux/netdevice.h> |
diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c index 5159be6b2625..ebe0ef3f1d83 100644 --- a/net/ax25/sysctl_net_ax25.c +++ b/net/ax25/sysctl_net_ax25.c | |||
@@ -7,6 +7,7 @@ | |||
7 | * Copyright (C) 1996 Mike Shaver (shaver@zeroknowledge.com) | 7 | * Copyright (C) 1996 Mike Shaver (shaver@zeroknowledge.com) |
8 | */ | 8 | */ |
9 | #include <linux/mm.h> | 9 | #include <linux/mm.h> |
10 | #include <linux/slab.h> | ||
10 | #include <linux/sysctl.h> | 11 | #include <linux/sysctl.h> |
11 | #include <linux/spinlock.h> | 12 | #include <linux/spinlock.h> |
12 | #include <net/ax25.h> | 13 | #include <net/ax25.h> |
diff --git a/net/bluetooth/af_bluetooth.c b/net/bluetooth/af_bluetooth.c index 087cc51f5927..404a8500fd03 100644 --- a/net/bluetooth/af_bluetooth.c +++ b/net/bluetooth/af_bluetooth.c | |||
@@ -31,7 +31,6 @@ | |||
31 | #include <linux/errno.h> | 31 | #include <linux/errno.h> |
32 | #include <linux/kernel.h> | 32 | #include <linux/kernel.h> |
33 | #include <linux/sched.h> | 33 | #include <linux/sched.h> |
34 | #include <linux/slab.h> | ||
35 | #include <linux/skbuff.h> | 34 | #include <linux/skbuff.h> |
36 | #include <linux/init.h> | 35 | #include <linux/init.h> |
37 | #include <linux/poll.h> | 36 | #include <linux/poll.h> |
diff --git a/net/bluetooth/bnep/core.c b/net/bluetooth/bnep/core.c index ef09c7b3a858..8062dad6d10d 100644 --- a/net/bluetooth/bnep/core.c +++ b/net/bluetooth/bnep/core.c | |||
@@ -35,6 +35,7 @@ | |||
35 | #include <linux/freezer.h> | 35 | #include <linux/freezer.h> |
36 | #include <linux/errno.h> | 36 | #include <linux/errno.h> |
37 | #include <linux/net.h> | 37 | #include <linux/net.h> |
38 | #include <linux/slab.h> | ||
38 | #include <net/sock.h> | 39 | #include <net/sock.h> |
39 | 40 | ||
40 | #include <linux/socket.h> | 41 | #include <linux/socket.h> |
diff --git a/net/bluetooth/bnep/netdev.c b/net/bluetooth/bnep/netdev.c index b6234b73c4cf..d48b33f4d4ba 100644 --- a/net/bluetooth/bnep/netdev.c +++ b/net/bluetooth/bnep/netdev.c | |||
@@ -26,6 +26,7 @@ | |||
26 | */ | 26 | */ |
27 | 27 | ||
28 | #include <linux/module.h> | 28 | #include <linux/module.h> |
29 | #include <linux/slab.h> | ||
29 | 30 | ||
30 | #include <linux/socket.h> | 31 | #include <linux/socket.h> |
31 | #include <linux/netdevice.h> | 32 | #include <linux/netdevice.h> |
@@ -87,7 +88,7 @@ static void bnep_net_set_mc_list(struct net_device *dev) | |||
87 | memcpy(__skb_put(skb, ETH_ALEN), dev->broadcast, ETH_ALEN); | 88 | memcpy(__skb_put(skb, ETH_ALEN), dev->broadcast, ETH_ALEN); |
88 | r->len = htons(ETH_ALEN * 2); | 89 | r->len = htons(ETH_ALEN * 2); |
89 | } else { | 90 | } else { |
90 | struct dev_mc_list *dmi = dev->mc_list; | 91 | struct netdev_hw_addr *ha; |
91 | int i, len = skb->len; | 92 | int i, len = skb->len; |
92 | 93 | ||
93 | if (dev->flags & IFF_BROADCAST) { | 94 | if (dev->flags & IFF_BROADCAST) { |
@@ -97,12 +98,12 @@ static void bnep_net_set_mc_list(struct net_device *dev) | |||
97 | 98 | ||
98 | /* FIXME: We should group addresses here. */ | 99 | /* FIXME: We should group addresses here. */ |
99 | 100 | ||
100 | for (i = 0; | 101 | i = 0; |
101 | i < netdev_mc_count(dev) && i < BNEP_MAX_MULTICAST_FILTERS; | 102 | netdev_for_each_mc_addr(ha, dev) { |
102 | i++) { | 103 | if (i == BNEP_MAX_MULTICAST_FILTERS) |
103 | memcpy(__skb_put(skb, ETH_ALEN), dmi->dmi_addr, ETH_ALEN); | 104 | break; |
104 | memcpy(__skb_put(skb, ETH_ALEN), dmi->dmi_addr, ETH_ALEN); | 105 | memcpy(__skb_put(skb, ETH_ALEN), ha->addr, ETH_ALEN); |
105 | dmi = dmi->next; | 106 | memcpy(__skb_put(skb, ETH_ALEN), ha->addr, ETH_ALEN); |
106 | } | 107 | } |
107 | r->len = htons(skb->len - len); | 108 | r->len = htons(skb->len - len); |
108 | } | 109 | } |
diff --git a/net/bluetooth/bnep/sock.c b/net/bluetooth/bnep/sock.c index 2ff6ac7b2ed4..2862f53b66b1 100644 --- a/net/bluetooth/bnep/sock.c +++ b/net/bluetooth/bnep/sock.c | |||
@@ -30,7 +30,6 @@ | |||
30 | #include <linux/capability.h> | 30 | #include <linux/capability.h> |
31 | #include <linux/errno.h> | 31 | #include <linux/errno.h> |
32 | #include <linux/kernel.h> | 32 | #include <linux/kernel.h> |
33 | #include <linux/slab.h> | ||
34 | #include <linux/poll.h> | 33 | #include <linux/poll.h> |
35 | #include <linux/fcntl.h> | 34 | #include <linux/fcntl.h> |
36 | #include <linux/skbuff.h> | 35 | #include <linux/skbuff.h> |
@@ -39,6 +38,7 @@ | |||
39 | #include <linux/file.h> | 38 | #include <linux/file.h> |
40 | #include <linux/init.h> | 39 | #include <linux/init.h> |
41 | #include <linux/compat.h> | 40 | #include <linux/compat.h> |
41 | #include <linux/gfp.h> | ||
42 | #include <net/sock.h> | 42 | #include <net/sock.h> |
43 | 43 | ||
44 | #include <asm/system.h> | 44 | #include <asm/system.h> |
diff --git a/net/bluetooth/cmtp/sock.c b/net/bluetooth/cmtp/sock.c index 978cc3a718ad..7ea1979a8e4f 100644 --- a/net/bluetooth/cmtp/sock.c +++ b/net/bluetooth/cmtp/sock.c | |||
@@ -26,7 +26,6 @@ | |||
26 | #include <linux/capability.h> | 26 | #include <linux/capability.h> |
27 | #include <linux/errno.h> | 27 | #include <linux/errno.h> |
28 | #include <linux/kernel.h> | 28 | #include <linux/kernel.h> |
29 | #include <linux/slab.h> | ||
30 | #include <linux/poll.h> | 29 | #include <linux/poll.h> |
31 | #include <linux/fcntl.h> | 30 | #include <linux/fcntl.h> |
32 | #include <linux/skbuff.h> | 31 | #include <linux/skbuff.h> |
@@ -34,6 +33,7 @@ | |||
34 | #include <linux/ioctl.h> | 33 | #include <linux/ioctl.h> |
35 | #include <linux/file.h> | 34 | #include <linux/file.h> |
36 | #include <linux/compat.h> | 35 | #include <linux/compat.h> |
36 | #include <linux/gfp.h> | ||
37 | #include <net/sock.h> | 37 | #include <net/sock.h> |
38 | 38 | ||
39 | #include <linux/isdn/capilli.h> | 39 | #include <linux/isdn/capilli.h> |
diff --git a/net/bluetooth/hci_sysfs.c b/net/bluetooth/hci_sysfs.c index cafb55b0cea5..0e8e1a59856c 100644 --- a/net/bluetooth/hci_sysfs.c +++ b/net/bluetooth/hci_sysfs.c | |||
@@ -1,6 +1,7 @@ | |||
1 | /* Bluetooth HCI driver model support. */ | 1 | /* Bluetooth HCI driver model support. */ |
2 | 2 | ||
3 | #include <linux/kernel.h> | 3 | #include <linux/kernel.h> |
4 | #include <linux/slab.h> | ||
4 | #include <linux/init.h> | 5 | #include <linux/init.h> |
5 | #include <linux/debugfs.h> | 6 | #include <linux/debugfs.h> |
6 | #include <linux/seq_file.h> | 7 | #include <linux/seq_file.h> |
@@ -8,8 +9,7 @@ | |||
8 | #include <net/bluetooth/bluetooth.h> | 9 | #include <net/bluetooth/bluetooth.h> |
9 | #include <net/bluetooth/hci_core.h> | 10 | #include <net/bluetooth/hci_core.h> |
10 | 11 | ||
11 | struct class *bt_class = NULL; | 12 | static struct class *bt_class; |
12 | EXPORT_SYMBOL_GPL(bt_class); | ||
13 | 13 | ||
14 | struct dentry *bt_debugfs = NULL; | 14 | struct dentry *bt_debugfs = NULL; |
15 | EXPORT_SYMBOL_GPL(bt_debugfs); | 15 | EXPORT_SYMBOL_GPL(bt_debugfs); |
diff --git a/net/bluetooth/hidp/sock.c b/net/bluetooth/hidp/sock.c index 9cfef68b9fec..250dfd46237d 100644 --- a/net/bluetooth/hidp/sock.c +++ b/net/bluetooth/hidp/sock.c | |||
@@ -26,7 +26,6 @@ | |||
26 | #include <linux/capability.h> | 26 | #include <linux/capability.h> |
27 | #include <linux/errno.h> | 27 | #include <linux/errno.h> |
28 | #include <linux/kernel.h> | 28 | #include <linux/kernel.h> |
29 | #include <linux/slab.h> | ||
30 | #include <linux/poll.h> | 29 | #include <linux/poll.h> |
31 | #include <linux/fcntl.h> | 30 | #include <linux/fcntl.h> |
32 | #include <linux/skbuff.h> | 31 | #include <linux/skbuff.h> |
@@ -35,6 +34,7 @@ | |||
35 | #include <linux/file.h> | 34 | #include <linux/file.h> |
36 | #include <linux/init.h> | 35 | #include <linux/init.h> |
37 | #include <linux/compat.h> | 36 | #include <linux/compat.h> |
37 | #include <linux/gfp.h> | ||
38 | #include <net/sock.h> | 38 | #include <net/sock.h> |
39 | 39 | ||
40 | #include "hidp.h" | 40 | #include "hidp.h" |
diff --git a/net/bluetooth/l2cap.c b/net/bluetooth/l2cap.c index 400efa26ddba..99d68c34e4f1 100644 --- a/net/bluetooth/l2cap.c +++ b/net/bluetooth/l2cap.c | |||
@@ -40,6 +40,8 @@ | |||
40 | #include <linux/skbuff.h> | 40 | #include <linux/skbuff.h> |
41 | #include <linux/list.h> | 41 | #include <linux/list.h> |
42 | #include <linux/device.h> | 42 | #include <linux/device.h> |
43 | #include <linux/debugfs.h> | ||
44 | #include <linux/seq_file.h> | ||
43 | #include <linux/uaccess.h> | 45 | #include <linux/uaccess.h> |
44 | #include <linux/crc16.h> | 46 | #include <linux/crc16.h> |
45 | #include <net/sock.h> | 47 | #include <net/sock.h> |
@@ -1000,7 +1002,8 @@ static int l2cap_sock_connect(struct socket *sock, struct sockaddr *addr, int al | |||
1000 | 1002 | ||
1001 | BT_DBG("sk %p", sk); | 1003 | BT_DBG("sk %p", sk); |
1002 | 1004 | ||
1003 | if (!addr || addr->sa_family != AF_BLUETOOTH) | 1005 | if (!addr || alen < sizeof(addr->sa_family) || |
1006 | addr->sa_family != AF_BLUETOOTH) | ||
1004 | return -EINVAL; | 1007 | return -EINVAL; |
1005 | 1008 | ||
1006 | memset(&la, 0, sizeof(la)); | 1009 | memset(&la, 0, sizeof(la)); |
@@ -2830,6 +2833,11 @@ static inline int l2cap_config_rsp(struct l2cap_conn *conn, struct l2cap_cmd_hdr | |||
2830 | int len = cmd->len - sizeof(*rsp); | 2833 | int len = cmd->len - sizeof(*rsp); |
2831 | char req[64]; | 2834 | char req[64]; |
2832 | 2835 | ||
2836 | if (len > sizeof(req) - sizeof(struct l2cap_conf_req)) { | ||
2837 | l2cap_send_disconn_req(conn, sk); | ||
2838 | goto done; | ||
2839 | } | ||
2840 | |||
2833 | /* throw out any old stored conf requests */ | 2841 | /* throw out any old stored conf requests */ |
2834 | result = L2CAP_CONF_SUCCESS; | 2842 | result = L2CAP_CONF_SUCCESS; |
2835 | len = l2cap_parse_conf_rsp(sk, rsp->data, | 2843 | len = l2cap_parse_conf_rsp(sk, rsp->data, |
@@ -3937,29 +3945,42 @@ drop: | |||
3937 | return 0; | 3945 | return 0; |
3938 | } | 3946 | } |
3939 | 3947 | ||
3940 | static ssize_t l2cap_sysfs_show(struct class *dev, char *buf) | 3948 | static int l2cap_debugfs_show(struct seq_file *f, void *p) |
3941 | { | 3949 | { |
3942 | struct sock *sk; | 3950 | struct sock *sk; |
3943 | struct hlist_node *node; | 3951 | struct hlist_node *node; |
3944 | char *str = buf; | ||
3945 | 3952 | ||
3946 | read_lock_bh(&l2cap_sk_list.lock); | 3953 | read_lock_bh(&l2cap_sk_list.lock); |
3947 | 3954 | ||
3948 | sk_for_each(sk, node, &l2cap_sk_list.head) { | 3955 | sk_for_each(sk, node, &l2cap_sk_list.head) { |
3949 | struct l2cap_pinfo *pi = l2cap_pi(sk); | 3956 | struct l2cap_pinfo *pi = l2cap_pi(sk); |
3950 | 3957 | ||
3951 | str += sprintf(str, "%s %s %d %d 0x%4.4x 0x%4.4x %d %d %d\n", | 3958 | seq_printf(f, "%s %s %d %d 0x%4.4x 0x%4.4x %d %d %d\n", |
3952 | batostr(&bt_sk(sk)->src), batostr(&bt_sk(sk)->dst), | 3959 | batostr(&bt_sk(sk)->src), |
3953 | sk->sk_state, __le16_to_cpu(pi->psm), pi->scid, | 3960 | batostr(&bt_sk(sk)->dst), |
3954 | pi->dcid, pi->imtu, pi->omtu, pi->sec_level); | 3961 | sk->sk_state, __le16_to_cpu(pi->psm), |
3962 | pi->scid, pi->dcid, | ||
3963 | pi->imtu, pi->omtu, pi->sec_level); | ||
3955 | } | 3964 | } |
3956 | 3965 | ||
3957 | read_unlock_bh(&l2cap_sk_list.lock); | 3966 | read_unlock_bh(&l2cap_sk_list.lock); |
3958 | 3967 | ||
3959 | return str - buf; | 3968 | return 0; |
3969 | } | ||
3970 | |||
3971 | static int l2cap_debugfs_open(struct inode *inode, struct file *file) | ||
3972 | { | ||
3973 | return single_open(file, l2cap_debugfs_show, inode->i_private); | ||
3960 | } | 3974 | } |
3961 | 3975 | ||
3962 | static CLASS_ATTR(l2cap, S_IRUGO, l2cap_sysfs_show, NULL); | 3976 | static const struct file_operations l2cap_debugfs_fops = { |
3977 | .open = l2cap_debugfs_open, | ||
3978 | .read = seq_read, | ||
3979 | .llseek = seq_lseek, | ||
3980 | .release = single_release, | ||
3981 | }; | ||
3982 | |||
3983 | static struct dentry *l2cap_debugfs; | ||
3963 | 3984 | ||
3964 | static const struct proto_ops l2cap_sock_ops = { | 3985 | static const struct proto_ops l2cap_sock_ops = { |
3965 | .family = PF_BLUETOOTH, | 3986 | .family = PF_BLUETOOTH, |
@@ -4019,8 +4040,12 @@ static int __init l2cap_init(void) | |||
4019 | goto error; | 4040 | goto error; |
4020 | } | 4041 | } |
4021 | 4042 | ||
4022 | if (class_create_file(bt_class, &class_attr_l2cap) < 0) | 4043 | if (bt_debugfs) { |
4023 | BT_ERR("Failed to create L2CAP info file"); | 4044 | l2cap_debugfs = debugfs_create_file("l2cap", 0444, |
4045 | bt_debugfs, NULL, &l2cap_debugfs_fops); | ||
4046 | if (!l2cap_debugfs) | ||
4047 | BT_ERR("Failed to create L2CAP debug file"); | ||
4048 | } | ||
4024 | 4049 | ||
4025 | BT_INFO("L2CAP ver %s", VERSION); | 4050 | BT_INFO("L2CAP ver %s", VERSION); |
4026 | BT_INFO("L2CAP socket layer initialized"); | 4051 | BT_INFO("L2CAP socket layer initialized"); |
@@ -4034,7 +4059,7 @@ error: | |||
4034 | 4059 | ||
4035 | static void __exit l2cap_exit(void) | 4060 | static void __exit l2cap_exit(void) |
4036 | { | 4061 | { |
4037 | class_remove_file(bt_class, &class_attr_l2cap); | 4062 | debugfs_remove(l2cap_debugfs); |
4038 | 4063 | ||
4039 | if (bt_sock_unregister(BTPROTO_L2CAP) < 0) | 4064 | if (bt_sock_unregister(BTPROTO_L2CAP) < 0) |
4040 | BT_ERR("L2CAP socket unregistration failed"); | 4065 | BT_ERR("L2CAP socket unregistration failed"); |
diff --git a/net/bluetooth/rfcomm/core.c b/net/bluetooth/rfcomm/core.c index 89f4a59eb82b..7dca91bb8c57 100644 --- a/net/bluetooth/rfcomm/core.c +++ b/net/bluetooth/rfcomm/core.c | |||
@@ -33,9 +33,12 @@ | |||
33 | #include <linux/init.h> | 33 | #include <linux/init.h> |
34 | #include <linux/wait.h> | 34 | #include <linux/wait.h> |
35 | #include <linux/device.h> | 35 | #include <linux/device.h> |
36 | #include <linux/debugfs.h> | ||
37 | #include <linux/seq_file.h> | ||
36 | #include <linux/net.h> | 38 | #include <linux/net.h> |
37 | #include <linux/mutex.h> | 39 | #include <linux/mutex.h> |
38 | #include <linux/kthread.h> | 40 | #include <linux/kthread.h> |
41 | #include <linux/slab.h> | ||
39 | 42 | ||
40 | #include <net/sock.h> | 43 | #include <net/sock.h> |
41 | #include <asm/uaccess.h> | 44 | #include <asm/uaccess.h> |
@@ -2098,11 +2101,10 @@ static struct hci_cb rfcomm_cb = { | |||
2098 | .security_cfm = rfcomm_security_cfm | 2101 | .security_cfm = rfcomm_security_cfm |
2099 | }; | 2102 | }; |
2100 | 2103 | ||
2101 | static ssize_t rfcomm_dlc_sysfs_show(struct class *dev, char *buf) | 2104 | static int rfcomm_dlc_debugfs_show(struct seq_file *f, void *x) |
2102 | { | 2105 | { |
2103 | struct rfcomm_session *s; | 2106 | struct rfcomm_session *s; |
2104 | struct list_head *pp, *p; | 2107 | struct list_head *pp, *p; |
2105 | char *str = buf; | ||
2106 | 2108 | ||
2107 | rfcomm_lock(); | 2109 | rfcomm_lock(); |
2108 | 2110 | ||
@@ -2112,18 +2114,32 @@ static ssize_t rfcomm_dlc_sysfs_show(struct class *dev, char *buf) | |||
2112 | struct sock *sk = s->sock->sk; | 2114 | struct sock *sk = s->sock->sk; |
2113 | struct rfcomm_dlc *d = list_entry(pp, struct rfcomm_dlc, list); | 2115 | struct rfcomm_dlc *d = list_entry(pp, struct rfcomm_dlc, list); |
2114 | 2116 | ||
2115 | str += sprintf(str, "%s %s %ld %d %d %d %d\n", | 2117 | seq_printf(f, "%s %s %ld %d %d %d %d\n", |
2116 | batostr(&bt_sk(sk)->src), batostr(&bt_sk(sk)->dst), | 2118 | batostr(&bt_sk(sk)->src), |
2117 | d->state, d->dlci, d->mtu, d->rx_credits, d->tx_credits); | 2119 | batostr(&bt_sk(sk)->dst), |
2120 | d->state, d->dlci, d->mtu, | ||
2121 | d->rx_credits, d->tx_credits); | ||
2118 | } | 2122 | } |
2119 | } | 2123 | } |
2120 | 2124 | ||
2121 | rfcomm_unlock(); | 2125 | rfcomm_unlock(); |
2122 | 2126 | ||
2123 | return (str - buf); | 2127 | return 0; |
2124 | } | 2128 | } |
2125 | 2129 | ||
2126 | static CLASS_ATTR(rfcomm_dlc, S_IRUGO, rfcomm_dlc_sysfs_show, NULL); | 2130 | static int rfcomm_dlc_debugfs_open(struct inode *inode, struct file *file) |
2131 | { | ||
2132 | return single_open(file, rfcomm_dlc_debugfs_show, inode->i_private); | ||
2133 | } | ||
2134 | |||
2135 | static const struct file_operations rfcomm_dlc_debugfs_fops = { | ||
2136 | .open = rfcomm_dlc_debugfs_open, | ||
2137 | .read = seq_read, | ||
2138 | .llseek = seq_lseek, | ||
2139 | .release = single_release, | ||
2140 | }; | ||
2141 | |||
2142 | static struct dentry *rfcomm_dlc_debugfs; | ||
2127 | 2143 | ||
2128 | /* ---- Initialization ---- */ | 2144 | /* ---- Initialization ---- */ |
2129 | static int __init rfcomm_init(void) | 2145 | static int __init rfcomm_init(void) |
@@ -2140,8 +2156,12 @@ static int __init rfcomm_init(void) | |||
2140 | goto unregister; | 2156 | goto unregister; |
2141 | } | 2157 | } |
2142 | 2158 | ||
2143 | if (class_create_file(bt_class, &class_attr_rfcomm_dlc) < 0) | 2159 | if (bt_debugfs) { |
2144 | BT_ERR("Failed to create RFCOMM info file"); | 2160 | rfcomm_dlc_debugfs = debugfs_create_file("rfcomm_dlc", 0444, |
2161 | bt_debugfs, NULL, &rfcomm_dlc_debugfs_fops); | ||
2162 | if (!rfcomm_dlc_debugfs) | ||
2163 | BT_ERR("Failed to create RFCOMM debug file"); | ||
2164 | } | ||
2145 | 2165 | ||
2146 | err = rfcomm_init_ttys(); | 2166 | err = rfcomm_init_ttys(); |
2147 | if (err < 0) | 2167 | if (err < 0) |
@@ -2169,7 +2189,7 @@ unregister: | |||
2169 | 2189 | ||
2170 | static void __exit rfcomm_exit(void) | 2190 | static void __exit rfcomm_exit(void) |
2171 | { | 2191 | { |
2172 | class_remove_file(bt_class, &class_attr_rfcomm_dlc); | 2192 | debugfs_remove(rfcomm_dlc_debugfs); |
2173 | 2193 | ||
2174 | hci_unregister_cb(&rfcomm_cb); | 2194 | hci_unregister_cb(&rfcomm_cb); |
2175 | 2195 | ||
diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c index 4b5968dda673..8ed3c37684fa 100644 --- a/net/bluetooth/rfcomm/sock.c +++ b/net/bluetooth/rfcomm/sock.c | |||
@@ -40,6 +40,8 @@ | |||
40 | #include <linux/skbuff.h> | 40 | #include <linux/skbuff.h> |
41 | #include <linux/list.h> | 41 | #include <linux/list.h> |
42 | #include <linux/device.h> | 42 | #include <linux/device.h> |
43 | #include <linux/debugfs.h> | ||
44 | #include <linux/seq_file.h> | ||
43 | #include <net/sock.h> | 45 | #include <net/sock.h> |
44 | 46 | ||
45 | #include <asm/system.h> | 47 | #include <asm/system.h> |
@@ -395,7 +397,8 @@ static int rfcomm_sock_connect(struct socket *sock, struct sockaddr *addr, int a | |||
395 | 397 | ||
396 | BT_DBG("sk %p", sk); | 398 | BT_DBG("sk %p", sk); |
397 | 399 | ||
398 | if (addr->sa_family != AF_BLUETOOTH || alen < sizeof(struct sockaddr_rc)) | 400 | if (alen < sizeof(struct sockaddr_rc) || |
401 | addr->sa_family != AF_BLUETOOTH) | ||
399 | return -EINVAL; | 402 | return -EINVAL; |
400 | 403 | ||
401 | lock_sock(sk); | 404 | lock_sock(sk); |
@@ -1061,26 +1064,38 @@ done: | |||
1061 | return result; | 1064 | return result; |
1062 | } | 1065 | } |
1063 | 1066 | ||
1064 | static ssize_t rfcomm_sock_sysfs_show(struct class *dev, char *buf) | 1067 | static int rfcomm_sock_debugfs_show(struct seq_file *f, void *p) |
1065 | { | 1068 | { |
1066 | struct sock *sk; | 1069 | struct sock *sk; |
1067 | struct hlist_node *node; | 1070 | struct hlist_node *node; |
1068 | char *str = buf; | ||
1069 | 1071 | ||
1070 | read_lock_bh(&rfcomm_sk_list.lock); | 1072 | read_lock_bh(&rfcomm_sk_list.lock); |
1071 | 1073 | ||
1072 | sk_for_each(sk, node, &rfcomm_sk_list.head) { | 1074 | sk_for_each(sk, node, &rfcomm_sk_list.head) { |
1073 | str += sprintf(str, "%s %s %d %d\n", | 1075 | seq_printf(f, "%s %s %d %d\n", |
1074 | batostr(&bt_sk(sk)->src), batostr(&bt_sk(sk)->dst), | 1076 | batostr(&bt_sk(sk)->src), |
1077 | batostr(&bt_sk(sk)->dst), | ||
1075 | sk->sk_state, rfcomm_pi(sk)->channel); | 1078 | sk->sk_state, rfcomm_pi(sk)->channel); |
1076 | } | 1079 | } |
1077 | 1080 | ||
1078 | read_unlock_bh(&rfcomm_sk_list.lock); | 1081 | read_unlock_bh(&rfcomm_sk_list.lock); |
1079 | 1082 | ||
1080 | return (str - buf); | 1083 | return 0; |
1081 | } | 1084 | } |
1082 | 1085 | ||
1083 | static CLASS_ATTR(rfcomm, S_IRUGO, rfcomm_sock_sysfs_show, NULL); | 1086 | static int rfcomm_sock_debugfs_open(struct inode *inode, struct file *file) |
1087 | { | ||
1088 | return single_open(file, rfcomm_sock_debugfs_show, inode->i_private); | ||
1089 | } | ||
1090 | |||
1091 | static const struct file_operations rfcomm_sock_debugfs_fops = { | ||
1092 | .open = rfcomm_sock_debugfs_open, | ||
1093 | .read = seq_read, | ||
1094 | .llseek = seq_lseek, | ||
1095 | .release = single_release, | ||
1096 | }; | ||
1097 | |||
1098 | static struct dentry *rfcomm_sock_debugfs; | ||
1084 | 1099 | ||
1085 | static const struct proto_ops rfcomm_sock_ops = { | 1100 | static const struct proto_ops rfcomm_sock_ops = { |
1086 | .family = PF_BLUETOOTH, | 1101 | .family = PF_BLUETOOTH, |
@@ -1120,8 +1135,12 @@ int __init rfcomm_init_sockets(void) | |||
1120 | if (err < 0) | 1135 | if (err < 0) |
1121 | goto error; | 1136 | goto error; |
1122 | 1137 | ||
1123 | if (class_create_file(bt_class, &class_attr_rfcomm) < 0) | 1138 | if (bt_debugfs) { |
1124 | BT_ERR("Failed to create RFCOMM info file"); | 1139 | rfcomm_sock_debugfs = debugfs_create_file("rfcomm", 0444, |
1140 | bt_debugfs, NULL, &rfcomm_sock_debugfs_fops); | ||
1141 | if (!rfcomm_sock_debugfs) | ||
1142 | BT_ERR("Failed to create RFCOMM debug file"); | ||
1143 | } | ||
1125 | 1144 | ||
1126 | BT_INFO("RFCOMM socket layer initialized"); | 1145 | BT_INFO("RFCOMM socket layer initialized"); |
1127 | 1146 | ||
@@ -1135,7 +1154,7 @@ error: | |||
1135 | 1154 | ||
1136 | void rfcomm_cleanup_sockets(void) | 1155 | void rfcomm_cleanup_sockets(void) |
1137 | { | 1156 | { |
1138 | class_remove_file(bt_class, &class_attr_rfcomm); | 1157 | debugfs_remove(rfcomm_sock_debugfs); |
1139 | 1158 | ||
1140 | if (bt_sock_unregister(BTPROTO_RFCOMM) < 0) | 1159 | if (bt_sock_unregister(BTPROTO_RFCOMM) < 0) |
1141 | BT_ERR("RFCOMM socket layer unregistration failed"); | 1160 | BT_ERR("RFCOMM socket layer unregistration failed"); |
diff --git a/net/bluetooth/sco.c b/net/bluetooth/sco.c index dd8f6ec57dce..ca6b2ad1c3fc 100644 --- a/net/bluetooth/sco.c +++ b/net/bluetooth/sco.c | |||
@@ -38,6 +38,8 @@ | |||
38 | #include <linux/socket.h> | 38 | #include <linux/socket.h> |
39 | #include <linux/skbuff.h> | 39 | #include <linux/skbuff.h> |
40 | #include <linux/device.h> | 40 | #include <linux/device.h> |
41 | #include <linux/debugfs.h> | ||
42 | #include <linux/seq_file.h> | ||
41 | #include <linux/list.h> | 43 | #include <linux/list.h> |
42 | #include <net/sock.h> | 44 | #include <net/sock.h> |
43 | 45 | ||
@@ -497,7 +499,8 @@ static int sco_sock_connect(struct socket *sock, struct sockaddr *addr, int alen | |||
497 | 499 | ||
498 | BT_DBG("sk %p", sk); | 500 | BT_DBG("sk %p", sk); |
499 | 501 | ||
500 | if (addr->sa_family != AF_BLUETOOTH || alen < sizeof(struct sockaddr_sco)) | 502 | if (alen < sizeof(struct sockaddr_sco) || |
503 | addr->sa_family != AF_BLUETOOTH) | ||
501 | return -EINVAL; | 504 | return -EINVAL; |
502 | 505 | ||
503 | if (sk->sk_state != BT_OPEN && sk->sk_state != BT_BOUND) | 506 | if (sk->sk_state != BT_OPEN && sk->sk_state != BT_BOUND) |
@@ -953,26 +956,36 @@ drop: | |||
953 | return 0; | 956 | return 0; |
954 | } | 957 | } |
955 | 958 | ||
956 | static ssize_t sco_sysfs_show(struct class *dev, char *buf) | 959 | static int sco_debugfs_show(struct seq_file *f, void *p) |
957 | { | 960 | { |
958 | struct sock *sk; | 961 | struct sock *sk; |
959 | struct hlist_node *node; | 962 | struct hlist_node *node; |
960 | char *str = buf; | ||
961 | 963 | ||
962 | read_lock_bh(&sco_sk_list.lock); | 964 | read_lock_bh(&sco_sk_list.lock); |
963 | 965 | ||
964 | sk_for_each(sk, node, &sco_sk_list.head) { | 966 | sk_for_each(sk, node, &sco_sk_list.head) { |
965 | str += sprintf(str, "%s %s %d\n", | 967 | seq_printf(f, "%s %s %d\n", batostr(&bt_sk(sk)->src), |
966 | batostr(&bt_sk(sk)->src), batostr(&bt_sk(sk)->dst), | 968 | batostr(&bt_sk(sk)->dst), sk->sk_state); |
967 | sk->sk_state); | ||
968 | } | 969 | } |
969 | 970 | ||
970 | read_unlock_bh(&sco_sk_list.lock); | 971 | read_unlock_bh(&sco_sk_list.lock); |
971 | 972 | ||
972 | return (str - buf); | 973 | return 0; |
973 | } | 974 | } |
974 | 975 | ||
975 | static CLASS_ATTR(sco, S_IRUGO, sco_sysfs_show, NULL); | 976 | static int sco_debugfs_open(struct inode *inode, struct file *file) |
977 | { | ||
978 | return single_open(file, sco_debugfs_show, inode->i_private); | ||
979 | } | ||
980 | |||
981 | static const struct file_operations sco_debugfs_fops = { | ||
982 | .open = sco_debugfs_open, | ||
983 | .read = seq_read, | ||
984 | .llseek = seq_lseek, | ||
985 | .release = single_release, | ||
986 | }; | ||
987 | |||
988 | static struct dentry *sco_debugfs; | ||
976 | 989 | ||
977 | static const struct proto_ops sco_sock_ops = { | 990 | static const struct proto_ops sco_sock_ops = { |
978 | .family = PF_BLUETOOTH, | 991 | .family = PF_BLUETOOTH, |
@@ -1030,8 +1043,12 @@ static int __init sco_init(void) | |||
1030 | goto error; | 1043 | goto error; |
1031 | } | 1044 | } |
1032 | 1045 | ||
1033 | if (class_create_file(bt_class, &class_attr_sco) < 0) | 1046 | if (bt_debugfs) { |
1034 | BT_ERR("Failed to create SCO info file"); | 1047 | sco_debugfs = debugfs_create_file("sco", 0444, |
1048 | bt_debugfs, NULL, &sco_debugfs_fops); | ||
1049 | if (!sco_debugfs) | ||
1050 | BT_ERR("Failed to create SCO debug file"); | ||
1051 | } | ||
1035 | 1052 | ||
1036 | BT_INFO("SCO (Voice Link) ver %s", VERSION); | 1053 | BT_INFO("SCO (Voice Link) ver %s", VERSION); |
1037 | BT_INFO("SCO socket layer initialized"); | 1054 | BT_INFO("SCO socket layer initialized"); |
@@ -1045,7 +1062,7 @@ error: | |||
1045 | 1062 | ||
1046 | static void __exit sco_exit(void) | 1063 | static void __exit sco_exit(void) |
1047 | { | 1064 | { |
1048 | class_remove_file(bt_class, &class_attr_sco); | 1065 | debugfs_remove(sco_debugfs); |
1049 | 1066 | ||
1050 | if (bt_sock_unregister(BTPROTO_SCO) < 0) | 1067 | if (bt_sock_unregister(BTPROTO_SCO) < 0) |
1051 | BT_ERR("SCO socket unregistration failed"); | 1068 | BT_ERR("SCO socket unregistration failed"); |
diff --git a/net/bridge/br_device.c b/net/bridge/br_device.c index eb7062d2e9e5..5b8a6e73b02f 100644 --- a/net/bridge/br_device.c +++ b/net/bridge/br_device.c | |||
@@ -26,11 +26,12 @@ netdev_tx_t br_dev_xmit(struct sk_buff *skb, struct net_device *dev) | |||
26 | const unsigned char *dest = skb->data; | 26 | const unsigned char *dest = skb->data; |
27 | struct net_bridge_fdb_entry *dst; | 27 | struct net_bridge_fdb_entry *dst; |
28 | struct net_bridge_mdb_entry *mdst; | 28 | struct net_bridge_mdb_entry *mdst; |
29 | struct br_cpu_netstats *brstats = this_cpu_ptr(br->stats); | ||
29 | 30 | ||
30 | BR_INPUT_SKB_CB(skb)->brdev = dev; | 31 | brstats->tx_packets++; |
32 | brstats->tx_bytes += skb->len; | ||
31 | 33 | ||
32 | dev->stats.tx_packets++; | 34 | BR_INPUT_SKB_CB(skb)->brdev = dev; |
33 | dev->stats.tx_bytes += skb->len; | ||
34 | 35 | ||
35 | skb_reset_mac_header(skb); | 36 | skb_reset_mac_header(skb); |
36 | skb_pull(skb, ETH_HLEN); | 37 | skb_pull(skb, ETH_HLEN); |
@@ -40,7 +41,7 @@ netdev_tx_t br_dev_xmit(struct sk_buff *skb, struct net_device *dev) | |||
40 | goto out; | 41 | goto out; |
41 | 42 | ||
42 | mdst = br_mdb_get(br, skb); | 43 | mdst = br_mdb_get(br, skb); |
43 | if (mdst || BR_INPUT_SKB_CB(skb)->mrouters_only) | 44 | if (mdst || BR_INPUT_SKB_CB_MROUTERS_ONLY(skb)) |
44 | br_multicast_deliver(mdst, skb); | 45 | br_multicast_deliver(mdst, skb); |
45 | else | 46 | else |
46 | br_flood_deliver(br, skb); | 47 | br_flood_deliver(br, skb); |
@@ -81,6 +82,31 @@ static int br_dev_stop(struct net_device *dev) | |||
81 | return 0; | 82 | return 0; |
82 | } | 83 | } |
83 | 84 | ||
85 | static struct net_device_stats *br_get_stats(struct net_device *dev) | ||
86 | { | ||
87 | struct net_bridge *br = netdev_priv(dev); | ||
88 | struct net_device_stats *stats = &dev->stats; | ||
89 | struct br_cpu_netstats sum = { 0 }; | ||
90 | unsigned int cpu; | ||
91 | |||
92 | for_each_possible_cpu(cpu) { | ||
93 | const struct br_cpu_netstats *bstats | ||
94 | = per_cpu_ptr(br->stats, cpu); | ||
95 | |||
96 | sum.tx_bytes += bstats->tx_bytes; | ||
97 | sum.tx_packets += bstats->tx_packets; | ||
98 | sum.rx_bytes += bstats->rx_bytes; | ||
99 | sum.rx_packets += bstats->rx_packets; | ||
100 | } | ||
101 | |||
102 | stats->tx_bytes = sum.tx_bytes; | ||
103 | stats->tx_packets = sum.tx_packets; | ||
104 | stats->rx_bytes = sum.rx_bytes; | ||
105 | stats->rx_packets = sum.rx_packets; | ||
106 | |||
107 | return stats; | ||
108 | } | ||
109 | |||
84 | static int br_change_mtu(struct net_device *dev, int new_mtu) | 110 | static int br_change_mtu(struct net_device *dev, int new_mtu) |
85 | { | 111 | { |
86 | struct net_bridge *br = netdev_priv(dev); | 112 | struct net_bridge *br = netdev_priv(dev); |
@@ -180,19 +206,28 @@ static const struct net_device_ops br_netdev_ops = { | |||
180 | .ndo_open = br_dev_open, | 206 | .ndo_open = br_dev_open, |
181 | .ndo_stop = br_dev_stop, | 207 | .ndo_stop = br_dev_stop, |
182 | .ndo_start_xmit = br_dev_xmit, | 208 | .ndo_start_xmit = br_dev_xmit, |
209 | .ndo_get_stats = br_get_stats, | ||
183 | .ndo_set_mac_address = br_set_mac_address, | 210 | .ndo_set_mac_address = br_set_mac_address, |
184 | .ndo_set_multicast_list = br_dev_set_multicast_list, | 211 | .ndo_set_multicast_list = br_dev_set_multicast_list, |
185 | .ndo_change_mtu = br_change_mtu, | 212 | .ndo_change_mtu = br_change_mtu, |
186 | .ndo_do_ioctl = br_dev_ioctl, | 213 | .ndo_do_ioctl = br_dev_ioctl, |
187 | }; | 214 | }; |
188 | 215 | ||
216 | static void br_dev_free(struct net_device *dev) | ||
217 | { | ||
218 | struct net_bridge *br = netdev_priv(dev); | ||
219 | |||
220 | free_percpu(br->stats); | ||
221 | free_netdev(dev); | ||
222 | } | ||
223 | |||
189 | void br_dev_setup(struct net_device *dev) | 224 | void br_dev_setup(struct net_device *dev) |
190 | { | 225 | { |
191 | random_ether_addr(dev->dev_addr); | 226 | random_ether_addr(dev->dev_addr); |
192 | ether_setup(dev); | 227 | ether_setup(dev); |
193 | 228 | ||
194 | dev->netdev_ops = &br_netdev_ops; | 229 | dev->netdev_ops = &br_netdev_ops; |
195 | dev->destructor = free_netdev; | 230 | dev->destructor = br_dev_free; |
196 | SET_ETHTOOL_OPS(dev, &br_ethtool_ops); | 231 | SET_ETHTOOL_OPS(dev, &br_ethtool_ops); |
197 | dev->tx_queue_len = 0; | 232 | dev->tx_queue_len = 0; |
198 | dev->priv_flags = IFF_EBRIDGE; | 233 | dev->priv_flags = IFF_EBRIDGE; |
diff --git a/net/bridge/br_fdb.c b/net/bridge/br_fdb.c index 3b8e038ab32c..9101a4e56201 100644 --- a/net/bridge/br_fdb.c +++ b/net/bridge/br_fdb.c | |||
@@ -20,6 +20,7 @@ | |||
20 | #include <linux/etherdevice.h> | 20 | #include <linux/etherdevice.h> |
21 | #include <linux/jhash.h> | 21 | #include <linux/jhash.h> |
22 | #include <linux/random.h> | 22 | #include <linux/random.h> |
23 | #include <linux/slab.h> | ||
23 | #include <asm/atomic.h> | 24 | #include <asm/atomic.h> |
24 | #include <asm/unaligned.h> | 25 | #include <asm/unaligned.h> |
25 | #include "br_private.h" | 26 | #include "br_private.h" |
diff --git a/net/bridge/br_forward.c b/net/bridge/br_forward.c index d61e6f741125..7a241c396981 100644 --- a/net/bridge/br_forward.c +++ b/net/bridge/br_forward.c | |||
@@ -12,6 +12,7 @@ | |||
12 | */ | 12 | */ |
13 | 13 | ||
14 | #include <linux/err.h> | 14 | #include <linux/err.h> |
15 | #include <linux/slab.h> | ||
15 | #include <linux/kernel.h> | 16 | #include <linux/kernel.h> |
16 | #include <linux/netdevice.h> | 17 | #include <linux/netdevice.h> |
17 | #include <linux/skbuff.h> | 18 | #include <linux/skbuff.h> |
@@ -19,6 +20,11 @@ | |||
19 | #include <linux/netfilter_bridge.h> | 20 | #include <linux/netfilter_bridge.h> |
20 | #include "br_private.h" | 21 | #include "br_private.h" |
21 | 22 | ||
23 | static int deliver_clone(const struct net_bridge_port *prev, | ||
24 | struct sk_buff *skb, | ||
25 | void (*__packet_hook)(const struct net_bridge_port *p, | ||
26 | struct sk_buff *skb)); | ||
27 | |||
22 | /* Don't forward packets to originating port or forwarding diasabled */ | 28 | /* Don't forward packets to originating port or forwarding diasabled */ |
23 | static inline int should_deliver(const struct net_bridge_port *p, | 29 | static inline int should_deliver(const struct net_bridge_port *p, |
24 | const struct sk_buff *skb) | 30 | const struct sk_buff *skb) |
@@ -94,17 +100,22 @@ void br_deliver(const struct net_bridge_port *to, struct sk_buff *skb) | |||
94 | } | 100 | } |
95 | 101 | ||
96 | /* called with rcu_read_lock */ | 102 | /* called with rcu_read_lock */ |
97 | void br_forward(const struct net_bridge_port *to, struct sk_buff *skb) | 103 | void br_forward(const struct net_bridge_port *to, struct sk_buff *skb, struct sk_buff *skb0) |
98 | { | 104 | { |
99 | if (should_deliver(to, skb)) { | 105 | if (should_deliver(to, skb)) { |
100 | __br_forward(to, skb); | 106 | if (skb0) |
107 | deliver_clone(to, skb, __br_forward); | ||
108 | else | ||
109 | __br_forward(to, skb); | ||
101 | return; | 110 | return; |
102 | } | 111 | } |
103 | 112 | ||
104 | kfree_skb(skb); | 113 | if (!skb0) |
114 | kfree_skb(skb); | ||
105 | } | 115 | } |
106 | 116 | ||
107 | static int deliver_clone(struct net_bridge_port *prev, struct sk_buff *skb, | 117 | static int deliver_clone(const struct net_bridge_port *prev, |
118 | struct sk_buff *skb, | ||
108 | void (*__packet_hook)(const struct net_bridge_port *p, | 119 | void (*__packet_hook)(const struct net_bridge_port *p, |
109 | struct sk_buff *skb)) | 120 | struct sk_buff *skb)) |
110 | { | 121 | { |
diff --git a/net/bridge/br_if.c b/net/bridge/br_if.c index b6a3872f5681..521439333316 100644 --- a/net/bridge/br_if.c +++ b/net/bridge/br_if.c | |||
@@ -19,6 +19,7 @@ | |||
19 | #include <linux/init.h> | 19 | #include <linux/init.h> |
20 | #include <linux/rtnetlink.h> | 20 | #include <linux/rtnetlink.h> |
21 | #include <linux/if_ether.h> | 21 | #include <linux/if_ether.h> |
22 | #include <linux/slab.h> | ||
22 | #include <net/sock.h> | 23 | #include <net/sock.h> |
23 | 24 | ||
24 | #include "br_private.h" | 25 | #include "br_private.h" |
@@ -185,6 +186,12 @@ static struct net_device *new_bridge_dev(struct net *net, const char *name) | |||
185 | br = netdev_priv(dev); | 186 | br = netdev_priv(dev); |
186 | br->dev = dev; | 187 | br->dev = dev; |
187 | 188 | ||
189 | br->stats = alloc_percpu(struct br_cpu_netstats); | ||
190 | if (!br->stats) { | ||
191 | free_netdev(dev); | ||
192 | return NULL; | ||
193 | } | ||
194 | |||
188 | spin_lock_init(&br->lock); | 195 | spin_lock_init(&br->lock); |
189 | INIT_LIST_HEAD(&br->port_list); | 196 | INIT_LIST_HEAD(&br->port_list); |
190 | spin_lock_init(&br->hash_lock); | 197 | spin_lock_init(&br->hash_lock); |
diff --git a/net/bridge/br_input.c b/net/bridge/br_input.c index 53b39851d87d..e7f4c1d02f57 100644 --- a/net/bridge/br_input.c +++ b/net/bridge/br_input.c | |||
@@ -11,6 +11,7 @@ | |||
11 | * 2 of the License, or (at your option) any later version. | 11 | * 2 of the License, or (at your option) any later version. |
12 | */ | 12 | */ |
13 | 13 | ||
14 | #include <linux/slab.h> | ||
14 | #include <linux/kernel.h> | 15 | #include <linux/kernel.h> |
15 | #include <linux/netdevice.h> | 16 | #include <linux/netdevice.h> |
16 | #include <linux/etherdevice.h> | 17 | #include <linux/etherdevice.h> |
@@ -23,9 +24,11 @@ const u8 br_group_address[ETH_ALEN] = { 0x01, 0x80, 0xc2, 0x00, 0x00, 0x00 }; | |||
23 | static int br_pass_frame_up(struct sk_buff *skb) | 24 | static int br_pass_frame_up(struct sk_buff *skb) |
24 | { | 25 | { |
25 | struct net_device *indev, *brdev = BR_INPUT_SKB_CB(skb)->brdev; | 26 | struct net_device *indev, *brdev = BR_INPUT_SKB_CB(skb)->brdev; |
27 | struct net_bridge *br = netdev_priv(brdev); | ||
28 | struct br_cpu_netstats *brstats = this_cpu_ptr(br->stats); | ||
26 | 29 | ||
27 | brdev->stats.rx_packets++; | 30 | brstats->rx_packets++; |
28 | brdev->stats.rx_bytes += skb->len; | 31 | brstats->rx_bytes += skb->len; |
29 | 32 | ||
30 | indev = skb->dev; | 33 | indev = skb->dev; |
31 | skb->dev = brdev; | 34 | skb->dev = brdev; |
@@ -70,7 +73,7 @@ int br_handle_frame_finish(struct sk_buff *skb) | |||
70 | 73 | ||
71 | if (is_multicast_ether_addr(dest)) { | 74 | if (is_multicast_ether_addr(dest)) { |
72 | mdst = br_mdb_get(br, skb); | 75 | mdst = br_mdb_get(br, skb); |
73 | if (mdst || BR_INPUT_SKB_CB(skb)->mrouters_only) { | 76 | if (mdst || BR_INPUT_SKB_CB_MROUTERS_ONLY(skb)) { |
74 | if ((mdst && !hlist_unhashed(&mdst->mglist)) || | 77 | if ((mdst && !hlist_unhashed(&mdst->mglist)) || |
75 | br_multicast_is_router(br)) | 78 | br_multicast_is_router(br)) |
76 | skb2 = skb; | 79 | skb2 = skb; |
@@ -90,7 +93,7 @@ int br_handle_frame_finish(struct sk_buff *skb) | |||
90 | 93 | ||
91 | if (skb) { | 94 | if (skb) { |
92 | if (dst) | 95 | if (dst) |
93 | br_forward(dst->dst, skb); | 96 | br_forward(dst->dst, skb, skb2); |
94 | else | 97 | else |
95 | br_flood_forward(br, skb, skb2); | 98 | br_flood_forward(br, skb, skb2); |
96 | } | 99 | } |
diff --git a/net/bridge/br_ioctl.c b/net/bridge/br_ioctl.c index 2af6e4a90262..995afc4b04dc 100644 --- a/net/bridge/br_ioctl.c +++ b/net/bridge/br_ioctl.c | |||
@@ -15,6 +15,7 @@ | |||
15 | #include <linux/kernel.h> | 15 | #include <linux/kernel.h> |
16 | #include <linux/if_bridge.h> | 16 | #include <linux/if_bridge.h> |
17 | #include <linux/netdevice.h> | 17 | #include <linux/netdevice.h> |
18 | #include <linux/slab.h> | ||
18 | #include <linux/times.h> | 19 | #include <linux/times.h> |
19 | #include <net/net_namespace.h> | 20 | #include <net/net_namespace.h> |
20 | #include <asm/uaccess.h> | 21 | #include <asm/uaccess.h> |
diff --git a/net/bridge/br_multicast.c b/net/bridge/br_multicast.c index 12ce1eaa4f3e..3fe86ffc069c 100644 --- a/net/bridge/br_multicast.c +++ b/net/bridge/br_multicast.c | |||
@@ -49,22 +49,23 @@ static struct net_bridge_mdb_entry *__br_mdb_ip_get( | |||
49 | static struct net_bridge_mdb_entry *br_mdb_ip_get( | 49 | static struct net_bridge_mdb_entry *br_mdb_ip_get( |
50 | struct net_bridge_mdb_htable *mdb, __be32 dst) | 50 | struct net_bridge_mdb_htable *mdb, __be32 dst) |
51 | { | 51 | { |
52 | if (!mdb) | ||
53 | return NULL; | ||
54 | |||
52 | return __br_mdb_ip_get(mdb, dst, br_ip_hash(mdb, dst)); | 55 | return __br_mdb_ip_get(mdb, dst, br_ip_hash(mdb, dst)); |
53 | } | 56 | } |
54 | 57 | ||
55 | struct net_bridge_mdb_entry *br_mdb_get(struct net_bridge *br, | 58 | struct net_bridge_mdb_entry *br_mdb_get(struct net_bridge *br, |
56 | struct sk_buff *skb) | 59 | struct sk_buff *skb) |
57 | { | 60 | { |
58 | struct net_bridge_mdb_htable *mdb = br->mdb; | 61 | if (br->multicast_disabled) |
59 | |||
60 | if (!mdb || br->multicast_disabled) | ||
61 | return NULL; | 62 | return NULL; |
62 | 63 | ||
63 | switch (skb->protocol) { | 64 | switch (skb->protocol) { |
64 | case htons(ETH_P_IP): | 65 | case htons(ETH_P_IP): |
65 | if (BR_INPUT_SKB_CB(skb)->igmp) | 66 | if (BR_INPUT_SKB_CB(skb)->igmp) |
66 | break; | 67 | break; |
67 | return br_mdb_ip_get(mdb, ip_hdr(skb)->daddr); | 68 | return br_mdb_ip_get(br->mdb, ip_hdr(skb)->daddr); |
68 | } | 69 | } |
69 | 70 | ||
70 | return NULL; | 71 | return NULL; |
@@ -722,7 +723,7 @@ static int br_multicast_igmp3_report(struct net_bridge *br, | |||
722 | if (!pskb_may_pull(skb, len)) | 723 | if (!pskb_may_pull(skb, len)) |
723 | return -EINVAL; | 724 | return -EINVAL; |
724 | 725 | ||
725 | grec = (void *)(skb->data + len); | 726 | grec = (void *)(skb->data + len - sizeof(*grec)); |
726 | group = grec->grec_mca; | 727 | group = grec->grec_mca; |
727 | type = grec->grec_type; | 728 | type = grec->grec_type; |
728 | 729 | ||
@@ -823,6 +824,7 @@ static int br_multicast_query(struct net_bridge *br, | |||
823 | unsigned long max_delay; | 824 | unsigned long max_delay; |
824 | unsigned long now = jiffies; | 825 | unsigned long now = jiffies; |
825 | __be32 group; | 826 | __be32 group; |
827 | int err = 0; | ||
826 | 828 | ||
827 | spin_lock(&br->multicast_lock); | 829 | spin_lock(&br->multicast_lock); |
828 | if (!netif_running(br->dev) || | 830 | if (!netif_running(br->dev) || |
@@ -841,15 +843,17 @@ static int br_multicast_query(struct net_bridge *br, | |||
841 | group = 0; | 843 | group = 0; |
842 | } | 844 | } |
843 | } else { | 845 | } else { |
844 | if (!pskb_may_pull(skb, sizeof(struct igmpv3_query))) | 846 | if (!pskb_may_pull(skb, sizeof(struct igmpv3_query))) { |
845 | return -EINVAL; | 847 | err = -EINVAL; |
848 | goto out; | ||
849 | } | ||
846 | 850 | ||
847 | ih3 = igmpv3_query_hdr(skb); | 851 | ih3 = igmpv3_query_hdr(skb); |
848 | if (ih3->nsrcs) | 852 | if (ih3->nsrcs) |
849 | return 0; | 853 | goto out; |
850 | 854 | ||
851 | max_delay = ih3->code ? 1 : | 855 | max_delay = ih3->code ? |
852 | IGMPV3_MRC(ih3->code) * (HZ / IGMP_TIMER_SCALE); | 856 | IGMPV3_MRC(ih3->code) * (HZ / IGMP_TIMER_SCALE) : 1; |
853 | } | 857 | } |
854 | 858 | ||
855 | if (!group) | 859 | if (!group) |
@@ -876,7 +880,7 @@ static int br_multicast_query(struct net_bridge *br, | |||
876 | 880 | ||
877 | out: | 881 | out: |
878 | spin_unlock(&br->multicast_lock); | 882 | spin_unlock(&br->multicast_lock); |
879 | return 0; | 883 | return err; |
880 | } | 884 | } |
881 | 885 | ||
882 | static void br_multicast_leave_group(struct net_bridge *br, | 886 | static void br_multicast_leave_group(struct net_bridge *br, |
@@ -987,7 +991,7 @@ static int br_multicast_ipv4_rcv(struct net_bridge *br, | |||
987 | 991 | ||
988 | err = pskb_trim_rcsum(skb2, len); | 992 | err = pskb_trim_rcsum(skb2, len); |
989 | if (err) | 993 | if (err) |
990 | return err; | 994 | goto err_out; |
991 | } | 995 | } |
992 | 996 | ||
993 | len -= ip_hdrlen(skb2); | 997 | len -= ip_hdrlen(skb2); |
@@ -999,8 +1003,6 @@ static int br_multicast_ipv4_rcv(struct net_bridge *br, | |||
999 | if (!pskb_may_pull(skb2, sizeof(*ih))) | 1003 | if (!pskb_may_pull(skb2, sizeof(*ih))) |
1000 | goto out; | 1004 | goto out; |
1001 | 1005 | ||
1002 | iph = ip_hdr(skb2); | ||
1003 | |||
1004 | switch (skb2->ip_summed) { | 1006 | switch (skb2->ip_summed) { |
1005 | case CHECKSUM_COMPLETE: | 1007 | case CHECKSUM_COMPLETE: |
1006 | if (!csum_fold(skb2->csum)) | 1008 | if (!csum_fold(skb2->csum)) |
@@ -1009,7 +1011,7 @@ static int br_multicast_ipv4_rcv(struct net_bridge *br, | |||
1009 | case CHECKSUM_NONE: | 1011 | case CHECKSUM_NONE: |
1010 | skb2->csum = 0; | 1012 | skb2->csum = 0; |
1011 | if (skb_checksum_complete(skb2)) | 1013 | if (skb_checksum_complete(skb2)) |
1012 | return -EINVAL; | 1014 | goto out; |
1013 | } | 1015 | } |
1014 | 1016 | ||
1015 | err = 0; | 1017 | err = 0; |
@@ -1036,6 +1038,7 @@ static int br_multicast_ipv4_rcv(struct net_bridge *br, | |||
1036 | 1038 | ||
1037 | out: | 1039 | out: |
1038 | __skb_push(skb2, offset); | 1040 | __skb_push(skb2, offset); |
1041 | err_out: | ||
1039 | if (skb2 != skb) | 1042 | if (skb2 != skb) |
1040 | kfree_skb(skb2); | 1043 | kfree_skb(skb2); |
1041 | return err; | 1044 | return err; |
diff --git a/net/bridge/br_netfilter.c b/net/bridge/br_netfilter.c index 268e2e725888..4c4977d12fd6 100644 --- a/net/bridge/br_netfilter.c +++ b/net/bridge/br_netfilter.c | |||
@@ -23,6 +23,7 @@ | |||
23 | 23 | ||
24 | #include <linux/module.h> | 24 | #include <linux/module.h> |
25 | #include <linux/kernel.h> | 25 | #include <linux/kernel.h> |
26 | #include <linux/slab.h> | ||
26 | #include <linux/ip.h> | 27 | #include <linux/ip.h> |
27 | #include <linux/netdevice.h> | 28 | #include <linux/netdevice.h> |
28 | #include <linux/skbuff.h> | 29 | #include <linux/skbuff.h> |
diff --git a/net/bridge/br_netlink.c b/net/bridge/br_netlink.c index fcffb3fb1177..aa56ac2c8829 100644 --- a/net/bridge/br_netlink.c +++ b/net/bridge/br_netlink.c | |||
@@ -11,6 +11,7 @@ | |||
11 | */ | 11 | */ |
12 | 12 | ||
13 | #include <linux/kernel.h> | 13 | #include <linux/kernel.h> |
14 | #include <linux/slab.h> | ||
14 | #include <net/rtnetlink.h> | 15 | #include <net/rtnetlink.h> |
15 | #include <net/net_namespace.h> | 16 | #include <net/net_namespace.h> |
16 | #include <net/sock.h> | 17 | #include <net/sock.h> |
diff --git a/net/bridge/br_notify.c b/net/bridge/br_notify.c index 763a3ec292e5..1413b72acc7f 100644 --- a/net/bridge/br_notify.c +++ b/net/bridge/br_notify.c | |||
@@ -82,6 +82,10 @@ static int br_device_event(struct notifier_block *unused, unsigned long event, v | |||
82 | case NETDEV_UNREGISTER: | 82 | case NETDEV_UNREGISTER: |
83 | br_del_if(br, dev); | 83 | br_del_if(br, dev); |
84 | break; | 84 | break; |
85 | |||
86 | case NETDEV_PRE_TYPE_CHANGE: | ||
87 | /* Forbid underlaying device to change its type. */ | ||
88 | return NOTIFY_BAD; | ||
85 | } | 89 | } |
86 | 90 | ||
87 | /* Events that may cause spanning tree to refresh */ | 91 | /* Events that may cause spanning tree to refresh */ |
diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h index 1cf2cef78584..791d4ab0fd4d 100644 --- a/net/bridge/br_private.h +++ b/net/bridge/br_private.h | |||
@@ -135,6 +135,14 @@ struct net_bridge | |||
135 | spinlock_t lock; | 135 | spinlock_t lock; |
136 | struct list_head port_list; | 136 | struct list_head port_list; |
137 | struct net_device *dev; | 137 | struct net_device *dev; |
138 | |||
139 | struct br_cpu_netstats __percpu { | ||
140 | unsigned long rx_packets; | ||
141 | unsigned long rx_bytes; | ||
142 | unsigned long tx_packets; | ||
143 | unsigned long tx_bytes; | ||
144 | } *stats; | ||
145 | |||
138 | spinlock_t hash_lock; | 146 | spinlock_t hash_lock; |
139 | struct hlist_head hash[BR_HASH_SIZE]; | 147 | struct hlist_head hash[BR_HASH_SIZE]; |
140 | unsigned long feature_mask; | 148 | unsigned long feature_mask; |
@@ -206,12 +214,20 @@ struct net_bridge | |||
206 | 214 | ||
207 | struct br_input_skb_cb { | 215 | struct br_input_skb_cb { |
208 | struct net_device *brdev; | 216 | struct net_device *brdev; |
217 | #ifdef CONFIG_BRIDGE_IGMP_SNOOPING | ||
209 | int igmp; | 218 | int igmp; |
210 | int mrouters_only; | 219 | int mrouters_only; |
220 | #endif | ||
211 | }; | 221 | }; |
212 | 222 | ||
213 | #define BR_INPUT_SKB_CB(__skb) ((struct br_input_skb_cb *)(__skb)->cb) | 223 | #define BR_INPUT_SKB_CB(__skb) ((struct br_input_skb_cb *)(__skb)->cb) |
214 | 224 | ||
225 | #ifdef CONFIG_BRIDGE_IGMP_SNOOPING | ||
226 | # define BR_INPUT_SKB_CB_MROUTERS_ONLY(__skb) (BR_INPUT_SKB_CB(__skb)->mrouters_only) | ||
227 | #else | ||
228 | # define BR_INPUT_SKB_CB_MROUTERS_ONLY(__skb) (0) | ||
229 | #endif | ||
230 | |||
215 | extern struct notifier_block br_device_notifier; | 231 | extern struct notifier_block br_device_notifier; |
216 | extern const u8 br_group_address[ETH_ALEN]; | 232 | extern const u8 br_group_address[ETH_ALEN]; |
217 | 233 | ||
@@ -252,7 +268,7 @@ extern void br_deliver(const struct net_bridge_port *to, | |||
252 | struct sk_buff *skb); | 268 | struct sk_buff *skb); |
253 | extern int br_dev_queue_push_xmit(struct sk_buff *skb); | 269 | extern int br_dev_queue_push_xmit(struct sk_buff *skb); |
254 | extern void br_forward(const struct net_bridge_port *to, | 270 | extern void br_forward(const struct net_bridge_port *to, |
255 | struct sk_buff *skb); | 271 | struct sk_buff *skb, struct sk_buff *skb0); |
256 | extern int br_forward_finish(struct sk_buff *skb); | 272 | extern int br_forward_finish(struct sk_buff *skb); |
257 | extern void br_flood_deliver(struct net_bridge *br, struct sk_buff *skb); | 273 | extern void br_flood_deliver(struct net_bridge *br, struct sk_buff *skb); |
258 | extern void br_flood_forward(struct net_bridge *br, struct sk_buff *skb, | 274 | extern void br_flood_forward(struct net_bridge *br, struct sk_buff *skb, |
@@ -423,7 +439,7 @@ extern void br_ifinfo_notify(int event, struct net_bridge_port *port); | |||
423 | 439 | ||
424 | #ifdef CONFIG_SYSFS | 440 | #ifdef CONFIG_SYSFS |
425 | /* br_sysfs_if.c */ | 441 | /* br_sysfs_if.c */ |
426 | extern struct sysfs_ops brport_sysfs_ops; | 442 | extern const struct sysfs_ops brport_sysfs_ops; |
427 | extern int br_sysfs_addif(struct net_bridge_port *p); | 443 | extern int br_sysfs_addif(struct net_bridge_port *p); |
428 | 444 | ||
429 | /* br_sysfs_br.c */ | 445 | /* br_sysfs_br.c */ |
diff --git a/net/bridge/br_stp_bpdu.c b/net/bridge/br_stp_bpdu.c index 81ae40b3f655..d66cce11f3bf 100644 --- a/net/bridge/br_stp_bpdu.c +++ b/net/bridge/br_stp_bpdu.c | |||
@@ -15,6 +15,7 @@ | |||
15 | #include <linux/netfilter_bridge.h> | 15 | #include <linux/netfilter_bridge.h> |
16 | #include <linux/etherdevice.h> | 16 | #include <linux/etherdevice.h> |
17 | #include <linux/llc.h> | 17 | #include <linux/llc.h> |
18 | #include <linux/slab.h> | ||
18 | #include <net/net_namespace.h> | 19 | #include <net/net_namespace.h> |
19 | #include <net/llc.h> | 20 | #include <net/llc.h> |
20 | #include <net/llc_pdu.h> | 21 | #include <net/llc_pdu.h> |
diff --git a/net/bridge/br_sysfs_if.c b/net/bridge/br_sysfs_if.c index 696596cd3384..0b9916489d6b 100644 --- a/net/bridge/br_sysfs_if.c +++ b/net/bridge/br_sysfs_if.c | |||
@@ -238,7 +238,7 @@ static ssize_t brport_store(struct kobject * kobj, | |||
238 | return ret; | 238 | return ret; |
239 | } | 239 | } |
240 | 240 | ||
241 | struct sysfs_ops brport_sysfs_ops = { | 241 | const struct sysfs_ops brport_sysfs_ops = { |
242 | .show = brport_show, | 242 | .show = brport_show, |
243 | .store = brport_store, | 243 | .store = brport_store, |
244 | }; | 244 | }; |
diff --git a/net/bridge/netfilter/ebt_ulog.c b/net/bridge/netfilter/ebt_ulog.c index c6ac657074a6..f9560f3dbdc7 100644 --- a/net/bridge/netfilter/ebt_ulog.c +++ b/net/bridge/netfilter/ebt_ulog.c | |||
@@ -29,6 +29,7 @@ | |||
29 | */ | 29 | */ |
30 | 30 | ||
31 | #include <linux/module.h> | 31 | #include <linux/module.h> |
32 | #include <linux/slab.h> | ||
32 | #include <linux/spinlock.h> | 33 | #include <linux/spinlock.h> |
33 | #include <linux/socket.h> | 34 | #include <linux/socket.h> |
34 | #include <linux/skbuff.h> | 35 | #include <linux/skbuff.h> |
diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c index dfb58056a89a..f0865fd1e3ec 100644 --- a/net/bridge/netfilter/ebtables.c +++ b/net/bridge/netfilter/ebtables.c | |||
@@ -23,6 +23,7 @@ | |||
23 | #include <linux/netfilter_bridge/ebtables.h> | 23 | #include <linux/netfilter_bridge/ebtables.h> |
24 | #include <linux/spinlock.h> | 24 | #include <linux/spinlock.h> |
25 | #include <linux/mutex.h> | 25 | #include <linux/mutex.h> |
26 | #include <linux/slab.h> | ||
26 | #include <asm/uaccess.h> | 27 | #include <asm/uaccess.h> |
27 | #include <linux/smp.h> | 28 | #include <linux/smp.h> |
28 | #include <linux/cpumask.h> | 29 | #include <linux/cpumask.h> |
diff --git a/net/caif/Kconfig b/net/caif/Kconfig new file mode 100644 index 000000000000..cd1daf6008bd --- /dev/null +++ b/net/caif/Kconfig | |||
@@ -0,0 +1,48 @@ | |||
1 | # | ||
2 | # CAIF net configurations | ||
3 | # | ||
4 | |||
5 | #menu "CAIF Support" | ||
6 | comment "CAIF Support" | ||
7 | menuconfig CAIF | ||
8 | tristate "Enable CAIF support" | ||
9 | select CRC_CCITT | ||
10 | default n | ||
11 | ---help--- | ||
12 | The "Communication CPU to Application CPU Interface" (CAIF) is a packet | ||
13 | based connection-oriented MUX protocol developed by ST-Ericsson for use | ||
14 | with its modems. It is accessed from user space as sockets (PF_CAIF). | ||
15 | |||
16 | Say Y (or M) here if you build for a phone product (e.g. Android or | ||
17 | MeeGo ) that uses CAIF as transport, if unsure say N. | ||
18 | |||
19 | If you select to build it as module then CAIF_NETDEV also needs to be | ||
20 | built as modules. You will also need to say yes to any CAIF physical | ||
21 | devices that your platform requires. | ||
22 | |||
23 | See Documentation/networking/caif for a further explanation on how to | ||
24 | use and configure CAIF. | ||
25 | |||
26 | if CAIF | ||
27 | |||
28 | config CAIF_DEBUG | ||
29 | bool "Enable Debug" | ||
30 | default n | ||
31 | --- help --- | ||
32 | Enable the inclusion of debug code in the CAIF stack. | ||
33 | Be aware that doing this will impact performance. | ||
34 | If unsure say N. | ||
35 | |||
36 | |||
37 | config CAIF_NETDEV | ||
38 | tristate "CAIF GPRS Network device" | ||
39 | default CAIF | ||
40 | ---help--- | ||
41 | Say Y if you will be using a CAIF based GPRS network device. | ||
42 | This can be either built-in or a loadable module, | ||
43 | If you select to build it as a built-in then the main CAIF device must | ||
44 | also be a built-in. | ||
45 | If unsure say Y. | ||
46 | |||
47 | endif | ||
48 | #endmenu | ||
diff --git a/net/caif/Makefile b/net/caif/Makefile new file mode 100644 index 000000000000..34852af2595e --- /dev/null +++ b/net/caif/Makefile | |||
@@ -0,0 +1,26 @@ | |||
1 | ifeq ($(CONFIG_CAIF_DEBUG),1) | ||
2 | CAIF_DBG_FLAGS := -DDEBUG | ||
3 | endif | ||
4 | |||
5 | ccflags-y := $(CAIF_FLAGS) $(CAIF_DBG_FLAGS) | ||
6 | |||
7 | caif-objs := caif_dev.o \ | ||
8 | cfcnfg.o cfmuxl.o cfctrl.o \ | ||
9 | cffrml.o cfveil.o cfdbgl.o\ | ||
10 | cfserl.o cfdgml.o \ | ||
11 | cfrfml.o cfvidl.o cfutill.o \ | ||
12 | cfsrvl.o cfpkt_skbuff.o caif_config_util.o | ||
13 | clean-dirs:= .tmp_versions | ||
14 | |||
15 | clean-files:= \ | ||
16 | Module.symvers \ | ||
17 | modules.order \ | ||
18 | *.cmd \ | ||
19 | *.o \ | ||
20 | *~ | ||
21 | |||
22 | obj-$(CONFIG_CAIF) += caif.o | ||
23 | obj-$(CONFIG_CAIF_NETDEV) += chnl_net.o | ||
24 | obj-$(CONFIG_CAIF) += caif_socket.o | ||
25 | |||
26 | export-objs := caif.o | ||
diff --git a/net/caif/caif_config_util.c b/net/caif/caif_config_util.c new file mode 100644 index 000000000000..6f36580366f0 --- /dev/null +++ b/net/caif/caif_config_util.c | |||
@@ -0,0 +1,87 @@ | |||
1 | /* | ||
2 | * Copyright (C) ST-Ericsson AB 2010 | ||
3 | * Author: Sjur Brendeland sjur.brandeland@stericsson.com | ||
4 | * License terms: GNU General Public License (GPL) version 2 | ||
5 | */ | ||
6 | |||
7 | #include <linux/module.h> | ||
8 | #include <linux/spinlock.h> | ||
9 | #include <net/caif/cfctrl.h> | ||
10 | #include <net/caif/cfcnfg.h> | ||
11 | #include <net/caif/caif_dev.h> | ||
12 | |||
13 | int connect_req_to_link_param(struct cfcnfg *cnfg, | ||
14 | struct caif_connect_request *s, | ||
15 | struct cfctrl_link_param *l) | ||
16 | { | ||
17 | struct dev_info *dev_info; | ||
18 | enum cfcnfg_phy_preference pref; | ||
19 | memset(l, 0, sizeof(*l)); | ||
20 | l->priority = s->priority; | ||
21 | |||
22 | if (s->link_name[0] != '\0') | ||
23 | l->phyid = cfcnfg_get_named(cnfg, s->link_name); | ||
24 | else { | ||
25 | switch (s->link_selector) { | ||
26 | case CAIF_LINK_HIGH_BANDW: | ||
27 | pref = CFPHYPREF_HIGH_BW; | ||
28 | break; | ||
29 | case CAIF_LINK_LOW_LATENCY: | ||
30 | pref = CFPHYPREF_LOW_LAT; | ||
31 | break; | ||
32 | default: | ||
33 | return -EINVAL; | ||
34 | } | ||
35 | dev_info = cfcnfg_get_phyid(cnfg, pref); | ||
36 | if (dev_info == NULL) | ||
37 | return -ENODEV; | ||
38 | l->phyid = dev_info->id; | ||
39 | } | ||
40 | switch (s->protocol) { | ||
41 | case CAIFPROTO_AT: | ||
42 | l->linktype = CFCTRL_SRV_VEI; | ||
43 | if (s->sockaddr.u.at.type == CAIF_ATTYPE_PLAIN) | ||
44 | l->chtype = 0x02; | ||
45 | else | ||
46 | l->chtype = s->sockaddr.u.at.type; | ||
47 | l->endpoint = 0x00; | ||
48 | break; | ||
49 | case CAIFPROTO_DATAGRAM: | ||
50 | l->linktype = CFCTRL_SRV_DATAGRAM; | ||
51 | l->chtype = 0x00; | ||
52 | l->u.datagram.connid = s->sockaddr.u.dgm.connection_id; | ||
53 | break; | ||
54 | case CAIFPROTO_DATAGRAM_LOOP: | ||
55 | l->linktype = CFCTRL_SRV_DATAGRAM; | ||
56 | l->chtype = 0x03; | ||
57 | l->endpoint = 0x00; | ||
58 | l->u.datagram.connid = s->sockaddr.u.dgm.connection_id; | ||
59 | break; | ||
60 | case CAIFPROTO_RFM: | ||
61 | l->linktype = CFCTRL_SRV_RFM; | ||
62 | l->u.datagram.connid = s->sockaddr.u.rfm.connection_id; | ||
63 | strncpy(l->u.rfm.volume, s->sockaddr.u.rfm.volume, | ||
64 | sizeof(l->u.rfm.volume)-1); | ||
65 | l->u.rfm.volume[sizeof(l->u.rfm.volume)-1] = 0; | ||
66 | break; | ||
67 | case CAIFPROTO_UTIL: | ||
68 | l->linktype = CFCTRL_SRV_UTIL; | ||
69 | l->endpoint = 0x00; | ||
70 | l->chtype = 0x00; | ||
71 | strncpy(l->u.utility.name, s->sockaddr.u.util.service, | ||
72 | sizeof(l->u.utility.name)-1); | ||
73 | l->u.utility.name[sizeof(l->u.utility.name)-1] = 0; | ||
74 | caif_assert(sizeof(l->u.utility.name) > 10); | ||
75 | l->u.utility.paramlen = s->param.size; | ||
76 | if (l->u.utility.paramlen > sizeof(l->u.utility.params)) | ||
77 | l->u.utility.paramlen = sizeof(l->u.utility.params); | ||
78 | |||
79 | memcpy(l->u.utility.params, s->param.data, | ||
80 | l->u.utility.paramlen); | ||
81 | |||
82 | break; | ||
83 | default: | ||
84 | return -EINVAL; | ||
85 | } | ||
86 | return 0; | ||
87 | } | ||
diff --git a/net/caif/caif_dev.c b/net/caif/caif_dev.c new file mode 100644 index 000000000000..e84837e1bc86 --- /dev/null +++ b/net/caif/caif_dev.c | |||
@@ -0,0 +1,413 @@ | |||
1 | /* | ||
2 | * CAIF Interface registration. | ||
3 | * Copyright (C) ST-Ericsson AB 2010 | ||
4 | * Author: Sjur Brendeland/sjur.brandeland@stericsson.com | ||
5 | * License terms: GNU General Public License (GPL) version 2 | ||
6 | * | ||
7 | * Borrowed heavily from file: pn_dev.c. Thanks to | ||
8 | * Remi Denis-Courmont <remi.denis-courmont@nokia.com> | ||
9 | * and Sakari Ailus <sakari.ailus@nokia.com> | ||
10 | */ | ||
11 | |||
12 | #include <linux/version.h> | ||
13 | #include <linux/module.h> | ||
14 | #include <linux/kernel.h> | ||
15 | #include <linux/if_arp.h> | ||
16 | #include <linux/net.h> | ||
17 | #include <linux/netdevice.h> | ||
18 | #include <linux/skbuff.h> | ||
19 | #include <linux/sched.h> | ||
20 | #include <linux/wait.h> | ||
21 | #include <net/netns/generic.h> | ||
22 | #include <net/net_namespace.h> | ||
23 | #include <net/pkt_sched.h> | ||
24 | #include <net/caif/caif_device.h> | ||
25 | #include <net/caif/caif_dev.h> | ||
26 | #include <net/caif/caif_layer.h> | ||
27 | #include <net/caif/cfpkt.h> | ||
28 | #include <net/caif/cfcnfg.h> | ||
29 | |||
30 | MODULE_LICENSE("GPL"); | ||
31 | #define TIMEOUT (HZ*5) | ||
32 | |||
33 | /* Used for local tracking of the CAIF net devices */ | ||
34 | struct caif_device_entry { | ||
35 | struct cflayer layer; | ||
36 | struct list_head list; | ||
37 | atomic_t in_use; | ||
38 | atomic_t state; | ||
39 | u16 phyid; | ||
40 | struct net_device *netdev; | ||
41 | wait_queue_head_t event; | ||
42 | }; | ||
43 | |||
44 | struct caif_device_entry_list { | ||
45 | struct list_head list; | ||
46 | /* Protects simulanous deletes in list */ | ||
47 | spinlock_t lock; | ||
48 | }; | ||
49 | |||
50 | struct caif_net { | ||
51 | struct caif_device_entry_list caifdevs; | ||
52 | }; | ||
53 | |||
54 | static int caif_net_id; | ||
55 | static struct cfcnfg *cfg; | ||
56 | |||
57 | static struct caif_device_entry_list *caif_device_list(struct net *net) | ||
58 | { | ||
59 | struct caif_net *caifn; | ||
60 | BUG_ON(!net); | ||
61 | caifn = net_generic(net, caif_net_id); | ||
62 | BUG_ON(!caifn); | ||
63 | return &caifn->caifdevs; | ||
64 | } | ||
65 | |||
66 | /* Allocate new CAIF device. */ | ||
67 | static struct caif_device_entry *caif_device_alloc(struct net_device *dev) | ||
68 | { | ||
69 | struct caif_device_entry_list *caifdevs; | ||
70 | struct caif_device_entry *caifd; | ||
71 | caifdevs = caif_device_list(dev_net(dev)); | ||
72 | BUG_ON(!caifdevs); | ||
73 | caifd = kzalloc(sizeof(*caifd), GFP_ATOMIC); | ||
74 | if (!caifd) | ||
75 | return NULL; | ||
76 | caifd->netdev = dev; | ||
77 | list_add(&caifd->list, &caifdevs->list); | ||
78 | init_waitqueue_head(&caifd->event); | ||
79 | return caifd; | ||
80 | } | ||
81 | |||
82 | static struct caif_device_entry *caif_get(struct net_device *dev) | ||
83 | { | ||
84 | struct caif_device_entry_list *caifdevs = | ||
85 | caif_device_list(dev_net(dev)); | ||
86 | struct caif_device_entry *caifd; | ||
87 | BUG_ON(!caifdevs); | ||
88 | list_for_each_entry(caifd, &caifdevs->list, list) { | ||
89 | if (caifd->netdev == dev) | ||
90 | return caifd; | ||
91 | } | ||
92 | return NULL; | ||
93 | } | ||
94 | |||
95 | static void caif_device_destroy(struct net_device *dev) | ||
96 | { | ||
97 | struct caif_device_entry_list *caifdevs = | ||
98 | caif_device_list(dev_net(dev)); | ||
99 | struct caif_device_entry *caifd; | ||
100 | ASSERT_RTNL(); | ||
101 | if (dev->type != ARPHRD_CAIF) | ||
102 | return; | ||
103 | |||
104 | spin_lock_bh(&caifdevs->lock); | ||
105 | caifd = caif_get(dev); | ||
106 | if (caifd == NULL) { | ||
107 | spin_unlock_bh(&caifdevs->lock); | ||
108 | return; | ||
109 | } | ||
110 | |||
111 | list_del(&caifd->list); | ||
112 | spin_unlock_bh(&caifdevs->lock); | ||
113 | |||
114 | kfree(caifd); | ||
115 | return; | ||
116 | } | ||
117 | |||
118 | static int transmit(struct cflayer *layer, struct cfpkt *pkt) | ||
119 | { | ||
120 | struct caif_device_entry *caifd = | ||
121 | container_of(layer, struct caif_device_entry, layer); | ||
122 | struct sk_buff *skb, *skb2; | ||
123 | int ret = -EINVAL; | ||
124 | skb = cfpkt_tonative(pkt); | ||
125 | skb->dev = caifd->netdev; | ||
126 | /* | ||
127 | * Don't allow SKB to be destroyed upon error, but signal resend | ||
128 | * notification to clients. We can't rely on the return value as | ||
129 | * congestion (NET_XMIT_CN) sometimes drops the packet, sometimes don't. | ||
130 | */ | ||
131 | if (netif_queue_stopped(caifd->netdev)) | ||
132 | return -EAGAIN; | ||
133 | skb2 = skb_get(skb); | ||
134 | |||
135 | ret = dev_queue_xmit(skb2); | ||
136 | |||
137 | if (!ret) | ||
138 | kfree_skb(skb); | ||
139 | else | ||
140 | return -EAGAIN; | ||
141 | |||
142 | return 0; | ||
143 | } | ||
144 | |||
145 | static int modemcmd(struct cflayer *layr, enum caif_modemcmd ctrl) | ||
146 | { | ||
147 | struct caif_device_entry *caifd; | ||
148 | struct caif_dev_common *caifdev; | ||
149 | caifd = container_of(layr, struct caif_device_entry, layer); | ||
150 | caifdev = netdev_priv(caifd->netdev); | ||
151 | if (ctrl == _CAIF_MODEMCMD_PHYIF_USEFULL) { | ||
152 | atomic_set(&caifd->in_use, 1); | ||
153 | wake_up_interruptible(&caifd->event); | ||
154 | |||
155 | } else if (ctrl == _CAIF_MODEMCMD_PHYIF_USELESS) { | ||
156 | atomic_set(&caifd->in_use, 0); | ||
157 | wake_up_interruptible(&caifd->event); | ||
158 | } | ||
159 | return 0; | ||
160 | } | ||
161 | |||
162 | /* | ||
163 | * Stuff received packets to associated sockets. | ||
164 | * On error, returns non-zero and releases the skb. | ||
165 | */ | ||
166 | static int receive(struct sk_buff *skb, struct net_device *dev, | ||
167 | struct packet_type *pkttype, struct net_device *orig_dev) | ||
168 | { | ||
169 | struct net *net; | ||
170 | struct cfpkt *pkt; | ||
171 | struct caif_device_entry *caifd; | ||
172 | net = dev_net(dev); | ||
173 | pkt = cfpkt_fromnative(CAIF_DIR_IN, skb); | ||
174 | caifd = caif_get(dev); | ||
175 | if (!caifd || !caifd->layer.up || !caifd->layer.up->ctrlcmd) | ||
176 | return NET_RX_DROP; | ||
177 | |||
178 | if (caifd->layer.up->receive(caifd->layer.up, pkt)) | ||
179 | return NET_RX_DROP; | ||
180 | |||
181 | return 0; | ||
182 | } | ||
183 | |||
184 | static struct packet_type caif_packet_type __read_mostly = { | ||
185 | .type = cpu_to_be16(ETH_P_CAIF), | ||
186 | .func = receive, | ||
187 | }; | ||
188 | |||
189 | static void dev_flowctrl(struct net_device *dev, int on) | ||
190 | { | ||
191 | struct caif_device_entry *caifd = caif_get(dev); | ||
192 | if (!caifd || !caifd->layer.up || !caifd->layer.up->ctrlcmd) | ||
193 | return; | ||
194 | |||
195 | caifd->layer.up->ctrlcmd(caifd->layer.up, | ||
196 | on ? | ||
197 | _CAIF_CTRLCMD_PHYIF_FLOW_ON_IND : | ||
198 | _CAIF_CTRLCMD_PHYIF_FLOW_OFF_IND, | ||
199 | caifd->layer.id); | ||
200 | } | ||
201 | |||
202 | /* notify Caif of device events */ | ||
203 | static int caif_device_notify(struct notifier_block *me, unsigned long what, | ||
204 | void *arg) | ||
205 | { | ||
206 | struct net_device *dev = arg; | ||
207 | struct caif_device_entry *caifd = NULL; | ||
208 | struct caif_dev_common *caifdev; | ||
209 | enum cfcnfg_phy_preference pref; | ||
210 | int res = -EINVAL; | ||
211 | enum cfcnfg_phy_type phy_type; | ||
212 | |||
213 | if (dev->type != ARPHRD_CAIF) | ||
214 | return 0; | ||
215 | |||
216 | switch (what) { | ||
217 | case NETDEV_REGISTER: | ||
218 | pr_info("CAIF: %s():register %s\n", __func__, dev->name); | ||
219 | caifd = caif_device_alloc(dev); | ||
220 | if (caifd == NULL) | ||
221 | break; | ||
222 | caifdev = netdev_priv(dev); | ||
223 | caifdev->flowctrl = dev_flowctrl; | ||
224 | atomic_set(&caifd->state, what); | ||
225 | res = 0; | ||
226 | break; | ||
227 | |||
228 | case NETDEV_UP: | ||
229 | pr_info("CAIF: %s(): up %s\n", __func__, dev->name); | ||
230 | caifd = caif_get(dev); | ||
231 | if (caifd == NULL) | ||
232 | break; | ||
233 | caifdev = netdev_priv(dev); | ||
234 | if (atomic_read(&caifd->state) == NETDEV_UP) { | ||
235 | pr_info("CAIF: %s():%s already up\n", | ||
236 | __func__, dev->name); | ||
237 | break; | ||
238 | } | ||
239 | atomic_set(&caifd->state, what); | ||
240 | caifd->layer.transmit = transmit; | ||
241 | caifd->layer.modemcmd = modemcmd; | ||
242 | |||
243 | if (caifdev->use_frag) | ||
244 | phy_type = CFPHYTYPE_FRAG; | ||
245 | else | ||
246 | phy_type = CFPHYTYPE_CAIF; | ||
247 | |||
248 | switch (caifdev->link_select) { | ||
249 | case CAIF_LINK_HIGH_BANDW: | ||
250 | pref = CFPHYPREF_LOW_LAT; | ||
251 | break; | ||
252 | case CAIF_LINK_LOW_LATENCY: | ||
253 | pref = CFPHYPREF_HIGH_BW; | ||
254 | break; | ||
255 | default: | ||
256 | pref = CFPHYPREF_HIGH_BW; | ||
257 | break; | ||
258 | } | ||
259 | |||
260 | cfcnfg_add_phy_layer(get_caif_conf(), | ||
261 | phy_type, | ||
262 | dev, | ||
263 | &caifd->layer, | ||
264 | &caifd->phyid, | ||
265 | pref, | ||
266 | caifdev->use_fcs, | ||
267 | caifdev->use_stx); | ||
268 | strncpy(caifd->layer.name, dev->name, | ||
269 | sizeof(caifd->layer.name) - 1); | ||
270 | caifd->layer.name[sizeof(caifd->layer.name) - 1] = 0; | ||
271 | break; | ||
272 | |||
273 | case NETDEV_GOING_DOWN: | ||
274 | caifd = caif_get(dev); | ||
275 | if (caifd == NULL) | ||
276 | break; | ||
277 | pr_info("CAIF: %s():going down %s\n", __func__, dev->name); | ||
278 | |||
279 | if (atomic_read(&caifd->state) == NETDEV_GOING_DOWN || | ||
280 | atomic_read(&caifd->state) == NETDEV_DOWN) | ||
281 | break; | ||
282 | |||
283 | atomic_set(&caifd->state, what); | ||
284 | if (!caifd || !caifd->layer.up || !caifd->layer.up->ctrlcmd) | ||
285 | return -EINVAL; | ||
286 | caifd->layer.up->ctrlcmd(caifd->layer.up, | ||
287 | _CAIF_CTRLCMD_PHYIF_DOWN_IND, | ||
288 | caifd->layer.id); | ||
289 | res = wait_event_interruptible_timeout(caifd->event, | ||
290 | atomic_read(&caifd->in_use) == 0, | ||
291 | TIMEOUT); | ||
292 | break; | ||
293 | |||
294 | case NETDEV_DOWN: | ||
295 | caifd = caif_get(dev); | ||
296 | if (caifd == NULL) | ||
297 | break; | ||
298 | pr_info("CAIF: %s(): down %s\n", __func__, dev->name); | ||
299 | if (atomic_read(&caifd->in_use)) | ||
300 | pr_warning("CAIF: %s(): " | ||
301 | "Unregistering an active CAIF device: %s\n", | ||
302 | __func__, dev->name); | ||
303 | cfcnfg_del_phy_layer(get_caif_conf(), &caifd->layer); | ||
304 | atomic_set(&caifd->state, what); | ||
305 | break; | ||
306 | |||
307 | case NETDEV_UNREGISTER: | ||
308 | caifd = caif_get(dev); | ||
309 | pr_info("CAIF: %s(): unregister %s\n", __func__, dev->name); | ||
310 | atomic_set(&caifd->state, what); | ||
311 | caif_device_destroy(dev); | ||
312 | break; | ||
313 | } | ||
314 | return 0; | ||
315 | } | ||
316 | |||
317 | static struct notifier_block caif_device_notifier = { | ||
318 | .notifier_call = caif_device_notify, | ||
319 | .priority = 0, | ||
320 | }; | ||
321 | |||
322 | |||
323 | struct cfcnfg *get_caif_conf(void) | ||
324 | { | ||
325 | return cfg; | ||
326 | } | ||
327 | EXPORT_SYMBOL(get_caif_conf); | ||
328 | |||
329 | int caif_connect_client(struct caif_connect_request *conn_req, | ||
330 | struct cflayer *client_layer) | ||
331 | { | ||
332 | struct cfctrl_link_param param; | ||
333 | if (connect_req_to_link_param(get_caif_conf(), conn_req, ¶m) == 0) | ||
334 | /* Hook up the adaptation layer. */ | ||
335 | return cfcnfg_add_adaptation_layer(get_caif_conf(), | ||
336 | ¶m, client_layer); | ||
337 | |||
338 | return -EINVAL; | ||
339 | |||
340 | caif_assert(0); | ||
341 | } | ||
342 | EXPORT_SYMBOL(caif_connect_client); | ||
343 | |||
344 | int caif_disconnect_client(struct cflayer *adap_layer) | ||
345 | { | ||
346 | return cfcnfg_del_adapt_layer(get_caif_conf(), adap_layer); | ||
347 | } | ||
348 | EXPORT_SYMBOL(caif_disconnect_client); | ||
349 | |||
350 | /* Per-namespace Caif devices handling */ | ||
351 | static int caif_init_net(struct net *net) | ||
352 | { | ||
353 | struct caif_net *caifn = net_generic(net, caif_net_id); | ||
354 | INIT_LIST_HEAD(&caifn->caifdevs.list); | ||
355 | spin_lock_init(&caifn->caifdevs.lock); | ||
356 | return 0; | ||
357 | } | ||
358 | |||
359 | static void caif_exit_net(struct net *net) | ||
360 | { | ||
361 | struct net_device *dev; | ||
362 | int res; | ||
363 | rtnl_lock(); | ||
364 | for_each_netdev(net, dev) { | ||
365 | if (dev->type != ARPHRD_CAIF) | ||
366 | continue; | ||
367 | res = dev_close(dev); | ||
368 | caif_device_destroy(dev); | ||
369 | } | ||
370 | rtnl_unlock(); | ||
371 | } | ||
372 | |||
373 | static struct pernet_operations caif_net_ops = { | ||
374 | .init = caif_init_net, | ||
375 | .exit = caif_exit_net, | ||
376 | .id = &caif_net_id, | ||
377 | .size = sizeof(struct caif_net), | ||
378 | }; | ||
379 | |||
380 | /* Initialize Caif devices list */ | ||
381 | static int __init caif_device_init(void) | ||
382 | { | ||
383 | int result; | ||
384 | cfg = cfcnfg_create(); | ||
385 | if (!cfg) { | ||
386 | pr_warning("CAIF: %s(): can't create cfcnfg.\n", __func__); | ||
387 | goto err_cfcnfg_create_failed; | ||
388 | } | ||
389 | result = register_pernet_device(&caif_net_ops); | ||
390 | |||
391 | if (result) { | ||
392 | kfree(cfg); | ||
393 | cfg = NULL; | ||
394 | return result; | ||
395 | } | ||
396 | dev_add_pack(&caif_packet_type); | ||
397 | register_netdevice_notifier(&caif_device_notifier); | ||
398 | |||
399 | return result; | ||
400 | err_cfcnfg_create_failed: | ||
401 | return -ENODEV; | ||
402 | } | ||
403 | |||
404 | static void __exit caif_device_exit(void) | ||
405 | { | ||
406 | dev_remove_pack(&caif_packet_type); | ||
407 | unregister_pernet_device(&caif_net_ops); | ||
408 | unregister_netdevice_notifier(&caif_device_notifier); | ||
409 | cfcnfg_remove(cfg); | ||
410 | } | ||
411 | |||
412 | module_init(caif_device_init); | ||
413 | module_exit(caif_device_exit); | ||
diff --git a/net/caif/caif_socket.c b/net/caif/caif_socket.c new file mode 100644 index 000000000000..cdf62b9fefac --- /dev/null +++ b/net/caif/caif_socket.c | |||
@@ -0,0 +1,1391 @@ | |||
1 | /* | ||
2 | * Copyright (C) ST-Ericsson AB 2010 | ||
3 | * Author: Sjur Brendeland sjur.brandeland@stericsson.com | ||
4 | * Per Sigmond per.sigmond@stericsson.com | ||
5 | * License terms: GNU General Public License (GPL) version 2 | ||
6 | */ | ||
7 | |||
8 | #include <linux/fs.h> | ||
9 | #include <linux/init.h> | ||
10 | #include <linux/module.h> | ||
11 | #include <linux/sched.h> | ||
12 | #include <linux/spinlock.h> | ||
13 | #include <linux/mutex.h> | ||
14 | #include <linux/list.h> | ||
15 | #include <linux/wait.h> | ||
16 | #include <linux/poll.h> | ||
17 | #include <linux/tcp.h> | ||
18 | #include <linux/uaccess.h> | ||
19 | #include <asm/atomic.h> | ||
20 | |||
21 | #include <linux/caif/caif_socket.h> | ||
22 | #include <net/caif/caif_layer.h> | ||
23 | #include <net/caif/caif_dev.h> | ||
24 | #include <net/caif/cfpkt.h> | ||
25 | |||
26 | MODULE_LICENSE("GPL"); | ||
27 | |||
28 | #define CHNL_SKT_READ_QUEUE_HIGH 200 | ||
29 | #define CHNL_SKT_READ_QUEUE_LOW 100 | ||
30 | |||
31 | static int caif_sockbuf_size = 40000; | ||
32 | static atomic_t caif_nr_socks = ATOMIC_INIT(0); | ||
33 | |||
34 | #define CONN_STATE_OPEN_BIT 1 | ||
35 | #define CONN_STATE_PENDING_BIT 2 | ||
36 | #define CONN_STATE_PEND_DESTROY_BIT 3 | ||
37 | #define CONN_REMOTE_SHUTDOWN_BIT 4 | ||
38 | |||
39 | #define TX_FLOW_ON_BIT 1 | ||
40 | #define RX_FLOW_ON_BIT 2 | ||
41 | |||
42 | #define STATE_IS_OPEN(cf_sk) test_bit(CONN_STATE_OPEN_BIT,\ | ||
43 | (void *) &(cf_sk)->conn_state) | ||
44 | #define STATE_IS_REMOTE_SHUTDOWN(cf_sk) test_bit(CONN_REMOTE_SHUTDOWN_BIT,\ | ||
45 | (void *) &(cf_sk)->conn_state) | ||
46 | #define STATE_IS_PENDING(cf_sk) test_bit(CONN_STATE_PENDING_BIT,\ | ||
47 | (void *) &(cf_sk)->conn_state) | ||
48 | #define STATE_IS_PENDING_DESTROY(cf_sk) test_bit(CONN_STATE_PEND_DESTROY_BIT,\ | ||
49 | (void *) &(cf_sk)->conn_state) | ||
50 | |||
51 | #define SET_STATE_PENDING_DESTROY(cf_sk) set_bit(CONN_STATE_PEND_DESTROY_BIT,\ | ||
52 | (void *) &(cf_sk)->conn_state) | ||
53 | #define SET_STATE_OPEN(cf_sk) set_bit(CONN_STATE_OPEN_BIT,\ | ||
54 | (void *) &(cf_sk)->conn_state) | ||
55 | #define SET_STATE_CLOSED(cf_sk) clear_bit(CONN_STATE_OPEN_BIT,\ | ||
56 | (void *) &(cf_sk)->conn_state) | ||
57 | #define SET_PENDING_ON(cf_sk) set_bit(CONN_STATE_PENDING_BIT,\ | ||
58 | (void *) &(cf_sk)->conn_state) | ||
59 | #define SET_PENDING_OFF(cf_sk) clear_bit(CONN_STATE_PENDING_BIT,\ | ||
60 | (void *) &(cf_sk)->conn_state) | ||
61 | #define SET_REMOTE_SHUTDOWN(cf_sk) set_bit(CONN_REMOTE_SHUTDOWN_BIT,\ | ||
62 | (void *) &(cf_sk)->conn_state) | ||
63 | |||
64 | #define SET_REMOTE_SHUTDOWN_OFF(dev) clear_bit(CONN_REMOTE_SHUTDOWN_BIT,\ | ||
65 | (void *) &(dev)->conn_state) | ||
66 | #define RX_FLOW_IS_ON(cf_sk) test_bit(RX_FLOW_ON_BIT,\ | ||
67 | (void *) &(cf_sk)->flow_state) | ||
68 | #define TX_FLOW_IS_ON(cf_sk) test_bit(TX_FLOW_ON_BIT,\ | ||
69 | (void *) &(cf_sk)->flow_state) | ||
70 | |||
71 | #define SET_RX_FLOW_OFF(cf_sk) clear_bit(RX_FLOW_ON_BIT,\ | ||
72 | (void *) &(cf_sk)->flow_state) | ||
73 | #define SET_RX_FLOW_ON(cf_sk) set_bit(RX_FLOW_ON_BIT,\ | ||
74 | (void *) &(cf_sk)->flow_state) | ||
75 | #define SET_TX_FLOW_OFF(cf_sk) clear_bit(TX_FLOW_ON_BIT,\ | ||
76 | (void *) &(cf_sk)->flow_state) | ||
77 | #define SET_TX_FLOW_ON(cf_sk) set_bit(TX_FLOW_ON_BIT,\ | ||
78 | (void *) &(cf_sk)->flow_state) | ||
79 | |||
80 | #define SKT_READ_FLAG 0x01 | ||
81 | #define SKT_WRITE_FLAG 0x02 | ||
82 | static struct dentry *debugfsdir; | ||
83 | #include <linux/debugfs.h> | ||
84 | |||
85 | #ifdef CONFIG_DEBUG_FS | ||
86 | struct debug_fs_counter { | ||
87 | atomic_t num_open; | ||
88 | atomic_t num_close; | ||
89 | atomic_t num_init; | ||
90 | atomic_t num_init_resp; | ||
91 | atomic_t num_init_fail_resp; | ||
92 | atomic_t num_deinit; | ||
93 | atomic_t num_deinit_resp; | ||
94 | atomic_t num_remote_shutdown_ind; | ||
95 | atomic_t num_tx_flow_off_ind; | ||
96 | atomic_t num_tx_flow_on_ind; | ||
97 | atomic_t num_rx_flow_off; | ||
98 | atomic_t num_rx_flow_on; | ||
99 | atomic_t skb_in_use; | ||
100 | atomic_t skb_alloc; | ||
101 | atomic_t skb_free; | ||
102 | }; | ||
103 | static struct debug_fs_counter cnt; | ||
104 | #define dbfs_atomic_inc(v) atomic_inc(v) | ||
105 | #define dbfs_atomic_dec(v) atomic_dec(v) | ||
106 | #else | ||
107 | #define dbfs_atomic_inc(v) | ||
108 | #define dbfs_atomic_dec(v) | ||
109 | #endif | ||
110 | |||
111 | /* The AF_CAIF socket */ | ||
112 | struct caifsock { | ||
113 | /* NOTE: sk has to be the first member */ | ||
114 | struct sock sk; | ||
115 | struct cflayer layer; | ||
116 | char name[CAIF_LAYER_NAME_SZ]; | ||
117 | u32 conn_state; | ||
118 | u32 flow_state; | ||
119 | struct cfpktq *pktq; | ||
120 | int file_mode; | ||
121 | struct caif_connect_request conn_req; | ||
122 | int read_queue_len; | ||
123 | /* protect updates of read_queue_len */ | ||
124 | spinlock_t read_queue_len_lock; | ||
125 | struct dentry *debugfs_socket_dir; | ||
126 | }; | ||
127 | |||
128 | static void drain_queue(struct caifsock *cf_sk); | ||
129 | |||
130 | /* Packet Receive Callback function called from CAIF Stack */ | ||
131 | static int caif_sktrecv_cb(struct cflayer *layr, struct cfpkt *pkt) | ||
132 | { | ||
133 | struct caifsock *cf_sk; | ||
134 | int read_queue_high; | ||
135 | cf_sk = container_of(layr, struct caifsock, layer); | ||
136 | |||
137 | if (!STATE_IS_OPEN(cf_sk)) { | ||
138 | /*FIXME: This should be allowed finally!*/ | ||
139 | pr_debug("CAIF: %s(): called after close request\n", __func__); | ||
140 | cfpkt_destroy(pkt); | ||
141 | return 0; | ||
142 | } | ||
143 | /* NOTE: This function may be called in Tasklet context! */ | ||
144 | |||
145 | /* The queue has its own lock */ | ||
146 | cfpkt_queue(cf_sk->pktq, pkt, 0); | ||
147 | |||
148 | spin_lock(&cf_sk->read_queue_len_lock); | ||
149 | cf_sk->read_queue_len++; | ||
150 | |||
151 | read_queue_high = (cf_sk->read_queue_len > CHNL_SKT_READ_QUEUE_HIGH); | ||
152 | spin_unlock(&cf_sk->read_queue_len_lock); | ||
153 | |||
154 | if (RX_FLOW_IS_ON(cf_sk) && read_queue_high) { | ||
155 | dbfs_atomic_inc(&cnt.num_rx_flow_off); | ||
156 | SET_RX_FLOW_OFF(cf_sk); | ||
157 | |||
158 | /* Send flow off (NOTE: must not sleep) */ | ||
159 | pr_debug("CAIF: %s():" | ||
160 | " sending flow OFF (queue len = %d)\n", | ||
161 | __func__, | ||
162 | cf_sk->read_queue_len); | ||
163 | caif_assert(cf_sk->layer.dn); | ||
164 | caif_assert(cf_sk->layer.dn->ctrlcmd); | ||
165 | |||
166 | (void) cf_sk->layer.dn->modemcmd(cf_sk->layer.dn, | ||
167 | CAIF_MODEMCMD_FLOW_OFF_REQ); | ||
168 | } | ||
169 | |||
170 | /* Signal reader that data is available. */ | ||
171 | |||
172 | wake_up_interruptible(cf_sk->sk.sk_sleep); | ||
173 | |||
174 | return 0; | ||
175 | } | ||
176 | |||
177 | /* Packet Flow Control Callback function called from CAIF */ | ||
178 | static void caif_sktflowctrl_cb(struct cflayer *layr, | ||
179 | enum caif_ctrlcmd flow, | ||
180 | int phyid) | ||
181 | { | ||
182 | struct caifsock *cf_sk; | ||
183 | |||
184 | /* NOTE: This function may be called in Tasklet context! */ | ||
185 | pr_debug("CAIF: %s(): flowctrl func called: %s.\n", | ||
186 | __func__, | ||
187 | flow == CAIF_CTRLCMD_FLOW_ON_IND ? "ON" : | ||
188 | flow == CAIF_CTRLCMD_FLOW_OFF_IND ? "OFF" : | ||
189 | flow == CAIF_CTRLCMD_INIT_RSP ? "INIT_RSP" : | ||
190 | flow == CAIF_CTRLCMD_DEINIT_RSP ? "DEINIT_RSP" : | ||
191 | flow == CAIF_CTRLCMD_INIT_FAIL_RSP ? "INIT_FAIL_RSP" : | ||
192 | flow == | ||
193 | CAIF_CTRLCMD_REMOTE_SHUTDOWN_IND ? "REMOTE_SHUTDOWN" : | ||
194 | "UKNOWN CTRL COMMAND"); | ||
195 | |||
196 | if (layr == NULL) | ||
197 | return; | ||
198 | |||
199 | cf_sk = container_of(layr, struct caifsock, layer); | ||
200 | |||
201 | switch (flow) { | ||
202 | case CAIF_CTRLCMD_FLOW_ON_IND: | ||
203 | dbfs_atomic_inc(&cnt.num_tx_flow_on_ind); | ||
204 | /* Signal reader that data is available. */ | ||
205 | SET_TX_FLOW_ON(cf_sk); | ||
206 | wake_up_interruptible(cf_sk->sk.sk_sleep); | ||
207 | break; | ||
208 | |||
209 | case CAIF_CTRLCMD_FLOW_OFF_IND: | ||
210 | dbfs_atomic_inc(&cnt.num_tx_flow_off_ind); | ||
211 | SET_TX_FLOW_OFF(cf_sk); | ||
212 | break; | ||
213 | |||
214 | case CAIF_CTRLCMD_INIT_RSP: | ||
215 | dbfs_atomic_inc(&cnt.num_init_resp); | ||
216 | /* Signal reader that data is available. */ | ||
217 | caif_assert(STATE_IS_OPEN(cf_sk)); | ||
218 | SET_PENDING_OFF(cf_sk); | ||
219 | SET_TX_FLOW_ON(cf_sk); | ||
220 | wake_up_interruptible(cf_sk->sk.sk_sleep); | ||
221 | break; | ||
222 | |||
223 | case CAIF_CTRLCMD_DEINIT_RSP: | ||
224 | dbfs_atomic_inc(&cnt.num_deinit_resp); | ||
225 | caif_assert(!STATE_IS_OPEN(cf_sk)); | ||
226 | SET_PENDING_OFF(cf_sk); | ||
227 | if (!STATE_IS_PENDING_DESTROY(cf_sk)) { | ||
228 | if (cf_sk->sk.sk_sleep != NULL) | ||
229 | wake_up_interruptible(cf_sk->sk.sk_sleep); | ||
230 | } | ||
231 | dbfs_atomic_inc(&cnt.num_deinit); | ||
232 | sock_put(&cf_sk->sk); | ||
233 | break; | ||
234 | |||
235 | case CAIF_CTRLCMD_INIT_FAIL_RSP: | ||
236 | dbfs_atomic_inc(&cnt.num_init_fail_resp); | ||
237 | caif_assert(STATE_IS_OPEN(cf_sk)); | ||
238 | SET_STATE_CLOSED(cf_sk); | ||
239 | SET_PENDING_OFF(cf_sk); | ||
240 | SET_TX_FLOW_OFF(cf_sk); | ||
241 | wake_up_interruptible(cf_sk->sk.sk_sleep); | ||
242 | break; | ||
243 | |||
244 | case CAIF_CTRLCMD_REMOTE_SHUTDOWN_IND: | ||
245 | dbfs_atomic_inc(&cnt.num_remote_shutdown_ind); | ||
246 | SET_REMOTE_SHUTDOWN(cf_sk); | ||
247 | /* Use sk_shutdown to indicate remote shutdown indication */ | ||
248 | cf_sk->sk.sk_shutdown |= RCV_SHUTDOWN; | ||
249 | cf_sk->file_mode = 0; | ||
250 | wake_up_interruptible(cf_sk->sk.sk_sleep); | ||
251 | break; | ||
252 | |||
253 | default: | ||
254 | pr_debug("CAIF: %s(): Unexpected flow command %d\n", | ||
255 | __func__, flow); | ||
256 | } | ||
257 | } | ||
258 | |||
259 | static void skb_destructor(struct sk_buff *skb) | ||
260 | { | ||
261 | dbfs_atomic_inc(&cnt.skb_free); | ||
262 | dbfs_atomic_dec(&cnt.skb_in_use); | ||
263 | } | ||
264 | |||
265 | |||
266 | static int caif_recvmsg(struct kiocb *iocb, struct socket *sock, | ||
267 | struct msghdr *m, size_t buf_len, int flags) | ||
268 | |||
269 | { | ||
270 | struct sock *sk = sock->sk; | ||
271 | struct caifsock *cf_sk = container_of(sk, struct caifsock, sk); | ||
272 | struct cfpkt *pkt = NULL; | ||
273 | size_t len; | ||
274 | int result; | ||
275 | struct sk_buff *skb; | ||
276 | ssize_t ret = -EIO; | ||
277 | int read_queue_low; | ||
278 | |||
279 | if (cf_sk == NULL) { | ||
280 | pr_debug("CAIF: %s(): private_data not set!\n", | ||
281 | __func__); | ||
282 | ret = -EBADFD; | ||
283 | goto read_error; | ||
284 | } | ||
285 | |||
286 | /* Don't do multiple iovec entries yet */ | ||
287 | if (m->msg_iovlen != 1) | ||
288 | return -EOPNOTSUPP; | ||
289 | |||
290 | if (unlikely(!buf_len)) | ||
291 | return -EINVAL; | ||
292 | |||
293 | lock_sock(&(cf_sk->sk)); | ||
294 | |||
295 | caif_assert(cf_sk->pktq); | ||
296 | |||
297 | if (!STATE_IS_OPEN(cf_sk)) { | ||
298 | /* Socket is closed or closing. */ | ||
299 | if (!STATE_IS_PENDING(cf_sk)) { | ||
300 | pr_debug("CAIF: %s(): socket is closed (by remote)\n", | ||
301 | __func__); | ||
302 | ret = -EPIPE; | ||
303 | } else { | ||
304 | pr_debug("CAIF: %s(): socket is closing..\n", __func__); | ||
305 | ret = -EBADF; | ||
306 | } | ||
307 | goto read_error; | ||
308 | } | ||
309 | /* Socket is open or opening. */ | ||
310 | if (STATE_IS_PENDING(cf_sk)) { | ||
311 | pr_debug("CAIF: %s(): socket is opening...\n", __func__); | ||
312 | |||
313 | if (flags & MSG_DONTWAIT) { | ||
314 | /* We can't block. */ | ||
315 | pr_debug("CAIF: %s():state pending and MSG_DONTWAIT\n", | ||
316 | __func__); | ||
317 | ret = -EAGAIN; | ||
318 | goto read_error; | ||
319 | } | ||
320 | |||
321 | /* | ||
322 | * Blocking mode; state is pending and we need to wait | ||
323 | * for its conclusion. | ||
324 | */ | ||
325 | release_sock(&cf_sk->sk); | ||
326 | |||
327 | result = | ||
328 | wait_event_interruptible(*cf_sk->sk.sk_sleep, | ||
329 | !STATE_IS_PENDING(cf_sk)); | ||
330 | |||
331 | lock_sock(&(cf_sk->sk)); | ||
332 | |||
333 | if (result == -ERESTARTSYS) { | ||
334 | pr_debug("CAIF: %s(): wait_event_interruptible" | ||
335 | " woken by a signal (1)", __func__); | ||
336 | ret = -ERESTARTSYS; | ||
337 | goto read_error; | ||
338 | } | ||
339 | } | ||
340 | |||
341 | if (STATE_IS_REMOTE_SHUTDOWN(cf_sk) || | ||
342 | !STATE_IS_OPEN(cf_sk) || | ||
343 | STATE_IS_PENDING(cf_sk)) { | ||
344 | |||
345 | pr_debug("CAIF: %s(): socket closed\n", | ||
346 | __func__); | ||
347 | ret = -ESHUTDOWN; | ||
348 | goto read_error; | ||
349 | } | ||
350 | |||
351 | /* | ||
352 | * Block if we don't have any received buffers. | ||
353 | * The queue has its own lock. | ||
354 | */ | ||
355 | while ((pkt = cfpkt_qpeek(cf_sk->pktq)) == NULL) { | ||
356 | |||
357 | if (flags & MSG_DONTWAIT) { | ||
358 | pr_debug("CAIF: %s(): MSG_DONTWAIT\n", __func__); | ||
359 | ret = -EAGAIN; | ||
360 | goto read_error; | ||
361 | } | ||
362 | trace_printk("CAIF: %s() wait_event\n", __func__); | ||
363 | |||
364 | /* Let writers in. */ | ||
365 | release_sock(&cf_sk->sk); | ||
366 | |||
367 | /* Block reader until data arrives or socket is closed. */ | ||
368 | if (wait_event_interruptible(*cf_sk->sk.sk_sleep, | ||
369 | cfpkt_qpeek(cf_sk->pktq) | ||
370 | || STATE_IS_REMOTE_SHUTDOWN(cf_sk) | ||
371 | || !STATE_IS_OPEN(cf_sk)) == | ||
372 | -ERESTARTSYS) { | ||
373 | pr_debug("CAIF: %s():" | ||
374 | " wait_event_interruptible woken by " | ||
375 | "a signal, signal_pending(current) = %d\n", | ||
376 | __func__, | ||
377 | signal_pending(current)); | ||
378 | return -ERESTARTSYS; | ||
379 | } | ||
380 | |||
381 | trace_printk("CAIF: %s() awake\n", __func__); | ||
382 | if (STATE_IS_REMOTE_SHUTDOWN(cf_sk)) { | ||
383 | pr_debug("CAIF: %s(): " | ||
384 | "received remote_shutdown indication\n", | ||
385 | __func__); | ||
386 | ret = -ESHUTDOWN; | ||
387 | goto read_error_no_unlock; | ||
388 | } | ||
389 | |||
390 | /* I want to be alone on cf_sk (except status and queue). */ | ||
391 | lock_sock(&(cf_sk->sk)); | ||
392 | |||
393 | if (!STATE_IS_OPEN(cf_sk)) { | ||
394 | /* Someone closed the link, report error. */ | ||
395 | pr_debug("CAIF: %s(): remote end shutdown!\n", | ||
396 | __func__); | ||
397 | ret = -EPIPE; | ||
398 | goto read_error; | ||
399 | } | ||
400 | } | ||
401 | |||
402 | /* The queue has its own lock. */ | ||
403 | len = cfpkt_getlen(pkt); | ||
404 | |||
405 | /* Check max length that can be copied. */ | ||
406 | if (len <= buf_len) | ||
407 | pkt = cfpkt_dequeue(cf_sk->pktq); | ||
408 | else { | ||
409 | pr_debug("CAIF: %s(): user buffer too small (%ld,%ld)\n", | ||
410 | __func__, (long) len, (long) buf_len); | ||
411 | if (sock->type == SOCK_SEQPACKET) { | ||
412 | ret = -EMSGSIZE; | ||
413 | goto read_error; | ||
414 | } | ||
415 | len = buf_len; | ||
416 | } | ||
417 | |||
418 | |||
419 | spin_lock(&cf_sk->read_queue_len_lock); | ||
420 | cf_sk->read_queue_len--; | ||
421 | read_queue_low = (cf_sk->read_queue_len < CHNL_SKT_READ_QUEUE_LOW); | ||
422 | spin_unlock(&cf_sk->read_queue_len_lock); | ||
423 | |||
424 | if (!RX_FLOW_IS_ON(cf_sk) && read_queue_low) { | ||
425 | dbfs_atomic_inc(&cnt.num_rx_flow_on); | ||
426 | SET_RX_FLOW_ON(cf_sk); | ||
427 | |||
428 | /* Send flow on. */ | ||
429 | pr_debug("CAIF: %s(): sending flow ON (queue len = %d)\n", | ||
430 | __func__, cf_sk->read_queue_len); | ||
431 | caif_assert(cf_sk->layer.dn); | ||
432 | caif_assert(cf_sk->layer.dn->ctrlcmd); | ||
433 | (void) cf_sk->layer.dn->modemcmd(cf_sk->layer.dn, | ||
434 | CAIF_MODEMCMD_FLOW_ON_REQ); | ||
435 | |||
436 | caif_assert(cf_sk->read_queue_len >= 0); | ||
437 | } | ||
438 | |||
439 | skb = cfpkt_tonative(pkt); | ||
440 | result = skb_copy_datagram_iovec(skb, 0, m->msg_iov, len); | ||
441 | skb_pull(skb, len); | ||
442 | |||
443 | if (result) { | ||
444 | pr_debug("CAIF: %s(): copy to_iovec failed\n", __func__); | ||
445 | cfpkt_destroy(pkt); | ||
446 | ret = -EFAULT; | ||
447 | goto read_error; | ||
448 | } | ||
449 | |||
450 | /* Free packet and remove from queue */ | ||
451 | if (skb->len == 0) | ||
452 | skb_free_datagram(sk, skb); | ||
453 | |||
454 | /* Let the others in. */ | ||
455 | release_sock(&cf_sk->sk); | ||
456 | return len; | ||
457 | |||
458 | read_error: | ||
459 | release_sock(&cf_sk->sk); | ||
460 | read_error_no_unlock: | ||
461 | return ret; | ||
462 | } | ||
463 | |||
464 | /* Send a signal as a consequence of sendmsg, sendto or caif_sendmsg. */ | ||
465 | static int caif_sendmsg(struct kiocb *kiocb, struct socket *sock, | ||
466 | struct msghdr *msg, size_t len) | ||
467 | { | ||
468 | |||
469 | struct sock *sk = sock->sk; | ||
470 | struct caifsock *cf_sk = container_of(sk, struct caifsock, sk); | ||
471 | size_t payload_size = msg->msg_iov->iov_len; | ||
472 | struct cfpkt *pkt = NULL; | ||
473 | struct caif_payload_info info; | ||
474 | unsigned char *txbuf; | ||
475 | ssize_t ret = -EIO; | ||
476 | int result; | ||
477 | struct sk_buff *skb; | ||
478 | caif_assert(msg->msg_iovlen == 1); | ||
479 | |||
480 | if (cf_sk == NULL) { | ||
481 | pr_debug("CAIF: %s(): private_data not set!\n", | ||
482 | __func__); | ||
483 | ret = -EBADFD; | ||
484 | goto write_error_no_unlock; | ||
485 | } | ||
486 | |||
487 | if (unlikely(msg->msg_iov->iov_base == NULL)) { | ||
488 | pr_warning("CAIF: %s(): Buffer is NULL.\n", __func__); | ||
489 | ret = -EINVAL; | ||
490 | goto write_error_no_unlock; | ||
491 | } | ||
492 | |||
493 | if (payload_size > CAIF_MAX_PAYLOAD_SIZE) { | ||
494 | pr_debug("CAIF: %s(): buffer too long\n", __func__); | ||
495 | if (sock->type == SOCK_SEQPACKET) { | ||
496 | ret = -EINVAL; | ||
497 | goto write_error_no_unlock; | ||
498 | } | ||
499 | payload_size = CAIF_MAX_PAYLOAD_SIZE; | ||
500 | } | ||
501 | |||
502 | /* I want to be alone on cf_sk (except status and queue) */ | ||
503 | lock_sock(&(cf_sk->sk)); | ||
504 | |||
505 | caif_assert(cf_sk->pktq); | ||
506 | |||
507 | if (!STATE_IS_OPEN(cf_sk)) { | ||
508 | /* Socket is closed or closing */ | ||
509 | if (!STATE_IS_PENDING(cf_sk)) { | ||
510 | pr_debug("CAIF: %s(): socket is closed (by remote)\n", | ||
511 | __func__); | ||
512 | ret = -EPIPE; | ||
513 | } else { | ||
514 | pr_debug("CAIF: %s(): socket is closing...\n", | ||
515 | __func__); | ||
516 | ret = -EBADF; | ||
517 | } | ||
518 | goto write_error; | ||
519 | } | ||
520 | |||
521 | /* Socket is open or opening */ | ||
522 | if (STATE_IS_PENDING(cf_sk)) { | ||
523 | pr_debug("CAIF: %s(): socket is opening...\n", __func__); | ||
524 | |||
525 | if (msg->msg_flags & MSG_DONTWAIT) { | ||
526 | /* We can't block */ | ||
527 | trace_printk("CAIF: %s():state pending:" | ||
528 | "state=MSG_DONTWAIT\n", __func__); | ||
529 | ret = -EAGAIN; | ||
530 | goto write_error; | ||
531 | } | ||
532 | /* Let readers in */ | ||
533 | release_sock(&cf_sk->sk); | ||
534 | |||
535 | /* | ||
536 | * Blocking mode; state is pending and we need to wait | ||
537 | * for its conclusion. | ||
538 | */ | ||
539 | result = | ||
540 | wait_event_interruptible(*cf_sk->sk.sk_sleep, | ||
541 | !STATE_IS_PENDING(cf_sk)); | ||
542 | /* I want to be alone on cf_sk (except status and queue) */ | ||
543 | lock_sock(&(cf_sk->sk)); | ||
544 | |||
545 | if (result == -ERESTARTSYS) { | ||
546 | pr_debug("CAIF: %s(): wait_event_interruptible" | ||
547 | " woken by a signal (1)", __func__); | ||
548 | ret = -ERESTARTSYS; | ||
549 | goto write_error; | ||
550 | } | ||
551 | } | ||
552 | if (STATE_IS_REMOTE_SHUTDOWN(cf_sk) || | ||
553 | !STATE_IS_OPEN(cf_sk) || | ||
554 | STATE_IS_PENDING(cf_sk)) { | ||
555 | |||
556 | pr_debug("CAIF: %s(): socket closed\n", | ||
557 | __func__); | ||
558 | ret = -ESHUTDOWN; | ||
559 | goto write_error; | ||
560 | } | ||
561 | |||
562 | if (!TX_FLOW_IS_ON(cf_sk)) { | ||
563 | |||
564 | /* Flow is off. Check non-block flag */ | ||
565 | if (msg->msg_flags & MSG_DONTWAIT) { | ||
566 | trace_printk("CAIF: %s(): MSG_DONTWAIT and tx flow off", | ||
567 | __func__); | ||
568 | ret = -EAGAIN; | ||
569 | goto write_error; | ||
570 | } | ||
571 | |||
572 | /* release lock before waiting */ | ||
573 | release_sock(&cf_sk->sk); | ||
574 | |||
575 | /* Wait until flow is on or socket is closed */ | ||
576 | if (wait_event_interruptible(*cf_sk->sk.sk_sleep, | ||
577 | TX_FLOW_IS_ON(cf_sk) | ||
578 | || !STATE_IS_OPEN(cf_sk) | ||
579 | || STATE_IS_REMOTE_SHUTDOWN(cf_sk) | ||
580 | ) == -ERESTARTSYS) { | ||
581 | pr_debug("CAIF: %s():" | ||
582 | " wait_event_interruptible woken by a signal", | ||
583 | __func__); | ||
584 | ret = -ERESTARTSYS; | ||
585 | goto write_error_no_unlock; | ||
586 | } | ||
587 | |||
588 | /* I want to be alone on cf_sk (except status and queue) */ | ||
589 | lock_sock(&(cf_sk->sk)); | ||
590 | |||
591 | if (!STATE_IS_OPEN(cf_sk)) { | ||
592 | /* someone closed the link, report error */ | ||
593 | pr_debug("CAIF: %s(): remote end shutdown!\n", | ||
594 | __func__); | ||
595 | ret = -EPIPE; | ||
596 | goto write_error; | ||
597 | } | ||
598 | |||
599 | if (STATE_IS_REMOTE_SHUTDOWN(cf_sk)) { | ||
600 | pr_debug("CAIF: %s(): " | ||
601 | "received remote_shutdown indication\n", | ||
602 | __func__); | ||
603 | ret = -ESHUTDOWN; | ||
604 | goto write_error; | ||
605 | } | ||
606 | } | ||
607 | |||
608 | pkt = cfpkt_create(payload_size); | ||
609 | skb = (struct sk_buff *)pkt; | ||
610 | skb->destructor = skb_destructor; | ||
611 | skb->sk = sk; | ||
612 | dbfs_atomic_inc(&cnt.skb_alloc); | ||
613 | dbfs_atomic_inc(&cnt.skb_in_use); | ||
614 | if (cfpkt_raw_append(pkt, (void **) &txbuf, payload_size) < 0) { | ||
615 | pr_debug("CAIF: %s(): cfpkt_raw_append failed\n", __func__); | ||
616 | cfpkt_destroy(pkt); | ||
617 | ret = -EINVAL; | ||
618 | goto write_error; | ||
619 | } | ||
620 | |||
621 | /* Copy data into buffer. */ | ||
622 | if (copy_from_user(txbuf, msg->msg_iov->iov_base, payload_size)) { | ||
623 | pr_debug("CAIF: %s(): copy_from_user returned non zero.\n", | ||
624 | __func__); | ||
625 | cfpkt_destroy(pkt); | ||
626 | ret = -EINVAL; | ||
627 | goto write_error; | ||
628 | } | ||
629 | memset(&info, 0, sizeof(info)); | ||
630 | |||
631 | /* Send the packet down the stack. */ | ||
632 | caif_assert(cf_sk->layer.dn); | ||
633 | caif_assert(cf_sk->layer.dn->transmit); | ||
634 | |||
635 | do { | ||
636 | ret = cf_sk->layer.dn->transmit(cf_sk->layer.dn, pkt); | ||
637 | |||
638 | if (likely((ret >= 0) || (ret != -EAGAIN))) | ||
639 | break; | ||
640 | |||
641 | /* EAGAIN - retry */ | ||
642 | if (msg->msg_flags & MSG_DONTWAIT) { | ||
643 | pr_debug("CAIF: %s(): NONBLOCK and transmit failed," | ||
644 | " error = %ld\n", __func__, (long) ret); | ||
645 | ret = -EAGAIN; | ||
646 | goto write_error; | ||
647 | } | ||
648 | |||
649 | /* Let readers in */ | ||
650 | release_sock(&cf_sk->sk); | ||
651 | |||
652 | /* Wait until flow is on or socket is closed */ | ||
653 | if (wait_event_interruptible(*cf_sk->sk.sk_sleep, | ||
654 | TX_FLOW_IS_ON(cf_sk) | ||
655 | || !STATE_IS_OPEN(cf_sk) | ||
656 | || STATE_IS_REMOTE_SHUTDOWN(cf_sk) | ||
657 | ) == -ERESTARTSYS) { | ||
658 | pr_debug("CAIF: %s(): wait_event_interruptible" | ||
659 | " woken by a signal", __func__); | ||
660 | ret = -ERESTARTSYS; | ||
661 | goto write_error_no_unlock; | ||
662 | } | ||
663 | |||
664 | /* I want to be alone on cf_sk (except status and queue) */ | ||
665 | lock_sock(&(cf_sk->sk)); | ||
666 | |||
667 | } while (ret == -EAGAIN); | ||
668 | |||
669 | if (ret < 0) { | ||
670 | cfpkt_destroy(pkt); | ||
671 | pr_debug("CAIF: %s(): transmit failed, error = %ld\n", | ||
672 | __func__, (long) ret); | ||
673 | |||
674 | goto write_error; | ||
675 | } | ||
676 | |||
677 | release_sock(&cf_sk->sk); | ||
678 | return payload_size; | ||
679 | |||
680 | write_error: | ||
681 | release_sock(&cf_sk->sk); | ||
682 | write_error_no_unlock: | ||
683 | return ret; | ||
684 | } | ||
685 | |||
686 | static unsigned int caif_poll(struct file *file, struct socket *sock, | ||
687 | poll_table *wait) | ||
688 | { | ||
689 | struct sock *sk = sock->sk; | ||
690 | struct caifsock *cf_sk = container_of(sk, struct caifsock, sk); | ||
691 | u32 mask = 0; | ||
692 | poll_wait(file, sk->sk_sleep, wait); | ||
693 | lock_sock(&(cf_sk->sk)); | ||
694 | if (!STATE_IS_OPEN(cf_sk)) { | ||
695 | if (!STATE_IS_PENDING(cf_sk)) | ||
696 | mask |= POLLHUP; | ||
697 | } else { | ||
698 | if (cfpkt_qpeek(cf_sk->pktq) != NULL) | ||
699 | mask |= (POLLIN | POLLRDNORM); | ||
700 | if (TX_FLOW_IS_ON(cf_sk)) | ||
701 | mask |= (POLLOUT | POLLWRNORM); | ||
702 | } | ||
703 | release_sock(&cf_sk->sk); | ||
704 | trace_printk("CAIF: %s(): poll mask=0x%04x\n", | ||
705 | __func__, mask); | ||
706 | return mask; | ||
707 | } | ||
708 | |||
709 | static void drain_queue(struct caifsock *cf_sk) | ||
710 | { | ||
711 | struct cfpkt *pkt = NULL; | ||
712 | |||
713 | /* Empty the queue */ | ||
714 | do { | ||
715 | /* The queue has its own lock */ | ||
716 | if (!cf_sk->pktq) | ||
717 | break; | ||
718 | |||
719 | pkt = cfpkt_dequeue(cf_sk->pktq); | ||
720 | if (!pkt) | ||
721 | break; | ||
722 | pr_debug("CAIF: %s(): freeing packet from read queue\n", | ||
723 | __func__); | ||
724 | cfpkt_destroy(pkt); | ||
725 | |||
726 | } while (1); | ||
727 | |||
728 | cf_sk->read_queue_len = 0; | ||
729 | } | ||
730 | |||
731 | static int setsockopt(struct socket *sock, | ||
732 | int lvl, int opt, char __user *ov, unsigned int ol) | ||
733 | { | ||
734 | struct sock *sk = sock->sk; | ||
735 | struct caifsock *cf_sk = container_of(sk, struct caifsock, sk); | ||
736 | int prio, linksel; | ||
737 | struct ifreq ifreq; | ||
738 | |||
739 | if (STATE_IS_OPEN(cf_sk)) { | ||
740 | pr_debug("CAIF: %s(): setsockopt " | ||
741 | "cannot be done on a connected socket\n", | ||
742 | __func__); | ||
743 | return -ENOPROTOOPT; | ||
744 | } | ||
745 | switch (opt) { | ||
746 | case CAIFSO_LINK_SELECT: | ||
747 | if (ol < sizeof(int)) { | ||
748 | pr_debug("CAIF: %s(): setsockopt" | ||
749 | " CAIFSO_CHANNEL_CONFIG bad size\n", __func__); | ||
750 | return -EINVAL; | ||
751 | } | ||
752 | if (lvl != SOL_CAIF) | ||
753 | goto bad_sol; | ||
754 | if (copy_from_user(&linksel, ov, sizeof(int))) | ||
755 | return -EINVAL; | ||
756 | lock_sock(&(cf_sk->sk)); | ||
757 | cf_sk->conn_req.link_selector = linksel; | ||
758 | release_sock(&cf_sk->sk); | ||
759 | return 0; | ||
760 | |||
761 | case SO_PRIORITY: | ||
762 | if (lvl != SOL_SOCKET) | ||
763 | goto bad_sol; | ||
764 | if (ol < sizeof(int)) { | ||
765 | pr_debug("CAIF: %s(): setsockopt" | ||
766 | " SO_PRIORITY bad size\n", __func__); | ||
767 | return -EINVAL; | ||
768 | } | ||
769 | if (copy_from_user(&prio, ov, sizeof(int))) | ||
770 | return -EINVAL; | ||
771 | lock_sock(&(cf_sk->sk)); | ||
772 | cf_sk->conn_req.priority = prio; | ||
773 | pr_debug("CAIF: %s(): Setting sockopt priority=%d\n", __func__, | ||
774 | cf_sk->conn_req.priority); | ||
775 | release_sock(&cf_sk->sk); | ||
776 | return 0; | ||
777 | |||
778 | case SO_BINDTODEVICE: | ||
779 | if (lvl != SOL_SOCKET) | ||
780 | goto bad_sol; | ||
781 | if (ol < sizeof(struct ifreq)) { | ||
782 | pr_debug("CAIF: %s(): setsockopt" | ||
783 | " SO_PRIORITY bad size\n", __func__); | ||
784 | return -EINVAL; | ||
785 | } | ||
786 | if (copy_from_user(&ifreq, ov, sizeof(ifreq))) | ||
787 | return -EFAULT; | ||
788 | lock_sock(&(cf_sk->sk)); | ||
789 | strncpy(cf_sk->conn_req.link_name, ifreq.ifr_name, | ||
790 | sizeof(cf_sk->conn_req.link_name)); | ||
791 | cf_sk->conn_req.link_name | ||
792 | [sizeof(cf_sk->conn_req.link_name)-1] = 0; | ||
793 | release_sock(&cf_sk->sk); | ||
794 | return 0; | ||
795 | |||
796 | case CAIFSO_REQ_PARAM: | ||
797 | if (lvl != SOL_CAIF) | ||
798 | goto bad_sol; | ||
799 | if (cf_sk->sk.sk_protocol != CAIFPROTO_UTIL) | ||
800 | return -ENOPROTOOPT; | ||
801 | if (ol > sizeof(cf_sk->conn_req.param.data)) | ||
802 | goto req_param_bad_size; | ||
803 | |||
804 | lock_sock(&(cf_sk->sk)); | ||
805 | cf_sk->conn_req.param.size = ol; | ||
806 | if (copy_from_user(&cf_sk->conn_req.param.data, ov, ol)) { | ||
807 | release_sock(&cf_sk->sk); | ||
808 | req_param_bad_size: | ||
809 | pr_debug("CAIF: %s(): setsockopt" | ||
810 | " CAIFSO_CHANNEL_CONFIG bad size\n", __func__); | ||
811 | return -EINVAL; | ||
812 | } | ||
813 | |||
814 | release_sock(&cf_sk->sk); | ||
815 | return 0; | ||
816 | |||
817 | default: | ||
818 | pr_debug("CAIF: %s(): unhandled option %d\n", __func__, opt); | ||
819 | return -EINVAL; | ||
820 | } | ||
821 | |||
822 | return 0; | ||
823 | bad_sol: | ||
824 | pr_debug("CAIF: %s(): setsockopt bad level\n", __func__); | ||
825 | return -ENOPROTOOPT; | ||
826 | |||
827 | } | ||
828 | |||
829 | static int caif_connect(struct socket *sock, struct sockaddr *uservaddr, | ||
830 | int sockaddr_len, int flags) | ||
831 | { | ||
832 | struct caifsock *cf_sk = NULL; | ||
833 | int result = -1; | ||
834 | int mode = 0; | ||
835 | int ret = -EIO; | ||
836 | struct sock *sk = sock->sk; | ||
837 | BUG_ON(sk == NULL); | ||
838 | |||
839 | cf_sk = container_of(sk, struct caifsock, sk); | ||
840 | |||
841 | trace_printk("CAIF: %s(): cf_sk=%p OPEN=%d, TX_FLOW=%d, RX_FLOW=%d\n", | ||
842 | __func__, cf_sk, | ||
843 | STATE_IS_OPEN(cf_sk), | ||
844 | TX_FLOW_IS_ON(cf_sk), RX_FLOW_IS_ON(cf_sk)); | ||
845 | |||
846 | |||
847 | if (sock->type == SOCK_SEQPACKET || sock->type == SOCK_STREAM) | ||
848 | sock->state = SS_CONNECTING; | ||
849 | else | ||
850 | goto out; | ||
851 | |||
852 | /* I want to be alone on cf_sk (except status and queue) */ | ||
853 | lock_sock(&(cf_sk->sk)); | ||
854 | |||
855 | if (sockaddr_len != sizeof(struct sockaddr_caif)) { | ||
856 | pr_debug("CAIF: %s(): Bad address len (%ld,%lu)\n", | ||
857 | __func__, (long) sockaddr_len, | ||
858 | (long unsigned) sizeof(struct sockaddr_caif)); | ||
859 | ret = -EINVAL; | ||
860 | goto open_error; | ||
861 | } | ||
862 | |||
863 | if (uservaddr->sa_family != AF_CAIF) { | ||
864 | pr_debug("CAIF: %s(): Bad address family (%d)\n", | ||
865 | __func__, uservaddr->sa_family); | ||
866 | ret = -EAFNOSUPPORT; | ||
867 | goto open_error; | ||
868 | } | ||
869 | |||
870 | memcpy(&cf_sk->conn_req.sockaddr, uservaddr, | ||
871 | sizeof(struct sockaddr_caif)); | ||
872 | |||
873 | dbfs_atomic_inc(&cnt.num_open); | ||
874 | mode = SKT_READ_FLAG | SKT_WRITE_FLAG; | ||
875 | |||
876 | /* If socket is not open, make sure socket is in fully closed state */ | ||
877 | if (!STATE_IS_OPEN(cf_sk)) { | ||
878 | /* Has link close response been received (if we ever sent it)?*/ | ||
879 | if (STATE_IS_PENDING(cf_sk)) { | ||
880 | /* | ||
881 | * Still waiting for close response from remote. | ||
882 | * If opened non-blocking, report "would block" | ||
883 | */ | ||
884 | if (flags & O_NONBLOCK) { | ||
885 | pr_debug("CAIF: %s(): O_NONBLOCK" | ||
886 | " && close pending\n", __func__); | ||
887 | ret = -EAGAIN; | ||
888 | goto open_error; | ||
889 | } | ||
890 | |||
891 | pr_debug("CAIF: %s(): Wait for close response" | ||
892 | " from remote...\n", __func__); | ||
893 | |||
894 | release_sock(&cf_sk->sk); | ||
895 | |||
896 | /* | ||
897 | * Blocking mode; close is pending and we need to wait | ||
898 | * for its conclusion. | ||
899 | */ | ||
900 | result = | ||
901 | wait_event_interruptible(*cf_sk->sk.sk_sleep, | ||
902 | !STATE_IS_PENDING(cf_sk)); | ||
903 | |||
904 | lock_sock(&(cf_sk->sk)); | ||
905 | if (result == -ERESTARTSYS) { | ||
906 | pr_debug("CAIF: %s(): wait_event_interruptible" | ||
907 | "woken by a signal (1)", __func__); | ||
908 | ret = -ERESTARTSYS; | ||
909 | goto open_error; | ||
910 | } | ||
911 | } | ||
912 | } | ||
913 | |||
914 | /* socket is now either closed, pending open or open */ | ||
915 | if (STATE_IS_OPEN(cf_sk) && !STATE_IS_PENDING(cf_sk)) { | ||
916 | /* Open */ | ||
917 | pr_debug("CAIF: %s(): Socket is already opened (cf_sk=%p)" | ||
918 | " check access f_flags = 0x%x file_mode = 0x%x\n", | ||
919 | __func__, cf_sk, mode, cf_sk->file_mode); | ||
920 | |||
921 | } else { | ||
922 | /* We are closed or pending open. | ||
923 | * If closed: send link setup | ||
924 | * If pending open: link setup already sent (we could have been | ||
925 | * interrupted by a signal last time) | ||
926 | */ | ||
927 | if (!STATE_IS_OPEN(cf_sk)) { | ||
928 | /* First opening of file; connect lower layers: */ | ||
929 | /* Drain queue (very unlikely) */ | ||
930 | drain_queue(cf_sk); | ||
931 | |||
932 | cf_sk->layer.receive = caif_sktrecv_cb; | ||
933 | SET_STATE_OPEN(cf_sk); | ||
934 | SET_PENDING_ON(cf_sk); | ||
935 | |||
936 | /* Register this channel. */ | ||
937 | result = | ||
938 | caif_connect_client(&cf_sk->conn_req, | ||
939 | &cf_sk->layer); | ||
940 | if (result < 0) { | ||
941 | pr_debug("CAIF: %s(): can't register channel\n", | ||
942 | __func__); | ||
943 | ret = -EIO; | ||
944 | SET_STATE_CLOSED(cf_sk); | ||
945 | SET_PENDING_OFF(cf_sk); | ||
946 | goto open_error; | ||
947 | } | ||
948 | dbfs_atomic_inc(&cnt.num_init); | ||
949 | } | ||
950 | |||
951 | /* If opened non-blocking, report "success". | ||
952 | */ | ||
953 | if (flags & O_NONBLOCK) { | ||
954 | pr_debug("CAIF: %s(): O_NONBLOCK success\n", | ||
955 | __func__); | ||
956 | ret = -EINPROGRESS; | ||
957 | cf_sk->sk.sk_err = -EINPROGRESS; | ||
958 | goto open_error; | ||
959 | } | ||
960 | |||
961 | trace_printk("CAIF: %s(): Wait for connect response\n", | ||
962 | __func__); | ||
963 | |||
964 | /* release lock before waiting */ | ||
965 | release_sock(&cf_sk->sk); | ||
966 | |||
967 | result = | ||
968 | wait_event_interruptible(*cf_sk->sk.sk_sleep, | ||
969 | !STATE_IS_PENDING(cf_sk)); | ||
970 | |||
971 | lock_sock(&(cf_sk->sk)); | ||
972 | |||
973 | if (result == -ERESTARTSYS) { | ||
974 | pr_debug("CAIF: %s(): wait_event_interruptible" | ||
975 | "woken by a signal (2)", __func__); | ||
976 | ret = -ERESTARTSYS; | ||
977 | goto open_error; | ||
978 | } | ||
979 | |||
980 | if (!STATE_IS_OPEN(cf_sk)) { | ||
981 | /* Lower layers said "no" */ | ||
982 | pr_debug("CAIF: %s(): Closed received\n", __func__); | ||
983 | ret = -EPIPE; | ||
984 | goto open_error; | ||
985 | } | ||
986 | |||
987 | trace_printk("CAIF: %s(): Connect received\n", __func__); | ||
988 | } | ||
989 | /* Open is ok */ | ||
990 | cf_sk->file_mode |= mode; | ||
991 | |||
992 | trace_printk("CAIF: %s(): Connected - file mode = %x\n", | ||
993 | __func__, cf_sk->file_mode); | ||
994 | |||
995 | release_sock(&cf_sk->sk); | ||
996 | return 0; | ||
997 | open_error: | ||
998 | sock->state = SS_UNCONNECTED; | ||
999 | release_sock(&cf_sk->sk); | ||
1000 | out: | ||
1001 | return ret; | ||
1002 | } | ||
1003 | |||
1004 | static int caif_shutdown(struct socket *sock, int how) | ||
1005 | { | ||
1006 | struct caifsock *cf_sk = NULL; | ||
1007 | int result = 0; | ||
1008 | int tx_flow_state_was_on; | ||
1009 | struct sock *sk = sock->sk; | ||
1010 | |||
1011 | trace_printk("CAIF: %s(): enter\n", __func__); | ||
1012 | pr_debug("f_flags=%x\n", sock->file->f_flags); | ||
1013 | |||
1014 | if (how != SHUT_RDWR) | ||
1015 | return -EOPNOTSUPP; | ||
1016 | |||
1017 | cf_sk = container_of(sk, struct caifsock, sk); | ||
1018 | if (cf_sk == NULL) { | ||
1019 | pr_debug("CAIF: %s(): COULD NOT FIND SOCKET\n", __func__); | ||
1020 | return -EBADF; | ||
1021 | } | ||
1022 | |||
1023 | /* I want to be alone on cf_sk (except status queue) */ | ||
1024 | lock_sock(&(cf_sk->sk)); | ||
1025 | sock_hold(&cf_sk->sk); | ||
1026 | |||
1027 | /* IS_CLOSED have double meaning: | ||
1028 | * 1) Spontanous Remote Shutdown Request. | ||
1029 | * 2) Ack on a channel teardown(disconnect) | ||
1030 | * Must clear bit in case we previously received | ||
1031 | * remote shudown request. | ||
1032 | */ | ||
1033 | if (STATE_IS_OPEN(cf_sk) && !STATE_IS_PENDING(cf_sk)) { | ||
1034 | SET_STATE_CLOSED(cf_sk); | ||
1035 | SET_PENDING_ON(cf_sk); | ||
1036 | tx_flow_state_was_on = TX_FLOW_IS_ON(cf_sk); | ||
1037 | SET_TX_FLOW_OFF(cf_sk); | ||
1038 | |||
1039 | /* Hold the socket until DEINIT_RSP is received */ | ||
1040 | sock_hold(&cf_sk->sk); | ||
1041 | result = caif_disconnect_client(&cf_sk->layer); | ||
1042 | |||
1043 | if (result < 0) { | ||
1044 | pr_debug("CAIF: %s(): " | ||
1045 | "caif_disconnect_client() failed\n", | ||
1046 | __func__); | ||
1047 | SET_STATE_CLOSED(cf_sk); | ||
1048 | SET_PENDING_OFF(cf_sk); | ||
1049 | SET_TX_FLOW_OFF(cf_sk); | ||
1050 | release_sock(&cf_sk->sk); | ||
1051 | sock_put(&cf_sk->sk); | ||
1052 | return -EIO; | ||
1053 | } | ||
1054 | |||
1055 | } | ||
1056 | if (STATE_IS_REMOTE_SHUTDOWN(cf_sk)) { | ||
1057 | SET_PENDING_OFF(cf_sk); | ||
1058 | SET_REMOTE_SHUTDOWN_OFF(cf_sk); | ||
1059 | } | ||
1060 | |||
1061 | /* | ||
1062 | * Socket is no longer in state pending close, | ||
1063 | * and we can release the reference. | ||
1064 | */ | ||
1065 | |||
1066 | dbfs_atomic_inc(&cnt.num_close); | ||
1067 | drain_queue(cf_sk); | ||
1068 | SET_RX_FLOW_ON(cf_sk); | ||
1069 | cf_sk->file_mode = 0; | ||
1070 | sock_put(&cf_sk->sk); | ||
1071 | release_sock(&cf_sk->sk); | ||
1072 | if (!result && (sock->file->f_flags & O_NONBLOCK)) { | ||
1073 | pr_debug("nonblocking shutdown returing -EAGAIN\n"); | ||
1074 | return -EAGAIN; | ||
1075 | } else | ||
1076 | return result; | ||
1077 | } | ||
1078 | |||
1079 | static ssize_t caif_sock_no_sendpage(struct socket *sock, | ||
1080 | struct page *page, | ||
1081 | int offset, size_t size, int flags) | ||
1082 | { | ||
1083 | return -EOPNOTSUPP; | ||
1084 | } | ||
1085 | |||
1086 | /* This function is called as part of close. */ | ||
1087 | static int caif_release(struct socket *sock) | ||
1088 | { | ||
1089 | struct sock *sk = sock->sk; | ||
1090 | struct caifsock *cf_sk = NULL; | ||
1091 | int res; | ||
1092 | caif_assert(sk != NULL); | ||
1093 | cf_sk = container_of(sk, struct caifsock, sk); | ||
1094 | |||
1095 | if (cf_sk->debugfs_socket_dir != NULL) | ||
1096 | debugfs_remove_recursive(cf_sk->debugfs_socket_dir); | ||
1097 | |||
1098 | res = caif_shutdown(sock, SHUT_RDWR); | ||
1099 | if (res && res != -EINPROGRESS) | ||
1100 | return res; | ||
1101 | |||
1102 | /* | ||
1103 | * FIXME: Shutdown should probably be possible to do async | ||
1104 | * without flushing queues, allowing reception of frames while | ||
1105 | * waiting for DEINIT_IND. | ||
1106 | * Release should always block, to allow secure decoupling of | ||
1107 | * CAIF stack. | ||
1108 | */ | ||
1109 | if (!(sock->file->f_flags & O_NONBLOCK)) { | ||
1110 | res = wait_event_interruptible(*cf_sk->sk.sk_sleep, | ||
1111 | !STATE_IS_PENDING(cf_sk)); | ||
1112 | |||
1113 | if (res == -ERESTARTSYS) { | ||
1114 | pr_debug("CAIF: %s(): wait_event_interruptible" | ||
1115 | "woken by a signal (1)", __func__); | ||
1116 | } | ||
1117 | } | ||
1118 | lock_sock(&(cf_sk->sk)); | ||
1119 | |||
1120 | sock->sk = NULL; | ||
1121 | |||
1122 | /* Detach the socket from its process context by making it orphan. */ | ||
1123 | sock_orphan(sk); | ||
1124 | |||
1125 | /* | ||
1126 | * Setting SHUTDOWN_MASK means that both send and receive are shutdown | ||
1127 | * for the socket. | ||
1128 | */ | ||
1129 | sk->sk_shutdown = SHUTDOWN_MASK; | ||
1130 | |||
1131 | /* | ||
1132 | * Set the socket state to closed, the TCP_CLOSE macro is used when | ||
1133 | * closing any socket. | ||
1134 | */ | ||
1135 | |||
1136 | /* Flush out this sockets receive queue. */ | ||
1137 | drain_queue(cf_sk); | ||
1138 | |||
1139 | /* Finally release the socket. */ | ||
1140 | SET_STATE_PENDING_DESTROY(cf_sk); | ||
1141 | |||
1142 | release_sock(&cf_sk->sk); | ||
1143 | |||
1144 | sock_put(sk); | ||
1145 | |||
1146 | /* | ||
1147 | * The rest of the cleanup will be handled from the | ||
1148 | * caif_sock_destructor | ||
1149 | */ | ||
1150 | return res; | ||
1151 | } | ||
1152 | |||
1153 | static const struct proto_ops caif_ops = { | ||
1154 | .family = PF_CAIF, | ||
1155 | .owner = THIS_MODULE, | ||
1156 | .release = caif_release, | ||
1157 | .bind = sock_no_bind, | ||
1158 | .connect = caif_connect, | ||
1159 | .socketpair = sock_no_socketpair, | ||
1160 | .accept = sock_no_accept, | ||
1161 | .getname = sock_no_getname, | ||
1162 | .poll = caif_poll, | ||
1163 | .ioctl = sock_no_ioctl, | ||
1164 | .listen = sock_no_listen, | ||
1165 | .shutdown = caif_shutdown, | ||
1166 | .setsockopt = setsockopt, | ||
1167 | .getsockopt = sock_no_getsockopt, | ||
1168 | .sendmsg = caif_sendmsg, | ||
1169 | .recvmsg = caif_recvmsg, | ||
1170 | .mmap = sock_no_mmap, | ||
1171 | .sendpage = caif_sock_no_sendpage, | ||
1172 | }; | ||
1173 | |||
1174 | /* This function is called when a socket is finally destroyed. */ | ||
1175 | static void caif_sock_destructor(struct sock *sk) | ||
1176 | { | ||
1177 | struct caifsock *cf_sk = NULL; | ||
1178 | cf_sk = container_of(sk, struct caifsock, sk); | ||
1179 | /* Error checks. */ | ||
1180 | caif_assert(!atomic_read(&sk->sk_wmem_alloc)); | ||
1181 | caif_assert(sk_unhashed(sk)); | ||
1182 | caif_assert(!sk->sk_socket); | ||
1183 | if (!sock_flag(sk, SOCK_DEAD)) { | ||
1184 | pr_debug("CAIF: %s(): 0x%p", __func__, sk); | ||
1185 | return; | ||
1186 | } | ||
1187 | |||
1188 | if (STATE_IS_OPEN(cf_sk)) { | ||
1189 | pr_debug("CAIF: %s(): socket is opened (cf_sk=%p)" | ||
1190 | " file_mode = 0x%x\n", __func__, | ||
1191 | cf_sk, cf_sk->file_mode); | ||
1192 | return; | ||
1193 | } | ||
1194 | drain_queue(cf_sk); | ||
1195 | kfree(cf_sk->pktq); | ||
1196 | |||
1197 | trace_printk("CAIF: %s(): caif_sock_destructor: Removing socket %s\n", | ||
1198 | __func__, cf_sk->name); | ||
1199 | atomic_dec(&caif_nr_socks); | ||
1200 | } | ||
1201 | |||
1202 | static int caif_create(struct net *net, struct socket *sock, int protocol, | ||
1203 | int kern) | ||
1204 | { | ||
1205 | struct sock *sk = NULL; | ||
1206 | struct caifsock *cf_sk = NULL; | ||
1207 | int result = 0; | ||
1208 | static struct proto prot = {.name = "PF_CAIF", | ||
1209 | .owner = THIS_MODULE, | ||
1210 | .obj_size = sizeof(struct caifsock), | ||
1211 | }; | ||
1212 | |||
1213 | /* | ||
1214 | * The sock->type specifies the socket type to use. | ||
1215 | * in SEQPACKET mode packet boundaries are enforced. | ||
1216 | */ | ||
1217 | if (sock->type != SOCK_SEQPACKET && sock->type != SOCK_STREAM) | ||
1218 | return -ESOCKTNOSUPPORT; | ||
1219 | |||
1220 | if (net != &init_net) | ||
1221 | return -EAFNOSUPPORT; | ||
1222 | |||
1223 | if (protocol < 0 || protocol >= CAIFPROTO_MAX) | ||
1224 | return -EPROTONOSUPPORT; | ||
1225 | /* | ||
1226 | * Set the socket state to unconnected. The socket state is really | ||
1227 | * not used at all in the net/core or socket.c but the | ||
1228 | * initialization makes sure that sock->state is not uninitialized. | ||
1229 | */ | ||
1230 | sock->state = SS_UNCONNECTED; | ||
1231 | |||
1232 | sk = sk_alloc(net, PF_CAIF, GFP_KERNEL, &prot); | ||
1233 | if (!sk) | ||
1234 | return -ENOMEM; | ||
1235 | |||
1236 | cf_sk = container_of(sk, struct caifsock, sk); | ||
1237 | |||
1238 | /* Store the protocol */ | ||
1239 | sk->sk_protocol = (unsigned char) protocol; | ||
1240 | |||
1241 | spin_lock_init(&cf_sk->read_queue_len_lock); | ||
1242 | |||
1243 | /* Fill in some information concerning the misc socket. */ | ||
1244 | snprintf(cf_sk->name, sizeof(cf_sk->name), "cf_sk%d", | ||
1245 | atomic_read(&caif_nr_socks)); | ||
1246 | |||
1247 | /* | ||
1248 | * Lock in order to try to stop someone from opening the socket | ||
1249 | * too early. | ||
1250 | */ | ||
1251 | lock_sock(&(cf_sk->sk)); | ||
1252 | |||
1253 | /* Initialize the nozero default sock structure data. */ | ||
1254 | sock_init_data(sock, sk); | ||
1255 | sock->ops = &caif_ops; | ||
1256 | sk->sk_destruct = caif_sock_destructor; | ||
1257 | sk->sk_sndbuf = caif_sockbuf_size; | ||
1258 | sk->sk_rcvbuf = caif_sockbuf_size; | ||
1259 | |||
1260 | cf_sk->pktq = cfpktq_create(); | ||
1261 | |||
1262 | if (!cf_sk->pktq) { | ||
1263 | pr_err("CAIF: %s(): queue create failed.\n", __func__); | ||
1264 | result = -ENOMEM; | ||
1265 | release_sock(&cf_sk->sk); | ||
1266 | goto err_failed; | ||
1267 | } | ||
1268 | cf_sk->layer.ctrlcmd = caif_sktflowctrl_cb; | ||
1269 | SET_STATE_CLOSED(cf_sk); | ||
1270 | SET_PENDING_OFF(cf_sk); | ||
1271 | SET_TX_FLOW_OFF(cf_sk); | ||
1272 | SET_RX_FLOW_ON(cf_sk); | ||
1273 | |||
1274 | /* Set default options on configuration */ | ||
1275 | cf_sk->conn_req.priority = CAIF_PRIO_NORMAL; | ||
1276 | cf_sk->conn_req.link_selector = CAIF_LINK_HIGH_BANDW; | ||
1277 | cf_sk->conn_req.protocol = protocol; | ||
1278 | /* Increase the number of sockets created. */ | ||
1279 | atomic_inc(&caif_nr_socks); | ||
1280 | if (!IS_ERR(debugfsdir)) { | ||
1281 | cf_sk->debugfs_socket_dir = | ||
1282 | debugfs_create_dir(cf_sk->name, debugfsdir); | ||
1283 | debugfs_create_u32("conn_state", S_IRUSR | S_IWUSR, | ||
1284 | cf_sk->debugfs_socket_dir, &cf_sk->conn_state); | ||
1285 | debugfs_create_u32("flow_state", S_IRUSR | S_IWUSR, | ||
1286 | cf_sk->debugfs_socket_dir, &cf_sk->flow_state); | ||
1287 | debugfs_create_u32("read_queue_len", S_IRUSR | S_IWUSR, | ||
1288 | cf_sk->debugfs_socket_dir, | ||
1289 | (u32 *) &cf_sk->read_queue_len); | ||
1290 | debugfs_create_u32("identity", S_IRUSR | S_IWUSR, | ||
1291 | cf_sk->debugfs_socket_dir, | ||
1292 | (u32 *) &cf_sk->layer.id); | ||
1293 | } | ||
1294 | release_sock(&cf_sk->sk); | ||
1295 | return 0; | ||
1296 | err_failed: | ||
1297 | sk_free(sk); | ||
1298 | return result; | ||
1299 | } | ||
1300 | |||
1301 | static struct net_proto_family caif_family_ops = { | ||
1302 | .family = PF_CAIF, | ||
1303 | .create = caif_create, | ||
1304 | .owner = THIS_MODULE, | ||
1305 | }; | ||
1306 | |||
1307 | static int af_caif_init(void) | ||
1308 | { | ||
1309 | int err; | ||
1310 | err = sock_register(&caif_family_ops); | ||
1311 | |||
1312 | if (!err) | ||
1313 | return err; | ||
1314 | |||
1315 | return 0; | ||
1316 | } | ||
1317 | |||
1318 | static int __init caif_sktinit_module(void) | ||
1319 | { | ||
1320 | int stat; | ||
1321 | #ifdef CONFIG_DEBUG_FS | ||
1322 | debugfsdir = debugfs_create_dir("chnl_skt", NULL); | ||
1323 | if (!IS_ERR(debugfsdir)) { | ||
1324 | debugfs_create_u32("skb_inuse", S_IRUSR | S_IWUSR, | ||
1325 | debugfsdir, | ||
1326 | (u32 *) &cnt.skb_in_use); | ||
1327 | debugfs_create_u32("skb_alloc", S_IRUSR | S_IWUSR, | ||
1328 | debugfsdir, | ||
1329 | (u32 *) &cnt.skb_alloc); | ||
1330 | debugfs_create_u32("skb_free", S_IRUSR | S_IWUSR, | ||
1331 | debugfsdir, | ||
1332 | (u32 *) &cnt.skb_free); | ||
1333 | debugfs_create_u32("num_sockets", S_IRUSR | S_IWUSR, | ||
1334 | debugfsdir, | ||
1335 | (u32 *) &caif_nr_socks); | ||
1336 | debugfs_create_u32("num_open", S_IRUSR | S_IWUSR, | ||
1337 | debugfsdir, | ||
1338 | (u32 *) &cnt.num_open); | ||
1339 | debugfs_create_u32("num_close", S_IRUSR | S_IWUSR, | ||
1340 | debugfsdir, | ||
1341 | (u32 *) &cnt.num_close); | ||
1342 | debugfs_create_u32("num_init", S_IRUSR | S_IWUSR, | ||
1343 | debugfsdir, | ||
1344 | (u32 *) &cnt.num_init); | ||
1345 | debugfs_create_u32("num_init_resp", S_IRUSR | S_IWUSR, | ||
1346 | debugfsdir, | ||
1347 | (u32 *) &cnt.num_init_resp); | ||
1348 | debugfs_create_u32("num_init_fail_resp", S_IRUSR | S_IWUSR, | ||
1349 | debugfsdir, | ||
1350 | (u32 *) &cnt.num_init_fail_resp); | ||
1351 | debugfs_create_u32("num_deinit", S_IRUSR | S_IWUSR, | ||
1352 | debugfsdir, | ||
1353 | (u32 *) &cnt.num_deinit); | ||
1354 | debugfs_create_u32("num_deinit_resp", S_IRUSR | S_IWUSR, | ||
1355 | debugfsdir, | ||
1356 | (u32 *) &cnt.num_deinit_resp); | ||
1357 | debugfs_create_u32("num_remote_shutdown_ind", | ||
1358 | S_IRUSR | S_IWUSR, debugfsdir, | ||
1359 | (u32 *) &cnt.num_remote_shutdown_ind); | ||
1360 | debugfs_create_u32("num_tx_flow_off_ind", S_IRUSR | S_IWUSR, | ||
1361 | debugfsdir, | ||
1362 | (u32 *) &cnt.num_tx_flow_off_ind); | ||
1363 | debugfs_create_u32("num_tx_flow_on_ind", S_IRUSR | S_IWUSR, | ||
1364 | debugfsdir, | ||
1365 | (u32 *) &cnt.num_tx_flow_on_ind); | ||
1366 | debugfs_create_u32("num_rx_flow_off", S_IRUSR | S_IWUSR, | ||
1367 | debugfsdir, | ||
1368 | (u32 *) &cnt.num_rx_flow_off); | ||
1369 | debugfs_create_u32("num_rx_flow_on", S_IRUSR | S_IWUSR, | ||
1370 | debugfsdir, | ||
1371 | (u32 *) &cnt.num_rx_flow_on); | ||
1372 | } | ||
1373 | #endif | ||
1374 | stat = af_caif_init(); | ||
1375 | if (stat) { | ||
1376 | pr_err("CAIF: %s(): Failed to initialize CAIF socket layer.", | ||
1377 | __func__); | ||
1378 | return stat; | ||
1379 | } | ||
1380 | return 0; | ||
1381 | } | ||
1382 | |||
1383 | static void __exit caif_sktexit_module(void) | ||
1384 | { | ||
1385 | sock_unregister(PF_CAIF); | ||
1386 | if (debugfsdir != NULL) | ||
1387 | debugfs_remove_recursive(debugfsdir); | ||
1388 | } | ||
1389 | |||
1390 | module_init(caif_sktinit_module); | ||
1391 | module_exit(caif_sktexit_module); | ||
diff --git a/net/caif/cfcnfg.c b/net/caif/cfcnfg.c new file mode 100644 index 000000000000..c873e3d4387c --- /dev/null +++ b/net/caif/cfcnfg.c | |||
@@ -0,0 +1,530 @@ | |||
1 | /* | ||
2 | * Copyright (C) ST-Ericsson AB 2010 | ||
3 | * Author: Sjur Brendeland/sjur.brandeland@stericsson.com | ||
4 | * License terms: GNU General Public License (GPL) version 2 | ||
5 | */ | ||
6 | #include <linux/kernel.h> | ||
7 | #include <linux/stddef.h> | ||
8 | #include <linux/slab.h> | ||
9 | #include <net/caif/caif_layer.h> | ||
10 | #include <net/caif/cfpkt.h> | ||
11 | #include <net/caif/cfcnfg.h> | ||
12 | #include <net/caif/cfctrl.h> | ||
13 | #include <net/caif/cfmuxl.h> | ||
14 | #include <net/caif/cffrml.h> | ||
15 | #include <net/caif/cfserl.h> | ||
16 | #include <net/caif/cfsrvl.h> | ||
17 | |||
18 | #include <linux/module.h> | ||
19 | #include <asm/atomic.h> | ||
20 | |||
21 | #define MAX_PHY_LAYERS 7 | ||
22 | #define PHY_NAME_LEN 20 | ||
23 | |||
24 | #define container_obj(layr) container_of(layr, struct cfcnfg, layer) | ||
25 | |||
26 | /* Information about CAIF physical interfaces held by Config Module in order | ||
27 | * to manage physical interfaces | ||
28 | */ | ||
29 | struct cfcnfg_phyinfo { | ||
30 | /* Pointer to the layer below the MUX (framing layer) */ | ||
31 | struct cflayer *frm_layer; | ||
32 | /* Pointer to the lowest actual physical layer */ | ||
33 | struct cflayer *phy_layer; | ||
34 | /* Unique identifier of the physical interface */ | ||
35 | unsigned int id; | ||
36 | /* Preference of the physical in interface */ | ||
37 | enum cfcnfg_phy_preference pref; | ||
38 | |||
39 | /* Reference count, number of channels using the device */ | ||
40 | int phy_ref_count; | ||
41 | |||
42 | /* Information about the physical device */ | ||
43 | struct dev_info dev_info; | ||
44 | }; | ||
45 | |||
46 | struct cfcnfg { | ||
47 | struct cflayer layer; | ||
48 | struct cflayer *ctrl; | ||
49 | struct cflayer *mux; | ||
50 | u8 last_phyid; | ||
51 | struct cfcnfg_phyinfo phy_layers[MAX_PHY_LAYERS]; | ||
52 | }; | ||
53 | |||
54 | static void cncfg_linkup_rsp(struct cflayer *layer, u8 linkid, | ||
55 | enum cfctrl_srv serv, u8 phyid, | ||
56 | struct cflayer *adapt_layer); | ||
57 | static void cncfg_linkdestroy_rsp(struct cflayer *layer, u8 linkid, | ||
58 | struct cflayer *client_layer); | ||
59 | static void cncfg_reject_rsp(struct cflayer *layer, u8 linkid, | ||
60 | struct cflayer *adapt_layer); | ||
61 | static void cfctrl_resp_func(void); | ||
62 | static void cfctrl_enum_resp(void); | ||
63 | |||
64 | struct cfcnfg *cfcnfg_create(void) | ||
65 | { | ||
66 | struct cfcnfg *this; | ||
67 | struct cfctrl_rsp *resp; | ||
68 | /* Initiate this layer */ | ||
69 | this = kmalloc(sizeof(struct cfcnfg), GFP_ATOMIC); | ||
70 | if (!this) { | ||
71 | pr_warning("CAIF: %s(): Out of memory\n", __func__); | ||
72 | return NULL; | ||
73 | } | ||
74 | memset(this, 0, sizeof(struct cfcnfg)); | ||
75 | this->mux = cfmuxl_create(); | ||
76 | if (!this->mux) | ||
77 | goto out_of_mem; | ||
78 | this->ctrl = cfctrl_create(); | ||
79 | if (!this->ctrl) | ||
80 | goto out_of_mem; | ||
81 | /* Initiate response functions */ | ||
82 | resp = cfctrl_get_respfuncs(this->ctrl); | ||
83 | resp->enum_rsp = cfctrl_enum_resp; | ||
84 | resp->linkerror_ind = cfctrl_resp_func; | ||
85 | resp->linkdestroy_rsp = cncfg_linkdestroy_rsp; | ||
86 | resp->sleep_rsp = cfctrl_resp_func; | ||
87 | resp->wake_rsp = cfctrl_resp_func; | ||
88 | resp->restart_rsp = cfctrl_resp_func; | ||
89 | resp->radioset_rsp = cfctrl_resp_func; | ||
90 | resp->linksetup_rsp = cncfg_linkup_rsp; | ||
91 | resp->reject_rsp = cncfg_reject_rsp; | ||
92 | |||
93 | this->last_phyid = 1; | ||
94 | |||
95 | cfmuxl_set_uplayer(this->mux, this->ctrl, 0); | ||
96 | layer_set_dn(this->ctrl, this->mux); | ||
97 | layer_set_up(this->ctrl, this); | ||
98 | return this; | ||
99 | out_of_mem: | ||
100 | pr_warning("CAIF: %s(): Out of memory\n", __func__); | ||
101 | kfree(this->mux); | ||
102 | kfree(this->ctrl); | ||
103 | kfree(this); | ||
104 | return NULL; | ||
105 | } | ||
106 | EXPORT_SYMBOL(cfcnfg_create); | ||
107 | |||
108 | void cfcnfg_remove(struct cfcnfg *cfg) | ||
109 | { | ||
110 | if (cfg) { | ||
111 | kfree(cfg->mux); | ||
112 | kfree(cfg->ctrl); | ||
113 | kfree(cfg); | ||
114 | } | ||
115 | } | ||
116 | |||
117 | static void cfctrl_resp_func(void) | ||
118 | { | ||
119 | } | ||
120 | |||
121 | static void cfctrl_enum_resp(void) | ||
122 | { | ||
123 | } | ||
124 | |||
125 | struct dev_info *cfcnfg_get_phyid(struct cfcnfg *cnfg, | ||
126 | enum cfcnfg_phy_preference phy_pref) | ||
127 | { | ||
128 | u16 i; | ||
129 | |||
130 | /* Try to match with specified preference */ | ||
131 | for (i = 1; i < MAX_PHY_LAYERS; i++) { | ||
132 | if (cnfg->phy_layers[i].id == i && | ||
133 | cnfg->phy_layers[i].pref == phy_pref && | ||
134 | cnfg->phy_layers[i].frm_layer != NULL) { | ||
135 | caif_assert(cnfg->phy_layers != NULL); | ||
136 | caif_assert(cnfg->phy_layers[i].id == i); | ||
137 | return &cnfg->phy_layers[i].dev_info; | ||
138 | } | ||
139 | } | ||
140 | /* Otherwise just return something */ | ||
141 | for (i = 1; i < MAX_PHY_LAYERS; i++) { | ||
142 | if (cnfg->phy_layers[i].id == i) { | ||
143 | caif_assert(cnfg->phy_layers != NULL); | ||
144 | caif_assert(cnfg->phy_layers[i].id == i); | ||
145 | return &cnfg->phy_layers[i].dev_info; | ||
146 | } | ||
147 | } | ||
148 | |||
149 | return NULL; | ||
150 | } | ||
151 | |||
152 | static struct cfcnfg_phyinfo *cfcnfg_get_phyinfo(struct cfcnfg *cnfg, | ||
153 | u8 phyid) | ||
154 | { | ||
155 | int i; | ||
156 | /* Try to match with specified preference */ | ||
157 | for (i = 0; i < MAX_PHY_LAYERS; i++) | ||
158 | if (cnfg->phy_layers[i].frm_layer != NULL && | ||
159 | cnfg->phy_layers[i].id == phyid) | ||
160 | return &cnfg->phy_layers[i]; | ||
161 | return NULL; | ||
162 | } | ||
163 | |||
164 | int cfcnfg_get_named(struct cfcnfg *cnfg, char *name) | ||
165 | { | ||
166 | int i; | ||
167 | |||
168 | /* Try to match with specified name */ | ||
169 | for (i = 0; i < MAX_PHY_LAYERS; i++) { | ||
170 | if (cnfg->phy_layers[i].frm_layer != NULL | ||
171 | && strcmp(cnfg->phy_layers[i].phy_layer->name, | ||
172 | name) == 0) | ||
173 | return cnfg->phy_layers[i].frm_layer->id; | ||
174 | } | ||
175 | return 0; | ||
176 | } | ||
177 | |||
178 | /* | ||
179 | * NOTE: What happens on destroy failure: | ||
180 | * 1a) No response - Too early | ||
181 | * This will not happen because enumerate has already | ||
182 | * completed. | ||
183 | * 1b) No response - FATAL | ||
184 | * Not handled, but this should be a CAIF PROTOCOL ERROR | ||
185 | * Modem error, response is really expected - this | ||
186 | * case is not really handled. | ||
187 | * 2) O/E-bit indicate error | ||
188 | * Ignored - this link is destroyed anyway. | ||
189 | * 3) Not able to match on request | ||
190 | * Not handled, but this should be a CAIF PROTOCOL ERROR | ||
191 | * 4) Link-Error - (no response) | ||
192 | * Not handled, but this should be a CAIF PROTOCOL ERROR | ||
193 | */ | ||
194 | |||
195 | int cfcnfg_del_adapt_layer(struct cfcnfg *cnfg, struct cflayer *adap_layer) | ||
196 | { | ||
197 | u8 channel_id = 0; | ||
198 | int ret = 0; | ||
199 | struct cfcnfg_phyinfo *phyinfo = NULL; | ||
200 | u8 phyid = 0; | ||
201 | |||
202 | caif_assert(adap_layer != NULL); | ||
203 | channel_id = adap_layer->id; | ||
204 | if (channel_id == 0) { | ||
205 | pr_err("CAIF: %s():adap_layer->id is 0\n", __func__); | ||
206 | ret = -ENOTCONN; | ||
207 | goto end; | ||
208 | } | ||
209 | |||
210 | if (adap_layer->dn == NULL) { | ||
211 | pr_err("CAIF: %s():adap_layer->dn is NULL\n", __func__); | ||
212 | ret = -ENODEV; | ||
213 | goto end; | ||
214 | } | ||
215 | |||
216 | if (adap_layer->dn != NULL) | ||
217 | phyid = cfsrvl_getphyid(adap_layer->dn); | ||
218 | |||
219 | phyinfo = cfcnfg_get_phyinfo(cnfg, phyid); | ||
220 | if (phyinfo == NULL) { | ||
221 | pr_warning("CAIF: %s(): No interface to send disconnect to\n", | ||
222 | __func__); | ||
223 | ret = -ENODEV; | ||
224 | goto end; | ||
225 | } | ||
226 | |||
227 | if (phyinfo->id != phyid | ||
228 | || phyinfo->phy_layer->id != phyid | ||
229 | || phyinfo->frm_layer->id != phyid) { | ||
230 | |||
231 | pr_err("CAIF: %s(): Inconsistency in phy registration\n", | ||
232 | __func__); | ||
233 | ret = -EINVAL; | ||
234 | goto end; | ||
235 | } | ||
236 | |||
237 | ret = cfctrl_linkdown_req(cnfg->ctrl, channel_id, adap_layer); | ||
238 | |||
239 | end: | ||
240 | if (phyinfo != NULL && --phyinfo->phy_ref_count == 0 && | ||
241 | phyinfo->phy_layer != NULL && | ||
242 | phyinfo->phy_layer->modemcmd != NULL) { | ||
243 | phyinfo->phy_layer->modemcmd(phyinfo->phy_layer, | ||
244 | _CAIF_MODEMCMD_PHYIF_USELESS); | ||
245 | } | ||
246 | return ret; | ||
247 | |||
248 | } | ||
249 | EXPORT_SYMBOL(cfcnfg_del_adapt_layer); | ||
250 | |||
251 | static void cncfg_linkdestroy_rsp(struct cflayer *layer, u8 linkid, | ||
252 | struct cflayer *client_layer) | ||
253 | { | ||
254 | struct cfcnfg *cnfg = container_obj(layer); | ||
255 | struct cflayer *servl; | ||
256 | |||
257 | /* | ||
258 | * 1) Remove service from the MUX layer. The MUX must | ||
259 | * guarante that no more payload sent "upwards" (receive) | ||
260 | */ | ||
261 | servl = cfmuxl_remove_uplayer(cnfg->mux, linkid); | ||
262 | |||
263 | if (servl == NULL) { | ||
264 | pr_err("CAIF: %s(): PROTOCOL ERROR " | ||
265 | "- Error removing service_layer Linkid(%d)", | ||
266 | __func__, linkid); | ||
267 | return; | ||
268 | } | ||
269 | caif_assert(linkid == servl->id); | ||
270 | |||
271 | if (servl != client_layer && servl->up != client_layer) { | ||
272 | pr_err("CAIF: %s(): Error removing service_layer " | ||
273 | "Linkid(%d) %p %p", | ||
274 | __func__, linkid, (void *) servl, | ||
275 | (void *) client_layer); | ||
276 | return; | ||
277 | } | ||
278 | |||
279 | /* | ||
280 | * 2) DEINIT_RSP must guarantee that no more packets are transmitted | ||
281 | * from client (adap_layer) when it returns. | ||
282 | */ | ||
283 | |||
284 | if (servl->ctrlcmd == NULL) { | ||
285 | pr_err("CAIF: %s(): Error servl->ctrlcmd == NULL", __func__); | ||
286 | return; | ||
287 | } | ||
288 | |||
289 | servl->ctrlcmd(servl, CAIF_CTRLCMD_DEINIT_RSP, 0); | ||
290 | |||
291 | /* 3) It is now safe to destroy the service layer. */ | ||
292 | cfservl_destroy(servl); | ||
293 | } | ||
294 | |||
295 | /* | ||
296 | * NOTE: What happens on linksetup failure: | ||
297 | * 1a) No response - Too early | ||
298 | * This will not happen because enumerate is secured | ||
299 | * before using interface. | ||
300 | * 1b) No response - FATAL | ||
301 | * Not handled, but this should be a CAIF PROTOCOL ERROR | ||
302 | * Modem error, response is really expected - this case is | ||
303 | * not really handled. | ||
304 | * 2) O/E-bit indicate error | ||
305 | * Handled in cnfg_reject_rsp | ||
306 | * 3) Not able to match on request | ||
307 | * Not handled, but this should be a CAIF PROTOCOL ERROR | ||
308 | * 4) Link-Error - (no response) | ||
309 | * Not handled, but this should be a CAIF PROTOCOL ERROR | ||
310 | */ | ||
311 | |||
312 | int | ||
313 | cfcnfg_add_adaptation_layer(struct cfcnfg *cnfg, | ||
314 | struct cfctrl_link_param *param, | ||
315 | struct cflayer *adap_layer) | ||
316 | { | ||
317 | struct cflayer *frml; | ||
318 | if (adap_layer == NULL) { | ||
319 | pr_err("CAIF: %s(): adap_layer is zero", __func__); | ||
320 | return -EINVAL; | ||
321 | } | ||
322 | if (adap_layer->receive == NULL) { | ||
323 | pr_err("CAIF: %s(): adap_layer->receive is NULL", __func__); | ||
324 | return -EINVAL; | ||
325 | } | ||
326 | if (adap_layer->ctrlcmd == NULL) { | ||
327 | pr_err("CAIF: %s(): adap_layer->ctrlcmd == NULL", __func__); | ||
328 | return -EINVAL; | ||
329 | } | ||
330 | frml = cnfg->phy_layers[param->phyid].frm_layer; | ||
331 | if (frml == NULL) { | ||
332 | pr_err("CAIF: %s(): Specified PHY type does not exist!", | ||
333 | __func__); | ||
334 | return -ENODEV; | ||
335 | } | ||
336 | caif_assert(param->phyid == cnfg->phy_layers[param->phyid].id); | ||
337 | caif_assert(cnfg->phy_layers[param->phyid].frm_layer->id == | ||
338 | param->phyid); | ||
339 | caif_assert(cnfg->phy_layers[param->phyid].phy_layer->id == | ||
340 | param->phyid); | ||
341 | /* FIXME: ENUMERATE INITIALLY WHEN ACTIVATING PHYSICAL INTERFACE */ | ||
342 | cfctrl_enum_req(cnfg->ctrl, param->phyid); | ||
343 | cfctrl_linkup_request(cnfg->ctrl, param, adap_layer); | ||
344 | return 0; | ||
345 | } | ||
346 | EXPORT_SYMBOL(cfcnfg_add_adaptation_layer); | ||
347 | |||
348 | static void cncfg_reject_rsp(struct cflayer *layer, u8 linkid, | ||
349 | struct cflayer *adapt_layer) | ||
350 | { | ||
351 | if (adapt_layer != NULL && adapt_layer->ctrlcmd != NULL) | ||
352 | adapt_layer->ctrlcmd(adapt_layer, | ||
353 | CAIF_CTRLCMD_INIT_FAIL_RSP, 0); | ||
354 | } | ||
355 | |||
356 | static void | ||
357 | cncfg_linkup_rsp(struct cflayer *layer, u8 linkid, enum cfctrl_srv serv, | ||
358 | u8 phyid, struct cflayer *adapt_layer) | ||
359 | { | ||
360 | struct cfcnfg *cnfg = container_obj(layer); | ||
361 | struct cflayer *servicel = NULL; | ||
362 | struct cfcnfg_phyinfo *phyinfo; | ||
363 | if (adapt_layer == NULL) { | ||
364 | pr_err("CAIF: %s(): PROTOCOL ERROR " | ||
365 | "- LinkUp Request/Response did not match\n", __func__); | ||
366 | return; | ||
367 | } | ||
368 | |||
369 | caif_assert(cnfg != NULL); | ||
370 | caif_assert(phyid != 0); | ||
371 | phyinfo = &cnfg->phy_layers[phyid]; | ||
372 | caif_assert(phyinfo != NULL); | ||
373 | caif_assert(phyinfo->id == phyid); | ||
374 | caif_assert(phyinfo->phy_layer != NULL); | ||
375 | caif_assert(phyinfo->phy_layer->id == phyid); | ||
376 | |||
377 | if (phyinfo != NULL && | ||
378 | phyinfo->phy_ref_count++ == 0 && | ||
379 | phyinfo->phy_layer != NULL && | ||
380 | phyinfo->phy_layer->modemcmd != NULL) { | ||
381 | caif_assert(phyinfo->phy_layer->id == phyid); | ||
382 | phyinfo->phy_layer->modemcmd(phyinfo->phy_layer, | ||
383 | _CAIF_MODEMCMD_PHYIF_USEFULL); | ||
384 | |||
385 | } | ||
386 | adapt_layer->id = linkid; | ||
387 | |||
388 | switch (serv) { | ||
389 | case CFCTRL_SRV_VEI: | ||
390 | servicel = cfvei_create(linkid, &phyinfo->dev_info); | ||
391 | break; | ||
392 | case CFCTRL_SRV_DATAGRAM: | ||
393 | servicel = cfdgml_create(linkid, &phyinfo->dev_info); | ||
394 | break; | ||
395 | case CFCTRL_SRV_RFM: | ||
396 | servicel = cfrfml_create(linkid, &phyinfo->dev_info); | ||
397 | break; | ||
398 | case CFCTRL_SRV_UTIL: | ||
399 | servicel = cfutill_create(linkid, &phyinfo->dev_info); | ||
400 | break; | ||
401 | case CFCTRL_SRV_VIDEO: | ||
402 | servicel = cfvidl_create(linkid, &phyinfo->dev_info); | ||
403 | break; | ||
404 | case CFCTRL_SRV_DBG: | ||
405 | servicel = cfdbgl_create(linkid, &phyinfo->dev_info); | ||
406 | break; | ||
407 | default: | ||
408 | pr_err("CAIF: %s(): Protocol error. " | ||
409 | "Link setup response - unknown channel type\n", | ||
410 | __func__); | ||
411 | return; | ||
412 | } | ||
413 | if (!servicel) { | ||
414 | pr_warning("CAIF: %s(): Out of memory\n", __func__); | ||
415 | return; | ||
416 | } | ||
417 | layer_set_dn(servicel, cnfg->mux); | ||
418 | cfmuxl_set_uplayer(cnfg->mux, servicel, linkid); | ||
419 | layer_set_up(servicel, adapt_layer); | ||
420 | layer_set_dn(adapt_layer, servicel); | ||
421 | servicel->ctrlcmd(servicel, CAIF_CTRLCMD_INIT_RSP, 0); | ||
422 | } | ||
423 | |||
424 | void | ||
425 | cfcnfg_add_phy_layer(struct cfcnfg *cnfg, enum cfcnfg_phy_type phy_type, | ||
426 | void *dev, struct cflayer *phy_layer, u16 *phyid, | ||
427 | enum cfcnfg_phy_preference pref, | ||
428 | bool fcs, bool stx) | ||
429 | { | ||
430 | struct cflayer *frml; | ||
431 | struct cflayer *phy_driver = NULL; | ||
432 | int i; | ||
433 | |||
434 | |||
435 | if (cnfg->phy_layers[cnfg->last_phyid].frm_layer == NULL) { | ||
436 | *phyid = cnfg->last_phyid; | ||
437 | |||
438 | /* range: * 1..(MAX_PHY_LAYERS-1) */ | ||
439 | cnfg->last_phyid = | ||
440 | (cnfg->last_phyid % (MAX_PHY_LAYERS - 1)) + 1; | ||
441 | } else { | ||
442 | *phyid = 0; | ||
443 | for (i = 1; i < MAX_PHY_LAYERS; i++) { | ||
444 | if (cnfg->phy_layers[i].frm_layer == NULL) { | ||
445 | *phyid = i; | ||
446 | break; | ||
447 | } | ||
448 | } | ||
449 | } | ||
450 | if (*phyid == 0) { | ||
451 | pr_err("CAIF: %s(): No Available PHY ID\n", __func__); | ||
452 | return; | ||
453 | } | ||
454 | |||
455 | switch (phy_type) { | ||
456 | case CFPHYTYPE_FRAG: | ||
457 | phy_driver = | ||
458 | cfserl_create(CFPHYTYPE_FRAG, *phyid, stx); | ||
459 | if (!phy_driver) { | ||
460 | pr_warning("CAIF: %s(): Out of memory\n", __func__); | ||
461 | return; | ||
462 | } | ||
463 | |||
464 | break; | ||
465 | case CFPHYTYPE_CAIF: | ||
466 | phy_driver = NULL; | ||
467 | break; | ||
468 | default: | ||
469 | pr_err("CAIF: %s(): %d", __func__, phy_type); | ||
470 | return; | ||
471 | break; | ||
472 | } | ||
473 | |||
474 | phy_layer->id = *phyid; | ||
475 | cnfg->phy_layers[*phyid].pref = pref; | ||
476 | cnfg->phy_layers[*phyid].id = *phyid; | ||
477 | cnfg->phy_layers[*phyid].dev_info.id = *phyid; | ||
478 | cnfg->phy_layers[*phyid].dev_info.dev = dev; | ||
479 | cnfg->phy_layers[*phyid].phy_layer = phy_layer; | ||
480 | cnfg->phy_layers[*phyid].phy_ref_count = 0; | ||
481 | phy_layer->type = phy_type; | ||
482 | frml = cffrml_create(*phyid, fcs); | ||
483 | if (!frml) { | ||
484 | pr_warning("CAIF: %s(): Out of memory\n", __func__); | ||
485 | return; | ||
486 | } | ||
487 | cnfg->phy_layers[*phyid].frm_layer = frml; | ||
488 | cfmuxl_set_dnlayer(cnfg->mux, frml, *phyid); | ||
489 | layer_set_up(frml, cnfg->mux); | ||
490 | |||
491 | if (phy_driver != NULL) { | ||
492 | phy_driver->id = *phyid; | ||
493 | layer_set_dn(frml, phy_driver); | ||
494 | layer_set_up(phy_driver, frml); | ||
495 | layer_set_dn(phy_driver, phy_layer); | ||
496 | layer_set_up(phy_layer, phy_driver); | ||
497 | } else { | ||
498 | layer_set_dn(frml, phy_layer); | ||
499 | layer_set_up(phy_layer, frml); | ||
500 | } | ||
501 | } | ||
502 | EXPORT_SYMBOL(cfcnfg_add_phy_layer); | ||
503 | |||
504 | int cfcnfg_del_phy_layer(struct cfcnfg *cnfg, struct cflayer *phy_layer) | ||
505 | { | ||
506 | struct cflayer *frml, *frml_dn; | ||
507 | u16 phyid; | ||
508 | phyid = phy_layer->id; | ||
509 | caif_assert(phyid == cnfg->phy_layers[phyid].id); | ||
510 | caif_assert(phy_layer == cnfg->phy_layers[phyid].phy_layer); | ||
511 | caif_assert(phy_layer->id == phyid); | ||
512 | caif_assert(cnfg->phy_layers[phyid].frm_layer->id == phyid); | ||
513 | |||
514 | memset(&cnfg->phy_layers[phy_layer->id], 0, | ||
515 | sizeof(struct cfcnfg_phyinfo)); | ||
516 | frml = cfmuxl_remove_dnlayer(cnfg->mux, phy_layer->id); | ||
517 | frml_dn = frml->dn; | ||
518 | cffrml_set_uplayer(frml, NULL); | ||
519 | cffrml_set_dnlayer(frml, NULL); | ||
520 | kfree(frml); | ||
521 | |||
522 | if (phy_layer != frml_dn) { | ||
523 | layer_set_up(frml_dn, NULL); | ||
524 | layer_set_dn(frml_dn, NULL); | ||
525 | kfree(frml_dn); | ||
526 | } | ||
527 | layer_set_up(phy_layer, NULL); | ||
528 | return 0; | ||
529 | } | ||
530 | EXPORT_SYMBOL(cfcnfg_del_phy_layer); | ||
diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c new file mode 100644 index 000000000000..11f80140f3cb --- /dev/null +++ b/net/caif/cfctrl.c | |||
@@ -0,0 +1,664 @@ | |||
1 | /* | ||
2 | * Copyright (C) ST-Ericsson AB 2010 | ||
3 | * Author: Sjur Brendeland/sjur.brandeland@stericsson.com | ||
4 | * License terms: GNU General Public License (GPL) version 2 | ||
5 | */ | ||
6 | |||
7 | #include <linux/stddef.h> | ||
8 | #include <linux/spinlock.h> | ||
9 | #include <linux/slab.h> | ||
10 | #include <net/caif/caif_layer.h> | ||
11 | #include <net/caif/cfpkt.h> | ||
12 | #include <net/caif/cfctrl.h> | ||
13 | |||
14 | #define container_obj(layr) container_of(layr, struct cfctrl, serv.layer) | ||
15 | #define UTILITY_NAME_LENGTH 16 | ||
16 | #define CFPKT_CTRL_PKT_LEN 20 | ||
17 | |||
18 | |||
19 | #ifdef CAIF_NO_LOOP | ||
20 | static int handle_loop(struct cfctrl *ctrl, | ||
21 | int cmd, struct cfpkt *pkt){ | ||
22 | return CAIF_FAILURE; | ||
23 | } | ||
24 | #else | ||
25 | static int handle_loop(struct cfctrl *ctrl, | ||
26 | int cmd, struct cfpkt *pkt); | ||
27 | #endif | ||
28 | static int cfctrl_recv(struct cflayer *layr, struct cfpkt *pkt); | ||
29 | static void cfctrl_ctrlcmd(struct cflayer *layr, enum caif_ctrlcmd ctrl, | ||
30 | int phyid); | ||
31 | |||
32 | |||
33 | struct cflayer *cfctrl_create(void) | ||
34 | { | ||
35 | struct cfctrl *this = | ||
36 | kmalloc(sizeof(struct cfctrl), GFP_ATOMIC); | ||
37 | if (!this) { | ||
38 | pr_warning("CAIF: %s(): Out of memory\n", __func__); | ||
39 | return NULL; | ||
40 | } | ||
41 | caif_assert(offsetof(struct cfctrl, serv.layer) == 0); | ||
42 | memset(this, 0, sizeof(*this)); | ||
43 | spin_lock_init(&this->info_list_lock); | ||
44 | atomic_set(&this->req_seq_no, 1); | ||
45 | atomic_set(&this->rsp_seq_no, 1); | ||
46 | this->serv.dev_info.id = 0xff; | ||
47 | this->serv.layer.id = 0; | ||
48 | this->serv.layer.receive = cfctrl_recv; | ||
49 | sprintf(this->serv.layer.name, "ctrl"); | ||
50 | this->serv.layer.ctrlcmd = cfctrl_ctrlcmd; | ||
51 | spin_lock_init(&this->loop_linkid_lock); | ||
52 | this->loop_linkid = 1; | ||
53 | return &this->serv.layer; | ||
54 | } | ||
55 | |||
56 | static bool param_eq(struct cfctrl_link_param *p1, struct cfctrl_link_param *p2) | ||
57 | { | ||
58 | bool eq = | ||
59 | p1->linktype == p2->linktype && | ||
60 | p1->priority == p2->priority && | ||
61 | p1->phyid == p2->phyid && | ||
62 | p1->endpoint == p2->endpoint && p1->chtype == p2->chtype; | ||
63 | |||
64 | if (!eq) | ||
65 | return false; | ||
66 | |||
67 | switch (p1->linktype) { | ||
68 | case CFCTRL_SRV_VEI: | ||
69 | return true; | ||
70 | case CFCTRL_SRV_DATAGRAM: | ||
71 | return p1->u.datagram.connid == p2->u.datagram.connid; | ||
72 | case CFCTRL_SRV_RFM: | ||
73 | return | ||
74 | p1->u.rfm.connid == p2->u.rfm.connid && | ||
75 | strcmp(p1->u.rfm.volume, p2->u.rfm.volume) == 0; | ||
76 | case CFCTRL_SRV_UTIL: | ||
77 | return | ||
78 | p1->u.utility.fifosize_kb == p2->u.utility.fifosize_kb | ||
79 | && p1->u.utility.fifosize_bufs == | ||
80 | p2->u.utility.fifosize_bufs | ||
81 | && strcmp(p1->u.utility.name, p2->u.utility.name) == 0 | ||
82 | && p1->u.utility.paramlen == p2->u.utility.paramlen | ||
83 | && memcmp(p1->u.utility.params, p2->u.utility.params, | ||
84 | p1->u.utility.paramlen) == 0; | ||
85 | |||
86 | case CFCTRL_SRV_VIDEO: | ||
87 | return p1->u.video.connid == p2->u.video.connid; | ||
88 | case CFCTRL_SRV_DBG: | ||
89 | return true; | ||
90 | case CFCTRL_SRV_DECM: | ||
91 | return false; | ||
92 | default: | ||
93 | return false; | ||
94 | } | ||
95 | return false; | ||
96 | } | ||
97 | |||
98 | bool cfctrl_req_eq(struct cfctrl_request_info *r1, | ||
99 | struct cfctrl_request_info *r2) | ||
100 | { | ||
101 | if (r1->cmd != r2->cmd) | ||
102 | return false; | ||
103 | if (r1->cmd == CFCTRL_CMD_LINK_SETUP) | ||
104 | return param_eq(&r1->param, &r2->param); | ||
105 | else | ||
106 | return r1->channel_id == r2->channel_id; | ||
107 | } | ||
108 | |||
109 | /* Insert request at the end */ | ||
110 | void cfctrl_insert_req(struct cfctrl *ctrl, | ||
111 | struct cfctrl_request_info *req) | ||
112 | { | ||
113 | struct cfctrl_request_info *p; | ||
114 | spin_lock(&ctrl->info_list_lock); | ||
115 | req->next = NULL; | ||
116 | atomic_inc(&ctrl->req_seq_no); | ||
117 | req->sequence_no = atomic_read(&ctrl->req_seq_no); | ||
118 | if (ctrl->first_req == NULL) { | ||
119 | ctrl->first_req = req; | ||
120 | spin_unlock(&ctrl->info_list_lock); | ||
121 | return; | ||
122 | } | ||
123 | p = ctrl->first_req; | ||
124 | while (p->next != NULL) | ||
125 | p = p->next; | ||
126 | p->next = req; | ||
127 | spin_unlock(&ctrl->info_list_lock); | ||
128 | } | ||
129 | |||
130 | static void cfctrl_insert_req2(struct cfctrl *ctrl, enum cfctrl_cmd cmd, | ||
131 | u8 linkid, struct cflayer *user_layer) | ||
132 | { | ||
133 | struct cfctrl_request_info *req = kmalloc(sizeof(*req), GFP_KERNEL); | ||
134 | if (!req) { | ||
135 | pr_warning("CAIF: %s(): Out of memory\n", __func__); | ||
136 | return; | ||
137 | } | ||
138 | req->client_layer = user_layer; | ||
139 | req->cmd = cmd; | ||
140 | req->channel_id = linkid; | ||
141 | cfctrl_insert_req(ctrl, req); | ||
142 | } | ||
143 | |||
144 | /* Compare and remove request */ | ||
145 | struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl, | ||
146 | struct cfctrl_request_info *req) | ||
147 | { | ||
148 | struct cfctrl_request_info *p; | ||
149 | struct cfctrl_request_info *ret; | ||
150 | |||
151 | spin_lock(&ctrl->info_list_lock); | ||
152 | if (ctrl->first_req == NULL) { | ||
153 | spin_unlock(&ctrl->info_list_lock); | ||
154 | return NULL; | ||
155 | } | ||
156 | |||
157 | if (cfctrl_req_eq(req, ctrl->first_req)) { | ||
158 | ret = ctrl->first_req; | ||
159 | caif_assert(ctrl->first_req); | ||
160 | atomic_set(&ctrl->rsp_seq_no, | ||
161 | ctrl->first_req->sequence_no); | ||
162 | ctrl->first_req = ctrl->first_req->next; | ||
163 | spin_unlock(&ctrl->info_list_lock); | ||
164 | return ret; | ||
165 | } | ||
166 | |||
167 | p = ctrl->first_req; | ||
168 | |||
169 | while (p->next != NULL) { | ||
170 | if (cfctrl_req_eq(req, p->next)) { | ||
171 | pr_warning("CAIF: %s(): Requests are not " | ||
172 | "received in order\n", | ||
173 | __func__); | ||
174 | ret = p->next; | ||
175 | atomic_set(&ctrl->rsp_seq_no, | ||
176 | p->next->sequence_no); | ||
177 | p->next = p->next->next; | ||
178 | spin_unlock(&ctrl->info_list_lock); | ||
179 | return ret; | ||
180 | } | ||
181 | p = p->next; | ||
182 | } | ||
183 | spin_unlock(&ctrl->info_list_lock); | ||
184 | |||
185 | pr_warning("CAIF: %s(): Request does not match\n", | ||
186 | __func__); | ||
187 | return NULL; | ||
188 | } | ||
189 | |||
190 | struct cfctrl_rsp *cfctrl_get_respfuncs(struct cflayer *layer) | ||
191 | { | ||
192 | struct cfctrl *this = container_obj(layer); | ||
193 | return &this->res; | ||
194 | } | ||
195 | |||
196 | void cfctrl_set_dnlayer(struct cflayer *this, struct cflayer *dn) | ||
197 | { | ||
198 | this->dn = dn; | ||
199 | } | ||
200 | |||
201 | void cfctrl_set_uplayer(struct cflayer *this, struct cflayer *up) | ||
202 | { | ||
203 | this->up = up; | ||
204 | } | ||
205 | |||
206 | static void init_info(struct caif_payload_info *info, struct cfctrl *cfctrl) | ||
207 | { | ||
208 | info->hdr_len = 0; | ||
209 | info->channel_id = cfctrl->serv.layer.id; | ||
210 | info->dev_info = &cfctrl->serv.dev_info; | ||
211 | } | ||
212 | |||
213 | void cfctrl_enum_req(struct cflayer *layer, u8 physlinkid) | ||
214 | { | ||
215 | struct cfctrl *cfctrl = container_obj(layer); | ||
216 | int ret; | ||
217 | struct cfpkt *pkt = cfpkt_create(CFPKT_CTRL_PKT_LEN); | ||
218 | if (!pkt) { | ||
219 | pr_warning("CAIF: %s(): Out of memory\n", __func__); | ||
220 | return; | ||
221 | } | ||
222 | caif_assert(offsetof(struct cfctrl, serv.layer) == 0); | ||
223 | init_info(cfpkt_info(pkt), cfctrl); | ||
224 | cfpkt_info(pkt)->dev_info->id = physlinkid; | ||
225 | cfctrl->serv.dev_info.id = physlinkid; | ||
226 | cfpkt_addbdy(pkt, CFCTRL_CMD_ENUM); | ||
227 | cfpkt_addbdy(pkt, physlinkid); | ||
228 | ret = | ||
229 | cfctrl->serv.layer.dn->transmit(cfctrl->serv.layer.dn, pkt); | ||
230 | if (ret < 0) { | ||
231 | pr_err("CAIF: %s(): Could not transmit enum message\n", | ||
232 | __func__); | ||
233 | cfpkt_destroy(pkt); | ||
234 | } | ||
235 | } | ||
236 | |||
237 | void cfctrl_linkup_request(struct cflayer *layer, | ||
238 | struct cfctrl_link_param *param, | ||
239 | struct cflayer *user_layer) | ||
240 | { | ||
241 | struct cfctrl *cfctrl = container_obj(layer); | ||
242 | u32 tmp32; | ||
243 | u16 tmp16; | ||
244 | u8 tmp8; | ||
245 | struct cfctrl_request_info *req; | ||
246 | int ret; | ||
247 | char utility_name[16]; | ||
248 | struct cfpkt *pkt = cfpkt_create(CFPKT_CTRL_PKT_LEN); | ||
249 | if (!pkt) { | ||
250 | pr_warning("CAIF: %s(): Out of memory\n", __func__); | ||
251 | return; | ||
252 | } | ||
253 | cfpkt_addbdy(pkt, CFCTRL_CMD_LINK_SETUP); | ||
254 | cfpkt_addbdy(pkt, (param->chtype << 4) + param->linktype); | ||
255 | cfpkt_addbdy(pkt, (param->priority << 3) + param->phyid); | ||
256 | cfpkt_addbdy(pkt, param->endpoint & 0x03); | ||
257 | |||
258 | switch (param->linktype) { | ||
259 | case CFCTRL_SRV_VEI: | ||
260 | break; | ||
261 | case CFCTRL_SRV_VIDEO: | ||
262 | cfpkt_addbdy(pkt, (u8) param->u.video.connid); | ||
263 | break; | ||
264 | case CFCTRL_SRV_DBG: | ||
265 | break; | ||
266 | case CFCTRL_SRV_DATAGRAM: | ||
267 | tmp32 = cpu_to_le32(param->u.datagram.connid); | ||
268 | cfpkt_add_body(pkt, &tmp32, 4); | ||
269 | break; | ||
270 | case CFCTRL_SRV_RFM: | ||
271 | /* Construct a frame, convert DatagramConnectionID to network | ||
272 | * format long and copy it out... | ||
273 | */ | ||
274 | tmp32 = cpu_to_le32(param->u.rfm.connid); | ||
275 | cfpkt_add_body(pkt, &tmp32, 4); | ||
276 | /* Add volume name, including zero termination... */ | ||
277 | cfpkt_add_body(pkt, param->u.rfm.volume, | ||
278 | strlen(param->u.rfm.volume) + 1); | ||
279 | break; | ||
280 | case CFCTRL_SRV_UTIL: | ||
281 | tmp16 = cpu_to_le16(param->u.utility.fifosize_kb); | ||
282 | cfpkt_add_body(pkt, &tmp16, 2); | ||
283 | tmp16 = cpu_to_le16(param->u.utility.fifosize_bufs); | ||
284 | cfpkt_add_body(pkt, &tmp16, 2); | ||
285 | memset(utility_name, 0, sizeof(utility_name)); | ||
286 | strncpy(utility_name, param->u.utility.name, | ||
287 | UTILITY_NAME_LENGTH - 1); | ||
288 | cfpkt_add_body(pkt, utility_name, UTILITY_NAME_LENGTH); | ||
289 | tmp8 = param->u.utility.paramlen; | ||
290 | cfpkt_add_body(pkt, &tmp8, 1); | ||
291 | cfpkt_add_body(pkt, param->u.utility.params, | ||
292 | param->u.utility.paramlen); | ||
293 | break; | ||
294 | default: | ||
295 | pr_warning("CAIF: %s():Request setup of bad link type = %d\n", | ||
296 | __func__, param->linktype); | ||
297 | } | ||
298 | req = kmalloc(sizeof(*req), GFP_KERNEL); | ||
299 | if (!req) { | ||
300 | pr_warning("CAIF: %s(): Out of memory\n", __func__); | ||
301 | return; | ||
302 | } | ||
303 | memset(req, 0, sizeof(*req)); | ||
304 | req->client_layer = user_layer; | ||
305 | req->cmd = CFCTRL_CMD_LINK_SETUP; | ||
306 | req->param = *param; | ||
307 | cfctrl_insert_req(cfctrl, req); | ||
308 | init_info(cfpkt_info(pkt), cfctrl); | ||
309 | cfpkt_info(pkt)->dev_info->id = param->phyid; | ||
310 | ret = | ||
311 | cfctrl->serv.layer.dn->transmit(cfctrl->serv.layer.dn, pkt); | ||
312 | if (ret < 0) { | ||
313 | pr_err("CAIF: %s(): Could not transmit linksetup request\n", | ||
314 | __func__); | ||
315 | cfpkt_destroy(pkt); | ||
316 | } | ||
317 | } | ||
318 | |||
319 | int cfctrl_linkdown_req(struct cflayer *layer, u8 channelid, | ||
320 | struct cflayer *client) | ||
321 | { | ||
322 | int ret; | ||
323 | struct cfctrl *cfctrl = container_obj(layer); | ||
324 | struct cfpkt *pkt = cfpkt_create(CFPKT_CTRL_PKT_LEN); | ||
325 | if (!pkt) { | ||
326 | pr_warning("CAIF: %s(): Out of memory\n", __func__); | ||
327 | return -ENOMEM; | ||
328 | } | ||
329 | cfctrl_insert_req2(cfctrl, CFCTRL_CMD_LINK_DESTROY, channelid, client); | ||
330 | cfpkt_addbdy(pkt, CFCTRL_CMD_LINK_DESTROY); | ||
331 | cfpkt_addbdy(pkt, channelid); | ||
332 | init_info(cfpkt_info(pkt), cfctrl); | ||
333 | ret = | ||
334 | cfctrl->serv.layer.dn->transmit(cfctrl->serv.layer.dn, pkt); | ||
335 | if (ret < 0) { | ||
336 | pr_err("CAIF: %s(): Could not transmit link-down request\n", | ||
337 | __func__); | ||
338 | cfpkt_destroy(pkt); | ||
339 | } | ||
340 | return ret; | ||
341 | } | ||
342 | |||
343 | void cfctrl_sleep_req(struct cflayer *layer) | ||
344 | { | ||
345 | int ret; | ||
346 | struct cfctrl *cfctrl = container_obj(layer); | ||
347 | struct cfpkt *pkt = cfpkt_create(CFPKT_CTRL_PKT_LEN); | ||
348 | if (!pkt) { | ||
349 | pr_warning("CAIF: %s(): Out of memory\n", __func__); | ||
350 | return; | ||
351 | } | ||
352 | cfpkt_addbdy(pkt, CFCTRL_CMD_SLEEP); | ||
353 | init_info(cfpkt_info(pkt), cfctrl); | ||
354 | ret = | ||
355 | cfctrl->serv.layer.dn->transmit(cfctrl->serv.layer.dn, pkt); | ||
356 | if (ret < 0) | ||
357 | cfpkt_destroy(pkt); | ||
358 | } | ||
359 | |||
360 | void cfctrl_wake_req(struct cflayer *layer) | ||
361 | { | ||
362 | int ret; | ||
363 | struct cfctrl *cfctrl = container_obj(layer); | ||
364 | struct cfpkt *pkt = cfpkt_create(CFPKT_CTRL_PKT_LEN); | ||
365 | if (!pkt) { | ||
366 | pr_warning("CAIF: %s(): Out of memory\n", __func__); | ||
367 | return; | ||
368 | } | ||
369 | cfpkt_addbdy(pkt, CFCTRL_CMD_WAKE); | ||
370 | init_info(cfpkt_info(pkt), cfctrl); | ||
371 | ret = | ||
372 | cfctrl->serv.layer.dn->transmit(cfctrl->serv.layer.dn, pkt); | ||
373 | if (ret < 0) | ||
374 | cfpkt_destroy(pkt); | ||
375 | } | ||
376 | |||
377 | void cfctrl_getstartreason_req(struct cflayer *layer) | ||
378 | { | ||
379 | int ret; | ||
380 | struct cfctrl *cfctrl = container_obj(layer); | ||
381 | struct cfpkt *pkt = cfpkt_create(CFPKT_CTRL_PKT_LEN); | ||
382 | if (!pkt) { | ||
383 | pr_warning("CAIF: %s(): Out of memory\n", __func__); | ||
384 | return; | ||
385 | } | ||
386 | cfpkt_addbdy(pkt, CFCTRL_CMD_START_REASON); | ||
387 | init_info(cfpkt_info(pkt), cfctrl); | ||
388 | ret = | ||
389 | cfctrl->serv.layer.dn->transmit(cfctrl->serv.layer.dn, pkt); | ||
390 | if (ret < 0) | ||
391 | cfpkt_destroy(pkt); | ||
392 | } | ||
393 | |||
394 | |||
395 | static int cfctrl_recv(struct cflayer *layer, struct cfpkt *pkt) | ||
396 | { | ||
397 | u8 cmdrsp; | ||
398 | u8 cmd; | ||
399 | int ret = -1; | ||
400 | u16 tmp16; | ||
401 | u8 len; | ||
402 | u8 param[255]; | ||
403 | u8 linkid; | ||
404 | struct cfctrl *cfctrl = container_obj(layer); | ||
405 | struct cfctrl_request_info rsp, *req; | ||
406 | |||
407 | |||
408 | cfpkt_extr_head(pkt, &cmdrsp, 1); | ||
409 | cmd = cmdrsp & CFCTRL_CMD_MASK; | ||
410 | if (cmd != CFCTRL_CMD_LINK_ERR | ||
411 | && CFCTRL_RSP_BIT != (CFCTRL_RSP_BIT & cmdrsp)) { | ||
412 | if (handle_loop(cfctrl, cmd, pkt) == CAIF_FAILURE) { | ||
413 | pr_info("CAIF: %s() CAIF Protocol error:" | ||
414 | "Response bit not set\n", __func__); | ||
415 | goto error; | ||
416 | } | ||
417 | } | ||
418 | |||
419 | switch (cmd) { | ||
420 | case CFCTRL_CMD_LINK_SETUP: | ||
421 | { | ||
422 | enum cfctrl_srv serv; | ||
423 | enum cfctrl_srv servtype; | ||
424 | u8 endpoint; | ||
425 | u8 physlinkid; | ||
426 | u8 prio; | ||
427 | u8 tmp; | ||
428 | u32 tmp32; | ||
429 | u8 *cp; | ||
430 | int i; | ||
431 | struct cfctrl_link_param linkparam; | ||
432 | memset(&linkparam, 0, sizeof(linkparam)); | ||
433 | |||
434 | cfpkt_extr_head(pkt, &tmp, 1); | ||
435 | |||
436 | serv = tmp & CFCTRL_SRV_MASK; | ||
437 | linkparam.linktype = serv; | ||
438 | |||
439 | servtype = tmp >> 4; | ||
440 | linkparam.chtype = servtype; | ||
441 | |||
442 | cfpkt_extr_head(pkt, &tmp, 1); | ||
443 | physlinkid = tmp & 0x07; | ||
444 | prio = tmp >> 3; | ||
445 | |||
446 | linkparam.priority = prio; | ||
447 | linkparam.phyid = physlinkid; | ||
448 | cfpkt_extr_head(pkt, &endpoint, 1); | ||
449 | linkparam.endpoint = endpoint & 0x03; | ||
450 | |||
451 | switch (serv) { | ||
452 | case CFCTRL_SRV_VEI: | ||
453 | case CFCTRL_SRV_DBG: | ||
454 | /* Link ID */ | ||
455 | cfpkt_extr_head(pkt, &linkid, 1); | ||
456 | break; | ||
457 | case CFCTRL_SRV_VIDEO: | ||
458 | cfpkt_extr_head(pkt, &tmp, 1); | ||
459 | linkparam.u.video.connid = tmp; | ||
460 | /* Link ID */ | ||
461 | cfpkt_extr_head(pkt, &linkid, 1); | ||
462 | break; | ||
463 | |||
464 | case CFCTRL_SRV_DATAGRAM: | ||
465 | cfpkt_extr_head(pkt, &tmp32, 4); | ||
466 | linkparam.u.datagram.connid = | ||
467 | le32_to_cpu(tmp32); | ||
468 | /* Link ID */ | ||
469 | cfpkt_extr_head(pkt, &linkid, 1); | ||
470 | break; | ||
471 | case CFCTRL_SRV_RFM: | ||
472 | /* Construct a frame, convert | ||
473 | * DatagramConnectionID | ||
474 | * to network format long and copy it out... | ||
475 | */ | ||
476 | cfpkt_extr_head(pkt, &tmp32, 4); | ||
477 | linkparam.u.rfm.connid = | ||
478 | le32_to_cpu(tmp32); | ||
479 | cp = (u8 *) linkparam.u.rfm.volume; | ||
480 | for (cfpkt_extr_head(pkt, &tmp, 1); | ||
481 | cfpkt_more(pkt) && tmp != '\0'; | ||
482 | cfpkt_extr_head(pkt, &tmp, 1)) | ||
483 | *cp++ = tmp; | ||
484 | *cp = '\0'; | ||
485 | |||
486 | /* Link ID */ | ||
487 | cfpkt_extr_head(pkt, &linkid, 1); | ||
488 | |||
489 | break; | ||
490 | case CFCTRL_SRV_UTIL: | ||
491 | /* Construct a frame, convert | ||
492 | * DatagramConnectionID | ||
493 | * to network format long and copy it out... | ||
494 | */ | ||
495 | /* Fifosize KB */ | ||
496 | cfpkt_extr_head(pkt, &tmp16, 2); | ||
497 | linkparam.u.utility.fifosize_kb = | ||
498 | le16_to_cpu(tmp16); | ||
499 | /* Fifosize bufs */ | ||
500 | cfpkt_extr_head(pkt, &tmp16, 2); | ||
501 | linkparam.u.utility.fifosize_bufs = | ||
502 | le16_to_cpu(tmp16); | ||
503 | /* name */ | ||
504 | cp = (u8 *) linkparam.u.utility.name; | ||
505 | caif_assert(sizeof(linkparam.u.utility.name) | ||
506 | >= UTILITY_NAME_LENGTH); | ||
507 | for (i = 0; | ||
508 | i < UTILITY_NAME_LENGTH | ||
509 | && cfpkt_more(pkt); i++) { | ||
510 | cfpkt_extr_head(pkt, &tmp, 1); | ||
511 | *cp++ = tmp; | ||
512 | } | ||
513 | /* Length */ | ||
514 | cfpkt_extr_head(pkt, &len, 1); | ||
515 | linkparam.u.utility.paramlen = len; | ||
516 | /* Param Data */ | ||
517 | cp = linkparam.u.utility.params; | ||
518 | while (cfpkt_more(pkt) && len--) { | ||
519 | cfpkt_extr_head(pkt, &tmp, 1); | ||
520 | *cp++ = tmp; | ||
521 | } | ||
522 | /* Link ID */ | ||
523 | cfpkt_extr_head(pkt, &linkid, 1); | ||
524 | /* Length */ | ||
525 | cfpkt_extr_head(pkt, &len, 1); | ||
526 | /* Param Data */ | ||
527 | cfpkt_extr_head(pkt, ¶m, len); | ||
528 | break; | ||
529 | default: | ||
530 | pr_warning("CAIF: %s(): Request setup " | ||
531 | "- invalid link type (%d)", | ||
532 | __func__, serv); | ||
533 | goto error; | ||
534 | } | ||
535 | |||
536 | rsp.cmd = cmd; | ||
537 | rsp.param = linkparam; | ||
538 | req = cfctrl_remove_req(cfctrl, &rsp); | ||
539 | |||
540 | if (CFCTRL_ERR_BIT == (CFCTRL_ERR_BIT & cmdrsp) || | ||
541 | cfpkt_erroneous(pkt)) { | ||
542 | pr_err("CAIF: %s(): Invalid O/E bit or parse " | ||
543 | "error on CAIF control channel", | ||
544 | __func__); | ||
545 | cfctrl->res.reject_rsp(cfctrl->serv.layer.up, | ||
546 | 0, | ||
547 | req ? req->client_layer | ||
548 | : NULL); | ||
549 | } else { | ||
550 | cfctrl->res.linksetup_rsp(cfctrl->serv. | ||
551 | layer.up, linkid, | ||
552 | serv, physlinkid, | ||
553 | req ? req-> | ||
554 | client_layer : NULL); | ||
555 | } | ||
556 | |||
557 | if (req != NULL) | ||
558 | kfree(req); | ||
559 | } | ||
560 | break; | ||
561 | case CFCTRL_CMD_LINK_DESTROY: | ||
562 | cfpkt_extr_head(pkt, &linkid, 1); | ||
563 | rsp.cmd = cmd; | ||
564 | rsp.channel_id = linkid; | ||
565 | req = cfctrl_remove_req(cfctrl, &rsp); | ||
566 | cfctrl->res.linkdestroy_rsp(cfctrl->serv.layer.up, linkid, | ||
567 | req ? req->client_layer : NULL); | ||
568 | if (req != NULL) | ||
569 | kfree(req); | ||
570 | break; | ||
571 | case CFCTRL_CMD_LINK_ERR: | ||
572 | pr_err("CAIF: %s(): Frame Error Indication received\n", | ||
573 | __func__); | ||
574 | cfctrl->res.linkerror_ind(); | ||
575 | break; | ||
576 | case CFCTRL_CMD_ENUM: | ||
577 | cfctrl->res.enum_rsp(); | ||
578 | break; | ||
579 | case CFCTRL_CMD_SLEEP: | ||
580 | cfctrl->res.sleep_rsp(); | ||
581 | break; | ||
582 | case CFCTRL_CMD_WAKE: | ||
583 | cfctrl->res.wake_rsp(); | ||
584 | break; | ||
585 | case CFCTRL_CMD_LINK_RECONF: | ||
586 | cfctrl->res.restart_rsp(); | ||
587 | break; | ||
588 | case CFCTRL_CMD_RADIO_SET: | ||
589 | cfctrl->res.radioset_rsp(); | ||
590 | break; | ||
591 | default: | ||
592 | pr_err("CAIF: %s(): Unrecognized Control Frame\n", __func__); | ||
593 | goto error; | ||
594 | break; | ||
595 | } | ||
596 | ret = 0; | ||
597 | error: | ||
598 | cfpkt_destroy(pkt); | ||
599 | return ret; | ||
600 | } | ||
601 | |||
602 | static void cfctrl_ctrlcmd(struct cflayer *layr, enum caif_ctrlcmd ctrl, | ||
603 | int phyid) | ||
604 | { | ||
605 | struct cfctrl *this = container_obj(layr); | ||
606 | switch (ctrl) { | ||
607 | case _CAIF_CTRLCMD_PHYIF_FLOW_OFF_IND: | ||
608 | case CAIF_CTRLCMD_FLOW_OFF_IND: | ||
609 | spin_lock(&this->info_list_lock); | ||
610 | if (this->first_req != NULL) { | ||
611 | pr_warning("CAIF: %s(): Received flow off in " | ||
612 | "control layer", __func__); | ||
613 | } | ||
614 | spin_unlock(&this->info_list_lock); | ||
615 | break; | ||
616 | default: | ||
617 | break; | ||
618 | } | ||
619 | } | ||
620 | |||
621 | #ifndef CAIF_NO_LOOP | ||
622 | static int handle_loop(struct cfctrl *ctrl, int cmd, struct cfpkt *pkt) | ||
623 | { | ||
624 | static int last_linkid; | ||
625 | u8 linkid, linktype, tmp; | ||
626 | switch (cmd) { | ||
627 | case CFCTRL_CMD_LINK_SETUP: | ||
628 | spin_lock(&ctrl->loop_linkid_lock); | ||
629 | for (linkid = last_linkid + 1; linkid < 255; linkid++) | ||
630 | if (!ctrl->loop_linkused[linkid]) | ||
631 | goto found; | ||
632 | for (linkid = last_linkid - 1; linkid > 0; linkid--) | ||
633 | if (!ctrl->loop_linkused[linkid]) | ||
634 | goto found; | ||
635 | spin_unlock(&ctrl->loop_linkid_lock); | ||
636 | return -EINVAL; | ||
637 | found: | ||
638 | if (!ctrl->loop_linkused[linkid]) | ||
639 | ctrl->loop_linkused[linkid] = 1; | ||
640 | |||
641 | last_linkid = linkid; | ||
642 | |||
643 | cfpkt_add_trail(pkt, &linkid, 1); | ||
644 | spin_unlock(&ctrl->loop_linkid_lock); | ||
645 | cfpkt_peek_head(pkt, &linktype, 1); | ||
646 | if (linktype == CFCTRL_SRV_UTIL) { | ||
647 | tmp = 0x01; | ||
648 | cfpkt_add_trail(pkt, &tmp, 1); | ||
649 | cfpkt_add_trail(pkt, &tmp, 1); | ||
650 | } | ||
651 | break; | ||
652 | |||
653 | case CFCTRL_CMD_LINK_DESTROY: | ||
654 | spin_lock(&ctrl->loop_linkid_lock); | ||
655 | cfpkt_peek_head(pkt, &linkid, 1); | ||
656 | ctrl->loop_linkused[linkid] = 0; | ||
657 | spin_unlock(&ctrl->loop_linkid_lock); | ||
658 | break; | ||
659 | default: | ||
660 | break; | ||
661 | } | ||
662 | return CAIF_SUCCESS; | ||
663 | } | ||
664 | #endif | ||
diff --git a/net/caif/cfdbgl.c b/net/caif/cfdbgl.c new file mode 100644 index 000000000000..ab6b6dc34cf8 --- /dev/null +++ b/net/caif/cfdbgl.c | |||
@@ -0,0 +1,40 @@ | |||
1 | /* | ||
2 | * Copyright (C) ST-Ericsson AB 2010 | ||
3 | * Author: Sjur Brendeland/sjur.brandeland@stericsson.com | ||
4 | * License terms: GNU General Public License (GPL) version 2 | ||
5 | */ | ||
6 | |||
7 | #include <linux/stddef.h> | ||
8 | #include <linux/slab.h> | ||
9 | #include <net/caif/caif_layer.h> | ||
10 | #include <net/caif/cfsrvl.h> | ||
11 | #include <net/caif/cfpkt.h> | ||
12 | |||
13 | static int cfdbgl_receive(struct cflayer *layr, struct cfpkt *pkt); | ||
14 | static int cfdbgl_transmit(struct cflayer *layr, struct cfpkt *pkt); | ||
15 | |||
16 | struct cflayer *cfdbgl_create(u8 channel_id, struct dev_info *dev_info) | ||
17 | { | ||
18 | struct cfsrvl *dbg = kmalloc(sizeof(struct cfsrvl), GFP_ATOMIC); | ||
19 | if (!dbg) { | ||
20 | pr_warning("CAIF: %s(): Out of memory\n", __func__); | ||
21 | return NULL; | ||
22 | } | ||
23 | caif_assert(offsetof(struct cfsrvl, layer) == 0); | ||
24 | memset(dbg, 0, sizeof(struct cfsrvl)); | ||
25 | cfsrvl_init(dbg, channel_id, dev_info); | ||
26 | dbg->layer.receive = cfdbgl_receive; | ||
27 | dbg->layer.transmit = cfdbgl_transmit; | ||
28 | snprintf(dbg->layer.name, CAIF_LAYER_NAME_SZ - 1, "dbg%d", channel_id); | ||
29 | return &dbg->layer; | ||
30 | } | ||
31 | |||
32 | static int cfdbgl_receive(struct cflayer *layr, struct cfpkt *pkt) | ||
33 | { | ||
34 | return layr->up->receive(layr->up, pkt); | ||
35 | } | ||
36 | |||
37 | static int cfdbgl_transmit(struct cflayer *layr, struct cfpkt *pkt) | ||
38 | { | ||
39 | return layr->dn->transmit(layr->dn, pkt); | ||
40 | } | ||
diff --git a/net/caif/cfdgml.c b/net/caif/cfdgml.c new file mode 100644 index 000000000000..53194840ecb6 --- /dev/null +++ b/net/caif/cfdgml.c | |||
@@ -0,0 +1,108 @@ | |||
1 | /* | ||
2 | * Copyright (C) ST-Ericsson AB 2010 | ||
3 | * Author: Sjur Brendeland/sjur.brandeland@stericsson.com | ||
4 | * License terms: GNU General Public License (GPL) version 2 | ||
5 | */ | ||
6 | |||
7 | #include <linux/stddef.h> | ||
8 | #include <linux/spinlock.h> | ||
9 | #include <linux/slab.h> | ||
10 | #include <net/caif/caif_layer.h> | ||
11 | #include <net/caif/cfsrvl.h> | ||
12 | #include <net/caif/cfpkt.h> | ||
13 | |||
14 | #define container_obj(layr) ((struct cfsrvl *) layr) | ||
15 | |||
16 | #define DGM_CMD_BIT 0x80 | ||
17 | #define DGM_FLOW_OFF 0x81 | ||
18 | #define DGM_FLOW_ON 0x80 | ||
19 | #define DGM_CTRL_PKT_SIZE 1 | ||
20 | |||
21 | static int cfdgml_receive(struct cflayer *layr, struct cfpkt *pkt); | ||
22 | static int cfdgml_transmit(struct cflayer *layr, struct cfpkt *pkt); | ||
23 | |||
24 | struct cflayer *cfdgml_create(u8 channel_id, struct dev_info *dev_info) | ||
25 | { | ||
26 | struct cfsrvl *dgm = kmalloc(sizeof(struct cfsrvl), GFP_ATOMIC); | ||
27 | if (!dgm) { | ||
28 | pr_warning("CAIF: %s(): Out of memory\n", __func__); | ||
29 | return NULL; | ||
30 | } | ||
31 | caif_assert(offsetof(struct cfsrvl, layer) == 0); | ||
32 | memset(dgm, 0, sizeof(struct cfsrvl)); | ||
33 | cfsrvl_init(dgm, channel_id, dev_info); | ||
34 | dgm->layer.receive = cfdgml_receive; | ||
35 | dgm->layer.transmit = cfdgml_transmit; | ||
36 | snprintf(dgm->layer.name, CAIF_LAYER_NAME_SZ - 1, "dgm%d", channel_id); | ||
37 | dgm->layer.name[CAIF_LAYER_NAME_SZ - 1] = '\0'; | ||
38 | return &dgm->layer; | ||
39 | } | ||
40 | |||
41 | static int cfdgml_receive(struct cflayer *layr, struct cfpkt *pkt) | ||
42 | { | ||
43 | u8 cmd = -1; | ||
44 | u8 dgmhdr[3]; | ||
45 | int ret; | ||
46 | caif_assert(layr->up != NULL); | ||
47 | caif_assert(layr->receive != NULL); | ||
48 | caif_assert(layr->ctrlcmd != NULL); | ||
49 | |||
50 | if (cfpkt_extr_head(pkt, &cmd, 1) < 0) { | ||
51 | pr_err("CAIF: %s(): Packet is erroneous!\n", __func__); | ||
52 | cfpkt_destroy(pkt); | ||
53 | return -EPROTO; | ||
54 | } | ||
55 | |||
56 | if ((cmd & DGM_CMD_BIT) == 0) { | ||
57 | if (cfpkt_extr_head(pkt, &dgmhdr, 3) < 0) { | ||
58 | pr_err("CAIF: %s(): Packet is erroneous!\n", __func__); | ||
59 | cfpkt_destroy(pkt); | ||
60 | return -EPROTO; | ||
61 | } | ||
62 | ret = layr->up->receive(layr->up, pkt); | ||
63 | return ret; | ||
64 | } | ||
65 | |||
66 | switch (cmd) { | ||
67 | case DGM_FLOW_OFF: /* FLOW OFF */ | ||
68 | layr->ctrlcmd(layr, CAIF_CTRLCMD_FLOW_OFF_IND, 0); | ||
69 | cfpkt_destroy(pkt); | ||
70 | return 0; | ||
71 | case DGM_FLOW_ON: /* FLOW ON */ | ||
72 | layr->ctrlcmd(layr, CAIF_CTRLCMD_FLOW_ON_IND, 0); | ||
73 | cfpkt_destroy(pkt); | ||
74 | return 0; | ||
75 | default: | ||
76 | cfpkt_destroy(pkt); | ||
77 | pr_info("CAIF: %s(): Unknown datagram control %d (0x%x)\n", | ||
78 | __func__, cmd, cmd); | ||
79 | return -EPROTO; | ||
80 | } | ||
81 | } | ||
82 | |||
83 | static int cfdgml_transmit(struct cflayer *layr, struct cfpkt *pkt) | ||
84 | { | ||
85 | u32 zero = 0; | ||
86 | struct caif_payload_info *info; | ||
87 | struct cfsrvl *service = container_obj(layr); | ||
88 | int ret; | ||
89 | if (!cfsrvl_ready(service, &ret)) | ||
90 | return ret; | ||
91 | |||
92 | cfpkt_add_head(pkt, &zero, 4); | ||
93 | |||
94 | /* Add info for MUX-layer to route the packet out. */ | ||
95 | info = cfpkt_info(pkt); | ||
96 | info->channel_id = service->layer.id; | ||
97 | /* To optimize alignment, we add up the size of CAIF header | ||
98 | * before payload. | ||
99 | */ | ||
100 | info->hdr_len = 4; | ||
101 | info->dev_info = &service->dev_info; | ||
102 | ret = layr->dn->transmit(layr->dn, pkt); | ||
103 | if (ret < 0) { | ||
104 | u32 tmp32; | ||
105 | cfpkt_extr_head(pkt, &tmp32, 4); | ||
106 | } | ||
107 | return ret; | ||
108 | } | ||
diff --git a/net/caif/cffrml.c b/net/caif/cffrml.c new file mode 100644 index 000000000000..e86a4ca3b217 --- /dev/null +++ b/net/caif/cffrml.c | |||
@@ -0,0 +1,151 @@ | |||
1 | /* | ||
2 | * CAIF Framing Layer. | ||
3 | * | ||
4 | * Copyright (C) ST-Ericsson AB 2010 | ||
5 | * Author: Sjur Brendeland/sjur.brandeland@stericsson.com | ||
6 | * License terms: GNU General Public License (GPL) version 2 | ||
7 | */ | ||
8 | |||
9 | #include <linux/stddef.h> | ||
10 | #include <linux/spinlock.h> | ||
11 | #include <linux/slab.h> | ||
12 | #include <linux/crc-ccitt.h> | ||
13 | #include <net/caif/caif_layer.h> | ||
14 | #include <net/caif/cfpkt.h> | ||
15 | #include <net/caif/cffrml.h> | ||
16 | |||
17 | #define container_obj(layr) container_of(layr, struct cffrml, layer) | ||
18 | |||
19 | struct cffrml { | ||
20 | struct cflayer layer; | ||
21 | bool dofcs; /* !< FCS active */ | ||
22 | }; | ||
23 | |||
24 | static int cffrml_receive(struct cflayer *layr, struct cfpkt *pkt); | ||
25 | static int cffrml_transmit(struct cflayer *layr, struct cfpkt *pkt); | ||
26 | static void cffrml_ctrlcmd(struct cflayer *layr, enum caif_ctrlcmd ctrl, | ||
27 | int phyid); | ||
28 | |||
29 | static u32 cffrml_rcv_error; | ||
30 | static u32 cffrml_rcv_checsum_error; | ||
31 | struct cflayer *cffrml_create(u16 phyid, bool use_fcs) | ||
32 | { | ||
33 | struct cffrml *this = kmalloc(sizeof(struct cffrml), GFP_ATOMIC); | ||
34 | if (!this) { | ||
35 | pr_warning("CAIF: %s(): Out of memory\n", __func__); | ||
36 | return NULL; | ||
37 | } | ||
38 | caif_assert(offsetof(struct cffrml, layer) == 0); | ||
39 | |||
40 | memset(this, 0, sizeof(struct cflayer)); | ||
41 | this->layer.receive = cffrml_receive; | ||
42 | this->layer.transmit = cffrml_transmit; | ||
43 | this->layer.ctrlcmd = cffrml_ctrlcmd; | ||
44 | snprintf(this->layer.name, CAIF_LAYER_NAME_SZ, "frm%d", phyid); | ||
45 | this->dofcs = use_fcs; | ||
46 | this->layer.id = phyid; | ||
47 | return (struct cflayer *) this; | ||
48 | } | ||
49 | |||
50 | void cffrml_set_uplayer(struct cflayer *this, struct cflayer *up) | ||
51 | { | ||
52 | this->up = up; | ||
53 | } | ||
54 | |||
55 | void cffrml_set_dnlayer(struct cflayer *this, struct cflayer *dn) | ||
56 | { | ||
57 | this->dn = dn; | ||
58 | } | ||
59 | |||
60 | static u16 cffrml_checksum(u16 chks, void *buf, u16 len) | ||
61 | { | ||
62 | /* FIXME: FCS should be moved to glue in order to use OS-Specific | ||
63 | * solutions | ||
64 | */ | ||
65 | return crc_ccitt(chks, buf, len); | ||
66 | } | ||
67 | |||
68 | static int cffrml_receive(struct cflayer *layr, struct cfpkt *pkt) | ||
69 | { | ||
70 | u16 tmp; | ||
71 | u16 len; | ||
72 | u16 hdrchks; | ||
73 | u16 pktchks; | ||
74 | struct cffrml *this; | ||
75 | this = container_obj(layr); | ||
76 | |||
77 | cfpkt_extr_head(pkt, &tmp, 2); | ||
78 | len = le16_to_cpu(tmp); | ||
79 | |||
80 | /* Subtract for FCS on length if FCS is not used. */ | ||
81 | if (!this->dofcs) | ||
82 | len -= 2; | ||
83 | |||
84 | if (cfpkt_setlen(pkt, len) < 0) { | ||
85 | ++cffrml_rcv_error; | ||
86 | pr_err("CAIF: %s():Framing length error (%d)\n", __func__, len); | ||
87 | cfpkt_destroy(pkt); | ||
88 | return -EPROTO; | ||
89 | } | ||
90 | /* | ||
91 | * Don't do extract if FCS is false, rather do setlen - then we don't | ||
92 | * get a cache-miss. | ||
93 | */ | ||
94 | if (this->dofcs) { | ||
95 | cfpkt_extr_trail(pkt, &tmp, 2); | ||
96 | hdrchks = le16_to_cpu(tmp); | ||
97 | pktchks = cfpkt_iterate(pkt, cffrml_checksum, 0xffff); | ||
98 | if (pktchks != hdrchks) { | ||
99 | cfpkt_add_trail(pkt, &tmp, 2); | ||
100 | ++cffrml_rcv_error; | ||
101 | ++cffrml_rcv_checsum_error; | ||
102 | pr_info("CAIF: %s(): Frame checksum error " | ||
103 | "(0x%x != 0x%x)\n", __func__, hdrchks, pktchks); | ||
104 | return -EILSEQ; | ||
105 | } | ||
106 | } | ||
107 | if (cfpkt_erroneous(pkt)) { | ||
108 | ++cffrml_rcv_error; | ||
109 | pr_err("CAIF: %s(): Packet is erroneous!\n", __func__); | ||
110 | cfpkt_destroy(pkt); | ||
111 | return -EPROTO; | ||
112 | } | ||
113 | return layr->up->receive(layr->up, pkt); | ||
114 | } | ||
115 | |||
116 | static int cffrml_transmit(struct cflayer *layr, struct cfpkt *pkt) | ||
117 | { | ||
118 | int tmp; | ||
119 | u16 chks; | ||
120 | u16 len; | ||
121 | int ret; | ||
122 | struct cffrml *this = container_obj(layr); | ||
123 | if (this->dofcs) { | ||
124 | chks = cfpkt_iterate(pkt, cffrml_checksum, 0xffff); | ||
125 | tmp = cpu_to_le16(chks); | ||
126 | cfpkt_add_trail(pkt, &tmp, 2); | ||
127 | } else { | ||
128 | cfpkt_pad_trail(pkt, 2); | ||
129 | } | ||
130 | len = cfpkt_getlen(pkt); | ||
131 | tmp = cpu_to_le16(len); | ||
132 | cfpkt_add_head(pkt, &tmp, 2); | ||
133 | cfpkt_info(pkt)->hdr_len += 2; | ||
134 | if (cfpkt_erroneous(pkt)) { | ||
135 | pr_err("CAIF: %s(): Packet is erroneous!\n", __func__); | ||
136 | return -EPROTO; | ||
137 | } | ||
138 | ret = layr->dn->transmit(layr->dn, pkt); | ||
139 | if (ret < 0) { | ||
140 | /* Remove header on faulty packet. */ | ||
141 | cfpkt_extr_head(pkt, &tmp, 2); | ||
142 | } | ||
143 | return ret; | ||
144 | } | ||
145 | |||
146 | static void cffrml_ctrlcmd(struct cflayer *layr, enum caif_ctrlcmd ctrl, | ||
147 | int phyid) | ||
148 | { | ||
149 | if (layr->up->ctrlcmd) | ||
150 | layr->up->ctrlcmd(layr->up, ctrl, layr->id); | ||
151 | } | ||
diff --git a/net/caif/cfmuxl.c b/net/caif/cfmuxl.c new file mode 100644 index 000000000000..6fb9f9e96cf8 --- /dev/null +++ b/net/caif/cfmuxl.c | |||
@@ -0,0 +1,246 @@ | |||
1 | /* | ||
2 | * Copyright (C) ST-Ericsson AB 2010 | ||
3 | * Author: Sjur Brendeland/sjur.brandeland@stericsson.com | ||
4 | * License terms: GNU General Public License (GPL) version 2 | ||
5 | */ | ||
6 | #include <linux/stddef.h> | ||
7 | #include <linux/spinlock.h> | ||
8 | #include <linux/slab.h> | ||
9 | #include <net/caif/cfpkt.h> | ||
10 | #include <net/caif/cfmuxl.h> | ||
11 | #include <net/caif/cfsrvl.h> | ||
12 | #include <net/caif/cffrml.h> | ||
13 | |||
14 | #define container_obj(layr) container_of(layr, struct cfmuxl, layer) | ||
15 | |||
16 | #define CAIF_CTRL_CHANNEL 0 | ||
17 | #define UP_CACHE_SIZE 8 | ||
18 | #define DN_CACHE_SIZE 8 | ||
19 | |||
20 | struct cfmuxl { | ||
21 | struct cflayer layer; | ||
22 | struct list_head srvl_list; | ||
23 | struct list_head frml_list; | ||
24 | struct cflayer *up_cache[UP_CACHE_SIZE]; | ||
25 | struct cflayer *dn_cache[DN_CACHE_SIZE]; | ||
26 | /* | ||
27 | * Set when inserting or removing downwards layers. | ||
28 | */ | ||
29 | spinlock_t transmit_lock; | ||
30 | |||
31 | /* | ||
32 | * Set when inserting or removing upwards layers. | ||
33 | */ | ||
34 | spinlock_t receive_lock; | ||
35 | |||
36 | }; | ||
37 | |||
38 | static int cfmuxl_receive(struct cflayer *layr, struct cfpkt *pkt); | ||
39 | static int cfmuxl_transmit(struct cflayer *layr, struct cfpkt *pkt); | ||
40 | static void cfmuxl_ctrlcmd(struct cflayer *layr, enum caif_ctrlcmd ctrl, | ||
41 | int phyid); | ||
42 | static struct cflayer *get_up(struct cfmuxl *muxl, u16 id); | ||
43 | |||
44 | struct cflayer *cfmuxl_create(void) | ||
45 | { | ||
46 | struct cfmuxl *this = kmalloc(sizeof(struct cfmuxl), GFP_ATOMIC); | ||
47 | if (!this) | ||
48 | return NULL; | ||
49 | memset(this, 0, sizeof(*this)); | ||
50 | this->layer.receive = cfmuxl_receive; | ||
51 | this->layer.transmit = cfmuxl_transmit; | ||
52 | this->layer.ctrlcmd = cfmuxl_ctrlcmd; | ||
53 | INIT_LIST_HEAD(&this->srvl_list); | ||
54 | INIT_LIST_HEAD(&this->frml_list); | ||
55 | spin_lock_init(&this->transmit_lock); | ||
56 | spin_lock_init(&this->receive_lock); | ||
57 | snprintf(this->layer.name, CAIF_LAYER_NAME_SZ, "mux"); | ||
58 | return &this->layer; | ||
59 | } | ||
60 | |||
61 | int cfmuxl_set_uplayer(struct cflayer *layr, struct cflayer *up, u8 linkid) | ||
62 | { | ||
63 | struct cfmuxl *muxl = container_obj(layr); | ||
64 | spin_lock(&muxl->receive_lock); | ||
65 | list_add(&up->node, &muxl->srvl_list); | ||
66 | spin_unlock(&muxl->receive_lock); | ||
67 | return 0; | ||
68 | } | ||
69 | |||
70 | bool cfmuxl_is_phy_inuse(struct cflayer *layr, u8 phyid) | ||
71 | { | ||
72 | struct list_head *node; | ||
73 | struct cflayer *layer; | ||
74 | struct cfmuxl *muxl = container_obj(layr); | ||
75 | bool match = false; | ||
76 | spin_lock(&muxl->receive_lock); | ||
77 | |||
78 | list_for_each(node, &muxl->srvl_list) { | ||
79 | layer = list_entry(node, struct cflayer, node); | ||
80 | if (cfsrvl_phyid_match(layer, phyid)) { | ||
81 | match = true; | ||
82 | break; | ||
83 | } | ||
84 | |||
85 | } | ||
86 | spin_unlock(&muxl->receive_lock); | ||
87 | return match; | ||
88 | } | ||
89 | |||
90 | u8 cfmuxl_get_phyid(struct cflayer *layr, u8 channel_id) | ||
91 | { | ||
92 | struct cflayer *up; | ||
93 | int phyid; | ||
94 | struct cfmuxl *muxl = container_obj(layr); | ||
95 | spin_lock(&muxl->receive_lock); | ||
96 | up = get_up(muxl, channel_id); | ||
97 | if (up != NULL) | ||
98 | phyid = cfsrvl_getphyid(up); | ||
99 | else | ||
100 | phyid = 0; | ||
101 | spin_unlock(&muxl->receive_lock); | ||
102 | return phyid; | ||
103 | } | ||
104 | |||
105 | int cfmuxl_set_dnlayer(struct cflayer *layr, struct cflayer *dn, u8 phyid) | ||
106 | { | ||
107 | struct cfmuxl *muxl = (struct cfmuxl *) layr; | ||
108 | spin_lock(&muxl->transmit_lock); | ||
109 | list_add(&dn->node, &muxl->frml_list); | ||
110 | spin_unlock(&muxl->transmit_lock); | ||
111 | return 0; | ||
112 | } | ||
113 | |||
114 | static struct cflayer *get_from_id(struct list_head *list, u16 id) | ||
115 | { | ||
116 | struct list_head *node; | ||
117 | struct cflayer *layer; | ||
118 | list_for_each(node, list) { | ||
119 | layer = list_entry(node, struct cflayer, node); | ||
120 | if (layer->id == id) | ||
121 | return layer; | ||
122 | } | ||
123 | return NULL; | ||
124 | } | ||
125 | |||
126 | struct cflayer *cfmuxl_remove_dnlayer(struct cflayer *layr, u8 phyid) | ||
127 | { | ||
128 | struct cfmuxl *muxl = container_obj(layr); | ||
129 | struct cflayer *dn; | ||
130 | spin_lock(&muxl->transmit_lock); | ||
131 | memset(muxl->dn_cache, 0, sizeof(muxl->dn_cache)); | ||
132 | dn = get_from_id(&muxl->frml_list, phyid); | ||
133 | if (dn == NULL) { | ||
134 | spin_unlock(&muxl->transmit_lock); | ||
135 | return NULL; | ||
136 | } | ||
137 | list_del(&dn->node); | ||
138 | caif_assert(dn != NULL); | ||
139 | spin_unlock(&muxl->transmit_lock); | ||
140 | return dn; | ||
141 | } | ||
142 | |||
143 | /* Invariant: lock is taken */ | ||
144 | static struct cflayer *get_up(struct cfmuxl *muxl, u16 id) | ||
145 | { | ||
146 | struct cflayer *up; | ||
147 | int idx = id % UP_CACHE_SIZE; | ||
148 | up = muxl->up_cache[idx]; | ||
149 | if (up == NULL || up->id != id) { | ||
150 | up = get_from_id(&muxl->srvl_list, id); | ||
151 | muxl->up_cache[idx] = up; | ||
152 | } | ||
153 | return up; | ||
154 | } | ||
155 | |||
156 | /* Invariant: lock is taken */ | ||
157 | static struct cflayer *get_dn(struct cfmuxl *muxl, struct dev_info *dev_info) | ||
158 | { | ||
159 | struct cflayer *dn; | ||
160 | int idx = dev_info->id % DN_CACHE_SIZE; | ||
161 | dn = muxl->dn_cache[idx]; | ||
162 | if (dn == NULL || dn->id != dev_info->id) { | ||
163 | dn = get_from_id(&muxl->frml_list, dev_info->id); | ||
164 | muxl->dn_cache[idx] = dn; | ||
165 | } | ||
166 | return dn; | ||
167 | } | ||
168 | |||
169 | struct cflayer *cfmuxl_remove_uplayer(struct cflayer *layr, u8 id) | ||
170 | { | ||
171 | struct cflayer *up; | ||
172 | struct cfmuxl *muxl = container_obj(layr); | ||
173 | spin_lock(&muxl->receive_lock); | ||
174 | up = get_up(muxl, id); | ||
175 | memset(muxl->up_cache, 0, sizeof(muxl->up_cache)); | ||
176 | list_del(&up->node); | ||
177 | spin_unlock(&muxl->receive_lock); | ||
178 | return up; | ||
179 | } | ||
180 | |||
181 | static int cfmuxl_receive(struct cflayer *layr, struct cfpkt *pkt) | ||
182 | { | ||
183 | int ret; | ||
184 | struct cfmuxl *muxl = container_obj(layr); | ||
185 | u8 id; | ||
186 | struct cflayer *up; | ||
187 | if (cfpkt_extr_head(pkt, &id, 1) < 0) { | ||
188 | pr_err("CAIF: %s(): erroneous Caif Packet\n", __func__); | ||
189 | cfpkt_destroy(pkt); | ||
190 | return -EPROTO; | ||
191 | } | ||
192 | |||
193 | spin_lock(&muxl->receive_lock); | ||
194 | up = get_up(muxl, id); | ||
195 | spin_unlock(&muxl->receive_lock); | ||
196 | if (up == NULL) { | ||
197 | pr_info("CAIF: %s():Received data on unknown link ID = %d " | ||
198 | "(0x%x) up == NULL", __func__, id, id); | ||
199 | cfpkt_destroy(pkt); | ||
200 | /* | ||
201 | * Don't return ERROR, since modem misbehaves and sends out | ||
202 | * flow on before linksetup response. | ||
203 | */ | ||
204 | return /* CFGLU_EPROT; */ 0; | ||
205 | } | ||
206 | |||
207 | ret = up->receive(up, pkt); | ||
208 | return ret; | ||
209 | } | ||
210 | |||
211 | static int cfmuxl_transmit(struct cflayer *layr, struct cfpkt *pkt) | ||
212 | { | ||
213 | int ret; | ||
214 | struct cfmuxl *muxl = container_obj(layr); | ||
215 | u8 linkid; | ||
216 | struct cflayer *dn; | ||
217 | struct caif_payload_info *info = cfpkt_info(pkt); | ||
218 | dn = get_dn(muxl, cfpkt_info(pkt)->dev_info); | ||
219 | if (dn == NULL) { | ||
220 | pr_warning("CAIF: %s(): Send data on unknown phy " | ||
221 | "ID = %d (0x%x)\n", | ||
222 | __func__, info->dev_info->id, info->dev_info->id); | ||
223 | return -ENOTCONN; | ||
224 | } | ||
225 | info->hdr_len += 1; | ||
226 | linkid = info->channel_id; | ||
227 | cfpkt_add_head(pkt, &linkid, 1); | ||
228 | ret = dn->transmit(dn, pkt); | ||
229 | /* Remove MUX protocol header upon error. */ | ||
230 | if (ret < 0) | ||
231 | cfpkt_extr_head(pkt, &linkid, 1); | ||
232 | return ret; | ||
233 | } | ||
234 | |||
235 | static void cfmuxl_ctrlcmd(struct cflayer *layr, enum caif_ctrlcmd ctrl, | ||
236 | int phyid) | ||
237 | { | ||
238 | struct cfmuxl *muxl = container_obj(layr); | ||
239 | struct list_head *node; | ||
240 | struct cflayer *layer; | ||
241 | list_for_each(node, &muxl->srvl_list) { | ||
242 | layer = list_entry(node, struct cflayer, node); | ||
243 | if (cfsrvl_phyid_match(layer, phyid)) | ||
244 | layer->ctrlcmd(layer, ctrl, phyid); | ||
245 | } | ||
246 | } | ||
diff --git a/net/caif/cfpkt_skbuff.c b/net/caif/cfpkt_skbuff.c new file mode 100644 index 000000000000..83fff2ff6658 --- /dev/null +++ b/net/caif/cfpkt_skbuff.c | |||
@@ -0,0 +1,571 @@ | |||
1 | /* | ||
2 | * Copyright (C) ST-Ericsson AB 2010 | ||
3 | * Author: Sjur Brendeland/sjur.brandeland@stericsson.com | ||
4 | * License terms: GNU General Public License (GPL) version 2 | ||
5 | */ | ||
6 | |||
7 | #include <linux/string.h> | ||
8 | #include <linux/skbuff.h> | ||
9 | #include <linux/hardirq.h> | ||
10 | #include <net/caif/cfpkt.h> | ||
11 | |||
12 | #define PKT_PREFIX CAIF_NEEDED_HEADROOM | ||
13 | #define PKT_POSTFIX CAIF_NEEDED_TAILROOM | ||
14 | #define PKT_LEN_WHEN_EXTENDING 128 | ||
15 | #define PKT_ERROR(pkt, errmsg) do { \ | ||
16 | cfpkt_priv(pkt)->erronous = true; \ | ||
17 | skb_reset_tail_pointer(&pkt->skb); \ | ||
18 | pr_warning("CAIF: " errmsg);\ | ||
19 | } while (0) | ||
20 | |||
21 | struct cfpktq { | ||
22 | struct sk_buff_head head; | ||
23 | atomic_t count; | ||
24 | /* Lock protects count updates */ | ||
25 | spinlock_t lock; | ||
26 | }; | ||
27 | |||
28 | /* | ||
29 | * net/caif/ is generic and does not | ||
30 | * understand SKB, so we do this typecast | ||
31 | */ | ||
32 | struct cfpkt { | ||
33 | struct sk_buff skb; | ||
34 | }; | ||
35 | |||
36 | /* Private data inside SKB */ | ||
37 | struct cfpkt_priv_data { | ||
38 | struct dev_info dev_info; | ||
39 | bool erronous; | ||
40 | }; | ||
41 | |||
42 | inline struct cfpkt_priv_data *cfpkt_priv(struct cfpkt *pkt) | ||
43 | { | ||
44 | return (struct cfpkt_priv_data *) pkt->skb.cb; | ||
45 | } | ||
46 | |||
47 | inline bool is_erronous(struct cfpkt *pkt) | ||
48 | { | ||
49 | return cfpkt_priv(pkt)->erronous; | ||
50 | } | ||
51 | |||
52 | inline struct sk_buff *pkt_to_skb(struct cfpkt *pkt) | ||
53 | { | ||
54 | return &pkt->skb; | ||
55 | } | ||
56 | |||
57 | inline struct cfpkt *skb_to_pkt(struct sk_buff *skb) | ||
58 | { | ||
59 | return (struct cfpkt *) skb; | ||
60 | } | ||
61 | |||
62 | |||
63 | struct cfpkt *cfpkt_fromnative(enum caif_direction dir, void *nativepkt) | ||
64 | { | ||
65 | struct cfpkt *pkt = skb_to_pkt(nativepkt); | ||
66 | cfpkt_priv(pkt)->erronous = false; | ||
67 | return pkt; | ||
68 | } | ||
69 | EXPORT_SYMBOL(cfpkt_fromnative); | ||
70 | |||
71 | void *cfpkt_tonative(struct cfpkt *pkt) | ||
72 | { | ||
73 | return (void *) pkt; | ||
74 | } | ||
75 | EXPORT_SYMBOL(cfpkt_tonative); | ||
76 | |||
77 | static struct cfpkt *cfpkt_create_pfx(u16 len, u16 pfx) | ||
78 | { | ||
79 | struct sk_buff *skb; | ||
80 | |||
81 | if (likely(in_interrupt())) | ||
82 | skb = alloc_skb(len + pfx, GFP_ATOMIC); | ||
83 | else | ||
84 | skb = alloc_skb(len + pfx, GFP_KERNEL); | ||
85 | |||
86 | if (unlikely(skb == NULL)) | ||
87 | return NULL; | ||
88 | |||
89 | skb_reserve(skb, pfx); | ||
90 | return skb_to_pkt(skb); | ||
91 | } | ||
92 | |||
93 | inline struct cfpkt *cfpkt_create(u16 len) | ||
94 | { | ||
95 | return cfpkt_create_pfx(len + PKT_POSTFIX, PKT_PREFIX); | ||
96 | } | ||
97 | EXPORT_SYMBOL(cfpkt_create); | ||
98 | |||
99 | void cfpkt_destroy(struct cfpkt *pkt) | ||
100 | { | ||
101 | struct sk_buff *skb = pkt_to_skb(pkt); | ||
102 | kfree_skb(skb); | ||
103 | } | ||
104 | EXPORT_SYMBOL(cfpkt_destroy); | ||
105 | |||
106 | inline bool cfpkt_more(struct cfpkt *pkt) | ||
107 | { | ||
108 | struct sk_buff *skb = pkt_to_skb(pkt); | ||
109 | return skb->len > 0; | ||
110 | } | ||
111 | EXPORT_SYMBOL(cfpkt_more); | ||
112 | |||
113 | int cfpkt_peek_head(struct cfpkt *pkt, void *data, u16 len) | ||
114 | { | ||
115 | struct sk_buff *skb = pkt_to_skb(pkt); | ||
116 | if (skb_headlen(skb) >= len) { | ||
117 | memcpy(data, skb->data, len); | ||
118 | return 0; | ||
119 | } | ||
120 | return !cfpkt_extr_head(pkt, data, len) && | ||
121 | !cfpkt_add_head(pkt, data, len); | ||
122 | } | ||
123 | EXPORT_SYMBOL(cfpkt_peek_head); | ||
124 | |||
125 | int cfpkt_extr_head(struct cfpkt *pkt, void *data, u16 len) | ||
126 | { | ||
127 | struct sk_buff *skb = pkt_to_skb(pkt); | ||
128 | u8 *from; | ||
129 | if (unlikely(is_erronous(pkt))) | ||
130 | return -EPROTO; | ||
131 | |||
132 | if (unlikely(len > skb->len)) { | ||
133 | PKT_ERROR(pkt, "cfpkt_extr_head read beyond end of packet\n"); | ||
134 | return -EPROTO; | ||
135 | } | ||
136 | |||
137 | if (unlikely(len > skb_headlen(skb))) { | ||
138 | if (unlikely(skb_linearize(skb) != 0)) { | ||
139 | PKT_ERROR(pkt, "cfpkt_extr_head linearize failed\n"); | ||
140 | return -EPROTO; | ||
141 | } | ||
142 | } | ||
143 | from = skb_pull(skb, len); | ||
144 | from -= len; | ||
145 | memcpy(data, from, len); | ||
146 | return 0; | ||
147 | } | ||
148 | EXPORT_SYMBOL(cfpkt_extr_head); | ||
149 | |||
150 | int cfpkt_extr_trail(struct cfpkt *pkt, void *dta, u16 len) | ||
151 | { | ||
152 | struct sk_buff *skb = pkt_to_skb(pkt); | ||
153 | u8 *data = dta; | ||
154 | u8 *from; | ||
155 | if (unlikely(is_erronous(pkt))) | ||
156 | return -EPROTO; | ||
157 | |||
158 | if (unlikely(skb_linearize(skb) != 0)) { | ||
159 | PKT_ERROR(pkt, "cfpkt_extr_trail linearize failed\n"); | ||
160 | return -EPROTO; | ||
161 | } | ||
162 | if (unlikely(skb->data + len > skb_tail_pointer(skb))) { | ||
163 | PKT_ERROR(pkt, "cfpkt_extr_trail read beyond end of packet\n"); | ||
164 | return -EPROTO; | ||
165 | } | ||
166 | from = skb_tail_pointer(skb) - len; | ||
167 | skb_trim(skb, skb->len - len); | ||
168 | memcpy(data, from, len); | ||
169 | return 0; | ||
170 | } | ||
171 | EXPORT_SYMBOL(cfpkt_extr_trail); | ||
172 | |||
173 | int cfpkt_pad_trail(struct cfpkt *pkt, u16 len) | ||
174 | { | ||
175 | return cfpkt_add_body(pkt, NULL, len); | ||
176 | } | ||
177 | EXPORT_SYMBOL(cfpkt_pad_trail); | ||
178 | |||
179 | int cfpkt_add_body(struct cfpkt *pkt, const void *data, u16 len) | ||
180 | { | ||
181 | struct sk_buff *skb = pkt_to_skb(pkt); | ||
182 | struct sk_buff *lastskb; | ||
183 | u8 *to; | ||
184 | u16 addlen = 0; | ||
185 | |||
186 | |||
187 | if (unlikely(is_erronous(pkt))) | ||
188 | return -EPROTO; | ||
189 | |||
190 | lastskb = skb; | ||
191 | |||
192 | /* Check whether we need to add space at the tail */ | ||
193 | if (unlikely(skb_tailroom(skb) < len)) { | ||
194 | if (likely(len < PKT_LEN_WHEN_EXTENDING)) | ||
195 | addlen = PKT_LEN_WHEN_EXTENDING; | ||
196 | else | ||
197 | addlen = len; | ||
198 | } | ||
199 | |||
200 | /* Check whether we need to change the SKB before writing to the tail */ | ||
201 | if (unlikely((addlen > 0) || skb_cloned(skb) || skb_shared(skb))) { | ||
202 | |||
203 | /* Make sure data is writable */ | ||
204 | if (unlikely(skb_cow_data(skb, addlen, &lastskb) < 0)) { | ||
205 | PKT_ERROR(pkt, "cfpkt_add_body: cow failed\n"); | ||
206 | return -EPROTO; | ||
207 | } | ||
208 | /* | ||
209 | * Is the SKB non-linear after skb_cow_data()? If so, we are | ||
210 | * going to add data to the last SKB, so we need to adjust | ||
211 | * lengths of the top SKB. | ||
212 | */ | ||
213 | if (lastskb != skb) { | ||
214 | pr_warning("CAIF: %s(): Packet is non-linear\n", | ||
215 | __func__); | ||
216 | skb->len += len; | ||
217 | skb->data_len += len; | ||
218 | } | ||
219 | } | ||
220 | |||
221 | /* All set to put the last SKB and optionally write data there. */ | ||
222 | to = skb_put(lastskb, len); | ||
223 | if (likely(data)) | ||
224 | memcpy(to, data, len); | ||
225 | return 0; | ||
226 | } | ||
227 | EXPORT_SYMBOL(cfpkt_add_body); | ||
228 | |||
229 | inline int cfpkt_addbdy(struct cfpkt *pkt, u8 data) | ||
230 | { | ||
231 | return cfpkt_add_body(pkt, &data, 1); | ||
232 | } | ||
233 | EXPORT_SYMBOL(cfpkt_addbdy); | ||
234 | |||
235 | int cfpkt_add_head(struct cfpkt *pkt, const void *data2, u16 len) | ||
236 | { | ||
237 | struct sk_buff *skb = pkt_to_skb(pkt); | ||
238 | struct sk_buff *lastskb; | ||
239 | u8 *to; | ||
240 | const u8 *data = data2; | ||
241 | if (unlikely(is_erronous(pkt))) | ||
242 | return -EPROTO; | ||
243 | if (unlikely(skb_headroom(skb) < len)) { | ||
244 | PKT_ERROR(pkt, "cfpkt_add_head: no headroom\n"); | ||
245 | return -EPROTO; | ||
246 | } | ||
247 | |||
248 | /* Make sure data is writable */ | ||
249 | if (unlikely(skb_cow_data(skb, 0, &lastskb) < 0)) { | ||
250 | PKT_ERROR(pkt, "cfpkt_add_head: cow failed\n"); | ||
251 | return -EPROTO; | ||
252 | } | ||
253 | |||
254 | to = skb_push(skb, len); | ||
255 | memcpy(to, data, len); | ||
256 | return 0; | ||
257 | } | ||
258 | EXPORT_SYMBOL(cfpkt_add_head); | ||
259 | |||
260 | inline int cfpkt_add_trail(struct cfpkt *pkt, const void *data, u16 len) | ||
261 | { | ||
262 | return cfpkt_add_body(pkt, data, len); | ||
263 | } | ||
264 | EXPORT_SYMBOL(cfpkt_add_trail); | ||
265 | |||
266 | inline u16 cfpkt_getlen(struct cfpkt *pkt) | ||
267 | { | ||
268 | struct sk_buff *skb = pkt_to_skb(pkt); | ||
269 | return skb->len; | ||
270 | } | ||
271 | EXPORT_SYMBOL(cfpkt_getlen); | ||
272 | |||
273 | inline u16 cfpkt_iterate(struct cfpkt *pkt, | ||
274 | u16 (*iter_func)(u16, void *, u16), | ||
275 | u16 data) | ||
276 | { | ||
277 | /* | ||
278 | * Don't care about the performance hit of linearizing, | ||
279 | * Checksum should not be used on high-speed interfaces anyway. | ||
280 | */ | ||
281 | if (unlikely(is_erronous(pkt))) | ||
282 | return -EPROTO; | ||
283 | if (unlikely(skb_linearize(&pkt->skb) != 0)) { | ||
284 | PKT_ERROR(pkt, "cfpkt_iterate: linearize failed\n"); | ||
285 | return -EPROTO; | ||
286 | } | ||
287 | return iter_func(data, pkt->skb.data, cfpkt_getlen(pkt)); | ||
288 | } | ||
289 | EXPORT_SYMBOL(cfpkt_iterate); | ||
290 | |||
291 | int cfpkt_setlen(struct cfpkt *pkt, u16 len) | ||
292 | { | ||
293 | struct sk_buff *skb = pkt_to_skb(pkt); | ||
294 | |||
295 | |||
296 | if (unlikely(is_erronous(pkt))) | ||
297 | return -EPROTO; | ||
298 | |||
299 | if (likely(len <= skb->len)) { | ||
300 | if (unlikely(skb->data_len)) | ||
301 | ___pskb_trim(skb, len); | ||
302 | else | ||
303 | skb_trim(skb, len); | ||
304 | |||
305 | return cfpkt_getlen(pkt); | ||
306 | } | ||
307 | |||
308 | /* Need to expand SKB */ | ||
309 | if (unlikely(!cfpkt_pad_trail(pkt, len - skb->len))) | ||
310 | PKT_ERROR(pkt, "cfpkt_setlen: skb_pad_trail failed\n"); | ||
311 | |||
312 | return cfpkt_getlen(pkt); | ||
313 | } | ||
314 | EXPORT_SYMBOL(cfpkt_setlen); | ||
315 | |||
316 | struct cfpkt *cfpkt_create_uplink(const unsigned char *data, unsigned int len) | ||
317 | { | ||
318 | struct cfpkt *pkt = cfpkt_create_pfx(len + PKT_POSTFIX, PKT_PREFIX); | ||
319 | if (unlikely(data != NULL)) | ||
320 | cfpkt_add_body(pkt, data, len); | ||
321 | return pkt; | ||
322 | } | ||
323 | EXPORT_SYMBOL(cfpkt_create_uplink); | ||
324 | |||
325 | struct cfpkt *cfpkt_append(struct cfpkt *dstpkt, | ||
326 | struct cfpkt *addpkt, | ||
327 | u16 expectlen) | ||
328 | { | ||
329 | struct sk_buff *dst = pkt_to_skb(dstpkt); | ||
330 | struct sk_buff *add = pkt_to_skb(addpkt); | ||
331 | u16 addlen = skb_headlen(add); | ||
332 | u16 neededtailspace; | ||
333 | struct sk_buff *tmp; | ||
334 | u16 dstlen; | ||
335 | u16 createlen; | ||
336 | if (unlikely(is_erronous(dstpkt) || is_erronous(addpkt))) { | ||
337 | cfpkt_destroy(addpkt); | ||
338 | return dstpkt; | ||
339 | } | ||
340 | if (expectlen > addlen) | ||
341 | neededtailspace = expectlen; | ||
342 | else | ||
343 | neededtailspace = addlen; | ||
344 | |||
345 | if (dst->tail + neededtailspace > dst->end) { | ||
346 | /* Create a dumplicate of 'dst' with more tail space */ | ||
347 | dstlen = skb_headlen(dst); | ||
348 | createlen = dstlen + neededtailspace; | ||
349 | tmp = pkt_to_skb( | ||
350 | cfpkt_create(createlen + PKT_PREFIX + PKT_POSTFIX)); | ||
351 | if (!tmp) | ||
352 | return NULL; | ||
353 | skb_set_tail_pointer(tmp, dstlen); | ||
354 | tmp->len = dstlen; | ||
355 | memcpy(tmp->data, dst->data, dstlen); | ||
356 | cfpkt_destroy(dstpkt); | ||
357 | dst = tmp; | ||
358 | } | ||
359 | memcpy(skb_tail_pointer(dst), add->data, skb_headlen(add)); | ||
360 | cfpkt_destroy(addpkt); | ||
361 | dst->tail += addlen; | ||
362 | dst->len += addlen; | ||
363 | return skb_to_pkt(dst); | ||
364 | } | ||
365 | EXPORT_SYMBOL(cfpkt_append); | ||
366 | |||
367 | struct cfpkt *cfpkt_split(struct cfpkt *pkt, u16 pos) | ||
368 | { | ||
369 | struct sk_buff *skb2; | ||
370 | struct sk_buff *skb = pkt_to_skb(pkt); | ||
371 | u8 *split = skb->data + pos; | ||
372 | u16 len2nd = skb_tail_pointer(skb) - split; | ||
373 | |||
374 | if (unlikely(is_erronous(pkt))) | ||
375 | return NULL; | ||
376 | |||
377 | if (skb->data + pos > skb_tail_pointer(skb)) { | ||
378 | PKT_ERROR(pkt, | ||
379 | "cfpkt_split: trying to split beyond end of packet"); | ||
380 | return NULL; | ||
381 | } | ||
382 | |||
383 | /* Create a new packet for the second part of the data */ | ||
384 | skb2 = pkt_to_skb( | ||
385 | cfpkt_create_pfx(len2nd + PKT_PREFIX + PKT_POSTFIX, | ||
386 | PKT_PREFIX)); | ||
387 | |||
388 | if (skb2 == NULL) | ||
389 | return NULL; | ||
390 | |||
391 | /* Reduce the length of the original packet */ | ||
392 | skb_set_tail_pointer(skb, pos); | ||
393 | skb->len = pos; | ||
394 | |||
395 | memcpy(skb2->data, split, len2nd); | ||
396 | skb2->tail += len2nd; | ||
397 | skb2->len += len2nd; | ||
398 | return skb_to_pkt(skb2); | ||
399 | } | ||
400 | EXPORT_SYMBOL(cfpkt_split); | ||
401 | |||
402 | char *cfpkt_log_pkt(struct cfpkt *pkt, char *buf, int buflen) | ||
403 | { | ||
404 | struct sk_buff *skb = pkt_to_skb(pkt); | ||
405 | char *p = buf; | ||
406 | int i; | ||
407 | |||
408 | /* | ||
409 | * Sanity check buffer length, it needs to be at least as large as | ||
410 | * the header info: ~=50+ bytes | ||
411 | */ | ||
412 | if (buflen < 50) | ||
413 | return NULL; | ||
414 | |||
415 | snprintf(buf, buflen, "%s: pkt:%p len:%ld(%ld+%ld) {%ld,%ld} data: [", | ||
416 | is_erronous(pkt) ? "ERRONOUS-SKB" : | ||
417 | (skb->data_len != 0 ? "COMPLEX-SKB" : "SKB"), | ||
418 | skb, | ||
419 | (long) skb->len, | ||
420 | (long) (skb_tail_pointer(skb) - skb->data), | ||
421 | (long) skb->data_len, | ||
422 | (long) (skb->data - skb->head), | ||
423 | (long) (skb_tail_pointer(skb) - skb->head)); | ||
424 | p = buf + strlen(buf); | ||
425 | |||
426 | for (i = 0; i < skb_tail_pointer(skb) - skb->data && i < 300; i++) { | ||
427 | if (p > buf + buflen - 10) { | ||
428 | sprintf(p, "..."); | ||
429 | p = buf + strlen(buf); | ||
430 | break; | ||
431 | } | ||
432 | sprintf(p, "%02x,", skb->data[i]); | ||
433 | p = buf + strlen(buf); | ||
434 | } | ||
435 | sprintf(p, "]\n"); | ||
436 | return buf; | ||
437 | } | ||
438 | EXPORT_SYMBOL(cfpkt_log_pkt); | ||
439 | |||
440 | int cfpkt_raw_append(struct cfpkt *pkt, void **buf, unsigned int buflen) | ||
441 | { | ||
442 | struct sk_buff *skb = pkt_to_skb(pkt); | ||
443 | struct sk_buff *lastskb; | ||
444 | |||
445 | caif_assert(buf != NULL); | ||
446 | if (unlikely(is_erronous(pkt))) | ||
447 | return -EPROTO; | ||
448 | /* Make sure SKB is writable */ | ||
449 | if (unlikely(skb_cow_data(skb, 0, &lastskb) < 0)) { | ||
450 | PKT_ERROR(pkt, "cfpkt_raw_append: skb_cow_data failed\n"); | ||
451 | return -EPROTO; | ||
452 | } | ||
453 | |||
454 | if (unlikely(skb_linearize(skb) != 0)) { | ||
455 | PKT_ERROR(pkt, "cfpkt_raw_append: linearize failed\n"); | ||
456 | return -EPROTO; | ||
457 | } | ||
458 | |||
459 | if (unlikely(skb_tailroom(skb) < buflen)) { | ||
460 | PKT_ERROR(pkt, "cfpkt_raw_append: buffer too short - failed\n"); | ||
461 | return -EPROTO; | ||
462 | } | ||
463 | |||
464 | *buf = skb_put(skb, buflen); | ||
465 | return 1; | ||
466 | } | ||
467 | EXPORT_SYMBOL(cfpkt_raw_append); | ||
468 | |||
469 | int cfpkt_raw_extract(struct cfpkt *pkt, void **buf, unsigned int buflen) | ||
470 | { | ||
471 | struct sk_buff *skb = pkt_to_skb(pkt); | ||
472 | |||
473 | caif_assert(buf != NULL); | ||
474 | if (unlikely(is_erronous(pkt))) | ||
475 | return -EPROTO; | ||
476 | |||
477 | if (unlikely(buflen > skb->len)) { | ||
478 | PKT_ERROR(pkt, "cfpkt_raw_extract: buflen too large " | ||
479 | "- failed\n"); | ||
480 | return -EPROTO; | ||
481 | } | ||
482 | |||
483 | if (unlikely(buflen > skb_headlen(skb))) { | ||
484 | if (unlikely(skb_linearize(skb) != 0)) { | ||
485 | PKT_ERROR(pkt, "cfpkt_raw_extract: linearize failed\n"); | ||
486 | return -EPROTO; | ||
487 | } | ||
488 | } | ||
489 | |||
490 | *buf = skb->data; | ||
491 | skb_pull(skb, buflen); | ||
492 | |||
493 | return 1; | ||
494 | } | ||
495 | EXPORT_SYMBOL(cfpkt_raw_extract); | ||
496 | |||
497 | inline bool cfpkt_erroneous(struct cfpkt *pkt) | ||
498 | { | ||
499 | return cfpkt_priv(pkt)->erronous; | ||
500 | } | ||
501 | EXPORT_SYMBOL(cfpkt_erroneous); | ||
502 | |||
503 | struct cfpktq *cfpktq_create(void) | ||
504 | { | ||
505 | struct cfpktq *q = kmalloc(sizeof(struct cfpktq), GFP_ATOMIC); | ||
506 | if (!q) | ||
507 | return NULL; | ||
508 | skb_queue_head_init(&q->head); | ||
509 | atomic_set(&q->count, 0); | ||
510 | spin_lock_init(&q->lock); | ||
511 | return q; | ||
512 | } | ||
513 | EXPORT_SYMBOL(cfpktq_create); | ||
514 | |||
515 | void cfpkt_queue(struct cfpktq *pktq, struct cfpkt *pkt, unsigned short prio) | ||
516 | { | ||
517 | atomic_inc(&pktq->count); | ||
518 | spin_lock(&pktq->lock); | ||
519 | skb_queue_tail(&pktq->head, pkt_to_skb(pkt)); | ||
520 | spin_unlock(&pktq->lock); | ||
521 | |||
522 | } | ||
523 | EXPORT_SYMBOL(cfpkt_queue); | ||
524 | |||
525 | struct cfpkt *cfpkt_qpeek(struct cfpktq *pktq) | ||
526 | { | ||
527 | struct cfpkt *tmp; | ||
528 | spin_lock(&pktq->lock); | ||
529 | tmp = skb_to_pkt(skb_peek(&pktq->head)); | ||
530 | spin_unlock(&pktq->lock); | ||
531 | return tmp; | ||
532 | } | ||
533 | EXPORT_SYMBOL(cfpkt_qpeek); | ||
534 | |||
535 | struct cfpkt *cfpkt_dequeue(struct cfpktq *pktq) | ||
536 | { | ||
537 | struct cfpkt *pkt; | ||
538 | spin_lock(&pktq->lock); | ||
539 | pkt = skb_to_pkt(skb_dequeue(&pktq->head)); | ||
540 | if (pkt) { | ||
541 | atomic_dec(&pktq->count); | ||
542 | caif_assert(atomic_read(&pktq->count) >= 0); | ||
543 | } | ||
544 | spin_unlock(&pktq->lock); | ||
545 | return pkt; | ||
546 | } | ||
547 | EXPORT_SYMBOL(cfpkt_dequeue); | ||
548 | |||
549 | int cfpkt_qcount(struct cfpktq *pktq) | ||
550 | { | ||
551 | return atomic_read(&pktq->count); | ||
552 | } | ||
553 | EXPORT_SYMBOL(cfpkt_qcount); | ||
554 | |||
555 | struct cfpkt *cfpkt_clone_release(struct cfpkt *pkt) | ||
556 | { | ||
557 | struct cfpkt *clone; | ||
558 | clone = skb_to_pkt(skb_clone(pkt_to_skb(pkt), GFP_ATOMIC)); | ||
559 | /* Free original packet. */ | ||
560 | cfpkt_destroy(pkt); | ||
561 | if (!clone) | ||
562 | return NULL; | ||
563 | return clone; | ||
564 | } | ||
565 | EXPORT_SYMBOL(cfpkt_clone_release); | ||
566 | |||
567 | struct caif_payload_info *cfpkt_info(struct cfpkt *pkt) | ||
568 | { | ||
569 | return (struct caif_payload_info *)&pkt_to_skb(pkt)->cb; | ||
570 | } | ||
571 | EXPORT_SYMBOL(cfpkt_info); | ||
diff --git a/net/caif/cfrfml.c b/net/caif/cfrfml.c new file mode 100644 index 000000000000..cd2830fec935 --- /dev/null +++ b/net/caif/cfrfml.c | |||
@@ -0,0 +1,108 @@ | |||
1 | /* | ||
2 | * Copyright (C) ST-Ericsson AB 2010 | ||
3 | * Author: Sjur Brendeland/sjur.brandeland@stericsson.com | ||
4 | * License terms: GNU General Public License (GPL) version 2 | ||
5 | */ | ||
6 | |||
7 | #include <linux/stddef.h> | ||
8 | #include <linux/spinlock.h> | ||
9 | #include <linux/slab.h> | ||
10 | #include <net/caif/caif_layer.h> | ||
11 | #include <net/caif/cfsrvl.h> | ||
12 | #include <net/caif/cfpkt.h> | ||
13 | |||
14 | #define container_obj(layr) container_of(layr, struct cfsrvl, layer) | ||
15 | |||
16 | #define RFM_SEGMENTATION_BIT 0x01 | ||
17 | #define RFM_PAYLOAD 0x00 | ||
18 | #define RFM_CMD_BIT 0x80 | ||
19 | #define RFM_FLOW_OFF 0x81 | ||
20 | #define RFM_FLOW_ON 0x80 | ||
21 | #define RFM_SET_PIN 0x82 | ||
22 | #define RFM_CTRL_PKT_SIZE 1 | ||
23 | |||
24 | static int cfrfml_receive(struct cflayer *layr, struct cfpkt *pkt); | ||
25 | static int cfrfml_transmit(struct cflayer *layr, struct cfpkt *pkt); | ||
26 | static int cfservl_modemcmd(struct cflayer *layr, enum caif_modemcmd ctrl); | ||
27 | |||
28 | struct cflayer *cfrfml_create(u8 channel_id, struct dev_info *dev_info) | ||
29 | { | ||
30 | struct cfsrvl *rfm = kmalloc(sizeof(struct cfsrvl), GFP_ATOMIC); | ||
31 | if (!rfm) { | ||
32 | pr_warning("CAIF: %s(): Out of memory\n", __func__); | ||
33 | return NULL; | ||
34 | } | ||
35 | caif_assert(offsetof(struct cfsrvl, layer) == 0); | ||
36 | memset(rfm, 0, sizeof(struct cfsrvl)); | ||
37 | cfsrvl_init(rfm, channel_id, dev_info); | ||
38 | rfm->layer.modemcmd = cfservl_modemcmd; | ||
39 | rfm->layer.receive = cfrfml_receive; | ||
40 | rfm->layer.transmit = cfrfml_transmit; | ||
41 | snprintf(rfm->layer.name, CAIF_LAYER_NAME_SZ, "rfm%d", channel_id); | ||
42 | return &rfm->layer; | ||
43 | } | ||
44 | |||
45 | static int cfservl_modemcmd(struct cflayer *layr, enum caif_modemcmd ctrl) | ||
46 | { | ||
47 | return -EPROTO; | ||
48 | } | ||
49 | |||
50 | static int cfrfml_receive(struct cflayer *layr, struct cfpkt *pkt) | ||
51 | { | ||
52 | u8 tmp; | ||
53 | bool segmented; | ||
54 | int ret; | ||
55 | caif_assert(layr->up != NULL); | ||
56 | caif_assert(layr->receive != NULL); | ||
57 | |||
58 | /* | ||
59 | * RFM is taking care of segmentation and stripping of | ||
60 | * segmentation bit. | ||
61 | */ | ||
62 | if (cfpkt_extr_head(pkt, &tmp, 1) < 0) { | ||
63 | pr_err("CAIF: %s(): Packet is erroneous!\n", __func__); | ||
64 | cfpkt_destroy(pkt); | ||
65 | return -EPROTO; | ||
66 | } | ||
67 | segmented = tmp & RFM_SEGMENTATION_BIT; | ||
68 | caif_assert(!segmented); | ||
69 | |||
70 | ret = layr->up->receive(layr->up, pkt); | ||
71 | return ret; | ||
72 | } | ||
73 | |||
74 | static int cfrfml_transmit(struct cflayer *layr, struct cfpkt *pkt) | ||
75 | { | ||
76 | u8 tmp = 0; | ||
77 | int ret; | ||
78 | struct cfsrvl *service = container_obj(layr); | ||
79 | |||
80 | caif_assert(layr->dn != NULL); | ||
81 | caif_assert(layr->dn->transmit != NULL); | ||
82 | |||
83 | if (!cfsrvl_ready(service, &ret)) | ||
84 | return ret; | ||
85 | |||
86 | if (!cfpkt_getlen(pkt) > CAIF_MAX_PAYLOAD_SIZE) { | ||
87 | pr_err("CAIF: %s():Packet too large - size=%d\n", | ||
88 | __func__, cfpkt_getlen(pkt)); | ||
89 | return -EOVERFLOW; | ||
90 | } | ||
91 | if (cfpkt_add_head(pkt, &tmp, 1) < 0) { | ||
92 | pr_err("CAIF: %s(): Packet is erroneous!\n", __func__); | ||
93 | return -EPROTO; | ||
94 | } | ||
95 | |||
96 | /* Add info for MUX-layer to route the packet out. */ | ||
97 | cfpkt_info(pkt)->channel_id = service->layer.id; | ||
98 | /* | ||
99 | * To optimize alignment, we add up the size of CAIF header before | ||
100 | * payload. | ||
101 | */ | ||
102 | cfpkt_info(pkt)->hdr_len = 1; | ||
103 | cfpkt_info(pkt)->dev_info = &service->dev_info; | ||
104 | ret = layr->dn->transmit(layr->dn, pkt); | ||
105 | if (ret < 0) | ||
106 | cfpkt_extr_head(pkt, &tmp, 1); | ||
107 | return ret; | ||
108 | } | ||
diff --git a/net/caif/cfserl.c b/net/caif/cfserl.c new file mode 100644 index 000000000000..06029ea2da2f --- /dev/null +++ b/net/caif/cfserl.c | |||
@@ -0,0 +1,192 @@ | |||
1 | /* | ||
2 | * Copyright (C) ST-Ericsson AB 2010 | ||
3 | * Author: Sjur Brendeland/sjur.brandeland@stericsson.com | ||
4 | * License terms: GNU General Public License (GPL) version 2 | ||
5 | */ | ||
6 | |||
7 | #include <linux/stddef.h> | ||
8 | #include <linux/spinlock.h> | ||
9 | #include <linux/slab.h> | ||
10 | #include <net/caif/caif_layer.h> | ||
11 | #include <net/caif/cfpkt.h> | ||
12 | #include <net/caif/cfserl.h> | ||
13 | |||
14 | #define container_obj(layr) ((struct cfserl *) layr) | ||
15 | |||
16 | #define CFSERL_STX 0x02 | ||
17 | #define CAIF_MINIUM_PACKET_SIZE 4 | ||
18 | struct cfserl { | ||
19 | struct cflayer layer; | ||
20 | struct cfpkt *incomplete_frm; | ||
21 | /* Protects parallel processing of incoming packets */ | ||
22 | spinlock_t sync; | ||
23 | bool usestx; | ||
24 | }; | ||
25 | #define STXLEN(layr) (layr->usestx ? 1 : 0) | ||
26 | |||
27 | static int cfserl_receive(struct cflayer *layr, struct cfpkt *pkt); | ||
28 | static int cfserl_transmit(struct cflayer *layr, struct cfpkt *pkt); | ||
29 | static void cfserl_ctrlcmd(struct cflayer *layr, enum caif_ctrlcmd ctrl, | ||
30 | int phyid); | ||
31 | |||
32 | struct cflayer *cfserl_create(int type, int instance, bool use_stx) | ||
33 | { | ||
34 | struct cfserl *this = kmalloc(sizeof(struct cfserl), GFP_ATOMIC); | ||
35 | if (!this) { | ||
36 | pr_warning("CAIF: %s(): Out of memory\n", __func__); | ||
37 | return NULL; | ||
38 | } | ||
39 | caif_assert(offsetof(struct cfserl, layer) == 0); | ||
40 | memset(this, 0, sizeof(struct cfserl)); | ||
41 | this->layer.receive = cfserl_receive; | ||
42 | this->layer.transmit = cfserl_transmit; | ||
43 | this->layer.ctrlcmd = cfserl_ctrlcmd; | ||
44 | this->layer.type = type; | ||
45 | this->usestx = use_stx; | ||
46 | spin_lock_init(&this->sync); | ||
47 | snprintf(this->layer.name, CAIF_LAYER_NAME_SZ, "ser1"); | ||
48 | return &this->layer; | ||
49 | } | ||
50 | |||
51 | static int cfserl_receive(struct cflayer *l, struct cfpkt *newpkt) | ||
52 | { | ||
53 | struct cfserl *layr = container_obj(l); | ||
54 | u16 pkt_len; | ||
55 | struct cfpkt *pkt = NULL; | ||
56 | struct cfpkt *tail_pkt = NULL; | ||
57 | u8 tmp8; | ||
58 | u16 tmp; | ||
59 | u8 stx = CFSERL_STX; | ||
60 | int ret; | ||
61 | u16 expectlen = 0; | ||
62 | caif_assert(newpkt != NULL); | ||
63 | spin_lock(&layr->sync); | ||
64 | |||
65 | if (layr->incomplete_frm != NULL) { | ||
66 | |||
67 | layr->incomplete_frm = | ||
68 | cfpkt_append(layr->incomplete_frm, newpkt, expectlen); | ||
69 | pkt = layr->incomplete_frm; | ||
70 | } else { | ||
71 | pkt = newpkt; | ||
72 | } | ||
73 | layr->incomplete_frm = NULL; | ||
74 | |||
75 | do { | ||
76 | /* Search for STX at start of pkt if STX is used */ | ||
77 | if (layr->usestx) { | ||
78 | cfpkt_extr_head(pkt, &tmp8, 1); | ||
79 | if (tmp8 != CFSERL_STX) { | ||
80 | while (cfpkt_more(pkt) | ||
81 | && tmp8 != CFSERL_STX) { | ||
82 | cfpkt_extr_head(pkt, &tmp8, 1); | ||
83 | } | ||
84 | if (!cfpkt_more(pkt)) { | ||
85 | cfpkt_destroy(pkt); | ||
86 | layr->incomplete_frm = NULL; | ||
87 | spin_unlock(&layr->sync); | ||
88 | return -EPROTO; | ||
89 | } | ||
90 | } | ||
91 | } | ||
92 | |||
93 | pkt_len = cfpkt_getlen(pkt); | ||
94 | |||
95 | /* | ||
96 | * pkt_len is the accumulated length of the packet data | ||
97 | * we have received so far. | ||
98 | * Exit if frame doesn't hold length. | ||
99 | */ | ||
100 | |||
101 | if (pkt_len < 2) { | ||
102 | if (layr->usestx) | ||
103 | cfpkt_add_head(pkt, &stx, 1); | ||
104 | layr->incomplete_frm = pkt; | ||
105 | spin_unlock(&layr->sync); | ||
106 | return 0; | ||
107 | } | ||
108 | |||
109 | /* | ||
110 | * Find length of frame. | ||
111 | * expectlen is the length we need for a full frame. | ||
112 | */ | ||
113 | cfpkt_peek_head(pkt, &tmp, 2); | ||
114 | expectlen = le16_to_cpu(tmp) + 2; | ||
115 | /* | ||
116 | * Frame error handling | ||
117 | */ | ||
118 | if (expectlen < CAIF_MINIUM_PACKET_SIZE | ||
119 | || expectlen > CAIF_MAX_FRAMESIZE) { | ||
120 | if (!layr->usestx) { | ||
121 | if (pkt != NULL) | ||
122 | cfpkt_destroy(pkt); | ||
123 | layr->incomplete_frm = NULL; | ||
124 | expectlen = 0; | ||
125 | spin_unlock(&layr->sync); | ||
126 | return -EPROTO; | ||
127 | } | ||
128 | continue; | ||
129 | } | ||
130 | |||
131 | if (pkt_len < expectlen) { | ||
132 | /* Too little received data */ | ||
133 | if (layr->usestx) | ||
134 | cfpkt_add_head(pkt, &stx, 1); | ||
135 | layr->incomplete_frm = pkt; | ||
136 | spin_unlock(&layr->sync); | ||
137 | return 0; | ||
138 | } | ||
139 | |||
140 | /* | ||
141 | * Enough data for at least one frame. | ||
142 | * Split the frame, if too long | ||
143 | */ | ||
144 | if (pkt_len > expectlen) | ||
145 | tail_pkt = cfpkt_split(pkt, expectlen); | ||
146 | else | ||
147 | tail_pkt = NULL; | ||
148 | |||
149 | /* Send the first part of packet upwards.*/ | ||
150 | spin_unlock(&layr->sync); | ||
151 | ret = layr->layer.up->receive(layr->layer.up, pkt); | ||
152 | spin_lock(&layr->sync); | ||
153 | if (ret == -EILSEQ) { | ||
154 | if (layr->usestx) { | ||
155 | if (tail_pkt != NULL) | ||
156 | pkt = cfpkt_append(pkt, tail_pkt, 0); | ||
157 | |||
158 | /* Start search for next STX if frame failed */ | ||
159 | continue; | ||
160 | } else { | ||
161 | cfpkt_destroy(pkt); | ||
162 | pkt = NULL; | ||
163 | } | ||
164 | } | ||
165 | |||
166 | pkt = tail_pkt; | ||
167 | |||
168 | } while (pkt != NULL); | ||
169 | |||
170 | spin_unlock(&layr->sync); | ||
171 | return 0; | ||
172 | } | ||
173 | |||
174 | static int cfserl_transmit(struct cflayer *layer, struct cfpkt *newpkt) | ||
175 | { | ||
176 | struct cfserl *layr = container_obj(layer); | ||
177 | int ret; | ||
178 | u8 tmp8 = CFSERL_STX; | ||
179 | if (layr->usestx) | ||
180 | cfpkt_add_head(newpkt, &tmp8, 1); | ||
181 | ret = layer->dn->transmit(layer->dn, newpkt); | ||
182 | if (ret < 0) | ||
183 | cfpkt_extr_head(newpkt, &tmp8, 1); | ||
184 | |||
185 | return ret; | ||
186 | } | ||
187 | |||
188 | static void cfserl_ctrlcmd(struct cflayer *layr, enum caif_ctrlcmd ctrl, | ||
189 | int phyid) | ||
190 | { | ||
191 | layr->up->ctrlcmd(layr->up, ctrl, phyid); | ||
192 | } | ||
diff --git a/net/caif/cfsrvl.c b/net/caif/cfsrvl.c new file mode 100644 index 000000000000..d470c51c6431 --- /dev/null +++ b/net/caif/cfsrvl.c | |||
@@ -0,0 +1,185 @@ | |||
1 | /* | ||
2 | * Copyright (C) ST-Ericsson AB 2010 | ||
3 | * Author: Sjur Brendeland/sjur.brandeland@stericsson.com | ||
4 | * License terms: GNU General Public License (GPL) version 2 | ||
5 | */ | ||
6 | |||
7 | #include <linux/kernel.h> | ||
8 | #include <linux/types.h> | ||
9 | #include <linux/errno.h> | ||
10 | #include <linux/slab.h> | ||
11 | #include <net/caif/caif_layer.h> | ||
12 | #include <net/caif/cfsrvl.h> | ||
13 | #include <net/caif/cfpkt.h> | ||
14 | |||
15 | #define SRVL_CTRL_PKT_SIZE 1 | ||
16 | #define SRVL_FLOW_OFF 0x81 | ||
17 | #define SRVL_FLOW_ON 0x80 | ||
18 | #define SRVL_SET_PIN 0x82 | ||
19 | #define SRVL_CTRL_PKT_SIZE 1 | ||
20 | |||
21 | #define container_obj(layr) container_of(layr, struct cfsrvl, layer) | ||
22 | |||
23 | static void cfservl_ctrlcmd(struct cflayer *layr, enum caif_ctrlcmd ctrl, | ||
24 | int phyid) | ||
25 | { | ||
26 | struct cfsrvl *service = container_obj(layr); | ||
27 | caif_assert(layr->up != NULL); | ||
28 | caif_assert(layr->up->ctrlcmd != NULL); | ||
29 | switch (ctrl) { | ||
30 | case CAIF_CTRLCMD_INIT_RSP: | ||
31 | service->open = true; | ||
32 | layr->up->ctrlcmd(layr->up, ctrl, phyid); | ||
33 | break; | ||
34 | case CAIF_CTRLCMD_DEINIT_RSP: | ||
35 | case CAIF_CTRLCMD_INIT_FAIL_RSP: | ||
36 | service->open = false; | ||
37 | layr->up->ctrlcmd(layr->up, ctrl, phyid); | ||
38 | break; | ||
39 | case _CAIF_CTRLCMD_PHYIF_FLOW_OFF_IND: | ||
40 | if (phyid != service->dev_info.id) | ||
41 | break; | ||
42 | if (service->modem_flow_on) | ||
43 | layr->up->ctrlcmd(layr->up, | ||
44 | CAIF_CTRLCMD_FLOW_OFF_IND, phyid); | ||
45 | service->phy_flow_on = false; | ||
46 | break; | ||
47 | case _CAIF_CTRLCMD_PHYIF_FLOW_ON_IND: | ||
48 | if (phyid != service->dev_info.id) | ||
49 | return; | ||
50 | if (service->modem_flow_on) { | ||
51 | layr->up->ctrlcmd(layr->up, | ||
52 | CAIF_CTRLCMD_FLOW_ON_IND, | ||
53 | phyid); | ||
54 | } | ||
55 | service->phy_flow_on = true; | ||
56 | break; | ||
57 | case CAIF_CTRLCMD_FLOW_OFF_IND: | ||
58 | if (service->phy_flow_on) { | ||
59 | layr->up->ctrlcmd(layr->up, | ||
60 | CAIF_CTRLCMD_FLOW_OFF_IND, phyid); | ||
61 | } | ||
62 | service->modem_flow_on = false; | ||
63 | break; | ||
64 | case CAIF_CTRLCMD_FLOW_ON_IND: | ||
65 | if (service->phy_flow_on) { | ||
66 | layr->up->ctrlcmd(layr->up, | ||
67 | CAIF_CTRLCMD_FLOW_ON_IND, phyid); | ||
68 | } | ||
69 | service->modem_flow_on = true; | ||
70 | break; | ||
71 | case _CAIF_CTRLCMD_PHYIF_DOWN_IND: | ||
72 | /* In case interface is down, let's fake a remove shutdown */ | ||
73 | layr->up->ctrlcmd(layr->up, | ||
74 | CAIF_CTRLCMD_REMOTE_SHUTDOWN_IND, phyid); | ||
75 | break; | ||
76 | case CAIF_CTRLCMD_REMOTE_SHUTDOWN_IND: | ||
77 | layr->up->ctrlcmd(layr->up, ctrl, phyid); | ||
78 | break; | ||
79 | default: | ||
80 | pr_warning("CAIF: %s(): " | ||
81 | "Unexpected ctrl in cfsrvl (%d)\n", __func__, ctrl); | ||
82 | /* We have both modem and phy flow on, send flow on */ | ||
83 | layr->up->ctrlcmd(layr->up, ctrl, phyid); | ||
84 | service->phy_flow_on = true; | ||
85 | break; | ||
86 | } | ||
87 | } | ||
88 | |||
89 | static int cfservl_modemcmd(struct cflayer *layr, enum caif_modemcmd ctrl) | ||
90 | { | ||
91 | struct cfsrvl *service = container_obj(layr); | ||
92 | caif_assert(layr != NULL); | ||
93 | caif_assert(layr->dn != NULL); | ||
94 | caif_assert(layr->dn->transmit != NULL); | ||
95 | switch (ctrl) { | ||
96 | case CAIF_MODEMCMD_FLOW_ON_REQ: | ||
97 | { | ||
98 | struct cfpkt *pkt; | ||
99 | struct caif_payload_info *info; | ||
100 | u8 flow_on = SRVL_FLOW_ON; | ||
101 | pkt = cfpkt_create(SRVL_CTRL_PKT_SIZE); | ||
102 | if (!pkt) { | ||
103 | pr_warning("CAIF: %s(): Out of memory\n", | ||
104 | __func__); | ||
105 | return -ENOMEM; | ||
106 | } | ||
107 | |||
108 | if (cfpkt_add_head(pkt, &flow_on, 1) < 0) { | ||
109 | pr_err("CAIF: %s(): Packet is erroneous!\n", | ||
110 | __func__); | ||
111 | cfpkt_destroy(pkt); | ||
112 | return -EPROTO; | ||
113 | } | ||
114 | info = cfpkt_info(pkt); | ||
115 | info->channel_id = service->layer.id; | ||
116 | info->hdr_len = 1; | ||
117 | info->dev_info = &service->dev_info; | ||
118 | return layr->dn->transmit(layr->dn, pkt); | ||
119 | } | ||
120 | case CAIF_MODEMCMD_FLOW_OFF_REQ: | ||
121 | { | ||
122 | struct cfpkt *pkt; | ||
123 | struct caif_payload_info *info; | ||
124 | u8 flow_off = SRVL_FLOW_OFF; | ||
125 | pkt = cfpkt_create(SRVL_CTRL_PKT_SIZE); | ||
126 | if (cfpkt_add_head(pkt, &flow_off, 1) < 0) { | ||
127 | pr_err("CAIF: %s(): Packet is erroneous!\n", | ||
128 | __func__); | ||
129 | cfpkt_destroy(pkt); | ||
130 | return -EPROTO; | ||
131 | } | ||
132 | info = cfpkt_info(pkt); | ||
133 | info->channel_id = service->layer.id; | ||
134 | info->hdr_len = 1; | ||
135 | info->dev_info = &service->dev_info; | ||
136 | return layr->dn->transmit(layr->dn, pkt); | ||
137 | } | ||
138 | default: | ||
139 | break; | ||
140 | } | ||
141 | return -EINVAL; | ||
142 | } | ||
143 | |||
144 | void cfservl_destroy(struct cflayer *layer) | ||
145 | { | ||
146 | kfree(layer); | ||
147 | } | ||
148 | |||
149 | void cfsrvl_init(struct cfsrvl *service, | ||
150 | u8 channel_id, | ||
151 | struct dev_info *dev_info) | ||
152 | { | ||
153 | caif_assert(offsetof(struct cfsrvl, layer) == 0); | ||
154 | service->open = false; | ||
155 | service->modem_flow_on = true; | ||
156 | service->phy_flow_on = true; | ||
157 | service->layer.id = channel_id; | ||
158 | service->layer.ctrlcmd = cfservl_ctrlcmd; | ||
159 | service->layer.modemcmd = cfservl_modemcmd; | ||
160 | service->dev_info = *dev_info; | ||
161 | } | ||
162 | |||
163 | bool cfsrvl_ready(struct cfsrvl *service, int *err) | ||
164 | { | ||
165 | if (service->open && service->modem_flow_on && service->phy_flow_on) | ||
166 | return true; | ||
167 | if (!service->open) { | ||
168 | *err = -ENOTCONN; | ||
169 | return false; | ||
170 | } | ||
171 | caif_assert(!(service->modem_flow_on && service->phy_flow_on)); | ||
172 | *err = -EAGAIN; | ||
173 | return false; | ||
174 | } | ||
175 | u8 cfsrvl_getphyid(struct cflayer *layer) | ||
176 | { | ||
177 | struct cfsrvl *servl = container_obj(layer); | ||
178 | return servl->dev_info.id; | ||
179 | } | ||
180 | |||
181 | bool cfsrvl_phyid_match(struct cflayer *layer, int phyid) | ||
182 | { | ||
183 | struct cfsrvl *servl = container_obj(layer); | ||
184 | return servl->dev_info.id == phyid; | ||
185 | } | ||
diff --git a/net/caif/cfutill.c b/net/caif/cfutill.c new file mode 100644 index 000000000000..5fd2c9ea8b42 --- /dev/null +++ b/net/caif/cfutill.c | |||
@@ -0,0 +1,115 @@ | |||
1 | /* | ||
2 | * Copyright (C) ST-Ericsson AB 2010 | ||
3 | * Author: Sjur Brendeland/sjur.brandeland@stericsson.com | ||
4 | * License terms: GNU General Public License (GPL) version 2 | ||
5 | */ | ||
6 | |||
7 | #include <linux/kernel.h> | ||
8 | #include <linux/types.h> | ||
9 | #include <linux/slab.h> | ||
10 | #include <linux/errno.h> | ||
11 | #include <net/caif/caif_layer.h> | ||
12 | #include <net/caif/cfsrvl.h> | ||
13 | #include <net/caif/cfpkt.h> | ||
14 | |||
15 | #define container_obj(layr) ((struct cfsrvl *) layr) | ||
16 | #define UTIL_PAYLOAD 0x00 | ||
17 | #define UTIL_CMD_BIT 0x80 | ||
18 | #define UTIL_REMOTE_SHUTDOWN 0x82 | ||
19 | #define UTIL_FLOW_OFF 0x81 | ||
20 | #define UTIL_FLOW_ON 0x80 | ||
21 | #define UTIL_CTRL_PKT_SIZE 1 | ||
22 | static int cfutill_receive(struct cflayer *layr, struct cfpkt *pkt); | ||
23 | static int cfutill_transmit(struct cflayer *layr, struct cfpkt *pkt); | ||
24 | |||
25 | struct cflayer *cfutill_create(u8 channel_id, struct dev_info *dev_info) | ||
26 | { | ||
27 | struct cfsrvl *util = kmalloc(sizeof(struct cfsrvl), GFP_ATOMIC); | ||
28 | if (!util) { | ||
29 | pr_warning("CAIF: %s(): Out of memory\n", __func__); | ||
30 | return NULL; | ||
31 | } | ||
32 | caif_assert(offsetof(struct cfsrvl, layer) == 0); | ||
33 | memset(util, 0, sizeof(struct cfsrvl)); | ||
34 | cfsrvl_init(util, channel_id, dev_info); | ||
35 | util->layer.receive = cfutill_receive; | ||
36 | util->layer.transmit = cfutill_transmit; | ||
37 | snprintf(util->layer.name, CAIF_LAYER_NAME_SZ - 1, "util1"); | ||
38 | return &util->layer; | ||
39 | } | ||
40 | |||
41 | static int cfutill_receive(struct cflayer *layr, struct cfpkt *pkt) | ||
42 | { | ||
43 | u8 cmd = -1; | ||
44 | struct cfsrvl *service = container_obj(layr); | ||
45 | caif_assert(layr != NULL); | ||
46 | caif_assert(layr->up != NULL); | ||
47 | caif_assert(layr->up->receive != NULL); | ||
48 | caif_assert(layr->up->ctrlcmd != NULL); | ||
49 | if (cfpkt_extr_head(pkt, &cmd, 1) < 0) { | ||
50 | pr_err("CAIF: %s(): Packet is erroneous!\n", __func__); | ||
51 | cfpkt_destroy(pkt); | ||
52 | return -EPROTO; | ||
53 | } | ||
54 | |||
55 | switch (cmd) { | ||
56 | case UTIL_PAYLOAD: | ||
57 | return layr->up->receive(layr->up, pkt); | ||
58 | case UTIL_FLOW_OFF: | ||
59 | layr->ctrlcmd(layr, CAIF_CTRLCMD_FLOW_OFF_IND, 0); | ||
60 | cfpkt_destroy(pkt); | ||
61 | return 0; | ||
62 | case UTIL_FLOW_ON: | ||
63 | layr->ctrlcmd(layr, CAIF_CTRLCMD_FLOW_ON_IND, 0); | ||
64 | cfpkt_destroy(pkt); | ||
65 | return 0; | ||
66 | case UTIL_REMOTE_SHUTDOWN: /* Remote Shutdown Request */ | ||
67 | pr_err("CAIF: %s(): REMOTE SHUTDOWN REQUEST RECEIVED\n", | ||
68 | __func__); | ||
69 | layr->ctrlcmd(layr, CAIF_CTRLCMD_REMOTE_SHUTDOWN_IND, 0); | ||
70 | service->open = false; | ||
71 | cfpkt_destroy(pkt); | ||
72 | return 0; | ||
73 | default: | ||
74 | cfpkt_destroy(pkt); | ||
75 | pr_warning("CAIF: %s(): Unknown service control %d (0x%x)\n", | ||
76 | __func__, cmd, cmd); | ||
77 | return -EPROTO; | ||
78 | } | ||
79 | } | ||
80 | |||
81 | static int cfutill_transmit(struct cflayer *layr, struct cfpkt *pkt) | ||
82 | { | ||
83 | u8 zero = 0; | ||
84 | struct caif_payload_info *info; | ||
85 | int ret; | ||
86 | struct cfsrvl *service = container_obj(layr); | ||
87 | caif_assert(layr != NULL); | ||
88 | caif_assert(layr->dn != NULL); | ||
89 | caif_assert(layr->dn->transmit != NULL); | ||
90 | if (!cfsrvl_ready(service, &ret)) | ||
91 | return ret; | ||
92 | |||
93 | if (cfpkt_getlen(pkt) > CAIF_MAX_PAYLOAD_SIZE) { | ||
94 | pr_err("CAIF: %s(): packet too large size=%d\n", | ||
95 | __func__, cfpkt_getlen(pkt)); | ||
96 | return -EOVERFLOW; | ||
97 | } | ||
98 | |||
99 | cfpkt_add_head(pkt, &zero, 1); | ||
100 | /* Add info for MUX-layer to route the packet out. */ | ||
101 | info = cfpkt_info(pkt); | ||
102 | info->channel_id = service->layer.id; | ||
103 | /* | ||
104 | * To optimize alignment, we add up the size of CAIF header before | ||
105 | * payload. | ||
106 | */ | ||
107 | info->hdr_len = 1; | ||
108 | info->dev_info = &service->dev_info; | ||
109 | ret = layr->dn->transmit(layr->dn, pkt); | ||
110 | if (ret < 0) { | ||
111 | u32 tmp32; | ||
112 | cfpkt_extr_head(pkt, &tmp32, 4); | ||
113 | } | ||
114 | return ret; | ||
115 | } | ||
diff --git a/net/caif/cfveil.c b/net/caif/cfveil.c new file mode 100644 index 000000000000..0fd827f49491 --- /dev/null +++ b/net/caif/cfveil.c | |||
@@ -0,0 +1,107 @@ | |||
1 | /* | ||
2 | * Copyright (C) ST-Ericsson AB 2010 | ||
3 | * Author: Sjur Brendeland/sjur.brandeland@stericsson.com | ||
4 | * License terms: GNU General Public License (GPL) version 2 | ||
5 | */ | ||
6 | |||
7 | #include <linux/stddef.h> | ||
8 | #include <linux/slab.h> | ||
9 | #include <net/caif/caif_layer.h> | ||
10 | #include <net/caif/cfsrvl.h> | ||
11 | #include <net/caif/cfpkt.h> | ||
12 | |||
13 | #define VEI_PAYLOAD 0x00 | ||
14 | #define VEI_CMD_BIT 0x80 | ||
15 | #define VEI_FLOW_OFF 0x81 | ||
16 | #define VEI_FLOW_ON 0x80 | ||
17 | #define VEI_SET_PIN 0x82 | ||
18 | #define VEI_CTRL_PKT_SIZE 1 | ||
19 | #define container_obj(layr) container_of(layr, struct cfsrvl, layer) | ||
20 | |||
21 | static int cfvei_receive(struct cflayer *layr, struct cfpkt *pkt); | ||
22 | static int cfvei_transmit(struct cflayer *layr, struct cfpkt *pkt); | ||
23 | |||
24 | struct cflayer *cfvei_create(u8 channel_id, struct dev_info *dev_info) | ||
25 | { | ||
26 | struct cfsrvl *vei = kmalloc(sizeof(struct cfsrvl), GFP_ATOMIC); | ||
27 | if (!vei) { | ||
28 | pr_warning("CAIF: %s(): Out of memory\n", __func__); | ||
29 | return NULL; | ||
30 | } | ||
31 | caif_assert(offsetof(struct cfsrvl, layer) == 0); | ||
32 | memset(vei, 0, sizeof(struct cfsrvl)); | ||
33 | cfsrvl_init(vei, channel_id, dev_info); | ||
34 | vei->layer.receive = cfvei_receive; | ||
35 | vei->layer.transmit = cfvei_transmit; | ||
36 | snprintf(vei->layer.name, CAIF_LAYER_NAME_SZ - 1, "vei%d", channel_id); | ||
37 | return &vei->layer; | ||
38 | } | ||
39 | |||
40 | static int cfvei_receive(struct cflayer *layr, struct cfpkt *pkt) | ||
41 | { | ||
42 | u8 cmd; | ||
43 | int ret; | ||
44 | caif_assert(layr->up != NULL); | ||
45 | caif_assert(layr->receive != NULL); | ||
46 | caif_assert(layr->ctrlcmd != NULL); | ||
47 | |||
48 | |||
49 | if (cfpkt_extr_head(pkt, &cmd, 1) < 0) { | ||
50 | pr_err("CAIF: %s(): Packet is erroneous!\n", __func__); | ||
51 | cfpkt_destroy(pkt); | ||
52 | return -EPROTO; | ||
53 | } | ||
54 | switch (cmd) { | ||
55 | case VEI_PAYLOAD: | ||
56 | ret = layr->up->receive(layr->up, pkt); | ||
57 | return ret; | ||
58 | case VEI_FLOW_OFF: | ||
59 | layr->ctrlcmd(layr, CAIF_CTRLCMD_FLOW_OFF_IND, 0); | ||
60 | cfpkt_destroy(pkt); | ||
61 | return 0; | ||
62 | case VEI_FLOW_ON: | ||
63 | layr->ctrlcmd(layr, CAIF_CTRLCMD_FLOW_ON_IND, 0); | ||
64 | cfpkt_destroy(pkt); | ||
65 | return 0; | ||
66 | case VEI_SET_PIN: /* SET RS232 PIN */ | ||
67 | cfpkt_destroy(pkt); | ||
68 | return 0; | ||
69 | default: /* SET RS232 PIN */ | ||
70 | pr_warning("CAIF: %s():Unknown VEI control packet %d (0x%x)!\n", | ||
71 | __func__, cmd, cmd); | ||
72 | cfpkt_destroy(pkt); | ||
73 | return -EPROTO; | ||
74 | } | ||
75 | } | ||
76 | |||
77 | static int cfvei_transmit(struct cflayer *layr, struct cfpkt *pkt) | ||
78 | { | ||
79 | u8 tmp = 0; | ||
80 | struct caif_payload_info *info; | ||
81 | int ret; | ||
82 | struct cfsrvl *service = container_obj(layr); | ||
83 | if (!cfsrvl_ready(service, &ret)) | ||
84 | return ret; | ||
85 | caif_assert(layr->dn != NULL); | ||
86 | caif_assert(layr->dn->transmit != NULL); | ||
87 | if (!cfpkt_getlen(pkt) > CAIF_MAX_PAYLOAD_SIZE) { | ||
88 | pr_warning("CAIF: %s(): Packet too large - size=%d\n", | ||
89 | __func__, cfpkt_getlen(pkt)); | ||
90 | return -EOVERFLOW; | ||
91 | } | ||
92 | |||
93 | if (cfpkt_add_head(pkt, &tmp, 1) < 0) { | ||
94 | pr_err("CAIF: %s(): Packet is erroneous!\n", __func__); | ||
95 | return -EPROTO; | ||
96 | } | ||
97 | |||
98 | /* Add info-> for MUX-layer to route the packet out. */ | ||
99 | info = cfpkt_info(pkt); | ||
100 | info->channel_id = service->layer.id; | ||
101 | info->hdr_len = 1; | ||
102 | info->dev_info = &service->dev_info; | ||
103 | ret = layr->dn->transmit(layr->dn, pkt); | ||
104 | if (ret < 0) | ||
105 | cfpkt_extr_head(pkt, &tmp, 1); | ||
106 | return ret; | ||
107 | } | ||
diff --git a/net/caif/cfvidl.c b/net/caif/cfvidl.c new file mode 100644 index 000000000000..89ad4ea239f1 --- /dev/null +++ b/net/caif/cfvidl.c | |||
@@ -0,0 +1,65 @@ | |||
1 | /* | ||
2 | * Copyright (C) ST-Ericsson AB 2010 | ||
3 | * Author: Sjur Brendeland/sjur.brandeland@stericsson.com | ||
4 | * License terms: GNU General Public License (GPL) version 2 | ||
5 | */ | ||
6 | |||
7 | #include <linux/kernel.h> | ||
8 | #include <linux/types.h> | ||
9 | #include <linux/slab.h> | ||
10 | #include <linux/errno.h> | ||
11 | #include <net/caif/caif_layer.h> | ||
12 | #include <net/caif/cfsrvl.h> | ||
13 | #include <net/caif/cfpkt.h> | ||
14 | |||
15 | #define container_obj(layr) ((struct cfsrvl *) layr) | ||
16 | |||
17 | static int cfvidl_receive(struct cflayer *layr, struct cfpkt *pkt); | ||
18 | static int cfvidl_transmit(struct cflayer *layr, struct cfpkt *pkt); | ||
19 | |||
20 | struct cflayer *cfvidl_create(u8 channel_id, struct dev_info *dev_info) | ||
21 | { | ||
22 | struct cfsrvl *vid = kmalloc(sizeof(struct cfsrvl), GFP_ATOMIC); | ||
23 | if (!vid) { | ||
24 | pr_warning("CAIF: %s(): Out of memory\n", __func__); | ||
25 | return NULL; | ||
26 | } | ||
27 | caif_assert(offsetof(struct cfsrvl, layer) == 0); | ||
28 | |||
29 | memset(vid, 0, sizeof(struct cfsrvl)); | ||
30 | cfsrvl_init(vid, channel_id, dev_info); | ||
31 | vid->layer.receive = cfvidl_receive; | ||
32 | vid->layer.transmit = cfvidl_transmit; | ||
33 | snprintf(vid->layer.name, CAIF_LAYER_NAME_SZ - 1, "vid1"); | ||
34 | return &vid->layer; | ||
35 | } | ||
36 | |||
37 | static int cfvidl_receive(struct cflayer *layr, struct cfpkt *pkt) | ||
38 | { | ||
39 | u32 videoheader; | ||
40 | if (cfpkt_extr_head(pkt, &videoheader, 4) < 0) { | ||
41 | pr_err("CAIF: %s(): Packet is erroneous!\n", __func__); | ||
42 | cfpkt_destroy(pkt); | ||
43 | return -EPROTO; | ||
44 | } | ||
45 | return layr->up->receive(layr->up, pkt); | ||
46 | } | ||
47 | |||
48 | static int cfvidl_transmit(struct cflayer *layr, struct cfpkt *pkt) | ||
49 | { | ||
50 | struct cfsrvl *service = container_obj(layr); | ||
51 | struct caif_payload_info *info; | ||
52 | u32 videoheader = 0; | ||
53 | int ret; | ||
54 | if (!cfsrvl_ready(service, &ret)) | ||
55 | return ret; | ||
56 | cfpkt_add_head(pkt, &videoheader, 4); | ||
57 | /* Add info for MUX-layer to route the packet out */ | ||
58 | info = cfpkt_info(pkt); | ||
59 | info->channel_id = service->layer.id; | ||
60 | info->dev_info = &service->dev_info; | ||
61 | ret = layr->dn->transmit(layr->dn, pkt); | ||
62 | if (ret < 0) | ||
63 | cfpkt_extr_head(pkt, &videoheader, 4); | ||
64 | return ret; | ||
65 | } | ||
diff --git a/net/caif/chnl_net.c b/net/caif/chnl_net.c new file mode 100644 index 000000000000..f622ff1d39ba --- /dev/null +++ b/net/caif/chnl_net.c | |||
@@ -0,0 +1,451 @@ | |||
1 | /* | ||
2 | * Copyright (C) ST-Ericsson AB 2010 | ||
3 | * Authors: Sjur Brendeland/sjur.brandeland@stericsson.com | ||
4 | * Daniel Martensson / Daniel.Martensson@stericsson.com | ||
5 | * License terms: GNU General Public License (GPL) version 2 | ||
6 | */ | ||
7 | |||
8 | #include <linux/version.h> | ||
9 | #include <linux/fs.h> | ||
10 | #include <linux/init.h> | ||
11 | #include <linux/module.h> | ||
12 | #include <linux/netdevice.h> | ||
13 | #include <linux/if_ether.h> | ||
14 | #include <linux/moduleparam.h> | ||
15 | #include <linux/ip.h> | ||
16 | #include <linux/sched.h> | ||
17 | #include <linux/sockios.h> | ||
18 | #include <linux/caif/if_caif.h> | ||
19 | #include <net/rtnetlink.h> | ||
20 | #include <net/caif/caif_layer.h> | ||
21 | #include <net/caif/cfcnfg.h> | ||
22 | #include <net/caif/cfpkt.h> | ||
23 | #include <net/caif/caif_dev.h> | ||
24 | |||
25 | #define CAIF_CONNECT_TIMEOUT 30 | ||
26 | #define SIZE_MTU 1500 | ||
27 | #define SIZE_MTU_MAX 4080 | ||
28 | #define SIZE_MTU_MIN 68 | ||
29 | #define CAIF_NET_DEFAULT_QUEUE_LEN 500 | ||
30 | |||
31 | #undef pr_debug | ||
32 | #define pr_debug pr_warning | ||
33 | |||
34 | /*This list is protected by the rtnl lock. */ | ||
35 | static LIST_HEAD(chnl_net_list); | ||
36 | |||
37 | MODULE_LICENSE("GPL"); | ||
38 | MODULE_ALIAS_RTNL_LINK("caif"); | ||
39 | |||
40 | struct chnl_net { | ||
41 | struct cflayer chnl; | ||
42 | struct net_device_stats stats; | ||
43 | struct caif_connect_request conn_req; | ||
44 | struct list_head list_field; | ||
45 | struct net_device *netdev; | ||
46 | char name[256]; | ||
47 | wait_queue_head_t netmgmt_wq; | ||
48 | /* Flow status to remember and control the transmission. */ | ||
49 | bool flowenabled; | ||
50 | bool pending_close; | ||
51 | }; | ||
52 | |||
53 | static void robust_list_del(struct list_head *delete_node) | ||
54 | { | ||
55 | struct list_head *list_node; | ||
56 | struct list_head *n; | ||
57 | ASSERT_RTNL(); | ||
58 | list_for_each_safe(list_node, n, &chnl_net_list) { | ||
59 | if (list_node == delete_node) { | ||
60 | list_del(list_node); | ||
61 | break; | ||
62 | } | ||
63 | } | ||
64 | } | ||
65 | |||
66 | static int chnl_recv_cb(struct cflayer *layr, struct cfpkt *pkt) | ||
67 | { | ||
68 | struct sk_buff *skb; | ||
69 | struct chnl_net *priv = NULL; | ||
70 | int pktlen; | ||
71 | int err = 0; | ||
72 | |||
73 | priv = container_of(layr, struct chnl_net, chnl); | ||
74 | |||
75 | if (!priv) | ||
76 | return -EINVAL; | ||
77 | |||
78 | /* Get length of CAIF packet. */ | ||
79 | pktlen = cfpkt_getlen(pkt); | ||
80 | |||
81 | skb = (struct sk_buff *) cfpkt_tonative(pkt); | ||
82 | /* Pass some minimum information and | ||
83 | * send the packet to the net stack. | ||
84 | */ | ||
85 | skb->dev = priv->netdev; | ||
86 | skb->protocol = htons(ETH_P_IP); | ||
87 | |||
88 | /* If we change the header in loop mode, the checksum is corrupted. */ | ||
89 | if (priv->conn_req.protocol == CAIFPROTO_DATAGRAM_LOOP) | ||
90 | skb->ip_summed = CHECKSUM_UNNECESSARY; | ||
91 | else | ||
92 | skb->ip_summed = CHECKSUM_NONE; | ||
93 | |||
94 | /* FIXME: Drivers should call this in tasklet context. */ | ||
95 | if (in_interrupt()) | ||
96 | netif_rx(skb); | ||
97 | else | ||
98 | netif_rx_ni(skb); | ||
99 | |||
100 | /* Update statistics. */ | ||
101 | priv->netdev->stats.rx_packets++; | ||
102 | priv->netdev->stats.rx_bytes += pktlen; | ||
103 | |||
104 | return err; | ||
105 | } | ||
106 | |||
107 | static int delete_device(struct chnl_net *dev) | ||
108 | { | ||
109 | ASSERT_RTNL(); | ||
110 | if (dev->netdev) | ||
111 | unregister_netdevice(dev->netdev); | ||
112 | return 0; | ||
113 | } | ||
114 | |||
115 | static void close_work(struct work_struct *work) | ||
116 | { | ||
117 | struct chnl_net *dev = NULL; | ||
118 | struct list_head *list_node; | ||
119 | struct list_head *_tmp; | ||
120 | rtnl_lock(); | ||
121 | list_for_each_safe(list_node, _tmp, &chnl_net_list) { | ||
122 | dev = list_entry(list_node, struct chnl_net, list_field); | ||
123 | if (!dev->pending_close) | ||
124 | continue; | ||
125 | list_del(list_node); | ||
126 | delete_device(dev); | ||
127 | } | ||
128 | rtnl_unlock(); | ||
129 | } | ||
130 | static DECLARE_WORK(close_worker, close_work); | ||
131 | |||
132 | static void chnl_flowctrl_cb(struct cflayer *layr, enum caif_ctrlcmd flow, | ||
133 | int phyid) | ||
134 | { | ||
135 | struct chnl_net *priv; | ||
136 | pr_debug("CAIF: %s(): NET flowctrl func called flow: %s.\n", | ||
137 | __func__, | ||
138 | flow == CAIF_CTRLCMD_FLOW_ON_IND ? "ON" : | ||
139 | flow == CAIF_CTRLCMD_INIT_RSP ? "INIT" : | ||
140 | flow == CAIF_CTRLCMD_FLOW_OFF_IND ? "OFF" : | ||
141 | flow == CAIF_CTRLCMD_DEINIT_RSP ? "CLOSE/DEINIT" : | ||
142 | flow == CAIF_CTRLCMD_INIT_FAIL_RSP ? "OPEN_FAIL" : | ||
143 | flow == CAIF_CTRLCMD_REMOTE_SHUTDOWN_IND ? | ||
144 | "REMOTE_SHUTDOWN" : "UKNOWN CTRL COMMAND"); | ||
145 | |||
146 | priv = container_of(layr, struct chnl_net, chnl); | ||
147 | |||
148 | switch (flow) { | ||
149 | case CAIF_CTRLCMD_FLOW_OFF_IND: | ||
150 | case CAIF_CTRLCMD_DEINIT_RSP: | ||
151 | case CAIF_CTRLCMD_INIT_FAIL_RSP: | ||
152 | case CAIF_CTRLCMD_REMOTE_SHUTDOWN_IND: | ||
153 | priv->flowenabled = false; | ||
154 | netif_tx_disable(priv->netdev); | ||
155 | pr_warning("CAIF: %s(): done\n", __func__); | ||
156 | priv->pending_close = 1; | ||
157 | schedule_work(&close_worker); | ||
158 | break; | ||
159 | case CAIF_CTRLCMD_FLOW_ON_IND: | ||
160 | case CAIF_CTRLCMD_INIT_RSP: | ||
161 | priv->flowenabled = true; | ||
162 | netif_wake_queue(priv->netdev); | ||
163 | wake_up_interruptible(&priv->netmgmt_wq); | ||
164 | break; | ||
165 | default: | ||
166 | break; | ||
167 | } | ||
168 | } | ||
169 | |||
170 | static int chnl_net_start_xmit(struct sk_buff *skb, struct net_device *dev) | ||
171 | { | ||
172 | struct chnl_net *priv; | ||
173 | struct cfpkt *pkt = NULL; | ||
174 | int len; | ||
175 | int result = -1; | ||
176 | /* Get our private data. */ | ||
177 | priv = netdev_priv(dev); | ||
178 | |||
179 | if (skb->len > priv->netdev->mtu) { | ||
180 | pr_warning("CAIF: %s(): Size of skb exceeded MTU\n", __func__); | ||
181 | return -ENOSPC; | ||
182 | } | ||
183 | |||
184 | if (!priv->flowenabled) { | ||
185 | pr_debug("CAIF: %s(): dropping packets flow off\n", __func__); | ||
186 | return NETDEV_TX_BUSY; | ||
187 | } | ||
188 | |||
189 | if (priv->conn_req.protocol == CAIFPROTO_DATAGRAM_LOOP) | ||
190 | swap(ip_hdr(skb)->saddr, ip_hdr(skb)->daddr); | ||
191 | |||
192 | /* Store original SKB length. */ | ||
193 | len = skb->len; | ||
194 | |||
195 | pkt = cfpkt_fromnative(CAIF_DIR_OUT, (void *) skb); | ||
196 | |||
197 | pr_debug("CAIF: %s(): transmit inst %s %d,%p\n", | ||
198 | __func__, dev->name, priv->chnl.dn->id, &priv->chnl.dn); | ||
199 | |||
200 | /* Send the packet down the stack. */ | ||
201 | result = priv->chnl.dn->transmit(priv->chnl.dn, pkt); | ||
202 | if (result) { | ||
203 | if (result == -EAGAIN) | ||
204 | result = NETDEV_TX_BUSY; | ||
205 | return result; | ||
206 | } | ||
207 | |||
208 | /* Update statistics. */ | ||
209 | dev->stats.tx_packets++; | ||
210 | dev->stats.tx_bytes += len; | ||
211 | |||
212 | return NETDEV_TX_OK; | ||
213 | } | ||
214 | |||
215 | static int chnl_net_open(struct net_device *dev) | ||
216 | { | ||
217 | struct chnl_net *priv = NULL; | ||
218 | int result = -1; | ||
219 | ASSERT_RTNL(); | ||
220 | |||
221 | priv = netdev_priv(dev); | ||
222 | pr_debug("CAIF: %s(): dev name: %s\n", __func__, priv->name); | ||
223 | |||
224 | if (!priv) { | ||
225 | pr_debug("CAIF: %s(): chnl_net_open: no priv\n", __func__); | ||
226 | return -ENODEV; | ||
227 | } | ||
228 | result = caif_connect_client(&priv->conn_req, &priv->chnl); | ||
229 | if (result != 0) { | ||
230 | pr_debug("CAIF: %s(): err: " | ||
231 | "Unable to register and open device, Err:%d\n", | ||
232 | __func__, | ||
233 | result); | ||
234 | return -ENODEV; | ||
235 | } | ||
236 | result = wait_event_interruptible(priv->netmgmt_wq, priv->flowenabled); | ||
237 | |||
238 | if (result == -ERESTARTSYS) { | ||
239 | pr_debug("CAIF: %s(): wait_event_interruptible" | ||
240 | " woken by a signal\n", __func__); | ||
241 | return -ERESTARTSYS; | ||
242 | } else | ||
243 | pr_debug("CAIF: %s(): Flow on recieved\n", __func__); | ||
244 | |||
245 | return 0; | ||
246 | } | ||
247 | |||
248 | static int chnl_net_stop(struct net_device *dev) | ||
249 | { | ||
250 | struct chnl_net *priv; | ||
251 | int result = -1; | ||
252 | ASSERT_RTNL(); | ||
253 | priv = netdev_priv(dev); | ||
254 | |||
255 | result = caif_disconnect_client(&priv->chnl); | ||
256 | if (result != 0) { | ||
257 | pr_debug("CAIF: %s(): chnl_net_stop: err: " | ||
258 | "Unable to STOP device, Err:%d\n", | ||
259 | __func__, result); | ||
260 | return -EBUSY; | ||
261 | } | ||
262 | result = wait_event_interruptible(priv->netmgmt_wq, | ||
263 | !priv->flowenabled); | ||
264 | |||
265 | if (result == -ERESTARTSYS) { | ||
266 | pr_debug("CAIF: %s(): wait_event_interruptible woken by" | ||
267 | " signal, signal_pending(current) = %d\n", | ||
268 | __func__, | ||
269 | signal_pending(current)); | ||
270 | } else { | ||
271 | pr_debug("CAIF: %s(): disconnect received\n", __func__); | ||
272 | |||
273 | } | ||
274 | |||
275 | return 0; | ||
276 | } | ||
277 | |||
278 | static int chnl_net_init(struct net_device *dev) | ||
279 | { | ||
280 | struct chnl_net *priv; | ||
281 | ASSERT_RTNL(); | ||
282 | priv = netdev_priv(dev); | ||
283 | strncpy(priv->name, dev->name, sizeof(priv->name)); | ||
284 | return 0; | ||
285 | } | ||
286 | |||
287 | static void chnl_net_uninit(struct net_device *dev) | ||
288 | { | ||
289 | struct chnl_net *priv; | ||
290 | ASSERT_RTNL(); | ||
291 | priv = netdev_priv(dev); | ||
292 | robust_list_del(&priv->list_field); | ||
293 | } | ||
294 | |||
295 | static const struct net_device_ops netdev_ops = { | ||
296 | .ndo_open = chnl_net_open, | ||
297 | .ndo_stop = chnl_net_stop, | ||
298 | .ndo_init = chnl_net_init, | ||
299 | .ndo_uninit = chnl_net_uninit, | ||
300 | .ndo_start_xmit = chnl_net_start_xmit, | ||
301 | }; | ||
302 | |||
303 | static void ipcaif_net_setup(struct net_device *dev) | ||
304 | { | ||
305 | struct chnl_net *priv; | ||
306 | dev->netdev_ops = &netdev_ops; | ||
307 | dev->destructor = free_netdev; | ||
308 | dev->flags |= IFF_NOARP; | ||
309 | dev->flags |= IFF_POINTOPOINT; | ||
310 | dev->needed_headroom = CAIF_NEEDED_HEADROOM; | ||
311 | dev->needed_tailroom = CAIF_NEEDED_TAILROOM; | ||
312 | dev->mtu = SIZE_MTU; | ||
313 | dev->tx_queue_len = CAIF_NET_DEFAULT_QUEUE_LEN; | ||
314 | |||
315 | priv = netdev_priv(dev); | ||
316 | priv->chnl.receive = chnl_recv_cb; | ||
317 | priv->chnl.ctrlcmd = chnl_flowctrl_cb; | ||
318 | priv->netdev = dev; | ||
319 | priv->conn_req.protocol = CAIFPROTO_DATAGRAM; | ||
320 | priv->conn_req.link_selector = CAIF_LINK_HIGH_BANDW; | ||
321 | priv->conn_req.priority = CAIF_PRIO_LOW; | ||
322 | /* Insert illegal value */ | ||
323 | priv->conn_req.sockaddr.u.dgm.connection_id = -1; | ||
324 | priv->flowenabled = false; | ||
325 | |||
326 | ASSERT_RTNL(); | ||
327 | init_waitqueue_head(&priv->netmgmt_wq); | ||
328 | list_add(&priv->list_field, &chnl_net_list); | ||
329 | } | ||
330 | |||
331 | |||
332 | static int ipcaif_fill_info(struct sk_buff *skb, const struct net_device *dev) | ||
333 | { | ||
334 | struct chnl_net *priv; | ||
335 | u8 loop; | ||
336 | priv = netdev_priv(dev); | ||
337 | NLA_PUT_U32(skb, IFLA_CAIF_IPV4_CONNID, | ||
338 | priv->conn_req.sockaddr.u.dgm.connection_id); | ||
339 | NLA_PUT_U32(skb, IFLA_CAIF_IPV6_CONNID, | ||
340 | priv->conn_req.sockaddr.u.dgm.connection_id); | ||
341 | loop = priv->conn_req.protocol == CAIFPROTO_DATAGRAM_LOOP; | ||
342 | NLA_PUT_U8(skb, IFLA_CAIF_LOOPBACK, loop); | ||
343 | |||
344 | |||
345 | return 0; | ||
346 | nla_put_failure: | ||
347 | return -EMSGSIZE; | ||
348 | |||
349 | } | ||
350 | |||
351 | static void caif_netlink_parms(struct nlattr *data[], | ||
352 | struct caif_connect_request *conn_req) | ||
353 | { | ||
354 | if (!data) { | ||
355 | pr_warning("CAIF: %s: no params data found\n", __func__); | ||
356 | return; | ||
357 | } | ||
358 | if (data[IFLA_CAIF_IPV4_CONNID]) | ||
359 | conn_req->sockaddr.u.dgm.connection_id = | ||
360 | nla_get_u32(data[IFLA_CAIF_IPV4_CONNID]); | ||
361 | if (data[IFLA_CAIF_IPV6_CONNID]) | ||
362 | conn_req->sockaddr.u.dgm.connection_id = | ||
363 | nla_get_u32(data[IFLA_CAIF_IPV6_CONNID]); | ||
364 | if (data[IFLA_CAIF_LOOPBACK]) { | ||
365 | if (nla_get_u8(data[IFLA_CAIF_LOOPBACK])) | ||
366 | conn_req->protocol = CAIFPROTO_DATAGRAM_LOOP; | ||
367 | else | ||
368 | conn_req->protocol = CAIFPROTO_DATAGRAM; | ||
369 | } | ||
370 | } | ||
371 | |||
372 | static int ipcaif_newlink(struct net *src_net, struct net_device *dev, | ||
373 | struct nlattr *tb[], struct nlattr *data[]) | ||
374 | { | ||
375 | int ret; | ||
376 | struct chnl_net *caifdev; | ||
377 | ASSERT_RTNL(); | ||
378 | caifdev = netdev_priv(dev); | ||
379 | caif_netlink_parms(data, &caifdev->conn_req); | ||
380 | ret = register_netdevice(dev); | ||
381 | if (ret) | ||
382 | pr_warning("CAIF: %s(): device rtml registration failed\n", | ||
383 | __func__); | ||
384 | return ret; | ||
385 | } | ||
386 | |||
387 | static int ipcaif_changelink(struct net_device *dev, struct nlattr *tb[], | ||
388 | struct nlattr *data[]) | ||
389 | { | ||
390 | struct chnl_net *caifdev; | ||
391 | ASSERT_RTNL(); | ||
392 | caifdev = netdev_priv(dev); | ||
393 | caif_netlink_parms(data, &caifdev->conn_req); | ||
394 | netdev_state_change(dev); | ||
395 | return 0; | ||
396 | } | ||
397 | |||
398 | static size_t ipcaif_get_size(const struct net_device *dev) | ||
399 | { | ||
400 | return | ||
401 | /* IFLA_CAIF_IPV4_CONNID */ | ||
402 | nla_total_size(4) + | ||
403 | /* IFLA_CAIF_IPV6_CONNID */ | ||
404 | nla_total_size(4) + | ||
405 | /* IFLA_CAIF_LOOPBACK */ | ||
406 | nla_total_size(2) + | ||
407 | 0; | ||
408 | } | ||
409 | |||
410 | static const struct nla_policy ipcaif_policy[IFLA_CAIF_MAX + 1] = { | ||
411 | [IFLA_CAIF_IPV4_CONNID] = { .type = NLA_U32 }, | ||
412 | [IFLA_CAIF_IPV6_CONNID] = { .type = NLA_U32 }, | ||
413 | [IFLA_CAIF_LOOPBACK] = { .type = NLA_U8 } | ||
414 | }; | ||
415 | |||
416 | |||
417 | static struct rtnl_link_ops ipcaif_link_ops __read_mostly = { | ||
418 | .kind = "caif", | ||
419 | .priv_size = sizeof(struct chnl_net), | ||
420 | .setup = ipcaif_net_setup, | ||
421 | .maxtype = IFLA_CAIF_MAX, | ||
422 | .policy = ipcaif_policy, | ||
423 | .newlink = ipcaif_newlink, | ||
424 | .changelink = ipcaif_changelink, | ||
425 | .get_size = ipcaif_get_size, | ||
426 | .fill_info = ipcaif_fill_info, | ||
427 | |||
428 | }; | ||
429 | |||
430 | static int __init chnl_init_module(void) | ||
431 | { | ||
432 | return rtnl_link_register(&ipcaif_link_ops); | ||
433 | } | ||
434 | |||
435 | static void __exit chnl_exit_module(void) | ||
436 | { | ||
437 | struct chnl_net *dev = NULL; | ||
438 | struct list_head *list_node; | ||
439 | struct list_head *_tmp; | ||
440 | rtnl_link_unregister(&ipcaif_link_ops); | ||
441 | rtnl_lock(); | ||
442 | list_for_each_safe(list_node, _tmp, &chnl_net_list) { | ||
443 | dev = list_entry(list_node, struct chnl_net, list_field); | ||
444 | list_del(list_node); | ||
445 | delete_device(dev); | ||
446 | } | ||
447 | rtnl_unlock(); | ||
448 | } | ||
449 | |||
450 | module_init(chnl_init_module); | ||
451 | module_exit(chnl_exit_module); | ||
diff --git a/net/can/bcm.c b/net/can/bcm.c index e32af52238a2..907dc871fac8 100644 --- a/net/can/bcm.c +++ b/net/can/bcm.c | |||
@@ -56,6 +56,7 @@ | |||
56 | #include <linux/can.h> | 56 | #include <linux/can.h> |
57 | #include <linux/can/core.h> | 57 | #include <linux/can/core.h> |
58 | #include <linux/can/bcm.h> | 58 | #include <linux/can/bcm.h> |
59 | #include <linux/slab.h> | ||
59 | #include <net/sock.h> | 60 | #include <net/sock.h> |
60 | #include <net/net_namespace.h> | 61 | #include <net/net_namespace.h> |
61 | 62 | ||
@@ -1478,6 +1479,9 @@ static int bcm_connect(struct socket *sock, struct sockaddr *uaddr, int len, | |||
1478 | struct sock *sk = sock->sk; | 1479 | struct sock *sk = sock->sk; |
1479 | struct bcm_sock *bo = bcm_sk(sk); | 1480 | struct bcm_sock *bo = bcm_sk(sk); |
1480 | 1481 | ||
1482 | if (len < sizeof(*addr)) | ||
1483 | return -EINVAL; | ||
1484 | |||
1481 | if (bo->bound) | 1485 | if (bo->bound) |
1482 | return -EISCONN; | 1486 | return -EISCONN; |
1483 | 1487 | ||
diff --git a/net/can/raw.c b/net/can/raw.c index abca920440b5..da99cf153b33 100644 --- a/net/can/raw.c +++ b/net/can/raw.c | |||
@@ -45,6 +45,7 @@ | |||
45 | #include <linux/init.h> | 45 | #include <linux/init.h> |
46 | #include <linux/uio.h> | 46 | #include <linux/uio.h> |
47 | #include <linux/net.h> | 47 | #include <linux/net.h> |
48 | #include <linux/slab.h> | ||
48 | #include <linux/netdevice.h> | 49 | #include <linux/netdevice.h> |
49 | #include <linux/socket.h> | 50 | #include <linux/socket.h> |
50 | #include <linux/if_arp.h> | 51 | #include <linux/if_arp.h> |
@@ -444,7 +445,7 @@ static int raw_setsockopt(struct socket *sock, int level, int optname, | |||
444 | return -EFAULT; | 445 | return -EFAULT; |
445 | } | 446 | } |
446 | } else if (count == 1) { | 447 | } else if (count == 1) { |
447 | if (copy_from_user(&sfilter, optval, optlen)) | 448 | if (copy_from_user(&sfilter, optval, sizeof(sfilter))) |
448 | return -EFAULT; | 449 | return -EFAULT; |
449 | } | 450 | } |
450 | 451 | ||
diff --git a/net/compat.c b/net/compat.c index a1fb1b079a82..ec24d9edb025 100644 --- a/net/compat.c +++ b/net/compat.c | |||
@@ -12,6 +12,7 @@ | |||
12 | */ | 12 | */ |
13 | 13 | ||
14 | #include <linux/kernel.h> | 14 | #include <linux/kernel.h> |
15 | #include <linux/gfp.h> | ||
15 | #include <linux/fs.h> | 16 | #include <linux/fs.h> |
16 | #include <linux/types.h> | 17 | #include <linux/types.h> |
17 | #include <linux/file.h> | 18 | #include <linux/file.h> |
diff --git a/net/core/Makefile b/net/core/Makefile index 08791ac3e05a..51c3eec850ef 100644 --- a/net/core/Makefile +++ b/net/core/Makefile | |||
@@ -7,7 +7,7 @@ obj-y := sock.o request_sock.o skbuff.o iovec.o datagram.o stream.o scm.o \ | |||
7 | 7 | ||
8 | obj-$(CONFIG_SYSCTL) += sysctl_net_core.o | 8 | obj-$(CONFIG_SYSCTL) += sysctl_net_core.o |
9 | 9 | ||
10 | obj-y += dev.o ethtool.o dev_mcast.o dst.o netevent.o \ | 10 | obj-y += dev.o ethtool.o dev_addr_lists.o dst.o netevent.o \ |
11 | neighbour.o rtnetlink.o utils.o link_watch.o filter.o | 11 | neighbour.o rtnetlink.o utils.o link_watch.o filter.o |
12 | 12 | ||
13 | obj-$(CONFIG_XFRM) += flow.o | 13 | obj-$(CONFIG_XFRM) += flow.o |
diff --git a/net/core/datagram.c b/net/core/datagram.c index 95c2e0840d0d..2dccd4ee591b 100644 --- a/net/core/datagram.c +++ b/net/core/datagram.c | |||
@@ -48,6 +48,7 @@ | |||
48 | #include <linux/poll.h> | 48 | #include <linux/poll.h> |
49 | #include <linux/highmem.h> | 49 | #include <linux/highmem.h> |
50 | #include <linux/spinlock.h> | 50 | #include <linux/spinlock.h> |
51 | #include <linux/slab.h> | ||
51 | 52 | ||
52 | #include <net/protocol.h> | 53 | #include <net/protocol.h> |
53 | #include <linux/skbuff.h> | 54 | #include <linux/skbuff.h> |
diff --git a/net/core/dev.c b/net/core/dev.c index bcc490cc9452..876b1112d5ba 100644 --- a/net/core/dev.c +++ b/net/core/dev.c | |||
@@ -80,6 +80,7 @@ | |||
80 | #include <linux/types.h> | 80 | #include <linux/types.h> |
81 | #include <linux/kernel.h> | 81 | #include <linux/kernel.h> |
82 | #include <linux/hash.h> | 82 | #include <linux/hash.h> |
83 | #include <linux/slab.h> | ||
83 | #include <linux/sched.h> | 84 | #include <linux/sched.h> |
84 | #include <linux/mutex.h> | 85 | #include <linux/mutex.h> |
85 | #include <linux/string.h> | 86 | #include <linux/string.h> |
@@ -129,6 +130,7 @@ | |||
129 | #include <linux/jhash.h> | 130 | #include <linux/jhash.h> |
130 | #include <linux/random.h> | 131 | #include <linux/random.h> |
131 | #include <trace/events/napi.h> | 132 | #include <trace/events/napi.h> |
133 | #include <linux/pci.h> | ||
132 | 134 | ||
133 | #include "net-sysfs.h" | 135 | #include "net-sysfs.h" |
134 | 136 | ||
@@ -206,6 +208,20 @@ static inline struct hlist_head *dev_index_hash(struct net *net, int ifindex) | |||
206 | return &net->dev_index_head[ifindex & (NETDEV_HASHENTRIES - 1)]; | 208 | return &net->dev_index_head[ifindex & (NETDEV_HASHENTRIES - 1)]; |
207 | } | 209 | } |
208 | 210 | ||
211 | static inline void rps_lock(struct softnet_data *queue) | ||
212 | { | ||
213 | #ifdef CONFIG_RPS | ||
214 | spin_lock(&queue->input_pkt_queue.lock); | ||
215 | #endif | ||
216 | } | ||
217 | |||
218 | static inline void rps_unlock(struct softnet_data *queue) | ||
219 | { | ||
220 | #ifdef CONFIG_RPS | ||
221 | spin_unlock(&queue->input_pkt_queue.lock); | ||
222 | #endif | ||
223 | } | ||
224 | |||
209 | /* Device list insertion */ | 225 | /* Device list insertion */ |
210 | static int list_netdevice(struct net_device *dev) | 226 | static int list_netdevice(struct net_device *dev) |
211 | { | 227 | { |
@@ -772,14 +788,17 @@ EXPORT_SYMBOL(__dev_getfirstbyhwtype); | |||
772 | 788 | ||
773 | struct net_device *dev_getfirstbyhwtype(struct net *net, unsigned short type) | 789 | struct net_device *dev_getfirstbyhwtype(struct net *net, unsigned short type) |
774 | { | 790 | { |
775 | struct net_device *dev; | 791 | struct net_device *dev, *ret = NULL; |
776 | 792 | ||
777 | rtnl_lock(); | 793 | rcu_read_lock(); |
778 | dev = __dev_getfirstbyhwtype(net, type); | 794 | for_each_netdev_rcu(net, dev) |
779 | if (dev) | 795 | if (dev->type == type) { |
780 | dev_hold(dev); | 796 | dev_hold(dev); |
781 | rtnl_unlock(); | 797 | ret = dev; |
782 | return dev; | 798 | break; |
799 | } | ||
800 | rcu_read_unlock(); | ||
801 | return ret; | ||
783 | } | 802 | } |
784 | EXPORT_SYMBOL(dev_getfirstbyhwtype); | 803 | EXPORT_SYMBOL(dev_getfirstbyhwtype); |
785 | 804 | ||
@@ -1084,9 +1103,9 @@ void netdev_state_change(struct net_device *dev) | |||
1084 | } | 1103 | } |
1085 | EXPORT_SYMBOL(netdev_state_change); | 1104 | EXPORT_SYMBOL(netdev_state_change); |
1086 | 1105 | ||
1087 | void netdev_bonding_change(struct net_device *dev, unsigned long event) | 1106 | int netdev_bonding_change(struct net_device *dev, unsigned long event) |
1088 | { | 1107 | { |
1089 | call_netdevice_notifiers(event, dev); | 1108 | return call_netdevice_notifiers(event, dev); |
1090 | } | 1109 | } |
1091 | EXPORT_SYMBOL(netdev_bonding_change); | 1110 | EXPORT_SYMBOL(netdev_bonding_change); |
1092 | 1111 | ||
@@ -1783,18 +1802,27 @@ EXPORT_SYMBOL(netdev_rx_csum_fault); | |||
1783 | * 2. No high memory really exists on this machine. | 1802 | * 2. No high memory really exists on this machine. |
1784 | */ | 1803 | */ |
1785 | 1804 | ||
1786 | static inline int illegal_highdma(struct net_device *dev, struct sk_buff *skb) | 1805 | static int illegal_highdma(struct net_device *dev, struct sk_buff *skb) |
1787 | { | 1806 | { |
1788 | #ifdef CONFIG_HIGHMEM | 1807 | #ifdef CONFIG_HIGHMEM |
1789 | int i; | 1808 | int i; |
1809 | if (!(dev->features & NETIF_F_HIGHDMA)) { | ||
1810 | for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) | ||
1811 | if (PageHighMem(skb_shinfo(skb)->frags[i].page)) | ||
1812 | return 1; | ||
1813 | } | ||
1790 | 1814 | ||
1791 | if (dev->features & NETIF_F_HIGHDMA) | 1815 | if (PCI_DMA_BUS_IS_PHYS) { |
1792 | return 0; | 1816 | struct device *pdev = dev->dev.parent; |
1793 | |||
1794 | for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) | ||
1795 | if (PageHighMem(skb_shinfo(skb)->frags[i].page)) | ||
1796 | return 1; | ||
1797 | 1817 | ||
1818 | if (!pdev) | ||
1819 | return 0; | ||
1820 | for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { | ||
1821 | dma_addr_t addr = page_to_phys(skb_shinfo(skb)->frags[i].page); | ||
1822 | if (!pdev->dma_mask || addr + PAGE_SIZE - 1 > *pdev->dma_mask) | ||
1823 | return 1; | ||
1824 | } | ||
1825 | } | ||
1798 | #endif | 1826 | #endif |
1799 | return 0; | 1827 | return 0; |
1800 | } | 1828 | } |
@@ -1931,7 +1959,7 @@ out_kfree_skb: | |||
1931 | return rc; | 1959 | return rc; |
1932 | } | 1960 | } |
1933 | 1961 | ||
1934 | static u32 skb_tx_hashrnd; | 1962 | static u32 hashrnd __read_mostly; |
1935 | 1963 | ||
1936 | u16 skb_tx_hash(const struct net_device *dev, const struct sk_buff *skb) | 1964 | u16 skb_tx_hash(const struct net_device *dev, const struct sk_buff *skb) |
1937 | { | 1965 | { |
@@ -1949,7 +1977,7 @@ u16 skb_tx_hash(const struct net_device *dev, const struct sk_buff *skb) | |||
1949 | else | 1977 | else |
1950 | hash = skb->protocol; | 1978 | hash = skb->protocol; |
1951 | 1979 | ||
1952 | hash = jhash_1word(hash, skb_tx_hashrnd); | 1980 | hash = jhash_1word(hash, hashrnd); |
1953 | 1981 | ||
1954 | return (u16) (((u64) hash * dev->real_num_tx_queues) >> 32); | 1982 | return (u16) (((u64) hash * dev->real_num_tx_queues) >> 32); |
1955 | } | 1983 | } |
@@ -1959,10 +1987,9 @@ static inline u16 dev_cap_txqueue(struct net_device *dev, u16 queue_index) | |||
1959 | { | 1987 | { |
1960 | if (unlikely(queue_index >= dev->real_num_tx_queues)) { | 1988 | if (unlikely(queue_index >= dev->real_num_tx_queues)) { |
1961 | if (net_ratelimit()) { | 1989 | if (net_ratelimit()) { |
1962 | WARN(1, "%s selects TX queue %d, but " | 1990 | pr_warning("%s selects TX queue %d, but " |
1963 | "real number of TX queues is %d\n", | 1991 | "real number of TX queues is %d\n", |
1964 | dev->name, queue_index, | 1992 | dev->name, queue_index, dev->real_num_tx_queues); |
1965 | dev->real_num_tx_queues); | ||
1966 | } | 1993 | } |
1967 | return 0; | 1994 | return 0; |
1968 | } | 1995 | } |
@@ -1988,7 +2015,7 @@ static struct netdev_queue *dev_pick_tx(struct net_device *dev, | |||
1988 | if (dev->real_num_tx_queues > 1) | 2015 | if (dev->real_num_tx_queues > 1) |
1989 | queue_index = skb_tx_hash(dev, skb); | 2016 | queue_index = skb_tx_hash(dev, skb); |
1990 | 2017 | ||
1991 | if (sk && sk->sk_dst_cache) | 2018 | if (sk && rcu_dereference_check(sk->sk_dst_cache, 1)) |
1992 | sk_tx_queue_set(sk, queue_index); | 2019 | sk_tx_queue_set(sk, queue_index); |
1993 | } | 2020 | } |
1994 | } | 2021 | } |
@@ -2175,6 +2202,178 @@ int weight_p __read_mostly = 64; /* old backlog weight */ | |||
2175 | 2202 | ||
2176 | DEFINE_PER_CPU(struct netif_rx_stats, netdev_rx_stat) = { 0, }; | 2203 | DEFINE_PER_CPU(struct netif_rx_stats, netdev_rx_stat) = { 0, }; |
2177 | 2204 | ||
2205 | #ifdef CONFIG_RPS | ||
2206 | /* | ||
2207 | * get_rps_cpu is called from netif_receive_skb and returns the target | ||
2208 | * CPU from the RPS map of the receiving queue for a given skb. | ||
2209 | */ | ||
2210 | static int get_rps_cpu(struct net_device *dev, struct sk_buff *skb) | ||
2211 | { | ||
2212 | struct ipv6hdr *ip6; | ||
2213 | struct iphdr *ip; | ||
2214 | struct netdev_rx_queue *rxqueue; | ||
2215 | struct rps_map *map; | ||
2216 | int cpu = -1; | ||
2217 | u8 ip_proto; | ||
2218 | u32 addr1, addr2, ports, ihl; | ||
2219 | |||
2220 | rcu_read_lock(); | ||
2221 | |||
2222 | if (skb_rx_queue_recorded(skb)) { | ||
2223 | u16 index = skb_get_rx_queue(skb); | ||
2224 | if (unlikely(index >= dev->num_rx_queues)) { | ||
2225 | if (net_ratelimit()) { | ||
2226 | pr_warning("%s received packet on queue " | ||
2227 | "%u, but number of RX queues is %u\n", | ||
2228 | dev->name, index, dev->num_rx_queues); | ||
2229 | } | ||
2230 | goto done; | ||
2231 | } | ||
2232 | rxqueue = dev->_rx + index; | ||
2233 | } else | ||
2234 | rxqueue = dev->_rx; | ||
2235 | |||
2236 | if (!rxqueue->rps_map) | ||
2237 | goto done; | ||
2238 | |||
2239 | if (skb->rxhash) | ||
2240 | goto got_hash; /* Skip hash computation on packet header */ | ||
2241 | |||
2242 | switch (skb->protocol) { | ||
2243 | case __constant_htons(ETH_P_IP): | ||
2244 | if (!pskb_may_pull(skb, sizeof(*ip))) | ||
2245 | goto done; | ||
2246 | |||
2247 | ip = (struct iphdr *) skb->data; | ||
2248 | ip_proto = ip->protocol; | ||
2249 | addr1 = ip->saddr; | ||
2250 | addr2 = ip->daddr; | ||
2251 | ihl = ip->ihl; | ||
2252 | break; | ||
2253 | case __constant_htons(ETH_P_IPV6): | ||
2254 | if (!pskb_may_pull(skb, sizeof(*ip6))) | ||
2255 | goto done; | ||
2256 | |||
2257 | ip6 = (struct ipv6hdr *) skb->data; | ||
2258 | ip_proto = ip6->nexthdr; | ||
2259 | addr1 = ip6->saddr.s6_addr32[3]; | ||
2260 | addr2 = ip6->daddr.s6_addr32[3]; | ||
2261 | ihl = (40 >> 2); | ||
2262 | break; | ||
2263 | default: | ||
2264 | goto done; | ||
2265 | } | ||
2266 | ports = 0; | ||
2267 | switch (ip_proto) { | ||
2268 | case IPPROTO_TCP: | ||
2269 | case IPPROTO_UDP: | ||
2270 | case IPPROTO_DCCP: | ||
2271 | case IPPROTO_ESP: | ||
2272 | case IPPROTO_AH: | ||
2273 | case IPPROTO_SCTP: | ||
2274 | case IPPROTO_UDPLITE: | ||
2275 | if (pskb_may_pull(skb, (ihl * 4) + 4)) | ||
2276 | ports = *((u32 *) (skb->data + (ihl * 4))); | ||
2277 | break; | ||
2278 | |||
2279 | default: | ||
2280 | break; | ||
2281 | } | ||
2282 | |||
2283 | skb->rxhash = jhash_3words(addr1, addr2, ports, hashrnd); | ||
2284 | if (!skb->rxhash) | ||
2285 | skb->rxhash = 1; | ||
2286 | |||
2287 | got_hash: | ||
2288 | map = rcu_dereference(rxqueue->rps_map); | ||
2289 | if (map) { | ||
2290 | u16 tcpu = map->cpus[((u64) skb->rxhash * map->len) >> 32]; | ||
2291 | |||
2292 | if (cpu_online(tcpu)) { | ||
2293 | cpu = tcpu; | ||
2294 | goto done; | ||
2295 | } | ||
2296 | } | ||
2297 | |||
2298 | done: | ||
2299 | rcu_read_unlock(); | ||
2300 | return cpu; | ||
2301 | } | ||
2302 | |||
2303 | /* | ||
2304 | * This structure holds the per-CPU mask of CPUs for which IPIs are scheduled | ||
2305 | * to be sent to kick remote softirq processing. There are two masks since | ||
2306 | * the sending of IPIs must be done with interrupts enabled. The select field | ||
2307 | * indicates the current mask that enqueue_backlog uses to schedule IPIs. | ||
2308 | * select is flipped before net_rps_action is called while still under lock, | ||
2309 | * net_rps_action then uses the non-selected mask to send the IPIs and clears | ||
2310 | * it without conflicting with enqueue_backlog operation. | ||
2311 | */ | ||
2312 | struct rps_remote_softirq_cpus { | ||
2313 | cpumask_t mask[2]; | ||
2314 | int select; | ||
2315 | }; | ||
2316 | static DEFINE_PER_CPU(struct rps_remote_softirq_cpus, rps_remote_softirq_cpus); | ||
2317 | |||
2318 | /* Called from hardirq (IPI) context */ | ||
2319 | static void trigger_softirq(void *data) | ||
2320 | { | ||
2321 | struct softnet_data *queue = data; | ||
2322 | __napi_schedule(&queue->backlog); | ||
2323 | __get_cpu_var(netdev_rx_stat).received_rps++; | ||
2324 | } | ||
2325 | #endif /* CONFIG_SMP */ | ||
2326 | |||
2327 | /* | ||
2328 | * enqueue_to_backlog is called to queue an skb to a per CPU backlog | ||
2329 | * queue (may be a remote CPU queue). | ||
2330 | */ | ||
2331 | static int enqueue_to_backlog(struct sk_buff *skb, int cpu) | ||
2332 | { | ||
2333 | struct softnet_data *queue; | ||
2334 | unsigned long flags; | ||
2335 | |||
2336 | queue = &per_cpu(softnet_data, cpu); | ||
2337 | |||
2338 | local_irq_save(flags); | ||
2339 | __get_cpu_var(netdev_rx_stat).total++; | ||
2340 | |||
2341 | rps_lock(queue); | ||
2342 | if (queue->input_pkt_queue.qlen <= netdev_max_backlog) { | ||
2343 | if (queue->input_pkt_queue.qlen) { | ||
2344 | enqueue: | ||
2345 | __skb_queue_tail(&queue->input_pkt_queue, skb); | ||
2346 | rps_unlock(queue); | ||
2347 | local_irq_restore(flags); | ||
2348 | return NET_RX_SUCCESS; | ||
2349 | } | ||
2350 | |||
2351 | /* Schedule NAPI for backlog device */ | ||
2352 | if (napi_schedule_prep(&queue->backlog)) { | ||
2353 | #ifdef CONFIG_RPS | ||
2354 | if (cpu != smp_processor_id()) { | ||
2355 | struct rps_remote_softirq_cpus *rcpus = | ||
2356 | &__get_cpu_var(rps_remote_softirq_cpus); | ||
2357 | |||
2358 | cpu_set(cpu, rcpus->mask[rcpus->select]); | ||
2359 | __raise_softirq_irqoff(NET_RX_SOFTIRQ); | ||
2360 | } else | ||
2361 | __napi_schedule(&queue->backlog); | ||
2362 | #else | ||
2363 | __napi_schedule(&queue->backlog); | ||
2364 | #endif | ||
2365 | } | ||
2366 | goto enqueue; | ||
2367 | } | ||
2368 | |||
2369 | rps_unlock(queue); | ||
2370 | |||
2371 | __get_cpu_var(netdev_rx_stat).dropped++; | ||
2372 | local_irq_restore(flags); | ||
2373 | |||
2374 | kfree_skb(skb); | ||
2375 | return NET_RX_DROP; | ||
2376 | } | ||
2178 | 2377 | ||
2179 | /** | 2378 | /** |
2180 | * netif_rx - post buffer to the network code | 2379 | * netif_rx - post buffer to the network code |
@@ -2193,8 +2392,7 @@ DEFINE_PER_CPU(struct netif_rx_stats, netdev_rx_stat) = { 0, }; | |||
2193 | 2392 | ||
2194 | int netif_rx(struct sk_buff *skb) | 2393 | int netif_rx(struct sk_buff *skb) |
2195 | { | 2394 | { |
2196 | struct softnet_data *queue; | 2395 | int cpu; |
2197 | unsigned long flags; | ||
2198 | 2396 | ||
2199 | /* if netpoll wants it, pretend we never saw it */ | 2397 | /* if netpoll wants it, pretend we never saw it */ |
2200 | if (netpoll_rx(skb)) | 2398 | if (netpoll_rx(skb)) |
@@ -2203,31 +2401,15 @@ int netif_rx(struct sk_buff *skb) | |||
2203 | if (!skb->tstamp.tv64) | 2401 | if (!skb->tstamp.tv64) |
2204 | net_timestamp(skb); | 2402 | net_timestamp(skb); |
2205 | 2403 | ||
2206 | /* | 2404 | #ifdef CONFIG_RPS |
2207 | * The code is rearranged so that the path is the most | 2405 | cpu = get_rps_cpu(skb->dev, skb); |
2208 | * short when CPU is congested, but is still operating. | 2406 | if (cpu < 0) |
2209 | */ | 2407 | cpu = smp_processor_id(); |
2210 | local_irq_save(flags); | 2408 | #else |
2211 | queue = &__get_cpu_var(softnet_data); | 2409 | cpu = smp_processor_id(); |
2212 | 2410 | #endif | |
2213 | __get_cpu_var(netdev_rx_stat).total++; | ||
2214 | if (queue->input_pkt_queue.qlen <= netdev_max_backlog) { | ||
2215 | if (queue->input_pkt_queue.qlen) { | ||
2216 | enqueue: | ||
2217 | __skb_queue_tail(&queue->input_pkt_queue, skb); | ||
2218 | local_irq_restore(flags); | ||
2219 | return NET_RX_SUCCESS; | ||
2220 | } | ||
2221 | |||
2222 | napi_schedule(&queue->backlog); | ||
2223 | goto enqueue; | ||
2224 | } | ||
2225 | |||
2226 | __get_cpu_var(netdev_rx_stat).dropped++; | ||
2227 | local_irq_restore(flags); | ||
2228 | 2411 | ||
2229 | kfree_skb(skb); | 2412 | return enqueue_to_backlog(skb, cpu); |
2230 | return NET_RX_DROP; | ||
2231 | } | 2413 | } |
2232 | EXPORT_SYMBOL(netif_rx); | 2414 | EXPORT_SYMBOL(netif_rx); |
2233 | 2415 | ||
@@ -2464,25 +2646,60 @@ void netif_nit_deliver(struct sk_buff *skb) | |||
2464 | rcu_read_unlock(); | 2646 | rcu_read_unlock(); |
2465 | } | 2647 | } |
2466 | 2648 | ||
2467 | /** | 2649 | static inline void skb_bond_set_mac_by_master(struct sk_buff *skb, |
2468 | * netif_receive_skb - process receive buffer from network | 2650 | struct net_device *master) |
2469 | * @skb: buffer to process | 2651 | { |
2470 | * | 2652 | if (skb->pkt_type == PACKET_HOST) { |
2471 | * netif_receive_skb() is the main receive data processing function. | 2653 | u16 *dest = (u16 *) eth_hdr(skb)->h_dest; |
2472 | * It always succeeds. The buffer may be dropped during processing | 2654 | |
2473 | * for congestion control or by the protocol layers. | 2655 | memcpy(dest, master->dev_addr, ETH_ALEN); |
2474 | * | 2656 | } |
2475 | * This function may only be called from softirq context and interrupts | 2657 | } |
2476 | * should be enabled. | 2658 | |
2477 | * | 2659 | /* On bonding slaves other than the currently active slave, suppress |
2478 | * Return values (usually ignored): | 2660 | * duplicates except for 802.3ad ETH_P_SLOW, alb non-mcast/bcast, and |
2479 | * NET_RX_SUCCESS: no congestion | 2661 | * ARP on active-backup slaves with arp_validate enabled. |
2480 | * NET_RX_DROP: packet was dropped | ||
2481 | */ | 2662 | */ |
2482 | int netif_receive_skb(struct sk_buff *skb) | 2663 | int __skb_bond_should_drop(struct sk_buff *skb, struct net_device *master) |
2664 | { | ||
2665 | struct net_device *dev = skb->dev; | ||
2666 | |||
2667 | if (master->priv_flags & IFF_MASTER_ARPMON) | ||
2668 | dev->last_rx = jiffies; | ||
2669 | |||
2670 | if ((master->priv_flags & IFF_MASTER_ALB) && master->br_port) { | ||
2671 | /* Do address unmangle. The local destination address | ||
2672 | * will be always the one master has. Provides the right | ||
2673 | * functionality in a bridge. | ||
2674 | */ | ||
2675 | skb_bond_set_mac_by_master(skb, master); | ||
2676 | } | ||
2677 | |||
2678 | if (dev->priv_flags & IFF_SLAVE_INACTIVE) { | ||
2679 | if ((dev->priv_flags & IFF_SLAVE_NEEDARP) && | ||
2680 | skb->protocol == __cpu_to_be16(ETH_P_ARP)) | ||
2681 | return 0; | ||
2682 | |||
2683 | if (master->priv_flags & IFF_MASTER_ALB) { | ||
2684 | if (skb->pkt_type != PACKET_BROADCAST && | ||
2685 | skb->pkt_type != PACKET_MULTICAST) | ||
2686 | return 0; | ||
2687 | } | ||
2688 | if (master->priv_flags & IFF_MASTER_8023AD && | ||
2689 | skb->protocol == __cpu_to_be16(ETH_P_SLOW)) | ||
2690 | return 0; | ||
2691 | |||
2692 | return 1; | ||
2693 | } | ||
2694 | return 0; | ||
2695 | } | ||
2696 | EXPORT_SYMBOL(__skb_bond_should_drop); | ||
2697 | |||
2698 | static int __netif_receive_skb(struct sk_buff *skb) | ||
2483 | { | 2699 | { |
2484 | struct packet_type *ptype, *pt_prev; | 2700 | struct packet_type *ptype, *pt_prev; |
2485 | struct net_device *orig_dev; | 2701 | struct net_device *orig_dev; |
2702 | struct net_device *master; | ||
2486 | struct net_device *null_or_orig; | 2703 | struct net_device *null_or_orig; |
2487 | struct net_device *null_or_bond; | 2704 | struct net_device *null_or_bond; |
2488 | int ret = NET_RX_DROP; | 2705 | int ret = NET_RX_DROP; |
@@ -2503,11 +2720,12 @@ int netif_receive_skb(struct sk_buff *skb) | |||
2503 | 2720 | ||
2504 | null_or_orig = NULL; | 2721 | null_or_orig = NULL; |
2505 | orig_dev = skb->dev; | 2722 | orig_dev = skb->dev; |
2506 | if (orig_dev->master) { | 2723 | master = ACCESS_ONCE(orig_dev->master); |
2507 | if (skb_bond_should_drop(skb)) | 2724 | if (master) { |
2725 | if (skb_bond_should_drop(skb, master)) | ||
2508 | null_or_orig = orig_dev; /* deliver only exact match */ | 2726 | null_or_orig = orig_dev; /* deliver only exact match */ |
2509 | else | 2727 | else |
2510 | skb->dev = orig_dev->master; | 2728 | skb->dev = master; |
2511 | } | 2729 | } |
2512 | 2730 | ||
2513 | __get_cpu_var(netdev_rx_stat).total++; | 2731 | __get_cpu_var(netdev_rx_stat).total++; |
@@ -2588,6 +2806,37 @@ out: | |||
2588 | rcu_read_unlock(); | 2806 | rcu_read_unlock(); |
2589 | return ret; | 2807 | return ret; |
2590 | } | 2808 | } |
2809 | |||
2810 | /** | ||
2811 | * netif_receive_skb - process receive buffer from network | ||
2812 | * @skb: buffer to process | ||
2813 | * | ||
2814 | * netif_receive_skb() is the main receive data processing function. | ||
2815 | * It always succeeds. The buffer may be dropped during processing | ||
2816 | * for congestion control or by the protocol layers. | ||
2817 | * | ||
2818 | * This function may only be called from softirq context and interrupts | ||
2819 | * should be enabled. | ||
2820 | * | ||
2821 | * Return values (usually ignored): | ||
2822 | * NET_RX_SUCCESS: no congestion | ||
2823 | * NET_RX_DROP: packet was dropped | ||
2824 | */ | ||
2825 | int netif_receive_skb(struct sk_buff *skb) | ||
2826 | { | ||
2827 | #ifdef CONFIG_RPS | ||
2828 | int cpu; | ||
2829 | |||
2830 | cpu = get_rps_cpu(skb->dev, skb); | ||
2831 | |||
2832 | if (cpu < 0) | ||
2833 | return __netif_receive_skb(skb); | ||
2834 | else | ||
2835 | return enqueue_to_backlog(skb, cpu); | ||
2836 | #else | ||
2837 | return __netif_receive_skb(skb); | ||
2838 | #endif | ||
2839 | } | ||
2591 | EXPORT_SYMBOL(netif_receive_skb); | 2840 | EXPORT_SYMBOL(netif_receive_skb); |
2592 | 2841 | ||
2593 | /* Network device is going away, flush any packets still pending */ | 2842 | /* Network device is going away, flush any packets still pending */ |
@@ -2597,11 +2846,13 @@ static void flush_backlog(void *arg) | |||
2597 | struct softnet_data *queue = &__get_cpu_var(softnet_data); | 2846 | struct softnet_data *queue = &__get_cpu_var(softnet_data); |
2598 | struct sk_buff *skb, *tmp; | 2847 | struct sk_buff *skb, *tmp; |
2599 | 2848 | ||
2849 | rps_lock(queue); | ||
2600 | skb_queue_walk_safe(&queue->input_pkt_queue, skb, tmp) | 2850 | skb_queue_walk_safe(&queue->input_pkt_queue, skb, tmp) |
2601 | if (skb->dev == dev) { | 2851 | if (skb->dev == dev) { |
2602 | __skb_unlink(skb, &queue->input_pkt_queue); | 2852 | __skb_unlink(skb, &queue->input_pkt_queue); |
2603 | kfree_skb(skb); | 2853 | kfree_skb(skb); |
2604 | } | 2854 | } |
2855 | rps_unlock(queue); | ||
2605 | } | 2856 | } |
2606 | 2857 | ||
2607 | static int napi_gro_complete(struct sk_buff *skb) | 2858 | static int napi_gro_complete(struct sk_buff *skb) |
@@ -2915,15 +3166,18 @@ static int process_backlog(struct napi_struct *napi, int quota) | |||
2915 | struct sk_buff *skb; | 3166 | struct sk_buff *skb; |
2916 | 3167 | ||
2917 | local_irq_disable(); | 3168 | local_irq_disable(); |
3169 | rps_lock(queue); | ||
2918 | skb = __skb_dequeue(&queue->input_pkt_queue); | 3170 | skb = __skb_dequeue(&queue->input_pkt_queue); |
2919 | if (!skb) { | 3171 | if (!skb) { |
2920 | __napi_complete(napi); | 3172 | __napi_complete(napi); |
3173 | rps_unlock(queue); | ||
2921 | local_irq_enable(); | 3174 | local_irq_enable(); |
2922 | break; | 3175 | break; |
2923 | } | 3176 | } |
3177 | rps_unlock(queue); | ||
2924 | local_irq_enable(); | 3178 | local_irq_enable(); |
2925 | 3179 | ||
2926 | netif_receive_skb(skb); | 3180 | __netif_receive_skb(skb); |
2927 | } while (++work < quota && jiffies == start_time); | 3181 | } while (++work < quota && jiffies == start_time); |
2928 | 3182 | ||
2929 | return work; | 3183 | return work; |
@@ -3012,6 +3266,24 @@ void netif_napi_del(struct napi_struct *napi) | |||
3012 | } | 3266 | } |
3013 | EXPORT_SYMBOL(netif_napi_del); | 3267 | EXPORT_SYMBOL(netif_napi_del); |
3014 | 3268 | ||
3269 | #ifdef CONFIG_RPS | ||
3270 | /* | ||
3271 | * net_rps_action sends any pending IPI's for rps. This is only called from | ||
3272 | * softirq and interrupts must be enabled. | ||
3273 | */ | ||
3274 | static void net_rps_action(cpumask_t *mask) | ||
3275 | { | ||
3276 | int cpu; | ||
3277 | |||
3278 | /* Send pending IPI's to kick RPS processing on remote cpus. */ | ||
3279 | for_each_cpu_mask_nr(cpu, *mask) { | ||
3280 | struct softnet_data *queue = &per_cpu(softnet_data, cpu); | ||
3281 | if (cpu_online(cpu)) | ||
3282 | __smp_call_function_single(cpu, &queue->csd, 0); | ||
3283 | } | ||
3284 | cpus_clear(*mask); | ||
3285 | } | ||
3286 | #endif | ||
3015 | 3287 | ||
3016 | static void net_rx_action(struct softirq_action *h) | 3288 | static void net_rx_action(struct softirq_action *h) |
3017 | { | 3289 | { |
@@ -3019,6 +3291,10 @@ static void net_rx_action(struct softirq_action *h) | |||
3019 | unsigned long time_limit = jiffies + 2; | 3291 | unsigned long time_limit = jiffies + 2; |
3020 | int budget = netdev_budget; | 3292 | int budget = netdev_budget; |
3021 | void *have; | 3293 | void *have; |
3294 | #ifdef CONFIG_RPS | ||
3295 | int select; | ||
3296 | struct rps_remote_softirq_cpus *rcpus; | ||
3297 | #endif | ||
3022 | 3298 | ||
3023 | local_irq_disable(); | 3299 | local_irq_disable(); |
3024 | 3300 | ||
@@ -3081,7 +3357,17 @@ static void net_rx_action(struct softirq_action *h) | |||
3081 | netpoll_poll_unlock(have); | 3357 | netpoll_poll_unlock(have); |
3082 | } | 3358 | } |
3083 | out: | 3359 | out: |
3360 | #ifdef CONFIG_RPS | ||
3361 | rcpus = &__get_cpu_var(rps_remote_softirq_cpus); | ||
3362 | select = rcpus->select; | ||
3363 | rcpus->select ^= 1; | ||
3364 | |||
3365 | local_irq_enable(); | ||
3366 | |||
3367 | net_rps_action(&rcpus->mask[select]); | ||
3368 | #else | ||
3084 | local_irq_enable(); | 3369 | local_irq_enable(); |
3370 | #endif | ||
3085 | 3371 | ||
3086 | #ifdef CONFIG_NET_DMA | 3372 | #ifdef CONFIG_NET_DMA |
3087 | /* | 3373 | /* |
@@ -3327,10 +3613,10 @@ static int softnet_seq_show(struct seq_file *seq, void *v) | |||
3327 | { | 3613 | { |
3328 | struct netif_rx_stats *s = v; | 3614 | struct netif_rx_stats *s = v; |
3329 | 3615 | ||
3330 | seq_printf(seq, "%08x %08x %08x %08x %08x %08x %08x %08x %08x\n", | 3616 | seq_printf(seq, "%08x %08x %08x %08x %08x %08x %08x %08x %08x %08x\n", |
3331 | s->total, s->dropped, s->time_squeeze, 0, | 3617 | s->total, s->dropped, s->time_squeeze, 0, |
3332 | 0, 0, 0, 0, /* was fastroute */ | 3618 | 0, 0, 0, 0, /* was fastroute */ |
3333 | s->cpu_collision); | 3619 | s->cpu_collision, s->received_rps); |
3334 | return 0; | 3620 | return 0; |
3335 | } | 3621 | } |
3336 | 3622 | ||
@@ -3553,11 +3839,10 @@ int netdev_set_master(struct net_device *slave, struct net_device *master) | |||
3553 | 3839 | ||
3554 | slave->master = master; | 3840 | slave->master = master; |
3555 | 3841 | ||
3556 | synchronize_net(); | 3842 | if (old) { |
3557 | 3843 | synchronize_net(); | |
3558 | if (old) | ||
3559 | dev_put(old); | 3844 | dev_put(old); |
3560 | 3845 | } | |
3561 | if (master) | 3846 | if (master) |
3562 | slave->flags |= IFF_SLAVE; | 3847 | slave->flags |= IFF_SLAVE; |
3563 | else | 3848 | else |
@@ -3734,562 +4019,6 @@ void dev_set_rx_mode(struct net_device *dev) | |||
3734 | netif_addr_unlock_bh(dev); | 4019 | netif_addr_unlock_bh(dev); |
3735 | } | 4020 | } |
3736 | 4021 | ||
3737 | /* hw addresses list handling functions */ | ||
3738 | |||
3739 | static int __hw_addr_add(struct netdev_hw_addr_list *list, unsigned char *addr, | ||
3740 | int addr_len, unsigned char addr_type) | ||
3741 | { | ||
3742 | struct netdev_hw_addr *ha; | ||
3743 | int alloc_size; | ||
3744 | |||
3745 | if (addr_len > MAX_ADDR_LEN) | ||
3746 | return -EINVAL; | ||
3747 | |||
3748 | list_for_each_entry(ha, &list->list, list) { | ||
3749 | if (!memcmp(ha->addr, addr, addr_len) && | ||
3750 | ha->type == addr_type) { | ||
3751 | ha->refcount++; | ||
3752 | return 0; | ||
3753 | } | ||
3754 | } | ||
3755 | |||
3756 | |||
3757 | alloc_size = sizeof(*ha); | ||
3758 | if (alloc_size < L1_CACHE_BYTES) | ||
3759 | alloc_size = L1_CACHE_BYTES; | ||
3760 | ha = kmalloc(alloc_size, GFP_ATOMIC); | ||
3761 | if (!ha) | ||
3762 | return -ENOMEM; | ||
3763 | memcpy(ha->addr, addr, addr_len); | ||
3764 | ha->type = addr_type; | ||
3765 | ha->refcount = 1; | ||
3766 | ha->synced = false; | ||
3767 | list_add_tail_rcu(&ha->list, &list->list); | ||
3768 | list->count++; | ||
3769 | return 0; | ||
3770 | } | ||
3771 | |||
3772 | static void ha_rcu_free(struct rcu_head *head) | ||
3773 | { | ||
3774 | struct netdev_hw_addr *ha; | ||
3775 | |||
3776 | ha = container_of(head, struct netdev_hw_addr, rcu_head); | ||
3777 | kfree(ha); | ||
3778 | } | ||
3779 | |||
3780 | static int __hw_addr_del(struct netdev_hw_addr_list *list, unsigned char *addr, | ||
3781 | int addr_len, unsigned char addr_type) | ||
3782 | { | ||
3783 | struct netdev_hw_addr *ha; | ||
3784 | |||
3785 | list_for_each_entry(ha, &list->list, list) { | ||
3786 | if (!memcmp(ha->addr, addr, addr_len) && | ||
3787 | (ha->type == addr_type || !addr_type)) { | ||
3788 | if (--ha->refcount) | ||
3789 | return 0; | ||
3790 | list_del_rcu(&ha->list); | ||
3791 | call_rcu(&ha->rcu_head, ha_rcu_free); | ||
3792 | list->count--; | ||
3793 | return 0; | ||
3794 | } | ||
3795 | } | ||
3796 | return -ENOENT; | ||
3797 | } | ||
3798 | |||
3799 | static int __hw_addr_add_multiple(struct netdev_hw_addr_list *to_list, | ||
3800 | struct netdev_hw_addr_list *from_list, | ||
3801 | int addr_len, | ||
3802 | unsigned char addr_type) | ||
3803 | { | ||
3804 | int err; | ||
3805 | struct netdev_hw_addr *ha, *ha2; | ||
3806 | unsigned char type; | ||
3807 | |||
3808 | list_for_each_entry(ha, &from_list->list, list) { | ||
3809 | type = addr_type ? addr_type : ha->type; | ||
3810 | err = __hw_addr_add(to_list, ha->addr, addr_len, type); | ||
3811 | if (err) | ||
3812 | goto unroll; | ||
3813 | } | ||
3814 | return 0; | ||
3815 | |||
3816 | unroll: | ||
3817 | list_for_each_entry(ha2, &from_list->list, list) { | ||
3818 | if (ha2 == ha) | ||
3819 | break; | ||
3820 | type = addr_type ? addr_type : ha2->type; | ||
3821 | __hw_addr_del(to_list, ha2->addr, addr_len, type); | ||
3822 | } | ||
3823 | return err; | ||
3824 | } | ||
3825 | |||
3826 | static void __hw_addr_del_multiple(struct netdev_hw_addr_list *to_list, | ||
3827 | struct netdev_hw_addr_list *from_list, | ||
3828 | int addr_len, | ||
3829 | unsigned char addr_type) | ||
3830 | { | ||
3831 | struct netdev_hw_addr *ha; | ||
3832 | unsigned char type; | ||
3833 | |||
3834 | list_for_each_entry(ha, &from_list->list, list) { | ||
3835 | type = addr_type ? addr_type : ha->type; | ||
3836 | __hw_addr_del(to_list, ha->addr, addr_len, addr_type); | ||
3837 | } | ||
3838 | } | ||
3839 | |||
3840 | static int __hw_addr_sync(struct netdev_hw_addr_list *to_list, | ||
3841 | struct netdev_hw_addr_list *from_list, | ||
3842 | int addr_len) | ||
3843 | { | ||
3844 | int err = 0; | ||
3845 | struct netdev_hw_addr *ha, *tmp; | ||
3846 | |||
3847 | list_for_each_entry_safe(ha, tmp, &from_list->list, list) { | ||
3848 | if (!ha->synced) { | ||
3849 | err = __hw_addr_add(to_list, ha->addr, | ||
3850 | addr_len, ha->type); | ||
3851 | if (err) | ||
3852 | break; | ||
3853 | ha->synced = true; | ||
3854 | ha->refcount++; | ||
3855 | } else if (ha->refcount == 1) { | ||
3856 | __hw_addr_del(to_list, ha->addr, addr_len, ha->type); | ||
3857 | __hw_addr_del(from_list, ha->addr, addr_len, ha->type); | ||
3858 | } | ||
3859 | } | ||
3860 | return err; | ||
3861 | } | ||
3862 | |||
3863 | static void __hw_addr_unsync(struct netdev_hw_addr_list *to_list, | ||
3864 | struct netdev_hw_addr_list *from_list, | ||
3865 | int addr_len) | ||
3866 | { | ||
3867 | struct netdev_hw_addr *ha, *tmp; | ||
3868 | |||
3869 | list_for_each_entry_safe(ha, tmp, &from_list->list, list) { | ||
3870 | if (ha->synced) { | ||
3871 | __hw_addr_del(to_list, ha->addr, | ||
3872 | addr_len, ha->type); | ||
3873 | ha->synced = false; | ||
3874 | __hw_addr_del(from_list, ha->addr, | ||
3875 | addr_len, ha->type); | ||
3876 | } | ||
3877 | } | ||
3878 | } | ||
3879 | |||
3880 | static void __hw_addr_flush(struct netdev_hw_addr_list *list) | ||
3881 | { | ||
3882 | struct netdev_hw_addr *ha, *tmp; | ||
3883 | |||
3884 | list_for_each_entry_safe(ha, tmp, &list->list, list) { | ||
3885 | list_del_rcu(&ha->list); | ||
3886 | call_rcu(&ha->rcu_head, ha_rcu_free); | ||
3887 | } | ||
3888 | list->count = 0; | ||
3889 | } | ||
3890 | |||
3891 | static void __hw_addr_init(struct netdev_hw_addr_list *list) | ||
3892 | { | ||
3893 | INIT_LIST_HEAD(&list->list); | ||
3894 | list->count = 0; | ||
3895 | } | ||
3896 | |||
3897 | /* Device addresses handling functions */ | ||
3898 | |||
3899 | static void dev_addr_flush(struct net_device *dev) | ||
3900 | { | ||
3901 | /* rtnl_mutex must be held here */ | ||
3902 | |||
3903 | __hw_addr_flush(&dev->dev_addrs); | ||
3904 | dev->dev_addr = NULL; | ||
3905 | } | ||
3906 | |||
3907 | static int dev_addr_init(struct net_device *dev) | ||
3908 | { | ||
3909 | unsigned char addr[MAX_ADDR_LEN]; | ||
3910 | struct netdev_hw_addr *ha; | ||
3911 | int err; | ||
3912 | |||
3913 | /* rtnl_mutex must be held here */ | ||
3914 | |||
3915 | __hw_addr_init(&dev->dev_addrs); | ||
3916 | memset(addr, 0, sizeof(addr)); | ||
3917 | err = __hw_addr_add(&dev->dev_addrs, addr, sizeof(addr), | ||
3918 | NETDEV_HW_ADDR_T_LAN); | ||
3919 | if (!err) { | ||
3920 | /* | ||
3921 | * Get the first (previously created) address from the list | ||
3922 | * and set dev_addr pointer to this location. | ||
3923 | */ | ||
3924 | ha = list_first_entry(&dev->dev_addrs.list, | ||
3925 | struct netdev_hw_addr, list); | ||
3926 | dev->dev_addr = ha->addr; | ||
3927 | } | ||
3928 | return err; | ||
3929 | } | ||
3930 | |||
3931 | /** | ||
3932 | * dev_addr_add - Add a device address | ||
3933 | * @dev: device | ||
3934 | * @addr: address to add | ||
3935 | * @addr_type: address type | ||
3936 | * | ||
3937 | * Add a device address to the device or increase the reference count if | ||
3938 | * it already exists. | ||
3939 | * | ||
3940 | * The caller must hold the rtnl_mutex. | ||
3941 | */ | ||
3942 | int dev_addr_add(struct net_device *dev, unsigned char *addr, | ||
3943 | unsigned char addr_type) | ||
3944 | { | ||
3945 | int err; | ||
3946 | |||
3947 | ASSERT_RTNL(); | ||
3948 | |||
3949 | err = __hw_addr_add(&dev->dev_addrs, addr, dev->addr_len, addr_type); | ||
3950 | if (!err) | ||
3951 | call_netdevice_notifiers(NETDEV_CHANGEADDR, dev); | ||
3952 | return err; | ||
3953 | } | ||
3954 | EXPORT_SYMBOL(dev_addr_add); | ||
3955 | |||
3956 | /** | ||
3957 | * dev_addr_del - Release a device address. | ||
3958 | * @dev: device | ||
3959 | * @addr: address to delete | ||
3960 | * @addr_type: address type | ||
3961 | * | ||
3962 | * Release reference to a device address and remove it from the device | ||
3963 | * if the reference count drops to zero. | ||
3964 | * | ||
3965 | * The caller must hold the rtnl_mutex. | ||
3966 | */ | ||
3967 | int dev_addr_del(struct net_device *dev, unsigned char *addr, | ||
3968 | unsigned char addr_type) | ||
3969 | { | ||
3970 | int err; | ||
3971 | struct netdev_hw_addr *ha; | ||
3972 | |||
3973 | ASSERT_RTNL(); | ||
3974 | |||
3975 | /* | ||
3976 | * We can not remove the first address from the list because | ||
3977 | * dev->dev_addr points to that. | ||
3978 | */ | ||
3979 | ha = list_first_entry(&dev->dev_addrs.list, | ||
3980 | struct netdev_hw_addr, list); | ||
3981 | if (ha->addr == dev->dev_addr && ha->refcount == 1) | ||
3982 | return -ENOENT; | ||
3983 | |||
3984 | err = __hw_addr_del(&dev->dev_addrs, addr, dev->addr_len, | ||
3985 | addr_type); | ||
3986 | if (!err) | ||
3987 | call_netdevice_notifiers(NETDEV_CHANGEADDR, dev); | ||
3988 | return err; | ||
3989 | } | ||
3990 | EXPORT_SYMBOL(dev_addr_del); | ||
3991 | |||
3992 | /** | ||
3993 | * dev_addr_add_multiple - Add device addresses from another device | ||
3994 | * @to_dev: device to which addresses will be added | ||
3995 | * @from_dev: device from which addresses will be added | ||
3996 | * @addr_type: address type - 0 means type will be used from from_dev | ||
3997 | * | ||
3998 | * Add device addresses of the one device to another. | ||
3999 | ** | ||
4000 | * The caller must hold the rtnl_mutex. | ||
4001 | */ | ||
4002 | int dev_addr_add_multiple(struct net_device *to_dev, | ||
4003 | struct net_device *from_dev, | ||
4004 | unsigned char addr_type) | ||
4005 | { | ||
4006 | int err; | ||
4007 | |||
4008 | ASSERT_RTNL(); | ||
4009 | |||
4010 | if (from_dev->addr_len != to_dev->addr_len) | ||
4011 | return -EINVAL; | ||
4012 | err = __hw_addr_add_multiple(&to_dev->dev_addrs, &from_dev->dev_addrs, | ||
4013 | to_dev->addr_len, addr_type); | ||
4014 | if (!err) | ||
4015 | call_netdevice_notifiers(NETDEV_CHANGEADDR, to_dev); | ||
4016 | return err; | ||
4017 | } | ||
4018 | EXPORT_SYMBOL(dev_addr_add_multiple); | ||
4019 | |||
4020 | /** | ||
4021 | * dev_addr_del_multiple - Delete device addresses by another device | ||
4022 | * @to_dev: device where the addresses will be deleted | ||
4023 | * @from_dev: device by which addresses the addresses will be deleted | ||
4024 | * @addr_type: address type - 0 means type will used from from_dev | ||
4025 | * | ||
4026 | * Deletes addresses in to device by the list of addresses in from device. | ||
4027 | * | ||
4028 | * The caller must hold the rtnl_mutex. | ||
4029 | */ | ||
4030 | int dev_addr_del_multiple(struct net_device *to_dev, | ||
4031 | struct net_device *from_dev, | ||
4032 | unsigned char addr_type) | ||
4033 | { | ||
4034 | ASSERT_RTNL(); | ||
4035 | |||
4036 | if (from_dev->addr_len != to_dev->addr_len) | ||
4037 | return -EINVAL; | ||
4038 | __hw_addr_del_multiple(&to_dev->dev_addrs, &from_dev->dev_addrs, | ||
4039 | to_dev->addr_len, addr_type); | ||
4040 | call_netdevice_notifiers(NETDEV_CHANGEADDR, to_dev); | ||
4041 | return 0; | ||
4042 | } | ||
4043 | EXPORT_SYMBOL(dev_addr_del_multiple); | ||
4044 | |||
4045 | /* multicast addresses handling functions */ | ||
4046 | |||
4047 | int __dev_addr_delete(struct dev_addr_list **list, int *count, | ||
4048 | void *addr, int alen, int glbl) | ||
4049 | { | ||
4050 | struct dev_addr_list *da; | ||
4051 | |||
4052 | for (; (da = *list) != NULL; list = &da->next) { | ||
4053 | if (memcmp(da->da_addr, addr, da->da_addrlen) == 0 && | ||
4054 | alen == da->da_addrlen) { | ||
4055 | if (glbl) { | ||
4056 | int old_glbl = da->da_gusers; | ||
4057 | da->da_gusers = 0; | ||
4058 | if (old_glbl == 0) | ||
4059 | break; | ||
4060 | } | ||
4061 | if (--da->da_users) | ||
4062 | return 0; | ||
4063 | |||
4064 | *list = da->next; | ||
4065 | kfree(da); | ||
4066 | (*count)--; | ||
4067 | return 0; | ||
4068 | } | ||
4069 | } | ||
4070 | return -ENOENT; | ||
4071 | } | ||
4072 | |||
4073 | int __dev_addr_add(struct dev_addr_list **list, int *count, | ||
4074 | void *addr, int alen, int glbl) | ||
4075 | { | ||
4076 | struct dev_addr_list *da; | ||
4077 | |||
4078 | for (da = *list; da != NULL; da = da->next) { | ||
4079 | if (memcmp(da->da_addr, addr, da->da_addrlen) == 0 && | ||
4080 | da->da_addrlen == alen) { | ||
4081 | if (glbl) { | ||
4082 | int old_glbl = da->da_gusers; | ||
4083 | da->da_gusers = 1; | ||
4084 | if (old_glbl) | ||
4085 | return 0; | ||
4086 | } | ||
4087 | da->da_users++; | ||
4088 | return 0; | ||
4089 | } | ||
4090 | } | ||
4091 | |||
4092 | da = kzalloc(sizeof(*da), GFP_ATOMIC); | ||
4093 | if (da == NULL) | ||
4094 | return -ENOMEM; | ||
4095 | memcpy(da->da_addr, addr, alen); | ||
4096 | da->da_addrlen = alen; | ||
4097 | da->da_users = 1; | ||
4098 | da->da_gusers = glbl ? 1 : 0; | ||
4099 | da->next = *list; | ||
4100 | *list = da; | ||
4101 | (*count)++; | ||
4102 | return 0; | ||
4103 | } | ||
4104 | |||
4105 | /** | ||
4106 | * dev_unicast_delete - Release secondary unicast address. | ||
4107 | * @dev: device | ||
4108 | * @addr: address to delete | ||
4109 | * | ||
4110 | * Release reference to a secondary unicast address and remove it | ||
4111 | * from the device if the reference count drops to zero. | ||
4112 | * | ||
4113 | * The caller must hold the rtnl_mutex. | ||
4114 | */ | ||
4115 | int dev_unicast_delete(struct net_device *dev, void *addr) | ||
4116 | { | ||
4117 | int err; | ||
4118 | |||
4119 | ASSERT_RTNL(); | ||
4120 | |||
4121 | netif_addr_lock_bh(dev); | ||
4122 | err = __hw_addr_del(&dev->uc, addr, dev->addr_len, | ||
4123 | NETDEV_HW_ADDR_T_UNICAST); | ||
4124 | if (!err) | ||
4125 | __dev_set_rx_mode(dev); | ||
4126 | netif_addr_unlock_bh(dev); | ||
4127 | return err; | ||
4128 | } | ||
4129 | EXPORT_SYMBOL(dev_unicast_delete); | ||
4130 | |||
4131 | /** | ||
4132 | * dev_unicast_add - add a secondary unicast address | ||
4133 | * @dev: device | ||
4134 | * @addr: address to add | ||
4135 | * | ||
4136 | * Add a secondary unicast address to the device or increase | ||
4137 | * the reference count if it already exists. | ||
4138 | * | ||
4139 | * The caller must hold the rtnl_mutex. | ||
4140 | */ | ||
4141 | int dev_unicast_add(struct net_device *dev, void *addr) | ||
4142 | { | ||
4143 | int err; | ||
4144 | |||
4145 | ASSERT_RTNL(); | ||
4146 | |||
4147 | netif_addr_lock_bh(dev); | ||
4148 | err = __hw_addr_add(&dev->uc, addr, dev->addr_len, | ||
4149 | NETDEV_HW_ADDR_T_UNICAST); | ||
4150 | if (!err) | ||
4151 | __dev_set_rx_mode(dev); | ||
4152 | netif_addr_unlock_bh(dev); | ||
4153 | return err; | ||
4154 | } | ||
4155 | EXPORT_SYMBOL(dev_unicast_add); | ||
4156 | |||
4157 | int __dev_addr_sync(struct dev_addr_list **to, int *to_count, | ||
4158 | struct dev_addr_list **from, int *from_count) | ||
4159 | { | ||
4160 | struct dev_addr_list *da, *next; | ||
4161 | int err = 0; | ||
4162 | |||
4163 | da = *from; | ||
4164 | while (da != NULL) { | ||
4165 | next = da->next; | ||
4166 | if (!da->da_synced) { | ||
4167 | err = __dev_addr_add(to, to_count, | ||
4168 | da->da_addr, da->da_addrlen, 0); | ||
4169 | if (err < 0) | ||
4170 | break; | ||
4171 | da->da_synced = 1; | ||
4172 | da->da_users++; | ||
4173 | } else if (da->da_users == 1) { | ||
4174 | __dev_addr_delete(to, to_count, | ||
4175 | da->da_addr, da->da_addrlen, 0); | ||
4176 | __dev_addr_delete(from, from_count, | ||
4177 | da->da_addr, da->da_addrlen, 0); | ||
4178 | } | ||
4179 | da = next; | ||
4180 | } | ||
4181 | return err; | ||
4182 | } | ||
4183 | EXPORT_SYMBOL_GPL(__dev_addr_sync); | ||
4184 | |||
4185 | void __dev_addr_unsync(struct dev_addr_list **to, int *to_count, | ||
4186 | struct dev_addr_list **from, int *from_count) | ||
4187 | { | ||
4188 | struct dev_addr_list *da, *next; | ||
4189 | |||
4190 | da = *from; | ||
4191 | while (da != NULL) { | ||
4192 | next = da->next; | ||
4193 | if (da->da_synced) { | ||
4194 | __dev_addr_delete(to, to_count, | ||
4195 | da->da_addr, da->da_addrlen, 0); | ||
4196 | da->da_synced = 0; | ||
4197 | __dev_addr_delete(from, from_count, | ||
4198 | da->da_addr, da->da_addrlen, 0); | ||
4199 | } | ||
4200 | da = next; | ||
4201 | } | ||
4202 | } | ||
4203 | EXPORT_SYMBOL_GPL(__dev_addr_unsync); | ||
4204 | |||
4205 | /** | ||
4206 | * dev_unicast_sync - Synchronize device's unicast list to another device | ||
4207 | * @to: destination device | ||
4208 | * @from: source device | ||
4209 | * | ||
4210 | * Add newly added addresses to the destination device and release | ||
4211 | * addresses that have no users left. The source device must be | ||
4212 | * locked by netif_tx_lock_bh. | ||
4213 | * | ||
4214 | * This function is intended to be called from the dev->set_rx_mode | ||
4215 | * function of layered software devices. | ||
4216 | */ | ||
4217 | int dev_unicast_sync(struct net_device *to, struct net_device *from) | ||
4218 | { | ||
4219 | int err = 0; | ||
4220 | |||
4221 | if (to->addr_len != from->addr_len) | ||
4222 | return -EINVAL; | ||
4223 | |||
4224 | netif_addr_lock_bh(to); | ||
4225 | err = __hw_addr_sync(&to->uc, &from->uc, to->addr_len); | ||
4226 | if (!err) | ||
4227 | __dev_set_rx_mode(to); | ||
4228 | netif_addr_unlock_bh(to); | ||
4229 | return err; | ||
4230 | } | ||
4231 | EXPORT_SYMBOL(dev_unicast_sync); | ||
4232 | |||
4233 | /** | ||
4234 | * dev_unicast_unsync - Remove synchronized addresses from the destination device | ||
4235 | * @to: destination device | ||
4236 | * @from: source device | ||
4237 | * | ||
4238 | * Remove all addresses that were added to the destination device by | ||
4239 | * dev_unicast_sync(). This function is intended to be called from the | ||
4240 | * dev->stop function of layered software devices. | ||
4241 | */ | ||
4242 | void dev_unicast_unsync(struct net_device *to, struct net_device *from) | ||
4243 | { | ||
4244 | if (to->addr_len != from->addr_len) | ||
4245 | return; | ||
4246 | |||
4247 | netif_addr_lock_bh(from); | ||
4248 | netif_addr_lock(to); | ||
4249 | __hw_addr_unsync(&to->uc, &from->uc, to->addr_len); | ||
4250 | __dev_set_rx_mode(to); | ||
4251 | netif_addr_unlock(to); | ||
4252 | netif_addr_unlock_bh(from); | ||
4253 | } | ||
4254 | EXPORT_SYMBOL(dev_unicast_unsync); | ||
4255 | |||
4256 | static void dev_unicast_flush(struct net_device *dev) | ||
4257 | { | ||
4258 | netif_addr_lock_bh(dev); | ||
4259 | __hw_addr_flush(&dev->uc); | ||
4260 | netif_addr_unlock_bh(dev); | ||
4261 | } | ||
4262 | |||
4263 | static void dev_unicast_init(struct net_device *dev) | ||
4264 | { | ||
4265 | __hw_addr_init(&dev->uc); | ||
4266 | } | ||
4267 | |||
4268 | |||
4269 | static void __dev_addr_discard(struct dev_addr_list **list) | ||
4270 | { | ||
4271 | struct dev_addr_list *tmp; | ||
4272 | |||
4273 | while (*list != NULL) { | ||
4274 | tmp = *list; | ||
4275 | *list = tmp->next; | ||
4276 | if (tmp->da_users > tmp->da_gusers) | ||
4277 | printk("__dev_addr_discard: address leakage! " | ||
4278 | "da_users=%d\n", tmp->da_users); | ||
4279 | kfree(tmp); | ||
4280 | } | ||
4281 | } | ||
4282 | |||
4283 | static void dev_addr_discard(struct net_device *dev) | ||
4284 | { | ||
4285 | netif_addr_lock_bh(dev); | ||
4286 | |||
4287 | __dev_addr_discard(&dev->mc_list); | ||
4288 | netdev_mc_count(dev) = 0; | ||
4289 | |||
4290 | netif_addr_unlock_bh(dev); | ||
4291 | } | ||
4292 | |||
4293 | /** | 4022 | /** |
4294 | * dev_get_flags - get flags reported to userspace | 4023 | * dev_get_flags - get flags reported to userspace |
4295 | * @dev: device | 4024 | * @dev: device |
@@ -4600,8 +4329,7 @@ static int dev_ifsioc(struct net *net, struct ifreq *ifr, unsigned int cmd) | |||
4600 | return -EINVAL; | 4329 | return -EINVAL; |
4601 | if (!netif_device_present(dev)) | 4330 | if (!netif_device_present(dev)) |
4602 | return -ENODEV; | 4331 | return -ENODEV; |
4603 | return dev_mc_add(dev, ifr->ifr_hwaddr.sa_data, | 4332 | return dev_mc_add_global(dev, ifr->ifr_hwaddr.sa_data); |
4604 | dev->addr_len, 1); | ||
4605 | 4333 | ||
4606 | case SIOCDELMULTI: | 4334 | case SIOCDELMULTI: |
4607 | if ((!ops->ndo_set_multicast_list && !ops->ndo_set_rx_mode) || | 4335 | if ((!ops->ndo_set_multicast_list && !ops->ndo_set_rx_mode) || |
@@ -4609,8 +4337,7 @@ static int dev_ifsioc(struct net *net, struct ifreq *ifr, unsigned int cmd) | |||
4609 | return -EINVAL; | 4337 | return -EINVAL; |
4610 | if (!netif_device_present(dev)) | 4338 | if (!netif_device_present(dev)) |
4611 | return -ENODEV; | 4339 | return -ENODEV; |
4612 | return dev_mc_delete(dev, ifr->ifr_hwaddr.sa_data, | 4340 | return dev_mc_del_global(dev, ifr->ifr_hwaddr.sa_data); |
4613 | dev->addr_len, 1); | ||
4614 | 4341 | ||
4615 | case SIOCSIFTXQLEN: | 4342 | case SIOCSIFTXQLEN: |
4616 | if (ifr->ifr_qlen < 0) | 4343 | if (ifr->ifr_qlen < 0) |
@@ -4917,8 +4644,8 @@ static void rollback_registered_many(struct list_head *head) | |||
4917 | /* | 4644 | /* |
4918 | * Flush the unicast and multicast chains | 4645 | * Flush the unicast and multicast chains |
4919 | */ | 4646 | */ |
4920 | dev_unicast_flush(dev); | 4647 | dev_uc_flush(dev); |
4921 | dev_addr_discard(dev); | 4648 | dev_mc_flush(dev); |
4922 | 4649 | ||
4923 | if (dev->netdev_ops->ndo_uninit) | 4650 | if (dev->netdev_ops->ndo_uninit) |
4924 | dev->netdev_ops->ndo_uninit(dev); | 4651 | dev->netdev_ops->ndo_uninit(dev); |
@@ -5067,6 +4794,24 @@ int register_netdevice(struct net_device *dev) | |||
5067 | 4794 | ||
5068 | dev->iflink = -1; | 4795 | dev->iflink = -1; |
5069 | 4796 | ||
4797 | #ifdef CONFIG_RPS | ||
4798 | if (!dev->num_rx_queues) { | ||
4799 | /* | ||
4800 | * Allocate a single RX queue if driver never called | ||
4801 | * alloc_netdev_mq | ||
4802 | */ | ||
4803 | |||
4804 | dev->_rx = kzalloc(sizeof(struct netdev_rx_queue), GFP_KERNEL); | ||
4805 | if (!dev->_rx) { | ||
4806 | ret = -ENOMEM; | ||
4807 | goto out; | ||
4808 | } | ||
4809 | |||
4810 | dev->_rx->first = dev->_rx; | ||
4811 | atomic_set(&dev->_rx->count, 1); | ||
4812 | dev->num_rx_queues = 1; | ||
4813 | } | ||
4814 | #endif | ||
5070 | /* Init, if this function is available */ | 4815 | /* Init, if this function is available */ |
5071 | if (dev->netdev_ops->ndo_init) { | 4816 | if (dev->netdev_ops->ndo_init) { |
5072 | ret = dev->netdev_ops->ndo_init(dev); | 4817 | ret = dev->netdev_ops->ndo_init(dev); |
@@ -5427,6 +5172,10 @@ struct net_device *alloc_netdev_mq(int sizeof_priv, const char *name, | |||
5427 | struct net_device *dev; | 5172 | struct net_device *dev; |
5428 | size_t alloc_size; | 5173 | size_t alloc_size; |
5429 | struct net_device *p; | 5174 | struct net_device *p; |
5175 | #ifdef CONFIG_RPS | ||
5176 | struct netdev_rx_queue *rx; | ||
5177 | int i; | ||
5178 | #endif | ||
5430 | 5179 | ||
5431 | BUG_ON(strlen(name) >= sizeof(dev->name)); | 5180 | BUG_ON(strlen(name) >= sizeof(dev->name)); |
5432 | 5181 | ||
@@ -5452,13 +5201,32 @@ struct net_device *alloc_netdev_mq(int sizeof_priv, const char *name, | |||
5452 | goto free_p; | 5201 | goto free_p; |
5453 | } | 5202 | } |
5454 | 5203 | ||
5204 | #ifdef CONFIG_RPS | ||
5205 | rx = kcalloc(queue_count, sizeof(struct netdev_rx_queue), GFP_KERNEL); | ||
5206 | if (!rx) { | ||
5207 | printk(KERN_ERR "alloc_netdev: Unable to allocate " | ||
5208 | "rx queues.\n"); | ||
5209 | goto free_tx; | ||
5210 | } | ||
5211 | |||
5212 | atomic_set(&rx->count, queue_count); | ||
5213 | |||
5214 | /* | ||
5215 | * Set a pointer to first element in the array which holds the | ||
5216 | * reference count. | ||
5217 | */ | ||
5218 | for (i = 0; i < queue_count; i++) | ||
5219 | rx[i].first = rx; | ||
5220 | #endif | ||
5221 | |||
5455 | dev = PTR_ALIGN(p, NETDEV_ALIGN); | 5222 | dev = PTR_ALIGN(p, NETDEV_ALIGN); |
5456 | dev->padded = (char *)dev - (char *)p; | 5223 | dev->padded = (char *)dev - (char *)p; |
5457 | 5224 | ||
5458 | if (dev_addr_init(dev)) | 5225 | if (dev_addr_init(dev)) |
5459 | goto free_tx; | 5226 | goto free_rx; |
5460 | 5227 | ||
5461 | dev_unicast_init(dev); | 5228 | dev_mc_init(dev); |
5229 | dev_uc_init(dev); | ||
5462 | 5230 | ||
5463 | dev_net_set(dev, &init_net); | 5231 | dev_net_set(dev, &init_net); |
5464 | 5232 | ||
@@ -5466,6 +5234,11 @@ struct net_device *alloc_netdev_mq(int sizeof_priv, const char *name, | |||
5466 | dev->num_tx_queues = queue_count; | 5234 | dev->num_tx_queues = queue_count; |
5467 | dev->real_num_tx_queues = queue_count; | 5235 | dev->real_num_tx_queues = queue_count; |
5468 | 5236 | ||
5237 | #ifdef CONFIG_RPS | ||
5238 | dev->_rx = rx; | ||
5239 | dev->num_rx_queues = queue_count; | ||
5240 | #endif | ||
5241 | |||
5469 | dev->gso_max_size = GSO_MAX_SIZE; | 5242 | dev->gso_max_size = GSO_MAX_SIZE; |
5470 | 5243 | ||
5471 | netdev_init_queues(dev); | 5244 | netdev_init_queues(dev); |
@@ -5480,9 +5253,12 @@ struct net_device *alloc_netdev_mq(int sizeof_priv, const char *name, | |||
5480 | strcpy(dev->name, name); | 5253 | strcpy(dev->name, name); |
5481 | return dev; | 5254 | return dev; |
5482 | 5255 | ||
5256 | free_rx: | ||
5257 | #ifdef CONFIG_RPS | ||
5258 | kfree(rx); | ||
5483 | free_tx: | 5259 | free_tx: |
5260 | #endif | ||
5484 | kfree(tx); | 5261 | kfree(tx); |
5485 | |||
5486 | free_p: | 5262 | free_p: |
5487 | kfree(p); | 5263 | kfree(p); |
5488 | return NULL; | 5264 | return NULL; |
@@ -5684,8 +5460,8 @@ int dev_change_net_namespace(struct net_device *dev, struct net *net, const char | |||
5684 | /* | 5460 | /* |
5685 | * Flush the unicast and multicast chains | 5461 | * Flush the unicast and multicast chains |
5686 | */ | 5462 | */ |
5687 | dev_unicast_flush(dev); | 5463 | dev_uc_flush(dev); |
5688 | dev_addr_discard(dev); | 5464 | dev_mc_flush(dev); |
5689 | 5465 | ||
5690 | netdev_unregister_kobject(dev); | 5466 | netdev_unregister_kobject(dev); |
5691 | 5467 | ||
@@ -5985,6 +5761,12 @@ static int __init net_dev_init(void) | |||
5985 | queue->completion_queue = NULL; | 5761 | queue->completion_queue = NULL; |
5986 | INIT_LIST_HEAD(&queue->poll_list); | 5762 | INIT_LIST_HEAD(&queue->poll_list); |
5987 | 5763 | ||
5764 | #ifdef CONFIG_RPS | ||
5765 | queue->csd.func = trigger_softirq; | ||
5766 | queue->csd.info = queue; | ||
5767 | queue->csd.flags = 0; | ||
5768 | #endif | ||
5769 | |||
5988 | queue->backlog.poll = process_backlog; | 5770 | queue->backlog.poll = process_backlog; |
5989 | queue->backlog.weight = weight_p; | 5771 | queue->backlog.weight = weight_p; |
5990 | queue->backlog.gro_list = NULL; | 5772 | queue->backlog.gro_list = NULL; |
@@ -6023,7 +5805,7 @@ subsys_initcall(net_dev_init); | |||
6023 | 5805 | ||
6024 | static int __init initialize_hashrnd(void) | 5806 | static int __init initialize_hashrnd(void) |
6025 | { | 5807 | { |
6026 | get_random_bytes(&skb_tx_hashrnd, sizeof(skb_tx_hashrnd)); | 5808 | get_random_bytes(&hashrnd, sizeof(hashrnd)); |
6027 | return 0; | 5809 | return 0; |
6028 | } | 5810 | } |
6029 | 5811 | ||
diff --git a/net/core/dev_addr_lists.c b/net/core/dev_addr_lists.c new file mode 100644 index 000000000000..508f9c18992f --- /dev/null +++ b/net/core/dev_addr_lists.c | |||
@@ -0,0 +1,741 @@ | |||
1 | /* | ||
2 | * net/core/dev_addr_lists.c - Functions for handling net device lists | ||
3 | * Copyright (c) 2010 Jiri Pirko <jpirko@redhat.com> | ||
4 | * | ||
5 | * This file contains functions for working with unicast, multicast and device | ||
6 | * addresses lists. | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License as published by | ||
10 | * the Free Software Foundation; either version 2 of the License, or | ||
11 | * (at your option) any later version. | ||
12 | */ | ||
13 | |||
14 | #include <linux/netdevice.h> | ||
15 | #include <linux/rtnetlink.h> | ||
16 | #include <linux/list.h> | ||
17 | #include <linux/proc_fs.h> | ||
18 | |||
19 | /* | ||
20 | * General list handling functions | ||
21 | */ | ||
22 | |||
23 | static int __hw_addr_add_ex(struct netdev_hw_addr_list *list, | ||
24 | unsigned char *addr, int addr_len, | ||
25 | unsigned char addr_type, bool global) | ||
26 | { | ||
27 | struct netdev_hw_addr *ha; | ||
28 | int alloc_size; | ||
29 | |||
30 | if (addr_len > MAX_ADDR_LEN) | ||
31 | return -EINVAL; | ||
32 | |||
33 | list_for_each_entry(ha, &list->list, list) { | ||
34 | if (!memcmp(ha->addr, addr, addr_len) && | ||
35 | ha->type == addr_type) { | ||
36 | if (global) { | ||
37 | /* check if addr is already used as global */ | ||
38 | if (ha->global_use) | ||
39 | return 0; | ||
40 | else | ||
41 | ha->global_use = true; | ||
42 | } | ||
43 | ha->refcount++; | ||
44 | return 0; | ||
45 | } | ||
46 | } | ||
47 | |||
48 | |||
49 | alloc_size = sizeof(*ha); | ||
50 | if (alloc_size < L1_CACHE_BYTES) | ||
51 | alloc_size = L1_CACHE_BYTES; | ||
52 | ha = kmalloc(alloc_size, GFP_ATOMIC); | ||
53 | if (!ha) | ||
54 | return -ENOMEM; | ||
55 | memcpy(ha->addr, addr, addr_len); | ||
56 | ha->type = addr_type; | ||
57 | ha->refcount = 1; | ||
58 | ha->global_use = global; | ||
59 | ha->synced = false; | ||
60 | list_add_tail_rcu(&ha->list, &list->list); | ||
61 | list->count++; | ||
62 | return 0; | ||
63 | } | ||
64 | |||
65 | static int __hw_addr_add(struct netdev_hw_addr_list *list, unsigned char *addr, | ||
66 | int addr_len, unsigned char addr_type) | ||
67 | { | ||
68 | return __hw_addr_add_ex(list, addr, addr_len, addr_type, false); | ||
69 | } | ||
70 | |||
71 | static void ha_rcu_free(struct rcu_head *head) | ||
72 | { | ||
73 | struct netdev_hw_addr *ha; | ||
74 | |||
75 | ha = container_of(head, struct netdev_hw_addr, rcu_head); | ||
76 | kfree(ha); | ||
77 | } | ||
78 | |||
79 | static int __hw_addr_del_ex(struct netdev_hw_addr_list *list, | ||
80 | unsigned char *addr, int addr_len, | ||
81 | unsigned char addr_type, bool global) | ||
82 | { | ||
83 | struct netdev_hw_addr *ha; | ||
84 | |||
85 | list_for_each_entry(ha, &list->list, list) { | ||
86 | if (!memcmp(ha->addr, addr, addr_len) && | ||
87 | (ha->type == addr_type || !addr_type)) { | ||
88 | if (global) { | ||
89 | if (!ha->global_use) | ||
90 | break; | ||
91 | else | ||
92 | ha->global_use = false; | ||
93 | } | ||
94 | if (--ha->refcount) | ||
95 | return 0; | ||
96 | list_del_rcu(&ha->list); | ||
97 | call_rcu(&ha->rcu_head, ha_rcu_free); | ||
98 | list->count--; | ||
99 | return 0; | ||
100 | } | ||
101 | } | ||
102 | return -ENOENT; | ||
103 | } | ||
104 | |||
105 | static int __hw_addr_del(struct netdev_hw_addr_list *list, unsigned char *addr, | ||
106 | int addr_len, unsigned char addr_type) | ||
107 | { | ||
108 | return __hw_addr_del_ex(list, addr, addr_len, addr_type, false); | ||
109 | } | ||
110 | |||
111 | int __hw_addr_add_multiple(struct netdev_hw_addr_list *to_list, | ||
112 | struct netdev_hw_addr_list *from_list, | ||
113 | int addr_len, unsigned char addr_type) | ||
114 | { | ||
115 | int err; | ||
116 | struct netdev_hw_addr *ha, *ha2; | ||
117 | unsigned char type; | ||
118 | |||
119 | list_for_each_entry(ha, &from_list->list, list) { | ||
120 | type = addr_type ? addr_type : ha->type; | ||
121 | err = __hw_addr_add(to_list, ha->addr, addr_len, type); | ||
122 | if (err) | ||
123 | goto unroll; | ||
124 | } | ||
125 | return 0; | ||
126 | |||
127 | unroll: | ||
128 | list_for_each_entry(ha2, &from_list->list, list) { | ||
129 | if (ha2 == ha) | ||
130 | break; | ||
131 | type = addr_type ? addr_type : ha2->type; | ||
132 | __hw_addr_del(to_list, ha2->addr, addr_len, type); | ||
133 | } | ||
134 | return err; | ||
135 | } | ||
136 | EXPORT_SYMBOL(__hw_addr_add_multiple); | ||
137 | |||
138 | void __hw_addr_del_multiple(struct netdev_hw_addr_list *to_list, | ||
139 | struct netdev_hw_addr_list *from_list, | ||
140 | int addr_len, unsigned char addr_type) | ||
141 | { | ||
142 | struct netdev_hw_addr *ha; | ||
143 | unsigned char type; | ||
144 | |||
145 | list_for_each_entry(ha, &from_list->list, list) { | ||
146 | type = addr_type ? addr_type : ha->type; | ||
147 | __hw_addr_del(to_list, ha->addr, addr_len, addr_type); | ||
148 | } | ||
149 | } | ||
150 | EXPORT_SYMBOL(__hw_addr_del_multiple); | ||
151 | |||
152 | int __hw_addr_sync(struct netdev_hw_addr_list *to_list, | ||
153 | struct netdev_hw_addr_list *from_list, | ||
154 | int addr_len) | ||
155 | { | ||
156 | int err = 0; | ||
157 | struct netdev_hw_addr *ha, *tmp; | ||
158 | |||
159 | list_for_each_entry_safe(ha, tmp, &from_list->list, list) { | ||
160 | if (!ha->synced) { | ||
161 | err = __hw_addr_add(to_list, ha->addr, | ||
162 | addr_len, ha->type); | ||
163 | if (err) | ||
164 | break; | ||
165 | ha->synced = true; | ||
166 | ha->refcount++; | ||
167 | } else if (ha->refcount == 1) { | ||
168 | __hw_addr_del(to_list, ha->addr, addr_len, ha->type); | ||
169 | __hw_addr_del(from_list, ha->addr, addr_len, ha->type); | ||
170 | } | ||
171 | } | ||
172 | return err; | ||
173 | } | ||
174 | EXPORT_SYMBOL(__hw_addr_sync); | ||
175 | |||
176 | void __hw_addr_unsync(struct netdev_hw_addr_list *to_list, | ||
177 | struct netdev_hw_addr_list *from_list, | ||
178 | int addr_len) | ||
179 | { | ||
180 | struct netdev_hw_addr *ha, *tmp; | ||
181 | |||
182 | list_for_each_entry_safe(ha, tmp, &from_list->list, list) { | ||
183 | if (ha->synced) { | ||
184 | __hw_addr_del(to_list, ha->addr, | ||
185 | addr_len, ha->type); | ||
186 | ha->synced = false; | ||
187 | __hw_addr_del(from_list, ha->addr, | ||
188 | addr_len, ha->type); | ||
189 | } | ||
190 | } | ||
191 | } | ||
192 | EXPORT_SYMBOL(__hw_addr_unsync); | ||
193 | |||
194 | void __hw_addr_flush(struct netdev_hw_addr_list *list) | ||
195 | { | ||
196 | struct netdev_hw_addr *ha, *tmp; | ||
197 | |||
198 | list_for_each_entry_safe(ha, tmp, &list->list, list) { | ||
199 | list_del_rcu(&ha->list); | ||
200 | call_rcu(&ha->rcu_head, ha_rcu_free); | ||
201 | } | ||
202 | list->count = 0; | ||
203 | } | ||
204 | EXPORT_SYMBOL(__hw_addr_flush); | ||
205 | |||
206 | void __hw_addr_init(struct netdev_hw_addr_list *list) | ||
207 | { | ||
208 | INIT_LIST_HEAD(&list->list); | ||
209 | list->count = 0; | ||
210 | } | ||
211 | EXPORT_SYMBOL(__hw_addr_init); | ||
212 | |||
213 | /* | ||
214 | * Device addresses handling functions | ||
215 | */ | ||
216 | |||
217 | /** | ||
218 | * dev_addr_flush - Flush device address list | ||
219 | * @dev: device | ||
220 | * | ||
221 | * Flush device address list and reset ->dev_addr. | ||
222 | * | ||
223 | * The caller must hold the rtnl_mutex. | ||
224 | */ | ||
225 | void dev_addr_flush(struct net_device *dev) | ||
226 | { | ||
227 | /* rtnl_mutex must be held here */ | ||
228 | |||
229 | __hw_addr_flush(&dev->dev_addrs); | ||
230 | dev->dev_addr = NULL; | ||
231 | } | ||
232 | EXPORT_SYMBOL(dev_addr_flush); | ||
233 | |||
234 | /** | ||
235 | * dev_addr_init - Init device address list | ||
236 | * @dev: device | ||
237 | * | ||
238 | * Init device address list and create the first element, | ||
239 | * used by ->dev_addr. | ||
240 | * | ||
241 | * The caller must hold the rtnl_mutex. | ||
242 | */ | ||
243 | int dev_addr_init(struct net_device *dev) | ||
244 | { | ||
245 | unsigned char addr[MAX_ADDR_LEN]; | ||
246 | struct netdev_hw_addr *ha; | ||
247 | int err; | ||
248 | |||
249 | /* rtnl_mutex must be held here */ | ||
250 | |||
251 | __hw_addr_init(&dev->dev_addrs); | ||
252 | memset(addr, 0, sizeof(addr)); | ||
253 | err = __hw_addr_add(&dev->dev_addrs, addr, sizeof(addr), | ||
254 | NETDEV_HW_ADDR_T_LAN); | ||
255 | if (!err) { | ||
256 | /* | ||
257 | * Get the first (previously created) address from the list | ||
258 | * and set dev_addr pointer to this location. | ||
259 | */ | ||
260 | ha = list_first_entry(&dev->dev_addrs.list, | ||
261 | struct netdev_hw_addr, list); | ||
262 | dev->dev_addr = ha->addr; | ||
263 | } | ||
264 | return err; | ||
265 | } | ||
266 | EXPORT_SYMBOL(dev_addr_init); | ||
267 | |||
268 | /** | ||
269 | * dev_addr_add - Add a device address | ||
270 | * @dev: device | ||
271 | * @addr: address to add | ||
272 | * @addr_type: address type | ||
273 | * | ||
274 | * Add a device address to the device or increase the reference count if | ||
275 | * it already exists. | ||
276 | * | ||
277 | * The caller must hold the rtnl_mutex. | ||
278 | */ | ||
279 | int dev_addr_add(struct net_device *dev, unsigned char *addr, | ||
280 | unsigned char addr_type) | ||
281 | { | ||
282 | int err; | ||
283 | |||
284 | ASSERT_RTNL(); | ||
285 | |||
286 | err = __hw_addr_add(&dev->dev_addrs, addr, dev->addr_len, addr_type); | ||
287 | if (!err) | ||
288 | call_netdevice_notifiers(NETDEV_CHANGEADDR, dev); | ||
289 | return err; | ||
290 | } | ||
291 | EXPORT_SYMBOL(dev_addr_add); | ||
292 | |||
293 | /** | ||
294 | * dev_addr_del - Release a device address. | ||
295 | * @dev: device | ||
296 | * @addr: address to delete | ||
297 | * @addr_type: address type | ||
298 | * | ||
299 | * Release reference to a device address and remove it from the device | ||
300 | * if the reference count drops to zero. | ||
301 | * | ||
302 | * The caller must hold the rtnl_mutex. | ||
303 | */ | ||
304 | int dev_addr_del(struct net_device *dev, unsigned char *addr, | ||
305 | unsigned char addr_type) | ||
306 | { | ||
307 | int err; | ||
308 | struct netdev_hw_addr *ha; | ||
309 | |||
310 | ASSERT_RTNL(); | ||
311 | |||
312 | /* | ||
313 | * We can not remove the first address from the list because | ||
314 | * dev->dev_addr points to that. | ||
315 | */ | ||
316 | ha = list_first_entry(&dev->dev_addrs.list, | ||
317 | struct netdev_hw_addr, list); | ||
318 | if (ha->addr == dev->dev_addr && ha->refcount == 1) | ||
319 | return -ENOENT; | ||
320 | |||
321 | err = __hw_addr_del(&dev->dev_addrs, addr, dev->addr_len, | ||
322 | addr_type); | ||
323 | if (!err) | ||
324 | call_netdevice_notifiers(NETDEV_CHANGEADDR, dev); | ||
325 | return err; | ||
326 | } | ||
327 | EXPORT_SYMBOL(dev_addr_del); | ||
328 | |||
329 | /** | ||
330 | * dev_addr_add_multiple - Add device addresses from another device | ||
331 | * @to_dev: device to which addresses will be added | ||
332 | * @from_dev: device from which addresses will be added | ||
333 | * @addr_type: address type - 0 means type will be used from from_dev | ||
334 | * | ||
335 | * Add device addresses of the one device to another. | ||
336 | ** | ||
337 | * The caller must hold the rtnl_mutex. | ||
338 | */ | ||
339 | int dev_addr_add_multiple(struct net_device *to_dev, | ||
340 | struct net_device *from_dev, | ||
341 | unsigned char addr_type) | ||
342 | { | ||
343 | int err; | ||
344 | |||
345 | ASSERT_RTNL(); | ||
346 | |||
347 | if (from_dev->addr_len != to_dev->addr_len) | ||
348 | return -EINVAL; | ||
349 | err = __hw_addr_add_multiple(&to_dev->dev_addrs, &from_dev->dev_addrs, | ||
350 | to_dev->addr_len, addr_type); | ||
351 | if (!err) | ||
352 | call_netdevice_notifiers(NETDEV_CHANGEADDR, to_dev); | ||
353 | return err; | ||
354 | } | ||
355 | EXPORT_SYMBOL(dev_addr_add_multiple); | ||
356 | |||
357 | /** | ||
358 | * dev_addr_del_multiple - Delete device addresses by another device | ||
359 | * @to_dev: device where the addresses will be deleted | ||
360 | * @from_dev: device by which addresses the addresses will be deleted | ||
361 | * @addr_type: address type - 0 means type will used from from_dev | ||
362 | * | ||
363 | * Deletes addresses in to device by the list of addresses in from device. | ||
364 | * | ||
365 | * The caller must hold the rtnl_mutex. | ||
366 | */ | ||
367 | int dev_addr_del_multiple(struct net_device *to_dev, | ||
368 | struct net_device *from_dev, | ||
369 | unsigned char addr_type) | ||
370 | { | ||
371 | ASSERT_RTNL(); | ||
372 | |||
373 | if (from_dev->addr_len != to_dev->addr_len) | ||
374 | return -EINVAL; | ||
375 | __hw_addr_del_multiple(&to_dev->dev_addrs, &from_dev->dev_addrs, | ||
376 | to_dev->addr_len, addr_type); | ||
377 | call_netdevice_notifiers(NETDEV_CHANGEADDR, to_dev); | ||
378 | return 0; | ||
379 | } | ||
380 | EXPORT_SYMBOL(dev_addr_del_multiple); | ||
381 | |||
382 | /* | ||
383 | * Unicast list handling functions | ||
384 | */ | ||
385 | |||
386 | /** | ||
387 | * dev_uc_add - Add a secondary unicast address | ||
388 | * @dev: device | ||
389 | * @addr: address to add | ||
390 | * | ||
391 | * Add a secondary unicast address to the device or increase | ||
392 | * the reference count if it already exists. | ||
393 | */ | ||
394 | int dev_uc_add(struct net_device *dev, unsigned char *addr) | ||
395 | { | ||
396 | int err; | ||
397 | |||
398 | netif_addr_lock_bh(dev); | ||
399 | err = __hw_addr_add(&dev->uc, addr, dev->addr_len, | ||
400 | NETDEV_HW_ADDR_T_UNICAST); | ||
401 | if (!err) | ||
402 | __dev_set_rx_mode(dev); | ||
403 | netif_addr_unlock_bh(dev); | ||
404 | return err; | ||
405 | } | ||
406 | EXPORT_SYMBOL(dev_uc_add); | ||
407 | |||
408 | /** | ||
409 | * dev_uc_del - Release secondary unicast address. | ||
410 | * @dev: device | ||
411 | * @addr: address to delete | ||
412 | * | ||
413 | * Release reference to a secondary unicast address and remove it | ||
414 | * from the device if the reference count drops to zero. | ||
415 | */ | ||
416 | int dev_uc_del(struct net_device *dev, unsigned char *addr) | ||
417 | { | ||
418 | int err; | ||
419 | |||
420 | netif_addr_lock_bh(dev); | ||
421 | err = __hw_addr_del(&dev->uc, addr, dev->addr_len, | ||
422 | NETDEV_HW_ADDR_T_UNICAST); | ||
423 | if (!err) | ||
424 | __dev_set_rx_mode(dev); | ||
425 | netif_addr_unlock_bh(dev); | ||
426 | return err; | ||
427 | } | ||
428 | EXPORT_SYMBOL(dev_uc_del); | ||
429 | |||
430 | /** | ||
431 | * dev_uc_sync - Synchronize device's unicast list to another device | ||
432 | * @to: destination device | ||
433 | * @from: source device | ||
434 | * | ||
435 | * Add newly added addresses to the destination device and release | ||
436 | * addresses that have no users left. The source device must be | ||
437 | * locked by netif_tx_lock_bh. | ||
438 | * | ||
439 | * This function is intended to be called from the dev->set_rx_mode | ||
440 | * function of layered software devices. | ||
441 | */ | ||
442 | int dev_uc_sync(struct net_device *to, struct net_device *from) | ||
443 | { | ||
444 | int err = 0; | ||
445 | |||
446 | if (to->addr_len != from->addr_len) | ||
447 | return -EINVAL; | ||
448 | |||
449 | netif_addr_lock_bh(to); | ||
450 | err = __hw_addr_sync(&to->uc, &from->uc, to->addr_len); | ||
451 | if (!err) | ||
452 | __dev_set_rx_mode(to); | ||
453 | netif_addr_unlock_bh(to); | ||
454 | return err; | ||
455 | } | ||
456 | EXPORT_SYMBOL(dev_uc_sync); | ||
457 | |||
458 | /** | ||
459 | * dev_uc_unsync - Remove synchronized addresses from the destination device | ||
460 | * @to: destination device | ||
461 | * @from: source device | ||
462 | * | ||
463 | * Remove all addresses that were added to the destination device by | ||
464 | * dev_uc_sync(). This function is intended to be called from the | ||
465 | * dev->stop function of layered software devices. | ||
466 | */ | ||
467 | void dev_uc_unsync(struct net_device *to, struct net_device *from) | ||
468 | { | ||
469 | if (to->addr_len != from->addr_len) | ||
470 | return; | ||
471 | |||
472 | netif_addr_lock_bh(from); | ||
473 | netif_addr_lock(to); | ||
474 | __hw_addr_unsync(&to->uc, &from->uc, to->addr_len); | ||
475 | __dev_set_rx_mode(to); | ||
476 | netif_addr_unlock(to); | ||
477 | netif_addr_unlock_bh(from); | ||
478 | } | ||
479 | EXPORT_SYMBOL(dev_uc_unsync); | ||
480 | |||
481 | /** | ||
482 | * dev_uc_flush - Flush unicast addresses | ||
483 | * @dev: device | ||
484 | * | ||
485 | * Flush unicast addresses. | ||
486 | */ | ||
487 | void dev_uc_flush(struct net_device *dev) | ||
488 | { | ||
489 | netif_addr_lock_bh(dev); | ||
490 | __hw_addr_flush(&dev->uc); | ||
491 | netif_addr_unlock_bh(dev); | ||
492 | } | ||
493 | EXPORT_SYMBOL(dev_uc_flush); | ||
494 | |||
495 | /** | ||
496 | * dev_uc_flush - Init unicast address list | ||
497 | * @dev: device | ||
498 | * | ||
499 | * Init unicast address list. | ||
500 | */ | ||
501 | void dev_uc_init(struct net_device *dev) | ||
502 | { | ||
503 | __hw_addr_init(&dev->uc); | ||
504 | } | ||
505 | EXPORT_SYMBOL(dev_uc_init); | ||
506 | |||
507 | /* | ||
508 | * Multicast list handling functions | ||
509 | */ | ||
510 | |||
511 | static int __dev_mc_add(struct net_device *dev, unsigned char *addr, | ||
512 | bool global) | ||
513 | { | ||
514 | int err; | ||
515 | |||
516 | netif_addr_lock_bh(dev); | ||
517 | err = __hw_addr_add_ex(&dev->mc, addr, dev->addr_len, | ||
518 | NETDEV_HW_ADDR_T_MULTICAST, global); | ||
519 | if (!err) | ||
520 | __dev_set_rx_mode(dev); | ||
521 | netif_addr_unlock_bh(dev); | ||
522 | return err; | ||
523 | } | ||
524 | /** | ||
525 | * dev_mc_add - Add a multicast address | ||
526 | * @dev: device | ||
527 | * @addr: address to add | ||
528 | * | ||
529 | * Add a multicast address to the device or increase | ||
530 | * the reference count if it already exists. | ||
531 | */ | ||
532 | int dev_mc_add(struct net_device *dev, unsigned char *addr) | ||
533 | { | ||
534 | return __dev_mc_add(dev, addr, false); | ||
535 | } | ||
536 | EXPORT_SYMBOL(dev_mc_add); | ||
537 | |||
538 | /** | ||
539 | * dev_mc_add_global - Add a global multicast address | ||
540 | * @dev: device | ||
541 | * @addr: address to add | ||
542 | * | ||
543 | * Add a global multicast address to the device. | ||
544 | */ | ||
545 | int dev_mc_add_global(struct net_device *dev, unsigned char *addr) | ||
546 | { | ||
547 | return __dev_mc_add(dev, addr, true); | ||
548 | } | ||
549 | EXPORT_SYMBOL(dev_mc_add_global); | ||
550 | |||
551 | static int __dev_mc_del(struct net_device *dev, unsigned char *addr, | ||
552 | bool global) | ||
553 | { | ||
554 | int err; | ||
555 | |||
556 | netif_addr_lock_bh(dev); | ||
557 | err = __hw_addr_del_ex(&dev->mc, addr, dev->addr_len, | ||
558 | NETDEV_HW_ADDR_T_MULTICAST, global); | ||
559 | if (!err) | ||
560 | __dev_set_rx_mode(dev); | ||
561 | netif_addr_unlock_bh(dev); | ||
562 | return err; | ||
563 | } | ||
564 | |||
565 | /** | ||
566 | * dev_mc_del - Delete a multicast address. | ||
567 | * @dev: device | ||
568 | * @addr: address to delete | ||
569 | * | ||
570 | * Release reference to a multicast address and remove it | ||
571 | * from the device if the reference count drops to zero. | ||
572 | */ | ||
573 | int dev_mc_del(struct net_device *dev, unsigned char *addr) | ||
574 | { | ||
575 | return __dev_mc_del(dev, addr, false); | ||
576 | } | ||
577 | EXPORT_SYMBOL(dev_mc_del); | ||
578 | |||
579 | /** | ||
580 | * dev_mc_del_global - Delete a global multicast address. | ||
581 | * @dev: device | ||
582 | * @addr: address to delete | ||
583 | * | ||
584 | * Release reference to a multicast address and remove it | ||
585 | * from the device if the reference count drops to zero. | ||
586 | */ | ||
587 | int dev_mc_del_global(struct net_device *dev, unsigned char *addr) | ||
588 | { | ||
589 | return __dev_mc_del(dev, addr, true); | ||
590 | } | ||
591 | EXPORT_SYMBOL(dev_mc_del_global); | ||
592 | |||
593 | /** | ||
594 | * dev_mc_sync - Synchronize device's unicast list to another device | ||
595 | * @to: destination device | ||
596 | * @from: source device | ||
597 | * | ||
598 | * Add newly added addresses to the destination device and release | ||
599 | * addresses that have no users left. The source device must be | ||
600 | * locked by netif_tx_lock_bh. | ||
601 | * | ||
602 | * This function is intended to be called from the dev->set_multicast_list | ||
603 | * or dev->set_rx_mode function of layered software devices. | ||
604 | */ | ||
605 | int dev_mc_sync(struct net_device *to, struct net_device *from) | ||
606 | { | ||
607 | int err = 0; | ||
608 | |||
609 | if (to->addr_len != from->addr_len) | ||
610 | return -EINVAL; | ||
611 | |||
612 | netif_addr_lock_bh(to); | ||
613 | err = __hw_addr_sync(&to->mc, &from->mc, to->addr_len); | ||
614 | if (!err) | ||
615 | __dev_set_rx_mode(to); | ||
616 | netif_addr_unlock_bh(to); | ||
617 | return err; | ||
618 | } | ||
619 | EXPORT_SYMBOL(dev_mc_sync); | ||
620 | |||
621 | /** | ||
622 | * dev_mc_unsync - Remove synchronized addresses from the destination device | ||
623 | * @to: destination device | ||
624 | * @from: source device | ||
625 | * | ||
626 | * Remove all addresses that were added to the destination device by | ||
627 | * dev_mc_sync(). This function is intended to be called from the | ||
628 | * dev->stop function of layered software devices. | ||
629 | */ | ||
630 | void dev_mc_unsync(struct net_device *to, struct net_device *from) | ||
631 | { | ||
632 | if (to->addr_len != from->addr_len) | ||
633 | return; | ||
634 | |||
635 | netif_addr_lock_bh(from); | ||
636 | netif_addr_lock(to); | ||
637 | __hw_addr_unsync(&to->mc, &from->mc, to->addr_len); | ||
638 | __dev_set_rx_mode(to); | ||
639 | netif_addr_unlock(to); | ||
640 | netif_addr_unlock_bh(from); | ||
641 | } | ||
642 | EXPORT_SYMBOL(dev_mc_unsync); | ||
643 | |||
644 | /** | ||
645 | * dev_mc_flush - Flush multicast addresses | ||
646 | * @dev: device | ||
647 | * | ||
648 | * Flush multicast addresses. | ||
649 | */ | ||
650 | void dev_mc_flush(struct net_device *dev) | ||
651 | { | ||
652 | netif_addr_lock_bh(dev); | ||
653 | __hw_addr_flush(&dev->mc); | ||
654 | netif_addr_unlock_bh(dev); | ||
655 | } | ||
656 | EXPORT_SYMBOL(dev_mc_flush); | ||
657 | |||
658 | /** | ||
659 | * dev_mc_flush - Init multicast address list | ||
660 | * @dev: device | ||
661 | * | ||
662 | * Init multicast address list. | ||
663 | */ | ||
664 | void dev_mc_init(struct net_device *dev) | ||
665 | { | ||
666 | __hw_addr_init(&dev->mc); | ||
667 | } | ||
668 | EXPORT_SYMBOL(dev_mc_init); | ||
669 | |||
670 | #ifdef CONFIG_PROC_FS | ||
671 | #include <linux/seq_file.h> | ||
672 | |||
673 | static int dev_mc_seq_show(struct seq_file *seq, void *v) | ||
674 | { | ||
675 | struct netdev_hw_addr *ha; | ||
676 | struct net_device *dev = v; | ||
677 | |||
678 | if (v == SEQ_START_TOKEN) | ||
679 | return 0; | ||
680 | |||
681 | netif_addr_lock_bh(dev); | ||
682 | netdev_for_each_mc_addr(ha, dev) { | ||
683 | int i; | ||
684 | |||
685 | seq_printf(seq, "%-4d %-15s %-5d %-5d ", dev->ifindex, | ||
686 | dev->name, ha->refcount, ha->global_use); | ||
687 | |||
688 | for (i = 0; i < dev->addr_len; i++) | ||
689 | seq_printf(seq, "%02x", ha->addr[i]); | ||
690 | |||
691 | seq_putc(seq, '\n'); | ||
692 | } | ||
693 | netif_addr_unlock_bh(dev); | ||
694 | return 0; | ||
695 | } | ||
696 | |||
697 | static const struct seq_operations dev_mc_seq_ops = { | ||
698 | .start = dev_seq_start, | ||
699 | .next = dev_seq_next, | ||
700 | .stop = dev_seq_stop, | ||
701 | .show = dev_mc_seq_show, | ||
702 | }; | ||
703 | |||
704 | static int dev_mc_seq_open(struct inode *inode, struct file *file) | ||
705 | { | ||
706 | return seq_open_net(inode, file, &dev_mc_seq_ops, | ||
707 | sizeof(struct seq_net_private)); | ||
708 | } | ||
709 | |||
710 | static const struct file_operations dev_mc_seq_fops = { | ||
711 | .owner = THIS_MODULE, | ||
712 | .open = dev_mc_seq_open, | ||
713 | .read = seq_read, | ||
714 | .llseek = seq_lseek, | ||
715 | .release = seq_release_net, | ||
716 | }; | ||
717 | |||
718 | #endif | ||
719 | |||
720 | static int __net_init dev_mc_net_init(struct net *net) | ||
721 | { | ||
722 | if (!proc_net_fops_create(net, "dev_mcast", 0, &dev_mc_seq_fops)) | ||
723 | return -ENOMEM; | ||
724 | return 0; | ||
725 | } | ||
726 | |||
727 | static void __net_exit dev_mc_net_exit(struct net *net) | ||
728 | { | ||
729 | proc_net_remove(net, "dev_mcast"); | ||
730 | } | ||
731 | |||
732 | static struct pernet_operations __net_initdata dev_mc_net_ops = { | ||
733 | .init = dev_mc_net_init, | ||
734 | .exit = dev_mc_net_exit, | ||
735 | }; | ||
736 | |||
737 | void __init dev_mcast_init(void) | ||
738 | { | ||
739 | register_pernet_subsys(&dev_mc_net_ops); | ||
740 | } | ||
741 | |||
diff --git a/net/core/dev_mcast.c b/net/core/dev_mcast.c deleted file mode 100644 index fd91569e2394..000000000000 --- a/net/core/dev_mcast.c +++ /dev/null | |||
@@ -1,231 +0,0 @@ | |||
1 | /* | ||
2 | * Linux NET3: Multicast List maintenance. | ||
3 | * | ||
4 | * Authors: | ||
5 | * Tim Kordas <tjk@nostromo.eeap.cwru.edu> | ||
6 | * Richard Underwood <richard@wuzz.demon.co.uk> | ||
7 | * | ||
8 | * Stir fried together from the IP multicast and CAP patches above | ||
9 | * Alan Cox <alan@lxorguk.ukuu.org.uk> | ||
10 | * | ||
11 | * Fixes: | ||
12 | * Alan Cox : Update the device on a real delete | ||
13 | * rather than any time but... | ||
14 | * Alan Cox : IFF_ALLMULTI support. | ||
15 | * Alan Cox : New format set_multicast_list() calls. | ||
16 | * Gleb Natapov : Remove dev_mc_lock. | ||
17 | * | ||
18 | * This program is free software; you can redistribute it and/or | ||
19 | * modify it under the terms of the GNU General Public License | ||
20 | * as published by the Free Software Foundation; either version | ||
21 | * 2 of the License, or (at your option) any later version. | ||
22 | */ | ||
23 | |||
24 | #include <linux/module.h> | ||
25 | #include <asm/uaccess.h> | ||
26 | #include <asm/system.h> | ||
27 | #include <linux/bitops.h> | ||
28 | #include <linux/types.h> | ||
29 | #include <linux/kernel.h> | ||
30 | #include <linux/string.h> | ||
31 | #include <linux/mm.h> | ||
32 | #include <linux/socket.h> | ||
33 | #include <linux/sockios.h> | ||
34 | #include <linux/in.h> | ||
35 | #include <linux/errno.h> | ||
36 | #include <linux/interrupt.h> | ||
37 | #include <linux/if_ether.h> | ||
38 | #include <linux/inet.h> | ||
39 | #include <linux/netdevice.h> | ||
40 | #include <linux/etherdevice.h> | ||
41 | #include <linux/proc_fs.h> | ||
42 | #include <linux/seq_file.h> | ||
43 | #include <linux/init.h> | ||
44 | #include <net/net_namespace.h> | ||
45 | #include <net/ip.h> | ||
46 | #include <net/route.h> | ||
47 | #include <linux/skbuff.h> | ||
48 | #include <net/sock.h> | ||
49 | #include <net/arp.h> | ||
50 | |||
51 | |||
52 | /* | ||
53 | * Device multicast list maintenance. | ||
54 | * | ||
55 | * This is used both by IP and by the user level maintenance functions. | ||
56 | * Unlike BSD we maintain a usage count on a given multicast address so | ||
57 | * that a casual user application can add/delete multicasts used by | ||
58 | * protocols without doing damage to the protocols when it deletes the | ||
59 | * entries. It also helps IP as it tracks overlapping maps. | ||
60 | * | ||
61 | * Device mc lists are changed by bh at least if IPv6 is enabled, | ||
62 | * so that it must be bh protected. | ||
63 | * | ||
64 | * We block accesses to device mc filters with netif_tx_lock. | ||
65 | */ | ||
66 | |||
67 | /* | ||
68 | * Delete a device level multicast | ||
69 | */ | ||
70 | |||
71 | int dev_mc_delete(struct net_device *dev, void *addr, int alen, int glbl) | ||
72 | { | ||
73 | int err; | ||
74 | |||
75 | netif_addr_lock_bh(dev); | ||
76 | err = __dev_addr_delete(&dev->mc_list, &dev->mc_count, | ||
77 | addr, alen, glbl); | ||
78 | if (!err) { | ||
79 | /* | ||
80 | * We have altered the list, so the card | ||
81 | * loaded filter is now wrong. Fix it | ||
82 | */ | ||
83 | |||
84 | __dev_set_rx_mode(dev); | ||
85 | } | ||
86 | netif_addr_unlock_bh(dev); | ||
87 | return err; | ||
88 | } | ||
89 | |||
90 | /* | ||
91 | * Add a device level multicast | ||
92 | */ | ||
93 | |||
94 | int dev_mc_add(struct net_device *dev, void *addr, int alen, int glbl) | ||
95 | { | ||
96 | int err; | ||
97 | |||
98 | netif_addr_lock_bh(dev); | ||
99 | if (alen != dev->addr_len) | ||
100 | return -EINVAL; | ||
101 | err = __dev_addr_add(&dev->mc_list, &dev->mc_count, addr, alen, glbl); | ||
102 | if (!err) | ||
103 | __dev_set_rx_mode(dev); | ||
104 | netif_addr_unlock_bh(dev); | ||
105 | return err; | ||
106 | } | ||
107 | |||
108 | /** | ||
109 | * dev_mc_sync - Synchronize device's multicast list to another device | ||
110 | * @to: destination device | ||
111 | * @from: source device | ||
112 | * | ||
113 | * Add newly added addresses to the destination device and release | ||
114 | * addresses that have no users left. The source device must be | ||
115 | * locked by netif_tx_lock_bh. | ||
116 | * | ||
117 | * This function is intended to be called from the dev->set_multicast_list | ||
118 | * or dev->set_rx_mode function of layered software devices. | ||
119 | */ | ||
120 | int dev_mc_sync(struct net_device *to, struct net_device *from) | ||
121 | { | ||
122 | int err = 0; | ||
123 | |||
124 | netif_addr_lock_bh(to); | ||
125 | err = __dev_addr_sync(&to->mc_list, &to->mc_count, | ||
126 | &from->mc_list, &from->mc_count); | ||
127 | if (!err) | ||
128 | __dev_set_rx_mode(to); | ||
129 | netif_addr_unlock_bh(to); | ||
130 | |||
131 | return err; | ||
132 | } | ||
133 | EXPORT_SYMBOL(dev_mc_sync); | ||
134 | |||
135 | |||
136 | /** | ||
137 | * dev_mc_unsync - Remove synchronized addresses from the destination | ||
138 | * device | ||
139 | * @to: destination device | ||
140 | * @from: source device | ||
141 | * | ||
142 | * Remove all addresses that were added to the destination device by | ||
143 | * dev_mc_sync(). This function is intended to be called from the | ||
144 | * dev->stop function of layered software devices. | ||
145 | */ | ||
146 | void dev_mc_unsync(struct net_device *to, struct net_device *from) | ||
147 | { | ||
148 | netif_addr_lock_bh(from); | ||
149 | netif_addr_lock(to); | ||
150 | |||
151 | __dev_addr_unsync(&to->mc_list, &to->mc_count, | ||
152 | &from->mc_list, &from->mc_count); | ||
153 | __dev_set_rx_mode(to); | ||
154 | |||
155 | netif_addr_unlock(to); | ||
156 | netif_addr_unlock_bh(from); | ||
157 | } | ||
158 | EXPORT_SYMBOL(dev_mc_unsync); | ||
159 | |||
160 | #ifdef CONFIG_PROC_FS | ||
161 | static int dev_mc_seq_show(struct seq_file *seq, void *v) | ||
162 | { | ||
163 | struct dev_addr_list *m; | ||
164 | struct net_device *dev = v; | ||
165 | |||
166 | if (v == SEQ_START_TOKEN) | ||
167 | return 0; | ||
168 | |||
169 | netif_addr_lock_bh(dev); | ||
170 | for (m = dev->mc_list; m; m = m->next) { | ||
171 | int i; | ||
172 | |||
173 | seq_printf(seq, "%-4d %-15s %-5d %-5d ", dev->ifindex, | ||
174 | dev->name, m->dmi_users, m->dmi_gusers); | ||
175 | |||
176 | for (i = 0; i < m->dmi_addrlen; i++) | ||
177 | seq_printf(seq, "%02x", m->dmi_addr[i]); | ||
178 | |||
179 | seq_putc(seq, '\n'); | ||
180 | } | ||
181 | netif_addr_unlock_bh(dev); | ||
182 | return 0; | ||
183 | } | ||
184 | |||
185 | static const struct seq_operations dev_mc_seq_ops = { | ||
186 | .start = dev_seq_start, | ||
187 | .next = dev_seq_next, | ||
188 | .stop = dev_seq_stop, | ||
189 | .show = dev_mc_seq_show, | ||
190 | }; | ||
191 | |||
192 | static int dev_mc_seq_open(struct inode *inode, struct file *file) | ||
193 | { | ||
194 | return seq_open_net(inode, file, &dev_mc_seq_ops, | ||
195 | sizeof(struct seq_net_private)); | ||
196 | } | ||
197 | |||
198 | static const struct file_operations dev_mc_seq_fops = { | ||
199 | .owner = THIS_MODULE, | ||
200 | .open = dev_mc_seq_open, | ||
201 | .read = seq_read, | ||
202 | .llseek = seq_lseek, | ||
203 | .release = seq_release_net, | ||
204 | }; | ||
205 | |||
206 | #endif | ||
207 | |||
208 | static int __net_init dev_mc_net_init(struct net *net) | ||
209 | { | ||
210 | if (!proc_net_fops_create(net, "dev_mcast", 0, &dev_mc_seq_fops)) | ||
211 | return -ENOMEM; | ||
212 | return 0; | ||
213 | } | ||
214 | |||
215 | static void __net_exit dev_mc_net_exit(struct net *net) | ||
216 | { | ||
217 | proc_net_remove(net, "dev_mcast"); | ||
218 | } | ||
219 | |||
220 | static struct pernet_operations __net_initdata dev_mc_net_ops = { | ||
221 | .init = dev_mc_net_init, | ||
222 | .exit = dev_mc_net_exit, | ||
223 | }; | ||
224 | |||
225 | void __init dev_mcast_init(void) | ||
226 | { | ||
227 | register_pernet_subsys(&dev_mc_net_ops); | ||
228 | } | ||
229 | |||
230 | EXPORT_SYMBOL(dev_mc_add); | ||
231 | EXPORT_SYMBOL(dev_mc_delete); | ||
diff --git a/net/core/drop_monitor.c b/net/core/drop_monitor.c index f8c874975350..cf208d8042b1 100644 --- a/net/core/drop_monitor.c +++ b/net/core/drop_monitor.c | |||
@@ -21,6 +21,7 @@ | |||
21 | #include <linux/percpu.h> | 21 | #include <linux/percpu.h> |
22 | #include <linux/timer.h> | 22 | #include <linux/timer.h> |
23 | #include <linux/bitops.h> | 23 | #include <linux/bitops.h> |
24 | #include <linux/slab.h> | ||
24 | #include <net/genetlink.h> | 25 | #include <net/genetlink.h> |
25 | #include <net/netevent.h> | 26 | #include <net/netevent.h> |
26 | 27 | ||
diff --git a/net/core/dst.c b/net/core/dst.c index cb1b3488b739..9920722cc82b 100644 --- a/net/core/dst.c +++ b/net/core/dst.c | |||
@@ -12,6 +12,7 @@ | |||
12 | #include <linux/workqueue.h> | 12 | #include <linux/workqueue.h> |
13 | #include <linux/mm.h> | 13 | #include <linux/mm.h> |
14 | #include <linux/module.h> | 14 | #include <linux/module.h> |
15 | #include <linux/slab.h> | ||
15 | #include <linux/netdevice.h> | 16 | #include <linux/netdevice.h> |
16 | #include <linux/skbuff.h> | 17 | #include <linux/skbuff.h> |
17 | #include <linux/string.h> | 18 | #include <linux/string.h> |
@@ -43,7 +44,7 @@ static atomic_t dst_total = ATOMIC_INIT(0); | |||
43 | */ | 44 | */ |
44 | static struct { | 45 | static struct { |
45 | spinlock_t lock; | 46 | spinlock_t lock; |
46 | struct dst_entry *list; | 47 | struct dst_entry *list; |
47 | unsigned long timer_inc; | 48 | unsigned long timer_inc; |
48 | unsigned long timer_expires; | 49 | unsigned long timer_expires; |
49 | } dst_garbage = { | 50 | } dst_garbage = { |
@@ -51,7 +52,7 @@ static struct { | |||
51 | .timer_inc = DST_GC_MAX, | 52 | .timer_inc = DST_GC_MAX, |
52 | }; | 53 | }; |
53 | static void dst_gc_task(struct work_struct *work); | 54 | static void dst_gc_task(struct work_struct *work); |
54 | static void ___dst_free(struct dst_entry * dst); | 55 | static void ___dst_free(struct dst_entry *dst); |
55 | 56 | ||
56 | static DECLARE_DELAYED_WORK(dst_gc_work, dst_gc_task); | 57 | static DECLARE_DELAYED_WORK(dst_gc_work, dst_gc_task); |
57 | 58 | ||
@@ -135,8 +136,8 @@ loop: | |||
135 | } | 136 | } |
136 | expires = dst_garbage.timer_expires; | 137 | expires = dst_garbage.timer_expires; |
137 | /* | 138 | /* |
138 | * if the next desired timer is more than 4 seconds in the future | 139 | * if the next desired timer is more than 4 seconds in the |
139 | * then round the timer to whole seconds | 140 | * future then round the timer to whole seconds |
140 | */ | 141 | */ |
141 | if (expires > 4*HZ) | 142 | if (expires > 4*HZ) |
142 | expires = round_jiffies_relative(expires); | 143 | expires = round_jiffies_relative(expires); |
@@ -151,7 +152,8 @@ loop: | |||
151 | " expires: %lu elapsed: %lu us\n", | 152 | " expires: %lu elapsed: %lu us\n", |
152 | atomic_read(&dst_total), delayed, work_performed, | 153 | atomic_read(&dst_total), delayed, work_performed, |
153 | expires, | 154 | expires, |
154 | elapsed.tv_sec * USEC_PER_SEC + elapsed.tv_nsec / NSEC_PER_USEC); | 155 | elapsed.tv_sec * USEC_PER_SEC + |
156 | elapsed.tv_nsec / NSEC_PER_USEC); | ||
155 | #endif | 157 | #endif |
156 | } | 158 | } |
157 | 159 | ||
@@ -162,9 +164,9 @@ int dst_discard(struct sk_buff *skb) | |||
162 | } | 164 | } |
163 | EXPORT_SYMBOL(dst_discard); | 165 | EXPORT_SYMBOL(dst_discard); |
164 | 166 | ||
165 | void * dst_alloc(struct dst_ops * ops) | 167 | void *dst_alloc(struct dst_ops *ops) |
166 | { | 168 | { |
167 | struct dst_entry * dst; | 169 | struct dst_entry *dst; |
168 | 170 | ||
169 | if (ops->gc && atomic_read(&ops->entries) > ops->gc_thresh) { | 171 | if (ops->gc && atomic_read(&ops->entries) > ops->gc_thresh) { |
170 | if (ops->gc(ops)) | 172 | if (ops->gc(ops)) |
@@ -184,19 +186,20 @@ void * dst_alloc(struct dst_ops * ops) | |||
184 | atomic_inc(&ops->entries); | 186 | atomic_inc(&ops->entries); |
185 | return dst; | 187 | return dst; |
186 | } | 188 | } |
189 | EXPORT_SYMBOL(dst_alloc); | ||
187 | 190 | ||
188 | static void ___dst_free(struct dst_entry * dst) | 191 | static void ___dst_free(struct dst_entry *dst) |
189 | { | 192 | { |
190 | /* The first case (dev==NULL) is required, when | 193 | /* The first case (dev==NULL) is required, when |
191 | protocol module is unloaded. | 194 | protocol module is unloaded. |
192 | */ | 195 | */ |
193 | if (dst->dev == NULL || !(dst->dev->flags&IFF_UP)) { | 196 | if (dst->dev == NULL || !(dst->dev->flags&IFF_UP)) |
194 | dst->input = dst->output = dst_discard; | 197 | dst->input = dst->output = dst_discard; |
195 | } | ||
196 | dst->obsolete = 2; | 198 | dst->obsolete = 2; |
197 | } | 199 | } |
200 | EXPORT_SYMBOL(__dst_free); | ||
198 | 201 | ||
199 | void __dst_free(struct dst_entry * dst) | 202 | void __dst_free(struct dst_entry *dst) |
200 | { | 203 | { |
201 | spin_lock_bh(&dst_garbage.lock); | 204 | spin_lock_bh(&dst_garbage.lock); |
202 | ___dst_free(dst); | 205 | ___dst_free(dst); |
@@ -261,15 +264,16 @@ again: | |||
261 | } | 264 | } |
262 | return NULL; | 265 | return NULL; |
263 | } | 266 | } |
267 | EXPORT_SYMBOL(dst_destroy); | ||
264 | 268 | ||
265 | void dst_release(struct dst_entry *dst) | 269 | void dst_release(struct dst_entry *dst) |
266 | { | 270 | { |
267 | if (dst) { | 271 | if (dst) { |
268 | int newrefcnt; | 272 | int newrefcnt; |
269 | 273 | ||
270 | smp_mb__before_atomic_dec(); | 274 | smp_mb__before_atomic_dec(); |
271 | newrefcnt = atomic_dec_return(&dst->__refcnt); | 275 | newrefcnt = atomic_dec_return(&dst->__refcnt); |
272 | WARN_ON(newrefcnt < 0); | 276 | WARN_ON(newrefcnt < 0); |
273 | } | 277 | } |
274 | } | 278 | } |
275 | EXPORT_SYMBOL(dst_release); | 279 | EXPORT_SYMBOL(dst_release); |
@@ -282,8 +286,8 @@ EXPORT_SYMBOL(dst_release); | |||
282 | * | 286 | * |
283 | * Commented and originally written by Alexey. | 287 | * Commented and originally written by Alexey. |
284 | */ | 288 | */ |
285 | static inline void dst_ifdown(struct dst_entry *dst, struct net_device *dev, | 289 | static void dst_ifdown(struct dst_entry *dst, struct net_device *dev, |
286 | int unregister) | 290 | int unregister) |
287 | { | 291 | { |
288 | if (dst->ops->ifdown) | 292 | if (dst->ops->ifdown) |
289 | dst->ops->ifdown(dst, dev, unregister); | 293 | dst->ops->ifdown(dst, dev, unregister); |
@@ -305,7 +309,8 @@ static inline void dst_ifdown(struct dst_entry *dst, struct net_device *dev, | |||
305 | } | 309 | } |
306 | } | 310 | } |
307 | 311 | ||
308 | static int dst_dev_event(struct notifier_block *this, unsigned long event, void *ptr) | 312 | static int dst_dev_event(struct notifier_block *this, unsigned long event, |
313 | void *ptr) | ||
309 | { | 314 | { |
310 | struct net_device *dev = ptr; | 315 | struct net_device *dev = ptr; |
311 | struct dst_entry *dst, *last = NULL; | 316 | struct dst_entry *dst, *last = NULL; |
@@ -328,9 +333,8 @@ static int dst_dev_event(struct notifier_block *this, unsigned long event, void | |||
328 | last->next = dst; | 333 | last->next = dst; |
329 | else | 334 | else |
330 | dst_busy_list = dst; | 335 | dst_busy_list = dst; |
331 | for (; dst; dst = dst->next) { | 336 | for (; dst; dst = dst->next) |
332 | dst_ifdown(dst, dev, event != NETDEV_DOWN); | 337 | dst_ifdown(dst, dev, event != NETDEV_DOWN); |
333 | } | ||
334 | mutex_unlock(&dst_gc_mutex); | 338 | mutex_unlock(&dst_gc_mutex); |
335 | break; | 339 | break; |
336 | } | 340 | } |
@@ -345,7 +349,3 @@ void __init dst_init(void) | |||
345 | { | 349 | { |
346 | register_netdevice_notifier(&dst_dev_notifier); | 350 | register_netdevice_notifier(&dst_dev_notifier); |
347 | } | 351 | } |
348 | |||
349 | EXPORT_SYMBOL(__dst_free); | ||
350 | EXPORT_SYMBOL(dst_alloc); | ||
351 | EXPORT_SYMBOL(dst_destroy); | ||
diff --git a/net/core/ethtool.c b/net/core/ethtool.c index f4cb6b6299d9..1a7db92037fa 100644 --- a/net/core/ethtool.c +++ b/net/core/ethtool.c | |||
@@ -18,7 +18,8 @@ | |||
18 | #include <linux/ethtool.h> | 18 | #include <linux/ethtool.h> |
19 | #include <linux/netdevice.h> | 19 | #include <linux/netdevice.h> |
20 | #include <linux/bitops.h> | 20 | #include <linux/bitops.h> |
21 | #include <asm/uaccess.h> | 21 | #include <linux/uaccess.h> |
22 | #include <linux/slab.h> | ||
22 | 23 | ||
23 | /* | 24 | /* |
24 | * Some useful ethtool_ops methods that're device independent. | 25 | * Some useful ethtool_ops methods that're device independent. |
@@ -30,6 +31,7 @@ u32 ethtool_op_get_link(struct net_device *dev) | |||
30 | { | 31 | { |
31 | return netif_carrier_ok(dev) ? 1 : 0; | 32 | return netif_carrier_ok(dev) ? 1 : 0; |
32 | } | 33 | } |
34 | EXPORT_SYMBOL(ethtool_op_get_link); | ||
33 | 35 | ||
34 | u32 ethtool_op_get_rx_csum(struct net_device *dev) | 36 | u32 ethtool_op_get_rx_csum(struct net_device *dev) |
35 | { | 37 | { |
@@ -62,6 +64,7 @@ int ethtool_op_set_tx_hw_csum(struct net_device *dev, u32 data) | |||
62 | 64 | ||
63 | return 0; | 65 | return 0; |
64 | } | 66 | } |
67 | EXPORT_SYMBOL(ethtool_op_set_tx_hw_csum); | ||
65 | 68 | ||
66 | int ethtool_op_set_tx_ipv6_csum(struct net_device *dev, u32 data) | 69 | int ethtool_op_set_tx_ipv6_csum(struct net_device *dev, u32 data) |
67 | { | 70 | { |
@@ -72,11 +75,13 @@ int ethtool_op_set_tx_ipv6_csum(struct net_device *dev, u32 data) | |||
72 | 75 | ||
73 | return 0; | 76 | return 0; |
74 | } | 77 | } |
78 | EXPORT_SYMBOL(ethtool_op_set_tx_ipv6_csum); | ||
75 | 79 | ||
76 | u32 ethtool_op_get_sg(struct net_device *dev) | 80 | u32 ethtool_op_get_sg(struct net_device *dev) |
77 | { | 81 | { |
78 | return (dev->features & NETIF_F_SG) != 0; | 82 | return (dev->features & NETIF_F_SG) != 0; |
79 | } | 83 | } |
84 | EXPORT_SYMBOL(ethtool_op_get_sg); | ||
80 | 85 | ||
81 | int ethtool_op_set_sg(struct net_device *dev, u32 data) | 86 | int ethtool_op_set_sg(struct net_device *dev, u32 data) |
82 | { | 87 | { |
@@ -87,11 +92,13 @@ int ethtool_op_set_sg(struct net_device *dev, u32 data) | |||
87 | 92 | ||
88 | return 0; | 93 | return 0; |
89 | } | 94 | } |
95 | EXPORT_SYMBOL(ethtool_op_set_sg); | ||
90 | 96 | ||
91 | u32 ethtool_op_get_tso(struct net_device *dev) | 97 | u32 ethtool_op_get_tso(struct net_device *dev) |
92 | { | 98 | { |
93 | return (dev->features & NETIF_F_TSO) != 0; | 99 | return (dev->features & NETIF_F_TSO) != 0; |
94 | } | 100 | } |
101 | EXPORT_SYMBOL(ethtool_op_get_tso); | ||
95 | 102 | ||
96 | int ethtool_op_set_tso(struct net_device *dev, u32 data) | 103 | int ethtool_op_set_tso(struct net_device *dev, u32 data) |
97 | { | 104 | { |
@@ -102,11 +109,13 @@ int ethtool_op_set_tso(struct net_device *dev, u32 data) | |||
102 | 109 | ||
103 | return 0; | 110 | return 0; |
104 | } | 111 | } |
112 | EXPORT_SYMBOL(ethtool_op_set_tso); | ||
105 | 113 | ||
106 | u32 ethtool_op_get_ufo(struct net_device *dev) | 114 | u32 ethtool_op_get_ufo(struct net_device *dev) |
107 | { | 115 | { |
108 | return (dev->features & NETIF_F_UFO) != 0; | 116 | return (dev->features & NETIF_F_UFO) != 0; |
109 | } | 117 | } |
118 | EXPORT_SYMBOL(ethtool_op_get_ufo); | ||
110 | 119 | ||
111 | int ethtool_op_set_ufo(struct net_device *dev, u32 data) | 120 | int ethtool_op_set_ufo(struct net_device *dev, u32 data) |
112 | { | 121 | { |
@@ -116,12 +125,13 @@ int ethtool_op_set_ufo(struct net_device *dev, u32 data) | |||
116 | dev->features &= ~NETIF_F_UFO; | 125 | dev->features &= ~NETIF_F_UFO; |
117 | return 0; | 126 | return 0; |
118 | } | 127 | } |
128 | EXPORT_SYMBOL(ethtool_op_set_ufo); | ||
119 | 129 | ||
120 | /* the following list of flags are the same as their associated | 130 | /* the following list of flags are the same as their associated |
121 | * NETIF_F_xxx values in include/linux/netdevice.h | 131 | * NETIF_F_xxx values in include/linux/netdevice.h |
122 | */ | 132 | */ |
123 | static const u32 flags_dup_features = | 133 | static const u32 flags_dup_features = |
124 | (ETH_FLAG_LRO | ETH_FLAG_NTUPLE); | 134 | (ETH_FLAG_LRO | ETH_FLAG_NTUPLE | ETH_FLAG_RXHASH); |
125 | 135 | ||
126 | u32 ethtool_op_get_flags(struct net_device *dev) | 136 | u32 ethtool_op_get_flags(struct net_device *dev) |
127 | { | 137 | { |
@@ -132,6 +142,7 @@ u32 ethtool_op_get_flags(struct net_device *dev) | |||
132 | 142 | ||
133 | return dev->features & flags_dup_features; | 143 | return dev->features & flags_dup_features; |
134 | } | 144 | } |
145 | EXPORT_SYMBOL(ethtool_op_get_flags); | ||
135 | 146 | ||
136 | int ethtool_op_set_flags(struct net_device *dev, u32 data) | 147 | int ethtool_op_set_flags(struct net_device *dev, u32 data) |
137 | { | 148 | { |
@@ -152,9 +163,15 @@ int ethtool_op_set_flags(struct net_device *dev, u32 data) | |||
152 | features &= ~NETIF_F_NTUPLE; | 163 | features &= ~NETIF_F_NTUPLE; |
153 | } | 164 | } |
154 | 165 | ||
166 | if (data & ETH_FLAG_RXHASH) | ||
167 | features |= NETIF_F_RXHASH; | ||
168 | else | ||
169 | features &= ~NETIF_F_RXHASH; | ||
170 | |||
155 | dev->features = features; | 171 | dev->features = features; |
156 | return 0; | 172 | return 0; |
157 | } | 173 | } |
174 | EXPORT_SYMBOL(ethtool_op_set_flags); | ||
158 | 175 | ||
159 | void ethtool_ntuple_flush(struct net_device *dev) | 176 | void ethtool_ntuple_flush(struct net_device *dev) |
160 | { | 177 | { |
@@ -200,7 +217,8 @@ static int ethtool_set_settings(struct net_device *dev, void __user *useraddr) | |||
200 | return dev->ethtool_ops->set_settings(dev, &cmd); | 217 | return dev->ethtool_ops->set_settings(dev, &cmd); |
201 | } | 218 | } |
202 | 219 | ||
203 | static noinline_for_stack int ethtool_get_drvinfo(struct net_device *dev, void __user *useraddr) | 220 | static noinline_for_stack int ethtool_get_drvinfo(struct net_device *dev, |
221 | void __user *useraddr) | ||
204 | { | 222 | { |
205 | struct ethtool_drvinfo info; | 223 | struct ethtool_drvinfo info; |
206 | const struct ethtool_ops *ops = dev->ethtool_ops; | 224 | const struct ethtool_ops *ops = dev->ethtool_ops; |
@@ -240,7 +258,7 @@ static noinline_for_stack int ethtool_get_drvinfo(struct net_device *dev, void _ | |||
240 | } | 258 | } |
241 | 259 | ||
242 | static noinline_for_stack int ethtool_get_sset_info(struct net_device *dev, | 260 | static noinline_for_stack int ethtool_get_sset_info(struct net_device *dev, |
243 | void __user *useraddr) | 261 | void __user *useraddr) |
244 | { | 262 | { |
245 | struct ethtool_sset_info info; | 263 | struct ethtool_sset_info info; |
246 | const struct ethtool_ops *ops = dev->ethtool_ops; | 264 | const struct ethtool_ops *ops = dev->ethtool_ops; |
@@ -299,7 +317,8 @@ out: | |||
299 | return ret; | 317 | return ret; |
300 | } | 318 | } |
301 | 319 | ||
302 | static noinline_for_stack int ethtool_set_rxnfc(struct net_device *dev, void __user *useraddr) | 320 | static noinline_for_stack int ethtool_set_rxnfc(struct net_device *dev, |
321 | void __user *useraddr) | ||
303 | { | 322 | { |
304 | struct ethtool_rxnfc cmd; | 323 | struct ethtool_rxnfc cmd; |
305 | 324 | ||
@@ -312,7 +331,8 @@ static noinline_for_stack int ethtool_set_rxnfc(struct net_device *dev, void __u | |||
312 | return dev->ethtool_ops->set_rxnfc(dev, &cmd); | 331 | return dev->ethtool_ops->set_rxnfc(dev, &cmd); |
313 | } | 332 | } |
314 | 333 | ||
315 | static noinline_for_stack int ethtool_get_rxnfc(struct net_device *dev, void __user *useraddr) | 334 | static noinline_for_stack int ethtool_get_rxnfc(struct net_device *dev, |
335 | void __user *useraddr) | ||
316 | { | 336 | { |
317 | struct ethtool_rxnfc info; | 337 | struct ethtool_rxnfc info; |
318 | const struct ethtool_ops *ops = dev->ethtool_ops; | 338 | const struct ethtool_ops *ops = dev->ethtool_ops; |
@@ -357,8 +377,8 @@ err_out: | |||
357 | } | 377 | } |
358 | 378 | ||
359 | static void __rx_ntuple_filter_add(struct ethtool_rx_ntuple_list *list, | 379 | static void __rx_ntuple_filter_add(struct ethtool_rx_ntuple_list *list, |
360 | struct ethtool_rx_ntuple_flow_spec *spec, | 380 | struct ethtool_rx_ntuple_flow_spec *spec, |
361 | struct ethtool_rx_ntuple_flow_spec_container *fsc) | 381 | struct ethtool_rx_ntuple_flow_spec_container *fsc) |
362 | { | 382 | { |
363 | 383 | ||
364 | /* don't add filters forever */ | 384 | /* don't add filters forever */ |
@@ -384,7 +404,8 @@ static void __rx_ntuple_filter_add(struct ethtool_rx_ntuple_list *list, | |||
384 | list->count++; | 404 | list->count++; |
385 | } | 405 | } |
386 | 406 | ||
387 | static noinline_for_stack int ethtool_set_rx_ntuple(struct net_device *dev, void __user *useraddr) | 407 | static noinline_for_stack int ethtool_set_rx_ntuple(struct net_device *dev, |
408 | void __user *useraddr) | ||
388 | { | 409 | { |
389 | struct ethtool_rx_ntuple cmd; | 410 | struct ethtool_rx_ntuple cmd; |
390 | const struct ethtool_ops *ops = dev->ethtool_ops; | 411 | const struct ethtool_ops *ops = dev->ethtool_ops; |
@@ -509,125 +530,125 @@ static int ethtool_get_rx_ntuple(struct net_device *dev, void __user *useraddr) | |||
509 | case UDP_V4_FLOW: | 530 | case UDP_V4_FLOW: |
510 | case SCTP_V4_FLOW: | 531 | case SCTP_V4_FLOW: |
511 | sprintf(p, "\tSrc IP addr: 0x%x\n", | 532 | sprintf(p, "\tSrc IP addr: 0x%x\n", |
512 | fsc->fs.h_u.tcp_ip4_spec.ip4src); | 533 | fsc->fs.h_u.tcp_ip4_spec.ip4src); |
513 | p += ETH_GSTRING_LEN; | 534 | p += ETH_GSTRING_LEN; |
514 | num_strings++; | 535 | num_strings++; |
515 | sprintf(p, "\tSrc IP mask: 0x%x\n", | 536 | sprintf(p, "\tSrc IP mask: 0x%x\n", |
516 | fsc->fs.m_u.tcp_ip4_spec.ip4src); | 537 | fsc->fs.m_u.tcp_ip4_spec.ip4src); |
517 | p += ETH_GSTRING_LEN; | 538 | p += ETH_GSTRING_LEN; |
518 | num_strings++; | 539 | num_strings++; |
519 | sprintf(p, "\tDest IP addr: 0x%x\n", | 540 | sprintf(p, "\tDest IP addr: 0x%x\n", |
520 | fsc->fs.h_u.tcp_ip4_spec.ip4dst); | 541 | fsc->fs.h_u.tcp_ip4_spec.ip4dst); |
521 | p += ETH_GSTRING_LEN; | 542 | p += ETH_GSTRING_LEN; |
522 | num_strings++; | 543 | num_strings++; |
523 | sprintf(p, "\tDest IP mask: 0x%x\n", | 544 | sprintf(p, "\tDest IP mask: 0x%x\n", |
524 | fsc->fs.m_u.tcp_ip4_spec.ip4dst); | 545 | fsc->fs.m_u.tcp_ip4_spec.ip4dst); |
525 | p += ETH_GSTRING_LEN; | 546 | p += ETH_GSTRING_LEN; |
526 | num_strings++; | 547 | num_strings++; |
527 | sprintf(p, "\tSrc Port: %d, mask: 0x%x\n", | 548 | sprintf(p, "\tSrc Port: %d, mask: 0x%x\n", |
528 | fsc->fs.h_u.tcp_ip4_spec.psrc, | 549 | fsc->fs.h_u.tcp_ip4_spec.psrc, |
529 | fsc->fs.m_u.tcp_ip4_spec.psrc); | 550 | fsc->fs.m_u.tcp_ip4_spec.psrc); |
530 | p += ETH_GSTRING_LEN; | 551 | p += ETH_GSTRING_LEN; |
531 | num_strings++; | 552 | num_strings++; |
532 | sprintf(p, "\tDest Port: %d, mask: 0x%x\n", | 553 | sprintf(p, "\tDest Port: %d, mask: 0x%x\n", |
533 | fsc->fs.h_u.tcp_ip4_spec.pdst, | 554 | fsc->fs.h_u.tcp_ip4_spec.pdst, |
534 | fsc->fs.m_u.tcp_ip4_spec.pdst); | 555 | fsc->fs.m_u.tcp_ip4_spec.pdst); |
535 | p += ETH_GSTRING_LEN; | 556 | p += ETH_GSTRING_LEN; |
536 | num_strings++; | 557 | num_strings++; |
537 | sprintf(p, "\tTOS: %d, mask: 0x%x\n", | 558 | sprintf(p, "\tTOS: %d, mask: 0x%x\n", |
538 | fsc->fs.h_u.tcp_ip4_spec.tos, | 559 | fsc->fs.h_u.tcp_ip4_spec.tos, |
539 | fsc->fs.m_u.tcp_ip4_spec.tos); | 560 | fsc->fs.m_u.tcp_ip4_spec.tos); |
540 | p += ETH_GSTRING_LEN; | 561 | p += ETH_GSTRING_LEN; |
541 | num_strings++; | 562 | num_strings++; |
542 | break; | 563 | break; |
543 | case AH_ESP_V4_FLOW: | 564 | case AH_ESP_V4_FLOW: |
544 | case ESP_V4_FLOW: | 565 | case ESP_V4_FLOW: |
545 | sprintf(p, "\tSrc IP addr: 0x%x\n", | 566 | sprintf(p, "\tSrc IP addr: 0x%x\n", |
546 | fsc->fs.h_u.ah_ip4_spec.ip4src); | 567 | fsc->fs.h_u.ah_ip4_spec.ip4src); |
547 | p += ETH_GSTRING_LEN; | 568 | p += ETH_GSTRING_LEN; |
548 | num_strings++; | 569 | num_strings++; |
549 | sprintf(p, "\tSrc IP mask: 0x%x\n", | 570 | sprintf(p, "\tSrc IP mask: 0x%x\n", |
550 | fsc->fs.m_u.ah_ip4_spec.ip4src); | 571 | fsc->fs.m_u.ah_ip4_spec.ip4src); |
551 | p += ETH_GSTRING_LEN; | 572 | p += ETH_GSTRING_LEN; |
552 | num_strings++; | 573 | num_strings++; |
553 | sprintf(p, "\tDest IP addr: 0x%x\n", | 574 | sprintf(p, "\tDest IP addr: 0x%x\n", |
554 | fsc->fs.h_u.ah_ip4_spec.ip4dst); | 575 | fsc->fs.h_u.ah_ip4_spec.ip4dst); |
555 | p += ETH_GSTRING_LEN; | 576 | p += ETH_GSTRING_LEN; |
556 | num_strings++; | 577 | num_strings++; |
557 | sprintf(p, "\tDest IP mask: 0x%x\n", | 578 | sprintf(p, "\tDest IP mask: 0x%x\n", |
558 | fsc->fs.m_u.ah_ip4_spec.ip4dst); | 579 | fsc->fs.m_u.ah_ip4_spec.ip4dst); |
559 | p += ETH_GSTRING_LEN; | 580 | p += ETH_GSTRING_LEN; |
560 | num_strings++; | 581 | num_strings++; |
561 | sprintf(p, "\tSPI: %d, mask: 0x%x\n", | 582 | sprintf(p, "\tSPI: %d, mask: 0x%x\n", |
562 | fsc->fs.h_u.ah_ip4_spec.spi, | 583 | fsc->fs.h_u.ah_ip4_spec.spi, |
563 | fsc->fs.m_u.ah_ip4_spec.spi); | 584 | fsc->fs.m_u.ah_ip4_spec.spi); |
564 | p += ETH_GSTRING_LEN; | 585 | p += ETH_GSTRING_LEN; |
565 | num_strings++; | 586 | num_strings++; |
566 | sprintf(p, "\tTOS: %d, mask: 0x%x\n", | 587 | sprintf(p, "\tTOS: %d, mask: 0x%x\n", |
567 | fsc->fs.h_u.ah_ip4_spec.tos, | 588 | fsc->fs.h_u.ah_ip4_spec.tos, |
568 | fsc->fs.m_u.ah_ip4_spec.tos); | 589 | fsc->fs.m_u.ah_ip4_spec.tos); |
569 | p += ETH_GSTRING_LEN; | 590 | p += ETH_GSTRING_LEN; |
570 | num_strings++; | 591 | num_strings++; |
571 | break; | 592 | break; |
572 | case IP_USER_FLOW: | 593 | case IP_USER_FLOW: |
573 | sprintf(p, "\tSrc IP addr: 0x%x\n", | 594 | sprintf(p, "\tSrc IP addr: 0x%x\n", |
574 | fsc->fs.h_u.raw_ip4_spec.ip4src); | 595 | fsc->fs.h_u.raw_ip4_spec.ip4src); |
575 | p += ETH_GSTRING_LEN; | 596 | p += ETH_GSTRING_LEN; |
576 | num_strings++; | 597 | num_strings++; |
577 | sprintf(p, "\tSrc IP mask: 0x%x\n", | 598 | sprintf(p, "\tSrc IP mask: 0x%x\n", |
578 | fsc->fs.m_u.raw_ip4_spec.ip4src); | 599 | fsc->fs.m_u.raw_ip4_spec.ip4src); |
579 | p += ETH_GSTRING_LEN; | 600 | p += ETH_GSTRING_LEN; |
580 | num_strings++; | 601 | num_strings++; |
581 | sprintf(p, "\tDest IP addr: 0x%x\n", | 602 | sprintf(p, "\tDest IP addr: 0x%x\n", |
582 | fsc->fs.h_u.raw_ip4_spec.ip4dst); | 603 | fsc->fs.h_u.raw_ip4_spec.ip4dst); |
583 | p += ETH_GSTRING_LEN; | 604 | p += ETH_GSTRING_LEN; |
584 | num_strings++; | 605 | num_strings++; |
585 | sprintf(p, "\tDest IP mask: 0x%x\n", | 606 | sprintf(p, "\tDest IP mask: 0x%x\n", |
586 | fsc->fs.m_u.raw_ip4_spec.ip4dst); | 607 | fsc->fs.m_u.raw_ip4_spec.ip4dst); |
587 | p += ETH_GSTRING_LEN; | 608 | p += ETH_GSTRING_LEN; |
588 | num_strings++; | 609 | num_strings++; |
589 | break; | 610 | break; |
590 | case IPV4_FLOW: | 611 | case IPV4_FLOW: |
591 | sprintf(p, "\tSrc IP addr: 0x%x\n", | 612 | sprintf(p, "\tSrc IP addr: 0x%x\n", |
592 | fsc->fs.h_u.usr_ip4_spec.ip4src); | 613 | fsc->fs.h_u.usr_ip4_spec.ip4src); |
593 | p += ETH_GSTRING_LEN; | 614 | p += ETH_GSTRING_LEN; |
594 | num_strings++; | 615 | num_strings++; |
595 | sprintf(p, "\tSrc IP mask: 0x%x\n", | 616 | sprintf(p, "\tSrc IP mask: 0x%x\n", |
596 | fsc->fs.m_u.usr_ip4_spec.ip4src); | 617 | fsc->fs.m_u.usr_ip4_spec.ip4src); |
597 | p += ETH_GSTRING_LEN; | 618 | p += ETH_GSTRING_LEN; |
598 | num_strings++; | 619 | num_strings++; |
599 | sprintf(p, "\tDest IP addr: 0x%x\n", | 620 | sprintf(p, "\tDest IP addr: 0x%x\n", |
600 | fsc->fs.h_u.usr_ip4_spec.ip4dst); | 621 | fsc->fs.h_u.usr_ip4_spec.ip4dst); |
601 | p += ETH_GSTRING_LEN; | 622 | p += ETH_GSTRING_LEN; |
602 | num_strings++; | 623 | num_strings++; |
603 | sprintf(p, "\tDest IP mask: 0x%x\n", | 624 | sprintf(p, "\tDest IP mask: 0x%x\n", |
604 | fsc->fs.m_u.usr_ip4_spec.ip4dst); | 625 | fsc->fs.m_u.usr_ip4_spec.ip4dst); |
605 | p += ETH_GSTRING_LEN; | 626 | p += ETH_GSTRING_LEN; |
606 | num_strings++; | 627 | num_strings++; |
607 | sprintf(p, "\tL4 bytes: 0x%x, mask: 0x%x\n", | 628 | sprintf(p, "\tL4 bytes: 0x%x, mask: 0x%x\n", |
608 | fsc->fs.h_u.usr_ip4_spec.l4_4_bytes, | 629 | fsc->fs.h_u.usr_ip4_spec.l4_4_bytes, |
609 | fsc->fs.m_u.usr_ip4_spec.l4_4_bytes); | 630 | fsc->fs.m_u.usr_ip4_spec.l4_4_bytes); |
610 | p += ETH_GSTRING_LEN; | 631 | p += ETH_GSTRING_LEN; |
611 | num_strings++; | 632 | num_strings++; |
612 | sprintf(p, "\tTOS: %d, mask: 0x%x\n", | 633 | sprintf(p, "\tTOS: %d, mask: 0x%x\n", |
613 | fsc->fs.h_u.usr_ip4_spec.tos, | 634 | fsc->fs.h_u.usr_ip4_spec.tos, |
614 | fsc->fs.m_u.usr_ip4_spec.tos); | 635 | fsc->fs.m_u.usr_ip4_spec.tos); |
615 | p += ETH_GSTRING_LEN; | 636 | p += ETH_GSTRING_LEN; |
616 | num_strings++; | 637 | num_strings++; |
617 | sprintf(p, "\tIP Version: %d, mask: 0x%x\n", | 638 | sprintf(p, "\tIP Version: %d, mask: 0x%x\n", |
618 | fsc->fs.h_u.usr_ip4_spec.ip_ver, | 639 | fsc->fs.h_u.usr_ip4_spec.ip_ver, |
619 | fsc->fs.m_u.usr_ip4_spec.ip_ver); | 640 | fsc->fs.m_u.usr_ip4_spec.ip_ver); |
620 | p += ETH_GSTRING_LEN; | 641 | p += ETH_GSTRING_LEN; |
621 | num_strings++; | 642 | num_strings++; |
622 | sprintf(p, "\tProtocol: %d, mask: 0x%x\n", | 643 | sprintf(p, "\tProtocol: %d, mask: 0x%x\n", |
623 | fsc->fs.h_u.usr_ip4_spec.proto, | 644 | fsc->fs.h_u.usr_ip4_spec.proto, |
624 | fsc->fs.m_u.usr_ip4_spec.proto); | 645 | fsc->fs.m_u.usr_ip4_spec.proto); |
625 | p += ETH_GSTRING_LEN; | 646 | p += ETH_GSTRING_LEN; |
626 | num_strings++; | 647 | num_strings++; |
627 | break; | 648 | break; |
628 | }; | 649 | }; |
629 | sprintf(p, "\tVLAN: %d, mask: 0x%x\n", | 650 | sprintf(p, "\tVLAN: %d, mask: 0x%x\n", |
630 | fsc->fs.vlan_tag, fsc->fs.vlan_tag_mask); | 651 | fsc->fs.vlan_tag, fsc->fs.vlan_tag_mask); |
631 | p += ETH_GSTRING_LEN; | 652 | p += ETH_GSTRING_LEN; |
632 | num_strings++; | 653 | num_strings++; |
633 | sprintf(p, "\tUser-defined: 0x%Lx\n", fsc->fs.data); | 654 | sprintf(p, "\tUser-defined: 0x%Lx\n", fsc->fs.data); |
@@ -640,7 +661,7 @@ static int ethtool_get_rx_ntuple(struct net_device *dev, void __user *useraddr) | |||
640 | sprintf(p, "\tAction: Drop\n"); | 661 | sprintf(p, "\tAction: Drop\n"); |
641 | else | 662 | else |
642 | sprintf(p, "\tAction: Direct to queue %d\n", | 663 | sprintf(p, "\tAction: Direct to queue %d\n", |
643 | fsc->fs.action); | 664 | fsc->fs.action); |
644 | p += ETH_GSTRING_LEN; | 665 | p += ETH_GSTRING_LEN; |
645 | num_strings++; | 666 | num_strings++; |
646 | unknown_filter: | 667 | unknown_filter: |
@@ -852,7 +873,8 @@ static int ethtool_set_eeprom(struct net_device *dev, void __user *useraddr) | |||
852 | return ret; | 873 | return ret; |
853 | } | 874 | } |
854 | 875 | ||
855 | static noinline_for_stack int ethtool_get_coalesce(struct net_device *dev, void __user *useraddr) | 876 | static noinline_for_stack int ethtool_get_coalesce(struct net_device *dev, |
877 | void __user *useraddr) | ||
856 | { | 878 | { |
857 | struct ethtool_coalesce coalesce = { .cmd = ETHTOOL_GCOALESCE }; | 879 | struct ethtool_coalesce coalesce = { .cmd = ETHTOOL_GCOALESCE }; |
858 | 880 | ||
@@ -866,7 +888,8 @@ static noinline_for_stack int ethtool_get_coalesce(struct net_device *dev, void | |||
866 | return 0; | 888 | return 0; |
867 | } | 889 | } |
868 | 890 | ||
869 | static noinline_for_stack int ethtool_set_coalesce(struct net_device *dev, void __user *useraddr) | 891 | static noinline_for_stack int ethtool_set_coalesce(struct net_device *dev, |
892 | void __user *useraddr) | ||
870 | { | 893 | { |
871 | struct ethtool_coalesce coalesce; | 894 | struct ethtool_coalesce coalesce; |
872 | 895 | ||
@@ -970,6 +993,7 @@ static int ethtool_set_tx_csum(struct net_device *dev, char __user *useraddr) | |||
970 | 993 | ||
971 | return dev->ethtool_ops->set_tx_csum(dev, edata.data); | 994 | return dev->ethtool_ops->set_tx_csum(dev, edata.data); |
972 | } | 995 | } |
996 | EXPORT_SYMBOL(ethtool_op_set_tx_csum); | ||
973 | 997 | ||
974 | static int ethtool_set_rx_csum(struct net_device *dev, char __user *useraddr) | 998 | static int ethtool_set_rx_csum(struct net_device *dev, char __user *useraddr) |
975 | { | 999 | { |
@@ -1041,7 +1065,7 @@ static int ethtool_get_gso(struct net_device *dev, char __user *useraddr) | |||
1041 | 1065 | ||
1042 | edata.data = dev->features & NETIF_F_GSO; | 1066 | edata.data = dev->features & NETIF_F_GSO; |
1043 | if (copy_to_user(useraddr, &edata, sizeof(edata))) | 1067 | if (copy_to_user(useraddr, &edata, sizeof(edata))) |
1044 | return -EFAULT; | 1068 | return -EFAULT; |
1045 | return 0; | 1069 | return 0; |
1046 | } | 1070 | } |
1047 | 1071 | ||
@@ -1064,7 +1088,7 @@ static int ethtool_get_gro(struct net_device *dev, char __user *useraddr) | |||
1064 | 1088 | ||
1065 | edata.data = dev->features & NETIF_F_GRO; | 1089 | edata.data = dev->features & NETIF_F_GRO; |
1066 | if (copy_to_user(useraddr, &edata, sizeof(edata))) | 1090 | if (copy_to_user(useraddr, &edata, sizeof(edata))) |
1067 | return -EFAULT; | 1091 | return -EFAULT; |
1068 | return 0; | 1092 | return 0; |
1069 | } | 1093 | } |
1070 | 1094 | ||
@@ -1276,7 +1300,8 @@ static int ethtool_set_value(struct net_device *dev, char __user *useraddr, | |||
1276 | return actor(dev, edata.data); | 1300 | return actor(dev, edata.data); |
1277 | } | 1301 | } |
1278 | 1302 | ||
1279 | static noinline_for_stack int ethtool_flash_device(struct net_device *dev, char __user *useraddr) | 1303 | static noinline_for_stack int ethtool_flash_device(struct net_device *dev, |
1304 | char __user *useraddr) | ||
1280 | { | 1305 | { |
1281 | struct ethtool_flash efl; | 1306 | struct ethtool_flash efl; |
1282 | 1307 | ||
@@ -1305,11 +1330,11 @@ int dev_ethtool(struct net *net, struct ifreq *ifr) | |||
1305 | if (!dev->ethtool_ops) | 1330 | if (!dev->ethtool_ops) |
1306 | return -EOPNOTSUPP; | 1331 | return -EOPNOTSUPP; |
1307 | 1332 | ||
1308 | if (copy_from_user(ðcmd, useraddr, sizeof (ethcmd))) | 1333 | if (copy_from_user(ðcmd, useraddr, sizeof(ethcmd))) |
1309 | return -EFAULT; | 1334 | return -EFAULT; |
1310 | 1335 | ||
1311 | /* Allow some commands to be done by anyone */ | 1336 | /* Allow some commands to be done by anyone */ |
1312 | switch(ethcmd) { | 1337 | switch (ethcmd) { |
1313 | case ETHTOOL_GDRVINFO: | 1338 | case ETHTOOL_GDRVINFO: |
1314 | case ETHTOOL_GMSGLVL: | 1339 | case ETHTOOL_GMSGLVL: |
1315 | case ETHTOOL_GCOALESCE: | 1340 | case ETHTOOL_GCOALESCE: |
@@ -1337,10 +1362,11 @@ int dev_ethtool(struct net *net, struct ifreq *ifr) | |||
1337 | return -EPERM; | 1362 | return -EPERM; |
1338 | } | 1363 | } |
1339 | 1364 | ||
1340 | if (dev->ethtool_ops->begin) | 1365 | if (dev->ethtool_ops->begin) { |
1341 | if ((rc = dev->ethtool_ops->begin(dev)) < 0) | 1366 | rc = dev->ethtool_ops->begin(dev); |
1367 | if (rc < 0) | ||
1342 | return rc; | 1368 | return rc; |
1343 | 1369 | } | |
1344 | old_features = dev->features; | 1370 | old_features = dev->features; |
1345 | 1371 | ||
1346 | switch (ethcmd) { | 1372 | switch (ethcmd) { |
@@ -1530,16 +1556,3 @@ int dev_ethtool(struct net *net, struct ifreq *ifr) | |||
1530 | 1556 | ||
1531 | return rc; | 1557 | return rc; |
1532 | } | 1558 | } |
1533 | |||
1534 | EXPORT_SYMBOL(ethtool_op_get_link); | ||
1535 | EXPORT_SYMBOL(ethtool_op_get_sg); | ||
1536 | EXPORT_SYMBOL(ethtool_op_get_tso); | ||
1537 | EXPORT_SYMBOL(ethtool_op_set_sg); | ||
1538 | EXPORT_SYMBOL(ethtool_op_set_tso); | ||
1539 | EXPORT_SYMBOL(ethtool_op_set_tx_csum); | ||
1540 | EXPORT_SYMBOL(ethtool_op_set_tx_hw_csum); | ||
1541 | EXPORT_SYMBOL(ethtool_op_set_tx_ipv6_csum); | ||
1542 | EXPORT_SYMBOL(ethtool_op_set_ufo); | ||
1543 | EXPORT_SYMBOL(ethtool_op_get_ufo); | ||
1544 | EXPORT_SYMBOL(ethtool_op_set_flags); | ||
1545 | EXPORT_SYMBOL(ethtool_op_get_flags); | ||
diff --git a/net/core/fib_rules.c b/net/core/fib_rules.c index 9a24377146bf..1bc66592453c 100644 --- a/net/core/fib_rules.c +++ b/net/core/fib_rules.c | |||
@@ -10,6 +10,7 @@ | |||
10 | 10 | ||
11 | #include <linux/types.h> | 11 | #include <linux/types.h> |
12 | #include <linux/kernel.h> | 12 | #include <linux/kernel.h> |
13 | #include <linux/slab.h> | ||
13 | #include <linux/list.h> | 14 | #include <linux/list.h> |
14 | #include <net/net_namespace.h> | 15 | #include <net/net_namespace.h> |
15 | #include <net/sock.h> | 16 | #include <net/sock.h> |
@@ -38,6 +39,24 @@ int fib_default_rule_add(struct fib_rules_ops *ops, | |||
38 | } | 39 | } |
39 | EXPORT_SYMBOL(fib_default_rule_add); | 40 | EXPORT_SYMBOL(fib_default_rule_add); |
40 | 41 | ||
42 | u32 fib_default_rule_pref(struct fib_rules_ops *ops) | ||
43 | { | ||
44 | struct list_head *pos; | ||
45 | struct fib_rule *rule; | ||
46 | |||
47 | if (!list_empty(&ops->rules_list)) { | ||
48 | pos = ops->rules_list.next; | ||
49 | if (pos->next != &ops->rules_list) { | ||
50 | rule = list_entry(pos->next, struct fib_rule, list); | ||
51 | if (rule->pref) | ||
52 | return rule->pref - 1; | ||
53 | } | ||
54 | } | ||
55 | |||
56 | return 0; | ||
57 | } | ||
58 | EXPORT_SYMBOL(fib_default_rule_pref); | ||
59 | |||
41 | static void notify_rule_change(int event, struct fib_rule *rule, | 60 | static void notify_rule_change(int event, struct fib_rule *rule, |
42 | struct fib_rules_ops *ops, struct nlmsghdr *nlh, | 61 | struct fib_rules_ops *ops, struct nlmsghdr *nlh, |
43 | u32 pid); | 62 | u32 pid); |
@@ -108,7 +127,7 @@ fib_rules_register(struct fib_rules_ops *tmpl, struct net *net) | |||
108 | struct fib_rules_ops *ops; | 127 | struct fib_rules_ops *ops; |
109 | int err; | 128 | int err; |
110 | 129 | ||
111 | ops = kmemdup(tmpl, sizeof (*ops), GFP_KERNEL); | 130 | ops = kmemdup(tmpl, sizeof(*ops), GFP_KERNEL); |
112 | if (ops == NULL) | 131 | if (ops == NULL) |
113 | return ERR_PTR(-ENOMEM); | 132 | return ERR_PTR(-ENOMEM); |
114 | 133 | ||
@@ -123,7 +142,6 @@ fib_rules_register(struct fib_rules_ops *tmpl, struct net *net) | |||
123 | 142 | ||
124 | return ops; | 143 | return ops; |
125 | } | 144 | } |
126 | |||
127 | EXPORT_SYMBOL_GPL(fib_rules_register); | 145 | EXPORT_SYMBOL_GPL(fib_rules_register); |
128 | 146 | ||
129 | void fib_rules_cleanup_ops(struct fib_rules_ops *ops) | 147 | void fib_rules_cleanup_ops(struct fib_rules_ops *ops) |
@@ -157,7 +175,6 @@ void fib_rules_unregister(struct fib_rules_ops *ops) | |||
157 | 175 | ||
158 | call_rcu(&ops->rcu, fib_rules_put_rcu); | 176 | call_rcu(&ops->rcu, fib_rules_put_rcu); |
159 | } | 177 | } |
160 | |||
161 | EXPORT_SYMBOL_GPL(fib_rules_unregister); | 178 | EXPORT_SYMBOL_GPL(fib_rules_unregister); |
162 | 179 | ||
163 | static int fib_rule_match(struct fib_rule *rule, struct fib_rules_ops *ops, | 180 | static int fib_rule_match(struct fib_rule *rule, struct fib_rules_ops *ops, |
@@ -220,7 +237,6 @@ out: | |||
220 | 237 | ||
221 | return err; | 238 | return err; |
222 | } | 239 | } |
223 | |||
224 | EXPORT_SYMBOL_GPL(fib_rules_lookup); | 240 | EXPORT_SYMBOL_GPL(fib_rules_lookup); |
225 | 241 | ||
226 | static int validate_rulemsg(struct fib_rule_hdr *frh, struct nlattr **tb, | 242 | static int validate_rulemsg(struct fib_rule_hdr *frh, struct nlattr **tb, |
@@ -519,6 +535,7 @@ static int fib_nl_fill_rule(struct sk_buff *skb, struct fib_rule *rule, | |||
519 | return -EMSGSIZE; | 535 | return -EMSGSIZE; |
520 | 536 | ||
521 | frh = nlmsg_data(nlh); | 537 | frh = nlmsg_data(nlh); |
538 | frh->family = ops->family; | ||
522 | frh->table = rule->table; | 539 | frh->table = rule->table; |
523 | NLA_PUT_U32(skb, FRA_TABLE, rule->table); | 540 | NLA_PUT_U32(skb, FRA_TABLE, rule->table); |
524 | frh->res1 = 0; | 541 | frh->res1 = 0; |
@@ -613,7 +630,7 @@ static int fib_nl_dumprule(struct sk_buff *skb, struct netlink_callback *cb) | |||
613 | break; | 630 | break; |
614 | 631 | ||
615 | cb->args[1] = 0; | 632 | cb->args[1] = 0; |
616 | skip: | 633 | skip: |
617 | idx++; | 634 | idx++; |
618 | } | 635 | } |
619 | rcu_read_unlock(); | 636 | rcu_read_unlock(); |
@@ -685,7 +702,6 @@ static int fib_rules_event(struct notifier_block *this, unsigned long event, | |||
685 | struct fib_rules_ops *ops; | 702 | struct fib_rules_ops *ops; |
686 | 703 | ||
687 | ASSERT_RTNL(); | 704 | ASSERT_RTNL(); |
688 | rcu_read_lock(); | ||
689 | 705 | ||
690 | switch (event) { | 706 | switch (event) { |
691 | case NETDEV_REGISTER: | 707 | case NETDEV_REGISTER: |
@@ -699,8 +715,6 @@ static int fib_rules_event(struct notifier_block *this, unsigned long event, | |||
699 | break; | 715 | break; |
700 | } | 716 | } |
701 | 717 | ||
702 | rcu_read_unlock(); | ||
703 | |||
704 | return NOTIFY_DONE; | 718 | return NOTIFY_DONE; |
705 | } | 719 | } |
706 | 720 | ||
diff --git a/net/core/filter.c b/net/core/filter.c index d38ef7fd50f0..ff943bed21af 100644 --- a/net/core/filter.c +++ b/net/core/filter.c | |||
@@ -25,6 +25,7 @@ | |||
25 | #include <linux/inet.h> | 25 | #include <linux/inet.h> |
26 | #include <linux/netdevice.h> | 26 | #include <linux/netdevice.h> |
27 | #include <linux/if_packet.h> | 27 | #include <linux/if_packet.h> |
28 | #include <linux/gfp.h> | ||
28 | #include <net/ip.h> | 29 | #include <net/ip.h> |
29 | #include <net/protocol.h> | 30 | #include <net/protocol.h> |
30 | #include <net/netlink.h> | 31 | #include <net/netlink.h> |
diff --git a/net/core/flow.c b/net/core/flow.c index 96015871ecea..161900674009 100644 --- a/net/core/flow.c +++ b/net/core/flow.c | |||
@@ -26,113 +26,158 @@ | |||
26 | #include <linux/security.h> | 26 | #include <linux/security.h> |
27 | 27 | ||
28 | struct flow_cache_entry { | 28 | struct flow_cache_entry { |
29 | struct flow_cache_entry *next; | 29 | union { |
30 | u16 family; | 30 | struct hlist_node hlist; |
31 | u8 dir; | 31 | struct list_head gc_list; |
32 | u32 genid; | 32 | } u; |
33 | struct flowi key; | 33 | u16 family; |
34 | void *object; | 34 | u8 dir; |
35 | atomic_t *object_ref; | 35 | u32 genid; |
36 | struct flowi key; | ||
37 | struct flow_cache_object *object; | ||
36 | }; | 38 | }; |
37 | 39 | ||
38 | atomic_t flow_cache_genid = ATOMIC_INIT(0); | 40 | struct flow_cache_percpu { |
39 | 41 | struct hlist_head *hash_table; | |
40 | static u32 flow_hash_shift; | 42 | int hash_count; |
41 | #define flow_hash_size (1 << flow_hash_shift) | 43 | u32 hash_rnd; |
42 | static DEFINE_PER_CPU(struct flow_cache_entry **, flow_tables) = { NULL }; | 44 | int hash_rnd_recalc; |
43 | 45 | struct tasklet_struct flush_tasklet; | |
44 | #define flow_table(cpu) (per_cpu(flow_tables, cpu)) | 46 | }; |
45 | |||
46 | static struct kmem_cache *flow_cachep __read_mostly; | ||
47 | 47 | ||
48 | static int flow_lwm, flow_hwm; | 48 | struct flow_flush_info { |
49 | struct flow_cache *cache; | ||
50 | atomic_t cpuleft; | ||
51 | struct completion completion; | ||
52 | }; | ||
49 | 53 | ||
50 | struct flow_percpu_info { | 54 | struct flow_cache { |
51 | int hash_rnd_recalc; | 55 | u32 hash_shift; |
52 | u32 hash_rnd; | 56 | unsigned long order; |
53 | int count; | 57 | struct flow_cache_percpu *percpu; |
58 | struct notifier_block hotcpu_notifier; | ||
59 | int low_watermark; | ||
60 | int high_watermark; | ||
61 | struct timer_list rnd_timer; | ||
54 | }; | 62 | }; |
55 | static DEFINE_PER_CPU(struct flow_percpu_info, flow_hash_info) = { 0 }; | ||
56 | 63 | ||
57 | #define flow_hash_rnd_recalc(cpu) \ | 64 | atomic_t flow_cache_genid = ATOMIC_INIT(0); |
58 | (per_cpu(flow_hash_info, cpu).hash_rnd_recalc) | 65 | static struct flow_cache flow_cache_global; |
59 | #define flow_hash_rnd(cpu) \ | 66 | static struct kmem_cache *flow_cachep; |
60 | (per_cpu(flow_hash_info, cpu).hash_rnd) | ||
61 | #define flow_count(cpu) \ | ||
62 | (per_cpu(flow_hash_info, cpu).count) | ||
63 | 67 | ||
64 | static struct timer_list flow_hash_rnd_timer; | 68 | static DEFINE_SPINLOCK(flow_cache_gc_lock); |
69 | static LIST_HEAD(flow_cache_gc_list); | ||
65 | 70 | ||
66 | #define FLOW_HASH_RND_PERIOD (10 * 60 * HZ) | 71 | #define flow_cache_hash_size(cache) (1 << (cache)->hash_shift) |
67 | 72 | #define FLOW_HASH_RND_PERIOD (10 * 60 * HZ) | |
68 | struct flow_flush_info { | ||
69 | atomic_t cpuleft; | ||
70 | struct completion completion; | ||
71 | }; | ||
72 | static DEFINE_PER_CPU(struct tasklet_struct, flow_flush_tasklets) = { NULL }; | ||
73 | |||
74 | #define flow_flush_tasklet(cpu) (&per_cpu(flow_flush_tasklets, cpu)) | ||
75 | 73 | ||
76 | static void flow_cache_new_hashrnd(unsigned long arg) | 74 | static void flow_cache_new_hashrnd(unsigned long arg) |
77 | { | 75 | { |
76 | struct flow_cache *fc = (void *) arg; | ||
78 | int i; | 77 | int i; |
79 | 78 | ||
80 | for_each_possible_cpu(i) | 79 | for_each_possible_cpu(i) |
81 | flow_hash_rnd_recalc(i) = 1; | 80 | per_cpu_ptr(fc->percpu, i)->hash_rnd_recalc = 1; |
82 | 81 | ||
83 | flow_hash_rnd_timer.expires = jiffies + FLOW_HASH_RND_PERIOD; | 82 | fc->rnd_timer.expires = jiffies + FLOW_HASH_RND_PERIOD; |
84 | add_timer(&flow_hash_rnd_timer); | 83 | add_timer(&fc->rnd_timer); |
84 | } | ||
85 | |||
86 | static int flow_entry_valid(struct flow_cache_entry *fle) | ||
87 | { | ||
88 | if (atomic_read(&flow_cache_genid) != fle->genid) | ||
89 | return 0; | ||
90 | if (fle->object && !fle->object->ops->check(fle->object)) | ||
91 | return 0; | ||
92 | return 1; | ||
85 | } | 93 | } |
86 | 94 | ||
87 | static void flow_entry_kill(int cpu, struct flow_cache_entry *fle) | 95 | static void flow_entry_kill(struct flow_cache_entry *fle) |
88 | { | 96 | { |
89 | if (fle->object) | 97 | if (fle->object) |
90 | atomic_dec(fle->object_ref); | 98 | fle->object->ops->delete(fle->object); |
91 | kmem_cache_free(flow_cachep, fle); | 99 | kmem_cache_free(flow_cachep, fle); |
92 | flow_count(cpu)--; | ||
93 | } | 100 | } |
94 | 101 | ||
95 | static void __flow_cache_shrink(int cpu, int shrink_to) | 102 | static void flow_cache_gc_task(struct work_struct *work) |
96 | { | 103 | { |
97 | struct flow_cache_entry *fle, **flp; | 104 | struct list_head gc_list; |
98 | int i; | 105 | struct flow_cache_entry *fce, *n; |
99 | 106 | ||
100 | for (i = 0; i < flow_hash_size; i++) { | 107 | INIT_LIST_HEAD(&gc_list); |
101 | int k = 0; | 108 | spin_lock_bh(&flow_cache_gc_lock); |
109 | list_splice_tail_init(&flow_cache_gc_list, &gc_list); | ||
110 | spin_unlock_bh(&flow_cache_gc_lock); | ||
102 | 111 | ||
103 | flp = &flow_table(cpu)[i]; | 112 | list_for_each_entry_safe(fce, n, &gc_list, u.gc_list) |
104 | while ((fle = *flp) != NULL && k < shrink_to) { | 113 | flow_entry_kill(fce); |
105 | k++; | 114 | } |
106 | flp = &fle->next; | 115 | static DECLARE_WORK(flow_cache_gc_work, flow_cache_gc_task); |
107 | } | 116 | |
108 | while ((fle = *flp) != NULL) { | 117 | static void flow_cache_queue_garbage(struct flow_cache_percpu *fcp, |
109 | *flp = fle->next; | 118 | int deleted, struct list_head *gc_list) |
110 | flow_entry_kill(cpu, fle); | 119 | { |
111 | } | 120 | if (deleted) { |
121 | fcp->hash_count -= deleted; | ||
122 | spin_lock_bh(&flow_cache_gc_lock); | ||
123 | list_splice_tail(gc_list, &flow_cache_gc_list); | ||
124 | spin_unlock_bh(&flow_cache_gc_lock); | ||
125 | schedule_work(&flow_cache_gc_work); | ||
112 | } | 126 | } |
113 | } | 127 | } |
114 | 128 | ||
115 | static void flow_cache_shrink(int cpu) | 129 | static void __flow_cache_shrink(struct flow_cache *fc, |
130 | struct flow_cache_percpu *fcp, | ||
131 | int shrink_to) | ||
116 | { | 132 | { |
117 | int shrink_to = flow_lwm / flow_hash_size; | 133 | struct flow_cache_entry *fle; |
134 | struct hlist_node *entry, *tmp; | ||
135 | LIST_HEAD(gc_list); | ||
136 | int i, deleted = 0; | ||
137 | |||
138 | for (i = 0; i < flow_cache_hash_size(fc); i++) { | ||
139 | int saved = 0; | ||
140 | |||
141 | hlist_for_each_entry_safe(fle, entry, tmp, | ||
142 | &fcp->hash_table[i], u.hlist) { | ||
143 | if (saved < shrink_to && | ||
144 | flow_entry_valid(fle)) { | ||
145 | saved++; | ||
146 | } else { | ||
147 | deleted++; | ||
148 | hlist_del(&fle->u.hlist); | ||
149 | list_add_tail(&fle->u.gc_list, &gc_list); | ||
150 | } | ||
151 | } | ||
152 | } | ||
118 | 153 | ||
119 | __flow_cache_shrink(cpu, shrink_to); | 154 | flow_cache_queue_garbage(fcp, deleted, &gc_list); |
120 | } | 155 | } |
121 | 156 | ||
122 | static void flow_new_hash_rnd(int cpu) | 157 | static void flow_cache_shrink(struct flow_cache *fc, |
158 | struct flow_cache_percpu *fcp) | ||
123 | { | 159 | { |
124 | get_random_bytes(&flow_hash_rnd(cpu), sizeof(u32)); | 160 | int shrink_to = fc->low_watermark / flow_cache_hash_size(fc); |
125 | flow_hash_rnd_recalc(cpu) = 0; | ||
126 | 161 | ||
127 | __flow_cache_shrink(cpu, 0); | 162 | __flow_cache_shrink(fc, fcp, shrink_to); |
128 | } | 163 | } |
129 | 164 | ||
130 | static u32 flow_hash_code(struct flowi *key, int cpu) | 165 | static void flow_new_hash_rnd(struct flow_cache *fc, |
166 | struct flow_cache_percpu *fcp) | ||
167 | { | ||
168 | get_random_bytes(&fcp->hash_rnd, sizeof(u32)); | ||
169 | fcp->hash_rnd_recalc = 0; | ||
170 | __flow_cache_shrink(fc, fcp, 0); | ||
171 | } | ||
172 | |||
173 | static u32 flow_hash_code(struct flow_cache *fc, | ||
174 | struct flow_cache_percpu *fcp, | ||
175 | struct flowi *key) | ||
131 | { | 176 | { |
132 | u32 *k = (u32 *) key; | 177 | u32 *k = (u32 *) key; |
133 | 178 | ||
134 | return (jhash2(k, (sizeof(*key) / sizeof(u32)), flow_hash_rnd(cpu)) & | 179 | return (jhash2(k, (sizeof(*key) / sizeof(u32)), fcp->hash_rnd) |
135 | (flow_hash_size - 1)); | 180 | & (flow_cache_hash_size(fc) - 1)); |
136 | } | 181 | } |
137 | 182 | ||
138 | #if (BITS_PER_LONG == 64) | 183 | #if (BITS_PER_LONG == 64) |
@@ -165,114 +210,117 @@ static int flow_key_compare(struct flowi *key1, struct flowi *key2) | |||
165 | return 0; | 210 | return 0; |
166 | } | 211 | } |
167 | 212 | ||
168 | void *flow_cache_lookup(struct net *net, struct flowi *key, u16 family, u8 dir, | 213 | struct flow_cache_object * |
169 | flow_resolve_t resolver) | 214 | flow_cache_lookup(struct net *net, struct flowi *key, u16 family, u8 dir, |
215 | flow_resolve_t resolver, void *ctx) | ||
170 | { | 216 | { |
171 | struct flow_cache_entry *fle, **head; | 217 | struct flow_cache *fc = &flow_cache_global; |
218 | struct flow_cache_percpu *fcp; | ||
219 | struct flow_cache_entry *fle, *tfle; | ||
220 | struct hlist_node *entry; | ||
221 | struct flow_cache_object *flo; | ||
172 | unsigned int hash; | 222 | unsigned int hash; |
173 | int cpu; | ||
174 | 223 | ||
175 | local_bh_disable(); | 224 | local_bh_disable(); |
176 | cpu = smp_processor_id(); | 225 | fcp = per_cpu_ptr(fc->percpu, smp_processor_id()); |
177 | 226 | ||
178 | fle = NULL; | 227 | fle = NULL; |
228 | flo = NULL; | ||
179 | /* Packet really early in init? Making flow_cache_init a | 229 | /* Packet really early in init? Making flow_cache_init a |
180 | * pre-smp initcall would solve this. --RR */ | 230 | * pre-smp initcall would solve this. --RR */ |
181 | if (!flow_table(cpu)) | 231 | if (!fcp->hash_table) |
182 | goto nocache; | 232 | goto nocache; |
183 | 233 | ||
184 | if (flow_hash_rnd_recalc(cpu)) | 234 | if (fcp->hash_rnd_recalc) |
185 | flow_new_hash_rnd(cpu); | 235 | flow_new_hash_rnd(fc, fcp); |
186 | hash = flow_hash_code(key, cpu); | ||
187 | 236 | ||
188 | head = &flow_table(cpu)[hash]; | 237 | hash = flow_hash_code(fc, fcp, key); |
189 | for (fle = *head; fle; fle = fle->next) { | 238 | hlist_for_each_entry(tfle, entry, &fcp->hash_table[hash], u.hlist) { |
190 | if (fle->family == family && | 239 | if (tfle->family == family && |
191 | fle->dir == dir && | 240 | tfle->dir == dir && |
192 | flow_key_compare(key, &fle->key) == 0) { | 241 | flow_key_compare(key, &tfle->key) == 0) { |
193 | if (fle->genid == atomic_read(&flow_cache_genid)) { | 242 | fle = tfle; |
194 | void *ret = fle->object; | ||
195 | |||
196 | if (ret) | ||
197 | atomic_inc(fle->object_ref); | ||
198 | local_bh_enable(); | ||
199 | |||
200 | return ret; | ||
201 | } | ||
202 | break; | 243 | break; |
203 | } | 244 | } |
204 | } | 245 | } |
205 | 246 | ||
206 | if (!fle) { | 247 | if (unlikely(!fle)) { |
207 | if (flow_count(cpu) > flow_hwm) | 248 | if (fcp->hash_count > fc->high_watermark) |
208 | flow_cache_shrink(cpu); | 249 | flow_cache_shrink(fc, fcp); |
209 | 250 | ||
210 | fle = kmem_cache_alloc(flow_cachep, GFP_ATOMIC); | 251 | fle = kmem_cache_alloc(flow_cachep, GFP_ATOMIC); |
211 | if (fle) { | 252 | if (fle) { |
212 | fle->next = *head; | ||
213 | *head = fle; | ||
214 | fle->family = family; | 253 | fle->family = family; |
215 | fle->dir = dir; | 254 | fle->dir = dir; |
216 | memcpy(&fle->key, key, sizeof(*key)); | 255 | memcpy(&fle->key, key, sizeof(*key)); |
217 | fle->object = NULL; | 256 | fle->object = NULL; |
218 | flow_count(cpu)++; | 257 | hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]); |
258 | fcp->hash_count++; | ||
219 | } | 259 | } |
260 | } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) { | ||
261 | flo = fle->object; | ||
262 | if (!flo) | ||
263 | goto ret_object; | ||
264 | flo = flo->ops->get(flo); | ||
265 | if (flo) | ||
266 | goto ret_object; | ||
267 | } else if (fle->object) { | ||
268 | flo = fle->object; | ||
269 | flo->ops->delete(flo); | ||
270 | fle->object = NULL; | ||
220 | } | 271 | } |
221 | 272 | ||
222 | nocache: | 273 | nocache: |
223 | { | 274 | flo = NULL; |
224 | int err; | 275 | if (fle) { |
225 | void *obj; | 276 | flo = fle->object; |
226 | atomic_t *obj_ref; | 277 | fle->object = NULL; |
227 | |||
228 | err = resolver(net, key, family, dir, &obj, &obj_ref); | ||
229 | |||
230 | if (fle && !err) { | ||
231 | fle->genid = atomic_read(&flow_cache_genid); | ||
232 | |||
233 | if (fle->object) | ||
234 | atomic_dec(fle->object_ref); | ||
235 | |||
236 | fle->object = obj; | ||
237 | fle->object_ref = obj_ref; | ||
238 | if (obj) | ||
239 | atomic_inc(fle->object_ref); | ||
240 | } | ||
241 | local_bh_enable(); | ||
242 | |||
243 | if (err) | ||
244 | obj = ERR_PTR(err); | ||
245 | return obj; | ||
246 | } | 278 | } |
279 | flo = resolver(net, key, family, dir, flo, ctx); | ||
280 | if (fle) { | ||
281 | fle->genid = atomic_read(&flow_cache_genid); | ||
282 | if (!IS_ERR(flo)) | ||
283 | fle->object = flo; | ||
284 | else | ||
285 | fle->genid--; | ||
286 | } else { | ||
287 | if (flo && !IS_ERR(flo)) | ||
288 | flo->ops->delete(flo); | ||
289 | } | ||
290 | ret_object: | ||
291 | local_bh_enable(); | ||
292 | return flo; | ||
247 | } | 293 | } |
248 | 294 | ||
249 | static void flow_cache_flush_tasklet(unsigned long data) | 295 | static void flow_cache_flush_tasklet(unsigned long data) |
250 | { | 296 | { |
251 | struct flow_flush_info *info = (void *)data; | 297 | struct flow_flush_info *info = (void *)data; |
252 | int i; | 298 | struct flow_cache *fc = info->cache; |
253 | int cpu; | 299 | struct flow_cache_percpu *fcp; |
254 | 300 | struct flow_cache_entry *fle; | |
255 | cpu = smp_processor_id(); | 301 | struct hlist_node *entry, *tmp; |
256 | for (i = 0; i < flow_hash_size; i++) { | 302 | LIST_HEAD(gc_list); |
257 | struct flow_cache_entry *fle; | 303 | int i, deleted = 0; |
258 | 304 | ||
259 | fle = flow_table(cpu)[i]; | 305 | fcp = per_cpu_ptr(fc->percpu, smp_processor_id()); |
260 | for (; fle; fle = fle->next) { | 306 | for (i = 0; i < flow_cache_hash_size(fc); i++) { |
261 | unsigned genid = atomic_read(&flow_cache_genid); | 307 | hlist_for_each_entry_safe(fle, entry, tmp, |
262 | 308 | &fcp->hash_table[i], u.hlist) { | |
263 | if (!fle->object || fle->genid == genid) | 309 | if (flow_entry_valid(fle)) |
264 | continue; | 310 | continue; |
265 | 311 | ||
266 | fle->object = NULL; | 312 | deleted++; |
267 | atomic_dec(fle->object_ref); | 313 | hlist_del(&fle->u.hlist); |
314 | list_add_tail(&fle->u.gc_list, &gc_list); | ||
268 | } | 315 | } |
269 | } | 316 | } |
270 | 317 | ||
318 | flow_cache_queue_garbage(fcp, deleted, &gc_list); | ||
319 | |||
271 | if (atomic_dec_and_test(&info->cpuleft)) | 320 | if (atomic_dec_and_test(&info->cpuleft)) |
272 | complete(&info->completion); | 321 | complete(&info->completion); |
273 | } | 322 | } |
274 | 323 | ||
275 | static void flow_cache_flush_per_cpu(void *) __attribute__((__unused__)); | ||
276 | static void flow_cache_flush_per_cpu(void *data) | 324 | static void flow_cache_flush_per_cpu(void *data) |
277 | { | 325 | { |
278 | struct flow_flush_info *info = data; | 326 | struct flow_flush_info *info = data; |
@@ -280,8 +328,7 @@ static void flow_cache_flush_per_cpu(void *data) | |||
280 | struct tasklet_struct *tasklet; | 328 | struct tasklet_struct *tasklet; |
281 | 329 | ||
282 | cpu = smp_processor_id(); | 330 | cpu = smp_processor_id(); |
283 | 331 | tasklet = &per_cpu_ptr(info->cache->percpu, cpu)->flush_tasklet; | |
284 | tasklet = flow_flush_tasklet(cpu); | ||
285 | tasklet->data = (unsigned long)info; | 332 | tasklet->data = (unsigned long)info; |
286 | tasklet_schedule(tasklet); | 333 | tasklet_schedule(tasklet); |
287 | } | 334 | } |
@@ -294,6 +341,7 @@ void flow_cache_flush(void) | |||
294 | /* Don't want cpus going down or up during this. */ | 341 | /* Don't want cpus going down or up during this. */ |
295 | get_online_cpus(); | 342 | get_online_cpus(); |
296 | mutex_lock(&flow_flush_sem); | 343 | mutex_lock(&flow_flush_sem); |
344 | info.cache = &flow_cache_global; | ||
297 | atomic_set(&info.cpuleft, num_online_cpus()); | 345 | atomic_set(&info.cpuleft, num_online_cpus()); |
298 | init_completion(&info.completion); | 346 | init_completion(&info.completion); |
299 | 347 | ||
@@ -307,62 +355,75 @@ void flow_cache_flush(void) | |||
307 | put_online_cpus(); | 355 | put_online_cpus(); |
308 | } | 356 | } |
309 | 357 | ||
310 | static void __init flow_cache_cpu_prepare(int cpu) | 358 | static void __init flow_cache_cpu_prepare(struct flow_cache *fc, |
359 | struct flow_cache_percpu *fcp) | ||
311 | { | 360 | { |
312 | struct tasklet_struct *tasklet; | 361 | fcp->hash_table = (struct hlist_head *) |
313 | unsigned long order; | 362 | __get_free_pages(GFP_KERNEL|__GFP_ZERO, fc->order); |
314 | 363 | if (!fcp->hash_table) | |
315 | for (order = 0; | 364 | panic("NET: failed to allocate flow cache order %lu\n", fc->order); |
316 | (PAGE_SIZE << order) < | 365 | |
317 | (sizeof(struct flow_cache_entry *)*flow_hash_size); | 366 | fcp->hash_rnd_recalc = 1; |
318 | order++) | 367 | fcp->hash_count = 0; |
319 | /* NOTHING */; | 368 | tasklet_init(&fcp->flush_tasklet, flow_cache_flush_tasklet, 0); |
320 | |||
321 | flow_table(cpu) = (struct flow_cache_entry **) | ||
322 | __get_free_pages(GFP_KERNEL|__GFP_ZERO, order); | ||
323 | if (!flow_table(cpu)) | ||
324 | panic("NET: failed to allocate flow cache order %lu\n", order); | ||
325 | |||
326 | flow_hash_rnd_recalc(cpu) = 1; | ||
327 | flow_count(cpu) = 0; | ||
328 | |||
329 | tasklet = flow_flush_tasklet(cpu); | ||
330 | tasklet_init(tasklet, flow_cache_flush_tasklet, 0); | ||
331 | } | 369 | } |
332 | 370 | ||
333 | static int flow_cache_cpu(struct notifier_block *nfb, | 371 | static int flow_cache_cpu(struct notifier_block *nfb, |
334 | unsigned long action, | 372 | unsigned long action, |
335 | void *hcpu) | 373 | void *hcpu) |
336 | { | 374 | { |
375 | struct flow_cache *fc = container_of(nfb, struct flow_cache, hotcpu_notifier); | ||
376 | int cpu = (unsigned long) hcpu; | ||
377 | struct flow_cache_percpu *fcp = per_cpu_ptr(fc->percpu, cpu); | ||
378 | |||
337 | if (action == CPU_DEAD || action == CPU_DEAD_FROZEN) | 379 | if (action == CPU_DEAD || action == CPU_DEAD_FROZEN) |
338 | __flow_cache_shrink((unsigned long)hcpu, 0); | 380 | __flow_cache_shrink(fc, fcp, 0); |
339 | return NOTIFY_OK; | 381 | return NOTIFY_OK; |
340 | } | 382 | } |
341 | 383 | ||
342 | static int __init flow_cache_init(void) | 384 | static int flow_cache_init(struct flow_cache *fc) |
343 | { | 385 | { |
386 | unsigned long order; | ||
344 | int i; | 387 | int i; |
345 | 388 | ||
346 | flow_cachep = kmem_cache_create("flow_cache", | 389 | fc->hash_shift = 10; |
347 | sizeof(struct flow_cache_entry), | 390 | fc->low_watermark = 2 * flow_cache_hash_size(fc); |
348 | 0, SLAB_PANIC, | 391 | fc->high_watermark = 4 * flow_cache_hash_size(fc); |
349 | NULL); | 392 | |
350 | flow_hash_shift = 10; | 393 | for (order = 0; |
351 | flow_lwm = 2 * flow_hash_size; | 394 | (PAGE_SIZE << order) < |
352 | flow_hwm = 4 * flow_hash_size; | 395 | (sizeof(struct hlist_head)*flow_cache_hash_size(fc)); |
396 | order++) | ||
397 | /* NOTHING */; | ||
398 | fc->order = order; | ||
399 | fc->percpu = alloc_percpu(struct flow_cache_percpu); | ||
353 | 400 | ||
354 | setup_timer(&flow_hash_rnd_timer, flow_cache_new_hashrnd, 0); | 401 | setup_timer(&fc->rnd_timer, flow_cache_new_hashrnd, |
355 | flow_hash_rnd_timer.expires = jiffies + FLOW_HASH_RND_PERIOD; | 402 | (unsigned long) fc); |
356 | add_timer(&flow_hash_rnd_timer); | 403 | fc->rnd_timer.expires = jiffies + FLOW_HASH_RND_PERIOD; |
404 | add_timer(&fc->rnd_timer); | ||
357 | 405 | ||
358 | for_each_possible_cpu(i) | 406 | for_each_possible_cpu(i) |
359 | flow_cache_cpu_prepare(i); | 407 | flow_cache_cpu_prepare(fc, per_cpu_ptr(fc->percpu, i)); |
408 | |||
409 | fc->hotcpu_notifier = (struct notifier_block){ | ||
410 | .notifier_call = flow_cache_cpu, | ||
411 | }; | ||
412 | register_hotcpu_notifier(&fc->hotcpu_notifier); | ||
360 | 413 | ||
361 | hotcpu_notifier(flow_cache_cpu, 0); | ||
362 | return 0; | 414 | return 0; |
363 | } | 415 | } |
364 | 416 | ||
365 | module_init(flow_cache_init); | 417 | static int __init flow_cache_init_global(void) |
418 | { | ||
419 | flow_cachep = kmem_cache_create("flow_cache", | ||
420 | sizeof(struct flow_cache_entry), | ||
421 | 0, SLAB_PANIC, NULL); | ||
422 | |||
423 | return flow_cache_init(&flow_cache_global); | ||
424 | } | ||
425 | |||
426 | module_init(flow_cache_init_global); | ||
366 | 427 | ||
367 | EXPORT_SYMBOL(flow_cache_genid); | 428 | EXPORT_SYMBOL(flow_cache_genid); |
368 | EXPORT_SYMBOL(flow_cache_lookup); | 429 | EXPORT_SYMBOL(flow_cache_lookup); |
diff --git a/net/core/gen_estimator.c b/net/core/gen_estimator.c index 493775f4f2f1..cf8e70392fe0 100644 --- a/net/core/gen_estimator.c +++ b/net/core/gen_estimator.c | |||
@@ -32,6 +32,7 @@ | |||
32 | #include <linux/rtnetlink.h> | 32 | #include <linux/rtnetlink.h> |
33 | #include <linux/init.h> | 33 | #include <linux/init.h> |
34 | #include <linux/rbtree.h> | 34 | #include <linux/rbtree.h> |
35 | #include <linux/slab.h> | ||
35 | #include <net/sock.h> | 36 | #include <net/sock.h> |
36 | #include <net/gen_stats.h> | 37 | #include <net/gen_stats.h> |
37 | 38 | ||
diff --git a/net/core/iovec.c b/net/core/iovec.c index 16ad45d4882b..1e7f4e91a935 100644 --- a/net/core/iovec.c +++ b/net/core/iovec.c | |||
@@ -20,7 +20,6 @@ | |||
20 | #include <linux/module.h> | 20 | #include <linux/module.h> |
21 | #include <linux/kernel.h> | 21 | #include <linux/kernel.h> |
22 | #include <linux/mm.h> | 22 | #include <linux/mm.h> |
23 | #include <linux/slab.h> | ||
24 | #include <linux/net.h> | 23 | #include <linux/net.h> |
25 | #include <linux/in6.h> | 24 | #include <linux/in6.h> |
26 | #include <asm/uaccess.h> | 25 | #include <asm/uaccess.h> |
diff --git a/net/core/link_watch.c b/net/core/link_watch.c index 5910b555a54a..bdbce2f5875b 100644 --- a/net/core/link_watch.c +++ b/net/core/link_watch.c | |||
@@ -19,7 +19,6 @@ | |||
19 | #include <linux/rtnetlink.h> | 19 | #include <linux/rtnetlink.h> |
20 | #include <linux/jiffies.h> | 20 | #include <linux/jiffies.h> |
21 | #include <linux/spinlock.h> | 21 | #include <linux/spinlock.h> |
22 | #include <linux/slab.h> | ||
23 | #include <linux/workqueue.h> | 22 | #include <linux/workqueue.h> |
24 | #include <linux/bitops.h> | 23 | #include <linux/bitops.h> |
25 | #include <asm/types.h> | 24 | #include <asm/types.h> |
diff --git a/net/core/neighbour.c b/net/core/neighbour.c index d102f6d9abdc..bff37908bd55 100644 --- a/net/core/neighbour.c +++ b/net/core/neighbour.c | |||
@@ -15,6 +15,7 @@ | |||
15 | * Harald Welte Add neighbour cache statistics like rtstat | 15 | * Harald Welte Add neighbour cache statistics like rtstat |
16 | */ | 16 | */ |
17 | 17 | ||
18 | #include <linux/slab.h> | ||
18 | #include <linux/types.h> | 19 | #include <linux/types.h> |
19 | #include <linux/kernel.h> | 20 | #include <linux/kernel.h> |
20 | #include <linux/module.h> | 21 | #include <linux/module.h> |
@@ -771,6 +772,8 @@ static __inline__ int neigh_max_probes(struct neighbour *n) | |||
771 | } | 772 | } |
772 | 773 | ||
773 | static void neigh_invalidate(struct neighbour *neigh) | 774 | static void neigh_invalidate(struct neighbour *neigh) |
775 | __releases(neigh->lock) | ||
776 | __acquires(neigh->lock) | ||
774 | { | 777 | { |
775 | struct sk_buff *skb; | 778 | struct sk_buff *skb; |
776 | 779 | ||
diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c index 099c753c4213..96ed6905b823 100644 --- a/net/core/net-sysfs.c +++ b/net/core/net-sysfs.c | |||
@@ -13,6 +13,7 @@ | |||
13 | #include <linux/kernel.h> | 13 | #include <linux/kernel.h> |
14 | #include <linux/netdevice.h> | 14 | #include <linux/netdevice.h> |
15 | #include <linux/if_arp.h> | 15 | #include <linux/if_arp.h> |
16 | #include <linux/slab.h> | ||
16 | #include <net/sock.h> | 17 | #include <net/sock.h> |
17 | #include <linux/rtnetlink.h> | 18 | #include <linux/rtnetlink.h> |
18 | #include <linux/wireless.h> | 19 | #include <linux/wireless.h> |
@@ -466,6 +467,217 @@ static struct attribute_group wireless_group = { | |||
466 | }; | 467 | }; |
467 | #endif | 468 | #endif |
468 | 469 | ||
470 | #ifdef CONFIG_RPS | ||
471 | /* | ||
472 | * RX queue sysfs structures and functions. | ||
473 | */ | ||
474 | struct rx_queue_attribute { | ||
475 | struct attribute attr; | ||
476 | ssize_t (*show)(struct netdev_rx_queue *queue, | ||
477 | struct rx_queue_attribute *attr, char *buf); | ||
478 | ssize_t (*store)(struct netdev_rx_queue *queue, | ||
479 | struct rx_queue_attribute *attr, const char *buf, size_t len); | ||
480 | }; | ||
481 | #define to_rx_queue_attr(_attr) container_of(_attr, \ | ||
482 | struct rx_queue_attribute, attr) | ||
483 | |||
484 | #define to_rx_queue(obj) container_of(obj, struct netdev_rx_queue, kobj) | ||
485 | |||
486 | static ssize_t rx_queue_attr_show(struct kobject *kobj, struct attribute *attr, | ||
487 | char *buf) | ||
488 | { | ||
489 | struct rx_queue_attribute *attribute = to_rx_queue_attr(attr); | ||
490 | struct netdev_rx_queue *queue = to_rx_queue(kobj); | ||
491 | |||
492 | if (!attribute->show) | ||
493 | return -EIO; | ||
494 | |||
495 | return attribute->show(queue, attribute, buf); | ||
496 | } | ||
497 | |||
498 | static ssize_t rx_queue_attr_store(struct kobject *kobj, struct attribute *attr, | ||
499 | const char *buf, size_t count) | ||
500 | { | ||
501 | struct rx_queue_attribute *attribute = to_rx_queue_attr(attr); | ||
502 | struct netdev_rx_queue *queue = to_rx_queue(kobj); | ||
503 | |||
504 | if (!attribute->store) | ||
505 | return -EIO; | ||
506 | |||
507 | return attribute->store(queue, attribute, buf, count); | ||
508 | } | ||
509 | |||
510 | static struct sysfs_ops rx_queue_sysfs_ops = { | ||
511 | .show = rx_queue_attr_show, | ||
512 | .store = rx_queue_attr_store, | ||
513 | }; | ||
514 | |||
515 | static ssize_t show_rps_map(struct netdev_rx_queue *queue, | ||
516 | struct rx_queue_attribute *attribute, char *buf) | ||
517 | { | ||
518 | struct rps_map *map; | ||
519 | cpumask_var_t mask; | ||
520 | size_t len = 0; | ||
521 | int i; | ||
522 | |||
523 | if (!zalloc_cpumask_var(&mask, GFP_KERNEL)) | ||
524 | return -ENOMEM; | ||
525 | |||
526 | rcu_read_lock(); | ||
527 | map = rcu_dereference(queue->rps_map); | ||
528 | if (map) | ||
529 | for (i = 0; i < map->len; i++) | ||
530 | cpumask_set_cpu(map->cpus[i], mask); | ||
531 | |||
532 | len += cpumask_scnprintf(buf + len, PAGE_SIZE, mask); | ||
533 | if (PAGE_SIZE - len < 3) { | ||
534 | rcu_read_unlock(); | ||
535 | free_cpumask_var(mask); | ||
536 | return -EINVAL; | ||
537 | } | ||
538 | rcu_read_unlock(); | ||
539 | |||
540 | free_cpumask_var(mask); | ||
541 | len += sprintf(buf + len, "\n"); | ||
542 | return len; | ||
543 | } | ||
544 | |||
545 | static void rps_map_release(struct rcu_head *rcu) | ||
546 | { | ||
547 | struct rps_map *map = container_of(rcu, struct rps_map, rcu); | ||
548 | |||
549 | kfree(map); | ||
550 | } | ||
551 | |||
552 | ssize_t store_rps_map(struct netdev_rx_queue *queue, | ||
553 | struct rx_queue_attribute *attribute, | ||
554 | const char *buf, size_t len) | ||
555 | { | ||
556 | struct rps_map *old_map, *map; | ||
557 | cpumask_var_t mask; | ||
558 | int err, cpu, i; | ||
559 | static DEFINE_SPINLOCK(rps_map_lock); | ||
560 | |||
561 | if (!capable(CAP_NET_ADMIN)) | ||
562 | return -EPERM; | ||
563 | |||
564 | if (!alloc_cpumask_var(&mask, GFP_KERNEL)) | ||
565 | return -ENOMEM; | ||
566 | |||
567 | err = bitmap_parse(buf, len, cpumask_bits(mask), nr_cpumask_bits); | ||
568 | if (err) { | ||
569 | free_cpumask_var(mask); | ||
570 | return err; | ||
571 | } | ||
572 | |||
573 | map = kzalloc(max_t(unsigned, | ||
574 | RPS_MAP_SIZE(cpumask_weight(mask)), L1_CACHE_BYTES), | ||
575 | GFP_KERNEL); | ||
576 | if (!map) { | ||
577 | free_cpumask_var(mask); | ||
578 | return -ENOMEM; | ||
579 | } | ||
580 | |||
581 | i = 0; | ||
582 | for_each_cpu_and(cpu, mask, cpu_online_mask) | ||
583 | map->cpus[i++] = cpu; | ||
584 | |||
585 | if (i) | ||
586 | map->len = i; | ||
587 | else { | ||
588 | kfree(map); | ||
589 | map = NULL; | ||
590 | } | ||
591 | |||
592 | spin_lock(&rps_map_lock); | ||
593 | old_map = queue->rps_map; | ||
594 | rcu_assign_pointer(queue->rps_map, map); | ||
595 | spin_unlock(&rps_map_lock); | ||
596 | |||
597 | if (old_map) | ||
598 | call_rcu(&old_map->rcu, rps_map_release); | ||
599 | |||
600 | free_cpumask_var(mask); | ||
601 | return len; | ||
602 | } | ||
603 | |||
604 | static struct rx_queue_attribute rps_cpus_attribute = | ||
605 | __ATTR(rps_cpus, S_IRUGO | S_IWUSR, show_rps_map, store_rps_map); | ||
606 | |||
607 | static struct attribute *rx_queue_default_attrs[] = { | ||
608 | &rps_cpus_attribute.attr, | ||
609 | NULL | ||
610 | }; | ||
611 | |||
612 | static void rx_queue_release(struct kobject *kobj) | ||
613 | { | ||
614 | struct netdev_rx_queue *queue = to_rx_queue(kobj); | ||
615 | struct rps_map *map = queue->rps_map; | ||
616 | struct netdev_rx_queue *first = queue->first; | ||
617 | |||
618 | if (map) | ||
619 | call_rcu(&map->rcu, rps_map_release); | ||
620 | |||
621 | if (atomic_dec_and_test(&first->count)) | ||
622 | kfree(first); | ||
623 | } | ||
624 | |||
625 | static struct kobj_type rx_queue_ktype = { | ||
626 | .sysfs_ops = &rx_queue_sysfs_ops, | ||
627 | .release = rx_queue_release, | ||
628 | .default_attrs = rx_queue_default_attrs, | ||
629 | }; | ||
630 | |||
631 | static int rx_queue_add_kobject(struct net_device *net, int index) | ||
632 | { | ||
633 | struct netdev_rx_queue *queue = net->_rx + index; | ||
634 | struct kobject *kobj = &queue->kobj; | ||
635 | int error = 0; | ||
636 | |||
637 | kobj->kset = net->queues_kset; | ||
638 | error = kobject_init_and_add(kobj, &rx_queue_ktype, NULL, | ||
639 | "rx-%u", index); | ||
640 | if (error) { | ||
641 | kobject_put(kobj); | ||
642 | return error; | ||
643 | } | ||
644 | |||
645 | kobject_uevent(kobj, KOBJ_ADD); | ||
646 | |||
647 | return error; | ||
648 | } | ||
649 | |||
650 | static int rx_queue_register_kobjects(struct net_device *net) | ||
651 | { | ||
652 | int i; | ||
653 | int error = 0; | ||
654 | |||
655 | net->queues_kset = kset_create_and_add("queues", | ||
656 | NULL, &net->dev.kobj); | ||
657 | if (!net->queues_kset) | ||
658 | return -ENOMEM; | ||
659 | for (i = 0; i < net->num_rx_queues; i++) { | ||
660 | error = rx_queue_add_kobject(net, i); | ||
661 | if (error) | ||
662 | break; | ||
663 | } | ||
664 | |||
665 | if (error) | ||
666 | while (--i >= 0) | ||
667 | kobject_put(&net->_rx[i].kobj); | ||
668 | |||
669 | return error; | ||
670 | } | ||
671 | |||
672 | static void rx_queue_remove_kobjects(struct net_device *net) | ||
673 | { | ||
674 | int i; | ||
675 | |||
676 | for (i = 0; i < net->num_rx_queues; i++) | ||
677 | kobject_put(&net->_rx[i].kobj); | ||
678 | kset_unregister(net->queues_kset); | ||
679 | } | ||
680 | #endif /* CONFIG_RPS */ | ||
469 | #endif /* CONFIG_SYSFS */ | 681 | #endif /* CONFIG_SYSFS */ |
470 | 682 | ||
471 | #ifdef CONFIG_HOTPLUG | 683 | #ifdef CONFIG_HOTPLUG |
@@ -529,6 +741,10 @@ void netdev_unregister_kobject(struct net_device * net) | |||
529 | if (!net_eq(dev_net(net), &init_net)) | 741 | if (!net_eq(dev_net(net), &init_net)) |
530 | return; | 742 | return; |
531 | 743 | ||
744 | #ifdef CONFIG_RPS | ||
745 | rx_queue_remove_kobjects(net); | ||
746 | #endif | ||
747 | |||
532 | device_del(dev); | 748 | device_del(dev); |
533 | } | 749 | } |
534 | 750 | ||
@@ -537,6 +753,7 @@ int netdev_register_kobject(struct net_device *net) | |||
537 | { | 753 | { |
538 | struct device *dev = &(net->dev); | 754 | struct device *dev = &(net->dev); |
539 | const struct attribute_group **groups = net->sysfs_groups; | 755 | const struct attribute_group **groups = net->sysfs_groups; |
756 | int error = 0; | ||
540 | 757 | ||
541 | dev->class = &net_class; | 758 | dev->class = &net_class; |
542 | dev->platform_data = net; | 759 | dev->platform_data = net; |
@@ -563,7 +780,19 @@ int netdev_register_kobject(struct net_device *net) | |||
563 | if (!net_eq(dev_net(net), &init_net)) | 780 | if (!net_eq(dev_net(net), &init_net)) |
564 | return 0; | 781 | return 0; |
565 | 782 | ||
566 | return device_add(dev); | 783 | error = device_add(dev); |
784 | if (error) | ||
785 | return error; | ||
786 | |||
787 | #ifdef CONFIG_RPS | ||
788 | error = rx_queue_register_kobjects(net); | ||
789 | if (error) { | ||
790 | device_del(dev); | ||
791 | return error; | ||
792 | } | ||
793 | #endif | ||
794 | |||
795 | return error; | ||
567 | } | 796 | } |
568 | 797 | ||
569 | int netdev_class_create_file(struct class_attribute *class_attr) | 798 | int netdev_class_create_file(struct class_attribute *class_attr) |
diff --git a/net/core/net-traces.c b/net/core/net-traces.c index f1e982c508bb..afa6380ed88a 100644 --- a/net/core/net-traces.c +++ b/net/core/net-traces.c | |||
@@ -19,6 +19,7 @@ | |||
19 | #include <linux/workqueue.h> | 19 | #include <linux/workqueue.h> |
20 | #include <linux/netlink.h> | 20 | #include <linux/netlink.h> |
21 | #include <linux/net_dropmon.h> | 21 | #include <linux/net_dropmon.h> |
22 | #include <linux/slab.h> | ||
22 | 23 | ||
23 | #include <asm/unaligned.h> | 24 | #include <asm/unaligned.h> |
24 | #include <asm/bitops.h> | 25 | #include <asm/bitops.h> |
diff --git a/net/core/netpoll.c b/net/core/netpoll.c index 7aa697253765..a58f59b97597 100644 --- a/net/core/netpoll.c +++ b/net/core/netpoll.c | |||
@@ -22,6 +22,7 @@ | |||
22 | #include <linux/delay.h> | 22 | #include <linux/delay.h> |
23 | #include <linux/rcupdate.h> | 23 | #include <linux/rcupdate.h> |
24 | #include <linux/workqueue.h> | 24 | #include <linux/workqueue.h> |
25 | #include <linux/slab.h> | ||
25 | #include <net/tcp.h> | 26 | #include <net/tcp.h> |
26 | #include <net/udp.h> | 27 | #include <net/udp.h> |
27 | #include <asm/unaligned.h> | 28 | #include <asm/unaligned.h> |
@@ -614,7 +615,7 @@ void netpoll_print_options(struct netpoll *np) | |||
614 | np->name, np->local_port); | 615 | np->name, np->local_port); |
615 | printk(KERN_INFO "%s: local IP %pI4\n", | 616 | printk(KERN_INFO "%s: local IP %pI4\n", |
616 | np->name, &np->local_ip); | 617 | np->name, &np->local_ip); |
617 | printk(KERN_INFO "%s: interface %s\n", | 618 | printk(KERN_INFO "%s: interface '%s'\n", |
618 | np->name, np->dev_name); | 619 | np->name, np->dev_name); |
619 | printk(KERN_INFO "%s: remote port %d\n", | 620 | printk(KERN_INFO "%s: remote port %d\n", |
620 | np->name, np->remote_port); | 621 | np->name, np->remote_port); |
@@ -661,6 +662,9 @@ int netpoll_parse_options(struct netpoll *np, char *opt) | |||
661 | if ((delim = strchr(cur, '@')) == NULL) | 662 | if ((delim = strchr(cur, '@')) == NULL) |
662 | goto parse_failed; | 663 | goto parse_failed; |
663 | *delim = 0; | 664 | *delim = 0; |
665 | if (*cur == ' ' || *cur == '\t') | ||
666 | printk(KERN_INFO "%s: warning: whitespace" | ||
667 | "is not allowed\n", np->name); | ||
664 | np->remote_port = simple_strtol(cur, NULL, 10); | 668 | np->remote_port = simple_strtol(cur, NULL, 10); |
665 | cur = delim; | 669 | cur = delim; |
666 | } | 670 | } |
@@ -708,7 +712,7 @@ int netpoll_parse_options(struct netpoll *np, char *opt) | |||
708 | return 0; | 712 | return 0; |
709 | 713 | ||
710 | parse_failed: | 714 | parse_failed: |
711 | printk(KERN_INFO "%s: couldn't parse config at %s!\n", | 715 | printk(KERN_INFO "%s: couldn't parse config at '%s'!\n", |
712 | np->name, cur); | 716 | np->name, cur); |
713 | return -1; | 717 | return -1; |
714 | } | 718 | } |
@@ -735,7 +739,7 @@ int netpoll_setup(struct netpoll *np) | |||
735 | npinfo = kmalloc(sizeof(*npinfo), GFP_KERNEL); | 739 | npinfo = kmalloc(sizeof(*npinfo), GFP_KERNEL); |
736 | if (!npinfo) { | 740 | if (!npinfo) { |
737 | err = -ENOMEM; | 741 | err = -ENOMEM; |
738 | goto release; | 742 | goto put; |
739 | } | 743 | } |
740 | 744 | ||
741 | npinfo->rx_flags = 0; | 745 | npinfo->rx_flags = 0; |
@@ -845,7 +849,7 @@ int netpoll_setup(struct netpoll *np) | |||
845 | 849 | ||
846 | kfree(npinfo); | 850 | kfree(npinfo); |
847 | } | 851 | } |
848 | 852 | put: | |
849 | dev_put(ndev); | 853 | dev_put(ndev); |
850 | return err; | 854 | return err; |
851 | } | 855 | } |
diff --git a/net/core/pktgen.c b/net/core/pktgen.c index 43923811bd6a..2ad68da418df 100644 --- a/net/core/pktgen.c +++ b/net/core/pktgen.c | |||
@@ -169,7 +169,7 @@ | |||
169 | #include <asm/dma.h> | 169 | #include <asm/dma.h> |
170 | #include <asm/div64.h> /* do_div */ | 170 | #include <asm/div64.h> /* do_div */ |
171 | 171 | ||
172 | #define VERSION "2.72" | 172 | #define VERSION "2.73" |
173 | #define IP_NAME_SZ 32 | 173 | #define IP_NAME_SZ 32 |
174 | #define MAX_MPLS_LABELS 16 /* This is the max label stack depth */ | 174 | #define MAX_MPLS_LABELS 16 /* This is the max label stack depth */ |
175 | #define MPLS_STACK_BOTTOM htonl(0x00000100) | 175 | #define MPLS_STACK_BOTTOM htonl(0x00000100) |
@@ -190,6 +190,7 @@ | |||
190 | #define F_IPSEC_ON (1<<12) /* ipsec on for flows */ | 190 | #define F_IPSEC_ON (1<<12) /* ipsec on for flows */ |
191 | #define F_QUEUE_MAP_RND (1<<13) /* queue map Random */ | 191 | #define F_QUEUE_MAP_RND (1<<13) /* queue map Random */ |
192 | #define F_QUEUE_MAP_CPU (1<<14) /* queue map mirrors smp_processor_id() */ | 192 | #define F_QUEUE_MAP_CPU (1<<14) /* queue map mirrors smp_processor_id() */ |
193 | #define F_NODE (1<<15) /* Node memory alloc*/ | ||
193 | 194 | ||
194 | /* Thread control flag bits */ | 195 | /* Thread control flag bits */ |
195 | #define T_STOP (1<<0) /* Stop run */ | 196 | #define T_STOP (1<<0) /* Stop run */ |
@@ -372,6 +373,7 @@ struct pktgen_dev { | |||
372 | 373 | ||
373 | u16 queue_map_min; | 374 | u16 queue_map_min; |
374 | u16 queue_map_max; | 375 | u16 queue_map_max; |
376 | int node; /* Memory node */ | ||
375 | 377 | ||
376 | #ifdef CONFIG_XFRM | 378 | #ifdef CONFIG_XFRM |
377 | __u8 ipsmode; /* IPSEC mode (config) */ | 379 | __u8 ipsmode; /* IPSEC mode (config) */ |
@@ -607,6 +609,9 @@ static int pktgen_if_show(struct seq_file *seq, void *v) | |||
607 | if (pkt_dev->traffic_class) | 609 | if (pkt_dev->traffic_class) |
608 | seq_printf(seq, " traffic_class: 0x%02x\n", pkt_dev->traffic_class); | 610 | seq_printf(seq, " traffic_class: 0x%02x\n", pkt_dev->traffic_class); |
609 | 611 | ||
612 | if (pkt_dev->node >= 0) | ||
613 | seq_printf(seq, " node: %d\n", pkt_dev->node); | ||
614 | |||
610 | seq_printf(seq, " Flags: "); | 615 | seq_printf(seq, " Flags: "); |
611 | 616 | ||
612 | if (pkt_dev->flags & F_IPV6) | 617 | if (pkt_dev->flags & F_IPV6) |
@@ -660,6 +665,9 @@ static int pktgen_if_show(struct seq_file *seq, void *v) | |||
660 | if (pkt_dev->flags & F_SVID_RND) | 665 | if (pkt_dev->flags & F_SVID_RND) |
661 | seq_printf(seq, "SVID_RND "); | 666 | seq_printf(seq, "SVID_RND "); |
662 | 667 | ||
668 | if (pkt_dev->flags & F_NODE) | ||
669 | seq_printf(seq, "NODE_ALLOC "); | ||
670 | |||
663 | seq_puts(seq, "\n"); | 671 | seq_puts(seq, "\n"); |
664 | 672 | ||
665 | /* not really stopped, more like last-running-at */ | 673 | /* not really stopped, more like last-running-at */ |
@@ -1074,6 +1082,21 @@ static ssize_t pktgen_if_write(struct file *file, | |||
1074 | pkt_dev->dst_mac_count); | 1082 | pkt_dev->dst_mac_count); |
1075 | return count; | 1083 | return count; |
1076 | } | 1084 | } |
1085 | if (!strcmp(name, "node")) { | ||
1086 | len = num_arg(&user_buffer[i], 10, &value); | ||
1087 | if (len < 0) | ||
1088 | return len; | ||
1089 | |||
1090 | i += len; | ||
1091 | |||
1092 | if (node_possible(value)) { | ||
1093 | pkt_dev->node = value; | ||
1094 | sprintf(pg_result, "OK: node=%d", pkt_dev->node); | ||
1095 | } | ||
1096 | else | ||
1097 | sprintf(pg_result, "ERROR: node not possible"); | ||
1098 | return count; | ||
1099 | } | ||
1077 | if (!strcmp(name, "flag")) { | 1100 | if (!strcmp(name, "flag")) { |
1078 | char f[32]; | 1101 | char f[32]; |
1079 | memset(f, 0, 32); | 1102 | memset(f, 0, 32); |
@@ -1166,12 +1189,18 @@ static ssize_t pktgen_if_write(struct file *file, | |||
1166 | else if (strcmp(f, "!IPV6") == 0) | 1189 | else if (strcmp(f, "!IPV6") == 0) |
1167 | pkt_dev->flags &= ~F_IPV6; | 1190 | pkt_dev->flags &= ~F_IPV6; |
1168 | 1191 | ||
1192 | else if (strcmp(f, "NODE_ALLOC") == 0) | ||
1193 | pkt_dev->flags |= F_NODE; | ||
1194 | |||
1195 | else if (strcmp(f, "!NODE_ALLOC") == 0) | ||
1196 | pkt_dev->flags &= ~F_NODE; | ||
1197 | |||
1169 | else { | 1198 | else { |
1170 | sprintf(pg_result, | 1199 | sprintf(pg_result, |
1171 | "Flag -:%s:- unknown\nAvailable flags, (prepend ! to un-set flag):\n%s", | 1200 | "Flag -:%s:- unknown\nAvailable flags, (prepend ! to un-set flag):\n%s", |
1172 | f, | 1201 | f, |
1173 | "IPSRC_RND, IPDST_RND, UDPSRC_RND, UDPDST_RND, " | 1202 | "IPSRC_RND, IPDST_RND, UDPSRC_RND, UDPDST_RND, " |
1174 | "MACSRC_RND, MACDST_RND, TXSIZE_RND, IPV6, MPLS_RND, VID_RND, SVID_RND, FLOW_SEQ, IPSEC\n"); | 1203 | "MACSRC_RND, MACDST_RND, TXSIZE_RND, IPV6, MPLS_RND, VID_RND, SVID_RND, FLOW_SEQ, IPSEC, NODE_ALLOC\n"); |
1175 | return count; | 1204 | return count; |
1176 | } | 1205 | } |
1177 | sprintf(pg_result, "OK: flags=0x%x", pkt_dev->flags); | 1206 | sprintf(pg_result, "OK: flags=0x%x", pkt_dev->flags); |
@@ -2572,9 +2601,27 @@ static struct sk_buff *fill_packet_ipv4(struct net_device *odev, | |||
2572 | mod_cur_headers(pkt_dev); | 2601 | mod_cur_headers(pkt_dev); |
2573 | 2602 | ||
2574 | datalen = (odev->hard_header_len + 16) & ~0xf; | 2603 | datalen = (odev->hard_header_len + 16) & ~0xf; |
2575 | skb = __netdev_alloc_skb(odev, | 2604 | |
2576 | pkt_dev->cur_pkt_size + 64 | 2605 | if (pkt_dev->flags & F_NODE) { |
2577 | + datalen + pkt_dev->pkt_overhead, GFP_NOWAIT); | 2606 | int node; |
2607 | |||
2608 | if (pkt_dev->node >= 0) | ||
2609 | node = pkt_dev->node; | ||
2610 | else | ||
2611 | node = numa_node_id(); | ||
2612 | |||
2613 | skb = __alloc_skb(NET_SKB_PAD + pkt_dev->cur_pkt_size + 64 | ||
2614 | + datalen + pkt_dev->pkt_overhead, GFP_NOWAIT, 0, node); | ||
2615 | if (likely(skb)) { | ||
2616 | skb_reserve(skb, NET_SKB_PAD); | ||
2617 | skb->dev = odev; | ||
2618 | } | ||
2619 | } | ||
2620 | else | ||
2621 | skb = __netdev_alloc_skb(odev, | ||
2622 | pkt_dev->cur_pkt_size + 64 | ||
2623 | + datalen + pkt_dev->pkt_overhead, GFP_NOWAIT); | ||
2624 | |||
2578 | if (!skb) { | 2625 | if (!skb) { |
2579 | sprintf(pkt_dev->result, "No memory"); | 2626 | sprintf(pkt_dev->result, "No memory"); |
2580 | return NULL; | 2627 | return NULL; |
@@ -3674,6 +3721,7 @@ static int pktgen_add_device(struct pktgen_thread *t, const char *ifname) | |||
3674 | pkt_dev->svlan_p = 0; | 3721 | pkt_dev->svlan_p = 0; |
3675 | pkt_dev->svlan_cfi = 0; | 3722 | pkt_dev->svlan_cfi = 0; |
3676 | pkt_dev->svlan_id = 0xffff; | 3723 | pkt_dev->svlan_id = 0xffff; |
3724 | pkt_dev->node = -1; | ||
3677 | 3725 | ||
3678 | err = pktgen_setup_dev(pkt_dev, ifname); | 3726 | err = pktgen_setup_dev(pkt_dev, ifname); |
3679 | if (err) | 3727 | if (err) |
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index 4568120d8533..78c85985cb30 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c | |||
@@ -118,7 +118,11 @@ static rtnl_doit_func rtnl_get_doit(int protocol, int msgindex) | |||
118 | { | 118 | { |
119 | struct rtnl_link *tab; | 119 | struct rtnl_link *tab; |
120 | 120 | ||
121 | tab = rtnl_msg_handlers[protocol]; | 121 | if (protocol < NPROTO) |
122 | tab = rtnl_msg_handlers[protocol]; | ||
123 | else | ||
124 | tab = NULL; | ||
125 | |||
122 | if (tab == NULL || tab[msgindex].doit == NULL) | 126 | if (tab == NULL || tab[msgindex].doit == NULL) |
123 | tab = rtnl_msg_handlers[PF_UNSPEC]; | 127 | tab = rtnl_msg_handlers[PF_UNSPEC]; |
124 | 128 | ||
@@ -129,7 +133,11 @@ static rtnl_dumpit_func rtnl_get_dumpit(int protocol, int msgindex) | |||
129 | { | 133 | { |
130 | struct rtnl_link *tab; | 134 | struct rtnl_link *tab; |
131 | 135 | ||
132 | tab = rtnl_msg_handlers[protocol]; | 136 | if (protocol < NPROTO) |
137 | tab = rtnl_msg_handlers[protocol]; | ||
138 | else | ||
139 | tab = NULL; | ||
140 | |||
133 | if (tab == NULL || tab[msgindex].dumpit == NULL) | 141 | if (tab == NULL || tab[msgindex].dumpit == NULL) |
134 | tab = rtnl_msg_handlers[PF_UNSPEC]; | 142 | tab = rtnl_msg_handlers[PF_UNSPEC]; |
135 | 143 | ||
@@ -600,7 +608,41 @@ static void copy_rtnl_link_stats(struct rtnl_link_stats *a, | |||
600 | 608 | ||
601 | a->rx_compressed = b->rx_compressed; | 609 | a->rx_compressed = b->rx_compressed; |
602 | a->tx_compressed = b->tx_compressed; | 610 | a->tx_compressed = b->tx_compressed; |
603 | }; | 611 | } |
612 | |||
613 | static void copy_rtnl_link_stats64(void *v, const struct net_device_stats *b) | ||
614 | { | ||
615 | struct rtnl_link_stats64 a; | ||
616 | |||
617 | a.rx_packets = b->rx_packets; | ||
618 | a.tx_packets = b->tx_packets; | ||
619 | a.rx_bytes = b->rx_bytes; | ||
620 | a.tx_bytes = b->tx_bytes; | ||
621 | a.rx_errors = b->rx_errors; | ||
622 | a.tx_errors = b->tx_errors; | ||
623 | a.rx_dropped = b->rx_dropped; | ||
624 | a.tx_dropped = b->tx_dropped; | ||
625 | |||
626 | a.multicast = b->multicast; | ||
627 | a.collisions = b->collisions; | ||
628 | |||
629 | a.rx_length_errors = b->rx_length_errors; | ||
630 | a.rx_over_errors = b->rx_over_errors; | ||
631 | a.rx_crc_errors = b->rx_crc_errors; | ||
632 | a.rx_frame_errors = b->rx_frame_errors; | ||
633 | a.rx_fifo_errors = b->rx_fifo_errors; | ||
634 | a.rx_missed_errors = b->rx_missed_errors; | ||
635 | |||
636 | a.tx_aborted_errors = b->tx_aborted_errors; | ||
637 | a.tx_carrier_errors = b->tx_carrier_errors; | ||
638 | a.tx_fifo_errors = b->tx_fifo_errors; | ||
639 | a.tx_heartbeat_errors = b->tx_heartbeat_errors; | ||
640 | a.tx_window_errors = b->tx_window_errors; | ||
641 | |||
642 | a.rx_compressed = b->rx_compressed; | ||
643 | a.tx_compressed = b->tx_compressed; | ||
644 | memcpy(v, &a, sizeof(a)); | ||
645 | } | ||
604 | 646 | ||
605 | static inline int rtnl_vfinfo_size(const struct net_device *dev) | 647 | static inline int rtnl_vfinfo_size(const struct net_device *dev) |
606 | { | 648 | { |
@@ -619,6 +661,7 @@ static inline size_t if_nlmsg_size(const struct net_device *dev) | |||
619 | + nla_total_size(IFNAMSIZ) /* IFLA_QDISC */ | 661 | + nla_total_size(IFNAMSIZ) /* IFLA_QDISC */ |
620 | + nla_total_size(sizeof(struct rtnl_link_ifmap)) | 662 | + nla_total_size(sizeof(struct rtnl_link_ifmap)) |
621 | + nla_total_size(sizeof(struct rtnl_link_stats)) | 663 | + nla_total_size(sizeof(struct rtnl_link_stats)) |
664 | + nla_total_size(sizeof(struct rtnl_link_stats64)) | ||
622 | + nla_total_size(MAX_ADDR_LEN) /* IFLA_ADDRESS */ | 665 | + nla_total_size(MAX_ADDR_LEN) /* IFLA_ADDRESS */ |
623 | + nla_total_size(MAX_ADDR_LEN) /* IFLA_BROADCAST */ | 666 | + nla_total_size(MAX_ADDR_LEN) /* IFLA_BROADCAST */ |
624 | + nla_total_size(4) /* IFLA_TXQLEN */ | 667 | + nla_total_size(4) /* IFLA_TXQLEN */ |
@@ -698,6 +741,12 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev, | |||
698 | stats = dev_get_stats(dev); | 741 | stats = dev_get_stats(dev); |
699 | copy_rtnl_link_stats(nla_data(attr), stats); | 742 | copy_rtnl_link_stats(nla_data(attr), stats); |
700 | 743 | ||
744 | attr = nla_reserve(skb, IFLA_STATS64, | ||
745 | sizeof(struct rtnl_link_stats64)); | ||
746 | if (attr == NULL) | ||
747 | goto nla_put_failure; | ||
748 | copy_rtnl_link_stats64(nla_data(attr), stats); | ||
749 | |||
701 | if (dev->netdev_ops->ndo_get_vf_config && dev->dev.parent) { | 750 | if (dev->netdev_ops->ndo_get_vf_config && dev->dev.parent) { |
702 | int i; | 751 | int i; |
703 | struct ifla_vf_info ivi; | 752 | struct ifla_vf_info ivi; |
@@ -1403,9 +1452,6 @@ static int rtnetlink_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh) | |||
1403 | return 0; | 1452 | return 0; |
1404 | 1453 | ||
1405 | family = ((struct rtgenmsg *)NLMSG_DATA(nlh))->rtgen_family; | 1454 | family = ((struct rtgenmsg *)NLMSG_DATA(nlh))->rtgen_family; |
1406 | if (family >= NPROTO) | ||
1407 | return -EAFNOSUPPORT; | ||
1408 | |||
1409 | sz_idx = type>>2; | 1455 | sz_idx = type>>2; |
1410 | kind = type&3; | 1456 | kind = type&3; |
1411 | 1457 | ||
@@ -1473,6 +1519,7 @@ static int rtnetlink_event(struct notifier_block *this, unsigned long event, voi | |||
1473 | case NETDEV_POST_INIT: | 1519 | case NETDEV_POST_INIT: |
1474 | case NETDEV_REGISTER: | 1520 | case NETDEV_REGISTER: |
1475 | case NETDEV_CHANGE: | 1521 | case NETDEV_CHANGE: |
1522 | case NETDEV_PRE_TYPE_CHANGE: | ||
1476 | case NETDEV_GOING_DOWN: | 1523 | case NETDEV_GOING_DOWN: |
1477 | case NETDEV_UNREGISTER: | 1524 | case NETDEV_UNREGISTER: |
1478 | case NETDEV_UNREGISTER_BATCH: | 1525 | case NETDEV_UNREGISTER_BATCH: |
diff --git a/net/core/scm.c b/net/core/scm.c index 9b264634acfd..b88f6f9d0b97 100644 --- a/net/core/scm.c +++ b/net/core/scm.c | |||
@@ -26,6 +26,7 @@ | |||
26 | #include <linux/security.h> | 26 | #include <linux/security.h> |
27 | #include <linux/pid.h> | 27 | #include <linux/pid.h> |
28 | #include <linux/nsproxy.h> | 28 | #include <linux/nsproxy.h> |
29 | #include <linux/slab.h> | ||
29 | 30 | ||
30 | #include <asm/system.h> | 31 | #include <asm/system.h> |
31 | #include <asm/uaccess.h> | 32 | #include <asm/uaccess.h> |
diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 93c4e060c91e..bdea0efdf8cb 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c | |||
@@ -534,6 +534,7 @@ static void __copy_skb_header(struct sk_buff *new, const struct sk_buff *old) | |||
534 | new->network_header = old->network_header; | 534 | new->network_header = old->network_header; |
535 | new->mac_header = old->mac_header; | 535 | new->mac_header = old->mac_header; |
536 | skb_dst_set(new, dst_clone(skb_dst(old))); | 536 | skb_dst_set(new, dst_clone(skb_dst(old))); |
537 | new->rxhash = old->rxhash; | ||
537 | #ifdef CONFIG_XFRM | 538 | #ifdef CONFIG_XFRM |
538 | new->sp = secpath_get(old->sp); | 539 | new->sp = secpath_get(old->sp); |
539 | #endif | 540 | #endif |
@@ -581,6 +582,7 @@ static struct sk_buff *__skb_clone(struct sk_buff *n, struct sk_buff *skb) | |||
581 | C(len); | 582 | C(len); |
582 | C(data_len); | 583 | C(data_len); |
583 | C(mac_len); | 584 | C(mac_len); |
585 | C(rxhash); | ||
584 | n->hdr_len = skb->nohdr ? skb_headroom(skb) : skb->hdr_len; | 586 | n->hdr_len = skb->nohdr ? skb_headroom(skb) : skb->hdr_len; |
585 | n->cloned = 1; | 587 | n->cloned = 1; |
586 | n->nohdr = 0; | 588 | n->nohdr = 0; |
diff --git a/net/core/sock.c b/net/core/sock.c index c5812bbc2cc9..7effa1e689df 100644 --- a/net/core/sock.c +++ b/net/core/sock.c | |||
@@ -364,11 +364,11 @@ EXPORT_SYMBOL(sk_reset_txq); | |||
364 | 364 | ||
365 | struct dst_entry *__sk_dst_check(struct sock *sk, u32 cookie) | 365 | struct dst_entry *__sk_dst_check(struct sock *sk, u32 cookie) |
366 | { | 366 | { |
367 | struct dst_entry *dst = sk->sk_dst_cache; | 367 | struct dst_entry *dst = __sk_dst_get(sk); |
368 | 368 | ||
369 | if (dst && dst->obsolete && dst->ops->check(dst, cookie) == NULL) { | 369 | if (dst && dst->obsolete && dst->ops->check(dst, cookie) == NULL) { |
370 | sk_tx_queue_clear(sk); | 370 | sk_tx_queue_clear(sk); |
371 | sk->sk_dst_cache = NULL; | 371 | rcu_assign_pointer(sk->sk_dst_cache, NULL); |
372 | dst_release(dst); | 372 | dst_release(dst); |
373 | return NULL; | 373 | return NULL; |
374 | } | 374 | } |
@@ -1157,7 +1157,7 @@ struct sock *sk_clone(const struct sock *sk, const gfp_t priority) | |||
1157 | skb_queue_head_init(&newsk->sk_async_wait_queue); | 1157 | skb_queue_head_init(&newsk->sk_async_wait_queue); |
1158 | #endif | 1158 | #endif |
1159 | 1159 | ||
1160 | rwlock_init(&newsk->sk_dst_lock); | 1160 | spin_lock_init(&newsk->sk_dst_lock); |
1161 | rwlock_init(&newsk->sk_callback_lock); | 1161 | rwlock_init(&newsk->sk_callback_lock); |
1162 | lockdep_set_class_and_name(&newsk->sk_callback_lock, | 1162 | lockdep_set_class_and_name(&newsk->sk_callback_lock, |
1163 | af_callback_keys + newsk->sk_family, | 1163 | af_callback_keys + newsk->sk_family, |
@@ -1898,7 +1898,7 @@ void sock_init_data(struct socket *sock, struct sock *sk) | |||
1898 | } else | 1898 | } else |
1899 | sk->sk_sleep = NULL; | 1899 | sk->sk_sleep = NULL; |
1900 | 1900 | ||
1901 | rwlock_init(&sk->sk_dst_lock); | 1901 | spin_lock_init(&sk->sk_dst_lock); |
1902 | rwlock_init(&sk->sk_callback_lock); | 1902 | rwlock_init(&sk->sk_callback_lock); |
1903 | lockdep_set_class_and_name(&sk->sk_callback_lock, | 1903 | lockdep_set_class_and_name(&sk->sk_callback_lock, |
1904 | af_callback_keys + sk->sk_family, | 1904 | af_callback_keys + sk->sk_family, |
diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c index 06124872af5b..b7b6b8208f75 100644 --- a/net/core/sysctl_net_core.c +++ b/net/core/sysctl_net_core.c | |||
@@ -12,6 +12,7 @@ | |||
12 | #include <linux/netdevice.h> | 12 | #include <linux/netdevice.h> |
13 | #include <linux/ratelimit.h> | 13 | #include <linux/ratelimit.h> |
14 | #include <linux/init.h> | 14 | #include <linux/init.h> |
15 | #include <linux/slab.h> | ||
15 | 16 | ||
16 | #include <net/ip.h> | 17 | #include <net/ip.h> |
17 | #include <net/sock.h> | 18 | #include <net/sock.h> |
diff --git a/net/dcb/dcbnl.c b/net/dcb/dcbnl.c index 813e399220a7..19ac2b985485 100644 --- a/net/dcb/dcbnl.c +++ b/net/dcb/dcbnl.c | |||
@@ -19,6 +19,7 @@ | |||
19 | 19 | ||
20 | #include <linux/netdevice.h> | 20 | #include <linux/netdevice.h> |
21 | #include <linux/netlink.h> | 21 | #include <linux/netlink.h> |
22 | #include <linux/slab.h> | ||
22 | #include <net/netlink.h> | 23 | #include <net/netlink.h> |
23 | #include <net/rtnetlink.h> | 24 | #include <net/rtnetlink.h> |
24 | #include <linux/dcbnl.h> | 25 | #include <linux/dcbnl.h> |
diff --git a/net/dccp/ccid.c b/net/dccp/ccid.c index 49d27c556bec..36479ca61e03 100644 --- a/net/dccp/ccid.c +++ b/net/dccp/ccid.c | |||
@@ -11,6 +11,8 @@ | |||
11 | * published by the Free Software Foundation. | 11 | * published by the Free Software Foundation. |
12 | */ | 12 | */ |
13 | 13 | ||
14 | #include <linux/slab.h> | ||
15 | |||
14 | #include "ccid.h" | 16 | #include "ccid.h" |
15 | #include "ccids/lib/tfrc.h" | 17 | #include "ccids/lib/tfrc.h" |
16 | 18 | ||
diff --git a/net/dccp/ccids/ccid2.c b/net/dccp/ccids/ccid2.c index a47a8c918ee8..9b3ae9922be1 100644 --- a/net/dccp/ccids/ccid2.c +++ b/net/dccp/ccids/ccid2.c | |||
@@ -23,6 +23,7 @@ | |||
23 | /* | 23 | /* |
24 | * This implementation should follow RFC 4341 | 24 | * This implementation should follow RFC 4341 |
25 | */ | 25 | */ |
26 | #include <linux/slab.h> | ||
26 | #include "../feat.h" | 27 | #include "../feat.h" |
27 | #include "../ccid.h" | 28 | #include "../ccid.h" |
28 | #include "../dccp.h" | 29 | #include "../dccp.h" |
diff --git a/net/dccp/ccids/ccid3.c b/net/dccp/ccids/ccid3.c index bcd7632299f5..d3235899c7e3 100644 --- a/net/dccp/ccids/ccid3.c +++ b/net/dccp/ccids/ccid3.c | |||
@@ -208,7 +208,7 @@ static void ccid3_hc_tx_no_feedback_timer(unsigned long data) | |||
208 | goto restart_timer; | 208 | goto restart_timer; |
209 | } | 209 | } |
210 | 210 | ||
211 | ccid3_pr_debug("%s(%p, state=%s) - entry \n", dccp_role(sk), sk, | 211 | ccid3_pr_debug("%s(%p, state=%s) - entry\n", dccp_role(sk), sk, |
212 | ccid3_tx_state_name(hc->tx_state)); | 212 | ccid3_tx_state_name(hc->tx_state)); |
213 | 213 | ||
214 | if (hc->tx_state == TFRC_SSTATE_FBACK) | 214 | if (hc->tx_state == TFRC_SSTATE_FBACK) |
diff --git a/net/dccp/dccp.h b/net/dccp/dccp.h index 5ef32c2f0d6a..a10a61a1ded2 100644 --- a/net/dccp/dccp.h +++ b/net/dccp/dccp.h | |||
@@ -189,7 +189,7 @@ enum { | |||
189 | #define DCCP_MIB_MAX __DCCP_MIB_MAX | 189 | #define DCCP_MIB_MAX __DCCP_MIB_MAX |
190 | struct dccp_mib { | 190 | struct dccp_mib { |
191 | unsigned long mibs[DCCP_MIB_MAX]; | 191 | unsigned long mibs[DCCP_MIB_MAX]; |
192 | } __SNMP_MIB_ALIGN__; | 192 | }; |
193 | 193 | ||
194 | DECLARE_SNMP_STAT(struct dccp_mib, dccp_statistics); | 194 | DECLARE_SNMP_STAT(struct dccp_mib, dccp_statistics); |
195 | #define DCCP_INC_STATS(field) SNMP_INC_STATS(dccp_statistics, field) | 195 | #define DCCP_INC_STATS(field) SNMP_INC_STATS(dccp_statistics, field) |
@@ -223,7 +223,7 @@ static inline void dccp_csum_outgoing(struct sk_buff *skb) | |||
223 | skb->csum = skb_checksum(skb, 0, (cov > skb->len)? skb->len : cov, 0); | 223 | skb->csum = skb_checksum(skb, 0, (cov > skb->len)? skb->len : cov, 0); |
224 | } | 224 | } |
225 | 225 | ||
226 | extern void dccp_v4_send_check(struct sock *sk, int len, struct sk_buff *skb); | 226 | extern void dccp_v4_send_check(struct sock *sk, struct sk_buff *skb); |
227 | 227 | ||
228 | extern int dccp_retransmit_skb(struct sock *sk); | 228 | extern int dccp_retransmit_skb(struct sock *sk); |
229 | 229 | ||
diff --git a/net/dccp/feat.c b/net/dccp/feat.c index 972b8dc918d6..df7dd26cf07e 100644 --- a/net/dccp/feat.c +++ b/net/dccp/feat.c | |||
@@ -22,6 +22,7 @@ | |||
22 | * 2 of the License, or (at your option) any later version. | 22 | * 2 of the License, or (at your option) any later version. |
23 | */ | 23 | */ |
24 | #include <linux/module.h> | 24 | #include <linux/module.h> |
25 | #include <linux/slab.h> | ||
25 | #include "ccid.h" | 26 | #include "ccid.h" |
26 | #include "feat.h" | 27 | #include "feat.h" |
27 | 28 | ||
diff --git a/net/dccp/input.c b/net/dccp/input.c index 7648f316310f..58f7bc156850 100644 --- a/net/dccp/input.c +++ b/net/dccp/input.c | |||
@@ -12,6 +12,7 @@ | |||
12 | 12 | ||
13 | #include <linux/dccp.h> | 13 | #include <linux/dccp.h> |
14 | #include <linux/skbuff.h> | 14 | #include <linux/skbuff.h> |
15 | #include <linux/slab.h> | ||
15 | 16 | ||
16 | #include <net/sock.h> | 17 | #include <net/sock.h> |
17 | 18 | ||
@@ -414,7 +415,7 @@ static int dccp_rcv_request_sent_state_process(struct sock *sk, | |||
414 | if (!between48(DCCP_SKB_CB(skb)->dccpd_ack_seq, | 415 | if (!between48(DCCP_SKB_CB(skb)->dccpd_ack_seq, |
415 | dp->dccps_awl, dp->dccps_awh)) { | 416 | dp->dccps_awl, dp->dccps_awh)) { |
416 | dccp_pr_debug("invalid ackno: S.AWL=%llu, " | 417 | dccp_pr_debug("invalid ackno: S.AWL=%llu, " |
417 | "P.ackno=%llu, S.AWH=%llu \n", | 418 | "P.ackno=%llu, S.AWH=%llu\n", |
418 | (unsigned long long)dp->dccps_awl, | 419 | (unsigned long long)dp->dccps_awl, |
419 | (unsigned long long)DCCP_SKB_CB(skb)->dccpd_ack_seq, | 420 | (unsigned long long)DCCP_SKB_CB(skb)->dccpd_ack_seq, |
420 | (unsigned long long)dp->dccps_awh); | 421 | (unsigned long long)dp->dccps_awh); |
diff --git a/net/dccp/ipv4.c b/net/dccp/ipv4.c index b195c4feaa0a..d9b11ef8694c 100644 --- a/net/dccp/ipv4.c +++ b/net/dccp/ipv4.c | |||
@@ -12,6 +12,7 @@ | |||
12 | 12 | ||
13 | #include <linux/dccp.h> | 13 | #include <linux/dccp.h> |
14 | #include <linux/icmp.h> | 14 | #include <linux/icmp.h> |
15 | #include <linux/slab.h> | ||
15 | #include <linux/module.h> | 16 | #include <linux/module.h> |
16 | #include <linux/skbuff.h> | 17 | #include <linux/skbuff.h> |
17 | #include <linux/random.h> | 18 | #include <linux/random.h> |
@@ -348,7 +349,7 @@ static inline __sum16 dccp_v4_csum_finish(struct sk_buff *skb, | |||
348 | return csum_tcpudp_magic(src, dst, skb->len, IPPROTO_DCCP, skb->csum); | 349 | return csum_tcpudp_magic(src, dst, skb->len, IPPROTO_DCCP, skb->csum); |
349 | } | 350 | } |
350 | 351 | ||
351 | void dccp_v4_send_check(struct sock *sk, int unused, struct sk_buff *skb) | 352 | void dccp_v4_send_check(struct sock *sk, struct sk_buff *skb) |
352 | { | 353 | { |
353 | const struct inet_sock *inet = inet_sk(sk); | 354 | const struct inet_sock *inet = inet_sk(sk); |
354 | struct dccp_hdr *dh = dccp_hdr(skb); | 355 | struct dccp_hdr *dh = dccp_hdr(skb); |
@@ -998,11 +999,11 @@ static struct inet_protosw dccp_v4_protosw = { | |||
998 | 999 | ||
999 | static int __net_init dccp_v4_init_net(struct net *net) | 1000 | static int __net_init dccp_v4_init_net(struct net *net) |
1000 | { | 1001 | { |
1001 | int err; | 1002 | if (dccp_hashinfo.bhash == NULL) |
1003 | return -ESOCKTNOSUPPORT; | ||
1002 | 1004 | ||
1003 | err = inet_ctl_sock_create(&net->dccp.v4_ctl_sk, PF_INET, | 1005 | return inet_ctl_sock_create(&net->dccp.v4_ctl_sk, PF_INET, |
1004 | SOCK_DCCP, IPPROTO_DCCP, net); | 1006 | SOCK_DCCP, IPPROTO_DCCP, net); |
1005 | return err; | ||
1006 | } | 1007 | } |
1007 | 1008 | ||
1008 | static void __net_exit dccp_v4_exit_net(struct net *net) | 1009 | static void __net_exit dccp_v4_exit_net(struct net *net) |
diff --git a/net/dccp/ipv6.c b/net/dccp/ipv6.c index 1aec6349e858..ab1ab95946df 100644 --- a/net/dccp/ipv6.c +++ b/net/dccp/ipv6.c | |||
@@ -14,6 +14,7 @@ | |||
14 | 14 | ||
15 | #include <linux/module.h> | 15 | #include <linux/module.h> |
16 | #include <linux/random.h> | 16 | #include <linux/random.h> |
17 | #include <linux/slab.h> | ||
17 | #include <linux/xfrm.h> | 18 | #include <linux/xfrm.h> |
18 | 19 | ||
19 | #include <net/addrconf.h> | 20 | #include <net/addrconf.h> |
@@ -59,8 +60,7 @@ static inline __sum16 dccp_v6_csum_finish(struct sk_buff *skb, | |||
59 | return csum_ipv6_magic(saddr, daddr, skb->len, IPPROTO_DCCP, skb->csum); | 60 | return csum_ipv6_magic(saddr, daddr, skb->len, IPPROTO_DCCP, skb->csum); |
60 | } | 61 | } |
61 | 62 | ||
62 | static inline void dccp_v6_send_check(struct sock *sk, int unused_value, | 63 | static inline void dccp_v6_send_check(struct sock *sk, struct sk_buff *skb) |
63 | struct sk_buff *skb) | ||
64 | { | 64 | { |
65 | struct ipv6_pinfo *np = inet6_sk(sk); | 65 | struct ipv6_pinfo *np = inet6_sk(sk); |
66 | struct dccp_hdr *dh = dccp_hdr(skb); | 66 | struct dccp_hdr *dh = dccp_hdr(skb); |
@@ -1191,11 +1191,11 @@ static struct inet_protosw dccp_v6_protosw = { | |||
1191 | 1191 | ||
1192 | static int __net_init dccp_v6_init_net(struct net *net) | 1192 | static int __net_init dccp_v6_init_net(struct net *net) |
1193 | { | 1193 | { |
1194 | int err; | 1194 | if (dccp_hashinfo.bhash == NULL) |
1195 | return -ESOCKTNOSUPPORT; | ||
1195 | 1196 | ||
1196 | err = inet_ctl_sock_create(&net->dccp.v6_ctl_sk, PF_INET6, | 1197 | return inet_ctl_sock_create(&net->dccp.v6_ctl_sk, PF_INET6, |
1197 | SOCK_DCCP, IPPROTO_DCCP, net); | 1198 | SOCK_DCCP, IPPROTO_DCCP, net); |
1198 | return err; | ||
1199 | } | 1199 | } |
1200 | 1200 | ||
1201 | static void __net_exit dccp_v6_exit_net(struct net *net) | 1201 | static void __net_exit dccp_v6_exit_net(struct net *net) |
diff --git a/net/dccp/minisocks.c b/net/dccp/minisocks.c index 0d508c359fa9..128b089d3aef 100644 --- a/net/dccp/minisocks.c +++ b/net/dccp/minisocks.c | |||
@@ -11,6 +11,7 @@ | |||
11 | */ | 11 | */ |
12 | 12 | ||
13 | #include <linux/dccp.h> | 13 | #include <linux/dccp.h> |
14 | #include <linux/gfp.h> | ||
14 | #include <linux/kernel.h> | 15 | #include <linux/kernel.h> |
15 | #include <linux/skbuff.h> | 16 | #include <linux/skbuff.h> |
16 | #include <linux/timer.h> | 17 | #include <linux/timer.h> |
diff --git a/net/dccp/output.c b/net/dccp/output.c index d6bb753bf6ad..b8d98e3c052a 100644 --- a/net/dccp/output.c +++ b/net/dccp/output.c | |||
@@ -13,6 +13,7 @@ | |||
13 | #include <linux/dccp.h> | 13 | #include <linux/dccp.h> |
14 | #include <linux/kernel.h> | 14 | #include <linux/kernel.h> |
15 | #include <linux/skbuff.h> | 15 | #include <linux/skbuff.h> |
16 | #include <linux/slab.h> | ||
16 | 17 | ||
17 | #include <net/inet_sock.h> | 18 | #include <net/inet_sock.h> |
18 | #include <net/sock.h> | 19 | #include <net/sock.h> |
@@ -128,7 +129,7 @@ static int dccp_transmit_skb(struct sock *sk, struct sk_buff *skb) | |||
128 | break; | 129 | break; |
129 | } | 130 | } |
130 | 131 | ||
131 | icsk->icsk_af_ops->send_check(sk, 0, skb); | 132 | icsk->icsk_af_ops->send_check(sk, skb); |
132 | 133 | ||
133 | if (set_ack) | 134 | if (set_ack) |
134 | dccp_event_ack_sent(sk); | 135 | dccp_event_ack_sent(sk); |
diff --git a/net/dccp/probe.c b/net/dccp/probe.c index f5b3464f1242..078e48d442fd 100644 --- a/net/dccp/probe.c +++ b/net/dccp/probe.c | |||
@@ -30,6 +30,7 @@ | |||
30 | #include <linux/module.h> | 30 | #include <linux/module.h> |
31 | #include <linux/kfifo.h> | 31 | #include <linux/kfifo.h> |
32 | #include <linux/vmalloc.h> | 32 | #include <linux/vmalloc.h> |
33 | #include <linux/gfp.h> | ||
33 | #include <net/net_namespace.h> | 34 | #include <net/net_namespace.h> |
34 | 35 | ||
35 | #include "dccp.h" | 36 | #include "dccp.h" |
diff --git a/net/dccp/proto.c b/net/dccp/proto.c index 0ef7061920c0..a0e38d8018f5 100644 --- a/net/dccp/proto.c +++ b/net/dccp/proto.c | |||
@@ -20,6 +20,7 @@ | |||
20 | #include <linux/if_arp.h> | 20 | #include <linux/if_arp.h> |
21 | #include <linux/init.h> | 21 | #include <linux/init.h> |
22 | #include <linux/random.h> | 22 | #include <linux/random.h> |
23 | #include <linux/slab.h> | ||
23 | #include <net/checksum.h> | 24 | #include <net/checksum.h> |
24 | 25 | ||
25 | #include <net/inet_sock.h> | 26 | #include <net/inet_sock.h> |
@@ -1036,7 +1037,7 @@ static int __init dccp_init(void) | |||
1036 | FIELD_SIZEOF(struct sk_buff, cb)); | 1037 | FIELD_SIZEOF(struct sk_buff, cb)); |
1037 | rc = percpu_counter_init(&dccp_orphan_count, 0); | 1038 | rc = percpu_counter_init(&dccp_orphan_count, 0); |
1038 | if (rc) | 1039 | if (rc) |
1039 | goto out; | 1040 | goto out_fail; |
1040 | rc = -ENOBUFS; | 1041 | rc = -ENOBUFS; |
1041 | inet_hashinfo_init(&dccp_hashinfo); | 1042 | inet_hashinfo_init(&dccp_hashinfo); |
1042 | dccp_hashinfo.bind_bucket_cachep = | 1043 | dccp_hashinfo.bind_bucket_cachep = |
@@ -1125,8 +1126,9 @@ static int __init dccp_init(void) | |||
1125 | goto out_sysctl_exit; | 1126 | goto out_sysctl_exit; |
1126 | 1127 | ||
1127 | dccp_timestamping_init(); | 1128 | dccp_timestamping_init(); |
1128 | out: | 1129 | |
1129 | return rc; | 1130 | return 0; |
1131 | |||
1130 | out_sysctl_exit: | 1132 | out_sysctl_exit: |
1131 | dccp_sysctl_exit(); | 1133 | dccp_sysctl_exit(); |
1132 | out_ackvec_exit: | 1134 | out_ackvec_exit: |
@@ -1135,18 +1137,19 @@ out_free_dccp_mib: | |||
1135 | dccp_mib_exit(); | 1137 | dccp_mib_exit(); |
1136 | out_free_dccp_bhash: | 1138 | out_free_dccp_bhash: |
1137 | free_pages((unsigned long)dccp_hashinfo.bhash, bhash_order); | 1139 | free_pages((unsigned long)dccp_hashinfo.bhash, bhash_order); |
1138 | dccp_hashinfo.bhash = NULL; | ||
1139 | out_free_dccp_locks: | 1140 | out_free_dccp_locks: |
1140 | inet_ehash_locks_free(&dccp_hashinfo); | 1141 | inet_ehash_locks_free(&dccp_hashinfo); |
1141 | out_free_dccp_ehash: | 1142 | out_free_dccp_ehash: |
1142 | free_pages((unsigned long)dccp_hashinfo.ehash, ehash_order); | 1143 | free_pages((unsigned long)dccp_hashinfo.ehash, ehash_order); |
1143 | dccp_hashinfo.ehash = NULL; | ||
1144 | out_free_bind_bucket_cachep: | 1144 | out_free_bind_bucket_cachep: |
1145 | kmem_cache_destroy(dccp_hashinfo.bind_bucket_cachep); | 1145 | kmem_cache_destroy(dccp_hashinfo.bind_bucket_cachep); |
1146 | dccp_hashinfo.bind_bucket_cachep = NULL; | ||
1147 | out_free_percpu: | 1146 | out_free_percpu: |
1148 | percpu_counter_destroy(&dccp_orphan_count); | 1147 | percpu_counter_destroy(&dccp_orphan_count); |
1149 | goto out; | 1148 | out_fail: |
1149 | dccp_hashinfo.bhash = NULL; | ||
1150 | dccp_hashinfo.ehash = NULL; | ||
1151 | dccp_hashinfo.bind_bucket_cachep = NULL; | ||
1152 | return rc; | ||
1150 | } | 1153 | } |
1151 | 1154 | ||
1152 | static void __exit dccp_fini(void) | 1155 | static void __exit dccp_fini(void) |
diff --git a/net/dccp/timer.c b/net/dccp/timer.c index bbfeb5eae46a..1a9aa05d4dc4 100644 --- a/net/dccp/timer.c +++ b/net/dccp/timer.c | |||
@@ -38,7 +38,7 @@ static int dccp_write_timeout(struct sock *sk) | |||
38 | 38 | ||
39 | if (sk->sk_state == DCCP_REQUESTING || sk->sk_state == DCCP_PARTOPEN) { | 39 | if (sk->sk_state == DCCP_REQUESTING || sk->sk_state == DCCP_PARTOPEN) { |
40 | if (icsk->icsk_retransmits != 0) | 40 | if (icsk->icsk_retransmits != 0) |
41 | dst_negative_advice(&sk->sk_dst_cache, sk); | 41 | dst_negative_advice(sk); |
42 | retry_until = icsk->icsk_syn_retries ? | 42 | retry_until = icsk->icsk_syn_retries ? |
43 | : sysctl_dccp_request_retries; | 43 | : sysctl_dccp_request_retries; |
44 | } else { | 44 | } else { |
@@ -63,7 +63,7 @@ static int dccp_write_timeout(struct sock *sk) | |||
63 | Golden words :-). | 63 | Golden words :-). |
64 | */ | 64 | */ |
65 | 65 | ||
66 | dst_negative_advice(&sk->sk_dst_cache, sk); | 66 | dst_negative_advice(sk); |
67 | } | 67 | } |
68 | 68 | ||
69 | retry_until = sysctl_dccp_retries2; | 69 | retry_until = sysctl_dccp_retries2; |
diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c index 2b494fac9468..55e3b6b0061a 100644 --- a/net/decnet/af_decnet.c +++ b/net/decnet/af_decnet.c | |||
@@ -446,7 +446,7 @@ static void dn_destruct(struct sock *sk) | |||
446 | skb_queue_purge(&scp->other_xmit_queue); | 446 | skb_queue_purge(&scp->other_xmit_queue); |
447 | skb_queue_purge(&scp->other_receive_queue); | 447 | skb_queue_purge(&scp->other_receive_queue); |
448 | 448 | ||
449 | dst_release(xchg(&sk->sk_dst_cache, NULL)); | 449 | dst_release(rcu_dereference_check(sk->sk_dst_cache, 1)); |
450 | } | 450 | } |
451 | 451 | ||
452 | static int dn_memory_pressure; | 452 | static int dn_memory_pressure; |
@@ -1105,7 +1105,7 @@ static int dn_accept(struct socket *sock, struct socket *newsock, int flags) | |||
1105 | release_sock(sk); | 1105 | release_sock(sk); |
1106 | 1106 | ||
1107 | dst = skb_dst(skb); | 1107 | dst = skb_dst(skb); |
1108 | dst_release(xchg(&newsk->sk_dst_cache, dst)); | 1108 | sk_dst_set(newsk, dst); |
1109 | skb_dst_set(skb, NULL); | 1109 | skb_dst_set(skb, NULL); |
1110 | 1110 | ||
1111 | DN_SK(newsk)->state = DN_CR; | 1111 | DN_SK(newsk)->state = DN_CR; |
@@ -1956,7 +1956,7 @@ static int dn_sendmsg(struct kiocb *iocb, struct socket *sock, | |||
1956 | } | 1956 | } |
1957 | 1957 | ||
1958 | if ((flags & MSG_TRYHARD) && sk->sk_dst_cache) | 1958 | if ((flags & MSG_TRYHARD) && sk->sk_dst_cache) |
1959 | dst_negative_advice(&sk->sk_dst_cache, sk); | 1959 | dst_negative_advice(sk); |
1960 | 1960 | ||
1961 | mss = scp->segsize_rem; | 1961 | mss = scp->segsize_rem; |
1962 | fctype = scp->services_rem & NSP_FC_MASK; | 1962 | fctype = scp->services_rem & NSP_FC_MASK; |
diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c index 238af093495b..615dbe3b43f9 100644 --- a/net/decnet/dn_dev.c +++ b/net/decnet/dn_dev.c | |||
@@ -40,6 +40,7 @@ | |||
40 | #include <linux/skbuff.h> | 40 | #include <linux/skbuff.h> |
41 | #include <linux/sysctl.h> | 41 | #include <linux/sysctl.h> |
42 | #include <linux/notifier.h> | 42 | #include <linux/notifier.h> |
43 | #include <linux/slab.h> | ||
43 | #include <asm/uaccess.h> | 44 | #include <asm/uaccess.h> |
44 | #include <asm/system.h> | 45 | #include <asm/system.h> |
45 | #include <net/net_namespace.h> | 46 | #include <net/net_namespace.h> |
@@ -349,7 +350,7 @@ static void dn_dev_del_ifa(struct dn_dev *dn_db, struct dn_ifaddr **ifap, int de | |||
349 | if (dn_db->dev->type == ARPHRD_ETHER) { | 350 | if (dn_db->dev->type == ARPHRD_ETHER) { |
350 | if (ifa1->ifa_local != dn_eth2dn(dev->dev_addr)) { | 351 | if (ifa1->ifa_local != dn_eth2dn(dev->dev_addr)) { |
351 | dn_dn2eth(mac_addr, ifa1->ifa_local); | 352 | dn_dn2eth(mac_addr, ifa1->ifa_local); |
352 | dev_mc_delete(dev, mac_addr, ETH_ALEN, 0); | 353 | dev_mc_del(dev, mac_addr); |
353 | } | 354 | } |
354 | } | 355 | } |
355 | 356 | ||
@@ -380,7 +381,7 @@ static int dn_dev_insert_ifa(struct dn_dev *dn_db, struct dn_ifaddr *ifa) | |||
380 | if (dev->type == ARPHRD_ETHER) { | 381 | if (dev->type == ARPHRD_ETHER) { |
381 | if (ifa->ifa_local != dn_eth2dn(dev->dev_addr)) { | 382 | if (ifa->ifa_local != dn_eth2dn(dev->dev_addr)) { |
382 | dn_dn2eth(mac_addr, ifa->ifa_local); | 383 | dn_dn2eth(mac_addr, ifa->ifa_local); |
383 | dev_mc_add(dev, mac_addr, ETH_ALEN, 0); | 384 | dev_mc_add(dev, mac_addr); |
384 | } | 385 | } |
385 | } | 386 | } |
386 | 387 | ||
@@ -1000,9 +1001,9 @@ static int dn_eth_up(struct net_device *dev) | |||
1000 | struct dn_dev *dn_db = dev->dn_ptr; | 1001 | struct dn_dev *dn_db = dev->dn_ptr; |
1001 | 1002 | ||
1002 | if (dn_db->parms.forwarding == 0) | 1003 | if (dn_db->parms.forwarding == 0) |
1003 | dev_mc_add(dev, dn_rt_all_end_mcast, ETH_ALEN, 0); | 1004 | dev_mc_add(dev, dn_rt_all_end_mcast); |
1004 | else | 1005 | else |
1005 | dev_mc_add(dev, dn_rt_all_rt_mcast, ETH_ALEN, 0); | 1006 | dev_mc_add(dev, dn_rt_all_rt_mcast); |
1006 | 1007 | ||
1007 | dn_db->use_long = 1; | 1008 | dn_db->use_long = 1; |
1008 | 1009 | ||
@@ -1014,9 +1015,9 @@ static void dn_eth_down(struct net_device *dev) | |||
1014 | struct dn_dev *dn_db = dev->dn_ptr; | 1015 | struct dn_dev *dn_db = dev->dn_ptr; |
1015 | 1016 | ||
1016 | if (dn_db->parms.forwarding == 0) | 1017 | if (dn_db->parms.forwarding == 0) |
1017 | dev_mc_delete(dev, dn_rt_all_end_mcast, ETH_ALEN, 0); | 1018 | dev_mc_del(dev, dn_rt_all_end_mcast); |
1018 | else | 1019 | else |
1019 | dev_mc_delete(dev, dn_rt_all_rt_mcast, ETH_ALEN, 0); | 1020 | dev_mc_del(dev, dn_rt_all_rt_mcast); |
1020 | } | 1021 | } |
1021 | 1022 | ||
1022 | static void dn_dev_set_timer(struct net_device *dev); | 1023 | static void dn_dev_set_timer(struct net_device *dev); |
diff --git a/net/decnet/dn_fib.c b/net/decnet/dn_fib.c index e9d48700e83a..4ab96c15166d 100644 --- a/net/decnet/dn_fib.c +++ b/net/decnet/dn_fib.c | |||
@@ -20,6 +20,7 @@ | |||
20 | #include <linux/string.h> | 20 | #include <linux/string.h> |
21 | #include <linux/net.h> | 21 | #include <linux/net.h> |
22 | #include <linux/socket.h> | 22 | #include <linux/socket.h> |
23 | #include <linux/slab.h> | ||
23 | #include <linux/sockios.h> | 24 | #include <linux/sockios.h> |
24 | #include <linux/init.h> | 25 | #include <linux/init.h> |
25 | #include <linux/skbuff.h> | 26 | #include <linux/skbuff.h> |
diff --git a/net/decnet/dn_neigh.c b/net/decnet/dn_neigh.c index 794b5bf95af1..deb723dba44b 100644 --- a/net/decnet/dn_neigh.c +++ b/net/decnet/dn_neigh.c | |||
@@ -28,6 +28,7 @@ | |||
28 | #include <linux/module.h> | 28 | #include <linux/module.h> |
29 | #include <linux/socket.h> | 29 | #include <linux/socket.h> |
30 | #include <linux/if_arp.h> | 30 | #include <linux/if_arp.h> |
31 | #include <linux/slab.h> | ||
31 | #include <linux/if_ether.h> | 32 | #include <linux/if_ether.h> |
32 | #include <linux/init.h> | 33 | #include <linux/init.h> |
33 | #include <linux/proc_fs.h> | 34 | #include <linux/proc_fs.h> |
diff --git a/net/decnet/dn_nsp_in.c b/net/decnet/dn_nsp_in.c index 932408dca86d..25a37299bc65 100644 --- a/net/decnet/dn_nsp_in.c +++ b/net/decnet/dn_nsp_in.c | |||
@@ -57,6 +57,7 @@ | |||
57 | #include <linux/netdevice.h> | 57 | #include <linux/netdevice.h> |
58 | #include <linux/inet.h> | 58 | #include <linux/inet.h> |
59 | #include <linux/route.h> | 59 | #include <linux/route.h> |
60 | #include <linux/slab.h> | ||
60 | #include <net/sock.h> | 61 | #include <net/sock.h> |
61 | #include <net/tcp_states.h> | 62 | #include <net/tcp_states.h> |
62 | #include <asm/system.h> | 63 | #include <asm/system.h> |
diff --git a/net/decnet/dn_nsp_out.c b/net/decnet/dn_nsp_out.c index a65e929ce76c..baeb1eaf011b 100644 --- a/net/decnet/dn_nsp_out.c +++ b/net/decnet/dn_nsp_out.c | |||
@@ -50,6 +50,7 @@ | |||
50 | #include <linux/netdevice.h> | 50 | #include <linux/netdevice.h> |
51 | #include <linux/inet.h> | 51 | #include <linux/inet.h> |
52 | #include <linux/route.h> | 52 | #include <linux/route.h> |
53 | #include <linux/slab.h> | ||
53 | #include <net/sock.h> | 54 | #include <net/sock.h> |
54 | #include <asm/system.h> | 55 | #include <asm/system.h> |
55 | #include <linux/fcntl.h> | 56 | #include <linux/fcntl.h> |
diff --git a/net/decnet/dn_route.c b/net/decnet/dn_route.c index a7bf03ca0a36..70ebe74027d5 100644 --- a/net/decnet/dn_route.c +++ b/net/decnet/dn_route.c | |||
@@ -66,6 +66,7 @@ | |||
66 | #include <linux/inet.h> | 66 | #include <linux/inet.h> |
67 | #include <linux/route.h> | 67 | #include <linux/route.h> |
68 | #include <linux/in_route.h> | 68 | #include <linux/in_route.h> |
69 | #include <linux/slab.h> | ||
69 | #include <net/sock.h> | 70 | #include <net/sock.h> |
70 | #include <linux/mm.h> | 71 | #include <linux/mm.h> |
71 | #include <linux/proc_fs.h> | 72 | #include <linux/proc_fs.h> |
diff --git a/net/decnet/dn_rules.c b/net/decnet/dn_rules.c index 7466c546f286..af28dcc21844 100644 --- a/net/decnet/dn_rules.c +++ b/net/decnet/dn_rules.c | |||
@@ -196,7 +196,6 @@ static int dn_fib_rule_fill(struct fib_rule *rule, struct sk_buff *skb, | |||
196 | { | 196 | { |
197 | struct dn_fib_rule *r = (struct dn_fib_rule *)rule; | 197 | struct dn_fib_rule *r = (struct dn_fib_rule *)rule; |
198 | 198 | ||
199 | frh->family = AF_DECnet; | ||
200 | frh->dst_len = r->dst_len; | 199 | frh->dst_len = r->dst_len; |
201 | frh->src_len = r->src_len; | 200 | frh->src_len = r->src_len; |
202 | frh->tos = 0; | 201 | frh->tos = 0; |
@@ -212,30 +211,13 @@ nla_put_failure: | |||
212 | return -ENOBUFS; | 211 | return -ENOBUFS; |
213 | } | 212 | } |
214 | 213 | ||
215 | static u32 dn_fib_rule_default_pref(struct fib_rules_ops *ops) | ||
216 | { | ||
217 | struct list_head *pos; | ||
218 | struct fib_rule *rule; | ||
219 | |||
220 | if (!list_empty(&dn_fib_rules_ops->rules_list)) { | ||
221 | pos = dn_fib_rules_ops->rules_list.next; | ||
222 | if (pos->next != &dn_fib_rules_ops->rules_list) { | ||
223 | rule = list_entry(pos->next, struct fib_rule, list); | ||
224 | if (rule->pref) | ||
225 | return rule->pref - 1; | ||
226 | } | ||
227 | } | ||
228 | |||
229 | return 0; | ||
230 | } | ||
231 | |||
232 | static void dn_fib_rule_flush_cache(struct fib_rules_ops *ops) | 214 | static void dn_fib_rule_flush_cache(struct fib_rules_ops *ops) |
233 | { | 215 | { |
234 | dn_rt_cache_flush(-1); | 216 | dn_rt_cache_flush(-1); |
235 | } | 217 | } |
236 | 218 | ||
237 | static struct fib_rules_ops dn_fib_rules_ops_template = { | 219 | static struct fib_rules_ops dn_fib_rules_ops_template = { |
238 | .family = AF_DECnet, | 220 | .family = FIB_RULES_DECNET, |
239 | .rule_size = sizeof(struct dn_fib_rule), | 221 | .rule_size = sizeof(struct dn_fib_rule), |
240 | .addr_size = sizeof(u16), | 222 | .addr_size = sizeof(u16), |
241 | .action = dn_fib_rule_action, | 223 | .action = dn_fib_rule_action, |
@@ -243,7 +225,7 @@ static struct fib_rules_ops dn_fib_rules_ops_template = { | |||
243 | .configure = dn_fib_rule_configure, | 225 | .configure = dn_fib_rule_configure, |
244 | .compare = dn_fib_rule_compare, | 226 | .compare = dn_fib_rule_compare, |
245 | .fill = dn_fib_rule_fill, | 227 | .fill = dn_fib_rule_fill, |
246 | .default_pref = dn_fib_rule_default_pref, | 228 | .default_pref = fib_default_rule_pref, |
247 | .flush_cache = dn_fib_rule_flush_cache, | 229 | .flush_cache = dn_fib_rule_flush_cache, |
248 | .nlgroup = RTNLGRP_DECnet_RULE, | 230 | .nlgroup = RTNLGRP_DECnet_RULE, |
249 | .policy = dn_fib_rule_policy, | 231 | .policy = dn_fib_rule_policy, |
diff --git a/net/decnet/dn_table.c b/net/decnet/dn_table.c index b9a33bb5e9cc..f2abd3755690 100644 --- a/net/decnet/dn_table.c +++ b/net/decnet/dn_table.c | |||
@@ -15,6 +15,7 @@ | |||
15 | #include <linux/string.h> | 15 | #include <linux/string.h> |
16 | #include <linux/net.h> | 16 | #include <linux/net.h> |
17 | #include <linux/socket.h> | 17 | #include <linux/socket.h> |
18 | #include <linux/slab.h> | ||
18 | #include <linux/sockios.h> | 19 | #include <linux/sockios.h> |
19 | #include <linux/init.h> | 20 | #include <linux/init.h> |
20 | #include <linux/skbuff.h> | 21 | #include <linux/skbuff.h> |
diff --git a/net/decnet/netfilter/dn_rtmsg.c b/net/decnet/netfilter/dn_rtmsg.c index 6d2bd3202048..64a7f39e069f 100644 --- a/net/decnet/netfilter/dn_rtmsg.c +++ b/net/decnet/netfilter/dn_rtmsg.c | |||
@@ -14,6 +14,7 @@ | |||
14 | */ | 14 | */ |
15 | #include <linux/module.h> | 15 | #include <linux/module.h> |
16 | #include <linux/skbuff.h> | 16 | #include <linux/skbuff.h> |
17 | #include <linux/slab.h> | ||
17 | #include <linux/init.h> | 18 | #include <linux/init.h> |
18 | #include <linux/netdevice.h> | 19 | #include <linux/netdevice.h> |
19 | #include <linux/netfilter.h> | 20 | #include <linux/netfilter.h> |
diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c index 71489f69a42c..6112a12578b2 100644 --- a/net/dsa/dsa.c +++ b/net/dsa/dsa.c | |||
@@ -11,6 +11,7 @@ | |||
11 | #include <linux/list.h> | 11 | #include <linux/list.h> |
12 | #include <linux/netdevice.h> | 12 | #include <linux/netdevice.h> |
13 | #include <linux/platform_device.h> | 13 | #include <linux/platform_device.h> |
14 | #include <linux/slab.h> | ||
14 | #include <net/dsa.h> | 15 | #include <net/dsa.h> |
15 | #include "dsa_priv.h" | 16 | #include "dsa_priv.h" |
16 | 17 | ||
diff --git a/net/dsa/slave.c b/net/dsa/slave.c index 2175e6d5cc8d..8fdca56bb08f 100644 --- a/net/dsa/slave.c +++ b/net/dsa/slave.c | |||
@@ -67,7 +67,7 @@ static int dsa_slave_open(struct net_device *dev) | |||
67 | return -ENETDOWN; | 67 | return -ENETDOWN; |
68 | 68 | ||
69 | if (compare_ether_addr(dev->dev_addr, master->dev_addr)) { | 69 | if (compare_ether_addr(dev->dev_addr, master->dev_addr)) { |
70 | err = dev_unicast_add(master, dev->dev_addr); | 70 | err = dev_uc_add(master, dev->dev_addr); |
71 | if (err < 0) | 71 | if (err < 0) |
72 | goto out; | 72 | goto out; |
73 | } | 73 | } |
@@ -90,7 +90,7 @@ clear_allmulti: | |||
90 | dev_set_allmulti(master, -1); | 90 | dev_set_allmulti(master, -1); |
91 | del_unicast: | 91 | del_unicast: |
92 | if (compare_ether_addr(dev->dev_addr, master->dev_addr)) | 92 | if (compare_ether_addr(dev->dev_addr, master->dev_addr)) |
93 | dev_unicast_delete(master, dev->dev_addr); | 93 | dev_uc_del(master, dev->dev_addr); |
94 | out: | 94 | out: |
95 | return err; | 95 | return err; |
96 | } | 96 | } |
@@ -101,14 +101,14 @@ static int dsa_slave_close(struct net_device *dev) | |||
101 | struct net_device *master = p->parent->dst->master_netdev; | 101 | struct net_device *master = p->parent->dst->master_netdev; |
102 | 102 | ||
103 | dev_mc_unsync(master, dev); | 103 | dev_mc_unsync(master, dev); |
104 | dev_unicast_unsync(master, dev); | 104 | dev_uc_unsync(master, dev); |
105 | if (dev->flags & IFF_ALLMULTI) | 105 | if (dev->flags & IFF_ALLMULTI) |
106 | dev_set_allmulti(master, -1); | 106 | dev_set_allmulti(master, -1); |
107 | if (dev->flags & IFF_PROMISC) | 107 | if (dev->flags & IFF_PROMISC) |
108 | dev_set_promiscuity(master, -1); | 108 | dev_set_promiscuity(master, -1); |
109 | 109 | ||
110 | if (compare_ether_addr(dev->dev_addr, master->dev_addr)) | 110 | if (compare_ether_addr(dev->dev_addr, master->dev_addr)) |
111 | dev_unicast_delete(master, dev->dev_addr); | 111 | dev_uc_del(master, dev->dev_addr); |
112 | 112 | ||
113 | return 0; | 113 | return 0; |
114 | } | 114 | } |
@@ -130,7 +130,7 @@ static void dsa_slave_set_rx_mode(struct net_device *dev) | |||
130 | struct net_device *master = p->parent->dst->master_netdev; | 130 | struct net_device *master = p->parent->dst->master_netdev; |
131 | 131 | ||
132 | dev_mc_sync(master, dev); | 132 | dev_mc_sync(master, dev); |
133 | dev_unicast_sync(master, dev); | 133 | dev_uc_sync(master, dev); |
134 | } | 134 | } |
135 | 135 | ||
136 | static int dsa_slave_set_mac_address(struct net_device *dev, void *a) | 136 | static int dsa_slave_set_mac_address(struct net_device *dev, void *a) |
@@ -147,13 +147,13 @@ static int dsa_slave_set_mac_address(struct net_device *dev, void *a) | |||
147 | goto out; | 147 | goto out; |
148 | 148 | ||
149 | if (compare_ether_addr(addr->sa_data, master->dev_addr)) { | 149 | if (compare_ether_addr(addr->sa_data, master->dev_addr)) { |
150 | err = dev_unicast_add(master, addr->sa_data); | 150 | err = dev_uc_add(master, addr->sa_data); |
151 | if (err < 0) | 151 | if (err < 0) |
152 | return err; | 152 | return err; |
153 | } | 153 | } |
154 | 154 | ||
155 | if (compare_ether_addr(dev->dev_addr, master->dev_addr)) | 155 | if (compare_ether_addr(dev->dev_addr, master->dev_addr)) |
156 | dev_unicast_delete(master, dev->dev_addr); | 156 | dev_uc_del(master, dev->dev_addr); |
157 | 157 | ||
158 | out: | 158 | out: |
159 | memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN); | 159 | memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN); |
diff --git a/net/dsa/tag_dsa.c b/net/dsa/tag_dsa.c index cdf2d28a0297..98dfe80b4538 100644 --- a/net/dsa/tag_dsa.c +++ b/net/dsa/tag_dsa.c | |||
@@ -11,6 +11,7 @@ | |||
11 | #include <linux/etherdevice.h> | 11 | #include <linux/etherdevice.h> |
12 | #include <linux/list.h> | 12 | #include <linux/list.h> |
13 | #include <linux/netdevice.h> | 13 | #include <linux/netdevice.h> |
14 | #include <linux/slab.h> | ||
14 | #include "dsa_priv.h" | 15 | #include "dsa_priv.h" |
15 | 16 | ||
16 | #define DSA_HLEN 4 | 17 | #define DSA_HLEN 4 |
diff --git a/net/dsa/tag_edsa.c b/net/dsa/tag_edsa.c index 8f53948cff4f..6f383322ad25 100644 --- a/net/dsa/tag_edsa.c +++ b/net/dsa/tag_edsa.c | |||
@@ -11,6 +11,7 @@ | |||
11 | #include <linux/etherdevice.h> | 11 | #include <linux/etherdevice.h> |
12 | #include <linux/list.h> | 12 | #include <linux/list.h> |
13 | #include <linux/netdevice.h> | 13 | #include <linux/netdevice.h> |
14 | #include <linux/slab.h> | ||
14 | #include "dsa_priv.h" | 15 | #include "dsa_priv.h" |
15 | 16 | ||
16 | #define DSA_HLEN 4 | 17 | #define DSA_HLEN 4 |
diff --git a/net/dsa/tag_trailer.c b/net/dsa/tag_trailer.c index a85c829853c0..d6d7d0add3cb 100644 --- a/net/dsa/tag_trailer.c +++ b/net/dsa/tag_trailer.c | |||
@@ -11,6 +11,7 @@ | |||
11 | #include <linux/etherdevice.h> | 11 | #include <linux/etherdevice.h> |
12 | #include <linux/list.h> | 12 | #include <linux/list.h> |
13 | #include <linux/netdevice.h> | 13 | #include <linux/netdevice.h> |
14 | #include <linux/slab.h> | ||
14 | #include "dsa_priv.h" | 15 | #include "dsa_priv.h" |
15 | 16 | ||
16 | netdev_tx_t trailer_xmit(struct sk_buff *skb, struct net_device *dev) | 17 | netdev_tx_t trailer_xmit(struct sk_buff *skb, struct net_device *dev) |
diff --git a/net/econet/af_econet.c b/net/econet/af_econet.c index 29b4931aae52..2a5a8053e000 100644 --- a/net/econet/af_econet.c +++ b/net/econet/af_econet.c | |||
@@ -30,6 +30,7 @@ | |||
30 | #include <linux/wireless.h> | 30 | #include <linux/wireless.h> |
31 | #include <linux/skbuff.h> | 31 | #include <linux/skbuff.h> |
32 | #include <linux/udp.h> | 32 | #include <linux/udp.h> |
33 | #include <linux/slab.h> | ||
33 | #include <net/sock.h> | 34 | #include <net/sock.h> |
34 | #include <net/inet_common.h> | 35 | #include <net/inet_common.h> |
35 | #include <linux/stat.h> | 36 | #include <linux/stat.h> |
diff --git a/net/ethernet/pe2.c b/net/ethernet/pe2.c index d60e15d9365e..eb00796758c3 100644 --- a/net/ethernet/pe2.c +++ b/net/ethernet/pe2.c | |||
@@ -3,6 +3,7 @@ | |||
3 | #include <linux/module.h> | 3 | #include <linux/module.h> |
4 | #include <linux/netdevice.h> | 4 | #include <linux/netdevice.h> |
5 | #include <linux/skbuff.h> | 5 | #include <linux/skbuff.h> |
6 | #include <linux/slab.h> | ||
6 | 7 | ||
7 | #include <net/datalink.h> | 8 | #include <net/datalink.h> |
8 | 9 | ||
diff --git a/net/ieee802154/af_ieee802154.c b/net/ieee802154/af_ieee802154.c index bad1c49fd960..c7da600750bb 100644 --- a/net/ieee802154/af_ieee802154.c +++ b/net/ieee802154/af_ieee802154.c | |||
@@ -28,6 +28,7 @@ | |||
28 | #include <linux/if.h> | 28 | #include <linux/if.h> |
29 | #include <linux/termios.h> /* For TIOCOUTQ/INQ */ | 29 | #include <linux/termios.h> /* For TIOCOUTQ/INQ */ |
30 | #include <linux/list.h> | 30 | #include <linux/list.h> |
31 | #include <linux/slab.h> | ||
31 | #include <net/datalink.h> | 32 | #include <net/datalink.h> |
32 | #include <net/psnap.h> | 33 | #include <net/psnap.h> |
33 | #include <net/sock.h> | 34 | #include <net/sock.h> |
@@ -126,6 +127,9 @@ static int ieee802154_sock_connect(struct socket *sock, struct sockaddr *uaddr, | |||
126 | { | 127 | { |
127 | struct sock *sk = sock->sk; | 128 | struct sock *sk = sock->sk; |
128 | 129 | ||
130 | if (addr_len < sizeof(uaddr->sa_family)) | ||
131 | return -EINVAL; | ||
132 | |||
129 | if (uaddr->sa_family == AF_UNSPEC) | 133 | if (uaddr->sa_family == AF_UNSPEC) |
130 | return sk->sk_prot->disconnect(sk, flags); | 134 | return sk->sk_prot->disconnect(sk, flags); |
131 | 135 | ||
diff --git a/net/ieee802154/dgram.c b/net/ieee802154/dgram.c index 9aac5aee1575..1a3334c2609a 100644 --- a/net/ieee802154/dgram.c +++ b/net/ieee802154/dgram.c | |||
@@ -25,6 +25,7 @@ | |||
25 | #include <linux/module.h> | 25 | #include <linux/module.h> |
26 | #include <linux/if_arp.h> | 26 | #include <linux/if_arp.h> |
27 | #include <linux/list.h> | 27 | #include <linux/list.h> |
28 | #include <linux/slab.h> | ||
28 | #include <net/sock.h> | 29 | #include <net/sock.h> |
29 | #include <net/af_ieee802154.h> | 30 | #include <net/af_ieee802154.h> |
30 | #include <net/ieee802154.h> | 31 | #include <net/ieee802154.h> |
diff --git a/net/ieee802154/netlink.c b/net/ieee802154/netlink.c index 33137b99e471..c8097ae2482f 100644 --- a/net/ieee802154/netlink.c +++ b/net/ieee802154/netlink.c | |||
@@ -23,6 +23,7 @@ | |||
23 | */ | 23 | */ |
24 | 24 | ||
25 | #include <linux/kernel.h> | 25 | #include <linux/kernel.h> |
26 | #include <linux/gfp.h> | ||
26 | #include <net/genetlink.h> | 27 | #include <net/genetlink.h> |
27 | #include <linux/nl802154.h> | 28 | #include <linux/nl802154.h> |
28 | 29 | ||
diff --git a/net/ieee802154/nl-mac.c b/net/ieee802154/nl-mac.c index 135c1678fb11..71ee1108d4f8 100644 --- a/net/ieee802154/nl-mac.c +++ b/net/ieee802154/nl-mac.c | |||
@@ -22,6 +22,7 @@ | |||
22 | * Maxim Osipov <maxim.osipov@siemens.com> | 22 | * Maxim Osipov <maxim.osipov@siemens.com> |
23 | */ | 23 | */ |
24 | 24 | ||
25 | #include <linux/gfp.h> | ||
25 | #include <linux/kernel.h> | 26 | #include <linux/kernel.h> |
26 | #include <linux/if_arp.h> | 27 | #include <linux/if_arp.h> |
27 | #include <linux/netdevice.h> | 28 | #include <linux/netdevice.h> |
diff --git a/net/ieee802154/nl-phy.c b/net/ieee802154/nl-phy.c index 199a2d9d12f9..ed0eab39f531 100644 --- a/net/ieee802154/nl-phy.c +++ b/net/ieee802154/nl-phy.c | |||
@@ -23,6 +23,7 @@ | |||
23 | */ | 23 | */ |
24 | 24 | ||
25 | #include <linux/kernel.h> | 25 | #include <linux/kernel.h> |
26 | #include <linux/slab.h> | ||
26 | #include <net/netlink.h> | 27 | #include <net/netlink.h> |
27 | #include <net/genetlink.h> | 28 | #include <net/genetlink.h> |
28 | #include <net/wpan-phy.h> | 29 | #include <net/wpan-phy.h> |
diff --git a/net/ieee802154/raw.c b/net/ieee802154/raw.c index 9c9b85c00033..10970ca85748 100644 --- a/net/ieee802154/raw.c +++ b/net/ieee802154/raw.c | |||
@@ -25,6 +25,7 @@ | |||
25 | #include <linux/module.h> | 25 | #include <linux/module.h> |
26 | #include <linux/if_arp.h> | 26 | #include <linux/if_arp.h> |
27 | #include <linux/list.h> | 27 | #include <linux/list.h> |
28 | #include <linux/slab.h> | ||
28 | #include <net/sock.h> | 29 | #include <net/sock.h> |
29 | #include <net/af_ieee802154.h> | 30 | #include <net/af_ieee802154.h> |
30 | 31 | ||
diff --git a/net/ieee802154/wpan-class.c b/net/ieee802154/wpan-class.c index 268691256a6d..3d803a1b9fb6 100644 --- a/net/ieee802154/wpan-class.c +++ b/net/ieee802154/wpan-class.c | |||
@@ -16,6 +16,7 @@ | |||
16 | * | 16 | * |
17 | */ | 17 | */ |
18 | 18 | ||
19 | #include <linux/slab.h> | ||
19 | #include <linux/kernel.h> | 20 | #include <linux/kernel.h> |
20 | #include <linux/module.h> | 21 | #include <linux/module.h> |
21 | #include <linux/device.h> | 22 | #include <linux/device.h> |
diff --git a/net/ipv4/Kconfig b/net/ipv4/Kconfig index 0c94a1ac2946..be597749c385 100644 --- a/net/ipv4/Kconfig +++ b/net/ipv4/Kconfig | |||
@@ -250,6 +250,20 @@ config IP_MROUTE | |||
250 | <file:Documentation/networking/multicast.txt>. If you haven't heard | 250 | <file:Documentation/networking/multicast.txt>. If you haven't heard |
251 | about it, you don't need it. | 251 | about it, you don't need it. |
252 | 252 | ||
253 | config IP_MROUTE_MULTIPLE_TABLES | ||
254 | bool "IP: multicast policy routing" | ||
255 | depends on IP_ADVANCED_ROUTER | ||
256 | select FIB_RULES | ||
257 | help | ||
258 | Normally, a multicast router runs a userspace daemon and decides | ||
259 | what to do with a multicast packet based on the source and | ||
260 | destination addresses. If you say Y here, the multicast router | ||
261 | will also be able to take interfaces and packet marks into | ||
262 | account and run multiple instances of userspace daemons | ||
263 | simultaneously, each one handling a single table. | ||
264 | |||
265 | If unsure, say N. | ||
266 | |||
253 | config IP_PIMSM_V1 | 267 | config IP_PIMSM_V1 |
254 | bool "IP: PIM-SM version 1 support" | 268 | bool "IP: PIM-SM version 1 support" |
255 | depends on IP_MROUTE | 269 | depends on IP_MROUTE |
@@ -587,9 +601,15 @@ choice | |||
587 | config DEFAULT_HTCP | 601 | config DEFAULT_HTCP |
588 | bool "Htcp" if TCP_CONG_HTCP=y | 602 | bool "Htcp" if TCP_CONG_HTCP=y |
589 | 603 | ||
604 | config DEFAULT_HYBLA | ||
605 | bool "Hybla" if TCP_CONG_HYBLA=y | ||
606 | |||
590 | config DEFAULT_VEGAS | 607 | config DEFAULT_VEGAS |
591 | bool "Vegas" if TCP_CONG_VEGAS=y | 608 | bool "Vegas" if TCP_CONG_VEGAS=y |
592 | 609 | ||
610 | config DEFAULT_VENO | ||
611 | bool "Veno" if TCP_CONG_VENO=y | ||
612 | |||
593 | config DEFAULT_WESTWOOD | 613 | config DEFAULT_WESTWOOD |
594 | bool "Westwood" if TCP_CONG_WESTWOOD=y | 614 | bool "Westwood" if TCP_CONG_WESTWOOD=y |
595 | 615 | ||
@@ -610,8 +630,10 @@ config DEFAULT_TCP_CONG | |||
610 | default "bic" if DEFAULT_BIC | 630 | default "bic" if DEFAULT_BIC |
611 | default "cubic" if DEFAULT_CUBIC | 631 | default "cubic" if DEFAULT_CUBIC |
612 | default "htcp" if DEFAULT_HTCP | 632 | default "htcp" if DEFAULT_HTCP |
633 | default "hybla" if DEFAULT_HYBLA | ||
613 | default "vegas" if DEFAULT_VEGAS | 634 | default "vegas" if DEFAULT_VEGAS |
614 | default "westwood" if DEFAULT_WESTWOOD | 635 | default "westwood" if DEFAULT_WESTWOOD |
636 | default "veno" if DEFAULT_VENO | ||
615 | default "reno" if DEFAULT_RENO | 637 | default "reno" if DEFAULT_RENO |
616 | default "cubic" | 638 | default "cubic" |
617 | 639 | ||
diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c index 33b7dffa7732..193dcd6ed64f 100644 --- a/net/ipv4/af_inet.c +++ b/net/ipv4/af_inet.c | |||
@@ -86,6 +86,7 @@ | |||
86 | #include <linux/poll.h> | 86 | #include <linux/poll.h> |
87 | #include <linux/netfilter_ipv4.h> | 87 | #include <linux/netfilter_ipv4.h> |
88 | #include <linux/random.h> | 88 | #include <linux/random.h> |
89 | #include <linux/slab.h> | ||
89 | 90 | ||
90 | #include <asm/uaccess.h> | 91 | #include <asm/uaccess.h> |
91 | #include <asm/system.h> | 92 | #include <asm/system.h> |
@@ -153,7 +154,7 @@ void inet_sock_destruct(struct sock *sk) | |||
153 | WARN_ON(sk->sk_forward_alloc); | 154 | WARN_ON(sk->sk_forward_alloc); |
154 | 155 | ||
155 | kfree(inet->opt); | 156 | kfree(inet->opt); |
156 | dst_release(sk->sk_dst_cache); | 157 | dst_release(rcu_dereference_check(sk->sk_dst_cache, 1)); |
157 | sk_refcnt_debug_dec(sk); | 158 | sk_refcnt_debug_dec(sk); |
158 | } | 159 | } |
159 | EXPORT_SYMBOL(inet_sock_destruct); | 160 | EXPORT_SYMBOL(inet_sock_destruct); |
@@ -530,6 +531,8 @@ int inet_dgram_connect(struct socket *sock, struct sockaddr * uaddr, | |||
530 | { | 531 | { |
531 | struct sock *sk = sock->sk; | 532 | struct sock *sk = sock->sk; |
532 | 533 | ||
534 | if (addr_len < sizeof(uaddr->sa_family)) | ||
535 | return -EINVAL; | ||
533 | if (uaddr->sa_family == AF_UNSPEC) | 536 | if (uaddr->sa_family == AF_UNSPEC) |
534 | return sk->sk_prot->disconnect(sk, flags); | 537 | return sk->sk_prot->disconnect(sk, flags); |
535 | 538 | ||
@@ -573,6 +576,9 @@ int inet_stream_connect(struct socket *sock, struct sockaddr *uaddr, | |||
573 | int err; | 576 | int err; |
574 | long timeo; | 577 | long timeo; |
575 | 578 | ||
579 | if (addr_len < sizeof(uaddr->sa_family)) | ||
580 | return -EINVAL; | ||
581 | |||
576 | lock_sock(sk); | 582 | lock_sock(sk); |
577 | 583 | ||
578 | if (uaddr->sa_family == AF_UNSPEC) { | 584 | if (uaddr->sa_family == AF_UNSPEC) { |
@@ -1401,10 +1407,10 @@ EXPORT_SYMBOL_GPL(snmp_fold_field); | |||
1401 | int snmp_mib_init(void __percpu *ptr[2], size_t mibsize) | 1407 | int snmp_mib_init(void __percpu *ptr[2], size_t mibsize) |
1402 | { | 1408 | { |
1403 | BUG_ON(ptr == NULL); | 1409 | BUG_ON(ptr == NULL); |
1404 | ptr[0] = __alloc_percpu(mibsize, __alignof__(unsigned long long)); | 1410 | ptr[0] = __alloc_percpu(mibsize, __alignof__(unsigned long)); |
1405 | if (!ptr[0]) | 1411 | if (!ptr[0]) |
1406 | goto err0; | 1412 | goto err0; |
1407 | ptr[1] = __alloc_percpu(mibsize, __alignof__(unsigned long long)); | 1413 | ptr[1] = __alloc_percpu(mibsize, __alignof__(unsigned long)); |
1408 | if (!ptr[1]) | 1414 | if (!ptr[1]) |
1409 | goto err1; | 1415 | goto err1; |
1410 | return 0; | 1416 | return 0; |
diff --git a/net/ipv4/ah4.c b/net/ipv4/ah4.c index 987b47dc69ad..880a5ec6dce0 100644 --- a/net/ipv4/ah4.c +++ b/net/ipv4/ah4.c | |||
@@ -1,6 +1,7 @@ | |||
1 | #include <crypto/hash.h> | 1 | #include <crypto/hash.h> |
2 | #include <linux/err.h> | 2 | #include <linux/err.h> |
3 | #include <linux/module.h> | 3 | #include <linux/module.h> |
4 | #include <linux/slab.h> | ||
4 | #include <net/ip.h> | 5 | #include <net/ip.h> |
5 | #include <net/xfrm.h> | 6 | #include <net/xfrm.h> |
6 | #include <net/ah.h> | 7 | #include <net/ah.h> |
diff --git a/net/ipv4/arp.c b/net/ipv4/arp.c index c4dd13542802..6e747065c202 100644 --- a/net/ipv4/arp.c +++ b/net/ipv4/arp.c | |||
@@ -98,6 +98,7 @@ | |||
98 | #include <linux/net.h> | 98 | #include <linux/net.h> |
99 | #include <linux/rcupdate.h> | 99 | #include <linux/rcupdate.h> |
100 | #include <linux/jhash.h> | 100 | #include <linux/jhash.h> |
101 | #include <linux/slab.h> | ||
101 | #ifdef CONFIG_SYSCTL | 102 | #ifdef CONFIG_SYSCTL |
102 | #include <linux/sysctl.h> | 103 | #include <linux/sysctl.h> |
103 | #endif | 104 | #endif |
diff --git a/net/ipv4/cipso_ipv4.c b/net/ipv4/cipso_ipv4.c index 1e029dc75455..c97cd9ff697e 100644 --- a/net/ipv4/cipso_ipv4.c +++ b/net/ipv4/cipso_ipv4.c | |||
@@ -44,6 +44,7 @@ | |||
44 | #include <linux/string.h> | 44 | #include <linux/string.h> |
45 | #include <linux/jhash.h> | 45 | #include <linux/jhash.h> |
46 | #include <linux/audit.h> | 46 | #include <linux/audit.h> |
47 | #include <linux/slab.h> | ||
47 | #include <net/ip.h> | 48 | #include <net/ip.h> |
48 | #include <net/icmp.h> | 49 | #include <net/icmp.h> |
49 | #include <net/tcp.h> | 50 | #include <net/tcp.h> |
diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c index 51ca946e3392..382bc768ed56 100644 --- a/net/ipv4/devinet.c +++ b/net/ipv4/devinet.c | |||
@@ -50,6 +50,7 @@ | |||
50 | #include <linux/notifier.h> | 50 | #include <linux/notifier.h> |
51 | #include <linux/inetdevice.h> | 51 | #include <linux/inetdevice.h> |
52 | #include <linux/igmp.h> | 52 | #include <linux/igmp.h> |
53 | #include <linux/slab.h> | ||
53 | #ifdef CONFIG_SYSCTL | 54 | #ifdef CONFIG_SYSCTL |
54 | #include <linux/sysctl.h> | 55 | #include <linux/sysctl.h> |
55 | #endif | 56 | #endif |
@@ -1095,10 +1096,10 @@ static int inetdev_event(struct notifier_block *this, unsigned long event, | |||
1095 | case NETDEV_DOWN: | 1096 | case NETDEV_DOWN: |
1096 | ip_mc_down(in_dev); | 1097 | ip_mc_down(in_dev); |
1097 | break; | 1098 | break; |
1098 | case NETDEV_BONDING_OLDTYPE: | 1099 | case NETDEV_PRE_TYPE_CHANGE: |
1099 | ip_mc_unmap(in_dev); | 1100 | ip_mc_unmap(in_dev); |
1100 | break; | 1101 | break; |
1101 | case NETDEV_BONDING_NEWTYPE: | 1102 | case NETDEV_POST_TYPE_CHANGE: |
1102 | ip_mc_remap(in_dev); | 1103 | ip_mc_remap(in_dev); |
1103 | break; | 1104 | break; |
1104 | case NETDEV_CHANGEMTU: | 1105 | case NETDEV_CHANGEMTU: |
@@ -1194,7 +1195,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb) | |||
1194 | hlist_for_each_entry_rcu(dev, node, head, index_hlist) { | 1195 | hlist_for_each_entry_rcu(dev, node, head, index_hlist) { |
1195 | if (idx < s_idx) | 1196 | if (idx < s_idx) |
1196 | goto cont; | 1197 | goto cont; |
1197 | if (idx > s_idx) | 1198 | if (h > s_h || idx > s_idx) |
1198 | s_ip_idx = 0; | 1199 | s_ip_idx = 0; |
1199 | in_dev = __in_dev_get_rcu(dev); | 1200 | in_dev = __in_dev_get_rcu(dev); |
1200 | if (!in_dev) | 1201 | if (!in_dev) |
diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c index 9b3e28ed5240..4f0ed458c883 100644 --- a/net/ipv4/fib_frontend.c +++ b/net/ipv4/fib_frontend.c | |||
@@ -34,6 +34,7 @@ | |||
34 | #include <linux/skbuff.h> | 34 | #include <linux/skbuff.h> |
35 | #include <linux/init.h> | 35 | #include <linux/init.h> |
36 | #include <linux/list.h> | 36 | #include <linux/list.h> |
37 | #include <linux/slab.h> | ||
37 | 38 | ||
38 | #include <net/ip.h> | 39 | #include <net/ip.h> |
39 | #include <net/protocol.h> | 40 | #include <net/protocol.h> |
diff --git a/net/ipv4/fib_hash.c b/net/ipv4/fib_hash.c index 14972017b9c2..4ed7e0dea1bc 100644 --- a/net/ipv4/fib_hash.c +++ b/net/ipv4/fib_hash.c | |||
@@ -32,6 +32,7 @@ | |||
32 | #include <linux/skbuff.h> | 32 | #include <linux/skbuff.h> |
33 | #include <linux/netlink.h> | 33 | #include <linux/netlink.h> |
34 | #include <linux/init.h> | 34 | #include <linux/init.h> |
35 | #include <linux/slab.h> | ||
35 | 36 | ||
36 | #include <net/net_namespace.h> | 37 | #include <net/net_namespace.h> |
37 | #include <net/ip.h> | 38 | #include <net/ip.h> |
diff --git a/net/ipv4/fib_rules.c b/net/ipv4/fib_rules.c index ca2d07b1c706..3ec84fea5b71 100644 --- a/net/ipv4/fib_rules.c +++ b/net/ipv4/fib_rules.c | |||
@@ -213,7 +213,6 @@ static int fib4_rule_fill(struct fib_rule *rule, struct sk_buff *skb, | |||
213 | { | 213 | { |
214 | struct fib4_rule *rule4 = (struct fib4_rule *) rule; | 214 | struct fib4_rule *rule4 = (struct fib4_rule *) rule; |
215 | 215 | ||
216 | frh->family = AF_INET; | ||
217 | frh->dst_len = rule4->dst_len; | 216 | frh->dst_len = rule4->dst_len; |
218 | frh->src_len = rule4->src_len; | 217 | frh->src_len = rule4->src_len; |
219 | frh->tos = rule4->tos; | 218 | frh->tos = rule4->tos; |
@@ -234,23 +233,6 @@ nla_put_failure: | |||
234 | return -ENOBUFS; | 233 | return -ENOBUFS; |
235 | } | 234 | } |
236 | 235 | ||
237 | static u32 fib4_rule_default_pref(struct fib_rules_ops *ops) | ||
238 | { | ||
239 | struct list_head *pos; | ||
240 | struct fib_rule *rule; | ||
241 | |||
242 | if (!list_empty(&ops->rules_list)) { | ||
243 | pos = ops->rules_list.next; | ||
244 | if (pos->next != &ops->rules_list) { | ||
245 | rule = list_entry(pos->next, struct fib_rule, list); | ||
246 | if (rule->pref) | ||
247 | return rule->pref - 1; | ||
248 | } | ||
249 | } | ||
250 | |||
251 | return 0; | ||
252 | } | ||
253 | |||
254 | static size_t fib4_rule_nlmsg_payload(struct fib_rule *rule) | 236 | static size_t fib4_rule_nlmsg_payload(struct fib_rule *rule) |
255 | { | 237 | { |
256 | return nla_total_size(4) /* dst */ | 238 | return nla_total_size(4) /* dst */ |
@@ -264,7 +246,7 @@ static void fib4_rule_flush_cache(struct fib_rules_ops *ops) | |||
264 | } | 246 | } |
265 | 247 | ||
266 | static struct fib_rules_ops fib4_rules_ops_template = { | 248 | static struct fib_rules_ops fib4_rules_ops_template = { |
267 | .family = AF_INET, | 249 | .family = FIB_RULES_IPV4, |
268 | .rule_size = sizeof(struct fib4_rule), | 250 | .rule_size = sizeof(struct fib4_rule), |
269 | .addr_size = sizeof(u32), | 251 | .addr_size = sizeof(u32), |
270 | .action = fib4_rule_action, | 252 | .action = fib4_rule_action, |
@@ -272,7 +254,7 @@ static struct fib_rules_ops fib4_rules_ops_template = { | |||
272 | .configure = fib4_rule_configure, | 254 | .configure = fib4_rule_configure, |
273 | .compare = fib4_rule_compare, | 255 | .compare = fib4_rule_compare, |
274 | .fill = fib4_rule_fill, | 256 | .fill = fib4_rule_fill, |
275 | .default_pref = fib4_rule_default_pref, | 257 | .default_pref = fib_default_rule_pref, |
276 | .nlmsg_payload = fib4_rule_nlmsg_payload, | 258 | .nlmsg_payload = fib4_rule_nlmsg_payload, |
277 | .flush_cache = fib4_rule_flush_cache, | 259 | .flush_cache = fib4_rule_flush_cache, |
278 | .nlgroup = RTNLGRP_IPV4_RULE, | 260 | .nlgroup = RTNLGRP_IPV4_RULE, |
diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c index 1af0ea0fb6a2..20f09c5b31e8 100644 --- a/net/ipv4/fib_semantics.c +++ b/net/ipv4/fib_semantics.c | |||
@@ -32,6 +32,7 @@ | |||
32 | #include <linux/proc_fs.h> | 32 | #include <linux/proc_fs.h> |
33 | #include <linux/skbuff.h> | 33 | #include <linux/skbuff.h> |
34 | #include <linux/init.h> | 34 | #include <linux/init.h> |
35 | #include <linux/slab.h> | ||
35 | 36 | ||
36 | #include <net/arp.h> | 37 | #include <net/arp.h> |
37 | #include <net/ip.h> | 38 | #include <net/ip.h> |
diff --git a/net/ipv4/fib_trie.c b/net/ipv4/fib_trie.c index af5d89792860..59a838795e3e 100644 --- a/net/ipv4/fib_trie.c +++ b/net/ipv4/fib_trie.c | |||
@@ -71,6 +71,7 @@ | |||
71 | #include <linux/netlink.h> | 71 | #include <linux/netlink.h> |
72 | #include <linux/init.h> | 72 | #include <linux/init.h> |
73 | #include <linux/list.h> | 73 | #include <linux/list.h> |
74 | #include <linux/slab.h> | ||
74 | #include <net/net_namespace.h> | 75 | #include <net/net_namespace.h> |
75 | #include <net/ip.h> | 76 | #include <net/ip.h> |
76 | #include <net/protocol.h> | 77 | #include <net/protocol.h> |
@@ -961,7 +962,9 @@ fib_find_node(struct trie *t, u32 key) | |||
961 | struct node *n; | 962 | struct node *n; |
962 | 963 | ||
963 | pos = 0; | 964 | pos = 0; |
964 | n = rcu_dereference(t->trie); | 965 | n = rcu_dereference_check(t->trie, |
966 | rcu_read_lock_held() || | ||
967 | lockdep_rtnl_is_held()); | ||
965 | 968 | ||
966 | while (n != NULL && NODE_TYPE(n) == T_TNODE) { | 969 | while (n != NULL && NODE_TYPE(n) == T_TNODE) { |
967 | tn = (struct tnode *) n; | 970 | tn = (struct tnode *) n; |
diff --git a/net/ipv4/icmp.c b/net/ipv4/icmp.c index 4b4c2bcd15db..f3d339f728b0 100644 --- a/net/ipv4/icmp.c +++ b/net/ipv4/icmp.c | |||
@@ -74,6 +74,7 @@ | |||
74 | #include <linux/netdevice.h> | 74 | #include <linux/netdevice.h> |
75 | #include <linux/string.h> | 75 | #include <linux/string.h> |
76 | #include <linux/netfilter_ipv4.h> | 76 | #include <linux/netfilter_ipv4.h> |
77 | #include <linux/slab.h> | ||
77 | #include <net/snmp.h> | 78 | #include <net/snmp.h> |
78 | #include <net/ip.h> | 79 | #include <net/ip.h> |
79 | #include <net/route.h> | 80 | #include <net/route.h> |
@@ -330,9 +331,10 @@ static void icmp_push_reply(struct icmp_bxm *icmp_param, | |||
330 | if (ip_append_data(sk, icmp_glue_bits, icmp_param, | 331 | if (ip_append_data(sk, icmp_glue_bits, icmp_param, |
331 | icmp_param->data_len+icmp_param->head_len, | 332 | icmp_param->data_len+icmp_param->head_len, |
332 | icmp_param->head_len, | 333 | icmp_param->head_len, |
333 | ipc, rt, MSG_DONTWAIT) < 0) | 334 | ipc, rt, MSG_DONTWAIT) < 0) { |
335 | ICMP_INC_STATS_BH(sock_net(sk), ICMP_MIB_OUTERRORS); | ||
334 | ip_flush_pending_frames(sk); | 336 | ip_flush_pending_frames(sk); |
335 | else if ((skb = skb_peek(&sk->sk_write_queue)) != NULL) { | 337 | } else if ((skb = skb_peek(&sk->sk_write_queue)) != NULL) { |
336 | struct icmphdr *icmph = icmp_hdr(skb); | 338 | struct icmphdr *icmph = icmp_hdr(skb); |
337 | __wsum csum = 0; | 339 | __wsum csum = 0; |
338 | struct sk_buff *skb1; | 340 | struct sk_buff *skb1; |
diff --git a/net/ipv4/igmp.c b/net/ipv4/igmp.c index 63bf298ca109..5fff865a4fa7 100644 --- a/net/ipv4/igmp.c +++ b/net/ipv4/igmp.c | |||
@@ -71,6 +71,7 @@ | |||
71 | */ | 71 | */ |
72 | 72 | ||
73 | #include <linux/module.h> | 73 | #include <linux/module.h> |
74 | #include <linux/slab.h> | ||
74 | #include <asm/uaccess.h> | 75 | #include <asm/uaccess.h> |
75 | #include <asm/system.h> | 76 | #include <asm/system.h> |
76 | #include <linux/types.h> | 77 | #include <linux/types.h> |
@@ -997,7 +998,7 @@ static void ip_mc_filter_add(struct in_device *in_dev, __be32 addr) | |||
997 | --ANK | 998 | --ANK |
998 | */ | 999 | */ |
999 | if (arp_mc_map(addr, buf, dev, 0) == 0) | 1000 | if (arp_mc_map(addr, buf, dev, 0) == 0) |
1000 | dev_mc_add(dev, buf, dev->addr_len, 0); | 1001 | dev_mc_add(dev, buf); |
1001 | } | 1002 | } |
1002 | 1003 | ||
1003 | /* | 1004 | /* |
@@ -1010,7 +1011,7 @@ static void ip_mc_filter_del(struct in_device *in_dev, __be32 addr) | |||
1010 | struct net_device *dev = in_dev->dev; | 1011 | struct net_device *dev = in_dev->dev; |
1011 | 1012 | ||
1012 | if (arp_mc_map(addr, buf, dev, 0) == 0) | 1013 | if (arp_mc_map(addr, buf, dev, 0) == 0) |
1013 | dev_mc_delete(dev, buf, dev->addr_len, 0); | 1014 | dev_mc_del(dev, buf); |
1014 | } | 1015 | } |
1015 | 1016 | ||
1016 | #ifdef CONFIG_IP_MULTICAST | 1017 | #ifdef CONFIG_IP_MULTICAST |
diff --git a/net/ipv4/inet_diag.c b/net/ipv4/inet_diag.c index 1aaa8110d84b..e5fa2ddce320 100644 --- a/net/ipv4/inet_diag.c +++ b/net/ipv4/inet_diag.c | |||
@@ -14,6 +14,7 @@ | |||
14 | #include <linux/types.h> | 14 | #include <linux/types.h> |
15 | #include <linux/fcntl.h> | 15 | #include <linux/fcntl.h> |
16 | #include <linux/random.h> | 16 | #include <linux/random.h> |
17 | #include <linux/slab.h> | ||
17 | #include <linux/cache.h> | 18 | #include <linux/cache.h> |
18 | #include <linux/init.h> | 19 | #include <linux/init.h> |
19 | #include <linux/time.h> | 20 | #include <linux/time.h> |
diff --git a/net/ipv4/inet_fragment.c b/net/ipv4/inet_fragment.c index eaf3e2c8646a..a2ca6aed763b 100644 --- a/net/ipv4/inet_fragment.c +++ b/net/ipv4/inet_fragment.c | |||
@@ -19,6 +19,7 @@ | |||
19 | #include <linux/random.h> | 19 | #include <linux/random.h> |
20 | #include <linux/skbuff.h> | 20 | #include <linux/skbuff.h> |
21 | #include <linux/rtnetlink.h> | 21 | #include <linux/rtnetlink.h> |
22 | #include <linux/slab.h> | ||
22 | 23 | ||
23 | #include <net/inet_frag.h> | 24 | #include <net/inet_frag.h> |
24 | 25 | ||
diff --git a/net/ipv4/inet_timewait_sock.c b/net/ipv4/inet_timewait_sock.c index cc94cc2d8b2d..c5af909cf701 100644 --- a/net/ipv4/inet_timewait_sock.c +++ b/net/ipv4/inet_timewait_sock.c | |||
@@ -10,6 +10,7 @@ | |||
10 | 10 | ||
11 | #include <linux/kernel.h> | 11 | #include <linux/kernel.h> |
12 | #include <linux/kmemcheck.h> | 12 | #include <linux/kmemcheck.h> |
13 | #include <linux/slab.h> | ||
13 | #include <net/inet_hashtables.h> | 14 | #include <net/inet_hashtables.h> |
14 | #include <net/inet_timewait_sock.h> | 15 | #include <net/inet_timewait_sock.h> |
15 | #include <net/ip.h> | 16 | #include <net/ip.h> |
diff --git a/net/ipv4/ip_forward.c b/net/ipv4/ip_forward.c index a2991bc8e32e..af10942b326c 100644 --- a/net/ipv4/ip_forward.c +++ b/net/ipv4/ip_forward.c | |||
@@ -25,6 +25,7 @@ | |||
25 | #include <linux/ip.h> | 25 | #include <linux/ip.h> |
26 | #include <linux/icmp.h> | 26 | #include <linux/icmp.h> |
27 | #include <linux/netdevice.h> | 27 | #include <linux/netdevice.h> |
28 | #include <linux/slab.h> | ||
28 | #include <net/sock.h> | 29 | #include <net/sock.h> |
29 | #include <net/ip.h> | 30 | #include <net/ip.h> |
30 | #include <net/tcp.h> | 31 | #include <net/tcp.h> |
diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c index b59430bc041c..75347ea70ea0 100644 --- a/net/ipv4/ip_fragment.c +++ b/net/ipv4/ip_fragment.c | |||
@@ -32,6 +32,7 @@ | |||
32 | #include <linux/netdevice.h> | 32 | #include <linux/netdevice.h> |
33 | #include <linux/jhash.h> | 33 | #include <linux/jhash.h> |
34 | #include <linux/random.h> | 34 | #include <linux/random.h> |
35 | #include <linux/slab.h> | ||
35 | #include <net/route.h> | 36 | #include <net/route.h> |
36 | #include <net/dst.h> | 37 | #include <net/dst.h> |
37 | #include <net/sock.h> | 38 | #include <net/sock.h> |
diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c index f47c9f76754b..fe381d12ecdd 100644 --- a/net/ipv4/ip_gre.c +++ b/net/ipv4/ip_gre.c | |||
@@ -14,6 +14,7 @@ | |||
14 | #include <linux/module.h> | 14 | #include <linux/module.h> |
15 | #include <linux/types.h> | 15 | #include <linux/types.h> |
16 | #include <linux/kernel.h> | 16 | #include <linux/kernel.h> |
17 | #include <linux/slab.h> | ||
17 | #include <asm/uaccess.h> | 18 | #include <asm/uaccess.h> |
18 | #include <linux/skbuff.h> | 19 | #include <linux/skbuff.h> |
19 | #include <linux/netdevice.h> | 20 | #include <linux/netdevice.h> |
@@ -810,11 +811,13 @@ static netdev_tx_t ipgre_tunnel_xmit(struct sk_buff *skb, struct net_device *dev | |||
810 | tunnel->err_count = 0; | 811 | tunnel->err_count = 0; |
811 | } | 812 | } |
812 | 813 | ||
813 | max_headroom = LL_RESERVED_SPACE(tdev) + gre_hlen; | 814 | max_headroom = LL_RESERVED_SPACE(tdev) + gre_hlen + rt->u.dst.header_len; |
814 | 815 | ||
815 | if (skb_headroom(skb) < max_headroom || skb_shared(skb)|| | 816 | if (skb_headroom(skb) < max_headroom || skb_shared(skb)|| |
816 | (skb_cloned(skb) && !skb_clone_writable(skb, 0))) { | 817 | (skb_cloned(skb) && !skb_clone_writable(skb, 0))) { |
817 | struct sk_buff *new_skb = skb_realloc_headroom(skb, max_headroom); | 818 | struct sk_buff *new_skb = skb_realloc_headroom(skb, max_headroom); |
819 | if (max_headroom > dev->needed_headroom) | ||
820 | dev->needed_headroom = max_headroom; | ||
818 | if (!new_skb) { | 821 | if (!new_skb) { |
819 | ip_rt_put(rt); | 822 | ip_rt_put(rt); |
820 | txq->tx_dropped++; | 823 | txq->tx_dropped++; |
diff --git a/net/ipv4/ip_input.c b/net/ipv4/ip_input.c index c29de9879fda..f8ab7a380d4a 100644 --- a/net/ipv4/ip_input.c +++ b/net/ipv4/ip_input.c | |||
@@ -119,6 +119,7 @@ | |||
119 | #include <linux/kernel.h> | 119 | #include <linux/kernel.h> |
120 | #include <linux/string.h> | 120 | #include <linux/string.h> |
121 | #include <linux/errno.h> | 121 | #include <linux/errno.h> |
122 | #include <linux/slab.h> | ||
122 | 123 | ||
123 | #include <linux/net.h> | 124 | #include <linux/net.h> |
124 | #include <linux/socket.h> | 125 | #include <linux/socket.h> |
diff --git a/net/ipv4/ip_options.c b/net/ipv4/ip_options.c index 94bf105ef3c9..4c09a31fd140 100644 --- a/net/ipv4/ip_options.c +++ b/net/ipv4/ip_options.c | |||
@@ -11,6 +11,7 @@ | |||
11 | 11 | ||
12 | #include <linux/capability.h> | 12 | #include <linux/capability.h> |
13 | #include <linux/module.h> | 13 | #include <linux/module.h> |
14 | #include <linux/slab.h> | ||
14 | #include <linux/types.h> | 15 | #include <linux/types.h> |
15 | #include <asm/uaccess.h> | 16 | #include <asm/uaccess.h> |
16 | #include <linux/skbuff.h> | 17 | #include <linux/skbuff.h> |
diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c index 3451799e3dbf..c65f18e0936e 100644 --- a/net/ipv4/ip_output.c +++ b/net/ipv4/ip_output.c | |||
@@ -51,6 +51,7 @@ | |||
51 | #include <linux/string.h> | 51 | #include <linux/string.h> |
52 | #include <linux/errno.h> | 52 | #include <linux/errno.h> |
53 | #include <linux/highmem.h> | 53 | #include <linux/highmem.h> |
54 | #include <linux/slab.h> | ||
54 | 55 | ||
55 | #include <linux/socket.h> | 56 | #include <linux/socket.h> |
56 | #include <linux/sockios.h> | 57 | #include <linux/sockios.h> |
diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c index 644dc43a55de..b0aa0546a3b3 100644 --- a/net/ipv4/ip_sockglue.c +++ b/net/ipv4/ip_sockglue.c | |||
@@ -23,6 +23,7 @@ | |||
23 | #include <linux/icmp.h> | 23 | #include <linux/icmp.h> |
24 | #include <linux/inetdevice.h> | 24 | #include <linux/inetdevice.h> |
25 | #include <linux/netdevice.h> | 25 | #include <linux/netdevice.h> |
26 | #include <linux/slab.h> | ||
26 | #include <net/sock.h> | 27 | #include <net/sock.h> |
27 | #include <net/ip.h> | 28 | #include <net/ip.h> |
28 | #include <net/icmp.h> | 29 | #include <net/icmp.h> |
@@ -286,12 +287,8 @@ int ip_ra_control(struct sock *sk, unsigned char on, | |||
286 | void ip_icmp_error(struct sock *sk, struct sk_buff *skb, int err, | 287 | void ip_icmp_error(struct sock *sk, struct sk_buff *skb, int err, |
287 | __be16 port, u32 info, u8 *payload) | 288 | __be16 port, u32 info, u8 *payload) |
288 | { | 289 | { |
289 | struct inet_sock *inet = inet_sk(sk); | ||
290 | struct sock_exterr_skb *serr; | 290 | struct sock_exterr_skb *serr; |
291 | 291 | ||
292 | if (!inet->recverr) | ||
293 | return; | ||
294 | |||
295 | skb = skb_clone(skb, GFP_ATOMIC); | 292 | skb = skb_clone(skb, GFP_ATOMIC); |
296 | if (!skb) | 293 | if (!skb) |
297 | return; | 294 | return; |
diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c index 10a6a604bf32..b9d84e800cf4 100644 --- a/net/ipv4/ipconfig.c +++ b/net/ipv4/ipconfig.c | |||
@@ -53,6 +53,7 @@ | |||
53 | #include <linux/root_dev.h> | 53 | #include <linux/root_dev.h> |
54 | #include <linux/delay.h> | 54 | #include <linux/delay.h> |
55 | #include <linux/nfs_fs.h> | 55 | #include <linux/nfs_fs.h> |
56 | #include <linux/slab.h> | ||
56 | #include <net/net_namespace.h> | 57 | #include <net/net_namespace.h> |
57 | #include <net/arp.h> | 58 | #include <net/arp.h> |
58 | #include <net/ip.h> | 59 | #include <net/ip.h> |
@@ -187,6 +188,16 @@ struct ic_device { | |||
187 | static struct ic_device *ic_first_dev __initdata = NULL;/* List of open device */ | 188 | static struct ic_device *ic_first_dev __initdata = NULL;/* List of open device */ |
188 | static struct net_device *ic_dev __initdata = NULL; /* Selected device */ | 189 | static struct net_device *ic_dev __initdata = NULL; /* Selected device */ |
189 | 190 | ||
191 | static bool __init ic_device_match(struct net_device *dev) | ||
192 | { | ||
193 | if (user_dev_name[0] ? !strcmp(dev->name, user_dev_name) : | ||
194 | (!(dev->flags & IFF_LOOPBACK) && | ||
195 | (dev->flags & (IFF_POINTOPOINT|IFF_BROADCAST)) && | ||
196 | strncmp(dev->name, "dummy", 5))) | ||
197 | return true; | ||
198 | return false; | ||
199 | } | ||
200 | |||
190 | static int __init ic_open_devs(void) | 201 | static int __init ic_open_devs(void) |
191 | { | 202 | { |
192 | struct ic_device *d, **last; | 203 | struct ic_device *d, **last; |
@@ -207,10 +218,7 @@ static int __init ic_open_devs(void) | |||
207 | for_each_netdev(&init_net, dev) { | 218 | for_each_netdev(&init_net, dev) { |
208 | if (dev->flags & IFF_LOOPBACK) | 219 | if (dev->flags & IFF_LOOPBACK) |
209 | continue; | 220 | continue; |
210 | if (user_dev_name[0] ? !strcmp(dev->name, user_dev_name) : | 221 | if (ic_device_match(dev)) { |
211 | (!(dev->flags & IFF_LOOPBACK) && | ||
212 | (dev->flags & (IFF_POINTOPOINT|IFF_BROADCAST)) && | ||
213 | strncmp(dev->name, "dummy", 5))) { | ||
214 | int able = 0; | 222 | int able = 0; |
215 | if (dev->mtu >= 364) | 223 | if (dev->mtu >= 364) |
216 | able |= IC_BOOTP; | 224 | able |= IC_BOOTP; |
@@ -228,7 +236,7 @@ static int __init ic_open_devs(void) | |||
228 | } | 236 | } |
229 | if (!(d = kmalloc(sizeof(struct ic_device), GFP_KERNEL))) { | 237 | if (!(d = kmalloc(sizeof(struct ic_device), GFP_KERNEL))) { |
230 | rtnl_unlock(); | 238 | rtnl_unlock(); |
231 | return -1; | 239 | return -ENOMEM; |
232 | } | 240 | } |
233 | d->dev = dev; | 241 | d->dev = dev; |
234 | *last = d; | 242 | *last = d; |
@@ -253,7 +261,7 @@ static int __init ic_open_devs(void) | |||
253 | printk(KERN_ERR "IP-Config: Device `%s' not found.\n", user_dev_name); | 261 | printk(KERN_ERR "IP-Config: Device `%s' not found.\n", user_dev_name); |
254 | else | 262 | else |
255 | printk(KERN_ERR "IP-Config: No network devices available.\n"); | 263 | printk(KERN_ERR "IP-Config: No network devices available.\n"); |
256 | return -1; | 264 | return -ENODEV; |
257 | } | 265 | } |
258 | return 0; | 266 | return 0; |
259 | } | 267 | } |
@@ -968,7 +976,7 @@ static int __init ic_bootp_recv(struct sk_buff *skb, struct net_device *dev, str | |||
968 | /* Is it a reply for the device we are configuring? */ | 976 | /* Is it a reply for the device we are configuring? */ |
969 | if (b->xid != ic_dev_xid) { | 977 | if (b->xid != ic_dev_xid) { |
970 | if (net_ratelimit()) | 978 | if (net_ratelimit()) |
971 | printk(KERN_ERR "DHCP/BOOTP: Ignoring delayed packet \n"); | 979 | printk(KERN_ERR "DHCP/BOOTP: Ignoring delayed packet\n"); |
972 | goto drop_unlock; | 980 | goto drop_unlock; |
973 | } | 981 | } |
974 | 982 | ||
@@ -1303,6 +1311,32 @@ __be32 __init root_nfs_parse_addr(char *name) | |||
1303 | return addr; | 1311 | return addr; |
1304 | } | 1312 | } |
1305 | 1313 | ||
1314 | #define DEVICE_WAIT_MAX 12 /* 12 seconds */ | ||
1315 | |||
1316 | static int __init wait_for_devices(void) | ||
1317 | { | ||
1318 | int i; | ||
1319 | |||
1320 | msleep(CONF_PRE_OPEN); | ||
1321 | for (i = 0; i < DEVICE_WAIT_MAX; i++) { | ||
1322 | struct net_device *dev; | ||
1323 | int found = 0; | ||
1324 | |||
1325 | rtnl_lock(); | ||
1326 | for_each_netdev(&init_net, dev) { | ||
1327 | if (ic_device_match(dev)) { | ||
1328 | found = 1; | ||
1329 | break; | ||
1330 | } | ||
1331 | } | ||
1332 | rtnl_unlock(); | ||
1333 | if (found) | ||
1334 | return 0; | ||
1335 | ssleep(1); | ||
1336 | } | ||
1337 | return -ENODEV; | ||
1338 | } | ||
1339 | |||
1306 | /* | 1340 | /* |
1307 | * IP Autoconfig dispatcher. | 1341 | * IP Autoconfig dispatcher. |
1308 | */ | 1342 | */ |
@@ -1313,6 +1347,7 @@ static int __init ip_auto_config(void) | |||
1313 | #ifdef IPCONFIG_DYNAMIC | 1347 | #ifdef IPCONFIG_DYNAMIC |
1314 | int retries = CONF_OPEN_RETRIES; | 1348 | int retries = CONF_OPEN_RETRIES; |
1315 | #endif | 1349 | #endif |
1350 | int err; | ||
1316 | 1351 | ||
1317 | #ifdef CONFIG_PROC_FS | 1352 | #ifdef CONFIG_PROC_FS |
1318 | proc_net_fops_create(&init_net, "pnp", S_IRUGO, &pnp_seq_fops); | 1353 | proc_net_fops_create(&init_net, "pnp", S_IRUGO, &pnp_seq_fops); |
@@ -1325,12 +1360,15 @@ static int __init ip_auto_config(void) | |||
1325 | #ifdef IPCONFIG_DYNAMIC | 1360 | #ifdef IPCONFIG_DYNAMIC |
1326 | try_try_again: | 1361 | try_try_again: |
1327 | #endif | 1362 | #endif |
1328 | /* Give hardware a chance to settle */ | 1363 | /* Wait for devices to appear */ |
1329 | msleep(CONF_PRE_OPEN); | 1364 | err = wait_for_devices(); |
1365 | if (err) | ||
1366 | return err; | ||
1330 | 1367 | ||
1331 | /* Setup all network devices */ | 1368 | /* Setup all network devices */ |
1332 | if (ic_open_devs() < 0) | 1369 | err = ic_open_devs(); |
1333 | return -1; | 1370 | if (err) |
1371 | return err; | ||
1334 | 1372 | ||
1335 | /* Give drivers a chance to settle */ | 1373 | /* Give drivers a chance to settle */ |
1336 | ssleep(CONF_POST_OPEN); | 1374 | ssleep(CONF_POST_OPEN); |
diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c index 2f302d3ac9a3..0b27b14dcc9d 100644 --- a/net/ipv4/ipip.c +++ b/net/ipv4/ipip.c | |||
@@ -95,6 +95,7 @@ | |||
95 | #include <linux/module.h> | 95 | #include <linux/module.h> |
96 | #include <linux/types.h> | 96 | #include <linux/types.h> |
97 | #include <linux/kernel.h> | 97 | #include <linux/kernel.h> |
98 | #include <linux/slab.h> | ||
98 | #include <asm/uaccess.h> | 99 | #include <asm/uaccess.h> |
99 | #include <linux/skbuff.h> | 100 | #include <linux/skbuff.h> |
100 | #include <linux/netdevice.h> | 101 | #include <linux/netdevice.h> |
diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c index 8582e12e4a62..5df5fd74c6d1 100644 --- a/net/ipv4/ipmr.c +++ b/net/ipv4/ipmr.c | |||
@@ -47,6 +47,7 @@ | |||
47 | #include <linux/mroute.h> | 47 | #include <linux/mroute.h> |
48 | #include <linux/init.h> | 48 | #include <linux/init.h> |
49 | #include <linux/if_ether.h> | 49 | #include <linux/if_ether.h> |
50 | #include <linux/slab.h> | ||
50 | #include <net/net_namespace.h> | 51 | #include <net/net_namespace.h> |
51 | #include <net/ip.h> | 52 | #include <net/ip.h> |
52 | #include <net/protocol.h> | 53 | #include <net/protocol.h> |
@@ -62,11 +63,37 @@ | |||
62 | #include <net/ipip.h> | 63 | #include <net/ipip.h> |
63 | #include <net/checksum.h> | 64 | #include <net/checksum.h> |
64 | #include <net/netlink.h> | 65 | #include <net/netlink.h> |
66 | #include <net/fib_rules.h> | ||
65 | 67 | ||
66 | #if defined(CONFIG_IP_PIMSM_V1) || defined(CONFIG_IP_PIMSM_V2) | 68 | #if defined(CONFIG_IP_PIMSM_V1) || defined(CONFIG_IP_PIMSM_V2) |
67 | #define CONFIG_IP_PIMSM 1 | 69 | #define CONFIG_IP_PIMSM 1 |
68 | #endif | 70 | #endif |
69 | 71 | ||
72 | struct mr_table { | ||
73 | struct list_head list; | ||
74 | u32 id; | ||
75 | struct sock *mroute_sk; | ||
76 | struct timer_list ipmr_expire_timer; | ||
77 | struct list_head mfc_unres_queue; | ||
78 | struct list_head mfc_cache_array[MFC_LINES]; | ||
79 | struct vif_device vif_table[MAXVIFS]; | ||
80 | int maxvif; | ||
81 | atomic_t cache_resolve_queue_len; | ||
82 | int mroute_do_assert; | ||
83 | int mroute_do_pim; | ||
84 | #if defined(CONFIG_IP_PIMSM_V1) || defined(CONFIG_IP_PIMSM_V2) | ||
85 | int mroute_reg_vif_num; | ||
86 | #endif | ||
87 | }; | ||
88 | |||
89 | struct ipmr_rule { | ||
90 | struct fib_rule common; | ||
91 | }; | ||
92 | |||
93 | struct ipmr_result { | ||
94 | struct mr_table *mrt; | ||
95 | }; | ||
96 | |||
70 | /* Big lock, protecting vif table, mrt cache and mroute socket state. | 97 | /* Big lock, protecting vif table, mrt cache and mroute socket state. |
71 | Note that the changes are semaphored via rtnl_lock. | 98 | Note that the changes are semaphored via rtnl_lock. |
72 | */ | 99 | */ |
@@ -77,9 +104,7 @@ static DEFINE_RWLOCK(mrt_lock); | |||
77 | * Multicast router control variables | 104 | * Multicast router control variables |
78 | */ | 105 | */ |
79 | 106 | ||
80 | #define VIF_EXISTS(_net, _idx) ((_net)->ipv4.vif_table[_idx].dev != NULL) | 107 | #define VIF_EXISTS(_mrt, _idx) ((_mrt)->vif_table[_idx].dev != NULL) |
81 | |||
82 | static struct mfc_cache *mfc_unres_queue; /* Queue of unresolved entries */ | ||
83 | 108 | ||
84 | /* Special spinlock for queue of unresolved entries */ | 109 | /* Special spinlock for queue of unresolved entries */ |
85 | static DEFINE_SPINLOCK(mfc_unres_lock); | 110 | static DEFINE_SPINLOCK(mfc_unres_lock); |
@@ -94,12 +119,214 @@ static DEFINE_SPINLOCK(mfc_unres_lock); | |||
94 | 119 | ||
95 | static struct kmem_cache *mrt_cachep __read_mostly; | 120 | static struct kmem_cache *mrt_cachep __read_mostly; |
96 | 121 | ||
97 | static int ip_mr_forward(struct sk_buff *skb, struct mfc_cache *cache, int local); | 122 | static struct mr_table *ipmr_new_table(struct net *net, u32 id); |
98 | static int ipmr_cache_report(struct net *net, | 123 | static int ip_mr_forward(struct net *net, struct mr_table *mrt, |
124 | struct sk_buff *skb, struct mfc_cache *cache, | ||
125 | int local); | ||
126 | static int ipmr_cache_report(struct mr_table *mrt, | ||
99 | struct sk_buff *pkt, vifi_t vifi, int assert); | 127 | struct sk_buff *pkt, vifi_t vifi, int assert); |
100 | static int ipmr_fill_mroute(struct sk_buff *skb, struct mfc_cache *c, struct rtmsg *rtm); | 128 | static int ipmr_fill_mroute(struct mr_table *mrt, struct sk_buff *skb, |
129 | struct mfc_cache *c, struct rtmsg *rtm); | ||
130 | static void ipmr_expire_process(unsigned long arg); | ||
131 | |||
132 | #ifdef CONFIG_IP_MROUTE_MULTIPLE_TABLES | ||
133 | #define ipmr_for_each_table(mrt, net) \ | ||
134 | list_for_each_entry_rcu(mrt, &net->ipv4.mr_tables, list) | ||
135 | |||
136 | static struct mr_table *ipmr_get_table(struct net *net, u32 id) | ||
137 | { | ||
138 | struct mr_table *mrt; | ||
139 | |||
140 | ipmr_for_each_table(mrt, net) { | ||
141 | if (mrt->id == id) | ||
142 | return mrt; | ||
143 | } | ||
144 | return NULL; | ||
145 | } | ||
146 | |||
147 | static int ipmr_fib_lookup(struct net *net, struct flowi *flp, | ||
148 | struct mr_table **mrt) | ||
149 | { | ||
150 | struct ipmr_result res; | ||
151 | struct fib_lookup_arg arg = { .result = &res, }; | ||
152 | int err; | ||
153 | |||
154 | err = fib_rules_lookup(net->ipv4.mr_rules_ops, flp, 0, &arg); | ||
155 | if (err < 0) | ||
156 | return err; | ||
157 | *mrt = res.mrt; | ||
158 | return 0; | ||
159 | } | ||
160 | |||
161 | static int ipmr_rule_action(struct fib_rule *rule, struct flowi *flp, | ||
162 | int flags, struct fib_lookup_arg *arg) | ||
163 | { | ||
164 | struct ipmr_result *res = arg->result; | ||
165 | struct mr_table *mrt; | ||
166 | |||
167 | switch (rule->action) { | ||
168 | case FR_ACT_TO_TBL: | ||
169 | break; | ||
170 | case FR_ACT_UNREACHABLE: | ||
171 | return -ENETUNREACH; | ||
172 | case FR_ACT_PROHIBIT: | ||
173 | return -EACCES; | ||
174 | case FR_ACT_BLACKHOLE: | ||
175 | default: | ||
176 | return -EINVAL; | ||
177 | } | ||
178 | |||
179 | mrt = ipmr_get_table(rule->fr_net, rule->table); | ||
180 | if (mrt == NULL) | ||
181 | return -EAGAIN; | ||
182 | res->mrt = mrt; | ||
183 | return 0; | ||
184 | } | ||
185 | |||
186 | static int ipmr_rule_match(struct fib_rule *rule, struct flowi *fl, int flags) | ||
187 | { | ||
188 | return 1; | ||
189 | } | ||
190 | |||
191 | static const struct nla_policy ipmr_rule_policy[FRA_MAX + 1] = { | ||
192 | FRA_GENERIC_POLICY, | ||
193 | }; | ||
194 | |||
195 | static int ipmr_rule_configure(struct fib_rule *rule, struct sk_buff *skb, | ||
196 | struct fib_rule_hdr *frh, struct nlattr **tb) | ||
197 | { | ||
198 | return 0; | ||
199 | } | ||
200 | |||
201 | static int ipmr_rule_compare(struct fib_rule *rule, struct fib_rule_hdr *frh, | ||
202 | struct nlattr **tb) | ||
203 | { | ||
204 | return 1; | ||
205 | } | ||
206 | |||
207 | static int ipmr_rule_fill(struct fib_rule *rule, struct sk_buff *skb, | ||
208 | struct fib_rule_hdr *frh) | ||
209 | { | ||
210 | frh->dst_len = 0; | ||
211 | frh->src_len = 0; | ||
212 | frh->tos = 0; | ||
213 | return 0; | ||
214 | } | ||
215 | |||
216 | static struct fib_rules_ops ipmr_rules_ops_template = { | ||
217 | .family = FIB_RULES_IPMR, | ||
218 | .rule_size = sizeof(struct ipmr_rule), | ||
219 | .addr_size = sizeof(u32), | ||
220 | .action = ipmr_rule_action, | ||
221 | .match = ipmr_rule_match, | ||
222 | .configure = ipmr_rule_configure, | ||
223 | .compare = ipmr_rule_compare, | ||
224 | .default_pref = fib_default_rule_pref, | ||
225 | .fill = ipmr_rule_fill, | ||
226 | .nlgroup = RTNLGRP_IPV4_RULE, | ||
227 | .policy = ipmr_rule_policy, | ||
228 | .owner = THIS_MODULE, | ||
229 | }; | ||
230 | |||
231 | static int __net_init ipmr_rules_init(struct net *net) | ||
232 | { | ||
233 | struct fib_rules_ops *ops; | ||
234 | struct mr_table *mrt; | ||
235 | int err; | ||
236 | |||
237 | ops = fib_rules_register(&ipmr_rules_ops_template, net); | ||
238 | if (IS_ERR(ops)) | ||
239 | return PTR_ERR(ops); | ||
240 | |||
241 | INIT_LIST_HEAD(&net->ipv4.mr_tables); | ||
242 | |||
243 | mrt = ipmr_new_table(net, RT_TABLE_DEFAULT); | ||
244 | if (mrt == NULL) { | ||
245 | err = -ENOMEM; | ||
246 | goto err1; | ||
247 | } | ||
248 | |||
249 | err = fib_default_rule_add(ops, 0x7fff, RT_TABLE_DEFAULT, 0); | ||
250 | if (err < 0) | ||
251 | goto err2; | ||
252 | |||
253 | net->ipv4.mr_rules_ops = ops; | ||
254 | return 0; | ||
255 | |||
256 | err2: | ||
257 | kfree(mrt); | ||
258 | err1: | ||
259 | fib_rules_unregister(ops); | ||
260 | return err; | ||
261 | } | ||
262 | |||
263 | static void __net_exit ipmr_rules_exit(struct net *net) | ||
264 | { | ||
265 | struct mr_table *mrt, *next; | ||
266 | |||
267 | list_for_each_entry_safe(mrt, next, &net->ipv4.mr_tables, list) | ||
268 | kfree(mrt); | ||
269 | fib_rules_unregister(net->ipv4.mr_rules_ops); | ||
270 | } | ||
271 | #else | ||
272 | #define ipmr_for_each_table(mrt, net) \ | ||
273 | for (mrt = net->ipv4.mrt; mrt; mrt = NULL) | ||
274 | |||
275 | static struct mr_table *ipmr_get_table(struct net *net, u32 id) | ||
276 | { | ||
277 | return net->ipv4.mrt; | ||
278 | } | ||
279 | |||
280 | static int ipmr_fib_lookup(struct net *net, struct flowi *flp, | ||
281 | struct mr_table **mrt) | ||
282 | { | ||
283 | *mrt = net->ipv4.mrt; | ||
284 | return 0; | ||
285 | } | ||
101 | 286 | ||
102 | static struct timer_list ipmr_expire_timer; | 287 | static int __net_init ipmr_rules_init(struct net *net) |
288 | { | ||
289 | net->ipv4.mrt = ipmr_new_table(net, RT_TABLE_DEFAULT); | ||
290 | return net->ipv4.mrt ? 0 : -ENOMEM; | ||
291 | } | ||
292 | |||
293 | static void __net_exit ipmr_rules_exit(struct net *net) | ||
294 | { | ||
295 | kfree(net->ipv4.mrt); | ||
296 | } | ||
297 | #endif | ||
298 | |||
299 | static struct mr_table *ipmr_new_table(struct net *net, u32 id) | ||
300 | { | ||
301 | struct mr_table *mrt; | ||
302 | unsigned int i; | ||
303 | |||
304 | mrt = ipmr_get_table(net, id); | ||
305 | if (mrt != NULL) | ||
306 | return mrt; | ||
307 | |||
308 | mrt = kzalloc(sizeof(*mrt), GFP_KERNEL); | ||
309 | if (mrt == NULL) | ||
310 | return NULL; | ||
311 | mrt->id = id; | ||
312 | |||
313 | /* Forwarding cache */ | ||
314 | for (i = 0; i < MFC_LINES; i++) | ||
315 | INIT_LIST_HEAD(&mrt->mfc_cache_array[i]); | ||
316 | |||
317 | INIT_LIST_HEAD(&mrt->mfc_unres_queue); | ||
318 | |||
319 | setup_timer(&mrt->ipmr_expire_timer, ipmr_expire_process, | ||
320 | (unsigned long)mrt); | ||
321 | |||
322 | #ifdef CONFIG_IP_PIMSM | ||
323 | mrt->mroute_reg_vif_num = -1; | ||
324 | #endif | ||
325 | #ifdef CONFIG_IP_MROUTE_MULTIPLE_TABLES | ||
326 | list_add_tail_rcu(&mrt->list, &net->ipv4.mr_tables); | ||
327 | #endif | ||
328 | return mrt; | ||
329 | } | ||
103 | 330 | ||
104 | /* Service routines creating virtual interfaces: DVMRP tunnels and PIMREG */ | 331 | /* Service routines creating virtual interfaces: DVMRP tunnels and PIMREG */ |
105 | 332 | ||
@@ -200,12 +427,22 @@ failure: | |||
200 | static netdev_tx_t reg_vif_xmit(struct sk_buff *skb, struct net_device *dev) | 427 | static netdev_tx_t reg_vif_xmit(struct sk_buff *skb, struct net_device *dev) |
201 | { | 428 | { |
202 | struct net *net = dev_net(dev); | 429 | struct net *net = dev_net(dev); |
430 | struct mr_table *mrt; | ||
431 | struct flowi fl = { | ||
432 | .oif = dev->ifindex, | ||
433 | .iif = skb->skb_iif, | ||
434 | .mark = skb->mark, | ||
435 | }; | ||
436 | int err; | ||
437 | |||
438 | err = ipmr_fib_lookup(net, &fl, &mrt); | ||
439 | if (err < 0) | ||
440 | return err; | ||
203 | 441 | ||
204 | read_lock(&mrt_lock); | 442 | read_lock(&mrt_lock); |
205 | dev->stats.tx_bytes += skb->len; | 443 | dev->stats.tx_bytes += skb->len; |
206 | dev->stats.tx_packets++; | 444 | dev->stats.tx_packets++; |
207 | ipmr_cache_report(net, skb, net->ipv4.mroute_reg_vif_num, | 445 | ipmr_cache_report(mrt, skb, mrt->mroute_reg_vif_num, IGMPMSG_WHOLEPKT); |
208 | IGMPMSG_WHOLEPKT); | ||
209 | read_unlock(&mrt_lock); | 446 | read_unlock(&mrt_lock); |
210 | kfree_skb(skb); | 447 | kfree_skb(skb); |
211 | return NETDEV_TX_OK; | 448 | return NETDEV_TX_OK; |
@@ -225,12 +462,18 @@ static void reg_vif_setup(struct net_device *dev) | |||
225 | dev->features |= NETIF_F_NETNS_LOCAL; | 462 | dev->features |= NETIF_F_NETNS_LOCAL; |
226 | } | 463 | } |
227 | 464 | ||
228 | static struct net_device *ipmr_reg_vif(struct net *net) | 465 | static struct net_device *ipmr_reg_vif(struct net *net, struct mr_table *mrt) |
229 | { | 466 | { |
230 | struct net_device *dev; | 467 | struct net_device *dev; |
231 | struct in_device *in_dev; | 468 | struct in_device *in_dev; |
469 | char name[IFNAMSIZ]; | ||
470 | |||
471 | if (mrt->id == RT_TABLE_DEFAULT) | ||
472 | sprintf(name, "pimreg"); | ||
473 | else | ||
474 | sprintf(name, "pimreg%u", mrt->id); | ||
232 | 475 | ||
233 | dev = alloc_netdev(0, "pimreg", reg_vif_setup); | 476 | dev = alloc_netdev(0, name, reg_vif_setup); |
234 | 477 | ||
235 | if (dev == NULL) | 478 | if (dev == NULL) |
236 | return NULL; | 479 | return NULL; |
@@ -275,17 +518,17 @@ failure: | |||
275 | * @notify: Set to 1, if the caller is a notifier_call | 518 | * @notify: Set to 1, if the caller is a notifier_call |
276 | */ | 519 | */ |
277 | 520 | ||
278 | static int vif_delete(struct net *net, int vifi, int notify, | 521 | static int vif_delete(struct mr_table *mrt, int vifi, int notify, |
279 | struct list_head *head) | 522 | struct list_head *head) |
280 | { | 523 | { |
281 | struct vif_device *v; | 524 | struct vif_device *v; |
282 | struct net_device *dev; | 525 | struct net_device *dev; |
283 | struct in_device *in_dev; | 526 | struct in_device *in_dev; |
284 | 527 | ||
285 | if (vifi < 0 || vifi >= net->ipv4.maxvif) | 528 | if (vifi < 0 || vifi >= mrt->maxvif) |
286 | return -EADDRNOTAVAIL; | 529 | return -EADDRNOTAVAIL; |
287 | 530 | ||
288 | v = &net->ipv4.vif_table[vifi]; | 531 | v = &mrt->vif_table[vifi]; |
289 | 532 | ||
290 | write_lock_bh(&mrt_lock); | 533 | write_lock_bh(&mrt_lock); |
291 | dev = v->dev; | 534 | dev = v->dev; |
@@ -297,17 +540,17 @@ static int vif_delete(struct net *net, int vifi, int notify, | |||
297 | } | 540 | } |
298 | 541 | ||
299 | #ifdef CONFIG_IP_PIMSM | 542 | #ifdef CONFIG_IP_PIMSM |
300 | if (vifi == net->ipv4.mroute_reg_vif_num) | 543 | if (vifi == mrt->mroute_reg_vif_num) |
301 | net->ipv4.mroute_reg_vif_num = -1; | 544 | mrt->mroute_reg_vif_num = -1; |
302 | #endif | 545 | #endif |
303 | 546 | ||
304 | if (vifi+1 == net->ipv4.maxvif) { | 547 | if (vifi+1 == mrt->maxvif) { |
305 | int tmp; | 548 | int tmp; |
306 | for (tmp=vifi-1; tmp>=0; tmp--) { | 549 | for (tmp=vifi-1; tmp>=0; tmp--) { |
307 | if (VIF_EXISTS(net, tmp)) | 550 | if (VIF_EXISTS(mrt, tmp)) |
308 | break; | 551 | break; |
309 | } | 552 | } |
310 | net->ipv4.maxvif = tmp+1; | 553 | mrt->maxvif = tmp+1; |
311 | } | 554 | } |
312 | 555 | ||
313 | write_unlock_bh(&mrt_lock); | 556 | write_unlock_bh(&mrt_lock); |
@@ -328,7 +571,6 @@ static int vif_delete(struct net *net, int vifi, int notify, | |||
328 | 571 | ||
329 | static inline void ipmr_cache_free(struct mfc_cache *c) | 572 | static inline void ipmr_cache_free(struct mfc_cache *c) |
330 | { | 573 | { |
331 | release_net(mfc_net(c)); | ||
332 | kmem_cache_free(mrt_cachep, c); | 574 | kmem_cache_free(mrt_cachep, c); |
333 | } | 575 | } |
334 | 576 | ||
@@ -336,13 +578,13 @@ static inline void ipmr_cache_free(struct mfc_cache *c) | |||
336 | and reporting error to netlink readers. | 578 | and reporting error to netlink readers. |
337 | */ | 579 | */ |
338 | 580 | ||
339 | static void ipmr_destroy_unres(struct mfc_cache *c) | 581 | static void ipmr_destroy_unres(struct mr_table *mrt, struct mfc_cache *c) |
340 | { | 582 | { |
583 | struct net *net = NULL; //mrt->net; | ||
341 | struct sk_buff *skb; | 584 | struct sk_buff *skb; |
342 | struct nlmsgerr *e; | 585 | struct nlmsgerr *e; |
343 | struct net *net = mfc_net(c); | ||
344 | 586 | ||
345 | atomic_dec(&net->ipv4.cache_resolve_queue_len); | 587 | atomic_dec(&mrt->cache_resolve_queue_len); |
346 | 588 | ||
347 | while ((skb = skb_dequeue(&c->mfc_un.unres.unresolved))) { | 589 | while ((skb = skb_dequeue(&c->mfc_un.unres.unresolved))) { |
348 | if (ip_hdr(skb)->version == 0) { | 590 | if (ip_hdr(skb)->version == 0) { |
@@ -363,42 +605,40 @@ static void ipmr_destroy_unres(struct mfc_cache *c) | |||
363 | } | 605 | } |
364 | 606 | ||
365 | 607 | ||
366 | /* Single timer process for all the unresolved queue. */ | 608 | /* Timer process for the unresolved queue. */ |
367 | 609 | ||
368 | static void ipmr_expire_process(unsigned long dummy) | 610 | static void ipmr_expire_process(unsigned long arg) |
369 | { | 611 | { |
612 | struct mr_table *mrt = (struct mr_table *)arg; | ||
370 | unsigned long now; | 613 | unsigned long now; |
371 | unsigned long expires; | 614 | unsigned long expires; |
372 | struct mfc_cache *c, **cp; | 615 | struct mfc_cache *c, *next; |
373 | 616 | ||
374 | if (!spin_trylock(&mfc_unres_lock)) { | 617 | if (!spin_trylock(&mfc_unres_lock)) { |
375 | mod_timer(&ipmr_expire_timer, jiffies+HZ/10); | 618 | mod_timer(&mrt->ipmr_expire_timer, jiffies+HZ/10); |
376 | return; | 619 | return; |
377 | } | 620 | } |
378 | 621 | ||
379 | if (mfc_unres_queue == NULL) | 622 | if (list_empty(&mrt->mfc_unres_queue)) |
380 | goto out; | 623 | goto out; |
381 | 624 | ||
382 | now = jiffies; | 625 | now = jiffies; |
383 | expires = 10*HZ; | 626 | expires = 10*HZ; |
384 | cp = &mfc_unres_queue; | ||
385 | 627 | ||
386 | while ((c=*cp) != NULL) { | 628 | list_for_each_entry_safe(c, next, &mrt->mfc_unres_queue, list) { |
387 | if (time_after(c->mfc_un.unres.expires, now)) { | 629 | if (time_after(c->mfc_un.unres.expires, now)) { |
388 | unsigned long interval = c->mfc_un.unres.expires - now; | 630 | unsigned long interval = c->mfc_un.unres.expires - now; |
389 | if (interval < expires) | 631 | if (interval < expires) |
390 | expires = interval; | 632 | expires = interval; |
391 | cp = &c->next; | ||
392 | continue; | 633 | continue; |
393 | } | 634 | } |
394 | 635 | ||
395 | *cp = c->next; | 636 | list_del(&c->list); |
396 | 637 | ipmr_destroy_unres(mrt, c); | |
397 | ipmr_destroy_unres(c); | ||
398 | } | 638 | } |
399 | 639 | ||
400 | if (mfc_unres_queue != NULL) | 640 | if (!list_empty(&mrt->mfc_unres_queue)) |
401 | mod_timer(&ipmr_expire_timer, jiffies + expires); | 641 | mod_timer(&mrt->ipmr_expire_timer, jiffies + expires); |
402 | 642 | ||
403 | out: | 643 | out: |
404 | spin_unlock(&mfc_unres_lock); | 644 | spin_unlock(&mfc_unres_lock); |
@@ -406,17 +646,17 @@ out: | |||
406 | 646 | ||
407 | /* Fill oifs list. It is called under write locked mrt_lock. */ | 647 | /* Fill oifs list. It is called under write locked mrt_lock. */ |
408 | 648 | ||
409 | static void ipmr_update_thresholds(struct mfc_cache *cache, unsigned char *ttls) | 649 | static void ipmr_update_thresholds(struct mr_table *mrt, struct mfc_cache *cache, |
650 | unsigned char *ttls) | ||
410 | { | 651 | { |
411 | int vifi; | 652 | int vifi; |
412 | struct net *net = mfc_net(cache); | ||
413 | 653 | ||
414 | cache->mfc_un.res.minvif = MAXVIFS; | 654 | cache->mfc_un.res.minvif = MAXVIFS; |
415 | cache->mfc_un.res.maxvif = 0; | 655 | cache->mfc_un.res.maxvif = 0; |
416 | memset(cache->mfc_un.res.ttls, 255, MAXVIFS); | 656 | memset(cache->mfc_un.res.ttls, 255, MAXVIFS); |
417 | 657 | ||
418 | for (vifi = 0; vifi < net->ipv4.maxvif; vifi++) { | 658 | for (vifi = 0; vifi < mrt->maxvif; vifi++) { |
419 | if (VIF_EXISTS(net, vifi) && | 659 | if (VIF_EXISTS(mrt, vifi) && |
420 | ttls[vifi] && ttls[vifi] < 255) { | 660 | ttls[vifi] && ttls[vifi] < 255) { |
421 | cache->mfc_un.res.ttls[vifi] = ttls[vifi]; | 661 | cache->mfc_un.res.ttls[vifi] = ttls[vifi]; |
422 | if (cache->mfc_un.res.minvif > vifi) | 662 | if (cache->mfc_un.res.minvif > vifi) |
@@ -427,16 +667,17 @@ static void ipmr_update_thresholds(struct mfc_cache *cache, unsigned char *ttls) | |||
427 | } | 667 | } |
428 | } | 668 | } |
429 | 669 | ||
430 | static int vif_add(struct net *net, struct vifctl *vifc, int mrtsock) | 670 | static int vif_add(struct net *net, struct mr_table *mrt, |
671 | struct vifctl *vifc, int mrtsock) | ||
431 | { | 672 | { |
432 | int vifi = vifc->vifc_vifi; | 673 | int vifi = vifc->vifc_vifi; |
433 | struct vif_device *v = &net->ipv4.vif_table[vifi]; | 674 | struct vif_device *v = &mrt->vif_table[vifi]; |
434 | struct net_device *dev; | 675 | struct net_device *dev; |
435 | struct in_device *in_dev; | 676 | struct in_device *in_dev; |
436 | int err; | 677 | int err; |
437 | 678 | ||
438 | /* Is vif busy ? */ | 679 | /* Is vif busy ? */ |
439 | if (VIF_EXISTS(net, vifi)) | 680 | if (VIF_EXISTS(mrt, vifi)) |
440 | return -EADDRINUSE; | 681 | return -EADDRINUSE; |
441 | 682 | ||
442 | switch (vifc->vifc_flags) { | 683 | switch (vifc->vifc_flags) { |
@@ -446,9 +687,9 @@ static int vif_add(struct net *net, struct vifctl *vifc, int mrtsock) | |||
446 | * Special Purpose VIF in PIM | 687 | * Special Purpose VIF in PIM |
447 | * All the packets will be sent to the daemon | 688 | * All the packets will be sent to the daemon |
448 | */ | 689 | */ |
449 | if (net->ipv4.mroute_reg_vif_num >= 0) | 690 | if (mrt->mroute_reg_vif_num >= 0) |
450 | return -EADDRINUSE; | 691 | return -EADDRINUSE; |
451 | dev = ipmr_reg_vif(net); | 692 | dev = ipmr_reg_vif(net, mrt); |
452 | if (!dev) | 693 | if (!dev) |
453 | return -ENOBUFS; | 694 | return -ENOBUFS; |
454 | err = dev_set_allmulti(dev, 1); | 695 | err = dev_set_allmulti(dev, 1); |
@@ -524,49 +765,47 @@ static int vif_add(struct net *net, struct vifctl *vifc, int mrtsock) | |||
524 | v->dev = dev; | 765 | v->dev = dev; |
525 | #ifdef CONFIG_IP_PIMSM | 766 | #ifdef CONFIG_IP_PIMSM |
526 | if (v->flags&VIFF_REGISTER) | 767 | if (v->flags&VIFF_REGISTER) |
527 | net->ipv4.mroute_reg_vif_num = vifi; | 768 | mrt->mroute_reg_vif_num = vifi; |
528 | #endif | 769 | #endif |
529 | if (vifi+1 > net->ipv4.maxvif) | 770 | if (vifi+1 > mrt->maxvif) |
530 | net->ipv4.maxvif = vifi+1; | 771 | mrt->maxvif = vifi+1; |
531 | write_unlock_bh(&mrt_lock); | 772 | write_unlock_bh(&mrt_lock); |
532 | return 0; | 773 | return 0; |
533 | } | 774 | } |
534 | 775 | ||
535 | static struct mfc_cache *ipmr_cache_find(struct net *net, | 776 | static struct mfc_cache *ipmr_cache_find(struct mr_table *mrt, |
536 | __be32 origin, | 777 | __be32 origin, |
537 | __be32 mcastgrp) | 778 | __be32 mcastgrp) |
538 | { | 779 | { |
539 | int line = MFC_HASH(mcastgrp, origin); | 780 | int line = MFC_HASH(mcastgrp, origin); |
540 | struct mfc_cache *c; | 781 | struct mfc_cache *c; |
541 | 782 | ||
542 | for (c = net->ipv4.mfc_cache_array[line]; c; c = c->next) { | 783 | list_for_each_entry(c, &mrt->mfc_cache_array[line], list) { |
543 | if (c->mfc_origin==origin && c->mfc_mcastgrp==mcastgrp) | 784 | if (c->mfc_origin == origin && c->mfc_mcastgrp == mcastgrp) |
544 | break; | 785 | return c; |
545 | } | 786 | } |
546 | return c; | 787 | return NULL; |
547 | } | 788 | } |
548 | 789 | ||
549 | /* | 790 | /* |
550 | * Allocate a multicast cache entry | 791 | * Allocate a multicast cache entry |
551 | */ | 792 | */ |
552 | static struct mfc_cache *ipmr_cache_alloc(struct net *net) | 793 | static struct mfc_cache *ipmr_cache_alloc(void) |
553 | { | 794 | { |
554 | struct mfc_cache *c = kmem_cache_zalloc(mrt_cachep, GFP_KERNEL); | 795 | struct mfc_cache *c = kmem_cache_zalloc(mrt_cachep, GFP_KERNEL); |
555 | if (c == NULL) | 796 | if (c == NULL) |
556 | return NULL; | 797 | return NULL; |
557 | c->mfc_un.res.minvif = MAXVIFS; | 798 | c->mfc_un.res.minvif = MAXVIFS; |
558 | mfc_net_set(c, net); | ||
559 | return c; | 799 | return c; |
560 | } | 800 | } |
561 | 801 | ||
562 | static struct mfc_cache *ipmr_cache_alloc_unres(struct net *net) | 802 | static struct mfc_cache *ipmr_cache_alloc_unres(void) |
563 | { | 803 | { |
564 | struct mfc_cache *c = kmem_cache_zalloc(mrt_cachep, GFP_ATOMIC); | 804 | struct mfc_cache *c = kmem_cache_zalloc(mrt_cachep, GFP_ATOMIC); |
565 | if (c == NULL) | 805 | if (c == NULL) |
566 | return NULL; | 806 | return NULL; |
567 | skb_queue_head_init(&c->mfc_un.unres.unresolved); | 807 | skb_queue_head_init(&c->mfc_un.unres.unresolved); |
568 | c->mfc_un.unres.expires = jiffies + 10*HZ; | 808 | c->mfc_un.unres.expires = jiffies + 10*HZ; |
569 | mfc_net_set(c, net); | ||
570 | return c; | 809 | return c; |
571 | } | 810 | } |
572 | 811 | ||
@@ -574,7 +813,8 @@ static struct mfc_cache *ipmr_cache_alloc_unres(struct net *net) | |||
574 | * A cache entry has gone into a resolved state from queued | 813 | * A cache entry has gone into a resolved state from queued |
575 | */ | 814 | */ |
576 | 815 | ||
577 | static void ipmr_cache_resolve(struct mfc_cache *uc, struct mfc_cache *c) | 816 | static void ipmr_cache_resolve(struct net *net, struct mr_table *mrt, |
817 | struct mfc_cache *uc, struct mfc_cache *c) | ||
578 | { | 818 | { |
579 | struct sk_buff *skb; | 819 | struct sk_buff *skb; |
580 | struct nlmsgerr *e; | 820 | struct nlmsgerr *e; |
@@ -587,7 +827,7 @@ static void ipmr_cache_resolve(struct mfc_cache *uc, struct mfc_cache *c) | |||
587 | if (ip_hdr(skb)->version == 0) { | 827 | if (ip_hdr(skb)->version == 0) { |
588 | struct nlmsghdr *nlh = (struct nlmsghdr *)skb_pull(skb, sizeof(struct iphdr)); | 828 | struct nlmsghdr *nlh = (struct nlmsghdr *)skb_pull(skb, sizeof(struct iphdr)); |
589 | 829 | ||
590 | if (ipmr_fill_mroute(skb, c, NLMSG_DATA(nlh)) > 0) { | 830 | if (ipmr_fill_mroute(mrt, skb, c, NLMSG_DATA(nlh)) > 0) { |
591 | nlh->nlmsg_len = (skb_tail_pointer(skb) - | 831 | nlh->nlmsg_len = (skb_tail_pointer(skb) - |
592 | (u8 *)nlh); | 832 | (u8 *)nlh); |
593 | } else { | 833 | } else { |
@@ -599,9 +839,9 @@ static void ipmr_cache_resolve(struct mfc_cache *uc, struct mfc_cache *c) | |||
599 | memset(&e->msg, 0, sizeof(e->msg)); | 839 | memset(&e->msg, 0, sizeof(e->msg)); |
600 | } | 840 | } |
601 | 841 | ||
602 | rtnl_unicast(skb, mfc_net(c), NETLINK_CB(skb).pid); | 842 | rtnl_unicast(skb, net, NETLINK_CB(skb).pid); |
603 | } else | 843 | } else |
604 | ip_mr_forward(skb, c, 0); | 844 | ip_mr_forward(net, mrt, skb, c, 0); |
605 | } | 845 | } |
606 | } | 846 | } |
607 | 847 | ||
@@ -612,7 +852,7 @@ static void ipmr_cache_resolve(struct mfc_cache *uc, struct mfc_cache *c) | |||
612 | * Called under mrt_lock. | 852 | * Called under mrt_lock. |
613 | */ | 853 | */ |
614 | 854 | ||
615 | static int ipmr_cache_report(struct net *net, | 855 | static int ipmr_cache_report(struct mr_table *mrt, |
616 | struct sk_buff *pkt, vifi_t vifi, int assert) | 856 | struct sk_buff *pkt, vifi_t vifi, int assert) |
617 | { | 857 | { |
618 | struct sk_buff *skb; | 858 | struct sk_buff *skb; |
@@ -645,7 +885,7 @@ static int ipmr_cache_report(struct net *net, | |||
645 | memcpy(msg, skb_network_header(pkt), sizeof(struct iphdr)); | 885 | memcpy(msg, skb_network_header(pkt), sizeof(struct iphdr)); |
646 | msg->im_msgtype = IGMPMSG_WHOLEPKT; | 886 | msg->im_msgtype = IGMPMSG_WHOLEPKT; |
647 | msg->im_mbz = 0; | 887 | msg->im_mbz = 0; |
648 | msg->im_vif = net->ipv4.mroute_reg_vif_num; | 888 | msg->im_vif = mrt->mroute_reg_vif_num; |
649 | ip_hdr(skb)->ihl = sizeof(struct iphdr) >> 2; | 889 | ip_hdr(skb)->ihl = sizeof(struct iphdr) >> 2; |
650 | ip_hdr(skb)->tot_len = htons(ntohs(ip_hdr(pkt)->tot_len) + | 890 | ip_hdr(skb)->tot_len = htons(ntohs(ip_hdr(pkt)->tot_len) + |
651 | sizeof(struct iphdr)); | 891 | sizeof(struct iphdr)); |
@@ -677,7 +917,7 @@ static int ipmr_cache_report(struct net *net, | |||
677 | skb->transport_header = skb->network_header; | 917 | skb->transport_header = skb->network_header; |
678 | } | 918 | } |
679 | 919 | ||
680 | if (net->ipv4.mroute_sk == NULL) { | 920 | if (mrt->mroute_sk == NULL) { |
681 | kfree_skb(skb); | 921 | kfree_skb(skb); |
682 | return -EINVAL; | 922 | return -EINVAL; |
683 | } | 923 | } |
@@ -685,7 +925,7 @@ static int ipmr_cache_report(struct net *net, | |||
685 | /* | 925 | /* |
686 | * Deliver to mrouted | 926 | * Deliver to mrouted |
687 | */ | 927 | */ |
688 | ret = sock_queue_rcv_skb(net->ipv4.mroute_sk, skb); | 928 | ret = sock_queue_rcv_skb(mrt->mroute_sk, skb); |
689 | if (ret < 0) { | 929 | if (ret < 0) { |
690 | if (net_ratelimit()) | 930 | if (net_ratelimit()) |
691 | printk(KERN_WARNING "mroute: pending queue full, dropping entries.\n"); | 931 | printk(KERN_WARNING "mroute: pending queue full, dropping entries.\n"); |
@@ -700,27 +940,29 @@ static int ipmr_cache_report(struct net *net, | |||
700 | */ | 940 | */ |
701 | 941 | ||
702 | static int | 942 | static int |
703 | ipmr_cache_unresolved(struct net *net, vifi_t vifi, struct sk_buff *skb) | 943 | ipmr_cache_unresolved(struct mr_table *mrt, vifi_t vifi, struct sk_buff *skb) |
704 | { | 944 | { |
945 | bool found = false; | ||
705 | int err; | 946 | int err; |
706 | struct mfc_cache *c; | 947 | struct mfc_cache *c; |
707 | const struct iphdr *iph = ip_hdr(skb); | 948 | const struct iphdr *iph = ip_hdr(skb); |
708 | 949 | ||
709 | spin_lock_bh(&mfc_unres_lock); | 950 | spin_lock_bh(&mfc_unres_lock); |
710 | for (c=mfc_unres_queue; c; c=c->next) { | 951 | list_for_each_entry(c, &mrt->mfc_unres_queue, list) { |
711 | if (net_eq(mfc_net(c), net) && | 952 | if (c->mfc_mcastgrp == iph->daddr && |
712 | c->mfc_mcastgrp == iph->daddr && | 953 | c->mfc_origin == iph->saddr) { |
713 | c->mfc_origin == iph->saddr) | 954 | found = true; |
714 | break; | 955 | break; |
956 | } | ||
715 | } | 957 | } |
716 | 958 | ||
717 | if (c == NULL) { | 959 | if (!found) { |
718 | /* | 960 | /* |
719 | * Create a new entry if allowable | 961 | * Create a new entry if allowable |
720 | */ | 962 | */ |
721 | 963 | ||
722 | if (atomic_read(&net->ipv4.cache_resolve_queue_len) >= 10 || | 964 | if (atomic_read(&mrt->cache_resolve_queue_len) >= 10 || |
723 | (c = ipmr_cache_alloc_unres(net)) == NULL) { | 965 | (c = ipmr_cache_alloc_unres()) == NULL) { |
724 | spin_unlock_bh(&mfc_unres_lock); | 966 | spin_unlock_bh(&mfc_unres_lock); |
725 | 967 | ||
726 | kfree_skb(skb); | 968 | kfree_skb(skb); |
@@ -737,7 +979,7 @@ ipmr_cache_unresolved(struct net *net, vifi_t vifi, struct sk_buff *skb) | |||
737 | /* | 979 | /* |
738 | * Reflect first query at mrouted. | 980 | * Reflect first query at mrouted. |
739 | */ | 981 | */ |
740 | err = ipmr_cache_report(net, skb, vifi, IGMPMSG_NOCACHE); | 982 | err = ipmr_cache_report(mrt, skb, vifi, IGMPMSG_NOCACHE); |
741 | if (err < 0) { | 983 | if (err < 0) { |
742 | /* If the report failed throw the cache entry | 984 | /* If the report failed throw the cache entry |
743 | out - Brad Parker | 985 | out - Brad Parker |
@@ -749,11 +991,10 @@ ipmr_cache_unresolved(struct net *net, vifi_t vifi, struct sk_buff *skb) | |||
749 | return err; | 991 | return err; |
750 | } | 992 | } |
751 | 993 | ||
752 | atomic_inc(&net->ipv4.cache_resolve_queue_len); | 994 | atomic_inc(&mrt->cache_resolve_queue_len); |
753 | c->next = mfc_unres_queue; | 995 | list_add(&c->list, &mrt->mfc_unres_queue); |
754 | mfc_unres_queue = c; | ||
755 | 996 | ||
756 | mod_timer(&ipmr_expire_timer, c->mfc_un.unres.expires); | 997 | mod_timer(&mrt->ipmr_expire_timer, c->mfc_un.unres.expires); |
757 | } | 998 | } |
758 | 999 | ||
759 | /* | 1000 | /* |
@@ -775,19 +1016,18 @@ ipmr_cache_unresolved(struct net *net, vifi_t vifi, struct sk_buff *skb) | |||
775 | * MFC cache manipulation by user space mroute daemon | 1016 | * MFC cache manipulation by user space mroute daemon |
776 | */ | 1017 | */ |
777 | 1018 | ||
778 | static int ipmr_mfc_delete(struct net *net, struct mfcctl *mfc) | 1019 | static int ipmr_mfc_delete(struct mr_table *mrt, struct mfcctl *mfc) |
779 | { | 1020 | { |
780 | int line; | 1021 | int line; |
781 | struct mfc_cache *c, **cp; | 1022 | struct mfc_cache *c, *next; |
782 | 1023 | ||
783 | line = MFC_HASH(mfc->mfcc_mcastgrp.s_addr, mfc->mfcc_origin.s_addr); | 1024 | line = MFC_HASH(mfc->mfcc_mcastgrp.s_addr, mfc->mfcc_origin.s_addr); |
784 | 1025 | ||
785 | for (cp = &net->ipv4.mfc_cache_array[line]; | 1026 | list_for_each_entry_safe(c, next, &mrt->mfc_cache_array[line], list) { |
786 | (c = *cp) != NULL; cp = &c->next) { | ||
787 | if (c->mfc_origin == mfc->mfcc_origin.s_addr && | 1027 | if (c->mfc_origin == mfc->mfcc_origin.s_addr && |
788 | c->mfc_mcastgrp == mfc->mfcc_mcastgrp.s_addr) { | 1028 | c->mfc_mcastgrp == mfc->mfcc_mcastgrp.s_addr) { |
789 | write_lock_bh(&mrt_lock); | 1029 | write_lock_bh(&mrt_lock); |
790 | *cp = c->next; | 1030 | list_del(&c->list); |
791 | write_unlock_bh(&mrt_lock); | 1031 | write_unlock_bh(&mrt_lock); |
792 | 1032 | ||
793 | ipmr_cache_free(c); | 1033 | ipmr_cache_free(c); |
@@ -797,24 +1037,30 @@ static int ipmr_mfc_delete(struct net *net, struct mfcctl *mfc) | |||
797 | return -ENOENT; | 1037 | return -ENOENT; |
798 | } | 1038 | } |
799 | 1039 | ||
800 | static int ipmr_mfc_add(struct net *net, struct mfcctl *mfc, int mrtsock) | 1040 | static int ipmr_mfc_add(struct net *net, struct mr_table *mrt, |
1041 | struct mfcctl *mfc, int mrtsock) | ||
801 | { | 1042 | { |
1043 | bool found = false; | ||
802 | int line; | 1044 | int line; |
803 | struct mfc_cache *uc, *c, **cp; | 1045 | struct mfc_cache *uc, *c; |
1046 | |||
1047 | if (mfc->mfcc_parent >= MAXVIFS) | ||
1048 | return -ENFILE; | ||
804 | 1049 | ||
805 | line = MFC_HASH(mfc->mfcc_mcastgrp.s_addr, mfc->mfcc_origin.s_addr); | 1050 | line = MFC_HASH(mfc->mfcc_mcastgrp.s_addr, mfc->mfcc_origin.s_addr); |
806 | 1051 | ||
807 | for (cp = &net->ipv4.mfc_cache_array[line]; | 1052 | list_for_each_entry(c, &mrt->mfc_cache_array[line], list) { |
808 | (c = *cp) != NULL; cp = &c->next) { | ||
809 | if (c->mfc_origin == mfc->mfcc_origin.s_addr && | 1053 | if (c->mfc_origin == mfc->mfcc_origin.s_addr && |
810 | c->mfc_mcastgrp == mfc->mfcc_mcastgrp.s_addr) | 1054 | c->mfc_mcastgrp == mfc->mfcc_mcastgrp.s_addr) { |
1055 | found = true; | ||
811 | break; | 1056 | break; |
1057 | } | ||
812 | } | 1058 | } |
813 | 1059 | ||
814 | if (c != NULL) { | 1060 | if (found) { |
815 | write_lock_bh(&mrt_lock); | 1061 | write_lock_bh(&mrt_lock); |
816 | c->mfc_parent = mfc->mfcc_parent; | 1062 | c->mfc_parent = mfc->mfcc_parent; |
817 | ipmr_update_thresholds(c, mfc->mfcc_ttls); | 1063 | ipmr_update_thresholds(mrt, c, mfc->mfcc_ttls); |
818 | if (!mrtsock) | 1064 | if (!mrtsock) |
819 | c->mfc_flags |= MFC_STATIC; | 1065 | c->mfc_flags |= MFC_STATIC; |
820 | write_unlock_bh(&mrt_lock); | 1066 | write_unlock_bh(&mrt_lock); |
@@ -824,20 +1070,19 @@ static int ipmr_mfc_add(struct net *net, struct mfcctl *mfc, int mrtsock) | |||
824 | if (!ipv4_is_multicast(mfc->mfcc_mcastgrp.s_addr)) | 1070 | if (!ipv4_is_multicast(mfc->mfcc_mcastgrp.s_addr)) |
825 | return -EINVAL; | 1071 | return -EINVAL; |
826 | 1072 | ||
827 | c = ipmr_cache_alloc(net); | 1073 | c = ipmr_cache_alloc(); |
828 | if (c == NULL) | 1074 | if (c == NULL) |
829 | return -ENOMEM; | 1075 | return -ENOMEM; |
830 | 1076 | ||
831 | c->mfc_origin = mfc->mfcc_origin.s_addr; | 1077 | c->mfc_origin = mfc->mfcc_origin.s_addr; |
832 | c->mfc_mcastgrp = mfc->mfcc_mcastgrp.s_addr; | 1078 | c->mfc_mcastgrp = mfc->mfcc_mcastgrp.s_addr; |
833 | c->mfc_parent = mfc->mfcc_parent; | 1079 | c->mfc_parent = mfc->mfcc_parent; |
834 | ipmr_update_thresholds(c, mfc->mfcc_ttls); | 1080 | ipmr_update_thresholds(mrt, c, mfc->mfcc_ttls); |
835 | if (!mrtsock) | 1081 | if (!mrtsock) |
836 | c->mfc_flags |= MFC_STATIC; | 1082 | c->mfc_flags |= MFC_STATIC; |
837 | 1083 | ||
838 | write_lock_bh(&mrt_lock); | 1084 | write_lock_bh(&mrt_lock); |
839 | c->next = net->ipv4.mfc_cache_array[line]; | 1085 | list_add(&c->list, &mrt->mfc_cache_array[line]); |
840 | net->ipv4.mfc_cache_array[line] = c; | ||
841 | write_unlock_bh(&mrt_lock); | 1086 | write_unlock_bh(&mrt_lock); |
842 | 1087 | ||
843 | /* | 1088 | /* |
@@ -845,22 +1090,20 @@ static int ipmr_mfc_add(struct net *net, struct mfcctl *mfc, int mrtsock) | |||
845 | * need to send on the frames and tidy up. | 1090 | * need to send on the frames and tidy up. |
846 | */ | 1091 | */ |
847 | spin_lock_bh(&mfc_unres_lock); | 1092 | spin_lock_bh(&mfc_unres_lock); |
848 | for (cp = &mfc_unres_queue; (uc=*cp) != NULL; | 1093 | list_for_each_entry(uc, &mrt->mfc_unres_queue, list) { |
849 | cp = &uc->next) { | 1094 | if (uc->mfc_origin == c->mfc_origin && |
850 | if (net_eq(mfc_net(uc), net) && | ||
851 | uc->mfc_origin == c->mfc_origin && | ||
852 | uc->mfc_mcastgrp == c->mfc_mcastgrp) { | 1095 | uc->mfc_mcastgrp == c->mfc_mcastgrp) { |
853 | *cp = uc->next; | 1096 | list_del(&uc->list); |
854 | atomic_dec(&net->ipv4.cache_resolve_queue_len); | 1097 | atomic_dec(&mrt->cache_resolve_queue_len); |
855 | break; | 1098 | break; |
856 | } | 1099 | } |
857 | } | 1100 | } |
858 | if (mfc_unres_queue == NULL) | 1101 | if (list_empty(&mrt->mfc_unres_queue)) |
859 | del_timer(&ipmr_expire_timer); | 1102 | del_timer(&mrt->ipmr_expire_timer); |
860 | spin_unlock_bh(&mfc_unres_lock); | 1103 | spin_unlock_bh(&mfc_unres_lock); |
861 | 1104 | ||
862 | if (uc) { | 1105 | if (uc) { |
863 | ipmr_cache_resolve(uc, c); | 1106 | ipmr_cache_resolve(net, mrt, uc, c); |
864 | ipmr_cache_free(uc); | 1107 | ipmr_cache_free(uc); |
865 | } | 1108 | } |
866 | return 0; | 1109 | return 0; |
@@ -870,53 +1113,41 @@ static int ipmr_mfc_add(struct net *net, struct mfcctl *mfc, int mrtsock) | |||
870 | * Close the multicast socket, and clear the vif tables etc | 1113 | * Close the multicast socket, and clear the vif tables etc |
871 | */ | 1114 | */ |
872 | 1115 | ||
873 | static void mroute_clean_tables(struct net *net) | 1116 | static void mroute_clean_tables(struct mr_table *mrt) |
874 | { | 1117 | { |
875 | int i; | 1118 | int i; |
876 | LIST_HEAD(list); | 1119 | LIST_HEAD(list); |
1120 | struct mfc_cache *c, *next; | ||
877 | 1121 | ||
878 | /* | 1122 | /* |
879 | * Shut down all active vif entries | 1123 | * Shut down all active vif entries |
880 | */ | 1124 | */ |
881 | for (i = 0; i < net->ipv4.maxvif; i++) { | 1125 | for (i = 0; i < mrt->maxvif; i++) { |
882 | if (!(net->ipv4.vif_table[i].flags&VIFF_STATIC)) | 1126 | if (!(mrt->vif_table[i].flags&VIFF_STATIC)) |
883 | vif_delete(net, i, 0, &list); | 1127 | vif_delete(mrt, i, 0, &list); |
884 | } | 1128 | } |
885 | unregister_netdevice_many(&list); | 1129 | unregister_netdevice_many(&list); |
886 | 1130 | ||
887 | /* | 1131 | /* |
888 | * Wipe the cache | 1132 | * Wipe the cache |
889 | */ | 1133 | */ |
890 | for (i=0; i<MFC_LINES; i++) { | 1134 | for (i = 0; i < MFC_LINES; i++) { |
891 | struct mfc_cache *c, **cp; | 1135 | list_for_each_entry_safe(c, next, &mrt->mfc_cache_array[i], list) { |
892 | 1136 | if (c->mfc_flags&MFC_STATIC) | |
893 | cp = &net->ipv4.mfc_cache_array[i]; | ||
894 | while ((c = *cp) != NULL) { | ||
895 | if (c->mfc_flags&MFC_STATIC) { | ||
896 | cp = &c->next; | ||
897 | continue; | 1137 | continue; |
898 | } | ||
899 | write_lock_bh(&mrt_lock); | 1138 | write_lock_bh(&mrt_lock); |
900 | *cp = c->next; | 1139 | list_del(&c->list); |
901 | write_unlock_bh(&mrt_lock); | 1140 | write_unlock_bh(&mrt_lock); |
902 | 1141 | ||
903 | ipmr_cache_free(c); | 1142 | ipmr_cache_free(c); |
904 | } | 1143 | } |
905 | } | 1144 | } |
906 | 1145 | ||
907 | if (atomic_read(&net->ipv4.cache_resolve_queue_len) != 0) { | 1146 | if (atomic_read(&mrt->cache_resolve_queue_len) != 0) { |
908 | struct mfc_cache *c, **cp; | ||
909 | |||
910 | spin_lock_bh(&mfc_unres_lock); | 1147 | spin_lock_bh(&mfc_unres_lock); |
911 | cp = &mfc_unres_queue; | 1148 | list_for_each_entry_safe(c, next, &mrt->mfc_unres_queue, list) { |
912 | while ((c = *cp) != NULL) { | 1149 | list_del(&c->list); |
913 | if (!net_eq(mfc_net(c), net)) { | 1150 | ipmr_destroy_unres(mrt, c); |
914 | cp = &c->next; | ||
915 | continue; | ||
916 | } | ||
917 | *cp = c->next; | ||
918 | |||
919 | ipmr_destroy_unres(c); | ||
920 | } | 1151 | } |
921 | spin_unlock_bh(&mfc_unres_lock); | 1152 | spin_unlock_bh(&mfc_unres_lock); |
922 | } | 1153 | } |
@@ -925,16 +1156,19 @@ static void mroute_clean_tables(struct net *net) | |||
925 | static void mrtsock_destruct(struct sock *sk) | 1156 | static void mrtsock_destruct(struct sock *sk) |
926 | { | 1157 | { |
927 | struct net *net = sock_net(sk); | 1158 | struct net *net = sock_net(sk); |
1159 | struct mr_table *mrt; | ||
928 | 1160 | ||
929 | rtnl_lock(); | 1161 | rtnl_lock(); |
930 | if (sk == net->ipv4.mroute_sk) { | 1162 | ipmr_for_each_table(mrt, net) { |
931 | IPV4_DEVCONF_ALL(net, MC_FORWARDING)--; | 1163 | if (sk == mrt->mroute_sk) { |
1164 | IPV4_DEVCONF_ALL(net, MC_FORWARDING)--; | ||
932 | 1165 | ||
933 | write_lock_bh(&mrt_lock); | 1166 | write_lock_bh(&mrt_lock); |
934 | net->ipv4.mroute_sk = NULL; | 1167 | mrt->mroute_sk = NULL; |
935 | write_unlock_bh(&mrt_lock); | 1168 | write_unlock_bh(&mrt_lock); |
936 | 1169 | ||
937 | mroute_clean_tables(net); | 1170 | mroute_clean_tables(mrt); |
1171 | } | ||
938 | } | 1172 | } |
939 | rtnl_unlock(); | 1173 | rtnl_unlock(); |
940 | } | 1174 | } |
@@ -952,9 +1186,14 @@ int ip_mroute_setsockopt(struct sock *sk, int optname, char __user *optval, unsi | |||
952 | struct vifctl vif; | 1186 | struct vifctl vif; |
953 | struct mfcctl mfc; | 1187 | struct mfcctl mfc; |
954 | struct net *net = sock_net(sk); | 1188 | struct net *net = sock_net(sk); |
1189 | struct mr_table *mrt; | ||
1190 | |||
1191 | mrt = ipmr_get_table(net, raw_sk(sk)->ipmr_table ? : RT_TABLE_DEFAULT); | ||
1192 | if (mrt == NULL) | ||
1193 | return -ENOENT; | ||
955 | 1194 | ||
956 | if (optname != MRT_INIT) { | 1195 | if (optname != MRT_INIT) { |
957 | if (sk != net->ipv4.mroute_sk && !capable(CAP_NET_ADMIN)) | 1196 | if (sk != mrt->mroute_sk && !capable(CAP_NET_ADMIN)) |
958 | return -EACCES; | 1197 | return -EACCES; |
959 | } | 1198 | } |
960 | 1199 | ||
@@ -967,7 +1206,7 @@ int ip_mroute_setsockopt(struct sock *sk, int optname, char __user *optval, unsi | |||
967 | return -ENOPROTOOPT; | 1206 | return -ENOPROTOOPT; |
968 | 1207 | ||
969 | rtnl_lock(); | 1208 | rtnl_lock(); |
970 | if (net->ipv4.mroute_sk) { | 1209 | if (mrt->mroute_sk) { |
971 | rtnl_unlock(); | 1210 | rtnl_unlock(); |
972 | return -EADDRINUSE; | 1211 | return -EADDRINUSE; |
973 | } | 1212 | } |
@@ -975,7 +1214,7 @@ int ip_mroute_setsockopt(struct sock *sk, int optname, char __user *optval, unsi | |||
975 | ret = ip_ra_control(sk, 1, mrtsock_destruct); | 1214 | ret = ip_ra_control(sk, 1, mrtsock_destruct); |
976 | if (ret == 0) { | 1215 | if (ret == 0) { |
977 | write_lock_bh(&mrt_lock); | 1216 | write_lock_bh(&mrt_lock); |
978 | net->ipv4.mroute_sk = sk; | 1217 | mrt->mroute_sk = sk; |
979 | write_unlock_bh(&mrt_lock); | 1218 | write_unlock_bh(&mrt_lock); |
980 | 1219 | ||
981 | IPV4_DEVCONF_ALL(net, MC_FORWARDING)++; | 1220 | IPV4_DEVCONF_ALL(net, MC_FORWARDING)++; |
@@ -983,7 +1222,7 @@ int ip_mroute_setsockopt(struct sock *sk, int optname, char __user *optval, unsi | |||
983 | rtnl_unlock(); | 1222 | rtnl_unlock(); |
984 | return ret; | 1223 | return ret; |
985 | case MRT_DONE: | 1224 | case MRT_DONE: |
986 | if (sk != net->ipv4.mroute_sk) | 1225 | if (sk != mrt->mroute_sk) |
987 | return -EACCES; | 1226 | return -EACCES; |
988 | return ip_ra_control(sk, 0, NULL); | 1227 | return ip_ra_control(sk, 0, NULL); |
989 | case MRT_ADD_VIF: | 1228 | case MRT_ADD_VIF: |
@@ -996,9 +1235,9 @@ int ip_mroute_setsockopt(struct sock *sk, int optname, char __user *optval, unsi | |||
996 | return -ENFILE; | 1235 | return -ENFILE; |
997 | rtnl_lock(); | 1236 | rtnl_lock(); |
998 | if (optname == MRT_ADD_VIF) { | 1237 | if (optname == MRT_ADD_VIF) { |
999 | ret = vif_add(net, &vif, sk == net->ipv4.mroute_sk); | 1238 | ret = vif_add(net, mrt, &vif, sk == mrt->mroute_sk); |
1000 | } else { | 1239 | } else { |
1001 | ret = vif_delete(net, vif.vifc_vifi, 0, NULL); | 1240 | ret = vif_delete(mrt, vif.vifc_vifi, 0, NULL); |
1002 | } | 1241 | } |
1003 | rtnl_unlock(); | 1242 | rtnl_unlock(); |
1004 | return ret; | 1243 | return ret; |
@@ -1015,9 +1254,9 @@ int ip_mroute_setsockopt(struct sock *sk, int optname, char __user *optval, unsi | |||
1015 | return -EFAULT; | 1254 | return -EFAULT; |
1016 | rtnl_lock(); | 1255 | rtnl_lock(); |
1017 | if (optname == MRT_DEL_MFC) | 1256 | if (optname == MRT_DEL_MFC) |
1018 | ret = ipmr_mfc_delete(net, &mfc); | 1257 | ret = ipmr_mfc_delete(mrt, &mfc); |
1019 | else | 1258 | else |
1020 | ret = ipmr_mfc_add(net, &mfc, sk == net->ipv4.mroute_sk); | 1259 | ret = ipmr_mfc_add(net, mrt, &mfc, sk == mrt->mroute_sk); |
1021 | rtnl_unlock(); | 1260 | rtnl_unlock(); |
1022 | return ret; | 1261 | return ret; |
1023 | /* | 1262 | /* |
@@ -1028,7 +1267,7 @@ int ip_mroute_setsockopt(struct sock *sk, int optname, char __user *optval, unsi | |||
1028 | int v; | 1267 | int v; |
1029 | if (get_user(v,(int __user *)optval)) | 1268 | if (get_user(v,(int __user *)optval)) |
1030 | return -EFAULT; | 1269 | return -EFAULT; |
1031 | net->ipv4.mroute_do_assert = (v) ? 1 : 0; | 1270 | mrt->mroute_do_assert = (v) ? 1 : 0; |
1032 | return 0; | 1271 | return 0; |
1033 | } | 1272 | } |
1034 | #ifdef CONFIG_IP_PIMSM | 1273 | #ifdef CONFIG_IP_PIMSM |
@@ -1042,14 +1281,35 @@ int ip_mroute_setsockopt(struct sock *sk, int optname, char __user *optval, unsi | |||
1042 | 1281 | ||
1043 | rtnl_lock(); | 1282 | rtnl_lock(); |
1044 | ret = 0; | 1283 | ret = 0; |
1045 | if (v != net->ipv4.mroute_do_pim) { | 1284 | if (v != mrt->mroute_do_pim) { |
1046 | net->ipv4.mroute_do_pim = v; | 1285 | mrt->mroute_do_pim = v; |
1047 | net->ipv4.mroute_do_assert = v; | 1286 | mrt->mroute_do_assert = v; |
1048 | } | 1287 | } |
1049 | rtnl_unlock(); | 1288 | rtnl_unlock(); |
1050 | return ret; | 1289 | return ret; |
1051 | } | 1290 | } |
1052 | #endif | 1291 | #endif |
1292 | #ifdef CONFIG_IP_MROUTE_MULTIPLE_TABLES | ||
1293 | case MRT_TABLE: | ||
1294 | { | ||
1295 | u32 v; | ||
1296 | |||
1297 | if (optlen != sizeof(u32)) | ||
1298 | return -EINVAL; | ||
1299 | if (get_user(v, (u32 __user *)optval)) | ||
1300 | return -EFAULT; | ||
1301 | if (sk == mrt->mroute_sk) | ||
1302 | return -EBUSY; | ||
1303 | |||
1304 | rtnl_lock(); | ||
1305 | ret = 0; | ||
1306 | if (!ipmr_new_table(net, v)) | ||
1307 | ret = -ENOMEM; | ||
1308 | raw_sk(sk)->ipmr_table = v; | ||
1309 | rtnl_unlock(); | ||
1310 | return ret; | ||
1311 | } | ||
1312 | #endif | ||
1053 | /* | 1313 | /* |
1054 | * Spurious command, or MRT_VERSION which you cannot | 1314 | * Spurious command, or MRT_VERSION which you cannot |
1055 | * set. | 1315 | * set. |
@@ -1068,6 +1328,11 @@ int ip_mroute_getsockopt(struct sock *sk, int optname, char __user *optval, int | |||
1068 | int olr; | 1328 | int olr; |
1069 | int val; | 1329 | int val; |
1070 | struct net *net = sock_net(sk); | 1330 | struct net *net = sock_net(sk); |
1331 | struct mr_table *mrt; | ||
1332 | |||
1333 | mrt = ipmr_get_table(net, raw_sk(sk)->ipmr_table ? : RT_TABLE_DEFAULT); | ||
1334 | if (mrt == NULL) | ||
1335 | return -ENOENT; | ||
1071 | 1336 | ||
1072 | if (optname != MRT_VERSION && | 1337 | if (optname != MRT_VERSION && |
1073 | #ifdef CONFIG_IP_PIMSM | 1338 | #ifdef CONFIG_IP_PIMSM |
@@ -1089,10 +1354,10 @@ int ip_mroute_getsockopt(struct sock *sk, int optname, char __user *optval, int | |||
1089 | val = 0x0305; | 1354 | val = 0x0305; |
1090 | #ifdef CONFIG_IP_PIMSM | 1355 | #ifdef CONFIG_IP_PIMSM |
1091 | else if (optname == MRT_PIM) | 1356 | else if (optname == MRT_PIM) |
1092 | val = net->ipv4.mroute_do_pim; | 1357 | val = mrt->mroute_do_pim; |
1093 | #endif | 1358 | #endif |
1094 | else | 1359 | else |
1095 | val = net->ipv4.mroute_do_assert; | 1360 | val = mrt->mroute_do_assert; |
1096 | if (copy_to_user(optval, &val, olr)) | 1361 | if (copy_to_user(optval, &val, olr)) |
1097 | return -EFAULT; | 1362 | return -EFAULT; |
1098 | return 0; | 1363 | return 0; |
@@ -1109,16 +1374,21 @@ int ipmr_ioctl(struct sock *sk, int cmd, void __user *arg) | |||
1109 | struct vif_device *vif; | 1374 | struct vif_device *vif; |
1110 | struct mfc_cache *c; | 1375 | struct mfc_cache *c; |
1111 | struct net *net = sock_net(sk); | 1376 | struct net *net = sock_net(sk); |
1377 | struct mr_table *mrt; | ||
1378 | |||
1379 | mrt = ipmr_get_table(net, raw_sk(sk)->ipmr_table ? : RT_TABLE_DEFAULT); | ||
1380 | if (mrt == NULL) | ||
1381 | return -ENOENT; | ||
1112 | 1382 | ||
1113 | switch (cmd) { | 1383 | switch (cmd) { |
1114 | case SIOCGETVIFCNT: | 1384 | case SIOCGETVIFCNT: |
1115 | if (copy_from_user(&vr, arg, sizeof(vr))) | 1385 | if (copy_from_user(&vr, arg, sizeof(vr))) |
1116 | return -EFAULT; | 1386 | return -EFAULT; |
1117 | if (vr.vifi >= net->ipv4.maxvif) | 1387 | if (vr.vifi >= mrt->maxvif) |
1118 | return -EINVAL; | 1388 | return -EINVAL; |
1119 | read_lock(&mrt_lock); | 1389 | read_lock(&mrt_lock); |
1120 | vif = &net->ipv4.vif_table[vr.vifi]; | 1390 | vif = &mrt->vif_table[vr.vifi]; |
1121 | if (VIF_EXISTS(net, vr.vifi)) { | 1391 | if (VIF_EXISTS(mrt, vr.vifi)) { |
1122 | vr.icount = vif->pkt_in; | 1392 | vr.icount = vif->pkt_in; |
1123 | vr.ocount = vif->pkt_out; | 1393 | vr.ocount = vif->pkt_out; |
1124 | vr.ibytes = vif->bytes_in; | 1394 | vr.ibytes = vif->bytes_in; |
@@ -1136,7 +1406,7 @@ int ipmr_ioctl(struct sock *sk, int cmd, void __user *arg) | |||
1136 | return -EFAULT; | 1406 | return -EFAULT; |
1137 | 1407 | ||
1138 | read_lock(&mrt_lock); | 1408 | read_lock(&mrt_lock); |
1139 | c = ipmr_cache_find(net, sr.src.s_addr, sr.grp.s_addr); | 1409 | c = ipmr_cache_find(mrt, sr.src.s_addr, sr.grp.s_addr); |
1140 | if (c) { | 1410 | if (c) { |
1141 | sr.pktcnt = c->mfc_un.res.pkt; | 1411 | sr.pktcnt = c->mfc_un.res.pkt; |
1142 | sr.bytecnt = c->mfc_un.res.bytes; | 1412 | sr.bytecnt = c->mfc_un.res.bytes; |
@@ -1159,16 +1429,20 @@ static int ipmr_device_event(struct notifier_block *this, unsigned long event, v | |||
1159 | { | 1429 | { |
1160 | struct net_device *dev = ptr; | 1430 | struct net_device *dev = ptr; |
1161 | struct net *net = dev_net(dev); | 1431 | struct net *net = dev_net(dev); |
1432 | struct mr_table *mrt; | ||
1162 | struct vif_device *v; | 1433 | struct vif_device *v; |
1163 | int ct; | 1434 | int ct; |
1164 | LIST_HEAD(list); | 1435 | LIST_HEAD(list); |
1165 | 1436 | ||
1166 | if (event != NETDEV_UNREGISTER) | 1437 | if (event != NETDEV_UNREGISTER) |
1167 | return NOTIFY_DONE; | 1438 | return NOTIFY_DONE; |
1168 | v = &net->ipv4.vif_table[0]; | 1439 | |
1169 | for (ct = 0; ct < net->ipv4.maxvif; ct++, v++) { | 1440 | ipmr_for_each_table(mrt, net) { |
1170 | if (v->dev == dev) | 1441 | v = &mrt->vif_table[0]; |
1171 | vif_delete(net, ct, 1, &list); | 1442 | for (ct = 0; ct < mrt->maxvif; ct++, v++) { |
1443 | if (v->dev == dev) | ||
1444 | vif_delete(mrt, ct, 1, &list); | ||
1445 | } | ||
1172 | } | 1446 | } |
1173 | unregister_netdevice_many(&list); | 1447 | unregister_netdevice_many(&list); |
1174 | return NOTIFY_DONE; | 1448 | return NOTIFY_DONE; |
@@ -1227,11 +1501,11 @@ static inline int ipmr_forward_finish(struct sk_buff *skb) | |||
1227 | * Processing handlers for ipmr_forward | 1501 | * Processing handlers for ipmr_forward |
1228 | */ | 1502 | */ |
1229 | 1503 | ||
1230 | static void ipmr_queue_xmit(struct sk_buff *skb, struct mfc_cache *c, int vifi) | 1504 | static void ipmr_queue_xmit(struct net *net, struct mr_table *mrt, |
1505 | struct sk_buff *skb, struct mfc_cache *c, int vifi) | ||
1231 | { | 1506 | { |
1232 | struct net *net = mfc_net(c); | ||
1233 | const struct iphdr *iph = ip_hdr(skb); | 1507 | const struct iphdr *iph = ip_hdr(skb); |
1234 | struct vif_device *vif = &net->ipv4.vif_table[vifi]; | 1508 | struct vif_device *vif = &mrt->vif_table[vifi]; |
1235 | struct net_device *dev; | 1509 | struct net_device *dev; |
1236 | struct rtable *rt; | 1510 | struct rtable *rt; |
1237 | int encap = 0; | 1511 | int encap = 0; |
@@ -1245,7 +1519,7 @@ static void ipmr_queue_xmit(struct sk_buff *skb, struct mfc_cache *c, int vifi) | |||
1245 | vif->bytes_out += skb->len; | 1519 | vif->bytes_out += skb->len; |
1246 | vif->dev->stats.tx_bytes += skb->len; | 1520 | vif->dev->stats.tx_bytes += skb->len; |
1247 | vif->dev->stats.tx_packets++; | 1521 | vif->dev->stats.tx_packets++; |
1248 | ipmr_cache_report(net, skb, vifi, IGMPMSG_WHOLEPKT); | 1522 | ipmr_cache_report(mrt, skb, vifi, IGMPMSG_WHOLEPKT); |
1249 | goto out_free; | 1523 | goto out_free; |
1250 | } | 1524 | } |
1251 | #endif | 1525 | #endif |
@@ -1328,12 +1602,12 @@ out_free: | |||
1328 | return; | 1602 | return; |
1329 | } | 1603 | } |
1330 | 1604 | ||
1331 | static int ipmr_find_vif(struct net_device *dev) | 1605 | static int ipmr_find_vif(struct mr_table *mrt, struct net_device *dev) |
1332 | { | 1606 | { |
1333 | struct net *net = dev_net(dev); | ||
1334 | int ct; | 1607 | int ct; |
1335 | for (ct = net->ipv4.maxvif-1; ct >= 0; ct--) { | 1608 | |
1336 | if (net->ipv4.vif_table[ct].dev == dev) | 1609 | for (ct = mrt->maxvif-1; ct >= 0; ct--) { |
1610 | if (mrt->vif_table[ct].dev == dev) | ||
1337 | break; | 1611 | break; |
1338 | } | 1612 | } |
1339 | return ct; | 1613 | return ct; |
@@ -1341,11 +1615,12 @@ static int ipmr_find_vif(struct net_device *dev) | |||
1341 | 1615 | ||
1342 | /* "local" means that we should preserve one skb (for local delivery) */ | 1616 | /* "local" means that we should preserve one skb (for local delivery) */ |
1343 | 1617 | ||
1344 | static int ip_mr_forward(struct sk_buff *skb, struct mfc_cache *cache, int local) | 1618 | static int ip_mr_forward(struct net *net, struct mr_table *mrt, |
1619 | struct sk_buff *skb, struct mfc_cache *cache, | ||
1620 | int local) | ||
1345 | { | 1621 | { |
1346 | int psend = -1; | 1622 | int psend = -1; |
1347 | int vif, ct; | 1623 | int vif, ct; |
1348 | struct net *net = mfc_net(cache); | ||
1349 | 1624 | ||
1350 | vif = cache->mfc_parent; | 1625 | vif = cache->mfc_parent; |
1351 | cache->mfc_un.res.pkt++; | 1626 | cache->mfc_un.res.pkt++; |
@@ -1354,7 +1629,7 @@ static int ip_mr_forward(struct sk_buff *skb, struct mfc_cache *cache, int local | |||
1354 | /* | 1629 | /* |
1355 | * Wrong interface: drop packet and (maybe) send PIM assert. | 1630 | * Wrong interface: drop packet and (maybe) send PIM assert. |
1356 | */ | 1631 | */ |
1357 | if (net->ipv4.vif_table[vif].dev != skb->dev) { | 1632 | if (mrt->vif_table[vif].dev != skb->dev) { |
1358 | int true_vifi; | 1633 | int true_vifi; |
1359 | 1634 | ||
1360 | if (skb_rtable(skb)->fl.iif == 0) { | 1635 | if (skb_rtable(skb)->fl.iif == 0) { |
@@ -1373,26 +1648,26 @@ static int ip_mr_forward(struct sk_buff *skb, struct mfc_cache *cache, int local | |||
1373 | } | 1648 | } |
1374 | 1649 | ||
1375 | cache->mfc_un.res.wrong_if++; | 1650 | cache->mfc_un.res.wrong_if++; |
1376 | true_vifi = ipmr_find_vif(skb->dev); | 1651 | true_vifi = ipmr_find_vif(mrt, skb->dev); |
1377 | 1652 | ||
1378 | if (true_vifi >= 0 && net->ipv4.mroute_do_assert && | 1653 | if (true_vifi >= 0 && mrt->mroute_do_assert && |
1379 | /* pimsm uses asserts, when switching from RPT to SPT, | 1654 | /* pimsm uses asserts, when switching from RPT to SPT, |
1380 | so that we cannot check that packet arrived on an oif. | 1655 | so that we cannot check that packet arrived on an oif. |
1381 | It is bad, but otherwise we would need to move pretty | 1656 | It is bad, but otherwise we would need to move pretty |
1382 | large chunk of pimd to kernel. Ough... --ANK | 1657 | large chunk of pimd to kernel. Ough... --ANK |
1383 | */ | 1658 | */ |
1384 | (net->ipv4.mroute_do_pim || | 1659 | (mrt->mroute_do_pim || |
1385 | cache->mfc_un.res.ttls[true_vifi] < 255) && | 1660 | cache->mfc_un.res.ttls[true_vifi] < 255) && |
1386 | time_after(jiffies, | 1661 | time_after(jiffies, |
1387 | cache->mfc_un.res.last_assert + MFC_ASSERT_THRESH)) { | 1662 | cache->mfc_un.res.last_assert + MFC_ASSERT_THRESH)) { |
1388 | cache->mfc_un.res.last_assert = jiffies; | 1663 | cache->mfc_un.res.last_assert = jiffies; |
1389 | ipmr_cache_report(net, skb, true_vifi, IGMPMSG_WRONGVIF); | 1664 | ipmr_cache_report(mrt, skb, true_vifi, IGMPMSG_WRONGVIF); |
1390 | } | 1665 | } |
1391 | goto dont_forward; | 1666 | goto dont_forward; |
1392 | } | 1667 | } |
1393 | 1668 | ||
1394 | net->ipv4.vif_table[vif].pkt_in++; | 1669 | mrt->vif_table[vif].pkt_in++; |
1395 | net->ipv4.vif_table[vif].bytes_in += skb->len; | 1670 | mrt->vif_table[vif].bytes_in += skb->len; |
1396 | 1671 | ||
1397 | /* | 1672 | /* |
1398 | * Forward the frame | 1673 | * Forward the frame |
@@ -1402,7 +1677,8 @@ static int ip_mr_forward(struct sk_buff *skb, struct mfc_cache *cache, int local | |||
1402 | if (psend != -1) { | 1677 | if (psend != -1) { |
1403 | struct sk_buff *skb2 = skb_clone(skb, GFP_ATOMIC); | 1678 | struct sk_buff *skb2 = skb_clone(skb, GFP_ATOMIC); |
1404 | if (skb2) | 1679 | if (skb2) |
1405 | ipmr_queue_xmit(skb2, cache, psend); | 1680 | ipmr_queue_xmit(net, mrt, skb2, cache, |
1681 | psend); | ||
1406 | } | 1682 | } |
1407 | psend = ct; | 1683 | psend = ct; |
1408 | } | 1684 | } |
@@ -1411,9 +1687,9 @@ static int ip_mr_forward(struct sk_buff *skb, struct mfc_cache *cache, int local | |||
1411 | if (local) { | 1687 | if (local) { |
1412 | struct sk_buff *skb2 = skb_clone(skb, GFP_ATOMIC); | 1688 | struct sk_buff *skb2 = skb_clone(skb, GFP_ATOMIC); |
1413 | if (skb2) | 1689 | if (skb2) |
1414 | ipmr_queue_xmit(skb2, cache, psend); | 1690 | ipmr_queue_xmit(net, mrt, skb2, cache, psend); |
1415 | } else { | 1691 | } else { |
1416 | ipmr_queue_xmit(skb, cache, psend); | 1692 | ipmr_queue_xmit(net, mrt, skb, cache, psend); |
1417 | return 0; | 1693 | return 0; |
1418 | } | 1694 | } |
1419 | } | 1695 | } |
@@ -1434,6 +1710,8 @@ int ip_mr_input(struct sk_buff *skb) | |||
1434 | struct mfc_cache *cache; | 1710 | struct mfc_cache *cache; |
1435 | struct net *net = dev_net(skb->dev); | 1711 | struct net *net = dev_net(skb->dev); |
1436 | int local = skb_rtable(skb)->rt_flags & RTCF_LOCAL; | 1712 | int local = skb_rtable(skb)->rt_flags & RTCF_LOCAL; |
1713 | struct mr_table *mrt; | ||
1714 | int err; | ||
1437 | 1715 | ||
1438 | /* Packet is looped back after forward, it should not be | 1716 | /* Packet is looped back after forward, it should not be |
1439 | forwarded second time, but still can be delivered locally. | 1717 | forwarded second time, but still can be delivered locally. |
@@ -1441,6 +1719,10 @@ int ip_mr_input(struct sk_buff *skb) | |||
1441 | if (IPCB(skb)->flags&IPSKB_FORWARDED) | 1719 | if (IPCB(skb)->flags&IPSKB_FORWARDED) |
1442 | goto dont_forward; | 1720 | goto dont_forward; |
1443 | 1721 | ||
1722 | err = ipmr_fib_lookup(net, &skb_rtable(skb)->fl, &mrt); | ||
1723 | if (err < 0) | ||
1724 | return err; | ||
1725 | |||
1444 | if (!local) { | 1726 | if (!local) { |
1445 | if (IPCB(skb)->opt.router_alert) { | 1727 | if (IPCB(skb)->opt.router_alert) { |
1446 | if (ip_call_ra_chain(skb)) | 1728 | if (ip_call_ra_chain(skb)) |
@@ -1453,9 +1735,9 @@ int ip_mr_input(struct sk_buff *skb) | |||
1453 | that we can forward NO IGMP messages. | 1735 | that we can forward NO IGMP messages. |
1454 | */ | 1736 | */ |
1455 | read_lock(&mrt_lock); | 1737 | read_lock(&mrt_lock); |
1456 | if (net->ipv4.mroute_sk) { | 1738 | if (mrt->mroute_sk) { |
1457 | nf_reset(skb); | 1739 | nf_reset(skb); |
1458 | raw_rcv(net->ipv4.mroute_sk, skb); | 1740 | raw_rcv(mrt->mroute_sk, skb); |
1459 | read_unlock(&mrt_lock); | 1741 | read_unlock(&mrt_lock); |
1460 | return 0; | 1742 | return 0; |
1461 | } | 1743 | } |
@@ -1464,7 +1746,7 @@ int ip_mr_input(struct sk_buff *skb) | |||
1464 | } | 1746 | } |
1465 | 1747 | ||
1466 | read_lock(&mrt_lock); | 1748 | read_lock(&mrt_lock); |
1467 | cache = ipmr_cache_find(net, ip_hdr(skb)->saddr, ip_hdr(skb)->daddr); | 1749 | cache = ipmr_cache_find(mrt, ip_hdr(skb)->saddr, ip_hdr(skb)->daddr); |
1468 | 1750 | ||
1469 | /* | 1751 | /* |
1470 | * No usable cache entry | 1752 | * No usable cache entry |
@@ -1482,9 +1764,9 @@ int ip_mr_input(struct sk_buff *skb) | |||
1482 | skb = skb2; | 1764 | skb = skb2; |
1483 | } | 1765 | } |
1484 | 1766 | ||
1485 | vif = ipmr_find_vif(skb->dev); | 1767 | vif = ipmr_find_vif(mrt, skb->dev); |
1486 | if (vif >= 0) { | 1768 | if (vif >= 0) { |
1487 | int err = ipmr_cache_unresolved(net, vif, skb); | 1769 | int err = ipmr_cache_unresolved(mrt, vif, skb); |
1488 | read_unlock(&mrt_lock); | 1770 | read_unlock(&mrt_lock); |
1489 | 1771 | ||
1490 | return err; | 1772 | return err; |
@@ -1494,7 +1776,7 @@ int ip_mr_input(struct sk_buff *skb) | |||
1494 | return -ENODEV; | 1776 | return -ENODEV; |
1495 | } | 1777 | } |
1496 | 1778 | ||
1497 | ip_mr_forward(skb, cache, local); | 1779 | ip_mr_forward(net, mrt, skb, cache, local); |
1498 | 1780 | ||
1499 | read_unlock(&mrt_lock); | 1781 | read_unlock(&mrt_lock); |
1500 | 1782 | ||
@@ -1511,11 +1793,11 @@ dont_forward: | |||
1511 | } | 1793 | } |
1512 | 1794 | ||
1513 | #ifdef CONFIG_IP_PIMSM | 1795 | #ifdef CONFIG_IP_PIMSM |
1514 | static int __pim_rcv(struct sk_buff *skb, unsigned int pimlen) | 1796 | static int __pim_rcv(struct mr_table *mrt, struct sk_buff *skb, |
1797 | unsigned int pimlen) | ||
1515 | { | 1798 | { |
1516 | struct net_device *reg_dev = NULL; | 1799 | struct net_device *reg_dev = NULL; |
1517 | struct iphdr *encap; | 1800 | struct iphdr *encap; |
1518 | struct net *net = dev_net(skb->dev); | ||
1519 | 1801 | ||
1520 | encap = (struct iphdr *)(skb_transport_header(skb) + pimlen); | 1802 | encap = (struct iphdr *)(skb_transport_header(skb) + pimlen); |
1521 | /* | 1803 | /* |
@@ -1530,8 +1812,8 @@ static int __pim_rcv(struct sk_buff *skb, unsigned int pimlen) | |||
1530 | return 1; | 1812 | return 1; |
1531 | 1813 | ||
1532 | read_lock(&mrt_lock); | 1814 | read_lock(&mrt_lock); |
1533 | if (net->ipv4.mroute_reg_vif_num >= 0) | 1815 | if (mrt->mroute_reg_vif_num >= 0) |
1534 | reg_dev = net->ipv4.vif_table[net->ipv4.mroute_reg_vif_num].dev; | 1816 | reg_dev = mrt->vif_table[mrt->mroute_reg_vif_num].dev; |
1535 | if (reg_dev) | 1817 | if (reg_dev) |
1536 | dev_hold(reg_dev); | 1818 | dev_hold(reg_dev); |
1537 | read_unlock(&mrt_lock); | 1819 | read_unlock(&mrt_lock); |
@@ -1566,17 +1848,21 @@ int pim_rcv_v1(struct sk_buff * skb) | |||
1566 | { | 1848 | { |
1567 | struct igmphdr *pim; | 1849 | struct igmphdr *pim; |
1568 | struct net *net = dev_net(skb->dev); | 1850 | struct net *net = dev_net(skb->dev); |
1851 | struct mr_table *mrt; | ||
1569 | 1852 | ||
1570 | if (!pskb_may_pull(skb, sizeof(*pim) + sizeof(struct iphdr))) | 1853 | if (!pskb_may_pull(skb, sizeof(*pim) + sizeof(struct iphdr))) |
1571 | goto drop; | 1854 | goto drop; |
1572 | 1855 | ||
1573 | pim = igmp_hdr(skb); | 1856 | pim = igmp_hdr(skb); |
1574 | 1857 | ||
1575 | if (!net->ipv4.mroute_do_pim || | 1858 | if (ipmr_fib_lookup(net, &skb_rtable(skb)->fl, &mrt) < 0) |
1859 | goto drop; | ||
1860 | |||
1861 | if (!mrt->mroute_do_pim || | ||
1576 | pim->group != PIM_V1_VERSION || pim->code != PIM_V1_REGISTER) | 1862 | pim->group != PIM_V1_VERSION || pim->code != PIM_V1_REGISTER) |
1577 | goto drop; | 1863 | goto drop; |
1578 | 1864 | ||
1579 | if (__pim_rcv(skb, sizeof(*pim))) { | 1865 | if (__pim_rcv(mrt, skb, sizeof(*pim))) { |
1580 | drop: | 1866 | drop: |
1581 | kfree_skb(skb); | 1867 | kfree_skb(skb); |
1582 | } | 1868 | } |
@@ -1588,6 +1874,8 @@ drop: | |||
1588 | static int pim_rcv(struct sk_buff * skb) | 1874 | static int pim_rcv(struct sk_buff * skb) |
1589 | { | 1875 | { |
1590 | struct pimreghdr *pim; | 1876 | struct pimreghdr *pim; |
1877 | struct net *net = dev_net(skb->dev); | ||
1878 | struct mr_table *mrt; | ||
1591 | 1879 | ||
1592 | if (!pskb_may_pull(skb, sizeof(*pim) + sizeof(struct iphdr))) | 1880 | if (!pskb_may_pull(skb, sizeof(*pim) + sizeof(struct iphdr))) |
1593 | goto drop; | 1881 | goto drop; |
@@ -1599,7 +1887,10 @@ static int pim_rcv(struct sk_buff * skb) | |||
1599 | csum_fold(skb_checksum(skb, 0, skb->len, 0)))) | 1887 | csum_fold(skb_checksum(skb, 0, skb->len, 0)))) |
1600 | goto drop; | 1888 | goto drop; |
1601 | 1889 | ||
1602 | if (__pim_rcv(skb, sizeof(*pim))) { | 1890 | if (ipmr_fib_lookup(net, &skb_rtable(skb)->fl, &mrt) < 0) |
1891 | goto drop; | ||
1892 | |||
1893 | if (__pim_rcv(mrt, skb, sizeof(*pim))) { | ||
1603 | drop: | 1894 | drop: |
1604 | kfree_skb(skb); | 1895 | kfree_skb(skb); |
1605 | } | 1896 | } |
@@ -1608,28 +1899,31 @@ drop: | |||
1608 | #endif | 1899 | #endif |
1609 | 1900 | ||
1610 | static int | 1901 | static int |
1611 | ipmr_fill_mroute(struct sk_buff *skb, struct mfc_cache *c, struct rtmsg *rtm) | 1902 | ipmr_fill_mroute(struct mr_table *mrt, struct sk_buff *skb, struct mfc_cache *c, |
1903 | struct rtmsg *rtm) | ||
1612 | { | 1904 | { |
1613 | int ct; | 1905 | int ct; |
1614 | struct rtnexthop *nhp; | 1906 | struct rtnexthop *nhp; |
1615 | struct net *net = mfc_net(c); | ||
1616 | struct net_device *dev = net->ipv4.vif_table[c->mfc_parent].dev; | ||
1617 | u8 *b = skb_tail_pointer(skb); | 1907 | u8 *b = skb_tail_pointer(skb); |
1618 | struct rtattr *mp_head; | 1908 | struct rtattr *mp_head; |
1619 | 1909 | ||
1620 | if (dev) | 1910 | /* If cache is unresolved, don't try to parse IIF and OIF */ |
1621 | RTA_PUT(skb, RTA_IIF, 4, &dev->ifindex); | 1911 | if (c->mfc_parent > MAXVIFS) |
1912 | return -ENOENT; | ||
1913 | |||
1914 | if (VIF_EXISTS(mrt, c->mfc_parent)) | ||
1915 | RTA_PUT(skb, RTA_IIF, 4, &mrt->vif_table[c->mfc_parent].dev->ifindex); | ||
1622 | 1916 | ||
1623 | mp_head = (struct rtattr *)skb_put(skb, RTA_LENGTH(0)); | 1917 | mp_head = (struct rtattr *)skb_put(skb, RTA_LENGTH(0)); |
1624 | 1918 | ||
1625 | for (ct = c->mfc_un.res.minvif; ct < c->mfc_un.res.maxvif; ct++) { | 1919 | for (ct = c->mfc_un.res.minvif; ct < c->mfc_un.res.maxvif; ct++) { |
1626 | if (c->mfc_un.res.ttls[ct] < 255) { | 1920 | if (VIF_EXISTS(mrt, ct) && c->mfc_un.res.ttls[ct] < 255) { |
1627 | if (skb_tailroom(skb) < RTA_ALIGN(RTA_ALIGN(sizeof(*nhp)) + 4)) | 1921 | if (skb_tailroom(skb) < RTA_ALIGN(RTA_ALIGN(sizeof(*nhp)) + 4)) |
1628 | goto rtattr_failure; | 1922 | goto rtattr_failure; |
1629 | nhp = (struct rtnexthop *)skb_put(skb, RTA_ALIGN(sizeof(*nhp))); | 1923 | nhp = (struct rtnexthop *)skb_put(skb, RTA_ALIGN(sizeof(*nhp))); |
1630 | nhp->rtnh_flags = 0; | 1924 | nhp->rtnh_flags = 0; |
1631 | nhp->rtnh_hops = c->mfc_un.res.ttls[ct]; | 1925 | nhp->rtnh_hops = c->mfc_un.res.ttls[ct]; |
1632 | nhp->rtnh_ifindex = net->ipv4.vif_table[ct].dev->ifindex; | 1926 | nhp->rtnh_ifindex = mrt->vif_table[ct].dev->ifindex; |
1633 | nhp->rtnh_len = sizeof(*nhp); | 1927 | nhp->rtnh_len = sizeof(*nhp); |
1634 | } | 1928 | } |
1635 | } | 1929 | } |
@@ -1647,11 +1941,16 @@ int ipmr_get_route(struct net *net, | |||
1647 | struct sk_buff *skb, struct rtmsg *rtm, int nowait) | 1941 | struct sk_buff *skb, struct rtmsg *rtm, int nowait) |
1648 | { | 1942 | { |
1649 | int err; | 1943 | int err; |
1944 | struct mr_table *mrt; | ||
1650 | struct mfc_cache *cache; | 1945 | struct mfc_cache *cache; |
1651 | struct rtable *rt = skb_rtable(skb); | 1946 | struct rtable *rt = skb_rtable(skb); |
1652 | 1947 | ||
1948 | mrt = ipmr_get_table(net, RT_TABLE_DEFAULT); | ||
1949 | if (mrt == NULL) | ||
1950 | return -ENOENT; | ||
1951 | |||
1653 | read_lock(&mrt_lock); | 1952 | read_lock(&mrt_lock); |
1654 | cache = ipmr_cache_find(net, rt->rt_src, rt->rt_dst); | 1953 | cache = ipmr_cache_find(mrt, rt->rt_src, rt->rt_dst); |
1655 | 1954 | ||
1656 | if (cache == NULL) { | 1955 | if (cache == NULL) { |
1657 | struct sk_buff *skb2; | 1956 | struct sk_buff *skb2; |
@@ -1665,7 +1964,7 @@ int ipmr_get_route(struct net *net, | |||
1665 | } | 1964 | } |
1666 | 1965 | ||
1667 | dev = skb->dev; | 1966 | dev = skb->dev; |
1668 | if (dev == NULL || (vif = ipmr_find_vif(dev)) < 0) { | 1967 | if (dev == NULL || (vif = ipmr_find_vif(mrt, dev)) < 0) { |
1669 | read_unlock(&mrt_lock); | 1968 | read_unlock(&mrt_lock); |
1670 | return -ENODEV; | 1969 | return -ENODEV; |
1671 | } | 1970 | } |
@@ -1682,14 +1981,14 @@ int ipmr_get_route(struct net *net, | |||
1682 | iph->saddr = rt->rt_src; | 1981 | iph->saddr = rt->rt_src; |
1683 | iph->daddr = rt->rt_dst; | 1982 | iph->daddr = rt->rt_dst; |
1684 | iph->version = 0; | 1983 | iph->version = 0; |
1685 | err = ipmr_cache_unresolved(net, vif, skb2); | 1984 | err = ipmr_cache_unresolved(mrt, vif, skb2); |
1686 | read_unlock(&mrt_lock); | 1985 | read_unlock(&mrt_lock); |
1687 | return err; | 1986 | return err; |
1688 | } | 1987 | } |
1689 | 1988 | ||
1690 | if (!nowait && (rtm->rtm_flags&RTM_F_NOTIFY)) | 1989 | if (!nowait && (rtm->rtm_flags&RTM_F_NOTIFY)) |
1691 | cache->mfc_flags |= MFC_NOTIFY; | 1990 | cache->mfc_flags |= MFC_NOTIFY; |
1692 | err = ipmr_fill_mroute(skb, cache, rtm); | 1991 | err = ipmr_fill_mroute(mrt, skb, cache, rtm); |
1693 | read_unlock(&mrt_lock); | 1992 | read_unlock(&mrt_lock); |
1694 | return err; | 1993 | return err; |
1695 | } | 1994 | } |
@@ -1700,6 +1999,7 @@ int ipmr_get_route(struct net *net, | |||
1700 | */ | 1999 | */ |
1701 | struct ipmr_vif_iter { | 2000 | struct ipmr_vif_iter { |
1702 | struct seq_net_private p; | 2001 | struct seq_net_private p; |
2002 | struct mr_table *mrt; | ||
1703 | int ct; | 2003 | int ct; |
1704 | }; | 2004 | }; |
1705 | 2005 | ||
@@ -1707,11 +2007,13 @@ static struct vif_device *ipmr_vif_seq_idx(struct net *net, | |||
1707 | struct ipmr_vif_iter *iter, | 2007 | struct ipmr_vif_iter *iter, |
1708 | loff_t pos) | 2008 | loff_t pos) |
1709 | { | 2009 | { |
1710 | for (iter->ct = 0; iter->ct < net->ipv4.maxvif; ++iter->ct) { | 2010 | struct mr_table *mrt = iter->mrt; |
1711 | if (!VIF_EXISTS(net, iter->ct)) | 2011 | |
2012 | for (iter->ct = 0; iter->ct < mrt->maxvif; ++iter->ct) { | ||
2013 | if (!VIF_EXISTS(mrt, iter->ct)) | ||
1712 | continue; | 2014 | continue; |
1713 | if (pos-- == 0) | 2015 | if (pos-- == 0) |
1714 | return &net->ipv4.vif_table[iter->ct]; | 2016 | return &mrt->vif_table[iter->ct]; |
1715 | } | 2017 | } |
1716 | return NULL; | 2018 | return NULL; |
1717 | } | 2019 | } |
@@ -1719,7 +2021,15 @@ static struct vif_device *ipmr_vif_seq_idx(struct net *net, | |||
1719 | static void *ipmr_vif_seq_start(struct seq_file *seq, loff_t *pos) | 2021 | static void *ipmr_vif_seq_start(struct seq_file *seq, loff_t *pos) |
1720 | __acquires(mrt_lock) | 2022 | __acquires(mrt_lock) |
1721 | { | 2023 | { |
2024 | struct ipmr_vif_iter *iter = seq->private; | ||
1722 | struct net *net = seq_file_net(seq); | 2025 | struct net *net = seq_file_net(seq); |
2026 | struct mr_table *mrt; | ||
2027 | |||
2028 | mrt = ipmr_get_table(net, RT_TABLE_DEFAULT); | ||
2029 | if (mrt == NULL) | ||
2030 | return ERR_PTR(-ENOENT); | ||
2031 | |||
2032 | iter->mrt = mrt; | ||
1723 | 2033 | ||
1724 | read_lock(&mrt_lock); | 2034 | read_lock(&mrt_lock); |
1725 | return *pos ? ipmr_vif_seq_idx(net, seq->private, *pos - 1) | 2035 | return *pos ? ipmr_vif_seq_idx(net, seq->private, *pos - 1) |
@@ -1730,15 +2040,16 @@ static void *ipmr_vif_seq_next(struct seq_file *seq, void *v, loff_t *pos) | |||
1730 | { | 2040 | { |
1731 | struct ipmr_vif_iter *iter = seq->private; | 2041 | struct ipmr_vif_iter *iter = seq->private; |
1732 | struct net *net = seq_file_net(seq); | 2042 | struct net *net = seq_file_net(seq); |
2043 | struct mr_table *mrt = iter->mrt; | ||
1733 | 2044 | ||
1734 | ++*pos; | 2045 | ++*pos; |
1735 | if (v == SEQ_START_TOKEN) | 2046 | if (v == SEQ_START_TOKEN) |
1736 | return ipmr_vif_seq_idx(net, iter, 0); | 2047 | return ipmr_vif_seq_idx(net, iter, 0); |
1737 | 2048 | ||
1738 | while (++iter->ct < net->ipv4.maxvif) { | 2049 | while (++iter->ct < mrt->maxvif) { |
1739 | if (!VIF_EXISTS(net, iter->ct)) | 2050 | if (!VIF_EXISTS(mrt, iter->ct)) |
1740 | continue; | 2051 | continue; |
1741 | return &net->ipv4.vif_table[iter->ct]; | 2052 | return &mrt->vif_table[iter->ct]; |
1742 | } | 2053 | } |
1743 | return NULL; | 2054 | return NULL; |
1744 | } | 2055 | } |
@@ -1751,7 +2062,8 @@ static void ipmr_vif_seq_stop(struct seq_file *seq, void *v) | |||
1751 | 2062 | ||
1752 | static int ipmr_vif_seq_show(struct seq_file *seq, void *v) | 2063 | static int ipmr_vif_seq_show(struct seq_file *seq, void *v) |
1753 | { | 2064 | { |
1754 | struct net *net = seq_file_net(seq); | 2065 | struct ipmr_vif_iter *iter = seq->private; |
2066 | struct mr_table *mrt = iter->mrt; | ||
1755 | 2067 | ||
1756 | if (v == SEQ_START_TOKEN) { | 2068 | if (v == SEQ_START_TOKEN) { |
1757 | seq_puts(seq, | 2069 | seq_puts(seq, |
@@ -1762,7 +2074,7 @@ static int ipmr_vif_seq_show(struct seq_file *seq, void *v) | |||
1762 | 2074 | ||
1763 | seq_printf(seq, | 2075 | seq_printf(seq, |
1764 | "%2Zd %-10s %8ld %7ld %8ld %7ld %05X %08X %08X\n", | 2076 | "%2Zd %-10s %8ld %7ld %8ld %7ld %05X %08X %08X\n", |
1765 | vif - net->ipv4.vif_table, | 2077 | vif - mrt->vif_table, |
1766 | name, vif->bytes_in, vif->pkt_in, | 2078 | name, vif->bytes_in, vif->pkt_in, |
1767 | vif->bytes_out, vif->pkt_out, | 2079 | vif->bytes_out, vif->pkt_out, |
1768 | vif->flags, vif->local, vif->remote); | 2080 | vif->flags, vif->local, vif->remote); |
@@ -1793,7 +2105,8 @@ static const struct file_operations ipmr_vif_fops = { | |||
1793 | 2105 | ||
1794 | struct ipmr_mfc_iter { | 2106 | struct ipmr_mfc_iter { |
1795 | struct seq_net_private p; | 2107 | struct seq_net_private p; |
1796 | struct mfc_cache **cache; | 2108 | struct mr_table *mrt; |
2109 | struct list_head *cache; | ||
1797 | int ct; | 2110 | int ct; |
1798 | }; | 2111 | }; |
1799 | 2112 | ||
@@ -1801,22 +2114,22 @@ struct ipmr_mfc_iter { | |||
1801 | static struct mfc_cache *ipmr_mfc_seq_idx(struct net *net, | 2114 | static struct mfc_cache *ipmr_mfc_seq_idx(struct net *net, |
1802 | struct ipmr_mfc_iter *it, loff_t pos) | 2115 | struct ipmr_mfc_iter *it, loff_t pos) |
1803 | { | 2116 | { |
2117 | struct mr_table *mrt = it->mrt; | ||
1804 | struct mfc_cache *mfc; | 2118 | struct mfc_cache *mfc; |
1805 | 2119 | ||
1806 | it->cache = net->ipv4.mfc_cache_array; | ||
1807 | read_lock(&mrt_lock); | 2120 | read_lock(&mrt_lock); |
1808 | for (it->ct = 0; it->ct < MFC_LINES; it->ct++) | 2121 | for (it->ct = 0; it->ct < MFC_LINES; it->ct++) { |
1809 | for (mfc = net->ipv4.mfc_cache_array[it->ct]; | 2122 | it->cache = &mrt->mfc_cache_array[it->ct]; |
1810 | mfc; mfc = mfc->next) | 2123 | list_for_each_entry(mfc, it->cache, list) |
1811 | if (pos-- == 0) | 2124 | if (pos-- == 0) |
1812 | return mfc; | 2125 | return mfc; |
2126 | } | ||
1813 | read_unlock(&mrt_lock); | 2127 | read_unlock(&mrt_lock); |
1814 | 2128 | ||
1815 | it->cache = &mfc_unres_queue; | ||
1816 | spin_lock_bh(&mfc_unres_lock); | 2129 | spin_lock_bh(&mfc_unres_lock); |
1817 | for (mfc = mfc_unres_queue; mfc; mfc = mfc->next) | 2130 | it->cache = &mrt->mfc_unres_queue; |
1818 | if (net_eq(mfc_net(mfc), net) && | 2131 | list_for_each_entry(mfc, it->cache, list) |
1819 | pos-- == 0) | 2132 | if (pos-- == 0) |
1820 | return mfc; | 2133 | return mfc; |
1821 | spin_unlock_bh(&mfc_unres_lock); | 2134 | spin_unlock_bh(&mfc_unres_lock); |
1822 | 2135 | ||
@@ -1829,7 +2142,13 @@ static void *ipmr_mfc_seq_start(struct seq_file *seq, loff_t *pos) | |||
1829 | { | 2142 | { |
1830 | struct ipmr_mfc_iter *it = seq->private; | 2143 | struct ipmr_mfc_iter *it = seq->private; |
1831 | struct net *net = seq_file_net(seq); | 2144 | struct net *net = seq_file_net(seq); |
2145 | struct mr_table *mrt; | ||
1832 | 2146 | ||
2147 | mrt = ipmr_get_table(net, RT_TABLE_DEFAULT); | ||
2148 | if (mrt == NULL) | ||
2149 | return ERR_PTR(-ENOENT); | ||
2150 | |||
2151 | it->mrt = mrt; | ||
1833 | it->cache = NULL; | 2152 | it->cache = NULL; |
1834 | it->ct = 0; | 2153 | it->ct = 0; |
1835 | return *pos ? ipmr_mfc_seq_idx(net, seq->private, *pos - 1) | 2154 | return *pos ? ipmr_mfc_seq_idx(net, seq->private, *pos - 1) |
@@ -1841,37 +2160,36 @@ static void *ipmr_mfc_seq_next(struct seq_file *seq, void *v, loff_t *pos) | |||
1841 | struct mfc_cache *mfc = v; | 2160 | struct mfc_cache *mfc = v; |
1842 | struct ipmr_mfc_iter *it = seq->private; | 2161 | struct ipmr_mfc_iter *it = seq->private; |
1843 | struct net *net = seq_file_net(seq); | 2162 | struct net *net = seq_file_net(seq); |
2163 | struct mr_table *mrt = it->mrt; | ||
1844 | 2164 | ||
1845 | ++*pos; | 2165 | ++*pos; |
1846 | 2166 | ||
1847 | if (v == SEQ_START_TOKEN) | 2167 | if (v == SEQ_START_TOKEN) |
1848 | return ipmr_mfc_seq_idx(net, seq->private, 0); | 2168 | return ipmr_mfc_seq_idx(net, seq->private, 0); |
1849 | 2169 | ||
1850 | if (mfc->next) | 2170 | if (mfc->list.next != it->cache) |
1851 | return mfc->next; | 2171 | return list_entry(mfc->list.next, struct mfc_cache, list); |
1852 | 2172 | ||
1853 | if (it->cache == &mfc_unres_queue) | 2173 | if (it->cache == &mrt->mfc_unres_queue) |
1854 | goto end_of_list; | 2174 | goto end_of_list; |
1855 | 2175 | ||
1856 | BUG_ON(it->cache != net->ipv4.mfc_cache_array); | 2176 | BUG_ON(it->cache != &mrt->mfc_cache_array[it->ct]); |
1857 | 2177 | ||
1858 | while (++it->ct < MFC_LINES) { | 2178 | while (++it->ct < MFC_LINES) { |
1859 | mfc = net->ipv4.mfc_cache_array[it->ct]; | 2179 | it->cache = &mrt->mfc_cache_array[it->ct]; |
1860 | if (mfc) | 2180 | if (list_empty(it->cache)) |
1861 | return mfc; | 2181 | continue; |
2182 | return list_first_entry(it->cache, struct mfc_cache, list); | ||
1862 | } | 2183 | } |
1863 | 2184 | ||
1864 | /* exhausted cache_array, show unresolved */ | 2185 | /* exhausted cache_array, show unresolved */ |
1865 | read_unlock(&mrt_lock); | 2186 | read_unlock(&mrt_lock); |
1866 | it->cache = &mfc_unres_queue; | 2187 | it->cache = &mrt->mfc_unres_queue; |
1867 | it->ct = 0; | 2188 | it->ct = 0; |
1868 | 2189 | ||
1869 | spin_lock_bh(&mfc_unres_lock); | 2190 | spin_lock_bh(&mfc_unres_lock); |
1870 | mfc = mfc_unres_queue; | 2191 | if (!list_empty(it->cache)) |
1871 | while (mfc && !net_eq(mfc_net(mfc), net)) | 2192 | return list_first_entry(it->cache, struct mfc_cache, list); |
1872 | mfc = mfc->next; | ||
1873 | if (mfc) | ||
1874 | return mfc; | ||
1875 | 2193 | ||
1876 | end_of_list: | 2194 | end_of_list: |
1877 | spin_unlock_bh(&mfc_unres_lock); | 2195 | spin_unlock_bh(&mfc_unres_lock); |
@@ -1883,18 +2201,17 @@ static void *ipmr_mfc_seq_next(struct seq_file *seq, void *v, loff_t *pos) | |||
1883 | static void ipmr_mfc_seq_stop(struct seq_file *seq, void *v) | 2201 | static void ipmr_mfc_seq_stop(struct seq_file *seq, void *v) |
1884 | { | 2202 | { |
1885 | struct ipmr_mfc_iter *it = seq->private; | 2203 | struct ipmr_mfc_iter *it = seq->private; |
1886 | struct net *net = seq_file_net(seq); | 2204 | struct mr_table *mrt = it->mrt; |
1887 | 2205 | ||
1888 | if (it->cache == &mfc_unres_queue) | 2206 | if (it->cache == &mrt->mfc_unres_queue) |
1889 | spin_unlock_bh(&mfc_unres_lock); | 2207 | spin_unlock_bh(&mfc_unres_lock); |
1890 | else if (it->cache == net->ipv4.mfc_cache_array) | 2208 | else if (it->cache == &mrt->mfc_cache_array[it->ct]) |
1891 | read_unlock(&mrt_lock); | 2209 | read_unlock(&mrt_lock); |
1892 | } | 2210 | } |
1893 | 2211 | ||
1894 | static int ipmr_mfc_seq_show(struct seq_file *seq, void *v) | 2212 | static int ipmr_mfc_seq_show(struct seq_file *seq, void *v) |
1895 | { | 2213 | { |
1896 | int n; | 2214 | int n; |
1897 | struct net *net = seq_file_net(seq); | ||
1898 | 2215 | ||
1899 | if (v == SEQ_START_TOKEN) { | 2216 | if (v == SEQ_START_TOKEN) { |
1900 | seq_puts(seq, | 2217 | seq_puts(seq, |
@@ -1902,20 +2219,21 @@ static int ipmr_mfc_seq_show(struct seq_file *seq, void *v) | |||
1902 | } else { | 2219 | } else { |
1903 | const struct mfc_cache *mfc = v; | 2220 | const struct mfc_cache *mfc = v; |
1904 | const struct ipmr_mfc_iter *it = seq->private; | 2221 | const struct ipmr_mfc_iter *it = seq->private; |
2222 | const struct mr_table *mrt = it->mrt; | ||
1905 | 2223 | ||
1906 | seq_printf(seq, "%08lX %08lX %-3hd", | 2224 | seq_printf(seq, "%08lX %08lX %-3hd", |
1907 | (unsigned long) mfc->mfc_mcastgrp, | 2225 | (unsigned long) mfc->mfc_mcastgrp, |
1908 | (unsigned long) mfc->mfc_origin, | 2226 | (unsigned long) mfc->mfc_origin, |
1909 | mfc->mfc_parent); | 2227 | mfc->mfc_parent); |
1910 | 2228 | ||
1911 | if (it->cache != &mfc_unres_queue) { | 2229 | if (it->cache != &mrt->mfc_unres_queue) { |
1912 | seq_printf(seq, " %8lu %8lu %8lu", | 2230 | seq_printf(seq, " %8lu %8lu %8lu", |
1913 | mfc->mfc_un.res.pkt, | 2231 | mfc->mfc_un.res.pkt, |
1914 | mfc->mfc_un.res.bytes, | 2232 | mfc->mfc_un.res.bytes, |
1915 | mfc->mfc_un.res.wrong_if); | 2233 | mfc->mfc_un.res.wrong_if); |
1916 | for (n = mfc->mfc_un.res.minvif; | 2234 | for (n = mfc->mfc_un.res.minvif; |
1917 | n < mfc->mfc_un.res.maxvif; n++ ) { | 2235 | n < mfc->mfc_un.res.maxvif; n++ ) { |
1918 | if (VIF_EXISTS(net, n) && | 2236 | if (VIF_EXISTS(mrt, n) && |
1919 | mfc->mfc_un.res.ttls[n] < 255) | 2237 | mfc->mfc_un.res.ttls[n] < 255) |
1920 | seq_printf(seq, | 2238 | seq_printf(seq, |
1921 | " %2d:%-3d", | 2239 | " %2d:%-3d", |
@@ -1967,27 +2285,11 @@ static const struct net_protocol pim_protocol = { | |||
1967 | */ | 2285 | */ |
1968 | static int __net_init ipmr_net_init(struct net *net) | 2286 | static int __net_init ipmr_net_init(struct net *net) |
1969 | { | 2287 | { |
1970 | int err = 0; | 2288 | int err; |
1971 | 2289 | ||
1972 | net->ipv4.vif_table = kcalloc(MAXVIFS, sizeof(struct vif_device), | 2290 | err = ipmr_rules_init(net); |
1973 | GFP_KERNEL); | 2291 | if (err < 0) |
1974 | if (!net->ipv4.vif_table) { | ||
1975 | err = -ENOMEM; | ||
1976 | goto fail; | 2292 | goto fail; |
1977 | } | ||
1978 | |||
1979 | /* Forwarding cache */ | ||
1980 | net->ipv4.mfc_cache_array = kcalloc(MFC_LINES, | ||
1981 | sizeof(struct mfc_cache *), | ||
1982 | GFP_KERNEL); | ||
1983 | if (!net->ipv4.mfc_cache_array) { | ||
1984 | err = -ENOMEM; | ||
1985 | goto fail_mfc_cache; | ||
1986 | } | ||
1987 | |||
1988 | #ifdef CONFIG_IP_PIMSM | ||
1989 | net->ipv4.mroute_reg_vif_num = -1; | ||
1990 | #endif | ||
1991 | 2293 | ||
1992 | #ifdef CONFIG_PROC_FS | 2294 | #ifdef CONFIG_PROC_FS |
1993 | err = -ENOMEM; | 2295 | err = -ENOMEM; |
@@ -2002,10 +2304,8 @@ static int __net_init ipmr_net_init(struct net *net) | |||
2002 | proc_cache_fail: | 2304 | proc_cache_fail: |
2003 | proc_net_remove(net, "ip_mr_vif"); | 2305 | proc_net_remove(net, "ip_mr_vif"); |
2004 | proc_vif_fail: | 2306 | proc_vif_fail: |
2005 | kfree(net->ipv4.mfc_cache_array); | 2307 | ipmr_rules_exit(net); |
2006 | #endif | 2308 | #endif |
2007 | fail_mfc_cache: | ||
2008 | kfree(net->ipv4.vif_table); | ||
2009 | fail: | 2309 | fail: |
2010 | return err; | 2310 | return err; |
2011 | } | 2311 | } |
@@ -2016,8 +2316,7 @@ static void __net_exit ipmr_net_exit(struct net *net) | |||
2016 | proc_net_remove(net, "ip_mr_cache"); | 2316 | proc_net_remove(net, "ip_mr_cache"); |
2017 | proc_net_remove(net, "ip_mr_vif"); | 2317 | proc_net_remove(net, "ip_mr_vif"); |
2018 | #endif | 2318 | #endif |
2019 | kfree(net->ipv4.mfc_cache_array); | 2319 | ipmr_rules_exit(net); |
2020 | kfree(net->ipv4.vif_table); | ||
2021 | } | 2320 | } |
2022 | 2321 | ||
2023 | static struct pernet_operations ipmr_net_ops = { | 2322 | static struct pernet_operations ipmr_net_ops = { |
@@ -2040,7 +2339,6 @@ int __init ip_mr_init(void) | |||
2040 | if (err) | 2339 | if (err) |
2041 | goto reg_pernet_fail; | 2340 | goto reg_pernet_fail; |
2042 | 2341 | ||
2043 | setup_timer(&ipmr_expire_timer, ipmr_expire_process, 0); | ||
2044 | err = register_netdevice_notifier(&ip_mr_notifier); | 2342 | err = register_netdevice_notifier(&ip_mr_notifier); |
2045 | if (err) | 2343 | if (err) |
2046 | goto reg_notif_fail; | 2344 | goto reg_notif_fail; |
@@ -2058,7 +2356,6 @@ add_proto_fail: | |||
2058 | unregister_netdevice_notifier(&ip_mr_notifier); | 2356 | unregister_netdevice_notifier(&ip_mr_notifier); |
2059 | #endif | 2357 | #endif |
2060 | reg_notif_fail: | 2358 | reg_notif_fail: |
2061 | del_timer(&ipmr_expire_timer); | ||
2062 | unregister_pernet_subsys(&ipmr_net_ops); | 2359 | unregister_pernet_subsys(&ipmr_net_ops); |
2063 | reg_pernet_fail: | 2360 | reg_pernet_fail: |
2064 | kmem_cache_destroy(mrt_cachep); | 2361 | kmem_cache_destroy(mrt_cachep); |
diff --git a/net/ipv4/netfilter.c b/net/ipv4/netfilter.c index c14623fc4d5e..82fb43c5c59e 100644 --- a/net/ipv4/netfilter.c +++ b/net/ipv4/netfilter.c | |||
@@ -4,6 +4,7 @@ | |||
4 | #include <linux/netfilter_ipv4.h> | 4 | #include <linux/netfilter_ipv4.h> |
5 | #include <linux/ip.h> | 5 | #include <linux/ip.h> |
6 | #include <linux/skbuff.h> | 6 | #include <linux/skbuff.h> |
7 | #include <linux/gfp.h> | ||
7 | #include <net/route.h> | 8 | #include <net/route.h> |
8 | #include <net/xfrm.h> | 9 | #include <net/xfrm.h> |
9 | #include <net/ip.h> | 10 | #include <net/ip.h> |
diff --git a/net/ipv4/netfilter/arptable_filter.c b/net/ipv4/netfilter/arptable_filter.c index bfe26f32b930..79ca5e70d497 100644 --- a/net/ipv4/netfilter/arptable_filter.c +++ b/net/ipv4/netfilter/arptable_filter.c | |||
@@ -8,6 +8,7 @@ | |||
8 | #include <linux/module.h> | 8 | #include <linux/module.h> |
9 | #include <linux/netfilter/x_tables.h> | 9 | #include <linux/netfilter/x_tables.h> |
10 | #include <linux/netfilter_arp/arp_tables.h> | 10 | #include <linux/netfilter_arp/arp_tables.h> |
11 | #include <linux/slab.h> | ||
11 | 12 | ||
12 | MODULE_LICENSE("GPL"); | 13 | MODULE_LICENSE("GPL"); |
13 | MODULE_AUTHOR("David S. Miller <davem@redhat.com>"); | 14 | MODULE_AUTHOR("David S. Miller <davem@redhat.com>"); |
diff --git a/net/ipv4/netfilter/ip_queue.c b/net/ipv4/netfilter/ip_queue.c index 2855f1f38cbc..e2787048aa0a 100644 --- a/net/ipv4/netfilter/ip_queue.c +++ b/net/ipv4/netfilter/ip_queue.c | |||
@@ -26,6 +26,7 @@ | |||
26 | #include <linux/security.h> | 26 | #include <linux/security.h> |
27 | #include <linux/net.h> | 27 | #include <linux/net.h> |
28 | #include <linux/mutex.h> | 28 | #include <linux/mutex.h> |
29 | #include <linux/slab.h> | ||
29 | #include <net/net_namespace.h> | 30 | #include <net/net_namespace.h> |
30 | #include <net/sock.h> | 31 | #include <net/sock.h> |
31 | #include <net/route.h> | 32 | #include <net/route.h> |
diff --git a/net/ipv4/netfilter/ipt_CLUSTERIP.c b/net/ipv4/netfilter/ipt_CLUSTERIP.c index 0886f96c736b..a992dc826f1c 100644 --- a/net/ipv4/netfilter/ipt_CLUSTERIP.c +++ b/net/ipv4/netfilter/ipt_CLUSTERIP.c | |||
@@ -14,6 +14,7 @@ | |||
14 | #include <linux/jhash.h> | 14 | #include <linux/jhash.h> |
15 | #include <linux/bitops.h> | 15 | #include <linux/bitops.h> |
16 | #include <linux/skbuff.h> | 16 | #include <linux/skbuff.h> |
17 | #include <linux/slab.h> | ||
17 | #include <linux/ip.h> | 18 | #include <linux/ip.h> |
18 | #include <linux/tcp.h> | 19 | #include <linux/tcp.h> |
19 | #include <linux/udp.h> | 20 | #include <linux/udp.h> |
@@ -87,7 +88,7 @@ clusterip_config_entry_put(struct clusterip_config *c) | |||
87 | list_del(&c->list); | 88 | list_del(&c->list); |
88 | write_unlock_bh(&clusterip_lock); | 89 | write_unlock_bh(&clusterip_lock); |
89 | 90 | ||
90 | dev_mc_delete(c->dev, c->clustermac, ETH_ALEN, 0); | 91 | dev_mc_del(c->dev, c->clustermac); |
91 | dev_put(c->dev); | 92 | dev_put(c->dev); |
92 | 93 | ||
93 | /* In case anyone still accesses the file, the open/close | 94 | /* In case anyone still accesses the file, the open/close |
@@ -396,7 +397,7 @@ static bool clusterip_tg_check(const struct xt_tgchk_param *par) | |||
396 | dev_put(dev); | 397 | dev_put(dev); |
397 | return false; | 398 | return false; |
398 | } | 399 | } |
399 | dev_mc_add(config->dev,config->clustermac, ETH_ALEN, 0); | 400 | dev_mc_add(config->dev, config->clustermac); |
400 | } | 401 | } |
401 | } | 402 | } |
402 | cipinfo->config = config; | 403 | cipinfo->config = config; |
diff --git a/net/ipv4/netfilter/ipt_REJECT.c b/net/ipv4/netfilter/ipt_REJECT.c index 5113b8f1a379..a0e8bcf04159 100644 --- a/net/ipv4/netfilter/ipt_REJECT.c +++ b/net/ipv4/netfilter/ipt_REJECT.c | |||
@@ -12,6 +12,7 @@ | |||
12 | 12 | ||
13 | #include <linux/module.h> | 13 | #include <linux/module.h> |
14 | #include <linux/skbuff.h> | 14 | #include <linux/skbuff.h> |
15 | #include <linux/slab.h> | ||
15 | #include <linux/ip.h> | 16 | #include <linux/ip.h> |
16 | #include <linux/udp.h> | 17 | #include <linux/udp.h> |
17 | #include <linux/icmp.h> | 18 | #include <linux/icmp.h> |
diff --git a/net/ipv4/netfilter/ipt_ULOG.c b/net/ipv4/netfilter/ipt_ULOG.c index 09a5d3f7cc41..0dbe697f164f 100644 --- a/net/ipv4/netfilter/ipt_ULOG.c +++ b/net/ipv4/netfilter/ipt_ULOG.c | |||
@@ -33,6 +33,7 @@ | |||
33 | #include <linux/module.h> | 33 | #include <linux/module.h> |
34 | #include <linux/spinlock.h> | 34 | #include <linux/spinlock.h> |
35 | #include <linux/socket.h> | 35 | #include <linux/socket.h> |
36 | #include <linux/slab.h> | ||
36 | #include <linux/skbuff.h> | 37 | #include <linux/skbuff.h> |
37 | #include <linux/kernel.h> | 38 | #include <linux/kernel.h> |
38 | #include <linux/timer.h> | 39 | #include <linux/timer.h> |
diff --git a/net/ipv4/netfilter/iptable_filter.c b/net/ipv4/netfilter/iptable_filter.c index c8dc9800d620..55392466daa4 100644 --- a/net/ipv4/netfilter/iptable_filter.c +++ b/net/ipv4/netfilter/iptable_filter.c | |||
@@ -13,6 +13,7 @@ | |||
13 | #include <linux/module.h> | 13 | #include <linux/module.h> |
14 | #include <linux/moduleparam.h> | 14 | #include <linux/moduleparam.h> |
15 | #include <linux/netfilter_ipv4/ip_tables.h> | 15 | #include <linux/netfilter_ipv4/ip_tables.h> |
16 | #include <linux/slab.h> | ||
16 | #include <net/ip.h> | 17 | #include <net/ip.h> |
17 | 18 | ||
18 | MODULE_LICENSE("GPL"); | 19 | MODULE_LICENSE("GPL"); |
diff --git a/net/ipv4/netfilter/iptable_mangle.c b/net/ipv4/netfilter/iptable_mangle.c index b9b83464cbf4..294a2a32f293 100644 --- a/net/ipv4/netfilter/iptable_mangle.c +++ b/net/ipv4/netfilter/iptable_mangle.c | |||
@@ -12,6 +12,7 @@ | |||
12 | #include <linux/netfilter_ipv4/ip_tables.h> | 12 | #include <linux/netfilter_ipv4/ip_tables.h> |
13 | #include <linux/netdevice.h> | 13 | #include <linux/netdevice.h> |
14 | #include <linux/skbuff.h> | 14 | #include <linux/skbuff.h> |
15 | #include <linux/slab.h> | ||
15 | #include <net/sock.h> | 16 | #include <net/sock.h> |
16 | #include <net/route.h> | 17 | #include <net/route.h> |
17 | #include <linux/ip.h> | 18 | #include <linux/ip.h> |
diff --git a/net/ipv4/netfilter/iptable_raw.c b/net/ipv4/netfilter/iptable_raw.c index 06fb9d11953c..07fb710cd722 100644 --- a/net/ipv4/netfilter/iptable_raw.c +++ b/net/ipv4/netfilter/iptable_raw.c | |||
@@ -5,6 +5,7 @@ | |||
5 | */ | 5 | */ |
6 | #include <linux/module.h> | 6 | #include <linux/module.h> |
7 | #include <linux/netfilter_ipv4/ip_tables.h> | 7 | #include <linux/netfilter_ipv4/ip_tables.h> |
8 | #include <linux/slab.h> | ||
8 | #include <net/ip.h> | 9 | #include <net/ip.h> |
9 | 10 | ||
10 | #define RAW_VALID_HOOKS ((1 << NF_INET_PRE_ROUTING) | (1 << NF_INET_LOCAL_OUT)) | 11 | #define RAW_VALID_HOOKS ((1 << NF_INET_PRE_ROUTING) | (1 << NF_INET_LOCAL_OUT)) |
diff --git a/net/ipv4/netfilter/iptable_security.c b/net/ipv4/netfilter/iptable_security.c index cce2f64e6f21..be45bdc4c602 100644 --- a/net/ipv4/netfilter/iptable_security.c +++ b/net/ipv4/netfilter/iptable_security.c | |||
@@ -17,6 +17,7 @@ | |||
17 | */ | 17 | */ |
18 | #include <linux/module.h> | 18 | #include <linux/module.h> |
19 | #include <linux/netfilter_ipv4/ip_tables.h> | 19 | #include <linux/netfilter_ipv4/ip_tables.h> |
20 | #include <linux/slab.h> | ||
20 | #include <net/ip.h> | 21 | #include <net/ip.h> |
21 | 22 | ||
22 | MODULE_LICENSE("GPL"); | 23 | MODULE_LICENSE("GPL"); |
diff --git a/net/ipv4/netfilter/nf_nat_core.c b/net/ipv4/netfilter/nf_nat_core.c index 4595281c2863..4f8bddb760c9 100644 --- a/net/ipv4/netfilter/nf_nat_core.c +++ b/net/ipv4/netfilter/nf_nat_core.c | |||
@@ -12,6 +12,7 @@ | |||
12 | #include <linux/types.h> | 12 | #include <linux/types.h> |
13 | #include <linux/timer.h> | 13 | #include <linux/timer.h> |
14 | #include <linux/skbuff.h> | 14 | #include <linux/skbuff.h> |
15 | #include <linux/gfp.h> | ||
15 | #include <net/checksum.h> | 16 | #include <net/checksum.h> |
16 | #include <net/icmp.h> | 17 | #include <net/icmp.h> |
17 | #include <net/ip.h> | 18 | #include <net/ip.h> |
diff --git a/net/ipv4/netfilter/nf_nat_helper.c b/net/ipv4/netfilter/nf_nat_helper.c index 4b6af4bb1f50..4a0c6b548eee 100644 --- a/net/ipv4/netfilter/nf_nat_helper.c +++ b/net/ipv4/netfilter/nf_nat_helper.c | |||
@@ -8,6 +8,7 @@ | |||
8 | * published by the Free Software Foundation. | 8 | * published by the Free Software Foundation. |
9 | */ | 9 | */ |
10 | #include <linux/module.h> | 10 | #include <linux/module.h> |
11 | #include <linux/gfp.h> | ||
11 | #include <linux/kmod.h> | 12 | #include <linux/kmod.h> |
12 | #include <linux/types.h> | 13 | #include <linux/types.h> |
13 | #include <linux/timer.h> | 14 | #include <linux/timer.h> |
diff --git a/net/ipv4/netfilter/nf_nat_rule.c b/net/ipv4/netfilter/nf_nat_rule.c index ab74cc0535e2..26de2c1f7fab 100644 --- a/net/ipv4/netfilter/nf_nat_rule.c +++ b/net/ipv4/netfilter/nf_nat_rule.c | |||
@@ -15,6 +15,7 @@ | |||
15 | #include <linux/kmod.h> | 15 | #include <linux/kmod.h> |
16 | #include <linux/skbuff.h> | 16 | #include <linux/skbuff.h> |
17 | #include <linux/proc_fs.h> | 17 | #include <linux/proc_fs.h> |
18 | #include <linux/slab.h> | ||
18 | #include <net/checksum.h> | 19 | #include <net/checksum.h> |
19 | #include <net/route.h> | 20 | #include <net/route.h> |
20 | #include <linux/bitops.h> | 21 | #include <linux/bitops.h> |
diff --git a/net/ipv4/netfilter/nf_nat_snmp_basic.c b/net/ipv4/netfilter/nf_nat_snmp_basic.c index 0b9c7ce3d6c5..4d85b6e55f29 100644 --- a/net/ipv4/netfilter/nf_nat_snmp_basic.c +++ b/net/ipv4/netfilter/nf_nat_snmp_basic.c | |||
@@ -43,6 +43,7 @@ | |||
43 | #include <linux/moduleparam.h> | 43 | #include <linux/moduleparam.h> |
44 | #include <linux/types.h> | 44 | #include <linux/types.h> |
45 | #include <linux/kernel.h> | 45 | #include <linux/kernel.h> |
46 | #include <linux/slab.h> | ||
46 | #include <linux/in.h> | 47 | #include <linux/in.h> |
47 | #include <linux/ip.h> | 48 | #include <linux/ip.h> |
48 | #include <linux/udp.h> | 49 | #include <linux/udp.h> |
diff --git a/net/ipv4/netfilter/nf_nat_standalone.c b/net/ipv4/netfilter/nf_nat_standalone.c index 5678e9562c15..c39c9cf6bee6 100644 --- a/net/ipv4/netfilter/nf_nat_standalone.c +++ b/net/ipv4/netfilter/nf_nat_standalone.c | |||
@@ -7,6 +7,7 @@ | |||
7 | */ | 7 | */ |
8 | #include <linux/types.h> | 8 | #include <linux/types.h> |
9 | #include <linux/icmp.h> | 9 | #include <linux/icmp.h> |
10 | #include <linux/gfp.h> | ||
10 | #include <linux/ip.h> | 11 | #include <linux/ip.h> |
11 | #include <linux/netfilter.h> | 12 | #include <linux/netfilter.h> |
12 | #include <linux/netfilter_ipv4.h> | 13 | #include <linux/netfilter_ipv4.h> |
diff --git a/net/ipv4/proc.c b/net/ipv4/proc.c index 4f1f337f4337..3dc9914c1dce 100644 --- a/net/ipv4/proc.c +++ b/net/ipv4/proc.c | |||
@@ -251,6 +251,7 @@ static const struct snmp_mib snmp4_net_list[] = { | |||
251 | SNMP_MIB_ITEM("TCPSackShiftFallback", LINUX_MIB_SACKSHIFTFALLBACK), | 251 | SNMP_MIB_ITEM("TCPSackShiftFallback", LINUX_MIB_SACKSHIFTFALLBACK), |
252 | SNMP_MIB_ITEM("TCPBacklogDrop", LINUX_MIB_TCPBACKLOGDROP), | 252 | SNMP_MIB_ITEM("TCPBacklogDrop", LINUX_MIB_TCPBACKLOGDROP), |
253 | SNMP_MIB_ITEM("TCPMinTTLDrop", LINUX_MIB_TCPMINTTLDROP), | 253 | SNMP_MIB_ITEM("TCPMinTTLDrop", LINUX_MIB_TCPMINTTLDROP), |
254 | SNMP_MIB_ITEM("TCPDeferAcceptDrop", LINUX_MIB_TCPDEFERACCEPTDROP), | ||
254 | SNMP_MIB_SENTINEL | 255 | SNMP_MIB_SENTINEL |
255 | }; | 256 | }; |
256 | 257 | ||
diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c index ce154b47f1da..cc6f097fbd5f 100644 --- a/net/ipv4/raw.c +++ b/net/ipv4/raw.c | |||
@@ -60,7 +60,6 @@ | |||
60 | #include <net/net_namespace.h> | 60 | #include <net/net_namespace.h> |
61 | #include <net/dst.h> | 61 | #include <net/dst.h> |
62 | #include <net/sock.h> | 62 | #include <net/sock.h> |
63 | #include <linux/gfp.h> | ||
64 | #include <linux/ip.h> | 63 | #include <linux/ip.h> |
65 | #include <linux/net.h> | 64 | #include <linux/net.h> |
66 | #include <net/ip.h> | 65 | #include <net/ip.h> |
diff --git a/net/ipv4/route.c b/net/ipv4/route.c index d9b40248b97f..cb562fdd9b9a 100644 --- a/net/ipv4/route.c +++ b/net/ipv4/route.c | |||
@@ -90,6 +90,7 @@ | |||
90 | #include <linux/jhash.h> | 90 | #include <linux/jhash.h> |
91 | #include <linux/rcupdate.h> | 91 | #include <linux/rcupdate.h> |
92 | #include <linux/times.h> | 92 | #include <linux/times.h> |
93 | #include <linux/slab.h> | ||
93 | #include <net/dst.h> | 94 | #include <net/dst.h> |
94 | #include <net/net_namespace.h> | 95 | #include <net/net_namespace.h> |
95 | #include <net/protocol.h> | 96 | #include <net/protocol.h> |
@@ -932,10 +933,8 @@ static void rt_secret_rebuild_oneshot(struct net *net) | |||
932 | { | 933 | { |
933 | del_timer_sync(&net->ipv4.rt_secret_timer); | 934 | del_timer_sync(&net->ipv4.rt_secret_timer); |
934 | rt_cache_invalidate(net); | 935 | rt_cache_invalidate(net); |
935 | if (ip_rt_secret_interval) { | 936 | if (ip_rt_secret_interval) |
936 | net->ipv4.rt_secret_timer.expires += ip_rt_secret_interval; | 937 | mod_timer(&net->ipv4.rt_secret_timer, jiffies + ip_rt_secret_interval); |
937 | add_timer(&net->ipv4.rt_secret_timer); | ||
938 | } | ||
939 | } | 938 | } |
940 | 939 | ||
941 | static void rt_emergency_hash_rebuild(struct net *net) | 940 | static void rt_emergency_hash_rebuild(struct net *net) |
@@ -1099,7 +1098,7 @@ static int slow_chain_length(const struct rtable *head) | |||
1099 | } | 1098 | } |
1100 | 1099 | ||
1101 | static int rt_intern_hash(unsigned hash, struct rtable *rt, | 1100 | static int rt_intern_hash(unsigned hash, struct rtable *rt, |
1102 | struct rtable **rp, struct sk_buff *skb) | 1101 | struct rtable **rp, struct sk_buff *skb, int ifindex) |
1103 | { | 1102 | { |
1104 | struct rtable *rth, **rthp; | 1103 | struct rtable *rth, **rthp; |
1105 | unsigned long now; | 1104 | unsigned long now; |
@@ -1214,11 +1213,16 @@ restart: | |||
1214 | slow_chain_length(rt_hash_table[hash].chain) > rt_chain_length_max) { | 1213 | slow_chain_length(rt_hash_table[hash].chain) > rt_chain_length_max) { |
1215 | struct net *net = dev_net(rt->u.dst.dev); | 1214 | struct net *net = dev_net(rt->u.dst.dev); |
1216 | int num = ++net->ipv4.current_rt_cache_rebuild_count; | 1215 | int num = ++net->ipv4.current_rt_cache_rebuild_count; |
1217 | if (!rt_caching(dev_net(rt->u.dst.dev))) { | 1216 | if (!rt_caching(net)) { |
1218 | printk(KERN_WARNING "%s: %d rebuilds is over limit, route caching disabled\n", | 1217 | printk(KERN_WARNING "%s: %d rebuilds is over limit, route caching disabled\n", |
1219 | rt->u.dst.dev->name, num); | 1218 | rt->u.dst.dev->name, num); |
1220 | } | 1219 | } |
1221 | rt_emergency_hash_rebuild(dev_net(rt->u.dst.dev)); | 1220 | rt_emergency_hash_rebuild(net); |
1221 | spin_unlock_bh(rt_hash_lock_addr(hash)); | ||
1222 | |||
1223 | hash = rt_hash(rt->fl.fl4_dst, rt->fl.fl4_src, | ||
1224 | ifindex, rt_genid(net)); | ||
1225 | goto restart; | ||
1222 | } | 1226 | } |
1223 | } | 1227 | } |
1224 | 1228 | ||
@@ -1443,7 +1447,7 @@ void ip_rt_redirect(__be32 old_gw, __be32 daddr, __be32 new_gw, | |||
1443 | dev_hold(rt->u.dst.dev); | 1447 | dev_hold(rt->u.dst.dev); |
1444 | if (rt->idev) | 1448 | if (rt->idev) |
1445 | in_dev_hold(rt->idev); | 1449 | in_dev_hold(rt->idev); |
1446 | rt->u.dst.obsolete = 0; | 1450 | rt->u.dst.obsolete = -1; |
1447 | rt->u.dst.lastuse = jiffies; | 1451 | rt->u.dst.lastuse = jiffies; |
1448 | rt->u.dst.path = &rt->u.dst; | 1452 | rt->u.dst.path = &rt->u.dst; |
1449 | rt->u.dst.neighbour = NULL; | 1453 | rt->u.dst.neighbour = NULL; |
@@ -1479,7 +1483,7 @@ void ip_rt_redirect(__be32 old_gw, __be32 daddr, __be32 new_gw, | |||
1479 | &netevent); | 1483 | &netevent); |
1480 | 1484 | ||
1481 | rt_del(hash, rth); | 1485 | rt_del(hash, rth); |
1482 | if (!rt_intern_hash(hash, rt, &rt, NULL)) | 1486 | if (!rt_intern_hash(hash, rt, &rt, NULL, rt->fl.oif)) |
1483 | ip_rt_put(rt); | 1487 | ip_rt_put(rt); |
1484 | goto do_next; | 1488 | goto do_next; |
1485 | } | 1489 | } |
@@ -1508,11 +1512,12 @@ static struct dst_entry *ipv4_negative_advice(struct dst_entry *dst) | |||
1508 | struct dst_entry *ret = dst; | 1512 | struct dst_entry *ret = dst; |
1509 | 1513 | ||
1510 | if (rt) { | 1514 | if (rt) { |
1511 | if (dst->obsolete) { | 1515 | if (dst->obsolete > 0) { |
1512 | ip_rt_put(rt); | 1516 | ip_rt_put(rt); |
1513 | ret = NULL; | 1517 | ret = NULL; |
1514 | } else if ((rt->rt_flags & RTCF_REDIRECTED) || | 1518 | } else if ((rt->rt_flags & RTCF_REDIRECTED) || |
1515 | rt->u.dst.expires) { | 1519 | (rt->u.dst.expires && |
1520 | time_after_eq(jiffies, rt->u.dst.expires))) { | ||
1516 | unsigned hash = rt_hash(rt->fl.fl4_dst, rt->fl.fl4_src, | 1521 | unsigned hash = rt_hash(rt->fl.fl4_dst, rt->fl.fl4_src, |
1517 | rt->fl.oif, | 1522 | rt->fl.oif, |
1518 | rt_genid(dev_net(dst->dev))); | 1523 | rt_genid(dev_net(dst->dev))); |
@@ -1728,7 +1733,9 @@ static void ip_rt_update_pmtu(struct dst_entry *dst, u32 mtu) | |||
1728 | 1733 | ||
1729 | static struct dst_entry *ipv4_dst_check(struct dst_entry *dst, u32 cookie) | 1734 | static struct dst_entry *ipv4_dst_check(struct dst_entry *dst, u32 cookie) |
1730 | { | 1735 | { |
1731 | return NULL; | 1736 | if (rt_is_expired((struct rtable *)dst)) |
1737 | return NULL; | ||
1738 | return dst; | ||
1732 | } | 1739 | } |
1733 | 1740 | ||
1734 | static void ipv4_dst_destroy(struct dst_entry *dst) | 1741 | static void ipv4_dst_destroy(struct dst_entry *dst) |
@@ -1890,7 +1897,8 @@ static int ip_route_input_mc(struct sk_buff *skb, __be32 daddr, __be32 saddr, | |||
1890 | if (!rth) | 1897 | if (!rth) |
1891 | goto e_nobufs; | 1898 | goto e_nobufs; |
1892 | 1899 | ||
1893 | rth->u.dst.output= ip_rt_bug; | 1900 | rth->u.dst.output = ip_rt_bug; |
1901 | rth->u.dst.obsolete = -1; | ||
1894 | 1902 | ||
1895 | atomic_set(&rth->u.dst.__refcnt, 1); | 1903 | atomic_set(&rth->u.dst.__refcnt, 1); |
1896 | rth->u.dst.flags= DST_HOST; | 1904 | rth->u.dst.flags= DST_HOST; |
@@ -1929,7 +1937,7 @@ static int ip_route_input_mc(struct sk_buff *skb, __be32 daddr, __be32 saddr, | |||
1929 | 1937 | ||
1930 | in_dev_put(in_dev); | 1938 | in_dev_put(in_dev); |
1931 | hash = rt_hash(daddr, saddr, dev->ifindex, rt_genid(dev_net(dev))); | 1939 | hash = rt_hash(daddr, saddr, dev->ifindex, rt_genid(dev_net(dev))); |
1932 | return rt_intern_hash(hash, rth, NULL, skb); | 1940 | return rt_intern_hash(hash, rth, NULL, skb, dev->ifindex); |
1933 | 1941 | ||
1934 | e_nobufs: | 1942 | e_nobufs: |
1935 | in_dev_put(in_dev); | 1943 | in_dev_put(in_dev); |
@@ -2056,6 +2064,7 @@ static int __mkroute_input(struct sk_buff *skb, | |||
2056 | rth->fl.oif = 0; | 2064 | rth->fl.oif = 0; |
2057 | rth->rt_spec_dst= spec_dst; | 2065 | rth->rt_spec_dst= spec_dst; |
2058 | 2066 | ||
2067 | rth->u.dst.obsolete = -1; | ||
2059 | rth->u.dst.input = ip_forward; | 2068 | rth->u.dst.input = ip_forward; |
2060 | rth->u.dst.output = ip_output; | 2069 | rth->u.dst.output = ip_output; |
2061 | rth->rt_genid = rt_genid(dev_net(rth->u.dst.dev)); | 2070 | rth->rt_genid = rt_genid(dev_net(rth->u.dst.dev)); |
@@ -2095,7 +2104,7 @@ static int ip_mkroute_input(struct sk_buff *skb, | |||
2095 | /* put it into the cache */ | 2104 | /* put it into the cache */ |
2096 | hash = rt_hash(daddr, saddr, fl->iif, | 2105 | hash = rt_hash(daddr, saddr, fl->iif, |
2097 | rt_genid(dev_net(rth->u.dst.dev))); | 2106 | rt_genid(dev_net(rth->u.dst.dev))); |
2098 | return rt_intern_hash(hash, rth, NULL, skb); | 2107 | return rt_intern_hash(hash, rth, NULL, skb, fl->iif); |
2099 | } | 2108 | } |
2100 | 2109 | ||
2101 | /* | 2110 | /* |
@@ -2220,6 +2229,7 @@ local_input: | |||
2220 | goto e_nobufs; | 2229 | goto e_nobufs; |
2221 | 2230 | ||
2222 | rth->u.dst.output= ip_rt_bug; | 2231 | rth->u.dst.output= ip_rt_bug; |
2232 | rth->u.dst.obsolete = -1; | ||
2223 | rth->rt_genid = rt_genid(net); | 2233 | rth->rt_genid = rt_genid(net); |
2224 | 2234 | ||
2225 | atomic_set(&rth->u.dst.__refcnt, 1); | 2235 | atomic_set(&rth->u.dst.__refcnt, 1); |
@@ -2251,7 +2261,7 @@ local_input: | |||
2251 | } | 2261 | } |
2252 | rth->rt_type = res.type; | 2262 | rth->rt_type = res.type; |
2253 | hash = rt_hash(daddr, saddr, fl.iif, rt_genid(net)); | 2263 | hash = rt_hash(daddr, saddr, fl.iif, rt_genid(net)); |
2254 | err = rt_intern_hash(hash, rth, NULL, skb); | 2264 | err = rt_intern_hash(hash, rth, NULL, skb, fl.iif); |
2255 | goto done; | 2265 | goto done; |
2256 | 2266 | ||
2257 | no_route: | 2267 | no_route: |
@@ -2446,6 +2456,7 @@ static int __mkroute_output(struct rtable **result, | |||
2446 | rth->rt_spec_dst= fl->fl4_src; | 2456 | rth->rt_spec_dst= fl->fl4_src; |
2447 | 2457 | ||
2448 | rth->u.dst.output=ip_output; | 2458 | rth->u.dst.output=ip_output; |
2459 | rth->u.dst.obsolete = -1; | ||
2449 | rth->rt_genid = rt_genid(dev_net(dev_out)); | 2460 | rth->rt_genid = rt_genid(dev_net(dev_out)); |
2450 | 2461 | ||
2451 | RT_CACHE_STAT_INC(out_slow_tot); | 2462 | RT_CACHE_STAT_INC(out_slow_tot); |
@@ -2497,7 +2508,7 @@ static int ip_mkroute_output(struct rtable **rp, | |||
2497 | if (err == 0) { | 2508 | if (err == 0) { |
2498 | hash = rt_hash(oldflp->fl4_dst, oldflp->fl4_src, oldflp->oif, | 2509 | hash = rt_hash(oldflp->fl4_dst, oldflp->fl4_src, oldflp->oif, |
2499 | rt_genid(dev_net(dev_out))); | 2510 | rt_genid(dev_net(dev_out))); |
2500 | err = rt_intern_hash(hash, rth, rp, NULL); | 2511 | err = rt_intern_hash(hash, rth, rp, NULL, oldflp->oif); |
2501 | } | 2512 | } |
2502 | 2513 | ||
2503 | return err; | 2514 | return err; |
@@ -3103,22 +3114,20 @@ static void rt_secret_reschedule(int old) | |||
3103 | rtnl_lock(); | 3114 | rtnl_lock(); |
3104 | for_each_net(net) { | 3115 | for_each_net(net) { |
3105 | int deleted = del_timer_sync(&net->ipv4.rt_secret_timer); | 3116 | int deleted = del_timer_sync(&net->ipv4.rt_secret_timer); |
3117 | long time; | ||
3106 | 3118 | ||
3107 | if (!new) | 3119 | if (!new) |
3108 | continue; | 3120 | continue; |
3109 | 3121 | ||
3110 | if (deleted) { | 3122 | if (deleted) { |
3111 | long time = net->ipv4.rt_secret_timer.expires - jiffies; | 3123 | time = net->ipv4.rt_secret_timer.expires - jiffies; |
3112 | 3124 | ||
3113 | if (time <= 0 || (time += diff) <= 0) | 3125 | if (time <= 0 || (time += diff) <= 0) |
3114 | time = 0; | 3126 | time = 0; |
3115 | |||
3116 | net->ipv4.rt_secret_timer.expires = time; | ||
3117 | } else | 3127 | } else |
3118 | net->ipv4.rt_secret_timer.expires = new; | 3128 | time = new; |
3119 | 3129 | ||
3120 | net->ipv4.rt_secret_timer.expires += jiffies; | 3130 | mod_timer(&net->ipv4.rt_secret_timer, jiffies + time); |
3121 | add_timer(&net->ipv4.rt_secret_timer); | ||
3122 | } | 3131 | } |
3123 | rtnl_unlock(); | 3132 | rtnl_unlock(); |
3124 | } | 3133 | } |
diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c index c1bc074f61b7..1cd5c15174b8 100644 --- a/net/ipv4/sysctl_net_ipv4.c +++ b/net/ipv4/sysctl_net_ipv4.c | |||
@@ -12,6 +12,7 @@ | |||
12 | #include <linux/inetdevice.h> | 12 | #include <linux/inetdevice.h> |
13 | #include <linux/seqlock.h> | 13 | #include <linux/seqlock.h> |
14 | #include <linux/init.h> | 14 | #include <linux/init.h> |
15 | #include <linux/slab.h> | ||
15 | #include <net/snmp.h> | 16 | #include <net/snmp.h> |
16 | #include <net/icmp.h> | 17 | #include <net/icmp.h> |
17 | #include <net/ip.h> | 18 | #include <net/ip.h> |
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index 5901010fad55..0f8caf64caa3 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c | |||
@@ -265,6 +265,7 @@ | |||
265 | #include <linux/err.h> | 265 | #include <linux/err.h> |
266 | #include <linux/crypto.h> | 266 | #include <linux/crypto.h> |
267 | #include <linux/time.h> | 267 | #include <linux/time.h> |
268 | #include <linux/slab.h> | ||
268 | 269 | ||
269 | #include <net/icmp.h> | 270 | #include <net/icmp.h> |
270 | #include <net/tcp.h> | 271 | #include <net/tcp.h> |
@@ -429,7 +430,7 @@ unsigned int tcp_poll(struct file *file, struct socket *sock, poll_table *wait) | |||
429 | if (tp->urg_seq == tp->copied_seq && | 430 | if (tp->urg_seq == tp->copied_seq && |
430 | !sock_flag(sk, SOCK_URGINLINE) && | 431 | !sock_flag(sk, SOCK_URGINLINE) && |
431 | tp->urg_data) | 432 | tp->urg_data) |
432 | target--; | 433 | target++; |
433 | 434 | ||
434 | /* Potential race condition. If read of tp below will | 435 | /* Potential race condition. If read of tp below will |
435 | * escape above sk->sk_state, we can be illegally awaken | 436 | * escape above sk->sk_state, we can be illegally awaken |
@@ -1254,6 +1255,39 @@ static void tcp_prequeue_process(struct sock *sk) | |||
1254 | tp->ucopy.memory = 0; | 1255 | tp->ucopy.memory = 0; |
1255 | } | 1256 | } |
1256 | 1257 | ||
1258 | #ifdef CONFIG_NET_DMA | ||
1259 | static void tcp_service_net_dma(struct sock *sk, bool wait) | ||
1260 | { | ||
1261 | dma_cookie_t done, used; | ||
1262 | dma_cookie_t last_issued; | ||
1263 | struct tcp_sock *tp = tcp_sk(sk); | ||
1264 | |||
1265 | if (!tp->ucopy.dma_chan) | ||
1266 | return; | ||
1267 | |||
1268 | last_issued = tp->ucopy.dma_cookie; | ||
1269 | dma_async_memcpy_issue_pending(tp->ucopy.dma_chan); | ||
1270 | |||
1271 | do { | ||
1272 | if (dma_async_memcpy_complete(tp->ucopy.dma_chan, | ||
1273 | last_issued, &done, | ||
1274 | &used) == DMA_SUCCESS) { | ||
1275 | /* Safe to free early-copied skbs now */ | ||
1276 | __skb_queue_purge(&sk->sk_async_wait_queue); | ||
1277 | break; | ||
1278 | } else { | ||
1279 | struct sk_buff *skb; | ||
1280 | while ((skb = skb_peek(&sk->sk_async_wait_queue)) && | ||
1281 | (dma_async_is_complete(skb->dma_cookie, done, | ||
1282 | used) == DMA_SUCCESS)) { | ||
1283 | __skb_dequeue(&sk->sk_async_wait_queue); | ||
1284 | kfree_skb(skb); | ||
1285 | } | ||
1286 | } | ||
1287 | } while (wait); | ||
1288 | } | ||
1289 | #endif | ||
1290 | |||
1257 | static inline struct sk_buff *tcp_recv_skb(struct sock *sk, u32 seq, u32 *off) | 1291 | static inline struct sk_buff *tcp_recv_skb(struct sock *sk, u32 seq, u32 *off) |
1258 | { | 1292 | { |
1259 | struct sk_buff *skb; | 1293 | struct sk_buff *skb; |
@@ -1335,6 +1369,7 @@ int tcp_read_sock(struct sock *sk, read_descriptor_t *desc, | |||
1335 | sk_eat_skb(sk, skb, 0); | 1369 | sk_eat_skb(sk, skb, 0); |
1336 | if (!desc->count) | 1370 | if (!desc->count) |
1337 | break; | 1371 | break; |
1372 | tp->copied_seq = seq; | ||
1338 | } | 1373 | } |
1339 | tp->copied_seq = seq; | 1374 | tp->copied_seq = seq; |
1340 | 1375 | ||
@@ -1546,6 +1581,10 @@ int tcp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg, | |||
1546 | /* __ Set realtime policy in scheduler __ */ | 1581 | /* __ Set realtime policy in scheduler __ */ |
1547 | } | 1582 | } |
1548 | 1583 | ||
1584 | #ifdef CONFIG_NET_DMA | ||
1585 | if (tp->ucopy.dma_chan) | ||
1586 | dma_async_memcpy_issue_pending(tp->ucopy.dma_chan); | ||
1587 | #endif | ||
1549 | if (copied >= target) { | 1588 | if (copied >= target) { |
1550 | /* Do not sleep, just process backlog. */ | 1589 | /* Do not sleep, just process backlog. */ |
1551 | release_sock(sk); | 1590 | release_sock(sk); |
@@ -1554,6 +1593,7 @@ int tcp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg, | |||
1554 | sk_wait_data(sk, &timeo); | 1593 | sk_wait_data(sk, &timeo); |
1555 | 1594 | ||
1556 | #ifdef CONFIG_NET_DMA | 1595 | #ifdef CONFIG_NET_DMA |
1596 | tcp_service_net_dma(sk, false); /* Don't block */ | ||
1557 | tp->ucopy.wakeup = 0; | 1597 | tp->ucopy.wakeup = 0; |
1558 | #endif | 1598 | #endif |
1559 | 1599 | ||
@@ -1633,6 +1673,9 @@ do_prequeue: | |||
1633 | copied = -EFAULT; | 1673 | copied = -EFAULT; |
1634 | break; | 1674 | break; |
1635 | } | 1675 | } |
1676 | |||
1677 | dma_async_memcpy_issue_pending(tp->ucopy.dma_chan); | ||
1678 | |||
1636 | if ((offset + used) == skb->len) | 1679 | if ((offset + used) == skb->len) |
1637 | copied_early = 1; | 1680 | copied_early = 1; |
1638 | 1681 | ||
@@ -1702,27 +1745,9 @@ skip_copy: | |||
1702 | } | 1745 | } |
1703 | 1746 | ||
1704 | #ifdef CONFIG_NET_DMA | 1747 | #ifdef CONFIG_NET_DMA |
1705 | if (tp->ucopy.dma_chan) { | 1748 | tcp_service_net_dma(sk, true); /* Wait for queue to drain */ |
1706 | dma_cookie_t done, used; | 1749 | tp->ucopy.dma_chan = NULL; |
1707 | |||
1708 | dma_async_memcpy_issue_pending(tp->ucopy.dma_chan); | ||
1709 | |||
1710 | while (dma_async_memcpy_complete(tp->ucopy.dma_chan, | ||
1711 | tp->ucopy.dma_cookie, &done, | ||
1712 | &used) == DMA_IN_PROGRESS) { | ||
1713 | /* do partial cleanup of sk_async_wait_queue */ | ||
1714 | while ((skb = skb_peek(&sk->sk_async_wait_queue)) && | ||
1715 | (dma_async_is_complete(skb->dma_cookie, done, | ||
1716 | used) == DMA_SUCCESS)) { | ||
1717 | __skb_dequeue(&sk->sk_async_wait_queue); | ||
1718 | kfree_skb(skb); | ||
1719 | } | ||
1720 | } | ||
1721 | 1750 | ||
1722 | /* Safe to free early-copied skbs now */ | ||
1723 | __skb_queue_purge(&sk->sk_async_wait_queue); | ||
1724 | tp->ucopy.dma_chan = NULL; | ||
1725 | } | ||
1726 | if (tp->ucopy.pinned_list) { | 1751 | if (tp->ucopy.pinned_list) { |
1727 | dma_unpin_iovec_pages(tp->ucopy.pinned_list); | 1752 | dma_unpin_iovec_pages(tp->ucopy.pinned_list); |
1728 | tp->ucopy.pinned_list = NULL; | 1753 | tp->ucopy.pinned_list = NULL; |
diff --git a/net/ipv4/tcp_cong.c b/net/ipv4/tcp_cong.c index 6428b342b164..0ec9bd0ae94f 100644 --- a/net/ipv4/tcp_cong.c +++ b/net/ipv4/tcp_cong.c | |||
@@ -10,6 +10,7 @@ | |||
10 | #include <linux/mm.h> | 10 | #include <linux/mm.h> |
11 | #include <linux/types.h> | 11 | #include <linux/types.h> |
12 | #include <linux/list.h> | 12 | #include <linux/list.h> |
13 | #include <linux/gfp.h> | ||
13 | #include <net/tcp.h> | 14 | #include <net/tcp.h> |
14 | 15 | ||
15 | int sysctl_tcp_max_ssthresh = 0; | 16 | int sysctl_tcp_max_ssthresh = 0; |
diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index 788851ca8c5d..ae3ec15fb630 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c | |||
@@ -62,6 +62,7 @@ | |||
62 | */ | 62 | */ |
63 | 63 | ||
64 | #include <linux/mm.h> | 64 | #include <linux/mm.h> |
65 | #include <linux/slab.h> | ||
65 | #include <linux/module.h> | 66 | #include <linux/module.h> |
66 | #include <linux/sysctl.h> | 67 | #include <linux/sysctl.h> |
67 | #include <linux/kernel.h> | 68 | #include <linux/kernel.h> |
@@ -2511,6 +2512,9 @@ static void tcp_mark_head_lost(struct sock *sk, int packets) | |||
2511 | int err; | 2512 | int err; |
2512 | unsigned int mss; | 2513 | unsigned int mss; |
2513 | 2514 | ||
2515 | if (packets == 0) | ||
2516 | return; | ||
2517 | |||
2514 | WARN_ON(packets > tp->packets_out); | 2518 | WARN_ON(packets > tp->packets_out); |
2515 | if (tp->lost_skb_hint) { | 2519 | if (tp->lost_skb_hint) { |
2516 | skb = tp->lost_skb_hint; | 2520 | skb = tp->lost_skb_hint; |
@@ -3706,7 +3710,7 @@ static int tcp_ack(struct sock *sk, struct sk_buff *skb, int flag) | |||
3706 | } | 3710 | } |
3707 | 3711 | ||
3708 | if ((flag & FLAG_FORWARD_PROGRESS) || !(flag & FLAG_NOT_DUP)) | 3712 | if ((flag & FLAG_FORWARD_PROGRESS) || !(flag & FLAG_NOT_DUP)) |
3709 | dst_confirm(sk->sk_dst_cache); | 3713 | dst_confirm(__sk_dst_get(sk)); |
3710 | 3714 | ||
3711 | return 1; | 3715 | return 1; |
3712 | 3716 | ||
@@ -4315,7 +4319,7 @@ static void tcp_ofo_queue(struct sock *sk) | |||
4315 | } | 4319 | } |
4316 | 4320 | ||
4317 | if (!after(TCP_SKB_CB(skb)->end_seq, tp->rcv_nxt)) { | 4321 | if (!after(TCP_SKB_CB(skb)->end_seq, tp->rcv_nxt)) { |
4318 | SOCK_DEBUG(sk, "ofo packet was already received \n"); | 4322 | SOCK_DEBUG(sk, "ofo packet was already received\n"); |
4319 | __skb_unlink(skb, &tp->out_of_order_queue); | 4323 | __skb_unlink(skb, &tp->out_of_order_queue); |
4320 | __kfree_skb(skb); | 4324 | __kfree_skb(skb); |
4321 | continue; | 4325 | continue; |
@@ -5829,7 +5833,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb, | |||
5829 | if (tp->snd_una == tp->write_seq) { | 5833 | if (tp->snd_una == tp->write_seq) { |
5830 | tcp_set_state(sk, TCP_FIN_WAIT2); | 5834 | tcp_set_state(sk, TCP_FIN_WAIT2); |
5831 | sk->sk_shutdown |= SEND_SHUTDOWN; | 5835 | sk->sk_shutdown |= SEND_SHUTDOWN; |
5832 | dst_confirm(sk->sk_dst_cache); | 5836 | dst_confirm(__sk_dst_get(sk)); |
5833 | 5837 | ||
5834 | if (!sock_flag(sk, SOCK_DEAD)) | 5838 | if (!sock_flag(sk, SOCK_DEAD)) |
5835 | /* Wake up lingering close() */ | 5839 | /* Wake up lingering close() */ |
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index 8d51d39ad1bb..a24995cdc4b6 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c | |||
@@ -60,6 +60,7 @@ | |||
60 | #include <linux/jhash.h> | 60 | #include <linux/jhash.h> |
61 | #include <linux/init.h> | 61 | #include <linux/init.h> |
62 | #include <linux/times.h> | 62 | #include <linux/times.h> |
63 | #include <linux/slab.h> | ||
63 | 64 | ||
64 | #include <net/net_namespace.h> | 65 | #include <net/net_namespace.h> |
65 | #include <net/icmp.h> | 66 | #include <net/icmp.h> |
@@ -370,6 +371,11 @@ void tcp_v4_err(struct sk_buff *icmp_skb, u32 info) | |||
370 | if (sk->sk_state == TCP_CLOSE) | 371 | if (sk->sk_state == TCP_CLOSE) |
371 | goto out; | 372 | goto out; |
372 | 373 | ||
374 | if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) { | ||
375 | NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP); | ||
376 | goto out; | ||
377 | } | ||
378 | |||
373 | icsk = inet_csk(sk); | 379 | icsk = inet_csk(sk); |
374 | tp = tcp_sk(sk); | 380 | tp = tcp_sk(sk); |
375 | seq = ntohl(th->seq); | 381 | seq = ntohl(th->seq); |
@@ -513,26 +519,31 @@ out: | |||
513 | sock_put(sk); | 519 | sock_put(sk); |
514 | } | 520 | } |
515 | 521 | ||
516 | /* This routine computes an IPv4 TCP checksum. */ | 522 | static void __tcp_v4_send_check(struct sk_buff *skb, |
517 | void tcp_v4_send_check(struct sock *sk, int len, struct sk_buff *skb) | 523 | __be32 saddr, __be32 daddr) |
518 | { | 524 | { |
519 | struct inet_sock *inet = inet_sk(sk); | ||
520 | struct tcphdr *th = tcp_hdr(skb); | 525 | struct tcphdr *th = tcp_hdr(skb); |
521 | 526 | ||
522 | if (skb->ip_summed == CHECKSUM_PARTIAL) { | 527 | if (skb->ip_summed == CHECKSUM_PARTIAL) { |
523 | th->check = ~tcp_v4_check(len, inet->inet_saddr, | 528 | th->check = ~tcp_v4_check(skb->len, saddr, daddr, 0); |
524 | inet->inet_daddr, 0); | ||
525 | skb->csum_start = skb_transport_header(skb) - skb->head; | 529 | skb->csum_start = skb_transport_header(skb) - skb->head; |
526 | skb->csum_offset = offsetof(struct tcphdr, check); | 530 | skb->csum_offset = offsetof(struct tcphdr, check); |
527 | } else { | 531 | } else { |
528 | th->check = tcp_v4_check(len, inet->inet_saddr, | 532 | th->check = tcp_v4_check(skb->len, saddr, daddr, |
529 | inet->inet_daddr, | ||
530 | csum_partial(th, | 533 | csum_partial(th, |
531 | th->doff << 2, | 534 | th->doff << 2, |
532 | skb->csum)); | 535 | skb->csum)); |
533 | } | 536 | } |
534 | } | 537 | } |
535 | 538 | ||
539 | /* This routine computes an IPv4 TCP checksum. */ | ||
540 | void tcp_v4_send_check(struct sock *sk, struct sk_buff *skb) | ||
541 | { | ||
542 | struct inet_sock *inet = inet_sk(sk); | ||
543 | |||
544 | __tcp_v4_send_check(skb, inet->inet_saddr, inet->inet_daddr); | ||
545 | } | ||
546 | |||
536 | int tcp_v4_gso_send_check(struct sk_buff *skb) | 547 | int tcp_v4_gso_send_check(struct sk_buff *skb) |
537 | { | 548 | { |
538 | const struct iphdr *iph; | 549 | const struct iphdr *iph; |
@@ -545,10 +556,8 @@ int tcp_v4_gso_send_check(struct sk_buff *skb) | |||
545 | th = tcp_hdr(skb); | 556 | th = tcp_hdr(skb); |
546 | 557 | ||
547 | th->check = 0; | 558 | th->check = 0; |
548 | th->check = ~tcp_v4_check(skb->len, iph->saddr, iph->daddr, 0); | ||
549 | skb->csum_start = skb_transport_header(skb) - skb->head; | ||
550 | skb->csum_offset = offsetof(struct tcphdr, check); | ||
551 | skb->ip_summed = CHECKSUM_PARTIAL; | 559 | skb->ip_summed = CHECKSUM_PARTIAL; |
560 | __tcp_v4_send_check(skb, iph->saddr, iph->daddr); | ||
552 | return 0; | 561 | return 0; |
553 | } | 562 | } |
554 | 563 | ||
@@ -757,13 +766,7 @@ static int tcp_v4_send_synack(struct sock *sk, struct dst_entry *dst, | |||
757 | skb = tcp_make_synack(sk, dst, req, rvp); | 766 | skb = tcp_make_synack(sk, dst, req, rvp); |
758 | 767 | ||
759 | if (skb) { | 768 | if (skb) { |
760 | struct tcphdr *th = tcp_hdr(skb); | 769 | __tcp_v4_send_check(skb, ireq->loc_addr, ireq->rmt_addr); |
761 | |||
762 | th->check = tcp_v4_check(skb->len, | ||
763 | ireq->loc_addr, | ||
764 | ireq->rmt_addr, | ||
765 | csum_partial(th, skb->len, | ||
766 | skb->csum)); | ||
767 | 770 | ||
768 | err = ip_build_and_send_pkt(skb, sk, ireq->loc_addr, | 771 | err = ip_build_and_send_pkt(skb, sk, ireq->loc_addr, |
769 | ireq->rmt_addr, | 772 | ireq->rmt_addr, |
@@ -1651,15 +1654,15 @@ int tcp_v4_rcv(struct sk_buff *skb) | |||
1651 | if (!sk) | 1654 | if (!sk) |
1652 | goto no_tcp_socket; | 1655 | goto no_tcp_socket; |
1653 | 1656 | ||
1657 | process: | ||
1658 | if (sk->sk_state == TCP_TIME_WAIT) | ||
1659 | goto do_time_wait; | ||
1660 | |||
1654 | if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) { | 1661 | if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) { |
1655 | NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP); | 1662 | NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP); |
1656 | goto discard_and_relse; | 1663 | goto discard_and_relse; |
1657 | } | 1664 | } |
1658 | 1665 | ||
1659 | process: | ||
1660 | if (sk->sk_state == TCP_TIME_WAIT) | ||
1661 | goto do_time_wait; | ||
1662 | |||
1663 | if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) | 1666 | if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) |
1664 | goto discard_and_relse; | 1667 | goto discard_and_relse; |
1665 | nf_reset(skb); | 1668 | nf_reset(skb); |
diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c index 4199bc6915c5..794c2e122a41 100644 --- a/net/ipv4/tcp_minisocks.c +++ b/net/ipv4/tcp_minisocks.c | |||
@@ -20,6 +20,7 @@ | |||
20 | 20 | ||
21 | #include <linux/mm.h> | 21 | #include <linux/mm.h> |
22 | #include <linux/module.h> | 22 | #include <linux/module.h> |
23 | #include <linux/slab.h> | ||
23 | #include <linux/sysctl.h> | 24 | #include <linux/sysctl.h> |
24 | #include <linux/workqueue.h> | 25 | #include <linux/workqueue.h> |
25 | #include <net/tcp.h> | 26 | #include <net/tcp.h> |
@@ -671,6 +672,7 @@ struct sock *tcp_check_req(struct sock *sk, struct sk_buff *skb, | |||
671 | if (req->retrans < inet_csk(sk)->icsk_accept_queue.rskq_defer_accept && | 672 | if (req->retrans < inet_csk(sk)->icsk_accept_queue.rskq_defer_accept && |
672 | TCP_SKB_CB(skb)->end_seq == tcp_rsk(req)->rcv_isn + 1) { | 673 | TCP_SKB_CB(skb)->end_seq == tcp_rsk(req)->rcv_isn + 1) { |
673 | inet_rsk(req)->acked = 1; | 674 | inet_rsk(req)->acked = 1; |
675 | NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_TCPDEFERACCEPTDROP); | ||
674 | return NULL; | 676 | return NULL; |
675 | } | 677 | } |
676 | 678 | ||
diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c index f181b78f2385..e46849989a53 100644 --- a/net/ipv4/tcp_output.c +++ b/net/ipv4/tcp_output.c | |||
@@ -37,6 +37,7 @@ | |||
37 | #include <net/tcp.h> | 37 | #include <net/tcp.h> |
38 | 38 | ||
39 | #include <linux/compiler.h> | 39 | #include <linux/compiler.h> |
40 | #include <linux/gfp.h> | ||
40 | #include <linux/module.h> | 41 | #include <linux/module.h> |
41 | 42 | ||
42 | /* People can turn this off for buggy TCP's found in printers etc. */ | 43 | /* People can turn this off for buggy TCP's found in printers etc. */ |
@@ -349,6 +350,7 @@ static inline void TCP_ECN_send(struct sock *sk, struct sk_buff *skb, | |||
349 | */ | 350 | */ |
350 | static void tcp_init_nondata_skb(struct sk_buff *skb, u32 seq, u8 flags) | 351 | static void tcp_init_nondata_skb(struct sk_buff *skb, u32 seq, u8 flags) |
351 | { | 352 | { |
353 | skb->ip_summed = CHECKSUM_PARTIAL; | ||
352 | skb->csum = 0; | 354 | skb->csum = 0; |
353 | 355 | ||
354 | TCP_SKB_CB(skb)->flags = flags; | 356 | TCP_SKB_CB(skb)->flags = flags; |
@@ -877,7 +879,7 @@ static int tcp_transmit_skb(struct sock *sk, struct sk_buff *skb, int clone_it, | |||
877 | } | 879 | } |
878 | #endif | 880 | #endif |
879 | 881 | ||
880 | icsk->icsk_af_ops->send_check(sk, skb->len, skb); | 882 | icsk->icsk_af_ops->send_check(sk, skb); |
881 | 883 | ||
882 | if (likely(tcb->flags & TCPCB_FLAG_ACK)) | 884 | if (likely(tcb->flags & TCPCB_FLAG_ACK)) |
883 | tcp_event_ack_sent(sk, tcp_skb_pcount(skb)); | 885 | tcp_event_ack_sent(sk, tcp_skb_pcount(skb)); |
diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c index 9bc805df95d2..f8efada580e8 100644 --- a/net/ipv4/tcp_probe.c +++ b/net/ipv4/tcp_probe.c | |||
@@ -22,6 +22,7 @@ | |||
22 | #include <linux/kprobes.h> | 22 | #include <linux/kprobes.h> |
23 | #include <linux/socket.h> | 23 | #include <linux/socket.h> |
24 | #include <linux/tcp.h> | 24 | #include <linux/tcp.h> |
25 | #include <linux/slab.h> | ||
25 | #include <linux/proc_fs.h> | 26 | #include <linux/proc_fs.h> |
26 | #include <linux/module.h> | 27 | #include <linux/module.h> |
27 | #include <linux/ktime.h> | 28 | #include <linux/ktime.h> |
diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c index a17629b8912e..c732be00606b 100644 --- a/net/ipv4/tcp_timer.c +++ b/net/ipv4/tcp_timer.c | |||
@@ -19,6 +19,7 @@ | |||
19 | */ | 19 | */ |
20 | 20 | ||
21 | #include <linux/module.h> | 21 | #include <linux/module.h> |
22 | #include <linux/gfp.h> | ||
22 | #include <net/tcp.h> | 23 | #include <net/tcp.h> |
23 | 24 | ||
24 | int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES; | 25 | int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES; |
@@ -134,7 +135,7 @@ static void tcp_mtu_probing(struct inet_connection_sock *icsk, struct sock *sk) | |||
134 | } | 135 | } |
135 | 136 | ||
136 | /* This function calculates a "timeout" which is equivalent to the timeout of a | 137 | /* This function calculates a "timeout" which is equivalent to the timeout of a |
137 | * TCP connection after "boundary" unsucessful, exponentially backed-off | 138 | * TCP connection after "boundary" unsuccessful, exponentially backed-off |
138 | * retransmissions with an initial RTO of TCP_RTO_MIN. | 139 | * retransmissions with an initial RTO of TCP_RTO_MIN. |
139 | */ | 140 | */ |
140 | static bool retransmits_timed_out(struct sock *sk, | 141 | static bool retransmits_timed_out(struct sock *sk, |
@@ -171,14 +172,14 @@ static int tcp_write_timeout(struct sock *sk) | |||
171 | 172 | ||
172 | if ((1 << sk->sk_state) & (TCPF_SYN_SENT | TCPF_SYN_RECV)) { | 173 | if ((1 << sk->sk_state) & (TCPF_SYN_SENT | TCPF_SYN_RECV)) { |
173 | if (icsk->icsk_retransmits) | 174 | if (icsk->icsk_retransmits) |
174 | dst_negative_advice(&sk->sk_dst_cache, sk); | 175 | dst_negative_advice(sk); |
175 | retry_until = icsk->icsk_syn_retries ? : sysctl_tcp_syn_retries; | 176 | retry_until = icsk->icsk_syn_retries ? : sysctl_tcp_syn_retries; |
176 | } else { | 177 | } else { |
177 | if (retransmits_timed_out(sk, sysctl_tcp_retries1)) { | 178 | if (retransmits_timed_out(sk, sysctl_tcp_retries1)) { |
178 | /* Black hole detection */ | 179 | /* Black hole detection */ |
179 | tcp_mtu_probing(icsk, sk); | 180 | tcp_mtu_probing(icsk, sk); |
180 | 181 | ||
181 | dst_negative_advice(&sk->sk_dst_cache, sk); | 182 | dst_negative_advice(sk); |
182 | } | 183 | } |
183 | 184 | ||
184 | retry_until = sysctl_tcp_retries2; | 185 | retry_until = sysctl_tcp_retries2; |
diff --git a/net/ipv4/tunnel4.c b/net/ipv4/tunnel4.c index 3959e0ca456a..3b3813cc80b9 100644 --- a/net/ipv4/tunnel4.c +++ b/net/ipv4/tunnel4.c | |||
@@ -8,6 +8,7 @@ | |||
8 | #include <linux/mutex.h> | 8 | #include <linux/mutex.h> |
9 | #include <linux/netdevice.h> | 9 | #include <linux/netdevice.h> |
10 | #include <linux/skbuff.h> | 10 | #include <linux/skbuff.h> |
11 | #include <linux/slab.h> | ||
11 | #include <net/icmp.h> | 12 | #include <net/icmp.h> |
12 | #include <net/ip.h> | 13 | #include <net/ip.h> |
13 | #include <net/protocol.h> | 14 | #include <net/protocol.h> |
diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c index 7af756d0f931..8fef859db35d 100644 --- a/net/ipv4/udp.c +++ b/net/ipv4/udp.c | |||
@@ -95,6 +95,7 @@ | |||
95 | #include <linux/mm.h> | 95 | #include <linux/mm.h> |
96 | #include <linux/inet.h> | 96 | #include <linux/inet.h> |
97 | #include <linux/netdevice.h> | 97 | #include <linux/netdevice.h> |
98 | #include <linux/slab.h> | ||
98 | #include <net/tcp_states.h> | 99 | #include <net/tcp_states.h> |
99 | #include <linux/skbuff.h> | 100 | #include <linux/skbuff.h> |
100 | #include <linux/proc_fs.h> | 101 | #include <linux/proc_fs.h> |
@@ -471,8 +472,8 @@ static struct sock *__udp4_lib_lookup(struct net *net, __be32 saddr, | |||
471 | if (hslot->count < hslot2->count) | 472 | if (hslot->count < hslot2->count) |
472 | goto begin; | 473 | goto begin; |
473 | 474 | ||
474 | result = udp4_lib_lookup2(net, INADDR_ANY, sport, | 475 | result = udp4_lib_lookup2(net, saddr, sport, |
475 | daddr, hnum, dif, | 476 | INADDR_ANY, hnum, dif, |
476 | hslot2, slot2); | 477 | hslot2, slot2); |
477 | } | 478 | } |
478 | rcu_read_unlock(); | 479 | rcu_read_unlock(); |
diff --git a/net/ipv4/xfrm4_input.c b/net/ipv4/xfrm4_input.c index f9f922a0ba88..c791bb63203f 100644 --- a/net/ipv4/xfrm4_input.c +++ b/net/ipv4/xfrm4_input.c | |||
@@ -9,6 +9,7 @@ | |||
9 | * | 9 | * |
10 | */ | 10 | */ |
11 | 11 | ||
12 | #include <linux/slab.h> | ||
12 | #include <linux/module.h> | 13 | #include <linux/module.h> |
13 | #include <linux/string.h> | 14 | #include <linux/string.h> |
14 | #include <linux/netfilter.h> | 15 | #include <linux/netfilter.h> |
diff --git a/net/ipv4/xfrm4_mode_tunnel.c b/net/ipv4/xfrm4_mode_tunnel.c index 3444f3b34eca..6f368413eb0e 100644 --- a/net/ipv4/xfrm4_mode_tunnel.c +++ b/net/ipv4/xfrm4_mode_tunnel.c | |||
@@ -4,6 +4,7 @@ | |||
4 | * Copyright (c) 2004-2006 Herbert Xu <herbert@gondor.apana.org.au> | 4 | * Copyright (c) 2004-2006 Herbert Xu <herbert@gondor.apana.org.au> |
5 | */ | 5 | */ |
6 | 6 | ||
7 | #include <linux/gfp.h> | ||
7 | #include <linux/init.h> | 8 | #include <linux/init.h> |
8 | #include <linux/kernel.h> | 9 | #include <linux/kernel.h> |
9 | #include <linux/module.h> | 10 | #include <linux/module.h> |
diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c index e4a1483fba77..1705476670ef 100644 --- a/net/ipv4/xfrm4_policy.c +++ b/net/ipv4/xfrm4_policy.c | |||
@@ -59,27 +59,6 @@ static int xfrm4_get_saddr(struct net *net, | |||
59 | return 0; | 59 | return 0; |
60 | } | 60 | } |
61 | 61 | ||
62 | static struct dst_entry * | ||
63 | __xfrm4_find_bundle(struct flowi *fl, struct xfrm_policy *policy) | ||
64 | { | ||
65 | struct dst_entry *dst; | ||
66 | |||
67 | read_lock_bh(&policy->lock); | ||
68 | for (dst = policy->bundles; dst; dst = dst->next) { | ||
69 | struct xfrm_dst *xdst = (struct xfrm_dst *)dst; | ||
70 | if (xdst->u.rt.fl.oif == fl->oif && /*XXX*/ | ||
71 | xdst->u.rt.fl.fl4_dst == fl->fl4_dst && | ||
72 | xdst->u.rt.fl.fl4_src == fl->fl4_src && | ||
73 | xdst->u.rt.fl.fl4_tos == fl->fl4_tos && | ||
74 | xfrm_bundle_ok(policy, xdst, fl, AF_INET, 0)) { | ||
75 | dst_clone(dst); | ||
76 | break; | ||
77 | } | ||
78 | } | ||
79 | read_unlock_bh(&policy->lock); | ||
80 | return dst; | ||
81 | } | ||
82 | |||
83 | static int xfrm4_get_tos(struct flowi *fl) | 62 | static int xfrm4_get_tos(struct flowi *fl) |
84 | { | 63 | { |
85 | return fl->fl4_tos; | 64 | return fl->fl4_tos; |
@@ -259,7 +238,6 @@ static struct xfrm_policy_afinfo xfrm4_policy_afinfo = { | |||
259 | .dst_ops = &xfrm4_dst_ops, | 238 | .dst_ops = &xfrm4_dst_ops, |
260 | .dst_lookup = xfrm4_dst_lookup, | 239 | .dst_lookup = xfrm4_dst_lookup, |
261 | .get_saddr = xfrm4_get_saddr, | 240 | .get_saddr = xfrm4_get_saddr, |
262 | .find_bundle = __xfrm4_find_bundle, | ||
263 | .decode_session = _decode_session4, | 241 | .decode_session = _decode_session4, |
264 | .get_tos = xfrm4_get_tos, | 242 | .get_tos = xfrm4_get_tos, |
265 | .init_path = xfrm4_init_path, | 243 | .init_path = xfrm4_init_path, |
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c index 6cf3ee14ace3..7cba8845242f 100644 --- a/net/ipv6/addrconf.c +++ b/net/ipv6/addrconf.c | |||
@@ -53,6 +53,7 @@ | |||
53 | #include <linux/route.h> | 53 | #include <linux/route.h> |
54 | #include <linux/inetdevice.h> | 54 | #include <linux/inetdevice.h> |
55 | #include <linux/init.h> | 55 | #include <linux/init.h> |
56 | #include <linux/slab.h> | ||
56 | #ifdef CONFIG_SYSCTL | 57 | #ifdef CONFIG_SYSCTL |
57 | #include <linux/sysctl.h> | 58 | #include <linux/sysctl.h> |
58 | #endif | 59 | #endif |
@@ -81,7 +82,7 @@ | |||
81 | #include <linux/random.h> | 82 | #include <linux/random.h> |
82 | #endif | 83 | #endif |
83 | 84 | ||
84 | #include <asm/uaccess.h> | 85 | #include <linux/uaccess.h> |
85 | #include <asm/unaligned.h> | 86 | #include <asm/unaligned.h> |
86 | 87 | ||
87 | #include <linux/proc_fs.h> | 88 | #include <linux/proc_fs.h> |
@@ -97,7 +98,11 @@ | |||
97 | #endif | 98 | #endif |
98 | 99 | ||
99 | #define INFINITY_LIFE_TIME 0xFFFFFFFF | 100 | #define INFINITY_LIFE_TIME 0xFFFFFFFF |
100 | #define TIME_DELTA(a,b) ((unsigned long)((long)(a) - (long)(b))) | 101 | #define TIME_DELTA(a, b) ((unsigned long)((long)(a) - (long)(b))) |
102 | |||
103 | #define ADDRCONF_TIMER_FUZZ_MINUS (HZ > 50 ? HZ/50 : 1) | ||
104 | #define ADDRCONF_TIMER_FUZZ (HZ / 4) | ||
105 | #define ADDRCONF_TIMER_FUZZ_MAX (HZ) | ||
101 | 106 | ||
102 | #ifdef CONFIG_SYSCTL | 107 | #ifdef CONFIG_SYSCTL |
103 | static void addrconf_sysctl_register(struct inet6_dev *idev); | 108 | static void addrconf_sysctl_register(struct inet6_dev *idev); |
@@ -126,8 +131,8 @@ static int ipv6_count_addresses(struct inet6_dev *idev); | |||
126 | /* | 131 | /* |
127 | * Configured unicast address hash table | 132 | * Configured unicast address hash table |
128 | */ | 133 | */ |
129 | static struct inet6_ifaddr *inet6_addr_lst[IN6_ADDR_HSIZE]; | 134 | static struct hlist_head inet6_addr_lst[IN6_ADDR_HSIZE]; |
130 | static DEFINE_RWLOCK(addrconf_hash_lock); | 135 | static DEFINE_SPINLOCK(addrconf_hash_lock); |
131 | 136 | ||
132 | static void addrconf_verify(unsigned long); | 137 | static void addrconf_verify(unsigned long); |
133 | 138 | ||
@@ -137,8 +142,8 @@ static DEFINE_SPINLOCK(addrconf_verify_lock); | |||
137 | static void addrconf_join_anycast(struct inet6_ifaddr *ifp); | 142 | static void addrconf_join_anycast(struct inet6_ifaddr *ifp); |
138 | static void addrconf_leave_anycast(struct inet6_ifaddr *ifp); | 143 | static void addrconf_leave_anycast(struct inet6_ifaddr *ifp); |
139 | 144 | ||
140 | static void addrconf_bonding_change(struct net_device *dev, | 145 | static void addrconf_type_change(struct net_device *dev, |
141 | unsigned long event); | 146 | unsigned long event); |
142 | static int addrconf_ifdown(struct net_device *dev, int how); | 147 | static int addrconf_ifdown(struct net_device *dev, int how); |
143 | 148 | ||
144 | static void addrconf_dad_start(struct inet6_ifaddr *ifp, u32 flags); | 149 | static void addrconf_dad_start(struct inet6_ifaddr *ifp, u32 flags); |
@@ -151,8 +156,8 @@ static void ipv6_ifa_notify(int event, struct inet6_ifaddr *ifa); | |||
151 | 156 | ||
152 | static void inet6_prefix_notify(int event, struct inet6_dev *idev, | 157 | static void inet6_prefix_notify(int event, struct inet6_dev *idev, |
153 | struct prefix_info *pinfo); | 158 | struct prefix_info *pinfo); |
154 | static int ipv6_chk_same_addr(struct net *net, const struct in6_addr *addr, | 159 | static bool ipv6_chk_same_addr(struct net *net, const struct in6_addr *addr, |
155 | struct net_device *dev); | 160 | struct net_device *dev); |
156 | 161 | ||
157 | static ATOMIC_NOTIFIER_HEAD(inet6addr_chain); | 162 | static ATOMIC_NOTIFIER_HEAD(inet6addr_chain); |
158 | 163 | ||
@@ -249,8 +254,7 @@ static void addrconf_del_timer(struct inet6_ifaddr *ifp) | |||
249 | __in6_ifa_put(ifp); | 254 | __in6_ifa_put(ifp); |
250 | } | 255 | } |
251 | 256 | ||
252 | enum addrconf_timer_t | 257 | enum addrconf_timer_t { |
253 | { | ||
254 | AC_NONE, | 258 | AC_NONE, |
255 | AC_DAD, | 259 | AC_DAD, |
256 | AC_RS, | 260 | AC_RS, |
@@ -270,7 +274,8 @@ static void addrconf_mod_timer(struct inet6_ifaddr *ifp, | |||
270 | case AC_RS: | 274 | case AC_RS: |
271 | ifp->timer.function = addrconf_rs_timer; | 275 | ifp->timer.function = addrconf_rs_timer; |
272 | break; | 276 | break; |
273 | default:; | 277 | default: |
278 | break; | ||
274 | } | 279 | } |
275 | ifp->timer.expires = jiffies + when; | 280 | ifp->timer.expires = jiffies + when; |
276 | add_timer(&ifp->timer); | 281 | add_timer(&ifp->timer); |
@@ -317,7 +322,7 @@ void in6_dev_finish_destroy(struct inet6_dev *idev) | |||
317 | { | 322 | { |
318 | struct net_device *dev = idev->dev; | 323 | struct net_device *dev = idev->dev; |
319 | 324 | ||
320 | WARN_ON(idev->addr_list != NULL); | 325 | WARN_ON(!list_empty(&idev->addr_list)); |
321 | WARN_ON(idev->mc_list != NULL); | 326 | WARN_ON(idev->mc_list != NULL); |
322 | 327 | ||
323 | #ifdef NET_REFCNT_DEBUG | 328 | #ifdef NET_REFCNT_DEBUG |
@@ -325,7 +330,7 @@ void in6_dev_finish_destroy(struct inet6_dev *idev) | |||
325 | #endif | 330 | #endif |
326 | dev_put(dev); | 331 | dev_put(dev); |
327 | if (!idev->dead) { | 332 | if (!idev->dead) { |
328 | printk("Freeing alive inet6 device %p\n", idev); | 333 | pr_warning("Freeing alive inet6 device %p\n", idev); |
329 | return; | 334 | return; |
330 | } | 335 | } |
331 | snmp6_free_dev(idev); | 336 | snmp6_free_dev(idev); |
@@ -350,6 +355,8 @@ static struct inet6_dev * ipv6_add_dev(struct net_device *dev) | |||
350 | 355 | ||
351 | rwlock_init(&ndev->lock); | 356 | rwlock_init(&ndev->lock); |
352 | ndev->dev = dev; | 357 | ndev->dev = dev; |
358 | INIT_LIST_HEAD(&ndev->addr_list); | ||
359 | |||
353 | memcpy(&ndev->cnf, dev_net(dev)->ipv6.devconf_dflt, sizeof(ndev->cnf)); | 360 | memcpy(&ndev->cnf, dev_net(dev)->ipv6.devconf_dflt, sizeof(ndev->cnf)); |
354 | ndev->cnf.mtu6 = dev->mtu; | 361 | ndev->cnf.mtu6 = dev->mtu; |
355 | ndev->cnf.sysctl = NULL; | 362 | ndev->cnf.sysctl = NULL; |
@@ -401,6 +408,7 @@ static struct inet6_dev * ipv6_add_dev(struct net_device *dev) | |||
401 | #endif | 408 | #endif |
402 | 409 | ||
403 | #ifdef CONFIG_IPV6_PRIVACY | 410 | #ifdef CONFIG_IPV6_PRIVACY |
411 | INIT_LIST_HEAD(&ndev->tempaddr_list); | ||
404 | setup_timer(&ndev->regen_timer, ipv6_regen_rndid, (unsigned long)ndev); | 412 | setup_timer(&ndev->regen_timer, ipv6_regen_rndid, (unsigned long)ndev); |
405 | if ((dev->flags&IFF_LOOPBACK) || | 413 | if ((dev->flags&IFF_LOOPBACK) || |
406 | dev->type == ARPHRD_TUNNEL || | 414 | dev->type == ARPHRD_TUNNEL || |
@@ -438,8 +446,10 @@ static struct inet6_dev * ipv6_find_idev(struct net_device *dev) | |||
438 | 446 | ||
439 | ASSERT_RTNL(); | 447 | ASSERT_RTNL(); |
440 | 448 | ||
441 | if ((idev = __in6_dev_get(dev)) == NULL) { | 449 | idev = __in6_dev_get(dev); |
442 | if ((idev = ipv6_add_dev(dev)) == NULL) | 450 | if (!idev) { |
451 | idev = ipv6_add_dev(dev); | ||
452 | if (!idev) | ||
443 | return NULL; | 453 | return NULL; |
444 | } | 454 | } |
445 | 455 | ||
@@ -465,7 +475,8 @@ static void dev_forward_change(struct inet6_dev *idev) | |||
465 | else | 475 | else |
466 | ipv6_dev_mc_dec(dev, &in6addr_linklocal_allrouters); | 476 | ipv6_dev_mc_dec(dev, &in6addr_linklocal_allrouters); |
467 | } | 477 | } |
468 | for (ifa=idev->addr_list; ifa; ifa=ifa->if_next) { | 478 | |
479 | list_for_each_entry(ifa, &idev->addr_list, if_list) { | ||
469 | if (ifa->flags&IFA_F_TENTATIVE) | 480 | if (ifa->flags&IFA_F_TENTATIVE) |
470 | continue; | 481 | continue; |
471 | if (idev->cnf.forwarding) | 482 | if (idev->cnf.forwarding) |
@@ -522,12 +533,16 @@ static int addrconf_fixup_forwarding(struct ctl_table *table, int *p, int old) | |||
522 | } | 533 | } |
523 | #endif | 534 | #endif |
524 | 535 | ||
525 | /* Nobody refers to this ifaddr, destroy it */ | 536 | static void inet6_ifa_finish_destroy_rcu(struct rcu_head *head) |
537 | { | ||
538 | struct inet6_ifaddr *ifp = container_of(head, struct inet6_ifaddr, rcu); | ||
539 | kfree(ifp); | ||
540 | } | ||
526 | 541 | ||
542 | /* Nobody refers to this ifaddr, destroy it */ | ||
527 | void inet6_ifa_finish_destroy(struct inet6_ifaddr *ifp) | 543 | void inet6_ifa_finish_destroy(struct inet6_ifaddr *ifp) |
528 | { | 544 | { |
529 | WARN_ON(ifp->if_next != NULL); | 545 | WARN_ON(!hlist_unhashed(&ifp->addr_lst)); |
530 | WARN_ON(ifp->lst_next != NULL); | ||
531 | 546 | ||
532 | #ifdef NET_REFCNT_DEBUG | 547 | #ifdef NET_REFCNT_DEBUG |
533 | printk(KERN_DEBUG "inet6_ifa_finish_destroy\n"); | 548 | printk(KERN_DEBUG "inet6_ifa_finish_destroy\n"); |
@@ -536,54 +551,45 @@ void inet6_ifa_finish_destroy(struct inet6_ifaddr *ifp) | |||
536 | in6_dev_put(ifp->idev); | 551 | in6_dev_put(ifp->idev); |
537 | 552 | ||
538 | if (del_timer(&ifp->timer)) | 553 | if (del_timer(&ifp->timer)) |
539 | printk("Timer is still running, when freeing ifa=%p\n", ifp); | 554 | pr_notice("Timer is still running, when freeing ifa=%p\n", ifp); |
540 | 555 | ||
541 | if (!ifp->dead) { | 556 | if (!ifp->dead) { |
542 | printk("Freeing alive inet6 address %p\n", ifp); | 557 | pr_warning("Freeing alive inet6 address %p\n", ifp); |
543 | return; | 558 | return; |
544 | } | 559 | } |
545 | dst_release(&ifp->rt->u.dst); | 560 | dst_release(&ifp->rt->u.dst); |
546 | 561 | ||
547 | kfree(ifp); | 562 | call_rcu(&ifp->rcu, inet6_ifa_finish_destroy_rcu); |
548 | } | 563 | } |
549 | 564 | ||
550 | static void | 565 | static void |
551 | ipv6_link_dev_addr(struct inet6_dev *idev, struct inet6_ifaddr *ifp) | 566 | ipv6_link_dev_addr(struct inet6_dev *idev, struct inet6_ifaddr *ifp) |
552 | { | 567 | { |
553 | struct inet6_ifaddr *ifa, **ifap; | 568 | struct list_head *p; |
554 | int ifp_scope = ipv6_addr_src_scope(&ifp->addr); | 569 | int ifp_scope = ipv6_addr_src_scope(&ifp->addr); |
555 | 570 | ||
556 | /* | 571 | /* |
557 | * Each device address list is sorted in order of scope - | 572 | * Each device address list is sorted in order of scope - |
558 | * global before linklocal. | 573 | * global before linklocal. |
559 | */ | 574 | */ |
560 | for (ifap = &idev->addr_list; (ifa = *ifap) != NULL; | 575 | list_for_each(p, &idev->addr_list) { |
561 | ifap = &ifa->if_next) { | 576 | struct inet6_ifaddr *ifa |
577 | = list_entry(p, struct inet6_ifaddr, if_list); | ||
562 | if (ifp_scope >= ipv6_addr_src_scope(&ifa->addr)) | 578 | if (ifp_scope >= ipv6_addr_src_scope(&ifa->addr)) |
563 | break; | 579 | break; |
564 | } | 580 | } |
565 | 581 | ||
566 | ifp->if_next = *ifap; | 582 | list_add_tail(&ifp->if_list, p); |
567 | *ifap = ifp; | ||
568 | } | 583 | } |
569 | 584 | ||
570 | /* | 585 | static u32 ipv6_addr_hash(const struct in6_addr *addr) |
571 | * Hash function taken from net_alias.c | ||
572 | */ | ||
573 | static u8 ipv6_addr_hash(const struct in6_addr *addr) | ||
574 | { | 586 | { |
575 | __u32 word; | ||
576 | |||
577 | /* | 587 | /* |
578 | * We perform the hash function over the last 64 bits of the address | 588 | * We perform the hash function over the last 64 bits of the address |
579 | * This will include the IEEE address token on links that support it. | 589 | * This will include the IEEE address token on links that support it. |
580 | */ | 590 | */ |
581 | 591 | return jhash_2words(addr->s6_addr32[2], addr->s6_addr32[3], 0) | |
582 | word = (__force u32)(addr->s6_addr32[2] ^ addr->s6_addr32[3]); | 592 | & (IN6_ADDR_HSIZE - 1); |
583 | word ^= (word >> 16); | ||
584 | word ^= (word >> 8); | ||
585 | |||
586 | return ((word ^ (word >> 4)) & 0x0f); | ||
587 | } | 593 | } |
588 | 594 | ||
589 | /* On success it returns ifp with increased reference count */ | 595 | /* On success it returns ifp with increased reference count */ |
@@ -594,7 +600,7 @@ ipv6_add_addr(struct inet6_dev *idev, const struct in6_addr *addr, int pfxlen, | |||
594 | { | 600 | { |
595 | struct inet6_ifaddr *ifa = NULL; | 601 | struct inet6_ifaddr *ifa = NULL; |
596 | struct rt6_info *rt; | 602 | struct rt6_info *rt; |
597 | int hash; | 603 | unsigned int hash; |
598 | int err = 0; | 604 | int err = 0; |
599 | int addr_type = ipv6_addr_type(addr); | 605 | int addr_type = ipv6_addr_type(addr); |
600 | 606 | ||
@@ -615,7 +621,7 @@ ipv6_add_addr(struct inet6_dev *idev, const struct in6_addr *addr, int pfxlen, | |||
615 | goto out2; | 621 | goto out2; |
616 | } | 622 | } |
617 | 623 | ||
618 | write_lock(&addrconf_hash_lock); | 624 | spin_lock(&addrconf_hash_lock); |
619 | 625 | ||
620 | /* Ignore adding duplicate addresses on an interface */ | 626 | /* Ignore adding duplicate addresses on an interface */ |
621 | if (ipv6_chk_same_addr(dev_net(idev->dev), addr, idev->dev)) { | 627 | if (ipv6_chk_same_addr(dev_net(idev->dev), addr, idev->dev)) { |
@@ -642,6 +648,7 @@ ipv6_add_addr(struct inet6_dev *idev, const struct in6_addr *addr, int pfxlen, | |||
642 | 648 | ||
643 | spin_lock_init(&ifa->lock); | 649 | spin_lock_init(&ifa->lock); |
644 | init_timer(&ifa->timer); | 650 | init_timer(&ifa->timer); |
651 | INIT_HLIST_NODE(&ifa->addr_lst); | ||
645 | ifa->timer.data = (unsigned long) ifa; | 652 | ifa->timer.data = (unsigned long) ifa; |
646 | ifa->scope = scope; | 653 | ifa->scope = scope; |
647 | ifa->prefix_len = pfxlen; | 654 | ifa->prefix_len = pfxlen; |
@@ -668,10 +675,8 @@ ipv6_add_addr(struct inet6_dev *idev, const struct in6_addr *addr, int pfxlen, | |||
668 | /* Add to big hash table */ | 675 | /* Add to big hash table */ |
669 | hash = ipv6_addr_hash(addr); | 676 | hash = ipv6_addr_hash(addr); |
670 | 677 | ||
671 | ifa->lst_next = inet6_addr_lst[hash]; | 678 | hlist_add_head_rcu(&ifa->addr_lst, &inet6_addr_lst[hash]); |
672 | inet6_addr_lst[hash] = ifa; | 679 | spin_unlock(&addrconf_hash_lock); |
673 | in6_ifa_hold(ifa); | ||
674 | write_unlock(&addrconf_hash_lock); | ||
675 | 680 | ||
676 | write_lock(&idev->lock); | 681 | write_lock(&idev->lock); |
677 | /* Add to inet6_dev unicast addr list. */ | 682 | /* Add to inet6_dev unicast addr list. */ |
@@ -679,8 +684,7 @@ ipv6_add_addr(struct inet6_dev *idev, const struct in6_addr *addr, int pfxlen, | |||
679 | 684 | ||
680 | #ifdef CONFIG_IPV6_PRIVACY | 685 | #ifdef CONFIG_IPV6_PRIVACY |
681 | if (ifa->flags&IFA_F_TEMPORARY) { | 686 | if (ifa->flags&IFA_F_TEMPORARY) { |
682 | ifa->tmp_next = idev->tempaddr_list; | 687 | list_add(&ifa->tmp_list, &idev->tempaddr_list); |
683 | idev->tempaddr_list = ifa; | ||
684 | in6_ifa_hold(ifa); | 688 | in6_ifa_hold(ifa); |
685 | } | 689 | } |
686 | #endif | 690 | #endif |
@@ -699,7 +703,7 @@ out2: | |||
699 | 703 | ||
700 | return ifa; | 704 | return ifa; |
701 | out: | 705 | out: |
702 | write_unlock(&addrconf_hash_lock); | 706 | spin_unlock(&addrconf_hash_lock); |
703 | goto out2; | 707 | goto out2; |
704 | } | 708 | } |
705 | 709 | ||
@@ -707,7 +711,7 @@ out: | |||
707 | 711 | ||
708 | static void ipv6_del_addr(struct inet6_ifaddr *ifp) | 712 | static void ipv6_del_addr(struct inet6_ifaddr *ifp) |
709 | { | 713 | { |
710 | struct inet6_ifaddr *ifa, **ifap; | 714 | struct inet6_ifaddr *ifa, *ifn; |
711 | struct inet6_dev *idev = ifp->idev; | 715 | struct inet6_dev *idev = ifp->idev; |
712 | int hash; | 716 | int hash; |
713 | int deleted = 0, onlink = 0; | 717 | int deleted = 0, onlink = 0; |
@@ -717,42 +721,27 @@ static void ipv6_del_addr(struct inet6_ifaddr *ifp) | |||
717 | 721 | ||
718 | ifp->dead = 1; | 722 | ifp->dead = 1; |
719 | 723 | ||
720 | write_lock_bh(&addrconf_hash_lock); | 724 | spin_lock_bh(&addrconf_hash_lock); |
721 | for (ifap = &inet6_addr_lst[hash]; (ifa=*ifap) != NULL; | 725 | hlist_del_init_rcu(&ifp->addr_lst); |
722 | ifap = &ifa->lst_next) { | 726 | spin_unlock_bh(&addrconf_hash_lock); |
723 | if (ifa == ifp) { | ||
724 | *ifap = ifa->lst_next; | ||
725 | __in6_ifa_put(ifp); | ||
726 | ifa->lst_next = NULL; | ||
727 | break; | ||
728 | } | ||
729 | } | ||
730 | write_unlock_bh(&addrconf_hash_lock); | ||
731 | 727 | ||
732 | write_lock_bh(&idev->lock); | 728 | write_lock_bh(&idev->lock); |
733 | #ifdef CONFIG_IPV6_PRIVACY | 729 | #ifdef CONFIG_IPV6_PRIVACY |
734 | if (ifp->flags&IFA_F_TEMPORARY) { | 730 | if (ifp->flags&IFA_F_TEMPORARY) { |
735 | for (ifap = &idev->tempaddr_list; (ifa=*ifap) != NULL; | 731 | list_del(&ifp->tmp_list); |
736 | ifap = &ifa->tmp_next) { | 732 | if (ifp->ifpub) { |
737 | if (ifa == ifp) { | 733 | in6_ifa_put(ifp->ifpub); |
738 | *ifap = ifa->tmp_next; | 734 | ifp->ifpub = NULL; |
739 | if (ifp->ifpub) { | ||
740 | in6_ifa_put(ifp->ifpub); | ||
741 | ifp->ifpub = NULL; | ||
742 | } | ||
743 | __in6_ifa_put(ifp); | ||
744 | ifa->tmp_next = NULL; | ||
745 | break; | ||
746 | } | ||
747 | } | 735 | } |
736 | __in6_ifa_put(ifp); | ||
748 | } | 737 | } |
749 | #endif | 738 | #endif |
750 | 739 | ||
751 | for (ifap = &idev->addr_list; (ifa=*ifap) != NULL;) { | 740 | list_for_each_entry_safe(ifa, ifn, &idev->addr_list, if_list) { |
752 | if (ifa == ifp) { | 741 | if (ifa == ifp) { |
753 | *ifap = ifa->if_next; | 742 | list_del_init(&ifp->if_list); |
754 | __in6_ifa_put(ifp); | 743 | __in6_ifa_put(ifp); |
755 | ifa->if_next = NULL; | 744 | |
756 | if (!(ifp->flags & IFA_F_PERMANENT) || onlink > 0) | 745 | if (!(ifp->flags & IFA_F_PERMANENT) || onlink > 0) |
757 | break; | 746 | break; |
758 | deleted = 1; | 747 | deleted = 1; |
@@ -785,7 +774,6 @@ static void ipv6_del_addr(struct inet6_ifaddr *ifp) | |||
785 | } | 774 | } |
786 | } | 775 | } |
787 | } | 776 | } |
788 | ifap = &ifa->if_next; | ||
789 | } | 777 | } |
790 | write_unlock_bh(&idev->lock); | 778 | write_unlock_bh(&idev->lock); |
791 | 779 | ||
@@ -1164,7 +1152,7 @@ int ipv6_dev_get_saddr(struct net *net, struct net_device *dst_dev, | |||
1164 | continue; | 1152 | continue; |
1165 | 1153 | ||
1166 | read_lock_bh(&idev->lock); | 1154 | read_lock_bh(&idev->lock); |
1167 | for (score->ifa = idev->addr_list; score->ifa; score->ifa = score->ifa->if_next) { | 1155 | list_for_each_entry(score->ifa, &idev->addr_list, if_list) { |
1168 | int i; | 1156 | int i; |
1169 | 1157 | ||
1170 | /* | 1158 | /* |
@@ -1242,7 +1230,6 @@ try_nextdev: | |||
1242 | in6_ifa_put(hiscore->ifa); | 1230 | in6_ifa_put(hiscore->ifa); |
1243 | return 0; | 1231 | return 0; |
1244 | } | 1232 | } |
1245 | |||
1246 | EXPORT_SYMBOL(ipv6_dev_get_saddr); | 1233 | EXPORT_SYMBOL(ipv6_dev_get_saddr); |
1247 | 1234 | ||
1248 | int ipv6_get_lladdr(struct net_device *dev, struct in6_addr *addr, | 1235 | int ipv6_get_lladdr(struct net_device *dev, struct in6_addr *addr, |
@@ -1252,12 +1239,14 @@ int ipv6_get_lladdr(struct net_device *dev, struct in6_addr *addr, | |||
1252 | int err = -EADDRNOTAVAIL; | 1239 | int err = -EADDRNOTAVAIL; |
1253 | 1240 | ||
1254 | rcu_read_lock(); | 1241 | rcu_read_lock(); |
1255 | if ((idev = __in6_dev_get(dev)) != NULL) { | 1242 | idev = __in6_dev_get(dev); |
1243 | if (idev) { | ||
1256 | struct inet6_ifaddr *ifp; | 1244 | struct inet6_ifaddr *ifp; |
1257 | 1245 | ||
1258 | read_lock_bh(&idev->lock); | 1246 | read_lock_bh(&idev->lock); |
1259 | for (ifp=idev->addr_list; ifp; ifp=ifp->if_next) { | 1247 | list_for_each_entry(ifp, &idev->addr_list, if_list) { |
1260 | if (ifp->scope == IFA_LINK && !(ifp->flags & banned_flags)) { | 1248 | if (ifp->scope == IFA_LINK && |
1249 | !(ifp->flags & banned_flags)) { | ||
1261 | ipv6_addr_copy(addr, &ifp->addr); | 1250 | ipv6_addr_copy(addr, &ifp->addr); |
1262 | err = 0; | 1251 | err = 0; |
1263 | break; | 1252 | break; |
@@ -1275,7 +1264,7 @@ static int ipv6_count_addresses(struct inet6_dev *idev) | |||
1275 | struct inet6_ifaddr *ifp; | 1264 | struct inet6_ifaddr *ifp; |
1276 | 1265 | ||
1277 | read_lock_bh(&idev->lock); | 1266 | read_lock_bh(&idev->lock); |
1278 | for (ifp=idev->addr_list; ifp; ifp=ifp->if_next) | 1267 | list_for_each_entry(ifp, &idev->addr_list, if_list) |
1279 | cnt++; | 1268 | cnt++; |
1280 | read_unlock_bh(&idev->lock); | 1269 | read_unlock_bh(&idev->lock); |
1281 | return cnt; | 1270 | return cnt; |
@@ -1284,11 +1273,12 @@ static int ipv6_count_addresses(struct inet6_dev *idev) | |||
1284 | int ipv6_chk_addr(struct net *net, struct in6_addr *addr, | 1273 | int ipv6_chk_addr(struct net *net, struct in6_addr *addr, |
1285 | struct net_device *dev, int strict) | 1274 | struct net_device *dev, int strict) |
1286 | { | 1275 | { |
1287 | struct inet6_ifaddr * ifp; | 1276 | struct inet6_ifaddr *ifp = NULL; |
1288 | u8 hash = ipv6_addr_hash(addr); | 1277 | struct hlist_node *node; |
1278 | unsigned int hash = ipv6_addr_hash(addr); | ||
1289 | 1279 | ||
1290 | read_lock_bh(&addrconf_hash_lock); | 1280 | rcu_read_lock_bh(); |
1291 | for(ifp = inet6_addr_lst[hash]; ifp; ifp=ifp->lst_next) { | 1281 | hlist_for_each_entry_rcu(ifp, node, &inet6_addr_lst[hash], addr_lst) { |
1292 | if (!net_eq(dev_net(ifp->idev->dev), net)) | 1282 | if (!net_eq(dev_net(ifp->idev->dev), net)) |
1293 | continue; | 1283 | continue; |
1294 | if (ipv6_addr_equal(&ifp->addr, addr) && | 1284 | if (ipv6_addr_equal(&ifp->addr, addr) && |
@@ -1298,27 +1288,28 @@ int ipv6_chk_addr(struct net *net, struct in6_addr *addr, | |||
1298 | break; | 1288 | break; |
1299 | } | 1289 | } |
1300 | } | 1290 | } |
1301 | read_unlock_bh(&addrconf_hash_lock); | 1291 | rcu_read_unlock_bh(); |
1292 | |||
1302 | return ifp != NULL; | 1293 | return ifp != NULL; |
1303 | } | 1294 | } |
1304 | EXPORT_SYMBOL(ipv6_chk_addr); | 1295 | EXPORT_SYMBOL(ipv6_chk_addr); |
1305 | 1296 | ||
1306 | static | 1297 | static bool ipv6_chk_same_addr(struct net *net, const struct in6_addr *addr, |
1307 | int ipv6_chk_same_addr(struct net *net, const struct in6_addr *addr, | 1298 | struct net_device *dev) |
1308 | struct net_device *dev) | ||
1309 | { | 1299 | { |
1310 | struct inet6_ifaddr * ifp; | 1300 | unsigned int hash = ipv6_addr_hash(addr); |
1311 | u8 hash = ipv6_addr_hash(addr); | 1301 | struct inet6_ifaddr *ifp; |
1302 | struct hlist_node *node; | ||
1312 | 1303 | ||
1313 | for(ifp = inet6_addr_lst[hash]; ifp; ifp=ifp->lst_next) { | 1304 | hlist_for_each_entry(ifp, node, &inet6_addr_lst[hash], addr_lst) { |
1314 | if (!net_eq(dev_net(ifp->idev->dev), net)) | 1305 | if (!net_eq(dev_net(ifp->idev->dev), net)) |
1315 | continue; | 1306 | continue; |
1316 | if (ipv6_addr_equal(&ifp->addr, addr)) { | 1307 | if (ipv6_addr_equal(&ifp->addr, addr)) { |
1317 | if (dev == NULL || ifp->idev->dev == dev) | 1308 | if (dev == NULL || ifp->idev->dev == dev) |
1318 | break; | 1309 | return true; |
1319 | } | 1310 | } |
1320 | } | 1311 | } |
1321 | return ifp != NULL; | 1312 | return false; |
1322 | } | 1313 | } |
1323 | 1314 | ||
1324 | int ipv6_chk_prefix(struct in6_addr *addr, struct net_device *dev) | 1315 | int ipv6_chk_prefix(struct in6_addr *addr, struct net_device *dev) |
@@ -1332,7 +1323,7 @@ int ipv6_chk_prefix(struct in6_addr *addr, struct net_device *dev) | |||
1332 | idev = __in6_dev_get(dev); | 1323 | idev = __in6_dev_get(dev); |
1333 | if (idev) { | 1324 | if (idev) { |
1334 | read_lock_bh(&idev->lock); | 1325 | read_lock_bh(&idev->lock); |
1335 | for (ifa = idev->addr_list; ifa; ifa = ifa->if_next) { | 1326 | list_for_each_entry(ifa, &idev->addr_list, if_list) { |
1336 | onlink = ipv6_prefix_equal(addr, &ifa->addr, | 1327 | onlink = ipv6_prefix_equal(addr, &ifa->addr, |
1337 | ifa->prefix_len); | 1328 | ifa->prefix_len); |
1338 | if (onlink) | 1329 | if (onlink) |
@@ -1349,24 +1340,26 @@ EXPORT_SYMBOL(ipv6_chk_prefix); | |||
1349 | struct inet6_ifaddr *ipv6_get_ifaddr(struct net *net, const struct in6_addr *addr, | 1340 | struct inet6_ifaddr *ipv6_get_ifaddr(struct net *net, const struct in6_addr *addr, |
1350 | struct net_device *dev, int strict) | 1341 | struct net_device *dev, int strict) |
1351 | { | 1342 | { |
1352 | struct inet6_ifaddr * ifp; | 1343 | struct inet6_ifaddr *ifp, *result = NULL; |
1353 | u8 hash = ipv6_addr_hash(addr); | 1344 | unsigned int hash = ipv6_addr_hash(addr); |
1345 | struct hlist_node *node; | ||
1354 | 1346 | ||
1355 | read_lock_bh(&addrconf_hash_lock); | 1347 | rcu_read_lock_bh(); |
1356 | for(ifp = inet6_addr_lst[hash]; ifp; ifp=ifp->lst_next) { | 1348 | hlist_for_each_entry_rcu(ifp, node, &inet6_addr_lst[hash], addr_lst) { |
1357 | if (!net_eq(dev_net(ifp->idev->dev), net)) | 1349 | if (!net_eq(dev_net(ifp->idev->dev), net)) |
1358 | continue; | 1350 | continue; |
1359 | if (ipv6_addr_equal(&ifp->addr, addr)) { | 1351 | if (ipv6_addr_equal(&ifp->addr, addr)) { |
1360 | if (dev == NULL || ifp->idev->dev == dev || | 1352 | if (dev == NULL || ifp->idev->dev == dev || |
1361 | !(ifp->scope&(IFA_LINK|IFA_HOST) || strict)) { | 1353 | !(ifp->scope&(IFA_LINK|IFA_HOST) || strict)) { |
1354 | result = ifp; | ||
1362 | in6_ifa_hold(ifp); | 1355 | in6_ifa_hold(ifp); |
1363 | break; | 1356 | break; |
1364 | } | 1357 | } |
1365 | } | 1358 | } |
1366 | } | 1359 | } |
1367 | read_unlock_bh(&addrconf_hash_lock); | 1360 | rcu_read_unlock_bh(); |
1368 | 1361 | ||
1369 | return ifp; | 1362 | return result; |
1370 | } | 1363 | } |
1371 | 1364 | ||
1372 | /* Gets referenced address, destroys ifaddr */ | 1365 | /* Gets referenced address, destroys ifaddr */ |
@@ -1380,6 +1373,8 @@ static void addrconf_dad_stop(struct inet6_ifaddr *ifp, int dad_failed) | |||
1380 | if (dad_failed) | 1373 | if (dad_failed) |
1381 | ifp->flags |= IFA_F_DADFAILED; | 1374 | ifp->flags |= IFA_F_DADFAILED; |
1382 | spin_unlock_bh(&ifp->lock); | 1375 | spin_unlock_bh(&ifp->lock); |
1376 | if (dad_failed) | ||
1377 | ipv6_ifa_notify(0, ifp); | ||
1383 | in6_ifa_put(ifp); | 1378 | in6_ifa_put(ifp); |
1384 | #ifdef CONFIG_IPV6_PRIVACY | 1379 | #ifdef CONFIG_IPV6_PRIVACY |
1385 | } else if (ifp->flags&IFA_F_TEMPORARY) { | 1380 | } else if (ifp->flags&IFA_F_TEMPORARY) { |
@@ -1567,7 +1562,7 @@ static int ipv6_inherit_eui64(u8 *eui, struct inet6_dev *idev) | |||
1567 | struct inet6_ifaddr *ifp; | 1562 | struct inet6_ifaddr *ifp; |
1568 | 1563 | ||
1569 | read_lock_bh(&idev->lock); | 1564 | read_lock_bh(&idev->lock); |
1570 | for (ifp=idev->addr_list; ifp; ifp=ifp->if_next) { | 1565 | list_for_each_entry(ifp, &idev->addr_list, if_list) { |
1571 | if (ifp->scope == IFA_LINK && !(ifp->flags&IFA_F_TENTATIVE)) { | 1566 | if (ifp->scope == IFA_LINK && !(ifp->flags&IFA_F_TENTATIVE)) { |
1572 | memcpy(eui, ifp->addr.s6_addr+8, 8); | 1567 | memcpy(eui, ifp->addr.s6_addr+8, 8); |
1573 | err = 0; | 1568 | err = 0; |
@@ -1735,7 +1730,8 @@ static struct inet6_dev *addrconf_add_dev(struct net_device *dev) | |||
1735 | 1730 | ||
1736 | ASSERT_RTNL(); | 1731 | ASSERT_RTNL(); |
1737 | 1732 | ||
1738 | if ((idev = ipv6_find_idev(dev)) == NULL) | 1733 | idev = ipv6_find_idev(dev); |
1734 | if (!idev) | ||
1739 | return NULL; | 1735 | return NULL; |
1740 | 1736 | ||
1741 | /* Add default multicast route */ | 1737 | /* Add default multicast route */ |
@@ -1968,7 +1964,7 @@ ok: | |||
1968 | #ifdef CONFIG_IPV6_PRIVACY | 1964 | #ifdef CONFIG_IPV6_PRIVACY |
1969 | read_lock_bh(&in6_dev->lock); | 1965 | read_lock_bh(&in6_dev->lock); |
1970 | /* update all temporary addresses in the list */ | 1966 | /* update all temporary addresses in the list */ |
1971 | for (ift=in6_dev->tempaddr_list; ift; ift=ift->tmp_next) { | 1967 | list_for_each_entry(ift, &in6_dev->tempaddr_list, tmp_list) { |
1972 | /* | 1968 | /* |
1973 | * When adjusting the lifetimes of an existing | 1969 | * When adjusting the lifetimes of an existing |
1974 | * temporary address, only lower the lifetimes. | 1970 | * temporary address, only lower the lifetimes. |
@@ -2171,7 +2167,7 @@ static int inet6_addr_del(struct net *net, int ifindex, struct in6_addr *pfx, | |||
2171 | return -ENXIO; | 2167 | return -ENXIO; |
2172 | 2168 | ||
2173 | read_lock_bh(&idev->lock); | 2169 | read_lock_bh(&idev->lock); |
2174 | for (ifp = idev->addr_list; ifp; ifp=ifp->if_next) { | 2170 | list_for_each_entry(ifp, &idev->addr_list, if_list) { |
2175 | if (ifp->prefix_len == plen && | 2171 | if (ifp->prefix_len == plen && |
2176 | ipv6_addr_equal(pfx, &ifp->addr)) { | 2172 | ipv6_addr_equal(pfx, &ifp->addr)) { |
2177 | in6_ifa_hold(ifp); | 2173 | in6_ifa_hold(ifp); |
@@ -2182,7 +2178,7 @@ static int inet6_addr_del(struct net *net, int ifindex, struct in6_addr *pfx, | |||
2182 | /* If the last address is deleted administratively, | 2178 | /* If the last address is deleted administratively, |
2183 | disable IPv6 on this interface. | 2179 | disable IPv6 on this interface. |
2184 | */ | 2180 | */ |
2185 | if (idev->addr_list == NULL) | 2181 | if (list_empty(&idev->addr_list)) |
2186 | addrconf_ifdown(idev->dev, 1); | 2182 | addrconf_ifdown(idev->dev, 1); |
2187 | return 0; | 2183 | return 0; |
2188 | } | 2184 | } |
@@ -2443,7 +2439,8 @@ static void addrconf_ip6_tnl_config(struct net_device *dev) | |||
2443 | 2439 | ||
2444 | ASSERT_RTNL(); | 2440 | ASSERT_RTNL(); |
2445 | 2441 | ||
2446 | if ((idev = addrconf_add_dev(dev)) == NULL) { | 2442 | idev = addrconf_add_dev(dev); |
2443 | if (!idev) { | ||
2447 | printk(KERN_DEBUG "init ip6-ip6: add_dev failed\n"); | 2444 | printk(KERN_DEBUG "init ip6-ip6: add_dev failed\n"); |
2448 | return; | 2445 | return; |
2449 | } | 2446 | } |
@@ -2458,7 +2455,7 @@ static int addrconf_notify(struct notifier_block *this, unsigned long event, | |||
2458 | int run_pending = 0; | 2455 | int run_pending = 0; |
2459 | int err; | 2456 | int err; |
2460 | 2457 | ||
2461 | switch(event) { | 2458 | switch (event) { |
2462 | case NETDEV_REGISTER: | 2459 | case NETDEV_REGISTER: |
2463 | if (!idev && dev->mtu >= IPV6_MIN_MTU) { | 2460 | if (!idev && dev->mtu >= IPV6_MIN_MTU) { |
2464 | idev = ipv6_add_dev(dev); | 2461 | idev = ipv6_add_dev(dev); |
@@ -2466,6 +2463,7 @@ static int addrconf_notify(struct notifier_block *this, unsigned long event, | |||
2466 | return notifier_from_errno(-ENOMEM); | 2463 | return notifier_from_errno(-ENOMEM); |
2467 | } | 2464 | } |
2468 | break; | 2465 | break; |
2466 | |||
2469 | case NETDEV_UP: | 2467 | case NETDEV_UP: |
2470 | case NETDEV_CHANGE: | 2468 | case NETDEV_CHANGE: |
2471 | if (dev->flags & IFF_SLAVE) | 2469 | if (dev->flags & IFF_SLAVE) |
@@ -2495,10 +2493,9 @@ static int addrconf_notify(struct notifier_block *this, unsigned long event, | |||
2495 | } | 2493 | } |
2496 | 2494 | ||
2497 | if (idev) { | 2495 | if (idev) { |
2498 | if (idev->if_flags & IF_READY) { | 2496 | if (idev->if_flags & IF_READY) |
2499 | /* device is already configured. */ | 2497 | /* device is already configured. */ |
2500 | break; | 2498 | break; |
2501 | } | ||
2502 | idev->if_flags |= IF_READY; | 2499 | idev->if_flags |= IF_READY; |
2503 | } | 2500 | } |
2504 | 2501 | ||
@@ -2510,7 +2507,7 @@ static int addrconf_notify(struct notifier_block *this, unsigned long event, | |||
2510 | run_pending = 1; | 2507 | run_pending = 1; |
2511 | } | 2508 | } |
2512 | 2509 | ||
2513 | switch(dev->type) { | 2510 | switch (dev->type) { |
2514 | #if defined(CONFIG_IPV6_SIT) || defined(CONFIG_IPV6_SIT_MODULE) | 2511 | #if defined(CONFIG_IPV6_SIT) || defined(CONFIG_IPV6_SIT_MODULE) |
2515 | case ARPHRD_SIT: | 2512 | case ARPHRD_SIT: |
2516 | addrconf_sit_config(dev); | 2513 | addrconf_sit_config(dev); |
@@ -2527,25 +2524,30 @@ static int addrconf_notify(struct notifier_block *this, unsigned long event, | |||
2527 | addrconf_dev_config(dev); | 2524 | addrconf_dev_config(dev); |
2528 | break; | 2525 | break; |
2529 | } | 2526 | } |
2527 | |||
2530 | if (idev) { | 2528 | if (idev) { |
2531 | if (run_pending) | 2529 | if (run_pending) |
2532 | addrconf_dad_run(idev); | 2530 | addrconf_dad_run(idev); |
2533 | 2531 | ||
2534 | /* If the MTU changed during the interface down, when the | 2532 | /* |
2535 | interface up, the changed MTU must be reflected in the | 2533 | * If the MTU changed during the interface down, |
2536 | idev as well as routers. | 2534 | * when the interface up, the changed MTU must be |
2535 | * reflected in the idev as well as routers. | ||
2537 | */ | 2536 | */ |
2538 | if (idev->cnf.mtu6 != dev->mtu && dev->mtu >= IPV6_MIN_MTU) { | 2537 | if (idev->cnf.mtu6 != dev->mtu && |
2538 | dev->mtu >= IPV6_MIN_MTU) { | ||
2539 | rt6_mtu_change(dev, dev->mtu); | 2539 | rt6_mtu_change(dev, dev->mtu); |
2540 | idev->cnf.mtu6 = dev->mtu; | 2540 | idev->cnf.mtu6 = dev->mtu; |
2541 | } | 2541 | } |
2542 | idev->tstamp = jiffies; | 2542 | idev->tstamp = jiffies; |
2543 | inet6_ifinfo_notify(RTM_NEWLINK, idev); | 2543 | inet6_ifinfo_notify(RTM_NEWLINK, idev); |
2544 | /* If the changed mtu during down is lower than IPV6_MIN_MTU | 2544 | |
2545 | stop IPv6 on this interface. | 2545 | /* |
2546 | * If the changed mtu during down is lower than | ||
2547 | * IPV6_MIN_MTU stop IPv6 on this interface. | ||
2546 | */ | 2548 | */ |
2547 | if (dev->mtu < IPV6_MIN_MTU) | 2549 | if (dev->mtu < IPV6_MIN_MTU) |
2548 | addrconf_ifdown(dev, event != NETDEV_DOWN); | 2550 | addrconf_ifdown(dev, 1); |
2549 | } | 2551 | } |
2550 | break; | 2552 | break; |
2551 | 2553 | ||
@@ -2562,7 +2564,10 @@ static int addrconf_notify(struct notifier_block *this, unsigned long event, | |||
2562 | break; | 2564 | break; |
2563 | } | 2565 | } |
2564 | 2566 | ||
2565 | /* MTU falled under IPV6_MIN_MTU. Stop IPv6 on this interface. */ | 2567 | /* |
2568 | * MTU falled under IPV6_MIN_MTU. | ||
2569 | * Stop IPv6 on this interface. | ||
2570 | */ | ||
2566 | 2571 | ||
2567 | case NETDEV_DOWN: | 2572 | case NETDEV_DOWN: |
2568 | case NETDEV_UNREGISTER: | 2573 | case NETDEV_UNREGISTER: |
@@ -2582,9 +2587,10 @@ static int addrconf_notify(struct notifier_block *this, unsigned long event, | |||
2582 | return notifier_from_errno(err); | 2587 | return notifier_from_errno(err); |
2583 | } | 2588 | } |
2584 | break; | 2589 | break; |
2585 | case NETDEV_BONDING_OLDTYPE: | 2590 | |
2586 | case NETDEV_BONDING_NEWTYPE: | 2591 | case NETDEV_PRE_TYPE_CHANGE: |
2587 | addrconf_bonding_change(dev, event); | 2592 | case NETDEV_POST_TYPE_CHANGE: |
2593 | addrconf_type_change(dev, event); | ||
2588 | break; | 2594 | break; |
2589 | } | 2595 | } |
2590 | 2596 | ||
@@ -2596,28 +2602,27 @@ static int addrconf_notify(struct notifier_block *this, unsigned long event, | |||
2596 | */ | 2602 | */ |
2597 | static struct notifier_block ipv6_dev_notf = { | 2603 | static struct notifier_block ipv6_dev_notf = { |
2598 | .notifier_call = addrconf_notify, | 2604 | .notifier_call = addrconf_notify, |
2599 | .priority = 0 | ||
2600 | }; | 2605 | }; |
2601 | 2606 | ||
2602 | static void addrconf_bonding_change(struct net_device *dev, unsigned long event) | 2607 | static void addrconf_type_change(struct net_device *dev, unsigned long event) |
2603 | { | 2608 | { |
2604 | struct inet6_dev *idev; | 2609 | struct inet6_dev *idev; |
2605 | ASSERT_RTNL(); | 2610 | ASSERT_RTNL(); |
2606 | 2611 | ||
2607 | idev = __in6_dev_get(dev); | 2612 | idev = __in6_dev_get(dev); |
2608 | 2613 | ||
2609 | if (event == NETDEV_BONDING_NEWTYPE) | 2614 | if (event == NETDEV_POST_TYPE_CHANGE) |
2610 | ipv6_mc_remap(idev); | 2615 | ipv6_mc_remap(idev); |
2611 | else if (event == NETDEV_BONDING_OLDTYPE) | 2616 | else if (event == NETDEV_PRE_TYPE_CHANGE) |
2612 | ipv6_mc_unmap(idev); | 2617 | ipv6_mc_unmap(idev); |
2613 | } | 2618 | } |
2614 | 2619 | ||
2615 | static int addrconf_ifdown(struct net_device *dev, int how) | 2620 | static int addrconf_ifdown(struct net_device *dev, int how) |
2616 | { | 2621 | { |
2617 | struct inet6_dev *idev; | ||
2618 | struct inet6_ifaddr *ifa, *keep_list, **bifa; | ||
2619 | struct net *net = dev_net(dev); | 2622 | struct net *net = dev_net(dev); |
2620 | int i; | 2623 | struct inet6_dev *idev; |
2624 | struct inet6_ifaddr *ifa; | ||
2625 | LIST_HEAD(keep_list); | ||
2621 | 2626 | ||
2622 | ASSERT_RTNL(); | 2627 | ASSERT_RTNL(); |
2623 | 2628 | ||
@@ -2628,8 +2633,9 @@ static int addrconf_ifdown(struct net_device *dev, int how) | |||
2628 | if (idev == NULL) | 2633 | if (idev == NULL) |
2629 | return -ENODEV; | 2634 | return -ENODEV; |
2630 | 2635 | ||
2631 | /* Step 1: remove reference to ipv6 device from parent device. | 2636 | /* |
2632 | Do not dev_put! | 2637 | * Step 1: remove reference to ipv6 device from parent device. |
2638 | * Do not dev_put! | ||
2633 | */ | 2639 | */ |
2634 | if (how) { | 2640 | if (how) { |
2635 | idev->dead = 1; | 2641 | idev->dead = 1; |
@@ -2642,40 +2648,21 @@ static int addrconf_ifdown(struct net_device *dev, int how) | |||
2642 | 2648 | ||
2643 | } | 2649 | } |
2644 | 2650 | ||
2645 | /* Step 2: clear hash table */ | ||
2646 | for (i=0; i<IN6_ADDR_HSIZE; i++) { | ||
2647 | bifa = &inet6_addr_lst[i]; | ||
2648 | |||
2649 | write_lock_bh(&addrconf_hash_lock); | ||
2650 | while ((ifa = *bifa) != NULL) { | ||
2651 | if (ifa->idev == idev && | ||
2652 | (how || !(ifa->flags&IFA_F_PERMANENT) || | ||
2653 | ipv6_addr_type(&ifa->addr) & IPV6_ADDR_LINKLOCAL)) { | ||
2654 | *bifa = ifa->lst_next; | ||
2655 | ifa->lst_next = NULL; | ||
2656 | __in6_ifa_put(ifa); | ||
2657 | continue; | ||
2658 | } | ||
2659 | bifa = &ifa->lst_next; | ||
2660 | } | ||
2661 | write_unlock_bh(&addrconf_hash_lock); | ||
2662 | } | ||
2663 | |||
2664 | write_lock_bh(&idev->lock); | 2651 | write_lock_bh(&idev->lock); |
2665 | 2652 | ||
2666 | /* Step 3: clear flags for stateless addrconf */ | 2653 | /* Step 2: clear flags for stateless addrconf */ |
2667 | if (!how) | 2654 | if (!how) |
2668 | idev->if_flags &= ~(IF_RS_SENT|IF_RA_RCVD|IF_READY); | 2655 | idev->if_flags &= ~(IF_RS_SENT|IF_RA_RCVD|IF_READY); |
2669 | 2656 | ||
2670 | /* Step 4: clear address list */ | ||
2671 | #ifdef CONFIG_IPV6_PRIVACY | 2657 | #ifdef CONFIG_IPV6_PRIVACY |
2672 | if (how && del_timer(&idev->regen_timer)) | 2658 | if (how && del_timer(&idev->regen_timer)) |
2673 | in6_dev_put(idev); | 2659 | in6_dev_put(idev); |
2674 | 2660 | ||
2675 | /* clear tempaddr list */ | 2661 | /* Step 3: clear tempaddr list */ |
2676 | while ((ifa = idev->tempaddr_list) != NULL) { | 2662 | while (!list_empty(&idev->tempaddr_list)) { |
2677 | idev->tempaddr_list = ifa->tmp_next; | 2663 | ifa = list_first_entry(&idev->tempaddr_list, |
2678 | ifa->tmp_next = NULL; | 2664 | struct inet6_ifaddr, tmp_list); |
2665 | list_del(&ifa->tmp_list); | ||
2679 | ifa->dead = 1; | 2666 | ifa->dead = 1; |
2680 | write_unlock_bh(&idev->lock); | 2667 | write_unlock_bh(&idev->lock); |
2681 | spin_lock_bh(&ifa->lock); | 2668 | spin_lock_bh(&ifa->lock); |
@@ -2689,23 +2676,18 @@ static int addrconf_ifdown(struct net_device *dev, int how) | |||
2689 | write_lock_bh(&idev->lock); | 2676 | write_lock_bh(&idev->lock); |
2690 | } | 2677 | } |
2691 | #endif | 2678 | #endif |
2692 | keep_list = NULL; | ||
2693 | bifa = &keep_list; | ||
2694 | while ((ifa = idev->addr_list) != NULL) { | ||
2695 | idev->addr_list = ifa->if_next; | ||
2696 | ifa->if_next = NULL; | ||
2697 | 2679 | ||
2680 | while (!list_empty(&idev->addr_list)) { | ||
2681 | ifa = list_first_entry(&idev->addr_list, | ||
2682 | struct inet6_ifaddr, if_list); | ||
2698 | addrconf_del_timer(ifa); | 2683 | addrconf_del_timer(ifa); |
2699 | 2684 | ||
2700 | /* If just doing link down, and address is permanent | 2685 | /* If just doing link down, and address is permanent |
2701 | and not link-local, then retain it. */ | 2686 | and not link-local, then retain it. */ |
2702 | if (how == 0 && | 2687 | if (!how && |
2703 | (ifa->flags&IFA_F_PERMANENT) && | 2688 | (ifa->flags&IFA_F_PERMANENT) && |
2704 | !(ipv6_addr_type(&ifa->addr) & IPV6_ADDR_LINKLOCAL)) { | 2689 | !(ipv6_addr_type(&ifa->addr) & IPV6_ADDR_LINKLOCAL)) { |
2705 | 2690 | list_move_tail(&ifa->if_list, &keep_list); | |
2706 | /* Move to holding list */ | ||
2707 | *bifa = ifa; | ||
2708 | bifa = &ifa->if_next; | ||
2709 | 2691 | ||
2710 | /* If not doing DAD on this address, just keep it. */ | 2692 | /* If not doing DAD on this address, just keep it. */ |
2711 | if ((dev->flags&(IFF_NOARP|IFF_LOOPBACK)) || | 2693 | if ((dev->flags&(IFF_NOARP|IFF_LOOPBACK)) || |
@@ -2720,24 +2702,32 @@ static int addrconf_ifdown(struct net_device *dev, int how) | |||
2720 | /* Flag it for later restoration when link comes up */ | 2702 | /* Flag it for later restoration when link comes up */ |
2721 | ifa->flags |= IFA_F_TENTATIVE; | 2703 | ifa->flags |= IFA_F_TENTATIVE; |
2722 | in6_ifa_hold(ifa); | 2704 | in6_ifa_hold(ifa); |
2705 | write_unlock_bh(&idev->lock); | ||
2723 | } else { | 2706 | } else { |
2707 | list_del(&ifa->if_list); | ||
2724 | ifa->dead = 1; | 2708 | ifa->dead = 1; |
2709 | write_unlock_bh(&idev->lock); | ||
2710 | |||
2711 | /* clear hash table */ | ||
2712 | spin_lock_bh(&addrconf_hash_lock); | ||
2713 | hlist_del_init_rcu(&ifa->addr_lst); | ||
2714 | spin_unlock_bh(&addrconf_hash_lock); | ||
2725 | } | 2715 | } |
2726 | write_unlock_bh(&idev->lock); | ||
2727 | 2716 | ||
2728 | __ipv6_ifa_notify(RTM_DELADDR, ifa); | 2717 | __ipv6_ifa_notify(RTM_DELADDR, ifa); |
2729 | atomic_notifier_call_chain(&inet6addr_chain, NETDEV_DOWN, ifa); | 2718 | if (ifa->dead) |
2719 | atomic_notifier_call_chain(&inet6addr_chain, | ||
2720 | NETDEV_DOWN, ifa); | ||
2730 | in6_ifa_put(ifa); | 2721 | in6_ifa_put(ifa); |
2731 | 2722 | ||
2732 | write_lock_bh(&idev->lock); | 2723 | write_lock_bh(&idev->lock); |
2733 | } | 2724 | } |
2734 | 2725 | ||
2735 | idev->addr_list = keep_list; | 2726 | list_splice(&keep_list, &idev->addr_list); |
2736 | 2727 | ||
2737 | write_unlock_bh(&idev->lock); | 2728 | write_unlock_bh(&idev->lock); |
2738 | 2729 | ||
2739 | /* Step 5: Discard multicast list */ | 2730 | /* Step 5: Discard multicast list */ |
2740 | |||
2741 | if (how) | 2731 | if (how) |
2742 | ipv6_mc_destroy_dev(idev); | 2732 | ipv6_mc_destroy_dev(idev); |
2743 | else | 2733 | else |
@@ -2745,8 +2735,7 @@ static int addrconf_ifdown(struct net_device *dev, int how) | |||
2745 | 2735 | ||
2746 | idev->tstamp = jiffies; | 2736 | idev->tstamp = jiffies; |
2747 | 2737 | ||
2748 | /* Shot the device (if unregistered) */ | 2738 | /* Last: Shot the device (if unregistered) */ |
2749 | |||
2750 | if (how) { | 2739 | if (how) { |
2751 | addrconf_sysctl_unregister(idev); | 2740 | addrconf_sysctl_unregister(idev); |
2752 | neigh_parms_release(&nd_tbl, idev->nd_parms); | 2741 | neigh_parms_release(&nd_tbl, idev->nd_parms); |
@@ -2857,7 +2846,7 @@ static void addrconf_dad_start(struct inet6_ifaddr *ifp, u32 flags) | |||
2857 | * Optimistic nodes can start receiving | 2846 | * Optimistic nodes can start receiving |
2858 | * Frames right away | 2847 | * Frames right away |
2859 | */ | 2848 | */ |
2860 | if(ifp->flags & IFA_F_OPTIMISTIC) | 2849 | if (ifp->flags & IFA_F_OPTIMISTIC) |
2861 | ip6_ins_rt(ifp->rt); | 2850 | ip6_ins_rt(ifp->rt); |
2862 | 2851 | ||
2863 | addrconf_dad_kick(ifp); | 2852 | addrconf_dad_kick(ifp); |
@@ -2907,7 +2896,7 @@ out: | |||
2907 | 2896 | ||
2908 | static void addrconf_dad_completed(struct inet6_ifaddr *ifp) | 2897 | static void addrconf_dad_completed(struct inet6_ifaddr *ifp) |
2909 | { | 2898 | { |
2910 | struct net_device * dev = ifp->idev->dev; | 2899 | struct net_device *dev = ifp->idev->dev; |
2911 | 2900 | ||
2912 | /* | 2901 | /* |
2913 | * Configure the address for reception. Now it is valid. | 2902 | * Configure the address for reception. Now it is valid. |
@@ -2938,11 +2927,12 @@ static void addrconf_dad_completed(struct inet6_ifaddr *ifp) | |||
2938 | } | 2927 | } |
2939 | } | 2928 | } |
2940 | 2929 | ||
2941 | static void addrconf_dad_run(struct inet6_dev *idev) { | 2930 | static void addrconf_dad_run(struct inet6_dev *idev) |
2931 | { | ||
2942 | struct inet6_ifaddr *ifp; | 2932 | struct inet6_ifaddr *ifp; |
2943 | 2933 | ||
2944 | read_lock_bh(&idev->lock); | 2934 | read_lock_bh(&idev->lock); |
2945 | for (ifp = idev->addr_list; ifp; ifp = ifp->if_next) { | 2935 | list_for_each_entry(ifp, &idev->addr_list, if_list) { |
2946 | spin_lock(&ifp->lock); | 2936 | spin_lock(&ifp->lock); |
2947 | if (!(ifp->flags & IFA_F_TENTATIVE)) { | 2937 | if (!(ifp->flags & IFA_F_TENTATIVE)) { |
2948 | spin_unlock(&ifp->lock); | 2938 | spin_unlock(&ifp->lock); |
@@ -2967,36 +2957,35 @@ static struct inet6_ifaddr *if6_get_first(struct seq_file *seq) | |||
2967 | struct net *net = seq_file_net(seq); | 2957 | struct net *net = seq_file_net(seq); |
2968 | 2958 | ||
2969 | for (state->bucket = 0; state->bucket < IN6_ADDR_HSIZE; ++state->bucket) { | 2959 | for (state->bucket = 0; state->bucket < IN6_ADDR_HSIZE; ++state->bucket) { |
2970 | ifa = inet6_addr_lst[state->bucket]; | 2960 | struct hlist_node *n; |
2971 | 2961 | hlist_for_each_entry_rcu(ifa, n, &inet6_addr_lst[state->bucket], | |
2972 | while (ifa && !net_eq(dev_net(ifa->idev->dev), net)) | 2962 | addr_lst) |
2973 | ifa = ifa->lst_next; | 2963 | if (net_eq(dev_net(ifa->idev->dev), net)) |
2974 | if (ifa) | 2964 | return ifa; |
2975 | break; | ||
2976 | } | 2965 | } |
2977 | return ifa; | 2966 | return NULL; |
2978 | } | 2967 | } |
2979 | 2968 | ||
2980 | static struct inet6_ifaddr *if6_get_next(struct seq_file *seq, struct inet6_ifaddr *ifa) | 2969 | static struct inet6_ifaddr *if6_get_next(struct seq_file *seq, |
2970 | struct inet6_ifaddr *ifa) | ||
2981 | { | 2971 | { |
2982 | struct if6_iter_state *state = seq->private; | 2972 | struct if6_iter_state *state = seq->private; |
2983 | struct net *net = seq_file_net(seq); | 2973 | struct net *net = seq_file_net(seq); |
2974 | struct hlist_node *n = &ifa->addr_lst; | ||
2984 | 2975 | ||
2985 | ifa = ifa->lst_next; | 2976 | hlist_for_each_entry_continue_rcu(ifa, n, addr_lst) |
2986 | try_again: | 2977 | if (net_eq(dev_net(ifa->idev->dev), net)) |
2987 | if (ifa) { | 2978 | return ifa; |
2988 | if (!net_eq(dev_net(ifa->idev->dev), net)) { | ||
2989 | ifa = ifa->lst_next; | ||
2990 | goto try_again; | ||
2991 | } | ||
2992 | } | ||
2993 | 2979 | ||
2994 | if (!ifa && ++state->bucket < IN6_ADDR_HSIZE) { | 2980 | while (++state->bucket < IN6_ADDR_HSIZE) { |
2995 | ifa = inet6_addr_lst[state->bucket]; | 2981 | hlist_for_each_entry(ifa, n, |
2996 | goto try_again; | 2982 | &inet6_addr_lst[state->bucket], addr_lst) { |
2983 | if (net_eq(dev_net(ifa->idev->dev), net)) | ||
2984 | return ifa; | ||
2985 | } | ||
2997 | } | 2986 | } |
2998 | 2987 | ||
2999 | return ifa; | 2988 | return NULL; |
3000 | } | 2989 | } |
3001 | 2990 | ||
3002 | static struct inet6_ifaddr *if6_get_idx(struct seq_file *seq, loff_t pos) | 2991 | static struct inet6_ifaddr *if6_get_idx(struct seq_file *seq, loff_t pos) |
@@ -3004,15 +2993,15 @@ static struct inet6_ifaddr *if6_get_idx(struct seq_file *seq, loff_t pos) | |||
3004 | struct inet6_ifaddr *ifa = if6_get_first(seq); | 2993 | struct inet6_ifaddr *ifa = if6_get_first(seq); |
3005 | 2994 | ||
3006 | if (ifa) | 2995 | if (ifa) |
3007 | while(pos && (ifa = if6_get_next(seq, ifa)) != NULL) | 2996 | while (pos && (ifa = if6_get_next(seq, ifa)) != NULL) |
3008 | --pos; | 2997 | --pos; |
3009 | return pos ? NULL : ifa; | 2998 | return pos ? NULL : ifa; |
3010 | } | 2999 | } |
3011 | 3000 | ||
3012 | static void *if6_seq_start(struct seq_file *seq, loff_t *pos) | 3001 | static void *if6_seq_start(struct seq_file *seq, loff_t *pos) |
3013 | __acquires(addrconf_hash_lock) | 3002 | __acquires(rcu) |
3014 | { | 3003 | { |
3015 | read_lock_bh(&addrconf_hash_lock); | 3004 | rcu_read_lock_bh(); |
3016 | return if6_get_idx(seq, *pos); | 3005 | return if6_get_idx(seq, *pos); |
3017 | } | 3006 | } |
3018 | 3007 | ||
@@ -3026,9 +3015,9 @@ static void *if6_seq_next(struct seq_file *seq, void *v, loff_t *pos) | |||
3026 | } | 3015 | } |
3027 | 3016 | ||
3028 | static void if6_seq_stop(struct seq_file *seq, void *v) | 3017 | static void if6_seq_stop(struct seq_file *seq, void *v) |
3029 | __releases(addrconf_hash_lock) | 3018 | __releases(rcu) |
3030 | { | 3019 | { |
3031 | read_unlock_bh(&addrconf_hash_lock); | 3020 | rcu_read_unlock_bh(); |
3032 | } | 3021 | } |
3033 | 3022 | ||
3034 | static int if6_seq_show(struct seq_file *seq, void *v) | 3023 | static int if6_seq_show(struct seq_file *seq, void *v) |
@@ -3098,10 +3087,12 @@ void if6_proc_exit(void) | |||
3098 | int ipv6_chk_home_addr(struct net *net, struct in6_addr *addr) | 3087 | int ipv6_chk_home_addr(struct net *net, struct in6_addr *addr) |
3099 | { | 3088 | { |
3100 | int ret = 0; | 3089 | int ret = 0; |
3101 | struct inet6_ifaddr * ifp; | 3090 | struct inet6_ifaddr *ifp = NULL; |
3102 | u8 hash = ipv6_addr_hash(addr); | 3091 | struct hlist_node *n; |
3103 | read_lock_bh(&addrconf_hash_lock); | 3092 | unsigned int hash = ipv6_addr_hash(addr); |
3104 | for (ifp = inet6_addr_lst[hash]; ifp; ifp = ifp->lst_next) { | 3093 | |
3094 | rcu_read_lock_bh(); | ||
3095 | hlist_for_each_entry_rcu(ifp, n, &inet6_addr_lst[hash], addr_lst) { | ||
3105 | if (!net_eq(dev_net(ifp->idev->dev), net)) | 3096 | if (!net_eq(dev_net(ifp->idev->dev), net)) |
3106 | continue; | 3097 | continue; |
3107 | if (ipv6_addr_equal(&ifp->addr, addr) && | 3098 | if (ipv6_addr_equal(&ifp->addr, addr) && |
@@ -3110,7 +3101,7 @@ int ipv6_chk_home_addr(struct net *net, struct in6_addr *addr) | |||
3110 | break; | 3101 | break; |
3111 | } | 3102 | } |
3112 | } | 3103 | } |
3113 | read_unlock_bh(&addrconf_hash_lock); | 3104 | rcu_read_unlock_bh(); |
3114 | return ret; | 3105 | return ret; |
3115 | } | 3106 | } |
3116 | #endif | 3107 | #endif |
@@ -3121,43 +3112,35 @@ int ipv6_chk_home_addr(struct net *net, struct in6_addr *addr) | |||
3121 | 3112 | ||
3122 | static void addrconf_verify(unsigned long foo) | 3113 | static void addrconf_verify(unsigned long foo) |
3123 | { | 3114 | { |
3115 | unsigned long now, next, next_sec, next_sched; | ||
3124 | struct inet6_ifaddr *ifp; | 3116 | struct inet6_ifaddr *ifp; |
3125 | unsigned long now, next; | 3117 | struct hlist_node *node; |
3126 | int i; | 3118 | int i; |
3127 | 3119 | ||
3128 | spin_lock_bh(&addrconf_verify_lock); | 3120 | rcu_read_lock_bh(); |
3121 | spin_lock(&addrconf_verify_lock); | ||
3129 | now = jiffies; | 3122 | now = jiffies; |
3130 | next = now + ADDR_CHECK_FREQUENCY; | 3123 | next = round_jiffies_up(now + ADDR_CHECK_FREQUENCY); |
3131 | 3124 | ||
3132 | del_timer(&addr_chk_timer); | 3125 | del_timer(&addr_chk_timer); |
3133 | 3126 | ||
3134 | for (i=0; i < IN6_ADDR_HSIZE; i++) { | 3127 | for (i = 0; i < IN6_ADDR_HSIZE; i++) { |
3135 | |||
3136 | restart: | 3128 | restart: |
3137 | read_lock(&addrconf_hash_lock); | 3129 | hlist_for_each_entry_rcu(ifp, node, |
3138 | for (ifp=inet6_addr_lst[i]; ifp; ifp=ifp->lst_next) { | 3130 | &inet6_addr_lst[i], addr_lst) { |
3139 | unsigned long age; | 3131 | unsigned long age; |
3140 | #ifdef CONFIG_IPV6_PRIVACY | ||
3141 | unsigned long regen_advance; | ||
3142 | #endif | ||
3143 | 3132 | ||
3144 | if (ifp->flags & IFA_F_PERMANENT) | 3133 | if (ifp->flags & IFA_F_PERMANENT) |
3145 | continue; | 3134 | continue; |
3146 | 3135 | ||
3147 | spin_lock(&ifp->lock); | 3136 | spin_lock(&ifp->lock); |
3148 | age = (now - ifp->tstamp) / HZ; | 3137 | /* We try to batch several events at once. */ |
3149 | 3138 | age = (now - ifp->tstamp + ADDRCONF_TIMER_FUZZ_MINUS) / HZ; | |
3150 | #ifdef CONFIG_IPV6_PRIVACY | ||
3151 | regen_advance = ifp->idev->cnf.regen_max_retry * | ||
3152 | ifp->idev->cnf.dad_transmits * | ||
3153 | ifp->idev->nd_parms->retrans_time / HZ; | ||
3154 | #endif | ||
3155 | 3139 | ||
3156 | if (ifp->valid_lft != INFINITY_LIFE_TIME && | 3140 | if (ifp->valid_lft != INFINITY_LIFE_TIME && |
3157 | age >= ifp->valid_lft) { | 3141 | age >= ifp->valid_lft) { |
3158 | spin_unlock(&ifp->lock); | 3142 | spin_unlock(&ifp->lock); |
3159 | in6_ifa_hold(ifp); | 3143 | in6_ifa_hold(ifp); |
3160 | read_unlock(&addrconf_hash_lock); | ||
3161 | ipv6_del_addr(ifp); | 3144 | ipv6_del_addr(ifp); |
3162 | goto restart; | 3145 | goto restart; |
3163 | } else if (ifp->prefered_lft == INFINITY_LIFE_TIME) { | 3146 | } else if (ifp->prefered_lft == INFINITY_LIFE_TIME) { |
@@ -3179,7 +3162,6 @@ restart: | |||
3179 | 3162 | ||
3180 | if (deprecate) { | 3163 | if (deprecate) { |
3181 | in6_ifa_hold(ifp); | 3164 | in6_ifa_hold(ifp); |
3182 | read_unlock(&addrconf_hash_lock); | ||
3183 | 3165 | ||
3184 | ipv6_ifa_notify(0, ifp); | 3166 | ipv6_ifa_notify(0, ifp); |
3185 | in6_ifa_put(ifp); | 3167 | in6_ifa_put(ifp); |
@@ -3188,6 +3170,10 @@ restart: | |||
3188 | #ifdef CONFIG_IPV6_PRIVACY | 3170 | #ifdef CONFIG_IPV6_PRIVACY |
3189 | } else if ((ifp->flags&IFA_F_TEMPORARY) && | 3171 | } else if ((ifp->flags&IFA_F_TEMPORARY) && |
3190 | !(ifp->flags&IFA_F_TENTATIVE)) { | 3172 | !(ifp->flags&IFA_F_TENTATIVE)) { |
3173 | unsigned long regen_advance = ifp->idev->cnf.regen_max_retry * | ||
3174 | ifp->idev->cnf.dad_transmits * | ||
3175 | ifp->idev->nd_parms->retrans_time / HZ; | ||
3176 | |||
3191 | if (age >= ifp->prefered_lft - regen_advance) { | 3177 | if (age >= ifp->prefered_lft - regen_advance) { |
3192 | struct inet6_ifaddr *ifpub = ifp->ifpub; | 3178 | struct inet6_ifaddr *ifpub = ifp->ifpub; |
3193 | if (time_before(ifp->tstamp + ifp->prefered_lft * HZ, next)) | 3179 | if (time_before(ifp->tstamp + ifp->prefered_lft * HZ, next)) |
@@ -3197,7 +3183,7 @@ restart: | |||
3197 | in6_ifa_hold(ifp); | 3183 | in6_ifa_hold(ifp); |
3198 | in6_ifa_hold(ifpub); | 3184 | in6_ifa_hold(ifpub); |
3199 | spin_unlock(&ifp->lock); | 3185 | spin_unlock(&ifp->lock); |
3200 | read_unlock(&addrconf_hash_lock); | 3186 | |
3201 | spin_lock(&ifpub->lock); | 3187 | spin_lock(&ifpub->lock); |
3202 | ifpub->regen_count = 0; | 3188 | ifpub->regen_count = 0; |
3203 | spin_unlock(&ifpub->lock); | 3189 | spin_unlock(&ifpub->lock); |
@@ -3217,12 +3203,26 @@ restart: | |||
3217 | spin_unlock(&ifp->lock); | 3203 | spin_unlock(&ifp->lock); |
3218 | } | 3204 | } |
3219 | } | 3205 | } |
3220 | read_unlock(&addrconf_hash_lock); | ||
3221 | } | 3206 | } |
3222 | 3207 | ||
3223 | addr_chk_timer.expires = time_before(next, jiffies + HZ) ? jiffies + HZ : next; | 3208 | next_sec = round_jiffies_up(next); |
3209 | next_sched = next; | ||
3210 | |||
3211 | /* If rounded timeout is accurate enough, accept it. */ | ||
3212 | if (time_before(next_sec, next + ADDRCONF_TIMER_FUZZ)) | ||
3213 | next_sched = next_sec; | ||
3214 | |||
3215 | /* And minimum interval is ADDRCONF_TIMER_FUZZ_MAX. */ | ||
3216 | if (time_before(next_sched, jiffies + ADDRCONF_TIMER_FUZZ_MAX)) | ||
3217 | next_sched = jiffies + ADDRCONF_TIMER_FUZZ_MAX; | ||
3218 | |||
3219 | ADBG((KERN_DEBUG "now = %lu, schedule = %lu, rounded schedule = %lu => %lu\n", | ||
3220 | now, next, next_sec, next_sched)); | ||
3221 | |||
3222 | addr_chk_timer.expires = next_sched; | ||
3224 | add_timer(&addr_chk_timer); | 3223 | add_timer(&addr_chk_timer); |
3225 | spin_unlock_bh(&addrconf_verify_lock); | 3224 | spin_unlock(&addrconf_verify_lock); |
3225 | rcu_read_unlock_bh(); | ||
3226 | } | 3226 | } |
3227 | 3227 | ||
3228 | static struct in6_addr *extract_addr(struct nlattr *addr, struct nlattr *local) | 3228 | static struct in6_addr *extract_addr(struct nlattr *addr, struct nlattr *local) |
@@ -3512,8 +3512,7 @@ static int inet6_fill_ifacaddr(struct sk_buff *skb, struct ifacaddr6 *ifaca, | |||
3512 | return nlmsg_end(skb, nlh); | 3512 | return nlmsg_end(skb, nlh); |
3513 | } | 3513 | } |
3514 | 3514 | ||
3515 | enum addr_type_t | 3515 | enum addr_type_t { |
3516 | { | ||
3517 | UNICAST_ADDR, | 3516 | UNICAST_ADDR, |
3518 | MULTICAST_ADDR, | 3517 | MULTICAST_ADDR, |
3519 | ANYCAST_ADDR, | 3518 | ANYCAST_ADDR, |
@@ -3524,7 +3523,6 @@ static int in6_dump_addrs(struct inet6_dev *idev, struct sk_buff *skb, | |||
3524 | struct netlink_callback *cb, enum addr_type_t type, | 3523 | struct netlink_callback *cb, enum addr_type_t type, |
3525 | int s_ip_idx, int *p_ip_idx) | 3524 | int s_ip_idx, int *p_ip_idx) |
3526 | { | 3525 | { |
3527 | struct inet6_ifaddr *ifa; | ||
3528 | struct ifmcaddr6 *ifmca; | 3526 | struct ifmcaddr6 *ifmca; |
3529 | struct ifacaddr6 *ifaca; | 3527 | struct ifacaddr6 *ifaca; |
3530 | int err = 1; | 3528 | int err = 1; |
@@ -3532,11 +3530,12 @@ static int in6_dump_addrs(struct inet6_dev *idev, struct sk_buff *skb, | |||
3532 | 3530 | ||
3533 | read_lock_bh(&idev->lock); | 3531 | read_lock_bh(&idev->lock); |
3534 | switch (type) { | 3532 | switch (type) { |
3535 | case UNICAST_ADDR: | 3533 | case UNICAST_ADDR: { |
3534 | struct inet6_ifaddr *ifa; | ||
3535 | |||
3536 | /* unicast address incl. temp addr */ | 3536 | /* unicast address incl. temp addr */ |
3537 | for (ifa = idev->addr_list; ifa; | 3537 | list_for_each_entry(ifa, &idev->addr_list, if_list) { |
3538 | ifa = ifa->if_next, ip_idx++) { | 3538 | if (++ip_idx < s_ip_idx) |
3539 | if (ip_idx < s_ip_idx) | ||
3540 | continue; | 3539 | continue; |
3541 | err = inet6_fill_ifaddr(skb, ifa, | 3540 | err = inet6_fill_ifaddr(skb, ifa, |
3542 | NETLINK_CB(cb->skb).pid, | 3541 | NETLINK_CB(cb->skb).pid, |
@@ -3547,6 +3546,7 @@ static int in6_dump_addrs(struct inet6_dev *idev, struct sk_buff *skb, | |||
3547 | break; | 3546 | break; |
3548 | } | 3547 | } |
3549 | break; | 3548 | break; |
3549 | } | ||
3550 | case MULTICAST_ADDR: | 3550 | case MULTICAST_ADDR: |
3551 | /* multicast address */ | 3551 | /* multicast address */ |
3552 | for (ifmca = idev->mc_list; ifmca; | 3552 | for (ifmca = idev->mc_list; ifmca; |
@@ -3608,10 +3608,11 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb, | |||
3608 | hlist_for_each_entry_rcu(dev, node, head, index_hlist) { | 3608 | hlist_for_each_entry_rcu(dev, node, head, index_hlist) { |
3609 | if (idx < s_idx) | 3609 | if (idx < s_idx) |
3610 | goto cont; | 3610 | goto cont; |
3611 | if (idx > s_idx) | 3611 | if (h > s_h || idx > s_idx) |
3612 | s_ip_idx = 0; | 3612 | s_ip_idx = 0; |
3613 | ip_idx = 0; | 3613 | ip_idx = 0; |
3614 | if ((idev = __in6_dev_get(dev)) == NULL) | 3614 | idev = __in6_dev_get(dev); |
3615 | if (!idev) | ||
3615 | goto cont; | 3616 | goto cont; |
3616 | 3617 | ||
3617 | if (in6_dump_addrs(idev, skb, cb, type, | 3618 | if (in6_dump_addrs(idev, skb, cb, type, |
@@ -3678,12 +3679,14 @@ static int inet6_rtm_getaddr(struct sk_buff *in_skb, struct nlmsghdr* nlh, | |||
3678 | if (ifm->ifa_index) | 3679 | if (ifm->ifa_index) |
3679 | dev = __dev_get_by_index(net, ifm->ifa_index); | 3680 | dev = __dev_get_by_index(net, ifm->ifa_index); |
3680 | 3681 | ||
3681 | if ((ifa = ipv6_get_ifaddr(net, addr, dev, 1)) == NULL) { | 3682 | ifa = ipv6_get_ifaddr(net, addr, dev, 1); |
3683 | if (!ifa) { | ||
3682 | err = -EADDRNOTAVAIL; | 3684 | err = -EADDRNOTAVAIL; |
3683 | goto errout; | 3685 | goto errout; |
3684 | } | 3686 | } |
3685 | 3687 | ||
3686 | if ((skb = nlmsg_new(inet6_ifaddr_msgsize(), GFP_KERNEL)) == NULL) { | 3688 | skb = nlmsg_new(inet6_ifaddr_msgsize(), GFP_KERNEL); |
3689 | if (!skb) { | ||
3687 | err = -ENOBUFS; | 3690 | err = -ENOBUFS; |
3688 | goto errout_ifa; | 3691 | goto errout_ifa; |
3689 | } | 3692 | } |
@@ -3808,7 +3811,7 @@ static inline void __snmp6_fill_stats(u64 *stats, void __percpu **mib, | |||
3808 | static void snmp6_fill_stats(u64 *stats, struct inet6_dev *idev, int attrtype, | 3811 | static void snmp6_fill_stats(u64 *stats, struct inet6_dev *idev, int attrtype, |
3809 | int bytes) | 3812 | int bytes) |
3810 | { | 3813 | { |
3811 | switch(attrtype) { | 3814 | switch (attrtype) { |
3812 | case IFLA_INET6_STATS: | 3815 | case IFLA_INET6_STATS: |
3813 | __snmp6_fill_stats(stats, (void __percpu **)idev->stats.ipv6, IPSTATS_MIB_MAX, bytes); | 3816 | __snmp6_fill_stats(stats, (void __percpu **)idev->stats.ipv6, IPSTATS_MIB_MAX, bytes); |
3814 | break; | 3817 | break; |
@@ -4044,7 +4047,8 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp) | |||
4044 | addrconf_leave_anycast(ifp); | 4047 | addrconf_leave_anycast(ifp); |
4045 | addrconf_leave_solict(ifp->idev, &ifp->addr); | 4048 | addrconf_leave_solict(ifp->idev, &ifp->addr); |
4046 | dst_hold(&ifp->rt->u.dst); | 4049 | dst_hold(&ifp->rt->u.dst); |
4047 | if (ip6_del_rt(ifp->rt)) | 4050 | |
4051 | if (ifp->dead && ip6_del_rt(ifp->rt)) | ||
4048 | dst_free(&ifp->rt->u.dst); | 4052 | dst_free(&ifp->rt->u.dst); |
4049 | break; | 4053 | break; |
4050 | } | 4054 | } |
@@ -4160,211 +4164,211 @@ static struct addrconf_sysctl_table | |||
4160 | .sysctl_header = NULL, | 4164 | .sysctl_header = NULL, |
4161 | .addrconf_vars = { | 4165 | .addrconf_vars = { |
4162 | { | 4166 | { |
4163 | .procname = "forwarding", | 4167 | .procname = "forwarding", |
4164 | .data = &ipv6_devconf.forwarding, | 4168 | .data = &ipv6_devconf.forwarding, |
4165 | .maxlen = sizeof(int), | 4169 | .maxlen = sizeof(int), |
4166 | .mode = 0644, | 4170 | .mode = 0644, |
4167 | .proc_handler = addrconf_sysctl_forward, | 4171 | .proc_handler = addrconf_sysctl_forward, |
4168 | }, | 4172 | }, |
4169 | { | 4173 | { |
4170 | .procname = "hop_limit", | 4174 | .procname = "hop_limit", |
4171 | .data = &ipv6_devconf.hop_limit, | 4175 | .data = &ipv6_devconf.hop_limit, |
4172 | .maxlen = sizeof(int), | 4176 | .maxlen = sizeof(int), |
4173 | .mode = 0644, | 4177 | .mode = 0644, |
4174 | .proc_handler = proc_dointvec, | 4178 | .proc_handler = proc_dointvec, |
4175 | }, | 4179 | }, |
4176 | { | 4180 | { |
4177 | .procname = "mtu", | 4181 | .procname = "mtu", |
4178 | .data = &ipv6_devconf.mtu6, | 4182 | .data = &ipv6_devconf.mtu6, |
4179 | .maxlen = sizeof(int), | 4183 | .maxlen = sizeof(int), |
4180 | .mode = 0644, | 4184 | .mode = 0644, |
4181 | .proc_handler = proc_dointvec, | 4185 | .proc_handler = proc_dointvec, |
4182 | }, | 4186 | }, |
4183 | { | 4187 | { |
4184 | .procname = "accept_ra", | 4188 | .procname = "accept_ra", |
4185 | .data = &ipv6_devconf.accept_ra, | 4189 | .data = &ipv6_devconf.accept_ra, |
4186 | .maxlen = sizeof(int), | 4190 | .maxlen = sizeof(int), |
4187 | .mode = 0644, | 4191 | .mode = 0644, |
4188 | .proc_handler = proc_dointvec, | 4192 | .proc_handler = proc_dointvec, |
4189 | }, | 4193 | }, |
4190 | { | 4194 | { |
4191 | .procname = "accept_redirects", | 4195 | .procname = "accept_redirects", |
4192 | .data = &ipv6_devconf.accept_redirects, | 4196 | .data = &ipv6_devconf.accept_redirects, |
4193 | .maxlen = sizeof(int), | 4197 | .maxlen = sizeof(int), |
4194 | .mode = 0644, | 4198 | .mode = 0644, |
4195 | .proc_handler = proc_dointvec, | 4199 | .proc_handler = proc_dointvec, |
4196 | }, | 4200 | }, |
4197 | { | 4201 | { |
4198 | .procname = "autoconf", | 4202 | .procname = "autoconf", |
4199 | .data = &ipv6_devconf.autoconf, | 4203 | .data = &ipv6_devconf.autoconf, |
4200 | .maxlen = sizeof(int), | 4204 | .maxlen = sizeof(int), |
4201 | .mode = 0644, | 4205 | .mode = 0644, |
4202 | .proc_handler = proc_dointvec, | 4206 | .proc_handler = proc_dointvec, |
4203 | }, | 4207 | }, |
4204 | { | 4208 | { |
4205 | .procname = "dad_transmits", | 4209 | .procname = "dad_transmits", |
4206 | .data = &ipv6_devconf.dad_transmits, | 4210 | .data = &ipv6_devconf.dad_transmits, |
4207 | .maxlen = sizeof(int), | 4211 | .maxlen = sizeof(int), |
4208 | .mode = 0644, | 4212 | .mode = 0644, |
4209 | .proc_handler = proc_dointvec, | 4213 | .proc_handler = proc_dointvec, |
4210 | }, | 4214 | }, |
4211 | { | 4215 | { |
4212 | .procname = "router_solicitations", | 4216 | .procname = "router_solicitations", |
4213 | .data = &ipv6_devconf.rtr_solicits, | 4217 | .data = &ipv6_devconf.rtr_solicits, |
4214 | .maxlen = sizeof(int), | 4218 | .maxlen = sizeof(int), |
4215 | .mode = 0644, | 4219 | .mode = 0644, |
4216 | .proc_handler = proc_dointvec, | 4220 | .proc_handler = proc_dointvec, |
4217 | }, | 4221 | }, |
4218 | { | 4222 | { |
4219 | .procname = "router_solicitation_interval", | 4223 | .procname = "router_solicitation_interval", |
4220 | .data = &ipv6_devconf.rtr_solicit_interval, | 4224 | .data = &ipv6_devconf.rtr_solicit_interval, |
4221 | .maxlen = sizeof(int), | 4225 | .maxlen = sizeof(int), |
4222 | .mode = 0644, | 4226 | .mode = 0644, |
4223 | .proc_handler = proc_dointvec_jiffies, | 4227 | .proc_handler = proc_dointvec_jiffies, |
4224 | }, | 4228 | }, |
4225 | { | 4229 | { |
4226 | .procname = "router_solicitation_delay", | 4230 | .procname = "router_solicitation_delay", |
4227 | .data = &ipv6_devconf.rtr_solicit_delay, | 4231 | .data = &ipv6_devconf.rtr_solicit_delay, |
4228 | .maxlen = sizeof(int), | 4232 | .maxlen = sizeof(int), |
4229 | .mode = 0644, | 4233 | .mode = 0644, |
4230 | .proc_handler = proc_dointvec_jiffies, | 4234 | .proc_handler = proc_dointvec_jiffies, |
4231 | }, | 4235 | }, |
4232 | { | 4236 | { |
4233 | .procname = "force_mld_version", | 4237 | .procname = "force_mld_version", |
4234 | .data = &ipv6_devconf.force_mld_version, | 4238 | .data = &ipv6_devconf.force_mld_version, |
4235 | .maxlen = sizeof(int), | 4239 | .maxlen = sizeof(int), |
4236 | .mode = 0644, | 4240 | .mode = 0644, |
4237 | .proc_handler = proc_dointvec, | 4241 | .proc_handler = proc_dointvec, |
4238 | }, | 4242 | }, |
4239 | #ifdef CONFIG_IPV6_PRIVACY | 4243 | #ifdef CONFIG_IPV6_PRIVACY |
4240 | { | 4244 | { |
4241 | .procname = "use_tempaddr", | 4245 | .procname = "use_tempaddr", |
4242 | .data = &ipv6_devconf.use_tempaddr, | 4246 | .data = &ipv6_devconf.use_tempaddr, |
4243 | .maxlen = sizeof(int), | 4247 | .maxlen = sizeof(int), |
4244 | .mode = 0644, | 4248 | .mode = 0644, |
4245 | .proc_handler = proc_dointvec, | 4249 | .proc_handler = proc_dointvec, |
4246 | }, | 4250 | }, |
4247 | { | 4251 | { |
4248 | .procname = "temp_valid_lft", | 4252 | .procname = "temp_valid_lft", |
4249 | .data = &ipv6_devconf.temp_valid_lft, | 4253 | .data = &ipv6_devconf.temp_valid_lft, |
4250 | .maxlen = sizeof(int), | 4254 | .maxlen = sizeof(int), |
4251 | .mode = 0644, | 4255 | .mode = 0644, |
4252 | .proc_handler = proc_dointvec, | 4256 | .proc_handler = proc_dointvec, |
4253 | }, | 4257 | }, |
4254 | { | 4258 | { |
4255 | .procname = "temp_prefered_lft", | 4259 | .procname = "temp_prefered_lft", |
4256 | .data = &ipv6_devconf.temp_prefered_lft, | 4260 | .data = &ipv6_devconf.temp_prefered_lft, |
4257 | .maxlen = sizeof(int), | 4261 | .maxlen = sizeof(int), |
4258 | .mode = 0644, | 4262 | .mode = 0644, |
4259 | .proc_handler = proc_dointvec, | 4263 | .proc_handler = proc_dointvec, |
4260 | }, | 4264 | }, |
4261 | { | 4265 | { |
4262 | .procname = "regen_max_retry", | 4266 | .procname = "regen_max_retry", |
4263 | .data = &ipv6_devconf.regen_max_retry, | 4267 | .data = &ipv6_devconf.regen_max_retry, |
4264 | .maxlen = sizeof(int), | 4268 | .maxlen = sizeof(int), |
4265 | .mode = 0644, | 4269 | .mode = 0644, |
4266 | .proc_handler = proc_dointvec, | 4270 | .proc_handler = proc_dointvec, |
4267 | }, | 4271 | }, |
4268 | { | 4272 | { |
4269 | .procname = "max_desync_factor", | 4273 | .procname = "max_desync_factor", |
4270 | .data = &ipv6_devconf.max_desync_factor, | 4274 | .data = &ipv6_devconf.max_desync_factor, |
4271 | .maxlen = sizeof(int), | 4275 | .maxlen = sizeof(int), |
4272 | .mode = 0644, | 4276 | .mode = 0644, |
4273 | .proc_handler = proc_dointvec, | 4277 | .proc_handler = proc_dointvec, |
4274 | }, | 4278 | }, |
4275 | #endif | 4279 | #endif |
4276 | { | 4280 | { |
4277 | .procname = "max_addresses", | 4281 | .procname = "max_addresses", |
4278 | .data = &ipv6_devconf.max_addresses, | 4282 | .data = &ipv6_devconf.max_addresses, |
4279 | .maxlen = sizeof(int), | 4283 | .maxlen = sizeof(int), |
4280 | .mode = 0644, | 4284 | .mode = 0644, |
4281 | .proc_handler = proc_dointvec, | 4285 | .proc_handler = proc_dointvec, |
4282 | }, | 4286 | }, |
4283 | { | 4287 | { |
4284 | .procname = "accept_ra_defrtr", | 4288 | .procname = "accept_ra_defrtr", |
4285 | .data = &ipv6_devconf.accept_ra_defrtr, | 4289 | .data = &ipv6_devconf.accept_ra_defrtr, |
4286 | .maxlen = sizeof(int), | 4290 | .maxlen = sizeof(int), |
4287 | .mode = 0644, | 4291 | .mode = 0644, |
4288 | .proc_handler = proc_dointvec, | 4292 | .proc_handler = proc_dointvec, |
4289 | }, | 4293 | }, |
4290 | { | 4294 | { |
4291 | .procname = "accept_ra_pinfo", | 4295 | .procname = "accept_ra_pinfo", |
4292 | .data = &ipv6_devconf.accept_ra_pinfo, | 4296 | .data = &ipv6_devconf.accept_ra_pinfo, |
4293 | .maxlen = sizeof(int), | 4297 | .maxlen = sizeof(int), |
4294 | .mode = 0644, | 4298 | .mode = 0644, |
4295 | .proc_handler = proc_dointvec, | 4299 | .proc_handler = proc_dointvec, |
4296 | }, | 4300 | }, |
4297 | #ifdef CONFIG_IPV6_ROUTER_PREF | 4301 | #ifdef CONFIG_IPV6_ROUTER_PREF |
4298 | { | 4302 | { |
4299 | .procname = "accept_ra_rtr_pref", | 4303 | .procname = "accept_ra_rtr_pref", |
4300 | .data = &ipv6_devconf.accept_ra_rtr_pref, | 4304 | .data = &ipv6_devconf.accept_ra_rtr_pref, |
4301 | .maxlen = sizeof(int), | 4305 | .maxlen = sizeof(int), |
4302 | .mode = 0644, | 4306 | .mode = 0644, |
4303 | .proc_handler = proc_dointvec, | 4307 | .proc_handler = proc_dointvec, |
4304 | }, | 4308 | }, |
4305 | { | 4309 | { |
4306 | .procname = "router_probe_interval", | 4310 | .procname = "router_probe_interval", |
4307 | .data = &ipv6_devconf.rtr_probe_interval, | 4311 | .data = &ipv6_devconf.rtr_probe_interval, |
4308 | .maxlen = sizeof(int), | 4312 | .maxlen = sizeof(int), |
4309 | .mode = 0644, | 4313 | .mode = 0644, |
4310 | .proc_handler = proc_dointvec_jiffies, | 4314 | .proc_handler = proc_dointvec_jiffies, |
4311 | }, | 4315 | }, |
4312 | #ifdef CONFIG_IPV6_ROUTE_INFO | 4316 | #ifdef CONFIG_IPV6_ROUTE_INFO |
4313 | { | 4317 | { |
4314 | .procname = "accept_ra_rt_info_max_plen", | 4318 | .procname = "accept_ra_rt_info_max_plen", |
4315 | .data = &ipv6_devconf.accept_ra_rt_info_max_plen, | 4319 | .data = &ipv6_devconf.accept_ra_rt_info_max_plen, |
4316 | .maxlen = sizeof(int), | 4320 | .maxlen = sizeof(int), |
4317 | .mode = 0644, | 4321 | .mode = 0644, |
4318 | .proc_handler = proc_dointvec, | 4322 | .proc_handler = proc_dointvec, |
4319 | }, | 4323 | }, |
4320 | #endif | 4324 | #endif |
4321 | #endif | 4325 | #endif |
4322 | { | 4326 | { |
4323 | .procname = "proxy_ndp", | 4327 | .procname = "proxy_ndp", |
4324 | .data = &ipv6_devconf.proxy_ndp, | 4328 | .data = &ipv6_devconf.proxy_ndp, |
4325 | .maxlen = sizeof(int), | 4329 | .maxlen = sizeof(int), |
4326 | .mode = 0644, | 4330 | .mode = 0644, |
4327 | .proc_handler = proc_dointvec, | 4331 | .proc_handler = proc_dointvec, |
4328 | }, | 4332 | }, |
4329 | { | 4333 | { |
4330 | .procname = "accept_source_route", | 4334 | .procname = "accept_source_route", |
4331 | .data = &ipv6_devconf.accept_source_route, | 4335 | .data = &ipv6_devconf.accept_source_route, |
4332 | .maxlen = sizeof(int), | 4336 | .maxlen = sizeof(int), |
4333 | .mode = 0644, | 4337 | .mode = 0644, |
4334 | .proc_handler = proc_dointvec, | 4338 | .proc_handler = proc_dointvec, |
4335 | }, | 4339 | }, |
4336 | #ifdef CONFIG_IPV6_OPTIMISTIC_DAD | 4340 | #ifdef CONFIG_IPV6_OPTIMISTIC_DAD |
4337 | { | 4341 | { |
4338 | .procname = "optimistic_dad", | 4342 | .procname = "optimistic_dad", |
4339 | .data = &ipv6_devconf.optimistic_dad, | 4343 | .data = &ipv6_devconf.optimistic_dad, |
4340 | .maxlen = sizeof(int), | 4344 | .maxlen = sizeof(int), |
4341 | .mode = 0644, | 4345 | .mode = 0644, |
4342 | .proc_handler = proc_dointvec, | 4346 | .proc_handler = proc_dointvec, |
4343 | 4347 | ||
4344 | }, | 4348 | }, |
4345 | #endif | 4349 | #endif |
4346 | #ifdef CONFIG_IPV6_MROUTE | 4350 | #ifdef CONFIG_IPV6_MROUTE |
4347 | { | 4351 | { |
4348 | .procname = "mc_forwarding", | 4352 | .procname = "mc_forwarding", |
4349 | .data = &ipv6_devconf.mc_forwarding, | 4353 | .data = &ipv6_devconf.mc_forwarding, |
4350 | .maxlen = sizeof(int), | 4354 | .maxlen = sizeof(int), |
4351 | .mode = 0444, | 4355 | .mode = 0444, |
4352 | .proc_handler = proc_dointvec, | 4356 | .proc_handler = proc_dointvec, |
4353 | }, | 4357 | }, |
4354 | #endif | 4358 | #endif |
4355 | { | 4359 | { |
4356 | .procname = "disable_ipv6", | 4360 | .procname = "disable_ipv6", |
4357 | .data = &ipv6_devconf.disable_ipv6, | 4361 | .data = &ipv6_devconf.disable_ipv6, |
4358 | .maxlen = sizeof(int), | 4362 | .maxlen = sizeof(int), |
4359 | .mode = 0644, | 4363 | .mode = 0644, |
4360 | .proc_handler = addrconf_sysctl_disable, | 4364 | .proc_handler = addrconf_sysctl_disable, |
4361 | }, | 4365 | }, |
4362 | { | 4366 | { |
4363 | .procname = "accept_dad", | 4367 | .procname = "accept_dad", |
4364 | .data = &ipv6_devconf.accept_dad, | 4368 | .data = &ipv6_devconf.accept_dad, |
4365 | .maxlen = sizeof(int), | 4369 | .maxlen = sizeof(int), |
4366 | .mode = 0644, | 4370 | .mode = 0644, |
4367 | .proc_handler = proc_dointvec, | 4371 | .proc_handler = proc_dointvec, |
4368 | }, | 4372 | }, |
4369 | { | 4373 | { |
4370 | .procname = "force_tllao", | 4374 | .procname = "force_tllao", |
@@ -4400,8 +4404,8 @@ static int __addrconf_sysctl_register(struct net *net, char *dev_name, | |||
4400 | if (t == NULL) | 4404 | if (t == NULL) |
4401 | goto out; | 4405 | goto out; |
4402 | 4406 | ||
4403 | for (i=0; t->addrconf_vars[i].data; i++) { | 4407 | for (i = 0; t->addrconf_vars[i].data; i++) { |
4404 | t->addrconf_vars[i].data += (char*)p - (char*)&ipv6_devconf; | 4408 | t->addrconf_vars[i].data += (char *)p - (char *)&ipv6_devconf; |
4405 | t->addrconf_vars[i].extra1 = idev; /* embedded; no ref */ | 4409 | t->addrconf_vars[i].extra1 = idev; /* embedded; no ref */ |
4406 | t->addrconf_vars[i].extra2 = net; | 4410 | t->addrconf_vars[i].extra2 = net; |
4407 | } | 4411 | } |
@@ -4538,14 +4542,12 @@ int register_inet6addr_notifier(struct notifier_block *nb) | |||
4538 | { | 4542 | { |
4539 | return atomic_notifier_chain_register(&inet6addr_chain, nb); | 4543 | return atomic_notifier_chain_register(&inet6addr_chain, nb); |
4540 | } | 4544 | } |
4541 | |||
4542 | EXPORT_SYMBOL(register_inet6addr_notifier); | 4545 | EXPORT_SYMBOL(register_inet6addr_notifier); |
4543 | 4546 | ||
4544 | int unregister_inet6addr_notifier(struct notifier_block *nb) | 4547 | int unregister_inet6addr_notifier(struct notifier_block *nb) |
4545 | { | 4548 | { |
4546 | return atomic_notifier_chain_unregister(&inet6addr_chain,nb); | 4549 | return atomic_notifier_chain_unregister(&inet6addr_chain, nb); |
4547 | } | 4550 | } |
4548 | |||
4549 | EXPORT_SYMBOL(unregister_inet6addr_notifier); | 4551 | EXPORT_SYMBOL(unregister_inet6addr_notifier); |
4550 | 4552 | ||
4551 | /* | 4553 | /* |
@@ -4554,11 +4556,12 @@ EXPORT_SYMBOL(unregister_inet6addr_notifier); | |||
4554 | 4556 | ||
4555 | int __init addrconf_init(void) | 4557 | int __init addrconf_init(void) |
4556 | { | 4558 | { |
4557 | int err; | 4559 | int i, err; |
4558 | 4560 | ||
4559 | if ((err = ipv6_addr_label_init()) < 0) { | 4561 | err = ipv6_addr_label_init(); |
4560 | printk(KERN_CRIT "IPv6 Addrconf: cannot initialize default policy table: %d.\n", | 4562 | if (err < 0) { |
4561 | err); | 4563 | printk(KERN_CRIT "IPv6 Addrconf:" |
4564 | " cannot initialize default policy table: %d.\n", err); | ||
4562 | return err; | 4565 | return err; |
4563 | } | 4566 | } |
4564 | 4567 | ||
@@ -4589,6 +4592,9 @@ int __init addrconf_init(void) | |||
4589 | if (err) | 4592 | if (err) |
4590 | goto errlo; | 4593 | goto errlo; |
4591 | 4594 | ||
4595 | for (i = 0; i < IN6_ADDR_HSIZE; i++) | ||
4596 | INIT_HLIST_HEAD(&inet6_addr_lst[i]); | ||
4597 | |||
4592 | register_netdevice_notifier(&ipv6_dev_notf); | 4598 | register_netdevice_notifier(&ipv6_dev_notf); |
4593 | 4599 | ||
4594 | addrconf_verify(0); | 4600 | addrconf_verify(0); |
@@ -4617,7 +4623,6 @@ errlo: | |||
4617 | 4623 | ||
4618 | void addrconf_cleanup(void) | 4624 | void addrconf_cleanup(void) |
4619 | { | 4625 | { |
4620 | struct inet6_ifaddr *ifa; | ||
4621 | struct net_device *dev; | 4626 | struct net_device *dev; |
4622 | int i; | 4627 | int i; |
4623 | 4628 | ||
@@ -4637,20 +4642,10 @@ void addrconf_cleanup(void) | |||
4637 | /* | 4642 | /* |
4638 | * Check hash table. | 4643 | * Check hash table. |
4639 | */ | 4644 | */ |
4640 | write_lock_bh(&addrconf_hash_lock); | 4645 | spin_lock_bh(&addrconf_hash_lock); |
4641 | for (i=0; i < IN6_ADDR_HSIZE; i++) { | 4646 | for (i = 0; i < IN6_ADDR_HSIZE; i++) |
4642 | for (ifa=inet6_addr_lst[i]; ifa; ) { | 4647 | WARN_ON(!hlist_empty(&inet6_addr_lst[i])); |
4643 | struct inet6_ifaddr *bifa; | 4648 | spin_unlock_bh(&addrconf_hash_lock); |
4644 | |||
4645 | bifa = ifa; | ||
4646 | ifa = ifa->lst_next; | ||
4647 | printk(KERN_DEBUG "bug: IPv6 address leakage detected: ifa=%p\n", bifa); | ||
4648 | /* Do not free it; something is wrong. | ||
4649 | Now we can investigate it with debugger. | ||
4650 | */ | ||
4651 | } | ||
4652 | } | ||
4653 | write_unlock_bh(&addrconf_hash_lock); | ||
4654 | 4649 | ||
4655 | del_timer(&addr_chk_timer); | 4650 | del_timer(&addr_chk_timer); |
4656 | rtnl_unlock(); | 4651 | rtnl_unlock(); |
diff --git a/net/ipv6/addrlabel.c b/net/ipv6/addrlabel.c index 6ff73c4c126a..ae404c9a746c 100644 --- a/net/ipv6/addrlabel.c +++ b/net/ipv6/addrlabel.c | |||
@@ -13,6 +13,7 @@ | |||
13 | #include <linux/list.h> | 13 | #include <linux/list.h> |
14 | #include <linux/rcupdate.h> | 14 | #include <linux/rcupdate.h> |
15 | #include <linux/in6.h> | 15 | #include <linux/in6.h> |
16 | #include <linux/slab.h> | ||
16 | #include <net/addrconf.h> | 17 | #include <net/addrconf.h> |
17 | #include <linux/if_addrlabel.h> | 18 | #include <linux/if_addrlabel.h> |
18 | #include <linux/netlink.h> | 19 | #include <linux/netlink.h> |
diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c index 37d14e735c27..3192aa02ba5d 100644 --- a/net/ipv6/af_inet6.c +++ b/net/ipv6/af_inet6.c | |||
@@ -36,6 +36,7 @@ | |||
36 | #include <linux/proc_fs.h> | 36 | #include <linux/proc_fs.h> |
37 | #include <linux/stat.h> | 37 | #include <linux/stat.h> |
38 | #include <linux/init.h> | 38 | #include <linux/init.h> |
39 | #include <linux/slab.h> | ||
39 | 40 | ||
40 | #include <linux/inet.h> | 41 | #include <linux/inet.h> |
41 | #include <linux/netdevice.h> | 42 | #include <linux/netdevice.h> |
diff --git a/net/ipv6/ah6.c b/net/ipv6/ah6.c index 5ac89025f9de..ee82d4ef26ce 100644 --- a/net/ipv6/ah6.c +++ b/net/ipv6/ah6.c | |||
@@ -26,6 +26,7 @@ | |||
26 | 26 | ||
27 | #include <crypto/hash.h> | 27 | #include <crypto/hash.h> |
28 | #include <linux/module.h> | 28 | #include <linux/module.h> |
29 | #include <linux/slab.h> | ||
29 | #include <net/ip.h> | 30 | #include <net/ip.h> |
30 | #include <net/ah.h> | 31 | #include <net/ah.h> |
31 | #include <linux/crypto.h> | 32 | #include <linux/crypto.h> |
diff --git a/net/ipv6/anycast.c b/net/ipv6/anycast.c index c4f6ca32fa74..b5b07054508a 100644 --- a/net/ipv6/anycast.c +++ b/net/ipv6/anycast.c | |||
@@ -29,6 +29,7 @@ | |||
29 | #include <linux/init.h> | 29 | #include <linux/init.h> |
30 | #include <linux/proc_fs.h> | 30 | #include <linux/proc_fs.h> |
31 | #include <linux/seq_file.h> | 31 | #include <linux/seq_file.h> |
32 | #include <linux/slab.h> | ||
32 | 33 | ||
33 | #include <net/net_namespace.h> | 34 | #include <net/net_namespace.h> |
34 | #include <net/sock.h> | 35 | #include <net/sock.h> |
diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c index e6f9cdf780fe..622dc7939a1b 100644 --- a/net/ipv6/datagram.c +++ b/net/ipv6/datagram.c | |||
@@ -21,6 +21,7 @@ | |||
21 | #include <linux/in6.h> | 21 | #include <linux/in6.h> |
22 | #include <linux/ipv6.h> | 22 | #include <linux/ipv6.h> |
23 | #include <linux/route.h> | 23 | #include <linux/route.h> |
24 | #include <linux/slab.h> | ||
24 | 25 | ||
25 | #include <net/ipv6.h> | 26 | #include <net/ipv6.h> |
26 | #include <net/ndisc.h> | 27 | #include <net/ndisc.h> |
diff --git a/net/ipv6/exthdrs.c b/net/ipv6/exthdrs.c index 074f2c084f9f..8a659f92d17a 100644 --- a/net/ipv6/exthdrs.c +++ b/net/ipv6/exthdrs.c | |||
@@ -29,6 +29,7 @@ | |||
29 | #include <linux/netdevice.h> | 29 | #include <linux/netdevice.h> |
30 | #include <linux/in6.h> | 30 | #include <linux/in6.h> |
31 | #include <linux/icmpv6.h> | 31 | #include <linux/icmpv6.h> |
32 | #include <linux/slab.h> | ||
32 | 33 | ||
33 | #include <net/dst.h> | 34 | #include <net/dst.h> |
34 | #include <net/sock.h> | 35 | #include <net/sock.h> |
diff --git a/net/ipv6/fib6_rules.c b/net/ipv6/fib6_rules.c index 5e463c43fcc2..8124f16f2ac2 100644 --- a/net/ipv6/fib6_rules.c +++ b/net/ipv6/fib6_rules.c | |||
@@ -208,7 +208,6 @@ static int fib6_rule_fill(struct fib_rule *rule, struct sk_buff *skb, | |||
208 | { | 208 | { |
209 | struct fib6_rule *rule6 = (struct fib6_rule *) rule; | 209 | struct fib6_rule *rule6 = (struct fib6_rule *) rule; |
210 | 210 | ||
211 | frh->family = AF_INET6; | ||
212 | frh->dst_len = rule6->dst.plen; | 211 | frh->dst_len = rule6->dst.plen; |
213 | frh->src_len = rule6->src.plen; | 212 | frh->src_len = rule6->src.plen; |
214 | frh->tos = rule6->tclass; | 213 | frh->tos = rule6->tclass; |
@@ -239,7 +238,7 @@ static size_t fib6_rule_nlmsg_payload(struct fib_rule *rule) | |||
239 | } | 238 | } |
240 | 239 | ||
241 | static struct fib_rules_ops fib6_rules_ops_template = { | 240 | static struct fib_rules_ops fib6_rules_ops_template = { |
242 | .family = AF_INET6, | 241 | .family = FIB_RULES_IPV6, |
243 | .rule_size = sizeof(struct fib6_rule), | 242 | .rule_size = sizeof(struct fib6_rule), |
244 | .addr_size = sizeof(struct in6_addr), | 243 | .addr_size = sizeof(struct in6_addr), |
245 | .action = fib6_rule_action, | 244 | .action = fib6_rule_action, |
diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c index eb9abe24bdf0..12d2fa42657d 100644 --- a/net/ipv6/icmp.c +++ b/net/ipv6/icmp.c | |||
@@ -40,6 +40,7 @@ | |||
40 | #include <linux/skbuff.h> | 40 | #include <linux/skbuff.h> |
41 | #include <linux/init.h> | 41 | #include <linux/init.h> |
42 | #include <linux/netfilter.h> | 42 | #include <linux/netfilter.h> |
43 | #include <linux/slab.h> | ||
43 | 44 | ||
44 | #ifdef CONFIG_SYSCTL | 45 | #ifdef CONFIG_SYSCTL |
45 | #include <linux/sysctl.h> | 46 | #include <linux/sysctl.h> |
@@ -482,6 +483,7 @@ route_done: | |||
482 | np->tclass, NULL, &fl, (struct rt6_info*)dst, | 483 | np->tclass, NULL, &fl, (struct rt6_info*)dst, |
483 | MSG_DONTWAIT); | 484 | MSG_DONTWAIT); |
484 | if (err) { | 485 | if (err) { |
486 | ICMP6_INC_STATS_BH(net, idev, ICMP6_MIB_OUTMSGS); | ||
485 | ip6_flush_pending_frames(sk); | 487 | ip6_flush_pending_frames(sk); |
486 | goto out_put; | 488 | goto out_put; |
487 | } | 489 | } |
@@ -562,6 +564,7 @@ static void icmpv6_echo_reply(struct sk_buff *skb) | |||
562 | (struct rt6_info*)dst, MSG_DONTWAIT); | 564 | (struct rt6_info*)dst, MSG_DONTWAIT); |
563 | 565 | ||
564 | if (err) { | 566 | if (err) { |
567 | ICMP6_INC_STATS_BH(net, idev, ICMP6_MIB_OUTMSGS); | ||
565 | ip6_flush_pending_frames(sk); | 568 | ip6_flush_pending_frames(sk); |
566 | goto out_put; | 569 | goto out_put; |
567 | } | 570 | } |
diff --git a/net/ipv6/inet6_connection_sock.c b/net/ipv6/inet6_connection_sock.c index 3516e6fe2e56..628db24bcf22 100644 --- a/net/ipv6/inet6_connection_sock.c +++ b/net/ipv6/inet6_connection_sock.c | |||
@@ -17,6 +17,7 @@ | |||
17 | #include <linux/in6.h> | 17 | #include <linux/in6.h> |
18 | #include <linux/ipv6.h> | 18 | #include <linux/ipv6.h> |
19 | #include <linux/jhash.h> | 19 | #include <linux/jhash.h> |
20 | #include <linux/slab.h> | ||
20 | 21 | ||
21 | #include <net/addrconf.h> | 22 | #include <net/addrconf.h> |
22 | #include <net/inet_connection_sock.h> | 23 | #include <net/inet_connection_sock.h> |
diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c index 2f9847924fa5..dc6e0b8f260d 100644 --- a/net/ipv6/ip6_fib.c +++ b/net/ipv6/ip6_fib.c | |||
@@ -26,6 +26,7 @@ | |||
26 | #include <linux/in6.h> | 26 | #include <linux/in6.h> |
27 | #include <linux/init.h> | 27 | #include <linux/init.h> |
28 | #include <linux/list.h> | 28 | #include <linux/list.h> |
29 | #include <linux/slab.h> | ||
29 | 30 | ||
30 | #ifdef CONFIG_PROC_FS | 31 | #ifdef CONFIG_PROC_FS |
31 | #include <linux/proc_fs.h> | 32 | #include <linux/proc_fs.h> |
@@ -127,12 +128,23 @@ static __inline__ u32 fib6_new_sernum(void) | |||
127 | /* | 128 | /* |
128 | * test bit | 129 | * test bit |
129 | */ | 130 | */ |
131 | #if defined(__LITTLE_ENDIAN) | ||
132 | # define BITOP_BE32_SWIZZLE (0x1F & ~7) | ||
133 | #else | ||
134 | # define BITOP_BE32_SWIZZLE 0 | ||
135 | #endif | ||
130 | 136 | ||
131 | static __inline__ __be32 addr_bit_set(void *token, int fn_bit) | 137 | static __inline__ __be32 addr_bit_set(void *token, int fn_bit) |
132 | { | 138 | { |
133 | __be32 *addr = token; | 139 | __be32 *addr = token; |
134 | 140 | /* | |
135 | return htonl(1 << ((~fn_bit)&0x1F)) & addr[fn_bit>>5]; | 141 | * Here, |
142 | * 1 << ((~fn_bit ^ BITOP_BE32_SWIZZLE) & 0x1f) | ||
143 | * is optimized version of | ||
144 | * htonl(1 << ((~fn_bit)&0x1F)) | ||
145 | * See include/asm-generic/bitops/le.h. | ||
146 | */ | ||
147 | return (1 << ((~fn_bit ^ BITOP_BE32_SWIZZLE) & 0x1f)) & addr[fn_bit >> 5]; | ||
136 | } | 148 | } |
137 | 149 | ||
138 | static __inline__ struct fib6_node * node_alloc(void) | 150 | static __inline__ struct fib6_node * node_alloc(void) |
diff --git a/net/ipv6/ip6_flowlabel.c b/net/ipv6/ip6_flowlabel.c index e41eba8aacf1..14e23216eb28 100644 --- a/net/ipv6/ip6_flowlabel.c +++ b/net/ipv6/ip6_flowlabel.c | |||
@@ -20,6 +20,7 @@ | |||
20 | #include <linux/route.h> | 20 | #include <linux/route.h> |
21 | #include <linux/proc_fs.h> | 21 | #include <linux/proc_fs.h> |
22 | #include <linux/seq_file.h> | 22 | #include <linux/seq_file.h> |
23 | #include <linux/slab.h> | ||
23 | 24 | ||
24 | #include <net/net_namespace.h> | 25 | #include <net/net_namespace.h> |
25 | #include <net/sock.h> | 26 | #include <net/sock.h> |
diff --git a/net/ipv6/ip6_input.c b/net/ipv6/ip6_input.c index e28f9203deca..6aa7ee1295c2 100644 --- a/net/ipv6/ip6_input.c +++ b/net/ipv6/ip6_input.c | |||
@@ -28,6 +28,7 @@ | |||
28 | #include <linux/in6.h> | 28 | #include <linux/in6.h> |
29 | #include <linux/icmpv6.h> | 29 | #include <linux/icmpv6.h> |
30 | #include <linux/mroute6.h> | 30 | #include <linux/mroute6.h> |
31 | #include <linux/slab.h> | ||
31 | 32 | ||
32 | #include <linux/netfilter.h> | 33 | #include <linux/netfilter.h> |
33 | #include <linux/netfilter_ipv6.h> | 34 | #include <linux/netfilter_ipv6.h> |
diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c index dabf108ad811..16c4391f952b 100644 --- a/net/ipv6/ip6_output.c +++ b/net/ipv6/ip6_output.c | |||
@@ -37,6 +37,7 @@ | |||
37 | #include <linux/tcp.h> | 37 | #include <linux/tcp.h> |
38 | #include <linux/route.h> | 38 | #include <linux/route.h> |
39 | #include <linux/module.h> | 39 | #include <linux/module.h> |
40 | #include <linux/slab.h> | ||
40 | 41 | ||
41 | #include <linux/netfilter.h> | 42 | #include <linux/netfilter.h> |
42 | #include <linux/netfilter_ipv6.h> | 43 | #include <linux/netfilter_ipv6.h> |
diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c index 138980eec214..2599870747ec 100644 --- a/net/ipv6/ip6_tunnel.c +++ b/net/ipv6/ip6_tunnel.c | |||
@@ -37,6 +37,7 @@ | |||
37 | #include <linux/route.h> | 37 | #include <linux/route.h> |
38 | #include <linux/rtnetlink.h> | 38 | #include <linux/rtnetlink.h> |
39 | #include <linux/netfilter_ipv6.h> | 39 | #include <linux/netfilter_ipv6.h> |
40 | #include <linux/slab.h> | ||
40 | 41 | ||
41 | #include <asm/uaccess.h> | 42 | #include <asm/uaccess.h> |
42 | #include <asm/atomic.h> | 43 | #include <asm/atomic.h> |
diff --git a/net/ipv6/ip6mr.c b/net/ipv6/ip6mr.c index 52e0f74fdfe0..3e333268db89 100644 --- a/net/ipv6/ip6mr.c +++ b/net/ipv6/ip6mr.c | |||
@@ -33,6 +33,7 @@ | |||
33 | #include <linux/proc_fs.h> | 33 | #include <linux/proc_fs.h> |
34 | #include <linux/seq_file.h> | 34 | #include <linux/seq_file.h> |
35 | #include <linux/init.h> | 35 | #include <linux/init.h> |
36 | #include <linux/slab.h> | ||
36 | #include <net/protocol.h> | 37 | #include <net/protocol.h> |
37 | #include <linux/skbuff.h> | 38 | #include <linux/skbuff.h> |
38 | #include <net/sock.h> | 39 | #include <net/sock.h> |
@@ -1113,6 +1114,9 @@ static int ip6mr_mfc_add(struct net *net, struct mf6cctl *mfc, int mrtsock) | |||
1113 | unsigned char ttls[MAXMIFS]; | 1114 | unsigned char ttls[MAXMIFS]; |
1114 | int i; | 1115 | int i; |
1115 | 1116 | ||
1117 | if (mfc->mf6cc_parent >= MAXMIFS) | ||
1118 | return -ENFILE; | ||
1119 | |||
1116 | memset(ttls, 255, MAXMIFS); | 1120 | memset(ttls, 255, MAXMIFS); |
1117 | for (i = 0; i < MAXMIFS; i++) { | 1121 | for (i = 0; i < MAXMIFS; i++) { |
1118 | if (IF_ISSET(i, &mfc->mf6cc_ifset)) | 1122 | if (IF_ISSET(i, &mfc->mf6cc_ifset)) |
@@ -1692,17 +1696,20 @@ ip6mr_fill_mroute(struct sk_buff *skb, struct mfc6_cache *c, struct rtmsg *rtm) | |||
1692 | int ct; | 1696 | int ct; |
1693 | struct rtnexthop *nhp; | 1697 | struct rtnexthop *nhp; |
1694 | struct net *net = mfc6_net(c); | 1698 | struct net *net = mfc6_net(c); |
1695 | struct net_device *dev = net->ipv6.vif6_table[c->mf6c_parent].dev; | ||
1696 | u8 *b = skb_tail_pointer(skb); | 1699 | u8 *b = skb_tail_pointer(skb); |
1697 | struct rtattr *mp_head; | 1700 | struct rtattr *mp_head; |
1698 | 1701 | ||
1699 | if (dev) | 1702 | /* If cache is unresolved, don't try to parse IIF and OIF */ |
1700 | RTA_PUT(skb, RTA_IIF, 4, &dev->ifindex); | 1703 | if (c->mf6c_parent > MAXMIFS) |
1704 | return -ENOENT; | ||
1705 | |||
1706 | if (MIF_EXISTS(net, c->mf6c_parent)) | ||
1707 | RTA_PUT(skb, RTA_IIF, 4, &net->ipv6.vif6_table[c->mf6c_parent].dev->ifindex); | ||
1701 | 1708 | ||
1702 | mp_head = (struct rtattr *)skb_put(skb, RTA_LENGTH(0)); | 1709 | mp_head = (struct rtattr *)skb_put(skb, RTA_LENGTH(0)); |
1703 | 1710 | ||
1704 | for (ct = c->mfc_un.res.minvif; ct < c->mfc_un.res.maxvif; ct++) { | 1711 | for (ct = c->mfc_un.res.minvif; ct < c->mfc_un.res.maxvif; ct++) { |
1705 | if (c->mfc_un.res.ttls[ct] < 255) { | 1712 | if (MIF_EXISTS(net, ct) && c->mfc_un.res.ttls[ct] < 255) { |
1706 | if (skb_tailroom(skb) < RTA_ALIGN(RTA_ALIGN(sizeof(*nhp)) + 4)) | 1713 | if (skb_tailroom(skb) < RTA_ALIGN(RTA_ALIGN(sizeof(*nhp)) + 4)) |
1707 | goto rtattr_failure; | 1714 | goto rtattr_failure; |
1708 | nhp = (struct rtnexthop *)skb_put(skb, RTA_ALIGN(sizeof(*nhp))); | 1715 | nhp = (struct rtnexthop *)skb_put(skb, RTA_ALIGN(sizeof(*nhp))); |
diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c index 430454ee5ead..1160400e9dbd 100644 --- a/net/ipv6/ipv6_sockglue.c +++ b/net/ipv6/ipv6_sockglue.c | |||
@@ -36,6 +36,7 @@ | |||
36 | #include <linux/init.h> | 36 | #include <linux/init.h> |
37 | #include <linux/sysctl.h> | 37 | #include <linux/sysctl.h> |
38 | #include <linux/netfilter.h> | 38 | #include <linux/netfilter.h> |
39 | #include <linux/slab.h> | ||
39 | 40 | ||
40 | #include <net/sock.h> | 41 | #include <net/sock.h> |
41 | #include <net/snmp.h> | 42 | #include <net/snmp.h> |
@@ -113,9 +114,9 @@ struct ipv6_txoptions *ipv6_update_options(struct sock *sk, | |||
113 | } | 114 | } |
114 | opt = xchg(&inet6_sk(sk)->opt, opt); | 115 | opt = xchg(&inet6_sk(sk)->opt, opt); |
115 | } else { | 116 | } else { |
116 | write_lock(&sk->sk_dst_lock); | 117 | spin_lock(&sk->sk_dst_lock); |
117 | opt = xchg(&inet6_sk(sk)->opt, opt); | 118 | opt = xchg(&inet6_sk(sk)->opt, opt); |
118 | write_unlock(&sk->sk_dst_lock); | 119 | spin_unlock(&sk->sk_dst_lock); |
119 | } | 120 | } |
120 | sk_dst_reset(sk); | 121 | sk_dst_reset(sk); |
121 | 122 | ||
@@ -970,14 +971,13 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname, | |||
970 | case IPV6_MTU: | 971 | case IPV6_MTU: |
971 | { | 972 | { |
972 | struct dst_entry *dst; | 973 | struct dst_entry *dst; |
974 | |||
973 | val = 0; | 975 | val = 0; |
974 | lock_sock(sk); | 976 | rcu_read_lock(); |
975 | dst = sk_dst_get(sk); | 977 | dst = __sk_dst_get(sk); |
976 | if (dst) { | 978 | if (dst) |
977 | val = dst_mtu(dst); | 979 | val = dst_mtu(dst); |
978 | dst_release(dst); | 980 | rcu_read_unlock(); |
979 | } | ||
980 | release_sock(sk); | ||
981 | if (!val) | 981 | if (!val) |
982 | return -ENOTCONN; | 982 | return -ENOTCONN; |
983 | break; | 983 | break; |
@@ -1065,12 +1065,14 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname, | |||
1065 | else | 1065 | else |
1066 | val = np->mcast_hops; | 1066 | val = np->mcast_hops; |
1067 | 1067 | ||
1068 | dst = sk_dst_get(sk); | 1068 | if (val < 0) { |
1069 | if (dst) { | 1069 | rcu_read_lock(); |
1070 | if (val < 0) | 1070 | dst = __sk_dst_get(sk); |
1071 | if (dst) | ||
1071 | val = ip6_dst_hoplimit(dst); | 1072 | val = ip6_dst_hoplimit(dst); |
1072 | dst_release(dst); | 1073 | rcu_read_unlock(); |
1073 | } | 1074 | } |
1075 | |||
1074 | if (val < 0) | 1076 | if (val < 0) |
1075 | val = sock_net(sk)->ipv6.devconf_all->hop_limit; | 1077 | val = sock_net(sk)->ipv6.devconf_all->hop_limit; |
1076 | break; | 1078 | break; |
diff --git a/net/ipv6/mcast.c b/net/ipv6/mcast.c index bcd971915969..62ed08213d91 100644 --- a/net/ipv6/mcast.c +++ b/net/ipv6/mcast.c | |||
@@ -43,6 +43,7 @@ | |||
43 | #include <linux/init.h> | 43 | #include <linux/init.h> |
44 | #include <linux/proc_fs.h> | 44 | #include <linux/proc_fs.h> |
45 | #include <linux/seq_file.h> | 45 | #include <linux/seq_file.h> |
46 | #include <linux/slab.h> | ||
46 | 47 | ||
47 | #include <linux/netfilter.h> | 48 | #include <linux/netfilter.h> |
48 | #include <linux/netfilter_ipv6.h> | 49 | #include <linux/netfilter_ipv6.h> |
@@ -714,7 +715,7 @@ static void igmp6_group_added(struct ifmcaddr6 *mc) | |||
714 | if (!(mc->mca_flags&MAF_LOADED)) { | 715 | if (!(mc->mca_flags&MAF_LOADED)) { |
715 | mc->mca_flags |= MAF_LOADED; | 716 | mc->mca_flags |= MAF_LOADED; |
716 | if (ndisc_mc_map(&mc->mca_addr, buf, dev, 0) == 0) | 717 | if (ndisc_mc_map(&mc->mca_addr, buf, dev, 0) == 0) |
717 | dev_mc_add(dev, buf, dev->addr_len, 0); | 718 | dev_mc_add(dev, buf); |
718 | } | 719 | } |
719 | spin_unlock_bh(&mc->mca_lock); | 720 | spin_unlock_bh(&mc->mca_lock); |
720 | 721 | ||
@@ -740,7 +741,7 @@ static void igmp6_group_dropped(struct ifmcaddr6 *mc) | |||
740 | if (mc->mca_flags&MAF_LOADED) { | 741 | if (mc->mca_flags&MAF_LOADED) { |
741 | mc->mca_flags &= ~MAF_LOADED; | 742 | mc->mca_flags &= ~MAF_LOADED; |
742 | if (ndisc_mc_map(&mc->mca_addr, buf, dev, 0) == 0) | 743 | if (ndisc_mc_map(&mc->mca_addr, buf, dev, 0) == 0) |
743 | dev_mc_delete(dev, buf, dev->addr_len, 0); | 744 | dev_mc_del(dev, buf); |
744 | } | 745 | } |
745 | 746 | ||
746 | if (mc->mca_flags & MAF_NOREPORT) | 747 | if (mc->mca_flags & MAF_NOREPORT) |
diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c index 8bcc4b7db3bf..da0a4d2adc69 100644 --- a/net/ipv6/ndisc.c +++ b/net/ipv6/ndisc.c | |||
@@ -59,6 +59,7 @@ | |||
59 | #include <linux/route.h> | 59 | #include <linux/route.h> |
60 | #include <linux/init.h> | 60 | #include <linux/init.h> |
61 | #include <linux/rcupdate.h> | 61 | #include <linux/rcupdate.h> |
62 | #include <linux/slab.h> | ||
62 | #ifdef CONFIG_SYSCTL | 63 | #ifdef CONFIG_SYSCTL |
63 | #include <linux/sysctl.h> | 64 | #include <linux/sysctl.h> |
64 | #endif | 65 | #endif |
diff --git a/net/ipv6/netfilter/ip6_queue.c b/net/ipv6/netfilter/ip6_queue.c index 7854052be60b..6a68a74d14a3 100644 --- a/net/ipv6/netfilter/ip6_queue.c +++ b/net/ipv6/netfilter/ip6_queue.c | |||
@@ -25,6 +25,7 @@ | |||
25 | #include <linux/proc_fs.h> | 25 | #include <linux/proc_fs.h> |
26 | #include <linux/seq_file.h> | 26 | #include <linux/seq_file.h> |
27 | #include <linux/mutex.h> | 27 | #include <linux/mutex.h> |
28 | #include <linux/slab.h> | ||
28 | #include <net/net_namespace.h> | 29 | #include <net/net_namespace.h> |
29 | #include <net/sock.h> | 30 | #include <net/sock.h> |
30 | #include <net/ipv6.h> | 31 | #include <net/ipv6.h> |
diff --git a/net/ipv6/netfilter/ip6t_REJECT.c b/net/ipv6/netfilter/ip6t_REJECT.c index dd8afbaf00a8..39b50c3768e8 100644 --- a/net/ipv6/netfilter/ip6t_REJECT.c +++ b/net/ipv6/netfilter/ip6t_REJECT.c | |||
@@ -15,6 +15,7 @@ | |||
15 | * 2 of the License, or (at your option) any later version. | 15 | * 2 of the License, or (at your option) any later version. |
16 | */ | 16 | */ |
17 | 17 | ||
18 | #include <linux/gfp.h> | ||
18 | #include <linux/module.h> | 19 | #include <linux/module.h> |
19 | #include <linux/skbuff.h> | 20 | #include <linux/skbuff.h> |
20 | #include <linux/icmpv6.h> | 21 | #include <linux/icmpv6.h> |
diff --git a/net/ipv6/netfilter/ip6t_hbh.c b/net/ipv6/netfilter/ip6t_hbh.c index cbe8dec9744b..e60677519e40 100644 --- a/net/ipv6/netfilter/ip6t_hbh.c +++ b/net/ipv6/netfilter/ip6t_hbh.c | |||
@@ -141,11 +141,11 @@ hbh_mt6(const struct sk_buff *skb, const struct xt_match_param *par) | |||
141 | } | 141 | } |
142 | 142 | ||
143 | /* Step to the next */ | 143 | /* Step to the next */ |
144 | pr_debug("len%04X \n", optlen); | 144 | pr_debug("len%04X\n", optlen); |
145 | 145 | ||
146 | if ((ptr > skb->len - optlen || hdrlen < optlen) && | 146 | if ((ptr > skb->len - optlen || hdrlen < optlen) && |
147 | temp < optinfo->optsnr - 1) { | 147 | temp < optinfo->optsnr - 1) { |
148 | pr_debug("new pointer is too large! \n"); | 148 | pr_debug("new pointer is too large!\n"); |
149 | break; | 149 | break; |
150 | } | 150 | } |
151 | ptr += optlen; | 151 | ptr += optlen; |
diff --git a/net/ipv6/netfilter/ip6table_filter.c b/net/ipv6/netfilter/ip6table_filter.c index 36b72cafc227..d6fc9aff3163 100644 --- a/net/ipv6/netfilter/ip6table_filter.c +++ b/net/ipv6/netfilter/ip6table_filter.c | |||
@@ -12,6 +12,7 @@ | |||
12 | #include <linux/module.h> | 12 | #include <linux/module.h> |
13 | #include <linux/moduleparam.h> | 13 | #include <linux/moduleparam.h> |
14 | #include <linux/netfilter_ipv6/ip6_tables.h> | 14 | #include <linux/netfilter_ipv6/ip6_tables.h> |
15 | #include <linux/slab.h> | ||
15 | 16 | ||
16 | MODULE_LICENSE("GPL"); | 17 | MODULE_LICENSE("GPL"); |
17 | MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>"); | 18 | MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>"); |
diff --git a/net/ipv6/netfilter/ip6table_mangle.c b/net/ipv6/netfilter/ip6table_mangle.c index 7844e557c0ec..6a102b57f356 100644 --- a/net/ipv6/netfilter/ip6table_mangle.c +++ b/net/ipv6/netfilter/ip6table_mangle.c | |||
@@ -10,6 +10,7 @@ | |||
10 | */ | 10 | */ |
11 | #include <linux/module.h> | 11 | #include <linux/module.h> |
12 | #include <linux/netfilter_ipv6/ip6_tables.h> | 12 | #include <linux/netfilter_ipv6/ip6_tables.h> |
13 | #include <linux/slab.h> | ||
13 | 14 | ||
14 | MODULE_LICENSE("GPL"); | 15 | MODULE_LICENSE("GPL"); |
15 | MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>"); | 16 | MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>"); |
diff --git a/net/ipv6/netfilter/ip6table_raw.c b/net/ipv6/netfilter/ip6table_raw.c index aef31a29de9e..5b9926a011bd 100644 --- a/net/ipv6/netfilter/ip6table_raw.c +++ b/net/ipv6/netfilter/ip6table_raw.c | |||
@@ -5,6 +5,7 @@ | |||
5 | */ | 5 | */ |
6 | #include <linux/module.h> | 6 | #include <linux/module.h> |
7 | #include <linux/netfilter_ipv6/ip6_tables.h> | 7 | #include <linux/netfilter_ipv6/ip6_tables.h> |
8 | #include <linux/slab.h> | ||
8 | 9 | ||
9 | #define RAW_VALID_HOOKS ((1 << NF_INET_PRE_ROUTING) | (1 << NF_INET_LOCAL_OUT)) | 10 | #define RAW_VALID_HOOKS ((1 << NF_INET_PRE_ROUTING) | (1 << NF_INET_LOCAL_OUT)) |
10 | 11 | ||
@@ -13,7 +14,7 @@ static const struct xt_table packet_raw = { | |||
13 | .valid_hooks = RAW_VALID_HOOKS, | 14 | .valid_hooks = RAW_VALID_HOOKS, |
14 | .me = THIS_MODULE, | 15 | .me = THIS_MODULE, |
15 | .af = NFPROTO_IPV6, | 16 | .af = NFPROTO_IPV6, |
16 | .priority = NF_IP6_PRI_FIRST, | 17 | .priority = NF_IP6_PRI_RAW, |
17 | }; | 18 | }; |
18 | 19 | ||
19 | /* The work comes in here from netfilter.c. */ | 20 | /* The work comes in here from netfilter.c. */ |
diff --git a/net/ipv6/netfilter/ip6table_security.c b/net/ipv6/netfilter/ip6table_security.c index 0824d865aa9b..91aa2b4d83c9 100644 --- a/net/ipv6/netfilter/ip6table_security.c +++ b/net/ipv6/netfilter/ip6table_security.c | |||
@@ -17,6 +17,7 @@ | |||
17 | */ | 17 | */ |
18 | #include <linux/module.h> | 18 | #include <linux/module.h> |
19 | #include <linux/netfilter_ipv6/ip6_tables.h> | 19 | #include <linux/netfilter_ipv6/ip6_tables.h> |
20 | #include <linux/slab.h> | ||
20 | 21 | ||
21 | MODULE_LICENSE("GPL"); | 22 | MODULE_LICENSE("GPL"); |
22 | MODULE_AUTHOR("James Morris <jmorris <at> redhat.com>"); | 23 | MODULE_AUTHOR("James Morris <jmorris <at> redhat.com>"); |
diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c index f1171b744650..dd5b9bd61c62 100644 --- a/net/ipv6/netfilter/nf_conntrack_reasm.c +++ b/net/ipv6/netfilter/nf_conntrack_reasm.c | |||
@@ -27,6 +27,7 @@ | |||
27 | #include <linux/ipv6.h> | 27 | #include <linux/ipv6.h> |
28 | #include <linux/icmpv6.h> | 28 | #include <linux/icmpv6.h> |
29 | #include <linux/random.h> | 29 | #include <linux/random.h> |
30 | #include <linux/slab.h> | ||
30 | 31 | ||
31 | #include <net/sock.h> | 32 | #include <net/sock.h> |
32 | #include <net/snmp.h> | 33 | #include <net/snmp.h> |
diff --git a/net/ipv6/proc.c b/net/ipv6/proc.c index 58344c0fbd13..458eabfbe130 100644 --- a/net/ipv6/proc.c +++ b/net/ipv6/proc.c | |||
@@ -97,6 +97,7 @@ static const struct snmp_mib snmp6_icmp6_list[] = { | |||
97 | SNMP_MIB_ITEM("Icmp6InMsgs", ICMP6_MIB_INMSGS), | 97 | SNMP_MIB_ITEM("Icmp6InMsgs", ICMP6_MIB_INMSGS), |
98 | SNMP_MIB_ITEM("Icmp6InErrors", ICMP6_MIB_INERRORS), | 98 | SNMP_MIB_ITEM("Icmp6InErrors", ICMP6_MIB_INERRORS), |
99 | SNMP_MIB_ITEM("Icmp6OutMsgs", ICMP6_MIB_OUTMSGS), | 99 | SNMP_MIB_ITEM("Icmp6OutMsgs", ICMP6_MIB_OUTMSGS), |
100 | SNMP_MIB_ITEM("Icmp6OutErrors", ICMP6_MIB_OUTERRORS), | ||
100 | SNMP_MIB_SENTINEL | 101 | SNMP_MIB_SENTINEL |
101 | }; | 102 | }; |
102 | 103 | ||
diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c index ed31c37c6e39..8763b1a0814a 100644 --- a/net/ipv6/raw.c +++ b/net/ipv6/raw.c | |||
@@ -21,6 +21,7 @@ | |||
21 | #include <linux/errno.h> | 21 | #include <linux/errno.h> |
22 | #include <linux/types.h> | 22 | #include <linux/types.h> |
23 | #include <linux/socket.h> | 23 | #include <linux/socket.h> |
24 | #include <linux/slab.h> | ||
24 | #include <linux/sockios.h> | 25 | #include <linux/sockios.h> |
25 | #include <linux/net.h> | 26 | #include <linux/net.h> |
26 | #include <linux/in6.h> | 27 | #include <linux/in6.h> |
diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c index a555156e9779..6d4292ff5854 100644 --- a/net/ipv6/reassembly.c +++ b/net/ipv6/reassembly.c | |||
@@ -41,6 +41,7 @@ | |||
41 | #include <linux/random.h> | 41 | #include <linux/random.h> |
42 | #include <linux/jhash.h> | 42 | #include <linux/jhash.h> |
43 | #include <linux/skbuff.h> | 43 | #include <linux/skbuff.h> |
44 | #include <linux/slab.h> | ||
44 | 45 | ||
45 | #include <net/sock.h> | 46 | #include <net/sock.h> |
46 | #include <net/snmp.h> | 47 | #include <net/snmp.h> |
diff --git a/net/ipv6/route.c b/net/ipv6/route.c index 52cd3eff31dc..c2438e8cb9d0 100644 --- a/net/ipv6/route.c +++ b/net/ipv6/route.c | |||
@@ -40,6 +40,7 @@ | |||
40 | #include <linux/proc_fs.h> | 40 | #include <linux/proc_fs.h> |
41 | #include <linux/seq_file.h> | 41 | #include <linux/seq_file.h> |
42 | #include <linux/nsproxy.h> | 42 | #include <linux/nsproxy.h> |
43 | #include <linux/slab.h> | ||
43 | #include <net/net_namespace.h> | 44 | #include <net/net_namespace.h> |
44 | #include <net/snmp.h> | 45 | #include <net/snmp.h> |
45 | #include <net/ipv6.h> | 46 | #include <net/ipv6.h> |
@@ -879,7 +880,7 @@ static struct dst_entry *ip6_dst_check(struct dst_entry *dst, u32 cookie) | |||
879 | 880 | ||
880 | rt = (struct rt6_info *) dst; | 881 | rt = (struct rt6_info *) dst; |
881 | 882 | ||
882 | if (rt && rt->rt6i_node && (rt->rt6i_node->fn_sernum == cookie)) | 883 | if (rt->rt6i_node && (rt->rt6i_node->fn_sernum == cookie)) |
883 | return dst; | 884 | return dst; |
884 | 885 | ||
885 | return NULL; | 886 | return NULL; |
@@ -890,12 +891,17 @@ static struct dst_entry *ip6_negative_advice(struct dst_entry *dst) | |||
890 | struct rt6_info *rt = (struct rt6_info *) dst; | 891 | struct rt6_info *rt = (struct rt6_info *) dst; |
891 | 892 | ||
892 | if (rt) { | 893 | if (rt) { |
893 | if (rt->rt6i_flags & RTF_CACHE) | 894 | if (rt->rt6i_flags & RTF_CACHE) { |
894 | ip6_del_rt(rt); | 895 | if (rt6_check_expired(rt)) { |
895 | else | 896 | ip6_del_rt(rt); |
897 | dst = NULL; | ||
898 | } | ||
899 | } else { | ||
896 | dst_release(dst); | 900 | dst_release(dst); |
901 | dst = NULL; | ||
902 | } | ||
897 | } | 903 | } |
898 | return NULL; | 904 | return dst; |
899 | } | 905 | } |
900 | 906 | ||
901 | static void ip6_link_failure(struct sk_buff *skb) | 907 | static void ip6_link_failure(struct sk_buff *skb) |
diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c index b1eea811be48..5abae10cd884 100644 --- a/net/ipv6/sit.c +++ b/net/ipv6/sit.c | |||
@@ -28,6 +28,7 @@ | |||
28 | #include <linux/netdevice.h> | 28 | #include <linux/netdevice.h> |
29 | #include <linux/if_arp.h> | 29 | #include <linux/if_arp.h> |
30 | #include <linux/icmp.h> | 30 | #include <linux/icmp.h> |
31 | #include <linux/slab.h> | ||
31 | #include <asm/uaccess.h> | 32 | #include <asm/uaccess.h> |
32 | #include <linux/init.h> | 33 | #include <linux/init.h> |
33 | #include <linux/netfilter_ipv4.h> | 34 | #include <linux/netfilter_ipv4.h> |
diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c index f841d93bf987..fa1d8f4e0051 100644 --- a/net/ipv6/sysctl_net_ipv6.c +++ b/net/ipv6/sysctl_net_ipv6.c | |||
@@ -9,6 +9,7 @@ | |||
9 | #include <linux/sysctl.h> | 9 | #include <linux/sysctl.h> |
10 | #include <linux/in6.h> | 10 | #include <linux/in6.h> |
11 | #include <linux/ipv6.h> | 11 | #include <linux/ipv6.h> |
12 | #include <linux/slab.h> | ||
12 | #include <net/ndisc.h> | 13 | #include <net/ndisc.h> |
13 | #include <net/ipv6.h> | 14 | #include <net/ipv6.h> |
14 | #include <net/addrconf.h> | 15 | #include <net/addrconf.h> |
diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c index 9b6dbba80d31..b429dfdd69dc 100644 --- a/net/ipv6/tcp_ipv6.c +++ b/net/ipv6/tcp_ipv6.c | |||
@@ -38,6 +38,7 @@ | |||
38 | #include <linux/jhash.h> | 38 | #include <linux/jhash.h> |
39 | #include <linux/ipsec.h> | 39 | #include <linux/ipsec.h> |
40 | #include <linux/times.h> | 40 | #include <linux/times.h> |
41 | #include <linux/slab.h> | ||
41 | 42 | ||
42 | #include <linux/ipv6.h> | 43 | #include <linux/ipv6.h> |
43 | #include <linux/icmpv6.h> | 44 | #include <linux/icmpv6.h> |
@@ -74,6 +75,9 @@ static void tcp_v6_reqsk_send_ack(struct sock *sk, struct sk_buff *skb, | |||
74 | struct request_sock *req); | 75 | struct request_sock *req); |
75 | 76 | ||
76 | static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb); | 77 | static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb); |
78 | static void __tcp_v6_send_check(struct sk_buff *skb, | ||
79 | struct in6_addr *saddr, | ||
80 | struct in6_addr *daddr); | ||
77 | 81 | ||
78 | static const struct inet_connection_sock_af_ops ipv6_mapped; | 82 | static const struct inet_connection_sock_af_ops ipv6_mapped; |
79 | static const struct inet_connection_sock_af_ops ipv6_specific; | 83 | static const struct inet_connection_sock_af_ops ipv6_specific; |
@@ -502,11 +506,7 @@ static int tcp_v6_send_synack(struct sock *sk, struct request_sock *req, | |||
502 | 506 | ||
503 | skb = tcp_make_synack(sk, dst, req, rvp); | 507 | skb = tcp_make_synack(sk, dst, req, rvp); |
504 | if (skb) { | 508 | if (skb) { |
505 | struct tcphdr *th = tcp_hdr(skb); | 509 | __tcp_v6_send_check(skb, &treq->loc_addr, &treq->rmt_addr); |
506 | |||
507 | th->check = tcp_v6_check(skb->len, | ||
508 | &treq->loc_addr, &treq->rmt_addr, | ||
509 | csum_partial(th, skb->len, skb->csum)); | ||
510 | 510 | ||
511 | ipv6_addr_copy(&fl.fl6_dst, &treq->rmt_addr); | 511 | ipv6_addr_copy(&fl.fl6_dst, &treq->rmt_addr); |
512 | err = ip6_xmit(sk, skb, &fl, opt, 0); | 512 | err = ip6_xmit(sk, skb, &fl, opt, 0); |
@@ -917,22 +917,29 @@ static struct timewait_sock_ops tcp6_timewait_sock_ops = { | |||
917 | .twsk_destructor= tcp_twsk_destructor, | 917 | .twsk_destructor= tcp_twsk_destructor, |
918 | }; | 918 | }; |
919 | 919 | ||
920 | static void tcp_v6_send_check(struct sock *sk, int len, struct sk_buff *skb) | 920 | static void __tcp_v6_send_check(struct sk_buff *skb, |
921 | struct in6_addr *saddr, struct in6_addr *daddr) | ||
921 | { | 922 | { |
922 | struct ipv6_pinfo *np = inet6_sk(sk); | ||
923 | struct tcphdr *th = tcp_hdr(skb); | 923 | struct tcphdr *th = tcp_hdr(skb); |
924 | 924 | ||
925 | if (skb->ip_summed == CHECKSUM_PARTIAL) { | 925 | if (skb->ip_summed == CHECKSUM_PARTIAL) { |
926 | th->check = ~csum_ipv6_magic(&np->saddr, &np->daddr, len, IPPROTO_TCP, 0); | 926 | th->check = ~tcp_v6_check(skb->len, saddr, daddr, 0); |
927 | skb->csum_start = skb_transport_header(skb) - skb->head; | 927 | skb->csum_start = skb_transport_header(skb) - skb->head; |
928 | skb->csum_offset = offsetof(struct tcphdr, check); | 928 | skb->csum_offset = offsetof(struct tcphdr, check); |
929 | } else { | 929 | } else { |
930 | th->check = csum_ipv6_magic(&np->saddr, &np->daddr, len, IPPROTO_TCP, | 930 | th->check = tcp_v6_check(skb->len, saddr, daddr, |
931 | csum_partial(th, th->doff<<2, | 931 | csum_partial(th, th->doff << 2, |
932 | skb->csum)); | 932 | skb->csum)); |
933 | } | 933 | } |
934 | } | 934 | } |
935 | 935 | ||
936 | static void tcp_v6_send_check(struct sock *sk, struct sk_buff *skb) | ||
937 | { | ||
938 | struct ipv6_pinfo *np = inet6_sk(sk); | ||
939 | |||
940 | __tcp_v6_send_check(skb, &np->saddr, &np->daddr); | ||
941 | } | ||
942 | |||
936 | static int tcp_v6_gso_send_check(struct sk_buff *skb) | 943 | static int tcp_v6_gso_send_check(struct sk_buff *skb) |
937 | { | 944 | { |
938 | struct ipv6hdr *ipv6h; | 945 | struct ipv6hdr *ipv6h; |
@@ -945,11 +952,8 @@ static int tcp_v6_gso_send_check(struct sk_buff *skb) | |||
945 | th = tcp_hdr(skb); | 952 | th = tcp_hdr(skb); |
946 | 953 | ||
947 | th->check = 0; | 954 | th->check = 0; |
948 | th->check = ~csum_ipv6_magic(&ipv6h->saddr, &ipv6h->daddr, skb->len, | ||
949 | IPPROTO_TCP, 0); | ||
950 | skb->csum_start = skb_transport_header(skb) - skb->head; | ||
951 | skb->csum_offset = offsetof(struct tcphdr, check); | ||
952 | skb->ip_summed = CHECKSUM_PARTIAL; | 955 | skb->ip_summed = CHECKSUM_PARTIAL; |
956 | __tcp_v6_send_check(skb, &ipv6h->saddr, &ipv6h->daddr); | ||
953 | return 0; | 957 | return 0; |
954 | } | 958 | } |
955 | 959 | ||
@@ -1052,9 +1056,7 @@ static void tcp_v6_send_response(struct sk_buff *skb, u32 seq, u32 ack, u32 win, | |||
1052 | ipv6_addr_copy(&fl.fl6_dst, &ipv6_hdr(skb)->saddr); | 1056 | ipv6_addr_copy(&fl.fl6_dst, &ipv6_hdr(skb)->saddr); |
1053 | ipv6_addr_copy(&fl.fl6_src, &ipv6_hdr(skb)->daddr); | 1057 | ipv6_addr_copy(&fl.fl6_src, &ipv6_hdr(skb)->daddr); |
1054 | 1058 | ||
1055 | t1->check = csum_ipv6_magic(&fl.fl6_src, &fl.fl6_dst, | 1059 | __tcp_v6_send_check(buff, &fl.fl6_src, &fl.fl6_dst); |
1056 | tot_len, IPPROTO_TCP, | ||
1057 | buff->csum); | ||
1058 | 1060 | ||
1059 | fl.proto = IPPROTO_TCP; | 1061 | fl.proto = IPPROTO_TCP; |
1060 | fl.oif = inet6_iif(skb); | 1062 | fl.oif = inet6_iif(skb); |
diff --git a/net/ipv6/tunnel6.c b/net/ipv6/tunnel6.c index e17bc1dfc1a4..fc3c86a47452 100644 --- a/net/ipv6/tunnel6.c +++ b/net/ipv6/tunnel6.c | |||
@@ -25,6 +25,7 @@ | |||
25 | #include <linux/mutex.h> | 25 | #include <linux/mutex.h> |
26 | #include <linux/netdevice.h> | 26 | #include <linux/netdevice.h> |
27 | #include <linux/skbuff.h> | 27 | #include <linux/skbuff.h> |
28 | #include <linux/slab.h> | ||
28 | #include <net/ipv6.h> | 29 | #include <net/ipv6.h> |
29 | #include <net/protocol.h> | 30 | #include <net/protocol.h> |
30 | #include <net/xfrm.h> | 31 | #include <net/xfrm.h> |
diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c index 3c0c9c755c92..90824852f598 100644 --- a/net/ipv6/udp.c +++ b/net/ipv6/udp.c | |||
@@ -34,6 +34,7 @@ | |||
34 | #include <linux/init.h> | 34 | #include <linux/init.h> |
35 | #include <linux/module.h> | 35 | #include <linux/module.h> |
36 | #include <linux/skbuff.h> | 36 | #include <linux/skbuff.h> |
37 | #include <linux/slab.h> | ||
37 | #include <asm/uaccess.h> | 38 | #include <asm/uaccess.h> |
38 | 39 | ||
39 | #include <net/ndisc.h> | 40 | #include <net/ndisc.h> |
@@ -258,8 +259,8 @@ static struct sock *__udp6_lib_lookup(struct net *net, | |||
258 | if (hslot->count < hslot2->count) | 259 | if (hslot->count < hslot2->count) |
259 | goto begin; | 260 | goto begin; |
260 | 261 | ||
261 | result = udp6_lib_lookup2(net, &in6addr_any, sport, | 262 | result = udp6_lib_lookup2(net, saddr, sport, |
262 | daddr, hnum, dif, | 263 | &in6addr_any, hnum, dif, |
263 | hslot2, slot2); | 264 | hslot2, slot2); |
264 | } | 265 | } |
265 | rcu_read_unlock(); | 266 | rcu_read_unlock(); |
diff --git a/net/ipv6/xfrm6_mode_tunnel.c b/net/ipv6/xfrm6_mode_tunnel.c index 3927832227b9..b809812c8d30 100644 --- a/net/ipv6/xfrm6_mode_tunnel.c +++ b/net/ipv6/xfrm6_mode_tunnel.c | |||
@@ -5,6 +5,7 @@ | |||
5 | * Copyright (c) 2004-2006 Herbert Xu <herbert@gondor.apana.org.au> | 5 | * Copyright (c) 2004-2006 Herbert Xu <herbert@gondor.apana.org.au> |
6 | */ | 6 | */ |
7 | 7 | ||
8 | #include <linux/gfp.h> | ||
8 | #include <linux/init.h> | 9 | #include <linux/init.h> |
9 | #include <linux/kernel.h> | 10 | #include <linux/kernel.h> |
10 | #include <linux/module.h> | 11 | #include <linux/module.h> |
diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c index ae181651c75a..8c452fd5ceae 100644 --- a/net/ipv6/xfrm6_policy.c +++ b/net/ipv6/xfrm6_policy.c | |||
@@ -67,36 +67,6 @@ static int xfrm6_get_saddr(struct net *net, | |||
67 | return 0; | 67 | return 0; |
68 | } | 68 | } |
69 | 69 | ||
70 | static struct dst_entry * | ||
71 | __xfrm6_find_bundle(struct flowi *fl, struct xfrm_policy *policy) | ||
72 | { | ||
73 | struct dst_entry *dst; | ||
74 | |||
75 | /* Still not clear if we should set fl->fl6_{src,dst}... */ | ||
76 | read_lock_bh(&policy->lock); | ||
77 | for (dst = policy->bundles; dst; dst = dst->next) { | ||
78 | struct xfrm_dst *xdst = (struct xfrm_dst*)dst; | ||
79 | struct in6_addr fl_dst_prefix, fl_src_prefix; | ||
80 | |||
81 | ipv6_addr_prefix(&fl_dst_prefix, | ||
82 | &fl->fl6_dst, | ||
83 | xdst->u.rt6.rt6i_dst.plen); | ||
84 | ipv6_addr_prefix(&fl_src_prefix, | ||
85 | &fl->fl6_src, | ||
86 | xdst->u.rt6.rt6i_src.plen); | ||
87 | if (ipv6_addr_equal(&xdst->u.rt6.rt6i_dst.addr, &fl_dst_prefix) && | ||
88 | ipv6_addr_equal(&xdst->u.rt6.rt6i_src.addr, &fl_src_prefix) && | ||
89 | xfrm_bundle_ok(policy, xdst, fl, AF_INET6, | ||
90 | (xdst->u.rt6.rt6i_dst.plen != 128 || | ||
91 | xdst->u.rt6.rt6i_src.plen != 128))) { | ||
92 | dst_clone(dst); | ||
93 | break; | ||
94 | } | ||
95 | } | ||
96 | read_unlock_bh(&policy->lock); | ||
97 | return dst; | ||
98 | } | ||
99 | |||
100 | static int xfrm6_get_tos(struct flowi *fl) | 70 | static int xfrm6_get_tos(struct flowi *fl) |
101 | { | 71 | { |
102 | return 0; | 72 | return 0; |
@@ -291,7 +261,6 @@ static struct xfrm_policy_afinfo xfrm6_policy_afinfo = { | |||
291 | .dst_ops = &xfrm6_dst_ops, | 261 | .dst_ops = &xfrm6_dst_ops, |
292 | .dst_lookup = xfrm6_dst_lookup, | 262 | .dst_lookup = xfrm6_dst_lookup, |
293 | .get_saddr = xfrm6_get_saddr, | 263 | .get_saddr = xfrm6_get_saddr, |
294 | .find_bundle = __xfrm6_find_bundle, | ||
295 | .decode_session = _decode_session6, | 264 | .decode_session = _decode_session6, |
296 | .get_tos = xfrm6_get_tos, | 265 | .get_tos = xfrm6_get_tos, |
297 | .init_path = xfrm6_init_path, | 266 | .init_path = xfrm6_init_path, |
diff --git a/net/ipv6/xfrm6_tunnel.c b/net/ipv6/xfrm6_tunnel.c index fa85a7d22dc4..2ce3a8278f26 100644 --- a/net/ipv6/xfrm6_tunnel.c +++ b/net/ipv6/xfrm6_tunnel.c | |||
@@ -23,6 +23,7 @@ | |||
23 | */ | 23 | */ |
24 | #include <linux/module.h> | 24 | #include <linux/module.h> |
25 | #include <linux/xfrm.h> | 25 | #include <linux/xfrm.h> |
26 | #include <linux/slab.h> | ||
26 | #include <linux/rculist.h> | 27 | #include <linux/rculist.h> |
27 | #include <net/ip.h> | 28 | #include <net/ip.h> |
28 | #include <net/xfrm.h> | 29 | #include <net/xfrm.h> |
diff --git a/net/ipx/af_ipx.c b/net/ipx/af_ipx.c index f9759b54a6de..da3d21c41d90 100644 --- a/net/ipx/af_ipx.c +++ b/net/ipx/af_ipx.c | |||
@@ -40,6 +40,7 @@ | |||
40 | #include <linux/net.h> | 40 | #include <linux/net.h> |
41 | #include <linux/netdevice.h> | 41 | #include <linux/netdevice.h> |
42 | #include <linux/uio.h> | 42 | #include <linux/uio.h> |
43 | #include <linux/slab.h> | ||
43 | #include <linux/skbuff.h> | 44 | #include <linux/skbuff.h> |
44 | #include <linux/smp_lock.h> | 45 | #include <linux/smp_lock.h> |
45 | #include <linux/socket.h> | 46 | #include <linux/socket.h> |
diff --git a/net/ipx/ipx_route.c b/net/ipx/ipx_route.c index e16c11423527..30f4519b092f 100644 --- a/net/ipx/ipx_route.c +++ b/net/ipx/ipx_route.c | |||
@@ -9,6 +9,7 @@ | |||
9 | 9 | ||
10 | #include <linux/list.h> | 10 | #include <linux/list.h> |
11 | #include <linux/route.h> | 11 | #include <linux/route.h> |
12 | #include <linux/slab.h> | ||
12 | #include <linux/spinlock.h> | 13 | #include <linux/spinlock.h> |
13 | 14 | ||
14 | #include <net/ipx.h> | 15 | #include <net/ipx.h> |
diff --git a/net/irda/af_irda.c b/net/irda/af_irda.c index 10093aab6173..2a4efcea3423 100644 --- a/net/irda/af_irda.c +++ b/net/irda/af_irda.c | |||
@@ -48,6 +48,7 @@ | |||
48 | #include <linux/smp_lock.h> | 48 | #include <linux/smp_lock.h> |
49 | #include <linux/socket.h> | 49 | #include <linux/socket.h> |
50 | #include <linux/sockios.h> | 50 | #include <linux/sockios.h> |
51 | #include <linux/slab.h> | ||
51 | #include <linux/init.h> | 52 | #include <linux/init.h> |
52 | #include <linux/net.h> | 53 | #include <linux/net.h> |
53 | #include <linux/irda.h> | 54 | #include <linux/irda.h> |
diff --git a/net/irda/discovery.c b/net/irda/discovery.c index a6f99b5a1499..c1c8ae939126 100644 --- a/net/irda/discovery.c +++ b/net/irda/discovery.c | |||
@@ -34,6 +34,7 @@ | |||
34 | #include <linux/socket.h> | 34 | #include <linux/socket.h> |
35 | #include <linux/fs.h> | 35 | #include <linux/fs.h> |
36 | #include <linux/seq_file.h> | 36 | #include <linux/seq_file.h> |
37 | #include <linux/slab.h> | ||
37 | 38 | ||
38 | #include <net/irda/irda.h> | 39 | #include <net/irda/irda.h> |
39 | #include <net/irda/irlmp.h> | 40 | #include <net/irda/irlmp.h> |
diff --git a/net/irda/ircomm/ircomm_core.c b/net/irda/ircomm/ircomm_core.c index 018c92941aba..e97082017f4f 100644 --- a/net/irda/ircomm/ircomm_core.c +++ b/net/irda/ircomm/ircomm_core.c | |||
@@ -33,6 +33,7 @@ | |||
33 | #include <linux/proc_fs.h> | 33 | #include <linux/proc_fs.h> |
34 | #include <linux/seq_file.h> | 34 | #include <linux/seq_file.h> |
35 | #include <linux/init.h> | 35 | #include <linux/init.h> |
36 | #include <linux/slab.h> | ||
36 | 37 | ||
37 | #include <net/irda/irda.h> | 38 | #include <net/irda/irda.h> |
38 | #include <net/irda/irmod.h> | 39 | #include <net/irda/irmod.h> |
diff --git a/net/irda/ircomm/ircomm_lmp.c b/net/irda/ircomm/ircomm_lmp.c index 7ba96618660e..08fb54dc8c41 100644 --- a/net/irda/ircomm/ircomm_lmp.c +++ b/net/irda/ircomm/ircomm_lmp.c | |||
@@ -31,6 +31,7 @@ | |||
31 | ********************************************************************/ | 31 | ********************************************************************/ |
32 | 32 | ||
33 | #include <linux/init.h> | 33 | #include <linux/init.h> |
34 | #include <linux/gfp.h> | ||
34 | 35 | ||
35 | #include <net/irda/irda.h> | 36 | #include <net/irda/irda.h> |
36 | #include <net/irda/irlmp.h> | 37 | #include <net/irda/irlmp.h> |
diff --git a/net/irda/ircomm/ircomm_param.c b/net/irda/ircomm/ircomm_param.c index d57aefd9fe77..8b915f3ac3b9 100644 --- a/net/irda/ircomm/ircomm_param.c +++ b/net/irda/ircomm/ircomm_param.c | |||
@@ -28,6 +28,7 @@ | |||
28 | * | 28 | * |
29 | ********************************************************************/ | 29 | ********************************************************************/ |
30 | 30 | ||
31 | #include <linux/gfp.h> | ||
31 | #include <linux/workqueue.h> | 32 | #include <linux/workqueue.h> |
32 | #include <linux/interrupt.h> | 33 | #include <linux/interrupt.h> |
33 | 34 | ||
@@ -474,7 +475,7 @@ static int ircomm_param_dce(void *instance, irda_param_t *param, int get) | |||
474 | /* Check if any of the settings have changed */ | 475 | /* Check if any of the settings have changed */ |
475 | if (dce & 0x0f) { | 476 | if (dce & 0x0f) { |
476 | if (dce & IRCOMM_DELTA_CTS) { | 477 | if (dce & IRCOMM_DELTA_CTS) { |
477 | IRDA_DEBUG(2, "%s(), CTS \n", __func__ ); | 478 | IRDA_DEBUG(2, "%s(), CTS\n", __func__ ); |
478 | } | 479 | } |
479 | } | 480 | } |
480 | 481 | ||
diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c index 8b85d774e47f..faa82ca2dfdc 100644 --- a/net/irda/ircomm/ircomm_tty.c +++ b/net/irda/ircomm/ircomm_tty.c | |||
@@ -33,6 +33,7 @@ | |||
33 | #include <linux/init.h> | 33 | #include <linux/init.h> |
34 | #include <linux/module.h> | 34 | #include <linux/module.h> |
35 | #include <linux/fs.h> | 35 | #include <linux/fs.h> |
36 | #include <linux/slab.h> | ||
36 | #include <linux/sched.h> | 37 | #include <linux/sched.h> |
37 | #include <linux/seq_file.h> | 38 | #include <linux/seq_file.h> |
38 | #include <linux/termios.h> | 39 | #include <linux/termios.h> |
diff --git a/net/irda/irda_device.c b/net/irda/irda_device.c index bf92e1473447..25cc2e695158 100644 --- a/net/irda/irda_device.c +++ b/net/irda/irda_device.c | |||
@@ -41,6 +41,7 @@ | |||
41 | #include <linux/tty.h> | 41 | #include <linux/tty.h> |
42 | #include <linux/kmod.h> | 42 | #include <linux/kmod.h> |
43 | #include <linux/spinlock.h> | 43 | #include <linux/spinlock.h> |
44 | #include <linux/slab.h> | ||
44 | 45 | ||
45 | #include <asm/ioctls.h> | 46 | #include <asm/ioctls.h> |
46 | #include <asm/uaccess.h> | 47 | #include <asm/uaccess.h> |
diff --git a/net/irda/iriap.c b/net/irda/iriap.c index 294e34d3517c..79a1e5a23e10 100644 --- a/net/irda/iriap.c +++ b/net/irda/iriap.c | |||
@@ -31,6 +31,7 @@ | |||
31 | #include <linux/string.h> | 31 | #include <linux/string.h> |
32 | #include <linux/init.h> | 32 | #include <linux/init.h> |
33 | #include <linux/seq_file.h> | 33 | #include <linux/seq_file.h> |
34 | #include <linux/slab.h> | ||
34 | 35 | ||
35 | #include <asm/byteorder.h> | 36 | #include <asm/byteorder.h> |
36 | #include <asm/unaligned.h> | 37 | #include <asm/unaligned.h> |
diff --git a/net/irda/iriap_event.c b/net/irda/iriap_event.c index a301cbd93785..703774e29e32 100644 --- a/net/irda/iriap_event.c +++ b/net/irda/iriap_event.c | |||
@@ -24,6 +24,8 @@ | |||
24 | * | 24 | * |
25 | ********************************************************************/ | 25 | ********************************************************************/ |
26 | 26 | ||
27 | #include <linux/slab.h> | ||
28 | |||
27 | #include <net/irda/irda.h> | 29 | #include <net/irda/irda.h> |
28 | #include <net/irda/irlmp.h> | 30 | #include <net/irda/irlmp.h> |
29 | #include <net/irda/iriap.h> | 31 | #include <net/irda/iriap.h> |
diff --git a/net/irda/irias_object.c b/net/irda/irias_object.c index 99ebb96f1386..f07ed9fd5792 100644 --- a/net/irda/irias_object.c +++ b/net/irda/irias_object.c | |||
@@ -22,6 +22,7 @@ | |||
22 | * | 22 | * |
23 | ********************************************************************/ | 23 | ********************************************************************/ |
24 | 24 | ||
25 | #include <linux/slab.h> | ||
25 | #include <linux/string.h> | 26 | #include <linux/string.h> |
26 | #include <linux/socket.h> | 27 | #include <linux/socket.h> |
27 | #include <linux/module.h> | 28 | #include <linux/module.h> |
diff --git a/net/irda/irlan/irlan_client.c b/net/irda/irlan/irlan_client.c index 42f7d960d055..7ed3af957935 100644 --- a/net/irda/irlan/irlan_client.c +++ b/net/irda/irlan/irlan_client.c | |||
@@ -28,6 +28,7 @@ | |||
28 | 28 | ||
29 | #include <linux/kernel.h> | 29 | #include <linux/kernel.h> |
30 | #include <linux/string.h> | 30 | #include <linux/string.h> |
31 | #include <linux/slab.h> | ||
31 | #include <linux/errno.h> | 32 | #include <linux/errno.h> |
32 | #include <linux/init.h> | 33 | #include <linux/init.h> |
33 | #include <linux/netdevice.h> | 34 | #include <linux/netdevice.h> |
diff --git a/net/irda/irlan/irlan_common.c b/net/irda/irlan/irlan_common.c index e486dc89ea59..a788f9e9427d 100644 --- a/net/irda/irlan/irlan_common.c +++ b/net/irda/irlan/irlan_common.c | |||
@@ -27,6 +27,7 @@ | |||
27 | 27 | ||
28 | #include <linux/kernel.h> | 28 | #include <linux/kernel.h> |
29 | #include <linux/string.h> | 29 | #include <linux/string.h> |
30 | #include <linux/gfp.h> | ||
30 | #include <linux/init.h> | 31 | #include <linux/init.h> |
31 | #include <linux/errno.h> | 32 | #include <linux/errno.h> |
32 | #include <linux/proc_fs.h> | 33 | #include <linux/proc_fs.h> |
diff --git a/net/irda/irlan/irlan_provider.c b/net/irda/irlan/irlan_provider.c index 3f81f81b2dfa..5cf5e6c872bb 100644 --- a/net/irda/irlan/irlan_provider.c +++ b/net/irda/irlan/irlan_provider.c | |||
@@ -34,6 +34,7 @@ | |||
34 | #include <linux/init.h> | 34 | #include <linux/init.h> |
35 | #include <linux/random.h> | 35 | #include <linux/random.h> |
36 | #include <linux/bitops.h> | 36 | #include <linux/bitops.h> |
37 | #include <linux/slab.h> | ||
37 | 38 | ||
38 | #include <asm/system.h> | 39 | #include <asm/system.h> |
39 | #include <asm/byteorder.h> | 40 | #include <asm/byteorder.h> |
diff --git a/net/irda/irlap_event.c b/net/irda/irlap_event.c index 94a9884d7146..d434c8880745 100644 --- a/net/irda/irlap_event.c +++ b/net/irda/irlap_event.c | |||
@@ -29,6 +29,7 @@ | |||
29 | #include <linux/kernel.h> | 29 | #include <linux/kernel.h> |
30 | #include <linux/delay.h> | 30 | #include <linux/delay.h> |
31 | #include <linux/skbuff.h> | 31 | #include <linux/skbuff.h> |
32 | #include <linux/slab.h> | ||
32 | 33 | ||
33 | #include <net/irda/irda.h> | 34 | #include <net/irda/irda.h> |
34 | #include <net/irda/irlap_event.h> | 35 | #include <net/irda/irlap_event.h> |
diff --git a/net/irda/irlap_frame.c b/net/irda/irlap_frame.c index 7af2e74deda8..688222cbf55b 100644 --- a/net/irda/irlap_frame.c +++ b/net/irda/irlap_frame.c | |||
@@ -29,6 +29,7 @@ | |||
29 | #include <linux/if_ether.h> | 29 | #include <linux/if_ether.h> |
30 | #include <linux/netdevice.h> | 30 | #include <linux/netdevice.h> |
31 | #include <linux/irda.h> | 31 | #include <linux/irda.h> |
32 | #include <linux/slab.h> | ||
32 | 33 | ||
33 | #include <net/pkt_sched.h> | 34 | #include <net/pkt_sched.h> |
34 | #include <net/sock.h> | 35 | #include <net/sock.h> |
diff --git a/net/irda/irnet/irnet_irda.c b/net/irda/irnet/irnet_irda.c index b26dee784aba..df18ab4b6c5e 100644 --- a/net/irda/irnet/irnet_irda.c +++ b/net/irda/irnet/irnet_irda.c | |||
@@ -11,6 +11,7 @@ | |||
11 | #include "irnet_irda.h" /* Private header */ | 11 | #include "irnet_irda.h" /* Private header */ |
12 | #include <linux/sched.h> | 12 | #include <linux/sched.h> |
13 | #include <linux/seq_file.h> | 13 | #include <linux/seq_file.h> |
14 | #include <linux/slab.h> | ||
14 | #include <asm/unaligned.h> | 15 | #include <asm/unaligned.h> |
15 | 16 | ||
16 | /* | 17 | /* |
diff --git a/net/irda/irnet/irnet_ppp.c b/net/irda/irnet/irnet_ppp.c index 6b3602de359a..6a1a202710c5 100644 --- a/net/irda/irnet/irnet_ppp.c +++ b/net/irda/irnet/irnet_ppp.c | |||
@@ -14,6 +14,7 @@ | |||
14 | */ | 14 | */ |
15 | 15 | ||
16 | #include <linux/sched.h> | 16 | #include <linux/sched.h> |
17 | #include <linux/slab.h> | ||
17 | #include <linux/smp_lock.h> | 18 | #include <linux/smp_lock.h> |
18 | #include "irnet_ppp.h" /* Private header */ | 19 | #include "irnet_ppp.h" /* Private header */ |
19 | /* Please put other headers in irnet.h - Thanks */ | 20 | /* Please put other headers in irnet.h - Thanks */ |
diff --git a/net/irda/irnetlink.c b/net/irda/irnetlink.c index 69b5b75f5431..6c7c4b92e4f8 100644 --- a/net/irda/irnetlink.c +++ b/net/irda/irnetlink.c | |||
@@ -15,6 +15,7 @@ | |||
15 | 15 | ||
16 | #include <linux/socket.h> | 16 | #include <linux/socket.h> |
17 | #include <linux/irda.h> | 17 | #include <linux/irda.h> |
18 | #include <linux/gfp.h> | ||
18 | #include <net/net_namespace.h> | 19 | #include <net/net_namespace.h> |
19 | #include <net/sock.h> | 20 | #include <net/sock.h> |
20 | #include <net/irda/irda.h> | 21 | #include <net/irda/irda.h> |
diff --git a/net/irda/irqueue.c b/net/irda/irqueue.c index ba01938becb5..849aaf0dabb5 100644 --- a/net/irda/irqueue.c +++ b/net/irda/irqueue.c | |||
@@ -192,6 +192,7 @@ | |||
192 | * Jean II | 192 | * Jean II |
193 | */ | 193 | */ |
194 | #include <linux/module.h> | 194 | #include <linux/module.h> |
195 | #include <linux/slab.h> | ||
195 | 196 | ||
196 | #include <net/irda/irda.h> | 197 | #include <net/irda/irda.h> |
197 | #include <net/irda/irqueue.h> | 198 | #include <net/irda/irqueue.h> |
diff --git a/net/irda/irttp.c b/net/irda/irttp.c index 9cb79f95bf63..47db1d8a0d92 100644 --- a/net/irda/irttp.c +++ b/net/irda/irttp.c | |||
@@ -28,6 +28,7 @@ | |||
28 | #include <linux/init.h> | 28 | #include <linux/init.h> |
29 | #include <linux/fs.h> | 29 | #include <linux/fs.h> |
30 | #include <linux/seq_file.h> | 30 | #include <linux/seq_file.h> |
31 | #include <linux/slab.h> | ||
31 | 32 | ||
32 | #include <asm/byteorder.h> | 33 | #include <asm/byteorder.h> |
33 | #include <asm/unaligned.h> | 34 | #include <asm/unaligned.h> |
diff --git a/net/key/af_key.c b/net/key/af_key.c index 368707882647..ba9a3fcc2fed 100644 --- a/net/key/af_key.c +++ b/net/key/af_key.c | |||
@@ -26,6 +26,7 @@ | |||
26 | #include <linux/in6.h> | 26 | #include <linux/in6.h> |
27 | #include <linux/proc_fs.h> | 27 | #include <linux/proc_fs.h> |
28 | #include <linux/init.h> | 28 | #include <linux/init.h> |
29 | #include <linux/slab.h> | ||
29 | #include <net/net_namespace.h> | 30 | #include <net/net_namespace.h> |
30 | #include <net/netns/generic.h> | 31 | #include <net/netns/generic.h> |
31 | #include <net/xfrm.h> | 32 | #include <net/xfrm.h> |
@@ -2129,10 +2130,9 @@ static int key_notify_policy(struct xfrm_policy *xp, int dir, struct km_event *c | |||
2129 | int err; | 2130 | int err; |
2130 | 2131 | ||
2131 | out_skb = pfkey_xfrm_policy2msg_prep(xp); | 2132 | out_skb = pfkey_xfrm_policy2msg_prep(xp); |
2132 | if (IS_ERR(out_skb)) { | 2133 | if (IS_ERR(out_skb)) |
2133 | err = PTR_ERR(out_skb); | 2134 | return PTR_ERR(out_skb); |
2134 | goto out; | 2135 | |
2135 | } | ||
2136 | err = pfkey_xfrm_policy2msg(out_skb, xp, dir); | 2136 | err = pfkey_xfrm_policy2msg(out_skb, xp, dir); |
2137 | if (err < 0) | 2137 | if (err < 0) |
2138 | return err; | 2138 | return err; |
@@ -2148,7 +2148,6 @@ static int key_notify_policy(struct xfrm_policy *xp, int dir, struct km_event *c | |||
2148 | out_hdr->sadb_msg_seq = c->seq; | 2148 | out_hdr->sadb_msg_seq = c->seq; |
2149 | out_hdr->sadb_msg_pid = c->pid; | 2149 | out_hdr->sadb_msg_pid = c->pid; |
2150 | pfkey_broadcast(out_skb, GFP_ATOMIC, BROADCAST_ALL, NULL, xp_net(xp)); | 2150 | pfkey_broadcast(out_skb, GFP_ATOMIC, BROADCAST_ALL, NULL, xp_net(xp)); |
2151 | out: | ||
2152 | return 0; | 2151 | return 0; |
2153 | 2152 | ||
2154 | } | 2153 | } |
diff --git a/net/l2tp/Kconfig b/net/l2tp/Kconfig new file mode 100644 index 000000000000..4b1e71751e10 --- /dev/null +++ b/net/l2tp/Kconfig | |||
@@ -0,0 +1,107 @@ | |||
1 | # | ||
2 | # Layer Two Tunneling Protocol (L2TP) | ||
3 | # | ||
4 | |||
5 | menuconfig L2TP | ||
6 | tristate "Layer Two Tunneling Protocol (L2TP)" | ||
7 | depends on INET | ||
8 | ---help--- | ||
9 | Layer Two Tunneling Protocol | ||
10 | |||
11 | From RFC 2661 <http://www.ietf.org/rfc/rfc2661.txt>. | ||
12 | |||
13 | L2TP facilitates the tunneling of packets across an | ||
14 | intervening network in a way that is as transparent as | ||
15 | possible to both end-users and applications. | ||
16 | |||
17 | L2TP is often used to tunnel PPP traffic over IP | ||
18 | tunnels. One IP tunnel may carry thousands of individual PPP | ||
19 | connections. L2TP is also used as a VPN protocol, popular | ||
20 | with home workers to connect to their offices. | ||
21 | |||
22 | L2TPv3 allows other protocols as well as PPP to be carried | ||
23 | over L2TP tunnels. L2TPv3 is defined in RFC 3931 | ||
24 | <http://www.ietf.org/rfc/rfc3931.txt>. | ||
25 | |||
26 | The kernel component handles only L2TP data packets: a | ||
27 | userland daemon handles L2TP the control protocol (tunnel | ||
28 | and session setup). One such daemon is OpenL2TP | ||
29 | (http://openl2tp.org/). | ||
30 | |||
31 | If you don't need L2TP, say N. To compile all L2TP code as | ||
32 | modules, choose M here. | ||
33 | |||
34 | config L2TP_DEBUGFS | ||
35 | tristate "L2TP debugfs support" | ||
36 | depends on L2TP && DEBUG_FS | ||
37 | help | ||
38 | Support for l2tp directory in debugfs filesystem. This may be | ||
39 | used to dump internal state of the l2tp drivers for problem | ||
40 | analysis. | ||
41 | |||
42 | If unsure, say 'Y'. | ||
43 | |||
44 | To compile this driver as a module, choose M here. The module | ||
45 | will be called l2tp_debugfs. | ||
46 | |||
47 | config L2TP_V3 | ||
48 | bool "L2TPv3 support (EXPERIMENTAL)" | ||
49 | depends on EXPERIMENTAL && L2TP | ||
50 | help | ||
51 | Layer Two Tunneling Protocol Version 3 | ||
52 | |||
53 | From RFC 3931 <http://www.ietf.org/rfc/rfc3931.txt>. | ||
54 | |||
55 | The Layer Two Tunneling Protocol (L2TP) provides a dynamic | ||
56 | mechanism for tunneling Layer 2 (L2) "circuits" across a | ||
57 | packet-oriented data network (e.g., over IP). L2TP, as | ||
58 | originally defined in RFC 2661, is a standard method for | ||
59 | tunneling Point-to-Point Protocol (PPP) [RFC1661] sessions. | ||
60 | L2TP has since been adopted for tunneling a number of other | ||
61 | L2 protocols, including ATM, Frame Relay, HDLC and even raw | ||
62 | ethernet frames. | ||
63 | |||
64 | If you are connecting to L2TPv3 equipment, or you want to | ||
65 | tunnel raw ethernet frames using L2TP, say Y here. If | ||
66 | unsure, say N. | ||
67 | |||
68 | config L2TP_IP | ||
69 | tristate "L2TP IP encapsulation for L2TPv3" | ||
70 | depends on L2TP_V3 | ||
71 | help | ||
72 | Support for L2TP-over-IP socket family. | ||
73 | |||
74 | The L2TPv3 protocol defines two possible encapsulations for | ||
75 | L2TP frames, namely UDP and plain IP (without UDP). This | ||
76 | driver provides a new L2TPIP socket family with which | ||
77 | userspace L2TPv3 daemons may create L2TP/IP tunnel sockets | ||
78 | when UDP encapsulation is not required. When L2TP is carried | ||
79 | in IP packets, it used IP protocol number 115, so this port | ||
80 | must be enabled in firewalls. | ||
81 | |||
82 | To compile this driver as a module, choose M here. The module | ||
83 | will be called l2tp_ip. | ||
84 | |||
85 | config L2TP_ETH | ||
86 | tristate "L2TP ethernet pseudowire support for L2TPv3" | ||
87 | depends on L2TP_V3 | ||
88 | help | ||
89 | Support for carrying raw ethernet frames over L2TPv3. | ||
90 | |||
91 | From RFC 4719 <http://www.ietf.org/rfc/rfc4719.txt>. | ||
92 | |||
93 | The Layer 2 Tunneling Protocol, Version 3 (L2TPv3) can be | ||
94 | used as a control protocol and for data encapsulation to set | ||
95 | up Pseudowires for transporting layer 2 Packet Data Units | ||
96 | across an IP network [RFC3931]. | ||
97 | |||
98 | This driver provides an ethernet virtual interface for each | ||
99 | L2TP ethernet pseudowire instance. Standard Linux tools may | ||
100 | be used to assign an IP address to the local virtual | ||
101 | interface, or add the interface to a bridge. | ||
102 | |||
103 | If you are using L2TPv3, you will almost certainly want to | ||
104 | enable this option. | ||
105 | |||
106 | To compile this driver as a module, choose M here. The module | ||
107 | will be called l2tp_eth. | ||
diff --git a/net/l2tp/Makefile b/net/l2tp/Makefile new file mode 100644 index 000000000000..110e7bc2de5e --- /dev/null +++ b/net/l2tp/Makefile | |||
@@ -0,0 +1,12 @@ | |||
1 | # | ||
2 | # Makefile for the L2TP. | ||
3 | # | ||
4 | |||
5 | obj-$(CONFIG_L2TP) += l2tp_core.o | ||
6 | |||
7 | # Build l2tp as modules if L2TP is M | ||
8 | obj-$(subst y,$(CONFIG_L2TP),$(CONFIG_PPPOL2TP)) += l2tp_ppp.o | ||
9 | obj-$(subst y,$(CONFIG_L2TP),$(CONFIG_L2TP_IP)) += l2tp_ip.o | ||
10 | obj-$(subst y,$(CONFIG_L2TP),$(CONFIG_L2TP_V3)) += l2tp_netlink.o | ||
11 | obj-$(subst y,$(CONFIG_L2TP),$(CONFIG_L2TP_ETH)) += l2tp_eth.o | ||
12 | obj-$(subst y,$(CONFIG_L2TP),$(CONFIG_L2TP_DEBUGFS)) += l2tp_debugfs.o | ||
diff --git a/net/l2tp/l2tp_core.c b/net/l2tp/l2tp_core.c new file mode 100644 index 000000000000..98dfcce1a5fc --- /dev/null +++ b/net/l2tp/l2tp_core.c | |||
@@ -0,0 +1,1692 @@ | |||
1 | /* | ||
2 | * L2TP core. | ||
3 | * | ||
4 | * Copyright (c) 2008,2009,2010 Katalix Systems Ltd | ||
5 | * | ||
6 | * This file contains some code of the original L2TPv2 pppol2tp | ||
7 | * driver, which has the following copyright: | ||
8 | * | ||
9 | * Authors: Martijn van Oosterhout <kleptog@svana.org> | ||
10 | * James Chapman (jchapman@katalix.com) | ||
11 | * Contributors: | ||
12 | * Michal Ostrowski <mostrows@speakeasy.net> | ||
13 | * Arnaldo Carvalho de Melo <acme@xconectiva.com.br> | ||
14 | * David S. Miller (davem@redhat.com) | ||
15 | * | ||
16 | * This program is free software; you can redistribute it and/or modify | ||
17 | * it under the terms of the GNU General Public License version 2 as | ||
18 | * published by the Free Software Foundation. | ||
19 | */ | ||
20 | |||
21 | #include <linux/module.h> | ||
22 | #include <linux/string.h> | ||
23 | #include <linux/list.h> | ||
24 | #include <linux/rculist.h> | ||
25 | #include <linux/uaccess.h> | ||
26 | |||
27 | #include <linux/kernel.h> | ||
28 | #include <linux/spinlock.h> | ||
29 | #include <linux/kthread.h> | ||
30 | #include <linux/sched.h> | ||
31 | #include <linux/slab.h> | ||
32 | #include <linux/errno.h> | ||
33 | #include <linux/jiffies.h> | ||
34 | |||
35 | #include <linux/netdevice.h> | ||
36 | #include <linux/net.h> | ||
37 | #include <linux/inetdevice.h> | ||
38 | #include <linux/skbuff.h> | ||
39 | #include <linux/init.h> | ||
40 | #include <linux/in.h> | ||
41 | #include <linux/ip.h> | ||
42 | #include <linux/udp.h> | ||
43 | #include <linux/l2tp.h> | ||
44 | #include <linux/hash.h> | ||
45 | #include <linux/sort.h> | ||
46 | #include <linux/file.h> | ||
47 | #include <linux/nsproxy.h> | ||
48 | #include <net/net_namespace.h> | ||
49 | #include <net/netns/generic.h> | ||
50 | #include <net/dst.h> | ||
51 | #include <net/ip.h> | ||
52 | #include <net/udp.h> | ||
53 | #include <net/inet_common.h> | ||
54 | #include <net/xfrm.h> | ||
55 | #include <net/protocol.h> | ||
56 | |||
57 | #include <asm/byteorder.h> | ||
58 | #include <asm/atomic.h> | ||
59 | |||
60 | #include "l2tp_core.h" | ||
61 | |||
62 | #define L2TP_DRV_VERSION "V2.0" | ||
63 | |||
64 | /* L2TP header constants */ | ||
65 | #define L2TP_HDRFLAG_T 0x8000 | ||
66 | #define L2TP_HDRFLAG_L 0x4000 | ||
67 | #define L2TP_HDRFLAG_S 0x0800 | ||
68 | #define L2TP_HDRFLAG_O 0x0200 | ||
69 | #define L2TP_HDRFLAG_P 0x0100 | ||
70 | |||
71 | #define L2TP_HDR_VER_MASK 0x000F | ||
72 | #define L2TP_HDR_VER_2 0x0002 | ||
73 | #define L2TP_HDR_VER_3 0x0003 | ||
74 | |||
75 | /* L2TPv3 default L2-specific sublayer */ | ||
76 | #define L2TP_SLFLAG_S 0x40000000 | ||
77 | #define L2TP_SL_SEQ_MASK 0x00ffffff | ||
78 | |||
79 | #define L2TP_HDR_SIZE_SEQ 10 | ||
80 | #define L2TP_HDR_SIZE_NOSEQ 6 | ||
81 | |||
82 | /* Default trace flags */ | ||
83 | #define L2TP_DEFAULT_DEBUG_FLAGS 0 | ||
84 | |||
85 | #define PRINTK(_mask, _type, _lvl, _fmt, args...) \ | ||
86 | do { \ | ||
87 | if ((_mask) & (_type)) \ | ||
88 | printk(_lvl "L2TP: " _fmt, ##args); \ | ||
89 | } while (0) | ||
90 | |||
91 | /* Private data stored for received packets in the skb. | ||
92 | */ | ||
93 | struct l2tp_skb_cb { | ||
94 | u32 ns; | ||
95 | u16 has_seq; | ||
96 | u16 length; | ||
97 | unsigned long expires; | ||
98 | }; | ||
99 | |||
100 | #define L2TP_SKB_CB(skb) ((struct l2tp_skb_cb *) &skb->cb[sizeof(struct inet_skb_parm)]) | ||
101 | |||
102 | static atomic_t l2tp_tunnel_count; | ||
103 | static atomic_t l2tp_session_count; | ||
104 | |||
105 | /* per-net private data for this module */ | ||
106 | static unsigned int l2tp_net_id; | ||
107 | struct l2tp_net { | ||
108 | struct list_head l2tp_tunnel_list; | ||
109 | spinlock_t l2tp_tunnel_list_lock; | ||
110 | struct hlist_head l2tp_session_hlist[L2TP_HASH_SIZE_2]; | ||
111 | spinlock_t l2tp_session_hlist_lock; | ||
112 | }; | ||
113 | |||
114 | static inline struct l2tp_net *l2tp_pernet(struct net *net) | ||
115 | { | ||
116 | BUG_ON(!net); | ||
117 | |||
118 | return net_generic(net, l2tp_net_id); | ||
119 | } | ||
120 | |||
121 | /* Session hash global list for L2TPv3. | ||
122 | * The session_id SHOULD be random according to RFC3931, but several | ||
123 | * L2TP implementations use incrementing session_ids. So we do a real | ||
124 | * hash on the session_id, rather than a simple bitmask. | ||
125 | */ | ||
126 | static inline struct hlist_head * | ||
127 | l2tp_session_id_hash_2(struct l2tp_net *pn, u32 session_id) | ||
128 | { | ||
129 | return &pn->l2tp_session_hlist[hash_32(session_id, L2TP_HASH_BITS_2)]; | ||
130 | |||
131 | } | ||
132 | |||
133 | /* Lookup a session by id in the global session list | ||
134 | */ | ||
135 | static struct l2tp_session *l2tp_session_find_2(struct net *net, u32 session_id) | ||
136 | { | ||
137 | struct l2tp_net *pn = l2tp_pernet(net); | ||
138 | struct hlist_head *session_list = | ||
139 | l2tp_session_id_hash_2(pn, session_id); | ||
140 | struct l2tp_session *session; | ||
141 | struct hlist_node *walk; | ||
142 | |||
143 | rcu_read_lock_bh(); | ||
144 | hlist_for_each_entry_rcu(session, walk, session_list, global_hlist) { | ||
145 | if (session->session_id == session_id) { | ||
146 | rcu_read_unlock_bh(); | ||
147 | return session; | ||
148 | } | ||
149 | } | ||
150 | rcu_read_unlock_bh(); | ||
151 | |||
152 | return NULL; | ||
153 | } | ||
154 | |||
155 | /* Session hash list. | ||
156 | * The session_id SHOULD be random according to RFC2661, but several | ||
157 | * L2TP implementations (Cisco and Microsoft) use incrementing | ||
158 | * session_ids. So we do a real hash on the session_id, rather than a | ||
159 | * simple bitmask. | ||
160 | */ | ||
161 | static inline struct hlist_head * | ||
162 | l2tp_session_id_hash(struct l2tp_tunnel *tunnel, u32 session_id) | ||
163 | { | ||
164 | return &tunnel->session_hlist[hash_32(session_id, L2TP_HASH_BITS)]; | ||
165 | } | ||
166 | |||
167 | /* Lookup a session by id | ||
168 | */ | ||
169 | struct l2tp_session *l2tp_session_find(struct net *net, struct l2tp_tunnel *tunnel, u32 session_id) | ||
170 | { | ||
171 | struct hlist_head *session_list; | ||
172 | struct l2tp_session *session; | ||
173 | struct hlist_node *walk; | ||
174 | |||
175 | /* In L2TPv3, session_ids are unique over all tunnels and we | ||
176 | * sometimes need to look them up before we know the | ||
177 | * tunnel. | ||
178 | */ | ||
179 | if (tunnel == NULL) | ||
180 | return l2tp_session_find_2(net, session_id); | ||
181 | |||
182 | session_list = l2tp_session_id_hash(tunnel, session_id); | ||
183 | read_lock_bh(&tunnel->hlist_lock); | ||
184 | hlist_for_each_entry(session, walk, session_list, hlist) { | ||
185 | if (session->session_id == session_id) { | ||
186 | read_unlock_bh(&tunnel->hlist_lock); | ||
187 | return session; | ||
188 | } | ||
189 | } | ||
190 | read_unlock_bh(&tunnel->hlist_lock); | ||
191 | |||
192 | return NULL; | ||
193 | } | ||
194 | EXPORT_SYMBOL_GPL(l2tp_session_find); | ||
195 | |||
196 | struct l2tp_session *l2tp_session_find_nth(struct l2tp_tunnel *tunnel, int nth) | ||
197 | { | ||
198 | int hash; | ||
199 | struct hlist_node *walk; | ||
200 | struct l2tp_session *session; | ||
201 | int count = 0; | ||
202 | |||
203 | read_lock_bh(&tunnel->hlist_lock); | ||
204 | for (hash = 0; hash < L2TP_HASH_SIZE; hash++) { | ||
205 | hlist_for_each_entry(session, walk, &tunnel->session_hlist[hash], hlist) { | ||
206 | if (++count > nth) { | ||
207 | read_unlock_bh(&tunnel->hlist_lock); | ||
208 | return session; | ||
209 | } | ||
210 | } | ||
211 | } | ||
212 | |||
213 | read_unlock_bh(&tunnel->hlist_lock); | ||
214 | |||
215 | return NULL; | ||
216 | } | ||
217 | EXPORT_SYMBOL_GPL(l2tp_session_find_nth); | ||
218 | |||
219 | /* Lookup a session by interface name. | ||
220 | * This is very inefficient but is only used by management interfaces. | ||
221 | */ | ||
222 | struct l2tp_session *l2tp_session_find_by_ifname(struct net *net, char *ifname) | ||
223 | { | ||
224 | struct l2tp_net *pn = l2tp_pernet(net); | ||
225 | int hash; | ||
226 | struct hlist_node *walk; | ||
227 | struct l2tp_session *session; | ||
228 | |||
229 | rcu_read_lock_bh(); | ||
230 | for (hash = 0; hash < L2TP_HASH_SIZE_2; hash++) { | ||
231 | hlist_for_each_entry_rcu(session, walk, &pn->l2tp_session_hlist[hash], global_hlist) { | ||
232 | if (!strcmp(session->ifname, ifname)) { | ||
233 | rcu_read_unlock_bh(); | ||
234 | return session; | ||
235 | } | ||
236 | } | ||
237 | } | ||
238 | |||
239 | rcu_read_unlock_bh(); | ||
240 | |||
241 | return NULL; | ||
242 | } | ||
243 | EXPORT_SYMBOL_GPL(l2tp_session_find_by_ifname); | ||
244 | |||
245 | /* Lookup a tunnel by id | ||
246 | */ | ||
247 | struct l2tp_tunnel *l2tp_tunnel_find(struct net *net, u32 tunnel_id) | ||
248 | { | ||
249 | struct l2tp_tunnel *tunnel; | ||
250 | struct l2tp_net *pn = l2tp_pernet(net); | ||
251 | |||
252 | rcu_read_lock_bh(); | ||
253 | list_for_each_entry_rcu(tunnel, &pn->l2tp_tunnel_list, list) { | ||
254 | if (tunnel->tunnel_id == tunnel_id) { | ||
255 | rcu_read_unlock_bh(); | ||
256 | return tunnel; | ||
257 | } | ||
258 | } | ||
259 | rcu_read_unlock_bh(); | ||
260 | |||
261 | return NULL; | ||
262 | } | ||
263 | EXPORT_SYMBOL_GPL(l2tp_tunnel_find); | ||
264 | |||
265 | struct l2tp_tunnel *l2tp_tunnel_find_nth(struct net *net, int nth) | ||
266 | { | ||
267 | struct l2tp_net *pn = l2tp_pernet(net); | ||
268 | struct l2tp_tunnel *tunnel; | ||
269 | int count = 0; | ||
270 | |||
271 | rcu_read_lock_bh(); | ||
272 | list_for_each_entry_rcu(tunnel, &pn->l2tp_tunnel_list, list) { | ||
273 | if (++count > nth) { | ||
274 | rcu_read_unlock_bh(); | ||
275 | return tunnel; | ||
276 | } | ||
277 | } | ||
278 | |||
279 | rcu_read_unlock_bh(); | ||
280 | |||
281 | return NULL; | ||
282 | } | ||
283 | EXPORT_SYMBOL_GPL(l2tp_tunnel_find_nth); | ||
284 | |||
285 | /***************************************************************************** | ||
286 | * Receive data handling | ||
287 | *****************************************************************************/ | ||
288 | |||
289 | /* Queue a skb in order. We come here only if the skb has an L2TP sequence | ||
290 | * number. | ||
291 | */ | ||
292 | static void l2tp_recv_queue_skb(struct l2tp_session *session, struct sk_buff *skb) | ||
293 | { | ||
294 | struct sk_buff *skbp; | ||
295 | struct sk_buff *tmp; | ||
296 | u32 ns = L2TP_SKB_CB(skb)->ns; | ||
297 | |||
298 | spin_lock_bh(&session->reorder_q.lock); | ||
299 | skb_queue_walk_safe(&session->reorder_q, skbp, tmp) { | ||
300 | if (L2TP_SKB_CB(skbp)->ns > ns) { | ||
301 | __skb_queue_before(&session->reorder_q, skbp, skb); | ||
302 | PRINTK(session->debug, L2TP_MSG_SEQ, KERN_DEBUG, | ||
303 | "%s: pkt %hu, inserted before %hu, reorder_q len=%d\n", | ||
304 | session->name, ns, L2TP_SKB_CB(skbp)->ns, | ||
305 | skb_queue_len(&session->reorder_q)); | ||
306 | session->stats.rx_oos_packets++; | ||
307 | goto out; | ||
308 | } | ||
309 | } | ||
310 | |||
311 | __skb_queue_tail(&session->reorder_q, skb); | ||
312 | |||
313 | out: | ||
314 | spin_unlock_bh(&session->reorder_q.lock); | ||
315 | } | ||
316 | |||
317 | /* Dequeue a single skb. | ||
318 | */ | ||
319 | static void l2tp_recv_dequeue_skb(struct l2tp_session *session, struct sk_buff *skb) | ||
320 | { | ||
321 | struct l2tp_tunnel *tunnel = session->tunnel; | ||
322 | int length = L2TP_SKB_CB(skb)->length; | ||
323 | |||
324 | /* We're about to requeue the skb, so return resources | ||
325 | * to its current owner (a socket receive buffer). | ||
326 | */ | ||
327 | skb_orphan(skb); | ||
328 | |||
329 | tunnel->stats.rx_packets++; | ||
330 | tunnel->stats.rx_bytes += length; | ||
331 | session->stats.rx_packets++; | ||
332 | session->stats.rx_bytes += length; | ||
333 | |||
334 | if (L2TP_SKB_CB(skb)->has_seq) { | ||
335 | /* Bump our Nr */ | ||
336 | session->nr++; | ||
337 | if (tunnel->version == L2TP_HDR_VER_2) | ||
338 | session->nr &= 0xffff; | ||
339 | else | ||
340 | session->nr &= 0xffffff; | ||
341 | |||
342 | PRINTK(session->debug, L2TP_MSG_SEQ, KERN_DEBUG, | ||
343 | "%s: updated nr to %hu\n", session->name, session->nr); | ||
344 | } | ||
345 | |||
346 | /* call private receive handler */ | ||
347 | if (session->recv_skb != NULL) | ||
348 | (*session->recv_skb)(session, skb, L2TP_SKB_CB(skb)->length); | ||
349 | else | ||
350 | kfree_skb(skb); | ||
351 | |||
352 | if (session->deref) | ||
353 | (*session->deref)(session); | ||
354 | } | ||
355 | |||
356 | /* Dequeue skbs from the session's reorder_q, subject to packet order. | ||
357 | * Skbs that have been in the queue for too long are simply discarded. | ||
358 | */ | ||
359 | static void l2tp_recv_dequeue(struct l2tp_session *session) | ||
360 | { | ||
361 | struct sk_buff *skb; | ||
362 | struct sk_buff *tmp; | ||
363 | |||
364 | /* If the pkt at the head of the queue has the nr that we | ||
365 | * expect to send up next, dequeue it and any other | ||
366 | * in-sequence packets behind it. | ||
367 | */ | ||
368 | spin_lock_bh(&session->reorder_q.lock); | ||
369 | skb_queue_walk_safe(&session->reorder_q, skb, tmp) { | ||
370 | if (time_after(jiffies, L2TP_SKB_CB(skb)->expires)) { | ||
371 | session->stats.rx_seq_discards++; | ||
372 | session->stats.rx_errors++; | ||
373 | PRINTK(session->debug, L2TP_MSG_SEQ, KERN_DEBUG, | ||
374 | "%s: oos pkt %u len %d discarded (too old), " | ||
375 | "waiting for %u, reorder_q_len=%d\n", | ||
376 | session->name, L2TP_SKB_CB(skb)->ns, | ||
377 | L2TP_SKB_CB(skb)->length, session->nr, | ||
378 | skb_queue_len(&session->reorder_q)); | ||
379 | __skb_unlink(skb, &session->reorder_q); | ||
380 | kfree_skb(skb); | ||
381 | if (session->deref) | ||
382 | (*session->deref)(session); | ||
383 | continue; | ||
384 | } | ||
385 | |||
386 | if (L2TP_SKB_CB(skb)->has_seq) { | ||
387 | if (L2TP_SKB_CB(skb)->ns != session->nr) { | ||
388 | PRINTK(session->debug, L2TP_MSG_SEQ, KERN_DEBUG, | ||
389 | "%s: holding oos pkt %u len %d, " | ||
390 | "waiting for %u, reorder_q_len=%d\n", | ||
391 | session->name, L2TP_SKB_CB(skb)->ns, | ||
392 | L2TP_SKB_CB(skb)->length, session->nr, | ||
393 | skb_queue_len(&session->reorder_q)); | ||
394 | goto out; | ||
395 | } | ||
396 | } | ||
397 | __skb_unlink(skb, &session->reorder_q); | ||
398 | |||
399 | /* Process the skb. We release the queue lock while we | ||
400 | * do so to let other contexts process the queue. | ||
401 | */ | ||
402 | spin_unlock_bh(&session->reorder_q.lock); | ||
403 | l2tp_recv_dequeue_skb(session, skb); | ||
404 | spin_lock_bh(&session->reorder_q.lock); | ||
405 | } | ||
406 | |||
407 | out: | ||
408 | spin_unlock_bh(&session->reorder_q.lock); | ||
409 | } | ||
410 | |||
411 | static inline int l2tp_verify_udp_checksum(struct sock *sk, | ||
412 | struct sk_buff *skb) | ||
413 | { | ||
414 | struct udphdr *uh = udp_hdr(skb); | ||
415 | u16 ulen = ntohs(uh->len); | ||
416 | struct inet_sock *inet; | ||
417 | __wsum psum; | ||
418 | |||
419 | if (sk->sk_no_check || skb_csum_unnecessary(skb) || !uh->check) | ||
420 | return 0; | ||
421 | |||
422 | inet = inet_sk(sk); | ||
423 | psum = csum_tcpudp_nofold(inet->inet_saddr, inet->inet_daddr, ulen, | ||
424 | IPPROTO_UDP, 0); | ||
425 | |||
426 | if ((skb->ip_summed == CHECKSUM_COMPLETE) && | ||
427 | !csum_fold(csum_add(psum, skb->csum))) | ||
428 | return 0; | ||
429 | |||
430 | skb->csum = psum; | ||
431 | |||
432 | return __skb_checksum_complete(skb); | ||
433 | } | ||
434 | |||
435 | /* Do receive processing of L2TP data frames. We handle both L2TPv2 | ||
436 | * and L2TPv3 data frames here. | ||
437 | * | ||
438 | * L2TPv2 Data Message Header | ||
439 | * | ||
440 | * 0 1 2 3 | ||
441 | * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 | ||
442 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
443 | * |T|L|x|x|S|x|O|P|x|x|x|x| Ver | Length (opt) | | ||
444 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
445 | * | Tunnel ID | Session ID | | ||
446 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
447 | * | Ns (opt) | Nr (opt) | | ||
448 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
449 | * | Offset Size (opt) | Offset pad... (opt) | ||
450 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
451 | * | ||
452 | * Data frames are marked by T=0. All other fields are the same as | ||
453 | * those in L2TP control frames. | ||
454 | * | ||
455 | * L2TPv3 Data Message Header | ||
456 | * | ||
457 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
458 | * | L2TP Session Header | | ||
459 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
460 | * | L2-Specific Sublayer | | ||
461 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
462 | * | Tunnel Payload ... | ||
463 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
464 | * | ||
465 | * L2TPv3 Session Header Over IP | ||
466 | * | ||
467 | * 0 1 2 3 | ||
468 | * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 | ||
469 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
470 | * | Session ID | | ||
471 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
472 | * | Cookie (optional, maximum 64 bits)... | ||
473 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
474 | * | | ||
475 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
476 | * | ||
477 | * L2TPv3 L2-Specific Sublayer Format | ||
478 | * | ||
479 | * 0 1 2 3 | ||
480 | * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 | ||
481 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
482 | * |x|S|x|x|x|x|x|x| Sequence Number | | ||
483 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
484 | * | ||
485 | * Cookie value, sublayer format and offset (pad) are negotiated with | ||
486 | * the peer when the session is set up. Unlike L2TPv2, we do not need | ||
487 | * to parse the packet header to determine if optional fields are | ||
488 | * present. | ||
489 | * | ||
490 | * Caller must already have parsed the frame and determined that it is | ||
491 | * a data (not control) frame before coming here. Fields up to the | ||
492 | * session-id have already been parsed and ptr points to the data | ||
493 | * after the session-id. | ||
494 | */ | ||
495 | void l2tp_recv_common(struct l2tp_session *session, struct sk_buff *skb, | ||
496 | unsigned char *ptr, unsigned char *optr, u16 hdrflags, | ||
497 | int length, int (*payload_hook)(struct sk_buff *skb)) | ||
498 | { | ||
499 | struct l2tp_tunnel *tunnel = session->tunnel; | ||
500 | int offset; | ||
501 | u32 ns, nr; | ||
502 | |||
503 | /* The ref count is increased since we now hold a pointer to | ||
504 | * the session. Take care to decrement the refcnt when exiting | ||
505 | * this function from now on... | ||
506 | */ | ||
507 | l2tp_session_inc_refcount(session); | ||
508 | if (session->ref) | ||
509 | (*session->ref)(session); | ||
510 | |||
511 | /* Parse and check optional cookie */ | ||
512 | if (session->peer_cookie_len > 0) { | ||
513 | if (memcmp(ptr, &session->peer_cookie[0], session->peer_cookie_len)) { | ||
514 | PRINTK(tunnel->debug, L2TP_MSG_DATA, KERN_INFO, | ||
515 | "%s: cookie mismatch (%u/%u). Discarding.\n", | ||
516 | tunnel->name, tunnel->tunnel_id, session->session_id); | ||
517 | session->stats.rx_cookie_discards++; | ||
518 | goto discard; | ||
519 | } | ||
520 | ptr += session->peer_cookie_len; | ||
521 | } | ||
522 | |||
523 | /* Handle the optional sequence numbers. Sequence numbers are | ||
524 | * in different places for L2TPv2 and L2TPv3. | ||
525 | * | ||
526 | * If we are the LAC, enable/disable sequence numbers under | ||
527 | * the control of the LNS. If no sequence numbers present but | ||
528 | * we were expecting them, discard frame. | ||
529 | */ | ||
530 | ns = nr = 0; | ||
531 | L2TP_SKB_CB(skb)->has_seq = 0; | ||
532 | if (tunnel->version == L2TP_HDR_VER_2) { | ||
533 | if (hdrflags & L2TP_HDRFLAG_S) { | ||
534 | ns = ntohs(*(__be16 *) ptr); | ||
535 | ptr += 2; | ||
536 | nr = ntohs(*(__be16 *) ptr); | ||
537 | ptr += 2; | ||
538 | |||
539 | /* Store L2TP info in the skb */ | ||
540 | L2TP_SKB_CB(skb)->ns = ns; | ||
541 | L2TP_SKB_CB(skb)->has_seq = 1; | ||
542 | |||
543 | PRINTK(session->debug, L2TP_MSG_SEQ, KERN_DEBUG, | ||
544 | "%s: recv data ns=%u, nr=%u, session nr=%u\n", | ||
545 | session->name, ns, nr, session->nr); | ||
546 | } | ||
547 | } else if (session->l2specific_type == L2TP_L2SPECTYPE_DEFAULT) { | ||
548 | u32 l2h = ntohl(*(__be32 *) ptr); | ||
549 | |||
550 | if (l2h & 0x40000000) { | ||
551 | ns = l2h & 0x00ffffff; | ||
552 | |||
553 | /* Store L2TP info in the skb */ | ||
554 | L2TP_SKB_CB(skb)->ns = ns; | ||
555 | L2TP_SKB_CB(skb)->has_seq = 1; | ||
556 | |||
557 | PRINTK(session->debug, L2TP_MSG_SEQ, KERN_DEBUG, | ||
558 | "%s: recv data ns=%u, session nr=%u\n", | ||
559 | session->name, ns, session->nr); | ||
560 | } | ||
561 | } | ||
562 | |||
563 | /* Advance past L2-specific header, if present */ | ||
564 | ptr += session->l2specific_len; | ||
565 | |||
566 | if (L2TP_SKB_CB(skb)->has_seq) { | ||
567 | /* Received a packet with sequence numbers. If we're the LNS, | ||
568 | * check if we sre sending sequence numbers and if not, | ||
569 | * configure it so. | ||
570 | */ | ||
571 | if ((!session->lns_mode) && (!session->send_seq)) { | ||
572 | PRINTK(session->debug, L2TP_MSG_SEQ, KERN_INFO, | ||
573 | "%s: requested to enable seq numbers by LNS\n", | ||
574 | session->name); | ||
575 | session->send_seq = -1; | ||
576 | l2tp_session_set_header_len(session, tunnel->version); | ||
577 | } | ||
578 | } else { | ||
579 | /* No sequence numbers. | ||
580 | * If user has configured mandatory sequence numbers, discard. | ||
581 | */ | ||
582 | if (session->recv_seq) { | ||
583 | PRINTK(session->debug, L2TP_MSG_SEQ, KERN_WARNING, | ||
584 | "%s: recv data has no seq numbers when required. " | ||
585 | "Discarding\n", session->name); | ||
586 | session->stats.rx_seq_discards++; | ||
587 | goto discard; | ||
588 | } | ||
589 | |||
590 | /* If we're the LAC and we're sending sequence numbers, the | ||
591 | * LNS has requested that we no longer send sequence numbers. | ||
592 | * If we're the LNS and we're sending sequence numbers, the | ||
593 | * LAC is broken. Discard the frame. | ||
594 | */ | ||
595 | if ((!session->lns_mode) && (session->send_seq)) { | ||
596 | PRINTK(session->debug, L2TP_MSG_SEQ, KERN_INFO, | ||
597 | "%s: requested to disable seq numbers by LNS\n", | ||
598 | session->name); | ||
599 | session->send_seq = 0; | ||
600 | l2tp_session_set_header_len(session, tunnel->version); | ||
601 | } else if (session->send_seq) { | ||
602 | PRINTK(session->debug, L2TP_MSG_SEQ, KERN_WARNING, | ||
603 | "%s: recv data has no seq numbers when required. " | ||
604 | "Discarding\n", session->name); | ||
605 | session->stats.rx_seq_discards++; | ||
606 | goto discard; | ||
607 | } | ||
608 | } | ||
609 | |||
610 | /* Session data offset is handled differently for L2TPv2 and | ||
611 | * L2TPv3. For L2TPv2, there is an optional 16-bit value in | ||
612 | * the header. For L2TPv3, the offset is negotiated using AVPs | ||
613 | * in the session setup control protocol. | ||
614 | */ | ||
615 | if (tunnel->version == L2TP_HDR_VER_2) { | ||
616 | /* If offset bit set, skip it. */ | ||
617 | if (hdrflags & L2TP_HDRFLAG_O) { | ||
618 | offset = ntohs(*(__be16 *)ptr); | ||
619 | ptr += 2 + offset; | ||
620 | } | ||
621 | } else | ||
622 | ptr += session->offset; | ||
623 | |||
624 | offset = ptr - optr; | ||
625 | if (!pskb_may_pull(skb, offset)) | ||
626 | goto discard; | ||
627 | |||
628 | __skb_pull(skb, offset); | ||
629 | |||
630 | /* If caller wants to process the payload before we queue the | ||
631 | * packet, do so now. | ||
632 | */ | ||
633 | if (payload_hook) | ||
634 | if ((*payload_hook)(skb)) | ||
635 | goto discard; | ||
636 | |||
637 | /* Prepare skb for adding to the session's reorder_q. Hold | ||
638 | * packets for max reorder_timeout or 1 second if not | ||
639 | * reordering. | ||
640 | */ | ||
641 | L2TP_SKB_CB(skb)->length = length; | ||
642 | L2TP_SKB_CB(skb)->expires = jiffies + | ||
643 | (session->reorder_timeout ? session->reorder_timeout : HZ); | ||
644 | |||
645 | /* Add packet to the session's receive queue. Reordering is done here, if | ||
646 | * enabled. Saved L2TP protocol info is stored in skb->sb[]. | ||
647 | */ | ||
648 | if (L2TP_SKB_CB(skb)->has_seq) { | ||
649 | if (session->reorder_timeout != 0) { | ||
650 | /* Packet reordering enabled. Add skb to session's | ||
651 | * reorder queue, in order of ns. | ||
652 | */ | ||
653 | l2tp_recv_queue_skb(session, skb); | ||
654 | } else { | ||
655 | /* Packet reordering disabled. Discard out-of-sequence | ||
656 | * packets | ||
657 | */ | ||
658 | if (L2TP_SKB_CB(skb)->ns != session->nr) { | ||
659 | session->stats.rx_seq_discards++; | ||
660 | PRINTK(session->debug, L2TP_MSG_SEQ, KERN_DEBUG, | ||
661 | "%s: oos pkt %u len %d discarded, " | ||
662 | "waiting for %u, reorder_q_len=%d\n", | ||
663 | session->name, L2TP_SKB_CB(skb)->ns, | ||
664 | L2TP_SKB_CB(skb)->length, session->nr, | ||
665 | skb_queue_len(&session->reorder_q)); | ||
666 | goto discard; | ||
667 | } | ||
668 | skb_queue_tail(&session->reorder_q, skb); | ||
669 | } | ||
670 | } else { | ||
671 | /* No sequence numbers. Add the skb to the tail of the | ||
672 | * reorder queue. This ensures that it will be | ||
673 | * delivered after all previous sequenced skbs. | ||
674 | */ | ||
675 | skb_queue_tail(&session->reorder_q, skb); | ||
676 | } | ||
677 | |||
678 | /* Try to dequeue as many skbs from reorder_q as we can. */ | ||
679 | l2tp_recv_dequeue(session); | ||
680 | |||
681 | l2tp_session_dec_refcount(session); | ||
682 | |||
683 | return; | ||
684 | |||
685 | discard: | ||
686 | session->stats.rx_errors++; | ||
687 | kfree_skb(skb); | ||
688 | |||
689 | if (session->deref) | ||
690 | (*session->deref)(session); | ||
691 | |||
692 | l2tp_session_dec_refcount(session); | ||
693 | } | ||
694 | EXPORT_SYMBOL(l2tp_recv_common); | ||
695 | |||
696 | /* Internal UDP receive frame. Do the real work of receiving an L2TP data frame | ||
697 | * here. The skb is not on a list when we get here. | ||
698 | * Returns 0 if the packet was a data packet and was successfully passed on. | ||
699 | * Returns 1 if the packet was not a good data packet and could not be | ||
700 | * forwarded. All such packets are passed up to userspace to deal with. | ||
701 | */ | ||
702 | int l2tp_udp_recv_core(struct l2tp_tunnel *tunnel, struct sk_buff *skb, | ||
703 | int (*payload_hook)(struct sk_buff *skb)) | ||
704 | { | ||
705 | struct l2tp_session *session = NULL; | ||
706 | unsigned char *ptr, *optr; | ||
707 | u16 hdrflags; | ||
708 | u32 tunnel_id, session_id; | ||
709 | int offset; | ||
710 | u16 version; | ||
711 | int length; | ||
712 | |||
713 | if (tunnel->sock && l2tp_verify_udp_checksum(tunnel->sock, skb)) | ||
714 | goto discard_bad_csum; | ||
715 | |||
716 | /* UDP always verifies the packet length. */ | ||
717 | __skb_pull(skb, sizeof(struct udphdr)); | ||
718 | |||
719 | /* Short packet? */ | ||
720 | if (!pskb_may_pull(skb, L2TP_HDR_SIZE_SEQ)) { | ||
721 | PRINTK(tunnel->debug, L2TP_MSG_DATA, KERN_INFO, | ||
722 | "%s: recv short packet (len=%d)\n", tunnel->name, skb->len); | ||
723 | goto error; | ||
724 | } | ||
725 | |||
726 | /* Point to L2TP header */ | ||
727 | optr = ptr = skb->data; | ||
728 | |||
729 | /* Trace packet contents, if enabled */ | ||
730 | if (tunnel->debug & L2TP_MSG_DATA) { | ||
731 | length = min(32u, skb->len); | ||
732 | if (!pskb_may_pull(skb, length)) | ||
733 | goto error; | ||
734 | |||
735 | printk(KERN_DEBUG "%s: recv: ", tunnel->name); | ||
736 | |||
737 | offset = 0; | ||
738 | do { | ||
739 | printk(" %02X", ptr[offset]); | ||
740 | } while (++offset < length); | ||
741 | |||
742 | printk("\n"); | ||
743 | } | ||
744 | |||
745 | /* Get L2TP header flags */ | ||
746 | hdrflags = ntohs(*(__be16 *) ptr); | ||
747 | |||
748 | /* Check protocol version */ | ||
749 | version = hdrflags & L2TP_HDR_VER_MASK; | ||
750 | if (version != tunnel->version) { | ||
751 | PRINTK(tunnel->debug, L2TP_MSG_DATA, KERN_INFO, | ||
752 | "%s: recv protocol version mismatch: got %d expected %d\n", | ||
753 | tunnel->name, version, tunnel->version); | ||
754 | goto error; | ||
755 | } | ||
756 | |||
757 | /* Get length of L2TP packet */ | ||
758 | length = skb->len; | ||
759 | |||
760 | /* If type is control packet, it is handled by userspace. */ | ||
761 | if (hdrflags & L2TP_HDRFLAG_T) { | ||
762 | PRINTK(tunnel->debug, L2TP_MSG_DATA, KERN_DEBUG, | ||
763 | "%s: recv control packet, len=%d\n", tunnel->name, length); | ||
764 | goto error; | ||
765 | } | ||
766 | |||
767 | /* Skip flags */ | ||
768 | ptr += 2; | ||
769 | |||
770 | if (tunnel->version == L2TP_HDR_VER_2) { | ||
771 | /* If length is present, skip it */ | ||
772 | if (hdrflags & L2TP_HDRFLAG_L) | ||
773 | ptr += 2; | ||
774 | |||
775 | /* Extract tunnel and session ID */ | ||
776 | tunnel_id = ntohs(*(__be16 *) ptr); | ||
777 | ptr += 2; | ||
778 | session_id = ntohs(*(__be16 *) ptr); | ||
779 | ptr += 2; | ||
780 | } else { | ||
781 | ptr += 2; /* skip reserved bits */ | ||
782 | tunnel_id = tunnel->tunnel_id; | ||
783 | session_id = ntohl(*(__be32 *) ptr); | ||
784 | ptr += 4; | ||
785 | } | ||
786 | |||
787 | /* Find the session context */ | ||
788 | session = l2tp_session_find(tunnel->l2tp_net, tunnel, session_id); | ||
789 | if (!session || !session->recv_skb) { | ||
790 | /* Not found? Pass to userspace to deal with */ | ||
791 | PRINTK(tunnel->debug, L2TP_MSG_DATA, KERN_INFO, | ||
792 | "%s: no session found (%u/%u). Passing up.\n", | ||
793 | tunnel->name, tunnel_id, session_id); | ||
794 | goto error; | ||
795 | } | ||
796 | |||
797 | l2tp_recv_common(session, skb, ptr, optr, hdrflags, length, payload_hook); | ||
798 | |||
799 | return 0; | ||
800 | |||
801 | discard_bad_csum: | ||
802 | LIMIT_NETDEBUG("%s: UDP: bad checksum\n", tunnel->name); | ||
803 | UDP_INC_STATS_USER(tunnel->l2tp_net, UDP_MIB_INERRORS, 0); | ||
804 | tunnel->stats.rx_errors++; | ||
805 | kfree_skb(skb); | ||
806 | |||
807 | return 0; | ||
808 | |||
809 | error: | ||
810 | /* Put UDP header back */ | ||
811 | __skb_push(skb, sizeof(struct udphdr)); | ||
812 | |||
813 | return 1; | ||
814 | } | ||
815 | EXPORT_SYMBOL_GPL(l2tp_udp_recv_core); | ||
816 | |||
817 | /* UDP encapsulation receive handler. See net/ipv4/udp.c. | ||
818 | * Return codes: | ||
819 | * 0 : success. | ||
820 | * <0: error | ||
821 | * >0: skb should be passed up to userspace as UDP. | ||
822 | */ | ||
823 | int l2tp_udp_encap_recv(struct sock *sk, struct sk_buff *skb) | ||
824 | { | ||
825 | struct l2tp_tunnel *tunnel; | ||
826 | |||
827 | tunnel = l2tp_sock_to_tunnel(sk); | ||
828 | if (tunnel == NULL) | ||
829 | goto pass_up; | ||
830 | |||
831 | PRINTK(tunnel->debug, L2TP_MSG_DATA, KERN_DEBUG, | ||
832 | "%s: received %d bytes\n", tunnel->name, skb->len); | ||
833 | |||
834 | if (l2tp_udp_recv_core(tunnel, skb, tunnel->recv_payload_hook)) | ||
835 | goto pass_up_put; | ||
836 | |||
837 | sock_put(sk); | ||
838 | return 0; | ||
839 | |||
840 | pass_up_put: | ||
841 | sock_put(sk); | ||
842 | pass_up: | ||
843 | return 1; | ||
844 | } | ||
845 | EXPORT_SYMBOL_GPL(l2tp_udp_encap_recv); | ||
846 | |||
847 | /************************************************************************ | ||
848 | * Transmit handling | ||
849 | ***********************************************************************/ | ||
850 | |||
851 | /* Build an L2TP header for the session into the buffer provided. | ||
852 | */ | ||
853 | static int l2tp_build_l2tpv2_header(struct l2tp_session *session, void *buf) | ||
854 | { | ||
855 | struct l2tp_tunnel *tunnel = session->tunnel; | ||
856 | __be16 *bufp = buf; | ||
857 | __be16 *optr = buf; | ||
858 | u16 flags = L2TP_HDR_VER_2; | ||
859 | u32 tunnel_id = tunnel->peer_tunnel_id; | ||
860 | u32 session_id = session->peer_session_id; | ||
861 | |||
862 | if (session->send_seq) | ||
863 | flags |= L2TP_HDRFLAG_S; | ||
864 | |||
865 | /* Setup L2TP header. */ | ||
866 | *bufp++ = htons(flags); | ||
867 | *bufp++ = htons(tunnel_id); | ||
868 | *bufp++ = htons(session_id); | ||
869 | if (session->send_seq) { | ||
870 | *bufp++ = htons(session->ns); | ||
871 | *bufp++ = 0; | ||
872 | session->ns++; | ||
873 | session->ns &= 0xffff; | ||
874 | PRINTK(session->debug, L2TP_MSG_SEQ, KERN_DEBUG, | ||
875 | "%s: updated ns to %u\n", session->name, session->ns); | ||
876 | } | ||
877 | |||
878 | return bufp - optr; | ||
879 | } | ||
880 | |||
881 | static int l2tp_build_l2tpv3_header(struct l2tp_session *session, void *buf) | ||
882 | { | ||
883 | struct l2tp_tunnel *tunnel = session->tunnel; | ||
884 | char *bufp = buf; | ||
885 | char *optr = bufp; | ||
886 | |||
887 | /* Setup L2TP header. The header differs slightly for UDP and | ||
888 | * IP encapsulations. For UDP, there is 4 bytes of flags. | ||
889 | */ | ||
890 | if (tunnel->encap == L2TP_ENCAPTYPE_UDP) { | ||
891 | u16 flags = L2TP_HDR_VER_3; | ||
892 | *((__be16 *) bufp) = htons(flags); | ||
893 | bufp += 2; | ||
894 | *((__be16 *) bufp) = 0; | ||
895 | bufp += 2; | ||
896 | } | ||
897 | |||
898 | *((__be32 *) bufp) = htonl(session->peer_session_id); | ||
899 | bufp += 4; | ||
900 | if (session->cookie_len) { | ||
901 | memcpy(bufp, &session->cookie[0], session->cookie_len); | ||
902 | bufp += session->cookie_len; | ||
903 | } | ||
904 | if (session->l2specific_len) { | ||
905 | if (session->l2specific_type == L2TP_L2SPECTYPE_DEFAULT) { | ||
906 | u32 l2h = 0; | ||
907 | if (session->send_seq) { | ||
908 | l2h = 0x40000000 | session->ns; | ||
909 | session->ns++; | ||
910 | session->ns &= 0xffffff; | ||
911 | PRINTK(session->debug, L2TP_MSG_SEQ, KERN_DEBUG, | ||
912 | "%s: updated ns to %u\n", session->name, session->ns); | ||
913 | } | ||
914 | |||
915 | *((__be32 *) bufp) = htonl(l2h); | ||
916 | } | ||
917 | bufp += session->l2specific_len; | ||
918 | } | ||
919 | if (session->offset) | ||
920 | bufp += session->offset; | ||
921 | |||
922 | return bufp - optr; | ||
923 | } | ||
924 | |||
925 | int l2tp_xmit_core(struct l2tp_session *session, struct sk_buff *skb, size_t data_len) | ||
926 | { | ||
927 | struct l2tp_tunnel *tunnel = session->tunnel; | ||
928 | unsigned int len = skb->len; | ||
929 | int error; | ||
930 | |||
931 | /* Debug */ | ||
932 | if (session->send_seq) | ||
933 | PRINTK(session->debug, L2TP_MSG_DATA, KERN_DEBUG, | ||
934 | "%s: send %Zd bytes, ns=%u\n", session->name, | ||
935 | data_len, session->ns - 1); | ||
936 | else | ||
937 | PRINTK(session->debug, L2TP_MSG_DATA, KERN_DEBUG, | ||
938 | "%s: send %Zd bytes\n", session->name, data_len); | ||
939 | |||
940 | if (session->debug & L2TP_MSG_DATA) { | ||
941 | int i; | ||
942 | int uhlen = (tunnel->encap == L2TP_ENCAPTYPE_UDP) ? sizeof(struct udphdr) : 0; | ||
943 | unsigned char *datap = skb->data + uhlen; | ||
944 | |||
945 | printk(KERN_DEBUG "%s: xmit:", session->name); | ||
946 | for (i = 0; i < (len - uhlen); i++) { | ||
947 | printk(" %02X", *datap++); | ||
948 | if (i == 31) { | ||
949 | printk(" ..."); | ||
950 | break; | ||
951 | } | ||
952 | } | ||
953 | printk("\n"); | ||
954 | } | ||
955 | |||
956 | /* Queue the packet to IP for output */ | ||
957 | error = ip_queue_xmit(skb, 1); | ||
958 | |||
959 | /* Update stats */ | ||
960 | if (error >= 0) { | ||
961 | tunnel->stats.tx_packets++; | ||
962 | tunnel->stats.tx_bytes += len; | ||
963 | session->stats.tx_packets++; | ||
964 | session->stats.tx_bytes += len; | ||
965 | } else { | ||
966 | tunnel->stats.tx_errors++; | ||
967 | session->stats.tx_errors++; | ||
968 | } | ||
969 | |||
970 | return 0; | ||
971 | } | ||
972 | EXPORT_SYMBOL_GPL(l2tp_xmit_core); | ||
973 | |||
974 | /* Automatically called when the skb is freed. | ||
975 | */ | ||
976 | static void l2tp_sock_wfree(struct sk_buff *skb) | ||
977 | { | ||
978 | sock_put(skb->sk); | ||
979 | } | ||
980 | |||
981 | /* For data skbs that we transmit, we associate with the tunnel socket | ||
982 | * but don't do accounting. | ||
983 | */ | ||
984 | static inline void l2tp_skb_set_owner_w(struct sk_buff *skb, struct sock *sk) | ||
985 | { | ||
986 | sock_hold(sk); | ||
987 | skb->sk = sk; | ||
988 | skb->destructor = l2tp_sock_wfree; | ||
989 | } | ||
990 | |||
991 | /* If caller requires the skb to have a ppp header, the header must be | ||
992 | * inserted in the skb data before calling this function. | ||
993 | */ | ||
994 | int l2tp_xmit_skb(struct l2tp_session *session, struct sk_buff *skb, int hdr_len) | ||
995 | { | ||
996 | int data_len = skb->len; | ||
997 | struct l2tp_tunnel *tunnel = session->tunnel; | ||
998 | struct sock *sk = tunnel->sock; | ||
999 | struct udphdr *uh; | ||
1000 | struct inet_sock *inet; | ||
1001 | __wsum csum; | ||
1002 | int old_headroom; | ||
1003 | int new_headroom; | ||
1004 | int headroom; | ||
1005 | int uhlen = (tunnel->encap == L2TP_ENCAPTYPE_UDP) ? sizeof(struct udphdr) : 0; | ||
1006 | int udp_len; | ||
1007 | |||
1008 | /* Check that there's enough headroom in the skb to insert IP, | ||
1009 | * UDP and L2TP headers. If not enough, expand it to | ||
1010 | * make room. Adjust truesize. | ||
1011 | */ | ||
1012 | headroom = NET_SKB_PAD + sizeof(struct iphdr) + | ||
1013 | uhlen + hdr_len; | ||
1014 | old_headroom = skb_headroom(skb); | ||
1015 | if (skb_cow_head(skb, headroom)) | ||
1016 | goto abort; | ||
1017 | |||
1018 | new_headroom = skb_headroom(skb); | ||
1019 | skb_orphan(skb); | ||
1020 | skb->truesize += new_headroom - old_headroom; | ||
1021 | |||
1022 | /* Setup L2TP header */ | ||
1023 | session->build_header(session, __skb_push(skb, hdr_len)); | ||
1024 | |||
1025 | /* Reset skb netfilter state */ | ||
1026 | memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt)); | ||
1027 | IPCB(skb)->flags &= ~(IPSKB_XFRM_TUNNEL_SIZE | IPSKB_XFRM_TRANSFORMED | | ||
1028 | IPSKB_REROUTED); | ||
1029 | nf_reset(skb); | ||
1030 | |||
1031 | /* Get routing info from the tunnel socket */ | ||
1032 | skb_dst_drop(skb); | ||
1033 | skb_dst_set(skb, dst_clone(__sk_dst_get(sk))); | ||
1034 | |||
1035 | switch (tunnel->encap) { | ||
1036 | case L2TP_ENCAPTYPE_UDP: | ||
1037 | /* Setup UDP header */ | ||
1038 | inet = inet_sk(sk); | ||
1039 | __skb_push(skb, sizeof(*uh)); | ||
1040 | skb_reset_transport_header(skb); | ||
1041 | uh = udp_hdr(skb); | ||
1042 | uh->source = inet->inet_sport; | ||
1043 | uh->dest = inet->inet_dport; | ||
1044 | udp_len = uhlen + hdr_len + data_len; | ||
1045 | uh->len = htons(udp_len); | ||
1046 | uh->check = 0; | ||
1047 | |||
1048 | /* Calculate UDP checksum if configured to do so */ | ||
1049 | if (sk->sk_no_check == UDP_CSUM_NOXMIT) | ||
1050 | skb->ip_summed = CHECKSUM_NONE; | ||
1051 | else if ((skb_dst(skb) && skb_dst(skb)->dev) && | ||
1052 | (!(skb_dst(skb)->dev->features & NETIF_F_V4_CSUM))) { | ||
1053 | skb->ip_summed = CHECKSUM_COMPLETE; | ||
1054 | csum = skb_checksum(skb, 0, udp_len, 0); | ||
1055 | uh->check = csum_tcpudp_magic(inet->inet_saddr, | ||
1056 | inet->inet_daddr, | ||
1057 | udp_len, IPPROTO_UDP, csum); | ||
1058 | if (uh->check == 0) | ||
1059 | uh->check = CSUM_MANGLED_0; | ||
1060 | } else { | ||
1061 | skb->ip_summed = CHECKSUM_PARTIAL; | ||
1062 | skb->csum_start = skb_transport_header(skb) - skb->head; | ||
1063 | skb->csum_offset = offsetof(struct udphdr, check); | ||
1064 | uh->check = ~csum_tcpudp_magic(inet->inet_saddr, | ||
1065 | inet->inet_daddr, | ||
1066 | udp_len, IPPROTO_UDP, 0); | ||
1067 | } | ||
1068 | break; | ||
1069 | |||
1070 | case L2TP_ENCAPTYPE_IP: | ||
1071 | break; | ||
1072 | } | ||
1073 | |||
1074 | l2tp_skb_set_owner_w(skb, sk); | ||
1075 | |||
1076 | l2tp_xmit_core(session, skb, data_len); | ||
1077 | |||
1078 | abort: | ||
1079 | return 0; | ||
1080 | } | ||
1081 | EXPORT_SYMBOL_GPL(l2tp_xmit_skb); | ||
1082 | |||
1083 | /***************************************************************************** | ||
1084 | * Tinnel and session create/destroy. | ||
1085 | *****************************************************************************/ | ||
1086 | |||
1087 | /* Tunnel socket destruct hook. | ||
1088 | * The tunnel context is deleted only when all session sockets have been | ||
1089 | * closed. | ||
1090 | */ | ||
1091 | void l2tp_tunnel_destruct(struct sock *sk) | ||
1092 | { | ||
1093 | struct l2tp_tunnel *tunnel; | ||
1094 | |||
1095 | tunnel = sk->sk_user_data; | ||
1096 | if (tunnel == NULL) | ||
1097 | goto end; | ||
1098 | |||
1099 | PRINTK(tunnel->debug, L2TP_MSG_CONTROL, KERN_INFO, | ||
1100 | "%s: closing...\n", tunnel->name); | ||
1101 | |||
1102 | /* Close all sessions */ | ||
1103 | l2tp_tunnel_closeall(tunnel); | ||
1104 | |||
1105 | switch (tunnel->encap) { | ||
1106 | case L2TP_ENCAPTYPE_UDP: | ||
1107 | /* No longer an encapsulation socket. See net/ipv4/udp.c */ | ||
1108 | (udp_sk(sk))->encap_type = 0; | ||
1109 | (udp_sk(sk))->encap_rcv = NULL; | ||
1110 | break; | ||
1111 | case L2TP_ENCAPTYPE_IP: | ||
1112 | break; | ||
1113 | } | ||
1114 | |||
1115 | /* Remove hooks into tunnel socket */ | ||
1116 | tunnel->sock = NULL; | ||
1117 | sk->sk_destruct = tunnel->old_sk_destruct; | ||
1118 | sk->sk_user_data = NULL; | ||
1119 | |||
1120 | /* Call the original destructor */ | ||
1121 | if (sk->sk_destruct) | ||
1122 | (*sk->sk_destruct)(sk); | ||
1123 | |||
1124 | /* We're finished with the socket */ | ||
1125 | l2tp_tunnel_dec_refcount(tunnel); | ||
1126 | |||
1127 | end: | ||
1128 | return; | ||
1129 | } | ||
1130 | EXPORT_SYMBOL(l2tp_tunnel_destruct); | ||
1131 | |||
1132 | /* When the tunnel is closed, all the attached sessions need to go too. | ||
1133 | */ | ||
1134 | void l2tp_tunnel_closeall(struct l2tp_tunnel *tunnel) | ||
1135 | { | ||
1136 | int hash; | ||
1137 | struct hlist_node *walk; | ||
1138 | struct hlist_node *tmp; | ||
1139 | struct l2tp_session *session; | ||
1140 | |||
1141 | BUG_ON(tunnel == NULL); | ||
1142 | |||
1143 | PRINTK(tunnel->debug, L2TP_MSG_CONTROL, KERN_INFO, | ||
1144 | "%s: closing all sessions...\n", tunnel->name); | ||
1145 | |||
1146 | write_lock_bh(&tunnel->hlist_lock); | ||
1147 | for (hash = 0; hash < L2TP_HASH_SIZE; hash++) { | ||
1148 | again: | ||
1149 | hlist_for_each_safe(walk, tmp, &tunnel->session_hlist[hash]) { | ||
1150 | session = hlist_entry(walk, struct l2tp_session, hlist); | ||
1151 | |||
1152 | PRINTK(session->debug, L2TP_MSG_CONTROL, KERN_INFO, | ||
1153 | "%s: closing session\n", session->name); | ||
1154 | |||
1155 | hlist_del_init(&session->hlist); | ||
1156 | |||
1157 | /* Since we should hold the sock lock while | ||
1158 | * doing any unbinding, we need to release the | ||
1159 | * lock we're holding before taking that lock. | ||
1160 | * Hold a reference to the sock so it doesn't | ||
1161 | * disappear as we're jumping between locks. | ||
1162 | */ | ||
1163 | if (session->ref != NULL) | ||
1164 | (*session->ref)(session); | ||
1165 | |||
1166 | write_unlock_bh(&tunnel->hlist_lock); | ||
1167 | |||
1168 | if (tunnel->version != L2TP_HDR_VER_2) { | ||
1169 | struct l2tp_net *pn = l2tp_pernet(tunnel->l2tp_net); | ||
1170 | |||
1171 | spin_lock_bh(&pn->l2tp_session_hlist_lock); | ||
1172 | hlist_del_init_rcu(&session->global_hlist); | ||
1173 | spin_unlock_bh(&pn->l2tp_session_hlist_lock); | ||
1174 | synchronize_rcu(); | ||
1175 | } | ||
1176 | |||
1177 | if (session->session_close != NULL) | ||
1178 | (*session->session_close)(session); | ||
1179 | |||
1180 | if (session->deref != NULL) | ||
1181 | (*session->deref)(session); | ||
1182 | |||
1183 | write_lock_bh(&tunnel->hlist_lock); | ||
1184 | |||
1185 | /* Now restart from the beginning of this hash | ||
1186 | * chain. We always remove a session from the | ||
1187 | * list so we are guaranteed to make forward | ||
1188 | * progress. | ||
1189 | */ | ||
1190 | goto again; | ||
1191 | } | ||
1192 | } | ||
1193 | write_unlock_bh(&tunnel->hlist_lock); | ||
1194 | } | ||
1195 | EXPORT_SYMBOL_GPL(l2tp_tunnel_closeall); | ||
1196 | |||
1197 | /* Really kill the tunnel. | ||
1198 | * Come here only when all sessions have been cleared from the tunnel. | ||
1199 | */ | ||
1200 | void l2tp_tunnel_free(struct l2tp_tunnel *tunnel) | ||
1201 | { | ||
1202 | struct l2tp_net *pn = l2tp_pernet(tunnel->l2tp_net); | ||
1203 | |||
1204 | BUG_ON(atomic_read(&tunnel->ref_count) != 0); | ||
1205 | BUG_ON(tunnel->sock != NULL); | ||
1206 | |||
1207 | PRINTK(tunnel->debug, L2TP_MSG_CONTROL, KERN_INFO, | ||
1208 | "%s: free...\n", tunnel->name); | ||
1209 | |||
1210 | /* Remove from tunnel list */ | ||
1211 | spin_lock_bh(&pn->l2tp_tunnel_list_lock); | ||
1212 | list_del_rcu(&tunnel->list); | ||
1213 | spin_unlock_bh(&pn->l2tp_tunnel_list_lock); | ||
1214 | synchronize_rcu(); | ||
1215 | |||
1216 | atomic_dec(&l2tp_tunnel_count); | ||
1217 | kfree(tunnel); | ||
1218 | } | ||
1219 | EXPORT_SYMBOL_GPL(l2tp_tunnel_free); | ||
1220 | |||
1221 | /* Create a socket for the tunnel, if one isn't set up by | ||
1222 | * userspace. This is used for static tunnels where there is no | ||
1223 | * managing L2TP daemon. | ||
1224 | */ | ||
1225 | static int l2tp_tunnel_sock_create(u32 tunnel_id, u32 peer_tunnel_id, struct l2tp_tunnel_cfg *cfg, struct socket **sockp) | ||
1226 | { | ||
1227 | int err = -EINVAL; | ||
1228 | struct sockaddr_in udp_addr; | ||
1229 | struct sockaddr_l2tpip ip_addr; | ||
1230 | struct socket *sock = NULL; | ||
1231 | |||
1232 | switch (cfg->encap) { | ||
1233 | case L2TP_ENCAPTYPE_UDP: | ||
1234 | err = sock_create(AF_INET, SOCK_DGRAM, 0, sockp); | ||
1235 | if (err < 0) | ||
1236 | goto out; | ||
1237 | |||
1238 | sock = *sockp; | ||
1239 | |||
1240 | memset(&udp_addr, 0, sizeof(udp_addr)); | ||
1241 | udp_addr.sin_family = AF_INET; | ||
1242 | udp_addr.sin_addr = cfg->local_ip; | ||
1243 | udp_addr.sin_port = htons(cfg->local_udp_port); | ||
1244 | err = kernel_bind(sock, (struct sockaddr *) &udp_addr, sizeof(udp_addr)); | ||
1245 | if (err < 0) | ||
1246 | goto out; | ||
1247 | |||
1248 | udp_addr.sin_family = AF_INET; | ||
1249 | udp_addr.sin_addr = cfg->peer_ip; | ||
1250 | udp_addr.sin_port = htons(cfg->peer_udp_port); | ||
1251 | err = kernel_connect(sock, (struct sockaddr *) &udp_addr, sizeof(udp_addr), 0); | ||
1252 | if (err < 0) | ||
1253 | goto out; | ||
1254 | |||
1255 | if (!cfg->use_udp_checksums) | ||
1256 | sock->sk->sk_no_check = UDP_CSUM_NOXMIT; | ||
1257 | |||
1258 | break; | ||
1259 | |||
1260 | case L2TP_ENCAPTYPE_IP: | ||
1261 | err = sock_create(AF_INET, SOCK_DGRAM, IPPROTO_L2TP, sockp); | ||
1262 | if (err < 0) | ||
1263 | goto out; | ||
1264 | |||
1265 | sock = *sockp; | ||
1266 | |||
1267 | memset(&ip_addr, 0, sizeof(ip_addr)); | ||
1268 | ip_addr.l2tp_family = AF_INET; | ||
1269 | ip_addr.l2tp_addr = cfg->local_ip; | ||
1270 | ip_addr.l2tp_conn_id = tunnel_id; | ||
1271 | err = kernel_bind(sock, (struct sockaddr *) &ip_addr, sizeof(ip_addr)); | ||
1272 | if (err < 0) | ||
1273 | goto out; | ||
1274 | |||
1275 | ip_addr.l2tp_family = AF_INET; | ||
1276 | ip_addr.l2tp_addr = cfg->peer_ip; | ||
1277 | ip_addr.l2tp_conn_id = peer_tunnel_id; | ||
1278 | err = kernel_connect(sock, (struct sockaddr *) &ip_addr, sizeof(ip_addr), 0); | ||
1279 | if (err < 0) | ||
1280 | goto out; | ||
1281 | |||
1282 | break; | ||
1283 | |||
1284 | default: | ||
1285 | goto out; | ||
1286 | } | ||
1287 | |||
1288 | out: | ||
1289 | if ((err < 0) && sock) { | ||
1290 | sock_release(sock); | ||
1291 | *sockp = NULL; | ||
1292 | } | ||
1293 | |||
1294 | return err; | ||
1295 | } | ||
1296 | |||
1297 | int l2tp_tunnel_create(struct net *net, int fd, int version, u32 tunnel_id, u32 peer_tunnel_id, struct l2tp_tunnel_cfg *cfg, struct l2tp_tunnel **tunnelp) | ||
1298 | { | ||
1299 | struct l2tp_tunnel *tunnel = NULL; | ||
1300 | int err; | ||
1301 | struct socket *sock = NULL; | ||
1302 | struct sock *sk = NULL; | ||
1303 | struct l2tp_net *pn; | ||
1304 | enum l2tp_encap_type encap = L2TP_ENCAPTYPE_UDP; | ||
1305 | |||
1306 | /* Get the tunnel socket from the fd, which was opened by | ||
1307 | * the userspace L2TP daemon. If not specified, create a | ||
1308 | * kernel socket. | ||
1309 | */ | ||
1310 | if (fd < 0) { | ||
1311 | err = l2tp_tunnel_sock_create(tunnel_id, peer_tunnel_id, cfg, &sock); | ||
1312 | if (err < 0) | ||
1313 | goto err; | ||
1314 | } else { | ||
1315 | err = -EBADF; | ||
1316 | sock = sockfd_lookup(fd, &err); | ||
1317 | if (!sock) { | ||
1318 | printk(KERN_ERR "tunl %hu: sockfd_lookup(fd=%d) returned %d\n", | ||
1319 | tunnel_id, fd, err); | ||
1320 | goto err; | ||
1321 | } | ||
1322 | } | ||
1323 | |||
1324 | sk = sock->sk; | ||
1325 | |||
1326 | if (cfg != NULL) | ||
1327 | encap = cfg->encap; | ||
1328 | |||
1329 | /* Quick sanity checks */ | ||
1330 | switch (encap) { | ||
1331 | case L2TP_ENCAPTYPE_UDP: | ||
1332 | err = -EPROTONOSUPPORT; | ||
1333 | if (sk->sk_protocol != IPPROTO_UDP) { | ||
1334 | printk(KERN_ERR "tunl %hu: fd %d wrong protocol, got %d, expected %d\n", | ||
1335 | tunnel_id, fd, sk->sk_protocol, IPPROTO_UDP); | ||
1336 | goto err; | ||
1337 | } | ||
1338 | break; | ||
1339 | case L2TP_ENCAPTYPE_IP: | ||
1340 | err = -EPROTONOSUPPORT; | ||
1341 | if (sk->sk_protocol != IPPROTO_L2TP) { | ||
1342 | printk(KERN_ERR "tunl %hu: fd %d wrong protocol, got %d, expected %d\n", | ||
1343 | tunnel_id, fd, sk->sk_protocol, IPPROTO_L2TP); | ||
1344 | goto err; | ||
1345 | } | ||
1346 | break; | ||
1347 | } | ||
1348 | |||
1349 | /* Check if this socket has already been prepped */ | ||
1350 | tunnel = (struct l2tp_tunnel *)sk->sk_user_data; | ||
1351 | if (tunnel != NULL) { | ||
1352 | /* This socket has already been prepped */ | ||
1353 | err = -EBUSY; | ||
1354 | goto err; | ||
1355 | } | ||
1356 | |||
1357 | tunnel = kzalloc(sizeof(struct l2tp_tunnel), GFP_KERNEL); | ||
1358 | if (tunnel == NULL) { | ||
1359 | err = -ENOMEM; | ||
1360 | goto err; | ||
1361 | } | ||
1362 | |||
1363 | tunnel->version = version; | ||
1364 | tunnel->tunnel_id = tunnel_id; | ||
1365 | tunnel->peer_tunnel_id = peer_tunnel_id; | ||
1366 | tunnel->debug = L2TP_DEFAULT_DEBUG_FLAGS; | ||
1367 | |||
1368 | tunnel->magic = L2TP_TUNNEL_MAGIC; | ||
1369 | sprintf(&tunnel->name[0], "tunl %u", tunnel_id); | ||
1370 | rwlock_init(&tunnel->hlist_lock); | ||
1371 | |||
1372 | /* The net we belong to */ | ||
1373 | tunnel->l2tp_net = net; | ||
1374 | pn = l2tp_pernet(net); | ||
1375 | |||
1376 | if (cfg != NULL) | ||
1377 | tunnel->debug = cfg->debug; | ||
1378 | |||
1379 | /* Mark socket as an encapsulation socket. See net/ipv4/udp.c */ | ||
1380 | tunnel->encap = encap; | ||
1381 | if (encap == L2TP_ENCAPTYPE_UDP) { | ||
1382 | /* Mark socket as an encapsulation socket. See net/ipv4/udp.c */ | ||
1383 | udp_sk(sk)->encap_type = UDP_ENCAP_L2TPINUDP; | ||
1384 | udp_sk(sk)->encap_rcv = l2tp_udp_encap_recv; | ||
1385 | } | ||
1386 | |||
1387 | sk->sk_user_data = tunnel; | ||
1388 | |||
1389 | /* Hook on the tunnel socket destructor so that we can cleanup | ||
1390 | * if the tunnel socket goes away. | ||
1391 | */ | ||
1392 | tunnel->old_sk_destruct = sk->sk_destruct; | ||
1393 | sk->sk_destruct = &l2tp_tunnel_destruct; | ||
1394 | tunnel->sock = sk; | ||
1395 | sk->sk_allocation = GFP_ATOMIC; | ||
1396 | |||
1397 | /* Add tunnel to our list */ | ||
1398 | INIT_LIST_HEAD(&tunnel->list); | ||
1399 | spin_lock_bh(&pn->l2tp_tunnel_list_lock); | ||
1400 | list_add_rcu(&tunnel->list, &pn->l2tp_tunnel_list); | ||
1401 | spin_unlock_bh(&pn->l2tp_tunnel_list_lock); | ||
1402 | synchronize_rcu(); | ||
1403 | atomic_inc(&l2tp_tunnel_count); | ||
1404 | |||
1405 | /* Bump the reference count. The tunnel context is deleted | ||
1406 | * only when this drops to zero. | ||
1407 | */ | ||
1408 | l2tp_tunnel_inc_refcount(tunnel); | ||
1409 | |||
1410 | err = 0; | ||
1411 | err: | ||
1412 | if (tunnelp) | ||
1413 | *tunnelp = tunnel; | ||
1414 | |||
1415 | /* If tunnel's socket was created by the kernel, it doesn't | ||
1416 | * have a file. | ||
1417 | */ | ||
1418 | if (sock && sock->file) | ||
1419 | sockfd_put(sock); | ||
1420 | |||
1421 | return err; | ||
1422 | } | ||
1423 | EXPORT_SYMBOL_GPL(l2tp_tunnel_create); | ||
1424 | |||
1425 | /* This function is used by the netlink TUNNEL_DELETE command. | ||
1426 | */ | ||
1427 | int l2tp_tunnel_delete(struct l2tp_tunnel *tunnel) | ||
1428 | { | ||
1429 | int err = 0; | ||
1430 | struct socket *sock = tunnel->sock ? tunnel->sock->sk_socket : NULL; | ||
1431 | |||
1432 | /* Force the tunnel socket to close. This will eventually | ||
1433 | * cause the tunnel to be deleted via the normal socket close | ||
1434 | * mechanisms when userspace closes the tunnel socket. | ||
1435 | */ | ||
1436 | if (sock != NULL) { | ||
1437 | err = inet_shutdown(sock, 2); | ||
1438 | |||
1439 | /* If the tunnel's socket was created by the kernel, | ||
1440 | * close the socket here since the socket was not | ||
1441 | * created by userspace. | ||
1442 | */ | ||
1443 | if (sock->file == NULL) | ||
1444 | err = inet_release(sock); | ||
1445 | } | ||
1446 | |||
1447 | return err; | ||
1448 | } | ||
1449 | EXPORT_SYMBOL_GPL(l2tp_tunnel_delete); | ||
1450 | |||
1451 | /* Really kill the session. | ||
1452 | */ | ||
1453 | void l2tp_session_free(struct l2tp_session *session) | ||
1454 | { | ||
1455 | struct l2tp_tunnel *tunnel; | ||
1456 | |||
1457 | BUG_ON(atomic_read(&session->ref_count) != 0); | ||
1458 | |||
1459 | tunnel = session->tunnel; | ||
1460 | if (tunnel != NULL) { | ||
1461 | BUG_ON(tunnel->magic != L2TP_TUNNEL_MAGIC); | ||
1462 | |||
1463 | /* Delete the session from the hash */ | ||
1464 | write_lock_bh(&tunnel->hlist_lock); | ||
1465 | hlist_del_init(&session->hlist); | ||
1466 | write_unlock_bh(&tunnel->hlist_lock); | ||
1467 | |||
1468 | /* Unlink from the global hash if not L2TPv2 */ | ||
1469 | if (tunnel->version != L2TP_HDR_VER_2) { | ||
1470 | struct l2tp_net *pn = l2tp_pernet(tunnel->l2tp_net); | ||
1471 | |||
1472 | spin_lock_bh(&pn->l2tp_session_hlist_lock); | ||
1473 | hlist_del_init_rcu(&session->global_hlist); | ||
1474 | spin_unlock_bh(&pn->l2tp_session_hlist_lock); | ||
1475 | synchronize_rcu(); | ||
1476 | } | ||
1477 | |||
1478 | if (session->session_id != 0) | ||
1479 | atomic_dec(&l2tp_session_count); | ||
1480 | |||
1481 | sock_put(tunnel->sock); | ||
1482 | |||
1483 | /* This will delete the tunnel context if this | ||
1484 | * is the last session on the tunnel. | ||
1485 | */ | ||
1486 | session->tunnel = NULL; | ||
1487 | l2tp_tunnel_dec_refcount(tunnel); | ||
1488 | } | ||
1489 | |||
1490 | kfree(session); | ||
1491 | |||
1492 | return; | ||
1493 | } | ||
1494 | EXPORT_SYMBOL_GPL(l2tp_session_free); | ||
1495 | |||
1496 | /* This function is used by the netlink SESSION_DELETE command and by | ||
1497 | pseudowire modules. | ||
1498 | */ | ||
1499 | int l2tp_session_delete(struct l2tp_session *session) | ||
1500 | { | ||
1501 | if (session->session_close != NULL) | ||
1502 | (*session->session_close)(session); | ||
1503 | |||
1504 | l2tp_session_dec_refcount(session); | ||
1505 | |||
1506 | return 0; | ||
1507 | } | ||
1508 | EXPORT_SYMBOL_GPL(l2tp_session_delete); | ||
1509 | |||
1510 | |||
1511 | /* We come here whenever a session's send_seq, cookie_len or | ||
1512 | * l2specific_len parameters are set. | ||
1513 | */ | ||
1514 | void l2tp_session_set_header_len(struct l2tp_session *session, int version) | ||
1515 | { | ||
1516 | if (version == L2TP_HDR_VER_2) { | ||
1517 | session->hdr_len = 6; | ||
1518 | if (session->send_seq) | ||
1519 | session->hdr_len += 4; | ||
1520 | } else { | ||
1521 | session->hdr_len = 4 + session->cookie_len + session->l2specific_len + session->offset; | ||
1522 | if (session->tunnel->encap == L2TP_ENCAPTYPE_UDP) | ||
1523 | session->hdr_len += 4; | ||
1524 | } | ||
1525 | |||
1526 | } | ||
1527 | EXPORT_SYMBOL_GPL(l2tp_session_set_header_len); | ||
1528 | |||
1529 | struct l2tp_session *l2tp_session_create(int priv_size, struct l2tp_tunnel *tunnel, u32 session_id, u32 peer_session_id, struct l2tp_session_cfg *cfg) | ||
1530 | { | ||
1531 | struct l2tp_session *session; | ||
1532 | |||
1533 | session = kzalloc(sizeof(struct l2tp_session) + priv_size, GFP_KERNEL); | ||
1534 | if (session != NULL) { | ||
1535 | session->magic = L2TP_SESSION_MAGIC; | ||
1536 | session->tunnel = tunnel; | ||
1537 | |||
1538 | session->session_id = session_id; | ||
1539 | session->peer_session_id = peer_session_id; | ||
1540 | session->nr = 1; | ||
1541 | |||
1542 | sprintf(&session->name[0], "sess %u/%u", | ||
1543 | tunnel->tunnel_id, session->session_id); | ||
1544 | |||
1545 | skb_queue_head_init(&session->reorder_q); | ||
1546 | |||
1547 | INIT_HLIST_NODE(&session->hlist); | ||
1548 | INIT_HLIST_NODE(&session->global_hlist); | ||
1549 | |||
1550 | /* Inherit debug options from tunnel */ | ||
1551 | session->debug = tunnel->debug; | ||
1552 | |||
1553 | if (cfg) { | ||
1554 | session->pwtype = cfg->pw_type; | ||
1555 | session->debug = cfg->debug; | ||
1556 | session->mtu = cfg->mtu; | ||
1557 | session->mru = cfg->mru; | ||
1558 | session->send_seq = cfg->send_seq; | ||
1559 | session->recv_seq = cfg->recv_seq; | ||
1560 | session->lns_mode = cfg->lns_mode; | ||
1561 | session->reorder_timeout = cfg->reorder_timeout; | ||
1562 | session->offset = cfg->offset; | ||
1563 | session->l2specific_type = cfg->l2specific_type; | ||
1564 | session->l2specific_len = cfg->l2specific_len; | ||
1565 | session->cookie_len = cfg->cookie_len; | ||
1566 | memcpy(&session->cookie[0], &cfg->cookie[0], cfg->cookie_len); | ||
1567 | session->peer_cookie_len = cfg->peer_cookie_len; | ||
1568 | memcpy(&session->peer_cookie[0], &cfg->peer_cookie[0], cfg->peer_cookie_len); | ||
1569 | } | ||
1570 | |||
1571 | if (tunnel->version == L2TP_HDR_VER_2) | ||
1572 | session->build_header = l2tp_build_l2tpv2_header; | ||
1573 | else | ||
1574 | session->build_header = l2tp_build_l2tpv3_header; | ||
1575 | |||
1576 | l2tp_session_set_header_len(session, tunnel->version); | ||
1577 | |||
1578 | /* Bump the reference count. The session context is deleted | ||
1579 | * only when this drops to zero. | ||
1580 | */ | ||
1581 | l2tp_session_inc_refcount(session); | ||
1582 | l2tp_tunnel_inc_refcount(tunnel); | ||
1583 | |||
1584 | /* Ensure tunnel socket isn't deleted */ | ||
1585 | sock_hold(tunnel->sock); | ||
1586 | |||
1587 | /* Add session to the tunnel's hash list */ | ||
1588 | write_lock_bh(&tunnel->hlist_lock); | ||
1589 | hlist_add_head(&session->hlist, | ||
1590 | l2tp_session_id_hash(tunnel, session_id)); | ||
1591 | write_unlock_bh(&tunnel->hlist_lock); | ||
1592 | |||
1593 | /* And to the global session list if L2TPv3 */ | ||
1594 | if (tunnel->version != L2TP_HDR_VER_2) { | ||
1595 | struct l2tp_net *pn = l2tp_pernet(tunnel->l2tp_net); | ||
1596 | |||
1597 | spin_lock_bh(&pn->l2tp_session_hlist_lock); | ||
1598 | hlist_add_head_rcu(&session->global_hlist, | ||
1599 | l2tp_session_id_hash_2(pn, session_id)); | ||
1600 | spin_unlock_bh(&pn->l2tp_session_hlist_lock); | ||
1601 | synchronize_rcu(); | ||
1602 | } | ||
1603 | |||
1604 | /* Ignore management session in session count value */ | ||
1605 | if (session->session_id != 0) | ||
1606 | atomic_inc(&l2tp_session_count); | ||
1607 | } | ||
1608 | |||
1609 | return session; | ||
1610 | } | ||
1611 | EXPORT_SYMBOL_GPL(l2tp_session_create); | ||
1612 | |||
1613 | /***************************************************************************** | ||
1614 | * Init and cleanup | ||
1615 | *****************************************************************************/ | ||
1616 | |||
1617 | static __net_init int l2tp_init_net(struct net *net) | ||
1618 | { | ||
1619 | struct l2tp_net *pn; | ||
1620 | int err; | ||
1621 | int hash; | ||
1622 | |||
1623 | pn = kzalloc(sizeof(*pn), GFP_KERNEL); | ||
1624 | if (!pn) | ||
1625 | return -ENOMEM; | ||
1626 | |||
1627 | INIT_LIST_HEAD(&pn->l2tp_tunnel_list); | ||
1628 | spin_lock_init(&pn->l2tp_tunnel_list_lock); | ||
1629 | |||
1630 | for (hash = 0; hash < L2TP_HASH_SIZE_2; hash++) | ||
1631 | INIT_HLIST_HEAD(&pn->l2tp_session_hlist[hash]); | ||
1632 | |||
1633 | spin_lock_init(&pn->l2tp_session_hlist_lock); | ||
1634 | |||
1635 | err = net_assign_generic(net, l2tp_net_id, pn); | ||
1636 | if (err) | ||
1637 | goto out; | ||
1638 | |||
1639 | return 0; | ||
1640 | |||
1641 | out: | ||
1642 | kfree(pn); | ||
1643 | return err; | ||
1644 | } | ||
1645 | |||
1646 | static __net_exit void l2tp_exit_net(struct net *net) | ||
1647 | { | ||
1648 | struct l2tp_net *pn; | ||
1649 | |||
1650 | pn = net_generic(net, l2tp_net_id); | ||
1651 | /* | ||
1652 | * if someone has cached our net then | ||
1653 | * further net_generic call will return NULL | ||
1654 | */ | ||
1655 | net_assign_generic(net, l2tp_net_id, NULL); | ||
1656 | kfree(pn); | ||
1657 | } | ||
1658 | |||
1659 | static struct pernet_operations l2tp_net_ops = { | ||
1660 | .init = l2tp_init_net, | ||
1661 | .exit = l2tp_exit_net, | ||
1662 | .id = &l2tp_net_id, | ||
1663 | .size = sizeof(struct l2tp_net), | ||
1664 | }; | ||
1665 | |||
1666 | static int __init l2tp_init(void) | ||
1667 | { | ||
1668 | int rc = 0; | ||
1669 | |||
1670 | rc = register_pernet_device(&l2tp_net_ops); | ||
1671 | if (rc) | ||
1672 | goto out; | ||
1673 | |||
1674 | printk(KERN_INFO "L2TP core driver, %s\n", L2TP_DRV_VERSION); | ||
1675 | |||
1676 | out: | ||
1677 | return rc; | ||
1678 | } | ||
1679 | |||
1680 | static void __exit l2tp_exit(void) | ||
1681 | { | ||
1682 | unregister_pernet_device(&l2tp_net_ops); | ||
1683 | } | ||
1684 | |||
1685 | module_init(l2tp_init); | ||
1686 | module_exit(l2tp_exit); | ||
1687 | |||
1688 | MODULE_AUTHOR("James Chapman <jchapman@katalix.com>"); | ||
1689 | MODULE_DESCRIPTION("L2TP core"); | ||
1690 | MODULE_LICENSE("GPL"); | ||
1691 | MODULE_VERSION(L2TP_DRV_VERSION); | ||
1692 | |||
diff --git a/net/l2tp/l2tp_core.h b/net/l2tp/l2tp_core.h new file mode 100644 index 000000000000..f0f318edd3f1 --- /dev/null +++ b/net/l2tp/l2tp_core.h | |||
@@ -0,0 +1,304 @@ | |||
1 | /* | ||
2 | * L2TP internal definitions. | ||
3 | * | ||
4 | * Copyright (c) 2008,2009 Katalix Systems Ltd | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License version 2 as | ||
8 | * published by the Free Software Foundation. | ||
9 | */ | ||
10 | |||
11 | #ifndef _L2TP_CORE_H_ | ||
12 | #define _L2TP_CORE_H_ | ||
13 | |||
14 | /* Just some random numbers */ | ||
15 | #define L2TP_TUNNEL_MAGIC 0x42114DDA | ||
16 | #define L2TP_SESSION_MAGIC 0x0C04EB7D | ||
17 | |||
18 | /* Per tunnel, session hash table size */ | ||
19 | #define L2TP_HASH_BITS 4 | ||
20 | #define L2TP_HASH_SIZE (1 << L2TP_HASH_BITS) | ||
21 | |||
22 | /* System-wide, session hash table size */ | ||
23 | #define L2TP_HASH_BITS_2 8 | ||
24 | #define L2TP_HASH_SIZE_2 (1 << L2TP_HASH_BITS_2) | ||
25 | |||
26 | /* Debug message categories for the DEBUG socket option */ | ||
27 | enum { | ||
28 | L2TP_MSG_DEBUG = (1 << 0), /* verbose debug (if | ||
29 | * compiled in) */ | ||
30 | L2TP_MSG_CONTROL = (1 << 1), /* userspace - kernel | ||
31 | * interface */ | ||
32 | L2TP_MSG_SEQ = (1 << 2), /* sequence numbers */ | ||
33 | L2TP_MSG_DATA = (1 << 3), /* data packets */ | ||
34 | }; | ||
35 | |||
36 | struct sk_buff; | ||
37 | |||
38 | struct l2tp_stats { | ||
39 | u64 tx_packets; | ||
40 | u64 tx_bytes; | ||
41 | u64 tx_errors; | ||
42 | u64 rx_packets; | ||
43 | u64 rx_bytes; | ||
44 | u64 rx_seq_discards; | ||
45 | u64 rx_oos_packets; | ||
46 | u64 rx_errors; | ||
47 | u64 rx_cookie_discards; | ||
48 | }; | ||
49 | |||
50 | struct l2tp_tunnel; | ||
51 | |||
52 | /* Describes a session. Contains information to determine incoming | ||
53 | * packets and transmit outgoing ones. | ||
54 | */ | ||
55 | struct l2tp_session_cfg { | ||
56 | enum l2tp_pwtype pw_type; | ||
57 | unsigned data_seq:2; /* data sequencing level | ||
58 | * 0 => none, 1 => IP only, | ||
59 | * 2 => all | ||
60 | */ | ||
61 | unsigned recv_seq:1; /* expect receive packets with | ||
62 | * sequence numbers? */ | ||
63 | unsigned send_seq:1; /* send packets with sequence | ||
64 | * numbers? */ | ||
65 | unsigned lns_mode:1; /* behave as LNS? LAC enables | ||
66 | * sequence numbers under | ||
67 | * control of LNS. */ | ||
68 | int debug; /* bitmask of debug message | ||
69 | * categories */ | ||
70 | u16 vlan_id; /* VLAN pseudowire only */ | ||
71 | u16 offset; /* offset to payload */ | ||
72 | u16 l2specific_len; /* Layer 2 specific length */ | ||
73 | u16 l2specific_type; /* Layer 2 specific type */ | ||
74 | u8 cookie[8]; /* optional cookie */ | ||
75 | int cookie_len; /* 0, 4 or 8 bytes */ | ||
76 | u8 peer_cookie[8]; /* peer's cookie */ | ||
77 | int peer_cookie_len; /* 0, 4 or 8 bytes */ | ||
78 | int reorder_timeout; /* configured reorder timeout | ||
79 | * (in jiffies) */ | ||
80 | int mtu; | ||
81 | int mru; | ||
82 | char *ifname; | ||
83 | }; | ||
84 | |||
85 | struct l2tp_session { | ||
86 | int magic; /* should be | ||
87 | * L2TP_SESSION_MAGIC */ | ||
88 | |||
89 | struct l2tp_tunnel *tunnel; /* back pointer to tunnel | ||
90 | * context */ | ||
91 | u32 session_id; | ||
92 | u32 peer_session_id; | ||
93 | u8 cookie[8]; | ||
94 | int cookie_len; | ||
95 | u8 peer_cookie[8]; | ||
96 | int peer_cookie_len; | ||
97 | u16 offset; /* offset from end of L2TP header | ||
98 | to beginning of data */ | ||
99 | u16 l2specific_len; | ||
100 | u16 l2specific_type; | ||
101 | u16 hdr_len; | ||
102 | u32 nr; /* session NR state (receive) */ | ||
103 | u32 ns; /* session NR state (send) */ | ||
104 | struct sk_buff_head reorder_q; /* receive reorder queue */ | ||
105 | struct hlist_node hlist; /* Hash list node */ | ||
106 | atomic_t ref_count; | ||
107 | |||
108 | char name[32]; /* for logging */ | ||
109 | char ifname[IFNAMSIZ]; | ||
110 | unsigned data_seq:2; /* data sequencing level | ||
111 | * 0 => none, 1 => IP only, | ||
112 | * 2 => all | ||
113 | */ | ||
114 | unsigned recv_seq:1; /* expect receive packets with | ||
115 | * sequence numbers? */ | ||
116 | unsigned send_seq:1; /* send packets with sequence | ||
117 | * numbers? */ | ||
118 | unsigned lns_mode:1; /* behave as LNS? LAC enables | ||
119 | * sequence numbers under | ||
120 | * control of LNS. */ | ||
121 | int debug; /* bitmask of debug message | ||
122 | * categories */ | ||
123 | int reorder_timeout; /* configured reorder timeout | ||
124 | * (in jiffies) */ | ||
125 | int mtu; | ||
126 | int mru; | ||
127 | enum l2tp_pwtype pwtype; | ||
128 | struct l2tp_stats stats; | ||
129 | struct hlist_node global_hlist; /* Global hash list node */ | ||
130 | |||
131 | int (*build_header)(struct l2tp_session *session, void *buf); | ||
132 | void (*recv_skb)(struct l2tp_session *session, struct sk_buff *skb, int data_len); | ||
133 | void (*session_close)(struct l2tp_session *session); | ||
134 | void (*ref)(struct l2tp_session *session); | ||
135 | void (*deref)(struct l2tp_session *session); | ||
136 | #if defined(CONFIG_L2TP_DEBUGFS) || defined(CONFIG_L2TP_DEBUGFS_MODULE) | ||
137 | void (*show)(struct seq_file *m, void *priv); | ||
138 | #endif | ||
139 | uint8_t priv[0]; /* private data */ | ||
140 | }; | ||
141 | |||
142 | /* Describes the tunnel. It contains info to track all the associated | ||
143 | * sessions so incoming packets can be sorted out | ||
144 | */ | ||
145 | struct l2tp_tunnel_cfg { | ||
146 | int debug; /* bitmask of debug message | ||
147 | * categories */ | ||
148 | enum l2tp_encap_type encap; | ||
149 | |||
150 | /* Used only for kernel-created sockets */ | ||
151 | struct in_addr local_ip; | ||
152 | struct in_addr peer_ip; | ||
153 | u16 local_udp_port; | ||
154 | u16 peer_udp_port; | ||
155 | unsigned int use_udp_checksums:1; | ||
156 | }; | ||
157 | |||
158 | struct l2tp_tunnel { | ||
159 | int magic; /* Should be L2TP_TUNNEL_MAGIC */ | ||
160 | rwlock_t hlist_lock; /* protect session_hlist */ | ||
161 | struct hlist_head session_hlist[L2TP_HASH_SIZE]; | ||
162 | /* hashed list of sessions, | ||
163 | * hashed by id */ | ||
164 | u32 tunnel_id; | ||
165 | u32 peer_tunnel_id; | ||
166 | int version; /* 2=>L2TPv2, 3=>L2TPv3 */ | ||
167 | |||
168 | char name[20]; /* for logging */ | ||
169 | int debug; /* bitmask of debug message | ||
170 | * categories */ | ||
171 | enum l2tp_encap_type encap; | ||
172 | struct l2tp_stats stats; | ||
173 | |||
174 | struct list_head list; /* Keep a list of all tunnels */ | ||
175 | struct net *l2tp_net; /* the net we belong to */ | ||
176 | |||
177 | atomic_t ref_count; | ||
178 | #ifdef CONFIG_DEBUG_FS | ||
179 | void (*show)(struct seq_file *m, void *arg); | ||
180 | #endif | ||
181 | int (*recv_payload_hook)(struct sk_buff *skb); | ||
182 | void (*old_sk_destruct)(struct sock *); | ||
183 | struct sock *sock; /* Parent socket */ | ||
184 | int fd; | ||
185 | |||
186 | uint8_t priv[0]; /* private data */ | ||
187 | }; | ||
188 | |||
189 | struct l2tp_nl_cmd_ops { | ||
190 | int (*session_create)(struct net *net, u32 tunnel_id, u32 session_id, u32 peer_session_id, struct l2tp_session_cfg *cfg); | ||
191 | int (*session_delete)(struct l2tp_session *session); | ||
192 | }; | ||
193 | |||
194 | static inline void *l2tp_tunnel_priv(struct l2tp_tunnel *tunnel) | ||
195 | { | ||
196 | return &tunnel->priv[0]; | ||
197 | } | ||
198 | |||
199 | static inline void *l2tp_session_priv(struct l2tp_session *session) | ||
200 | { | ||
201 | return &session->priv[0]; | ||
202 | } | ||
203 | |||
204 | static inline struct l2tp_tunnel *l2tp_sock_to_tunnel(struct sock *sk) | ||
205 | { | ||
206 | struct l2tp_tunnel *tunnel; | ||
207 | |||
208 | if (sk == NULL) | ||
209 | return NULL; | ||
210 | |||
211 | sock_hold(sk); | ||
212 | tunnel = (struct l2tp_tunnel *)(sk->sk_user_data); | ||
213 | if (tunnel == NULL) { | ||
214 | sock_put(sk); | ||
215 | goto out; | ||
216 | } | ||
217 | |||
218 | BUG_ON(tunnel->magic != L2TP_TUNNEL_MAGIC); | ||
219 | |||
220 | out: | ||
221 | return tunnel; | ||
222 | } | ||
223 | |||
224 | extern struct l2tp_session *l2tp_session_find(struct net *net, struct l2tp_tunnel *tunnel, u32 session_id); | ||
225 | extern struct l2tp_session *l2tp_session_find_nth(struct l2tp_tunnel *tunnel, int nth); | ||
226 | extern struct l2tp_session *l2tp_session_find_by_ifname(struct net *net, char *ifname); | ||
227 | extern struct l2tp_tunnel *l2tp_tunnel_find(struct net *net, u32 tunnel_id); | ||
228 | extern struct l2tp_tunnel *l2tp_tunnel_find_nth(struct net *net, int nth); | ||
229 | |||
230 | extern int l2tp_tunnel_create(struct net *net, int fd, int version, u32 tunnel_id, u32 peer_tunnel_id, struct l2tp_tunnel_cfg *cfg, struct l2tp_tunnel **tunnelp); | ||
231 | extern int l2tp_tunnel_delete(struct l2tp_tunnel *tunnel); | ||
232 | extern struct l2tp_session *l2tp_session_create(int priv_size, struct l2tp_tunnel *tunnel, u32 session_id, u32 peer_session_id, struct l2tp_session_cfg *cfg); | ||
233 | extern int l2tp_session_delete(struct l2tp_session *session); | ||
234 | extern void l2tp_tunnel_free(struct l2tp_tunnel *tunnel); | ||
235 | extern void l2tp_session_free(struct l2tp_session *session); | ||
236 | extern void l2tp_recv_common(struct l2tp_session *session, struct sk_buff *skb, unsigned char *ptr, unsigned char *optr, u16 hdrflags, int length, int (*payload_hook)(struct sk_buff *skb)); | ||
237 | extern int l2tp_udp_recv_core(struct l2tp_tunnel *tunnel, struct sk_buff *skb, int (*payload_hook)(struct sk_buff *skb)); | ||
238 | extern int l2tp_udp_encap_recv(struct sock *sk, struct sk_buff *skb); | ||
239 | |||
240 | extern int l2tp_xmit_core(struct l2tp_session *session, struct sk_buff *skb, size_t data_len); | ||
241 | extern int l2tp_xmit_skb(struct l2tp_session *session, struct sk_buff *skb, int hdr_len); | ||
242 | extern void l2tp_tunnel_destruct(struct sock *sk); | ||
243 | extern void l2tp_tunnel_closeall(struct l2tp_tunnel *tunnel); | ||
244 | extern void l2tp_session_set_header_len(struct l2tp_session *session, int version); | ||
245 | |||
246 | extern int l2tp_nl_register_ops(enum l2tp_pwtype pw_type, const struct l2tp_nl_cmd_ops *ops); | ||
247 | extern void l2tp_nl_unregister_ops(enum l2tp_pwtype pw_type); | ||
248 | |||
249 | /* Tunnel reference counts. Incremented per session that is added to | ||
250 | * the tunnel. | ||
251 | */ | ||
252 | static inline void l2tp_tunnel_inc_refcount_1(struct l2tp_tunnel *tunnel) | ||
253 | { | ||
254 | atomic_inc(&tunnel->ref_count); | ||
255 | } | ||
256 | |||
257 | static inline void l2tp_tunnel_dec_refcount_1(struct l2tp_tunnel *tunnel) | ||
258 | { | ||
259 | if (atomic_dec_and_test(&tunnel->ref_count)) | ||
260 | l2tp_tunnel_free(tunnel); | ||
261 | } | ||
262 | #ifdef L2TP_REFCNT_DEBUG | ||
263 | #define l2tp_tunnel_inc_refcount(_t) do { \ | ||
264 | printk(KERN_DEBUG "l2tp_tunnel_inc_refcount: %s:%d %s: cnt=%d\n", __func__, __LINE__, (_t)->name, atomic_read(&_t->ref_count)); \ | ||
265 | l2tp_tunnel_inc_refcount_1(_t); \ | ||
266 | } while (0) | ||
267 | #define l2tp_tunnel_dec_refcount(_t) do { \ | ||
268 | printk(KERN_DEBUG "l2tp_tunnel_dec_refcount: %s:%d %s: cnt=%d\n", __func__, __LINE__, (_t)->name, atomic_read(&_t->ref_count)); \ | ||
269 | l2tp_tunnel_dec_refcount_1(_t); \ | ||
270 | } while (0) | ||
271 | #else | ||
272 | #define l2tp_tunnel_inc_refcount(t) l2tp_tunnel_inc_refcount_1(t) | ||
273 | #define l2tp_tunnel_dec_refcount(t) l2tp_tunnel_dec_refcount_1(t) | ||
274 | #endif | ||
275 | |||
276 | /* Session reference counts. Incremented when code obtains a reference | ||
277 | * to a session. | ||
278 | */ | ||
279 | static inline void l2tp_session_inc_refcount_1(struct l2tp_session *session) | ||
280 | { | ||
281 | atomic_inc(&session->ref_count); | ||
282 | } | ||
283 | |||
284 | static inline void l2tp_session_dec_refcount_1(struct l2tp_session *session) | ||
285 | { | ||
286 | if (atomic_dec_and_test(&session->ref_count)) | ||
287 | l2tp_session_free(session); | ||
288 | } | ||
289 | |||
290 | #ifdef L2TP_REFCNT_DEBUG | ||
291 | #define l2tp_session_inc_refcount(_s) do { \ | ||
292 | printk(KERN_DEBUG "l2tp_session_inc_refcount: %s:%d %s: cnt=%d\n", __func__, __LINE__, (_s)->name, atomic_read(&_s->ref_count)); \ | ||
293 | l2tp_session_inc_refcount_1(_s); \ | ||
294 | } while (0) | ||
295 | #define l2tp_session_dec_refcount(_s) do { \ | ||
296 | printk(KERN_DEBUG "l2tp_session_dec_refcount: %s:%d %s: cnt=%d\n", __func__, __LINE__, (_s)->name, atomic_read(&_s->ref_count)); \ | ||
297 | l2tp_session_dec_refcount_1(_s); \ | ||
298 | } while (0) | ||
299 | #else | ||
300 | #define l2tp_session_inc_refcount(s) l2tp_session_inc_refcount_1(s) | ||
301 | #define l2tp_session_dec_refcount(s) l2tp_session_dec_refcount_1(s) | ||
302 | #endif | ||
303 | |||
304 | #endif /* _L2TP_CORE_H_ */ | ||
diff --git a/net/l2tp/l2tp_debugfs.c b/net/l2tp/l2tp_debugfs.c new file mode 100644 index 000000000000..908f10f9720e --- /dev/null +++ b/net/l2tp/l2tp_debugfs.c | |||
@@ -0,0 +1,341 @@ | |||
1 | /* | ||
2 | * L2TP subsystem debugfs | ||
3 | * | ||
4 | * Copyright (c) 2010 Katalix Systems Ltd | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or | ||
7 | * modify it under the terms of the GNU General Public License | ||
8 | * as published by the Free Software Foundation; either version | ||
9 | * 2 of the License, or (at your option) any later version. | ||
10 | */ | ||
11 | |||
12 | #include <linux/module.h> | ||
13 | #include <linux/skbuff.h> | ||
14 | #include <linux/socket.h> | ||
15 | #include <linux/hash.h> | ||
16 | #include <linux/l2tp.h> | ||
17 | #include <linux/in.h> | ||
18 | #include <linux/etherdevice.h> | ||
19 | #include <linux/spinlock.h> | ||
20 | #include <linux/debugfs.h> | ||
21 | #include <net/sock.h> | ||
22 | #include <net/ip.h> | ||
23 | #include <net/icmp.h> | ||
24 | #include <net/udp.h> | ||
25 | #include <net/inet_common.h> | ||
26 | #include <net/inet_hashtables.h> | ||
27 | #include <net/tcp_states.h> | ||
28 | #include <net/protocol.h> | ||
29 | #include <net/xfrm.h> | ||
30 | #include <net/net_namespace.h> | ||
31 | #include <net/netns/generic.h> | ||
32 | |||
33 | #include "l2tp_core.h" | ||
34 | |||
35 | static struct dentry *rootdir; | ||
36 | static struct dentry *tunnels; | ||
37 | |||
38 | struct l2tp_dfs_seq_data { | ||
39 | struct net *net; | ||
40 | int tunnel_idx; /* current tunnel */ | ||
41 | int session_idx; /* index of session within current tunnel */ | ||
42 | struct l2tp_tunnel *tunnel; | ||
43 | struct l2tp_session *session; /* NULL means get next tunnel */ | ||
44 | }; | ||
45 | |||
46 | static void l2tp_dfs_next_tunnel(struct l2tp_dfs_seq_data *pd) | ||
47 | { | ||
48 | pd->tunnel = l2tp_tunnel_find_nth(pd->net, pd->tunnel_idx); | ||
49 | pd->tunnel_idx++; | ||
50 | } | ||
51 | |||
52 | static void l2tp_dfs_next_session(struct l2tp_dfs_seq_data *pd) | ||
53 | { | ||
54 | pd->session = l2tp_session_find_nth(pd->tunnel, pd->session_idx); | ||
55 | pd->session_idx++; | ||
56 | |||
57 | if (pd->session == NULL) { | ||
58 | pd->session_idx = 0; | ||
59 | l2tp_dfs_next_tunnel(pd); | ||
60 | } | ||
61 | |||
62 | } | ||
63 | |||
64 | static void *l2tp_dfs_seq_start(struct seq_file *m, loff_t *offs) | ||
65 | { | ||
66 | struct l2tp_dfs_seq_data *pd = SEQ_START_TOKEN; | ||
67 | loff_t pos = *offs; | ||
68 | |||
69 | if (!pos) | ||
70 | goto out; | ||
71 | |||
72 | BUG_ON(m->private == NULL); | ||
73 | pd = m->private; | ||
74 | |||
75 | if (pd->tunnel == NULL) | ||
76 | l2tp_dfs_next_tunnel(pd); | ||
77 | else | ||
78 | l2tp_dfs_next_session(pd); | ||
79 | |||
80 | /* NULL tunnel and session indicates end of list */ | ||
81 | if ((pd->tunnel == NULL) && (pd->session == NULL)) | ||
82 | pd = NULL; | ||
83 | |||
84 | out: | ||
85 | return pd; | ||
86 | } | ||
87 | |||
88 | |||
89 | static void *l2tp_dfs_seq_next(struct seq_file *m, void *v, loff_t *pos) | ||
90 | { | ||
91 | (*pos)++; | ||
92 | return NULL; | ||
93 | } | ||
94 | |||
95 | static void l2tp_dfs_seq_stop(struct seq_file *p, void *v) | ||
96 | { | ||
97 | /* nothing to do */ | ||
98 | } | ||
99 | |||
100 | static void l2tp_dfs_seq_tunnel_show(struct seq_file *m, void *v) | ||
101 | { | ||
102 | struct l2tp_tunnel *tunnel = v; | ||
103 | int session_count = 0; | ||
104 | int hash; | ||
105 | struct hlist_node *walk; | ||
106 | struct hlist_node *tmp; | ||
107 | |||
108 | read_lock_bh(&tunnel->hlist_lock); | ||
109 | for (hash = 0; hash < L2TP_HASH_SIZE; hash++) { | ||
110 | hlist_for_each_safe(walk, tmp, &tunnel->session_hlist[hash]) { | ||
111 | struct l2tp_session *session; | ||
112 | |||
113 | session = hlist_entry(walk, struct l2tp_session, hlist); | ||
114 | if (session->session_id == 0) | ||
115 | continue; | ||
116 | |||
117 | session_count++; | ||
118 | } | ||
119 | } | ||
120 | read_unlock_bh(&tunnel->hlist_lock); | ||
121 | |||
122 | seq_printf(m, "\nTUNNEL %u peer %u", tunnel->tunnel_id, tunnel->peer_tunnel_id); | ||
123 | if (tunnel->sock) { | ||
124 | struct inet_sock *inet = inet_sk(tunnel->sock); | ||
125 | seq_printf(m, " from " NIPQUAD_FMT " to " NIPQUAD_FMT "\n", | ||
126 | NIPQUAD(inet->inet_saddr), NIPQUAD(inet->inet_daddr)); | ||
127 | if (tunnel->encap == L2TP_ENCAPTYPE_UDP) | ||
128 | seq_printf(m, " source port %hu, dest port %hu\n", | ||
129 | ntohs(inet->inet_sport), ntohs(inet->inet_dport)); | ||
130 | } | ||
131 | seq_printf(m, " L2TPv%d, %s\n", tunnel->version, | ||
132 | tunnel->encap == L2TP_ENCAPTYPE_UDP ? "UDP" : | ||
133 | tunnel->encap == L2TP_ENCAPTYPE_IP ? "IP" : | ||
134 | ""); | ||
135 | seq_printf(m, " %d sessions, refcnt %d/%d\n", session_count, | ||
136 | tunnel->sock ? atomic_read(&tunnel->sock->sk_refcnt) : 0, | ||
137 | atomic_read(&tunnel->ref_count)); | ||
138 | |||
139 | seq_printf(m, " %08x rx %llu/%llu/%llu rx %llu/%llu/%llu\n", | ||
140 | tunnel->debug, | ||
141 | (unsigned long long)tunnel->stats.tx_packets, | ||
142 | (unsigned long long)tunnel->stats.tx_bytes, | ||
143 | (unsigned long long)tunnel->stats.tx_errors, | ||
144 | (unsigned long long)tunnel->stats.rx_packets, | ||
145 | (unsigned long long)tunnel->stats.rx_bytes, | ||
146 | (unsigned long long)tunnel->stats.rx_errors); | ||
147 | |||
148 | if (tunnel->show != NULL) | ||
149 | tunnel->show(m, tunnel); | ||
150 | } | ||
151 | |||
152 | static void l2tp_dfs_seq_session_show(struct seq_file *m, void *v) | ||
153 | { | ||
154 | struct l2tp_session *session = v; | ||
155 | |||
156 | seq_printf(m, " SESSION %u, peer %u, %s\n", session->session_id, | ||
157 | session->peer_session_id, | ||
158 | session->pwtype == L2TP_PWTYPE_ETH ? "ETH" : | ||
159 | session->pwtype == L2TP_PWTYPE_PPP ? "PPP" : | ||
160 | ""); | ||
161 | if (session->send_seq || session->recv_seq) | ||
162 | seq_printf(m, " nr %hu, ns %hu\n", session->nr, session->ns); | ||
163 | seq_printf(m, " refcnt %d\n", atomic_read(&session->ref_count)); | ||
164 | seq_printf(m, " config %d/%d/%c/%c/%s/%s %08x %u\n", | ||
165 | session->mtu, session->mru, | ||
166 | session->recv_seq ? 'R' : '-', | ||
167 | session->send_seq ? 'S' : '-', | ||
168 | session->data_seq == 1 ? "IPSEQ" : | ||
169 | session->data_seq == 2 ? "DATASEQ" : "-", | ||
170 | session->lns_mode ? "LNS" : "LAC", | ||
171 | session->debug, | ||
172 | jiffies_to_msecs(session->reorder_timeout)); | ||
173 | seq_printf(m, " offset %hu l2specific %hu/%hu\n", | ||
174 | session->offset, session->l2specific_type, session->l2specific_len); | ||
175 | if (session->cookie_len) { | ||
176 | seq_printf(m, " cookie %02x%02x%02x%02x", | ||
177 | session->cookie[0], session->cookie[1], | ||
178 | session->cookie[2], session->cookie[3]); | ||
179 | if (session->cookie_len == 8) | ||
180 | seq_printf(m, "%02x%02x%02x%02x", | ||
181 | session->cookie[4], session->cookie[5], | ||
182 | session->cookie[6], session->cookie[7]); | ||
183 | seq_printf(m, "\n"); | ||
184 | } | ||
185 | if (session->peer_cookie_len) { | ||
186 | seq_printf(m, " peer cookie %02x%02x%02x%02x", | ||
187 | session->peer_cookie[0], session->peer_cookie[1], | ||
188 | session->peer_cookie[2], session->peer_cookie[3]); | ||
189 | if (session->peer_cookie_len == 8) | ||
190 | seq_printf(m, "%02x%02x%02x%02x", | ||
191 | session->peer_cookie[4], session->peer_cookie[5], | ||
192 | session->peer_cookie[6], session->peer_cookie[7]); | ||
193 | seq_printf(m, "\n"); | ||
194 | } | ||
195 | |||
196 | seq_printf(m, " %hu/%hu tx %llu/%llu/%llu rx %llu/%llu/%llu\n", | ||
197 | session->nr, session->ns, | ||
198 | (unsigned long long)session->stats.tx_packets, | ||
199 | (unsigned long long)session->stats.tx_bytes, | ||
200 | (unsigned long long)session->stats.tx_errors, | ||
201 | (unsigned long long)session->stats.rx_packets, | ||
202 | (unsigned long long)session->stats.rx_bytes, | ||
203 | (unsigned long long)session->stats.rx_errors); | ||
204 | |||
205 | if (session->show != NULL) | ||
206 | session->show(m, session); | ||
207 | } | ||
208 | |||
209 | static int l2tp_dfs_seq_show(struct seq_file *m, void *v) | ||
210 | { | ||
211 | struct l2tp_dfs_seq_data *pd = v; | ||
212 | |||
213 | /* display header on line 1 */ | ||
214 | if (v == SEQ_START_TOKEN) { | ||
215 | seq_puts(m, "TUNNEL ID, peer ID from IP to IP\n"); | ||
216 | seq_puts(m, " L2TPv2/L2TPv3, UDP/IP\n"); | ||
217 | seq_puts(m, " sessions session-count, refcnt refcnt/sk->refcnt\n"); | ||
218 | seq_puts(m, " debug tx-pkts/bytes/errs rx-pkts/bytes/errs\n"); | ||
219 | seq_puts(m, " SESSION ID, peer ID, PWTYPE\n"); | ||
220 | seq_puts(m, " refcnt cnt\n"); | ||
221 | seq_puts(m, " offset OFFSET l2specific TYPE/LEN\n"); | ||
222 | seq_puts(m, " [ cookie ]\n"); | ||
223 | seq_puts(m, " [ peer cookie ]\n"); | ||
224 | seq_puts(m, " config mtu/mru/rcvseq/sendseq/dataseq/lns debug reorderto\n"); | ||
225 | seq_puts(m, " nr/ns tx-pkts/bytes/errs rx-pkts/bytes/errs\n"); | ||
226 | goto out; | ||
227 | } | ||
228 | |||
229 | /* Show the tunnel or session context */ | ||
230 | if (pd->session == NULL) | ||
231 | l2tp_dfs_seq_tunnel_show(m, pd->tunnel); | ||
232 | else | ||
233 | l2tp_dfs_seq_session_show(m, pd->session); | ||
234 | |||
235 | out: | ||
236 | return 0; | ||
237 | } | ||
238 | |||
239 | static const struct seq_operations l2tp_dfs_seq_ops = { | ||
240 | .start = l2tp_dfs_seq_start, | ||
241 | .next = l2tp_dfs_seq_next, | ||
242 | .stop = l2tp_dfs_seq_stop, | ||
243 | .show = l2tp_dfs_seq_show, | ||
244 | }; | ||
245 | |||
246 | static int l2tp_dfs_seq_open(struct inode *inode, struct file *file) | ||
247 | { | ||
248 | struct l2tp_dfs_seq_data *pd; | ||
249 | struct seq_file *seq; | ||
250 | int rc = -ENOMEM; | ||
251 | |||
252 | pd = kzalloc(GFP_KERNEL, sizeof(*pd)); | ||
253 | if (pd == NULL) | ||
254 | goto out; | ||
255 | |||
256 | /* Derive the network namespace from the pid opening the | ||
257 | * file. | ||
258 | */ | ||
259 | pd->net = get_net_ns_by_pid(current->pid); | ||
260 | if (IS_ERR(pd->net)) { | ||
261 | rc = -PTR_ERR(pd->net); | ||
262 | goto err_free_pd; | ||
263 | } | ||
264 | |||
265 | rc = seq_open(file, &l2tp_dfs_seq_ops); | ||
266 | if (rc) | ||
267 | goto err_free_net; | ||
268 | |||
269 | seq = file->private_data; | ||
270 | seq->private = pd; | ||
271 | |||
272 | out: | ||
273 | return rc; | ||
274 | |||
275 | err_free_net: | ||
276 | put_net(pd->net); | ||
277 | err_free_pd: | ||
278 | kfree(pd); | ||
279 | goto out; | ||
280 | } | ||
281 | |||
282 | static int l2tp_dfs_seq_release(struct inode *inode, struct file *file) | ||
283 | { | ||
284 | struct l2tp_dfs_seq_data *pd; | ||
285 | struct seq_file *seq; | ||
286 | |||
287 | seq = file->private_data; | ||
288 | pd = seq->private; | ||
289 | if (pd->net) | ||
290 | put_net(pd->net); | ||
291 | kfree(pd); | ||
292 | seq_release(inode, file); | ||
293 | |||
294 | return 0; | ||
295 | } | ||
296 | |||
297 | static const struct file_operations l2tp_dfs_fops = { | ||
298 | .owner = THIS_MODULE, | ||
299 | .open = l2tp_dfs_seq_open, | ||
300 | .read = seq_read, | ||
301 | .llseek = seq_lseek, | ||
302 | .release = l2tp_dfs_seq_release, | ||
303 | }; | ||
304 | |||
305 | static int __init l2tp_debugfs_init(void) | ||
306 | { | ||
307 | int rc = 0; | ||
308 | |||
309 | rootdir = debugfs_create_dir("l2tp", NULL); | ||
310 | if (IS_ERR(rootdir)) { | ||
311 | rc = PTR_ERR(rootdir); | ||
312 | rootdir = NULL; | ||
313 | goto out; | ||
314 | } | ||
315 | |||
316 | tunnels = debugfs_create_file("tunnels", 0600, rootdir, NULL, &l2tp_dfs_fops); | ||
317 | if (tunnels == NULL) | ||
318 | rc = -EIO; | ||
319 | |||
320 | printk(KERN_INFO "L2TP debugfs support\n"); | ||
321 | |||
322 | out: | ||
323 | if (rc) | ||
324 | printk(KERN_WARNING "l2tp debugfs: unable to init\n"); | ||
325 | |||
326 | return rc; | ||
327 | } | ||
328 | |||
329 | static void __exit l2tp_debugfs_exit(void) | ||
330 | { | ||
331 | debugfs_remove(tunnels); | ||
332 | debugfs_remove(rootdir); | ||
333 | } | ||
334 | |||
335 | module_init(l2tp_debugfs_init); | ||
336 | module_exit(l2tp_debugfs_exit); | ||
337 | |||
338 | MODULE_LICENSE("GPL"); | ||
339 | MODULE_AUTHOR("James Chapman <jchapman@katalix.com>"); | ||
340 | MODULE_DESCRIPTION("L2TP debugfs driver"); | ||
341 | MODULE_VERSION("1.0"); | ||
diff --git a/net/l2tp/l2tp_eth.c b/net/l2tp/l2tp_eth.c new file mode 100644 index 000000000000..ca1164afeb74 --- /dev/null +++ b/net/l2tp/l2tp_eth.c | |||
@@ -0,0 +1,361 @@ | |||
1 | /* | ||
2 | * L2TPv3 ethernet pseudowire driver | ||
3 | * | ||
4 | * Copyright (c) 2008,2009,2010 Katalix Systems Ltd | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or | ||
7 | * modify it under the terms of the GNU General Public License | ||
8 | * as published by the Free Software Foundation; either version | ||
9 | * 2 of the License, or (at your option) any later version. | ||
10 | */ | ||
11 | |||
12 | #include <linux/module.h> | ||
13 | #include <linux/skbuff.h> | ||
14 | #include <linux/socket.h> | ||
15 | #include <linux/hash.h> | ||
16 | #include <linux/l2tp.h> | ||
17 | #include <linux/in.h> | ||
18 | #include <linux/etherdevice.h> | ||
19 | #include <linux/spinlock.h> | ||
20 | #include <net/sock.h> | ||
21 | #include <net/ip.h> | ||
22 | #include <net/icmp.h> | ||
23 | #include <net/udp.h> | ||
24 | #include <net/inet_common.h> | ||
25 | #include <net/inet_hashtables.h> | ||
26 | #include <net/tcp_states.h> | ||
27 | #include <net/protocol.h> | ||
28 | #include <net/xfrm.h> | ||
29 | #include <net/net_namespace.h> | ||
30 | #include <net/netns/generic.h> | ||
31 | |||
32 | #include "l2tp_core.h" | ||
33 | |||
34 | /* Default device name. May be overridden by name specified by user */ | ||
35 | #define L2TP_ETH_DEV_NAME "l2tpeth%d" | ||
36 | |||
37 | /* via netdev_priv() */ | ||
38 | struct l2tp_eth { | ||
39 | struct net_device *dev; | ||
40 | struct sock *tunnel_sock; | ||
41 | struct l2tp_session *session; | ||
42 | struct list_head list; | ||
43 | }; | ||
44 | |||
45 | /* via l2tp_session_priv() */ | ||
46 | struct l2tp_eth_sess { | ||
47 | struct net_device *dev; | ||
48 | }; | ||
49 | |||
50 | /* per-net private data for this module */ | ||
51 | static unsigned int l2tp_eth_net_id; | ||
52 | struct l2tp_eth_net { | ||
53 | struct list_head l2tp_eth_dev_list; | ||
54 | spinlock_t l2tp_eth_lock; | ||
55 | }; | ||
56 | |||
57 | static inline struct l2tp_eth_net *l2tp_eth_pernet(struct net *net) | ||
58 | { | ||
59 | return net_generic(net, l2tp_eth_net_id); | ||
60 | } | ||
61 | |||
62 | static int l2tp_eth_dev_init(struct net_device *dev) | ||
63 | { | ||
64 | struct l2tp_eth *priv = netdev_priv(dev); | ||
65 | |||
66 | priv->dev = dev; | ||
67 | random_ether_addr(dev->dev_addr); | ||
68 | memset(&dev->broadcast[0], 0xff, 6); | ||
69 | |||
70 | return 0; | ||
71 | } | ||
72 | |||
73 | static void l2tp_eth_dev_uninit(struct net_device *dev) | ||
74 | { | ||
75 | struct l2tp_eth *priv = netdev_priv(dev); | ||
76 | struct l2tp_eth_net *pn = l2tp_eth_pernet(dev_net(dev)); | ||
77 | |||
78 | spin_lock(&pn->l2tp_eth_lock); | ||
79 | list_del_init(&priv->list); | ||
80 | spin_unlock(&pn->l2tp_eth_lock); | ||
81 | dev_put(dev); | ||
82 | } | ||
83 | |||
84 | static int l2tp_eth_dev_xmit(struct sk_buff *skb, struct net_device *dev) | ||
85 | { | ||
86 | struct l2tp_eth *priv = netdev_priv(dev); | ||
87 | struct l2tp_session *session = priv->session; | ||
88 | |||
89 | l2tp_xmit_skb(session, skb, session->hdr_len); | ||
90 | |||
91 | dev->stats.tx_bytes += skb->len; | ||
92 | dev->stats.tx_packets++; | ||
93 | |||
94 | return 0; | ||
95 | } | ||
96 | |||
97 | static struct net_device_ops l2tp_eth_netdev_ops = { | ||
98 | .ndo_init = l2tp_eth_dev_init, | ||
99 | .ndo_uninit = l2tp_eth_dev_uninit, | ||
100 | .ndo_start_xmit = l2tp_eth_dev_xmit, | ||
101 | }; | ||
102 | |||
103 | static void l2tp_eth_dev_setup(struct net_device *dev) | ||
104 | { | ||
105 | ether_setup(dev); | ||
106 | |||
107 | dev->netdev_ops = &l2tp_eth_netdev_ops; | ||
108 | dev->destructor = free_netdev; | ||
109 | } | ||
110 | |||
111 | static void l2tp_eth_dev_recv(struct l2tp_session *session, struct sk_buff *skb, int data_len) | ||
112 | { | ||
113 | struct l2tp_eth_sess *spriv = l2tp_session_priv(session); | ||
114 | struct net_device *dev = spriv->dev; | ||
115 | |||
116 | if (session->debug & L2TP_MSG_DATA) { | ||
117 | unsigned int length; | ||
118 | int offset; | ||
119 | u8 *ptr = skb->data; | ||
120 | |||
121 | length = min(32u, skb->len); | ||
122 | if (!pskb_may_pull(skb, length)) | ||
123 | goto error; | ||
124 | |||
125 | printk(KERN_DEBUG "%s: eth recv: ", session->name); | ||
126 | |||
127 | offset = 0; | ||
128 | do { | ||
129 | printk(" %02X", ptr[offset]); | ||
130 | } while (++offset < length); | ||
131 | |||
132 | printk("\n"); | ||
133 | } | ||
134 | |||
135 | if (data_len < ETH_HLEN) | ||
136 | goto error; | ||
137 | |||
138 | secpath_reset(skb); | ||
139 | |||
140 | /* checksums verified by L2TP */ | ||
141 | skb->ip_summed = CHECKSUM_NONE; | ||
142 | |||
143 | skb_dst_drop(skb); | ||
144 | nf_reset(skb); | ||
145 | |||
146 | if (dev_forward_skb(dev, skb) == NET_RX_SUCCESS) { | ||
147 | dev->last_rx = jiffies; | ||
148 | dev->stats.rx_packets++; | ||
149 | dev->stats.rx_bytes += data_len; | ||
150 | } else | ||
151 | dev->stats.rx_errors++; | ||
152 | |||
153 | return; | ||
154 | |||
155 | error: | ||
156 | dev->stats.rx_errors++; | ||
157 | kfree_skb(skb); | ||
158 | } | ||
159 | |||
160 | static void l2tp_eth_delete(struct l2tp_session *session) | ||
161 | { | ||
162 | struct l2tp_eth_sess *spriv; | ||
163 | struct net_device *dev; | ||
164 | |||
165 | if (session) { | ||
166 | spriv = l2tp_session_priv(session); | ||
167 | dev = spriv->dev; | ||
168 | if (dev) { | ||
169 | unregister_netdev(dev); | ||
170 | spriv->dev = NULL; | ||
171 | } | ||
172 | } | ||
173 | } | ||
174 | |||
175 | #if defined(CONFIG_L2TP_DEBUGFS) || defined(CONFIG_L2TP_DEBUGFS_MODULE) | ||
176 | static void l2tp_eth_show(struct seq_file *m, void *arg) | ||
177 | { | ||
178 | struct l2tp_session *session = arg; | ||
179 | struct l2tp_eth_sess *spriv = l2tp_session_priv(session); | ||
180 | struct net_device *dev = spriv->dev; | ||
181 | |||
182 | seq_printf(m, " interface %s\n", dev->name); | ||
183 | } | ||
184 | #endif | ||
185 | |||
186 | static int l2tp_eth_create(struct net *net, u32 tunnel_id, u32 session_id, u32 peer_session_id, struct l2tp_session_cfg *cfg) | ||
187 | { | ||
188 | struct net_device *dev; | ||
189 | char name[IFNAMSIZ]; | ||
190 | struct l2tp_tunnel *tunnel; | ||
191 | struct l2tp_session *session; | ||
192 | struct l2tp_eth *priv; | ||
193 | struct l2tp_eth_sess *spriv; | ||
194 | int rc; | ||
195 | struct l2tp_eth_net *pn; | ||
196 | |||
197 | tunnel = l2tp_tunnel_find(net, tunnel_id); | ||
198 | if (!tunnel) { | ||
199 | rc = -ENODEV; | ||
200 | goto out; | ||
201 | } | ||
202 | |||
203 | session = l2tp_session_find(net, tunnel, session_id); | ||
204 | if (session) { | ||
205 | rc = -EEXIST; | ||
206 | goto out; | ||
207 | } | ||
208 | |||
209 | if (cfg->ifname) { | ||
210 | dev = dev_get_by_name(net, cfg->ifname); | ||
211 | if (dev) { | ||
212 | dev_put(dev); | ||
213 | rc = -EEXIST; | ||
214 | goto out; | ||
215 | } | ||
216 | strlcpy(name, cfg->ifname, IFNAMSIZ); | ||
217 | } else | ||
218 | strcpy(name, L2TP_ETH_DEV_NAME); | ||
219 | |||
220 | session = l2tp_session_create(sizeof(*spriv), tunnel, session_id, | ||
221 | peer_session_id, cfg); | ||
222 | if (!session) { | ||
223 | rc = -ENOMEM; | ||
224 | goto out; | ||
225 | } | ||
226 | |||
227 | dev = alloc_netdev(sizeof(*priv), name, l2tp_eth_dev_setup); | ||
228 | if (!dev) { | ||
229 | rc = -ENOMEM; | ||
230 | goto out_del_session; | ||
231 | } | ||
232 | |||
233 | dev_net_set(dev, net); | ||
234 | if (session->mtu == 0) | ||
235 | session->mtu = dev->mtu - session->hdr_len; | ||
236 | dev->mtu = session->mtu; | ||
237 | dev->needed_headroom += session->hdr_len; | ||
238 | |||
239 | priv = netdev_priv(dev); | ||
240 | priv->dev = dev; | ||
241 | priv->session = session; | ||
242 | INIT_LIST_HEAD(&priv->list); | ||
243 | |||
244 | priv->tunnel_sock = tunnel->sock; | ||
245 | session->recv_skb = l2tp_eth_dev_recv; | ||
246 | session->session_close = l2tp_eth_delete; | ||
247 | #if defined(CONFIG_L2TP_DEBUGFS) || defined(CONFIG_L2TP_DEBUGFS_MODULE) | ||
248 | session->show = l2tp_eth_show; | ||
249 | #endif | ||
250 | |||
251 | spriv = l2tp_session_priv(session); | ||
252 | spriv->dev = dev; | ||
253 | |||
254 | rc = register_netdev(dev); | ||
255 | if (rc < 0) | ||
256 | goto out_del_dev; | ||
257 | |||
258 | /* Must be done after register_netdev() */ | ||
259 | strlcpy(session->ifname, dev->name, IFNAMSIZ); | ||
260 | |||
261 | dev_hold(dev); | ||
262 | pn = l2tp_eth_pernet(dev_net(dev)); | ||
263 | spin_lock(&pn->l2tp_eth_lock); | ||
264 | list_add(&priv->list, &pn->l2tp_eth_dev_list); | ||
265 | spin_unlock(&pn->l2tp_eth_lock); | ||
266 | |||
267 | return 0; | ||
268 | |||
269 | out_del_dev: | ||
270 | free_netdev(dev); | ||
271 | out_del_session: | ||
272 | l2tp_session_delete(session); | ||
273 | out: | ||
274 | return rc; | ||
275 | } | ||
276 | |||
277 | static __net_init int l2tp_eth_init_net(struct net *net) | ||
278 | { | ||
279 | struct l2tp_eth_net *pn; | ||
280 | int err; | ||
281 | |||
282 | pn = kzalloc(sizeof(*pn), GFP_KERNEL); | ||
283 | if (!pn) | ||
284 | return -ENOMEM; | ||
285 | |||
286 | INIT_LIST_HEAD(&pn->l2tp_eth_dev_list); | ||
287 | spin_lock_init(&pn->l2tp_eth_lock); | ||
288 | |||
289 | err = net_assign_generic(net, l2tp_eth_net_id, pn); | ||
290 | if (err) | ||
291 | goto out; | ||
292 | |||
293 | return 0; | ||
294 | |||
295 | out: | ||
296 | kfree(pn); | ||
297 | return err; | ||
298 | } | ||
299 | |||
300 | static __net_exit void l2tp_eth_exit_net(struct net *net) | ||
301 | { | ||
302 | struct l2tp_eth_net *pn; | ||
303 | |||
304 | pn = net_generic(net, l2tp_eth_net_id); | ||
305 | /* | ||
306 | * if someone has cached our net then | ||
307 | * further net_generic call will return NULL | ||
308 | */ | ||
309 | net_assign_generic(net, l2tp_eth_net_id, NULL); | ||
310 | kfree(pn); | ||
311 | } | ||
312 | |||
313 | static __net_initdata struct pernet_operations l2tp_eth_net_ops = { | ||
314 | .init = l2tp_eth_init_net, | ||
315 | .exit = l2tp_eth_exit_net, | ||
316 | .id = &l2tp_eth_net_id, | ||
317 | .size = sizeof(struct l2tp_eth_net), | ||
318 | }; | ||
319 | |||
320 | |||
321 | static const struct l2tp_nl_cmd_ops l2tp_eth_nl_cmd_ops = { | ||
322 | .session_create = l2tp_eth_create, | ||
323 | .session_delete = l2tp_session_delete, | ||
324 | }; | ||
325 | |||
326 | |||
327 | static int __init l2tp_eth_init(void) | ||
328 | { | ||
329 | int err = 0; | ||
330 | |||
331 | err = l2tp_nl_register_ops(L2TP_PWTYPE_ETH, &l2tp_eth_nl_cmd_ops); | ||
332 | if (err) | ||
333 | goto out; | ||
334 | |||
335 | err = register_pernet_device(&l2tp_eth_net_ops); | ||
336 | if (err) | ||
337 | goto out_unreg; | ||
338 | |||
339 | printk(KERN_INFO "L2TP ethernet pseudowire support (L2TPv3)\n"); | ||
340 | |||
341 | return 0; | ||
342 | |||
343 | out_unreg: | ||
344 | l2tp_nl_unregister_ops(L2TP_PWTYPE_ETH); | ||
345 | out: | ||
346 | return err; | ||
347 | } | ||
348 | |||
349 | static void __exit l2tp_eth_exit(void) | ||
350 | { | ||
351 | unregister_pernet_device(&l2tp_eth_net_ops); | ||
352 | l2tp_nl_unregister_ops(L2TP_PWTYPE_ETH); | ||
353 | } | ||
354 | |||
355 | module_init(l2tp_eth_init); | ||
356 | module_exit(l2tp_eth_exit); | ||
357 | |||
358 | MODULE_LICENSE("GPL"); | ||
359 | MODULE_AUTHOR("James Chapman <jchapman@katalix.com>"); | ||
360 | MODULE_DESCRIPTION("L2TP ethernet pseudowire driver"); | ||
361 | MODULE_VERSION("1.0"); | ||
diff --git a/net/l2tp/l2tp_ip.c b/net/l2tp/l2tp_ip.c new file mode 100644 index 000000000000..75bf784ba18d --- /dev/null +++ b/net/l2tp/l2tp_ip.c | |||
@@ -0,0 +1,679 @@ | |||
1 | /* | ||
2 | * L2TPv3 IP encapsulation support | ||
3 | * | ||
4 | * Copyright (c) 2008,2009,2010 Katalix Systems Ltd | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or | ||
7 | * modify it under the terms of the GNU General Public License | ||
8 | * as published by the Free Software Foundation; either version | ||
9 | * 2 of the License, or (at your option) any later version. | ||
10 | */ | ||
11 | |||
12 | #include <linux/icmp.h> | ||
13 | #include <linux/module.h> | ||
14 | #include <linux/skbuff.h> | ||
15 | #include <linux/random.h> | ||
16 | #include <linux/socket.h> | ||
17 | #include <linux/l2tp.h> | ||
18 | #include <linux/in.h> | ||
19 | #include <net/sock.h> | ||
20 | #include <net/ip.h> | ||
21 | #include <net/icmp.h> | ||
22 | #include <net/udp.h> | ||
23 | #include <net/inet_common.h> | ||
24 | #include <net/inet_hashtables.h> | ||
25 | #include <net/tcp_states.h> | ||
26 | #include <net/protocol.h> | ||
27 | #include <net/xfrm.h> | ||
28 | |||
29 | #include "l2tp_core.h" | ||
30 | |||
31 | struct l2tp_ip_sock { | ||
32 | /* inet_sock has to be the first member of l2tp_ip_sock */ | ||
33 | struct inet_sock inet; | ||
34 | |||
35 | __u32 conn_id; | ||
36 | __u32 peer_conn_id; | ||
37 | |||
38 | __u64 tx_packets; | ||
39 | __u64 tx_bytes; | ||
40 | __u64 tx_errors; | ||
41 | __u64 rx_packets; | ||
42 | __u64 rx_bytes; | ||
43 | __u64 rx_errors; | ||
44 | }; | ||
45 | |||
46 | static DEFINE_RWLOCK(l2tp_ip_lock); | ||
47 | static struct hlist_head l2tp_ip_table; | ||
48 | static struct hlist_head l2tp_ip_bind_table; | ||
49 | |||
50 | static inline struct l2tp_ip_sock *l2tp_ip_sk(const struct sock *sk) | ||
51 | { | ||
52 | return (struct l2tp_ip_sock *)sk; | ||
53 | } | ||
54 | |||
55 | static struct sock *__l2tp_ip_bind_lookup(struct net *net, __be32 laddr, int dif, u32 tunnel_id) | ||
56 | { | ||
57 | struct hlist_node *node; | ||
58 | struct sock *sk; | ||
59 | |||
60 | sk_for_each_bound(sk, node, &l2tp_ip_bind_table) { | ||
61 | struct inet_sock *inet = inet_sk(sk); | ||
62 | struct l2tp_ip_sock *l2tp = l2tp_ip_sk(sk); | ||
63 | |||
64 | if (l2tp == NULL) | ||
65 | continue; | ||
66 | |||
67 | if ((l2tp->conn_id == tunnel_id) && | ||
68 | #ifdef CONFIG_NET_NS | ||
69 | (sk->sk_net == net) && | ||
70 | #endif | ||
71 | !(inet->inet_rcv_saddr && inet->inet_rcv_saddr != laddr) && | ||
72 | !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif)) | ||
73 | goto found; | ||
74 | } | ||
75 | |||
76 | sk = NULL; | ||
77 | found: | ||
78 | return sk; | ||
79 | } | ||
80 | |||
81 | static inline struct sock *l2tp_ip_bind_lookup(struct net *net, __be32 laddr, int dif, u32 tunnel_id) | ||
82 | { | ||
83 | struct sock *sk = __l2tp_ip_bind_lookup(net, laddr, dif, tunnel_id); | ||
84 | if (sk) | ||
85 | sock_hold(sk); | ||
86 | |||
87 | return sk; | ||
88 | } | ||
89 | |||
90 | /* When processing receive frames, there are two cases to | ||
91 | * consider. Data frames consist of a non-zero session-id and an | ||
92 | * optional cookie. Control frames consist of a regular L2TP header | ||
93 | * preceded by 32-bits of zeros. | ||
94 | * | ||
95 | * L2TPv3 Session Header Over IP | ||
96 | * | ||
97 | * 0 1 2 3 | ||
98 | * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 | ||
99 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
100 | * | Session ID | | ||
101 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
102 | * | Cookie (optional, maximum 64 bits)... | ||
103 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
104 | * | | ||
105 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
106 | * | ||
107 | * L2TPv3 Control Message Header Over IP | ||
108 | * | ||
109 | * 0 1 2 3 | ||
110 | * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 | ||
111 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
112 | * | (32 bits of zeros) | | ||
113 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
114 | * |T|L|x|x|S|x|x|x|x|x|x|x| Ver | Length | | ||
115 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
116 | * | Control Connection ID | | ||
117 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
118 | * | Ns | Nr | | ||
119 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
120 | * | ||
121 | * All control frames are passed to userspace. | ||
122 | */ | ||
123 | static int l2tp_ip_recv(struct sk_buff *skb) | ||
124 | { | ||
125 | struct sock *sk; | ||
126 | u32 session_id; | ||
127 | u32 tunnel_id; | ||
128 | unsigned char *ptr, *optr; | ||
129 | struct l2tp_session *session; | ||
130 | struct l2tp_tunnel *tunnel = NULL; | ||
131 | int length; | ||
132 | int offset; | ||
133 | |||
134 | /* Point to L2TP header */ | ||
135 | optr = ptr = skb->data; | ||
136 | |||
137 | if (!pskb_may_pull(skb, 4)) | ||
138 | goto discard; | ||
139 | |||
140 | session_id = ntohl(*((__be32 *) ptr)); | ||
141 | ptr += 4; | ||
142 | |||
143 | /* RFC3931: L2TP/IP packets have the first 4 bytes containing | ||
144 | * the session_id. If it is 0, the packet is a L2TP control | ||
145 | * frame and the session_id value can be discarded. | ||
146 | */ | ||
147 | if (session_id == 0) { | ||
148 | __skb_pull(skb, 4); | ||
149 | goto pass_up; | ||
150 | } | ||
151 | |||
152 | /* Ok, this is a data packet. Lookup the session. */ | ||
153 | session = l2tp_session_find(&init_net, NULL, session_id); | ||
154 | if (session == NULL) | ||
155 | goto discard; | ||
156 | |||
157 | tunnel = session->tunnel; | ||
158 | if (tunnel == NULL) | ||
159 | goto discard; | ||
160 | |||
161 | /* Trace packet contents, if enabled */ | ||
162 | if (tunnel->debug & L2TP_MSG_DATA) { | ||
163 | length = min(32u, skb->len); | ||
164 | if (!pskb_may_pull(skb, length)) | ||
165 | goto discard; | ||
166 | |||
167 | printk(KERN_DEBUG "%s: ip recv: ", tunnel->name); | ||
168 | |||
169 | offset = 0; | ||
170 | do { | ||
171 | printk(" %02X", ptr[offset]); | ||
172 | } while (++offset < length); | ||
173 | |||
174 | printk("\n"); | ||
175 | } | ||
176 | |||
177 | l2tp_recv_common(session, skb, ptr, optr, 0, skb->len, tunnel->recv_payload_hook); | ||
178 | |||
179 | return 0; | ||
180 | |||
181 | pass_up: | ||
182 | /* Get the tunnel_id from the L2TP header */ | ||
183 | if (!pskb_may_pull(skb, 12)) | ||
184 | goto discard; | ||
185 | |||
186 | if ((skb->data[0] & 0xc0) != 0xc0) | ||
187 | goto discard; | ||
188 | |||
189 | tunnel_id = ntohl(*(__be32 *) &skb->data[4]); | ||
190 | tunnel = l2tp_tunnel_find(&init_net, tunnel_id); | ||
191 | if (tunnel != NULL) | ||
192 | sk = tunnel->sock; | ||
193 | else { | ||
194 | struct iphdr *iph = (struct iphdr *) skb_network_header(skb); | ||
195 | |||
196 | read_lock_bh(&l2tp_ip_lock); | ||
197 | sk = __l2tp_ip_bind_lookup(&init_net, iph->daddr, 0, tunnel_id); | ||
198 | read_unlock_bh(&l2tp_ip_lock); | ||
199 | } | ||
200 | |||
201 | if (sk == NULL) | ||
202 | goto discard; | ||
203 | |||
204 | sock_hold(sk); | ||
205 | |||
206 | if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) | ||
207 | goto discard_put; | ||
208 | |||
209 | nf_reset(skb); | ||
210 | |||
211 | return sk_receive_skb(sk, skb, 1); | ||
212 | |||
213 | discard_put: | ||
214 | sock_put(sk); | ||
215 | |||
216 | discard: | ||
217 | kfree_skb(skb); | ||
218 | return 0; | ||
219 | } | ||
220 | |||
221 | static int l2tp_ip_open(struct sock *sk) | ||
222 | { | ||
223 | /* Prevent autobind. We don't have ports. */ | ||
224 | inet_sk(sk)->inet_num = IPPROTO_L2TP; | ||
225 | |||
226 | write_lock_bh(&l2tp_ip_lock); | ||
227 | sk_add_node(sk, &l2tp_ip_table); | ||
228 | write_unlock_bh(&l2tp_ip_lock); | ||
229 | |||
230 | return 0; | ||
231 | } | ||
232 | |||
233 | static void l2tp_ip_close(struct sock *sk, long timeout) | ||
234 | { | ||
235 | write_lock_bh(&l2tp_ip_lock); | ||
236 | hlist_del_init(&sk->sk_bind_node); | ||
237 | hlist_del_init(&sk->sk_node); | ||
238 | write_unlock_bh(&l2tp_ip_lock); | ||
239 | sk_common_release(sk); | ||
240 | } | ||
241 | |||
242 | static void l2tp_ip_destroy_sock(struct sock *sk) | ||
243 | { | ||
244 | struct sk_buff *skb; | ||
245 | |||
246 | while ((skb = __skb_dequeue_tail(&sk->sk_write_queue)) != NULL) | ||
247 | kfree_skb(skb); | ||
248 | |||
249 | sk_refcnt_debug_dec(sk); | ||
250 | } | ||
251 | |||
252 | static int l2tp_ip_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len) | ||
253 | { | ||
254 | struct inet_sock *inet = inet_sk(sk); | ||
255 | struct sockaddr_l2tpip *addr = (struct sockaddr_l2tpip *) uaddr; | ||
256 | int ret = -EINVAL; | ||
257 | int chk_addr_ret; | ||
258 | |||
259 | ret = -EADDRINUSE; | ||
260 | read_lock_bh(&l2tp_ip_lock); | ||
261 | if (__l2tp_ip_bind_lookup(&init_net, addr->l2tp_addr.s_addr, sk->sk_bound_dev_if, addr->l2tp_conn_id)) | ||
262 | goto out_in_use; | ||
263 | |||
264 | read_unlock_bh(&l2tp_ip_lock); | ||
265 | |||
266 | lock_sock(sk); | ||
267 | if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_l2tpip)) | ||
268 | goto out; | ||
269 | |||
270 | chk_addr_ret = inet_addr_type(&init_net, addr->l2tp_addr.s_addr); | ||
271 | ret = -EADDRNOTAVAIL; | ||
272 | if (addr->l2tp_addr.s_addr && chk_addr_ret != RTN_LOCAL && | ||
273 | chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST) | ||
274 | goto out; | ||
275 | |||
276 | inet->inet_rcv_saddr = inet->inet_saddr = addr->l2tp_addr.s_addr; | ||
277 | if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST) | ||
278 | inet->inet_saddr = 0; /* Use device */ | ||
279 | sk_dst_reset(sk); | ||
280 | |||
281 | l2tp_ip_sk(sk)->conn_id = addr->l2tp_conn_id; | ||
282 | |||
283 | write_lock_bh(&l2tp_ip_lock); | ||
284 | sk_add_bind_node(sk, &l2tp_ip_bind_table); | ||
285 | sk_del_node_init(sk); | ||
286 | write_unlock_bh(&l2tp_ip_lock); | ||
287 | ret = 0; | ||
288 | out: | ||
289 | release_sock(sk); | ||
290 | |||
291 | return ret; | ||
292 | |||
293 | out_in_use: | ||
294 | read_unlock_bh(&l2tp_ip_lock); | ||
295 | |||
296 | return ret; | ||
297 | } | ||
298 | |||
299 | static int l2tp_ip_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len) | ||
300 | { | ||
301 | int rc; | ||
302 | struct inet_sock *inet = inet_sk(sk); | ||
303 | struct sockaddr_l2tpip *lsa = (struct sockaddr_l2tpip *) uaddr; | ||
304 | struct rtable *rt; | ||
305 | __be32 saddr; | ||
306 | int oif; | ||
307 | |||
308 | rc = -EINVAL; | ||
309 | if (addr_len < sizeof(*lsa)) | ||
310 | goto out; | ||
311 | |||
312 | rc = -EAFNOSUPPORT; | ||
313 | if (lsa->l2tp_family != AF_INET) | ||
314 | goto out; | ||
315 | |||
316 | sk_dst_reset(sk); | ||
317 | |||
318 | oif = sk->sk_bound_dev_if; | ||
319 | saddr = inet->inet_saddr; | ||
320 | |||
321 | rc = -EINVAL; | ||
322 | if (ipv4_is_multicast(lsa->l2tp_addr.s_addr)) | ||
323 | goto out; | ||
324 | |||
325 | rc = ip_route_connect(&rt, lsa->l2tp_addr.s_addr, saddr, | ||
326 | RT_CONN_FLAGS(sk), oif, | ||
327 | IPPROTO_L2TP, | ||
328 | 0, 0, sk, 1); | ||
329 | if (rc) { | ||
330 | if (rc == -ENETUNREACH) | ||
331 | IP_INC_STATS_BH(&init_net, IPSTATS_MIB_OUTNOROUTES); | ||
332 | goto out; | ||
333 | } | ||
334 | |||
335 | rc = -ENETUNREACH; | ||
336 | if (rt->rt_flags & (RTCF_MULTICAST | RTCF_BROADCAST)) { | ||
337 | ip_rt_put(rt); | ||
338 | goto out; | ||
339 | } | ||
340 | |||
341 | l2tp_ip_sk(sk)->peer_conn_id = lsa->l2tp_conn_id; | ||
342 | |||
343 | if (!inet->inet_saddr) | ||
344 | inet->inet_saddr = rt->rt_src; | ||
345 | if (!inet->inet_rcv_saddr) | ||
346 | inet->inet_rcv_saddr = rt->rt_src; | ||
347 | inet->inet_daddr = rt->rt_dst; | ||
348 | sk->sk_state = TCP_ESTABLISHED; | ||
349 | inet->inet_id = jiffies; | ||
350 | |||
351 | sk_dst_set(sk, &rt->u.dst); | ||
352 | |||
353 | write_lock_bh(&l2tp_ip_lock); | ||
354 | hlist_del_init(&sk->sk_bind_node); | ||
355 | sk_add_bind_node(sk, &l2tp_ip_bind_table); | ||
356 | write_unlock_bh(&l2tp_ip_lock); | ||
357 | |||
358 | rc = 0; | ||
359 | out: | ||
360 | return rc; | ||
361 | } | ||
362 | |||
363 | static int l2tp_ip_getname(struct socket *sock, struct sockaddr *uaddr, | ||
364 | int *uaddr_len, int peer) | ||
365 | { | ||
366 | struct sock *sk = sock->sk; | ||
367 | struct inet_sock *inet = inet_sk(sk); | ||
368 | struct l2tp_ip_sock *lsk = l2tp_ip_sk(sk); | ||
369 | struct sockaddr_l2tpip *lsa = (struct sockaddr_l2tpip *)uaddr; | ||
370 | |||
371 | memset(lsa, 0, sizeof(*lsa)); | ||
372 | lsa->l2tp_family = AF_INET; | ||
373 | if (peer) { | ||
374 | if (!inet->inet_dport) | ||
375 | return -ENOTCONN; | ||
376 | lsa->l2tp_conn_id = lsk->peer_conn_id; | ||
377 | lsa->l2tp_addr.s_addr = inet->inet_daddr; | ||
378 | } else { | ||
379 | __be32 addr = inet->inet_rcv_saddr; | ||
380 | if (!addr) | ||
381 | addr = inet->inet_saddr; | ||
382 | lsa->l2tp_conn_id = lsk->conn_id; | ||
383 | lsa->l2tp_addr.s_addr = addr; | ||
384 | } | ||
385 | *uaddr_len = sizeof(*lsa); | ||
386 | return 0; | ||
387 | } | ||
388 | |||
389 | static int l2tp_ip_backlog_recv(struct sock *sk, struct sk_buff *skb) | ||
390 | { | ||
391 | int rc; | ||
392 | |||
393 | if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) | ||
394 | goto drop; | ||
395 | |||
396 | nf_reset(skb); | ||
397 | |||
398 | /* Charge it to the socket, dropping if the queue is full. */ | ||
399 | rc = sock_queue_rcv_skb(sk, skb); | ||
400 | if (rc < 0) | ||
401 | goto drop; | ||
402 | |||
403 | return 0; | ||
404 | |||
405 | drop: | ||
406 | IP_INC_STATS(&init_net, IPSTATS_MIB_INDISCARDS); | ||
407 | kfree_skb(skb); | ||
408 | return -1; | ||
409 | } | ||
410 | |||
411 | /* Userspace will call sendmsg() on the tunnel socket to send L2TP | ||
412 | * control frames. | ||
413 | */ | ||
414 | static int l2tp_ip_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg, size_t len) | ||
415 | { | ||
416 | struct sk_buff *skb; | ||
417 | int rc; | ||
418 | struct l2tp_ip_sock *lsa = l2tp_ip_sk(sk); | ||
419 | struct inet_sock *inet = inet_sk(sk); | ||
420 | struct ip_options *opt = inet->opt; | ||
421 | struct rtable *rt = NULL; | ||
422 | int connected = 0; | ||
423 | __be32 daddr; | ||
424 | |||
425 | if (sock_flag(sk, SOCK_DEAD)) | ||
426 | return -ENOTCONN; | ||
427 | |||
428 | /* Get and verify the address. */ | ||
429 | if (msg->msg_name) { | ||
430 | struct sockaddr_l2tpip *lip = (struct sockaddr_l2tpip *) msg->msg_name; | ||
431 | if (msg->msg_namelen < sizeof(*lip)) | ||
432 | return -EINVAL; | ||
433 | |||
434 | if (lip->l2tp_family != AF_INET) { | ||
435 | if (lip->l2tp_family != AF_UNSPEC) | ||
436 | return -EAFNOSUPPORT; | ||
437 | } | ||
438 | |||
439 | daddr = lip->l2tp_addr.s_addr; | ||
440 | } else { | ||
441 | if (sk->sk_state != TCP_ESTABLISHED) | ||
442 | return -EDESTADDRREQ; | ||
443 | |||
444 | daddr = inet->inet_daddr; | ||
445 | connected = 1; | ||
446 | } | ||
447 | |||
448 | /* Allocate a socket buffer */ | ||
449 | rc = -ENOMEM; | ||
450 | skb = sock_wmalloc(sk, 2 + NET_SKB_PAD + sizeof(struct iphdr) + | ||
451 | 4 + len, 0, GFP_KERNEL); | ||
452 | if (!skb) | ||
453 | goto error; | ||
454 | |||
455 | /* Reserve space for headers, putting IP header on 4-byte boundary. */ | ||
456 | skb_reserve(skb, 2 + NET_SKB_PAD); | ||
457 | skb_reset_network_header(skb); | ||
458 | skb_reserve(skb, sizeof(struct iphdr)); | ||
459 | skb_reset_transport_header(skb); | ||
460 | |||
461 | /* Insert 0 session_id */ | ||
462 | *((__be32 *) skb_put(skb, 4)) = 0; | ||
463 | |||
464 | /* Copy user data into skb */ | ||
465 | rc = memcpy_fromiovec(skb_put(skb, len), msg->msg_iov, len); | ||
466 | if (rc < 0) { | ||
467 | kfree_skb(skb); | ||
468 | goto error; | ||
469 | } | ||
470 | |||
471 | if (connected) | ||
472 | rt = (struct rtable *) __sk_dst_check(sk, 0); | ||
473 | |||
474 | if (rt == NULL) { | ||
475 | /* Use correct destination address if we have options. */ | ||
476 | if (opt && opt->srr) | ||
477 | daddr = opt->faddr; | ||
478 | |||
479 | { | ||
480 | struct flowi fl = { .oif = sk->sk_bound_dev_if, | ||
481 | .nl_u = { .ip4_u = { | ||
482 | .daddr = daddr, | ||
483 | .saddr = inet->inet_saddr, | ||
484 | .tos = RT_CONN_FLAGS(sk) } }, | ||
485 | .proto = sk->sk_protocol, | ||
486 | .flags = inet_sk_flowi_flags(sk), | ||
487 | .uli_u = { .ports = { | ||
488 | .sport = inet->inet_sport, | ||
489 | .dport = inet->inet_dport } } }; | ||
490 | |||
491 | /* If this fails, retransmit mechanism of transport layer will | ||
492 | * keep trying until route appears or the connection times | ||
493 | * itself out. | ||
494 | */ | ||
495 | security_sk_classify_flow(sk, &fl); | ||
496 | if (ip_route_output_flow(sock_net(sk), &rt, &fl, sk, 0)) | ||
497 | goto no_route; | ||
498 | } | ||
499 | sk_setup_caps(sk, &rt->u.dst); | ||
500 | } | ||
501 | skb_dst_set(skb, dst_clone(&rt->u.dst)); | ||
502 | |||
503 | /* Queue the packet to IP for output */ | ||
504 | rc = ip_queue_xmit(skb, 0); | ||
505 | |||
506 | error: | ||
507 | /* Update stats */ | ||
508 | if (rc >= 0) { | ||
509 | lsa->tx_packets++; | ||
510 | lsa->tx_bytes += len; | ||
511 | rc = len; | ||
512 | } else { | ||
513 | lsa->tx_errors++; | ||
514 | } | ||
515 | |||
516 | return rc; | ||
517 | |||
518 | no_route: | ||
519 | IP_INC_STATS(sock_net(sk), IPSTATS_MIB_OUTNOROUTES); | ||
520 | kfree_skb(skb); | ||
521 | return -EHOSTUNREACH; | ||
522 | } | ||
523 | |||
524 | static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg, | ||
525 | size_t len, int noblock, int flags, int *addr_len) | ||
526 | { | ||
527 | struct inet_sock *inet = inet_sk(sk); | ||
528 | struct l2tp_ip_sock *lsk = l2tp_ip_sk(sk); | ||
529 | size_t copied = 0; | ||
530 | int err = -EOPNOTSUPP; | ||
531 | struct sockaddr_in *sin = (struct sockaddr_in *)msg->msg_name; | ||
532 | struct sk_buff *skb; | ||
533 | |||
534 | if (flags & MSG_OOB) | ||
535 | goto out; | ||
536 | |||
537 | if (addr_len) | ||
538 | *addr_len = sizeof(*sin); | ||
539 | |||
540 | skb = skb_recv_datagram(sk, flags, noblock, &err); | ||
541 | if (!skb) | ||
542 | goto out; | ||
543 | |||
544 | copied = skb->len; | ||
545 | if (len < copied) { | ||
546 | msg->msg_flags |= MSG_TRUNC; | ||
547 | copied = len; | ||
548 | } | ||
549 | |||
550 | err = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied); | ||
551 | if (err) | ||
552 | goto done; | ||
553 | |||
554 | sock_recv_timestamp(msg, sk, skb); | ||
555 | |||
556 | /* Copy the address. */ | ||
557 | if (sin) { | ||
558 | sin->sin_family = AF_INET; | ||
559 | sin->sin_addr.s_addr = ip_hdr(skb)->saddr; | ||
560 | sin->sin_port = 0; | ||
561 | memset(&sin->sin_zero, 0, sizeof(sin->sin_zero)); | ||
562 | } | ||
563 | if (inet->cmsg_flags) | ||
564 | ip_cmsg_recv(msg, skb); | ||
565 | if (flags & MSG_TRUNC) | ||
566 | copied = skb->len; | ||
567 | done: | ||
568 | skb_free_datagram(sk, skb); | ||
569 | out: | ||
570 | if (err) { | ||
571 | lsk->rx_errors++; | ||
572 | return err; | ||
573 | } | ||
574 | |||
575 | lsk->rx_packets++; | ||
576 | lsk->rx_bytes += copied; | ||
577 | |||
578 | return copied; | ||
579 | } | ||
580 | |||
581 | struct proto l2tp_ip_prot = { | ||
582 | .name = "L2TP/IP", | ||
583 | .owner = THIS_MODULE, | ||
584 | .init = l2tp_ip_open, | ||
585 | .close = l2tp_ip_close, | ||
586 | .bind = l2tp_ip_bind, | ||
587 | .connect = l2tp_ip_connect, | ||
588 | .disconnect = udp_disconnect, | ||
589 | .ioctl = udp_ioctl, | ||
590 | .destroy = l2tp_ip_destroy_sock, | ||
591 | .setsockopt = ip_setsockopt, | ||
592 | .getsockopt = ip_getsockopt, | ||
593 | .sendmsg = l2tp_ip_sendmsg, | ||
594 | .recvmsg = l2tp_ip_recvmsg, | ||
595 | .backlog_rcv = l2tp_ip_backlog_recv, | ||
596 | .hash = inet_hash, | ||
597 | .unhash = inet_unhash, | ||
598 | .obj_size = sizeof(struct l2tp_ip_sock), | ||
599 | #ifdef CONFIG_COMPAT | ||
600 | .compat_setsockopt = compat_ip_setsockopt, | ||
601 | .compat_getsockopt = compat_ip_getsockopt, | ||
602 | #endif | ||
603 | }; | ||
604 | |||
605 | static const struct proto_ops l2tp_ip_ops = { | ||
606 | .family = PF_INET, | ||
607 | .owner = THIS_MODULE, | ||
608 | .release = inet_release, | ||
609 | .bind = inet_bind, | ||
610 | .connect = inet_dgram_connect, | ||
611 | .socketpair = sock_no_socketpair, | ||
612 | .accept = sock_no_accept, | ||
613 | .getname = l2tp_ip_getname, | ||
614 | .poll = datagram_poll, | ||
615 | .ioctl = inet_ioctl, | ||
616 | .listen = sock_no_listen, | ||
617 | .shutdown = inet_shutdown, | ||
618 | .setsockopt = sock_common_setsockopt, | ||
619 | .getsockopt = sock_common_getsockopt, | ||
620 | .sendmsg = inet_sendmsg, | ||
621 | .recvmsg = sock_common_recvmsg, | ||
622 | .mmap = sock_no_mmap, | ||
623 | .sendpage = sock_no_sendpage, | ||
624 | #ifdef CONFIG_COMPAT | ||
625 | .compat_setsockopt = compat_sock_common_setsockopt, | ||
626 | .compat_getsockopt = compat_sock_common_getsockopt, | ||
627 | #endif | ||
628 | }; | ||
629 | |||
630 | static struct inet_protosw l2tp_ip_protosw = { | ||
631 | .type = SOCK_DGRAM, | ||
632 | .protocol = IPPROTO_L2TP, | ||
633 | .prot = &l2tp_ip_prot, | ||
634 | .ops = &l2tp_ip_ops, | ||
635 | .no_check = 0, | ||
636 | }; | ||
637 | |||
638 | static struct net_protocol l2tp_ip_protocol __read_mostly = { | ||
639 | .handler = l2tp_ip_recv, | ||
640 | }; | ||
641 | |||
642 | static int __init l2tp_ip_init(void) | ||
643 | { | ||
644 | int err; | ||
645 | |||
646 | printk(KERN_INFO "L2TP IP encapsulation support (L2TPv3)\n"); | ||
647 | |||
648 | err = proto_register(&l2tp_ip_prot, 1); | ||
649 | if (err != 0) | ||
650 | goto out; | ||
651 | |||
652 | err = inet_add_protocol(&l2tp_ip_protocol, IPPROTO_L2TP); | ||
653 | if (err) | ||
654 | goto out1; | ||
655 | |||
656 | inet_register_protosw(&l2tp_ip_protosw); | ||
657 | return 0; | ||
658 | |||
659 | out1: | ||
660 | proto_unregister(&l2tp_ip_prot); | ||
661 | out: | ||
662 | return err; | ||
663 | } | ||
664 | |||
665 | static void __exit l2tp_ip_exit(void) | ||
666 | { | ||
667 | inet_unregister_protosw(&l2tp_ip_protosw); | ||
668 | inet_del_protocol(&l2tp_ip_protocol, IPPROTO_L2TP); | ||
669 | proto_unregister(&l2tp_ip_prot); | ||
670 | } | ||
671 | |||
672 | module_init(l2tp_ip_init); | ||
673 | module_exit(l2tp_ip_exit); | ||
674 | |||
675 | MODULE_LICENSE("GPL"); | ||
676 | MODULE_AUTHOR("James Chapman <jchapman@katalix.com>"); | ||
677 | MODULE_DESCRIPTION("L2TP over IP"); | ||
678 | MODULE_VERSION("1.0"); | ||
679 | MODULE_ALIAS_NET_PF_PROTO_TYPE(PF_INET, SOCK_DGRAM, IPPROTO_L2TP); | ||
diff --git a/net/l2tp/l2tp_netlink.c b/net/l2tp/l2tp_netlink.c new file mode 100644 index 000000000000..4c1e540732d7 --- /dev/null +++ b/net/l2tp/l2tp_netlink.c | |||
@@ -0,0 +1,840 @@ | |||
1 | /* | ||
2 | * L2TP netlink layer, for management | ||
3 | * | ||
4 | * Copyright (c) 2008,2009,2010 Katalix Systems Ltd | ||
5 | * | ||
6 | * Partly based on the IrDA nelink implementation | ||
7 | * (see net/irda/irnetlink.c) which is: | ||
8 | * Copyright (c) 2007 Samuel Ortiz <samuel@sortiz.org> | ||
9 | * which is in turn partly based on the wireless netlink code: | ||
10 | * Copyright 2006 Johannes Berg <johannes@sipsolutions.net> | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or modify | ||
13 | * it under the terms of the GNU General Public License version 2 as | ||
14 | * published by the Free Software Foundation. | ||
15 | */ | ||
16 | |||
17 | #include <net/sock.h> | ||
18 | #include <net/genetlink.h> | ||
19 | #include <net/udp.h> | ||
20 | #include <linux/in.h> | ||
21 | #include <linux/udp.h> | ||
22 | #include <linux/socket.h> | ||
23 | #include <linux/module.h> | ||
24 | #include <linux/list.h> | ||
25 | #include <net/net_namespace.h> | ||
26 | |||
27 | #include <linux/l2tp.h> | ||
28 | |||
29 | #include "l2tp_core.h" | ||
30 | |||
31 | |||
32 | static struct genl_family l2tp_nl_family = { | ||
33 | .id = GENL_ID_GENERATE, | ||
34 | .name = L2TP_GENL_NAME, | ||
35 | .version = L2TP_GENL_VERSION, | ||
36 | .hdrsize = 0, | ||
37 | .maxattr = L2TP_ATTR_MAX, | ||
38 | }; | ||
39 | |||
40 | /* Accessed under genl lock */ | ||
41 | static const struct l2tp_nl_cmd_ops *l2tp_nl_cmd_ops[__L2TP_PWTYPE_MAX]; | ||
42 | |||
43 | static struct l2tp_session *l2tp_nl_session_find(struct genl_info *info) | ||
44 | { | ||
45 | u32 tunnel_id; | ||
46 | u32 session_id; | ||
47 | char *ifname; | ||
48 | struct l2tp_tunnel *tunnel; | ||
49 | struct l2tp_session *session = NULL; | ||
50 | struct net *net = genl_info_net(info); | ||
51 | |||
52 | if (info->attrs[L2TP_ATTR_IFNAME]) { | ||
53 | ifname = nla_data(info->attrs[L2TP_ATTR_IFNAME]); | ||
54 | session = l2tp_session_find_by_ifname(net, ifname); | ||
55 | } else if ((info->attrs[L2TP_ATTR_SESSION_ID]) && | ||
56 | (info->attrs[L2TP_ATTR_CONN_ID])) { | ||
57 | tunnel_id = nla_get_u32(info->attrs[L2TP_ATTR_CONN_ID]); | ||
58 | session_id = nla_get_u32(info->attrs[L2TP_ATTR_SESSION_ID]); | ||
59 | tunnel = l2tp_tunnel_find(net, tunnel_id); | ||
60 | if (tunnel) | ||
61 | session = l2tp_session_find(net, tunnel, session_id); | ||
62 | } | ||
63 | |||
64 | return session; | ||
65 | } | ||
66 | |||
67 | static int l2tp_nl_cmd_noop(struct sk_buff *skb, struct genl_info *info) | ||
68 | { | ||
69 | struct sk_buff *msg; | ||
70 | void *hdr; | ||
71 | int ret = -ENOBUFS; | ||
72 | |||
73 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); | ||
74 | if (!msg) { | ||
75 | ret = -ENOMEM; | ||
76 | goto out; | ||
77 | } | ||
78 | |||
79 | hdr = genlmsg_put(msg, info->snd_pid, info->snd_seq, | ||
80 | &l2tp_nl_family, 0, L2TP_CMD_NOOP); | ||
81 | if (IS_ERR(hdr)) { | ||
82 | ret = PTR_ERR(hdr); | ||
83 | goto err_out; | ||
84 | } | ||
85 | |||
86 | genlmsg_end(msg, hdr); | ||
87 | |||
88 | return genlmsg_unicast(genl_info_net(info), msg, info->snd_pid); | ||
89 | |||
90 | err_out: | ||
91 | nlmsg_free(msg); | ||
92 | |||
93 | out: | ||
94 | return ret; | ||
95 | } | ||
96 | |||
97 | static int l2tp_nl_cmd_tunnel_create(struct sk_buff *skb, struct genl_info *info) | ||
98 | { | ||
99 | u32 tunnel_id; | ||
100 | u32 peer_tunnel_id; | ||
101 | int proto_version; | ||
102 | int fd; | ||
103 | int ret = 0; | ||
104 | struct l2tp_tunnel_cfg cfg = { 0, }; | ||
105 | struct l2tp_tunnel *tunnel; | ||
106 | struct net *net = genl_info_net(info); | ||
107 | |||
108 | if (!info->attrs[L2TP_ATTR_CONN_ID]) { | ||
109 | ret = -EINVAL; | ||
110 | goto out; | ||
111 | } | ||
112 | tunnel_id = nla_get_u32(info->attrs[L2TP_ATTR_CONN_ID]); | ||
113 | |||
114 | if (!info->attrs[L2TP_ATTR_PEER_CONN_ID]) { | ||
115 | ret = -EINVAL; | ||
116 | goto out; | ||
117 | } | ||
118 | peer_tunnel_id = nla_get_u32(info->attrs[L2TP_ATTR_PEER_CONN_ID]); | ||
119 | |||
120 | if (!info->attrs[L2TP_ATTR_PROTO_VERSION]) { | ||
121 | ret = -EINVAL; | ||
122 | goto out; | ||
123 | } | ||
124 | proto_version = nla_get_u8(info->attrs[L2TP_ATTR_PROTO_VERSION]); | ||
125 | |||
126 | if (!info->attrs[L2TP_ATTR_ENCAP_TYPE]) { | ||
127 | ret = -EINVAL; | ||
128 | goto out; | ||
129 | } | ||
130 | cfg.encap = nla_get_u16(info->attrs[L2TP_ATTR_ENCAP_TYPE]); | ||
131 | |||
132 | fd = -1; | ||
133 | if (info->attrs[L2TP_ATTR_FD]) { | ||
134 | fd = nla_get_u32(info->attrs[L2TP_ATTR_FD]); | ||
135 | } else { | ||
136 | if (info->attrs[L2TP_ATTR_IP_SADDR]) | ||
137 | cfg.local_ip.s_addr = nla_get_be32(info->attrs[L2TP_ATTR_IP_SADDR]); | ||
138 | if (info->attrs[L2TP_ATTR_IP_DADDR]) | ||
139 | cfg.peer_ip.s_addr = nla_get_be32(info->attrs[L2TP_ATTR_IP_DADDR]); | ||
140 | if (info->attrs[L2TP_ATTR_UDP_SPORT]) | ||
141 | cfg.local_udp_port = nla_get_u16(info->attrs[L2TP_ATTR_UDP_SPORT]); | ||
142 | if (info->attrs[L2TP_ATTR_UDP_DPORT]) | ||
143 | cfg.peer_udp_port = nla_get_u16(info->attrs[L2TP_ATTR_UDP_DPORT]); | ||
144 | if (info->attrs[L2TP_ATTR_UDP_CSUM]) | ||
145 | cfg.use_udp_checksums = nla_get_flag(info->attrs[L2TP_ATTR_UDP_CSUM]); | ||
146 | } | ||
147 | |||
148 | if (info->attrs[L2TP_ATTR_DEBUG]) | ||
149 | cfg.debug = nla_get_u32(info->attrs[L2TP_ATTR_DEBUG]); | ||
150 | |||
151 | tunnel = l2tp_tunnel_find(net, tunnel_id); | ||
152 | if (tunnel != NULL) { | ||
153 | ret = -EEXIST; | ||
154 | goto out; | ||
155 | } | ||
156 | |||
157 | ret = -EINVAL; | ||
158 | switch (cfg.encap) { | ||
159 | case L2TP_ENCAPTYPE_UDP: | ||
160 | case L2TP_ENCAPTYPE_IP: | ||
161 | ret = l2tp_tunnel_create(net, fd, proto_version, tunnel_id, | ||
162 | peer_tunnel_id, &cfg, &tunnel); | ||
163 | break; | ||
164 | } | ||
165 | |||
166 | out: | ||
167 | return ret; | ||
168 | } | ||
169 | |||
170 | static int l2tp_nl_cmd_tunnel_delete(struct sk_buff *skb, struct genl_info *info) | ||
171 | { | ||
172 | struct l2tp_tunnel *tunnel; | ||
173 | u32 tunnel_id; | ||
174 | int ret = 0; | ||
175 | struct net *net = genl_info_net(info); | ||
176 | |||
177 | if (!info->attrs[L2TP_ATTR_CONN_ID]) { | ||
178 | ret = -EINVAL; | ||
179 | goto out; | ||
180 | } | ||
181 | tunnel_id = nla_get_u32(info->attrs[L2TP_ATTR_CONN_ID]); | ||
182 | |||
183 | tunnel = l2tp_tunnel_find(net, tunnel_id); | ||
184 | if (tunnel == NULL) { | ||
185 | ret = -ENODEV; | ||
186 | goto out; | ||
187 | } | ||
188 | |||
189 | (void) l2tp_tunnel_delete(tunnel); | ||
190 | |||
191 | out: | ||
192 | return ret; | ||
193 | } | ||
194 | |||
195 | static int l2tp_nl_cmd_tunnel_modify(struct sk_buff *skb, struct genl_info *info) | ||
196 | { | ||
197 | struct l2tp_tunnel *tunnel; | ||
198 | u32 tunnel_id; | ||
199 | int ret = 0; | ||
200 | struct net *net = genl_info_net(info); | ||
201 | |||
202 | if (!info->attrs[L2TP_ATTR_CONN_ID]) { | ||
203 | ret = -EINVAL; | ||
204 | goto out; | ||
205 | } | ||
206 | tunnel_id = nla_get_u32(info->attrs[L2TP_ATTR_CONN_ID]); | ||
207 | |||
208 | tunnel = l2tp_tunnel_find(net, tunnel_id); | ||
209 | if (tunnel == NULL) { | ||
210 | ret = -ENODEV; | ||
211 | goto out; | ||
212 | } | ||
213 | |||
214 | if (info->attrs[L2TP_ATTR_DEBUG]) | ||
215 | tunnel->debug = nla_get_u32(info->attrs[L2TP_ATTR_DEBUG]); | ||
216 | |||
217 | out: | ||
218 | return ret; | ||
219 | } | ||
220 | |||
221 | static int l2tp_nl_tunnel_send(struct sk_buff *skb, u32 pid, u32 seq, int flags, | ||
222 | struct l2tp_tunnel *tunnel) | ||
223 | { | ||
224 | void *hdr; | ||
225 | struct nlattr *nest; | ||
226 | struct sock *sk = NULL; | ||
227 | struct inet_sock *inet; | ||
228 | |||
229 | hdr = genlmsg_put(skb, pid, seq, &l2tp_nl_family, flags, | ||
230 | L2TP_CMD_TUNNEL_GET); | ||
231 | if (IS_ERR(hdr)) | ||
232 | return PTR_ERR(hdr); | ||
233 | |||
234 | NLA_PUT_U8(skb, L2TP_ATTR_PROTO_VERSION, tunnel->version); | ||
235 | NLA_PUT_U32(skb, L2TP_ATTR_CONN_ID, tunnel->tunnel_id); | ||
236 | NLA_PUT_U32(skb, L2TP_ATTR_PEER_CONN_ID, tunnel->peer_tunnel_id); | ||
237 | NLA_PUT_U32(skb, L2TP_ATTR_DEBUG, tunnel->debug); | ||
238 | NLA_PUT_U16(skb, L2TP_ATTR_ENCAP_TYPE, tunnel->encap); | ||
239 | |||
240 | nest = nla_nest_start(skb, L2TP_ATTR_STATS); | ||
241 | if (nest == NULL) | ||
242 | goto nla_put_failure; | ||
243 | |||
244 | NLA_PUT_U64(skb, L2TP_ATTR_TX_PACKETS, tunnel->stats.tx_packets); | ||
245 | NLA_PUT_U64(skb, L2TP_ATTR_TX_BYTES, tunnel->stats.tx_bytes); | ||
246 | NLA_PUT_U64(skb, L2TP_ATTR_TX_ERRORS, tunnel->stats.tx_errors); | ||
247 | NLA_PUT_U64(skb, L2TP_ATTR_RX_PACKETS, tunnel->stats.rx_packets); | ||
248 | NLA_PUT_U64(skb, L2TP_ATTR_RX_BYTES, tunnel->stats.rx_bytes); | ||
249 | NLA_PUT_U64(skb, L2TP_ATTR_RX_SEQ_DISCARDS, tunnel->stats.rx_seq_discards); | ||
250 | NLA_PUT_U64(skb, L2TP_ATTR_RX_OOS_PACKETS, tunnel->stats.rx_oos_packets); | ||
251 | NLA_PUT_U64(skb, L2TP_ATTR_RX_ERRORS, tunnel->stats.rx_errors); | ||
252 | nla_nest_end(skb, nest); | ||
253 | |||
254 | sk = tunnel->sock; | ||
255 | if (!sk) | ||
256 | goto out; | ||
257 | |||
258 | inet = inet_sk(sk); | ||
259 | |||
260 | switch (tunnel->encap) { | ||
261 | case L2TP_ENCAPTYPE_UDP: | ||
262 | NLA_PUT_U16(skb, L2TP_ATTR_UDP_SPORT, ntohs(inet->inet_sport)); | ||
263 | NLA_PUT_U16(skb, L2TP_ATTR_UDP_DPORT, ntohs(inet->inet_dport)); | ||
264 | NLA_PUT_U8(skb, L2TP_ATTR_UDP_CSUM, (sk->sk_no_check != UDP_CSUM_NOXMIT)); | ||
265 | /* NOBREAK */ | ||
266 | case L2TP_ENCAPTYPE_IP: | ||
267 | NLA_PUT_BE32(skb, L2TP_ATTR_IP_SADDR, inet->inet_saddr); | ||
268 | NLA_PUT_BE32(skb, L2TP_ATTR_IP_DADDR, inet->inet_daddr); | ||
269 | break; | ||
270 | } | ||
271 | |||
272 | out: | ||
273 | return genlmsg_end(skb, hdr); | ||
274 | |||
275 | nla_put_failure: | ||
276 | genlmsg_cancel(skb, hdr); | ||
277 | return -1; | ||
278 | } | ||
279 | |||
280 | static int l2tp_nl_cmd_tunnel_get(struct sk_buff *skb, struct genl_info *info) | ||
281 | { | ||
282 | struct l2tp_tunnel *tunnel; | ||
283 | struct sk_buff *msg; | ||
284 | u32 tunnel_id; | ||
285 | int ret = -ENOBUFS; | ||
286 | struct net *net = genl_info_net(info); | ||
287 | |||
288 | if (!info->attrs[L2TP_ATTR_CONN_ID]) { | ||
289 | ret = -EINVAL; | ||
290 | goto out; | ||
291 | } | ||
292 | |||
293 | tunnel_id = nla_get_u32(info->attrs[L2TP_ATTR_CONN_ID]); | ||
294 | |||
295 | tunnel = l2tp_tunnel_find(net, tunnel_id); | ||
296 | if (tunnel == NULL) { | ||
297 | ret = -ENODEV; | ||
298 | goto out; | ||
299 | } | ||
300 | |||
301 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); | ||
302 | if (!msg) { | ||
303 | ret = -ENOMEM; | ||
304 | goto out; | ||
305 | } | ||
306 | |||
307 | ret = l2tp_nl_tunnel_send(msg, info->snd_pid, info->snd_seq, | ||
308 | NLM_F_ACK, tunnel); | ||
309 | if (ret < 0) | ||
310 | goto err_out; | ||
311 | |||
312 | return genlmsg_unicast(net, msg, info->snd_pid); | ||
313 | |||
314 | err_out: | ||
315 | nlmsg_free(msg); | ||
316 | |||
317 | out: | ||
318 | return ret; | ||
319 | } | ||
320 | |||
321 | static int l2tp_nl_cmd_tunnel_dump(struct sk_buff *skb, struct netlink_callback *cb) | ||
322 | { | ||
323 | int ti = cb->args[0]; | ||
324 | struct l2tp_tunnel *tunnel; | ||
325 | struct net *net = sock_net(skb->sk); | ||
326 | |||
327 | for (;;) { | ||
328 | tunnel = l2tp_tunnel_find_nth(net, ti); | ||
329 | if (tunnel == NULL) | ||
330 | goto out; | ||
331 | |||
332 | if (l2tp_nl_tunnel_send(skb, NETLINK_CB(cb->skb).pid, | ||
333 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | ||
334 | tunnel) <= 0) | ||
335 | goto out; | ||
336 | |||
337 | ti++; | ||
338 | } | ||
339 | |||
340 | out: | ||
341 | cb->args[0] = ti; | ||
342 | |||
343 | return skb->len; | ||
344 | } | ||
345 | |||
346 | static int l2tp_nl_cmd_session_create(struct sk_buff *skb, struct genl_info *info) | ||
347 | { | ||
348 | u32 tunnel_id = 0; | ||
349 | u32 session_id; | ||
350 | u32 peer_session_id; | ||
351 | int ret = 0; | ||
352 | struct l2tp_tunnel *tunnel; | ||
353 | struct l2tp_session *session; | ||
354 | struct l2tp_session_cfg cfg = { 0, }; | ||
355 | struct net *net = genl_info_net(info); | ||
356 | |||
357 | if (!info->attrs[L2TP_ATTR_CONN_ID]) { | ||
358 | ret = -EINVAL; | ||
359 | goto out; | ||
360 | } | ||
361 | tunnel_id = nla_get_u32(info->attrs[L2TP_ATTR_CONN_ID]); | ||
362 | tunnel = l2tp_tunnel_find(net, tunnel_id); | ||
363 | if (!tunnel) { | ||
364 | ret = -ENODEV; | ||
365 | goto out; | ||
366 | } | ||
367 | |||
368 | if (!info->attrs[L2TP_ATTR_SESSION_ID]) { | ||
369 | ret = -EINVAL; | ||
370 | goto out; | ||
371 | } | ||
372 | session_id = nla_get_u32(info->attrs[L2TP_ATTR_SESSION_ID]); | ||
373 | session = l2tp_session_find(net, tunnel, session_id); | ||
374 | if (session) { | ||
375 | ret = -EEXIST; | ||
376 | goto out; | ||
377 | } | ||
378 | |||
379 | if (!info->attrs[L2TP_ATTR_PEER_SESSION_ID]) { | ||
380 | ret = -EINVAL; | ||
381 | goto out; | ||
382 | } | ||
383 | peer_session_id = nla_get_u32(info->attrs[L2TP_ATTR_PEER_SESSION_ID]); | ||
384 | |||
385 | if (!info->attrs[L2TP_ATTR_PW_TYPE]) { | ||
386 | ret = -EINVAL; | ||
387 | goto out; | ||
388 | } | ||
389 | cfg.pw_type = nla_get_u16(info->attrs[L2TP_ATTR_PW_TYPE]); | ||
390 | if (cfg.pw_type >= __L2TP_PWTYPE_MAX) { | ||
391 | ret = -EINVAL; | ||
392 | goto out; | ||
393 | } | ||
394 | |||
395 | if (tunnel->version > 2) { | ||
396 | if (info->attrs[L2TP_ATTR_OFFSET]) | ||
397 | cfg.offset = nla_get_u16(info->attrs[L2TP_ATTR_OFFSET]); | ||
398 | |||
399 | if (info->attrs[L2TP_ATTR_DATA_SEQ]) | ||
400 | cfg.data_seq = nla_get_u8(info->attrs[L2TP_ATTR_DATA_SEQ]); | ||
401 | |||
402 | cfg.l2specific_type = L2TP_L2SPECTYPE_DEFAULT; | ||
403 | if (info->attrs[L2TP_ATTR_L2SPEC_TYPE]) | ||
404 | cfg.l2specific_type = nla_get_u8(info->attrs[L2TP_ATTR_L2SPEC_TYPE]); | ||
405 | |||
406 | cfg.l2specific_len = 4; | ||
407 | if (info->attrs[L2TP_ATTR_L2SPEC_LEN]) | ||
408 | cfg.l2specific_len = nla_get_u8(info->attrs[L2TP_ATTR_L2SPEC_LEN]); | ||
409 | |||
410 | if (info->attrs[L2TP_ATTR_COOKIE]) { | ||
411 | u16 len = nla_len(info->attrs[L2TP_ATTR_COOKIE]); | ||
412 | if (len > 8) { | ||
413 | ret = -EINVAL; | ||
414 | goto out; | ||
415 | } | ||
416 | cfg.cookie_len = len; | ||
417 | memcpy(&cfg.cookie[0], nla_data(info->attrs[L2TP_ATTR_COOKIE]), len); | ||
418 | } | ||
419 | if (info->attrs[L2TP_ATTR_PEER_COOKIE]) { | ||
420 | u16 len = nla_len(info->attrs[L2TP_ATTR_PEER_COOKIE]); | ||
421 | if (len > 8) { | ||
422 | ret = -EINVAL; | ||
423 | goto out; | ||
424 | } | ||
425 | cfg.peer_cookie_len = len; | ||
426 | memcpy(&cfg.peer_cookie[0], nla_data(info->attrs[L2TP_ATTR_PEER_COOKIE]), len); | ||
427 | } | ||
428 | if (info->attrs[L2TP_ATTR_IFNAME]) | ||
429 | cfg.ifname = nla_data(info->attrs[L2TP_ATTR_IFNAME]); | ||
430 | |||
431 | if (info->attrs[L2TP_ATTR_VLAN_ID]) | ||
432 | cfg.vlan_id = nla_get_u16(info->attrs[L2TP_ATTR_VLAN_ID]); | ||
433 | } | ||
434 | |||
435 | if (info->attrs[L2TP_ATTR_DEBUG]) | ||
436 | cfg.debug = nla_get_u32(info->attrs[L2TP_ATTR_DEBUG]); | ||
437 | |||
438 | if (info->attrs[L2TP_ATTR_RECV_SEQ]) | ||
439 | cfg.recv_seq = nla_get_u8(info->attrs[L2TP_ATTR_RECV_SEQ]); | ||
440 | |||
441 | if (info->attrs[L2TP_ATTR_SEND_SEQ]) | ||
442 | cfg.send_seq = nla_get_u8(info->attrs[L2TP_ATTR_SEND_SEQ]); | ||
443 | |||
444 | if (info->attrs[L2TP_ATTR_LNS_MODE]) | ||
445 | cfg.lns_mode = nla_get_u8(info->attrs[L2TP_ATTR_LNS_MODE]); | ||
446 | |||
447 | if (info->attrs[L2TP_ATTR_RECV_TIMEOUT]) | ||
448 | cfg.reorder_timeout = nla_get_msecs(info->attrs[L2TP_ATTR_RECV_TIMEOUT]); | ||
449 | |||
450 | if (info->attrs[L2TP_ATTR_MTU]) | ||
451 | cfg.mtu = nla_get_u16(info->attrs[L2TP_ATTR_MTU]); | ||
452 | |||
453 | if (info->attrs[L2TP_ATTR_MRU]) | ||
454 | cfg.mru = nla_get_u16(info->attrs[L2TP_ATTR_MRU]); | ||
455 | |||
456 | if ((l2tp_nl_cmd_ops[cfg.pw_type] == NULL) || | ||
457 | (l2tp_nl_cmd_ops[cfg.pw_type]->session_create == NULL)) { | ||
458 | ret = -EPROTONOSUPPORT; | ||
459 | goto out; | ||
460 | } | ||
461 | |||
462 | /* Check that pseudowire-specific params are present */ | ||
463 | switch (cfg.pw_type) { | ||
464 | case L2TP_PWTYPE_NONE: | ||
465 | break; | ||
466 | case L2TP_PWTYPE_ETH_VLAN: | ||
467 | if (!info->attrs[L2TP_ATTR_VLAN_ID]) { | ||
468 | ret = -EINVAL; | ||
469 | goto out; | ||
470 | } | ||
471 | break; | ||
472 | case L2TP_PWTYPE_ETH: | ||
473 | break; | ||
474 | case L2TP_PWTYPE_PPP: | ||
475 | case L2TP_PWTYPE_PPP_AC: | ||
476 | break; | ||
477 | case L2TP_PWTYPE_IP: | ||
478 | default: | ||
479 | ret = -EPROTONOSUPPORT; | ||
480 | break; | ||
481 | } | ||
482 | |||
483 | ret = -EPROTONOSUPPORT; | ||
484 | if (l2tp_nl_cmd_ops[cfg.pw_type]->session_create) | ||
485 | ret = (*l2tp_nl_cmd_ops[cfg.pw_type]->session_create)(net, tunnel_id, | ||
486 | session_id, peer_session_id, &cfg); | ||
487 | |||
488 | out: | ||
489 | return ret; | ||
490 | } | ||
491 | |||
492 | static int l2tp_nl_cmd_session_delete(struct sk_buff *skb, struct genl_info *info) | ||
493 | { | ||
494 | int ret = 0; | ||
495 | struct l2tp_session *session; | ||
496 | u16 pw_type; | ||
497 | |||
498 | session = l2tp_nl_session_find(info); | ||
499 | if (session == NULL) { | ||
500 | ret = -ENODEV; | ||
501 | goto out; | ||
502 | } | ||
503 | |||
504 | pw_type = session->pwtype; | ||
505 | if (pw_type < __L2TP_PWTYPE_MAX) | ||
506 | if (l2tp_nl_cmd_ops[pw_type] && l2tp_nl_cmd_ops[pw_type]->session_delete) | ||
507 | ret = (*l2tp_nl_cmd_ops[pw_type]->session_delete)(session); | ||
508 | |||
509 | out: | ||
510 | return ret; | ||
511 | } | ||
512 | |||
513 | static int l2tp_nl_cmd_session_modify(struct sk_buff *skb, struct genl_info *info) | ||
514 | { | ||
515 | int ret = 0; | ||
516 | struct l2tp_session *session; | ||
517 | |||
518 | session = l2tp_nl_session_find(info); | ||
519 | if (session == NULL) { | ||
520 | ret = -ENODEV; | ||
521 | goto out; | ||
522 | } | ||
523 | |||
524 | if (info->attrs[L2TP_ATTR_DEBUG]) | ||
525 | session->debug = nla_get_u32(info->attrs[L2TP_ATTR_DEBUG]); | ||
526 | |||
527 | if (info->attrs[L2TP_ATTR_DATA_SEQ]) | ||
528 | session->data_seq = nla_get_u8(info->attrs[L2TP_ATTR_DATA_SEQ]); | ||
529 | |||
530 | if (info->attrs[L2TP_ATTR_RECV_SEQ]) | ||
531 | session->recv_seq = nla_get_u8(info->attrs[L2TP_ATTR_RECV_SEQ]); | ||
532 | |||
533 | if (info->attrs[L2TP_ATTR_SEND_SEQ]) | ||
534 | session->send_seq = nla_get_u8(info->attrs[L2TP_ATTR_SEND_SEQ]); | ||
535 | |||
536 | if (info->attrs[L2TP_ATTR_LNS_MODE]) | ||
537 | session->lns_mode = nla_get_u8(info->attrs[L2TP_ATTR_LNS_MODE]); | ||
538 | |||
539 | if (info->attrs[L2TP_ATTR_RECV_TIMEOUT]) | ||
540 | session->reorder_timeout = nla_get_msecs(info->attrs[L2TP_ATTR_RECV_TIMEOUT]); | ||
541 | |||
542 | if (info->attrs[L2TP_ATTR_MTU]) | ||
543 | session->mtu = nla_get_u16(info->attrs[L2TP_ATTR_MTU]); | ||
544 | |||
545 | if (info->attrs[L2TP_ATTR_MRU]) | ||
546 | session->mru = nla_get_u16(info->attrs[L2TP_ATTR_MRU]); | ||
547 | |||
548 | out: | ||
549 | return ret; | ||
550 | } | ||
551 | |||
552 | static int l2tp_nl_session_send(struct sk_buff *skb, u32 pid, u32 seq, int flags, | ||
553 | struct l2tp_session *session) | ||
554 | { | ||
555 | void *hdr; | ||
556 | struct nlattr *nest; | ||
557 | struct l2tp_tunnel *tunnel = session->tunnel; | ||
558 | struct sock *sk = NULL; | ||
559 | |||
560 | sk = tunnel->sock; | ||
561 | |||
562 | hdr = genlmsg_put(skb, pid, seq, &l2tp_nl_family, flags, L2TP_CMD_SESSION_GET); | ||
563 | if (IS_ERR(hdr)) | ||
564 | return PTR_ERR(hdr); | ||
565 | |||
566 | NLA_PUT_U32(skb, L2TP_ATTR_CONN_ID, tunnel->tunnel_id); | ||
567 | NLA_PUT_U32(skb, L2TP_ATTR_SESSION_ID, session->session_id); | ||
568 | NLA_PUT_U32(skb, L2TP_ATTR_PEER_CONN_ID, tunnel->peer_tunnel_id); | ||
569 | NLA_PUT_U32(skb, L2TP_ATTR_PEER_SESSION_ID, session->peer_session_id); | ||
570 | NLA_PUT_U32(skb, L2TP_ATTR_DEBUG, session->debug); | ||
571 | NLA_PUT_U16(skb, L2TP_ATTR_PW_TYPE, session->pwtype); | ||
572 | NLA_PUT_U16(skb, L2TP_ATTR_MTU, session->mtu); | ||
573 | if (session->mru) | ||
574 | NLA_PUT_U16(skb, L2TP_ATTR_MRU, session->mru); | ||
575 | |||
576 | if (session->ifname && session->ifname[0]) | ||
577 | NLA_PUT_STRING(skb, L2TP_ATTR_IFNAME, session->ifname); | ||
578 | if (session->cookie_len) | ||
579 | NLA_PUT(skb, L2TP_ATTR_COOKIE, session->cookie_len, &session->cookie[0]); | ||
580 | if (session->peer_cookie_len) | ||
581 | NLA_PUT(skb, L2TP_ATTR_PEER_COOKIE, session->peer_cookie_len, &session->peer_cookie[0]); | ||
582 | NLA_PUT_U8(skb, L2TP_ATTR_RECV_SEQ, session->recv_seq); | ||
583 | NLA_PUT_U8(skb, L2TP_ATTR_SEND_SEQ, session->send_seq); | ||
584 | NLA_PUT_U8(skb, L2TP_ATTR_LNS_MODE, session->lns_mode); | ||
585 | #ifdef CONFIG_XFRM | ||
586 | if ((sk) && (sk->sk_policy[0] || sk->sk_policy[1])) | ||
587 | NLA_PUT_U8(skb, L2TP_ATTR_USING_IPSEC, 1); | ||
588 | #endif | ||
589 | if (session->reorder_timeout) | ||
590 | NLA_PUT_MSECS(skb, L2TP_ATTR_RECV_TIMEOUT, session->reorder_timeout); | ||
591 | |||
592 | nest = nla_nest_start(skb, L2TP_ATTR_STATS); | ||
593 | if (nest == NULL) | ||
594 | goto nla_put_failure; | ||
595 | NLA_PUT_U64(skb, L2TP_ATTR_TX_PACKETS, session->stats.tx_packets); | ||
596 | NLA_PUT_U64(skb, L2TP_ATTR_TX_BYTES, session->stats.tx_bytes); | ||
597 | NLA_PUT_U64(skb, L2TP_ATTR_TX_ERRORS, session->stats.tx_errors); | ||
598 | NLA_PUT_U64(skb, L2TP_ATTR_RX_PACKETS, session->stats.rx_packets); | ||
599 | NLA_PUT_U64(skb, L2TP_ATTR_RX_BYTES, session->stats.rx_bytes); | ||
600 | NLA_PUT_U64(skb, L2TP_ATTR_RX_SEQ_DISCARDS, session->stats.rx_seq_discards); | ||
601 | NLA_PUT_U64(skb, L2TP_ATTR_RX_OOS_PACKETS, session->stats.rx_oos_packets); | ||
602 | NLA_PUT_U64(skb, L2TP_ATTR_RX_ERRORS, session->stats.rx_errors); | ||
603 | nla_nest_end(skb, nest); | ||
604 | |||
605 | return genlmsg_end(skb, hdr); | ||
606 | |||
607 | nla_put_failure: | ||
608 | genlmsg_cancel(skb, hdr); | ||
609 | return -1; | ||
610 | } | ||
611 | |||
612 | static int l2tp_nl_cmd_session_get(struct sk_buff *skb, struct genl_info *info) | ||
613 | { | ||
614 | struct l2tp_session *session; | ||
615 | struct sk_buff *msg; | ||
616 | int ret; | ||
617 | |||
618 | session = l2tp_nl_session_find(info); | ||
619 | if (session == NULL) { | ||
620 | ret = -ENODEV; | ||
621 | goto out; | ||
622 | } | ||
623 | |||
624 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); | ||
625 | if (!msg) { | ||
626 | ret = -ENOMEM; | ||
627 | goto out; | ||
628 | } | ||
629 | |||
630 | ret = l2tp_nl_session_send(msg, info->snd_pid, info->snd_seq, | ||
631 | 0, session); | ||
632 | if (ret < 0) | ||
633 | goto err_out; | ||
634 | |||
635 | return genlmsg_unicast(genl_info_net(info), msg, info->snd_pid); | ||
636 | |||
637 | err_out: | ||
638 | nlmsg_free(msg); | ||
639 | |||
640 | out: | ||
641 | return ret; | ||
642 | } | ||
643 | |||
644 | static int l2tp_nl_cmd_session_dump(struct sk_buff *skb, struct netlink_callback *cb) | ||
645 | { | ||
646 | struct net *net = sock_net(skb->sk); | ||
647 | struct l2tp_session *session; | ||
648 | struct l2tp_tunnel *tunnel = NULL; | ||
649 | int ti = cb->args[0]; | ||
650 | int si = cb->args[1]; | ||
651 | |||
652 | for (;;) { | ||
653 | if (tunnel == NULL) { | ||
654 | tunnel = l2tp_tunnel_find_nth(net, ti); | ||
655 | if (tunnel == NULL) | ||
656 | goto out; | ||
657 | } | ||
658 | |||
659 | session = l2tp_session_find_nth(tunnel, si); | ||
660 | if (session == NULL) { | ||
661 | ti++; | ||
662 | tunnel = NULL; | ||
663 | si = 0; | ||
664 | continue; | ||
665 | } | ||
666 | |||
667 | if (l2tp_nl_session_send(skb, NETLINK_CB(cb->skb).pid, | ||
668 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | ||
669 | session) <= 0) | ||
670 | break; | ||
671 | |||
672 | si++; | ||
673 | } | ||
674 | |||
675 | out: | ||
676 | cb->args[0] = ti; | ||
677 | cb->args[1] = si; | ||
678 | |||
679 | return skb->len; | ||
680 | } | ||
681 | |||
682 | static struct nla_policy l2tp_nl_policy[L2TP_ATTR_MAX + 1] = { | ||
683 | [L2TP_ATTR_NONE] = { .type = NLA_UNSPEC, }, | ||
684 | [L2TP_ATTR_PW_TYPE] = { .type = NLA_U16, }, | ||
685 | [L2TP_ATTR_ENCAP_TYPE] = { .type = NLA_U16, }, | ||
686 | [L2TP_ATTR_OFFSET] = { .type = NLA_U16, }, | ||
687 | [L2TP_ATTR_DATA_SEQ] = { .type = NLA_U8, }, | ||
688 | [L2TP_ATTR_L2SPEC_TYPE] = { .type = NLA_U8, }, | ||
689 | [L2TP_ATTR_L2SPEC_LEN] = { .type = NLA_U8, }, | ||
690 | [L2TP_ATTR_PROTO_VERSION] = { .type = NLA_U8, }, | ||
691 | [L2TP_ATTR_CONN_ID] = { .type = NLA_U32, }, | ||
692 | [L2TP_ATTR_PEER_CONN_ID] = { .type = NLA_U32, }, | ||
693 | [L2TP_ATTR_SESSION_ID] = { .type = NLA_U32, }, | ||
694 | [L2TP_ATTR_PEER_SESSION_ID] = { .type = NLA_U32, }, | ||
695 | [L2TP_ATTR_UDP_CSUM] = { .type = NLA_U8, }, | ||
696 | [L2TP_ATTR_VLAN_ID] = { .type = NLA_U16, }, | ||
697 | [L2TP_ATTR_DEBUG] = { .type = NLA_U32, }, | ||
698 | [L2TP_ATTR_RECV_SEQ] = { .type = NLA_U8, }, | ||
699 | [L2TP_ATTR_SEND_SEQ] = { .type = NLA_U8, }, | ||
700 | [L2TP_ATTR_LNS_MODE] = { .type = NLA_U8, }, | ||
701 | [L2TP_ATTR_USING_IPSEC] = { .type = NLA_U8, }, | ||
702 | [L2TP_ATTR_RECV_TIMEOUT] = { .type = NLA_MSECS, }, | ||
703 | [L2TP_ATTR_FD] = { .type = NLA_U32, }, | ||
704 | [L2TP_ATTR_IP_SADDR] = { .type = NLA_U32, }, | ||
705 | [L2TP_ATTR_IP_DADDR] = { .type = NLA_U32, }, | ||
706 | [L2TP_ATTR_UDP_SPORT] = { .type = NLA_U16, }, | ||
707 | [L2TP_ATTR_UDP_DPORT] = { .type = NLA_U16, }, | ||
708 | [L2TP_ATTR_MTU] = { .type = NLA_U16, }, | ||
709 | [L2TP_ATTR_MRU] = { .type = NLA_U16, }, | ||
710 | [L2TP_ATTR_STATS] = { .type = NLA_NESTED, }, | ||
711 | [L2TP_ATTR_IFNAME] = { | ||
712 | .type = NLA_NUL_STRING, | ||
713 | .len = IFNAMSIZ - 1, | ||
714 | }, | ||
715 | [L2TP_ATTR_COOKIE] = { | ||
716 | .type = NLA_BINARY, | ||
717 | .len = 8, | ||
718 | }, | ||
719 | [L2TP_ATTR_PEER_COOKIE] = { | ||
720 | .type = NLA_BINARY, | ||
721 | .len = 8, | ||
722 | }, | ||
723 | }; | ||
724 | |||
725 | static struct genl_ops l2tp_nl_ops[] = { | ||
726 | { | ||
727 | .cmd = L2TP_CMD_NOOP, | ||
728 | .doit = l2tp_nl_cmd_noop, | ||
729 | .policy = l2tp_nl_policy, | ||
730 | /* can be retrieved by unprivileged users */ | ||
731 | }, | ||
732 | { | ||
733 | .cmd = L2TP_CMD_TUNNEL_CREATE, | ||
734 | .doit = l2tp_nl_cmd_tunnel_create, | ||
735 | .policy = l2tp_nl_policy, | ||
736 | .flags = GENL_ADMIN_PERM, | ||
737 | }, | ||
738 | { | ||
739 | .cmd = L2TP_CMD_TUNNEL_DELETE, | ||
740 | .doit = l2tp_nl_cmd_tunnel_delete, | ||
741 | .policy = l2tp_nl_policy, | ||
742 | .flags = GENL_ADMIN_PERM, | ||
743 | }, | ||
744 | { | ||
745 | .cmd = L2TP_CMD_TUNNEL_MODIFY, | ||
746 | .doit = l2tp_nl_cmd_tunnel_modify, | ||
747 | .policy = l2tp_nl_policy, | ||
748 | .flags = GENL_ADMIN_PERM, | ||
749 | }, | ||
750 | { | ||
751 | .cmd = L2TP_CMD_TUNNEL_GET, | ||
752 | .doit = l2tp_nl_cmd_tunnel_get, | ||
753 | .dumpit = l2tp_nl_cmd_tunnel_dump, | ||
754 | .policy = l2tp_nl_policy, | ||
755 | .flags = GENL_ADMIN_PERM, | ||
756 | }, | ||
757 | { | ||
758 | .cmd = L2TP_CMD_SESSION_CREATE, | ||
759 | .doit = l2tp_nl_cmd_session_create, | ||
760 | .policy = l2tp_nl_policy, | ||
761 | .flags = GENL_ADMIN_PERM, | ||
762 | }, | ||
763 | { | ||
764 | .cmd = L2TP_CMD_SESSION_DELETE, | ||
765 | .doit = l2tp_nl_cmd_session_delete, | ||
766 | .policy = l2tp_nl_policy, | ||
767 | .flags = GENL_ADMIN_PERM, | ||
768 | }, | ||
769 | { | ||
770 | .cmd = L2TP_CMD_SESSION_MODIFY, | ||
771 | .doit = l2tp_nl_cmd_session_modify, | ||
772 | .policy = l2tp_nl_policy, | ||
773 | .flags = GENL_ADMIN_PERM, | ||
774 | }, | ||
775 | { | ||
776 | .cmd = L2TP_CMD_SESSION_GET, | ||
777 | .doit = l2tp_nl_cmd_session_get, | ||
778 | .dumpit = l2tp_nl_cmd_session_dump, | ||
779 | .policy = l2tp_nl_policy, | ||
780 | .flags = GENL_ADMIN_PERM, | ||
781 | }, | ||
782 | }; | ||
783 | |||
784 | int l2tp_nl_register_ops(enum l2tp_pwtype pw_type, const struct l2tp_nl_cmd_ops *ops) | ||
785 | { | ||
786 | int ret; | ||
787 | |||
788 | ret = -EINVAL; | ||
789 | if (pw_type >= __L2TP_PWTYPE_MAX) | ||
790 | goto err; | ||
791 | |||
792 | genl_lock(); | ||
793 | ret = -EBUSY; | ||
794 | if (l2tp_nl_cmd_ops[pw_type]) | ||
795 | goto out; | ||
796 | |||
797 | l2tp_nl_cmd_ops[pw_type] = ops; | ||
798 | |||
799 | out: | ||
800 | genl_unlock(); | ||
801 | err: | ||
802 | return 0; | ||
803 | } | ||
804 | EXPORT_SYMBOL_GPL(l2tp_nl_register_ops); | ||
805 | |||
806 | void l2tp_nl_unregister_ops(enum l2tp_pwtype pw_type) | ||
807 | { | ||
808 | if (pw_type < __L2TP_PWTYPE_MAX) { | ||
809 | genl_lock(); | ||
810 | l2tp_nl_cmd_ops[pw_type] = NULL; | ||
811 | genl_unlock(); | ||
812 | } | ||
813 | } | ||
814 | EXPORT_SYMBOL_GPL(l2tp_nl_unregister_ops); | ||
815 | |||
816 | static int l2tp_nl_init(void) | ||
817 | { | ||
818 | int err; | ||
819 | |||
820 | printk(KERN_INFO "L2TP netlink interface\n"); | ||
821 | err = genl_register_family_with_ops(&l2tp_nl_family, l2tp_nl_ops, | ||
822 | ARRAY_SIZE(l2tp_nl_ops)); | ||
823 | |||
824 | return err; | ||
825 | } | ||
826 | |||
827 | static void l2tp_nl_cleanup(void) | ||
828 | { | ||
829 | genl_unregister_family(&l2tp_nl_family); | ||
830 | } | ||
831 | |||
832 | module_init(l2tp_nl_init); | ||
833 | module_exit(l2tp_nl_cleanup); | ||
834 | |||
835 | MODULE_AUTHOR("James Chapman <jchapman@katalix.com>"); | ||
836 | MODULE_DESCRIPTION("L2TP netlink"); | ||
837 | MODULE_LICENSE("GPL"); | ||
838 | MODULE_VERSION("1.0"); | ||
839 | MODULE_ALIAS("net-pf-" __stringify(PF_NETLINK) "-proto-" \ | ||
840 | __stringify(NETLINK_GENERIC) "-type-" "l2tp"); | ||
diff --git a/net/l2tp/l2tp_ppp.c b/net/l2tp/l2tp_ppp.c new file mode 100644 index 000000000000..90d82b3f2889 --- /dev/null +++ b/net/l2tp/l2tp_ppp.c | |||
@@ -0,0 +1,1837 @@ | |||
1 | /***************************************************************************** | ||
2 | * Linux PPP over L2TP (PPPoX/PPPoL2TP) Sockets | ||
3 | * | ||
4 | * PPPoX --- Generic PPP encapsulation socket family | ||
5 | * PPPoL2TP --- PPP over L2TP (RFC 2661) | ||
6 | * | ||
7 | * Version: 2.0.0 | ||
8 | * | ||
9 | * Authors: James Chapman (jchapman@katalix.com) | ||
10 | * | ||
11 | * Based on original work by Martijn van Oosterhout <kleptog@svana.org> | ||
12 | * | ||
13 | * License: | ||
14 | * This program is free software; you can redistribute it and/or | ||
15 | * modify it under the terms of the GNU General Public License | ||
16 | * as published by the Free Software Foundation; either version | ||
17 | * 2 of the License, or (at your option) any later version. | ||
18 | * | ||
19 | */ | ||
20 | |||
21 | /* This driver handles only L2TP data frames; control frames are handled by a | ||
22 | * userspace application. | ||
23 | * | ||
24 | * To send data in an L2TP session, userspace opens a PPPoL2TP socket and | ||
25 | * attaches it to a bound UDP socket with local tunnel_id / session_id and | ||
26 | * peer tunnel_id / session_id set. Data can then be sent or received using | ||
27 | * regular socket sendmsg() / recvmsg() calls. Kernel parameters of the socket | ||
28 | * can be read or modified using ioctl() or [gs]etsockopt() calls. | ||
29 | * | ||
30 | * When a PPPoL2TP socket is connected with local and peer session_id values | ||
31 | * zero, the socket is treated as a special tunnel management socket. | ||
32 | * | ||
33 | * Here's example userspace code to create a socket for sending/receiving data | ||
34 | * over an L2TP session:- | ||
35 | * | ||
36 | * struct sockaddr_pppol2tp sax; | ||
37 | * int fd; | ||
38 | * int session_fd; | ||
39 | * | ||
40 | * fd = socket(AF_PPPOX, SOCK_DGRAM, PX_PROTO_OL2TP); | ||
41 | * | ||
42 | * sax.sa_family = AF_PPPOX; | ||
43 | * sax.sa_protocol = PX_PROTO_OL2TP; | ||
44 | * sax.pppol2tp.fd = tunnel_fd; // bound UDP socket | ||
45 | * sax.pppol2tp.addr.sin_addr.s_addr = addr->sin_addr.s_addr; | ||
46 | * sax.pppol2tp.addr.sin_port = addr->sin_port; | ||
47 | * sax.pppol2tp.addr.sin_family = AF_INET; | ||
48 | * sax.pppol2tp.s_tunnel = tunnel_id; | ||
49 | * sax.pppol2tp.s_session = session_id; | ||
50 | * sax.pppol2tp.d_tunnel = peer_tunnel_id; | ||
51 | * sax.pppol2tp.d_session = peer_session_id; | ||
52 | * | ||
53 | * session_fd = connect(fd, (struct sockaddr *)&sax, sizeof(sax)); | ||
54 | * | ||
55 | * A pppd plugin that allows PPP traffic to be carried over L2TP using | ||
56 | * this driver is available from the OpenL2TP project at | ||
57 | * http://openl2tp.sourceforge.net. | ||
58 | */ | ||
59 | |||
60 | #include <linux/module.h> | ||
61 | #include <linux/string.h> | ||
62 | #include <linux/list.h> | ||
63 | #include <linux/uaccess.h> | ||
64 | |||
65 | #include <linux/kernel.h> | ||
66 | #include <linux/spinlock.h> | ||
67 | #include <linux/kthread.h> | ||
68 | #include <linux/sched.h> | ||
69 | #include <linux/slab.h> | ||
70 | #include <linux/errno.h> | ||
71 | #include <linux/jiffies.h> | ||
72 | |||
73 | #include <linux/netdevice.h> | ||
74 | #include <linux/net.h> | ||
75 | #include <linux/inetdevice.h> | ||
76 | #include <linux/skbuff.h> | ||
77 | #include <linux/init.h> | ||
78 | #include <linux/ip.h> | ||
79 | #include <linux/udp.h> | ||
80 | #include <linux/if_pppox.h> | ||
81 | #include <linux/if_pppol2tp.h> | ||
82 | #include <net/sock.h> | ||
83 | #include <linux/ppp_channel.h> | ||
84 | #include <linux/ppp_defs.h> | ||
85 | #include <linux/if_ppp.h> | ||
86 | #include <linux/file.h> | ||
87 | #include <linux/hash.h> | ||
88 | #include <linux/sort.h> | ||
89 | #include <linux/proc_fs.h> | ||
90 | #include <linux/l2tp.h> | ||
91 | #include <linux/nsproxy.h> | ||
92 | #include <net/net_namespace.h> | ||
93 | #include <net/netns/generic.h> | ||
94 | #include <net/dst.h> | ||
95 | #include <net/ip.h> | ||
96 | #include <net/udp.h> | ||
97 | #include <net/xfrm.h> | ||
98 | |||
99 | #include <asm/byteorder.h> | ||
100 | #include <asm/atomic.h> | ||
101 | |||
102 | #include "l2tp_core.h" | ||
103 | |||
104 | #define PPPOL2TP_DRV_VERSION "V2.0" | ||
105 | |||
106 | /* Space for UDP, L2TP and PPP headers */ | ||
107 | #define PPPOL2TP_HEADER_OVERHEAD 40 | ||
108 | |||
109 | #define PRINTK(_mask, _type, _lvl, _fmt, args...) \ | ||
110 | do { \ | ||
111 | if ((_mask) & (_type)) \ | ||
112 | printk(_lvl "PPPOL2TP: " _fmt, ##args); \ | ||
113 | } while (0) | ||
114 | |||
115 | /* Number of bytes to build transmit L2TP headers. | ||
116 | * Unfortunately the size is different depending on whether sequence numbers | ||
117 | * are enabled. | ||
118 | */ | ||
119 | #define PPPOL2TP_L2TP_HDR_SIZE_SEQ 10 | ||
120 | #define PPPOL2TP_L2TP_HDR_SIZE_NOSEQ 6 | ||
121 | |||
122 | /* Private data of each session. This data lives at the end of struct | ||
123 | * l2tp_session, referenced via session->priv[]. | ||
124 | */ | ||
125 | struct pppol2tp_session { | ||
126 | int owner; /* pid that opened the socket */ | ||
127 | |||
128 | struct sock *sock; /* Pointer to the session | ||
129 | * PPPoX socket */ | ||
130 | struct sock *tunnel_sock; /* Pointer to the tunnel UDP | ||
131 | * socket */ | ||
132 | int flags; /* accessed by PPPIOCGFLAGS. | ||
133 | * Unused. */ | ||
134 | }; | ||
135 | |||
136 | static int pppol2tp_xmit(struct ppp_channel *chan, struct sk_buff *skb); | ||
137 | |||
138 | static struct ppp_channel_ops pppol2tp_chan_ops = { pppol2tp_xmit , NULL }; | ||
139 | static const struct proto_ops pppol2tp_ops; | ||
140 | |||
141 | /* Helpers to obtain tunnel/session contexts from sockets. | ||
142 | */ | ||
143 | static inline struct l2tp_session *pppol2tp_sock_to_session(struct sock *sk) | ||
144 | { | ||
145 | struct l2tp_session *session; | ||
146 | |||
147 | if (sk == NULL) | ||
148 | return NULL; | ||
149 | |||
150 | sock_hold(sk); | ||
151 | session = (struct l2tp_session *)(sk->sk_user_data); | ||
152 | if (session == NULL) { | ||
153 | sock_put(sk); | ||
154 | goto out; | ||
155 | } | ||
156 | |||
157 | BUG_ON(session->magic != L2TP_SESSION_MAGIC); | ||
158 | |||
159 | out: | ||
160 | return session; | ||
161 | } | ||
162 | |||
163 | /***************************************************************************** | ||
164 | * Receive data handling | ||
165 | *****************************************************************************/ | ||
166 | |||
167 | static int pppol2tp_recv_payload_hook(struct sk_buff *skb) | ||
168 | { | ||
169 | /* Skip PPP header, if present. In testing, Microsoft L2TP clients | ||
170 | * don't send the PPP header (PPP header compression enabled), but | ||
171 | * other clients can include the header. So we cope with both cases | ||
172 | * here. The PPP header is always FF03 when using L2TP. | ||
173 | * | ||
174 | * Note that skb->data[] isn't dereferenced from a u16 ptr here since | ||
175 | * the field may be unaligned. | ||
176 | */ | ||
177 | if (!pskb_may_pull(skb, 2)) | ||
178 | return 1; | ||
179 | |||
180 | if ((skb->data[0] == 0xff) && (skb->data[1] == 0x03)) | ||
181 | skb_pull(skb, 2); | ||
182 | |||
183 | return 0; | ||
184 | } | ||
185 | |||
186 | /* Receive message. This is the recvmsg for the PPPoL2TP socket. | ||
187 | */ | ||
188 | static int pppol2tp_recvmsg(struct kiocb *iocb, struct socket *sock, | ||
189 | struct msghdr *msg, size_t len, | ||
190 | int flags) | ||
191 | { | ||
192 | int err; | ||
193 | struct sk_buff *skb; | ||
194 | struct sock *sk = sock->sk; | ||
195 | |||
196 | err = -EIO; | ||
197 | if (sk->sk_state & PPPOX_BOUND) | ||
198 | goto end; | ||
199 | |||
200 | msg->msg_namelen = 0; | ||
201 | |||
202 | err = 0; | ||
203 | skb = skb_recv_datagram(sk, flags & ~MSG_DONTWAIT, | ||
204 | flags & MSG_DONTWAIT, &err); | ||
205 | if (!skb) | ||
206 | goto end; | ||
207 | |||
208 | if (len > skb->len) | ||
209 | len = skb->len; | ||
210 | else if (len < skb->len) | ||
211 | msg->msg_flags |= MSG_TRUNC; | ||
212 | |||
213 | err = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, len); | ||
214 | if (likely(err == 0)) | ||
215 | err = len; | ||
216 | |||
217 | kfree_skb(skb); | ||
218 | end: | ||
219 | return err; | ||
220 | } | ||
221 | |||
222 | static void pppol2tp_recv(struct l2tp_session *session, struct sk_buff *skb, int data_len) | ||
223 | { | ||
224 | struct pppol2tp_session *ps = l2tp_session_priv(session); | ||
225 | struct sock *sk = NULL; | ||
226 | |||
227 | /* If the socket is bound, send it in to PPP's input queue. Otherwise | ||
228 | * queue it on the session socket. | ||
229 | */ | ||
230 | sk = ps->sock; | ||
231 | if (sk == NULL) | ||
232 | goto no_sock; | ||
233 | |||
234 | if (sk->sk_state & PPPOX_BOUND) { | ||
235 | struct pppox_sock *po; | ||
236 | PRINTK(session->debug, PPPOL2TP_MSG_DATA, KERN_DEBUG, | ||
237 | "%s: recv %d byte data frame, passing to ppp\n", | ||
238 | session->name, data_len); | ||
239 | |||
240 | /* We need to forget all info related to the L2TP packet | ||
241 | * gathered in the skb as we are going to reuse the same | ||
242 | * skb for the inner packet. | ||
243 | * Namely we need to: | ||
244 | * - reset xfrm (IPSec) information as it applies to | ||
245 | * the outer L2TP packet and not to the inner one | ||
246 | * - release the dst to force a route lookup on the inner | ||
247 | * IP packet since skb->dst currently points to the dst | ||
248 | * of the UDP tunnel | ||
249 | * - reset netfilter information as it doesn't apply | ||
250 | * to the inner packet either | ||
251 | */ | ||
252 | secpath_reset(skb); | ||
253 | skb_dst_drop(skb); | ||
254 | nf_reset(skb); | ||
255 | |||
256 | po = pppox_sk(sk); | ||
257 | ppp_input(&po->chan, skb); | ||
258 | } else { | ||
259 | PRINTK(session->debug, PPPOL2TP_MSG_DATA, KERN_INFO, | ||
260 | "%s: socket not bound\n", session->name); | ||
261 | |||
262 | /* Not bound. Nothing we can do, so discard. */ | ||
263 | session->stats.rx_errors++; | ||
264 | kfree_skb(skb); | ||
265 | } | ||
266 | |||
267 | return; | ||
268 | |||
269 | no_sock: | ||
270 | PRINTK(session->debug, PPPOL2TP_MSG_DATA, KERN_INFO, | ||
271 | "%s: no socket\n", session->name); | ||
272 | kfree_skb(skb); | ||
273 | } | ||
274 | |||
275 | static void pppol2tp_session_sock_hold(struct l2tp_session *session) | ||
276 | { | ||
277 | struct pppol2tp_session *ps = l2tp_session_priv(session); | ||
278 | |||
279 | if (ps->sock) | ||
280 | sock_hold(ps->sock); | ||
281 | } | ||
282 | |||
283 | static void pppol2tp_session_sock_put(struct l2tp_session *session) | ||
284 | { | ||
285 | struct pppol2tp_session *ps = l2tp_session_priv(session); | ||
286 | |||
287 | if (ps->sock) | ||
288 | sock_put(ps->sock); | ||
289 | } | ||
290 | |||
291 | /************************************************************************ | ||
292 | * Transmit handling | ||
293 | ***********************************************************************/ | ||
294 | |||
295 | /* This is the sendmsg for the PPPoL2TP pppol2tp_session socket. We come here | ||
296 | * when a user application does a sendmsg() on the session socket. L2TP and | ||
297 | * PPP headers must be inserted into the user's data. | ||
298 | */ | ||
299 | static int pppol2tp_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *m, | ||
300 | size_t total_len) | ||
301 | { | ||
302 | static const unsigned char ppph[2] = { 0xff, 0x03 }; | ||
303 | struct sock *sk = sock->sk; | ||
304 | struct sk_buff *skb; | ||
305 | int error; | ||
306 | struct l2tp_session *session; | ||
307 | struct l2tp_tunnel *tunnel; | ||
308 | struct pppol2tp_session *ps; | ||
309 | int uhlen; | ||
310 | |||
311 | error = -ENOTCONN; | ||
312 | if (sock_flag(sk, SOCK_DEAD) || !(sk->sk_state & PPPOX_CONNECTED)) | ||
313 | goto error; | ||
314 | |||
315 | /* Get session and tunnel contexts */ | ||
316 | error = -EBADF; | ||
317 | session = pppol2tp_sock_to_session(sk); | ||
318 | if (session == NULL) | ||
319 | goto error; | ||
320 | |||
321 | ps = l2tp_session_priv(session); | ||
322 | tunnel = l2tp_sock_to_tunnel(ps->tunnel_sock); | ||
323 | if (tunnel == NULL) | ||
324 | goto error_put_sess; | ||
325 | |||
326 | uhlen = (tunnel->encap == L2TP_ENCAPTYPE_UDP) ? sizeof(struct udphdr) : 0; | ||
327 | |||
328 | /* Allocate a socket buffer */ | ||
329 | error = -ENOMEM; | ||
330 | skb = sock_wmalloc(sk, NET_SKB_PAD + sizeof(struct iphdr) + | ||
331 | uhlen + session->hdr_len + | ||
332 | sizeof(ppph) + total_len, | ||
333 | 0, GFP_KERNEL); | ||
334 | if (!skb) | ||
335 | goto error_put_sess_tun; | ||
336 | |||
337 | /* Reserve space for headers. */ | ||
338 | skb_reserve(skb, NET_SKB_PAD); | ||
339 | skb_reset_network_header(skb); | ||
340 | skb_reserve(skb, sizeof(struct iphdr)); | ||
341 | skb_reset_transport_header(skb); | ||
342 | skb_reserve(skb, uhlen); | ||
343 | |||
344 | /* Add PPP header */ | ||
345 | skb->data[0] = ppph[0]; | ||
346 | skb->data[1] = ppph[1]; | ||
347 | skb_put(skb, 2); | ||
348 | |||
349 | /* Copy user data into skb */ | ||
350 | error = memcpy_fromiovec(skb->data, m->msg_iov, total_len); | ||
351 | if (error < 0) { | ||
352 | kfree_skb(skb); | ||
353 | goto error_put_sess_tun; | ||
354 | } | ||
355 | skb_put(skb, total_len); | ||
356 | |||
357 | l2tp_xmit_skb(session, skb, session->hdr_len); | ||
358 | |||
359 | sock_put(ps->tunnel_sock); | ||
360 | |||
361 | return error; | ||
362 | |||
363 | error_put_sess_tun: | ||
364 | sock_put(ps->tunnel_sock); | ||
365 | error_put_sess: | ||
366 | sock_put(sk); | ||
367 | error: | ||
368 | return error; | ||
369 | } | ||
370 | |||
371 | /* Transmit function called by generic PPP driver. Sends PPP frame | ||
372 | * over PPPoL2TP socket. | ||
373 | * | ||
374 | * This is almost the same as pppol2tp_sendmsg(), but rather than | ||
375 | * being called with a msghdr from userspace, it is called with a skb | ||
376 | * from the kernel. | ||
377 | * | ||
378 | * The supplied skb from ppp doesn't have enough headroom for the | ||
379 | * insertion of L2TP, UDP and IP headers so we need to allocate more | ||
380 | * headroom in the skb. This will create a cloned skb. But we must be | ||
381 | * careful in the error case because the caller will expect to free | ||
382 | * the skb it supplied, not our cloned skb. So we take care to always | ||
383 | * leave the original skb unfreed if we return an error. | ||
384 | */ | ||
385 | static int pppol2tp_xmit(struct ppp_channel *chan, struct sk_buff *skb) | ||
386 | { | ||
387 | static const u8 ppph[2] = { 0xff, 0x03 }; | ||
388 | struct sock *sk = (struct sock *) chan->private; | ||
389 | struct sock *sk_tun; | ||
390 | struct l2tp_session *session; | ||
391 | struct l2tp_tunnel *tunnel; | ||
392 | struct pppol2tp_session *ps; | ||
393 | int old_headroom; | ||
394 | int new_headroom; | ||
395 | |||
396 | if (sock_flag(sk, SOCK_DEAD) || !(sk->sk_state & PPPOX_CONNECTED)) | ||
397 | goto abort; | ||
398 | |||
399 | /* Get session and tunnel contexts from the socket */ | ||
400 | session = pppol2tp_sock_to_session(sk); | ||
401 | if (session == NULL) | ||
402 | goto abort; | ||
403 | |||
404 | ps = l2tp_session_priv(session); | ||
405 | sk_tun = ps->tunnel_sock; | ||
406 | if (sk_tun == NULL) | ||
407 | goto abort_put_sess; | ||
408 | tunnel = l2tp_sock_to_tunnel(sk_tun); | ||
409 | if (tunnel == NULL) | ||
410 | goto abort_put_sess; | ||
411 | |||
412 | old_headroom = skb_headroom(skb); | ||
413 | if (skb_cow_head(skb, sizeof(ppph))) | ||
414 | goto abort_put_sess_tun; | ||
415 | |||
416 | new_headroom = skb_headroom(skb); | ||
417 | skb->truesize += new_headroom - old_headroom; | ||
418 | |||
419 | /* Setup PPP header */ | ||
420 | __skb_push(skb, sizeof(ppph)); | ||
421 | skb->data[0] = ppph[0]; | ||
422 | skb->data[1] = ppph[1]; | ||
423 | |||
424 | l2tp_xmit_skb(session, skb, session->hdr_len); | ||
425 | |||
426 | sock_put(sk_tun); | ||
427 | sock_put(sk); | ||
428 | return 1; | ||
429 | |||
430 | abort_put_sess_tun: | ||
431 | sock_put(sk_tun); | ||
432 | abort_put_sess: | ||
433 | sock_put(sk); | ||
434 | abort: | ||
435 | /* Free the original skb */ | ||
436 | kfree_skb(skb); | ||
437 | return 1; | ||
438 | } | ||
439 | |||
440 | /***************************************************************************** | ||
441 | * Session (and tunnel control) socket create/destroy. | ||
442 | *****************************************************************************/ | ||
443 | |||
444 | /* Called by l2tp_core when a session socket is being closed. | ||
445 | */ | ||
446 | static void pppol2tp_session_close(struct l2tp_session *session) | ||
447 | { | ||
448 | struct pppol2tp_session *ps = l2tp_session_priv(session); | ||
449 | struct sock *sk = ps->sock; | ||
450 | struct sk_buff *skb; | ||
451 | |||
452 | BUG_ON(session->magic != L2TP_SESSION_MAGIC); | ||
453 | |||
454 | if (session->session_id == 0) | ||
455 | goto out; | ||
456 | |||
457 | if (sk != NULL) { | ||
458 | lock_sock(sk); | ||
459 | |||
460 | if (sk->sk_state & (PPPOX_CONNECTED | PPPOX_BOUND)) { | ||
461 | pppox_unbind_sock(sk); | ||
462 | sk->sk_state = PPPOX_DEAD; | ||
463 | sk->sk_state_change(sk); | ||
464 | } | ||
465 | |||
466 | /* Purge any queued data */ | ||
467 | skb_queue_purge(&sk->sk_receive_queue); | ||
468 | skb_queue_purge(&sk->sk_write_queue); | ||
469 | while ((skb = skb_dequeue(&session->reorder_q))) { | ||
470 | kfree_skb(skb); | ||
471 | sock_put(sk); | ||
472 | } | ||
473 | |||
474 | release_sock(sk); | ||
475 | } | ||
476 | |||
477 | out: | ||
478 | return; | ||
479 | } | ||
480 | |||
481 | /* Really kill the session socket. (Called from sock_put() if | ||
482 | * refcnt == 0.) | ||
483 | */ | ||
484 | static void pppol2tp_session_destruct(struct sock *sk) | ||
485 | { | ||
486 | struct l2tp_session *session; | ||
487 | |||
488 | if (sk->sk_user_data != NULL) { | ||
489 | session = sk->sk_user_data; | ||
490 | if (session == NULL) | ||
491 | goto out; | ||
492 | |||
493 | sk->sk_user_data = NULL; | ||
494 | BUG_ON(session->magic != L2TP_SESSION_MAGIC); | ||
495 | l2tp_session_dec_refcount(session); | ||
496 | } | ||
497 | |||
498 | out: | ||
499 | return; | ||
500 | } | ||
501 | |||
502 | /* Called when the PPPoX socket (session) is closed. | ||
503 | */ | ||
504 | static int pppol2tp_release(struct socket *sock) | ||
505 | { | ||
506 | struct sock *sk = sock->sk; | ||
507 | struct l2tp_session *session; | ||
508 | int error; | ||
509 | |||
510 | if (!sk) | ||
511 | return 0; | ||
512 | |||
513 | error = -EBADF; | ||
514 | lock_sock(sk); | ||
515 | if (sock_flag(sk, SOCK_DEAD) != 0) | ||
516 | goto error; | ||
517 | |||
518 | pppox_unbind_sock(sk); | ||
519 | |||
520 | /* Signal the death of the socket. */ | ||
521 | sk->sk_state = PPPOX_DEAD; | ||
522 | sock_orphan(sk); | ||
523 | sock->sk = NULL; | ||
524 | |||
525 | session = pppol2tp_sock_to_session(sk); | ||
526 | |||
527 | /* Purge any queued data */ | ||
528 | skb_queue_purge(&sk->sk_receive_queue); | ||
529 | skb_queue_purge(&sk->sk_write_queue); | ||
530 | if (session != NULL) { | ||
531 | struct sk_buff *skb; | ||
532 | while ((skb = skb_dequeue(&session->reorder_q))) { | ||
533 | kfree_skb(skb); | ||
534 | sock_put(sk); | ||
535 | } | ||
536 | sock_put(sk); | ||
537 | } | ||
538 | |||
539 | release_sock(sk); | ||
540 | |||
541 | /* This will delete the session context via | ||
542 | * pppol2tp_session_destruct() if the socket's refcnt drops to | ||
543 | * zero. | ||
544 | */ | ||
545 | sock_put(sk); | ||
546 | |||
547 | return 0; | ||
548 | |||
549 | error: | ||
550 | release_sock(sk); | ||
551 | return error; | ||
552 | } | ||
553 | |||
554 | static struct proto pppol2tp_sk_proto = { | ||
555 | .name = "PPPOL2TP", | ||
556 | .owner = THIS_MODULE, | ||
557 | .obj_size = sizeof(struct pppox_sock), | ||
558 | }; | ||
559 | |||
560 | static int pppol2tp_backlog_recv(struct sock *sk, struct sk_buff *skb) | ||
561 | { | ||
562 | int rc; | ||
563 | |||
564 | rc = l2tp_udp_encap_recv(sk, skb); | ||
565 | if (rc) | ||
566 | kfree_skb(skb); | ||
567 | |||
568 | return NET_RX_SUCCESS; | ||
569 | } | ||
570 | |||
571 | /* socket() handler. Initialize a new struct sock. | ||
572 | */ | ||
573 | static int pppol2tp_create(struct net *net, struct socket *sock) | ||
574 | { | ||
575 | int error = -ENOMEM; | ||
576 | struct sock *sk; | ||
577 | |||
578 | sk = sk_alloc(net, PF_PPPOX, GFP_KERNEL, &pppol2tp_sk_proto); | ||
579 | if (!sk) | ||
580 | goto out; | ||
581 | |||
582 | sock_init_data(sock, sk); | ||
583 | |||
584 | sock->state = SS_UNCONNECTED; | ||
585 | sock->ops = &pppol2tp_ops; | ||
586 | |||
587 | sk->sk_backlog_rcv = pppol2tp_backlog_recv; | ||
588 | sk->sk_protocol = PX_PROTO_OL2TP; | ||
589 | sk->sk_family = PF_PPPOX; | ||
590 | sk->sk_state = PPPOX_NONE; | ||
591 | sk->sk_type = SOCK_STREAM; | ||
592 | sk->sk_destruct = pppol2tp_session_destruct; | ||
593 | |||
594 | error = 0; | ||
595 | |||
596 | out: | ||
597 | return error; | ||
598 | } | ||
599 | |||
600 | #if defined(CONFIG_L2TP_DEBUGFS) || defined(CONFIG_L2TP_DEBUGFS_MODULE) | ||
601 | static void pppol2tp_show(struct seq_file *m, void *arg) | ||
602 | { | ||
603 | struct l2tp_session *session = arg; | ||
604 | struct pppol2tp_session *ps = l2tp_session_priv(session); | ||
605 | |||
606 | if (ps) { | ||
607 | struct pppox_sock *po = pppox_sk(ps->sock); | ||
608 | if (po) | ||
609 | seq_printf(m, " interface %s\n", ppp_dev_name(&po->chan)); | ||
610 | } | ||
611 | } | ||
612 | #endif | ||
613 | |||
614 | /* connect() handler. Attach a PPPoX socket to a tunnel UDP socket | ||
615 | */ | ||
616 | static int pppol2tp_connect(struct socket *sock, struct sockaddr *uservaddr, | ||
617 | int sockaddr_len, int flags) | ||
618 | { | ||
619 | struct sock *sk = sock->sk; | ||
620 | struct sockaddr_pppol2tp *sp = (struct sockaddr_pppol2tp *) uservaddr; | ||
621 | struct sockaddr_pppol2tpv3 *sp3 = (struct sockaddr_pppol2tpv3 *) uservaddr; | ||
622 | struct pppox_sock *po = pppox_sk(sk); | ||
623 | struct l2tp_session *session = NULL; | ||
624 | struct l2tp_tunnel *tunnel; | ||
625 | struct pppol2tp_session *ps; | ||
626 | struct dst_entry *dst; | ||
627 | struct l2tp_session_cfg cfg = { 0, }; | ||
628 | int error = 0; | ||
629 | u32 tunnel_id, peer_tunnel_id; | ||
630 | u32 session_id, peer_session_id; | ||
631 | int ver = 2; | ||
632 | int fd; | ||
633 | |||
634 | lock_sock(sk); | ||
635 | |||
636 | error = -EINVAL; | ||
637 | if (sp->sa_protocol != PX_PROTO_OL2TP) | ||
638 | goto end; | ||
639 | |||
640 | /* Check for already bound sockets */ | ||
641 | error = -EBUSY; | ||
642 | if (sk->sk_state & PPPOX_CONNECTED) | ||
643 | goto end; | ||
644 | |||
645 | /* We don't supporting rebinding anyway */ | ||
646 | error = -EALREADY; | ||
647 | if (sk->sk_user_data) | ||
648 | goto end; /* socket is already attached */ | ||
649 | |||
650 | /* Get params from socket address. Handle L2TPv2 and L2TPv3 */ | ||
651 | if (sockaddr_len == sizeof(struct sockaddr_pppol2tp)) { | ||
652 | fd = sp->pppol2tp.fd; | ||
653 | tunnel_id = sp->pppol2tp.s_tunnel; | ||
654 | peer_tunnel_id = sp->pppol2tp.d_tunnel; | ||
655 | session_id = sp->pppol2tp.s_session; | ||
656 | peer_session_id = sp->pppol2tp.d_session; | ||
657 | } else if (sockaddr_len == sizeof(struct sockaddr_pppol2tpv3)) { | ||
658 | ver = 3; | ||
659 | fd = sp3->pppol2tp.fd; | ||
660 | tunnel_id = sp3->pppol2tp.s_tunnel; | ||
661 | peer_tunnel_id = sp3->pppol2tp.d_tunnel; | ||
662 | session_id = sp3->pppol2tp.s_session; | ||
663 | peer_session_id = sp3->pppol2tp.d_session; | ||
664 | } else { | ||
665 | error = -EINVAL; | ||
666 | goto end; /* bad socket address */ | ||
667 | } | ||
668 | |||
669 | /* Don't bind if tunnel_id is 0 */ | ||
670 | error = -EINVAL; | ||
671 | if (tunnel_id == 0) | ||
672 | goto end; | ||
673 | |||
674 | tunnel = l2tp_tunnel_find(sock_net(sk), tunnel_id); | ||
675 | |||
676 | /* Special case: create tunnel context if session_id and | ||
677 | * peer_session_id is 0. Otherwise look up tunnel using supplied | ||
678 | * tunnel id. | ||
679 | */ | ||
680 | if ((session_id == 0) && (peer_session_id == 0)) { | ||
681 | if (tunnel == NULL) { | ||
682 | struct l2tp_tunnel_cfg tcfg = { | ||
683 | .encap = L2TP_ENCAPTYPE_UDP, | ||
684 | .debug = 0, | ||
685 | }; | ||
686 | error = l2tp_tunnel_create(sock_net(sk), fd, ver, tunnel_id, peer_tunnel_id, &tcfg, &tunnel); | ||
687 | if (error < 0) | ||
688 | goto end; | ||
689 | } | ||
690 | } else { | ||
691 | /* Error if we can't find the tunnel */ | ||
692 | error = -ENOENT; | ||
693 | if (tunnel == NULL) | ||
694 | goto end; | ||
695 | |||
696 | /* Error if socket is not prepped */ | ||
697 | if (tunnel->sock == NULL) | ||
698 | goto end; | ||
699 | } | ||
700 | |||
701 | if (tunnel->recv_payload_hook == NULL) | ||
702 | tunnel->recv_payload_hook = pppol2tp_recv_payload_hook; | ||
703 | |||
704 | if (tunnel->peer_tunnel_id == 0) { | ||
705 | if (ver == 2) | ||
706 | tunnel->peer_tunnel_id = sp->pppol2tp.d_tunnel; | ||
707 | else | ||
708 | tunnel->peer_tunnel_id = sp3->pppol2tp.d_tunnel; | ||
709 | } | ||
710 | |||
711 | /* Create session if it doesn't already exist. We handle the | ||
712 | * case where a session was previously created by the netlink | ||
713 | * interface by checking that the session doesn't already have | ||
714 | * a socket and its tunnel socket are what we expect. If any | ||
715 | * of those checks fail, return EEXIST to the caller. | ||
716 | */ | ||
717 | session = l2tp_session_find(sock_net(sk), tunnel, session_id); | ||
718 | if (session == NULL) { | ||
719 | /* Default MTU must allow space for UDP/L2TP/PPP | ||
720 | * headers. | ||
721 | */ | ||
722 | cfg.mtu = cfg.mru = 1500 - PPPOL2TP_HEADER_OVERHEAD; | ||
723 | |||
724 | /* Allocate and initialize a new session context. */ | ||
725 | session = l2tp_session_create(sizeof(struct pppol2tp_session), | ||
726 | tunnel, session_id, | ||
727 | peer_session_id, &cfg); | ||
728 | if (session == NULL) { | ||
729 | error = -ENOMEM; | ||
730 | goto end; | ||
731 | } | ||
732 | } else { | ||
733 | ps = l2tp_session_priv(session); | ||
734 | error = -EEXIST; | ||
735 | if (ps->sock != NULL) | ||
736 | goto end; | ||
737 | |||
738 | /* consistency checks */ | ||
739 | if (ps->tunnel_sock != tunnel->sock) | ||
740 | goto end; | ||
741 | } | ||
742 | |||
743 | /* Associate session with its PPPoL2TP socket */ | ||
744 | ps = l2tp_session_priv(session); | ||
745 | ps->owner = current->pid; | ||
746 | ps->sock = sk; | ||
747 | ps->tunnel_sock = tunnel->sock; | ||
748 | |||
749 | session->recv_skb = pppol2tp_recv; | ||
750 | session->session_close = pppol2tp_session_close; | ||
751 | #if defined(CONFIG_L2TP_DEBUGFS) || defined(CONFIG_L2TP_DEBUGFS_MODULE) | ||
752 | session->show = pppol2tp_show; | ||
753 | #endif | ||
754 | |||
755 | /* We need to know each time a skb is dropped from the reorder | ||
756 | * queue. | ||
757 | */ | ||
758 | session->ref = pppol2tp_session_sock_hold; | ||
759 | session->deref = pppol2tp_session_sock_put; | ||
760 | |||
761 | /* If PMTU discovery was enabled, use the MTU that was discovered */ | ||
762 | dst = sk_dst_get(sk); | ||
763 | if (dst != NULL) { | ||
764 | u32 pmtu = dst_mtu(__sk_dst_get(sk)); | ||
765 | if (pmtu != 0) | ||
766 | session->mtu = session->mru = pmtu - | ||
767 | PPPOL2TP_HEADER_OVERHEAD; | ||
768 | dst_release(dst); | ||
769 | } | ||
770 | |||
771 | /* Special case: if source & dest session_id == 0x0000, this | ||
772 | * socket is being created to manage the tunnel. Just set up | ||
773 | * the internal context for use by ioctl() and sockopt() | ||
774 | * handlers. | ||
775 | */ | ||
776 | if ((session->session_id == 0) && | ||
777 | (session->peer_session_id == 0)) { | ||
778 | error = 0; | ||
779 | goto out_no_ppp; | ||
780 | } | ||
781 | |||
782 | /* The only header we need to worry about is the L2TP | ||
783 | * header. This size is different depending on whether | ||
784 | * sequence numbers are enabled for the data channel. | ||
785 | */ | ||
786 | po->chan.hdrlen = PPPOL2TP_L2TP_HDR_SIZE_NOSEQ; | ||
787 | |||
788 | po->chan.private = sk; | ||
789 | po->chan.ops = &pppol2tp_chan_ops; | ||
790 | po->chan.mtu = session->mtu; | ||
791 | |||
792 | error = ppp_register_net_channel(sock_net(sk), &po->chan); | ||
793 | if (error) | ||
794 | goto end; | ||
795 | |||
796 | out_no_ppp: | ||
797 | /* This is how we get the session context from the socket. */ | ||
798 | sk->sk_user_data = session; | ||
799 | sk->sk_state = PPPOX_CONNECTED; | ||
800 | PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO, | ||
801 | "%s: created\n", session->name); | ||
802 | |||
803 | end: | ||
804 | release_sock(sk); | ||
805 | |||
806 | return error; | ||
807 | } | ||
808 | |||
809 | #ifdef CONFIG_L2TP_V3 | ||
810 | |||
811 | /* Called when creating sessions via the netlink interface. | ||
812 | */ | ||
813 | static int pppol2tp_session_create(struct net *net, u32 tunnel_id, u32 session_id, u32 peer_session_id, struct l2tp_session_cfg *cfg) | ||
814 | { | ||
815 | int error; | ||
816 | struct l2tp_tunnel *tunnel; | ||
817 | struct l2tp_session *session; | ||
818 | struct pppol2tp_session *ps; | ||
819 | |||
820 | tunnel = l2tp_tunnel_find(net, tunnel_id); | ||
821 | |||
822 | /* Error if we can't find the tunnel */ | ||
823 | error = -ENOENT; | ||
824 | if (tunnel == NULL) | ||
825 | goto out; | ||
826 | |||
827 | /* Error if tunnel socket is not prepped */ | ||
828 | if (tunnel->sock == NULL) | ||
829 | goto out; | ||
830 | |||
831 | /* Check that this session doesn't already exist */ | ||
832 | error = -EEXIST; | ||
833 | session = l2tp_session_find(net, tunnel, session_id); | ||
834 | if (session != NULL) | ||
835 | goto out; | ||
836 | |||
837 | /* Default MTU values. */ | ||
838 | if (cfg->mtu == 0) | ||
839 | cfg->mtu = 1500 - PPPOL2TP_HEADER_OVERHEAD; | ||
840 | if (cfg->mru == 0) | ||
841 | cfg->mru = cfg->mtu; | ||
842 | |||
843 | /* Allocate and initialize a new session context. */ | ||
844 | error = -ENOMEM; | ||
845 | session = l2tp_session_create(sizeof(struct pppol2tp_session), | ||
846 | tunnel, session_id, | ||
847 | peer_session_id, cfg); | ||
848 | if (session == NULL) | ||
849 | goto out; | ||
850 | |||
851 | ps = l2tp_session_priv(session); | ||
852 | ps->tunnel_sock = tunnel->sock; | ||
853 | |||
854 | PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO, | ||
855 | "%s: created\n", session->name); | ||
856 | |||
857 | error = 0; | ||
858 | |||
859 | out: | ||
860 | return error; | ||
861 | } | ||
862 | |||
863 | /* Called when deleting sessions via the netlink interface. | ||
864 | */ | ||
865 | static int pppol2tp_session_delete(struct l2tp_session *session) | ||
866 | { | ||
867 | struct pppol2tp_session *ps = l2tp_session_priv(session); | ||
868 | |||
869 | if (ps->sock == NULL) | ||
870 | l2tp_session_dec_refcount(session); | ||
871 | |||
872 | return 0; | ||
873 | } | ||
874 | |||
875 | #endif /* CONFIG_L2TP_V3 */ | ||
876 | |||
877 | /* getname() support. | ||
878 | */ | ||
879 | static int pppol2tp_getname(struct socket *sock, struct sockaddr *uaddr, | ||
880 | int *usockaddr_len, int peer) | ||
881 | { | ||
882 | int len = 0; | ||
883 | int error = 0; | ||
884 | struct l2tp_session *session; | ||
885 | struct l2tp_tunnel *tunnel; | ||
886 | struct sock *sk = sock->sk; | ||
887 | struct inet_sock *inet; | ||
888 | struct pppol2tp_session *pls; | ||
889 | |||
890 | error = -ENOTCONN; | ||
891 | if (sk == NULL) | ||
892 | goto end; | ||
893 | if (sk->sk_state != PPPOX_CONNECTED) | ||
894 | goto end; | ||
895 | |||
896 | error = -EBADF; | ||
897 | session = pppol2tp_sock_to_session(sk); | ||
898 | if (session == NULL) | ||
899 | goto end; | ||
900 | |||
901 | pls = l2tp_session_priv(session); | ||
902 | tunnel = l2tp_sock_to_tunnel(pls->tunnel_sock); | ||
903 | if (tunnel == NULL) { | ||
904 | error = -EBADF; | ||
905 | goto end_put_sess; | ||
906 | } | ||
907 | |||
908 | inet = inet_sk(sk); | ||
909 | if (tunnel->version == 2) { | ||
910 | struct sockaddr_pppol2tp sp; | ||
911 | len = sizeof(sp); | ||
912 | memset(&sp, 0, len); | ||
913 | sp.sa_family = AF_PPPOX; | ||
914 | sp.sa_protocol = PX_PROTO_OL2TP; | ||
915 | sp.pppol2tp.fd = tunnel->fd; | ||
916 | sp.pppol2tp.pid = pls->owner; | ||
917 | sp.pppol2tp.s_tunnel = tunnel->tunnel_id; | ||
918 | sp.pppol2tp.d_tunnel = tunnel->peer_tunnel_id; | ||
919 | sp.pppol2tp.s_session = session->session_id; | ||
920 | sp.pppol2tp.d_session = session->peer_session_id; | ||
921 | sp.pppol2tp.addr.sin_family = AF_INET; | ||
922 | sp.pppol2tp.addr.sin_port = inet->inet_dport; | ||
923 | sp.pppol2tp.addr.sin_addr.s_addr = inet->inet_daddr; | ||
924 | memcpy(uaddr, &sp, len); | ||
925 | } else if (tunnel->version == 3) { | ||
926 | struct sockaddr_pppol2tpv3 sp; | ||
927 | len = sizeof(sp); | ||
928 | memset(&sp, 0, len); | ||
929 | sp.sa_family = AF_PPPOX; | ||
930 | sp.sa_protocol = PX_PROTO_OL2TP; | ||
931 | sp.pppol2tp.fd = tunnel->fd; | ||
932 | sp.pppol2tp.pid = pls->owner; | ||
933 | sp.pppol2tp.s_tunnel = tunnel->tunnel_id; | ||
934 | sp.pppol2tp.d_tunnel = tunnel->peer_tunnel_id; | ||
935 | sp.pppol2tp.s_session = session->session_id; | ||
936 | sp.pppol2tp.d_session = session->peer_session_id; | ||
937 | sp.pppol2tp.addr.sin_family = AF_INET; | ||
938 | sp.pppol2tp.addr.sin_port = inet->inet_dport; | ||
939 | sp.pppol2tp.addr.sin_addr.s_addr = inet->inet_daddr; | ||
940 | memcpy(uaddr, &sp, len); | ||
941 | } | ||
942 | |||
943 | *usockaddr_len = len; | ||
944 | |||
945 | sock_put(pls->tunnel_sock); | ||
946 | end_put_sess: | ||
947 | sock_put(sk); | ||
948 | error = 0; | ||
949 | |||
950 | end: | ||
951 | return error; | ||
952 | } | ||
953 | |||
954 | /**************************************************************************** | ||
955 | * ioctl() handlers. | ||
956 | * | ||
957 | * The PPPoX socket is created for L2TP sessions: tunnels have their own UDP | ||
958 | * sockets. However, in order to control kernel tunnel features, we allow | ||
959 | * userspace to create a special "tunnel" PPPoX socket which is used for | ||
960 | * control only. Tunnel PPPoX sockets have session_id == 0 and simply allow | ||
961 | * the user application to issue L2TP setsockopt(), getsockopt() and ioctl() | ||
962 | * calls. | ||
963 | ****************************************************************************/ | ||
964 | |||
965 | static void pppol2tp_copy_stats(struct pppol2tp_ioc_stats *dest, | ||
966 | struct l2tp_stats *stats) | ||
967 | { | ||
968 | dest->tx_packets = stats->tx_packets; | ||
969 | dest->tx_bytes = stats->tx_bytes; | ||
970 | dest->tx_errors = stats->tx_errors; | ||
971 | dest->rx_packets = stats->rx_packets; | ||
972 | dest->rx_bytes = stats->rx_bytes; | ||
973 | dest->rx_seq_discards = stats->rx_seq_discards; | ||
974 | dest->rx_oos_packets = stats->rx_oos_packets; | ||
975 | dest->rx_errors = stats->rx_errors; | ||
976 | } | ||
977 | |||
978 | /* Session ioctl helper. | ||
979 | */ | ||
980 | static int pppol2tp_session_ioctl(struct l2tp_session *session, | ||
981 | unsigned int cmd, unsigned long arg) | ||
982 | { | ||
983 | struct ifreq ifr; | ||
984 | int err = 0; | ||
985 | struct sock *sk; | ||
986 | int val = (int) arg; | ||
987 | struct pppol2tp_session *ps = l2tp_session_priv(session); | ||
988 | struct l2tp_tunnel *tunnel = session->tunnel; | ||
989 | struct pppol2tp_ioc_stats stats; | ||
990 | |||
991 | PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_DEBUG, | ||
992 | "%s: pppol2tp_session_ioctl(cmd=%#x, arg=%#lx)\n", | ||
993 | session->name, cmd, arg); | ||
994 | |||
995 | sk = ps->sock; | ||
996 | sock_hold(sk); | ||
997 | |||
998 | switch (cmd) { | ||
999 | case SIOCGIFMTU: | ||
1000 | err = -ENXIO; | ||
1001 | if (!(sk->sk_state & PPPOX_CONNECTED)) | ||
1002 | break; | ||
1003 | |||
1004 | err = -EFAULT; | ||
1005 | if (copy_from_user(&ifr, (void __user *) arg, sizeof(struct ifreq))) | ||
1006 | break; | ||
1007 | ifr.ifr_mtu = session->mtu; | ||
1008 | if (copy_to_user((void __user *) arg, &ifr, sizeof(struct ifreq))) | ||
1009 | break; | ||
1010 | |||
1011 | PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO, | ||
1012 | "%s: get mtu=%d\n", session->name, session->mtu); | ||
1013 | err = 0; | ||
1014 | break; | ||
1015 | |||
1016 | case SIOCSIFMTU: | ||
1017 | err = -ENXIO; | ||
1018 | if (!(sk->sk_state & PPPOX_CONNECTED)) | ||
1019 | break; | ||
1020 | |||
1021 | err = -EFAULT; | ||
1022 | if (copy_from_user(&ifr, (void __user *) arg, sizeof(struct ifreq))) | ||
1023 | break; | ||
1024 | |||
1025 | session->mtu = ifr.ifr_mtu; | ||
1026 | |||
1027 | PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO, | ||
1028 | "%s: set mtu=%d\n", session->name, session->mtu); | ||
1029 | err = 0; | ||
1030 | break; | ||
1031 | |||
1032 | case PPPIOCGMRU: | ||
1033 | err = -ENXIO; | ||
1034 | if (!(sk->sk_state & PPPOX_CONNECTED)) | ||
1035 | break; | ||
1036 | |||
1037 | err = -EFAULT; | ||
1038 | if (put_user(session->mru, (int __user *) arg)) | ||
1039 | break; | ||
1040 | |||
1041 | PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO, | ||
1042 | "%s: get mru=%d\n", session->name, session->mru); | ||
1043 | err = 0; | ||
1044 | break; | ||
1045 | |||
1046 | case PPPIOCSMRU: | ||
1047 | err = -ENXIO; | ||
1048 | if (!(sk->sk_state & PPPOX_CONNECTED)) | ||
1049 | break; | ||
1050 | |||
1051 | err = -EFAULT; | ||
1052 | if (get_user(val, (int __user *) arg)) | ||
1053 | break; | ||
1054 | |||
1055 | session->mru = val; | ||
1056 | PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO, | ||
1057 | "%s: set mru=%d\n", session->name, session->mru); | ||
1058 | err = 0; | ||
1059 | break; | ||
1060 | |||
1061 | case PPPIOCGFLAGS: | ||
1062 | err = -EFAULT; | ||
1063 | if (put_user(ps->flags, (int __user *) arg)) | ||
1064 | break; | ||
1065 | |||
1066 | PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO, | ||
1067 | "%s: get flags=%d\n", session->name, ps->flags); | ||
1068 | err = 0; | ||
1069 | break; | ||
1070 | |||
1071 | case PPPIOCSFLAGS: | ||
1072 | err = -EFAULT; | ||
1073 | if (get_user(val, (int __user *) arg)) | ||
1074 | break; | ||
1075 | ps->flags = val; | ||
1076 | PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO, | ||
1077 | "%s: set flags=%d\n", session->name, ps->flags); | ||
1078 | err = 0; | ||
1079 | break; | ||
1080 | |||
1081 | case PPPIOCGL2TPSTATS: | ||
1082 | err = -ENXIO; | ||
1083 | if (!(sk->sk_state & PPPOX_CONNECTED)) | ||
1084 | break; | ||
1085 | |||
1086 | memset(&stats, 0, sizeof(stats)); | ||
1087 | stats.tunnel_id = tunnel->tunnel_id; | ||
1088 | stats.session_id = session->session_id; | ||
1089 | pppol2tp_copy_stats(&stats, &session->stats); | ||
1090 | if (copy_to_user((void __user *) arg, &stats, | ||
1091 | sizeof(stats))) | ||
1092 | break; | ||
1093 | PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO, | ||
1094 | "%s: get L2TP stats\n", session->name); | ||
1095 | err = 0; | ||
1096 | break; | ||
1097 | |||
1098 | default: | ||
1099 | err = -ENOSYS; | ||
1100 | break; | ||
1101 | } | ||
1102 | |||
1103 | sock_put(sk); | ||
1104 | |||
1105 | return err; | ||
1106 | } | ||
1107 | |||
1108 | /* Tunnel ioctl helper. | ||
1109 | * | ||
1110 | * Note the special handling for PPPIOCGL2TPSTATS below. If the ioctl data | ||
1111 | * specifies a session_id, the session ioctl handler is called. This allows an | ||
1112 | * application to retrieve session stats via a tunnel socket. | ||
1113 | */ | ||
1114 | static int pppol2tp_tunnel_ioctl(struct l2tp_tunnel *tunnel, | ||
1115 | unsigned int cmd, unsigned long arg) | ||
1116 | { | ||
1117 | int err = 0; | ||
1118 | struct sock *sk; | ||
1119 | struct pppol2tp_ioc_stats stats; | ||
1120 | |||
1121 | PRINTK(tunnel->debug, PPPOL2TP_MSG_CONTROL, KERN_DEBUG, | ||
1122 | "%s: pppol2tp_tunnel_ioctl(cmd=%#x, arg=%#lx)\n", | ||
1123 | tunnel->name, cmd, arg); | ||
1124 | |||
1125 | sk = tunnel->sock; | ||
1126 | sock_hold(sk); | ||
1127 | |||
1128 | switch (cmd) { | ||
1129 | case PPPIOCGL2TPSTATS: | ||
1130 | err = -ENXIO; | ||
1131 | if (!(sk->sk_state & PPPOX_CONNECTED)) | ||
1132 | break; | ||
1133 | |||
1134 | if (copy_from_user(&stats, (void __user *) arg, | ||
1135 | sizeof(stats))) { | ||
1136 | err = -EFAULT; | ||
1137 | break; | ||
1138 | } | ||
1139 | if (stats.session_id != 0) { | ||
1140 | /* resend to session ioctl handler */ | ||
1141 | struct l2tp_session *session = | ||
1142 | l2tp_session_find(sock_net(sk), tunnel, stats.session_id); | ||
1143 | if (session != NULL) | ||
1144 | err = pppol2tp_session_ioctl(session, cmd, arg); | ||
1145 | else | ||
1146 | err = -EBADR; | ||
1147 | break; | ||
1148 | } | ||
1149 | #ifdef CONFIG_XFRM | ||
1150 | stats.using_ipsec = (sk->sk_policy[0] || sk->sk_policy[1]) ? 1 : 0; | ||
1151 | #endif | ||
1152 | pppol2tp_copy_stats(&stats, &tunnel->stats); | ||
1153 | if (copy_to_user((void __user *) arg, &stats, sizeof(stats))) { | ||
1154 | err = -EFAULT; | ||
1155 | break; | ||
1156 | } | ||
1157 | PRINTK(tunnel->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO, | ||
1158 | "%s: get L2TP stats\n", tunnel->name); | ||
1159 | err = 0; | ||
1160 | break; | ||
1161 | |||
1162 | default: | ||
1163 | err = -ENOSYS; | ||
1164 | break; | ||
1165 | } | ||
1166 | |||
1167 | sock_put(sk); | ||
1168 | |||
1169 | return err; | ||
1170 | } | ||
1171 | |||
1172 | /* Main ioctl() handler. | ||
1173 | * Dispatch to tunnel or session helpers depending on the socket. | ||
1174 | */ | ||
1175 | static int pppol2tp_ioctl(struct socket *sock, unsigned int cmd, | ||
1176 | unsigned long arg) | ||
1177 | { | ||
1178 | struct sock *sk = sock->sk; | ||
1179 | struct l2tp_session *session; | ||
1180 | struct l2tp_tunnel *tunnel; | ||
1181 | struct pppol2tp_session *ps; | ||
1182 | int err; | ||
1183 | |||
1184 | if (!sk) | ||
1185 | return 0; | ||
1186 | |||
1187 | err = -EBADF; | ||
1188 | if (sock_flag(sk, SOCK_DEAD) != 0) | ||
1189 | goto end; | ||
1190 | |||
1191 | err = -ENOTCONN; | ||
1192 | if ((sk->sk_user_data == NULL) || | ||
1193 | (!(sk->sk_state & (PPPOX_CONNECTED | PPPOX_BOUND)))) | ||
1194 | goto end; | ||
1195 | |||
1196 | /* Get session context from the socket */ | ||
1197 | err = -EBADF; | ||
1198 | session = pppol2tp_sock_to_session(sk); | ||
1199 | if (session == NULL) | ||
1200 | goto end; | ||
1201 | |||
1202 | /* Special case: if session's session_id is zero, treat ioctl as a | ||
1203 | * tunnel ioctl | ||
1204 | */ | ||
1205 | ps = l2tp_session_priv(session); | ||
1206 | if ((session->session_id == 0) && | ||
1207 | (session->peer_session_id == 0)) { | ||
1208 | err = -EBADF; | ||
1209 | tunnel = l2tp_sock_to_tunnel(ps->tunnel_sock); | ||
1210 | if (tunnel == NULL) | ||
1211 | goto end_put_sess; | ||
1212 | |||
1213 | err = pppol2tp_tunnel_ioctl(tunnel, cmd, arg); | ||
1214 | sock_put(ps->tunnel_sock); | ||
1215 | goto end_put_sess; | ||
1216 | } | ||
1217 | |||
1218 | err = pppol2tp_session_ioctl(session, cmd, arg); | ||
1219 | |||
1220 | end_put_sess: | ||
1221 | sock_put(sk); | ||
1222 | end: | ||
1223 | return err; | ||
1224 | } | ||
1225 | |||
1226 | /***************************************************************************** | ||
1227 | * setsockopt() / getsockopt() support. | ||
1228 | * | ||
1229 | * The PPPoX socket is created for L2TP sessions: tunnels have their own UDP | ||
1230 | * sockets. In order to control kernel tunnel features, we allow userspace to | ||
1231 | * create a special "tunnel" PPPoX socket which is used for control only. | ||
1232 | * Tunnel PPPoX sockets have session_id == 0 and simply allow the user | ||
1233 | * application to issue L2TP setsockopt(), getsockopt() and ioctl() calls. | ||
1234 | *****************************************************************************/ | ||
1235 | |||
1236 | /* Tunnel setsockopt() helper. | ||
1237 | */ | ||
1238 | static int pppol2tp_tunnel_setsockopt(struct sock *sk, | ||
1239 | struct l2tp_tunnel *tunnel, | ||
1240 | int optname, int val) | ||
1241 | { | ||
1242 | int err = 0; | ||
1243 | |||
1244 | switch (optname) { | ||
1245 | case PPPOL2TP_SO_DEBUG: | ||
1246 | tunnel->debug = val; | ||
1247 | PRINTK(tunnel->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO, | ||
1248 | "%s: set debug=%x\n", tunnel->name, tunnel->debug); | ||
1249 | break; | ||
1250 | |||
1251 | default: | ||
1252 | err = -ENOPROTOOPT; | ||
1253 | break; | ||
1254 | } | ||
1255 | |||
1256 | return err; | ||
1257 | } | ||
1258 | |||
1259 | /* Session setsockopt helper. | ||
1260 | */ | ||
1261 | static int pppol2tp_session_setsockopt(struct sock *sk, | ||
1262 | struct l2tp_session *session, | ||
1263 | int optname, int val) | ||
1264 | { | ||
1265 | int err = 0; | ||
1266 | struct pppol2tp_session *ps = l2tp_session_priv(session); | ||
1267 | |||
1268 | switch (optname) { | ||
1269 | case PPPOL2TP_SO_RECVSEQ: | ||
1270 | if ((val != 0) && (val != 1)) { | ||
1271 | err = -EINVAL; | ||
1272 | break; | ||
1273 | } | ||
1274 | session->recv_seq = val ? -1 : 0; | ||
1275 | PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO, | ||
1276 | "%s: set recv_seq=%d\n", session->name, session->recv_seq); | ||
1277 | break; | ||
1278 | |||
1279 | case PPPOL2TP_SO_SENDSEQ: | ||
1280 | if ((val != 0) && (val != 1)) { | ||
1281 | err = -EINVAL; | ||
1282 | break; | ||
1283 | } | ||
1284 | session->send_seq = val ? -1 : 0; | ||
1285 | { | ||
1286 | struct sock *ssk = ps->sock; | ||
1287 | struct pppox_sock *po = pppox_sk(ssk); | ||
1288 | po->chan.hdrlen = val ? PPPOL2TP_L2TP_HDR_SIZE_SEQ : | ||
1289 | PPPOL2TP_L2TP_HDR_SIZE_NOSEQ; | ||
1290 | } | ||
1291 | PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO, | ||
1292 | "%s: set send_seq=%d\n", session->name, session->send_seq); | ||
1293 | break; | ||
1294 | |||
1295 | case PPPOL2TP_SO_LNSMODE: | ||
1296 | if ((val != 0) && (val != 1)) { | ||
1297 | err = -EINVAL; | ||
1298 | break; | ||
1299 | } | ||
1300 | session->lns_mode = val ? -1 : 0; | ||
1301 | PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO, | ||
1302 | "%s: set lns_mode=%d\n", session->name, session->lns_mode); | ||
1303 | break; | ||
1304 | |||
1305 | case PPPOL2TP_SO_DEBUG: | ||
1306 | session->debug = val; | ||
1307 | PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO, | ||
1308 | "%s: set debug=%x\n", session->name, session->debug); | ||
1309 | break; | ||
1310 | |||
1311 | case PPPOL2TP_SO_REORDERTO: | ||
1312 | session->reorder_timeout = msecs_to_jiffies(val); | ||
1313 | PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO, | ||
1314 | "%s: set reorder_timeout=%d\n", session->name, session->reorder_timeout); | ||
1315 | break; | ||
1316 | |||
1317 | default: | ||
1318 | err = -ENOPROTOOPT; | ||
1319 | break; | ||
1320 | } | ||
1321 | |||
1322 | return err; | ||
1323 | } | ||
1324 | |||
1325 | /* Main setsockopt() entry point. | ||
1326 | * Does API checks, then calls either the tunnel or session setsockopt | ||
1327 | * handler, according to whether the PPPoL2TP socket is a for a regular | ||
1328 | * session or the special tunnel type. | ||
1329 | */ | ||
1330 | static int pppol2tp_setsockopt(struct socket *sock, int level, int optname, | ||
1331 | char __user *optval, unsigned int optlen) | ||
1332 | { | ||
1333 | struct sock *sk = sock->sk; | ||
1334 | struct l2tp_session *session; | ||
1335 | struct l2tp_tunnel *tunnel; | ||
1336 | struct pppol2tp_session *ps; | ||
1337 | int val; | ||
1338 | int err; | ||
1339 | |||
1340 | if (level != SOL_PPPOL2TP) | ||
1341 | return udp_prot.setsockopt(sk, level, optname, optval, optlen); | ||
1342 | |||
1343 | if (optlen < sizeof(int)) | ||
1344 | return -EINVAL; | ||
1345 | |||
1346 | if (get_user(val, (int __user *)optval)) | ||
1347 | return -EFAULT; | ||
1348 | |||
1349 | err = -ENOTCONN; | ||
1350 | if (sk->sk_user_data == NULL) | ||
1351 | goto end; | ||
1352 | |||
1353 | /* Get session context from the socket */ | ||
1354 | err = -EBADF; | ||
1355 | session = pppol2tp_sock_to_session(sk); | ||
1356 | if (session == NULL) | ||
1357 | goto end; | ||
1358 | |||
1359 | /* Special case: if session_id == 0x0000, treat as operation on tunnel | ||
1360 | */ | ||
1361 | ps = l2tp_session_priv(session); | ||
1362 | if ((session->session_id == 0) && | ||
1363 | (session->peer_session_id == 0)) { | ||
1364 | err = -EBADF; | ||
1365 | tunnel = l2tp_sock_to_tunnel(ps->tunnel_sock); | ||
1366 | if (tunnel == NULL) | ||
1367 | goto end_put_sess; | ||
1368 | |||
1369 | err = pppol2tp_tunnel_setsockopt(sk, tunnel, optname, val); | ||
1370 | sock_put(ps->tunnel_sock); | ||
1371 | } else | ||
1372 | err = pppol2tp_session_setsockopt(sk, session, optname, val); | ||
1373 | |||
1374 | err = 0; | ||
1375 | |||
1376 | end_put_sess: | ||
1377 | sock_put(sk); | ||
1378 | end: | ||
1379 | return err; | ||
1380 | } | ||
1381 | |||
1382 | /* Tunnel getsockopt helper. Called with sock locked. | ||
1383 | */ | ||
1384 | static int pppol2tp_tunnel_getsockopt(struct sock *sk, | ||
1385 | struct l2tp_tunnel *tunnel, | ||
1386 | int optname, int *val) | ||
1387 | { | ||
1388 | int err = 0; | ||
1389 | |||
1390 | switch (optname) { | ||
1391 | case PPPOL2TP_SO_DEBUG: | ||
1392 | *val = tunnel->debug; | ||
1393 | PRINTK(tunnel->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO, | ||
1394 | "%s: get debug=%x\n", tunnel->name, tunnel->debug); | ||
1395 | break; | ||
1396 | |||
1397 | default: | ||
1398 | err = -ENOPROTOOPT; | ||
1399 | break; | ||
1400 | } | ||
1401 | |||
1402 | return err; | ||
1403 | } | ||
1404 | |||
1405 | /* Session getsockopt helper. Called with sock locked. | ||
1406 | */ | ||
1407 | static int pppol2tp_session_getsockopt(struct sock *sk, | ||
1408 | struct l2tp_session *session, | ||
1409 | int optname, int *val) | ||
1410 | { | ||
1411 | int err = 0; | ||
1412 | |||
1413 | switch (optname) { | ||
1414 | case PPPOL2TP_SO_RECVSEQ: | ||
1415 | *val = session->recv_seq; | ||
1416 | PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO, | ||
1417 | "%s: get recv_seq=%d\n", session->name, *val); | ||
1418 | break; | ||
1419 | |||
1420 | case PPPOL2TP_SO_SENDSEQ: | ||
1421 | *val = session->send_seq; | ||
1422 | PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO, | ||
1423 | "%s: get send_seq=%d\n", session->name, *val); | ||
1424 | break; | ||
1425 | |||
1426 | case PPPOL2TP_SO_LNSMODE: | ||
1427 | *val = session->lns_mode; | ||
1428 | PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO, | ||
1429 | "%s: get lns_mode=%d\n", session->name, *val); | ||
1430 | break; | ||
1431 | |||
1432 | case PPPOL2TP_SO_DEBUG: | ||
1433 | *val = session->debug; | ||
1434 | PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO, | ||
1435 | "%s: get debug=%d\n", session->name, *val); | ||
1436 | break; | ||
1437 | |||
1438 | case PPPOL2TP_SO_REORDERTO: | ||
1439 | *val = (int) jiffies_to_msecs(session->reorder_timeout); | ||
1440 | PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO, | ||
1441 | "%s: get reorder_timeout=%d\n", session->name, *val); | ||
1442 | break; | ||
1443 | |||
1444 | default: | ||
1445 | err = -ENOPROTOOPT; | ||
1446 | } | ||
1447 | |||
1448 | return err; | ||
1449 | } | ||
1450 | |||
1451 | /* Main getsockopt() entry point. | ||
1452 | * Does API checks, then calls either the tunnel or session getsockopt | ||
1453 | * handler, according to whether the PPPoX socket is a for a regular session | ||
1454 | * or the special tunnel type. | ||
1455 | */ | ||
1456 | static int pppol2tp_getsockopt(struct socket *sock, int level, | ||
1457 | int optname, char __user *optval, int __user *optlen) | ||
1458 | { | ||
1459 | struct sock *sk = sock->sk; | ||
1460 | struct l2tp_session *session; | ||
1461 | struct l2tp_tunnel *tunnel; | ||
1462 | int val, len; | ||
1463 | int err; | ||
1464 | struct pppol2tp_session *ps; | ||
1465 | |||
1466 | if (level != SOL_PPPOL2TP) | ||
1467 | return udp_prot.getsockopt(sk, level, optname, optval, optlen); | ||
1468 | |||
1469 | if (get_user(len, (int __user *) optlen)) | ||
1470 | return -EFAULT; | ||
1471 | |||
1472 | len = min_t(unsigned int, len, sizeof(int)); | ||
1473 | |||
1474 | if (len < 0) | ||
1475 | return -EINVAL; | ||
1476 | |||
1477 | err = -ENOTCONN; | ||
1478 | if (sk->sk_user_data == NULL) | ||
1479 | goto end; | ||
1480 | |||
1481 | /* Get the session context */ | ||
1482 | err = -EBADF; | ||
1483 | session = pppol2tp_sock_to_session(sk); | ||
1484 | if (session == NULL) | ||
1485 | goto end; | ||
1486 | |||
1487 | /* Special case: if session_id == 0x0000, treat as operation on tunnel */ | ||
1488 | ps = l2tp_session_priv(session); | ||
1489 | if ((session->session_id == 0) && | ||
1490 | (session->peer_session_id == 0)) { | ||
1491 | err = -EBADF; | ||
1492 | tunnel = l2tp_sock_to_tunnel(ps->tunnel_sock); | ||
1493 | if (tunnel == NULL) | ||
1494 | goto end_put_sess; | ||
1495 | |||
1496 | err = pppol2tp_tunnel_getsockopt(sk, tunnel, optname, &val); | ||
1497 | sock_put(ps->tunnel_sock); | ||
1498 | } else | ||
1499 | err = pppol2tp_session_getsockopt(sk, session, optname, &val); | ||
1500 | |||
1501 | err = -EFAULT; | ||
1502 | if (put_user(len, (int __user *) optlen)) | ||
1503 | goto end_put_sess; | ||
1504 | |||
1505 | if (copy_to_user((void __user *) optval, &val, len)) | ||
1506 | goto end_put_sess; | ||
1507 | |||
1508 | err = 0; | ||
1509 | |||
1510 | end_put_sess: | ||
1511 | sock_put(sk); | ||
1512 | end: | ||
1513 | return err; | ||
1514 | } | ||
1515 | |||
1516 | /***************************************************************************** | ||
1517 | * /proc filesystem for debug | ||
1518 | * Since the original pppol2tp driver provided /proc/net/pppol2tp for | ||
1519 | * L2TPv2, we dump only L2TPv2 tunnels and sessions here. | ||
1520 | *****************************************************************************/ | ||
1521 | |||
1522 | static unsigned int pppol2tp_net_id; | ||
1523 | |||
1524 | #ifdef CONFIG_PROC_FS | ||
1525 | |||
1526 | struct pppol2tp_seq_data { | ||
1527 | struct seq_net_private p; | ||
1528 | int tunnel_idx; /* current tunnel */ | ||
1529 | int session_idx; /* index of session within current tunnel */ | ||
1530 | struct l2tp_tunnel *tunnel; | ||
1531 | struct l2tp_session *session; /* NULL means get next tunnel */ | ||
1532 | }; | ||
1533 | |||
1534 | static void pppol2tp_next_tunnel(struct net *net, struct pppol2tp_seq_data *pd) | ||
1535 | { | ||
1536 | for (;;) { | ||
1537 | pd->tunnel = l2tp_tunnel_find_nth(net, pd->tunnel_idx); | ||
1538 | pd->tunnel_idx++; | ||
1539 | |||
1540 | if (pd->tunnel == NULL) | ||
1541 | break; | ||
1542 | |||
1543 | /* Ignore L2TPv3 tunnels */ | ||
1544 | if (pd->tunnel->version < 3) | ||
1545 | break; | ||
1546 | } | ||
1547 | } | ||
1548 | |||
1549 | static void pppol2tp_next_session(struct net *net, struct pppol2tp_seq_data *pd) | ||
1550 | { | ||
1551 | pd->session = l2tp_session_find_nth(pd->tunnel, pd->session_idx); | ||
1552 | pd->session_idx++; | ||
1553 | |||
1554 | if (pd->session == NULL) { | ||
1555 | pd->session_idx = 0; | ||
1556 | pppol2tp_next_tunnel(net, pd); | ||
1557 | } | ||
1558 | } | ||
1559 | |||
1560 | static void *pppol2tp_seq_start(struct seq_file *m, loff_t *offs) | ||
1561 | { | ||
1562 | struct pppol2tp_seq_data *pd = SEQ_START_TOKEN; | ||
1563 | loff_t pos = *offs; | ||
1564 | struct net *net; | ||
1565 | |||
1566 | if (!pos) | ||
1567 | goto out; | ||
1568 | |||
1569 | BUG_ON(m->private == NULL); | ||
1570 | pd = m->private; | ||
1571 | net = seq_file_net(m); | ||
1572 | |||
1573 | if (pd->tunnel == NULL) | ||
1574 | pppol2tp_next_tunnel(net, pd); | ||
1575 | else | ||
1576 | pppol2tp_next_session(net, pd); | ||
1577 | |||
1578 | /* NULL tunnel and session indicates end of list */ | ||
1579 | if ((pd->tunnel == NULL) && (pd->session == NULL)) | ||
1580 | pd = NULL; | ||
1581 | |||
1582 | out: | ||
1583 | return pd; | ||
1584 | } | ||
1585 | |||
1586 | static void *pppol2tp_seq_next(struct seq_file *m, void *v, loff_t *pos) | ||
1587 | { | ||
1588 | (*pos)++; | ||
1589 | return NULL; | ||
1590 | } | ||
1591 | |||
1592 | static void pppol2tp_seq_stop(struct seq_file *p, void *v) | ||
1593 | { | ||
1594 | /* nothing to do */ | ||
1595 | } | ||
1596 | |||
1597 | static void pppol2tp_seq_tunnel_show(struct seq_file *m, void *v) | ||
1598 | { | ||
1599 | struct l2tp_tunnel *tunnel = v; | ||
1600 | |||
1601 | seq_printf(m, "\nTUNNEL '%s', %c %d\n", | ||
1602 | tunnel->name, | ||
1603 | (tunnel == tunnel->sock->sk_user_data) ? 'Y' : 'N', | ||
1604 | atomic_read(&tunnel->ref_count) - 1); | ||
1605 | seq_printf(m, " %08x %llu/%llu/%llu %llu/%llu/%llu\n", | ||
1606 | tunnel->debug, | ||
1607 | (unsigned long long)tunnel->stats.tx_packets, | ||
1608 | (unsigned long long)tunnel->stats.tx_bytes, | ||
1609 | (unsigned long long)tunnel->stats.tx_errors, | ||
1610 | (unsigned long long)tunnel->stats.rx_packets, | ||
1611 | (unsigned long long)tunnel->stats.rx_bytes, | ||
1612 | (unsigned long long)tunnel->stats.rx_errors); | ||
1613 | } | ||
1614 | |||
1615 | static void pppol2tp_seq_session_show(struct seq_file *m, void *v) | ||
1616 | { | ||
1617 | struct l2tp_session *session = v; | ||
1618 | struct l2tp_tunnel *tunnel = session->tunnel; | ||
1619 | struct pppol2tp_session *ps = l2tp_session_priv(session); | ||
1620 | struct pppox_sock *po = pppox_sk(ps->sock); | ||
1621 | u32 ip = 0; | ||
1622 | u16 port = 0; | ||
1623 | |||
1624 | if (tunnel->sock) { | ||
1625 | struct inet_sock *inet = inet_sk(tunnel->sock); | ||
1626 | ip = ntohl(inet->inet_saddr); | ||
1627 | port = ntohs(inet->inet_sport); | ||
1628 | } | ||
1629 | |||
1630 | seq_printf(m, " SESSION '%s' %08X/%d %04X/%04X -> " | ||
1631 | "%04X/%04X %d %c\n", | ||
1632 | session->name, ip, port, | ||
1633 | tunnel->tunnel_id, | ||
1634 | session->session_id, | ||
1635 | tunnel->peer_tunnel_id, | ||
1636 | session->peer_session_id, | ||
1637 | ps->sock->sk_state, | ||
1638 | (session == ps->sock->sk_user_data) ? | ||
1639 | 'Y' : 'N'); | ||
1640 | seq_printf(m, " %d/%d/%c/%c/%s %08x %u\n", | ||
1641 | session->mtu, session->mru, | ||
1642 | session->recv_seq ? 'R' : '-', | ||
1643 | session->send_seq ? 'S' : '-', | ||
1644 | session->lns_mode ? "LNS" : "LAC", | ||
1645 | session->debug, | ||
1646 | jiffies_to_msecs(session->reorder_timeout)); | ||
1647 | seq_printf(m, " %hu/%hu %llu/%llu/%llu %llu/%llu/%llu\n", | ||
1648 | session->nr, session->ns, | ||
1649 | (unsigned long long)session->stats.tx_packets, | ||
1650 | (unsigned long long)session->stats.tx_bytes, | ||
1651 | (unsigned long long)session->stats.tx_errors, | ||
1652 | (unsigned long long)session->stats.rx_packets, | ||
1653 | (unsigned long long)session->stats.rx_bytes, | ||
1654 | (unsigned long long)session->stats.rx_errors); | ||
1655 | |||
1656 | if (po) | ||
1657 | seq_printf(m, " interface %s\n", ppp_dev_name(&po->chan)); | ||
1658 | } | ||
1659 | |||
1660 | static int pppol2tp_seq_show(struct seq_file *m, void *v) | ||
1661 | { | ||
1662 | struct pppol2tp_seq_data *pd = v; | ||
1663 | |||
1664 | /* display header on line 1 */ | ||
1665 | if (v == SEQ_START_TOKEN) { | ||
1666 | seq_puts(m, "PPPoL2TP driver info, " PPPOL2TP_DRV_VERSION "\n"); | ||
1667 | seq_puts(m, "TUNNEL name, user-data-ok session-count\n"); | ||
1668 | seq_puts(m, " debug tx-pkts/bytes/errs rx-pkts/bytes/errs\n"); | ||
1669 | seq_puts(m, " SESSION name, addr/port src-tid/sid " | ||
1670 | "dest-tid/sid state user-data-ok\n"); | ||
1671 | seq_puts(m, " mtu/mru/rcvseq/sendseq/lns debug reorderto\n"); | ||
1672 | seq_puts(m, " nr/ns tx-pkts/bytes/errs rx-pkts/bytes/errs\n"); | ||
1673 | goto out; | ||
1674 | } | ||
1675 | |||
1676 | /* Show the tunnel or session context. | ||
1677 | */ | ||
1678 | if (pd->session == NULL) | ||
1679 | pppol2tp_seq_tunnel_show(m, pd->tunnel); | ||
1680 | else | ||
1681 | pppol2tp_seq_session_show(m, pd->session); | ||
1682 | |||
1683 | out: | ||
1684 | return 0; | ||
1685 | } | ||
1686 | |||
1687 | static const struct seq_operations pppol2tp_seq_ops = { | ||
1688 | .start = pppol2tp_seq_start, | ||
1689 | .next = pppol2tp_seq_next, | ||
1690 | .stop = pppol2tp_seq_stop, | ||
1691 | .show = pppol2tp_seq_show, | ||
1692 | }; | ||
1693 | |||
1694 | /* Called when our /proc file is opened. We allocate data for use when | ||
1695 | * iterating our tunnel / session contexts and store it in the private | ||
1696 | * data of the seq_file. | ||
1697 | */ | ||
1698 | static int pppol2tp_proc_open(struct inode *inode, struct file *file) | ||
1699 | { | ||
1700 | return seq_open_net(inode, file, &pppol2tp_seq_ops, | ||
1701 | sizeof(struct pppol2tp_seq_data)); | ||
1702 | } | ||
1703 | |||
1704 | static const struct file_operations pppol2tp_proc_fops = { | ||
1705 | .owner = THIS_MODULE, | ||
1706 | .open = pppol2tp_proc_open, | ||
1707 | .read = seq_read, | ||
1708 | .llseek = seq_lseek, | ||
1709 | .release = seq_release_net, | ||
1710 | }; | ||
1711 | |||
1712 | #endif /* CONFIG_PROC_FS */ | ||
1713 | |||
1714 | /***************************************************************************** | ||
1715 | * Network namespace | ||
1716 | *****************************************************************************/ | ||
1717 | |||
1718 | static __net_init int pppol2tp_init_net(struct net *net) | ||
1719 | { | ||
1720 | struct proc_dir_entry *pde; | ||
1721 | int err = 0; | ||
1722 | |||
1723 | pde = proc_net_fops_create(net, "pppol2tp", S_IRUGO, &pppol2tp_proc_fops); | ||
1724 | if (!pde) { | ||
1725 | err = -ENOMEM; | ||
1726 | goto out; | ||
1727 | } | ||
1728 | |||
1729 | out: | ||
1730 | return err; | ||
1731 | } | ||
1732 | |||
1733 | static __net_exit void pppol2tp_exit_net(struct net *net) | ||
1734 | { | ||
1735 | proc_net_remove(net, "pppol2tp"); | ||
1736 | } | ||
1737 | |||
1738 | static struct pernet_operations pppol2tp_net_ops = { | ||
1739 | .init = pppol2tp_init_net, | ||
1740 | .exit = pppol2tp_exit_net, | ||
1741 | .id = &pppol2tp_net_id, | ||
1742 | }; | ||
1743 | |||
1744 | /***************************************************************************** | ||
1745 | * Init and cleanup | ||
1746 | *****************************************************************************/ | ||
1747 | |||
1748 | static const struct proto_ops pppol2tp_ops = { | ||
1749 | .family = AF_PPPOX, | ||
1750 | .owner = THIS_MODULE, | ||
1751 | .release = pppol2tp_release, | ||
1752 | .bind = sock_no_bind, | ||
1753 | .connect = pppol2tp_connect, | ||
1754 | .socketpair = sock_no_socketpair, | ||
1755 | .accept = sock_no_accept, | ||
1756 | .getname = pppol2tp_getname, | ||
1757 | .poll = datagram_poll, | ||
1758 | .listen = sock_no_listen, | ||
1759 | .shutdown = sock_no_shutdown, | ||
1760 | .setsockopt = pppol2tp_setsockopt, | ||
1761 | .getsockopt = pppol2tp_getsockopt, | ||
1762 | .sendmsg = pppol2tp_sendmsg, | ||
1763 | .recvmsg = pppol2tp_recvmsg, | ||
1764 | .mmap = sock_no_mmap, | ||
1765 | .ioctl = pppox_ioctl, | ||
1766 | }; | ||
1767 | |||
1768 | static struct pppox_proto pppol2tp_proto = { | ||
1769 | .create = pppol2tp_create, | ||
1770 | .ioctl = pppol2tp_ioctl | ||
1771 | }; | ||
1772 | |||
1773 | #ifdef CONFIG_L2TP_V3 | ||
1774 | |||
1775 | static const struct l2tp_nl_cmd_ops pppol2tp_nl_cmd_ops = { | ||
1776 | .session_create = pppol2tp_session_create, | ||
1777 | .session_delete = pppol2tp_session_delete, | ||
1778 | }; | ||
1779 | |||
1780 | #endif /* CONFIG_L2TP_V3 */ | ||
1781 | |||
1782 | static int __init pppol2tp_init(void) | ||
1783 | { | ||
1784 | int err; | ||
1785 | |||
1786 | err = register_pernet_device(&pppol2tp_net_ops); | ||
1787 | if (err) | ||
1788 | goto out; | ||
1789 | |||
1790 | err = proto_register(&pppol2tp_sk_proto, 0); | ||
1791 | if (err) | ||
1792 | goto out_unregister_pppol2tp_pernet; | ||
1793 | |||
1794 | err = register_pppox_proto(PX_PROTO_OL2TP, &pppol2tp_proto); | ||
1795 | if (err) | ||
1796 | goto out_unregister_pppol2tp_proto; | ||
1797 | |||
1798 | #ifdef CONFIG_L2TP_V3 | ||
1799 | err = l2tp_nl_register_ops(L2TP_PWTYPE_PPP, &pppol2tp_nl_cmd_ops); | ||
1800 | if (err) | ||
1801 | goto out_unregister_pppox; | ||
1802 | #endif | ||
1803 | |||
1804 | printk(KERN_INFO "PPPoL2TP kernel driver, %s\n", | ||
1805 | PPPOL2TP_DRV_VERSION); | ||
1806 | |||
1807 | out: | ||
1808 | return err; | ||
1809 | |||
1810 | #ifdef CONFIG_L2TP_V3 | ||
1811 | out_unregister_pppox: | ||
1812 | unregister_pppox_proto(PX_PROTO_OL2TP); | ||
1813 | #endif | ||
1814 | out_unregister_pppol2tp_proto: | ||
1815 | proto_unregister(&pppol2tp_sk_proto); | ||
1816 | out_unregister_pppol2tp_pernet: | ||
1817 | unregister_pernet_device(&pppol2tp_net_ops); | ||
1818 | goto out; | ||
1819 | } | ||
1820 | |||
1821 | static void __exit pppol2tp_exit(void) | ||
1822 | { | ||
1823 | #ifdef CONFIG_L2TP_V3 | ||
1824 | l2tp_nl_unregister_ops(L2TP_PWTYPE_PPP); | ||
1825 | #endif | ||
1826 | unregister_pppox_proto(PX_PROTO_OL2TP); | ||
1827 | proto_unregister(&pppol2tp_sk_proto); | ||
1828 | unregister_pernet_device(&pppol2tp_net_ops); | ||
1829 | } | ||
1830 | |||
1831 | module_init(pppol2tp_init); | ||
1832 | module_exit(pppol2tp_exit); | ||
1833 | |||
1834 | MODULE_AUTHOR("James Chapman <jchapman@katalix.com>"); | ||
1835 | MODULE_DESCRIPTION("PPP over L2TP over UDP"); | ||
1836 | MODULE_LICENSE("GPL"); | ||
1837 | MODULE_VERSION(PPPOL2TP_DRV_VERSION); | ||
diff --git a/net/lapb/lapb_iface.c b/net/lapb/lapb_iface.c index bda96d18fd98..d5d8d555c410 100644 --- a/net/lapb/lapb_iface.c +++ b/net/lapb/lapb_iface.c | |||
@@ -29,6 +29,7 @@ | |||
29 | #include <linux/inet.h> | 29 | #include <linux/inet.h> |
30 | #include <linux/if_arp.h> | 30 | #include <linux/if_arp.h> |
31 | #include <linux/skbuff.h> | 31 | #include <linux/skbuff.h> |
32 | #include <linux/slab.h> | ||
32 | #include <net/sock.h> | 33 | #include <net/sock.h> |
33 | #include <asm/uaccess.h> | 34 | #include <asm/uaccess.h> |
34 | #include <asm/system.h> | 35 | #include <asm/system.h> |
diff --git a/net/lapb/lapb_in.c b/net/lapb/lapb_in.c index 6762e7c751eb..21904a002449 100644 --- a/net/lapb/lapb_in.c +++ b/net/lapb/lapb_in.c | |||
@@ -27,6 +27,7 @@ | |||
27 | #include <linux/inet.h> | 27 | #include <linux/inet.h> |
28 | #include <linux/netdevice.h> | 28 | #include <linux/netdevice.h> |
29 | #include <linux/skbuff.h> | 29 | #include <linux/skbuff.h> |
30 | #include <linux/slab.h> | ||
30 | #include <net/sock.h> | 31 | #include <net/sock.h> |
31 | #include <asm/uaccess.h> | 32 | #include <asm/uaccess.h> |
32 | #include <asm/system.h> | 33 | #include <asm/system.h> |
diff --git a/net/lapb/lapb_out.c b/net/lapb/lapb_out.c index 339cc5f2684f..c75a79540f9f 100644 --- a/net/lapb/lapb_out.c +++ b/net/lapb/lapb_out.c | |||
@@ -25,6 +25,7 @@ | |||
25 | #include <linux/net.h> | 25 | #include <linux/net.h> |
26 | #include <linux/inet.h> | 26 | #include <linux/inet.h> |
27 | #include <linux/skbuff.h> | 27 | #include <linux/skbuff.h> |
28 | #include <linux/slab.h> | ||
28 | #include <net/sock.h> | 29 | #include <net/sock.h> |
29 | #include <asm/uaccess.h> | 30 | #include <asm/uaccess.h> |
30 | #include <asm/system.h> | 31 | #include <asm/system.h> |
diff --git a/net/lapb/lapb_subr.c b/net/lapb/lapb_subr.c index b827f47ac133..43a2a7fb327b 100644 --- a/net/lapb/lapb_subr.c +++ b/net/lapb/lapb_subr.c | |||
@@ -24,6 +24,7 @@ | |||
24 | #include <linux/net.h> | 24 | #include <linux/net.h> |
25 | #include <linux/inet.h> | 25 | #include <linux/inet.h> |
26 | #include <linux/skbuff.h> | 26 | #include <linux/skbuff.h> |
27 | #include <linux/slab.h> | ||
27 | #include <net/sock.h> | 28 | #include <net/sock.h> |
28 | #include <asm/uaccess.h> | 29 | #include <asm/uaccess.h> |
29 | #include <asm/system.h> | 30 | #include <asm/system.h> |
diff --git a/net/llc/af_llc.c b/net/llc/af_llc.c index e35d907fba2c..2db6a9f75913 100644 --- a/net/llc/af_llc.c +++ b/net/llc/af_llc.c | |||
@@ -25,6 +25,7 @@ | |||
25 | #include <linux/module.h> | 25 | #include <linux/module.h> |
26 | #include <linux/rtnetlink.h> | 26 | #include <linux/rtnetlink.h> |
27 | #include <linux/init.h> | 27 | #include <linux/init.h> |
28 | #include <linux/slab.h> | ||
28 | #include <net/llc.h> | 29 | #include <net/llc.h> |
29 | #include <net/llc_sap.h> | 30 | #include <net/llc_sap.h> |
30 | #include <net/llc_pdu.h> | 31 | #include <net/llc_pdu.h> |
diff --git a/net/llc/llc_c_ac.c b/net/llc/llc_c_ac.c index 86d6985b9d49..ea225bd2672c 100644 --- a/net/llc/llc_c_ac.c +++ b/net/llc/llc_c_ac.c | |||
@@ -18,6 +18,7 @@ | |||
18 | * See the GNU General Public License for more details. | 18 | * See the GNU General Public License for more details. |
19 | */ | 19 | */ |
20 | #include <linux/netdevice.h> | 20 | #include <linux/netdevice.h> |
21 | #include <linux/slab.h> | ||
21 | #include <net/llc_conn.h> | 22 | #include <net/llc_conn.h> |
22 | #include <net/llc_sap.h> | 23 | #include <net/llc_sap.h> |
23 | #include <net/sock.h> | 24 | #include <net/sock.h> |
diff --git a/net/llc/llc_conn.c b/net/llc/llc_conn.c index a12144da7974..ba137a6a224d 100644 --- a/net/llc/llc_conn.c +++ b/net/llc/llc_conn.c | |||
@@ -13,6 +13,7 @@ | |||
13 | */ | 13 | */ |
14 | 14 | ||
15 | #include <linux/init.h> | 15 | #include <linux/init.h> |
16 | #include <linux/slab.h> | ||
16 | #include <net/llc_sap.h> | 17 | #include <net/llc_sap.h> |
17 | #include <net/llc_conn.h> | 18 | #include <net/llc_conn.h> |
18 | #include <net/sock.h> | 19 | #include <net/sock.h> |
diff --git a/net/llc/llc_core.c b/net/llc/llc_core.c index 78167e81dfeb..2bb0ddff8c0f 100644 --- a/net/llc/llc_core.c +++ b/net/llc/llc_core.c | |||
@@ -144,12 +144,6 @@ static struct packet_type llc_tr_packet_type __read_mostly = { | |||
144 | 144 | ||
145 | static int __init llc_init(void) | 145 | static int __init llc_init(void) |
146 | { | 146 | { |
147 | struct net_device *dev; | ||
148 | |||
149 | dev = first_net_device(&init_net); | ||
150 | if (dev != NULL) | ||
151 | dev = next_net_device(dev); | ||
152 | |||
153 | dev_add_pack(&llc_packet_type); | 147 | dev_add_pack(&llc_packet_type); |
154 | dev_add_pack(&llc_tr_packet_type); | 148 | dev_add_pack(&llc_tr_packet_type); |
155 | return 0; | 149 | return 0; |
diff --git a/net/llc/llc_if.c b/net/llc/llc_if.c index a89917130a7b..25c31c0a3fdb 100644 --- a/net/llc/llc_if.c +++ b/net/llc/llc_if.c | |||
@@ -11,6 +11,7 @@ | |||
11 | * | 11 | * |
12 | * See the GNU General Public License for more details. | 12 | * See the GNU General Public License for more details. |
13 | */ | 13 | */ |
14 | #include <linux/gfp.h> | ||
14 | #include <linux/module.h> | 15 | #include <linux/module.h> |
15 | #include <linux/kernel.h> | 16 | #include <linux/kernel.h> |
16 | #include <linux/netdevice.h> | 17 | #include <linux/netdevice.h> |
diff --git a/net/llc/llc_input.c b/net/llc/llc_input.c index 57ad974e4d94..f99687439139 100644 --- a/net/llc/llc_input.c +++ b/net/llc/llc_input.c | |||
@@ -12,6 +12,7 @@ | |||
12 | * See the GNU General Public License for more details. | 12 | * See the GNU General Public License for more details. |
13 | */ | 13 | */ |
14 | #include <linux/netdevice.h> | 14 | #include <linux/netdevice.h> |
15 | #include <linux/slab.h> | ||
15 | #include <net/net_namespace.h> | 16 | #include <net/net_namespace.h> |
16 | #include <net/llc.h> | 17 | #include <net/llc.h> |
17 | #include <net/llc_pdu.h> | 18 | #include <net/llc_pdu.h> |
diff --git a/net/llc/llc_sap.c b/net/llc/llc_sap.c index ad6e6e1cf22f..a432f0ec051c 100644 --- a/net/llc/llc_sap.c +++ b/net/llc/llc_sap.c | |||
@@ -23,6 +23,7 @@ | |||
23 | #include <net/sock.h> | 23 | #include <net/sock.h> |
24 | #include <net/tcp_states.h> | 24 | #include <net/tcp_states.h> |
25 | #include <linux/llc.h> | 25 | #include <linux/llc.h> |
26 | #include <linux/slab.h> | ||
26 | 27 | ||
27 | static int llc_mac_header_len(unsigned short devtype) | 28 | static int llc_mac_header_len(unsigned short devtype) |
28 | { | 29 | { |
diff --git a/net/llc/llc_station.c b/net/llc/llc_station.c index 83da13339490..e4dae0244d76 100644 --- a/net/llc/llc_station.c +++ b/net/llc/llc_station.c | |||
@@ -13,6 +13,7 @@ | |||
13 | */ | 13 | */ |
14 | #include <linux/init.h> | 14 | #include <linux/init.h> |
15 | #include <linux/module.h> | 15 | #include <linux/module.h> |
16 | #include <linux/slab.h> | ||
16 | #include <net/llc.h> | 17 | #include <net/llc.h> |
17 | #include <net/llc_sap.h> | 18 | #include <net/llc_sap.h> |
18 | #include <net/llc_conn.h> | 19 | #include <net/llc_conn.h> |
diff --git a/net/mac80211/agg-rx.c b/net/mac80211/agg-rx.c index 53233ab50f65..9598fdb4ad01 100644 --- a/net/mac80211/agg-rx.c +++ b/net/mac80211/agg-rx.c | |||
@@ -14,6 +14,7 @@ | |||
14 | */ | 14 | */ |
15 | 15 | ||
16 | #include <linux/ieee80211.h> | 16 | #include <linux/ieee80211.h> |
17 | #include <linux/slab.h> | ||
17 | #include <net/mac80211.h> | 18 | #include <net/mac80211.h> |
18 | #include "ieee80211_i.h" | 19 | #include "ieee80211_i.h" |
19 | #include "driver-ops.h" | 20 | #include "driver-ops.h" |
diff --git a/net/mac80211/agg-tx.c b/net/mac80211/agg-tx.c index 6bb4d0a1e5c5..608063f11797 100644 --- a/net/mac80211/agg-tx.c +++ b/net/mac80211/agg-tx.c | |||
@@ -14,6 +14,7 @@ | |||
14 | */ | 14 | */ |
15 | 15 | ||
16 | #include <linux/ieee80211.h> | 16 | #include <linux/ieee80211.h> |
17 | #include <linux/slab.h> | ||
17 | #include <net/mac80211.h> | 18 | #include <net/mac80211.h> |
18 | #include "ieee80211_i.h" | 19 | #include "ieee80211_i.h" |
19 | #include "driver-ops.h" | 20 | #include "driver-ops.h" |
diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c index 4edd73cbf052..7dd7cda75cfa 100644 --- a/net/mac80211/cfg.c +++ b/net/mac80211/cfg.c | |||
@@ -9,6 +9,7 @@ | |||
9 | #include <linux/ieee80211.h> | 9 | #include <linux/ieee80211.h> |
10 | #include <linux/nl80211.h> | 10 | #include <linux/nl80211.h> |
11 | #include <linux/rtnetlink.h> | 11 | #include <linux/rtnetlink.h> |
12 | #include <linux/slab.h> | ||
12 | #include <net/net_namespace.h> | 13 | #include <net/net_namespace.h> |
13 | #include <linux/rcupdate.h> | 14 | #include <linux/rcupdate.h> |
14 | #include <net/cfg80211.h> | 15 | #include <net/cfg80211.h> |
diff --git a/net/mac80211/debugfs_key.c b/net/mac80211/debugfs_key.c index d12e743cb4e1..97c9e46e859e 100644 --- a/net/mac80211/debugfs_key.c +++ b/net/mac80211/debugfs_key.c | |||
@@ -9,6 +9,7 @@ | |||
9 | */ | 9 | */ |
10 | 10 | ||
11 | #include <linux/kobject.h> | 11 | #include <linux/kobject.h> |
12 | #include <linux/slab.h> | ||
12 | #include "ieee80211_i.h" | 13 | #include "ieee80211_i.h" |
13 | #include "key.h" | 14 | #include "key.h" |
14 | #include "debugfs.h" | 15 | #include "debugfs.h" |
diff --git a/net/mac80211/debugfs_netdev.c b/net/mac80211/debugfs_netdev.c index 623e6644b80c..20b2998fa0ed 100644 --- a/net/mac80211/debugfs_netdev.c +++ b/net/mac80211/debugfs_netdev.c | |||
@@ -13,6 +13,7 @@ | |||
13 | #include <linux/interrupt.h> | 13 | #include <linux/interrupt.h> |
14 | #include <linux/netdevice.h> | 14 | #include <linux/netdevice.h> |
15 | #include <linux/rtnetlink.h> | 15 | #include <linux/rtnetlink.h> |
16 | #include <linux/slab.h> | ||
16 | #include <linux/notifier.h> | 17 | #include <linux/notifier.h> |
17 | #include <net/mac80211.h> | 18 | #include <net/mac80211.h> |
18 | #include <net/cfg80211.h> | 19 | #include <net/cfg80211.h> |
diff --git a/net/mac80211/driver-ops.h b/net/mac80211/driver-ops.h index c3d844093a2f..9179196da264 100644 --- a/net/mac80211/driver-ops.h +++ b/net/mac80211/driver-ops.h | |||
@@ -84,16 +84,14 @@ static inline void drv_bss_info_changed(struct ieee80211_local *local, | |||
84 | } | 84 | } |
85 | 85 | ||
86 | static inline u64 drv_prepare_multicast(struct ieee80211_local *local, | 86 | static inline u64 drv_prepare_multicast(struct ieee80211_local *local, |
87 | int mc_count, | 87 | struct netdev_hw_addr_list *mc_list) |
88 | struct dev_addr_list *mc_list) | ||
89 | { | 88 | { |
90 | u64 ret = 0; | 89 | u64 ret = 0; |
91 | 90 | ||
92 | if (local->ops->prepare_multicast) | 91 | if (local->ops->prepare_multicast) |
93 | ret = local->ops->prepare_multicast(&local->hw, mc_count, | 92 | ret = local->ops->prepare_multicast(&local->hw, mc_list); |
94 | mc_list); | ||
95 | 93 | ||
96 | trace_drv_prepare_multicast(local, mc_count, ret); | 94 | trace_drv_prepare_multicast(local, mc_list->count, ret); |
97 | 95 | ||
98 | return ret; | 96 | return ret; |
99 | } | 97 | } |
diff --git a/net/mac80211/ibss.c b/net/mac80211/ibss.c index 01974c2510a8..e6f3b0c7a71f 100644 --- a/net/mac80211/ibss.c +++ b/net/mac80211/ibss.c | |||
@@ -13,6 +13,7 @@ | |||
13 | */ | 13 | */ |
14 | 14 | ||
15 | #include <linux/delay.h> | 15 | #include <linux/delay.h> |
16 | #include <linux/slab.h> | ||
16 | #include <linux/if_ether.h> | 17 | #include <linux/if_ether.h> |
17 | #include <linux/skbuff.h> | 18 | #include <linux/skbuff.h> |
18 | #include <linux/if_arp.h> | 19 | #include <linux/if_arp.h> |
diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h index 4e73660ebe99..c9712f35e596 100644 --- a/net/mac80211/ieee80211_i.h +++ b/net/mac80211/ieee80211_i.h | |||
@@ -665,8 +665,7 @@ struct ieee80211_local { | |||
665 | struct work_struct recalc_smps; | 665 | struct work_struct recalc_smps; |
666 | 666 | ||
667 | /* aggregated multicast list */ | 667 | /* aggregated multicast list */ |
668 | struct dev_addr_list *mc_list; | 668 | struct netdev_hw_addr_list mc_list; |
669 | int mc_count; | ||
670 | 669 | ||
671 | bool tim_in_locked_section; /* see ieee80211_beacon_get() */ | 670 | bool tim_in_locked_section; /* see ieee80211_beacon_get() */ |
672 | 671 | ||
diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c index b4ec59a8dc03..50deb017fd6e 100644 --- a/net/mac80211/iface.c +++ b/net/mac80211/iface.c | |||
@@ -10,6 +10,7 @@ | |||
10 | * it under the terms of the GNU General Public License version 2 as | 10 | * it under the terms of the GNU General Public License version 2 as |
11 | * published by the Free Software Foundation. | 11 | * published by the Free Software Foundation. |
12 | */ | 12 | */ |
13 | #include <linux/slab.h> | ||
13 | #include <linux/kernel.h> | 14 | #include <linux/kernel.h> |
14 | #include <linux/if_arp.h> | 15 | #include <linux/if_arp.h> |
15 | #include <linux/netdevice.h> | 16 | #include <linux/netdevice.h> |
@@ -412,8 +413,7 @@ static int ieee80211_stop(struct net_device *dev) | |||
412 | 413 | ||
413 | netif_addr_lock_bh(dev); | 414 | netif_addr_lock_bh(dev); |
414 | spin_lock_bh(&local->filter_lock); | 415 | spin_lock_bh(&local->filter_lock); |
415 | __dev_addr_unsync(&local->mc_list, &local->mc_count, | 416 | __hw_addr_unsync(&local->mc_list, &dev->mc, dev->addr_len); |
416 | &dev->mc_list, &dev->mc_count); | ||
417 | spin_unlock_bh(&local->filter_lock); | 417 | spin_unlock_bh(&local->filter_lock); |
418 | netif_addr_unlock_bh(dev); | 418 | netif_addr_unlock_bh(dev); |
419 | 419 | ||
@@ -596,8 +596,7 @@ static void ieee80211_set_multicast_list(struct net_device *dev) | |||
596 | sdata->flags ^= IEEE80211_SDATA_PROMISC; | 596 | sdata->flags ^= IEEE80211_SDATA_PROMISC; |
597 | } | 597 | } |
598 | spin_lock_bh(&local->filter_lock); | 598 | spin_lock_bh(&local->filter_lock); |
599 | __dev_addr_sync(&local->mc_list, &local->mc_count, | 599 | __hw_addr_sync(&local->mc_list, &dev->mc, dev->addr_len); |
600 | &dev->mc_list, &dev->mc_count); | ||
601 | spin_unlock_bh(&local->filter_lock); | 600 | spin_unlock_bh(&local->filter_lock); |
602 | ieee80211_queue_work(&local->hw, &local->reconfig_filter); | 601 | ieee80211_queue_work(&local->hw, &local->reconfig_filter); |
603 | } | 602 | } |
diff --git a/net/mac80211/key.c b/net/mac80211/key.c index 8160d9c5372e..e8f6e3b252d8 100644 --- a/net/mac80211/key.c +++ b/net/mac80211/key.c | |||
@@ -14,6 +14,7 @@ | |||
14 | #include <linux/list.h> | 14 | #include <linux/list.h> |
15 | #include <linux/rcupdate.h> | 15 | #include <linux/rcupdate.h> |
16 | #include <linux/rtnetlink.h> | 16 | #include <linux/rtnetlink.h> |
17 | #include <linux/slab.h> | ||
17 | #include <net/mac80211.h> | 18 | #include <net/mac80211.h> |
18 | #include "ieee80211_i.h" | 19 | #include "ieee80211_i.h" |
19 | #include "driver-ops.h" | 20 | #include "driver-ops.h" |
diff --git a/net/mac80211/led.c b/net/mac80211/led.c index 162a643f16b6..063aad944246 100644 --- a/net/mac80211/led.c +++ b/net/mac80211/led.c | |||
@@ -8,6 +8,7 @@ | |||
8 | 8 | ||
9 | /* just for IFNAMSIZ */ | 9 | /* just for IFNAMSIZ */ |
10 | #include <linux/if.h> | 10 | #include <linux/if.h> |
11 | #include <linux/slab.h> | ||
11 | #include "led.h" | 12 | #include "led.h" |
12 | 13 | ||
13 | void ieee80211_led_rx(struct ieee80211_local *local) | 14 | void ieee80211_led_rx(struct ieee80211_local *local) |
diff --git a/net/mac80211/main.c b/net/mac80211/main.c index 4afe851cf8dc..011ee85bcd57 100644 --- a/net/mac80211/main.c +++ b/net/mac80211/main.c | |||
@@ -71,7 +71,7 @@ void ieee80211_configure_filter(struct ieee80211_local *local) | |||
71 | spin_lock_bh(&local->filter_lock); | 71 | spin_lock_bh(&local->filter_lock); |
72 | changed_flags = local->filter_flags ^ new_flags; | 72 | changed_flags = local->filter_flags ^ new_flags; |
73 | 73 | ||
74 | mc = drv_prepare_multicast(local, local->mc_count, local->mc_list); | 74 | mc = drv_prepare_multicast(local, &local->mc_list); |
75 | spin_unlock_bh(&local->filter_lock); | 75 | spin_unlock_bh(&local->filter_lock); |
76 | 76 | ||
77 | /* be a bit nasty */ | 77 | /* be a bit nasty */ |
@@ -390,6 +390,9 @@ struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len, | |||
390 | local->uapsd_max_sp_len = IEEE80211_DEFAULT_MAX_SP_LEN; | 390 | local->uapsd_max_sp_len = IEEE80211_DEFAULT_MAX_SP_LEN; |
391 | 391 | ||
392 | INIT_LIST_HEAD(&local->interfaces); | 392 | INIT_LIST_HEAD(&local->interfaces); |
393 | |||
394 | __hw_addr_init(&local->mc_list); | ||
395 | |||
393 | mutex_init(&local->iflist_mtx); | 396 | mutex_init(&local->iflist_mtx); |
394 | mutex_init(&local->scan_mtx); | 397 | mutex_init(&local->scan_mtx); |
395 | 398 | ||
diff --git a/net/mac80211/mesh.c b/net/mac80211/mesh.c index 2669fbf8c812..7e93524459fc 100644 --- a/net/mac80211/mesh.c +++ b/net/mac80211/mesh.c | |||
@@ -8,6 +8,7 @@ | |||
8 | * published by the Free Software Foundation. | 8 | * published by the Free Software Foundation. |
9 | */ | 9 | */ |
10 | 10 | ||
11 | #include <linux/slab.h> | ||
11 | #include <asm/unaligned.h> | 12 | #include <asm/unaligned.h> |
12 | #include "ieee80211_i.h" | 13 | #include "ieee80211_i.h" |
13 | #include "mesh.h" | 14 | #include "mesh.h" |
diff --git a/net/mac80211/mesh_hwmp.c b/net/mac80211/mesh_hwmp.c index 36141d6e701b..d89ed7f2592b 100644 --- a/net/mac80211/mesh_hwmp.c +++ b/net/mac80211/mesh_hwmp.c | |||
@@ -7,6 +7,7 @@ | |||
7 | * published by the Free Software Foundation. | 7 | * published by the Free Software Foundation. |
8 | */ | 8 | */ |
9 | 9 | ||
10 | #include <linux/slab.h> | ||
10 | #include "mesh.h" | 11 | #include "mesh.h" |
11 | 12 | ||
12 | #ifdef CONFIG_MAC80211_VERBOSE_MHWMP_DEBUG | 13 | #ifdef CONFIG_MAC80211_VERBOSE_MHWMP_DEBUG |
diff --git a/net/mac80211/mesh_pathtbl.c b/net/mac80211/mesh_pathtbl.c index 2312efe04c62..181ffd6efd81 100644 --- a/net/mac80211/mesh_pathtbl.c +++ b/net/mac80211/mesh_pathtbl.c | |||
@@ -10,6 +10,7 @@ | |||
10 | #include <linux/etherdevice.h> | 10 | #include <linux/etherdevice.h> |
11 | #include <linux/list.h> | 11 | #include <linux/list.h> |
12 | #include <linux/random.h> | 12 | #include <linux/random.h> |
13 | #include <linux/slab.h> | ||
13 | #include <linux/spinlock.h> | 14 | #include <linux/spinlock.h> |
14 | #include <linux/string.h> | 15 | #include <linux/string.h> |
15 | #include <net/mac80211.h> | 16 | #include <net/mac80211.h> |
diff --git a/net/mac80211/mesh_plink.c b/net/mac80211/mesh_plink.c index c384154ac895..3cd5f7b5d693 100644 --- a/net/mac80211/mesh_plink.c +++ b/net/mac80211/mesh_plink.c | |||
@@ -6,6 +6,7 @@ | |||
6 | * it under the terms of the GNU General Public License version 2 as | 6 | * it under the terms of the GNU General Public License version 2 as |
7 | * published by the Free Software Foundation. | 7 | * published by the Free Software Foundation. |
8 | */ | 8 | */ |
9 | #include <linux/gfp.h> | ||
9 | #include <linux/kernel.h> | 10 | #include <linux/kernel.h> |
10 | #include <linux/random.h> | 11 | #include <linux/random.h> |
11 | #include "ieee80211_i.h" | 12 | #include "ieee80211_i.h" |
@@ -744,7 +745,7 @@ void mesh_rx_plink_frame(struct ieee80211_sub_if_data *sdata, struct ieee80211_m | |||
744 | break; | 745 | break; |
745 | default: | 746 | default: |
746 | /* should not get here, PLINK_BLOCKED is dealt with at the | 747 | /* should not get here, PLINK_BLOCKED is dealt with at the |
747 | * beggining of the function | 748 | * beginning of the function |
748 | */ | 749 | */ |
749 | spin_unlock_bh(&sta->lock); | 750 | spin_unlock_bh(&sta->lock); |
750 | break; | 751 | break; |
diff --git a/net/mac80211/mlme.c b/net/mac80211/mlme.c index d11a54c289a2..35d850223a75 100644 --- a/net/mac80211/mlme.c +++ b/net/mac80211/mlme.c | |||
@@ -19,6 +19,7 @@ | |||
19 | #include <linux/rtnetlink.h> | 19 | #include <linux/rtnetlink.h> |
20 | #include <linux/pm_qos_params.h> | 20 | #include <linux/pm_qos_params.h> |
21 | #include <linux/crc32.h> | 21 | #include <linux/crc32.h> |
22 | #include <linux/slab.h> | ||
22 | #include <net/mac80211.h> | 23 | #include <net/mac80211.h> |
23 | #include <asm/unaligned.h> | 24 | #include <asm/unaligned.h> |
24 | 25 | ||
diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c index 0b299d236fa1..6d0bd198af19 100644 --- a/net/mac80211/rate.c +++ b/net/mac80211/rate.c | |||
@@ -10,6 +10,7 @@ | |||
10 | 10 | ||
11 | #include <linux/kernel.h> | 11 | #include <linux/kernel.h> |
12 | #include <linux/rtnetlink.h> | 12 | #include <linux/rtnetlink.h> |
13 | #include <linux/slab.h> | ||
13 | #include "rate.h" | 14 | #include "rate.h" |
14 | #include "ieee80211_i.h" | 15 | #include "ieee80211_i.h" |
15 | #include "debugfs.h" | 16 | #include "debugfs.h" |
diff --git a/net/mac80211/rc80211_minstrel.c b/net/mac80211/rc80211_minstrel.c index 4926d929fd9f..f65ce6dcc8e2 100644 --- a/net/mac80211/rc80211_minstrel.c +++ b/net/mac80211/rc80211_minstrel.c | |||
@@ -50,6 +50,7 @@ | |||
50 | #include <linux/debugfs.h> | 50 | #include <linux/debugfs.h> |
51 | #include <linux/random.h> | 51 | #include <linux/random.h> |
52 | #include <linux/ieee80211.h> | 52 | #include <linux/ieee80211.h> |
53 | #include <linux/slab.h> | ||
53 | #include <net/mac80211.h> | 54 | #include <net/mac80211.h> |
54 | #include "rate.h" | 55 | #include "rate.h" |
55 | #include "rc80211_minstrel.h" | 56 | #include "rc80211_minstrel.h" |
diff --git a/net/mac80211/rc80211_minstrel_debugfs.c b/net/mac80211/rc80211_minstrel_debugfs.c index 56d0f24957d9..241e76f3fdf2 100644 --- a/net/mac80211/rc80211_minstrel_debugfs.c +++ b/net/mac80211/rc80211_minstrel_debugfs.c | |||
@@ -49,6 +49,7 @@ | |||
49 | #include <linux/skbuff.h> | 49 | #include <linux/skbuff.h> |
50 | #include <linux/debugfs.h> | 50 | #include <linux/debugfs.h> |
51 | #include <linux/ieee80211.h> | 51 | #include <linux/ieee80211.h> |
52 | #include <linux/slab.h> | ||
52 | #include <net/mac80211.h> | 53 | #include <net/mac80211.h> |
53 | #include "rc80211_minstrel.h" | 54 | #include "rc80211_minstrel.h" |
54 | 55 | ||
diff --git a/net/mac80211/rc80211_pid_algo.c b/net/mac80211/rc80211_pid_algo.c index 2652a374974e..aeda65466f3e 100644 --- a/net/mac80211/rc80211_pid_algo.c +++ b/net/mac80211/rc80211_pid_algo.c | |||
@@ -13,6 +13,7 @@ | |||
13 | #include <linux/types.h> | 13 | #include <linux/types.h> |
14 | #include <linux/skbuff.h> | 14 | #include <linux/skbuff.h> |
15 | #include <linux/debugfs.h> | 15 | #include <linux/debugfs.h> |
16 | #include <linux/slab.h> | ||
16 | #include <net/mac80211.h> | 17 | #include <net/mac80211.h> |
17 | #include "rate.h" | 18 | #include "rate.h" |
18 | #include "mesh.h" | 19 | #include "mesh.h" |
diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c index 45667054a5f3..47438b4a9af5 100644 --- a/net/mac80211/rc80211_pid_debugfs.c +++ b/net/mac80211/rc80211_pid_debugfs.c | |||
@@ -12,6 +12,7 @@ | |||
12 | #include <linux/netdevice.h> | 12 | #include <linux/netdevice.h> |
13 | #include <linux/types.h> | 13 | #include <linux/types.h> |
14 | #include <linux/skbuff.h> | 14 | #include <linux/skbuff.h> |
15 | #include <linux/slab.h> | ||
15 | 16 | ||
16 | #include <net/mac80211.h> | 17 | #include <net/mac80211.h> |
17 | #include "rate.h" | 18 | #include "rate.h" |
diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c index 8ee7db193269..72efbd87c1eb 100644 --- a/net/mac80211/rx.c +++ b/net/mac80211/rx.c | |||
@@ -10,6 +10,7 @@ | |||
10 | */ | 10 | */ |
11 | 11 | ||
12 | #include <linux/jiffies.h> | 12 | #include <linux/jiffies.h> |
13 | #include <linux/slab.h> | ||
13 | #include <linux/kernel.h> | 14 | #include <linux/kernel.h> |
14 | #include <linux/skbuff.h> | 15 | #include <linux/skbuff.h> |
15 | #include <linux/netdevice.h> | 16 | #include <linux/netdevice.h> |
diff --git a/net/mac80211/scan.c b/net/mac80211/scan.c index eb86a5f6e645..e1a3defdf581 100644 --- a/net/mac80211/scan.c +++ b/net/mac80211/scan.c | |||
@@ -16,6 +16,7 @@ | |||
16 | #include <linux/rtnetlink.h> | 16 | #include <linux/rtnetlink.h> |
17 | #include <linux/pm_qos_params.h> | 17 | #include <linux/pm_qos_params.h> |
18 | #include <net/sch_generic.h> | 18 | #include <net/sch_generic.h> |
19 | #include <linux/slab.h> | ||
19 | #include <net/mac80211.h> | 20 | #include <net/mac80211.h> |
20 | 21 | ||
21 | #include "ieee80211_i.h" | 22 | #include "ieee80211_i.h" |
diff --git a/net/mac80211/wep.c b/net/mac80211/wep.c index 5d745f2d7236..5f3a4113bda1 100644 --- a/net/mac80211/wep.c +++ b/net/mac80211/wep.c | |||
@@ -17,6 +17,7 @@ | |||
17 | #include <linux/err.h> | 17 | #include <linux/err.h> |
18 | #include <linux/mm.h> | 18 | #include <linux/mm.h> |
19 | #include <linux/scatterlist.h> | 19 | #include <linux/scatterlist.h> |
20 | #include <linux/slab.h> | ||
20 | #include <asm/unaligned.h> | 21 | #include <asm/unaligned.h> |
21 | 22 | ||
22 | #include <net/mac80211.h> | 23 | #include <net/mac80211.h> |
diff --git a/net/mac80211/work.c b/net/mac80211/work.c index 7bd8670379de..bdb1d05b16fc 100644 --- a/net/mac80211/work.c +++ b/net/mac80211/work.c | |||
@@ -19,6 +19,7 @@ | |||
19 | #include <linux/if_arp.h> | 19 | #include <linux/if_arp.h> |
20 | #include <linux/etherdevice.h> | 20 | #include <linux/etherdevice.h> |
21 | #include <linux/crc32.h> | 21 | #include <linux/crc32.h> |
22 | #include <linux/slab.h> | ||
22 | #include <net/mac80211.h> | 23 | #include <net/mac80211.h> |
23 | #include <asm/unaligned.h> | 24 | #include <asm/unaligned.h> |
24 | 25 | ||
diff --git a/net/mac80211/wpa.c b/net/mac80211/wpa.c index f4971cd45c64..0adbcc941ac9 100644 --- a/net/mac80211/wpa.c +++ b/net/mac80211/wpa.c | |||
@@ -9,10 +9,10 @@ | |||
9 | 9 | ||
10 | #include <linux/netdevice.h> | 10 | #include <linux/netdevice.h> |
11 | #include <linux/types.h> | 11 | #include <linux/types.h> |
12 | #include <linux/slab.h> | ||
13 | #include <linux/skbuff.h> | 12 | #include <linux/skbuff.h> |
14 | #include <linux/compiler.h> | 13 | #include <linux/compiler.h> |
15 | #include <linux/ieee80211.h> | 14 | #include <linux/ieee80211.h> |
15 | #include <linux/gfp.h> | ||
16 | #include <asm/unaligned.h> | 16 | #include <asm/unaligned.h> |
17 | #include <net/mac80211.h> | 17 | #include <net/mac80211.h> |
18 | 18 | ||
diff --git a/net/netfilter/core.c b/net/netfilter/core.c index 60ec4e4badaa..78b505d33bfb 100644 --- a/net/netfilter/core.c +++ b/net/netfilter/core.c | |||
@@ -19,6 +19,7 @@ | |||
19 | #include <linux/inetdevice.h> | 19 | #include <linux/inetdevice.h> |
20 | #include <linux/proc_fs.h> | 20 | #include <linux/proc_fs.h> |
21 | #include <linux/mutex.h> | 21 | #include <linux/mutex.h> |
22 | #include <linux/slab.h> | ||
22 | #include <net/net_namespace.h> | 23 | #include <net/net_namespace.h> |
23 | #include <net/sock.h> | 24 | #include <net/sock.h> |
24 | 25 | ||
diff --git a/net/netfilter/ipvs/ip_vs_app.c b/net/netfilter/ipvs/ip_vs_app.c index 3c7e42735b60..1cb0e834f8ff 100644 --- a/net/netfilter/ipvs/ip_vs_app.c +++ b/net/netfilter/ipvs/ip_vs_app.c | |||
@@ -27,6 +27,7 @@ | |||
27 | #include <linux/in.h> | 27 | #include <linux/in.h> |
28 | #include <linux/ip.h> | 28 | #include <linux/ip.h> |
29 | #include <linux/netfilter.h> | 29 | #include <linux/netfilter.h> |
30 | #include <linux/slab.h> | ||
30 | #include <net/net_namespace.h> | 31 | #include <net/net_namespace.h> |
31 | #include <net/protocol.h> | 32 | #include <net/protocol.h> |
32 | #include <net/tcp.h> | 33 | #include <net/tcp.h> |
diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c index 60bb41a8d8d4..d8f7e8ef67b4 100644 --- a/net/netfilter/ipvs/ip_vs_conn.c +++ b/net/netfilter/ipvs/ip_vs_conn.c | |||
@@ -32,6 +32,7 @@ | |||
32 | #include <linux/module.h> | 32 | #include <linux/module.h> |
33 | #include <linux/vmalloc.h> | 33 | #include <linux/vmalloc.h> |
34 | #include <linux/proc_fs.h> /* for proc_net_* */ | 34 | #include <linux/proc_fs.h> /* for proc_net_* */ |
35 | #include <linux/slab.h> | ||
35 | #include <linux/seq_file.h> | 36 | #include <linux/seq_file.h> |
36 | #include <linux/jhash.h> | 37 | #include <linux/jhash.h> |
37 | #include <linux/random.h> | 38 | #include <linux/random.h> |
diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c index 44590887a92c..1cd6e3fd058b 100644 --- a/net/netfilter/ipvs/ip_vs_core.c +++ b/net/netfilter/ipvs/ip_vs_core.c | |||
@@ -33,6 +33,7 @@ | |||
33 | #include <linux/tcp.h> | 33 | #include <linux/tcp.h> |
34 | #include <linux/sctp.h> | 34 | #include <linux/sctp.h> |
35 | #include <linux/icmp.h> | 35 | #include <linux/icmp.h> |
36 | #include <linux/slab.h> | ||
36 | 37 | ||
37 | #include <net/ip.h> | 38 | #include <net/ip.h> |
38 | #include <net/tcp.h> | 39 | #include <net/tcp.h> |
diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c index 7ee9c3426f44..36dc1d88c2fa 100644 --- a/net/netfilter/ipvs/ip_vs_ctl.c +++ b/net/netfilter/ipvs/ip_vs_ctl.c | |||
@@ -31,6 +31,7 @@ | |||
31 | #include <linux/workqueue.h> | 31 | #include <linux/workqueue.h> |
32 | #include <linux/swap.h> | 32 | #include <linux/swap.h> |
33 | #include <linux/seq_file.h> | 33 | #include <linux/seq_file.h> |
34 | #include <linux/slab.h> | ||
34 | 35 | ||
35 | #include <linux/netfilter.h> | 36 | #include <linux/netfilter.h> |
36 | #include <linux/netfilter_ipv4.h> | 37 | #include <linux/netfilter_ipv4.h> |
diff --git a/net/netfilter/ipvs/ip_vs_dh.c b/net/netfilter/ipvs/ip_vs_dh.c index fe3e18834b91..95fd0d14200b 100644 --- a/net/netfilter/ipvs/ip_vs_dh.c +++ b/net/netfilter/ipvs/ip_vs_dh.c | |||
@@ -39,6 +39,7 @@ | |||
39 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt | 39 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt |
40 | 40 | ||
41 | #include <linux/ip.h> | 41 | #include <linux/ip.h> |
42 | #include <linux/slab.h> | ||
42 | #include <linux/module.h> | 43 | #include <linux/module.h> |
43 | #include <linux/kernel.h> | 44 | #include <linux/kernel.h> |
44 | #include <linux/skbuff.h> | 45 | #include <linux/skbuff.h> |
diff --git a/net/netfilter/ipvs/ip_vs_est.c b/net/netfilter/ipvs/ip_vs_est.c index 702b53ca937c..ff28801962e0 100644 --- a/net/netfilter/ipvs/ip_vs_est.c +++ b/net/netfilter/ipvs/ip_vs_est.c | |||
@@ -17,7 +17,6 @@ | |||
17 | 17 | ||
18 | #include <linux/kernel.h> | 18 | #include <linux/kernel.h> |
19 | #include <linux/jiffies.h> | 19 | #include <linux/jiffies.h> |
20 | #include <linux/slab.h> | ||
21 | #include <linux/types.h> | 20 | #include <linux/types.h> |
22 | #include <linux/interrupt.h> | 21 | #include <linux/interrupt.h> |
23 | #include <linux/sysctl.h> | 22 | #include <linux/sysctl.h> |
diff --git a/net/netfilter/ipvs/ip_vs_ftp.c b/net/netfilter/ipvs/ip_vs_ftp.c index 73f38ea98f25..2c7f185dfae4 100644 --- a/net/netfilter/ipvs/ip_vs_ftp.c +++ b/net/netfilter/ipvs/ip_vs_ftp.c | |||
@@ -32,6 +32,7 @@ | |||
32 | #include <linux/in.h> | 32 | #include <linux/in.h> |
33 | #include <linux/ip.h> | 33 | #include <linux/ip.h> |
34 | #include <linux/netfilter.h> | 34 | #include <linux/netfilter.h> |
35 | #include <linux/gfp.h> | ||
35 | #include <net/protocol.h> | 36 | #include <net/protocol.h> |
36 | #include <net/tcp.h> | 37 | #include <net/tcp.h> |
37 | #include <asm/unaligned.h> | 38 | #include <asm/unaligned.h> |
diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c index 1b9370db2305..94a45213faa6 100644 --- a/net/netfilter/ipvs/ip_vs_lblc.c +++ b/net/netfilter/ipvs/ip_vs_lblc.c | |||
@@ -43,6 +43,7 @@ | |||
43 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt | 43 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt |
44 | 44 | ||
45 | #include <linux/ip.h> | 45 | #include <linux/ip.h> |
46 | #include <linux/slab.h> | ||
46 | #include <linux/module.h> | 47 | #include <linux/module.h> |
47 | #include <linux/kernel.h> | 48 | #include <linux/kernel.h> |
48 | #include <linux/skbuff.h> | 49 | #include <linux/skbuff.h> |
diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c index caa58fa1438a..535dc2b419d8 100644 --- a/net/netfilter/ipvs/ip_vs_lblcr.c +++ b/net/netfilter/ipvs/ip_vs_lblcr.c | |||
@@ -46,6 +46,7 @@ | |||
46 | #include <linux/skbuff.h> | 46 | #include <linux/skbuff.h> |
47 | #include <linux/jiffies.h> | 47 | #include <linux/jiffies.h> |
48 | #include <linux/list.h> | 48 | #include <linux/list.h> |
49 | #include <linux/slab.h> | ||
49 | 50 | ||
50 | /* for sysctl */ | 51 | /* for sysctl */ |
51 | #include <linux/fs.h> | 52 | #include <linux/fs.h> |
diff --git a/net/netfilter/ipvs/ip_vs_proto.c b/net/netfilter/ipvs/ip_vs_proto.c index 0e584553819d..7fc49f4cf5ad 100644 --- a/net/netfilter/ipvs/ip_vs_proto.c +++ b/net/netfilter/ipvs/ip_vs_proto.c | |||
@@ -19,6 +19,7 @@ | |||
19 | #include <linux/module.h> | 19 | #include <linux/module.h> |
20 | #include <linux/kernel.h> | 20 | #include <linux/kernel.h> |
21 | #include <linux/skbuff.h> | 21 | #include <linux/skbuff.h> |
22 | #include <linux/gfp.h> | ||
22 | #include <linux/in.h> | 23 | #include <linux/in.h> |
23 | #include <linux/ip.h> | 24 | #include <linux/ip.h> |
24 | #include <net/protocol.h> | 25 | #include <net/protocol.h> |
diff --git a/net/netfilter/ipvs/ip_vs_sh.c b/net/netfilter/ipvs/ip_vs_sh.c index 8e6cfd36e6f0..e6cc174fbc06 100644 --- a/net/netfilter/ipvs/ip_vs_sh.c +++ b/net/netfilter/ipvs/ip_vs_sh.c | |||
@@ -36,6 +36,7 @@ | |||
36 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt | 36 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt |
37 | 37 | ||
38 | #include <linux/ip.h> | 38 | #include <linux/ip.h> |
39 | #include <linux/slab.h> | ||
39 | #include <linux/module.h> | 40 | #include <linux/module.h> |
40 | #include <linux/kernel.h> | 41 | #include <linux/kernel.h> |
41 | #include <linux/skbuff.h> | 42 | #include <linux/skbuff.h> |
diff --git a/net/netfilter/ipvs/ip_vs_wrr.c b/net/netfilter/ipvs/ip_vs_wrr.c index 3c115fc19784..30db633f88f1 100644 --- a/net/netfilter/ipvs/ip_vs_wrr.c +++ b/net/netfilter/ipvs/ip_vs_wrr.c | |||
@@ -23,6 +23,7 @@ | |||
23 | 23 | ||
24 | #include <linux/module.h> | 24 | #include <linux/module.h> |
25 | #include <linux/kernel.h> | 25 | #include <linux/kernel.h> |
26 | #include <linux/slab.h> | ||
26 | #include <linux/net.h> | 27 | #include <linux/net.h> |
27 | #include <linux/gcd.h> | 28 | #include <linux/gcd.h> |
28 | 29 | ||
diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c index 223b5018c7dc..e450cd6f4eb5 100644 --- a/net/netfilter/ipvs/ip_vs_xmit.c +++ b/net/netfilter/ipvs/ip_vs_xmit.c | |||
@@ -17,6 +17,7 @@ | |||
17 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt | 17 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt |
18 | 18 | ||
19 | #include <linux/kernel.h> | 19 | #include <linux/kernel.h> |
20 | #include <linux/slab.h> | ||
20 | #include <linux/tcp.h> /* for tcphdr */ | 21 | #include <linux/tcp.h> /* for tcphdr */ |
21 | #include <net/ip.h> | 22 | #include <net/ip.h> |
22 | #include <net/tcp.h> /* for csum_tcpudp_magic */ | 23 | #include <net/tcp.h> /* for csum_tcpudp_magic */ |
diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c index 018f90db511c..ab81b380eae6 100644 --- a/net/netfilter/nf_conntrack_acct.c +++ b/net/netfilter/nf_conntrack_acct.c | |||
@@ -9,6 +9,7 @@ | |||
9 | */ | 9 | */ |
10 | 10 | ||
11 | #include <linux/netfilter.h> | 11 | #include <linux/netfilter.h> |
12 | #include <linux/slab.h> | ||
12 | #include <linux/kernel.h> | 13 | #include <linux/kernel.h> |
13 | #include <linux/moduleparam.h> | 14 | #include <linux/moduleparam.h> |
14 | 15 | ||
diff --git a/net/netfilter/nf_conntrack_amanda.c b/net/netfilter/nf_conntrack_amanda.c index 07d9d8857e5d..372e80f07a81 100644 --- a/net/netfilter/nf_conntrack_amanda.c +++ b/net/netfilter/nf_conntrack_amanda.c | |||
@@ -16,6 +16,7 @@ | |||
16 | #include <linux/in.h> | 16 | #include <linux/in.h> |
17 | #include <linux/udp.h> | 17 | #include <linux/udp.h> |
18 | #include <linux/netfilter.h> | 18 | #include <linux/netfilter.h> |
19 | #include <linux/gfp.h> | ||
19 | 20 | ||
20 | #include <net/netfilter/nf_conntrack.h> | 21 | #include <net/netfilter/nf_conntrack.h> |
21 | #include <net/netfilter/nf_conntrack_expect.h> | 22 | #include <net/netfilter/nf_conntrack_expect.h> |
diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c index d5a9bcd7d61b..f516961a83b4 100644 --- a/net/netfilter/nf_conntrack_ecache.c +++ b/net/netfilter/nf_conntrack_ecache.c | |||
@@ -18,6 +18,7 @@ | |||
18 | #include <linux/percpu.h> | 18 | #include <linux/percpu.h> |
19 | #include <linux/kernel.h> | 19 | #include <linux/kernel.h> |
20 | #include <linux/netdevice.h> | 20 | #include <linux/netdevice.h> |
21 | #include <linux/slab.h> | ||
21 | 22 | ||
22 | #include <net/netfilter/nf_conntrack.h> | 23 | #include <net/netfilter/nf_conntrack.h> |
23 | #include <net/netfilter/nf_conntrack_core.h> | 24 | #include <net/netfilter/nf_conntrack_core.h> |
diff --git a/net/netfilter/nf_conntrack_ftp.c b/net/netfilter/nf_conntrack_ftp.c index f0732aa18e4f..2ae3169e7633 100644 --- a/net/netfilter/nf_conntrack_ftp.c +++ b/net/netfilter/nf_conntrack_ftp.c | |||
@@ -13,6 +13,7 @@ | |||
13 | #include <linux/moduleparam.h> | 13 | #include <linux/moduleparam.h> |
14 | #include <linux/netfilter.h> | 14 | #include <linux/netfilter.h> |
15 | #include <linux/ip.h> | 15 | #include <linux/ip.h> |
16 | #include <linux/slab.h> | ||
16 | #include <linux/ipv6.h> | 17 | #include <linux/ipv6.h> |
17 | #include <linux/ctype.h> | 18 | #include <linux/ctype.h> |
18 | #include <linux/inet.h> | 19 | #include <linux/inet.h> |
diff --git a/net/netfilter/nf_conntrack_h323_main.c b/net/netfilter/nf_conntrack_h323_main.c index a1c8dd917e12..a487c8038044 100644 --- a/net/netfilter/nf_conntrack_h323_main.c +++ b/net/netfilter/nf_conntrack_h323_main.c | |||
@@ -17,6 +17,7 @@ | |||
17 | #include <linux/inet.h> | 17 | #include <linux/inet.h> |
18 | #include <linux/in.h> | 18 | #include <linux/in.h> |
19 | #include <linux/ip.h> | 19 | #include <linux/ip.h> |
20 | #include <linux/slab.h> | ||
20 | #include <linux/udp.h> | 21 | #include <linux/udp.h> |
21 | #include <linux/tcp.h> | 22 | #include <linux/tcp.h> |
22 | #include <linux/skbuff.h> | 23 | #include <linux/skbuff.h> |
diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c index 4509fa6726f8..59e1a4cd4e8b 100644 --- a/net/netfilter/nf_conntrack_helper.c +++ b/net/netfilter/nf_conntrack_helper.c | |||
@@ -15,7 +15,6 @@ | |||
15 | #include <linux/skbuff.h> | 15 | #include <linux/skbuff.h> |
16 | #include <linux/vmalloc.h> | 16 | #include <linux/vmalloc.h> |
17 | #include <linux/stddef.h> | 17 | #include <linux/stddef.h> |
18 | #include <linux/slab.h> | ||
19 | #include <linux/random.h> | 18 | #include <linux/random.h> |
20 | #include <linux/err.h> | 19 | #include <linux/err.h> |
21 | #include <linux/kernel.h> | 20 | #include <linux/kernel.h> |
diff --git a/net/netfilter/nf_conntrack_irc.c b/net/netfilter/nf_conntrack_irc.c index 8bd98c84f77e..7673930ca342 100644 --- a/net/netfilter/nf_conntrack_irc.c +++ b/net/netfilter/nf_conntrack_irc.c | |||
@@ -15,6 +15,7 @@ | |||
15 | #include <linux/ip.h> | 15 | #include <linux/ip.h> |
16 | #include <linux/tcp.h> | 16 | #include <linux/tcp.h> |
17 | #include <linux/netfilter.h> | 17 | #include <linux/netfilter.h> |
18 | #include <linux/slab.h> | ||
18 | 19 | ||
19 | #include <net/netfilter/nf_conntrack.h> | 20 | #include <net/netfilter/nf_conntrack.h> |
20 | #include <net/netfilter/nf_conntrack_expect.h> | 21 | #include <net/netfilter/nf_conntrack_expect.h> |
diff --git a/net/netfilter/nf_conntrack_netlink.c b/net/netfilter/nf_conntrack_netlink.c index 2b2af631d2b8..afc52f2ee4ac 100644 --- a/net/netfilter/nf_conntrack_netlink.c +++ b/net/netfilter/nf_conntrack_netlink.c | |||
@@ -27,6 +27,7 @@ | |||
27 | #include <linux/netlink.h> | 27 | #include <linux/netlink.h> |
28 | #include <linux/spinlock.h> | 28 | #include <linux/spinlock.h> |
29 | #include <linux/interrupt.h> | 29 | #include <linux/interrupt.h> |
30 | #include <linux/slab.h> | ||
30 | 31 | ||
31 | #include <linux/netfilter.h> | 32 | #include <linux/netfilter.h> |
32 | #include <net/netlink.h> | 33 | #include <net/netlink.h> |
@@ -582,7 +583,9 @@ nla_put_failure: | |||
582 | nlmsg_failure: | 583 | nlmsg_failure: |
583 | kfree_skb(skb); | 584 | kfree_skb(skb); |
584 | errout: | 585 | errout: |
585 | nfnetlink_set_err(net, 0, group, -ENOBUFS); | 586 | if (nfnetlink_set_err(net, 0, group, -ENOBUFS) > 0) |
587 | return -ENOBUFS; | ||
588 | |||
586 | return 0; | 589 | return 0; |
587 | } | 590 | } |
588 | #endif /* CONFIG_NF_CONNTRACK_EVENTS */ | 591 | #endif /* CONFIG_NF_CONNTRACK_EVENTS */ |
diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c index 1a4568bf7ea5..a44fa75b5178 100644 --- a/net/netfilter/nf_conntrack_proto.c +++ b/net/netfilter/nf_conntrack_proto.c | |||
@@ -12,6 +12,7 @@ | |||
12 | #include <linux/types.h> | 12 | #include <linux/types.h> |
13 | #include <linux/netfilter.h> | 13 | #include <linux/netfilter.h> |
14 | #include <linux/module.h> | 14 | #include <linux/module.h> |
15 | #include <linux/slab.h> | ||
15 | #include <linux/mutex.h> | 16 | #include <linux/mutex.h> |
16 | #include <linux/skbuff.h> | 17 | #include <linux/skbuff.h> |
17 | #include <linux/vmalloc.h> | 18 | #include <linux/vmalloc.h> |
diff --git a/net/netfilter/nf_conntrack_proto_dccp.c b/net/netfilter/nf_conntrack_proto_dccp.c index 9a2815549375..5292560d6d4a 100644 --- a/net/netfilter/nf_conntrack_proto_dccp.c +++ b/net/netfilter/nf_conntrack_proto_dccp.c | |||
@@ -15,6 +15,7 @@ | |||
15 | #include <linux/spinlock.h> | 15 | #include <linux/spinlock.h> |
16 | #include <linux/skbuff.h> | 16 | #include <linux/skbuff.h> |
17 | #include <linux/dccp.h> | 17 | #include <linux/dccp.h> |
18 | #include <linux/slab.h> | ||
18 | 19 | ||
19 | #include <net/net_namespace.h> | 20 | #include <net/net_namespace.h> |
20 | #include <net/netns/generic.h> | 21 | #include <net/netns/generic.h> |
diff --git a/net/netfilter/nf_conntrack_proto_gre.c b/net/netfilter/nf_conntrack_proto_gre.c index d899b1a69940..cf616e55ca41 100644 --- a/net/netfilter/nf_conntrack_proto_gre.c +++ b/net/netfilter/nf_conntrack_proto_gre.c | |||
@@ -31,6 +31,7 @@ | |||
31 | #include <linux/in.h> | 31 | #include <linux/in.h> |
32 | #include <linux/netdevice.h> | 32 | #include <linux/netdevice.h> |
33 | #include <linux/skbuff.h> | 33 | #include <linux/skbuff.h> |
34 | #include <linux/slab.h> | ||
34 | #include <net/dst.h> | 35 | #include <net/dst.h> |
35 | #include <net/net_namespace.h> | 36 | #include <net/net_namespace.h> |
36 | #include <net/netns/generic.h> | 37 | #include <net/netns/generic.h> |
diff --git a/net/netfilter/nf_conntrack_sane.c b/net/netfilter/nf_conntrack_sane.c index dcfecbb81c46..d9e27734b2a2 100644 --- a/net/netfilter/nf_conntrack_sane.c +++ b/net/netfilter/nf_conntrack_sane.c | |||
@@ -20,6 +20,7 @@ | |||
20 | #include <linux/module.h> | 20 | #include <linux/module.h> |
21 | #include <linux/moduleparam.h> | 21 | #include <linux/moduleparam.h> |
22 | #include <linux/netfilter.h> | 22 | #include <linux/netfilter.h> |
23 | #include <linux/slab.h> | ||
23 | #include <linux/in.h> | 24 | #include <linux/in.h> |
24 | #include <linux/tcp.h> | 25 | #include <linux/tcp.h> |
25 | #include <net/netfilter/nf_conntrack.h> | 26 | #include <net/netfilter/nf_conntrack.h> |
diff --git a/net/netfilter/nf_conntrack_sip.c b/net/netfilter/nf_conntrack_sip.c index 8dd75d90efc0..c6cd1b84eddd 100644 --- a/net/netfilter/nf_conntrack_sip.c +++ b/net/netfilter/nf_conntrack_sip.c | |||
@@ -284,7 +284,7 @@ EXPORT_SYMBOL_GPL(ct_sip_parse_request); | |||
284 | * tabs, spaces and continuation lines, which are treated as a single whitespace | 284 | * tabs, spaces and continuation lines, which are treated as a single whitespace |
285 | * character. | 285 | * character. |
286 | * | 286 | * |
287 | * Some headers may appear multiple times. A comma seperated list of values is | 287 | * Some headers may appear multiple times. A comma separated list of values is |
288 | * equivalent to multiple headers. | 288 | * equivalent to multiple headers. |
289 | */ | 289 | */ |
290 | static const struct sip_header ct_sip_hdrs[] = { | 290 | static const struct sip_header ct_sip_hdrs[] = { |
@@ -421,7 +421,7 @@ int ct_sip_get_header(const struct nf_conn *ct, const char *dptr, | |||
421 | } | 421 | } |
422 | EXPORT_SYMBOL_GPL(ct_sip_get_header); | 422 | EXPORT_SYMBOL_GPL(ct_sip_get_header); |
423 | 423 | ||
424 | /* Get next header field in a list of comma seperated values */ | 424 | /* Get next header field in a list of comma separated values */ |
425 | static int ct_sip_next_header(const struct nf_conn *ct, const char *dptr, | 425 | static int ct_sip_next_header(const struct nf_conn *ct, const char *dptr, |
426 | unsigned int dataoff, unsigned int datalen, | 426 | unsigned int dataoff, unsigned int datalen, |
427 | enum sip_header_types type, | 427 | enum sip_header_types type, |
diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c index 24a42efe62ef..faa8eb3722b9 100644 --- a/net/netfilter/nf_conntrack_standalone.c +++ b/net/netfilter/nf_conntrack_standalone.c | |||
@@ -8,6 +8,7 @@ | |||
8 | 8 | ||
9 | #include <linux/types.h> | 9 | #include <linux/types.h> |
10 | #include <linux/netfilter.h> | 10 | #include <linux/netfilter.h> |
11 | #include <linux/slab.h> | ||
11 | #include <linux/module.h> | 12 | #include <linux/module.h> |
12 | #include <linux/skbuff.h> | 13 | #include <linux/skbuff.h> |
13 | #include <linux/proc_fs.h> | 14 | #include <linux/proc_fs.h> |
diff --git a/net/netfilter/nf_queue.c b/net/netfilter/nf_queue.c index ba095fd014e5..c49ef219899e 100644 --- a/net/netfilter/nf_queue.c +++ b/net/netfilter/nf_queue.c | |||
@@ -1,4 +1,5 @@ | |||
1 | #include <linux/kernel.h> | 1 | #include <linux/kernel.h> |
2 | #include <linux/slab.h> | ||
2 | #include <linux/init.h> | 3 | #include <linux/init.h> |
3 | #include <linux/module.h> | 4 | #include <linux/module.h> |
4 | #include <linux/proc_fs.h> | 5 | #include <linux/proc_fs.h> |
diff --git a/net/netfilter/nfnetlink.c b/net/netfilter/nfnetlink.c index 8eb0cc23ada3..6afa3d52ea5f 100644 --- a/net/netfilter/nfnetlink.c +++ b/net/netfilter/nfnetlink.c | |||
@@ -113,9 +113,9 @@ int nfnetlink_send(struct sk_buff *skb, struct net *net, u32 pid, | |||
113 | } | 113 | } |
114 | EXPORT_SYMBOL_GPL(nfnetlink_send); | 114 | EXPORT_SYMBOL_GPL(nfnetlink_send); |
115 | 115 | ||
116 | void nfnetlink_set_err(struct net *net, u32 pid, u32 group, int error) | 116 | int nfnetlink_set_err(struct net *net, u32 pid, u32 group, int error) |
117 | { | 117 | { |
118 | netlink_set_err(net->nfnl, pid, group, error); | 118 | return netlink_set_err(net->nfnl, pid, group, error); |
119 | } | 119 | } |
120 | EXPORT_SYMBOL_GPL(nfnetlink_set_err); | 120 | EXPORT_SYMBOL_GPL(nfnetlink_set_err); |
121 | 121 | ||
diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c index d9b8fb8ab340..203643fb2c52 100644 --- a/net/netfilter/nfnetlink_log.c +++ b/net/netfilter/nfnetlink_log.c | |||
@@ -28,6 +28,7 @@ | |||
28 | #include <linux/list.h> | 28 | #include <linux/list.h> |
29 | #include <linux/jhash.h> | 29 | #include <linux/jhash.h> |
30 | #include <linux/random.h> | 30 | #include <linux/random.h> |
31 | #include <linux/slab.h> | ||
31 | #include <net/sock.h> | 32 | #include <net/sock.h> |
32 | #include <net/netfilter/nf_log.h> | 33 | #include <net/netfilter/nf_log.h> |
33 | #include <net/netfilter/nfnetlink_log.h> | 34 | #include <net/netfilter/nfnetlink_log.h> |
diff --git a/net/netfilter/nfnetlink_queue.c b/net/netfilter/nfnetlink_queue.c index 7ba4abc405c9..e70a6ef1f4f2 100644 --- a/net/netfilter/nfnetlink_queue.c +++ b/net/netfilter/nfnetlink_queue.c | |||
@@ -18,6 +18,7 @@ | |||
18 | #include <linux/skbuff.h> | 18 | #include <linux/skbuff.h> |
19 | #include <linux/init.h> | 19 | #include <linux/init.h> |
20 | #include <linux/spinlock.h> | 20 | #include <linux/spinlock.h> |
21 | #include <linux/slab.h> | ||
21 | #include <linux/notifier.h> | 22 | #include <linux/notifier.h> |
22 | #include <linux/netdevice.h> | 23 | #include <linux/netdevice.h> |
23 | #include <linux/netfilter.h> | 24 | #include <linux/netfilter.h> |
diff --git a/net/netfilter/x_tables.c b/net/netfilter/x_tables.c index 0a12cedfe9e3..665f5beef6ad 100644 --- a/net/netfilter/x_tables.c +++ b/net/netfilter/x_tables.c | |||
@@ -22,6 +22,7 @@ | |||
22 | #include <linux/vmalloc.h> | 22 | #include <linux/vmalloc.h> |
23 | #include <linux/mutex.h> | 23 | #include <linux/mutex.h> |
24 | #include <linux/mm.h> | 24 | #include <linux/mm.h> |
25 | #include <linux/slab.h> | ||
25 | #include <net/net_namespace.h> | 26 | #include <net/net_namespace.h> |
26 | 27 | ||
27 | #include <linux/netfilter/x_tables.h> | 28 | #include <linux/netfilter/x_tables.h> |
diff --git a/net/netfilter/xt_CT.c b/net/netfilter/xt_CT.c index 61c50fa84703..ee18b231b950 100644 --- a/net/netfilter/xt_CT.c +++ b/net/netfilter/xt_CT.c | |||
@@ -7,6 +7,7 @@ | |||
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include <linux/module.h> | 9 | #include <linux/module.h> |
10 | #include <linux/gfp.h> | ||
10 | #include <linux/skbuff.h> | 11 | #include <linux/skbuff.h> |
11 | #include <linux/selinux.h> | 12 | #include <linux/selinux.h> |
12 | #include <linux/netfilter_ipv4/ip_tables.h> | 13 | #include <linux/netfilter_ipv4/ip_tables.h> |
diff --git a/net/netfilter/xt_LED.c b/net/netfilter/xt_LED.c index 8ff7843bb921..3271c8e52153 100644 --- a/net/netfilter/xt_LED.c +++ b/net/netfilter/xt_LED.c | |||
@@ -22,6 +22,7 @@ | |||
22 | #include <linux/module.h> | 22 | #include <linux/module.h> |
23 | #include <linux/skbuff.h> | 23 | #include <linux/skbuff.h> |
24 | #include <linux/netfilter/x_tables.h> | 24 | #include <linux/netfilter/x_tables.h> |
25 | #include <linux/slab.h> | ||
25 | #include <linux/leds.h> | 26 | #include <linux/leds.h> |
26 | #include <linux/mutex.h> | 27 | #include <linux/mutex.h> |
27 | 28 | ||
diff --git a/net/netfilter/xt_RATEEST.c b/net/netfilter/xt_RATEEST.c index 87ae97e5516f..d16d55df4f61 100644 --- a/net/netfilter/xt_RATEEST.c +++ b/net/netfilter/xt_RATEEST.c | |||
@@ -11,6 +11,7 @@ | |||
11 | #include <linux/jhash.h> | 11 | #include <linux/jhash.h> |
12 | #include <linux/rtnetlink.h> | 12 | #include <linux/rtnetlink.h> |
13 | #include <linux/random.h> | 13 | #include <linux/random.h> |
14 | #include <linux/slab.h> | ||
14 | #include <net/gen_stats.h> | 15 | #include <net/gen_stats.h> |
15 | #include <net/netlink.h> | 16 | #include <net/netlink.h> |
16 | 17 | ||
diff --git a/net/netfilter/xt_TCPMSS.c b/net/netfilter/xt_TCPMSS.c index 0e357ac9a2a8..c5f4b9919e9a 100644 --- a/net/netfilter/xt_TCPMSS.c +++ b/net/netfilter/xt_TCPMSS.c | |||
@@ -11,6 +11,7 @@ | |||
11 | #include <linux/module.h> | 11 | #include <linux/module.h> |
12 | #include <linux/skbuff.h> | 12 | #include <linux/skbuff.h> |
13 | #include <linux/ip.h> | 13 | #include <linux/ip.h> |
14 | #include <linux/gfp.h> | ||
14 | #include <linux/ipv6.h> | 15 | #include <linux/ipv6.h> |
15 | #include <linux/tcp.h> | 16 | #include <linux/tcp.h> |
16 | #include <net/dst.h> | 17 | #include <net/dst.h> |
diff --git a/net/netfilter/xt_connlimit.c b/net/netfilter/xt_connlimit.c index 26997ce90e48..388ca4596098 100644 --- a/net/netfilter/xt_connlimit.c +++ b/net/netfilter/xt_connlimit.c | |||
@@ -17,6 +17,7 @@ | |||
17 | #include <linux/ip.h> | 17 | #include <linux/ip.h> |
18 | #include <linux/ipv6.h> | 18 | #include <linux/ipv6.h> |
19 | #include <linux/jhash.h> | 19 | #include <linux/jhash.h> |
20 | #include <linux/slab.h> | ||
20 | #include <linux/list.h> | 21 | #include <linux/list.h> |
21 | #include <linux/module.h> | 22 | #include <linux/module.h> |
22 | #include <linux/random.h> | 23 | #include <linux/random.h> |
diff --git a/net/netfilter/xt_dccp.c b/net/netfilter/xt_dccp.c index 0989f29ade2e..395af5943ffd 100644 --- a/net/netfilter/xt_dccp.c +++ b/net/netfilter/xt_dccp.c | |||
@@ -10,6 +10,7 @@ | |||
10 | 10 | ||
11 | #include <linux/module.h> | 11 | #include <linux/module.h> |
12 | #include <linux/skbuff.h> | 12 | #include <linux/skbuff.h> |
13 | #include <linux/slab.h> | ||
13 | #include <linux/spinlock.h> | 14 | #include <linux/spinlock.h> |
14 | #include <net/ip.h> | 15 | #include <net/ip.h> |
15 | #include <linux/dccp.h> | 16 | #include <linux/dccp.h> |
diff --git a/net/netfilter/xt_hashlimit.c b/net/netfilter/xt_hashlimit.c index d952806b6469..215a64835de8 100644 --- a/net/netfilter/xt_hashlimit.c +++ b/net/netfilter/xt_hashlimit.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | * xt_hashlimit - Netfilter module to limit the number of packets per time | 2 | * xt_hashlimit - Netfilter module to limit the number of packets per time |
3 | * seperately for each hashbucket (sourceip/sourceport/dstip/dstport) | 3 | * separately for each hashbucket (sourceip/sourceport/dstip/dstport) |
4 | * | 4 | * |
5 | * (C) 2003-2004 by Harald Welte <laforge@netfilter.org> | 5 | * (C) 2003-2004 by Harald Welte <laforge@netfilter.org> |
6 | * Copyright © CC Computer Consultants GmbH, 2007 - 2008 | 6 | * Copyright © CC Computer Consultants GmbH, 2007 - 2008 |
@@ -493,6 +493,7 @@ static void hashlimit_ipv6_mask(__be32 *i, unsigned int p) | |||
493 | case 64 ... 95: | 493 | case 64 ... 95: |
494 | i[2] = maskl(i[2], p - 64); | 494 | i[2] = maskl(i[2], p - 64); |
495 | i[3] = 0; | 495 | i[3] = 0; |
496 | break; | ||
496 | case 96 ... 127: | 497 | case 96 ... 127: |
497 | i[3] = maskl(i[3], p - 96); | 498 | i[3] = maskl(i[3], p - 96); |
498 | break; | 499 | break; |
@@ -879,7 +880,8 @@ static void dl_seq_stop(struct seq_file *s, void *v) | |||
879 | struct xt_hashlimit_htable *htable = s->private; | 880 | struct xt_hashlimit_htable *htable = s->private; |
880 | unsigned int *bucket = (unsigned int *)v; | 881 | unsigned int *bucket = (unsigned int *)v; |
881 | 882 | ||
882 | kfree(bucket); | 883 | if (!IS_ERR(bucket)) |
884 | kfree(bucket); | ||
883 | spin_unlock_bh(&htable->lock); | 885 | spin_unlock_bh(&htable->lock); |
884 | } | 886 | } |
885 | 887 | ||
diff --git a/net/netfilter/xt_limit.c b/net/netfilter/xt_limit.c index a0ca5339af41..e5d7e1ffb1a4 100644 --- a/net/netfilter/xt_limit.c +++ b/net/netfilter/xt_limit.c | |||
@@ -6,6 +6,7 @@ | |||
6 | * published by the Free Software Foundation. | 6 | * published by the Free Software Foundation. |
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include <linux/slab.h> | ||
9 | #include <linux/module.h> | 10 | #include <linux/module.h> |
10 | #include <linux/skbuff.h> | 11 | #include <linux/skbuff.h> |
11 | #include <linux/spinlock.h> | 12 | #include <linux/spinlock.h> |
diff --git a/net/netfilter/xt_quota.c b/net/netfilter/xt_quota.c index 390b7d09fe51..2d5562498c43 100644 --- a/net/netfilter/xt_quota.c +++ b/net/netfilter/xt_quota.c | |||
@@ -4,6 +4,7 @@ | |||
4 | * Sam Johnston <samj@samj.net> | 4 | * Sam Johnston <samj@samj.net> |
5 | */ | 5 | */ |
6 | #include <linux/skbuff.h> | 6 | #include <linux/skbuff.h> |
7 | #include <linux/slab.h> | ||
7 | #include <linux/spinlock.h> | 8 | #include <linux/spinlock.h> |
8 | 9 | ||
9 | #include <linux/netfilter/x_tables.h> | 10 | #include <linux/netfilter/x_tables.h> |
diff --git a/net/netfilter/xt_recent.c b/net/netfilter/xt_recent.c index 7073dbb8100c..834b736857cb 100644 --- a/net/netfilter/xt_recent.c +++ b/net/netfilter/xt_recent.c | |||
@@ -27,6 +27,7 @@ | |||
27 | #include <linux/bitops.h> | 27 | #include <linux/bitops.h> |
28 | #include <linux/skbuff.h> | 28 | #include <linux/skbuff.h> |
29 | #include <linux/inet.h> | 29 | #include <linux/inet.h> |
30 | #include <linux/slab.h> | ||
30 | #include <net/net_namespace.h> | 31 | #include <net/net_namespace.h> |
31 | #include <net/netns/generic.h> | 32 | #include <net/netns/generic.h> |
32 | 33 | ||
@@ -267,7 +268,7 @@ recent_mt(const struct sk_buff *skb, const struct xt_match_param *par) | |||
267 | for (i = 0; i < e->nstamps; i++) { | 268 | for (i = 0; i < e->nstamps; i++) { |
268 | if (info->seconds && time_after(time, e->stamps[i])) | 269 | if (info->seconds && time_after(time, e->stamps[i])) |
269 | continue; | 270 | continue; |
270 | if (info->hit_count && ++hits >= info->hit_count) { | 271 | if (!info->hit_count || ++hits >= info->hit_count) { |
271 | ret = !ret; | 272 | ret = !ret; |
272 | break; | 273 | break; |
273 | } | 274 | } |
diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c index d8c0f8f1a78e..937ce0633e99 100644 --- a/net/netfilter/xt_statistic.c +++ b/net/netfilter/xt_statistic.c | |||
@@ -12,6 +12,7 @@ | |||
12 | #include <linux/spinlock.h> | 12 | #include <linux/spinlock.h> |
13 | #include <linux/skbuff.h> | 13 | #include <linux/skbuff.h> |
14 | #include <linux/net.h> | 14 | #include <linux/net.h> |
15 | #include <linux/slab.h> | ||
15 | 16 | ||
16 | #include <linux/netfilter/xt_statistic.h> | 17 | #include <linux/netfilter/xt_statistic.h> |
17 | #include <linux/netfilter/x_tables.h> | 18 | #include <linux/netfilter/x_tables.h> |
diff --git a/net/netfilter/xt_string.c b/net/netfilter/xt_string.c index b4d774111311..96801ffd8af8 100644 --- a/net/netfilter/xt_string.c +++ b/net/netfilter/xt_string.c | |||
@@ -7,6 +7,7 @@ | |||
7 | * published by the Free Software Foundation. | 7 | * published by the Free Software Foundation. |
8 | */ | 8 | */ |
9 | 9 | ||
10 | #include <linux/gfp.h> | ||
10 | #include <linux/init.h> | 11 | #include <linux/init.h> |
11 | #include <linux/module.h> | 12 | #include <linux/module.h> |
12 | #include <linux/kernel.h> | 13 | #include <linux/kernel.h> |
diff --git a/net/netlabel/netlabel_cipso_v4.c b/net/netlabel/netlabel_cipso_v4.c index e639298bc9c8..5f14c8462e30 100644 --- a/net/netlabel/netlabel_cipso_v4.c +++ b/net/netlabel/netlabel_cipso_v4.c | |||
@@ -33,6 +33,7 @@ | |||
33 | #include <linux/string.h> | 33 | #include <linux/string.h> |
34 | #include <linux/skbuff.h> | 34 | #include <linux/skbuff.h> |
35 | #include <linux/audit.h> | 35 | #include <linux/audit.h> |
36 | #include <linux/slab.h> | ||
36 | #include <net/sock.h> | 37 | #include <net/sock.h> |
37 | #include <net/netlink.h> | 38 | #include <net/netlink.h> |
38 | #include <net/genetlink.h> | 39 | #include <net/genetlink.h> |
diff --git a/net/netlabel/netlabel_domainhash.c b/net/netlabel/netlabel_domainhash.c index 0bfeaab88ef5..d37b7f80fa37 100644 --- a/net/netlabel/netlabel_domainhash.c +++ b/net/netlabel/netlabel_domainhash.c | |||
@@ -35,6 +35,7 @@ | |||
35 | #include <linux/spinlock.h> | 35 | #include <linux/spinlock.h> |
36 | #include <linux/string.h> | 36 | #include <linux/string.h> |
37 | #include <linux/audit.h> | 37 | #include <linux/audit.h> |
38 | #include <linux/slab.h> | ||
38 | #include <net/netlabel.h> | 39 | #include <net/netlabel.h> |
39 | #include <net/cipso_ipv4.h> | 40 | #include <net/cipso_ipv4.h> |
40 | #include <asm/bug.h> | 41 | #include <asm/bug.h> |
@@ -50,9 +51,12 @@ struct netlbl_domhsh_tbl { | |||
50 | }; | 51 | }; |
51 | 52 | ||
52 | /* Domain hash table */ | 53 | /* Domain hash table */ |
53 | /* XXX - updates should be so rare that having one spinlock for the entire | 54 | /* updates should be so rare that having one spinlock for the entire hash table |
54 | * hash table should be okay */ | 55 | * should be okay */ |
55 | static DEFINE_SPINLOCK(netlbl_domhsh_lock); | 56 | static DEFINE_SPINLOCK(netlbl_domhsh_lock); |
57 | #define netlbl_domhsh_rcu_deref(p) \ | ||
58 | rcu_dereference_check(p, rcu_read_lock_held() || \ | ||
59 | lockdep_is_held(&netlbl_domhsh_lock)) | ||
56 | static struct netlbl_domhsh_tbl *netlbl_domhsh = NULL; | 60 | static struct netlbl_domhsh_tbl *netlbl_domhsh = NULL; |
57 | static struct netlbl_dom_map *netlbl_domhsh_def = NULL; | 61 | static struct netlbl_dom_map *netlbl_domhsh_def = NULL; |
58 | 62 | ||
@@ -106,7 +110,8 @@ static void netlbl_domhsh_free_entry(struct rcu_head *entry) | |||
106 | * Description: | 110 | * Description: |
107 | * This is the hashing function for the domain hash table, it returns the | 111 | * This is the hashing function for the domain hash table, it returns the |
108 | * correct bucket number for the domain. The caller is responsibile for | 112 | * correct bucket number for the domain. The caller is responsibile for |
109 | * calling the rcu_read_[un]lock() functions. | 113 | * ensuring that the hash table is protected with either a RCU read lock or the |
114 | * hash table lock. | ||
110 | * | 115 | * |
111 | */ | 116 | */ |
112 | static u32 netlbl_domhsh_hash(const char *key) | 117 | static u32 netlbl_domhsh_hash(const char *key) |
@@ -120,7 +125,7 @@ static u32 netlbl_domhsh_hash(const char *key) | |||
120 | 125 | ||
121 | for (iter = 0, val = 0, len = strlen(key); iter < len; iter++) | 126 | for (iter = 0, val = 0, len = strlen(key); iter < len; iter++) |
122 | val = (val << 4 | (val >> (8 * sizeof(u32) - 4))) ^ key[iter]; | 127 | val = (val << 4 | (val >> (8 * sizeof(u32) - 4))) ^ key[iter]; |
123 | return val & (rcu_dereference(netlbl_domhsh)->size - 1); | 128 | return val & (netlbl_domhsh_rcu_deref(netlbl_domhsh)->size - 1); |
124 | } | 129 | } |
125 | 130 | ||
126 | /** | 131 | /** |
@@ -130,7 +135,8 @@ static u32 netlbl_domhsh_hash(const char *key) | |||
130 | * Description: | 135 | * Description: |
131 | * Searches the domain hash table and returns a pointer to the hash table | 136 | * Searches the domain hash table and returns a pointer to the hash table |
132 | * entry if found, otherwise NULL is returned. The caller is responsibile for | 137 | * entry if found, otherwise NULL is returned. The caller is responsibile for |
133 | * the rcu hash table locks (i.e. the caller much call rcu_read_[un]lock()). | 138 | * ensuring that the hash table is protected with either a RCU read lock or the |
139 | * hash table lock. | ||
134 | * | 140 | * |
135 | */ | 141 | */ |
136 | static struct netlbl_dom_map *netlbl_domhsh_search(const char *domain) | 142 | static struct netlbl_dom_map *netlbl_domhsh_search(const char *domain) |
@@ -141,7 +147,7 @@ static struct netlbl_dom_map *netlbl_domhsh_search(const char *domain) | |||
141 | 147 | ||
142 | if (domain != NULL) { | 148 | if (domain != NULL) { |
143 | bkt = netlbl_domhsh_hash(domain); | 149 | bkt = netlbl_domhsh_hash(domain); |
144 | bkt_list = &rcu_dereference(netlbl_domhsh)->tbl[bkt]; | 150 | bkt_list = &netlbl_domhsh_rcu_deref(netlbl_domhsh)->tbl[bkt]; |
145 | list_for_each_entry_rcu(iter, bkt_list, list) | 151 | list_for_each_entry_rcu(iter, bkt_list, list) |
146 | if (iter->valid && strcmp(iter->domain, domain) == 0) | 152 | if (iter->valid && strcmp(iter->domain, domain) == 0) |
147 | return iter; | 153 | return iter; |
@@ -159,8 +165,8 @@ static struct netlbl_dom_map *netlbl_domhsh_search(const char *domain) | |||
159 | * Searches the domain hash table and returns a pointer to the hash table | 165 | * Searches the domain hash table and returns a pointer to the hash table |
160 | * entry if an exact match is found, if an exact match is not present in the | 166 | * entry if an exact match is found, if an exact match is not present in the |
161 | * hash table then the default entry is returned if valid otherwise NULL is | 167 | * hash table then the default entry is returned if valid otherwise NULL is |
162 | * returned. The caller is responsibile for the rcu hash table locks | 168 | * returned. The caller is responsibile ensuring that the hash table is |
163 | * (i.e. the caller much call rcu_read_[un]lock()). | 169 | * protected with either a RCU read lock or the hash table lock. |
164 | * | 170 | * |
165 | */ | 171 | */ |
166 | static struct netlbl_dom_map *netlbl_domhsh_search_def(const char *domain) | 172 | static struct netlbl_dom_map *netlbl_domhsh_search_def(const char *domain) |
@@ -169,7 +175,7 @@ static struct netlbl_dom_map *netlbl_domhsh_search_def(const char *domain) | |||
169 | 175 | ||
170 | entry = netlbl_domhsh_search(domain); | 176 | entry = netlbl_domhsh_search(domain); |
171 | if (entry == NULL) { | 177 | if (entry == NULL) { |
172 | entry = rcu_dereference(netlbl_domhsh_def); | 178 | entry = netlbl_domhsh_rcu_deref(netlbl_domhsh_def); |
173 | if (entry != NULL && !entry->valid) | 179 | if (entry != NULL && !entry->valid) |
174 | entry = NULL; | 180 | entry = NULL; |
175 | } | 181 | } |
@@ -306,8 +312,11 @@ int netlbl_domhsh_add(struct netlbl_dom_map *entry, | |||
306 | struct netlbl_af6list *tmp6; | 312 | struct netlbl_af6list *tmp6; |
307 | #endif /* IPv6 */ | 313 | #endif /* IPv6 */ |
308 | 314 | ||
315 | /* XXX - we can remove this RCU read lock as the spinlock protects the | ||
316 | * entire function, but before we do we need to fixup the | ||
317 | * netlbl_af[4,6]list RCU functions to do "the right thing" with | ||
318 | * respect to rcu_dereference() when only a spinlock is held. */ | ||
309 | rcu_read_lock(); | 319 | rcu_read_lock(); |
310 | |||
311 | spin_lock(&netlbl_domhsh_lock); | 320 | spin_lock(&netlbl_domhsh_lock); |
312 | if (entry->domain != NULL) | 321 | if (entry->domain != NULL) |
313 | entry_old = netlbl_domhsh_search(entry->domain); | 322 | entry_old = netlbl_domhsh_search(entry->domain); |
diff --git a/net/netlabel/netlabel_kapi.c b/net/netlabel/netlabel_kapi.c index 6ce00205f342..1b83e0009d8d 100644 --- a/net/netlabel/netlabel_kapi.c +++ b/net/netlabel/netlabel_kapi.c | |||
@@ -30,6 +30,7 @@ | |||
30 | 30 | ||
31 | #include <linux/init.h> | 31 | #include <linux/init.h> |
32 | #include <linux/types.h> | 32 | #include <linux/types.h> |
33 | #include <linux/slab.h> | ||
33 | #include <linux/audit.h> | 34 | #include <linux/audit.h> |
34 | #include <linux/in.h> | 35 | #include <linux/in.h> |
35 | #include <linux/in6.h> | 36 | #include <linux/in6.h> |
diff --git a/net/netlabel/netlabel_mgmt.c b/net/netlabel/netlabel_mgmt.c index 8203623e65ad..998e85e895d0 100644 --- a/net/netlabel/netlabel_mgmt.c +++ b/net/netlabel/netlabel_mgmt.c | |||
@@ -34,6 +34,7 @@ | |||
34 | #include <linux/skbuff.h> | 34 | #include <linux/skbuff.h> |
35 | #include <linux/in.h> | 35 | #include <linux/in.h> |
36 | #include <linux/in6.h> | 36 | #include <linux/in6.h> |
37 | #include <linux/slab.h> | ||
37 | #include <net/sock.h> | 38 | #include <net/sock.h> |
38 | #include <net/netlink.h> | 39 | #include <net/netlink.h> |
39 | #include <net/genetlink.h> | 40 | #include <net/genetlink.h> |
diff --git a/net/netlabel/netlabel_unlabeled.c b/net/netlabel/netlabel_unlabeled.c index 852d9d7976b9..a3d64aabe2f7 100644 --- a/net/netlabel/netlabel_unlabeled.c +++ b/net/netlabel/netlabel_unlabeled.c | |||
@@ -43,6 +43,7 @@ | |||
43 | #include <linux/notifier.h> | 43 | #include <linux/notifier.h> |
44 | #include <linux/netdevice.h> | 44 | #include <linux/netdevice.h> |
45 | #include <linux/security.h> | 45 | #include <linux/security.h> |
46 | #include <linux/slab.h> | ||
46 | #include <net/sock.h> | 47 | #include <net/sock.h> |
47 | #include <net/netlink.h> | 48 | #include <net/netlink.h> |
48 | #include <net/genetlink.h> | 49 | #include <net/genetlink.h> |
@@ -114,6 +115,9 @@ struct netlbl_unlhsh_walk_arg { | |||
114 | /* updates should be so rare that having one spinlock for the entire | 115 | /* updates should be so rare that having one spinlock for the entire |
115 | * hash table should be okay */ | 116 | * hash table should be okay */ |
116 | static DEFINE_SPINLOCK(netlbl_unlhsh_lock); | 117 | static DEFINE_SPINLOCK(netlbl_unlhsh_lock); |
118 | #define netlbl_unlhsh_rcu_deref(p) \ | ||
119 | rcu_dereference_check(p, rcu_read_lock_held() || \ | ||
120 | lockdep_is_held(&netlbl_unlhsh_lock)) | ||
117 | static struct netlbl_unlhsh_tbl *netlbl_unlhsh = NULL; | 121 | static struct netlbl_unlhsh_tbl *netlbl_unlhsh = NULL; |
118 | static struct netlbl_unlhsh_iface *netlbl_unlhsh_def = NULL; | 122 | static struct netlbl_unlhsh_iface *netlbl_unlhsh_def = NULL; |
119 | 123 | ||
@@ -235,15 +239,13 @@ static void netlbl_unlhsh_free_iface(struct rcu_head *entry) | |||
235 | * Description: | 239 | * Description: |
236 | * This is the hashing function for the unlabeled hash table, it returns the | 240 | * This is the hashing function for the unlabeled hash table, it returns the |
237 | * bucket number for the given device/interface. The caller is responsible for | 241 | * bucket number for the given device/interface. The caller is responsible for |
238 | * calling the rcu_read_[un]lock() functions. | 242 | * ensuring that the hash table is protected with either a RCU read lock or |
243 | * the hash table lock. | ||
239 | * | 244 | * |
240 | */ | 245 | */ |
241 | static u32 netlbl_unlhsh_hash(int ifindex) | 246 | static u32 netlbl_unlhsh_hash(int ifindex) |
242 | { | 247 | { |
243 | /* this is taken _almost_ directly from | 248 | return ifindex & (netlbl_unlhsh_rcu_deref(netlbl_unlhsh)->size - 1); |
244 | * security/selinux/netif.c:sel_netif_hasfn() as they do pretty much | ||
245 | * the same thing */ | ||
246 | return ifindex & (rcu_dereference(netlbl_unlhsh)->size - 1); | ||
247 | } | 249 | } |
248 | 250 | ||
249 | /** | 251 | /** |
@@ -253,7 +255,8 @@ static u32 netlbl_unlhsh_hash(int ifindex) | |||
253 | * Description: | 255 | * Description: |
254 | * Searches the unlabeled connection hash table and returns a pointer to the | 256 | * Searches the unlabeled connection hash table and returns a pointer to the |
255 | * interface entry which matches @ifindex, otherwise NULL is returned. The | 257 | * interface entry which matches @ifindex, otherwise NULL is returned. The |
256 | * caller is responsible for calling the rcu_read_[un]lock() functions. | 258 | * caller is responsible for ensuring that the hash table is protected with |
259 | * either a RCU read lock or the hash table lock. | ||
257 | * | 260 | * |
258 | */ | 261 | */ |
259 | static struct netlbl_unlhsh_iface *netlbl_unlhsh_search_iface(int ifindex) | 262 | static struct netlbl_unlhsh_iface *netlbl_unlhsh_search_iface(int ifindex) |
@@ -263,7 +266,7 @@ static struct netlbl_unlhsh_iface *netlbl_unlhsh_search_iface(int ifindex) | |||
263 | struct netlbl_unlhsh_iface *iter; | 266 | struct netlbl_unlhsh_iface *iter; |
264 | 267 | ||
265 | bkt = netlbl_unlhsh_hash(ifindex); | 268 | bkt = netlbl_unlhsh_hash(ifindex); |
266 | bkt_list = &rcu_dereference(netlbl_unlhsh)->tbl[bkt]; | 269 | bkt_list = &netlbl_unlhsh_rcu_deref(netlbl_unlhsh)->tbl[bkt]; |
267 | list_for_each_entry_rcu(iter, bkt_list, list) | 270 | list_for_each_entry_rcu(iter, bkt_list, list) |
268 | if (iter->valid && iter->ifindex == ifindex) | 271 | if (iter->valid && iter->ifindex == ifindex) |
269 | return iter; | 272 | return iter; |
@@ -272,33 +275,6 @@ static struct netlbl_unlhsh_iface *netlbl_unlhsh_search_iface(int ifindex) | |||
272 | } | 275 | } |
273 | 276 | ||
274 | /** | 277 | /** |
275 | * netlbl_unlhsh_search_iface_def - Search for a matching interface entry | ||
276 | * @ifindex: the network interface | ||
277 | * | ||
278 | * Description: | ||
279 | * Searches the unlabeled connection hash table and returns a pointer to the | ||
280 | * interface entry which matches @ifindex. If an exact match can not be found | ||
281 | * and there is a valid default entry, the default entry is returned, otherwise | ||
282 | * NULL is returned. The caller is responsible for calling the | ||
283 | * rcu_read_[un]lock() functions. | ||
284 | * | ||
285 | */ | ||
286 | static struct netlbl_unlhsh_iface *netlbl_unlhsh_search_iface_def(int ifindex) | ||
287 | { | ||
288 | struct netlbl_unlhsh_iface *entry; | ||
289 | |||
290 | entry = netlbl_unlhsh_search_iface(ifindex); | ||
291 | if (entry != NULL) | ||
292 | return entry; | ||
293 | |||
294 | entry = rcu_dereference(netlbl_unlhsh_def); | ||
295 | if (entry != NULL && entry->valid) | ||
296 | return entry; | ||
297 | |||
298 | return NULL; | ||
299 | } | ||
300 | |||
301 | /** | ||
302 | * netlbl_unlhsh_add_addr4 - Add a new IPv4 address entry to the hash table | 278 | * netlbl_unlhsh_add_addr4 - Add a new IPv4 address entry to the hash table |
303 | * @iface: the associated interface entry | 279 | * @iface: the associated interface entry |
304 | * @addr: IPv4 address in network byte order | 280 | * @addr: IPv4 address in network byte order |
@@ -308,8 +284,7 @@ static struct netlbl_unlhsh_iface *netlbl_unlhsh_search_iface_def(int ifindex) | |||
308 | * Description: | 284 | * Description: |
309 | * Add a new address entry into the unlabeled connection hash table using the | 285 | * Add a new address entry into the unlabeled connection hash table using the |
310 | * interface entry specified by @iface. On success zero is returned, otherwise | 286 | * interface entry specified by @iface. On success zero is returned, otherwise |
311 | * a negative value is returned. The caller is responsible for calling the | 287 | * a negative value is returned. |
312 | * rcu_read_[un]lock() functions. | ||
313 | * | 288 | * |
314 | */ | 289 | */ |
315 | static int netlbl_unlhsh_add_addr4(struct netlbl_unlhsh_iface *iface, | 290 | static int netlbl_unlhsh_add_addr4(struct netlbl_unlhsh_iface *iface, |
@@ -349,8 +324,7 @@ static int netlbl_unlhsh_add_addr4(struct netlbl_unlhsh_iface *iface, | |||
349 | * Description: | 324 | * Description: |
350 | * Add a new address entry into the unlabeled connection hash table using the | 325 | * Add a new address entry into the unlabeled connection hash table using the |
351 | * interface entry specified by @iface. On success zero is returned, otherwise | 326 | * interface entry specified by @iface. On success zero is returned, otherwise |
352 | * a negative value is returned. The caller is responsible for calling the | 327 | * a negative value is returned. |
353 | * rcu_read_[un]lock() functions. | ||
354 | * | 328 | * |
355 | */ | 329 | */ |
356 | static int netlbl_unlhsh_add_addr6(struct netlbl_unlhsh_iface *iface, | 330 | static int netlbl_unlhsh_add_addr6(struct netlbl_unlhsh_iface *iface, |
@@ -391,8 +365,7 @@ static int netlbl_unlhsh_add_addr6(struct netlbl_unlhsh_iface *iface, | |||
391 | * Description: | 365 | * Description: |
392 | * Add a new, empty, interface entry into the unlabeled connection hash table. | 366 | * Add a new, empty, interface entry into the unlabeled connection hash table. |
393 | * On success a pointer to the new interface entry is returned, on failure NULL | 367 | * On success a pointer to the new interface entry is returned, on failure NULL |
394 | * is returned. The caller is responsible for calling the rcu_read_[un]lock() | 368 | * is returned. |
395 | * functions. | ||
396 | * | 369 | * |
397 | */ | 370 | */ |
398 | static struct netlbl_unlhsh_iface *netlbl_unlhsh_add_iface(int ifindex) | 371 | static struct netlbl_unlhsh_iface *netlbl_unlhsh_add_iface(int ifindex) |
@@ -415,10 +388,10 @@ static struct netlbl_unlhsh_iface *netlbl_unlhsh_add_iface(int ifindex) | |||
415 | if (netlbl_unlhsh_search_iface(ifindex) != NULL) | 388 | if (netlbl_unlhsh_search_iface(ifindex) != NULL) |
416 | goto add_iface_failure; | 389 | goto add_iface_failure; |
417 | list_add_tail_rcu(&iface->list, | 390 | list_add_tail_rcu(&iface->list, |
418 | &rcu_dereference(netlbl_unlhsh)->tbl[bkt]); | 391 | &netlbl_unlhsh_rcu_deref(netlbl_unlhsh)->tbl[bkt]); |
419 | } else { | 392 | } else { |
420 | INIT_LIST_HEAD(&iface->list); | 393 | INIT_LIST_HEAD(&iface->list); |
421 | if (rcu_dereference(netlbl_unlhsh_def) != NULL) | 394 | if (netlbl_unlhsh_rcu_deref(netlbl_unlhsh_def) != NULL) |
422 | goto add_iface_failure; | 395 | goto add_iface_failure; |
423 | rcu_assign_pointer(netlbl_unlhsh_def, iface); | 396 | rcu_assign_pointer(netlbl_unlhsh_def, iface); |
424 | } | 397 | } |
@@ -548,8 +521,7 @@ unlhsh_add_return: | |||
548 | * | 521 | * |
549 | * Description: | 522 | * Description: |
550 | * Remove an IP address entry from the unlabeled connection hash table. | 523 | * Remove an IP address entry from the unlabeled connection hash table. |
551 | * Returns zero on success, negative values on failure. The caller is | 524 | * Returns zero on success, negative values on failure. |
552 | * responsible for calling the rcu_read_[un]lock() functions. | ||
553 | * | 525 | * |
554 | */ | 526 | */ |
555 | static int netlbl_unlhsh_remove_addr4(struct net *net, | 527 | static int netlbl_unlhsh_remove_addr4(struct net *net, |
@@ -611,8 +583,7 @@ static int netlbl_unlhsh_remove_addr4(struct net *net, | |||
611 | * | 583 | * |
612 | * Description: | 584 | * Description: |
613 | * Remove an IP address entry from the unlabeled connection hash table. | 585 | * Remove an IP address entry from the unlabeled connection hash table. |
614 | * Returns zero on success, negative values on failure. The caller is | 586 | * Returns zero on success, negative values on failure. |
615 | * responsible for calling the rcu_read_[un]lock() functions. | ||
616 | * | 587 | * |
617 | */ | 588 | */ |
618 | static int netlbl_unlhsh_remove_addr6(struct net *net, | 589 | static int netlbl_unlhsh_remove_addr6(struct net *net, |
@@ -1547,8 +1518,10 @@ int netlbl_unlabel_getattr(const struct sk_buff *skb, | |||
1547 | struct netlbl_unlhsh_iface *iface; | 1518 | struct netlbl_unlhsh_iface *iface; |
1548 | 1519 | ||
1549 | rcu_read_lock(); | 1520 | rcu_read_lock(); |
1550 | iface = netlbl_unlhsh_search_iface_def(skb->skb_iif); | 1521 | iface = netlbl_unlhsh_search_iface(skb->skb_iif); |
1551 | if (iface == NULL) | 1522 | if (iface == NULL) |
1523 | iface = rcu_dereference(netlbl_unlhsh_def); | ||
1524 | if (iface == NULL || !iface->valid) | ||
1552 | goto unlabel_getattr_nolabel; | 1525 | goto unlabel_getattr_nolabel; |
1553 | switch (family) { | 1526 | switch (family) { |
1554 | case PF_INET: { | 1527 | case PF_INET: { |
diff --git a/net/netlabel/netlabel_user.c b/net/netlabel/netlabel_user.c index 68706b4e3bf8..a3fd75ac3fa5 100644 --- a/net/netlabel/netlabel_user.c +++ b/net/netlabel/netlabel_user.c | |||
@@ -35,6 +35,7 @@ | |||
35 | #include <linux/audit.h> | 35 | #include <linux/audit.h> |
36 | #include <linux/tty.h> | 36 | #include <linux/tty.h> |
37 | #include <linux/security.h> | 37 | #include <linux/security.h> |
38 | #include <linux/gfp.h> | ||
38 | #include <net/sock.h> | 39 | #include <net/sock.h> |
39 | #include <net/netlink.h> | 40 | #include <net/netlink.h> |
40 | #include <net/genetlink.h> | 41 | #include <net/genetlink.h> |
diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c index 320d0423a240..6464a1972a69 100644 --- a/net/netlink/af_netlink.c +++ b/net/netlink/af_netlink.c | |||
@@ -545,7 +545,7 @@ static int netlink_autobind(struct socket *sock) | |||
545 | struct hlist_head *head; | 545 | struct hlist_head *head; |
546 | struct sock *osk; | 546 | struct sock *osk; |
547 | struct hlist_node *node; | 547 | struct hlist_node *node; |
548 | s32 pid = current->tgid; | 548 | s32 pid = task_tgid_vnr(current); |
549 | int err; | 549 | int err; |
550 | static s32 rover = -4097; | 550 | static s32 rover = -4097; |
551 | 551 | ||
@@ -683,6 +683,9 @@ static int netlink_connect(struct socket *sock, struct sockaddr *addr, | |||
683 | struct netlink_sock *nlk = nlk_sk(sk); | 683 | struct netlink_sock *nlk = nlk_sk(sk); |
684 | struct sockaddr_nl *nladdr = (struct sockaddr_nl *)addr; | 684 | struct sockaddr_nl *nladdr = (struct sockaddr_nl *)addr; |
685 | 685 | ||
686 | if (alen < sizeof(addr->sa_family)) | ||
687 | return -EINVAL; | ||
688 | |||
686 | if (addr->sa_family == AF_UNSPEC) { | 689 | if (addr->sa_family == AF_UNSPEC) { |
687 | sk->sk_state = NETLINK_UNCONNECTED; | 690 | sk->sk_state = NETLINK_UNCONNECTED; |
688 | nlk->dst_pid = 0; | 691 | nlk->dst_pid = 0; |
@@ -1093,6 +1096,7 @@ static inline int do_one_set_err(struct sock *sk, | |||
1093 | struct netlink_set_err_data *p) | 1096 | struct netlink_set_err_data *p) |
1094 | { | 1097 | { |
1095 | struct netlink_sock *nlk = nlk_sk(sk); | 1098 | struct netlink_sock *nlk = nlk_sk(sk); |
1099 | int ret = 0; | ||
1096 | 1100 | ||
1097 | if (sk == p->exclude_sk) | 1101 | if (sk == p->exclude_sk) |
1098 | goto out; | 1102 | goto out; |
@@ -1104,10 +1108,15 @@ static inline int do_one_set_err(struct sock *sk, | |||
1104 | !test_bit(p->group - 1, nlk->groups)) | 1108 | !test_bit(p->group - 1, nlk->groups)) |
1105 | goto out; | 1109 | goto out; |
1106 | 1110 | ||
1111 | if (p->code == ENOBUFS && nlk->flags & NETLINK_RECV_NO_ENOBUFS) { | ||
1112 | ret = 1; | ||
1113 | goto out; | ||
1114 | } | ||
1115 | |||
1107 | sk->sk_err = p->code; | 1116 | sk->sk_err = p->code; |
1108 | sk->sk_error_report(sk); | 1117 | sk->sk_error_report(sk); |
1109 | out: | 1118 | out: |
1110 | return 0; | 1119 | return ret; |
1111 | } | 1120 | } |
1112 | 1121 | ||
1113 | /** | 1122 | /** |
@@ -1116,12 +1125,16 @@ out: | |||
1116 | * @pid: the PID of a process that we want to skip (if any) | 1125 | * @pid: the PID of a process that we want to skip (if any) |
1117 | * @groups: the broadcast group that will notice the error | 1126 | * @groups: the broadcast group that will notice the error |
1118 | * @code: error code, must be negative (as usual in kernelspace) | 1127 | * @code: error code, must be negative (as usual in kernelspace) |
1128 | * | ||
1129 | * This function returns the number of broadcast listeners that have set the | ||
1130 | * NETLINK_RECV_NO_ENOBUFS socket option. | ||
1119 | */ | 1131 | */ |
1120 | void netlink_set_err(struct sock *ssk, u32 pid, u32 group, int code) | 1132 | int netlink_set_err(struct sock *ssk, u32 pid, u32 group, int code) |
1121 | { | 1133 | { |
1122 | struct netlink_set_err_data info; | 1134 | struct netlink_set_err_data info; |
1123 | struct hlist_node *node; | 1135 | struct hlist_node *node; |
1124 | struct sock *sk; | 1136 | struct sock *sk; |
1137 | int ret = 0; | ||
1125 | 1138 | ||
1126 | info.exclude_sk = ssk; | 1139 | info.exclude_sk = ssk; |
1127 | info.pid = pid; | 1140 | info.pid = pid; |
@@ -1132,9 +1145,10 @@ void netlink_set_err(struct sock *ssk, u32 pid, u32 group, int code) | |||
1132 | read_lock(&nl_table_lock); | 1145 | read_lock(&nl_table_lock); |
1133 | 1146 | ||
1134 | sk_for_each_bound(sk, node, &nl_table[ssk->sk_protocol].mc_list) | 1147 | sk_for_each_bound(sk, node, &nl_table[ssk->sk_protocol].mc_list) |
1135 | do_one_set_err(sk, &info); | 1148 | ret += do_one_set_err(sk, &info); |
1136 | 1149 | ||
1137 | read_unlock(&nl_table_lock); | 1150 | read_unlock(&nl_table_lock); |
1151 | return ret; | ||
1138 | } | 1152 | } |
1139 | EXPORT_SYMBOL(netlink_set_err); | 1153 | EXPORT_SYMBOL(netlink_set_err); |
1140 | 1154 | ||
diff --git a/net/netlink/genetlink.c b/net/netlink/genetlink.c index a4b6e148c5de..aa4308afcc7f 100644 --- a/net/netlink/genetlink.c +++ b/net/netlink/genetlink.c | |||
@@ -8,6 +8,7 @@ | |||
8 | 8 | ||
9 | #include <linux/module.h> | 9 | #include <linux/module.h> |
10 | #include <linux/kernel.h> | 10 | #include <linux/kernel.h> |
11 | #include <linux/slab.h> | ||
11 | #include <linux/errno.h> | 12 | #include <linux/errno.h> |
12 | #include <linux/types.h> | 13 | #include <linux/types.h> |
13 | #include <linux/socket.h> | 14 | #include <linux/socket.h> |
@@ -20,15 +21,17 @@ | |||
20 | 21 | ||
21 | static DEFINE_MUTEX(genl_mutex); /* serialization of message processing */ | 22 | static DEFINE_MUTEX(genl_mutex); /* serialization of message processing */ |
22 | 23 | ||
23 | static inline void genl_lock(void) | 24 | void genl_lock(void) |
24 | { | 25 | { |
25 | mutex_lock(&genl_mutex); | 26 | mutex_lock(&genl_mutex); |
26 | } | 27 | } |
28 | EXPORT_SYMBOL(genl_lock); | ||
27 | 29 | ||
28 | static inline void genl_unlock(void) | 30 | void genl_unlock(void) |
29 | { | 31 | { |
30 | mutex_unlock(&genl_mutex); | 32 | mutex_unlock(&genl_mutex); |
31 | } | 33 | } |
34 | EXPORT_SYMBOL(genl_unlock); | ||
32 | 35 | ||
33 | #define GENL_FAM_TAB_SIZE 16 | 36 | #define GENL_FAM_TAB_SIZE 16 |
34 | #define GENL_FAM_TAB_MASK (GENL_FAM_TAB_SIZE - 1) | 37 | #define GENL_FAM_TAB_MASK (GENL_FAM_TAB_SIZE - 1) |
diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c index a249127020a5..fa07f044b599 100644 --- a/net/netrom/af_netrom.c +++ b/net/netrom/af_netrom.c | |||
@@ -15,6 +15,7 @@ | |||
15 | #include <linux/types.h> | 15 | #include <linux/types.h> |
16 | #include <linux/socket.h> | 16 | #include <linux/socket.h> |
17 | #include <linux/in.h> | 17 | #include <linux/in.h> |
18 | #include <linux/slab.h> | ||
18 | #include <linux/kernel.h> | 19 | #include <linux/kernel.h> |
19 | #include <linux/sched.h> | 20 | #include <linux/sched.h> |
20 | #include <linux/timer.h> | 21 | #include <linux/timer.h> |
diff --git a/net/netrom/nr_dev.c b/net/netrom/nr_dev.c index 7aa11b01b2e2..64e6dde9749d 100644 --- a/net/netrom/nr_dev.c +++ b/net/netrom/nr_dev.c | |||
@@ -19,6 +19,7 @@ | |||
19 | #include <linux/fcntl.h> | 19 | #include <linux/fcntl.h> |
20 | #include <linux/in.h> | 20 | #include <linux/in.h> |
21 | #include <linux/if_ether.h> /* For the statistics structure. */ | 21 | #include <linux/if_ether.h> /* For the statistics structure. */ |
22 | #include <linux/slab.h> | ||
22 | 23 | ||
23 | #include <asm/system.h> | 24 | #include <asm/system.h> |
24 | #include <asm/uaccess.h> | 25 | #include <asm/uaccess.h> |
diff --git a/net/netrom/nr_in.c b/net/netrom/nr_in.c index 68176483617f..6d4ef6d65b3d 100644 --- a/net/netrom/nr_in.c +++ b/net/netrom/nr_in.c | |||
@@ -16,6 +16,7 @@ | |||
16 | #include <linux/string.h> | 16 | #include <linux/string.h> |
17 | #include <linux/sockios.h> | 17 | #include <linux/sockios.h> |
18 | #include <linux/net.h> | 18 | #include <linux/net.h> |
19 | #include <linux/slab.h> | ||
19 | #include <net/ax25.h> | 20 | #include <net/ax25.h> |
20 | #include <linux/inet.h> | 21 | #include <linux/inet.h> |
21 | #include <linux/netdevice.h> | 22 | #include <linux/netdevice.h> |
diff --git a/net/netrom/nr_loopback.c b/net/netrom/nr_loopback.c index f324d5df4186..94d4e922af53 100644 --- a/net/netrom/nr_loopback.c +++ b/net/netrom/nr_loopback.c | |||
@@ -7,6 +7,7 @@ | |||
7 | * Copyright Tomi Manninen OH2BNS (oh2bns@sral.fi) | 7 | * Copyright Tomi Manninen OH2BNS (oh2bns@sral.fi) |
8 | */ | 8 | */ |
9 | #include <linux/types.h> | 9 | #include <linux/types.h> |
10 | #include <linux/slab.h> | ||
10 | #include <linux/socket.h> | 11 | #include <linux/socket.h> |
11 | #include <linux/timer.h> | 12 | #include <linux/timer.h> |
12 | #include <net/ax25.h> | 13 | #include <net/ax25.h> |
diff --git a/net/netrom/nr_out.c b/net/netrom/nr_out.c index e3e6c44e1890..607fddb4fdbb 100644 --- a/net/netrom/nr_out.c +++ b/net/netrom/nr_out.c | |||
@@ -16,6 +16,7 @@ | |||
16 | #include <linux/string.h> | 16 | #include <linux/string.h> |
17 | #include <linux/sockios.h> | 17 | #include <linux/sockios.h> |
18 | #include <linux/net.h> | 18 | #include <linux/net.h> |
19 | #include <linux/slab.h> | ||
19 | #include <net/ax25.h> | 20 | #include <net/ax25.h> |
20 | #include <linux/inet.h> | 21 | #include <linux/inet.h> |
21 | #include <linux/netdevice.h> | 22 | #include <linux/netdevice.h> |
diff --git a/net/netrom/nr_route.c b/net/netrom/nr_route.c index 5cc648012f50..44059d0c8dd1 100644 --- a/net/netrom/nr_route.c +++ b/net/netrom/nr_route.c | |||
@@ -17,6 +17,7 @@ | |||
17 | #include <linux/string.h> | 17 | #include <linux/string.h> |
18 | #include <linux/sockios.h> | 18 | #include <linux/sockios.h> |
19 | #include <linux/net.h> | 19 | #include <linux/net.h> |
20 | #include <linux/slab.h> | ||
20 | #include <net/ax25.h> | 21 | #include <net/ax25.h> |
21 | #include <linux/inet.h> | 22 | #include <linux/inet.h> |
22 | #include <linux/netdevice.h> | 23 | #include <linux/netdevice.h> |
diff --git a/net/netrom/nr_subr.c b/net/netrom/nr_subr.c index 04e7d0d2fd8f..6a947ae50dbd 100644 --- a/net/netrom/nr_subr.c +++ b/net/netrom/nr_subr.c | |||
@@ -15,6 +15,7 @@ | |||
15 | #include <linux/string.h> | 15 | #include <linux/string.h> |
16 | #include <linux/sockios.h> | 16 | #include <linux/sockios.h> |
17 | #include <linux/net.h> | 17 | #include <linux/net.h> |
18 | #include <linux/slab.h> | ||
18 | #include <net/ax25.h> | 19 | #include <net/ax25.h> |
19 | #include <linux/inet.h> | 20 | #include <linux/inet.h> |
20 | #include <linux/netdevice.h> | 21 | #include <linux/netdevice.h> |
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c index 1612d417d10c..f162d59d8161 100644 --- a/net/packet/af_packet.c +++ b/net/packet/af_packet.c | |||
@@ -60,6 +60,7 @@ | |||
60 | #include <linux/wireless.h> | 60 | #include <linux/wireless.h> |
61 | #include <linux/kernel.h> | 61 | #include <linux/kernel.h> |
62 | #include <linux/kmod.h> | 62 | #include <linux/kmod.h> |
63 | #include <linux/slab.h> | ||
63 | #include <net/net_namespace.h> | 64 | #include <net/net_namespace.h> |
64 | #include <net/ip.h> | 65 | #include <net/ip.h> |
65 | #include <net/protocol.h> | 66 | #include <net/protocol.h> |
@@ -81,6 +82,7 @@ | |||
81 | #include <linux/mutex.h> | 82 | #include <linux/mutex.h> |
82 | #include <linux/if_vlan.h> | 83 | #include <linux/if_vlan.h> |
83 | #include <linux/virtio_net.h> | 84 | #include <linux/virtio_net.h> |
85 | #include <linux/errqueue.h> | ||
84 | 86 | ||
85 | #ifdef CONFIG_INET | 87 | #ifdef CONFIG_INET |
86 | #include <net/inet_common.h> | 88 | #include <net/inet_common.h> |
@@ -314,6 +316,8 @@ static inline struct packet_sock *pkt_sk(struct sock *sk) | |||
314 | 316 | ||
315 | static void packet_sock_destruct(struct sock *sk) | 317 | static void packet_sock_destruct(struct sock *sk) |
316 | { | 318 | { |
319 | skb_queue_purge(&sk->sk_error_queue); | ||
320 | |||
317 | WARN_ON(atomic_read(&sk->sk_rmem_alloc)); | 321 | WARN_ON(atomic_read(&sk->sk_rmem_alloc)); |
318 | WARN_ON(atomic_read(&sk->sk_wmem_alloc)); | 322 | WARN_ON(atomic_read(&sk->sk_wmem_alloc)); |
319 | 323 | ||
@@ -482,6 +486,9 @@ retry: | |||
482 | skb->dev = dev; | 486 | skb->dev = dev; |
483 | skb->priority = sk->sk_priority; | 487 | skb->priority = sk->sk_priority; |
484 | skb->mark = sk->sk_mark; | 488 | skb->mark = sk->sk_mark; |
489 | err = sock_tx_timestamp(msg, sk, skb_tx(skb)); | ||
490 | if (err < 0) | ||
491 | goto out_unlock; | ||
485 | 492 | ||
486 | dev_queue_xmit(skb); | 493 | dev_queue_xmit(skb); |
487 | rcu_read_unlock(); | 494 | rcu_read_unlock(); |
@@ -1187,6 +1194,9 @@ static int packet_snd(struct socket *sock, | |||
1187 | err = skb_copy_datagram_from_iovec(skb, offset, msg->msg_iov, 0, len); | 1194 | err = skb_copy_datagram_from_iovec(skb, offset, msg->msg_iov, 0, len); |
1188 | if (err) | 1195 | if (err) |
1189 | goto out_free; | 1196 | goto out_free; |
1197 | err = sock_tx_timestamp(msg, sk, skb_tx(skb)); | ||
1198 | if (err < 0) | ||
1199 | goto out_free; | ||
1190 | 1200 | ||
1191 | skb->protocol = proto; | 1201 | skb->protocol = proto; |
1192 | skb->dev = dev; | 1202 | skb->dev = dev; |
@@ -1486,6 +1496,51 @@ out: | |||
1486 | return err; | 1496 | return err; |
1487 | } | 1497 | } |
1488 | 1498 | ||
1499 | static int packet_recv_error(struct sock *sk, struct msghdr *msg, int len) | ||
1500 | { | ||
1501 | struct sock_exterr_skb *serr; | ||
1502 | struct sk_buff *skb, *skb2; | ||
1503 | int copied, err; | ||
1504 | |||
1505 | err = -EAGAIN; | ||
1506 | skb = skb_dequeue(&sk->sk_error_queue); | ||
1507 | if (skb == NULL) | ||
1508 | goto out; | ||
1509 | |||
1510 | copied = skb->len; | ||
1511 | if (copied > len) { | ||
1512 | msg->msg_flags |= MSG_TRUNC; | ||
1513 | copied = len; | ||
1514 | } | ||
1515 | err = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied); | ||
1516 | if (err) | ||
1517 | goto out_free_skb; | ||
1518 | |||
1519 | sock_recv_timestamp(msg, sk, skb); | ||
1520 | |||
1521 | serr = SKB_EXT_ERR(skb); | ||
1522 | put_cmsg(msg, SOL_PACKET, PACKET_TX_TIMESTAMP, | ||
1523 | sizeof(serr->ee), &serr->ee); | ||
1524 | |||
1525 | msg->msg_flags |= MSG_ERRQUEUE; | ||
1526 | err = copied; | ||
1527 | |||
1528 | /* Reset and regenerate socket error */ | ||
1529 | spin_lock_bh(&sk->sk_error_queue.lock); | ||
1530 | sk->sk_err = 0; | ||
1531 | if ((skb2 = skb_peek(&sk->sk_error_queue)) != NULL) { | ||
1532 | sk->sk_err = SKB_EXT_ERR(skb2)->ee.ee_errno; | ||
1533 | spin_unlock_bh(&sk->sk_error_queue.lock); | ||
1534 | sk->sk_error_report(sk); | ||
1535 | } else | ||
1536 | spin_unlock_bh(&sk->sk_error_queue.lock); | ||
1537 | |||
1538 | out_free_skb: | ||
1539 | kfree_skb(skb); | ||
1540 | out: | ||
1541 | return err; | ||
1542 | } | ||
1543 | |||
1489 | /* | 1544 | /* |
1490 | * Pull a packet from our receive queue and hand it to the user. | 1545 | * Pull a packet from our receive queue and hand it to the user. |
1491 | * If necessary we block. | 1546 | * If necessary we block. |
@@ -1501,7 +1556,7 @@ static int packet_recvmsg(struct kiocb *iocb, struct socket *sock, | |||
1501 | int vnet_hdr_len = 0; | 1556 | int vnet_hdr_len = 0; |
1502 | 1557 | ||
1503 | err = -EINVAL; | 1558 | err = -EINVAL; |
1504 | if (flags & ~(MSG_PEEK|MSG_DONTWAIT|MSG_TRUNC|MSG_CMSG_COMPAT)) | 1559 | if (flags & ~(MSG_PEEK|MSG_DONTWAIT|MSG_TRUNC|MSG_CMSG_COMPAT|MSG_ERRQUEUE)) |
1505 | goto out; | 1560 | goto out; |
1506 | 1561 | ||
1507 | #if 0 | 1562 | #if 0 |
@@ -1510,6 +1565,11 @@ static int packet_recvmsg(struct kiocb *iocb, struct socket *sock, | |||
1510 | return -ENODEV; | 1565 | return -ENODEV; |
1511 | #endif | 1566 | #endif |
1512 | 1567 | ||
1568 | if (flags & MSG_ERRQUEUE) { | ||
1569 | err = packet_recv_error(sk, msg, len); | ||
1570 | goto out; | ||
1571 | } | ||
1572 | |||
1513 | /* | 1573 | /* |
1514 | * Call the generic datagram receiver. This handles all sorts | 1574 | * Call the generic datagram receiver. This handles all sorts |
1515 | * of horrible races and re-entrancy so we can forget about it | 1575 | * of horrible races and re-entrancy so we can forget about it |
@@ -1691,9 +1751,9 @@ static int packet_dev_mc(struct net_device *dev, struct packet_mclist *i, | |||
1691 | if (i->alen != dev->addr_len) | 1751 | if (i->alen != dev->addr_len) |
1692 | return -EINVAL; | 1752 | return -EINVAL; |
1693 | if (what > 0) | 1753 | if (what > 0) |
1694 | return dev_mc_add(dev, i->addr, i->alen, 0); | 1754 | return dev_mc_add(dev, i->addr); |
1695 | else | 1755 | else |
1696 | return dev_mc_delete(dev, i->addr, i->alen, 0); | 1756 | return dev_mc_del(dev, i->addr); |
1697 | break; | 1757 | break; |
1698 | case PACKET_MR_PROMISC: | 1758 | case PACKET_MR_PROMISC: |
1699 | return dev_set_promiscuity(dev, what); | 1759 | return dev_set_promiscuity(dev, what); |
@@ -1705,9 +1765,9 @@ static int packet_dev_mc(struct net_device *dev, struct packet_mclist *i, | |||
1705 | if (i->alen != dev->addr_len) | 1765 | if (i->alen != dev->addr_len) |
1706 | return -EINVAL; | 1766 | return -EINVAL; |
1707 | if (what > 0) | 1767 | if (what > 0) |
1708 | return dev_unicast_add(dev, i->addr); | 1768 | return dev_uc_add(dev, i->addr); |
1709 | else | 1769 | else |
1710 | return dev_unicast_delete(dev, i->addr); | 1770 | return dev_uc_del(dev, i->addr); |
1711 | break; | 1771 | break; |
1712 | default: | 1772 | default: |
1713 | break; | 1773 | break; |
diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c index 526d0273991a..73aee7f2fcdc 100644 --- a/net/phonet/af_phonet.c +++ b/net/phonet/af_phonet.c | |||
@@ -25,6 +25,7 @@ | |||
25 | 25 | ||
26 | #include <linux/kernel.h> | 26 | #include <linux/kernel.h> |
27 | #include <linux/module.h> | 27 | #include <linux/module.h> |
28 | #include <linux/slab.h> | ||
28 | #include <asm/unaligned.h> | 29 | #include <asm/unaligned.h> |
29 | #include <net/sock.h> | 30 | #include <net/sock.h> |
30 | 31 | ||
diff --git a/net/phonet/datagram.c b/net/phonet/datagram.c index 387197b579b1..1bd38db4fe1e 100644 --- a/net/phonet/datagram.c +++ b/net/phonet/datagram.c | |||
@@ -24,6 +24,7 @@ | |||
24 | */ | 24 | */ |
25 | 25 | ||
26 | #include <linux/kernel.h> | 26 | #include <linux/kernel.h> |
27 | #include <linux/slab.h> | ||
27 | #include <linux/socket.h> | 28 | #include <linux/socket.h> |
28 | #include <asm/ioctls.h> | 29 | #include <asm/ioctls.h> |
29 | #include <net/sock.h> | 30 | #include <net/sock.h> |
diff --git a/net/phonet/pep.c b/net/phonet/pep.c index 360cf377693e..e2a95762abd3 100644 --- a/net/phonet/pep.c +++ b/net/phonet/pep.c | |||
@@ -23,6 +23,7 @@ | |||
23 | */ | 23 | */ |
24 | 24 | ||
25 | #include <linux/kernel.h> | 25 | #include <linux/kernel.h> |
26 | #include <linux/slab.h> | ||
26 | #include <linux/socket.h> | 27 | #include <linux/socket.h> |
27 | #include <net/sock.h> | 28 | #include <net/sock.h> |
28 | #include <net/tcp_states.h> | 29 | #include <net/tcp_states.h> |
diff --git a/net/phonet/pn_dev.c b/net/phonet/pn_dev.c index c597cc53a6fb..9b4ced6e0968 100644 --- a/net/phonet/pn_dev.c +++ b/net/phonet/pn_dev.c | |||
@@ -25,6 +25,7 @@ | |||
25 | 25 | ||
26 | #include <linux/kernel.h> | 26 | #include <linux/kernel.h> |
27 | #include <linux/net.h> | 27 | #include <linux/net.h> |
28 | #include <linux/slab.h> | ||
28 | #include <linux/netdevice.h> | 29 | #include <linux/netdevice.h> |
29 | #include <linux/phonet.h> | 30 | #include <linux/phonet.h> |
30 | #include <linux/proc_fs.h> | 31 | #include <linux/proc_fs.h> |
@@ -107,8 +108,7 @@ static void phonet_device_destroy(struct net_device *dev) | |||
107 | if (pnd) { | 108 | if (pnd) { |
108 | u8 addr; | 109 | u8 addr; |
109 | 110 | ||
110 | for (addr = find_first_bit(pnd->addrs, 64); addr < 64; | 111 | for_each_set_bit(addr, pnd->addrs, 64) |
111 | addr = find_next_bit(pnd->addrs, 64, 1+addr)) | ||
112 | phonet_address_notify(RTM_DELADDR, dev, addr); | 112 | phonet_address_notify(RTM_DELADDR, dev, addr); |
113 | kfree(pnd); | 113 | kfree(pnd); |
114 | } | 114 | } |
diff --git a/net/phonet/pn_netlink.c b/net/phonet/pn_netlink.c index 2e6c7eb8e76a..58b3b1f991ed 100644 --- a/net/phonet/pn_netlink.c +++ b/net/phonet/pn_netlink.c | |||
@@ -26,6 +26,7 @@ | |||
26 | #include <linux/kernel.h> | 26 | #include <linux/kernel.h> |
27 | #include <linux/netlink.h> | 27 | #include <linux/netlink.h> |
28 | #include <linux/phonet.h> | 28 | #include <linux/phonet.h> |
29 | #include <linux/slab.h> | ||
29 | #include <net/sock.h> | 30 | #include <net/sock.h> |
30 | #include <net/phonet/pn_dev.h> | 31 | #include <net/phonet/pn_dev.h> |
31 | 32 | ||
@@ -141,8 +142,7 @@ static int getaddr_dumpit(struct sk_buff *skb, struct netlink_callback *cb) | |||
141 | continue; | 142 | continue; |
142 | 143 | ||
143 | addr_idx = 0; | 144 | addr_idx = 0; |
144 | for (addr = find_first_bit(pnd->addrs, 64); addr < 64; | 145 | for_each_set_bit(addr, pnd->addrs, 64) { |
145 | addr = find_next_bit(pnd->addrs, 64, 1+addr)) { | ||
146 | if (addr_idx++ < addr_start_idx) | 146 | if (addr_idx++ < addr_start_idx) |
147 | continue; | 147 | continue; |
148 | 148 | ||
diff --git a/net/phonet/socket.c b/net/phonet/socket.c index 69c8b826a0ce..c785bfd0744f 100644 --- a/net/phonet/socket.c +++ b/net/phonet/socket.c | |||
@@ -23,6 +23,7 @@ | |||
23 | * 02110-1301 USA | 23 | * 02110-1301 USA |
24 | */ | 24 | */ |
25 | 25 | ||
26 | #include <linux/gfp.h> | ||
26 | #include <linux/kernel.h> | 27 | #include <linux/kernel.h> |
27 | #include <linux/net.h> | 28 | #include <linux/net.h> |
28 | #include <linux/poll.h> | 29 | #include <linux/poll.h> |
diff --git a/net/rds/af_rds.c b/net/rds/af_rds.c index 853c52be781f..7919a9edb8e9 100644 --- a/net/rds/af_rds.c +++ b/net/rds/af_rds.c | |||
@@ -33,6 +33,7 @@ | |||
33 | #include <linux/module.h> | 33 | #include <linux/module.h> |
34 | #include <linux/errno.h> | 34 | #include <linux/errno.h> |
35 | #include <linux/kernel.h> | 35 | #include <linux/kernel.h> |
36 | #include <linux/gfp.h> | ||
36 | #include <linux/in.h> | 37 | #include <linux/in.h> |
37 | #include <linux/poll.h> | 38 | #include <linux/poll.h> |
38 | #include <net/sock.h> | 39 | #include <net/sock.h> |
@@ -159,7 +160,8 @@ static unsigned int rds_poll(struct file *file, struct socket *sock, | |||
159 | 160 | ||
160 | poll_wait(file, sk->sk_sleep, wait); | 161 | poll_wait(file, sk->sk_sleep, wait); |
161 | 162 | ||
162 | poll_wait(file, &rds_poll_waitq, wait); | 163 | if (rs->rs_seen_congestion) |
164 | poll_wait(file, &rds_poll_waitq, wait); | ||
163 | 165 | ||
164 | read_lock_irqsave(&rs->rs_recv_lock, flags); | 166 | read_lock_irqsave(&rs->rs_recv_lock, flags); |
165 | if (!rs->rs_cong_monitor) { | 167 | if (!rs->rs_cong_monitor) { |
@@ -181,6 +183,10 @@ static unsigned int rds_poll(struct file *file, struct socket *sock, | |||
181 | mask |= (POLLOUT | POLLWRNORM); | 183 | mask |= (POLLOUT | POLLWRNORM); |
182 | read_unlock_irqrestore(&rs->rs_recv_lock, flags); | 184 | read_unlock_irqrestore(&rs->rs_recv_lock, flags); |
183 | 185 | ||
186 | /* clear state any time we wake a seen-congested socket */ | ||
187 | if (mask) | ||
188 | rs->rs_seen_congestion = 0; | ||
189 | |||
184 | return mask; | 190 | return mask; |
185 | } | 191 | } |
186 | 192 | ||
@@ -446,7 +452,6 @@ static void rds_sock_inc_info(struct socket *sock, unsigned int len, | |||
446 | struct rds_info_lengths *lens) | 452 | struct rds_info_lengths *lens) |
447 | { | 453 | { |
448 | struct rds_sock *rs; | 454 | struct rds_sock *rs; |
449 | struct sock *sk; | ||
450 | struct rds_incoming *inc; | 455 | struct rds_incoming *inc; |
451 | unsigned long flags; | 456 | unsigned long flags; |
452 | unsigned int total = 0; | 457 | unsigned int total = 0; |
@@ -456,7 +461,6 @@ static void rds_sock_inc_info(struct socket *sock, unsigned int len, | |||
456 | spin_lock_irqsave(&rds_sock_lock, flags); | 461 | spin_lock_irqsave(&rds_sock_lock, flags); |
457 | 462 | ||
458 | list_for_each_entry(rs, &rds_sock_list, rs_item) { | 463 | list_for_each_entry(rs, &rds_sock_list, rs_item) { |
459 | sk = rds_rs_to_sk(rs); | ||
460 | read_lock(&rs->rs_recv_lock); | 464 | read_lock(&rs->rs_recv_lock); |
461 | 465 | ||
462 | /* XXX too lazy to maintain counts.. */ | 466 | /* XXX too lazy to maintain counts.. */ |
diff --git a/net/rds/cong.c b/net/rds/cong.c index 6d06cac2649c..0871a29f0780 100644 --- a/net/rds/cong.c +++ b/net/rds/cong.c | |||
@@ -30,6 +30,7 @@ | |||
30 | * SOFTWARE. | 30 | * SOFTWARE. |
31 | * | 31 | * |
32 | */ | 32 | */ |
33 | #include <linux/slab.h> | ||
33 | #include <linux/types.h> | 34 | #include <linux/types.h> |
34 | #include <linux/rbtree.h> | 35 | #include <linux/rbtree.h> |
35 | 36 | ||
@@ -218,8 +219,6 @@ void rds_cong_queue_updates(struct rds_cong_map *map) | |||
218 | spin_lock_irqsave(&rds_cong_lock, flags); | 219 | spin_lock_irqsave(&rds_cong_lock, flags); |
219 | 220 | ||
220 | list_for_each_entry(conn, &map->m_conn_list, c_map_item) { | 221 | list_for_each_entry(conn, &map->m_conn_list, c_map_item) { |
221 | if (conn->c_loopback) | ||
222 | continue; | ||
223 | if (!test_and_set_bit(0, &conn->c_map_queued)) { | 222 | if (!test_and_set_bit(0, &conn->c_map_queued)) { |
224 | rds_stats_inc(s_cong_update_queued); | 223 | rds_stats_inc(s_cong_update_queued); |
225 | queue_delayed_work(rds_wq, &conn->c_send_w, 0); | 224 | queue_delayed_work(rds_wq, &conn->c_send_w, 0); |
diff --git a/net/rds/connection.c b/net/rds/connection.c index 278f607ab603..7619b671ca28 100644 --- a/net/rds/connection.c +++ b/net/rds/connection.c | |||
@@ -32,6 +32,7 @@ | |||
32 | */ | 32 | */ |
33 | #include <linux/kernel.h> | 33 | #include <linux/kernel.h> |
34 | #include <linux/list.h> | 34 | #include <linux/list.h> |
35 | #include <linux/slab.h> | ||
35 | #include <net/inet_hashtables.h> | 36 | #include <net/inet_hashtables.h> |
36 | 37 | ||
37 | #include "rds.h" | 38 | #include "rds.h" |
diff --git a/net/rds/ib.c b/net/rds/ib.c index 3b8992361042..8f2d6dd7700a 100644 --- a/net/rds/ib.c +++ b/net/rds/ib.c | |||
@@ -37,6 +37,7 @@ | |||
37 | #include <linux/inetdevice.h> | 37 | #include <linux/inetdevice.h> |
38 | #include <linux/if_arp.h> | 38 | #include <linux/if_arp.h> |
39 | #include <linux/delay.h> | 39 | #include <linux/delay.h> |
40 | #include <linux/slab.h> | ||
40 | 41 | ||
41 | #include "rds.h" | 42 | #include "rds.h" |
42 | #include "ib.h" | 43 | #include "ib.h" |
diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c index 647cb8ffc39b..10ed0d55f759 100644 --- a/net/rds/ib_cm.c +++ b/net/rds/ib_cm.c | |||
@@ -32,6 +32,7 @@ | |||
32 | */ | 32 | */ |
33 | #include <linux/kernel.h> | 33 | #include <linux/kernel.h> |
34 | #include <linux/in.h> | 34 | #include <linux/in.h> |
35 | #include <linux/slab.h> | ||
35 | #include <linux/vmalloc.h> | 36 | #include <linux/vmalloc.h> |
36 | 37 | ||
37 | #include "rds.h" | 38 | #include "rds.h" |
@@ -203,9 +204,10 @@ static void rds_ib_qp_event_handler(struct ib_event *event, void *data) | |||
203 | rdma_notify(ic->i_cm_id, IB_EVENT_COMM_EST); | 204 | rdma_notify(ic->i_cm_id, IB_EVENT_COMM_EST); |
204 | break; | 205 | break; |
205 | default: | 206 | default: |
206 | rds_ib_conn_error(conn, "RDS/IB: Fatal QP Event %u " | 207 | rdsdebug("Fatal QP Event %u " |
207 | "- connection %pI4->%pI4, reconnecting\n", | 208 | "- connection %pI4->%pI4, reconnecting\n", |
208 | event->event, &conn->c_laddr, &conn->c_faddr); | 209 | event->event, &conn->c_laddr, &conn->c_faddr); |
210 | rds_conn_drop(conn); | ||
209 | break; | 211 | break; |
210 | } | 212 | } |
211 | } | 213 | } |
diff --git a/net/rds/ib_rdma.c b/net/rds/ib_rdma.c index 4b0da865a72c..a54cd63f9e35 100644 --- a/net/rds/ib_rdma.c +++ b/net/rds/ib_rdma.c | |||
@@ -31,6 +31,7 @@ | |||
31 | * | 31 | * |
32 | */ | 32 | */ |
33 | #include <linux/kernel.h> | 33 | #include <linux/kernel.h> |
34 | #include <linux/slab.h> | ||
34 | 35 | ||
35 | #include "rds.h" | 36 | #include "rds.h" |
36 | #include "rdma.h" | 37 | #include "rdma.h" |
@@ -234,8 +235,8 @@ void rds_ib_destroy_mr_pool(struct rds_ib_mr_pool *pool) | |||
234 | { | 235 | { |
235 | flush_workqueue(rds_wq); | 236 | flush_workqueue(rds_wq); |
236 | rds_ib_flush_mr_pool(pool, 1); | 237 | rds_ib_flush_mr_pool(pool, 1); |
237 | BUG_ON(atomic_read(&pool->item_count)); | 238 | WARN_ON(atomic_read(&pool->item_count)); |
238 | BUG_ON(atomic_read(&pool->free_pinned)); | 239 | WARN_ON(atomic_read(&pool->free_pinned)); |
239 | kfree(pool); | 240 | kfree(pool); |
240 | } | 241 | } |
241 | 242 | ||
@@ -440,6 +441,7 @@ static void __rds_ib_teardown_mr(struct rds_ib_mr *ibmr) | |||
440 | 441 | ||
441 | /* FIXME we need a way to tell a r/w MR | 442 | /* FIXME we need a way to tell a r/w MR |
442 | * from a r/o MR */ | 443 | * from a r/o MR */ |
444 | BUG_ON(in_interrupt()); | ||
443 | set_page_dirty(page); | 445 | set_page_dirty(page); |
444 | put_page(page); | 446 | put_page(page); |
445 | } | 447 | } |
diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c index 04dc0d3f3c95..c74e9904a6b2 100644 --- a/net/rds/ib_recv.c +++ b/net/rds/ib_recv.c | |||
@@ -31,6 +31,7 @@ | |||
31 | * | 31 | * |
32 | */ | 32 | */ |
33 | #include <linux/kernel.h> | 33 | #include <linux/kernel.h> |
34 | #include <linux/slab.h> | ||
34 | #include <linux/pci.h> | 35 | #include <linux/pci.h> |
35 | #include <linux/dma-mapping.h> | 36 | #include <linux/dma-mapping.h> |
36 | #include <rdma/rdma_cm.h> | 37 | #include <rdma/rdma_cm.h> |
@@ -468,8 +469,8 @@ static void rds_ib_send_ack(struct rds_ib_connection *ic, unsigned int adv_credi | |||
468 | set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags); | 469 | set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags); |
469 | 470 | ||
470 | rds_ib_stats_inc(s_ib_ack_send_failure); | 471 | rds_ib_stats_inc(s_ib_ack_send_failure); |
471 | /* Need to finesse this later. */ | 472 | |
472 | BUG(); | 473 | rds_ib_conn_error(ic->conn, "sending ack failed\n"); |
473 | } else | 474 | } else |
474 | rds_ib_stats_inc(s_ib_ack_sent); | 475 | rds_ib_stats_inc(s_ib_ack_sent); |
475 | } | 476 | } |
diff --git a/net/rds/ib_send.c b/net/rds/ib_send.c index a10fab6886d1..17fa80803ab0 100644 --- a/net/rds/ib_send.c +++ b/net/rds/ib_send.c | |||
@@ -243,8 +243,12 @@ void rds_ib_send_cq_comp_handler(struct ib_cq *cq, void *context) | |||
243 | struct rds_message *rm; | 243 | struct rds_message *rm; |
244 | 244 | ||
245 | rm = rds_send_get_message(conn, send->s_op); | 245 | rm = rds_send_get_message(conn, send->s_op); |
246 | if (rm) | 246 | if (rm) { |
247 | if (rm->m_rdma_op) | ||
248 | rds_ib_send_unmap_rdma(ic, rm->m_rdma_op); | ||
247 | rds_ib_send_rdma_complete(rm, wc.status); | 249 | rds_ib_send_rdma_complete(rm, wc.status); |
250 | rds_message_put(rm); | ||
251 | } | ||
248 | } | 252 | } |
249 | 253 | ||
250 | oldest = (oldest + 1) % ic->i_send_ring.w_nr; | 254 | oldest = (oldest + 1) % ic->i_send_ring.w_nr; |
@@ -482,6 +486,13 @@ int rds_ib_xmit(struct rds_connection *conn, struct rds_message *rm, | |||
482 | BUG_ON(off % RDS_FRAG_SIZE); | 486 | BUG_ON(off % RDS_FRAG_SIZE); |
483 | BUG_ON(hdr_off != 0 && hdr_off != sizeof(struct rds_header)); | 487 | BUG_ON(hdr_off != 0 && hdr_off != sizeof(struct rds_header)); |
484 | 488 | ||
489 | /* Do not send cong updates to IB loopback */ | ||
490 | if (conn->c_loopback | ||
491 | && rm->m_inc.i_hdr.h_flags & RDS_FLAG_CONG_BITMAP) { | ||
492 | rds_cong_map_updated(conn->c_fcong, ~(u64) 0); | ||
493 | return sizeof(struct rds_header) + RDS_CONG_MAP_BYTES; | ||
494 | } | ||
495 | |||
485 | /* FIXME we may overallocate here */ | 496 | /* FIXME we may overallocate here */ |
486 | if (be32_to_cpu(rm->m_inc.i_hdr.h_len) == 0) | 497 | if (be32_to_cpu(rm->m_inc.i_hdr.h_len) == 0) |
487 | i = 1; | 498 | i = 1; |
@@ -574,8 +585,7 @@ int rds_ib_xmit(struct rds_connection *conn, struct rds_message *rm, | |||
574 | rds_ib_send_grab_credits(ic, 0, &posted, 1, RDS_MAX_ADV_CREDIT - adv_credits); | 585 | rds_ib_send_grab_credits(ic, 0, &posted, 1, RDS_MAX_ADV_CREDIT - adv_credits); |
575 | adv_credits += posted; | 586 | adv_credits += posted; |
576 | BUG_ON(adv_credits > 255); | 587 | BUG_ON(adv_credits > 255); |
577 | } else if (ic->i_rm != rm) | 588 | } |
578 | BUG(); | ||
579 | 589 | ||
580 | send = &ic->i_sends[pos]; | 590 | send = &ic->i_sends[pos]; |
581 | first = send; | 591 | first = send; |
@@ -714,8 +724,8 @@ add_header: | |||
714 | ic->i_rm = prev->s_rm; | 724 | ic->i_rm = prev->s_rm; |
715 | prev->s_rm = NULL; | 725 | prev->s_rm = NULL; |
716 | } | 726 | } |
717 | /* Finesse this later */ | 727 | |
718 | BUG(); | 728 | rds_ib_conn_error(ic->conn, "ib_post_send failed\n"); |
719 | goto out; | 729 | goto out; |
720 | } | 730 | } |
721 | 731 | ||
diff --git a/net/rds/info.c b/net/rds/info.c index 814a91a6f4a7..c45c4173a44d 100644 --- a/net/rds/info.c +++ b/net/rds/info.c | |||
@@ -32,6 +32,7 @@ | |||
32 | */ | 32 | */ |
33 | #include <linux/percpu.h> | 33 | #include <linux/percpu.h> |
34 | #include <linux/seq_file.h> | 34 | #include <linux/seq_file.h> |
35 | #include <linux/slab.h> | ||
35 | #include <linux/proc_fs.h> | 36 | #include <linux/proc_fs.h> |
36 | 37 | ||
37 | #include "rds.h" | 38 | #include "rds.h" |
diff --git a/net/rds/iw.c b/net/rds/iw.c index b28fa8525b24..c8f3d3525cb9 100644 --- a/net/rds/iw.c +++ b/net/rds/iw.c | |||
@@ -37,6 +37,7 @@ | |||
37 | #include <linux/inetdevice.h> | 37 | #include <linux/inetdevice.h> |
38 | #include <linux/if_arp.h> | 38 | #include <linux/if_arp.h> |
39 | #include <linux/delay.h> | 39 | #include <linux/delay.h> |
40 | #include <linux/slab.h> | ||
40 | 41 | ||
41 | #include "rds.h" | 42 | #include "rds.h" |
42 | #include "iw.h" | 43 | #include "iw.h" |
diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c index 394cf6b4d0aa..a9d951b4fbae 100644 --- a/net/rds/iw_cm.c +++ b/net/rds/iw_cm.c | |||
@@ -32,6 +32,7 @@ | |||
32 | */ | 32 | */ |
33 | #include <linux/kernel.h> | 33 | #include <linux/kernel.h> |
34 | #include <linux/in.h> | 34 | #include <linux/in.h> |
35 | #include <linux/slab.h> | ||
35 | #include <linux/vmalloc.h> | 36 | #include <linux/vmalloc.h> |
36 | 37 | ||
37 | #include "rds.h" | 38 | #include "rds.h" |
@@ -156,9 +157,11 @@ static void rds_iw_qp_event_handler(struct ib_event *event, void *data) | |||
156 | case IB_EVENT_QP_REQ_ERR: | 157 | case IB_EVENT_QP_REQ_ERR: |
157 | case IB_EVENT_QP_FATAL: | 158 | case IB_EVENT_QP_FATAL: |
158 | default: | 159 | default: |
159 | rds_iw_conn_error(conn, "RDS/IW: Fatal QP Event %u - connection %pI4->%pI4...reconnecting\n", | 160 | rdsdebug("Fatal QP Event %u " |
161 | "- connection %pI4->%pI4, reconnecting\n", | ||
160 | event->event, &conn->c_laddr, | 162 | event->event, &conn->c_laddr, |
161 | &conn->c_faddr); | 163 | &conn->c_faddr); |
164 | rds_conn_drop(conn); | ||
162 | break; | 165 | break; |
163 | } | 166 | } |
164 | } | 167 | } |
diff --git a/net/rds/iw_rdma.c b/net/rds/iw_rdma.c index 9eda11cca956..13dc1862d862 100644 --- a/net/rds/iw_rdma.c +++ b/net/rds/iw_rdma.c | |||
@@ -31,6 +31,7 @@ | |||
31 | * | 31 | * |
32 | */ | 32 | */ |
33 | #include <linux/kernel.h> | 33 | #include <linux/kernel.h> |
34 | #include <linux/slab.h> | ||
34 | 35 | ||
35 | #include "rds.h" | 36 | #include "rds.h" |
36 | #include "rdma.h" | 37 | #include "rdma.h" |
diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c index 54af7d6b92da..3d479067d54d 100644 --- a/net/rds/iw_recv.c +++ b/net/rds/iw_recv.c | |||
@@ -31,6 +31,7 @@ | |||
31 | * | 31 | * |
32 | */ | 32 | */ |
33 | #include <linux/kernel.h> | 33 | #include <linux/kernel.h> |
34 | #include <linux/slab.h> | ||
34 | #include <linux/pci.h> | 35 | #include <linux/pci.h> |
35 | #include <linux/dma-mapping.h> | 36 | #include <linux/dma-mapping.h> |
36 | #include <rdma/rdma_cm.h> | 37 | #include <rdma/rdma_cm.h> |
@@ -468,8 +469,8 @@ static void rds_iw_send_ack(struct rds_iw_connection *ic, unsigned int adv_credi | |||
468 | set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags); | 469 | set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags); |
469 | 470 | ||
470 | rds_iw_stats_inc(s_iw_ack_send_failure); | 471 | rds_iw_stats_inc(s_iw_ack_send_failure); |
471 | /* Need to finesse this later. */ | 472 | |
472 | BUG(); | 473 | rds_iw_conn_error(ic->conn, "sending ack failed\n"); |
473 | } else | 474 | } else |
474 | rds_iw_stats_inc(s_iw_ack_sent); | 475 | rds_iw_stats_inc(s_iw_ack_sent); |
475 | } | 476 | } |
diff --git a/net/rds/iw_send.c b/net/rds/iw_send.c index 1379e9d66a78..52182ff7519e 100644 --- a/net/rds/iw_send.c +++ b/net/rds/iw_send.c | |||
@@ -616,8 +616,7 @@ int rds_iw_xmit(struct rds_connection *conn, struct rds_message *rm, | |||
616 | rds_iw_send_grab_credits(ic, 0, &posted, 1, RDS_MAX_ADV_CREDIT - adv_credits); | 616 | rds_iw_send_grab_credits(ic, 0, &posted, 1, RDS_MAX_ADV_CREDIT - adv_credits); |
617 | adv_credits += posted; | 617 | adv_credits += posted; |
618 | BUG_ON(adv_credits > 255); | 618 | BUG_ON(adv_credits > 255); |
619 | } else if (ic->i_rm != rm) | 619 | } |
620 | BUG(); | ||
621 | 620 | ||
622 | send = &ic->i_sends[pos]; | 621 | send = &ic->i_sends[pos]; |
623 | first = send; | 622 | first = send; |
diff --git a/net/rds/loop.c b/net/rds/loop.c index 4a61997f554d..dd9879379457 100644 --- a/net/rds/loop.c +++ b/net/rds/loop.c | |||
@@ -31,6 +31,7 @@ | |||
31 | * | 31 | * |
32 | */ | 32 | */ |
33 | #include <linux/kernel.h> | 33 | #include <linux/kernel.h> |
34 | #include <linux/slab.h> | ||
34 | #include <linux/in.h> | 35 | #include <linux/in.h> |
35 | 36 | ||
36 | #include "rds.h" | 37 | #include "rds.h" |
@@ -80,16 +81,9 @@ static int rds_loop_xmit_cong_map(struct rds_connection *conn, | |||
80 | struct rds_cong_map *map, | 81 | struct rds_cong_map *map, |
81 | unsigned long offset) | 82 | unsigned long offset) |
82 | { | 83 | { |
83 | unsigned long i; | ||
84 | |||
85 | BUG_ON(offset); | 84 | BUG_ON(offset); |
86 | BUG_ON(map != conn->c_lcong); | 85 | BUG_ON(map != conn->c_lcong); |
87 | 86 | ||
88 | for (i = 0; i < RDS_CONG_MAP_PAGES; i++) { | ||
89 | memcpy((void *)conn->c_fcong->m_page_addrs[i], | ||
90 | (void *)map->m_page_addrs[i], PAGE_SIZE); | ||
91 | } | ||
92 | |||
93 | rds_cong_map_updated(conn->c_fcong, ~(u64) 0); | 87 | rds_cong_map_updated(conn->c_fcong, ~(u64) 0); |
94 | 88 | ||
95 | return sizeof(struct rds_header) + RDS_CONG_MAP_BYTES; | 89 | return sizeof(struct rds_header) + RDS_CONG_MAP_BYTES; |
diff --git a/net/rds/message.c b/net/rds/message.c index 73e600ffd87f..9a1d67e001ba 100644 --- a/net/rds/message.c +++ b/net/rds/message.c | |||
@@ -31,6 +31,7 @@ | |||
31 | * | 31 | * |
32 | */ | 32 | */ |
33 | #include <linux/kernel.h> | 33 | #include <linux/kernel.h> |
34 | #include <linux/slab.h> | ||
34 | 35 | ||
35 | #include "rds.h" | 36 | #include "rds.h" |
36 | #include "rdma.h" | 37 | #include "rdma.h" |
diff --git a/net/rds/page.c b/net/rds/page.c index 36790122dfd4..595a952d4b17 100644 --- a/net/rds/page.c +++ b/net/rds/page.c | |||
@@ -31,6 +31,7 @@ | |||
31 | * | 31 | * |
32 | */ | 32 | */ |
33 | #include <linux/highmem.h> | 33 | #include <linux/highmem.h> |
34 | #include <linux/gfp.h> | ||
34 | 35 | ||
35 | #include "rds.h" | 36 | #include "rds.h" |
36 | 37 | ||
diff --git a/net/rds/rdma.c b/net/rds/rdma.c index 4c64daa1f5d5..75fd13bb631b 100644 --- a/net/rds/rdma.c +++ b/net/rds/rdma.c | |||
@@ -31,6 +31,7 @@ | |||
31 | * | 31 | * |
32 | */ | 32 | */ |
33 | #include <linux/pagemap.h> | 33 | #include <linux/pagemap.h> |
34 | #include <linux/slab.h> | ||
34 | #include <linux/rbtree.h> | 35 | #include <linux/rbtree.h> |
35 | #include <linux/dma-mapping.h> /* for DMA_*_DEVICE */ | 36 | #include <linux/dma-mapping.h> /* for DMA_*_DEVICE */ |
36 | 37 | ||
@@ -438,8 +439,10 @@ void rds_rdma_free_op(struct rds_rdma_op *ro) | |||
438 | /* Mark page dirty if it was possibly modified, which | 439 | /* Mark page dirty if it was possibly modified, which |
439 | * is the case for a RDMA_READ which copies from remote | 440 | * is the case for a RDMA_READ which copies from remote |
440 | * to local memory */ | 441 | * to local memory */ |
441 | if (!ro->r_write) | 442 | if (!ro->r_write) { |
443 | BUG_ON(in_interrupt()); | ||
442 | set_page_dirty(page); | 444 | set_page_dirty(page); |
445 | } | ||
443 | put_page(page); | 446 | put_page(page); |
444 | } | 447 | } |
445 | 448 | ||
diff --git a/net/rds/rdma_transport.c b/net/rds/rdma_transport.c index 9ece910ea394..5ea82fc47c3e 100644 --- a/net/rds/rdma_transport.c +++ b/net/rds/rdma_transport.c | |||
@@ -101,7 +101,7 @@ int rds_rdma_cm_event_handler(struct rdma_cm_id *cm_id, | |||
101 | break; | 101 | break; |
102 | 102 | ||
103 | case RDMA_CM_EVENT_DISCONNECTED: | 103 | case RDMA_CM_EVENT_DISCONNECTED: |
104 | printk(KERN_WARNING "RDS/RDMA: DISCONNECT event - dropping connection " | 104 | rdsdebug("DISCONNECT event - dropping connection " |
105 | "%pI4->%pI4\n", &conn->c_laddr, | 105 | "%pI4->%pI4\n", &conn->c_laddr, |
106 | &conn->c_faddr); | 106 | &conn->c_faddr); |
107 | rds_conn_drop(conn); | 107 | rds_conn_drop(conn); |
@@ -109,8 +109,7 @@ int rds_rdma_cm_event_handler(struct rdma_cm_id *cm_id, | |||
109 | 109 | ||
110 | default: | 110 | default: |
111 | /* things like device disconnect? */ | 111 | /* things like device disconnect? */ |
112 | printk(KERN_ERR "unknown event %u\n", event->event); | 112 | printk(KERN_ERR "RDS: unknown event %u!\n", event->event); |
113 | BUG(); | ||
114 | break; | 113 | break; |
115 | } | 114 | } |
116 | 115 | ||
diff --git a/net/rds/rds.h b/net/rds/rds.h index 85d6f897ecc7..4bec6e2ed495 100644 --- a/net/rds/rds.h +++ b/net/rds/rds.h | |||
@@ -388,6 +388,8 @@ struct rds_sock { | |||
388 | 388 | ||
389 | /* flag indicating we were congested or not */ | 389 | /* flag indicating we were congested or not */ |
390 | int rs_congested; | 390 | int rs_congested; |
391 | /* seen congestion (ENOBUFS) when sending? */ | ||
392 | int rs_seen_congestion; | ||
391 | 393 | ||
392 | /* rs_lock protects all these adjacent members before the newline */ | 394 | /* rs_lock protects all these adjacent members before the newline */ |
393 | spinlock_t rs_lock; | 395 | spinlock_t rs_lock; |
diff --git a/net/rds/recv.c b/net/rds/recv.c index b426d67f760c..e2a2b9344f7b 100644 --- a/net/rds/recv.c +++ b/net/rds/recv.c | |||
@@ -31,6 +31,7 @@ | |||
31 | * | 31 | * |
32 | */ | 32 | */ |
33 | #include <linux/kernel.h> | 33 | #include <linux/kernel.h> |
34 | #include <linux/slab.h> | ||
34 | #include <net/sock.h> | 35 | #include <net/sock.h> |
35 | #include <linux/in.h> | 36 | #include <linux/in.h> |
36 | 37 | ||
diff --git a/net/rds/send.c b/net/rds/send.c index b2fccfc20769..53d6795ac9d0 100644 --- a/net/rds/send.c +++ b/net/rds/send.c | |||
@@ -31,6 +31,7 @@ | |||
31 | * | 31 | * |
32 | */ | 32 | */ |
33 | #include <linux/kernel.h> | 33 | #include <linux/kernel.h> |
34 | #include <linux/gfp.h> | ||
34 | #include <net/sock.h> | 35 | #include <net/sock.h> |
35 | #include <linux/in.h> | 36 | #include <linux/in.h> |
36 | #include <linux/list.h> | 37 | #include <linux/list.h> |
@@ -507,12 +508,13 @@ EXPORT_SYMBOL_GPL(rds_send_get_message); | |||
507 | */ | 508 | */ |
508 | void rds_send_remove_from_sock(struct list_head *messages, int status) | 509 | void rds_send_remove_from_sock(struct list_head *messages, int status) |
509 | { | 510 | { |
510 | unsigned long flags = 0; /* silence gcc :P */ | 511 | unsigned long flags; |
511 | struct rds_sock *rs = NULL; | 512 | struct rds_sock *rs = NULL; |
512 | struct rds_message *rm; | 513 | struct rds_message *rm; |
513 | 514 | ||
514 | local_irq_save(flags); | ||
515 | while (!list_empty(messages)) { | 515 | while (!list_empty(messages)) { |
516 | int was_on_sock = 0; | ||
517 | |||
516 | rm = list_entry(messages->next, struct rds_message, | 518 | rm = list_entry(messages->next, struct rds_message, |
517 | m_conn_item); | 519 | m_conn_item); |
518 | list_del_init(&rm->m_conn_item); | 520 | list_del_init(&rm->m_conn_item); |
@@ -527,20 +529,19 @@ void rds_send_remove_from_sock(struct list_head *messages, int status) | |||
527 | * while we're messing with it. It does not prevent the | 529 | * while we're messing with it. It does not prevent the |
528 | * message from being removed from the socket, though. | 530 | * message from being removed from the socket, though. |
529 | */ | 531 | */ |
530 | spin_lock(&rm->m_rs_lock); | 532 | spin_lock_irqsave(&rm->m_rs_lock, flags); |
531 | if (!test_bit(RDS_MSG_ON_SOCK, &rm->m_flags)) | 533 | if (!test_bit(RDS_MSG_ON_SOCK, &rm->m_flags)) |
532 | goto unlock_and_drop; | 534 | goto unlock_and_drop; |
533 | 535 | ||
534 | if (rs != rm->m_rs) { | 536 | if (rs != rm->m_rs) { |
535 | if (rs) { | 537 | if (rs) { |
536 | spin_unlock(&rs->rs_lock); | ||
537 | rds_wake_sk_sleep(rs); | 538 | rds_wake_sk_sleep(rs); |
538 | sock_put(rds_rs_to_sk(rs)); | 539 | sock_put(rds_rs_to_sk(rs)); |
539 | } | 540 | } |
540 | rs = rm->m_rs; | 541 | rs = rm->m_rs; |
541 | spin_lock(&rs->rs_lock); | ||
542 | sock_hold(rds_rs_to_sk(rs)); | 542 | sock_hold(rds_rs_to_sk(rs)); |
543 | } | 543 | } |
544 | spin_lock(&rs->rs_lock); | ||
544 | 545 | ||
545 | if (test_and_clear_bit(RDS_MSG_ON_SOCK, &rm->m_flags)) { | 546 | if (test_and_clear_bit(RDS_MSG_ON_SOCK, &rm->m_flags)) { |
546 | struct rds_rdma_op *ro = rm->m_rdma_op; | 547 | struct rds_rdma_op *ro = rm->m_rdma_op; |
@@ -557,21 +558,22 @@ void rds_send_remove_from_sock(struct list_head *messages, int status) | |||
557 | notifier->n_status = status; | 558 | notifier->n_status = status; |
558 | rm->m_rdma_op->r_notifier = NULL; | 559 | rm->m_rdma_op->r_notifier = NULL; |
559 | } | 560 | } |
560 | rds_message_put(rm); | 561 | was_on_sock = 1; |
561 | rm->m_rs = NULL; | 562 | rm->m_rs = NULL; |
562 | } | 563 | } |
564 | spin_unlock(&rs->rs_lock); | ||
563 | 565 | ||
564 | unlock_and_drop: | 566 | unlock_and_drop: |
565 | spin_unlock(&rm->m_rs_lock); | 567 | spin_unlock_irqrestore(&rm->m_rs_lock, flags); |
566 | rds_message_put(rm); | 568 | rds_message_put(rm); |
569 | if (was_on_sock) | ||
570 | rds_message_put(rm); | ||
567 | } | 571 | } |
568 | 572 | ||
569 | if (rs) { | 573 | if (rs) { |
570 | spin_unlock(&rs->rs_lock); | ||
571 | rds_wake_sk_sleep(rs); | 574 | rds_wake_sk_sleep(rs); |
572 | sock_put(rds_rs_to_sk(rs)); | 575 | sock_put(rds_rs_to_sk(rs)); |
573 | } | 576 | } |
574 | local_irq_restore(flags); | ||
575 | } | 577 | } |
576 | 578 | ||
577 | /* | 579 | /* |
@@ -633,9 +635,6 @@ void rds_send_drop_to(struct rds_sock *rs, struct sockaddr_in *dest) | |||
633 | list_move(&rm->m_sock_item, &list); | 635 | list_move(&rm->m_sock_item, &list); |
634 | rds_send_sndbuf_remove(rs, rm); | 636 | rds_send_sndbuf_remove(rs, rm); |
635 | clear_bit(RDS_MSG_ON_SOCK, &rm->m_flags); | 637 | clear_bit(RDS_MSG_ON_SOCK, &rm->m_flags); |
636 | |||
637 | /* If this is a RDMA operation, notify the app. */ | ||
638 | __rds_rdma_send_complete(rs, rm, RDS_RDMA_CANCELED); | ||
639 | } | 638 | } |
640 | 639 | ||
641 | /* order flag updates with the rs lock */ | 640 | /* order flag updates with the rs lock */ |
@@ -644,9 +643,6 @@ void rds_send_drop_to(struct rds_sock *rs, struct sockaddr_in *dest) | |||
644 | 643 | ||
645 | spin_unlock_irqrestore(&rs->rs_lock, flags); | 644 | spin_unlock_irqrestore(&rs->rs_lock, flags); |
646 | 645 | ||
647 | if (wake) | ||
648 | rds_wake_sk_sleep(rs); | ||
649 | |||
650 | conn = NULL; | 646 | conn = NULL; |
651 | 647 | ||
652 | /* now remove the messages from the conn list as needed */ | 648 | /* now remove the messages from the conn list as needed */ |
@@ -654,6 +650,10 @@ void rds_send_drop_to(struct rds_sock *rs, struct sockaddr_in *dest) | |||
654 | /* We do this here rather than in the loop above, so that | 650 | /* We do this here rather than in the loop above, so that |
655 | * we don't have to nest m_rs_lock under rs->rs_lock */ | 651 | * we don't have to nest m_rs_lock under rs->rs_lock */ |
656 | spin_lock_irqsave(&rm->m_rs_lock, flags2); | 652 | spin_lock_irqsave(&rm->m_rs_lock, flags2); |
653 | /* If this is a RDMA operation, notify the app. */ | ||
654 | spin_lock(&rs->rs_lock); | ||
655 | __rds_rdma_send_complete(rs, rm, RDS_RDMA_CANCELED); | ||
656 | spin_unlock(&rs->rs_lock); | ||
657 | rm->m_rs = NULL; | 657 | rm->m_rs = NULL; |
658 | spin_unlock_irqrestore(&rm->m_rs_lock, flags2); | 658 | spin_unlock_irqrestore(&rm->m_rs_lock, flags2); |
659 | 659 | ||
@@ -682,6 +682,9 @@ void rds_send_drop_to(struct rds_sock *rs, struct sockaddr_in *dest) | |||
682 | if (conn) | 682 | if (conn) |
683 | spin_unlock_irqrestore(&conn->c_lock, flags); | 683 | spin_unlock_irqrestore(&conn->c_lock, flags); |
684 | 684 | ||
685 | if (wake) | ||
686 | rds_wake_sk_sleep(rs); | ||
687 | |||
685 | while (!list_empty(&list)) { | 688 | while (!list_empty(&list)) { |
686 | rm = list_entry(list.next, struct rds_message, m_sock_item); | 689 | rm = list_entry(list.next, struct rds_message, m_sock_item); |
687 | list_del_init(&rm->m_sock_item); | 690 | list_del_init(&rm->m_sock_item); |
@@ -815,7 +818,7 @@ int rds_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg, | |||
815 | int ret = 0; | 818 | int ret = 0; |
816 | int queued = 0, allocated_mr = 0; | 819 | int queued = 0, allocated_mr = 0; |
817 | int nonblock = msg->msg_flags & MSG_DONTWAIT; | 820 | int nonblock = msg->msg_flags & MSG_DONTWAIT; |
818 | long timeo = sock_rcvtimeo(sk, nonblock); | 821 | long timeo = sock_sndtimeo(sk, nonblock); |
819 | 822 | ||
820 | /* Mirror Linux UDP mirror of BSD error message compatibility */ | 823 | /* Mirror Linux UDP mirror of BSD error message compatibility */ |
821 | /* XXX: Perhaps MSG_MORE someday */ | 824 | /* XXX: Perhaps MSG_MORE someday */ |
@@ -894,8 +897,10 @@ int rds_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg, | |||
894 | queue_delayed_work(rds_wq, &conn->c_conn_w, 0); | 897 | queue_delayed_work(rds_wq, &conn->c_conn_w, 0); |
895 | 898 | ||
896 | ret = rds_cong_wait(conn->c_fcong, dport, nonblock, rs); | 899 | ret = rds_cong_wait(conn->c_fcong, dport, nonblock, rs); |
897 | if (ret) | 900 | if (ret) { |
901 | rs->rs_seen_congestion = 1; | ||
898 | goto out; | 902 | goto out; |
903 | } | ||
899 | 904 | ||
900 | while (!rds_send_queue_rm(rs, conn, rm, rs->rs_bound_port, | 905 | while (!rds_send_queue_rm(rs, conn, rm, rs->rs_bound_port, |
901 | dport, &queued)) { | 906 | dport, &queued)) { |
diff --git a/net/rds/tcp.c b/net/rds/tcp.c index b5198aee45d3..babf4577ff7d 100644 --- a/net/rds/tcp.c +++ b/net/rds/tcp.c | |||
@@ -31,6 +31,7 @@ | |||
31 | * | 31 | * |
32 | */ | 32 | */ |
33 | #include <linux/kernel.h> | 33 | #include <linux/kernel.h> |
34 | #include <linux/slab.h> | ||
34 | #include <linux/in.h> | 35 | #include <linux/in.h> |
35 | #include <net/tcp.h> | 36 | #include <net/tcp.h> |
36 | 37 | ||
diff --git a/net/rds/tcp_listen.c b/net/rds/tcp_listen.c index 53cb1b54165d..975183fe6950 100644 --- a/net/rds/tcp_listen.c +++ b/net/rds/tcp_listen.c | |||
@@ -31,6 +31,7 @@ | |||
31 | * | 31 | * |
32 | */ | 32 | */ |
33 | #include <linux/kernel.h> | 33 | #include <linux/kernel.h> |
34 | #include <linux/gfp.h> | ||
34 | #include <linux/in.h> | 35 | #include <linux/in.h> |
35 | #include <net/tcp.h> | 36 | #include <net/tcp.h> |
36 | 37 | ||
diff --git a/net/rds/tcp_recv.c b/net/rds/tcp_recv.c index c00dafffbb5a..1aba6878fa5d 100644 --- a/net/rds/tcp_recv.c +++ b/net/rds/tcp_recv.c | |||
@@ -31,6 +31,7 @@ | |||
31 | * | 31 | * |
32 | */ | 32 | */ |
33 | #include <linux/kernel.h> | 33 | #include <linux/kernel.h> |
34 | #include <linux/slab.h> | ||
34 | #include <net/tcp.h> | 35 | #include <net/tcp.h> |
35 | 36 | ||
36 | #include "rds.h" | 37 | #include "rds.h" |
@@ -97,6 +98,7 @@ int rds_tcp_inc_copy_to_user(struct rds_incoming *inc, struct iovec *first_iov, | |||
97 | goto out; | 98 | goto out; |
98 | } | 99 | } |
99 | 100 | ||
101 | rds_stats_add(s_copy_to_user, to_copy); | ||
100 | size -= to_copy; | 102 | size -= to_copy; |
101 | ret += to_copy; | 103 | ret += to_copy; |
102 | skb_off += to_copy; | 104 | skb_off += to_copy; |
diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c index 34fdcc059e54..a28b895ff0d1 100644 --- a/net/rds/tcp_send.c +++ b/net/rds/tcp_send.c | |||
@@ -240,7 +240,9 @@ void rds_tcp_write_space(struct sock *sk) | |||
240 | tc->t_last_seen_una = rds_tcp_snd_una(tc); | 240 | tc->t_last_seen_una = rds_tcp_snd_una(tc); |
241 | rds_send_drop_acked(conn, rds_tcp_snd_una(tc), rds_tcp_is_acked); | 241 | rds_send_drop_acked(conn, rds_tcp_snd_una(tc), rds_tcp_is_acked); |
242 | 242 | ||
243 | queue_delayed_work(rds_wq, &conn->c_send_w, 0); | 243 | if ((atomic_read(&sk->sk_wmem_alloc) << 1) <= sk->sk_sndbuf) |
244 | queue_delayed_work(rds_wq, &conn->c_send_w, 0); | ||
245 | |||
244 | out: | 246 | out: |
245 | read_unlock(&sk->sk_callback_lock); | 247 | read_unlock(&sk->sk_callback_lock); |
246 | 248 | ||
diff --git a/net/rds/threads.c b/net/rds/threads.c index 00fa10e59af8..786c20eaaf5e 100644 --- a/net/rds/threads.c +++ b/net/rds/threads.c | |||
@@ -259,7 +259,7 @@ void rds_threads_exit(void) | |||
259 | 259 | ||
260 | int __init rds_threads_init(void) | 260 | int __init rds_threads_init(void) |
261 | { | 261 | { |
262 | rds_wq = create_singlethread_workqueue("krdsd"); | 262 | rds_wq = create_workqueue("krdsd"); |
263 | if (rds_wq == NULL) | 263 | if (rds_wq == NULL) |
264 | return -ENOMEM; | 264 | return -ENOMEM; |
265 | 265 | ||
diff --git a/net/rfkill/core.c b/net/rfkill/core.c index 7ae58b5b5a08..51875a0c5d48 100644 --- a/net/rfkill/core.c +++ b/net/rfkill/core.c | |||
@@ -33,6 +33,7 @@ | |||
33 | #include <linux/wait.h> | 33 | #include <linux/wait.h> |
34 | #include <linux/poll.h> | 34 | #include <linux/poll.h> |
35 | #include <linux/fs.h> | 35 | #include <linux/fs.h> |
36 | #include <linux/slab.h> | ||
36 | 37 | ||
37 | #include "rfkill.h" | 38 | #include "rfkill.h" |
38 | 39 | ||
diff --git a/net/rose/af_rose.c b/net/rose/af_rose.c index e90b9b6c16ae..4fb711a035f4 100644 --- a/net/rose/af_rose.c +++ b/net/rose/af_rose.c | |||
@@ -18,6 +18,7 @@ | |||
18 | #include <linux/types.h> | 18 | #include <linux/types.h> |
19 | #include <linux/socket.h> | 19 | #include <linux/socket.h> |
20 | #include <linux/in.h> | 20 | #include <linux/in.h> |
21 | #include <linux/slab.h> | ||
21 | #include <linux/kernel.h> | 22 | #include <linux/kernel.h> |
22 | #include <linux/sched.h> | 23 | #include <linux/sched.h> |
23 | #include <linux/spinlock.h> | 24 | #include <linux/spinlock.h> |
diff --git a/net/rose/rose_dev.c b/net/rose/rose_dev.c index 424b893d1450..178ff4f73c85 100644 --- a/net/rose/rose_dev.c +++ b/net/rose/rose_dev.c | |||
@@ -19,6 +19,7 @@ | |||
19 | #include <linux/fcntl.h> | 19 | #include <linux/fcntl.h> |
20 | #include <linux/in.h> | 20 | #include <linux/in.h> |
21 | #include <linux/if_ether.h> | 21 | #include <linux/if_ether.h> |
22 | #include <linux/slab.h> | ||
22 | 23 | ||
23 | #include <asm/system.h> | 24 | #include <asm/system.h> |
24 | #include <asm/io.h> | 25 | #include <asm/io.h> |
diff --git a/net/rose/rose_link.c b/net/rose/rose_link.c index 5ef5f6988a2e..a750a28e0221 100644 --- a/net/rose/rose_link.c +++ b/net/rose/rose_link.c | |||
@@ -16,6 +16,7 @@ | |||
16 | #include <linux/string.h> | 16 | #include <linux/string.h> |
17 | #include <linux/sockios.h> | 17 | #include <linux/sockios.h> |
18 | #include <linux/net.h> | 18 | #include <linux/net.h> |
19 | #include <linux/slab.h> | ||
19 | #include <net/ax25.h> | 20 | #include <net/ax25.h> |
20 | #include <linux/inet.h> | 21 | #include <linux/inet.h> |
21 | #include <linux/netdevice.h> | 22 | #include <linux/netdevice.h> |
diff --git a/net/rose/rose_loopback.c b/net/rose/rose_loopback.c index 968e8bac1b5d..ae4a9d99aec7 100644 --- a/net/rose/rose_loopback.c +++ b/net/rose/rose_loopback.c | |||
@@ -7,6 +7,7 @@ | |||
7 | * Copyright (C) Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk) | 7 | * Copyright (C) Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk) |
8 | */ | 8 | */ |
9 | #include <linux/types.h> | 9 | #include <linux/types.h> |
10 | #include <linux/slab.h> | ||
10 | #include <linux/socket.h> | 11 | #include <linux/socket.h> |
11 | #include <linux/timer.h> | 12 | #include <linux/timer.h> |
12 | #include <net/ax25.h> | 13 | #include <net/ax25.h> |
diff --git a/net/rose/rose_out.c b/net/rose/rose_out.c index 69820f93414b..4ebf33afbe47 100644 --- a/net/rose/rose_out.c +++ b/net/rose/rose_out.c | |||
@@ -15,6 +15,7 @@ | |||
15 | #include <linux/string.h> | 15 | #include <linux/string.h> |
16 | #include <linux/sockios.h> | 16 | #include <linux/sockios.h> |
17 | #include <linux/net.h> | 17 | #include <linux/net.h> |
18 | #include <linux/gfp.h> | ||
18 | #include <net/ax25.h> | 19 | #include <net/ax25.h> |
19 | #include <linux/inet.h> | 20 | #include <linux/inet.h> |
20 | #include <linux/netdevice.h> | 21 | #include <linux/netdevice.h> |
diff --git a/net/rose/rose_route.c b/net/rose/rose_route.c index 70a0b3b4b4d2..cbc244a128bd 100644 --- a/net/rose/rose_route.c +++ b/net/rose/rose_route.c | |||
@@ -16,6 +16,7 @@ | |||
16 | #include <linux/string.h> | 16 | #include <linux/string.h> |
17 | #include <linux/sockios.h> | 17 | #include <linux/sockios.h> |
18 | #include <linux/net.h> | 18 | #include <linux/net.h> |
19 | #include <linux/slab.h> | ||
19 | #include <net/ax25.h> | 20 | #include <net/ax25.h> |
20 | #include <linux/inet.h> | 21 | #include <linux/inet.h> |
21 | #include <linux/netdevice.h> | 22 | #include <linux/netdevice.h> |
diff --git a/net/rose/rose_subr.c b/net/rose/rose_subr.c index b05108f382da..1734abba26a2 100644 --- a/net/rose/rose_subr.c +++ b/net/rose/rose_subr.c | |||
@@ -15,6 +15,7 @@ | |||
15 | #include <linux/string.h> | 15 | #include <linux/string.h> |
16 | #include <linux/sockios.h> | 16 | #include <linux/sockios.h> |
17 | #include <linux/net.h> | 17 | #include <linux/net.h> |
18 | #include <linux/slab.h> | ||
18 | #include <net/ax25.h> | 19 | #include <net/ax25.h> |
19 | #include <linux/inet.h> | 20 | #include <linux/inet.h> |
20 | #include <linux/netdevice.h> | 21 | #include <linux/netdevice.h> |
diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c index 287b1415cee9..c060095b27ce 100644 --- a/net/rxrpc/af_rxrpc.c +++ b/net/rxrpc/af_rxrpc.c | |||
@@ -11,6 +11,7 @@ | |||
11 | 11 | ||
12 | #include <linux/module.h> | 12 | #include <linux/module.h> |
13 | #include <linux/net.h> | 13 | #include <linux/net.h> |
14 | #include <linux/slab.h> | ||
14 | #include <linux/skbuff.h> | 15 | #include <linux/skbuff.h> |
15 | #include <linux/poll.h> | 16 | #include <linux/poll.h> |
16 | #include <linux/proc_fs.h> | 17 | #include <linux/proc_fs.h> |
diff --git a/net/rxrpc/ar-accept.c b/net/rxrpc/ar-accept.c index 77228f28fa36..6d79310fcaae 100644 --- a/net/rxrpc/ar-accept.c +++ b/net/rxrpc/ar-accept.c | |||
@@ -17,6 +17,7 @@ | |||
17 | #include <linux/in.h> | 17 | #include <linux/in.h> |
18 | #include <linux/in6.h> | 18 | #include <linux/in6.h> |
19 | #include <linux/icmp.h> | 19 | #include <linux/icmp.h> |
20 | #include <linux/gfp.h> | ||
20 | #include <net/sock.h> | 21 | #include <net/sock.h> |
21 | #include <net/af_rxrpc.h> | 22 | #include <net/af_rxrpc.h> |
22 | #include <net/ip.h> | 23 | #include <net/ip.h> |
@@ -88,6 +89,11 @@ static int rxrpc_accept_incoming_call(struct rxrpc_local *local, | |||
88 | 89 | ||
89 | /* get a notification message to send to the server app */ | 90 | /* get a notification message to send to the server app */ |
90 | notification = alloc_skb(0, GFP_NOFS); | 91 | notification = alloc_skb(0, GFP_NOFS); |
92 | if (!notification) { | ||
93 | _debug("no memory"); | ||
94 | ret = -ENOMEM; | ||
95 | goto error_nofree; | ||
96 | } | ||
91 | rxrpc_new_skb(notification); | 97 | rxrpc_new_skb(notification); |
92 | notification->mark = RXRPC_SKB_MARK_NEW_CALL; | 98 | notification->mark = RXRPC_SKB_MARK_NEW_CALL; |
93 | 99 | ||
@@ -189,6 +195,7 @@ invalid_service: | |||
189 | ret = -ECONNREFUSED; | 195 | ret = -ECONNREFUSED; |
190 | error: | 196 | error: |
191 | rxrpc_free_skb(notification); | 197 | rxrpc_free_skb(notification); |
198 | error_nofree: | ||
192 | _leave(" = %d", ret); | 199 | _leave(" = %d", ret); |
193 | return ret; | 200 | return ret; |
194 | } | 201 | } |
diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c index b4a220977031..2714da167fb8 100644 --- a/net/rxrpc/ar-ack.c +++ b/net/rxrpc/ar-ack.c | |||
@@ -13,6 +13,7 @@ | |||
13 | #include <linux/circ_buf.h> | 13 | #include <linux/circ_buf.h> |
14 | #include <linux/net.h> | 14 | #include <linux/net.h> |
15 | #include <linux/skbuff.h> | 15 | #include <linux/skbuff.h> |
16 | #include <linux/slab.h> | ||
16 | #include <linux/udp.h> | 17 | #include <linux/udp.h> |
17 | #include <net/sock.h> | 18 | #include <net/sock.h> |
18 | #include <net/af_rxrpc.h> | 19 | #include <net/af_rxrpc.h> |
diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c index bc0019f704fe..909d092de9f4 100644 --- a/net/rxrpc/ar-call.c +++ b/net/rxrpc/ar-call.c | |||
@@ -9,6 +9,7 @@ | |||
9 | * 2 of the License, or (at your option) any later version. | 9 | * 2 of the License, or (at your option) any later version. |
10 | */ | 10 | */ |
11 | 11 | ||
12 | #include <linux/slab.h> | ||
12 | #include <linux/module.h> | 13 | #include <linux/module.h> |
13 | #include <linux/circ_buf.h> | 14 | #include <linux/circ_buf.h> |
14 | #include <net/sock.h> | 15 | #include <net/sock.h> |
diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c index 9f1ce841a0bb..4106ca95ec86 100644 --- a/net/rxrpc/ar-connection.c +++ b/net/rxrpc/ar-connection.c | |||
@@ -10,6 +10,7 @@ | |||
10 | */ | 10 | */ |
11 | 11 | ||
12 | #include <linux/module.h> | 12 | #include <linux/module.h> |
13 | #include <linux/slab.h> | ||
13 | #include <linux/net.h> | 14 | #include <linux/net.h> |
14 | #include <linux/skbuff.h> | 15 | #include <linux/skbuff.h> |
15 | #include <linux/crypto.h> | 16 | #include <linux/crypto.h> |
diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c index f98c8027e5c1..89315009bab1 100644 --- a/net/rxrpc/ar-input.c +++ b/net/rxrpc/ar-input.c | |||
@@ -17,6 +17,7 @@ | |||
17 | #include <linux/in.h> | 17 | #include <linux/in.h> |
18 | #include <linux/in6.h> | 18 | #include <linux/in6.h> |
19 | #include <linux/icmp.h> | 19 | #include <linux/icmp.h> |
20 | #include <linux/gfp.h> | ||
20 | #include <net/sock.h> | 21 | #include <net/sock.h> |
21 | #include <net/af_rxrpc.h> | 22 | #include <net/af_rxrpc.h> |
22 | #include <net/ip.h> | 23 | #include <net/ip.h> |
diff --git a/net/rxrpc/ar-key.c b/net/rxrpc/ar-key.c index 74697b200496..5ee16f0353fe 100644 --- a/net/rxrpc/ar-key.c +++ b/net/rxrpc/ar-key.c | |||
@@ -18,6 +18,7 @@ | |||
18 | #include <linux/key-type.h> | 18 | #include <linux/key-type.h> |
19 | #include <linux/crypto.h> | 19 | #include <linux/crypto.h> |
20 | #include <linux/ctype.h> | 20 | #include <linux/ctype.h> |
21 | #include <linux/slab.h> | ||
21 | #include <net/sock.h> | 22 | #include <net/sock.h> |
22 | #include <net/af_rxrpc.h> | 23 | #include <net/af_rxrpc.h> |
23 | #include <keys/rxrpc-type.h> | 24 | #include <keys/rxrpc-type.h> |
diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c index 807535ff29b5..87f7135d238b 100644 --- a/net/rxrpc/ar-local.c +++ b/net/rxrpc/ar-local.c | |||
@@ -12,6 +12,7 @@ | |||
12 | #include <linux/module.h> | 12 | #include <linux/module.h> |
13 | #include <linux/net.h> | 13 | #include <linux/net.h> |
14 | #include <linux/skbuff.h> | 14 | #include <linux/skbuff.h> |
15 | #include <linux/slab.h> | ||
15 | #include <net/sock.h> | 16 | #include <net/sock.h> |
16 | #include <net/af_rxrpc.h> | 17 | #include <net/af_rxrpc.h> |
17 | #include "ar-internal.h" | 18 | #include "ar-internal.h" |
diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c index cc9102c5b588..5f22e263eda7 100644 --- a/net/rxrpc/ar-output.c +++ b/net/rxrpc/ar-output.c | |||
@@ -10,6 +10,7 @@ | |||
10 | */ | 10 | */ |
11 | 11 | ||
12 | #include <linux/net.h> | 12 | #include <linux/net.h> |
13 | #include <linux/gfp.h> | ||
13 | #include <linux/skbuff.h> | 14 | #include <linux/skbuff.h> |
14 | #include <linux/circ_buf.h> | 15 | #include <linux/circ_buf.h> |
15 | #include <net/sock.h> | 16 | #include <net/sock.h> |
diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c index edc026c1eb76..f0f85b0123f7 100644 --- a/net/rxrpc/ar-peer.c +++ b/net/rxrpc/ar-peer.c | |||
@@ -16,6 +16,7 @@ | |||
16 | #include <linux/in.h> | 16 | #include <linux/in.h> |
17 | #include <linux/in6.h> | 17 | #include <linux/in6.h> |
18 | #include <linux/icmp.h> | 18 | #include <linux/icmp.h> |
19 | #include <linux/slab.h> | ||
19 | #include <net/sock.h> | 20 | #include <net/sock.h> |
20 | #include <net/af_rxrpc.h> | 21 | #include <net/af_rxrpc.h> |
21 | #include <net/ip.h> | 22 | #include <net/ip.h> |
diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c index 0936e1acc30e..5e0226fe587e 100644 --- a/net/rxrpc/ar-transport.c +++ b/net/rxrpc/ar-transport.c | |||
@@ -12,6 +12,7 @@ | |||
12 | #include <linux/module.h> | 12 | #include <linux/module.h> |
13 | #include <linux/net.h> | 13 | #include <linux/net.h> |
14 | #include <linux/skbuff.h> | 14 | #include <linux/skbuff.h> |
15 | #include <linux/slab.h> | ||
15 | #include <net/sock.h> | 16 | #include <net/sock.h> |
16 | #include <net/af_rxrpc.h> | 17 | #include <net/af_rxrpc.h> |
17 | #include "ar-internal.h" | 18 | #include "ar-internal.h" |
diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c index 713ac593e2e9..7635107726ce 100644 --- a/net/rxrpc/rxkad.c +++ b/net/rxrpc/rxkad.c | |||
@@ -16,6 +16,7 @@ | |||
16 | #include <linux/crypto.h> | 16 | #include <linux/crypto.h> |
17 | #include <linux/scatterlist.h> | 17 | #include <linux/scatterlist.h> |
18 | #include <linux/ctype.h> | 18 | #include <linux/ctype.h> |
19 | #include <linux/slab.h> | ||
19 | #include <net/sock.h> | 20 | #include <net/sock.h> |
20 | #include <net/af_rxrpc.h> | 21 | #include <net/af_rxrpc.h> |
21 | #include <keys/rxrpc-type.h> | 22 | #include <keys/rxrpc-type.h> |
diff --git a/net/sched/Kconfig b/net/sched/Kconfig index 21f9c7678aa3..2f691fb180d1 100644 --- a/net/sched/Kconfig +++ b/net/sched/Kconfig | |||
@@ -328,13 +328,16 @@ config NET_CLS_FLOW | |||
328 | module will be called cls_flow. | 328 | module will be called cls_flow. |
329 | 329 | ||
330 | config NET_CLS_CGROUP | 330 | config NET_CLS_CGROUP |
331 | bool "Control Group Classifier" | 331 | tristate "Control Group Classifier" |
332 | select NET_CLS | 332 | select NET_CLS |
333 | depends on CGROUPS | 333 | depends on CGROUPS |
334 | ---help--- | 334 | ---help--- |
335 | Say Y here if you want to classify packets based on the control | 335 | Say Y here if you want to classify packets based on the control |
336 | cgroup of their process. | 336 | cgroup of their process. |
337 | 337 | ||
338 | To compile this code as a module, choose M here: the | ||
339 | module will be called cls_cgroup. | ||
340 | |||
338 | config NET_EMATCH | 341 | config NET_EMATCH |
339 | bool "Extended Matches" | 342 | bool "Extended Matches" |
340 | select NET_CLS | 343 | select NET_CLS |
diff --git a/net/sched/act_api.c b/net/sched/act_api.c index 64f5e328cee9..019045174fc3 100644 --- a/net/sched/act_api.c +++ b/net/sched/act_api.c | |||
@@ -15,6 +15,7 @@ | |||
15 | #include <linux/kernel.h> | 15 | #include <linux/kernel.h> |
16 | #include <linux/string.h> | 16 | #include <linux/string.h> |
17 | #include <linux/errno.h> | 17 | #include <linux/errno.h> |
18 | #include <linux/slab.h> | ||
18 | #include <linux/skbuff.h> | 19 | #include <linux/skbuff.h> |
19 | #include <linux/init.h> | 20 | #include <linux/init.h> |
20 | #include <linux/kmod.h> | 21 | #include <linux/kmod.h> |
@@ -667,7 +668,8 @@ nlmsg_failure: | |||
667 | } | 668 | } |
668 | 669 | ||
669 | static int | 670 | static int |
670 | act_get_notify(u32 pid, struct nlmsghdr *n, struct tc_action *a, int event) | 671 | act_get_notify(struct net *net, u32 pid, struct nlmsghdr *n, |
672 | struct tc_action *a, int event) | ||
671 | { | 673 | { |
672 | struct sk_buff *skb; | 674 | struct sk_buff *skb; |
673 | 675 | ||
@@ -679,7 +681,7 @@ act_get_notify(u32 pid, struct nlmsghdr *n, struct tc_action *a, int event) | |||
679 | return -EINVAL; | 681 | return -EINVAL; |
680 | } | 682 | } |
681 | 683 | ||
682 | return rtnl_unicast(skb, &init_net, pid); | 684 | return rtnl_unicast(skb, net, pid); |
683 | } | 685 | } |
684 | 686 | ||
685 | static struct tc_action * | 687 | static struct tc_action * |
@@ -749,7 +751,8 @@ static struct tc_action *create_a(int i) | |||
749 | return act; | 751 | return act; |
750 | } | 752 | } |
751 | 753 | ||
752 | static int tca_action_flush(struct nlattr *nla, struct nlmsghdr *n, u32 pid) | 754 | static int tca_action_flush(struct net *net, struct nlattr *nla, |
755 | struct nlmsghdr *n, u32 pid) | ||
753 | { | 756 | { |
754 | struct sk_buff *skb; | 757 | struct sk_buff *skb; |
755 | unsigned char *b; | 758 | unsigned char *b; |
@@ -808,7 +811,7 @@ static int tca_action_flush(struct nlattr *nla, struct nlmsghdr *n, u32 pid) | |||
808 | nlh->nlmsg_flags |= NLM_F_ROOT; | 811 | nlh->nlmsg_flags |= NLM_F_ROOT; |
809 | module_put(a->ops->owner); | 812 | module_put(a->ops->owner); |
810 | kfree(a); | 813 | kfree(a); |
811 | err = rtnetlink_send(skb, &init_net, pid, RTNLGRP_TC, n->nlmsg_flags&NLM_F_ECHO); | 814 | err = rtnetlink_send(skb, net, pid, RTNLGRP_TC, n->nlmsg_flags&NLM_F_ECHO); |
812 | if (err > 0) | 815 | if (err > 0) |
813 | return 0; | 816 | return 0; |
814 | 817 | ||
@@ -825,7 +828,8 @@ noflush_out: | |||
825 | } | 828 | } |
826 | 829 | ||
827 | static int | 830 | static int |
828 | tca_action_gd(struct nlattr *nla, struct nlmsghdr *n, u32 pid, int event) | 831 | tca_action_gd(struct net *net, struct nlattr *nla, struct nlmsghdr *n, |
832 | u32 pid, int event) | ||
829 | { | 833 | { |
830 | int i, ret; | 834 | int i, ret; |
831 | struct nlattr *tb[TCA_ACT_MAX_PRIO+1]; | 835 | struct nlattr *tb[TCA_ACT_MAX_PRIO+1]; |
@@ -837,7 +841,7 @@ tca_action_gd(struct nlattr *nla, struct nlmsghdr *n, u32 pid, int event) | |||
837 | 841 | ||
838 | if (event == RTM_DELACTION && n->nlmsg_flags&NLM_F_ROOT) { | 842 | if (event == RTM_DELACTION && n->nlmsg_flags&NLM_F_ROOT) { |
839 | if (tb[1] != NULL) | 843 | if (tb[1] != NULL) |
840 | return tca_action_flush(tb[1], n, pid); | 844 | return tca_action_flush(net, tb[1], n, pid); |
841 | else | 845 | else |
842 | return -EINVAL; | 846 | return -EINVAL; |
843 | } | 847 | } |
@@ -858,7 +862,7 @@ tca_action_gd(struct nlattr *nla, struct nlmsghdr *n, u32 pid, int event) | |||
858 | } | 862 | } |
859 | 863 | ||
860 | if (event == RTM_GETACTION) | 864 | if (event == RTM_GETACTION) |
861 | ret = act_get_notify(pid, n, head, event); | 865 | ret = act_get_notify(net, pid, n, head, event); |
862 | else { /* delete */ | 866 | else { /* delete */ |
863 | struct sk_buff *skb; | 867 | struct sk_buff *skb; |
864 | 868 | ||
@@ -877,7 +881,7 @@ tca_action_gd(struct nlattr *nla, struct nlmsghdr *n, u32 pid, int event) | |||
877 | 881 | ||
878 | /* now do the delete */ | 882 | /* now do the delete */ |
879 | tcf_action_destroy(head, 0); | 883 | tcf_action_destroy(head, 0); |
880 | ret = rtnetlink_send(skb, &init_net, pid, RTNLGRP_TC, | 884 | ret = rtnetlink_send(skb, net, pid, RTNLGRP_TC, |
881 | n->nlmsg_flags&NLM_F_ECHO); | 885 | n->nlmsg_flags&NLM_F_ECHO); |
882 | if (ret > 0) | 886 | if (ret > 0) |
883 | return 0; | 887 | return 0; |
@@ -888,8 +892,8 @@ err: | |||
888 | return ret; | 892 | return ret; |
889 | } | 893 | } |
890 | 894 | ||
891 | static int tcf_add_notify(struct tc_action *a, u32 pid, u32 seq, int event, | 895 | static int tcf_add_notify(struct net *net, struct tc_action *a, |
892 | u16 flags) | 896 | u32 pid, u32 seq, int event, u16 flags) |
893 | { | 897 | { |
894 | struct tcamsg *t; | 898 | struct tcamsg *t; |
895 | struct nlmsghdr *nlh; | 899 | struct nlmsghdr *nlh; |
@@ -922,7 +926,7 @@ static int tcf_add_notify(struct tc_action *a, u32 pid, u32 seq, int event, | |||
922 | nlh->nlmsg_len = skb_tail_pointer(skb) - b; | 926 | nlh->nlmsg_len = skb_tail_pointer(skb) - b; |
923 | NETLINK_CB(skb).dst_group = RTNLGRP_TC; | 927 | NETLINK_CB(skb).dst_group = RTNLGRP_TC; |
924 | 928 | ||
925 | err = rtnetlink_send(skb, &init_net, pid, RTNLGRP_TC, flags&NLM_F_ECHO); | 929 | err = rtnetlink_send(skb, net, pid, RTNLGRP_TC, flags&NLM_F_ECHO); |
926 | if (err > 0) | 930 | if (err > 0) |
927 | err = 0; | 931 | err = 0; |
928 | return err; | 932 | return err; |
@@ -935,7 +939,8 @@ nlmsg_failure: | |||
935 | 939 | ||
936 | 940 | ||
937 | static int | 941 | static int |
938 | tcf_action_add(struct nlattr *nla, struct nlmsghdr *n, u32 pid, int ovr) | 942 | tcf_action_add(struct net *net, struct nlattr *nla, struct nlmsghdr *n, |
943 | u32 pid, int ovr) | ||
939 | { | 944 | { |
940 | int ret = 0; | 945 | int ret = 0; |
941 | struct tc_action *act; | 946 | struct tc_action *act; |
@@ -953,7 +958,7 @@ tcf_action_add(struct nlattr *nla, struct nlmsghdr *n, u32 pid, int ovr) | |||
953 | /* dump then free all the actions after update; inserted policy | 958 | /* dump then free all the actions after update; inserted policy |
954 | * stays intact | 959 | * stays intact |
955 | * */ | 960 | * */ |
956 | ret = tcf_add_notify(act, pid, seq, RTM_NEWACTION, n->nlmsg_flags); | 961 | ret = tcf_add_notify(net, act, pid, seq, RTM_NEWACTION, n->nlmsg_flags); |
957 | for (a = act; a; a = act) { | 962 | for (a = act; a; a = act) { |
958 | act = a->next; | 963 | act = a->next; |
959 | kfree(a); | 964 | kfree(a); |
@@ -969,9 +974,6 @@ static int tc_ctl_action(struct sk_buff *skb, struct nlmsghdr *n, void *arg) | |||
969 | u32 pid = skb ? NETLINK_CB(skb).pid : 0; | 974 | u32 pid = skb ? NETLINK_CB(skb).pid : 0; |
970 | int ret = 0, ovr = 0; | 975 | int ret = 0, ovr = 0; |
971 | 976 | ||
972 | if (!net_eq(net, &init_net)) | ||
973 | return -EINVAL; | ||
974 | |||
975 | ret = nlmsg_parse(n, sizeof(struct tcamsg), tca, TCA_ACT_MAX, NULL); | 977 | ret = nlmsg_parse(n, sizeof(struct tcamsg), tca, TCA_ACT_MAX, NULL); |
976 | if (ret < 0) | 978 | if (ret < 0) |
977 | return ret; | 979 | return ret; |
@@ -994,15 +996,17 @@ static int tc_ctl_action(struct sk_buff *skb, struct nlmsghdr *n, void *arg) | |||
994 | if (n->nlmsg_flags&NLM_F_REPLACE) | 996 | if (n->nlmsg_flags&NLM_F_REPLACE) |
995 | ovr = 1; | 997 | ovr = 1; |
996 | replay: | 998 | replay: |
997 | ret = tcf_action_add(tca[TCA_ACT_TAB], n, pid, ovr); | 999 | ret = tcf_action_add(net, tca[TCA_ACT_TAB], n, pid, ovr); |
998 | if (ret == -EAGAIN) | 1000 | if (ret == -EAGAIN) |
999 | goto replay; | 1001 | goto replay; |
1000 | break; | 1002 | break; |
1001 | case RTM_DELACTION: | 1003 | case RTM_DELACTION: |
1002 | ret = tca_action_gd(tca[TCA_ACT_TAB], n, pid, RTM_DELACTION); | 1004 | ret = tca_action_gd(net, tca[TCA_ACT_TAB], n, |
1005 | pid, RTM_DELACTION); | ||
1003 | break; | 1006 | break; |
1004 | case RTM_GETACTION: | 1007 | case RTM_GETACTION: |
1005 | ret = tca_action_gd(tca[TCA_ACT_TAB], n, pid, RTM_GETACTION); | 1008 | ret = tca_action_gd(net, tca[TCA_ACT_TAB], n, |
1009 | pid, RTM_GETACTION); | ||
1006 | break; | 1010 | break; |
1007 | default: | 1011 | default: |
1008 | BUG(); | 1012 | BUG(); |
@@ -1042,7 +1046,6 @@ find_dump_kind(const struct nlmsghdr *n) | |||
1042 | static int | 1046 | static int |
1043 | tc_dump_action(struct sk_buff *skb, struct netlink_callback *cb) | 1047 | tc_dump_action(struct sk_buff *skb, struct netlink_callback *cb) |
1044 | { | 1048 | { |
1045 | struct net *net = sock_net(skb->sk); | ||
1046 | struct nlmsghdr *nlh; | 1049 | struct nlmsghdr *nlh; |
1047 | unsigned char *b = skb_tail_pointer(skb); | 1050 | unsigned char *b = skb_tail_pointer(skb); |
1048 | struct nlattr *nest; | 1051 | struct nlattr *nest; |
@@ -1052,9 +1055,6 @@ tc_dump_action(struct sk_buff *skb, struct netlink_callback *cb) | |||
1052 | struct tcamsg *t = (struct tcamsg *) NLMSG_DATA(cb->nlh); | 1055 | struct tcamsg *t = (struct tcamsg *) NLMSG_DATA(cb->nlh); |
1053 | struct nlattr *kind = find_dump_kind(cb->nlh); | 1056 | struct nlattr *kind = find_dump_kind(cb->nlh); |
1054 | 1057 | ||
1055 | if (!net_eq(net, &init_net)) | ||
1056 | return 0; | ||
1057 | |||
1058 | if (kind == NULL) { | 1058 | if (kind == NULL) { |
1059 | printk("tc_dump_action: action bad kind\n"); | 1059 | printk("tc_dump_action: action bad kind\n"); |
1060 | return 0; | 1060 | return 0; |
diff --git a/net/sched/act_ipt.c b/net/sched/act_ipt.c index 082c520b0def..da27a170b6b7 100644 --- a/net/sched/act_ipt.c +++ b/net/sched/act_ipt.c | |||
@@ -19,6 +19,7 @@ | |||
19 | #include <linux/rtnetlink.h> | 19 | #include <linux/rtnetlink.h> |
20 | #include <linux/module.h> | 20 | #include <linux/module.h> |
21 | #include <linux/init.h> | 21 | #include <linux/init.h> |
22 | #include <linux/slab.h> | ||
22 | #include <net/netlink.h> | 23 | #include <net/netlink.h> |
23 | #include <net/pkt_sched.h> | 24 | #include <net/pkt_sched.h> |
24 | #include <linux/tc_act/tc_ipt.h> | 25 | #include <linux/tc_act/tc_ipt.h> |
diff --git a/net/sched/act_mirred.c b/net/sched/act_mirred.c index d329170243cb..c046682054eb 100644 --- a/net/sched/act_mirred.c +++ b/net/sched/act_mirred.c | |||
@@ -20,6 +20,7 @@ | |||
20 | #include <linux/rtnetlink.h> | 20 | #include <linux/rtnetlink.h> |
21 | #include <linux/module.h> | 21 | #include <linux/module.h> |
22 | #include <linux/init.h> | 22 | #include <linux/init.h> |
23 | #include <linux/gfp.h> | ||
23 | #include <net/net_namespace.h> | 24 | #include <net/net_namespace.h> |
24 | #include <net/netlink.h> | 25 | #include <net/netlink.h> |
25 | #include <net/pkt_sched.h> | 26 | #include <net/pkt_sched.h> |
diff --git a/net/sched/act_pedit.c b/net/sched/act_pedit.c index 6b0359a500e6..b7dcfedc802e 100644 --- a/net/sched/act_pedit.c +++ b/net/sched/act_pedit.c | |||
@@ -17,6 +17,7 @@ | |||
17 | #include <linux/rtnetlink.h> | 17 | #include <linux/rtnetlink.h> |
18 | #include <linux/module.h> | 18 | #include <linux/module.h> |
19 | #include <linux/init.h> | 19 | #include <linux/init.h> |
20 | #include <linux/slab.h> | ||
20 | #include <net/netlink.h> | 21 | #include <net/netlink.h> |
21 | #include <net/pkt_sched.h> | 22 | #include <net/pkt_sched.h> |
22 | #include <linux/tc_act/tc_pedit.h> | 23 | #include <linux/tc_act/tc_pedit.h> |
diff --git a/net/sched/act_police.c b/net/sched/act_police.c index 723964c3ee4f..654f73dff7c1 100644 --- a/net/sched/act_police.c +++ b/net/sched/act_police.c | |||
@@ -18,6 +18,7 @@ | |||
18 | #include <linux/skbuff.h> | 18 | #include <linux/skbuff.h> |
19 | #include <linux/rtnetlink.h> | 19 | #include <linux/rtnetlink.h> |
20 | #include <linux/init.h> | 20 | #include <linux/init.h> |
21 | #include <linux/slab.h> | ||
21 | #include <net/act_api.h> | 22 | #include <net/act_api.h> |
22 | #include <net/netlink.h> | 23 | #include <net/netlink.h> |
23 | 24 | ||
diff --git a/net/sched/act_simple.c b/net/sched/act_simple.c index 8daa1ebc7413..622ca809c15c 100644 --- a/net/sched/act_simple.c +++ b/net/sched/act_simple.c | |||
@@ -11,6 +11,7 @@ | |||
11 | */ | 11 | */ |
12 | 12 | ||
13 | #include <linux/module.h> | 13 | #include <linux/module.h> |
14 | #include <linux/slab.h> | ||
14 | #include <linux/init.h> | 15 | #include <linux/init.h> |
15 | #include <linux/kernel.h> | 16 | #include <linux/kernel.h> |
16 | #include <linux/skbuff.h> | 17 | #include <linux/skbuff.h> |
diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c index 3725d8fa29db..5fd0c28ef79a 100644 --- a/net/sched/cls_api.c +++ b/net/sched/cls_api.c | |||
@@ -24,6 +24,7 @@ | |||
24 | #include <linux/kmod.h> | 24 | #include <linux/kmod.h> |
25 | #include <linux/netlink.h> | 25 | #include <linux/netlink.h> |
26 | #include <linux/err.h> | 26 | #include <linux/err.h> |
27 | #include <linux/slab.h> | ||
27 | #include <net/net_namespace.h> | 28 | #include <net/net_namespace.h> |
28 | #include <net/sock.h> | 29 | #include <net/sock.h> |
29 | #include <net/netlink.h> | 30 | #include <net/netlink.h> |
@@ -98,8 +99,9 @@ out: | |||
98 | } | 99 | } |
99 | EXPORT_SYMBOL(unregister_tcf_proto_ops); | 100 | EXPORT_SYMBOL(unregister_tcf_proto_ops); |
100 | 101 | ||
101 | static int tfilter_notify(struct sk_buff *oskb, struct nlmsghdr *n, | 102 | static int tfilter_notify(struct net *net, struct sk_buff *oskb, |
102 | struct tcf_proto *tp, unsigned long fh, int event); | 103 | struct nlmsghdr *n, struct tcf_proto *tp, |
104 | unsigned long fh, int event); | ||
103 | 105 | ||
104 | 106 | ||
105 | /* Select new prio value from the range, managed by kernel. */ | 107 | /* Select new prio value from the range, managed by kernel. */ |
@@ -137,9 +139,6 @@ static int tc_ctl_tfilter(struct sk_buff *skb, struct nlmsghdr *n, void *arg) | |||
137 | int err; | 139 | int err; |
138 | int tp_created = 0; | 140 | int tp_created = 0; |
139 | 141 | ||
140 | if (!net_eq(net, &init_net)) | ||
141 | return -EINVAL; | ||
142 | |||
143 | replay: | 142 | replay: |
144 | t = NLMSG_DATA(n); | 143 | t = NLMSG_DATA(n); |
145 | protocol = TC_H_MIN(t->tcm_info); | 144 | protocol = TC_H_MIN(t->tcm_info); |
@@ -158,7 +157,7 @@ replay: | |||
158 | /* Find head of filter chain. */ | 157 | /* Find head of filter chain. */ |
159 | 158 | ||
160 | /* Find link */ | 159 | /* Find link */ |
161 | dev = __dev_get_by_index(&init_net, t->tcm_ifindex); | 160 | dev = __dev_get_by_index(net, t->tcm_ifindex); |
162 | if (dev == NULL) | 161 | if (dev == NULL) |
163 | return -ENODEV; | 162 | return -ENODEV; |
164 | 163 | ||
@@ -282,7 +281,7 @@ replay: | |||
282 | *back = tp->next; | 281 | *back = tp->next; |
283 | spin_unlock_bh(root_lock); | 282 | spin_unlock_bh(root_lock); |
284 | 283 | ||
285 | tfilter_notify(skb, n, tp, fh, RTM_DELTFILTER); | 284 | tfilter_notify(net, skb, n, tp, fh, RTM_DELTFILTER); |
286 | tcf_destroy(tp); | 285 | tcf_destroy(tp); |
287 | err = 0; | 286 | err = 0; |
288 | goto errout; | 287 | goto errout; |
@@ -305,10 +304,10 @@ replay: | |||
305 | case RTM_DELTFILTER: | 304 | case RTM_DELTFILTER: |
306 | err = tp->ops->delete(tp, fh); | 305 | err = tp->ops->delete(tp, fh); |
307 | if (err == 0) | 306 | if (err == 0) |
308 | tfilter_notify(skb, n, tp, fh, RTM_DELTFILTER); | 307 | tfilter_notify(net, skb, n, tp, fh, RTM_DELTFILTER); |
309 | goto errout; | 308 | goto errout; |
310 | case RTM_GETTFILTER: | 309 | case RTM_GETTFILTER: |
311 | err = tfilter_notify(skb, n, tp, fh, RTM_NEWTFILTER); | 310 | err = tfilter_notify(net, skb, n, tp, fh, RTM_NEWTFILTER); |
312 | goto errout; | 311 | goto errout; |
313 | default: | 312 | default: |
314 | err = -EINVAL; | 313 | err = -EINVAL; |
@@ -324,7 +323,7 @@ replay: | |||
324 | *back = tp; | 323 | *back = tp; |
325 | spin_unlock_bh(root_lock); | 324 | spin_unlock_bh(root_lock); |
326 | } | 325 | } |
327 | tfilter_notify(skb, n, tp, fh, RTM_NEWTFILTER); | 326 | tfilter_notify(net, skb, n, tp, fh, RTM_NEWTFILTER); |
328 | } else { | 327 | } else { |
329 | if (tp_created) | 328 | if (tp_created) |
330 | tcf_destroy(tp); | 329 | tcf_destroy(tp); |
@@ -370,8 +369,9 @@ nla_put_failure: | |||
370 | return -1; | 369 | return -1; |
371 | } | 370 | } |
372 | 371 | ||
373 | static int tfilter_notify(struct sk_buff *oskb, struct nlmsghdr *n, | 372 | static int tfilter_notify(struct net *net, struct sk_buff *oskb, |
374 | struct tcf_proto *tp, unsigned long fh, int event) | 373 | struct nlmsghdr *n, struct tcf_proto *tp, |
374 | unsigned long fh, int event) | ||
375 | { | 375 | { |
376 | struct sk_buff *skb; | 376 | struct sk_buff *skb; |
377 | u32 pid = oskb ? NETLINK_CB(oskb).pid : 0; | 377 | u32 pid = oskb ? NETLINK_CB(oskb).pid : 0; |
@@ -385,7 +385,7 @@ static int tfilter_notify(struct sk_buff *oskb, struct nlmsghdr *n, | |||
385 | return -EINVAL; | 385 | return -EINVAL; |
386 | } | 386 | } |
387 | 387 | ||
388 | return rtnetlink_send(skb, &init_net, pid, RTNLGRP_TC, | 388 | return rtnetlink_send(skb, net, pid, RTNLGRP_TC, |
389 | n->nlmsg_flags & NLM_F_ECHO); | 389 | n->nlmsg_flags & NLM_F_ECHO); |
390 | } | 390 | } |
391 | 391 | ||
@@ -418,12 +418,9 @@ static int tc_dump_tfilter(struct sk_buff *skb, struct netlink_callback *cb) | |||
418 | const struct Qdisc_class_ops *cops; | 418 | const struct Qdisc_class_ops *cops; |
419 | struct tcf_dump_args arg; | 419 | struct tcf_dump_args arg; |
420 | 420 | ||
421 | if (!net_eq(net, &init_net)) | ||
422 | return 0; | ||
423 | |||
424 | if (cb->nlh->nlmsg_len < NLMSG_LENGTH(sizeof(*tcm))) | 421 | if (cb->nlh->nlmsg_len < NLMSG_LENGTH(sizeof(*tcm))) |
425 | return skb->len; | 422 | return skb->len; |
426 | if ((dev = __dev_get_by_index(&init_net, tcm->tcm_ifindex)) == NULL) | 423 | if ((dev = __dev_get_by_index(net, tcm->tcm_ifindex)) == NULL) |
427 | return skb->len; | 424 | return skb->len; |
428 | 425 | ||
429 | if (!tcm->tcm_parent) | 426 | if (!tcm->tcm_parent) |
diff --git a/net/sched/cls_basic.c b/net/sched/cls_basic.c index 4e2bda854119..efd4f95fd050 100644 --- a/net/sched/cls_basic.c +++ b/net/sched/cls_basic.c | |||
@@ -10,6 +10,7 @@ | |||
10 | */ | 10 | */ |
11 | 11 | ||
12 | #include <linux/module.h> | 12 | #include <linux/module.h> |
13 | #include <linux/slab.h> | ||
13 | #include <linux/types.h> | 14 | #include <linux/types.h> |
14 | #include <linux/kernel.h> | 15 | #include <linux/kernel.h> |
15 | #include <linux/string.h> | 16 | #include <linux/string.h> |
diff --git a/net/sched/cls_cgroup.c b/net/sched/cls_cgroup.c index e4877ca6727c..221180384fd7 100644 --- a/net/sched/cls_cgroup.c +++ b/net/sched/cls_cgroup.c | |||
@@ -10,6 +10,7 @@ | |||
10 | */ | 10 | */ |
11 | 11 | ||
12 | #include <linux/module.h> | 12 | #include <linux/module.h> |
13 | #include <linux/slab.h> | ||
13 | #include <linux/types.h> | 14 | #include <linux/types.h> |
14 | #include <linux/string.h> | 15 | #include <linux/string.h> |
15 | #include <linux/errno.h> | 16 | #include <linux/errno.h> |
@@ -24,6 +25,25 @@ struct cgroup_cls_state | |||
24 | u32 classid; | 25 | u32 classid; |
25 | }; | 26 | }; |
26 | 27 | ||
28 | static struct cgroup_subsys_state *cgrp_create(struct cgroup_subsys *ss, | ||
29 | struct cgroup *cgrp); | ||
30 | static void cgrp_destroy(struct cgroup_subsys *ss, struct cgroup *cgrp); | ||
31 | static int cgrp_populate(struct cgroup_subsys *ss, struct cgroup *cgrp); | ||
32 | |||
33 | struct cgroup_subsys net_cls_subsys = { | ||
34 | .name = "net_cls", | ||
35 | .create = cgrp_create, | ||
36 | .destroy = cgrp_destroy, | ||
37 | .populate = cgrp_populate, | ||
38 | #ifdef CONFIG_NET_CLS_CGROUP | ||
39 | .subsys_id = net_cls_subsys_id, | ||
40 | #else | ||
41 | #define net_cls_subsys_id net_cls_subsys.subsys_id | ||
42 | #endif | ||
43 | .module = THIS_MODULE, | ||
44 | }; | ||
45 | |||
46 | |||
27 | static inline struct cgroup_cls_state *cgrp_cls_state(struct cgroup *cgrp) | 47 | static inline struct cgroup_cls_state *cgrp_cls_state(struct cgroup *cgrp) |
28 | { | 48 | { |
29 | return container_of(cgroup_subsys_state(cgrp, net_cls_subsys_id), | 49 | return container_of(cgroup_subsys_state(cgrp, net_cls_subsys_id), |
@@ -79,14 +99,6 @@ static int cgrp_populate(struct cgroup_subsys *ss, struct cgroup *cgrp) | |||
79 | return cgroup_add_files(cgrp, ss, ss_files, ARRAY_SIZE(ss_files)); | 99 | return cgroup_add_files(cgrp, ss, ss_files, ARRAY_SIZE(ss_files)); |
80 | } | 100 | } |
81 | 101 | ||
82 | struct cgroup_subsys net_cls_subsys = { | ||
83 | .name = "net_cls", | ||
84 | .create = cgrp_create, | ||
85 | .destroy = cgrp_destroy, | ||
86 | .populate = cgrp_populate, | ||
87 | .subsys_id = net_cls_subsys_id, | ||
88 | }; | ||
89 | |||
90 | struct cls_cgroup_head | 102 | struct cls_cgroup_head |
91 | { | 103 | { |
92 | u32 handle; | 104 | u32 handle; |
@@ -277,12 +289,19 @@ static struct tcf_proto_ops cls_cgroup_ops __read_mostly = { | |||
277 | 289 | ||
278 | static int __init init_cgroup_cls(void) | 290 | static int __init init_cgroup_cls(void) |
279 | { | 291 | { |
280 | return register_tcf_proto_ops(&cls_cgroup_ops); | 292 | int ret = register_tcf_proto_ops(&cls_cgroup_ops); |
293 | if (ret) | ||
294 | return ret; | ||
295 | ret = cgroup_load_subsys(&net_cls_subsys); | ||
296 | if (ret) | ||
297 | unregister_tcf_proto_ops(&cls_cgroup_ops); | ||
298 | return ret; | ||
281 | } | 299 | } |
282 | 300 | ||
283 | static void __exit exit_cgroup_cls(void) | 301 | static void __exit exit_cgroup_cls(void) |
284 | { | 302 | { |
285 | unregister_tcf_proto_ops(&cls_cgroup_ops); | 303 | unregister_tcf_proto_ops(&cls_cgroup_ops); |
304 | cgroup_unload_subsys(&net_cls_subsys); | ||
286 | } | 305 | } |
287 | 306 | ||
288 | module_init(init_cgroup_cls); | 307 | module_init(init_cgroup_cls); |
diff --git a/net/sched/cls_flow.c b/net/sched/cls_flow.c index e054c62857e1..6ed61b10e002 100644 --- a/net/sched/cls_flow.c +++ b/net/sched/cls_flow.c | |||
@@ -20,6 +20,7 @@ | |||
20 | #include <linux/ip.h> | 20 | #include <linux/ip.h> |
21 | #include <linux/ipv6.h> | 21 | #include <linux/ipv6.h> |
22 | #include <linux/if_vlan.h> | 22 | #include <linux/if_vlan.h> |
23 | #include <linux/slab.h> | ||
23 | 24 | ||
24 | #include <net/pkt_cls.h> | 25 | #include <net/pkt_cls.h> |
25 | #include <net/ip.h> | 26 | #include <net/ip.h> |
diff --git a/net/sched/cls_fw.c b/net/sched/cls_fw.c index 6d6e87585fb1..93b0a7b6f9b4 100644 --- a/net/sched/cls_fw.c +++ b/net/sched/cls_fw.c | |||
@@ -19,6 +19,7 @@ | |||
19 | */ | 19 | */ |
20 | 20 | ||
21 | #include <linux/module.h> | 21 | #include <linux/module.h> |
22 | #include <linux/slab.h> | ||
22 | #include <linux/types.h> | 23 | #include <linux/types.h> |
23 | #include <linux/kernel.h> | 24 | #include <linux/kernel.h> |
24 | #include <linux/string.h> | 25 | #include <linux/string.h> |
diff --git a/net/sched/cls_route.c b/net/sched/cls_route.c index dd872d5383ef..694dcd85dec8 100644 --- a/net/sched/cls_route.c +++ b/net/sched/cls_route.c | |||
@@ -10,6 +10,7 @@ | |||
10 | */ | 10 | */ |
11 | 11 | ||
12 | #include <linux/module.h> | 12 | #include <linux/module.h> |
13 | #include <linux/slab.h> | ||
13 | #include <linux/types.h> | 14 | #include <linux/types.h> |
14 | #include <linux/kernel.h> | 15 | #include <linux/kernel.h> |
15 | #include <linux/string.h> | 16 | #include <linux/string.h> |
diff --git a/net/sched/cls_tcindex.c b/net/sched/cls_tcindex.c index e806f2314b5e..20ef330bb918 100644 --- a/net/sched/cls_tcindex.c +++ b/net/sched/cls_tcindex.c | |||
@@ -9,6 +9,7 @@ | |||
9 | #include <linux/kernel.h> | 9 | #include <linux/kernel.h> |
10 | #include <linux/skbuff.h> | 10 | #include <linux/skbuff.h> |
11 | #include <linux/errno.h> | 11 | #include <linux/errno.h> |
12 | #include <linux/slab.h> | ||
12 | #include <net/act_api.h> | 13 | #include <net/act_api.h> |
13 | #include <net/netlink.h> | 14 | #include <net/netlink.h> |
14 | #include <net/pkt_cls.h> | 15 | #include <net/pkt_cls.h> |
diff --git a/net/sched/cls_u32.c b/net/sched/cls_u32.c index 07372f60bee3..593eac056e8d 100644 --- a/net/sched/cls_u32.c +++ b/net/sched/cls_u32.c | |||
@@ -31,6 +31,7 @@ | |||
31 | */ | 31 | */ |
32 | 32 | ||
33 | #include <linux/module.h> | 33 | #include <linux/module.h> |
34 | #include <linux/slab.h> | ||
34 | #include <linux/types.h> | 35 | #include <linux/types.h> |
35 | #include <linux/kernel.h> | 36 | #include <linux/kernel.h> |
36 | #include <linux/string.h> | 37 | #include <linux/string.h> |
@@ -772,10 +773,10 @@ static int __init init_u32(void) | |||
772 | printk(" Performance counters on\n"); | 773 | printk(" Performance counters on\n"); |
773 | #endif | 774 | #endif |
774 | #ifdef CONFIG_NET_CLS_IND | 775 | #ifdef CONFIG_NET_CLS_IND |
775 | printk(" input device check on \n"); | 776 | printk(" input device check on\n"); |
776 | #endif | 777 | #endif |
777 | #ifdef CONFIG_NET_CLS_ACT | 778 | #ifdef CONFIG_NET_CLS_ACT |
778 | printk(" Actions configured \n"); | 779 | printk(" Actions configured\n"); |
779 | #endif | 780 | #endif |
780 | return register_tcf_proto_ops(&cls_u32_ops); | 781 | return register_tcf_proto_ops(&cls_u32_ops); |
781 | } | 782 | } |
diff --git a/net/sched/em_meta.c b/net/sched/em_meta.c index 24dce8b648a4..3bcac8aa333c 100644 --- a/net/sched/em_meta.c +++ b/net/sched/em_meta.c | |||
@@ -58,6 +58,7 @@ | |||
58 | * only available if that subsystem is enabled in the kernel. | 58 | * only available if that subsystem is enabled in the kernel. |
59 | */ | 59 | */ |
60 | 60 | ||
61 | #include <linux/slab.h> | ||
61 | #include <linux/module.h> | 62 | #include <linux/module.h> |
62 | #include <linux/types.h> | 63 | #include <linux/types.h> |
63 | #include <linux/kernel.h> | 64 | #include <linux/kernel.h> |
diff --git a/net/sched/em_nbyte.c b/net/sched/em_nbyte.c index 370a1b2ea317..1a4176aee6e5 100644 --- a/net/sched/em_nbyte.c +++ b/net/sched/em_nbyte.c | |||
@@ -9,6 +9,7 @@ | |||
9 | * Authors: Thomas Graf <tgraf@suug.ch> | 9 | * Authors: Thomas Graf <tgraf@suug.ch> |
10 | */ | 10 | */ |
11 | 11 | ||
12 | #include <linux/gfp.h> | ||
12 | #include <linux/module.h> | 13 | #include <linux/module.h> |
13 | #include <linux/types.h> | 14 | #include <linux/types.h> |
14 | #include <linux/kernel.h> | 15 | #include <linux/kernel.h> |
diff --git a/net/sched/em_text.c b/net/sched/em_text.c index 853c5ead87fd..763253257411 100644 --- a/net/sched/em_text.c +++ b/net/sched/em_text.c | |||
@@ -9,6 +9,7 @@ | |||
9 | * Authors: Thomas Graf <tgraf@suug.ch> | 9 | * Authors: Thomas Graf <tgraf@suug.ch> |
10 | */ | 10 | */ |
11 | 11 | ||
12 | #include <linux/slab.h> | ||
12 | #include <linux/module.h> | 13 | #include <linux/module.h> |
13 | #include <linux/types.h> | 14 | #include <linux/types.h> |
14 | #include <linux/kernel.h> | 15 | #include <linux/kernel.h> |
diff --git a/net/sched/ematch.c b/net/sched/ematch.c index aab59409728b..e782bdeedc58 100644 --- a/net/sched/ematch.c +++ b/net/sched/ematch.c | |||
@@ -82,6 +82,7 @@ | |||
82 | */ | 82 | */ |
83 | 83 | ||
84 | #include <linux/module.h> | 84 | #include <linux/module.h> |
85 | #include <linux/slab.h> | ||
85 | #include <linux/types.h> | 86 | #include <linux/types.h> |
86 | #include <linux/kernel.h> | 87 | #include <linux/kernel.h> |
87 | #include <linux/errno.h> | 88 | #include <linux/errno.h> |
diff --git a/net/sched/sch_api.c b/net/sched/sch_api.c index 6cd491013b50..9839b26674f4 100644 --- a/net/sched/sch_api.c +++ b/net/sched/sch_api.c | |||
@@ -28,16 +28,19 @@ | |||
28 | #include <linux/list.h> | 28 | #include <linux/list.h> |
29 | #include <linux/hrtimer.h> | 29 | #include <linux/hrtimer.h> |
30 | #include <linux/lockdep.h> | 30 | #include <linux/lockdep.h> |
31 | #include <linux/slab.h> | ||
31 | 32 | ||
32 | #include <net/net_namespace.h> | 33 | #include <net/net_namespace.h> |
33 | #include <net/sock.h> | 34 | #include <net/sock.h> |
34 | #include <net/netlink.h> | 35 | #include <net/netlink.h> |
35 | #include <net/pkt_sched.h> | 36 | #include <net/pkt_sched.h> |
36 | 37 | ||
37 | static int qdisc_notify(struct sk_buff *oskb, struct nlmsghdr *n, u32 clid, | 38 | static int qdisc_notify(struct net *net, struct sk_buff *oskb, |
39 | struct nlmsghdr *n, u32 clid, | ||
38 | struct Qdisc *old, struct Qdisc *new); | 40 | struct Qdisc *old, struct Qdisc *new); |
39 | static int tclass_notify(struct sk_buff *oskb, struct nlmsghdr *n, | 41 | static int tclass_notify(struct net *net, struct sk_buff *oskb, |
40 | struct Qdisc *q, unsigned long cl, int event); | 42 | struct nlmsghdr *n, struct Qdisc *q, |
43 | unsigned long cl, int event); | ||
41 | 44 | ||
42 | /* | 45 | /* |
43 | 46 | ||
@@ -638,11 +641,12 @@ void qdisc_tree_decrease_qlen(struct Qdisc *sch, unsigned int n) | |||
638 | } | 641 | } |
639 | EXPORT_SYMBOL(qdisc_tree_decrease_qlen); | 642 | EXPORT_SYMBOL(qdisc_tree_decrease_qlen); |
640 | 643 | ||
641 | static void notify_and_destroy(struct sk_buff *skb, struct nlmsghdr *n, u32 clid, | 644 | static void notify_and_destroy(struct net *net, struct sk_buff *skb, |
645 | struct nlmsghdr *n, u32 clid, | ||
642 | struct Qdisc *old, struct Qdisc *new) | 646 | struct Qdisc *old, struct Qdisc *new) |
643 | { | 647 | { |
644 | if (new || old) | 648 | if (new || old) |
645 | qdisc_notify(skb, n, clid, old, new); | 649 | qdisc_notify(net, skb, n, clid, old, new); |
646 | 650 | ||
647 | if (old) | 651 | if (old) |
648 | qdisc_destroy(old); | 652 | qdisc_destroy(old); |
@@ -662,6 +666,7 @@ static int qdisc_graft(struct net_device *dev, struct Qdisc *parent, | |||
662 | struct Qdisc *new, struct Qdisc *old) | 666 | struct Qdisc *new, struct Qdisc *old) |
663 | { | 667 | { |
664 | struct Qdisc *q = old; | 668 | struct Qdisc *q = old; |
669 | struct net *net = dev_net(dev); | ||
665 | int err = 0; | 670 | int err = 0; |
666 | 671 | ||
667 | if (parent == NULL) { | 672 | if (parent == NULL) { |
@@ -698,12 +703,13 @@ static int qdisc_graft(struct net_device *dev, struct Qdisc *parent, | |||
698 | } | 703 | } |
699 | 704 | ||
700 | if (!ingress) { | 705 | if (!ingress) { |
701 | notify_and_destroy(skb, n, classid, dev->qdisc, new); | 706 | notify_and_destroy(net, skb, n, classid, |
707 | dev->qdisc, new); | ||
702 | if (new && !new->ops->attach) | 708 | if (new && !new->ops->attach) |
703 | atomic_inc(&new->refcnt); | 709 | atomic_inc(&new->refcnt); |
704 | dev->qdisc = new ? : &noop_qdisc; | 710 | dev->qdisc = new ? : &noop_qdisc; |
705 | } else { | 711 | } else { |
706 | notify_and_destroy(skb, n, classid, old, new); | 712 | notify_and_destroy(net, skb, n, classid, old, new); |
707 | } | 713 | } |
708 | 714 | ||
709 | if (dev->flags & IFF_UP) | 715 | if (dev->flags & IFF_UP) |
@@ -721,7 +727,7 @@ static int qdisc_graft(struct net_device *dev, struct Qdisc *parent, | |||
721 | err = -ENOENT; | 727 | err = -ENOENT; |
722 | } | 728 | } |
723 | if (!err) | 729 | if (!err) |
724 | notify_and_destroy(skb, n, classid, old, new); | 730 | notify_and_destroy(net, skb, n, classid, old, new); |
725 | } | 731 | } |
726 | return err; | 732 | return err; |
727 | } | 733 | } |
@@ -947,10 +953,7 @@ static int tc_get_qdisc(struct sk_buff *skb, struct nlmsghdr *n, void *arg) | |||
947 | struct Qdisc *p = NULL; | 953 | struct Qdisc *p = NULL; |
948 | int err; | 954 | int err; |
949 | 955 | ||
950 | if (!net_eq(net, &init_net)) | 956 | if ((dev = __dev_get_by_index(net, tcm->tcm_ifindex)) == NULL) |
951 | return -EINVAL; | ||
952 | |||
953 | if ((dev = __dev_get_by_index(&init_net, tcm->tcm_ifindex)) == NULL) | ||
954 | return -ENODEV; | 957 | return -ENODEV; |
955 | 958 | ||
956 | err = nlmsg_parse(n, sizeof(*tcm), tca, TCA_MAX, NULL); | 959 | err = nlmsg_parse(n, sizeof(*tcm), tca, TCA_MAX, NULL); |
@@ -990,7 +993,7 @@ static int tc_get_qdisc(struct sk_buff *skb, struct nlmsghdr *n, void *arg) | |||
990 | if ((err = qdisc_graft(dev, p, skb, n, clid, NULL, q)) != 0) | 993 | if ((err = qdisc_graft(dev, p, skb, n, clid, NULL, q)) != 0) |
991 | return err; | 994 | return err; |
992 | } else { | 995 | } else { |
993 | qdisc_notify(skb, n, clid, NULL, q); | 996 | qdisc_notify(net, skb, n, clid, NULL, q); |
994 | } | 997 | } |
995 | return 0; | 998 | return 0; |
996 | } | 999 | } |
@@ -1009,16 +1012,13 @@ static int tc_modify_qdisc(struct sk_buff *skb, struct nlmsghdr *n, void *arg) | |||
1009 | struct Qdisc *q, *p; | 1012 | struct Qdisc *q, *p; |
1010 | int err; | 1013 | int err; |
1011 | 1014 | ||
1012 | if (!net_eq(net, &init_net)) | ||
1013 | return -EINVAL; | ||
1014 | |||
1015 | replay: | 1015 | replay: |
1016 | /* Reinit, just in case something touches this. */ | 1016 | /* Reinit, just in case something touches this. */ |
1017 | tcm = NLMSG_DATA(n); | 1017 | tcm = NLMSG_DATA(n); |
1018 | clid = tcm->tcm_parent; | 1018 | clid = tcm->tcm_parent; |
1019 | q = p = NULL; | 1019 | q = p = NULL; |
1020 | 1020 | ||
1021 | if ((dev = __dev_get_by_index(&init_net, tcm->tcm_ifindex)) == NULL) | 1021 | if ((dev = __dev_get_by_index(net, tcm->tcm_ifindex)) == NULL) |
1022 | return -ENODEV; | 1022 | return -ENODEV; |
1023 | 1023 | ||
1024 | err = nlmsg_parse(n, sizeof(*tcm), tca, TCA_MAX, NULL); | 1024 | err = nlmsg_parse(n, sizeof(*tcm), tca, TCA_MAX, NULL); |
@@ -1105,7 +1105,7 @@ replay: | |||
1105 | return -EINVAL; | 1105 | return -EINVAL; |
1106 | err = qdisc_change(q, tca); | 1106 | err = qdisc_change(q, tca); |
1107 | if (err == 0) | 1107 | if (err == 0) |
1108 | qdisc_notify(skb, n, clid, NULL, q); | 1108 | qdisc_notify(net, skb, n, clid, NULL, q); |
1109 | return err; | 1109 | return err; |
1110 | 1110 | ||
1111 | create_n_graft: | 1111 | create_n_graft: |
@@ -1195,8 +1195,9 @@ nla_put_failure: | |||
1195 | return -1; | 1195 | return -1; |
1196 | } | 1196 | } |
1197 | 1197 | ||
1198 | static int qdisc_notify(struct sk_buff *oskb, struct nlmsghdr *n, | 1198 | static int qdisc_notify(struct net *net, struct sk_buff *oskb, |
1199 | u32 clid, struct Qdisc *old, struct Qdisc *new) | 1199 | struct nlmsghdr *n, u32 clid, |
1200 | struct Qdisc *old, struct Qdisc *new) | ||
1200 | { | 1201 | { |
1201 | struct sk_buff *skb; | 1202 | struct sk_buff *skb; |
1202 | u32 pid = oskb ? NETLINK_CB(oskb).pid : 0; | 1203 | u32 pid = oskb ? NETLINK_CB(oskb).pid : 0; |
@@ -1215,7 +1216,7 @@ static int qdisc_notify(struct sk_buff *oskb, struct nlmsghdr *n, | |||
1215 | } | 1216 | } |
1216 | 1217 | ||
1217 | if (skb->len) | 1218 | if (skb->len) |
1218 | return rtnetlink_send(skb, &init_net, pid, RTNLGRP_TC, n->nlmsg_flags&NLM_F_ECHO); | 1219 | return rtnetlink_send(skb, net, pid, RTNLGRP_TC, n->nlmsg_flags&NLM_F_ECHO); |
1219 | 1220 | ||
1220 | err_out: | 1221 | err_out: |
1221 | kfree_skb(skb); | 1222 | kfree_skb(skb); |
@@ -1274,15 +1275,12 @@ static int tc_dump_qdisc(struct sk_buff *skb, struct netlink_callback *cb) | |||
1274 | int s_idx, s_q_idx; | 1275 | int s_idx, s_q_idx; |
1275 | struct net_device *dev; | 1276 | struct net_device *dev; |
1276 | 1277 | ||
1277 | if (!net_eq(net, &init_net)) | ||
1278 | return 0; | ||
1279 | |||
1280 | s_idx = cb->args[0]; | 1278 | s_idx = cb->args[0]; |
1281 | s_q_idx = q_idx = cb->args[1]; | 1279 | s_q_idx = q_idx = cb->args[1]; |
1282 | 1280 | ||
1283 | rcu_read_lock(); | 1281 | rcu_read_lock(); |
1284 | idx = 0; | 1282 | idx = 0; |
1285 | for_each_netdev_rcu(&init_net, dev) { | 1283 | for_each_netdev_rcu(net, dev) { |
1286 | struct netdev_queue *dev_queue; | 1284 | struct netdev_queue *dev_queue; |
1287 | 1285 | ||
1288 | if (idx < s_idx) | 1286 | if (idx < s_idx) |
@@ -1334,10 +1332,7 @@ static int tc_ctl_tclass(struct sk_buff *skb, struct nlmsghdr *n, void *arg) | |||
1334 | u32 qid = TC_H_MAJ(clid); | 1332 | u32 qid = TC_H_MAJ(clid); |
1335 | int err; | 1333 | int err; |
1336 | 1334 | ||
1337 | if (!net_eq(net, &init_net)) | 1335 | if ((dev = __dev_get_by_index(net, tcm->tcm_ifindex)) == NULL) |
1338 | return -EINVAL; | ||
1339 | |||
1340 | if ((dev = __dev_get_by_index(&init_net, tcm->tcm_ifindex)) == NULL) | ||
1341 | return -ENODEV; | 1336 | return -ENODEV; |
1342 | 1337 | ||
1343 | err = nlmsg_parse(n, sizeof(*tcm), tca, TCA_MAX, NULL); | 1338 | err = nlmsg_parse(n, sizeof(*tcm), tca, TCA_MAX, NULL); |
@@ -1418,10 +1413,10 @@ static int tc_ctl_tclass(struct sk_buff *skb, struct nlmsghdr *n, void *arg) | |||
1418 | if (cops->delete) | 1413 | if (cops->delete) |
1419 | err = cops->delete(q, cl); | 1414 | err = cops->delete(q, cl); |
1420 | if (err == 0) | 1415 | if (err == 0) |
1421 | tclass_notify(skb, n, q, cl, RTM_DELTCLASS); | 1416 | tclass_notify(net, skb, n, q, cl, RTM_DELTCLASS); |
1422 | goto out; | 1417 | goto out; |
1423 | case RTM_GETTCLASS: | 1418 | case RTM_GETTCLASS: |
1424 | err = tclass_notify(skb, n, q, cl, RTM_NEWTCLASS); | 1419 | err = tclass_notify(net, skb, n, q, cl, RTM_NEWTCLASS); |
1425 | goto out; | 1420 | goto out; |
1426 | default: | 1421 | default: |
1427 | err = -EINVAL; | 1422 | err = -EINVAL; |
@@ -1434,7 +1429,7 @@ static int tc_ctl_tclass(struct sk_buff *skb, struct nlmsghdr *n, void *arg) | |||
1434 | if (cops->change) | 1429 | if (cops->change) |
1435 | err = cops->change(q, clid, pid, tca, &new_cl); | 1430 | err = cops->change(q, clid, pid, tca, &new_cl); |
1436 | if (err == 0) | 1431 | if (err == 0) |
1437 | tclass_notify(skb, n, q, new_cl, RTM_NEWTCLASS); | 1432 | tclass_notify(net, skb, n, q, new_cl, RTM_NEWTCLASS); |
1438 | 1433 | ||
1439 | out: | 1434 | out: |
1440 | if (cl) | 1435 | if (cl) |
@@ -1486,8 +1481,9 @@ nla_put_failure: | |||
1486 | return -1; | 1481 | return -1; |
1487 | } | 1482 | } |
1488 | 1483 | ||
1489 | static int tclass_notify(struct sk_buff *oskb, struct nlmsghdr *n, | 1484 | static int tclass_notify(struct net *net, struct sk_buff *oskb, |
1490 | struct Qdisc *q, unsigned long cl, int event) | 1485 | struct nlmsghdr *n, struct Qdisc *q, |
1486 | unsigned long cl, int event) | ||
1491 | { | 1487 | { |
1492 | struct sk_buff *skb; | 1488 | struct sk_buff *skb; |
1493 | u32 pid = oskb ? NETLINK_CB(oskb).pid : 0; | 1489 | u32 pid = oskb ? NETLINK_CB(oskb).pid : 0; |
@@ -1501,7 +1497,7 @@ static int tclass_notify(struct sk_buff *oskb, struct nlmsghdr *n, | |||
1501 | return -EINVAL; | 1497 | return -EINVAL; |
1502 | } | 1498 | } |
1503 | 1499 | ||
1504 | return rtnetlink_send(skb, &init_net, pid, RTNLGRP_TC, n->nlmsg_flags&NLM_F_ECHO); | 1500 | return rtnetlink_send(skb, net, pid, RTNLGRP_TC, n->nlmsg_flags&NLM_F_ECHO); |
1505 | } | 1501 | } |
1506 | 1502 | ||
1507 | struct qdisc_dump_args | 1503 | struct qdisc_dump_args |
@@ -1576,12 +1572,9 @@ static int tc_dump_tclass(struct sk_buff *skb, struct netlink_callback *cb) | |||
1576 | struct net_device *dev; | 1572 | struct net_device *dev; |
1577 | int t, s_t; | 1573 | int t, s_t; |
1578 | 1574 | ||
1579 | if (!net_eq(net, &init_net)) | ||
1580 | return 0; | ||
1581 | |||
1582 | if (cb->nlh->nlmsg_len < NLMSG_LENGTH(sizeof(*tcm))) | 1575 | if (cb->nlh->nlmsg_len < NLMSG_LENGTH(sizeof(*tcm))) |
1583 | return 0; | 1576 | return 0; |
1584 | if ((dev = dev_get_by_index(&init_net, tcm->tcm_ifindex)) == NULL) | 1577 | if ((dev = dev_get_by_index(net, tcm->tcm_ifindex)) == NULL) |
1585 | return 0; | 1578 | return 0; |
1586 | 1579 | ||
1587 | s_t = cb->args[0]; | 1580 | s_t = cb->args[0]; |
@@ -1691,7 +1684,7 @@ static int psched_show(struct seq_file *seq, void *v) | |||
1691 | 1684 | ||
1692 | static int psched_open(struct inode *inode, struct file *file) | 1685 | static int psched_open(struct inode *inode, struct file *file) |
1693 | { | 1686 | { |
1694 | return single_open(file, psched_show, PDE(inode)->data); | 1687 | return single_open(file, psched_show, NULL); |
1695 | } | 1688 | } |
1696 | 1689 | ||
1697 | static const struct file_operations psched_fops = { | 1690 | static const struct file_operations psched_fops = { |
@@ -1701,15 +1694,53 @@ static const struct file_operations psched_fops = { | |||
1701 | .llseek = seq_lseek, | 1694 | .llseek = seq_lseek, |
1702 | .release = single_release, | 1695 | .release = single_release, |
1703 | }; | 1696 | }; |
1697 | |||
1698 | static int __net_init psched_net_init(struct net *net) | ||
1699 | { | ||
1700 | struct proc_dir_entry *e; | ||
1701 | |||
1702 | e = proc_net_fops_create(net, "psched", 0, &psched_fops); | ||
1703 | if (e == NULL) | ||
1704 | return -ENOMEM; | ||
1705 | |||
1706 | return 0; | ||
1707 | } | ||
1708 | |||
1709 | static void __net_exit psched_net_exit(struct net *net) | ||
1710 | { | ||
1711 | proc_net_remove(net, "psched"); | ||
1712 | } | ||
1713 | #else | ||
1714 | static int __net_init psched_net_init(struct net *net) | ||
1715 | { | ||
1716 | return 0; | ||
1717 | } | ||
1718 | |||
1719 | static void __net_exit psched_net_exit(struct net *net) | ||
1720 | { | ||
1721 | } | ||
1704 | #endif | 1722 | #endif |
1705 | 1723 | ||
1724 | static struct pernet_operations psched_net_ops = { | ||
1725 | .init = psched_net_init, | ||
1726 | .exit = psched_net_exit, | ||
1727 | }; | ||
1728 | |||
1706 | static int __init pktsched_init(void) | 1729 | static int __init pktsched_init(void) |
1707 | { | 1730 | { |
1731 | int err; | ||
1732 | |||
1733 | err = register_pernet_subsys(&psched_net_ops); | ||
1734 | if (err) { | ||
1735 | printk(KERN_ERR "pktsched_init: " | ||
1736 | "cannot initialize per netns operations\n"); | ||
1737 | return err; | ||
1738 | } | ||
1739 | |||
1708 | register_qdisc(&pfifo_qdisc_ops); | 1740 | register_qdisc(&pfifo_qdisc_ops); |
1709 | register_qdisc(&bfifo_qdisc_ops); | 1741 | register_qdisc(&bfifo_qdisc_ops); |
1710 | register_qdisc(&pfifo_head_drop_qdisc_ops); | 1742 | register_qdisc(&pfifo_head_drop_qdisc_ops); |
1711 | register_qdisc(&mq_qdisc_ops); | 1743 | register_qdisc(&mq_qdisc_ops); |
1712 | proc_net_fops_create(&init_net, "psched", 0, &psched_fops); | ||
1713 | 1744 | ||
1714 | rtnl_register(PF_UNSPEC, RTM_NEWQDISC, tc_modify_qdisc, NULL); | 1745 | rtnl_register(PF_UNSPEC, RTM_NEWQDISC, tc_modify_qdisc, NULL); |
1715 | rtnl_register(PF_UNSPEC, RTM_DELQDISC, tc_get_qdisc, NULL); | 1746 | rtnl_register(PF_UNSPEC, RTM_DELQDISC, tc_get_qdisc, NULL); |
diff --git a/net/sched/sch_atm.c b/net/sched/sch_atm.c index ab82f145f689..fcbb86a486a2 100644 --- a/net/sched/sch_atm.c +++ b/net/sched/sch_atm.c | |||
@@ -3,6 +3,7 @@ | |||
3 | /* Written 1998-2000 by Werner Almesberger, EPFL ICA */ | 3 | /* Written 1998-2000 by Werner Almesberger, EPFL ICA */ |
4 | 4 | ||
5 | #include <linux/module.h> | 5 | #include <linux/module.h> |
6 | #include <linux/slab.h> | ||
6 | #include <linux/init.h> | 7 | #include <linux/init.h> |
7 | #include <linux/string.h> | 8 | #include <linux/string.h> |
8 | #include <linux/errno.h> | 9 | #include <linux/errno.h> |
diff --git a/net/sched/sch_cbq.c b/net/sched/sch_cbq.c index 3846d65bc03e..28c01ef5abc8 100644 --- a/net/sched/sch_cbq.c +++ b/net/sched/sch_cbq.c | |||
@@ -11,6 +11,7 @@ | |||
11 | */ | 11 | */ |
12 | 12 | ||
13 | #include <linux/module.h> | 13 | #include <linux/module.h> |
14 | #include <linux/slab.h> | ||
14 | #include <linux/types.h> | 15 | #include <linux/types.h> |
15 | #include <linux/kernel.h> | 16 | #include <linux/kernel.h> |
16 | #include <linux/string.h> | 17 | #include <linux/string.h> |
diff --git a/net/sched/sch_drr.c b/net/sched/sch_drr.c index a65604f8f2b8..b74046a95397 100644 --- a/net/sched/sch_drr.c +++ b/net/sched/sch_drr.c | |||
@@ -9,6 +9,7 @@ | |||
9 | */ | 9 | */ |
10 | 10 | ||
11 | #include <linux/module.h> | 11 | #include <linux/module.h> |
12 | #include <linux/slab.h> | ||
12 | #include <linux/init.h> | 13 | #include <linux/init.h> |
13 | #include <linux/errno.h> | 14 | #include <linux/errno.h> |
14 | #include <linux/netdevice.h> | 15 | #include <linux/netdevice.h> |
diff --git a/net/sched/sch_dsmark.c b/net/sched/sch_dsmark.c index d303daa45d49..63d41f86679c 100644 --- a/net/sched/sch_dsmark.c +++ b/net/sched/sch_dsmark.c | |||
@@ -5,6 +5,7 @@ | |||
5 | 5 | ||
6 | #include <linux/module.h> | 6 | #include <linux/module.h> |
7 | #include <linux/init.h> | 7 | #include <linux/init.h> |
8 | #include <linux/slab.h> | ||
8 | #include <linux/types.h> | 9 | #include <linux/types.h> |
9 | #include <linux/string.h> | 10 | #include <linux/string.h> |
10 | #include <linux/errno.h> | 11 | #include <linux/errno.h> |
diff --git a/net/sched/sch_fifo.c b/net/sched/sch_fifo.c index 4b0a6cc44c77..5948bafa8ce2 100644 --- a/net/sched/sch_fifo.c +++ b/net/sched/sch_fifo.c | |||
@@ -10,6 +10,7 @@ | |||
10 | */ | 10 | */ |
11 | 11 | ||
12 | #include <linux/module.h> | 12 | #include <linux/module.h> |
13 | #include <linux/slab.h> | ||
13 | #include <linux/types.h> | 14 | #include <linux/types.h> |
14 | #include <linux/kernel.h> | 15 | #include <linux/kernel.h> |
15 | #include <linux/errno.h> | 16 | #include <linux/errno.h> |
diff --git a/net/sched/sch_generic.c b/net/sched/sch_generic.c index 5173c1e1b19c..aeddabfb8e4e 100644 --- a/net/sched/sch_generic.c +++ b/net/sched/sch_generic.c | |||
@@ -24,6 +24,7 @@ | |||
24 | #include <linux/init.h> | 24 | #include <linux/init.h> |
25 | #include <linux/rcupdate.h> | 25 | #include <linux/rcupdate.h> |
26 | #include <linux/list.h> | 26 | #include <linux/list.h> |
27 | #include <linux/slab.h> | ||
27 | #include <net/pkt_sched.h> | 28 | #include <net/pkt_sched.h> |
28 | 29 | ||
29 | /* Main transmission queue. */ | 30 | /* Main transmission queue. */ |
@@ -528,7 +529,7 @@ struct Qdisc *qdisc_alloc(struct netdev_queue *dev_queue, | |||
528 | unsigned int size; | 529 | unsigned int size; |
529 | int err = -ENOBUFS; | 530 | int err = -ENOBUFS; |
530 | 531 | ||
531 | /* ensure that the Qdisc and the private data are 32-byte aligned */ | 532 | /* ensure that the Qdisc and the private data are 64-byte aligned */ |
532 | size = QDISC_ALIGN(sizeof(*sch)); | 533 | size = QDISC_ALIGN(sizeof(*sch)); |
533 | size += ops->priv_size + (QDISC_ALIGNTO - 1); | 534 | size += ops->priv_size + (QDISC_ALIGNTO - 1); |
534 | 535 | ||
@@ -590,6 +591,13 @@ void qdisc_reset(struct Qdisc *qdisc) | |||
590 | } | 591 | } |
591 | EXPORT_SYMBOL(qdisc_reset); | 592 | EXPORT_SYMBOL(qdisc_reset); |
592 | 593 | ||
594 | static void qdisc_rcu_free(struct rcu_head *head) | ||
595 | { | ||
596 | struct Qdisc *qdisc = container_of(head, struct Qdisc, rcu_head); | ||
597 | |||
598 | kfree((char *) qdisc - qdisc->padded); | ||
599 | } | ||
600 | |||
593 | void qdisc_destroy(struct Qdisc *qdisc) | 601 | void qdisc_destroy(struct Qdisc *qdisc) |
594 | { | 602 | { |
595 | const struct Qdisc_ops *ops = qdisc->ops; | 603 | const struct Qdisc_ops *ops = qdisc->ops; |
@@ -613,7 +621,11 @@ void qdisc_destroy(struct Qdisc *qdisc) | |||
613 | dev_put(qdisc_dev(qdisc)); | 621 | dev_put(qdisc_dev(qdisc)); |
614 | 622 | ||
615 | kfree_skb(qdisc->gso_skb); | 623 | kfree_skb(qdisc->gso_skb); |
616 | kfree((char *) qdisc - qdisc->padded); | 624 | /* |
625 | * gen_estimator est_timer() might access qdisc->q.lock, | ||
626 | * wait a RCU grace period before freeing qdisc. | ||
627 | */ | ||
628 | call_rcu(&qdisc->rcu_head, qdisc_rcu_free); | ||
617 | } | 629 | } |
618 | EXPORT_SYMBOL(qdisc_destroy); | 630 | EXPORT_SYMBOL(qdisc_destroy); |
619 | 631 | ||
diff --git a/net/sched/sch_gred.c b/net/sched/sch_gred.c index 40408d595c08..51dcc2aa5c92 100644 --- a/net/sched/sch_gred.c +++ b/net/sched/sch_gred.c | |||
@@ -18,6 +18,7 @@ | |||
18 | * For all the glorious comments look at include/net/red.h | 18 | * For all the glorious comments look at include/net/red.h |
19 | */ | 19 | */ |
20 | 20 | ||
21 | #include <linux/slab.h> | ||
21 | #include <linux/module.h> | 22 | #include <linux/module.h> |
22 | #include <linux/types.h> | 23 | #include <linux/types.h> |
23 | #include <linux/kernel.h> | 24 | #include <linux/kernel.h> |
diff --git a/net/sched/sch_htb.c b/net/sched/sch_htb.c index 508cf5f3a6d5..0b52b8de562c 100644 --- a/net/sched/sch_htb.c +++ b/net/sched/sch_htb.c | |||
@@ -36,6 +36,7 @@ | |||
36 | #include <linux/compiler.h> | 36 | #include <linux/compiler.h> |
37 | #include <linux/rbtree.h> | 37 | #include <linux/rbtree.h> |
38 | #include <linux/workqueue.h> | 38 | #include <linux/workqueue.h> |
39 | #include <linux/slab.h> | ||
39 | #include <net/netlink.h> | 40 | #include <net/netlink.h> |
40 | #include <net/pkt_sched.h> | 41 | #include <net/pkt_sched.h> |
41 | 42 | ||
diff --git a/net/sched/sch_mq.c b/net/sched/sch_mq.c index d1dea3d5dc92..b2aba3f5e6fa 100644 --- a/net/sched/sch_mq.c +++ b/net/sched/sch_mq.c | |||
@@ -9,6 +9,7 @@ | |||
9 | */ | 9 | */ |
10 | 10 | ||
11 | #include <linux/types.h> | 11 | #include <linux/types.h> |
12 | #include <linux/slab.h> | ||
12 | #include <linux/kernel.h> | 13 | #include <linux/kernel.h> |
13 | #include <linux/string.h> | 14 | #include <linux/string.h> |
14 | #include <linux/errno.h> | 15 | #include <linux/errno.h> |
diff --git a/net/sched/sch_multiq.c b/net/sched/sch_multiq.c index 7db2c88ce585..c50876cd8704 100644 --- a/net/sched/sch_multiq.c +++ b/net/sched/sch_multiq.c | |||
@@ -18,6 +18,7 @@ | |||
18 | */ | 18 | */ |
19 | 19 | ||
20 | #include <linux/module.h> | 20 | #include <linux/module.h> |
21 | #include <linux/slab.h> | ||
21 | #include <linux/types.h> | 22 | #include <linux/types.h> |
22 | #include <linux/kernel.h> | 23 | #include <linux/kernel.h> |
23 | #include <linux/string.h> | 24 | #include <linux/string.h> |
diff --git a/net/sched/sch_netem.c b/net/sched/sch_netem.c index d8b10e054627..4714ff162bbd 100644 --- a/net/sched/sch_netem.c +++ b/net/sched/sch_netem.c | |||
@@ -14,6 +14,7 @@ | |||
14 | */ | 14 | */ |
15 | 15 | ||
16 | #include <linux/module.h> | 16 | #include <linux/module.h> |
17 | #include <linux/slab.h> | ||
17 | #include <linux/types.h> | 18 | #include <linux/types.h> |
18 | #include <linux/kernel.h> | 19 | #include <linux/kernel.h> |
19 | #include <linux/errno.h> | 20 | #include <linux/errno.h> |
diff --git a/net/sched/sch_prio.c b/net/sched/sch_prio.c index 93285cecb246..81672e0c1b25 100644 --- a/net/sched/sch_prio.c +++ b/net/sched/sch_prio.c | |||
@@ -12,6 +12,7 @@ | |||
12 | */ | 12 | */ |
13 | 13 | ||
14 | #include <linux/module.h> | 14 | #include <linux/module.h> |
15 | #include <linux/slab.h> | ||
15 | #include <linux/types.h> | 16 | #include <linux/types.h> |
16 | #include <linux/kernel.h> | 17 | #include <linux/kernel.h> |
17 | #include <linux/string.h> | 18 | #include <linux/string.h> |
diff --git a/net/sched/sch_sfq.c b/net/sched/sch_sfq.c index cb21380c0605..c5a9ac566007 100644 --- a/net/sched/sch_sfq.c +++ b/net/sched/sch_sfq.c | |||
@@ -20,6 +20,7 @@ | |||
20 | #include <linux/ipv6.h> | 20 | #include <linux/ipv6.h> |
21 | #include <linux/skbuff.h> | 21 | #include <linux/skbuff.h> |
22 | #include <linux/jhash.h> | 22 | #include <linux/jhash.h> |
23 | #include <linux/slab.h> | ||
23 | #include <net/ip.h> | 24 | #include <net/ip.h> |
24 | #include <net/netlink.h> | 25 | #include <net/netlink.h> |
25 | #include <net/pkt_sched.h> | 26 | #include <net/pkt_sched.h> |
diff --git a/net/sched/sch_teql.c b/net/sched/sch_teql.c index db69637069c4..3415b6ce1c0a 100644 --- a/net/sched/sch_teql.c +++ b/net/sched/sch_teql.c | |||
@@ -11,6 +11,7 @@ | |||
11 | #include <linux/module.h> | 11 | #include <linux/module.h> |
12 | #include <linux/types.h> | 12 | #include <linux/types.h> |
13 | #include <linux/kernel.h> | 13 | #include <linux/kernel.h> |
14 | #include <linux/slab.h> | ||
14 | #include <linux/string.h> | 15 | #include <linux/string.h> |
15 | #include <linux/errno.h> | 16 | #include <linux/errno.h> |
16 | #include <linux/if_arp.h> | 17 | #include <linux/if_arp.h> |
diff --git a/net/sctp/auth.c b/net/sctp/auth.c index 56935bbc1496..86366390038a 100644 --- a/net/sctp/auth.c +++ b/net/sctp/auth.c | |||
@@ -34,6 +34,7 @@ | |||
34 | * be incorporated into the next SCTP release. | 34 | * be incorporated into the next SCTP release. |
35 | */ | 35 | */ |
36 | 36 | ||
37 | #include <linux/slab.h> | ||
37 | #include <linux/types.h> | 38 | #include <linux/types.h> |
38 | #include <linux/crypto.h> | 39 | #include <linux/crypto.h> |
39 | #include <linux/scatterlist.h> | 40 | #include <linux/scatterlist.h> |
diff --git a/net/sctp/bind_addr.c b/net/sctp/bind_addr.c index bef133731683..faf71d179e46 100644 --- a/net/sctp/bind_addr.c +++ b/net/sctp/bind_addr.c | |||
@@ -43,6 +43,7 @@ | |||
43 | */ | 43 | */ |
44 | 44 | ||
45 | #include <linux/types.h> | 45 | #include <linux/types.h> |
46 | #include <linux/slab.h> | ||
46 | #include <linux/in.h> | 47 | #include <linux/in.h> |
47 | #include <net/sock.h> | 48 | #include <net/sock.h> |
48 | #include <net/ipv6.h> | 49 | #include <net/ipv6.h> |
diff --git a/net/sctp/chunk.c b/net/sctp/chunk.c index 8e4320040f05..3eab6db59a37 100644 --- a/net/sctp/chunk.c +++ b/net/sctp/chunk.c | |||
@@ -42,6 +42,7 @@ | |||
42 | #include <linux/net.h> | 42 | #include <linux/net.h> |
43 | #include <linux/inet.h> | 43 | #include <linux/inet.h> |
44 | #include <linux/skbuff.h> | 44 | #include <linux/skbuff.h> |
45 | #include <linux/slab.h> | ||
45 | #include <net/sock.h> | 46 | #include <net/sock.h> |
46 | #include <net/sctp/sctp.h> | 47 | #include <net/sctp/sctp.h> |
47 | #include <net/sctp/sm.h> | 48 | #include <net/sctp/sm.h> |
diff --git a/net/sctp/input.c b/net/sctp/input.c index 3d74b264ea22..2a570184e5a9 100644 --- a/net/sctp/input.c +++ b/net/sctp/input.c | |||
@@ -53,6 +53,7 @@ | |||
53 | #include <linux/socket.h> | 53 | #include <linux/socket.h> |
54 | #include <linux/ip.h> | 54 | #include <linux/ip.h> |
55 | #include <linux/time.h> /* For struct timeval */ | 55 | #include <linux/time.h> /* For struct timeval */ |
56 | #include <linux/slab.h> | ||
56 | #include <net/ip.h> | 57 | #include <net/ip.h> |
57 | #include <net/icmp.h> | 58 | #include <net/icmp.h> |
58 | #include <net/snmp.h> | 59 | #include <net/snmp.h> |
diff --git a/net/sctp/inqueue.c b/net/sctp/inqueue.c index bbf5dd2a97c4..ccb6dc48d15b 100644 --- a/net/sctp/inqueue.c +++ b/net/sctp/inqueue.c | |||
@@ -46,6 +46,7 @@ | |||
46 | #include <net/sctp/sctp.h> | 46 | #include <net/sctp/sctp.h> |
47 | #include <net/sctp/sm.h> | 47 | #include <net/sctp/sm.h> |
48 | #include <linux/interrupt.h> | 48 | #include <linux/interrupt.h> |
49 | #include <linux/slab.h> | ||
49 | 50 | ||
50 | /* Initialize an SCTP inqueue. */ | 51 | /* Initialize an SCTP inqueue. */ |
51 | void sctp_inq_init(struct sctp_inq *queue) | 52 | void sctp_inq_init(struct sctp_inq *queue) |
diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c index 1d7ac70ba39f..14db5689fb89 100644 --- a/net/sctp/ipv6.c +++ b/net/sctp/ipv6.c | |||
@@ -58,6 +58,7 @@ | |||
58 | #include <linux/netdevice.h> | 58 | #include <linux/netdevice.h> |
59 | #include <linux/init.h> | 59 | #include <linux/init.h> |
60 | #include <linux/ipsec.h> | 60 | #include <linux/ipsec.h> |
61 | #include <linux/slab.h> | ||
61 | 62 | ||
62 | #include <linux/ipv6.h> | 63 | #include <linux/ipv6.h> |
63 | #include <linux/icmpv6.h> | 64 | #include <linux/icmpv6.h> |
@@ -276,20 +277,7 @@ static struct dst_entry *sctp_v6_get_dst(struct sctp_association *asoc, | |||
276 | static inline int sctp_v6_addr_match_len(union sctp_addr *s1, | 277 | static inline int sctp_v6_addr_match_len(union sctp_addr *s1, |
277 | union sctp_addr *s2) | 278 | union sctp_addr *s2) |
278 | { | 279 | { |
279 | struct in6_addr *a1 = &s1->v6.sin6_addr; | 280 | return ipv6_addr_diff(&s1->v6.sin6_addr, &s2->v6.sin6_addr); |
280 | struct in6_addr *a2 = &s2->v6.sin6_addr; | ||
281 | int i, j; | ||
282 | |||
283 | for (i = 0; i < 4 ; i++) { | ||
284 | __be32 a1xora2; | ||
285 | |||
286 | a1xora2 = a1->s6_addr32[i] ^ a2->s6_addr32[i]; | ||
287 | |||
288 | if ((j = fls(ntohl(a1xora2)))) | ||
289 | return (i * 32 + 32 - j); | ||
290 | } | ||
291 | |||
292 | return (i*32); | ||
293 | } | 281 | } |
294 | 282 | ||
295 | /* Fills in the source address(saddr) based on the destination address(daddr) | 283 | /* Fills in the source address(saddr) based on the destination address(daddr) |
@@ -371,13 +359,13 @@ static void sctp_v6_copy_addrlist(struct list_head *addrlist, | |||
371 | } | 359 | } |
372 | 360 | ||
373 | read_lock_bh(&in6_dev->lock); | 361 | read_lock_bh(&in6_dev->lock); |
374 | for (ifp = in6_dev->addr_list; ifp; ifp = ifp->if_next) { | 362 | list_for_each_entry(ifp, &in6_dev->addr_list, if_list) { |
375 | /* Add the address to the local list. */ | 363 | /* Add the address to the local list. */ |
376 | addr = t_new(struct sctp_sockaddr_entry, GFP_ATOMIC); | 364 | addr = t_new(struct sctp_sockaddr_entry, GFP_ATOMIC); |
377 | if (addr) { | 365 | if (addr) { |
378 | addr->a.v6.sin6_family = AF_INET6; | 366 | addr->a.v6.sin6_family = AF_INET6; |
379 | addr->a.v6.sin6_port = 0; | 367 | addr->a.v6.sin6_port = 0; |
380 | addr->a.v6.sin6_addr = ifp->addr; | 368 | ipv6_addr_copy(&addr->a.v6.sin6_addr, &ifp->addr); |
381 | addr->a.v6.sin6_scope_id = dev->ifindex; | 369 | addr->a.v6.sin6_scope_id = dev->ifindex; |
382 | addr->valid = 1; | 370 | addr->valid = 1; |
383 | INIT_LIST_HEAD(&addr->list); | 371 | INIT_LIST_HEAD(&addr->list); |
@@ -418,7 +406,7 @@ static void sctp_v6_from_sk(union sctp_addr *addr, struct sock *sk) | |||
418 | { | 406 | { |
419 | addr->v6.sin6_family = AF_INET6; | 407 | addr->v6.sin6_family = AF_INET6; |
420 | addr->v6.sin6_port = 0; | 408 | addr->v6.sin6_port = 0; |
421 | addr->v6.sin6_addr = inet6_sk(sk)->rcv_saddr; | 409 | ipv6_addr_copy(&addr->v6.sin6_addr, &inet6_sk(sk)->rcv_saddr); |
422 | } | 410 | } |
423 | 411 | ||
424 | /* Initialize sk->sk_rcv_saddr from sctp_addr. */ | 412 | /* Initialize sk->sk_rcv_saddr from sctp_addr. */ |
@@ -431,7 +419,7 @@ static void sctp_v6_to_sk_saddr(union sctp_addr *addr, struct sock *sk) | |||
431 | inet6_sk(sk)->rcv_saddr.s6_addr32[3] = | 419 | inet6_sk(sk)->rcv_saddr.s6_addr32[3] = |
432 | addr->v4.sin_addr.s_addr; | 420 | addr->v4.sin_addr.s_addr; |
433 | } else { | 421 | } else { |
434 | inet6_sk(sk)->rcv_saddr = addr->v6.sin6_addr; | 422 | ipv6_addr_copy(&inet6_sk(sk)->rcv_saddr, &addr->v6.sin6_addr); |
435 | } | 423 | } |
436 | } | 424 | } |
437 | 425 | ||
@@ -444,7 +432,7 @@ static void sctp_v6_to_sk_daddr(union sctp_addr *addr, struct sock *sk) | |||
444 | inet6_sk(sk)->daddr.s6_addr32[2] = htonl(0x0000ffff); | 432 | inet6_sk(sk)->daddr.s6_addr32[2] = htonl(0x0000ffff); |
445 | inet6_sk(sk)->daddr.s6_addr32[3] = addr->v4.sin_addr.s_addr; | 433 | inet6_sk(sk)->daddr.s6_addr32[3] = addr->v4.sin_addr.s_addr; |
446 | } else { | 434 | } else { |
447 | inet6_sk(sk)->daddr = addr->v6.sin6_addr; | 435 | ipv6_addr_copy(&inet6_sk(sk)->daddr, &addr->v6.sin6_addr); |
448 | } | 436 | } |
449 | } | 437 | } |
450 | 438 | ||
diff --git a/net/sctp/output.c b/net/sctp/output.c index 7c5589363433..fad261d41ec2 100644 --- a/net/sctp/output.c +++ b/net/sctp/output.c | |||
@@ -48,6 +48,7 @@ | |||
48 | #include <linux/ip.h> | 48 | #include <linux/ip.h> |
49 | #include <linux/ipv6.h> | 49 | #include <linux/ipv6.h> |
50 | #include <linux/init.h> | 50 | #include <linux/init.h> |
51 | #include <linux/slab.h> | ||
51 | #include <net/inet_ecn.h> | 52 | #include <net/inet_ecn.h> |
52 | #include <net/ip.h> | 53 | #include <net/ip.h> |
53 | #include <net/icmp.h> | 54 | #include <net/icmp.h> |
diff --git a/net/sctp/outqueue.c b/net/sctp/outqueue.c index 229690f02a1d..abfc0b8dee74 100644 --- a/net/sctp/outqueue.c +++ b/net/sctp/outqueue.c | |||
@@ -50,6 +50,7 @@ | |||
50 | #include <linux/list.h> /* For struct list_head */ | 50 | #include <linux/list.h> /* For struct list_head */ |
51 | #include <linux/socket.h> | 51 | #include <linux/socket.h> |
52 | #include <linux/ip.h> | 52 | #include <linux/ip.h> |
53 | #include <linux/slab.h> | ||
53 | #include <net/sock.h> /* For skb_set_owner_w */ | 54 | #include <net/sock.h> /* For skb_set_owner_w */ |
54 | 55 | ||
55 | #include <net/sctp/sctp.h> | 56 | #include <net/sctp/sctp.h> |
diff --git a/net/sctp/primitive.c b/net/sctp/primitive.c index 8cb4f060bce6..534c7eae9d15 100644 --- a/net/sctp/primitive.c +++ b/net/sctp/primitive.c | |||
@@ -50,6 +50,7 @@ | |||
50 | #include <linux/socket.h> | 50 | #include <linux/socket.h> |
51 | #include <linux/ip.h> | 51 | #include <linux/ip.h> |
52 | #include <linux/time.h> /* For struct timeval */ | 52 | #include <linux/time.h> /* For struct timeval */ |
53 | #include <linux/gfp.h> | ||
53 | #include <net/sock.h> | 54 | #include <net/sock.h> |
54 | #include <net/sctp/sctp.h> | 55 | #include <net/sctp/sctp.h> |
55 | #include <net/sctp/sm.h> | 56 | #include <net/sctp/sm.h> |
diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c index e771690f6d5d..a56f98e82f92 100644 --- a/net/sctp/protocol.c +++ b/net/sctp/protocol.c | |||
@@ -54,6 +54,7 @@ | |||
54 | #include <linux/bootmem.h> | 54 | #include <linux/bootmem.h> |
55 | #include <linux/highmem.h> | 55 | #include <linux/highmem.h> |
56 | #include <linux/swap.h> | 56 | #include <linux/swap.h> |
57 | #include <linux/slab.h> | ||
57 | #include <net/net_namespace.h> | 58 | #include <net/net_namespace.h> |
58 | #include <net/protocol.h> | 59 | #include <net/protocol.h> |
59 | #include <net/ip.h> | 60 | #include <net/ip.h> |
diff --git a/net/sctp/sm_make_chunk.c b/net/sctp/sm_make_chunk.c index 9e732916b671..17cb400ecd6a 100644 --- a/net/sctp/sm_make_chunk.c +++ b/net/sctp/sm_make_chunk.c | |||
@@ -58,6 +58,7 @@ | |||
58 | #include <linux/inet.h> | 58 | #include <linux/inet.h> |
59 | #include <linux/scatterlist.h> | 59 | #include <linux/scatterlist.h> |
60 | #include <linux/crypto.h> | 60 | #include <linux/crypto.h> |
61 | #include <linux/slab.h> | ||
61 | #include <net/sock.h> | 62 | #include <net/sock.h> |
62 | 63 | ||
63 | #include <linux/skbuff.h> | 64 | #include <linux/skbuff.h> |
diff --git a/net/sctp/sm_sideeffect.c b/net/sctp/sm_sideeffect.c index 4e4ca65cd320..4c5bed9af4e3 100644 --- a/net/sctp/sm_sideeffect.c +++ b/net/sctp/sm_sideeffect.c | |||
@@ -51,6 +51,7 @@ | |||
51 | #include <linux/types.h> | 51 | #include <linux/types.h> |
52 | #include <linux/socket.h> | 52 | #include <linux/socket.h> |
53 | #include <linux/ip.h> | 53 | #include <linux/ip.h> |
54 | #include <linux/gfp.h> | ||
54 | #include <net/sock.h> | 55 | #include <net/sock.h> |
55 | #include <net/sctp/sctp.h> | 56 | #include <net/sctp/sctp.h> |
56 | #include <net/sctp/sm.h> | 57 | #include <net/sctp/sm.h> |
@@ -475,7 +476,7 @@ static void sctp_do_8_2_transport_strike(struct sctp_association *asoc, | |||
475 | * used to provide an upper bound to this doubling operation. | 476 | * used to provide an upper bound to this doubling operation. |
476 | * | 477 | * |
477 | * Special Case: the first HB doesn't trigger exponential backoff. | 478 | * Special Case: the first HB doesn't trigger exponential backoff. |
478 | * The first unacknowleged HB triggers it. We do this with a flag | 479 | * The first unacknowledged HB triggers it. We do this with a flag |
479 | * that indicates that we have an outstanding HB. | 480 | * that indicates that we have an outstanding HB. |
480 | */ | 481 | */ |
481 | if (!is_hb || transport->hb_sent) { | 482 | if (!is_hb || transport->hb_sent) { |
diff --git a/net/sctp/sm_statefuns.c b/net/sctp/sm_statefuns.c index 47bc20d3a85b..abf601a1b847 100644 --- a/net/sctp/sm_statefuns.c +++ b/net/sctp/sm_statefuns.c | |||
@@ -56,6 +56,7 @@ | |||
56 | #include <linux/ipv6.h> | 56 | #include <linux/ipv6.h> |
57 | #include <linux/net.h> | 57 | #include <linux/net.h> |
58 | #include <linux/inet.h> | 58 | #include <linux/inet.h> |
59 | #include <linux/slab.h> | ||
59 | #include <net/sock.h> | 60 | #include <net/sock.h> |
60 | #include <net/inet_ecn.h> | 61 | #include <net/inet_ecn.h> |
61 | #include <linux/skbuff.h> | 62 | #include <linux/skbuff.h> |
diff --git a/net/sctp/socket.c b/net/sctp/socket.c index dfc5c127efd4..c1941276f6e3 100644 --- a/net/sctp/socket.c +++ b/net/sctp/socket.c | |||
@@ -67,6 +67,7 @@ | |||
67 | #include <linux/poll.h> | 67 | #include <linux/poll.h> |
68 | #include <linux/init.h> | 68 | #include <linux/init.h> |
69 | #include <linux/crypto.h> | 69 | #include <linux/crypto.h> |
70 | #include <linux/slab.h> | ||
70 | 71 | ||
71 | #include <net/ip.h> | 72 | #include <net/ip.h> |
72 | #include <net/icmp.h> | 73 | #include <net/icmp.h> |
@@ -5481,7 +5482,6 @@ pp_found: | |||
5481 | */ | 5482 | */ |
5482 | int reuse = sk->sk_reuse; | 5483 | int reuse = sk->sk_reuse; |
5483 | struct sock *sk2; | 5484 | struct sock *sk2; |
5484 | struct hlist_node *node; | ||
5485 | 5485 | ||
5486 | SCTP_DEBUG_PRINTK("sctp_get_port() found a possible match\n"); | 5486 | SCTP_DEBUG_PRINTK("sctp_get_port() found a possible match\n"); |
5487 | if (pp->fastreuse && sk->sk_reuse && | 5487 | if (pp->fastreuse && sk->sk_reuse && |
diff --git a/net/sctp/ssnmap.c b/net/sctp/ssnmap.c index 737d330e5ffc..442ad4ed6315 100644 --- a/net/sctp/ssnmap.c +++ b/net/sctp/ssnmap.c | |||
@@ -37,6 +37,7 @@ | |||
37 | */ | 37 | */ |
38 | 38 | ||
39 | #include <linux/types.h> | 39 | #include <linux/types.h> |
40 | #include <linux/slab.h> | ||
40 | #include <net/sctp/sctp.h> | 41 | #include <net/sctp/sctp.h> |
41 | #include <net/sctp/sm.h> | 42 | #include <net/sctp/sm.h> |
42 | 43 | ||
diff --git a/net/sctp/transport.c b/net/sctp/transport.c index b827d21dbe54..be4d63d5a5cc 100644 --- a/net/sctp/transport.c +++ b/net/sctp/transport.c | |||
@@ -48,6 +48,7 @@ | |||
48 | * be incorporated into the next SCTP release. | 48 | * be incorporated into the next SCTP release. |
49 | */ | 49 | */ |
50 | 50 | ||
51 | #include <linux/slab.h> | ||
51 | #include <linux/types.h> | 52 | #include <linux/types.h> |
52 | #include <linux/random.h> | 53 | #include <linux/random.h> |
53 | #include <net/sctp/sctp.h> | 54 | #include <net/sctp/sctp.h> |
diff --git a/net/sctp/tsnmap.c b/net/sctp/tsnmap.c index 9bd64565021a..747d5412c463 100644 --- a/net/sctp/tsnmap.c +++ b/net/sctp/tsnmap.c | |||
@@ -42,6 +42,7 @@ | |||
42 | * be incorporated into the next SCTP release. | 42 | * be incorporated into the next SCTP release. |
43 | */ | 43 | */ |
44 | 44 | ||
45 | #include <linux/slab.h> | ||
45 | #include <linux/types.h> | 46 | #include <linux/types.h> |
46 | #include <linux/bitmap.h> | 47 | #include <linux/bitmap.h> |
47 | #include <net/sctp/sctp.h> | 48 | #include <net/sctp/sctp.h> |
diff --git a/net/sctp/ulpevent.c b/net/sctp/ulpevent.c index 8b3560fd876d..aa72e89c3ee1 100644 --- a/net/sctp/ulpevent.c +++ b/net/sctp/ulpevent.c | |||
@@ -43,6 +43,7 @@ | |||
43 | * be incorporated into the next SCTP release. | 43 | * be incorporated into the next SCTP release. |
44 | */ | 44 | */ |
45 | 45 | ||
46 | #include <linux/slab.h> | ||
46 | #include <linux/types.h> | 47 | #include <linux/types.h> |
47 | #include <linux/skbuff.h> | 48 | #include <linux/skbuff.h> |
48 | #include <net/sctp/structs.h> | 49 | #include <net/sctp/structs.h> |
diff --git a/net/sctp/ulpqueue.c b/net/sctp/ulpqueue.c index 7b23803343cc..3a448536f0b6 100644 --- a/net/sctp/ulpqueue.c +++ b/net/sctp/ulpqueue.c | |||
@@ -41,6 +41,7 @@ | |||
41 | * be incorporated into the next SCTP release. | 41 | * be incorporated into the next SCTP release. |
42 | */ | 42 | */ |
43 | 43 | ||
44 | #include <linux/slab.h> | ||
44 | #include <linux/types.h> | 45 | #include <linux/types.h> |
45 | #include <linux/skbuff.h> | 46 | #include <linux/skbuff.h> |
46 | #include <net/sock.h> | 47 | #include <net/sock.h> |
diff --git a/net/socket.c b/net/socket.c index 769c386bd428..35bc198bbf68 100644 --- a/net/socket.c +++ b/net/socket.c | |||
@@ -87,6 +87,7 @@ | |||
87 | #include <linux/wireless.h> | 87 | #include <linux/wireless.h> |
88 | #include <linux/nsproxy.h> | 88 | #include <linux/nsproxy.h> |
89 | #include <linux/magic.h> | 89 | #include <linux/magic.h> |
90 | #include <linux/slab.h> | ||
90 | 91 | ||
91 | #include <asm/uaccess.h> | 92 | #include <asm/uaccess.h> |
92 | #include <asm/unistd.h> | 93 | #include <asm/unistd.h> |
@@ -619,10 +620,9 @@ void __sock_recv_timestamp(struct msghdr *msg, struct sock *sk, | |||
619 | put_cmsg(msg, SOL_SOCKET, SCM_TIMESTAMP, | 620 | put_cmsg(msg, SOL_SOCKET, SCM_TIMESTAMP, |
620 | sizeof(tv), &tv); | 621 | sizeof(tv), &tv); |
621 | } else { | 622 | } else { |
622 | struct timespec ts; | 623 | skb_get_timestampns(skb, &ts[0]); |
623 | skb_get_timestampns(skb, &ts); | ||
624 | put_cmsg(msg, SOL_SOCKET, SCM_TIMESTAMPNS, | 624 | put_cmsg(msg, SOL_SOCKET, SCM_TIMESTAMPNS, |
625 | sizeof(ts), &ts); | 625 | sizeof(ts[0]), &ts[0]); |
626 | } | 626 | } |
627 | } | 627 | } |
628 | 628 | ||
@@ -2135,6 +2135,10 @@ int __sys_recvmmsg(int fd, struct mmsghdr __user *mmsg, unsigned int vlen, | |||
2135 | break; | 2135 | break; |
2136 | ++datagrams; | 2136 | ++datagrams; |
2137 | 2137 | ||
2138 | /* MSG_WAITFORONE turns on MSG_DONTWAIT after one packet */ | ||
2139 | if (flags & MSG_WAITFORONE) | ||
2140 | flags |= MSG_DONTWAIT; | ||
2141 | |||
2138 | if (timeout) { | 2142 | if (timeout) { |
2139 | ktime_get_ts(timeout); | 2143 | ktime_get_ts(timeout); |
2140 | *timeout = timespec_sub(end_time, *timeout); | 2144 | *timeout = timespec_sub(end_time, *timeout); |
diff --git a/net/sunrpc/addr.c b/net/sunrpc/addr.c index 6dcdd2517819..1419d0cdbbac 100644 --- a/net/sunrpc/addr.c +++ b/net/sunrpc/addr.c | |||
@@ -18,6 +18,7 @@ | |||
18 | 18 | ||
19 | #include <net/ipv6.h> | 19 | #include <net/ipv6.h> |
20 | #include <linux/sunrpc/clnt.h> | 20 | #include <linux/sunrpc/clnt.h> |
21 | #include <linux/slab.h> | ||
21 | 22 | ||
22 | #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) | 23 | #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) |
23 | 24 | ||
@@ -71,8 +72,9 @@ static size_t rpc_ntop6(const struct sockaddr *sap, | |||
71 | if (unlikely(len == 0)) | 72 | if (unlikely(len == 0)) |
72 | return len; | 73 | return len; |
73 | 74 | ||
74 | if (!(ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_LINKLOCAL) && | 75 | if (!(ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_LINKLOCAL)) |
75 | !(ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_SITELOCAL)) | 76 | return len; |
77 | if (sin6->sin6_scope_id == 0) | ||
76 | return len; | 78 | return len; |
77 | 79 | ||
78 | rc = snprintf(scopebuf, sizeof(scopebuf), "%c%u", | 80 | rc = snprintf(scopebuf, sizeof(scopebuf), "%c%u", |
@@ -165,8 +167,7 @@ static int rpc_parse_scope_id(const char *buf, const size_t buflen, | |||
165 | if (*delim != IPV6_SCOPE_DELIMITER) | 167 | if (*delim != IPV6_SCOPE_DELIMITER) |
166 | return 0; | 168 | return 0; |
167 | 169 | ||
168 | if (!(ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_LINKLOCAL) && | 170 | if (!(ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_LINKLOCAL)) |
169 | !(ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_SITELOCAL)) | ||
170 | return 0; | 171 | return 0; |
171 | 172 | ||
172 | len = (buf + buflen) - delim - 1; | 173 | len = (buf + buflen) - delim - 1; |
diff --git a/net/sunrpc/auth_generic.c b/net/sunrpc/auth_generic.c index bf88bf8e9365..8f623b0f03dd 100644 --- a/net/sunrpc/auth_generic.c +++ b/net/sunrpc/auth_generic.c | |||
@@ -5,6 +5,7 @@ | |||
5 | */ | 5 | */ |
6 | 6 | ||
7 | #include <linux/err.h> | 7 | #include <linux/err.h> |
8 | #include <linux/slab.h> | ||
8 | #include <linux/types.h> | 9 | #include <linux/types.h> |
9 | #include <linux/module.h> | 10 | #include <linux/module.h> |
10 | #include <linux/sched.h> | 11 | #include <linux/sched.h> |
diff --git a/net/sunrpc/auth_gss/auth_gss.c b/net/sunrpc/auth_gss/auth_gss.c index f7a7f8380e38..c389ccf6437d 100644 --- a/net/sunrpc/auth_gss/auth_gss.c +++ b/net/sunrpc/auth_gss/auth_gss.c | |||
@@ -206,8 +206,14 @@ gss_fill_context(const void *p, const void *end, struct gss_cl_ctx *ctx, struct | |||
206 | ctx->gc_win = window_size; | 206 | ctx->gc_win = window_size; |
207 | /* gssd signals an error by passing ctx->gc_win = 0: */ | 207 | /* gssd signals an error by passing ctx->gc_win = 0: */ |
208 | if (ctx->gc_win == 0) { | 208 | if (ctx->gc_win == 0) { |
209 | /* in which case, p points to an error code which we ignore */ | 209 | /* |
210 | p = ERR_PTR(-EACCES); | 210 | * in which case, p points to an error code. Anything other |
211 | * than -EKEYEXPIRED gets converted to -EACCES. | ||
212 | */ | ||
213 | p = simple_get_bytes(p, end, &ret, sizeof(ret)); | ||
214 | if (!IS_ERR(p)) | ||
215 | p = (ret == -EKEYEXPIRED) ? ERR_PTR(-EKEYEXPIRED) : | ||
216 | ERR_PTR(-EACCES); | ||
211 | goto err; | 217 | goto err; |
212 | } | 218 | } |
213 | /* copy the opaque wire context */ | 219 | /* copy the opaque wire context */ |
@@ -646,6 +652,7 @@ gss_pipe_downcall(struct file *filp, const char __user *src, size_t mlen) | |||
646 | err = PTR_ERR(p); | 652 | err = PTR_ERR(p); |
647 | switch (err) { | 653 | switch (err) { |
648 | case -EACCES: | 654 | case -EACCES: |
655 | case -EKEYEXPIRED: | ||
649 | gss_msg->msg.errno = err; | 656 | gss_msg->msg.errno = err; |
650 | err = mlen; | 657 | err = mlen; |
651 | break; | 658 | break; |
@@ -1273,9 +1280,8 @@ alloc_enc_pages(struct rpc_rqst *rqstp) | |||
1273 | rqstp->rq_release_snd_buf = priv_release_snd_buf; | 1280 | rqstp->rq_release_snd_buf = priv_release_snd_buf; |
1274 | return 0; | 1281 | return 0; |
1275 | out_free: | 1282 | out_free: |
1276 | for (i--; i >= 0; i--) { | 1283 | rqstp->rq_enc_pages_num = i; |
1277 | __free_page(rqstp->rq_enc_pages[i]); | 1284 | priv_release_snd_buf(rqstp); |
1278 | } | ||
1279 | out: | 1285 | out: |
1280 | return -EAGAIN; | 1286 | return -EAGAIN; |
1281 | } | 1287 | } |
diff --git a/net/sunrpc/auth_gss/gss_generic_token.c b/net/sunrpc/auth_gss/gss_generic_token.c index c0ba39c4f5f2..310b78e99456 100644 --- a/net/sunrpc/auth_gss/gss_generic_token.c +++ b/net/sunrpc/auth_gss/gss_generic_token.c | |||
@@ -33,7 +33,6 @@ | |||
33 | 33 | ||
34 | #include <linux/types.h> | 34 | #include <linux/types.h> |
35 | #include <linux/module.h> | 35 | #include <linux/module.h> |
36 | #include <linux/slab.h> | ||
37 | #include <linux/string.h> | 36 | #include <linux/string.h> |
38 | #include <linux/sunrpc/sched.h> | 37 | #include <linux/sunrpc/sched.h> |
39 | #include <linux/sunrpc/gss_asn1.h> | 38 | #include <linux/sunrpc/gss_asn1.h> |
diff --git a/net/sunrpc/auth_gss/gss_krb5_crypto.c b/net/sunrpc/auth_gss/gss_krb5_crypto.c index c93fca204558..e9b636176687 100644 --- a/net/sunrpc/auth_gss/gss_krb5_crypto.c +++ b/net/sunrpc/auth_gss/gss_krb5_crypto.c | |||
@@ -37,7 +37,6 @@ | |||
37 | #include <linux/err.h> | 37 | #include <linux/err.h> |
38 | #include <linux/types.h> | 38 | #include <linux/types.h> |
39 | #include <linux/mm.h> | 39 | #include <linux/mm.h> |
40 | #include <linux/slab.h> | ||
41 | #include <linux/scatterlist.h> | 40 | #include <linux/scatterlist.h> |
42 | #include <linux/crypto.h> | 41 | #include <linux/crypto.h> |
43 | #include <linux/highmem.h> | 42 | #include <linux/highmem.h> |
diff --git a/net/sunrpc/auth_gss/gss_krb5_seal.c b/net/sunrpc/auth_gss/gss_krb5_seal.c index b8f42ef7178e..88fe6e75ed7e 100644 --- a/net/sunrpc/auth_gss/gss_krb5_seal.c +++ b/net/sunrpc/auth_gss/gss_krb5_seal.c | |||
@@ -59,7 +59,6 @@ | |||
59 | */ | 59 | */ |
60 | 60 | ||
61 | #include <linux/types.h> | 61 | #include <linux/types.h> |
62 | #include <linux/slab.h> | ||
63 | #include <linux/jiffies.h> | 62 | #include <linux/jiffies.h> |
64 | #include <linux/sunrpc/gss_krb5.h> | 63 | #include <linux/sunrpc/gss_krb5.h> |
65 | #include <linux/random.h> | 64 | #include <linux/random.h> |
diff --git a/net/sunrpc/auth_gss/gss_krb5_seqnum.c b/net/sunrpc/auth_gss/gss_krb5_seqnum.c index 17562b4c35f6..6331cd6866ec 100644 --- a/net/sunrpc/auth_gss/gss_krb5_seqnum.c +++ b/net/sunrpc/auth_gss/gss_krb5_seqnum.c | |||
@@ -32,7 +32,6 @@ | |||
32 | */ | 32 | */ |
33 | 33 | ||
34 | #include <linux/types.h> | 34 | #include <linux/types.h> |
35 | #include <linux/slab.h> | ||
36 | #include <linux/sunrpc/gss_krb5.h> | 35 | #include <linux/sunrpc/gss_krb5.h> |
37 | #include <linux/crypto.h> | 36 | #include <linux/crypto.h> |
38 | 37 | ||
diff --git a/net/sunrpc/auth_gss/gss_krb5_unseal.c b/net/sunrpc/auth_gss/gss_krb5_unseal.c index 066ec73c84d6..ce6c247edad0 100644 --- a/net/sunrpc/auth_gss/gss_krb5_unseal.c +++ b/net/sunrpc/auth_gss/gss_krb5_unseal.c | |||
@@ -58,7 +58,6 @@ | |||
58 | */ | 58 | */ |
59 | 59 | ||
60 | #include <linux/types.h> | 60 | #include <linux/types.h> |
61 | #include <linux/slab.h> | ||
62 | #include <linux/jiffies.h> | 61 | #include <linux/jiffies.h> |
63 | #include <linux/sunrpc/gss_krb5.h> | 62 | #include <linux/sunrpc/gss_krb5.h> |
64 | #include <linux/crypto.h> | 63 | #include <linux/crypto.h> |
diff --git a/net/sunrpc/auth_gss/gss_krb5_wrap.c b/net/sunrpc/auth_gss/gss_krb5_wrap.c index ae8e69b59c4c..a6e905637e03 100644 --- a/net/sunrpc/auth_gss/gss_krb5_wrap.c +++ b/net/sunrpc/auth_gss/gss_krb5_wrap.c | |||
@@ -1,5 +1,4 @@ | |||
1 | #include <linux/types.h> | 1 | #include <linux/types.h> |
2 | #include <linux/slab.h> | ||
3 | #include <linux/jiffies.h> | 2 | #include <linux/jiffies.h> |
4 | #include <linux/sunrpc/gss_krb5.h> | 3 | #include <linux/sunrpc/gss_krb5.h> |
5 | #include <linux/random.h> | 4 | #include <linux/random.h> |
diff --git a/net/sunrpc/auth_gss/gss_spkm3_seal.c b/net/sunrpc/auth_gss/gss_spkm3_seal.c index c832712f8d55..5a3a65a0e2b4 100644 --- a/net/sunrpc/auth_gss/gss_spkm3_seal.c +++ b/net/sunrpc/auth_gss/gss_spkm3_seal.c | |||
@@ -34,7 +34,6 @@ | |||
34 | */ | 34 | */ |
35 | 35 | ||
36 | #include <linux/types.h> | 36 | #include <linux/types.h> |
37 | #include <linux/slab.h> | ||
38 | #include <linux/jiffies.h> | 37 | #include <linux/jiffies.h> |
39 | #include <linux/sunrpc/gss_spkm3.h> | 38 | #include <linux/sunrpc/gss_spkm3.h> |
40 | #include <linux/random.h> | 39 | #include <linux/random.h> |
diff --git a/net/sunrpc/auth_gss/gss_spkm3_token.c b/net/sunrpc/auth_gss/gss_spkm3_token.c index 3308157436d2..a99825d7caa0 100644 --- a/net/sunrpc/auth_gss/gss_spkm3_token.c +++ b/net/sunrpc/auth_gss/gss_spkm3_token.c | |||
@@ -223,7 +223,7 @@ spkm3_verify_mic_token(unsigned char **tokp, int *mic_hdrlen, unsigned char **ck | |||
223 | 223 | ||
224 | /* only support SPKM_MIC_TOK */ | 224 | /* only support SPKM_MIC_TOK */ |
225 | if((ptr[6] != 0x01) || (ptr[7] != 0x01)) { | 225 | if((ptr[6] != 0x01) || (ptr[7] != 0x01)) { |
226 | dprintk("RPC: ERROR unsupported SPKM3 token \n"); | 226 | dprintk("RPC: ERROR unsupported SPKM3 token\n"); |
227 | goto out; | 227 | goto out; |
228 | } | 228 | } |
229 | 229 | ||
diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c index e34bc531fcb9..b81e790ef9f4 100644 --- a/net/sunrpc/auth_gss/svcauth_gss.c +++ b/net/sunrpc/auth_gss/svcauth_gss.c | |||
@@ -37,6 +37,7 @@ | |||
37 | * | 37 | * |
38 | */ | 38 | */ |
39 | 39 | ||
40 | #include <linux/slab.h> | ||
40 | #include <linux/types.h> | 41 | #include <linux/types.h> |
41 | #include <linux/module.h> | 42 | #include <linux/module.h> |
42 | #include <linux/pagemap.h> | 43 | #include <linux/pagemap.h> |
diff --git a/net/sunrpc/auth_unix.c b/net/sunrpc/auth_unix.c index 46b2647c5bd2..aac2f8b4ee21 100644 --- a/net/sunrpc/auth_unix.c +++ b/net/sunrpc/auth_unix.c | |||
@@ -6,6 +6,7 @@ | |||
6 | * Copyright (C) 1996, Olaf Kirch <okir@monad.swb.de> | 6 | * Copyright (C) 1996, Olaf Kirch <okir@monad.swb.de> |
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include <linux/slab.h> | ||
9 | #include <linux/types.h> | 10 | #include <linux/types.h> |
10 | #include <linux/sched.h> | 11 | #include <linux/sched.h> |
11 | #include <linux/module.h> | 12 | #include <linux/module.h> |
diff --git a/net/sunrpc/backchannel_rqst.c b/net/sunrpc/backchannel_rqst.c index 553621fb2c41..cf06af3b63c6 100644 --- a/net/sunrpc/backchannel_rqst.c +++ b/net/sunrpc/backchannel_rqst.c | |||
@@ -22,6 +22,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
22 | ******************************************************************************/ | 22 | ******************************************************************************/ |
23 | 23 | ||
24 | #include <linux/tcp.h> | 24 | #include <linux/tcp.h> |
25 | #include <linux/slab.h> | ||
25 | #include <linux/sunrpc/xprt.h> | 26 | #include <linux/sunrpc/xprt.h> |
26 | 27 | ||
27 | #ifdef RPC_DEBUG | 28 | #ifdef RPC_DEBUG |
diff --git a/net/sunrpc/bc_svc.c b/net/sunrpc/bc_svc.c index 13f214f53120..7dcfe0cc3500 100644 --- a/net/sunrpc/bc_svc.c +++ b/net/sunrpc/bc_svc.c | |||
@@ -37,21 +37,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
37 | 37 | ||
38 | #define RPCDBG_FACILITY RPCDBG_SVCDSP | 38 | #define RPCDBG_FACILITY RPCDBG_SVCDSP |
39 | 39 | ||
40 | void bc_release_request(struct rpc_task *task) | ||
41 | { | ||
42 | struct rpc_rqst *req = task->tk_rqstp; | ||
43 | |||
44 | dprintk("RPC: bc_release_request: task= %p\n", task); | ||
45 | |||
46 | /* | ||
47 | * Release this request only if it's a backchannel | ||
48 | * preallocated request | ||
49 | */ | ||
50 | if (!bc_prealloc(req)) | ||
51 | return; | ||
52 | xprt_free_bc_request(req); | ||
53 | } | ||
54 | |||
55 | /* Empty callback ops */ | 40 | /* Empty callback ops */ |
56 | static const struct rpc_call_ops nfs41_callback_ops = { | 41 | static const struct rpc_call_ops nfs41_callback_ops = { |
57 | }; | 42 | }; |
@@ -75,7 +60,7 @@ int bc_send(struct rpc_rqst *req) | |||
75 | rpc_put_task(task); | 60 | rpc_put_task(task); |
76 | } | 61 | } |
77 | return ret; | 62 | return ret; |
78 | dprintk("RPC: bc_send ret= %d \n", ret); | 63 | dprintk("RPC: bc_send ret= %d\n", ret); |
79 | } | 64 | } |
80 | 65 | ||
81 | #endif /* CONFIG_NFS_V4_1 */ | 66 | #endif /* CONFIG_NFS_V4_1 */ |
diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c index 154034b675bd..19c9983d5360 100644 --- a/net/sunrpc/clnt.c +++ b/net/sunrpc/clnt.c | |||
@@ -659,6 +659,7 @@ struct rpc_task *rpc_run_bc_task(struct rpc_rqst *req, | |||
659 | task = rpc_new_task(&task_setup_data); | 659 | task = rpc_new_task(&task_setup_data); |
660 | if (!task) { | 660 | if (!task) { |
661 | xprt_free_bc_request(req); | 661 | xprt_free_bc_request(req); |
662 | task = ERR_PTR(-ENOMEM); | ||
662 | goto out; | 663 | goto out; |
663 | } | 664 | } |
664 | task->tk_rqstp = req; | 665 | task->tk_rqstp = req; |
diff --git a/net/sunrpc/rpc_pipe.c b/net/sunrpc/rpc_pipe.c index 9ea45383480e..20e30c6f8355 100644 --- a/net/sunrpc/rpc_pipe.c +++ b/net/sunrpc/rpc_pipe.c | |||
@@ -587,6 +587,8 @@ static struct dentry *__rpc_lookup_create_exclusive(struct dentry *parent, | |||
587 | struct dentry *dentry; | 587 | struct dentry *dentry; |
588 | 588 | ||
589 | dentry = __rpc_lookup_create(parent, name); | 589 | dentry = __rpc_lookup_create(parent, name); |
590 | if (IS_ERR(dentry)) | ||
591 | return dentry; | ||
590 | if (dentry->d_inode == NULL) | 592 | if (dentry->d_inode == NULL) |
591 | return dentry; | 593 | return dentry; |
592 | dput(dentry); | 594 | dput(dentry); |
@@ -999,19 +1001,14 @@ rpc_fill_super(struct super_block *sb, void *data, int silent) | |||
999 | inode = rpc_get_inode(sb, S_IFDIR | 0755); | 1001 | inode = rpc_get_inode(sb, S_IFDIR | 0755); |
1000 | if (!inode) | 1002 | if (!inode) |
1001 | return -ENOMEM; | 1003 | return -ENOMEM; |
1002 | root = d_alloc_root(inode); | 1004 | sb->s_root = root = d_alloc_root(inode); |
1003 | if (!root) { | 1005 | if (!root) { |
1004 | iput(inode); | 1006 | iput(inode); |
1005 | return -ENOMEM; | 1007 | return -ENOMEM; |
1006 | } | 1008 | } |
1007 | if (rpc_populate(root, files, RPCAUTH_lockd, RPCAUTH_RootEOF, NULL)) | 1009 | if (rpc_populate(root, files, RPCAUTH_lockd, RPCAUTH_RootEOF, NULL)) |
1008 | goto out; | 1010 | return -ENOMEM; |
1009 | sb->s_root = root; | ||
1010 | return 0; | 1011 | return 0; |
1011 | out: | ||
1012 | d_genocide(root); | ||
1013 | dput(root); | ||
1014 | return -ENOMEM; | ||
1015 | } | 1012 | } |
1016 | 1013 | ||
1017 | static int | 1014 | static int |
diff --git a/net/sunrpc/rpcb_clnt.c b/net/sunrpc/rpcb_clnt.c index 3e3772d8eb92..121105355f60 100644 --- a/net/sunrpc/rpcb_clnt.c +++ b/net/sunrpc/rpcb_clnt.c | |||
@@ -21,6 +21,7 @@ | |||
21 | #include <linux/kernel.h> | 21 | #include <linux/kernel.h> |
22 | #include <linux/errno.h> | 22 | #include <linux/errno.h> |
23 | #include <linux/mutex.h> | 23 | #include <linux/mutex.h> |
24 | #include <linux/slab.h> | ||
24 | #include <net/ipv6.h> | 25 | #include <net/ipv6.h> |
25 | 26 | ||
26 | #include <linux/sunrpc/clnt.h> | 27 | #include <linux/sunrpc/clnt.h> |
diff --git a/net/sunrpc/socklib.c b/net/sunrpc/socklib.c index a661a3acb37e..10b4319ebbca 100644 --- a/net/sunrpc/socklib.c +++ b/net/sunrpc/socklib.c | |||
@@ -8,6 +8,7 @@ | |||
8 | 8 | ||
9 | #include <linux/compiler.h> | 9 | #include <linux/compiler.h> |
10 | #include <linux/netdevice.h> | 10 | #include <linux/netdevice.h> |
11 | #include <linux/gfp.h> | ||
11 | #include <linux/skbuff.h> | 12 | #include <linux/skbuff.h> |
12 | #include <linux/types.h> | 13 | #include <linux/types.h> |
13 | #include <linux/pagemap.h> | 14 | #include <linux/pagemap.h> |
diff --git a/net/sunrpc/stats.c b/net/sunrpc/stats.c index 1b4e6791ecf3..5785d2037f45 100644 --- a/net/sunrpc/stats.c +++ b/net/sunrpc/stats.c | |||
@@ -13,6 +13,7 @@ | |||
13 | */ | 13 | */ |
14 | 14 | ||
15 | #include <linux/module.h> | 15 | #include <linux/module.h> |
16 | #include <linux/slab.h> | ||
16 | 17 | ||
17 | #include <linux/init.h> | 18 | #include <linux/init.h> |
18 | #include <linux/kernel.h> | 19 | #include <linux/kernel.h> |
diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c index 538ca433a56c..d9017d64597e 100644 --- a/net/sunrpc/svc.c +++ b/net/sunrpc/svc.c | |||
@@ -19,6 +19,7 @@ | |||
19 | #include <linux/interrupt.h> | 19 | #include <linux/interrupt.h> |
20 | #include <linux/module.h> | 20 | #include <linux/module.h> |
21 | #include <linux/kthread.h> | 21 | #include <linux/kthread.h> |
22 | #include <linux/slab.h> | ||
22 | 23 | ||
23 | #include <linux/sunrpc/types.h> | 24 | #include <linux/sunrpc/types.h> |
24 | #include <linux/sunrpc/xdr.h> | 25 | #include <linux/sunrpc/xdr.h> |
@@ -133,7 +134,7 @@ svc_pool_map_choose_mode(void) | |||
133 | return SVC_POOL_PERNODE; | 134 | return SVC_POOL_PERNODE; |
134 | } | 135 | } |
135 | 136 | ||
136 | node = any_online_node(node_online_map); | 137 | node = first_online_node; |
137 | if (nr_cpus_node(node) > 2) { | 138 | if (nr_cpus_node(node) > 2) { |
138 | /* | 139 | /* |
139 | * Non-trivial SMP, or CONFIG_NUMA on | 140 | * Non-trivial SMP, or CONFIG_NUMA on |
@@ -506,6 +507,10 @@ svc_init_buffer(struct svc_rqst *rqstp, unsigned int size) | |||
506 | { | 507 | { |
507 | unsigned int pages, arghi; | 508 | unsigned int pages, arghi; |
508 | 509 | ||
510 | /* bc_xprt uses fore channel allocated buffers */ | ||
511 | if (svc_is_backchannel(rqstp)) | ||
512 | return 1; | ||
513 | |||
509 | pages = size / PAGE_SIZE + 1; /* extra page as we hold both request and reply. | 514 | pages = size / PAGE_SIZE + 1; /* extra page as we hold both request and reply. |
510 | * We assume one is at most one page | 515 | * We assume one is at most one page |
511 | */ | 516 | */ |
diff --git a/net/sunrpc/svc_xprt.c b/net/sunrpc/svc_xprt.c index 7d1f9e928f69..061b2e0f9118 100644 --- a/net/sunrpc/svc_xprt.c +++ b/net/sunrpc/svc_xprt.c | |||
@@ -9,6 +9,7 @@ | |||
9 | #include <linux/errno.h> | 9 | #include <linux/errno.h> |
10 | #include <linux/freezer.h> | 10 | #include <linux/freezer.h> |
11 | #include <linux/kthread.h> | 11 | #include <linux/kthread.h> |
12 | #include <linux/slab.h> | ||
12 | #include <net/sock.h> | 13 | #include <net/sock.h> |
13 | #include <linux/sunrpc/stats.h> | 14 | #include <linux/sunrpc/stats.h> |
14 | #include <linux/sunrpc/svc_xprt.h> | 15 | #include <linux/sunrpc/svc_xprt.h> |
@@ -173,11 +174,13 @@ static struct svc_xprt *__svc_xpo_create(struct svc_xprt_class *xcl, | |||
173 | .sin_addr.s_addr = htonl(INADDR_ANY), | 174 | .sin_addr.s_addr = htonl(INADDR_ANY), |
174 | .sin_port = htons(port), | 175 | .sin_port = htons(port), |
175 | }; | 176 | }; |
177 | #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) | ||
176 | struct sockaddr_in6 sin6 = { | 178 | struct sockaddr_in6 sin6 = { |
177 | .sin6_family = AF_INET6, | 179 | .sin6_family = AF_INET6, |
178 | .sin6_addr = IN6ADDR_ANY_INIT, | 180 | .sin6_addr = IN6ADDR_ANY_INIT, |
179 | .sin6_port = htons(port), | 181 | .sin6_port = htons(port), |
180 | }; | 182 | }; |
183 | #endif /* defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) */ | ||
181 | struct sockaddr *sap; | 184 | struct sockaddr *sap; |
182 | size_t len; | 185 | size_t len; |
183 | 186 | ||
@@ -186,10 +189,12 @@ static struct svc_xprt *__svc_xpo_create(struct svc_xprt_class *xcl, | |||
186 | sap = (struct sockaddr *)&sin; | 189 | sap = (struct sockaddr *)&sin; |
187 | len = sizeof(sin); | 190 | len = sizeof(sin); |
188 | break; | 191 | break; |
192 | #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) | ||
189 | case PF_INET6: | 193 | case PF_INET6: |
190 | sap = (struct sockaddr *)&sin6; | 194 | sap = (struct sockaddr *)&sin6; |
191 | len = sizeof(sin6); | 195 | len = sizeof(sin6); |
192 | break; | 196 | break; |
197 | #endif /* defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) */ | ||
193 | default: | 198 | default: |
194 | return ERR_PTR(-EAFNOSUPPORT); | 199 | return ERR_PTR(-EAFNOSUPPORT); |
195 | } | 200 | } |
@@ -231,7 +236,10 @@ int svc_create_xprt(struct svc_serv *serv, const char *xprt_name, | |||
231 | err: | 236 | err: |
232 | spin_unlock(&svc_xprt_class_lock); | 237 | spin_unlock(&svc_xprt_class_lock); |
233 | dprintk("svc: transport %s not found\n", xprt_name); | 238 | dprintk("svc: transport %s not found\n", xprt_name); |
234 | return -ENOENT; | 239 | |
240 | /* This errno is exposed to user space. Provide a reasonable | ||
241 | * perror msg for a bad transport. */ | ||
242 | return -EPROTONOSUPPORT; | ||
235 | } | 243 | } |
236 | EXPORT_SYMBOL_GPL(svc_create_xprt); | 244 | EXPORT_SYMBOL_GPL(svc_create_xprt); |
237 | 245 | ||
@@ -699,8 +707,10 @@ int svc_recv(struct svc_rqst *rqstp, long timeout) | |||
699 | spin_unlock_bh(&pool->sp_lock); | 707 | spin_unlock_bh(&pool->sp_lock); |
700 | 708 | ||
701 | len = 0; | 709 | len = 0; |
702 | if (test_bit(XPT_LISTENER, &xprt->xpt_flags) && | 710 | if (test_bit(XPT_CLOSE, &xprt->xpt_flags)) { |
703 | !test_bit(XPT_CLOSE, &xprt->xpt_flags)) { | 711 | dprintk("svc_recv: found XPT_CLOSE\n"); |
712 | svc_delete_xprt(xprt); | ||
713 | } else if (test_bit(XPT_LISTENER, &xprt->xpt_flags)) { | ||
704 | struct svc_xprt *newxpt; | 714 | struct svc_xprt *newxpt; |
705 | newxpt = xprt->xpt_ops->xpo_accept(xprt); | 715 | newxpt = xprt->xpt_ops->xpo_accept(xprt); |
706 | if (newxpt) { | 716 | if (newxpt) { |
@@ -726,7 +736,7 @@ int svc_recv(struct svc_rqst *rqstp, long timeout) | |||
726 | svc_xprt_received(newxpt); | 736 | svc_xprt_received(newxpt); |
727 | } | 737 | } |
728 | svc_xprt_received(xprt); | 738 | svc_xprt_received(xprt); |
729 | } else if (!test_bit(XPT_CLOSE, &xprt->xpt_flags)) { | 739 | } else { |
730 | dprintk("svc: server %p, pool %u, transport %p, inuse=%d\n", | 740 | dprintk("svc: server %p, pool %u, transport %p, inuse=%d\n", |
731 | rqstp, pool->sp_id, xprt, | 741 | rqstp, pool->sp_id, xprt, |
732 | atomic_read(&xprt->xpt_ref.refcount)); | 742 | atomic_read(&xprt->xpt_ref.refcount)); |
@@ -739,11 +749,6 @@ int svc_recv(struct svc_rqst *rqstp, long timeout) | |||
739 | dprintk("svc: got len=%d\n", len); | 749 | dprintk("svc: got len=%d\n", len); |
740 | } | 750 | } |
741 | 751 | ||
742 | if (test_bit(XPT_CLOSE, &xprt->xpt_flags)) { | ||
743 | dprintk("svc_recv: found XPT_CLOSE\n"); | ||
744 | svc_delete_xprt(xprt); | ||
745 | } | ||
746 | |||
747 | /* No data, incomplete (TCP) read, or accept() */ | 752 | /* No data, incomplete (TCP) read, or accept() */ |
748 | if (len == 0 || len == -EAGAIN) { | 753 | if (len == 0 || len == -EAGAIN) { |
749 | rqstp->rq_res.len = 0; | 754 | rqstp->rq_res.len = 0; |
@@ -889,11 +894,8 @@ void svc_delete_xprt(struct svc_xprt *xprt) | |||
889 | if (test_bit(XPT_TEMP, &xprt->xpt_flags)) | 894 | if (test_bit(XPT_TEMP, &xprt->xpt_flags)) |
890 | serv->sv_tmpcnt--; | 895 | serv->sv_tmpcnt--; |
891 | 896 | ||
892 | for (dr = svc_deferred_dequeue(xprt); dr; | 897 | while ((dr = svc_deferred_dequeue(xprt)) != NULL) |
893 | dr = svc_deferred_dequeue(xprt)) { | ||
894 | svc_xprt_put(xprt); | ||
895 | kfree(dr); | 898 | kfree(dr); |
896 | } | ||
897 | 899 | ||
898 | svc_xprt_put(xprt); | 900 | svc_xprt_put(xprt); |
899 | spin_unlock_bh(&serv->sv_lock); | 901 | spin_unlock_bh(&serv->sv_lock); |
diff --git a/net/sunrpc/svcauth_unix.c b/net/sunrpc/svcauth_unix.c index d8c041114497..207311610988 100644 --- a/net/sunrpc/svcauth_unix.c +++ b/net/sunrpc/svcauth_unix.c | |||
@@ -10,11 +10,13 @@ | |||
10 | #include <linux/seq_file.h> | 10 | #include <linux/seq_file.h> |
11 | #include <linux/hash.h> | 11 | #include <linux/hash.h> |
12 | #include <linux/string.h> | 12 | #include <linux/string.h> |
13 | #include <linux/slab.h> | ||
13 | #include <net/sock.h> | 14 | #include <net/sock.h> |
14 | #include <net/ipv6.h> | 15 | #include <net/ipv6.h> |
15 | #include <linux/kernel.h> | 16 | #include <linux/kernel.h> |
16 | #define RPCDBG_FACILITY RPCDBG_AUTH | 17 | #define RPCDBG_FACILITY RPCDBG_AUTH |
17 | 18 | ||
19 | #include <linux/sunrpc/clnt.h> | ||
18 | 20 | ||
19 | /* | 21 | /* |
20 | * AUTHUNIX and AUTHNULL credentials are both handled here. | 22 | * AUTHUNIX and AUTHNULL credentials are both handled here. |
@@ -187,10 +189,13 @@ static int ip_map_parse(struct cache_detail *cd, | |||
187 | * for scratch: */ | 189 | * for scratch: */ |
188 | char *buf = mesg; | 190 | char *buf = mesg; |
189 | int len; | 191 | int len; |
190 | int b1, b2, b3, b4, b5, b6, b7, b8; | ||
191 | char c; | ||
192 | char class[8]; | 192 | char class[8]; |
193 | struct in6_addr addr; | 193 | union { |
194 | struct sockaddr sa; | ||
195 | struct sockaddr_in s4; | ||
196 | struct sockaddr_in6 s6; | ||
197 | } address; | ||
198 | struct sockaddr_in6 sin6; | ||
194 | int err; | 199 | int err; |
195 | 200 | ||
196 | struct ip_map *ipmp; | 201 | struct ip_map *ipmp; |
@@ -209,24 +214,24 @@ static int ip_map_parse(struct cache_detail *cd, | |||
209 | len = qword_get(&mesg, buf, mlen); | 214 | len = qword_get(&mesg, buf, mlen); |
210 | if (len <= 0) return -EINVAL; | 215 | if (len <= 0) return -EINVAL; |
211 | 216 | ||
212 | if (sscanf(buf, "%u.%u.%u.%u%c", &b1, &b2, &b3, &b4, &c) == 4) { | 217 | if (rpc_pton(buf, len, &address.sa, sizeof(address)) == 0) |
213 | addr.s6_addr32[0] = 0; | ||
214 | addr.s6_addr32[1] = 0; | ||
215 | addr.s6_addr32[2] = htonl(0xffff); | ||
216 | addr.s6_addr32[3] = | ||
217 | htonl((((((b1<<8)|b2)<<8)|b3)<<8)|b4); | ||
218 | } else if (sscanf(buf, "%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x%c", | ||
219 | &b1, &b2, &b3, &b4, &b5, &b6, &b7, &b8, &c) == 8) { | ||
220 | addr.s6_addr16[0] = htons(b1); | ||
221 | addr.s6_addr16[1] = htons(b2); | ||
222 | addr.s6_addr16[2] = htons(b3); | ||
223 | addr.s6_addr16[3] = htons(b4); | ||
224 | addr.s6_addr16[4] = htons(b5); | ||
225 | addr.s6_addr16[5] = htons(b6); | ||
226 | addr.s6_addr16[6] = htons(b7); | ||
227 | addr.s6_addr16[7] = htons(b8); | ||
228 | } else | ||
229 | return -EINVAL; | 218 | return -EINVAL; |
219 | switch (address.sa.sa_family) { | ||
220 | case AF_INET: | ||
221 | /* Form a mapped IPv4 address in sin6 */ | ||
222 | memset(&sin6, 0, sizeof(sin6)); | ||
223 | sin6.sin6_family = AF_INET6; | ||
224 | sin6.sin6_addr.s6_addr32[2] = htonl(0xffff); | ||
225 | sin6.sin6_addr.s6_addr32[3] = address.s4.sin_addr.s_addr; | ||
226 | break; | ||
227 | #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) | ||
228 | case AF_INET6: | ||
229 | memcpy(&sin6, &address.s6, sizeof(sin6)); | ||
230 | break; | ||
231 | #endif | ||
232 | default: | ||
233 | return -EINVAL; | ||
234 | } | ||
230 | 235 | ||
231 | expiry = get_expiry(&mesg); | 236 | expiry = get_expiry(&mesg); |
232 | if (expiry ==0) | 237 | if (expiry ==0) |
@@ -243,7 +248,8 @@ static int ip_map_parse(struct cache_detail *cd, | |||
243 | } else | 248 | } else |
244 | dom = NULL; | 249 | dom = NULL; |
245 | 250 | ||
246 | ipmp = ip_map_lookup(class, &addr); | 251 | /* IPv6 scope IDs are ignored for now */ |
252 | ipmp = ip_map_lookup(class, &sin6.sin6_addr); | ||
247 | if (ipmp) { | 253 | if (ipmp) { |
248 | err = ip_map_update(ipmp, | 254 | err = ip_map_update(ipmp, |
249 | container_of(dom, struct unix_domain, h), | 255 | container_of(dom, struct unix_domain, h), |
@@ -619,7 +625,7 @@ static int unix_gid_show(struct seq_file *m, | |||
619 | else | 625 | else |
620 | glen = 0; | 626 | glen = 0; |
621 | 627 | ||
622 | seq_printf(m, "%d %d:", ug->uid, glen); | 628 | seq_printf(m, "%u %d:", ug->uid, glen); |
623 | for (i = 0; i < glen; i++) | 629 | for (i = 0; i < glen; i++) |
624 | seq_printf(m, " %d", GROUP_AT(ug->gi, i)); | 630 | seq_printf(m, " %d", GROUP_AT(ug->gi, i)); |
625 | seq_printf(m, "\n"); | 631 | seq_printf(m, "\n"); |
diff --git a/net/sunrpc/svcsock.c b/net/sunrpc/svcsock.c index 870929e08e5d..a29f259204e6 100644 --- a/net/sunrpc/svcsock.c +++ b/net/sunrpc/svcsock.c | |||
@@ -968,6 +968,7 @@ static int svc_tcp_recv_record(struct svc_sock *svsk, struct svc_rqst *rqstp) | |||
968 | return len; | 968 | return len; |
969 | err_delete: | 969 | err_delete: |
970 | set_bit(XPT_CLOSE, &svsk->sk_xprt.xpt_flags); | 970 | set_bit(XPT_CLOSE, &svsk->sk_xprt.xpt_flags); |
971 | svc_xprt_received(&svsk->sk_xprt); | ||
971 | err_again: | 972 | err_again: |
972 | return -EAGAIN; | 973 | return -EAGAIN; |
973 | } | 974 | } |
@@ -1357,7 +1358,7 @@ int svc_addsock(struct svc_serv *serv, const int fd, char *name_return, | |||
1357 | 1358 | ||
1358 | if (!so) | 1359 | if (!so) |
1359 | return err; | 1360 | return err; |
1360 | if (so->sk->sk_family != AF_INET) | 1361 | if ((so->sk->sk_family != PF_INET) && (so->sk->sk_family != PF_INET6)) |
1361 | err = -EAFNOSUPPORT; | 1362 | err = -EAFNOSUPPORT; |
1362 | else if (so->sk->sk_protocol != IPPROTO_TCP && | 1363 | else if (so->sk->sk_protocol != IPPROTO_TCP && |
1363 | so->sk->sk_protocol != IPPROTO_UDP) | 1364 | so->sk->sk_protocol != IPPROTO_UDP) |
diff --git a/net/sunrpc/xdr.c b/net/sunrpc/xdr.c index 8bd690c48b69..2763fde88499 100644 --- a/net/sunrpc/xdr.c +++ b/net/sunrpc/xdr.c | |||
@@ -7,6 +7,7 @@ | |||
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include <linux/module.h> | 9 | #include <linux/module.h> |
10 | #include <linux/slab.h> | ||
10 | #include <linux/types.h> | 11 | #include <linux/types.h> |
11 | #include <linux/string.h> | 12 | #include <linux/string.h> |
12 | #include <linux/kernel.h> | 13 | #include <linux/kernel.h> |
diff --git a/net/sunrpc/xprt.c b/net/sunrpc/xprt.c index 469de292c23c..42f09ade0044 100644 --- a/net/sunrpc/xprt.c +++ b/net/sunrpc/xprt.c | |||
@@ -46,6 +46,7 @@ | |||
46 | 46 | ||
47 | #include <linux/sunrpc/clnt.h> | 47 | #include <linux/sunrpc/clnt.h> |
48 | #include <linux/sunrpc/metrics.h> | 48 | #include <linux/sunrpc/metrics.h> |
49 | #include <linux/sunrpc/bc_xprt.h> | ||
49 | 50 | ||
50 | #include "sunrpc.h" | 51 | #include "sunrpc.h" |
51 | 52 | ||
@@ -1032,21 +1033,16 @@ void xprt_release(struct rpc_task *task) | |||
1032 | if (req->rq_release_snd_buf) | 1033 | if (req->rq_release_snd_buf) |
1033 | req->rq_release_snd_buf(req); | 1034 | req->rq_release_snd_buf(req); |
1034 | 1035 | ||
1035 | /* | ||
1036 | * Early exit if this is a backchannel preallocated request. | ||
1037 | * There is no need to have it added to the RPC slot list. | ||
1038 | */ | ||
1039 | if (is_bc_request) | ||
1040 | return; | ||
1041 | |||
1042 | memset(req, 0, sizeof(*req)); /* mark unused */ | ||
1043 | |||
1044 | dprintk("RPC: %5u release request %p\n", task->tk_pid, req); | 1036 | dprintk("RPC: %5u release request %p\n", task->tk_pid, req); |
1037 | if (likely(!is_bc_request)) { | ||
1038 | memset(req, 0, sizeof(*req)); /* mark unused */ | ||
1045 | 1039 | ||
1046 | spin_lock(&xprt->reserve_lock); | 1040 | spin_lock(&xprt->reserve_lock); |
1047 | list_add(&req->rq_list, &xprt->free); | 1041 | list_add(&req->rq_list, &xprt->free); |
1048 | rpc_wake_up_next(&xprt->backlog); | 1042 | rpc_wake_up_next(&xprt->backlog); |
1049 | spin_unlock(&xprt->reserve_lock); | 1043 | spin_unlock(&xprt->reserve_lock); |
1044 | } else | ||
1045 | xprt_free_bc_request(req); | ||
1050 | } | 1046 | } |
1051 | 1047 | ||
1052 | /** | 1048 | /** |
diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c index 5b8a8ff93a25..d718b8fa9525 100644 --- a/net/sunrpc/xprtrdma/svc_rdma.c +++ b/net/sunrpc/xprtrdma/svc_rdma.c | |||
@@ -40,6 +40,7 @@ | |||
40 | */ | 40 | */ |
41 | #include <linux/module.h> | 41 | #include <linux/module.h> |
42 | #include <linux/init.h> | 42 | #include <linux/init.h> |
43 | #include <linux/slab.h> | ||
43 | #include <linux/fs.h> | 44 | #include <linux/fs.h> |
44 | #include <linux/sysctl.h> | 45 | #include <linux/sysctl.h> |
45 | #include <linux/sunrpc/clnt.h> | 46 | #include <linux/sunrpc/clnt.h> |
diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c index 3fa5751af0ec..fd90eb89842b 100644 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c | |||
@@ -43,6 +43,7 @@ | |||
43 | #include <linux/sunrpc/debug.h> | 43 | #include <linux/sunrpc/debug.h> |
44 | #include <linux/sunrpc/rpc_rdma.h> | 44 | #include <linux/sunrpc/rpc_rdma.h> |
45 | #include <linux/sched.h> | 45 | #include <linux/sched.h> |
46 | #include <linux/slab.h> | ||
46 | #include <linux/spinlock.h> | 47 | #include <linux/spinlock.h> |
47 | #include <rdma/ib_verbs.h> | 48 | #include <rdma/ib_verbs.h> |
48 | #include <rdma/rdma_cm.h> | 49 | #include <rdma/rdma_cm.h> |
diff --git a/net/sunrpc/xprtrdma/transport.c b/net/sunrpc/xprtrdma/transport.c index f96c2fe6137b..187257b1d880 100644 --- a/net/sunrpc/xprtrdma/transport.c +++ b/net/sunrpc/xprtrdma/transport.c | |||
@@ -49,6 +49,7 @@ | |||
49 | 49 | ||
50 | #include <linux/module.h> | 50 | #include <linux/module.h> |
51 | #include <linux/init.h> | 51 | #include <linux/init.h> |
52 | #include <linux/slab.h> | ||
52 | #include <linux/seq_file.h> | 53 | #include <linux/seq_file.h> |
53 | 54 | ||
54 | #include "xprt_rdma.h" | 55 | #include "xprt_rdma.h" |
diff --git a/net/sunrpc/xprtrdma/verbs.c b/net/sunrpc/xprtrdma/verbs.c index 2209aa87d899..27015c6d8eb5 100644 --- a/net/sunrpc/xprtrdma/verbs.c +++ b/net/sunrpc/xprtrdma/verbs.c | |||
@@ -48,6 +48,7 @@ | |||
48 | */ | 48 | */ |
49 | 49 | ||
50 | #include <linux/pci.h> /* for Tavor hack below */ | 50 | #include <linux/pci.h> /* for Tavor hack below */ |
51 | #include <linux/slab.h> | ||
51 | 52 | ||
52 | #include "xprt_rdma.h" | 53 | #include "xprt_rdma.h" |
53 | 54 | ||
diff --git a/net/sunrpc/xprtsock.c b/net/sunrpc/xprtsock.c index 4f55ab7ec1b1..9847c30b5001 100644 --- a/net/sunrpc/xprtsock.c +++ b/net/sunrpc/xprtsock.c | |||
@@ -548,8 +548,6 @@ static int xs_udp_send_request(struct rpc_task *task) | |||
548 | /* Still some bytes left; set up for a retry later. */ | 548 | /* Still some bytes left; set up for a retry later. */ |
549 | status = -EAGAIN; | 549 | status = -EAGAIN; |
550 | } | 550 | } |
551 | if (!transport->sock) | ||
552 | goto out; | ||
553 | 551 | ||
554 | switch (status) { | 552 | switch (status) { |
555 | case -ENOTSOCK: | 553 | case -ENOTSOCK: |
@@ -569,7 +567,7 @@ static int xs_udp_send_request(struct rpc_task *task) | |||
569 | * prompts ECONNREFUSED. */ | 567 | * prompts ECONNREFUSED. */ |
570 | clear_bit(SOCK_ASYNC_NOSPACE, &transport->sock->flags); | 568 | clear_bit(SOCK_ASYNC_NOSPACE, &transport->sock->flags); |
571 | } | 569 | } |
572 | out: | 570 | |
573 | return status; | 571 | return status; |
574 | } | 572 | } |
575 | 573 | ||
@@ -651,8 +649,6 @@ static int xs_tcp_send_request(struct rpc_task *task) | |||
651 | status = -EAGAIN; | 649 | status = -EAGAIN; |
652 | break; | 650 | break; |
653 | } | 651 | } |
654 | if (!transport->sock) | ||
655 | goto out; | ||
656 | 652 | ||
657 | switch (status) { | 653 | switch (status) { |
658 | case -ENOTSOCK: | 654 | case -ENOTSOCK: |
@@ -672,7 +668,7 @@ static int xs_tcp_send_request(struct rpc_task *task) | |||
672 | case -ENOTCONN: | 668 | case -ENOTCONN: |
673 | clear_bit(SOCK_ASYNC_NOSPACE, &transport->sock->flags); | 669 | clear_bit(SOCK_ASYNC_NOSPACE, &transport->sock->flags); |
674 | } | 670 | } |
675 | out: | 671 | |
676 | return status; | 672 | return status; |
677 | } | 673 | } |
678 | 674 | ||
@@ -1911,6 +1907,11 @@ static void xs_tcp_setup_socket(struct rpc_xprt *xprt, | |||
1911 | case -EALREADY: | 1907 | case -EALREADY: |
1912 | xprt_clear_connecting(xprt); | 1908 | xprt_clear_connecting(xprt); |
1913 | return; | 1909 | return; |
1910 | case -EINVAL: | ||
1911 | /* Happens, for instance, if the user specified a link | ||
1912 | * local IPv6 address without a scope-id. | ||
1913 | */ | ||
1914 | goto out; | ||
1914 | } | 1915 | } |
1915 | out_eagain: | 1916 | out_eagain: |
1916 | status = -EAGAIN; | 1917 | status = -EAGAIN; |
@@ -2099,7 +2100,7 @@ static void xs_tcp_print_stats(struct rpc_xprt *xprt, struct seq_file *seq) | |||
2099 | * we allocate pages instead doing a kmalloc like rpc_malloc is because we want | 2100 | * we allocate pages instead doing a kmalloc like rpc_malloc is because we want |
2100 | * to use the server side send routines. | 2101 | * to use the server side send routines. |
2101 | */ | 2102 | */ |
2102 | void *bc_malloc(struct rpc_task *task, size_t size) | 2103 | static void *bc_malloc(struct rpc_task *task, size_t size) |
2103 | { | 2104 | { |
2104 | struct page *page; | 2105 | struct page *page; |
2105 | struct rpc_buffer *buf; | 2106 | struct rpc_buffer *buf; |
@@ -2119,7 +2120,7 @@ void *bc_malloc(struct rpc_task *task, size_t size) | |||
2119 | /* | 2120 | /* |
2120 | * Free the space allocated in the bc_alloc routine | 2121 | * Free the space allocated in the bc_alloc routine |
2121 | */ | 2122 | */ |
2122 | void bc_free(void *buffer) | 2123 | static void bc_free(void *buffer) |
2123 | { | 2124 | { |
2124 | struct rpc_buffer *buf; | 2125 | struct rpc_buffer *buf; |
2125 | 2126 | ||
@@ -2250,9 +2251,6 @@ static struct rpc_xprt_ops xs_tcp_ops = { | |||
2250 | .buf_free = rpc_free, | 2251 | .buf_free = rpc_free, |
2251 | .send_request = xs_tcp_send_request, | 2252 | .send_request = xs_tcp_send_request, |
2252 | .set_retrans_timeout = xprt_set_retrans_timeout_def, | 2253 | .set_retrans_timeout = xprt_set_retrans_timeout_def, |
2253 | #if defined(CONFIG_NFS_V4_1) | ||
2254 | .release_request = bc_release_request, | ||
2255 | #endif /* CONFIG_NFS_V4_1 */ | ||
2256 | .close = xs_tcp_close, | 2254 | .close = xs_tcp_close, |
2257 | .destroy = xs_destroy, | 2255 | .destroy = xs_destroy, |
2258 | .print_stats = xs_tcp_print_stats, | 2256 | .print_stats = xs_tcp_print_stats, |
diff --git a/net/tipc/bcast.c b/net/tipc/bcast.c index a3bfd4064912..90a051912c03 100644 --- a/net/tipc/bcast.c +++ b/net/tipc/bcast.c | |||
@@ -558,10 +558,7 @@ static int tipc_bcbearer_send(struct sk_buff *buf, | |||
558 | struct tipc_bearer *unused1, | 558 | struct tipc_bearer *unused1, |
559 | struct tipc_media_addr *unused2) | 559 | struct tipc_media_addr *unused2) |
560 | { | 560 | { |
561 | static int send_count = 0; | ||
562 | |||
563 | int bp_index; | 561 | int bp_index; |
564 | int swap_time; | ||
565 | 562 | ||
566 | /* Prepare buffer for broadcasting (if first time trying to send it) */ | 563 | /* Prepare buffer for broadcasting (if first time trying to send it) */ |
567 | 564 | ||
@@ -575,11 +572,6 @@ static int tipc_bcbearer_send(struct sk_buff *buf, | |||
575 | msg_set_mc_netid(msg, tipc_net_id); | 572 | msg_set_mc_netid(msg, tipc_net_id); |
576 | } | 573 | } |
577 | 574 | ||
578 | /* Determine if bearer pairs should be swapped following this attempt */ | ||
579 | |||
580 | if ((swap_time = (++send_count >= 10))) | ||
581 | send_count = 0; | ||
582 | |||
583 | /* Send buffer over bearers until all targets reached */ | 575 | /* Send buffer over bearers until all targets reached */ |
584 | 576 | ||
585 | bcbearer->remains = tipc_cltr_bcast_nodes; | 577 | bcbearer->remains = tipc_cltr_bcast_nodes; |
@@ -595,21 +587,22 @@ static int tipc_bcbearer_send(struct sk_buff *buf, | |||
595 | if (bcbearer->remains_new.count == bcbearer->remains.count) | 587 | if (bcbearer->remains_new.count == bcbearer->remains.count) |
596 | continue; /* bearer pair doesn't add anything */ | 588 | continue; /* bearer pair doesn't add anything */ |
597 | 589 | ||
598 | if (!p->publ.blocked && | 590 | if (p->publ.blocked || |
599 | !p->media->send_msg(buf, &p->publ, &p->media->bcast_addr)) { | 591 | p->media->send_msg(buf, &p->publ, &p->media->bcast_addr)) { |
600 | if (swap_time && s && !s->publ.blocked) | 592 | /* unable to send on primary bearer */ |
601 | goto swap; | 593 | if (!s || s->publ.blocked || |
602 | else | 594 | s->media->send_msg(buf, &s->publ, |
603 | goto update; | 595 | &s->media->bcast_addr)) { |
596 | /* unable to send on either bearer */ | ||
597 | continue; | ||
598 | } | ||
599 | } | ||
600 | |||
601 | if (s) { | ||
602 | bcbearer->bpairs[bp_index].primary = s; | ||
603 | bcbearer->bpairs[bp_index].secondary = p; | ||
604 | } | 604 | } |
605 | 605 | ||
606 | if (!s || s->publ.blocked || | ||
607 | s->media->send_msg(buf, &s->publ, &s->media->bcast_addr)) | ||
608 | continue; /* unable to send using bearer pair */ | ||
609 | swap: | ||
610 | bcbearer->bpairs[bp_index].primary = s; | ||
611 | bcbearer->bpairs[bp_index].secondary = p; | ||
612 | update: | ||
613 | if (bcbearer->remains_new.count == 0) | 606 | if (bcbearer->remains_new.count == 0) |
614 | return 0; | 607 | return 0; |
615 | 608 | ||
diff --git a/net/tipc/core.c b/net/tipc/core.c index 52c571fedbe0..4e84c8431f32 100644 --- a/net/tipc/core.c +++ b/net/tipc/core.c | |||
@@ -49,7 +49,7 @@ | |||
49 | #include "config.h" | 49 | #include "config.h" |
50 | 50 | ||
51 | 51 | ||
52 | #define TIPC_MOD_VER "1.6.4" | 52 | #define TIPC_MOD_VER "2.0.0" |
53 | 53 | ||
54 | #ifndef CONFIG_TIPC_ZONES | 54 | #ifndef CONFIG_TIPC_ZONES |
55 | #define CONFIG_TIPC_ZONES 3 | 55 | #define CONFIG_TIPC_ZONES 3 |
diff --git a/net/tipc/core.h b/net/tipc/core.h index a881f92a8537..c58a1d16563a 100644 --- a/net/tipc/core.h +++ b/net/tipc/core.h | |||
@@ -56,6 +56,7 @@ | |||
56 | #include <linux/netdevice.h> | 56 | #include <linux/netdevice.h> |
57 | #include <linux/in.h> | 57 | #include <linux/in.h> |
58 | #include <linux/list.h> | 58 | #include <linux/list.h> |
59 | #include <linux/slab.h> | ||
59 | #include <linux/vmalloc.h> | 60 | #include <linux/vmalloc.h> |
60 | 61 | ||
61 | /* | 62 | /* |
diff --git a/net/tipc/eth_media.c b/net/tipc/eth_media.c index 524ba5696d4d..6230d16020c4 100644 --- a/net/tipc/eth_media.c +++ b/net/tipc/eth_media.c | |||
@@ -38,6 +38,7 @@ | |||
38 | #include <net/tipc/tipc_bearer.h> | 38 | #include <net/tipc/tipc_bearer.h> |
39 | #include <net/tipc/tipc_msg.h> | 39 | #include <net/tipc/tipc_msg.h> |
40 | #include <linux/netdevice.h> | 40 | #include <linux/netdevice.h> |
41 | #include <linux/slab.h> | ||
41 | #include <net/net_namespace.h> | 42 | #include <net/net_namespace.h> |
42 | 43 | ||
43 | #define MAX_ETH_BEARERS 2 | 44 | #define MAX_ETH_BEARERS 2 |
diff --git a/net/tipc/link.c b/net/tipc/link.c index 1a7e4665af80..c76e82e5f982 100644 --- a/net/tipc/link.c +++ b/net/tipc/link.c | |||
@@ -877,7 +877,7 @@ static void link_state_event(struct link *l_ptr, unsigned event) | |||
877 | case TIMEOUT_EVT: | 877 | case TIMEOUT_EVT: |
878 | dbg_link("TIM "); | 878 | dbg_link("TIM "); |
879 | if (l_ptr->next_in_no != l_ptr->checkpoint) { | 879 | if (l_ptr->next_in_no != l_ptr->checkpoint) { |
880 | dbg_link("-> WW \n"); | 880 | dbg_link("-> WW\n"); |
881 | l_ptr->state = WORKING_WORKING; | 881 | l_ptr->state = WORKING_WORKING; |
882 | l_ptr->fsm_msg_cnt = 0; | 882 | l_ptr->fsm_msg_cnt = 0; |
883 | l_ptr->checkpoint = l_ptr->next_in_no; | 883 | l_ptr->checkpoint = l_ptr->next_in_no; |
@@ -934,7 +934,7 @@ static void link_state_event(struct link *l_ptr, unsigned event) | |||
934 | link_set_timer(l_ptr, cont_intv); | 934 | link_set_timer(l_ptr, cont_intv); |
935 | break; | 935 | break; |
936 | case RESET_MSG: | 936 | case RESET_MSG: |
937 | dbg_link("RES \n"); | 937 | dbg_link("RES\n"); |
938 | dbg_link(" -> RR\n"); | 938 | dbg_link(" -> RR\n"); |
939 | l_ptr->state = RESET_RESET; | 939 | l_ptr->state = RESET_RESET; |
940 | l_ptr->fsm_msg_cnt = 0; | 940 | l_ptr->fsm_msg_cnt = 0; |
@@ -947,7 +947,7 @@ static void link_state_event(struct link *l_ptr, unsigned event) | |||
947 | l_ptr->started = 1; | 947 | l_ptr->started = 1; |
948 | /* fall through */ | 948 | /* fall through */ |
949 | case TIMEOUT_EVT: | 949 | case TIMEOUT_EVT: |
950 | dbg_link("TIM \n"); | 950 | dbg_link("TIM\n"); |
951 | tipc_link_send_proto_msg(l_ptr, RESET_MSG, 0, 0, 0, 0, 0); | 951 | tipc_link_send_proto_msg(l_ptr, RESET_MSG, 0, 0, 0, 0, 0); |
952 | l_ptr->fsm_msg_cnt++; | 952 | l_ptr->fsm_msg_cnt++; |
953 | link_set_timer(l_ptr, cont_intv); | 953 | link_set_timer(l_ptr, cont_intv); |
@@ -1553,7 +1553,7 @@ u32 tipc_link_push_packet(struct link *l_ptr) | |||
1553 | 1553 | ||
1554 | /* Continue retransmission now, if there is anything: */ | 1554 | /* Continue retransmission now, if there is anything: */ |
1555 | 1555 | ||
1556 | if (r_q_size && buf && !skb_cloned(buf)) { | 1556 | if (r_q_size && buf) { |
1557 | msg_set_ack(buf_msg(buf), mod(l_ptr->next_in_no - 1)); | 1557 | msg_set_ack(buf_msg(buf), mod(l_ptr->next_in_no - 1)); |
1558 | msg_set_bcast_ack(buf_msg(buf), l_ptr->owner->bclink.last_in); | 1558 | msg_set_bcast_ack(buf_msg(buf), l_ptr->owner->bclink.last_in); |
1559 | if (tipc_bearer_send(l_ptr->b_ptr, buf, &l_ptr->media_addr)) { | 1559 | if (tipc_bearer_send(l_ptr->b_ptr, buf, &l_ptr->media_addr)) { |
@@ -1722,15 +1722,16 @@ void tipc_link_retransmit(struct link *l_ptr, struct sk_buff *buf, | |||
1722 | dbg("Retransmitting %u in link %x\n", retransmits, l_ptr); | 1722 | dbg("Retransmitting %u in link %x\n", retransmits, l_ptr); |
1723 | 1723 | ||
1724 | if (tipc_bearer_congested(l_ptr->b_ptr, l_ptr)) { | 1724 | if (tipc_bearer_congested(l_ptr->b_ptr, l_ptr)) { |
1725 | if (!skb_cloned(buf)) { | 1725 | if (l_ptr->retransm_queue_size == 0) { |
1726 | msg_dbg(msg, ">NO_RETR->BCONG>"); | 1726 | msg_dbg(msg, ">NO_RETR->BCONG>"); |
1727 | dbg_print_link(l_ptr, " "); | 1727 | dbg_print_link(l_ptr, " "); |
1728 | l_ptr->retransm_queue_head = msg_seqno(msg); | 1728 | l_ptr->retransm_queue_head = msg_seqno(msg); |
1729 | l_ptr->retransm_queue_size = retransmits; | 1729 | l_ptr->retransm_queue_size = retransmits; |
1730 | return; | ||
1731 | } else { | 1730 | } else { |
1732 | /* Don't retransmit if driver already has the buffer */ | 1731 | err("Unexpected retransmit on link %s (qsize=%d)\n", |
1732 | l_ptr->name, l_ptr->retransm_queue_size); | ||
1733 | } | 1733 | } |
1734 | return; | ||
1734 | } else { | 1735 | } else { |
1735 | /* Detect repeated retransmit failures on uncongested bearer */ | 1736 | /* Detect repeated retransmit failures on uncongested bearer */ |
1736 | 1737 | ||
@@ -1745,7 +1746,7 @@ void tipc_link_retransmit(struct link *l_ptr, struct sk_buff *buf, | |||
1745 | } | 1746 | } |
1746 | } | 1747 | } |
1747 | 1748 | ||
1748 | while (retransmits && (buf != l_ptr->next_out) && buf && !skb_cloned(buf)) { | 1749 | while (retransmits && (buf != l_ptr->next_out) && buf) { |
1749 | msg = buf_msg(buf); | 1750 | msg = buf_msg(buf); |
1750 | msg_set_ack(msg, mod(l_ptr->next_in_no - 1)); | 1751 | msg_set_ack(msg, mod(l_ptr->next_in_no - 1)); |
1751 | msg_set_bcast_ack(msg, l_ptr->owner->bclink.last_in); | 1752 | msg_set_bcast_ack(msg, l_ptr->owner->bclink.last_in); |
@@ -3294,7 +3295,7 @@ static void link_dump_rec_queue(struct link *l_ptr) | |||
3294 | info("buffer %x invalid\n", crs); | 3295 | info("buffer %x invalid\n", crs); |
3295 | return; | 3296 | return; |
3296 | } | 3297 | } |
3297 | msg_dbg(buf_msg(crs), "In rec queue: \n"); | 3298 | msg_dbg(buf_msg(crs), "In rec queue:\n"); |
3298 | crs = crs->next; | 3299 | crs = crs->next; |
3299 | } | 3300 | } |
3300 | } | 3301 | } |
diff --git a/net/tipc/net.c b/net/tipc/net.c index f25b1cdb64eb..d7cd1e064a80 100644 --- a/net/tipc/net.c +++ b/net/tipc/net.c | |||
@@ -116,7 +116,7 @@ | |||
116 | */ | 116 | */ |
117 | 117 | ||
118 | DEFINE_RWLOCK(tipc_net_lock); | 118 | DEFINE_RWLOCK(tipc_net_lock); |
119 | struct _zone *tipc_zones[256] = { NULL, }; | 119 | static struct _zone *tipc_zones[256] = { NULL, }; |
120 | struct network tipc_net = { tipc_zones }; | 120 | struct network tipc_net = { tipc_zones }; |
121 | 121 | ||
122 | struct tipc_node *tipc_net_select_remote_node(u32 addr, u32 ref) | 122 | struct tipc_node *tipc_net_select_remote_node(u32 addr, u32 ref) |
@@ -291,6 +291,6 @@ void tipc_net_stop(void) | |||
291 | tipc_bclink_stop(); | 291 | tipc_bclink_stop(); |
292 | net_stop(); | 292 | net_stop(); |
293 | write_unlock_bh(&tipc_net_lock); | 293 | write_unlock_bh(&tipc_net_lock); |
294 | info("Left network mode \n"); | 294 | info("Left network mode\n"); |
295 | } | 295 | } |
296 | 296 | ||
diff --git a/net/tipc/node.c b/net/tipc/node.c index 2c24e7d6d950..17cc394f424f 100644 --- a/net/tipc/node.c +++ b/net/tipc/node.c | |||
@@ -278,7 +278,7 @@ struct tipc_node *tipc_node_attach_link(struct link *l_ptr) | |||
278 | n_ptr->link_cnt++; | 278 | n_ptr->link_cnt++; |
279 | return n_ptr; | 279 | return n_ptr; |
280 | } | 280 | } |
281 | err("Attempt to establish second link on <%s> to %s \n", | 281 | err("Attempt to establish second link on <%s> to %s\n", |
282 | l_ptr->b_ptr->publ.name, | 282 | l_ptr->b_ptr->publ.name, |
283 | addr_string_fill(addr_string, l_ptr->addr)); | 283 | addr_string_fill(addr_string, l_ptr->addr)); |
284 | } | 284 | } |
diff --git a/net/tipc/ref.c b/net/tipc/ref.c index 414fc34b8bea..8dea66500cf5 100644 --- a/net/tipc/ref.c +++ b/net/tipc/ref.c | |||
@@ -153,11 +153,11 @@ void tipc_ref_table_stop(void) | |||
153 | 153 | ||
154 | u32 tipc_ref_acquire(void *object, spinlock_t **lock) | 154 | u32 tipc_ref_acquire(void *object, spinlock_t **lock) |
155 | { | 155 | { |
156 | struct reference *entry; | ||
157 | u32 index; | 156 | u32 index; |
158 | u32 index_mask; | 157 | u32 index_mask; |
159 | u32 next_plus_upper; | 158 | u32 next_plus_upper; |
160 | u32 ref; | 159 | u32 ref; |
160 | struct reference *entry = NULL; | ||
161 | 161 | ||
162 | if (!object) { | 162 | if (!object) { |
163 | err("Attempt to acquire reference to non-existent object\n"); | 163 | err("Attempt to acquire reference to non-existent object\n"); |
@@ -175,30 +175,36 @@ u32 tipc_ref_acquire(void *object, spinlock_t **lock) | |||
175 | index = tipc_ref_table.first_free; | 175 | index = tipc_ref_table.first_free; |
176 | entry = &(tipc_ref_table.entries[index]); | 176 | entry = &(tipc_ref_table.entries[index]); |
177 | index_mask = tipc_ref_table.index_mask; | 177 | index_mask = tipc_ref_table.index_mask; |
178 | /* take lock in case a previous user of entry still holds it */ | ||
179 | spin_lock_bh(&entry->lock); | ||
180 | next_plus_upper = entry->ref; | 178 | next_plus_upper = entry->ref; |
181 | tipc_ref_table.first_free = next_plus_upper & index_mask; | 179 | tipc_ref_table.first_free = next_plus_upper & index_mask; |
182 | ref = (next_plus_upper & ~index_mask) + index; | 180 | ref = (next_plus_upper & ~index_mask) + index; |
183 | entry->ref = ref; | ||
184 | entry->object = object; | ||
185 | *lock = &entry->lock; | ||
186 | } | 181 | } |
187 | else if (tipc_ref_table.init_point < tipc_ref_table.capacity) { | 182 | else if (tipc_ref_table.init_point < tipc_ref_table.capacity) { |
188 | index = tipc_ref_table.init_point++; | 183 | index = tipc_ref_table.init_point++; |
189 | entry = &(tipc_ref_table.entries[index]); | 184 | entry = &(tipc_ref_table.entries[index]); |
190 | spin_lock_init(&entry->lock); | 185 | spin_lock_init(&entry->lock); |
191 | spin_lock_bh(&entry->lock); | ||
192 | ref = tipc_ref_table.start_mask + index; | 186 | ref = tipc_ref_table.start_mask + index; |
193 | entry->ref = ref; | ||
194 | entry->object = object; | ||
195 | *lock = &entry->lock; | ||
196 | } | 187 | } |
197 | else { | 188 | else { |
198 | ref = 0; | 189 | ref = 0; |
199 | } | 190 | } |
200 | write_unlock_bh(&ref_table_lock); | 191 | write_unlock_bh(&ref_table_lock); |
201 | 192 | ||
193 | /* | ||
194 | * Grab the lock so no one else can modify this entry | ||
195 | * While we assign its ref value & object pointer | ||
196 | */ | ||
197 | if (entry) { | ||
198 | spin_lock_bh(&entry->lock); | ||
199 | entry->ref = ref; | ||
200 | entry->object = object; | ||
201 | *lock = &entry->lock; | ||
202 | /* | ||
203 | * keep it locked, the caller is responsible | ||
204 | * for unlocking this when they're done with it | ||
205 | */ | ||
206 | } | ||
207 | |||
202 | return ref; | 208 | return ref; |
203 | } | 209 | } |
204 | 210 | ||
diff --git a/net/tipc/socket.c b/net/tipc/socket.c index 4b235fc1c70f..cfb20b80b3a1 100644 --- a/net/tipc/socket.c +++ b/net/tipc/socket.c | |||
@@ -40,9 +40,9 @@ | |||
40 | #include <linux/socket.h> | 40 | #include <linux/socket.h> |
41 | #include <linux/errno.h> | 41 | #include <linux/errno.h> |
42 | #include <linux/mm.h> | 42 | #include <linux/mm.h> |
43 | #include <linux/slab.h> | ||
44 | #include <linux/poll.h> | 43 | #include <linux/poll.h> |
45 | #include <linux/fcntl.h> | 44 | #include <linux/fcntl.h> |
45 | #include <linux/gfp.h> | ||
46 | #include <asm/string.h> | 46 | #include <asm/string.h> |
47 | #include <asm/atomic.h> | 47 | #include <asm/atomic.h> |
48 | #include <net/sock.h> | 48 | #include <net/sock.h> |
diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c index ff123e56114a..ab6eab4c45e2 100644 --- a/net/tipc/subscr.c +++ b/net/tipc/subscr.c | |||
@@ -274,7 +274,7 @@ static void subscr_cancel(struct tipc_subscr *s, | |||
274 | { | 274 | { |
275 | struct subscription *sub; | 275 | struct subscription *sub; |
276 | struct subscription *sub_temp; | 276 | struct subscription *sub_temp; |
277 | __u32 type, lower, upper; | 277 | __u32 type, lower, upper, timeout, filter; |
278 | int found = 0; | 278 | int found = 0; |
279 | 279 | ||
280 | /* Find first matching subscription, exit if not found */ | 280 | /* Find first matching subscription, exit if not found */ |
@@ -282,12 +282,18 @@ static void subscr_cancel(struct tipc_subscr *s, | |||
282 | type = ntohl(s->seq.type); | 282 | type = ntohl(s->seq.type); |
283 | lower = ntohl(s->seq.lower); | 283 | lower = ntohl(s->seq.lower); |
284 | upper = ntohl(s->seq.upper); | 284 | upper = ntohl(s->seq.upper); |
285 | timeout = ntohl(s->timeout); | ||
286 | filter = ntohl(s->filter) & ~TIPC_SUB_CANCEL; | ||
285 | 287 | ||
286 | list_for_each_entry_safe(sub, sub_temp, &subscriber->subscription_list, | 288 | list_for_each_entry_safe(sub, sub_temp, &subscriber->subscription_list, |
287 | subscription_list) { | 289 | subscription_list) { |
288 | if ((type == sub->seq.type) && | 290 | if ((type == sub->seq.type) && |
289 | (lower == sub->seq.lower) && | 291 | (lower == sub->seq.lower) && |
290 | (upper == sub->seq.upper)) { | 292 | (upper == sub->seq.upper) && |
293 | (timeout == sub->timeout) && | ||
294 | (filter == sub->filter) && | ||
295 | !memcmp(s->usr_handle,sub->evt.s.usr_handle, | ||
296 | sizeof(s->usr_handle)) ){ | ||
291 | found = 1; | 297 | found = 1; |
292 | break; | 298 | break; |
293 | } | 299 | } |
@@ -304,7 +310,7 @@ static void subscr_cancel(struct tipc_subscr *s, | |||
304 | k_term_timer(&sub->timer); | 310 | k_term_timer(&sub->timer); |
305 | spin_lock_bh(subscriber->lock); | 311 | spin_lock_bh(subscriber->lock); |
306 | } | 312 | } |
307 | dbg("Cancel: removing sub %u,%u,%u from subscriber %x list\n", | 313 | dbg("Cancel: removing sub %u,%u,%u from subscriber %p list\n", |
308 | sub->seq.type, sub->seq.lower, sub->seq.upper, subscriber); | 314 | sub->seq.type, sub->seq.lower, sub->seq.upper, subscriber); |
309 | subscr_del(sub); | 315 | subscr_del(sub); |
310 | } | 316 | } |
@@ -352,8 +358,7 @@ static struct subscription *subscr_subscribe(struct tipc_subscr *s, | |||
352 | sub->seq.upper = ntohl(s->seq.upper); | 358 | sub->seq.upper = ntohl(s->seq.upper); |
353 | sub->timeout = ntohl(s->timeout); | 359 | sub->timeout = ntohl(s->timeout); |
354 | sub->filter = ntohl(s->filter); | 360 | sub->filter = ntohl(s->filter); |
355 | if ((!(sub->filter & TIPC_SUB_PORTS) == | 361 | if ((sub->filter && (sub->filter != TIPC_SUB_PORTS)) || |
356 | !(sub->filter & TIPC_SUB_SERVICE)) || | ||
357 | (sub->seq.lower > sub->seq.upper)) { | 362 | (sub->seq.lower > sub->seq.upper)) { |
358 | warn("Subscription rejected, illegal request\n"); | 363 | warn("Subscription rejected, illegal request\n"); |
359 | kfree(sub); | 364 | kfree(sub); |
diff --git a/net/unix/garbage.c b/net/unix/garbage.c index 19c17e4a0c8b..14c22c3768da 100644 --- a/net/unix/garbage.c +++ b/net/unix/garbage.c | |||
@@ -74,7 +74,6 @@ | |||
74 | #include <linux/un.h> | 74 | #include <linux/un.h> |
75 | #include <linux/net.h> | 75 | #include <linux/net.h> |
76 | #include <linux/fs.h> | 76 | #include <linux/fs.h> |
77 | #include <linux/slab.h> | ||
78 | #include <linux/skbuff.h> | 77 | #include <linux/skbuff.h> |
79 | #include <linux/netdevice.h> | 78 | #include <linux/netdevice.h> |
80 | #include <linux/file.h> | 79 | #include <linux/file.h> |
diff --git a/net/unix/sysctl_net_unix.c b/net/unix/sysctl_net_unix.c index d095c7be10d0..397cffebb3b6 100644 --- a/net/unix/sysctl_net_unix.c +++ b/net/unix/sysctl_net_unix.c | |||
@@ -10,6 +10,7 @@ | |||
10 | */ | 10 | */ |
11 | 11 | ||
12 | #include <linux/mm.h> | 12 | #include <linux/mm.h> |
13 | #include <linux/slab.h> | ||
13 | #include <linux/sysctl.h> | 14 | #include <linux/sysctl.h> |
14 | 15 | ||
15 | #include <net/af_unix.h> | 16 | #include <net/af_unix.h> |
diff --git a/net/wimax/op-msg.c b/net/wimax/op-msg.c index 7718657e93dc..d5b7c3779c43 100644 --- a/net/wimax/op-msg.c +++ b/net/wimax/op-msg.c | |||
@@ -72,6 +72,7 @@ | |||
72 | * wimax_msg_send() | 72 | * wimax_msg_send() |
73 | */ | 73 | */ |
74 | #include <linux/device.h> | 74 | #include <linux/device.h> |
75 | #include <linux/slab.h> | ||
75 | #include <net/genetlink.h> | 76 | #include <net/genetlink.h> |
76 | #include <linux/netdevice.h> | 77 | #include <linux/netdevice.h> |
77 | #include <linux/wimax.h> | 78 | #include <linux/wimax.h> |
diff --git a/net/wimax/op-reset.c b/net/wimax/op-reset.c index 4dc82a54ba30..68bedf3e5443 100644 --- a/net/wimax/op-reset.c +++ b/net/wimax/op-reset.c | |||
@@ -110,7 +110,6 @@ int wimax_gnl_doit_reset(struct sk_buff *skb, struct genl_info *info) | |||
110 | { | 110 | { |
111 | int result, ifindex; | 111 | int result, ifindex; |
112 | struct wimax_dev *wimax_dev; | 112 | struct wimax_dev *wimax_dev; |
113 | struct device *dev; | ||
114 | 113 | ||
115 | d_fnstart(3, NULL, "(skb %p info %p)\n", skb, info); | 114 | d_fnstart(3, NULL, "(skb %p info %p)\n", skb, info); |
116 | result = -ENODEV; | 115 | result = -ENODEV; |
@@ -123,7 +122,6 @@ int wimax_gnl_doit_reset(struct sk_buff *skb, struct genl_info *info) | |||
123 | wimax_dev = wimax_dev_get_by_genl_info(info, ifindex); | 122 | wimax_dev = wimax_dev_get_by_genl_info(info, ifindex); |
124 | if (wimax_dev == NULL) | 123 | if (wimax_dev == NULL) |
125 | goto error_no_wimax_dev; | 124 | goto error_no_wimax_dev; |
126 | dev = wimax_dev_to_dev(wimax_dev); | ||
127 | /* Execute the operation and send the result back to user space */ | 125 | /* Execute the operation and send the result back to user space */ |
128 | result = wimax_reset(wimax_dev); | 126 | result = wimax_reset(wimax_dev); |
129 | dev_put(wimax_dev->net_dev); | 127 | dev_put(wimax_dev->net_dev); |
diff --git a/net/wimax/op-state-get.c b/net/wimax/op-state-get.c index 11ad3356eb56..aff8776e2d41 100644 --- a/net/wimax/op-state-get.c +++ b/net/wimax/op-state-get.c | |||
@@ -53,7 +53,6 @@ int wimax_gnl_doit_state_get(struct sk_buff *skb, struct genl_info *info) | |||
53 | { | 53 | { |
54 | int result, ifindex; | 54 | int result, ifindex; |
55 | struct wimax_dev *wimax_dev; | 55 | struct wimax_dev *wimax_dev; |
56 | struct device *dev; | ||
57 | 56 | ||
58 | d_fnstart(3, NULL, "(skb %p info %p)\n", skb, info); | 57 | d_fnstart(3, NULL, "(skb %p info %p)\n", skb, info); |
59 | result = -ENODEV; | 58 | result = -ENODEV; |
@@ -66,7 +65,6 @@ int wimax_gnl_doit_state_get(struct sk_buff *skb, struct genl_info *info) | |||
66 | wimax_dev = wimax_dev_get_by_genl_info(info, ifindex); | 65 | wimax_dev = wimax_dev_get_by_genl_info(info, ifindex); |
67 | if (wimax_dev == NULL) | 66 | if (wimax_dev == NULL) |
68 | goto error_no_wimax_dev; | 67 | goto error_no_wimax_dev; |
69 | dev = wimax_dev_to_dev(wimax_dev); | ||
70 | /* Execute the operation and send the result back to user space */ | 68 | /* Execute the operation and send the result back to user space */ |
71 | result = wimax_state_get(wimax_dev); | 69 | result = wimax_state_get(wimax_dev); |
72 | dev_put(wimax_dev->net_dev); | 70 | dev_put(wimax_dev->net_dev); |
diff --git a/net/wimax/stack.c b/net/wimax/stack.c index 813e1eaea29b..1ed65dbdab03 100644 --- a/net/wimax/stack.c +++ b/net/wimax/stack.c | |||
@@ -51,6 +51,7 @@ | |||
51 | * wimax_rfkill_rm() | 51 | * wimax_rfkill_rm() |
52 | */ | 52 | */ |
53 | #include <linux/device.h> | 53 | #include <linux/device.h> |
54 | #include <linux/gfp.h> | ||
54 | #include <net/genetlink.h> | 55 | #include <net/genetlink.h> |
55 | #include <linux/netdevice.h> | 56 | #include <linux/netdevice.h> |
56 | #include <linux/wimax.h> | 57 | #include <linux/wimax.h> |
diff --git a/net/wireless/core.c b/net/wireless/core.c index 7fdb9409ad2a..6ac70c101523 100644 --- a/net/wireless/core.c +++ b/net/wireless/core.c | |||
@@ -8,6 +8,7 @@ | |||
8 | #include <linux/module.h> | 8 | #include <linux/module.h> |
9 | #include <linux/err.h> | 9 | #include <linux/err.h> |
10 | #include <linux/list.h> | 10 | #include <linux/list.h> |
11 | #include <linux/slab.h> | ||
11 | #include <linux/nl80211.h> | 12 | #include <linux/nl80211.h> |
12 | #include <linux/debugfs.h> | 13 | #include <linux/debugfs.h> |
13 | #include <linux/notifier.h> | 14 | #include <linux/notifier.h> |
diff --git a/net/wireless/debugfs.c b/net/wireless/debugfs.c index 2e4895615037..a4991a3efec0 100644 --- a/net/wireless/debugfs.c +++ b/net/wireless/debugfs.c | |||
@@ -9,6 +9,7 @@ | |||
9 | * published by the Free Software Foundation. | 9 | * published by the Free Software Foundation. |
10 | */ | 10 | */ |
11 | 11 | ||
12 | #include <linux/slab.h> | ||
12 | #include "core.h" | 13 | #include "core.h" |
13 | #include "debugfs.h" | 14 | #include "debugfs.h" |
14 | 15 | ||
diff --git a/net/wireless/ibss.c b/net/wireless/ibss.c index 6ef5a491fb4b..6a5acf750174 100644 --- a/net/wireless/ibss.c +++ b/net/wireless/ibss.c | |||
@@ -6,6 +6,7 @@ | |||
6 | 6 | ||
7 | #include <linux/etherdevice.h> | 7 | #include <linux/etherdevice.h> |
8 | #include <linux/if_arp.h> | 8 | #include <linux/if_arp.h> |
9 | #include <linux/slab.h> | ||
9 | #include <net/cfg80211.h> | 10 | #include <net/cfg80211.h> |
10 | #include "wext-compat.h" | 11 | #include "wext-compat.h" |
11 | #include "nl80211.h" | 12 | #include "nl80211.h" |
diff --git a/net/wireless/mlme.c b/net/wireless/mlme.c index 387dd2a27d2f..48ead6f0426d 100644 --- a/net/wireless/mlme.c +++ b/net/wireless/mlme.c | |||
@@ -8,6 +8,7 @@ | |||
8 | #include <linux/module.h> | 8 | #include <linux/module.h> |
9 | #include <linux/netdevice.h> | 9 | #include <linux/netdevice.h> |
10 | #include <linux/nl80211.h> | 10 | #include <linux/nl80211.h> |
11 | #include <linux/slab.h> | ||
11 | #include <linux/wireless.h> | 12 | #include <linux/wireless.h> |
12 | #include <net/cfg80211.h> | 13 | #include <net/cfg80211.h> |
13 | #include <net/iw_handler.h> | 14 | #include <net/iw_handler.h> |
diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index df5505b3930c..356a84a5daee 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c | |||
@@ -7,6 +7,7 @@ | |||
7 | #include <linux/if.h> | 7 | #include <linux/if.h> |
8 | #include <linux/module.h> | 8 | #include <linux/module.h> |
9 | #include <linux/err.h> | 9 | #include <linux/err.h> |
10 | #include <linux/slab.h> | ||
10 | #include <linux/list.h> | 11 | #include <linux/list.h> |
11 | #include <linux/if_ether.h> | 12 | #include <linux/if_ether.h> |
12 | #include <linux/ieee80211.h> | 13 | #include <linux/ieee80211.h> |
diff --git a/net/wireless/reg.c b/net/wireless/reg.c index 496348c48506..8f0d97dd3109 100644 --- a/net/wireless/reg.c +++ b/net/wireless/reg.c | |||
@@ -33,6 +33,7 @@ | |||
33 | * | 33 | * |
34 | */ | 34 | */ |
35 | #include <linux/kernel.h> | 35 | #include <linux/kernel.h> |
36 | #include <linux/slab.h> | ||
36 | #include <linux/list.h> | 37 | #include <linux/list.h> |
37 | #include <linux/random.h> | 38 | #include <linux/random.h> |
38 | #include <linux/nl80211.h> | 39 | #include <linux/nl80211.h> |
diff --git a/net/wireless/scan.c b/net/wireless/scan.c index 978cac3414b5..a026c6d56bd3 100644 --- a/net/wireless/scan.c +++ b/net/wireless/scan.c | |||
@@ -4,6 +4,7 @@ | |||
4 | * Copyright 2008 Johannes Berg <johannes@sipsolutions.net> | 4 | * Copyright 2008 Johannes Berg <johannes@sipsolutions.net> |
5 | */ | 5 | */ |
6 | #include <linux/kernel.h> | 6 | #include <linux/kernel.h> |
7 | #include <linux/slab.h> | ||
7 | #include <linux/module.h> | 8 | #include <linux/module.h> |
8 | #include <linux/netdevice.h> | 9 | #include <linux/netdevice.h> |
9 | #include <linux/wireless.h> | 10 | #include <linux/wireless.h> |
diff --git a/net/wireless/sme.c b/net/wireless/sme.c index 17465777eb47..c2735775ec19 100644 --- a/net/wireless/sme.c +++ b/net/wireless/sme.c | |||
@@ -7,6 +7,7 @@ | |||
7 | 7 | ||
8 | #include <linux/etherdevice.h> | 8 | #include <linux/etherdevice.h> |
9 | #include <linux/if_arp.h> | 9 | #include <linux/if_arp.h> |
10 | #include <linux/slab.h> | ||
10 | #include <linux/workqueue.h> | 11 | #include <linux/workqueue.h> |
11 | #include <linux/wireless.h> | 12 | #include <linux/wireless.h> |
12 | #include <net/iw_handler.h> | 13 | #include <net/iw_handler.h> |
diff --git a/net/wireless/util.c b/net/wireless/util.c index 7acb81b9675d..3416373a9c0c 100644 --- a/net/wireless/util.c +++ b/net/wireless/util.c | |||
@@ -5,6 +5,7 @@ | |||
5 | */ | 5 | */ |
6 | #include <linux/bitops.h> | 6 | #include <linux/bitops.h> |
7 | #include <linux/etherdevice.h> | 7 | #include <linux/etherdevice.h> |
8 | #include <linux/slab.h> | ||
8 | #include <net/cfg80211.h> | 9 | #include <net/cfg80211.h> |
9 | #include <net/ip.h> | 10 | #include <net/ip.h> |
10 | #include "core.h" | 11 | #include "core.h" |
diff --git a/net/wireless/wext-compat.c b/net/wireless/wext-compat.c index 9ab51838849e..a60a2773b497 100644 --- a/net/wireless/wext-compat.c +++ b/net/wireless/wext-compat.c | |||
@@ -12,6 +12,7 @@ | |||
12 | #include <linux/nl80211.h> | 12 | #include <linux/nl80211.h> |
13 | #include <linux/if_arp.h> | 13 | #include <linux/if_arp.h> |
14 | #include <linux/etherdevice.h> | 14 | #include <linux/etherdevice.h> |
15 | #include <linux/slab.h> | ||
15 | #include <net/iw_handler.h> | 16 | #include <net/iw_handler.h> |
16 | #include <net/cfg80211.h> | 17 | #include <net/cfg80211.h> |
17 | #include "wext-compat.h" | 18 | #include "wext-compat.h" |
diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c index bfcbeee23f9c..0ef17bc42bac 100644 --- a/net/wireless/wext-core.c +++ b/net/wireless/wext-core.c | |||
@@ -10,6 +10,7 @@ | |||
10 | #include <linux/kernel.h> | 10 | #include <linux/kernel.h> |
11 | #include <linux/netdevice.h> | 11 | #include <linux/netdevice.h> |
12 | #include <linux/rtnetlink.h> | 12 | #include <linux/rtnetlink.h> |
13 | #include <linux/slab.h> | ||
13 | #include <linux/wireless.h> | 14 | #include <linux/wireless.h> |
14 | #include <linux/uaccess.h> | 15 | #include <linux/uaccess.h> |
15 | #include <net/cfg80211.h> | 16 | #include <net/cfg80211.h> |
diff --git a/net/wireless/wext-priv.c b/net/wireless/wext-priv.c index a3c2277de9e5..3feb28e41c53 100644 --- a/net/wireless/wext-priv.c +++ b/net/wireless/wext-priv.c | |||
@@ -7,6 +7,7 @@ | |||
7 | * | 7 | * |
8 | * (As all part of the Linux kernel, this file is GPL) | 8 | * (As all part of the Linux kernel, this file is GPL) |
9 | */ | 9 | */ |
10 | #include <linux/slab.h> | ||
10 | #include <linux/wireless.h> | 11 | #include <linux/wireless.h> |
11 | #include <linux/netdevice.h> | 12 | #include <linux/netdevice.h> |
12 | #include <net/iw_handler.h> | 13 | #include <net/iw_handler.h> |
diff --git a/net/wireless/wext-sme.c b/net/wireless/wext-sme.c index 5615a8802536..d5c6140f4cb8 100644 --- a/net/wireless/wext-sme.c +++ b/net/wireless/wext-sme.c | |||
@@ -7,6 +7,7 @@ | |||
7 | 7 | ||
8 | #include <linux/etherdevice.h> | 8 | #include <linux/etherdevice.h> |
9 | #include <linux/if_arp.h> | 9 | #include <linux/if_arp.h> |
10 | #include <linux/slab.h> | ||
10 | #include <net/cfg80211.h> | 11 | #include <net/cfg80211.h> |
11 | #include "wext-compat.h" | 12 | #include "wext-compat.h" |
12 | #include "nl80211.h" | 13 | #include "nl80211.h" |
diff --git a/net/x25/af_x25.c b/net/x25/af_x25.c index 9796f3ed1edb..cbddd0cb83f1 100644 --- a/net/x25/af_x25.c +++ b/net/x25/af_x25.c | |||
@@ -47,6 +47,7 @@ | |||
47 | #include <linux/netdevice.h> | 47 | #include <linux/netdevice.h> |
48 | #include <linux/if_arp.h> | 48 | #include <linux/if_arp.h> |
49 | #include <linux/skbuff.h> | 49 | #include <linux/skbuff.h> |
50 | #include <linux/slab.h> | ||
50 | #include <net/sock.h> | 51 | #include <net/sock.h> |
51 | #include <net/tcp_states.h> | 52 | #include <net/tcp_states.h> |
52 | #include <asm/uaccess.h> | 53 | #include <asm/uaccess.h> |
@@ -82,6 +83,41 @@ struct compat_x25_subscrip_struct { | |||
82 | }; | 83 | }; |
83 | #endif | 84 | #endif |
84 | 85 | ||
86 | |||
87 | int x25_parse_address_block(struct sk_buff *skb, | ||
88 | struct x25_address *called_addr, | ||
89 | struct x25_address *calling_addr) | ||
90 | { | ||
91 | unsigned char len; | ||
92 | int needed; | ||
93 | int rc; | ||
94 | |||
95 | if (skb->len < 1) { | ||
96 | /* packet has no address block */ | ||
97 | rc = 0; | ||
98 | goto empty; | ||
99 | } | ||
100 | |||
101 | len = *skb->data; | ||
102 | needed = 1 + (len >> 4) + (len & 0x0f); | ||
103 | |||
104 | if (skb->len < needed) { | ||
105 | /* packet is too short to hold the addresses it claims | ||
106 | to hold */ | ||
107 | rc = -1; | ||
108 | goto empty; | ||
109 | } | ||
110 | |||
111 | return x25_addr_ntoa(skb->data, called_addr, calling_addr); | ||
112 | |||
113 | empty: | ||
114 | *called_addr->x25_addr = 0; | ||
115 | *calling_addr->x25_addr = 0; | ||
116 | |||
117 | return rc; | ||
118 | } | ||
119 | |||
120 | |||
85 | int x25_addr_ntoa(unsigned char *p, struct x25_address *called_addr, | 121 | int x25_addr_ntoa(unsigned char *p, struct x25_address *called_addr, |
86 | struct x25_address *calling_addr) | 122 | struct x25_address *calling_addr) |
87 | { | 123 | { |
@@ -553,7 +589,8 @@ static int x25_create(struct net *net, struct socket *sock, int protocol, | |||
553 | x25->facilities.winsize_out = X25_DEFAULT_WINDOW_SIZE; | 589 | x25->facilities.winsize_out = X25_DEFAULT_WINDOW_SIZE; |
554 | x25->facilities.pacsize_in = X25_DEFAULT_PACKET_SIZE; | 590 | x25->facilities.pacsize_in = X25_DEFAULT_PACKET_SIZE; |
555 | x25->facilities.pacsize_out = X25_DEFAULT_PACKET_SIZE; | 591 | x25->facilities.pacsize_out = X25_DEFAULT_PACKET_SIZE; |
556 | x25->facilities.throughput = X25_DEFAULT_THROUGHPUT; | 592 | x25->facilities.throughput = 0; /* by default don't negotiate |
593 | throughput */ | ||
557 | x25->facilities.reverse = X25_DEFAULT_REVERSE; | 594 | x25->facilities.reverse = X25_DEFAULT_REVERSE; |
558 | x25->dte_facilities.calling_len = 0; | 595 | x25->dte_facilities.calling_len = 0; |
559 | x25->dte_facilities.called_len = 0; | 596 | x25->dte_facilities.called_len = 0; |
@@ -921,16 +958,26 @@ int x25_rx_call_request(struct sk_buff *skb, struct x25_neigh *nb, | |||
921 | /* | 958 | /* |
922 | * Extract the X.25 addresses and convert them to ASCII strings, | 959 | * Extract the X.25 addresses and convert them to ASCII strings, |
923 | * and remove them. | 960 | * and remove them. |
961 | * | ||
962 | * Address block is mandatory in call request packets | ||
924 | */ | 963 | */ |
925 | addr_len = x25_addr_ntoa(skb->data, &source_addr, &dest_addr); | 964 | addr_len = x25_parse_address_block(skb, &source_addr, &dest_addr); |
965 | if (addr_len <= 0) | ||
966 | goto out_clear_request; | ||
926 | skb_pull(skb, addr_len); | 967 | skb_pull(skb, addr_len); |
927 | 968 | ||
928 | /* | 969 | /* |
929 | * Get the length of the facilities, skip past them for the moment | 970 | * Get the length of the facilities, skip past them for the moment |
930 | * get the call user data because this is needed to determine | 971 | * get the call user data because this is needed to determine |
931 | * the correct listener | 972 | * the correct listener |
973 | * | ||
974 | * Facilities length is mandatory in call request packets | ||
932 | */ | 975 | */ |
976 | if (skb->len < 1) | ||
977 | goto out_clear_request; | ||
933 | len = skb->data[0] + 1; | 978 | len = skb->data[0] + 1; |
979 | if (skb->len < len) | ||
980 | goto out_clear_request; | ||
934 | skb_pull(skb,len); | 981 | skb_pull(skb,len); |
935 | 982 | ||
936 | /* | 983 | /* |
@@ -1414,9 +1461,20 @@ static int x25_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) | |||
1414 | if (facilities.winsize_in < 1 || | 1461 | if (facilities.winsize_in < 1 || |
1415 | facilities.winsize_in > 127) | 1462 | facilities.winsize_in > 127) |
1416 | break; | 1463 | break; |
1417 | if (facilities.throughput < 0x03 || | 1464 | if (facilities.throughput) { |
1418 | facilities.throughput > 0xDD) | 1465 | int out = facilities.throughput & 0xf0; |
1419 | break; | 1466 | int in = facilities.throughput & 0x0f; |
1467 | if (!out) | ||
1468 | facilities.throughput |= | ||
1469 | X25_DEFAULT_THROUGHPUT << 4; | ||
1470 | else if (out < 0x30 || out > 0xD0) | ||
1471 | break; | ||
1472 | if (!in) | ||
1473 | facilities.throughput |= | ||
1474 | X25_DEFAULT_THROUGHPUT; | ||
1475 | else if (in < 0x03 || in > 0x0D) | ||
1476 | break; | ||
1477 | } | ||
1420 | if (facilities.reverse && | 1478 | if (facilities.reverse && |
1421 | (facilities.reverse & 0x81) != 0x81) | 1479 | (facilities.reverse & 0x81) != 0x81) |
1422 | break; | 1480 | break; |
diff --git a/net/x25/x25_dev.c b/net/x25/x25_dev.c index 52e304212241..b9ef682230a0 100644 --- a/net/x25/x25_dev.c +++ b/net/x25/x25_dev.c | |||
@@ -20,6 +20,7 @@ | |||
20 | #include <linux/kernel.h> | 20 | #include <linux/kernel.h> |
21 | #include <linux/netdevice.h> | 21 | #include <linux/netdevice.h> |
22 | #include <linux/skbuff.h> | 22 | #include <linux/skbuff.h> |
23 | #include <linux/slab.h> | ||
23 | #include <net/sock.h> | 24 | #include <net/sock.h> |
24 | #include <linux/if_arp.h> | 25 | #include <linux/if_arp.h> |
25 | #include <net/x25.h> | 26 | #include <net/x25.h> |
diff --git a/net/x25/x25_facilities.c b/net/x25/x25_facilities.c index a21f6646eb3a..771bab00754b 100644 --- a/net/x25/x25_facilities.c +++ b/net/x25/x25_facilities.c | |||
@@ -35,7 +35,7 @@ int x25_parse_facilities(struct sk_buff *skb, struct x25_facilities *facilities, | |||
35 | struct x25_dte_facilities *dte_facs, unsigned long *vc_fac_mask) | 35 | struct x25_dte_facilities *dte_facs, unsigned long *vc_fac_mask) |
36 | { | 36 | { |
37 | unsigned char *p = skb->data; | 37 | unsigned char *p = skb->data; |
38 | unsigned int len = *p++; | 38 | unsigned int len; |
39 | 39 | ||
40 | *vc_fac_mask = 0; | 40 | *vc_fac_mask = 0; |
41 | 41 | ||
@@ -50,6 +50,14 @@ int x25_parse_facilities(struct sk_buff *skb, struct x25_facilities *facilities, | |||
50 | memset(dte_facs->called_ae, '\0', sizeof(dte_facs->called_ae)); | 50 | memset(dte_facs->called_ae, '\0', sizeof(dte_facs->called_ae)); |
51 | memset(dte_facs->calling_ae, '\0', sizeof(dte_facs->calling_ae)); | 51 | memset(dte_facs->calling_ae, '\0', sizeof(dte_facs->calling_ae)); |
52 | 52 | ||
53 | if (skb->len < 1) | ||
54 | return 0; | ||
55 | |||
56 | len = *p++; | ||
57 | |||
58 | if (len >= skb->len) | ||
59 | return -1; | ||
60 | |||
53 | while (len > 0) { | 61 | while (len > 0) { |
54 | switch (*p & X25_FAC_CLASS_MASK) { | 62 | switch (*p & X25_FAC_CLASS_MASK) { |
55 | case X25_FAC_CLASS_A: | 63 | case X25_FAC_CLASS_A: |
@@ -247,6 +255,8 @@ int x25_negotiate_facilities(struct sk_buff *skb, struct sock *sk, | |||
247 | memcpy(new, ours, sizeof(*new)); | 255 | memcpy(new, ours, sizeof(*new)); |
248 | 256 | ||
249 | len = x25_parse_facilities(skb, &theirs, dte, &x25->vc_facil_mask); | 257 | len = x25_parse_facilities(skb, &theirs, dte, &x25->vc_facil_mask); |
258 | if (len < 0) | ||
259 | return len; | ||
250 | 260 | ||
251 | /* | 261 | /* |
252 | * They want reverse charging, we won't accept it. | 262 | * They want reverse charging, we won't accept it. |
@@ -259,9 +269,18 @@ int x25_negotiate_facilities(struct sk_buff *skb, struct sock *sk, | |||
259 | new->reverse = theirs.reverse; | 269 | new->reverse = theirs.reverse; |
260 | 270 | ||
261 | if (theirs.throughput) { | 271 | if (theirs.throughput) { |
262 | if (theirs.throughput < ours->throughput) { | 272 | int theirs_in = theirs.throughput & 0x0f; |
263 | SOCK_DEBUG(sk, "X.25: throughput negotiated down\n"); | 273 | int theirs_out = theirs.throughput & 0xf0; |
264 | new->throughput = theirs.throughput; | 274 | int ours_in = ours->throughput & 0x0f; |
275 | int ours_out = ours->throughput & 0xf0; | ||
276 | if (!ours_in || theirs_in < ours_in) { | ||
277 | SOCK_DEBUG(sk, "X.25: inbound throughput negotiated\n"); | ||
278 | new->throughput = (new->throughput & 0xf0) | theirs_in; | ||
279 | } | ||
280 | if (!ours_out || theirs_out < ours_out) { | ||
281 | SOCK_DEBUG(sk, | ||
282 | "X.25: outbound throughput negotiated\n"); | ||
283 | new->throughput = (new->throughput & 0x0f) | theirs_out; | ||
265 | } | 284 | } |
266 | } | 285 | } |
267 | 286 | ||
diff --git a/net/x25/x25_forward.c b/net/x25/x25_forward.c index 056a55f3a871..25a810793968 100644 --- a/net/x25/x25_forward.c +++ b/net/x25/x25_forward.c | |||
@@ -10,6 +10,7 @@ | |||
10 | */ | 10 | */ |
11 | #include <linux/if_arp.h> | 11 | #include <linux/if_arp.h> |
12 | #include <linux/init.h> | 12 | #include <linux/init.h> |
13 | #include <linux/slab.h> | ||
13 | #include <net/x25.h> | 14 | #include <net/x25.h> |
14 | 15 | ||
15 | LIST_HEAD(x25_forward_list); | 16 | LIST_HEAD(x25_forward_list); |
diff --git a/net/x25/x25_in.c b/net/x25/x25_in.c index 96d922783547..372ac226e648 100644 --- a/net/x25/x25_in.c +++ b/net/x25/x25_in.c | |||
@@ -23,6 +23,7 @@ | |||
23 | * i-frames. | 23 | * i-frames. |
24 | */ | 24 | */ |
25 | 25 | ||
26 | #include <linux/slab.h> | ||
26 | #include <linux/errno.h> | 27 | #include <linux/errno.h> |
27 | #include <linux/kernel.h> | 28 | #include <linux/kernel.h> |
28 | #include <linux/string.h> | 29 | #include <linux/string.h> |
@@ -89,6 +90,7 @@ static int x25_queue_rx_frame(struct sock *sk, struct sk_buff *skb, int more) | |||
89 | static int x25_state1_machine(struct sock *sk, struct sk_buff *skb, int frametype) | 90 | static int x25_state1_machine(struct sock *sk, struct sk_buff *skb, int frametype) |
90 | { | 91 | { |
91 | struct x25_address source_addr, dest_addr; | 92 | struct x25_address source_addr, dest_addr; |
93 | int len; | ||
92 | 94 | ||
93 | switch (frametype) { | 95 | switch (frametype) { |
94 | case X25_CALL_ACCEPTED: { | 96 | case X25_CALL_ACCEPTED: { |
@@ -106,11 +108,17 @@ static int x25_state1_machine(struct sock *sk, struct sk_buff *skb, int frametyp | |||
106 | * Parse the data in the frame. | 108 | * Parse the data in the frame. |
107 | */ | 109 | */ |
108 | skb_pull(skb, X25_STD_MIN_LEN); | 110 | skb_pull(skb, X25_STD_MIN_LEN); |
109 | skb_pull(skb, x25_addr_ntoa(skb->data, &source_addr, &dest_addr)); | 111 | |
110 | skb_pull(skb, | 112 | len = x25_parse_address_block(skb, &source_addr, |
111 | x25_parse_facilities(skb, &x25->facilities, | 113 | &dest_addr); |
114 | if (len > 0) | ||
115 | skb_pull(skb, len); | ||
116 | |||
117 | len = x25_parse_facilities(skb, &x25->facilities, | ||
112 | &x25->dte_facilities, | 118 | &x25->dte_facilities, |
113 | &x25->vc_facil_mask)); | 119 | &x25->vc_facil_mask); |
120 | if (len > 0) | ||
121 | skb_pull(skb, len); | ||
114 | /* | 122 | /* |
115 | * Copy any Call User Data. | 123 | * Copy any Call User Data. |
116 | */ | 124 | */ |
diff --git a/net/x25/x25_link.c b/net/x25/x25_link.c index e4e1b6e49538..73e7b954ad28 100644 --- a/net/x25/x25_link.c +++ b/net/x25/x25_link.c | |||
@@ -24,6 +24,7 @@ | |||
24 | #include <linux/kernel.h> | 24 | #include <linux/kernel.h> |
25 | #include <linux/jiffies.h> | 25 | #include <linux/jiffies.h> |
26 | #include <linux/timer.h> | 26 | #include <linux/timer.h> |
27 | #include <linux/slab.h> | ||
27 | #include <linux/netdevice.h> | 28 | #include <linux/netdevice.h> |
28 | #include <linux/skbuff.h> | 29 | #include <linux/skbuff.h> |
29 | #include <asm/uaccess.h> | 30 | #include <asm/uaccess.h> |
diff --git a/net/x25/x25_out.c b/net/x25/x25_out.c index 2b96b52114d6..52351a26b6fc 100644 --- a/net/x25/x25_out.c +++ b/net/x25/x25_out.c | |||
@@ -22,6 +22,7 @@ | |||
22 | * needed cleaned seq-number fields. | 22 | * needed cleaned seq-number fields. |
23 | */ | 23 | */ |
24 | 24 | ||
25 | #include <linux/slab.h> | ||
25 | #include <linux/socket.h> | 26 | #include <linux/socket.h> |
26 | #include <linux/kernel.h> | 27 | #include <linux/kernel.h> |
27 | #include <linux/string.h> | 28 | #include <linux/string.h> |
diff --git a/net/x25/x25_route.c b/net/x25/x25_route.c index b95fae9ab393..97d77c532d8c 100644 --- a/net/x25/x25_route.c +++ b/net/x25/x25_route.c | |||
@@ -19,6 +19,7 @@ | |||
19 | 19 | ||
20 | #include <linux/if_arp.h> | 20 | #include <linux/if_arp.h> |
21 | #include <linux/init.h> | 21 | #include <linux/init.h> |
22 | #include <linux/slab.h> | ||
22 | #include <net/x25.h> | 23 | #include <net/x25.h> |
23 | 24 | ||
24 | LIST_HEAD(x25_route_list); | 25 | LIST_HEAD(x25_route_list); |
diff --git a/net/x25/x25_subr.c b/net/x25/x25_subr.c index 352b32d216fc..dc20cf12f39b 100644 --- a/net/x25/x25_subr.c +++ b/net/x25/x25_subr.c | |||
@@ -23,6 +23,7 @@ | |||
23 | * restriction on response. | 23 | * restriction on response. |
24 | */ | 24 | */ |
25 | 25 | ||
26 | #include <linux/slab.h> | ||
26 | #include <linux/kernel.h> | 27 | #include <linux/kernel.h> |
27 | #include <linux/string.h> | 28 | #include <linux/string.h> |
28 | #include <linux/skbuff.h> | 29 | #include <linux/skbuff.h> |
diff --git a/net/xfrm/xfrm_ipcomp.c b/net/xfrm/xfrm_ipcomp.c index 0fc5ff66d1fa..fc91ad7ee26e 100644 --- a/net/xfrm/xfrm_ipcomp.c +++ b/net/xfrm/xfrm_ipcomp.c | |||
@@ -17,11 +17,11 @@ | |||
17 | 17 | ||
18 | #include <linux/crypto.h> | 18 | #include <linux/crypto.h> |
19 | #include <linux/err.h> | 19 | #include <linux/err.h> |
20 | #include <linux/gfp.h> | ||
21 | #include <linux/list.h> | 20 | #include <linux/list.h> |
22 | #include <linux/module.h> | 21 | #include <linux/module.h> |
23 | #include <linux/mutex.h> | 22 | #include <linux/mutex.h> |
24 | #include <linux/percpu.h> | 23 | #include <linux/percpu.h> |
24 | #include <linux/slab.h> | ||
25 | #include <linux/smp.h> | 25 | #include <linux/smp.h> |
26 | #include <linux/vmalloc.h> | 26 | #include <linux/vmalloc.h> |
27 | #include <net/ip.h> | 27 | #include <net/ip.h> |
diff --git a/net/xfrm/xfrm_output.c b/net/xfrm/xfrm_output.c index b9fe13138c07..6a329158bdfa 100644 --- a/net/xfrm/xfrm_output.c +++ b/net/xfrm/xfrm_output.c | |||
@@ -14,6 +14,7 @@ | |||
14 | #include <linux/netdevice.h> | 14 | #include <linux/netdevice.h> |
15 | #include <linux/netfilter.h> | 15 | #include <linux/netfilter.h> |
16 | #include <linux/skbuff.h> | 16 | #include <linux/skbuff.h> |
17 | #include <linux/slab.h> | ||
17 | #include <linux/spinlock.h> | 18 | #include <linux/spinlock.h> |
18 | #include <net/dst.h> | 19 | #include <net/dst.h> |
19 | #include <net/xfrm.h> | 20 | #include <net/xfrm.h> |
diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c index 843e066649cb..7430ac26ec49 100644 --- a/net/xfrm/xfrm_policy.c +++ b/net/xfrm/xfrm_policy.c | |||
@@ -37,6 +37,8 @@ | |||
37 | DEFINE_MUTEX(xfrm_cfg_mutex); | 37 | DEFINE_MUTEX(xfrm_cfg_mutex); |
38 | EXPORT_SYMBOL(xfrm_cfg_mutex); | 38 | EXPORT_SYMBOL(xfrm_cfg_mutex); |
39 | 39 | ||
40 | static DEFINE_SPINLOCK(xfrm_policy_sk_bundle_lock); | ||
41 | static struct dst_entry *xfrm_policy_sk_bundles; | ||
40 | static DEFINE_RWLOCK(xfrm_policy_lock); | 42 | static DEFINE_RWLOCK(xfrm_policy_lock); |
41 | 43 | ||
42 | static DEFINE_RWLOCK(xfrm_policy_afinfo_lock); | 44 | static DEFINE_RWLOCK(xfrm_policy_afinfo_lock); |
@@ -44,12 +46,10 @@ static struct xfrm_policy_afinfo *xfrm_policy_afinfo[NPROTO]; | |||
44 | 46 | ||
45 | static struct kmem_cache *xfrm_dst_cache __read_mostly; | 47 | static struct kmem_cache *xfrm_dst_cache __read_mostly; |
46 | 48 | ||
47 | static HLIST_HEAD(xfrm_policy_gc_list); | ||
48 | static DEFINE_SPINLOCK(xfrm_policy_gc_lock); | ||
49 | |||
50 | static struct xfrm_policy_afinfo *xfrm_policy_get_afinfo(unsigned short family); | 49 | static struct xfrm_policy_afinfo *xfrm_policy_get_afinfo(unsigned short family); |
51 | static void xfrm_policy_put_afinfo(struct xfrm_policy_afinfo *afinfo); | 50 | static void xfrm_policy_put_afinfo(struct xfrm_policy_afinfo *afinfo); |
52 | static void xfrm_init_pmtu(struct dst_entry *dst); | 51 | static void xfrm_init_pmtu(struct dst_entry *dst); |
52 | static int stale_bundle(struct dst_entry *dst); | ||
53 | 53 | ||
54 | static struct xfrm_policy *__xfrm_policy_unlink(struct xfrm_policy *pol, | 54 | static struct xfrm_policy *__xfrm_policy_unlink(struct xfrm_policy *pol, |
55 | int dir); | 55 | int dir); |
@@ -156,7 +156,7 @@ static void xfrm_policy_timer(unsigned long data) | |||
156 | 156 | ||
157 | read_lock(&xp->lock); | 157 | read_lock(&xp->lock); |
158 | 158 | ||
159 | if (xp->walk.dead) | 159 | if (unlikely(xp->walk.dead)) |
160 | goto out; | 160 | goto out; |
161 | 161 | ||
162 | dir = xfrm_policy_id2dir(xp->index); | 162 | dir = xfrm_policy_id2dir(xp->index); |
@@ -216,6 +216,35 @@ expired: | |||
216 | xfrm_pol_put(xp); | 216 | xfrm_pol_put(xp); |
217 | } | 217 | } |
218 | 218 | ||
219 | static struct flow_cache_object *xfrm_policy_flo_get(struct flow_cache_object *flo) | ||
220 | { | ||
221 | struct xfrm_policy *pol = container_of(flo, struct xfrm_policy, flo); | ||
222 | |||
223 | if (unlikely(pol->walk.dead)) | ||
224 | flo = NULL; | ||
225 | else | ||
226 | xfrm_pol_hold(pol); | ||
227 | |||
228 | return flo; | ||
229 | } | ||
230 | |||
231 | static int xfrm_policy_flo_check(struct flow_cache_object *flo) | ||
232 | { | ||
233 | struct xfrm_policy *pol = container_of(flo, struct xfrm_policy, flo); | ||
234 | |||
235 | return !pol->walk.dead; | ||
236 | } | ||
237 | |||
238 | static void xfrm_policy_flo_delete(struct flow_cache_object *flo) | ||
239 | { | ||
240 | xfrm_pol_put(container_of(flo, struct xfrm_policy, flo)); | ||
241 | } | ||
242 | |||
243 | static const struct flow_cache_ops xfrm_policy_fc_ops = { | ||
244 | .get = xfrm_policy_flo_get, | ||
245 | .check = xfrm_policy_flo_check, | ||
246 | .delete = xfrm_policy_flo_delete, | ||
247 | }; | ||
219 | 248 | ||
220 | /* Allocate xfrm_policy. Not used here, it is supposed to be used by pfkeyv2 | 249 | /* Allocate xfrm_policy. Not used here, it is supposed to be used by pfkeyv2 |
221 | * SPD calls. | 250 | * SPD calls. |
@@ -236,6 +265,7 @@ struct xfrm_policy *xfrm_policy_alloc(struct net *net, gfp_t gfp) | |||
236 | atomic_set(&policy->refcnt, 1); | 265 | atomic_set(&policy->refcnt, 1); |
237 | setup_timer(&policy->timer, xfrm_policy_timer, | 266 | setup_timer(&policy->timer, xfrm_policy_timer, |
238 | (unsigned long)policy); | 267 | (unsigned long)policy); |
268 | policy->flo.ops = &xfrm_policy_fc_ops; | ||
239 | } | 269 | } |
240 | return policy; | 270 | return policy; |
241 | } | 271 | } |
@@ -247,8 +277,6 @@ void xfrm_policy_destroy(struct xfrm_policy *policy) | |||
247 | { | 277 | { |
248 | BUG_ON(!policy->walk.dead); | 278 | BUG_ON(!policy->walk.dead); |
249 | 279 | ||
250 | BUG_ON(policy->bundles); | ||
251 | |||
252 | if (del_timer(&policy->timer)) | 280 | if (del_timer(&policy->timer)) |
253 | BUG(); | 281 | BUG(); |
254 | 282 | ||
@@ -257,63 +285,20 @@ void xfrm_policy_destroy(struct xfrm_policy *policy) | |||
257 | } | 285 | } |
258 | EXPORT_SYMBOL(xfrm_policy_destroy); | 286 | EXPORT_SYMBOL(xfrm_policy_destroy); |
259 | 287 | ||
260 | static void xfrm_policy_gc_kill(struct xfrm_policy *policy) | ||
261 | { | ||
262 | struct dst_entry *dst; | ||
263 | |||
264 | while ((dst = policy->bundles) != NULL) { | ||
265 | policy->bundles = dst->next; | ||
266 | dst_free(dst); | ||
267 | } | ||
268 | |||
269 | if (del_timer(&policy->timer)) | ||
270 | atomic_dec(&policy->refcnt); | ||
271 | |||
272 | if (atomic_read(&policy->refcnt) > 1) | ||
273 | flow_cache_flush(); | ||
274 | |||
275 | xfrm_pol_put(policy); | ||
276 | } | ||
277 | |||
278 | static void xfrm_policy_gc_task(struct work_struct *work) | ||
279 | { | ||
280 | struct xfrm_policy *policy; | ||
281 | struct hlist_node *entry, *tmp; | ||
282 | struct hlist_head gc_list; | ||
283 | |||
284 | spin_lock_bh(&xfrm_policy_gc_lock); | ||
285 | gc_list.first = xfrm_policy_gc_list.first; | ||
286 | INIT_HLIST_HEAD(&xfrm_policy_gc_list); | ||
287 | spin_unlock_bh(&xfrm_policy_gc_lock); | ||
288 | |||
289 | hlist_for_each_entry_safe(policy, entry, tmp, &gc_list, bydst) | ||
290 | xfrm_policy_gc_kill(policy); | ||
291 | } | ||
292 | static DECLARE_WORK(xfrm_policy_gc_work, xfrm_policy_gc_task); | ||
293 | |||
294 | /* Rule must be locked. Release descentant resources, announce | 288 | /* Rule must be locked. Release descentant resources, announce |
295 | * entry dead. The rule must be unlinked from lists to the moment. | 289 | * entry dead. The rule must be unlinked from lists to the moment. |
296 | */ | 290 | */ |
297 | 291 | ||
298 | static void xfrm_policy_kill(struct xfrm_policy *policy) | 292 | static void xfrm_policy_kill(struct xfrm_policy *policy) |
299 | { | 293 | { |
300 | int dead; | ||
301 | |||
302 | write_lock_bh(&policy->lock); | ||
303 | dead = policy->walk.dead; | ||
304 | policy->walk.dead = 1; | 294 | policy->walk.dead = 1; |
305 | write_unlock_bh(&policy->lock); | ||
306 | 295 | ||
307 | if (unlikely(dead)) { | 296 | atomic_inc(&policy->genid); |
308 | WARN_ON(1); | ||
309 | return; | ||
310 | } | ||
311 | 297 | ||
312 | spin_lock_bh(&xfrm_policy_gc_lock); | 298 | if (del_timer(&policy->timer)) |
313 | hlist_add_head(&policy->bydst, &xfrm_policy_gc_list); | 299 | xfrm_pol_put(policy); |
314 | spin_unlock_bh(&xfrm_policy_gc_lock); | ||
315 | 300 | ||
316 | schedule_work(&xfrm_policy_gc_work); | 301 | xfrm_pol_put(policy); |
317 | } | 302 | } |
318 | 303 | ||
319 | static unsigned int xfrm_policy_hashmax __read_mostly = 1 * 1024 * 1024; | 304 | static unsigned int xfrm_policy_hashmax __read_mostly = 1 * 1024 * 1024; |
@@ -555,7 +540,6 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl) | |||
555 | struct xfrm_policy *delpol; | 540 | struct xfrm_policy *delpol; |
556 | struct hlist_head *chain; | 541 | struct hlist_head *chain; |
557 | struct hlist_node *entry, *newpos; | 542 | struct hlist_node *entry, *newpos; |
558 | struct dst_entry *gc_list; | ||
559 | u32 mark = policy->mark.v & policy->mark.m; | 543 | u32 mark = policy->mark.v & policy->mark.m; |
560 | 544 | ||
561 | write_lock_bh(&xfrm_policy_lock); | 545 | write_lock_bh(&xfrm_policy_lock); |
@@ -605,34 +589,6 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl) | |||
605 | else if (xfrm_bydst_should_resize(net, dir, NULL)) | 589 | else if (xfrm_bydst_should_resize(net, dir, NULL)) |
606 | schedule_work(&net->xfrm.policy_hash_work); | 590 | schedule_work(&net->xfrm.policy_hash_work); |
607 | 591 | ||
608 | read_lock_bh(&xfrm_policy_lock); | ||
609 | gc_list = NULL; | ||
610 | entry = &policy->bydst; | ||
611 | hlist_for_each_entry_continue(policy, entry, bydst) { | ||
612 | struct dst_entry *dst; | ||
613 | |||
614 | write_lock(&policy->lock); | ||
615 | dst = policy->bundles; | ||
616 | if (dst) { | ||
617 | struct dst_entry *tail = dst; | ||
618 | while (tail->next) | ||
619 | tail = tail->next; | ||
620 | tail->next = gc_list; | ||
621 | gc_list = dst; | ||
622 | |||
623 | policy->bundles = NULL; | ||
624 | } | ||
625 | write_unlock(&policy->lock); | ||
626 | } | ||
627 | read_unlock_bh(&xfrm_policy_lock); | ||
628 | |||
629 | while (gc_list) { | ||
630 | struct dst_entry *dst = gc_list; | ||
631 | |||
632 | gc_list = dst->next; | ||
633 | dst_free(dst); | ||
634 | } | ||
635 | |||
636 | return 0; | 592 | return 0; |
637 | } | 593 | } |
638 | EXPORT_SYMBOL(xfrm_policy_insert); | 594 | EXPORT_SYMBOL(xfrm_policy_insert); |
@@ -671,10 +627,8 @@ struct xfrm_policy *xfrm_policy_bysel_ctx(struct net *net, u32 mark, u8 type, | |||
671 | } | 627 | } |
672 | write_unlock_bh(&xfrm_policy_lock); | 628 | write_unlock_bh(&xfrm_policy_lock); |
673 | 629 | ||
674 | if (ret && delete) { | 630 | if (ret && delete) |
675 | atomic_inc(&flow_cache_genid); | ||
676 | xfrm_policy_kill(ret); | 631 | xfrm_policy_kill(ret); |
677 | } | ||
678 | return ret; | 632 | return ret; |
679 | } | 633 | } |
680 | EXPORT_SYMBOL(xfrm_policy_bysel_ctx); | 634 | EXPORT_SYMBOL(xfrm_policy_bysel_ctx); |
@@ -713,10 +667,8 @@ struct xfrm_policy *xfrm_policy_byid(struct net *net, u32 mark, u8 type, | |||
713 | } | 667 | } |
714 | write_unlock_bh(&xfrm_policy_lock); | 668 | write_unlock_bh(&xfrm_policy_lock); |
715 | 669 | ||
716 | if (ret && delete) { | 670 | if (ret && delete) |
717 | atomic_inc(&flow_cache_genid); | ||
718 | xfrm_policy_kill(ret); | 671 | xfrm_policy_kill(ret); |
719 | } | ||
720 | return ret; | 672 | return ret; |
721 | } | 673 | } |
722 | EXPORT_SYMBOL(xfrm_policy_byid); | 674 | EXPORT_SYMBOL(xfrm_policy_byid); |
@@ -776,7 +728,6 @@ xfrm_policy_flush_secctx_check(struct net *net, u8 type, struct xfrm_audit *audi | |||
776 | int xfrm_policy_flush(struct net *net, u8 type, struct xfrm_audit *audit_info) | 728 | int xfrm_policy_flush(struct net *net, u8 type, struct xfrm_audit *audit_info) |
777 | { | 729 | { |
778 | int dir, err = 0, cnt = 0; | 730 | int dir, err = 0, cnt = 0; |
779 | struct xfrm_policy *dp; | ||
780 | 731 | ||
781 | write_lock_bh(&xfrm_policy_lock); | 732 | write_lock_bh(&xfrm_policy_lock); |
782 | 733 | ||
@@ -794,10 +745,9 @@ int xfrm_policy_flush(struct net *net, u8 type, struct xfrm_audit *audit_info) | |||
794 | &net->xfrm.policy_inexact[dir], bydst) { | 745 | &net->xfrm.policy_inexact[dir], bydst) { |
795 | if (pol->type != type) | 746 | if (pol->type != type) |
796 | continue; | 747 | continue; |
797 | dp = __xfrm_policy_unlink(pol, dir); | 748 | __xfrm_policy_unlink(pol, dir); |
798 | write_unlock_bh(&xfrm_policy_lock); | 749 | write_unlock_bh(&xfrm_policy_lock); |
799 | if (dp) | 750 | cnt++; |
800 | cnt++; | ||
801 | 751 | ||
802 | xfrm_audit_policy_delete(pol, 1, audit_info->loginuid, | 752 | xfrm_audit_policy_delete(pol, 1, audit_info->loginuid, |
803 | audit_info->sessionid, | 753 | audit_info->sessionid, |
@@ -816,10 +766,9 @@ int xfrm_policy_flush(struct net *net, u8 type, struct xfrm_audit *audit_info) | |||
816 | bydst) { | 766 | bydst) { |
817 | if (pol->type != type) | 767 | if (pol->type != type) |
818 | continue; | 768 | continue; |
819 | dp = __xfrm_policy_unlink(pol, dir); | 769 | __xfrm_policy_unlink(pol, dir); |
820 | write_unlock_bh(&xfrm_policy_lock); | 770 | write_unlock_bh(&xfrm_policy_lock); |
821 | if (dp) | 771 | cnt++; |
822 | cnt++; | ||
823 | 772 | ||
824 | xfrm_audit_policy_delete(pol, 1, | 773 | xfrm_audit_policy_delete(pol, 1, |
825 | audit_info->loginuid, | 774 | audit_info->loginuid, |
@@ -835,7 +784,6 @@ int xfrm_policy_flush(struct net *net, u8 type, struct xfrm_audit *audit_info) | |||
835 | } | 784 | } |
836 | if (!cnt) | 785 | if (!cnt) |
837 | err = -ESRCH; | 786 | err = -ESRCH; |
838 | atomic_inc(&flow_cache_genid); | ||
839 | out: | 787 | out: |
840 | write_unlock_bh(&xfrm_policy_lock); | 788 | write_unlock_bh(&xfrm_policy_lock); |
841 | return err; | 789 | return err; |
@@ -989,32 +937,37 @@ fail: | |||
989 | return ret; | 937 | return ret; |
990 | } | 938 | } |
991 | 939 | ||
992 | static int xfrm_policy_lookup(struct net *net, struct flowi *fl, u16 family, | 940 | static struct xfrm_policy * |
993 | u8 dir, void **objp, atomic_t **obj_refp) | 941 | __xfrm_policy_lookup(struct net *net, struct flowi *fl, u16 family, u8 dir) |
994 | { | 942 | { |
943 | #ifdef CONFIG_XFRM_SUB_POLICY | ||
995 | struct xfrm_policy *pol; | 944 | struct xfrm_policy *pol; |
996 | int err = 0; | ||
997 | 945 | ||
998 | #ifdef CONFIG_XFRM_SUB_POLICY | ||
999 | pol = xfrm_policy_lookup_bytype(net, XFRM_POLICY_TYPE_SUB, fl, family, dir); | 946 | pol = xfrm_policy_lookup_bytype(net, XFRM_POLICY_TYPE_SUB, fl, family, dir); |
1000 | if (IS_ERR(pol)) { | 947 | if (pol != NULL) |
1001 | err = PTR_ERR(pol); | 948 | return pol; |
1002 | pol = NULL; | ||
1003 | } | ||
1004 | if (pol || err) | ||
1005 | goto end; | ||
1006 | #endif | ||
1007 | pol = xfrm_policy_lookup_bytype(net, XFRM_POLICY_TYPE_MAIN, fl, family, dir); | ||
1008 | if (IS_ERR(pol)) { | ||
1009 | err = PTR_ERR(pol); | ||
1010 | pol = NULL; | ||
1011 | } | ||
1012 | #ifdef CONFIG_XFRM_SUB_POLICY | ||
1013 | end: | ||
1014 | #endif | 949 | #endif |
1015 | if ((*objp = (void *) pol) != NULL) | 950 | return xfrm_policy_lookup_bytype(net, XFRM_POLICY_TYPE_MAIN, fl, family, dir); |
1016 | *obj_refp = &pol->refcnt; | 951 | } |
1017 | return err; | 952 | |
953 | static struct flow_cache_object * | ||
954 | xfrm_policy_lookup(struct net *net, struct flowi *fl, u16 family, | ||
955 | u8 dir, struct flow_cache_object *old_obj, void *ctx) | ||
956 | { | ||
957 | struct xfrm_policy *pol; | ||
958 | |||
959 | if (old_obj) | ||
960 | xfrm_pol_put(container_of(old_obj, struct xfrm_policy, flo)); | ||
961 | |||
962 | pol = __xfrm_policy_lookup(net, fl, family, dir); | ||
963 | if (IS_ERR_OR_NULL(pol)) | ||
964 | return ERR_CAST(pol); | ||
965 | |||
966 | /* Resolver returns two references: | ||
967 | * one for cache and one for caller of flow_cache_lookup() */ | ||
968 | xfrm_pol_hold(pol); | ||
969 | |||
970 | return &pol->flo; | ||
1018 | } | 971 | } |
1019 | 972 | ||
1020 | static inline int policy_to_flow_dir(int dir) | 973 | static inline int policy_to_flow_dir(int dir) |
@@ -1104,8 +1057,6 @@ int xfrm_policy_delete(struct xfrm_policy *pol, int dir) | |||
1104 | pol = __xfrm_policy_unlink(pol, dir); | 1057 | pol = __xfrm_policy_unlink(pol, dir); |
1105 | write_unlock_bh(&xfrm_policy_lock); | 1058 | write_unlock_bh(&xfrm_policy_lock); |
1106 | if (pol) { | 1059 | if (pol) { |
1107 | if (dir < XFRM_POLICY_MAX) | ||
1108 | atomic_inc(&flow_cache_genid); | ||
1109 | xfrm_policy_kill(pol); | 1060 | xfrm_policy_kill(pol); |
1110 | return 0; | 1061 | return 0; |
1111 | } | 1062 | } |
@@ -1132,6 +1083,9 @@ int xfrm_sk_policy_insert(struct sock *sk, int dir, struct xfrm_policy *pol) | |||
1132 | __xfrm_policy_link(pol, XFRM_POLICY_MAX+dir); | 1083 | __xfrm_policy_link(pol, XFRM_POLICY_MAX+dir); |
1133 | } | 1084 | } |
1134 | if (old_pol) | 1085 | if (old_pol) |
1086 | /* Unlinking succeeds always. This is the only function | ||
1087 | * allowed to delete or replace socket policy. | ||
1088 | */ | ||
1135 | __xfrm_policy_unlink(old_pol, XFRM_POLICY_MAX+dir); | 1089 | __xfrm_policy_unlink(old_pol, XFRM_POLICY_MAX+dir); |
1136 | write_unlock_bh(&xfrm_policy_lock); | 1090 | write_unlock_bh(&xfrm_policy_lock); |
1137 | 1091 | ||
@@ -1300,18 +1254,6 @@ xfrm_tmpl_resolve(struct xfrm_policy **pols, int npols, struct flowi *fl, | |||
1300 | * still valid. | 1254 | * still valid. |
1301 | */ | 1255 | */ |
1302 | 1256 | ||
1303 | static struct dst_entry * | ||
1304 | xfrm_find_bundle(struct flowi *fl, struct xfrm_policy *policy, unsigned short family) | ||
1305 | { | ||
1306 | struct dst_entry *x; | ||
1307 | struct xfrm_policy_afinfo *afinfo = xfrm_policy_get_afinfo(family); | ||
1308 | if (unlikely(afinfo == NULL)) | ||
1309 | return ERR_PTR(-EINVAL); | ||
1310 | x = afinfo->find_bundle(fl, policy); | ||
1311 | xfrm_policy_put_afinfo(afinfo); | ||
1312 | return x; | ||
1313 | } | ||
1314 | |||
1315 | static inline int xfrm_get_tos(struct flowi *fl, int family) | 1257 | static inline int xfrm_get_tos(struct flowi *fl, int family) |
1316 | { | 1258 | { |
1317 | struct xfrm_policy_afinfo *afinfo = xfrm_policy_get_afinfo(family); | 1259 | struct xfrm_policy_afinfo *afinfo = xfrm_policy_get_afinfo(family); |
@@ -1327,6 +1269,54 @@ static inline int xfrm_get_tos(struct flowi *fl, int family) | |||
1327 | return tos; | 1269 | return tos; |
1328 | } | 1270 | } |
1329 | 1271 | ||
1272 | static struct flow_cache_object *xfrm_bundle_flo_get(struct flow_cache_object *flo) | ||
1273 | { | ||
1274 | struct xfrm_dst *xdst = container_of(flo, struct xfrm_dst, flo); | ||
1275 | struct dst_entry *dst = &xdst->u.dst; | ||
1276 | |||
1277 | if (xdst->route == NULL) { | ||
1278 | /* Dummy bundle - if it has xfrms we were not | ||
1279 | * able to build bundle as template resolution failed. | ||
1280 | * It means we need to try again resolving. */ | ||
1281 | if (xdst->num_xfrms > 0) | ||
1282 | return NULL; | ||
1283 | } else { | ||
1284 | /* Real bundle */ | ||
1285 | if (stale_bundle(dst)) | ||
1286 | return NULL; | ||
1287 | } | ||
1288 | |||
1289 | dst_hold(dst); | ||
1290 | return flo; | ||
1291 | } | ||
1292 | |||
1293 | static int xfrm_bundle_flo_check(struct flow_cache_object *flo) | ||
1294 | { | ||
1295 | struct xfrm_dst *xdst = container_of(flo, struct xfrm_dst, flo); | ||
1296 | struct dst_entry *dst = &xdst->u.dst; | ||
1297 | |||
1298 | if (!xdst->route) | ||
1299 | return 0; | ||
1300 | if (stale_bundle(dst)) | ||
1301 | return 0; | ||
1302 | |||
1303 | return 1; | ||
1304 | } | ||
1305 | |||
1306 | static void xfrm_bundle_flo_delete(struct flow_cache_object *flo) | ||
1307 | { | ||
1308 | struct xfrm_dst *xdst = container_of(flo, struct xfrm_dst, flo); | ||
1309 | struct dst_entry *dst = &xdst->u.dst; | ||
1310 | |||
1311 | dst_free(dst); | ||
1312 | } | ||
1313 | |||
1314 | static const struct flow_cache_ops xfrm_bundle_fc_ops = { | ||
1315 | .get = xfrm_bundle_flo_get, | ||
1316 | .check = xfrm_bundle_flo_check, | ||
1317 | .delete = xfrm_bundle_flo_delete, | ||
1318 | }; | ||
1319 | |||
1330 | static inline struct xfrm_dst *xfrm_alloc_dst(struct net *net, int family) | 1320 | static inline struct xfrm_dst *xfrm_alloc_dst(struct net *net, int family) |
1331 | { | 1321 | { |
1332 | struct xfrm_policy_afinfo *afinfo = xfrm_policy_get_afinfo(family); | 1322 | struct xfrm_policy_afinfo *afinfo = xfrm_policy_get_afinfo(family); |
@@ -1349,9 +1339,10 @@ static inline struct xfrm_dst *xfrm_alloc_dst(struct net *net, int family) | |||
1349 | BUG(); | 1339 | BUG(); |
1350 | } | 1340 | } |
1351 | xdst = dst_alloc(dst_ops) ?: ERR_PTR(-ENOBUFS); | 1341 | xdst = dst_alloc(dst_ops) ?: ERR_PTR(-ENOBUFS); |
1352 | |||
1353 | xfrm_policy_put_afinfo(afinfo); | 1342 | xfrm_policy_put_afinfo(afinfo); |
1354 | 1343 | ||
1344 | xdst->flo.ops = &xfrm_bundle_fc_ops; | ||
1345 | |||
1355 | return xdst; | 1346 | return xdst; |
1356 | } | 1347 | } |
1357 | 1348 | ||
@@ -1389,6 +1380,7 @@ static inline int xfrm_fill_dst(struct xfrm_dst *xdst, struct net_device *dev, | |||
1389 | return err; | 1380 | return err; |
1390 | } | 1381 | } |
1391 | 1382 | ||
1383 | |||
1392 | /* Allocate chain of dst_entry's, attach known xfrm's, calculate | 1384 | /* Allocate chain of dst_entry's, attach known xfrm's, calculate |
1393 | * all the metrics... Shortly, bundle a bundle. | 1385 | * all the metrics... Shortly, bundle a bundle. |
1394 | */ | 1386 | */ |
@@ -1452,7 +1444,7 @@ static struct dst_entry *xfrm_bundle_create(struct xfrm_policy *policy, | |||
1452 | dst_hold(dst); | 1444 | dst_hold(dst); |
1453 | 1445 | ||
1454 | dst1->xfrm = xfrm[i]; | 1446 | dst1->xfrm = xfrm[i]; |
1455 | xdst->genid = xfrm[i]->genid; | 1447 | xdst->xfrm_genid = xfrm[i]->genid; |
1456 | 1448 | ||
1457 | dst1->obsolete = -1; | 1449 | dst1->obsolete = -1; |
1458 | dst1->flags |= DST_HOST; | 1450 | dst1->flags |= DST_HOST; |
@@ -1545,7 +1537,186 @@ xfrm_dst_update_origin(struct dst_entry *dst, struct flowi *fl) | |||
1545 | #endif | 1537 | #endif |
1546 | } | 1538 | } |
1547 | 1539 | ||
1548 | static int stale_bundle(struct dst_entry *dst); | 1540 | static int xfrm_expand_policies(struct flowi *fl, u16 family, |
1541 | struct xfrm_policy **pols, | ||
1542 | int *num_pols, int *num_xfrms) | ||
1543 | { | ||
1544 | int i; | ||
1545 | |||
1546 | if (*num_pols == 0 || !pols[0]) { | ||
1547 | *num_pols = 0; | ||
1548 | *num_xfrms = 0; | ||
1549 | return 0; | ||
1550 | } | ||
1551 | if (IS_ERR(pols[0])) | ||
1552 | return PTR_ERR(pols[0]); | ||
1553 | |||
1554 | *num_xfrms = pols[0]->xfrm_nr; | ||
1555 | |||
1556 | #ifdef CONFIG_XFRM_SUB_POLICY | ||
1557 | if (pols[0] && pols[0]->action == XFRM_POLICY_ALLOW && | ||
1558 | pols[0]->type != XFRM_POLICY_TYPE_MAIN) { | ||
1559 | pols[1] = xfrm_policy_lookup_bytype(xp_net(pols[0]), | ||
1560 | XFRM_POLICY_TYPE_MAIN, | ||
1561 | fl, family, | ||
1562 | XFRM_POLICY_OUT); | ||
1563 | if (pols[1]) { | ||
1564 | if (IS_ERR(pols[1])) { | ||
1565 | xfrm_pols_put(pols, *num_pols); | ||
1566 | return PTR_ERR(pols[1]); | ||
1567 | } | ||
1568 | (*num_pols) ++; | ||
1569 | (*num_xfrms) += pols[1]->xfrm_nr; | ||
1570 | } | ||
1571 | } | ||
1572 | #endif | ||
1573 | for (i = 0; i < *num_pols; i++) { | ||
1574 | if (pols[i]->action != XFRM_POLICY_ALLOW) { | ||
1575 | *num_xfrms = -1; | ||
1576 | break; | ||
1577 | } | ||
1578 | } | ||
1579 | |||
1580 | return 0; | ||
1581 | |||
1582 | } | ||
1583 | |||
1584 | static struct xfrm_dst * | ||
1585 | xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols, | ||
1586 | struct flowi *fl, u16 family, | ||
1587 | struct dst_entry *dst_orig) | ||
1588 | { | ||
1589 | struct net *net = xp_net(pols[0]); | ||
1590 | struct xfrm_state *xfrm[XFRM_MAX_DEPTH]; | ||
1591 | struct dst_entry *dst; | ||
1592 | struct xfrm_dst *xdst; | ||
1593 | int err; | ||
1594 | |||
1595 | /* Try to instantiate a bundle */ | ||
1596 | err = xfrm_tmpl_resolve(pols, num_pols, fl, xfrm, family); | ||
1597 | if (err < 0) { | ||
1598 | if (err != -EAGAIN) | ||
1599 | XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTPOLERROR); | ||
1600 | return ERR_PTR(err); | ||
1601 | } | ||
1602 | |||
1603 | dst = xfrm_bundle_create(pols[0], xfrm, err, fl, dst_orig); | ||
1604 | if (IS_ERR(dst)) { | ||
1605 | XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTBUNDLEGENERROR); | ||
1606 | return ERR_CAST(dst); | ||
1607 | } | ||
1608 | |||
1609 | xdst = (struct xfrm_dst *)dst; | ||
1610 | xdst->num_xfrms = err; | ||
1611 | if (num_pols > 1) | ||
1612 | err = xfrm_dst_update_parent(dst, &pols[1]->selector); | ||
1613 | else | ||
1614 | err = xfrm_dst_update_origin(dst, fl); | ||
1615 | if (unlikely(err)) { | ||
1616 | dst_free(dst); | ||
1617 | XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTBUNDLECHECKERROR); | ||
1618 | return ERR_PTR(err); | ||
1619 | } | ||
1620 | |||
1621 | xdst->num_pols = num_pols; | ||
1622 | memcpy(xdst->pols, pols, sizeof(struct xfrm_policy*) * num_pols); | ||
1623 | xdst->policy_genid = atomic_read(&pols[0]->genid); | ||
1624 | |||
1625 | return xdst; | ||
1626 | } | ||
1627 | |||
1628 | static struct flow_cache_object * | ||
1629 | xfrm_bundle_lookup(struct net *net, struct flowi *fl, u16 family, u8 dir, | ||
1630 | struct flow_cache_object *oldflo, void *ctx) | ||
1631 | { | ||
1632 | struct dst_entry *dst_orig = (struct dst_entry *)ctx; | ||
1633 | struct xfrm_policy *pols[XFRM_POLICY_TYPE_MAX]; | ||
1634 | struct xfrm_dst *xdst, *new_xdst; | ||
1635 | int num_pols = 0, num_xfrms = 0, i, err, pol_dead; | ||
1636 | |||
1637 | /* Check if the policies from old bundle are usable */ | ||
1638 | xdst = NULL; | ||
1639 | if (oldflo) { | ||
1640 | xdst = container_of(oldflo, struct xfrm_dst, flo); | ||
1641 | num_pols = xdst->num_pols; | ||
1642 | num_xfrms = xdst->num_xfrms; | ||
1643 | pol_dead = 0; | ||
1644 | for (i = 0; i < num_pols; i++) { | ||
1645 | pols[i] = xdst->pols[i]; | ||
1646 | pol_dead |= pols[i]->walk.dead; | ||
1647 | } | ||
1648 | if (pol_dead) { | ||
1649 | dst_free(&xdst->u.dst); | ||
1650 | xdst = NULL; | ||
1651 | num_pols = 0; | ||
1652 | num_xfrms = 0; | ||
1653 | oldflo = NULL; | ||
1654 | } | ||
1655 | } | ||
1656 | |||
1657 | /* Resolve policies to use if we couldn't get them from | ||
1658 | * previous cache entry */ | ||
1659 | if (xdst == NULL) { | ||
1660 | num_pols = 1; | ||
1661 | pols[0] = __xfrm_policy_lookup(net, fl, family, dir); | ||
1662 | err = xfrm_expand_policies(fl, family, pols, | ||
1663 | &num_pols, &num_xfrms); | ||
1664 | if (err < 0) | ||
1665 | goto inc_error; | ||
1666 | if (num_pols == 0) | ||
1667 | return NULL; | ||
1668 | if (num_xfrms <= 0) | ||
1669 | goto make_dummy_bundle; | ||
1670 | } | ||
1671 | |||
1672 | new_xdst = xfrm_resolve_and_create_bundle(pols, num_pols, fl, family, dst_orig); | ||
1673 | if (IS_ERR(new_xdst)) { | ||
1674 | err = PTR_ERR(new_xdst); | ||
1675 | if (err != -EAGAIN) | ||
1676 | goto error; | ||
1677 | if (oldflo == NULL) | ||
1678 | goto make_dummy_bundle; | ||
1679 | dst_hold(&xdst->u.dst); | ||
1680 | return oldflo; | ||
1681 | } | ||
1682 | |||
1683 | /* Kill the previous bundle */ | ||
1684 | if (xdst) { | ||
1685 | /* The policies were stolen for newly generated bundle */ | ||
1686 | xdst->num_pols = 0; | ||
1687 | dst_free(&xdst->u.dst); | ||
1688 | } | ||
1689 | |||
1690 | /* Flow cache does not have reference, it dst_free()'s, | ||
1691 | * but we do need to return one reference for original caller */ | ||
1692 | dst_hold(&new_xdst->u.dst); | ||
1693 | return &new_xdst->flo; | ||
1694 | |||
1695 | make_dummy_bundle: | ||
1696 | /* We found policies, but there's no bundles to instantiate: | ||
1697 | * either because the policy blocks, has no transformations or | ||
1698 | * we could not build template (no xfrm_states).*/ | ||
1699 | xdst = xfrm_alloc_dst(net, family); | ||
1700 | if (IS_ERR(xdst)) { | ||
1701 | xfrm_pols_put(pols, num_pols); | ||
1702 | return ERR_CAST(xdst); | ||
1703 | } | ||
1704 | xdst->num_pols = num_pols; | ||
1705 | xdst->num_xfrms = num_xfrms; | ||
1706 | memcpy(xdst->pols, pols, sizeof(struct xfrm_policy*) * num_pols); | ||
1707 | |||
1708 | dst_hold(&xdst->u.dst); | ||
1709 | return &xdst->flo; | ||
1710 | |||
1711 | inc_error: | ||
1712 | XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTPOLERROR); | ||
1713 | error: | ||
1714 | if (xdst != NULL) | ||
1715 | dst_free(&xdst->u.dst); | ||
1716 | else | ||
1717 | xfrm_pols_put(pols, num_pols); | ||
1718 | return ERR_PTR(err); | ||
1719 | } | ||
1549 | 1720 | ||
1550 | /* Main function: finds/creates a bundle for given flow. | 1721 | /* Main function: finds/creates a bundle for given flow. |
1551 | * | 1722 | * |
@@ -1555,245 +1726,152 @@ static int stale_bundle(struct dst_entry *dst); | |||
1555 | int __xfrm_lookup(struct net *net, struct dst_entry **dst_p, struct flowi *fl, | 1726 | int __xfrm_lookup(struct net *net, struct dst_entry **dst_p, struct flowi *fl, |
1556 | struct sock *sk, int flags) | 1727 | struct sock *sk, int flags) |
1557 | { | 1728 | { |
1558 | struct xfrm_policy *policy; | ||
1559 | struct xfrm_policy *pols[XFRM_POLICY_TYPE_MAX]; | 1729 | struct xfrm_policy *pols[XFRM_POLICY_TYPE_MAX]; |
1560 | int npols; | 1730 | struct flow_cache_object *flo; |
1561 | int pol_dead; | 1731 | struct xfrm_dst *xdst; |
1562 | int xfrm_nr; | 1732 | struct dst_entry *dst, *dst_orig = *dst_p, *route; |
1563 | int pi; | 1733 | u16 family = dst_orig->ops->family; |
1564 | struct xfrm_state *xfrm[XFRM_MAX_DEPTH]; | ||
1565 | struct dst_entry *dst, *dst_orig = *dst_p; | ||
1566 | int nx = 0; | ||
1567 | int err; | ||
1568 | u32 genid; | ||
1569 | u16 family; | ||
1570 | u8 dir = policy_to_flow_dir(XFRM_POLICY_OUT); | 1734 | u8 dir = policy_to_flow_dir(XFRM_POLICY_OUT); |
1735 | int i, err, num_pols, num_xfrms, drop_pols = 0; | ||
1571 | 1736 | ||
1572 | restart: | 1737 | restart: |
1573 | genid = atomic_read(&flow_cache_genid); | 1738 | dst = NULL; |
1574 | policy = NULL; | 1739 | xdst = NULL; |
1575 | for (pi = 0; pi < ARRAY_SIZE(pols); pi++) | 1740 | route = NULL; |
1576 | pols[pi] = NULL; | ||
1577 | npols = 0; | ||
1578 | pol_dead = 0; | ||
1579 | xfrm_nr = 0; | ||
1580 | 1741 | ||
1581 | if (sk && sk->sk_policy[XFRM_POLICY_OUT]) { | 1742 | if (sk && sk->sk_policy[XFRM_POLICY_OUT]) { |
1582 | policy = xfrm_sk_policy_lookup(sk, XFRM_POLICY_OUT, fl); | 1743 | num_pols = 1; |
1583 | err = PTR_ERR(policy); | 1744 | pols[0] = xfrm_sk_policy_lookup(sk, XFRM_POLICY_OUT, fl); |
1584 | if (IS_ERR(policy)) { | 1745 | err = xfrm_expand_policies(fl, family, pols, |
1585 | XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTPOLERROR); | 1746 | &num_pols, &num_xfrms); |
1747 | if (err < 0) | ||
1586 | goto dropdst; | 1748 | goto dropdst; |
1749 | |||
1750 | if (num_pols) { | ||
1751 | if (num_xfrms <= 0) { | ||
1752 | drop_pols = num_pols; | ||
1753 | goto no_transform; | ||
1754 | } | ||
1755 | |||
1756 | xdst = xfrm_resolve_and_create_bundle( | ||
1757 | pols, num_pols, fl, | ||
1758 | family, dst_orig); | ||
1759 | if (IS_ERR(xdst)) { | ||
1760 | xfrm_pols_put(pols, num_pols); | ||
1761 | err = PTR_ERR(xdst); | ||
1762 | goto dropdst; | ||
1763 | } | ||
1764 | |||
1765 | spin_lock_bh(&xfrm_policy_sk_bundle_lock); | ||
1766 | xdst->u.dst.next = xfrm_policy_sk_bundles; | ||
1767 | xfrm_policy_sk_bundles = &xdst->u.dst; | ||
1768 | spin_unlock_bh(&xfrm_policy_sk_bundle_lock); | ||
1769 | |||
1770 | route = xdst->route; | ||
1587 | } | 1771 | } |
1588 | } | 1772 | } |
1589 | 1773 | ||
1590 | if (!policy) { | 1774 | if (xdst == NULL) { |
1591 | /* To accelerate a bit... */ | 1775 | /* To accelerate a bit... */ |
1592 | if ((dst_orig->flags & DST_NOXFRM) || | 1776 | if ((dst_orig->flags & DST_NOXFRM) || |
1593 | !net->xfrm.policy_count[XFRM_POLICY_OUT]) | 1777 | !net->xfrm.policy_count[XFRM_POLICY_OUT]) |
1594 | goto nopol; | 1778 | goto nopol; |
1595 | 1779 | ||
1596 | policy = flow_cache_lookup(net, fl, dst_orig->ops->family, | 1780 | flo = flow_cache_lookup(net, fl, family, dir, |
1597 | dir, xfrm_policy_lookup); | 1781 | xfrm_bundle_lookup, dst_orig); |
1598 | err = PTR_ERR(policy); | 1782 | if (flo == NULL) |
1599 | if (IS_ERR(policy)) { | 1783 | goto nopol; |
1600 | XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTPOLERROR); | 1784 | if (IS_ERR(flo)) { |
1785 | err = PTR_ERR(flo); | ||
1601 | goto dropdst; | 1786 | goto dropdst; |
1602 | } | 1787 | } |
1788 | xdst = container_of(flo, struct xfrm_dst, flo); | ||
1789 | |||
1790 | num_pols = xdst->num_pols; | ||
1791 | num_xfrms = xdst->num_xfrms; | ||
1792 | memcpy(pols, xdst->pols, sizeof(struct xfrm_policy*) * num_pols); | ||
1793 | route = xdst->route; | ||
1794 | } | ||
1795 | |||
1796 | dst = &xdst->u.dst; | ||
1797 | if (route == NULL && num_xfrms > 0) { | ||
1798 | /* The only case when xfrm_bundle_lookup() returns a | ||
1799 | * bundle with null route, is when the template could | ||
1800 | * not be resolved. It means policies are there, but | ||
1801 | * bundle could not be created, since we don't yet | ||
1802 | * have the xfrm_state's. We need to wait for KM to | ||
1803 | * negotiate new SA's or bail out with error.*/ | ||
1804 | if (net->xfrm.sysctl_larval_drop) { | ||
1805 | /* EREMOTE tells the caller to generate | ||
1806 | * a one-shot blackhole route. */ | ||
1807 | dst_release(dst); | ||
1808 | xfrm_pols_put(pols, num_pols); | ||
1809 | XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTNOSTATES); | ||
1810 | return -EREMOTE; | ||
1811 | } | ||
1812 | if (flags & XFRM_LOOKUP_WAIT) { | ||
1813 | DECLARE_WAITQUEUE(wait, current); | ||
1814 | |||
1815 | add_wait_queue(&net->xfrm.km_waitq, &wait); | ||
1816 | set_current_state(TASK_INTERRUPTIBLE); | ||
1817 | schedule(); | ||
1818 | set_current_state(TASK_RUNNING); | ||
1819 | remove_wait_queue(&net->xfrm.km_waitq, &wait); | ||
1820 | |||
1821 | if (!signal_pending(current)) { | ||
1822 | dst_release(dst); | ||
1823 | goto restart; | ||
1824 | } | ||
1825 | |||
1826 | err = -ERESTART; | ||
1827 | } else | ||
1828 | err = -EAGAIN; | ||
1829 | |||
1830 | XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTNOSTATES); | ||
1831 | goto error; | ||
1603 | } | 1832 | } |
1604 | 1833 | ||
1605 | if (!policy) | 1834 | no_transform: |
1835 | if (num_pols == 0) | ||
1606 | goto nopol; | 1836 | goto nopol; |
1607 | 1837 | ||
1608 | family = dst_orig->ops->family; | 1838 | if ((flags & XFRM_LOOKUP_ICMP) && |
1609 | pols[0] = policy; | 1839 | !(pols[0]->flags & XFRM_POLICY_ICMP)) { |
1610 | npols ++; | 1840 | err = -ENOENT; |
1611 | xfrm_nr += pols[0]->xfrm_nr; | ||
1612 | |||
1613 | err = -ENOENT; | ||
1614 | if ((flags & XFRM_LOOKUP_ICMP) && !(policy->flags & XFRM_POLICY_ICMP)) | ||
1615 | goto error; | 1841 | goto error; |
1842 | } | ||
1616 | 1843 | ||
1617 | policy->curlft.use_time = get_seconds(); | 1844 | for (i = 0; i < num_pols; i++) |
1845 | pols[i]->curlft.use_time = get_seconds(); | ||
1618 | 1846 | ||
1619 | switch (policy->action) { | 1847 | if (num_xfrms < 0) { |
1620 | default: | ||
1621 | case XFRM_POLICY_BLOCK: | ||
1622 | /* Prohibit the flow */ | 1848 | /* Prohibit the flow */ |
1623 | XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTPOLBLOCK); | 1849 | XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTPOLBLOCK); |
1624 | err = -EPERM; | 1850 | err = -EPERM; |
1625 | goto error; | 1851 | goto error; |
1626 | 1852 | } else if (num_xfrms > 0) { | |
1627 | case XFRM_POLICY_ALLOW: | 1853 | /* Flow transformed */ |
1628 | #ifndef CONFIG_XFRM_SUB_POLICY | 1854 | *dst_p = dst; |
1629 | if (policy->xfrm_nr == 0) { | 1855 | dst_release(dst_orig); |
1630 | /* Flow passes not transformed. */ | 1856 | } else { |
1631 | xfrm_pol_put(policy); | 1857 | /* Flow passes untransformed */ |
1632 | return 0; | 1858 | dst_release(dst); |
1633 | } | ||
1634 | #endif | ||
1635 | |||
1636 | /* Try to find matching bundle. | ||
1637 | * | ||
1638 | * LATER: help from flow cache. It is optional, this | ||
1639 | * is required only for output policy. | ||
1640 | */ | ||
1641 | dst = xfrm_find_bundle(fl, policy, family); | ||
1642 | if (IS_ERR(dst)) { | ||
1643 | XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTBUNDLECHECKERROR); | ||
1644 | err = PTR_ERR(dst); | ||
1645 | goto error; | ||
1646 | } | ||
1647 | |||
1648 | if (dst) | ||
1649 | break; | ||
1650 | |||
1651 | #ifdef CONFIG_XFRM_SUB_POLICY | ||
1652 | if (pols[0]->type != XFRM_POLICY_TYPE_MAIN) { | ||
1653 | pols[1] = xfrm_policy_lookup_bytype(net, | ||
1654 | XFRM_POLICY_TYPE_MAIN, | ||
1655 | fl, family, | ||
1656 | XFRM_POLICY_OUT); | ||
1657 | if (pols[1]) { | ||
1658 | if (IS_ERR(pols[1])) { | ||
1659 | XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTPOLERROR); | ||
1660 | err = PTR_ERR(pols[1]); | ||
1661 | goto error; | ||
1662 | } | ||
1663 | if (pols[1]->action == XFRM_POLICY_BLOCK) { | ||
1664 | XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTPOLBLOCK); | ||
1665 | err = -EPERM; | ||
1666 | goto error; | ||
1667 | } | ||
1668 | npols ++; | ||
1669 | xfrm_nr += pols[1]->xfrm_nr; | ||
1670 | } | ||
1671 | } | ||
1672 | |||
1673 | /* | ||
1674 | * Because neither flowi nor bundle information knows about | ||
1675 | * transformation template size. On more than one policy usage | ||
1676 | * we can realize whether all of them is bypass or not after | ||
1677 | * they are searched. See above not-transformed bypass | ||
1678 | * is surrounded by non-sub policy configuration, too. | ||
1679 | */ | ||
1680 | if (xfrm_nr == 0) { | ||
1681 | /* Flow passes not transformed. */ | ||
1682 | xfrm_pols_put(pols, npols); | ||
1683 | return 0; | ||
1684 | } | ||
1685 | |||
1686 | #endif | ||
1687 | nx = xfrm_tmpl_resolve(pols, npols, fl, xfrm, family); | ||
1688 | |||
1689 | if (unlikely(nx<0)) { | ||
1690 | err = nx; | ||
1691 | if (err == -EAGAIN && net->xfrm.sysctl_larval_drop) { | ||
1692 | /* EREMOTE tells the caller to generate | ||
1693 | * a one-shot blackhole route. | ||
1694 | */ | ||
1695 | XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTNOSTATES); | ||
1696 | xfrm_pol_put(policy); | ||
1697 | return -EREMOTE; | ||
1698 | } | ||
1699 | if (err == -EAGAIN && (flags & XFRM_LOOKUP_WAIT)) { | ||
1700 | DECLARE_WAITQUEUE(wait, current); | ||
1701 | |||
1702 | add_wait_queue(&net->xfrm.km_waitq, &wait); | ||
1703 | set_current_state(TASK_INTERRUPTIBLE); | ||
1704 | schedule(); | ||
1705 | set_current_state(TASK_RUNNING); | ||
1706 | remove_wait_queue(&net->xfrm.km_waitq, &wait); | ||
1707 | |||
1708 | nx = xfrm_tmpl_resolve(pols, npols, fl, xfrm, family); | ||
1709 | |||
1710 | if (nx == -EAGAIN && signal_pending(current)) { | ||
1711 | XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTNOSTATES); | ||
1712 | err = -ERESTART; | ||
1713 | goto error; | ||
1714 | } | ||
1715 | if (nx == -EAGAIN || | ||
1716 | genid != atomic_read(&flow_cache_genid)) { | ||
1717 | xfrm_pols_put(pols, npols); | ||
1718 | goto restart; | ||
1719 | } | ||
1720 | err = nx; | ||
1721 | } | ||
1722 | if (err < 0) { | ||
1723 | XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTNOSTATES); | ||
1724 | goto error; | ||
1725 | } | ||
1726 | } | ||
1727 | if (nx == 0) { | ||
1728 | /* Flow passes not transformed. */ | ||
1729 | xfrm_pols_put(pols, npols); | ||
1730 | return 0; | ||
1731 | } | ||
1732 | |||
1733 | dst = xfrm_bundle_create(policy, xfrm, nx, fl, dst_orig); | ||
1734 | err = PTR_ERR(dst); | ||
1735 | if (IS_ERR(dst)) { | ||
1736 | XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTBUNDLEGENERROR); | ||
1737 | goto error; | ||
1738 | } | ||
1739 | |||
1740 | for (pi = 0; pi < npols; pi++) { | ||
1741 | read_lock_bh(&pols[pi]->lock); | ||
1742 | pol_dead |= pols[pi]->walk.dead; | ||
1743 | read_unlock_bh(&pols[pi]->lock); | ||
1744 | } | ||
1745 | |||
1746 | write_lock_bh(&policy->lock); | ||
1747 | if (unlikely(pol_dead || stale_bundle(dst))) { | ||
1748 | /* Wow! While we worked on resolving, this | ||
1749 | * policy has gone. Retry. It is not paranoia, | ||
1750 | * we just cannot enlist new bundle to dead object. | ||
1751 | * We can't enlist stable bundles either. | ||
1752 | */ | ||
1753 | write_unlock_bh(&policy->lock); | ||
1754 | dst_free(dst); | ||
1755 | |||
1756 | if (pol_dead) | ||
1757 | XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTPOLDEAD); | ||
1758 | else | ||
1759 | XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTBUNDLECHECKERROR); | ||
1760 | err = -EHOSTUNREACH; | ||
1761 | goto error; | ||
1762 | } | ||
1763 | |||
1764 | if (npols > 1) | ||
1765 | err = xfrm_dst_update_parent(dst, &pols[1]->selector); | ||
1766 | else | ||
1767 | err = xfrm_dst_update_origin(dst, fl); | ||
1768 | if (unlikely(err)) { | ||
1769 | write_unlock_bh(&policy->lock); | ||
1770 | dst_free(dst); | ||
1771 | XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTBUNDLECHECKERROR); | ||
1772 | goto error; | ||
1773 | } | ||
1774 | |||
1775 | dst->next = policy->bundles; | ||
1776 | policy->bundles = dst; | ||
1777 | dst_hold(dst); | ||
1778 | write_unlock_bh(&policy->lock); | ||
1779 | } | 1859 | } |
1780 | *dst_p = dst; | 1860 | ok: |
1781 | dst_release(dst_orig); | 1861 | xfrm_pols_put(pols, drop_pols); |
1782 | xfrm_pols_put(pols, npols); | ||
1783 | return 0; | 1862 | return 0; |
1784 | 1863 | ||
1864 | nopol: | ||
1865 | if (!(flags & XFRM_LOOKUP_ICMP)) | ||
1866 | goto ok; | ||
1867 | err = -ENOENT; | ||
1785 | error: | 1868 | error: |
1786 | xfrm_pols_put(pols, npols); | 1869 | dst_release(dst); |
1787 | dropdst: | 1870 | dropdst: |
1788 | dst_release(dst_orig); | 1871 | dst_release(dst_orig); |
1789 | *dst_p = NULL; | 1872 | *dst_p = NULL; |
1873 | xfrm_pols_put(pols, drop_pols); | ||
1790 | return err; | 1874 | return err; |
1791 | |||
1792 | nopol: | ||
1793 | err = -ENOENT; | ||
1794 | if (flags & XFRM_LOOKUP_ICMP) | ||
1795 | goto dropdst; | ||
1796 | return 0; | ||
1797 | } | 1875 | } |
1798 | EXPORT_SYMBOL(__xfrm_lookup); | 1876 | EXPORT_SYMBOL(__xfrm_lookup); |
1799 | 1877 | ||
@@ -1952,9 +2030,16 @@ int __xfrm_policy_check(struct sock *sk, int dir, struct sk_buff *skb, | |||
1952 | } | 2030 | } |
1953 | } | 2031 | } |
1954 | 2032 | ||
1955 | if (!pol) | 2033 | if (!pol) { |
1956 | pol = flow_cache_lookup(net, &fl, family, fl_dir, | 2034 | struct flow_cache_object *flo; |
1957 | xfrm_policy_lookup); | 2035 | |
2036 | flo = flow_cache_lookup(net, &fl, family, fl_dir, | ||
2037 | xfrm_policy_lookup, NULL); | ||
2038 | if (IS_ERR_OR_NULL(flo)) | ||
2039 | pol = ERR_CAST(flo); | ||
2040 | else | ||
2041 | pol = container_of(flo, struct xfrm_policy, flo); | ||
2042 | } | ||
1958 | 2043 | ||
1959 | if (IS_ERR(pol)) { | 2044 | if (IS_ERR(pol)) { |
1960 | XFRM_INC_STATS(net, LINUX_MIB_XFRMINPOLERROR); | 2045 | XFRM_INC_STATS(net, LINUX_MIB_XFRMINPOLERROR); |
@@ -2138,71 +2223,24 @@ static struct dst_entry *xfrm_negative_advice(struct dst_entry *dst) | |||
2138 | return dst; | 2223 | return dst; |
2139 | } | 2224 | } |
2140 | 2225 | ||
2141 | static void prune_one_bundle(struct xfrm_policy *pol, int (*func)(struct dst_entry *), struct dst_entry **gc_list_p) | 2226 | static void __xfrm_garbage_collect(struct net *net) |
2142 | { | ||
2143 | struct dst_entry *dst, **dstp; | ||
2144 | |||
2145 | write_lock(&pol->lock); | ||
2146 | dstp = &pol->bundles; | ||
2147 | while ((dst=*dstp) != NULL) { | ||
2148 | if (func(dst)) { | ||
2149 | *dstp = dst->next; | ||
2150 | dst->next = *gc_list_p; | ||
2151 | *gc_list_p = dst; | ||
2152 | } else { | ||
2153 | dstp = &dst->next; | ||
2154 | } | ||
2155 | } | ||
2156 | write_unlock(&pol->lock); | ||
2157 | } | ||
2158 | |||
2159 | static void xfrm_prune_bundles(struct net *net, int (*func)(struct dst_entry *)) | ||
2160 | { | 2227 | { |
2161 | struct dst_entry *gc_list = NULL; | 2228 | struct dst_entry *head, *next; |
2162 | int dir; | ||
2163 | 2229 | ||
2164 | read_lock_bh(&xfrm_policy_lock); | 2230 | flow_cache_flush(); |
2165 | for (dir = 0; dir < XFRM_POLICY_MAX * 2; dir++) { | ||
2166 | struct xfrm_policy *pol; | ||
2167 | struct hlist_node *entry; | ||
2168 | struct hlist_head *table; | ||
2169 | int i; | ||
2170 | 2231 | ||
2171 | hlist_for_each_entry(pol, entry, | 2232 | spin_lock_bh(&xfrm_policy_sk_bundle_lock); |
2172 | &net->xfrm.policy_inexact[dir], bydst) | 2233 | head = xfrm_policy_sk_bundles; |
2173 | prune_one_bundle(pol, func, &gc_list); | 2234 | xfrm_policy_sk_bundles = NULL; |
2235 | spin_unlock_bh(&xfrm_policy_sk_bundle_lock); | ||
2174 | 2236 | ||
2175 | table = net->xfrm.policy_bydst[dir].table; | 2237 | while (head) { |
2176 | for (i = net->xfrm.policy_bydst[dir].hmask; i >= 0; i--) { | 2238 | next = head->next; |
2177 | hlist_for_each_entry(pol, entry, table + i, bydst) | 2239 | dst_free(head); |
2178 | prune_one_bundle(pol, func, &gc_list); | 2240 | head = next; |
2179 | } | ||
2180 | } | ||
2181 | read_unlock_bh(&xfrm_policy_lock); | ||
2182 | |||
2183 | while (gc_list) { | ||
2184 | struct dst_entry *dst = gc_list; | ||
2185 | gc_list = dst->next; | ||
2186 | dst_free(dst); | ||
2187 | } | 2241 | } |
2188 | } | 2242 | } |
2189 | 2243 | ||
2190 | static int unused_bundle(struct dst_entry *dst) | ||
2191 | { | ||
2192 | return !atomic_read(&dst->__refcnt); | ||
2193 | } | ||
2194 | |||
2195 | static void __xfrm_garbage_collect(struct net *net) | ||
2196 | { | ||
2197 | xfrm_prune_bundles(net, unused_bundle); | ||
2198 | } | ||
2199 | |||
2200 | static int xfrm_flush_bundles(struct net *net) | ||
2201 | { | ||
2202 | xfrm_prune_bundles(net, stale_bundle); | ||
2203 | return 0; | ||
2204 | } | ||
2205 | |||
2206 | static void xfrm_init_pmtu(struct dst_entry *dst) | 2244 | static void xfrm_init_pmtu(struct dst_entry *dst) |
2207 | { | 2245 | { |
2208 | do { | 2246 | do { |
@@ -2260,7 +2298,9 @@ int xfrm_bundle_ok(struct xfrm_policy *pol, struct xfrm_dst *first, | |||
2260 | return 0; | 2298 | return 0; |
2261 | if (dst->xfrm->km.state != XFRM_STATE_VALID) | 2299 | if (dst->xfrm->km.state != XFRM_STATE_VALID) |
2262 | return 0; | 2300 | return 0; |
2263 | if (xdst->genid != dst->xfrm->genid) | 2301 | if (xdst->xfrm_genid != dst->xfrm->genid) |
2302 | return 0; | ||
2303 | if (xdst->policy_genid != atomic_read(&xdst->pols[0]->genid)) | ||
2264 | return 0; | 2304 | return 0; |
2265 | 2305 | ||
2266 | if (strict && fl && | 2306 | if (strict && fl && |
@@ -2425,7 +2465,7 @@ static int xfrm_dev_event(struct notifier_block *this, unsigned long event, void | |||
2425 | 2465 | ||
2426 | switch (event) { | 2466 | switch (event) { |
2427 | case NETDEV_DOWN: | 2467 | case NETDEV_DOWN: |
2428 | xfrm_flush_bundles(dev_net(dev)); | 2468 | __xfrm_garbage_collect(dev_net(dev)); |
2429 | } | 2469 | } |
2430 | return NOTIFY_DONE; | 2470 | return NOTIFY_DONE; |
2431 | } | 2471 | } |
@@ -2531,7 +2571,6 @@ static void xfrm_policy_fini(struct net *net) | |||
2531 | audit_info.sessionid = -1; | 2571 | audit_info.sessionid = -1; |
2532 | audit_info.secid = 0; | 2572 | audit_info.secid = 0; |
2533 | xfrm_policy_flush(net, XFRM_POLICY_TYPE_MAIN, &audit_info); | 2573 | xfrm_policy_flush(net, XFRM_POLICY_TYPE_MAIN, &audit_info); |
2534 | flush_work(&xfrm_policy_gc_work); | ||
2535 | 2574 | ||
2536 | WARN_ON(!list_empty(&net->xfrm.policy_all)); | 2575 | WARN_ON(!list_empty(&net->xfrm.policy_all)); |
2537 | 2576 | ||
@@ -2757,7 +2796,6 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol, | |||
2757 | struct xfrm_migrate *m, int num_migrate) | 2796 | struct xfrm_migrate *m, int num_migrate) |
2758 | { | 2797 | { |
2759 | struct xfrm_migrate *mp; | 2798 | struct xfrm_migrate *mp; |
2760 | struct dst_entry *dst; | ||
2761 | int i, j, n = 0; | 2799 | int i, j, n = 0; |
2762 | 2800 | ||
2763 | write_lock_bh(&pol->lock); | 2801 | write_lock_bh(&pol->lock); |
@@ -2782,10 +2820,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol, | |||
2782 | sizeof(pol->xfrm_vec[i].saddr)); | 2820 | sizeof(pol->xfrm_vec[i].saddr)); |
2783 | pol->xfrm_vec[i].encap_family = mp->new_family; | 2821 | pol->xfrm_vec[i].encap_family = mp->new_family; |
2784 | /* flush bundles */ | 2822 | /* flush bundles */ |
2785 | while ((dst = pol->bundles) != NULL) { | 2823 | atomic_inc(&pol->genid); |
2786 | pol->bundles = dst->next; | ||
2787 | dst_free(dst); | ||
2788 | } | ||
2789 | } | 2824 | } |
2790 | } | 2825 | } |
2791 | 2826 | ||
diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c index 17d5b96f2fc8..5208b12fbfb4 100644 --- a/net/xfrm/xfrm_state.c +++ b/net/xfrm/xfrm_state.c | |||
@@ -22,6 +22,7 @@ | |||
22 | #include <linux/audit.h> | 22 | #include <linux/audit.h> |
23 | #include <asm/uaccess.h> | 23 | #include <asm/uaccess.h> |
24 | #include <linux/ktime.h> | 24 | #include <linux/ktime.h> |
25 | #include <linux/slab.h> | ||
25 | #include <linux/interrupt.h> | 26 | #include <linux/interrupt.h> |
26 | #include <linux/kernel.h> | 27 | #include <linux/kernel.h> |
27 | 28 | ||
@@ -37,7 +38,6 @@ | |||
37 | static DEFINE_SPINLOCK(xfrm_state_lock); | 38 | static DEFINE_SPINLOCK(xfrm_state_lock); |
38 | 39 | ||
39 | static unsigned int xfrm_state_hashmax __read_mostly = 1 * 1024 * 1024; | 40 | static unsigned int xfrm_state_hashmax __read_mostly = 1 * 1024 * 1024; |
40 | static unsigned int xfrm_state_genid; | ||
41 | 41 | ||
42 | static struct xfrm_state_afinfo *xfrm_state_get_afinfo(unsigned int family); | 42 | static struct xfrm_state_afinfo *xfrm_state_get_afinfo(unsigned int family); |
43 | static void xfrm_state_put_afinfo(struct xfrm_state_afinfo *afinfo); | 43 | static void xfrm_state_put_afinfo(struct xfrm_state_afinfo *afinfo); |
@@ -923,8 +923,6 @@ static void __xfrm_state_insert(struct xfrm_state *x) | |||
923 | struct net *net = xs_net(x); | 923 | struct net *net = xs_net(x); |
924 | unsigned int h; | 924 | unsigned int h; |
925 | 925 | ||
926 | x->genid = ++xfrm_state_genid; | ||
927 | |||
928 | list_add(&x->km.all, &net->xfrm.state_all); | 926 | list_add(&x->km.all, &net->xfrm.state_all); |
929 | 927 | ||
930 | h = xfrm_dst_hash(net, &x->id.daddr, &x->props.saddr, | 928 | h = xfrm_dst_hash(net, &x->id.daddr, &x->props.saddr, |
@@ -970,7 +968,7 @@ static void __xfrm_state_bump_genids(struct xfrm_state *xnew) | |||
970 | (mark & x->mark.m) == x->mark.v && | 968 | (mark & x->mark.m) == x->mark.v && |
971 | !xfrm_addr_cmp(&x->id.daddr, &xnew->id.daddr, family) && | 969 | !xfrm_addr_cmp(&x->id.daddr, &xnew->id.daddr, family) && |
972 | !xfrm_addr_cmp(&x->props.saddr, &xnew->props.saddr, family)) | 970 | !xfrm_addr_cmp(&x->props.saddr, &xnew->props.saddr, family)) |
973 | x->genid = xfrm_state_genid; | 971 | x->genid++; |
974 | } | 972 | } |
975 | } | 973 | } |
976 | 974 | ||
diff --git a/net/xfrm/xfrm_sysctl.c b/net/xfrm/xfrm_sysctl.c index 2c4d6cdcba49..05640bc9594b 100644 --- a/net/xfrm/xfrm_sysctl.c +++ b/net/xfrm/xfrm_sysctl.c | |||
@@ -1,4 +1,5 @@ | |||
1 | #include <linux/sysctl.h> | 1 | #include <linux/sysctl.h> |
2 | #include <linux/slab.h> | ||
2 | #include <net/net_namespace.h> | 3 | #include <net/net_namespace.h> |
3 | #include <net/xfrm.h> | 4 | #include <net/xfrm.h> |
4 | 5 | ||
diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c index 6106b72826d3..a267fbdda525 100644 --- a/net/xfrm/xfrm_user.c +++ b/net/xfrm/xfrm_user.c | |||
@@ -1741,6 +1741,10 @@ static int xfrm_add_pol_expire(struct sk_buff *skb, struct nlmsghdr *nlh, | |||
1741 | if (err) | 1741 | if (err) |
1742 | return err; | 1742 | return err; |
1743 | 1743 | ||
1744 | err = verify_policy_dir(p->dir); | ||
1745 | if (err) | ||
1746 | return err; | ||
1747 | |||
1744 | if (p->index) | 1748 | if (p->index) |
1745 | xp = xfrm_policy_byid(net, mark, type, p->dir, p->index, 0, &err); | 1749 | xp = xfrm_policy_byid(net, mark, type, p->dir, p->index, 0, &err); |
1746 | else { | 1750 | else { |
@@ -1766,13 +1770,9 @@ static int xfrm_add_pol_expire(struct sk_buff *skb, struct nlmsghdr *nlh, | |||
1766 | if (xp == NULL) | 1770 | if (xp == NULL) |
1767 | return -ENOENT; | 1771 | return -ENOENT; |
1768 | 1772 | ||
1769 | read_lock(&xp->lock); | 1773 | if (unlikely(xp->walk.dead)) |
1770 | if (xp->walk.dead) { | ||
1771 | read_unlock(&xp->lock); | ||
1772 | goto out; | 1774 | goto out; |
1773 | } | ||
1774 | 1775 | ||
1775 | read_unlock(&xp->lock); | ||
1776 | err = 0; | 1776 | err = 0; |
1777 | if (up->hard) { | 1777 | if (up->hard) { |
1778 | uid_t loginuid = NETLINK_CB(skb).loginuid; | 1778 | uid_t loginuid = NETLINK_CB(skb).loginuid; |