MINOR: session: Rely on client source address at session level to log error

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.
This commit is contained in:
Christopher Faulet 2021-10-22 17:47:14 +02:00
parent f9c4d8d5be
commit c269f664bd
1 changed files with 4 additions and 3 deletions

View 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),