Skip to content

Commit e8961c5

Browse files
Chiachang Wangklassert
authored andcommitted
xfrm: Refactor migration setup during the cloning process
Previously, migration related setup, such as updating family, destination address, and source address, was performed after the clone was created in `xfrm_state_migrate`. This change moves this setup into the cloning function itself, improving code locality and reducing redundancy. The `xfrm_state_clone_and_setup` function now conditionally applies the migration parameters from struct xfrm_migrate if it is provided. This allows the function to be used both for simple cloning and for cloning with migration setup. Test: Tested with kernel test in the Android tree located in https://android.googlesource.com/kernel/tests/ The xfrm_tunnel_test.py under the tests folder in particular. Signed-off-by: Chiachang Wang <[email protected]> Reviewed-by: Leon Romanovsky <[email protected]> Signed-off-by: Steffen Klassert <[email protected]>
1 parent ab244a3 commit e8961c5

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

net/xfrm/xfrm_state.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1958,8 +1958,9 @@ static inline int clone_security(struct xfrm_state *x, struct xfrm_sec_ctx *secu
19581958
return 0;
19591959
}
19601960

1961-
static struct xfrm_state *xfrm_state_clone(struct xfrm_state *orig,
1962-
struct xfrm_encap_tmpl *encap)
1961+
static struct xfrm_state *xfrm_state_clone_and_setup(struct xfrm_state *orig,
1962+
struct xfrm_encap_tmpl *encap,
1963+
struct xfrm_migrate *m)
19631964
{
19641965
struct net *net = xs_net(orig);
19651966
struct xfrm_state *x = xfrm_state_alloc(net);
@@ -2058,6 +2059,11 @@ static struct xfrm_state *xfrm_state_clone(struct xfrm_state *orig,
20582059
goto error;
20592060
}
20602061

2062+
2063+
x->props.family = m->new_family;
2064+
memcpy(&x->id.daddr, &m->new_daddr, sizeof(x->id.daddr));
2065+
memcpy(&x->props.saddr, &m->new_saddr, sizeof(x->props.saddr));
2066+
20612067
return x;
20622068

20632069
error:
@@ -2127,18 +2133,13 @@ struct xfrm_state *xfrm_state_migrate(struct xfrm_state *x,
21272133
{
21282134
struct xfrm_state *xc;
21292135

2130-
xc = xfrm_state_clone(x, encap);
2136+
xc = xfrm_state_clone_and_setup(x, encap, m);
21312137
if (!xc)
21322138
return NULL;
21332139

2134-
xc->props.family = m->new_family;
2135-
21362140
if (xfrm_init_state(xc) < 0)
21372141
goto error;
21382142

2139-
memcpy(&xc->id.daddr, &m->new_daddr, sizeof(xc->id.daddr));
2140-
memcpy(&xc->props.saddr, &m->new_saddr, sizeof(xc->props.saddr));
2141-
21422143
/* configure the hardware if offload is requested */
21432144
if (xuo && xfrm_dev_state_add(net, xc, xuo, extack))
21442145
goto error;

0 commit comments

Comments
 (0)