summaryrefslogtreecommitdiffstats
path: root/include/net/lwtunnel.h
diff options
context:
space:
mode:
authorRoopa Prabhu <roopa@cumulusnetworks.com>2015-07-21 04:43:46 -0400
committerDavid S. Miller <davem@davemloft.net>2015-07-21 13:39:03 -0400
commit499a24256862714539e902c0499b67da2bb3ab72 (patch)
treeed502c5671b9c4806080731be8d3b5e5ff09f02c /include/net/lwtunnel.h
parenta0d9a8604f29ee3340126ec3f90c9421f930aa50 (diff)
lwtunnel: infrastructure for handling light weight tunnels like mpls
Provides infrastructure to parse/dump/store encap information for light weight tunnels like mpls. Encap information for such tunnels is associated with fib routes. This infrastructure is based on previous suggestions from Eric Biederman to follow the xfrm infrastructure. Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include/net/lwtunnel.h')
-rw-r--r--include/net/lwtunnel.h132
1 files changed, 132 insertions, 0 deletions
diff --git a/include/net/lwtunnel.h b/include/net/lwtunnel.h
new file mode 100644
index 000000000000..df24b3611ff4
--- /dev/null
+++ b/include/net/lwtunnel.h
@@ -0,0 +1,132 @@
1#ifndef __NET_LWTUNNEL_H
2#define __NET_LWTUNNEL_H 1
3
4#include <linux/lwtunnel.h>
5#include <linux/netdevice.h>
6#include <linux/skbuff.h>
7#include <linux/types.h>
8#include <net/route.h>
9
10#define LWTUNNEL_HASH_BITS 7
11#define LWTUNNEL_HASH_SIZE (1 << LWTUNNEL_HASH_BITS)
12
13/* lw tunnel state flags */
14#define LWTUNNEL_STATE_OUTPUT_REDIRECT 0x1
15
16struct lwtunnel_state {
17 __u16 type;
18 __u16 flags;
19 atomic_t refcnt;
20 int len;
21 __u8 data[0];
22};
23
24struct lwtunnel_encap_ops {
25 int (*build_state)(struct net_device *dev, struct nlattr *encap,
26 struct lwtunnel_state **ts);
27 int (*output)(struct sock *sk, struct sk_buff *skb);
28 int (*fill_encap)(struct sk_buff *skb,
29 struct lwtunnel_state *lwtstate);
30 int (*get_encap_size)(struct lwtunnel_state *lwtstate);
31 int (*cmp_encap)(struct lwtunnel_state *a, struct lwtunnel_state *b);
32};
33
34extern const struct lwtunnel_encap_ops __rcu *
35 lwtun_encaps[LWTUNNEL_ENCAP_MAX+1];
36
37#ifdef CONFIG_LWTUNNEL
38static inline void lwtunnel_state_get(struct lwtunnel_state *lws)
39{
40 atomic_inc(&lws->refcnt);
41}
42
43static inline void lwtunnel_state_put(struct lwtunnel_state *lws)
44{
45 if (!lws)
46 return;
47
48 if (atomic_dec_and_test(&lws->refcnt))
49 kfree(lws);
50}
51
52static inline bool lwtunnel_output_redirect(struct lwtunnel_state *lwtstate)
53{
54 if (lwtstate && (lwtstate->flags & LWTUNNEL_STATE_OUTPUT_REDIRECT))
55 return true;
56
57 return false;
58}
59
60int lwtunnel_encap_add_ops(const struct lwtunnel_encap_ops *op,
61 unsigned int num);
62int lwtunnel_encap_del_ops(const struct lwtunnel_encap_ops *op,
63 unsigned int num);
64int lwtunnel_build_state(struct net_device *dev, u16 encap_type,
65 struct nlattr *encap,
66 struct lwtunnel_state **lws);
67int lwtunnel_fill_encap(struct sk_buff *skb,
68 struct lwtunnel_state *lwtstate);
69int lwtunnel_get_encap_size(struct lwtunnel_state *lwtstate);
70struct lwtunnel_state *lwtunnel_state_alloc(int hdr_len);
71int lwtunnel_cmp_encap(struct lwtunnel_state *a, struct lwtunnel_state *b);
72
73#else
74
75static inline void lwtunnel_state_get(struct lwtunnel_state *lws)
76{
77}
78
79static inline void lwtunnel_state_put(struct lwtunnel_state *lws)
80{
81}
82
83static inline bool lwtunnel_output_redirect(struct lwtunnel_state *lwtstate)
84{
85 return false;
86}
87
88static inline int lwtunnel_encap_add_ops(const struct lwtunnel_encap_ops *op,
89 unsigned int num)
90{
91 return -EOPNOTSUPP;
92
93}
94
95static inline int lwtunnel_encap_del_ops(const struct lwtunnel_encap_ops *op,
96 unsigned int num)
97{
98 return -EOPNOTSUPP;
99}
100
101static inline int lwtunnel_build_state(struct net_device *dev, u16 encap_type,
102 struct nlattr *encap,
103 struct lwtunnel_state **lws)
104{
105 return -EOPNOTSUPP;
106}
107
108static inline int lwtunnel_fill_encap(struct sk_buff *skb,
109 struct lwtunnel_state *lwtstate)
110{
111 return 0;
112}
113
114static inline int lwtunnel_get_encap_size(struct lwtunnel_state *lwtstate)
115{
116 return 0;
117}
118
119static inline struct lwtunnel_state *lwtunnel_state_alloc(int hdr_len)
120{
121 return NULL;
122}
123
124static inline int lwtunnel_cmp_encap(struct lwtunnel_state *a,
125 struct lwtunnel_state *b)
126{
127 return 0;
128}
129
130#endif
131
132#endif /* __NET_LWTUNNEL_H */