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>
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, struct fou *fou, size_t len)
53 /* Remove 'len' bytes from the packet (UDP header and
54 * FOU header if present).
56 if (fou->family == AF_INET)
57 ip_hdr(skb)->tot_len = htons(ntohs(ip_hdr(skb)->tot_len) - len);
59 ipv6_hdr(skb)->payload_len =
60 htons(ntohs(ipv6_hdr(skb)->payload_len) - len);
63 skb_postpull_rcsum(skb, udp_hdr(skb), len);
64 skb_reset_transport_header(skb);
65 return iptunnel_pull_offloads(skb);
68 static int fou_udp_recv(struct sock *sk, struct sk_buff *skb)
70 struct fou *fou = fou_from_sock(sk);
75 if (fou_recv_pull(skb, fou, sizeof(struct udphdr)))
78 return -fou->protocol;
85 static struct guehdr *gue_remcsum(struct sk_buff *skb, struct guehdr *guehdr,
86 void *data, size_t hdrlen, u8 ipproto,
90 size_t start = ntohs(pd[0]);
91 size_t offset = ntohs(pd[1]);
92 size_t plen = sizeof(struct udphdr) + hdrlen +
93 max_t(size_t, offset + sizeof(u16), start);
95 if (skb->remcsum_offload)
98 if (!pskb_may_pull(skb, plen))
100 guehdr = (struct guehdr *)&udp_hdr(skb)[1];
102 skb_remcsum_process(skb, (void *)guehdr + hdrlen,
103 start, offset, nopartial);
108 static int gue_control_message(struct sk_buff *skb, struct guehdr *guehdr)
115 static int gue_udp_recv(struct sock *sk, struct sk_buff *skb)
117 struct fou *fou = fou_from_sock(sk);
118 size_t len, optlen, hdrlen;
119 struct guehdr *guehdr;
127 len = sizeof(struct udphdr) + sizeof(struct guehdr);
128 if (!pskb_may_pull(skb, len))
131 guehdr = (struct guehdr *)&udp_hdr(skb)[1];
133 switch (guehdr->version) {
134 case 0: /* Full GUE header present */
138 /* Direct encasulation of IPv4 or IPv6 */
142 switch (((struct iphdr *)guehdr)->version) {
153 if (fou_recv_pull(skb, fou, sizeof(struct udphdr)))
159 default: /* Undefined version */
163 optlen = guehdr->hlen << 2;
166 if (!pskb_may_pull(skb, len))
169 /* guehdr may change after pull */
170 guehdr = (struct guehdr *)&udp_hdr(skb)[1];
172 hdrlen = sizeof(struct guehdr) + optlen;
174 if (guehdr->version != 0 || validate_gue_flags(guehdr, optlen))
177 hdrlen = sizeof(struct guehdr) + optlen;
179 if (fou->family == AF_INET)
180 ip_hdr(skb)->tot_len = htons(ntohs(ip_hdr(skb)->tot_len) - len);
182 ipv6_hdr(skb)->payload_len =
183 htons(ntohs(ipv6_hdr(skb)->payload_len) - len);
185 /* Pull csum through the guehdr now . This can be used if
186 * there is a remote checksum offload.
188 skb_postpull_rcsum(skb, udp_hdr(skb), len);
192 if (guehdr->flags & GUE_FLAG_PRIV) {
193 __be32 flags = *(__be32 *)(data + doffset);
195 doffset += GUE_LEN_PRIV;
197 if (flags & GUE_PFLAG_REMCSUM) {
198 guehdr = gue_remcsum(skb, guehdr, data + doffset,
199 hdrlen, guehdr->proto_ctype,
201 FOU_F_REMCSUM_NOPARTIAL));
207 doffset += GUE_PLEN_REMCSUM;
211 if (unlikely(guehdr->control))
212 return gue_control_message(skb, guehdr);
214 proto_ctype = guehdr->proto_ctype;
215 __skb_pull(skb, sizeof(struct udphdr) + hdrlen);
216 skb_reset_transport_header(skb);
218 if (iptunnel_pull_offloads(skb))
228 static struct sk_buff **fou_gro_receive(struct sock *sk,
229 struct sk_buff **head,
232 const struct net_offload *ops;
233 struct sk_buff **pp = NULL;
234 u8 proto = fou_from_sock(sk)->protocol;
235 const struct net_offload **offloads;
237 /* We can clear the encap_mark for FOU as we are essentially doing
238 * one of two possible things. We are either adding an L4 tunnel
239 * header to the outer L3 tunnel header, or we are are simply
240 * treating the GRE tunnel header as though it is a UDP protocol
241 * specific header such as VXLAN or GENEVE.
243 NAPI_GRO_CB(skb)->encap_mark = 0;
245 /* Flag this frame as already having an outer encap header */
246 NAPI_GRO_CB(skb)->is_fou = 1;
249 offloads = NAPI_GRO_CB(skb)->is_ipv6 ? inet6_offloads : inet_offloads;
250 ops = rcu_dereference(offloads[proto]);
251 if (!ops || !ops->callbacks.gro_receive)
254 pp = call_gro_receive(ops->callbacks.gro_receive, head, skb);
262 static int fou_gro_complete(struct sock *sk, struct sk_buff *skb,
265 const struct net_offload *ops;
266 u8 proto = fou_from_sock(sk)->protocol;
268 const struct net_offload **offloads;
271 offloads = NAPI_GRO_CB(skb)->is_ipv6 ? inet6_offloads : inet_offloads;
272 ops = rcu_dereference(offloads[proto]);
273 if (WARN_ON(!ops || !ops->callbacks.gro_complete))
276 err = ops->callbacks.gro_complete(skb, nhoff);
278 skb_set_inner_mac_header(skb, nhoff);
286 static struct guehdr *gue_gro_remcsum(struct sk_buff *skb, unsigned int off,
287 struct guehdr *guehdr, void *data,
288 size_t hdrlen, struct gro_remcsum *grc,
292 size_t start = ntohs(pd[0]);
293 size_t offset = ntohs(pd[1]);
295 if (skb->remcsum_offload)
298 if (!NAPI_GRO_CB(skb)->csum_valid)
301 guehdr = skb_gro_remcsum_process(skb, (void *)guehdr, off, hdrlen,
302 start, offset, grc, nopartial);
304 skb->remcsum_offload = 1;
309 static struct sk_buff **gue_gro_receive(struct sock *sk,
310 struct sk_buff **head,
313 const struct net_offload **offloads;
314 const struct net_offload *ops;
315 struct sk_buff **pp = NULL;
317 struct guehdr *guehdr;
318 size_t len, optlen, hdrlen, off;
322 struct fou *fou = fou_from_sock(sk);
323 struct gro_remcsum grc;
326 skb_gro_remcsum_init(&grc);
328 off = skb_gro_offset(skb);
329 len = off + sizeof(*guehdr);
331 guehdr = skb_gro_header_fast(skb, off);
332 if (skb_gro_header_hard(skb, len)) {
333 guehdr = skb_gro_header_slow(skb, len, off);
334 if (unlikely(!guehdr))
338 switch (guehdr->version) {
342 switch (((struct iphdr *)guehdr)->version) {
344 proto = IPPROTO_IPIP;
347 proto = IPPROTO_IPV6;
357 optlen = guehdr->hlen << 2;
360 if (skb_gro_header_hard(skb, len)) {
361 guehdr = skb_gro_header_slow(skb, len, off);
362 if (unlikely(!guehdr))
366 if (unlikely(guehdr->control) || guehdr->version != 0 ||
367 validate_gue_flags(guehdr, optlen))
370 hdrlen = sizeof(*guehdr) + optlen;
372 /* Adjust NAPI_GRO_CB(skb)->csum to account for guehdr,
373 * this is needed if there is a remote checkcsum offload.
375 skb_gro_postpull_rcsum(skb, guehdr, hdrlen);
379 if (guehdr->flags & GUE_FLAG_PRIV) {
380 __be32 flags = *(__be32 *)(data + doffset);
382 doffset += GUE_LEN_PRIV;
384 if (flags & GUE_PFLAG_REMCSUM) {
385 guehdr = gue_gro_remcsum(skb, off, guehdr,
386 data + doffset, hdrlen, &grc,
388 FOU_F_REMCSUM_NOPARTIAL));
395 doffset += GUE_PLEN_REMCSUM;
399 skb_gro_pull(skb, hdrlen);
401 for (p = *head; p; p = p->next) {
402 const struct guehdr *guehdr2;
404 if (!NAPI_GRO_CB(p)->same_flow)
407 guehdr2 = (struct guehdr *)(p->data + off);
409 /* Compare base GUE header to be equal (covers
410 * hlen, version, proto_ctype, and flags.
412 if (guehdr->word != guehdr2->word) {
413 NAPI_GRO_CB(p)->same_flow = 0;
417 /* Compare optional fields are the same. */
418 if (guehdr->hlen && memcmp(&guehdr[1], &guehdr2[1],
419 guehdr->hlen << 2)) {
420 NAPI_GRO_CB(p)->same_flow = 0;
425 proto = guehdr->proto_ctype;
429 /* We can clear the encap_mark for GUE as we are essentially doing
430 * one of two possible things. We are either adding an L4 tunnel
431 * header to the outer L3 tunnel header, or we are are simply
432 * treating the GRE tunnel header as though it is a UDP protocol
433 * specific header such as VXLAN or GENEVE.
435 NAPI_GRO_CB(skb)->encap_mark = 0;
437 /* Flag this frame as already having an outer encap header */
438 NAPI_GRO_CB(skb)->is_fou = 1;
441 offloads = NAPI_GRO_CB(skb)->is_ipv6 ? inet6_offloads : inet_offloads;
442 ops = rcu_dereference(offloads[proto]);
443 if (WARN_ON_ONCE(!ops || !ops->callbacks.gro_receive))
446 pp = call_gro_receive(ops->callbacks.gro_receive, head, skb);
452 NAPI_GRO_CB(skb)->flush |= flush;
453 skb_gro_remcsum_cleanup(skb, &grc);
458 static int gue_gro_complete(struct sock *sk, struct sk_buff *skb, int nhoff)
460 const struct net_offload **offloads;
461 struct guehdr *guehdr = (struct guehdr *)(skb->data + nhoff);
462 const struct net_offload *ops;
463 unsigned int guehlen = 0;
467 switch (guehdr->version) {
469 proto = guehdr->proto_ctype;
470 guehlen = sizeof(*guehdr) + (guehdr->hlen << 2);
473 switch (((struct iphdr *)guehdr)->version) {
475 proto = IPPROTO_IPIP;
478 proto = IPPROTO_IPV6;
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))
494 err = ops->callbacks.gro_complete(skb, nhoff + guehlen);
496 skb_set_inner_mac_header(skb, nhoff + guehlen);
503 static int fou_add_to_port_list(struct net *net, struct fou *fou)
505 struct fou_net *fn = net_generic(net, fou_net_id);
508 mutex_lock(&fn->fou_lock);
509 list_for_each_entry(fout, &fn->fou_list, list) {
510 if (fou->port == fout->port &&
511 fou->family == fout->family) {
512 mutex_unlock(&fn->fou_lock);
517 list_add(&fou->list, &fn->fou_list);
518 mutex_unlock(&fn->fou_lock);
523 static void fou_release(struct fou *fou)
525 struct socket *sock = fou->sock;
527 list_del(&fou->list);
528 udp_tunnel_sock_release(sock);
533 static int fou_create(struct net *net, struct fou_cfg *cfg,
534 struct socket **sockp)
536 struct socket *sock = NULL;
537 struct fou *fou = NULL;
539 struct udp_tunnel_sock_cfg tunnel_cfg;
542 /* Open UDP socket */
543 err = udp_sock_create(net, &cfg->udp_config, &sock);
547 /* Allocate FOU port structure */
548 fou = kzalloc(sizeof(*fou), GFP_KERNEL);
556 fou->port = cfg->udp_config.local_udp_port;
557 fou->family = cfg->udp_config.family;
558 fou->flags = cfg->flags;
559 fou->type = cfg->type;
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;
567 /* Initial for fou type */
569 case FOU_ENCAP_DIRECT:
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;
576 tunnel_cfg.encap_rcv = gue_udp_recv;
577 tunnel_cfg.gro_receive = gue_gro_receive;
578 tunnel_cfg.gro_complete = gue_gro_complete;
585 setup_udp_tunnel_sock(net, sock, &tunnel_cfg);
587 sk->sk_allocation = GFP_ATOMIC;
589 err = fou_add_to_port_list(net, fou);
601 udp_tunnel_sock_release(sock);
606 static int fou_destroy(struct net *net, struct fou_cfg *cfg)
608 struct fou_net *fn = net_generic(net, fou_net_id);
609 __be16 port = cfg->udp_config.local_udp_port;
610 u8 family = cfg->udp_config.family;
614 mutex_lock(&fn->fou_lock);
615 list_for_each_entry(fou, &fn->fou_list, list) {
616 if (fou->port == port && fou->family == family) {
622 mutex_unlock(&fn->fou_lock);
627 static struct genl_family fou_nl_family = {
628 .id = GENL_ID_GENERATE,
630 .name = FOU_GENL_NAME,
631 .version = FOU_GENL_VERSION,
632 .maxattr = FOU_ATTR_MAX,
636 static const struct nla_policy fou_nl_policy[FOU_ATTR_MAX + 1] = {
637 [FOU_ATTR_PORT] = { .type = NLA_U16, },
638 [FOU_ATTR_AF] = { .type = NLA_U8, },
639 [FOU_ATTR_IPPROTO] = { .type = NLA_U8, },
640 [FOU_ATTR_TYPE] = { .type = NLA_U8, },
641 [FOU_ATTR_REMCSUM_NOPARTIAL] = { .type = NLA_FLAG, },
644 static int parse_nl_config(struct genl_info *info,
647 memset(cfg, 0, sizeof(*cfg));
649 cfg->udp_config.family = AF_INET;
651 if (info->attrs[FOU_ATTR_AF]) {
652 u8 family = nla_get_u8(info->attrs[FOU_ATTR_AF]);
658 cfg->udp_config.ipv6_v6only = 1;
661 return -EAFNOSUPPORT;
664 cfg->udp_config.family = family;
667 if (info->attrs[FOU_ATTR_PORT]) {
668 __be16 port = nla_get_be16(info->attrs[FOU_ATTR_PORT]);
670 cfg->udp_config.local_udp_port = port;
673 if (info->attrs[FOU_ATTR_IPPROTO])
674 cfg->protocol = nla_get_u8(info->attrs[FOU_ATTR_IPPROTO]);
676 if (info->attrs[FOU_ATTR_TYPE])
677 cfg->type = nla_get_u8(info->attrs[FOU_ATTR_TYPE]);
679 if (info->attrs[FOU_ATTR_REMCSUM_NOPARTIAL])
680 cfg->flags |= FOU_F_REMCSUM_NOPARTIAL;
685 static int fou_nl_cmd_add_port(struct sk_buff *skb, struct genl_info *info)
687 struct net *net = genl_info_net(info);
691 err = parse_nl_config(info, &cfg);
695 return fou_create(net, &cfg, NULL);
698 static int fou_nl_cmd_rm_port(struct sk_buff *skb, struct genl_info *info)
700 struct net *net = genl_info_net(info);
704 err = parse_nl_config(info, &cfg);
708 return fou_destroy(net, &cfg);
711 static int fou_fill_info(struct fou *fou, struct sk_buff *msg)
713 if (nla_put_u8(msg, FOU_ATTR_AF, fou->sock->sk->sk_family) ||
714 nla_put_be16(msg, FOU_ATTR_PORT, fou->port) ||
715 nla_put_u8(msg, FOU_ATTR_IPPROTO, fou->protocol) ||
716 nla_put_u8(msg, FOU_ATTR_TYPE, fou->type))
719 if (fou->flags & FOU_F_REMCSUM_NOPARTIAL)
720 if (nla_put_flag(msg, FOU_ATTR_REMCSUM_NOPARTIAL))
725 static int fou_dump_info(struct fou *fou, u32 portid, u32 seq,
726 u32 flags, struct sk_buff *skb, u8 cmd)
730 hdr = genlmsg_put(skb, portid, seq, &fou_nl_family, flags, cmd);
734 if (fou_fill_info(fou, skb) < 0)
735 goto nla_put_failure;
737 genlmsg_end(skb, hdr);
741 genlmsg_cancel(skb, hdr);
745 static int fou_nl_cmd_get_port(struct sk_buff *skb, struct genl_info *info)
747 struct net *net = genl_info_net(info);
748 struct fou_net *fn = net_generic(net, fou_net_id);
756 ret = parse_nl_config(info, &cfg);
759 port = cfg.udp_config.local_udp_port;
763 family = cfg.udp_config.family;
764 if (family != AF_INET && family != AF_INET6)
767 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
772 mutex_lock(&fn->fou_lock);
773 list_for_each_entry(fout, &fn->fou_list, list) {
774 if (port == fout->port && family == fout->family) {
775 ret = fou_dump_info(fout, info->snd_portid,
776 info->snd_seq, 0, msg,
781 mutex_unlock(&fn->fou_lock);
785 return genlmsg_reply(msg, info);
792 static int fou_nl_dump(struct sk_buff *skb, struct netlink_callback *cb)
794 struct net *net = sock_net(skb->sk);
795 struct fou_net *fn = net_generic(net, fou_net_id);
799 mutex_lock(&fn->fou_lock);
800 list_for_each_entry(fout, &fn->fou_list, list) {
801 if (idx++ < cb->args[0])
803 ret = fou_dump_info(fout, NETLINK_CB(cb->skb).portid,
804 cb->nlh->nlmsg_seq, NLM_F_MULTI,
809 mutex_unlock(&fn->fou_lock);
815 static const struct genl_ops fou_nl_ops[] = {
818 .doit = fou_nl_cmd_add_port,
819 .policy = fou_nl_policy,
820 .flags = GENL_ADMIN_PERM,
824 .doit = fou_nl_cmd_rm_port,
825 .policy = fou_nl_policy,
826 .flags = GENL_ADMIN_PERM,
830 .doit = fou_nl_cmd_get_port,
831 .dumpit = fou_nl_dump,
832 .policy = fou_nl_policy,
836 size_t fou_encap_hlen(struct ip_tunnel_encap *e)
838 return sizeof(struct udphdr);
840 EXPORT_SYMBOL(fou_encap_hlen);
842 size_t gue_encap_hlen(struct ip_tunnel_encap *e)
845 bool need_priv = false;
847 len = sizeof(struct udphdr) + sizeof(struct guehdr);
849 if (e->flags & TUNNEL_ENCAP_FLAG_REMCSUM) {
850 len += GUE_PLEN_REMCSUM;
854 len += need_priv ? GUE_LEN_PRIV : 0;
858 EXPORT_SYMBOL(gue_encap_hlen);
860 static void fou_build_udp(struct sk_buff *skb, struct ip_tunnel_encap *e,
861 struct flowi4 *fl4, u8 *protocol, __be16 sport)
865 skb_push(skb, sizeof(struct udphdr));
866 skb_reset_transport_header(skb);
872 uh->len = htons(skb->len);
873 udp_set_csum(!(e->flags & TUNNEL_ENCAP_FLAG_CSUM), skb,
874 fl4->saddr, fl4->daddr, skb->len);
876 *protocol = IPPROTO_UDP;
879 int __fou_build_header(struct sk_buff *skb, struct ip_tunnel_encap *e,
880 u8 *protocol, __be16 *sport, int type)
884 err = iptunnel_handle_offloads(skb, type);
888 *sport = e->sport ? : udp_flow_src_port(dev_net(skb->dev),
893 EXPORT_SYMBOL(__fou_build_header);
895 int fou_build_header(struct sk_buff *skb, struct ip_tunnel_encap *e,
896 u8 *protocol, struct flowi4 *fl4)
898 int type = e->flags & TUNNEL_ENCAP_FLAG_CSUM ? SKB_GSO_UDP_TUNNEL_CSUM :
903 err = __fou_build_header(skb, e, protocol, &sport, type);
907 fou_build_udp(skb, e, fl4, protocol, sport);
911 EXPORT_SYMBOL(fou_build_header);
913 int __gue_build_header(struct sk_buff *skb, struct ip_tunnel_encap *e,
914 u8 *protocol, __be16 *sport, int type)
916 struct guehdr *guehdr;
917 size_t hdrlen, optlen = 0;
919 bool need_priv = false;
922 if ((e->flags & TUNNEL_ENCAP_FLAG_REMCSUM) &&
923 skb->ip_summed == CHECKSUM_PARTIAL) {
924 optlen += GUE_PLEN_REMCSUM;
925 type |= SKB_GSO_TUNNEL_REMCSUM;
929 optlen += need_priv ? GUE_LEN_PRIV : 0;
931 err = iptunnel_handle_offloads(skb, type);
935 /* Get source port (based on flow hash) before skb_push */
936 *sport = e->sport ? : udp_flow_src_port(dev_net(skb->dev),
939 hdrlen = sizeof(struct guehdr) + optlen;
941 skb_push(skb, hdrlen);
943 guehdr = (struct guehdr *)skb->data;
947 guehdr->hlen = optlen >> 2;
949 guehdr->proto_ctype = *protocol;
954 __be32 *flags = data;
956 guehdr->flags |= GUE_FLAG_PRIV;
958 data += GUE_LEN_PRIV;
960 if (type & SKB_GSO_TUNNEL_REMCSUM) {
961 u16 csum_start = skb_checksum_start_offset(skb);
964 if (csum_start < hdrlen)
967 csum_start -= hdrlen;
968 pd[0] = htons(csum_start);
969 pd[1] = htons(csum_start + skb->csum_offset);
971 if (!skb_is_gso(skb)) {
972 skb->ip_summed = CHECKSUM_NONE;
973 skb->encapsulation = 0;
976 *flags |= GUE_PFLAG_REMCSUM;
977 data += GUE_PLEN_REMCSUM;
984 EXPORT_SYMBOL(__gue_build_header);
986 int gue_build_header(struct sk_buff *skb, struct ip_tunnel_encap *e,
987 u8 *protocol, struct flowi4 *fl4)
989 int type = e->flags & TUNNEL_ENCAP_FLAG_CSUM ? SKB_GSO_UDP_TUNNEL_CSUM :
994 err = __gue_build_header(skb, e, protocol, &sport, type);
998 fou_build_udp(skb, e, fl4, protocol, sport);
1002 EXPORT_SYMBOL(gue_build_header);
1004 #ifdef CONFIG_NET_FOU_IP_TUNNELS
1006 static const struct ip_tunnel_encap_ops fou_iptun_ops = {
1007 .encap_hlen = fou_encap_hlen,
1008 .build_header = fou_build_header,
1011 static const struct ip_tunnel_encap_ops gue_iptun_ops = {
1012 .encap_hlen = gue_encap_hlen,
1013 .build_header = gue_build_header,
1016 static int ip_tunnel_encap_add_fou_ops(void)
1020 ret = ip_tunnel_encap_add_ops(&fou_iptun_ops, TUNNEL_ENCAP_FOU);
1022 pr_err("can't add fou ops\n");
1026 ret = ip_tunnel_encap_add_ops(&gue_iptun_ops, TUNNEL_ENCAP_GUE);
1028 pr_err("can't add gue ops\n");
1029 ip_tunnel_encap_del_ops(&fou_iptun_ops, TUNNEL_ENCAP_FOU);
1036 static void ip_tunnel_encap_del_fou_ops(void)
1038 ip_tunnel_encap_del_ops(&fou_iptun_ops, TUNNEL_ENCAP_FOU);
1039 ip_tunnel_encap_del_ops(&gue_iptun_ops, TUNNEL_ENCAP_GUE);
1044 static int ip_tunnel_encap_add_fou_ops(void)
1049 static void ip_tunnel_encap_del_fou_ops(void)
1055 static __net_init int fou_init_net(struct net *net)
1057 struct fou_net *fn = net_generic(net, fou_net_id);
1059 INIT_LIST_HEAD(&fn->fou_list);
1060 mutex_init(&fn->fou_lock);
1064 static __net_exit void fou_exit_net(struct net *net)
1066 struct fou_net *fn = net_generic(net, fou_net_id);
1067 struct fou *fou, *next;
1069 /* Close all the FOU sockets */
1070 mutex_lock(&fn->fou_lock);
1071 list_for_each_entry_safe(fou, next, &fn->fou_list, list)
1073 mutex_unlock(&fn->fou_lock);
1076 static struct pernet_operations fou_net_ops = {
1077 .init = fou_init_net,
1078 .exit = fou_exit_net,
1080 .size = sizeof(struct fou_net),
1083 static int __init fou_init(void)
1087 ret = register_pernet_device(&fou_net_ops);
1091 ret = genl_register_family_with_ops(&fou_nl_family,
1096 ret = ip_tunnel_encap_add_fou_ops();
1100 genl_unregister_family(&fou_nl_family);
1102 unregister_pernet_device(&fou_net_ops);
1107 static void __exit fou_fini(void)
1109 ip_tunnel_encap_del_fou_ops();
1110 genl_unregister_family(&fou_nl_family);
1111 unregister_pernet_device(&fou_net_ops);
1114 module_init(fou_init);
1115 module_exit(fou_fini);
1116 MODULE_AUTHOR("Tom Herbert <therbert@google.com>");
1117 MODULE_LICENSE("GPL");