Subject: Re: [PATCH iproute2-next] f_flower: add cfm support

From: Ido Schimmel <[email-masked]>
Date: Tue, 20 Jun 2023 09:58:35 +0300

On Mon, Jun 19, 2023 at 11:35:23PM +0200, Zahari Doychev wrote:
> +static int flower_parse_cfm(int *argc_p, char ***argv_p, __be16 eth_type,
> +			    struct nlmsghdr *n)
> +{
> +	struct rtattr *cfm_attr;
> +	char **argv = *argv_p;
> +	int argc = *argc_p;
> +	int ret;
> +
> +	if (eth_type != htons(ETH_P_CFM)) {
> +		fprintf(stderr,
> +			"Can't set attribute if ethertype isn't CFM\n");
> +		return -1;
> +	}
> +
> +	cfm_attr = addattr_nest(n, MAX_MSG, TCA_FLOWER_KEY_CFM | NLA_F_NESTED);
> +
> +	while (argc > 0) {
> +		if (matches(*argv, "mdl") == 0) {

New code is expected to use strcmp() instead of matches(). Looks good
otherwise.

> +			__u8 val;
> +
> +			NEXT_ARG();
> +			ret = get_u8(&val, *argv, 10);
> +			if (ret < 0) {
> +				fprintf(stderr, "Illegal \"cfm md level\"\n");
> +				return -1;
> +			}
> +			addattr8(n, MAX_MSG, TCA_FLOWER_KEY_CFM_MD_LEVEL, val);
> +		} else if (matches(*argv, "op") == 0) {

Likewise.

> +			__u8 val;
> +
> +			NEXT_ARG();
> +			ret = get_u8(&val, *argv, 10);
> +			if (ret < 0) {
> +				fprintf(stderr, "Illegal \"cfm opcode\"\n");
> +				return -1;
> +			}
> +			addattr8(n, MAX_MSG, TCA_FLOWER_KEY_CFM_OPCODE, val);
> +		} else {
> +			break;
> +		}
> +		argc--; argv++;
> +	}
> +
> +	addattr_nest_end(n, cfm_attr);
> +
> +	*argc_p = argc;
> +	*argv_p = argv;
> +
> +	return 0;
> +}
> +
>  static int flower_parse_opt(struct filter_util *qu, char *handle,
>  			    int argc, char **argv, struct nlmsghdr *n)
>  {
> @@ -2065,6 +2118,12 @@ static int flower_parse_opt(struct filter_util *qu, char *handle,
>  				return -1;
>  			}
>  			continue;
> +		} else if (matches(*argv, "cfm") == 0) {

Likewise.

> +			NEXT_ARG();
> +			ret = flower_parse_cfm(&argc, &argv, eth_type, n);
> +			if (ret < 0)
> +				return -1;
> +			continue;
>  		} else {
>  			if (strcmp(*argv, "help") != 0)
>  				fprintf(stderr, "What is \"%s\"?\n", *argv);