Eric Salama | 8a9c6c2 | 2017-11-10 11:02:23 +0100 | [diff] [blame] | 1 | /* |
| 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 | |
Eric Salama | 8a9c6c2 | 2017-11-10 11:02:23 +0100 | [diff] [blame] | 66 | /* All supported SPOE actions */ |
| 67 | enum spoe_action_type { |
| 68 | SPOE_ACT_T_SET_VAR = 1, |
| 69 | SPOE_ACT_T_UNSET_VAR, |
| 70 | SPOE_ACT_TYPES, |
| 71 | }; |
| 72 | |
| 73 | /* All supported SPOE events */ |
| 74 | enum spoe_event { |
| 75 | SPOE_EV_NONE = 0, |
| 76 | |
| 77 | /* Request events */ |
| 78 | SPOE_EV_ON_CLIENT_SESS = 1, |
| 79 | SPOE_EV_ON_TCP_REQ_FE, |
| 80 | SPOE_EV_ON_TCP_REQ_BE, |
| 81 | SPOE_EV_ON_HTTP_REQ_FE, |
| 82 | SPOE_EV_ON_HTTP_REQ_BE, |
| 83 | |
| 84 | /* Response events */ |
| 85 | SPOE_EV_ON_SERVER_SESS, |
| 86 | SPOE_EV_ON_TCP_RSP, |
| 87 | SPOE_EV_ON_HTTP_RSP, |
| 88 | |
| 89 | SPOE_EV_EVENTS |
| 90 | }; |
| 91 | |
| 92 | /* Errors triggered by streams */ |
| 93 | enum spoe_context_error { |
| 94 | SPOE_CTX_ERR_NONE = 0, |
| 95 | SPOE_CTX_ERR_TOUT, |
| 96 | SPOE_CTX_ERR_RES, |
| 97 | SPOE_CTX_ERR_TOO_BIG, |
| 98 | SPOE_CTX_ERR_FRAG_FRAME_ABRT, |
| 99 | SPOE_CTX_ERR_UNKNOWN = 255, |
| 100 | SPOE_CTX_ERRS, |
| 101 | }; |
| 102 | |
Ilya Shipitsin | ce7b00f | 2020-03-23 22:28:40 +0500 | [diff] [blame] | 103 | /* Errors triggered by SPOE applet */ |
Eric Salama | 8a9c6c2 | 2017-11-10 11:02:23 +0100 | [diff] [blame] | 104 | enum spoe_frame_error { |
| 105 | SPOE_FRM_ERR_NONE = 0, |
| 106 | SPOE_FRM_ERR_IO, |
| 107 | SPOE_FRM_ERR_TOUT, |
| 108 | SPOE_FRM_ERR_TOO_BIG, |
| 109 | SPOE_FRM_ERR_INVALID, |
| 110 | SPOE_FRM_ERR_NO_VSN, |
| 111 | SPOE_FRM_ERR_NO_FRAME_SIZE, |
| 112 | SPOE_FRM_ERR_NO_CAP, |
| 113 | SPOE_FRM_ERR_BAD_VSN, |
| 114 | SPOE_FRM_ERR_BAD_FRAME_SIZE, |
| 115 | SPOE_FRM_ERR_FRAG_NOT_SUPPORTED, |
| 116 | SPOE_FRM_ERR_INTERLACED_FRAMES, |
| 117 | SPOE_FRM_ERR_FRAMEID_NOTFOUND, |
| 118 | SPOE_FRM_ERR_RES, |
| 119 | SPOE_FRM_ERR_UNKNOWN = 99, |
| 120 | SPOE_FRM_ERRS, |
| 121 | }; |
| 122 | |
| 123 | /* Scopes used for variables set by agents. It is a way to be agnotic to vars |
| 124 | * scope. */ |
| 125 | enum spoe_vars_scope { |
| 126 | SPOE_SCOPE_PROC = 0, /* <=> SCOPE_PROC */ |
| 127 | SPOE_SCOPE_SESS, /* <=> SCOPE_SESS */ |
| 128 | SPOE_SCOPE_TXN, /* <=> SCOPE_TXN */ |
| 129 | SPOE_SCOPE_REQ, /* <=> SCOPE_REQ */ |
| 130 | SPOE_SCOPE_RES, /* <=> SCOPE_RES */ |
| 131 | }; |
| 132 | |
| 133 | |
| 134 | /* Describe an argument that will be linked to a message. It is a sample fetch, |
| 135 | * with an optional name. */ |
| 136 | struct spoe_arg { |
| 137 | char *name; /* Name of the argument, may be NULL */ |
| 138 | unsigned int name_len; /* The name length, 0 if NULL */ |
| 139 | struct sample_expr *expr; /* Sample expression */ |
| 140 | struct list list; /* Used to chain SPOE args */ |
| 141 | }; |
| 142 | |
| 143 | /* Used during the config parsing only because, when a SPOE agent section is |
| 144 | * parsed, messages can be undefined. */ |
| 145 | struct spoe_msg_placeholder { |
| 146 | char *id; /* SPOE message placeholder id */ |
| 147 | struct list list; /* Use to chain SPOE message placeholders */ |
| 148 | }; |
| 149 | |
| 150 | /* Describe a message that will be sent in a NOTIFY frame. A message has a name, |
| 151 | * an argument list (see above) and it is linked to a specific event. */ |
| 152 | struct spoe_message { |
| 153 | char *id; /* SPOE message id */ |
| 154 | unsigned int id_len; /* The message id length */ |
| 155 | struct spoe_agent *agent; /* SPOE agent owning this SPOE message */ |
| 156 | struct { |
| 157 | char *file; /* file where the SPOE message appears */ |
| 158 | int line; /* line where the SPOE message appears */ |
| 159 | } conf; /* config information */ |
| 160 | unsigned int nargs; /* # of arguments */ |
| 161 | struct list args; /* Arguments added when the SPOE messages is sent */ |
| 162 | struct list list; /* Used to chain SPOE messages */ |
| 163 | |
| 164 | enum spoe_event event; /* SPOE_EV_* */ |
| 165 | }; |
| 166 | |
| 167 | enum spoe_frame_type { |
| 168 | SPOE_FRM_T_UNSET = 0, |
| 169 | |
| 170 | /* Frames sent by HAProxy */ |
| 171 | SPOE_FRM_T_HAPROXY_HELLO = 1, |
| 172 | SPOE_FRM_T_HAPROXY_DISCON, |
| 173 | SPOE_FRM_T_HAPROXY_NOTIFY, |
| 174 | |
| 175 | /* Frames sent by the agents */ |
| 176 | SPOE_FRM_T_AGENT_HELLO = 101, |
| 177 | SPOE_FRM_T_AGENT_DISCON, |
| 178 | SPOE_FRM_T_AGENT_ACK |
| 179 | }; |
| 180 | |
| 181 | /* All supported data types */ |
| 182 | enum spoe_data_type { |
| 183 | SPOE_DATA_T_NULL = 0, |
| 184 | SPOE_DATA_T_BOOL, |
| 185 | SPOE_DATA_T_INT32, |
| 186 | SPOE_DATA_T_UINT32, |
| 187 | SPOE_DATA_T_INT64, |
| 188 | SPOE_DATA_T_UINT64, |
| 189 | SPOE_DATA_T_IPV4, |
| 190 | SPOE_DATA_T_IPV6, |
| 191 | SPOE_DATA_T_STR, |
| 192 | SPOE_DATA_T_BIN, |
| 193 | SPOE_DATA_TYPES |
| 194 | }; |
| 195 | |
Willy Tarreau | 75f4246 | 2017-11-14 15:01:22 +0100 | [diff] [blame] | 196 | /* a memory block of arbitrary size, or a string */ |
| 197 | struct chunk { |
| 198 | char *ptr; |
| 199 | size_t len; |
| 200 | }; |
| 201 | |
| 202 | /* all data types that may be encoded/decoded for each spoe_data_type */ |
| 203 | union spoe_data { |
| 204 | bool boolean; |
| 205 | int32_t int32; |
| 206 | uint32_t uint32; |
| 207 | int64_t int64; |
| 208 | uint64_t uint64; |
| 209 | struct in_addr ipv4; |
| 210 | struct in6_addr ipv6; |
| 211 | struct chunk chk; /* types STR and BIN */ |
| 212 | }; |
| 213 | |
Eric Salama | 8a9c6c2 | 2017-11-10 11:02:23 +0100 | [diff] [blame] | 214 | /* Masks to get data type or flags value */ |
| 215 | #define SPOE_DATA_T_MASK 0x0F |
| 216 | #define SPOE_DATA_FL_MASK 0xF0 |
| 217 | |
| 218 | /* Flags to set Boolean values */ |
| 219 | #define SPOE_DATA_FL_FALSE 0x00 |
| 220 | #define SPOE_DATA_FL_TRUE 0x10 |
| 221 | |
| 222 | |
| 223 | #endif /* _TYPES_SPOE_H */ |