Skip to content

Commit 86e530c

Browse files
committed
Merge branch 'Update offload configuration with SA'
Chiachang Wang says: ==================== The current Security Association (SA) offload setting cannot be modified without removing and re-adding the SA with the new configuration. Although existing netlink messages allow SA migration, the offload setting will be removed after migration. This patchset enhances SA migration to include updating the offload setting. This is beneficial for devices that support IPsec session management. ==================== Signed-off-by: Steffen Klassert <[email protected]>
2 parents 197c297 + e8961c5 commit 86e530c

File tree

5 files changed

+37
-16
lines changed

5 files changed

+37
-16
lines changed

include/net/xfrm.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1904,12 +1904,16 @@ struct xfrm_state *xfrm_migrate_state_find(struct xfrm_migrate *m, struct net *n
19041904
u32 if_id);
19051905
struct xfrm_state *xfrm_state_migrate(struct xfrm_state *x,
19061906
struct xfrm_migrate *m,
1907-
struct xfrm_encap_tmpl *encap);
1907+
struct xfrm_encap_tmpl *encap,
1908+
struct net *net,
1909+
struct xfrm_user_offload *xuo,
1910+
struct netlink_ext_ack *extack);
19081911
int xfrm_migrate(const struct xfrm_selector *sel, u8 dir, u8 type,
19091912
struct xfrm_migrate *m, int num_bundles,
19101913
struct xfrm_kmaddress *k, struct net *net,
19111914
struct xfrm_encap_tmpl *encap, u32 if_id,
1912-
struct netlink_ext_ack *extack);
1915+
struct netlink_ext_ack *extack,
1916+
struct xfrm_user_offload *xuo);
19131917
#endif
19141918

19151919
int km_new_mapping(struct xfrm_state *x, xfrm_address_t *ipaddr, __be16 sport);

net/key/af_key.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2630,7 +2630,7 @@ static int pfkey_migrate(struct sock *sk, struct sk_buff *skb,
26302630
}
26312631

26322632
return xfrm_migrate(&sel, dir, XFRM_POLICY_TYPE_MAIN, m, i,
2633-
kma ? &k : NULL, net, NULL, 0, NULL);
2633+
kma ? &k : NULL, net, NULL, 0, NULL, NULL);
26342634

26352635
out:
26362636
return err;

net/xfrm/xfrm_policy.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4630,7 +4630,7 @@ int xfrm_migrate(const struct xfrm_selector *sel, u8 dir, u8 type,
46304630
struct xfrm_migrate *m, int num_migrate,
46314631
struct xfrm_kmaddress *k, struct net *net,
46324632
struct xfrm_encap_tmpl *encap, u32 if_id,
4633-
struct netlink_ext_ack *extack)
4633+
struct netlink_ext_ack *extack, struct xfrm_user_offload *xuo)
46344634
{
46354635
int i, err, nx_cur = 0, nx_new = 0;
46364636
struct xfrm_policy *pol = NULL;
@@ -4663,7 +4663,7 @@ int xfrm_migrate(const struct xfrm_selector *sel, u8 dir, u8 type,
46634663
if ((x = xfrm_migrate_state_find(mp, net, if_id))) {
46644664
x_cur[nx_cur] = x;
46654665
nx_cur++;
4666-
xc = xfrm_state_migrate(x, mp, encap);
4666+
xc = xfrm_state_migrate(x, mp, encap, net, xuo, extack);
46674667
if (xc) {
46684668
x_new[nx_new] = xc;
46694669
nx_new++;

net/xfrm/xfrm_state.c

Lines changed: 16 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:
@@ -2120,21 +2126,23 @@ EXPORT_SYMBOL(xfrm_migrate_state_find);
21202126

21212127
struct xfrm_state *xfrm_state_migrate(struct xfrm_state *x,
21222128
struct xfrm_migrate *m,
2123-
struct xfrm_encap_tmpl *encap)
2129+
struct xfrm_encap_tmpl *encap,
2130+
struct net *net,
2131+
struct xfrm_user_offload *xuo,
2132+
struct netlink_ext_ack *extack)
21242133
{
21252134
struct xfrm_state *xc;
21262135

2127-
xc = xfrm_state_clone(x, encap);
2136+
xc = xfrm_state_clone_and_setup(x, encap, m);
21282137
if (!xc)
21292138
return NULL;
21302139

2131-
xc->props.family = m->new_family;
2132-
21332140
if (xfrm_init_state(xc) < 0)
21342141
goto error;
21352142

2136-
memcpy(&xc->id.daddr, &m->new_daddr, sizeof(xc->id.daddr));
2137-
memcpy(&xc->props.saddr, &m->new_saddr, sizeof(xc->props.saddr));
2143+
/* configure the hardware if offload is requested */
2144+
if (xuo && xfrm_dev_state_add(net, xc, xuo, extack))
2145+
goto error;
21382146

21392147
/* add state */
21402148
if (xfrm_addr_equal(&x->id.daddr, &m->new_daddr, m->new_family)) {

net/xfrm/xfrm_user.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3069,6 +3069,7 @@ static int xfrm_do_migrate(struct sk_buff *skb, struct nlmsghdr *nlh,
30693069
int n = 0;
30703070
struct net *net = sock_net(skb->sk);
30713071
struct xfrm_encap_tmpl *encap = NULL;
3072+
struct xfrm_user_offload *xuo = NULL;
30723073
u32 if_id = 0;
30733074

30743075
if (!attrs[XFRMA_MIGRATE]) {
@@ -3099,11 +3100,19 @@ static int xfrm_do_migrate(struct sk_buff *skb, struct nlmsghdr *nlh,
30993100
if (attrs[XFRMA_IF_ID])
31003101
if_id = nla_get_u32(attrs[XFRMA_IF_ID]);
31013102

3103+
if (attrs[XFRMA_OFFLOAD_DEV]) {
3104+
xuo = kmemdup(nla_data(attrs[XFRMA_OFFLOAD_DEV]),
3105+
sizeof(*xuo), GFP_KERNEL);
3106+
if (!xuo) {
3107+
err = -ENOMEM;
3108+
goto error;
3109+
}
3110+
}
31023111
err = xfrm_migrate(&pi->sel, pi->dir, type, m, n, kmp, net, encap,
3103-
if_id, extack);
3104-
3112+
if_id, extack, xuo);
3113+
error:
31053114
kfree(encap);
3106-
3115+
kfree(xuo);
31073116
return err;
31083117
}
31093118
#else

0 commit comments

Comments
 (0)