Merge tag 's390-5.0-2' of git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux
[platform/kernel/linux-rpi.git] / drivers / net / vxlan.c
index 0565f88..5209ee9 100644 (file)
@@ -79,9 +79,11 @@ struct vxlan_fdb {
        u8                eth_addr[ETH_ALEN];
        u16               state;        /* see ndm_state */
        __be32            vni;
-       u8                flags;        /* see ndm_flags */
+       u16               flags;        /* see ndm_flags and below */
 };
 
+#define NTF_VXLAN_ADDED_BY_USER 0x100
+
 /* salt for hash table */
 static u32 vxlan_salt __read_mostly;
 
@@ -186,7 +188,7 @@ static inline struct vxlan_rdst *first_remote_rtnl(struct vxlan_fdb *fdb)
  * and enabled unshareable flags.
  */
 static struct vxlan_sock *vxlan_find_sock(struct net *net, sa_family_t family,
-                                         __be16 port, u32 flags)
+                                         __be16 port, u32 flags, int ifindex)
 {
        struct vxlan_sock *vs;
 
@@ -195,7 +197,8 @@ static struct vxlan_sock *vxlan_find_sock(struct net *net, sa_family_t family,
        hlist_for_each_entry_rcu(vs, vs_head(net, port), hlist) {
                if (inet_sk(vs->sock->sk)->inet_sport == port &&
                    vxlan_get_sk_family(vs) == family &&
-                   vs->flags == flags)
+                   vs->flags == flags &&
+                   vs->sock->sk->sk_bound_dev_if == ifindex)
                        return vs;
        }
        return NULL;
@@ -235,7 +238,7 @@ static struct vxlan_dev *vxlan_find_vni(struct net *net, int ifindex,
 {
        struct vxlan_sock *vs;
 
-       vs = vxlan_find_sock(net, family, port, flags);
+       vs = vxlan_find_sock(net, family, port, flags, ifindex);
        if (!vs)
                return NULL;
 
@@ -355,6 +358,23 @@ errout:
                rtnl_set_sk_err(net, RTNLGRP_NEIGH, err);
 }
 
+static void vxlan_fdb_switchdev_notifier_info(const struct vxlan_dev *vxlan,
+                           const struct vxlan_fdb *fdb,
+                           const struct vxlan_rdst *rd,
+                           struct switchdev_notifier_vxlan_fdb_info *fdb_info)
+{
+       fdb_info->info.dev = vxlan->dev;
+       fdb_info->info.extack = NULL;
+       fdb_info->remote_ip = rd->remote_ip;
+       fdb_info->remote_port = rd->remote_port;
+       fdb_info->remote_vni = rd->remote_vni;
+       fdb_info->remote_ifindex = rd->remote_ifindex;
+       memcpy(fdb_info->eth_addr, fdb->eth_addr, ETH_ALEN);
+       fdb_info->vni = fdb->vni;
+       fdb_info->offloaded = rd->offloaded;
+       fdb_info->added_by_user = fdb->flags & NTF_VXLAN_ADDED_BY_USER;
+}
+
 static void vxlan_fdb_switchdev_call_notifiers(struct vxlan_dev *vxlan,
                                               struct vxlan_fdb *fdb,
                                               struct vxlan_rdst *rd,
@@ -368,31 +388,25 @@ static void vxlan_fdb_switchdev_call_notifiers(struct vxlan_dev *vxlan,
 
        notifier_type = adding ? SWITCHDEV_VXLAN_FDB_ADD_TO_DEVICE
                               : SWITCHDEV_VXLAN_FDB_DEL_TO_DEVICE;
-
-       info = (struct switchdev_notifier_vxlan_fdb_info){
-               .remote_ip = rd->remote_ip,
-               .remote_port = rd->remote_port,
-               .remote_vni = rd->remote_vni,
-               .remote_ifindex = rd->remote_ifindex,
-               .vni = fdb->vni,
-               .offloaded = rd->offloaded,
-       };
-       memcpy(info.eth_addr, fdb->eth_addr, ETH_ALEN);
-
+       vxlan_fdb_switchdev_notifier_info(vxlan, fdb, rd, &info);
        call_switchdev_notifiers(notifier_type, vxlan->dev,
                                 &info.info);
 }
 
 static void vxlan_fdb_notify(struct vxlan_dev *vxlan, struct vxlan_fdb *fdb,
-                            struct vxlan_rdst *rd, int type)
+                            struct vxlan_rdst *rd, int type, bool swdev_notify)
 {
-       switch (type) {
-       case RTM_NEWNEIGH:
-               vxlan_fdb_switchdev_call_notifiers(vxlan, fdb, rd, true);
-               break;
-       case RTM_DELNEIGH:
-               vxlan_fdb_switchdev_call_notifiers(vxlan, fdb, rd, false);
-               break;
+       if (swdev_notify) {
+               switch (type) {
+               case RTM_NEWNEIGH:
+                       vxlan_fdb_switchdev_call_notifiers(vxlan, fdb, rd,
+                                                          true);
+                       break;
+               case RTM_DELNEIGH:
+                       vxlan_fdb_switchdev_call_notifiers(vxlan, fdb, rd,
+                                                          false);
+                       break;
+               }
        }
 
        __vxlan_fdb_notify(vxlan, fdb, rd, type);
@@ -409,7 +423,7 @@ static void vxlan_ip_miss(struct net_device *dev, union vxlan_addr *ipa)
                .remote_vni = cpu_to_be32(VXLAN_N_VID),
        };
 
-       vxlan_fdb_notify(vxlan, &f, &remote, RTM_GETNEIGH);
+       vxlan_fdb_notify(vxlan, &f, &remote, RTM_GETNEIGH, true);
 }
 
 static void vxlan_fdb_miss(struct vxlan_dev *vxlan, const u8 eth_addr[ETH_ALEN])
@@ -421,7 +435,7 @@ static void vxlan_fdb_miss(struct vxlan_dev *vxlan, const u8 eth_addr[ETH_ALEN])
 
        memcpy(f.eth_addr, eth_addr, ETH_ALEN);
 
-       vxlan_fdb_notify(vxlan, &f, &remote, RTM_GETNEIGH);
+       vxlan_fdb_notify(vxlan, &f, &remote, RTM_GETNEIGH, true);
 }
 
 /* Hash Ethernet address */
@@ -531,16 +545,7 @@ int vxlan_fdb_find_uc(struct net_device *dev, const u8 *mac, __be32 vni,
        }
 
        rdst = first_remote_rcu(f);
-
-       memset(fdb_info, 0, sizeof(*fdb_info));
-       fdb_info->info.dev = dev;
-       fdb_info->remote_ip = rdst->remote_ip;
-       fdb_info->remote_port = rdst->remote_port;
-       fdb_info->remote_vni = rdst->remote_vni;
-       fdb_info->remote_ifindex = rdst->remote_ifindex;
-       fdb_info->vni = vni;
-       fdb_info->offloaded = rdst->offloaded;
-       ether_addr_copy(fdb_info->eth_addr, mac);
+       vxlan_fdb_switchdev_notifier_info(vxlan, f, rdst, fdb_info);
 
 out:
        rcu_read_unlock();
@@ -548,6 +553,75 @@ out:
 }
 EXPORT_SYMBOL_GPL(vxlan_fdb_find_uc);
 
+static int vxlan_fdb_notify_one(struct notifier_block *nb,
+                               const struct vxlan_dev *vxlan,
+                               const struct vxlan_fdb *f,
+                               const struct vxlan_rdst *rdst)
+{
+       struct switchdev_notifier_vxlan_fdb_info fdb_info;
+       int rc;
+
+       vxlan_fdb_switchdev_notifier_info(vxlan, f, rdst, &fdb_info);
+       rc = nb->notifier_call(nb, SWITCHDEV_VXLAN_FDB_ADD_TO_DEVICE,
+                              &fdb_info);
+       return notifier_to_errno(rc);
+}
+
+int vxlan_fdb_replay(const struct net_device *dev, __be32 vni,
+                    struct notifier_block *nb)
+{
+       struct vxlan_dev *vxlan;
+       struct vxlan_rdst *rdst;
+       struct vxlan_fdb *f;
+       unsigned int h;
+       int rc = 0;
+
+       if (!netif_is_vxlan(dev))
+               return -EINVAL;
+       vxlan = netdev_priv(dev);
+
+       spin_lock_bh(&vxlan->hash_lock);
+       for (h = 0; h < FDB_HASH_SIZE; ++h) {
+               hlist_for_each_entry(f, &vxlan->fdb_head[h], hlist) {
+                       if (f->vni == vni) {
+                               list_for_each_entry(rdst, &f->remotes, list) {
+                                       rc = vxlan_fdb_notify_one(nb, vxlan,
+                                                                 f, rdst);
+                                       if (rc)
+                                               goto out;
+                               }
+                       }
+               }
+       }
+
+out:
+       spin_unlock_bh(&vxlan->hash_lock);
+       return rc;
+}
+EXPORT_SYMBOL_GPL(vxlan_fdb_replay);
+
+void vxlan_fdb_clear_offload(const struct net_device *dev, __be32 vni)
+{
+       struct vxlan_dev *vxlan;
+       struct vxlan_rdst *rdst;
+       struct vxlan_fdb *f;
+       unsigned int h;
+
+       if (!netif_is_vxlan(dev))
+               return;
+       vxlan = netdev_priv(dev);
+
+       spin_lock_bh(&vxlan->hash_lock);
+       for (h = 0; h < FDB_HASH_SIZE; ++h) {
+               hlist_for_each_entry(f, &vxlan->fdb_head[h], hlist)
+                       if (f->vni == vni)
+                               list_for_each_entry(rdst, &f->remotes, list)
+                                       rdst->offloaded = false;
+       }
+       spin_unlock_bh(&vxlan->hash_lock);
+}
+EXPORT_SYMBOL_GPL(vxlan_fdb_clear_offload);
+
 /* Replace destination of unicast mac */
 static int vxlan_fdb_replace(struct vxlan_fdb *f,
                             union vxlan_addr *ip, __be16 port, __be32 vni,
@@ -701,7 +775,7 @@ static int vxlan_gro_complete(struct sock *sk, struct sk_buff *skb, int nhoff)
 
 static struct vxlan_fdb *vxlan_fdb_alloc(struct vxlan_dev *vxlan,
                                         const u8 *mac, __u16 state,
-                                        __be32 src_vni, __u8 ndm_flags)
+                                        __be32 src_vni, __u16 ndm_flags)
 {
        struct vxlan_fdb *f;
 
@@ -721,7 +795,7 @@ static struct vxlan_fdb *vxlan_fdb_alloc(struct vxlan_dev *vxlan,
 static int vxlan_fdb_create(struct vxlan_dev *vxlan,
                            const u8 *mac, union vxlan_addr *ip,
                            __u16 state, __be16 port, __be32 src_vni,
-                           __be32 vni, __u32 ifindex, __u8 ndm_flags,
+                           __be32 vni, __u32 ifindex, __u16 ndm_flags,
                            struct vxlan_fdb **fdb)
 {
        struct vxlan_rdst *rd = NULL;
@@ -757,9 +831,10 @@ static int vxlan_fdb_update(struct vxlan_dev *vxlan,
                            const u8 *mac, union vxlan_addr *ip,
                            __u16 state, __u16 flags,
                            __be16 port, __be32 src_vni, __be32 vni,
-                           __u32 ifindex, __u8 ndm_flags)
+                           __u32 ifindex, __u16 ndm_flags,
+                           bool swdev_notify)
 {
-       __u8 fdb_flags = (ndm_flags & ~NTF_USE);
+       __u16 fdb_flags = (ndm_flags & ~NTF_USE);
        struct vxlan_rdst *rd = NULL;
        struct vxlan_fdb *f;
        int notify = 0;
@@ -772,16 +847,24 @@ static int vxlan_fdb_update(struct vxlan_dev *vxlan,
                                   "lost race to create %pM\n", mac);
                        return -EEXIST;
                }
-               if (f->state != state) {
-                       f->state = state;
-                       f->updated = jiffies;
-                       notify = 1;
-               }
-               if (f->flags != fdb_flags) {
-                       f->flags = fdb_flags;
-                       f->updated = jiffies;
-                       notify = 1;
+
+               /* Do not allow an externally learned entry to take over an
+                * entry added by the user.
+                */
+               if (!(fdb_flags & NTF_EXT_LEARNED) ||
+                   !(f->flags & NTF_VXLAN_ADDED_BY_USER)) {
+                       if (f->state != state) {
+                               f->state = state;
+                               f->updated = jiffies;
+                               notify = 1;
+                       }
+                       if (f->flags != fdb_flags) {
+                               f->flags = fdb_flags;
+                               f->updated = jiffies;
+                               notify = 1;
+                       }
                }
+
                if ((flags & NLM_F_REPLACE)) {
                        /* Only change unicasts */
                        if (!(is_multicast_ether_addr(f->eth_addr) ||
@@ -823,7 +906,7 @@ static int vxlan_fdb_update(struct vxlan_dev *vxlan,
        if (notify) {
                if (rd == NULL)
                        rd = first_remote_rtnl(f);
-               vxlan_fdb_notify(vxlan, f, rd, RTM_NEWNEIGH);
+               vxlan_fdb_notify(vxlan, f, rd, RTM_NEWNEIGH, swdev_notify);
        }
 
        return 0;
@@ -842,7 +925,7 @@ static void vxlan_fdb_free(struct rcu_head *head)
 }
 
 static void vxlan_fdb_destroy(struct vxlan_dev *vxlan, struct vxlan_fdb *f,
-                             bool do_notify)
+                             bool do_notify, bool swdev_notify)
 {
        struct vxlan_rdst *rd;
 
@@ -852,7 +935,8 @@ static void vxlan_fdb_destroy(struct vxlan_dev *vxlan, struct vxlan_fdb *f,
        --vxlan->addrcnt;
        if (do_notify)
                list_for_each_entry(rd, &f->remotes, list)
-                       vxlan_fdb_notify(vxlan, f, rd, RTM_DELNEIGH);
+                       vxlan_fdb_notify(vxlan, f, rd, RTM_DELNEIGH,
+                                        swdev_notify);
 
        hlist_del_rcu(&f->hlist);
        call_rcu(&f->rcu, vxlan_fdb_free);
@@ -867,10 +951,10 @@ static void vxlan_dst_free(struct rcu_head *head)
 }
 
 static void vxlan_fdb_dst_destroy(struct vxlan_dev *vxlan, struct vxlan_fdb *f,
-                                 struct vxlan_rdst *rd)
+                                 struct vxlan_rdst *rd, bool swdev_notify)
 {
        list_del_rcu(&rd->list);
-       vxlan_fdb_notify(vxlan, f, rd, RTM_DELNEIGH);
+       vxlan_fdb_notify(vxlan, f, rd, RTM_DELNEIGH, swdev_notify);
        call_rcu(&rd->rcu, vxlan_dst_free);
 }
 
@@ -969,7 +1053,9 @@ static int vxlan_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
 
        spin_lock_bh(&vxlan->hash_lock);
        err = vxlan_fdb_update(vxlan, addr, &ip, ndm->ndm_state, flags,
-                              port, src_vni, vni, ifindex, ndm->ndm_flags);
+                              port, src_vni, vni, ifindex,
+                              ndm->ndm_flags | NTF_VXLAN_ADDED_BY_USER,
+                              true);
        spin_unlock_bh(&vxlan->hash_lock);
 
        return err;
@@ -978,7 +1064,7 @@ static int vxlan_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
 static int __vxlan_fdb_delete(struct vxlan_dev *vxlan,
                              const unsigned char *addr, union vxlan_addr ip,
                              __be16 port, __be32 src_vni, __be32 vni,
-                             u32 ifindex, u16 vid)
+                             u32 ifindex, bool swdev_notify)
 {
        struct vxlan_fdb *f;
        struct vxlan_rdst *rd = NULL;
@@ -998,11 +1084,11 @@ static int __vxlan_fdb_delete(struct vxlan_dev *vxlan,
         * otherwise destroy the fdb entry
         */
        if (rd && !list_is_singular(&f->remotes)) {
-               vxlan_fdb_dst_destroy(vxlan, f, rd);
+               vxlan_fdb_dst_destroy(vxlan, f, rd, swdev_notify);
                goto out;
        }
 
-       vxlan_fdb_destroy(vxlan, f, true);
+       vxlan_fdb_destroy(vxlan, f, true, swdev_notify);
 
 out:
        return 0;
@@ -1026,7 +1112,7 @@ static int vxlan_fdb_delete(struct ndmsg *ndm, struct nlattr *tb[],
 
        spin_lock_bh(&vxlan->hash_lock);
        err = __vxlan_fdb_delete(vxlan, addr, ip, port, src_vni, vni, ifindex,
-                                vid);
+                                true);
        spin_unlock_bh(&vxlan->hash_lock);
 
        return err;
@@ -1067,6 +1153,39 @@ out:
        return err;
 }
 
+static int vxlan_fdb_get(struct sk_buff *skb,
+                        struct nlattr *tb[],
+                        struct net_device *dev,
+                        const unsigned char *addr,
+                        u16 vid, u32 portid, u32 seq,
+                        struct netlink_ext_ack *extack)
+{
+       struct vxlan_dev *vxlan = netdev_priv(dev);
+       struct vxlan_fdb *f;
+       __be32 vni;
+       int err;
+
+       if (tb[NDA_VNI])
+               vni = cpu_to_be32(nla_get_u32(tb[NDA_VNI]));
+       else
+               vni = vxlan->default_dst.remote_vni;
+
+       rcu_read_lock();
+
+       f = __vxlan_find_mac(vxlan, addr, vni);
+       if (!f) {
+               NL_SET_ERR_MSG(extack, "Fdb entry not found");
+               err = -ENOENT;
+               goto errout;
+       }
+
+       err = vxlan_fdb_info(skb, vxlan, f, portid, seq,
+                            RTM_NEWNEIGH, 0, first_remote_rcu(f));
+errout:
+       rcu_read_unlock();
+       return err;
+}
+
 /* Watch incoming packets to learn mapping between Ethernet address
  * and Tunnel endpoint.
  * Return true if packet is bogus and should be dropped.
@@ -1104,7 +1223,7 @@ static bool vxlan_snoop(struct net_device *dev,
 
                rdst->remote_ip = *src_ip;
                f->updated = jiffies;
-               vxlan_fdb_notify(vxlan, f, rdst, RTM_NEWNEIGH);
+               vxlan_fdb_notify(vxlan, f, rdst, RTM_NEWNEIGH, true);
        } else {
                /* learned new entry */
                spin_lock(&vxlan->hash_lock);
@@ -1117,7 +1236,7 @@ static bool vxlan_snoop(struct net_device *dev,
                                         vxlan->cfg.dst_port,
                                         vni,
                                         vxlan->default_dst.remote_vni,
-                                        ifindex, NTF_SELF);
+                                        ifindex, NTF_SELF, true);
                spin_unlock(&vxlan->hash_lock);
        }
 
@@ -1553,6 +1672,34 @@ drop:
        return 0;
 }
 
+/* Callback from net/ipv{4,6}/udp.c to check that we have a VNI for errors */
+static int vxlan_err_lookup(struct sock *sk, struct sk_buff *skb)
+{
+       struct vxlan_dev *vxlan;
+       struct vxlan_sock *vs;
+       struct vxlanhdr *hdr;
+       __be32 vni;
+
+       if (skb->len < VXLAN_HLEN)
+               return -EINVAL;
+
+       hdr = vxlan_hdr(skb);
+
+       if (!(hdr->vx_flags & VXLAN_HF_VNI))
+               return -EINVAL;
+
+       vs = rcu_dereference_sk_user_data(sk);
+       if (!vs)
+               return -ENOENT;
+
+       vni = vxlan_vni(hdr->vx_vni);
+       vxlan = vxlan_vs_find_vni(vs, skb->dev->ifindex, vni);
+       if (!vxlan)
+               return -ENOENT;
+
+       return 0;
+}
+
 static int arp_reduce(struct net_device *dev, struct sk_buff *skb, __be32 vni)
 {
        struct vxlan_dev *vxlan = netdev_priv(dev);
@@ -2241,6 +2388,9 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
                struct rtable *rt;
                __be16 df = 0;
 
+               if (!ifindex)
+                       ifindex = sock4->sock->sk->sk_bound_dev_if;
+
                rt = vxlan_get_route(vxlan, dev, sock4, skb, ifindex, tos,
                                     dst->sin.sin_addr.s_addr,
                                     &local_ip.sin.sin_addr.s_addr,
@@ -2251,13 +2401,24 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
                        goto tx_error;
                }
 
-               /* Bypass encapsulation if the destination is local */
                if (!info) {
+                       /* Bypass encapsulation if the destination is local */
                        err = encap_bypass_if_local(skb, dev, vxlan, dst,
                                                    dst_port, ifindex, vni,
                                                    &rt->dst, rt->rt_flags);
                        if (err)
                                goto out_unlock;
+
+                       if (vxlan->cfg.df == VXLAN_DF_SET) {
+                               df = htons(IP_DF);
+                       } else if (vxlan->cfg.df == VXLAN_DF_INHERIT) {
+                               struct ethhdr *eth = eth_hdr(skb);
+
+                               if (ntohs(eth->h_proto) == ETH_P_IPV6 ||
+                                   (ntohs(eth->h_proto) == ETH_P_IP &&
+                                    old_iph->frag_off & htons(IP_DF)))
+                                       df = htons(IP_DF);
+                       }
                } else if (info->key.tun_flags & TUNNEL_DONT_FRAGMENT) {
                        df = htons(IP_DF);
                }
@@ -2279,6 +2440,9 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
        } else {
                struct vxlan_sock *sock6 = rcu_dereference(vxlan->vn6_sock);
 
+               if (!ifindex)
+                       ifindex = sock6->sock->sk->sk_bound_dev_if;
+
                ndst = vxlan6_get_route(vxlan, dev, sock6, skb, ifindex, tos,
                                        label, &dst->sin6.sin6_addr,
                                        &local_ip.sin6.sin6_addr,
@@ -2462,7 +2626,7 @@ static void vxlan_cleanup(struct timer_list *t)
                                           "garbage collect %pM\n",
                                           f->eth_addr);
                                f->state = NUD_STALE;
-                               vxlan_fdb_destroy(vxlan, f, true);
+                               vxlan_fdb_destroy(vxlan, f, true, true);
                        } else if (time_before(timeout, next_timer))
                                next_timer = timeout;
                }
@@ -2513,7 +2677,7 @@ static void vxlan_fdb_delete_default(struct vxlan_dev *vxlan, __be32 vni)
        spin_lock_bh(&vxlan->hash_lock);
        f = __vxlan_find_mac(vxlan, all_zeros_mac, vni);
        if (f)
-               vxlan_fdb_destroy(vxlan, f, true);
+               vxlan_fdb_destroy(vxlan, f, true, true);
        spin_unlock_bh(&vxlan->hash_lock);
 }
 
@@ -2567,7 +2731,7 @@ static void vxlan_flush(struct vxlan_dev *vxlan, bool do_all)
                                continue;
                        /* the all_zeros_mac entry is deleted at vxlan_uninit */
                        if (!is_zero_ether_addr(f->eth_addr))
-                               vxlan_fdb_destroy(vxlan, f, true);
+                               vxlan_fdb_destroy(vxlan, f, true, true);
                }
        }
        spin_unlock_bh(&vxlan->hash_lock);
@@ -2675,6 +2839,7 @@ static const struct net_device_ops vxlan_netdev_ether_ops = {
        .ndo_fdb_add            = vxlan_fdb_add,
        .ndo_fdb_del            = vxlan_fdb_delete,
        .ndo_fdb_dump           = vxlan_fdb_dump,
+       .ndo_fdb_get            = vxlan_fdb_get,
        .ndo_fill_metadata_dst  = vxlan_fill_metadata_dst,
 };
 
@@ -2810,6 +2975,7 @@ static const struct nla_policy vxlan_policy[IFLA_VXLAN_MAX + 1] = {
        [IFLA_VXLAN_GPE]        = { .type = NLA_FLAG, },
        [IFLA_VXLAN_REMCSUM_NOPARTIAL]  = { .type = NLA_FLAG },
        [IFLA_VXLAN_TTL_INHERIT]        = { .type = NLA_FLAG },
+       [IFLA_VXLAN_DF]         = { .type = NLA_U8 },
 };
 
 static int vxlan_validate(struct nlattr *tb[], struct nlattr *data[],
@@ -2866,6 +3032,16 @@ static int vxlan_validate(struct nlattr *tb[], struct nlattr *data[],
                }
        }
 
+       if (data[IFLA_VXLAN_DF]) {
+               enum ifla_vxlan_df df = nla_get_u8(data[IFLA_VXLAN_DF]);
+
+               if (df < 0 || df > VXLAN_DF_MAX) {
+                       NL_SET_ERR_MSG_ATTR(extack, tb[IFLA_VXLAN_DF],
+                                           "Invalid DF attribute");
+                       return -EINVAL;
+               }
+       }
+
        return 0;
 }
 
@@ -2882,7 +3058,7 @@ static const struct ethtool_ops vxlan_ethtool_ops = {
 };
 
 static struct socket *vxlan_create_sock(struct net *net, bool ipv6,
-                                       __be16 port, u32 flags)
+                                       __be16 port, u32 flags, int ifindex)
 {
        struct socket *sock;
        struct udp_port_cfg udp_conf;
@@ -2900,6 +3076,7 @@ static struct socket *vxlan_create_sock(struct net *net, bool ipv6,
        }
 
        udp_conf.local_udp_port = port;
+       udp_conf.bind_ifindex = ifindex;
 
        /* Open UDP socket */
        err = udp_sock_create(net, &udp_conf, &sock);
@@ -2911,7 +3088,8 @@ static struct socket *vxlan_create_sock(struct net *net, bool ipv6,
 
 /* Create new listen socket if needed */
 static struct vxlan_sock *vxlan_socket_create(struct net *net, bool ipv6,
-                                             __be16 port, u32 flags)
+                                             __be16 port, u32 flags,
+                                             int ifindex)
 {
        struct vxlan_net *vn = net_generic(net, vxlan_net_id);
        struct vxlan_sock *vs;
@@ -2926,7 +3104,7 @@ static struct vxlan_sock *vxlan_socket_create(struct net *net, bool ipv6,
        for (h = 0; h < VNI_HASH_SIZE; ++h)
                INIT_HLIST_HEAD(&vs->vni_list[h]);
 
-       sock = vxlan_create_sock(net, ipv6, port, flags);
+       sock = vxlan_create_sock(net, ipv6, port, flags, ifindex);
        if (IS_ERR(sock)) {
                kfree(vs);
                return ERR_CAST(sock);
@@ -2949,6 +3127,7 @@ static struct vxlan_sock *vxlan_socket_create(struct net *net, bool ipv6,
        tunnel_cfg.sk_user_data = vs;
        tunnel_cfg.encap_type = 1;
        tunnel_cfg.encap_rcv = vxlan_rcv;
+       tunnel_cfg.encap_err_lookup = vxlan_err_lookup;
        tunnel_cfg.encap_destroy = NULL;
        tunnel_cfg.gro_receive = vxlan_gro_receive;
        tunnel_cfg.gro_complete = vxlan_gro_complete;
@@ -2963,11 +3142,17 @@ static int __vxlan_sock_add(struct vxlan_dev *vxlan, bool ipv6)
        struct vxlan_net *vn = net_generic(vxlan->net, vxlan_net_id);
        struct vxlan_sock *vs = NULL;
        struct vxlan_dev_node *node;
+       int l3mdev_index = 0;
+
+       if (vxlan->cfg.remote_ifindex)
+               l3mdev_index = l3mdev_master_upper_ifindex_by_index(
+                       vxlan->net, vxlan->cfg.remote_ifindex);
 
        if (!vxlan->cfg.no_share) {
                spin_lock(&vn->sock_lock);
                vs = vxlan_find_sock(vxlan->net, ipv6 ? AF_INET6 : AF_INET,
-                                    vxlan->cfg.dst_port, vxlan->cfg.flags);
+                                    vxlan->cfg.dst_port, vxlan->cfg.flags,
+                                    l3mdev_index);
                if (vs && !refcount_inc_not_zero(&vs->refcnt)) {
                        spin_unlock(&vn->sock_lock);
                        return -EBUSY;
@@ -2976,7 +3161,8 @@ static int __vxlan_sock_add(struct vxlan_dev *vxlan, bool ipv6)
        }
        if (!vs)
                vs = vxlan_socket_create(vxlan->net, ipv6,
-                                        vxlan->cfg.dst_port, vxlan->cfg.flags);
+                                        vxlan->cfg.dst_port, vxlan->cfg.flags,
+                                        l3mdev_index);
        if (IS_ERR(vs))
                return PTR_ERR(vs);
 #if IS_ENABLED(CONFIG_IPV6)
@@ -3293,7 +3479,8 @@ static int __vxlan_dev_create(struct net *net, struct net_device *dev,
 
        /* notify default fdb entry */
        if (f)
-               vxlan_fdb_notify(vxlan, f, first_remote_rtnl(f), RTM_NEWNEIGH);
+               vxlan_fdb_notify(vxlan, f, first_remote_rtnl(f), RTM_NEWNEIGH,
+                                true);
 
        list_add(&vxlan->next, &vn->vxlan_list);
        return 0;
@@ -3304,7 +3491,7 @@ errout:
         * destroy the entry by hand here.
         */
        if (f)
-               vxlan_fdb_destroy(vxlan, f, false);
+               vxlan_fdb_destroy(vxlan, f, false, false);
        if (unregister)
                unregister_netdevice(dev);
        return err;
@@ -3394,11 +3581,8 @@ static int vxlan_nl2conf(struct nlattr *tb[], struct nlattr *data[],
                conf->flags |= VXLAN_F_LEARN;
        }
 
-       if (data[IFLA_VXLAN_AGEING]) {
-               if (changelink)
-                       return -EOPNOTSUPP;
+       if (data[IFLA_VXLAN_AGEING])
                conf->age_interval = nla_get_u32(data[IFLA_VXLAN_AGEING]);
-       }
 
        if (data[IFLA_VXLAN_PROXY]) {
                if (changelink)
@@ -3517,6 +3701,9 @@ static int vxlan_nl2conf(struct nlattr *tb[], struct nlattr *data[],
                conf->mtu = nla_get_u32(tb[IFLA_MTU]);
        }
 
+       if (data[IFLA_VXLAN_DF])
+               conf->df = nla_get_u8(data[IFLA_VXLAN_DF]);
+
        return 0;
 }
 
@@ -3540,6 +3727,7 @@ static int vxlan_changelink(struct net_device *dev, struct nlattr *tb[],
 {
        struct vxlan_dev *vxlan = netdev_priv(dev);
        struct vxlan_rdst *dst = &vxlan->default_dst;
+       unsigned long old_age_interval;
        struct vxlan_rdst old_dst;
        struct vxlan_config conf;
        int err;
@@ -3549,12 +3737,16 @@ static int vxlan_changelink(struct net_device *dev, struct nlattr *tb[],
        if (err)
                return err;
 
+       old_age_interval = vxlan->cfg.age_interval;
        memcpy(&old_dst, dst, sizeof(struct vxlan_rdst));
 
        err = vxlan_dev_configure(vxlan->net, dev, &conf, true, extack);
        if (err)
                return err;
 
+       if (old_age_interval != vxlan->cfg.age_interval)
+               mod_timer(&vxlan->age_timer, jiffies);
+
        /* handle default dst entry */
        if (!vxlan_addr_equal(&dst->remote_ip, &old_dst.remote_ip)) {
                spin_lock_bh(&vxlan->hash_lock);
@@ -3564,7 +3756,8 @@ static int vxlan_changelink(struct net_device *dev, struct nlattr *tb[],
                                           vxlan->cfg.dst_port,
                                           old_dst.remote_vni,
                                           old_dst.remote_vni,
-                                          old_dst.remote_ifindex, 0);
+                                          old_dst.remote_ifindex,
+                                          true);
 
                if (!vxlan_addr_any(&dst->remote_ip)) {
                        err = vxlan_fdb_update(vxlan, all_zeros_mac,
@@ -3575,7 +3768,7 @@ static int vxlan_changelink(struct net_device *dev, struct nlattr *tb[],
                                               dst->remote_vni,
                                               dst->remote_vni,
                                               dst->remote_ifindex,
-                                              NTF_SELF);
+                                              NTF_SELF, true);
                        if (err) {
                                spin_unlock_bh(&vxlan->hash_lock);
                                return err;
@@ -3608,6 +3801,7 @@ static size_t vxlan_get_size(const struct net_device *dev)
                nla_total_size(sizeof(__u8)) +  /* IFLA_VXLAN_TTL */
                nla_total_size(sizeof(__u8)) +  /* IFLA_VXLAN_TTL_INHERIT */
                nla_total_size(sizeof(__u8)) +  /* IFLA_VXLAN_TOS */
+               nla_total_size(sizeof(__u8)) +  /* IFLA_VXLAN_DF */
                nla_total_size(sizeof(__be32)) + /* IFLA_VXLAN_LABEL */
                nla_total_size(sizeof(__u8)) +  /* IFLA_VXLAN_LEARNING */
                nla_total_size(sizeof(__u8)) +  /* IFLA_VXLAN_PROXY */
@@ -3674,6 +3868,7 @@ static int vxlan_fill_info(struct sk_buff *skb, const struct net_device *dev)
            nla_put_u8(skb, IFLA_VXLAN_TTL_INHERIT,
                       !!(vxlan->cfg.flags & VXLAN_F_TTL_INHERIT)) ||
            nla_put_u8(skb, IFLA_VXLAN_TOS, vxlan->cfg.tos) ||
+           nla_put_u8(skb, IFLA_VXLAN_DF, vxlan->cfg.df) ||
            nla_put_be32(skb, IFLA_VXLAN_LABEL, vxlan->cfg.label) ||
            nla_put_u8(skb, IFLA_VXLAN_LEARNING,
                        !!(vxlan->cfg.flags & VXLAN_F_LEARN)) ||
@@ -3756,7 +3951,7 @@ struct net_device *vxlan_dev_create(struct net *net, const char *name,
        memset(&tb, 0, sizeof(tb));
 
        dev = rtnl_create_link(net, name, name_assign_type,
-                              &vxlan_link_ops, tb);
+                              &vxlan_link_ops, tb, NULL);
        if (IS_ERR(dev))
                return dev;
 
@@ -3851,18 +4046,89 @@ out:
        spin_unlock_bh(&vxlan->hash_lock);
 }
 
+static int
+vxlan_fdb_external_learn_add(struct net_device *dev,
+                            struct switchdev_notifier_vxlan_fdb_info *fdb_info)
+{
+       struct vxlan_dev *vxlan = netdev_priv(dev);
+       int err;
+
+       spin_lock_bh(&vxlan->hash_lock);
+       err = vxlan_fdb_update(vxlan, fdb_info->eth_addr, &fdb_info->remote_ip,
+                              NUD_REACHABLE,
+                              NLM_F_CREATE | NLM_F_REPLACE,
+                              fdb_info->remote_port,
+                              fdb_info->vni,
+                              fdb_info->remote_vni,
+                              fdb_info->remote_ifindex,
+                              NTF_USE | NTF_SELF | NTF_EXT_LEARNED,
+                              false);
+       spin_unlock_bh(&vxlan->hash_lock);
+
+       return err;
+}
+
+static int
+vxlan_fdb_external_learn_del(struct net_device *dev,
+                            struct switchdev_notifier_vxlan_fdb_info *fdb_info)
+{
+       struct vxlan_dev *vxlan = netdev_priv(dev);
+       struct vxlan_fdb *f;
+       int err = 0;
+
+       spin_lock_bh(&vxlan->hash_lock);
+
+       f = vxlan_find_mac(vxlan, fdb_info->eth_addr, fdb_info->vni);
+       if (!f)
+               err = -ENOENT;
+       else if (f->flags & NTF_EXT_LEARNED)
+               err = __vxlan_fdb_delete(vxlan, fdb_info->eth_addr,
+                                        fdb_info->remote_ip,
+                                        fdb_info->remote_port,
+                                        fdb_info->vni,
+                                        fdb_info->remote_vni,
+                                        fdb_info->remote_ifindex,
+                                        false);
+
+       spin_unlock_bh(&vxlan->hash_lock);
+
+       return err;
+}
+
 static int vxlan_switchdev_event(struct notifier_block *unused,
                                 unsigned long event, void *ptr)
 {
        struct net_device *dev = switchdev_notifier_info_to_dev(ptr);
+       struct switchdev_notifier_vxlan_fdb_info *fdb_info;
+       int err = 0;
 
        switch (event) {
        case SWITCHDEV_VXLAN_FDB_OFFLOADED:
                vxlan_fdb_offloaded_set(dev, ptr);
                break;
+       case SWITCHDEV_VXLAN_FDB_ADD_TO_BRIDGE:
+               fdb_info = ptr;
+               err = vxlan_fdb_external_learn_add(dev, fdb_info);
+               if (err) {
+                       err = notifier_from_errno(err);
+                       break;
+               }
+               fdb_info->offloaded = true;
+               vxlan_fdb_offloaded_set(dev, fdb_info);
+               break;
+       case SWITCHDEV_VXLAN_FDB_DEL_TO_BRIDGE:
+               fdb_info = ptr;
+               err = vxlan_fdb_external_learn_del(dev, fdb_info);
+               if (err) {
+                       err = notifier_from_errno(err);
+                       break;
+               }
+               fdb_info->offloaded = false;
+               vxlan_fdb_offloaded_set(dev, fdb_info);
+               break;
        }
 
-       return 0;
+       return err;
 }
 
 static struct notifier_block vxlan_switchdev_notifier_block __read_mostly = {