]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - include/net/dst_metadata.h
Merge branch 'fixes' of git://ftp.arm.linux.org.uk/~rmk/linux-arm
[karo-tx-linux.git] / include / net / dst_metadata.h
index 2cb52d562272aa395be9186f676c4dbcaf3c1462..af9d5382f6cbae8c38d45106f5702bd1e66c5671 100644 (file)
@@ -7,7 +7,6 @@
 
 struct metadata_dst {
        struct dst_entry                dst;
-       size_t                          opts_len;
        union {
                struct ip_tunnel_info   tun_info;
        } u;
@@ -48,4 +47,62 @@ static inline bool skb_valid_dst(const struct sk_buff *skb)
 struct metadata_dst *metadata_dst_alloc(u8 optslen, gfp_t flags);
 struct metadata_dst __percpu *metadata_dst_alloc_percpu(u8 optslen, gfp_t flags);
 
+static inline struct metadata_dst *tun_rx_dst(int md_size)
+{
+       struct metadata_dst *tun_dst;
+
+       tun_dst = metadata_dst_alloc(md_size, GFP_ATOMIC);
+       if (!tun_dst)
+               return NULL;
+
+       tun_dst->u.tun_info.options_len = 0;
+       tun_dst->u.tun_info.mode = 0;
+       return tun_dst;
+}
+
+static inline struct metadata_dst *ip_tun_rx_dst(struct sk_buff *skb,
+                                                __be16 flags,
+                                                __be64 tunnel_id,
+                                                int md_size)
+{
+       const struct iphdr *iph = ip_hdr(skb);
+       struct metadata_dst *tun_dst;
+
+       tun_dst = tun_rx_dst(md_size);
+       if (!tun_dst)
+               return NULL;
+
+       ip_tunnel_key_init(&tun_dst->u.tun_info.key,
+                          iph->saddr, iph->daddr, iph->tos, iph->ttl,
+                          0, 0, tunnel_id, flags);
+       return tun_dst;
+}
+
+static inline struct metadata_dst *ipv6_tun_rx_dst(struct sk_buff *skb,
+                                                __be16 flags,
+                                                __be64 tunnel_id,
+                                                int md_size)
+{
+       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;
+       return tun_dst;
+}
+
 #endif /* __NET_DST_METADATA_H */