Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7f9562a1 authored by Jiri Benc's avatar Jiri Benc Committed by David S. Miller
Browse files

ip_tunnels: record IP version in tunnel info



There's currently nothing preventing directing packets with IPv6
encapsulation data to IPv4 tunnels (and vice versa). If this happens,
IPv6 addresses are incorrectly interpreted as IPv4 ones.

Track whether the given ip_tunnel_key contains IPv4 or IPv6 data. Store this
in ip_tunnel_info. Reject packets at appropriate places if they are supposed
to be encapsulated into an incompatible protocol.

Signed-off-by: default avatarJiri Benc <jbenc@redhat.com>
Acked-by: default avatarAlexei Starovoitov <ast@plumgrid.com>
Acked-by: default avatarThomas Graf <tgraf@suug.ch>
Acked-by: default avatarPravin B Shelar <pshelar@nicira.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 46fa062a
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -627,6 +627,8 @@ static netdev_tx_t geneve_xmit(struct sk_buff *skb, struct net_device *dev)
			netdev_dbg(dev, "no tunnel metadata\n");
			goto tx_error;
		}
		if (info && ip_tunnel_info_af(info) != AF_INET)
			goto tx_error;
	}

	rt = geneve_get_rt(skb, dev, &fl4, info);
+2 −0
Original line number Diff line number Diff line
@@ -1903,6 +1903,8 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
				  dev->name);
			goto drop;
		}
		if (family != ip_tunnel_info_af(info))
			goto drop;

		dst_port = info->key.tp_dst ? : vxlan->cfg.dst_port;
		vni = be64_to_cpu(info->key.tun_id);
+1 −0
Original line number Diff line number Diff line
@@ -105,6 +105,7 @@ static inline struct metadata_dst *ipv6_tun_rx_dst(struct sk_buff *skb,
	info->key.u.ipv6.dst = ip6h->daddr;
	info->key.tos = ipv6_get_dsfield(ip6h);
	info->key.ttl = ip6h->hop_limit;
	info->mode = IP_TUNNEL_INFO_IPV6;
	return tun_dst;
}

+10 −0
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@
#include <linux/if_tunnel.h>
#include <linux/netdevice.h>
#include <linux/skbuff.h>
#include <linux/socket.h>
#include <linux/types.h>
#include <linux/u64_stats_sync.h>
#include <net/dsfield.h>
@@ -52,6 +53,7 @@ struct ip_tunnel_key {

/* Flags for ip_tunnel_info mode. */
#define IP_TUNNEL_INFO_TX	0x01	/* represents tx tunnel parameters */
#define IP_TUNNEL_INFO_IPV6	0x02	/* key contains IPv6 addresses */

struct ip_tunnel_info {
	struct ip_tunnel_key	key;
@@ -208,6 +210,8 @@ static inline void __ip_tunnel_info_init(struct ip_tunnel_info *tun_info,

	tun_info->options = opts;
	tun_info->options_len = opts_len;

	tun_info->mode = 0;
}

static inline void ip_tunnel_info_init(struct ip_tunnel_info *tun_info,
@@ -221,6 +225,12 @@ static inline void ip_tunnel_info_init(struct ip_tunnel_info *tun_info,
			      tun_id, tun_flags, opts, opts_len);
}

static inline unsigned short ip_tunnel_info_af(const struct ip_tunnel_info
					       *tun_info)
{
	return tun_info->mode & IP_TUNNEL_INFO_IPV6 ? AF_INET6 : AF_INET;
}

#ifdef CONFIG_INET

int ip_tunnel_init(struct net_device *dev);
+2 −0
Original line number Diff line number Diff line
@@ -1493,6 +1493,8 @@ static u64 bpf_skb_get_tunnel_key(u64 r1, u64 r2, u64 size, u64 flags, u64 r5)

	if (unlikely(size != sizeof(struct bpf_tunnel_key) || flags || !info))
		return -EINVAL;
	if (ip_tunnel_info_af(info) != AF_INET)
		return -EINVAL;

	to->tunnel_id = be64_to_cpu(info->key.tun_id);
	to->remote_ipv4 = be32_to_cpu(info->key.u.ipv4.src);
Loading