Merge branch 'signal-for-v5.11' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux-2.6-microblaze.git] / drivers / net / vxlan.c
index b9fefe2..a8ad710 100644 (file)
@@ -66,6 +66,7 @@ struct vxlan_net {
        struct list_head  vxlan_list;
        struct hlist_head sock_list[PORT_HASH_SIZE];
        spinlock_t        sock_lock;
+       struct notifier_block nexthop_notifier_block;
 };
 
 /* Forwarding table entry */
@@ -190,8 +191,9 @@ static inline struct vxlan_rdst *first_remote_rtnl(struct vxlan_fdb *fdb)
        return list_first_entry(&fdb->remotes, struct vxlan_rdst, list);
 }
 
-/* Find VXLAN socket based on network namespace, address family and UDP port
- * and enabled unshareable flags.
+/* Find VXLAN socket based on network namespace, address family, UDP port,
+ * enabled unshareable flags and socket device binding (see l3mdev with
+ * non-default VRF).
  */
 static struct vxlan_sock *vxlan_find_sock(struct net *net, sa_family_t family,
                                          __be16 port, u32 flags, int ifindex)
@@ -1825,7 +1827,6 @@ static bool vxlan_ecn_decapsulate(struct vxlan_sock *vs, void *oiph,
 /* Callback from net/ipv4/udp.c to receive packets */
 static int vxlan_rcv(struct sock *sk, struct sk_buff *skb)
 {
-       struct pcpu_sw_netstats *stats;
        struct vxlan_dev *vxlan;
        struct vxlan_sock *vs;
        struct vxlanhdr unparsed;
@@ -1875,6 +1876,10 @@ static int vxlan_rcv(struct sock *sk, struct sk_buff *skb)
                                   !net_eq(vxlan->net, dev_net(vxlan->dev))))
                goto drop;
 
+       if (vs->flags & VXLAN_F_REMCSUM_RX)
+               if (unlikely(!vxlan_remcsum(&unparsed, skb, vs->flags)))
+                       goto drop;
+
        if (vxlan_collect_metadata(vs)) {
                struct metadata_dst *tun_dst;
 
@@ -1891,9 +1896,6 @@ static int vxlan_rcv(struct sock *sk, struct sk_buff *skb)
                memset(md, 0, sizeof(*md));
        }
 
-       if (vs->flags & VXLAN_F_REMCSUM_RX)
-               if (!vxlan_remcsum(&unparsed, skb, vs->flags))
-                       goto drop;
        if (vs->flags & VXLAN_F_GBP)
                vxlan_parse_gbp_hdr(&unparsed, skb, vs->flags, md);
        /* Note that GBP and GPE can never be active together. This is
@@ -1938,12 +1940,7 @@ static int vxlan_rcv(struct sock *sk, struct sk_buff *skb)
                goto drop;
        }
 
-       stats = this_cpu_ptr(vxlan->dev->tstats);
-       u64_stats_update_begin(&stats->syncp);
-       stats->rx_packets++;
-       stats->rx_bytes += skb->len;
-       u64_stats_update_end(&stats->syncp);
-
+       dev_sw_netstats_rx_add(vxlan->dev, skb->len);
        gro_cells_receive(&vxlan->gro_cells, skb);
 
        rcu_read_unlock();
@@ -2480,7 +2477,7 @@ static struct dst_entry *vxlan6_get_route(struct vxlan_dev *vxlan,
 
        ndst = ipv6_stub->ipv6_dst_lookup_flow(vxlan->net, sock6->sock->sk,
                                               &fl6, NULL);
-       if (unlikely(IS_ERR(ndst))) {
+       if (IS_ERR(ndst)) {
                netdev_dbg(dev, "no route to %pI6\n", daddr);
                return ERR_PTR(-ENETUNREACH);
        }
@@ -3214,7 +3211,7 @@ static const struct net_device_ops vxlan_netdev_ether_ops = {
        .ndo_open               = vxlan_open,
        .ndo_stop               = vxlan_stop,
        .ndo_start_xmit         = vxlan_xmit,
-       .ndo_get_stats64        = ip_tunnel_get_stats64,
+       .ndo_get_stats64        = dev_get_tstats64,
        .ndo_set_rx_mode        = vxlan_set_multicast_list,
        .ndo_change_mtu         = vxlan_change_mtu,
        .ndo_validate_addr      = eth_validate_addr,
@@ -3233,7 +3230,7 @@ static const struct net_device_ops vxlan_netdev_raw_ops = {
        .ndo_open               = vxlan_open,
        .ndo_stop               = vxlan_stop,
        .ndo_start_xmit         = vxlan_xmit,
-       .ndo_get_stats64        = ip_tunnel_get_stats64,
+       .ndo_get_stats64        = dev_get_tstats64,
        .ndo_change_mtu         = vxlan_change_mtu,
        .ndo_fill_metadata_dst  = vxlan_fill_metadata_dst,
 };
@@ -3802,6 +3799,9 @@ static void vxlan_config_apply(struct net_device *dev,
                dev->gso_max_segs = lowerdev->gso_max_segs;
 
                needed_headroom = lowerdev->hard_header_len;
+               needed_headroom += lowerdev->needed_headroom;
+
+               dev->needed_tailroom = lowerdev->needed_tailroom;
 
                max_mtu = lowerdev->mtu - (use_ipv6 ? VXLAN6_HEADROOM :
                                           VXLAN_HEADROOM);
@@ -3881,8 +3881,10 @@ static int __vxlan_dev_create(struct net *net, struct net_device *dev,
 
        if (dst->remote_ifindex) {
                remote_dev = __dev_get_by_index(net, dst->remote_ifindex);
-               if (!remote_dev)
+               if (!remote_dev) {
+                       err = -ENODEV;
                        goto errout;
+               }
 
                err = netdev_upper_dev_link(remote_dev, dev, extack);
                if (err)
@@ -3890,7 +3892,7 @@ static int __vxlan_dev_create(struct net *net, struct net_device *dev,
        }
 
        err = rtnl_configure_link(dev, NULL);
-       if (err)
+       if (err < 0)
                goto unlink;
 
        if (f) {
@@ -4687,9 +4689,14 @@ static void vxlan_fdb_nh_flush(struct nexthop *nh)
 static int vxlan_nexthop_event(struct notifier_block *nb,
                               unsigned long event, void *ptr)
 {
-       struct nexthop *nh = ptr;
+       struct nh_notifier_info *info = ptr;
+       struct nexthop *nh;
 
-       if (!nh || event != NEXTHOP_EVENT_DEL)
+       if (event != NEXTHOP_EVENT_DEL)
+               return NOTIFY_DONE;
+
+       nh = nexthop_find_by_id(info->net, info->id);
+       if (!nh)
                return NOTIFY_DONE;
 
        vxlan_fdb_nh_flush(nh);
@@ -4697,10 +4704,6 @@ static int vxlan_nexthop_event(struct notifier_block *nb,
        return NOTIFY_DONE;
 }
 
-static struct notifier_block vxlan_nexthop_notifier_block __read_mostly = {
-       .notifier_call = vxlan_nexthop_event,
-};
-
 static __net_init int vxlan_init_net(struct net *net)
 {
        struct vxlan_net *vn = net_generic(net, vxlan_net_id);
@@ -4708,11 +4711,13 @@ static __net_init int vxlan_init_net(struct net *net)
 
        INIT_LIST_HEAD(&vn->vxlan_list);
        spin_lock_init(&vn->sock_lock);
+       vn->nexthop_notifier_block.notifier_call = vxlan_nexthop_event;
 
        for (h = 0; h < PORT_HASH_SIZE; ++h)
                INIT_HLIST_HEAD(&vn->sock_list[h]);
 
-       return register_nexthop_notifier(net, &vxlan_nexthop_notifier_block);
+       return register_nexthop_notifier(net, &vn->nexthop_notifier_block,
+                                        NULL);
 }
 
 static void vxlan_destroy_tunnels(struct net *net, struct list_head *head)
@@ -4744,8 +4749,11 @@ static void __net_exit vxlan_exit_batch_net(struct list_head *net_list)
        LIST_HEAD(list);
 
        rtnl_lock();
-       list_for_each_entry(net, net_list, exit_list)
-               unregister_nexthop_notifier(net, &vxlan_nexthop_notifier_block);
+       list_for_each_entry(net, net_list, exit_list) {
+               struct vxlan_net *vn = net_generic(net, vxlan_net_id);
+
+               unregister_nexthop_notifier(net, &vn->nexthop_notifier_block);
+       }
        list_for_each_entry(net, net_list, exit_list)
                vxlan_destroy_tunnels(net, &list);