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