History

net: nexthop: Add ability to enable / disable hardware statistics

Add netlink support for enabling collection of HW statistics on nexthop groups.

Ido Schimmel committed 2 years ago

Commit 746c19a1 parent 58777863 files · +19 −1Browse files

Unified · Split

3 files
  1. include/net/nexthop.h +2 −0
  2. include/uapi/linux/nexthop.h +3 −0
  3. net/ipv4/nexthop.c +14 −1
include/net/nexthop.h+2−0
@@ -47,6 +47,8 @@ struct nh_config { · 46 unmodified lines
4747 bool nh_grp_res_has_idle_timer;
4848 bool nh_grp_res_has_unbalanced_timer;
4949
50+ bool nh_hw_stats;
51+
5052 struct nlattr *nh_encap;
5153 u16 nh_encap_type;
5254
include/uapi/linux/nexthop.h+3−0
@@ -68,6 +68,9 @@ enum { · 67 unmodified lines
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+14−1
@@ -39,6 +39,7 @@ static const struct nla_policy rtm_nh_policy_new[] = { · 38 unmodified lines
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, · 733 unmodified lines
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, · 417 unmodified lines
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, · 1414 unmodified lines
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;
@@ -2964,6 +2970,9 @@ static int rtm_to_nh_config(struct net *net, struct sk_buff *skb, · 336 unmodified lines
29642970 err = rtm_to_nh_config_grp_res(tb[NHA_RES_GROUP],
29652971 cfg, extack);
29662972
2973+ if (tb[NHA_HW_STATS_ENABLE])
2974+ cfg->nh_hw_stats = nla_get_u32(tb[NHA_HW_STATS_ENABLE]);
2975+
29672976 /* no other attributes should be set */
29682977 goto out;
29692978 }
@@ -3055,6 +3064,10 @@ static int rtm_to_nh_config(struct net *net, struct sk_buff *skb, · 85 unmodified lines
30553064 goto out;
30563065 }
30573066
3067+ if (tb[NHA_HW_STATS_ENABLE]) {
3068+ NL_SET_ERR_MSG(extack, "Cannot enable nexthop hardware statistics for non-group nexthops");
3069+ goto out;
3070+ }
30583071
30593072 err = 0;
30603073 out: