blob: b5abf39919423a6027d9a157edba7ee5e994e4a1 [file] [log] [blame]
Eric Salama8a9c6c22017-11-10 11:02:23 +01001/*
2 * include/spoe_types.h
3 * Macros, variables and structures for the SPOE filter.
4 *
5 * Copyright (C) 2017 HAProxy Technologies, Christopher Faulet <cfaulet@haproxy.com>
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 _SPOE_TYPES_H
23#define _SPOE_TYPES_H
24
25#include <mini-clist.h>
26
27// Taken from HAProxy's defaults.h
28/* Maximum host name length */
29#ifndef MAX_HOSTNAME_LEN
30#if MAXHOSTNAMELEN
31#define MAX_HOSTNAME_LEN MAXHOSTNAMELEN
32#else
33#define MAX_HOSTNAME_LEN 64
34#endif // MAXHOSTNAMELEN
35#endif // MAX_HOSTNAME_LEN
36
37/* Flags set on the SPOE agent */
38#define SPOE_FL_CONT_ON_ERR 0x00000001 /* Do not stop events processing when an error occurred */
39#define SPOE_FL_PIPELINING 0x00000002 /* Set when SPOE agent supports pipelining (set by default) */
40#define SPOE_FL_ASYNC 0x00000004 /* Set when SPOE agent supports async (set by default) */
41#define SPOE_FL_SND_FRAGMENTATION 0x00000008 /* Set when SPOE agent supports sending fragmented payload */
42#define SPOE_FL_RCV_FRAGMENTATION 0x00000010 /* Set when SPOE agent supports receiving fragmented payload */
43
44/* Flags set on the SPOE context */
45#define SPOE_CTX_FL_CLI_CONNECTED 0x00000001 /* Set after that on-client-session event was processed */
46#define SPOE_CTX_FL_SRV_CONNECTED 0x00000002 /* Set after that on-server-session event was processed */
47#define SPOE_CTX_FL_REQ_PROCESS 0x00000004 /* Set when SPOE is processing the request */
48#define SPOE_CTX_FL_RSP_PROCESS 0x00000008 /* Set when SPOE is processing the response */
49#define SPOE_CTX_FL_FRAGMENTED 0x00000010 /* Set when a fragmented frame is processing */
50
51#define SPOE_CTX_FL_PROCESS (SPOE_CTX_FL_REQ_PROCESS|SPOE_CTX_FL_RSP_PROCESS)
52
53/* Flags set on the SPOE applet */
54#define SPOE_APPCTX_FL_PIPELINING 0x00000001 /* Set if pipelining is supported */
55#define SPOE_APPCTX_FL_ASYNC 0x00000002 /* Set if asynchronus frames is supported */
56#define SPOE_APPCTX_FL_FRAGMENTATION 0x00000004 /* Set if fragmentation is supported */
57#define SPOE_APPCTX_FL_PERSIST 0x00000008 /* Set if the applet is persistent */
58
59#define SPOE_APPCTX_ERR_NONE 0x00000000 /* no error yet, leave it to zero */
60#define SPOE_APPCTX_ERR_TOUT 0x00000001 /* SPOE applet timeout */
61
62/* Flags set on the SPOE frame */
63#define SPOE_FRM_FL_FIN 0x00000001
64#define SPOE_FRM_FL_ABRT 0x00000002
65
66/* All possible states for a SPOE context */
67enum spoe_ctx_state {
68 SPOE_CTX_ST_NONE = 0,
69 SPOE_CTX_ST_READY,
70 SPOE_CTX_ST_ENCODING_MSGS,
71 SPOE_CTX_ST_SENDING_MSGS,
72 SPOE_CTX_ST_WAITING_ACK,
73 SPOE_CTX_ST_DONE,
74 SPOE_CTX_ST_ERROR,
75};
76
77/* All possible states for a SPOE applet */
78enum spoe_appctx_state {
79 SPOE_APPCTX_ST_CONNECT = 0,
80 SPOE_APPCTX_ST_CONNECTING,
81 SPOE_APPCTX_ST_IDLE,
82 SPOE_APPCTX_ST_PROCESSING,
83 SPOE_APPCTX_ST_SENDING_FRAG_NOTIFY,
84 SPOE_APPCTX_ST_WAITING_SYNC_ACK,
85 SPOE_APPCTX_ST_DISCONNECT,
86 SPOE_APPCTX_ST_DISCONNECTING,
87 SPOE_APPCTX_ST_EXIT,
88 SPOE_APPCTX_ST_END,
89};
90
91/* All supported SPOE actions */
92enum spoe_action_type {
93 SPOE_ACT_T_SET_VAR = 1,
94 SPOE_ACT_T_UNSET_VAR,
95 SPOE_ACT_TYPES,
96};
97
98/* All supported SPOE events */
99enum spoe_event {
100 SPOE_EV_NONE = 0,
101
102 /* Request events */
103 SPOE_EV_ON_CLIENT_SESS = 1,
104 SPOE_EV_ON_TCP_REQ_FE,
105 SPOE_EV_ON_TCP_REQ_BE,
106 SPOE_EV_ON_HTTP_REQ_FE,
107 SPOE_EV_ON_HTTP_REQ_BE,
108
109 /* Response events */
110 SPOE_EV_ON_SERVER_SESS,
111 SPOE_EV_ON_TCP_RSP,
112 SPOE_EV_ON_HTTP_RSP,
113
114 SPOE_EV_EVENTS
115};
116
117/* Errors triggered by streams */
118enum spoe_context_error {
119 SPOE_CTX_ERR_NONE = 0,
120 SPOE_CTX_ERR_TOUT,
121 SPOE_CTX_ERR_RES,
122 SPOE_CTX_ERR_TOO_BIG,
123 SPOE_CTX_ERR_FRAG_FRAME_ABRT,
124 SPOE_CTX_ERR_UNKNOWN = 255,
125 SPOE_CTX_ERRS,
126};
127
128/* Errors triggerd by SPOE applet */
129enum spoe_frame_error {
130 SPOE_FRM_ERR_NONE = 0,
131 SPOE_FRM_ERR_IO,
132 SPOE_FRM_ERR_TOUT,
133 SPOE_FRM_ERR_TOO_BIG,
134 SPOE_FRM_ERR_INVALID,
135 SPOE_FRM_ERR_NO_VSN,
136 SPOE_FRM_ERR_NO_FRAME_SIZE,
137 SPOE_FRM_ERR_NO_CAP,
138 SPOE_FRM_ERR_BAD_VSN,
139 SPOE_FRM_ERR_BAD_FRAME_SIZE,
140 SPOE_FRM_ERR_FRAG_NOT_SUPPORTED,
141 SPOE_FRM_ERR_INTERLACED_FRAMES,
142 SPOE_FRM_ERR_FRAMEID_NOTFOUND,
143 SPOE_FRM_ERR_RES,
144 SPOE_FRM_ERR_UNKNOWN = 99,
145 SPOE_FRM_ERRS,
146};
147
148/* Scopes used for variables set by agents. It is a way to be agnotic to vars
149 * scope. */
150enum spoe_vars_scope {
151 SPOE_SCOPE_PROC = 0, /* <=> SCOPE_PROC */
152 SPOE_SCOPE_SESS, /* <=> SCOPE_SESS */
153 SPOE_SCOPE_TXN, /* <=> SCOPE_TXN */
154 SPOE_SCOPE_REQ, /* <=> SCOPE_REQ */
155 SPOE_SCOPE_RES, /* <=> SCOPE_RES */
156};
157
158
159/* Describe an argument that will be linked to a message. It is a sample fetch,
160 * with an optional name. */
161struct spoe_arg {
162 char *name; /* Name of the argument, may be NULL */
163 unsigned int name_len; /* The name length, 0 if NULL */
164 struct sample_expr *expr; /* Sample expression */
165 struct list list; /* Used to chain SPOE args */
166};
167
168/* Used during the config parsing only because, when a SPOE agent section is
169 * parsed, messages can be undefined. */
170struct spoe_msg_placeholder {
171 char *id; /* SPOE message placeholder id */
172 struct list list; /* Use to chain SPOE message placeholders */
173};
174
175/* Describe a message that will be sent in a NOTIFY frame. A message has a name,
176 * an argument list (see above) and it is linked to a specific event. */
177struct spoe_message {
178 char *id; /* SPOE message id */
179 unsigned int id_len; /* The message id length */
180 struct spoe_agent *agent; /* SPOE agent owning this SPOE message */
181 struct {
182 char *file; /* file where the SPOE message appears */
183 int line; /* line where the SPOE message appears */
184 } conf; /* config information */
185 unsigned int nargs; /* # of arguments */
186 struct list args; /* Arguments added when the SPOE messages is sent */
187 struct list list; /* Used to chain SPOE messages */
188
189 enum spoe_event event; /* SPOE_EV_* */
190};
191
192enum spoe_frame_type {
193 SPOE_FRM_T_UNSET = 0,
194
195 /* Frames sent by HAProxy */
196 SPOE_FRM_T_HAPROXY_HELLO = 1,
197 SPOE_FRM_T_HAPROXY_DISCON,
198 SPOE_FRM_T_HAPROXY_NOTIFY,
199
200 /* Frames sent by the agents */
201 SPOE_FRM_T_AGENT_HELLO = 101,
202 SPOE_FRM_T_AGENT_DISCON,
203 SPOE_FRM_T_AGENT_ACK
204};
205
206/* All supported data types */
207enum spoe_data_type {
208 SPOE_DATA_T_NULL = 0,
209 SPOE_DATA_T_BOOL,
210 SPOE_DATA_T_INT32,
211 SPOE_DATA_T_UINT32,
212 SPOE_DATA_T_INT64,
213 SPOE_DATA_T_UINT64,
214 SPOE_DATA_T_IPV4,
215 SPOE_DATA_T_IPV6,
216 SPOE_DATA_T_STR,
217 SPOE_DATA_T_BIN,
218 SPOE_DATA_TYPES
219};
220
221/* Masks to get data type or flags value */
222#define SPOE_DATA_T_MASK 0x0F
223#define SPOE_DATA_FL_MASK 0xF0
224
225/* Flags to set Boolean values */
226#define SPOE_DATA_FL_FALSE 0x00
227#define SPOE_DATA_FL_TRUE 0x10
228
229
230#endif /* _TYPES_SPOE_H */