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->mode = IP_TUNNEL_INFO_RX;
63 info->key.tun_flags = flags;
64 info->key.tun_id = tunnel_id;
70 static inline struct metadata_dst *ip_tun_rx_dst(struct sk_buff *skb,
75 const struct iphdr *iph = ip_hdr(skb);
76 struct metadata_dst *tun_dst;
77 struct ip_tunnel_info *info;
79 tun_dst = tun_rx_dst(flags, tunnel_id, md_size);
83 info = &tun_dst->u.tun_info;
84 info->key.u.ipv4.src = iph->saddr;
85 info->key.u.ipv4.dst = iph->daddr;
86 info->key.tos = iph->tos;
87 info->key.ttl = iph->ttl;
91 static inline struct metadata_dst *ipv6_tun_rx_dst(struct sk_buff *skb,
96 const struct ipv6hdr *ip6h = ipv6_hdr(skb);
97 struct metadata_dst *tun_dst;
98 struct ip_tunnel_info *info;
100 tun_dst = tun_rx_dst(flags, tunnel_id, md_size);
104 info = &tun_dst->u.tun_info;
105 info->key.u.ipv6.src = ip6h->saddr;
106 info->key.u.ipv6.dst = ip6h->daddr;
107 info->key.tos = ipv6_get_dsfield(ip6h);
108 info->key.ttl = ip6h->hop_limit;
112 #endif /* __NET_DST_METADATA_H */