]>
Commit | Line | Data |
---|---|---|
499a2425 RP |
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 */ | |
25368623 TH |
14 | #define LWTUNNEL_STATE_OUTPUT_REDIRECT BIT(0) |
15 | #define LWTUNNEL_STATE_INPUT_REDIRECT BIT(1) | |
14972cbd RP |
16 | #define LWTUNNEL_STATE_XMIT_REDIRECT BIT(2) |
17 | ||
18 | enum { | |
19 | LWTUNNEL_XMIT_DONE, | |
20 | LWTUNNEL_XMIT_CONTINUE, | |
21 | }; | |
22 | ||
499a2425 RP |
23 | |
24 | struct lwtunnel_state { | |
25 | __u16 type; | |
26 | __u16 flags; | |
f76a9db3 | 27 | __u16 headroom; |
499a2425 | 28 | atomic_t refcnt; |
ede2059d | 29 | int (*orig_output)(struct net *net, struct sock *sk, struct sk_buff *skb); |
25368623 | 30 | int (*orig_input)(struct sk_buff *); |
1104d9ba | 31 | struct rcu_head rcu; |
499a2425 RP |
32 | __u8 data[0]; |
33 | }; | |
34 | ||
35 | struct lwtunnel_encap_ops { | |
30357d7d | 36 | int (*build_state)(struct nlattr *encap, |
127eb7cd | 37 | unsigned int family, const void *cfg, |
9ae28727 DA |
38 | struct lwtunnel_state **ts, |
39 | struct netlink_ext_ack *extack); | |
1104d9ba | 40 | void (*destroy_state)(struct lwtunnel_state *lws); |
ede2059d | 41 | int (*output)(struct net *net, struct sock *sk, struct sk_buff *skb); |
25368623 | 42 | int (*input)(struct sk_buff *skb); |
499a2425 RP |
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); | |
14972cbd | 47 | int (*xmit)(struct sk_buff *skb); |
88ff7334 RS |
48 | |
49 | struct module *owner; | |
499a2425 RP |
50 | }; |
51 | ||
499a2425 | 52 | #ifdef CONFIG_LWTUNNEL |
1104d9ba | 53 | void lwtstate_free(struct lwtunnel_state *lws); |
df383e62 | 54 | |
5a6228a0 ND |
55 | static inline struct lwtunnel_state * |
56 | lwtstate_get(struct lwtunnel_state *lws) | |
499a2425 | 57 | { |
5a6228a0 ND |
58 | if (lws) |
59 | atomic_inc(&lws->refcnt); | |
60 | ||
61 | return lws; | |
499a2425 RP |
62 | } |
63 | ||
5a6228a0 | 64 | static inline void lwtstate_put(struct lwtunnel_state *lws) |
499a2425 RP |
65 | { |
66 | if (!lws) | |
67 | return; | |
68 | ||
69 | if (atomic_dec_and_test(&lws->refcnt)) | |
df383e62 | 70 | lwtstate_free(lws); |
499a2425 RP |
71 | } |
72 | ||
73 | static inline bool lwtunnel_output_redirect(struct lwtunnel_state *lwtstate) | |
74 | { | |
75 | if (lwtstate && (lwtstate->flags & LWTUNNEL_STATE_OUTPUT_REDIRECT)) | |
76 | return true; | |
77 | ||
78 | return false; | |
79 | } | |
80 | ||
25368623 TH |
81 | static inline bool lwtunnel_input_redirect(struct lwtunnel_state *lwtstate) |
82 | { | |
83 | if (lwtstate && (lwtstate->flags & LWTUNNEL_STATE_INPUT_REDIRECT)) | |
84 | return true; | |
85 | ||
86 | return false; | |
87 | } | |
14972cbd RP |
88 | |
89 | static inline bool lwtunnel_xmit_redirect(struct lwtunnel_state *lwtstate) | |
90 | { | |
91 | if (lwtstate && (lwtstate->flags & LWTUNNEL_STATE_XMIT_REDIRECT)) | |
92 | return true; | |
93 | ||
94 | return false; | |
95 | } | |
96 | ||
97 | static inline unsigned int lwtunnel_headroom(struct lwtunnel_state *lwtstate, | |
98 | unsigned int mtu) | |
99 | { | |
a23a8f5b DL |
100 | if ((lwtunnel_xmit_redirect(lwtstate) || |
101 | lwtunnel_output_redirect(lwtstate)) && lwtstate->headroom < mtu) | |
14972cbd RP |
102 | return lwtstate->headroom; |
103 | ||
104 | return 0; | |
105 | } | |
106 | ||
499a2425 RP |
107 | int lwtunnel_encap_add_ops(const struct lwtunnel_encap_ops *op, |
108 | unsigned int num); | |
109 | int lwtunnel_encap_del_ops(const struct lwtunnel_encap_ops *op, | |
110 | unsigned int num); | |
c255bd68 DA |
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); | |
30357d7d | 115 | int lwtunnel_build_state(u16 encap_type, |
499a2425 | 116 | struct nlattr *encap, |
127eb7cd | 117 | unsigned int family, const void *cfg, |
9ae28727 DA |
118 | struct lwtunnel_state **lws, |
119 | struct netlink_ext_ack *extack); | |
499a2425 RP |
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); | |
ede2059d | 125 | int lwtunnel_output(struct net *net, struct sock *sk, struct sk_buff *skb); |
25368623 | 126 | int lwtunnel_input(struct sk_buff *skb); |
14972cbd | 127 | int lwtunnel_xmit(struct sk_buff *skb); |
499a2425 RP |
128 | |
129 | #else | |
130 | ||
824e7383 YX |
131 | static inline void lwtstate_free(struct lwtunnel_state *lws) |
132 | { | |
133 | } | |
134 | ||
5a6228a0 ND |
135 | static inline struct lwtunnel_state * |
136 | lwtstate_get(struct lwtunnel_state *lws) | |
499a2425 | 137 | { |
5a6228a0 | 138 | return lws; |
499a2425 RP |
139 | } |
140 | ||
5a6228a0 | 141 | static inline void lwtstate_put(struct lwtunnel_state *lws) |
499a2425 RP |
142 | { |
143 | } | |
144 | ||
145 | static inline bool lwtunnel_output_redirect(struct lwtunnel_state *lwtstate) | |
146 | { | |
147 | return false; | |
148 | } | |
149 | ||
25368623 TH |
150 | static inline bool lwtunnel_input_redirect(struct lwtunnel_state *lwtstate) |
151 | { | |
152 | return false; | |
153 | } | |
154 | ||
14972cbd RP |
155 | static inline bool lwtunnel_xmit_redirect(struct lwtunnel_state *lwtstate) |
156 | { | |
157 | return false; | |
158 | } | |
159 | ||
160 | static inline unsigned int lwtunnel_headroom(struct lwtunnel_state *lwtstate, | |
161 | unsigned int mtu) | |
162 | { | |
163 | return 0; | |
164 | } | |
165 | ||
499a2425 RP |
166 | static inline int lwtunnel_encap_add_ops(const struct lwtunnel_encap_ops *op, |
167 | unsigned int num) | |
168 | { | |
169 | return -EOPNOTSUPP; | |
170 | ||
171 | } | |
172 | ||
173 | static inline int lwtunnel_encap_del_ops(const struct lwtunnel_encap_ops *op, | |
174 | unsigned int num) | |
175 | { | |
176 | return -EOPNOTSUPP; | |
177 | } | |
178 | ||
c255bd68 DA |
179 | static inline int lwtunnel_valid_encap_type(u16 encap_type, |
180 | struct netlink_ext_ack *extack) | |
9ed59592 | 181 | { |
c255bd68 | 182 | NL_SET_ERR_MSG(extack, "CONFIG_LWTUNNEL is not enabled in this kernel"); |
9ed59592 DA |
183 | return -EOPNOTSUPP; |
184 | } | |
c255bd68 DA |
185 | static inline int lwtunnel_valid_encap_type_attr(struct nlattr *attr, int len, |
186 | struct netlink_ext_ack *extack) | |
9ed59592 | 187 | { |
2bd137de DA |
188 | /* return 0 since we are not walking attr looking for |
189 | * RTA_ENCAP_TYPE attribute on nexthops. | |
190 | */ | |
191 | return 0; | |
9ed59592 DA |
192 | } |
193 | ||
30357d7d | 194 | static inline int lwtunnel_build_state(u16 encap_type, |
499a2425 | 195 | struct nlattr *encap, |
127eb7cd | 196 | unsigned int family, const void *cfg, |
9ae28727 DA |
197 | struct lwtunnel_state **lws, |
198 | struct netlink_ext_ack *extack) | |
499a2425 RP |
199 | { |
200 | return -EOPNOTSUPP; | |
201 | } | |
202 | ||
203 | static inline int lwtunnel_fill_encap(struct sk_buff *skb, | |
204 | struct lwtunnel_state *lwtstate) | |
205 | { | |
206 | return 0; | |
207 | } | |
208 | ||
209 | static inline int lwtunnel_get_encap_size(struct lwtunnel_state *lwtstate) | |
210 | { | |
211 | return 0; | |
212 | } | |
213 | ||
214 | static inline struct lwtunnel_state *lwtunnel_state_alloc(int hdr_len) | |
215 | { | |
216 | return NULL; | |
217 | } | |
218 | ||
219 | static inline int lwtunnel_cmp_encap(struct lwtunnel_state *a, | |
220 | struct lwtunnel_state *b) | |
221 | { | |
222 | return 0; | |
223 | } | |
224 | ||
ede2059d | 225 | static inline int lwtunnel_output(struct net *net, struct sock *sk, struct sk_buff *skb) |
ffce4196 RP |
226 | { |
227 | return -EOPNOTSUPP; | |
228 | } | |
229 | ||
25368623 TH |
230 | static inline int lwtunnel_input(struct sk_buff *skb) |
231 | { | |
232 | return -EOPNOTSUPP; | |
233 | } | |
234 | ||
14972cbd RP |
235 | static inline int lwtunnel_xmit(struct sk_buff *skb) |
236 | { | |
237 | return -EOPNOTSUPP; | |
238 | } | |
239 | ||
745041e2 RS |
240 | #endif /* CONFIG_LWTUNNEL */ |
241 | ||
242 | #define MODULE_ALIAS_RTNL_LWT(encap_type) MODULE_ALIAS("rtnl-lwt-" __stringify(encap_type)) | |
499a2425 RP |
243 | |
244 | #endif /* __NET_LWTUNNEL_H */ |