datapath: Add support for lwtunnel
[cascardo/ovs.git] / datapath / linux / compat / lisp.c
1 /*
2  * Copyright (c) 2015 Nicira, Inc.
3  * Copyright (c) 2013 Cisco Systems, Inc.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of version 2 of the GNU General Public
7  * License as published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * General Public License for more details.
13  *
14  */
15
16 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
17
18 #include <linux/version.h>
19
20 #include <linux/in.h>
21 #include <linux/ip.h>
22 #include <linux/net.h>
23 #include <linux/module.h>
24 #include <linux/rculist.h>
25 #include <linux/udp.h>
26
27 #include <net/icmp.h>
28 #include <net/ip.h>
29 #include <net/lisp.h>
30 #include <net/net_namespace.h>
31 #include <net/netns/generic.h>
32 #include <net/route.h>
33 #include <net/udp.h>
34 #include <net/udp_tunnel.h>
35 #include <net/xfrm.h>
36
37 #include "datapath.h"
38 #include "gso.h"
39 #include "vport.h"
40 #include "gso.h"
41 #include "vport-netdev.h"
42
43 #define LISP_UDP_PORT           4341
44 #define LISP_NETDEV_VER         "0.1"
45 static int lisp_net_id;
46
47 /* Pseudo network device */
48 struct lisp_dev {
49         struct net         *net;        /* netns for packet i/o */
50         struct net_device  *dev;        /* netdev for lisp tunnel */
51         struct socket           *sock;
52         __be16             dst_port;
53         struct list_head   next;
54 };
55
56 /* per-network namespace private data for this module */
57 struct lisp_net {
58         struct list_head lisp_list;
59 };
60
61 /*
62  *  LISP encapsulation header:
63  *
64  *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
65  *  |N|L|E|V|I|flags|            Nonce/Map-Version                  |
66  *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
67  *  |                 Instance ID/Locator Status Bits               |
68  *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
69  *
70  */
71
72 /**
73  * struct lisphdr - LISP header
74  * @nonce_present: Flag indicating the presence of a 24 bit nonce value.
75  * @locator_status_bits_present: Flag indicating the presence of Locator Status
76  *                               Bits (LSB).
77  * @solicit_echo_nonce: Flag indicating the use of the echo noncing mechanism.
78  * @map_version_present: Flag indicating the use of mapping versioning.
79  * @instance_id_present: Flag indicating the presence of a 24 bit Instance ID.
80  * @reserved_flags: 3 bits reserved for future flags.
81  * @nonce: 24 bit nonce value.
82  * @map_version: 24 bit mapping version.
83  * @locator_status_bits: Locator Status Bits: 32 bits when instance_id_present
84  *                       is not set, 8 bits when it is.
85  * @instance_id: 24 bit Instance ID
86  */
87 struct lisphdr {
88 #ifdef __LITTLE_ENDIAN_BITFIELD
89         __u8 reserved_flags:3;
90         __u8 instance_id_present:1;
91         __u8 map_version_present:1;
92         __u8 solicit_echo_nonce:1;
93         __u8 locator_status_bits_present:1;
94         __u8 nonce_present:1;
95 #else
96         __u8 nonce_present:1;
97         __u8 locator_status_bits_present:1;
98         __u8 solicit_echo_nonce:1;
99         __u8 map_version_present:1;
100         __u8 instance_id_present:1;
101         __u8 reserved_flags:3;
102 #endif
103         union {
104                 __u8 nonce[3];
105                 __u8 map_version[3];
106         } u1;
107         union {
108                 __be32 locator_status_bits;
109                 struct {
110                         __u8 instance_id[3];
111                         __u8 locator_status_bits;
112                 } word2;
113         } u2;
114 };
115
116 #define LISP_HLEN (sizeof(struct udphdr) + sizeof(struct lisphdr))
117
118 static inline struct lisphdr *lisp_hdr(const struct sk_buff *skb)
119 {
120         return (struct lisphdr *)(udp_hdr(skb) + 1);
121 }
122
123 /* Convert 64 bit tunnel ID to 24 bit Instance ID. */
124 static void tunnel_id_to_instance_id(__be64 tun_id, __u8 *iid)
125 {
126
127 #ifdef __BIG_ENDIAN
128         iid[0] = (__force __u8)(tun_id >> 16);
129         iid[1] = (__force __u8)(tun_id >> 8);
130         iid[2] = (__force __u8)tun_id;
131 #else
132         iid[0] = (__force __u8)((__force u64)tun_id >> 40);
133         iid[1] = (__force __u8)((__force u64)tun_id >> 48);
134         iid[2] = (__force __u8)((__force u64)tun_id >> 56);
135 #endif
136 }
137
138 /* Convert 24 bit Instance ID to 64 bit tunnel ID. */
139 static __be64 instance_id_to_tunnel_id(__u8 *iid)
140 {
141 #ifdef __BIG_ENDIAN
142         return (iid[0] << 16) | (iid[1] << 8) | iid[2];
143 #else
144         return (__force __be64)(((__force u64)iid[0] << 40) |
145                         ((__force u64)iid[1] << 48) |
146                         ((__force u64)iid[2] << 56));
147 #endif
148 }
149
150 /* Compute source UDP port for outgoing packet.
151  * Currently we use the flow hash.
152  */
153 static u16 get_src_port(struct net *net, struct sk_buff *skb)
154 {
155         u32 hash = skb_get_hash(skb);
156         unsigned int range;
157         int high;
158         int low;
159
160         if (!hash) {
161                 if (skb->protocol == htons(ETH_P_IP)) {
162                         struct iphdr *iph;
163                         int size = (sizeof(iph->saddr) * 2) / sizeof(u32);
164
165                         iph = (struct iphdr *) skb_network_header(skb);
166                         hash = jhash2((const u32 *)&iph->saddr, size, 0);
167                 } else if (skb->protocol == htons(ETH_P_IPV6)) {
168                         struct ipv6hdr *ipv6hdr;
169
170                         ipv6hdr = (struct ipv6hdr *) skb_network_header(skb);
171                         hash = jhash2((const u32 *)&ipv6hdr->saddr,
172                                         (sizeof(struct in6_addr) * 2) / sizeof(u32), 0);
173                 } else {
174                         pr_warn_once("LISP inner protocol is not IP when "
175                                         "calculating hash.\n");
176                 }
177         }
178
179         inet_get_local_port_range(net, &low, &high);
180         range = (high - low) + 1;
181         return (((u64) hash * range) >> 32) + low;
182 }
183
184 static void lisp_build_header(struct sk_buff *skb,
185                               const struct ip_tunnel_key *tun_key)
186 {
187         struct lisphdr *lisph;
188
189         lisph = (struct lisphdr *)__skb_push(skb, sizeof(struct lisphdr));
190         lisph->nonce_present = 0;       /* We don't support echo nonce algorithm */
191         lisph->locator_status_bits_present = 1; /* Set LSB */
192         lisph->solicit_echo_nonce = 0;  /* No echo noncing */
193         lisph->map_version_present = 0; /* No mapping versioning, nonce instead */
194         lisph->instance_id_present = 1; /* Store the tun_id as Instance ID  */
195         lisph->reserved_flags = 0;      /* Reserved flags, set to 0  */
196
197         lisph->u1.nonce[0] = 0;
198         lisph->u1.nonce[1] = 0;
199         lisph->u1.nonce[2] = 0;
200
201         tunnel_id_to_instance_id(tun_key->tun_id, &lisph->u2.word2.instance_id[0]);
202         lisph->u2.word2.locator_status_bits = 1;
203 }
204
205 /* Called with rcu_read_lock and BH disabled. */
206 static int lisp_rcv(struct sock *sk, struct sk_buff *skb)
207 {
208         struct net_device *dev;
209         struct lisphdr *lisph;
210         struct iphdr *inner_iph;
211         struct metadata_dst *tun_dst;
212 #ifndef HAVE_METADATA_DST
213         struct metadata_dst temp;
214 #endif
215         __be64 key;
216         struct ethhdr *ethh;
217         __be16 protocol;
218
219         dev = rcu_dereference_sk_user_data(sk);
220         if (unlikely(!dev))
221                 goto error;
222
223         if (iptunnel_pull_header(skb, LISP_HLEN, 0))
224                 goto error;
225
226         lisph = lisp_hdr(skb);
227
228         if (lisph->instance_id_present != 1)
229                 key = 0;
230         else
231                 key = instance_id_to_tunnel_id(&lisph->u2.word2.instance_id[0]);
232
233         /* Save outer tunnel values */
234 #ifndef HAVE_METADATA_DST
235         tun_dst = &temp;
236         ovs_udp_tun_rx_dst(&tun_dst->u.tun_info, skb, AF_INET, TUNNEL_KEY, key, 0);
237 #else
238         tun_dst = udp_tun_rx_dst(skb, AF_INET, TUNNEL_KEY, key, 0);
239 #endif
240         /* Drop non-IP inner packets */
241         inner_iph = (struct iphdr *)(lisph + 1);
242         switch (inner_iph->version) {
243         case 4:
244                 protocol = htons(ETH_P_IP);
245                 break;
246         case 6:
247                 protocol = htons(ETH_P_IPV6);
248                 break;
249         default:
250                 goto error;
251         }
252         skb->protocol = protocol;
253
254         /* Add Ethernet header */
255         ethh = (struct ethhdr *)skb_push(skb, ETH_HLEN);
256         memset(ethh, 0, ETH_HLEN);
257         ethh->h_dest[0] = 0x02;
258         ethh->h_source[0] = 0x02;
259         ethh->h_proto = protocol;
260
261         ovs_ip_tunnel_rcv(dev, skb, tun_dst);
262         goto out;
263
264 error:
265         kfree_skb(skb);
266 out:
267         return 0;
268 }
269
270 netdev_tx_t rpl_lisp_xmit(struct sk_buff *skb)
271 {
272         struct net_device *dev = skb->dev;
273         struct lisp_dev *lisp_dev = netdev_priv(dev);
274         struct net *net = lisp_dev->net;
275         int network_offset = skb_network_offset(skb);
276         struct ip_tunnel_info *info;
277         struct ip_tunnel_key *tun_key;
278         struct rtable *rt;
279         int min_headroom;
280         __be16 src_port, dst_port;
281         struct flowi4 fl;
282         __be16 df;
283         int err;
284
285         info = skb_tunnel_info(skb);
286         if (unlikely(!info)) {
287                 err = -EINVAL;
288                 goto error;
289         }
290
291         if (skb->protocol != htons(ETH_P_IP) &&
292                         skb->protocol != htons(ETH_P_IPV6)) {
293                 err = 0;
294                 goto error;
295         }
296
297         tun_key = &info->key;
298
299         /* Route lookup */
300         memset(&fl, 0, sizeof(fl));
301         fl.daddr = tun_key->u.ipv4.dst;
302         fl.saddr = tun_key->u.ipv4.src;
303         fl.flowi4_tos = RT_TOS(tun_key->tos);
304         fl.flowi4_mark = skb->mark;
305         fl.flowi4_proto = IPPROTO_UDP;
306         rt = ip_route_output_key(net, &fl);
307         if (IS_ERR(rt)) {
308                 err = PTR_ERR(rt);
309                 goto error;
310         }
311
312         min_headroom = LL_RESERVED_SPACE(rt_dst(rt).dev) + rt_dst(rt).header_len
313                 + sizeof(struct iphdr) + LISP_HLEN;
314
315         if (skb_headroom(skb) < min_headroom || skb_header_cloned(skb)) {
316                 int head_delta = SKB_DATA_ALIGN(min_headroom -
317                                 skb_headroom(skb) +
318                                 16);
319
320                 err = pskb_expand_head(skb, max_t(int, head_delta, 0),
321                                 0, GFP_ATOMIC);
322                 if (unlikely(err))
323                         goto err_free_rt;
324         }
325
326         /* Reset l2 headers. */
327         skb_pull(skb, network_offset);
328         skb_reset_mac_header(skb);
329         vlan_set_tci(skb, 0);
330
331         skb = udp_tunnel_handle_offloads(skb, false, 0, false);
332         if (IS_ERR(skb)) {
333                 err = PTR_ERR(skb);
334                 skb = NULL;
335                 goto err_free_rt;
336         }
337
338         src_port = htons(get_src_port(net, skb));
339         dst_port = lisp_dev->dst_port;
340
341         lisp_build_header(skb, tun_key);
342
343         skb->ignore_df = 1;
344
345         ovs_skb_set_inner_protocol(skb, skb->protocol);
346
347         df = tun_key->tun_flags & TUNNEL_DONT_FRAGMENT ? htons(IP_DF) : 0;
348         err = udp_tunnel_xmit_skb(rt, lisp_dev->sock->sk, skb,
349                         fl.saddr, tun_key->u.ipv4.dst,
350                         tun_key->tos, tun_key->ttl,
351                         df, src_port, dst_port, false, true);
352
353         iptunnel_xmit_stats(err, &dev->stats, (struct pcpu_sw_netstats __percpu *)dev->tstats);
354         return NETDEV_TX_OK;
355
356 err_free_rt:
357         ip_rt_put(rt);
358 error:
359         kfree_skb(skb);
360         return NETDEV_TX_OK;
361 }
362 EXPORT_SYMBOL(rpl_lisp_xmit);
363
364 #ifdef HAVE_DEV_TSTATS
365 /* Setup stats when device is created */
366 static int lisp_init(struct net_device *dev)
367 {
368         dev->tstats = (typeof(dev->tstats)) netdev_alloc_pcpu_stats(struct pcpu_sw_netstats);
369         if (!dev->tstats)
370                 return -ENOMEM;
371
372         return 0;
373 }
374
375 static void lisp_uninit(struct net_device *dev)
376 {
377         free_percpu(dev->tstats);
378 }
379 #endif
380
381 static struct socket *create_sock(struct net *net, bool ipv6,
382                                        __be16 port)
383 {
384         struct socket *sock;
385         struct udp_port_cfg udp_conf;
386         int err;
387
388         memset(&udp_conf, 0, sizeof(udp_conf));
389
390         if (ipv6) {
391                 udp_conf.family = AF_INET6;
392         } else {
393                 udp_conf.family = AF_INET;
394                 udp_conf.local_ip.s_addr = htonl(INADDR_ANY);
395         }
396
397         udp_conf.local_udp_port = port;
398
399         /* Open UDP socket */
400         err = udp_sock_create(net, &udp_conf, &sock);
401         if (err < 0)
402                 return ERR_PTR(err);
403
404         return sock;
405 }
406
407 static int lisp_open(struct net_device *dev)
408 {
409         struct lisp_dev *lisp = netdev_priv(dev);
410         struct udp_tunnel_sock_cfg tunnel_cfg;
411         struct net *net = lisp->net;
412
413         lisp->sock = create_sock(net, false, lisp->dst_port);
414         if (IS_ERR(lisp->sock))
415                 return PTR_ERR(lisp->sock);
416
417         /* Mark socket as an encapsulation socket */
418         tunnel_cfg.sk_user_data = dev;
419         tunnel_cfg.encap_type = 1;
420         tunnel_cfg.encap_rcv = lisp_rcv;
421         tunnel_cfg.encap_destroy = NULL;
422         setup_udp_tunnel_sock(net, lisp->sock, &tunnel_cfg);
423         return 0;
424 }
425
426 static int lisp_stop(struct net_device *dev)
427 {
428         struct lisp_dev *lisp = netdev_priv(dev);
429
430         udp_tunnel_sock_release(lisp->sock);
431         lisp->sock = NULL;
432         return 0;
433 }
434
435 static netdev_tx_t lisp_dev_xmit(struct sk_buff *skb, struct net_device *dev)
436 {
437 #ifdef HAVE_METADATA_DST
438         return rpl_lisp_xmit(skb);
439 #else
440         /* Drop All packets coming from networking stack. OVS-CB is
441          * not initialized for these packets.
442          */
443
444         dev_kfree_skb(skb);
445         dev->stats.tx_dropped++;
446         return NETDEV_TX_OK;
447 #endif
448 }
449
450 static const struct net_device_ops lisp_netdev_ops = {
451 #ifdef HAVE_DEV_TSTATS
452         .ndo_init               = lisp_init,
453         .ndo_uninit             = lisp_uninit,
454         .ndo_get_stats64        = ip_tunnel_get_stats64,
455 #endif
456         .ndo_open               = lisp_open,
457         .ndo_stop               = lisp_stop,
458         .ndo_start_xmit         = lisp_dev_xmit,
459         .ndo_change_mtu         = eth_change_mtu,
460         .ndo_validate_addr      = eth_validate_addr,
461         .ndo_set_mac_address    = eth_mac_addr,
462 };
463
464 static void lisp_get_drvinfo(struct net_device *dev,
465                 struct ethtool_drvinfo *drvinfo)
466 {
467         strlcpy(drvinfo->version, LISP_NETDEV_VER, sizeof(drvinfo->version));
468         strlcpy(drvinfo->driver, "lisp", sizeof(drvinfo->driver));
469 }
470
471 static const struct ethtool_ops lisp_ethtool_ops = {
472         .get_drvinfo    = lisp_get_drvinfo,
473         .get_link       = ethtool_op_get_link,
474 };
475
476 /* Info for udev, that this is a virtual tunnel endpoint */
477 static struct device_type lisp_type = {
478         .name = "lisp",
479 };
480
481 /* Initialize the device structure. */
482 static void lisp_setup(struct net_device *dev)
483 {
484         ether_setup(dev);
485
486         dev->netdev_ops = &lisp_netdev_ops;
487         dev->ethtool_ops = &lisp_ethtool_ops;
488         dev->destructor = free_netdev;
489
490         SET_NETDEV_DEVTYPE(dev, &lisp_type);
491
492         dev->features    |= NETIF_F_LLTX | NETIF_F_NETNS_LOCAL;
493         dev->features    |= NETIF_F_SG | NETIF_F_HW_CSUM;
494         dev->features    |= NETIF_F_RXCSUM;
495         dev->features    |= NETIF_F_GSO_SOFTWARE;
496
497 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,39)
498         dev->hw_features |= NETIF_F_SG | NETIF_F_HW_CSUM | NETIF_F_RXCSUM;
499         dev->hw_features |= NETIF_F_GSO_SOFTWARE;
500 #endif
501 #ifdef HAVE_METADATA_DST
502         netif_keep_dst(dev);
503 #endif
504         dev->priv_flags |= IFF_LIVE_ADDR_CHANGE | IFF_NO_QUEUE;
505         eth_hw_addr_random(dev);
506 }
507
508 static const struct nla_policy lisp_policy[IFLA_LISP_MAX + 1] = {
509         [IFLA_LISP_PORT]              = { .type = NLA_U16 },
510 };
511
512 static int lisp_validate(struct nlattr *tb[], struct nlattr *data[])
513 {
514         if (tb[IFLA_ADDRESS]) {
515                 if (nla_len(tb[IFLA_ADDRESS]) != ETH_ALEN)
516                         return -EINVAL;
517
518                 if (!is_valid_ether_addr(nla_data(tb[IFLA_ADDRESS])))
519                         return -EADDRNOTAVAIL;
520         }
521
522         return 0;
523 }
524
525 static struct lisp_dev *find_dev(struct net *net, __be16 dst_port)
526 {
527         struct lisp_net *ln = net_generic(net, lisp_net_id);
528         struct lisp_dev *dev;
529
530         list_for_each_entry(dev, &ln->lisp_list, next) {
531                 if (dev->dst_port == dst_port)
532                         return dev;
533         }
534         return NULL;
535 }
536
537 static int lisp_configure(struct net *net, struct net_device *dev,
538                           __be16 dst_port)
539 {
540         struct lisp_net *ln = net_generic(net, lisp_net_id);
541         struct lisp_dev *lisp = netdev_priv(dev);
542         int err;
543
544         lisp->net = net;
545         lisp->dev = dev;
546
547         lisp->dst_port = dst_port;
548
549         if (find_dev(net, dst_port))
550                 return -EBUSY;
551
552         err = register_netdevice(dev);
553         if (err)
554                 return err;
555
556         list_add(&lisp->next, &ln->lisp_list);
557         return 0;
558 }
559
560 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,39)
561 static int lisp_newlink(struct net *net, struct net_device *dev,
562                 struct nlattr *tb[], struct nlattr *data[])
563 {
564 #else
565 static int lisp_newlink(struct net_device *dev,
566                 struct nlattr *tb[], struct nlattr *data[])
567
568 {
569         struct net *net = &init_net;
570 #endif
571         __be16 dst_port = htons(LISP_UDP_PORT);
572
573         if (data[IFLA_LISP_PORT])
574                 dst_port = nla_get_be16(data[IFLA_LISP_PORT]);
575
576         return lisp_configure(net, dev, dst_port);
577 }
578
579 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,39)
580 static void lisp_dellink(struct net_device *dev, struct list_head *head)
581 #else
582 static void lisp_dellink(struct net_device *dev)
583 #endif
584 {
585         struct lisp_dev *lisp = netdev_priv(dev);
586
587         list_del(&lisp->next);
588         unregister_netdevice_queue(dev, head);
589 }
590
591 static size_t lisp_get_size(const struct net_device *dev)
592 {
593         return nla_total_size(sizeof(__be32));  /* IFLA_LISP_PORT */
594 }
595
596 static int lisp_fill_info(struct sk_buff *skb, const struct net_device *dev)
597 {
598         struct lisp_dev *lisp = netdev_priv(dev);
599
600         if (nla_put_be16(skb, IFLA_LISP_PORT, lisp->dst_port))
601                 goto nla_put_failure;
602
603         return 0;
604
605 nla_put_failure:
606         return -EMSGSIZE;
607 }
608
609 static struct rtnl_link_ops lisp_link_ops __read_mostly = {
610         .kind           = "lisp",
611         .maxtype        = IFLA_LISP_MAX,
612         .policy         = lisp_policy,
613         .priv_size      = sizeof(struct lisp_dev),
614         .setup          = lisp_setup,
615         .validate       = lisp_validate,
616         .newlink        = lisp_newlink,
617         .dellink        = lisp_dellink,
618         .get_size       = lisp_get_size,
619         .fill_info      = lisp_fill_info,
620 };
621
622 struct net_device *rpl_lisp_dev_create_fb(struct net *net, const char *name,
623                                       u8 name_assign_type, u16 dst_port)
624 {
625         struct nlattr *tb[IFLA_MAX + 1];
626         struct net_device *dev;
627         int err;
628
629         memset(tb, 0, sizeof(tb));
630         dev = rtnl_create_link(net, (char *) name, name_assign_type,
631                         &lisp_link_ops, tb);
632         if (IS_ERR(dev))
633                 return dev;
634
635         err = lisp_configure(net, dev, htons(dst_port));
636         if (err) {
637                 free_netdev(dev);
638                 return ERR_PTR(err);
639         }
640         return dev;
641 }
642 EXPORT_SYMBOL_GPL(rpl_lisp_dev_create_fb);
643
644 static int lisp_init_net(struct net *net)
645 {
646         struct lisp_net *ln = net_generic(net, lisp_net_id);
647
648         INIT_LIST_HEAD(&ln->lisp_list);
649         return 0;
650 }
651
652 static void lisp_exit_net(struct net *net)
653 {
654         struct lisp_net *ln = net_generic(net, lisp_net_id);
655         struct lisp_dev *lisp, *next;
656         struct net_device *dev, *aux;
657         LIST_HEAD(list);
658
659         rtnl_lock();
660
661         /* gather any lisp devices that were moved into this ns */
662         for_each_netdev_safe(net, dev, aux)
663                 if (dev->rtnl_link_ops == &lisp_link_ops)
664                         unregister_netdevice_queue(dev, &list);
665
666         list_for_each_entry_safe(lisp, next, &ln->lisp_list, next) {
667                 /* If lisp->dev is in the same netns, it was already added
668                  * to the lisp by the previous loop.
669                  */
670                 if (!net_eq(dev_net(lisp->dev), net))
671                         unregister_netdevice_queue(lisp->dev, &list);
672         }
673
674         /* unregister the devices gathered above */
675         unregister_netdevice_many(&list);
676         rtnl_unlock();
677 }
678
679 static struct pernet_operations lisp_net_ops = {
680         .init = lisp_init_net,
681         .exit = lisp_exit_net,
682         .id   = &lisp_net_id,
683         .size = sizeof(struct lisp_net),
684 };
685
686 DEFINE_COMPAT_PNET_REG_FUNC(device)
687 int rpl_lisp_init_module(void)
688 {
689         int rc;
690
691         rc = register_pernet_subsys(&lisp_net_ops);
692         if (rc)
693                 goto out1;
694
695         rc = rtnl_link_register(&lisp_link_ops);
696         if (rc)
697                 goto out2;
698
699         pr_info("LISP tunneling driver\n");
700         return 0;
701 out2:
702         unregister_pernet_subsys(&lisp_net_ops);
703 out1:
704         return rc;
705 }
706
707 void rpl_lisp_cleanup_module(void)
708 {
709         rtnl_link_unregister(&lisp_link_ops);
710         unregister_pernet_subsys(&lisp_net_ops);
711 }