Subject: Re: [PATCH iproute2-next 2/4] iplink: Update iplink_parse to use netns_get_fd_pid

From: Leon Romanovsky <[email-masked]>
Date: Sun, 10 May 2026 13:01:48 +0300

On Thu, May 07, 2026 at 09:08:33AM -0600, David Ahern wrote:
> From: David Ahern <[email-masked]>
> 
> Drop the open coding of proc/pid/ns/net in favor of
> netns_get_fd_pid.
> 
> Signed-off-by: David Ahern <[email-masked]>
> ---
>  ip/iplink.c | 12 +++---------
>  1 file changed, 3 insertions(+), 9 deletions(-)
> 
> diff --git a/ip/iplink.c b/ip/iplink.c
> index eae51438..6c4586ee 100644
> --- a/ip/iplink.c
> +++ b/ip/iplink.c
> @@ -650,19 +650,13 @@ int iplink_parse(int argc, char **argv, struct iplink_req *req, char **type)
>  			if (offload && name == dev)
>  				dev = NULL;
>  		} else if (strcmp(*argv, "netns") == 0) {
> -			int pid;
> -
>  			NEXT_ARG();
>  			if (netns != -1)
>  				duparg("netns", *argv);
> +			/* try by name then by pid */
>  			netns = netns_get_fd(*argv);
> -			if (netns < 0 && get_integer(&pid, *argv, 0) == 0) {
> -				char path[PATH_MAX];
> -
> -				snprintf(path, sizeof(path), "/proc/%d/ns/net",
> -					 pid);
> -				netns = open(path, O_RDONLY);
> -			}
> +			if (netns < 0)
> +				netns = netns_get_fd_pid(*argv);

It would be good to have a single function that handles the entire
netns_get_fd() → netns < 0 → netns_get_fd_pid() sequence internally. This
logic is used by at least iplink and rdmatool.

Thanks