Netdev Archive on lore.kernel.org
help / color / mirror / Atom feed
From: David Ahern <dsahern@gmail.com>
To: Justin Iurman <justin.iurman@uliege.be>, netdev@vger.kernel.org
Cc: stephen@networkplumber.org
Subject: Re: [PATCH iproute2-next v2 1/3] Add, show, link, remove IOAM namespaces and schemas
Date: Wed, 28 Jul 2021 20:41:36 -0600	[thread overview]
Message-ID: <54514656-7e71-6071-a5b2-d6aa8eed6275@gmail.com> (raw)
In-Reply-To: <20210724172108.26524-2-justin.iurman@uliege.be>

On 7/24/21 11:21 AM, Justin Iurman wrote:
> +static void print_schema(struct rtattr *attrs[])
> +{
> +	__u8 data[IOAM6_MAX_SCHEMA_DATA_LEN + 1];
> +	int len;
> +
> +	print_uint(PRINT_ANY, "schema", "schema %u",
> +		   rta_getattr_u32(attrs[IOAM6_ATTR_SC_ID]));
> +
> +	if (attrs[IOAM6_ATTR_NS_ID])
> +		print_uint(PRINT_ANY, "namespace", " [namespace %u]",
> +			   rta_getattr_u16(attrs[IOAM6_ATTR_NS_ID]));
> +
> +	len = RTA_PAYLOAD(attrs[IOAM6_ATTR_SC_DATA]);
> +	memcpy(data, RTA_DATA(attrs[IOAM6_ATTR_SC_DATA]), len);
> +	data[len] = '\0';
> +
> +	print_string(PRINT_ANY, "data", ", data \"%s\"", (const char *)data);

The attribute descriptions shows this as binary data, not a string.

> +	print_null(PRINT_ANY, "", "\n", NULL);
> +}
> +
> +static int process_msg(struct nlmsghdr *n, void *arg)
> +{
> +	struct rtattr *attrs[IOAM6_ATTR_MAX + 1];
> +	struct genlmsghdr *ghdr;
> +	int len = n->nlmsg_len;
> +
> +	if (n->nlmsg_type != genl_family)
> +		return -1;
> +
> +	len -= NLMSG_LENGTH(GENL_HDRLEN);
> +	if (len < 0)
> +		return -1;
> +
> +	ghdr = NLMSG_DATA(n);
> +	parse_rtattr(attrs, IOAM6_ATTR_MAX, (void *)ghdr + GENL_HDRLEN, len);
> +
> +	open_json_object(NULL);
> +	switch (ghdr->cmd) {
> +	case IOAM6_CMD_DUMP_NAMESPACES:
> +		print_namespace(attrs);
> +		break;
> +	case IOAM6_CMD_DUMP_SCHEMAS:
> +		print_schema(attrs);
> +		break;
> +	}
> +	close_json_object();
> +
> +	return 0;
> +}
> +
> +static int ioam6_do_cmd(void)
> +{
> +	IOAM6_REQUEST(req, 1036, opts.cmd, NLM_F_REQUEST);
> +	int dump = 0;
> +
> +	if (genl_family < 0) {
> +		if (rtnl_open_byproto(&grth, 0, NETLINK_GENERIC) < 0) {
> +			fprintf(stderr, "Cannot open generic netlink socket\n");
> +			exit(1);
> +		}
> +		genl_family = genl_resolve_family(&grth, IOAM6_GENL_NAME);

The above 2 calls can be done with genl_init_handle.

> +		if (genl_family < 0)
> +			exit(1);
> +		req.n.nlmsg_type = genl_family;
> +	}
> +


> +int do_ioam6(int argc, char **argv)
> +{
> +	bool maybe_wide = false;
> +
> +	if (argc < 1 || matches(*argv, "help") == 0)
> +		usage();
> +
> +	memset(&opts, 0, sizeof(opts));
> +
> +	if (matches(*argv, "namespace") == 0) {

matches has been shown to be quite frail. Convenient for shorthand
typing commands, but frail in the big picture. We should stop using it -
especially for new commands.




  reply	other threads:[~2021-07-29  2:41 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-24 17:21 [PATCH iproute2-next v2 0/3] Provide support for IOAM Justin Iurman
2021-07-24 17:21 ` [PATCH iproute2-next v2 1/3] Add, show, link, remove IOAM namespaces and schemas Justin Iurman
2021-07-29  2:41   ` David Ahern [this message]
2021-07-29  9:51     ` Justin Iurman
2021-07-29 14:32       ` David Ahern
2021-07-29 16:41         ` Justin Iurman
2021-07-30 14:39           ` David Ahern
2021-08-11  3:47             ` Stephen Hemminger
2021-08-11  3:46   ` Stephen Hemminger
2021-07-24 17:21 ` [PATCH iproute2-next v2 2/3] New IOAM6 encap type for routes Justin Iurman
2021-07-27 13:42   ` Justin Iurman
2021-07-29  2:44     ` David Ahern
2021-07-24 17:21 ` [PATCH iproute2-next v2 3/3] IOAM man8 Justin Iurman

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=54514656-7e71-6071-a5b2-d6aa8eed6275@gmail.com \
    --to=dsahern@gmail.com \
    --cc=justin.iurman@uliege.be \
    --cc=netdev@vger.kernel.org \
    --cc=stephen@networkplumber.org \
    --subject='Re: [PATCH iproute2-next v2 1/3] Add, show, link, remove IOAM namespaces and schemas' \
    /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

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).