Bug 203533

Summary: VxLAN: Cannot create multiple vxlan devices for a given VNI and different source addresses.
Product: Networking Reporter: Hasan Naqvi (hasanrazaonline)
Component: IPV4Assignee: Stephen Hemminger (stephen)
Status: NEW ---    
Severity: normal CC: hasanrazaonline, kishorekunal02
Priority: P1    
Hardware: All   
OS: Linux   
Kernel Version: 4.9.110 Subsystem:
Regression: No Bisected commit-id:

Description Hasan Naqvi 2019-05-06 21:18:30 UTC
When trying to create two vxlan terminations with different source VTEPs, only one termination is allowed and second netdevice creation fails with EEXIST error.

root@:~# ip link add vxlan-10 type vxlan id 10 local 10.1.1.1 dstport 4789
root@:~# ip link add vxlan2-10 type vxlan id 10 local 20.1.1.1 dstport 4789
RTNETLINK answers: File exists
root@:~#

It is a valid use-case scenario where a router is terminating multiple VxLAN endpoints. But this doesn't seem to be allowed in the kernel.

The EEXIST error is coming from here:
vxlan_dev_configure():
...
    list_for_each_entry(tmp, &vn->vxlan_list, next) {
        if (tmp->cfg.vni == conf->vni &&
          | (tmp->default_dst.remote_ip.sa.sa_family == AF_INET6 ||
          |  tmp->cfg.saddr.sa.sa_family == AF_INET6) == use_ipv6 &&
          | tmp->cfg.dst_port == vxlan->cfg.dst_port &&
          | (tmp->flags & VXLAN_F_RCV_FLAGS) ==
          | (vxlan->flags & VXLAN_F_RCV_FLAGS)) {
            pr_info("duplicate VNI %u\n", be32_to_cpu(conf->vni));
            return -EEXIST;
        }
    }

The uniqueness of vxlan device should be checked with <local-endpoint, vni, dstport> instead of just <vni, dstport>. Similarly, vxlan_vs_find_vni() should lookup vxlan device using <src-addr, vni> instead of just <vni>:
static struct vxlan_dev *vxlan_vs_find_vni(struct vxlan_sock *vs, __be32 vni)

As per the code, I can see this issue exists in v5.1 as well.