Skip to content

Commit b3859c8

Browse files
committed
esp: Use a synchronous crypto algorithm on offloading.
We need a fallback algorithm for crypto offloading to a NIC. This is because packets can be rerouted to other NICs that don't support crypto offloading. The fallback is going to be implemented at layer2 where we know the final output device but can't handle asynchronous returns fron the crypto layer. Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
1 parent d7dbefc commit b3859c8

2 files changed

Lines changed: 20 additions & 4 deletions

File tree

‎net/ipv4/esp4.c‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -783,13 +783,17 @@ static int esp_init_aead(struct xfrm_state *x)
783783
char aead_name[CRYPTO_MAX_ALG_NAME];
784784
struct crypto_aead *aead;
785785
int err;
786+
u32 mask = 0;
786787

787788
err = -ENAMETOOLONG;
788789
if (snprintf(aead_name, CRYPTO_MAX_ALG_NAME, "%s(%s)",
789790
x->geniv, x->aead->alg_name) >= CRYPTO_MAX_ALG_NAME)
790791
goto error;
791792

792-
aead = crypto_alloc_aead(aead_name, 0, 0);
793+
if (x->xso.offload_handle)
794+
mask |= CRYPTO_ALG_ASYNC;
795+
796+
aead = crypto_alloc_aead(aead_name, 0, mask);
793797
err = PTR_ERR(aead);
794798
if (IS_ERR(aead))
795799
goto error;
@@ -819,6 +823,7 @@ static int esp_init_authenc(struct xfrm_state *x)
819823
char authenc_name[CRYPTO_MAX_ALG_NAME];
820824
unsigned int keylen;
821825
int err;
826+
u32 mask = 0;
822827

823828
err = -EINVAL;
824829
if (!x->ealg)
@@ -844,7 +849,10 @@ static int esp_init_authenc(struct xfrm_state *x)
844849
goto error;
845850
}
846851

847-
aead = crypto_alloc_aead(authenc_name, 0, 0);
852+
if (x->xso.offload_handle)
853+
mask |= CRYPTO_ALG_ASYNC;
854+
855+
aead = crypto_alloc_aead(authenc_name, 0, mask);
848856
err = PTR_ERR(aead);
849857
if (IS_ERR(aead))
850858
goto error;

‎net/ipv6/esp6.c‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -704,13 +704,17 @@ static int esp_init_aead(struct xfrm_state *x)
704704
char aead_name[CRYPTO_MAX_ALG_NAME];
705705
struct crypto_aead *aead;
706706
int err;
707+
u32 mask = 0;
707708

708709
err = -ENAMETOOLONG;
709710
if (snprintf(aead_name, CRYPTO_MAX_ALG_NAME, "%s(%s)",
710711
x->geniv, x->aead->alg_name) >= CRYPTO_MAX_ALG_NAME)
711712
goto error;
712713

713-
aead = crypto_alloc_aead(aead_name, 0, 0);
714+
if (x->xso.offload_handle)
715+
mask |= CRYPTO_ALG_ASYNC;
716+
717+
aead = crypto_alloc_aead(aead_name, 0, mask);
714718
err = PTR_ERR(aead);
715719
if (IS_ERR(aead))
716720
goto error;
@@ -740,6 +744,7 @@ static int esp_init_authenc(struct xfrm_state *x)
740744
char authenc_name[CRYPTO_MAX_ALG_NAME];
741745
unsigned int keylen;
742746
int err;
747+
u32 mask = 0;
743748

744749
err = -EINVAL;
745750
if (!x->ealg)
@@ -765,7 +770,10 @@ static int esp_init_authenc(struct xfrm_state *x)
765770
goto error;
766771
}
767772

768-
aead = crypto_alloc_aead(authenc_name, 0, 0);
773+
if (x->xso.offload_handle)
774+
mask |= CRYPTO_ALG_ASYNC;
775+
776+
aead = crypto_alloc_aead(authenc_name, 0, mask);
769777
err = PTR_ERR(aead);
770778
if (IS_ERR(aead))
771779
goto error;

0 commit comments

Comments
 (0)