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

From: Leon Romanovsky <[email-masked]>
Date: Tue, 12 May 2026 19:12:24 +0300

On Tue, May 12, 2026 at 09:23:52AM -0600, David Ahern wrote:
> On 5/10/26 4:01 AM, Leon Romanovsky wrote:
> >> 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.
> > 
> 
> I considered that. devlink usage of netns_get_fd and its handling of pid
> vs name makes it a more complicated change.

You are not modifying devlink in this series, so rather than introducing
netns_get_fd_pid(), introduce netns_get_fd_fallback_pid() or another
appropriately named helper.

Thanks