[PATCH v4 net-next 07/12] netlink: spec: add shaper introspection support
From: Paolo Abeni <pabeni@redhat.com>
Date: 2024-08-20 15:13:29
Subsystem:
networking drivers, networking [general], the rest, yaml netlink (ynl) · Maintainers:
Andrew Lunn, "David S. Miller", Eric Dumazet, Jakub Kicinski, Paolo Abeni, Linus Torvalds, Donald Hunter
Allow the user-space to fine-grain query the shaping features supported by the NIC on each domain. Signed-off-by: Paolo Abeni <pabeni@redhat.com> --- Documentation/netlink/specs/net_shaper.yaml | 84 +++++++++++++++++++++ include/uapi/linux/net_shaper.h | 17 +++++ net/shaper/shaper.c | 22 ++++++ net/shaper/shaper_nl_gen.c | 27 +++++++ net/shaper/shaper_nl_gen.h | 8 ++ 5 files changed, 158 insertions(+)
diff --git a/Documentation/netlink/specs/net_shaper.yaml b/Documentation/netlink/specs/net_shaper.yaml
index a2b7900646ae..64d827176a61 100644
--- a/Documentation/netlink/specs/net_shaper.yaml
+++ b/Documentation/netlink/specs/net_shaper.yaml@@ -20,6 +20,11 @@ doc: | The user can query the running configuration via the @get operation. + Different devices can provide different feature set, e.g. with no + support for complex scheduling hierarchy, or for some shaping + parameters. The user can introspect the HW capabilities via the + @cap-get operation. + definitions: - type: enum
@@ -187,6 +192,52 @@ attribute-sets: name: priority - name: weight + - + name: capabilities + attributes: + - + name: ifindex + type: u32 + - + name: scope + type: u32 + enum: scope + doc: The scope to which the queried capabilities apply. + - + name: support-metric-bps + type: flag + doc: The device accepts 'bps' metric for bw-min, bw-max and burst. + - + name: support-metric-pps + type: flag + doc: The device accepts 'pps' metric for bw-min, bw-max and burst. + - + name: support-nesting + type: flag + doc: | + The device supports nesting shaper belonging to this scope + below 'node' scoped shapers. Only 'queue' and 'node' + scope can have flag 'support-nesting'. + - + name: support-bw-min + type: flag + doc: The device supports a minimum guaranteed B/W. + - + name: support-bw-max + type: flag + doc: The device supports maximum B/W shaping. + - + name: support-burst + type: flag + doc: The device supports a maximum burst size. + - + name: support-priority + type: flag + doc: The device supports priority scheduling. + - + name: support-weight + type: flag + doc: The device supports weighted round robin scheduling. operations: list:
@@ -287,3 +338,36 @@ operations: - root reply: attributes: *ns-binding + + - + name: cap-get + doc: | + Get / Dump the shaper capabilities supported by the given device. + attribute-set: capabilities + + do: + pre: net-shaper-nl-cap-pre-doit + post: net-shaper-nl-cap-post-doit + request: + attributes: + - ifindex + - scope + reply: + attributes: &cap-attrs + - ifindex + - scope + - support-metric-bps + - support-metric-pps + - support-nesting + - support-bw-min + - support-bw-max + - support-burst + - support-priority + - support-weight + + dump: + request: + attributes: + - ifindex + reply: + attributes: *cap-attrs
diff --git a/include/uapi/linux/net_shaper.h b/include/uapi/linux/net_shaper.h
index 05917f10b021..70d9639f9345 100644
--- a/include/uapi/linux/net_shaper.h
+++ b/include/uapi/linux/net_shaper.h@@ -60,11 +60,28 @@ enum { NET_SHAPER_A_MAX = (__NET_SHAPER_A_MAX - 1) }; +enum { + NET_SHAPER_A_CAPABILITIES_IFINDEX = 1, + NET_SHAPER_A_CAPABILITIES_SCOPE, + NET_SHAPER_A_CAPABILITIES_SUPPORT_METRIC_BPS, + NET_SHAPER_A_CAPABILITIES_SUPPORT_METRIC_PPS, + NET_SHAPER_A_CAPABILITIES_SUPPORT_NESTING, + NET_SHAPER_A_CAPABILITIES_SUPPORT_BW_MIN, + NET_SHAPER_A_CAPABILITIES_SUPPORT_BW_MAX, + NET_SHAPER_A_CAPABILITIES_SUPPORT_BURST, + NET_SHAPER_A_CAPABILITIES_SUPPORT_PRIORITY, + NET_SHAPER_A_CAPABILITIES_SUPPORT_WEIGHT, + + __NET_SHAPER_A_CAPABILITIES_MAX, + NET_SHAPER_A_CAPABILITIES_MAX = (__NET_SHAPER_A_CAPABILITIES_MAX - 1) +}; + enum { NET_SHAPER_CMD_GET = 1, NET_SHAPER_CMD_SET, NET_SHAPER_CMD_DELETE, NET_SHAPER_CMD_GROUP, + NET_SHAPER_CMD_CAP_GET, __NET_SHAPER_CMD_MAX, NET_SHAPER_CMD_MAX = (__NET_SHAPER_CMD_MAX - 1)
diff --git a/net/shaper/shaper.c b/net/shaper/shaper.c
index e5282c5bebe1..d3bb0ee1a18a 100644
--- a/net/shaper/shaper.c
+++ b/net/shaper/shaper.c@@ -501,6 +501,17 @@ void net_shaper_nl_post_doit(const struct genl_split_ops *ops, netdev_put(dev, NULL); } +int net_shaper_nl_cap_pre_doit(const struct genl_split_ops *ops, + struct sk_buff *skb, struct genl_info *info) +{ + return -EOPNOTSUPP; +} + +void net_shaper_nl_cap_post_doit(const struct genl_split_ops *ops, + struct sk_buff *skb, struct genl_info *info) +{ +} + int net_shaper_nl_get_doit(struct sk_buff *skb, struct genl_info *info) { struct net_device *dev = info->user_ptr[0];
@@ -1052,6 +1063,17 @@ int net_shaper_nl_group_doit(struct sk_buff *skb, struct genl_info *info) return ret; } +int net_shaper_nl_cap_get_doit(struct sk_buff *skb, struct genl_info *info) +{ + return 0; +} + +int net_shaper_nl_cap_get_dumpit(struct sk_buff *skb, + struct netlink_callback *cb) +{ + return 0; +} + void net_shaper_flush(struct net_device *dev) { struct xarray *xa = net_shaper_cache_container(dev);
diff --git a/net/shaper/shaper_nl_gen.c b/net/shaper/shaper_nl_gen.c
index b0a4bdf1f00a..04f9cbf3aee0 100644
--- a/net/shaper/shaper_nl_gen.c
+++ b/net/shaper/shaper_nl_gen.c@@ -67,6 +67,17 @@ static const struct nla_policy net_shaper_group_nl_policy[NET_SHAPER_A_ROOT + 1] [NET_SHAPER_A_ROOT] = NLA_POLICY_NESTED(net_shaper_root_info_nl_policy), }; +/* NET_SHAPER_CMD_CAP_GET - do */ +static const struct nla_policy net_shaper_cap_get_do_nl_policy[NET_SHAPER_A_CAPABILITIES_SCOPE + 1] = { + [NET_SHAPER_A_CAPABILITIES_IFINDEX] = { .type = NLA_U32, }, + [NET_SHAPER_A_CAPABILITIES_SCOPE] = NLA_POLICY_MAX(NLA_U32, 3), +}; + +/* NET_SHAPER_CMD_CAP_GET - dump */ +static const struct nla_policy net_shaper_cap_get_dump_nl_policy[NET_SHAPER_A_CAPABILITIES_IFINDEX + 1] = { + [NET_SHAPER_A_CAPABILITIES_IFINDEX] = { .type = NLA_U32, }, +}; + /* Ops table for net_shaper */ static const struct genl_split_ops net_shaper_nl_ops[] = { {
@@ -112,6 +123,22 @@ static const struct genl_split_ops net_shaper_nl_ops[] = { .maxattr = NET_SHAPER_A_ROOT, .flags = GENL_ADMIN_PERM | GENL_CMD_CAP_DO, }, + { + .cmd = NET_SHAPER_CMD_CAP_GET, + .pre_doit = net_shaper_nl_cap_pre_doit, + .doit = net_shaper_nl_cap_get_doit, + .post_doit = net_shaper_nl_cap_post_doit, + .policy = net_shaper_cap_get_do_nl_policy, + .maxattr = NET_SHAPER_A_CAPABILITIES_SCOPE, + .flags = GENL_CMD_CAP_DO, + }, + { + .cmd = NET_SHAPER_CMD_CAP_GET, + .dumpit = net_shaper_nl_cap_get_dumpit, + .policy = net_shaper_cap_get_dump_nl_policy, + .maxattr = NET_SHAPER_A_CAPABILITIES_IFINDEX, + .flags = GENL_CMD_CAP_DUMP, + }, }; struct genl_family net_shaper_nl_family __ro_after_init = {
diff --git a/net/shaper/shaper_nl_gen.h b/net/shaper/shaper_nl_gen.h
index 9b0682c83a07..6cec8903f25b 100644
--- a/net/shaper/shaper_nl_gen.h
+++ b/net/shaper/shaper_nl_gen.h@@ -18,15 +18,23 @@ extern const struct nla_policy net_shaper_root_info_nl_policy[NET_SHAPER_A_PAREN int net_shaper_nl_pre_doit(const struct genl_split_ops *ops, struct sk_buff *skb, struct genl_info *info); +int net_shaper_nl_cap_pre_doit(const struct genl_split_ops *ops, + struct sk_buff *skb, struct genl_info *info); void net_shaper_nl_post_doit(const struct genl_split_ops *ops, struct sk_buff *skb, struct genl_info *info); +void +net_shaper_nl_cap_post_doit(const struct genl_split_ops *ops, + struct sk_buff *skb, struct genl_info *info); int net_shaper_nl_get_doit(struct sk_buff *skb, struct genl_info *info); int net_shaper_nl_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb); int net_shaper_nl_set_doit(struct sk_buff *skb, struct genl_info *info); int net_shaper_nl_delete_doit(struct sk_buff *skb, struct genl_info *info); int net_shaper_nl_group_doit(struct sk_buff *skb, struct genl_info *info); +int net_shaper_nl_cap_get_doit(struct sk_buff *skb, struct genl_info *info); +int net_shaper_nl_cap_get_dumpit(struct sk_buff *skb, + struct netlink_callback *cb); extern struct genl_family net_shaper_nl_family;
--
2.45.2