From 773d65f413cfb91759046ba2cf99e9e76dd87264 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Fri, 12 Oct 2012 14:56:11 +0200 Subject: [PATCH] MEDIUM: log: suffix the frontend's name with '~' when using SSL Until now it was not possible to know from the logs whether the incoming connection was made over SSL or not. In order to address this in the existing log formats, a new log format %ft was introduced, to log the frontend's name suffixed with its transport layer. The only transport layer in use right now is '~' for SSL, so that existing log formats for non-SSL traffic are not affected at all, and SSL log formats have the frontend's name suffixed with '~'. The TCP, HTTP and CLF log format now use %ft instead of %f. This does not affect existing log formats which still make use of %f however. --- doc/configuration.txt | 7 ++++--- include/types/log.h | 1 + src/log.c | 27 ++++++++++++++++++++++++--- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/doc/configuration.txt b/doc/configuration.txt index da9d20540..aee1d904b 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -9699,18 +9699,18 @@ Flags are : At the moment, the default HTTP format is defined this way : - log-format %Ci:%Cp\ [%t]\ %f\ %b/%s\ %Tq/%Tw/%Tc/%Tr/%Tt\ %st\ %B\ %cc\ \ + log-format %Ci:%Cp\ [%t]\ %ft\ %b/%s\ %Tq/%Tw/%Tc/%Tr/%Tt\ %st\ %B\ %cc\ \ %cs\ %tsc\ %ac/%fc/%bc/%sc/%rc\ %sq/%bq\ %hr\ %hs\ %{+Q}r the default CLF format is defined this way : log-format %{+Q}o\ %{-Q}Ci\ -\ -\ [%T]\ %r\ %st\ %B\ \"\"\ \"\"\ %Cp\ \ - %ms\ %f\ %b\ %s\ \%Tq\ %Tw\ %Tc\ %Tr\ %Tt\ %tsc\ %ac\ %fc\ \ + %ms\ %ft\ %b\ %s\ \%Tq\ %Tw\ %Tc\ %Tr\ %Tt\ %tsc\ %ac\ %fc\ \ %bc\ %sc\ %rc\ %sq\ %bq\ %cc\ %cs\ \%hrl\ %hsl and the default TCP format is defined this way : - log-format %Ci:%Cp\ [%t]\ %f\ %b/%s\ %Tw/%Tc/%Tt\ %B\ %ts\ \ + log-format %Ci:%Cp\ [%t]\ %ft\ %b/%s\ %Tw/%Tc/%Tt\ %B\ %ts\ \ %ac/%fc/%bc/%sc/%rc\ %sq/%bq Please refer to the table below for currently defined variables : @@ -9746,6 +9746,7 @@ Please refer to the table below for currently defined variables : | * | %rt | http_request_counter | numeric | | * | %cs | captured_response_cookie | string | | | %f | frontend_name | string | + | | %ft | frontend_name_transport ('~' suffix for SSL) | string | | | %fc | feconn | numeric | | * | %hr | captured_request_headers default style | string | | * | %hrl | captured_request_headers CLF style | string list | diff --git a/include/types/log.h b/include/types/log.h index ac985fc47..02243260b 100644 --- a/include/types/log.h +++ b/include/types/log.h @@ -60,6 +60,7 @@ enum { LOG_FMT_TS, LOG_FMT_MS, LOG_FMT_FRONTEND, + LOG_FMT_FRONTEND_XPRT, LOG_FMT_BACKEND, LOG_FMT_SERVER, LOG_FMT_BYTES, diff --git a/src/log.c b/src/log.c index 2d33856ec..ce1b2a691 100644 --- a/src/log.c +++ b/src/log.c @@ -33,6 +33,9 @@ #include #include #include +#ifdef USE_OPENSSL +#include +#endif const char *log_facilities[NB_LOG_FACILITIES] = { "kern", "user", "mail", "daemon", @@ -80,6 +83,7 @@ static const struct logformat_type logformat_keywords[] = { { "Ts", LOG_FMT_TS, PR_MODE_TCP, LW_INIT, NULL }, /* timestamp GMT */ { "ms", LOG_FMT_MS, PR_MODE_TCP, LW_INIT, NULL }, /* accept date millisecond */ { "f", LOG_FMT_FRONTEND, PR_MODE_TCP, LW_INIT, NULL }, /* frontend */ + { "ft", LOG_FMT_FRONTEND_XPRT, PR_MODE_TCP, LW_INIT, NULL }, /* frontend with transport mode */ { "b", LOG_FMT_BACKEND, PR_MODE_TCP, LW_INIT, NULL }, /* backend */ { "s", LOG_FMT_SERVER, PR_MODE_TCP, LW_SVID, NULL }, /* server */ { "B", LOG_FMT_BYTES, PR_MODE_TCP, LW_BYTES, NULL }, /* bytes read */ @@ -112,9 +116,9 @@ static const struct logformat_type logformat_keywords[] = { { 0, 0, 0, 0, NULL } }; -char default_http_log_format[] = "%Ci:%Cp [%t] %f %b/%s %Tq/%Tw/%Tc/%Tr/%Tt %st %B %cc %cs %tsc %ac/%fc/%bc/%sc/%rc %sq/%bq %hr %hs %{+Q}r"; // default format -char clf_http_log_format[] = "%{+Q}o %{-Q}Ci - - [%T] %r %st %B \"\" \"\" %Cp %ms %f %b %s %Tq %Tw %Tc %Tr %Tt %tsc %ac %fc %bc %sc %rc %sq %bq %cc %cs %hrl %hsl"; -char default_tcp_log_format[] = "%Ci:%Cp [%t] %f %b/%s %Tw/%Tc/%Tt %B %ts %ac/%fc/%bc/%sc/%rc %sq/%bq"; +char default_http_log_format[] = "%Ci:%Cp [%t] %ft %b/%s %Tq/%Tw/%Tc/%Tr/%Tt %st %B %cc %cs %tsc %ac/%fc/%bc/%sc/%rc %sq/%bq %hr %hs %{+Q}r"; // default format +char clf_http_log_format[] = "%{+Q}o %{-Q}Ci - - [%T] %r %st %B \"\" \"\" %Cp %ms %ft %b %s %Tq %Tw %Tc %Tr %Tt %tsc %ac %fc %bc %sc %rc %sq %bq %cc %cs %hrl %hsl"; +char default_tcp_log_format[] = "%Ci:%Cp [%t] %ft %b/%s %Tw/%Tc/%Tt %B %ts %ac/%fc/%bc/%sc/%rc %sq/%bq"; char *log_format = NULL; /* This is a global syslog line, common to all outgoing messages. It begins @@ -981,6 +985,23 @@ int build_logline(struct session *s, char *dst, size_t maxsize, struct list *lis last_isspace = 0; break; + case LOG_FMT_FRONTEND_XPRT: // %ft + src = fe->id; + if (tmp->options & LOG_OPT_QUOTE) + LOGCHAR('"'); + iret = strlcpy2(tmplog, src, dst + maxsize - tmplog); + if (iret == 0) + goto out; + tmplog += iret; +#ifdef USE_OPENSSL + if (s->listener->xprt == &ssl_sock) + LOGCHAR('~'); +#endif + if (tmp->options & LOG_OPT_QUOTE) + LOGCHAR('"'); + last_isspace = 0; + break; + case LOG_FMT_BACKEND: // %b src = be->id; ret = lf_text(tmplog, src, dst + maxsize - tmplog, tmp);