summaryrefslogtreecommitdiff
path: root/include/haproxy/connection-t.h
Commit message (Collapse)AuthorAgeFilesLines
* BUG/MAJOR: conn-idle: fix hash indexing issues on idle connsWilly Tarreau2022-10-031-3/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Idle connections do not work on 32-bit machines due to an alignment issue causing the connection nodes to be indexed with their lower 32-bits set to zero and the higher 32 ones containing the 32 lower bitss of the hash. The cause is the use of ebmb_node with an aligned data, as on this platform ebmb_node is only 32-bit aligned, leaving a hole before the following hash which is a uint64_t: $ pahole -C conn_hash_node ./haproxy struct conn_hash_node { struct ebmb_node node; /* 0 20 */ /* XXX 4 bytes hole, try to pack */ int64_t hash; /* 24 8 */ struct connection * conn; /* 32 4 */ /* size: 40, cachelines: 1, members: 3 */ /* sum members: 32, holes: 1, sum holes: 4 */ /* padding: 4 */ /* last cacheline: 40 bytes */ }; Instead, eb64 nodes should be used when it comes to simply storing a 64-bit key, and that is what this patch does. For backports, a variant consisting in simply marking the "hash" member with a "packed" attribute on the struct also does the job (tested), and might be preferable if the fix is difficult to adapt. Only 2.6 and 2.5 are affected by this.
* MINOR: flags/connection: use flag dumping for connection flagsWilly Tarreau2022-09-091-1/+27
| | | | | The new function is conn_show_flags(), it only deals with flags. Nothing is planned for connection error types at the moment.
* MINOR: muxes: add a "show_sd" helper to complete "show sess" dumpsWilly Tarreau2022-09-021-0/+1
| | | | | | | | This helper will be called for muxes that provide it and will be used to let the mux provide extra information about the stream attached to a stream descriptor. A line prefix is passed in argument so that the mux is free to break long lines without breaking indent. No prefix means no line breaks should be produced (e.g. for short dumps).
* CLEANUP: connection: rename all occurrences of stconn "cs" to "sc"Willy Tarreau2022-05-271-8/+8
| | | | | Function arguments and local variables called "cs" were renamed to "sc" to avoid future confusion.
* CLEANUP: muxes: rename "get_first_cs" to "get_first_sc"Willy Tarreau2022-05-271-1/+1
| | | | | This is renamed both in the mux_ops descriptor and the mux functions themselves to accommodate the new type name.
* REORG: stconn: rename conn_stream.{c,h} to stconn.{c,h}Willy Tarreau2022-05-271-2/+2
| | | | | | There's no more reason for keepin the code and definitions in conn_stream, let's move all that to stconn. The alphabetical ordering of include files was adjusted.
* CLEANUP: conn_stream: tree-wide rename to stconn (stream connector)Willy Tarreau2022-05-271-11/+11
| | | | | | | | This renames the "struct conn_stream" to "struct stconn" and updates the descriptions in all comments (and the rare help descriptions) to "stream connector" or "connector". This touches a lot of files but the change is minimal. The local variables were not even renamed, so there's still a lot of "cs" everywhere.
* CLEANUP: conn_stream: rename cs_endpoint to sedesc (stream endpoint descriptor)Willy Tarreau2022-05-271-3/+3
| | | | | | | | | | After some discussion we found that the cs_endpoint was precisely the descriptor for a stream endpoint, hence the naturally coming name, stream endpoint constructor. This patch renames only the type everywhere and the new/init/free functions to remain consistent with it. Future patches will address field names and argument names in various code areas.
* MINOR: connection: add flag MX_FL_FRAMED to mark muxes relying on framed xprtWilly Tarreau2022-05-201-0/+1
| | | | | | In order to be able to check compatibility between muxes and transport layers, we'll need a new flag to tag muxes that work on framed transport layers like QUIC. Only QUIC has this flag now.
* CLEANUP: muxes: make mux->attach/detach take a conn_stream endpointWilly Tarreau2022-05-131-2/+3
| | | | | | | | | | | | | | | | | | | | | | | The mux ->detach() function currently takes a conn_stream. This causes an awkward situation where the caller cs_detach_endp() has to partially mark it as released but not completely so that ->detach() finds its endpoint and context, and it cannot be done later since it's possible that ->detach() deletes the endpoint. As such the endpoint link between the conn_stream and the mux's stream is in a transient situation while we'd like it to be clean so that the mux's ->detach() code can call any regular function it wants that knows the regular semantics of the relation between the CS and the endpoint. A better approach consists in slightly modifying the detach() API to better match the reality, which is that the endpoint is detached but still alive and that it's the only part the function is interested in. As such, this patch modifies the function to take an endpoint there, and by analogy (or simplicity) does the same for ->attach(), even though it looks less important there since we're always attaching an endpoint to a conn_stream anyway. It is possible that in the future the API could evolve to use more endpoints that provide a bit more flexibility in the API, but at this point we don't need to go further.
* MINOR: connection: get rid of the CO_FL_ADDR_*_SET flagsWilly Tarreau2022-05-021-2/+2
| | | | | | | | | | Just like for the conn_stream, now that these addresses are dynamically allocated, there is no single case where the pointer is set without the corresponding flag, and the flag is used as a permission to dereference the pointer. Let's just replace the test of the flag with a test of the pointer and remove all flag assignment. This makes the code clearer (especially in "if" conditions) and saves the need for future code to think about properly setting the flag after setting the pointer.
* CLEANUP: muxes: Remove MX_FL_CLEAN_ABRT flagChristopher Faulet2022-04-131-4/+3
| | | | | This flag is unused. Thus, it may be removed. No reason to still set it. It also cleans up "haproxy -vv" output.
* MINOR: connection: unconst mux's get_fist_cs() callback functionChristopher Faulet2022-04-131-1/+1
| | | | This change is mandatory for next commits.
* MINOR: conn-stream/connection: Move SHR/SHW modes in the connection scopeChristopher Faulet2022-04-131-3/+14
| | | | | | These flags only concerns the connection part. In addition, it is required for a next commit, to avoid circular deps. Thus CS_SHR_* and CS_SHW_* were renamed with the "CO_" prefix.
* MEDIUM: quic: move conn->qc into conn->handleWilly Tarreau2022-04-111-3/+4
| | | | | | | | It was supposed to be there, and probably was not placed there due to historic limitations in listener_accept(), but now there does not seem to be a remaining valid reason for keeping the quic_conn out of the handle. In addition in new_quic_cli_conn() the handle->fd was incorrectly set to the listener's FD.
* MEDIUM: ssl: improve retrieval of ssl_sock_ctx and SSL detectionWilly Tarreau2022-04-111-0/+2
| | | | | | | | | | | | | | | Historically there was a single way to have an SSL transport on a connection, so detecting if the transport layer was SSL and a context was present was sufficient to detect SSL. With QUIC, things have changed because QUIC also relies on SSL, but the context is embedded inside the quic_conn and the transport layer doesn't match expectations outside, making it difficult to detect that SSL is in use over the connection. The approach taken here to improve this consists in adding a new method at the transport layer, get_ssl_sock_ctx(), to retrieve this often needed ssl_sock_ctx, and to use this to detect the presence of SSL. This will even allow some simplifications and cleanups to be made in the SSL code itself, and QUIC will be able to provide one to export its ssl_sock_ctx.
* MINOR: connection: add a new flag CO_FL_FDLESS on fd-less connectionsWilly Tarreau2022-04-111-0/+2
| | | | | | | | | | | | | | | QUIC connections do not use a file descriptor, instead they use the quic equivalent which is the quic_conn. A number of our historical functions at the connection level continue to unconditionally touch the file descriptor and this may have consequences once QUIC starts to be used. This patch adds a new flag on QUIC connections, CO_FL_FDLESS, to mention that the connection doesn't have a file descriptor, hence the FD-based API must never be used on them. From now on it will be possible to intrument existing functions to panic when this flag is present.
* REORG: conn_stream: move conn-stream stuff in dedicated filesChristopher Faulet2022-02-241-69/+1
| | | | Move code dealing with the conn-streams in dedicated files.
* MEDIUM: stream: No longer release backend conn-stream on connection retryChristopher Faulet2022-02-241-1/+1
| | | | | | | | | | | | The backend conn-stream is no longer released on connection retry. This means the conn-stream is detached from the underlying connection but not released. Thus, during connection retries, the stream has always an allocated conn-stream with no connection. All previous changes were made to make this possible. Note that .attach() mux callback function was changed to get the conn-stream as argument. The muxes are no longer responsible to create the conn-stream when a server connection is attached to a stream.
* MAJOR: mux-quic: implement a simplified mux versionAmaury Denoyelle2021-12-071-4/+0
| | | | | | | | | Re-implement the QUIC mux. It will reuse the mechanics from the previous mux without all untested/unsupported features. This should ease the maintenance. Note that a lot of features are broken for the moment. They will be re-implemented on the following commits to have a clean commit history.
* MEDIUM: connection: rename fc_conn_err and bc_conn_err to fc_err and bc_errWilly Tarreau2021-11-061-2/+2
| | | | | | | | | | | | | Commit 3d2093af9 ("MINOR: connection: Add a connection error code sample fetch") added these convenient sample-fetch functions but it appears that due to a misunderstanding the redundant "conn" part was kept in their name, causing confusion, since "fc" already stands for "front connection". Let's simply call them "fc_err" and "bc_err" to match all other related ones before they appear in a final release. The VTC they appeared in were also updated, and the alpha sort in the keywords table updated. Cc: William Lallemand <wlallemand@haproxy.org>
* MINOR: stream/mux: implement websocket stream flagAmaury Denoyelle2021-11-031-0/+3
| | | | | | | | | | Define a new stream flag SF_WEBSOCKET and a new cs flag CS_FL_WEBSOCKET. The conn-stream flag is first set by h1/h2 muxes if the request is a valid websocket upgrade. The flag is then converted to SF_WEBSOCKET on the stream creation. This will be useful to properly manage websocket streams in connect_server().
* MINOR: connection: add a new CO_FL_WANT_DRAIN flag to force drain on closeWilly Tarreau2021-10-211-1/+1
| | | | | | | | | | Sometimes we'd like to do our best to drain pending data before closing in order to save the peer from risking to receive an RST on close. This adds a new connection flag CO_FL_WANT_DRAIN that is used to trigger a call to conn_ctrl_drain() from conn_ctrl_close(), and the sock_drain() function ignores fd_recv_ready() if this flag is set, in order to catch latest data. It's not used for now.
* CLEANUP: tree-wide: only include ebtree-t from type filesWilly Tarreau2021-10-071-1/+1
| | | | | | No need to include the full tree management code, type files only need the definitions. Doing so reduces the whole code size by around 3.6% and the build time is down to just 6s.
* MINOR: connection: use uint64_t for the hashesWilly Tarreau2021-10-071-3/+2
| | | | | | | | The hash type stored everywhere is XXH64_hash_t, which annoyingly forces everyone to include the huge xxhash file. We know it's an uint64_t because that's its purpose and the type is only made to abstract it on machines where uint64_t is not availble. Let's switch the type to uint64_t everywhere and avoid including xxhash from the type file.
* MINOR: ssl: Set connection error code in case of SSL read or write fatal failureRemi Tricot-Le Breton2021-09-301-0/+2
| | | | | | | | | | | | | | | | In case of a connection error happening after the SSL handshake is completed, the error code stored in the connection structure would not always be set, hence having some connection failures being described as successful in the fc_conn_err or bc_conn_err sample fetches. The most common case in which it could happen is when the SSL server rejects the client's certificate. The SSL_do_handshake call on the client side would be sucessful because the client effectively sent its client hello and certificate information to the server, but the next call to SSL_read on the client side would raise an SSL_ERROR_SSL code (through the SSL_get_error function) which is decribed in OpenSSL documentation as a non-recoverable and fatal SSL error. This patch ensures that in such a case, the connection's error code is set to a special CO_ERR_SSL_FATAL value.
* MINOR: stream-int: Notify mux when the buffer is not stuck when calling rcv_bufChristopher Faulet2021-09-231-4/+5
| | | | | | | | | | | | | | The transient flag CO_RFL_BUF_NOT_STUCK should now be set when the mux's rcv_buf() function is called, in si_cs_recv(), to be sure the mux is able to perform some optimisation during data copy. This flag is set when we are sure the channel buffer is not stuck. Concretely, it happens when there are data scheduled to be sent. It is not a fix and this flag is not used for now. But it makes sense to have this info to be sure to be able to do some optimisations if necessary. This patch is related to the issue #1362. It may be backported to 2.4 to ease future backports.
* MINOR: connection: Add callbacks definitions for QUIC.Frédéric Lécaille2021-09-231-0/+7
| | | | | | The flow control at stream level is organized by types (client bidi, server bidi, client uni, server uni). Adds at least callback to retrieve the number of available streams by direction.
* CLEANUP: Add haproxy/xxhash.h to avoid modifying import/xxhash.hTim Duesterhus2021-09-111-1/+1
| | | | | | | This solves setting XXH_INLINE_ALL in a cleaner way, because the imported header is not modified, easing future updates. see 6f7cc11e6dd0f01b437fba893da2edd2362660a2
* MINOR: connection: Add a connection error code sample fetchRemi Tricot-Le Breton2021-07-291-1/+5
| | | | | | | | | The fc_conn_err and fc_conn_err_str sample fetches give information about the problem that made the connection fail. This information would previously only have been given by the error log messages meaning that thanks to these fetches, the error log can now be included in a custom log format. The log strings were all found in the conn_err_code_str function.
* BUILD: connection: stop including listener-t.hWilly Tarreau2021-05-081-1/+2
| | | | | | | | listener-t comes with openssl just due to the SSL_CTX type that is declred as a typedef in openssl hence cannot be abstracted at this level. However connection-t.h doen't need all that just to know that bind_conf is a struct. Let's declare it with other external types instead..
* MINOR: conn-stream: Force mux to wait for read events if abortonclose is setChristopher Faulet2021-05-061-0/+1
| | | | | | | | | | When the abortonclose option is enabled, to be sure to be immediately notified when a shutdown is received from the client, the frontend conn-stream must be sure the mux will wait for read events. To do so, the CO_RFL_KEEP_RECV flag is set when mux->rcv_buf() is called. This new flag instructs the mux to wait for read events, regardless its internal state. This patch is required to fix abortonclose option for H1 client connections.
* MEDIUM: connection: close front idling connection on soft-stopAmaury Denoyelle2021-05-051-0/+9
| | | | | | | | | | | | | Implement a safe mechanism to close front idling connection which prevents the soft-stop to complete. Every h1/h2 front connection is added in a new per-thread list instance. On shutdown, a new task is waking up which calls wake mux operation on every connection still present in the new list. A new stopping_list attach point has been added in the connection structure. As this member is only used for frontend connections, it shared the same union as the session_list reserved for backend connections.
* MINOR: connection: move session_list member in a unionAmaury Denoyelle2021-05-051-1/+3
| | | | | | | | | | | Move the session_list attach point in an anonymous union. This member is only used for backend connections. This commit is in preparation for the support of stopping frontend idling connections which will add another member to the union. This change means that a special care must be taken to be sure that only backend connections manipulate the session_list. A few BUG_ON has been added as special guard to prevent from misuse.
* MINOR: muxes: Add a flag to notify a mux does not support any upgradeChristopher Faulet2021-04-011-0/+1
| | | | | | | MX_FL_NO_UPG flag may now be set on a multiplexer to explicitly disable upgrades from this mux. For now, it is set on the FCGI multiplexer because it is not supported and there is no upgrade on backend-only multiplexers. It is also set on the H2 multiplexer because it is clearly not supported.
* MINOR: muxes: garbage collect the reset() method.Olivier Houchard2021-03-191-1/+0
| | | | | | Now that connections aren't being reused when they failed, remove the reset() method. It was unimplemented anywhere, except for H1 where it did nothing, anyway.
* MEDIUM: connections: Introduce a new XPRT method, start().Olivier Houchard2021-03-191-1/+2
| | | | | | | | | | | Introduce a new XPRT method, start(). The init() method will now only initialize whatever is needed for the XPRT to run, but any action the XPRT has to do before being ready, such as handshakes, will be done in the new start() method. That way, we will be sure the full stack of xprt will be initialized before attempting to do anything. The init() call is also moved to conn_prepare(). There's no longer any reason to wait for the ctrl to be ready, any action will be deferred until start(), anyway. This means conn_xprt_init() is no longer needed.
* BUILD: connection: do not use VAR_ARRAY in struct tlvWilly Tarreau2021-03-091-1/+1
| | | | | | | | | | It was brought by commit c44b8de99 ("CLEANUP: connection: Use `VAR_ARRAY` in `struct tlv` definition") but breaks the build with clang. Actually it had already been done 6 months ago by commit 4987a4744 ("CLEANUP: tree-wide: use VAR_ARRAY instead of [0] in various definitions") then reverted by commit 441b6c31e ("BUILD: connection: fix build on clang after the VAR_ARRAY cleanup") which explained the same thing but didn't place a comment in the code to justify this (in short it's just an end of struct marker).
* MINOR: connection: Use a `struct ist` to store proxy_authorityTim Duesterhus2021-03-091-3/+2
| | | | | This makes the code cleaner, because proxy_authority can be handled like proxy_unique_id.
* CLEANUP: connection: Use `VAR_ARRAY` in `struct tlv` definitionTim Duesterhus2021-03-091-1/+1
| | | | This is for consistency with `struct tlv_ssl`.
* MINOR: xprt: add new xprt_set_idle and xprt_set_used methodsWilly Tarreau2021-03-051-0/+2
| | | | | | | | | | | | These functions are used on the mux layer to indicate that the connection is becoming idle and that the xprt ought to be careful before checking the context or that it's not idle anymore and that the context is safe. The purpose is to allow a mux which is going to release a connection to tell the xprt to be careful when touching it. At the moment, the xprt are always careful and that's costly so we want to have the ability to relax this a bit. No xprt layer uses this yet.
* MINOR: backend: handle reuse for conns with no server as targetAmaury Denoyelle2021-03-031-1/+1
| | | | | | | | | | | | | | | | | | | | | | | If dispatch mode or transparent backend is used, the backend connection target is a proxy instead of a server. In these cases, the reuse of backend connections is not consistent. With the default behavior, no reuse is done and every new request uses a new connection. However, if http-reuse is set to never, the connection are stored by the mux in the session and can be reused for future requests in the same session. As no server is used for these connections, no reuse can be made outside of the session, similarly to http-reuse never mode. A different http-reuse config value should not have an impact. To achieve this, mark these connections as private to have a defined behavior. For this feature to properly work, the connection hash has been slightly adjusted. The server pointer as an input as been replaced by a generic target pointer to refer to the server or proxy instance. The hash is always calculated on connect_server even if the connection target is not a server. This also requires to allocate the connection hash node for every backend connections, not just the one with a server target.
* MINOR: connection: allocate dynamically hash node for backend connsAmaury Denoyelle2021-02-191-3/+14
| | | | | | | | Remove ebmb_node entry from struct connection and create a dedicated struct conn_hash_node. struct connection contains now only a pointer to a conn_hash_node, allocated only for connections where target is of type OBJ_TYPE_SERVER. This will reduce memory footprints for every connections that does not need http-reuse such as frontend connections.
* MINOR: connection: remove pointers for prehash in conn_hash_paramsAmaury Denoyelle2021-02-171-2/+2
| | | | | Replace unneeded pointers for sni/proxy prehash by plain data type. The code is slightly cleaner.
* MINOR: connection: use proxy protocol as parameter for srv conn hashAmaury Denoyelle2021-02-121-1/+3
| | | | | | | | | | | | Use the proxy protocol frame if proxy protocol is activated on the server line. Do not add anymore these connections in the private list. If some requests are made with the same proxy fields, they can reuse the idle connection. The reg-tests proxy_protocol_send_unique_id must be adapted has it relied on the side effect behavior that every requests from a same connection reused a private server connection. Now, a new connection is created as expected if the proxy protocol fields differ.
* MINOR: connection: use src addr as parameter for srv conn hashAmaury Denoyelle2021-02-121-1/+4
| | | | | | | | The source address is used as an input to the the server connection hash. The address and port are used as separate hash inputs. Do not add anymore these connections in the private list. This parameter is set only if used in the transparent-proxy mode.
* MINOR: connection: use dst addr as parameter for srv conn hashAmaury Denoyelle2021-02-121-2/+5
| | | | | | | | | | | | The destination address is used as an input to the server connection hash. The address and port are used as separated hash inputs. Note that they are not used when statically specified on the server line. This is only useful for dynamic destination address. This is typically used when the server address is dynamically set via the set-dst action. The address and port are separated hash parameters. Most notably, it should fixed set-dst use case (cf github issue #947).
* MINOR: connection: use sni as parameter for srv conn hashAmaury Denoyelle2021-02-121-2/+3
| | | | | | The sni parameter is an input to the server connection hash. Do not add anymore connections with dynamic sni in the private list. Thus, it is now possible to reuse a server connection if they use the same sni.
* MINOR: connection: use the srv pointer for the srv conn hashAmaury Denoyelle2021-02-121-0/+1
| | | | | | | The pointer of the target server is used as a first parameter for the server connection hash calcul. This prevents the hash to be null when no specific parameters are present, and can serve as a simple defense against an attacker trying to reuse a non-conform connection.
* MINOR: connection: prepare hash calcul for server connsAmaury Denoyelle2021-02-121-0/+23
| | | | | | | | | | This is a preliminary work for the calcul of the backend connection hash. A structure conn_hash_params is the input for the operation, containing the various specific parameters of a connection. The high bits of the hash will reflect the parameters present as input. A set of macros is written to manipulate the connection hash and extract the parameters/payload.