We run an NETransparentProxyProvider that claims outbound UDP, and zero-length UDP datagrams (valid per RFC 768, used for keep-alives and NAT probes) don't survive it in either direction. macOS 26.5.2 (25F84), Apple silicon.
- (1) App to provider: the read is not completed.
An app sends "a", waits 200 ms, sends a zero-length datagram, waits 200 ms, sends "b". The framework logs received 0 datagram bytes from app as soon as the empty datagram is sent, but our pending readDatagrams is not completed. It completes only when "b" arrives, carrying both datagrams in order, or when the app closes the socket (Closing reads, not closed by plugin, then plugin read 0 bytes). A zero-length datagram that is the first datagram of a flow is delivered promptly. Without the provider, each datagram arrives within a millisecond.
XNU does forward it: flow_divert_send_app_data has if (to_send || data_size == 0) (xnu-12377.121.6, bsd/netinet/flow_divert.c).
- (2) Provider to app: the write is rejected.
writeDatagrams with a zero-length Data fails. The framework logs data length 0 <= 0 and Failed to write flow Data, and the completion gets NEAppProxyFlowErrorDomain code 4 (invalid argument). The other datagrams in the same call are not written either.
Reproduction. Our provider is open source: https://github.com/plabayo/rama, with an example transparent proxy in ffi/apple/examples/transparent_proxy. To see (2), use commit eaeaed7a0; later revisions drop empty datagrams before calling writeDatagrams. Any provider that reads with readDatagrams and echoes with writeDatagrams should show both. Test app:
import socket, time
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
peer = ("<lan-ip-of-a-udp-echo-peer>", 9000)
for payload in (b"a", b"", b"b"):
s.sendto(payload, peer)
time.sleep(0.2)
Questions.
- Is the delayed read completion for a zero-length datagram known or intended?
- Is there a supported way for a provider to deliver a zero-length datagram to the app?