]>
Commit | Line | Data |
---|---|---|
23461551 TH |
1 | #include <linux/module.h> |
2 | #include <linux/errno.h> | |
3 | #include <linux/socket.h> | |
4 | #include <linux/skbuff.h> | |
5 | #include <linux/ip.h> | |
6 | #include <linux/udp.h> | |
7 | #include <linux/types.h> | |
8 | #include <linux/kernel.h> | |
9 | #include <net/genetlink.h> | |
37dd0247 | 10 | #include <net/gue.h> |
9dc621af | 11 | #include <net/fou.h> |
23461551 | 12 | #include <net/ip.h> |
afe93325 | 13 | #include <net/protocol.h> |
23461551 TH |
14 | #include <net/udp.h> |
15 | #include <net/udp_tunnel.h> | |
16 | #include <net/xfrm.h> | |
17 | #include <uapi/linux/fou.h> | |
18 | #include <uapi/linux/genetlink.h> | |
19 | ||
23461551 TH |
20 | struct fou { |
21 | struct socket *sock; | |
22 | u8 protocol; | |
fe881ef1 | 23 | u8 flags; |
4cbcdf2b | 24 | __be16 port; |
5f914b68 | 25 | u8 family; |
7a6c8c34 | 26 | u16 type; |
23461551 | 27 | struct list_head list; |
3036facb | 28 | struct rcu_head rcu; |
23461551 TH |
29 | }; |
30 | ||
fe881ef1 TH |
31 | #define FOU_F_REMCSUM_NOPARTIAL BIT(0) |
32 | ||
23461551 | 33 | struct fou_cfg { |
37dd0247 | 34 | u16 type; |
23461551 | 35 | u8 protocol; |
fe881ef1 | 36 | u8 flags; |
23461551 TH |
37 | struct udp_port_cfg udp_config; |
38 | }; | |
39 | ||
02d793c5 WC |
40 | static unsigned int fou_net_id; |
41 | ||
42 | struct fou_net { | |
43 | struct list_head fou_list; | |
44 | struct mutex fou_lock; | |
45 | }; | |
46 | ||
23461551 TH |
47 | static inline struct fou *fou_from_sock(struct sock *sk) |
48 | { | |
49 | return sk->sk_user_data; | |
50 | } | |
51 | ||
5f914b68 | 52 | static int fou_recv_pull(struct sk_buff *skb, struct fou *fou, size_t len) |
23461551 | 53 | { |
23461551 | 54 | /* Remove 'len' bytes from the packet (UDP header and |
5024c33a | 55 | * FOU header if present). |
23461551 | 56 | */ |
5f914b68 TH |
57 | if (fou->family == AF_INET) |
58 | ip_hdr(skb)->tot_len = htons(ntohs(ip_hdr(skb)->tot_len) - len); | |
59 | else | |
60 | ipv6_hdr(skb)->payload_len = | |
61 | htons(ntohs(ipv6_hdr(skb)->payload_len) - len); | |
62 | ||
23461551 TH |
63 | __skb_pull(skb, len); |
64 | skb_postpull_rcsum(skb, udp_hdr(skb), len); | |
65 | skb_reset_transport_header(skb); | |
a09a4c8d | 66 | return iptunnel_pull_offloads(skb); |
23461551 TH |
67 | } |
68 | ||
69 | static int fou_udp_recv(struct sock *sk, struct sk_buff *skb) | |
70 | { | |
71 | struct fou *fou = fou_from_sock(sk); | |
72 | ||
73 | if (!fou) | |
74 | return 1; | |
75 | ||
5f914b68 | 76 | if (fou_recv_pull(skb, fou, sizeof(struct udphdr))) |
a09a4c8d | 77 | goto drop; |
5024c33a TH |
78 | |
79 | return -fou->protocol; | |
a09a4c8d JG |
80 | |
81 | drop: | |
82 | kfree_skb(skb); | |
83 | return 0; | |
5024c33a TH |
84 | } |
85 | ||
a8d31c12 | 86 | static struct guehdr *gue_remcsum(struct sk_buff *skb, struct guehdr *guehdr, |
fe881ef1 TH |
87 | void *data, size_t hdrlen, u8 ipproto, |
88 | bool nopartial) | |
a8d31c12 TH |
89 | { |
90 | __be16 *pd = data; | |
4fd671de TH |
91 | size_t start = ntohs(pd[0]); |
92 | size_t offset = ntohs(pd[1]); | |
b7fe10e5 TH |
93 | size_t plen = sizeof(struct udphdr) + hdrlen + |
94 | max_t(size_t, offset + sizeof(u16), start); | |
95 | ||
96 | if (skb->remcsum_offload) | |
97 | return guehdr; | |
a8d31c12 | 98 | |
a8d31c12 TH |
99 | if (!pskb_may_pull(skb, plen)) |
100 | return NULL; | |
101 | guehdr = (struct guehdr *)&udp_hdr(skb)[1]; | |
102 | ||
fe881ef1 TH |
103 | skb_remcsum_process(skb, (void *)guehdr + hdrlen, |
104 | start, offset, nopartial); | |
a8d31c12 TH |
105 | |
106 | return guehdr; | |
107 | } | |
108 | ||
5024c33a TH |
109 | static int gue_control_message(struct sk_buff *skb, struct guehdr *guehdr) |
110 | { | |
111 | /* No support yet */ | |
112 | kfree_skb(skb); | |
113 | return 0; | |
23461551 TH |
114 | } |
115 | ||
37dd0247 TH |
116 | static int gue_udp_recv(struct sock *sk, struct sk_buff *skb) |
117 | { | |
118 | struct fou *fou = fou_from_sock(sk); | |
5024c33a | 119 | size_t len, optlen, hdrlen; |
37dd0247 | 120 | struct guehdr *guehdr; |
5024c33a | 121 | void *data; |
a8d31c12 | 122 | u16 doffset = 0; |
37dd0247 TH |
123 | |
124 | if (!fou) | |
125 | return 1; | |
126 | ||
127 | len = sizeof(struct udphdr) + sizeof(struct guehdr); | |
128 | if (!pskb_may_pull(skb, len)) | |
129 | goto drop; | |
130 | ||
5024c33a TH |
131 | guehdr = (struct guehdr *)&udp_hdr(skb)[1]; |
132 | ||
c1e48af7 TH |
133 | switch (guehdr->version) { |
134 | case 0: /* Full GUE header present */ | |
135 | break; | |
136 | ||
137 | case 1: { | |
138 | /* Direct encasulation of IPv4 or IPv6 */ | |
139 | ||
140 | int prot; | |
141 | ||
142 | switch (((struct iphdr *)guehdr)->version) { | |
143 | case 4: | |
144 | prot = IPPROTO_IPIP; | |
145 | break; | |
146 | case 6: | |
147 | prot = IPPROTO_IPV6; | |
148 | break; | |
149 | default: | |
150 | goto drop; | |
151 | } | |
152 | ||
153 | if (fou_recv_pull(skb, fou, sizeof(struct udphdr))) | |
154 | goto drop; | |
155 | ||
156 | return -prot; | |
157 | } | |
158 | ||
159 | default: /* Undefined version */ | |
160 | goto drop; | |
161 | } | |
162 | ||
5024c33a TH |
163 | optlen = guehdr->hlen << 2; |
164 | len += optlen; | |
37dd0247 | 165 | |
37dd0247 TH |
166 | if (!pskb_may_pull(skb, len)) |
167 | goto drop; | |
168 | ||
5024c33a TH |
169 | /* guehdr may change after pull */ |
170 | guehdr = (struct guehdr *)&udp_hdr(skb)[1]; | |
d8f00d27 | 171 | |
5024c33a | 172 | hdrlen = sizeof(struct guehdr) + optlen; |
37dd0247 | 173 | |
5024c33a | 174 | if (guehdr->version != 0 || validate_gue_flags(guehdr, optlen)) |
37dd0247 | 175 | goto drop; |
5024c33a | 176 | |
a8d31c12 TH |
177 | hdrlen = sizeof(struct guehdr) + optlen; |
178 | ||
5f914b68 TH |
179 | if (fou->family == AF_INET) |
180 | ip_hdr(skb)->tot_len = htons(ntohs(ip_hdr(skb)->tot_len) - len); | |
181 | else | |
182 | ipv6_hdr(skb)->payload_len = | |
183 | htons(ntohs(ipv6_hdr(skb)->payload_len) - len); | |
a8d31c12 | 184 | |
a8d31c12 TH |
185 | /* Pull csum through the guehdr now . This can be used if |
186 | * there is a remote checksum offload. | |
187 | */ | |
188 | skb_postpull_rcsum(skb, udp_hdr(skb), len); | |
5024c33a TH |
189 | |
190 | data = &guehdr[1]; | |
191 | ||
192 | if (guehdr->flags & GUE_FLAG_PRIV) { | |
a8d31c12 TH |
193 | __be32 flags = *(__be32 *)(data + doffset); |
194 | ||
195 | doffset += GUE_LEN_PRIV; | |
196 | ||
197 | if (flags & GUE_PFLAG_REMCSUM) { | |
198 | guehdr = gue_remcsum(skb, guehdr, data + doffset, | |
fe881ef1 TH |
199 | hdrlen, guehdr->proto_ctype, |
200 | !!(fou->flags & | |
201 | FOU_F_REMCSUM_NOPARTIAL)); | |
a8d31c12 TH |
202 | if (!guehdr) |
203 | goto drop; | |
204 | ||
205 | data = &guehdr[1]; | |
5024c33a | 206 | |
a8d31c12 TH |
207 | doffset += GUE_PLEN_REMCSUM; |
208 | } | |
37dd0247 TH |
209 | } |
210 | ||
5024c33a TH |
211 | if (unlikely(guehdr->control)) |
212 | return gue_control_message(skb, guehdr); | |
213 | ||
4fd671de | 214 | __skb_pull(skb, sizeof(struct udphdr) + hdrlen); |
a8d31c12 TH |
215 | skb_reset_transport_header(skb); |
216 | ||
a09a4c8d JG |
217 | if (iptunnel_pull_offloads(skb)) |
218 | goto drop; | |
219 | ||
5024c33a TH |
220 | return -guehdr->proto_ctype; |
221 | ||
37dd0247 TH |
222 | drop: |
223 | kfree_skb(skb); | |
224 | return 0; | |
225 | } | |
226 | ||
d92283e3 TH |
227 | static struct sk_buff **fou_gro_receive(struct sock *sk, |
228 | struct sk_buff **head, | |
229 | struct sk_buff *skb) | |
afe93325 TH |
230 | { |
231 | const struct net_offload *ops; | |
232 | struct sk_buff **pp = NULL; | |
d92283e3 | 233 | u8 proto = fou_from_sock(sk)->protocol; |
efc98d08 | 234 | const struct net_offload **offloads; |
afe93325 | 235 | |
c3483384 AD |
236 | /* We can clear the encap_mark for FOU as we are essentially doing |
237 | * one of two possible things. We are either adding an L4 tunnel | |
238 | * header to the outer L3 tunnel header, or we are are simply | |
239 | * treating the GRE tunnel header as though it is a UDP protocol | |
240 | * specific header such as VXLAN or GENEVE. | |
241 | */ | |
242 | NAPI_GRO_CB(skb)->encap_mark = 0; | |
243 | ||
a0ca153f AD |
244 | /* Flag this frame as already having an outer encap header */ |
245 | NAPI_GRO_CB(skb)->is_fou = 1; | |
246 | ||
afe93325 | 247 | rcu_read_lock(); |
efc98d08 | 248 | offloads = NAPI_GRO_CB(skb)->is_ipv6 ? inet6_offloads : inet_offloads; |
afe93325 TH |
249 | ops = rcu_dereference(offloads[proto]); |
250 | if (!ops || !ops->callbacks.gro_receive) | |
251 | goto out_unlock; | |
252 | ||
fcd91dd4 | 253 | pp = call_gro_receive(ops->callbacks.gro_receive, head, skb); |
afe93325 TH |
254 | |
255 | out_unlock: | |
256 | rcu_read_unlock(); | |
257 | ||
258 | return pp; | |
259 | } | |
260 | ||
d92283e3 TH |
261 | static int fou_gro_complete(struct sock *sk, struct sk_buff *skb, |
262 | int nhoff) | |
afe93325 TH |
263 | { |
264 | const struct net_offload *ops; | |
d92283e3 | 265 | u8 proto = fou_from_sock(sk)->protocol; |
afe93325 | 266 | int err = -ENOSYS; |
efc98d08 | 267 | const struct net_offload **offloads; |
afe93325 TH |
268 | |
269 | rcu_read_lock(); | |
efc98d08 | 270 | offloads = NAPI_GRO_CB(skb)->is_ipv6 ? inet6_offloads : inet_offloads; |
afe93325 TH |
271 | ops = rcu_dereference(offloads[proto]); |
272 | if (WARN_ON(!ops || !ops->callbacks.gro_complete)) | |
273 | goto out_unlock; | |
274 | ||
275 | err = ops->callbacks.gro_complete(skb, nhoff); | |
276 | ||
229740c6 JR |
277 | skb_set_inner_mac_header(skb, nhoff); |
278 | ||
afe93325 TH |
279 | out_unlock: |
280 | rcu_read_unlock(); | |
281 | ||
282 | return err; | |
283 | } | |
284 | ||
a8d31c12 TH |
285 | static struct guehdr *gue_gro_remcsum(struct sk_buff *skb, unsigned int off, |
286 | struct guehdr *guehdr, void *data, | |
b7fe10e5 TH |
287 | size_t hdrlen, struct gro_remcsum *grc, |
288 | bool nopartial) | |
a8d31c12 TH |
289 | { |
290 | __be16 *pd = data; | |
4fd671de TH |
291 | size_t start = ntohs(pd[0]); |
292 | size_t offset = ntohs(pd[1]); | |
a8d31c12 TH |
293 | |
294 | if (skb->remcsum_offload) | |
b7fe10e5 | 295 | return guehdr; |
a8d31c12 | 296 | |
4fd671de | 297 | if (!NAPI_GRO_CB(skb)->csum_valid) |
a8d31c12 TH |
298 | return NULL; |
299 | ||
b7fe10e5 TH |
300 | guehdr = skb_gro_remcsum_process(skb, (void *)guehdr, off, hdrlen, |
301 | start, offset, grc, nopartial); | |
a8d31c12 TH |
302 | |
303 | skb->remcsum_offload = 1; | |
304 | ||
305 | return guehdr; | |
306 | } | |
307 | ||
d92283e3 TH |
308 | static struct sk_buff **gue_gro_receive(struct sock *sk, |
309 | struct sk_buff **head, | |
310 | struct sk_buff *skb) | |
37dd0247 TH |
311 | { |
312 | const struct net_offload **offloads; | |
313 | const struct net_offload *ops; | |
314 | struct sk_buff **pp = NULL; | |
315 | struct sk_buff *p; | |
37dd0247 | 316 | struct guehdr *guehdr; |
5024c33a TH |
317 | size_t len, optlen, hdrlen, off; |
318 | void *data; | |
a8d31c12 | 319 | u16 doffset = 0; |
37dd0247 | 320 | int flush = 1; |
d92283e3 | 321 | struct fou *fou = fou_from_sock(sk); |
26c4f7da | 322 | struct gro_remcsum grc; |
c1e48af7 | 323 | u8 proto; |
26c4f7da TH |
324 | |
325 | skb_gro_remcsum_init(&grc); | |
37dd0247 TH |
326 | |
327 | off = skb_gro_offset(skb); | |
5024c33a TH |
328 | len = off + sizeof(*guehdr); |
329 | ||
37dd0247 | 330 | guehdr = skb_gro_header_fast(skb, off); |
5024c33a TH |
331 | if (skb_gro_header_hard(skb, len)) { |
332 | guehdr = skb_gro_header_slow(skb, len, off); | |
37dd0247 TH |
333 | if (unlikely(!guehdr)) |
334 | goto out; | |
335 | } | |
336 | ||
c1e48af7 TH |
337 | switch (guehdr->version) { |
338 | case 0: | |
339 | break; | |
340 | case 1: | |
341 | switch (((struct iphdr *)guehdr)->version) { | |
342 | case 4: | |
343 | proto = IPPROTO_IPIP; | |
344 | break; | |
345 | case 6: | |
346 | proto = IPPROTO_IPV6; | |
347 | break; | |
348 | default: | |
349 | goto out; | |
350 | } | |
351 | goto next_proto; | |
352 | default: | |
353 | goto out; | |
354 | } | |
355 | ||
5024c33a TH |
356 | optlen = guehdr->hlen << 2; |
357 | len += optlen; | |
37dd0247 | 358 | |
5024c33a TH |
359 | if (skb_gro_header_hard(skb, len)) { |
360 | guehdr = skb_gro_header_slow(skb, len, off); | |
361 | if (unlikely(!guehdr)) | |
362 | goto out; | |
363 | } | |
37dd0247 | 364 | |
5024c33a TH |
365 | if (unlikely(guehdr->control) || guehdr->version != 0 || |
366 | validate_gue_flags(guehdr, optlen)) | |
367 | goto out; | |
37dd0247 | 368 | |
5024c33a TH |
369 | hdrlen = sizeof(*guehdr) + optlen; |
370 | ||
a8d31c12 TH |
371 | /* Adjust NAPI_GRO_CB(skb)->csum to account for guehdr, |
372 | * this is needed if there is a remote checkcsum offload. | |
373 | */ | |
5024c33a TH |
374 | skb_gro_postpull_rcsum(skb, guehdr, hdrlen); |
375 | ||
376 | data = &guehdr[1]; | |
377 | ||
378 | if (guehdr->flags & GUE_FLAG_PRIV) { | |
a8d31c12 | 379 | __be32 flags = *(__be32 *)(data + doffset); |
5024c33a | 380 | |
a8d31c12 TH |
381 | doffset += GUE_LEN_PRIV; |
382 | ||
383 | if (flags & GUE_PFLAG_REMCSUM) { | |
384 | guehdr = gue_gro_remcsum(skb, off, guehdr, | |
b7fe10e5 | 385 | data + doffset, hdrlen, &grc, |
fe881ef1 TH |
386 | !!(fou->flags & |
387 | FOU_F_REMCSUM_NOPARTIAL)); | |
b7fe10e5 | 388 | |
a8d31c12 TH |
389 | if (!guehdr) |
390 | goto out; | |
391 | ||
392 | data = &guehdr[1]; | |
393 | ||
394 | doffset += GUE_PLEN_REMCSUM; | |
395 | } | |
37dd0247 TH |
396 | } |
397 | ||
a8d31c12 TH |
398 | skb_gro_pull(skb, hdrlen); |
399 | ||
37dd0247 TH |
400 | for (p = *head; p; p = p->next) { |
401 | const struct guehdr *guehdr2; | |
402 | ||
403 | if (!NAPI_GRO_CB(p)->same_flow) | |
404 | continue; | |
405 | ||
406 | guehdr2 = (struct guehdr *)(p->data + off); | |
407 | ||
408 | /* Compare base GUE header to be equal (covers | |
5024c33a | 409 | * hlen, version, proto_ctype, and flags. |
37dd0247 TH |
410 | */ |
411 | if (guehdr->word != guehdr2->word) { | |
412 | NAPI_GRO_CB(p)->same_flow = 0; | |
413 | continue; | |
414 | } | |
415 | ||
416 | /* Compare optional fields are the same. */ | |
417 | if (guehdr->hlen && memcmp(&guehdr[1], &guehdr2[1], | |
418 | guehdr->hlen << 2)) { | |
419 | NAPI_GRO_CB(p)->same_flow = 0; | |
420 | continue; | |
421 | } | |
422 | } | |
423 | ||
c1e48af7 TH |
424 | proto = guehdr->proto_ctype; |
425 | ||
426 | next_proto: | |
427 | ||
c3483384 AD |
428 | /* We can clear the encap_mark for GUE as we are essentially doing |
429 | * one of two possible things. We are either adding an L4 tunnel | |
430 | * header to the outer L3 tunnel header, or we are are simply | |
431 | * treating the GRE tunnel header as though it is a UDP protocol | |
432 | * specific header such as VXLAN or GENEVE. | |
433 | */ | |
434 | NAPI_GRO_CB(skb)->encap_mark = 0; | |
435 | ||
a0ca153f AD |
436 | /* Flag this frame as already having an outer encap header */ |
437 | NAPI_GRO_CB(skb)->is_fou = 1; | |
438 | ||
5024c33a TH |
439 | rcu_read_lock(); |
440 | offloads = NAPI_GRO_CB(skb)->is_ipv6 ? inet6_offloads : inet_offloads; | |
c1e48af7 | 441 | ops = rcu_dereference(offloads[proto]); |
27013661 | 442 | if (WARN_ON_ONCE(!ops || !ops->callbacks.gro_receive)) |
5024c33a | 443 | goto out_unlock; |
37dd0247 | 444 | |
fcd91dd4 | 445 | pp = call_gro_receive(ops->callbacks.gro_receive, head, skb); |
c194cf93 | 446 | flush = 0; |
37dd0247 TH |
447 | |
448 | out_unlock: | |
449 | rcu_read_unlock(); | |
450 | out: | |
451 | NAPI_GRO_CB(skb)->flush |= flush; | |
26c4f7da | 452 | skb_gro_remcsum_cleanup(skb, &grc); |
1bff8a0c | 453 | skb->remcsum_offload = 0; |
37dd0247 TH |
454 | |
455 | return pp; | |
456 | } | |
457 | ||
d92283e3 | 458 | static int gue_gro_complete(struct sock *sk, struct sk_buff *skb, int nhoff) |
37dd0247 TH |
459 | { |
460 | const struct net_offload **offloads; | |
461 | struct guehdr *guehdr = (struct guehdr *)(skb->data + nhoff); | |
462 | const struct net_offload *ops; | |
c1e48af7 | 463 | unsigned int guehlen = 0; |
37dd0247 TH |
464 | u8 proto; |
465 | int err = -ENOENT; | |
466 | ||
c1e48af7 TH |
467 | switch (guehdr->version) { |
468 | case 0: | |
469 | proto = guehdr->proto_ctype; | |
470 | guehlen = sizeof(*guehdr) + (guehdr->hlen << 2); | |
471 | break; | |
472 | case 1: | |
473 | switch (((struct iphdr *)guehdr)->version) { | |
474 | case 4: | |
475 | proto = IPPROTO_IPIP; | |
476 | break; | |
477 | case 6: | |
478 | proto = IPPROTO_IPV6; | |
479 | break; | |
480 | default: | |
481 | return err; | |
482 | } | |
483 | break; | |
484 | default: | |
485 | return err; | |
486 | } | |
37dd0247 TH |
487 | |
488 | rcu_read_lock(); | |
489 | offloads = NAPI_GRO_CB(skb)->is_ipv6 ? inet6_offloads : inet_offloads; | |
490 | ops = rcu_dereference(offloads[proto]); | |
491 | if (WARN_ON(!ops || !ops->callbacks.gro_complete)) | |
492 | goto out_unlock; | |
493 | ||
494 | err = ops->callbacks.gro_complete(skb, nhoff + guehlen); | |
495 | ||
229740c6 JR |
496 | skb_set_inner_mac_header(skb, nhoff + guehlen); |
497 | ||
37dd0247 TH |
498 | out_unlock: |
499 | rcu_read_unlock(); | |
500 | return err; | |
501 | } | |
502 | ||
02d793c5 | 503 | static int fou_add_to_port_list(struct net *net, struct fou *fou) |
23461551 | 504 | { |
02d793c5 | 505 | struct fou_net *fn = net_generic(net, fou_net_id); |
23461551 TH |
506 | struct fou *fout; |
507 | ||
02d793c5 WC |
508 | mutex_lock(&fn->fou_lock); |
509 | list_for_each_entry(fout, &fn->fou_list, list) { | |
5f914b68 TH |
510 | if (fou->port == fout->port && |
511 | fou->family == fout->family) { | |
02d793c5 | 512 | mutex_unlock(&fn->fou_lock); |
23461551 TH |
513 | return -EALREADY; |
514 | } | |
515 | } | |
516 | ||
02d793c5 WC |
517 | list_add(&fou->list, &fn->fou_list); |
518 | mutex_unlock(&fn->fou_lock); | |
23461551 TH |
519 | |
520 | return 0; | |
521 | } | |
522 | ||
523 | static void fou_release(struct fou *fou) | |
524 | { | |
525 | struct socket *sock = fou->sock; | |
23461551 | 526 | |
23461551 | 527 | list_del(&fou->list); |
02d793c5 | 528 | udp_tunnel_sock_release(sock); |
23461551 | 529 | |
3036facb | 530 | kfree_rcu(fou, rcu); |
23461551 TH |
531 | } |
532 | ||
533 | static int fou_create(struct net *net, struct fou_cfg *cfg, | |
534 | struct socket **sockp) | |
535 | { | |
23461551 | 536 | struct socket *sock = NULL; |
02d793c5 | 537 | struct fou *fou = NULL; |
23461551 | 538 | struct sock *sk; |
440924bb | 539 | struct udp_tunnel_sock_cfg tunnel_cfg; |
02d793c5 | 540 | int err; |
23461551 TH |
541 | |
542 | /* Open UDP socket */ | |
543 | err = udp_sock_create(net, &cfg->udp_config, &sock); | |
544 | if (err < 0) | |
545 | goto error; | |
546 | ||
547 | /* Allocate FOU port structure */ | |
548 | fou = kzalloc(sizeof(*fou), GFP_KERNEL); | |
549 | if (!fou) { | |
550 | err = -ENOMEM; | |
551 | goto error; | |
552 | } | |
553 | ||
554 | sk = sock->sk; | |
555 | ||
37dd0247 | 556 | fou->port = cfg->udp_config.local_udp_port; |
5f914b68 TH |
557 | fou->family = cfg->udp_config.family; |
558 | fou->flags = cfg->flags; | |
440924bb TH |
559 | fou->type = cfg->type; |
560 | fou->sock = sock; | |
561 | ||
562 | memset(&tunnel_cfg, 0, sizeof(tunnel_cfg)); | |
563 | tunnel_cfg.encap_type = 1; | |
564 | tunnel_cfg.sk_user_data = fou; | |
565 | tunnel_cfg.encap_destroy = NULL; | |
37dd0247 TH |
566 | |
567 | /* Initial for fou type */ | |
568 | switch (cfg->type) { | |
569 | case FOU_ENCAP_DIRECT: | |
440924bb TH |
570 | tunnel_cfg.encap_rcv = fou_udp_recv; |
571 | tunnel_cfg.gro_receive = fou_gro_receive; | |
572 | tunnel_cfg.gro_complete = fou_gro_complete; | |
573 | fou->protocol = cfg->protocol; | |
37dd0247 TH |
574 | break; |
575 | case FOU_ENCAP_GUE: | |
440924bb TH |
576 | tunnel_cfg.encap_rcv = gue_udp_recv; |
577 | tunnel_cfg.gro_receive = gue_gro_receive; | |
578 | tunnel_cfg.gro_complete = gue_gro_complete; | |
37dd0247 TH |
579 | break; |
580 | default: | |
581 | err = -EINVAL; | |
582 | goto error; | |
583 | } | |
23461551 | 584 | |
440924bb | 585 | setup_udp_tunnel_sock(net, sock, &tunnel_cfg); |
23461551 TH |
586 | |
587 | sk->sk_allocation = GFP_ATOMIC; | |
588 | ||
02d793c5 | 589 | err = fou_add_to_port_list(net, fou); |
23461551 TH |
590 | if (err) |
591 | goto error; | |
592 | ||
593 | if (sockp) | |
594 | *sockp = sock; | |
595 | ||
596 | return 0; | |
597 | ||
598 | error: | |
599 | kfree(fou); | |
600 | if (sock) | |
02d793c5 | 601 | udp_tunnel_sock_release(sock); |
23461551 TH |
602 | |
603 | return err; | |
604 | } | |
605 | ||
606 | static int fou_destroy(struct net *net, struct fou_cfg *cfg) | |
607 | { | |
02d793c5 | 608 | struct fou_net *fn = net_generic(net, fou_net_id); |
4cbcdf2b | 609 | __be16 port = cfg->udp_config.local_udp_port; |
5f914b68 | 610 | u8 family = cfg->udp_config.family; |
23461551 | 611 | int err = -EINVAL; |
02d793c5 | 612 | struct fou *fou; |
23461551 | 613 | |
02d793c5 WC |
614 | mutex_lock(&fn->fou_lock); |
615 | list_for_each_entry(fou, &fn->fou_list, list) { | |
5f914b68 | 616 | if (fou->port == port && fou->family == family) { |
23461551 TH |
617 | fou_release(fou); |
618 | err = 0; | |
619 | break; | |
620 | } | |
621 | } | |
02d793c5 | 622 | mutex_unlock(&fn->fou_lock); |
23461551 TH |
623 | |
624 | return err; | |
625 | } | |
626 | ||
489111e5 | 627 | static struct genl_family fou_nl_family; |
23461551 | 628 | |
3f18ff2b | 629 | static const struct nla_policy fou_nl_policy[FOU_ATTR_MAX + 1] = { |
23461551 TH |
630 | [FOU_ATTR_PORT] = { .type = NLA_U16, }, |
631 | [FOU_ATTR_AF] = { .type = NLA_U8, }, | |
632 | [FOU_ATTR_IPPROTO] = { .type = NLA_U8, }, | |
37dd0247 | 633 | [FOU_ATTR_TYPE] = { .type = NLA_U8, }, |
fe881ef1 | 634 | [FOU_ATTR_REMCSUM_NOPARTIAL] = { .type = NLA_FLAG, }, |
23461551 TH |
635 | }; |
636 | ||
637 | static int parse_nl_config(struct genl_info *info, | |
638 | struct fou_cfg *cfg) | |
639 | { | |
640 | memset(cfg, 0, sizeof(*cfg)); | |
641 | ||
642 | cfg->udp_config.family = AF_INET; | |
643 | ||
644 | if (info->attrs[FOU_ATTR_AF]) { | |
645 | u8 family = nla_get_u8(info->attrs[FOU_ATTR_AF]); | |
646 | ||
5f914b68 TH |
647 | switch (family) { |
648 | case AF_INET: | |
649 | break; | |
650 | case AF_INET6: | |
651 | cfg->udp_config.ipv6_v6only = 1; | |
652 | break; | |
653 | default: | |
654 | return -EAFNOSUPPORT; | |
655 | } | |
23461551 TH |
656 | |
657 | cfg->udp_config.family = family; | |
658 | } | |
659 | ||
660 | if (info->attrs[FOU_ATTR_PORT]) { | |
4cbcdf2b | 661 | __be16 port = nla_get_be16(info->attrs[FOU_ATTR_PORT]); |
23461551 TH |
662 | |
663 | cfg->udp_config.local_udp_port = port; | |
664 | } | |
665 | ||
666 | if (info->attrs[FOU_ATTR_IPPROTO]) | |
667 | cfg->protocol = nla_get_u8(info->attrs[FOU_ATTR_IPPROTO]); | |
668 | ||
37dd0247 TH |
669 | if (info->attrs[FOU_ATTR_TYPE]) |
670 | cfg->type = nla_get_u8(info->attrs[FOU_ATTR_TYPE]); | |
671 | ||
fe881ef1 TH |
672 | if (info->attrs[FOU_ATTR_REMCSUM_NOPARTIAL]) |
673 | cfg->flags |= FOU_F_REMCSUM_NOPARTIAL; | |
674 | ||
23461551 TH |
675 | return 0; |
676 | } | |
677 | ||
678 | static int fou_nl_cmd_add_port(struct sk_buff *skb, struct genl_info *info) | |
679 | { | |
02d793c5 | 680 | struct net *net = genl_info_net(info); |
23461551 TH |
681 | struct fou_cfg cfg; |
682 | int err; | |
683 | ||
684 | err = parse_nl_config(info, &cfg); | |
685 | if (err) | |
686 | return err; | |
687 | ||
02d793c5 | 688 | return fou_create(net, &cfg, NULL); |
23461551 TH |
689 | } |
690 | ||
691 | static int fou_nl_cmd_rm_port(struct sk_buff *skb, struct genl_info *info) | |
692 | { | |
02d793c5 | 693 | struct net *net = genl_info_net(info); |
23461551 | 694 | struct fou_cfg cfg; |
67270636 | 695 | int err; |
23461551 | 696 | |
67270636 WC |
697 | err = parse_nl_config(info, &cfg); |
698 | if (err) | |
699 | return err; | |
23461551 | 700 | |
02d793c5 | 701 | return fou_destroy(net, &cfg); |
23461551 TH |
702 | } |
703 | ||
7a6c8c34 WC |
704 | static int fou_fill_info(struct fou *fou, struct sk_buff *msg) |
705 | { | |
706 | if (nla_put_u8(msg, FOU_ATTR_AF, fou->sock->sk->sk_family) || | |
707 | nla_put_be16(msg, FOU_ATTR_PORT, fou->port) || | |
708 | nla_put_u8(msg, FOU_ATTR_IPPROTO, fou->protocol) || | |
709 | nla_put_u8(msg, FOU_ATTR_TYPE, fou->type)) | |
710 | return -1; | |
711 | ||
712 | if (fou->flags & FOU_F_REMCSUM_NOPARTIAL) | |
713 | if (nla_put_flag(msg, FOU_ATTR_REMCSUM_NOPARTIAL)) | |
714 | return -1; | |
715 | return 0; | |
716 | } | |
717 | ||
718 | static int fou_dump_info(struct fou *fou, u32 portid, u32 seq, | |
719 | u32 flags, struct sk_buff *skb, u8 cmd) | |
720 | { | |
721 | void *hdr; | |
722 | ||
723 | hdr = genlmsg_put(skb, portid, seq, &fou_nl_family, flags, cmd); | |
724 | if (!hdr) | |
725 | return -ENOMEM; | |
726 | ||
727 | if (fou_fill_info(fou, skb) < 0) | |
728 | goto nla_put_failure; | |
729 | ||
730 | genlmsg_end(skb, hdr); | |
731 | return 0; | |
732 | ||
733 | nla_put_failure: | |
734 | genlmsg_cancel(skb, hdr); | |
735 | return -EMSGSIZE; | |
736 | } | |
737 | ||
738 | static int fou_nl_cmd_get_port(struct sk_buff *skb, struct genl_info *info) | |
739 | { | |
740 | struct net *net = genl_info_net(info); | |
741 | struct fou_net *fn = net_generic(net, fou_net_id); | |
742 | struct sk_buff *msg; | |
743 | struct fou_cfg cfg; | |
744 | struct fou *fout; | |
745 | __be16 port; | |
5f914b68 | 746 | u8 family; |
7a6c8c34 WC |
747 | int ret; |
748 | ||
749 | ret = parse_nl_config(info, &cfg); | |
750 | if (ret) | |
751 | return ret; | |
752 | port = cfg.udp_config.local_udp_port; | |
753 | if (port == 0) | |
754 | return -EINVAL; | |
755 | ||
5f914b68 TH |
756 | family = cfg.udp_config.family; |
757 | if (family != AF_INET && family != AF_INET6) | |
758 | return -EINVAL; | |
759 | ||
7a6c8c34 WC |
760 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
761 | if (!msg) | |
762 | return -ENOMEM; | |
763 | ||
764 | ret = -ESRCH; | |
765 | mutex_lock(&fn->fou_lock); | |
766 | list_for_each_entry(fout, &fn->fou_list, list) { | |
5f914b68 | 767 | if (port == fout->port && family == fout->family) { |
7a6c8c34 WC |
768 | ret = fou_dump_info(fout, info->snd_portid, |
769 | info->snd_seq, 0, msg, | |
770 | info->genlhdr->cmd); | |
771 | break; | |
772 | } | |
773 | } | |
774 | mutex_unlock(&fn->fou_lock); | |
775 | if (ret < 0) | |
776 | goto out_free; | |
777 | ||
778 | return genlmsg_reply(msg, info); | |
779 | ||
780 | out_free: | |
781 | nlmsg_free(msg); | |
782 | return ret; | |
783 | } | |
784 | ||
785 | static int fou_nl_dump(struct sk_buff *skb, struct netlink_callback *cb) | |
786 | { | |
787 | struct net *net = sock_net(skb->sk); | |
788 | struct fou_net *fn = net_generic(net, fou_net_id); | |
789 | struct fou *fout; | |
790 | int idx = 0, ret; | |
791 | ||
792 | mutex_lock(&fn->fou_lock); | |
793 | list_for_each_entry(fout, &fn->fou_list, list) { | |
794 | if (idx++ < cb->args[0]) | |
795 | continue; | |
796 | ret = fou_dump_info(fout, NETLINK_CB(cb->skb).portid, | |
797 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | |
798 | skb, FOU_CMD_GET); | |
799 | if (ret) | |
540207ae | 800 | break; |
7a6c8c34 WC |
801 | } |
802 | mutex_unlock(&fn->fou_lock); | |
803 | ||
7a6c8c34 WC |
804 | cb->args[0] = idx; |
805 | return skb->len; | |
806 | } | |
807 | ||
23461551 TH |
808 | static const struct genl_ops fou_nl_ops[] = { |
809 | { | |
810 | .cmd = FOU_CMD_ADD, | |
811 | .doit = fou_nl_cmd_add_port, | |
812 | .policy = fou_nl_policy, | |
813 | .flags = GENL_ADMIN_PERM, | |
814 | }, | |
815 | { | |
816 | .cmd = FOU_CMD_DEL, | |
817 | .doit = fou_nl_cmd_rm_port, | |
818 | .policy = fou_nl_policy, | |
819 | .flags = GENL_ADMIN_PERM, | |
820 | }, | |
7a6c8c34 WC |
821 | { |
822 | .cmd = FOU_CMD_GET, | |
823 | .doit = fou_nl_cmd_get_port, | |
824 | .dumpit = fou_nl_dump, | |
825 | .policy = fou_nl_policy, | |
826 | }, | |
23461551 TH |
827 | }; |
828 | ||
56989f6d | 829 | static struct genl_family fou_nl_family __ro_after_init = { |
489111e5 JB |
830 | .hdrsize = 0, |
831 | .name = FOU_GENL_NAME, | |
832 | .version = FOU_GENL_VERSION, | |
833 | .maxattr = FOU_ATTR_MAX, | |
834 | .netnsok = true, | |
835 | .module = THIS_MODULE, | |
836 | .ops = fou_nl_ops, | |
837 | .n_ops = ARRAY_SIZE(fou_nl_ops), | |
838 | }; | |
839 | ||
a8c5f90f TH |
840 | size_t fou_encap_hlen(struct ip_tunnel_encap *e) |
841 | { | |
842 | return sizeof(struct udphdr); | |
843 | } | |
844 | EXPORT_SYMBOL(fou_encap_hlen); | |
845 | ||
846 | size_t gue_encap_hlen(struct ip_tunnel_encap *e) | |
847 | { | |
848 | size_t len; | |
849 | bool need_priv = false; | |
850 | ||
851 | len = sizeof(struct udphdr) + sizeof(struct guehdr); | |
852 | ||
853 | if (e->flags & TUNNEL_ENCAP_FLAG_REMCSUM) { | |
854 | len += GUE_PLEN_REMCSUM; | |
855 | need_priv = true; | |
856 | } | |
857 | ||
858 | len += need_priv ? GUE_LEN_PRIV : 0; | |
859 | ||
860 | return len; | |
861 | } | |
862 | EXPORT_SYMBOL(gue_encap_hlen); | |
863 | ||
dc969b81 TH |
864 | int __fou_build_header(struct sk_buff *skb, struct ip_tunnel_encap *e, |
865 | u8 *protocol, __be16 *sport, int type) | |
866 | { | |
867 | int err; | |
868 | ||
869 | err = iptunnel_handle_offloads(skb, type); | |
870 | if (err) | |
871 | return err; | |
872 | ||
873 | *sport = e->sport ? : udp_flow_src_port(dev_net(skb->dev), | |
874 | skb, 0, 0, false); | |
875 | ||
876 | return 0; | |
877 | } | |
878 | EXPORT_SYMBOL(__fou_build_header); | |
879 | ||
dc969b81 TH |
880 | int __gue_build_header(struct sk_buff *skb, struct ip_tunnel_encap *e, |
881 | u8 *protocol, __be16 *sport, int type) | |
63487bab | 882 | { |
63487bab | 883 | struct guehdr *guehdr; |
b17f709a | 884 | size_t hdrlen, optlen = 0; |
5024c33a TH |
885 | void *data; |
886 | bool need_priv = false; | |
aed069df | 887 | int err; |
5024c33a | 888 | |
b17f709a TH |
889 | if ((e->flags & TUNNEL_ENCAP_FLAG_REMCSUM) && |
890 | skb->ip_summed == CHECKSUM_PARTIAL) { | |
b17f709a TH |
891 | optlen += GUE_PLEN_REMCSUM; |
892 | type |= SKB_GSO_TUNNEL_REMCSUM; | |
893 | need_priv = true; | |
894 | } | |
895 | ||
5024c33a | 896 | optlen += need_priv ? GUE_LEN_PRIV : 0; |
63487bab | 897 | |
aed069df AD |
898 | err = iptunnel_handle_offloads(skb, type); |
899 | if (err) | |
900 | return err; | |
63487bab TH |
901 | |
902 | /* Get source port (based on flow hash) before skb_push */ | |
dc969b81 TH |
903 | *sport = e->sport ? : udp_flow_src_port(dev_net(skb->dev), |
904 | skb, 0, 0, false); | |
63487bab | 905 | |
b17f709a TH |
906 | hdrlen = sizeof(struct guehdr) + optlen; |
907 | ||
908 | skb_push(skb, hdrlen); | |
63487bab TH |
909 | |
910 | guehdr = (struct guehdr *)skb->data; | |
911 | ||
5024c33a | 912 | guehdr->control = 0; |
63487bab | 913 | guehdr->version = 0; |
5024c33a | 914 | guehdr->hlen = optlen >> 2; |
63487bab | 915 | guehdr->flags = 0; |
5024c33a TH |
916 | guehdr->proto_ctype = *protocol; |
917 | ||
918 | data = &guehdr[1]; | |
919 | ||
920 | if (need_priv) { | |
921 | __be32 *flags = data; | |
922 | ||
923 | guehdr->flags |= GUE_FLAG_PRIV; | |
924 | *flags = 0; | |
925 | data += GUE_LEN_PRIV; | |
926 | ||
b17f709a TH |
927 | if (type & SKB_GSO_TUNNEL_REMCSUM) { |
928 | u16 csum_start = skb_checksum_start_offset(skb); | |
929 | __be16 *pd = data; | |
930 | ||
931 | if (csum_start < hdrlen) | |
932 | return -EINVAL; | |
933 | ||
934 | csum_start -= hdrlen; | |
935 | pd[0] = htons(csum_start); | |
936 | pd[1] = htons(csum_start + skb->csum_offset); | |
937 | ||
938 | if (!skb_is_gso(skb)) { | |
939 | skb->ip_summed = CHECKSUM_NONE; | |
940 | skb->encapsulation = 0; | |
941 | } | |
942 | ||
943 | *flags |= GUE_PFLAG_REMCSUM; | |
944 | data += GUE_PLEN_REMCSUM; | |
945 | } | |
946 | ||
5024c33a | 947 | } |
63487bab | 948 | |
dc969b81 TH |
949 | return 0; |
950 | } | |
951 | EXPORT_SYMBOL(__gue_build_header); | |
952 | ||
9dc621af | 953 | #ifdef CONFIG_NET_FOU_IP_TUNNELS |
954 | ||
955 | static void fou_build_udp(struct sk_buff *skb, struct ip_tunnel_encap *e, | |
956 | struct flowi4 *fl4, u8 *protocol, __be16 sport) | |
957 | { | |
958 | struct udphdr *uh; | |
959 | ||
960 | skb_push(skb, sizeof(struct udphdr)); | |
961 | skb_reset_transport_header(skb); | |
962 | ||
963 | uh = udp_hdr(skb); | |
964 | ||
965 | uh->dest = e->dport; | |
966 | uh->source = sport; | |
967 | uh->len = htons(skb->len); | |
968 | udp_set_csum(!(e->flags & TUNNEL_ENCAP_FLAG_CSUM), skb, | |
969 | fl4->saddr, fl4->daddr, skb->len); | |
970 | ||
971 | *protocol = IPPROTO_UDP; | |
972 | } | |
973 | ||
974 | static int fou_build_header(struct sk_buff *skb, struct ip_tunnel_encap *e, | |
975 | u8 *protocol, struct flowi4 *fl4) | |
976 | { | |
977 | int type = e->flags & TUNNEL_ENCAP_FLAG_CSUM ? SKB_GSO_UDP_TUNNEL_CSUM : | |
978 | SKB_GSO_UDP_TUNNEL; | |
979 | __be16 sport; | |
980 | int err; | |
981 | ||
982 | err = __fou_build_header(skb, e, protocol, &sport, type); | |
983 | if (err) | |
984 | return err; | |
985 | ||
986 | fou_build_udp(skb, e, fl4, protocol, sport); | |
987 | ||
988 | return 0; | |
989 | } | |
990 | ||
991 | static int gue_build_header(struct sk_buff *skb, struct ip_tunnel_encap *e, | |
992 | u8 *protocol, struct flowi4 *fl4) | |
dc969b81 TH |
993 | { |
994 | int type = e->flags & TUNNEL_ENCAP_FLAG_CSUM ? SKB_GSO_UDP_TUNNEL_CSUM : | |
995 | SKB_GSO_UDP_TUNNEL; | |
996 | __be16 sport; | |
997 | int err; | |
998 | ||
999 | err = __gue_build_header(skb, e, protocol, &sport, type); | |
1000 | if (err) | |
1001 | return err; | |
1002 | ||
63487bab TH |
1003 | fou_build_udp(skb, e, fl4, protocol, sport); |
1004 | ||
1005 | return 0; | |
1006 | } | |
63487bab | 1007 | |
a8c5f90f | 1008 | |
5eeb2922 | 1009 | static const struct ip_tunnel_encap_ops fou_iptun_ops = { |
a8c5f90f TH |
1010 | .encap_hlen = fou_encap_hlen, |
1011 | .build_header = fou_build_header, | |
1012 | }; | |
1013 | ||
5eeb2922 | 1014 | static const struct ip_tunnel_encap_ops gue_iptun_ops = { |
a8c5f90f TH |
1015 | .encap_hlen = gue_encap_hlen, |
1016 | .build_header = gue_build_header, | |
1017 | }; | |
1018 | ||
1019 | static int ip_tunnel_encap_add_fou_ops(void) | |
1020 | { | |
1021 | int ret; | |
1022 | ||
1023 | ret = ip_tunnel_encap_add_ops(&fou_iptun_ops, TUNNEL_ENCAP_FOU); | |
1024 | if (ret < 0) { | |
1025 | pr_err("can't add fou ops\n"); | |
1026 | return ret; | |
1027 | } | |
1028 | ||
1029 | ret = ip_tunnel_encap_add_ops(&gue_iptun_ops, TUNNEL_ENCAP_GUE); | |
1030 | if (ret < 0) { | |
1031 | pr_err("can't add gue ops\n"); | |
1032 | ip_tunnel_encap_del_ops(&fou_iptun_ops, TUNNEL_ENCAP_FOU); | |
1033 | return ret; | |
1034 | } | |
1035 | ||
1036 | return 0; | |
1037 | } | |
1038 | ||
1039 | static void ip_tunnel_encap_del_fou_ops(void) | |
1040 | { | |
1041 | ip_tunnel_encap_del_ops(&fou_iptun_ops, TUNNEL_ENCAP_FOU); | |
1042 | ip_tunnel_encap_del_ops(&gue_iptun_ops, TUNNEL_ENCAP_GUE); | |
1043 | } | |
1044 | ||
1045 | #else | |
1046 | ||
1047 | static int ip_tunnel_encap_add_fou_ops(void) | |
1048 | { | |
1049 | return 0; | |
1050 | } | |
1051 | ||
882288c0 | 1052 | static void ip_tunnel_encap_del_fou_ops(void) |
a8c5f90f TH |
1053 | { |
1054 | } | |
1055 | ||
1056 | #endif | |
1057 | ||
02d793c5 WC |
1058 | static __net_init int fou_init_net(struct net *net) |
1059 | { | |
1060 | struct fou_net *fn = net_generic(net, fou_net_id); | |
1061 | ||
1062 | INIT_LIST_HEAD(&fn->fou_list); | |
1063 | mutex_init(&fn->fou_lock); | |
1064 | return 0; | |
1065 | } | |
1066 | ||
1067 | static __net_exit void fou_exit_net(struct net *net) | |
1068 | { | |
1069 | struct fou_net *fn = net_generic(net, fou_net_id); | |
1070 | struct fou *fou, *next; | |
1071 | ||
1072 | /* Close all the FOU sockets */ | |
1073 | mutex_lock(&fn->fou_lock); | |
1074 | list_for_each_entry_safe(fou, next, &fn->fou_list, list) | |
1075 | fou_release(fou); | |
1076 | mutex_unlock(&fn->fou_lock); | |
1077 | } | |
1078 | ||
1079 | static struct pernet_operations fou_net_ops = { | |
1080 | .init = fou_init_net, | |
1081 | .exit = fou_exit_net, | |
1082 | .id = &fou_net_id, | |
1083 | .size = sizeof(struct fou_net), | |
1084 | }; | |
1085 | ||
23461551 TH |
1086 | static int __init fou_init(void) |
1087 | { | |
1088 | int ret; | |
1089 | ||
02d793c5 WC |
1090 | ret = register_pernet_device(&fou_net_ops); |
1091 | if (ret) | |
1092 | goto exit; | |
1093 | ||
489111e5 | 1094 | ret = genl_register_family(&fou_nl_family); |
a8c5f90f | 1095 | if (ret < 0) |
02d793c5 | 1096 | goto unregister; |
a8c5f90f TH |
1097 | |
1098 | ret = ip_tunnel_encap_add_fou_ops(); | |
02d793c5 WC |
1099 | if (ret == 0) |
1100 | return 0; | |
a8c5f90f | 1101 | |
02d793c5 WC |
1102 | genl_unregister_family(&fou_nl_family); |
1103 | unregister: | |
1104 | unregister_pernet_device(&fou_net_ops); | |
a8c5f90f | 1105 | exit: |
23461551 TH |
1106 | return ret; |
1107 | } | |
1108 | ||
1109 | static void __exit fou_fini(void) | |
1110 | { | |
a8c5f90f | 1111 | ip_tunnel_encap_del_fou_ops(); |
23461551 | 1112 | genl_unregister_family(&fou_nl_family); |
02d793c5 | 1113 | unregister_pernet_device(&fou_net_ops); |
23461551 TH |
1114 | } |
1115 | ||
1116 | module_init(fou_init); | |
1117 | module_exit(fou_fini); | |
1118 | MODULE_AUTHOR("Tom Herbert <[email protected]>"); | |
1119 | MODULE_LICENSE("GPL"); |