Skip to content

Commit efbd31c

Browse files
rleonkuba-moo
authored andcommitted
net/mlx5e: Support IPsec TX packet offload in tunnel mode
Extend mlx5 driver with logic to support IPsec TX packet offload in tunnel mode. Signed-off-by: Leon Romanovsky <[email protected]> Reviewed-by: Simon Horman <[email protected]> Reviewed-by: Sridhar Samudrala <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 37a417c commit efbd31c

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,18 @@ static void mlx5e_ipsec_init_macs(struct mlx5e_ipsec_sa_entry *sa_entry,
271271
neigh_ha_snapshot(addr, n, netdev);
272272
ether_addr_copy(attrs->smac, addr);
273273
break;
274+
case XFRM_DEV_OFFLOAD_OUT:
275+
ether_addr_copy(attrs->smac, addr);
276+
n = neigh_lookup(&arp_tbl, &attrs->daddr.a4, netdev);
277+
if (!n) {
278+
n = neigh_create(&arp_tbl, &attrs->daddr.a4, netdev);
279+
if (IS_ERR(n))
280+
return;
281+
neigh_event_send(n, NULL);
282+
}
283+
neigh_ha_snapshot(addr, n, netdev);
284+
ether_addr_copy(attrs->dmac, addr);
285+
break;
274286
default:
275287
return;
276288
}

drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec_fs.c

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#define NUM_IPSEC_FTE BIT(15)
1313
#define MLX5_REFORMAT_TYPE_ADD_ESP_TRANSPORT_SIZE 16
14+
#define IPSEC_TUNNEL_DEFAULT_TTL 0x40
1415

1516
struct mlx5e_ipsec_fc {
1617
struct mlx5_fc *cnt;
@@ -842,12 +843,31 @@ setup_pkt_tunnel_reformat(struct mlx5_core_dev *mdev,
842843
struct mlx5_accel_esp_xfrm_attrs *attrs,
843844
struct mlx5_pkt_reformat_params *reformat_params)
844845
{
846+
struct ip_esp_hdr *esp_hdr;
847+
struct ipv6hdr *ipv6hdr;
845848
struct ethhdr *eth_hdr;
849+
struct iphdr *iphdr;
846850
char *reformatbf;
847851
size_t bfflen;
852+
void *hdr;
848853

849854
bfflen = sizeof(*eth_hdr);
850855

856+
if (attrs->dir == XFRM_DEV_OFFLOAD_OUT) {
857+
bfflen += sizeof(*esp_hdr) + 8;
858+
859+
switch (attrs->family) {
860+
case AF_INET:
861+
bfflen += sizeof(*iphdr);
862+
break;
863+
case AF_INET6:
864+
bfflen += sizeof(*ipv6hdr);
865+
break;
866+
default:
867+
return -EINVAL;
868+
}
869+
}
870+
851871
reformatbf = kzalloc(bfflen, GFP_KERNEL);
852872
if (!reformatbf)
853873
return -ENOMEM;
@@ -871,6 +891,38 @@ setup_pkt_tunnel_reformat(struct mlx5_core_dev *mdev,
871891
case XFRM_DEV_OFFLOAD_IN:
872892
reformat_params->type = MLX5_REFORMAT_TYPE_L3_ESP_TUNNEL_TO_L2;
873893
break;
894+
case XFRM_DEV_OFFLOAD_OUT:
895+
reformat_params->type = MLX5_REFORMAT_TYPE_L2_TO_L3_ESP_TUNNEL;
896+
reformat_params->param_0 = attrs->authsize;
897+
898+
hdr = reformatbf + sizeof(*eth_hdr);
899+
switch (attrs->family) {
900+
case AF_INET:
901+
iphdr = (struct iphdr *)hdr;
902+
memcpy(&iphdr->saddr, &attrs->saddr.a4, 4);
903+
memcpy(&iphdr->daddr, &attrs->daddr.a4, 4);
904+
iphdr->version = 4;
905+
iphdr->ihl = 5;
906+
iphdr->ttl = IPSEC_TUNNEL_DEFAULT_TTL;
907+
iphdr->protocol = IPPROTO_ESP;
908+
hdr += sizeof(*iphdr);
909+
break;
910+
case AF_INET6:
911+
ipv6hdr = (struct ipv6hdr *)hdr;
912+
memcpy(&ipv6hdr->saddr, &attrs->saddr.a6, 16);
913+
memcpy(&ipv6hdr->daddr, &attrs->daddr.a6, 16);
914+
ipv6hdr->nexthdr = IPPROTO_ESP;
915+
ipv6hdr->version = 6;
916+
ipv6hdr->hop_limit = IPSEC_TUNNEL_DEFAULT_TTL;
917+
hdr += sizeof(*ipv6hdr);
918+
break;
919+
default:
920+
goto free_reformatbf;
921+
}
922+
923+
esp_hdr = (struct ip_esp_hdr *)hdr;
924+
esp_hdr->spi = htonl(attrs->spi);
925+
break;
874926
default:
875927
goto free_reformatbf;
876928
}

0 commit comments

Comments
 (0)