sit.c 29 KB

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