blob: 0426388d351de58bf116ae526b791c8e42c22764 [file] [log] [blame]
YOSHIFUJI Hideakia716c112007-02-09 23:25:29 +09001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * 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
YOSHIFUJI Hideakia716c112007-02-09 23:25:29 +09008 * Software Foundation; either version 2 of the License, or (at your option)
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * any later version.
10 */
11
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/module.h>
13#include <linux/kernel.h>
14#include <linux/pfkeyv2.h>
15#include <linux/crypto.h>
Heiko Carstensb3b724f2007-10-23 09:28:34 +020016#include <linux/scatterlist.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <net/xfrm.h>
18#if defined(CONFIG_INET_AH) || defined(CONFIG_INET_AH_MODULE) || defined(CONFIG_INET6_AH) || defined(CONFIG_INET6_AH_MODULE)
19#include <net/ah.h>
20#endif
21#if defined(CONFIG_INET_ESP) || defined(CONFIG_INET_ESP_MODULE) || defined(CONFIG_INET6_ESP) || defined(CONFIG_INET6_ESP_MODULE)
22#include <net/esp.h>
23#endif
24#include <asm/scatterlist.h>
25
26/*
27 * Algorithms supported by IPsec. These entries contain properties which
28 * are used in key negotiation and xfrm processing, and are used to verify
29 * that instantiated crypto transforms have correct parameters for IPsec
30 * purposes.
31 */
32static struct xfrm_algo_desc aalg_list[] = {
33{
Herbert Xu07d4ee52006-08-20 14:24:50 +100034 .name = "hmac(digest_null)",
35 .compat = "digest_null",
YOSHIFUJI Hideakia716c112007-02-09 23:25:29 +090036
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 .uinfo = {
38 .auth = {
39 .icv_truncbits = 0,
40 .icv_fullbits = 0,
41 }
42 },
YOSHIFUJI Hideakia716c112007-02-09 23:25:29 +090043
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 .desc = {
45 .sadb_alg_id = SADB_X_AALG_NULL,
46 .sadb_alg_ivlen = 0,
47 .sadb_alg_minbits = 0,
48 .sadb_alg_maxbits = 0
49 }
50},
51{
Herbert Xu07d4ee52006-08-20 14:24:50 +100052 .name = "hmac(md5)",
53 .compat = "md5",
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
55 .uinfo = {
56 .auth = {
57 .icv_truncbits = 96,
58 .icv_fullbits = 128,
59 }
60 },
YOSHIFUJI Hideakia716c112007-02-09 23:25:29 +090061
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 .desc = {
63 .sadb_alg_id = SADB_AALG_MD5HMAC,
64 .sadb_alg_ivlen = 0,
65 .sadb_alg_minbits = 128,
66 .sadb_alg_maxbits = 128
67 }
68},
69{
Herbert Xu07d4ee52006-08-20 14:24:50 +100070 .name = "hmac(sha1)",
71 .compat = "sha1",
Linus Torvalds1da177e2005-04-16 15:20:36 -070072
73 .uinfo = {
74 .auth = {
75 .icv_truncbits = 96,
76 .icv_fullbits = 160,
77 }
78 },
79
80 .desc = {
81 .sadb_alg_id = SADB_AALG_SHA1HMAC,
82 .sadb_alg_ivlen = 0,
83 .sadb_alg_minbits = 160,
84 .sadb_alg_maxbits = 160
85 }
86},
87{
Herbert Xu07d4ee52006-08-20 14:24:50 +100088 .name = "hmac(sha256)",
89 .compat = "sha256",
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
91 .uinfo = {
92 .auth = {
93 .icv_truncbits = 96,
94 .icv_fullbits = 256,
95 }
96 },
97
98 .desc = {
99 .sadb_alg_id = SADB_X_AALG_SHA2_256HMAC,
100 .sadb_alg_ivlen = 0,
101 .sadb_alg_minbits = 256,
102 .sadb_alg_maxbits = 256
103 }
104},
105{
Herbert Xu07d4ee52006-08-20 14:24:50 +1000106 .name = "hmac(ripemd160)",
107 .compat = "ripemd160",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
109 .uinfo = {
110 .auth = {
111 .icv_truncbits = 96,
112 .icv_fullbits = 160,
113 }
114 },
115
116 .desc = {
117 .sadb_alg_id = SADB_X_AALG_RIPEMD160HMAC,
118 .sadb_alg_ivlen = 0,
119 .sadb_alg_minbits = 160,
120 .sadb_alg_maxbits = 160
121 }
122},
Kazunori MIYAZAWA7cf4c1a2006-10-28 13:21:22 +1000123{
124 .name = "xcbc(aes)",
125
126 .uinfo = {
127 .auth = {
128 .icv_truncbits = 96,
129 .icv_fullbits = 128,
130 }
131 },
132
133 .desc = {
134 .sadb_alg_id = SADB_X_AALG_AES_XCBC_MAC,
135 .sadb_alg_ivlen = 0,
136 .sadb_alg_minbits = 128,
137 .sadb_alg_maxbits = 128
138 }
139},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140};
141
142static struct xfrm_algo_desc ealg_list[] = {
143{
Herbert Xu6b7326c2006-07-30 15:41:01 +1000144 .name = "ecb(cipher_null)",
145 .compat = "cipher_null",
YOSHIFUJI Hideakia716c112007-02-09 23:25:29 +0900146
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 .uinfo = {
148 .encr = {
149 .blockbits = 8,
150 .defkeybits = 0,
151 }
152 },
YOSHIFUJI Hideakia716c112007-02-09 23:25:29 +0900153
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 .desc = {
155 .sadb_alg_id = SADB_EALG_NULL,
156 .sadb_alg_ivlen = 0,
157 .sadb_alg_minbits = 0,
158 .sadb_alg_maxbits = 0
159 }
160},
161{
Herbert Xu6b7326c2006-07-30 15:41:01 +1000162 .name = "cbc(des)",
163 .compat = "des",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164
165 .uinfo = {
166 .encr = {
167 .blockbits = 64,
168 .defkeybits = 64,
169 }
170 },
171
172 .desc = {
173 .sadb_alg_id = SADB_EALG_DESCBC,
174 .sadb_alg_ivlen = 8,
175 .sadb_alg_minbits = 64,
176 .sadb_alg_maxbits = 64
177 }
178},
179{
Herbert Xu6b7326c2006-07-30 15:41:01 +1000180 .name = "cbc(des3_ede)",
181 .compat = "des3_ede",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182
183 .uinfo = {
184 .encr = {
185 .blockbits = 64,
186 .defkeybits = 192,
187 }
188 },
189
190 .desc = {
191 .sadb_alg_id = SADB_EALG_3DESCBC,
192 .sadb_alg_ivlen = 8,
193 .sadb_alg_minbits = 192,
194 .sadb_alg_maxbits = 192
195 }
196},
197{
Herbert Xu6b7326c2006-07-30 15:41:01 +1000198 .name = "cbc(cast128)",
199 .compat = "cast128",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200
201 .uinfo = {
202 .encr = {
203 .blockbits = 64,
204 .defkeybits = 128,
205 }
206 },
207
208 .desc = {
209 .sadb_alg_id = SADB_X_EALG_CASTCBC,
210 .sadb_alg_ivlen = 8,
211 .sadb_alg_minbits = 40,
212 .sadb_alg_maxbits = 128
213 }
214},
215{
Herbert Xu6b7326c2006-07-30 15:41:01 +1000216 .name = "cbc(blowfish)",
217 .compat = "blowfish",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218
219 .uinfo = {
220 .encr = {
221 .blockbits = 64,
222 .defkeybits = 128,
223 }
224 },
225
226 .desc = {
227 .sadb_alg_id = SADB_X_EALG_BLOWFISHCBC,
228 .sadb_alg_ivlen = 8,
229 .sadb_alg_minbits = 40,
230 .sadb_alg_maxbits = 448
231 }
232},
233{
Herbert Xu6b7326c2006-07-30 15:41:01 +1000234 .name = "cbc(aes)",
235 .compat = "aes",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236
237 .uinfo = {
238 .encr = {
239 .blockbits = 128,
240 .defkeybits = 128,
241 }
242 },
243
244 .desc = {
245 .sadb_alg_id = SADB_X_EALG_AESCBC,
246 .sadb_alg_ivlen = 8,
247 .sadb_alg_minbits = 128,
248 .sadb_alg_maxbits = 256
249 }
250},
251{
YOSHIFUJI Hideakia716c112007-02-09 23:25:29 +0900252 .name = "cbc(serpent)",
253 .compat = "serpent",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254
YOSHIFUJI Hideakia716c112007-02-09 23:25:29 +0900255 .uinfo = {
256 .encr = {
257 .blockbits = 128,
258 .defkeybits = 128,
259 }
260 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261
YOSHIFUJI Hideakia716c112007-02-09 23:25:29 +0900262 .desc = {
263 .sadb_alg_id = SADB_X_EALG_SERPENTCBC,
264 .sadb_alg_ivlen = 8,
265 .sadb_alg_minbits = 128,
266 .sadb_alg_maxbits = 256,
267 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268},
269{
Noriaki TAKAMIYA6a0dc8d2006-10-22 15:05:57 +1000270 .name = "cbc(camellia)",
271
272 .uinfo = {
273 .encr = {
274 .blockbits = 128,
275 .defkeybits = 128,
276 }
277 },
278
279 .desc = {
280 .sadb_alg_id = SADB_X_EALG_CAMELLIACBC,
281 .sadb_alg_ivlen = 8,
282 .sadb_alg_minbits = 128,
283 .sadb_alg_maxbits = 256
284 }
285},
286{
YOSHIFUJI Hideakia716c112007-02-09 23:25:29 +0900287 .name = "cbc(twofish)",
288 .compat = "twofish",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289
YOSHIFUJI Hideakia716c112007-02-09 23:25:29 +0900290 .uinfo = {
291 .encr = {
292 .blockbits = 128,
293 .defkeybits = 128,
294 }
295 },
296
297 .desc = {
298 .sadb_alg_id = SADB_X_EALG_TWOFISHCBC,
299 .sadb_alg_ivlen = 8,
300 .sadb_alg_minbits = 128,
301 .sadb_alg_maxbits = 256
302 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303},
304};
305
306static struct xfrm_algo_desc calg_list[] = {
307{
308 .name = "deflate",
309 .uinfo = {
310 .comp = {
311 .threshold = 90,
312 }
313 },
314 .desc = { .sadb_alg_id = SADB_X_CALG_DEFLATE }
315},
316{
317 .name = "lzs",
318 .uinfo = {
319 .comp = {
320 .threshold = 90,
321 }
322 },
323 .desc = { .sadb_alg_id = SADB_X_CALG_LZS }
324},
325{
326 .name = "lzjh",
327 .uinfo = {
328 .comp = {
329 .threshold = 50,
330 }
331 },
332 .desc = { .sadb_alg_id = SADB_X_CALG_LZJH }
333},
334};
335
336static inline int aalg_entries(void)
337{
338 return ARRAY_SIZE(aalg_list);
339}
340
341static inline int ealg_entries(void)
342{
343 return ARRAY_SIZE(ealg_list);
344}
345
346static inline int calg_entries(void)
347{
348 return ARRAY_SIZE(calg_list);
349}
350
Herbert Xuc92b3a22007-05-19 14:21:18 -0700351struct xfrm_algo_list {
352 struct xfrm_algo_desc *algs;
353 int entries;
354 u32 type;
355 u32 mask;
356};
357
358static const struct xfrm_algo_list xfrm_aalg_list = {
359 .algs = aalg_list,
360 .entries = ARRAY_SIZE(aalg_list),
361 .type = CRYPTO_ALG_TYPE_HASH,
362 .mask = CRYPTO_ALG_TYPE_HASH_MASK | CRYPTO_ALG_ASYNC,
363};
364
365static const struct xfrm_algo_list xfrm_ealg_list = {
366 .algs = ealg_list,
367 .entries = ARRAY_SIZE(ealg_list),
368 .type = CRYPTO_ALG_TYPE_BLKCIPHER,
369 .mask = CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_ASYNC,
370};
371
372static const struct xfrm_algo_list xfrm_calg_list = {
373 .algs = calg_list,
374 .entries = ARRAY_SIZE(calg_list),
375 .type = CRYPTO_ALG_TYPE_COMPRESS,
376 .mask = CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_ASYNC,
377};
378
379static struct xfrm_algo_desc *xfrm_find_algo(
380 const struct xfrm_algo_list *algo_list,
381 int match(const struct xfrm_algo_desc *entry, const void *data),
382 const void *data, int probe)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383{
Herbert Xuc92b3a22007-05-19 14:21:18 -0700384 struct xfrm_algo_desc *list = algo_list->algs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 int i, status;
386
Herbert Xuc92b3a22007-05-19 14:21:18 -0700387 for (i = 0; i < algo_list->entries; i++) {
388 if (!match(list + i, data))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 continue;
390
391 if (list[i].available)
392 return &list[i];
393
394 if (!probe)
395 break;
396
Herbert Xuc92b3a22007-05-19 14:21:18 -0700397 status = crypto_has_alg(list[i].name, algo_list->type,
398 algo_list->mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 if (!status)
400 break;
401
402 list[i].available = status;
403 return &list[i];
404 }
405 return NULL;
406}
407
Herbert Xuc92b3a22007-05-19 14:21:18 -0700408static int xfrm_alg_id_match(const struct xfrm_algo_desc *entry,
409 const void *data)
410{
Herbert Xu26b8e512007-05-22 16:12:26 -0700411 return entry->desc.sadb_alg_id == (unsigned long)data;
Herbert Xuc92b3a22007-05-19 14:21:18 -0700412}
413
414struct xfrm_algo_desc *xfrm_aalg_get_byid(int alg_id)
415{
416 return xfrm_find_algo(&xfrm_aalg_list, xfrm_alg_id_match,
Herbert Xu26b8e512007-05-22 16:12:26 -0700417 (void *)(unsigned long)alg_id, 1);
Herbert Xuc92b3a22007-05-19 14:21:18 -0700418}
419EXPORT_SYMBOL_GPL(xfrm_aalg_get_byid);
420
421struct xfrm_algo_desc *xfrm_ealg_get_byid(int alg_id)
422{
423 return xfrm_find_algo(&xfrm_ealg_list, xfrm_alg_id_match,
Herbert Xu26b8e512007-05-22 16:12:26 -0700424 (void *)(unsigned long)alg_id, 1);
Herbert Xuc92b3a22007-05-19 14:21:18 -0700425}
426EXPORT_SYMBOL_GPL(xfrm_ealg_get_byid);
427
428struct xfrm_algo_desc *xfrm_calg_get_byid(int alg_id)
429{
430 return xfrm_find_algo(&xfrm_calg_list, xfrm_alg_id_match,
Herbert Xu26b8e512007-05-22 16:12:26 -0700431 (void *)(unsigned long)alg_id, 1);
Herbert Xuc92b3a22007-05-19 14:21:18 -0700432}
433EXPORT_SYMBOL_GPL(xfrm_calg_get_byid);
434
435static int xfrm_alg_name_match(const struct xfrm_algo_desc *entry,
436 const void *data)
437{
438 const char *name = data;
439
440 return name && (!strcmp(name, entry->name) ||
441 (entry->compat && !strcmp(name, entry->compat)));
442}
443
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444struct xfrm_algo_desc *xfrm_aalg_get_byname(char *name, int probe)
445{
Herbert Xuc92b3a22007-05-19 14:21:18 -0700446 return xfrm_find_algo(&xfrm_aalg_list, xfrm_alg_name_match, name,
447 probe);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448}
449EXPORT_SYMBOL_GPL(xfrm_aalg_get_byname);
450
451struct xfrm_algo_desc *xfrm_ealg_get_byname(char *name, int probe)
452{
Herbert Xuc92b3a22007-05-19 14:21:18 -0700453 return xfrm_find_algo(&xfrm_ealg_list, xfrm_alg_name_match, name,
454 probe);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455}
456EXPORT_SYMBOL_GPL(xfrm_ealg_get_byname);
457
458struct xfrm_algo_desc *xfrm_calg_get_byname(char *name, int probe)
459{
Herbert Xuc92b3a22007-05-19 14:21:18 -0700460 return xfrm_find_algo(&xfrm_calg_list, xfrm_alg_name_match, name,
461 probe);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462}
463EXPORT_SYMBOL_GPL(xfrm_calg_get_byname);
464
465struct xfrm_algo_desc *xfrm_aalg_get_byidx(unsigned int idx)
466{
467 if (idx >= aalg_entries())
468 return NULL;
469
470 return &aalg_list[idx];
471}
472EXPORT_SYMBOL_GPL(xfrm_aalg_get_byidx);
473
474struct xfrm_algo_desc *xfrm_ealg_get_byidx(unsigned int idx)
475{
476 if (idx >= ealg_entries())
477 return NULL;
478
479 return &ealg_list[idx];
480}
481EXPORT_SYMBOL_GPL(xfrm_ealg_get_byidx);
482
483/*
484 * Probe for the availability of crypto algorithms, and set the available
485 * flag for any algorithms found on the system. This is typically called by
486 * pfkey during userspace SA add, update or register.
487 */
488void xfrm_probe_algs(void)
489{
490#ifdef CONFIG_CRYPTO
491 int i, status;
YOSHIFUJI Hideakia716c112007-02-09 23:25:29 +0900492
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 BUG_ON(in_softirq());
494
495 for (i = 0; i < aalg_entries(); i++) {
Herbert Xue4d5b792006-08-26 18:12:40 +1000496 status = crypto_has_hash(aalg_list[i].name, 0,
497 CRYPTO_ALG_ASYNC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 if (aalg_list[i].available != status)
499 aalg_list[i].available = status;
500 }
YOSHIFUJI Hideakia716c112007-02-09 23:25:29 +0900501
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 for (i = 0; i < ealg_entries(); i++) {
Herbert Xue4d5b792006-08-26 18:12:40 +1000503 status = crypto_has_blkcipher(ealg_list[i].name, 0,
504 CRYPTO_ALG_ASYNC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 if (ealg_list[i].available != status)
506 ealg_list[i].available = status;
507 }
YOSHIFUJI Hideakia716c112007-02-09 23:25:29 +0900508
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 for (i = 0; i < calg_entries(); i++) {
Herbert Xue4d5b792006-08-26 18:12:40 +1000510 status = crypto_has_comp(calg_list[i].name, 0,
511 CRYPTO_ALG_ASYNC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 if (calg_list[i].available != status)
513 calg_list[i].available = status;
514 }
515#endif
516}
517EXPORT_SYMBOL_GPL(xfrm_probe_algs);
518
519int xfrm_count_auth_supported(void)
520{
521 int i, n;
522
523 for (i = 0, n = 0; i < aalg_entries(); i++)
524 if (aalg_list[i].available)
525 n++;
526 return n;
527}
528EXPORT_SYMBOL_GPL(xfrm_count_auth_supported);
529
530int xfrm_count_enc_supported(void)
531{
532 int i, n;
533
534 for (i = 0, n = 0; i < ealg_entries(); i++)
535 if (ealg_list[i].available)
536 n++;
537 return n;
538}
539EXPORT_SYMBOL_GPL(xfrm_count_enc_supported);
540
541/* Move to common area: it is shared with AH. */
542
Herbert Xu07d4ee52006-08-20 14:24:50 +1000543int skb_icv_walk(const struct sk_buff *skb, struct hash_desc *desc,
544 int offset, int len, icv_update_fn_t icv_update)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545{
David S. Miller1a028e52007-04-27 15:21:23 -0700546 int start = skb_headlen(skb);
547 int i, copy = start - offset;
Herbert Xu07d4ee52006-08-20 14:24:50 +1000548 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 struct scatterlist sg;
550
551 /* Checksum header. */
552 if (copy > 0) {
553 if (copy > len)
554 copy = len;
YOSHIFUJI Hideakia716c112007-02-09 23:25:29 +0900555
David S. Miller0e0940d2007-10-26 00:39:27 -0700556 sg_init_one(&sg, skb->data + offset, copy);
YOSHIFUJI Hideakia716c112007-02-09 23:25:29 +0900557
Herbert Xu07d4ee52006-08-20 14:24:50 +1000558 err = icv_update(desc, &sg, copy);
559 if (unlikely(err))
560 return err;
YOSHIFUJI Hideakia716c112007-02-09 23:25:29 +0900561
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 if ((len -= copy) == 0)
Herbert Xu07d4ee52006-08-20 14:24:50 +1000563 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 offset += copy;
565 }
566
567 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
David S. Miller1a028e52007-04-27 15:21:23 -0700568 int end;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569
David S. Miller1a028e52007-04-27 15:21:23 -0700570 BUG_TRAP(start <= offset + len);
571
572 end = start + skb_shinfo(skb)->frags[i].size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 if ((copy = end - offset) > 0) {
574 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
575
576 if (copy > len)
577 copy = len;
YOSHIFUJI Hideakia716c112007-02-09 23:25:29 +0900578
David S. Miller0e0940d2007-10-26 00:39:27 -0700579 sg_init_table(&sg, 1);
Jens Axboe642f1492007-10-24 11:20:47 +0200580 sg_set_page(&sg, frag->page, copy,
David S. Miller0e0940d2007-10-26 00:39:27 -0700581 frag->page_offset + offset-start);
YOSHIFUJI Hideakia716c112007-02-09 23:25:29 +0900582
Herbert Xu07d4ee52006-08-20 14:24:50 +1000583 err = icv_update(desc, &sg, copy);
584 if (unlikely(err))
585 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586
587 if (!(len -= copy))
Herbert Xu07d4ee52006-08-20 14:24:50 +1000588 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 offset += copy;
590 }
David S. Miller1a028e52007-04-27 15:21:23 -0700591 start = end;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 }
593
594 if (skb_shinfo(skb)->frag_list) {
595 struct sk_buff *list = skb_shinfo(skb)->frag_list;
596
597 for (; list; list = list->next) {
David S. Miller1a028e52007-04-27 15:21:23 -0700598 int end;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599
David S. Miller1a028e52007-04-27 15:21:23 -0700600 BUG_TRAP(start <= offset + len);
601
602 end = start + list->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 if ((copy = end - offset) > 0) {
604 if (copy > len)
605 copy = len;
David S. Miller1a028e52007-04-27 15:21:23 -0700606 err = skb_icv_walk(list, desc, offset-start,
Herbert Xu07d4ee52006-08-20 14:24:50 +1000607 copy, icv_update);
608 if (unlikely(err))
609 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 if ((len -= copy) == 0)
Herbert Xu07d4ee52006-08-20 14:24:50 +1000611 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 offset += copy;
613 }
David S. Miller1a028e52007-04-27 15:21:23 -0700614 start = end;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 }
616 }
Kris Katterjohn09a62662006-01-08 22:24:28 -0800617 BUG_ON(len);
Herbert Xu07d4ee52006-08-20 14:24:50 +1000618 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619}
620EXPORT_SYMBOL_GPL(skb_icv_walk);
621
622#if defined(CONFIG_INET_ESP) || defined(CONFIG_INET_ESP_MODULE) || defined(CONFIG_INET6_ESP) || defined(CONFIG_INET6_ESP_MODULE)
623
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624void *pskb_put(struct sk_buff *skb, struct sk_buff *tail, int len)
625{
626 if (tail != skb) {
627 skb->data_len += len;
628 skb->len += len;
629 }
630 return skb_put(tail, len);
631}
632EXPORT_SYMBOL_GPL(pskb_put);
633#endif