diff options
| -rw-r--r-- | drivers/net/ipvlan/ipvlan.h | 4 | ||||
| -rw-r--r-- | drivers/net/ipvlan/ipvlan_core.c | 28 | ||||
| -rw-r--r-- | drivers/net/ipvlan/ipvlan_main.c | 30 |
3 files changed, 42 insertions, 20 deletions
diff --git a/drivers/net/ipvlan/ipvlan.h b/drivers/net/ipvlan/ipvlan.h index 924ea98bd531..54549a6223dd 100644 --- a/drivers/net/ipvlan/ipvlan.h +++ b/drivers/net/ipvlan/ipvlan.h | |||
| @@ -114,7 +114,9 @@ unsigned int ipvlan_mac_hash(const unsigned char *addr); | |||
| 114 | rx_handler_result_t ipvlan_handle_frame(struct sk_buff **pskb); | 114 | rx_handler_result_t ipvlan_handle_frame(struct sk_buff **pskb); |
| 115 | int ipvlan_queue_xmit(struct sk_buff *skb, struct net_device *dev); | 115 | int ipvlan_queue_xmit(struct sk_buff *skb, struct net_device *dev); |
| 116 | void ipvlan_ht_addr_add(struct ipvl_dev *ipvlan, struct ipvl_addr *addr); | 116 | void ipvlan_ht_addr_add(struct ipvl_dev *ipvlan, struct ipvl_addr *addr); |
| 117 | bool ipvlan_addr_busy(struct ipvl_dev *ipvlan, void *iaddr, bool is_v6); | 117 | struct ipvl_addr *ipvlan_find_addr(const struct ipvl_dev *ipvlan, |
| 118 | const void *iaddr, bool is_v6); | ||
| 119 | bool ipvlan_addr_busy(struct ipvl_port *port, void *iaddr, bool is_v6); | ||
| 118 | struct ipvl_addr *ipvlan_ht_addr_lookup(const struct ipvl_port *port, | 120 | struct ipvl_addr *ipvlan_ht_addr_lookup(const struct ipvl_port *port, |
| 119 | const void *iaddr, bool is_v6); | 121 | const void *iaddr, bool is_v6); |
| 120 | void ipvlan_ht_addr_del(struct ipvl_addr *addr, bool sync); | 122 | void ipvlan_ht_addr_del(struct ipvl_addr *addr, bool sync); |
diff --git a/drivers/net/ipvlan/ipvlan_core.c b/drivers/net/ipvlan/ipvlan_core.c index 2a175006028b..b7877a194cfe 100644 --- a/drivers/net/ipvlan/ipvlan_core.c +++ b/drivers/net/ipvlan/ipvlan_core.c | |||
| @@ -81,19 +81,20 @@ void ipvlan_ht_addr_add(struct ipvl_dev *ipvlan, struct ipvl_addr *addr) | |||
| 81 | hash = (addr->atype == IPVL_IPV6) ? | 81 | hash = (addr->atype == IPVL_IPV6) ? |
| 82 | ipvlan_get_v6_hash(&addr->ip6addr) : | 82 | ipvlan_get_v6_hash(&addr->ip6addr) : |
| 83 | ipvlan_get_v4_hash(&addr->ip4addr); | 83 | ipvlan_get_v4_hash(&addr->ip4addr); |
| 84 | hlist_add_head_rcu(&addr->hlnode, &port->hlhead[hash]); | 84 | if (hlist_unhashed(&addr->hlnode)) |
| 85 | hlist_add_head_rcu(&addr->hlnode, &port->hlhead[hash]); | ||
| 85 | } | 86 | } |
| 86 | 87 | ||
| 87 | void ipvlan_ht_addr_del(struct ipvl_addr *addr, bool sync) | 88 | void ipvlan_ht_addr_del(struct ipvl_addr *addr, bool sync) |
| 88 | { | 89 | { |
| 89 | hlist_del_rcu(&addr->hlnode); | 90 | hlist_del_init_rcu(&addr->hlnode); |
| 90 | if (sync) | 91 | if (sync) |
| 91 | synchronize_rcu(); | 92 | synchronize_rcu(); |
| 92 | } | 93 | } |
| 93 | 94 | ||
| 94 | bool ipvlan_addr_busy(struct ipvl_dev *ipvlan, void *iaddr, bool is_v6) | 95 | struct ipvl_addr *ipvlan_find_addr(const struct ipvl_dev *ipvlan, |
| 96 | const void *iaddr, bool is_v6) | ||
| 95 | { | 97 | { |
| 96 | struct ipvl_port *port = ipvlan->port; | ||
| 97 | struct ipvl_addr *addr; | 98 | struct ipvl_addr *addr; |
| 98 | 99 | ||
| 99 | list_for_each_entry(addr, &ipvlan->addrs, anode) { | 100 | list_for_each_entry(addr, &ipvlan->addrs, anode) { |
| @@ -101,12 +102,21 @@ bool ipvlan_addr_busy(struct ipvl_dev *ipvlan, void *iaddr, bool is_v6) | |||
| 101 | ipv6_addr_equal(&addr->ip6addr, iaddr)) || | 102 | ipv6_addr_equal(&addr->ip6addr, iaddr)) || |
| 102 | (!is_v6 && addr->atype == IPVL_IPV4 && | 103 | (!is_v6 && addr->atype == IPVL_IPV4 && |
| 103 | addr->ip4addr.s_addr == ((struct in_addr *)iaddr)->s_addr)) | 104 | addr->ip4addr.s_addr == ((struct in_addr *)iaddr)->s_addr)) |
| 104 | return true; | 105 | return addr; |
| 105 | } | 106 | } |
| 107 | return NULL; | ||
| 108 | } | ||
| 109 | |||
| 110 | bool ipvlan_addr_busy(struct ipvl_port *port, void *iaddr, bool is_v6) | ||
| 111 | { | ||
| 112 | struct ipvl_dev *ipvlan; | ||
| 106 | 113 | ||
| 107 | if (ipvlan_ht_addr_lookup(port, iaddr, is_v6)) | 114 | ASSERT_RTNL(); |
| 108 | return true; | ||
| 109 | 115 | ||
| 116 | list_for_each_entry(ipvlan, &port->ipvlans, pnode) { | ||
| 117 | if (ipvlan_find_addr(ipvlan, iaddr, is_v6)) | ||
| 118 | return true; | ||
| 119 | } | ||
| 110 | return false; | 120 | return false; |
| 111 | } | 121 | } |
| 112 | 122 | ||
| @@ -192,7 +202,8 @@ static void ipvlan_multicast_frame(struct ipvl_port *port, struct sk_buff *skb, | |||
| 192 | if (skb->protocol == htons(ETH_P_PAUSE)) | 202 | if (skb->protocol == htons(ETH_P_PAUSE)) |
| 193 | return; | 203 | return; |
| 194 | 204 | ||
| 195 | list_for_each_entry(ipvlan, &port->ipvlans, pnode) { | 205 | rcu_read_lock(); |
| 206 | list_for_each_entry_rcu(ipvlan, &port->ipvlans, pnode) { | ||
| 196 | if (local && (ipvlan == in_dev)) | 207 | if (local && (ipvlan == in_dev)) |
| 197 | continue; | 208 | continue; |
| 198 | 209 | ||
| @@ -219,6 +230,7 @@ static void ipvlan_multicast_frame(struct ipvl_port *port, struct sk_buff *skb, | |||
| 219 | mcast_acct: | 230 | mcast_acct: |
| 220 | ipvlan_count_rx(ipvlan, len, ret == NET_RX_SUCCESS, true); | 231 | ipvlan_count_rx(ipvlan, len, ret == NET_RX_SUCCESS, true); |
| 221 | } | 232 | } |
| 233 | rcu_read_unlock(); | ||
| 222 | 234 | ||
| 223 | /* Locally generated? ...Forward a copy to the main-device as | 235 | /* Locally generated? ...Forward a copy to the main-device as |
| 224 | * well. On the RX side we'll ignore it (wont give it to any | 236 | * well. On the RX side we'll ignore it (wont give it to any |
diff --git a/drivers/net/ipvlan/ipvlan_main.c b/drivers/net/ipvlan/ipvlan_main.c index 4f4099d5603d..4fa14208d799 100644 --- a/drivers/net/ipvlan/ipvlan_main.c +++ b/drivers/net/ipvlan/ipvlan_main.c | |||
| @@ -505,7 +505,7 @@ static void ipvlan_link_delete(struct net_device *dev, struct list_head *head) | |||
| 505 | if (ipvlan->ipv6cnt > 0 || ipvlan->ipv4cnt > 0) { | 505 | if (ipvlan->ipv6cnt > 0 || ipvlan->ipv4cnt > 0) { |
| 506 | list_for_each_entry_safe(addr, next, &ipvlan->addrs, anode) { | 506 | list_for_each_entry_safe(addr, next, &ipvlan->addrs, anode) { |
| 507 | ipvlan_ht_addr_del(addr, !dev->dismantle); | 507 | ipvlan_ht_addr_del(addr, !dev->dismantle); |
| 508 | list_del_rcu(&addr->anode); | 508 | list_del(&addr->anode); |
| 509 | } | 509 | } |
| 510 | } | 510 | } |
| 511 | list_del_rcu(&ipvlan->pnode); | 511 | list_del_rcu(&ipvlan->pnode); |
| @@ -607,7 +607,7 @@ static int ipvlan_add_addr6(struct ipvl_dev *ipvlan, struct in6_addr *ip6_addr) | |||
| 607 | { | 607 | { |
| 608 | struct ipvl_addr *addr; | 608 | struct ipvl_addr *addr; |
| 609 | 609 | ||
| 610 | if (ipvlan_addr_busy(ipvlan, ip6_addr, true)) { | 610 | if (ipvlan_addr_busy(ipvlan->port, ip6_addr, true)) { |
| 611 | netif_err(ipvlan, ifup, ipvlan->dev, | 611 | netif_err(ipvlan, ifup, ipvlan->dev, |
| 612 | "Failed to add IPv6=%pI6c addr for %s intf\n", | 612 | "Failed to add IPv6=%pI6c addr for %s intf\n", |
| 613 | ip6_addr, ipvlan->dev->name); | 613 | ip6_addr, ipvlan->dev->name); |
| @@ -620,9 +620,13 @@ static int ipvlan_add_addr6(struct ipvl_dev *ipvlan, struct in6_addr *ip6_addr) | |||
| 620 | addr->master = ipvlan; | 620 | addr->master = ipvlan; |
| 621 | memcpy(&addr->ip6addr, ip6_addr, sizeof(struct in6_addr)); | 621 | memcpy(&addr->ip6addr, ip6_addr, sizeof(struct in6_addr)); |
| 622 | addr->atype = IPVL_IPV6; | 622 | addr->atype = IPVL_IPV6; |
| 623 | list_add_tail_rcu(&addr->anode, &ipvlan->addrs); | 623 | list_add_tail(&addr->anode, &ipvlan->addrs); |
| 624 | ipvlan->ipv6cnt++; | 624 | ipvlan->ipv6cnt++; |
| 625 | ipvlan_ht_addr_add(ipvlan, addr); | 625 | /* If the interface is not up, the address will be added to the hash |
| 626 | * list by ipvlan_open. | ||
| 627 | */ | ||
| 628 | if (netif_running(ipvlan->dev)) | ||
| 629 | ipvlan_ht_addr_add(ipvlan, addr); | ||
| 626 | 630 | ||
| 627 | return 0; | 631 | return 0; |
| 628 | } | 632 | } |
| @@ -631,12 +635,12 @@ static void ipvlan_del_addr6(struct ipvl_dev *ipvlan, struct in6_addr *ip6_addr) | |||
| 631 | { | 635 | { |
| 632 | struct ipvl_addr *addr; | 636 | struct ipvl_addr *addr; |
| 633 | 637 | ||
| 634 | addr = ipvlan_ht_addr_lookup(ipvlan->port, ip6_addr, true); | 638 | addr = ipvlan_find_addr(ipvlan, ip6_addr, true); |
| 635 | if (!addr) | 639 | if (!addr) |
| 636 | return; | 640 | return; |
| 637 | 641 | ||
| 638 | ipvlan_ht_addr_del(addr, true); | 642 | ipvlan_ht_addr_del(addr, true); |
| 639 | list_del_rcu(&addr->anode); | 643 | list_del(&addr->anode); |
| 640 | ipvlan->ipv6cnt--; | 644 | ipvlan->ipv6cnt--; |
| 641 | WARN_ON(ipvlan->ipv6cnt < 0); | 645 | WARN_ON(ipvlan->ipv6cnt < 0); |
| 642 | kfree_rcu(addr, rcu); | 646 | kfree_rcu(addr, rcu); |
| @@ -675,7 +679,7 @@ static int ipvlan_add_addr4(struct ipvl_dev *ipvlan, struct in_addr *ip4_addr) | |||
| 675 | { | 679 | { |
| 676 | struct ipvl_addr *addr; | 680 | struct ipvl_addr *addr; |
| 677 | 681 | ||
| 678 | if (ipvlan_addr_busy(ipvlan, ip4_addr, false)) { | 682 | if (ipvlan_addr_busy(ipvlan->port, ip4_addr, false)) { |
| 679 | netif_err(ipvlan, ifup, ipvlan->dev, | 683 | netif_err(ipvlan, ifup, ipvlan->dev, |
| 680 | "Failed to add IPv4=%pI4 on %s intf.\n", | 684 | "Failed to add IPv4=%pI4 on %s intf.\n", |
| 681 | ip4_addr, ipvlan->dev->name); | 685 | ip4_addr, ipvlan->dev->name); |
| @@ -688,9 +692,13 @@ static int ipvlan_add_addr4(struct ipvl_dev *ipvlan, struct in_addr *ip4_addr) | |||
| 688 | addr->master = ipvlan; | 692 | addr->master = ipvlan; |
| 689 | memcpy(&addr->ip4addr, ip4_addr, sizeof(struct in_addr)); | 693 | memcpy(&addr->ip4addr, ip4_addr, sizeof(struct in_addr)); |
| 690 | addr->atype = IPVL_IPV4; | 694 | addr->atype = IPVL_IPV4; |
| 691 | list_add_tail_rcu(&addr->anode, &ipvlan->addrs); | 695 | list_add_tail(&addr->anode, &ipvlan->addrs); |
| 692 | ipvlan->ipv4cnt++; | 696 | ipvlan->ipv4cnt++; |
| 693 | ipvlan_ht_addr_add(ipvlan, addr); | 697 | /* If the interface is not up, the address will be added to the hash |
| 698 | * list by ipvlan_open. | ||
| 699 | */ | ||
| 700 | if (netif_running(ipvlan->dev)) | ||
| 701 | ipvlan_ht_addr_add(ipvlan, addr); | ||
| 694 | ipvlan_set_broadcast_mac_filter(ipvlan, true); | 702 | ipvlan_set_broadcast_mac_filter(ipvlan, true); |
| 695 | 703 | ||
| 696 | return 0; | 704 | return 0; |
| @@ -700,12 +708,12 @@ static void ipvlan_del_addr4(struct ipvl_dev *ipvlan, struct in_addr *ip4_addr) | |||
| 700 | { | 708 | { |
| 701 | struct ipvl_addr *addr; | 709 | struct ipvl_addr *addr; |
| 702 | 710 | ||
| 703 | addr = ipvlan_ht_addr_lookup(ipvlan->port, ip4_addr, false); | 711 | addr = ipvlan_find_addr(ipvlan, ip4_addr, false); |
| 704 | if (!addr) | 712 | if (!addr) |
| 705 | return; | 713 | return; |
| 706 | 714 | ||
| 707 | ipvlan_ht_addr_del(addr, true); | 715 | ipvlan_ht_addr_del(addr, true); |
| 708 | list_del_rcu(&addr->anode); | 716 | list_del(&addr->anode); |
| 709 | ipvlan->ipv4cnt--; | 717 | ipvlan->ipv4cnt--; |
| 710 | WARN_ON(ipvlan->ipv4cnt < 0); | 718 | WARN_ON(ipvlan->ipv4cnt < 0); |
| 711 | if (!ipvlan->ipv4cnt) | 719 | if (!ipvlan->ipv4cnt) |
