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.
This commit is contained in:
Christopher Faulet 2021-10-25 07:48:27 +02:00
parent 8a104ba3e0
commit 6fc817a28e
1 changed files with 11 additions and 10 deletions

View 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;