MINOR: log: Rely on client addresses at the appropriate level to log messages

When a log message is emitted, if the stream exits, we use the frontend
stream-interface to retrieve the client source and destination
addresses. Otherwise, the session is used. 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
addresses at the appropriate level when set instead of those at the
connection level.
This commit is contained in:
Christopher Faulet 2021-10-22 17:43:22 +02:00
parent c9c8e1cc01
commit f9c4d8d5be
1 changed files with 17 additions and 18 deletions

View File

@ -2053,6 +2053,7 @@ int sess_build_logline(struct session *sess, struct stream *s, char *dst, size_t
list_for_each_entry(tmp, list_format, list) { list_for_each_entry(tmp, list_format, list) {
struct connection *conn; struct connection *conn;
const struct sockaddr_storage *addr;
const char *src = NULL; const char *src = NULL;
struct sample *key; struct sample *key;
const struct buffer empty = { }; const struct buffer empty = { };
@ -2101,11 +2102,12 @@ int sess_build_logline(struct session *sess, struct stream *s, char *dst, size_t
break; break;
case LOG_FMT_CLIENTIP: // %ci case LOG_FMT_CLIENTIP: // %ci
conn = objt_conn(sess->origin); addr = (s ? si_src(&s->si[0]) : sess_src(sess));
if (conn && conn_get_src(conn)) if (addr)
ret = lf_ip(tmplog, (struct sockaddr *)conn->src, dst + maxsize - tmplog, tmp); ret = lf_ip(tmplog, (struct sockaddr *)addr, dst + maxsize - tmplog, tmp);
else else
ret = lf_text_len(tmplog, NULL, 0, dst + maxsize - tmplog, tmp); ret = lf_text_len(tmplog, NULL, 0, dst + maxsize - tmplog, tmp);
if (ret == NULL) if (ret == NULL)
goto out; goto out;
tmplog = ret; tmplog = ret;
@ -2113,14 +2115,12 @@ int sess_build_logline(struct session *sess, struct stream *s, char *dst, size_t
break; break;
case LOG_FMT_CLIENTPORT: // %cp case LOG_FMT_CLIENTPORT: // %cp
conn = objt_conn(sess->origin); addr = (s ? si_src(&s->si[0]) : sess_src(sess));
if (conn && conn_get_src(conn)) { if (addr) {
if (conn->src->ss_family == AF_UNIX) { if (addr->ss_family == AF_UNIX)
ret = ltoa_o(sess->listener->luid, tmplog, dst + maxsize - tmplog); ret = ltoa_o(sess->listener->luid, tmplog, dst + maxsize - tmplog);
} else { else
ret = lf_port(tmplog, (struct sockaddr *)conn->src, ret = lf_port(tmplog, (struct sockaddr *)addr, dst + maxsize - tmplog, tmp);
dst + maxsize - tmplog, tmp);
}
} }
else else
ret = lf_text_len(tmplog, NULL, 0, dst + maxsize - tmplog, tmp); ret = lf_text_len(tmplog, NULL, 0, dst + maxsize - tmplog, tmp);
@ -2132,10 +2132,9 @@ int sess_build_logline(struct session *sess, struct stream *s, char *dst, size_t
break; break;
case LOG_FMT_FRONTENDIP: // %fi case LOG_FMT_FRONTENDIP: // %fi
conn = objt_conn(sess->origin); addr = (s ? si_dst(&s->si[0]) : sess_dst(sess));
if (conn && conn_get_dst(conn)) { if (addr)
ret = lf_ip(tmplog, (struct sockaddr *)conn->dst, dst + maxsize - tmplog, tmp); ret = lf_ip(tmplog, (struct sockaddr *)addr, dst + maxsize - tmplog, tmp);
}
else else
ret = lf_text_len(tmplog, NULL, 0, dst + maxsize - tmplog, tmp); ret = lf_text_len(tmplog, NULL, 0, dst + maxsize - tmplog, tmp);
@ -2146,12 +2145,12 @@ int sess_build_logline(struct session *sess, struct stream *s, char *dst, size_t
break; break;
case LOG_FMT_FRONTENDPORT: // %fp case LOG_FMT_FRONTENDPORT: // %fp
conn = objt_conn(sess->origin); addr = (s ? si_dst(&s->si[0]) : sess_dst(sess));
if (conn && conn_get_dst(conn)) { if (addr) {
if (conn->dst->ss_family == AF_UNIX) if (addr->ss_family == AF_UNIX)
ret = ltoa_o(sess->listener->luid, tmplog, dst + maxsize - tmplog); ret = ltoa_o(sess->listener->luid, tmplog, dst + maxsize - tmplog);
else else
ret = lf_port(tmplog, (struct sockaddr *)conn->dst, dst + maxsize - tmplog, tmp); ret = lf_port(tmplog, (struct sockaddr *)addr, dst + maxsize - tmplog, tmp);
} }
else else
ret = lf_text_len(tmplog, NULL, 0, dst + maxsize - tmplog, tmp); ret = lf_text_len(tmplog, NULL, 0, dst + maxsize - tmplog, tmp);