blob: 7f38068876e9c825dbf0fea492713abf4d2af3e7 [file] [log] [blame]
Christopher Fauletf7e4e7e2016-10-27 22:29:49 +02001 -----------------------------------------------
2 Stream Processing Offload Engine (SPOE)
Christopher Faulet57583e42017-09-04 15:41:09 +02003 Version 1.2
4 ( Last update: 2017-09-22 )
Christopher Fauletf7e4e7e2016-10-27 22:29:49 +02005 -----------------------------------------------
6 Author : Christopher Faulet
7 Contact : cfaulet at haproxy dot com
8
9
10SUMMARY
11--------
12
13 0. Terms
14 1. Introduction
15 2. SPOE configuration
16 2.1. SPOE scope
17 2.2. "spoe-agent" section
18 2.3. "spoe-message" section
Christopher Faulet11610f32017-09-21 10:23:10 +020019 2.4. "spoe-group" section
20 2.5. Example
Christopher Fauletf7e4e7e2016-10-27 22:29:49 +020021 3. SPOP specification
22 3.1. Data types
23 3.2. Frames
24 3.2.1. Frame capabilities
25 3.2.2. Frame types overview
26 3.2.3. Workflow
27 3.2.4. Frame: HAPROXY-HELLO
28 3.2.5. Frame: AGENT-HELLO
29 3.2.6. Frame: NOTIFY
30 3.2.7. Frame: ACK
31 3.2.8. Frame: HAPROXY-DISCONNECT
32 3.2.9. Frame: AGENT-DISCONNECT
33 3.3. Events & messages
34 3.4. Actions
Christopher Fauletd1307ce2017-02-27 21:59:39 +010035 3.5. Errors & timeouts
Christopher Fauletf7e4e7e2016-10-27 22:29:49 +020036
37
380. Terms
39---------
40
41* SPOE : Stream Processing Offload Engine.
42
43 A SPOE is a filter talking to servers managed ba a SPOA to offload the
44 stream processing. An engine is attached to a proxy. A proxy can have
Christopher Fauletd1307ce2017-02-27 21:59:39 +010045 several engines. Each engine is linked to an agent and only one.
Christopher Fauletf7e4e7e2016-10-27 22:29:49 +020046
47* SPOA : Stream Processing Offload Agent.
48
49 A SPOA is a service that will receive info from a SPOE to offload the
50 stream processing. An agent manages several servers. It uses a backend to
51 reference all of them. By extension, these servers can also be called
52 agents.
53
54* SPOP : Stream Processing Offload Protocol, used by SPOEs to talk to SPOA
55 servers.
56
57 This protocol is used by engines to talk to agents. It is an in-house
58 binary protocol described in this documentation.
59
60
611. Introduction
62----------------
63
64SPOE is a feature introduced in HAProxy 1.7. It makes possible the
65communication with external components to retrieve some info. The idea started
66with the problems caused by most ldap libs not working fine in event-driven
67systems (often at least the connect() is blocking). So, it is hard to properly
68implement Single Sign On solution (SSO) in HAProxy. The SPOE will ease this
69kind of processing, or we hope so.
70
71Now, the aim of SPOE is to allow any kind of offloading on the streams. First
72releases, besides being experimental, won't do lot of things. As we will see,
73there are few handled events and even less actions supported. Actually, for
74now, the SPOE can offload the processing before "tcp-request content",
75"tcp-response content", "http-request" and "http-response" rules. And it only
76supports variables definition. But, in spite of these limited features, we can
77easily imagine to implement SSO solution, ip reputation or ip geolocation
78services.
79
80
812. SPOE configuration
82----------------------
83
84Because SPOE is implemented as a filter, To use it, you must declare a "filter
85spoe" line in a proxy section (frontend/backend/listen) :
86
87 frontend my-front
88 ...
89 filter spoe [engine <name>] config <file>
90 ...
91
92The "config" parameter is mandatory. It specififies the SPOE configuration
93file. The engine name is optional. It can be set to declare the scope to use in
94the SPOE configuration. So it is possible to use the same SPOE configuration
95for several engines. If no name is provided, the SPOE configuration must not
96contain any scope directive.
97
98We use a separate configuration file on purpose. By commenting SPOE filter
99line, you completly disable the feature, including the parsing of sections
100reserved to SPOE. This is also a way to keep the HAProxy configuration clean.
101
102A SPOE configuration file must contains, at least, the SPOA configuration
Christopher Faulet11610f32017-09-21 10:23:10 +0200103("spoe-agent" section) and SPOE messages/groups ("spoe-message" or "spoe-group"
104sections) attached to this agent.
Christopher Fauletf7e4e7e2016-10-27 22:29:49 +0200105
106IMPORTANT : The configuration of a SPOE filter must be located in a dedicated
107file. But the backend used by a SPOA must be declared in HAProxy configuration
108file.
109
1102.1. SPOE scope
111-------------------------
112
113If you specify an engine name on the SPOE filter line, then you need to define
114scope in the SPOE configuration with the same name. You can have several SPOE
115scope in the same file. In each scope, you must define one and only one
116"spoe-agent" section to configure the SPOA linked to your SPOE and several
Christopher Faulet11610f32017-09-21 10:23:10 +0200117"spoe-message" and "spoe-group" sections to describe, respecively, messages and
118group of messages sent to servers mananged by your SPOA.
Christopher Fauletf7e4e7e2016-10-27 22:29:49 +0200119
120A SPOE scope starts with this kind of line :
121
122 [<name>]
123
124where <name> is the same engine name specified on the SPOE filter line. The
125scope ends when the file ends or when another scope is found.
126
127 Example :
128 [my-first-engine]
129 spoe-agent my-agent
130 ...
131 spoe-message msg1
132 ...
133 spoe-message msg2
134 ...
Christopher Faulet11610f32017-09-21 10:23:10 +0200135 spoe-group grp1
136 ...
137 spoe-group grp2
138 ...
Christopher Fauletf7e4e7e2016-10-27 22:29:49 +0200139
140 [my-second-engine]
141 ...
142
143If no engine name is provided on the SPOE filter line, no SPOE scope must be
144found in the SPOE configuration file. All the file is considered to be in the
145same anonymous and implicit scope.
146
Christopher Faulet7ee86672017-09-19 11:08:28 +0200147The engine name must be uniq for a proxy. If no engine name is provided on the
148SPOE filter line, the SPOE agent name is unsed by default.
149
Christopher Fauletf7e4e7e2016-10-27 22:29:49 +02001502.2. "spoe-agent" section
151--------------------------
152
153For each engine, you must define one and only one "spoe-agent" section. In this
154section, you will declare SPOE messages and the backend you will use. You will
155also set timeouts and options to customize your agent's behaviour.
156
157
158spoe-agent <name>
159 Create a new SPOA with the name <name>. It must have one and only one
160 "spoe-agent" definition by SPOE scope.
161
162 Arguments :
163 <name> is the name of the agent section.
164
165 following keywords are supported :
Christopher Faulet11610f32017-09-21 10:23:10 +0200166 - groups
Christopher Faulet48026722016-11-16 15:01:12 +0100167 - maxconnrate
168 - maxerrrate
Christopher Fauletd1307ce2017-02-27 21:59:39 +0100169 - max-frame-size
Christopher Fauletf7e4e7e2016-10-27 22:29:49 +0200170 - messages
Christopher Fauletd1307ce2017-02-27 21:59:39 +0100171 - [no] option async
172 - [no] option pipelining
173 - [no] option send-frag-payload
Christopher Fauletea62c2a2016-11-14 10:54:21 +0100174 - option continue-on-error
Christopher Faulet985532d2016-11-16 15:36:19 +0100175 - option set-on-error
Christopher Fauletf7e4e7e2016-10-27 22:29:49 +0200176 - option var-prefix
Christopher Faulet03a34492016-11-19 16:47:56 +0100177 - timeout hello|idle|processing
Christopher Fauletf7e4e7e2016-10-27 22:29:49 +0200178 - use-backend
179
180
Christopher Faulet11610f32017-09-21 10:23:10 +0200181groups <grp-name> ...
182 Declare the list of SPOE groups that an agent will handle.
183
184 Arguments :
185 <grp-name> is the name of a SPOE group.
186
187 Groups delcared here must be found in the same engine scope, else an error is
188 triggered during the configuration parsing. You can have many "groups" lines.
189
190 See also: "spoe-group" section.
191
192
Christopher Faulet48026722016-11-16 15:01:12 +0100193maxconnrate <number>
194 Set the maximum number of connections per second to <number>. The SPOE will
195 stop to open new connections if the maximum is reached and will wait to
196 acquire an existing one. So it is important to set "timeout hello" to a
197 relatively small value.
198
199
200maxerrrate <number>
201 Set the maximum number of errors per second to <number>. The SPOE will stop
202 its processing if the maximum is reached.
203
204
Christopher Fauletd1307ce2017-02-27 21:59:39 +0100205max-frame-size <number>
206 Set the maximum allowed size for frames exchanged between HAProxy and SPOA.
207 It must be in the range [256, tune.bufsize-4] (4 bytes are reserved for the
208 frame length). By default, it is set to (tune.bufsize-4).
209
210
Christopher Fauletf7e4e7e2016-10-27 22:29:49 +0200211messages <msg-name> ...
212 Declare the list of SPOE messages that an agent will handle.
213
214 Arguments :
215 <msg-name> is the name of a SPOE message.
216
217 Messages declared here must be found in the same engine scope, else an error
218 is triggered during the configuration parsing. You can have many "messages"
219 lines.
220
221 See also: "spoe-message" section.
222
223
Christopher Fauletd1307ce2017-02-27 21:59:39 +0100224option async
225no option async
226 Enable or disable the support of asynchronus exchanges between HAProxy and
227 SPOA. By default, this option is enabled.
228
229
Christopher Fauletea62c2a2016-11-14 10:54:21 +0100230option continue-on-error
231 Do not stop the events processing when an error occurred on a stream.
232
233 By default, for a specific stream, when an abnormal/unexpected error occurs,
234 the SPOE is disabled for all the transaction. So if you have several events
235 configured, such error on an event will disabled all followings. For TCP
236 streams, this will disable the SPOE for the whole session. For HTTP streams,
237 this will disable it for the transaction (request and response).
238
239 When set, this option bypass this behaviour and only the current event will
240 be ignored.
241
242
Christopher Fauletd1307ce2017-02-27 21:59:39 +0100243option pipelining
244no option pipelining
245 Enable or disable the support of pipelined exchanges between HAProxy and
246 SPOA. By default, this option is enabled.
247
248
249option send-frag-payload
250no option send-frag-payload
251 Enable or disable the sending of fragmented payload to SPOA. By default, this
252 option is enabled.
253
254
Christopher Faulet985532d2016-11-16 15:36:19 +0100255option set-on-error <var name>
256 Define the variable to set when an error occurred during an event processing.
257
258 Arguments :
259
260 <var name> is the variable name, without the scope. The name may only
261 contain characters 'a-z', 'A-Z', '0-9', '.' and '_'.
262
263 This variable will only be set when an error occurred in the scope of the
264 transaction. As for all other variables define by the SPOE, it will be
265 prefixed. So, if your variable name is "error" and your prefix is
266 "my_spoe_pfx", the variable will be "txn.my_spoe_pfx.error".
267
Christopher Fauletb067b062017-01-04 16:39:11 +0100268 When set, the variable is an integer representing the error reason. For values
269 under 256, it represents an error coming from the engine. Below 256, it
270 reports a SPOP error. In this case, to retrieve the right SPOP status code,
271 you must remove 256 to this value. Here are possible values:
272
273 * 1 a timeout occurred during the event processing.
274
275 * 2 an error was triggered during the ressources allocation.
276
Christopher Fauletd1307ce2017-02-27 21:59:39 +0100277 * 3 the frame payload exceeds the frame size and it cannot be
278 fragmented.
279
280 * 4 the fragmentation of a payload is aborted.
281
Christopher Fauletb067b062017-01-04 16:39:11 +0100282 * 255 an unknown error occurred during the event processing.
283
284 * 256+N a SPOP error occurred during the event processing (see section
285 "Errors & timeouts").
286
287 Note that if "option continue-on-error" is set, the variable is not
288 automatically removed between events processing.
Christopher Faulet985532d2016-11-16 15:36:19 +0100289
290 See also: "option continue-on-error", "option var-prefix".
291
Christopher Fauletf7e4e7e2016-10-27 22:29:49 +0200292option var-prefix <prefix>
293 Define the prefix used when variables are set by an agent.
294
295 Arguments :
296
297 <prefix> is the prefix used to limit the scope of variables set by an
298 agent.
299
300 To avoid conflict with other variables defined by HAProxy, all variables
301 names will be prefixed. By default, the "spoe-agent" name is used. This
302 option can be used to customize it.
303
304 The prefix will be added between the variable scope and its name, separated
305 by a '.'. It may only contain characters 'a-z', 'A-Z', '0-9', '.' and '_', as
306 for variables name. In HAProxy configuration, you need to use this prefix as
307 a part of the variables name. For example, if an agent define the variable
308 "myvar" in the "txn" scope, with the prefix "my_spoe_pfx", then you should
309 use "txn.my_spoe_pfx.myvar" name in your HAProxy configuration.
310
311 An agent will never set new variables at runtime. It can only set new value
312 for existing ones.
313
314
Christopher Fauletf7e4e7e2016-10-27 22:29:49 +0200315timeout hello <timeout>
316 Set the maximum time to wait for an agent to receive the AGENT-HELLO frame.
Christopher Fauletf7a30922016-11-10 15:04:51 +0100317 It is applied on the stream that handle the connection with the agent.
Christopher Fauletf7e4e7e2016-10-27 22:29:49 +0200318
319 Arguments :
320 <timeout> is the timeout value specified in milliseconds by default, but
321 can be in any other unit if the number is suffixed by the unit,
322 as explained at the top of this document.
323
324 This timeout is an applicative timeout. It differ from "timeout connect"
325 defined on backends.
326
327
328timeout idle <timeout>
Christopher Fauletf7a30922016-11-10 15:04:51 +0100329 Set the maximum time to wait for an agent to close an idle connection. It is
330 applied on the stream that handle the connection with the agent.
331
332 Arguments :
333 <timeout> is the timeout value specified in milliseconds by default, but
334 can be in any other unit if the number is suffixed by the unit,
335 as explained at the top of this document.
336
337
338timeout processing <timeout>
339 Set the maximum time to wait for a stream to process an event, i.e to acquire
340 a stream to talk with an agent, to encode all messages, to send the NOTIFY
341 frame, to receive the corrsponding acknowledgement and to process all
342 actions. It is applied on the stream that handle the client and the server
343 sessions.
Christopher Fauletf7e4e7e2016-10-27 22:29:49 +0200344
345 Arguments :
346 <timeout> is the timeout value specified in milliseconds by default, but
347 can be in any other unit if the number is suffixed by the unit,
348 as explained at the top of this document.
349
350
351use-backend <backend>
352 Specify the backend to use. It must be defined.
353
354 Arguments :
355 <backend> is the name of a valid "backend" section.
356
357
3582.3. "spoe-message" section
359----------------------------
360
361To offload the stream processing, SPOE will send messages with specific
362information at a specific moment in the stream life and will wait for
363corresponding replies to know what to do.
364
365
366spoe-message <name>
367 Create a new SPOE message with the name <name>.
368
369 Arguments :
370 <name> is the name of the SPOE message.
371
372 Here you define a message that can be referenced in a "spoe-agent"
373 section. Following keywords are supported :
Christopher Faulet57583e42017-09-04 15:41:09 +0200374 - acl
Christopher Fauletf7e4e7e2016-10-27 22:29:49 +0200375 - args
376 - event
377
378 See also: "spoe-agent" section.
379
380
Christopher Faulet57583e42017-09-04 15:41:09 +0200381acl <aclname> <criterion> [flags] [operator] <value> ...
382
383 Declare or complete an access list.
384
385 See section 7 about ACL usage in the HAProxy Configuration Manual.
386
387
Christopher Fauletf7e4e7e2016-10-27 22:29:49 +0200388args [name=]<sample> ...
389 Define arguments passed into the SPOE message.
390
391 Arguments :
392 <sample> is a sample expression.
393
394 When the message is processed, if a sample expression is not available, it is
395 set to NULL. Arguments are processed in their declaration order and added in
396 the message in that order. It is possible to declare named arguements.
397
398 For example:
399 args frontend=fe_id src dst
400
401
Christopher Faulet57583e42017-09-04 15:41:09 +0200402event <name> [ { if | unless } <condition> ]
403 Set the event that triggers sending of the message. It may optionally be
404 followed by an ACL-based condition, in which case it will only be evaluated
405 if the condition is true.
Christopher Fauletf7e4e7e2016-10-27 22:29:49 +0200406
Christopher Faulet57583e42017-09-04 15:41:09 +0200407 ACL-based conditions are executed in the context of the stream that handle
408 the client and the server connections.
409
410 Arguments :
411 <name> is the event name.
412 <condition> is a standard ACL-based condition.
Christopher Fauletf7e4e7e2016-10-27 22:29:49 +0200413
414 Supported events are:
415 - on-client-session
Christopher Faulet1002aac2016-12-09 17:41:54 +0100416 - on-server-session
Christopher Fauletf7e4e7e2016-10-27 22:29:49 +0200417 - on-frontend-tcp-request
418 - on-backend-tcp-request
419 - on-tcp-response
420 - on-frontend-http-request
421 - on-backend-http-request
422 - on-http-response
423
Christopher Faulet57583e42017-09-04 15:41:09 +0200424 See section "Events & Messages" for more details about supported events.
425 See section 7 about ACL usage in the HAProxy Configuration Manual.
Christopher Fauletf7e4e7e2016-10-27 22:29:49 +0200426
Christopher Faulet11610f32017-09-21 10:23:10 +02004272.4. "spoe-group" section
428--------------------------
429
430This section can be used to declare a group of SPOE messages. Unlike messages
431referenced in a "spoe-agent" section, messages inside a group are not sent on a
432specific event. The sending must be triggered by TCP or HTTP rules, from the
433HAProxy configuration.
434
435
436spoe-group <name>
437 Create a new SPOE group with the name <name>.
438
439 Arguments :
440 <name> is the name of the SPOE group.
441
442 Here you define a group of SPOE messages that can be referenced in a
443 "spoe-agent" section. Following keywords are supported :
444 - messages
445
446 See also: "spoe-agent" and "spoe-message" sections.
447
448
449messages <msg-name> ...
450 Declare the list of SPOE messages belonging to the group.
451
452 Arguments :
453 <msg-name> is the name of a SPOE message.
454
455 Messages declared here must be found in the same engine scope, else an error
456 is triggered during the configuration parsing. Furthermore, a message belongs
457 at most to a group. You can have many "messages" lines.
458
459 See also: "spoe-message" section.
460
461
4622.5. Example
Christopher Fauletf7e4e7e2016-10-27 22:29:49 +0200463-------------
464
465Here is a simple but complete example that sends client-ip address to a ip
466reputation service. This service can set the variable "ip_score" which is an
467integer between 0 and 100, indicating its reputation (100 means totally safe
468and 0 a blacklisted IP with no doubt).
469
470 ###
471 ### HAProxy configuration
472 frontend www
473 mode http
474 bind *:80
475
476 filter spoe engine ip-reputation config spoe-ip-reputation.conf
477
478 # Reject connection if the IP reputation is under 20
479 tcp-request content reject if { var(sess.iprep.ip_score) -m int lt 20 }
480
481 default_backend http-servers
482
483 backend http-servers
484 mode http
485 server http A.B.C.D:80
486
487 backend iprep-servers
488 mode tcp
489 balance roundrobin
490
491 timeout connect 5s # greater than hello timeout
492 timeout server 3m # greater than idle timeout
493
494 server iprep1 A1.B1.C1.D1:12345
495 server iprep2 A2.B2.C2.D2:12345
496
497 ####
498 ### spoe-ip-reputation.conf
499 [ip-reputation]
500
501 spoe-agent iprep-agent
502 messages get-ip-reputation
503
504 option var-prefix iprep
505
Christopher Faulet03a34492016-11-19 16:47:56 +0100506 timeout hello 2s
507 timeout idle 2m
508 timeout processing 10ms
Christopher Fauletf7e4e7e2016-10-27 22:29:49 +0200509
510 use-backend iprep-servers
511
512 spoe-message get-ip-reputation
513 args ip=src
Christopher Faulet57583e42017-09-04 15:41:09 +0200514 event on-client-session if ! { src -f /etc/haproxy/whitelist.lst }
Christopher Fauletf7e4e7e2016-10-27 22:29:49 +0200515
516
5173. SPOP specification
518----------------------
519
5203.1. Data types
521----------------
522
523Here is the bytewise representation of typed data:
524
525 TYPED-DATA : <TYPE:4 bits><FLAGS:4 bits><DATA>
526
527Supported types and their representation are:
528
529 TYPE | ID | DESCRIPTION
530 -----------------------------+-----+----------------------------------
531 NULL | 0 | NULL : <0>
532 Boolean | 1 | BOOL : <1+FLAG>
533 32bits signed integer | 2 | INT32 : <2><VALUE:varint>
534 32bits unsigned integer | 3 | UINT32 : <3><VALUE:varint>
535 64bits signed integer | 4 | INT64 : <4><VALUE:varint>
536 32bits unsigned integer | 5 | UNIT64 : <5><VALUE:varint>
537 IPV4 | 6 | IPV4 : <6><STRUCT IN_ADDR:4 bytes>
538 IPV6 | 7 | IPV6 : <7><STRUCT IN_ADDR6:16 bytes>
539 String | 8 | STRING : <8><LENGTH:varint><BYTES>
540 Binary | 9 | BINARY : <9><LENGTH:varint><BYTES>
541 10 -> 15 unused/reserved | - | -
542 -----------------------------+-----+----------------------------------
543
544Variable-length integer (varint) are encoded using Peers encoding:
545
546
547 0 <= X < 240 : 1 byte (7.875 bits) [ XXXX XXXX ]
548 240 <= X < 2288 : 2 bytes (11 bits) [ 1111 XXXX ] [ 0XXX XXXX ]
549 2288 <= X < 264432 : 3 bytes (18 bits) [ 1111 XXXX ] [ 1XXX XXXX ] [ 0XXX XXXX ]
550 264432 <= X < 33818864 : 4 bytes (25 bits) [ 1111 XXXX ] [ 1XXX XXXX ]*2 [ 0XXX XXXX ]
551 33818864 <= X < 4328786160 : 5 bytes (32 bits) [ 1111 XXXX ] [ 1XXX XXXX ]*3 [ 0XXX XXXX ]
552 ...
553
554For booleans, the value (true or false) is the first bit in the FLAGS
555bitfield. if this bit is set to 0, then the boolean is evaluated as false,
556otherwise, the boolean is evaluated as true.
557
5583.2. Frames
559------------
560
561Exchange between HAProxy and agents are made using FRAME packets. All frames
562must be prefixed with their size encoded on 4 bytes in network byte order:
563
564 <FRAME-LENGTH:4 bytes> <FRAME>
565
566A frame always starts with its type, on one byte, followed by metadata
567containing flags, on 4 bytes and a two variable-length integer representing the
568stream identifier and the frame identifier inside the stream:
569
570 FRAME : <FRAME-TYPE:1 byte> <METADATA> <FRAME-PAYLOAD>
571 METADATA : <FLAGS:4 bytes> <STREAM-ID:varint> <FRAME-ID:varint>
572
573Then comes the frame payload. Depending on the frame type, the payload can be
574of three types: a simple key/value list, a list of messages or a list of
575actions.
576
577 FRAME-PAYLOAD : <LIST-OF-MESSAGES> | <LIST-OF-ACTIONS> | <KV-LIST>
578
579 LIST-OF-MESSAGES : [ <MESSAGE-NAME> <NB-ARGS:1 byte> <KV-LIST> ... ]
580 MESSAGE-NAME : <STRING>
581
582 LIST-OF-ACTIONS : [ <ACTION-TYPE:1 byte> <NB-ARGS:1 byte> <ACTION-ARGS> ... ]
583 ACTION-ARGS : [ <TYPED-DATA>... ]
584
585 KV-LIST : [ <KV-NAME> <KV-VALUE> ... ]
586 KV-NAME : <STRING>
587 KV-VALUE : <TYPED-DATA>
588
Christopher Fauletd1307ce2017-02-27 21:59:39 +0100589 FLAGS : 0 1 2-31
590 +---+---+----------+
591 | | A | |
592 | F | B | |
593 | I | O | RESERVED |
594 | N | R | |
595 | | T | |
596 +---+---+----------+
Christopher Fauletf7e4e7e2016-10-27 22:29:49 +0200597
598 FIN: Indicates that this is the final payload fragment. The first fragment
599 may also be the final fragment.
600
Christopher Fauletd1307ce2017-02-27 21:59:39 +0100601 ABORT: Indicates that the processing of the current frame must be
602 cancelled. This bit should be set on frames with a fragmented
603 payload. It can be ignore for frames with an unfragemnted
604 payload. When it is set, the FIN bit must also be set.
605
606
Christopher Fauletf7e4e7e2016-10-27 22:29:49 +0200607Frames cannot exceed a maximum size negociated between HAProxy and agents
608during the HELLO handshake. Most of time, payload will be small enough to send
609it in one frame. But when supported by the peer, it will be possible to
610fragment huge payload on many frames. This ability is announced during the
611HELLO handshake and it can be asynmetric (supported by agents but not by
612HAProxy or the opposite). The following rules apply to fragmentation:
613
614 * An unfragemnted payload consists of a single frame with the FIN bit set.
615
616 * A fragemented payload consists of several frames with the FIN bit clear and
617 terminated by a single frame with the FIN bit set. All these frames must
Christopher Fauletd1307ce2017-02-27 21:59:39 +0100618 share the same STREAM-ID and FRAME-ID. The first frame must set the right
619 FRAME-TYPE (e.g, NOTIFY). The following frames must have an unset type (0).
Christopher Fauletf7e4e7e2016-10-27 22:29:49 +0200620
621Beside the support of fragmented payload by a peer, some payload must not be
622fragmented. See below for details.
623
Christopher Fauletd1307ce2017-02-27 21:59:39 +0100624IMPORTANT : The maximum size supported by peers for a frame must be greater
625than or equal to 256 bytes.
Christopher Fauletf7e4e7e2016-10-27 22:29:49 +0200626
6273.2.1. Frame capabilities
628--------------------------
629
630Here are the list of official capabilities that HAProxy and agents can support:
631
Christopher Fauleta1cda022016-12-21 08:58:06 +0100632 * fragmentation: This is the ability for a peer to support fragmented
633 payload in received frames. This is an asymmectical
634 capability, it only concerns the peer that announces
635 it. This is the responsibility to the other peer to use it
636 or not.
637
638 * pipelining: This is the ability for a peer to decouple NOTIFY and ACK
639 frames. This is a symmectical capability. To be used, it must
640 be supported by HAproxy and agents. Unlike HTTP pipelining, the
641 ACK frames can be send in any order, but always on the same TCP
642 connection used for the corresponding NOTIFY frame.
643
644 * async: This ability is similar to the pipelining, but here any TCP
645 connection established between HAProxy and the agent can be used to
646 send ACK frames. if an agent accepts connections from multiple
647 HAProxy, it can use the "engine-id" value to group TCP
648 connections. See details about HAPROXY-HELLO frame.
Christopher Fauletf7e4e7e2016-10-27 22:29:49 +0200649
650Unsupported or unknown capabilities are silently ignored, when possible.
651
6523.2.2. Frame types overview
653----------------------------
654
655Here are types of frame supported by SPOE. Frames sent by HAProxy come first,
656then frames sent by agents :
657
658 TYPE | ID | DESCRIPTION
659 -----------------------------+-----+-------------------------------------
Christopher Fauletd1307ce2017-02-27 21:59:39 +0100660 UNSET | 0 | Used for all frames but the first when a
661 | | payload is fragmented.
662 -----------------------------+-----+-------------------------------------
Christopher Fauletf7e4e7e2016-10-27 22:29:49 +0200663 HAPROXY-HELLO | 1 | Sent by HAProxy when it opens a
664 | | connection on an agent.
665 | |
666 HAPROXY-DISCONNECT | 2 | Sent by HAProxy when it want to close
667 | | the connection or in reply to an
668 | | AGENT-DISCONNECT frame
669 | |
670 NOTIFY | 3 | Sent by HAProxy to pass information
671 | | to an agent
672 -----------------------------+-----+-------------------------------------
673 AGENT-HELLO | 101 | Reply to a HAPROXY-HELLO frame, when
674 | | the connection is established
675 | |
676 AGENT-DISCONNECT | 102 | Sent by an agent just before closing
677 | | the connection
678 | |
679 ACK | 103 | Sent to acknowledge a NOTIFY frame
680 -----------------------------+-----+-------------------------------------
681
682Unknown frames may be silently skipped.
683
6843.2.3. Workflow
685----------------
686
687 * Successful HELLO handshake:
688
689 HAPROXY AGENT SRV
690 | HAPROXY-HELLO |
Christopher Fauletba7bc162016-11-07 21:07:38 +0100691 | (healthcheck: false) |
Christopher Fauletf7e4e7e2016-10-27 22:29:49 +0200692 | --------------------------> |
693 | |
694 | AGENT-HELLO |
695 | <-------------------------- |
696 | |
697
Christopher Fauletba7bc162016-11-07 21:07:38 +0100698 * Successful HELLO healthcheck:
699
700 HAPROXY AGENT SRV
701 | HAPROXY-HELLO |
702 | (healthcheck: true) |
703 | --------------------------> |
704 | |
705 | AGENT-HELLO + close() |
706 | <-------------------------- |
707 | |
708
Christopher Fauletf7e4e7e2016-10-27 22:29:49 +0200709
710 * Error encountered by agent during the HELLO handshake:
711
712 HAPROXY AGENT SRV
713 | HAPROXY-HELLO |
714 | --------------------------> |
715 | |
716 | DISCONNECT + close() |
717 | <-------------------------- |
718 | |
719
720 * Error encountered by HAProxy during the HELLO handshake:
721
722 HAPROXY AGENT SRV
723 | HAPROXY-HELLO |
724 | --------------------------> |
725 | |
726 | AGENT-HELLO |
727 | <-------------------------- |
728 | |
729 | DISCONNECT |
730 | --------------------------> |
731 | |
732 | DISCONNECT + close() |
733 | <-------------------------- |
734 | |
735
Christopher Fauletd1307ce2017-02-27 21:59:39 +0100736 * Notify / Ack exchange (unfragmented payload):
Christopher Fauletf7e4e7e2016-10-27 22:29:49 +0200737
738 HAPROXY AGENT SRV
739 | NOTIFY |
740 | --------------------------> |
741 | |
742 | ACK |
743 | <-------------------------- |
744 | |
745
Christopher Fauletd1307ce2017-02-27 21:59:39 +0100746 * Notify / Ack exchange (fragmented payload):
747
748 HAPROXY AGENT SRV
749 | NOTIFY (frag 1) |
750 | --------------------------> |
751 | |
752 | UNSET (frag 2) |
753 | --------------------------> |
754 | ... |
755 | UNSET (frag N) |
756 | --------------------------> |
757 | |
758 | ACK |
759 | <-------------------------- |
760 | |
761
762 * Aborted fragmentation of a NOTIFY frame:
763
764 HAPROXY AGENT SRV
765 | ... |
766 | UNSET (frag X) |
767 | --------------------------> |
768 | |
769 | ACK/ABORT |
770 | <-------------------------- |
771 | |
772 | UNSET (frag X+1) |
773 | -----------X |
774 | |
775 | |
776
Christopher Fauletf7e4e7e2016-10-27 22:29:49 +0200777 * Connection closed by haproxy:
778
779 HAPROXY AGENT SRV
780 | DISCONNECT |
781 | --------------------------> |
782 | |
783 | DISCONNECT + close() |
784 | <-------------------------- |
785 | |
786
787 * Connection closed by agent:
788
789 HAPROXY AGENT SRV
790 | DISCONNECT + close() |
791 | <-------------------------- |
792 | |
793
7943.2.4. Frame: HAPROXY-HELLO
795----------------------------
796
797This frame is the first one exchanged between HAProxy and an agent, when the
798connection is established. The payload of this frame is a KV-LIST. It cannot be
799fragmented. STREAM-ID and FRAME-ID are must be set 0.
800
801Following items are mandatory in the KV-LIST:
802
803 * "supported-versions" <STRING>
804
805 Last SPOP major versions supported by HAProxy. It is a comma-separated list
806 of versions, following the format "Major.Minor". Spaces must be ignored, if
807 any. When a major version is announced by HAProxy, it means it also support
808 all previous minor versions.
809
810 Example: "2.0, 1.5" means HAProxy supports SPOP 2.0 and 1.0 to 1.5
811
812 * "max-frame-size" <UINT32>
813
814 This is the maximum size allowed for a frame. The HAPROXY-HELLO frame must
815 be lower or equal to this value.
816
817 * "capabilities" <STRING>
818
819 This a comma-separated list of capabilities supported by HAProxy. Spaces
820 must be ignored, if any.
821
Christopher Fauletba7bc162016-11-07 21:07:38 +0100822Following optional items can be added in the KV-LIST:
823
824 * "healthcheck" <BOOLEAN>
825
826 If this item is set to TRUE, then the HAPROXY-HELLO frame is sent during a
827 SPOE health check. When set to FALSE, this item can be ignored.
828
Christopher Fauleta1cda022016-12-21 08:58:06 +0100829 * "engine-id" <STRING>
830
831 This is a uniq string that identify a SPOE engine.
832
Christopher Fauletf7e4e7e2016-10-27 22:29:49 +0200833To finish the HELLO handshake, the agent must return an AGENT-HELLO frame with
834its supported SPOP version, the lower value between its maximum size allowed
835for a frame and the HAProxy one and capabilities it supports. If an error
836occurs or if an incompatibility is detected with the agent configuration, an
837AGENT-DISCONNECT frame must be returned.
838
8393.2.5. Frame: AGENT-HELLO
840--------------------------
841
842This frame is sent in reply to a HAPROXY-HELLO frame to finish a HELLO
843handshake. As for HAPROXY-HELLO frame, STREAM-ID and FRAME-ID are also set
8440. The payload of this frame is a KV-LIST and it cannot be fragmented.
845
846Following items are mandatory in the KV-LIST:
847
848 * "version" <STRING>
849
850 This is the SPOP version the agent supports. It must follow the format
851 "Major.Minor" and it must be lower or equal than one of major versions
852 announced by HAProxy.
853
854 * "max-frame-size" <UINT32>
855
856 This is the maximum size allowed for a frame. It must be lower or equal to
857 the value in the HAPROXY-HELLO frame. This value will be used for all
858 subsequent frames.
859
860 * "capabilities" <STRING>
861
862 This a comma-separated list of capabilities supported by agent. Spaces must
863 be ignored, if any.
864
865At this time, if everything is ok for HAProxy (supported version and valid
866max-frame-size value), the HELLO handshake is successfully completed. Else,
867HAProxy sends a HAPROXY-DISCONNECT frame with the corresponding error.
868
Christopher Fauletba7bc162016-11-07 21:07:38 +0100869If "healthcheck" item was set to TRUE in the HAPROXY-HELLO frame, the agent can
870safely close the connection without DISCONNECT frame. In all cases, HAProxy
871will close the connexion at the end of the health check.
872
Christopher Fauletf7e4e7e2016-10-27 22:29:49 +02008733.2.6. Frame: NOTIFY
874---------------------
875
876Information are sent to the agents inside NOTIFY frames. These frames are
877attached to a stream, so STREAM-ID and FRAME-ID must be set. The payload of
878NOTIFY frames is a LIST-OF-MESSAGES and, if supported by agents, it can be
879fragmented.
880
881NOTIFY frames must be acknowledge by agents sending an ACK frame, repeating
882right STREAM-ID and FRAME-ID.
883
8843.2.7. Frame: ACK
885------------------
886
887ACK frames must be sent by agents to reply to NOTIFY frames. STREAM-ID and
888FRAME-ID found in a NOTIFY frame must be reuse in the corresponding ACK
889frame. The payload of ACK frames is a LIST-OF-ACTIONS and, if supported by
890HAProxy, it can be fragmented.
891
8923.2.8. Frame: HAPROXY-DISCONNECT
893---------------------------------
894
895If an error occurs, at anytime, from the HAProxy side, a HAPROXY-DISCONNECT
896frame is sent with information describing the error. HAProxy will wait an
897AGENT-DISCONNECT frame in reply. All other frames will be ignored. The agent
898must then close the socket.
899
900The payload of this frame is a KV-LIST. It cannot be fragmented. STREAM-ID and
901FRAME-ID are must be set 0.
902
903Following items are mandatory in the KV-LIST:
904
905 * "status-code" <UINT32>
906
907 This is the code corresponding to the error.
908
909 * "message" <STRING>
910
911 This is a textual message describing the error.
912
913For more information about known errors, see section "Errors & timeouts"
914
9153.2.9. Frame: AGENT-DISCONNECT
916-------------------------------
917
918If an error occurs, at anytime, from the agent size, a AGENT-DISCONNECT frame
919is sent, with information desribing the error. such frame is also sent in reply
920to a HAPROXY-DISCONNECT. The agent must close the socket just after sending
921this frame.
922
923The payload of this frame is a KV-LIST. It cannot be fragmented. STREAM-ID and
924FRAME-ID are must be set 0.
925
926Following items are mandatory in the KV-LIST:
927
928 * "status-code" <UINT32>
929
930 This is the code corresponding to the error.
931
932 * "message" <STRING>
933
934 This is a textual message describing the error.
935
936For more information about known errors, see section "Errors & timeouts"
937
9383.3. Events & Messages
939-----------------------
940
941Information about streams are sent in NOTIFY frames. You can specify which kind
942of information to send by defining "spoe-message" sections in your SPOE
943configuration file. for each "spoe-message" there will be a message in a NOTIFY
944frame when the right event is triggered.
945
946A NOTIFY frame is sent for an specific event when there is at least one
947"spoe-message" attached to this event. All messages for an event will be added
948in the same NOTIFY frame.
949
950Here is the list of supported events:
951
952 * on-client-session is triggered when a new client session is created.
953 This event is only available for SPOE filters
954 declared in a frontend or a listen section.
955
956 * on-frontend-tcp-request is triggered just before the evaluation of
957 "tcp-request content" rules on the frontend side.
958 This event is only available for SPOE filters
959 declared in a frontend or a listen section.
960
961 * on-backend-tcp-request is triggered just before the evaluation of
962 "tcp-request content" rules on the backend side.
963 This event is skipped for SPOE filters declared
964 in a listen section.
965
966 * on-frontend-http-request is triggered just before the evaluation of
967 "http-request" rules on the frontend side. This
968 event is only available for SPOE filters declared
969 in a frontend or a listen section.
970
971 * on-backend-http-request is triggered just before the evaluation of
972 "http-request" rules on the backend side. This
973 event is skipped for SPOE filters declared in a
974 listen section.
975
976 * on-server-session is triggered when the session with the server is
977 established.
978
979 * on-tcp-response is triggered just before the evaluation of
980 "tcp-response content" rules.
981
982 * on-http-response is triggered just before the evaluation of
983 "http-response" rules.
984
985
986The stream processing will loop on these events, when triggered, waiting the
987agent reply.
988
9893.4. Actions
990-------------
991
992An agent must acknowledge each NOTIFY frame by sending the corresponding ACK
993frame. Actions can be added in these frames to dynamically take action on the
994processing of a stream.
995
996Here is the list of supported actions:
997
998 * set-var set the value for an existing variable. 3 arguments must be
999 attached to this action: the variable scope (proc, sess, txn,
1000 req or req), the variable name (a string) and its value.
1001
1002 ACTION-SET-VAR : <SET-VAR:1 byte><NB-ARGS:1 byte><VAR-SCOPE:1 byte><VAR-NAME><VAR-VALUE>
1003
1004 SET-VAR : <1>
1005 NB-ARGS : <3>
1006 VAR-SCOPE : <PROCESS> | <SESSION> | <TRANSACTION> | <REQUEST> | <RESPONSE>
1007 VAR-NAME : <STRING>
1008 VAR-VALUE : <TYPED-DATA>
1009
1010 PROCESS : <0>
1011 SESSION : <1>
1012 TRANSACTION : <2>
1013 REQUEST : <3>
Christopher Fauleta1cda022016-12-21 08:58:06 +01001014 RESPONSE : <4>
Christopher Fauletf7e4e7e2016-10-27 22:29:49 +02001015
1016 * unset-var unset the value for an existing variable. 2 arguments must be
1017 attached to this action: the variable scope (proc, sess, txn,
1018 req or req) and the variable name (a string).
1019
Christopher Faulet1002aac2016-12-09 17:41:54 +01001020 ACTION-UNSET-VAR : <UNSET-VAR:1 byte><NB-ARGS:1 byte><VAR-SCOPE:1 byte><VAR-NAME>
Christopher Fauletf7e4e7e2016-10-27 22:29:49 +02001021
Christopher Faulet1002aac2016-12-09 17:41:54 +01001022 UNSET-VAR : <2>
1023 NB-ARGS : <2>
Christopher Fauletf7e4e7e2016-10-27 22:29:49 +02001024 VAR-SCOPE : <PROCESS> | <SESSION> | <TRANSACTION> | <REQUEST> | <RESPONSE>
1025 VAR-NAME : <STRING>
1026
1027 PROCESS : <0>
1028 SESSION : <1>
1029 TRANSACTION : <2>
1030 REQUEST : <3>
Christopher Fauleta1cda022016-12-21 08:58:06 +01001031 RESPONSE : <4>
Christopher Fauletf7e4e7e2016-10-27 22:29:49 +02001032
1033
1034NOTE: Name of the variables will be automatically prefixed by HAProxy to avoid
1035 name clashes with other variables used in HAProxy. Moreover, unknown
1036 variable will be silently ignored.
1037
Christopher Fauletd1307ce2017-02-27 21:59:39 +010010383.5. Errors & timeouts
Christopher Fauletf7e4e7e2016-10-27 22:29:49 +02001039----------------------
1040
1041Here is the list of all known errors:
1042
1043 STATUS CODE | DESCRIPTION
1044 ----------------+--------------------------------------------------------
1045 0 | normal (no error occurred)
1046 1 | I/O error
1047 2 | A timeout occurred
1048 3 | frame is too big
1049 4 | invalid frame received
1050 5 | version value not found
1051 6 | max-frame-size value not found
1052 7 | capabilities value not found
1053 8 | unsupported version
1054 9 | max-frame-size too big or too small
Christopher Fauletd1307ce2017-02-27 21:59:39 +01001055 10 | payload fragmentation is not supported
1056 11 | invalid interlaced frames
1057 12 | frame-id not found (it does not match any referenced frame)
1058 13 | resource allocation error
Christopher Fauletf7e4e7e2016-10-27 22:29:49 +02001059 99 | an unknown error occurrde
1060 ----------------+--------------------------------------------------------
1061
1062An agent can define its own errors using a not yet assigned status code.
1063
Christopher Fauletea62c2a2016-11-14 10:54:21 +01001064IMPORTANT NOTE: By default, for a specific stream, when an abnormal/unexpected
1065 error occurs, the SPOE is disabled for all the transaction. So
1066 if you have several events configured, such error on an event
1067 will disabled all followings. For TCP streams, this will
1068 disable the SPOE for the whole session. For HTTP streams, this
1069 will disable it for the transaction (request and response).
1070 See 'option continue-on-error' to bypass this limitation.
Christopher Fauletf7e4e7e2016-10-27 22:29:49 +02001071
1072To avoid a stream to wait infinitly, you must carefully choose the
1073acknowledgement timeout. In most of cases, it will be quiet low. But it depends
1074on the responsivness of your service.
1075
1076You must also choose idle timeout carefully. Because connection with your
1077service depends on the backend configuration used by the SPOA, it is important
1078to use a lower value for idle timeout than the server timeout. Else the
1079connection will be closed by HAProxy. The same is true for hello timeout. You
1080should choose a lower value than the connect timeout.
1081
1082
1083/*
1084 * Local variables:
1085 * fill-column: 79
1086 * End:
1087 */