]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: session: use conn->src instead of conn->addr.from
authorWilly Tarreau <w@1wt.eu>
Wed, 17 Jul 2019 13:23:20 +0000 (15:23 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 19 Jul 2019 11:50:09 +0000 (13:50 +0200)
In session_accept_fd() we'll soon have to dynamically allocate the
address, or better, steal it from the caller and define a strict calling
convention regarding who's responsible for the freeing. In the simpler
session_prepare_log_prefix(), just add an attempt to retrieve the address
if not yet set and do not dereference it on failure.

src/session.c

index f608c46675529443d938115407c45f1cb25ffec7..782d4889c4cb24c18b59b99d2cd14d14b4a7b43c 100644 (file)
@@ -156,7 +156,8 @@ int session_accept_fd(struct listener *l, int cfd, struct sockaddr_storage *addr
                goto out_close;
 
        cli_conn->handle.fd = cfd;
-       cli_conn->addr.from = *addr;
+       /* FIXME WTA: an allocation will be needed here. Better steal the original address on success */
+       *cli_conn->src = *addr;
        cli_conn->flags |= CO_FL_ADDR_FROM_SET;
        cli_conn->target = &l->obj_type;
        cli_conn->proxy_netns = l->netns;
@@ -327,13 +328,13 @@ static void session_prepare_log_prefix(struct session *sess)
        char *end;
        struct connection *cli_conn = __objt_conn(sess->origin);
 
-       ret = addr_to_str(&cli_conn->addr.from, pn, sizeof(pn));
+       ret = conn_get_src(cli_conn) ? addr_to_str(cli_conn->src, pn, sizeof(pn)) : 0;
        if (ret <= 0)
                chunk_printf(&trash, "unknown [");
        else if (ret == AF_UNIX)
                chunk_printf(&trash, "%s:%d [", pn, sess->listener->luid);
        else
-               chunk_printf(&trash, "%s:%d [", pn, get_host_port(&cli_conn->addr.from));
+               chunk_printf(&trash, "%s:%d [", pn, get_host_port(cli_conn->src));
 
        get_localtime(sess->accept_date.tv_sec, &tm);
        end = date2str_log(trash.area + trash.data, &tm, &(sess->accept_date),