Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1 | /* |
Willy Tarreau | aeed4a8 | 2020-06-04 22:01:04 +0200 | [diff] [blame] | 2 | * include/haproxy/log-t.h |
| 3 | * This file contains definitions of log-related structures and macros. |
| 4 | * |
| 5 | * Copyright (C) 2000-2020 Willy Tarreau - w@1wt.eu |
| 6 | * |
| 7 | * This library is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU Lesser General Public |
| 9 | * License as published by the Free Software Foundation, version 2.1 |
| 10 | * exclusively. |
| 11 | * |
| 12 | * This library is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * Lesser General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Lesser General Public |
| 18 | * License along with this library; if not, write to the Free Software |
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 | */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 21 | |
Willy Tarreau | aeed4a8 | 2020-06-04 22:01:04 +0200 | [diff] [blame] | 22 | #ifndef _HAPROXY_LOG_T_H |
| 23 | #define _HAPROXY_LOG_T_H |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 24 | |
Willy Tarreau | 019767b | 2007-12-05 11:11:55 +0100 | [diff] [blame] | 25 | #include <sys/socket.h> |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 26 | #include <sys/un.h> |
| 27 | #include <netinet/in.h> |
Willy Tarreau | aeed4a8 | 2020-06-04 22:01:04 +0200 | [diff] [blame] | 28 | |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 29 | #include <haproxy/api-t.h> |
Willy Tarreau | d2ad57c | 2020-06-03 19:43:35 +0200 | [diff] [blame] | 30 | #include <haproxy/ring-t.h> |
Willy Tarreau | aeed4a8 | 2020-06-04 22:01:04 +0200 | [diff] [blame] | 31 | #include <haproxy/thread-t.h> |
Willy Tarreau | aeed4a8 | 2020-06-04 22:01:04 +0200 | [diff] [blame] | 32 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 33 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 34 | #define NB_LOG_FACILITIES 24 |
| 35 | #define NB_LOG_LEVELS 8 |
Emeric Brun | 5464885 | 2020-07-06 15:54:06 +0200 | [diff] [blame] | 36 | #define NB_LOG_HDR_MAX_ELEMENTS 15 |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 37 | #define SYSLOG_PORT 514 |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 38 | #define UNIQUEID_LEN 128 |
| 39 | |
Willy Tarreau | aeed4a8 | 2020-06-04 22:01:04 +0200 | [diff] [blame] | 40 | /* flags used in logformat_node->options */ |
| 41 | #define LOG_OPT_HEXA 0x00000001 |
| 42 | #define LOG_OPT_MANDATORY 0x00000002 |
| 43 | #define LOG_OPT_QUOTE 0x00000004 |
| 44 | #define LOG_OPT_REQ_CAP 0x00000008 |
| 45 | #define LOG_OPT_RES_CAP 0x00000010 |
| 46 | #define LOG_OPT_HTTP 0x00000020 |
| 47 | #define LOG_OPT_ESC 0x00000040 |
Dragan Dosen | 1e3b16f | 2020-06-23 18:16:44 +0200 | [diff] [blame] | 48 | #define LOG_OPT_MERGE_SPACES 0x00000080 |
Willy Tarreau | 869efd5 | 2019-11-15 15:16:57 +0100 | [diff] [blame] | 49 | |
Willy Tarreau | aeed4a8 | 2020-06-04 22:01:04 +0200 | [diff] [blame] | 50 | |
| 51 | /* Fields that need to be extracted from the incoming connection or request for |
| 52 | * logging or for sending specific header information. They're set in px->to_log |
| 53 | * and appear as flags in session->logs.logwait, which are removed once the |
| 54 | * required information has been collected. |
| 55 | */ |
| 56 | #define LW_INIT 1 /* anything */ |
| 57 | #define LW_CLIP 2 /* CLient IP */ |
| 58 | #define LW_SVIP 4 /* SerVer IP */ |
| 59 | #define LW_SVID 8 /* server ID */ |
| 60 | #define LW_REQ 16 /* http REQuest */ |
| 61 | #define LW_RESP 32 /* http RESPonse */ |
| 62 | #define LW_BYTES 256 /* bytes read from server */ |
| 63 | #define LW_COOKIE 512 /* captured cookie */ |
| 64 | #define LW_REQHDR 1024 /* request header(s) */ |
| 65 | #define LW_RSPHDR 2048 /* response header(s) */ |
| 66 | #define LW_BCKIP 4096 /* backend IP */ |
| 67 | #define LW_FRTIP 8192 /* frontend IP */ |
| 68 | #define LW_XPRT 16384 /* transport layer information (eg: SSL) */ |
| 69 | |
Emeric Brun | 5464885 | 2020-07-06 15:54:06 +0200 | [diff] [blame] | 70 | #define LOG_LEGACYTIME_LEN 15 |
| 71 | #define LOG_ISOTIME_MINLEN 20 |
| 72 | #define LOG_ISOTIME_MAXLEN 32 |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 73 | |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 74 | /* enum for log format */ |
Emeric Brun | 5464885 | 2020-07-06 15:54:06 +0200 | [diff] [blame] | 75 | enum log_fmt { |
| 76 | LOG_FORMAT_UNSPEC = 0, |
Emeric Brun | 0237c4e | 2020-11-27 16:24:34 +0100 | [diff] [blame] | 77 | LOG_FORMAT_LOCAL, |
Emeric Brun | 5464885 | 2020-07-06 15:54:06 +0200 | [diff] [blame] | 78 | LOG_FORMAT_RFC3164, |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 79 | LOG_FORMAT_RFC5424, |
Emeric Brun | 5464885 | 2020-07-06 15:54:06 +0200 | [diff] [blame] | 80 | LOG_FORMAT_PRIO, |
Willy Tarreau | e8746a0 | 2018-11-12 08:45:00 +0100 | [diff] [blame] | 81 | LOG_FORMAT_SHORT, |
Emeric Brun | 5464885 | 2020-07-06 15:54:06 +0200 | [diff] [blame] | 82 | LOG_FORMAT_TIMED, |
| 83 | LOG_FORMAT_ISO, |
Willy Tarreau | c1b0645 | 2018-11-12 11:57:56 +0100 | [diff] [blame] | 84 | LOG_FORMAT_RAW, |
Emeric Brun | 5464885 | 2020-07-06 15:54:06 +0200 | [diff] [blame] | 85 | LOG_FORMATS /* number of supported log formats, must always be last */ |
| 86 | }; |
| 87 | |
| 88 | /* enum log header meta data */ |
| 89 | enum log_meta { |
| 90 | LOG_META_PRIO, |
| 91 | LOG_META_TIME, |
| 92 | LOG_META_HOST, |
| 93 | LOG_META_TAG, |
| 94 | LOG_META_PID, |
| 95 | LOG_META_MSGID, |
| 96 | LOG_META_STDATA, |
| 97 | LOG_META_FIELDS /* must always be the last */ |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 98 | }; |
| 99 | |
Willy Tarreau | f3dc30f | 2019-08-30 14:18:44 +0200 | [diff] [blame] | 100 | /* log target types */ |
| 101 | enum log_tgt { |
| 102 | LOG_TARGET_DGRAM = 0, // datagram address (udp, unix socket) |
| 103 | LOG_TARGET_FD, // file descriptor |
Willy Tarreau | c046d16 | 2019-08-30 15:24:59 +0200 | [diff] [blame] | 104 | LOG_TARGET_BUFFER, // ring buffer |
Willy Tarreau | f3dc30f | 2019-08-30 14:18:44 +0200 | [diff] [blame] | 105 | }; |
| 106 | |
Willy Tarreau | aeed4a8 | 2020-06-04 22:01:04 +0200 | [diff] [blame] | 107 | /* lists of fields that can be logged, for logformat_node->type */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 108 | enum { |
| 109 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 110 | LOG_FMT_TEXT = 0, /* raw text */ |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 111 | LOG_FMT_EXPR, /* sample expression */ |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 112 | LOG_FMT_SEPARATOR, /* separator replaced by one space */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 113 | |
| 114 | /* information fields */ |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 115 | LOG_FMT_GLOBAL, |
| 116 | LOG_FMT_CLIENTIP, |
| 117 | LOG_FMT_CLIENTPORT, |
| 118 | LOG_FMT_BACKENDIP, |
| 119 | LOG_FMT_BACKENDPORT, |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 120 | LOG_FMT_FRONTENDIP, |
| 121 | LOG_FMT_FRONTENDPORT, |
| 122 | LOG_FMT_SERVERPORT, |
| 123 | LOG_FMT_SERVERIP, |
| 124 | LOG_FMT_COUNTER, |
Willy Tarreau | 7346acb | 2014-08-28 15:03:15 +0200 | [diff] [blame] | 125 | LOG_FMT_LOGCNT, |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 126 | LOG_FMT_PID, |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 127 | LOG_FMT_DATE, |
| 128 | LOG_FMT_DATEGMT, |
Yuxans Yao | 4e25b01 | 2012-10-19 10:36:09 +0800 | [diff] [blame] | 129 | LOG_FMT_DATELOCAL, |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 130 | LOG_FMT_TS, |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 131 | LOG_FMT_MS, |
| 132 | LOG_FMT_FRONTEND, |
Willy Tarreau | 773d65f | 2012-10-12 14:56:11 +0200 | [diff] [blame] | 133 | LOG_FMT_FRONTEND_XPRT, |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 134 | LOG_FMT_BACKEND, |
| 135 | LOG_FMT_SERVER, |
| 136 | LOG_FMT_BYTES, |
Willy Tarreau | c5259fd | 2012-12-20 15:38:04 +0100 | [diff] [blame] | 137 | LOG_FMT_BYTES_UP, |
Thierry FOURNIER / OZON.IO | 4cac359 | 2016-07-28 17:19:45 +0200 | [diff] [blame] | 138 | LOG_FMT_Ta, |
| 139 | LOG_FMT_Th, |
| 140 | LOG_FMT_Ti, |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 141 | LOG_FMT_TQ, |
| 142 | LOG_FMT_TW, |
| 143 | LOG_FMT_TC, |
Thierry FOURNIER / OZON.IO | 4cac359 | 2016-07-28 17:19:45 +0200 | [diff] [blame] | 144 | LOG_FMT_Tr, |
| 145 | LOG_FMT_tr, |
| 146 | LOG_FMT_trg, |
| 147 | LOG_FMT_trl, |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 148 | LOG_FMT_TR, |
Willy Tarreau | 27b639d | 2016-05-17 17:55:27 +0200 | [diff] [blame] | 149 | LOG_FMT_TD, |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 150 | LOG_FMT_TT, |
Damien Claisse | 57c8eb9 | 2020-04-28 12:09:19 +0000 | [diff] [blame] | 151 | LOG_FMT_TU, |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 152 | LOG_FMT_STATUS, |
| 153 | LOG_FMT_CCLIENT, |
| 154 | LOG_FMT_CSERVER, |
| 155 | LOG_FMT_TERMSTATE, |
| 156 | LOG_FMT_TERMSTATE_CK, |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 157 | LOG_FMT_ACTCONN, |
| 158 | LOG_FMT_FECONN, |
| 159 | LOG_FMT_BECONN, |
| 160 | LOG_FMT_SRVCONN, |
| 161 | LOG_FMT_RETRIES, |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 162 | LOG_FMT_SRVQUEUE, |
| 163 | LOG_FMT_BCKQUEUE, |
| 164 | LOG_FMT_HDRREQUEST, |
| 165 | LOG_FMT_HDRRESPONS, |
| 166 | LOG_FMT_HDRREQUESTLIST, |
| 167 | LOG_FMT_HDRRESPONSLIST, |
| 168 | LOG_FMT_REQ, |
Andrew Hayworth | 0ebc55f | 2015-04-27 21:37:03 +0000 | [diff] [blame] | 169 | LOG_FMT_HTTP_METHOD, |
| 170 | LOG_FMT_HTTP_URI, |
| 171 | LOG_FMT_HTTP_PATH, |
Maciej Zdeb | fcdfd85 | 2020-11-30 18:27:47 +0000 | [diff] [blame] | 172 | LOG_FMT_HTTP_PATH_ONLY, |
Andrew Hayworth | e63ac87 | 2015-07-31 16:14:16 +0000 | [diff] [blame] | 173 | LOG_FMT_HTTP_QUERY, |
Andrew Hayworth | 0ebc55f | 2015-04-27 21:37:03 +0000 | [diff] [blame] | 174 | LOG_FMT_HTTP_VERSION, |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 175 | LOG_FMT_HOSTNAME, |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 176 | LOG_FMT_UNIQUEID, |
Willy Tarreau | ffc3fcd | 2012-10-12 20:17:54 +0200 | [diff] [blame] | 177 | LOG_FMT_SSL_CIPHER, |
| 178 | LOG_FMT_SSL_VERSION, |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 179 | }; |
| 180 | |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 181 | /* enum for parse_logformat_string */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 182 | enum { |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 183 | LF_INIT = 0, // before first character |
| 184 | LF_TEXT, // normal text |
| 185 | LF_SEPARATOR, // a single separator |
| 186 | LF_VAR, // variable name, after '%' or '%{..}' |
| 187 | LF_STARTVAR, // % in text |
| 188 | LF_STARG, // after '%{' and berore '}' |
| 189 | LF_EDARG, // '}' after '%{' |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 190 | LF_STEXPR, // after '%[' or '%{..}[' and berore ']' |
| 191 | LF_EDEXPR, // ']' after '%[' |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 192 | LF_END, // \0 found |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 193 | }; |
| 194 | |
| 195 | |
| 196 | struct logformat_node { |
| 197 | struct list list; |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 198 | int type; // LOG_FMT_* |
| 199 | int options; // LOG_OPT_* |
| 200 | char *arg; // text for LOG_FMT_TEXT, arg for others |
| 201 | void *expr; // for use with LOG_FMT_EXPR |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 202 | }; |
| 203 | |
Frédéric Lécaille | d95ea28 | 2019-04-24 16:14:33 +0200 | [diff] [blame] | 204 | /* Range of indexes for log sampling. */ |
| 205 | struct smp_log_range { |
| 206 | unsigned int low; /* Low limit of the indexes of this range. */ |
| 207 | unsigned int high; /* High limit of the indexes of this range. */ |
| 208 | size_t sz; /* The size of this range, or number of indexes in |
| 209 | * this range. |
| 210 | */ |
| 211 | unsigned int curr_idx; /* The current index used to sample this range of |
| 212 | *indexes. |
| 213 | */ |
| 214 | }; |
| 215 | |
| 216 | /* Log sampling information. */ |
| 217 | struct smp_info { |
| 218 | struct smp_log_range *smp_rgs; /* Array of ranges for log sampling. */ |
| 219 | size_t smp_rgs_sz; /* The size of <smp_rgs> array. */ |
| 220 | size_t smp_sz; /* The total number of logs to be sampled. */ |
| 221 | unsigned int curr_rg; /* The current range to be sampled. */ |
| 222 | unsigned int curr_idx; /* A counter to store the current index of the log |
| 223 | * already sampled. |
| 224 | */ |
| 225 | }; |
| 226 | |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 227 | struct logsrv { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 228 | struct list list; |
David du Colombier | 11bcb6c | 2011-03-24 12:23:00 +0100 | [diff] [blame] | 229 | struct sockaddr_storage addr; |
Frédéric Lécaille | d95ea28 | 2019-04-24 16:14:33 +0200 | [diff] [blame] | 230 | struct smp_info lb; |
Emeric Brun | e709e1e | 2020-05-06 17:23:59 +0200 | [diff] [blame] | 231 | struct sink *sink; |
Emeric Brun | 99c453d | 2020-05-25 15:01:04 +0200 | [diff] [blame] | 232 | char *ring_name; |
Willy Tarreau | f3dc30f | 2019-08-30 14:18:44 +0200 | [diff] [blame] | 233 | enum log_tgt type; |
Emeric Brun | 5464885 | 2020-07-06 15:54:06 +0200 | [diff] [blame] | 234 | enum log_fmt format; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 235 | int facility; |
| 236 | int level; |
| 237 | int minlvl; |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 238 | int maxlen; |
Christopher Faulet | 28ac099 | 2018-03-26 16:09:19 +0200 | [diff] [blame] | 239 | struct logsrv *ref; |
Emeric Brun | 9533a70 | 2021-04-02 10:13:43 +0200 | [diff] [blame] | 240 | struct { |
| 241 | char *file; /* file where the logsrv appears */ |
| 242 | int line; /* line where the logsrv appears */ |
| 243 | } conf; |
Willy Tarreau | af613e8 | 2020-06-05 08:40:51 +0200 | [diff] [blame] | 244 | __decl_thread(HA_SPINLOCK_T lock); |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 245 | }; |
| 246 | |
Willy Tarreau | aeed4a8 | 2020-06-04 22:01:04 +0200 | [diff] [blame] | 247 | #endif /* _HAPROXY_LOG_T_H */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 248 | |
| 249 | /* |
| 250 | * Local variables: |
| 251 | * c-indent-level: 8 |
| 252 | * c-basic-offset: 8 |
| 253 | * End: |
| 254 | */ |