public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Jiri Pirko <jiri@resnulli.us>
To: David Ahern <dsahern@gmail.com>
Cc: netdev@vger.kernel.org, stephen@networkplumber.org
Subject: Re: [patch iproute2-next 2/4] devlink: introduce support for netns id for nested handle
Date: Tue, 19 Sep 2023 13:57:40 +0200	[thread overview]
Message-ID: <ZQmMtO+InwpjRDmQ@nanopsycho> (raw)
In-Reply-To: <ZQlIVVsUCcY5yHpK@nanopsycho>

Tue, Sep 19, 2023 at 09:05:57AM CEST, jiri@resnulli.us wrote:
>Tue, Sep 19, 2023 at 05:06:12AM CEST, dsahern@gmail.com wrote:
>>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
>
>True, but that one is in "ip", that is why I decided to duplicate, for
>simplicity sake. How do you suggest to re-use it? Should I move it
>to lib? Any existing file?

Nevermind, took a stab at it in v2, just sent. Thanks!

>
>
>
>>

  reply	other threads:[~2023-09-19 11:57 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
2023-09-19  7:05     ` Jiri Pirko
2023-09-19 11:57       ` Jiri Pirko [this message]
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=ZQmMtO+InwpjRDmQ@nanopsycho \
    --to=jiri@resnulli.us \
    --cc=dsahern@gmail.com \
    --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