ip6_gre.c 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774
  1. /*
  2. * GRE over IPv6 protocol decoder.
  3. *
  4. * Authors: Dmitry Kozlov (xeb@mail.ru)
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. *
  11. */
  12. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  13. #include <linux/capability.h>
  14. #include <linux/module.h>
  15. #include <linux/types.h>
  16. #include <linux/kernel.h>
  17. #include <linux/slab.h>
  18. #include <linux/uaccess.h>
  19. #include <linux/skbuff.h>
  20. #include <linux/netdevice.h>
  21. #include <linux/in.h>
  22. #include <linux/tcp.h>
  23. #include <linux/udp.h>
  24. #include <linux/if_arp.h>
  25. #include <linux/mroute.h>
  26. #include <linux/init.h>
  27. #include <linux/in6.h>
  28. #include <linux/inetdevice.h>
  29. #include <linux/igmp.h>
  30. #include <linux/netfilter_ipv4.h>
  31. #include <linux/etherdevice.h>
  32. #include <linux/if_ether.h>
  33. #include <linux/hash.h>
  34. #include <linux/if_tunnel.h>
  35. #include <linux/ip6_tunnel.h>
  36. #include <net/sock.h>
  37. #include <net/ip.h>
  38. #include <net/icmp.h>
  39. #include <net/protocol.h>
  40. #include <net/addrconf.h>
  41. #include <net/arp.h>
  42. #include <net/checksum.h>
  43. #include <net/dsfield.h>
  44. #include <net/inet_ecn.h>
  45. #include <net/xfrm.h>
  46. #include <net/net_namespace.h>
  47. #include <net/netns/generic.h>
  48. #include <net/rtnetlink.h>
  49. #include <net/ipv6.h>
  50. #include <net/ip6_fib.h>
  51. #include <net/ip6_route.h>
  52. #include <net/ip6_tunnel.h>
  53. #define IPV6_TCLASS_MASK (IPV6_FLOWINFO_MASK & ~IPV6_FLOWLABEL_MASK)
  54. #define IPV6_TCLASS_SHIFT 20
  55. #define HASH_SIZE_SHIFT 5
  56. #define HASH_SIZE (1 << HASH_SIZE_SHIFT)
  57. static int ip6gre_net_id __read_mostly;
  58. struct ip6gre_net {
  59. struct ip6_tnl __rcu *tunnels[4][HASH_SIZE];
  60. struct net_device *fb_tunnel_dev;
  61. };
  62. static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
  63. static int ip6gre_tunnel_init(struct net_device *dev);
  64. static void ip6gre_tunnel_setup(struct net_device *dev);
  65. static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
  66. static void ip6gre_tnl_link_config(struct ip6_tnl *t, int set_mtu);
  67. /* Tunnel hash table */
  68. /*
  69. 4 hash tables:
  70. 3: (remote,local)
  71. 2: (remote,*)
  72. 1: (*,local)
  73. 0: (*,*)
  74. We require exact key match i.e. if a key is present in packet
  75. it will match only tunnel with the same key; if it is not present,
  76. it will match only keyless tunnel.
  77. All keysless packets, if not matched configured keyless tunnels
  78. will match fallback tunnel.
  79. */
  80. #define HASH_KEY(key) (((__force u32)key^((__force u32)key>>4))&(HASH_SIZE - 1))
  81. static u32 HASH_ADDR(const struct in6_addr *addr)
  82. {
  83. u32 hash = ipv6_addr_hash(addr);
  84. return hash_32(hash, HASH_SIZE_SHIFT);
  85. }
  86. #define tunnels_r_l tunnels[3]
  87. #define tunnels_r tunnels[2]
  88. #define tunnels_l tunnels[1]
  89. #define tunnels_wc tunnels[0]
  90. /*
  91. * Locking : hash tables are protected by RCU and RTNL
  92. */
  93. #define for_each_ip_tunnel_rcu(start) \
  94. for (t = rcu_dereference(start); t; t = rcu_dereference(t->next))
  95. /* often modified stats are per cpu, other are shared (netdev->stats) */
  96. struct pcpu_tstats {
  97. u64 rx_packets;
  98. u64 rx_bytes;
  99. u64 tx_packets;
  100. u64 tx_bytes;
  101. struct u64_stats_sync syncp;
  102. };
  103. static struct rtnl_link_stats64 *ip6gre_get_stats64(struct net_device *dev,
  104. struct rtnl_link_stats64 *tot)
  105. {
  106. int i;
  107. for_each_possible_cpu(i) {
  108. const struct pcpu_tstats *tstats = per_cpu_ptr(dev->tstats, i);
  109. u64 rx_packets, rx_bytes, tx_packets, tx_bytes;
  110. unsigned int start;
  111. do {
  112. start = u64_stats_fetch_begin_bh(&tstats->syncp);
  113. rx_packets = tstats->rx_packets;
  114. tx_packets = tstats->tx_packets;
  115. rx_bytes = tstats->rx_bytes;
  116. tx_bytes = tstats->tx_bytes;
  117. } while (u64_stats_fetch_retry_bh(&tstats->syncp, start));
  118. tot->rx_packets += rx_packets;
  119. tot->tx_packets += tx_packets;
  120. tot->rx_bytes += rx_bytes;
  121. tot->tx_bytes += tx_bytes;
  122. }
  123. tot->multicast = dev->stats.multicast;
  124. tot->rx_crc_errors = dev->stats.rx_crc_errors;
  125. tot->rx_fifo_errors = dev->stats.rx_fifo_errors;
  126. tot->rx_length_errors = dev->stats.rx_length_errors;
  127. tot->rx_errors = dev->stats.rx_errors;
  128. tot->tx_fifo_errors = dev->stats.tx_fifo_errors;
  129. tot->tx_carrier_errors = dev->stats.tx_carrier_errors;
  130. tot->tx_dropped = dev->stats.tx_dropped;
  131. tot->tx_aborted_errors = dev->stats.tx_aborted_errors;
  132. tot->tx_errors = dev->stats.tx_errors;
  133. return tot;
  134. }
  135. /* Given src, dst and key, find appropriate for input tunnel. */
  136. static struct ip6_tnl *ip6gre_tunnel_lookup(struct net_device *dev,
  137. const struct in6_addr *remote, const struct in6_addr *local,
  138. __be32 key, __be16 gre_proto)
  139. {
  140. struct net *net = dev_net(dev);
  141. int link = dev->ifindex;
  142. unsigned int h0 = HASH_ADDR(remote);
  143. unsigned int h1 = HASH_KEY(key);
  144. struct ip6_tnl *t, *cand = NULL;
  145. struct ip6gre_net *ign = net_generic(net, ip6gre_net_id);
  146. int dev_type = (gre_proto == htons(ETH_P_TEB)) ?
  147. ARPHRD_ETHER : ARPHRD_IP6GRE;
  148. int score, cand_score = 4;
  149. for_each_ip_tunnel_rcu(ign->tunnels_r_l[h0 ^ h1]) {
  150. if (!ipv6_addr_equal(local, &t->parms.laddr) ||
  151. !ipv6_addr_equal(remote, &t->parms.raddr) ||
  152. key != t->parms.i_key ||
  153. !(t->dev->flags & IFF_UP))
  154. continue;
  155. if (t->dev->type != ARPHRD_IP6GRE &&
  156. t->dev->type != dev_type)
  157. continue;
  158. score = 0;
  159. if (t->parms.link != link)
  160. score |= 1;
  161. if (t->dev->type != dev_type)
  162. score |= 2;
  163. if (score == 0)
  164. return t;
  165. if (score < cand_score) {
  166. cand = t;
  167. cand_score = score;
  168. }
  169. }
  170. for_each_ip_tunnel_rcu(ign->tunnels_r[h0 ^ h1]) {
  171. if (!ipv6_addr_equal(remote, &t->parms.raddr) ||
  172. key != t->parms.i_key ||
  173. !(t->dev->flags & IFF_UP))
  174. continue;
  175. if (t->dev->type != ARPHRD_IP6GRE &&
  176. t->dev->type != dev_type)
  177. continue;
  178. score = 0;
  179. if (t->parms.link != link)
  180. score |= 1;
  181. if (t->dev->type != dev_type)
  182. score |= 2;
  183. if (score == 0)
  184. return t;
  185. if (score < cand_score) {
  186. cand = t;
  187. cand_score = score;
  188. }
  189. }
  190. for_each_ip_tunnel_rcu(ign->tunnels_l[h1]) {
  191. if ((!ipv6_addr_equal(local, &t->parms.laddr) &&
  192. (!ipv6_addr_equal(local, &t->parms.raddr) ||
  193. !ipv6_addr_is_multicast(local))) ||
  194. key != t->parms.i_key ||
  195. !(t->dev->flags & IFF_UP))
  196. continue;
  197. if (t->dev->type != ARPHRD_IP6GRE &&
  198. t->dev->type != dev_type)
  199. continue;
  200. score = 0;
  201. if (t->parms.link != link)
  202. score |= 1;
  203. if (t->dev->type != dev_type)
  204. score |= 2;
  205. if (score == 0)
  206. return t;
  207. if (score < cand_score) {
  208. cand = t;
  209. cand_score = score;
  210. }
  211. }
  212. for_each_ip_tunnel_rcu(ign->tunnels_wc[h1]) {
  213. if (t->parms.i_key != key ||
  214. !(t->dev->flags & IFF_UP))
  215. continue;
  216. if (t->dev->type != ARPHRD_IP6GRE &&
  217. t->dev->type != dev_type)
  218. continue;
  219. score = 0;
  220. if (t->parms.link != link)
  221. score |= 1;
  222. if (t->dev->type != dev_type)
  223. score |= 2;
  224. if (score == 0)
  225. return t;
  226. if (score < cand_score) {
  227. cand = t;
  228. cand_score = score;
  229. }
  230. }
  231. if (cand != NULL)
  232. return cand;
  233. dev = ign->fb_tunnel_dev;
  234. if (dev->flags & IFF_UP)
  235. return netdev_priv(dev);
  236. return NULL;
  237. }
  238. static struct ip6_tnl __rcu **__ip6gre_bucket(struct ip6gre_net *ign,
  239. const struct __ip6_tnl_parm *p)
  240. {
  241. const struct in6_addr *remote = &p->raddr;
  242. const struct in6_addr *local = &p->laddr;
  243. unsigned int h = HASH_KEY(p->i_key);
  244. int prio = 0;
  245. if (!ipv6_addr_any(local))
  246. prio |= 1;
  247. if (!ipv6_addr_any(remote) && !ipv6_addr_is_multicast(remote)) {
  248. prio |= 2;
  249. h ^= HASH_ADDR(remote);
  250. }
  251. return &ign->tunnels[prio][h];
  252. }
  253. static inline struct ip6_tnl __rcu **ip6gre_bucket(struct ip6gre_net *ign,
  254. const struct ip6_tnl *t)
  255. {
  256. return __ip6gre_bucket(ign, &t->parms);
  257. }
  258. static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t)
  259. {
  260. struct ip6_tnl __rcu **tp = ip6gre_bucket(ign, t);
  261. rcu_assign_pointer(t->next, rtnl_dereference(*tp));
  262. rcu_assign_pointer(*tp, t);
  263. }
  264. static void ip6gre_tunnel_unlink(struct ip6gre_net *ign, struct ip6_tnl *t)
  265. {
  266. struct ip6_tnl __rcu **tp;
  267. struct ip6_tnl *iter;
  268. for (tp = ip6gre_bucket(ign, t);
  269. (iter = rtnl_dereference(*tp)) != NULL;
  270. tp = &iter->next) {
  271. if (t == iter) {
  272. rcu_assign_pointer(*tp, t->next);
  273. break;
  274. }
  275. }
  276. }
  277. static struct ip6_tnl *ip6gre_tunnel_find(struct net *net,
  278. const struct __ip6_tnl_parm *parms,
  279. int type)
  280. {
  281. const struct in6_addr *remote = &parms->raddr;
  282. const struct in6_addr *local = &parms->laddr;
  283. __be32 key = parms->i_key;
  284. int link = parms->link;
  285. struct ip6_tnl *t;
  286. struct ip6_tnl __rcu **tp;
  287. struct ip6gre_net *ign = net_generic(net, ip6gre_net_id);
  288. for (tp = __ip6gre_bucket(ign, parms);
  289. (t = rtnl_dereference(*tp)) != NULL;
  290. tp = &t->next)
  291. if (ipv6_addr_equal(local, &t->parms.laddr) &&
  292. ipv6_addr_equal(remote, &t->parms.raddr) &&
  293. key == t->parms.i_key &&
  294. link == t->parms.link &&
  295. type == t->dev->type)
  296. break;
  297. return t;
  298. }
  299. static struct ip6_tnl *ip6gre_tunnel_locate(struct net *net,
  300. const struct __ip6_tnl_parm *parms, int create)
  301. {
  302. struct ip6_tnl *t, *nt;
  303. struct net_device *dev;
  304. char name[IFNAMSIZ];
  305. struct ip6gre_net *ign = net_generic(net, ip6gre_net_id);
  306. t = ip6gre_tunnel_find(net, parms, ARPHRD_IP6GRE);
  307. if (t || !create)
  308. return t;
  309. if (parms->name[0])
  310. strlcpy(name, parms->name, IFNAMSIZ);
  311. else
  312. strcpy(name, "ip6gre%d");
  313. dev = alloc_netdev(sizeof(*t), name, ip6gre_tunnel_setup);
  314. if (!dev)
  315. return NULL;
  316. dev_net_set(dev, net);
  317. nt = netdev_priv(dev);
  318. nt->parms = *parms;
  319. dev->rtnl_link_ops = &ip6gre_link_ops;
  320. nt->dev = dev;
  321. ip6gre_tnl_link_config(nt, 1);
  322. if (register_netdevice(dev) < 0)
  323. goto failed_free;
  324. /* Can use a lockless transmit, unless we generate output sequences */
  325. if (!(nt->parms.o_flags & GRE_SEQ))
  326. dev->features |= NETIF_F_LLTX;
  327. dev_hold(dev);
  328. ip6gre_tunnel_link(ign, nt);
  329. return nt;
  330. failed_free:
  331. free_netdev(dev);
  332. return NULL;
  333. }
  334. static void ip6gre_tunnel_uninit(struct net_device *dev)
  335. {
  336. struct net *net = dev_net(dev);
  337. struct ip6gre_net *ign = net_generic(net, ip6gre_net_id);
  338. ip6gre_tunnel_unlink(ign, netdev_priv(dev));
  339. dev_put(dev);
  340. }
  341. static void ip6gre_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
  342. u8 type, u8 code, int offset, __be32 info)
  343. {
  344. const struct ipv6hdr *ipv6h = (const struct ipv6hdr *)skb->data;
  345. __be16 *p = (__be16 *)(skb->data + offset);
  346. int grehlen = offset + 4;
  347. struct ip6_tnl *t;
  348. __be16 flags;
  349. flags = p[0];
  350. if (flags&(GRE_CSUM|GRE_KEY|GRE_SEQ|GRE_ROUTING|GRE_VERSION)) {
  351. if (flags&(GRE_VERSION|GRE_ROUTING))
  352. return;
  353. if (flags&GRE_KEY) {
  354. grehlen += 4;
  355. if (flags&GRE_CSUM)
  356. grehlen += 4;
  357. }
  358. }
  359. /* If only 8 bytes returned, keyed message will be dropped here */
  360. if (!pskb_may_pull(skb, grehlen))
  361. return;
  362. ipv6h = (const struct ipv6hdr *)skb->data;
  363. p = (__be16 *)(skb->data + offset);
  364. t = ip6gre_tunnel_lookup(skb->dev, &ipv6h->daddr, &ipv6h->saddr,
  365. flags & GRE_KEY ?
  366. *(((__be32 *)p) + (grehlen / 4) - 1) : 0,
  367. p[1]);
  368. if (t == NULL)
  369. return;
  370. switch (type) {
  371. __u32 teli;
  372. struct ipv6_tlv_tnl_enc_lim *tel;
  373. __u32 mtu;
  374. case ICMPV6_DEST_UNREACH:
  375. net_warn_ratelimited("%s: Path to destination invalid or inactive!\n",
  376. t->parms.name);
  377. break;
  378. case ICMPV6_TIME_EXCEED:
  379. if (code == ICMPV6_EXC_HOPLIMIT) {
  380. net_warn_ratelimited("%s: Too small hop limit or routing loop in tunnel!\n",
  381. t->parms.name);
  382. }
  383. break;
  384. case ICMPV6_PARAMPROB:
  385. teli = 0;
  386. if (code == ICMPV6_HDR_FIELD)
  387. teli = ip6_tnl_parse_tlv_enc_lim(skb, skb->data);
  388. if (teli && teli == info - 2) {
  389. tel = (struct ipv6_tlv_tnl_enc_lim *) &skb->data[teli];
  390. if (tel->encap_limit == 0) {
  391. net_warn_ratelimited("%s: Too small encapsulation limit or routing loop in tunnel!\n",
  392. t->parms.name);
  393. }
  394. } else {
  395. net_warn_ratelimited("%s: Recipient unable to parse tunneled packet!\n",
  396. t->parms.name);
  397. }
  398. break;
  399. case ICMPV6_PKT_TOOBIG:
  400. mtu = info - offset;
  401. if (mtu < IPV6_MIN_MTU)
  402. mtu = IPV6_MIN_MTU;
  403. t->dev->mtu = mtu;
  404. break;
  405. }
  406. if (time_before(jiffies, t->err_time + IP6TUNNEL_ERR_TIMEO))
  407. t->err_count++;
  408. else
  409. t->err_count = 1;
  410. t->err_time = jiffies;
  411. }
  412. static inline void ip6gre_ecn_decapsulate_ipv4(const struct ip6_tnl *t,
  413. const struct ipv6hdr *ipv6h, struct sk_buff *skb)
  414. {
  415. __u8 dsfield = ipv6_get_dsfield(ipv6h) & ~INET_ECN_MASK;
  416. if (t->parms.flags & IP6_TNL_F_RCV_DSCP_COPY)
  417. ipv4_change_dsfield(ip_hdr(skb), INET_ECN_MASK, dsfield);
  418. if (INET_ECN_is_ce(dsfield))
  419. IP_ECN_set_ce(ip_hdr(skb));
  420. }
  421. static inline void ip6gre_ecn_decapsulate_ipv6(const struct ip6_tnl *t,
  422. const struct ipv6hdr *ipv6h, struct sk_buff *skb)
  423. {
  424. if (t->parms.flags & IP6_TNL_F_RCV_DSCP_COPY)
  425. ipv6_copy_dscp(ipv6_get_dsfield(ipv6h), ipv6_hdr(skb));
  426. if (INET_ECN_is_ce(ipv6_get_dsfield(ipv6h)))
  427. IP6_ECN_set_ce(ipv6_hdr(skb));
  428. }
  429. static int ip6gre_rcv(struct sk_buff *skb)
  430. {
  431. const struct ipv6hdr *ipv6h;
  432. u8 *h;
  433. __be16 flags;
  434. __sum16 csum = 0;
  435. __be32 key = 0;
  436. u32 seqno = 0;
  437. struct ip6_tnl *tunnel;
  438. int offset = 4;
  439. __be16 gre_proto;
  440. if (!pskb_may_pull(skb, sizeof(struct in6_addr)))
  441. goto drop;
  442. ipv6h = ipv6_hdr(skb);
  443. h = skb->data;
  444. flags = *(__be16 *)h;
  445. if (flags&(GRE_CSUM|GRE_KEY|GRE_ROUTING|GRE_SEQ|GRE_VERSION)) {
  446. /* - Version must be 0.
  447. - We do not support routing headers.
  448. */
  449. if (flags&(GRE_VERSION|GRE_ROUTING))
  450. goto drop;
  451. if (flags&GRE_CSUM) {
  452. switch (skb->ip_summed) {
  453. case CHECKSUM_COMPLETE:
  454. csum = csum_fold(skb->csum);
  455. if (!csum)
  456. break;
  457. /* fall through */
  458. case CHECKSUM_NONE:
  459. skb->csum = 0;
  460. csum = __skb_checksum_complete(skb);
  461. skb->ip_summed = CHECKSUM_COMPLETE;
  462. }
  463. offset += 4;
  464. }
  465. if (flags&GRE_KEY) {
  466. key = *(__be32 *)(h + offset);
  467. offset += 4;
  468. }
  469. if (flags&GRE_SEQ) {
  470. seqno = ntohl(*(__be32 *)(h + offset));
  471. offset += 4;
  472. }
  473. }
  474. gre_proto = *(__be16 *)(h + 2);
  475. tunnel = ip6gre_tunnel_lookup(skb->dev,
  476. &ipv6h->saddr, &ipv6h->daddr, key,
  477. gre_proto);
  478. if (tunnel) {
  479. struct pcpu_tstats *tstats;
  480. if (!xfrm6_policy_check(NULL, XFRM_POLICY_IN, skb))
  481. goto drop;
  482. if (!ip6_tnl_rcv_ctl(tunnel, &ipv6h->daddr, &ipv6h->saddr)) {
  483. tunnel->dev->stats.rx_dropped++;
  484. goto drop;
  485. }
  486. secpath_reset(skb);
  487. skb->protocol = gre_proto;
  488. /* WCCP version 1 and 2 protocol decoding.
  489. * - Change protocol to IP
  490. * - When dealing with WCCPv2, Skip extra 4 bytes in GRE header
  491. */
  492. if (flags == 0 && gre_proto == htons(ETH_P_WCCP)) {
  493. skb->protocol = htons(ETH_P_IP);
  494. if ((*(h + offset) & 0xF0) != 0x40)
  495. offset += 4;
  496. }
  497. skb->mac_header = skb->network_header;
  498. __pskb_pull(skb, offset);
  499. skb_postpull_rcsum(skb, skb_transport_header(skb), offset);
  500. skb->pkt_type = PACKET_HOST;
  501. if (((flags&GRE_CSUM) && csum) ||
  502. (!(flags&GRE_CSUM) && tunnel->parms.i_flags&GRE_CSUM)) {
  503. tunnel->dev->stats.rx_crc_errors++;
  504. tunnel->dev->stats.rx_errors++;
  505. goto drop;
  506. }
  507. if (tunnel->parms.i_flags&GRE_SEQ) {
  508. if (!(flags&GRE_SEQ) ||
  509. (tunnel->i_seqno &&
  510. (s32)(seqno - tunnel->i_seqno) < 0)) {
  511. tunnel->dev->stats.rx_fifo_errors++;
  512. tunnel->dev->stats.rx_errors++;
  513. goto drop;
  514. }
  515. tunnel->i_seqno = seqno + 1;
  516. }
  517. /* Warning: All skb pointers will be invalidated! */
  518. if (tunnel->dev->type == ARPHRD_ETHER) {
  519. if (!pskb_may_pull(skb, ETH_HLEN)) {
  520. tunnel->dev->stats.rx_length_errors++;
  521. tunnel->dev->stats.rx_errors++;
  522. goto drop;
  523. }
  524. ipv6h = ipv6_hdr(skb);
  525. skb->protocol = eth_type_trans(skb, tunnel->dev);
  526. skb_postpull_rcsum(skb, eth_hdr(skb), ETH_HLEN);
  527. }
  528. tstats = this_cpu_ptr(tunnel->dev->tstats);
  529. u64_stats_update_begin(&tstats->syncp);
  530. tstats->rx_packets++;
  531. tstats->rx_bytes += skb->len;
  532. u64_stats_update_end(&tstats->syncp);
  533. __skb_tunnel_rx(skb, tunnel->dev);
  534. skb_reset_network_header(skb);
  535. if (skb->protocol == htons(ETH_P_IP))
  536. ip6gre_ecn_decapsulate_ipv4(tunnel, ipv6h, skb);
  537. else if (skb->protocol == htons(ETH_P_IPV6))
  538. ip6gre_ecn_decapsulate_ipv6(tunnel, ipv6h, skb);
  539. netif_rx(skb);
  540. return 0;
  541. }
  542. icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
  543. drop:
  544. kfree_skb(skb);
  545. return 0;
  546. }
  547. struct ipv6_tel_txoption {
  548. struct ipv6_txoptions ops;
  549. __u8 dst_opt[8];
  550. };
  551. static void init_tel_txopt(struct ipv6_tel_txoption *opt, __u8 encap_limit)
  552. {
  553. memset(opt, 0, sizeof(struct ipv6_tel_txoption));
  554. opt->dst_opt[2] = IPV6_TLV_TNL_ENCAP_LIMIT;
  555. opt->dst_opt[3] = 1;
  556. opt->dst_opt[4] = encap_limit;
  557. opt->dst_opt[5] = IPV6_TLV_PADN;
  558. opt->dst_opt[6] = 1;
  559. opt->ops.dst0opt = (struct ipv6_opt_hdr *) opt->dst_opt;
  560. opt->ops.opt_nflen = 8;
  561. }
  562. static netdev_tx_t ip6gre_xmit2(struct sk_buff *skb,
  563. struct net_device *dev,
  564. __u8 dsfield,
  565. struct flowi6 *fl6,
  566. int encap_limit,
  567. __u32 *pmtu)
  568. {
  569. struct net *net = dev_net(dev);
  570. struct ip6_tnl *tunnel = netdev_priv(dev);
  571. struct net_device *tdev; /* Device to other host */
  572. struct ipv6hdr *ipv6h; /* Our new IP header */
  573. unsigned int max_headroom; /* The extra header space needed */
  574. int gre_hlen;
  575. struct ipv6_tel_txoption opt;
  576. int mtu;
  577. struct dst_entry *dst = NULL, *ndst = NULL;
  578. struct net_device_stats *stats = &tunnel->dev->stats;
  579. int err = -1;
  580. u8 proto;
  581. int pkt_len;
  582. struct sk_buff *new_skb;
  583. if (dev->type == ARPHRD_ETHER)
  584. IPCB(skb)->flags = 0;
  585. if (dev->header_ops && dev->type == ARPHRD_IP6GRE) {
  586. gre_hlen = 0;
  587. ipv6h = (struct ipv6hdr *)skb->data;
  588. fl6->daddr = ipv6h->daddr;
  589. } else {
  590. gre_hlen = tunnel->hlen;
  591. fl6->daddr = tunnel->parms.raddr;
  592. }
  593. if (!fl6->flowi6_mark)
  594. dst = ip6_tnl_dst_check(tunnel);
  595. if (!dst) {
  596. ndst = ip6_route_output(net, NULL, fl6);
  597. if (ndst->error)
  598. goto tx_err_link_failure;
  599. ndst = xfrm_lookup(net, ndst, flowi6_to_flowi(fl6), NULL, 0);
  600. if (IS_ERR(ndst)) {
  601. err = PTR_ERR(ndst);
  602. ndst = NULL;
  603. goto tx_err_link_failure;
  604. }
  605. dst = ndst;
  606. }
  607. tdev = dst->dev;
  608. if (tdev == dev) {
  609. stats->collisions++;
  610. net_warn_ratelimited("%s: Local routing loop detected!\n",
  611. tunnel->parms.name);
  612. goto tx_err_dst_release;
  613. }
  614. mtu = dst_mtu(dst) - sizeof(*ipv6h);
  615. if (encap_limit >= 0) {
  616. max_headroom += 8;
  617. mtu -= 8;
  618. }
  619. if (mtu < IPV6_MIN_MTU)
  620. mtu = IPV6_MIN_MTU;
  621. if (skb_dst(skb))
  622. skb_dst(skb)->ops->update_pmtu(skb_dst(skb), NULL, skb, mtu);
  623. if (skb->len > mtu) {
  624. *pmtu = mtu;
  625. err = -EMSGSIZE;
  626. goto tx_err_dst_release;
  627. }
  628. if (tunnel->err_count > 0) {
  629. if (time_before(jiffies,
  630. tunnel->err_time + IP6TUNNEL_ERR_TIMEO)) {
  631. tunnel->err_count--;
  632. dst_link_failure(skb);
  633. } else
  634. tunnel->err_count = 0;
  635. }
  636. max_headroom = LL_RESERVED_SPACE(tdev) + gre_hlen + dst->header_len;
  637. if (skb_headroom(skb) < max_headroom || skb_shared(skb) ||
  638. (skb_cloned(skb) && !skb_clone_writable(skb, 0))) {
  639. new_skb = skb_realloc_headroom(skb, max_headroom);
  640. if (max_headroom > dev->needed_headroom)
  641. dev->needed_headroom = max_headroom;
  642. if (!new_skb)
  643. goto tx_err_dst_release;
  644. if (skb->sk)
  645. skb_set_owner_w(new_skb, skb->sk);
  646. consume_skb(skb);
  647. skb = new_skb;
  648. }
  649. skb_dst_drop(skb);
  650. if (fl6->flowi6_mark) {
  651. skb_dst_set(skb, dst);
  652. ndst = NULL;
  653. } else {
  654. skb_dst_set_noref(skb, dst);
  655. }
  656. proto = NEXTHDR_GRE;
  657. if (encap_limit >= 0) {
  658. init_tel_txopt(&opt, encap_limit);
  659. ipv6_push_nfrag_opts(skb, &opt.ops, &proto, NULL);
  660. }
  661. skb_push(skb, gre_hlen);
  662. skb_reset_network_header(skb);
  663. skb_set_transport_header(skb, sizeof(*ipv6h));
  664. /*
  665. * Push down and install the IP header.
  666. */
  667. ipv6h = ipv6_hdr(skb);
  668. ip6_flow_hdr(ipv6h, INET_ECN_encapsulate(0, dsfield), fl6->flowlabel);
  669. ipv6h->hop_limit = tunnel->parms.hop_limit;
  670. ipv6h->nexthdr = proto;
  671. ipv6h->saddr = fl6->saddr;
  672. ipv6h->daddr = fl6->daddr;
  673. ((__be16 *)(ipv6h + 1))[0] = tunnel->parms.o_flags;
  674. ((__be16 *)(ipv6h + 1))[1] = (dev->type == ARPHRD_ETHER) ?
  675. htons(ETH_P_TEB) : skb->protocol;
  676. if (tunnel->parms.o_flags&(GRE_KEY|GRE_CSUM|GRE_SEQ)) {
  677. __be32 *ptr = (__be32 *)(((u8 *)ipv6h) + tunnel->hlen - 4);
  678. if (tunnel->parms.o_flags&GRE_SEQ) {
  679. ++tunnel->o_seqno;
  680. *ptr = htonl(tunnel->o_seqno);
  681. ptr--;
  682. }
  683. if (tunnel->parms.o_flags&GRE_KEY) {
  684. *ptr = tunnel->parms.o_key;
  685. ptr--;
  686. }
  687. if (tunnel->parms.o_flags&GRE_CSUM) {
  688. *ptr = 0;
  689. *(__sum16 *)ptr = ip_compute_csum((void *)(ipv6h+1),
  690. skb->len - sizeof(struct ipv6hdr));
  691. }
  692. }
  693. nf_reset(skb);
  694. pkt_len = skb->len;
  695. err = ip6_local_out(skb);
  696. if (net_xmit_eval(err) == 0) {
  697. struct pcpu_tstats *tstats = this_cpu_ptr(tunnel->dev->tstats);
  698. tstats->tx_bytes += pkt_len;
  699. tstats->tx_packets++;
  700. } else {
  701. stats->tx_errors++;
  702. stats->tx_aborted_errors++;
  703. }
  704. if (ndst)
  705. ip6_tnl_dst_store(tunnel, ndst);
  706. return 0;
  707. tx_err_link_failure:
  708. stats->tx_carrier_errors++;
  709. dst_link_failure(skb);
  710. tx_err_dst_release:
  711. dst_release(ndst);
  712. return err;
  713. }
  714. static inline int ip6gre_xmit_ipv4(struct sk_buff *skb, struct net_device *dev)
  715. {
  716. struct ip6_tnl *t = netdev_priv(dev);
  717. const struct iphdr *iph = ip_hdr(skb);
  718. int encap_limit = -1;
  719. struct flowi6 fl6;
  720. __u8 dsfield;
  721. __u32 mtu;
  722. int err;
  723. if (!(t->parms.flags & IP6_TNL_F_IGN_ENCAP_LIMIT))
  724. encap_limit = t->parms.encap_limit;
  725. memcpy(&fl6, &t->fl.u.ip6, sizeof(fl6));
  726. fl6.flowi6_proto = IPPROTO_IPIP;
  727. dsfield = ipv4_get_dsfield(iph);
  728. if (t->parms.flags & IP6_TNL_F_USE_ORIG_TCLASS)
  729. fl6.flowlabel |= htonl((__u32)iph->tos << IPV6_TCLASS_SHIFT)
  730. & IPV6_TCLASS_MASK;
  731. if (t->parms.flags & IP6_TNL_F_USE_ORIG_FWMARK)
  732. fl6.flowi6_mark = skb->mark;
  733. err = ip6gre_xmit2(skb, dev, dsfield, &fl6, encap_limit, &mtu);
  734. if (err != 0) {
  735. /* XXX: send ICMP error even if DF is not set. */
  736. if (err == -EMSGSIZE)
  737. icmp_send(skb, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED,
  738. htonl(mtu));
  739. return -1;
  740. }
  741. return 0;
  742. }
  743. static inline int ip6gre_xmit_ipv6(struct sk_buff *skb, struct net_device *dev)
  744. {
  745. struct ip6_tnl *t = netdev_priv(dev);
  746. struct ipv6hdr *ipv6h = ipv6_hdr(skb);
  747. int encap_limit = -1;
  748. __u16 offset;
  749. struct flowi6 fl6;
  750. __u8 dsfield;
  751. __u32 mtu;
  752. int err;
  753. if (ipv6_addr_equal(&t->parms.raddr, &ipv6h->saddr))
  754. return -1;
  755. offset = ip6_tnl_parse_tlv_enc_lim(skb, skb_network_header(skb));
  756. if (offset > 0) {
  757. struct ipv6_tlv_tnl_enc_lim *tel;
  758. tel = (struct ipv6_tlv_tnl_enc_lim *)&skb_network_header(skb)[offset];
  759. if (tel->encap_limit == 0) {
  760. icmpv6_send(skb, ICMPV6_PARAMPROB,
  761. ICMPV6_HDR_FIELD, offset + 2);
  762. return -1;
  763. }
  764. encap_limit = tel->encap_limit - 1;
  765. } else if (!(t->parms.flags & IP6_TNL_F_IGN_ENCAP_LIMIT))
  766. encap_limit = t->parms.encap_limit;
  767. memcpy(&fl6, &t->fl.u.ip6, sizeof(fl6));
  768. fl6.flowi6_proto = IPPROTO_IPV6;
  769. dsfield = ipv6_get_dsfield(ipv6h);
  770. if (t->parms.flags & IP6_TNL_F_USE_ORIG_TCLASS)
  771. fl6.flowlabel |= (*(__be32 *) ipv6h & IPV6_TCLASS_MASK);
  772. if (t->parms.flags & IP6_TNL_F_USE_ORIG_FLOWLABEL)
  773. fl6.flowlabel |= (*(__be32 *) ipv6h & IPV6_FLOWLABEL_MASK);
  774. if (t->parms.flags & IP6_TNL_F_USE_ORIG_FWMARK)
  775. fl6.flowi6_mark = skb->mark;
  776. err = ip6gre_xmit2(skb, dev, dsfield, &fl6, encap_limit, &mtu);
  777. if (err != 0) {
  778. if (err == -EMSGSIZE)
  779. icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu);
  780. return -1;
  781. }
  782. return 0;
  783. }
  784. /**
  785. * ip6_tnl_addr_conflict - compare packet addresses to tunnel's own
  786. * @t: the outgoing tunnel device
  787. * @hdr: IPv6 header from the incoming packet
  788. *
  789. * Description:
  790. * Avoid trivial tunneling loop by checking that tunnel exit-point
  791. * doesn't match source of incoming packet.
  792. *
  793. * Return:
  794. * 1 if conflict,
  795. * 0 else
  796. **/
  797. static inline bool ip6gre_tnl_addr_conflict(const struct ip6_tnl *t,
  798. const struct ipv6hdr *hdr)
  799. {
  800. return ipv6_addr_equal(&t->parms.raddr, &hdr->saddr);
  801. }
  802. static int ip6gre_xmit_other(struct sk_buff *skb, struct net_device *dev)
  803. {
  804. struct ip6_tnl *t = netdev_priv(dev);
  805. int encap_limit = -1;
  806. struct flowi6 fl6;
  807. __u32 mtu;
  808. int err;
  809. if (!(t->parms.flags & IP6_TNL_F_IGN_ENCAP_LIMIT))
  810. encap_limit = t->parms.encap_limit;
  811. memcpy(&fl6, &t->fl.u.ip6, sizeof(fl6));
  812. fl6.flowi6_proto = skb->protocol;
  813. err = ip6gre_xmit2(skb, dev, 0, &fl6, encap_limit, &mtu);
  814. return err;
  815. }
  816. static netdev_tx_t ip6gre_tunnel_xmit(struct sk_buff *skb,
  817. struct net_device *dev)
  818. {
  819. struct ip6_tnl *t = netdev_priv(dev);
  820. struct net_device_stats *stats = &t->dev->stats;
  821. int ret;
  822. if (!ip6_tnl_xmit_ctl(t))
  823. return -1;
  824. switch (skb->protocol) {
  825. case htons(ETH_P_IP):
  826. ret = ip6gre_xmit_ipv4(skb, dev);
  827. break;
  828. case htons(ETH_P_IPV6):
  829. ret = ip6gre_xmit_ipv6(skb, dev);
  830. break;
  831. default:
  832. ret = ip6gre_xmit_other(skb, dev);
  833. break;
  834. }
  835. if (ret < 0)
  836. goto tx_err;
  837. return NETDEV_TX_OK;
  838. tx_err:
  839. stats->tx_errors++;
  840. stats->tx_dropped++;
  841. kfree_skb(skb);
  842. return NETDEV_TX_OK;
  843. }
  844. static void ip6gre_tnl_link_config(struct ip6_tnl *t, int set_mtu)
  845. {
  846. struct net_device *dev = t->dev;
  847. struct __ip6_tnl_parm *p = &t->parms;
  848. struct flowi6 *fl6 = &t->fl.u.ip6;
  849. int addend = sizeof(struct ipv6hdr) + 4;
  850. if (dev->type != ARPHRD_ETHER) {
  851. memcpy(dev->dev_addr, &p->laddr, sizeof(struct in6_addr));
  852. memcpy(dev->broadcast, &p->raddr, sizeof(struct in6_addr));
  853. }
  854. /* Set up flowi template */
  855. fl6->saddr = p->laddr;
  856. fl6->daddr = p->raddr;
  857. fl6->flowi6_oif = p->link;
  858. fl6->flowlabel = 0;
  859. if (!(p->flags&IP6_TNL_F_USE_ORIG_TCLASS))
  860. fl6->flowlabel |= IPV6_TCLASS_MASK & p->flowinfo;
  861. if (!(p->flags&IP6_TNL_F_USE_ORIG_FLOWLABEL))
  862. fl6->flowlabel |= IPV6_FLOWLABEL_MASK & p->flowinfo;
  863. p->flags &= ~(IP6_TNL_F_CAP_XMIT|IP6_TNL_F_CAP_RCV|IP6_TNL_F_CAP_PER_PACKET);
  864. p->flags |= ip6_tnl_get_cap(t, &p->laddr, &p->raddr);
  865. if (p->flags&IP6_TNL_F_CAP_XMIT &&
  866. p->flags&IP6_TNL_F_CAP_RCV && dev->type != ARPHRD_ETHER)
  867. dev->flags |= IFF_POINTOPOINT;
  868. else
  869. dev->flags &= ~IFF_POINTOPOINT;
  870. dev->iflink = p->link;
  871. /* Precalculate GRE options length */
  872. if (t->parms.o_flags&(GRE_CSUM|GRE_KEY|GRE_SEQ)) {
  873. if (t->parms.o_flags&GRE_CSUM)
  874. addend += 4;
  875. if (t->parms.o_flags&GRE_KEY)
  876. addend += 4;
  877. if (t->parms.o_flags&GRE_SEQ)
  878. addend += 4;
  879. }
  880. if (p->flags & IP6_TNL_F_CAP_XMIT) {
  881. int strict = (ipv6_addr_type(&p->raddr) &
  882. (IPV6_ADDR_MULTICAST|IPV6_ADDR_LINKLOCAL));
  883. struct rt6_info *rt = rt6_lookup(dev_net(dev),
  884. &p->raddr, &p->laddr,
  885. p->link, strict);
  886. if (rt == NULL)
  887. return;
  888. if (rt->dst.dev) {
  889. dev->hard_header_len = rt->dst.dev->hard_header_len + addend;
  890. if (set_mtu) {
  891. dev->mtu = rt->dst.dev->mtu - addend;
  892. if (!(t->parms.flags & IP6_TNL_F_IGN_ENCAP_LIMIT))
  893. dev->mtu -= 8;
  894. if (dev->mtu < IPV6_MIN_MTU)
  895. dev->mtu = IPV6_MIN_MTU;
  896. }
  897. }
  898. dst_release(&rt->dst);
  899. }
  900. t->hlen = addend;
  901. }
  902. static int ip6gre_tnl_change(struct ip6_tnl *t,
  903. const struct __ip6_tnl_parm *p, int set_mtu)
  904. {
  905. t->parms.laddr = p->laddr;
  906. t->parms.raddr = p->raddr;
  907. t->parms.flags = p->flags;
  908. t->parms.hop_limit = p->hop_limit;
  909. t->parms.encap_limit = p->encap_limit;
  910. t->parms.flowinfo = p->flowinfo;
  911. t->parms.link = p->link;
  912. t->parms.proto = p->proto;
  913. t->parms.i_key = p->i_key;
  914. t->parms.o_key = p->o_key;
  915. t->parms.i_flags = p->i_flags;
  916. t->parms.o_flags = p->o_flags;
  917. ip6_tnl_dst_reset(t);
  918. ip6gre_tnl_link_config(t, set_mtu);
  919. return 0;
  920. }
  921. static void ip6gre_tnl_parm_from_user(struct __ip6_tnl_parm *p,
  922. const struct ip6_tnl_parm2 *u)
  923. {
  924. p->laddr = u->laddr;
  925. p->raddr = u->raddr;
  926. p->flags = u->flags;
  927. p->hop_limit = u->hop_limit;
  928. p->encap_limit = u->encap_limit;
  929. p->flowinfo = u->flowinfo;
  930. p->link = u->link;
  931. p->i_key = u->i_key;
  932. p->o_key = u->o_key;
  933. p->i_flags = u->i_flags;
  934. p->o_flags = u->o_flags;
  935. memcpy(p->name, u->name, sizeof(u->name));
  936. }
  937. static void ip6gre_tnl_parm_to_user(struct ip6_tnl_parm2 *u,
  938. const struct __ip6_tnl_parm *p)
  939. {
  940. u->proto = IPPROTO_GRE;
  941. u->laddr = p->laddr;
  942. u->raddr = p->raddr;
  943. u->flags = p->flags;
  944. u->hop_limit = p->hop_limit;
  945. u->encap_limit = p->encap_limit;
  946. u->flowinfo = p->flowinfo;
  947. u->link = p->link;
  948. u->i_key = p->i_key;
  949. u->o_key = p->o_key;
  950. u->i_flags = p->i_flags;
  951. u->o_flags = p->o_flags;
  952. memcpy(u->name, p->name, sizeof(u->name));
  953. }
  954. static int ip6gre_tunnel_ioctl(struct net_device *dev,
  955. struct ifreq *ifr, int cmd)
  956. {
  957. int err = 0;
  958. struct ip6_tnl_parm2 p;
  959. struct __ip6_tnl_parm p1;
  960. struct ip6_tnl *t;
  961. struct net *net = dev_net(dev);
  962. struct ip6gre_net *ign = net_generic(net, ip6gre_net_id);
  963. switch (cmd) {
  964. case SIOCGETTUNNEL:
  965. t = NULL;
  966. if (dev == ign->fb_tunnel_dev) {
  967. if (copy_from_user(&p, ifr->ifr_ifru.ifru_data, sizeof(p))) {
  968. err = -EFAULT;
  969. break;
  970. }
  971. ip6gre_tnl_parm_from_user(&p1, &p);
  972. t = ip6gre_tunnel_locate(net, &p1, 0);
  973. }
  974. if (t == NULL)
  975. t = netdev_priv(dev);
  976. ip6gre_tnl_parm_to_user(&p, &t->parms);
  977. if (copy_to_user(ifr->ifr_ifru.ifru_data, &p, sizeof(p)))
  978. err = -EFAULT;
  979. break;
  980. case SIOCADDTUNNEL:
  981. case SIOCCHGTUNNEL:
  982. err = -EPERM;
  983. if (!capable(CAP_NET_ADMIN))
  984. goto done;
  985. err = -EFAULT;
  986. if (copy_from_user(&p, ifr->ifr_ifru.ifru_data, sizeof(p)))
  987. goto done;
  988. err = -EINVAL;
  989. if ((p.i_flags|p.o_flags)&(GRE_VERSION|GRE_ROUTING))
  990. goto done;
  991. if (!(p.i_flags&GRE_KEY))
  992. p.i_key = 0;
  993. if (!(p.o_flags&GRE_KEY))
  994. p.o_key = 0;
  995. ip6gre_tnl_parm_from_user(&p1, &p);
  996. t = ip6gre_tunnel_locate(net, &p1, cmd == SIOCADDTUNNEL);
  997. if (dev != ign->fb_tunnel_dev && cmd == SIOCCHGTUNNEL) {
  998. if (t != NULL) {
  999. if (t->dev != dev) {
  1000. err = -EEXIST;
  1001. break;
  1002. }
  1003. } else {
  1004. t = netdev_priv(dev);
  1005. ip6gre_tunnel_unlink(ign, t);
  1006. synchronize_net();
  1007. ip6gre_tnl_change(t, &p1, 1);
  1008. ip6gre_tunnel_link(ign, t);
  1009. netdev_state_change(dev);
  1010. }
  1011. }
  1012. if (t) {
  1013. err = 0;
  1014. ip6gre_tnl_parm_to_user(&p, &t->parms);
  1015. if (copy_to_user(ifr->ifr_ifru.ifru_data, &p, sizeof(p)))
  1016. err = -EFAULT;
  1017. } else
  1018. err = (cmd == SIOCADDTUNNEL ? -ENOBUFS : -ENOENT);
  1019. break;
  1020. case SIOCDELTUNNEL:
  1021. err = -EPERM;
  1022. if (!capable(CAP_NET_ADMIN))
  1023. goto done;
  1024. if (dev == ign->fb_tunnel_dev) {
  1025. err = -EFAULT;
  1026. if (copy_from_user(&p, ifr->ifr_ifru.ifru_data, sizeof(p)))
  1027. goto done;
  1028. err = -ENOENT;
  1029. ip6gre_tnl_parm_from_user(&p1, &p);
  1030. t = ip6gre_tunnel_locate(net, &p1, 0);
  1031. if (t == NULL)
  1032. goto done;
  1033. err = -EPERM;
  1034. if (t == netdev_priv(ign->fb_tunnel_dev))
  1035. goto done;
  1036. dev = t->dev;
  1037. }
  1038. unregister_netdevice(dev);
  1039. err = 0;
  1040. break;
  1041. default:
  1042. err = -EINVAL;
  1043. }
  1044. done:
  1045. return err;
  1046. }
  1047. static int ip6gre_tunnel_change_mtu(struct net_device *dev, int new_mtu)
  1048. {
  1049. struct ip6_tnl *tunnel = netdev_priv(dev);
  1050. if (new_mtu < 68 ||
  1051. new_mtu > 0xFFF8 - dev->hard_header_len - tunnel->hlen)
  1052. return -EINVAL;
  1053. dev->mtu = new_mtu;
  1054. return 0;
  1055. }
  1056. static int ip6gre_header(struct sk_buff *skb, struct net_device *dev,
  1057. unsigned short type,
  1058. const void *daddr, const void *saddr, unsigned int len)
  1059. {
  1060. struct ip6_tnl *t = netdev_priv(dev);
  1061. struct ipv6hdr *ipv6h = (struct ipv6hdr *)skb_push(skb, t->hlen);
  1062. __be16 *p = (__be16 *)(ipv6h+1);
  1063. ip6_flow_hdr(ipv6h, 0, t->fl.u.ip6.flowlabel);
  1064. ipv6h->hop_limit = t->parms.hop_limit;
  1065. ipv6h->nexthdr = NEXTHDR_GRE;
  1066. ipv6h->saddr = t->parms.laddr;
  1067. ipv6h->daddr = t->parms.raddr;
  1068. p[0] = t->parms.o_flags;
  1069. p[1] = htons(type);
  1070. /*
  1071. * Set the source hardware address.
  1072. */
  1073. if (saddr)
  1074. memcpy(&ipv6h->saddr, saddr, sizeof(struct in6_addr));
  1075. if (daddr)
  1076. memcpy(&ipv6h->daddr, daddr, sizeof(struct in6_addr));
  1077. if (!ipv6_addr_any(&ipv6h->daddr))
  1078. return t->hlen;
  1079. return -t->hlen;
  1080. }
  1081. static const struct header_ops ip6gre_header_ops = {
  1082. .create = ip6gre_header,
  1083. };
  1084. static const struct net_device_ops ip6gre_netdev_ops = {
  1085. .ndo_init = ip6gre_tunnel_init,
  1086. .ndo_uninit = ip6gre_tunnel_uninit,
  1087. .ndo_start_xmit = ip6gre_tunnel_xmit,
  1088. .ndo_do_ioctl = ip6gre_tunnel_ioctl,
  1089. .ndo_change_mtu = ip6gre_tunnel_change_mtu,
  1090. .ndo_get_stats64 = ip6gre_get_stats64,
  1091. };
  1092. static void ip6gre_dev_free(struct net_device *dev)
  1093. {
  1094. free_percpu(dev->tstats);
  1095. free_netdev(dev);
  1096. }
  1097. static void ip6gre_tunnel_setup(struct net_device *dev)
  1098. {
  1099. struct ip6_tnl *t;
  1100. dev->netdev_ops = &ip6gre_netdev_ops;
  1101. dev->destructor = ip6gre_dev_free;
  1102. dev->type = ARPHRD_IP6GRE;
  1103. dev->hard_header_len = LL_MAX_HEADER + sizeof(struct ipv6hdr) + 4;
  1104. dev->mtu = ETH_DATA_LEN - sizeof(struct ipv6hdr) - 4;
  1105. t = netdev_priv(dev);
  1106. if (!(t->parms.flags & IP6_TNL_F_IGN_ENCAP_LIMIT))
  1107. dev->mtu -= 8;
  1108. dev->flags |= IFF_NOARP;
  1109. dev->iflink = 0;
  1110. dev->addr_len = sizeof(struct in6_addr);
  1111. dev->features |= NETIF_F_NETNS_LOCAL;
  1112. dev->priv_flags &= ~IFF_XMIT_DST_RELEASE;
  1113. }
  1114. static int ip6gre_tunnel_init(struct net_device *dev)
  1115. {
  1116. struct ip6_tnl *tunnel;
  1117. tunnel = netdev_priv(dev);
  1118. tunnel->dev = dev;
  1119. strcpy(tunnel->parms.name, dev->name);
  1120. memcpy(dev->dev_addr, &tunnel->parms.laddr, sizeof(struct in6_addr));
  1121. memcpy(dev->broadcast, &tunnel->parms.raddr, sizeof(struct in6_addr));
  1122. if (ipv6_addr_any(&tunnel->parms.raddr))
  1123. dev->header_ops = &ip6gre_header_ops;
  1124. dev->tstats = alloc_percpu(struct pcpu_tstats);
  1125. if (!dev->tstats)
  1126. return -ENOMEM;
  1127. return 0;
  1128. }
  1129. static void ip6gre_fb_tunnel_init(struct net_device *dev)
  1130. {
  1131. struct ip6_tnl *tunnel = netdev_priv(dev);
  1132. tunnel->dev = dev;
  1133. strcpy(tunnel->parms.name, dev->name);
  1134. tunnel->hlen = sizeof(struct ipv6hdr) + 4;
  1135. dev_hold(dev);
  1136. }
  1137. static struct inet6_protocol ip6gre_protocol __read_mostly = {
  1138. .handler = ip6gre_rcv,
  1139. .err_handler = ip6gre_err,
  1140. .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
  1141. };
  1142. static void ip6gre_destroy_tunnels(struct ip6gre_net *ign,
  1143. struct list_head *head)
  1144. {
  1145. int prio;
  1146. for (prio = 0; prio < 4; prio++) {
  1147. int h;
  1148. for (h = 0; h < HASH_SIZE; h++) {
  1149. struct ip6_tnl *t;
  1150. t = rtnl_dereference(ign->tunnels[prio][h]);
  1151. while (t != NULL) {
  1152. unregister_netdevice_queue(t->dev, head);
  1153. t = rtnl_dereference(t->next);
  1154. }
  1155. }
  1156. }
  1157. }
  1158. static int __net_init ip6gre_init_net(struct net *net)
  1159. {
  1160. struct ip6gre_net *ign = net_generic(net, ip6gre_net_id);
  1161. int err;
  1162. ign->fb_tunnel_dev = alloc_netdev(sizeof(struct ip6_tnl), "ip6gre0",
  1163. ip6gre_tunnel_setup);
  1164. if (!ign->fb_tunnel_dev) {
  1165. err = -ENOMEM;
  1166. goto err_alloc_dev;
  1167. }
  1168. dev_net_set(ign->fb_tunnel_dev, net);
  1169. ip6gre_fb_tunnel_init(ign->fb_tunnel_dev);
  1170. ign->fb_tunnel_dev->rtnl_link_ops = &ip6gre_link_ops;
  1171. err = register_netdev(ign->fb_tunnel_dev);
  1172. if (err)
  1173. goto err_reg_dev;
  1174. rcu_assign_pointer(ign->tunnels_wc[0],
  1175. netdev_priv(ign->fb_tunnel_dev));
  1176. return 0;
  1177. err_reg_dev:
  1178. ip6gre_dev_free(ign->fb_tunnel_dev);
  1179. err_alloc_dev:
  1180. return err;
  1181. }
  1182. static void __net_exit ip6gre_exit_net(struct net *net)
  1183. {
  1184. struct ip6gre_net *ign;
  1185. LIST_HEAD(list);
  1186. ign = net_generic(net, ip6gre_net_id);
  1187. rtnl_lock();
  1188. ip6gre_destroy_tunnels(ign, &list);
  1189. unregister_netdevice_many(&list);
  1190. rtnl_unlock();
  1191. }
  1192. static struct pernet_operations ip6gre_net_ops = {
  1193. .init = ip6gre_init_net,
  1194. .exit = ip6gre_exit_net,
  1195. .id = &ip6gre_net_id,
  1196. .size = sizeof(struct ip6gre_net),
  1197. };
  1198. static int ip6gre_tunnel_validate(struct nlattr *tb[], struct nlattr *data[])
  1199. {
  1200. __be16 flags;
  1201. if (!data)
  1202. return 0;
  1203. flags = 0;
  1204. if (data[IFLA_GRE_IFLAGS])
  1205. flags |= nla_get_be16(data[IFLA_GRE_IFLAGS]);
  1206. if (data[IFLA_GRE_OFLAGS])
  1207. flags |= nla_get_be16(data[IFLA_GRE_OFLAGS]);
  1208. if (flags & (GRE_VERSION|GRE_ROUTING))
  1209. return -EINVAL;
  1210. return 0;
  1211. }
  1212. static int ip6gre_tap_validate(struct nlattr *tb[], struct nlattr *data[])
  1213. {
  1214. struct in6_addr daddr;
  1215. if (tb[IFLA_ADDRESS]) {
  1216. if (nla_len(tb[IFLA_ADDRESS]) != ETH_ALEN)
  1217. return -EINVAL;
  1218. if (!is_valid_ether_addr(nla_data(tb[IFLA_ADDRESS])))
  1219. return -EADDRNOTAVAIL;
  1220. }
  1221. if (!data)
  1222. goto out;
  1223. if (data[IFLA_GRE_REMOTE]) {
  1224. nla_memcpy(&daddr, data[IFLA_GRE_REMOTE], sizeof(struct in6_addr));
  1225. if (ipv6_addr_any(&daddr))
  1226. return -EINVAL;
  1227. }
  1228. out:
  1229. return ip6gre_tunnel_validate(tb, data);
  1230. }
  1231. static void ip6gre_netlink_parms(struct nlattr *data[],
  1232. struct __ip6_tnl_parm *parms)
  1233. {
  1234. memset(parms, 0, sizeof(*parms));
  1235. if (!data)
  1236. return;
  1237. if (data[IFLA_GRE_LINK])
  1238. parms->link = nla_get_u32(data[IFLA_GRE_LINK]);
  1239. if (data[IFLA_GRE_IFLAGS])
  1240. parms->i_flags = nla_get_be16(data[IFLA_GRE_IFLAGS]);
  1241. if (data[IFLA_GRE_OFLAGS])
  1242. parms->o_flags = nla_get_be16(data[IFLA_GRE_OFLAGS]);
  1243. if (data[IFLA_GRE_IKEY])
  1244. parms->i_key = nla_get_be32(data[IFLA_GRE_IKEY]);
  1245. if (data[IFLA_GRE_OKEY])
  1246. parms->o_key = nla_get_be32(data[IFLA_GRE_OKEY]);
  1247. if (data[IFLA_GRE_LOCAL])
  1248. nla_memcpy(&parms->laddr, data[IFLA_GRE_LOCAL], sizeof(struct in6_addr));
  1249. if (data[IFLA_GRE_REMOTE])
  1250. nla_memcpy(&parms->raddr, data[IFLA_GRE_REMOTE], sizeof(struct in6_addr));
  1251. if (data[IFLA_GRE_TTL])
  1252. parms->hop_limit = nla_get_u8(data[IFLA_GRE_TTL]);
  1253. if (data[IFLA_GRE_ENCAP_LIMIT])
  1254. parms->encap_limit = nla_get_u8(data[IFLA_GRE_ENCAP_LIMIT]);
  1255. if (data[IFLA_GRE_FLOWINFO])
  1256. parms->flowinfo = nla_get_u32(data[IFLA_GRE_FLOWINFO]);
  1257. if (data[IFLA_GRE_FLAGS])
  1258. parms->flags = nla_get_u32(data[IFLA_GRE_FLAGS]);
  1259. }
  1260. static int ip6gre_tap_init(struct net_device *dev)
  1261. {
  1262. struct ip6_tnl *tunnel;
  1263. tunnel = netdev_priv(dev);
  1264. tunnel->dev = dev;
  1265. strcpy(tunnel->parms.name, dev->name);
  1266. ip6gre_tnl_link_config(tunnel, 1);
  1267. dev->tstats = alloc_percpu(struct pcpu_tstats);
  1268. if (!dev->tstats)
  1269. return -ENOMEM;
  1270. return 0;
  1271. }
  1272. static const struct net_device_ops ip6gre_tap_netdev_ops = {
  1273. .ndo_init = ip6gre_tap_init,
  1274. .ndo_uninit = ip6gre_tunnel_uninit,
  1275. .ndo_start_xmit = ip6gre_tunnel_xmit,
  1276. .ndo_set_mac_address = eth_mac_addr,
  1277. .ndo_validate_addr = eth_validate_addr,
  1278. .ndo_change_mtu = ip6gre_tunnel_change_mtu,
  1279. .ndo_get_stats64 = ip6gre_get_stats64,
  1280. };
  1281. static void ip6gre_tap_setup(struct net_device *dev)
  1282. {
  1283. ether_setup(dev);
  1284. dev->netdev_ops = &ip6gre_tap_netdev_ops;
  1285. dev->destructor = ip6gre_dev_free;
  1286. dev->iflink = 0;
  1287. dev->features |= NETIF_F_NETNS_LOCAL;
  1288. }
  1289. static int ip6gre_newlink(struct net *src_net, struct net_device *dev,
  1290. struct nlattr *tb[], struct nlattr *data[])
  1291. {
  1292. struct ip6_tnl *nt;
  1293. struct net *net = dev_net(dev);
  1294. struct ip6gre_net *ign = net_generic(net, ip6gre_net_id);
  1295. int err;
  1296. nt = netdev_priv(dev);
  1297. ip6gre_netlink_parms(data, &nt->parms);
  1298. if (ip6gre_tunnel_find(net, &nt->parms, dev->type))
  1299. return -EEXIST;
  1300. if (dev->type == ARPHRD_ETHER && !tb[IFLA_ADDRESS])
  1301. eth_hw_addr_random(dev);
  1302. nt->dev = dev;
  1303. ip6gre_tnl_link_config(nt, !tb[IFLA_MTU]);
  1304. /* Can use a lockless transmit, unless we generate output sequences */
  1305. if (!(nt->parms.o_flags & GRE_SEQ))
  1306. dev->features |= NETIF_F_LLTX;
  1307. err = register_netdevice(dev);
  1308. if (err)
  1309. goto out;
  1310. dev_hold(dev);
  1311. ip6gre_tunnel_link(ign, nt);
  1312. out:
  1313. return err;
  1314. }
  1315. static int ip6gre_changelink(struct net_device *dev, struct nlattr *tb[],
  1316. struct nlattr *data[])
  1317. {
  1318. struct ip6_tnl *t, *nt;
  1319. struct net *net = dev_net(dev);
  1320. struct ip6gre_net *ign = net_generic(net, ip6gre_net_id);
  1321. struct __ip6_tnl_parm p;
  1322. if (dev == ign->fb_tunnel_dev)
  1323. return -EINVAL;
  1324. nt = netdev_priv(dev);
  1325. ip6gre_netlink_parms(data, &p);
  1326. t = ip6gre_tunnel_locate(net, &p, 0);
  1327. if (t) {
  1328. if (t->dev != dev)
  1329. return -EEXIST;
  1330. } else {
  1331. t = nt;
  1332. ip6gre_tunnel_unlink(ign, t);
  1333. ip6gre_tnl_change(t, &p, !tb[IFLA_MTU]);
  1334. ip6gre_tunnel_link(ign, t);
  1335. netdev_state_change(dev);
  1336. }
  1337. return 0;
  1338. }
  1339. static size_t ip6gre_get_size(const struct net_device *dev)
  1340. {
  1341. return
  1342. /* IFLA_GRE_LINK */
  1343. nla_total_size(4) +
  1344. /* IFLA_GRE_IFLAGS */
  1345. nla_total_size(2) +
  1346. /* IFLA_GRE_OFLAGS */
  1347. nla_total_size(2) +
  1348. /* IFLA_GRE_IKEY */
  1349. nla_total_size(4) +
  1350. /* IFLA_GRE_OKEY */
  1351. nla_total_size(4) +
  1352. /* IFLA_GRE_LOCAL */
  1353. nla_total_size(sizeof(struct in6_addr)) +
  1354. /* IFLA_GRE_REMOTE */
  1355. nla_total_size(sizeof(struct in6_addr)) +
  1356. /* IFLA_GRE_TTL */
  1357. nla_total_size(1) +
  1358. /* IFLA_GRE_TOS */
  1359. nla_total_size(1) +
  1360. /* IFLA_GRE_ENCAP_LIMIT */
  1361. nla_total_size(1) +
  1362. /* IFLA_GRE_FLOWINFO */
  1363. nla_total_size(4) +
  1364. /* IFLA_GRE_FLAGS */
  1365. nla_total_size(4) +
  1366. 0;
  1367. }
  1368. static int ip6gre_fill_info(struct sk_buff *skb, const struct net_device *dev)
  1369. {
  1370. struct ip6_tnl *t = netdev_priv(dev);
  1371. struct __ip6_tnl_parm *p = &t->parms;
  1372. if (nla_put_u32(skb, IFLA_GRE_LINK, p->link) ||
  1373. nla_put_be16(skb, IFLA_GRE_IFLAGS, p->i_flags) ||
  1374. nla_put_be16(skb, IFLA_GRE_OFLAGS, p->o_flags) ||
  1375. nla_put_be32(skb, IFLA_GRE_IKEY, p->i_key) ||
  1376. nla_put_be32(skb, IFLA_GRE_OKEY, p->o_key) ||
  1377. nla_put(skb, IFLA_GRE_LOCAL, sizeof(struct in6_addr), &p->laddr) ||
  1378. nla_put(skb, IFLA_GRE_REMOTE, sizeof(struct in6_addr), &p->raddr) ||
  1379. nla_put_u8(skb, IFLA_GRE_TTL, p->hop_limit) ||
  1380. /*nla_put_u8(skb, IFLA_GRE_TOS, t->priority) ||*/
  1381. nla_put_u8(skb, IFLA_GRE_ENCAP_LIMIT, p->encap_limit) ||
  1382. nla_put_be32(skb, IFLA_GRE_FLOWINFO, p->flowinfo) ||
  1383. nla_put_u32(skb, IFLA_GRE_FLAGS, p->flags))
  1384. goto nla_put_failure;
  1385. return 0;
  1386. nla_put_failure:
  1387. return -EMSGSIZE;
  1388. }
  1389. static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
  1390. [IFLA_GRE_LINK] = { .type = NLA_U32 },
  1391. [IFLA_GRE_IFLAGS] = { .type = NLA_U16 },
  1392. [IFLA_GRE_OFLAGS] = { .type = NLA_U16 },
  1393. [IFLA_GRE_IKEY] = { .type = NLA_U32 },
  1394. [IFLA_GRE_OKEY] = { .type = NLA_U32 },
  1395. [IFLA_GRE_LOCAL] = { .len = FIELD_SIZEOF(struct ipv6hdr, saddr) },
  1396. [IFLA_GRE_REMOTE] = { .len = FIELD_SIZEOF(struct ipv6hdr, daddr) },
  1397. [IFLA_GRE_TTL] = { .type = NLA_U8 },
  1398. [IFLA_GRE_ENCAP_LIMIT] = { .type = NLA_U8 },
  1399. [IFLA_GRE_FLOWINFO] = { .type = NLA_U32 },
  1400. [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
  1401. };
  1402. static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
  1403. .kind = "ip6gre",
  1404. .maxtype = IFLA_GRE_MAX,
  1405. .policy = ip6gre_policy,
  1406. .priv_size = sizeof(struct ip6_tnl),
  1407. .setup = ip6gre_tunnel_setup,
  1408. .validate = ip6gre_tunnel_validate,
  1409. .newlink = ip6gre_newlink,
  1410. .changelink = ip6gre_changelink,
  1411. .get_size = ip6gre_get_size,
  1412. .fill_info = ip6gre_fill_info,
  1413. };
  1414. static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
  1415. .kind = "ip6gretap",
  1416. .maxtype = IFLA_GRE_MAX,
  1417. .policy = ip6gre_policy,
  1418. .priv_size = sizeof(struct ip6_tnl),
  1419. .setup = ip6gre_tap_setup,
  1420. .validate = ip6gre_tap_validate,
  1421. .newlink = ip6gre_newlink,
  1422. .changelink = ip6gre_changelink,
  1423. .get_size = ip6gre_get_size,
  1424. .fill_info = ip6gre_fill_info,
  1425. };
  1426. /*
  1427. * And now the modules code and kernel interface.
  1428. */
  1429. static int __init ip6gre_init(void)
  1430. {
  1431. int err;
  1432. pr_info("GRE over IPv6 tunneling driver\n");
  1433. err = register_pernet_device(&ip6gre_net_ops);
  1434. if (err < 0)
  1435. return err;
  1436. err = inet6_add_protocol(&ip6gre_protocol, IPPROTO_GRE);
  1437. if (err < 0) {
  1438. pr_info("%s: can't add protocol\n", __func__);
  1439. goto add_proto_failed;
  1440. }
  1441. err = rtnl_link_register(&ip6gre_link_ops);
  1442. if (err < 0)
  1443. goto rtnl_link_failed;
  1444. err = rtnl_link_register(&ip6gre_tap_ops);
  1445. if (err < 0)
  1446. goto tap_ops_failed;
  1447. out:
  1448. return err;
  1449. tap_ops_failed:
  1450. rtnl_link_unregister(&ip6gre_link_ops);
  1451. rtnl_link_failed:
  1452. inet6_del_protocol(&ip6gre_protocol, IPPROTO_GRE);
  1453. add_proto_failed:
  1454. unregister_pernet_device(&ip6gre_net_ops);
  1455. goto out;
  1456. }
  1457. static void __exit ip6gre_fini(void)
  1458. {
  1459. rtnl_link_unregister(&ip6gre_tap_ops);
  1460. rtnl_link_unregister(&ip6gre_link_ops);
  1461. inet6_del_protocol(&ip6gre_protocol, IPPROTO_GRE);
  1462. unregister_pernet_device(&ip6gre_net_ops);
  1463. }
  1464. module_init(ip6gre_init);
  1465. module_exit(ip6gre_fini);
  1466. MODULE_LICENSE("GPL");
  1467. MODULE_AUTHOR("D. Kozlov (xeb@mail.ru)");
  1468. MODULE_DESCRIPTION("GRE over IPv6 tunneling device");
  1469. MODULE_ALIAS_RTNL_LINK("ip6gre");
  1470. MODULE_ALIAS_NETDEV("ip6gre0");