Thomas Graf | f38a9eb | 2015-07-21 10:43:56 +0200 | [diff] [blame] | 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; |
Thomas Graf | ee122c7 | 2015-07-21 10:43:58 +0200 | [diff] [blame] | 11 | union { |
| 12 | struct ip_tunnel_info tun_info; |
| 13 | } u; |
Thomas Graf | f38a9eb | 2015-07-21 10:43:56 +0200 | [diff] [blame] | 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 | |
Thomas Graf | 3093fbe | 2015-07-21 10:44:00 +0200 | [diff] [blame] | 26 | static inline struct ip_tunnel_info *skb_tunnel_info(struct sk_buff *skb, |
| 27 | int family) |
Thomas Graf | ee122c7 | 2015-07-21 10:43:58 +0200 | [diff] [blame] | 28 | { |
| 29 | struct metadata_dst *md_dst = skb_metadata_dst(skb); |
Thomas Graf | 3093fbe | 2015-07-21 10:44:00 +0200 | [diff] [blame] | 30 | struct rtable *rt; |
Thomas Graf | ee122c7 | 2015-07-21 10:43:58 +0200 | [diff] [blame] | 31 | |
| 32 | if (md_dst) |
| 33 | return &md_dst->u.tun_info; |
| 34 | |
Thomas Graf | 3093fbe | 2015-07-21 10:44:00 +0200 | [diff] [blame] | 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 | |
Thomas Graf | ee122c7 | 2015-07-21 10:43:58 +0200 | [diff] [blame] | 43 | return NULL; |
| 44 | } |
| 45 | |
Thomas Graf | f38a9eb | 2015-07-21 10:43:56 +0200 | [diff] [blame] | 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 | |
| 55 | #endif /* __NET_DST_METADATA_H */ |