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.
This commit is contained in:
Willy Tarreau 2012-10-12 14:56:11 +02:00
parent fd33a26d75
commit 773d65f413
3 changed files with 29 additions and 6 deletions

View File

@ -9699,18 +9699,18 @@ Flags are :
At the moment, the default HTTP format is defined this way : 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 %cs\ %tsc\ %ac/%fc/%bc/%sc/%rc\ %sq/%bq\ %hr\ %hs\ %{+Q}r
the default CLF format is defined this way : the default CLF format is defined this way :
log-format %{+Q}o\ %{-Q}Ci\ -\ -\ [%T]\ %r\ %st\ %B\ \"\"\ \"\"\ %Cp\ \ 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 %bc\ %sc\ %rc\ %sq\ %bq\ %cc\ %cs\ \%hrl\ %hsl
and the default TCP format is defined this way : 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 %ac/%fc/%bc/%sc/%rc\ %sq/%bq
Please refer to the table below for currently defined variables : 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 | | * | %rt | http_request_counter | numeric |
| * | %cs | captured_response_cookie | string | | * | %cs | captured_response_cookie | string |
| | %f | frontend_name | string | | | %f | frontend_name | string |
| | %ft | frontend_name_transport ('~' suffix for SSL) | string |
| | %fc | feconn | numeric | | | %fc | feconn | numeric |
| * | %hr | captured_request_headers default style | string | | * | %hr | captured_request_headers default style | string |
| * | %hrl | captured_request_headers CLF style | string list | | * | %hrl | captured_request_headers CLF style | string list |

View File

@ -60,6 +60,7 @@ enum {
LOG_FMT_TS, LOG_FMT_TS,
LOG_FMT_MS, LOG_FMT_MS,
LOG_FMT_FRONTEND, LOG_FMT_FRONTEND,
LOG_FMT_FRONTEND_XPRT,
LOG_FMT_BACKEND, LOG_FMT_BACKEND,
LOG_FMT_SERVER, LOG_FMT_SERVER,
LOG_FMT_BYTES, LOG_FMT_BYTES,

View File

@ -33,6 +33,9 @@
#include <proto/frontend.h> #include <proto/frontend.h>
#include <proto/log.h> #include <proto/log.h>
#include <proto/stream_interface.h> #include <proto/stream_interface.h>
#ifdef USE_OPENSSL
#include <proto/ssl_sock.h>
#endif
const char *log_facilities[NB_LOG_FACILITIES] = { const char *log_facilities[NB_LOG_FACILITIES] = {
"kern", "user", "mail", "daemon", "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 */ { "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 */ { "ms", LOG_FMT_MS, PR_MODE_TCP, LW_INIT, NULL }, /* accept date millisecond */
{ "f", LOG_FMT_FRONTEND, PR_MODE_TCP, LW_INIT, NULL }, /* frontend */ { "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 */ { "b", LOG_FMT_BACKEND, PR_MODE_TCP, LW_INIT, NULL }, /* backend */
{ "s", LOG_FMT_SERVER, PR_MODE_TCP, LW_SVID, NULL }, /* server */ { "s", LOG_FMT_SERVER, PR_MODE_TCP, LW_SVID, NULL }, /* server */
{ "B", LOG_FMT_BYTES, PR_MODE_TCP, LW_BYTES, NULL }, /* bytes read */ { "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 } { 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 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 %f %b %s %Tq %Tw %Tc %Tr %Tt %tsc %ac %fc %bc %sc %rc %sq %bq %cc %cs %hrl %hsl"; 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] %f %b/%s %Tw/%Tc/%Tt %B %ts %ac/%fc/%bc/%sc/%rc %sq/%bq"; 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; char *log_format = NULL;
/* This is a global syslog line, common to all outgoing messages. It begins /* 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; last_isspace = 0;
break; 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 case LOG_FMT_BACKEND: // %b
src = be->id; src = be->id;
ret = lf_text(tmplog, src, dst + maxsize - tmplog, tmp); ret = lf_text(tmplog, src, dst + maxsize - tmplog, tmp);