Subject: Re: [PATCH net-next v18 20/25] ovpn: implement peer add/get/dump/delete via netlink

From: Sabrina Dubroca <[email-masked]>
Date: Mon, 3 Feb 2025 11:42:38 +0100

2025-02-03, 10:46:19 +0100, Antonio Quartulli wrote:
> On 03/02/2025 00:07, Sabrina Dubroca wrote:
> > 2025-01-13, 10:31:39 +0100, Antonio Quartulli wrote:
> > > +		NL_SET_ERR_MSG_FMT_MOD(info->extack,
> > > +				       "unexpected remote IP address for non UDP socket");
> > > +		sockfd_put(sock);
> > > +		return -EINVAL;
> > > +	}
> > > +
> > > +	ovpn_sock = ovpn_socket_new(sock, peer);
> > > +	if (IS_ERR(ovpn_sock)) {
> > > +		NL_SET_ERR_MSG_FMT_MOD(info->extack,
> > > +				       "cannot encapsulate socket: %ld",
> > > +				       PTR_ERR(ovpn_sock));
> > > +		sockfd_put(sock);
> > > +		return -ENOTSOCK;
> > 
> > Maybe s/-ENOTSOCK/PTR_ERR(ovpn_sock)/ ?
> > Overwriting ovpn_socket_new's -EBUSY etc with -ENOTSOCK is a bit
> > misleading to the caller.
> 
> This is the error code that userspace will see.
> Returning -EBUSY/-EALREADY for a socket error from the PEER_NEW call would
> be too vague IMHO (the user wouldn't know this is coming from the socket
> processing subroutine).
> 
> Hence the decision to explicitly return -ENOSOCK (something's wrong with the
> socket you passed) and then send the underling error in the ERR_MSG (which
> the user can inspect if he wants to learn more about what exactly went
> wrong).
> Doesn't it make sense?

Right, it doesn't matter that much as long as the user can see the
message in the extack. Error codes will always be imprecise. I find
"Not a socket" a bit inappropriate in this case ("what do you mean
it's not a socket, of course it is"), but I can live with it. In the
end the problem is what data ends up in bug reports from users
(whatever the userspace program prints), and what help developers get
from the kernel (the extack).

-- 
Sabrina