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
47 bool nh_grp_res_has_idle_timer;47 bool nh_grp_res_has_idle_timer;
48 bool nh_grp_res_has_unbalanced_timer;48 bool nh_grp_res_has_unbalanced_timer;
49 49
50 bool nh_hw_stats;
51
50 struct nlattr *nh_encap;52 struct nlattr *nh_encap;
51 u16 nh_encap_type;53 u16 nh_encap_type;
52 54
include/uapi/linux/nexthop.h+3−0
@@ -68,6 +68,9 @@ enum { · 67 unmodified lines
68 /* nested; nexthop group stats */68 /* nested; nexthop group stats */
69 NHA_GROUP_STATS,69 NHA_GROUP_STATS,
70 70
71 /* u32; nexthop hardware stats enable */
72 NHA_HW_STATS_ENABLE,
73
71 __NHA_MAX,74 __NHA_MAX,
72};75};
73 76
net/ipv4/nexthop.c+14−1
@@ -39,6 +39,7 @@ static const struct nla_policy rtm_nh_policy_new[] = { · 38 unmodified lines
39 [NHA_ENCAP] = { .type = NLA_NESTED },39 [NHA_ENCAP] = { .type = NLA_NESTED },
40 [NHA_FDB] = { .type = NLA_FLAG },40 [NHA_FDB] = { .type = NLA_FLAG },
41 [NHA_RES_GROUP] = { .type = NLA_NESTED },41 [NHA_RES_GROUP] = { .type = NLA_NESTED },
42 [NHA_HW_STATS_ENABLE] = NLA_POLICY_MAX(NLA_U32, true),
42};43};
43 44
44static const struct nla_policy rtm_nh_policy_get[] = {45static 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
778 goto nla_put_failure;779 goto nla_put_failure;
779 780
780 if (op_flags & NHA_OP_FLAG_DUMP_STATS &&781 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)))
782 goto nla_put_failure;784 goto nla_put_failure;
783 785
784 return 0;786 return 0;
@@ -1202,6 +1204,7 @@ static int nh_check_attr_group(struct net *net, · 417 unmodified lines
1202 if (!tb[i])1204 if (!tb[i])
1203 continue;1205 continue;
1204 switch (i) {1206 switch (i) {
1207 case NHA_HW_STATS_ENABLE:
1205 case NHA_FDB:1208 case NHA_FDB:
1206 continue;1209 continue;
1207 case NHA_RES_GROUP:1210 case NHA_RES_GROUP:
@@ -2622,6 +2625,9 @@ static struct nexthop *nexthop_create_group(struct net *net, · 1414 unmodified lines
2622 if (cfg->nh_fdb)2625 if (cfg->nh_fdb)
2623 nhg->fdb_nh = 1;2626 nhg->fdb_nh = 1;
2624 2627
2628 if (cfg->nh_hw_stats)
2629 nhg->hw_stats = true;
2630
2625 rcu_assign_pointer(nh->nh_grp, nhg);2631 rcu_assign_pointer(nh->nh_grp, nhg);
2626 2632
2627 return nh;2633 return nh;
@@ -2964,6 +2970,9 @@ static int rtm_to_nh_config(struct net *net, struct sk_buff *skb, · 336 unmodified lines
2964 err = rtm_to_nh_config_grp_res(tb[NHA_RES_GROUP],2970 err = rtm_to_nh_config_grp_res(tb[NHA_RES_GROUP],
2965 cfg, extack);2971 cfg, extack);
2966 2972
2973 if (tb[NHA_HW_STATS_ENABLE])
2974 cfg->nh_hw_stats = nla_get_u32(tb[NHA_HW_STATS_ENABLE]);
2975
2967 /* no other attributes should be set */2976 /* no other attributes should be set */
2968 goto out;2977 goto out;
2969 }2978 }
@@ -3055,6 +3064,10 @@ static int rtm_to_nh_config(struct net *net, struct sk_buff *skb, · 85 unmodified lines
3055 goto out;3064 goto out;
3056 }3065 }
3057 3066
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 }
3058 3071
3059 err = 0;3072 err = 0;
3060out:3073out: