MINOR: frontend: Rely on client src and dst addresses at stream level

For now, stream-interface or 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 the client addresses at the stream level, when set,
instead of those at the connection level. The addresses are retrieved from
the frontend stream-interface.
This commit is contained in:
Christopher Faulet 2021-10-22 17:39:06 +02:00
parent 859ff84f8c
commit c9c8e1cc01

View File

@ -47,6 +47,7 @@
*/ */
int frontend_accept(struct stream *s) int frontend_accept(struct stream *s)
{ {
const struct sockaddr_storage *src, *dst;
struct session *sess = s->sess; struct session *sess = s->sess;
struct connection *conn = objt_conn(sess->origin); struct connection *conn = objt_conn(sess->origin);
struct listener *l = sess->listener; struct listener *l = sess->listener;
@ -60,35 +61,38 @@ int frontend_accept(struct stream *s)
if (!(s->logs.logwait &= ~(LW_CLIP|LW_INIT))) if (!(s->logs.logwait &= ~(LW_CLIP|LW_INIT)))
s->do_log(s); s->do_log(s);
} }
else if (conn && !conn_get_src(conn)) {
send_log(fe, LOG_INFO, "Connect from unknown source to listener %d (%s/%s)\n",
l->luid, fe->id, (fe->mode == PR_MODE_HTTP) ? "HTTP" : "TCP");
}
else if (conn) { else if (conn) {
char pn[INET6_ADDRSTRLEN], sn[INET6_ADDRSTRLEN]; src = si_src(&s->si[0]);
int port; if (!src)
send_log(fe, LOG_INFO, "Connect from unknown source to listener %d (%s/%s)\n",
l->luid, fe->id, (fe->mode == PR_MODE_HTTP) ? "HTTP" : "TCP");
else {
char pn[INET6_ADDRSTRLEN], sn[INET6_ADDRSTRLEN];
int port;
switch (addr_to_str(conn->src, pn, sizeof(pn))) { switch (addr_to_str(src, pn, sizeof(pn))) {
case AF_INET: case AF_INET:
case AF_INET6: case AF_INET6:
if (conn_get_dst(conn)) { dst = si_dst(&s->si[0]);
addr_to_str(conn->dst, sn, sizeof(sn)); if (dst) {
port = get_host_port(conn->dst); addr_to_str(dst, sn, sizeof(sn));
} else { port = get_host_port(dst);
strcpy(sn, "undetermined address"); } else {
port = 0; strcpy(sn, "undetermined address");
port = 0;
}
send_log(fe, LOG_INFO, "Connect from %s:%d to %s:%d (%s/%s)\n",
pn, get_host_port(src),
sn, port,
fe->id, (fe->mode == PR_MODE_HTTP) ? "HTTP" : "TCP");
break;
case AF_UNIX:
/* UNIX socket, only the destination is known */
send_log(fe, LOG_INFO, "Connect to unix:%d (%s/%s)\n",
l->luid,
fe->id, (fe->mode == PR_MODE_HTTP) ? "HTTP" : "TCP");
break;
} }
send_log(fe, LOG_INFO, "Connect from %s:%d to %s:%d (%s/%s)\n",
pn, get_host_port(conn->src),
sn, port,
fe->id, (fe->mode == PR_MODE_HTTP) ? "HTTP" : "TCP");
break;
case AF_UNIX:
/* UNIX socket, only the destination is known */
send_log(fe, LOG_INFO, "Connect to unix:%d (%s/%s)\n",
l->luid,
fe->id, (fe->mode == PR_MODE_HTTP) ? "HTTP" : "TCP");
break;
} }
} }
} }
@ -109,17 +113,18 @@ int frontend_accept(struct stream *s)
} }
} }
if (!conn_get_src(conn)) { src = si_src(&s->si[0]);
if (!src) {
chunk_printf(&trash, "%08x:%s.accept(%04x)=%04x from [listener:%d] ALPN=%s\n", chunk_printf(&trash, "%08x:%s.accept(%04x)=%04x from [listener:%d] ALPN=%s\n",
s->uniq_id, fe->id, (unsigned short)l->rx.fd, (unsigned short)conn->handle.fd, s->uniq_id, fe->id, (unsigned short)l->rx.fd, (unsigned short)conn->handle.fd,
l->luid, alpn); l->luid, alpn);
} }
else switch (addr_to_str(conn->src, pn, sizeof(pn))) { else switch (addr_to_str(src, pn, sizeof(pn))) {
case AF_INET: case AF_INET:
case AF_INET6: case AF_INET6:
chunk_printf(&trash, "%08x:%s.accept(%04x)=%04x from [%s:%d] ALPN=%s\n", chunk_printf(&trash, "%08x:%s.accept(%04x)=%04x from [%s:%d] ALPN=%s\n",
s->uniq_id, fe->id, (unsigned short)l->rx.fd, (unsigned short)conn->handle.fd, s->uniq_id, fe->id, (unsigned short)l->rx.fd, (unsigned short)conn->handle.fd,
pn, get_host_port(conn->src), alpn); pn, get_host_port(src), alpn);
break; break;
case AF_UNIX: case AF_UNIX:
/* UNIX socket, only the destination is known */ /* UNIX socket, only the destination is known */