2 * Linux NET3: IP/IP protocol decoder.
4 * Version: $Id: ipip.c,v 1.50 2001/10/02 02:22:36 davem Exp $
7 * Sam Lantinga (slouken@cs.ucdavis.edu) 02/01/95
10 * Alan Cox : Merged and made usable non modular (its so tiny its silly as
11 * a module taking up 2 pages).
12 * Alan Cox : Fixed bug with 1.3.18 and IPIP not working (now needs to set skb->h.iph)
13 * to keep ip_forward happy.
14 * Alan Cox : More fixes for 1.3.21, and firewall fix. Maybe this will work soon 8).
15 * Kai Schulte : Fixed #defines for IP_FIREWALL->FIREWALL
16 * David Woodhouse : Perform some basic ICMP handling.
17 * IPIP Routing without decapsulation.
18 * Carlos Picoto : GRE over IP support
19 * Alexey Kuznetsov: Reworked. Really, now it is truncated version of ipv4/ip_gre.c.
20 * I do not want to merge them together.
22 * This program is free software; you can redistribute it and/or
23 * modify it under the terms of the GNU General Public License
24 * as published by the Free Software Foundation; either version
25 * 2 of the License, or (at your option) any later version.
29 /* tunnel.c: an IP tunnel driver
31 The purpose of this driver is to provide an IP tunnel through
32 which you can tunnel network traffic transparently across subnets.
34 This was written by looking at Nick Holloway's dummy driver
35 Thanks for the great code!
37 -Sam Lantinga (slouken@cs.ucdavis.edu) 02/01/95
40 Cleaned up the code a little and added some pre-1.3.0 tweaks.
41 dev->hard_header/hard_header_len changed to use no headers.
42 Comments/bracketing tweaked.
43 Made the tunnels use dev->name not tunnel: when error reporting.
46 -Alan Cox (Alan.Cox@linux.org) 21 March 95
49 Changed to tunnel to destination gateway in addition to the
50 tunnel's pointopoint address
51 Almost completely rewritten
52 Note: There is currently no firewall or ICMP handling done.
54 -Sam Lantinga (slouken@cs.ucdavis.edu) 02/13/96
58 /* Things I wish I had known when writing the tunnel driver:
60 When the tunnel_xmit() function is called, the skb contains the
61 packet to be sent (plus a great deal of extra info), and dev
62 contains the tunnel device that _we_ are.
64 When we are passed a packet, we are expected to fill in the
65 source address with our source IP address.
67 What is the proper way to allocate, copy and free a buffer?
68 After you allocate it, it is a "0 length" chunk of memory
69 starting at zero. If you want to add headers to the buffer
70 later, you'll have to call "skb_reserve(skb, amount)" with
71 the amount of memory you want reserved. Then, you call
72 "skb_put(skb, amount)" with the amount of space you want in
73 the buffer. skb_put() returns a pointer to the top (#0) of
74 that buffer. skb->len is set to the amount of space you have
75 "allocated" with skb_put(). You can then write up to skb->len
76 bytes to that buffer. If you need more, you can call skb_put()
77 again with the additional amount of space you need. You can
78 find out how much more space you can allocate by calling
80 Now, to add header space, call "skb_push(skb, header_len)".
81 This creates space at the beginning of the buffer and returns
82 a pointer to this new space. If later you need to strip a
83 header from a buffer, call "skb_pull(skb, header_len)".
84 skb_headroom() will return how much space is left at the top
85 of the buffer (before the main data). Remember, this headroom
86 space must be reserved before the skb_put() function is called.
90 This version of net/ipv4/ipip.c is cloned of net/ipv4/ip_gre.c
92 For comments look at net/ipv4/ip_gre.c --ANK
96 #include <linux/capability.h>
97 #include <linux/module.h>
98 #include <linux/types.h>
99 #include <linux/kernel.h>
100 #include <asm/uaccess.h>
101 #include <linux/skbuff.h>
102 #include <linux/netdevice.h>
103 #include <linux/in.h>
104 #include <linux/tcp.h>
105 #include <linux/udp.h>
106 #include <linux/if_arp.h>
107 #include <linux/mroute.h>
108 #include <linux/init.h>
109 #include <linux/netfilter_ipv4.h>
110 #include <linux/if_ether.h>
112 #include <net/sock.h>
114 #include <net/icmp.h>
115 #include <net/ipip.h>
116 #include <net/inet_ecn.h>
117 #include <net/xfrm.h>
118 #include <net/net_namespace.h>
119 #include <net/netns/generic.h>
122 #define HASH(addr) (((__force u32)addr^((__force u32)addr>>4))&0xF)
124 static int ipip_net_id;
126 struct ip_tunnel *tunnels_r_l[HASH_SIZE];
127 struct ip_tunnel *tunnels_r[HASH_SIZE];
128 struct ip_tunnel *tunnels_l[HASH_SIZE];
129 struct ip_tunnel *tunnels_wc[1];
130 struct ip_tunnel **tunnels[4];
132 struct net_device *fb_tunnel_dev;
135 static int ipip_fb_tunnel_init(struct net_device *dev);
136 static int ipip_tunnel_init(struct net_device *dev);
137 static void ipip_tunnel_setup(struct net_device *dev);
139 static DEFINE_RWLOCK(ipip_lock);
141 static struct ip_tunnel * ipip_tunnel_lookup(struct net *net,
142 __be32 remote, __be32 local)
144 unsigned h0 = HASH(remote);
145 unsigned h1 = HASH(local);
147 struct ipip_net *ipn = net_generic(net, ipip_net_id);
149 for (t = ipn->tunnels_r_l[h0^h1]; t; t = t->next) {
150 if (local == t->parms.iph.saddr &&
151 remote == t->parms.iph.daddr && (t->dev->flags&IFF_UP))
154 for (t = ipn->tunnels_r[h0]; t; t = t->next) {
155 if (remote == t->parms.iph.daddr && (t->dev->flags&IFF_UP))
158 for (t = ipn->tunnels_l[h1]; t; t = t->next) {
159 if (local == t->parms.iph.saddr && (t->dev->flags&IFF_UP))
162 if ((t = ipn->tunnels_wc[0]) != NULL && (t->dev->flags&IFF_UP))
167 static struct ip_tunnel **__ipip_bucket(struct ipip_net *ipn,
168 struct ip_tunnel_parm *parms)
170 __be32 remote = parms->iph.daddr;
171 __be32 local = parms->iph.saddr;
183 return &ipn->tunnels[prio][h];
186 static inline struct ip_tunnel **ipip_bucket(struct ipip_net *ipn,
189 return __ipip_bucket(ipn, &t->parms);
192 static void ipip_tunnel_unlink(struct ipip_net *ipn, struct ip_tunnel *t)
194 struct ip_tunnel **tp;
196 for (tp = ipip_bucket(ipn, t); *tp; tp = &(*tp)->next) {
198 write_lock_bh(&ipip_lock);
200 write_unlock_bh(&ipip_lock);
206 static void ipip_tunnel_link(struct ipip_net *ipn, struct ip_tunnel *t)
208 struct ip_tunnel **tp = ipip_bucket(ipn, t);
211 write_lock_bh(&ipip_lock);
213 write_unlock_bh(&ipip_lock);
216 static struct ip_tunnel * ipip_tunnel_locate(struct net *net,
217 struct ip_tunnel_parm *parms, int create)
219 __be32 remote = parms->iph.daddr;
220 __be32 local = parms->iph.saddr;
221 struct ip_tunnel *t, **tp, *nt;
222 struct net_device *dev;
224 struct ipip_net *ipn = net_generic(net, ipip_net_id);
226 for (tp = __ipip_bucket(ipn, parms); (t = *tp) != NULL; tp = &t->next) {
227 if (local == t->parms.iph.saddr && remote == t->parms.iph.daddr)
234 strlcpy(name, parms->name, IFNAMSIZ);
236 sprintf(name, "tunl%%d");
238 dev = alloc_netdev(sizeof(*t), name, ipip_tunnel_setup);
242 if (strchr(name, '%')) {
243 if (dev_alloc_name(dev, name) < 0)
247 nt = netdev_priv(dev);
248 dev->init = ipip_tunnel_init;
251 if (register_netdevice(dev) < 0)
255 ipip_tunnel_link(ipn, nt);
263 static void ipip_tunnel_uninit(struct net_device *dev)
265 struct net *net = dev_net(dev);
266 struct ipip_net *ipn = net_generic(net, ipip_net_id);
268 if (dev == ipn->fb_tunnel_dev) {
269 write_lock_bh(&ipip_lock);
270 ipn->tunnels_wc[0] = NULL;
271 write_unlock_bh(&ipip_lock);
273 ipip_tunnel_unlink(ipn, netdev_priv(dev));
277 static int ipip_err(struct sk_buff *skb, u32 info)
279 #ifndef I_WISH_WORLD_WERE_PERFECT
281 /* It is not :-( All the routers (except for Linux) return only
282 8 bytes of packet payload. It means, that precise relaying of
283 ICMP in the real Internet is absolutely infeasible.
285 struct iphdr *iph = (struct iphdr*)skb->data;
286 const int type = icmp_hdr(skb)->type;
287 const int code = icmp_hdr(skb)->code;
293 case ICMP_PARAMETERPROB:
296 case ICMP_DEST_UNREACH:
299 case ICMP_PORT_UNREACH:
300 /* Impossible event. */
302 case ICMP_FRAG_NEEDED:
303 /* Soft state for pmtu is maintained by IP core. */
306 /* All others are translated to HOST_UNREACH.
307 rfc2003 contains "deep thoughts" about NET_UNREACH,
308 I believe they are just ether pollution. --ANK
313 case ICMP_TIME_EXCEEDED:
314 if (code != ICMP_EXC_TTL)
321 read_lock(&ipip_lock);
322 t = ipip_tunnel_lookup(dev_net(skb->dev), iph->daddr, iph->saddr);
323 if (t == NULL || t->parms.iph.daddr == 0)
327 if (t->parms.iph.ttl == 0 && type == ICMP_TIME_EXCEEDED)
330 if (jiffies - t->err_time < IPTUNNEL_ERR_TIMEO)
334 t->err_time = jiffies;
336 read_unlock(&ipip_lock);
339 struct iphdr *iph = (struct iphdr*)dp;
340 int hlen = iph->ihl<<2;
342 const int type = icmp_hdr(skb)->type;
343 const int code = icmp_hdr(skb)->code;
348 struct sk_buff *skb2;
352 if (len < hlen + sizeof(struct iphdr))
354 eiph = (struct iphdr*)(dp + hlen);
359 case ICMP_PARAMETERPROB:
360 n = ntohl(icmp_hdr(skb)->un.gateway) >> 24;
364 /* So... This guy found something strange INSIDE encapsulated
365 packet. Well, he is fool, but what can we do ?
367 rel_type = ICMP_PARAMETERPROB;
368 rel_info = htonl((n - hlen) << 24);
371 case ICMP_DEST_UNREACH:
374 case ICMP_PORT_UNREACH:
375 /* Impossible event. */
377 case ICMP_FRAG_NEEDED:
378 /* And it is the only really necessary thing :-) */
379 n = ntohs(icmp_hdr(skb)->un.frag.mtu);
383 /* BSD 4.2 MORE DOES NOT EXIST IN NATURE. */
384 if (n > ntohs(eiph->tot_len))
389 /* All others are translated to HOST_UNREACH.
390 rfc2003 contains "deep thoughts" about NET_UNREACH,
391 I believe, it is just ether pollution. --ANK
393 rel_type = ICMP_DEST_UNREACH;
394 rel_code = ICMP_HOST_UNREACH;
398 case ICMP_TIME_EXCEEDED:
399 if (code != ICMP_EXC_TTL)
404 /* Prepare fake skb to feed it to icmp_send */
405 skb2 = skb_clone(skb, GFP_ATOMIC);
408 dst_release(skb2->dst);
410 skb_pull(skb2, skb->data - (u8*)eiph);
411 skb_reset_network_header(skb2);
413 /* Try to guess incoming interface */
414 memset(&fl, 0, sizeof(fl));
415 fl.fl4_daddr = eiph->saddr;
416 fl.fl4_tos = RT_TOS(eiph->tos);
417 fl.proto = IPPROTO_IPIP;
418 if (ip_route_output_key(&init_net, &rt, &key)) {
422 skb2->dev = rt->u.dst.dev;
424 /* route "incoming" packet */
425 if (rt->rt_flags&RTCF_LOCAL) {
428 fl.fl4_daddr = eiph->daddr;
429 fl.fl4_src = eiph->saddr;
430 fl.fl4_tos = eiph->tos;
431 if (ip_route_output_key(&init_net, &rt, &fl) ||
432 rt->u.dst.dev->type != ARPHRD_TUNNEL) {
439 if (ip_route_input(skb2, eiph->daddr, eiph->saddr, eiph->tos, skb2->dev) ||
440 skb2->dst->dev->type != ARPHRD_TUNNEL) {
446 /* change mtu on this route */
447 if (type == ICMP_DEST_UNREACH && code == ICMP_FRAG_NEEDED) {
448 if (n > dst_mtu(skb2->dst)) {
452 skb2->dst->ops->update_pmtu(skb2->dst, n);
453 } else if (type == ICMP_TIME_EXCEEDED) {
454 struct ip_tunnel *t = netdev_priv(skb2->dev);
455 if (t->parms.iph.ttl) {
456 rel_type = ICMP_DEST_UNREACH;
457 rel_code = ICMP_HOST_UNREACH;
461 icmp_send(skb2, rel_type, rel_code, rel_info);
467 static inline void ipip_ecn_decapsulate(const struct iphdr *outer_iph,
470 struct iphdr *inner_iph = ip_hdr(skb);
472 if (INET_ECN_is_ce(outer_iph->tos))
473 IP_ECN_set_ce(inner_iph);
476 static int ipip_rcv(struct sk_buff *skb)
478 struct ip_tunnel *tunnel;
479 const struct iphdr *iph = ip_hdr(skb);
481 read_lock(&ipip_lock);
482 if ((tunnel = ipip_tunnel_lookup(dev_net(skb->dev),
483 iph->saddr, iph->daddr)) != NULL) {
484 if (!xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb)) {
485 read_unlock(&ipip_lock);
492 skb->mac_header = skb->network_header;
493 skb_reset_network_header(skb);
494 skb->protocol = htons(ETH_P_IP);
495 skb->pkt_type = PACKET_HOST;
497 tunnel->stat.rx_packets++;
498 tunnel->stat.rx_bytes += skb->len;
499 skb->dev = tunnel->dev;
500 dst_release(skb->dst);
503 ipip_ecn_decapsulate(iph, skb);
505 read_unlock(&ipip_lock);
508 read_unlock(&ipip_lock);
514 * This function assumes it is being called from dev_queue_xmit()
515 * and that skb is filled properly by that function.
518 static int ipip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev)
520 struct ip_tunnel *tunnel = netdev_priv(dev);
521 struct net_device_stats *stats = &tunnel->stat;
522 struct iphdr *tiph = &tunnel->parms.iph;
523 u8 tos = tunnel->parms.iph.tos;
524 __be16 df = tiph->frag_off;
525 struct rtable *rt; /* Route to the other host */
526 struct net_device *tdev; /* Device to other host */
527 struct iphdr *old_iph = ip_hdr(skb);
528 struct iphdr *iph; /* Our new IP header */
529 unsigned int max_headroom; /* The extra header space needed */
530 __be32 dst = tiph->daddr;
533 if (tunnel->recursion++) {
534 tunnel->stat.collisions++;
538 if (skb->protocol != htons(ETH_P_IP))
546 if ((rt = skb->rtable) == NULL) {
547 tunnel->stat.tx_fifo_errors++;
550 if ((dst = rt->rt_gateway) == 0)
555 struct flowi fl = { .oif = tunnel->parms.link,
558 .saddr = tiph->saddr,
559 .tos = RT_TOS(tos) } },
560 .proto = IPPROTO_IPIP };
561 if (ip_route_output_key(&init_net, &rt, &fl)) {
562 tunnel->stat.tx_carrier_errors++;
566 tdev = rt->u.dst.dev;
570 tunnel->stat.collisions++;
575 mtu = dst_mtu(&rt->u.dst) - sizeof(struct iphdr);
577 mtu = skb->dst ? dst_mtu(skb->dst) : dev->mtu;
580 tunnel->stat.collisions++;
585 skb->dst->ops->update_pmtu(skb->dst, mtu);
587 df |= (old_iph->frag_off&htons(IP_DF));
589 if ((old_iph->frag_off&htons(IP_DF)) && mtu < ntohs(old_iph->tot_len)) {
590 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED, htonl(mtu));
595 if (tunnel->err_count > 0) {
596 if (jiffies - tunnel->err_time < IPTUNNEL_ERR_TIMEO) {
598 dst_link_failure(skb);
600 tunnel->err_count = 0;
604 * Okay, now see if we can stuff it in the buffer as-is.
606 max_headroom = (LL_RESERVED_SPACE(tdev)+sizeof(struct iphdr));
608 if (skb_headroom(skb) < max_headroom || skb_shared(skb) ||
609 (skb_cloned(skb) && !skb_clone_writable(skb, 0))) {
610 struct sk_buff *new_skb = skb_realloc_headroom(skb, max_headroom);
619 skb_set_owner_w(new_skb, skb->sk);
622 old_iph = ip_hdr(skb);
625 skb->transport_header = skb->network_header;
626 skb_push(skb, sizeof(struct iphdr));
627 skb_reset_network_header(skb);
628 memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt));
629 IPCB(skb)->flags &= ~(IPSKB_XFRM_TUNNEL_SIZE | IPSKB_XFRM_TRANSFORMED |
631 dst_release(skb->dst);
632 skb->dst = &rt->u.dst;
635 * Push down and install the IPIP header.
640 iph->ihl = sizeof(struct iphdr)>>2;
642 iph->protocol = IPPROTO_IPIP;
643 iph->tos = INET_ECN_encapsulate(tos, old_iph->tos);
644 iph->daddr = rt->rt_dst;
645 iph->saddr = rt->rt_src;
647 if ((iph->ttl = tiph->ttl) == 0)
648 iph->ttl = old_iph->ttl;
657 dst_link_failure(skb);
665 static void ipip_tunnel_bind_dev(struct net_device *dev)
667 struct net_device *tdev = NULL;
668 struct ip_tunnel *tunnel;
671 tunnel = netdev_priv(dev);
672 iph = &tunnel->parms.iph;
675 struct flowi fl = { .oif = tunnel->parms.link,
677 { .daddr = iph->daddr,
679 .tos = RT_TOS(iph->tos) } },
680 .proto = IPPROTO_IPIP };
682 if (!ip_route_output_key(&init_net, &rt, &fl)) {
683 tdev = rt->u.dst.dev;
686 dev->flags |= IFF_POINTOPOINT;
689 if (!tdev && tunnel->parms.link)
690 tdev = __dev_get_by_index(&init_net, tunnel->parms.link);
693 dev->hard_header_len = tdev->hard_header_len + sizeof(struct iphdr);
694 dev->mtu = tdev->mtu - sizeof(struct iphdr);
696 dev->iflink = tunnel->parms.link;
700 ipip_tunnel_ioctl (struct net_device *dev, struct ifreq *ifr, int cmd)
703 struct ip_tunnel_parm p;
705 struct net *net = dev_net(dev);
706 struct ipip_net *ipn = net_generic(net, ipip_net_id);
711 if (dev == ipn->fb_tunnel_dev) {
712 if (copy_from_user(&p, ifr->ifr_ifru.ifru_data, sizeof(p))) {
716 t = ipip_tunnel_locate(net, &p, 0);
719 t = netdev_priv(dev);
720 memcpy(&p, &t->parms, sizeof(p));
721 if (copy_to_user(ifr->ifr_ifru.ifru_data, &p, sizeof(p)))
728 if (!capable(CAP_NET_ADMIN))
732 if (copy_from_user(&p, ifr->ifr_ifru.ifru_data, sizeof(p)))
736 if (p.iph.version != 4 || p.iph.protocol != IPPROTO_IPIP ||
737 p.iph.ihl != 5 || (p.iph.frag_off&htons(~IP_DF)))
740 p.iph.frag_off |= htons(IP_DF);
742 t = ipip_tunnel_locate(net, &p, cmd == SIOCADDTUNNEL);
744 if (dev != ipn->fb_tunnel_dev && cmd == SIOCCHGTUNNEL) {
751 if (((dev->flags&IFF_POINTOPOINT) && !p.iph.daddr) ||
752 (!(dev->flags&IFF_POINTOPOINT) && p.iph.daddr)) {
756 t = netdev_priv(dev);
757 ipip_tunnel_unlink(ipn, t);
758 t->parms.iph.saddr = p.iph.saddr;
759 t->parms.iph.daddr = p.iph.daddr;
760 memcpy(dev->dev_addr, &p.iph.saddr, 4);
761 memcpy(dev->broadcast, &p.iph.daddr, 4);
762 ipip_tunnel_link(ipn, t);
763 netdev_state_change(dev);
769 if (cmd == SIOCCHGTUNNEL) {
770 t->parms.iph.ttl = p.iph.ttl;
771 t->parms.iph.tos = p.iph.tos;
772 t->parms.iph.frag_off = p.iph.frag_off;
773 if (t->parms.link != p.link) {
774 t->parms.link = p.link;
775 ipip_tunnel_bind_dev(dev);
776 netdev_state_change(dev);
779 if (copy_to_user(ifr->ifr_ifru.ifru_data, &t->parms, sizeof(p)))
782 err = (cmd == SIOCADDTUNNEL ? -ENOBUFS : -ENOENT);
787 if (!capable(CAP_NET_ADMIN))
790 if (dev == ipn->fb_tunnel_dev) {
792 if (copy_from_user(&p, ifr->ifr_ifru.ifru_data, sizeof(p)))
795 if ((t = ipip_tunnel_locate(net, &p, 0)) == NULL)
798 if (t->dev == ipn->fb_tunnel_dev)
802 unregister_netdevice(dev);
814 static struct net_device_stats *ipip_tunnel_get_stats(struct net_device *dev)
816 return &(((struct ip_tunnel*)netdev_priv(dev))->stat);
819 static int ipip_tunnel_change_mtu(struct net_device *dev, int new_mtu)
821 if (new_mtu < 68 || new_mtu > 0xFFF8 - sizeof(struct iphdr))
827 static void ipip_tunnel_setup(struct net_device *dev)
829 dev->uninit = ipip_tunnel_uninit;
830 dev->hard_start_xmit = ipip_tunnel_xmit;
831 dev->get_stats = ipip_tunnel_get_stats;
832 dev->do_ioctl = ipip_tunnel_ioctl;
833 dev->change_mtu = ipip_tunnel_change_mtu;
834 dev->destructor = free_netdev;
836 dev->type = ARPHRD_TUNNEL;
837 dev->hard_header_len = LL_MAX_HEADER + sizeof(struct iphdr);
838 dev->mtu = ETH_DATA_LEN - sizeof(struct iphdr);
839 dev->flags = IFF_NOARP;
844 static int ipip_tunnel_init(struct net_device *dev)
846 struct ip_tunnel *tunnel;
848 tunnel = netdev_priv(dev);
851 strcpy(tunnel->parms.name, dev->name);
853 memcpy(dev->dev_addr, &tunnel->parms.iph.saddr, 4);
854 memcpy(dev->broadcast, &tunnel->parms.iph.daddr, 4);
856 ipip_tunnel_bind_dev(dev);
861 static int ipip_fb_tunnel_init(struct net_device *dev)
863 struct ip_tunnel *tunnel = netdev_priv(dev);
864 struct iphdr *iph = &tunnel->parms.iph;
865 struct ipip_net *ipn = net_generic(dev_net(dev), ipip_net_id);
868 strcpy(tunnel->parms.name, dev->name);
871 iph->protocol = IPPROTO_IPIP;
875 ipn->tunnels_wc[0] = tunnel;
879 static struct xfrm_tunnel ipip_handler = {
881 .err_handler = ipip_err,
885 static char banner[] __initdata =
886 KERN_INFO "IPv4 over IPv4 tunneling driver\n";
888 static void ipip_destroy_tunnels(struct ipip_net *ipn)
892 for (prio = 1; prio < 4; prio++) {
894 for (h = 0; h < HASH_SIZE; h++) {
896 while ((t = ipn->tunnels[prio][h]) != NULL)
897 unregister_netdevice(t->dev);
902 static int ipip_init_net(struct net *net)
905 struct ipip_net *ipn;
908 ipn = kzalloc(sizeof(struct ipip_net), GFP_KERNEL);
912 err = net_assign_generic(net, ipip_net_id, ipn);
916 ipn->tunnels[0] = ipn->tunnels_wc;
917 ipn->tunnels[1] = ipn->tunnels_l;
918 ipn->tunnels[2] = ipn->tunnels_r;
919 ipn->tunnels[3] = ipn->tunnels_r_l;
921 ipn->fb_tunnel_dev = alloc_netdev(sizeof(struct ip_tunnel),
924 if (!ipn->fb_tunnel_dev) {
929 ipn->fb_tunnel_dev->init = ipip_fb_tunnel_init;
930 dev_net_set(ipn->fb_tunnel_dev, net);
932 if ((err = register_netdev(ipn->fb_tunnel_dev)))
938 free_netdev(ipn->fb_tunnel_dev);
947 static void ipip_exit_net(struct net *net)
949 struct ipip_net *ipn;
951 ipn = net_generic(net, ipip_net_id);
953 ipip_destroy_tunnels(ipn);
954 unregister_netdevice(ipn->fb_tunnel_dev);
959 static struct pernet_operations ipip_net_ops = {
960 .init = ipip_init_net,
961 .exit = ipip_exit_net,
964 static int __init ipip_init(void)
970 if (xfrm4_tunnel_register(&ipip_handler, AF_INET)) {
971 printk(KERN_INFO "ipip init: can't register tunnel\n");
975 err = register_pernet_gen_device(&ipip_net_id, &ipip_net_ops);
977 xfrm4_tunnel_deregister(&ipip_handler, AF_INET);
982 static void __exit ipip_fini(void)
984 if (xfrm4_tunnel_deregister(&ipip_handler, AF_INET))
985 printk(KERN_INFO "ipip close: can't deregister tunnel\n");
987 unregister_pernet_gen_device(ipip_net_id, &ipip_net_ops);
990 module_init(ipip_init);
991 module_exit(ipip_fini);
992 MODULE_LICENSE("GPL");