diff options
author | Steffen Klassert <steffen.klassert@secunet.com> | 2011-03-28 15:46:39 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2011-03-29 02:34:52 -0400 |
commit | af2f464e326ebad57284cfdecb03f1606e89bbc7 (patch) | |
tree | 0b9f1e9918a47f49e1454a0df5e045a0d627050d | |
parent | 36ae0148dbb6b9e15d8f067bb7523fd2b765a6af (diff) |
xfrm: Assign esn pointers when cloning a state
When we clone a xfrm state we have to assign the replay_esn
and the preplay_esn pointers to the state if we use the
new replay detection method. To this end, we add a
xfrm_replay_clone() function that allocates memory for
the replay detection and takes over the necessary values
from the original state.
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
Acked-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | include/net/xfrm.h | 22 | ||||
-rw-r--r-- | net/xfrm/xfrm_state.c | 6 |
2 files changed, 28 insertions, 0 deletions
diff --git a/include/net/xfrm.h b/include/net/xfrm.h index cffa5dc66449..6ae4bc5ce8a7 100644 --- a/include/net/xfrm.h +++ b/include/net/xfrm.h | |||
@@ -1601,6 +1601,28 @@ static inline int xfrm_replay_state_esn_len(struct xfrm_replay_state_esn *replay | |||
1601 | } | 1601 | } |
1602 | 1602 | ||
1603 | #ifdef CONFIG_XFRM_MIGRATE | 1603 | #ifdef CONFIG_XFRM_MIGRATE |
1604 | static inline int xfrm_replay_clone(struct xfrm_state *x, | ||
1605 | struct xfrm_state *orig) | ||
1606 | { | ||
1607 | x->replay_esn = kzalloc(xfrm_replay_state_esn_len(orig->replay_esn), | ||
1608 | GFP_KERNEL); | ||
1609 | if (!x->replay_esn) | ||
1610 | return -ENOMEM; | ||
1611 | |||
1612 | x->replay_esn->bmp_len = orig->replay_esn->bmp_len; | ||
1613 | x->replay_esn->replay_window = orig->replay_esn->replay_window; | ||
1614 | |||
1615 | x->preplay_esn = kmemdup(x->replay_esn, | ||
1616 | xfrm_replay_state_esn_len(x->replay_esn), | ||
1617 | GFP_KERNEL); | ||
1618 | if (!x->preplay_esn) { | ||
1619 | kfree(x->replay_esn); | ||
1620 | return -ENOMEM; | ||
1621 | } | ||
1622 | |||
1623 | return 0; | ||
1624 | } | ||
1625 | |||
1604 | static inline struct xfrm_algo *xfrm_algo_clone(struct xfrm_algo *orig) | 1626 | static inline struct xfrm_algo *xfrm_algo_clone(struct xfrm_algo *orig) |
1605 | { | 1627 | { |
1606 | return kmemdup(orig, xfrm_alg_len(orig), GFP_KERNEL); | 1628 | return kmemdup(orig, xfrm_alg_len(orig), GFP_KERNEL); |
diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c index f83a3d1da81b..dd78536d40de 100644 --- a/net/xfrm/xfrm_state.c +++ b/net/xfrm/xfrm_state.c | |||
@@ -1181,6 +1181,12 @@ static struct xfrm_state *xfrm_state_clone(struct xfrm_state *orig, int *errp) | |||
1181 | goto error; | 1181 | goto error; |
1182 | } | 1182 | } |
1183 | 1183 | ||
1184 | if (orig->replay_esn) { | ||
1185 | err = xfrm_replay_clone(x, orig); | ||
1186 | if (err) | ||
1187 | goto error; | ||
1188 | } | ||
1189 | |||
1184 | memcpy(&x->mark, &orig->mark, sizeof(x->mark)); | 1190 | memcpy(&x->mark, &orig->mark, sizeof(x->mark)); |
1185 | 1191 | ||
1186 | err = xfrm_init_state(x); | 1192 | err = xfrm_init_state(x); |