1 #include <linux/module.h>
2 #include <linux/errno.h>
3 #include <linux/socket.h>
4 #include <linux/skbuff.h>
7 #include <linux/types.h>
8 #include <linux/kernel.h>
9 #include <net/genetlink.h>
12 #include <net/protocol.h>
14 #include <net/udp_tunnel.h>
16 #include <uapi/linux/fou.h>
17 #include <uapi/linux/genetlink.h>
25 struct udp_offload udp_offloads
;
26 struct list_head list
;
30 #define FOU_F_REMCSUM_NOPARTIAL BIT(0)
36 struct udp_port_cfg udp_config
;
39 static unsigned int fou_net_id
;
42 struct list_head fou_list
;
43 struct mutex fou_lock
;
46 static inline struct fou
*fou_from_sock(struct sock
*sk
)
48 return sk
->sk_user_data
;
51 static int fou_recv_pull(struct sk_buff
*skb
, size_t len
)
53 struct iphdr
*iph
= ip_hdr(skb
);
55 /* Remove 'len' bytes from the packet (UDP header and
56 * FOU header if present).
58 iph
->tot_len
= htons(ntohs(iph
->tot_len
) - len
);
60 skb_postpull_rcsum(skb
, udp_hdr(skb
), len
);
61 skb_reset_transport_header(skb
);
62 return iptunnel_pull_offloads(skb
);
65 static int fou_udp_recv(struct sock
*sk
, struct sk_buff
*skb
)
67 struct fou
*fou
= fou_from_sock(sk
);
72 if (fou_recv_pull(skb
, sizeof(struct udphdr
)))
75 return -fou
->protocol
;
82 static struct guehdr
*gue_remcsum(struct sk_buff
*skb
, struct guehdr
*guehdr
,
83 void *data
, size_t hdrlen
, u8 ipproto
,
87 size_t start
= ntohs(pd
[0]);
88 size_t offset
= ntohs(pd
[1]);
89 size_t plen
= sizeof(struct udphdr
) + hdrlen
+
90 max_t(size_t, offset
+ sizeof(u16
), start
);
92 if (skb
->remcsum_offload
)
95 if (!pskb_may_pull(skb
, plen
))
97 guehdr
= (struct guehdr
*)&udp_hdr(skb
)[1];
99 skb_remcsum_process(skb
, (void *)guehdr
+ hdrlen
,
100 start
, offset
, nopartial
);
105 static int gue_control_message(struct sk_buff
*skb
, struct guehdr
*guehdr
)
112 static int gue_udp_recv(struct sock
*sk
, struct sk_buff
*skb
)
114 struct fou
*fou
= fou_from_sock(sk
);
115 size_t len
, optlen
, hdrlen
;
116 struct guehdr
*guehdr
;
123 len
= sizeof(struct udphdr
) + sizeof(struct guehdr
);
124 if (!pskb_may_pull(skb
, len
))
127 guehdr
= (struct guehdr
*)&udp_hdr(skb
)[1];
129 optlen
= guehdr
->hlen
<< 2;
132 if (!pskb_may_pull(skb
, len
))
135 /* guehdr may change after pull */
136 guehdr
= (struct guehdr
*)&udp_hdr(skb
)[1];
138 hdrlen
= sizeof(struct guehdr
) + optlen
;
140 if (guehdr
->version
!= 0 || validate_gue_flags(guehdr
, optlen
))
143 hdrlen
= sizeof(struct guehdr
) + optlen
;
145 ip_hdr(skb
)->tot_len
= htons(ntohs(ip_hdr(skb
)->tot_len
) - len
);
147 /* Pull csum through the guehdr now . This can be used if
148 * there is a remote checksum offload.
150 skb_postpull_rcsum(skb
, udp_hdr(skb
), len
);
154 if (guehdr
->flags
& GUE_FLAG_PRIV
) {
155 __be32 flags
= *(__be32
*)(data
+ doffset
);
157 doffset
+= GUE_LEN_PRIV
;
159 if (flags
& GUE_PFLAG_REMCSUM
) {
160 guehdr
= gue_remcsum(skb
, guehdr
, data
+ doffset
,
161 hdrlen
, guehdr
->proto_ctype
,
163 FOU_F_REMCSUM_NOPARTIAL
));
169 doffset
+= GUE_PLEN_REMCSUM
;
173 if (unlikely(guehdr
->control
))
174 return gue_control_message(skb
, guehdr
);
176 __skb_pull(skb
, sizeof(struct udphdr
) + hdrlen
);
177 skb_reset_transport_header(skb
);
179 if (iptunnel_pull_offloads(skb
))
182 return -guehdr
->proto_ctype
;
189 static struct sk_buff
**fou_gro_receive(struct sk_buff
**head
,
191 struct udp_offload
*uoff
)
193 const struct net_offload
*ops
;
194 struct sk_buff
**pp
= NULL
;
195 u8 proto
= NAPI_GRO_CB(skb
)->proto
;
196 const struct net_offload
**offloads
;
198 /* We can clear the encap_mark for FOU as we are essentially doing
199 * one of two possible things. We are either adding an L4 tunnel
200 * header to the outer L3 tunnel header, or we are are simply
201 * treating the GRE tunnel header as though it is a UDP protocol
202 * specific header such as VXLAN or GENEVE.
204 NAPI_GRO_CB(skb
)->encap_mark
= 0;
207 offloads
= NAPI_GRO_CB(skb
)->is_ipv6
? inet6_offloads
: inet_offloads
;
208 ops
= rcu_dereference(offloads
[proto
]);
209 if (!ops
|| !ops
->callbacks
.gro_receive
)
212 pp
= ops
->callbacks
.gro_receive(head
, skb
);
220 static int fou_gro_complete(struct sk_buff
*skb
, int nhoff
,
221 struct udp_offload
*uoff
)
223 const struct net_offload
*ops
;
224 u8 proto
= NAPI_GRO_CB(skb
)->proto
;
226 const struct net_offload
**offloads
;
228 udp_tunnel_gro_complete(skb
, nhoff
);
231 offloads
= NAPI_GRO_CB(skb
)->is_ipv6
? inet6_offloads
: inet_offloads
;
232 ops
= rcu_dereference(offloads
[proto
]);
233 if (WARN_ON(!ops
|| !ops
->callbacks
.gro_complete
))
236 err
= ops
->callbacks
.gro_complete(skb
, nhoff
);
244 static struct guehdr
*gue_gro_remcsum(struct sk_buff
*skb
, unsigned int off
,
245 struct guehdr
*guehdr
, void *data
,
246 size_t hdrlen
, struct gro_remcsum
*grc
,
250 size_t start
= ntohs(pd
[0]);
251 size_t offset
= ntohs(pd
[1]);
253 if (skb
->remcsum_offload
)
256 if (!NAPI_GRO_CB(skb
)->csum_valid
)
259 guehdr
= skb_gro_remcsum_process(skb
, (void *)guehdr
, off
, hdrlen
,
260 start
, offset
, grc
, nopartial
);
262 skb
->remcsum_offload
= 1;
267 static struct sk_buff
**gue_gro_receive(struct sk_buff
**head
,
269 struct udp_offload
*uoff
)
271 const struct net_offload
**offloads
;
272 const struct net_offload
*ops
;
273 struct sk_buff
**pp
= NULL
;
275 struct guehdr
*guehdr
;
276 size_t len
, optlen
, hdrlen
, off
;
280 struct fou
*fou
= container_of(uoff
, struct fou
, udp_offloads
);
281 struct gro_remcsum grc
;
283 skb_gro_remcsum_init(&grc
);
285 off
= skb_gro_offset(skb
);
286 len
= off
+ sizeof(*guehdr
);
288 guehdr
= skb_gro_header_fast(skb
, off
);
289 if (skb_gro_header_hard(skb
, len
)) {
290 guehdr
= skb_gro_header_slow(skb
, len
, off
);
291 if (unlikely(!guehdr
))
295 optlen
= guehdr
->hlen
<< 2;
298 if (skb_gro_header_hard(skb
, len
)) {
299 guehdr
= skb_gro_header_slow(skb
, len
, off
);
300 if (unlikely(!guehdr
))
304 if (unlikely(guehdr
->control
) || guehdr
->version
!= 0 ||
305 validate_gue_flags(guehdr
, optlen
))
308 hdrlen
= sizeof(*guehdr
) + optlen
;
310 /* Adjust NAPI_GRO_CB(skb)->csum to account for guehdr,
311 * this is needed if there is a remote checkcsum offload.
313 skb_gro_postpull_rcsum(skb
, guehdr
, hdrlen
);
317 if (guehdr
->flags
& GUE_FLAG_PRIV
) {
318 __be32 flags
= *(__be32
*)(data
+ doffset
);
320 doffset
+= GUE_LEN_PRIV
;
322 if (flags
& GUE_PFLAG_REMCSUM
) {
323 guehdr
= gue_gro_remcsum(skb
, off
, guehdr
,
324 data
+ doffset
, hdrlen
, &grc
,
326 FOU_F_REMCSUM_NOPARTIAL
));
333 doffset
+= GUE_PLEN_REMCSUM
;
337 skb_gro_pull(skb
, hdrlen
);
339 for (p
= *head
; p
; p
= p
->next
) {
340 const struct guehdr
*guehdr2
;
342 if (!NAPI_GRO_CB(p
)->same_flow
)
345 guehdr2
= (struct guehdr
*)(p
->data
+ off
);
347 /* Compare base GUE header to be equal (covers
348 * hlen, version, proto_ctype, and flags.
350 if (guehdr
->word
!= guehdr2
->word
) {
351 NAPI_GRO_CB(p
)->same_flow
= 0;
355 /* Compare optional fields are the same. */
356 if (guehdr
->hlen
&& memcmp(&guehdr
[1], &guehdr2
[1],
357 guehdr
->hlen
<< 2)) {
358 NAPI_GRO_CB(p
)->same_flow
= 0;
363 /* We can clear the encap_mark for GUE as we are essentially doing
364 * one of two possible things. We are either adding an L4 tunnel
365 * header to the outer L3 tunnel header, or we are are simply
366 * treating the GRE tunnel header as though it is a UDP protocol
367 * specific header such as VXLAN or GENEVE.
369 NAPI_GRO_CB(skb
)->encap_mark
= 0;
372 offloads
= NAPI_GRO_CB(skb
)->is_ipv6
? inet6_offloads
: inet_offloads
;
373 ops
= rcu_dereference(offloads
[guehdr
->proto_ctype
]);
374 if (WARN_ON_ONCE(!ops
|| !ops
->callbacks
.gro_receive
))
377 pp
= ops
->callbacks
.gro_receive(head
, skb
);
383 NAPI_GRO_CB(skb
)->flush
|= flush
;
384 skb_gro_remcsum_cleanup(skb
, &grc
);
389 static int gue_gro_complete(struct sk_buff
*skb
, int nhoff
,
390 struct udp_offload
*uoff
)
392 const struct net_offload
**offloads
;
393 struct guehdr
*guehdr
= (struct guehdr
*)(skb
->data
+ nhoff
);
394 const struct net_offload
*ops
;
395 unsigned int guehlen
;
399 proto
= guehdr
->proto_ctype
;
401 guehlen
= sizeof(*guehdr
) + (guehdr
->hlen
<< 2);
404 offloads
= NAPI_GRO_CB(skb
)->is_ipv6
? inet6_offloads
: inet_offloads
;
405 ops
= rcu_dereference(offloads
[proto
]);
406 if (WARN_ON(!ops
|| !ops
->callbacks
.gro_complete
))
409 err
= ops
->callbacks
.gro_complete(skb
, nhoff
+ guehlen
);
416 static int fou_add_to_port_list(struct net
*net
, struct fou
*fou
)
418 struct fou_net
*fn
= net_generic(net
, fou_net_id
);
421 mutex_lock(&fn
->fou_lock
);
422 list_for_each_entry(fout
, &fn
->fou_list
, list
) {
423 if (fou
->port
== fout
->port
) {
424 mutex_unlock(&fn
->fou_lock
);
429 list_add(&fou
->list
, &fn
->fou_list
);
430 mutex_unlock(&fn
->fou_lock
);
435 static void fou_release(struct fou
*fou
)
437 struct socket
*sock
= fou
->sock
;
438 struct sock
*sk
= sock
->sk
;
440 if (sk
->sk_family
== AF_INET
)
441 udp_del_offload(&fou
->udp_offloads
);
442 list_del(&fou
->list
);
443 udp_tunnel_sock_release(sock
);
448 static int fou_encap_init(struct sock
*sk
, struct fou
*fou
, struct fou_cfg
*cfg
)
450 udp_sk(sk
)->encap_rcv
= fou_udp_recv
;
451 fou
->protocol
= cfg
->protocol
;
452 fou
->udp_offloads
.callbacks
.gro_receive
= fou_gro_receive
;
453 fou
->udp_offloads
.callbacks
.gro_complete
= fou_gro_complete
;
454 fou
->udp_offloads
.port
= cfg
->udp_config
.local_udp_port
;
455 fou
->udp_offloads
.ipproto
= cfg
->protocol
;
460 static int gue_encap_init(struct sock
*sk
, struct fou
*fou
, struct fou_cfg
*cfg
)
462 udp_sk(sk
)->encap_rcv
= gue_udp_recv
;
463 fou
->udp_offloads
.callbacks
.gro_receive
= gue_gro_receive
;
464 fou
->udp_offloads
.callbacks
.gro_complete
= gue_gro_complete
;
465 fou
->udp_offloads
.port
= cfg
->udp_config
.local_udp_port
;
470 static int fou_create(struct net
*net
, struct fou_cfg
*cfg
,
471 struct socket
**sockp
)
473 struct socket
*sock
= NULL
;
474 struct fou
*fou
= NULL
;
478 /* Open UDP socket */
479 err
= udp_sock_create(net
, &cfg
->udp_config
, &sock
);
483 /* Allocate FOU port structure */
484 fou
= kzalloc(sizeof(*fou
), GFP_KERNEL
);
492 fou
->flags
= cfg
->flags
;
493 fou
->port
= cfg
->udp_config
.local_udp_port
;
495 /* Initial for fou type */
497 case FOU_ENCAP_DIRECT
:
498 err
= fou_encap_init(sk
, fou
, cfg
);
503 err
= gue_encap_init(sk
, fou
, cfg
);
512 fou
->type
= cfg
->type
;
514 udp_sk(sk
)->encap_type
= 1;
517 sk
->sk_user_data
= fou
;
520 inet_inc_convert_csum(sk
);
522 sk
->sk_allocation
= GFP_ATOMIC
;
524 if (cfg
->udp_config
.family
== AF_INET
) {
525 err
= udp_add_offload(net
, &fou
->udp_offloads
);
530 err
= fou_add_to_port_list(net
, fou
);
542 udp_tunnel_sock_release(sock
);
547 static int fou_destroy(struct net
*net
, struct fou_cfg
*cfg
)
549 struct fou_net
*fn
= net_generic(net
, fou_net_id
);
550 __be16 port
= cfg
->udp_config
.local_udp_port
;
554 mutex_lock(&fn
->fou_lock
);
555 list_for_each_entry(fou
, &fn
->fou_list
, list
) {
556 if (fou
->port
== port
) {
562 mutex_unlock(&fn
->fou_lock
);
567 static struct genl_family fou_nl_family
= {
568 .id
= GENL_ID_GENERATE
,
570 .name
= FOU_GENL_NAME
,
571 .version
= FOU_GENL_VERSION
,
572 .maxattr
= FOU_ATTR_MAX
,
576 static struct nla_policy fou_nl_policy
[FOU_ATTR_MAX
+ 1] = {
577 [FOU_ATTR_PORT
] = { .type
= NLA_U16
, },
578 [FOU_ATTR_AF
] = { .type
= NLA_U8
, },
579 [FOU_ATTR_IPPROTO
] = { .type
= NLA_U8
, },
580 [FOU_ATTR_TYPE
] = { .type
= NLA_U8
, },
581 [FOU_ATTR_REMCSUM_NOPARTIAL
] = { .type
= NLA_FLAG
, },
584 static int parse_nl_config(struct genl_info
*info
,
587 memset(cfg
, 0, sizeof(*cfg
));
589 cfg
->udp_config
.family
= AF_INET
;
591 if (info
->attrs
[FOU_ATTR_AF
]) {
592 u8 family
= nla_get_u8(info
->attrs
[FOU_ATTR_AF
]);
594 if (family
!= AF_INET
)
597 cfg
->udp_config
.family
= family
;
600 if (info
->attrs
[FOU_ATTR_PORT
]) {
601 __be16 port
= nla_get_be16(info
->attrs
[FOU_ATTR_PORT
]);
603 cfg
->udp_config
.local_udp_port
= port
;
606 if (info
->attrs
[FOU_ATTR_IPPROTO
])
607 cfg
->protocol
= nla_get_u8(info
->attrs
[FOU_ATTR_IPPROTO
]);
609 if (info
->attrs
[FOU_ATTR_TYPE
])
610 cfg
->type
= nla_get_u8(info
->attrs
[FOU_ATTR_TYPE
]);
612 if (info
->attrs
[FOU_ATTR_REMCSUM_NOPARTIAL
])
613 cfg
->flags
|= FOU_F_REMCSUM_NOPARTIAL
;
618 static int fou_nl_cmd_add_port(struct sk_buff
*skb
, struct genl_info
*info
)
620 struct net
*net
= genl_info_net(info
);
624 err
= parse_nl_config(info
, &cfg
);
628 return fou_create(net
, &cfg
, NULL
);
631 static int fou_nl_cmd_rm_port(struct sk_buff
*skb
, struct genl_info
*info
)
633 struct net
*net
= genl_info_net(info
);
637 err
= parse_nl_config(info
, &cfg
);
641 return fou_destroy(net
, &cfg
);
644 static int fou_fill_info(struct fou
*fou
, struct sk_buff
*msg
)
646 if (nla_put_u8(msg
, FOU_ATTR_AF
, fou
->sock
->sk
->sk_family
) ||
647 nla_put_be16(msg
, FOU_ATTR_PORT
, fou
->port
) ||
648 nla_put_u8(msg
, FOU_ATTR_IPPROTO
, fou
->protocol
) ||
649 nla_put_u8(msg
, FOU_ATTR_TYPE
, fou
->type
))
652 if (fou
->flags
& FOU_F_REMCSUM_NOPARTIAL
)
653 if (nla_put_flag(msg
, FOU_ATTR_REMCSUM_NOPARTIAL
))
658 static int fou_dump_info(struct fou
*fou
, u32 portid
, u32 seq
,
659 u32 flags
, struct sk_buff
*skb
, u8 cmd
)
663 hdr
= genlmsg_put(skb
, portid
, seq
, &fou_nl_family
, flags
, cmd
);
667 if (fou_fill_info(fou
, skb
) < 0)
668 goto nla_put_failure
;
670 genlmsg_end(skb
, hdr
);
674 genlmsg_cancel(skb
, hdr
);
678 static int fou_nl_cmd_get_port(struct sk_buff
*skb
, struct genl_info
*info
)
680 struct net
*net
= genl_info_net(info
);
681 struct fou_net
*fn
= net_generic(net
, fou_net_id
);
688 ret
= parse_nl_config(info
, &cfg
);
691 port
= cfg
.udp_config
.local_udp_port
;
695 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
700 mutex_lock(&fn
->fou_lock
);
701 list_for_each_entry(fout
, &fn
->fou_list
, list
) {
702 if (port
== fout
->port
) {
703 ret
= fou_dump_info(fout
, info
->snd_portid
,
704 info
->snd_seq
, 0, msg
,
709 mutex_unlock(&fn
->fou_lock
);
713 return genlmsg_reply(msg
, info
);
720 static int fou_nl_dump(struct sk_buff
*skb
, struct netlink_callback
*cb
)
722 struct net
*net
= sock_net(skb
->sk
);
723 struct fou_net
*fn
= net_generic(net
, fou_net_id
);
727 mutex_lock(&fn
->fou_lock
);
728 list_for_each_entry(fout
, &fn
->fou_list
, list
) {
729 if (idx
++ < cb
->args
[0])
731 ret
= fou_dump_info(fout
, NETLINK_CB(cb
->skb
).portid
,
732 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
737 mutex_unlock(&fn
->fou_lock
);
743 static const struct genl_ops fou_nl_ops
[] = {
746 .doit
= fou_nl_cmd_add_port
,
747 .policy
= fou_nl_policy
,
748 .flags
= GENL_ADMIN_PERM
,
752 .doit
= fou_nl_cmd_rm_port
,
753 .policy
= fou_nl_policy
,
754 .flags
= GENL_ADMIN_PERM
,
758 .doit
= fou_nl_cmd_get_port
,
759 .dumpit
= fou_nl_dump
,
760 .policy
= fou_nl_policy
,
764 size_t fou_encap_hlen(struct ip_tunnel_encap
*e
)
766 return sizeof(struct udphdr
);
768 EXPORT_SYMBOL(fou_encap_hlen
);
770 size_t gue_encap_hlen(struct ip_tunnel_encap
*e
)
773 bool need_priv
= false;
775 len
= sizeof(struct udphdr
) + sizeof(struct guehdr
);
777 if (e
->flags
& TUNNEL_ENCAP_FLAG_REMCSUM
) {
778 len
+= GUE_PLEN_REMCSUM
;
782 len
+= need_priv
? GUE_LEN_PRIV
: 0;
786 EXPORT_SYMBOL(gue_encap_hlen
);
788 static void fou_build_udp(struct sk_buff
*skb
, struct ip_tunnel_encap
*e
,
789 struct flowi4
*fl4
, u8
*protocol
, __be16 sport
)
793 skb_push(skb
, sizeof(struct udphdr
));
794 skb_reset_transport_header(skb
);
800 uh
->len
= htons(skb
->len
);
801 udp_set_csum(!(e
->flags
& TUNNEL_ENCAP_FLAG_CSUM
), skb
,
802 fl4
->saddr
, fl4
->daddr
, skb
->len
);
804 *protocol
= IPPROTO_UDP
;
807 int fou_build_header(struct sk_buff
*skb
, struct ip_tunnel_encap
*e
,
808 u8
*protocol
, struct flowi4
*fl4
)
810 int type
= e
->flags
& TUNNEL_ENCAP_FLAG_CSUM
? SKB_GSO_UDP_TUNNEL_CSUM
:
814 skb
= iptunnel_handle_offloads(skb
, type
);
819 sport
= e
->sport
? : udp_flow_src_port(dev_net(skb
->dev
),
821 fou_build_udp(skb
, e
, fl4
, protocol
, sport
);
825 EXPORT_SYMBOL(fou_build_header
);
827 int gue_build_header(struct sk_buff
*skb
, struct ip_tunnel_encap
*e
,
828 u8
*protocol
, struct flowi4
*fl4
)
830 int type
= e
->flags
& TUNNEL_ENCAP_FLAG_CSUM
? SKB_GSO_UDP_TUNNEL_CSUM
:
832 struct guehdr
*guehdr
;
833 size_t hdrlen
, optlen
= 0;
836 bool need_priv
= false;
838 if ((e
->flags
& TUNNEL_ENCAP_FLAG_REMCSUM
) &&
839 skb
->ip_summed
== CHECKSUM_PARTIAL
) {
840 optlen
+= GUE_PLEN_REMCSUM
;
841 type
|= SKB_GSO_TUNNEL_REMCSUM
;
845 optlen
+= need_priv
? GUE_LEN_PRIV
: 0;
847 skb
= iptunnel_handle_offloads(skb
, type
);
852 /* Get source port (based on flow hash) before skb_push */
853 sport
= e
->sport
? : udp_flow_src_port(dev_net(skb
->dev
),
856 hdrlen
= sizeof(struct guehdr
) + optlen
;
858 skb_push(skb
, hdrlen
);
860 guehdr
= (struct guehdr
*)skb
->data
;
864 guehdr
->hlen
= optlen
>> 2;
866 guehdr
->proto_ctype
= *protocol
;
871 __be32
*flags
= data
;
873 guehdr
->flags
|= GUE_FLAG_PRIV
;
875 data
+= GUE_LEN_PRIV
;
877 if (type
& SKB_GSO_TUNNEL_REMCSUM
) {
878 u16 csum_start
= skb_checksum_start_offset(skb
);
881 if (csum_start
< hdrlen
)
884 csum_start
-= hdrlen
;
885 pd
[0] = htons(csum_start
);
886 pd
[1] = htons(csum_start
+ skb
->csum_offset
);
888 if (!skb_is_gso(skb
)) {
889 skb
->ip_summed
= CHECKSUM_NONE
;
890 skb
->encapsulation
= 0;
893 *flags
|= GUE_PFLAG_REMCSUM
;
894 data
+= GUE_PLEN_REMCSUM
;
899 fou_build_udp(skb
, e
, fl4
, protocol
, sport
);
903 EXPORT_SYMBOL(gue_build_header
);
905 #ifdef CONFIG_NET_FOU_IP_TUNNELS
907 static const struct ip_tunnel_encap_ops fou_iptun_ops
= {
908 .encap_hlen
= fou_encap_hlen
,
909 .build_header
= fou_build_header
,
912 static const struct ip_tunnel_encap_ops gue_iptun_ops
= {
913 .encap_hlen
= gue_encap_hlen
,
914 .build_header
= gue_build_header
,
917 static int ip_tunnel_encap_add_fou_ops(void)
921 ret
= ip_tunnel_encap_add_ops(&fou_iptun_ops
, TUNNEL_ENCAP_FOU
);
923 pr_err("can't add fou ops\n");
927 ret
= ip_tunnel_encap_add_ops(&gue_iptun_ops
, TUNNEL_ENCAP_GUE
);
929 pr_err("can't add gue ops\n");
930 ip_tunnel_encap_del_ops(&fou_iptun_ops
, TUNNEL_ENCAP_FOU
);
937 static void ip_tunnel_encap_del_fou_ops(void)
939 ip_tunnel_encap_del_ops(&fou_iptun_ops
, TUNNEL_ENCAP_FOU
);
940 ip_tunnel_encap_del_ops(&gue_iptun_ops
, TUNNEL_ENCAP_GUE
);
945 static int ip_tunnel_encap_add_fou_ops(void)
950 static void ip_tunnel_encap_del_fou_ops(void)
956 static __net_init
int fou_init_net(struct net
*net
)
958 struct fou_net
*fn
= net_generic(net
, fou_net_id
);
960 INIT_LIST_HEAD(&fn
->fou_list
);
961 mutex_init(&fn
->fou_lock
);
965 static __net_exit
void fou_exit_net(struct net
*net
)
967 struct fou_net
*fn
= net_generic(net
, fou_net_id
);
968 struct fou
*fou
, *next
;
970 /* Close all the FOU sockets */
971 mutex_lock(&fn
->fou_lock
);
972 list_for_each_entry_safe(fou
, next
, &fn
->fou_list
, list
)
974 mutex_unlock(&fn
->fou_lock
);
977 static struct pernet_operations fou_net_ops
= {
978 .init
= fou_init_net
,
979 .exit
= fou_exit_net
,
981 .size
= sizeof(struct fou_net
),
984 static int __init
fou_init(void)
988 ret
= register_pernet_device(&fou_net_ops
);
992 ret
= genl_register_family_with_ops(&fou_nl_family
,
997 ret
= ip_tunnel_encap_add_fou_ops();
1001 genl_unregister_family(&fou_nl_family
);
1003 unregister_pernet_device(&fou_net_ops
);
1008 static void __exit
fou_fini(void)
1010 ip_tunnel_encap_del_fou_ops();
1011 genl_unregister_family(&fou_nl_family
);
1012 unregister_pernet_device(&fou_net_ops
);
1015 module_init(fou_init
);
1016 module_exit(fou_fini
);
1017 MODULE_AUTHOR("Tom Herbert <therbert@google.com>");
1018 MODULE_LICENSE("GPL");