Skip to content

Commit c2bf84f

Browse files
rleonSaeed Mahameed
authored andcommitted
net/mlx5e: Tidy up IPsec NAT-T SA discovery
IPsec NAT-T packets are UDP encapsulated packets over ESP normal ones. In case they arrive to RX, the SPI and ESP are located in inner header, while the check was performed on outer header instead. That wrong check caused to the situation where received rekeying request was missed and caused to rekey timeout, which "compensated" this failure by completing rekeying. Fixes: d659549 ("net/mlx5e: Support IPsec NAT-T functionality") Signed-off-by: Leon Romanovsky <[email protected]>
1 parent dddb49b commit c2bf84f

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

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

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,13 +1212,22 @@ static void setup_fte_esp(struct mlx5_flow_spec *spec)
12121212
MLX5_SET(fte_match_param, spec->match_value, outer_headers.ip_protocol, IPPROTO_ESP);
12131213
}
12141214

1215-
static void setup_fte_spi(struct mlx5_flow_spec *spec, u32 spi)
1215+
static void setup_fte_spi(struct mlx5_flow_spec *spec, u32 spi, bool encap)
12161216
{
12171217
/* SPI number */
12181218
spec->match_criteria_enable |= MLX5_MATCH_MISC_PARAMETERS;
12191219

1220-
MLX5_SET_TO_ONES(fte_match_param, spec->match_criteria, misc_parameters.outer_esp_spi);
1221-
MLX5_SET(fte_match_param, spec->match_value, misc_parameters.outer_esp_spi, spi);
1220+
if (encap) {
1221+
MLX5_SET_TO_ONES(fte_match_param, spec->match_criteria,
1222+
misc_parameters.inner_esp_spi);
1223+
MLX5_SET(fte_match_param, spec->match_value,
1224+
misc_parameters.inner_esp_spi, spi);
1225+
} else {
1226+
MLX5_SET_TO_ONES(fte_match_param, spec->match_criteria,
1227+
misc_parameters.outer_esp_spi);
1228+
MLX5_SET(fte_match_param, spec->match_value,
1229+
misc_parameters.outer_esp_spi, spi);
1230+
}
12221231
}
12231232

12241233
static void setup_fte_no_frags(struct mlx5_flow_spec *spec)
@@ -1596,8 +1605,9 @@ static int rx_add_rule(struct mlx5e_ipsec_sa_entry *sa_entry)
15961605
else
15971606
setup_fte_addr6(spec, attrs->saddr.a6, attrs->daddr.a6);
15981607

1599-
setup_fte_spi(spec, attrs->spi);
1600-
setup_fte_esp(spec);
1608+
setup_fte_spi(spec, attrs->spi, attrs->encap);
1609+
if (!attrs->encap)
1610+
setup_fte_esp(spec);
16011611
setup_fte_no_frags(spec);
16021612
setup_fte_upper_proto_match(spec, &attrs->upspec);
16031613

@@ -1719,7 +1729,7 @@ static int tx_add_rule(struct mlx5e_ipsec_sa_entry *sa_entry)
17191729

17201730
switch (attrs->type) {
17211731
case XFRM_DEV_OFFLOAD_CRYPTO:
1722-
setup_fte_spi(spec, attrs->spi);
1732+
setup_fte_spi(spec, attrs->spi, false);
17231733
setup_fte_esp(spec);
17241734
setup_fte_reg_a(spec);
17251735
break;

include/linux/mlx5/mlx5_ifc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ struct mlx5_ifc_fte_match_set_misc_bits {
621621

622622
u8 reserved_at_140[0x8];
623623
u8 bth_dst_qp[0x18];
624-
u8 reserved_at_160[0x20];
624+
u8 inner_esp_spi[0x20];
625625
u8 outer_esp_spi[0x20];
626626
u8 reserved_at_1a0[0x60];
627627
};

0 commit comments

Comments
 (0)