Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1 | /* |
| 2 | * General logging functions. |
| 3 | * |
Willy Tarreau | b7f694f | 2008-06-22 17:18:02 +0200 | [diff] [blame] | 4 | * Copyright 2000-2008 Willy Tarreau <w@1wt.eu> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version |
| 9 | * 2 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | */ |
| 12 | |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 13 | #include <ctype.h> |
Willy Tarreau | c8f24f8 | 2007-11-30 18:38:35 +0100 | [diff] [blame] | 14 | #include <fcntl.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 15 | #include <stdarg.h> |
| 16 | #include <stdio.h> |
| 17 | #include <stdlib.h> |
| 18 | #include <string.h> |
| 19 | #include <syslog.h> |
| 20 | #include <time.h> |
| 21 | #include <unistd.h> |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 22 | #include <errno.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 23 | |
| 24 | #include <sys/time.h> |
| 25 | |
Willy Tarreau | e3ba5f0 | 2006-06-29 18:54:54 +0200 | [diff] [blame] | 26 | #include <common/config.h> |
Willy Tarreau | d6d0690 | 2009-08-19 11:22:33 +0200 | [diff] [blame] | 27 | #include <common/compat.h> |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 28 | #include <common/standard.h> |
Willy Tarreau | fb27867 | 2006-10-15 15:38:50 +0200 | [diff] [blame] | 29 | #include <common/time.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 30 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 31 | #include <types/global.h> |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 32 | #include <types/log.h> |
Willy Tarreau | ec6c5df | 2008-07-15 00:22:45 +0200 | [diff] [blame] | 33 | |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 34 | #include <proto/frontend.h> |
Willy Tarreau | ec6c5df | 2008-07-15 00:22:45 +0200 | [diff] [blame] | 35 | #include <proto/log.h> |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 36 | #include <proto/sample.h> |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 37 | #include <proto/stream_interface.h> |
Willy Tarreau | 773d65f | 2012-10-12 14:56:11 +0200 | [diff] [blame] | 38 | #ifdef USE_OPENSSL |
| 39 | #include <proto/ssl_sock.h> |
| 40 | #endif |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 41 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 42 | const char *log_facilities[NB_LOG_FACILITIES] = { |
| 43 | "kern", "user", "mail", "daemon", |
| 44 | "auth", "syslog", "lpr", "news", |
| 45 | "uucp", "cron", "auth2", "ftp", |
| 46 | "ntp", "audit", "alert", "cron2", |
| 47 | "local0", "local1", "local2", "local3", |
| 48 | "local4", "local5", "local6", "local7" |
| 49 | }; |
| 50 | |
| 51 | |
| 52 | const char *log_levels[NB_LOG_LEVELS] = { |
| 53 | "emerg", "alert", "crit", "err", |
| 54 | "warning", "notice", "info", "debug" |
| 55 | }; |
| 56 | |
Willy Tarreau | 570f221 | 2013-06-10 16:42:09 +0200 | [diff] [blame] | 57 | const char sess_term_cond[16] = "-LcCsSPRIDKUIIII"; /* normal, Local, CliTo, CliErr, SrvTo, SrvErr, PxErr, Resource, Internal, Down, Killed, Up, -- */ |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 58 | const char sess_fin_state[8] = "-RCHDLQT"; /* cliRequest, srvConnect, srvHeader, Data, Last, Queue, Tarpit */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 59 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 60 | |
| 61 | /* log_format */ |
| 62 | struct logformat_type { |
| 63 | char *name; |
| 64 | int type; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 65 | int mode; |
William Lallemand | 5e19a28 | 2012-04-02 16:22:10 +0200 | [diff] [blame] | 66 | int lw; /* logwait bitsfield */ |
William Lallemand | b7ff6a3 | 2012-03-02 14:35:21 +0100 | [diff] [blame] | 67 | int (*config_callback)(struct logformat_node *node, struct proxy *curproxy); |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 68 | const char *replace_by; /* new option to use instead of old one */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 69 | }; |
| 70 | |
William Lallemand | b7ff6a3 | 2012-03-02 14:35:21 +0100 | [diff] [blame] | 71 | int prepare_addrsource(struct logformat_node *node, struct proxy *curproxy); |
| 72 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 73 | /* log_format variable names */ |
| 74 | static const struct logformat_type logformat_keywords[] = { |
William Lallemand | 5e19a28 | 2012-04-02 16:22:10 +0200 | [diff] [blame] | 75 | { "o", LOG_FMT_GLOBAL, PR_MODE_TCP, 0, NULL }, /* global option */ |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 76 | |
| 77 | /* please keep these lines sorted ! */ |
| 78 | { "B", LOG_FMT_BYTES, PR_MODE_TCP, LW_BYTES, NULL }, /* bytes from server to client */ |
| 79 | { "CC", LOG_FMT_CCLIENT, PR_MODE_HTTP, LW_REQHDR, NULL }, /* client cookie */ |
| 80 | { "CS", LOG_FMT_CSERVER, PR_MODE_HTTP, LW_RSPHDR, NULL }, /* server cookie */ |
| 81 | { "H", LOG_FMT_HOSTNAME, PR_MODE_TCP, LW_INIT, NULL }, /* Hostname */ |
| 82 | { "ID", LOG_FMT_UNIQUEID, PR_MODE_HTTP, LW_BYTES, NULL }, /* Unique ID */ |
| 83 | { "ST", LOG_FMT_STATUS, PR_MODE_HTTP, LW_RESP, NULL }, /* status code */ |
William Lallemand | 5e19a28 | 2012-04-02 16:22:10 +0200 | [diff] [blame] | 84 | { "T", LOG_FMT_DATEGMT, PR_MODE_TCP, LW_INIT, NULL }, /* date GMT */ |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 85 | { "Tc", LOG_FMT_TC, PR_MODE_TCP, LW_BYTES, NULL }, /* Tc */ |
Yuxans Yao | 4e25b01 | 2012-10-19 10:36:09 +0800 | [diff] [blame] | 86 | { "Tl", LOG_FMT_DATELOCAL, PR_MODE_TCP, LW_INIT, NULL }, /* date local timezone */ |
William Lallemand | 5e19a28 | 2012-04-02 16:22:10 +0200 | [diff] [blame] | 87 | { "Tq", LOG_FMT_TQ, PR_MODE_HTTP, LW_BYTES, NULL }, /* Tq */ |
William Lallemand | 5e19a28 | 2012-04-02 16:22:10 +0200 | [diff] [blame] | 88 | { "Tr", LOG_FMT_TR, PR_MODE_HTTP, LW_BYTES, NULL }, /* Tr */ |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 89 | { "Ts", LOG_FMT_TS, PR_MODE_TCP, LW_INIT, NULL }, /* timestamp GMT */ |
William Lallemand | 5e19a28 | 2012-04-02 16:22:10 +0200 | [diff] [blame] | 90 | { "Tt", LOG_FMT_TT, PR_MODE_TCP, LW_BYTES, NULL }, /* Tt */ |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 91 | { "Tw", LOG_FMT_TW, PR_MODE_TCP, LW_BYTES, NULL }, /* Tw */ |
| 92 | { "U", LOG_FMT_BYTES_UP, PR_MODE_TCP, LW_BYTES, NULL }, /* bytes from client to server */ |
William Lallemand | 5e19a28 | 2012-04-02 16:22:10 +0200 | [diff] [blame] | 93 | { "ac", LOG_FMT_ACTCONN, PR_MODE_TCP, LW_BYTES, NULL }, /* actconn */ |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 94 | { "b", LOG_FMT_BACKEND, PR_MODE_TCP, LW_INIT, NULL }, /* backend */ |
William Lallemand | 5e19a28 | 2012-04-02 16:22:10 +0200 | [diff] [blame] | 95 | { "bc", LOG_FMT_BECONN, PR_MODE_TCP, LW_BYTES, NULL }, /* beconn */ |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 96 | { "bi", LOG_FMT_BACKENDIP, PR_MODE_TCP, LW_BCKIP, prepare_addrsource }, /* backend source ip */ |
| 97 | { "bp", LOG_FMT_BACKENDPORT, PR_MODE_TCP, LW_BCKIP, prepare_addrsource }, /* backend source port */ |
William Lallemand | 5e19a28 | 2012-04-02 16:22:10 +0200 | [diff] [blame] | 98 | { "bq", LOG_FMT_BCKQUEUE, PR_MODE_TCP, LW_BYTES, NULL }, /* backend_queue */ |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 99 | { "ci", LOG_FMT_CLIENTIP, PR_MODE_TCP, LW_CLIP, NULL }, /* client ip */ |
| 100 | { "cp", LOG_FMT_CLIENTPORT, PR_MODE_TCP, LW_CLIP, NULL }, /* client port */ |
| 101 | { "f", LOG_FMT_FRONTEND, PR_MODE_TCP, LW_INIT, NULL }, /* frontend */ |
| 102 | { "fc", LOG_FMT_FECONN, PR_MODE_TCP, LW_BYTES, NULL }, /* feconn */ |
| 103 | { "fi", LOG_FMT_FRONTENDIP, PR_MODE_TCP, LW_FRTIP, NULL }, /* frontend ip */ |
| 104 | { "fp", LOG_FMT_FRONTENDPORT, PR_MODE_TCP, LW_FRTIP, NULL }, /* frontend port */ |
| 105 | { "ft", LOG_FMT_FRONTEND_XPRT, PR_MODE_TCP, LW_INIT, NULL }, /* frontend with transport mode */ |
William Lallemand | 5e19a28 | 2012-04-02 16:22:10 +0200 | [diff] [blame] | 106 | { "hr", LOG_FMT_HDRREQUEST, PR_MODE_HTTP, LW_REQHDR, NULL }, /* header request */ |
William Lallemand | 5e19a28 | 2012-04-02 16:22:10 +0200 | [diff] [blame] | 107 | { "hrl", LOG_FMT_HDRREQUESTLIST, PR_MODE_HTTP, LW_REQHDR, NULL }, /* header request list */ |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 108 | { "hs", LOG_FMT_HDRRESPONS, PR_MODE_HTTP, LW_RSPHDR, NULL }, /* header response */ |
William Lallemand | 5e19a28 | 2012-04-02 16:22:10 +0200 | [diff] [blame] | 109 | { "hsl", LOG_FMT_HDRRESPONSLIST, PR_MODE_HTTP, LW_RSPHDR, NULL }, /* header response list */ |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 110 | { "ms", LOG_FMT_MS, PR_MODE_TCP, LW_INIT, NULL }, /* accept date millisecond */ |
William Lallemand | 5e19a28 | 2012-04-02 16:22:10 +0200 | [diff] [blame] | 111 | { "pid", LOG_FMT_PID, PR_MODE_TCP, LW_INIT, NULL }, /* log pid */ |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 112 | { "r", LOG_FMT_REQ, PR_MODE_HTTP, LW_REQ, NULL }, /* request */ |
| 113 | { "rc", LOG_FMT_RETRIES, PR_MODE_TCP, LW_BYTES, NULL }, /* retries */ |
William Lallemand | 5e19a28 | 2012-04-02 16:22:10 +0200 | [diff] [blame] | 114 | { "rt", LOG_FMT_COUNTER, PR_MODE_HTTP, LW_REQ, NULL }, /* HTTP request counter */ |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 115 | { "s", LOG_FMT_SERVER, PR_MODE_TCP, LW_SVID, NULL }, /* server */ |
| 116 | { "sc", LOG_FMT_SRVCONN, PR_MODE_TCP, LW_BYTES, NULL }, /* srv_conn */ |
| 117 | { "si", LOG_FMT_SERVERIP, PR_MODE_TCP, LW_SVIP, NULL }, /* server destination ip */ |
| 118 | { "sp", LOG_FMT_SERVERPORT, PR_MODE_TCP, LW_SVIP, NULL }, /* server destination port */ |
| 119 | { "sq", LOG_FMT_SRVQUEUE, PR_MODE_TCP, LW_BYTES, NULL }, /* srv_queue */ |
Willy Tarreau | ffc3fcd | 2012-10-12 20:17:54 +0200 | [diff] [blame] | 120 | { "sslc", LOG_FMT_SSL_CIPHER, PR_MODE_TCP, LW_XPRT, NULL }, /* client-side SSL ciphers */ |
| 121 | { "sslv", LOG_FMT_SSL_VERSION, PR_MODE_TCP, LW_XPRT, NULL }, /* client-side SSL protocol version */ |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 122 | { "t", LOG_FMT_DATE, PR_MODE_TCP, LW_INIT, NULL }, /* date */ |
| 123 | { "ts", LOG_FMT_TERMSTATE, PR_MODE_TCP, LW_BYTES, NULL },/* termination state */ |
| 124 | { "tsc", LOG_FMT_TERMSTATE_CK, PR_MODE_TCP, LW_INIT, NULL },/* termination state */ |
| 125 | |
| 126 | /* The following tags are deprecated and will be removed soon */ |
| 127 | { "Bi", LOG_FMT_BACKENDIP, PR_MODE_TCP, LW_BCKIP, prepare_addrsource, "bi" }, /* backend source ip */ |
| 128 | { "Bp", LOG_FMT_BACKENDPORT, PR_MODE_TCP, LW_BCKIP, prepare_addrsource, "bp" }, /* backend source port */ |
| 129 | { "Ci", LOG_FMT_CLIENTIP, PR_MODE_TCP, LW_CLIP, NULL, "ci" }, /* client ip */ |
| 130 | { "Cp", LOG_FMT_CLIENTPORT, PR_MODE_TCP, LW_CLIP, NULL, "cp" }, /* client port */ |
| 131 | { "Fi", LOG_FMT_FRONTENDIP, PR_MODE_TCP, LW_FRTIP, NULL, "fi" }, /* frontend ip */ |
| 132 | { "Fp", LOG_FMT_FRONTENDPORT, PR_MODE_TCP, LW_FRTIP, NULL, "fp" }, /* frontend port */ |
| 133 | { "Si", LOG_FMT_SERVERIP, PR_MODE_TCP, LW_SVIP, NULL, "si" }, /* server destination ip */ |
| 134 | { "Sp", LOG_FMT_SERVERPORT, PR_MODE_TCP, LW_SVIP, NULL, "sp" }, /* server destination port */ |
| 135 | { "cc", LOG_FMT_CCLIENT, PR_MODE_HTTP, LW_REQHDR, NULL, "CC" }, /* client cookie */ |
| 136 | { "cs", LOG_FMT_CSERVER, PR_MODE_HTTP, LW_RSPHDR, NULL, "CS" }, /* server cookie */ |
| 137 | { "st", LOG_FMT_STATUS, PR_MODE_HTTP, LW_RESP, NULL, "ST" }, /* status code */ |
William Lallemand | 5e19a28 | 2012-04-02 16:22:10 +0200 | [diff] [blame] | 138 | { 0, 0, 0, 0, NULL } |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 139 | }; |
| 140 | |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 141 | 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 |
| 142 | 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"; |
| 143 | char default_tcp_log_format[] = "%ci:%cp [%t] %ft %b/%s %Tw/%Tc/%Tt %B %ts %ac/%fc/%bc/%sc/%rc %sq/%bq"; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 144 | char *log_format = NULL; |
| 145 | |
Willy Tarreau | b1a2faf | 2012-03-19 16:51:53 +0100 | [diff] [blame] | 146 | /* This is a global syslog line, common to all outgoing messages. It begins |
| 147 | * with the syslog tag and the date that are updated by update_log_hdr(). |
| 148 | */ |
| 149 | static char logline[MAX_SYSLOG_LEN]; |
| 150 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 151 | struct logformat_var_args { |
| 152 | char *name; |
| 153 | int mask; |
| 154 | }; |
| 155 | |
| 156 | struct logformat_var_args var_args_list[] = { |
| 157 | // global |
| 158 | { "M", LOG_OPT_MANDATORY }, |
| 159 | { "Q", LOG_OPT_QUOTE }, |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 160 | { "X", LOG_OPT_HEXA }, |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 161 | { 0, 0 } |
| 162 | }; |
| 163 | |
Willy Tarreau | b1f3af2 | 2013-04-12 18:30:32 +0200 | [diff] [blame] | 164 | /* return the name of the directive used in the current proxy for which we're |
| 165 | * currently parsing a header, when it is known. |
| 166 | */ |
| 167 | static inline const char *fmt_directive(const struct proxy *curproxy) |
| 168 | { |
Willy Tarreau | bf0addb | 2013-12-02 12:24:54 +0100 | [diff] [blame] | 169 | switch (curproxy->conf.args.ctx) { |
| 170 | case ARGC_UIF: |
Willy Tarreau | b1f3af2 | 2013-04-12 18:30:32 +0200 | [diff] [blame] | 171 | return "unique-id-format"; |
Willy Tarreau | bf0addb | 2013-12-02 12:24:54 +0100 | [diff] [blame] | 172 | case ARGC_HRQ: |
Thierry FOURNIER | 1c0054f | 2013-11-20 15:09:52 +0100 | [diff] [blame] | 173 | return "http-request"; |
Willy Tarreau | bf0addb | 2013-12-02 12:24:54 +0100 | [diff] [blame] | 174 | case ARGC_HRS: |
Thierry FOURNIER | 1c0054f | 2013-11-20 15:09:52 +0100 | [diff] [blame] | 175 | return "http-response"; |
Willy Tarreau | bf0addb | 2013-12-02 12:24:54 +0100 | [diff] [blame] | 176 | case ARGC_STK: |
| 177 | return "stick"; |
| 178 | case ARGC_TRK: |
| 179 | return "track-sc"; break; |
Thierry FOURNIER | d18cd0f | 2013-11-29 12:15:45 +0100 | [diff] [blame] | 180 | case ARGC_RDR: |
| 181 | return "redirect"; break; |
Willy Tarreau | bf0addb | 2013-12-02 12:24:54 +0100 | [diff] [blame] | 182 | case ARGC_ACL: |
| 183 | return "acl"; break; |
| 184 | default: |
Willy Tarreau | b1f3af2 | 2013-04-12 18:30:32 +0200 | [diff] [blame] | 185 | return "log-format"; |
Willy Tarreau | bf0addb | 2013-12-02 12:24:54 +0100 | [diff] [blame] | 186 | } |
Willy Tarreau | b1f3af2 | 2013-04-12 18:30:32 +0200 | [diff] [blame] | 187 | } |
| 188 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 189 | /* |
William Lallemand | b7ff6a3 | 2012-03-02 14:35:21 +0100 | [diff] [blame] | 190 | * callback used to configure addr source retrieval |
| 191 | */ |
| 192 | int prepare_addrsource(struct logformat_node *node, struct proxy *curproxy) |
| 193 | { |
| 194 | curproxy->options2 |= PR_O2_SRC_ADDR; |
| 195 | |
| 196 | return 0; |
| 197 | } |
| 198 | |
| 199 | |
| 200 | /* |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 201 | * Parse args in a logformat_var |
| 202 | */ |
| 203 | int parse_logformat_var_args(char *args, struct logformat_node *node) |
| 204 | { |
| 205 | int i = 0; |
| 206 | int end = 0; |
| 207 | int flags = 0; // 1 = + 2 = - |
| 208 | char *sp = NULL; // start pointer |
| 209 | |
| 210 | if (args == NULL) |
| 211 | return 1; |
| 212 | |
| 213 | while (1) { |
| 214 | if (*args == '\0') |
| 215 | end = 1; |
| 216 | |
| 217 | if (*args == '+') { |
| 218 | // add flag |
| 219 | sp = args + 1; |
| 220 | flags = 1; |
| 221 | } |
| 222 | if (*args == '-') { |
| 223 | // delete flag |
| 224 | sp = args + 1; |
| 225 | flags = 2; |
| 226 | } |
| 227 | |
| 228 | if (*args == '\0' || *args == ',') { |
| 229 | *args = '\0'; |
Willy Tarreau | 254d44c | 2012-12-20 18:19:26 +0100 | [diff] [blame] | 230 | for (i = 0; sp && var_args_list[i].name; i++) { |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 231 | if (strcmp(sp, var_args_list[i].name) == 0) { |
| 232 | if (flags == 1) { |
| 233 | node->options |= var_args_list[i].mask; |
| 234 | break; |
| 235 | } else if (flags == 2) { |
| 236 | node->options &= ~var_args_list[i].mask; |
| 237 | break; |
| 238 | } |
| 239 | } |
| 240 | } |
| 241 | sp = NULL; |
| 242 | if (end) |
| 243 | break; |
| 244 | } |
Willy Tarreau | 254d44c | 2012-12-20 18:19:26 +0100 | [diff] [blame] | 245 | args++; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 246 | } |
| 247 | return 0; |
| 248 | } |
| 249 | |
| 250 | /* |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 251 | * Parse a variable '%varname' or '%{args}varname' in log-format. The caller |
| 252 | * must pass the args part in the <arg> pointer with its length in <arg_len>, |
| 253 | * and varname with its length in <var> and <var_len> respectively. <arg> is |
| 254 | * ignored when arg_len is 0. Neither <var> nor <var_len> may be null. |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 255 | */ |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 256 | int parse_logformat_var(char *arg, int arg_len, char *var, int var_len, struct proxy *curproxy, struct list *list_format, int *defoptions) |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 257 | { |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 258 | int j; |
| 259 | struct logformat_node *node; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 260 | |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 261 | for (j = 0; logformat_keywords[j].name; j++) { // search a log type |
| 262 | if (strlen(logformat_keywords[j].name) == var_len && |
| 263 | strncmp(var, logformat_keywords[j].name, var_len) == 0) { |
| 264 | if (logformat_keywords[j].mode != PR_MODE_HTTP || curproxy->mode == PR_MODE_HTTP) { |
| 265 | node = calloc(1, sizeof(struct logformat_node)); |
| 266 | node->type = logformat_keywords[j].type; |
| 267 | node->options = *defoptions; |
| 268 | if (arg_len) { |
| 269 | node->arg = my_strndup(arg, arg_len); |
| 270 | parse_logformat_var_args(node->arg, node); |
| 271 | } |
| 272 | if (node->type == LOG_FMT_GLOBAL) { |
| 273 | *defoptions = node->options; |
| 274 | free(node->arg); |
| 275 | free(node); |
| 276 | } else { |
| 277 | if (logformat_keywords[j].config_callback && |
| 278 | logformat_keywords[j].config_callback(node, curproxy) != 0) { |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 279 | return -1; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 280 | } |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 281 | curproxy->to_log |= logformat_keywords[j].lw; |
| 282 | LIST_ADDQ(list_format, &node->list); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 283 | } |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 284 | if (logformat_keywords[j].replace_by) |
Willy Tarreau | 06d97f9 | 2013-12-02 17:45:48 +0100 | [diff] [blame] | 285 | Warning("parsing [%s:%d] : deprecated variable '%s' in '%s', please replace it with '%s'.\n", |
Willy Tarreau | b1f3af2 | 2013-04-12 18:30:32 +0200 | [diff] [blame] | 286 | curproxy->conf.args.file, curproxy->conf.args.line, |
| 287 | logformat_keywords[j].name, fmt_directive(curproxy), logformat_keywords[j].replace_by); |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 288 | return 0; |
| 289 | } else { |
Willy Tarreau | 06d97f9 | 2013-12-02 17:45:48 +0100 | [diff] [blame] | 290 | Warning("parsing [%s:%d] : '%s' : format variable '%s' is reserved for HTTP mode.\n", |
Willy Tarreau | b1f3af2 | 2013-04-12 18:30:32 +0200 | [diff] [blame] | 291 | curproxy->conf.args.file, curproxy->conf.args.line, fmt_directive(curproxy), |
| 292 | logformat_keywords[j].name); |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 293 | return -1; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 294 | } |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 295 | } |
| 296 | } |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 297 | |
| 298 | j = var[var_len]; |
| 299 | var[var_len] = 0; |
Willy Tarreau | 06d97f9 | 2013-12-02 17:45:48 +0100 | [diff] [blame] | 300 | Warning("parsing [%s:%d] : no such format variable '%s' in '%s'. If you wanted to emit the '%%' character verbatim, you need to use '%%%%' in log-format expressions.\n", |
Willy Tarreau | b1f3af2 | 2013-04-12 18:30:32 +0200 | [diff] [blame] | 301 | curproxy->conf.args.file, curproxy->conf.args.line, var, fmt_directive(curproxy)); |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 302 | var[var_len] = j; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 303 | return -1; |
| 304 | } |
| 305 | |
| 306 | /* |
| 307 | * push to the logformat linked list |
| 308 | * |
| 309 | * start: start pointer |
| 310 | * end: end text pointer |
| 311 | * type: string type |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 312 | * list_format: destination list |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 313 | * |
| 314 | * LOG_TEXT: copy chars from start to end excluding end. |
| 315 | * |
| 316 | */ |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 317 | void add_to_logformat_list(char *start, char *end, int type, struct list *list_format) |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 318 | { |
| 319 | char *str; |
| 320 | |
Willy Tarreau | a357166 | 2012-12-20 21:59:12 +0100 | [diff] [blame] | 321 | if (type == LF_TEXT) { /* type text */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 322 | struct logformat_node *node = calloc(1, sizeof(struct logformat_node)); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 323 | str = calloc(end - start + 1, 1); |
| 324 | strncpy(str, start, end - start); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 325 | str[end - start] = '\0'; |
| 326 | node->arg = str; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 327 | node->type = LOG_FMT_TEXT; // type string |
| 328 | LIST_ADDQ(list_format, &node->list); |
Willy Tarreau | a357166 | 2012-12-20 21:59:12 +0100 | [diff] [blame] | 329 | } else if (type == LF_SEPARATOR) { |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 330 | struct logformat_node *node = calloc(1, sizeof(struct logformat_node)); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 331 | node->type = LOG_FMT_SEPARATOR; |
| 332 | LIST_ADDQ(list_format, &node->list); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 333 | } |
| 334 | } |
| 335 | |
| 336 | /* |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 337 | * Parse the sample fetch expression <text> and add a node to <list_format> upon |
| 338 | * success. At the moment, sample converters are not yet supported but fetch arguments |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 339 | * should work. The curpx->conf.args.ctx must be set by the caller. |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 340 | */ |
Willy Tarreau | 434c57c | 2013-01-08 01:10:24 +0100 | [diff] [blame] | 341 | void add_sample_to_logformat_list(char *text, char *arg, int arg_len, struct proxy *curpx, struct list *list_format, int options, int cap) |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 342 | { |
| 343 | char *cmd[2]; |
| 344 | struct sample_expr *expr; |
| 345 | struct logformat_node *node; |
| 346 | int cmd_arg; |
| 347 | |
| 348 | cmd[0] = text; |
| 349 | cmd[1] = ""; |
| 350 | cmd_arg = 0; |
| 351 | |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 352 | expr = sample_parse_expr(cmd, &cmd_arg, trash.str, trash.size, &curpx->conf.args); |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 353 | if (!expr) { |
Willy Tarreau | b1f3af2 | 2013-04-12 18:30:32 +0200 | [diff] [blame] | 354 | Warning("parsing [%s:%d] : '%s' : sample fetch <%s> failed with : %s\n", |
| 355 | curpx->conf.args.file, curpx->conf.args.line, fmt_directive(curpx), |
| 356 | text, trash.str); |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 357 | return; |
| 358 | } |
| 359 | |
| 360 | node = calloc(1, sizeof(struct logformat_node)); |
| 361 | node->type = LOG_FMT_EXPR; |
| 362 | node->expr = expr; |
| 363 | node->options = options; |
| 364 | |
| 365 | if (arg_len) { |
| 366 | node->arg = my_strndup(arg, arg_len); |
| 367 | parse_logformat_var_args(node->arg, node); |
| 368 | } |
Willy Tarreau | 434c57c | 2013-01-08 01:10:24 +0100 | [diff] [blame] | 369 | if (expr->fetch->val & cap & SMP_VAL_REQUEST) |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 370 | node->options |= LOG_OPT_REQ_CAP; /* fetch method is request-compatible */ |
| 371 | |
Willy Tarreau | 434c57c | 2013-01-08 01:10:24 +0100 | [diff] [blame] | 372 | if (expr->fetch->val & cap & SMP_VAL_RESPONSE) |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 373 | node->options |= LOG_OPT_RES_CAP; /* fetch method is response-compatible */ |
| 374 | |
Willy Tarreau | 434c57c | 2013-01-08 01:10:24 +0100 | [diff] [blame] | 375 | if (!(expr->fetch->val & cap)) |
Willy Tarreau | b1f3af2 | 2013-04-12 18:30:32 +0200 | [diff] [blame] | 376 | Warning("parsing [%s:%d] : '%s' : sample fetch <%s> may not be reliably used here because it needs '%s' which is not available here.\n", |
| 377 | curpx->conf.args.file, curpx->conf.args.line, fmt_directive(curpx), |
| 378 | text, sample_src_names(expr->fetch->use)); |
Willy Tarreau | 434c57c | 2013-01-08 01:10:24 +0100 | [diff] [blame] | 379 | |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 380 | /* check if we need to allocate an hdr_idx struct for HTTP parsing */ |
| 381 | /* Note, we may also need to set curpx->to_log with certain fetches */ |
Willy Tarreau | 25320b2 | 2013-03-24 07:22:08 +0100 | [diff] [blame] | 382 | curpx->http_needed |= !!(expr->fetch->use & SMP_USE_HTTP_ANY); |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 383 | |
Willy Tarreau | 1f31c73 | 2013-01-10 16:22:27 +0100 | [diff] [blame] | 384 | /* FIXME: temporary workaround for missing LW_XPRT flag needed with some |
| 385 | * sample fetches (eg: ssl*). We always set it for now on, but this will |
| 386 | * leave with sample capabilities soon. |
| 387 | */ |
| 388 | curpx->to_log |= LW_XPRT; |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 389 | LIST_ADDQ(list_format, &node->list); |
| 390 | } |
| 391 | |
| 392 | /* |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 393 | * Parse the log_format string and fill a linked list. |
| 394 | * Variable name are preceded by % and composed by characters [a-zA-Z0-9]* : %varname |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 395 | * You can set arguments using { } : %{many arguments}varname. |
| 396 | * The curproxy->conf.args.ctx must be set by the caller. |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 397 | * |
| 398 | * str: the string to parse |
| 399 | * curproxy: the proxy affected |
| 400 | * list_format: the destination list |
Willy Tarreau | 6cbbdbf | 2013-02-05 18:52:25 +0100 | [diff] [blame] | 401 | * options: LOG_OPT_* to force on every node |
Willy Tarreau | 434c57c | 2013-01-08 01:10:24 +0100 | [diff] [blame] | 402 | * cap: all SMP_VAL_* flags supported by the consumer |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 403 | */ |
Willy Tarreau | 434c57c | 2013-01-08 01:10:24 +0100 | [diff] [blame] | 404 | void parse_logformat_string(const char *fmt, struct proxy *curproxy, struct list *list_format, int options, int cap) |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 405 | { |
Willy Tarreau | b83bc1e | 2012-12-24 12:36:33 +0100 | [diff] [blame] | 406 | char *sp, *str, *backfmt; /* start pointer for text parts */ |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 407 | char *arg = NULL; /* start pointer for args */ |
| 408 | char *var = NULL; /* start pointer for vars */ |
| 409 | int arg_len = 0; |
| 410 | int var_len = 0; |
| 411 | int cformat; /* current token format */ |
| 412 | int pformat; /* previous token format */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 413 | struct logformat_node *tmplf, *back; |
| 414 | |
Willy Tarreau | b83bc1e | 2012-12-24 12:36:33 +0100 | [diff] [blame] | 415 | sp = str = backfmt = strdup(fmt); |
William Lallemand | 1dc00ef | 2012-08-09 16:41:35 +0200 | [diff] [blame] | 416 | curproxy->to_log |= LW_INIT; |
William Lallemand | 5e19a28 | 2012-04-02 16:22:10 +0200 | [diff] [blame] | 417 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 418 | /* flush the list first. */ |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 419 | list_for_each_entry_safe(tmplf, back, list_format, list) { |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 420 | LIST_DEL(&tmplf->list); |
| 421 | free(tmplf); |
| 422 | } |
| 423 | |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 424 | for (cformat = LF_INIT; cformat != LF_END; str++) { |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 425 | pformat = cformat; |
| 426 | |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 427 | if (!*str) |
| 428 | cformat = LF_END; // preset it to save all states from doing this |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 429 | |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 430 | /* The prinicple of the two-step state machine below is to first detect a change, and |
| 431 | * second have all common paths processed at one place. The common paths are the ones |
| 432 | * encountered in text areas (LF_INIT, LF_TEXT, LF_SEPARATOR) and at the end (LF_END). |
| 433 | * We use the common LF_INIT state to dispatch to the different final states. |
| 434 | */ |
| 435 | switch (pformat) { |
| 436 | case LF_STARTVAR: // text immediately following a '%' |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 437 | arg = NULL; var = NULL; |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 438 | arg_len = var_len = 0; |
| 439 | if (*str == '{') { // optional argument |
| 440 | cformat = LF_STARG; |
| 441 | arg = str + 1; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 442 | } |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 443 | else if (*str == '[') { |
| 444 | cformat = LF_STEXPR; |
| 445 | var = str + 1; // store expr in variable name |
| 446 | } |
Willy Tarreau | 06d97f9 | 2013-12-02 17:45:48 +0100 | [diff] [blame] | 447 | else if (isalpha((int)*str)) { // variable name |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 448 | cformat = LF_VAR; |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 449 | var = str; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 450 | } |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 451 | else if (*str == '%') |
| 452 | cformat = LF_TEXT; // convert this character to a litteral (useful for '%') |
Willy Tarreau | 9eba36b | 2013-12-03 00:51:09 +0100 | [diff] [blame] | 453 | else if (isdigit(*str) || *str == ' ' || *str == '\t') { |
Willy Tarreau | 06d97f9 | 2013-12-02 17:45:48 +0100 | [diff] [blame] | 454 | /* single '%' followed by blank or digit, send them both */ |
| 455 | cformat = LF_TEXT; |
| 456 | pformat = LF_TEXT; /* finally we include the previous char as well */ |
| 457 | sp = str - 1; /* send both the '%' and the current char */ |
| 458 | Warning("parsing [%s:%d] : Fixed missing '%%' before '%c' at position %d in %s line : '%s'. Please use '%%%%' when you need the '%%' character in a log-format expression.\n", |
| 459 | curproxy->conf.args.file, curproxy->conf.args.line, *str, (int)(str - backfmt), fmt_directive(curproxy), fmt); |
| 460 | |
| 461 | } |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 462 | else |
| 463 | cformat = LF_INIT; // handle other cases of litterals |
| 464 | break; |
| 465 | |
| 466 | case LF_STARG: // text immediately following '%{' |
| 467 | if (*str == '}') { // end of arg |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 468 | cformat = LF_EDARG; |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 469 | arg_len = str - arg; |
| 470 | *str = 0; // used for reporting errors |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 471 | } |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 472 | break; |
| 473 | |
| 474 | case LF_EDARG: // text immediately following '%{arg}' |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 475 | if (*str == '[') { |
| 476 | cformat = LF_STEXPR; |
| 477 | var = str + 1; // store expr in variable name |
| 478 | break; |
| 479 | } |
| 480 | else if (isalnum((int)*str)) { // variable name |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 481 | cformat = LF_VAR; |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 482 | var = str; |
| 483 | break; |
| 484 | } |
Willy Tarreau | b1f3af2 | 2013-04-12 18:30:32 +0200 | [diff] [blame] | 485 | Warning("parsing [%s:%d] : Skipping isolated argument in '%s' line : '%%{%s}'\n", |
| 486 | curproxy->conf.args.file, curproxy->conf.args.line, fmt_directive(curproxy), arg); |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 487 | cformat = LF_INIT; |
| 488 | break; |
| 489 | |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 490 | case LF_STEXPR: // text immediately following '%[' |
| 491 | if (*str == ']') { // end of arg |
| 492 | cformat = LF_EDEXPR; |
| 493 | var_len = str - var; |
| 494 | *str = 0; // needed for parsing the expression |
| 495 | } |
| 496 | break; |
| 497 | |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 498 | case LF_VAR: // text part of a variable name |
| 499 | var_len = str - var; |
| 500 | if (!isalnum((int)*str)) |
| 501 | cformat = LF_INIT; // not variable name anymore |
| 502 | break; |
| 503 | |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 504 | default: // LF_INIT, LF_TEXT, LF_SEPARATOR, LF_END, LF_EDEXPR |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 505 | cformat = LF_INIT; |
| 506 | } |
| 507 | |
| 508 | if (cformat == LF_INIT) { /* resynchronize state to text/sep/startvar */ |
| 509 | switch (*str) { |
| 510 | case '%': cformat = LF_STARTVAR; break; |
| 511 | case ' ': cformat = LF_SEPARATOR; break; |
| 512 | case 0 : cformat = LF_END; break; |
| 513 | default : cformat = LF_TEXT; break; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 514 | } |
| 515 | } |
| 516 | |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 517 | if (cformat != pformat || pformat == LF_SEPARATOR) { |
| 518 | switch (pformat) { |
| 519 | case LF_VAR: |
| 520 | parse_logformat_var(arg, arg_len, var, var_len, curproxy, list_format, &options); |
| 521 | break; |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 522 | case LF_STEXPR: |
Willy Tarreau | 434c57c | 2013-01-08 01:10:24 +0100 | [diff] [blame] | 523 | add_sample_to_logformat_list(var, arg, arg_len, curproxy, list_format, options, cap); |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 524 | break; |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 525 | case LF_TEXT: |
| 526 | case LF_SEPARATOR: |
| 527 | add_to_logformat_list(sp, str, pformat, list_format); |
| 528 | break; |
| 529 | } |
| 530 | sp = str; /* new start of text at every state switch and at every separator */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 531 | } |
| 532 | } |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 533 | |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 534 | if (pformat == LF_STARTVAR || pformat == LF_STARG || pformat == LF_STEXPR) |
Willy Tarreau | b1f3af2 | 2013-04-12 18:30:32 +0200 | [diff] [blame] | 535 | Warning("parsing [%s:%d] : Ignoring end of truncated '%s' line after '%s'\n", |
| 536 | curproxy->conf.args.file, curproxy->conf.args.line, fmt_directive(curproxy), |
| 537 | var ? var : arg ? arg : "%"); |
Willy Tarreau | 3ed22a4 | 2012-12-23 17:29:07 +0100 | [diff] [blame] | 538 | |
Willy Tarreau | b83bc1e | 2012-12-24 12:36:33 +0100 | [diff] [blame] | 539 | free(backfmt); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 540 | } |
| 541 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 542 | /* |
| 543 | * Displays the message on stderr with the date and pid. Overrides the quiet |
| 544 | * mode during startup. |
| 545 | */ |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 546 | void Alert(const char *fmt, ...) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 547 | { |
| 548 | va_list argp; |
Willy Tarreau | fe94460 | 2007-10-25 10:34:16 +0200 | [diff] [blame] | 549 | struct tm tm; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 550 | |
| 551 | if (!(global.mode & MODE_QUIET) || (global.mode & (MODE_VERBOSE | MODE_STARTING))) { |
| 552 | va_start(argp, fmt); |
| 553 | |
Willy Tarreau | b7f694f | 2008-06-22 17:18:02 +0200 | [diff] [blame] | 554 | get_localtime(date.tv_sec, &tm); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 555 | fprintf(stderr, "[ALERT] %03d/%02d%02d%02d (%d) : ", |
Willy Tarreau | fe94460 | 2007-10-25 10:34:16 +0200 | [diff] [blame] | 556 | tm.tm_yday, tm.tm_hour, tm.tm_min, tm.tm_sec, (int)getpid()); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 557 | vfprintf(stderr, fmt, argp); |
| 558 | fflush(stderr); |
| 559 | va_end(argp); |
| 560 | } |
| 561 | } |
| 562 | |
| 563 | |
| 564 | /* |
| 565 | * Displays the message on stderr with the date and pid. |
| 566 | */ |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 567 | void Warning(const char *fmt, ...) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 568 | { |
| 569 | va_list argp; |
Willy Tarreau | fe94460 | 2007-10-25 10:34:16 +0200 | [diff] [blame] | 570 | struct tm tm; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 571 | |
| 572 | if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE)) { |
| 573 | va_start(argp, fmt); |
| 574 | |
Willy Tarreau | b7f694f | 2008-06-22 17:18:02 +0200 | [diff] [blame] | 575 | get_localtime(date.tv_sec, &tm); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 576 | fprintf(stderr, "[WARNING] %03d/%02d%02d%02d (%d) : ", |
Willy Tarreau | fe94460 | 2007-10-25 10:34:16 +0200 | [diff] [blame] | 577 | tm.tm_yday, tm.tm_hour, tm.tm_min, tm.tm_sec, (int)getpid()); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 578 | vfprintf(stderr, fmt, argp); |
| 579 | fflush(stderr); |
| 580 | va_end(argp); |
| 581 | } |
| 582 | } |
| 583 | |
| 584 | /* |
| 585 | * Displays the message on <out> only if quiet mode is not set. |
| 586 | */ |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 587 | void qfprintf(FILE *out, const char *fmt, ...) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 588 | { |
| 589 | va_list argp; |
| 590 | |
| 591 | if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE)) { |
| 592 | va_start(argp, fmt); |
| 593 | vfprintf(out, fmt, argp); |
| 594 | fflush(out); |
| 595 | va_end(argp); |
| 596 | } |
| 597 | } |
| 598 | |
| 599 | /* |
| 600 | * returns log level for <lev> or -1 if not found. |
| 601 | */ |
| 602 | int get_log_level(const char *lev) |
| 603 | { |
| 604 | int level; |
| 605 | |
| 606 | level = NB_LOG_LEVELS - 1; |
| 607 | while (level >= 0 && strcmp(log_levels[level], lev)) |
| 608 | level--; |
| 609 | |
| 610 | return level; |
| 611 | } |
| 612 | |
| 613 | |
| 614 | /* |
| 615 | * returns log facility for <fac> or -1 if not found. |
| 616 | */ |
| 617 | int get_log_facility(const char *fac) |
| 618 | { |
| 619 | int facility; |
| 620 | |
| 621 | facility = NB_LOG_FACILITIES - 1; |
| 622 | while (facility >= 0 && strcmp(log_facilities[facility], fac)) |
| 623 | facility--; |
William Lallemand | 2a4a44f | 2012-02-06 16:00:33 +0100 | [diff] [blame] | 624 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 625 | return facility; |
| 626 | } |
| 627 | |
William Lallemand | a1cc381 | 2012-02-08 16:38:44 +0100 | [diff] [blame] | 628 | /* |
| 629 | * Write a string in the log string |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 630 | * Take cares of quote options |
William Lallemand | a1cc381 | 2012-02-08 16:38:44 +0100 | [diff] [blame] | 631 | * |
| 632 | * Return the adress of the \0 character, or NULL on error |
| 633 | */ |
Willy Tarreau | 2b0108a | 2012-12-21 19:23:44 +0100 | [diff] [blame] | 634 | char *lf_text_len(char *dst, const char *src, size_t len, size_t size, struct logformat_node *node) |
William Lallemand | a1cc381 | 2012-02-08 16:38:44 +0100 | [diff] [blame] | 635 | { |
Willy Tarreau | 2b0108a | 2012-12-21 19:23:44 +0100 | [diff] [blame] | 636 | if (size < 2) |
| 637 | return NULL; |
William Lallemand | a1cc381 | 2012-02-08 16:38:44 +0100 | [diff] [blame] | 638 | |
Willy Tarreau | 2b0108a | 2012-12-21 19:23:44 +0100 | [diff] [blame] | 639 | if (node->options & LOG_OPT_QUOTE) { |
| 640 | *(dst++) = '"'; |
| 641 | size--; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 642 | } |
Willy Tarreau | 2b0108a | 2012-12-21 19:23:44 +0100 | [diff] [blame] | 643 | |
Willy Tarreau | 6cbbdbf | 2013-02-05 18:52:25 +0100 | [diff] [blame] | 644 | if (src && len) { |
Willy Tarreau | 2b0108a | 2012-12-21 19:23:44 +0100 | [diff] [blame] | 645 | if (++len > size) |
| 646 | len = size; |
| 647 | len = strlcpy2(dst, src, len); |
| 648 | |
| 649 | size -= len; |
| 650 | dst += len; |
| 651 | } |
Willy Tarreau | 6cbbdbf | 2013-02-05 18:52:25 +0100 | [diff] [blame] | 652 | else if ((node->options & (LOG_OPT_QUOTE|LOG_OPT_MANDATORY)) == LOG_OPT_MANDATORY) { |
| 653 | if (size < 2) |
| 654 | return NULL; |
| 655 | *(dst++) = '-'; |
| 656 | } |
Willy Tarreau | 2b0108a | 2012-12-21 19:23:44 +0100 | [diff] [blame] | 657 | |
| 658 | if (node->options & LOG_OPT_QUOTE) { |
| 659 | if (size < 2) |
| 660 | return NULL; |
| 661 | *(dst++) = '"'; |
| 662 | } |
| 663 | |
| 664 | *dst = '\0'; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 665 | return dst; |
William Lallemand | a1cc381 | 2012-02-08 16:38:44 +0100 | [diff] [blame] | 666 | } |
| 667 | |
Willy Tarreau | 2b0108a | 2012-12-21 19:23:44 +0100 | [diff] [blame] | 668 | static inline char *lf_text(char *dst, const char *src, size_t size, struct logformat_node *node) |
| 669 | { |
| 670 | return lf_text_len(dst, src, size, size, node); |
| 671 | } |
| 672 | |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 673 | /* |
| 674 | * Write a IP adress to the log string |
| 675 | * +X option write in hexadecimal notation, most signifant byte on the left |
| 676 | */ |
| 677 | char *lf_ip(char *dst, struct sockaddr *sockaddr, size_t size, struct logformat_node *node) |
| 678 | { |
| 679 | char *ret = dst; |
| 680 | int iret; |
| 681 | char pn[INET6_ADDRSTRLEN]; |
| 682 | |
| 683 | if (node->options & LOG_OPT_HEXA) { |
| 684 | const unsigned char *addr = (const unsigned char *)&((struct sockaddr_in *)sockaddr)->sin_addr.s_addr; |
| 685 | iret = snprintf(dst, size, "%02X%02X%02X%02X", addr[0], addr[1], addr[2], addr[3]); |
| 686 | if (iret < 0 || iret > size) |
| 687 | return NULL; |
| 688 | ret += iret; |
| 689 | } else { |
| 690 | addr_to_str((struct sockaddr_storage *)sockaddr, pn, sizeof(pn)); |
| 691 | ret = lf_text(dst, pn, size, node); |
| 692 | if (ret == NULL) |
| 693 | return NULL; |
| 694 | } |
| 695 | return ret; |
| 696 | } |
| 697 | |
| 698 | /* |
| 699 | * Write a port to the log |
| 700 | * +X option write in hexadecimal notation, most signifant byte on the left |
| 701 | */ |
| 702 | char *lf_port(char *dst, struct sockaddr *sockaddr, size_t size, struct logformat_node *node) |
| 703 | { |
| 704 | char *ret = dst; |
| 705 | int iret; |
| 706 | |
| 707 | if (node->options & LOG_OPT_HEXA) { |
| 708 | const unsigned char *port = (const unsigned char *)&((struct sockaddr_in *)sockaddr)->sin_port; |
| 709 | iret = snprintf(dst, size, "%02X%02X", port[0], port[1]); |
| 710 | if (iret < 0 || iret > size) |
| 711 | return NULL; |
| 712 | ret += iret; |
| 713 | } else { |
| 714 | ret = ltoa_o(get_host_port((struct sockaddr_storage *)sockaddr), dst, size); |
| 715 | if (ret == NULL) |
| 716 | return NULL; |
| 717 | } |
| 718 | return ret; |
| 719 | } |
| 720 | |
Willy Tarreau | b1a2faf | 2012-03-19 16:51:53 +0100 | [diff] [blame] | 721 | /* Re-generate the syslog header at the beginning of logline once a second and |
| 722 | * return the pointer to the first character after the header. |
| 723 | */ |
| 724 | static char *update_log_hdr() |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 725 | { |
Willy Tarreau | b1a2faf | 2012-03-19 16:51:53 +0100 | [diff] [blame] | 726 | static long tvsec; |
| 727 | static char *dataptr = NULL; /* backup of last end of header, NULL first time */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 728 | |
Willy Tarreau | b7f694f | 2008-06-22 17:18:02 +0200 | [diff] [blame] | 729 | if (unlikely(date.tv_sec != tvsec || dataptr == NULL)) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 730 | /* this string is rebuild only once a second */ |
Willy Tarreau | fe94460 | 2007-10-25 10:34:16 +0200 | [diff] [blame] | 731 | struct tm tm; |
Willy Tarreau | b1a2faf | 2012-03-19 16:51:53 +0100 | [diff] [blame] | 732 | int hdr_len; |
Willy Tarreau | fe94460 | 2007-10-25 10:34:16 +0200 | [diff] [blame] | 733 | |
Willy Tarreau | b7f694f | 2008-06-22 17:18:02 +0200 | [diff] [blame] | 734 | tvsec = date.tv_sec; |
Willy Tarreau | fe94460 | 2007-10-25 10:34:16 +0200 | [diff] [blame] | 735 | get_localtime(tvsec, &tm); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 736 | |
Willy Tarreau | b1a2faf | 2012-03-19 16:51:53 +0100 | [diff] [blame] | 737 | hdr_len = snprintf(logline, MAX_SYSLOG_LEN, |
Joe Williams | df5b38f | 2010-12-29 17:05:48 +0100 | [diff] [blame] | 738 | "<<<<>%s %2d %02d:%02d:%02d %s%s[%d]: ", |
Willy Tarreau | fe94460 | 2007-10-25 10:34:16 +0200 | [diff] [blame] | 739 | monthname[tm.tm_mon], |
| 740 | tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, |
Joe Williams | df5b38f | 2010-12-29 17:05:48 +0100 | [diff] [blame] | 741 | global.log_send_hostname ? global.log_send_hostname : "", |
Kevinm | 48936af | 2010-12-22 16:08:21 +0000 | [diff] [blame] | 742 | global.log_tag, pid); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 743 | /* WARNING: depending upon implementations, snprintf may return |
| 744 | * either -1 or the number of bytes that would be needed to store |
| 745 | * the total message. In both cases, we must adjust it. |
| 746 | */ |
William Lallemand | 2a4a44f | 2012-02-06 16:00:33 +0100 | [diff] [blame] | 747 | if (hdr_len < 0 || hdr_len > MAX_SYSLOG_LEN) |
| 748 | hdr_len = MAX_SYSLOG_LEN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 749 | |
Willy Tarreau | b1a2faf | 2012-03-19 16:51:53 +0100 | [diff] [blame] | 750 | dataptr = logline + hdr_len; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 751 | } |
| 752 | |
William Lallemand | 2a4a44f | 2012-02-06 16:00:33 +0100 | [diff] [blame] | 753 | return dataptr; |
| 754 | } |
| 755 | |
| 756 | /* |
| 757 | * This function adds a header to the message and sends the syslog message |
Willy Tarreau | 53bf6af | 2012-02-24 11:46:54 +0100 | [diff] [blame] | 758 | * using a printf format string. It expects an LF-terminated message. |
William Lallemand | 2a4a44f | 2012-02-06 16:00:33 +0100 | [diff] [blame] | 759 | */ |
| 760 | void send_log(struct proxy *p, int level, const char *format, ...) |
| 761 | { |
| 762 | va_list argp; |
Willy Tarreau | b1a2faf | 2012-03-19 16:51:53 +0100 | [diff] [blame] | 763 | char *dataptr; |
| 764 | int data_len; |
William Lallemand | 2a4a44f | 2012-02-06 16:00:33 +0100 | [diff] [blame] | 765 | |
| 766 | if (level < 0 || format == NULL) |
| 767 | return; |
| 768 | |
Willy Tarreau | b1a2faf | 2012-03-19 16:51:53 +0100 | [diff] [blame] | 769 | dataptr = update_log_hdr(); /* update log header and skip it */ |
| 770 | data_len = dataptr - logline; |
William Lallemand | 2a4a44f | 2012-02-06 16:00:33 +0100 | [diff] [blame] | 771 | |
| 772 | va_start(argp, format); |
Willy Tarreau | b1a2faf | 2012-03-19 16:51:53 +0100 | [diff] [blame] | 773 | data_len += vsnprintf(dataptr, logline + sizeof(logline) - dataptr, format, argp); |
William Lallemand | 2a4a44f | 2012-02-06 16:00:33 +0100 | [diff] [blame] | 774 | if (data_len < 0 || data_len > MAX_SYSLOG_LEN) |
| 775 | data_len = MAX_SYSLOG_LEN; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 776 | va_end(argp); |
William Lallemand | 2a4a44f | 2012-02-06 16:00:33 +0100 | [diff] [blame] | 777 | |
Willy Tarreau | b1a2faf | 2012-03-19 16:51:53 +0100 | [diff] [blame] | 778 | __send_log(p, level, logline, data_len); |
William Lallemand | 2a4a44f | 2012-02-06 16:00:33 +0100 | [diff] [blame] | 779 | } |
| 780 | |
| 781 | /* |
| 782 | * This function sends a syslog message. |
| 783 | * It doesn't care about errors nor does it report them. |
Willy Tarreau | 53bf6af | 2012-02-24 11:46:54 +0100 | [diff] [blame] | 784 | * It overrides the last byte (message[size-1]) with an LF character. |
William Lallemand | 2a4a44f | 2012-02-06 16:00:33 +0100 | [diff] [blame] | 785 | */ |
| 786 | void __send_log(struct proxy *p, int level, char *message, size_t size) |
| 787 | { |
| 788 | static int logfdunix = -1; /* syslog to AF_UNIX socket */ |
| 789 | static int logfdinet = -1; /* syslog to AF_INET socket */ |
| 790 | static char *dataptr = NULL; |
| 791 | int fac_level; |
| 792 | struct list *logsrvs = NULL; |
| 793 | struct logsrv *tmp = NULL; |
| 794 | int nblogger; |
| 795 | char *log_ptr; |
| 796 | |
| 797 | dataptr = message; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 798 | |
| 799 | if (p == NULL) { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 800 | if (!LIST_ISEMPTY(&global.logsrvs)) { |
| 801 | logsrvs = &global.logsrvs; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 802 | } |
| 803 | } else { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 804 | if (!LIST_ISEMPTY(&p->logsrvs)) { |
| 805 | logsrvs = &p->logsrvs; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 806 | } |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 807 | } |
| 808 | |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 809 | if (!logsrvs) |
| 810 | return; |
| 811 | |
William Lallemand | 2a4a44f | 2012-02-06 16:00:33 +0100 | [diff] [blame] | 812 | message[size - 1] = '\n'; |
| 813 | |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 814 | /* Lazily set up syslog sockets for protocol families of configured |
| 815 | * syslog servers. */ |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 816 | nblogger = 0; |
| 817 | list_for_each_entry(tmp, logsrvs, list) { |
| 818 | const struct logsrv *logsrv = tmp; |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 819 | int proto, *plogfd; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 820 | |
David du Colombier | 11bcb6c | 2011-03-24 12:23:00 +0100 | [diff] [blame] | 821 | if (logsrv->addr.ss_family == AF_UNIX) { |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 822 | proto = 0; |
| 823 | plogfd = &logfdunix; |
| 824 | } else { |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 825 | proto = IPPROTO_UDP; |
| 826 | plogfd = &logfdinet; |
| 827 | } |
| 828 | if (*plogfd >= 0) { |
| 829 | /* socket already created. */ |
| 830 | continue; |
| 831 | } |
David du Colombier | 11bcb6c | 2011-03-24 12:23:00 +0100 | [diff] [blame] | 832 | if ((*plogfd = socket(logsrv->addr.ss_family, SOCK_DGRAM, |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 833 | proto)) < 0) { |
| 834 | Alert("socket for logger #%d failed: %s (errno=%d)\n", |
| 835 | nblogger + 1, strerror(errno), errno); |
| 836 | return; |
| 837 | } |
| 838 | /* we don't want to receive anything on this socket */ |
| 839 | setsockopt(*plogfd, SOL_SOCKET, SO_RCVBUF, &zero, sizeof(zero)); |
| 840 | /* does nothing under Linux, maybe needed for others */ |
| 841 | shutdown(*plogfd, SHUT_RD); |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 842 | nblogger++; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 843 | } |
| 844 | |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 845 | /* Send log messages to syslog server. */ |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 846 | nblogger = 0; |
| 847 | list_for_each_entry(tmp, logsrvs, list) { |
| 848 | const struct logsrv *logsrv = tmp; |
David du Colombier | 11bcb6c | 2011-03-24 12:23:00 +0100 | [diff] [blame] | 849 | int *plogfd = logsrv->addr.ss_family == AF_UNIX ? |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 850 | &logfdunix : &logfdinet; |
| 851 | int sent; |
| 852 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 853 | /* we can filter the level of the messages that are sent to each logger */ |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 854 | if (level > logsrv->level) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 855 | continue; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 856 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 857 | /* For each target, we may have a different facility. |
| 858 | * We can also have a different log level for each message. |
| 859 | * This induces variations in the message header length. |
| 860 | * Since we don't want to recompute it each time, nor copy it every |
| 861 | * time, we only change the facility in the pre-computed header, |
| 862 | * and we change the pointer to the header accordingly. |
| 863 | */ |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 864 | fac_level = (logsrv->facility << 3) + MAX(level, logsrv->minlvl); |
William Lallemand | 2a4a44f | 2012-02-06 16:00:33 +0100 | [diff] [blame] | 865 | log_ptr = dataptr + 3; /* last digit of the log level */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 866 | do { |
| 867 | *log_ptr = '0' + fac_level % 10; |
| 868 | fac_level /= 10; |
| 869 | log_ptr--; |
William Lallemand | 2a4a44f | 2012-02-06 16:00:33 +0100 | [diff] [blame] | 870 | } while (fac_level && log_ptr > dataptr); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 871 | *log_ptr = '<'; |
William Lallemand | 2a4a44f | 2012-02-06 16:00:33 +0100 | [diff] [blame] | 872 | |
William Lallemand | afeb987 | 2013-08-30 14:17:46 +0200 | [diff] [blame] | 873 | sent = sendto(*plogfd, log_ptr, size - (log_ptr - dataptr), |
Willy Tarreau | 1b4b7ce | 2011-04-05 16:56:50 +0200 | [diff] [blame] | 874 | MSG_DONTWAIT | MSG_NOSIGNAL, |
| 875 | (struct sockaddr *)&logsrv->addr, get_addr_len(&logsrv->addr)); |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 876 | if (sent < 0) { |
| 877 | Alert("sendto logger #%d failed: %s (errno=%d)\n", |
| 878 | nblogger, strerror(errno), errno); |
| 879 | } |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 880 | nblogger++; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 881 | } |
| 882 | } |
| 883 | |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 884 | extern fd_set hdr_encode_map[]; |
| 885 | extern fd_set url_encode_map[]; |
| 886 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 887 | |
Willy Tarreau | c89ccb6 | 2012-04-05 21:18:22 +0200 | [diff] [blame] | 888 | const char sess_cookie[8] = "NIDVEOU7"; /* No cookie, Invalid cookie, cookie for a Down server, Valid cookie, Expired cookie, Old cookie, Unused, unknown */ |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 889 | const char sess_set_cookie[8] = "NPDIRU67"; /* No set-cookie, Set-cookie found and left unchanged (passive), |
| 890 | Set-cookie Deleted, Set-Cookie Inserted, Set-cookie Rewritten, |
| 891 | Set-cookie Updated, unknown, unknown */ |
| 892 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 893 | /* |
| 894 | * try to write a character if there is enough space, or goto out |
| 895 | */ |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 896 | #define LOGCHAR(x) do { \ |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 897 | if (tmplog < dst + maxsize - 1) { \ |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 898 | *(tmplog++) = (x); \ |
| 899 | } else { \ |
| 900 | goto out; \ |
| 901 | } \ |
| 902 | } while(0) |
| 903 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 904 | |
Willy Tarreau | df97447 | 2012-12-28 02:44:01 +0100 | [diff] [blame] | 905 | /* Builds a log line in <dst> based on <list_format>, and stops before reaching |
| 906 | * <maxsize> characters. Returns the size of the output string in characters, |
| 907 | * not counting the trailing zero which is always added if the resulting size |
| 908 | * is not zero. |
| 909 | */ |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 910 | int build_logline(struct session *s, char *dst, size_t maxsize, struct list *list_format) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 911 | { |
Willy Tarreau | 73de989 | 2006-11-30 11:40:23 +0100 | [diff] [blame] | 912 | struct proxy *fe = s->fe; |
Willy Tarreau | ddb358d | 2006-12-17 22:55:52 +0100 | [diff] [blame] | 913 | struct proxy *be = s->be; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 914 | struct http_txn *txn = &s->txn; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 915 | char *uri; |
Willy Tarreau | fe94460 | 2007-10-25 10:34:16 +0200 | [diff] [blame] | 916 | struct tm tm; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 917 | int t_request; |
| 918 | int hdr; |
| 919 | int last_isspace = 1; |
Willy Tarreau | b1a2faf | 2012-03-19 16:51:53 +0100 | [diff] [blame] | 920 | char *tmplog; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 921 | char *ret; |
| 922 | int iret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 923 | struct logformat_node *tmp; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 924 | |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 925 | /* FIXME: let's limit ourselves to frontend logging for now. */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 926 | |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 927 | t_request = -1; |
| 928 | if (tv_isge(&s->logs.tv_request, &s->logs.tv_accept)) |
| 929 | t_request = tv_ms_elapsed(&s->logs.tv_accept, &s->logs.tv_request); |
| 930 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 931 | tmplog = dst; |
Willy Tarreau | c9bd0cc | 2009-05-10 11:57:02 +0200 | [diff] [blame] | 932 | |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 933 | /* fill logbuffer */ |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 934 | if (LIST_ISEMPTY(list_format)) |
| 935 | return 0; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 936 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 937 | list_for_each_entry(tmp, list_format, list) { |
Willy Tarreau | 4f65356 | 2012-10-12 19:48:16 +0200 | [diff] [blame] | 938 | const char *src = NULL; |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 939 | struct sample *key; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 940 | |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 941 | switch (tmp->type) { |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 942 | case LOG_FMT_SEPARATOR: |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 943 | if (!last_isspace) { |
| 944 | LOGCHAR(' '); |
| 945 | last_isspace = 1; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 946 | } |
| 947 | break; |
| 948 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 949 | case LOG_FMT_TEXT: // text |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 950 | src = tmp->arg; |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 951 | iret = strlcpy2(tmplog, src, dst + maxsize - tmplog); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 952 | if (iret == 0) |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 953 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 954 | tmplog += iret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 955 | last_isspace = 0; |
| 956 | break; |
| 957 | |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 958 | case LOG_FMT_EXPR: // sample expression, may be request or response |
| 959 | key = NULL; |
| 960 | if (tmp->options & LOG_OPT_REQ_CAP) |
| 961 | key = sample_fetch_string(be, s, txn, SMP_OPT_DIR_REQ|SMP_OPT_FINAL, tmp->expr); |
| 962 | if (!key && (tmp->options & LOG_OPT_RES_CAP)) |
| 963 | key = sample_fetch_string(be, s, txn, SMP_OPT_DIR_RES|SMP_OPT_FINAL, tmp->expr); |
Willy Tarreau | 6cbbdbf | 2013-02-05 18:52:25 +0100 | [diff] [blame] | 964 | ret = lf_text_len(tmplog, key ? key->data.str.str : NULL, key ? key->data.str.len : 0, dst + maxsize - tmplog, tmp); |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 965 | if (ret == 0) |
| 966 | goto out; |
| 967 | tmplog = ret; |
| 968 | last_isspace = 0; |
| 969 | break; |
| 970 | |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 971 | case LOG_FMT_CLIENTIP: // %ci |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 972 | ret = lf_ip(tmplog, (struct sockaddr *)&s->req->prod->conn->addr.from, |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 973 | dst + maxsize - tmplog, tmp); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 974 | if (ret == NULL) |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 975 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 976 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 977 | last_isspace = 0; |
| 978 | break; |
| 979 | |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 980 | case LOG_FMT_CLIENTPORT: // %cp |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 981 | if (s->req->prod->conn->addr.from.ss_family == AF_UNIX) { |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 982 | ret = ltoa_o(s->listener->luid, tmplog, dst + maxsize - tmplog); |
| 983 | } else { |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 984 | ret = lf_port(tmplog, (struct sockaddr *)&s->req->prod->conn->addr.from, |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 985 | dst + maxsize - tmplog, tmp); |
| 986 | } |
| 987 | if (ret == NULL) |
| 988 | goto out; |
| 989 | tmplog = ret; |
| 990 | last_isspace = 0; |
| 991 | break; |
| 992 | |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 993 | case LOG_FMT_FRONTENDIP: // %fi |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 994 | conn_get_to_addr(s->req->prod->conn); |
| 995 | ret = lf_ip(tmplog, (struct sockaddr *)&s->req->prod->conn->addr.to, |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 996 | dst + maxsize - tmplog, tmp); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 997 | if (ret == NULL) |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 998 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 999 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1000 | last_isspace = 0; |
| 1001 | break; |
| 1002 | |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 1003 | case LOG_FMT_FRONTENDPORT: // %fp |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 1004 | conn_get_to_addr(s->req->prod->conn); |
| 1005 | if (s->req->prod->conn->addr.to.ss_family == AF_UNIX) { |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1006 | ret = ltoa_o(s->listener->luid, |
| 1007 | tmplog, dst + maxsize - tmplog); |
| 1008 | } else { |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 1009 | ret = lf_port(tmplog, (struct sockaddr *)&s->req->prod->conn->addr.to, |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1010 | dst + maxsize - tmplog, tmp); |
| 1011 | } |
| 1012 | if (ret == NULL) |
| 1013 | goto out; |
| 1014 | tmplog = ret; |
| 1015 | last_isspace = 0; |
| 1016 | break; |
| 1017 | |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 1018 | case LOG_FMT_BACKENDIP: // %bi |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 1019 | ret = lf_ip(tmplog, (struct sockaddr *)&s->req->cons->conn->addr.from, |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1020 | dst + maxsize - tmplog, tmp); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1021 | if (ret == NULL) |
William Lallemand | b7ff6a3 | 2012-03-02 14:35:21 +0100 | [diff] [blame] | 1022 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1023 | tmplog = ret; |
William Lallemand | b7ff6a3 | 2012-03-02 14:35:21 +0100 | [diff] [blame] | 1024 | last_isspace = 0; |
| 1025 | break; |
| 1026 | |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 1027 | case LOG_FMT_BACKENDPORT: // %bp |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 1028 | ret = lf_port(tmplog, (struct sockaddr *)&s->req->cons->conn->addr.from, |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1029 | dst + maxsize - tmplog, tmp); |
| 1030 | if (ret == NULL) |
| 1031 | goto out; |
| 1032 | tmplog = ret; |
| 1033 | last_isspace = 0; |
| 1034 | break; |
| 1035 | |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 1036 | case LOG_FMT_SERVERIP: // %si |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 1037 | ret = lf_ip(tmplog, (struct sockaddr *)&s->req->cons->conn->addr.to, |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1038 | dst + maxsize - tmplog, tmp); |
| 1039 | if (ret == NULL) |
| 1040 | goto out; |
| 1041 | tmplog = ret; |
| 1042 | last_isspace = 0; |
| 1043 | break; |
| 1044 | |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 1045 | case LOG_FMT_SERVERPORT: // %sp |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 1046 | ret = lf_port(tmplog, (struct sockaddr *)&s->req->cons->conn->addr.to, |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1047 | dst + maxsize - tmplog, tmp); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1048 | if (ret == NULL) |
William Lallemand | b7ff6a3 | 2012-03-02 14:35:21 +0100 | [diff] [blame] | 1049 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1050 | tmplog = ret; |
William Lallemand | b7ff6a3 | 2012-03-02 14:35:21 +0100 | [diff] [blame] | 1051 | last_isspace = 0; |
| 1052 | break; |
| 1053 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1054 | case LOG_FMT_DATE: // %t |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1055 | get_localtime(s->logs.accept_date.tv_sec, &tm); |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1056 | ret = date2str_log(tmplog, &tm, &(s->logs.accept_date), |
| 1057 | dst + maxsize - tmplog); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1058 | if (ret == NULL) |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1059 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1060 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1061 | last_isspace = 0; |
| 1062 | break; |
| 1063 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1064 | case LOG_FMT_DATEGMT: // %T |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1065 | get_gmtime(s->logs.accept_date.tv_sec, &tm); |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1066 | ret = gmt2str_log(tmplog, &tm, dst + maxsize - tmplog); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1067 | if (ret == NULL) |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1068 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1069 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1070 | last_isspace = 0; |
| 1071 | break; |
| 1072 | |
Yuxans Yao | 4e25b01 | 2012-10-19 10:36:09 +0800 | [diff] [blame] | 1073 | case LOG_FMT_DATELOCAL: // %Tl |
| 1074 | get_localtime(s->logs.accept_date.tv_sec, &tm); |
| 1075 | ret = localdate2str_log(tmplog, &tm, dst + maxsize - tmplog); |
| 1076 | if (ret == NULL) |
| 1077 | goto out; |
| 1078 | tmplog = ret; |
| 1079 | last_isspace = 0; |
| 1080 | break; |
| 1081 | |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1082 | case LOG_FMT_TS: // %Ts |
| 1083 | get_gmtime(s->logs.accept_date.tv_sec, &tm); |
| 1084 | if (tmp->options & LOG_OPT_HEXA) { |
| 1085 | iret = snprintf(tmplog, dst + maxsize - tmplog, "%04X", (unsigned int)s->logs.accept_date.tv_sec); |
| 1086 | if (iret < 0 || iret > dst + maxsize - tmplog) |
| 1087 | goto out; |
| 1088 | last_isspace = 0; |
| 1089 | tmplog += iret; |
| 1090 | } else { |
| 1091 | ret = ltoa_o(s->logs.accept_date.tv_sec, tmplog, dst + maxsize - tmplog); |
| 1092 | if (ret == NULL) |
| 1093 | goto out; |
| 1094 | tmplog = ret; |
| 1095 | last_isspace = 0; |
| 1096 | } |
| 1097 | break; |
| 1098 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1099 | case LOG_FMT_MS: // %ms |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1100 | if (tmp->options & LOG_OPT_HEXA) { |
| 1101 | iret = snprintf(tmplog, dst + maxsize - tmplog, "%02X",(unsigned int)s->logs.accept_date.tv_usec/1000); |
| 1102 | if (iret < 0 || iret > dst + maxsize - tmplog) |
| 1103 | goto out; |
| 1104 | last_isspace = 0; |
| 1105 | tmplog += iret; |
| 1106 | } else { |
| 1107 | if ((dst + maxsize - tmplog) < 4) |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1108 | goto out; |
Willy Tarreau | 9e60cd8 | 2013-01-24 01:18:16 +0100 | [diff] [blame] | 1109 | ret = utoa_pad((unsigned int)s->logs.accept_date.tv_usec/1000, |
| 1110 | tmplog, 4); |
| 1111 | if (ret == NULL) |
William Lallemand | 51b5dca | 2012-03-26 17:52:55 +0200 | [diff] [blame] | 1112 | goto out; |
Willy Tarreau | 9e60cd8 | 2013-01-24 01:18:16 +0100 | [diff] [blame] | 1113 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1114 | last_isspace = 0; |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1115 | } |
| 1116 | break; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1117 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1118 | case LOG_FMT_FRONTEND: // %f |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1119 | src = fe->id; |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1120 | ret = lf_text(tmplog, src, dst + maxsize - tmplog, tmp); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1121 | if (ret == NULL) |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1122 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1123 | tmplog = ret; |
William Lallemand | 51b5dca | 2012-03-26 17:52:55 +0200 | [diff] [blame] | 1124 | last_isspace = 0; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1125 | break; |
| 1126 | |
Willy Tarreau | 773d65f | 2012-10-12 14:56:11 +0200 | [diff] [blame] | 1127 | case LOG_FMT_FRONTEND_XPRT: // %ft |
| 1128 | src = fe->id; |
| 1129 | if (tmp->options & LOG_OPT_QUOTE) |
| 1130 | LOGCHAR('"'); |
| 1131 | iret = strlcpy2(tmplog, src, dst + maxsize - tmplog); |
| 1132 | if (iret == 0) |
| 1133 | goto out; |
| 1134 | tmplog += iret; |
| 1135 | #ifdef USE_OPENSSL |
| 1136 | if (s->listener->xprt == &ssl_sock) |
| 1137 | LOGCHAR('~'); |
| 1138 | #endif |
| 1139 | if (tmp->options & LOG_OPT_QUOTE) |
| 1140 | LOGCHAR('"'); |
| 1141 | last_isspace = 0; |
| 1142 | break; |
Willy Tarreau | ffc3fcd | 2012-10-12 20:17:54 +0200 | [diff] [blame] | 1143 | #ifdef USE_OPENSSL |
| 1144 | case LOG_FMT_SSL_CIPHER: // %sslc |
| 1145 | src = NULL; |
| 1146 | if (s->listener->xprt == &ssl_sock) |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 1147 | src = ssl_sock_get_cipher_name(s->si[0].conn); |
Willy Tarreau | ffc3fcd | 2012-10-12 20:17:54 +0200 | [diff] [blame] | 1148 | ret = lf_text(tmplog, src, dst + maxsize - tmplog, tmp); |
| 1149 | if (ret == NULL) |
| 1150 | goto out; |
| 1151 | tmplog = ret; |
| 1152 | last_isspace = 0; |
| 1153 | break; |
Willy Tarreau | 773d65f | 2012-10-12 14:56:11 +0200 | [diff] [blame] | 1154 | |
Willy Tarreau | ffc3fcd | 2012-10-12 20:17:54 +0200 | [diff] [blame] | 1155 | case LOG_FMT_SSL_VERSION: // %sslv |
| 1156 | src = NULL; |
| 1157 | if (s->listener->xprt == &ssl_sock) |
Willy Tarreau | f2943dc | 2012-10-26 20:10:28 +0200 | [diff] [blame] | 1158 | src = ssl_sock_get_proto_version(s->si[0].conn); |
Willy Tarreau | ffc3fcd | 2012-10-12 20:17:54 +0200 | [diff] [blame] | 1159 | ret = lf_text(tmplog, src, dst + maxsize - tmplog, tmp); |
| 1160 | if (ret == NULL) |
| 1161 | goto out; |
| 1162 | tmplog = ret; |
| 1163 | last_isspace = 0; |
| 1164 | break; |
| 1165 | #endif |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1166 | case LOG_FMT_BACKEND: // %b |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1167 | src = be->id; |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1168 | ret = lf_text(tmplog, src, dst + maxsize - tmplog, tmp); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1169 | if (ret == NULL) |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1170 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1171 | tmplog = ret; |
William Lallemand | 51b5dca | 2012-03-26 17:52:55 +0200 | [diff] [blame] | 1172 | last_isspace = 0; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1173 | break; |
| 1174 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1175 | case LOG_FMT_SERVER: // %s |
Willy Tarreau | d79a3b2 | 2012-12-28 09:40:16 +0100 | [diff] [blame] | 1176 | switch (obj_type(s->target)) { |
| 1177 | case OBJ_TYPE_SERVER: |
| 1178 | src = objt_server(s->target)->id; |
| 1179 | break; |
| 1180 | case OBJ_TYPE_APPLET: |
| 1181 | src = objt_applet(s->target)->name; |
| 1182 | break; |
| 1183 | default: |
| 1184 | src = "<NOSRV>"; |
| 1185 | break; |
| 1186 | } |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1187 | ret = lf_text(tmplog, src, dst + maxsize - tmplog, tmp); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1188 | if (ret == NULL) |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1189 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1190 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1191 | last_isspace = 0; |
| 1192 | break; |
| 1193 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1194 | case LOG_FMT_TQ: // %Tq |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1195 | ret = ltoa_o(t_request, tmplog, dst + maxsize - tmplog); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1196 | if (ret == NULL) |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1197 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1198 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1199 | last_isspace = 0; |
| 1200 | break; |
| 1201 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1202 | case LOG_FMT_TW: // %Tw |
| 1203 | ret = ltoa_o((s->logs.t_queue >= 0) ? s->logs.t_queue - t_request : -1, |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1204 | tmplog, dst + maxsize - tmplog); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1205 | if (ret == NULL) |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1206 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1207 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1208 | last_isspace = 0; |
| 1209 | break; |
| 1210 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1211 | case LOG_FMT_TC: // %Tc |
| 1212 | ret = ltoa_o((s->logs.t_connect >= 0) ? s->logs.t_connect - s->logs.t_queue : -1, |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1213 | tmplog, dst + maxsize - tmplog); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1214 | if (ret == NULL) |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1215 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1216 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1217 | last_isspace = 0; |
| 1218 | break; |
| 1219 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1220 | case LOG_FMT_TR: // %Tr |
| 1221 | ret = ltoa_o((s->logs.t_data >= 0) ? s->logs.t_data - s->logs.t_connect : -1, |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1222 | tmplog, dst + maxsize - tmplog); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1223 | if (ret == NULL) |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1224 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1225 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1226 | last_isspace = 0; |
| 1227 | break; |
| 1228 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1229 | case LOG_FMT_TT: // %Tt |
Willy Tarreau | d79a3b2 | 2012-12-28 09:40:16 +0100 | [diff] [blame] | 1230 | if (!(fe->to_log & LW_BYTES)) |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1231 | LOGCHAR('+'); |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1232 | ret = ltoa_o(s->logs.t_close, tmplog, dst + maxsize - tmplog); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1233 | if (ret == NULL) |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1234 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1235 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1236 | last_isspace = 0; |
| 1237 | break; |
| 1238 | |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 1239 | case LOG_FMT_STATUS: // %ST |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1240 | ret = ltoa_o(txn->status, tmplog, dst + maxsize - tmplog); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1241 | if (ret == NULL) |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1242 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1243 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1244 | last_isspace = 0; |
| 1245 | break; |
| 1246 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1247 | case LOG_FMT_BYTES: // %B |
Willy Tarreau | d79a3b2 | 2012-12-28 09:40:16 +0100 | [diff] [blame] | 1248 | if (!(fe->to_log & LW_BYTES)) |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1249 | LOGCHAR('+'); |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1250 | ret = lltoa(s->logs.bytes_out, tmplog, dst + maxsize - tmplog); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1251 | if (ret == NULL) |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1252 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1253 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1254 | last_isspace = 0; |
| 1255 | break; |
| 1256 | |
Willy Tarreau | c5259fd | 2012-12-20 15:38:04 +0100 | [diff] [blame] | 1257 | case LOG_FMT_BYTES_UP: // %U |
Willy Tarreau | c5259fd | 2012-12-20 15:38:04 +0100 | [diff] [blame] | 1258 | ret = lltoa(s->logs.bytes_in, tmplog, dst + maxsize - tmplog); |
| 1259 | if (ret == NULL) |
| 1260 | goto out; |
| 1261 | tmplog = ret; |
| 1262 | last_isspace = 0; |
| 1263 | break; |
| 1264 | |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 1265 | case LOG_FMT_CCLIENT: // %CC |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1266 | src = txn->cli_cookie; |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1267 | ret = lf_text(tmplog, src, dst + maxsize - tmplog, tmp); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1268 | if (ret == NULL) |
William Lallemand | 51b5dca | 2012-03-26 17:52:55 +0200 | [diff] [blame] | 1269 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1270 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1271 | last_isspace = 0; |
| 1272 | break; |
| 1273 | |
Willy Tarreau | 2beef58 | 2012-12-20 17:22:52 +0100 | [diff] [blame] | 1274 | case LOG_FMT_CSERVER: // %CS |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1275 | src = txn->srv_cookie; |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1276 | ret = lf_text(tmplog, src, dst + maxsize - tmplog, tmp); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1277 | if (ret == NULL) |
William Lallemand | 51b5dca | 2012-03-26 17:52:55 +0200 | [diff] [blame] | 1278 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1279 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1280 | last_isspace = 0; |
| 1281 | break; |
| 1282 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1283 | case LOG_FMT_TERMSTATE: // %ts |
Willy Tarreau | 6580c06 | 2012-03-12 15:09:42 +0100 | [diff] [blame] | 1284 | LOGCHAR(sess_term_cond[(s->flags & SN_ERR_MASK) >> SN_ERR_SHIFT]); |
| 1285 | LOGCHAR(sess_fin_state[(s->flags & SN_FINST_MASK) >> SN_FINST_SHIFT]); |
| 1286 | *tmplog = '\0'; |
| 1287 | last_isspace = 0; |
| 1288 | break; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1289 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1290 | case LOG_FMT_TERMSTATE_CK: // %tsc, same as TS with cookie state (for mode HTTP) |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1291 | LOGCHAR(sess_term_cond[(s->flags & SN_ERR_MASK) >> SN_ERR_SHIFT]); |
| 1292 | LOGCHAR(sess_fin_state[(s->flags & SN_FINST_MASK) >> SN_FINST_SHIFT]); |
Willy Tarreau | 6740213 | 2012-05-31 20:40:20 +0200 | [diff] [blame] | 1293 | LOGCHAR((be->ck_opts & PR_CK_ANY) ? sess_cookie[(txn->flags & TX_CK_MASK) >> TX_CK_SHIFT] : '-'); |
| 1294 | LOGCHAR((be->ck_opts & PR_CK_ANY) ? sess_set_cookie[(txn->flags & TX_SCK_MASK) >> TX_SCK_SHIFT] : '-'); |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1295 | last_isspace = 0; |
| 1296 | break; |
| 1297 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1298 | case LOG_FMT_ACTCONN: // %ac |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1299 | ret = ltoa_o(actconn, tmplog, dst + maxsize - tmplog); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1300 | if (ret == NULL) |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1301 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1302 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1303 | last_isspace = 0; |
| 1304 | break; |
| 1305 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1306 | case LOG_FMT_FECONN: // %fc |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1307 | ret = ltoa_o(fe->feconn, tmplog, dst + maxsize - tmplog); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1308 | if (ret == NULL) |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1309 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1310 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1311 | last_isspace = 0; |
| 1312 | break; |
| 1313 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1314 | case LOG_FMT_BECONN: // %bc |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1315 | ret = ltoa_o(be->beconn, tmplog, dst + maxsize - tmplog); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1316 | if (ret == NULL) |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1317 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1318 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1319 | last_isspace = 0; |
| 1320 | break; |
| 1321 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1322 | case LOG_FMT_SRVCONN: // %sc |
Willy Tarreau | 54a08d3 | 2012-11-12 01:14:56 +0100 | [diff] [blame] | 1323 | ret = ultoa_o(objt_server(s->target) ? |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 1324 | objt_server(s->target)->cur_sess : |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1325 | 0, tmplog, dst + maxsize - tmplog); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1326 | if (ret == NULL) |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1327 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1328 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1329 | last_isspace = 0; |
| 1330 | break; |
| 1331 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1332 | case LOG_FMT_RETRIES: // %rq |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1333 | if (s->flags & SN_REDISP) |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1334 | LOGCHAR('+'); |
| 1335 | ret = ltoa_o((s->req->cons->conn_retries>0) ? |
| 1336 | (be->conn_retries - s->req->cons->conn_retries) : |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1337 | be->conn_retries, tmplog, dst + maxsize - tmplog); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1338 | if (ret == NULL) |
William Lallemand | 51b5dca | 2012-03-26 17:52:55 +0200 | [diff] [blame] | 1339 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1340 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1341 | last_isspace = 0; |
| 1342 | break; |
| 1343 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1344 | case LOG_FMT_SRVQUEUE: // %sq |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1345 | ret = ltoa_o(s->logs.srv_queue_size, tmplog, dst + maxsize - tmplog); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1346 | if (ret == NULL) |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1347 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1348 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1349 | last_isspace = 0; |
| 1350 | break; |
| 1351 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1352 | case LOG_FMT_BCKQUEUE: // %bq |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1353 | ret = ltoa_o(s->logs.prx_queue_size, tmplog, dst + maxsize - tmplog); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1354 | if (ret == NULL) |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1355 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1356 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1357 | last_isspace = 0; |
| 1358 | break; |
| 1359 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1360 | case LOG_FMT_HDRREQUEST: // %hr |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1361 | /* request header */ |
Willy Tarreau | d79a3b2 | 2012-12-28 09:40:16 +0100 | [diff] [blame] | 1362 | if (fe->nb_req_cap && txn->req.cap) { |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1363 | if (tmp->options & LOG_OPT_QUOTE) |
| 1364 | LOGCHAR('"'); |
| 1365 | LOGCHAR('{'); |
| 1366 | for (hdr = 0; hdr < fe->nb_req_cap; hdr++) { |
| 1367 | if (hdr) |
| 1368 | LOGCHAR('|'); |
William Lallemand | 51b5dca | 2012-03-26 17:52:55 +0200 | [diff] [blame] | 1369 | if (txn->req.cap[hdr] != NULL) { |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1370 | ret = encode_string(tmplog, dst + maxsize, |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1371 | '#', hdr_encode_map, txn->req.cap[hdr]); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1372 | if (ret == NULL || *ret != '\0') |
William Lallemand | 51b5dca | 2012-03-26 17:52:55 +0200 | [diff] [blame] | 1373 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1374 | tmplog = ret; |
William Lallemand | 51b5dca | 2012-03-26 17:52:55 +0200 | [diff] [blame] | 1375 | } |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1376 | } |
| 1377 | LOGCHAR('}'); |
William Lallemand | 51b5dca | 2012-03-26 17:52:55 +0200 | [diff] [blame] | 1378 | if (tmp->options & LOG_OPT_QUOTE) |
| 1379 | LOGCHAR('"'); |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1380 | last_isspace = 0; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1381 | if (tmp->options & LOG_OPT_QUOTE) |
| 1382 | LOGCHAR('"'); |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1383 | } |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1384 | break; |
| 1385 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1386 | case LOG_FMT_HDRREQUESTLIST: // %hrl |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1387 | /* request header list */ |
Willy Tarreau | d79a3b2 | 2012-12-28 09:40:16 +0100 | [diff] [blame] | 1388 | if (fe->nb_req_cap && txn->req.cap) { |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1389 | for (hdr = 0; hdr < fe->nb_req_cap; hdr++) { |
| 1390 | if (hdr > 0) |
| 1391 | LOGCHAR(' '); |
| 1392 | if (tmp->options & LOG_OPT_QUOTE) |
| 1393 | LOGCHAR('"'); |
| 1394 | if (txn->req.cap[hdr] != NULL) { |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1395 | ret = encode_string(tmplog, dst + maxsize, |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1396 | '#', hdr_encode_map, txn->req.cap[hdr]); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1397 | if (ret == NULL || *ret != '\0') |
William Lallemand | 51b5dca | 2012-03-26 17:52:55 +0200 | [diff] [blame] | 1398 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1399 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1400 | } else if (!(tmp->options & LOG_OPT_QUOTE)) |
| 1401 | LOGCHAR('-'); |
| 1402 | if (tmp->options & LOG_OPT_QUOTE) |
| 1403 | LOGCHAR('"'); |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1404 | last_isspace = 0; |
| 1405 | } |
| 1406 | } |
| 1407 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1408 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1409 | |
| 1410 | case LOG_FMT_HDRRESPONS: // %hs |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1411 | /* response header */ |
Willy Tarreau | d79a3b2 | 2012-12-28 09:40:16 +0100 | [diff] [blame] | 1412 | if (fe->nb_rsp_cap && txn->rsp.cap) { |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1413 | if (tmp->options & LOG_OPT_QUOTE) |
| 1414 | LOGCHAR('"'); |
| 1415 | LOGCHAR('{'); |
| 1416 | for (hdr = 0; hdr < fe->nb_rsp_cap; hdr++) { |
| 1417 | if (hdr) |
| 1418 | LOGCHAR('|'); |
William Lallemand | 51b5dca | 2012-03-26 17:52:55 +0200 | [diff] [blame] | 1419 | if (txn->rsp.cap[hdr] != NULL) { |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1420 | ret = encode_string(tmplog, dst + maxsize, |
| 1421 | '#', hdr_encode_map, txn->rsp.cap[hdr]); |
| 1422 | if (ret == NULL || *ret != '\0') |
William Lallemand | 51b5dca | 2012-03-26 17:52:55 +0200 | [diff] [blame] | 1423 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1424 | tmplog = ret; |
William Lallemand | 51b5dca | 2012-03-26 17:52:55 +0200 | [diff] [blame] | 1425 | } |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1426 | } |
| 1427 | LOGCHAR('}'); |
| 1428 | last_isspace = 0; |
| 1429 | if (tmp->options & LOG_OPT_QUOTE) |
| 1430 | LOGCHAR('"'); |
| 1431 | } |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1432 | break; |
| 1433 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1434 | case LOG_FMT_HDRRESPONSLIST: // %hsl |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1435 | /* response header list */ |
Willy Tarreau | d79a3b2 | 2012-12-28 09:40:16 +0100 | [diff] [blame] | 1436 | if (fe->nb_rsp_cap && txn->rsp.cap) { |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1437 | for (hdr = 0; hdr < fe->nb_rsp_cap; hdr++) { |
| 1438 | if (hdr > 0) |
| 1439 | LOGCHAR(' '); |
| 1440 | if (tmp->options & LOG_OPT_QUOTE) |
| 1441 | LOGCHAR('"'); |
| 1442 | if (txn->rsp.cap[hdr] != NULL) { |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1443 | ret = encode_string(tmplog, dst + maxsize, |
| 1444 | '#', hdr_encode_map, txn->rsp.cap[hdr]); |
| 1445 | if (ret == NULL || *ret != '\0') |
William Lallemand | 51b5dca | 2012-03-26 17:52:55 +0200 | [diff] [blame] | 1446 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1447 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1448 | } else if (!(tmp->options & LOG_OPT_QUOTE)) |
| 1449 | LOGCHAR('-'); |
| 1450 | if (tmp->options & LOG_OPT_QUOTE) |
| 1451 | LOGCHAR('"'); |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1452 | last_isspace = 0; |
| 1453 | } |
| 1454 | } |
| 1455 | break; |
| 1456 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1457 | case LOG_FMT_REQ: // %r |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1458 | /* Request */ |
| 1459 | if (tmp->options & LOG_OPT_QUOTE) |
| 1460 | LOGCHAR('"'); |
| 1461 | uri = txn->uri ? txn->uri : "<BADREQ>"; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1462 | ret = encode_string(tmplog, dst + maxsize, |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1463 | '#', url_encode_map, uri); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1464 | if (ret == NULL || *ret != '\0') |
William Lallemand | 51b5dca | 2012-03-26 17:52:55 +0200 | [diff] [blame] | 1465 | goto out; |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1466 | tmplog = ret; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1467 | if (tmp->options & LOG_OPT_QUOTE) |
| 1468 | LOGCHAR('"'); |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1469 | last_isspace = 0; |
| 1470 | break; |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1471 | |
| 1472 | case LOG_FMT_COUNTER: // %rt |
| 1473 | if (tmp->options & LOG_OPT_HEXA) { |
Willy Tarreau | 9f09521 | 2013-08-13 17:51:07 +0200 | [diff] [blame] | 1474 | iret = snprintf(tmplog, dst + maxsize - tmplog, "%04X", global.req_count++); |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1475 | if (iret < 0 || iret > dst + maxsize - tmplog) |
| 1476 | goto out; |
| 1477 | last_isspace = 0; |
| 1478 | tmplog += iret; |
| 1479 | } else { |
Willy Tarreau | 9f09521 | 2013-08-13 17:51:07 +0200 | [diff] [blame] | 1480 | ret = ltoa_o(global.req_count++, tmplog, dst + maxsize - tmplog); |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 1481 | if (ret == NULL) |
| 1482 | goto out; |
| 1483 | tmplog = ret; |
| 1484 | last_isspace = 0; |
| 1485 | } |
| 1486 | break; |
| 1487 | |
| 1488 | case LOG_FMT_HOSTNAME: // %H |
| 1489 | src = hostname; |
| 1490 | ret = lf_text(tmplog, src, dst + maxsize - tmplog, tmp); |
| 1491 | if (ret == NULL) |
| 1492 | goto out; |
| 1493 | tmplog = ret; |
| 1494 | last_isspace = 0; |
| 1495 | break; |
| 1496 | |
| 1497 | case LOG_FMT_PID: // %pid |
| 1498 | if (tmp->options & LOG_OPT_HEXA) { |
| 1499 | iret = snprintf(tmplog, dst + maxsize - tmplog, "%04X", pid); |
| 1500 | if (iret < 0 || iret > dst + maxsize - tmplog) |
| 1501 | goto out; |
| 1502 | last_isspace = 0; |
| 1503 | tmplog += iret; |
| 1504 | } else { |
| 1505 | ret = ltoa_o(pid, tmplog, dst + maxsize - tmplog); |
| 1506 | if (ret == NULL) |
| 1507 | goto out; |
| 1508 | tmplog = ret; |
| 1509 | last_isspace = 0; |
| 1510 | } |
| 1511 | break; |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 1512 | |
| 1513 | case LOG_FMT_UNIQUEID: // %ID |
William Lallemand | 5b7ea3a | 2013-08-28 15:44:19 +0200 | [diff] [blame] | 1514 | ret = NULL; |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 1515 | src = s->unique_id; |
William Lallemand | 5b7ea3a | 2013-08-28 15:44:19 +0200 | [diff] [blame] | 1516 | if (src) |
| 1517 | ret = lf_text(tmplog, src, maxsize - (tmplog - dst), tmp); |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 1518 | if (ret == NULL) |
| 1519 | goto out; |
| 1520 | tmplog = ret; |
| 1521 | last_isspace = 0; |
| 1522 | break; |
| 1523 | |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1524 | } |
| 1525 | } |
| 1526 | |
| 1527 | out: |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1528 | /* *tmplog is a unused character */ |
| 1529 | *tmplog = '\0'; |
Willy Tarreau | df97447 | 2012-12-28 02:44:01 +0100 | [diff] [blame] | 1530 | return tmplog - dst; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1531 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1532 | } |
| 1533 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1534 | /* |
| 1535 | * send a log for the session when we have enough info about it. |
| 1536 | * Will not log if the frontend has no log defined. |
| 1537 | */ |
| 1538 | void sess_log(struct session *s) |
| 1539 | { |
| 1540 | char *tmplog; |
| 1541 | int size, err, level; |
| 1542 | |
| 1543 | /* if we don't want to log normal traffic, return now */ |
Willy Tarreau | 570f221 | 2013-06-10 16:42:09 +0200 | [diff] [blame] | 1544 | err = (s->flags & SN_REDISP) || |
| 1545 | ((s->flags & SN_ERR_MASK) > SN_ERR_LOCAL) || |
| 1546 | (((s->flags & SN_ERR_MASK) == SN_ERR_NONE) && |
| 1547 | (s->req->cons->conn_retries != s->be->conn_retries)) || |
| 1548 | ((s->fe->mode == PR_MODE_HTTP) && s->txn.status >= 500); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1549 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1550 | if (!err && (s->fe->options2 & PR_O2_NOLOGNORM)) |
| 1551 | return; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1552 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1553 | if (LIST_ISEMPTY(&s->fe->logsrvs)) |
| 1554 | return; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1555 | |
Willy Tarreau | abcd514 | 2013-06-11 17:18:02 +0200 | [diff] [blame] | 1556 | if (s->logs.level) { /* loglevel was overridden */ |
| 1557 | if (s->logs.level == -1) { |
| 1558 | s->logs.logwait = 0; /* logs disabled */ |
| 1559 | return; |
| 1560 | } |
| 1561 | level = s->logs.level - 1; |
| 1562 | } |
| 1563 | else { |
| 1564 | level = LOG_INFO; |
| 1565 | if (err && (s->fe->options2 & PR_O2_LOGERRORS)) |
| 1566 | level = LOG_ERR; |
| 1567 | } |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1568 | |
William Lallemand | 5b7ea3a | 2013-08-28 15:44:19 +0200 | [diff] [blame] | 1569 | /* if unique-id was not generated */ |
| 1570 | if (!s->unique_id && !LIST_ISEMPTY(&s->fe->format_unique_id)) { |
| 1571 | if ((s->unique_id = pool_alloc2(pool2_uniqueid)) != NULL) |
| 1572 | build_logline(s, s->unique_id, UNIQUEID_LEN, &s->fe->format_unique_id); |
| 1573 | } |
| 1574 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1575 | tmplog = update_log_hdr(); |
| 1576 | size = tmplog - logline; |
| 1577 | size += build_logline(s, tmplog, sizeof(logline) - size, &s->fe->logformat); |
| 1578 | if (size > 0) { |
Willy Tarreau | df97447 | 2012-12-28 02:44:01 +0100 | [diff] [blame] | 1579 | __send_log(s->fe, level, logline, size + 1); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 1580 | s->logs.logwait = 0; |
| 1581 | } |
| 1582 | } |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 1583 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1584 | /* |
| 1585 | * Local variables: |
| 1586 | * c-indent-level: 8 |
| 1587 | * c-basic-offset: 8 |
| 1588 | * End: |
| 1589 | */ |