diff options
Diffstat (limited to 'net/core/dev.c')
-rw-r--r-- | net/core/dev.c | 336 |
1 files changed, 244 insertions, 92 deletions
diff --git a/net/core/dev.c b/net/core/dev.c index 231d3125bf26..edcf019c056d 100644 --- a/net/core/dev.c +++ b/net/core/dev.c | |||
@@ -133,6 +133,10 @@ | |||
133 | #include <linux/pci.h> | 133 | #include <linux/pci.h> |
134 | #include <linux/inetdevice.h> | 134 | #include <linux/inetdevice.h> |
135 | #include <linux/cpu_rmap.h> | 135 | #include <linux/cpu_rmap.h> |
136 | #include <linux/if_tunnel.h> | ||
137 | #include <linux/if_pppox.h> | ||
138 | #include <linux/ppp_defs.h> | ||
139 | #include <linux/net_tstamp.h> | ||
136 | 140 | ||
137 | #include "net-sysfs.h" | 141 | #include "net-sysfs.h" |
138 | 142 | ||
@@ -1474,6 +1478,57 @@ static inline void net_timestamp_check(struct sk_buff *skb) | |||
1474 | __net_timestamp(skb); | 1478 | __net_timestamp(skb); |
1475 | } | 1479 | } |
1476 | 1480 | ||
1481 | static int net_hwtstamp_validate(struct ifreq *ifr) | ||
1482 | { | ||
1483 | struct hwtstamp_config cfg; | ||
1484 | enum hwtstamp_tx_types tx_type; | ||
1485 | enum hwtstamp_rx_filters rx_filter; | ||
1486 | int tx_type_valid = 0; | ||
1487 | int rx_filter_valid = 0; | ||
1488 | |||
1489 | if (copy_from_user(&cfg, ifr->ifr_data, sizeof(cfg))) | ||
1490 | return -EFAULT; | ||
1491 | |||
1492 | if (cfg.flags) /* reserved for future extensions */ | ||
1493 | return -EINVAL; | ||
1494 | |||
1495 | tx_type = cfg.tx_type; | ||
1496 | rx_filter = cfg.rx_filter; | ||
1497 | |||
1498 | switch (tx_type) { | ||
1499 | case HWTSTAMP_TX_OFF: | ||
1500 | case HWTSTAMP_TX_ON: | ||
1501 | case HWTSTAMP_TX_ONESTEP_SYNC: | ||
1502 | tx_type_valid = 1; | ||
1503 | break; | ||
1504 | } | ||
1505 | |||
1506 | switch (rx_filter) { | ||
1507 | case HWTSTAMP_FILTER_NONE: | ||
1508 | case HWTSTAMP_FILTER_ALL: | ||
1509 | case HWTSTAMP_FILTER_SOME: | ||
1510 | case HWTSTAMP_FILTER_PTP_V1_L4_EVENT: | ||
1511 | case HWTSTAMP_FILTER_PTP_V1_L4_SYNC: | ||
1512 | case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ: | ||
1513 | case HWTSTAMP_FILTER_PTP_V2_L4_EVENT: | ||
1514 | case HWTSTAMP_FILTER_PTP_V2_L4_SYNC: | ||
1515 | case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ: | ||
1516 | case HWTSTAMP_FILTER_PTP_V2_L2_EVENT: | ||
1517 | case HWTSTAMP_FILTER_PTP_V2_L2_SYNC: | ||
1518 | case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ: | ||
1519 | case HWTSTAMP_FILTER_PTP_V2_EVENT: | ||
1520 | case HWTSTAMP_FILTER_PTP_V2_SYNC: | ||
1521 | case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ: | ||
1522 | rx_filter_valid = 1; | ||
1523 | break; | ||
1524 | } | ||
1525 | |||
1526 | if (!tx_type_valid || !rx_filter_valid) | ||
1527 | return -ERANGE; | ||
1528 | |||
1529 | return 0; | ||
1530 | } | ||
1531 | |||
1477 | static inline bool is_skb_forwardable(struct net_device *dev, | 1532 | static inline bool is_skb_forwardable(struct net_device *dev, |
1478 | struct sk_buff *skb) | 1533 | struct sk_buff *skb) |
1479 | { | 1534 | { |
@@ -1955,9 +2010,11 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb) | |||
1955 | #ifdef CONFIG_HIGHMEM | 2010 | #ifdef CONFIG_HIGHMEM |
1956 | int i; | 2011 | int i; |
1957 | if (!(dev->features & NETIF_F_HIGHDMA)) { | 2012 | if (!(dev->features & NETIF_F_HIGHDMA)) { |
1958 | for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) | 2013 | for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { |
1959 | if (PageHighMem(skb_shinfo(skb)->frags[i].page)) | 2014 | skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; |
2015 | if (PageHighMem(skb_frag_page(frag))) | ||
1960 | return 1; | 2016 | return 1; |
2017 | } | ||
1961 | } | 2018 | } |
1962 | 2019 | ||
1963 | if (PCI_DMA_BUS_IS_PHYS) { | 2020 | if (PCI_DMA_BUS_IS_PHYS) { |
@@ -1966,7 +2023,8 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb) | |||
1966 | if (!pdev) | 2023 | if (!pdev) |
1967 | return 0; | 2024 | return 0; |
1968 | for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { | 2025 | for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { |
1969 | dma_addr_t addr = page_to_phys(skb_shinfo(skb)->frags[i].page); | 2026 | skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; |
2027 | dma_addr_t addr = page_to_phys(skb_frag_page(frag)); | ||
1970 | if (!pdev->dma_mask || addr + PAGE_SIZE - 1 > *pdev->dma_mask) | 2028 | if (!pdev->dma_mask || addr + PAGE_SIZE - 1 > *pdev->dma_mask) |
1971 | return 1; | 2029 | return 1; |
1972 | } | 2030 | } |
@@ -2527,25 +2585,31 @@ static inline void ____napi_schedule(struct softnet_data *sd, | |||
2527 | 2585 | ||
2528 | /* | 2586 | /* |
2529 | * __skb_get_rxhash: calculate a flow hash based on src/dst addresses | 2587 | * __skb_get_rxhash: calculate a flow hash based on src/dst addresses |
2530 | * and src/dst port numbers. Returns a non-zero hash number on success | 2588 | * and src/dst port numbers. Sets rxhash in skb to non-zero hash value |
2531 | * and 0 on failure. | 2589 | * on success, zero indicates no valid hash. Also, sets l4_rxhash in skb |
2590 | * if hash is a canonical 4-tuple hash over transport ports. | ||
2532 | */ | 2591 | */ |
2533 | __u32 __skb_get_rxhash(struct sk_buff *skb) | 2592 | void __skb_get_rxhash(struct sk_buff *skb) |
2534 | { | 2593 | { |
2535 | int nhoff, hash = 0, poff; | 2594 | int nhoff, hash = 0, poff; |
2536 | const struct ipv6hdr *ip6; | 2595 | const struct ipv6hdr *ip6; |
2537 | const struct iphdr *ip; | 2596 | const struct iphdr *ip; |
2597 | const struct vlan_hdr *vlan; | ||
2538 | u8 ip_proto; | 2598 | u8 ip_proto; |
2539 | u32 addr1, addr2, ihl; | 2599 | u32 addr1, addr2; |
2600 | u16 proto; | ||
2540 | union { | 2601 | union { |
2541 | u32 v32; | 2602 | u32 v32; |
2542 | u16 v16[2]; | 2603 | u16 v16[2]; |
2543 | } ports; | 2604 | } ports; |
2544 | 2605 | ||
2545 | nhoff = skb_network_offset(skb); | 2606 | nhoff = skb_network_offset(skb); |
2607 | proto = skb->protocol; | ||
2546 | 2608 | ||
2547 | switch (skb->protocol) { | 2609 | again: |
2610 | switch (proto) { | ||
2548 | case __constant_htons(ETH_P_IP): | 2611 | case __constant_htons(ETH_P_IP): |
2612 | ip: | ||
2549 | if (!pskb_may_pull(skb, sizeof(*ip) + nhoff)) | 2613 | if (!pskb_may_pull(skb, sizeof(*ip) + nhoff)) |
2550 | goto done; | 2614 | goto done; |
2551 | 2615 | ||
@@ -2556,9 +2620,10 @@ __u32 __skb_get_rxhash(struct sk_buff *skb) | |||
2556 | ip_proto = ip->protocol; | 2620 | ip_proto = ip->protocol; |
2557 | addr1 = (__force u32) ip->saddr; | 2621 | addr1 = (__force u32) ip->saddr; |
2558 | addr2 = (__force u32) ip->daddr; | 2622 | addr2 = (__force u32) ip->daddr; |
2559 | ihl = ip->ihl; | 2623 | nhoff += ip->ihl * 4; |
2560 | break; | 2624 | break; |
2561 | case __constant_htons(ETH_P_IPV6): | 2625 | case __constant_htons(ETH_P_IPV6): |
2626 | ipv6: | ||
2562 | if (!pskb_may_pull(skb, sizeof(*ip6) + nhoff)) | 2627 | if (!pskb_may_pull(skb, sizeof(*ip6) + nhoff)) |
2563 | goto done; | 2628 | goto done; |
2564 | 2629 | ||
@@ -2566,20 +2631,71 @@ __u32 __skb_get_rxhash(struct sk_buff *skb) | |||
2566 | ip_proto = ip6->nexthdr; | 2631 | ip_proto = ip6->nexthdr; |
2567 | addr1 = (__force u32) ip6->saddr.s6_addr32[3]; | 2632 | addr1 = (__force u32) ip6->saddr.s6_addr32[3]; |
2568 | addr2 = (__force u32) ip6->daddr.s6_addr32[3]; | 2633 | addr2 = (__force u32) ip6->daddr.s6_addr32[3]; |
2569 | ihl = (40 >> 2); | 2634 | nhoff += 40; |
2570 | break; | 2635 | break; |
2636 | case __constant_htons(ETH_P_8021Q): | ||
2637 | if (!pskb_may_pull(skb, sizeof(*vlan) + nhoff)) | ||
2638 | goto done; | ||
2639 | vlan = (const struct vlan_hdr *) (skb->data + nhoff); | ||
2640 | proto = vlan->h_vlan_encapsulated_proto; | ||
2641 | nhoff += sizeof(*vlan); | ||
2642 | goto again; | ||
2643 | case __constant_htons(ETH_P_PPP_SES): | ||
2644 | if (!pskb_may_pull(skb, PPPOE_SES_HLEN + nhoff)) | ||
2645 | goto done; | ||
2646 | proto = *((__be16 *) (skb->data + nhoff + | ||
2647 | sizeof(struct pppoe_hdr))); | ||
2648 | nhoff += PPPOE_SES_HLEN; | ||
2649 | switch (proto) { | ||
2650 | case __constant_htons(PPP_IP): | ||
2651 | goto ip; | ||
2652 | case __constant_htons(PPP_IPV6): | ||
2653 | goto ipv6; | ||
2654 | default: | ||
2655 | goto done; | ||
2656 | } | ||
2571 | default: | 2657 | default: |
2572 | goto done; | 2658 | goto done; |
2573 | } | 2659 | } |
2574 | 2660 | ||
2661 | switch (ip_proto) { | ||
2662 | case IPPROTO_GRE: | ||
2663 | if (pskb_may_pull(skb, nhoff + 16)) { | ||
2664 | u8 *h = skb->data + nhoff; | ||
2665 | __be16 flags = *(__be16 *)h; | ||
2666 | |||
2667 | /* | ||
2668 | * Only look inside GRE if version zero and no | ||
2669 | * routing | ||
2670 | */ | ||
2671 | if (!(flags & (GRE_VERSION|GRE_ROUTING))) { | ||
2672 | proto = *(__be16 *)(h + 2); | ||
2673 | nhoff += 4; | ||
2674 | if (flags & GRE_CSUM) | ||
2675 | nhoff += 4; | ||
2676 | if (flags & GRE_KEY) | ||
2677 | nhoff += 4; | ||
2678 | if (flags & GRE_SEQ) | ||
2679 | nhoff += 4; | ||
2680 | goto again; | ||
2681 | } | ||
2682 | } | ||
2683 | break; | ||
2684 | case IPPROTO_IPIP: | ||
2685 | goto again; | ||
2686 | default: | ||
2687 | break; | ||
2688 | } | ||
2689 | |||
2575 | ports.v32 = 0; | 2690 | ports.v32 = 0; |
2576 | poff = proto_ports_offset(ip_proto); | 2691 | poff = proto_ports_offset(ip_proto); |
2577 | if (poff >= 0) { | 2692 | if (poff >= 0) { |
2578 | nhoff += ihl * 4 + poff; | 2693 | nhoff += poff; |
2579 | if (pskb_may_pull(skb, nhoff + 4)) { | 2694 | if (pskb_may_pull(skb, nhoff + 4)) { |
2580 | ports.v32 = * (__force u32 *) (skb->data + nhoff); | 2695 | ports.v32 = * (__force u32 *) (skb->data + nhoff); |
2581 | if (ports.v16[1] < ports.v16[0]) | 2696 | if (ports.v16[1] < ports.v16[0]) |
2582 | swap(ports.v16[0], ports.v16[1]); | 2697 | swap(ports.v16[0], ports.v16[1]); |
2698 | skb->l4_rxhash = 1; | ||
2583 | } | 2699 | } |
2584 | } | 2700 | } |
2585 | 2701 | ||
@@ -2592,7 +2708,7 @@ __u32 __skb_get_rxhash(struct sk_buff *skb) | |||
2592 | hash = 1; | 2708 | hash = 1; |
2593 | 2709 | ||
2594 | done: | 2710 | done: |
2595 | return hash; | 2711 | skb->rxhash = hash; |
2596 | } | 2712 | } |
2597 | EXPORT_SYMBOL(__skb_get_rxhash); | 2713 | EXPORT_SYMBOL(__skb_get_rxhash); |
2598 | 2714 | ||
@@ -2606,10 +2722,7 @@ static struct rps_dev_flow * | |||
2606 | set_rps_cpu(struct net_device *dev, struct sk_buff *skb, | 2722 | set_rps_cpu(struct net_device *dev, struct sk_buff *skb, |
2607 | struct rps_dev_flow *rflow, u16 next_cpu) | 2723 | struct rps_dev_flow *rflow, u16 next_cpu) |
2608 | { | 2724 | { |
2609 | u16 tcpu; | 2725 | if (next_cpu != RPS_NO_CPU) { |
2610 | |||
2611 | tcpu = rflow->cpu = next_cpu; | ||
2612 | if (tcpu != RPS_NO_CPU) { | ||
2613 | #ifdef CONFIG_RFS_ACCEL | 2726 | #ifdef CONFIG_RFS_ACCEL |
2614 | struct netdev_rx_queue *rxqueue; | 2727 | struct netdev_rx_queue *rxqueue; |
2615 | struct rps_dev_flow_table *flow_table; | 2728 | struct rps_dev_flow_table *flow_table; |
@@ -2637,16 +2750,16 @@ set_rps_cpu(struct net_device *dev, struct sk_buff *skb, | |||
2637 | goto out; | 2750 | goto out; |
2638 | old_rflow = rflow; | 2751 | old_rflow = rflow; |
2639 | rflow = &flow_table->flows[flow_id]; | 2752 | rflow = &flow_table->flows[flow_id]; |
2640 | rflow->cpu = next_cpu; | ||
2641 | rflow->filter = rc; | 2753 | rflow->filter = rc; |
2642 | if (old_rflow->filter == rflow->filter) | 2754 | if (old_rflow->filter == rflow->filter) |
2643 | old_rflow->filter = RPS_NO_FILTER; | 2755 | old_rflow->filter = RPS_NO_FILTER; |
2644 | out: | 2756 | out: |
2645 | #endif | 2757 | #endif |
2646 | rflow->last_qtail = | 2758 | rflow->last_qtail = |
2647 | per_cpu(softnet_data, tcpu).input_queue_head; | 2759 | per_cpu(softnet_data, next_cpu).input_queue_head; |
2648 | } | 2760 | } |
2649 | 2761 | ||
2762 | rflow->cpu = next_cpu; | ||
2650 | return rflow; | 2763 | return rflow; |
2651 | } | 2764 | } |
2652 | 2765 | ||
@@ -2681,13 +2794,13 @@ static int get_rps_cpu(struct net_device *dev, struct sk_buff *skb, | |||
2681 | map = rcu_dereference(rxqueue->rps_map); | 2794 | map = rcu_dereference(rxqueue->rps_map); |
2682 | if (map) { | 2795 | if (map) { |
2683 | if (map->len == 1 && | 2796 | if (map->len == 1 && |
2684 | !rcu_dereference_raw(rxqueue->rps_flow_table)) { | 2797 | !rcu_access_pointer(rxqueue->rps_flow_table)) { |
2685 | tcpu = map->cpus[0]; | 2798 | tcpu = map->cpus[0]; |
2686 | if (cpu_online(tcpu)) | 2799 | if (cpu_online(tcpu)) |
2687 | cpu = tcpu; | 2800 | cpu = tcpu; |
2688 | goto done; | 2801 | goto done; |
2689 | } | 2802 | } |
2690 | } else if (!rcu_dereference_raw(rxqueue->rps_flow_table)) { | 2803 | } else if (!rcu_access_pointer(rxqueue->rps_flow_table)) { |
2691 | goto done; | 2804 | goto done; |
2692 | } | 2805 | } |
2693 | 2806 | ||
@@ -3102,8 +3215,8 @@ void netdev_rx_handler_unregister(struct net_device *dev) | |||
3102 | { | 3215 | { |
3103 | 3216 | ||
3104 | ASSERT_RTNL(); | 3217 | ASSERT_RTNL(); |
3105 | rcu_assign_pointer(dev->rx_handler, NULL); | 3218 | RCU_INIT_POINTER(dev->rx_handler, NULL); |
3106 | rcu_assign_pointer(dev->rx_handler_data, NULL); | 3219 | RCU_INIT_POINTER(dev->rx_handler_data, NULL); |
3107 | } | 3220 | } |
3108 | EXPORT_SYMBOL_GPL(netdev_rx_handler_unregister); | 3221 | EXPORT_SYMBOL_GPL(netdev_rx_handler_unregister); |
3109 | 3222 | ||
@@ -3170,6 +3283,17 @@ another_round: | |||
3170 | ncls: | 3283 | ncls: |
3171 | #endif | 3284 | #endif |
3172 | 3285 | ||
3286 | if (vlan_tx_tag_present(skb)) { | ||
3287 | if (pt_prev) { | ||
3288 | ret = deliver_skb(skb, pt_prev, orig_dev); | ||
3289 | pt_prev = NULL; | ||
3290 | } | ||
3291 | if (vlan_do_receive(&skb)) | ||
3292 | goto another_round; | ||
3293 | else if (unlikely(!skb)) | ||
3294 | goto out; | ||
3295 | } | ||
3296 | |||
3173 | rx_handler = rcu_dereference(skb->dev->rx_handler); | 3297 | rx_handler = rcu_dereference(skb->dev->rx_handler); |
3174 | if (rx_handler) { | 3298 | if (rx_handler) { |
3175 | if (pt_prev) { | 3299 | if (pt_prev) { |
@@ -3190,18 +3314,6 @@ ncls: | |||
3190 | } | 3314 | } |
3191 | } | 3315 | } |
3192 | 3316 | ||
3193 | if (vlan_tx_tag_present(skb)) { | ||
3194 | if (pt_prev) { | ||
3195 | ret = deliver_skb(skb, pt_prev, orig_dev); | ||
3196 | pt_prev = NULL; | ||
3197 | } | ||
3198 | if (vlan_do_receive(&skb)) { | ||
3199 | ret = __netif_receive_skb(skb); | ||
3200 | goto out; | ||
3201 | } else if (unlikely(!skb)) | ||
3202 | goto out; | ||
3203 | } | ||
3204 | |||
3205 | /* deliver only exact match when indicated */ | 3317 | /* deliver only exact match when indicated */ |
3206 | null_or_dev = deliver_exact ? skb->dev : NULL; | 3318 | null_or_dev = deliver_exact ? skb->dev : NULL; |
3207 | 3319 | ||
@@ -3429,10 +3541,10 @@ pull: | |||
3429 | skb->data_len -= grow; | 3541 | skb->data_len -= grow; |
3430 | 3542 | ||
3431 | skb_shinfo(skb)->frags[0].page_offset += grow; | 3543 | skb_shinfo(skb)->frags[0].page_offset += grow; |
3432 | skb_shinfo(skb)->frags[0].size -= grow; | 3544 | skb_frag_size_sub(&skb_shinfo(skb)->frags[0], grow); |
3433 | 3545 | ||
3434 | if (unlikely(!skb_shinfo(skb)->frags[0].size)) { | 3546 | if (unlikely(!skb_frag_size(&skb_shinfo(skb)->frags[0]))) { |
3435 | put_page(skb_shinfo(skb)->frags[0].page); | 3547 | skb_frag_unref(skb, 0); |
3436 | memmove(skb_shinfo(skb)->frags, | 3548 | memmove(skb_shinfo(skb)->frags, |
3437 | skb_shinfo(skb)->frags + 1, | 3549 | skb_shinfo(skb)->frags + 1, |
3438 | --skb_shinfo(skb)->nr_frags * sizeof(skb_frag_t)); | 3550 | --skb_shinfo(skb)->nr_frags * sizeof(skb_frag_t)); |
@@ -3496,11 +3608,10 @@ void skb_gro_reset_offset(struct sk_buff *skb) | |||
3496 | NAPI_GRO_CB(skb)->frag0_len = 0; | 3608 | NAPI_GRO_CB(skb)->frag0_len = 0; |
3497 | 3609 | ||
3498 | if (skb->mac_header == skb->tail && | 3610 | if (skb->mac_header == skb->tail && |
3499 | !PageHighMem(skb_shinfo(skb)->frags[0].page)) { | 3611 | !PageHighMem(skb_frag_page(&skb_shinfo(skb)->frags[0]))) { |
3500 | NAPI_GRO_CB(skb)->frag0 = | 3612 | NAPI_GRO_CB(skb)->frag0 = |
3501 | page_address(skb_shinfo(skb)->frags[0].page) + | 3613 | skb_frag_address(&skb_shinfo(skb)->frags[0]); |
3502 | skb_shinfo(skb)->frags[0].page_offset; | 3614 | NAPI_GRO_CB(skb)->frag0_len = skb_frag_size(&skb_shinfo(skb)->frags[0]); |
3503 | NAPI_GRO_CB(skb)->frag0_len = skb_shinfo(skb)->frags[0].size; | ||
3504 | } | 3615 | } |
3505 | } | 3616 | } |
3506 | EXPORT_SYMBOL(skb_gro_reset_offset); | 3617 | EXPORT_SYMBOL(skb_gro_reset_offset); |
@@ -3982,6 +4093,60 @@ static int dev_ifconf(struct net *net, char __user *arg) | |||
3982 | } | 4093 | } |
3983 | 4094 | ||
3984 | #ifdef CONFIG_PROC_FS | 4095 | #ifdef CONFIG_PROC_FS |
4096 | |||
4097 | #define BUCKET_SPACE (32 - NETDEV_HASHBITS) | ||
4098 | |||
4099 | struct dev_iter_state { | ||
4100 | struct seq_net_private p; | ||
4101 | unsigned int pos; /* bucket << BUCKET_SPACE + offset */ | ||
4102 | }; | ||
4103 | |||
4104 | #define get_bucket(x) ((x) >> BUCKET_SPACE) | ||
4105 | #define get_offset(x) ((x) & ((1 << BUCKET_SPACE) - 1)) | ||
4106 | #define set_bucket_offset(b, o) ((b) << BUCKET_SPACE | (o)) | ||
4107 | |||
4108 | static inline struct net_device *dev_from_same_bucket(struct seq_file *seq) | ||
4109 | { | ||
4110 | struct dev_iter_state *state = seq->private; | ||
4111 | struct net *net = seq_file_net(seq); | ||
4112 | struct net_device *dev; | ||
4113 | struct hlist_node *p; | ||
4114 | struct hlist_head *h; | ||
4115 | unsigned int count, bucket, offset; | ||
4116 | |||
4117 | bucket = get_bucket(state->pos); | ||
4118 | offset = get_offset(state->pos); | ||
4119 | h = &net->dev_name_head[bucket]; | ||
4120 | count = 0; | ||
4121 | hlist_for_each_entry_rcu(dev, p, h, name_hlist) { | ||
4122 | if (count++ == offset) { | ||
4123 | state->pos = set_bucket_offset(bucket, count); | ||
4124 | return dev; | ||
4125 | } | ||
4126 | } | ||
4127 | |||
4128 | return NULL; | ||
4129 | } | ||
4130 | |||
4131 | static inline struct net_device *dev_from_new_bucket(struct seq_file *seq) | ||
4132 | { | ||
4133 | struct dev_iter_state *state = seq->private; | ||
4134 | struct net_device *dev; | ||
4135 | unsigned int bucket; | ||
4136 | |||
4137 | bucket = get_bucket(state->pos); | ||
4138 | do { | ||
4139 | dev = dev_from_same_bucket(seq); | ||
4140 | if (dev) | ||
4141 | return dev; | ||
4142 | |||
4143 | bucket++; | ||
4144 | state->pos = set_bucket_offset(bucket, 0); | ||
4145 | } while (bucket < NETDEV_HASHENTRIES); | ||
4146 | |||
4147 | return NULL; | ||
4148 | } | ||
4149 | |||
3985 | /* | 4150 | /* |
3986 | * This is invoked by the /proc filesystem handler to display a device | 4151 | * This is invoked by the /proc filesystem handler to display a device |
3987 | * in detail. | 4152 | * in detail. |
@@ -3989,33 +4154,33 @@ static int dev_ifconf(struct net *net, char __user *arg) | |||
3989 | void *dev_seq_start(struct seq_file *seq, loff_t *pos) | 4154 | void *dev_seq_start(struct seq_file *seq, loff_t *pos) |
3990 | __acquires(RCU) | 4155 | __acquires(RCU) |
3991 | { | 4156 | { |
3992 | struct net *net = seq_file_net(seq); | 4157 | struct dev_iter_state *state = seq->private; |
3993 | loff_t off; | ||
3994 | struct net_device *dev; | ||
3995 | 4158 | ||
3996 | rcu_read_lock(); | 4159 | rcu_read_lock(); |
3997 | if (!*pos) | 4160 | if (!*pos) |
3998 | return SEQ_START_TOKEN; | 4161 | return SEQ_START_TOKEN; |
3999 | 4162 | ||
4000 | off = 1; | 4163 | /* check for end of the hash */ |
4001 | for_each_netdev_rcu(net, dev) | 4164 | if (state->pos == 0 && *pos > 1) |
4002 | if (off++ == *pos) | 4165 | return NULL; |
4003 | return dev; | ||
4004 | 4166 | ||
4005 | return NULL; | 4167 | return dev_from_new_bucket(seq); |
4006 | } | 4168 | } |
4007 | 4169 | ||
4008 | void *dev_seq_next(struct seq_file *seq, void *v, loff_t *pos) | 4170 | void *dev_seq_next(struct seq_file *seq, void *v, loff_t *pos) |
4009 | { | 4171 | { |
4010 | struct net_device *dev = v; | 4172 | struct net_device *dev; |
4173 | |||
4174 | ++*pos; | ||
4011 | 4175 | ||
4012 | if (v == SEQ_START_TOKEN) | 4176 | if (v == SEQ_START_TOKEN) |
4013 | dev = first_net_device_rcu(seq_file_net(seq)); | 4177 | return dev_from_new_bucket(seq); |
4014 | else | ||
4015 | dev = next_net_device_rcu(dev); | ||
4016 | 4178 | ||
4017 | ++*pos; | 4179 | dev = dev_from_same_bucket(seq); |
4018 | return dev; | 4180 | if (dev) |
4181 | return dev; | ||
4182 | |||
4183 | return dev_from_new_bucket(seq); | ||
4019 | } | 4184 | } |
4020 | 4185 | ||
4021 | void dev_seq_stop(struct seq_file *seq, void *v) | 4186 | void dev_seq_stop(struct seq_file *seq, void *v) |
@@ -4114,7 +4279,7 @@ static const struct seq_operations dev_seq_ops = { | |||
4114 | static int dev_seq_open(struct inode *inode, struct file *file) | 4279 | static int dev_seq_open(struct inode *inode, struct file *file) |
4115 | { | 4280 | { |
4116 | return seq_open_net(inode, file, &dev_seq_ops, | 4281 | return seq_open_net(inode, file, &dev_seq_ops, |
4117 | sizeof(struct seq_net_private)); | 4282 | sizeof(struct dev_iter_state)); |
4118 | } | 4283 | } |
4119 | 4284 | ||
4120 | static const struct file_operations dev_seq_fops = { | 4285 | static const struct file_operations dev_seq_fops = { |
@@ -4497,9 +4662,7 @@ void __dev_set_rx_mode(struct net_device *dev) | |||
4497 | if (!netif_device_present(dev)) | 4662 | if (!netif_device_present(dev)) |
4498 | return; | 4663 | return; |
4499 | 4664 | ||
4500 | if (ops->ndo_set_rx_mode) | 4665 | if (!(dev->priv_flags & IFF_UNICAST_FLT)) { |
4501 | ops->ndo_set_rx_mode(dev); | ||
4502 | else { | ||
4503 | /* Unicast addresses changes may only happen under the rtnl, | 4666 | /* Unicast addresses changes may only happen under the rtnl, |
4504 | * therefore calling __dev_set_promiscuity here is safe. | 4667 | * therefore calling __dev_set_promiscuity here is safe. |
4505 | */ | 4668 | */ |
@@ -4510,10 +4673,10 @@ void __dev_set_rx_mode(struct net_device *dev) | |||
4510 | __dev_set_promiscuity(dev, -1); | 4673 | __dev_set_promiscuity(dev, -1); |
4511 | dev->uc_promisc = false; | 4674 | dev->uc_promisc = false; |
4512 | } | 4675 | } |
4513 | |||
4514 | if (ops->ndo_set_multicast_list) | ||
4515 | ops->ndo_set_multicast_list(dev); | ||
4516 | } | 4676 | } |
4677 | |||
4678 | if (ops->ndo_set_rx_mode) | ||
4679 | ops->ndo_set_rx_mode(dev); | ||
4517 | } | 4680 | } |
4518 | 4681 | ||
4519 | void dev_set_rx_mode(struct net_device *dev) | 4682 | void dev_set_rx_mode(struct net_device *dev) |
@@ -4524,30 +4687,6 @@ void dev_set_rx_mode(struct net_device *dev) | |||
4524 | } | 4687 | } |
4525 | 4688 | ||
4526 | /** | 4689 | /** |
4527 | * dev_ethtool_get_settings - call device's ethtool_ops::get_settings() | ||
4528 | * @dev: device | ||
4529 | * @cmd: memory area for ethtool_ops::get_settings() result | ||
4530 | * | ||
4531 | * The cmd arg is initialized properly (cleared and | ||
4532 | * ethtool_cmd::cmd field set to ETHTOOL_GSET). | ||
4533 | * | ||
4534 | * Return device's ethtool_ops::get_settings() result value or | ||
4535 | * -EOPNOTSUPP when device doesn't expose | ||
4536 | * ethtool_ops::get_settings() operation. | ||
4537 | */ | ||
4538 | int dev_ethtool_get_settings(struct net_device *dev, | ||
4539 | struct ethtool_cmd *cmd) | ||
4540 | { | ||
4541 | if (!dev->ethtool_ops || !dev->ethtool_ops->get_settings) | ||
4542 | return -EOPNOTSUPP; | ||
4543 | |||
4544 | memset(cmd, 0, sizeof(struct ethtool_cmd)); | ||
4545 | cmd->cmd = ETHTOOL_GSET; | ||
4546 | return dev->ethtool_ops->get_settings(dev, cmd); | ||
4547 | } | ||
4548 | EXPORT_SYMBOL(dev_ethtool_get_settings); | ||
4549 | |||
4550 | /** | ||
4551 | * dev_get_flags - get flags reported to userspace | 4690 | * dev_get_flags - get flags reported to userspace |
4552 | * @dev: device | 4691 | * @dev: device |
4553 | * | 4692 | * |
@@ -4863,7 +5002,7 @@ static int dev_ifsioc(struct net *net, struct ifreq *ifr, unsigned int cmd) | |||
4863 | return -EOPNOTSUPP; | 5002 | return -EOPNOTSUPP; |
4864 | 5003 | ||
4865 | case SIOCADDMULTI: | 5004 | case SIOCADDMULTI: |
4866 | if ((!ops->ndo_set_multicast_list && !ops->ndo_set_rx_mode) || | 5005 | if (!ops->ndo_set_rx_mode || |
4867 | ifr->ifr_hwaddr.sa_family != AF_UNSPEC) | 5006 | ifr->ifr_hwaddr.sa_family != AF_UNSPEC) |
4868 | return -EINVAL; | 5007 | return -EINVAL; |
4869 | if (!netif_device_present(dev)) | 5008 | if (!netif_device_present(dev)) |
@@ -4871,7 +5010,7 @@ static int dev_ifsioc(struct net *net, struct ifreq *ifr, unsigned int cmd) | |||
4871 | return dev_mc_add_global(dev, ifr->ifr_hwaddr.sa_data); | 5010 | return dev_mc_add_global(dev, ifr->ifr_hwaddr.sa_data); |
4872 | 5011 | ||
4873 | case SIOCDELMULTI: | 5012 | case SIOCDELMULTI: |
4874 | if ((!ops->ndo_set_multicast_list && !ops->ndo_set_rx_mode) || | 5013 | if (!ops->ndo_set_rx_mode || |
4875 | ifr->ifr_hwaddr.sa_family != AF_UNSPEC) | 5014 | ifr->ifr_hwaddr.sa_family != AF_UNSPEC) |
4876 | return -EINVAL; | 5015 | return -EINVAL; |
4877 | if (!netif_device_present(dev)) | 5016 | if (!netif_device_present(dev)) |
@@ -4888,6 +5027,12 @@ static int dev_ifsioc(struct net *net, struct ifreq *ifr, unsigned int cmd) | |||
4888 | ifr->ifr_newname[IFNAMSIZ-1] = '\0'; | 5027 | ifr->ifr_newname[IFNAMSIZ-1] = '\0'; |
4889 | return dev_change_name(dev, ifr->ifr_newname); | 5028 | return dev_change_name(dev, ifr->ifr_newname); |
4890 | 5029 | ||
5030 | case SIOCSHWTSTAMP: | ||
5031 | err = net_hwtstamp_validate(ifr); | ||
5032 | if (err) | ||
5033 | return err; | ||
5034 | /* fall through */ | ||
5035 | |||
4891 | /* | 5036 | /* |
4892 | * Unknown or private ioctl | 5037 | * Unknown or private ioctl |
4893 | */ | 5038 | */ |
@@ -5202,7 +5347,7 @@ static void rollback_registered_many(struct list_head *head) | |||
5202 | dev = list_first_entry(head, struct net_device, unreg_list); | 5347 | dev = list_first_entry(head, struct net_device, unreg_list); |
5203 | call_netdevice_notifiers(NETDEV_UNREGISTER_BATCH, dev); | 5348 | call_netdevice_notifiers(NETDEV_UNREGISTER_BATCH, dev); |
5204 | 5349 | ||
5205 | rcu_barrier(); | 5350 | synchronize_net(); |
5206 | 5351 | ||
5207 | list_for_each_entry(dev, head, unreg_list) | 5352 | list_for_each_entry(dev, head, unreg_list) |
5208 | dev_put(dev); | 5353 | dev_put(dev); |
@@ -5715,6 +5860,12 @@ void netdev_run_todo(void) | |||
5715 | 5860 | ||
5716 | __rtnl_unlock(); | 5861 | __rtnl_unlock(); |
5717 | 5862 | ||
5863 | /* Wait for rcu callbacks to finish before attempting to drain | ||
5864 | * the device list. This usually avoids a 250ms wait. | ||
5865 | */ | ||
5866 | if (!list_empty(&list)) | ||
5867 | rcu_barrier(); | ||
5868 | |||
5718 | while (!list_empty(&list)) { | 5869 | while (!list_empty(&list)) { |
5719 | struct net_device *dev | 5870 | struct net_device *dev |
5720 | = list_first_entry(&list, struct net_device, todo_list); | 5871 | = list_first_entry(&list, struct net_device, todo_list); |
@@ -5735,8 +5886,8 @@ void netdev_run_todo(void) | |||
5735 | 5886 | ||
5736 | /* paranoia */ | 5887 | /* paranoia */ |
5737 | BUG_ON(netdev_refcnt_read(dev)); | 5888 | BUG_ON(netdev_refcnt_read(dev)); |
5738 | WARN_ON(rcu_dereference_raw(dev->ip_ptr)); | 5889 | WARN_ON(rcu_access_pointer(dev->ip_ptr)); |
5739 | WARN_ON(rcu_dereference_raw(dev->ip6_ptr)); | 5890 | WARN_ON(rcu_access_pointer(dev->ip6_ptr)); |
5740 | WARN_ON(dev->dn_ptr); | 5891 | WARN_ON(dev->dn_ptr); |
5741 | 5892 | ||
5742 | if (dev->destructor) | 5893 | if (dev->destructor) |
@@ -5940,7 +6091,7 @@ void free_netdev(struct net_device *dev) | |||
5940 | kfree(dev->_rx); | 6091 | kfree(dev->_rx); |
5941 | #endif | 6092 | #endif |
5942 | 6093 | ||
5943 | kfree(rcu_dereference_raw(dev->ingress_queue)); | 6094 | kfree(rcu_dereference_protected(dev->ingress_queue, 1)); |
5944 | 6095 | ||
5945 | /* Flush device addresses */ | 6096 | /* Flush device addresses */ |
5946 | dev_addr_flush(dev); | 6097 | dev_addr_flush(dev); |
@@ -6115,6 +6266,7 @@ int dev_change_net_namespace(struct net_device *dev, struct net *net, const char | |||
6115 | */ | 6266 | */ |
6116 | call_netdevice_notifiers(NETDEV_UNREGISTER, dev); | 6267 | call_netdevice_notifiers(NETDEV_UNREGISTER, dev); |
6117 | call_netdevice_notifiers(NETDEV_UNREGISTER_BATCH, dev); | 6268 | call_netdevice_notifiers(NETDEV_UNREGISTER_BATCH, dev); |
6269 | rtmsg_ifinfo(RTM_DELLINK, dev, ~0U); | ||
6118 | 6270 | ||
6119 | /* | 6271 | /* |
6120 | * Flush the unicast and multicast chains | 6272 | * Flush the unicast and multicast chains |