From: Willy Tarreau Date: Tue, 1 Oct 2013 09:41:55 +0000 (+0200) Subject: MINOR: connection: make it easier to emit proxy protocol for unknown addresses X-Git-Tag: v1.5-dev20~134 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2e1401afb0e1f73c586a0e842afa314f26ff0fed;p=thirdparty%2Fhaproxy.git MINOR: connection: make it easier to emit proxy protocol for unknown addresses Currently a connection is required on the remote side to emit a proxy protocol header line. Let's support NULL addresses to emit an UNKNOWN tag as well. --- diff --git a/src/connection.c b/src/connection.c index 456d1bd2c3..6200283573 100644 --- a/src/connection.c +++ b/src/connection.c @@ -451,13 +451,14 @@ int conn_recv_proxy(struct connection *conn, int flag) * buffer for a maximum size of (including the trailing zero). * It returns the number of bytes composing this line (including the trailing * LF), or zero in case of failure (eg: not enough space). It supports TCP4, - * TCP6 and "UNKNOWN" formats. + * TCP6 and "UNKNOWN" formats. If any of or is null, UNKNOWN is + * emitted as well. */ int make_proxy_line(char *buf, int buf_len, struct sockaddr_storage *src, struct sockaddr_storage *dst) { int ret = 0; - if (src->ss_family == dst->ss_family && src->ss_family == AF_INET) { + if (src && dst && src->ss_family == dst->ss_family && src->ss_family == AF_INET) { ret = snprintf(buf + ret, buf_len - ret, "PROXY TCP4 "); if (ret >= buf_len) return 0; @@ -487,7 +488,7 @@ int make_proxy_line(char *buf, int buf_len, struct sockaddr_storage *src, struct if (ret >= buf_len) return 0; } - else if (src->ss_family == dst->ss_family && src->ss_family == AF_INET6) { + else if (src && dst && src->ss_family == dst->ss_family && src->ss_family == AF_INET6) { ret = snprintf(buf + ret, buf_len - ret, "PROXY TCP6 "); if (ret >= buf_len) return 0;