Coverage Report

Created: 2026-07-16 07:11

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/haproxy/include/haproxy/connection-t.h
Line
Count
Source
1
/*
2
 * include/haproxy/connection-t.h
3
 * This file describes the connection struct and associated constants.
4
 *
5
 * Copyright (C) 2000-2014 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 _HAPROXY_CONNECTION_T_H
23
#define _HAPROXY_CONNECTION_T_H
24
25
#include <stdlib.h>
26
#include <sys/socket.h>
27
#include <netinet/in_systm.h>
28
#include <netinet/ip.h>
29
#include <netinet/ip6.h>
30
31
#include <import/cebtree.h>
32
#include <import/ist.h>
33
34
#include <haproxy/api-t.h>
35
#include <haproxy/buf-t.h>
36
#include <haproxy/obj_type-t.h>
37
#include <haproxy/port_range-t.h>
38
#include <haproxy/protocol-t.h>
39
#include <haproxy/show_flags-t.h>
40
#include <haproxy/task-t.h>
41
#include <haproxy/thread-t.h>
42
43
/* referenced below */
44
struct connection;
45
struct stconn;
46
struct sedesc;
47
struct se_abort_info;
48
struct cs_info;
49
struct buffer;
50
struct proxy;
51
struct server;
52
struct session;
53
struct pipe;
54
struct quic_conn;
55
struct bind_conf;
56
struct qcs;
57
struct ssl_sock_ctx;
58
59
/* For each direction, we have a CO_FL_XPRT_<DIR>_ENA flag, which
60
 * indicates if read or write is desired in that direction for the respective
61
 * layers. The current status corresponding to the current layer being used is
62
 * remembered in the CO_FL_XPRT_<DIR>_ENA flag. The need to poll (ie receipt of
63
 * EAGAIN) is remembered at the file descriptor level so that even when the
64
 * activity is stopped and restarted, we still remember whether it was needed
65
 * to poll before attempting the I/O.
66
 *
67
 * The FD state is updated according to CO_FL_XPRT_<DIR>_ENA in
68
 * conn_cond_update_polling().
69
 */
70
71
/* A bit of explanation is required for backend connection reuse. A connection
72
 * may be shared between multiple streams of the same thread (e.g. h2, fcgi,
73
 * quic) and may be reused by subsequent streams of a different thread if it
74
 * is totally idle (i.e. not used at all). In order to permit other streams
75
 * to find a connection, it has to appear in lists and/or trees that reflect
76
 * its current state. If the connection is full and cannot be shared anymore,
77
 * it is not in any of such places. The various states are the following:
78
 *
79
 * - private: a private connection is not visible to other threads. It is
80
 *   attached via its <idle_list> member to the <conn_list> head of a
81
 *   sess_priv_conns struct specific to the server, itself attached to the
82
 *   session. Only other streams of the same session may find this connection.
83
 *   Such connections include totally idle connections as well as connections
84
 *   with available slots left. The <hash_node> part is still used to store
85
 *   the hash key but the tree node part is otherwise left unused.
86
 *
87
 * - avail: an available connection is a connection that has at least one
88
 *   stream in use and at least one slot available for a new stream. Such a
89
 *   connection is indexed in the server's <avail_conns> member based on the
90
 *   key of the hash_node. It cannot be used by other threads, and is not
91
 *   present in the server's <idle_conn_list>, so its <idle_list> member is
92
 *   always empty. Since this connection is in use by a single thread and
93
 *   cannot be taken over, it doesn't require any locking to enter/leave the
94
 *   tree.
95
 *
96
 * - safe: a safe connection is an idle connection that has proven that it
97
 *   could reliably be reused. Such a connection may be taken over at any
98
 *   instant by other threads, and must only be manipulated under the server's
99
 *   <idle_lock>. It is indexed in the server's <safe_conns> member based on
100
 *   the key of the hash_node. It is attached to the server's <idle_conn_list>
101
 *   via its <idle_list> member. It may be purged after too long inactivity,
102
 *   though the thread responsible for doing this will first take it over. Such
103
 *   a connection has (conn->flags & CO_FL_LIST_MASK) = CO_FL_SAFE_LIST.
104
 *
105
 * - idle: a purely idle connection has not yet proven that it could reliably
106
 *   be reused. Such a connection may be taken over at any instant by other
107
 *   threads, and must only be manipulated under the server's <idle_lock>. It
108
 *   is indexed in the server's <idle_conns> member based on the key of the
109
 *   hash_node. It is attached to the server's <idle_conn_list> via its
110
 *   <idle_list> member. It may be purged after too long inactivity, though the
111
 *   thread responsible for doing this will first take it over. Such a
112
 *   connection has (conn->flags & CO_FL_LIST_MASK) = CO_FL_IDLE_LIST.
113
 */
114
115
/* flags for use in connection->flags. Please also update the conn_show_flags()
116
 * function below in case of changes.
117
 */
118
enum {
119
  CO_FL_NONE          = 0x00000000,  /* Just for initialization purposes */
120
121
  /* Do not change these values without updating conn_*_poll_changes() ! */
122
  CO_FL_SAFE_LIST     = 0x00000001,  /* 0 = not in any list, 1 = in safe_list  */
123
  CO_FL_IDLE_LIST     = 0x00000002,  /* 2 = in idle_list, 3 = invalid */
124
  CO_FL_LIST_MASK     = 0x00000003,  /* Is the connection in any server-managed list ? */
125
126
  CO_FL_REVERSED      = 0x00000004,  /* connection has been reversed to backend / reversed and accepted on frontend */
127
  CO_FL_ACT_REVERSING = 0x00000008,  /* connection has been reversed to frontend but not yet accepted */
128
129
  CO_FL_OPT_MARK      = 0x00000010,  /* connection has a special sockopt mark */
130
131
  CO_FL_OPT_TOS       = 0x00000020,  /* connection has a special sockopt tos */
132
133
  CO_FL_QMUX_SEND    = 0x00000040,   /* connection uses QMux protocol, needs to exchange transport parameters before starting mux layer */
134
  CO_FL_QMUX_RECV    = 0x00000080,   /* connection uses QMux protocol, needs to exchange transport parameters before starting mux layer */
135
136
  /* These flags indicate whether the Control and Transport layers are initialized */
137
  CO_FL_CTRL_READY    = 0x00000100, /* FD was registered, fd_delete() needed */
138
  CO_FL_XPRT_READY    = 0x00000200, /* xprt_start() done, xprt can be used */
139
140
  CO_FL_WANT_DRAIN    = 0x00000400, /* try to drain pending data when closing */
141
142
  /* This flag is used by data layers to indicate they had to stop
143
   * receiving data because a buffer was full. The connection handler
144
   * clears it before first calling the I/O and data callbacks.
145
   */
146
  CO_FL_WAIT_ROOM     = 0x00000800,  /* data sink is full */
147
148
  CO_FL_WANT_SPLICING = 0x00001000,  /* we wish to use splicing on the connection when possible */
149
  CO_FL_SSL_NO_CACHED_INFO = 0x00002000, /* Don't use any cached information when creating a new SSL connection */
150
151
  CO_FL_EARLY_SSL_HS  = 0x00004000,  /* We have early data pending, don't start SSL handshake yet */
152
  CO_FL_EARLY_DATA    = 0x00008000,  /* At least some of the data are early data */
153
  CO_FL_SOCKS4_SEND   = 0x00010000,  /* handshaking with upstream SOCKS4 proxy, going to send the handshake */
154
  CO_FL_SOCKS4_RECV   = 0x00020000,  /* handshaking with upstream SOCKS4 proxy, going to check if handshake succeed */
155
156
  /* flags used to remember what shutdown have been performed/reported */
157
  CO_FL_SOCK_RD_SH    = 0x00040000,  /* SOCK layer was notified about shutr/read0 */
158
  CO_FL_SOCK_WR_SH    = 0x00080000,  /* SOCK layer asked for shutw */
159
160
  /* flags used to report connection errors or other closing conditions */
161
  CO_FL_ERROR         = 0x00100000,  /* a fatal error was reported     */
162
  CO_FL_NOTIFY_DONE   = 0x001C0000,  /* any xprt shut/error flags above needs to be reported */
163
164
  CO_FL_FDLESS        = 0x00200000,  /* this connection doesn't use any FD (e.g. QUIC) */
165
166
  /* flags used to report connection status updates */
167
  CO_FL_WAIT_L4_CONN  = 0x00400000,  /* waiting for L4 to be connected */
168
  CO_FL_WAIT_L6_CONN  = 0x00800000,  /* waiting for L6 to be connected (eg: SSL) */
169
  CO_FL_WAIT_L4L6     = 0x00C00000,  /* waiting for L4 and/or L6 to be connected */
170
171
  /* All the flags below are used for connection handshakes. Any new
172
   * handshake should be added after this point, and CO_FL_HANDSHAKE
173
   * should be updated.
174
   */
175
  CO_FL_SEND_PROXY    = 0x01000000,  /* send a valid PROXY protocol header */
176
  CO_FL_ACCEPT_PROXY  = 0x02000000,  /* receive a valid PROXY protocol header */
177
  CO_FL_ACCEPT_CIP    = 0x04000000,  /* receive a valid NetScaler Client IP header */
178
179
  /* below we have all handshake flags grouped into one */
180
  CO_FL_HANDSHAKE     = CO_FL_SEND_PROXY | CO_FL_ACCEPT_PROXY | CO_FL_ACCEPT_CIP | CO_FL_SOCKS4_SEND | CO_FL_SOCKS4_RECV,
181
  CO_FL_WAIT_XPRT     = CO_FL_WAIT_L4_CONN | CO_FL_HANDSHAKE | CO_FL_WAIT_L6_CONN,
182
  /* handshake running on top of a layer6 */
183
  CO_FL_WAIT_XPRT_L6  = CO_FL_QMUX_SEND | CO_FL_QMUX_RECV,
184
185
  CO_FL_SSL_WAIT_HS   = 0x08000000,  /* wait for an SSL handshake to complete */
186
187
  /* This connection may not be shared between clients */
188
  CO_FL_PRIVATE       = 0x10000000,
189
190
  /* This flag is used to know that a PROXY protocol header was sent by the client */
191
  CO_FL_RCVD_PROXY    = 0x20000000,
192
193
  /* The connection is unused by its owner */
194
  CO_FL_SESS_IDLE     = 0x40000000,
195
196
  /* This last flag indicates that the transport layer is used (for instance
197
   * by logs) and must not be cleared yet. The last call to conn_xprt_close()
198
   * must be done after clearing this flag.
199
   */
200
  CO_FL_XPRT_TRACKED  = 0x80000000,
201
202
  /* below we have all SOCKS handshake flags grouped into one */
203
  CO_FL_SOCKS4        = CO_FL_SOCKS4_SEND | CO_FL_SOCKS4_RECV,
204
};
205
206
/* This function is used to report flags in debugging tools. Please reflect
207
 * below any single-bit flag addition above in the same order via the
208
 * __APPEND_FLAG macro. The new end of the buffer is returned.
209
 */
210
static forceinline char *conn_show_flags(char *buf, size_t len, const char *delim, uint flg)
211
0
{
212
0
#define _(f, ...) __APPEND_FLAG(buf, len, delim, flg, f, #f, __VA_ARGS__)
213
0
  /* prologue */
214
0
  _(0);
215
0
  /* flags */
216
0
  _(CO_FL_SAFE_LIST, _(CO_FL_IDLE_LIST, _(CO_FL_CTRL_READY,
217
0
  _(CO_FL_REVERSED, _(CO_FL_ACT_REVERSING, _(CO_FL_OPT_MARK, _(CO_FL_OPT_TOS,
218
0
  _(CO_FL_QMUX_SEND, _(CO_FL_QMUX_RECV,
219
0
  _(CO_FL_XPRT_READY, _(CO_FL_WANT_DRAIN, _(CO_FL_WAIT_ROOM, _(CO_FL_SSL_NO_CACHED_INFO, _(CO_FL_EARLY_SSL_HS,
220
0
  _(CO_FL_EARLY_DATA, _(CO_FL_SOCKS4_SEND, _(CO_FL_SOCKS4_RECV, _(CO_FL_SOCK_RD_SH,
221
0
  _(CO_FL_SOCK_WR_SH, _(CO_FL_ERROR, _(CO_FL_FDLESS, _(CO_FL_WAIT_L4_CONN,
222
0
  _(CO_FL_WAIT_L6_CONN, _(CO_FL_SEND_PROXY, _(CO_FL_ACCEPT_PROXY, _(CO_FL_ACCEPT_CIP,
223
0
  _(CO_FL_SSL_WAIT_HS, _(CO_FL_PRIVATE, _(CO_FL_RCVD_PROXY, _(CO_FL_SESS_IDLE,
224
0
  _(CO_FL_XPRT_TRACKED
225
0
  )))))))))))))))))))))))))))))));
226
0
  /* epilogue */
227
0
  _(~0U);
228
0
  return buf;
229
0
#undef _
230
0
}
Unexecuted instantiation: fuzz_http.c:conn_show_flags
Unexecuted instantiation: http.c:conn_show_flags
Unexecuted instantiation: tools.c:conn_show_flags
Unexecuted instantiation: applet.c:conn_show_flags
Unexecuted instantiation: cfgparse.c:conn_show_flags
Unexecuted instantiation: channel.c:conn_show_flags
Unexecuted instantiation: chunk.c:conn_show_flags
Unexecuted instantiation: cli.c:conn_show_flags
Unexecuted instantiation: clock.c:conn_show_flags
Unexecuted instantiation: connection.c:conn_show_flags
Unexecuted instantiation: debug.c:conn_show_flags
Unexecuted instantiation: dgram.c:conn_show_flags
Unexecuted instantiation: dynbuf.c:conn_show_flags
Unexecuted instantiation: errors.c:conn_show_flags
Unexecuted instantiation: fd.c:conn_show_flags
Unexecuted instantiation: freq_ctr.c:conn_show_flags
Unexecuted instantiation: frontend.c:conn_show_flags
Unexecuted instantiation: haproxy.c:conn_show_flags
Unexecuted instantiation: http_ana.c:conn_show_flags
Unexecuted instantiation: http_ext.c:conn_show_flags
Unexecuted instantiation: http_htx.c:conn_show_flags
Unexecuted instantiation: http_rules.c:conn_show_flags
Unexecuted instantiation: htx.c:conn_show_flags
Unexecuted instantiation: limits.c:conn_show_flags
Unexecuted instantiation: listener.c:conn_show_flags
Unexecuted instantiation: log.c:conn_show_flags
Unexecuted instantiation: mailers.c:conn_show_flags
Unexecuted instantiation: mworker.c:conn_show_flags
Unexecuted instantiation: peers.c:conn_show_flags
Unexecuted instantiation: pool.c:conn_show_flags
Unexecuted instantiation: proto_rhttp.c:conn_show_flags
Unexecuted instantiation: proto_sockpair.c:conn_show_flags
Unexecuted instantiation: protocol.c:conn_show_flags
Unexecuted instantiation: proxy.c:conn_show_flags
Unexecuted instantiation: queue.c:conn_show_flags
Unexecuted instantiation: regex.c:conn_show_flags
Unexecuted instantiation: resolvers.c:conn_show_flags
Unexecuted instantiation: ring.c:conn_show_flags
Unexecuted instantiation: sample.c:conn_show_flags
Unexecuted instantiation: server.c:conn_show_flags
Unexecuted instantiation: session.c:conn_show_flags
Unexecuted instantiation: signal.c:conn_show_flags
Unexecuted instantiation: sink.c:conn_show_flags
Unexecuted instantiation: sock.c:conn_show_flags
Unexecuted instantiation: sock_inet.c:conn_show_flags
Unexecuted instantiation: stats-html.c:conn_show_flags
Unexecuted instantiation: stats-proxy.c:conn_show_flags
Unexecuted instantiation: stats.c:conn_show_flags
Unexecuted instantiation: stconn.c:conn_show_flags
Unexecuted instantiation: stick_table.c:conn_show_flags
Unexecuted instantiation: stream.c:conn_show_flags
Unexecuted instantiation: systemd.c:conn_show_flags
Unexecuted instantiation: task.c:conn_show_flags
Unexecuted instantiation: tcp_rules.c:conn_show_flags
Unexecuted instantiation: tcpcheck.c:conn_show_flags
Unexecuted instantiation: thread.c:conn_show_flags
Unexecuted instantiation: trace.c:conn_show_flags
Unexecuted instantiation: uri_auth.c:conn_show_flags
Unexecuted instantiation: vars.c:conn_show_flags
Unexecuted instantiation: version.c:conn_show_flags
Unexecuted instantiation: acl.c:conn_show_flags
Unexecuted instantiation: action.c:conn_show_flags
Unexecuted instantiation: activity.c:conn_show_flags
Unexecuted instantiation: arg.c:conn_show_flags
Unexecuted instantiation: auth.c:conn_show_flags
Unexecuted instantiation: backend.c:conn_show_flags
Unexecuted instantiation: cfgcond.c:conn_show_flags
Unexecuted instantiation: cfgparse-global.c:conn_show_flags
Unexecuted instantiation: cfgparse-listen.c:conn_show_flags
Unexecuted instantiation: check.c:conn_show_flags
Unexecuted instantiation: compression.c:conn_show_flags
Unexecuted instantiation: counters.c:conn_show_flags
Unexecuted instantiation: dns.c:conn_show_flags
Unexecuted instantiation: dns_ring.c:conn_show_flags
Unexecuted instantiation: event_hdl.c:conn_show_flags
Unexecuted instantiation: extcheck.c:conn_show_flags
Unexecuted instantiation: filters.c:conn_show_flags
Unexecuted instantiation: fix.c:conn_show_flags
Unexecuted instantiation: flt_http_comp.c:conn_show_flags
Unexecuted instantiation: guid.c:conn_show_flags
Unexecuted instantiation: h1.c:conn_show_flags
Unexecuted instantiation: haterm.c:conn_show_flags
Unexecuted instantiation: http_fetch.c:conn_show_flags
Unexecuted instantiation: lb_chash.c:conn_show_flags
Unexecuted instantiation: lb_fas.c:conn_show_flags
Unexecuted instantiation: lb_fwlc.c:conn_show_flags
Unexecuted instantiation: lb_fwrr.c:conn_show_flags
Unexecuted instantiation: lb_map.c:conn_show_flags
Unexecuted instantiation: lb_ss.c:conn_show_flags
Unexecuted instantiation: mqtt.c:conn_show_flags
Unexecuted instantiation: mux_spop.c:conn_show_flags
Unexecuted instantiation: pattern.c:conn_show_flags
Unexecuted instantiation: payload.c:conn_show_flags
Unexecuted instantiation: pipe.c:conn_show_flags
Unexecuted instantiation: proto_tcp.c:conn_show_flags
Unexecuted instantiation: stats-file.c:conn_show_flags
Unexecuted instantiation: stats-json.c:conn_show_flags
Unexecuted instantiation: cache.c:conn_show_flags
Unexecuted instantiation: fcgi-app.c:conn_show_flags
Unexecuted instantiation: flt_spoe.c:conn_show_flags
Unexecuted instantiation: h1_htx.c:conn_show_flags
Unexecuted instantiation: shctx.c:conn_show_flags
231
232
/* Possible connection error codes.
233
 * Warning: Do not reorder the codes, they are fetchable through the
234
 * "fc_err" sample fetch. If a new code is added, please add an error label
235
 * in conn_err_code_str and in the "fc_err_str" sample fetch documentation.
236
 */
237
enum {
238
  CO_ER_NONE,             /* no error */
239
240
  CO_ER_CONF_FDLIM,       /* reached process's configured FD limitation */
241
  CO_ER_PROC_FDLIM,       /* reached process's FD limitation */
242
  CO_ER_SYS_FDLIM,        /* reached system's FD limitation */
243
  CO_ER_SYS_MEMLIM,       /* reached system buffers limitation */
244
  CO_ER_NOPROTO,          /* protocol not supported */
245
  CO_ER_SOCK_ERR,         /* other socket error */
246
247
  CO_ER_PORT_RANGE,       /* source port range exhausted */
248
  CO_ER_CANT_BIND,        /* can't bind to source address */
249
  CO_ER_FREE_PORTS,       /* no more free ports on the system */
250
  CO_ER_ADDR_INUSE,       /* local address already in use */
251
252
  CO_ER_PRX_EMPTY,        /* nothing received in PROXY protocol header */
253
  CO_ER_PRX_ABORT,        /* client abort during PROXY protocol header */
254
  CO_ER_PRX_TIMEOUT,      /* timeout while waiting for a PROXY header */
255
  CO_ER_PRX_TRUNCATED,    /* truncated PROXY protocol header */
256
  CO_ER_PRX_NOT_HDR,      /* not a PROXY protocol header */
257
  CO_ER_PRX_BAD_HDR,      /* bad PROXY protocol header */
258
  CO_ER_PRX_BAD_PROTO,    /* unsupported protocol in PROXY header */
259
260
  CO_ER_CIP_EMPTY,        /* nothing received in NetScaler Client IP header */
261
  CO_ER_CIP_ABORT,        /* client abort during NetScaler Client IP header */
262
  CO_ER_CIP_TIMEOUT,      /* timeout while waiting for a NetScaler Client IP header */
263
  CO_ER_CIP_TRUNCATED,    /* truncated NetScaler Client IP header */
264
  CO_ER_CIP_BAD_MAGIC,    /* bad magic number in NetScaler Client IP header */
265
  CO_ER_CIP_BAD_PROTO,    /* unsupported protocol in NetScaler Client IP header */
266
267
  CO_ER_SSL_EMPTY,        /* client closed during SSL handshake */
268
  CO_ER_SSL_ABORT,        /* client abort during SSL handshake */
269
  CO_ER_SSL_TIMEOUT,      /* timeout during SSL handshake */
270
  CO_ER_SSL_TOO_MANY,     /* too many SSL connections */
271
  CO_ER_SSL_NO_MEM,       /* no more memory to allocate an SSL connection */
272
  CO_ER_SSL_RENEG,        /* forbidden client renegotiation */
273
  CO_ER_SSL_CA_FAIL,      /* client cert verification failed in the CA chain */
274
  CO_ER_SSL_CRT_FAIL,     /* client cert verification failed on the certificate */
275
  CO_ER_SSL_MISMATCH,     /* Server presented an SSL certificate different from the configured one */
276
  CO_ER_SSL_MISMATCH_SNI, /* Server presented an SSL certificate different from the expected one */
277
  CO_ER_SSL_HANDSHAKE,    /* SSL error during handshake */
278
  CO_ER_SSL_HANDSHAKE_HB, /* SSL error during handshake with heartbeat present */
279
  CO_ER_SSL_KILLED_HB,    /* Stopped a TLSv1 heartbeat attack (CVE-2014-0160) */
280
  CO_ER_SSL_NO_TARGET,    /* unknown target (not client nor server) */
281
  CO_ER_SSL_EARLY_FAILED, /* Server refused early data */
282
283
  CO_ER_SOCKS4_SEND,       /* SOCKS4 Proxy write error during handshake */
284
  CO_ER_SOCKS4_RECV,       /* SOCKS4 Proxy read error during handshake */
285
  CO_ER_SOCKS4_DENY,       /* SOCKS4 Proxy deny the request */
286
  CO_ER_SOCKS4_ABORT,      /* SOCKS4 Proxy handshake aborted by server */
287
288
  CO_ER_SSL_FATAL,         /* SSL fatal error during a SSL_read or SSL_write */
289
290
  CO_ER_QMUX,              /* QMux transport parameter exchange failure */
291
292
  CO_ER_REVERSE,           /* Error during reverse connect */
293
294
  CO_ER_POLLERR,           /* we only noticed POLLERR */
295
  CO_ER_EREFUSED,          /* ECONNREFUSED returned to recv/send */
296
  CO_ER_ERESET,            /* ECONNRESET returned to recv/send */
297
  CO_ER_EUNREACH,          /* ENETUNREACH returned to recv/send */
298
  CO_ER_ENOMEM,            /* ENOMEM returned to recv/send */
299
  CO_ER_EBADF,             /* EBADF returned to recv/send (serious bug) */
300
  CO_ER_EFAULT,            /* EFAULT returned to recv/send (serious bug) */
301
  CO_ER_EINVAL,            /* EINVAL returned to recv/send (serious bug) */
302
  CO_ER_ENCONN,            /* ENCONN returned to recv/send */
303
  CO_ER_ENSOCK,            /* ENSOCK returned to recv/send */
304
  CO_ER_ENOBUFS,           /* ENOBUFS returned to send */
305
  CO_ER_EPIPE,             /* EPIPE returned to send */
306
};
307
308
/* error return codes for accept_conn() */
309
enum {
310
  CO_AC_NONE = 0,  /* no error, valid connection returned */
311
  CO_AC_DONE,      /* reached the end of the queue (typically EAGAIN) */
312
  CO_AC_RETRY,     /* late signal delivery or anything requiring the caller to try again */
313
  CO_AC_YIELD,     /* short-lived limitation that requires a short pause */
314
  CO_AC_PAUSE,     /* long-lived issue (resource/memory allocation error, paused FD) */
315
  CO_AC_PERMERR,   /* permanent, non-recoverable error (e.g. closed listener socket) */
316
};
317
318
/* source address settings for outgoing connections */
319
enum {
320
  /* Tproxy exclusive values from 0 to 7 */
321
  CO_SRC_TPROXY_ADDR = 0x0001,    /* bind to this non-local address when connecting */
322
  CO_SRC_TPROXY_CIP  = 0x0002,    /* bind to the client's IP address when connecting */
323
  CO_SRC_TPROXY_CLI  = 0x0003,    /* bind to the client's IP+port when connecting */
324
  CO_SRC_TPROXY_DYN  = 0x0004,    /* bind to a dynamically computed non-local address */
325
  CO_SRC_TPROXY_MASK = 0x0007,    /* bind to a non-local address when connecting */
326
327
  CO_SRC_BIND        = 0x0008,    /* bind to a specific source address when connecting */
328
};
329
330
/* flags that can be passed to xprt->rcv_buf() and mux->rcv_buf() */
331
enum {
332
  CO_RFL_BUF_WET       = 0x0001,    /* Buffer still has some output data present */
333
  CO_RFL_BUF_FLUSH     = 0x0002,    /* Flush mux's buffers but don't read more data */
334
  CO_RFL_READ_ONCE     = 0x0004,    /* don't loop even if the request/response is small */
335
  CO_RFL_KEEP_RECV     = 0x0008,    /* Instruct the mux to still wait for read events  */
336
  CO_RFL_BUF_NOT_STUCK = 0x0010,    /* Buffer is not stuck. Optims are possible during data copy */
337
  CO_RFL_MAY_SPLICE    = 0x0020,    /* The producer can use the kernel splicing */
338
  CO_RFL_TRY_HARDER    = 0x0040,    /* Try to read till READ0 even on short reads */
339
};
340
341
/* flags that can be passed to xprt->snd_buf() and mux->snd_buf() */
342
enum {
343
  CO_SFL_MSG_MORE    = 0x0001,    /* More data to come afterwards */
344
  CO_SFL_STREAMER    = 0x0002,    /* Producer is continuously streaming data */
345
  CO_SFL_LAST_DATA   = 0x0003,    /* Sent data are the last ones, shutdown is pending */
346
};
347
348
/* known transport layers (for ease of lookup) */
349
enum {
350
  XPRT_RAW = 0,
351
  XPRT_SSL = 1,
352
  XPRT_HANDSHAKE = 2,
353
  XPRT_QUIC = 3,
354
  XPRT_QMUX = 4,
355
  XPRT_ENTRIES /* must be last one */
356
};
357
358
/* MUX-specific flags */
359
enum {
360
  MX_FL_NONE        = 0x00000000,
361
  MX_FL_HTX         = 0x00000001, /* set if it is an HTX multiplexer */
362
  MX_FL_HOL_RISK    = 0x00000002, /* set if the protocol is subject the to head-of-line blocking on server */
363
  MX_FL_NO_UPG      = 0x00000004, /* set if mux does not support any upgrade */
364
  MX_FL_FRAMED      = 0x00000008, /* mux working on top of a framed transport layer (QUIC) */
365
  MX_FL_REVERSABLE  = 0x00000010, /* mux supports connection reversal */
366
  MX_FL_EXPERIMENTAL = 0x00000020, /* requires experimental support directives */
367
};
368
369
/* PROTO token registration */
370
enum proto_proxy_mode {
371
  PROTO_MODE_NONE = 0,
372
  PROTO_MODE_TCP  = 1 << 0, // must not be changed!
373
  PROTO_MODE_HTTP = 1 << 1, // must not be changed!
374
  PROTO_MODE_SPOP = 1 << 2, // must not be changed!
375
  PROTO_MODE_ANY  = PROTO_MODE_TCP | PROTO_MODE_HTTP | PROTO_MODE_SPOP,
376
};
377
378
enum proto_proxy_side {
379
  PROTO_SIDE_NONE = 0,
380
  PROTO_SIDE_FE   = 1, // same as PR_CAP_FE
381
  PROTO_SIDE_BE   = 2, // same as PR_CAP_BE
382
  PROTO_SIDE_BOTH = PROTO_SIDE_FE | PROTO_SIDE_BE,
383
};
384
385
/* ctl command used by mux->ctl() */
386
enum mux_ctl_type {
387
  MUX_CTL_STATUS, /* Expects an int as output, sets it to a combination of MUX_CTL_STATUS flags */
388
  MUX_CTL_EXIT_STATUS, /* Expects an int as output, sets the mux exist/error/http status, if known or 0 */
389
  MUX_CTL_REVERSE_CONN, /* Notify about an active reverse connection accepted. */
390
  MUX_CTL_SUBS_RECV, /* Notify the mux it must wait for read events again  */
391
  MUX_CTL_GET_GLITCHES, /* returns number of glitches on the connection */
392
  MUX_CTL_GET_NBSTRM, /* Return the current number of streams on the connection */
393
  MUX_CTL_GET_MAXSTRM, /* Return the max number of streams supported by the connection */
394
  MUX_CTL_TEVTS, /* Return the termination events log of the mux connection */
395
};
396
397
/* sctl command used by mux->sctl() */
398
enum mux_sctl_type {
399
  MUX_SCTL_SID, /* Return the mux stream ID as output, as a signed 64bits integer */
400
  MUX_SCTL_DBG_STR,    /* takes a mux_sctl_dbg_str_ctx argument, reads flags and returns debug info */
401
  MUX_SCTL_TEVTS, /* Return the termination events log of the mux stream */
402
};
403
404
0
#define MUX_SCTL_DBG_STR_L_MUXS  0x00000001  // info from mux stream
405
0
#define MUX_SCTL_DBG_STR_L_MUXC  0x00000002  // info from mux connection
406
#define MUX_SCTL_DBG_STR_L_XPRT  0x00000004  // info from xprt layer
407
0
#define MUX_SCTL_DBG_STR_L_CONN  0x00000008  // info from struct connection layer
408
#define MUX_SCTL_DBG_STR_L_SOCK  0x00000010  // info from socket layer (quic_conn as well)
409
410
411
/* response for ctl MUX_STATUS */
412
0
#define MUX_STATUS_READY (1 << 0)
413
414
enum mux_exit_status {
415
  MUX_ES_SUCCESS,      /* Success */
416
  MUX_ES_INVALID_ERR,  /* invalid input */
417
  MUX_ES_TOUT_ERR,     /* timeout */
418
  MUX_ES_NOTIMPL_ERR,  /* not-implemented error */
419
  MUX_ES_INTERNAL_ERR, /* internal error */
420
  MUX_ES_UNKNOWN       /* unknown status (must be the last) */
421
};
422
423
/* socks4 response length */
424
0
#define SOCKS4_HS_RSP_LEN 8
425
426
/* socks4 upstream proxy definitions */
427
struct socks4_request {
428
  uint8_t version;  /* SOCKS version number, 1 byte, must be 0x04 for this version */
429
  uint8_t command;  /* 0x01 = establish a TCP/IP stream connection */
430
  uint16_t port;    /* port number, 2 bytes (in network byte order) */
431
  uint32_t ip;    /* IP address, 4 bytes (in network byte order) */
432
  char user_id[8];  /* the user ID string, variable length, terminated with a null (0x00); Using "HAProxy\0" */
433
};
434
435
/* A connection handle is how we differentiate two connections on the lower
436
 * layers. It usually is a file descriptor but can be a connection id. The
437
 * CO_FL_FDLESS flag indicates which one is relevant.
438
 */
439
union conn_handle {
440
  struct quic_conn *qc;   /* Only present if this connection is a QUIC one (CO_FL_FDLESS=1) */
441
  int fd;                 /* file descriptor, for regular sockets (CO_FL_FDLESS=0) */
442
};
443
444
enum xprt_capabilities {
445
  XPRT_CAN_SPLICE,
446
};
447
448
enum xprt_splice_cap {
449
  XPRT_CONN_CAN_NOT_SPLICE, /* This connection can't, and won't ever be able to splice */
450
  XPRT_CONN_COULD_SPLICE, /* This connection can't splice, but may later */
451
  XPRT_CONN_CAN_SPLICE /* This connection can splice */
452
};
453
454
/* xprt_ops describes transport-layer operations for a connection. They
455
 * generally run over a socket-based control layer, but not always. Some
456
 * of them are used for data transfer with the upper layer (rcv_*, snd_*)
457
 * and the other ones are used to setup and release the transport layer.
458
 */
459
struct xprt_ops {
460
  size_t (*rcv_buf)(struct connection *conn, void *xprt_ctx, struct buffer *buf, size_t count, void *msg_control, size_t *msg_controllen, int flags); /* recv callback */
461
  size_t (*snd_buf)(struct connection *conn, void *xprt_ctx, const struct buffer *buf, size_t count, void *msg_control, size_t msg_controllen, int flags); /* send callback */
462
  int  (*rcv_pipe)(struct connection *conn, void *xprt_ctx, struct pipe *pipe, unsigned int count); /* recv-to-pipe callback */
463
  int  (*snd_pipe)(struct connection *conn, void *xprt_ctx, struct pipe *pipe, unsigned int count); /* send-to-pipe callback */
464
  void (*shutr)(struct connection *conn, void *xprt_ctx, int);    /* shutr function */
465
  void (*shutw)(struct connection *conn, void *xprt_ctx, int);    /* shutw function */
466
  void (*close)(struct connection *conn, void *xprt_ctx);         /* close the transport layer */
467
  int  (*init)(struct connection *conn, void **ctx);      /* initialize the transport layer */
468
  int  (*start)(struct connection *conn, void *ctx);      /* Start the transport layer, if needed */
469
  int  (*prepare_bind_conf)(struct bind_conf *conf); /* prepare a whole bind_conf */
470
  void (*destroy_bind_conf)(struct bind_conf *conf); /* destroy a whole bind_conf */
471
  int  (*prepare_srv)(struct server *srv);    /* prepare a server context */
472
  void (*destroy_srv)(struct server *srv);    /* destroy a server context */
473
  int  (*get_alpn)(const struct connection *conn, void *xprt_ctx, const char **str, int *len); /* get application layer name */
474
  int (*takeover)(struct connection *conn, void *xprt_ctx, int orig_tid, int release); /* Let the xprt know the fd have been taken over */
475
  void (*set_idle)(struct connection *conn, void *xprt_ctx); /* notify the xprt that the connection becomes idle. implies set_used. */
476
  void (*set_used)(struct connection *conn, void *xprt_ctx); /* notify the xprt that the connection leaves idle. implies set_idle. */
477
  char name[8];                               /* transport layer name, zero-terminated */
478
  int (*subscribe)(struct connection *conn, void *xprt_ctx, int event_type, struct wait_event *es); /* Subscribe <es> to events, such as "being able to send" */
479
  int (*unsubscribe)(struct connection *conn, void *xprt_ctx, int event_type, struct wait_event *es); /* Unsubscribe <es> from events */
480
  int (*remove_xprt)(struct connection *conn, void *xprt_ctx, void *toremove_ctx, const struct xprt_ops *newops, void *newctx); /* Remove an xprt from the connection, used by temporary xprt such as the handshake one */
481
  int (*add_xprt)(struct connection *conn, void *xprt_ctx, void *toadd_ctx, const struct xprt_ops *toadd_ops, void **oldxprt_ctx, const struct xprt_ops **oldxprt_ops); /* Add a new XPRT as the new xprt, and return the old one */
482
  struct ssl_sock_ctx *(*get_ssl_sock_ctx)(struct connection *); /* retrieve the ssl_sock_ctx in use, or NULL if none */
483
  int (*show_fd)(struct buffer *, const struct connection *, const void *ctx); /* append some data about xprt for "show fd"; returns non-zero if suspicious */
484
  void (*dump_info)(struct buffer *, const struct connection *);
485
  /*
486
   * Returns the value for various capabilities.
487
   * Returns 0 if the capability is known, with the actual value in arg,
488
   * or -1 otherwise
489
   */
490
  int (*get_capability)(struct connection *connection, void *xprt_ctx, enum xprt_capabilities, void *arg);
491
};
492
493
/* mux_ops describes the mux operations, which are to be performed at the
494
 * connection level after data are exchanged with the transport layer in order
495
 * to propagate them to streams. The <init> function will automatically be
496
 * called once the mux is instantiated by the connection's owner at the end
497
 * of a transport handshake, when it is about to transfer data and the data
498
 * layer is not ready yet.
499
 */
500
struct mux_ops {
501
  int  (*init)(struct connection *conn, struct proxy *prx, struct session *sess, struct buffer *input);  /* early initialization */
502
  int  (*wake)(struct connection *conn);        /* mux-layer callback to report activity, mandatory */
503
  size_t (*rcv_buf)(struct stconn *sc, struct buffer *buf, size_t count, int flags); /* Called from the upper layer to get data */
504
  size_t (*snd_buf)(struct stconn *sc, struct buffer *buf, size_t count, int flags); /* Called from the upper layer to send data */
505
  size_t (*nego_fastfwd)(struct stconn *sc, struct buffer *input, size_t count, unsigned int may_splice); /* Callback to fill the SD iobuf */
506
  size_t (*done_fastfwd)(struct stconn *sc); /* Callback to terminate fast data forwarding */
507
  int (*fastfwd)(struct stconn *sc, unsigned int count, unsigned int flags); /* Callback to init fast data forwarding */
508
  int (*resume_fastfwd)(struct stconn *sc, unsigned int flags); /* Callback to resume fast data forwarding */
509
  void (*shut)(struct stconn *sc, unsigned int mode, struct se_abort_info *reason); /* shutdown function */
510
511
  int (*attach)(struct connection *conn, struct sedesc *, struct session *sess); /* attach a stconn to an outgoing connection */
512
  struct stconn *(*get_first_sc)(const struct connection *); /* retrieves any valid stconn from this connection */
513
  void (*detach)(struct sedesc *); /* Detach an stconn from the stdesc from an outgoing connection, when the request is done */
514
  int (*show_fd)(struct buffer *, struct connection *); /* append some data about connection into chunk for "show fd"; returns non-zero if suspicious */
515
  int (*show_sd)(struct buffer *, struct sedesc *, const char *pfx); /* append some data about the mux stream into chunk for "show sess"; returns non-zero if suspicious */
516
  int (*subscribe)(struct stconn *sc, int event_type,  struct wait_event *es); /* Subscribe <es> to events, such as "being able to send" */
517
  int (*unsubscribe)(struct stconn *sc, int event_type,  struct wait_event *es); /* Unsubscribe <es> from events */
518
  int (*sctl)(struct stconn *sc, enum mux_sctl_type mux_sctl, void *arg); /* Provides information about the mux stream */
519
  int (*avail_streams)(struct connection *conn); /* Returns the number of streams still available for a connection */
520
  int (*used_streams)(struct connection *conn);  /* Returns the number of streams in use on a connection. */
521
  void (*destroy)(void *ctx); /* Let the mux know one of its users left, so it may have to disappear */
522
  int (*ctl)(struct connection *conn, enum mux_ctl_type mux_ctl, void *arg); /* Provides information about the mux connection */
523
524
  /* Attempts to migrate <conn> from <orig_tid> to the current thread. If
525
   * <release> is true, it will be destroyed immediately after by caller.
526
   */
527
  int (*takeover)(struct connection *conn, int orig_tid, int release);
528
529
  unsigned int flags;                           /* some flags characterizing the mux's capabilities (MX_FL_*) */
530
  char name[8];                                 /* mux layer name, zero-terminated */
531
};
532
533
/* list of frontend connections. Used to call mux wake operation on soft-stop
534
 * to close idling connections.
535
 */
536
struct mux_stopping_data {
537
  struct list list; /* list of registered frontend connections */
538
  struct task *task; /* task woken up on soft-stop */
539
};
540
541
struct my_tcphdr {
542
  uint16_t source;
543
  uint16_t dest;
544
};
545
546
/* a connection source profile defines all the parameters needed to properly
547
 * bind an outgoing connection for a server or proxy.
548
 */
549
struct conn_src {
550
  unsigned int opts;                   /* CO_SRC_* */
551
  int iface_len;                       /* bind interface name length */
552
  char *iface_name;                    /* bind interface name or NULL */
553
  struct port_range *sport_range;      /* optional per-server TCP source ports */
554
  struct sockaddr_storage source_addr; /* the address to which we want to bind for connect() */
555
#if defined(CONFIG_HAP_TRANSPARENT)
556
  struct sockaddr_storage tproxy_addr; /* non-local address we want to bind to for connect() */
557
  char *bind_hdr_name;                 /* bind to this header name if defined */
558
  int bind_hdr_len;                    /* length of the name of the header above */
559
  int bind_hdr_occ;                    /* occurrence number of header above: >0 = from first, <0 = from end, 0=disabled */
560
#endif
561
};
562
563
/* Hash header flag reflecting the input parameters present
564
 * CAUTION! Always update CONN_HASH_PARAMS_TYPE_COUNT when adding a new entry.
565
 */
566
enum conn_hash_params_t {
567
  CONN_HASH_PARAMS_TYPE_NAME     = 0x1,
568
  CONN_HASH_PARAMS_TYPE_DST_ADDR = 0x2,
569
  CONN_HASH_PARAMS_TYPE_DST_PORT = 0x4,
570
  CONN_HASH_PARAMS_TYPE_SRC_ADDR = 0x8,
571
  CONN_HASH_PARAMS_TYPE_SRC_PORT = 0x10,
572
  CONN_HASH_PARAMS_TYPE_PROXY    = 0x20,
573
  CONN_HASH_PARAMS_TYPE_MARK_TOS = 0x40,
574
};
575
0
#define CONN_HASH_PARAMS_TYPE_COUNT 7
576
577
#define CONN_HASH_PAYLOAD_LEN \
578
0
  (((sizeof(((struct conn_hash_node *)0)->key)) * 8) - CONN_HASH_PARAMS_TYPE_COUNT)
579
580
#define CONN_HASH_GET_PAYLOAD(hash) \
581
0
  (((hash) << CONN_HASH_PARAMS_TYPE_COUNT) >> CONN_HASH_PARAMS_TYPE_COUNT)
582
583
/* To avoid overflow, dynamically sized parameters must be pre-hashed. Their
584
 * hashed will then be reused as input for the generation of the final
585
 * connection hash.
586
 */
587
struct conn_hash_params {
588
  uint64_t name_prehash;
589
  uint64_t proxy_prehash;
590
  uint64_t mark_tos_prehash;
591
  void *target;
592
  struct sockaddr_storage *src_addr;
593
  struct sockaddr_storage *dst_addr;
594
};
595
596
/*
597
 * This structure describes an TLV entry consisting of its type
598
 * and corresponding payload. This can be used to construct a list
599
 * from which arbitrary TLV payloads can be fetched.
600
 * It might be possible to embed the 'tlv struct' here in the future.
601
 */
602
struct conn_tlv_list {
603
  struct list list;
604
  unsigned short len; // 65535 should be more than enough!
605
  unsigned char type;
606
  char value[0];
607
} __attribute__((packed));
608
609
610
/* node for backend connection in the idle trees for http-reuse
611
 * A connection is identified by a hash generated from its specific parameters
612
 */
613
struct conn_hash_node {
614
  struct ceb_node node;    /* indexes the hashing key for safe/idle/avail */
615
  uint64_t key;            /* the hashing key, also used by session-owned */
616
};
617
618
/* This structure describes a connection with its methods and data.
619
 * A connection may be performed to proxy or server via a local or remote
620
 * socket, and can also be made to an internal applet. It can support
621
 * several transport schemes (raw, ssl, ...). It can support several
622
 * connection control schemes, generally a protocol for socket-oriented
623
 * connections, but other methods for applets.
624
 */
625
struct connection {
626
  /* first cache line */
627
  enum obj_type obj_type;       /* differentiates connection from applet context */
628
  unsigned char err_code;       /* CO_ER_* */
629
  signed short send_proxy_ofs;  /* <0 = offset to (re)send from the end, >0 = send all (reused for SOCKS4) */
630
  unsigned int flags;           /* CO_FL_* */
631
  const struct protocol *ctrl;  /* operations at the socket layer */
632
  const struct xprt_ops *xprt;  /* operations at the transport layer */
633
  const struct mux_ops  *mux;   /* mux layer operations. Must be set before xprt->init() */
634
  void *xprt_ctx;               /* general purpose pointer, initialized to NULL */
635
  void *ctx;                    /* highest level context (usually the mux), initialized to NULL */
636
  void *owner;                  /* pointer to the owner session, or NULL */
637
  enum obj_type *target;        /* the target to connect to (server, proxy, applet, ...) */
638
639
  /* second cache line */
640
  struct wait_event *subs; /* Task to wake when awaited events are ready */
641
  union {
642
    /* Backend connections only */
643
    struct {
644
      struct mt_list toremove_list; /* list element when idle connection is ready to be purged */
645
      struct list    idle_list;     /* list element for idle connection in server idle list */
646
      struct list    sess_el;       /* used by private connections, list elem into session */
647
    };
648
    /* Frontend connections only */
649
    struct list stopping_list; /* attach point in mux stopping list */
650
  };
651
  union conn_handle handle;     /* connection handle at the socket layer */
652
  const struct netns_entry *proxy_netns;
653
654
  /* third cache line and beyond */
655
  void (*destroy_cb)(struct connection *conn);  /* callback to notify of imminent death of the connection */
656
  struct sockaddr_storage *src; /* source address (pool), when known, otherwise NULL */
657
  struct sockaddr_storage *dst; /* destination address (pool), when known, otherwise NULL */
658
  struct list tlv_list;         /* list of TLVs received via PROXYv2 */
659
660
  /* used to identify a backend connection for http-reuse,
661
   * thus only present if conn.target is of type OBJ_TYPE_SERVER
662
   */
663
  struct conn_hash_node hash_node;
664
665
  /* Members used if connection must be reversed. */
666
  struct {
667
    enum obj_type *target; /* Listener for active reverse, server for passive. */
668
    struct buffer name;    /* Only used for passive reverse. Used as SNI when connection added to server idle pool. */
669
  } reverse;
670
671
  uint64_t sni_hash;             /* Hash of the SNI. Used to cache the TLS session and try to reuse it. set to 0 is there is no SNI */
672
  uint32_t term_evts_log;        /* Termination events log: first 4 events reported from fd, handshake or xprt */
673
  uint32_t mark;                 /* set network mark, if CO_FL_OPT_MARK is set */
674
  uint8_t tos;                   /* set ip tos, if CO_FL_OPT_TOS is set */
675
};
676
677
struct mux_proto_list {
678
  const struct ist mux_proto;    /* Mux protocol, to be used with the "proto" directive */
679
  enum proto_proxy_mode mode;
680
  enum proto_proxy_side side;
681
  const struct mux_ops *mux;
682
  const char *alpn;          /* Default alpn to set by default when the mux protocol is forced (optional, in binary form) */
683
  int init_xprt;
684
  struct list list;
685
};
686
687
/* proxy protocol stuff below */
688
689
/* proxy protocol v2 definitions */
690
0
#define PP2_SIGNATURE        "\x0D\x0A\x0D\x0A\x00\x0D\x0A\x51\x55\x49\x54\x0A"
691
0
#define PP2_SIGNATURE_LEN    12
692
0
#define PP2_HEADER_LEN       16
693
694
/* ver_cmd byte */
695
0
#define PP2_CMD_LOCAL        0x00
696
0
#define PP2_CMD_PROXY        0x01
697
0
#define PP2_CMD_MASK         0x0F
698
699
0
#define PP2_VERSION          0x20
700
0
#define PP2_VERSION_MASK     0xF0
701
702
/* fam byte */
703
0
#define PP2_TRANS_UNSPEC     0x00
704
0
#define PP2_TRANS_STREAM     0x01
705
#define PP2_TRANS_DGRAM      0x02
706
#define PP2_TRANS_MASK       0x0F
707
708
0
#define PP2_FAM_UNSPEC       0x00
709
0
#define PP2_FAM_INET         0x10
710
0
#define PP2_FAM_INET6        0x20
711
#define PP2_FAM_UNIX         0x30
712
#define PP2_FAM_MASK         0xF0
713
714
0
#define PP2_ADDR_LEN_UNSPEC  (0)
715
0
#define PP2_ADDR_LEN_INET    (4 + 4 + 2 + 2)
716
0
#define PP2_ADDR_LEN_INET6   (16 + 16 + 2 + 2)
717
#define PP2_ADDR_LEN_UNIX    (108 + 108)
718
719
0
#define PP2_HDR_LEN_UNSPEC   (PP2_HEADER_LEN + PP2_ADDR_LEN_UNSPEC)
720
0
#define PP2_HDR_LEN_INET     (PP2_HEADER_LEN + PP2_ADDR_LEN_INET)
721
0
#define PP2_HDR_LEN_INET6    (PP2_HEADER_LEN + PP2_ADDR_LEN_INET6)
722
#define PP2_HDR_LEN_UNIX     (PP2_HEADER_LEN + PP2_ADDR_LEN_UNIX)
723
724
0
#define PP2_TYPE_ALPN           0x01
725
0
#define PP2_TYPE_AUTHORITY      0x02
726
0
#define PP2_TYPE_CRC32C         0x03
727
0
#define PP2_TYPE_NOOP           0x04
728
0
#define PP2_TYPE_UNIQUE_ID      0x05
729
0
#define PP2_TYPE_SSL            0x20
730
0
#define PP2_SUBTYPE_SSL_VERSION 0x21
731
0
#define PP2_SUBTYPE_SSL_CN      0x22
732
0
#define PP2_SUBTYPE_SSL_CIPHER  0x23
733
0
#define PP2_SUBTYPE_SSL_SIG_ALG 0x24
734
0
#define PP2_SUBTYPE_SSL_KEY_ALG 0x25
735
0
#define PP2_TYPE_NETNS          0x30
736
737
#define PP2_CLIENT_SSL           0x01
738
#define PP2_CLIENT_CERT_CONN     0x02
739
#define PP2_CLIENT_CERT_SESS     0x04
740
741
0
#define PP2_CRC32C_LEN 4 /* Length of a CRC32C TLV value */
742
743
0
#define TLV_HEADER_SIZE 3
744
745
0
#define HA_PP2_AUTHORITY_MAX 255  /* Maximum length of an authority TLV */
746
0
#define HA_PP2_TLV_VALUE_128 128  /* E.g., accommodate unique IDs (128 B) */
747
0
#define HA_PP2_TLV_VALUE_256 256  /* E.g., accommodate authority TLVs (currently, <= 255 B) */
748
#define HA_PP2_MAX_ALLOC     1024 /* Maximum TLV value for PPv2 to prevent DoS */
749
750
struct proxy_hdr_v2 {
751
  uint8_t sig[12];   /* hex 0D 0A 0D 0A 00 0D 0A 51 55 49 54 0A */
752
  uint8_t ver_cmd;   /* protocol version and command */
753
  uint8_t fam;       /* protocol family and transport */
754
  uint16_t len;      /* number of following bytes part of the header */
755
  union {
756
    struct {   /* for TCP/UDP over IPv4, len = 12 */
757
      uint32_t src_addr;
758
      uint32_t dst_addr;
759
      uint16_t src_port;
760
      uint16_t dst_port;
761
    } ip4;
762
    struct {   /* for TCP/UDP over IPv6, len = 36 */
763
      uint8_t  src_addr[16];
764
      uint8_t  dst_addr[16];
765
      uint16_t src_port;
766
      uint16_t dst_port;
767
    } ip6;
768
    struct {   /* for AF_UNIX sockets, len = 216 */
769
      uint8_t src_addr[108];
770
      uint8_t dst_addr[108];
771
    } unx;
772
  } addr;
773
};
774
775
struct tlv {
776
  uint8_t type;
777
  uint8_t length_hi;
778
  uint8_t length_lo;
779
  uint8_t value[0]; // WT: don't use VAR_ARRAY here, it's an end of struct marker
780
}__attribute__((packed));
781
782
struct tlv_ssl {
783
  struct tlv tlv;
784
  uint8_t client;
785
  uint32_t verify;
786
  uint8_t sub_tlv[VAR_ARRAY];
787
}__attribute__((packed));
788
789
/* context for a MUX_SCTL_DBG_STR call */
790
union mux_sctl_dbg_str_ctx {
791
  struct {
792
    uint debug_flags; // union of MUX_SCTL_DBG_STR_L_*
793
  } arg; // sctl argument for the call
794
  struct {
795
    struct buffer buf;
796
  } ret; // sctl return contents
797
};
798
799
/* This structure is used to manage idle connections, their locking, and the
800
 * list of such idle connections to be removed. It is per-thread and must be
801
 * accessible from foreign threads.
802
 */
803
struct idle_conns {
804
  struct mt_list toremove_conns;
805
  struct task *cleanup_task;
806
  __decl_thread(HA_SPINLOCK_T idle_conns_lock);
807
} THREAD_ALIGNED();
808
809
810
/* Termination events logs:
811
 * Each event is stored on 8 bits: 4 bits bor the event location and
812
 * 4 bits for the event type.
813
 */
814
815
/* Locations for termination event logs (4-bits). But only 7 locations are
816
 * supported because 1 bit is reserved to distinguish frontend to backend
817
 * events: the msb is set to 1 for backend events.
818
 */
819
enum term_event_loc {
820
  tevt_loc_fd    = 1,
821
  tevt_loc_hs    = 2,
822
  tevt_loc_xprt  = 3,
823
  tevt_loc_muxc  = 4,
824
  tevt_loc_se    = 5,
825
  tevt_loc_strm  = 6,
826
};
827
828
/* Types for termination event logs (4-bits) per location */
829
enum fd_term_event_type {
830
  fd_tevt_type_shutw       = 1,
831
  fd_tevt_type_shutr       = 2,
832
  fd_tevt_type_rcv_err     = 3,
833
  fd_tevt_type_snd_err     = 4,
834
  /* unused: 5, 6 */
835
  fd_tevt_type_connect_err = 7,
836
  fd_tevt_type_intercepted = 8,
837
838
  fd_tevt_type_connect_poll_err  =  9,
839
  fd_tevt_type_poll_err          = 10,
840
  fd_tevt_type_poll_hup          = 11,
841
};
842
843
enum hs_term_event_type {
844
  /* unused: 1, 2, 3 */
845
  hs_tevt_type_snd_err           = 4,
846
  hs_tevt_type_truncated_shutr   = 5,
847
  hs_tevt_type_truncated_rcv_err = 6,
848
};
849
850
enum xprt_term_event_type {
851
  xprt_tevt_type_shutw   = 1,
852
  xprt_tevt_type_shutr   = 2,
853
  xprt_tevt_type_rcv_err = 3,
854
  xprt_tevt_type_snd_err = 4,
855
};
856
857
enum muxc_term_event_type {
858
  muxc_tevt_type_shutw            =  1,
859
  muxc_tevt_type_shutr            =  2,
860
  muxc_tevt_type_rcv_err          =  3,
861
  muxc_tevt_type_snd_err          =  4,
862
  muxc_tevt_type_truncated_shutr  =  5,
863
  muxc_tevt_type_truncated_rcv_err=  6,
864
865
  muxc_tevt_type_tout             =  7,
866
  muxc_tevt_type_goaway_rcvd      =  8,
867
  muxc_tevt_type_proto_err        =  9,
868
  muxc_tevt_type_internal_err     = 10,
869
  muxc_tevt_type_other_err        = 11,
870
  muxc_tevt_type_graceful_shut    = 12,
871
};
872
873
enum se_term_event_type {
874
  se_tevt_type_shutw            =  1,
875
  se_tevt_type_eos              =  2,
876
  se_tevt_type_rcv_err          =  3,
877
  se_tevt_type_snd_err          =  4,
878
  se_tevt_type_truncated_eos    =  5,
879
  se_tevt_type_truncated_rcv_err=  6,
880
  /* unused: 7 */
881
  se_tevt_type_rst_rcvd         =  8,
882
  se_tevt_type_proto_err        =  9,
883
  se_tevt_type_internal_err     = 10,
884
  se_tevt_type_other_err        = 11,
885
  se_tevt_type_cancelled        = 12,
886
};
887
888
enum strm_term_event_type {
889
  strm_tevt_type_shutw            =  1,
890
  strm_tevt_type_eos              =  2,
891
  strm_tevt_type_rcv_err          =  3,
892
  strm_tevt_type_snd_err          =  4,
893
  strm_tevt_type_truncated_eos    =  5,
894
  strm_tevt_type_truncated_rcv_err=  6,
895
896
  strm_tevt_type_tout             =  7,
897
  strm_tevt_type_intercepted      =  8,
898
899
  strm_tevt_type_proto_err        =  9,
900
  strm_tevt_type_internal_err     = 10,
901
  strm_tevt_type_other_err        = 11,
902
  strm_tevt_type_aborted          = 12,
903
};
904
905
#endif /* _HAPROXY_CONNECTION_T_H */
906
907
/*
908
 * Local variables:
909
 *  c-indent-level: 8
910
 *  c-basic-offset: 8
911
 * End:
912
 */