sit.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293
  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. dev_hold(dev);
  232. ipip6_tunnel_link(sitn, nt);
  233. return nt;
  234. failed_free:
  235. ipip6_dev_free(dev);
  236. failed:
  237. return NULL;
  238. }
  239. #define for_each_prl_rcu(start) \
  240. for (prl = rcu_dereference(start); \
  241. prl; \
  242. prl = rcu_dereference(prl->next))
  243. static struct ip_tunnel_prl_entry *
  244. __ipip6_tunnel_locate_prl(struct ip_tunnel *t, __be32 addr)
  245. {
  246. struct ip_tunnel_prl_entry *prl;
  247. for_each_prl_rcu(t->prl)
  248. if (prl->addr == addr)
  249. break;
  250. return prl;
  251. }
  252. static int ipip6_tunnel_get_prl(struct ip_tunnel *t,
  253. struct ip_tunnel_prl __user *a)
  254. {
  255. struct ip_tunnel_prl kprl, *kp;
  256. struct ip_tunnel_prl_entry *prl;
  257. unsigned int cmax, c = 0, ca, len;
  258. int ret = 0;
  259. if (copy_from_user(&kprl, a, sizeof(kprl)))
  260. return -EFAULT;
  261. cmax = kprl.datalen / sizeof(kprl);
  262. if (cmax > 1 && kprl.addr != htonl(INADDR_ANY))
  263. cmax = 1;
  264. /* For simple GET or for root users,
  265. * we try harder to allocate.
  266. */
  267. kp = (cmax <= 1 || capable(CAP_NET_ADMIN)) ?
  268. kcalloc(cmax, sizeof(*kp), GFP_KERNEL) :
  269. NULL;
  270. rcu_read_lock();
  271. ca = t->prl_count < cmax ? t->prl_count : cmax;
  272. if (!kp) {
  273. /* We don't try hard to allocate much memory for
  274. * non-root users.
  275. * For root users, retry allocating enough memory for
  276. * the answer.
  277. */
  278. kp = kcalloc(ca, sizeof(*kp), GFP_ATOMIC);
  279. if (!kp) {
  280. ret = -ENOMEM;
  281. goto out;
  282. }
  283. }
  284. c = 0;
  285. for_each_prl_rcu(t->prl) {
  286. if (c >= cmax)
  287. break;
  288. if (kprl.addr != htonl(INADDR_ANY) && prl->addr != kprl.addr)
  289. continue;
  290. kp[c].addr = prl->addr;
  291. kp[c].flags = prl->flags;
  292. c++;
  293. if (kprl.addr != htonl(INADDR_ANY))
  294. break;
  295. }
  296. out:
  297. rcu_read_unlock();
  298. len = sizeof(*kp) * c;
  299. ret = 0;
  300. if ((len && copy_to_user(a + 1, kp, len)) || put_user(len, &a->datalen))
  301. ret = -EFAULT;
  302. kfree(kp);
  303. return ret;
  304. }
  305. static int
  306. ipip6_tunnel_add_prl(struct ip_tunnel *t, struct ip_tunnel_prl *a, int chg)
  307. {
  308. struct ip_tunnel_prl_entry *p;
  309. int err = 0;
  310. if (a->addr == htonl(INADDR_ANY))
  311. return -EINVAL;
  312. ASSERT_RTNL();
  313. for (p = rtnl_dereference(t->prl); p; p = rtnl_dereference(p->next)) {
  314. if (p->addr == a->addr) {
  315. if (chg) {
  316. p->flags = a->flags;
  317. goto out;
  318. }
  319. err = -EEXIST;
  320. goto out;
  321. }
  322. }
  323. if (chg) {
  324. err = -ENXIO;
  325. goto out;
  326. }
  327. p = kzalloc(sizeof(struct ip_tunnel_prl_entry), GFP_KERNEL);
  328. if (!p) {
  329. err = -ENOBUFS;
  330. goto out;
  331. }
  332. p->next = t->prl;
  333. p->addr = a->addr;
  334. p->flags = a->flags;
  335. t->prl_count++;
  336. rcu_assign_pointer(t->prl, p);
  337. out:
  338. return err;
  339. }
  340. static void prl_entry_destroy_rcu(struct rcu_head *head)
  341. {
  342. kfree(container_of(head, struct ip_tunnel_prl_entry, rcu_head));
  343. }
  344. static void prl_list_destroy_rcu(struct rcu_head *head)
  345. {
  346. struct ip_tunnel_prl_entry *p, *n;
  347. p = container_of(head, struct ip_tunnel_prl_entry, rcu_head);
  348. do {
  349. n = rcu_dereference_protected(p->next, 1);
  350. kfree(p);
  351. p = n;
  352. } while (p);
  353. }
  354. static int
  355. ipip6_tunnel_del_prl(struct ip_tunnel *t, struct ip_tunnel_prl *a)
  356. {
  357. struct ip_tunnel_prl_entry *x;
  358. struct ip_tunnel_prl_entry __rcu **p;
  359. int err = 0;
  360. ASSERT_RTNL();
  361. if (a && a->addr != htonl(INADDR_ANY)) {
  362. for (p = &t->prl;
  363. (x = rtnl_dereference(*p)) != NULL;
  364. p = &x->next) {
  365. if (x->addr == a->addr) {
  366. *p = x->next;
  367. call_rcu(&x->rcu_head, prl_entry_destroy_rcu);
  368. t->prl_count--;
  369. goto out;
  370. }
  371. }
  372. err = -ENXIO;
  373. } else {
  374. x = rtnl_dereference(t->prl);
  375. if (x) {
  376. t->prl_count = 0;
  377. call_rcu(&x->rcu_head, prl_list_destroy_rcu);
  378. t->prl = NULL;
  379. }
  380. }
  381. out:
  382. return err;
  383. }
  384. static int
  385. isatap_chksrc(struct sk_buff *skb, const struct iphdr *iph, struct ip_tunnel *t)
  386. {
  387. struct ip_tunnel_prl_entry *p;
  388. int ok = 1;
  389. rcu_read_lock();
  390. p = __ipip6_tunnel_locate_prl(t, iph->saddr);
  391. if (p) {
  392. if (p->flags & PRL_DEFAULT)
  393. skb->ndisc_nodetype = NDISC_NODETYPE_DEFAULT;
  394. else
  395. skb->ndisc_nodetype = NDISC_NODETYPE_NODEFAULT;
  396. } else {
  397. const struct in6_addr *addr6 = &ipv6_hdr(skb)->saddr;
  398. if (ipv6_addr_is_isatap(addr6) &&
  399. (addr6->s6_addr32[3] == iph->saddr) &&
  400. ipv6_chk_prefix(addr6, t->dev))
  401. skb->ndisc_nodetype = NDISC_NODETYPE_HOST;
  402. else
  403. ok = 0;
  404. }
  405. rcu_read_unlock();
  406. return ok;
  407. }
  408. static void ipip6_tunnel_uninit(struct net_device *dev)
  409. {
  410. struct net *net = dev_net(dev);
  411. struct sit_net *sitn = net_generic(net, sit_net_id);
  412. if (dev == sitn->fb_tunnel_dev) {
  413. rcu_assign_pointer(sitn->tunnels_wc[0], NULL);
  414. } else {
  415. ipip6_tunnel_unlink(sitn, netdev_priv(dev));
  416. ipip6_tunnel_del_prl(netdev_priv(dev), NULL);
  417. }
  418. dev_put(dev);
  419. }
  420. static int ipip6_err(struct sk_buff *skb, u32 info)
  421. {
  422. /* All the routers (except for Linux) return only
  423. 8 bytes of packet payload. It means, that precise relaying of
  424. ICMP in the real Internet is absolutely infeasible.
  425. */
  426. const struct iphdr *iph = (const struct iphdr *)skb->data;
  427. const int type = icmp_hdr(skb)->type;
  428. const int code = icmp_hdr(skb)->code;
  429. struct ip_tunnel *t;
  430. int err;
  431. switch (type) {
  432. default:
  433. case ICMP_PARAMETERPROB:
  434. return 0;
  435. case ICMP_DEST_UNREACH:
  436. switch (code) {
  437. case ICMP_SR_FAILED:
  438. case ICMP_PORT_UNREACH:
  439. /* Impossible event. */
  440. return 0;
  441. case ICMP_FRAG_NEEDED:
  442. /* Soft state for pmtu is maintained by IP core. */
  443. return 0;
  444. default:
  445. /* All others are translated to HOST_UNREACH.
  446. rfc2003 contains "deep thoughts" about NET_UNREACH,
  447. I believe they are just ether pollution. --ANK
  448. */
  449. break;
  450. }
  451. break;
  452. case ICMP_TIME_EXCEEDED:
  453. if (code != ICMP_EXC_TTL)
  454. return 0;
  455. break;
  456. }
  457. err = -ENOENT;
  458. rcu_read_lock();
  459. t = ipip6_tunnel_lookup(dev_net(skb->dev),
  460. skb->dev,
  461. iph->daddr,
  462. iph->saddr);
  463. if (t == NULL || t->parms.iph.daddr == 0)
  464. goto out;
  465. err = 0;
  466. if (t->parms.iph.ttl == 0 && type == ICMP_TIME_EXCEEDED)
  467. goto out;
  468. if (time_before(jiffies, t->err_time + IPTUNNEL_ERR_TIMEO))
  469. t->err_count++;
  470. else
  471. t->err_count = 1;
  472. t->err_time = jiffies;
  473. out:
  474. rcu_read_unlock();
  475. return err;
  476. }
  477. static inline void ipip6_ecn_decapsulate(const struct iphdr *iph, struct sk_buff *skb)
  478. {
  479. if (INET_ECN_is_ce(iph->tos))
  480. IP6_ECN_set_ce(ipv6_hdr(skb));
  481. }
  482. static int ipip6_rcv(struct sk_buff *skb)
  483. {
  484. const struct iphdr *iph;
  485. struct ip_tunnel *tunnel;
  486. if (!pskb_may_pull(skb, sizeof(struct ipv6hdr)))
  487. goto out;
  488. iph = ip_hdr(skb);
  489. rcu_read_lock();
  490. tunnel = ipip6_tunnel_lookup(dev_net(skb->dev), skb->dev,
  491. iph->saddr, iph->daddr);
  492. if (tunnel != NULL) {
  493. struct pcpu_tstats *tstats;
  494. secpath_reset(skb);
  495. skb->mac_header = skb->network_header;
  496. skb_reset_network_header(skb);
  497. IPCB(skb)->flags = 0;
  498. skb->protocol = htons(ETH_P_IPV6);
  499. skb->pkt_type = PACKET_HOST;
  500. if ((tunnel->dev->priv_flags & IFF_ISATAP) &&
  501. !isatap_chksrc(skb, iph, tunnel)) {
  502. tunnel->dev->stats.rx_errors++;
  503. rcu_read_unlock();
  504. kfree_skb(skb);
  505. return 0;
  506. }
  507. tstats = this_cpu_ptr(tunnel->dev->tstats);
  508. tstats->rx_packets++;
  509. tstats->rx_bytes += skb->len;
  510. __skb_tunnel_rx(skb, tunnel->dev);
  511. ipip6_ecn_decapsulate(iph, skb);
  512. netif_rx(skb);
  513. rcu_read_unlock();
  514. return 0;
  515. }
  516. /* no tunnel matched, let upstream know, ipsec may handle it */
  517. rcu_read_unlock();
  518. return 1;
  519. out:
  520. kfree_skb(skb);
  521. return 0;
  522. }
  523. /*
  524. * Returns the embedded IPv4 address if the IPv6 address
  525. * comes from 6rd / 6to4 (RFC 3056) addr space.
  526. */
  527. static inline
  528. __be32 try_6rd(const struct in6_addr *v6dst, struct ip_tunnel *tunnel)
  529. {
  530. __be32 dst = 0;
  531. #ifdef CONFIG_IPV6_SIT_6RD
  532. if (ipv6_prefix_equal(v6dst, &tunnel->ip6rd.prefix,
  533. tunnel->ip6rd.prefixlen)) {
  534. unsigned int pbw0, pbi0;
  535. int pbi1;
  536. u32 d;
  537. pbw0 = tunnel->ip6rd.prefixlen >> 5;
  538. pbi0 = tunnel->ip6rd.prefixlen & 0x1f;
  539. d = (ntohl(v6dst->s6_addr32[pbw0]) << pbi0) >>
  540. tunnel->ip6rd.relay_prefixlen;
  541. pbi1 = pbi0 - tunnel->ip6rd.relay_prefixlen;
  542. if (pbi1 > 0)
  543. d |= ntohl(v6dst->s6_addr32[pbw0 + 1]) >>
  544. (32 - pbi1);
  545. dst = tunnel->ip6rd.relay_prefix | htonl(d);
  546. }
  547. #else
  548. if (v6dst->s6_addr16[0] == htons(0x2002)) {
  549. /* 6to4 v6 addr has 16 bits prefix, 32 v4addr, 16 SLA, ... */
  550. memcpy(&dst, &v6dst->s6_addr16[1], 4);
  551. }
  552. #endif
  553. return dst;
  554. }
  555. /*
  556. * This function assumes it is being called from dev_queue_xmit()
  557. * and that skb is filled properly by that function.
  558. */
  559. static netdev_tx_t ipip6_tunnel_xmit(struct sk_buff *skb,
  560. struct net_device *dev)
  561. {
  562. struct ip_tunnel *tunnel = netdev_priv(dev);
  563. struct pcpu_tstats *tstats;
  564. const struct iphdr *tiph = &tunnel->parms.iph;
  565. const struct ipv6hdr *iph6 = ipv6_hdr(skb);
  566. u8 tos = tunnel->parms.iph.tos;
  567. __be16 df = tiph->frag_off;
  568. struct rtable *rt; /* Route to the other host */
  569. struct net_device *tdev; /* Device to other host */
  570. struct iphdr *iph; /* Our new IP header */
  571. unsigned int max_headroom; /* The extra header space needed */
  572. __be32 dst = tiph->daddr;
  573. struct flowi4 fl4;
  574. int mtu;
  575. const struct in6_addr *addr6;
  576. int addr_type;
  577. if (skb->protocol != htons(ETH_P_IPV6))
  578. goto tx_error;
  579. /* ISATAP (RFC4214) - must come before 6to4 */
  580. if (dev->priv_flags & IFF_ISATAP) {
  581. struct neighbour *neigh = NULL;
  582. if (skb_dst(skb))
  583. neigh = skb_dst(skb)->neighbour;
  584. if (neigh == NULL) {
  585. if (net_ratelimit())
  586. printk(KERN_DEBUG "sit: nexthop == NULL\n");
  587. goto tx_error;
  588. }
  589. addr6 = (const struct in6_addr*)&neigh->primary_key;
  590. addr_type = ipv6_addr_type(addr6);
  591. if ((addr_type & IPV6_ADDR_UNICAST) &&
  592. ipv6_addr_is_isatap(addr6))
  593. dst = addr6->s6_addr32[3];
  594. else
  595. goto tx_error;
  596. }
  597. if (!dst)
  598. dst = try_6rd(&iph6->daddr, tunnel);
  599. if (!dst) {
  600. struct neighbour *neigh = NULL;
  601. if (skb_dst(skb))
  602. neigh = skb_dst(skb)->neighbour;
  603. if (neigh == NULL) {
  604. if (net_ratelimit())
  605. printk(KERN_DEBUG "sit: nexthop == NULL\n");
  606. goto tx_error;
  607. }
  608. addr6 = (const struct in6_addr*)&neigh->primary_key;
  609. addr_type = ipv6_addr_type(addr6);
  610. if (addr_type == IPV6_ADDR_ANY) {
  611. addr6 = &ipv6_hdr(skb)->daddr;
  612. addr_type = ipv6_addr_type(addr6);
  613. }
  614. if ((addr_type & IPV6_ADDR_COMPATv4) == 0)
  615. goto tx_error_icmp;
  616. dst = addr6->s6_addr32[3];
  617. }
  618. rt = ip_route_output_ports(dev_net(dev), &fl4, NULL,
  619. dst, tiph->saddr,
  620. 0, 0,
  621. IPPROTO_IPV6, RT_TOS(tos),
  622. tunnel->parms.link);
  623. if (IS_ERR(rt)) {
  624. dev->stats.tx_carrier_errors++;
  625. goto tx_error_icmp;
  626. }
  627. if (rt->rt_type != RTN_UNICAST) {
  628. ip_rt_put(rt);
  629. dev->stats.tx_carrier_errors++;
  630. goto tx_error_icmp;
  631. }
  632. tdev = rt->dst.dev;
  633. if (tdev == dev) {
  634. ip_rt_put(rt);
  635. dev->stats.collisions++;
  636. goto tx_error;
  637. }
  638. if (df) {
  639. mtu = dst_mtu(&rt->dst) - sizeof(struct iphdr);
  640. if (mtu < 68) {
  641. dev->stats.collisions++;
  642. ip_rt_put(rt);
  643. goto tx_error;
  644. }
  645. if (mtu < IPV6_MIN_MTU) {
  646. mtu = IPV6_MIN_MTU;
  647. df = 0;
  648. }
  649. if (tunnel->parms.iph.daddr && skb_dst(skb))
  650. skb_dst(skb)->ops->update_pmtu(skb_dst(skb), mtu);
  651. if (skb->len > mtu) {
  652. icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu);
  653. ip_rt_put(rt);
  654. goto tx_error;
  655. }
  656. }
  657. if (tunnel->err_count > 0) {
  658. if (time_before(jiffies,
  659. tunnel->err_time + IPTUNNEL_ERR_TIMEO)) {
  660. tunnel->err_count--;
  661. dst_link_failure(skb);
  662. } else
  663. tunnel->err_count = 0;
  664. }
  665. /*
  666. * Okay, now see if we can stuff it in the buffer as-is.
  667. */
  668. max_headroom = LL_RESERVED_SPACE(tdev)+sizeof(struct iphdr);
  669. if (skb_headroom(skb) < max_headroom || skb_shared(skb) ||
  670. (skb_cloned(skb) && !skb_clone_writable(skb, 0))) {
  671. struct sk_buff *new_skb = skb_realloc_headroom(skb, max_headroom);
  672. if (!new_skb) {
  673. ip_rt_put(rt);
  674. dev->stats.tx_dropped++;
  675. dev_kfree_skb(skb);
  676. return NETDEV_TX_OK;
  677. }
  678. if (skb->sk)
  679. skb_set_owner_w(new_skb, skb->sk);
  680. dev_kfree_skb(skb);
  681. skb = new_skb;
  682. iph6 = ipv6_hdr(skb);
  683. }
  684. skb->transport_header = skb->network_header;
  685. skb_push(skb, sizeof(struct iphdr));
  686. skb_reset_network_header(skb);
  687. memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt));
  688. IPCB(skb)->flags = 0;
  689. skb_dst_drop(skb);
  690. skb_dst_set(skb, &rt->dst);
  691. /*
  692. * Push down and install the IPIP header.
  693. */
  694. iph = ip_hdr(skb);
  695. iph->version = 4;
  696. iph->ihl = sizeof(struct iphdr)>>2;
  697. iph->frag_off = df;
  698. iph->protocol = IPPROTO_IPV6;
  699. iph->tos = INET_ECN_encapsulate(tos, ipv6_get_dsfield(iph6));
  700. iph->daddr = fl4.daddr;
  701. iph->saddr = fl4.saddr;
  702. if ((iph->ttl = tiph->ttl) == 0)
  703. iph->ttl = iph6->hop_limit;
  704. nf_reset(skb);
  705. tstats = this_cpu_ptr(dev->tstats);
  706. __IPTUNNEL_XMIT(tstats, &dev->stats);
  707. return NETDEV_TX_OK;
  708. tx_error_icmp:
  709. dst_link_failure(skb);
  710. tx_error:
  711. dev->stats.tx_errors++;
  712. dev_kfree_skb(skb);
  713. return NETDEV_TX_OK;
  714. }
  715. static void ipip6_tunnel_bind_dev(struct net_device *dev)
  716. {
  717. struct net_device *tdev = NULL;
  718. struct ip_tunnel *tunnel;
  719. const struct iphdr *iph;
  720. struct flowi4 fl4;
  721. tunnel = netdev_priv(dev);
  722. iph = &tunnel->parms.iph;
  723. if (iph->daddr) {
  724. struct rtable *rt = ip_route_output_ports(dev_net(dev), &fl4, NULL,
  725. iph->daddr, iph->saddr,
  726. 0, 0,
  727. IPPROTO_IPV6,
  728. RT_TOS(iph->tos),
  729. tunnel->parms.link);
  730. if (!IS_ERR(rt)) {
  731. tdev = rt->dst.dev;
  732. ip_rt_put(rt);
  733. }
  734. dev->flags |= IFF_POINTOPOINT;
  735. }
  736. if (!tdev && tunnel->parms.link)
  737. tdev = __dev_get_by_index(dev_net(dev), tunnel->parms.link);
  738. if (tdev) {
  739. dev->hard_header_len = tdev->hard_header_len + sizeof(struct iphdr);
  740. dev->mtu = tdev->mtu - sizeof(struct iphdr);
  741. if (dev->mtu < IPV6_MIN_MTU)
  742. dev->mtu = IPV6_MIN_MTU;
  743. }
  744. dev->iflink = tunnel->parms.link;
  745. }
  746. static int
  747. ipip6_tunnel_ioctl (struct net_device *dev, struct ifreq *ifr, int cmd)
  748. {
  749. int err = 0;
  750. struct ip_tunnel_parm p;
  751. struct ip_tunnel_prl prl;
  752. struct ip_tunnel *t;
  753. struct net *net = dev_net(dev);
  754. struct sit_net *sitn = net_generic(net, sit_net_id);
  755. #ifdef CONFIG_IPV6_SIT_6RD
  756. struct ip_tunnel_6rd ip6rd;
  757. #endif
  758. switch (cmd) {
  759. case SIOCGETTUNNEL:
  760. #ifdef CONFIG_IPV6_SIT_6RD
  761. case SIOCGET6RD:
  762. #endif
  763. t = NULL;
  764. if (dev == sitn->fb_tunnel_dev) {
  765. if (copy_from_user(&p, ifr->ifr_ifru.ifru_data, sizeof(p))) {
  766. err = -EFAULT;
  767. break;
  768. }
  769. t = ipip6_tunnel_locate(net, &p, 0);
  770. }
  771. if (t == NULL)
  772. t = netdev_priv(dev);
  773. err = -EFAULT;
  774. if (cmd == SIOCGETTUNNEL) {
  775. memcpy(&p, &t->parms, sizeof(p));
  776. if (copy_to_user(ifr->ifr_ifru.ifru_data, &p,
  777. sizeof(p)))
  778. goto done;
  779. #ifdef CONFIG_IPV6_SIT_6RD
  780. } else {
  781. ipv6_addr_copy(&ip6rd.prefix, &t->ip6rd.prefix);
  782. ip6rd.relay_prefix = t->ip6rd.relay_prefix;
  783. ip6rd.prefixlen = t->ip6rd.prefixlen;
  784. ip6rd.relay_prefixlen = t->ip6rd.relay_prefixlen;
  785. if (copy_to_user(ifr->ifr_ifru.ifru_data, &ip6rd,
  786. sizeof(ip6rd)))
  787. goto done;
  788. #endif
  789. }
  790. err = 0;
  791. break;
  792. case SIOCADDTUNNEL:
  793. case SIOCCHGTUNNEL:
  794. err = -EPERM;
  795. if (!capable(CAP_NET_ADMIN))
  796. goto done;
  797. err = -EFAULT;
  798. if (copy_from_user(&p, ifr->ifr_ifru.ifru_data, sizeof(p)))
  799. goto done;
  800. err = -EINVAL;
  801. if (p.iph.version != 4 || p.iph.protocol != IPPROTO_IPV6 ||
  802. p.iph.ihl != 5 || (p.iph.frag_off&htons(~IP_DF)))
  803. goto done;
  804. if (p.iph.ttl)
  805. p.iph.frag_off |= htons(IP_DF);
  806. t = ipip6_tunnel_locate(net, &p, cmd == SIOCADDTUNNEL);
  807. if (dev != sitn->fb_tunnel_dev && cmd == SIOCCHGTUNNEL) {
  808. if (t != NULL) {
  809. if (t->dev != dev) {
  810. err = -EEXIST;
  811. break;
  812. }
  813. } else {
  814. if (((dev->flags&IFF_POINTOPOINT) && !p.iph.daddr) ||
  815. (!(dev->flags&IFF_POINTOPOINT) && p.iph.daddr)) {
  816. err = -EINVAL;
  817. break;
  818. }
  819. t = netdev_priv(dev);
  820. ipip6_tunnel_unlink(sitn, t);
  821. synchronize_net();
  822. t->parms.iph.saddr = p.iph.saddr;
  823. t->parms.iph.daddr = p.iph.daddr;
  824. memcpy(dev->dev_addr, &p.iph.saddr, 4);
  825. memcpy(dev->broadcast, &p.iph.daddr, 4);
  826. ipip6_tunnel_link(sitn, t);
  827. netdev_state_change(dev);
  828. }
  829. }
  830. if (t) {
  831. err = 0;
  832. if (cmd == SIOCCHGTUNNEL) {
  833. t->parms.iph.ttl = p.iph.ttl;
  834. t->parms.iph.tos = p.iph.tos;
  835. if (t->parms.link != p.link) {
  836. t->parms.link = p.link;
  837. ipip6_tunnel_bind_dev(dev);
  838. netdev_state_change(dev);
  839. }
  840. }
  841. if (copy_to_user(ifr->ifr_ifru.ifru_data, &t->parms, sizeof(p)))
  842. err = -EFAULT;
  843. } else
  844. err = (cmd == SIOCADDTUNNEL ? -ENOBUFS : -ENOENT);
  845. break;
  846. case SIOCDELTUNNEL:
  847. err = -EPERM;
  848. if (!capable(CAP_NET_ADMIN))
  849. goto done;
  850. if (dev == sitn->fb_tunnel_dev) {
  851. err = -EFAULT;
  852. if (copy_from_user(&p, ifr->ifr_ifru.ifru_data, sizeof(p)))
  853. goto done;
  854. err = -ENOENT;
  855. if ((t = ipip6_tunnel_locate(net, &p, 0)) == NULL)
  856. goto done;
  857. err = -EPERM;
  858. if (t == netdev_priv(sitn->fb_tunnel_dev))
  859. goto done;
  860. dev = t->dev;
  861. }
  862. unregister_netdevice(dev);
  863. err = 0;
  864. break;
  865. case SIOCGETPRL:
  866. err = -EINVAL;
  867. if (dev == sitn->fb_tunnel_dev)
  868. goto done;
  869. err = -ENOENT;
  870. if (!(t = netdev_priv(dev)))
  871. goto done;
  872. err = ipip6_tunnel_get_prl(t, ifr->ifr_ifru.ifru_data);
  873. break;
  874. case SIOCADDPRL:
  875. case SIOCDELPRL:
  876. case SIOCCHGPRL:
  877. err = -EPERM;
  878. if (!capable(CAP_NET_ADMIN))
  879. goto done;
  880. err = -EINVAL;
  881. if (dev == sitn->fb_tunnel_dev)
  882. goto done;
  883. err = -EFAULT;
  884. if (copy_from_user(&prl, ifr->ifr_ifru.ifru_data, sizeof(prl)))
  885. goto done;
  886. err = -ENOENT;
  887. if (!(t = netdev_priv(dev)))
  888. goto done;
  889. switch (cmd) {
  890. case SIOCDELPRL:
  891. err = ipip6_tunnel_del_prl(t, &prl);
  892. break;
  893. case SIOCADDPRL:
  894. case SIOCCHGPRL:
  895. err = ipip6_tunnel_add_prl(t, &prl, cmd == SIOCCHGPRL);
  896. break;
  897. }
  898. netdev_state_change(dev);
  899. break;
  900. #ifdef CONFIG_IPV6_SIT_6RD
  901. case SIOCADD6RD:
  902. case SIOCCHG6RD:
  903. case SIOCDEL6RD:
  904. err = -EPERM;
  905. if (!capable(CAP_NET_ADMIN))
  906. goto done;
  907. err = -EFAULT;
  908. if (copy_from_user(&ip6rd, ifr->ifr_ifru.ifru_data,
  909. sizeof(ip6rd)))
  910. goto done;
  911. t = netdev_priv(dev);
  912. if (cmd != SIOCDEL6RD) {
  913. struct in6_addr prefix;
  914. __be32 relay_prefix;
  915. err = -EINVAL;
  916. if (ip6rd.relay_prefixlen > 32 ||
  917. ip6rd.prefixlen + (32 - ip6rd.relay_prefixlen) > 64)
  918. goto done;
  919. ipv6_addr_prefix(&prefix, &ip6rd.prefix,
  920. ip6rd.prefixlen);
  921. if (!ipv6_addr_equal(&prefix, &ip6rd.prefix))
  922. goto done;
  923. if (ip6rd.relay_prefixlen)
  924. relay_prefix = ip6rd.relay_prefix &
  925. htonl(0xffffffffUL <<
  926. (32 - ip6rd.relay_prefixlen));
  927. else
  928. relay_prefix = 0;
  929. if (relay_prefix != ip6rd.relay_prefix)
  930. goto done;
  931. ipv6_addr_copy(&t->ip6rd.prefix, &prefix);
  932. t->ip6rd.relay_prefix = relay_prefix;
  933. t->ip6rd.prefixlen = ip6rd.prefixlen;
  934. t->ip6rd.relay_prefixlen = ip6rd.relay_prefixlen;
  935. } else
  936. ipip6_tunnel_clone_6rd(dev, sitn);
  937. err = 0;
  938. break;
  939. #endif
  940. default:
  941. err = -EINVAL;
  942. }
  943. done:
  944. return err;
  945. }
  946. static int ipip6_tunnel_change_mtu(struct net_device *dev, int new_mtu)
  947. {
  948. if (new_mtu < IPV6_MIN_MTU || new_mtu > 0xFFF8 - sizeof(struct iphdr))
  949. return -EINVAL;
  950. dev->mtu = new_mtu;
  951. return 0;
  952. }
  953. static const struct net_device_ops ipip6_netdev_ops = {
  954. .ndo_uninit = ipip6_tunnel_uninit,
  955. .ndo_start_xmit = ipip6_tunnel_xmit,
  956. .ndo_do_ioctl = ipip6_tunnel_ioctl,
  957. .ndo_change_mtu = ipip6_tunnel_change_mtu,
  958. .ndo_get_stats = ipip6_get_stats,
  959. };
  960. static void ipip6_dev_free(struct net_device *dev)
  961. {
  962. free_percpu(dev->tstats);
  963. free_netdev(dev);
  964. }
  965. static void ipip6_tunnel_setup(struct net_device *dev)
  966. {
  967. dev->netdev_ops = &ipip6_netdev_ops;
  968. dev->destructor = ipip6_dev_free;
  969. dev->type = ARPHRD_SIT;
  970. dev->hard_header_len = LL_MAX_HEADER + sizeof(struct iphdr);
  971. dev->mtu = ETH_DATA_LEN - sizeof(struct iphdr);
  972. dev->flags = IFF_NOARP;
  973. dev->priv_flags &= ~IFF_XMIT_DST_RELEASE;
  974. dev->iflink = 0;
  975. dev->addr_len = 4;
  976. dev->features |= NETIF_F_NETNS_LOCAL;
  977. dev->features |= NETIF_F_LLTX;
  978. }
  979. static int ipip6_tunnel_init(struct net_device *dev)
  980. {
  981. struct ip_tunnel *tunnel = netdev_priv(dev);
  982. tunnel->dev = dev;
  983. strcpy(tunnel->parms.name, dev->name);
  984. memcpy(dev->dev_addr, &tunnel->parms.iph.saddr, 4);
  985. memcpy(dev->broadcast, &tunnel->parms.iph.daddr, 4);
  986. ipip6_tunnel_bind_dev(dev);
  987. dev->tstats = alloc_percpu(struct pcpu_tstats);
  988. if (!dev->tstats)
  989. return -ENOMEM;
  990. return 0;
  991. }
  992. static int __net_init ipip6_fb_tunnel_init(struct net_device *dev)
  993. {
  994. struct ip_tunnel *tunnel = netdev_priv(dev);
  995. struct iphdr *iph = &tunnel->parms.iph;
  996. struct net *net = dev_net(dev);
  997. struct sit_net *sitn = net_generic(net, sit_net_id);
  998. tunnel->dev = dev;
  999. strcpy(tunnel->parms.name, dev->name);
  1000. iph->version = 4;
  1001. iph->protocol = IPPROTO_IPV6;
  1002. iph->ihl = 5;
  1003. iph->ttl = 64;
  1004. dev->tstats = alloc_percpu(struct pcpu_tstats);
  1005. if (!dev->tstats)
  1006. return -ENOMEM;
  1007. dev_hold(dev);
  1008. rcu_assign_pointer(sitn->tunnels_wc[0], tunnel);
  1009. return 0;
  1010. }
  1011. static struct xfrm_tunnel sit_handler __read_mostly = {
  1012. .handler = ipip6_rcv,
  1013. .err_handler = ipip6_err,
  1014. .priority = 1,
  1015. };
  1016. static void __net_exit sit_destroy_tunnels(struct sit_net *sitn, struct list_head *head)
  1017. {
  1018. int prio;
  1019. for (prio = 1; prio < 4; prio++) {
  1020. int h;
  1021. for (h = 0; h < HASH_SIZE; h++) {
  1022. struct ip_tunnel *t;
  1023. t = rtnl_dereference(sitn->tunnels[prio][h]);
  1024. while (t != NULL) {
  1025. unregister_netdevice_queue(t->dev, head);
  1026. t = rtnl_dereference(t->next);
  1027. }
  1028. }
  1029. }
  1030. }
  1031. static int __net_init sit_init_net(struct net *net)
  1032. {
  1033. struct sit_net *sitn = net_generic(net, sit_net_id);
  1034. int err;
  1035. sitn->tunnels[0] = sitn->tunnels_wc;
  1036. sitn->tunnels[1] = sitn->tunnels_l;
  1037. sitn->tunnels[2] = sitn->tunnels_r;
  1038. sitn->tunnels[3] = sitn->tunnels_r_l;
  1039. sitn->fb_tunnel_dev = alloc_netdev(sizeof(struct ip_tunnel), "sit0",
  1040. ipip6_tunnel_setup);
  1041. if (!sitn->fb_tunnel_dev) {
  1042. err = -ENOMEM;
  1043. goto err_alloc_dev;
  1044. }
  1045. dev_net_set(sitn->fb_tunnel_dev, net);
  1046. err = ipip6_fb_tunnel_init(sitn->fb_tunnel_dev);
  1047. if (err)
  1048. goto err_dev_free;
  1049. ipip6_tunnel_clone_6rd(sitn->fb_tunnel_dev, sitn);
  1050. if ((err = register_netdev(sitn->fb_tunnel_dev)))
  1051. goto err_reg_dev;
  1052. return 0;
  1053. err_reg_dev:
  1054. dev_put(sitn->fb_tunnel_dev);
  1055. err_dev_free:
  1056. ipip6_dev_free(sitn->fb_tunnel_dev);
  1057. err_alloc_dev:
  1058. return err;
  1059. }
  1060. static void __net_exit sit_exit_net(struct net *net)
  1061. {
  1062. struct sit_net *sitn = net_generic(net, sit_net_id);
  1063. LIST_HEAD(list);
  1064. rtnl_lock();
  1065. sit_destroy_tunnels(sitn, &list);
  1066. unregister_netdevice_queue(sitn->fb_tunnel_dev, &list);
  1067. unregister_netdevice_many(&list);
  1068. rtnl_unlock();
  1069. }
  1070. static struct pernet_operations sit_net_ops = {
  1071. .init = sit_init_net,
  1072. .exit = sit_exit_net,
  1073. .id = &sit_net_id,
  1074. .size = sizeof(struct sit_net),
  1075. };
  1076. static void __exit sit_cleanup(void)
  1077. {
  1078. xfrm4_tunnel_deregister(&sit_handler, AF_INET6);
  1079. unregister_pernet_device(&sit_net_ops);
  1080. rcu_barrier(); /* Wait for completion of call_rcu()'s */
  1081. }
  1082. static int __init sit_init(void)
  1083. {
  1084. int err;
  1085. printk(KERN_INFO "IPv6 over IPv4 tunneling driver\n");
  1086. err = register_pernet_device(&sit_net_ops);
  1087. if (err < 0)
  1088. return err;
  1089. err = xfrm4_tunnel_register(&sit_handler, AF_INET6);
  1090. if (err < 0) {
  1091. unregister_pernet_device(&sit_net_ops);
  1092. printk(KERN_INFO "sit init: Can't add protocol\n");
  1093. }
  1094. return err;
  1095. }
  1096. module_init(sit_init);
  1097. module_exit(sit_cleanup);
  1098. MODULE_LICENSE("GPL");
  1099. MODULE_ALIAS_NETDEV("sit0");