blob: 039621a34e4ae346566aa373f8ea59eb65d23e41 [file] [log] [blame]
Willy Tarreaubaaee002006-06-26 02:48:02 +02001/*
Willy Tarreauaeed4a82020-06-04 22:01:04 +02002 * 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 Tarreaubaaee002006-06-26 02:48:02 +020021
Willy Tarreauaeed4a82020-06-04 22:01:04 +020022#ifndef _HAPROXY_LOG_T_H
23#define _HAPROXY_LOG_T_H
Willy Tarreaubaaee002006-06-26 02:48:02 +020024
Willy Tarreau019767b2007-12-05 11:11:55 +010025#include <sys/socket.h>
Robert Tsai81ae1952007-12-05 10:47:29 +010026#include <sys/un.h>
27#include <netinet/in.h>
Willy Tarreauaeed4a82020-06-04 22:01:04 +020028
Willy Tarreaub2551052020-06-09 09:07:15 +020029#include <haproxy/api-t.h>
Willy Tarreaud2ad57c2020-06-03 19:43:35 +020030#include <haproxy/ring-t.h>
Willy Tarreauaeed4a82020-06-04 22:01:04 +020031#include <haproxy/thread-t.h>
Willy Tarreauaeed4a82020-06-04 22:01:04 +020032
Willy Tarreaubaaee002006-06-26 02:48:02 +020033
Willy Tarreaubaaee002006-06-26 02:48:02 +020034#define NB_LOG_FACILITIES 24
35#define NB_LOG_LEVELS 8
Emeric Brun54648852020-07-06 15:54:06 +020036#define NB_LOG_HDR_MAX_ELEMENTS 15
Willy Tarreaubaaee002006-06-26 02:48:02 +020037#define SYSLOG_PORT 514
William Lallemanda73203e2012-03-12 12:48:57 +010038#define UNIQUEID_LEN 128
39
Willy Tarreauaeed4a82020-06-04 22:01:04 +020040/* 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 Dosen1e3b16f2020-06-23 18:16:44 +020048#define LOG_OPT_MERGE_SPACES 0x00000080
Willy Tarreau869efd52019-11-15 15:16:57 +010049
Willy Tarreauaeed4a82020-06-04 22:01:04 +020050
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 Brun54648852020-07-06 15:54:06 +020070#define LOG_LEGACYTIME_LEN 15
71#define LOG_ISOTIME_MINLEN 20
72#define LOG_ISOTIME_MAXLEN 32
Willy Tarreaubaaee002006-06-26 02:48:02 +020073
Dragan Dosen1322d092015-09-22 16:05:32 +020074/* enum for log format */
Emeric Brun54648852020-07-06 15:54:06 +020075enum log_fmt {
76 LOG_FORMAT_UNSPEC = 0,
Emeric Brun0237c4e2020-11-27 16:24:34 +010077 LOG_FORMAT_LOCAL,
Emeric Brun54648852020-07-06 15:54:06 +020078 LOG_FORMAT_RFC3164,
Dragan Dosen1322d092015-09-22 16:05:32 +020079 LOG_FORMAT_RFC5424,
Emeric Brun54648852020-07-06 15:54:06 +020080 LOG_FORMAT_PRIO,
Willy Tarreaue8746a02018-11-12 08:45:00 +010081 LOG_FORMAT_SHORT,
Emeric Brun54648852020-07-06 15:54:06 +020082 LOG_FORMAT_TIMED,
83 LOG_FORMAT_ISO,
Willy Tarreauc1b06452018-11-12 11:57:56 +010084 LOG_FORMAT_RAW,
Emeric Brun54648852020-07-06 15:54:06 +020085 LOG_FORMATS /* number of supported log formats, must always be last */
86};
87
88/* enum log header meta data */
89enum 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 Dosen1322d092015-09-22 16:05:32 +020098};
99
Willy Tarreauf3dc30f2019-08-30 14:18:44 +0200100/* log target types */
101enum log_tgt {
102 LOG_TARGET_DGRAM = 0, // datagram address (udp, unix socket)
103 LOG_TARGET_FD, // file descriptor
Willy Tarreauc046d162019-08-30 15:24:59 +0200104 LOG_TARGET_BUFFER, // ring buffer
Willy Tarreauf3dc30f2019-08-30 14:18:44 +0200105};
106
Willy Tarreauaeed4a82020-06-04 22:01:04 +0200107/* lists of fields that can be logged, for logformat_node->type */
William Lallemand723b73a2012-02-08 16:37:49 +0100108enum {
109
William Lallemand1d705562012-03-12 12:46:41 +0100110 LOG_FMT_TEXT = 0, /* raw text */
Willy Tarreauc8368452012-12-21 00:09:23 +0100111 LOG_FMT_EXPR, /* sample expression */
William Lallemand1d705562012-03-12 12:46:41 +0100112 LOG_FMT_SEPARATOR, /* separator replaced by one space */
William Lallemand723b73a2012-02-08 16:37:49 +0100113
114 /* information fields */
William Lallemand1d705562012-03-12 12:46:41 +0100115 LOG_FMT_GLOBAL,
116 LOG_FMT_CLIENTIP,
117 LOG_FMT_CLIENTPORT,
118 LOG_FMT_BACKENDIP,
119 LOG_FMT_BACKENDPORT,
William Lallemand5f232402012-04-05 18:02:55 +0200120 LOG_FMT_FRONTENDIP,
121 LOG_FMT_FRONTENDPORT,
122 LOG_FMT_SERVERPORT,
123 LOG_FMT_SERVERIP,
124 LOG_FMT_COUNTER,
Willy Tarreau7346acb2014-08-28 15:03:15 +0200125 LOG_FMT_LOGCNT,
William Lallemand5f232402012-04-05 18:02:55 +0200126 LOG_FMT_PID,
William Lallemand1d705562012-03-12 12:46:41 +0100127 LOG_FMT_DATE,
128 LOG_FMT_DATEGMT,
Yuxans Yao4e25b012012-10-19 10:36:09 +0800129 LOG_FMT_DATELOCAL,
William Lallemand5f232402012-04-05 18:02:55 +0200130 LOG_FMT_TS,
William Lallemand1d705562012-03-12 12:46:41 +0100131 LOG_FMT_MS,
132 LOG_FMT_FRONTEND,
Willy Tarreau773d65f2012-10-12 14:56:11 +0200133 LOG_FMT_FRONTEND_XPRT,
William Lallemand1d705562012-03-12 12:46:41 +0100134 LOG_FMT_BACKEND,
135 LOG_FMT_SERVER,
136 LOG_FMT_BYTES,
Willy Tarreauc5259fd2012-12-20 15:38:04 +0100137 LOG_FMT_BYTES_UP,
Thierry FOURNIER / OZON.IO4cac3592016-07-28 17:19:45 +0200138 LOG_FMT_Ta,
139 LOG_FMT_Th,
140 LOG_FMT_Ti,
William Lallemand1d705562012-03-12 12:46:41 +0100141 LOG_FMT_TQ,
142 LOG_FMT_TW,
143 LOG_FMT_TC,
Thierry FOURNIER / OZON.IO4cac3592016-07-28 17:19:45 +0200144 LOG_FMT_Tr,
145 LOG_FMT_tr,
146 LOG_FMT_trg,
147 LOG_FMT_trl,
William Lallemand1d705562012-03-12 12:46:41 +0100148 LOG_FMT_TR,
Willy Tarreau27b639d2016-05-17 17:55:27 +0200149 LOG_FMT_TD,
William Lallemand1d705562012-03-12 12:46:41 +0100150 LOG_FMT_TT,
Damien Claisse57c8eb92020-04-28 12:09:19 +0000151 LOG_FMT_TU,
William Lallemand1d705562012-03-12 12:46:41 +0100152 LOG_FMT_STATUS,
153 LOG_FMT_CCLIENT,
154 LOG_FMT_CSERVER,
155 LOG_FMT_TERMSTATE,
156 LOG_FMT_TERMSTATE_CK,
William Lallemand1d705562012-03-12 12:46:41 +0100157 LOG_FMT_ACTCONN,
158 LOG_FMT_FECONN,
159 LOG_FMT_BECONN,
160 LOG_FMT_SRVCONN,
161 LOG_FMT_RETRIES,
William Lallemand1d705562012-03-12 12:46:41 +0100162 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 Hayworth0ebc55f2015-04-27 21:37:03 +0000169 LOG_FMT_HTTP_METHOD,
170 LOG_FMT_HTTP_URI,
171 LOG_FMT_HTTP_PATH,
Maciej Zdebfcdfd852020-11-30 18:27:47 +0000172 LOG_FMT_HTTP_PATH_ONLY,
Andrew Hayworthe63ac872015-07-31 16:14:16 +0000173 LOG_FMT_HTTP_QUERY,
Andrew Hayworth0ebc55f2015-04-27 21:37:03 +0000174 LOG_FMT_HTTP_VERSION,
William Lallemand5f232402012-04-05 18:02:55 +0200175 LOG_FMT_HOSTNAME,
William Lallemanda73203e2012-03-12 12:48:57 +0100176 LOG_FMT_UNIQUEID,
Willy Tarreauffc3fcd2012-10-12 20:17:54 +0200177 LOG_FMT_SSL_CIPHER,
178 LOG_FMT_SSL_VERSION,
William Lallemand723b73a2012-02-08 16:37:49 +0100179};
180
Willy Tarreau8a3f52f2012-12-20 21:23:42 +0100181/* enum for parse_logformat_string */
William Lallemand723b73a2012-02-08 16:37:49 +0100182enum {
Willy Tarreau8a3f52f2012-12-20 21:23:42 +0100183 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 Tarreauc8368452012-12-21 00:09:23 +0100190 LF_STEXPR, // after '%[' or '%{..}[' and berore ']'
191 LF_EDEXPR, // ']' after '%['
Willy Tarreau8a3f52f2012-12-20 21:23:42 +0100192 LF_END, // \0 found
William Lallemand723b73a2012-02-08 16:37:49 +0100193};
194
195
196struct logformat_node {
197 struct list list;
Willy Tarreauc8368452012-12-21 00:09:23 +0100198 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 Lallemand723b73a2012-02-08 16:37:49 +0100202};
203
Frédéric Lécailled95ea282019-04-24 16:14:33 +0200204/* Range of indexes for log sampling. */
205struct 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. */
217struct 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 Tsai81ae1952007-12-05 10:47:29 +0100227struct logsrv {
William Lallemand0f99e342011-10-12 17:50:54 +0200228 struct list list;
David du Colombier11bcb6c2011-03-24 12:23:00 +0100229 struct sockaddr_storage addr;
Frédéric Lécailled95ea282019-04-24 16:14:33 +0200230 struct smp_info lb;
Emeric Brune709e1e2020-05-06 17:23:59 +0200231 struct sink *sink;
Emeric Brun99c453d2020-05-25 15:01:04 +0200232 char *ring_name;
Willy Tarreauf3dc30f2019-08-30 14:18:44 +0200233 enum log_tgt type;
Emeric Brun54648852020-07-06 15:54:06 +0200234 enum log_fmt format;
William Lallemand0f99e342011-10-12 17:50:54 +0200235 int facility;
236 int level;
237 int minlvl;
Willy Tarreau18324f52014-06-27 18:10:07 +0200238 int maxlen;
Christopher Faulet28ac0992018-03-26 16:09:19 +0200239 struct logsrv *ref;
Emeric Brun9533a702021-04-02 10:13:43 +0200240 struct {
241 char *file; /* file where the logsrv appears */
242 int line; /* line where the logsrv appears */
243 } conf;
Willy Tarreauaf613e82020-06-05 08:40:51 +0200244 __decl_thread(HA_SPINLOCK_T lock);
Robert Tsai81ae1952007-12-05 10:47:29 +0100245};
246
Willy Tarreauaeed4a82020-06-04 22:01:04 +0200247#endif /* _HAPROXY_LOG_T_H */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200248
249/*
250 * Local variables:
251 * c-indent-level: 8
252 * c-basic-offset: 8
253 * End:
254 */