From 4d3c60ad8d25f572b5ebf0bd0f926def35e1c7b5 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Wed, 17 Jul 2019 15:23:20 +0200 Subject: [PATCH] MINOR: session: use conn->src instead of conn->addr.from 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 | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/session.c b/src/session.c index f608c4667..782d4889c 100644 --- a/src/session.c +++ b/src/session.c @@ -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),