]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: log: suffix the frontend's name with '~' when using SSL
authorWilly Tarreau <w@1wt.eu>
Fri, 12 Oct 2012 12:56:11 +0000 (14:56 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 12 Oct 2012 12:56:11 +0000 (14:56 +0200)
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
include/types/log.h
src/log.c

index da9d205400c03f0e71e448a9d772ef4ff3dda955..aee1d904b0737850666fa8cf86614fa9995e130d 100644 (file)
@@ -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 |
index ac985fc478e17b9b023ea4e946f52f906624a0d8..02243260bfdaa9fe0bba6a1f3501d1c2568f9f31 100644 (file)
@@ -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,
index 2d33856ec392ea4dd1f7ef5f7406db8945d1a8e3..ce1b2a6919f8584528497581946c9cd06ecbce04 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -33,6 +33,9 @@
 #include <proto/frontend.h>
 #include <proto/log.h>
 #include <proto/stream_interface.h>
+#ifdef USE_OPENSSL
+#include <proto/ssl_sock.h>
+#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);