1 #ifndef __NET_DST_METADATA_H
2 #define __NET_DST_METADATA_H 1
4 #include <linux/skbuff.h>
5 #include <net/ip_tunnels.h>
12 struct ip_tunnel_info tun_info;
16 static inline struct metadata_dst *skb_metadata_dst(struct sk_buff *skb)
18 struct metadata_dst *md_dst = (struct metadata_dst *) skb_dst(skb);
20 if (md_dst && md_dst->dst.flags & DST_METADATA)
26 static inline struct ip_tunnel_info *skb_tunnel_info(struct sk_buff *skb)
28 struct metadata_dst *md_dst = skb_metadata_dst(skb);
29 struct dst_entry *dst;
32 return &md_dst->u.tun_info;
35 if (dst && dst->lwtstate)
36 return lwt_tun_info(dst->lwtstate);
41 static inline bool skb_valid_dst(const struct sk_buff *skb)
43 struct dst_entry *dst = skb_dst(skb);
45 return dst && !(dst->flags & DST_METADATA);
48 struct metadata_dst *metadata_dst_alloc(u8 optslen, gfp_t flags);
49 struct metadata_dst __percpu *metadata_dst_alloc_percpu(u8 optslen, gfp_t flags);
51 static inline struct metadata_dst *tun_rx_dst(__be16 flags,
52 __be64 tunnel_id, int md_size)
54 struct metadata_dst *tun_dst;
55 struct ip_tunnel_info *info;
57 tun_dst = metadata_dst_alloc(md_size, GFP_ATOMIC);
61 info = &tun_dst->u.tun_info;
62 info->key.tun_flags = flags;
63 info->key.tun_id = tunnel_id;
69 static inline struct metadata_dst *ip_tun_rx_dst(struct sk_buff *skb,
74 const struct iphdr *iph = ip_hdr(skb);
75 struct metadata_dst *tun_dst;
76 struct ip_tunnel_info *info;
78 tun_dst = tun_rx_dst(flags, tunnel_id, md_size);
82 info = &tun_dst->u.tun_info;
83 info->key.u.ipv4.src = iph->saddr;
84 info->key.u.ipv4.dst = iph->daddr;
85 info->key.tos = iph->tos;
86 info->key.ttl = iph->ttl;
90 static inline struct metadata_dst *ipv6_tun_rx_dst(struct sk_buff *skb,
95 const struct ipv6hdr *ip6h = ipv6_hdr(skb);
96 struct metadata_dst *tun_dst;
97 struct ip_tunnel_info *info;
99 tun_dst = tun_rx_dst(flags, tunnel_id, md_size);
103 info = &tun_dst->u.tun_info;
104 info->key.u.ipv6.src = ip6h->saddr;
105 info->key.u.ipv6.dst = ip6h->daddr;
106 info->key.tos = ipv6_get_dsfield(ip6h);
107 info->key.ttl = ip6h->hop_limit;
108 info->mode = IP_TUNNEL_INFO_IPV6;
112 #endif /* __NET_DST_METADATA_H */