aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2015-05-27 04:03:45 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2015-05-27 23:23:20 -0400
commit69b0137f6164a14993504d4cf5a61dabf79e6c43 (patch)
tree0654e06290f7940fdb693513c54dd9fa6c93699b
parent165ecc6373c7bfcd63da6dc489980c892fac2db9 (diff)
ipsec: Add IV generator information to xfrm_state
This patch adds IV generator information to xfrm_state. This is currently obtained from our own list of algorithm descriptions. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-rw-r--r--include/net/xfrm.h1
-rw-r--r--net/key/af_key.c1
-rw-r--r--net/xfrm/xfrm_user.c40
3 files changed, 33 insertions, 9 deletions
diff --git a/include/net/xfrm.h b/include/net/xfrm.h
index 30bca865c9dc..f0ee97eec24d 100644
--- a/include/net/xfrm.h
+++ b/include/net/xfrm.h
@@ -168,6 +168,7 @@ struct xfrm_state {
168 struct xfrm_algo *ealg; 168 struct xfrm_algo *ealg;
169 struct xfrm_algo *calg; 169 struct xfrm_algo *calg;
170 struct xfrm_algo_aead *aead; 170 struct xfrm_algo_aead *aead;
171 const char *geniv;
171 172
172 /* Data for encapsulator */ 173 /* Data for encapsulator */
173 struct xfrm_encap_tmpl *encap; 174 struct xfrm_encap_tmpl *encap;
diff --git a/net/key/af_key.c b/net/key/af_key.c
index f0d52d721b3a..3c5b8ce38ef4 100644
--- a/net/key/af_key.c
+++ b/net/key/af_key.c
@@ -1190,6 +1190,7 @@ static struct xfrm_state * pfkey_msg2xfrm_state(struct net *net,
1190 memcpy(x->ealg->alg_key, key+1, keysize); 1190 memcpy(x->ealg->alg_key, key+1, keysize);
1191 } 1191 }
1192 x->props.ealgo = sa->sadb_sa_encrypt; 1192 x->props.ealgo = sa->sadb_sa_encrypt;
1193 x->geniv = a->uinfo.encr.geniv;
1193 } 1194 }
1194 } 1195 }
1195 /* x->algo.flags = sa->sadb_sa_flags; */ 1196 /* x->algo.flags = sa->sadb_sa_flags; */
diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c
index 2091664295ba..bd16c6c7e1e7 100644
--- a/net/xfrm/xfrm_user.c
+++ b/net/xfrm/xfrm_user.c
@@ -289,6 +289,31 @@ static int attach_one_algo(struct xfrm_algo **algpp, u8 *props,
289 return 0; 289 return 0;
290} 290}
291 291
292static int attach_crypt(struct xfrm_state *x, struct nlattr *rta)
293{
294 struct xfrm_algo *p, *ualg;
295 struct xfrm_algo_desc *algo;
296
297 if (!rta)
298 return 0;
299
300 ualg = nla_data(rta);
301
302 algo = xfrm_ealg_get_byname(ualg->alg_name, 1);
303 if (!algo)
304 return -ENOSYS;
305 x->props.ealgo = algo->desc.sadb_alg_id;
306
307 p = kmemdup(ualg, xfrm_alg_len(ualg), GFP_KERNEL);
308 if (!p)
309 return -ENOMEM;
310
311 strcpy(p->alg_name, algo->name);
312 x->ealg = p;
313 x->geniv = algo->uinfo.encr.geniv;
314 return 0;
315}
316
292static int attach_auth(struct xfrm_algo_auth **algpp, u8 *props, 317static int attach_auth(struct xfrm_algo_auth **algpp, u8 *props,
293 struct nlattr *rta) 318 struct nlattr *rta)
294{ 319{
@@ -349,8 +374,7 @@ static int attach_auth_trunc(struct xfrm_algo_auth **algpp, u8 *props,
349 return 0; 374 return 0;
350} 375}
351 376
352static int attach_aead(struct xfrm_algo_aead **algpp, u8 *props, 377static int attach_aead(struct xfrm_state *x, struct nlattr *rta)
353 struct nlattr *rta)
354{ 378{
355 struct xfrm_algo_aead *p, *ualg; 379 struct xfrm_algo_aead *p, *ualg;
356 struct xfrm_algo_desc *algo; 380 struct xfrm_algo_desc *algo;
@@ -363,14 +387,15 @@ static int attach_aead(struct xfrm_algo_aead **algpp, u8 *props,
363 algo = xfrm_aead_get_byname(ualg->alg_name, ualg->alg_icv_len, 1); 387 algo = xfrm_aead_get_byname(ualg->alg_name, ualg->alg_icv_len, 1);
364 if (!algo) 388 if (!algo)
365 return -ENOSYS; 389 return -ENOSYS;
366 *props = algo->desc.sadb_alg_id; 390 x->props.ealgo = algo->desc.sadb_alg_id;
367 391
368 p = kmemdup(ualg, aead_len(ualg), GFP_KERNEL); 392 p = kmemdup(ualg, aead_len(ualg), GFP_KERNEL);
369 if (!p) 393 if (!p)
370 return -ENOMEM; 394 return -ENOMEM;
371 395
372 strcpy(p->alg_name, algo->name); 396 strcpy(p->alg_name, algo->name);
373 *algpp = p; 397 x->aead = p;
398 x->geniv = algo->uinfo.aead.geniv;
374 return 0; 399 return 0;
375} 400}
376 401
@@ -515,8 +540,7 @@ static struct xfrm_state *xfrm_state_construct(struct net *net,
515 if (attrs[XFRMA_SA_EXTRA_FLAGS]) 540 if (attrs[XFRMA_SA_EXTRA_FLAGS])
516 x->props.extra_flags = nla_get_u32(attrs[XFRMA_SA_EXTRA_FLAGS]); 541 x->props.extra_flags = nla_get_u32(attrs[XFRMA_SA_EXTRA_FLAGS]);
517 542
518 if ((err = attach_aead(&x->aead, &x->props.ealgo, 543 if ((err = attach_aead(x, attrs[XFRMA_ALG_AEAD])))
519 attrs[XFRMA_ALG_AEAD])))
520 goto error; 544 goto error;
521 if ((err = attach_auth_trunc(&x->aalg, &x->props.aalgo, 545 if ((err = attach_auth_trunc(&x->aalg, &x->props.aalgo,
522 attrs[XFRMA_ALG_AUTH_TRUNC]))) 546 attrs[XFRMA_ALG_AUTH_TRUNC])))
@@ -526,9 +550,7 @@ static struct xfrm_state *xfrm_state_construct(struct net *net,
526 attrs[XFRMA_ALG_AUTH]))) 550 attrs[XFRMA_ALG_AUTH])))
527 goto error; 551 goto error;
528 } 552 }
529 if ((err = attach_one_algo(&x->ealg, &x->props.ealgo, 553 if ((err = attach_crypt(x, attrs[XFRMA_ALG_CRYPT])))
530 xfrm_ealg_get_byname,
531 attrs[XFRMA_ALG_CRYPT])))
532 goto error; 554 goto error;
533 if ((err = attach_one_algo(&x->calg, &x->props.calgo, 555 if ((err = attach_one_algo(&x->calg, &x->props.calgo,
534 xfrm_calg_get_byname, 556 xfrm_calg_get_byname,