Re: [PATCH iproute2-next 1/5] netshaper: Extract parse_scope() and parse_rate() helpers

David Ahern
2026-05-01T17:47:41Z

On 4/30/26 7:16 PM, Mohsin Bashir wrote:
> diff --git a/netshaper/netshaper.c b/netshaper/netshaper.c
> index 47fb805e..1603e6e5 100644
> --- a/netshaper/netshaper.c
> +++ b/netshaper/netshaper.c
> @@ -47,6 +47,28 @@ static const char *net_shaper_scope_names[NET_SHAPER_SCOPE_MAX + 1] = {
> "node"
> };
>
> +static int parse_scope(const char *str)
> +{
> + if (strcmp(str, "netdev") == 0)
> + return NET_SHAPER_SCOPE_NETDEV;
> + if (strcmp(str, "queue") == 0)
> + return NET_SHAPER_SCOPE_QUEUE;
> + if (strcmp(str, "node") == 0)
> + return NET_SHAPER_SCOPE_NODE;
> + return -1;

net_shaper_scope_names exists. Create 1 table used for both parsing and
printing.

> +}
> +
> +static int parse_rate(const char *str, __u64 *rate_bps)
> +{
> + if (get_rate64(rate_bps, str)) {
> + fprintf(stderr, "Invalid rate value \"%s\"\n", str);
> + return -1;
> + }
> + /* get_rate64 returns bytes/sec, convert to bits/sec */
> + *rate_bps *= 8;

no magic numbers. Add a define for BITS_PER_BYTE to include/utils.h
above BIT()