Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1 | /* |
| 2 | include/types/log.h |
| 3 | This file contains definitions of log-related structures and macros. |
| 4 | |
| 5 | Copyright (C) 2000-2006 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 | */ |
| 21 | |
| 22 | #ifndef _TYPES_LOG_H |
| 23 | #define _TYPES_LOG_H |
| 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 | e3ba5f0 | 2006-06-29 18:54:54 +0200 | [diff] [blame] | 28 | #include <common/config.h> |
Frédéric Lécaille | d803e47 | 2019-04-25 07:42:09 +0200 | [diff] [blame] | 29 | #include <common/hathreads.h> |
Willy Tarreau | c7e4238 | 2012-08-24 19:22:53 +0200 | [diff] [blame] | 30 | #include <common/mini-clist.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 31 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 32 | #define NB_LOG_FACILITIES 24 |
| 33 | #define NB_LOG_LEVELS 8 |
Dragan Dosen | 43885c7 | 2015-10-01 13:18:13 +0200 | [diff] [blame] | 34 | #define NB_MSG_IOVEC_ELEMENTS 8 |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 35 | #define SYSLOG_PORT 514 |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 36 | #define UNIQUEID_LEN 128 |
| 37 | |
Thierry FOURNIER | 2ba18a2 | 2015-01-23 14:07:08 +0100 | [diff] [blame] | 38 | /* The array containing the names of the log levels. */ |
| 39 | extern const char *log_levels[]; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 40 | |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 41 | /* enum for log format */ |
| 42 | enum { |
| 43 | LOG_FORMAT_RFC3164 = 0, |
| 44 | LOG_FORMAT_RFC5424, |
Willy Tarreau | e8746a0 | 2018-11-12 08:45:00 +0100 | [diff] [blame] | 45 | LOG_FORMAT_SHORT, |
Willy Tarreau | c1b0645 | 2018-11-12 11:57:56 +0100 | [diff] [blame] | 46 | LOG_FORMAT_RAW, |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 47 | LOG_FORMATS, /* number of supported log formats, must always be last */ |
| 48 | }; |
| 49 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 50 | /* lists of fields that can be logged */ |
| 51 | enum { |
| 52 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 53 | LOG_FMT_TEXT = 0, /* raw text */ |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 54 | LOG_FMT_EXPR, /* sample expression */ |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 55 | LOG_FMT_SEPARATOR, /* separator replaced by one space */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 56 | |
| 57 | /* information fields */ |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 58 | LOG_FMT_GLOBAL, |
| 59 | LOG_FMT_CLIENTIP, |
| 60 | LOG_FMT_CLIENTPORT, |
| 61 | LOG_FMT_BACKENDIP, |
| 62 | LOG_FMT_BACKENDPORT, |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 63 | LOG_FMT_FRONTENDIP, |
| 64 | LOG_FMT_FRONTENDPORT, |
| 65 | LOG_FMT_SERVERPORT, |
| 66 | LOG_FMT_SERVERIP, |
| 67 | LOG_FMT_COUNTER, |
Willy Tarreau | 7346acb | 2014-08-28 15:03:15 +0200 | [diff] [blame] | 68 | LOG_FMT_LOGCNT, |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 69 | LOG_FMT_PID, |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 70 | LOG_FMT_DATE, |
| 71 | LOG_FMT_DATEGMT, |
Yuxans Yao | 4e25b01 | 2012-10-19 10:36:09 +0800 | [diff] [blame] | 72 | LOG_FMT_DATELOCAL, |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 73 | LOG_FMT_TS, |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 74 | LOG_FMT_MS, |
| 75 | LOG_FMT_FRONTEND, |
Willy Tarreau | 773d65f | 2012-10-12 14:56:11 +0200 | [diff] [blame] | 76 | LOG_FMT_FRONTEND_XPRT, |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 77 | LOG_FMT_BACKEND, |
| 78 | LOG_FMT_SERVER, |
| 79 | LOG_FMT_BYTES, |
Willy Tarreau | c5259fd | 2012-12-20 15:38:04 +0100 | [diff] [blame] | 80 | LOG_FMT_BYTES_UP, |
Thierry FOURNIER / OZON.IO | 4cac359 | 2016-07-28 17:19:45 +0200 | [diff] [blame] | 81 | LOG_FMT_Ta, |
| 82 | LOG_FMT_Th, |
| 83 | LOG_FMT_Ti, |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 84 | LOG_FMT_TQ, |
| 85 | LOG_FMT_TW, |
| 86 | LOG_FMT_TC, |
Thierry FOURNIER / OZON.IO | 4cac359 | 2016-07-28 17:19:45 +0200 | [diff] [blame] | 87 | LOG_FMT_Tr, |
| 88 | LOG_FMT_tr, |
| 89 | LOG_FMT_trg, |
| 90 | LOG_FMT_trl, |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 91 | LOG_FMT_TR, |
Willy Tarreau | 27b639d | 2016-05-17 17:55:27 +0200 | [diff] [blame] | 92 | LOG_FMT_TD, |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 93 | LOG_FMT_TT, |
| 94 | LOG_FMT_STATUS, |
| 95 | LOG_FMT_CCLIENT, |
| 96 | LOG_FMT_CSERVER, |
| 97 | LOG_FMT_TERMSTATE, |
| 98 | LOG_FMT_TERMSTATE_CK, |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 99 | LOG_FMT_ACTCONN, |
| 100 | LOG_FMT_FECONN, |
| 101 | LOG_FMT_BECONN, |
| 102 | LOG_FMT_SRVCONN, |
| 103 | LOG_FMT_RETRIES, |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 104 | LOG_FMT_SRVQUEUE, |
| 105 | LOG_FMT_BCKQUEUE, |
| 106 | LOG_FMT_HDRREQUEST, |
| 107 | LOG_FMT_HDRRESPONS, |
| 108 | LOG_FMT_HDRREQUESTLIST, |
| 109 | LOG_FMT_HDRRESPONSLIST, |
| 110 | LOG_FMT_REQ, |
Andrew Hayworth | 0ebc55f | 2015-04-27 21:37:03 +0000 | [diff] [blame] | 111 | LOG_FMT_HTTP_METHOD, |
| 112 | LOG_FMT_HTTP_URI, |
| 113 | LOG_FMT_HTTP_PATH, |
Andrew Hayworth | e63ac87 | 2015-07-31 16:14:16 +0000 | [diff] [blame] | 114 | LOG_FMT_HTTP_QUERY, |
Andrew Hayworth | 0ebc55f | 2015-04-27 21:37:03 +0000 | [diff] [blame] | 115 | LOG_FMT_HTTP_VERSION, |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 116 | LOG_FMT_HOSTNAME, |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 117 | LOG_FMT_UNIQUEID, |
Willy Tarreau | ffc3fcd | 2012-10-12 20:17:54 +0200 | [diff] [blame] | 118 | LOG_FMT_SSL_CIPHER, |
| 119 | LOG_FMT_SSL_VERSION, |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 120 | }; |
| 121 | |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 122 | /* enum for parse_logformat_string */ |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 123 | enum { |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 124 | LF_INIT = 0, // before first character |
| 125 | LF_TEXT, // normal text |
| 126 | LF_SEPARATOR, // a single separator |
| 127 | LF_VAR, // variable name, after '%' or '%{..}' |
| 128 | LF_STARTVAR, // % in text |
| 129 | LF_STARG, // after '%{' and berore '}' |
| 130 | LF_EDARG, // '}' after '%{' |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 131 | LF_STEXPR, // after '%[' or '%{..}[' and berore ']' |
| 132 | LF_EDEXPR, // ']' after '%[' |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 133 | LF_END, // \0 found |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 134 | }; |
| 135 | |
| 136 | |
| 137 | struct logformat_node { |
| 138 | struct list list; |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 139 | int type; // LOG_FMT_* |
| 140 | int options; // LOG_OPT_* |
| 141 | char *arg; // text for LOG_FMT_TEXT, arg for others |
| 142 | void *expr; // for use with LOG_FMT_EXPR |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 143 | }; |
| 144 | |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 145 | #define LOG_OPT_HEXA 0x00000001 |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 146 | #define LOG_OPT_MANDATORY 0x00000002 |
| 147 | #define LOG_OPT_QUOTE 0x00000004 |
Willy Tarreau | c836845 | 2012-12-21 00:09:23 +0100 | [diff] [blame] | 148 | #define LOG_OPT_REQ_CAP 0x00000008 |
| 149 | #define LOG_OPT_RES_CAP 0x00000010 |
Thierry FOURNIER | d048d8b | 2014-03-13 16:46:18 +0100 | [diff] [blame] | 150 | #define LOG_OPT_HTTP 0x00000020 |
Dragan Dosen | 835b921 | 2016-02-12 13:23:03 +0100 | [diff] [blame] | 151 | #define LOG_OPT_ESC 0x00000040 |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 152 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 153 | |
Willy Tarreau | d79a3b2 | 2012-12-28 09:40:16 +0100 | [diff] [blame] | 154 | /* Fields that need to be extracted from the incoming connection or request for |
| 155 | * logging or for sending specific header information. They're set in px->to_log |
| 156 | * and appear as flags in session->logs.logwait, which are removed once the |
| 157 | * required information has been collected. |
| 158 | */ |
| 159 | #define LW_INIT 1 /* anything */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 160 | #define LW_CLIP 2 /* CLient IP */ |
| 161 | #define LW_SVIP 4 /* SerVer IP */ |
| 162 | #define LW_SVID 8 /* server ID */ |
| 163 | #define LW_REQ 16 /* http REQuest */ |
| 164 | #define LW_RESP 32 /* http RESPonse */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 165 | #define LW_BYTES 256 /* bytes read from server */ |
| 166 | #define LW_COOKIE 512 /* captured cookie */ |
| 167 | #define LW_REQHDR 1024 /* request header(s) */ |
| 168 | #define LW_RSPHDR 2048 /* response header(s) */ |
William Lallemand | 5e19a28 | 2012-04-02 16:22:10 +0200 | [diff] [blame] | 169 | #define LW_BCKIP 4096 /* backend IP */ |
| 170 | #define LW_FRTIP 8192 /* frontend IP */ |
Willy Tarreau | 93dbc2b | 2012-10-12 18:01:49 +0200 | [diff] [blame] | 171 | #define LW_XPRT 16384 /* transport layer information (eg: SSL) */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 172 | |
Frédéric Lécaille | d95ea28 | 2019-04-24 16:14:33 +0200 | [diff] [blame] | 173 | /* Range of indexes for log sampling. */ |
| 174 | struct smp_log_range { |
| 175 | unsigned int low; /* Low limit of the indexes of this range. */ |
| 176 | unsigned int high; /* High limit of the indexes of this range. */ |
| 177 | size_t sz; /* The size of this range, or number of indexes in |
| 178 | * this range. |
| 179 | */ |
| 180 | unsigned int curr_idx; /* The current index used to sample this range of |
| 181 | *indexes. |
| 182 | */ |
| 183 | }; |
| 184 | |
| 185 | /* Log sampling information. */ |
| 186 | struct smp_info { |
| 187 | struct smp_log_range *smp_rgs; /* Array of ranges for log sampling. */ |
| 188 | size_t smp_rgs_sz; /* The size of <smp_rgs> array. */ |
| 189 | size_t smp_sz; /* The total number of logs to be sampled. */ |
| 190 | unsigned int curr_rg; /* The current range to be sampled. */ |
| 191 | unsigned int curr_idx; /* A counter to store the current index of the log |
| 192 | * already sampled. |
| 193 | */ |
| 194 | }; |
| 195 | |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 196 | struct logsrv { |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 197 | struct list list; |
David du Colombier | 11bcb6c | 2011-03-24 12:23:00 +0100 | [diff] [blame] | 198 | struct sockaddr_storage addr; |
Frédéric Lécaille | d95ea28 | 2019-04-24 16:14:33 +0200 | [diff] [blame] | 199 | struct smp_info lb; |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 200 | int format; |
William Lallemand | 0f99e34 | 2011-10-12 17:50:54 +0200 | [diff] [blame] | 201 | int facility; |
| 202 | int level; |
| 203 | int minlvl; |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 204 | int maxlen; |
Christopher Faulet | 28ac099 | 2018-03-26 16:09:19 +0200 | [diff] [blame] | 205 | struct logsrv *ref; |
Frédéric Lécaille | d803e47 | 2019-04-25 07:42:09 +0200 | [diff] [blame] | 206 | __decl_hathreads(HA_SPINLOCK_T lock); |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 207 | }; |
| 208 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 209 | #endif /* _TYPES_LOG_H */ |
| 210 | |
| 211 | /* |
| 212 | * Local variables: |
| 213 | * c-indent-level: 8 |
| 214 | * c-basic-offset: 8 |
| 215 | * End: |
| 216 | */ |