]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: connection: make it easier to emit proxy protocol for unknown addresses
authorWilly Tarreau <w@1wt.eu>
Tue, 1 Oct 2013 09:41:55 +0000 (11:41 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 9 Dec 2013 14:40:22 +0000 (15:40 +0100)
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.

src/connection.c

index 456d1bd2c33e8205f89ad382f70f33fdb2d5583a..62002835730dcbc0f5a921e03662b6f5cb149540 100644 (file)
@@ -451,13 +451,14 @@ int conn_recv_proxy(struct connection *conn, int flag)
  * buffer <buf> for a maximum size of <buf_len> (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 <src> or <dst> 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;