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 nlattr
*encap
,
37 unsigned int family
, const void *cfg
,
38 struct lwtunnel_state
**ts
,
39 struct netlink_ext_ack
*extack
);
40 void (*destroy_state
)(struct lwtunnel_state
*lws
);
41 int (*output
)(struct net
*net
, struct sock
*sk
, struct sk_buff
*skb
);
42 int (*input
)(struct sk_buff
*skb
);
43 int (*fill_encap
)(struct sk_buff
*skb
,
44 struct lwtunnel_state
*lwtstate
);
45 int (*get_encap_size
)(struct lwtunnel_state
*lwtstate
);
46 int (*cmp_encap
)(struct lwtunnel_state
*a
, struct lwtunnel_state
*b
);
47 int (*xmit
)(struct sk_buff
*skb
);
52 #ifdef CONFIG_LWTUNNEL
53 void lwtstate_free(struct lwtunnel_state
*lws
);
55 static inline struct lwtunnel_state
*
56 lwtstate_get(struct lwtunnel_state
*lws
)
59 atomic_inc(&lws
->refcnt
);
64 static inline void lwtstate_put(struct lwtunnel_state
*lws
)
69 if (atomic_dec_and_test(&lws
->refcnt
))
73 static inline bool lwtunnel_output_redirect(struct lwtunnel_state
*lwtstate
)
75 if (lwtstate
&& (lwtstate
->flags
& LWTUNNEL_STATE_OUTPUT_REDIRECT
))
81 static inline bool lwtunnel_input_redirect(struct lwtunnel_state
*lwtstate
)
83 if (lwtstate
&& (lwtstate
->flags
& LWTUNNEL_STATE_INPUT_REDIRECT
))
89 static inline bool lwtunnel_xmit_redirect(struct lwtunnel_state
*lwtstate
)
91 if (lwtstate
&& (lwtstate
->flags
& LWTUNNEL_STATE_XMIT_REDIRECT
))
97 static inline unsigned int lwtunnel_headroom(struct lwtunnel_state
*lwtstate
,
100 if ((lwtunnel_xmit_redirect(lwtstate
) ||
101 lwtunnel_output_redirect(lwtstate
)) && lwtstate
->headroom
< mtu
)
102 return lwtstate
->headroom
;
107 int lwtunnel_encap_add_ops(const struct lwtunnel_encap_ops
*op
,
109 int lwtunnel_encap_del_ops(const struct lwtunnel_encap_ops
*op
,
111 int lwtunnel_valid_encap_type(u16 encap_type
,
112 struct netlink_ext_ack
*extack
);
113 int lwtunnel_valid_encap_type_attr(struct nlattr
*attr
, int len
,
114 struct netlink_ext_ack
*extack
);
115 int lwtunnel_build_state(u16 encap_type
,
116 struct nlattr
*encap
,
117 unsigned int family
, const void *cfg
,
118 struct lwtunnel_state
**lws
,
119 struct netlink_ext_ack
*extack
);
120 int lwtunnel_fill_encap(struct sk_buff
*skb
,
121 struct lwtunnel_state
*lwtstate
);
122 int lwtunnel_get_encap_size(struct lwtunnel_state
*lwtstate
);
123 struct lwtunnel_state
*lwtunnel_state_alloc(int hdr_len
);
124 int lwtunnel_cmp_encap(struct lwtunnel_state
*a
, struct lwtunnel_state
*b
);
125 int lwtunnel_output(struct net
*net
, struct sock
*sk
, struct sk_buff
*skb
);
126 int lwtunnel_input(struct sk_buff
*skb
);
127 int lwtunnel_xmit(struct sk_buff
*skb
);
131 static inline void lwtstate_free(struct lwtunnel_state
*lws
)
135 static inline struct lwtunnel_state
*
136 lwtstate_get(struct lwtunnel_state
*lws
)
141 static inline void lwtstate_put(struct lwtunnel_state
*lws
)
145 static inline bool lwtunnel_output_redirect(struct lwtunnel_state
*lwtstate
)
150 static inline bool lwtunnel_input_redirect(struct lwtunnel_state
*lwtstate
)
155 static inline bool lwtunnel_xmit_redirect(struct lwtunnel_state
*lwtstate
)
160 static inline unsigned int lwtunnel_headroom(struct lwtunnel_state
*lwtstate
,
166 static inline int lwtunnel_encap_add_ops(const struct lwtunnel_encap_ops
*op
,
173 static inline int lwtunnel_encap_del_ops(const struct lwtunnel_encap_ops
*op
,
179 static inline int lwtunnel_valid_encap_type(u16 encap_type
,
180 struct netlink_ext_ack
*extack
)
182 NL_SET_ERR_MSG(extack
, "CONFIG_LWTUNNEL is not enabled in this kernel");
185 static inline int lwtunnel_valid_encap_type_attr(struct nlattr
*attr
, int len
,
186 struct netlink_ext_ack
*extack
)
188 /* return 0 since we are not walking attr looking for
189 * RTA_ENCAP_TYPE attribute on nexthops.
194 static inline int lwtunnel_build_state(u16 encap_type
,
195 struct nlattr
*encap
,
196 unsigned int family
, const void *cfg
,
197 struct lwtunnel_state
**lws
,
198 struct netlink_ext_ack
*extack
)
203 static inline int lwtunnel_fill_encap(struct sk_buff
*skb
,
204 struct lwtunnel_state
*lwtstate
)
209 static inline int lwtunnel_get_encap_size(struct lwtunnel_state
*lwtstate
)
214 static inline struct lwtunnel_state
*lwtunnel_state_alloc(int hdr_len
)
219 static inline int lwtunnel_cmp_encap(struct lwtunnel_state
*a
,
220 struct lwtunnel_state
*b
)
225 static inline int lwtunnel_output(struct net
*net
, struct sock
*sk
, struct sk_buff
*skb
)
230 static inline int lwtunnel_input(struct sk_buff
*skb
)
235 static inline int lwtunnel_xmit(struct sk_buff
*skb
)
240 #endif /* CONFIG_LWTUNNEL */
242 #define MODULE_ALIAS_RTNL_LWT(encap_type) MODULE_ALIAS("rtnl-lwt-" __stringify(encap_type))
244 #endif /* __NET_LWTUNNEL_H */