netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: Sabrina Dubroca <sd@queasysnail.net>
Cc: netdev@vger.kernel.org,
	Hannes Frederic Sowa <hannes@stressinduktion.org>,
	Florian Westphal <fw@strlen.de>, Paolo Abeni <pabeni@redhat.com>
Subject: Re: [PATCH iproute2 net-next] ip: add MACsec support
Date: Mon, 7 Mar 2016 11:48:42 -0800	[thread overview]
Message-ID: <20160307114842.4314d50b@xeon-e3> (raw)
In-Reply-To: <e448dc09765ed22e9bd8353acbe85e7f692aa2f6.1457369326.git.sd@queasysnail.net>


> +static int one_of(const char *msg, const char *realval, const char **list,
> +		  size_t len, int *index)
> +{
> +	int i;
> +
> +	for (i = 0; i < len; i++) {
> +		if (matches(realval, list[i]) == 0) {
> +			*index = i;
> +			return 0;
> +		}
> +	}
> +
> +	fprintf(stderr, "Error: argument of \"%s\" must be one of ", msg);
> +	for (i = 0; i < len; i++)
> +		fprintf(stderr, "\"%s\", ", list[i]);
> +	fprintf(stderr, "not \"%s\"\n", realval);
> +	return -1;
> +}
> +
> +static int get_an(__u8 *val, const char *arg)
> +{
> +	int ret = get_u8(val, arg, 0);
> +
> +	if (ret)
> +		return ret;
> +
> +	if (*val > 3)
> +		return -1;
> +
> +	return 0;
> +}
> +
> +static int get_sci(__u64 *sci, const char *arg)
> +{
> +	return get_u64(sci, arg, 16);
> +}
> +
> +static int get_port(__be16 *port, const char *arg)
> +{
> +	__u16 p;
> +	int ret = get_u16(&p, arg, 10);
> +
> +	if (ret)
> +		return ret;
> +
> +	*port = htons(p);
> +	return 0;
> +}

Some of these should probably go into lib

> +static int from_hex(char c)
> +{
> +	if (c >= '0' && c <= '9')
> +		return c - '0';
> +	if (c >= 'a' && c <= 'f')
> +		return c - 'a' + 10;
> +	if (c >= 'A' && c <= 'F')
> +		return c - 'A' + 10;
> +
> +	return -1;
> +}

There already several copies of similar code (ipl2tp, ipmaddr, ipx)
for basically the same code.

...
> +	print_flag(stdout, attrs, "sc", MACSEC_ATTR_SC_ACTIVE);
> +	print_flag(stdout, attrs, "sa", MACSEC_ATTR_SA_ACTIVE);
> +	print_flag(stdout, attrs, "encrypt", MACSEC_ATTR_ENCRYPT);
> +	print_flag(stdout, attrs, "send_sci", MACSEC_ATTR_INC_SCI);
> +	print_flag(stdout, attrs, "end_station", MACSEC_ATTR_ES);
> +	print_flag(stdout, attrs, "scb", MACSEC_ATTR_SCB);
> +
> +	print_flag(stdout, attrs, "replayprotect", MACSEC_ATTR_REPLAY);
> +	if (attrs[MACSEC_ATTR_WINDOW]) {
> +		printf("window %d ",
> +		       rta_getattr_u32(attrs[MACSEC_ATTR_WINDOW]));
> +	}
> +
> +	if (attrs[MACSEC_ATTR_CIPHER_SUITE] && attrs[MACSEC_ATTR_ICV_LEN]) {
> +		printf("\n");
> +		print_cipher_suite(prefix,
> +			rta_getattr_u64(attrs[MACSEC_ATTR_CIPHER_SUITE]),
> +			rta_getattr_u8(attrs[MACSEC_ATTR_ICV_LEN]));
> +	}
> +
> +}

It is unwritten rule of ip commands that the print and set commands should
be invertable. I.e if you are going to print an attribute the format should
be the same as the argument passed in.

  reply	other threads:[~2016-03-07 19:48 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-07 17:12 [PATCH net-next 0/3] MACsec IEEE 802.1AE implementation Sabrina Dubroca
2016-03-07 17:12 ` [PATCH net-next 1/3] uapi: add MACsec bits Sabrina Dubroca
2016-03-08 19:52   ` Johannes Berg
2016-03-09 10:51     ` Sabrina Dubroca
2016-03-09 11:34       ` Johannes Berg
2016-03-10  9:55         ` Sabrina Dubroca
2016-03-07 17:12 ` [PATCH net-next 2/3] net: add MACsec netdevice priv_flags and helper Sabrina Dubroca
2016-03-07 17:12 ` [PATCH net-next 3/3] macsec: introduce IEEE 802.1AE driver Sabrina Dubroca
2016-03-07 19:05   ` David Miller
2016-03-08 20:13   ` Johannes Berg
2016-03-09 10:56     ` Sabrina Dubroca
2016-03-09 11:24       ` Johannes Berg
2016-03-09 17:09         ` David Miller
2016-03-07 17:12 ` [PATCH iproute2 net-next] ip: add MACsec support Sabrina Dubroca
2016-03-07 19:48   ` Stephen Hemminger [this message]
2016-03-08 10:49     ` Sabrina Dubroca

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=20160307114842.4314d50b@xeon-e3 \
    --to=stephen@networkplumber.org \
    --cc=fw@strlen.de \
    --cc=hannes@stressinduktion.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sd@queasysnail.net \
    /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).