1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /* 3 * IPv6 over IPv4 tunnel device - Simple Internet Transition (SIT) 4 * Linux INET6 implementation 5 * 6 * Authors: 7 * Pedro Roque <roque@di.fc.ul.pt> 8 * Alexey Kuznetsov <kuznet@ms2.inr.ac.ru> 9 * 10 * Changes: 11 * Roger Venning <r.venning@telstra.com>: 6to4 support 12 * Nate Thompson <nate@thebog.net>: 6to4 support 13 * Fred Templin <fred.l.templin@boeing.com>: isatap support 14 */ 15 16 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 17 18 #include <linux/module.h> 19 #include <linux/capability.h> 20 #include <linux/errno.h> 21 #include <linux/types.h> 22 #include <linux/socket.h> 23 #include <linux/sockios.h> 24 #include <linux/string.h> 25 #include <linux/net.h> 26 #include <linux/in6.h> 27 #include <linux/netdevice.h> 28 #include <linux/if_arp.h> 29 #include <linux/icmp.h> 30 #include <linux/slab.h> 31 #include <linux/uaccess.h> 32 #include <linux/init.h> 33 #include <linux/netfilter_ipv4.h> 34 #include <linux/if_ether.h> 35 36 #include <net/sock.h> 37 #include <net/snmp.h> 38 39 #include <net/ipv6.h> 40 #include <net/protocol.h> 41 #include <net/transp_v6.h> 42 #include <net/ip6_fib.h> 43 #include <net/ip6_route.h> 44 #include <net/ndisc.h> 45 #include <net/addrconf.h> 46 #include <net/ip.h> 47 #include <net/udp.h> 48 #include <net/icmp.h> 49 #include <net/ip_tunnels.h> 50 #include <net/inet_ecn.h> 51 #include <net/xfrm.h> 52 #include <net/dsfield.h> 53 #include <net/net_namespace.h> 54 #include <net/netns/generic.h> 55 #include <net/netdev_lock.h> 56 #include <net/inet_dscp.h> 57 58 /* 59 This version of net/ipv6/sit.c is cloned of net/ipv4/ip_gre.c 60 61 For comments look at net/ipv4/ip_gre.c --ANK 62 */ 63 64 #define IP6_SIT_HASH_SIZE 16 65 #define HASH(addr) (((__force u32)addr^((__force u32)addr>>4))&0xF) 66 67 static bool log_ecn_error = true; 68 module_param(log_ecn_error, bool, 0644); 69 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN"); 70 71 static int ipip6_tunnel_init(struct net_device *dev); 72 static void ipip6_tunnel_setup(struct net_device *dev); 73 static void ipip6_dev_free(struct net_device *dev); 74 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst, 75 __be32 *v4dst); 76 static struct rtnl_link_ops sit_link_ops __read_mostly; 77 78 static unsigned int sit_net_id __read_mostly; 79 struct sit_net { 80 struct ip_tunnel __rcu *tunnels_r_l[IP6_SIT_HASH_SIZE]; 81 struct ip_tunnel __rcu *tunnels_r[IP6_SIT_HASH_SIZE]; 82 struct ip_tunnel __rcu *tunnels_l[IP6_SIT_HASH_SIZE]; 83 struct ip_tunnel __rcu *tunnels_wc[1]; 84 struct ip_tunnel __rcu **tunnels[4]; 85 86 struct net_device *fb_tunnel_dev; 87 }; 88 89 static inline struct sit_net *dev_to_sit_net(struct net_device *dev) 90 { 91 struct ip_tunnel *t = netdev_priv(dev); 92 93 return net_generic(t->net, sit_net_id); 94 } 95 96 /* 97 * Must be invoked with rcu_read_lock 98 */ 99 static struct ip_tunnel *ipip6_tunnel_lookup(struct net *net, 100 struct net_device *dev, 101 __be32 remote, __be32 local, 102 int sifindex) 103 { 104 unsigned int h0 = HASH(remote); 105 unsigned int h1 = HASH(local); 106 struct ip_tunnel *t; 107 struct sit_net *sitn = net_generic(net, sit_net_id); 108 int ifindex = dev ? dev->ifindex : 0; 109 110 for_each_ip_tunnel_rcu(t, sitn->tunnels_r_l[h0 ^ h1]) { 111 if (local == t->parms.iph.saddr && 112 remote == t->parms.iph.daddr && 113 (!dev || !t->parms.link || ifindex == t->parms.link || 114 sifindex == t->parms.link) && 115 (t->dev->flags & IFF_UP)) 116 return t; 117 } 118 for_each_ip_tunnel_rcu(t, sitn->tunnels_r[h0]) { 119 if (remote == t->parms.iph.daddr && 120 (!dev || !t->parms.link || ifindex == t->parms.link || 121 sifindex == t->parms.link) && 122 (t->dev->flags & IFF_UP)) 123 return t; 124 } 125 for_each_ip_tunnel_rcu(t, sitn->tunnels_l[h1]) { 126 if (local == t->parms.iph.saddr && 127 (!dev || !t->parms.link || ifindex == t->parms.link || 128 sifindex == t->parms.link) && 129 (t->dev->flags & IFF_UP)) 130 return t; 131 } 132 t = rcu_dereference(sitn->tunnels_wc[0]); 133 if (t && (t->dev->flags & IFF_UP)) 134 return t; 135 return NULL; 136 } 137 138 static struct ip_tunnel __rcu ** 139 __ipip6_bucket(struct sit_net *sitn, struct ip_tunnel_parm_kern *parms) 140 { 141 __be32 remote = parms->iph.daddr; 142 __be32 local = parms->iph.saddr; 143 unsigned int h = 0; 144 int prio = 0; 145 146 if (remote) { 147 prio |= 2; 148 h ^= HASH(remote); 149 } 150 if (local) { 151 prio |= 1; 152 h ^= HASH(local); 153 } 154 return &sitn->tunnels[prio][h]; 155 } 156 157 static inline struct ip_tunnel __rcu **ipip6_bucket(struct sit_net *sitn, 158 struct ip_tunnel *t) 159 { 160 return __ipip6_bucket(sitn, &t->parms); 161 } 162 163 static void ipip6_tunnel_unlink(struct sit_net *sitn, struct ip_tunnel *t) 164 { 165 struct ip_tunnel __rcu **tp; 166 struct ip_tunnel *iter; 167 168 for (tp = ipip6_bucket(sitn, t); 169 (iter = rtnl_dereference(*tp)) != NULL; 170 tp = &iter->next) { 171 if (t == iter) { 172 rcu_assign_pointer(*tp, t->next); 173 break; 174 } 175 } 176 } 177 178 static void ipip6_tunnel_link(struct sit_net *sitn, struct ip_tunnel *t) 179 { 180 struct ip_tunnel __rcu **tp = ipip6_bucket(sitn, t); 181 182 rcu_assign_pointer(t->next, rtnl_dereference(*tp)); 183 rcu_assign_pointer(*tp, t); 184 } 185 186 static void ipip6_tunnel_clone_6rd(struct net_device *dev, struct sit_net *sitn) 187 { 188 #ifdef CONFIG_IPV6_SIT_6RD 189 struct ip_tunnel *t = netdev_priv(dev); 190 191 if (dev == sitn->fb_tunnel_dev || !sitn->fb_tunnel_dev) { 192 ipv6_addr_set(&t->ip6rd.prefix, htonl(0x20020000), 0, 0, 0); 193 t->ip6rd.relay_prefix = 0; 194 t->ip6rd.prefixlen = 16; 195 t->ip6rd.relay_prefixlen = 0; 196 } else { 197 struct ip_tunnel *t0 = netdev_priv(sitn->fb_tunnel_dev); 198 memcpy(&t->ip6rd, &t0->ip6rd, sizeof(t->ip6rd)); 199 } 200 #endif 201 } 202 203 static int ipip6_tunnel_create(struct net_device *dev) 204 { 205 struct ip_tunnel *t = netdev_priv(dev); 206 struct sit_net *sitn = net_generic(t->net, sit_net_id); 207 int err; 208 209 __dev_addr_set(dev, &t->parms.iph.saddr, 4); 210 memcpy(dev->broadcast, &t->parms.iph.daddr, 4); 211 212 if (test_bit(IP_TUNNEL_SIT_ISATAP_BIT, t->parms.i_flags)) 213 dev->priv_flags |= IFF_ISATAP; 214 215 dev->rtnl_link_ops = &sit_link_ops; 216 217 err = register_netdevice(dev); 218 if (err < 0) 219 goto out; 220 221 ipip6_tunnel_clone_6rd(dev, sitn); 222 223 ipip6_tunnel_link(sitn, t); 224 return 0; 225 226 out: 227 return err; 228 } 229 230 static struct ip_tunnel *ipip6_tunnel_locate(struct net *net, 231 struct ip_tunnel_parm_kern *parms, 232 int create) 233 { 234 __be32 remote = parms->iph.daddr; 235 __be32 local = parms->iph.saddr; 236 struct ip_tunnel *t, *nt; 237 struct ip_tunnel __rcu **tp; 238 struct net_device *dev; 239 char name[IFNAMSIZ]; 240 struct sit_net *sitn = net_generic(net, sit_net_id); 241 242 for (tp = __ipip6_bucket(sitn, parms); 243 (t = rtnl_dereference(*tp)) != NULL; 244 tp = &t->next) { 245 if (local == t->parms.iph.saddr && 246 remote == t->parms.iph.daddr && 247 parms->link == t->parms.link) { 248 if (create) 249 return NULL; 250 else 251 return t; 252 } 253 } 254 if (!create) 255 goto failed; 256 257 if (parms->name[0]) { 258 if (!dev_valid_name(parms->name)) 259 goto failed; 260 strscpy(name, parms->name); 261 } else { 262 strscpy(name, "sit%d"); 263 } 264 dev = alloc_netdev(sizeof(*t), name, NET_NAME_UNKNOWN, 265 ipip6_tunnel_setup); 266 if (!dev) 267 return NULL; 268 269 dev_net_set(dev, net); 270 271 nt = netdev_priv(dev); 272 273 nt->net = net; 274 nt->parms = *parms; 275 if (ipip6_tunnel_create(dev) < 0) 276 goto failed_free; 277 278 if (!parms->name[0]) 279 strscpy(parms->name, dev->name); 280 281 return nt; 282 283 failed_free: 284 free_netdev(dev); 285 failed: 286 return NULL; 287 } 288 289 #define for_each_prl_rcu(start) \ 290 for (prl = rcu_dereference(start); \ 291 prl; \ 292 prl = rcu_dereference(prl->next)) 293 294 static struct ip_tunnel_prl_entry * 295 __ipip6_tunnel_locate_prl(struct ip_tunnel *t, __be32 addr) 296 { 297 struct ip_tunnel_prl_entry *prl; 298 299 for_each_prl_rcu(t->prl) 300 if (prl->addr == addr) 301 break; 302 return prl; 303 304 } 305 306 static int ipip6_tunnel_get_prl(struct net_device *dev, struct ip_tunnel_prl __user *a) 307 { 308 struct ip_tunnel *t = netdev_priv(dev); 309 struct ip_tunnel_prl kprl, *kp; 310 struct ip_tunnel_prl_entry *prl; 311 unsigned int cmax, c = 0, ca, len; 312 int ret; 313 314 if (dev == dev_to_sit_net(dev)->fb_tunnel_dev) 315 return -EINVAL; 316 317 if (copy_from_user(&kprl, a, sizeof(kprl))) 318 return -EFAULT; 319 cmax = kprl.datalen / sizeof(kprl); 320 if (cmax > 1 && kprl.addr != htonl(INADDR_ANY)) 321 cmax = 1; 322 323 /* For simple GET or for root users, 324 * we try harder to allocate. 325 */ 326 kp = (cmax <= 1 || capable(CAP_NET_ADMIN)) ? 327 kzalloc_objs(*kp, cmax, GFP_KERNEL_ACCOUNT | __GFP_NOWARN) : 328 NULL; 329 330 ca = min(t->prl_count, cmax); 331 332 if (!kp) { 333 /* We don't try hard to allocate much memory for 334 * non-root users. 335 * For root users, retry allocating enough memory for 336 * the answer. 337 */ 338 kp = kzalloc_objs(*kp, ca, 339 GFP_ATOMIC | __GFP_ACCOUNT | __GFP_NOWARN); 340 if (!kp) { 341 ret = -ENOMEM; 342 goto out; 343 } 344 } 345 346 rcu_read_lock(); 347 for_each_prl_rcu(t->prl) { 348 if (c >= cmax) 349 break; 350 if (kprl.addr != htonl(INADDR_ANY) && prl->addr != kprl.addr) 351 continue; 352 kp[c].addr = prl->addr; 353 kp[c].flags = prl->flags; 354 c++; 355 if (kprl.addr != htonl(INADDR_ANY)) 356 break; 357 } 358 359 rcu_read_unlock(); 360 361 len = sizeof(*kp) * c; 362 ret = 0; 363 if ((len && copy_to_user(a + 1, kp, len)) || put_user(len, &a->datalen)) 364 ret = -EFAULT; 365 366 kfree(kp); 367 out: 368 return ret; 369 } 370 371 static int 372 ipip6_tunnel_add_prl(struct ip_tunnel *t, struct ip_tunnel_prl *a, int chg) 373 { 374 struct ip_tunnel_prl_entry *p; 375 int err = 0; 376 377 if (a->addr == htonl(INADDR_ANY)) 378 return -EINVAL; 379 380 ASSERT_RTNL(); 381 382 for (p = rtnl_dereference(t->prl); p; p = rtnl_dereference(p->next)) { 383 if (p->addr == a->addr) { 384 if (chg) { 385 p->flags = a->flags; 386 goto out; 387 } 388 err = -EEXIST; 389 goto out; 390 } 391 } 392 393 if (chg) { 394 err = -ENXIO; 395 goto out; 396 } 397 398 p = kzalloc_obj(struct ip_tunnel_prl_entry); 399 if (!p) { 400 err = -ENOBUFS; 401 goto out; 402 } 403 404 p->next = t->prl; 405 p->addr = a->addr; 406 p->flags = a->flags; 407 t->prl_count++; 408 rcu_assign_pointer(t->prl, p); 409 out: 410 return err; 411 } 412 413 static void prl_list_destroy_rcu(struct rcu_head *head) 414 { 415 struct ip_tunnel_prl_entry *p, *n; 416 417 p = container_of(head, struct ip_tunnel_prl_entry, rcu_head); 418 do { 419 n = rcu_dereference_protected(p->next, 1); 420 kfree(p); 421 p = n; 422 } while (p); 423 } 424 425 static int 426 ipip6_tunnel_del_prl(struct ip_tunnel *t, struct ip_tunnel_prl *a) 427 { 428 struct ip_tunnel_prl_entry *x; 429 struct ip_tunnel_prl_entry __rcu **p; 430 int err = 0; 431 432 ASSERT_RTNL(); 433 434 if (a && a->addr != htonl(INADDR_ANY)) { 435 for (p = &t->prl; 436 (x = rtnl_dereference(*p)) != NULL; 437 p = &x->next) { 438 if (x->addr == a->addr) { 439 *p = x->next; 440 kfree_rcu(x, rcu_head); 441 t->prl_count--; 442 goto out; 443 } 444 } 445 err = -ENXIO; 446 } else { 447 x = rtnl_dereference(t->prl); 448 if (x) { 449 t->prl_count = 0; 450 call_rcu(&x->rcu_head, prl_list_destroy_rcu); 451 t->prl = NULL; 452 } 453 } 454 out: 455 return err; 456 } 457 458 static int ipip6_tunnel_prl_ctl(struct net_device *dev, 459 struct ip_tunnel_prl __user *data, int cmd) 460 { 461 struct ip_tunnel *t = netdev_priv(dev); 462 struct ip_tunnel_prl prl; 463 int err; 464 465 if (!ns_capable(t->net->user_ns, CAP_NET_ADMIN)) 466 return -EPERM; 467 if (dev == dev_to_sit_net(dev)->fb_tunnel_dev) 468 return -EINVAL; 469 470 if (copy_from_user(&prl, data, sizeof(prl))) 471 return -EFAULT; 472 473 switch (cmd) { 474 case SIOCDELPRL: 475 err = ipip6_tunnel_del_prl(t, &prl); 476 break; 477 case SIOCADDPRL: 478 case SIOCCHGPRL: 479 err = ipip6_tunnel_add_prl(t, &prl, cmd == SIOCCHGPRL); 480 break; 481 } 482 dst_cache_reset(&t->dst_cache); 483 netdev_state_change(dev); 484 return err; 485 } 486 487 static int 488 isatap_chksrc(struct sk_buff *skb, const struct iphdr *iph, struct ip_tunnel *t) 489 { 490 struct ip_tunnel_prl_entry *p; 491 int ok = 1; 492 493 rcu_read_lock(); 494 p = __ipip6_tunnel_locate_prl(t, iph->saddr); 495 if (p) { 496 if (p->flags & PRL_DEFAULT) 497 skb->ndisc_nodetype = NDISC_NODETYPE_DEFAULT; 498 else 499 skb->ndisc_nodetype = NDISC_NODETYPE_NODEFAULT; 500 } else { 501 const struct in6_addr *addr6 = &ipv6_hdr(skb)->saddr; 502 503 if (ipv6_addr_is_isatap(addr6) && 504 (addr6->s6_addr32[3] == iph->saddr) && 505 ipv6_chk_prefix(addr6, t->dev)) 506 skb->ndisc_nodetype = NDISC_NODETYPE_HOST; 507 else 508 ok = 0; 509 } 510 rcu_read_unlock(); 511 return ok; 512 } 513 514 static void ipip6_tunnel_uninit(struct net_device *dev) 515 { 516 struct ip_tunnel *tunnel = netdev_priv(dev); 517 struct sit_net *sitn = net_generic(tunnel->net, sit_net_id); 518 519 if (dev == sitn->fb_tunnel_dev) { 520 RCU_INIT_POINTER(sitn->tunnels_wc[0], NULL); 521 } else { 522 ipip6_tunnel_unlink(sitn, tunnel); 523 ipip6_tunnel_del_prl(tunnel, NULL); 524 } 525 dst_cache_reset(&tunnel->dst_cache); 526 netdev_put(dev, &tunnel->dev_tracker); 527 } 528 529 static int ipip6_err(struct sk_buff *skb, u32 info) 530 { 531 const struct iphdr *iph = (const struct iphdr *)skb->data; 532 const int type = icmp_hdr(skb)->type; 533 const int code = icmp_hdr(skb)->code; 534 unsigned int data_len = 0; 535 struct ip_tunnel *t; 536 int sifindex; 537 int err; 538 539 switch (type) { 540 default: 541 case ICMP_PARAMETERPROB: 542 return 0; 543 544 case ICMP_DEST_UNREACH: 545 switch (code) { 546 case ICMP_SR_FAILED: 547 /* Impossible event. */ 548 return 0; 549 default: 550 /* All others are translated to HOST_UNREACH. 551 rfc2003 contains "deep thoughts" about NET_UNREACH, 552 I believe they are just ether pollution. --ANK 553 */ 554 break; 555 } 556 break; 557 case ICMP_TIME_EXCEEDED: 558 if (code != ICMP_EXC_TTL) 559 return 0; 560 data_len = icmp_hdr(skb)->un.reserved[1] * 4; /* RFC 4884 4.1 */ 561 break; 562 case ICMP_REDIRECT: 563 break; 564 } 565 566 err = -ENOENT; 567 568 sifindex = netif_is_l3_master(skb->dev) ? IPCB(skb)->iif : 0; 569 t = ipip6_tunnel_lookup(dev_net(skb->dev), skb->dev, 570 iph->daddr, iph->saddr, sifindex); 571 if (!t) 572 goto out; 573 574 if (type == ICMP_DEST_UNREACH && code == ICMP_FRAG_NEEDED) { 575 ipv4_update_pmtu(skb, dev_net(skb->dev), info, 576 t->parms.link, iph->protocol); 577 err = 0; 578 goto out; 579 } 580 if (type == ICMP_REDIRECT) { 581 ipv4_redirect(skb, dev_net(skb->dev), t->parms.link, 582 iph->protocol); 583 err = 0; 584 goto out; 585 } 586 587 err = 0; 588 if (__in6_dev_get(skb->dev) && 589 !ip6_err_gen_icmpv6_unreach(skb, iph->ihl * 4, type, data_len)) 590 goto out; 591 592 if (t->parms.iph.daddr == 0) 593 goto out; 594 595 if (t->parms.iph.ttl == 0 && type == ICMP_TIME_EXCEEDED) 596 goto out; 597 598 if (time_before(jiffies, t->err_time + IPTUNNEL_ERR_TIMEO)) 599 t->err_count++; 600 else 601 t->err_count = 1; 602 t->err_time = jiffies; 603 out: 604 return err; 605 } 606 607 static inline bool is_spoofed_6rd(struct ip_tunnel *tunnel, const __be32 v4addr, 608 const struct in6_addr *v6addr) 609 { 610 __be32 v4embed = 0; 611 if (check_6rd(tunnel, v6addr, &v4embed) && v4addr != v4embed) 612 return true; 613 return false; 614 } 615 616 /* Checks if an address matches an address on the tunnel interface. 617 * Used to detect the NAT of proto 41 packets and let them pass spoofing test. 618 * Long story: 619 * This function is called after we considered the packet as spoofed 620 * in is_spoofed_6rd. 621 * We may have a router that is doing NAT for proto 41 packets 622 * for an internal station. Destination a.a.a.a/PREFIX:bbbb:bbbb 623 * will be translated to n.n.n.n/PREFIX:bbbb:bbbb. And is_spoofed_6rd 624 * function will return true, dropping the packet. 625 * But, we can still check if is spoofed against the IP 626 * addresses associated with the interface. 627 */ 628 static bool only_dnatted(const struct ip_tunnel *tunnel, 629 const struct in6_addr *v6dst) 630 { 631 int prefix_len; 632 633 #ifdef CONFIG_IPV6_SIT_6RD 634 prefix_len = tunnel->ip6rd.prefixlen + 32 635 - tunnel->ip6rd.relay_prefixlen; 636 #else 637 prefix_len = 48; 638 #endif 639 return ipv6_chk_custom_prefix(v6dst, prefix_len, tunnel->dev); 640 } 641 642 /* Returns true if a packet is spoofed */ 643 static bool packet_is_spoofed(struct sk_buff *skb, 644 const struct iphdr *iph, 645 struct ip_tunnel *tunnel) 646 { 647 const struct ipv6hdr *ipv6h; 648 649 if (tunnel->dev->priv_flags & IFF_ISATAP) { 650 if (!isatap_chksrc(skb, iph, tunnel)) 651 return true; 652 653 return false; 654 } 655 656 if (tunnel->dev->flags & IFF_POINTOPOINT) 657 return false; 658 659 ipv6h = ipv6_hdr(skb); 660 661 if (unlikely(is_spoofed_6rd(tunnel, iph->saddr, &ipv6h->saddr))) { 662 net_warn_ratelimited("Src spoofed %pI4/%pI6c -> %pI4/%pI6c\n", 663 &iph->saddr, &ipv6h->saddr, 664 &iph->daddr, &ipv6h->daddr); 665 return true; 666 } 667 668 if (likely(!is_spoofed_6rd(tunnel, iph->daddr, &ipv6h->daddr))) 669 return false; 670 671 if (only_dnatted(tunnel, &ipv6h->daddr)) 672 return false; 673 674 net_warn_ratelimited("Dst spoofed %pI4/%pI6c -> %pI4/%pI6c\n", 675 &iph->saddr, &ipv6h->saddr, 676 &iph->daddr, &ipv6h->daddr); 677 return true; 678 } 679 680 static int ipip6_rcv(struct sk_buff *skb) 681 { 682 const struct iphdr *iph = ip_hdr(skb); 683 struct ip_tunnel *tunnel; 684 int sifindex; 685 int err; 686 687 sifindex = netif_is_l3_master(skb->dev) ? IPCB(skb)->iif : 0; 688 tunnel = ipip6_tunnel_lookup(dev_net(skb->dev), skb->dev, 689 iph->saddr, iph->daddr, sifindex); 690 if (tunnel) { 691 if (tunnel->parms.iph.protocol != IPPROTO_IPV6 && 692 tunnel->parms.iph.protocol != 0) 693 goto out; 694 695 skb->mac_header = skb->network_header; 696 skb_reset_network_header(skb); 697 IPCB(skb)->flags = 0; 698 skb->dev = tunnel->dev; 699 700 if (packet_is_spoofed(skb, iph, tunnel)) { 701 DEV_STATS_INC(tunnel->dev, rx_errors); 702 goto out; 703 } 704 705 if (iptunnel_pull_header(skb, 0, htons(ETH_P_IPV6), 706 !net_eq(tunnel->net, dev_net(tunnel->dev)))) 707 goto out; 708 709 /* skb can be uncloned in iptunnel_pull_header, so 710 * old iph is no longer valid 711 */ 712 iph = (const struct iphdr *)skb_mac_header(skb); 713 skb_reset_mac_header(skb); 714 715 err = IP_ECN_decapsulate(iph, skb); 716 if (unlikely(err)) { 717 if (log_ecn_error) 718 net_info_ratelimited("non-ECT from %pI4 with TOS=%#x\n", 719 &iph->saddr, iph->tos); 720 if (err > 1) { 721 DEV_STATS_INC(tunnel->dev, rx_frame_errors); 722 DEV_STATS_INC(tunnel->dev, rx_errors); 723 goto out; 724 } 725 } 726 727 dev_sw_netstats_rx_add(tunnel->dev, skb->len); 728 729 netif_rx(skb); 730 731 return 0; 732 } 733 734 /* no tunnel matched, let upstream know, ipsec may handle it */ 735 return 1; 736 out: 737 kfree_skb(skb); 738 return 0; 739 } 740 741 static const struct tnl_ptk_info ipip_tpi = { 742 /* no tunnel info required for ipip. */ 743 .proto = htons(ETH_P_IP), 744 }; 745 746 #if IS_ENABLED(CONFIG_MPLS) 747 static const struct tnl_ptk_info mplsip_tpi = { 748 /* no tunnel info required for mplsip. */ 749 .proto = htons(ETH_P_MPLS_UC), 750 }; 751 #endif 752 753 static int sit_tunnel_rcv(struct sk_buff *skb, u8 ipproto) 754 { 755 const struct iphdr *iph; 756 struct ip_tunnel *tunnel; 757 int sifindex; 758 759 sifindex = netif_is_l3_master(skb->dev) ? IPCB(skb)->iif : 0; 760 761 iph = ip_hdr(skb); 762 tunnel = ipip6_tunnel_lookup(dev_net(skb->dev), skb->dev, 763 iph->saddr, iph->daddr, sifindex); 764 if (tunnel) { 765 const struct tnl_ptk_info *tpi; 766 767 if (tunnel->parms.iph.protocol != ipproto && 768 tunnel->parms.iph.protocol != 0) 769 goto drop; 770 771 if (!xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb)) 772 goto drop; 773 #if IS_ENABLED(CONFIG_MPLS) 774 if (ipproto == IPPROTO_MPLS) 775 tpi = &mplsip_tpi; 776 else 777 #endif 778 tpi = &ipip_tpi; 779 if (iptunnel_pull_header(skb, 0, tpi->proto, false)) 780 goto drop; 781 skb_reset_mac_header(skb); 782 783 return ip_tunnel_rcv(tunnel, skb, tpi, NULL, log_ecn_error); 784 } 785 786 return 1; 787 788 drop: 789 kfree_skb(skb); 790 return 0; 791 } 792 793 static int ipip_rcv(struct sk_buff *skb) 794 { 795 return sit_tunnel_rcv(skb, IPPROTO_IPIP); 796 } 797 798 #if IS_ENABLED(CONFIG_MPLS) 799 static int mplsip_rcv(struct sk_buff *skb) 800 { 801 return sit_tunnel_rcv(skb, IPPROTO_MPLS); 802 } 803 #endif 804 805 /* 806 * If the IPv6 address comes from 6rd / 6to4 (RFC 3056) addr space this function 807 * stores the embedded IPv4 address in v4dst and returns true. 808 */ 809 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst, 810 __be32 *v4dst) 811 { 812 #ifdef CONFIG_IPV6_SIT_6RD 813 if (ipv6_prefix_equal(v6dst, &tunnel->ip6rd.prefix, 814 tunnel->ip6rd.prefixlen)) { 815 unsigned int pbw0, pbi0; 816 int pbi1; 817 u32 d; 818 819 pbw0 = tunnel->ip6rd.prefixlen >> 5; 820 pbi0 = tunnel->ip6rd.prefixlen & 0x1f; 821 822 d = tunnel->ip6rd.relay_prefixlen < 32 ? 823 (ntohl(v6dst->s6_addr32[pbw0]) << pbi0) >> 824 tunnel->ip6rd.relay_prefixlen : 0; 825 826 pbi1 = pbi0 - tunnel->ip6rd.relay_prefixlen; 827 if (pbi1 > 0) 828 d |= ntohl(v6dst->s6_addr32[pbw0 + 1]) >> 829 (32 - pbi1); 830 831 *v4dst = tunnel->ip6rd.relay_prefix | htonl(d); 832 return true; 833 } 834 #else 835 if (v6dst->s6_addr16[0] == htons(0x2002)) { 836 /* 6to4 v6 addr has 16 bits prefix, 32 v4addr, 16 SLA, ... */ 837 memcpy(v4dst, &v6dst->s6_addr16[1], 4); 838 return true; 839 } 840 #endif 841 return false; 842 } 843 844 static inline __be32 try_6rd(struct ip_tunnel *tunnel, 845 const struct in6_addr *v6dst) 846 { 847 __be32 dst = 0; 848 check_6rd(tunnel, v6dst, &dst); 849 return dst; 850 } 851 852 static bool ipip6_tunnel_dst_find(struct sk_buff *skb, __be32 *dst, 853 bool is_isatap) 854 { 855 const struct ipv6hdr *iph6 = ipv6_hdr(skb); 856 struct neighbour *neigh = NULL; 857 const struct in6_addr *addr6; 858 bool found = false; 859 int addr_type; 860 861 if (skb_dst(skb)) 862 neigh = dst_neigh_lookup(skb_dst(skb), &iph6->daddr); 863 864 if (!neigh) { 865 net_dbg_ratelimited("nexthop == NULL\n"); 866 return false; 867 } 868 869 addr6 = (const struct in6_addr *)&neigh->primary_key; 870 addr_type = ipv6_addr_type(addr6); 871 872 if (is_isatap) { 873 if ((addr_type & IPV6_ADDR_UNICAST) && 874 ipv6_addr_is_isatap(addr6)) { 875 *dst = addr6->s6_addr32[3]; 876 found = true; 877 } 878 } else { 879 if (addr_type == IPV6_ADDR_ANY) { 880 addr6 = &ipv6_hdr(skb)->daddr; 881 addr_type = ipv6_addr_type(addr6); 882 } 883 884 if ((addr_type & IPV6_ADDR_COMPATv4) != 0) { 885 *dst = addr6->s6_addr32[3]; 886 found = true; 887 } 888 } 889 890 neigh_release(neigh); 891 892 return found; 893 } 894 895 /* 896 * This function assumes it is being called from dev_queue_xmit() 897 * and that skb is filled properly by that function. 898 */ 899 900 static netdev_tx_t ipip6_tunnel_xmit(struct sk_buff *skb, 901 struct net_device *dev) 902 { 903 struct ip_tunnel *tunnel = netdev_priv(dev); 904 const struct iphdr *tiph = &tunnel->parms.iph; 905 const struct ipv6hdr *iph6 = ipv6_hdr(skb); 906 u8 tos = tunnel->parms.iph.tos; 907 __be16 df = tiph->frag_off; 908 struct rtable *rt; /* Route to the other host */ 909 struct net_device *tdev; /* Device to other host */ 910 unsigned int max_headroom; /* The extra header space needed */ 911 __be32 dst = tiph->daddr; 912 struct flowi4 fl4; 913 int mtu; 914 u8 ttl; 915 u8 protocol = IPPROTO_IPV6; 916 int t_hlen = tunnel->hlen + sizeof(struct iphdr); 917 918 if (tos == 1) 919 tos = ipv6_get_dsfield(iph6); 920 921 /* ISATAP (RFC4214) - must come before 6to4 */ 922 if ((dev->priv_flags & IFF_ISATAP) && 923 !ipip6_tunnel_dst_find(skb, &dst, true)) 924 goto tx_error; 925 926 if (!dst) 927 dst = try_6rd(tunnel, &iph6->daddr); 928 929 if (!dst && !ipip6_tunnel_dst_find(skb, &dst, false)) 930 goto tx_error; 931 932 flowi4_init_output(&fl4, tunnel->parms.link, tunnel->fwmark, 933 tos & INET_DSCP_MASK, RT_SCOPE_UNIVERSE, 934 IPPROTO_IPV6, 0, dst, tiph->saddr, 0, 0, 935 sock_net_uid(tunnel->net, NULL)); 936 937 rt = dst_cache_get_ip4(&tunnel->dst_cache, &fl4.saddr); 938 if (!rt) { 939 rt = ip_route_output_flow(tunnel->net, &fl4, NULL); 940 if (IS_ERR(rt)) { 941 DEV_STATS_INC(dev, tx_carrier_errors); 942 goto tx_error_icmp; 943 } 944 dst_cache_set_ip4(&tunnel->dst_cache, &rt->dst, fl4.saddr); 945 } 946 947 if (rt->rt_type != RTN_UNICAST && rt->rt_type != RTN_LOCAL) { 948 ip_rt_put(rt); 949 DEV_STATS_INC(dev, tx_carrier_errors); 950 goto tx_error_icmp; 951 } 952 tdev = rt->dst.dev; 953 954 if (tdev == dev) { 955 ip_rt_put(rt); 956 DEV_STATS_INC(dev, collisions); 957 goto tx_error; 958 } 959 960 if (iptunnel_handle_offloads(skb, SKB_GSO_IPXIP4)) { 961 ip_rt_put(rt); 962 goto tx_error; 963 } 964 iph6 = ipv6_hdr(skb); 965 966 if (df) { 967 mtu = dst4_mtu(&rt->dst) - t_hlen; 968 969 if (mtu < IPV4_MIN_MTU) { 970 DEV_STATS_INC(dev, collisions); 971 ip_rt_put(rt); 972 goto tx_error; 973 } 974 975 if (mtu < IPV6_MIN_MTU) { 976 mtu = IPV6_MIN_MTU; 977 df = 0; 978 } 979 980 if (tunnel->parms.iph.daddr) 981 skb_dst_update_pmtu_no_confirm(skb, mtu); 982 983 if (skb->len > mtu && !skb_is_gso(skb)) { 984 icmpv6_ndo_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu); 985 ip_rt_put(rt); 986 goto tx_error; 987 } 988 } 989 990 if (tunnel->err_count > 0) { 991 if (time_before(jiffies, 992 tunnel->err_time + IPTUNNEL_ERR_TIMEO)) { 993 tunnel->err_count--; 994 dst_link_failure(skb); 995 } else 996 tunnel->err_count = 0; 997 } 998 999 /* 1000 * Okay, now see if we can stuff it in the buffer as-is. 1001 */ 1002 max_headroom = LL_RESERVED_SPACE(tdev) + t_hlen; 1003 1004 if (skb_headroom(skb) < max_headroom || skb_shared(skb) || 1005 (skb_cloned(skb) && !skb_clone_writable(skb, 0))) { 1006 struct sk_buff *new_skb = skb_realloc_headroom(skb, max_headroom); 1007 if (!new_skb) { 1008 ip_rt_put(rt); 1009 DEV_STATS_INC(dev, tx_dropped); 1010 kfree_skb(skb); 1011 return NETDEV_TX_OK; 1012 } 1013 if (skb->sk) 1014 skb_set_owner_w(new_skb, skb->sk); 1015 dev_kfree_skb(skb); 1016 skb = new_skb; 1017 iph6 = ipv6_hdr(skb); 1018 } 1019 ttl = tiph->ttl; 1020 if (ttl == 0) 1021 ttl = iph6->hop_limit; 1022 tos = INET_ECN_encapsulate(tos, ipv6_get_dsfield(iph6)); 1023 1024 if (ip_tunnel_encap(skb, &tunnel->encap, &protocol, &fl4) < 0) { 1025 ip_rt_put(rt); 1026 goto tx_error; 1027 } 1028 1029 skb_set_inner_ipproto(skb, IPPROTO_IPV6); 1030 1031 iptunnel_xmit(NULL, rt, skb, fl4.saddr, fl4.daddr, protocol, tos, ttl, 1032 df, !net_eq(tunnel->net, dev_net(dev)), 0); 1033 return NETDEV_TX_OK; 1034 1035 tx_error_icmp: 1036 dst_link_failure(skb); 1037 tx_error: 1038 kfree_skb(skb); 1039 DEV_STATS_INC(dev, tx_errors); 1040 return NETDEV_TX_OK; 1041 } 1042 1043 static netdev_tx_t sit_tunnel_xmit__(struct sk_buff *skb, 1044 struct net_device *dev, u8 ipproto) 1045 { 1046 struct ip_tunnel *tunnel = netdev_priv(dev); 1047 const struct iphdr *tiph = &tunnel->parms.iph; 1048 1049 if (iptunnel_handle_offloads(skb, SKB_GSO_IPXIP4)) 1050 goto tx_error; 1051 1052 skb_set_inner_ipproto(skb, ipproto); 1053 1054 ip_tunnel_xmit(skb, dev, tiph, ipproto); 1055 return NETDEV_TX_OK; 1056 tx_error: 1057 kfree_skb(skb); 1058 DEV_STATS_INC(dev, tx_errors); 1059 return NETDEV_TX_OK; 1060 } 1061 1062 static netdev_tx_t sit_tunnel_xmit(struct sk_buff *skb, 1063 struct net_device *dev) 1064 { 1065 if (!pskb_inet_may_pull(skb)) 1066 goto tx_err; 1067 1068 switch (skb->protocol) { 1069 case htons(ETH_P_IP): 1070 sit_tunnel_xmit__(skb, dev, IPPROTO_IPIP); 1071 break; 1072 case htons(ETH_P_IPV6): 1073 ipip6_tunnel_xmit(skb, dev); 1074 break; 1075 #if IS_ENABLED(CONFIG_MPLS) 1076 case htons(ETH_P_MPLS_UC): 1077 sit_tunnel_xmit__(skb, dev, IPPROTO_MPLS); 1078 break; 1079 #endif 1080 default: 1081 goto tx_err; 1082 } 1083 1084 return NETDEV_TX_OK; 1085 1086 tx_err: 1087 DEV_STATS_INC(dev, tx_errors); 1088 kfree_skb(skb); 1089 return NETDEV_TX_OK; 1090 1091 } 1092 1093 static void ipip6_tunnel_bind_dev(struct net_device *dev) 1094 { 1095 struct ip_tunnel *tunnel = netdev_priv(dev); 1096 int t_hlen = tunnel->hlen + sizeof(struct iphdr); 1097 struct net_device *tdev = NULL; 1098 int hlen = LL_MAX_HEADER; 1099 const struct iphdr *iph; 1100 struct flowi4 fl4; 1101 1102 iph = &tunnel->parms.iph; 1103 1104 if (iph->daddr) { 1105 struct rtable *rt = ip_route_output_ports(tunnel->net, &fl4, 1106 NULL, 1107 iph->daddr, iph->saddr, 1108 0, 0, 1109 IPPROTO_IPV6, 1110 iph->tos & INET_DSCP_MASK, 1111 tunnel->parms.link); 1112 1113 if (!IS_ERR(rt)) { 1114 tdev = rt->dst.dev; 1115 ip_rt_put(rt); 1116 } 1117 dev->flags |= IFF_POINTOPOINT; 1118 } 1119 1120 if (!tdev && tunnel->parms.link) 1121 tdev = __dev_get_by_index(tunnel->net, tunnel->parms.link); 1122 1123 if (tdev && !netif_is_l3_master(tdev)) { 1124 int mtu; 1125 1126 mtu = tdev->mtu - t_hlen; 1127 if (mtu < IPV6_MIN_MTU) 1128 mtu = IPV6_MIN_MTU; 1129 WRITE_ONCE(dev->mtu, mtu); 1130 hlen = tdev->hard_header_len + tdev->needed_headroom; 1131 } 1132 dev->needed_headroom = t_hlen + hlen; 1133 } 1134 1135 static void ipip6_tunnel_update(struct ip_tunnel *t, 1136 struct ip_tunnel_parm_kern *p, 1137 __u32 fwmark) 1138 { 1139 struct net *net = t->net; 1140 struct sit_net *sitn = net_generic(net, sit_net_id); 1141 1142 ipip6_tunnel_unlink(sitn, t); 1143 synchronize_net(); 1144 t->parms.iph.saddr = p->iph.saddr; 1145 t->parms.iph.daddr = p->iph.daddr; 1146 __dev_addr_set(t->dev, &p->iph.saddr, 4); 1147 memcpy(t->dev->broadcast, &p->iph.daddr, 4); 1148 ipip6_tunnel_link(sitn, t); 1149 t->parms.iph.ttl = p->iph.ttl; 1150 t->parms.iph.tos = p->iph.tos; 1151 t->parms.iph.frag_off = p->iph.frag_off; 1152 if (t->parms.link != p->link || t->fwmark != fwmark) { 1153 t->parms.link = p->link; 1154 t->fwmark = fwmark; 1155 ipip6_tunnel_bind_dev(t->dev); 1156 } 1157 dst_cache_reset(&t->dst_cache); 1158 netdev_state_change(t->dev); 1159 } 1160 1161 #ifdef CONFIG_IPV6_SIT_6RD 1162 static int ipip6_tunnel_update_6rd(struct ip_tunnel *t, 1163 struct ip_tunnel_6rd *ip6rd) 1164 { 1165 struct in6_addr prefix; 1166 __be32 relay_prefix; 1167 1168 if (ip6rd->relay_prefixlen > 32 || 1169 ip6rd->prefixlen + (32 - ip6rd->relay_prefixlen) > 64) 1170 return -EINVAL; 1171 1172 ipv6_addr_prefix(&prefix, &ip6rd->prefix, ip6rd->prefixlen); 1173 if (!ipv6_addr_equal(&prefix, &ip6rd->prefix)) 1174 return -EINVAL; 1175 if (ip6rd->relay_prefixlen) 1176 relay_prefix = ip6rd->relay_prefix & 1177 htonl(0xffffffffUL << 1178 (32 - ip6rd->relay_prefixlen)); 1179 else 1180 relay_prefix = 0; 1181 if (relay_prefix != ip6rd->relay_prefix) 1182 return -EINVAL; 1183 1184 t->ip6rd.prefix = prefix; 1185 t->ip6rd.relay_prefix = relay_prefix; 1186 t->ip6rd.prefixlen = ip6rd->prefixlen; 1187 t->ip6rd.relay_prefixlen = ip6rd->relay_prefixlen; 1188 dst_cache_reset(&t->dst_cache); 1189 netdev_state_change(t->dev); 1190 return 0; 1191 } 1192 1193 static int 1194 ipip6_tunnel_get6rd(struct net_device *dev, struct ip_tunnel_parm __user *data) 1195 { 1196 struct ip_tunnel *t = netdev_priv(dev); 1197 struct ip_tunnel_parm_kern p; 1198 struct ip_tunnel_6rd ip6rd; 1199 1200 if (dev == dev_to_sit_net(dev)->fb_tunnel_dev) { 1201 if (!ip_tunnel_parm_from_user(&p, data)) 1202 return -EFAULT; 1203 t = ipip6_tunnel_locate(t->net, &p, 0); 1204 } 1205 if (!t) 1206 t = netdev_priv(dev); 1207 1208 ip6rd.prefix = t->ip6rd.prefix; 1209 ip6rd.relay_prefix = t->ip6rd.relay_prefix; 1210 ip6rd.prefixlen = t->ip6rd.prefixlen; 1211 ip6rd.relay_prefixlen = t->ip6rd.relay_prefixlen; 1212 if (copy_to_user(data, &ip6rd, sizeof(ip6rd))) 1213 return -EFAULT; 1214 return 0; 1215 } 1216 1217 static int 1218 ipip6_tunnel_6rdctl(struct net_device *dev, struct ip_tunnel_6rd __user *data, 1219 int cmd) 1220 { 1221 struct ip_tunnel *t = netdev_priv(dev); 1222 struct ip_tunnel_6rd ip6rd; 1223 int err; 1224 1225 if (!ns_capable(t->net->user_ns, CAP_NET_ADMIN)) 1226 return -EPERM; 1227 if (copy_from_user(&ip6rd, data, sizeof(ip6rd))) 1228 return -EFAULT; 1229 1230 if (cmd != SIOCDEL6RD) { 1231 err = ipip6_tunnel_update_6rd(t, &ip6rd); 1232 if (err < 0) 1233 return err; 1234 } else 1235 ipip6_tunnel_clone_6rd(dev, dev_to_sit_net(dev)); 1236 return 0; 1237 } 1238 1239 #endif /* CONFIG_IPV6_SIT_6RD */ 1240 1241 static bool ipip6_valid_ip_proto(u8 ipproto) 1242 { 1243 return ipproto == IPPROTO_IPV6 || 1244 ipproto == IPPROTO_IPIP || 1245 #if IS_ENABLED(CONFIG_MPLS) 1246 ipproto == IPPROTO_MPLS || 1247 #endif 1248 ipproto == 0; 1249 } 1250 1251 static int 1252 __ipip6_tunnel_ioctl_validate(struct net *net, struct ip_tunnel_parm_kern *p) 1253 { 1254 if (!ns_capable(net->user_ns, CAP_NET_ADMIN)) 1255 return -EPERM; 1256 1257 if (!ipip6_valid_ip_proto(p->iph.protocol)) 1258 return -EINVAL; 1259 if (p->iph.version != 4 || 1260 p->iph.ihl != 5 || (p->iph.frag_off & htons(~IP_DF))) 1261 return -EINVAL; 1262 1263 if (p->iph.ttl) 1264 p->iph.frag_off |= htons(IP_DF); 1265 return 0; 1266 } 1267 1268 static int 1269 ipip6_tunnel_get(struct net_device *dev, struct ip_tunnel_parm_kern *p) 1270 { 1271 struct ip_tunnel *t = netdev_priv(dev); 1272 1273 if (dev == dev_to_sit_net(dev)->fb_tunnel_dev) 1274 t = ipip6_tunnel_locate(t->net, p, 0); 1275 if (!t) 1276 t = netdev_priv(dev); 1277 memcpy(p, &t->parms, sizeof(*p)); 1278 return 0; 1279 } 1280 1281 static int 1282 ipip6_tunnel_add(struct net_device *dev, struct ip_tunnel_parm_kern *p) 1283 { 1284 struct ip_tunnel *t = netdev_priv(dev); 1285 int err; 1286 1287 err = __ipip6_tunnel_ioctl_validate(t->net, p); 1288 if (err) 1289 return err; 1290 1291 t = ipip6_tunnel_locate(t->net, p, 1); 1292 if (!t) 1293 return -ENOBUFS; 1294 return 0; 1295 } 1296 1297 static int 1298 ipip6_tunnel_change(struct net_device *dev, struct ip_tunnel_parm_kern *p) 1299 { 1300 struct ip_tunnel *t = netdev_priv(dev); 1301 int err; 1302 1303 err = __ipip6_tunnel_ioctl_validate(t->net, p); 1304 if (err) 1305 return err; 1306 1307 t = ipip6_tunnel_locate(t->net, p, 0); 1308 if (dev == dev_to_sit_net(dev)->fb_tunnel_dev) { 1309 if (!t) 1310 return -ENOENT; 1311 } else { 1312 if (t) { 1313 if (t->dev != dev) 1314 return -EEXIST; 1315 } else { 1316 if (((dev->flags & IFF_POINTOPOINT) && !p->iph.daddr) || 1317 (!(dev->flags & IFF_POINTOPOINT) && p->iph.daddr)) 1318 return -EINVAL; 1319 t = netdev_priv(dev); 1320 } 1321 1322 ipip6_tunnel_update(t, p, t->fwmark); 1323 } 1324 1325 return 0; 1326 } 1327 1328 static int 1329 ipip6_tunnel_del(struct net_device *dev, struct ip_tunnel_parm_kern *p) 1330 { 1331 struct ip_tunnel *t = netdev_priv(dev); 1332 1333 if (!ns_capable(t->net->user_ns, CAP_NET_ADMIN)) 1334 return -EPERM; 1335 1336 if (dev == dev_to_sit_net(dev)->fb_tunnel_dev) { 1337 t = ipip6_tunnel_locate(t->net, p, 0); 1338 if (!t) 1339 return -ENOENT; 1340 if (t == netdev_priv(dev_to_sit_net(dev)->fb_tunnel_dev)) 1341 return -EPERM; 1342 dev = t->dev; 1343 } 1344 unregister_netdevice(dev); 1345 return 0; 1346 } 1347 1348 static int 1349 ipip6_tunnel_ctl(struct net_device *dev, struct ip_tunnel_parm_kern *p, 1350 int cmd) 1351 { 1352 switch (cmd) { 1353 case SIOCGETTUNNEL: 1354 return ipip6_tunnel_get(dev, p); 1355 case SIOCADDTUNNEL: 1356 return ipip6_tunnel_add(dev, p); 1357 case SIOCCHGTUNNEL: 1358 return ipip6_tunnel_change(dev, p); 1359 case SIOCDELTUNNEL: 1360 return ipip6_tunnel_del(dev, p); 1361 default: 1362 return -EINVAL; 1363 } 1364 } 1365 1366 static int 1367 ipip6_tunnel_siocdevprivate(struct net_device *dev, struct ifreq *ifr, 1368 void __user *data, int cmd) 1369 { 1370 switch (cmd) { 1371 case SIOCGETTUNNEL: 1372 case SIOCADDTUNNEL: 1373 case SIOCCHGTUNNEL: 1374 case SIOCDELTUNNEL: 1375 return ip_tunnel_siocdevprivate(dev, ifr, data, cmd); 1376 case SIOCGETPRL: 1377 return ipip6_tunnel_get_prl(dev, data); 1378 case SIOCADDPRL: 1379 case SIOCDELPRL: 1380 case SIOCCHGPRL: 1381 return ipip6_tunnel_prl_ctl(dev, data, cmd); 1382 #ifdef CONFIG_IPV6_SIT_6RD 1383 case SIOCGET6RD: 1384 return ipip6_tunnel_get6rd(dev, data); 1385 case SIOCADD6RD: 1386 case SIOCCHG6RD: 1387 case SIOCDEL6RD: 1388 return ipip6_tunnel_6rdctl(dev, data, cmd); 1389 #endif 1390 default: 1391 return -EINVAL; 1392 } 1393 } 1394 1395 static const struct net_device_ops ipip6_netdev_ops = { 1396 .ndo_init = ipip6_tunnel_init, 1397 .ndo_uninit = ipip6_tunnel_uninit, 1398 .ndo_start_xmit = sit_tunnel_xmit, 1399 .ndo_siocdevprivate = ipip6_tunnel_siocdevprivate, 1400 .ndo_get_iflink = ip_tunnel_get_iflink, 1401 .ndo_tunnel_ctl = ipip6_tunnel_ctl, 1402 }; 1403 1404 static void ipip6_dev_free(struct net_device *dev) 1405 { 1406 struct ip_tunnel *tunnel = netdev_priv(dev); 1407 1408 dst_cache_destroy(&tunnel->dst_cache); 1409 } 1410 1411 #define SIT_FEATURES (NETIF_F_SG | \ 1412 NETIF_F_FRAGLIST | \ 1413 NETIF_F_HIGHDMA | \ 1414 NETIF_F_GSO_SOFTWARE | \ 1415 NETIF_F_HW_CSUM) 1416 1417 static void ipip6_tunnel_setup(struct net_device *dev) 1418 { 1419 struct ip_tunnel *tunnel = netdev_priv(dev); 1420 int t_hlen = tunnel->hlen + sizeof(struct iphdr); 1421 1422 dev->netdev_ops = &ipip6_netdev_ops; 1423 dev->header_ops = &ip_tunnel_header_ops; 1424 dev->needs_free_netdev = true; 1425 dev->priv_destructor = ipip6_dev_free; 1426 1427 dev->type = ARPHRD_SIT; 1428 dev->mtu = ETH_DATA_LEN - t_hlen; 1429 dev->min_mtu = IPV6_MIN_MTU; 1430 dev->max_mtu = IP6_MAX_MTU - t_hlen; 1431 dev->flags = IFF_NOARP; 1432 netif_keep_dst(dev); 1433 dev->addr_len = 4; 1434 dev->lltx = true; 1435 dev->features |= SIT_FEATURES; 1436 dev->hw_features |= SIT_FEATURES; 1437 dev->pcpu_stat_type = NETDEV_PCPU_STAT_TSTATS; 1438 1439 } 1440 1441 static int ipip6_tunnel_init(struct net_device *dev) 1442 { 1443 struct ip_tunnel *tunnel = netdev_priv(dev); 1444 int err; 1445 1446 tunnel->dev = dev; 1447 strscpy(tunnel->parms.name, dev->name); 1448 1449 ipip6_tunnel_bind_dev(dev); 1450 1451 err = dst_cache_init(&tunnel->dst_cache, GFP_KERNEL); 1452 if (err) 1453 return err; 1454 1455 netdev_hold(dev, &tunnel->dev_tracker, GFP_KERNEL); 1456 netdev_lockdep_set_classes(dev); 1457 return 0; 1458 } 1459 1460 static void __net_init ipip6_fb_tunnel_init(struct net_device *dev) 1461 { 1462 struct ip_tunnel *tunnel = netdev_priv(dev); 1463 struct iphdr *iph = &tunnel->parms.iph; 1464 struct net *net = dev_net(dev); 1465 struct sit_net *sitn = net_generic(net, sit_net_id); 1466 1467 iph->version = 4; 1468 iph->protocol = IPPROTO_IPV6; 1469 iph->ihl = 5; 1470 iph->ttl = 64; 1471 1472 rcu_assign_pointer(sitn->tunnels_wc[0], tunnel); 1473 } 1474 1475 static int ipip6_validate(struct nlattr *tb[], struct nlattr *data[], 1476 struct netlink_ext_ack *extack) 1477 { 1478 u8 proto; 1479 1480 if (!data || !data[IFLA_IPTUN_PROTO]) 1481 return 0; 1482 1483 proto = nla_get_u8(data[IFLA_IPTUN_PROTO]); 1484 if (!ipip6_valid_ip_proto(proto)) 1485 return -EINVAL; 1486 1487 return 0; 1488 } 1489 1490 static void ipip6_netlink_parms(struct nlattr *data[], 1491 struct ip_tunnel_parm_kern *parms, 1492 __u32 *fwmark) 1493 { 1494 memset(parms, 0, sizeof(*parms)); 1495 1496 parms->iph.version = 4; 1497 parms->iph.protocol = IPPROTO_IPV6; 1498 parms->iph.ihl = 5; 1499 parms->iph.ttl = 64; 1500 1501 if (!data) 1502 return; 1503 1504 ip_tunnel_netlink_parms(data, parms); 1505 1506 if (data[IFLA_IPTUN_FWMARK]) 1507 *fwmark = nla_get_u32(data[IFLA_IPTUN_FWMARK]); 1508 } 1509 1510 #ifdef CONFIG_IPV6_SIT_6RD 1511 /* This function returns true when 6RD attributes are present in the nl msg */ 1512 static bool ipip6_netlink_6rd_parms(struct nlattr *data[], 1513 struct ip_tunnel_6rd *ip6rd) 1514 { 1515 bool ret = false; 1516 memset(ip6rd, 0, sizeof(*ip6rd)); 1517 1518 if (!data) 1519 return ret; 1520 1521 if (data[IFLA_IPTUN_6RD_PREFIX]) { 1522 ret = true; 1523 ip6rd->prefix = nla_get_in6_addr(data[IFLA_IPTUN_6RD_PREFIX]); 1524 } 1525 1526 if (data[IFLA_IPTUN_6RD_RELAY_PREFIX]) { 1527 ret = true; 1528 ip6rd->relay_prefix = 1529 nla_get_be32(data[IFLA_IPTUN_6RD_RELAY_PREFIX]); 1530 } 1531 1532 if (data[IFLA_IPTUN_6RD_PREFIXLEN]) { 1533 ret = true; 1534 ip6rd->prefixlen = nla_get_u16(data[IFLA_IPTUN_6RD_PREFIXLEN]); 1535 } 1536 1537 if (data[IFLA_IPTUN_6RD_RELAY_PREFIXLEN]) { 1538 ret = true; 1539 ip6rd->relay_prefixlen = 1540 nla_get_u16(data[IFLA_IPTUN_6RD_RELAY_PREFIXLEN]); 1541 } 1542 1543 return ret; 1544 } 1545 #endif 1546 1547 static int ipip6_newlink(struct net_device *dev, 1548 struct rtnl_newlink_params *params, 1549 struct netlink_ext_ack *extack) 1550 { 1551 struct nlattr **data = params->data; 1552 struct nlattr **tb = params->tb; 1553 struct ip_tunnel *nt; 1554 struct ip_tunnel_encap ipencap; 1555 #ifdef CONFIG_IPV6_SIT_6RD 1556 struct ip_tunnel_6rd ip6rd; 1557 #endif 1558 struct net *net; 1559 int err; 1560 1561 net = params->link_net ? : dev_net(dev); 1562 nt = netdev_priv(dev); 1563 nt->net = net; 1564 1565 if (ip_tunnel_netlink_encap_parms(data, &ipencap)) { 1566 err = ip_tunnel_encap_setup(nt, &ipencap); 1567 if (err < 0) 1568 return err; 1569 } 1570 1571 ipip6_netlink_parms(data, &nt->parms, &nt->fwmark); 1572 1573 if (ipip6_tunnel_locate(net, &nt->parms, 0)) 1574 return -EEXIST; 1575 1576 err = ipip6_tunnel_create(dev); 1577 if (err < 0) 1578 return err; 1579 1580 if (tb[IFLA_MTU]) { 1581 u32 mtu = nla_get_u32(tb[IFLA_MTU]); 1582 1583 if (mtu >= IPV6_MIN_MTU && 1584 mtu <= IP6_MAX_MTU - dev->hard_header_len) 1585 dev->mtu = mtu; 1586 } 1587 1588 #ifdef CONFIG_IPV6_SIT_6RD 1589 if (ipip6_netlink_6rd_parms(data, &ip6rd)) { 1590 err = ipip6_tunnel_update_6rd(nt, &ip6rd); 1591 if (err < 0) 1592 unregister_netdevice_queue(dev, NULL); 1593 } 1594 #endif 1595 1596 return err; 1597 } 1598 1599 static int ipip6_changelink(struct net_device *dev, struct nlattr *tb[], 1600 struct nlattr *data[], 1601 struct netlink_ext_ack *extack) 1602 { 1603 struct ip_tunnel *t = netdev_priv(dev); 1604 struct ip_tunnel_encap ipencap; 1605 struct ip_tunnel_parm_kern p; 1606 struct net *net = t->net; 1607 struct sit_net *sitn = net_generic(net, sit_net_id); 1608 #ifdef CONFIG_IPV6_SIT_6RD 1609 struct ip_tunnel_6rd ip6rd; 1610 #endif 1611 __u32 fwmark = t->fwmark; 1612 int err; 1613 1614 if (dev == sitn->fb_tunnel_dev) 1615 return -EINVAL; 1616 1617 if (ip_tunnel_netlink_encap_parms(data, &ipencap)) { 1618 err = ip_tunnel_encap_setup(t, &ipencap); 1619 if (err < 0) 1620 return err; 1621 } 1622 1623 ipip6_netlink_parms(data, &p, &fwmark); 1624 1625 if (((dev->flags & IFF_POINTOPOINT) && !p.iph.daddr) || 1626 (!(dev->flags & IFF_POINTOPOINT) && p.iph.daddr)) 1627 return -EINVAL; 1628 1629 t = ipip6_tunnel_locate(net, &p, 0); 1630 1631 if (t) { 1632 if (t->dev != dev) 1633 return -EEXIST; 1634 } else 1635 t = netdev_priv(dev); 1636 1637 ipip6_tunnel_update(t, &p, fwmark); 1638 1639 #ifdef CONFIG_IPV6_SIT_6RD 1640 if (ipip6_netlink_6rd_parms(data, &ip6rd)) 1641 return ipip6_tunnel_update_6rd(t, &ip6rd); 1642 #endif 1643 1644 return 0; 1645 } 1646 1647 static size_t ipip6_get_size(const struct net_device *dev) 1648 { 1649 return 1650 /* IFLA_IPTUN_LINK */ 1651 nla_total_size(4) + 1652 /* IFLA_IPTUN_LOCAL */ 1653 nla_total_size(4) + 1654 /* IFLA_IPTUN_REMOTE */ 1655 nla_total_size(4) + 1656 /* IFLA_IPTUN_TTL */ 1657 nla_total_size(1) + 1658 /* IFLA_IPTUN_TOS */ 1659 nla_total_size(1) + 1660 /* IFLA_IPTUN_PMTUDISC */ 1661 nla_total_size(1) + 1662 /* IFLA_IPTUN_FLAGS */ 1663 nla_total_size(2) + 1664 /* IFLA_IPTUN_PROTO */ 1665 nla_total_size(1) + 1666 #ifdef CONFIG_IPV6_SIT_6RD 1667 /* IFLA_IPTUN_6RD_PREFIX */ 1668 nla_total_size(sizeof(struct in6_addr)) + 1669 /* IFLA_IPTUN_6RD_RELAY_PREFIX */ 1670 nla_total_size(4) + 1671 /* IFLA_IPTUN_6RD_PREFIXLEN */ 1672 nla_total_size(2) + 1673 /* IFLA_IPTUN_6RD_RELAY_PREFIXLEN */ 1674 nla_total_size(2) + 1675 #endif 1676 /* IFLA_IPTUN_ENCAP_TYPE */ 1677 nla_total_size(2) + 1678 /* IFLA_IPTUN_ENCAP_FLAGS */ 1679 nla_total_size(2) + 1680 /* IFLA_IPTUN_ENCAP_SPORT */ 1681 nla_total_size(2) + 1682 /* IFLA_IPTUN_ENCAP_DPORT */ 1683 nla_total_size(2) + 1684 /* IFLA_IPTUN_FWMARK */ 1685 nla_total_size(4) + 1686 0; 1687 } 1688 1689 static int ipip6_fill_info(struct sk_buff *skb, const struct net_device *dev) 1690 { 1691 struct ip_tunnel *tunnel = netdev_priv(dev); 1692 struct ip_tunnel_parm_kern *parm = &tunnel->parms; 1693 1694 if (nla_put_u32(skb, IFLA_IPTUN_LINK, parm->link) || 1695 nla_put_in_addr(skb, IFLA_IPTUN_LOCAL, parm->iph.saddr) || 1696 nla_put_in_addr(skb, IFLA_IPTUN_REMOTE, parm->iph.daddr) || 1697 nla_put_u8(skb, IFLA_IPTUN_TTL, parm->iph.ttl) || 1698 nla_put_u8(skb, IFLA_IPTUN_TOS, parm->iph.tos) || 1699 nla_put_u8(skb, IFLA_IPTUN_PMTUDISC, 1700 !!(parm->iph.frag_off & htons(IP_DF))) || 1701 nla_put_u8(skb, IFLA_IPTUN_PROTO, parm->iph.protocol) || 1702 nla_put_be16(skb, IFLA_IPTUN_FLAGS, 1703 ip_tunnel_flags_to_be16(parm->i_flags)) || 1704 nla_put_u32(skb, IFLA_IPTUN_FWMARK, tunnel->fwmark)) 1705 goto nla_put_failure; 1706 1707 #ifdef CONFIG_IPV6_SIT_6RD 1708 if (nla_put_in6_addr(skb, IFLA_IPTUN_6RD_PREFIX, 1709 &tunnel->ip6rd.prefix) || 1710 nla_put_in_addr(skb, IFLA_IPTUN_6RD_RELAY_PREFIX, 1711 tunnel->ip6rd.relay_prefix) || 1712 nla_put_u16(skb, IFLA_IPTUN_6RD_PREFIXLEN, 1713 tunnel->ip6rd.prefixlen) || 1714 nla_put_u16(skb, IFLA_IPTUN_6RD_RELAY_PREFIXLEN, 1715 tunnel->ip6rd.relay_prefixlen)) 1716 goto nla_put_failure; 1717 #endif 1718 1719 if (nla_put_u16(skb, IFLA_IPTUN_ENCAP_TYPE, 1720 tunnel->encap.type) || 1721 nla_put_be16(skb, IFLA_IPTUN_ENCAP_SPORT, 1722 tunnel->encap.sport) || 1723 nla_put_be16(skb, IFLA_IPTUN_ENCAP_DPORT, 1724 tunnel->encap.dport) || 1725 nla_put_u16(skb, IFLA_IPTUN_ENCAP_FLAGS, 1726 tunnel->encap.flags)) 1727 goto nla_put_failure; 1728 1729 return 0; 1730 1731 nla_put_failure: 1732 return -EMSGSIZE; 1733 } 1734 1735 static const struct nla_policy ipip6_policy[IFLA_IPTUN_MAX + 1] = { 1736 [IFLA_IPTUN_LINK] = { .type = NLA_U32 }, 1737 [IFLA_IPTUN_LOCAL] = { .type = NLA_U32 }, 1738 [IFLA_IPTUN_REMOTE] = { .type = NLA_U32 }, 1739 [IFLA_IPTUN_TTL] = { .type = NLA_U8 }, 1740 [IFLA_IPTUN_TOS] = { .type = NLA_U8 }, 1741 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 }, 1742 [IFLA_IPTUN_FLAGS] = { .type = NLA_U16 }, 1743 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 }, 1744 #ifdef CONFIG_IPV6_SIT_6RD 1745 [IFLA_IPTUN_6RD_PREFIX] = { .len = sizeof(struct in6_addr) }, 1746 [IFLA_IPTUN_6RD_RELAY_PREFIX] = { .type = NLA_U32 }, 1747 [IFLA_IPTUN_6RD_PREFIXLEN] = { .type = NLA_U16 }, 1748 [IFLA_IPTUN_6RD_RELAY_PREFIXLEN] = { .type = NLA_U16 }, 1749 #endif 1750 [IFLA_IPTUN_ENCAP_TYPE] = { .type = NLA_U16 }, 1751 [IFLA_IPTUN_ENCAP_FLAGS] = { .type = NLA_U16 }, 1752 [IFLA_IPTUN_ENCAP_SPORT] = { .type = NLA_U16 }, 1753 [IFLA_IPTUN_ENCAP_DPORT] = { .type = NLA_U16 }, 1754 [IFLA_IPTUN_FWMARK] = { .type = NLA_U32 }, 1755 }; 1756 1757 static void ipip6_dellink(struct net_device *dev, struct list_head *head) 1758 { 1759 struct net *net = dev_net(dev); 1760 struct sit_net *sitn = net_generic(net, sit_net_id); 1761 1762 if (dev != sitn->fb_tunnel_dev) 1763 unregister_netdevice_queue(dev, head); 1764 } 1765 1766 static struct rtnl_link_ops sit_link_ops __read_mostly = { 1767 .kind = "sit", 1768 .maxtype = IFLA_IPTUN_MAX, 1769 .policy = ipip6_policy, 1770 .priv_size = sizeof(struct ip_tunnel), 1771 .setup = ipip6_tunnel_setup, 1772 .validate = ipip6_validate, 1773 .newlink = ipip6_newlink, 1774 .changelink = ipip6_changelink, 1775 .get_size = ipip6_get_size, 1776 .fill_info = ipip6_fill_info, 1777 .dellink = ipip6_dellink, 1778 .get_link_net = ip_tunnel_get_link_net, 1779 }; 1780 1781 static struct xfrm_tunnel sit_handler __read_mostly = { 1782 .handler = ipip6_rcv, 1783 .err_handler = ipip6_err, 1784 .priority = 1, 1785 }; 1786 1787 static struct xfrm_tunnel ipip_handler __read_mostly = { 1788 .handler = ipip_rcv, 1789 .err_handler = ipip6_err, 1790 .priority = 2, 1791 }; 1792 1793 #if IS_ENABLED(CONFIG_MPLS) 1794 static struct xfrm_tunnel mplsip_handler __read_mostly = { 1795 .handler = mplsip_rcv, 1796 .err_handler = ipip6_err, 1797 .priority = 2, 1798 }; 1799 #endif 1800 1801 static void __net_exit sit_exit_rtnl_net(struct net *net, struct list_head *head) 1802 { 1803 struct sit_net *sitn = net_generic(net, sit_net_id); 1804 struct net_device *dev, *aux; 1805 int prio; 1806 1807 for_each_netdev_safe(net, dev, aux) 1808 if (dev->rtnl_link_ops == &sit_link_ops) 1809 unregister_netdevice_queue(dev, head); 1810 1811 for (prio = 0; prio < 4; prio++) { 1812 int h; 1813 for (h = 0; h < (prio ? IP6_SIT_HASH_SIZE : 1); h++) { 1814 struct ip_tunnel *t; 1815 1816 t = rtnl_net_dereference(net, sitn->tunnels[prio][h]); 1817 while (t) { 1818 /* If dev is in the same netns, it has already 1819 * been added to the list by the previous loop. 1820 */ 1821 if (!net_eq(dev_net(t->dev), net)) 1822 unregister_netdevice_queue(t->dev, head); 1823 1824 t = rtnl_net_dereference(net, t->next); 1825 } 1826 } 1827 } 1828 } 1829 1830 static int __net_init sit_init_net(struct net *net) 1831 { 1832 struct sit_net *sitn = net_generic(net, sit_net_id); 1833 struct ip_tunnel *t; 1834 int err; 1835 1836 sitn->tunnels[0] = sitn->tunnels_wc; 1837 sitn->tunnels[1] = sitn->tunnels_l; 1838 sitn->tunnels[2] = sitn->tunnels_r; 1839 sitn->tunnels[3] = sitn->tunnels_r_l; 1840 1841 if (!net_has_fallback_tunnels(net)) 1842 return 0; 1843 1844 sitn->fb_tunnel_dev = alloc_netdev(sizeof(struct ip_tunnel), "sit0", 1845 NET_NAME_UNKNOWN, 1846 ipip6_tunnel_setup); 1847 if (!sitn->fb_tunnel_dev) { 1848 err = -ENOMEM; 1849 goto err_alloc_dev; 1850 } 1851 dev_net_set(sitn->fb_tunnel_dev, net); 1852 sitn->fb_tunnel_dev->rtnl_link_ops = &sit_link_ops; 1853 /* FB netdevice is special: we have one, and only one per netns. 1854 * Allowing to move it to another netns is clearly unsafe. 1855 */ 1856 sitn->fb_tunnel_dev->netns_immutable = true; 1857 1858 t = netdev_priv(sitn->fb_tunnel_dev); 1859 t->net = net; 1860 1861 err = register_netdev(sitn->fb_tunnel_dev); 1862 if (err) 1863 goto err_reg_dev; 1864 1865 ipip6_tunnel_clone_6rd(sitn->fb_tunnel_dev, sitn); 1866 ipip6_fb_tunnel_init(sitn->fb_tunnel_dev); 1867 1868 strscpy(t->parms.name, sitn->fb_tunnel_dev->name); 1869 return 0; 1870 1871 err_reg_dev: 1872 free_netdev(sitn->fb_tunnel_dev); 1873 err_alloc_dev: 1874 return err; 1875 } 1876 1877 static struct pernet_operations sit_net_ops = { 1878 .init = sit_init_net, 1879 .exit_rtnl = sit_exit_rtnl_net, 1880 .id = &sit_net_id, 1881 .size = sizeof(struct sit_net), 1882 }; 1883 1884 static void __exit sit_cleanup(void) 1885 { 1886 rtnl_link_unregister(&sit_link_ops); 1887 xfrm4_tunnel_deregister(&sit_handler, AF_INET6); 1888 xfrm4_tunnel_deregister(&ipip_handler, AF_INET); 1889 #if IS_ENABLED(CONFIG_MPLS) 1890 xfrm4_tunnel_deregister(&mplsip_handler, AF_MPLS); 1891 #endif 1892 1893 unregister_pernet_device(&sit_net_ops); 1894 rcu_barrier(); /* Wait for completion of call_rcu()'s */ 1895 } 1896 1897 static int __init sit_init(void) 1898 { 1899 int err; 1900 1901 pr_info("IPv6, IPv4 and MPLS over IPv4 tunneling driver\n"); 1902 1903 err = register_pernet_device(&sit_net_ops); 1904 if (err < 0) 1905 return err; 1906 err = xfrm4_tunnel_register(&sit_handler, AF_INET6); 1907 if (err < 0) { 1908 pr_info("%s: can't register ip6ip4\n", __func__); 1909 goto xfrm_tunnel_failed; 1910 } 1911 err = xfrm4_tunnel_register(&ipip_handler, AF_INET); 1912 if (err < 0) { 1913 pr_info("%s: can't register ip4ip4\n", __func__); 1914 goto xfrm_tunnel4_failed; 1915 } 1916 #if IS_ENABLED(CONFIG_MPLS) 1917 err = xfrm4_tunnel_register(&mplsip_handler, AF_MPLS); 1918 if (err < 0) { 1919 pr_info("%s: can't register mplsip\n", __func__); 1920 goto xfrm_tunnel_mpls_failed; 1921 } 1922 #endif 1923 err = rtnl_link_register(&sit_link_ops); 1924 if (err < 0) 1925 goto rtnl_link_failed; 1926 1927 out: 1928 return err; 1929 1930 rtnl_link_failed: 1931 #if IS_ENABLED(CONFIG_MPLS) 1932 xfrm4_tunnel_deregister(&mplsip_handler, AF_MPLS); 1933 xfrm_tunnel_mpls_failed: 1934 #endif 1935 xfrm4_tunnel_deregister(&ipip_handler, AF_INET); 1936 xfrm_tunnel4_failed: 1937 xfrm4_tunnel_deregister(&sit_handler, AF_INET6); 1938 xfrm_tunnel_failed: 1939 unregister_pernet_device(&sit_net_ops); 1940 goto out; 1941 } 1942 1943 module_init(sit_init); 1944 module_exit(sit_cleanup); 1945 MODULE_DESCRIPTION("IPv6-in-IPv4 tunnel SIT driver"); 1946 MODULE_LICENSE("GPL"); 1947 MODULE_ALIAS_RTNL_LINK("sit"); 1948 MODULE_ALIAS_NETDEV("sit0"); 1949