Files
freebsd/lib
John Ericson 6563dcb6b1 unix: allow connectat(2) to name the peer socket by descriptor
Accept an empty `sun_path` when `fd` is not `AT_FDCWD`: the descriptor
then names the peer unix socket directly, instead of being the starting
directory for a pathname lookup.  The held file reference keeps the peer
PCB stable, playing the role `unp_vp_mtxpool` plays in the pathname
path.

The descriptor must carry `CAP_CONNECTAT` and refer to an `AF_UNIX`
socket (`EPROTOTYPE` otherwise, `ENOTSOCK` for non-sockets).  As with a
pathname, a stream/seqpacket peer must be listening.  No filesystem
permission or MAC vnode check applies on this path: possession of the
descriptor is the authorization, as with descriptor passing.

Note this makes it possible to connect a datagram socket to an unbound
peer, which no pathname could previously name.

`connect(2)` and the implicit-connect send path pass `AT_FDCWD` and
still reject an empty path with `EINVAL`.

The `unp_sun_path()` call is hoisted out of `unp_connectat()` because the
early exit conditions for the two system calls (`connect(2)` and
`connectat(2)`) are slightly different.

Additionally, support `/dev/fd/<N>`. In a world with `connectat(2)`,
this is largely overkill, but this also allows me to add support for
direct peer connections with plain `connect(2)`. I think that is a wise
choice because this will allow me to propose this functionality for
Linux too without a new system call (saving that conversation for
later). Ultimately, I want to see multiple operating systems support
this to foster broader userland adoption, which should benefit everyone
including FreeBSD --- it's nicer if more 3rd party in addition to 1st
party software uses the new kernel functionality. Therefore, I hope this
additional feature is also acceptable.

Signed-off-by: John Ericson <[email protected]>
Assisted-by: Claude Code (Claude Opus 4.8 and Fable 5)

Reviewed by:	markj
MFC after:	2 months
Differential Revision:	https://reviews.freebsd.org/D58405
2026-08-10 17:31:22 +00:00
..
2026-01-13 10:19:04 -05:00
2026-01-03 21:37:18 +01:00
2026-01-06 12:56:50 -05:00
2026-03-31 18:45:14 -07:00
2026-06-02 21:54:25 -07:00
2025-10-03 19:46:55 +02:00
2026-03-15 00:41:29 -03:00
2025-11-24 10:47:10 -05:00
2025-08-08 13:27:26 -05:00
2026-08-04 18:27:21 +00:00
2025-09-30 09:14:05 +01:00
2026-01-06 04:26:53 +00:00
2026-03-13 23:49:53 +00:00
2026-04-08 14:22:45 -07:00
2026-08-02 13:17:45 +02:00
2026-01-15 07:28:28 +01:00
2025-12-03 14:21:07 +00:00
2026-07-07 08:47:36 +02:00