Skip to content

Commit 348ed4b

Browse files
rleonkuba-moo
authored andcommitted
net/mlx5e: Separate address related variables to be in struct
Prepare the code to addition of prefix handling logic which is needed to support matching logic based on source and/or destination network prefixes. Signed-off-by: Leon Romanovsky <[email protected]> Signed-off-by: Tariq Toukan <[email protected]> Reviewed-by: Michal Swiatkowski <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 5aa2e6d commit 348ed4b

File tree

3 files changed

+68
-65
lines changed

3 files changed

+68
-65
lines changed

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

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -277,12 +277,12 @@ static void mlx5e_ipsec_init_macs(struct mlx5e_ipsec_sa_entry *sa_entry,
277277
case XFRM_DEV_OFFLOAD_IN:
278278
src = attrs->dmac;
279279
dst = attrs->smac;
280-
pkey = &attrs->saddr.a4;
280+
pkey = &attrs->addrs.saddr.a4;
281281
break;
282282
case XFRM_DEV_OFFLOAD_OUT:
283283
src = attrs->smac;
284284
dst = attrs->dmac;
285-
pkey = &attrs->daddr.a4;
285+
pkey = &attrs->addrs.daddr.a4;
286286
break;
287287
default:
288288
return;
@@ -374,9 +374,10 @@ void mlx5e_ipsec_build_accel_xfrm_attrs(struct mlx5e_ipsec_sa_entry *sa_entry,
374374
attrs->spi = be32_to_cpu(x->id.spi);
375375

376376
/* source , destination ips */
377-
memcpy(&attrs->saddr, x->props.saddr.a6, sizeof(attrs->saddr));
378-
memcpy(&attrs->daddr, x->id.daddr.a6, sizeof(attrs->daddr));
379-
attrs->family = x->props.family;
377+
memcpy(&attrs->addrs.saddr, x->props.saddr.a6,
378+
sizeof(attrs->addrs.saddr));
379+
memcpy(&attrs->addrs.daddr, x->id.daddr.a6, sizeof(attrs->addrs.daddr));
380+
attrs->addrs.family = x->props.family;
380381
attrs->type = x->xso.type;
381382
attrs->reqid = x->props.reqid;
382383
attrs->upspec.dport = ntohs(x->sel.dport);
@@ -428,7 +429,8 @@ static int mlx5e_xfrm_validate_state(struct mlx5_core_dev *mdev,
428429
}
429430
if (x->encap) {
430431
if (!(mlx5_ipsec_device_caps(mdev) & MLX5_IPSEC_CAP_ESPINUDP)) {
431-
NL_SET_ERR_MSG_MOD(extack, "Encapsulation is not supported");
432+
NL_SET_ERR_MSG_MOD(extack,
433+
"Encapsulation is not supported");
432434
return -EINVAL;
433435
}
434436

@@ -853,13 +855,13 @@ static int mlx5e_ipsec_netevent_event(struct notifier_block *nb,
853855
xa_for_each_marked(&ipsec->sadb, idx, sa_entry, MLX5E_IPSEC_TUNNEL_SA) {
854856
attrs = &sa_entry->attrs;
855857

856-
if (attrs->family == AF_INET) {
857-
if (!neigh_key_eq32(n, &attrs->saddr.a4) &&
858-
!neigh_key_eq32(n, &attrs->daddr.a4))
858+
if (attrs->addrs.family == AF_INET) {
859+
if (!neigh_key_eq32(n, &attrs->addrs.saddr.a4) &&
860+
!neigh_key_eq32(n, &attrs->addrs.daddr.a4))
859861
continue;
860862
} else {
861-
if (!neigh_key_eq128(n, &attrs->saddr.a4) &&
862-
!neigh_key_eq128(n, &attrs->daddr.a4))
863+
if (!neigh_key_eq128(n, &attrs->addrs.saddr.a4) &&
864+
!neigh_key_eq128(n, &attrs->addrs.daddr.a4))
863865
continue;
864866
}
865867

@@ -1035,7 +1037,7 @@ static void mlx5e_xfrm_update_stats(struct xfrm_state *x)
10351037
* by removing always available headers.
10361038
*/
10371039
headers = sizeof(struct ethhdr);
1038-
if (sa_entry->attrs.family == AF_INET)
1040+
if (sa_entry->attrs.addrs.family == AF_INET)
10391041
headers += sizeof(struct iphdr);
10401042
else
10411043
headers += sizeof(struct ipv6hdr);
@@ -1116,9 +1118,9 @@ mlx5e_ipsec_build_accel_pol_attrs(struct mlx5e_ipsec_pol_entry *pol_entry,
11161118
sel = &x->selector;
11171119
memset(attrs, 0, sizeof(*attrs));
11181120

1119-
memcpy(&attrs->saddr, sel->saddr.a6, sizeof(attrs->saddr));
1120-
memcpy(&attrs->daddr, sel->daddr.a6, sizeof(attrs->daddr));
1121-
attrs->family = sel->family;
1121+
memcpy(&attrs->addrs.saddr, sel->saddr.a6, sizeof(attrs->addrs.saddr));
1122+
memcpy(&attrs->addrs.daddr, sel->daddr.a6, sizeof(attrs->addrs.daddr));
1123+
attrs->addrs.family = sel->family;
11221124
attrs->dir = x->xdo.dir;
11231125
attrs->action = x->action;
11241126
attrs->type = XFRM_DEV_OFFLOAD_PACKET;

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

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,7 @@ struct mlx5_replay_esn {
7676
u8 trigger : 1;
7777
};
7878

79-
struct mlx5_accel_esp_xfrm_attrs {
80-
u32 spi;
81-
u32 mode;
82-
struct aes_gcm_keymat aes_gcm;
83-
79+
struct mlx5e_ipsec_addr {
8480
union {
8581
__be32 a4;
8682
__be32 a6[4];
@@ -90,13 +86,19 @@ struct mlx5_accel_esp_xfrm_attrs {
9086
__be32 a4;
9187
__be32 a6[4];
9288
} daddr;
89+
u8 family;
90+
};
9391

92+
struct mlx5_accel_esp_xfrm_attrs {
93+
u32 spi;
94+
u32 mode;
95+
struct aes_gcm_keymat aes_gcm;
96+
struct mlx5e_ipsec_addr addrs;
9497
struct upspec upspec;
9598
u8 dir : 2;
9699
u8 type : 2;
97100
u8 drop : 1;
98101
u8 encap : 1;
99-
u8 family;
100102
struct mlx5_replay_esn replay_esn;
101103
u32 authsize;
102104
u32 reqid;
@@ -279,18 +281,8 @@ struct mlx5e_ipsec_sa_entry {
279281
};
280282

281283
struct mlx5_accel_pol_xfrm_attrs {
282-
union {
283-
__be32 a4;
284-
__be32 a6[4];
285-
} saddr;
286-
287-
union {
288-
__be32 a4;
289-
__be32 a6[4];
290-
} daddr;
291-
284+
struct mlx5e_ipsec_addr addrs;
292285
struct upspec upspec;
293-
u8 family;
294286
u8 action;
295287
u8 type : 2;
296288
u8 dir : 2;

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

Lines changed: 42 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,9 +1484,12 @@ static void tx_ft_put_policy(struct mlx5e_ipsec *ipsec, u32 prio, int type)
14841484
mutex_unlock(&tx->ft.mutex);
14851485
}
14861486

1487-
static void setup_fte_addr4(struct mlx5_flow_spec *spec, __be32 *saddr,
1488-
__be32 *daddr)
1487+
static void setup_fte_addr4(struct mlx5_flow_spec *spec,
1488+
struct mlx5e_ipsec_addr *addrs)
14891489
{
1490+
__be32 *saddr = &addrs->saddr.a4;
1491+
__be32 *daddr = &addrs->daddr.a4;
1492+
14901493
if (!*saddr && !*daddr)
14911494
return;
14921495

@@ -1510,9 +1513,12 @@ static void setup_fte_addr4(struct mlx5_flow_spec *spec, __be32 *saddr,
15101513
}
15111514
}
15121515

1513-
static void setup_fte_addr6(struct mlx5_flow_spec *spec, __be32 *saddr,
1514-
__be32 *daddr)
1516+
static void setup_fte_addr6(struct mlx5_flow_spec *spec,
1517+
struct mlx5e_ipsec_addr *addrs)
15151518
{
1519+
__be32 *saddr = addrs->saddr.a6;
1520+
__be32 *daddr = addrs->daddr.a6;
1521+
15161522
if (addr6_all_zero(saddr) && addr6_all_zero(daddr))
15171523
return;
15181524

@@ -1722,7 +1728,7 @@ setup_pkt_tunnel_reformat(struct mlx5_core_dev *mdev,
17221728
if (attrs->dir == XFRM_DEV_OFFLOAD_OUT) {
17231729
bfflen += sizeof(*esp_hdr) + 8;
17241730

1725-
switch (attrs->family) {
1731+
switch (attrs->addrs.family) {
17261732
case AF_INET:
17271733
bfflen += sizeof(*iphdr);
17281734
break;
@@ -1739,7 +1745,7 @@ setup_pkt_tunnel_reformat(struct mlx5_core_dev *mdev,
17391745
return -ENOMEM;
17401746

17411747
eth_hdr = (struct ethhdr *)reformatbf;
1742-
switch (attrs->family) {
1748+
switch (attrs->addrs.family) {
17431749
case AF_INET:
17441750
eth_hdr->h_proto = htons(ETH_P_IP);
17451751
break;
@@ -1762,11 +1768,11 @@ setup_pkt_tunnel_reformat(struct mlx5_core_dev *mdev,
17621768
reformat_params->param_0 = attrs->authsize;
17631769

17641770
hdr = reformatbf + sizeof(*eth_hdr);
1765-
switch (attrs->family) {
1771+
switch (attrs->addrs.family) {
17661772
case AF_INET:
17671773
iphdr = (struct iphdr *)hdr;
1768-
memcpy(&iphdr->saddr, &attrs->saddr.a4, 4);
1769-
memcpy(&iphdr->daddr, &attrs->daddr.a4, 4);
1774+
memcpy(&iphdr->saddr, &attrs->addrs.saddr.a4, 4);
1775+
memcpy(&iphdr->daddr, &attrs->addrs.daddr.a4, 4);
17701776
iphdr->version = 4;
17711777
iphdr->ihl = 5;
17721778
iphdr->ttl = IPSEC_TUNNEL_DEFAULT_TTL;
@@ -1775,8 +1781,8 @@ setup_pkt_tunnel_reformat(struct mlx5_core_dev *mdev,
17751781
break;
17761782
case AF_INET6:
17771783
ipv6hdr = (struct ipv6hdr *)hdr;
1778-
memcpy(&ipv6hdr->saddr, &attrs->saddr.a6, 16);
1779-
memcpy(&ipv6hdr->daddr, &attrs->daddr.a6, 16);
1784+
memcpy(&ipv6hdr->saddr, &attrs->addrs.saddr.a6, 16);
1785+
memcpy(&ipv6hdr->daddr, &attrs->addrs.daddr.a6, 16);
17801786
ipv6hdr->nexthdr = IPPROTO_ESP;
17811787
ipv6hdr->version = 6;
17821788
ipv6hdr->hop_limit = IPSEC_TUNNEL_DEFAULT_TTL;
@@ -1810,7 +1816,7 @@ static int get_reformat_type(struct mlx5_accel_esp_xfrm_attrs *attrs)
18101816
return MLX5_REFORMAT_TYPE_DEL_ESP_TRANSPORT_OVER_UDP;
18111817
return MLX5_REFORMAT_TYPE_DEL_ESP_TRANSPORT;
18121818
case XFRM_DEV_OFFLOAD_OUT:
1813-
if (attrs->family == AF_INET) {
1819+
if (attrs->addrs.family == AF_INET) {
18141820
if (attrs->encap)
18151821
return MLX5_REFORMAT_TYPE_ADD_ESP_TRANSPORT_OVER_UDPV4;
18161822
return MLX5_REFORMAT_TYPE_ADD_ESP_TRANSPORT_OVER_IPV4;
@@ -2003,7 +2009,7 @@ static int rx_add_rule(struct mlx5e_ipsec_sa_entry *sa_entry)
20032009
struct mlx5_fc *counter;
20042010
int err = 0;
20052011

2006-
rx = rx_ft_get(mdev, ipsec, attrs->family, attrs->type);
2012+
rx = rx_ft_get(mdev, ipsec, attrs->addrs.family, attrs->type);
20072013
if (IS_ERR(rx))
20082014
return PTR_ERR(rx);
20092015

@@ -2013,10 +2019,10 @@ static int rx_add_rule(struct mlx5e_ipsec_sa_entry *sa_entry)
20132019
goto err_alloc;
20142020
}
20152021

2016-
if (attrs->family == AF_INET)
2017-
setup_fte_addr4(spec, &attrs->saddr.a4, &attrs->daddr.a4);
2022+
if (attrs->addrs.family == AF_INET)
2023+
setup_fte_addr4(spec, &attrs->addrs);
20182024
else
2019-
setup_fte_addr6(spec, attrs->saddr.a6, attrs->daddr.a6);
2025+
setup_fte_addr6(spec, &attrs->addrs);
20202026

20212027
setup_fte_spi(spec, attrs->spi, attrs->encap);
20222028
if (!attrs->encap)
@@ -2116,7 +2122,7 @@ static int rx_add_rule(struct mlx5e_ipsec_sa_entry *sa_entry)
21162122
err_mod_header:
21172123
kvfree(spec);
21182124
err_alloc:
2119-
rx_ft_put(ipsec, attrs->family, attrs->type);
2125+
rx_ft_put(ipsec, attrs->addrs.family, attrs->type);
21202126
return err;
21212127
}
21222128

@@ -2148,10 +2154,10 @@ static int tx_add_rule(struct mlx5e_ipsec_sa_entry *sa_entry)
21482154

21492155
switch (attrs->type) {
21502156
case XFRM_DEV_OFFLOAD_CRYPTO:
2151-
if (attrs->family == AF_INET)
2152-
setup_fte_addr4(spec, &attrs->saddr.a4, &attrs->daddr.a4);
2157+
if (attrs->addrs.family == AF_INET)
2158+
setup_fte_addr4(spec, &attrs->addrs);
21532159
else
2154-
setup_fte_addr6(spec, attrs->saddr.a6, attrs->daddr.a6);
2160+
setup_fte_addr6(spec, &attrs->addrs);
21552161
setup_fte_spi(spec, attrs->spi, false);
21562162
setup_fte_esp(spec);
21572163
setup_fte_reg_a(spec);
@@ -2235,10 +2241,10 @@ static int tx_add_policy(struct mlx5e_ipsec_pol_entry *pol_entry)
22352241
}
22362242

22372243
tx = ipsec_tx(ipsec, attrs->type);
2238-
if (attrs->family == AF_INET)
2239-
setup_fte_addr4(spec, &attrs->saddr.a4, &attrs->daddr.a4);
2244+
if (attrs->addrs.family == AF_INET)
2245+
setup_fte_addr4(spec, &attrs->addrs);
22402246
else
2241-
setup_fte_addr6(spec, attrs->saddr.a6, attrs->daddr.a6);
2247+
setup_fte_addr6(spec, &attrs->addrs);
22422248

22432249
setup_fte_no_frags(spec);
22442250
setup_fte_upper_proto_match(spec, &attrs->upspec);
@@ -2308,23 +2314,23 @@ static int rx_add_policy(struct mlx5e_ipsec_pol_entry *pol_entry)
23082314
struct mlx5e_ipsec_rx *rx;
23092315
int err, dstn = 0;
23102316

2311-
ft = rx_ft_get_policy(mdev, pol_entry->ipsec, attrs->family, attrs->prio,
2312-
attrs->type);
2317+
ft = rx_ft_get_policy(mdev, pol_entry->ipsec, attrs->addrs.family,
2318+
attrs->prio, attrs->type);
23132319
if (IS_ERR(ft))
23142320
return PTR_ERR(ft);
23152321

2316-
rx = ipsec_rx(pol_entry->ipsec, attrs->family, attrs->type);
2322+
rx = ipsec_rx(pol_entry->ipsec, attrs->addrs.family, attrs->type);
23172323

23182324
spec = kvzalloc(sizeof(*spec), GFP_KERNEL);
23192325
if (!spec) {
23202326
err = -ENOMEM;
23212327
goto err_alloc;
23222328
}
23232329

2324-
if (attrs->family == AF_INET)
2325-
setup_fte_addr4(spec, &attrs->saddr.a4, &attrs->daddr.a4);
2330+
if (attrs->addrs.family == AF_INET)
2331+
setup_fte_addr4(spec, &attrs->addrs);
23262332
else
2327-
setup_fte_addr6(spec, attrs->saddr.a6, attrs->daddr.a6);
2333+
setup_fte_addr6(spec, &attrs->addrs);
23282334

23292335
setup_fte_no_frags(spec);
23302336
setup_fte_upper_proto_match(spec, &attrs->upspec);
@@ -2364,7 +2370,8 @@ static int rx_add_policy(struct mlx5e_ipsec_pol_entry *pol_entry)
23642370
err_action:
23652371
kvfree(spec);
23662372
err_alloc:
2367-
rx_ft_put_policy(pol_entry->ipsec, attrs->family, attrs->prio, attrs->type);
2373+
rx_ft_put_policy(pol_entry->ipsec, attrs->addrs.family, attrs->prio,
2374+
attrs->type);
23682375
return err;
23692376
}
23702377

@@ -2638,7 +2645,8 @@ void mlx5e_accel_ipsec_fs_del_rule(struct mlx5e_ipsec_sa_entry *sa_entry)
26382645
mlx5_fc_destroy(mdev, ipsec_rule->replay.fc);
26392646
}
26402647
mlx5_esw_ipsec_rx_id_mapping_remove(sa_entry);
2641-
rx_ft_put(sa_entry->ipsec, sa_entry->attrs.family, sa_entry->attrs.type);
2648+
rx_ft_put(sa_entry->ipsec, sa_entry->attrs.addrs.family,
2649+
sa_entry->attrs.type);
26422650
}
26432651

26442652
int mlx5e_accel_ipsec_fs_add_pol(struct mlx5e_ipsec_pol_entry *pol_entry)
@@ -2674,7 +2682,8 @@ void mlx5e_accel_ipsec_fs_del_pol(struct mlx5e_ipsec_pol_entry *pol_entry)
26742682
mlx5e_ipsec_unblock_tc_offload(pol_entry->ipsec->mdev);
26752683

26762684
if (pol_entry->attrs.dir == XFRM_DEV_OFFLOAD_IN) {
2677-
rx_ft_put_policy(pol_entry->ipsec, pol_entry->attrs.family,
2685+
rx_ft_put_policy(pol_entry->ipsec,
2686+
pol_entry->attrs.addrs.family,
26782687
pol_entry->attrs.prio, pol_entry->attrs.type);
26792688
return;
26802689
}
@@ -2814,7 +2823,7 @@ bool mlx5e_ipsec_fs_tunnel_enabled(struct mlx5e_ipsec_sa_entry *sa_entry)
28142823
struct mlx5e_ipsec_rx *rx;
28152824
struct mlx5e_ipsec_tx *tx;
28162825

2817-
rx = ipsec_rx(sa_entry->ipsec, attrs->family, attrs->type);
2826+
rx = ipsec_rx(sa_entry->ipsec, attrs->addrs.family, attrs->type);
28182827
tx = ipsec_tx(sa_entry->ipsec, attrs->type);
28192828
if (sa_entry->attrs.dir == XFRM_DEV_OFFLOAD_OUT)
28202829
return tx->allow_tunnel_mode;

0 commit comments

Comments
 (0)