mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2024-12-27 23:22:09 +00:00
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:
parent
c9c8e1cc01
commit
f9c4d8d5be
35
src/log.c
35
src/log.c
@ -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) {
|
||||
struct connection *conn;
|
||||
const struct sockaddr_storage *addr;
|
||||
const char *src = NULL;
|
||||
struct sample *key;
|
||||
const struct buffer empty = { };
|
||||
@ -2101,11 +2102,12 @@ int sess_build_logline(struct session *sess, struct stream *s, char *dst, size_t
|
||||
break;
|
||||
|
||||
case LOG_FMT_CLIENTIP: // %ci
|
||||
conn = objt_conn(sess->origin);
|
||||
if (conn && conn_get_src(conn))
|
||||
ret = lf_ip(tmplog, (struct sockaddr *)conn->src, dst + maxsize - tmplog, tmp);
|
||||
addr = (s ? si_src(&s->si[0]) : sess_src(sess));
|
||||
if (addr)
|
||||
ret = lf_ip(tmplog, (struct sockaddr *)addr, dst + maxsize - tmplog, tmp);
|
||||
else
|
||||
ret = lf_text_len(tmplog, NULL, 0, dst + maxsize - tmplog, tmp);
|
||||
|
||||
if (ret == NULL)
|
||||
goto out;
|
||||
tmplog = ret;
|
||||
@ -2113,14 +2115,12 @@ int sess_build_logline(struct session *sess, struct stream *s, char *dst, size_t
|
||||
break;
|
||||
|
||||
case LOG_FMT_CLIENTPORT: // %cp
|
||||
conn = objt_conn(sess->origin);
|
||||
if (conn && conn_get_src(conn)) {
|
||||
if (conn->src->ss_family == AF_UNIX) {
|
||||
addr = (s ? si_src(&s->si[0]) : sess_src(sess));
|
||||
if (addr) {
|
||||
if (addr->ss_family == AF_UNIX)
|
||||
ret = ltoa_o(sess->listener->luid, tmplog, dst + maxsize - tmplog);
|
||||
} else {
|
||||
ret = lf_port(tmplog, (struct sockaddr *)conn->src,
|
||||
dst + maxsize - tmplog, tmp);
|
||||
}
|
||||
else
|
||||
ret = lf_port(tmplog, (struct sockaddr *)addr, dst + maxsize - tmplog, tmp);
|
||||
}
|
||||
else
|
||||
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;
|
||||
|
||||
case LOG_FMT_FRONTENDIP: // %fi
|
||||
conn = objt_conn(sess->origin);
|
||||
if (conn && conn_get_dst(conn)) {
|
||||
ret = lf_ip(tmplog, (struct sockaddr *)conn->dst, dst + maxsize - tmplog, tmp);
|
||||
}
|
||||
addr = (s ? si_dst(&s->si[0]) : sess_dst(sess));
|
||||
if (addr)
|
||||
ret = lf_ip(tmplog, (struct sockaddr *)addr, dst + maxsize - tmplog, tmp);
|
||||
else
|
||||
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;
|
||||
|
||||
case LOG_FMT_FRONTENDPORT: // %fp
|
||||
conn = objt_conn(sess->origin);
|
||||
if (conn && conn_get_dst(conn)) {
|
||||
if (conn->dst->ss_family == AF_UNIX)
|
||||
addr = (s ? si_dst(&s->si[0]) : sess_dst(sess));
|
||||
if (addr) {
|
||||
if (addr->ss_family == AF_UNIX)
|
||||
ret = ltoa_o(sess->listener->luid, tmplog, dst + maxsize - tmplog);
|
||||
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
|
||||
ret = lf_text_len(tmplog, NULL, 0, dst + maxsize - tmplog, tmp);
|
||||
|
Loading…
Reference in New Issue
Block a user