blob: 81376e0de5fea545fa19d1cca51d6b8a021f69d7 [file] [log] [blame]
Christopher Fauletf7e4e7e2016-10-27 22:29:49 +02001 -----------------------------------------------
2 Stream Processing Offload Engine (SPOE)
3 Version 1.0
4 ( Last update: 2016-11-07 )
5 -----------------------------------------------
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
19 2.4. Example
20 3. SPOP specification
21 3.1. Data types
22 3.2. Frames
23 3.2.1. Frame capabilities
24 3.2.2. Frame types overview
25 3.2.3. Workflow
26 3.2.4. Frame: HAPROXY-HELLO
27 3.2.5. Frame: AGENT-HELLO
28 3.2.6. Frame: NOTIFY
29 3.2.7. Frame: ACK
30 3.2.8. Frame: HAPROXY-DISCONNECT
31 3.2.9. Frame: AGENT-DISCONNECT
32 3.3. Events & messages
33 3.4. Actions
34 3.5. Error & timeouts
35
36
370. Terms
38---------
39
40* SPOE : Stream Processing Offload Engine.
41
42 A SPOE is a filter talking to servers managed ba a SPOA to offload the
43 stream processing. An engine is attached to a proxy. A proxy can have
44 several engine. Each engine is linked to an agent and only one.
45
46* SPOA : Stream Processing Offload Agent.
47
48 A SPOA is a service that will receive info from a SPOE to offload the
49 stream processing. An agent manages several servers. It uses a backend to
50 reference all of them. By extension, these servers can also be called
51 agents.
52
53* SPOP : Stream Processing Offload Protocol, used by SPOEs to talk to SPOA
54 servers.
55
56 This protocol is used by engines to talk to agents. It is an in-house
57 binary protocol described in this documentation.
58
59
601. Introduction
61----------------
62
63SPOE is a feature introduced in HAProxy 1.7. It makes possible the
64communication with external components to retrieve some info. The idea started
65with the problems caused by most ldap libs not working fine in event-driven
66systems (often at least the connect() is blocking). So, it is hard to properly
67implement Single Sign On solution (SSO) in HAProxy. The SPOE will ease this
68kind of processing, or we hope so.
69
70Now, the aim of SPOE is to allow any kind of offloading on the streams. First
71releases, besides being experimental, won't do lot of things. As we will see,
72there are few handled events and even less actions supported. Actually, for
73now, the SPOE can offload the processing before "tcp-request content",
74"tcp-response content", "http-request" and "http-response" rules. And it only
75supports variables definition. But, in spite of these limited features, we can
76easily imagine to implement SSO solution, ip reputation or ip geolocation
77services.
78
79
802. SPOE configuration
81----------------------
82
83Because SPOE is implemented as a filter, To use it, you must declare a "filter
84spoe" line in a proxy section (frontend/backend/listen) :
85
86 frontend my-front
87 ...
88 filter spoe [engine <name>] config <file>
89 ...
90
91The "config" parameter is mandatory. It specififies the SPOE configuration
92file. The engine name is optional. It can be set to declare the scope to use in
93the SPOE configuration. So it is possible to use the same SPOE configuration
94for several engines. If no name is provided, the SPOE configuration must not
95contain any scope directive.
96
97We use a separate configuration file on purpose. By commenting SPOE filter
98line, you completly disable the feature, including the parsing of sections
99reserved to SPOE. This is also a way to keep the HAProxy configuration clean.
100
101A SPOE configuration file must contains, at least, the SPOA configuration
102("spoe-agent" section) and SPOE messages ("spoe-message" section) attached to
103this agent. Unused messages (not reference in "spoe-agent" section) will be
104ignored.
105
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
117"spoe-message" sections to describe messages sent to servers mananger by your
118SPOA.
119
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 ...
135
136 [my-second-engine]
137 ...
138
139If no engine name is provided on the SPOE filter line, no SPOE scope must be
140found in the SPOE configuration file. All the file is considered to be in the
141same anonymous and implicit scope.
142
1432.2. "spoe-agent" section
144--------------------------
145
146For each engine, you must define one and only one "spoe-agent" section. In this
147section, you will declare SPOE messages and the backend you will use. You will
148also set timeouts and options to customize your agent's behaviour.
149
150
151spoe-agent <name>
152 Create a new SPOA with the name <name>. It must have one and only one
153 "spoe-agent" definition by SPOE scope.
154
155 Arguments :
156 <name> is the name of the agent section.
157
158 following keywords are supported :
Christopher Faulet48026722016-11-16 15:01:12 +0100159 - maxconnrate
160 - maxerrrate
Christopher Fauletf7e4e7e2016-10-27 22:29:49 +0200161 - messages
Christopher Fauletea62c2a2016-11-14 10:54:21 +0100162 - option continue-on-error
Christopher Faulet985532d2016-11-16 15:36:19 +0100163 - option set-on-error
Christopher Fauletf7e4e7e2016-10-27 22:29:49 +0200164 - option var-prefix
Christopher Faulet03a34492016-11-19 16:47:56 +0100165 - timeout hello|idle|processing
Christopher Fauletf7e4e7e2016-10-27 22:29:49 +0200166 - use-backend
167
168
Christopher Faulet48026722016-11-16 15:01:12 +0100169maxconnrate <number>
170 Set the maximum number of connections per second to <number>. The SPOE will
171 stop to open new connections if the maximum is reached and will wait to
172 acquire an existing one. So it is important to set "timeout hello" to a
173 relatively small value.
174
175
176maxerrrate <number>
177 Set the maximum number of errors per second to <number>. The SPOE will stop
178 its processing if the maximum is reached.
179
180
Christopher Fauletf7e4e7e2016-10-27 22:29:49 +0200181messages <msg-name> ...
182 Declare the list of SPOE messages that an agent will handle.
183
184 Arguments :
185 <msg-name> is the name of a SPOE message.
186
187 Messages declared here must be found in the same engine scope, else an error
188 is triggered during the configuration parsing. You can have many "messages"
189 lines.
190
191 See also: "spoe-message" section.
192
193
Christopher Fauletea62c2a2016-11-14 10:54:21 +0100194option continue-on-error
195 Do not stop the events processing when an error occurred on a stream.
196
197 By default, for a specific stream, when an abnormal/unexpected error occurs,
198 the SPOE is disabled for all the transaction. So if you have several events
199 configured, such error on an event will disabled all followings. For TCP
200 streams, this will disable the SPOE for the whole session. For HTTP streams,
201 this will disable it for the transaction (request and response).
202
203 When set, this option bypass this behaviour and only the current event will
204 be ignored.
205
206
Christopher Faulet985532d2016-11-16 15:36:19 +0100207option set-on-error <var name>
208 Define the variable to set when an error occurred during an event processing.
209
210 Arguments :
211
212 <var name> is the variable name, without the scope. The name may only
213 contain characters 'a-z', 'A-Z', '0-9', '.' and '_'.
214
215 This variable will only be set when an error occurred in the scope of the
216 transaction. As for all other variables define by the SPOE, it will be
217 prefixed. So, if your variable name is "error" and your prefix is
218 "my_spoe_pfx", the variable will be "txn.my_spoe_pfx.error".
219
Christopher Fauletb067b062017-01-04 16:39:11 +0100220 When set, the variable is an integer representing the error reason. For values
221 under 256, it represents an error coming from the engine. Below 256, it
222 reports a SPOP error. In this case, to retrieve the right SPOP status code,
223 you must remove 256 to this value. Here are possible values:
224
225 * 1 a timeout occurred during the event processing.
226
227 * 2 an error was triggered during the ressources allocation.
228
229 * 255 an unknown error occurred during the event processing.
230
231 * 256+N a SPOP error occurred during the event processing (see section
232 "Errors & timeouts").
233
234 Note that if "option continue-on-error" is set, the variable is not
235 automatically removed between events processing.
Christopher Faulet985532d2016-11-16 15:36:19 +0100236
237 See also: "option continue-on-error", "option var-prefix".
238
Christopher Fauletf7e4e7e2016-10-27 22:29:49 +0200239option var-prefix <prefix>
240 Define the prefix used when variables are set by an agent.
241
242 Arguments :
243
244 <prefix> is the prefix used to limit the scope of variables set by an
245 agent.
246
247 To avoid conflict with other variables defined by HAProxy, all variables
248 names will be prefixed. By default, the "spoe-agent" name is used. This
249 option can be used to customize it.
250
251 The prefix will be added between the variable scope and its name, separated
252 by a '.'. It may only contain characters 'a-z', 'A-Z', '0-9', '.' and '_', as
253 for variables name. In HAProxy configuration, you need to use this prefix as
254 a part of the variables name. For example, if an agent define the variable
255 "myvar" in the "txn" scope, with the prefix "my_spoe_pfx", then you should
256 use "txn.my_spoe_pfx.myvar" name in your HAProxy configuration.
257
258 An agent will never set new variables at runtime. It can only set new value
259 for existing ones.
260
261
Christopher Fauletf7e4e7e2016-10-27 22:29:49 +0200262timeout hello <timeout>
263 Set the maximum time to wait for an agent to receive the AGENT-HELLO frame.
Christopher Fauletf7a30922016-11-10 15:04:51 +0100264 It is applied on the stream that handle the connection with the agent.
Christopher Fauletf7e4e7e2016-10-27 22:29:49 +0200265
266 Arguments :
267 <timeout> is the timeout value specified in milliseconds by default, but
268 can be in any other unit if the number is suffixed by the unit,
269 as explained at the top of this document.
270
271 This timeout is an applicative timeout. It differ from "timeout connect"
272 defined on backends.
273
274
275timeout idle <timeout>
Christopher Fauletf7a30922016-11-10 15:04:51 +0100276 Set the maximum time to wait for an agent to close an idle connection. It is
277 applied on the stream that handle the connection with the agent.
278
279 Arguments :
280 <timeout> is the timeout value specified in milliseconds by default, but
281 can be in any other unit if the number is suffixed by the unit,
282 as explained at the top of this document.
283
284
285timeout processing <timeout>
286 Set the maximum time to wait for a stream to process an event, i.e to acquire
287 a stream to talk with an agent, to encode all messages, to send the NOTIFY
288 frame, to receive the corrsponding acknowledgement and to process all
289 actions. It is applied on the stream that handle the client and the server
290 sessions.
Christopher Fauletf7e4e7e2016-10-27 22:29:49 +0200291
292 Arguments :
293 <timeout> is the timeout value specified in milliseconds by default, but
294 can be in any other unit if the number is suffixed by the unit,
295 as explained at the top of this document.
296
297
298use-backend <backend>
299 Specify the backend to use. It must be defined.
300
301 Arguments :
302 <backend> is the name of a valid "backend" section.
303
304
3052.3. "spoe-message" section
306----------------------------
307
308To offload the stream processing, SPOE will send messages with specific
309information at a specific moment in the stream life and will wait for
310corresponding replies to know what to do.
311
312
313spoe-message <name>
314 Create a new SPOE message with the name <name>.
315
316 Arguments :
317 <name> is the name of the SPOE message.
318
319 Here you define a message that can be referenced in a "spoe-agent"
320 section. Following keywords are supported :
321 - args
322 - event
323
324 See also: "spoe-agent" section.
325
326
327args [name=]<sample> ...
328 Define arguments passed into the SPOE message.
329
330 Arguments :
331 <sample> is a sample expression.
332
333 When the message is processed, if a sample expression is not available, it is
334 set to NULL. Arguments are processed in their declaration order and added in
335 the message in that order. It is possible to declare named arguements.
336
337 For example:
338 args frontend=fe_id src dst
339
340
341event <name>
342 Set the event that triggers sending of the message.
343
344 Argument :
345 <name> is the event name.
346
347 Supported events are:
348 - on-client-session
Christopher Faulet1002aac2016-12-09 17:41:54 +0100349 - on-server-session
Christopher Fauletf7e4e7e2016-10-27 22:29:49 +0200350 - on-frontend-tcp-request
351 - on-backend-tcp-request
352 - on-tcp-response
353 - on-frontend-http-request
354 - on-backend-http-request
355 - on-http-response
356
Christopher Fauletb067b062017-01-04 16:39:11 +0100357 See section "Events & Messages".
Christopher Fauletf7e4e7e2016-10-27 22:29:49 +0200358
3592.4. Example
360-------------
361
362Here is a simple but complete example that sends client-ip address to a ip
363reputation service. This service can set the variable "ip_score" which is an
364integer between 0 and 100, indicating its reputation (100 means totally safe
365and 0 a blacklisted IP with no doubt).
366
367 ###
368 ### HAProxy configuration
369 frontend www
370 mode http
371 bind *:80
372
373 filter spoe engine ip-reputation config spoe-ip-reputation.conf
374
375 # Reject connection if the IP reputation is under 20
376 tcp-request content reject if { var(sess.iprep.ip_score) -m int lt 20 }
377
378 default_backend http-servers
379
380 backend http-servers
381 mode http
382 server http A.B.C.D:80
383
384 backend iprep-servers
385 mode tcp
386 balance roundrobin
387
388 timeout connect 5s # greater than hello timeout
389 timeout server 3m # greater than idle timeout
390
391 server iprep1 A1.B1.C1.D1:12345
392 server iprep2 A2.B2.C2.D2:12345
393
394 ####
395 ### spoe-ip-reputation.conf
396 [ip-reputation]
397
398 spoe-agent iprep-agent
399 messages get-ip-reputation
400
401 option var-prefix iprep
402
Christopher Faulet03a34492016-11-19 16:47:56 +0100403 timeout hello 2s
404 timeout idle 2m
405 timeout processing 10ms
Christopher Fauletf7e4e7e2016-10-27 22:29:49 +0200406
407 use-backend iprep-servers
408
409 spoe-message get-ip-reputation
410 args ip=src
411 event on-client-session
412
413
4143. SPOP specification
415----------------------
416
4173.1. Data types
418----------------
419
420Here is the bytewise representation of typed data:
421
422 TYPED-DATA : <TYPE:4 bits><FLAGS:4 bits><DATA>
423
424Supported types and their representation are:
425
426 TYPE | ID | DESCRIPTION
427 -----------------------------+-----+----------------------------------
428 NULL | 0 | NULL : <0>
429 Boolean | 1 | BOOL : <1+FLAG>
430 32bits signed integer | 2 | INT32 : <2><VALUE:varint>
431 32bits unsigned integer | 3 | UINT32 : <3><VALUE:varint>
432 64bits signed integer | 4 | INT64 : <4><VALUE:varint>
433 32bits unsigned integer | 5 | UNIT64 : <5><VALUE:varint>
434 IPV4 | 6 | IPV4 : <6><STRUCT IN_ADDR:4 bytes>
435 IPV6 | 7 | IPV6 : <7><STRUCT IN_ADDR6:16 bytes>
436 String | 8 | STRING : <8><LENGTH:varint><BYTES>
437 Binary | 9 | BINARY : <9><LENGTH:varint><BYTES>
438 10 -> 15 unused/reserved | - | -
439 -----------------------------+-----+----------------------------------
440
441Variable-length integer (varint) are encoded using Peers encoding:
442
443
444 0 <= X < 240 : 1 byte (7.875 bits) [ XXXX XXXX ]
445 240 <= X < 2288 : 2 bytes (11 bits) [ 1111 XXXX ] [ 0XXX XXXX ]
446 2288 <= X < 264432 : 3 bytes (18 bits) [ 1111 XXXX ] [ 1XXX XXXX ] [ 0XXX XXXX ]
447 264432 <= X < 33818864 : 4 bytes (25 bits) [ 1111 XXXX ] [ 1XXX XXXX ]*2 [ 0XXX XXXX ]
448 33818864 <= X < 4328786160 : 5 bytes (32 bits) [ 1111 XXXX ] [ 1XXX XXXX ]*3 [ 0XXX XXXX ]
449 ...
450
451For booleans, the value (true or false) is the first bit in the FLAGS
452bitfield. if this bit is set to 0, then the boolean is evaluated as false,
453otherwise, the boolean is evaluated as true.
454
4553.2. Frames
456------------
457
458Exchange between HAProxy and agents are made using FRAME packets. All frames
459must be prefixed with their size encoded on 4 bytes in network byte order:
460
461 <FRAME-LENGTH:4 bytes> <FRAME>
462
463A frame always starts with its type, on one byte, followed by metadata
464containing flags, on 4 bytes and a two variable-length integer representing the
465stream identifier and the frame identifier inside the stream:
466
467 FRAME : <FRAME-TYPE:1 byte> <METADATA> <FRAME-PAYLOAD>
468 METADATA : <FLAGS:4 bytes> <STREAM-ID:varint> <FRAME-ID:varint>
469
470Then comes the frame payload. Depending on the frame type, the payload can be
471of three types: a simple key/value list, a list of messages or a list of
472actions.
473
474 FRAME-PAYLOAD : <LIST-OF-MESSAGES> | <LIST-OF-ACTIONS> | <KV-LIST>
475
476 LIST-OF-MESSAGES : [ <MESSAGE-NAME> <NB-ARGS:1 byte> <KV-LIST> ... ]
477 MESSAGE-NAME : <STRING>
478
479 LIST-OF-ACTIONS : [ <ACTION-TYPE:1 byte> <NB-ARGS:1 byte> <ACTION-ARGS> ... ]
480 ACTION-ARGS : [ <TYPED-DATA>... ]
481
482 KV-LIST : [ <KV-NAME> <KV-VALUE> ... ]
483 KV-NAME : <STRING>
484 KV-VALUE : <TYPED-DATA>
485
486 FLAGS : 0 1-31
487 +---+-----------+
488 | F| |
489 | I| RESERVED |
490 | N| |
491 +--+------------+
492
493 FIN: Indicates that this is the final payload fragment. The first fragment
494 may also be the final fragment.
495
496Frames cannot exceed a maximum size negociated between HAProxy and agents
497during the HELLO handshake. Most of time, payload will be small enough to send
498it in one frame. But when supported by the peer, it will be possible to
499fragment huge payload on many frames. This ability is announced during the
500HELLO handshake and it can be asynmetric (supported by agents but not by
501HAProxy or the opposite). The following rules apply to fragmentation:
502
503 * An unfragemnted payload consists of a single frame with the FIN bit set.
504
505 * A fragemented payload consists of several frames with the FIN bit clear and
506 terminated by a single frame with the FIN bit set. All these frames must
507 share the same STREAM-ID and FRAME-ID. And, of course, the FRAME-TYPE must
508 be the same.
509
510Beside the support of fragmented payload by a peer, some payload must not be
511fragmented. See below for details.
512
513IMPORTANT : The maximum size supported by peers for a frame must be greater or
514equal to 256 bytes.
515
5163.2.1. Frame capabilities
517--------------------------
518
519Here are the list of official capabilities that HAProxy and agents can support:
520
Christopher Fauleta1cda022016-12-21 08:58:06 +0100521 * fragmentation: This is the ability for a peer to support fragmented
522 payload in received frames. This is an asymmectical
523 capability, it only concerns the peer that announces
524 it. This is the responsibility to the other peer to use it
525 or not.
526
527 * pipelining: This is the ability for a peer to decouple NOTIFY and ACK
528 frames. This is a symmectical capability. To be used, it must
529 be supported by HAproxy and agents. Unlike HTTP pipelining, the
530 ACK frames can be send in any order, but always on the same TCP
531 connection used for the corresponding NOTIFY frame.
532
533 * async: This ability is similar to the pipelining, but here any TCP
534 connection established between HAProxy and the agent can be used to
535 send ACK frames. if an agent accepts connections from multiple
536 HAProxy, it can use the "engine-id" value to group TCP
537 connections. See details about HAPROXY-HELLO frame.
Christopher Fauletf7e4e7e2016-10-27 22:29:49 +0200538
539Unsupported or unknown capabilities are silently ignored, when possible.
540
5413.2.2. Frame types overview
542----------------------------
543
544Here are types of frame supported by SPOE. Frames sent by HAProxy come first,
545then frames sent by agents :
546
547 TYPE | ID | DESCRIPTION
548 -----------------------------+-----+-------------------------------------
549 HAPROXY-HELLO | 1 | Sent by HAProxy when it opens a
550 | | connection on an agent.
551 | |
552 HAPROXY-DISCONNECT | 2 | Sent by HAProxy when it want to close
553 | | the connection or in reply to an
554 | | AGENT-DISCONNECT frame
555 | |
556 NOTIFY | 3 | Sent by HAProxy to pass information
557 | | to an agent
558 -----------------------------+-----+-------------------------------------
559 AGENT-HELLO | 101 | Reply to a HAPROXY-HELLO frame, when
560 | | the connection is established
561 | |
562 AGENT-DISCONNECT | 102 | Sent by an agent just before closing
563 | | the connection
564 | |
565 ACK | 103 | Sent to acknowledge a NOTIFY frame
566 -----------------------------+-----+-------------------------------------
567
568Unknown frames may be silently skipped.
569
5703.2.3. Workflow
571----------------
572
573 * Successful HELLO handshake:
574
575 HAPROXY AGENT SRV
576 | HAPROXY-HELLO |
Christopher Fauletba7bc162016-11-07 21:07:38 +0100577 | (healthcheck: false) |
Christopher Fauletf7e4e7e2016-10-27 22:29:49 +0200578 | --------------------------> |
579 | |
580 | AGENT-HELLO |
581 | <-------------------------- |
582 | |
583
Christopher Fauletba7bc162016-11-07 21:07:38 +0100584 * Successful HELLO healthcheck:
585
586 HAPROXY AGENT SRV
587 | HAPROXY-HELLO |
588 | (healthcheck: true) |
589 | --------------------------> |
590 | |
591 | AGENT-HELLO + close() |
592 | <-------------------------- |
593 | |
594
Christopher Fauletf7e4e7e2016-10-27 22:29:49 +0200595
596 * Error encountered by agent during the HELLO handshake:
597
598 HAPROXY AGENT SRV
599 | HAPROXY-HELLO |
600 | --------------------------> |
601 | |
602 | DISCONNECT + close() |
603 | <-------------------------- |
604 | |
605
606 * Error encountered by HAProxy during the HELLO handshake:
607
608 HAPROXY AGENT SRV
609 | HAPROXY-HELLO |
610 | --------------------------> |
611 | |
612 | AGENT-HELLO |
613 | <-------------------------- |
614 | |
615 | DISCONNECT |
616 | --------------------------> |
617 | |
618 | DISCONNECT + close() |
619 | <-------------------------- |
620 | |
621
622 * Notify / Ack exchange:
623
624 HAPROXY AGENT SRV
625 | NOTIFY |
626 | --------------------------> |
627 | |
628 | ACK |
629 | <-------------------------- |
630 | |
631
632 * Connection closed by haproxy:
633
634 HAPROXY AGENT SRV
635 | DISCONNECT |
636 | --------------------------> |
637 | |
638 | DISCONNECT + close() |
639 | <-------------------------- |
640 | |
641
642 * Connection closed by agent:
643
644 HAPROXY AGENT SRV
645 | DISCONNECT + close() |
646 | <-------------------------- |
647 | |
648
6493.2.4. Frame: HAPROXY-HELLO
650----------------------------
651
652This frame is the first one exchanged between HAProxy and an agent, when the
653connection is established. The payload of this frame is a KV-LIST. It cannot be
654fragmented. STREAM-ID and FRAME-ID are must be set 0.
655
656Following items are mandatory in the KV-LIST:
657
658 * "supported-versions" <STRING>
659
660 Last SPOP major versions supported by HAProxy. It is a comma-separated list
661 of versions, following the format "Major.Minor". Spaces must be ignored, if
662 any. When a major version is announced by HAProxy, it means it also support
663 all previous minor versions.
664
665 Example: "2.0, 1.5" means HAProxy supports SPOP 2.0 and 1.0 to 1.5
666
667 * "max-frame-size" <UINT32>
668
669 This is the maximum size allowed for a frame. The HAPROXY-HELLO frame must
670 be lower or equal to this value.
671
672 * "capabilities" <STRING>
673
674 This a comma-separated list of capabilities supported by HAProxy. Spaces
675 must be ignored, if any.
676
Christopher Fauletba7bc162016-11-07 21:07:38 +0100677Following optional items can be added in the KV-LIST:
678
679 * "healthcheck" <BOOLEAN>
680
681 If this item is set to TRUE, then the HAPROXY-HELLO frame is sent during a
682 SPOE health check. When set to FALSE, this item can be ignored.
683
Christopher Fauleta1cda022016-12-21 08:58:06 +0100684 * "engine-id" <STRING>
685
686 This is a uniq string that identify a SPOE engine.
687
Christopher Fauletf7e4e7e2016-10-27 22:29:49 +0200688To finish the HELLO handshake, the agent must return an AGENT-HELLO frame with
689its supported SPOP version, the lower value between its maximum size allowed
690for a frame and the HAProxy one and capabilities it supports. If an error
691occurs or if an incompatibility is detected with the agent configuration, an
692AGENT-DISCONNECT frame must be returned.
693
6943.2.5. Frame: AGENT-HELLO
695--------------------------
696
697This frame is sent in reply to a HAPROXY-HELLO frame to finish a HELLO
698handshake. As for HAPROXY-HELLO frame, STREAM-ID and FRAME-ID are also set
6990. The payload of this frame is a KV-LIST and it cannot be fragmented.
700
701Following items are mandatory in the KV-LIST:
702
703 * "version" <STRING>
704
705 This is the SPOP version the agent supports. It must follow the format
706 "Major.Minor" and it must be lower or equal than one of major versions
707 announced by HAProxy.
708
709 * "max-frame-size" <UINT32>
710
711 This is the maximum size allowed for a frame. It must be lower or equal to
712 the value in the HAPROXY-HELLO frame. This value will be used for all
713 subsequent frames.
714
715 * "capabilities" <STRING>
716
717 This a comma-separated list of capabilities supported by agent. Spaces must
718 be ignored, if any.
719
720At this time, if everything is ok for HAProxy (supported version and valid
721max-frame-size value), the HELLO handshake is successfully completed. Else,
722HAProxy sends a HAPROXY-DISCONNECT frame with the corresponding error.
723
Christopher Fauletba7bc162016-11-07 21:07:38 +0100724If "healthcheck" item was set to TRUE in the HAPROXY-HELLO frame, the agent can
725safely close the connection without DISCONNECT frame. In all cases, HAProxy
726will close the connexion at the end of the health check.
727
Christopher Fauletf7e4e7e2016-10-27 22:29:49 +02007283.2.6. Frame: NOTIFY
729---------------------
730
731Information are sent to the agents inside NOTIFY frames. These frames are
732attached to a stream, so STREAM-ID and FRAME-ID must be set. The payload of
733NOTIFY frames is a LIST-OF-MESSAGES and, if supported by agents, it can be
734fragmented.
735
736NOTIFY frames must be acknowledge by agents sending an ACK frame, repeating
737right STREAM-ID and FRAME-ID.
738
7393.2.7. Frame: ACK
740------------------
741
742ACK frames must be sent by agents to reply to NOTIFY frames. STREAM-ID and
743FRAME-ID found in a NOTIFY frame must be reuse in the corresponding ACK
744frame. The payload of ACK frames is a LIST-OF-ACTIONS and, if supported by
745HAProxy, it can be fragmented.
746
7473.2.8. Frame: HAPROXY-DISCONNECT
748---------------------------------
749
750If an error occurs, at anytime, from the HAProxy side, a HAPROXY-DISCONNECT
751frame is sent with information describing the error. HAProxy will wait an
752AGENT-DISCONNECT frame in reply. All other frames will be ignored. The agent
753must then close the socket.
754
755The payload of this frame is a KV-LIST. It cannot be fragmented. STREAM-ID and
756FRAME-ID are must be set 0.
757
758Following items are mandatory in the KV-LIST:
759
760 * "status-code" <UINT32>
761
762 This is the code corresponding to the error.
763
764 * "message" <STRING>
765
766 This is a textual message describing the error.
767
768For more information about known errors, see section "Errors & timeouts"
769
7703.2.9. Frame: AGENT-DISCONNECT
771-------------------------------
772
773If an error occurs, at anytime, from the agent size, a AGENT-DISCONNECT frame
774is sent, with information desribing the error. such frame is also sent in reply
775to a HAPROXY-DISCONNECT. The agent must close the socket just after sending
776this frame.
777
778The payload of this frame is a KV-LIST. It cannot be fragmented. STREAM-ID and
779FRAME-ID are must be set 0.
780
781Following items are mandatory in the KV-LIST:
782
783 * "status-code" <UINT32>
784
785 This is the code corresponding to the error.
786
787 * "message" <STRING>
788
789 This is a textual message describing the error.
790
791For more information about known errors, see section "Errors & timeouts"
792
7933.3. Events & Messages
794-----------------------
795
796Information about streams are sent in NOTIFY frames. You can specify which kind
797of information to send by defining "spoe-message" sections in your SPOE
798configuration file. for each "spoe-message" there will be a message in a NOTIFY
799frame when the right event is triggered.
800
801A NOTIFY frame is sent for an specific event when there is at least one
802"spoe-message" attached to this event. All messages for an event will be added
803in the same NOTIFY frame.
804
805Here is the list of supported events:
806
807 * on-client-session is triggered when a new client session is created.
808 This event is only available for SPOE filters
809 declared in a frontend or a listen section.
810
811 * on-frontend-tcp-request is triggered just before the evaluation of
812 "tcp-request content" rules on the frontend side.
813 This event is only available for SPOE filters
814 declared in a frontend or a listen section.
815
816 * on-backend-tcp-request is triggered just before the evaluation of
817 "tcp-request content" rules on the backend side.
818 This event is skipped for SPOE filters declared
819 in a listen section.
820
821 * on-frontend-http-request is triggered just before the evaluation of
822 "http-request" rules on the frontend side. This
823 event is only available for SPOE filters declared
824 in a frontend or a listen section.
825
826 * on-backend-http-request is triggered just before the evaluation of
827 "http-request" rules on the backend side. This
828 event is skipped for SPOE filters declared in a
829 listen section.
830
831 * on-server-session is triggered when the session with the server is
832 established.
833
834 * on-tcp-response is triggered just before the evaluation of
835 "tcp-response content" rules.
836
837 * on-http-response is triggered just before the evaluation of
838 "http-response" rules.
839
840
841The stream processing will loop on these events, when triggered, waiting the
842agent reply.
843
8443.4. Actions
845-------------
846
847An agent must acknowledge each NOTIFY frame by sending the corresponding ACK
848frame. Actions can be added in these frames to dynamically take action on the
849processing of a stream.
850
851Here is the list of supported actions:
852
853 * set-var set the value for an existing variable. 3 arguments must be
854 attached to this action: the variable scope (proc, sess, txn,
855 req or req), the variable name (a string) and its value.
856
857 ACTION-SET-VAR : <SET-VAR:1 byte><NB-ARGS:1 byte><VAR-SCOPE:1 byte><VAR-NAME><VAR-VALUE>
858
859 SET-VAR : <1>
860 NB-ARGS : <3>
861 VAR-SCOPE : <PROCESS> | <SESSION> | <TRANSACTION> | <REQUEST> | <RESPONSE>
862 VAR-NAME : <STRING>
863 VAR-VALUE : <TYPED-DATA>
864
865 PROCESS : <0>
866 SESSION : <1>
867 TRANSACTION : <2>
868 REQUEST : <3>
Christopher Fauleta1cda022016-12-21 08:58:06 +0100869 RESPONSE : <4>
Christopher Fauletf7e4e7e2016-10-27 22:29:49 +0200870
871 * unset-var unset the value for an existing variable. 2 arguments must be
872 attached to this action: the variable scope (proc, sess, txn,
873 req or req) and the variable name (a string).
874
Christopher Faulet1002aac2016-12-09 17:41:54 +0100875 ACTION-UNSET-VAR : <UNSET-VAR:1 byte><NB-ARGS:1 byte><VAR-SCOPE:1 byte><VAR-NAME>
Christopher Fauletf7e4e7e2016-10-27 22:29:49 +0200876
Christopher Faulet1002aac2016-12-09 17:41:54 +0100877 UNSET-VAR : <2>
878 NB-ARGS : <2>
Christopher Fauletf7e4e7e2016-10-27 22:29:49 +0200879 VAR-SCOPE : <PROCESS> | <SESSION> | <TRANSACTION> | <REQUEST> | <RESPONSE>
880 VAR-NAME : <STRING>
881
882 PROCESS : <0>
883 SESSION : <1>
884 TRANSACTION : <2>
885 REQUEST : <3>
Christopher Fauleta1cda022016-12-21 08:58:06 +0100886 RESPONSE : <4>
Christopher Fauletf7e4e7e2016-10-27 22:29:49 +0200887
888
889NOTE: Name of the variables will be automatically prefixed by HAProxy to avoid
890 name clashes with other variables used in HAProxy. Moreover, unknown
891 variable will be silently ignored.
892
8933.5. Error & timeouts
894----------------------
895
896Here is the list of all known errors:
897
898 STATUS CODE | DESCRIPTION
899 ----------------+--------------------------------------------------------
900 0 | normal (no error occurred)
901 1 | I/O error
902 2 | A timeout occurred
903 3 | frame is too big
904 4 | invalid frame received
905 5 | version value not found
906 6 | max-frame-size value not found
907 7 | capabilities value not found
908 8 | unsupported version
909 9 | max-frame-size too big or too small
910 99 | an unknown error occurrde
911 ----------------+--------------------------------------------------------
912
913An agent can define its own errors using a not yet assigned status code.
914
Christopher Fauletea62c2a2016-11-14 10:54:21 +0100915IMPORTANT NOTE: By default, for a specific stream, when an abnormal/unexpected
916 error occurs, the SPOE is disabled for all the transaction. So
917 if you have several events configured, such error on an event
918 will disabled all followings. For TCP streams, this will
919 disable the SPOE for the whole session. For HTTP streams, this
920 will disable it for the transaction (request and response).
921 See 'option continue-on-error' to bypass this limitation.
Christopher Fauletf7e4e7e2016-10-27 22:29:49 +0200922
923To avoid a stream to wait infinitly, you must carefully choose the
924acknowledgement timeout. In most of cases, it will be quiet low. But it depends
925on the responsivness of your service.
926
927You must also choose idle timeout carefully. Because connection with your
928service depends on the backend configuration used by the SPOA, it is important
929to use a lower value for idle timeout than the server timeout. Else the
930connection will be closed by HAProxy. The same is true for hello timeout. You
931should choose a lower value than the connect timeout.
932
933
934/*
935 * Local variables:
936 * fill-column: 79
937 * End:
938 */