ip_tunnels: add IPv6 addresses to ip_tunnel_key
authorJiri Benc <jbenc@redhat.com>
Thu, 20 Aug 2015 11:56:23 +0000 (13:56 +0200)
committerDavid S. Miller <davem@davemloft.net>
Thu, 20 Aug 2015 22:42:36 +0000 (15:42 -0700)
Add the IPv6 addresses as an union with IPv4 ones. When using IPv4, the
newly introduced padding after the IPv4 addresses needs to be zeroed out.

Signed-off-by: Jiri Benc <jbenc@redhat.com>
Acked-by: Thomas Graf <tgraf@suug.ch>
Acked-by: Alexei Starovoitov <ast@plumgrid.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/vxlan.c
include/net/ip_tunnels.h
net/core/filter.c
net/ipv4/ip_gre.c
net/ipv4/ip_tunnel_core.c
net/openvswitch/flow_netlink.c
net/openvswitch/flow_table.c
net/openvswitch/vport-geneve.c
net/openvswitch/vport.c
net/openvswitch/vport.h

index ad51dac..30a7abc 100644 (file)
@@ -1276,8 +1276,8 @@ static int vxlan_udp_encap_recv(struct sock *sk, struct sk_buff *skb)
                        goto drop;
 
                info = &tun_dst->u.tun_info;
-               info->key.ipv4_src = iph->saddr;
-               info->key.ipv4_dst = iph->daddr;
+               info->key.u.ipv4.src = iph->saddr;
+               info->key.u.ipv4.dst = iph->daddr;
                info->key.ipv4_tos = iph->tos;
                info->key.ipv4_ttl = iph->ttl;
                info->key.tp_src = udp_hdr(skb)->source;
@@ -1925,7 +1925,7 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
                dst_port = info->key.tp_dst ? : vxlan->cfg.dst_port;
                vni = be64_to_cpu(info->key.tun_id);
                remote_ip.sin.sin_family = AF_INET;
-               remote_ip.sin.sin_addr.s_addr = info->key.ipv4_dst;
+               remote_ip.sin.sin_addr.s_addr = info->key.u.ipv4.dst;
                dst = &remote_ip;
        }
 
index cc3b39e..6a51371 100644 (file)
 /* Used to memset ip_tunnel padding. */
 #define IP_TUNNEL_KEY_SIZE     offsetofend(struct ip_tunnel_key, tp_dst)
 
+/* Used to memset ipv4 address padding. */
+#define IP_TUNNEL_KEY_IPV4_PAD offsetofend(struct ip_tunnel_key, u.ipv4.dst)
+#define IP_TUNNEL_KEY_IPV4_PAD_LEN                             \
+       (FIELD_SIZEOF(struct ip_tunnel_key, u) -                \
+        FIELD_SIZEOF(struct ip_tunnel_key, u.ipv4))
+
 struct ip_tunnel_key {
        __be64                  tun_id;
-       __be32                  ipv4_src;
-       __be32                  ipv4_dst;
+       union {
+               struct {
+                       __be32  src;
+                       __be32  dst;
+               } ipv4;
+               struct {
+                       struct in6_addr src;
+                       struct in6_addr dst;
+               } ipv6;
+       } u;
        __be16                  tun_flags;
        u8                      ipv4_tos;
        u8                      ipv4_ttl;
@@ -177,8 +191,10 @@ static inline void __ip_tunnel_info_init(struct ip_tunnel_info *tun_info,
                                         const void *opts, u8 opts_len)
 {
        tun_info->key.tun_id = tun_id;
-       tun_info->key.ipv4_src = saddr;
-       tun_info->key.ipv4_dst = daddr;
+       tun_info->key.u.ipv4.src = saddr;
+       tun_info->key.u.ipv4.dst = daddr;
+       memset((unsigned char *)&tun_info->key + IP_TUNNEL_KEY_IPV4_PAD,
+              0, IP_TUNNEL_KEY_IPV4_PAD_LEN);
        tun_info->key.ipv4_tos = tos;
        tun_info->key.ipv4_ttl = ttl;
        tun_info->key.tun_flags = tun_flags;
index 83f08ce..3795685 100644 (file)
@@ -1495,7 +1495,7 @@ static u64 bpf_skb_get_tunnel_key(u64 r1, u64 r2, u64 size, u64 flags, u64 r5)
                return -EINVAL;
 
        to->tunnel_id = be64_to_cpu(info->key.tun_id);
-       to->remote_ipv4 = be32_to_cpu(info->key.ipv4_src);
+       to->remote_ipv4 = be32_to_cpu(info->key.u.ipv4.src);
 
        return 0;
 }
@@ -1529,7 +1529,7 @@ static u64 bpf_skb_set_tunnel_key(u64 r1, u64 r2, u64 size, u64 flags, u64 r5)
        info = &md->u.tun_info;
        info->mode = IP_TUNNEL_INFO_TX;
        info->key.tun_id = cpu_to_be64(from->tunnel_id);
-       info->key.ipv4_dst = cpu_to_be32(from->remote_ipv4);
+       info->key.u.ipv4.dst = cpu_to_be32(from->remote_ipv4);
 
        return 0;
 }
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge