]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: session: Rely on client source address at session level to log error
authorChristopher Faulet <cfaulet@haproxy.com>
Fri, 22 Oct 2021 15:47:14 +0000 (17:47 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Wed, 27 Oct 2021 09:34:21 +0000 (11:34 +0200)
When an embryonic session is killed, if no log format is defined for this
error, a generic error is emitted. When this happens, we now rely on the
session to get the client source address. For now, 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 session
level when set instead of those at the connection level.

src/session.c

index 06ace8a0f64bf2fa0a7d35203f4b7454c8498b27..0b0a9a49f1488e903b4b59dd32b75f3251b57d46 100644 (file)
@@ -302,19 +302,20 @@ int session_accept_fd(struct connection *cli_conn)
  */
 static void session_prepare_log_prefix(struct session *sess)
 {
+       const struct sockaddr_storage *src;
        struct tm tm;
        char pn[INET6_ADDRSTRLEN];
        int ret;
        char *end;
-       struct connection *cli_conn = __objt_conn(sess->origin);
 
-       ret = conn_get_src(cli_conn) ? addr_to_str(cli_conn->src, pn, sizeof(pn)) : 0;
+       src = sess_src(sess);
+       ret = (src ? addr_to_str(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->src));
+               chunk_printf(&trash, "%s:%d [", pn, get_host_port(src));
 
        get_localtime(sess->accept_date.tv_sec, &tm);
        end = date2str_log(trash.area + trash.data, &tm, &(sess->accept_date),