esp6.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Copyright (C)2002 USAGI/WIDE Project
  4. *
  5. * Authors
  6. *
  7. * Mitsuru KANDA @USAGI : IPv6 Support
  8. * Kazunori MIYAZAWA @USAGI :
  9. * Kunihiro Ishiguro <[email protected]>
  10. *
  11. * This file is derived from net/ipv4/esp.c
  12. */
  13. #define pr_fmt(fmt) "IPv6: " fmt
  14. #include <crypto/aead.h>
  15. #include <crypto/authenc.h>
  16. #include <linux/err.h>
  17. #include <linux/module.h>
  18. #include <net/ip.h>
  19. #include <net/xfrm.h>
  20. #include <net/esp.h>
  21. #include <linux/scatterlist.h>
  22. #include <linux/kernel.h>
  23. #include <linux/pfkeyv2.h>
  24. #include <linux/random.h>
  25. #include <linux/slab.h>
  26. #include <linux/spinlock.h>
  27. #include <net/ip6_checksum.h>
  28. #include <net/ip6_route.h>
  29. #include <net/icmp.h>
  30. #include <net/ipv6.h>
  31. #include <net/protocol.h>
  32. #include <net/udp.h>
  33. #include <linux/icmpv6.h>
  34. #include <net/tcp.h>
  35. #include <net/espintcp.h>
  36. #include <net/inet6_hashtables.h>
  37. #include <linux/highmem.h>
  38. struct esp_skb_cb {
  39. struct xfrm_skb_cb xfrm;
  40. void *tmp;
  41. };
  42. struct esp_output_extra {
  43. __be32 seqhi;
  44. u32 esphoff;
  45. };
  46. #define ESP_SKB_CB(__skb) ((struct esp_skb_cb *)&((__skb)->cb[0]))
  47. /*
  48. * Allocate an AEAD request structure with extra space for SG and IV.
  49. *
  50. * For alignment considerations the upper 32 bits of the sequence number are
  51. * placed at the front, if present. Followed by the IV, the request and finally
  52. * the SG list.
  53. *
  54. * TODO: Use spare space in skb for this where possible.
  55. */
  56. static void *esp_alloc_tmp(struct crypto_aead *aead, int nfrags, int seqihlen)
  57. {
  58. unsigned int len;
  59. len = seqihlen;
  60. len += crypto_aead_ivsize(aead);
  61. if (len) {
  62. len += crypto_aead_alignmask(aead) &
  63. ~(crypto_tfm_ctx_alignment() - 1);
  64. len = ALIGN(len, crypto_tfm_ctx_alignment());
  65. }
  66. len += sizeof(struct aead_request) + crypto_aead_reqsize(aead);
  67. len = ALIGN(len, __alignof__(struct scatterlist));
  68. len += sizeof(struct scatterlist) * nfrags;
  69. return kmalloc(len, GFP_ATOMIC);
  70. }
  71. static inline void *esp_tmp_extra(void *tmp)
  72. {
  73. return PTR_ALIGN(tmp, __alignof__(struct esp_output_extra));
  74. }
  75. static inline u8 *esp_tmp_iv(struct crypto_aead *aead, void *tmp, int seqhilen)
  76. {
  77. return crypto_aead_ivsize(aead) ?
  78. PTR_ALIGN((u8 *)tmp + seqhilen,
  79. crypto_aead_alignmask(aead) + 1) : tmp + seqhilen;
  80. }
  81. static inline struct aead_request *esp_tmp_req(struct crypto_aead *aead, u8 *iv)
  82. {
  83. struct aead_request *req;
  84. req = (void *)PTR_ALIGN(iv + crypto_aead_ivsize(aead),
  85. crypto_tfm_ctx_alignment());
  86. aead_request_set_tfm(req, aead);
  87. return req;
  88. }
  89. static inline struct scatterlist *esp_req_sg(struct crypto_aead *aead,
  90. struct aead_request *req)
  91. {
  92. return (void *)ALIGN((unsigned long)(req + 1) +
  93. crypto_aead_reqsize(aead),
  94. __alignof__(struct scatterlist));
  95. }
  96. static void esp_ssg_unref(struct xfrm_state *x, void *tmp)
  97. {
  98. struct crypto_aead *aead = x->data;
  99. int extralen = 0;
  100. u8 *iv;
  101. struct aead_request *req;
  102. struct scatterlist *sg;
  103. if (x->props.flags & XFRM_STATE_ESN)
  104. extralen += sizeof(struct esp_output_extra);
  105. iv = esp_tmp_iv(aead, tmp, extralen);
  106. req = esp_tmp_req(aead, iv);
  107. /* Unref skb_frag_pages in the src scatterlist if necessary.
  108. * Skip the first sg which comes from skb->data.
  109. */
  110. if (req->src != req->dst)
  111. for (sg = sg_next(req->src); sg; sg = sg_next(sg))
  112. put_page(sg_page(sg));
  113. }
  114. #ifdef CONFIG_INET6_ESPINTCP
  115. struct esp_tcp_sk {
  116. struct sock *sk;
  117. struct rcu_head rcu;
  118. };
  119. static void esp_free_tcp_sk(struct rcu_head *head)
  120. {
  121. struct esp_tcp_sk *esk = container_of(head, struct esp_tcp_sk, rcu);
  122. sock_put(esk->sk);
  123. kfree(esk);
  124. }
  125. static struct sock *esp6_find_tcp_sk(struct xfrm_state *x)
  126. {
  127. struct xfrm_encap_tmpl *encap = x->encap;
  128. struct net *net = xs_net(x);
  129. struct esp_tcp_sk *esk;
  130. __be16 sport, dport;
  131. struct sock *nsk;
  132. struct sock *sk;
  133. sk = rcu_dereference(x->encap_sk);
  134. if (sk && sk->sk_state == TCP_ESTABLISHED)
  135. return sk;
  136. spin_lock_bh(&x->lock);
  137. sport = encap->encap_sport;
  138. dport = encap->encap_dport;
  139. nsk = rcu_dereference_protected(x->encap_sk,
  140. lockdep_is_held(&x->lock));
  141. if (sk && sk == nsk) {
  142. esk = kmalloc(sizeof(*esk), GFP_ATOMIC);
  143. if (!esk) {
  144. spin_unlock_bh(&x->lock);
  145. return ERR_PTR(-ENOMEM);
  146. }
  147. RCU_INIT_POINTER(x->encap_sk, NULL);
  148. esk->sk = sk;
  149. call_rcu(&esk->rcu, esp_free_tcp_sk);
  150. }
  151. spin_unlock_bh(&x->lock);
  152. sk = __inet6_lookup_established(net, net->ipv4.tcp_death_row.hashinfo, &x->id.daddr.in6,
  153. dport, &x->props.saddr.in6, ntohs(sport), 0, 0);
  154. if (!sk)
  155. return ERR_PTR(-ENOENT);
  156. if (!tcp_is_ulp_esp(sk)) {
  157. sock_put(sk);
  158. return ERR_PTR(-EINVAL);
  159. }
  160. spin_lock_bh(&x->lock);
  161. nsk = rcu_dereference_protected(x->encap_sk,
  162. lockdep_is_held(&x->lock));
  163. if (encap->encap_sport != sport ||
  164. encap->encap_dport != dport) {
  165. sock_put(sk);
  166. sk = nsk ?: ERR_PTR(-EREMCHG);
  167. } else if (sk == nsk) {
  168. sock_put(sk);
  169. } else {
  170. rcu_assign_pointer(x->encap_sk, sk);
  171. }
  172. spin_unlock_bh(&x->lock);
  173. return sk;
  174. }
  175. static int esp_output_tcp_finish(struct xfrm_state *x, struct sk_buff *skb)
  176. {
  177. struct sock *sk;
  178. int err;
  179. rcu_read_lock();
  180. sk = esp6_find_tcp_sk(x);
  181. err = PTR_ERR_OR_ZERO(sk);
  182. if (err)
  183. goto out;
  184. bh_lock_sock(sk);
  185. if (sock_owned_by_user(sk))
  186. err = espintcp_queue_out(sk, skb);
  187. else
  188. err = espintcp_push_skb(sk, skb);
  189. bh_unlock_sock(sk);
  190. out:
  191. rcu_read_unlock();
  192. return err;
  193. }
  194. static int esp_output_tcp_encap_cb(struct net *net, struct sock *sk,
  195. struct sk_buff *skb)
  196. {
  197. struct dst_entry *dst = skb_dst(skb);
  198. struct xfrm_state *x = dst->xfrm;
  199. return esp_output_tcp_finish(x, skb);
  200. }
  201. static int esp_output_tail_tcp(struct xfrm_state *x, struct sk_buff *skb)
  202. {
  203. int err;
  204. local_bh_disable();
  205. err = xfrm_trans_queue_net(xs_net(x), skb, esp_output_tcp_encap_cb);
  206. local_bh_enable();
  207. /* EINPROGRESS just happens to do the right thing. It
  208. * actually means that the skb has been consumed and
  209. * isn't coming back.
  210. */
  211. return err ?: -EINPROGRESS;
  212. }
  213. #else
  214. static int esp_output_tail_tcp(struct xfrm_state *x, struct sk_buff *skb)
  215. {
  216. kfree_skb(skb);
  217. return -EOPNOTSUPP;
  218. }
  219. #endif
  220. static void esp_output_encap_csum(struct sk_buff *skb)
  221. {
  222. /* UDP encap with IPv6 requires a valid checksum */
  223. if (*skb_mac_header(skb) == IPPROTO_UDP) {
  224. struct udphdr *uh = udp_hdr(skb);
  225. struct ipv6hdr *ip6h = ipv6_hdr(skb);
  226. int len = ntohs(uh->len);
  227. unsigned int offset = skb_transport_offset(skb);
  228. __wsum csum = skb_checksum(skb, offset, skb->len - offset, 0);
  229. uh->check = csum_ipv6_magic(&ip6h->saddr, &ip6h->daddr,
  230. len, IPPROTO_UDP, csum);
  231. if (uh->check == 0)
  232. uh->check = CSUM_MANGLED_0;
  233. }
  234. }
  235. static void esp_output_done(struct crypto_async_request *base, int err)
  236. {
  237. struct sk_buff *skb = base->data;
  238. struct xfrm_offload *xo = xfrm_offload(skb);
  239. void *tmp;
  240. struct xfrm_state *x;
  241. if (xo && (xo->flags & XFRM_DEV_RESUME)) {
  242. struct sec_path *sp = skb_sec_path(skb);
  243. x = sp->xvec[sp->len - 1];
  244. } else {
  245. x = skb_dst(skb)->xfrm;
  246. }
  247. tmp = ESP_SKB_CB(skb)->tmp;
  248. esp_ssg_unref(x, tmp);
  249. kfree(tmp);
  250. esp_output_encap_csum(skb);
  251. if (xo && (xo->flags & XFRM_DEV_RESUME)) {
  252. if (err) {
  253. XFRM_INC_STATS(xs_net(x), LINUX_MIB_XFRMOUTSTATEPROTOERROR);
  254. kfree_skb(skb);
  255. return;
  256. }
  257. skb_push(skb, skb->data - skb_mac_header(skb));
  258. secpath_reset(skb);
  259. xfrm_dev_resume(skb);
  260. } else {
  261. if (!err &&
  262. x->encap && x->encap->encap_type == TCP_ENCAP_ESPINTCP)
  263. esp_output_tail_tcp(x, skb);
  264. else
  265. xfrm_output_resume(skb->sk, skb, err);
  266. }
  267. }
  268. /* Move ESP header back into place. */
  269. static void esp_restore_header(struct sk_buff *skb, unsigned int offset)
  270. {
  271. struct ip_esp_hdr *esph = (void *)(skb->data + offset);
  272. void *tmp = ESP_SKB_CB(skb)->tmp;
  273. __be32 *seqhi = esp_tmp_extra(tmp);
  274. esph->seq_no = esph->spi;
  275. esph->spi = *seqhi;
  276. }
  277. static void esp_output_restore_header(struct sk_buff *skb)
  278. {
  279. void *tmp = ESP_SKB_CB(skb)->tmp;
  280. struct esp_output_extra *extra = esp_tmp_extra(tmp);
  281. esp_restore_header(skb, skb_transport_offset(skb) + extra->esphoff -
  282. sizeof(__be32));
  283. }
  284. static struct ip_esp_hdr *esp_output_set_esn(struct sk_buff *skb,
  285. struct xfrm_state *x,
  286. struct ip_esp_hdr *esph,
  287. struct esp_output_extra *extra)
  288. {
  289. /* For ESN we move the header forward by 4 bytes to
  290. * accommodate the high bits. We will move it back after
  291. * encryption.
  292. */
  293. if ((x->props.flags & XFRM_STATE_ESN)) {
  294. __u32 seqhi;
  295. struct xfrm_offload *xo = xfrm_offload(skb);
  296. if (xo)
  297. seqhi = xo->seq.hi;
  298. else
  299. seqhi = XFRM_SKB_CB(skb)->seq.output.hi;
  300. extra->esphoff = (unsigned char *)esph -
  301. skb_transport_header(skb);
  302. esph = (struct ip_esp_hdr *)((unsigned char *)esph - 4);
  303. extra->seqhi = esph->spi;
  304. esph->seq_no = htonl(seqhi);
  305. }
  306. esph->spi = x->id.spi;
  307. return esph;
  308. }
  309. static void esp_output_done_esn(struct crypto_async_request *base, int err)
  310. {
  311. struct sk_buff *skb = base->data;
  312. esp_output_restore_header(skb);
  313. esp_output_done(base, err);
  314. }
  315. static struct ip_esp_hdr *esp6_output_udp_encap(struct sk_buff *skb,
  316. int encap_type,
  317. struct esp_info *esp,
  318. __be16 sport,
  319. __be16 dport)
  320. {
  321. struct udphdr *uh;
  322. __be32 *udpdata32;
  323. unsigned int len;
  324. len = skb->len + esp->tailen - skb_transport_offset(skb);
  325. if (len > U16_MAX)
  326. return ERR_PTR(-EMSGSIZE);
  327. uh = (struct udphdr *)esp->esph;
  328. uh->source = sport;
  329. uh->dest = dport;
  330. uh->len = htons(len);
  331. uh->check = 0;
  332. *skb_mac_header(skb) = IPPROTO_UDP;
  333. if (encap_type == UDP_ENCAP_ESPINUDP_NON_IKE) {
  334. udpdata32 = (__be32 *)(uh + 1);
  335. udpdata32[0] = udpdata32[1] = 0;
  336. return (struct ip_esp_hdr *)(udpdata32 + 2);
  337. }
  338. return (struct ip_esp_hdr *)(uh + 1);
  339. }
  340. #ifdef CONFIG_INET6_ESPINTCP
  341. static struct ip_esp_hdr *esp6_output_tcp_encap(struct xfrm_state *x,
  342. struct sk_buff *skb,
  343. struct esp_info *esp)
  344. {
  345. __be16 *lenp = (void *)esp->esph;
  346. struct ip_esp_hdr *esph;
  347. unsigned int len;
  348. struct sock *sk;
  349. len = skb->len + esp->tailen - skb_transport_offset(skb);
  350. if (len > IP_MAX_MTU)
  351. return ERR_PTR(-EMSGSIZE);
  352. rcu_read_lock();
  353. sk = esp6_find_tcp_sk(x);
  354. rcu_read_unlock();
  355. if (IS_ERR(sk))
  356. return ERR_CAST(sk);
  357. *lenp = htons(len);
  358. esph = (struct ip_esp_hdr *)(lenp + 1);
  359. return esph;
  360. }
  361. #else
  362. static struct ip_esp_hdr *esp6_output_tcp_encap(struct xfrm_state *x,
  363. struct sk_buff *skb,
  364. struct esp_info *esp)
  365. {
  366. return ERR_PTR(-EOPNOTSUPP);
  367. }
  368. #endif
  369. static int esp6_output_encap(struct xfrm_state *x, struct sk_buff *skb,
  370. struct esp_info *esp)
  371. {
  372. struct xfrm_encap_tmpl *encap = x->encap;
  373. struct ip_esp_hdr *esph;
  374. __be16 sport, dport;
  375. int encap_type;
  376. spin_lock_bh(&x->lock);
  377. sport = encap->encap_sport;
  378. dport = encap->encap_dport;
  379. encap_type = encap->encap_type;
  380. spin_unlock_bh(&x->lock);
  381. switch (encap_type) {
  382. default:
  383. case UDP_ENCAP_ESPINUDP:
  384. case UDP_ENCAP_ESPINUDP_NON_IKE:
  385. esph = esp6_output_udp_encap(skb, encap_type, esp, sport, dport);
  386. break;
  387. case TCP_ENCAP_ESPINTCP:
  388. esph = esp6_output_tcp_encap(x, skb, esp);
  389. break;
  390. }
  391. if (IS_ERR(esph))
  392. return PTR_ERR(esph);
  393. esp->esph = esph;
  394. return 0;
  395. }
  396. int esp6_output_head(struct xfrm_state *x, struct sk_buff *skb, struct esp_info *esp)
  397. {
  398. u8 *tail;
  399. int nfrags;
  400. int esph_offset;
  401. struct page *page;
  402. struct sk_buff *trailer;
  403. int tailen = esp->tailen;
  404. if (x->encap) {
  405. int err = esp6_output_encap(x, skb, esp);
  406. if (err < 0)
  407. return err;
  408. }
  409. if (ALIGN(tailen, L1_CACHE_BYTES) > PAGE_SIZE ||
  410. ALIGN(skb->data_len, L1_CACHE_BYTES) > PAGE_SIZE)
  411. goto cow;
  412. if (!skb_cloned(skb)) {
  413. if (tailen <= skb_tailroom(skb)) {
  414. nfrags = 1;
  415. trailer = skb;
  416. tail = skb_tail_pointer(trailer);
  417. goto skip_cow;
  418. } else if ((skb_shinfo(skb)->nr_frags < MAX_SKB_FRAGS)
  419. && !skb_has_frag_list(skb)) {
  420. int allocsize;
  421. struct sock *sk = skb->sk;
  422. struct page_frag *pfrag = &x->xfrag;
  423. esp->inplace = false;
  424. allocsize = ALIGN(tailen, L1_CACHE_BYTES);
  425. spin_lock_bh(&x->lock);
  426. if (unlikely(!skb_page_frag_refill(allocsize, pfrag, GFP_ATOMIC))) {
  427. spin_unlock_bh(&x->lock);
  428. goto cow;
  429. }
  430. page = pfrag->page;
  431. get_page(page);
  432. tail = page_address(page) + pfrag->offset;
  433. esp_output_fill_trailer(tail, esp->tfclen, esp->plen, esp->proto);
  434. nfrags = skb_shinfo(skb)->nr_frags;
  435. __skb_fill_page_desc(skb, nfrags, page, pfrag->offset,
  436. tailen);
  437. skb_shinfo(skb)->nr_frags = ++nfrags;
  438. pfrag->offset = pfrag->offset + allocsize;
  439. spin_unlock_bh(&x->lock);
  440. nfrags++;
  441. skb->len += tailen;
  442. skb->data_len += tailen;
  443. skb->truesize += tailen;
  444. if (sk && sk_fullsock(sk))
  445. refcount_add(tailen, &sk->sk_wmem_alloc);
  446. goto out;
  447. }
  448. }
  449. cow:
  450. esph_offset = (unsigned char *)esp->esph - skb_transport_header(skb);
  451. nfrags = skb_cow_data(skb, tailen, &trailer);
  452. if (nfrags < 0)
  453. goto out;
  454. tail = skb_tail_pointer(trailer);
  455. esp->esph = (struct ip_esp_hdr *)(skb_transport_header(skb) + esph_offset);
  456. skip_cow:
  457. esp_output_fill_trailer(tail, esp->tfclen, esp->plen, esp->proto);
  458. pskb_put(skb, trailer, tailen);
  459. out:
  460. return nfrags;
  461. }
  462. EXPORT_SYMBOL_GPL(esp6_output_head);
  463. int esp6_output_tail(struct xfrm_state *x, struct sk_buff *skb, struct esp_info *esp)
  464. {
  465. u8 *iv;
  466. int alen;
  467. void *tmp;
  468. int ivlen;
  469. int assoclen;
  470. int extralen;
  471. struct page *page;
  472. struct ip_esp_hdr *esph;
  473. struct aead_request *req;
  474. struct crypto_aead *aead;
  475. struct scatterlist *sg, *dsg;
  476. struct esp_output_extra *extra;
  477. int err = -ENOMEM;
  478. assoclen = sizeof(struct ip_esp_hdr);
  479. extralen = 0;
  480. if (x->props.flags & XFRM_STATE_ESN) {
  481. extralen += sizeof(*extra);
  482. assoclen += sizeof(__be32);
  483. }
  484. aead = x->data;
  485. alen = crypto_aead_authsize(aead);
  486. ivlen = crypto_aead_ivsize(aead);
  487. tmp = esp_alloc_tmp(aead, esp->nfrags + 2, extralen);
  488. if (!tmp)
  489. goto error;
  490. extra = esp_tmp_extra(tmp);
  491. iv = esp_tmp_iv(aead, tmp, extralen);
  492. req = esp_tmp_req(aead, iv);
  493. sg = esp_req_sg(aead, req);
  494. if (esp->inplace)
  495. dsg = sg;
  496. else
  497. dsg = &sg[esp->nfrags];
  498. esph = esp_output_set_esn(skb, x, esp->esph, extra);
  499. esp->esph = esph;
  500. sg_init_table(sg, esp->nfrags);
  501. err = skb_to_sgvec(skb, sg,
  502. (unsigned char *)esph - skb->data,
  503. assoclen + ivlen + esp->clen + alen);
  504. if (unlikely(err < 0))
  505. goto error_free;
  506. if (!esp->inplace) {
  507. int allocsize;
  508. struct page_frag *pfrag = &x->xfrag;
  509. allocsize = ALIGN(skb->data_len, L1_CACHE_BYTES);
  510. spin_lock_bh(&x->lock);
  511. if (unlikely(!skb_page_frag_refill(allocsize, pfrag, GFP_ATOMIC))) {
  512. spin_unlock_bh(&x->lock);
  513. goto error_free;
  514. }
  515. skb_shinfo(skb)->nr_frags = 1;
  516. page = pfrag->page;
  517. get_page(page);
  518. /* replace page frags in skb with new page */
  519. __skb_fill_page_desc(skb, 0, page, pfrag->offset, skb->data_len);
  520. pfrag->offset = pfrag->offset + allocsize;
  521. spin_unlock_bh(&x->lock);
  522. sg_init_table(dsg, skb_shinfo(skb)->nr_frags + 1);
  523. err = skb_to_sgvec(skb, dsg,
  524. (unsigned char *)esph - skb->data,
  525. assoclen + ivlen + esp->clen + alen);
  526. if (unlikely(err < 0))
  527. goto error_free;
  528. }
  529. if ((x->props.flags & XFRM_STATE_ESN))
  530. aead_request_set_callback(req, 0, esp_output_done_esn, skb);
  531. else
  532. aead_request_set_callback(req, 0, esp_output_done, skb);
  533. aead_request_set_crypt(req, sg, dsg, ivlen + esp->clen, iv);
  534. aead_request_set_ad(req, assoclen);
  535. memset(iv, 0, ivlen);
  536. memcpy(iv + ivlen - min(ivlen, 8), (u8 *)&esp->seqno + 8 - min(ivlen, 8),
  537. min(ivlen, 8));
  538. ESP_SKB_CB(skb)->tmp = tmp;
  539. err = crypto_aead_encrypt(req);
  540. switch (err) {
  541. case -EINPROGRESS:
  542. goto error;
  543. case -ENOSPC:
  544. err = NET_XMIT_DROP;
  545. break;
  546. case 0:
  547. if ((x->props.flags & XFRM_STATE_ESN))
  548. esp_output_restore_header(skb);
  549. esp_output_encap_csum(skb);
  550. }
  551. if (sg != dsg)
  552. esp_ssg_unref(x, tmp);
  553. if (!err && x->encap && x->encap->encap_type == TCP_ENCAP_ESPINTCP)
  554. err = esp_output_tail_tcp(x, skb);
  555. error_free:
  556. kfree(tmp);
  557. error:
  558. return err;
  559. }
  560. EXPORT_SYMBOL_GPL(esp6_output_tail);
  561. static int esp6_output(struct xfrm_state *x, struct sk_buff *skb)
  562. {
  563. int alen;
  564. int blksize;
  565. struct ip_esp_hdr *esph;
  566. struct crypto_aead *aead;
  567. struct esp_info esp;
  568. esp.inplace = true;
  569. esp.proto = *skb_mac_header(skb);
  570. *skb_mac_header(skb) = IPPROTO_ESP;
  571. /* skb is pure payload to encrypt */
  572. aead = x->data;
  573. alen = crypto_aead_authsize(aead);
  574. esp.tfclen = 0;
  575. if (x->tfcpad) {
  576. struct xfrm_dst *dst = (struct xfrm_dst *)skb_dst(skb);
  577. u32 padto;
  578. padto = min(x->tfcpad, xfrm_state_mtu(x, dst->child_mtu_cached));
  579. if (skb->len < padto)
  580. esp.tfclen = padto - skb->len;
  581. }
  582. blksize = ALIGN(crypto_aead_blocksize(aead), 4);
  583. esp.clen = ALIGN(skb->len + 2 + esp.tfclen, blksize);
  584. esp.plen = esp.clen - skb->len - esp.tfclen;
  585. esp.tailen = esp.tfclen + esp.plen + alen;
  586. esp.esph = ip_esp_hdr(skb);
  587. esp.nfrags = esp6_output_head(x, skb, &esp);
  588. if (esp.nfrags < 0)
  589. return esp.nfrags;
  590. esph = esp.esph;
  591. esph->spi = x->id.spi;
  592. esph->seq_no = htonl(XFRM_SKB_CB(skb)->seq.output.low);
  593. esp.seqno = cpu_to_be64(XFRM_SKB_CB(skb)->seq.output.low +
  594. ((u64)XFRM_SKB_CB(skb)->seq.output.hi << 32));
  595. skb_push(skb, -skb_network_offset(skb));
  596. return esp6_output_tail(x, skb, &esp);
  597. }
  598. static inline int esp_remove_trailer(struct sk_buff *skb)
  599. {
  600. struct xfrm_state *x = xfrm_input_state(skb);
  601. struct crypto_aead *aead = x->data;
  602. int alen, hlen, elen;
  603. int padlen, trimlen;
  604. __wsum csumdiff;
  605. u8 nexthdr[2];
  606. int ret;
  607. alen = crypto_aead_authsize(aead);
  608. hlen = sizeof(struct ip_esp_hdr) + crypto_aead_ivsize(aead);
  609. elen = skb->len - hlen;
  610. ret = skb_copy_bits(skb, skb->len - alen - 2, nexthdr, 2);
  611. BUG_ON(ret);
  612. ret = -EINVAL;
  613. padlen = nexthdr[0];
  614. if (padlen + 2 + alen >= elen) {
  615. net_dbg_ratelimited("ipsec esp packet is garbage padlen=%d, elen=%d\n",
  616. padlen + 2, elen - alen);
  617. goto out;
  618. }
  619. trimlen = alen + padlen + 2;
  620. if (skb->ip_summed == CHECKSUM_COMPLETE) {
  621. csumdiff = skb_checksum(skb, skb->len - trimlen, trimlen, 0);
  622. skb->csum = csum_block_sub(skb->csum, csumdiff,
  623. skb->len - trimlen);
  624. }
  625. ret = pskb_trim(skb, skb->len - trimlen);
  626. if (unlikely(ret))
  627. return ret;
  628. ret = nexthdr[1];
  629. out:
  630. return ret;
  631. }
  632. int esp6_input_done2(struct sk_buff *skb, int err)
  633. {
  634. struct xfrm_state *x = xfrm_input_state(skb);
  635. struct xfrm_offload *xo = xfrm_offload(skb);
  636. struct crypto_aead *aead = x->data;
  637. int hlen = sizeof(struct ip_esp_hdr) + crypto_aead_ivsize(aead);
  638. int hdr_len = skb_network_header_len(skb);
  639. if (!xo || !(xo->flags & CRYPTO_DONE))
  640. kfree(ESP_SKB_CB(skb)->tmp);
  641. if (unlikely(err))
  642. goto out;
  643. err = esp_remove_trailer(skb);
  644. if (unlikely(err < 0))
  645. goto out;
  646. if (x->encap) {
  647. const struct ipv6hdr *ip6h = ipv6_hdr(skb);
  648. int offset = skb_network_offset(skb) + sizeof(*ip6h);
  649. struct xfrm_encap_tmpl *encap = x->encap;
  650. u8 nexthdr = ip6h->nexthdr;
  651. __be16 frag_off, source;
  652. struct udphdr *uh;
  653. struct tcphdr *th;
  654. offset = ipv6_skip_exthdr(skb, offset, &nexthdr, &frag_off);
  655. if (offset == -1) {
  656. err = -EINVAL;
  657. goto out;
  658. }
  659. uh = (void *)(skb->data + offset);
  660. th = (void *)(skb->data + offset);
  661. hdr_len += offset;
  662. switch (x->encap->encap_type) {
  663. case TCP_ENCAP_ESPINTCP:
  664. source = th->source;
  665. break;
  666. case UDP_ENCAP_ESPINUDP:
  667. case UDP_ENCAP_ESPINUDP_NON_IKE:
  668. source = uh->source;
  669. break;
  670. default:
  671. WARN_ON_ONCE(1);
  672. err = -EINVAL;
  673. goto out;
  674. }
  675. /*
  676. * 1) if the NAT-T peer's IP or port changed then
  677. * advertize the change to the keying daemon.
  678. * This is an inbound SA, so just compare
  679. * SRC ports.
  680. */
  681. if (!ipv6_addr_equal(&ip6h->saddr, &x->props.saddr.in6) ||
  682. source != encap->encap_sport) {
  683. xfrm_address_t ipaddr;
  684. memcpy(&ipaddr.a6, &ip6h->saddr.s6_addr, sizeof(ipaddr.a6));
  685. km_new_mapping(x, &ipaddr, source);
  686. /* XXX: perhaps add an extra
  687. * policy check here, to see
  688. * if we should allow or
  689. * reject a packet from a
  690. * different source
  691. * address/port.
  692. */
  693. }
  694. /*
  695. * 2) ignore UDP/TCP checksums in case
  696. * of NAT-T in Transport Mode, or
  697. * perform other post-processing fixes
  698. * as per draft-ietf-ipsec-udp-encaps-06,
  699. * section 3.1.2
  700. */
  701. if (x->props.mode == XFRM_MODE_TRANSPORT)
  702. skb->ip_summed = CHECKSUM_UNNECESSARY;
  703. }
  704. skb_postpull_rcsum(skb, skb_network_header(skb),
  705. skb_network_header_len(skb));
  706. skb_pull_rcsum(skb, hlen);
  707. if (x->props.mode == XFRM_MODE_TUNNEL)
  708. skb_reset_transport_header(skb);
  709. else
  710. skb_set_transport_header(skb, -hdr_len);
  711. /* RFC4303: Drop dummy packets without any error */
  712. if (err == IPPROTO_NONE)
  713. err = -EINVAL;
  714. out:
  715. return err;
  716. }
  717. EXPORT_SYMBOL_GPL(esp6_input_done2);
  718. static void esp_input_done(struct crypto_async_request *base, int err)
  719. {
  720. struct sk_buff *skb = base->data;
  721. xfrm_input_resume(skb, esp6_input_done2(skb, err));
  722. }
  723. static void esp_input_restore_header(struct sk_buff *skb)
  724. {
  725. esp_restore_header(skb, 0);
  726. __skb_pull(skb, 4);
  727. }
  728. static void esp_input_set_header(struct sk_buff *skb, __be32 *seqhi)
  729. {
  730. struct xfrm_state *x = xfrm_input_state(skb);
  731. /* For ESN we move the header forward by 4 bytes to
  732. * accommodate the high bits. We will move it back after
  733. * decryption.
  734. */
  735. if ((x->props.flags & XFRM_STATE_ESN)) {
  736. struct ip_esp_hdr *esph = skb_push(skb, 4);
  737. *seqhi = esph->spi;
  738. esph->spi = esph->seq_no;
  739. esph->seq_no = XFRM_SKB_CB(skb)->seq.input.hi;
  740. }
  741. }
  742. static void esp_input_done_esn(struct crypto_async_request *base, int err)
  743. {
  744. struct sk_buff *skb = base->data;
  745. esp_input_restore_header(skb);
  746. esp_input_done(base, err);
  747. }
  748. static int esp6_input(struct xfrm_state *x, struct sk_buff *skb)
  749. {
  750. struct crypto_aead *aead = x->data;
  751. struct aead_request *req;
  752. struct sk_buff *trailer;
  753. int ivlen = crypto_aead_ivsize(aead);
  754. int elen = skb->len - sizeof(struct ip_esp_hdr) - ivlen;
  755. int nfrags;
  756. int assoclen;
  757. int seqhilen;
  758. int ret = 0;
  759. void *tmp;
  760. __be32 *seqhi;
  761. u8 *iv;
  762. struct scatterlist *sg;
  763. if (!pskb_may_pull(skb, sizeof(struct ip_esp_hdr) + ivlen)) {
  764. ret = -EINVAL;
  765. goto out;
  766. }
  767. if (elen <= 0) {
  768. ret = -EINVAL;
  769. goto out;
  770. }
  771. assoclen = sizeof(struct ip_esp_hdr);
  772. seqhilen = 0;
  773. if (x->props.flags & XFRM_STATE_ESN) {
  774. seqhilen += sizeof(__be32);
  775. assoclen += seqhilen;
  776. }
  777. if (!skb_cloned(skb)) {
  778. if (!skb_is_nonlinear(skb)) {
  779. nfrags = 1;
  780. goto skip_cow;
  781. } else if (!skb_has_frag_list(skb)) {
  782. nfrags = skb_shinfo(skb)->nr_frags;
  783. nfrags++;
  784. goto skip_cow;
  785. }
  786. }
  787. nfrags = skb_cow_data(skb, 0, &trailer);
  788. if (nfrags < 0) {
  789. ret = -EINVAL;
  790. goto out;
  791. }
  792. skip_cow:
  793. ret = -ENOMEM;
  794. tmp = esp_alloc_tmp(aead, nfrags, seqhilen);
  795. if (!tmp)
  796. goto out;
  797. ESP_SKB_CB(skb)->tmp = tmp;
  798. seqhi = esp_tmp_extra(tmp);
  799. iv = esp_tmp_iv(aead, tmp, seqhilen);
  800. req = esp_tmp_req(aead, iv);
  801. sg = esp_req_sg(aead, req);
  802. esp_input_set_header(skb, seqhi);
  803. sg_init_table(sg, nfrags);
  804. ret = skb_to_sgvec(skb, sg, 0, skb->len);
  805. if (unlikely(ret < 0)) {
  806. kfree(tmp);
  807. goto out;
  808. }
  809. skb->ip_summed = CHECKSUM_NONE;
  810. if ((x->props.flags & XFRM_STATE_ESN))
  811. aead_request_set_callback(req, 0, esp_input_done_esn, skb);
  812. else
  813. aead_request_set_callback(req, 0, esp_input_done, skb);
  814. aead_request_set_crypt(req, sg, sg, elen + ivlen, iv);
  815. aead_request_set_ad(req, assoclen);
  816. ret = crypto_aead_decrypt(req);
  817. if (ret == -EINPROGRESS)
  818. goto out;
  819. if ((x->props.flags & XFRM_STATE_ESN))
  820. esp_input_restore_header(skb);
  821. ret = esp6_input_done2(skb, ret);
  822. out:
  823. return ret;
  824. }
  825. static int esp6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
  826. u8 type, u8 code, int offset, __be32 info)
  827. {
  828. struct net *net = dev_net(skb->dev);
  829. const struct ipv6hdr *iph = (const struct ipv6hdr *)skb->data;
  830. struct ip_esp_hdr *esph = (struct ip_esp_hdr *)(skb->data + offset);
  831. struct xfrm_state *x;
  832. if (type != ICMPV6_PKT_TOOBIG &&
  833. type != NDISC_REDIRECT)
  834. return 0;
  835. x = xfrm_state_lookup(net, skb->mark, (const xfrm_address_t *)&iph->daddr,
  836. esph->spi, IPPROTO_ESP, AF_INET6);
  837. if (!x)
  838. return 0;
  839. if (type == NDISC_REDIRECT)
  840. ip6_redirect(skb, net, skb->dev->ifindex, 0,
  841. sock_net_uid(net, NULL));
  842. else
  843. ip6_update_pmtu(skb, net, info, 0, 0, sock_net_uid(net, NULL));
  844. xfrm_state_put(x);
  845. return 0;
  846. }
  847. static void esp6_destroy(struct xfrm_state *x)
  848. {
  849. struct crypto_aead *aead = x->data;
  850. if (!aead)
  851. return;
  852. crypto_free_aead(aead);
  853. }
  854. static int esp_init_aead(struct xfrm_state *x, struct netlink_ext_ack *extack)
  855. {
  856. char aead_name[CRYPTO_MAX_ALG_NAME];
  857. struct crypto_aead *aead;
  858. int err;
  859. if (snprintf(aead_name, CRYPTO_MAX_ALG_NAME, "%s(%s)",
  860. x->geniv, x->aead->alg_name) >= CRYPTO_MAX_ALG_NAME) {
  861. NL_SET_ERR_MSG(extack, "Algorithm name is too long");
  862. return -ENAMETOOLONG;
  863. }
  864. aead = crypto_alloc_aead(aead_name, 0, 0);
  865. err = PTR_ERR(aead);
  866. if (IS_ERR(aead))
  867. goto error;
  868. x->data = aead;
  869. err = crypto_aead_setkey(aead, x->aead->alg_key,
  870. (x->aead->alg_key_len + 7) / 8);
  871. if (err)
  872. goto error;
  873. err = crypto_aead_setauthsize(aead, x->aead->alg_icv_len / 8);
  874. if (err)
  875. goto error;
  876. return 0;
  877. error:
  878. NL_SET_ERR_MSG(extack, "Kernel was unable to initialize cryptographic operations");
  879. return err;
  880. }
  881. static int esp_init_authenc(struct xfrm_state *x,
  882. struct netlink_ext_ack *extack)
  883. {
  884. struct crypto_aead *aead;
  885. struct crypto_authenc_key_param *param;
  886. struct rtattr *rta;
  887. char *key;
  888. char *p;
  889. char authenc_name[CRYPTO_MAX_ALG_NAME];
  890. unsigned int keylen;
  891. int err;
  892. err = -ENAMETOOLONG;
  893. if ((x->props.flags & XFRM_STATE_ESN)) {
  894. if (snprintf(authenc_name, CRYPTO_MAX_ALG_NAME,
  895. "%s%sauthencesn(%s,%s)%s",
  896. x->geniv ?: "", x->geniv ? "(" : "",
  897. x->aalg ? x->aalg->alg_name : "digest_null",
  898. x->ealg->alg_name,
  899. x->geniv ? ")" : "") >= CRYPTO_MAX_ALG_NAME) {
  900. NL_SET_ERR_MSG(extack, "Algorithm name is too long");
  901. goto error;
  902. }
  903. } else {
  904. if (snprintf(authenc_name, CRYPTO_MAX_ALG_NAME,
  905. "%s%sauthenc(%s,%s)%s",
  906. x->geniv ?: "", x->geniv ? "(" : "",
  907. x->aalg ? x->aalg->alg_name : "digest_null",
  908. x->ealg->alg_name,
  909. x->geniv ? ")" : "") >= CRYPTO_MAX_ALG_NAME) {
  910. NL_SET_ERR_MSG(extack, "Algorithm name is too long");
  911. goto error;
  912. }
  913. }
  914. aead = crypto_alloc_aead(authenc_name, 0, 0);
  915. err = PTR_ERR(aead);
  916. if (IS_ERR(aead)) {
  917. NL_SET_ERR_MSG(extack, "Kernel was unable to initialize cryptographic operations");
  918. goto error;
  919. }
  920. x->data = aead;
  921. keylen = (x->aalg ? (x->aalg->alg_key_len + 7) / 8 : 0) +
  922. (x->ealg->alg_key_len + 7) / 8 + RTA_SPACE(sizeof(*param));
  923. err = -ENOMEM;
  924. key = kmalloc(keylen, GFP_KERNEL);
  925. if (!key)
  926. goto error;
  927. p = key;
  928. rta = (void *)p;
  929. rta->rta_type = CRYPTO_AUTHENC_KEYA_PARAM;
  930. rta->rta_len = RTA_LENGTH(sizeof(*param));
  931. param = RTA_DATA(rta);
  932. p += RTA_SPACE(sizeof(*param));
  933. if (x->aalg) {
  934. struct xfrm_algo_desc *aalg_desc;
  935. memcpy(p, x->aalg->alg_key, (x->aalg->alg_key_len + 7) / 8);
  936. p += (x->aalg->alg_key_len + 7) / 8;
  937. aalg_desc = xfrm_aalg_get_byname(x->aalg->alg_name, 0);
  938. BUG_ON(!aalg_desc);
  939. err = -EINVAL;
  940. if (aalg_desc->uinfo.auth.icv_fullbits / 8 !=
  941. crypto_aead_authsize(aead)) {
  942. NL_SET_ERR_MSG(extack, "Kernel was unable to initialize cryptographic operations");
  943. goto free_key;
  944. }
  945. err = crypto_aead_setauthsize(
  946. aead, x->aalg->alg_trunc_len / 8);
  947. if (err) {
  948. NL_SET_ERR_MSG(extack, "Kernel was unable to initialize cryptographic operations");
  949. goto free_key;
  950. }
  951. }
  952. param->enckeylen = cpu_to_be32((x->ealg->alg_key_len + 7) / 8);
  953. memcpy(p, x->ealg->alg_key, (x->ealg->alg_key_len + 7) / 8);
  954. err = crypto_aead_setkey(aead, key, keylen);
  955. free_key:
  956. kfree(key);
  957. error:
  958. return err;
  959. }
  960. static int esp6_init_state(struct xfrm_state *x, struct netlink_ext_ack *extack)
  961. {
  962. struct crypto_aead *aead;
  963. u32 align;
  964. int err;
  965. x->data = NULL;
  966. if (x->aead) {
  967. err = esp_init_aead(x, extack);
  968. } else if (x->ealg) {
  969. err = esp_init_authenc(x, extack);
  970. } else {
  971. NL_SET_ERR_MSG(extack, "ESP: AEAD or CRYPT must be provided");
  972. err = -EINVAL;
  973. }
  974. if (err)
  975. goto error;
  976. aead = x->data;
  977. x->props.header_len = sizeof(struct ip_esp_hdr) +
  978. crypto_aead_ivsize(aead);
  979. switch (x->props.mode) {
  980. case XFRM_MODE_BEET:
  981. if (x->sel.family != AF_INET6)
  982. x->props.header_len += IPV4_BEET_PHMAXLEN +
  983. (sizeof(struct ipv6hdr) - sizeof(struct iphdr));
  984. break;
  985. default:
  986. case XFRM_MODE_TRANSPORT:
  987. break;
  988. case XFRM_MODE_TUNNEL:
  989. x->props.header_len += sizeof(struct ipv6hdr);
  990. break;
  991. }
  992. if (x->encap) {
  993. struct xfrm_encap_tmpl *encap = x->encap;
  994. switch (encap->encap_type) {
  995. default:
  996. NL_SET_ERR_MSG(extack, "Unsupported encapsulation type for ESP");
  997. err = -EINVAL;
  998. goto error;
  999. case UDP_ENCAP_ESPINUDP:
  1000. x->props.header_len += sizeof(struct udphdr);
  1001. break;
  1002. case UDP_ENCAP_ESPINUDP_NON_IKE:
  1003. x->props.header_len += sizeof(struct udphdr) + 2 * sizeof(u32);
  1004. break;
  1005. #ifdef CONFIG_INET6_ESPINTCP
  1006. case TCP_ENCAP_ESPINTCP:
  1007. /* only the length field, TCP encap is done by
  1008. * the socket
  1009. */
  1010. x->props.header_len += 2;
  1011. break;
  1012. #endif
  1013. }
  1014. }
  1015. align = ALIGN(crypto_aead_blocksize(aead), 4);
  1016. x->props.trailer_len = align + 1 + crypto_aead_authsize(aead);
  1017. error:
  1018. return err;
  1019. }
  1020. static int esp6_rcv_cb(struct sk_buff *skb, int err)
  1021. {
  1022. return 0;
  1023. }
  1024. static const struct xfrm_type esp6_type = {
  1025. .owner = THIS_MODULE,
  1026. .proto = IPPROTO_ESP,
  1027. .flags = XFRM_TYPE_REPLAY_PROT,
  1028. .init_state = esp6_init_state,
  1029. .destructor = esp6_destroy,
  1030. .input = esp6_input,
  1031. .output = esp6_output,
  1032. };
  1033. static struct xfrm6_protocol esp6_protocol = {
  1034. .handler = xfrm6_rcv,
  1035. .input_handler = xfrm_input,
  1036. .cb_handler = esp6_rcv_cb,
  1037. .err_handler = esp6_err,
  1038. .priority = 0,
  1039. };
  1040. static int __init esp6_init(void)
  1041. {
  1042. if (xfrm_register_type(&esp6_type, AF_INET6) < 0) {
  1043. pr_info("%s: can't add xfrm type\n", __func__);
  1044. return -EAGAIN;
  1045. }
  1046. if (xfrm6_protocol_register(&esp6_protocol, IPPROTO_ESP) < 0) {
  1047. pr_info("%s: can't add protocol\n", __func__);
  1048. xfrm_unregister_type(&esp6_type, AF_INET6);
  1049. return -EAGAIN;
  1050. }
  1051. return 0;
  1052. }
  1053. static void __exit esp6_fini(void)
  1054. {
  1055. if (xfrm6_protocol_deregister(&esp6_protocol, IPPROTO_ESP) < 0)
  1056. pr_info("%s: can't remove protocol\n", __func__);
  1057. xfrm_unregister_type(&esp6_type, AF_INET6);
  1058. }
  1059. module_init(esp6_init);
  1060. module_exit(esp6_fini);
  1061. MODULE_LICENSE("GPL");
  1062. MODULE_ALIAS_XFRM_TYPE(AF_INET6, XFRM_PROTO_ESP);