Re: [PATCH] usbip: tools: add --sockfd option to usbip attach
From: Shuah Khan
Date: Thu Nov 12 2026 - 19:59:25 EST
On 10/21/26 15:48, Raul E Rangel wrote:
'usbip attach' always opens its own TCP connection to --remote. A client
that reaches the USB/IP server some other way, for example over a UNIX
domain socket or a channel forwarded by a multiplexed SSH connection,
therefore has to expose a listening TCP port on the local host just so
usbip can connect back to it. Any local user can connect to that port
while it is open.
Add a '--sockfd <fd>' option (short option '-s') that attaches the
device over an inherited, already-connected stream socket instead.
'--sockfd' and '--remote' are mutually exclusive. Because sudo closes
file descriptors >= 3 by default but preserves stdin, the typical
invocation passes the socket as stdin:
sudo usbip attach --sockfd 0 --busid <busid>
The descriptor must be a connected SOCK_STREAM socket: fstat() must
report S_ISSOCK, getsockopt(SO_TYPE) must return SOCK_STREAM and
getpeername() must succeed. Both AF_UNIX and AF_INET/AF_INET6 sockets
are accepted, since vhci_hcd only requires a SOCK_STREAM socket. For
AF_INET/AF_INET6 sockets, TCP_NODELAY and SO_KEEPALIVE are set as
usbip_net_tcp_connect() does.
The connection recorded in /var/run/vhci_hcd/port<N> for 'usbip port'
uses the numeric peer address and port for AF_INET/AF_INET6 sockets.
UNIX sockets have no port, so 'unix' and '-' are recorded instead; this
keeps read_record() working and 'usbip port' shows
'usbip://unix:-/<busid>'.
Update doc/usbip.8 and the usage text accordingly.
Does this patch fix a problem or does this add an enhancement?
What doesn't work without this patch?
thanks,
-- Shuah