ip_vti.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  1. /*
  2. * Linux NET3: IP/IP protocol decoder modified to support
  3. * virtual tunnel interface
  4. *
  5. * Authors:
  6. * Saurabh Mohan (saurabh.mohan@vyatta.com) 05/07/2012
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version
  11. * 2 of the License, or (at your option) any later version.
  12. *
  13. */
  14. /*
  15. This version of net/ipv4/ip_vti.c is cloned of net/ipv4/ipip.c
  16. For comments look at net/ipv4/ip_gre.c --ANK
  17. */
  18. #include <linux/capability.h>
  19. #include <linux/module.h>
  20. #include <linux/types.h>
  21. #include <linux/kernel.h>
  22. #include <linux/uaccess.h>
  23. #include <linux/skbuff.h>
  24. #include <linux/netdevice.h>
  25. #include <linux/in.h>
  26. #include <linux/tcp.h>
  27. #include <linux/udp.h>
  28. #include <linux/if_arp.h>
  29. #include <linux/init.h>
  30. #include <linux/netfilter_ipv4.h>
  31. #include <linux/if_ether.h>
  32. #include <linux/icmpv6.h>
  33. #include <net/sock.h>
  34. #include <net/ip.h>
  35. #include <net/icmp.h>
  36. #include <net/ip_tunnels.h>
  37. #include <net/inet_ecn.h>
  38. #include <net/xfrm.h>
  39. #include <net/net_namespace.h>
  40. #include <net/netns/generic.h>
  41. static struct rtnl_link_ops vti_link_ops __read_mostly;
  42. static int vti_net_id __read_mostly;
  43. static int vti_tunnel_init(struct net_device *dev);
  44. static int vti_input(struct sk_buff *skb, int nexthdr, __be32 spi,
  45. int encap_type)
  46. {
  47. struct ip_tunnel *tunnel;
  48. const struct iphdr *iph = ip_hdr(skb);
  49. struct net *net = dev_net(skb->dev);
  50. struct ip_tunnel_net *itn = net_generic(net, vti_net_id);
  51. tunnel = ip_tunnel_lookup(itn, skb->dev->ifindex, TUNNEL_NO_KEY,
  52. iph->saddr, iph->daddr, 0);
  53. if (tunnel) {
  54. if (!xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb))
  55. goto drop;
  56. XFRM_TUNNEL_SKB_CB(skb)->tunnel.ip4 = tunnel;
  57. return xfrm_input(skb, nexthdr, spi, encap_type);
  58. }
  59. return -EINVAL;
  60. drop:
  61. kfree_skb(skb);
  62. return 0;
  63. }
  64. static int vti_rcv(struct sk_buff *skb)
  65. {
  66. XFRM_SPI_SKB_CB(skb)->family = AF_INET;
  67. XFRM_SPI_SKB_CB(skb)->daddroff = offsetof(struct iphdr, daddr);
  68. return vti_input(skb, ip_hdr(skb)->protocol, 0, 0);
  69. }
  70. static int vti_rcv_cb(struct sk_buff *skb, int err)
  71. {
  72. unsigned short family;
  73. struct net_device *dev;
  74. struct pcpu_sw_netstats *tstats;
  75. struct xfrm_state *x;
  76. struct xfrm_mode *inner_mode;
  77. struct ip_tunnel *tunnel = XFRM_TUNNEL_SKB_CB(skb)->tunnel.ip4;
  78. u32 orig_mark = skb->mark;
  79. int ret;
  80. if (!tunnel)
  81. return 1;
  82. dev = tunnel->dev;
  83. if (err) {
  84. dev->stats.rx_errors++;
  85. dev->stats.rx_dropped++;
  86. return 0;
  87. }
  88. x = xfrm_input_state(skb);
  89. inner_mode = x->inner_mode;
  90. if (x->sel.family == AF_UNSPEC) {
  91. inner_mode = xfrm_ip2inner_mode(x, XFRM_MODE_SKB_CB(skb)->protocol);
  92. if (inner_mode == NULL) {
  93. XFRM_INC_STATS(dev_net(skb->dev),
  94. LINUX_MIB_XFRMINSTATEMODEERROR);
  95. return -EINVAL;
  96. }
  97. }
  98. family = inner_mode->afinfo->family;
  99. skb->mark = be32_to_cpu(tunnel->parms.i_key);
  100. ret = xfrm_policy_check(NULL, XFRM_POLICY_IN, skb, family);
  101. skb->mark = orig_mark;
  102. if (!ret)
  103. return -EPERM;
  104. skb_scrub_packet(skb, !net_eq(tunnel->net, dev_net(skb->dev)));
  105. skb->dev = dev;
  106. tstats = this_cpu_ptr(dev->tstats);
  107. u64_stats_update_begin(&tstats->syncp);
  108. tstats->rx_packets++;
  109. tstats->rx_bytes += skb->len;
  110. u64_stats_update_end(&tstats->syncp);
  111. return 0;
  112. }
  113. static bool vti_state_check(const struct xfrm_state *x, __be32 dst, __be32 src)
  114. {
  115. xfrm_address_t *daddr = (xfrm_address_t *)&dst;
  116. xfrm_address_t *saddr = (xfrm_address_t *)&src;
  117. /* if there is no transform then this tunnel is not functional.
  118. * Or if the xfrm is not mode tunnel.
  119. */
  120. if (!x || x->props.mode != XFRM_MODE_TUNNEL ||
  121. x->props.family != AF_INET)
  122. return false;
  123. if (!dst)
  124. return xfrm_addr_equal(saddr, &x->props.saddr, AF_INET);
  125. if (!xfrm_state_addr_check(x, daddr, saddr, AF_INET))
  126. return false;
  127. return true;
  128. }
  129. static netdev_tx_t vti_xmit(struct sk_buff *skb, struct net_device *dev,
  130. struct flowi *fl)
  131. {
  132. struct ip_tunnel *tunnel = netdev_priv(dev);
  133. struct ip_tunnel_parm *parms = &tunnel->parms;
  134. struct dst_entry *dst = skb_dst(skb);
  135. struct net_device *tdev; /* Device to other host */
  136. int pkt_len = skb->len;
  137. int err;
  138. int mtu;
  139. if (!dst) {
  140. dev->stats.tx_carrier_errors++;
  141. goto tx_error_icmp;
  142. }
  143. dst_hold(dst);
  144. dst = xfrm_lookup(tunnel->net, dst, fl, NULL, 0);
  145. if (IS_ERR(dst)) {
  146. dev->stats.tx_carrier_errors++;
  147. goto tx_error_icmp;
  148. }
  149. if (!vti_state_check(dst->xfrm, parms->iph.daddr, parms->iph.saddr)) {
  150. dev->stats.tx_carrier_errors++;
  151. dst_release(dst);
  152. goto tx_error_icmp;
  153. }
  154. tdev = dst->dev;
  155. if (tdev == dev) {
  156. dst_release(dst);
  157. dev->stats.collisions++;
  158. goto tx_error;
  159. }
  160. if (tunnel->err_count > 0) {
  161. if (time_before(jiffies,
  162. tunnel->err_time + IPTUNNEL_ERR_TIMEO)) {
  163. tunnel->err_count--;
  164. dst_link_failure(skb);
  165. } else
  166. tunnel->err_count = 0;
  167. }
  168. mtu = dst_mtu(dst);
  169. if (skb->len > mtu) {
  170. skb_dst(skb)->ops->update_pmtu(skb_dst(skb), NULL, skb, mtu);
  171. if (skb->protocol == htons(ETH_P_IP)) {
  172. icmp_send(skb, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED,
  173. htonl(mtu));
  174. } else {
  175. if (mtu < IPV6_MIN_MTU)
  176. mtu = IPV6_MIN_MTU;
  177. icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu);
  178. }
  179. dst_release(dst);
  180. goto tx_error;
  181. }
  182. skb_scrub_packet(skb, !net_eq(tunnel->net, dev_net(dev)));
  183. skb_dst_set(skb, dst);
  184. skb->dev = skb_dst(skb)->dev;
  185. err = dst_output(tunnel->net, skb->sk, skb);
  186. if (net_xmit_eval(err) == 0)
  187. err = pkt_len;
  188. iptunnel_xmit_stats(dev, err);
  189. return NETDEV_TX_OK;
  190. tx_error_icmp:
  191. dst_link_failure(skb);
  192. tx_error:
  193. dev->stats.tx_errors++;
  194. kfree_skb(skb);
  195. return NETDEV_TX_OK;
  196. }
  197. /* This function assumes it is being called from dev_queue_xmit()
  198. * and that skb is filled properly by that function.
  199. */
  200. static netdev_tx_t vti_tunnel_xmit(struct sk_buff *skb, struct net_device *dev)
  201. {
  202. struct ip_tunnel *tunnel = netdev_priv(dev);
  203. struct flowi fl;
  204. memset(&fl, 0, sizeof(fl));
  205. switch (skb->protocol) {
  206. case htons(ETH_P_IP):
  207. xfrm_decode_session(skb, &fl, AF_INET);
  208. memset(IPCB(skb), 0, sizeof(*IPCB(skb)));
  209. break;
  210. case htons(ETH_P_IPV6):
  211. xfrm_decode_session(skb, &fl, AF_INET6);
  212. memset(IP6CB(skb), 0, sizeof(*IP6CB(skb)));
  213. break;
  214. default:
  215. dev->stats.tx_errors++;
  216. dev_kfree_skb(skb);
  217. return NETDEV_TX_OK;
  218. }
  219. /* override mark with tunnel output key */
  220. fl.flowi_mark = be32_to_cpu(tunnel->parms.o_key);
  221. return vti_xmit(skb, dev, &fl);
  222. }
  223. static int vti4_err(struct sk_buff *skb, u32 info)
  224. {
  225. __be32 spi;
  226. __u32 mark;
  227. struct xfrm_state *x;
  228. struct ip_tunnel *tunnel;
  229. struct ip_esp_hdr *esph;
  230. struct ip_auth_hdr *ah ;
  231. struct ip_comp_hdr *ipch;
  232. struct net *net = dev_net(skb->dev);
  233. const struct iphdr *iph = (const struct iphdr *)skb->data;
  234. int protocol = iph->protocol;
  235. struct ip_tunnel_net *itn = net_generic(net, vti_net_id);
  236. tunnel = ip_tunnel_lookup(itn, skb->dev->ifindex, TUNNEL_NO_KEY,
  237. iph->daddr, iph->saddr, 0);
  238. if (!tunnel)
  239. return -1;
  240. mark = be32_to_cpu(tunnel->parms.o_key);
  241. switch (protocol) {
  242. case IPPROTO_ESP:
  243. esph = (struct ip_esp_hdr *)(skb->data+(iph->ihl<<2));
  244. spi = esph->spi;
  245. break;
  246. case IPPROTO_AH:
  247. ah = (struct ip_auth_hdr *)(skb->data+(iph->ihl<<2));
  248. spi = ah->spi;
  249. break;
  250. case IPPROTO_COMP:
  251. ipch = (struct ip_comp_hdr *)(skb->data+(iph->ihl<<2));
  252. spi = htonl(ntohs(ipch->cpi));
  253. break;
  254. default:
  255. return 0;
  256. }
  257. switch (icmp_hdr(skb)->type) {
  258. case ICMP_DEST_UNREACH:
  259. if (icmp_hdr(skb)->code != ICMP_FRAG_NEEDED)
  260. return 0;
  261. case ICMP_REDIRECT:
  262. break;
  263. default:
  264. return 0;
  265. }
  266. x = xfrm_state_lookup(net, mark, (const xfrm_address_t *)&iph->daddr,
  267. spi, protocol, AF_INET);
  268. if (!x)
  269. return 0;
  270. if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH)
  271. ipv4_update_pmtu(skb, net, info, 0, 0, protocol, 0);
  272. else
  273. ipv4_redirect(skb, net, 0, 0, protocol, 0);
  274. xfrm_state_put(x);
  275. return 0;
  276. }
  277. static int
  278. vti_tunnel_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  279. {
  280. int err = 0;
  281. struct ip_tunnel_parm p;
  282. if (copy_from_user(&p, ifr->ifr_ifru.ifru_data, sizeof(p)))
  283. return -EFAULT;
  284. if (cmd == SIOCADDTUNNEL || cmd == SIOCCHGTUNNEL) {
  285. if (p.iph.version != 4 || p.iph.protocol != IPPROTO_IPIP ||
  286. p.iph.ihl != 5)
  287. return -EINVAL;
  288. }
  289. if (!(p.i_flags & GRE_KEY))
  290. p.i_key = 0;
  291. if (!(p.o_flags & GRE_KEY))
  292. p.o_key = 0;
  293. p.i_flags = VTI_ISVTI;
  294. err = ip_tunnel_ioctl(dev, &p, cmd);
  295. if (err)
  296. return err;
  297. if (cmd != SIOCDELTUNNEL) {
  298. p.i_flags |= GRE_KEY;
  299. p.o_flags |= GRE_KEY;
  300. }
  301. if (copy_to_user(ifr->ifr_ifru.ifru_data, &p, sizeof(p)))
  302. return -EFAULT;
  303. return 0;
  304. }
  305. static const struct net_device_ops vti_netdev_ops = {
  306. .ndo_init = vti_tunnel_init,
  307. .ndo_uninit = ip_tunnel_uninit,
  308. .ndo_start_xmit = vti_tunnel_xmit,
  309. .ndo_do_ioctl = vti_tunnel_ioctl,
  310. .ndo_change_mtu = ip_tunnel_change_mtu,
  311. .ndo_get_stats64 = ip_tunnel_get_stats64,
  312. .ndo_get_iflink = ip_tunnel_get_iflink,
  313. };
  314. static void vti_tunnel_setup(struct net_device *dev)
  315. {
  316. dev->netdev_ops = &vti_netdev_ops;
  317. dev->type = ARPHRD_TUNNEL;
  318. ip_tunnel_setup(dev, vti_net_id);
  319. }
  320. static int vti_tunnel_init(struct net_device *dev)
  321. {
  322. struct ip_tunnel *tunnel = netdev_priv(dev);
  323. struct iphdr *iph = &tunnel->parms.iph;
  324. memcpy(dev->dev_addr, &iph->saddr, 4);
  325. memcpy(dev->broadcast, &iph->daddr, 4);
  326. dev->mtu = ETH_DATA_LEN;
  327. dev->flags = IFF_NOARP;
  328. dev->addr_len = 4;
  329. dev->features |= NETIF_F_LLTX;
  330. netif_keep_dst(dev);
  331. return ip_tunnel_init(dev);
  332. }
  333. static void __net_init vti_fb_tunnel_init(struct net_device *dev)
  334. {
  335. struct ip_tunnel *tunnel = netdev_priv(dev);
  336. struct iphdr *iph = &tunnel->parms.iph;
  337. iph->version = 4;
  338. iph->protocol = IPPROTO_IPIP;
  339. iph->ihl = 5;
  340. }
  341. static struct xfrm4_protocol vti_esp4_protocol __read_mostly = {
  342. .handler = vti_rcv,
  343. .input_handler = vti_input,
  344. .cb_handler = vti_rcv_cb,
  345. .err_handler = vti4_err,
  346. .priority = 100,
  347. };
  348. static struct xfrm4_protocol vti_ah4_protocol __read_mostly = {
  349. .handler = vti_rcv,
  350. .input_handler = vti_input,
  351. .cb_handler = vti_rcv_cb,
  352. .err_handler = vti4_err,
  353. .priority = 100,
  354. };
  355. static struct xfrm4_protocol vti_ipcomp4_protocol __read_mostly = {
  356. .handler = vti_rcv,
  357. .input_handler = vti_input,
  358. .cb_handler = vti_rcv_cb,
  359. .err_handler = vti4_err,
  360. .priority = 100,
  361. };
  362. static int __net_init vti_init_net(struct net *net)
  363. {
  364. int err;
  365. struct ip_tunnel_net *itn;
  366. err = ip_tunnel_init_net(net, vti_net_id, &vti_link_ops, "ip_vti0");
  367. if (err)
  368. return err;
  369. itn = net_generic(net, vti_net_id);
  370. vti_fb_tunnel_init(itn->fb_tunnel_dev);
  371. return 0;
  372. }
  373. static void __net_exit vti_exit_net(struct net *net)
  374. {
  375. struct ip_tunnel_net *itn = net_generic(net, vti_net_id);
  376. ip_tunnel_delete_net(itn, &vti_link_ops);
  377. }
  378. static struct pernet_operations vti_net_ops = {
  379. .init = vti_init_net,
  380. .exit = vti_exit_net,
  381. .id = &vti_net_id,
  382. .size = sizeof(struct ip_tunnel_net),
  383. };
  384. static int vti_tunnel_validate(struct nlattr *tb[], struct nlattr *data[])
  385. {
  386. return 0;
  387. }
  388. static void vti_netlink_parms(struct nlattr *data[],
  389. struct ip_tunnel_parm *parms)
  390. {
  391. memset(parms, 0, sizeof(*parms));
  392. parms->iph.protocol = IPPROTO_IPIP;
  393. if (!data)
  394. return;
  395. parms->i_flags = VTI_ISVTI;
  396. if (data[IFLA_VTI_LINK])
  397. parms->link = nla_get_u32(data[IFLA_VTI_LINK]);
  398. if (data[IFLA_VTI_IKEY])
  399. parms->i_key = nla_get_be32(data[IFLA_VTI_IKEY]);
  400. if (data[IFLA_VTI_OKEY])
  401. parms->o_key = nla_get_be32(data[IFLA_VTI_OKEY]);
  402. if (data[IFLA_VTI_LOCAL])
  403. parms->iph.saddr = nla_get_in_addr(data[IFLA_VTI_LOCAL]);
  404. if (data[IFLA_VTI_REMOTE])
  405. parms->iph.daddr = nla_get_in_addr(data[IFLA_VTI_REMOTE]);
  406. }
  407. static int vti_newlink(struct net *src_net, struct net_device *dev,
  408. struct nlattr *tb[], struct nlattr *data[])
  409. {
  410. struct ip_tunnel_parm parms;
  411. vti_netlink_parms(data, &parms);
  412. return ip_tunnel_newlink(dev, tb, &parms);
  413. }
  414. static int vti_changelink(struct net_device *dev, struct nlattr *tb[],
  415. struct nlattr *data[])
  416. {
  417. struct ip_tunnel_parm p;
  418. vti_netlink_parms(data, &p);
  419. return ip_tunnel_changelink(dev, tb, &p);
  420. }
  421. static size_t vti_get_size(const struct net_device *dev)
  422. {
  423. return
  424. /* IFLA_VTI_LINK */
  425. nla_total_size(4) +
  426. /* IFLA_VTI_IKEY */
  427. nla_total_size(4) +
  428. /* IFLA_VTI_OKEY */
  429. nla_total_size(4) +
  430. /* IFLA_VTI_LOCAL */
  431. nla_total_size(4) +
  432. /* IFLA_VTI_REMOTE */
  433. nla_total_size(4) +
  434. 0;
  435. }
  436. static int vti_fill_info(struct sk_buff *skb, const struct net_device *dev)
  437. {
  438. struct ip_tunnel *t = netdev_priv(dev);
  439. struct ip_tunnel_parm *p = &t->parms;
  440. nla_put_u32(skb, IFLA_VTI_LINK, p->link);
  441. nla_put_be32(skb, IFLA_VTI_IKEY, p->i_key);
  442. nla_put_be32(skb, IFLA_VTI_OKEY, p->o_key);
  443. nla_put_in_addr(skb, IFLA_VTI_LOCAL, p->iph.saddr);
  444. nla_put_in_addr(skb, IFLA_VTI_REMOTE, p->iph.daddr);
  445. return 0;
  446. }
  447. static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
  448. [IFLA_VTI_LINK] = { .type = NLA_U32 },
  449. [IFLA_VTI_IKEY] = { .type = NLA_U32 },
  450. [IFLA_VTI_OKEY] = { .type = NLA_U32 },
  451. [IFLA_VTI_LOCAL] = { .len = FIELD_SIZEOF(struct iphdr, saddr) },
  452. [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
  453. };
  454. static struct rtnl_link_ops vti_link_ops __read_mostly = {
  455. .kind = "vti",
  456. .maxtype = IFLA_VTI_MAX,
  457. .policy = vti_policy,
  458. .priv_size = sizeof(struct ip_tunnel),
  459. .setup = vti_tunnel_setup,
  460. .validate = vti_tunnel_validate,
  461. .newlink = vti_newlink,
  462. .changelink = vti_changelink,
  463. .dellink = ip_tunnel_dellink,
  464. .get_size = vti_get_size,
  465. .fill_info = vti_fill_info,
  466. .get_link_net = ip_tunnel_get_link_net,
  467. };
  468. static bool is_vti_tunnel(const struct net_device *dev)
  469. {
  470. return dev->netdev_ops == &vti_netdev_ops;
  471. }
  472. static int vti_device_event(struct notifier_block *unused,
  473. unsigned long event, void *ptr)
  474. {
  475. struct net_device *dev = netdev_notifier_info_to_dev(ptr);
  476. struct ip_tunnel *tunnel = netdev_priv(dev);
  477. if (!is_vti_tunnel(dev))
  478. return NOTIFY_DONE;
  479. switch (event) {
  480. case NETDEV_DOWN:
  481. if (!net_eq(tunnel->net, dev_net(dev)))
  482. xfrm_garbage_collect(tunnel->net);
  483. break;
  484. }
  485. return NOTIFY_DONE;
  486. }
  487. static struct notifier_block vti_notifier_block __read_mostly = {
  488. .notifier_call = vti_device_event,
  489. };
  490. static int __init vti_init(void)
  491. {
  492. const char *msg;
  493. int err;
  494. pr_info("IPv4 over IPsec tunneling driver\n");
  495. register_netdevice_notifier(&vti_notifier_block);
  496. msg = "tunnel device";
  497. err = register_pernet_device(&vti_net_ops);
  498. if (err < 0)
  499. goto pernet_dev_failed;
  500. msg = "tunnel protocols";
  501. err = xfrm4_protocol_register(&vti_esp4_protocol, IPPROTO_ESP);
  502. if (err < 0)
  503. goto xfrm_proto_esp_failed;
  504. err = xfrm4_protocol_register(&vti_ah4_protocol, IPPROTO_AH);
  505. if (err < 0)
  506. goto xfrm_proto_ah_failed;
  507. err = xfrm4_protocol_register(&vti_ipcomp4_protocol, IPPROTO_COMP);
  508. if (err < 0)
  509. goto xfrm_proto_comp_failed;
  510. msg = "netlink interface";
  511. err = rtnl_link_register(&vti_link_ops);
  512. if (err < 0)
  513. goto rtnl_link_failed;
  514. return err;
  515. rtnl_link_failed:
  516. xfrm4_protocol_deregister(&vti_ipcomp4_protocol, IPPROTO_COMP);
  517. xfrm_proto_comp_failed:
  518. xfrm4_protocol_deregister(&vti_ah4_protocol, IPPROTO_AH);
  519. xfrm_proto_ah_failed:
  520. xfrm4_protocol_deregister(&vti_esp4_protocol, IPPROTO_ESP);
  521. xfrm_proto_esp_failed:
  522. unregister_pernet_device(&vti_net_ops);
  523. pernet_dev_failed:
  524. unregister_netdevice_notifier(&vti_notifier_block);
  525. pr_err("vti init: failed to register %s\n", msg);
  526. return err;
  527. }
  528. static void __exit vti_fini(void)
  529. {
  530. rtnl_link_unregister(&vti_link_ops);
  531. xfrm4_protocol_deregister(&vti_ipcomp4_protocol, IPPROTO_COMP);
  532. xfrm4_protocol_deregister(&vti_ah4_protocol, IPPROTO_AH);
  533. xfrm4_protocol_deregister(&vti_esp4_protocol, IPPROTO_ESP);
  534. unregister_pernet_device(&vti_net_ops);
  535. unregister_netdevice_notifier(&vti_notifier_block);
  536. }
  537. module_init(vti_init);
  538. module_exit(vti_fini);
  539. MODULE_LICENSE("GPL");
  540. MODULE_ALIAS_RTNL_LINK("vti");
  541. MODULE_ALIAS_NETDEV("ip_vti0");