]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: http-fetch: Rely on addresses at stream level in HTTP sample fetches
authorChristopher Faulet <cfaulet@haproxy.com>
Mon, 25 Oct 2021 05:48:27 +0000 (07:48 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Wed, 27 Oct 2021 09:34:21 +0000 (11:34 +0200)
Client source and destination addresses at stream level are now used to
compute base32+src and url32+src hashes. For now, stream-interface 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 stream
level, when set, instead of those at the connection level.

src/http_fetch.c

index 7b4e41d85f3eeda4f5be6a20ac0178b7ab70904d..0d78fa54ac8750299a3ba3cadb78dfe04f72af70 100644 (file)
@@ -35,6 +35,7 @@
 #include <haproxy/pool.h>
 #include <haproxy/sample.h>
 #include <haproxy/stream.h>
+#include <haproxy/stream_interface.h>
 #include <haproxy/tools.h>
 #include <haproxy/version.h>
 
@@ -1179,10 +1180,10 @@ static int smp_fetch_base32(const struct arg *args, struct sample *smp, const ch
  */
 static int smp_fetch_base32_src(const struct arg *args, struct sample *smp, const char *kw, void *private)
 {
+       const struct sockaddr_storage *src = (smp->strm ? si_src(&smp->strm->si[0]) : NULL);
        struct buffer *temp;
-       struct connection *cli_conn = objt_conn(smp->sess->origin);
 
-       if (!cli_conn || !conn_get_src(cli_conn))
+       if (!src)
                return 0;
 
        if (!smp_fetch_base32(args, smp, kw, private))
@@ -1192,16 +1193,16 @@ static int smp_fetch_base32_src(const struct arg *args, struct sample *smp, cons
        *(unsigned int *) temp->area = htonl(smp->data.u.sint);
        temp->data += sizeof(unsigned int);
 
-       switch (cli_conn->src->ss_family) {
+       switch (src->ss_family) {
        case AF_INET:
                memcpy(temp->area + temp->data,
-                      &((struct sockaddr_in *)cli_conn->src)->sin_addr,
+                      &((struct sockaddr_in *)src)->sin_addr,
                       4);
                temp->data += 4;
                break;
        case AF_INET6:
                memcpy(temp->area + temp->data,
-                      &((struct sockaddr_in6 *)cli_conn->src)->sin6_addr,
+                      &((struct sockaddr_in6 *)src)->sin6_addr,
                       16);
                temp->data += 16;
                break;
@@ -2041,10 +2042,10 @@ static int smp_fetch_url32(const struct arg *args, struct sample *smp, const cha
  */
 static int smp_fetch_url32_src(const struct arg *args, struct sample *smp, const char *kw, void *private)
 {
+       const struct sockaddr_storage *src = (smp->strm ? si_src(&smp->strm->si[0]) : NULL);
        struct buffer *temp;
-       struct connection *cli_conn = objt_conn(smp->sess->origin);
 
-       if (!cli_conn || !conn_get_src(cli_conn))
+       if (!src)
                return 0;
 
        if (!smp_fetch_url32(args, smp, kw, private))
@@ -2054,16 +2055,16 @@ static int smp_fetch_url32_src(const struct arg *args, struct sample *smp, const
        *(unsigned int *) temp->area = htonl(smp->data.u.sint);
        temp->data += sizeof(unsigned int);
 
-       switch (cli_conn->src->ss_family) {
+       switch (src->ss_family) {
        case AF_INET:
                memcpy(temp->area + temp->data,
-                      &((struct sockaddr_in *)cli_conn->src)->sin_addr,
+                      &((struct sockaddr_in *)src)->sin_addr,
                       4);
                temp->data += 4;
                break;
        case AF_INET6:
                memcpy(temp->area + temp->data,
-                      &((struct sockaddr_in6 *)cli_conn->src)->sin6_addr,
+                      &((struct sockaddr_in6 *)src)->sin6_addr,
                       16);
                temp->data += 16;
                break;