Skip to main content

Module proxy_protocol

Module proxy_protocol 

Source
Expand description

Pure PROXY-protocol-v2 DGRAM header builder.

No reference proxy ships PPv2-over-UDP, but the v2 spec carries a DGRAM encoding: the version+command byte (offset 12) is 0x21 (v2 + PROXY) and the family+transport byte (offset 13) is 0x12 for UDP-over-IPv4 or 0x22 for UDP-over-IPv6 (the low nibble 0x2 = DGRAM, vs 0x1 = STREAM used by the TCP serializer in protocol/proxy_protocol/header.rs).

This builds the header for a flow’s first upstream datagram with the real (pre-NAT) client address as the PPv2 source. The destination is the backend address. The header is a cheap prefix the core prepends in place to the owned payload Vec<u8>.

Layout (v2):

 0..12  signature  0D 0A 0D 0A 00 0D 0A 51 55 49 54 0A
 12     version+command  0x21  (v2 | PROXY)
 13     family+transport 0x12 (AF_INET|DGRAM) / 0x22 (AF_INET6|DGRAM)
 14..16 address length (u16 BE): 12 (v4) / 36 (v6)
 16..   src ip, dst ip, src port, dst port  (BE)

Functions§

dgram_header
Build the PPv2 DGRAM header bytes for a datagram whose real client source is client and whose backend destination is backend.
prepend_dgram_header
Prepend the PPv2 DGRAM header to an owned payload in place, returning the header length so the shell can account for the prefix bytes in metrics/logs.