xfrm_algo.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775
  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(name, type, mask | CRYPTO_ALG_ASYNC);
  356. if (!status)
  357. break;
  358. list[i].available = status;
  359. return &list[i];
  360. }
  361. return NULL;
  362. }
  363. struct xfrm_algo_desc *xfrm_aalg_get_byname(char *name, int probe)
  364. {
  365. return xfrm_get_byname(aalg_list, aalg_entries(),
  366. CRYPTO_ALG_TYPE_HASH, CRYPTO_ALG_TYPE_HASH_MASK,
  367. name, probe);
  368. }
  369. EXPORT_SYMBOL_GPL(xfrm_aalg_get_byname);
  370. struct xfrm_algo_desc *xfrm_ealg_get_byname(char *name, int probe)
  371. {
  372. return xfrm_get_byname(ealg_list, ealg_entries(),
  373. CRYPTO_ALG_TYPE_BLKCIPHER, CRYPTO_ALG_TYPE_MASK,
  374. name, probe);
  375. }
  376. EXPORT_SYMBOL_GPL(xfrm_ealg_get_byname);
  377. struct xfrm_algo_desc *xfrm_calg_get_byname(char *name, int probe)
  378. {
  379. return xfrm_get_byname(calg_list, calg_entries(),
  380. CRYPTO_ALG_TYPE_COMPRESS, CRYPTO_ALG_TYPE_MASK,
  381. name, probe);
  382. }
  383. EXPORT_SYMBOL_GPL(xfrm_calg_get_byname);
  384. struct xfrm_algo_desc *xfrm_aalg_get_byidx(unsigned int idx)
  385. {
  386. if (idx >= aalg_entries())
  387. return NULL;
  388. return &aalg_list[idx];
  389. }
  390. EXPORT_SYMBOL_GPL(xfrm_aalg_get_byidx);
  391. struct xfrm_algo_desc *xfrm_ealg_get_byidx(unsigned int idx)
  392. {
  393. if (idx >= ealg_entries())
  394. return NULL;
  395. return &ealg_list[idx];
  396. }
  397. EXPORT_SYMBOL_GPL(xfrm_ealg_get_byidx);
  398. /*
  399. * Probe for the availability of crypto algorithms, and set the available
  400. * flag for any algorithms found on the system. This is typically called by
  401. * pfkey during userspace SA add, update or register.
  402. */
  403. void xfrm_probe_algs(void)
  404. {
  405. #ifdef CONFIG_CRYPTO
  406. int i, status;
  407. BUG_ON(in_softirq());
  408. for (i = 0; i < aalg_entries(); i++) {
  409. status = crypto_has_hash(aalg_list[i].name, 0,
  410. CRYPTO_ALG_ASYNC);
  411. if (aalg_list[i].available != status)
  412. aalg_list[i].available = status;
  413. }
  414. for (i = 0; i < ealg_entries(); i++) {
  415. status = crypto_has_blkcipher(ealg_list[i].name, 0,
  416. CRYPTO_ALG_ASYNC);
  417. if (ealg_list[i].available != status)
  418. ealg_list[i].available = status;
  419. }
  420. for (i = 0; i < calg_entries(); i++) {
  421. status = crypto_has_comp(calg_list[i].name, 0,
  422. CRYPTO_ALG_ASYNC);
  423. if (calg_list[i].available != status)
  424. calg_list[i].available = status;
  425. }
  426. #endif
  427. }
  428. EXPORT_SYMBOL_GPL(xfrm_probe_algs);
  429. int xfrm_count_auth_supported(void)
  430. {
  431. int i, n;
  432. for (i = 0, n = 0; i < aalg_entries(); i++)
  433. if (aalg_list[i].available)
  434. n++;
  435. return n;
  436. }
  437. EXPORT_SYMBOL_GPL(xfrm_count_auth_supported);
  438. int xfrm_count_enc_supported(void)
  439. {
  440. int i, n;
  441. for (i = 0, n = 0; i < ealg_entries(); i++)
  442. if (ealg_list[i].available)
  443. n++;
  444. return n;
  445. }
  446. EXPORT_SYMBOL_GPL(xfrm_count_enc_supported);
  447. /* Move to common area: it is shared with AH. */
  448. int skb_icv_walk(const struct sk_buff *skb, struct hash_desc *desc,
  449. int offset, int len, icv_update_fn_t icv_update)
  450. {
  451. int start = skb_headlen(skb);
  452. int i, copy = start - offset;
  453. int err;
  454. struct scatterlist sg;
  455. /* Checksum header. */
  456. if (copy > 0) {
  457. if (copy > len)
  458. copy = len;
  459. sg.page = virt_to_page(skb->data + offset);
  460. sg.offset = (unsigned long)(skb->data + offset) % PAGE_SIZE;
  461. sg.length = copy;
  462. err = icv_update(desc, &sg, copy);
  463. if (unlikely(err))
  464. return err;
  465. if ((len -= copy) == 0)
  466. return 0;
  467. offset += copy;
  468. }
  469. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
  470. int end;
  471. BUG_TRAP(start <= offset + len);
  472. end = start + skb_shinfo(skb)->frags[i].size;
  473. if ((copy = end - offset) > 0) {
  474. skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  475. if (copy > len)
  476. copy = len;
  477. sg.page = frag->page;
  478. sg.offset = frag->page_offset + offset-start;
  479. sg.length = copy;
  480. err = icv_update(desc, &sg, copy);
  481. if (unlikely(err))
  482. return err;
  483. if (!(len -= copy))
  484. return 0;
  485. offset += copy;
  486. }
  487. start = end;
  488. }
  489. if (skb_shinfo(skb)->frag_list) {
  490. struct sk_buff *list = skb_shinfo(skb)->frag_list;
  491. for (; list; list = list->next) {
  492. int end;
  493. BUG_TRAP(start <= offset + len);
  494. end = start + list->len;
  495. if ((copy = end - offset) > 0) {
  496. if (copy > len)
  497. copy = len;
  498. err = skb_icv_walk(list, desc, offset-start,
  499. copy, icv_update);
  500. if (unlikely(err))
  501. return err;
  502. if ((len -= copy) == 0)
  503. return 0;
  504. offset += copy;
  505. }
  506. start = end;
  507. }
  508. }
  509. BUG_ON(len);
  510. return 0;
  511. }
  512. EXPORT_SYMBOL_GPL(skb_icv_walk);
  513. #if defined(CONFIG_INET_ESP) || defined(CONFIG_INET_ESP_MODULE) || defined(CONFIG_INET6_ESP) || defined(CONFIG_INET6_ESP_MODULE)
  514. /* Looking generic it is not used in another places. */
  515. int
  516. skb_to_sgvec(struct sk_buff *skb, struct scatterlist *sg, int offset, int len)
  517. {
  518. int start = skb_headlen(skb);
  519. int i, copy = start - offset;
  520. int elt = 0;
  521. if (copy > 0) {
  522. if (copy > len)
  523. copy = len;
  524. sg[elt].page = virt_to_page(skb->data + offset);
  525. sg[elt].offset = (unsigned long)(skb->data + offset) % PAGE_SIZE;
  526. sg[elt].length = copy;
  527. elt++;
  528. if ((len -= copy) == 0)
  529. return elt;
  530. offset += copy;
  531. }
  532. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
  533. int end;
  534. BUG_TRAP(start <= offset + len);
  535. end = start + skb_shinfo(skb)->frags[i].size;
  536. if ((copy = end - offset) > 0) {
  537. skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  538. if (copy > len)
  539. copy = len;
  540. sg[elt].page = frag->page;
  541. sg[elt].offset = frag->page_offset+offset-start;
  542. sg[elt].length = copy;
  543. elt++;
  544. if (!(len -= copy))
  545. return elt;
  546. offset += copy;
  547. }
  548. start = end;
  549. }
  550. if (skb_shinfo(skb)->frag_list) {
  551. struct sk_buff *list = skb_shinfo(skb)->frag_list;
  552. for (; list; list = list->next) {
  553. int end;
  554. BUG_TRAP(start <= offset + len);
  555. end = start + list->len;
  556. if ((copy = end - offset) > 0) {
  557. if (copy > len)
  558. copy = len;
  559. elt += skb_to_sgvec(list, sg+elt, offset - start, copy);
  560. if ((len -= copy) == 0)
  561. return elt;
  562. offset += copy;
  563. }
  564. start = end;
  565. }
  566. }
  567. BUG_ON(len);
  568. return elt;
  569. }
  570. EXPORT_SYMBOL_GPL(skb_to_sgvec);
  571. /* Check that skb data bits are writable. If they are not, copy data
  572. * to newly created private area. If "tailbits" is given, make sure that
  573. * tailbits bytes beyond current end of skb are writable.
  574. *
  575. * Returns amount of elements of scatterlist to load for subsequent
  576. * transformations and pointer to writable trailer skb.
  577. */
  578. int skb_cow_data(struct sk_buff *skb, int tailbits, struct sk_buff **trailer)
  579. {
  580. int copyflag;
  581. int elt;
  582. struct sk_buff *skb1, **skb_p;
  583. /* If skb is cloned or its head is paged, reallocate
  584. * head pulling out all the pages (pages are considered not writable
  585. * at the moment even if they are anonymous).
  586. */
  587. if ((skb_cloned(skb) || skb_shinfo(skb)->nr_frags) &&
  588. __pskb_pull_tail(skb, skb_pagelen(skb)-skb_headlen(skb)) == NULL)
  589. return -ENOMEM;
  590. /* Easy case. Most of packets will go this way. */
  591. if (!skb_shinfo(skb)->frag_list) {
  592. /* A little of trouble, not enough of space for trailer.
  593. * This should not happen, when stack is tuned to generate
  594. * good frames. OK, on miss we reallocate and reserve even more
  595. * space, 128 bytes is fair. */
  596. if (skb_tailroom(skb) < tailbits &&
  597. pskb_expand_head(skb, 0, tailbits-skb_tailroom(skb)+128, GFP_ATOMIC))
  598. return -ENOMEM;
  599. /* Voila! */
  600. *trailer = skb;
  601. return 1;
  602. }
  603. /* Misery. We are in troubles, going to mincer fragments... */
  604. elt = 1;
  605. skb_p = &skb_shinfo(skb)->frag_list;
  606. copyflag = 0;
  607. while ((skb1 = *skb_p) != NULL) {
  608. int ntail = 0;
  609. /* The fragment is partially pulled by someone,
  610. * this can happen on input. Copy it and everything
  611. * after it. */
  612. if (skb_shared(skb1))
  613. copyflag = 1;
  614. /* If the skb is the last, worry about trailer. */
  615. if (skb1->next == NULL && tailbits) {
  616. if (skb_shinfo(skb1)->nr_frags ||
  617. skb_shinfo(skb1)->frag_list ||
  618. skb_tailroom(skb1) < tailbits)
  619. ntail = tailbits + 128;
  620. }
  621. if (copyflag ||
  622. skb_cloned(skb1) ||
  623. ntail ||
  624. skb_shinfo(skb1)->nr_frags ||
  625. skb_shinfo(skb1)->frag_list) {
  626. struct sk_buff *skb2;
  627. /* Fuck, we are miserable poor guys... */
  628. if (ntail == 0)
  629. skb2 = skb_copy(skb1, GFP_ATOMIC);
  630. else
  631. skb2 = skb_copy_expand(skb1,
  632. skb_headroom(skb1),
  633. ntail,
  634. GFP_ATOMIC);
  635. if (unlikely(skb2 == NULL))
  636. return -ENOMEM;
  637. if (skb1->sk)
  638. skb_set_owner_w(skb2, skb1->sk);
  639. /* Looking around. Are we still alive?
  640. * OK, link new skb, drop old one */
  641. skb2->next = skb1->next;
  642. *skb_p = skb2;
  643. kfree_skb(skb1);
  644. skb1 = skb2;
  645. }
  646. elt++;
  647. *trailer = skb1;
  648. skb_p = &skb1->next;
  649. }
  650. return elt;
  651. }
  652. EXPORT_SYMBOL_GPL(skb_cow_data);
  653. void *pskb_put(struct sk_buff *skb, struct sk_buff *tail, int len)
  654. {
  655. if (tail != skb) {
  656. skb->data_len += len;
  657. skb->len += len;
  658. }
  659. return skb_put(tail, len);
  660. }
  661. EXPORT_SYMBOL_GPL(pskb_put);
  662. #endif