From 6fc817a28e486cf8732e3912a85669734344f93b Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Mon, 25 Oct 2021 07:48:27 +0200 Subject: [PATCH] MINOR: http-fetch: Rely on addresses at stream level in HTTP sample fetches 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 | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/http_fetch.c b/src/http_fetch.c index 7b4e41d85f..0d78fa54ac 100644 --- a/src/http_fetch.c +++ b/src/http_fetch.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include @@ -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;