Skip to content

Commit ffdb521

Browse files
ilantayariklassert
authored andcommitted
xfrm: Auto-load xfrm offload modules
IPSec crypto offload depends on the protocol-specific offload module (such as esp_offload.ko). When the user installs an SA with crypto-offload, load the offload module automatically, in the same way that the protocol module is loaded (such as esp.ko) Signed-off-by: Ilan Tayari <ilant@mellanox.com> Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
1 parent a9b28c2 commit ffdb521

File tree

6 files changed

+19
-7
lines changed

6 files changed

+19
-7
lines changed

include/net/xfrm.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
MODULE_ALIAS("xfrm-mode-" __stringify(family) "-" __stringify(encap))
4444
#define MODULE_ALIAS_XFRM_TYPE(family, proto) \
4545
MODULE_ALIAS("xfrm-type-" __stringify(family) "-" __stringify(proto))
46+
#define MODULE_ALIAS_XFRM_OFFLOAD_TYPE(family, proto) \
47+
MODULE_ALIAS("xfrm-offload-" __stringify(family) "-" __stringify(proto))
4648

4749
#ifdef CONFIG_XFRM_STATISTICS
4850
#define XFRM_INC_STATS(net, field) SNMP_INC_STATS((net)->mib.xfrm_statistics, field)
@@ -1558,7 +1560,7 @@ void xfrm_spd_getinfo(struct net *net, struct xfrmk_spdinfo *si);
15581560
u32 xfrm_replay_seqhi(struct xfrm_state *x, __be32 net_seq);
15591561
int xfrm_init_replay(struct xfrm_state *x);
15601562
int xfrm_state_mtu(struct xfrm_state *x, int mtu);
1561-
int __xfrm_init_state(struct xfrm_state *x, bool init_replay);
1563+
int __xfrm_init_state(struct xfrm_state *x, bool init_replay, bool offload);
15621564
int xfrm_init_state(struct xfrm_state *x);
15631565
int xfrm_prepare_input(struct xfrm_state *x, struct sk_buff *skb);
15641566
int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type);

net/ipv4/esp4_offload.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,3 +305,4 @@ module_init(esp4_offload_init);
305305
module_exit(esp4_offload_exit);
306306
MODULE_LICENSE("GPL");
307307
MODULE_AUTHOR("Steffen Klassert <steffen.klassert@secunet.com>");
308+
MODULE_ALIAS_XFRM_OFFLOAD_TYPE(AF_INET, XFRM_PROTO_ESP);

net/ipv6/esp6_offload.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,3 +334,4 @@ module_init(esp6_offload_init);
334334
module_exit(esp6_offload_exit);
335335
MODULE_LICENSE("GPL");
336336
MODULE_AUTHOR("Steffen Klassert <steffen.klassert@secunet.com>");
337+
MODULE_ALIAS_XFRM_OFFLOAD_TYPE(AF_INET6, XFRM_PROTO_ESP);

net/xfrm/xfrm_device.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ int xfrm_dev_state_add(struct net *net, struct xfrm_state *x,
6363
xfrm_address_t *daddr;
6464

6565
if (!x->type_offload)
66-
return 0;
66+
return -EINVAL;
6767

6868
/* We don't yet support UDP encapsulation, TFC padding and ESN. */
6969
if (x->encap || x->tfcpad || (x->props.flags & XFRM_STATE_ESN))

net/xfrm/xfrm_state.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,12 +296,14 @@ int xfrm_unregister_type_offload(const struct xfrm_type_offload *type,
296296
}
297297
EXPORT_SYMBOL(xfrm_unregister_type_offload);
298298

299-
static const struct xfrm_type_offload *xfrm_get_type_offload(u8 proto, unsigned short family)
299+
static const struct xfrm_type_offload *
300+
xfrm_get_type_offload(u8 proto, unsigned short family, bool try_load)
300301
{
301302
struct xfrm_state_afinfo *afinfo;
302303
const struct xfrm_type_offload **typemap;
303304
const struct xfrm_type_offload *type;
304305

306+
retry:
305307
afinfo = xfrm_state_get_afinfo(family);
306308
if (unlikely(afinfo == NULL))
307309
return NULL;
@@ -311,6 +313,12 @@ static const struct xfrm_type_offload *xfrm_get_type_offload(u8 proto, unsigned
311313
if ((type && !try_module_get(type->owner)))
312314
type = NULL;
313315

316+
if (!type && try_load) {
317+
request_module("xfrm-offload-%d-%d", family, proto);
318+
try_load = 0;
319+
goto retry;
320+
}
321+
314322
rcu_read_unlock();
315323
return type;
316324
}
@@ -2165,7 +2173,7 @@ int xfrm_state_mtu(struct xfrm_state *x, int mtu)
21652173
return mtu - x->props.header_len;
21662174
}
21672175

2168-
int __xfrm_init_state(struct xfrm_state *x, bool init_replay)
2176+
int __xfrm_init_state(struct xfrm_state *x, bool init_replay, bool offload)
21692177
{
21702178
struct xfrm_state_afinfo *afinfo;
21712179
struct xfrm_mode *inner_mode;
@@ -2230,7 +2238,7 @@ int __xfrm_init_state(struct xfrm_state *x, bool init_replay)
22302238
if (x->type == NULL)
22312239
goto error;
22322240

2233-
x->type_offload = xfrm_get_type_offload(x->id.proto, family);
2241+
x->type_offload = xfrm_get_type_offload(x->id.proto, family, offload);
22342242

22352243
err = x->type->init_state(x);
22362244
if (err)
@@ -2258,7 +2266,7 @@ EXPORT_SYMBOL(__xfrm_init_state);
22582266

22592267
int xfrm_init_state(struct xfrm_state *x)
22602268
{
2261-
return __xfrm_init_state(x, true);
2269+
return __xfrm_init_state(x, true, false);
22622270
}
22632271

22642272
EXPORT_SYMBOL(xfrm_init_state);

net/xfrm/xfrm_user.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ static struct xfrm_state *xfrm_state_construct(struct net *net,
584584

585585
xfrm_mark_get(attrs, &x->mark);
586586

587-
err = __xfrm_init_state(x, false);
587+
err = __xfrm_init_state(x, false, attrs[XFRMA_OFFLOAD_DEV]);
588588
if (err)
589589
goto error;
590590

0 commit comments

Comments
 (0)