Download raw body.
relayd: PROXY: use client source port to unbreak forwarding
09.11.2026 23:39, Christoph Liebender пишет:
> Thanks, that was probably an oversight on my end.
>
> FWIW: ok christoph
Thanks.
Updated diff without unused variable and with relayd.conf example.
regress does not cover PROXY at all, I am still looking into this.
>
> Am 09.11.26 um 18:05 schrieb Klemens Nanni:
>> https://www.haproxy.org/download/1.8/doc/proxy-protocol.txt
>> 2.1. Human-readable header format (Version 1)
>>
>> A valid v1 header from 2001:db8::1/1234 to example.com/80 would be
>>
>> PROXY TCP6 2001:db8::1 2606:4700:10::6814:179a 1234 80
>>
>>
>> With pf diverting such connections
>>
>> pass ... divert-to ::1 port 3127
>>
>> for relayd to proxy them
>>
>> relay proxy {
>> listen on ::1 port 3127
>> forward to ... port 3128 proxy-protocol v1
>> }
>> # HAProxy equivalent
>> #frontend proxy
>> # bind [::1]:3127
>> # use_backend remote
>> #backend remote
>> # server srv ...:3128 send-proxy #-v2
Adding 'with tls' to relayd.conf breaks it again.
Adding 'ssl ...' to haproxy.cfg works.
So this is another bug in relayd I'll hunt next to fix interop.
>>
>> the PROXY v1 header produced by relayd contains the remote proxy port
>> instead of the client's source port, i.e.
>>
>> PROXY TCP6 2001:db8::1 2606:4700:10::6814:179a 1234 3128
>>
>>
>> Send the client port to unbreak PROXY forwarding.
>> I have tested both v1 and v2 against HAProxy as remote:
>>
>> listen proxy
>> bind [::]:3128 accept-proxy
>> use_backend self
>> backend self
>> server def [::]
Kirill pointed out https://marc.info/?l=openbsd-tech&m=179261003498017&w=2
Subject: Re: relayd: receive the PROXY protocol (v1 and v2) on listeners
I propose fixing the in-tree sender and covering regress first before
committing any receiver bits.
Feedback? OK?
Index: etc/examples/relayd.conf
===================================================================
RCS file: /cvs/src/etc/examples/relayd.conf,v
diff -u -p -r1.7 relayd.conf
--- etc/examples/relayd.conf 17 May 2026 09:11:01 -0000 1.7
+++ etc/examples/relayd.conf 10 Nov 2026 15:15:16 -0000
@@ -110,3 +110,15 @@ relay httpproxy {
# Forward to the original target host
forward to destination
}
+
+#
+# Relay for a transparent PROXY tunnel sender
+# https://www.haproxy.org/download/1.8/doc/proxy-protocol.txt
+#
+relay proxy {
+ # Receive through pf 'pass ... divert-to localhost port 3127'
+ listen on localhost port 3127
+
+ # Send binary v2 header
+ forward to remote port 3128 proxy-protocol v2
+}
Index: usr.sbin/relayd/proxy_protocol.c
===================================================================
RCS file: /cvs/src/usr.sbin/relayd/proxy_protocol.c,v
diff -u -p -r1.2 proxy_protocol.c
--- usr.sbin/relayd/proxy_protocol.c 15 Jun 2026 11:02:13 -0000 1.2
+++ usr.sbin/relayd/proxy_protocol.c 10 Nov 2026 13:31:25 -0000
@@ -55,6 +55,8 @@ proxy_protocol_v1(struct rsession *con,
{
char ibuf[128], obuf[128];
const char *proxyproto;
+ const struct sockaddr_storage *dstss = &con->se_sockname;
+ in_port_t dstport = 0;
int ret;
bzero(&ibuf, sizeof(ibuf));
@@ -70,9 +72,11 @@ proxy_protocol_v1(struct rsession *con,
switch (con->se_in.ss.ss_family) {
case AF_INET:
proxyproto = "TCP4";
+ dstport = ((const struct sockaddr_in *)dstss)->sin_port;
break;
case AF_INET6:
proxyproto = "TCP6";
+ dstport = ((const struct sockaddr_in6 *)dstss)->sin6_port;
break;
default:
proxyproto = "UNKNOWN";
@@ -82,7 +86,7 @@ proxy_protocol_v1(struct rsession *con,
ret = evbuffer_add_printf(dstout,
"PROXY %s %s %s %d %d\r\n", proxyproto, ibuf, obuf,
- ntohs(con->se_in.port), ntohs(con->se_relay->rl_conf.port));
+ ntohs(con->se_in.port), ntohs(dstport));
return ret == -1 ? -1 : 0;
}
@@ -97,7 +101,6 @@ proxy_protocol_v2(struct rsession *con,
const struct sockaddr_storage *dstss = &con->se_sockname;
int error;
in_port_t srcport = con->se_in.port;
- in_port_t dstport = conf->port;
u_int16_t len;
bcopy(PROXY_V2_SIG, hdr.sig, sizeof(hdr.sig));
@@ -113,7 +116,8 @@ proxy_protocol_v2(struct rsession *con,
addr.ipv4_addr.dst_addr =
((const struct sockaddr_in *)dstss)->sin_addr.s_addr;
addr.ipv4_addr.src_port = srcport;
- addr.ipv4_addr.dst_port = dstport;
+ addr.ipv4_addr.dst_port =
+ ((const struct sockaddr_in *)dstss)->sin_port;
break;
case AF_INET6:
hdr.fam = (conf->flags & F_UDP) ?
@@ -124,7 +128,8 @@ proxy_protocol_v2(struct rsession *con,
bcopy(&((const struct sockaddr_in6 *)dstss)->sin6_addr,
addr.ipv6_addr.dst_addr, sizeof(addr.ipv6_addr.dst_addr));
addr.ipv6_addr.src_port = srcport;
- addr.ipv6_addr.dst_port = dstport;
+ addr.ipv6_addr.dst_port =
+ ((const struct sockaddr_in6 *)dstss)->sin6_port;
break;
default:
hdr.fam = 0x00;
relayd: PROXY: use client source port to unbreak forwarding