[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <628fff39-307f-c848-f72e-4ed8c682b34e@gmail.com>
Date: Mon, 18 Sep 2023 21:06:12 -0600
From: David Ahern <dsahern@...il.com>
To: Jiri Pirko <jiri@...nulli.us>, netdev@...r.kernel.org
Cc: stephen@...workplumber.org
Subject: Re: [patch iproute2-next 2/4] devlink: introduce support for netns id
for nested handle
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
Powered by blists - more mailing lists