xref: /openbmc/linux/include/net/dst_metadata.h (revision bbde9fc1824aab58bc78c084163007dd6c03fe5b)
1 #ifndef __NET_DST_METADATA_H
2 #define __NET_DST_METADATA_H 1
3 
4 #include <linux/skbuff.h>
5 #include <net/ip_tunnels.h>
6 #include <net/dst.h>
7 
8 struct metadata_dst {
9 	struct dst_entry		dst;
10 	size_t				opts_len;
11 	union {
12 		struct ip_tunnel_info	tun_info;
13 	} u;
14 };
15 
16 static inline struct metadata_dst *skb_metadata_dst(struct sk_buff *skb)
17 {
18 	struct metadata_dst *md_dst = (struct metadata_dst *) skb_dst(skb);
19 
20 	if (md_dst && md_dst->dst.flags & DST_METADATA)
21 		return md_dst;
22 
23 	return NULL;
24 }
25 
26 static inline struct ip_tunnel_info *skb_tunnel_info(struct sk_buff *skb,
27 						     int family)
28 {
29 	struct metadata_dst *md_dst = skb_metadata_dst(skb);
30 	struct rtable *rt;
31 
32 	if (md_dst)
33 		return &md_dst->u.tun_info;
34 
35 	switch (family) {
36 	case AF_INET:
37 		rt = (struct rtable *)skb_dst(skb);
38 		if (rt && rt->rt_lwtstate)
39 			return lwt_tun_info(rt->rt_lwtstate);
40 		break;
41 	}
42 
43 	return NULL;
44 }
45 
46 static inline bool skb_valid_dst(const struct sk_buff *skb)
47 {
48 	struct dst_entry *dst = skb_dst(skb);
49 
50 	return dst && !(dst->flags & DST_METADATA);
51 }
52 
53 struct metadata_dst *metadata_dst_alloc(u8 optslen, gfp_t flags);
54 struct metadata_dst __percpu *metadata_dst_alloc_percpu(u8 optslen, gfp_t flags);
55 
56 #endif /* __NET_DST_METADATA_H */
57