We already have ip_tunnel_key_init, this does the same for IPv6. Will be
used also by openvswitch in the next patch.

Signed-off-by: Jiri Benc <jb...@redhat.com>
---
New patch in v2 of the set.
---
 include/net/dst_metadata.h | 18 ++++++------------
 include/net/ip_tunnels.h   | 40 +++++++++++++++++++++++++++++++---------
 2 files changed, 37 insertions(+), 21 deletions(-)

diff --git a/include/net/dst_metadata.h b/include/net/dst_metadata.h
index af9d5382f6cb..30e925aba1a4 100644
--- a/include/net/dst_metadata.h
+++ b/include/net/dst_metadata.h
@@ -85,23 +85,17 @@ static inline struct metadata_dst *ipv6_tun_rx_dst(struct 
sk_buff *skb,
 {
        const struct ipv6hdr *ip6h = ipv6_hdr(skb);
        struct metadata_dst *tun_dst;
-       struct ip_tunnel_info *info;
 
        tun_dst = tun_rx_dst(md_size);
        if (!tun_dst)
                return NULL;
 
-       info = &tun_dst->u.tun_info;
-       info->mode = IP_TUNNEL_INFO_IPV6;
-       info->key.tun_flags = flags;
-       info->key.tun_id = tunnel_id;
-       info->key.tp_src = 0;
-       info->key.tp_dst = 0;
-
-       info->key.u.ipv6.src = ip6h->saddr;
-       info->key.u.ipv6.dst = ip6h->daddr;
-       info->key.tos = ipv6_get_dsfield(ip6h);
-       info->key.ttl = ip6h->hop_limit;
+       tun_dst->u.tun_info.mode = IP_TUNNEL_INFO_IPV6;
+       ip6_tunnel_key_init(&tun_dst->u.tun_info.key,
+                           &ip6h->saddr, &ip6h->daddr,
+                           ipv6_get_dsfield(ip6h), ip6h->hop_limit,
+                           0, 0, tunnel_id, flags);
+
        return tun_dst;
 }
 
diff --git a/include/net/ip_tunnels.h b/include/net/ip_tunnels.h
index f6dafec9102c..087b2e24e5e0 100644
--- a/include/net/ip_tunnels.h
+++ b/include/net/ip_tunnels.h
@@ -179,17 +179,12 @@ int ip_tunnel_encap_add_ops(const struct 
ip_tunnel_encap_ops *op,
 int ip_tunnel_encap_del_ops(const struct ip_tunnel_encap_ops *op,
                            unsigned int num);
 
-static inline void ip_tunnel_key_init(struct ip_tunnel_key *key,
-                                     __be32 saddr, __be32 daddr,
-                                     u8 tos, u8 ttl,
-                                     __be16 tp_src, __be16 tp_dst,
-                                     __be64 tun_id, __be16 tun_flags)
+static inline void __ip_tunnel_key_init(struct ip_tunnel_key *key,
+                                       u8 tos, u8 ttl,
+                                       __be16 tp_src, __be16 tp_dst,
+                                       __be64 tun_id, __be16 tun_flags)
 {
        key->tun_id = tun_id;
-       key->u.ipv4.src = saddr;
-       key->u.ipv4.dst = daddr;
-       memset((unsigned char *)key + IP_TUNNEL_KEY_IPV4_PAD,
-              0, IP_TUNNEL_KEY_IPV4_PAD_LEN);
        key->tos = tos;
        key->ttl = ttl;
        key->tun_flags = tun_flags;
@@ -207,6 +202,33 @@ static inline void ip_tunnel_key_init(struct ip_tunnel_key 
*key,
                       0, sizeof(*key) - IP_TUNNEL_KEY_SIZE);
 }
 
+static inline void ip_tunnel_key_init(struct ip_tunnel_key *key,
+                                     __be32 saddr, __be32 daddr,
+                                     u8 tos, u8 ttl,
+                                     __be16 tp_src, __be16 tp_dst,
+                                     __be64 tun_id, __be16 tun_flags)
+{
+       __ip_tunnel_key_init(key, tos, ttl, tp_src, tp_dst, tun_id,
+                            tun_flags);
+       key->u.ipv4.src = saddr;
+       key->u.ipv4.dst = daddr;
+       memset((unsigned char *)key + IP_TUNNEL_KEY_IPV4_PAD,
+              0, IP_TUNNEL_KEY_IPV4_PAD_LEN);
+}
+
+static inline void ip6_tunnel_key_init(struct ip_tunnel_key *key,
+                                      const struct in6_addr *saddr,
+                                      const struct in6_addr *daddr,
+                                      u8 tos, u8 ttl,
+                                      __be16 tp_src, __be16 tp_dst,
+                                      __be64 tun_id, __be16 tun_flags)
+{
+       __ip_tunnel_key_init(key, tos, ttl, tp_src, tp_dst, tun_id,
+                            tun_flags);
+       key->u.ipv6.src = *saddr;
+       key->u.ipv6.dst = *daddr;
+}
+
 static inline unsigned short ip_tunnel_info_af(const struct ip_tunnel_info
                                               *tun_info)
 {
-- 
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to