blob: 7b03068946634932ca0cf8b1b06fd9ef912b9e17 [file] [log] [blame]
Thomas Graff38a9eb2015-07-21 10:43:56 +02001#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
8struct metadata_dst {
9 struct dst_entry dst;
10 size_t opts_len;
Thomas Grafee122c72015-07-21 10:43:58 +020011 union {
12 struct ip_tunnel_info tun_info;
13 } u;
Thomas Graff38a9eb2015-07-21 10:43:56 +020014};
15
16static 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
Thomas Graf3093fbe2015-07-21 10:44:00 +020026static inline struct ip_tunnel_info *skb_tunnel_info(struct sk_buff *skb,
27 int family)
Thomas Grafee122c72015-07-21 10:43:58 +020028{
29 struct metadata_dst *md_dst = skb_metadata_dst(skb);
Thomas Graf3093fbe2015-07-21 10:44:00 +020030 struct rtable *rt;
Thomas Grafee122c72015-07-21 10:43:58 +020031
32 if (md_dst)
33 return &md_dst->u.tun_info;
34
Thomas Graf3093fbe2015-07-21 10:44:00 +020035 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
Thomas Grafee122c72015-07-21 10:43:58 +020043 return NULL;
44}
45
Thomas Graff38a9eb2015-07-21 10:43:56 +020046static 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
53struct metadata_dst *metadata_dst_alloc(u8 optslen, gfp_t flags);
54
55#endif /* __NET_DST_METADATA_H */