blob: cdde82e34a25aef7a0552a3996a12a0850763c72 [file] [log] [blame]
Willy Tarreau8263b912011-09-05 01:04:44 +020012011/02/25 - Description of the different entities in haproxy - w@1wt.eu
2
3
41) Definitions
5--------------
6
7Listener
8--------
9
10A listener is the entity which is part of a frontend and which accepts
11connections. There are as many listeners as there are ip:port couples.
Ilya Shipitsin2075ca82020-03-06 23:22:22 +050012There is at least one listener instantiated for each "bind" entry, and
Willy Tarreau8263b912011-09-05 01:04:44 +020013port ranges will lead to as many listeners as there are ports in the
14range. A listener just has a listening file descriptor ready to accept
15incoming connections and to dispatch them to upper layers.
16
17
18Initiator
19---------
20
Ilya Shipitsin2075ca82020-03-06 23:22:22 +050021An initiator is instantiated for each incoming connection on a listener. It may
22also be instantiated by a task pretending to be a client. An initiator calls
Willy Tarreau8263b912011-09-05 01:04:44 +020023the next stage's accept() callback to present it with the parameters of the
24incoming connection.
25
26
27Session
28-------
29
30A session is the only entity located between an initiator and a connector.
31This is the last stage which offers an accept() callback, and all of its
32processing will continue with the next stage's connect() callback. It holds
33the buffers needed to forward the protocol data between each side. This entity
34sees the native protocol, and is able to call analysers on these buffers. As it
35is used in both directions, it always has two buffers.
36
37When transformations are required, some of them may be done on the initiator
38side and other ones on the connector side. If additional buffers are needed for
39such transforms, those buffers cannot replace the session's buffers, but they
40may complete them.
41
Ilya Shipitsin2075ca82020-03-06 23:22:22 +050042A session only needs to be instantiated when forwarding of data is required
Willy Tarreau8263b912011-09-05 01:04:44 +020043between two sides. Accepting and filtering on layer 4 information only does not
44require a session.
45
46For instance, let's consider the case of a proxy which receives and decodes
47HTTPS traffic, processes it as HTTP and recodes it as HTTPS before forwarding
48it. We'd have 3 layers of buffers, where the middle ones are used for
49forwarding of the protocol data (HTTP here) :
50
51 <-- ssl dec --> <-forwarding-> <-- ssl enc -->
52
53 ,->[||||]--. ,->[||||]--. ,->[||||]--.
54 client (|) (|) (|) (|) server
55 ^--[||||]<-' ^--[||||]<-' ^--[||||]<-'
56
57 HTTPS HTTP HTTPS
58
59The session handling code is only responsible for monitoring the forwarding
60buffers here. It may declare the end of the session once those buffers are
61closed and no analyser wants to re-open them. The session is also the entity
62which applies the load balancing algorithm and decides the server to use.
63
64The other sides are responsible for propagating the state up to the session
65which takes decisions.
66
67
68Connector
69---------
70
Joseph Herlant02cedc42018-11-13 19:45:17 -080071A connector is the entity which permits to instantiate a connection to a known
Willy Tarreau8263b912011-09-05 01:04:44 +020072destination. It presents a connect() callback, and as such appears on the right
73side of diagrams.
74
75
76Connection
77----------
78
Ilya Shipitsin2075ca82020-03-06 23:22:22 +050079A connection is the entity instantiated by a connector. It may be composed of
Willy Tarreau8263b912011-09-05 01:04:44 +020080multiple stages linked together. Generally it is the part of the stream
81interface holding a file descriptor, but it can also be a processing block or a
82transformation block terminated by a connection. A connection presents a
83server-side interface.
84
85
862) Sequencing
87-------------
88
Ilya Shipitsin2075ca82020-03-06 23:22:22 +050089Upon startup, listeners are instantiated by the configuration. When an incoming
Willy Tarreau8263b912011-09-05 01:04:44 +020090connection reaches a listening file descriptor, its read() callback calls the
Ilya Shipitsin2075ca82020-03-06 23:22:22 +050091corresponding listener's accept() function which instantiates an initiator and
Willy Tarreau8263b912011-09-05 01:04:44 +020092in turn recursively calls upper layers' accept() callbacks until
Ilya Shipitsin2075ca82020-03-06 23:22:22 +050093accept_session() is called. accept_session() instantiates a new session which
Willy Tarreau8263b912011-09-05 01:04:44 +020094starts protocol analysis via process_session(). When all protocol analysis is
95done, process_session() calls the connect() callback of the connector in order
96to get a connection.