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 void 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
);
64 static int fou_udp_recv(struct sock
*sk
, struct sk_buff
*skb
)
66 struct fou
*fou
= fou_from_sock(sk
);
71 fou_recv_pull(skb
, sizeof(struct udphdr
));
73 return -fou
->protocol
;
76 static struct guehdr
*gue_remcsum(struct sk_buff
*skb
, struct guehdr
*guehdr
,
77 void *data
, size_t hdrlen
, u8 ipproto
,
81 size_t start
= ntohs(pd
[0]);
82 size_t offset
= ntohs(pd
[1]);
83 size_t plen
= sizeof(struct udphdr
) + hdrlen
+
84 max_t(size_t, offset
+ sizeof(u16
), start
);
86 if (skb
->remcsum_offload
)
89 if (!pskb_may_pull(skb
, plen
))
91 guehdr
= (struct guehdr
*)&udp_hdr(skb
)[1];
93 skb_remcsum_process(skb
, (void *)guehdr
+ hdrlen
,
94 start
, offset
, nopartial
);
99 static int gue_control_message(struct sk_buff
*skb
, struct guehdr
*guehdr
)
106 static int gue_udp_recv(struct sock
*sk
, struct sk_buff
*skb
)
108 struct fou
*fou
= fou_from_sock(sk
);
109 size_t len
, optlen
, hdrlen
;
110 struct guehdr
*guehdr
;
117 len
= sizeof(struct udphdr
) + sizeof(struct guehdr
);
118 if (!pskb_may_pull(skb
, len
))
121 guehdr
= (struct guehdr
*)&udp_hdr(skb
)[1];
123 optlen
= guehdr
->hlen
<< 2;
126 if (!pskb_may_pull(skb
, len
))
129 /* guehdr may change after pull */
130 guehdr
= (struct guehdr
*)&udp_hdr(skb
)[1];
132 hdrlen
= sizeof(struct guehdr
) + optlen
;
134 if (guehdr
->version
!= 0 || validate_gue_flags(guehdr
, optlen
))
137 hdrlen
= sizeof(struct guehdr
) + optlen
;
139 ip_hdr(skb
)->tot_len
= htons(ntohs(ip_hdr(skb
)->tot_len
) - len
);
141 /* Pull csum through the guehdr now . This can be used if
142 * there is a remote checksum offload.
144 skb_postpull_rcsum(skb
, udp_hdr(skb
), len
);
148 if (guehdr
->flags
& GUE_FLAG_PRIV
) {
149 __be32 flags
= *(__be32
*)(data
+ doffset
);
151 doffset
+= GUE_LEN_PRIV
;
153 if (flags
& GUE_PFLAG_REMCSUM
) {
154 guehdr
= gue_remcsum(skb
, guehdr
, data
+ doffset
,
155 hdrlen
, guehdr
->proto_ctype
,
157 FOU_F_REMCSUM_NOPARTIAL
));
163 doffset
+= GUE_PLEN_REMCSUM
;
167 if (unlikely(guehdr
->control
))
168 return gue_control_message(skb
, guehdr
);
170 __skb_pull(skb
, sizeof(struct udphdr
) + hdrlen
);
171 skb_reset_transport_header(skb
);
173 return -guehdr
->proto_ctype
;
180 static struct sk_buff
**fou_gro_receive(struct sk_buff
**head
,
182 struct udp_offload
*uoff
)
184 const struct net_offload
*ops
;
185 struct sk_buff
**pp
= NULL
;
186 u8 proto
= NAPI_GRO_CB(skb
)->proto
;
187 const struct net_offload
**offloads
;
190 offloads
= NAPI_GRO_CB(skb
)->is_ipv6
? inet6_offloads
: inet_offloads
;
191 ops
= rcu_dereference(offloads
[proto
]);
192 if (!ops
|| !ops
->callbacks
.gro_receive
)
195 pp
= ops
->callbacks
.gro_receive(head
, skb
);
203 static int fou_gro_complete(struct sk_buff
*skb
, int nhoff
,
204 struct udp_offload
*uoff
)
206 const struct net_offload
*ops
;
207 u8 proto
= NAPI_GRO_CB(skb
)->proto
;
209 const struct net_offload
**offloads
;
211 udp_tunnel_gro_complete(skb
, nhoff
);
214 offloads
= NAPI_GRO_CB(skb
)->is_ipv6
? inet6_offloads
: inet_offloads
;
215 ops
= rcu_dereference(offloads
[proto
]);
216 if (WARN_ON(!ops
|| !ops
->callbacks
.gro_complete
))
219 err
= ops
->callbacks
.gro_complete(skb
, nhoff
);
227 static struct guehdr
*gue_gro_remcsum(struct sk_buff
*skb
, unsigned int off
,
228 struct guehdr
*guehdr
, void *data
,
229 size_t hdrlen
, struct gro_remcsum
*grc
,
233 size_t start
= ntohs(pd
[0]);
234 size_t offset
= ntohs(pd
[1]);
236 if (skb
->remcsum_offload
)
239 if (!NAPI_GRO_CB(skb
)->csum_valid
)
242 guehdr
= skb_gro_remcsum_process(skb
, (void *)guehdr
, off
, hdrlen
,
243 start
, offset
, grc
, nopartial
);
245 skb
->remcsum_offload
= 1;
250 static struct sk_buff
**gue_gro_receive(struct sk_buff
**head
,
252 struct udp_offload
*uoff
)
254 const struct net_offload
**offloads
;
255 const struct net_offload
*ops
;
256 struct sk_buff
**pp
= NULL
;
258 struct guehdr
*guehdr
;
259 size_t len
, optlen
, hdrlen
, off
;
263 struct fou
*fou
= container_of(uoff
, struct fou
, udp_offloads
);
264 struct gro_remcsum grc
;
266 skb_gro_remcsum_init(&grc
);
268 off
= skb_gro_offset(skb
);
269 len
= off
+ sizeof(*guehdr
);
271 guehdr
= skb_gro_header_fast(skb
, off
);
272 if (skb_gro_header_hard(skb
, len
)) {
273 guehdr
= skb_gro_header_slow(skb
, len
, off
);
274 if (unlikely(!guehdr
))
278 optlen
= guehdr
->hlen
<< 2;
281 if (skb_gro_header_hard(skb
, len
)) {
282 guehdr
= skb_gro_header_slow(skb
, len
, off
);
283 if (unlikely(!guehdr
))
287 if (unlikely(guehdr
->control
) || guehdr
->version
!= 0 ||
288 validate_gue_flags(guehdr
, optlen
))
291 hdrlen
= sizeof(*guehdr
) + optlen
;
293 /* Adjust NAPI_GRO_CB(skb)->csum to account for guehdr,
294 * this is needed if there is a remote checkcsum offload.
296 skb_gro_postpull_rcsum(skb
, guehdr
, hdrlen
);
300 if (guehdr
->flags
& GUE_FLAG_PRIV
) {
301 __be32 flags
= *(__be32
*)(data
+ doffset
);
303 doffset
+= GUE_LEN_PRIV
;
305 if (flags
& GUE_PFLAG_REMCSUM
) {
306 guehdr
= gue_gro_remcsum(skb
, off
, guehdr
,
307 data
+ doffset
, hdrlen
, &grc
,
309 FOU_F_REMCSUM_NOPARTIAL
));
316 doffset
+= GUE_PLEN_REMCSUM
;
320 skb_gro_pull(skb
, hdrlen
);
324 for (p
= *head
; p
; p
= p
->next
) {
325 const struct guehdr
*guehdr2
;
327 if (!NAPI_GRO_CB(p
)->same_flow
)
330 guehdr2
= (struct guehdr
*)(p
->data
+ off
);
332 /* Compare base GUE header to be equal (covers
333 * hlen, version, proto_ctype, and flags.
335 if (guehdr
->word
!= guehdr2
->word
) {
336 NAPI_GRO_CB(p
)->same_flow
= 0;
340 /* Compare optional fields are the same. */
341 if (guehdr
->hlen
&& memcmp(&guehdr
[1], &guehdr2
[1],
342 guehdr
->hlen
<< 2)) {
343 NAPI_GRO_CB(p
)->same_flow
= 0;
349 offloads
= NAPI_GRO_CB(skb
)->is_ipv6
? inet6_offloads
: inet_offloads
;
350 ops
= rcu_dereference(offloads
[guehdr
->proto_ctype
]);
351 if (WARN_ON_ONCE(!ops
|| !ops
->callbacks
.gro_receive
))
354 pp
= ops
->callbacks
.gro_receive(head
, skb
);
359 NAPI_GRO_CB(skb
)->flush
|= flush
;
360 skb_gro_remcsum_cleanup(skb
, &grc
);
365 static int gue_gro_complete(struct sk_buff
*skb
, int nhoff
,
366 struct udp_offload
*uoff
)
368 const struct net_offload
**offloads
;
369 struct guehdr
*guehdr
= (struct guehdr
*)(skb
->data
+ nhoff
);
370 const struct net_offload
*ops
;
371 unsigned int guehlen
;
375 proto
= guehdr
->proto_ctype
;
377 guehlen
= sizeof(*guehdr
) + (guehdr
->hlen
<< 2);
380 offloads
= NAPI_GRO_CB(skb
)->is_ipv6
? inet6_offloads
: inet_offloads
;
381 ops
= rcu_dereference(offloads
[proto
]);
382 if (WARN_ON(!ops
|| !ops
->callbacks
.gro_complete
))
385 err
= ops
->callbacks
.gro_complete(skb
, nhoff
+ guehlen
);
392 static int fou_add_to_port_list(struct net
*net
, struct fou
*fou
)
394 struct fou_net
*fn
= net_generic(net
, fou_net_id
);
397 mutex_lock(&fn
->fou_lock
);
398 list_for_each_entry(fout
, &fn
->fou_list
, list
) {
399 if (fou
->port
== fout
->port
) {
400 mutex_unlock(&fn
->fou_lock
);
405 list_add(&fou
->list
, &fn
->fou_list
);
406 mutex_unlock(&fn
->fou_lock
);
411 static void fou_release(struct fou
*fou
)
413 struct socket
*sock
= fou
->sock
;
414 struct sock
*sk
= sock
->sk
;
416 if (sk
->sk_family
== AF_INET
)
417 udp_del_offload(&fou
->udp_offloads
);
418 list_del(&fou
->list
);
419 udp_tunnel_sock_release(sock
);
424 static int fou_encap_init(struct sock
*sk
, struct fou
*fou
, struct fou_cfg
*cfg
)
426 udp_sk(sk
)->encap_rcv
= fou_udp_recv
;
427 fou
->protocol
= cfg
->protocol
;
428 fou
->udp_offloads
.callbacks
.gro_receive
= fou_gro_receive
;
429 fou
->udp_offloads
.callbacks
.gro_complete
= fou_gro_complete
;
430 fou
->udp_offloads
.port
= cfg
->udp_config
.local_udp_port
;
431 fou
->udp_offloads
.ipproto
= cfg
->protocol
;
436 static int gue_encap_init(struct sock
*sk
, struct fou
*fou
, struct fou_cfg
*cfg
)
438 udp_sk(sk
)->encap_rcv
= gue_udp_recv
;
439 fou
->udp_offloads
.callbacks
.gro_receive
= gue_gro_receive
;
440 fou
->udp_offloads
.callbacks
.gro_complete
= gue_gro_complete
;
441 fou
->udp_offloads
.port
= cfg
->udp_config
.local_udp_port
;
446 static int fou_create(struct net
*net
, struct fou_cfg
*cfg
,
447 struct socket
**sockp
)
449 struct socket
*sock
= NULL
;
450 struct fou
*fou
= NULL
;
454 /* Open UDP socket */
455 err
= udp_sock_create(net
, &cfg
->udp_config
, &sock
);
459 /* Allocate FOU port structure */
460 fou
= kzalloc(sizeof(*fou
), GFP_KERNEL
);
468 fou
->flags
= cfg
->flags
;
469 fou
->port
= cfg
->udp_config
.local_udp_port
;
471 /* Initial for fou type */
473 case FOU_ENCAP_DIRECT
:
474 err
= fou_encap_init(sk
, fou
, cfg
);
479 err
= gue_encap_init(sk
, fou
, cfg
);
488 fou
->type
= cfg
->type
;
490 udp_sk(sk
)->encap_type
= 1;
493 sk
->sk_user_data
= fou
;
496 inet_inc_convert_csum(sk
);
498 sk
->sk_allocation
= GFP_ATOMIC
;
500 if (cfg
->udp_config
.family
== AF_INET
) {
501 err
= udp_add_offload(&fou
->udp_offloads
);
506 err
= fou_add_to_port_list(net
, fou
);
518 udp_tunnel_sock_release(sock
);
523 static int fou_destroy(struct net
*net
, struct fou_cfg
*cfg
)
525 struct fou_net
*fn
= net_generic(net
, fou_net_id
);
526 __be16 port
= cfg
->udp_config
.local_udp_port
;
530 mutex_lock(&fn
->fou_lock
);
531 list_for_each_entry(fou
, &fn
->fou_list
, list
) {
532 if (fou
->port
== port
) {
538 mutex_unlock(&fn
->fou_lock
);
543 static struct genl_family fou_nl_family
= {
544 .id
= GENL_ID_GENERATE
,
546 .name
= FOU_GENL_NAME
,
547 .version
= FOU_GENL_VERSION
,
548 .maxattr
= FOU_ATTR_MAX
,
552 static struct nla_policy fou_nl_policy
[FOU_ATTR_MAX
+ 1] = {
553 [FOU_ATTR_PORT
] = { .type
= NLA_U16
, },
554 [FOU_ATTR_AF
] = { .type
= NLA_U8
, },
555 [FOU_ATTR_IPPROTO
] = { .type
= NLA_U8
, },
556 [FOU_ATTR_TYPE
] = { .type
= NLA_U8
, },
557 [FOU_ATTR_REMCSUM_NOPARTIAL
] = { .type
= NLA_FLAG
, },
560 static int parse_nl_config(struct genl_info
*info
,
563 memset(cfg
, 0, sizeof(*cfg
));
565 cfg
->udp_config
.family
= AF_INET
;
567 if (info
->attrs
[FOU_ATTR_AF
]) {
568 u8 family
= nla_get_u8(info
->attrs
[FOU_ATTR_AF
]);
570 if (family
!= AF_INET
)
573 cfg
->udp_config
.family
= family
;
576 if (info
->attrs
[FOU_ATTR_PORT
]) {
577 __be16 port
= nla_get_be16(info
->attrs
[FOU_ATTR_PORT
]);
579 cfg
->udp_config
.local_udp_port
= port
;
582 if (info
->attrs
[FOU_ATTR_IPPROTO
])
583 cfg
->protocol
= nla_get_u8(info
->attrs
[FOU_ATTR_IPPROTO
]);
585 if (info
->attrs
[FOU_ATTR_TYPE
])
586 cfg
->type
= nla_get_u8(info
->attrs
[FOU_ATTR_TYPE
]);
588 if (info
->attrs
[FOU_ATTR_REMCSUM_NOPARTIAL
])
589 cfg
->flags
|= FOU_F_REMCSUM_NOPARTIAL
;
594 static int fou_nl_cmd_add_port(struct sk_buff
*skb
, struct genl_info
*info
)
596 struct net
*net
= genl_info_net(info
);
600 err
= parse_nl_config(info
, &cfg
);
604 return fou_create(net
, &cfg
, NULL
);
607 static int fou_nl_cmd_rm_port(struct sk_buff
*skb
, struct genl_info
*info
)
609 struct net
*net
= genl_info_net(info
);
613 err
= parse_nl_config(info
, &cfg
);
617 return fou_destroy(net
, &cfg
);
620 static int fou_fill_info(struct fou
*fou
, struct sk_buff
*msg
)
622 if (nla_put_u8(msg
, FOU_ATTR_AF
, fou
->sock
->sk
->sk_family
) ||
623 nla_put_be16(msg
, FOU_ATTR_PORT
, fou
->port
) ||
624 nla_put_u8(msg
, FOU_ATTR_IPPROTO
, fou
->protocol
) ||
625 nla_put_u8(msg
, FOU_ATTR_TYPE
, fou
->type
))
628 if (fou
->flags
& FOU_F_REMCSUM_NOPARTIAL
)
629 if (nla_put_flag(msg
, FOU_ATTR_REMCSUM_NOPARTIAL
))
634 static int fou_dump_info(struct fou
*fou
, u32 portid
, u32 seq
,
635 u32 flags
, struct sk_buff
*skb
, u8 cmd
)
639 hdr
= genlmsg_put(skb
, portid
, seq
, &fou_nl_family
, flags
, cmd
);
643 if (fou_fill_info(fou
, skb
) < 0)
644 goto nla_put_failure
;
646 genlmsg_end(skb
, hdr
);
650 genlmsg_cancel(skb
, hdr
);
654 static int fou_nl_cmd_get_port(struct sk_buff
*skb
, struct genl_info
*info
)
656 struct net
*net
= genl_info_net(info
);
657 struct fou_net
*fn
= net_generic(net
, fou_net_id
);
664 ret
= parse_nl_config(info
, &cfg
);
667 port
= cfg
.udp_config
.local_udp_port
;
671 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
676 mutex_lock(&fn
->fou_lock
);
677 list_for_each_entry(fout
, &fn
->fou_list
, list
) {
678 if (port
== fout
->port
) {
679 ret
= fou_dump_info(fout
, info
->snd_portid
,
680 info
->snd_seq
, 0, msg
,
685 mutex_unlock(&fn
->fou_lock
);
689 return genlmsg_reply(msg
, info
);
696 static int fou_nl_dump(struct sk_buff
*skb
, struct netlink_callback
*cb
)
698 struct net
*net
= sock_net(skb
->sk
);
699 struct fou_net
*fn
= net_generic(net
, fou_net_id
);
703 mutex_lock(&fn
->fou_lock
);
704 list_for_each_entry(fout
, &fn
->fou_list
, list
) {
705 if (idx
++ < cb
->args
[0])
707 ret
= fou_dump_info(fout
, NETLINK_CB(cb
->skb
).portid
,
708 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
713 mutex_unlock(&fn
->fou_lock
);
719 static const struct genl_ops fou_nl_ops
[] = {
722 .doit
= fou_nl_cmd_add_port
,
723 .policy
= fou_nl_policy
,
724 .flags
= GENL_ADMIN_PERM
,
728 .doit
= fou_nl_cmd_rm_port
,
729 .policy
= fou_nl_policy
,
730 .flags
= GENL_ADMIN_PERM
,
734 .doit
= fou_nl_cmd_get_port
,
735 .dumpit
= fou_nl_dump
,
736 .policy
= fou_nl_policy
,
740 size_t fou_encap_hlen(struct ip_tunnel_encap
*e
)
742 return sizeof(struct udphdr
);
744 EXPORT_SYMBOL(fou_encap_hlen
);
746 size_t gue_encap_hlen(struct ip_tunnel_encap
*e
)
749 bool need_priv
= false;
751 len
= sizeof(struct udphdr
) + sizeof(struct guehdr
);
753 if (e
->flags
& TUNNEL_ENCAP_FLAG_REMCSUM
) {
754 len
+= GUE_PLEN_REMCSUM
;
758 len
+= need_priv
? GUE_LEN_PRIV
: 0;
762 EXPORT_SYMBOL(gue_encap_hlen
);
764 static void fou_build_udp(struct sk_buff
*skb
, struct ip_tunnel_encap
*e
,
765 struct flowi4
*fl4
, u8
*protocol
, __be16 sport
)
769 skb_push(skb
, sizeof(struct udphdr
));
770 skb_reset_transport_header(skb
);
776 uh
->len
= htons(skb
->len
);
778 udp_set_csum(!(e
->flags
& TUNNEL_ENCAP_FLAG_CSUM
), skb
,
779 fl4
->saddr
, fl4
->daddr
, skb
->len
);
781 *protocol
= IPPROTO_UDP
;
784 int fou_build_header(struct sk_buff
*skb
, struct ip_tunnel_encap
*e
,
785 u8
*protocol
, struct flowi4
*fl4
)
787 bool csum
= !!(e
->flags
& TUNNEL_ENCAP_FLAG_CSUM
);
788 int type
= csum
? SKB_GSO_UDP_TUNNEL_CSUM
: SKB_GSO_UDP_TUNNEL
;
791 skb
= iptunnel_handle_offloads(skb
, csum
, type
);
796 sport
= e
->sport
? : udp_flow_src_port(dev_net(skb
->dev
),
798 fou_build_udp(skb
, e
, fl4
, protocol
, sport
);
802 EXPORT_SYMBOL(fou_build_header
);
804 int gue_build_header(struct sk_buff
*skb
, struct ip_tunnel_encap
*e
,
805 u8
*protocol
, struct flowi4
*fl4
)
807 bool csum
= !!(e
->flags
& TUNNEL_ENCAP_FLAG_CSUM
);
808 int type
= csum
? SKB_GSO_UDP_TUNNEL_CSUM
: SKB_GSO_UDP_TUNNEL
;
809 struct guehdr
*guehdr
;
810 size_t hdrlen
, optlen
= 0;
813 bool need_priv
= false;
815 if ((e
->flags
& TUNNEL_ENCAP_FLAG_REMCSUM
) &&
816 skb
->ip_summed
== CHECKSUM_PARTIAL
) {
818 optlen
+= GUE_PLEN_REMCSUM
;
819 type
|= SKB_GSO_TUNNEL_REMCSUM
;
823 optlen
+= need_priv
? GUE_LEN_PRIV
: 0;
825 skb
= iptunnel_handle_offloads(skb
, csum
, type
);
830 /* Get source port (based on flow hash) before skb_push */
831 sport
= e
->sport
? : udp_flow_src_port(dev_net(skb
->dev
),
834 hdrlen
= sizeof(struct guehdr
) + optlen
;
836 skb_push(skb
, hdrlen
);
838 guehdr
= (struct guehdr
*)skb
->data
;
842 guehdr
->hlen
= optlen
>> 2;
844 guehdr
->proto_ctype
= *protocol
;
849 __be32
*flags
= data
;
851 guehdr
->flags
|= GUE_FLAG_PRIV
;
853 data
+= GUE_LEN_PRIV
;
855 if (type
& SKB_GSO_TUNNEL_REMCSUM
) {
856 u16 csum_start
= skb_checksum_start_offset(skb
);
859 if (csum_start
< hdrlen
)
862 csum_start
-= hdrlen
;
863 pd
[0] = htons(csum_start
);
864 pd
[1] = htons(csum_start
+ skb
->csum_offset
);
866 if (!skb_is_gso(skb
)) {
867 skb
->ip_summed
= CHECKSUM_NONE
;
868 skb
->encapsulation
= 0;
871 *flags
|= GUE_PFLAG_REMCSUM
;
872 data
+= GUE_PLEN_REMCSUM
;
877 fou_build_udp(skb
, e
, fl4
, protocol
, sport
);
881 EXPORT_SYMBOL(gue_build_header
);
883 #ifdef CONFIG_NET_FOU_IP_TUNNELS
885 static const struct ip_tunnel_encap_ops fou_iptun_ops
= {
886 .encap_hlen
= fou_encap_hlen
,
887 .build_header
= fou_build_header
,
890 static const struct ip_tunnel_encap_ops gue_iptun_ops
= {
891 .encap_hlen
= gue_encap_hlen
,
892 .build_header
= gue_build_header
,
895 static int ip_tunnel_encap_add_fou_ops(void)
899 ret
= ip_tunnel_encap_add_ops(&fou_iptun_ops
, TUNNEL_ENCAP_FOU
);
901 pr_err("can't add fou ops\n");
905 ret
= ip_tunnel_encap_add_ops(&gue_iptun_ops
, TUNNEL_ENCAP_GUE
);
907 pr_err("can't add gue ops\n");
908 ip_tunnel_encap_del_ops(&fou_iptun_ops
, TUNNEL_ENCAP_FOU
);
915 static void ip_tunnel_encap_del_fou_ops(void)
917 ip_tunnel_encap_del_ops(&fou_iptun_ops
, TUNNEL_ENCAP_FOU
);
918 ip_tunnel_encap_del_ops(&gue_iptun_ops
, TUNNEL_ENCAP_GUE
);
923 static int ip_tunnel_encap_add_fou_ops(void)
928 static void ip_tunnel_encap_del_fou_ops(void)
934 static __net_init
int fou_init_net(struct net
*net
)
936 struct fou_net
*fn
= net_generic(net
, fou_net_id
);
938 INIT_LIST_HEAD(&fn
->fou_list
);
939 mutex_init(&fn
->fou_lock
);
943 static __net_exit
void fou_exit_net(struct net
*net
)
945 struct fou_net
*fn
= net_generic(net
, fou_net_id
);
946 struct fou
*fou
, *next
;
948 /* Close all the FOU sockets */
949 mutex_lock(&fn
->fou_lock
);
950 list_for_each_entry_safe(fou
, next
, &fn
->fou_list
, list
)
952 mutex_unlock(&fn
->fou_lock
);
955 static struct pernet_operations fou_net_ops
= {
956 .init
= fou_init_net
,
957 .exit
= fou_exit_net
,
959 .size
= sizeof(struct fou_net
),
962 static int __init
fou_init(void)
966 ret
= register_pernet_device(&fou_net_ops
);
970 ret
= genl_register_family_with_ops(&fou_nl_family
,
975 ret
= ip_tunnel_encap_add_fou_ops();
979 genl_unregister_family(&fou_nl_family
);
981 unregister_pernet_device(&fou_net_ops
);
986 static void __exit
fou_fini(void)
988 ip_tunnel_encap_del_fou_ops();
989 genl_unregister_family(&fou_nl_family
);
990 unregister_pernet_device(&fou_net_ops
);
993 module_init(fou_init
);
994 module_exit(fou_fini
);
995 MODULE_AUTHOR("Tom Herbert <therbert@google.com>");
996 MODULE_LICENSE("GPL");