Skip to content

Commit 43d32cc

Browse files
committed
net: nexthop: Add ability to enable / disable hardware statistics
JIRA: https://issues.redhat.com/browse/RHEL-59118 commit 746c19a Author: Ido Schimmel <idosch@nvidia.com> Date: Wed Mar 6 13:49:20 2024 +0100 net: nexthop: Add ability to enable / disable hardware statistics Add netlink support for enabling collection of HW statistics on nexthop groups. Signed-off-by: Ido Schimmel <idosch@nvidia.com> Reviewed-by: David Ahern <dsahern@kernel.org> Signed-off-by: Petr Machata <petrm@nvidia.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Ivan Vecera <ivecera@redhat.com>
1 parent f4bbfe0 commit 43d32cc

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

include/net/nexthop.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ struct nh_config {
4949
bool nh_grp_res_has_idle_timer;
5050
bool nh_grp_res_has_unbalanced_timer;
5151

52+
bool nh_hw_stats;
53+
5254
struct nlattr *nh_encap;
5355
u16 nh_encap_type;
5456

include/uapi/linux/nexthop.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ enum {
6868
/* nested; nexthop group stats */
6969
NHA_GROUP_STATS,
7070

71+
/* u32; nexthop hardware stats enable */
72+
NHA_HW_STATS_ENABLE,
73+
7174
__NHA_MAX,
7275
};
7376

net/ipv4/nexthop.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ static const struct nla_policy rtm_nh_policy_new[] = {
3939
[NHA_ENCAP] = { .type = NLA_NESTED },
4040
[NHA_FDB] = { .type = NLA_FLAG },
4141
[NHA_RES_GROUP] = { .type = NLA_NESTED },
42+
[NHA_HW_STATS_ENABLE] = NLA_POLICY_MAX(NLA_U32, true),
4243
};
4344

4445
static const struct nla_policy rtm_nh_policy_get[] = {
@@ -778,7 +779,8 @@ static int nla_put_nh_group(struct sk_buff *skb, struct nexthop *nh,
778779
goto nla_put_failure;
779780

780781
if (op_flags & NHA_OP_FLAG_DUMP_STATS &&
781-
nla_put_nh_group_stats(skb, nh))
782+
(nla_put_u32(skb, NHA_HW_STATS_ENABLE, nhg->hw_stats) ||
783+
nla_put_nh_group_stats(skb, nh)))
782784
goto nla_put_failure;
783785

784786
return 0;
@@ -1202,6 +1204,7 @@ static int nh_check_attr_group(struct net *net,
12021204
if (!tb[i])
12031205
continue;
12041206
switch (i) {
1207+
case NHA_HW_STATS_ENABLE:
12051208
case NHA_FDB:
12061209
continue;
12071210
case NHA_RES_GROUP:
@@ -2622,6 +2625,9 @@ static struct nexthop *nexthop_create_group(struct net *net,
26222625
if (cfg->nh_fdb)
26232626
nhg->fdb_nh = 1;
26242627

2628+
if (cfg->nh_hw_stats)
2629+
nhg->hw_stats = true;
2630+
26252631
rcu_assign_pointer(nh->nh_grp, nhg);
26262632

26272633
return nh;
@@ -2962,6 +2968,9 @@ static int rtm_to_nh_config(struct net *net, struct sk_buff *skb,
29622968
err = rtm_to_nh_config_grp_res(tb[NHA_RES_GROUP],
29632969
cfg, extack);
29642970

2971+
if (tb[NHA_HW_STATS_ENABLE])
2972+
cfg->nh_hw_stats = nla_get_u32(tb[NHA_HW_STATS_ENABLE]);
2973+
29652974
/* no other attributes should be set */
29662975
goto out;
29672976
}
@@ -3053,6 +3062,10 @@ static int rtm_to_nh_config(struct net *net, struct sk_buff *skb,
30533062
goto out;
30543063
}
30553064

3065+
if (tb[NHA_HW_STATS_ENABLE]) {
3066+
NL_SET_ERR_MSG(extack, "Cannot enable nexthop hardware statistics for non-group nexthops");
3067+
goto out;
3068+
}
30563069

30573070
err = 0;
30583071
out:

0 commit comments

Comments
 (0)