Skip to content

Commit 6fb7f94

Browse files
rleonSaeed Mahameed
authored andcommitted
net/mlx5e: Connect mlx5 IPsec statistics with XFRM core
Fill integrity, replay and bad trailer counters. As an example, after simulating replay window attack with 5 packets: [leonro@c ~]$ grep XfrmInStateSeqError /proc/net/xfrm_stat XfrmInStateSeqError 5 [leonro@c ~]$ sudo ip -s x s <...> stats: replay-window 0 replay 5 failed 0 Signed-off-by: Leon Romanovsky <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]>
1 parent f9f221c commit 6fb7f94

File tree

1 file changed

+20
-2
lines changed
  • drivers/net/ethernet/mellanox/mlx5/core/en_accel

1 file changed

+20
-2
lines changed

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -988,19 +988,37 @@ static void mlx5e_xfrm_update_stats(struct xfrm_state *x)
988988
{
989989
struct mlx5e_ipsec_sa_entry *sa_entry = to_ipsec_sa_entry(x);
990990
struct mlx5e_ipsec_rule *ipsec_rule = &sa_entry->ipsec_rule;
991+
struct net *net = dev_net(x->xso.dev);
991992
u64 packets, bytes, lastuse;
992993

993994
lockdep_assert(lockdep_is_held(&x->lock) ||
994995
lockdep_is_held(&dev_net(x->xso.real_dev)->xfrm.xfrm_cfg_mutex) ||
995996
lockdep_is_held(&dev_net(x->xso.real_dev)->xfrm.xfrm_state_lock));
996997

997-
if (x->xso.flags & XFRM_DEV_OFFLOAD_FLAG_ACQ ||
998-
x->xso.type != XFRM_DEV_OFFLOAD_PACKET)
998+
if (x->xso.flags & XFRM_DEV_OFFLOAD_FLAG_ACQ)
999+
return;
1000+
1001+
if (sa_entry->attrs.dir == XFRM_DEV_OFFLOAD_IN) {
1002+
mlx5_fc_query_cached(ipsec_rule->auth.fc, &bytes, &packets, &lastuse);
1003+
x->stats.integrity_failed += packets;
1004+
XFRM_ADD_STATS(net, LINUX_MIB_XFRMINSTATEPROTOERROR, packets);
1005+
1006+
mlx5_fc_query_cached(ipsec_rule->trailer.fc, &bytes, &packets, &lastuse);
1007+
XFRM_ADD_STATS(net, LINUX_MIB_XFRMINHDRERROR, packets);
1008+
}
1009+
1010+
if (x->xso.type != XFRM_DEV_OFFLOAD_PACKET)
9991011
return;
10001012

10011013
mlx5_fc_query_cached(ipsec_rule->fc, &bytes, &packets, &lastuse);
10021014
x->curlft.packets += packets;
10031015
x->curlft.bytes += bytes;
1016+
1017+
if (sa_entry->attrs.dir == XFRM_DEV_OFFLOAD_IN) {
1018+
mlx5_fc_query_cached(ipsec_rule->replay.fc, &bytes, &packets, &lastuse);
1019+
x->stats.replay += packets;
1020+
XFRM_ADD_STATS(net, LINUX_MIB_XFRMINSTATESEQERROR, packets);
1021+
}
10041022
}
10051023

10061024
static int mlx5e_xfrm_validate_policy(struct mlx5_core_dev *mdev,

0 commit comments

Comments
 (0)