netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jesus Sanchez-Palencia <jesus.sanchez-palencia@intel.com>
To: David Ahern <dsahern@gmail.com>, netdev@vger.kernel.org
Cc: jhs@mojatatu.com, xiyou.wangcong@gmail.com, jiri@resnulli.us,
	Vinicius Costa Gomes <vinicius.gomes@intel.com>
Subject: Re: [PATCH v3 iproute2 2/3] tc: Add support for the ETF Qdisc
Date: Mon, 9 Jul 2018 08:48:35 -0700	[thread overview]
Message-ID: <a009803c-1036-eae9-c57d-2b95eecd551d@intel.com> (raw)
In-Reply-To: <b2fda267-bc71-4280-9622-f2c949faab56@gmail.com>

Hi David,


On 07/06/2018 08:58 AM, David Ahern wrote:
> On 7/5/18 4:42 PM, Jesus Sanchez-Palencia wrote:
> 
>> +static int get_clockid(__s32 *val, const char *arg)
>> +{
>> +	const struct static_clockid {
>> +		const char *name;
>> +		clockid_t clockid;
>> +	} clockids_sysv[] = {
>> +		{ "CLOCK_REALTIME", CLOCK_REALTIME },
>> +		{ "CLOCK_TAI", CLOCK_TAI },
>> +		{ "CLOCK_BOOTTIME", CLOCK_BOOTTIME },
>> +		{ "CLOCK_MONOTONIC", CLOCK_MONOTONIC },
>> +		{ NULL }
>> +	};
>> +
>> +	const struct static_clockid *c;
>> +
>> +	for (c = clockids_sysv; c->name; c++) {
>> +		if (strncasecmp(c->name, arg, 25) == 0) {
> 
> Why 25?


That was just an upper bound giving some room beyond the longest
clockid name we have today. Should I add a define MAX_CLOCK_NAME ?


> 
> be nice to allow shortcuts -- e.g., just REALTIME or realtime.


I'd rather just keep it as is and use the names as they are defined for
everything else (i.e. CLOCK_REALTIME), unless there are some strong objections.



> 
>> +			*val = c->clockid;
>> +
>> +			return 0;
>> +		}
>> +	}
>> +
>> +	return -1;
>> +}
>> +
>> +
>> +static int etf_parse_opt(struct qdisc_util *qu, int argc,
>> +			 char **argv, struct nlmsghdr *n, const char *dev)
>> +{
>> +	struct tc_etf_qopt opt = {
>> +		.clockid = CLOCKID_INVALID,
>> +	};
>> +	struct rtattr *tail;
>> +
>> +	while (argc > 0) {
>> +		if (matches(*argv, "offload") == 0) {
>> +			if (opt.flags & TC_ETF_OFFLOAD_ON) {
>> +				fprintf(stderr, "etf: duplicate \"offload\" specification\n");
>> +				return -1;
>> +			}
>> +
>> +			opt.flags |= TC_ETF_OFFLOAD_ON;
>> +		} else if (matches(*argv, "deadline_mode") == 0) {
>> +			if (opt.flags & TC_ETF_DEADLINE_MODE_ON) {
>> +				fprintf(stderr, "etf: duplicate \"deadline_mode\" specification\n");
>> +				return -1;
>> +			}
>> +
>> +			opt.flags |= TC_ETF_DEADLINE_MODE_ON;
>> +		} else if (matches(*argv, "delta") == 0) {
>> +			NEXT_ARG();
>> +			if (opt.delta) {
>> +				fprintf(stderr, "etf: duplicate \"delta\" specification\n");
>> +				return -1;
>> +			}
>> +			if (get_s32(&opt.delta, *argv, 0)) {
>> +				explain1("delta", *argv);
>> +				return -1;
>> +			}
>> +		} else if (matches(*argv, "clockid") == 0) {
>> +			NEXT_ARG();
>> +			if (opt.clockid != CLOCKID_INVALID) {
>> +				fprintf(stderr, "etf: duplicate \"clockid\" specification\n");
>> +				return -1;
>> +			}
>> +			if (get_clockid(&opt.clockid, *argv)) {
>> +				explain_clockid(*argv);
>> +				return -1;
>> +			}
>> +		} else if (strcmp(*argv, "help") == 0) {
>> +			explain();
>> +			return -1;
>> +		} else {
>> +			fprintf(stderr, "etf: unknown parameter \"%s\"\n", *argv);
>> +			explain();
>> +			return -1;
>> +		}
>> +		argc--; argv++;
>> +	}
>> +
>> +	tail = NLMSG_TAIL(n);
>> +	addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
>> +	addattr_l(n, 2024, TCA_ETF_PARMS, &opt, sizeof(opt));
>> +	tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
>> +	return 0;
>> +}
>> +
>> +static int etf_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
>> +{
>> +	struct rtattr *tb[TCA_ETF_MAX+1];
>> +	struct tc_etf_qopt *qopt;
>> +
>> +	if (opt == NULL)
>> +		return 0;
>> +
>> +	parse_rtattr_nested(tb, TCA_ETF_MAX, opt);
>> +
>> +	if (tb[TCA_ETF_PARMS] == NULL)
>> +		return -1;
>> +
>> +	qopt = RTA_DATA(tb[TCA_ETF_PARMS]);
>> +	if (RTA_PAYLOAD(tb[TCA_ETF_PARMS])  < sizeof(*qopt))
>> +		return -1;
>> +
>> +	if (qopt->clockid == CLOCKID_INVALID)
>> +		print_string(PRINT_ANY, "clockid", "clockid %s ", "invalid");
>> +	else
>> +		print_uint(PRINT_ANY, "clockid", "clockid %d ", qopt->clockid);
> 
> If you allow the user to input a string, then you should return it here too.


Ok, will fix.

Thanks,
Jesus

  reply	other threads:[~2018-07-09 15:53 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-05 22:42 [PATCH v3 iproute2 0/3] Add support for ETF qdisc Jesus Sanchez-Palencia
2018-07-05 22:42 ` [PATCH v3 iproute2 1/3] uapi pkt_sched: Add etf info - DO NOT COMMIT Jesus Sanchez-Palencia
2018-07-05 22:42 ` [PATCH v3 iproute2 2/3] tc: Add support for the ETF Qdisc Jesus Sanchez-Palencia
2018-07-06 15:58   ` David Ahern
2018-07-09 15:48     ` Jesus Sanchez-Palencia [this message]
2018-07-09 17:32       ` David Ahern
2018-07-09 23:16         ` Jesus Sanchez-Palencia
2018-07-06 21:32   ` Stephen Hemminger
2018-07-06 21:54     ` Jesus Sanchez-Palencia
2018-07-05 22:42 ` [PATCH v3 iproute2 3/3] man: Add initial manpage for tc-etf(8) Jesus Sanchez-Palencia

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a009803c-1036-eae9-c57d-2b95eecd551d@intel.com \
    --to=jesus.sanchez-palencia@intel.com \
    --cc=dsahern@gmail.com \
    --cc=jhs@mojatatu.com \
    --cc=jiri@resnulli.us \
    --cc=netdev@vger.kernel.org \
    --cc=vinicius.gomes@intel.com \
    --cc=xiyou.wangcong@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).