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
{
28 int (*orig_output
)(struct net
*net
, struct sock
*sk
, struct sk_buff
*skb
);
29 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 int (*output
)(struct net
*net
, struct sock
*sk
, struct sk_buff
*skb
);
40 int (*input
)(struct sk_buff
*skb
);
41 int (*fill_encap
)(struct sk_buff
*skb
,
42 struct lwtunnel_state
*lwtstate
);
43 int (*get_encap_size
)(struct lwtunnel_state
*lwtstate
);
44 int (*cmp_encap
)(struct lwtunnel_state
*a
, struct lwtunnel_state
*b
);
45 int (*xmit
)(struct sk_buff
*skb
);
50 #ifdef CONFIG_LWTUNNEL
51 void lwtstate_free(struct lwtunnel_state
*lws
);
53 static inline struct lwtunnel_state
*
54 lwtstate_get(struct lwtunnel_state
*lws
)
57 atomic_inc(&lws
->refcnt
);
62 static inline void lwtstate_put(struct lwtunnel_state
*lws
)
67 if (atomic_dec_and_test(&lws
->refcnt
))
71 static inline bool lwtunnel_output_redirect(struct lwtunnel_state
*lwtstate
)
73 if (lwtstate
&& (lwtstate
->flags
& LWTUNNEL_STATE_OUTPUT_REDIRECT
))
79 static inline bool lwtunnel_input_redirect(struct lwtunnel_state
*lwtstate
)
81 if (lwtstate
&& (lwtstate
->flags
& LWTUNNEL_STATE_INPUT_REDIRECT
))
87 static inline bool lwtunnel_xmit_redirect(struct lwtunnel_state
*lwtstate
)
89 if (lwtstate
&& (lwtstate
->flags
& LWTUNNEL_STATE_XMIT_REDIRECT
))
95 static inline unsigned int lwtunnel_headroom(struct lwtunnel_state
*lwtstate
,
98 if (lwtunnel_xmit_redirect(lwtstate
) && lwtstate
->headroom
< mtu
)
99 return lwtstate
->headroom
;
104 int lwtunnel_encap_add_ops(const struct lwtunnel_encap_ops
*op
,
106 int lwtunnel_encap_del_ops(const struct lwtunnel_encap_ops
*op
,
108 int lwtunnel_valid_encap_type(u16 encap_type
);
109 int lwtunnel_valid_encap_type_attr(struct nlattr
*attr
, int len
);
110 int lwtunnel_build_state(struct net_device
*dev
, u16 encap_type
,
111 struct nlattr
*encap
,
112 unsigned int family
, const void *cfg
,
113 struct lwtunnel_state
**lws
);
114 int lwtunnel_fill_encap(struct sk_buff
*skb
,
115 struct lwtunnel_state
*lwtstate
);
116 int lwtunnel_get_encap_size(struct lwtunnel_state
*lwtstate
);
117 struct lwtunnel_state
*lwtunnel_state_alloc(int hdr_len
);
118 int lwtunnel_cmp_encap(struct lwtunnel_state
*a
, struct lwtunnel_state
*b
);
119 int lwtunnel_output(struct net
*net
, struct sock
*sk
, struct sk_buff
*skb
);
120 int lwtunnel_input(struct sk_buff
*skb
);
121 int lwtunnel_xmit(struct sk_buff
*skb
);
125 static inline void lwtstate_free(struct lwtunnel_state
*lws
)
129 static inline struct lwtunnel_state
*
130 lwtstate_get(struct lwtunnel_state
*lws
)
135 static inline void lwtstate_put(struct lwtunnel_state
*lws
)
139 static inline bool lwtunnel_output_redirect(struct lwtunnel_state
*lwtstate
)
144 static inline bool lwtunnel_input_redirect(struct lwtunnel_state
*lwtstate
)
149 static inline bool lwtunnel_xmit_redirect(struct lwtunnel_state
*lwtstate
)
154 static inline unsigned int lwtunnel_headroom(struct lwtunnel_state
*lwtstate
,
160 static inline int lwtunnel_encap_add_ops(const struct lwtunnel_encap_ops
*op
,
167 static inline int lwtunnel_encap_del_ops(const struct lwtunnel_encap_ops
*op
,
173 static inline int lwtunnel_valid_encap_type(u16 encap_type
)
177 static inline int lwtunnel_valid_encap_type_attr(struct nlattr
*attr
, int len
)
179 /* return 0 since we are not walking attr looking for
180 * RTA_ENCAP_TYPE attribute on nexthops.
185 static inline int lwtunnel_build_state(struct net_device
*dev
, u16 encap_type
,
186 struct nlattr
*encap
,
187 unsigned int family
, const void *cfg
,
188 struct lwtunnel_state
**lws
)
193 static inline int lwtunnel_fill_encap(struct sk_buff
*skb
,
194 struct lwtunnel_state
*lwtstate
)
199 static inline int lwtunnel_get_encap_size(struct lwtunnel_state
*lwtstate
)
204 static inline struct lwtunnel_state
*lwtunnel_state_alloc(int hdr_len
)
209 static inline int lwtunnel_cmp_encap(struct lwtunnel_state
*a
,
210 struct lwtunnel_state
*b
)
215 static inline int lwtunnel_output(struct net
*net
, struct sock
*sk
, struct sk_buff
*skb
)
220 static inline int lwtunnel_input(struct sk_buff
*skb
)
225 static inline int lwtunnel_xmit(struct sk_buff
*skb
)
230 #endif /* CONFIG_LWTUNNEL */
232 #define MODULE_ALIAS_RTNL_LWT(encap_type) MODULE_ALIAS("rtnl-lwt-" __stringify(encap_type))
234 #endif /* __NET_LWTUNNEL_H */