]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: connection: Rely on addresses at stream level to make proxy line
authorChristopher Faulet <cfaulet@haproxy.com>
Mon, 25 Oct 2021 06:05:28 +0000 (08:05 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Wed, 27 Oct 2021 09:35:57 +0000 (11:35 +0200)
If the stream exists, the frontend stream-interface is used to get the
client source and destination addresses when the proxy line is built. For
now, stream-interface or session addresses are never set. So, thanks to the
fallback mechanism, no changes are expected with this patch. But its purpose
is to rely on addresses at the appropriate level when set instead of those
at the connection level.

src/connection.c

index bec639c8c5521ee1df1b8f615b2c6fda3e5914d3..2e3f274efd8aaa9ef72e0889077eb8a2b72c7b43 100644 (file)
@@ -1567,7 +1567,7 @@ void list_mux_proto(FILE *out)
  * TCP6 and "UNKNOWN" formats. If any of <src> or <dst> is null, UNKNOWN is
  * emitted as well.
  */
-static int make_proxy_line_v1(char *buf, int buf_len, struct sockaddr_storage *src, struct sockaddr_storage *dst)
+static int make_proxy_line_v1(char *buf, int buf_len, const struct sockaddr_storage *src, const struct sockaddr_storage *dst)
 {
        int ret = 0;
        char * protocol;
@@ -1662,8 +1662,8 @@ static int make_proxy_line_v2(char *buf, int buf_len, struct server *srv, struct
        int ret = 0;
        struct proxy_hdr_v2 *hdr = (struct proxy_hdr_v2 *)buf;
        struct sockaddr_storage null_addr = { .ss_family = 0 };
-       struct sockaddr_storage *src = &null_addr;
-       struct sockaddr_storage *dst = &null_addr;
+       const struct sockaddr_storage *src = &null_addr;
+       const struct sockaddr_storage *dst = &null_addr;
        const char *value;
        int value_len;
 
@@ -1671,9 +1671,13 @@ static int make_proxy_line_v2(char *buf, int buf_len, struct server *srv, struct
                return 0;
        memcpy(hdr->sig, pp2_signature, PP2_SIGNATURE_LEN);
 
-       if (remote && conn_get_src(remote) && conn_get_dst(remote)) {
-               src = remote->src;
-               dst = remote->dst;
+       if (strm) {
+               src = si_src(&strm->si[0]);
+               dst = si_dst(&strm->si[0]);
+       }
+       else if (remote && conn_get_src(remote) && conn_get_dst(remote)) {
+               src = conn_src(remote);
+               dst = conn_dst(remote);
        }
 
        /* At least one of src or dst is not of AF_INET or AF_INET6 */
@@ -1863,8 +1867,20 @@ int make_proxy_line(char *buf, int buf_len, struct server *srv, struct connectio
                ret = make_proxy_line_v2(buf, buf_len, srv, remote, strm);
        }
        else {
-               if (remote && conn_get_src(remote) && conn_get_dst(remote))
-                       ret = make_proxy_line_v1(buf, buf_len, remote->src, remote->dst);
+               const struct sockaddr_storage *src = NULL;
+               const struct sockaddr_storage *dst = NULL;
+
+               if (strm) {
+                       src = si_src(&strm->si[0]);
+                       dst = si_dst(&strm->si[0]);
+               }
+               else if (remote && conn_get_src(remote) && conn_get_dst(remote)) {
+                       src = conn_src(remote);
+                       dst = conn_dst(remote);
+               }
+
+               if (src && dst)
+                       ret = make_proxy_line_v1(buf, buf_len, src, dst);
                else
                        ret = make_proxy_line_v1(buf, buf_len, NULL, NULL);
        }