Commit 69b0137f authored by Herbert Xu's avatar Herbert Xu

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: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 165ecc63
...@@ -168,6 +168,7 @@ struct xfrm_state { ...@@ -168,6 +168,7 @@ struct xfrm_state {
struct xfrm_algo *ealg; struct xfrm_algo *ealg;
struct xfrm_algo *calg; struct xfrm_algo *calg;
struct xfrm_algo_aead *aead; struct xfrm_algo_aead *aead;
const char *geniv;
/* Data for encapsulator */ /* Data for encapsulator */
struct xfrm_encap_tmpl *encap; struct xfrm_encap_tmpl *encap;
......
...@@ -1190,6 +1190,7 @@ static struct xfrm_state * pfkey_msg2xfrm_state(struct net *net, ...@@ -1190,6 +1190,7 @@ static struct xfrm_state * pfkey_msg2xfrm_state(struct net *net,
memcpy(x->ealg->alg_key, key+1, keysize); memcpy(x->ealg->alg_key, key+1, keysize);
} }
x->props.ealgo = sa->sadb_sa_encrypt; x->props.ealgo = sa->sadb_sa_encrypt;
x->geniv = a->uinfo.encr.geniv;
} }
} }
/* x->algo.flags = sa->sadb_sa_flags; */ /* x->algo.flags = sa->sadb_sa_flags; */
......
...@@ -289,6 +289,31 @@ static int attach_one_algo(struct xfrm_algo **algpp, u8 *props, ...@@ -289,6 +289,31 @@ static int attach_one_algo(struct xfrm_algo **algpp, u8 *props,
return 0; return 0;
} }
static int attach_crypt(struct xfrm_state *x, struct nlattr *rta)
{
struct xfrm_algo *p, *ualg;
struct xfrm_algo_desc *algo;
if (!rta)
return 0;
ualg = nla_data(rta);
algo = xfrm_ealg_get_byname(ualg->alg_name, 1);
if (!algo)
return -ENOSYS;
x->props.ealgo = algo->desc.sadb_alg_id;
p = kmemdup(ualg, xfrm_alg_len(ualg), GFP_KERNEL);
if (!p)
return -ENOMEM;
strcpy(p->alg_name, algo->name);
x->ealg = p;
x->geniv = algo->uinfo.encr.geniv;
return 0;
}
static int attach_auth(struct xfrm_algo_auth **algpp, u8 *props, static int attach_auth(struct xfrm_algo_auth **algpp, u8 *props,
struct nlattr *rta) struct nlattr *rta)
{ {
...@@ -349,8 +374,7 @@ static int attach_auth_trunc(struct xfrm_algo_auth **algpp, u8 *props, ...@@ -349,8 +374,7 @@ static int attach_auth_trunc(struct xfrm_algo_auth **algpp, u8 *props,
return 0; return 0;
} }
static int attach_aead(struct xfrm_algo_aead **algpp, u8 *props, static int attach_aead(struct xfrm_state *x, struct nlattr *rta)
struct nlattr *rta)
{ {
struct xfrm_algo_aead *p, *ualg; struct xfrm_algo_aead *p, *ualg;
struct xfrm_algo_desc *algo; struct xfrm_algo_desc *algo;
...@@ -363,14 +387,15 @@ static int attach_aead(struct xfrm_algo_aead **algpp, u8 *props, ...@@ -363,14 +387,15 @@ static int attach_aead(struct xfrm_algo_aead **algpp, u8 *props,
algo = xfrm_aead_get_byname(ualg->alg_name, ualg->alg_icv_len, 1); algo = xfrm_aead_get_byname(ualg->alg_name, ualg->alg_icv_len, 1);
if (!algo) if (!algo)
return -ENOSYS; return -ENOSYS;
*props = algo->desc.sadb_alg_id; x->props.ealgo = algo->desc.sadb_alg_id;
p = kmemdup(ualg, aead_len(ualg), GFP_KERNEL); p = kmemdup(ualg, aead_len(ualg), GFP_KERNEL);
if (!p) if (!p)
return -ENOMEM; return -ENOMEM;
strcpy(p->alg_name, algo->name); strcpy(p->alg_name, algo->name);
*algpp = p; x->aead = p;
x->geniv = algo->uinfo.aead.geniv;
return 0; return 0;
} }
...@@ -515,8 +540,7 @@ static struct xfrm_state *xfrm_state_construct(struct net *net, ...@@ -515,8 +540,7 @@ static struct xfrm_state *xfrm_state_construct(struct net *net,
if (attrs[XFRMA_SA_EXTRA_FLAGS]) if (attrs[XFRMA_SA_EXTRA_FLAGS])
x->props.extra_flags = nla_get_u32(attrs[XFRMA_SA_EXTRA_FLAGS]); x->props.extra_flags = nla_get_u32(attrs[XFRMA_SA_EXTRA_FLAGS]);
if ((err = attach_aead(&x->aead, &x->props.ealgo, if ((err = attach_aead(x, attrs[XFRMA_ALG_AEAD])))
attrs[XFRMA_ALG_AEAD])))
goto error; goto error;
if ((err = attach_auth_trunc(&x->aalg, &x->props.aalgo, if ((err = attach_auth_trunc(&x->aalg, &x->props.aalgo,
attrs[XFRMA_ALG_AUTH_TRUNC]))) attrs[XFRMA_ALG_AUTH_TRUNC])))
...@@ -526,9 +550,7 @@ static struct xfrm_state *xfrm_state_construct(struct net *net, ...@@ -526,9 +550,7 @@ static struct xfrm_state *xfrm_state_construct(struct net *net,
attrs[XFRMA_ALG_AUTH]))) attrs[XFRMA_ALG_AUTH])))
goto error; goto error;
} }
if ((err = attach_one_algo(&x->ealg, &x->props.ealgo, if ((err = attach_crypt(x, attrs[XFRMA_ALG_CRYPT])))
xfrm_ealg_get_byname,
attrs[XFRMA_ALG_CRYPT])))
goto error; goto error;
if ((err = attach_one_algo(&x->calg, &x->props.calgo, if ((err = attach_one_algo(&x->calg, &x->props.calgo,
xfrm_calg_get_byname, xfrm_calg_get_byname,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment