Skip to content

Report UDP pending errors only when asked - #1895

Draft
Weidong Cui (wdcui) wants to merge 4 commits into
wdcui/ulitebox/reserve-refused-portsfrom
wdcui/ulitebox/udp-pending-errors
Draft

Weidong Cui (wdcui) wants to merge 4 commits into
wdcui/ulitebox/reserve-refused-portsfrom
wdcui/ulitebox/udp-pending-errors

Conversation

@wdcui

Copy link
Copy Markdown
Member

This PR makes UDP pending-error reporting in the broker guest-neutral. A UDP send checks its destination, policy and source first, and refuses broadcast with EACCES. It reports a pending error only when the sender sets the new REPORT_PENDING_ERROR flag, which the Linux shim does; otherwise the error stays pending for a later receive or SO_ERROR. On Linux hosts, a send without the flag first takes the host socket's error and keeps it, and the socket can still wait for writes while it keeps one.

Weidong Cui (wdcui) and others added 4 commits November 14, 2026 10:57
A UDP send took the socket's pending error before checking its
destination, so a send that its destination fails, such as a broadcast
or a policy-denied one, reported and lost the error. Linux checks the
destination and route first, and keeps the error. Check them first, and
refuse the broadcast address with PolicyDenied (EACCES, as Linux without
SO_BROADCAST) rather than InvalidArgument, for sends and connects.

Check a broadcast sendto and connect in udp_broker.c in place of the
port-0 sendto, which the shim refuses before the broker. Drop the unit
check of a failed send while the error is with the transport, which the
new order makes no different. Rebuild the Windows runner's udp_broker.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: f5406de6-bab4-4f3b-b232-ae238032c2c2
A UDP send took the socket's pending error once its destination was
checked, which is one guest OS's rule; others report it at another point
or only on receive. Make datagram sends leave pending errors pending
unless the new SendFlags::REPORT_PENDING_ERROR asks for one to be
reported in place of sending, once the destination is checked and before
a write shutdown is. The rule binds the socket providers too: the
userland and smoltcp ones take their own cached errors only with the
flag, and where a host send takes the host socket's error, as a Linux
host's does, the userland one takes it first and keeps it. Stream sends,
which have no destination to check first, reject the flag. The Linux
shim sets it on UDP sends, so Linux guests see no change.

Check that sends without the flag leave the error for a take or a
receive, in the core and in both providers.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: f5406de6-bab4-4f3b-b232-ae238032c2c2
A UDP endpoint was not watched again while it had an error pending. A
send that would block while the endpoint kept an error, as a send
without REPORT_PENDING_ERROR leaves one, then never learned that the
host could send until a call took the error. Only an error the host
socket still holds must stop the watch, which would report it again at
once. Watch again while the endpoint keeps the error, and take an error
that reaches the host socket meanwhile, coalescing it into the kept
one, so that the watch does not report it over and over.

Check that such a send learns when it can send, with the error kept,
and that a later host error is taken at once.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: f5406de6-bab4-4f3b-b232-ae238032c2c2
A UDP socket connected to itself refuses datagrams only on Linux, so
use refusing_udp_address() and keep Windows coverage of the fix.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: f5406de6-bab4-4f3b-b232-ae238032c2c2
@github-actions

Copy link
Copy Markdown

ℹ️ Note: This semver check was run against the wdcui/ulitebox/reserve-refused-ports branch, not main or ulitebox.

🤖 SemverChecks 🤖 No breaking API changes detected

Note: this does not mean API is unchanged, or even that there are no breaking changes; simply, none of the detections triggered.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant