Repository navigation
fix(udp): name the listener, not the backend, as PPv2 destination - #1927
Merged
Merged
Conversation
Collaborator
Author
|
Additional evidence beyond the description: Every-datagram path seen red on its own. Reverting only the
No unit-test binary failed. All 17 In the default-features run ( Formatting. Re-checked with the nightly toolchain invoked directly, because this workstation's environment overrides |
The PROXY protocol v2 header prepended to UDP datagrams carried the backend the datagram was forwarded to as its destination. The spec defines the destination as the address the client contacted, and the TCP serializer (SendProxyProtocol::back_writable) already uses the accepted socket's local address. A production capture on 2026-11-17 showed dst 10.101.0.6 (the backend node) over UDP against the load balancer's public IP over TCP. ManagerInput::ClientDatagram gains a per-datagram `dst`, the address the datagram arrived on, which both forward paths pass to prepend_dgram_header, so first-datagram-only and every-datagram modes are fixed alike. The shell fills it from UdpListener::local_address, read once from local_addr() when the listener socket is activated. A listener bound to 0.0.0.0 or :: advertises that wildcard IP with the listener port: the datagram's real destination (IP_PKTINFO / IPV6_RECVPKTINFO) is not read. Documented in the UDP LIFECYCLE.md, doc/configure.md and the changelog. A manager-level test covers both modes with distinct client, listener and backend addresses, and the PPv2 e2e test now asserts the advertised destination is the listener. Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
force-pushed
the
fix/udp-proxy-protocol-destination
branch
from
November 18, 2026 11:30
3634499 to
ca4d701
Compare
FlorentinDUBOIS
added a commit
that referenced
this pull request
Nov 18, 2026
Prepare Sōzu 2.3.6: #1927 (the PROXY protocol v2 header Sōzu prepends to UDP datagrams names the UDP listener's address as its destination, not the backend it forwards to) and #1928 (libz-sys 1.1.33 for RUSTSEC-2026-0544; the sozu-e2e Kafka test moves from rskafka to kafka-protocol, dropping chrono and RUSTSEC-2026-0543). Align all six package versions, workspace dependency minima, lockfiles, RPM metadata and changelog. Advance the previous-stable two-worker upgrade gate from published 2.3.4 to published 2.3.5 (archive 63332cdb…, executable aa63f2ce…, `sozu 2.3.5 (768fad4 HEAD)`), keeping the 2.2.1 bridge and 2.3.1 metadata cases. Signed-off-by: Florentin Dubois <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The PROXY protocol v2 header Sōzu prepends to UDP datagrams (
send_proxy_protocol, first datagram or every datagram) named the backend as its destination. The spec defines the destination as the address the client contacted, and Sōzu's TCP serializer already does that:SendProxyProtocol::back_writable(lib/src/protocol/proxy_protocol/send.rs) uses the accepted socket'slocal_addr().On the UDP side,
UdpManager::forward_admission_datagramandUdpManager::forward_on_existing_flow(lib/src/protocol/udp/manager.rs) calledprepend_dgram_header(&mut out, flow.client, backend).This was observed on 2026-11-17 against a production load balancer (loadbalancer-agent 0.7.5, Sōzu 2.3) with
proxyProtocol: Send. These are the first 28 bytes of the first datagram:The source address, the real client, was right in both captures. Only the UDP destination was wrong.
Fix
ManagerInput::ClientDatagramgainsdst: SocketAddr, the local address the datagram arrived on. The core passes it toprepend_dgram_headerat both forward sites, so first-datagram-only and every-datagram modes both carry it. TheTransmitstill goes to the backend; only the header changes.dstfrom a newUdpListener::local_addressfield (lib/src/udp.rs). That field is read once fromlocal_addr()whenUdpListener::activateregisters the socket, so the receive path pays nogetsocknameper datagram. Reading the socket rather than the config keeps an ephemeral-port bind and an inherited socket correct, the same way the TCP side reads the accepted socket.dgram_header/prepend_dgram_headerrename their second parameter frombackendtodestination, and their docs now say what it is.lib/src/protocol/udp/LIFECYCLE.md(the message contract and §8), thesend_proxy_protocolrow indoc/configure.md, andCHANGELOG.mdunder Unreleased → Fixed.dstis carried per datagram, not stored per flow. That leaves room to read the real destination from the packet later as a change to the shell alone.Wildcard binds: a known limitation, stated
A listener bound to
0.0.0.0or::has no single address the client contacted. Sōzu does not read the datagram's real destination from the packet (IP_PKTINFO/IPV6_RECVPKTINFOonrecvmsg(2)). On such a listener the header now names the wildcard IP with the listener's port. That is honest but incomplete: it is never the backend any more, and the IP is unspecified.The return path already has the matching limitation: on a wildcard socket,
send_tolets the kernel choose the reply's source address.Doing this properly means:
recv_fromwithrecvmsgand cmsg parsing in the hot path, which is newunsafe;activateso that inherited sockets get it as well.That is its own change, so it is left out here and documented in
LIFECYCLE.md§8 and the changelog.For the case that was reported, the listener is bound to the LB's public IP. loadbalancer-agent binds
public_ipv4.unwrap_or(0.0.0.0), and the TCP capture shows that the LB has a public IPv4. The wildcard case only arises for an address family the LB has no public address for.Tests
proxy_protocol_destination_is_the_listener_not_the_backendinlib/src/protocol/udp/manager.rs. It runs both modes throughUdpManager::handle_inputwith pairwise-distinct client, listener and backend addresses. It asserts that the header's source is the client, that its destination is the listener and not the backend, and that the transmit still goes to the backend.test_udp_proxy_protocol_to_backendnow also asserts the advertised destination is the listener. To support that, the mock backend's PPv2 parser (e2e/src/mock/udp_backend.rs) now also returns the destination, and its own unit test checks it.ClientDatagramwere updated: the unit tests, thesozu-simharness,fuzz_udp_flow(with a fixed listener address, so the input layout is unchanged) and one test inlib/src/server.rs.Red with the fix reverted (both call sites back to
backend), then green:Commands run
Local runs. The workstation's environment forced toolchain 1.99.1, so clippy was also run on the repo-pinned 1.93.1.
The 4 workspace failures are the
tests::fuzz_tests::*wrappers that CI skips (--skip tests::fuzz_tests::). On this workstationRUSTUP_TOOLCHAINpins a stable toolchain over+nightly, so the wrappers fail with "the optionZis only accepted on the nightly compiler". With nightly forced,fuzz_udp_flowitself passes; that run is shown above.cargo test --workspace --all-featuresadditionally fails 411 e2e tests on rustls's "Could not automatically determine the process-level CryptoProvider".--all-featuresenables several crypto providers at once, and CI never tests that combination: it runs one crypto cell per job.Impact
ManagerInput::ClientDatagramgains a field, so code that constructs it no longer compiles until it passesdst.unsafe, no new syscall per datagram, and no change to admission, limits or the return path.