Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

vxlan: do not receive IPv4 packets on IPv6 socket

By default (subject to the sysctl settings), IPv6 sockets listen also for
IPv4 traffic. Vxlan is not prepared for that and expects IPv6 header in
packets received through an IPv6 socket.

In addition, it's currently not possible to have both IPv4 and IPv6 vxlan
tunnel on the same port (unless bindv6only sysctl is enabled), as it's not
possible to create and bind both IPv4 and IPv6 vxlan interfaces and there's
no way to specify both IPv4 and IPv6 remote/group IP addresses.

Set IPV6_V6ONLY on vxlan sockets to fix both of these issues. This is not
done globally in udp_tunnel, as l2tp and tipc seems to work okay when
receiving IPv4 packets on IPv6 socket and people may rely on this behavior.
The other tunnels (geneve and fou) do not support IPv6.

Signed-off-by: Jiri Benc <jbenc@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Jiri Benc and committed by
David S. Miller
a43a9ef6 b9b6695c

+12 -1
+1
drivers/net/vxlan.c
··· 2530 2530 udp_conf.family = AF_INET6; 2531 2531 udp_conf.use_udp6_rx_checksums = 2532 2532 !(flags & VXLAN_F_UDP_ZERO_CSUM6_RX); 2533 + udp_conf.ipv6_v6only = 1; 2533 2534 } else { 2534 2535 udp_conf.family = AF_INET; 2535 2536 }
+2 -1
include/net/udp_tunnel.h
··· 31 31 __be16 peer_udp_port; 32 32 unsigned int use_udp_checksums:1, 33 33 use_udp6_tx_checksums:1, 34 - use_udp6_rx_checksums:1; 34 + use_udp6_rx_checksums:1, 35 + ipv6_v6only:1; 35 36 }; 36 37 37 38 int udp_sock_create4(struct net *net, struct udp_port_cfg *cfg,
+9
net/ipv6/ip6_udp_tunnel.c
··· 23 23 if (err < 0) 24 24 goto error; 25 25 26 + if (cfg->ipv6_v6only) { 27 + int val = 1; 28 + 29 + err = kernel_setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, 30 + (char *) &val, sizeof(val)); 31 + if (err < 0) 32 + goto error; 33 + } 34 + 26 35 udp6_addr.sin6_family = AF_INET6; 27 36 memcpy(&udp6_addr.sin6_addr, &cfg->local_ip6, 28 37 sizeof(udp6_addr.sin6_addr));