Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * IPv6 over IPv4 tunnel device - Simple Internet Transition (SIT) |
| 3 | * Linux INET6 implementation |
| 4 | * |
| 5 | * Authors: |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 6 | * Pedro Roque <roque@di.fc.ul.pt> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * Alexey Kuznetsov <kuznet@ms2.inr.ac.ru> |
| 8 | * |
| 9 | * $Id: sit.c,v 1.53 2001/09/25 05:09:53 davem Exp $ |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or |
| 12 | * modify it under the terms of the GNU General Public License |
| 13 | * as published by the Free Software Foundation; either version |
| 14 | * 2 of the License, or (at your option) any later version. |
| 15 | * |
| 16 | * Changes: |
| 17 | * Roger Venning <r.venning@telstra.com>: 6to4 support |
| 18 | * Nate Thompson <nate@thebog.net>: 6to4 support |
Templin, Fred L | fadf6bf | 2008-03-11 18:35:59 -0400 | [diff] [blame] | 19 | * Fred Templin <fred.l.templin@boeing.com>: isatap support |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | */ |
| 21 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <linux/module.h> |
Randy Dunlap | 4fc268d | 2006-01-11 12:17:47 -0800 | [diff] [blame] | 23 | #include <linux/capability.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <linux/errno.h> |
| 25 | #include <linux/types.h> |
| 26 | #include <linux/socket.h> |
| 27 | #include <linux/sockios.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include <linux/net.h> |
| 29 | #include <linux/in6.h> |
| 30 | #include <linux/netdevice.h> |
| 31 | #include <linux/if_arp.h> |
| 32 | #include <linux/icmp.h> |
| 33 | #include <asm/uaccess.h> |
| 34 | #include <linux/init.h> |
| 35 | #include <linux/netfilter_ipv4.h> |
Kris Katterjohn | 46f25df | 2006-01-05 16:35:42 -0800 | [diff] [blame] | 36 | #include <linux/if_ether.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
| 38 | #include <net/sock.h> |
| 39 | #include <net/snmp.h> |
| 40 | |
| 41 | #include <net/ipv6.h> |
| 42 | #include <net/protocol.h> |
| 43 | #include <net/transp_v6.h> |
| 44 | #include <net/ip6_fib.h> |
| 45 | #include <net/ip6_route.h> |
| 46 | #include <net/ndisc.h> |
| 47 | #include <net/addrconf.h> |
| 48 | #include <net/ip.h> |
| 49 | #include <net/udp.h> |
| 50 | #include <net/icmp.h> |
| 51 | #include <net/ipip.h> |
| 52 | #include <net/inet_ecn.h> |
| 53 | #include <net/xfrm.h> |
| 54 | #include <net/dsfield.h> |
| 55 | |
| 56 | /* |
| 57 | This version of net/ipv6/sit.c is cloned of net/ipv4/ip_gre.c |
| 58 | |
| 59 | For comments look at net/ipv4/ip_gre.c --ANK |
| 60 | */ |
| 61 | |
| 62 | #define HASH_SIZE 16 |
Al Viro | e69a4ad | 2006-11-14 20:56:00 -0800 | [diff] [blame] | 63 | #define HASH(addr) (((__force u32)addr^((__force u32)addr>>4))&0xF) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | |
| 65 | static int ipip6_fb_tunnel_init(struct net_device *dev); |
| 66 | static int ipip6_tunnel_init(struct net_device *dev); |
| 67 | static void ipip6_tunnel_setup(struct net_device *dev); |
| 68 | |
| 69 | static struct net_device *ipip6_fb_tunnel_dev; |
| 70 | |
| 71 | static struct ip_tunnel *tunnels_r_l[HASH_SIZE]; |
| 72 | static struct ip_tunnel *tunnels_r[HASH_SIZE]; |
| 73 | static struct ip_tunnel *tunnels_l[HASH_SIZE]; |
| 74 | static struct ip_tunnel *tunnels_wc[1]; |
| 75 | static struct ip_tunnel **tunnels[4] = { tunnels_wc, tunnels_l, tunnels_r, tunnels_r_l }; |
| 76 | |
| 77 | static DEFINE_RWLOCK(ipip6_lock); |
| 78 | |
Al Viro | e69a4ad | 2006-11-14 20:56:00 -0800 | [diff] [blame] | 79 | static struct ip_tunnel * ipip6_tunnel_lookup(__be32 remote, __be32 local) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | { |
| 81 | unsigned h0 = HASH(remote); |
| 82 | unsigned h1 = HASH(local); |
| 83 | struct ip_tunnel *t; |
| 84 | |
| 85 | for (t = tunnels_r_l[h0^h1]; t; t = t->next) { |
| 86 | if (local == t->parms.iph.saddr && |
| 87 | remote == t->parms.iph.daddr && (t->dev->flags&IFF_UP)) |
| 88 | return t; |
| 89 | } |
| 90 | for (t = tunnels_r[h0]; t; t = t->next) { |
| 91 | if (remote == t->parms.iph.daddr && (t->dev->flags&IFF_UP)) |
| 92 | return t; |
| 93 | } |
| 94 | for (t = tunnels_l[h1]; t; t = t->next) { |
| 95 | if (local == t->parms.iph.saddr && (t->dev->flags&IFF_UP)) |
| 96 | return t; |
| 97 | } |
| 98 | if ((t = tunnels_wc[0]) != NULL && (t->dev->flags&IFF_UP)) |
| 99 | return t; |
| 100 | return NULL; |
| 101 | } |
| 102 | |
YOSHIFUJI Hideaki | 420fe23 | 2007-04-24 20:44:47 +0900 | [diff] [blame] | 103 | static struct ip_tunnel **__ipip6_bucket(struct ip_tunnel_parm *parms) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | { |
YOSHIFUJI Hideaki | 420fe23 | 2007-04-24 20:44:47 +0900 | [diff] [blame] | 105 | __be32 remote = parms->iph.daddr; |
| 106 | __be32 local = parms->iph.saddr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | unsigned h = 0; |
| 108 | int prio = 0; |
| 109 | |
| 110 | if (remote) { |
| 111 | prio |= 2; |
| 112 | h ^= HASH(remote); |
| 113 | } |
| 114 | if (local) { |
| 115 | prio |= 1; |
| 116 | h ^= HASH(local); |
| 117 | } |
| 118 | return &tunnels[prio][h]; |
| 119 | } |
| 120 | |
YOSHIFUJI Hideaki | 420fe23 | 2007-04-24 20:44:47 +0900 | [diff] [blame] | 121 | static inline struct ip_tunnel **ipip6_bucket(struct ip_tunnel *t) |
| 122 | { |
| 123 | return __ipip6_bucket(&t->parms); |
| 124 | } |
| 125 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | static void ipip6_tunnel_unlink(struct ip_tunnel *t) |
| 127 | { |
| 128 | struct ip_tunnel **tp; |
| 129 | |
| 130 | for (tp = ipip6_bucket(t); *tp; tp = &(*tp)->next) { |
| 131 | if (t == *tp) { |
| 132 | write_lock_bh(&ipip6_lock); |
| 133 | *tp = t->next; |
| 134 | write_unlock_bh(&ipip6_lock); |
| 135 | break; |
| 136 | } |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | static void ipip6_tunnel_link(struct ip_tunnel *t) |
| 141 | { |
| 142 | struct ip_tunnel **tp = ipip6_bucket(t); |
| 143 | |
| 144 | t->next = *tp; |
| 145 | write_lock_bh(&ipip6_lock); |
| 146 | *tp = t; |
| 147 | write_unlock_bh(&ipip6_lock); |
| 148 | } |
| 149 | |
| 150 | static struct ip_tunnel * ipip6_tunnel_locate(struct ip_tunnel_parm *parms, int create) |
| 151 | { |
Al Viro | e69a4ad | 2006-11-14 20:56:00 -0800 | [diff] [blame] | 152 | __be32 remote = parms->iph.daddr; |
| 153 | __be32 local = parms->iph.saddr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | struct ip_tunnel *t, **tp, *nt; |
| 155 | struct net_device *dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | char name[IFNAMSIZ]; |
| 157 | |
YOSHIFUJI Hideaki | 420fe23 | 2007-04-24 20:44:47 +0900 | [diff] [blame] | 158 | for (tp = __ipip6_bucket(parms); (t = *tp) != NULL; tp = &t->next) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | if (local == t->parms.iph.saddr && remote == t->parms.iph.daddr) |
| 160 | return t; |
| 161 | } |
| 162 | if (!create) |
| 163 | goto failed; |
| 164 | |
| 165 | if (parms->name[0]) |
| 166 | strlcpy(name, parms->name, IFNAMSIZ); |
Pavel Emelyanov | 34cc7ba | 2008-02-23 20:19:20 -0800 | [diff] [blame] | 167 | else |
| 168 | sprintf(name, "sit%%d"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | |
| 170 | dev = alloc_netdev(sizeof(*t), name, ipip6_tunnel_setup); |
| 171 | if (dev == NULL) |
| 172 | return NULL; |
| 173 | |
Pavel Emelyanov | b37d428b | 2008-02-26 23:51:04 -0800 | [diff] [blame] | 174 | if (strchr(name, '%')) { |
| 175 | if (dev_alloc_name(dev, name) < 0) |
| 176 | goto failed_free; |
| 177 | } |
| 178 | |
Patrick McHardy | 2941a48 | 2006-01-08 22:05:26 -0800 | [diff] [blame] | 179 | nt = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | dev->init = ipip6_tunnel_init; |
| 181 | nt->parms = *parms; |
| 182 | |
Fred L. Templin | c7dc89c | 2007-11-29 22:11:40 +1100 | [diff] [blame] | 183 | if (parms->i_flags & SIT_ISATAP) |
| 184 | dev->priv_flags |= IFF_ISATAP; |
| 185 | |
Pavel Emelyanov | b37d428b | 2008-02-26 23:51:04 -0800 | [diff] [blame] | 186 | if (register_netdevice(dev) < 0) |
| 187 | goto failed_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | |
| 189 | dev_hold(dev); |
| 190 | |
| 191 | ipip6_tunnel_link(nt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | return nt; |
| 193 | |
Pavel Emelyanov | b37d428b | 2008-02-26 23:51:04 -0800 | [diff] [blame] | 194 | failed_free: |
| 195 | free_netdev(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | failed: |
| 197 | return NULL; |
| 198 | } |
| 199 | |
Templin, Fred L | fadf6bf | 2008-03-11 18:35:59 -0400 | [diff] [blame] | 200 | static struct ip_tunnel_prl_entry * |
YOSHIFUJI Hideaki | 3fcfa12 | 2008-03-22 17:42:57 +0900 | [diff] [blame] | 201 | __ipip6_tunnel_locate_prl(struct ip_tunnel *t, __be32 addr) |
Templin, Fred L | fadf6bf | 2008-03-11 18:35:59 -0400 | [diff] [blame] | 202 | { |
| 203 | struct ip_tunnel_prl_entry *p = (struct ip_tunnel_prl_entry *)NULL; |
| 204 | |
| 205 | for (p = t->prl; p; p = p->next) |
YOSHIFUJI Hideaki | 300aaee | 2008-03-24 18:28:39 +0900 | [diff] [blame] | 206 | if (p->addr == addr) |
Templin, Fred L | fadf6bf | 2008-03-11 18:35:59 -0400 | [diff] [blame] | 207 | break; |
| 208 | return p; |
| 209 | |
| 210 | } |
| 211 | |
YOSHIFUJI Hideaki | 300aaee | 2008-03-24 18:28:39 +0900 | [diff] [blame] | 212 | static int ipip6_tunnel_get_prl(struct ip_tunnel *t, struct ip_tunnel_prl *a) |
| 213 | { |
| 214 | struct ip_tunnel_prl *kp; |
| 215 | struct ip_tunnel_prl_entry *prl; |
| 216 | unsigned int cmax, c = 0, ca, len; |
| 217 | int ret = 0; |
| 218 | |
| 219 | cmax = a->datalen / sizeof(*a); |
| 220 | if (cmax > 1 && a->addr != htonl(INADDR_ANY)) |
| 221 | cmax = 1; |
| 222 | |
| 223 | /* For simple GET or for root users, |
| 224 | * we try harder to allocate. |
| 225 | */ |
| 226 | kp = (cmax <= 1 || capable(CAP_NET_ADMIN)) ? |
| 227 | kcalloc(cmax, sizeof(*kp), GFP_KERNEL) : |
| 228 | NULL; |
| 229 | |
| 230 | read_lock(&ipip6_lock); |
| 231 | |
| 232 | ca = t->prl_count < cmax ? t->prl_count : cmax; |
| 233 | |
| 234 | if (!kp) { |
| 235 | /* We don't try hard to allocate much memory for |
| 236 | * non-root users. |
| 237 | * For root users, retry allocating enough memory for |
| 238 | * the answer. |
| 239 | */ |
| 240 | kp = kcalloc(ca, sizeof(*kp), GFP_ATOMIC); |
| 241 | if (!kp) { |
| 242 | ret = -ENOMEM; |
| 243 | goto out; |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | c = 0; |
| 248 | for (prl = t->prl; prl; prl = prl->next) { |
| 249 | if (c > cmax) |
| 250 | break; |
| 251 | if (a->addr != htonl(INADDR_ANY) && prl->addr != a->addr) |
| 252 | continue; |
| 253 | kp[c].addr = prl->addr; |
| 254 | kp[c].flags = prl->flags; |
| 255 | c++; |
| 256 | if (a->addr != htonl(INADDR_ANY)) |
| 257 | break; |
| 258 | } |
| 259 | out: |
| 260 | read_unlock(&ipip6_lock); |
| 261 | |
| 262 | len = sizeof(*kp) * c; |
| 263 | ret = len ? copy_to_user(a->data, kp, len) : 0; |
| 264 | |
| 265 | kfree(kp); |
| 266 | if (ret) |
| 267 | return -EFAULT; |
| 268 | |
| 269 | a->datalen = len; |
| 270 | return 0; |
| 271 | } |
| 272 | |
Templin, Fred L | fadf6bf | 2008-03-11 18:35:59 -0400 | [diff] [blame] | 273 | static int |
| 274 | ipip6_tunnel_add_prl(struct ip_tunnel *t, struct ip_tunnel_prl *a, int chg) |
| 275 | { |
| 276 | struct ip_tunnel_prl_entry *p; |
YOSHIFUJI Hideaki | 3fcfa12 | 2008-03-22 17:42:57 +0900 | [diff] [blame] | 277 | int err = 0; |
| 278 | |
YOSHIFUJI Hideaki | 0009ae1 | 2008-03-22 17:50:59 +0900 | [diff] [blame] | 279 | if (a->addr == htonl(INADDR_ANY)) |
| 280 | return -EINVAL; |
| 281 | |
YOSHIFUJI Hideaki | 3fcfa12 | 2008-03-22 17:42:57 +0900 | [diff] [blame] | 282 | write_lock(&ipip6_lock); |
Templin, Fred L | fadf6bf | 2008-03-11 18:35:59 -0400 | [diff] [blame] | 283 | |
| 284 | for (p = t->prl; p; p = p->next) { |
YOSHIFUJI Hideaki | 300aaee | 2008-03-24 18:28:39 +0900 | [diff] [blame] | 285 | if (p->addr == a->addr) { |
YOSHIFUJI Hideaki | 3fcfa12 | 2008-03-22 17:42:57 +0900 | [diff] [blame] | 286 | if (chg) |
| 287 | goto update; |
| 288 | err = -EEXIST; |
| 289 | goto out; |
Templin, Fred L | fadf6bf | 2008-03-11 18:35:59 -0400 | [diff] [blame] | 290 | } |
| 291 | } |
| 292 | |
YOSHIFUJI Hideaki | 3fcfa12 | 2008-03-22 17:42:57 +0900 | [diff] [blame] | 293 | if (chg) { |
| 294 | err = -ENXIO; |
| 295 | goto out; |
| 296 | } |
Templin, Fred L | fadf6bf | 2008-03-11 18:35:59 -0400 | [diff] [blame] | 297 | |
| 298 | p = kzalloc(sizeof(struct ip_tunnel_prl_entry), GFP_KERNEL); |
YOSHIFUJI Hideaki | 3fcfa12 | 2008-03-22 17:42:57 +0900 | [diff] [blame] | 299 | if (!p) { |
| 300 | err = -ENOBUFS; |
| 301 | goto out; |
| 302 | } |
Templin, Fred L | fadf6bf | 2008-03-11 18:35:59 -0400 | [diff] [blame] | 303 | |
Templin, Fred L | fadf6bf | 2008-03-11 18:35:59 -0400 | [diff] [blame] | 304 | p->next = t->prl; |
| 305 | t->prl = p; |
YOSHIFUJI Hideaki | 300aaee | 2008-03-24 18:28:39 +0900 | [diff] [blame] | 306 | t->prl_count++; |
YOSHIFUJI Hideaki | 3fcfa12 | 2008-03-22 17:42:57 +0900 | [diff] [blame] | 307 | update: |
YOSHIFUJI Hideaki | 300aaee | 2008-03-24 18:28:39 +0900 | [diff] [blame] | 308 | p->addr = a->addr; |
| 309 | p->flags = a->flags; |
YOSHIFUJI Hideaki | 3fcfa12 | 2008-03-22 17:42:57 +0900 | [diff] [blame] | 310 | out: |
| 311 | write_unlock(&ipip6_lock); |
| 312 | return err; |
Templin, Fred L | fadf6bf | 2008-03-11 18:35:59 -0400 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | static int |
| 316 | ipip6_tunnel_del_prl(struct ip_tunnel *t, struct ip_tunnel_prl *a) |
| 317 | { |
| 318 | struct ip_tunnel_prl_entry *x, **p; |
YOSHIFUJI Hideaki | 3fcfa12 | 2008-03-22 17:42:57 +0900 | [diff] [blame] | 319 | int err = 0; |
| 320 | |
| 321 | write_lock(&ipip6_lock); |
Templin, Fred L | fadf6bf | 2008-03-11 18:35:59 -0400 | [diff] [blame] | 322 | |
YOSHIFUJI Hideaki | 0009ae1 | 2008-03-22 17:50:59 +0900 | [diff] [blame] | 323 | if (a && a->addr != htonl(INADDR_ANY)) { |
Templin, Fred L | fadf6bf | 2008-03-11 18:35:59 -0400 | [diff] [blame] | 324 | for (p = &t->prl; *p; p = &(*p)->next) { |
YOSHIFUJI Hideaki | 300aaee | 2008-03-24 18:28:39 +0900 | [diff] [blame] | 325 | if ((*p)->addr == a->addr) { |
Templin, Fred L | fadf6bf | 2008-03-11 18:35:59 -0400 | [diff] [blame] | 326 | x = *p; |
| 327 | *p = x->next; |
| 328 | kfree(x); |
YOSHIFUJI Hideaki | 300aaee | 2008-03-24 18:28:39 +0900 | [diff] [blame] | 329 | t->prl_count--; |
YOSHIFUJI Hideaki | 3fcfa12 | 2008-03-22 17:42:57 +0900 | [diff] [blame] | 330 | goto out; |
Templin, Fred L | fadf6bf | 2008-03-11 18:35:59 -0400 | [diff] [blame] | 331 | } |
| 332 | } |
YOSHIFUJI Hideaki | 3fcfa12 | 2008-03-22 17:42:57 +0900 | [diff] [blame] | 333 | err = -ENXIO; |
Templin, Fred L | fadf6bf | 2008-03-11 18:35:59 -0400 | [diff] [blame] | 334 | } else { |
| 335 | while (t->prl) { |
| 336 | x = t->prl; |
| 337 | t->prl = t->prl->next; |
| 338 | kfree(x); |
YOSHIFUJI Hideaki | 300aaee | 2008-03-24 18:28:39 +0900 | [diff] [blame] | 339 | t->prl_count--; |
Templin, Fred L | fadf6bf | 2008-03-11 18:35:59 -0400 | [diff] [blame] | 340 | } |
| 341 | } |
YOSHIFUJI Hideaki | 3fcfa12 | 2008-03-22 17:42:57 +0900 | [diff] [blame] | 342 | out: |
| 343 | write_unlock(&ipip6_lock); |
Templin, Fred L | fadf6bf | 2008-03-11 18:35:59 -0400 | [diff] [blame] | 344 | return 0; |
| 345 | } |
| 346 | |
Templin, Fred L | fadf6bf | 2008-03-11 18:35:59 -0400 | [diff] [blame] | 347 | static int |
| 348 | isatap_chksrc(struct sk_buff *skb, struct iphdr *iph, struct ip_tunnel *t) |
| 349 | { |
YOSHIFUJI Hideaki | 3fcfa12 | 2008-03-22 17:42:57 +0900 | [diff] [blame] | 350 | struct ip_tunnel_prl_entry *p; |
Templin, Fred L | fadf6bf | 2008-03-11 18:35:59 -0400 | [diff] [blame] | 351 | int ok = 1; |
| 352 | |
YOSHIFUJI Hideaki | 3fcfa12 | 2008-03-22 17:42:57 +0900 | [diff] [blame] | 353 | read_lock(&ipip6_lock); |
| 354 | p = __ipip6_tunnel_locate_prl(t, iph->saddr); |
Templin, Fred L | fadf6bf | 2008-03-11 18:35:59 -0400 | [diff] [blame] | 355 | if (p) { |
YOSHIFUJI Hideaki | 300aaee | 2008-03-24 18:28:39 +0900 | [diff] [blame] | 356 | if (p->flags & PRL_DEFAULT) |
Templin, Fred L | fadf6bf | 2008-03-11 18:35:59 -0400 | [diff] [blame] | 357 | skb->ndisc_nodetype = NDISC_NODETYPE_DEFAULT; |
| 358 | else |
| 359 | skb->ndisc_nodetype = NDISC_NODETYPE_NODEFAULT; |
| 360 | } else { |
| 361 | struct in6_addr *addr6 = &ipv6_hdr(skb)->saddr; |
| 362 | if (ipv6_addr_is_isatap(addr6) && |
| 363 | (addr6->s6_addr32[3] == iph->saddr) && |
YOSHIFUJI Hideaki | 52eeeb8 | 2008-03-15 22:54:23 -0400 | [diff] [blame^] | 364 | ipv6_chk_prefix(addr6, t->dev)) |
Templin, Fred L | fadf6bf | 2008-03-11 18:35:59 -0400 | [diff] [blame] | 365 | skb->ndisc_nodetype = NDISC_NODETYPE_HOST; |
| 366 | else |
| 367 | ok = 0; |
| 368 | } |
YOSHIFUJI Hideaki | 3fcfa12 | 2008-03-22 17:42:57 +0900 | [diff] [blame] | 369 | read_unlock(&ipip6_lock); |
Templin, Fred L | fadf6bf | 2008-03-11 18:35:59 -0400 | [diff] [blame] | 370 | return ok; |
| 371 | } |
| 372 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | static void ipip6_tunnel_uninit(struct net_device *dev) |
| 374 | { |
| 375 | if (dev == ipip6_fb_tunnel_dev) { |
| 376 | write_lock_bh(&ipip6_lock); |
| 377 | tunnels_wc[0] = NULL; |
| 378 | write_unlock_bh(&ipip6_lock); |
| 379 | dev_put(dev); |
| 380 | } else { |
Patrick McHardy | 2941a48 | 2006-01-08 22:05:26 -0800 | [diff] [blame] | 381 | ipip6_tunnel_unlink(netdev_priv(dev)); |
Templin, Fred L | fadf6bf | 2008-03-11 18:35:59 -0400 | [diff] [blame] | 382 | ipip6_tunnel_del_prl(netdev_priv(dev), 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | dev_put(dev); |
| 384 | } |
| 385 | } |
| 386 | |
| 387 | |
Kazunori MIYAZAWA | c73cb5a | 2007-02-13 12:55:25 -0800 | [diff] [blame] | 388 | static int ipip6_err(struct sk_buff *skb, u32 info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | { |
| 390 | #ifndef I_WISH_WORLD_WERE_PERFECT |
| 391 | |
| 392 | /* It is not :-( All the routers (except for Linux) return only |
| 393 | 8 bytes of packet payload. It means, that precise relaying of |
| 394 | ICMP in the real Internet is absolutely infeasible. |
| 395 | */ |
| 396 | struct iphdr *iph = (struct iphdr*)skb->data; |
Arnaldo Carvalho de Melo | 88c7664 | 2007-03-13 14:43:18 -0300 | [diff] [blame] | 397 | const int type = icmp_hdr(skb)->type; |
| 398 | const int code = icmp_hdr(skb)->code; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | struct ip_tunnel *t; |
Kazunori MIYAZAWA | c73cb5a | 2007-02-13 12:55:25 -0800 | [diff] [blame] | 400 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | |
| 402 | switch (type) { |
| 403 | default: |
| 404 | case ICMP_PARAMETERPROB: |
Kazunori MIYAZAWA | c73cb5a | 2007-02-13 12:55:25 -0800 | [diff] [blame] | 405 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | |
| 407 | case ICMP_DEST_UNREACH: |
| 408 | switch (code) { |
| 409 | case ICMP_SR_FAILED: |
| 410 | case ICMP_PORT_UNREACH: |
| 411 | /* Impossible event. */ |
Kazunori MIYAZAWA | c73cb5a | 2007-02-13 12:55:25 -0800 | [diff] [blame] | 412 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | case ICMP_FRAG_NEEDED: |
| 414 | /* Soft state for pmtu is maintained by IP core. */ |
Kazunori MIYAZAWA | c73cb5a | 2007-02-13 12:55:25 -0800 | [diff] [blame] | 415 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | default: |
| 417 | /* All others are translated to HOST_UNREACH. |
| 418 | rfc2003 contains "deep thoughts" about NET_UNREACH, |
| 419 | I believe they are just ether pollution. --ANK |
| 420 | */ |
| 421 | break; |
| 422 | } |
| 423 | break; |
| 424 | case ICMP_TIME_EXCEEDED: |
| 425 | if (code != ICMP_EXC_TTL) |
Kazunori MIYAZAWA | c73cb5a | 2007-02-13 12:55:25 -0800 | [diff] [blame] | 426 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | break; |
| 428 | } |
| 429 | |
Kazunori MIYAZAWA | c73cb5a | 2007-02-13 12:55:25 -0800 | [diff] [blame] | 430 | err = -ENOENT; |
| 431 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | read_lock(&ipip6_lock); |
| 433 | t = ipip6_tunnel_lookup(iph->daddr, iph->saddr); |
| 434 | if (t == NULL || t->parms.iph.daddr == 0) |
| 435 | goto out; |
Kazunori MIYAZAWA | c73cb5a | 2007-02-13 12:55:25 -0800 | [diff] [blame] | 436 | |
| 437 | err = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | if (t->parms.iph.ttl == 0 && type == ICMP_TIME_EXCEEDED) |
| 439 | goto out; |
| 440 | |
| 441 | if (jiffies - t->err_time < IPTUNNEL_ERR_TIMEO) |
| 442 | t->err_count++; |
| 443 | else |
| 444 | t->err_count = 1; |
| 445 | t->err_time = jiffies; |
| 446 | out: |
| 447 | read_unlock(&ipip6_lock); |
Kazunori MIYAZAWA | c73cb5a | 2007-02-13 12:55:25 -0800 | [diff] [blame] | 448 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | #else |
| 450 | struct iphdr *iph = (struct iphdr*)dp; |
| 451 | int hlen = iph->ihl<<2; |
| 452 | struct ipv6hdr *iph6; |
Arnaldo Carvalho de Melo | 88c7664 | 2007-03-13 14:43:18 -0300 | [diff] [blame] | 453 | const int type = icmp_hdr(skb)->type; |
| 454 | const int code = icmp_hdr(skb)->code; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | int rel_type = 0; |
| 456 | int rel_code = 0; |
| 457 | int rel_info = 0; |
| 458 | struct sk_buff *skb2; |
| 459 | struct rt6_info *rt6i; |
| 460 | |
| 461 | if (len < hlen + sizeof(struct ipv6hdr)) |
| 462 | return; |
| 463 | iph6 = (struct ipv6hdr*)(dp + hlen); |
| 464 | |
| 465 | switch (type) { |
| 466 | default: |
| 467 | return; |
| 468 | case ICMP_PARAMETERPROB: |
Arnaldo Carvalho de Melo | 88c7664 | 2007-03-13 14:43:18 -0300 | [diff] [blame] | 469 | if (icmp_hdr(skb)->un.gateway < hlen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | return; |
| 471 | |
| 472 | /* So... This guy found something strange INSIDE encapsulated |
| 473 | packet. Well, he is fool, but what can we do ? |
| 474 | */ |
| 475 | rel_type = ICMPV6_PARAMPROB; |
Arnaldo Carvalho de Melo | 88c7664 | 2007-03-13 14:43:18 -0300 | [diff] [blame] | 476 | rel_info = icmp_hdr(skb)->un.gateway - hlen; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | break; |
| 478 | |
| 479 | case ICMP_DEST_UNREACH: |
| 480 | switch (code) { |
| 481 | case ICMP_SR_FAILED: |
| 482 | case ICMP_PORT_UNREACH: |
| 483 | /* Impossible event. */ |
| 484 | return; |
| 485 | case ICMP_FRAG_NEEDED: |
| 486 | /* Too complicated case ... */ |
| 487 | return; |
| 488 | default: |
| 489 | /* All others are translated to HOST_UNREACH. |
| 490 | rfc2003 contains "deep thoughts" about NET_UNREACH, |
| 491 | I believe, it is just ether pollution. --ANK |
| 492 | */ |
| 493 | rel_type = ICMPV6_DEST_UNREACH; |
| 494 | rel_code = ICMPV6_ADDR_UNREACH; |
| 495 | break; |
| 496 | } |
| 497 | break; |
| 498 | case ICMP_TIME_EXCEEDED: |
| 499 | if (code != ICMP_EXC_TTL) |
| 500 | return; |
| 501 | rel_type = ICMPV6_TIME_EXCEED; |
| 502 | rel_code = ICMPV6_EXC_HOPLIMIT; |
| 503 | break; |
| 504 | } |
| 505 | |
| 506 | /* Prepare fake skb to feed it to icmpv6_send */ |
| 507 | skb2 = skb_clone(skb, GFP_ATOMIC); |
| 508 | if (skb2 == NULL) |
Kazunori MIYAZAWA | c73cb5a | 2007-02-13 12:55:25 -0800 | [diff] [blame] | 509 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | dst_release(skb2->dst); |
| 511 | skb2->dst = NULL; |
| 512 | skb_pull(skb2, skb->data - (u8*)iph6); |
Arnaldo Carvalho de Melo | c1d2bbe | 2007-04-10 20:45:18 -0700 | [diff] [blame] | 513 | skb_reset_network_header(skb2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | |
| 515 | /* Try to guess incoming interface */ |
Daniel Lezcano | 606a2b4 | 2008-03-04 13:45:59 -0800 | [diff] [blame] | 516 | rt6i = rt6_lookup(&init_net, &iph6->saddr, NULL, NULL, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | if (rt6i && rt6i->rt6i_dev) { |
| 518 | skb2->dev = rt6i->rt6i_dev; |
| 519 | |
Daniel Lezcano | 606a2b4 | 2008-03-04 13:45:59 -0800 | [diff] [blame] | 520 | rt6i = rt6_lookup(&init_net, &iph6->daddr, &iph6->saddr, NULL, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | |
| 522 | if (rt6i && rt6i->rt6i_dev && rt6i->rt6i_dev->type == ARPHRD_SIT) { |
Patrick McHardy | 2941a48 | 2006-01-08 22:05:26 -0800 | [diff] [blame] | 523 | struct ip_tunnel *t = netdev_priv(rt6i->rt6i_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | if (rel_type == ICMPV6_TIME_EXCEED && t->parms.iph.ttl) { |
| 525 | rel_type = ICMPV6_DEST_UNREACH; |
| 526 | rel_code = ICMPV6_ADDR_UNREACH; |
| 527 | } |
| 528 | icmpv6_send(skb2, rel_type, rel_code, rel_info, skb2->dev); |
| 529 | } |
| 530 | } |
| 531 | kfree_skb(skb2); |
Kazunori MIYAZAWA | c73cb5a | 2007-02-13 12:55:25 -0800 | [diff] [blame] | 532 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | #endif |
| 534 | } |
| 535 | |
| 536 | static inline void ipip6_ecn_decapsulate(struct iphdr *iph, struct sk_buff *skb) |
| 537 | { |
| 538 | if (INET_ECN_is_ce(iph->tos)) |
Arnaldo Carvalho de Melo | 0660e03 | 2007-04-25 17:54:47 -0700 | [diff] [blame] | 539 | IP6_ECN_set_ce(ipv6_hdr(skb)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | } |
| 541 | |
| 542 | static int ipip6_rcv(struct sk_buff *skb) |
| 543 | { |
| 544 | struct iphdr *iph; |
| 545 | struct ip_tunnel *tunnel; |
| 546 | |
| 547 | if (!pskb_may_pull(skb, sizeof(struct ipv6hdr))) |
| 548 | goto out; |
| 549 | |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 550 | iph = ip_hdr(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | |
| 552 | read_lock(&ipip6_lock); |
| 553 | if ((tunnel = ipip6_tunnel_lookup(iph->saddr, iph->daddr)) != NULL) { |
| 554 | secpath_reset(skb); |
Arnaldo Carvalho de Melo | b0e380b | 2007-04-10 21:21:55 -0700 | [diff] [blame] | 555 | skb->mac_header = skb->network_header; |
Arnaldo Carvalho de Melo | c1d2bbe | 2007-04-10 20:45:18 -0700 | [diff] [blame] | 556 | skb_reset_network_header(skb); |
Patrick McHardy | 8cdfab8 | 2006-01-06 23:04:01 -0800 | [diff] [blame] | 557 | IPCB(skb)->flags = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | skb->protocol = htons(ETH_P_IPV6); |
| 559 | skb->pkt_type = PACKET_HOST; |
Fred L. Templin | c7dc89c | 2007-11-29 22:11:40 +1100 | [diff] [blame] | 560 | |
| 561 | if ((tunnel->dev->priv_flags & IFF_ISATAP) && |
Templin, Fred L | fadf6bf | 2008-03-11 18:35:59 -0400 | [diff] [blame] | 562 | !isatap_chksrc(skb, iph, tunnel)) { |
Fred L. Templin | c7dc89c | 2007-11-29 22:11:40 +1100 | [diff] [blame] | 563 | tunnel->stat.rx_errors++; |
| 564 | read_unlock(&ipip6_lock); |
| 565 | kfree_skb(skb); |
| 566 | return 0; |
| 567 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | tunnel->stat.rx_packets++; |
| 569 | tunnel->stat.rx_bytes += skb->len; |
| 570 | skb->dev = tunnel->dev; |
| 571 | dst_release(skb->dst); |
| 572 | skb->dst = NULL; |
| 573 | nf_reset(skb); |
| 574 | ipip6_ecn_decapsulate(iph, skb); |
| 575 | netif_rx(skb); |
| 576 | read_unlock(&ipip6_lock); |
| 577 | return 0; |
| 578 | } |
| 579 | |
Herbert Xu | 45af08b | 2006-04-05 22:31:19 -0700 | [diff] [blame] | 580 | icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | kfree_skb(skb); |
| 582 | read_unlock(&ipip6_lock); |
| 583 | out: |
| 584 | return 0; |
| 585 | } |
| 586 | |
| 587 | /* Returns the embedded IPv4 address if the IPv6 address |
| 588 | comes from 6to4 (RFC 3056) addr space */ |
| 589 | |
Al Viro | e69a4ad | 2006-11-14 20:56:00 -0800 | [diff] [blame] | 590 | static inline __be32 try_6to4(struct in6_addr *v6dst) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | { |
Al Viro | e69a4ad | 2006-11-14 20:56:00 -0800 | [diff] [blame] | 592 | __be32 dst = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | |
| 594 | if (v6dst->s6_addr16[0] == htons(0x2002)) { |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 595 | /* 6to4 v6 addr has 16 bits prefix, 32 v4addr, 16 SLA, ... */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | memcpy(&dst, &v6dst->s6_addr16[1], 4); |
| 597 | } |
| 598 | return dst; |
| 599 | } |
| 600 | |
| 601 | /* |
| 602 | * This function assumes it is being called from dev_queue_xmit() |
| 603 | * and that skb is filled properly by that function. |
| 604 | */ |
| 605 | |
| 606 | static int ipip6_tunnel_xmit(struct sk_buff *skb, struct net_device *dev) |
| 607 | { |
Patrick McHardy | 2941a48 | 2006-01-08 22:05:26 -0800 | [diff] [blame] | 608 | struct ip_tunnel *tunnel = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | struct net_device_stats *stats = &tunnel->stat; |
| 610 | struct iphdr *tiph = &tunnel->parms.iph; |
Arnaldo Carvalho de Melo | 0660e03 | 2007-04-25 17:54:47 -0700 | [diff] [blame] | 611 | struct ipv6hdr *iph6 = ipv6_hdr(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | u8 tos = tunnel->parms.iph.tos; |
| 613 | struct rtable *rt; /* Route to the other host */ |
| 614 | struct net_device *tdev; /* Device to other host */ |
| 615 | struct iphdr *iph; /* Our new IP header */ |
Chuck Lever | c2636b4 | 2007-10-23 21:07:32 -0700 | [diff] [blame] | 616 | unsigned int max_headroom; /* The extra header space needed */ |
Al Viro | e69a4ad | 2006-11-14 20:56:00 -0800 | [diff] [blame] | 617 | __be32 dst = tiph->daddr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | int mtu; |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 619 | struct in6_addr *addr6; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | int addr_type; |
| 621 | |
| 622 | if (tunnel->recursion++) { |
| 623 | tunnel->stat.collisions++; |
| 624 | goto tx_error; |
| 625 | } |
| 626 | |
| 627 | if (skb->protocol != htons(ETH_P_IPV6)) |
| 628 | goto tx_error; |
| 629 | |
Fred L. Templin | c7dc89c | 2007-11-29 22:11:40 +1100 | [diff] [blame] | 630 | /* ISATAP (RFC4214) - must come before 6to4 */ |
| 631 | if (dev->priv_flags & IFF_ISATAP) { |
| 632 | struct neighbour *neigh = NULL; |
| 633 | |
| 634 | if (skb->dst) |
| 635 | neigh = skb->dst->neighbour; |
| 636 | |
| 637 | if (neigh == NULL) { |
| 638 | if (net_ratelimit()) |
| 639 | printk(KERN_DEBUG "sit: nexthop == NULL\n"); |
| 640 | goto tx_error; |
| 641 | } |
| 642 | |
| 643 | addr6 = (struct in6_addr*)&neigh->primary_key; |
| 644 | addr_type = ipv6_addr_type(addr6); |
| 645 | |
| 646 | if ((addr_type & IPV6_ADDR_UNICAST) && |
| 647 | ipv6_addr_is_isatap(addr6)) |
| 648 | dst = addr6->s6_addr32[3]; |
| 649 | else |
| 650 | goto tx_error; |
| 651 | } |
| 652 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | if (!dst) |
| 654 | dst = try_6to4(&iph6->daddr); |
| 655 | |
| 656 | if (!dst) { |
| 657 | struct neighbour *neigh = NULL; |
| 658 | |
| 659 | if (skb->dst) |
| 660 | neigh = skb->dst->neighbour; |
| 661 | |
| 662 | if (neigh == NULL) { |
| 663 | if (net_ratelimit()) |
| 664 | printk(KERN_DEBUG "sit: nexthop == NULL\n"); |
| 665 | goto tx_error; |
| 666 | } |
| 667 | |
| 668 | addr6 = (struct in6_addr*)&neigh->primary_key; |
| 669 | addr_type = ipv6_addr_type(addr6); |
| 670 | |
| 671 | if (addr_type == IPV6_ADDR_ANY) { |
Arnaldo Carvalho de Melo | 0660e03 | 2007-04-25 17:54:47 -0700 | [diff] [blame] | 672 | addr6 = &ipv6_hdr(skb)->daddr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | addr_type = ipv6_addr_type(addr6); |
| 674 | } |
| 675 | |
| 676 | if ((addr_type & IPV6_ADDR_COMPATv4) == 0) |
| 677 | goto tx_error_icmp; |
| 678 | |
| 679 | dst = addr6->s6_addr32[3]; |
| 680 | } |
| 681 | |
| 682 | { |
| 683 | struct flowi fl = { .nl_u = { .ip4_u = |
| 684 | { .daddr = dst, |
| 685 | .saddr = tiph->saddr, |
| 686 | .tos = RT_TOS(tos) } }, |
| 687 | .oif = tunnel->parms.link, |
| 688 | .proto = IPPROTO_IPV6 }; |
Denis V. Lunev | f206351 | 2008-01-22 22:07:34 -0800 | [diff] [blame] | 689 | if (ip_route_output_key(&init_net, &rt, &fl)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | tunnel->stat.tx_carrier_errors++; |
| 691 | goto tx_error_icmp; |
| 692 | } |
| 693 | } |
| 694 | if (rt->rt_type != RTN_UNICAST) { |
| 695 | ip_rt_put(rt); |
| 696 | tunnel->stat.tx_carrier_errors++; |
| 697 | goto tx_error_icmp; |
| 698 | } |
| 699 | tdev = rt->u.dst.dev; |
| 700 | |
| 701 | if (tdev == dev) { |
| 702 | ip_rt_put(rt); |
| 703 | tunnel->stat.collisions++; |
| 704 | goto tx_error; |
| 705 | } |
| 706 | |
| 707 | if (tiph->frag_off) |
| 708 | mtu = dst_mtu(&rt->u.dst) - sizeof(struct iphdr); |
| 709 | else |
| 710 | mtu = skb->dst ? dst_mtu(skb->dst) : dev->mtu; |
| 711 | |
| 712 | if (mtu < 68) { |
| 713 | tunnel->stat.collisions++; |
| 714 | ip_rt_put(rt); |
| 715 | goto tx_error; |
| 716 | } |
| 717 | if (mtu < IPV6_MIN_MTU) |
| 718 | mtu = IPV6_MIN_MTU; |
| 719 | if (tunnel->parms.iph.daddr && skb->dst) |
| 720 | skb->dst->ops->update_pmtu(skb->dst, mtu); |
| 721 | |
| 722 | if (skb->len > mtu) { |
| 723 | icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu, dev); |
| 724 | ip_rt_put(rt); |
| 725 | goto tx_error; |
| 726 | } |
| 727 | |
| 728 | if (tunnel->err_count > 0) { |
| 729 | if (jiffies - tunnel->err_time < IPTUNNEL_ERR_TIMEO) { |
| 730 | tunnel->err_count--; |
| 731 | dst_link_failure(skb); |
| 732 | } else |
| 733 | tunnel->err_count = 0; |
| 734 | } |
| 735 | |
| 736 | /* |
| 737 | * Okay, now see if we can stuff it in the buffer as-is. |
| 738 | */ |
| 739 | max_headroom = LL_RESERVED_SPACE(tdev)+sizeof(struct iphdr); |
| 740 | |
Patrick McHardy | cfbba49 | 2007-07-09 15:33:40 -0700 | [diff] [blame] | 741 | if (skb_headroom(skb) < max_headroom || skb_shared(skb) || |
| 742 | (skb_cloned(skb) && !skb_clone_writable(skb, 0))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 743 | struct sk_buff *new_skb = skb_realloc_headroom(skb, max_headroom); |
| 744 | if (!new_skb) { |
| 745 | ip_rt_put(rt); |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 746 | stats->tx_dropped++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | dev_kfree_skb(skb); |
| 748 | tunnel->recursion--; |
| 749 | return 0; |
| 750 | } |
| 751 | if (skb->sk) |
| 752 | skb_set_owner_w(new_skb, skb->sk); |
| 753 | dev_kfree_skb(skb); |
| 754 | skb = new_skb; |
Arnaldo Carvalho de Melo | 0660e03 | 2007-04-25 17:54:47 -0700 | [diff] [blame] | 755 | iph6 = ipv6_hdr(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | } |
| 757 | |
Arnaldo Carvalho de Melo | b0e380b | 2007-04-10 21:21:55 -0700 | [diff] [blame] | 758 | skb->transport_header = skb->network_header; |
Arnaldo Carvalho de Melo | e2d1bca | 2007-04-10 20:46:21 -0700 | [diff] [blame] | 759 | skb_push(skb, sizeof(struct iphdr)); |
| 760 | skb_reset_network_header(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt)); |
Patrick McHardy | 8cdfab8 | 2006-01-06 23:04:01 -0800 | [diff] [blame] | 762 | IPCB(skb)->flags = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 763 | dst_release(skb->dst); |
| 764 | skb->dst = &rt->u.dst; |
| 765 | |
| 766 | /* |
| 767 | * Push down and install the IPIP header. |
| 768 | */ |
| 769 | |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 770 | iph = ip_hdr(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 771 | iph->version = 4; |
| 772 | iph->ihl = sizeof(struct iphdr)>>2; |
| 773 | if (mtu > IPV6_MIN_MTU) |
| 774 | iph->frag_off = htons(IP_DF); |
| 775 | else |
| 776 | iph->frag_off = 0; |
| 777 | |
| 778 | iph->protocol = IPPROTO_IPV6; |
| 779 | iph->tos = INET_ECN_encapsulate(tos, ipv6_get_dsfield(iph6)); |
| 780 | iph->daddr = rt->rt_dst; |
| 781 | iph->saddr = rt->rt_src; |
| 782 | |
| 783 | if ((iph->ttl = tiph->ttl) == 0) |
| 784 | iph->ttl = iph6->hop_limit; |
| 785 | |
| 786 | nf_reset(skb); |
| 787 | |
| 788 | IPTUNNEL_XMIT(); |
| 789 | tunnel->recursion--; |
| 790 | return 0; |
| 791 | |
| 792 | tx_error_icmp: |
| 793 | dst_link_failure(skb); |
| 794 | tx_error: |
| 795 | stats->tx_errors++; |
| 796 | dev_kfree_skb(skb); |
| 797 | tunnel->recursion--; |
| 798 | return 0; |
| 799 | } |
| 800 | |
Michal Schmidt | 8a4a50f | 2007-12-13 09:47:00 -0800 | [diff] [blame] | 801 | static void ipip6_tunnel_bind_dev(struct net_device *dev) |
| 802 | { |
| 803 | struct net_device *tdev = NULL; |
| 804 | struct ip_tunnel *tunnel; |
| 805 | struct iphdr *iph; |
| 806 | |
| 807 | tunnel = netdev_priv(dev); |
| 808 | iph = &tunnel->parms.iph; |
| 809 | |
| 810 | if (iph->daddr) { |
| 811 | struct flowi fl = { .nl_u = { .ip4_u = |
| 812 | { .daddr = iph->daddr, |
| 813 | .saddr = iph->saddr, |
| 814 | .tos = RT_TOS(iph->tos) } }, |
| 815 | .oif = tunnel->parms.link, |
| 816 | .proto = IPPROTO_IPV6 }; |
| 817 | struct rtable *rt; |
Denis V. Lunev | f206351 | 2008-01-22 22:07:34 -0800 | [diff] [blame] | 818 | if (!ip_route_output_key(&init_net, &rt, &fl)) { |
Michal Schmidt | 8a4a50f | 2007-12-13 09:47:00 -0800 | [diff] [blame] | 819 | tdev = rt->u.dst.dev; |
| 820 | ip_rt_put(rt); |
| 821 | } |
| 822 | dev->flags |= IFF_POINTOPOINT; |
| 823 | } |
| 824 | |
| 825 | if (!tdev && tunnel->parms.link) |
| 826 | tdev = __dev_get_by_index(&init_net, tunnel->parms.link); |
| 827 | |
| 828 | if (tdev) { |
| 829 | dev->hard_header_len = tdev->hard_header_len + sizeof(struct iphdr); |
| 830 | dev->mtu = tdev->mtu - sizeof(struct iphdr); |
| 831 | if (dev->mtu < IPV6_MIN_MTU) |
| 832 | dev->mtu = IPV6_MIN_MTU; |
| 833 | } |
| 834 | dev->iflink = tunnel->parms.link; |
| 835 | } |
| 836 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | static int |
| 838 | ipip6_tunnel_ioctl (struct net_device *dev, struct ifreq *ifr, int cmd) |
| 839 | { |
| 840 | int err = 0; |
| 841 | struct ip_tunnel_parm p; |
Templin, Fred L | fadf6bf | 2008-03-11 18:35:59 -0400 | [diff] [blame] | 842 | struct ip_tunnel_prl prl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | struct ip_tunnel *t; |
| 844 | |
| 845 | switch (cmd) { |
| 846 | case SIOCGETTUNNEL: |
| 847 | t = NULL; |
| 848 | if (dev == ipip6_fb_tunnel_dev) { |
| 849 | if (copy_from_user(&p, ifr->ifr_ifru.ifru_data, sizeof(p))) { |
| 850 | err = -EFAULT; |
| 851 | break; |
| 852 | } |
| 853 | t = ipip6_tunnel_locate(&p, 0); |
| 854 | } |
| 855 | if (t == NULL) |
Patrick McHardy | 2941a48 | 2006-01-08 22:05:26 -0800 | [diff] [blame] | 856 | t = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 857 | memcpy(&p, &t->parms, sizeof(p)); |
| 858 | if (copy_to_user(ifr->ifr_ifru.ifru_data, &p, sizeof(p))) |
| 859 | err = -EFAULT; |
| 860 | break; |
| 861 | |
| 862 | case SIOCADDTUNNEL: |
| 863 | case SIOCCHGTUNNEL: |
| 864 | err = -EPERM; |
| 865 | if (!capable(CAP_NET_ADMIN)) |
| 866 | goto done; |
| 867 | |
| 868 | err = -EFAULT; |
| 869 | if (copy_from_user(&p, ifr->ifr_ifru.ifru_data, sizeof(p))) |
| 870 | goto done; |
| 871 | |
| 872 | err = -EINVAL; |
| 873 | if (p.iph.version != 4 || p.iph.protocol != IPPROTO_IPV6 || |
| 874 | p.iph.ihl != 5 || (p.iph.frag_off&htons(~IP_DF))) |
| 875 | goto done; |
| 876 | if (p.iph.ttl) |
| 877 | p.iph.frag_off |= htons(IP_DF); |
| 878 | |
| 879 | t = ipip6_tunnel_locate(&p, cmd == SIOCADDTUNNEL); |
| 880 | |
| 881 | if (dev != ipip6_fb_tunnel_dev && cmd == SIOCCHGTUNNEL) { |
| 882 | if (t != NULL) { |
| 883 | if (t->dev != dev) { |
| 884 | err = -EEXIST; |
| 885 | break; |
| 886 | } |
| 887 | } else { |
| 888 | if (((dev->flags&IFF_POINTOPOINT) && !p.iph.daddr) || |
| 889 | (!(dev->flags&IFF_POINTOPOINT) && p.iph.daddr)) { |
| 890 | err = -EINVAL; |
| 891 | break; |
| 892 | } |
Patrick McHardy | 2941a48 | 2006-01-08 22:05:26 -0800 | [diff] [blame] | 893 | t = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | ipip6_tunnel_unlink(t); |
| 895 | t->parms.iph.saddr = p.iph.saddr; |
| 896 | t->parms.iph.daddr = p.iph.daddr; |
| 897 | memcpy(dev->dev_addr, &p.iph.saddr, 4); |
| 898 | memcpy(dev->broadcast, &p.iph.daddr, 4); |
| 899 | ipip6_tunnel_link(t); |
| 900 | netdev_state_change(dev); |
| 901 | } |
| 902 | } |
| 903 | |
| 904 | if (t) { |
| 905 | err = 0; |
| 906 | if (cmd == SIOCCHGTUNNEL) { |
| 907 | t->parms.iph.ttl = p.iph.ttl; |
| 908 | t->parms.iph.tos = p.iph.tos; |
Michal Schmidt | 8a4a50f | 2007-12-13 09:47:00 -0800 | [diff] [blame] | 909 | if (t->parms.link != p.link) { |
| 910 | t->parms.link = p.link; |
| 911 | ipip6_tunnel_bind_dev(dev); |
| 912 | netdev_state_change(dev); |
| 913 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 914 | } |
| 915 | if (copy_to_user(ifr->ifr_ifru.ifru_data, &t->parms, sizeof(p))) |
| 916 | err = -EFAULT; |
| 917 | } else |
| 918 | err = (cmd == SIOCADDTUNNEL ? -ENOBUFS : -ENOENT); |
| 919 | break; |
| 920 | |
| 921 | case SIOCDELTUNNEL: |
| 922 | err = -EPERM; |
| 923 | if (!capable(CAP_NET_ADMIN)) |
| 924 | goto done; |
| 925 | |
| 926 | if (dev == ipip6_fb_tunnel_dev) { |
| 927 | err = -EFAULT; |
| 928 | if (copy_from_user(&p, ifr->ifr_ifru.ifru_data, sizeof(p))) |
| 929 | goto done; |
| 930 | err = -ENOENT; |
| 931 | if ((t = ipip6_tunnel_locate(&p, 0)) == NULL) |
| 932 | goto done; |
| 933 | err = -EPERM; |
Patrick McHardy | 2941a48 | 2006-01-08 22:05:26 -0800 | [diff] [blame] | 934 | if (t == netdev_priv(ipip6_fb_tunnel_dev)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | goto done; |
| 936 | dev = t->dev; |
| 937 | } |
Stephen Hemminger | 22f8cde | 2007-02-07 00:09:58 -0800 | [diff] [blame] | 938 | unregister_netdevice(dev); |
| 939 | err = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | break; |
| 941 | |
YOSHIFUJI Hideaki | 300aaee | 2008-03-24 18:28:39 +0900 | [diff] [blame] | 942 | case SIOCGETPRL: |
Templin, Fred L | fadf6bf | 2008-03-11 18:35:59 -0400 | [diff] [blame] | 943 | case SIOCADDPRL: |
| 944 | case SIOCDELPRL: |
| 945 | case SIOCCHGPRL: |
| 946 | err = -EPERM; |
YOSHIFUJI Hideaki | 300aaee | 2008-03-24 18:28:39 +0900 | [diff] [blame] | 947 | if (cmd != SIOCGETPRL && !capable(CAP_NET_ADMIN)) |
Templin, Fred L | fadf6bf | 2008-03-11 18:35:59 -0400 | [diff] [blame] | 948 | goto done; |
| 949 | err = -EINVAL; |
| 950 | if (dev == ipip6_fb_tunnel_dev) |
| 951 | goto done; |
| 952 | err = -EFAULT; |
| 953 | if (copy_from_user(&prl, ifr->ifr_ifru.ifru_data, sizeof(prl))) |
| 954 | goto done; |
| 955 | err = -ENOENT; |
| 956 | if (!(t = netdev_priv(dev))) |
| 957 | goto done; |
| 958 | |
YOSHIFUJI Hideaki | 300aaee | 2008-03-24 18:28:39 +0900 | [diff] [blame] | 959 | switch (cmd) { |
| 960 | case SIOCGETPRL: |
| 961 | err = ipip6_tunnel_get_prl(t, &prl); |
| 962 | if (!err && copy_to_user(ifr->ifr_ifru.ifru_data, |
| 963 | &prl, sizeof(prl))) |
| 964 | err = -EFAULT; |
| 965 | break; |
| 966 | case SIOCDELPRL: |
Templin, Fred L | fadf6bf | 2008-03-11 18:35:59 -0400 | [diff] [blame] | 967 | err = ipip6_tunnel_del_prl(t, &prl); |
YOSHIFUJI Hideaki | 300aaee | 2008-03-24 18:28:39 +0900 | [diff] [blame] | 968 | break; |
| 969 | case SIOCADDPRL: |
| 970 | case SIOCCHGPRL: |
Templin, Fred L | fadf6bf | 2008-03-11 18:35:59 -0400 | [diff] [blame] | 971 | err = ipip6_tunnel_add_prl(t, &prl, cmd == SIOCCHGPRL); |
YOSHIFUJI Hideaki | 300aaee | 2008-03-24 18:28:39 +0900 | [diff] [blame] | 972 | break; |
| 973 | } |
| 974 | if (cmd != SIOCGETPRL) |
| 975 | netdev_state_change(dev); |
Templin, Fred L | fadf6bf | 2008-03-11 18:35:59 -0400 | [diff] [blame] | 976 | break; |
| 977 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 978 | default: |
| 979 | err = -EINVAL; |
| 980 | } |
| 981 | |
| 982 | done: |
| 983 | return err; |
| 984 | } |
| 985 | |
| 986 | static struct net_device_stats *ipip6_tunnel_get_stats(struct net_device *dev) |
| 987 | { |
Patrick McHardy | 2941a48 | 2006-01-08 22:05:26 -0800 | [diff] [blame] | 988 | return &(((struct ip_tunnel*)netdev_priv(dev))->stat); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 989 | } |
| 990 | |
| 991 | static int ipip6_tunnel_change_mtu(struct net_device *dev, int new_mtu) |
| 992 | { |
| 993 | if (new_mtu < IPV6_MIN_MTU || new_mtu > 0xFFF8 - sizeof(struct iphdr)) |
| 994 | return -EINVAL; |
| 995 | dev->mtu = new_mtu; |
| 996 | return 0; |
| 997 | } |
| 998 | |
| 999 | static void ipip6_tunnel_setup(struct net_device *dev) |
| 1000 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1001 | dev->uninit = ipip6_tunnel_uninit; |
| 1002 | dev->destructor = free_netdev; |
| 1003 | dev->hard_start_xmit = ipip6_tunnel_xmit; |
| 1004 | dev->get_stats = ipip6_tunnel_get_stats; |
| 1005 | dev->do_ioctl = ipip6_tunnel_ioctl; |
| 1006 | dev->change_mtu = ipip6_tunnel_change_mtu; |
| 1007 | |
| 1008 | dev->type = ARPHRD_SIT; |
| 1009 | dev->hard_header_len = LL_MAX_HEADER + sizeof(struct iphdr); |
Kris Katterjohn | 46f25df | 2006-01-05 16:35:42 -0800 | [diff] [blame] | 1010 | dev->mtu = ETH_DATA_LEN - sizeof(struct iphdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1011 | dev->flags = IFF_NOARP; |
| 1012 | dev->iflink = 0; |
| 1013 | dev->addr_len = 4; |
| 1014 | } |
| 1015 | |
| 1016 | static int ipip6_tunnel_init(struct net_device *dev) |
| 1017 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1018 | struct ip_tunnel *tunnel; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1019 | |
Patrick McHardy | 2941a48 | 2006-01-08 22:05:26 -0800 | [diff] [blame] | 1020 | tunnel = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1021 | |
| 1022 | tunnel->dev = dev; |
| 1023 | strcpy(tunnel->parms.name, dev->name); |
| 1024 | |
| 1025 | memcpy(dev->dev_addr, &tunnel->parms.iph.saddr, 4); |
| 1026 | memcpy(dev->broadcast, &tunnel->parms.iph.daddr, 4); |
| 1027 | |
Michal Schmidt | 8a4a50f | 2007-12-13 09:47:00 -0800 | [diff] [blame] | 1028 | ipip6_tunnel_bind_dev(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1029 | |
| 1030 | return 0; |
| 1031 | } |
| 1032 | |
Arnaldo Carvalho de Melo | 2038073 | 2005-08-16 02:18:02 -0300 | [diff] [blame] | 1033 | static int __init ipip6_fb_tunnel_init(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1034 | { |
Patrick McHardy | 2941a48 | 2006-01-08 22:05:26 -0800 | [diff] [blame] | 1035 | struct ip_tunnel *tunnel = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1036 | struct iphdr *iph = &tunnel->parms.iph; |
| 1037 | |
| 1038 | tunnel->dev = dev; |
| 1039 | strcpy(tunnel->parms.name, dev->name); |
| 1040 | |
| 1041 | iph->version = 4; |
| 1042 | iph->protocol = IPPROTO_IPV6; |
| 1043 | iph->ihl = 5; |
| 1044 | iph->ttl = 64; |
| 1045 | |
| 1046 | dev_hold(dev); |
| 1047 | tunnels_wc[0] = tunnel; |
| 1048 | return 0; |
| 1049 | } |
| 1050 | |
Kazunori MIYAZAWA | c73cb5a | 2007-02-13 12:55:25 -0800 | [diff] [blame] | 1051 | static struct xfrm_tunnel sit_handler = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1052 | .handler = ipip6_rcv, |
| 1053 | .err_handler = ipip6_err, |
Kazunori MIYAZAWA | c73cb5a | 2007-02-13 12:55:25 -0800 | [diff] [blame] | 1054 | .priority = 1, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1055 | }; |
| 1056 | |
Alexey Kuznetsov | db44575 | 2005-07-30 17:46:44 -0700 | [diff] [blame] | 1057 | static void __exit sit_destroy_tunnels(void) |
| 1058 | { |
| 1059 | int prio; |
| 1060 | |
| 1061 | for (prio = 1; prio < 4; prio++) { |
| 1062 | int h; |
| 1063 | for (h = 0; h < HASH_SIZE; h++) { |
| 1064 | struct ip_tunnel *t; |
| 1065 | while ((t = tunnels[prio][h]) != NULL) |
| 1066 | unregister_netdevice(t->dev); |
| 1067 | } |
| 1068 | } |
| 1069 | } |
| 1070 | |
Adrian Bunk | 89c8945 | 2006-11-20 16:56:48 -0800 | [diff] [blame] | 1071 | static void __exit sit_cleanup(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1072 | { |
Kazunori MIYAZAWA | c73cb5a | 2007-02-13 12:55:25 -0800 | [diff] [blame] | 1073 | xfrm4_tunnel_deregister(&sit_handler, AF_INET6); |
Alexey Kuznetsov | db44575 | 2005-07-30 17:46:44 -0700 | [diff] [blame] | 1074 | |
| 1075 | rtnl_lock(); |
| 1076 | sit_destroy_tunnels(); |
| 1077 | unregister_netdevice(ipip6_fb_tunnel_dev); |
| 1078 | rtnl_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1079 | } |
| 1080 | |
Adrian Bunk | 89c8945 | 2006-11-20 16:56:48 -0800 | [diff] [blame] | 1081 | static int __init sit_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1082 | { |
| 1083 | int err; |
| 1084 | |
| 1085 | printk(KERN_INFO "IPv6 over IPv4 tunneling driver\n"); |
| 1086 | |
Kazunori MIYAZAWA | c73cb5a | 2007-02-13 12:55:25 -0800 | [diff] [blame] | 1087 | if (xfrm4_tunnel_register(&sit_handler, AF_INET6) < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1088 | printk(KERN_INFO "sit init: Can't add protocol\n"); |
| 1089 | return -EAGAIN; |
| 1090 | } |
| 1091 | |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 1092 | ipip6_fb_tunnel_dev = alloc_netdev(sizeof(struct ip_tunnel), "sit0", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1093 | ipip6_tunnel_setup); |
| 1094 | if (!ipip6_fb_tunnel_dev) { |
| 1095 | err = -ENOMEM; |
| 1096 | goto err1; |
| 1097 | } |
| 1098 | |
| 1099 | ipip6_fb_tunnel_dev->init = ipip6_fb_tunnel_init; |
| 1100 | |
| 1101 | if ((err = register_netdev(ipip6_fb_tunnel_dev))) |
| 1102 | goto err2; |
| 1103 | |
| 1104 | out: |
| 1105 | return err; |
| 1106 | err2: |
| 1107 | free_netdev(ipip6_fb_tunnel_dev); |
| 1108 | err1: |
Kazunori MIYAZAWA | c73cb5a | 2007-02-13 12:55:25 -0800 | [diff] [blame] | 1109 | xfrm4_tunnel_deregister(&sit_handler, AF_INET6); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1110 | goto out; |
| 1111 | } |
Joerg Roedel | 989e5b9 | 2006-10-10 14:47:44 -0700 | [diff] [blame] | 1112 | |
| 1113 | module_init(sit_init); |
| 1114 | module_exit(sit_cleanup); |
Jan Dittmer | 39c8508 | 2006-10-13 15:05:53 -0700 | [diff] [blame] | 1115 | MODULE_LICENSE("GPL"); |
Patrick McHardy | daccff0 | 2006-11-05 15:47:04 -0800 | [diff] [blame] | 1116 | MODULE_ALIAS("sit0"); |