1 #ifndef __NET_LWTUNNEL_H
2 #define __NET_LWTUNNEL_H 1
4 #include <linux/lwtunnel.h>
5 #include <linux/netdevice.h>
6 #include <linux/skbuff.h>
7 #include <linux/types.h>
10 #define LWTUNNEL_HASH_BITS 7
11 #define LWTUNNEL_HASH_SIZE (1 << LWTUNNEL_HASH_BITS)
13 /* lw tunnel state flags */
14 #define LWTUNNEL_STATE_OUTPUT_REDIRECT BIT(0)
15 #define LWTUNNEL_STATE_INPUT_REDIRECT BIT(1)
16 #define LWTUNNEL_STATE_XMIT_REDIRECT BIT(2)
20 LWTUNNEL_XMIT_CONTINUE
,
24 struct lwtunnel_state
{
29 int (*orig_output
)(struct net
*net
, struct sock
*sk
, struct sk_buff
*skb
);
30 int (*orig_input
)(struct sk_buff
*);
35 struct lwtunnel_encap_ops
{
36 int (*build_state
)(struct net_device
*dev
, struct nlattr
*encap
,
37 unsigned int family
, const void *cfg
,
38 struct lwtunnel_state
**ts
);
39 void (*destroy_state
)(struct lwtunnel_state
*lws
);
40 int (*output
)(struct net
*net
, struct sock
*sk
, struct sk_buff
*skb
);
41 int (*input
)(struct sk_buff
*skb
);
42 int (*fill_encap
)(struct sk_buff
*skb
,
43 struct lwtunnel_state
*lwtstate
);
44 int (*get_encap_size
)(struct lwtunnel_state
*lwtstate
);
45 int (*cmp_encap
)(struct lwtunnel_state
*a
, struct lwtunnel_state
*b
);
46 int (*xmit
)(struct sk_buff
*skb
);
51 #ifdef CONFIG_LWTUNNEL
52 void lwtstate_free(struct lwtunnel_state
*lws
);
54 static inline struct lwtunnel_state
*
55 lwtstate_get(struct lwtunnel_state
*lws
)
58 atomic_inc(&lws
->refcnt
);
63 static inline void lwtstate_put(struct lwtunnel_state
*lws
)
68 if (atomic_dec_and_test(&lws
->refcnt
))
72 static inline bool lwtunnel_output_redirect(struct lwtunnel_state
*lwtstate
)
74 if (lwtstate
&& (lwtstate
->flags
& LWTUNNEL_STATE_OUTPUT_REDIRECT
))
80 static inline bool lwtunnel_input_redirect(struct lwtunnel_state
*lwtstate
)
82 if (lwtstate
&& (lwtstate
->flags
& LWTUNNEL_STATE_INPUT_REDIRECT
))
88 static inline bool lwtunnel_xmit_redirect(struct lwtunnel_state
*lwtstate
)
90 if (lwtstate
&& (lwtstate
->flags
& LWTUNNEL_STATE_XMIT_REDIRECT
))
96 static inline unsigned int lwtunnel_headroom(struct lwtunnel_state
*lwtstate
,
99 if ((lwtunnel_xmit_redirect(lwtstate
) ||
100 lwtunnel_output_redirect(lwtstate
)) && lwtstate
->headroom
< mtu
)
101 return lwtstate
->headroom
;
106 int lwtunnel_encap_add_ops(const struct lwtunnel_encap_ops
*op
,
108 int lwtunnel_encap_del_ops(const struct lwtunnel_encap_ops
*op
,
110 int lwtunnel_valid_encap_type(u16 encap_type
);
111 int lwtunnel_valid_encap_type_attr(struct nlattr
*attr
, int len
);
112 int lwtunnel_build_state(struct net_device
*dev
, u16 encap_type
,
113 struct nlattr
*encap
,
114 unsigned int family
, const void *cfg
,
115 struct lwtunnel_state
**lws
);
116 int lwtunnel_fill_encap(struct sk_buff
*skb
,
117 struct lwtunnel_state
*lwtstate
);
118 int lwtunnel_get_encap_size(struct lwtunnel_state
*lwtstate
);
119 struct lwtunnel_state
*lwtunnel_state_alloc(int hdr_len
);
120 int lwtunnel_cmp_encap(struct lwtunnel_state
*a
, struct lwtunnel_state
*b
);
121 int lwtunnel_output(struct net
*net
, struct sock
*sk
, struct sk_buff
*skb
);
122 int lwtunnel_input(struct sk_buff
*skb
);
123 int lwtunnel_xmit(struct sk_buff
*skb
);
127 static inline void lwtstate_free(struct lwtunnel_state
*lws
)
131 static inline struct lwtunnel_state
*
132 lwtstate_get(struct lwtunnel_state
*lws
)
137 static inline void lwtstate_put(struct lwtunnel_state
*lws
)
141 static inline bool lwtunnel_output_redirect(struct lwtunnel_state
*lwtstate
)
146 static inline bool lwtunnel_input_redirect(struct lwtunnel_state
*lwtstate
)
151 static inline bool lwtunnel_xmit_redirect(struct lwtunnel_state
*lwtstate
)
156 static inline unsigned int lwtunnel_headroom(struct lwtunnel_state
*lwtstate
,
162 static inline int lwtunnel_encap_add_ops(const struct lwtunnel_encap_ops
*op
,
169 static inline int lwtunnel_encap_del_ops(const struct lwtunnel_encap_ops
*op
,
175 static inline int lwtunnel_valid_encap_type(u16 encap_type
)
179 static inline int lwtunnel_valid_encap_type_attr(struct nlattr
*attr
, int len
)
184 static inline int lwtunnel_build_state(struct net_device
*dev
, u16 encap_type
,
185 struct nlattr
*encap
,
186 unsigned int family
, const void *cfg
,
187 struct lwtunnel_state
**lws
)
192 static inline int lwtunnel_fill_encap(struct sk_buff
*skb
,
193 struct lwtunnel_state
*lwtstate
)
198 static inline int lwtunnel_get_encap_size(struct lwtunnel_state
*lwtstate
)
203 static inline struct lwtunnel_state
*lwtunnel_state_alloc(int hdr_len
)
208 static inline int lwtunnel_cmp_encap(struct lwtunnel_state
*a
,
209 struct lwtunnel_state
*b
)
214 static inline int lwtunnel_output(struct net
*net
, struct sock
*sk
, struct sk_buff
*skb
)
219 static inline int lwtunnel_input(struct sk_buff
*skb
)
224 static inline int lwtunnel_xmit(struct sk_buff
*skb
)
229 #endif /* CONFIG_LWTUNNEL */
231 #define MODULE_ALIAS_RTNL_LWT(encap_type) MODULE_ALIAS("rtnl-lwt-" __stringify(encap_type))
233 #endif /* __NET_LWTUNNEL_H */