Commit Graph

20 Commits

Author SHA1 Message Date
Dean 4ddce7993d
Merge pull request #4845 from EagleBearerYS/test/guest-udp-readv-compare
test(libkernel): compare the unterminated readv buffer with memcmp
2026-10-14 14:34:41 +13:00
Dean 3779597778
Merge pull request #4658 from milescoviello/fix/sockopt-option-lengths
fix(libkernel): accept socket option values longer than an int
2026-10-13 16:53:12 +13:00
Yunus Shaikh 584c59e5ac test(libkernel): compare the unterminated readv buffer with memcmp 2026-10-12 16:37:56 -07:00
milescoviello b8d71fc7f2 fix(libkernel): dissolve a UDP association on connect to AF_UNSPEC
connect() on a guest datagram socket checked the address family before
doing anything, so an AF_UNSPEC (null) address failed with EAFNOSUPPORT
and left the socket connected: getpeername() still reported the old
peer, send() without an address still went there, and datagrams from
any other sender were dropped by the host.

FreeBSD 11.4 disconnects a connected datagram socket first and only then
rejects the address. sys/kern/uipc_socket.c, soconnectat():

	 * If protocol is connection-based, can only connect once.
	 * Otherwise, if connected, try to disconnect first.  This allows
	 * user to disconnect by connecting to, e.g., a null address.
	 */
	if (so->so_state & (SS_ISCONNECTED|SS_ISCONNECTING) &&
	    ((so->so_proto->pr_flags & PR_CONNREQUIRED) ||
	    (error = sodisconnect(so)))) {

udp_disconnect() (sys/netinet/udp_usrreq.c) clears the peer and resets
only the local address, keeping the local port:

	in_pcbdisconnect(inp);
	inp->inp_laddr.s_addr = INADDR_ANY;

after which in_pcbconnect_setup() (sys/netinet/in_pcb.c) returns
EAFNOSUPPORT for the full-size address, as main already does. connect(2)
documents it: "Datagram sockets may dissolve the association by
connecting to an invalid address, such as a null address."

A connected internet datagram socket given an address whose family byte
is 0 is now disconnected on the host first (AF_UNSPEC on Linux, a zeroed
address on Windows) and the call then fails as before. Linux also drops
an ephemeral local port on that disconnect, so the port is bound again
on the wildcard address, which is what FreeBSD leaves. A host
failure during the disconnect is returned as the call's error. Stream
sockets keep the previous path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-12 19:33:20 +00:00
milescoviello eb9da23e68 fix(libkernel): accept socket option values longer than an int
setsockopt() on a guest socket failed with EINVAL unless the option
length was exactly sizeof(int), so an option passed as a 64-bit value
(for example SO_BROADCAST or SO_RCVBUF from an int64_t or size_t) was
rejected and silently left unchanged.

FreeBSD 11.4 reads these integer options through sooptcopyin() with the
size of an int as both the wanted and the minimum length, and only a
shorter value fails. sys/kern/uipc_socket.c, sooptcopyin():

	 * If the user gives us more than we wanted, we ignore it, but if we
	 * don't get the minimum length the caller wants, we return EINVAL.
	...
	if ((valsize = sopt->sopt_valsize) < minlen)
		return EINVAL;
	if (valsize > len)
		sopt->sopt_valsize = valsize = len;

and sosetopt() uses it for SO_BROADCAST, SO_REUSEADDR, SO_SNDBUF and
SO_RCVBUF:

	error = sooptcopyin(sopt, &optval, sizeof optval,
	    sizeof optval);

A longer value now sets the option from its first int; a shorter one
still fails with EINVAL.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-12 18:04:27 +00:00
Dean 9bc4356990
Merge pull request #4295 from AaravMehta-07/codex/kernel-socket-address-length
fix(libkernel): report copied socket address lengths
2026-10-13 01:57:25 +13:00
Dean 90c7ab3390
Merge pull request #4102 from itsbo5/fix/libkernel-udp-send-edestaddrreq
fix(libkernel): return EDESTADDRREQ for send and sendto on unconnecte…
2026-10-13 01:28:39 +13:00
Aarav 6197edea2b fix(libkernel): report copied socket address lengths 2026-10-12 10:21:17 +05:30
milescoviello cba3b5a8b3 fix(libkernel): accept SOCK_NONBLOCK and SOCK_CLOEXEC in socket
socket only took a type of exactly SOCK_STREAM or SOCK_DGRAM, so a type
with SOCK_NONBLOCK (0x20000000) or SOCK_CLOEXEC (0x10000000) set failed
with EPROTONOSUPPORT, although socketpair already accepted both.

FreeBSD strips both flags before creating the socket (sys/kern/
uipc_syscalls.c, kern_socket: "if ((type & SOCK_CLOEXEC) != 0) { type
&= ~SOCK_CLOEXEC; oflag |= O_CLOEXEC; }" and the same for SOCK_NONBLOCK
with FNONBLOCK), and makes the new socket non-blocking with
"fo_ioctl(fp, FIONBIO, &fflag, ...)".

socket now does the same as socketpair: it creates the socket from the
plain type and, with SOCK_NONBLOCK, switches it to non-blocking.
SOCK_CLOEXEC needs nothing more, since a guest never executes another
program.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-12 01:48:40 +00:00
virp-mta 8b04156bfd fix(libkernel): return EDESTADDRREQ for send and sendto on unconnected UDP sockets 2026-10-12 03:12:34 +04:00
Adrià Franch e8ea9a62bb test(libkernel): check that a socket call returns the mapped guest errno
Sending on an unconnected UDP socket must report the guest EDESTADDRREQ (39)
through NativeError, so a regression to EIO is caught on Linux.
2026-10-11 23:43:47 +02:00
DariusHQ b4a59e34c4 feat(libkernel): export _ioctl
Stremio Plus (PPSA74126) stops at start-up on _ioctl, which its statically
linked tc* functions call. FreeBSD's _ioctl is the same system call as
ioctl, so it forwards to ioctl.
2026-10-11 14:19:02 +03:00
MarcZX100 d78af2c710 fix(libkernel): route vector I/O on guest sockets 2026-10-11 01:16:58 +00:00
Scott Schuster a2f9a50985 fix(libkernel): accept MSG_NOSIGNAL in send and sendto
send, sendto and sendmsg rejected every flag with EOPNOTSUPP, so callers
that pass FreeBSD's MSG_NOSIGNAL (0x20000) could not send at all. Accept
it: Windows sockets never raise SIGPIPE, and on Linux it maps to the
native MSG_NOSIGNAL. Other flags still fail with EOPNOTSUPP.

DOOM (PPSA99666) sends its upload server replies with MSG_NOSIGNAL and
closed every connection without an answer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-08 12:36:58 +02:00
kjhq afb8d8e2d7 fix(libkernel): accept guest socket addresses whatever their sa_len
The FreeBSD kernel ignores sa_len in a socket address passed in and sets
it from the length argument, so titles may leave it 0. Only the family
and the length argument decide the address kind now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-07 10:34:23 +00:00
Chad 77550ab731 feat(libkernel): implement sendmsg and recvmsg
Both take the FreeBSD msghdr (48 bytes, iovecs of a pointer and a 64-bit
length) and run on the host sockets: sendmsg gathers the iovecs and sends
through sendto, recvmsg receives into one buffer and scatters it. A
datagram longer than the iovecs is cut and reported with MSG_TRUNC, also
on Windows where recvfrom fails with WSAEMSGSIZE. More than 1024 iovecs
fail with EMSGSIZE. No ancillary data is ever received, so recvmsg
clears msg_controllen; sending control data throws.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 20:10:13 -05:00
Praetorian0420 e3eeac4a81 Implement network control and socket functionality improvements
- Enhanced the network control library to check for host addresses and update connection states accordingly.
- Added support for socket operations including connect, listen, accept, send, and recv in the UDP and TCP socket implementations.
- Introduced error handling for various socket operations, ensuring proper feedback for unsupported actions.
- Created comprehensive tests for both TCP and UDP socket functionalities, validating the expected behavior of the network stack.
- Refactored existing code to improve clarity and maintainability, including the removal of unused functions and the addition of necessary error checks.
2026-09-30 23:29:01 -05:00
asimplestray a4e755ccb1 feat(kernel): implement file metadata ops and address conversion 2026-09-30 16:51:37 +00:00
SamG-Coder b8c1097db4 feat(kernel): support socket nonblocking flags through fcntl 2026-09-25 06:34:30 +10:00
SamG-Coder 9cbefb7e04 feat(kernel): implement tracked UDP sockets and ioctl 2026-09-25 06:23:44 +10:00