irqchip/s3c24xx: Mark init_eint as __maybe_unused
[linux/fpc-iii.git] / drivers / net / geneve.c
blob58efdec12f300dec69f6790c19f7cd56b10a4b22
1 /*
2 * GENEVE: Generic Network Virtualization Encapsulation
4 * Copyright (c) 2015 Red Hat, Inc.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
11 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
13 #include <linux/kernel.h>
14 #include <linux/module.h>
15 #include <linux/netdevice.h>
16 #include <linux/etherdevice.h>
17 #include <linux/hash.h>
18 #include <net/dst_metadata.h>
19 #include <net/gro_cells.h>
20 #include <net/rtnetlink.h>
21 #include <net/geneve.h>
22 #include <net/protocol.h>
24 #define GENEVE_NETDEV_VER "0.6"
26 #define GENEVE_UDP_PORT 6081
28 #define GENEVE_N_VID (1u << 24)
29 #define GENEVE_VID_MASK (GENEVE_N_VID - 1)
31 #define VNI_HASH_BITS 10
32 #define VNI_HASH_SIZE (1<<VNI_HASH_BITS)
34 static bool log_ecn_error = true;
35 module_param(log_ecn_error, bool, 0644);
36 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
38 #define GENEVE_VER 0
39 #define GENEVE_BASE_HLEN (sizeof(struct udphdr) + sizeof(struct genevehdr))
41 /* per-network namespace private data for this module */
42 struct geneve_net {
43 struct list_head geneve_list;
44 struct list_head sock_list;
47 static int geneve_net_id;
49 union geneve_addr {
50 struct sockaddr_in sin;
51 struct sockaddr_in6 sin6;
52 struct sockaddr sa;
55 static union geneve_addr geneve_remote_unspec = { .sa.sa_family = AF_UNSPEC, };
57 /* Pseudo network device */
58 struct geneve_dev {
59 struct hlist_node hlist; /* vni hash table */
60 struct net *net; /* netns for packet i/o */
61 struct net_device *dev; /* netdev for geneve tunnel */
62 struct geneve_sock *sock4; /* IPv4 socket used for geneve tunnel */
63 #if IS_ENABLED(CONFIG_IPV6)
64 struct geneve_sock *sock6; /* IPv6 socket used for geneve tunnel */
65 #endif
66 u8 vni[3]; /* virtual network ID for tunnel */
67 u8 ttl; /* TTL override */
68 u8 tos; /* TOS override */
69 union geneve_addr remote; /* IP address for link partner */
70 struct list_head next; /* geneve's per namespace list */
71 __be16 dst_port;
72 bool collect_md;
73 struct gro_cells gro_cells;
76 struct geneve_sock {
77 bool collect_md;
78 struct list_head list;
79 struct socket *sock;
80 struct rcu_head rcu;
81 int refcnt;
82 struct udp_offload udp_offloads;
83 struct hlist_head vni_list[VNI_HASH_SIZE];
86 static inline __u32 geneve_net_vni_hash(u8 vni[3])
88 __u32 vnid;
90 vnid = (vni[0] << 16) | (vni[1] << 8) | vni[2];
91 return hash_32(vnid, VNI_HASH_BITS);
94 static __be64 vni_to_tunnel_id(const __u8 *vni)
96 #ifdef __BIG_ENDIAN
97 return (vni[0] << 16) | (vni[1] << 8) | vni[2];
98 #else
99 return (__force __be64)(((__force u64)vni[0] << 40) |
100 ((__force u64)vni[1] << 48) |
101 ((__force u64)vni[2] << 56));
102 #endif
105 static struct geneve_dev *geneve_lookup(struct geneve_sock *gs,
106 __be32 addr, u8 vni[])
108 struct hlist_head *vni_list_head;
109 struct geneve_dev *geneve;
110 __u32 hash;
112 /* Find the device for this VNI */
113 hash = geneve_net_vni_hash(vni);
114 vni_list_head = &gs->vni_list[hash];
115 hlist_for_each_entry_rcu(geneve, vni_list_head, hlist) {
116 if (!memcmp(vni, geneve->vni, sizeof(geneve->vni)) &&
117 addr == geneve->remote.sin.sin_addr.s_addr)
118 return geneve;
120 return NULL;
123 #if IS_ENABLED(CONFIG_IPV6)
124 static struct geneve_dev *geneve6_lookup(struct geneve_sock *gs,
125 struct in6_addr addr6, u8 vni[])
127 struct hlist_head *vni_list_head;
128 struct geneve_dev *geneve;
129 __u32 hash;
131 /* Find the device for this VNI */
132 hash = geneve_net_vni_hash(vni);
133 vni_list_head = &gs->vni_list[hash];
134 hlist_for_each_entry_rcu(geneve, vni_list_head, hlist) {
135 if (!memcmp(vni, geneve->vni, sizeof(geneve->vni)) &&
136 ipv6_addr_equal(&addr6, &geneve->remote.sin6.sin6_addr))
137 return geneve;
139 return NULL;
141 #endif
143 static inline struct genevehdr *geneve_hdr(const struct sk_buff *skb)
145 return (struct genevehdr *)(udp_hdr(skb) + 1);
148 /* geneve receive/decap routine */
149 static void geneve_rx(struct geneve_sock *gs, struct sk_buff *skb)
151 struct genevehdr *gnvh = geneve_hdr(skb);
152 struct metadata_dst *tun_dst = NULL;
153 struct geneve_dev *geneve = NULL;
154 struct pcpu_sw_netstats *stats;
155 struct iphdr *iph = NULL;
156 __be32 addr;
157 static u8 zero_vni[3];
158 u8 *vni;
159 int err = 0;
160 sa_family_t sa_family;
161 #if IS_ENABLED(CONFIG_IPV6)
162 struct ipv6hdr *ip6h = NULL;
163 struct in6_addr addr6;
164 static struct in6_addr zero_addr6;
165 #endif
167 sa_family = gs->sock->sk->sk_family;
169 if (sa_family == AF_INET) {
170 iph = ip_hdr(skb); /* outer IP header... */
172 if (gs->collect_md) {
173 vni = zero_vni;
174 addr = 0;
175 } else {
176 vni = gnvh->vni;
178 addr = iph->saddr;
181 geneve = geneve_lookup(gs, addr, vni);
182 #if IS_ENABLED(CONFIG_IPV6)
183 } else if (sa_family == AF_INET6) {
184 ip6h = ipv6_hdr(skb); /* outer IPv6 header... */
186 if (gs->collect_md) {
187 vni = zero_vni;
188 addr6 = zero_addr6;
189 } else {
190 vni = gnvh->vni;
192 addr6 = ip6h->saddr;
195 geneve = geneve6_lookup(gs, addr6, vni);
196 #endif
198 if (!geneve)
199 goto drop;
201 if (ip_tunnel_collect_metadata() || gs->collect_md) {
202 __be16 flags;
204 flags = TUNNEL_KEY | TUNNEL_GENEVE_OPT |
205 (gnvh->oam ? TUNNEL_OAM : 0) |
206 (gnvh->critical ? TUNNEL_CRIT_OPT : 0);
208 tun_dst = udp_tun_rx_dst(skb, sa_family, flags,
209 vni_to_tunnel_id(gnvh->vni),
210 gnvh->opt_len * 4);
211 if (!tun_dst)
212 goto drop;
213 /* Update tunnel dst according to Geneve options. */
214 ip_tunnel_info_opts_set(&tun_dst->u.tun_info,
215 gnvh->options, gnvh->opt_len * 4);
216 } else {
217 /* Drop packets w/ critical options,
218 * since we don't support any...
220 if (gnvh->critical)
221 goto drop;
224 skb_reset_mac_header(skb);
225 skb_scrub_packet(skb, !net_eq(geneve->net, dev_net(geneve->dev)));
226 skb->protocol = eth_type_trans(skb, geneve->dev);
227 skb_postpull_rcsum(skb, eth_hdr(skb), ETH_HLEN);
229 if (tun_dst)
230 skb_dst_set(skb, &tun_dst->dst);
232 /* Ignore packet loops (and multicast echo) */
233 if (ether_addr_equal(eth_hdr(skb)->h_source, geneve->dev->dev_addr))
234 goto drop;
236 skb_reset_network_header(skb);
238 if (iph)
239 err = IP_ECN_decapsulate(iph, skb);
240 #if IS_ENABLED(CONFIG_IPV6)
241 if (ip6h)
242 err = IP6_ECN_decapsulate(ip6h, skb);
243 #endif
245 if (unlikely(err)) {
246 if (log_ecn_error) {
247 if (iph)
248 net_info_ratelimited("non-ECT from %pI4 "
249 "with TOS=%#x\n",
250 &iph->saddr, iph->tos);
251 #if IS_ENABLED(CONFIG_IPV6)
252 if (ip6h)
253 net_info_ratelimited("non-ECT from %pI6\n",
254 &ip6h->saddr);
255 #endif
257 if (err > 1) {
258 ++geneve->dev->stats.rx_frame_errors;
259 ++geneve->dev->stats.rx_errors;
260 goto drop;
264 stats = this_cpu_ptr(geneve->dev->tstats);
265 u64_stats_update_begin(&stats->syncp);
266 stats->rx_packets++;
267 stats->rx_bytes += skb->len;
268 u64_stats_update_end(&stats->syncp);
270 gro_cells_receive(&geneve->gro_cells, skb);
271 return;
272 drop:
273 /* Consume bad packet */
274 kfree_skb(skb);
277 /* Setup stats when device is created */
278 static int geneve_init(struct net_device *dev)
280 struct geneve_dev *geneve = netdev_priv(dev);
281 int err;
283 dev->tstats = netdev_alloc_pcpu_stats(struct pcpu_sw_netstats);
284 if (!dev->tstats)
285 return -ENOMEM;
287 err = gro_cells_init(&geneve->gro_cells, dev);
288 if (err) {
289 free_percpu(dev->tstats);
290 return err;
293 return 0;
296 static void geneve_uninit(struct net_device *dev)
298 struct geneve_dev *geneve = netdev_priv(dev);
300 gro_cells_destroy(&geneve->gro_cells);
301 free_percpu(dev->tstats);
304 /* Callback from net/ipv4/udp.c to receive packets */
305 static int geneve_udp_encap_recv(struct sock *sk, struct sk_buff *skb)
307 struct genevehdr *geneveh;
308 struct geneve_sock *gs;
309 int opts_len;
311 /* Need Geneve and inner Ethernet header to be present */
312 if (unlikely(!pskb_may_pull(skb, GENEVE_BASE_HLEN)))
313 goto error;
315 /* Return packets with reserved bits set */
316 geneveh = geneve_hdr(skb);
317 if (unlikely(geneveh->ver != GENEVE_VER))
318 goto error;
320 if (unlikely(geneveh->proto_type != htons(ETH_P_TEB)))
321 goto error;
323 opts_len = geneveh->opt_len * 4;
324 if (iptunnel_pull_header(skb, GENEVE_BASE_HLEN + opts_len,
325 htons(ETH_P_TEB)))
326 goto drop;
328 gs = rcu_dereference_sk_user_data(sk);
329 if (!gs)
330 goto drop;
332 geneve_rx(gs, skb);
333 return 0;
335 drop:
336 /* Consume bad packet */
337 kfree_skb(skb);
338 return 0;
340 error:
341 /* Let the UDP layer deal with the skb */
342 return 1;
345 static struct socket *geneve_create_sock(struct net *net, bool ipv6,
346 __be16 port)
348 struct socket *sock;
349 struct udp_port_cfg udp_conf;
350 int err;
352 memset(&udp_conf, 0, sizeof(udp_conf));
354 if (ipv6) {
355 udp_conf.family = AF_INET6;
356 udp_conf.ipv6_v6only = 1;
357 } else {
358 udp_conf.family = AF_INET;
359 udp_conf.local_ip.s_addr = htonl(INADDR_ANY);
362 udp_conf.local_udp_port = port;
364 /* Open UDP socket */
365 err = udp_sock_create(net, &udp_conf, &sock);
366 if (err < 0)
367 return ERR_PTR(err);
369 return sock;
372 static void geneve_notify_add_rx_port(struct geneve_sock *gs)
374 struct sock *sk = gs->sock->sk;
375 sa_family_t sa_family = sk->sk_family;
376 int err;
378 if (sa_family == AF_INET) {
379 err = udp_add_offload(&gs->udp_offloads);
380 if (err)
381 pr_warn("geneve: udp_add_offload failed with status %d\n",
382 err);
386 static int geneve_hlen(struct genevehdr *gh)
388 return sizeof(*gh) + gh->opt_len * 4;
391 static struct sk_buff **geneve_gro_receive(struct sk_buff **head,
392 struct sk_buff *skb,
393 struct udp_offload *uoff)
395 struct sk_buff *p, **pp = NULL;
396 struct genevehdr *gh, *gh2;
397 unsigned int hlen, gh_len, off_gnv;
398 const struct packet_offload *ptype;
399 __be16 type;
400 int flush = 1;
402 off_gnv = skb_gro_offset(skb);
403 hlen = off_gnv + sizeof(*gh);
404 gh = skb_gro_header_fast(skb, off_gnv);
405 if (skb_gro_header_hard(skb, hlen)) {
406 gh = skb_gro_header_slow(skb, hlen, off_gnv);
407 if (unlikely(!gh))
408 goto out;
411 if (gh->ver != GENEVE_VER || gh->oam)
412 goto out;
413 gh_len = geneve_hlen(gh);
415 hlen = off_gnv + gh_len;
416 if (skb_gro_header_hard(skb, hlen)) {
417 gh = skb_gro_header_slow(skb, hlen, off_gnv);
418 if (unlikely(!gh))
419 goto out;
422 flush = 0;
424 for (p = *head; p; p = p->next) {
425 if (!NAPI_GRO_CB(p)->same_flow)
426 continue;
428 gh2 = (struct genevehdr *)(p->data + off_gnv);
429 if (gh->opt_len != gh2->opt_len ||
430 memcmp(gh, gh2, gh_len)) {
431 NAPI_GRO_CB(p)->same_flow = 0;
432 continue;
436 type = gh->proto_type;
438 rcu_read_lock();
439 ptype = gro_find_receive_by_type(type);
440 if (!ptype) {
441 flush = 1;
442 goto out_unlock;
445 skb_gro_pull(skb, gh_len);
446 skb_gro_postpull_rcsum(skb, gh, gh_len);
447 pp = ptype->callbacks.gro_receive(head, skb);
449 out_unlock:
450 rcu_read_unlock();
451 out:
452 NAPI_GRO_CB(skb)->flush |= flush;
454 return pp;
457 static int geneve_gro_complete(struct sk_buff *skb, int nhoff,
458 struct udp_offload *uoff)
460 struct genevehdr *gh;
461 struct packet_offload *ptype;
462 __be16 type;
463 int gh_len;
464 int err = -ENOSYS;
466 udp_tunnel_gro_complete(skb, nhoff);
468 gh = (struct genevehdr *)(skb->data + nhoff);
469 gh_len = geneve_hlen(gh);
470 type = gh->proto_type;
472 rcu_read_lock();
473 ptype = gro_find_complete_by_type(type);
474 if (ptype)
475 err = ptype->callbacks.gro_complete(skb, nhoff + gh_len);
477 rcu_read_unlock();
478 return err;
481 /* Create new listen socket if needed */
482 static struct geneve_sock *geneve_socket_create(struct net *net, __be16 port,
483 bool ipv6)
485 struct geneve_net *gn = net_generic(net, geneve_net_id);
486 struct geneve_sock *gs;
487 struct socket *sock;
488 struct udp_tunnel_sock_cfg tunnel_cfg;
489 int h;
491 gs = kzalloc(sizeof(*gs), GFP_KERNEL);
492 if (!gs)
493 return ERR_PTR(-ENOMEM);
495 sock = geneve_create_sock(net, ipv6, port);
496 if (IS_ERR(sock)) {
497 kfree(gs);
498 return ERR_CAST(sock);
501 gs->sock = sock;
502 gs->refcnt = 1;
503 for (h = 0; h < VNI_HASH_SIZE; ++h)
504 INIT_HLIST_HEAD(&gs->vni_list[h]);
506 /* Initialize the geneve udp offloads structure */
507 gs->udp_offloads.port = port;
508 gs->udp_offloads.callbacks.gro_receive = geneve_gro_receive;
509 gs->udp_offloads.callbacks.gro_complete = geneve_gro_complete;
510 geneve_notify_add_rx_port(gs);
512 /* Mark socket as an encapsulation socket */
513 tunnel_cfg.sk_user_data = gs;
514 tunnel_cfg.encap_type = 1;
515 tunnel_cfg.encap_rcv = geneve_udp_encap_recv;
516 tunnel_cfg.encap_destroy = NULL;
517 setup_udp_tunnel_sock(net, sock, &tunnel_cfg);
518 list_add(&gs->list, &gn->sock_list);
519 return gs;
522 static void geneve_notify_del_rx_port(struct geneve_sock *gs)
524 struct sock *sk = gs->sock->sk;
525 sa_family_t sa_family = sk->sk_family;
527 if (sa_family == AF_INET)
528 udp_del_offload(&gs->udp_offloads);
531 static void __geneve_sock_release(struct geneve_sock *gs)
533 if (!gs || --gs->refcnt)
534 return;
536 list_del(&gs->list);
537 geneve_notify_del_rx_port(gs);
538 udp_tunnel_sock_release(gs->sock);
539 kfree_rcu(gs, rcu);
542 static void geneve_sock_release(struct geneve_dev *geneve)
544 __geneve_sock_release(geneve->sock4);
545 #if IS_ENABLED(CONFIG_IPV6)
546 __geneve_sock_release(geneve->sock6);
547 #endif
550 static struct geneve_sock *geneve_find_sock(struct geneve_net *gn,
551 sa_family_t family,
552 __be16 dst_port)
554 struct geneve_sock *gs;
556 list_for_each_entry(gs, &gn->sock_list, list) {
557 if (inet_sk(gs->sock->sk)->inet_sport == dst_port &&
558 inet_sk(gs->sock->sk)->sk.sk_family == family) {
559 return gs;
562 return NULL;
565 static int geneve_sock_add(struct geneve_dev *geneve, bool ipv6)
567 struct net *net = geneve->net;
568 struct geneve_net *gn = net_generic(net, geneve_net_id);
569 struct geneve_sock *gs;
570 __u32 hash;
572 gs = geneve_find_sock(gn, ipv6 ? AF_INET6 : AF_INET, geneve->dst_port);
573 if (gs) {
574 gs->refcnt++;
575 goto out;
578 gs = geneve_socket_create(net, geneve->dst_port, ipv6);
579 if (IS_ERR(gs))
580 return PTR_ERR(gs);
582 out:
583 gs->collect_md = geneve->collect_md;
584 #if IS_ENABLED(CONFIG_IPV6)
585 if (ipv6)
586 geneve->sock6 = gs;
587 else
588 #endif
589 geneve->sock4 = gs;
591 hash = geneve_net_vni_hash(geneve->vni);
592 hlist_add_head_rcu(&geneve->hlist, &gs->vni_list[hash]);
593 return 0;
596 static int geneve_open(struct net_device *dev)
598 struct geneve_dev *geneve = netdev_priv(dev);
599 bool ipv6 = geneve->remote.sa.sa_family == AF_INET6;
600 bool metadata = geneve->collect_md;
601 int ret = 0;
603 geneve->sock4 = NULL;
604 #if IS_ENABLED(CONFIG_IPV6)
605 geneve->sock6 = NULL;
606 if (ipv6 || metadata)
607 ret = geneve_sock_add(geneve, true);
608 #endif
609 if (!ret && (!ipv6 || metadata))
610 ret = geneve_sock_add(geneve, false);
611 if (ret < 0)
612 geneve_sock_release(geneve);
614 return ret;
617 static int geneve_stop(struct net_device *dev)
619 struct geneve_dev *geneve = netdev_priv(dev);
621 if (!hlist_unhashed(&geneve->hlist))
622 hlist_del_rcu(&geneve->hlist);
623 geneve_sock_release(geneve);
624 return 0;
627 static void geneve_build_header(struct genevehdr *geneveh,
628 __be16 tun_flags, u8 vni[3],
629 u8 options_len, u8 *options)
631 geneveh->ver = GENEVE_VER;
632 geneveh->opt_len = options_len / 4;
633 geneveh->oam = !!(tun_flags & TUNNEL_OAM);
634 geneveh->critical = !!(tun_flags & TUNNEL_CRIT_OPT);
635 geneveh->rsvd1 = 0;
636 memcpy(geneveh->vni, vni, 3);
637 geneveh->proto_type = htons(ETH_P_TEB);
638 geneveh->rsvd2 = 0;
640 memcpy(geneveh->options, options, options_len);
643 static int geneve_build_skb(struct rtable *rt, struct sk_buff *skb,
644 __be16 tun_flags, u8 vni[3], u8 opt_len, u8 *opt,
645 bool csum, bool xnet)
647 struct genevehdr *gnvh;
648 int min_headroom;
649 int err;
651 skb_scrub_packet(skb, xnet);
653 min_headroom = LL_RESERVED_SPACE(rt->dst.dev) + rt->dst.header_len
654 + GENEVE_BASE_HLEN + opt_len + sizeof(struct iphdr);
655 err = skb_cow_head(skb, min_headroom);
656 if (unlikely(err)) {
657 kfree_skb(skb);
658 goto free_rt;
661 skb = udp_tunnel_handle_offloads(skb, csum);
662 if (IS_ERR(skb)) {
663 err = PTR_ERR(skb);
664 goto free_rt;
667 gnvh = (struct genevehdr *)__skb_push(skb, sizeof(*gnvh) + opt_len);
668 geneve_build_header(gnvh, tun_flags, vni, opt_len, opt);
670 skb_set_inner_protocol(skb, htons(ETH_P_TEB));
671 return 0;
673 free_rt:
674 ip_rt_put(rt);
675 return err;
678 #if IS_ENABLED(CONFIG_IPV6)
679 static int geneve6_build_skb(struct dst_entry *dst, struct sk_buff *skb,
680 __be16 tun_flags, u8 vni[3], u8 opt_len, u8 *opt,
681 bool csum, bool xnet)
683 struct genevehdr *gnvh;
684 int min_headroom;
685 int err;
687 skb_scrub_packet(skb, xnet);
689 min_headroom = LL_RESERVED_SPACE(dst->dev) + dst->header_len
690 + GENEVE_BASE_HLEN + opt_len + sizeof(struct ipv6hdr);
691 err = skb_cow_head(skb, min_headroom);
692 if (unlikely(err)) {
693 kfree_skb(skb);
694 goto free_dst;
697 skb = udp_tunnel_handle_offloads(skb, csum);
698 if (IS_ERR(skb)) {
699 err = PTR_ERR(skb);
700 goto free_dst;
703 gnvh = (struct genevehdr *)__skb_push(skb, sizeof(*gnvh) + opt_len);
704 geneve_build_header(gnvh, tun_flags, vni, opt_len, opt);
706 skb_set_inner_protocol(skb, htons(ETH_P_TEB));
707 return 0;
709 free_dst:
710 dst_release(dst);
711 return err;
713 #endif
715 static struct rtable *geneve_get_v4_rt(struct sk_buff *skb,
716 struct net_device *dev,
717 struct flowi4 *fl4,
718 struct ip_tunnel_info *info)
720 struct geneve_dev *geneve = netdev_priv(dev);
721 struct rtable *rt = NULL;
722 __u8 tos;
724 memset(fl4, 0, sizeof(*fl4));
725 fl4->flowi4_mark = skb->mark;
726 fl4->flowi4_proto = IPPROTO_UDP;
728 if (info) {
729 fl4->daddr = info->key.u.ipv4.dst;
730 fl4->saddr = info->key.u.ipv4.src;
731 fl4->flowi4_tos = RT_TOS(info->key.tos);
732 } else {
733 tos = geneve->tos;
734 if (tos == 1) {
735 const struct iphdr *iip = ip_hdr(skb);
737 tos = ip_tunnel_get_dsfield(iip, skb);
740 fl4->flowi4_tos = RT_TOS(tos);
741 fl4->daddr = geneve->remote.sin.sin_addr.s_addr;
744 rt = ip_route_output_key(geneve->net, fl4);
745 if (IS_ERR(rt)) {
746 netdev_dbg(dev, "no route to %pI4\n", &fl4->daddr);
747 return ERR_PTR(-ENETUNREACH);
749 if (rt->dst.dev == dev) { /* is this necessary? */
750 netdev_dbg(dev, "circular route to %pI4\n", &fl4->daddr);
751 ip_rt_put(rt);
752 return ERR_PTR(-ELOOP);
754 return rt;
757 #if IS_ENABLED(CONFIG_IPV6)
758 static struct dst_entry *geneve_get_v6_dst(struct sk_buff *skb,
759 struct net_device *dev,
760 struct flowi6 *fl6,
761 struct ip_tunnel_info *info)
763 struct geneve_dev *geneve = netdev_priv(dev);
764 struct geneve_sock *gs6 = geneve->sock6;
765 struct dst_entry *dst = NULL;
766 __u8 prio;
768 memset(fl6, 0, sizeof(*fl6));
769 fl6->flowi6_mark = skb->mark;
770 fl6->flowi6_proto = IPPROTO_UDP;
772 if (info) {
773 fl6->daddr = info->key.u.ipv6.dst;
774 fl6->saddr = info->key.u.ipv6.src;
775 fl6->flowi6_tos = RT_TOS(info->key.tos);
776 } else {
777 prio = geneve->tos;
778 if (prio == 1) {
779 const struct iphdr *iip = ip_hdr(skb);
781 prio = ip_tunnel_get_dsfield(iip, skb);
784 fl6->flowi6_tos = RT_TOS(prio);
785 fl6->daddr = geneve->remote.sin6.sin6_addr;
788 if (ipv6_stub->ipv6_dst_lookup(geneve->net, gs6->sock->sk, &dst, fl6)) {
789 netdev_dbg(dev, "no route to %pI6\n", &fl6->daddr);
790 return ERR_PTR(-ENETUNREACH);
792 if (dst->dev == dev) { /* is this necessary? */
793 netdev_dbg(dev, "circular route to %pI6\n", &fl6->daddr);
794 dst_release(dst);
795 return ERR_PTR(-ELOOP);
798 return dst;
800 #endif
802 /* Convert 64 bit tunnel ID to 24 bit VNI. */
803 static void tunnel_id_to_vni(__be64 tun_id, __u8 *vni)
805 #ifdef __BIG_ENDIAN
806 vni[0] = (__force __u8)(tun_id >> 16);
807 vni[1] = (__force __u8)(tun_id >> 8);
808 vni[2] = (__force __u8)tun_id;
809 #else
810 vni[0] = (__force __u8)((__force u64)tun_id >> 40);
811 vni[1] = (__force __u8)((__force u64)tun_id >> 48);
812 vni[2] = (__force __u8)((__force u64)tun_id >> 56);
813 #endif
816 static netdev_tx_t geneve_xmit_skb(struct sk_buff *skb, struct net_device *dev,
817 struct ip_tunnel_info *info)
819 struct geneve_dev *geneve = netdev_priv(dev);
820 struct geneve_sock *gs4 = geneve->sock4;
821 struct rtable *rt = NULL;
822 const struct iphdr *iip; /* interior IP header */
823 int err = -EINVAL;
824 struct flowi4 fl4;
825 __u8 tos, ttl;
826 __be16 sport;
827 bool udp_csum;
828 __be16 df;
829 bool xnet = !net_eq(geneve->net, dev_net(geneve->dev));
831 if (geneve->collect_md) {
832 if (unlikely(!info || !(info->mode & IP_TUNNEL_INFO_TX))) {
833 netdev_dbg(dev, "no tunnel metadata\n");
834 goto tx_error;
836 if (info && ip_tunnel_info_af(info) != AF_INET)
837 goto tx_error;
840 rt = geneve_get_v4_rt(skb, dev, &fl4, info);
841 if (IS_ERR(rt)) {
842 err = PTR_ERR(rt);
843 goto tx_error;
846 sport = udp_flow_src_port(geneve->net, skb, 1, USHRT_MAX, true);
847 skb_reset_mac_header(skb);
849 iip = ip_hdr(skb);
851 if (info) {
852 const struct ip_tunnel_key *key = &info->key;
853 u8 *opts = NULL;
854 u8 vni[3];
856 tunnel_id_to_vni(key->tun_id, vni);
857 if (key->tun_flags & TUNNEL_GENEVE_OPT)
858 opts = ip_tunnel_info_opts(info);
860 udp_csum = !!(key->tun_flags & TUNNEL_CSUM);
861 err = geneve_build_skb(rt, skb, key->tun_flags, vni,
862 info->options_len, opts, udp_csum, xnet);
863 if (unlikely(err))
864 goto err;
866 tos = ip_tunnel_ecn_encap(key->tos, iip, skb);
867 ttl = key->ttl;
868 df = key->tun_flags & TUNNEL_DONT_FRAGMENT ? htons(IP_DF) : 0;
869 } else {
870 udp_csum = false;
871 err = geneve_build_skb(rt, skb, 0, geneve->vni,
872 0, NULL, udp_csum, xnet);
873 if (unlikely(err))
874 goto err;
876 tos = ip_tunnel_ecn_encap(fl4.flowi4_tos, iip, skb);
877 ttl = geneve->ttl;
878 if (!ttl && IN_MULTICAST(ntohl(fl4.daddr)))
879 ttl = 1;
880 ttl = ttl ? : ip4_dst_hoplimit(&rt->dst);
881 df = 0;
883 err = udp_tunnel_xmit_skb(rt, gs4->sock->sk, skb, fl4.saddr, fl4.daddr,
884 tos, ttl, df, sport, geneve->dst_port,
885 !net_eq(geneve->net, dev_net(geneve->dev)),
886 !udp_csum);
888 iptunnel_xmit_stats(err, &dev->stats, dev->tstats);
889 return NETDEV_TX_OK;
891 tx_error:
892 dev_kfree_skb(skb);
893 err:
894 if (err == -ELOOP)
895 dev->stats.collisions++;
896 else if (err == -ENETUNREACH)
897 dev->stats.tx_carrier_errors++;
898 else
899 dev->stats.tx_errors++;
900 return NETDEV_TX_OK;
903 #if IS_ENABLED(CONFIG_IPV6)
904 static netdev_tx_t geneve6_xmit_skb(struct sk_buff *skb, struct net_device *dev,
905 struct ip_tunnel_info *info)
907 struct geneve_dev *geneve = netdev_priv(dev);
908 struct geneve_sock *gs6 = geneve->sock6;
909 struct dst_entry *dst = NULL;
910 const struct iphdr *iip; /* interior IP header */
911 int err = -EINVAL;
912 struct flowi6 fl6;
913 __u8 prio, ttl;
914 __be16 sport;
915 bool udp_csum;
916 bool xnet = !net_eq(geneve->net, dev_net(geneve->dev));
918 if (geneve->collect_md) {
919 if (unlikely(!info || !(info->mode & IP_TUNNEL_INFO_TX))) {
920 netdev_dbg(dev, "no tunnel metadata\n");
921 goto tx_error;
925 dst = geneve_get_v6_dst(skb, dev, &fl6, info);
926 if (IS_ERR(dst)) {
927 err = PTR_ERR(dst);
928 goto tx_error;
931 sport = udp_flow_src_port(geneve->net, skb, 1, USHRT_MAX, true);
932 skb_reset_mac_header(skb);
934 iip = ip_hdr(skb);
936 if (info) {
937 const struct ip_tunnel_key *key = &info->key;
938 u8 *opts = NULL;
939 u8 vni[3];
941 tunnel_id_to_vni(key->tun_id, vni);
942 if (key->tun_flags & TUNNEL_GENEVE_OPT)
943 opts = ip_tunnel_info_opts(info);
945 udp_csum = !!(key->tun_flags & TUNNEL_CSUM);
946 err = geneve6_build_skb(dst, skb, key->tun_flags, vni,
947 info->options_len, opts,
948 udp_csum, xnet);
949 if (unlikely(err))
950 goto err;
952 prio = ip_tunnel_ecn_encap(key->tos, iip, skb);
953 ttl = key->ttl;
954 } else {
955 udp_csum = false;
956 err = geneve6_build_skb(dst, skb, 0, geneve->vni,
957 0, NULL, udp_csum, xnet);
958 if (unlikely(err))
959 goto err;
961 prio = ip_tunnel_ecn_encap(fl6.flowi6_tos, iip, skb);
962 ttl = geneve->ttl;
963 if (!ttl && ipv6_addr_is_multicast(&fl6.daddr))
964 ttl = 1;
965 ttl = ttl ? : ip6_dst_hoplimit(dst);
967 err = udp_tunnel6_xmit_skb(dst, gs6->sock->sk, skb, dev,
968 &fl6.saddr, &fl6.daddr, prio, ttl,
969 sport, geneve->dst_port, !udp_csum);
970 return NETDEV_TX_OK;
972 tx_error:
973 dev_kfree_skb(skb);
974 err:
975 if (err == -ELOOP)
976 dev->stats.collisions++;
977 else if (err == -ENETUNREACH)
978 dev->stats.tx_carrier_errors++;
979 else
980 dev->stats.tx_errors++;
981 return NETDEV_TX_OK;
983 #endif
985 static netdev_tx_t geneve_xmit(struct sk_buff *skb, struct net_device *dev)
987 struct geneve_dev *geneve = netdev_priv(dev);
988 struct ip_tunnel_info *info = NULL;
990 if (geneve->collect_md)
991 info = skb_tunnel_info(skb);
993 #if IS_ENABLED(CONFIG_IPV6)
994 if ((info && ip_tunnel_info_af(info) == AF_INET6) ||
995 (!info && geneve->remote.sa.sa_family == AF_INET6))
996 return geneve6_xmit_skb(skb, dev, info);
997 #endif
998 return geneve_xmit_skb(skb, dev, info);
1001 static int geneve_fill_metadata_dst(struct net_device *dev, struct sk_buff *skb)
1003 struct ip_tunnel_info *info = skb_tunnel_info(skb);
1004 struct geneve_dev *geneve = netdev_priv(dev);
1005 struct rtable *rt;
1006 struct flowi4 fl4;
1007 #if IS_ENABLED(CONFIG_IPV6)
1008 struct dst_entry *dst;
1009 struct flowi6 fl6;
1010 #endif
1012 if (ip_tunnel_info_af(info) == AF_INET) {
1013 rt = geneve_get_v4_rt(skb, dev, &fl4, info);
1014 if (IS_ERR(rt))
1015 return PTR_ERR(rt);
1017 ip_rt_put(rt);
1018 info->key.u.ipv4.src = fl4.saddr;
1019 #if IS_ENABLED(CONFIG_IPV6)
1020 } else if (ip_tunnel_info_af(info) == AF_INET6) {
1021 dst = geneve_get_v6_dst(skb, dev, &fl6, info);
1022 if (IS_ERR(dst))
1023 return PTR_ERR(dst);
1025 dst_release(dst);
1026 info->key.u.ipv6.src = fl6.saddr;
1027 #endif
1028 } else {
1029 return -EINVAL;
1032 info->key.tp_src = udp_flow_src_port(geneve->net, skb,
1033 1, USHRT_MAX, true);
1034 info->key.tp_dst = geneve->dst_port;
1035 return 0;
1038 static const struct net_device_ops geneve_netdev_ops = {
1039 .ndo_init = geneve_init,
1040 .ndo_uninit = geneve_uninit,
1041 .ndo_open = geneve_open,
1042 .ndo_stop = geneve_stop,
1043 .ndo_start_xmit = geneve_xmit,
1044 .ndo_get_stats64 = ip_tunnel_get_stats64,
1045 .ndo_change_mtu = eth_change_mtu,
1046 .ndo_validate_addr = eth_validate_addr,
1047 .ndo_set_mac_address = eth_mac_addr,
1048 .ndo_fill_metadata_dst = geneve_fill_metadata_dst,
1051 static void geneve_get_drvinfo(struct net_device *dev,
1052 struct ethtool_drvinfo *drvinfo)
1054 strlcpy(drvinfo->version, GENEVE_NETDEV_VER, sizeof(drvinfo->version));
1055 strlcpy(drvinfo->driver, "geneve", sizeof(drvinfo->driver));
1058 static const struct ethtool_ops geneve_ethtool_ops = {
1059 .get_drvinfo = geneve_get_drvinfo,
1060 .get_link = ethtool_op_get_link,
1063 /* Info for udev, that this is a virtual tunnel endpoint */
1064 static struct device_type geneve_type = {
1065 .name = "geneve",
1068 /* Initialize the device structure. */
1069 static void geneve_setup(struct net_device *dev)
1071 ether_setup(dev);
1073 dev->netdev_ops = &geneve_netdev_ops;
1074 dev->ethtool_ops = &geneve_ethtool_ops;
1075 dev->destructor = free_netdev;
1077 SET_NETDEV_DEVTYPE(dev, &geneve_type);
1079 dev->features |= NETIF_F_LLTX;
1080 dev->features |= NETIF_F_SG | NETIF_F_HW_CSUM;
1081 dev->features |= NETIF_F_RXCSUM;
1082 dev->features |= NETIF_F_GSO_SOFTWARE;
1084 dev->hw_features |= NETIF_F_SG | NETIF_F_HW_CSUM | NETIF_F_RXCSUM;
1085 dev->hw_features |= NETIF_F_GSO_SOFTWARE;
1087 netif_keep_dst(dev);
1088 dev->priv_flags |= IFF_LIVE_ADDR_CHANGE | IFF_NO_QUEUE;
1089 eth_hw_addr_random(dev);
1092 static const struct nla_policy geneve_policy[IFLA_GENEVE_MAX + 1] = {
1093 [IFLA_GENEVE_ID] = { .type = NLA_U32 },
1094 [IFLA_GENEVE_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
1095 [IFLA_GENEVE_REMOTE6] = { .len = sizeof(struct in6_addr) },
1096 [IFLA_GENEVE_TTL] = { .type = NLA_U8 },
1097 [IFLA_GENEVE_TOS] = { .type = NLA_U8 },
1098 [IFLA_GENEVE_PORT] = { .type = NLA_U16 },
1099 [IFLA_GENEVE_COLLECT_METADATA] = { .type = NLA_FLAG },
1102 static int geneve_validate(struct nlattr *tb[], struct nlattr *data[])
1104 if (tb[IFLA_ADDRESS]) {
1105 if (nla_len(tb[IFLA_ADDRESS]) != ETH_ALEN)
1106 return -EINVAL;
1108 if (!is_valid_ether_addr(nla_data(tb[IFLA_ADDRESS])))
1109 return -EADDRNOTAVAIL;
1112 if (!data)
1113 return -EINVAL;
1115 if (data[IFLA_GENEVE_ID]) {
1116 __u32 vni = nla_get_u32(data[IFLA_GENEVE_ID]);
1118 if (vni >= GENEVE_VID_MASK)
1119 return -ERANGE;
1122 return 0;
1125 static struct geneve_dev *geneve_find_dev(struct geneve_net *gn,
1126 __be16 dst_port,
1127 union geneve_addr *remote,
1128 u8 vni[],
1129 bool *tun_on_same_port,
1130 bool *tun_collect_md)
1132 struct geneve_dev *geneve, *t;
1134 *tun_on_same_port = false;
1135 *tun_collect_md = false;
1136 t = NULL;
1137 list_for_each_entry(geneve, &gn->geneve_list, next) {
1138 if (geneve->dst_port == dst_port) {
1139 *tun_collect_md = geneve->collect_md;
1140 *tun_on_same_port = true;
1142 if (!memcmp(vni, geneve->vni, sizeof(geneve->vni)) &&
1143 !memcmp(remote, &geneve->remote, sizeof(geneve->remote)) &&
1144 dst_port == geneve->dst_port)
1145 t = geneve;
1147 return t;
1150 static int geneve_configure(struct net *net, struct net_device *dev,
1151 union geneve_addr *remote,
1152 __u32 vni, __u8 ttl, __u8 tos, __be16 dst_port,
1153 bool metadata)
1155 struct geneve_net *gn = net_generic(net, geneve_net_id);
1156 struct geneve_dev *t, *geneve = netdev_priv(dev);
1157 bool tun_collect_md, tun_on_same_port;
1158 int err, encap_len;
1160 if (!remote)
1161 return -EINVAL;
1162 if (metadata &&
1163 (remote->sa.sa_family != AF_UNSPEC || vni || tos || ttl))
1164 return -EINVAL;
1166 geneve->net = net;
1167 geneve->dev = dev;
1169 geneve->vni[0] = (vni & 0x00ff0000) >> 16;
1170 geneve->vni[1] = (vni & 0x0000ff00) >> 8;
1171 geneve->vni[2] = vni & 0x000000ff;
1173 if ((remote->sa.sa_family == AF_INET &&
1174 IN_MULTICAST(ntohl(remote->sin.sin_addr.s_addr))) ||
1175 (remote->sa.sa_family == AF_INET6 &&
1176 ipv6_addr_is_multicast(&remote->sin6.sin6_addr)))
1177 return -EINVAL;
1178 geneve->remote = *remote;
1180 geneve->ttl = ttl;
1181 geneve->tos = tos;
1182 geneve->dst_port = dst_port;
1183 geneve->collect_md = metadata;
1185 t = geneve_find_dev(gn, dst_port, remote, geneve->vni,
1186 &tun_on_same_port, &tun_collect_md);
1187 if (t)
1188 return -EBUSY;
1190 /* make enough headroom for basic scenario */
1191 encap_len = GENEVE_BASE_HLEN + ETH_HLEN;
1192 if (remote->sa.sa_family == AF_INET)
1193 encap_len += sizeof(struct iphdr);
1194 else
1195 encap_len += sizeof(struct ipv6hdr);
1196 dev->needed_headroom = encap_len + ETH_HLEN;
1198 if (metadata) {
1199 if (tun_on_same_port)
1200 return -EPERM;
1201 } else {
1202 if (tun_collect_md)
1203 return -EPERM;
1206 err = register_netdevice(dev);
1207 if (err)
1208 return err;
1210 list_add(&geneve->next, &gn->geneve_list);
1211 return 0;
1214 static int geneve_newlink(struct net *net, struct net_device *dev,
1215 struct nlattr *tb[], struct nlattr *data[])
1217 __be16 dst_port = htons(GENEVE_UDP_PORT);
1218 __u8 ttl = 0, tos = 0;
1219 bool metadata = false;
1220 union geneve_addr remote = geneve_remote_unspec;
1221 __u32 vni = 0;
1223 if (data[IFLA_GENEVE_REMOTE] && data[IFLA_GENEVE_REMOTE6])
1224 return -EINVAL;
1226 if (data[IFLA_GENEVE_REMOTE]) {
1227 remote.sa.sa_family = AF_INET;
1228 remote.sin.sin_addr.s_addr =
1229 nla_get_in_addr(data[IFLA_GENEVE_REMOTE]);
1232 if (data[IFLA_GENEVE_REMOTE6]) {
1233 if (!IS_ENABLED(CONFIG_IPV6))
1234 return -EPFNOSUPPORT;
1236 remote.sa.sa_family = AF_INET6;
1237 remote.sin6.sin6_addr =
1238 nla_get_in6_addr(data[IFLA_GENEVE_REMOTE6]);
1240 if (ipv6_addr_type(&remote.sin6.sin6_addr) &
1241 IPV6_ADDR_LINKLOCAL) {
1242 netdev_dbg(dev, "link-local remote is unsupported\n");
1243 return -EINVAL;
1247 if (data[IFLA_GENEVE_ID])
1248 vni = nla_get_u32(data[IFLA_GENEVE_ID]);
1250 if (data[IFLA_GENEVE_TTL])
1251 ttl = nla_get_u8(data[IFLA_GENEVE_TTL]);
1253 if (data[IFLA_GENEVE_TOS])
1254 tos = nla_get_u8(data[IFLA_GENEVE_TOS]);
1256 if (data[IFLA_GENEVE_PORT])
1257 dst_port = nla_get_be16(data[IFLA_GENEVE_PORT]);
1259 if (data[IFLA_GENEVE_COLLECT_METADATA])
1260 metadata = true;
1262 return geneve_configure(net, dev, &remote, vni, ttl, tos, dst_port,
1263 metadata);
1266 static void geneve_dellink(struct net_device *dev, struct list_head *head)
1268 struct geneve_dev *geneve = netdev_priv(dev);
1270 list_del(&geneve->next);
1271 unregister_netdevice_queue(dev, head);
1274 static size_t geneve_get_size(const struct net_device *dev)
1276 return nla_total_size(sizeof(__u32)) + /* IFLA_GENEVE_ID */
1277 nla_total_size(sizeof(struct in6_addr)) + /* IFLA_GENEVE_REMOTE{6} */
1278 nla_total_size(sizeof(__u8)) + /* IFLA_GENEVE_TTL */
1279 nla_total_size(sizeof(__u8)) + /* IFLA_GENEVE_TOS */
1280 nla_total_size(sizeof(__be16)) + /* IFLA_GENEVE_PORT */
1281 nla_total_size(0) + /* IFLA_GENEVE_COLLECT_METADATA */
1285 static int geneve_fill_info(struct sk_buff *skb, const struct net_device *dev)
1287 struct geneve_dev *geneve = netdev_priv(dev);
1288 __u32 vni;
1290 vni = (geneve->vni[0] << 16) | (geneve->vni[1] << 8) | geneve->vni[2];
1291 if (nla_put_u32(skb, IFLA_GENEVE_ID, vni))
1292 goto nla_put_failure;
1294 if (geneve->remote.sa.sa_family == AF_INET) {
1295 if (nla_put_in_addr(skb, IFLA_GENEVE_REMOTE,
1296 geneve->remote.sin.sin_addr.s_addr))
1297 goto nla_put_failure;
1298 #if IS_ENABLED(CONFIG_IPV6)
1299 } else {
1300 if (nla_put_in6_addr(skb, IFLA_GENEVE_REMOTE6,
1301 &geneve->remote.sin6.sin6_addr))
1302 goto nla_put_failure;
1303 #endif
1306 if (nla_put_u8(skb, IFLA_GENEVE_TTL, geneve->ttl) ||
1307 nla_put_u8(skb, IFLA_GENEVE_TOS, geneve->tos))
1308 goto nla_put_failure;
1310 if (nla_put_be16(skb, IFLA_GENEVE_PORT, geneve->dst_port))
1311 goto nla_put_failure;
1313 if (geneve->collect_md) {
1314 if (nla_put_flag(skb, IFLA_GENEVE_COLLECT_METADATA))
1315 goto nla_put_failure;
1318 return 0;
1320 nla_put_failure:
1321 return -EMSGSIZE;
1324 static struct rtnl_link_ops geneve_link_ops __read_mostly = {
1325 .kind = "geneve",
1326 .maxtype = IFLA_GENEVE_MAX,
1327 .policy = geneve_policy,
1328 .priv_size = sizeof(struct geneve_dev),
1329 .setup = geneve_setup,
1330 .validate = geneve_validate,
1331 .newlink = geneve_newlink,
1332 .dellink = geneve_dellink,
1333 .get_size = geneve_get_size,
1334 .fill_info = geneve_fill_info,
1337 struct net_device *geneve_dev_create_fb(struct net *net, const char *name,
1338 u8 name_assign_type, u16 dst_port)
1340 struct nlattr *tb[IFLA_MAX + 1];
1341 struct net_device *dev;
1342 int err;
1344 memset(tb, 0, sizeof(tb));
1345 dev = rtnl_create_link(net, name, name_assign_type,
1346 &geneve_link_ops, tb);
1347 if (IS_ERR(dev))
1348 return dev;
1350 err = geneve_configure(net, dev, &geneve_remote_unspec,
1351 0, 0, 0, htons(dst_port), true);
1352 if (err) {
1353 free_netdev(dev);
1354 return ERR_PTR(err);
1356 return dev;
1358 EXPORT_SYMBOL_GPL(geneve_dev_create_fb);
1360 static __net_init int geneve_init_net(struct net *net)
1362 struct geneve_net *gn = net_generic(net, geneve_net_id);
1364 INIT_LIST_HEAD(&gn->geneve_list);
1365 INIT_LIST_HEAD(&gn->sock_list);
1366 return 0;
1369 static void __net_exit geneve_exit_net(struct net *net)
1371 struct geneve_net *gn = net_generic(net, geneve_net_id);
1372 struct geneve_dev *geneve, *next;
1373 struct net_device *dev, *aux;
1374 LIST_HEAD(list);
1376 rtnl_lock();
1378 /* gather any geneve devices that were moved into this ns */
1379 for_each_netdev_safe(net, dev, aux)
1380 if (dev->rtnl_link_ops == &geneve_link_ops)
1381 unregister_netdevice_queue(dev, &list);
1383 /* now gather any other geneve devices that were created in this ns */
1384 list_for_each_entry_safe(geneve, next, &gn->geneve_list, next) {
1385 /* If geneve->dev is in the same netns, it was already added
1386 * to the list by the previous loop.
1388 if (!net_eq(dev_net(geneve->dev), net))
1389 unregister_netdevice_queue(geneve->dev, &list);
1392 /* unregister the devices gathered above */
1393 unregister_netdevice_many(&list);
1394 rtnl_unlock();
1397 static struct pernet_operations geneve_net_ops = {
1398 .init = geneve_init_net,
1399 .exit = geneve_exit_net,
1400 .id = &geneve_net_id,
1401 .size = sizeof(struct geneve_net),
1404 static int __init geneve_init_module(void)
1406 int rc;
1408 rc = register_pernet_subsys(&geneve_net_ops);
1409 if (rc)
1410 goto out1;
1412 rc = rtnl_link_register(&geneve_link_ops);
1413 if (rc)
1414 goto out2;
1416 return 0;
1417 out2:
1418 unregister_pernet_subsys(&geneve_net_ops);
1419 out1:
1420 return rc;
1422 late_initcall(geneve_init_module);
1424 static void __exit geneve_cleanup_module(void)
1426 rtnl_link_unregister(&geneve_link_ops);
1427 unregister_pernet_subsys(&geneve_net_ops);
1429 module_exit(geneve_cleanup_module);
1431 MODULE_LICENSE("GPL");
1432 MODULE_VERSION(GENEVE_NETDEV_VER);
1433 MODULE_AUTHOR("John W. Linville <linville@tuxdriver.com>");
1434 MODULE_DESCRIPTION("Interface driver for GENEVE encapsulated traffic");
1435 MODULE_ALIAS_RTNL_LINK("geneve");