diff options
Diffstat (limited to 'drivers/net/vxlan.c')
-rw-r--r-- | drivers/net/vxlan.c | 41 |
1 files changed, 23 insertions, 18 deletions
diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c index ca309820d39e..be4649a49c5e 100644 --- a/drivers/net/vxlan.c +++ b/drivers/net/vxlan.c | |||
@@ -67,12 +67,6 @@ | |||
67 | 67 | ||
68 | #define VXLAN_FLAGS 0x08000000 /* struct vxlanhdr.vx_flags required value. */ | 68 | #define VXLAN_FLAGS 0x08000000 /* struct vxlanhdr.vx_flags required value. */ |
69 | 69 | ||
70 | /* VXLAN protocol header */ | ||
71 | struct vxlanhdr { | ||
72 | __be32 vx_flags; | ||
73 | __be32 vx_vni; | ||
74 | }; | ||
75 | |||
76 | /* UDP port for VXLAN traffic. | 70 | /* UDP port for VXLAN traffic. |
77 | * The IANA assigned port is 4789, but the Linux default is 8472 | 71 | * The IANA assigned port is 4789, but the Linux default is 8472 |
78 | * for compatibility with early adopters. | 72 | * for compatibility with early adopters. |
@@ -275,13 +269,15 @@ static inline struct vxlan_rdst *first_remote_rtnl(struct vxlan_fdb *fdb) | |||
275 | return list_first_entry(&fdb->remotes, struct vxlan_rdst, list); | 269 | return list_first_entry(&fdb->remotes, struct vxlan_rdst, list); |
276 | } | 270 | } |
277 | 271 | ||
278 | /* Find VXLAN socket based on network namespace and UDP port */ | 272 | /* Find VXLAN socket based on network namespace, address family and UDP port */ |
279 | static struct vxlan_sock *vxlan_find_sock(struct net *net, __be16 port) | 273 | static struct vxlan_sock *vxlan_find_sock(struct net *net, |
274 | sa_family_t family, __be16 port) | ||
280 | { | 275 | { |
281 | struct vxlan_sock *vs; | 276 | struct vxlan_sock *vs; |
282 | 277 | ||
283 | hlist_for_each_entry_rcu(vs, vs_head(net, port), hlist) { | 278 | hlist_for_each_entry_rcu(vs, vs_head(net, port), hlist) { |
284 | if (inet_sk(vs->sock->sk)->inet_sport == port) | 279 | if (inet_sk(vs->sock->sk)->inet_sport == port && |
280 | inet_sk(vs->sock->sk)->sk.sk_family == family) | ||
285 | return vs; | 281 | return vs; |
286 | } | 282 | } |
287 | return NULL; | 283 | return NULL; |
@@ -300,11 +296,12 @@ static struct vxlan_dev *vxlan_vs_find_vni(struct vxlan_sock *vs, u32 id) | |||
300 | } | 296 | } |
301 | 297 | ||
302 | /* Look up VNI in a per net namespace table */ | 298 | /* Look up VNI in a per net namespace table */ |
303 | static struct vxlan_dev *vxlan_find_vni(struct net *net, u32 id, __be16 port) | 299 | static struct vxlan_dev *vxlan_find_vni(struct net *net, u32 id, |
300 | sa_family_t family, __be16 port) | ||
304 | { | 301 | { |
305 | struct vxlan_sock *vs; | 302 | struct vxlan_sock *vs; |
306 | 303 | ||
307 | vs = vxlan_find_sock(net, port); | 304 | vs = vxlan_find_sock(net, family, port); |
308 | if (!vs) | 305 | if (!vs) |
309 | return NULL; | 306 | return NULL; |
310 | 307 | ||
@@ -621,6 +618,8 @@ static int vxlan_gro_complete(struct sk_buff *skb, int nhoff) | |||
621 | int vxlan_len = sizeof(struct vxlanhdr) + sizeof(struct ethhdr); | 618 | int vxlan_len = sizeof(struct vxlanhdr) + sizeof(struct ethhdr); |
622 | int err = -ENOSYS; | 619 | int err = -ENOSYS; |
623 | 620 | ||
621 | udp_tunnel_gro_complete(skb, nhoff); | ||
622 | |||
624 | eh = (struct ethhdr *)(skb->data + nhoff + sizeof(struct vxlanhdr)); | 623 | eh = (struct ethhdr *)(skb->data + nhoff + sizeof(struct vxlanhdr)); |
625 | type = eh->h_proto; | 624 | type = eh->h_proto; |
626 | 625 | ||
@@ -1771,7 +1770,8 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev, | |||
1771 | struct vxlan_dev *dst_vxlan; | 1770 | struct vxlan_dev *dst_vxlan; |
1772 | 1771 | ||
1773 | ip_rt_put(rt); | 1772 | ip_rt_put(rt); |
1774 | dst_vxlan = vxlan_find_vni(vxlan->net, vni, dst_port); | 1773 | dst_vxlan = vxlan_find_vni(vxlan->net, vni, |
1774 | dst->sa.sa_family, dst_port); | ||
1775 | if (!dst_vxlan) | 1775 | if (!dst_vxlan) |
1776 | goto tx_error; | 1776 | goto tx_error; |
1777 | vxlan_encap_bypass(skb, vxlan, dst_vxlan); | 1777 | vxlan_encap_bypass(skb, vxlan, dst_vxlan); |
@@ -1825,7 +1825,8 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev, | |||
1825 | struct vxlan_dev *dst_vxlan; | 1825 | struct vxlan_dev *dst_vxlan; |
1826 | 1826 | ||
1827 | dst_release(ndst); | 1827 | dst_release(ndst); |
1828 | dst_vxlan = vxlan_find_vni(vxlan->net, vni, dst_port); | 1828 | dst_vxlan = vxlan_find_vni(vxlan->net, vni, |
1829 | dst->sa.sa_family, dst_port); | ||
1829 | if (!dst_vxlan) | 1830 | if (!dst_vxlan) |
1830 | goto tx_error; | 1831 | goto tx_error; |
1831 | vxlan_encap_bypass(skb, vxlan, dst_vxlan); | 1832 | vxlan_encap_bypass(skb, vxlan, dst_vxlan); |
@@ -1985,13 +1986,15 @@ static int vxlan_init(struct net_device *dev) | |||
1985 | struct vxlan_dev *vxlan = netdev_priv(dev); | 1986 | struct vxlan_dev *vxlan = netdev_priv(dev); |
1986 | struct vxlan_net *vn = net_generic(vxlan->net, vxlan_net_id); | 1987 | struct vxlan_net *vn = net_generic(vxlan->net, vxlan_net_id); |
1987 | struct vxlan_sock *vs; | 1988 | struct vxlan_sock *vs; |
1989 | bool ipv6 = vxlan->flags & VXLAN_F_IPV6; | ||
1988 | 1990 | ||
1989 | dev->tstats = netdev_alloc_pcpu_stats(struct pcpu_sw_netstats); | 1991 | dev->tstats = netdev_alloc_pcpu_stats(struct pcpu_sw_netstats); |
1990 | if (!dev->tstats) | 1992 | if (!dev->tstats) |
1991 | return -ENOMEM; | 1993 | return -ENOMEM; |
1992 | 1994 | ||
1993 | spin_lock(&vn->sock_lock); | 1995 | spin_lock(&vn->sock_lock); |
1994 | vs = vxlan_find_sock(vxlan->net, vxlan->dst_port); | 1996 | vs = vxlan_find_sock(vxlan->net, ipv6 ? AF_INET6 : AF_INET, |
1997 | vxlan->dst_port); | ||
1995 | if (vs) { | 1998 | if (vs) { |
1996 | /* If we have a socket with same port already, reuse it */ | 1999 | /* If we have a socket with same port already, reuse it */ |
1997 | atomic_inc(&vs->refcnt); | 2000 | atomic_inc(&vs->refcnt); |
@@ -2303,9 +2306,9 @@ static struct socket *vxlan_create_sock(struct net *net, bool ipv6, | |||
2303 | if (ipv6) { | 2306 | if (ipv6) { |
2304 | udp_conf.family = AF_INET6; | 2307 | udp_conf.family = AF_INET6; |
2305 | udp_conf.use_udp6_tx_checksums = | 2308 | udp_conf.use_udp6_tx_checksums = |
2306 | !!(flags & VXLAN_F_UDP_ZERO_CSUM6_TX); | 2309 | !(flags & VXLAN_F_UDP_ZERO_CSUM6_TX); |
2307 | udp_conf.use_udp6_rx_checksums = | 2310 | udp_conf.use_udp6_rx_checksums = |
2308 | !!(flags & VXLAN_F_UDP_ZERO_CSUM6_RX); | 2311 | !(flags & VXLAN_F_UDP_ZERO_CSUM6_RX); |
2309 | } else { | 2312 | } else { |
2310 | udp_conf.family = AF_INET; | 2313 | udp_conf.family = AF_INET; |
2311 | udp_conf.local_ip.s_addr = INADDR_ANY; | 2314 | udp_conf.local_ip.s_addr = INADDR_ANY; |
@@ -2382,6 +2385,7 @@ struct vxlan_sock *vxlan_sock_add(struct net *net, __be16 port, | |||
2382 | { | 2385 | { |
2383 | struct vxlan_net *vn = net_generic(net, vxlan_net_id); | 2386 | struct vxlan_net *vn = net_generic(net, vxlan_net_id); |
2384 | struct vxlan_sock *vs; | 2387 | struct vxlan_sock *vs; |
2388 | bool ipv6 = flags & VXLAN_F_IPV6; | ||
2385 | 2389 | ||
2386 | vs = vxlan_socket_create(net, port, rcv, data, flags); | 2390 | vs = vxlan_socket_create(net, port, rcv, data, flags); |
2387 | if (!IS_ERR(vs)) | 2391 | if (!IS_ERR(vs)) |
@@ -2391,7 +2395,7 @@ struct vxlan_sock *vxlan_sock_add(struct net *net, __be16 port, | |||
2391 | return vs; | 2395 | return vs; |
2392 | 2396 | ||
2393 | spin_lock(&vn->sock_lock); | 2397 | spin_lock(&vn->sock_lock); |
2394 | vs = vxlan_find_sock(net, port); | 2398 | vs = vxlan_find_sock(net, ipv6 ? AF_INET6 : AF_INET, port); |
2395 | if (vs) { | 2399 | if (vs) { |
2396 | if (vs->rcv == rcv) | 2400 | if (vs->rcv == rcv) |
2397 | atomic_inc(&vs->refcnt); | 2401 | atomic_inc(&vs->refcnt); |
@@ -2550,7 +2554,8 @@ static int vxlan_newlink(struct net *net, struct net_device *dev, | |||
2550 | nla_get_u8(data[IFLA_VXLAN_UDP_ZERO_CSUM6_RX])) | 2554 | nla_get_u8(data[IFLA_VXLAN_UDP_ZERO_CSUM6_RX])) |
2551 | vxlan->flags |= VXLAN_F_UDP_ZERO_CSUM6_RX; | 2555 | vxlan->flags |= VXLAN_F_UDP_ZERO_CSUM6_RX; |
2552 | 2556 | ||
2553 | if (vxlan_find_vni(net, vni, vxlan->dst_port)) { | 2557 | if (vxlan_find_vni(net, vni, use_ipv6 ? AF_INET6 : AF_INET, |
2558 | vxlan->dst_port)) { | ||
2554 | pr_info("duplicate VNI %u\n", vni); | 2559 | pr_info("duplicate VNI %u\n", vni); |
2555 | return -EEXIST; | 2560 | return -EEXIST; |
2556 | } | 2561 | } |