xfrm_algo.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776
  1. /*
  2. * xfrm algorithm interface
  3. *
  4. * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the Free
  8. * Software Foundation; either version 2 of the License, or (at your option)
  9. * any later version.
  10. */
  11. #include <linux/module.h>
  12. #include <linux/kernel.h>
  13. #include <linux/pfkeyv2.h>
  14. #include <linux/crypto.h>
  15. #include <net/xfrm.h>
  16. #if defined(CONFIG_INET_AH) || defined(CONFIG_INET_AH_MODULE) || defined(CONFIG_INET6_AH) || defined(CONFIG_INET6_AH_MODULE)
  17. #include <net/ah.h>
  18. #endif
  19. #if defined(CONFIG_INET_ESP) || defined(CONFIG_INET_ESP_MODULE) || defined(CONFIG_INET6_ESP) || defined(CONFIG_INET6_ESP_MODULE)
  20. #include <net/esp.h>
  21. #endif
  22. #include <asm/scatterlist.h>
  23. /*
  24. * Algorithms supported by IPsec. These entries contain properties which
  25. * are used in key negotiation and xfrm processing, and are used to verify
  26. * that instantiated crypto transforms have correct parameters for IPsec
  27. * purposes.
  28. */
  29. static struct xfrm_algo_desc aalg_list[] = {
  30. {
  31. .name = "hmac(digest_null)",
  32. .compat = "digest_null",
  33. .uinfo = {
  34. .auth = {
  35. .icv_truncbits = 0,
  36. .icv_fullbits = 0,
  37. }
  38. },
  39. .desc = {
  40. .sadb_alg_id = SADB_X_AALG_NULL,
  41. .sadb_alg_ivlen = 0,
  42. .sadb_alg_minbits = 0,
  43. .sadb_alg_maxbits = 0
  44. }
  45. },
  46. {
  47. .name = "hmac(md5)",
  48. .compat = "md5",
  49. .uinfo = {
  50. .auth = {
  51. .icv_truncbits = 96,
  52. .icv_fullbits = 128,
  53. }
  54. },
  55. .desc = {
  56. .sadb_alg_id = SADB_AALG_MD5HMAC,
  57. .sadb_alg_ivlen = 0,
  58. .sadb_alg_minbits = 128,
  59. .sadb_alg_maxbits = 128
  60. }
  61. },
  62. {
  63. .name = "hmac(sha1)",
  64. .compat = "sha1",
  65. .uinfo = {
  66. .auth = {
  67. .icv_truncbits = 96,
  68. .icv_fullbits = 160,
  69. }
  70. },
  71. .desc = {
  72. .sadb_alg_id = SADB_AALG_SHA1HMAC,
  73. .sadb_alg_ivlen = 0,
  74. .sadb_alg_minbits = 160,
  75. .sadb_alg_maxbits = 160
  76. }
  77. },
  78. {
  79. .name = "hmac(sha256)",
  80. .compat = "sha256",
  81. .uinfo = {
  82. .auth = {
  83. .icv_truncbits = 96,
  84. .icv_fullbits = 256,
  85. }
  86. },
  87. .desc = {
  88. .sadb_alg_id = SADB_X_AALG_SHA2_256HMAC,
  89. .sadb_alg_ivlen = 0,
  90. .sadb_alg_minbits = 256,
  91. .sadb_alg_maxbits = 256
  92. }
  93. },
  94. {
  95. .name = "hmac(ripemd160)",
  96. .compat = "ripemd160",
  97. .uinfo = {
  98. .auth = {
  99. .icv_truncbits = 96,
  100. .icv_fullbits = 160,
  101. }
  102. },
  103. .desc = {
  104. .sadb_alg_id = SADB_X_AALG_RIPEMD160HMAC,
  105. .sadb_alg_ivlen = 0,
  106. .sadb_alg_minbits = 160,
  107. .sadb_alg_maxbits = 160
  108. }
  109. },
  110. {
  111. .name = "xcbc(aes)",
  112. .uinfo = {
  113. .auth = {
  114. .icv_truncbits = 96,
  115. .icv_fullbits = 128,
  116. }
  117. },
  118. .desc = {
  119. .sadb_alg_id = SADB_X_AALG_AES_XCBC_MAC,
  120. .sadb_alg_ivlen = 0,
  121. .sadb_alg_minbits = 128,
  122. .sadb_alg_maxbits = 128
  123. }
  124. },
  125. };
  126. static struct xfrm_algo_desc ealg_list[] = {
  127. {
  128. .name = "ecb(cipher_null)",
  129. .compat = "cipher_null",
  130. .uinfo = {
  131. .encr = {
  132. .blockbits = 8,
  133. .defkeybits = 0,
  134. }
  135. },
  136. .desc = {
  137. .sadb_alg_id = SADB_EALG_NULL,
  138. .sadb_alg_ivlen = 0,
  139. .sadb_alg_minbits = 0,
  140. .sadb_alg_maxbits = 0
  141. }
  142. },
  143. {
  144. .name = "cbc(des)",
  145. .compat = "des",
  146. .uinfo = {
  147. .encr = {
  148. .blockbits = 64,
  149. .defkeybits = 64,
  150. }
  151. },
  152. .desc = {
  153. .sadb_alg_id = SADB_EALG_DESCBC,
  154. .sadb_alg_ivlen = 8,
  155. .sadb_alg_minbits = 64,
  156. .sadb_alg_maxbits = 64
  157. }
  158. },
  159. {
  160. .name = "cbc(des3_ede)",
  161. .compat = "des3_ede",
  162. .uinfo = {
  163. .encr = {
  164. .blockbits = 64,
  165. .defkeybits = 192,
  166. }
  167. },
  168. .desc = {
  169. .sadb_alg_id = SADB_EALG_3DESCBC,
  170. .sadb_alg_ivlen = 8,
  171. .sadb_alg_minbits = 192,
  172. .sadb_alg_maxbits = 192
  173. }
  174. },
  175. {
  176. .name = "cbc(cast128)",
  177. .compat = "cast128",
  178. .uinfo = {
  179. .encr = {
  180. .blockbits = 64,
  181. .defkeybits = 128,
  182. }
  183. },
  184. .desc = {
  185. .sadb_alg_id = SADB_X_EALG_CASTCBC,
  186. .sadb_alg_ivlen = 8,
  187. .sadb_alg_minbits = 40,
  188. .sadb_alg_maxbits = 128
  189. }
  190. },
  191. {
  192. .name = "cbc(blowfish)",
  193. .compat = "blowfish",
  194. .uinfo = {
  195. .encr = {
  196. .blockbits = 64,
  197. .defkeybits = 128,
  198. }
  199. },
  200. .desc = {
  201. .sadb_alg_id = SADB_X_EALG_BLOWFISHCBC,
  202. .sadb_alg_ivlen = 8,
  203. .sadb_alg_minbits = 40,
  204. .sadb_alg_maxbits = 448
  205. }
  206. },
  207. {
  208. .name = "cbc(aes)",
  209. .compat = "aes",
  210. .uinfo = {
  211. .encr = {
  212. .blockbits = 128,
  213. .defkeybits = 128,
  214. }
  215. },
  216. .desc = {
  217. .sadb_alg_id = SADB_X_EALG_AESCBC,
  218. .sadb_alg_ivlen = 8,
  219. .sadb_alg_minbits = 128,
  220. .sadb_alg_maxbits = 256
  221. }
  222. },
  223. {
  224. .name = "cbc(serpent)",
  225. .compat = "serpent",
  226. .uinfo = {
  227. .encr = {
  228. .blockbits = 128,
  229. .defkeybits = 128,
  230. }
  231. },
  232. .desc = {
  233. .sadb_alg_id = SADB_X_EALG_SERPENTCBC,
  234. .sadb_alg_ivlen = 8,
  235. .sadb_alg_minbits = 128,
  236. .sadb_alg_maxbits = 256,
  237. }
  238. },
  239. {
  240. .name = "cbc(twofish)",
  241. .compat = "twofish",
  242. .uinfo = {
  243. .encr = {
  244. .blockbits = 128,
  245. .defkeybits = 128,
  246. }
  247. },
  248. .desc = {
  249. .sadb_alg_id = SADB_X_EALG_TWOFISHCBC,
  250. .sadb_alg_ivlen = 8,
  251. .sadb_alg_minbits = 128,
  252. .sadb_alg_maxbits = 256
  253. }
  254. },
  255. };
  256. static struct xfrm_algo_desc calg_list[] = {
  257. {
  258. .name = "deflate",
  259. .uinfo = {
  260. .comp = {
  261. .threshold = 90,
  262. }
  263. },
  264. .desc = { .sadb_alg_id = SADB_X_CALG_DEFLATE }
  265. },
  266. {
  267. .name = "lzs",
  268. .uinfo = {
  269. .comp = {
  270. .threshold = 90,
  271. }
  272. },
  273. .desc = { .sadb_alg_id = SADB_X_CALG_LZS }
  274. },
  275. {
  276. .name = "lzjh",
  277. .uinfo = {
  278. .comp = {
  279. .threshold = 50,
  280. }
  281. },
  282. .desc = { .sadb_alg_id = SADB_X_CALG_LZJH }
  283. },
  284. };
  285. static inline int aalg_entries(void)
  286. {
  287. return ARRAY_SIZE(aalg_list);
  288. }
  289. static inline int ealg_entries(void)
  290. {
  291. return ARRAY_SIZE(ealg_list);
  292. }
  293. static inline int calg_entries(void)
  294. {
  295. return ARRAY_SIZE(calg_list);
  296. }
  297. /* Todo: generic iterators */
  298. struct xfrm_algo_desc *xfrm_aalg_get_byid(int alg_id)
  299. {
  300. int i;
  301. for (i = 0; i < aalg_entries(); i++) {
  302. if (aalg_list[i].desc.sadb_alg_id == alg_id) {
  303. if (aalg_list[i].available)
  304. return &aalg_list[i];
  305. else
  306. break;
  307. }
  308. }
  309. return NULL;
  310. }
  311. EXPORT_SYMBOL_GPL(xfrm_aalg_get_byid);
  312. struct xfrm_algo_desc *xfrm_ealg_get_byid(int alg_id)
  313. {
  314. int i;
  315. for (i = 0; i < ealg_entries(); i++) {
  316. if (ealg_list[i].desc.sadb_alg_id == alg_id) {
  317. if (ealg_list[i].available)
  318. return &ealg_list[i];
  319. else
  320. break;
  321. }
  322. }
  323. return NULL;
  324. }
  325. EXPORT_SYMBOL_GPL(xfrm_ealg_get_byid);
  326. struct xfrm_algo_desc *xfrm_calg_get_byid(int alg_id)
  327. {
  328. int i;
  329. for (i = 0; i < calg_entries(); i++) {
  330. if (calg_list[i].desc.sadb_alg_id == alg_id) {
  331. if (calg_list[i].available)
  332. return &calg_list[i];
  333. else
  334. break;
  335. }
  336. }
  337. return NULL;
  338. }
  339. EXPORT_SYMBOL_GPL(xfrm_calg_get_byid);
  340. static struct xfrm_algo_desc *xfrm_get_byname(struct xfrm_algo_desc *list,
  341. int entries, u32 type, u32 mask,
  342. char *name, int probe)
  343. {
  344. int i, status;
  345. if (!name)
  346. return NULL;
  347. for (i = 0; i < entries; i++) {
  348. if (strcmp(name, list[i].name) &&
  349. (!list[i].compat || strcmp(name, list[i].compat)))
  350. continue;
  351. if (list[i].available)
  352. return &list[i];
  353. if (!probe)
  354. break;
  355. status = crypto_has_alg(list[i].name, type,
  356. mask | CRYPTO_ALG_ASYNC);
  357. if (!status)
  358. break;
  359. list[i].available = status;
  360. return &list[i];
  361. }
  362. return NULL;
  363. }
  364. struct xfrm_algo_desc *xfrm_aalg_get_byname(char *name, int probe)
  365. {
  366. return xfrm_get_byname(aalg_list, aalg_entries(),
  367. CRYPTO_ALG_TYPE_HASH, CRYPTO_ALG_TYPE_HASH_MASK,
  368. name, probe);
  369. }
  370. EXPORT_SYMBOL_GPL(xfrm_aalg_get_byname);
  371. struct xfrm_algo_desc *xfrm_ealg_get_byname(char *name, int probe)
  372. {
  373. return xfrm_get_byname(ealg_list, ealg_entries(),
  374. CRYPTO_ALG_TYPE_BLKCIPHER, CRYPTO_ALG_TYPE_MASK,
  375. name, probe);
  376. }
  377. EXPORT_SYMBOL_GPL(xfrm_ealg_get_byname);
  378. struct xfrm_algo_desc *xfrm_calg_get_byname(char *name, int probe)
  379. {
  380. return xfrm_get_byname(calg_list, calg_entries(),
  381. CRYPTO_ALG_TYPE_COMPRESS, CRYPTO_ALG_TYPE_MASK,
  382. name, probe);
  383. }
  384. EXPORT_SYMBOL_GPL(xfrm_calg_get_byname);
  385. struct xfrm_algo_desc *xfrm_aalg_get_byidx(unsigned int idx)
  386. {
  387. if (idx >= aalg_entries())
  388. return NULL;
  389. return &aalg_list[idx];
  390. }
  391. EXPORT_SYMBOL_GPL(xfrm_aalg_get_byidx);
  392. struct xfrm_algo_desc *xfrm_ealg_get_byidx(unsigned int idx)
  393. {
  394. if (idx >= ealg_entries())
  395. return NULL;
  396. return &ealg_list[idx];
  397. }
  398. EXPORT_SYMBOL_GPL(xfrm_ealg_get_byidx);
  399. /*
  400. * Probe for the availability of crypto algorithms, and set the available
  401. * flag for any algorithms found on the system. This is typically called by
  402. * pfkey during userspace SA add, update or register.
  403. */
  404. void xfrm_probe_algs(void)
  405. {
  406. #ifdef CONFIG_CRYPTO
  407. int i, status;
  408. BUG_ON(in_softirq());
  409. for (i = 0; i < aalg_entries(); i++) {
  410. status = crypto_has_hash(aalg_list[i].name, 0,
  411. CRYPTO_ALG_ASYNC);
  412. if (aalg_list[i].available != status)
  413. aalg_list[i].available = status;
  414. }
  415. for (i = 0; i < ealg_entries(); i++) {
  416. status = crypto_has_blkcipher(ealg_list[i].name, 0,
  417. CRYPTO_ALG_ASYNC);
  418. if (ealg_list[i].available != status)
  419. ealg_list[i].available = status;
  420. }
  421. for (i = 0; i < calg_entries(); i++) {
  422. status = crypto_has_comp(calg_list[i].name, 0,
  423. CRYPTO_ALG_ASYNC);
  424. if (calg_list[i].available != status)
  425. calg_list[i].available = status;
  426. }
  427. #endif
  428. }
  429. EXPORT_SYMBOL_GPL(xfrm_probe_algs);
  430. int xfrm_count_auth_supported(void)
  431. {
  432. int i, n;
  433. for (i = 0, n = 0; i < aalg_entries(); i++)
  434. if (aalg_list[i].available)
  435. n++;
  436. return n;
  437. }
  438. EXPORT_SYMBOL_GPL(xfrm_count_auth_supported);
  439. int xfrm_count_enc_supported(void)
  440. {
  441. int i, n;
  442. for (i = 0, n = 0; i < ealg_entries(); i++)
  443. if (ealg_list[i].available)
  444. n++;
  445. return n;
  446. }
  447. EXPORT_SYMBOL_GPL(xfrm_count_enc_supported);
  448. /* Move to common area: it is shared with AH. */
  449. int skb_icv_walk(const struct sk_buff *skb, struct hash_desc *desc,
  450. int offset, int len, icv_update_fn_t icv_update)
  451. {
  452. int start = skb_headlen(skb);
  453. int i, copy = start - offset;
  454. int err;
  455. struct scatterlist sg;
  456. /* Checksum header. */
  457. if (copy > 0) {
  458. if (copy > len)
  459. copy = len;
  460. sg.page = virt_to_page(skb->data + offset);
  461. sg.offset = (unsigned long)(skb->data + offset) % PAGE_SIZE;
  462. sg.length = copy;
  463. err = icv_update(desc, &sg, copy);
  464. if (unlikely(err))
  465. return err;
  466. if ((len -= copy) == 0)
  467. return 0;
  468. offset += copy;
  469. }
  470. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
  471. int end;
  472. BUG_TRAP(start <= offset + len);
  473. end = start + skb_shinfo(skb)->frags[i].size;
  474. if ((copy = end - offset) > 0) {
  475. skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  476. if (copy > len)
  477. copy = len;
  478. sg.page = frag->page;
  479. sg.offset = frag->page_offset + offset-start;
  480. sg.length = copy;
  481. err = icv_update(desc, &sg, copy);
  482. if (unlikely(err))
  483. return err;
  484. if (!(len -= copy))
  485. return 0;
  486. offset += copy;
  487. }
  488. start = end;
  489. }
  490. if (skb_shinfo(skb)->frag_list) {
  491. struct sk_buff *list = skb_shinfo(skb)->frag_list;
  492. for (; list; list = list->next) {
  493. int end;
  494. BUG_TRAP(start <= offset + len);
  495. end = start + list->len;
  496. if ((copy = end - offset) > 0) {
  497. if (copy > len)
  498. copy = len;
  499. err = skb_icv_walk(list, desc, offset-start,
  500. copy, icv_update);
  501. if (unlikely(err))
  502. return err;
  503. if ((len -= copy) == 0)
  504. return 0;
  505. offset += copy;
  506. }
  507. start = end;
  508. }
  509. }
  510. BUG_ON(len);
  511. return 0;
  512. }
  513. EXPORT_SYMBOL_GPL(skb_icv_walk);
  514. #if defined(CONFIG_INET_ESP) || defined(CONFIG_INET_ESP_MODULE) || defined(CONFIG_INET6_ESP) || defined(CONFIG_INET6_ESP_MODULE)
  515. /* Looking generic it is not used in another places. */
  516. int
  517. skb_to_sgvec(struct sk_buff *skb, struct scatterlist *sg, int offset, int len)
  518. {
  519. int start = skb_headlen(skb);
  520. int i, copy = start - offset;
  521. int elt = 0;
  522. if (copy > 0) {
  523. if (copy > len)
  524. copy = len;
  525. sg[elt].page = virt_to_page(skb->data + offset);
  526. sg[elt].offset = (unsigned long)(skb->data + offset) % PAGE_SIZE;
  527. sg[elt].length = copy;
  528. elt++;
  529. if ((len -= copy) == 0)
  530. return elt;
  531. offset += copy;
  532. }
  533. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
  534. int end;
  535. BUG_TRAP(start <= offset + len);
  536. end = start + skb_shinfo(skb)->frags[i].size;
  537. if ((copy = end - offset) > 0) {
  538. skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  539. if (copy > len)
  540. copy = len;
  541. sg[elt].page = frag->page;
  542. sg[elt].offset = frag->page_offset+offset-start;
  543. sg[elt].length = copy;
  544. elt++;
  545. if (!(len -= copy))
  546. return elt;
  547. offset += copy;
  548. }
  549. start = end;
  550. }
  551. if (skb_shinfo(skb)->frag_list) {
  552. struct sk_buff *list = skb_shinfo(skb)->frag_list;
  553. for (; list; list = list->next) {
  554. int end;
  555. BUG_TRAP(start <= offset + len);
  556. end = start + list->len;
  557. if ((copy = end - offset) > 0) {
  558. if (copy > len)
  559. copy = len;
  560. elt += skb_to_sgvec(list, sg+elt, offset - start, copy);
  561. if ((len -= copy) == 0)
  562. return elt;
  563. offset += copy;
  564. }
  565. start = end;
  566. }
  567. }
  568. BUG_ON(len);
  569. return elt;
  570. }
  571. EXPORT_SYMBOL_GPL(skb_to_sgvec);
  572. /* Check that skb data bits are writable. If they are not, copy data
  573. * to newly created private area. If "tailbits" is given, make sure that
  574. * tailbits bytes beyond current end of skb are writable.
  575. *
  576. * Returns amount of elements of scatterlist to load for subsequent
  577. * transformations and pointer to writable trailer skb.
  578. */
  579. int skb_cow_data(struct sk_buff *skb, int tailbits, struct sk_buff **trailer)
  580. {
  581. int copyflag;
  582. int elt;
  583. struct sk_buff *skb1, **skb_p;
  584. /* If skb is cloned or its head is paged, reallocate
  585. * head pulling out all the pages (pages are considered not writable
  586. * at the moment even if they are anonymous).
  587. */
  588. if ((skb_cloned(skb) || skb_shinfo(skb)->nr_frags) &&
  589. __pskb_pull_tail(skb, skb_pagelen(skb)-skb_headlen(skb)) == NULL)
  590. return -ENOMEM;
  591. /* Easy case. Most of packets will go this way. */
  592. if (!skb_shinfo(skb)->frag_list) {
  593. /* A little of trouble, not enough of space for trailer.
  594. * This should not happen, when stack is tuned to generate
  595. * good frames. OK, on miss we reallocate and reserve even more
  596. * space, 128 bytes is fair. */
  597. if (skb_tailroom(skb) < tailbits &&
  598. pskb_expand_head(skb, 0, tailbits-skb_tailroom(skb)+128, GFP_ATOMIC))
  599. return -ENOMEM;
  600. /* Voila! */
  601. *trailer = skb;
  602. return 1;
  603. }
  604. /* Misery. We are in troubles, going to mincer fragments... */
  605. elt = 1;
  606. skb_p = &skb_shinfo(skb)->frag_list;
  607. copyflag = 0;
  608. while ((skb1 = *skb_p) != NULL) {
  609. int ntail = 0;
  610. /* The fragment is partially pulled by someone,
  611. * this can happen on input. Copy it and everything
  612. * after it. */
  613. if (skb_shared(skb1))
  614. copyflag = 1;
  615. /* If the skb is the last, worry about trailer. */
  616. if (skb1->next == NULL && tailbits) {
  617. if (skb_shinfo(skb1)->nr_frags ||
  618. skb_shinfo(skb1)->frag_list ||
  619. skb_tailroom(skb1) < tailbits)
  620. ntail = tailbits + 128;
  621. }
  622. if (copyflag ||
  623. skb_cloned(skb1) ||
  624. ntail ||
  625. skb_shinfo(skb1)->nr_frags ||
  626. skb_shinfo(skb1)->frag_list) {
  627. struct sk_buff *skb2;
  628. /* Fuck, we are miserable poor guys... */
  629. if (ntail == 0)
  630. skb2 = skb_copy(skb1, GFP_ATOMIC);
  631. else
  632. skb2 = skb_copy_expand(skb1,
  633. skb_headroom(skb1),
  634. ntail,
  635. GFP_ATOMIC);
  636. if (unlikely(skb2 == NULL))
  637. return -ENOMEM;
  638. if (skb1->sk)
  639. skb_set_owner_w(skb2, skb1->sk);
  640. /* Looking around. Are we still alive?
  641. * OK, link new skb, drop old one */
  642. skb2->next = skb1->next;
  643. *skb_p = skb2;
  644. kfree_skb(skb1);
  645. skb1 = skb2;
  646. }
  647. elt++;
  648. *trailer = skb1;
  649. skb_p = &skb1->next;
  650. }
  651. return elt;
  652. }
  653. EXPORT_SYMBOL_GPL(skb_cow_data);
  654. void *pskb_put(struct sk_buff *skb, struct sk_buff *tail, int len)
  655. {
  656. if (tail != skb) {
  657. skb->data_len += len;
  658. skb->len += len;
  659. }
  660. return skb_put(tail, len);
  661. }
  662. EXPORT_SYMBOL_GPL(pskb_put);
  663. #endif