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)
17 struct lwtunnel_state
{
21 int (*orig_output
)(struct net
*net
, struct sock
*sk
, struct sk_buff
*skb
);
22 int (*orig_input
)(struct sk_buff
*);
27 struct lwtunnel_encap_ops
{
28 int (*build_state
)(struct net_device
*dev
, struct nlattr
*encap
,
29 unsigned int family
, const void *cfg
,
30 struct lwtunnel_state
**ts
);
31 int (*output
)(struct net
*net
, struct sock
*sk
, struct sk_buff
*skb
);
32 int (*input
)(struct sk_buff
*skb
);
33 int (*fill_encap
)(struct sk_buff
*skb
,
34 struct lwtunnel_state
*lwtstate
);
35 int (*get_encap_size
)(struct lwtunnel_state
*lwtstate
);
36 int (*cmp_encap
)(struct lwtunnel_state
*a
, struct lwtunnel_state
*b
);
39 #ifdef CONFIG_LWTUNNEL
40 static inline void lwtstate_free(struct lwtunnel_state
*lws
)
45 static inline struct lwtunnel_state
*
46 lwtstate_get(struct lwtunnel_state
*lws
)
49 atomic_inc(&lws
->refcnt
);
54 static inline void lwtstate_put(struct lwtunnel_state
*lws
)
59 if (atomic_dec_and_test(&lws
->refcnt
))
63 static inline bool lwtunnel_output_redirect(struct lwtunnel_state
*lwtstate
)
65 if (lwtstate
&& (lwtstate
->flags
& LWTUNNEL_STATE_OUTPUT_REDIRECT
))
71 static inline bool lwtunnel_input_redirect(struct lwtunnel_state
*lwtstate
)
73 if (lwtstate
&& (lwtstate
->flags
& LWTUNNEL_STATE_INPUT_REDIRECT
))
78 int lwtunnel_encap_add_ops(const struct lwtunnel_encap_ops
*op
,
80 int lwtunnel_encap_del_ops(const struct lwtunnel_encap_ops
*op
,
82 int lwtunnel_build_state(struct net_device
*dev
, u16 encap_type
,
84 unsigned int family
, const void *cfg
,
85 struct lwtunnel_state
**lws
);
86 int lwtunnel_fill_encap(struct sk_buff
*skb
,
87 struct lwtunnel_state
*lwtstate
);
88 int lwtunnel_get_encap_size(struct lwtunnel_state
*lwtstate
);
89 struct lwtunnel_state
*lwtunnel_state_alloc(int hdr_len
);
90 int lwtunnel_cmp_encap(struct lwtunnel_state
*a
, struct lwtunnel_state
*b
);
91 int lwtunnel_output(struct net
*net
, struct sock
*sk
, struct sk_buff
*skb
);
92 int lwtunnel_input(struct sk_buff
*skb
);
96 static inline void lwtstate_free(struct lwtunnel_state
*lws
)
100 static inline struct lwtunnel_state
*
101 lwtstate_get(struct lwtunnel_state
*lws
)
106 static inline void lwtstate_put(struct lwtunnel_state
*lws
)
110 static inline bool lwtunnel_output_redirect(struct lwtunnel_state
*lwtstate
)
115 static inline bool lwtunnel_input_redirect(struct lwtunnel_state
*lwtstate
)
120 static inline int lwtunnel_encap_add_ops(const struct lwtunnel_encap_ops
*op
,
127 static inline int lwtunnel_encap_del_ops(const struct lwtunnel_encap_ops
*op
,
133 static inline int lwtunnel_build_state(struct net_device
*dev
, u16 encap_type
,
134 struct nlattr
*encap
,
135 unsigned int family
, const void *cfg
,
136 struct lwtunnel_state
**lws
)
141 static inline int lwtunnel_fill_encap(struct sk_buff
*skb
,
142 struct lwtunnel_state
*lwtstate
)
147 static inline int lwtunnel_get_encap_size(struct lwtunnel_state
*lwtstate
)
152 static inline struct lwtunnel_state
*lwtunnel_state_alloc(int hdr_len
)
157 static inline int lwtunnel_cmp_encap(struct lwtunnel_state
*a
,
158 struct lwtunnel_state
*b
)
163 static inline int lwtunnel_output(struct net
*net
, struct sock
*sk
, struct sk_buff
*skb
)
168 static inline int lwtunnel_input(struct sk_buff
*skb
)
173 #endif /* CONFIG_LWTUNNEL */
175 #define MODULE_ALIAS_RTNL_LWT(encap_type) MODULE_ALIAS("rtnl-lwt-" __stringify(encap_type))
177 #endif /* __NET_LWTUNNEL_H */