From: Willy Tarreau Date: Wed, 17 Jul 2019 13:23:20 +0000 (+0200) Subject: MINOR: session: use conn->src instead of conn->addr.from X-Git-Tag: v2.1-dev2~309 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4d3c60ad8d25f572b5ebf0bd0f926def35e1c7b5;p=thirdparty%2Fhaproxy.git 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. --- diff --git a/src/session.c b/src/session.c index f608c46675..782d4889c4 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),