public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: David Ahern <dsahern@gmail.com>
To: Jiri Pirko <jiri@resnulli.us>, netdev@vger.kernel.org
Cc: stephen@networkplumber.org
Subject: Re: [patch iproute2-next 2/4] devlink: introduce support for netns id for nested handle
Date: Mon, 18 Sep 2023 21:06:12 -0600	[thread overview]
Message-ID: <628fff39-307f-c848-f72e-4ed8c682b34e@gmail.com> (raw)
In-Reply-To: <20230918105416.1107260-3-jiri@resnulli.us>

On 9/18/23 4:54 AM, Jiri Pirko wrote:
>  static const enum mnl_attr_data_type
> @@ -2723,6 +2725,85 @@ static bool should_arr_last_handle_end(struct dl *dl, const char *bus_name,
>  	       !cmp_arr_last_handle(dl, bus_name, dev_name);
>  }
>  
> +static int32_t netns_id_by_name(const char *name)
> +{
> +	struct {
> +		struct nlmsghdr n;
> +		struct rtgenmsg g;
> +		char            buf[1024];
> +	} req = {
> +		.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtgenmsg)),
> +		.n.nlmsg_flags = NLM_F_REQUEST,
> +		.n.nlmsg_type = RTM_GETNSID,
> +		.g.rtgen_family = AF_UNSPEC,
> +	};
> +	int ret = NETNSA_NSID_NOT_ASSIGNED;
> +	struct rtattr *tb[NETNSA_MAX + 1];
> +	struct nlmsghdr *n = NULL;
> +	struct rtnl_handle rth;
> +	struct rtgenmsg *rtg;
> +	int len;
> +	int fd;
> +
> +	fd = netns_get_fd(name);
> +	if (fd < 0)
> +		return ret;
> +
> +	if (rtnl_open(&rth, 0) < 0)
> +		return ret;
> +
> +	addattr32(&req.n, sizeof(req), NETNSA_FD, fd);
> +	if (rtnl_talk(&rth, &req.n, &n) < 0)
> +		goto out;
> +
> +	if (n->nlmsg_type == NLMSG_ERROR)
> +		goto out;
> +
> +	rtg = NLMSG_DATA(n);
> +	len = n->nlmsg_len;
> +
> +	len -= NLMSG_SPACE(sizeof(*rtg));
> +	if (len < 0)
> +		goto out;
> +
> +	parse_rtattr(tb, NETNSA_MAX, NETNS_RTA(rtg), len);
> +	if (tb[NETNSA_NSID])
> +		ret = rta_getattr_s32(tb[NETNSA_NSID]);
> +
> +out:
> +	free(n);
> +	rtnl_close(&rth);
> +	close(fd);
> +	return ret;
> +}

duplicates get_netnsid_from_name


  parent reply	other threads:[~2023-09-19  3:06 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-18 10:54 [patch iproute2-next 0/4] expose devlink instances relationships Jiri Pirko
2023-09-18 10:54 ` [patch iproute2-next 1/4] devlink: update headers Jiri Pirko
2023-09-18 10:54 ` [patch iproute2-next 2/4] devlink: introduce support for netns id for nested handle Jiri Pirko
2023-09-18 11:34   ` Daniel Machon
2023-09-18 12:29     ` Jiri Pirko
2023-09-19  3:06   ` David Ahern [this message]
2023-09-19  7:05     ` Jiri Pirko
2023-09-19 11:57       ` Jiri Pirko
2023-09-18 10:54 ` [patch iproute2-next 3/4] devlink: print nested handle for port function Jiri Pirko
2023-09-18 10:54 ` [patch iproute2-next 4/4] devlink: print nested devlink handle for devlink dev Jiri Pirko

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=628fff39-307f-c848-f72e-4ed8c682b34e@gmail.com \
    --to=dsahern@gmail.com \
    --cc=jiri@resnulli.us \
    --cc=netdev@vger.kernel.org \
    --cc=stephen@networkplumber.org \
    /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