2015-04-03 07:53:24 -04:00
|
|
|
/*
|
2015-04-04 12:50:31 -04:00
|
|
|
* Session management functions.
|
2015-04-03 07:53:24 -04:00
|
|
|
*
|
2015-04-04 12:50:31 -04:00
|
|
|
* Copyright 2000-2015 Willy Tarreau <w@1wt.eu>
|
2015-04-03 07:53:24 -04:00
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
|
* as published by the Free Software Foundation; either version
|
|
|
|
|
* 2 of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2023-05-12 11:13:46 -04:00
|
|
|
#include <haproxy/ssl_sock-t.h>
|
|
|
|
|
|
2020-05-27 06:58:42 -04:00
|
|
|
#include <haproxy/api.h>
|
2020-06-04 12:02:10 -04:00
|
|
|
#include <haproxy/connection.h>
|
2020-06-04 11:05:57 -04:00
|
|
|
#include <haproxy/global.h>
|
2020-06-02 13:11:26 -04:00
|
|
|
#include <haproxy/http.h>
|
2020-06-04 08:58:24 -04:00
|
|
|
#include <haproxy/listener.h>
|
2020-06-04 16:01:04 -04:00
|
|
|
#include <haproxy/log.h>
|
2020-06-02 03:38:52 -04:00
|
|
|
#include <haproxy/pool.h>
|
2020-06-04 16:29:18 -04:00
|
|
|
#include <haproxy/proxy.h>
|
2020-06-04 12:58:52 -04:00
|
|
|
#include <haproxy/session.h>
|
2020-06-04 11:42:48 -04:00
|
|
|
#include <haproxy/tcp_rules.h>
|
2021-05-08 07:03:04 -04:00
|
|
|
#include <haproxy/tools.h>
|
2020-06-04 10:25:31 -04:00
|
|
|
#include <haproxy/vars.h>
|
2015-04-03 07:53:24 -04:00
|
|
|
|
2015-04-04 10:31:16 -04:00
|
|
|
|
2018-11-26 05:58:30 -05:00
|
|
|
DECLARE_POOL(pool_head_session, "session", sizeof(struct session));
|
2018-12-27 11:20:54 -05:00
|
|
|
DECLARE_POOL(pool_head_sess_srv_list, "session server list",
|
|
|
|
|
sizeof(struct sess_srv_list));
|
2015-04-03 07:53:24 -04:00
|
|
|
|
2020-01-22 12:08:48 -05:00
|
|
|
int conn_complete_session(struct connection *conn);
|
2015-04-04 12:50:31 -04:00
|
|
|
|
2015-04-04 18:38:48 -04:00
|
|
|
/* Create a a new session and assign it to frontend <fe>, listener <li>,
|
|
|
|
|
* origin <origin>, set the current date and clear the stick counters pointers.
|
|
|
|
|
* Returns the session upon success or NULL. The session may be released using
|
2017-09-15 04:25:14 -04:00
|
|
|
* session_free(). Note: <li> may be NULL.
|
2015-04-04 18:38:48 -04:00
|
|
|
*/
|
|
|
|
|
struct session *session_new(struct proxy *fe, struct listener *li, enum obj_type *origin)
|
|
|
|
|
{
|
|
|
|
|
struct session *sess;
|
|
|
|
|
|
2017-11-24 11:34:44 -05:00
|
|
|
sess = pool_alloc(pool_head_session);
|
2015-04-04 18:38:48 -04:00
|
|
|
if (sess) {
|
|
|
|
|
sess->listener = li;
|
|
|
|
|
sess->fe = fe;
|
|
|
|
|
sess->origin = origin;
|
|
|
|
|
sess->accept_date = date; /* user-visible date for logging */
|
2023-04-28 03:16:15 -04:00
|
|
|
sess->accept_ts = now_ns; /* corrected date for internal use */
|
2023-01-06 10:09:58 -05:00
|
|
|
sess->stkctr = NULL;
|
|
|
|
|
if (pool_head_stk_ctr) {
|
|
|
|
|
sess->stkctr = pool_alloc(pool_head_stk_ctr);
|
|
|
|
|
if (!sess->stkctr)
|
|
|
|
|
goto out_fail_alloc;
|
|
|
|
|
memset(sess->stkctr, 0, sizeof(sess->stkctr[0]) * global.tune.nb_stk_ctr);
|
|
|
|
|
}
|
2021-08-31 02:13:25 -04:00
|
|
|
vars_init_head(&sess->vars, SCOPE_SESS);
|
2017-08-28 13:02:51 -04:00
|
|
|
sess->task = NULL;
|
2018-09-05 05:56:48 -04:00
|
|
|
sess->t_handshake = -1; /* handshake not done yet */
|
2020-09-30 04:28:02 -04:00
|
|
|
sess->t_idle = -1;
|
2021-04-06 07:53:36 -04:00
|
|
|
_HA_ATOMIC_INC(&totalconn);
|
|
|
|
|
_HA_ATOMIC_INC(&jobs);
|
2018-12-27 11:20:54 -05:00
|
|
|
LIST_INIT(&sess->srv_list);
|
2018-12-28 12:50:57 -05:00
|
|
|
sess->idle_conns = 0;
|
2019-05-29 09:01:50 -04:00
|
|
|
sess->flags = SESS_FL_NONE;
|
2021-10-22 09:41:57 -04:00
|
|
|
sess->src = NULL;
|
|
|
|
|
sess->dst = NULL;
|
2015-04-04 18:38:48 -04:00
|
|
|
}
|
|
|
|
|
return sess;
|
2023-01-06 10:09:58 -05:00
|
|
|
out_fail_alloc:
|
|
|
|
|
pool_free(pool_head_session, sess);
|
|
|
|
|
return NULL;
|
2015-04-04 18:38:48 -04:00
|
|
|
}
|
|
|
|
|
|
2015-04-04 09:54:03 -04:00
|
|
|
void session_free(struct session *sess)
|
|
|
|
|
{
|
2018-11-30 11:24:55 -05:00
|
|
|
struct connection *conn, *conn_back;
|
2018-12-27 11:20:54 -05:00
|
|
|
struct sess_srv_list *srv_list, *srv_list_back;
|
2018-11-13 10:48:36 -05:00
|
|
|
|
2017-10-18 09:01:14 -04:00
|
|
|
if (sess->listener)
|
|
|
|
|
listener_release(sess->listener);
|
2015-04-04 10:31:16 -04:00
|
|
|
session_store_counters(sess);
|
2023-01-06 10:09:58 -05:00
|
|
|
pool_free(pool_head_stk_ctr, sess->stkctr);
|
2015-06-19 05:59:02 -04:00
|
|
|
vars_prune_per_sess(&sess->vars);
|
2018-11-13 10:48:36 -05:00
|
|
|
conn = objt_conn(sess->origin);
|
|
|
|
|
if (conn != NULL && conn->mux)
|
2019-04-08 05:23:22 -04:00
|
|
|
conn->mux->destroy(conn->ctx);
|
2018-12-27 11:20:54 -05:00
|
|
|
list_for_each_entry_safe(srv_list, srv_list_back, &sess->srv_list, srv_list) {
|
|
|
|
|
list_for_each_entry_safe(conn, conn_back, &srv_list->conn_list, session_list) {
|
2019-11-15 01:04:24 -05:00
|
|
|
LIST_DEL_INIT(&conn->session_list);
|
2018-11-30 11:24:55 -05:00
|
|
|
if (conn->mux) {
|
|
|
|
|
conn->owner = NULL;
|
2019-01-31 13:31:19 -05:00
|
|
|
conn->flags &= ~CO_FL_SESS_IDLE;
|
2020-01-20 07:56:01 -05:00
|
|
|
conn->mux->destroy(conn->ctx);
|
2018-11-30 11:24:55 -05:00
|
|
|
} else {
|
|
|
|
|
/* We have a connection, but not yet an associated mux.
|
|
|
|
|
* So destroy it now.
|
|
|
|
|
*/
|
|
|
|
|
conn_stop_tracking(conn);
|
|
|
|
|
conn_full_close(conn);
|
|
|
|
|
conn_free(conn);
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-12-27 11:20:54 -05:00
|
|
|
pool_free(pool_head_sess_srv_list, srv_list);
|
2018-11-20 18:16:29 -05:00
|
|
|
}
|
2021-10-22 09:41:57 -04:00
|
|
|
sockaddr_free(&sess->src);
|
|
|
|
|
sockaddr_free(&sess->dst);
|
2017-11-24 11:34:44 -05:00
|
|
|
pool_free(pool_head_session, sess);
|
2021-04-06 07:53:36 -04:00
|
|
|
_HA_ATOMIC_DEC(&jobs);
|
2015-04-04 09:54:03 -04:00
|
|
|
}
|
|
|
|
|
|
2017-10-08 05:26:30 -04:00
|
|
|
/* callback used from the connection/mux layer to notify that a connection is
|
2018-11-25 14:22:10 -05:00
|
|
|
* going to be released.
|
2017-10-08 05:26:30 -04:00
|
|
|
*/
|
|
|
|
|
void conn_session_free(struct connection *conn)
|
|
|
|
|
{
|
|
|
|
|
session_free(conn->owner);
|
BUG/MAJOR: connection: reset conn->owner when detaching from session list
Baptiste reported a new crash affecting 2.3 which can be triggered
when using H2 on the backend, with http-reuse always and with a tens
of clients doing close only. There are a few combined cases which cause
this to happen, but each time the issue is the same, an already freed
session is dereferenced in session_unown_conn().
Two cases were identified to cause this:
- a connection referencing a session as its owner, which is detached
from the session's list and is destroyed after this session ends.
The test on conn->owner before calling session_unown_conn() is not
sufficent as the pointer is not null but is not valid anymore.
- a connection that never goes idle and that gets killed form the
mux, where session_free() is called first, then conn_free() calls
session_unown_conn() which scans the just freed session for older
connections. This one is only triggered with DEBUG_UAF
The reason for this session to be present here is that it's needed during
the connection setup, to be passed to conn_install_mux_be() to mux->init()
as the owning session, but it's never deleted aftrewards. Furthermore, even
conn_session_free() doesn't delete this pointer after freeing the session
that lies there. Both do definitely result in a use-after-free that's more
easily triggered under DEBUG_UAF.
This patch makes sure that the owner is always deleted after detaching
or killing the session. However it is currently not possible to clear
the owner right after a synchronous init because the proxy protocol
apparently needs it (a reg test checks this), and if we leave it past
the connection setup with the session not attached anywhere, it's hard
to catch the right moment to detach it. This means that the session may
remain in conn->owner as long as the connection has never been added to
nor removed from the session's idle list. Given that this patch needs to
remain simple enough to be backported, instead it adds a workaround in
session_unown_conn() to detect that the element is already not attached
anywhere.
This fix absolutely requires previous patch "CLEANUP: connection: do not
use conn->owner when the session is known" otherwise the situation will
be even worse, as some places used to rely on conn->owner instead of the
session.
The fix could theorically be backported as far as 1.8. However, the code
in this area has significantly changed along versions and there are more
risks of breaking working stuff than fixing real issues there. The issue
was really woken up in two steps during 2.3-dev when slightly reworking
the idle conns with commit 08016ab82 ("MEDIUM: connection: Add private
connections synchronously in session server list") and when adding
support for storing used H2 connections in the session and adding the
necessary call to session_unown_conn() in the muxes. But the same test
managed to crash 2.2 when built in DEBUG_UAF and patched like this,
proving that we used to already leave dangling pointers behind us:
| diff --git a/include/haproxy/connection.h b/include/haproxy/connection.h
| index f8f235c1a..dd30b5f80 100644
| --- a/include/haproxy/connection.h
| +++ b/include/haproxy/connection.h
| @@ -458,6 +458,10 @@ static inline void conn_free(struct connection *conn)
| sess->idle_conns--;
| session_unown_conn(sess, conn);
| }
| + else {
| + struct session *sess = conn->owner;
| + BUG_ON(sess && sess->origin != &conn->obj_type);
| + }
|
| sockaddr_free(&conn->src);
| sockaddr_free(&conn->dst);
It's uncertain whether an existing code path there can lead to dereferencing
conn->owner when it's bad, though certain suspicious memory corruption bugs
make one think it's a likely candidate. The patch should not be hard to
adapt there.
Backports to 2.1 and older are left to the appreciation of the person
doing the backport.
A reproducer consists in this:
global
nbthread 1
listen l
bind :9000
mode http
http-reuse always
server s 127.0.0.1:8999 proto h2
frontend f
bind :8999 proto h2
mode http
http-request return status 200
Then this will make it crash within 2-3 seconds:
$ h1load -e -r 1 -c 10 http://0:9000/
If it does not, it might be that DEBUG_UAF was not used (it's harder then)
and it might be useful to restart.
2020-11-20 11:22:44 -05:00
|
|
|
conn->owner = NULL;
|
2017-10-08 05:26:30 -04:00
|
|
|
}
|
|
|
|
|
|
2015-04-08 12:10:49 -04:00
|
|
|
/* count a new session to keep frontend, listener and track stats up to date */
|
|
|
|
|
static void session_count_new(struct session *sess)
|
|
|
|
|
{
|
|
|
|
|
struct stkctr *stkctr;
|
|
|
|
|
void *ptr;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
proxy_inc_fe_sess_ctr(sess->listener, sess->fe);
|
|
|
|
|
|
2023-01-06 10:09:58 -05:00
|
|
|
for (i = 0; i < global.tune.nb_stk_ctr; i++) {
|
2015-04-08 12:10:49 -04:00
|
|
|
stkctr = &sess->stkctr[i];
|
|
|
|
|
if (!stkctr_entry(stkctr))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_SESS_CNT);
|
|
|
|
|
if (ptr)
|
2021-06-30 11:18:28 -04:00
|
|
|
HA_ATOMIC_INC(&stktable_data_cast(ptr, std_t_uint));
|
2015-04-08 12:10:49 -04:00
|
|
|
|
|
|
|
|
ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_SESS_RATE);
|
|
|
|
|
if (ptr)
|
2021-06-30 11:18:28 -04:00
|
|
|
update_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp),
|
2015-04-08 12:10:49 -04:00
|
|
|
stkctr->table->data_arg[STKTABLE_DT_SESS_RATE].u, 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-04 12:50:31 -04:00
|
|
|
/* This function is called from the protocol layer accept() in order to
|
2018-06-21 12:03:20 -04:00
|
|
|
* instantiate a new session on behalf of a given listener and frontend. It
|
2015-04-04 12:50:31 -04:00
|
|
|
* returns a positive value upon success, 0 if the connection can be ignored,
|
2020-10-14 11:37:17 -04:00
|
|
|
* or a negative value upon critical failure. The accepted connection is
|
2015-04-04 12:50:31 -04:00
|
|
|
* closed if we return <= 0. If no handshake is needed, it immediately tries
|
2020-10-14 11:37:17 -04:00
|
|
|
* to instantiate a new stream. The connection must already have been filled
|
|
|
|
|
* with the incoming connection handle (a fd), a target (the listener) and a
|
|
|
|
|
* source address.
|
2015-04-04 12:50:31 -04:00
|
|
|
*/
|
2020-10-14 11:37:17 -04:00
|
|
|
int session_accept_fd(struct connection *cli_conn)
|
2015-04-04 12:50:31 -04:00
|
|
|
{
|
2020-10-14 11:37:17 -04:00
|
|
|
struct listener *l = __objt_listener(cli_conn->target);
|
2016-12-21 18:13:31 -05:00
|
|
|
struct proxy *p = l->bind_conf->frontend;
|
2020-10-14 11:37:17 -04:00
|
|
|
int cfd = cli_conn->handle.fd;
|
2015-04-04 12:50:31 -04:00
|
|
|
struct session *sess;
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
ret = -1; /* assume unrecoverable error by default */
|
|
|
|
|
|
2020-09-03 01:50:19 -04:00
|
|
|
cli_conn->proxy_netns = l->rx.settings->netns;
|
2015-04-04 12:50:31 -04:00
|
|
|
|
2023-08-23 12:02:51 -04:00
|
|
|
/* Active reversed connection has already been initialized before being
|
2023-11-21 13:54:16 -05:00
|
|
|
* accepted. It must not be reset.
|
2023-08-23 12:02:51 -04:00
|
|
|
* TODO use a dedicated accept_fd callback for reverse protocol
|
|
|
|
|
*/
|
|
|
|
|
if (!cli_conn->xprt) {
|
|
|
|
|
if (conn_prepare(cli_conn, l->rx.proto, l->bind_conf->xprt) < 0)
|
|
|
|
|
goto out_free_conn;
|
2021-03-05 17:37:48 -05:00
|
|
|
|
2023-08-23 12:02:51 -04:00
|
|
|
conn_ctrl_init(cli_conn);
|
2015-04-04 12:50:31 -04:00
|
|
|
|
2023-08-23 12:02:51 -04:00
|
|
|
/* wait for a PROXY protocol header */
|
|
|
|
|
if (l->bind_conf->options & BC_O_ACC_PROXY)
|
|
|
|
|
cli_conn->flags |= CO_FL_ACCEPT_PROXY;
|
2015-04-04 12:50:31 -04:00
|
|
|
|
2023-08-23 12:02:51 -04:00
|
|
|
/* wait for a NetScaler client IP insertion protocol header */
|
|
|
|
|
if (l->bind_conf->options & BC_O_ACC_CIP)
|
|
|
|
|
cli_conn->flags |= CO_FL_ACCEPT_CIP;
|
2016-06-04 10:11:10 -04:00
|
|
|
|
2023-08-23 12:02:51 -04:00
|
|
|
/* Add the handshake pseudo-XPRT */
|
|
|
|
|
if (cli_conn->flags & (CO_FL_ACCEPT_PROXY | CO_FL_ACCEPT_CIP)) {
|
|
|
|
|
if (xprt_add_hs(cli_conn) != 0)
|
|
|
|
|
goto out_free_conn;
|
|
|
|
|
}
|
2019-05-27 06:09:19 -04:00
|
|
|
}
|
2023-08-23 12:02:51 -04:00
|
|
|
|
2015-04-04 18:39:16 -04:00
|
|
|
sess = session_new(p, l, &cli_conn->obj_type);
|
2015-04-04 12:50:31 -04:00
|
|
|
if (!sess)
|
|
|
|
|
goto out_free_conn;
|
|
|
|
|
|
2017-10-08 05:16:46 -04:00
|
|
|
conn_set_owner(cli_conn, sess, NULL);
|
2017-08-28 13:02:51 -04:00
|
|
|
|
2015-04-04 12:50:31 -04:00
|
|
|
/* now evaluate the tcp-request layer4 rules. We only need a session
|
|
|
|
|
* and no stream for these rules.
|
|
|
|
|
*/
|
2023-01-12 14:03:38 -05:00
|
|
|
if (!LIST_ISEMPTY(&p->tcp_req.l4_rules) && !tcp_exec_l4_rules(sess)) {
|
2015-04-04 12:50:31 -04:00
|
|
|
/* let's do a no-linger now to close with a single RST. */
|
BUG/MEDIUM: quic: fix crash when "option nolinger" is set in the frontend
Commit 0aba11e9e ("MINOR: quic: remove unnecessary quic_session_accept()")
overlooked one problem, in session_accept_fd() at the end, there's a bunch
of FD-specific stuff that either sets up or resets the socket at the TCP
level. The tests are mostly performed for AF_INET/AF_INET6 families but
they're only for one part (i.e. to avoid setting up TCP options on UNIX
sockets). Other pieces continue to configure the socket regardless of its
family. All of this directly acts on the FD, which is not correct since
the FD is not valid here, it corresponds to the QUIC handle. The issue
is much more visible when "option nolinger" is enabled in the frontend,
because the access to fdatb[cfd].state immediately crashes on the first
connection, as can be seen in github issue #2030.
This patch bypasses this setup for FD-less connections, such as QUIC.
However some of them could definitely be relevant to the QUIC stack, or
even to UNIX sockets sometimes. A better long-term solution would consist
in implementing a setsockopt() equivalent at the protocol layer that would
be used to configure the socket, either the FD or the QUIC conn depending
on the case. Some of them would not always be implemented but that would
allow to unify all this code.
This fix must be backported everywhere the commit above is backported,
namely 2.6 and 2.7.
Thanks to github user @twomoses for the nicely detailed report.
2023-02-09 11:53:41 -05:00
|
|
|
if (!(cli_conn->flags & CO_FL_FDLESS))
|
|
|
|
|
setsockopt(cfd, SOL_SOCKET, SO_LINGER, (struct linger *) &nolinger, sizeof(struct linger));
|
2015-04-04 12:50:31 -04:00
|
|
|
ret = 0; /* successful termination */
|
|
|
|
|
goto out_free_sess;
|
|
|
|
|
}
|
2021-03-05 17:37:48 -05:00
|
|
|
/* TCP rules may flag the connection as needing proxy protocol, now that it's done we can start ourxprt */
|
|
|
|
|
if (conn_xprt_start(cli_conn) < 0)
|
2022-03-11 01:25:11 -05:00
|
|
|
goto out_free_sess;
|
2015-04-04 12:50:31 -04:00
|
|
|
|
BUG/MEDIUM: quic: fix crash when "option nolinger" is set in the frontend
Commit 0aba11e9e ("MINOR: quic: remove unnecessary quic_session_accept()")
overlooked one problem, in session_accept_fd() at the end, there's a bunch
of FD-specific stuff that either sets up or resets the socket at the TCP
level. The tests are mostly performed for AF_INET/AF_INET6 families but
they're only for one part (i.e. to avoid setting up TCP options on UNIX
sockets). Other pieces continue to configure the socket regardless of its
family. All of this directly acts on the FD, which is not correct since
the FD is not valid here, it corresponds to the QUIC handle. The issue
is much more visible when "option nolinger" is enabled in the frontend,
because the access to fdatb[cfd].state immediately crashes on the first
connection, as can be seen in github issue #2030.
This patch bypasses this setup for FD-less connections, such as QUIC.
However some of them could definitely be relevant to the QUIC stack, or
even to UNIX sockets sometimes. A better long-term solution would consist
in implementing a setsockopt() equivalent at the protocol layer that would
be used to configure the socket, either the FD or the QUIC conn depending
on the case. Some of them would not always be implemented but that would
allow to unify all this code.
This fix must be backported everywhere the commit above is backported,
namely 2.6 and 2.7.
Thanks to github user @twomoses for the nicely detailed report.
2023-02-09 11:53:41 -05:00
|
|
|
/* FIXME/WTA: we should implement the setsockopt() calls at the proto
|
|
|
|
|
* level instead and let non-inet protocols implement their own equivalent.
|
|
|
|
|
*/
|
|
|
|
|
if (cli_conn->flags & CO_FL_FDLESS)
|
|
|
|
|
goto skip_fd_setup;
|
|
|
|
|
|
2015-04-05 11:56:47 -04:00
|
|
|
/* Adjust some socket options */
|
2020-08-27 01:48:42 -04:00
|
|
|
if (l->rx.addr.ss_family == AF_INET || l->rx.addr.ss_family == AF_INET6) {
|
2015-04-05 11:56:47 -04:00
|
|
|
setsockopt(cfd, IPPROTO_TCP, TCP_NODELAY, (char *) &one, sizeof(one));
|
|
|
|
|
|
2020-07-08 22:13:20 -04:00
|
|
|
if (p->options & PR_O_TCP_CLI_KA) {
|
2015-04-05 11:56:47 -04:00
|
|
|
setsockopt(cfd, SOL_SOCKET, SO_KEEPALIVE, (char *) &one, sizeof(one));
|
|
|
|
|
|
2020-07-08 23:58:51 -04:00
|
|
|
#ifdef TCP_KEEPCNT
|
2020-07-08 22:13:20 -04:00
|
|
|
if (p->clitcpka_cnt)
|
|
|
|
|
setsockopt(cfd, IPPROTO_TCP, TCP_KEEPCNT, &p->clitcpka_cnt, sizeof(p->clitcpka_cnt));
|
2020-07-08 23:58:51 -04:00
|
|
|
#endif
|
2020-07-08 22:13:20 -04:00
|
|
|
|
2020-07-08 23:58:51 -04:00
|
|
|
#ifdef TCP_KEEPIDLE
|
2020-07-08 22:13:20 -04:00
|
|
|
if (p->clitcpka_idle)
|
|
|
|
|
setsockopt(cfd, IPPROTO_TCP, TCP_KEEPIDLE, &p->clitcpka_idle, sizeof(p->clitcpka_idle));
|
2020-07-08 23:58:51 -04:00
|
|
|
#endif
|
2020-07-08 22:13:20 -04:00
|
|
|
|
2020-07-08 23:58:51 -04:00
|
|
|
#ifdef TCP_KEEPINTVL
|
2020-07-08 22:13:20 -04:00
|
|
|
if (p->clitcpka_intvl)
|
|
|
|
|
setsockopt(cfd, IPPROTO_TCP, TCP_KEEPINTVL, &p->clitcpka_intvl, sizeof(p->clitcpka_intvl));
|
2020-07-08 23:58:51 -04:00
|
|
|
#endif
|
2020-07-08 22:13:20 -04:00
|
|
|
}
|
|
|
|
|
|
2015-04-05 11:56:47 -04:00
|
|
|
if (p->options & PR_O_TCP_NOLING)
|
2021-04-06 11:49:19 -04:00
|
|
|
HA_ATOMIC_OR(&fdtab[cfd].state, FD_LINGER_RISK);
|
2015-04-05 11:56:47 -04:00
|
|
|
|
|
|
|
|
#if defined(TCP_MAXSEG)
|
2023-01-12 12:42:49 -05:00
|
|
|
if (l->bind_conf->maxseg < 0) {
|
2015-04-05 11:56:47 -04:00
|
|
|
/* we just want to reduce the current MSS by that value */
|
|
|
|
|
int mss;
|
|
|
|
|
socklen_t mss_len = sizeof(mss);
|
|
|
|
|
if (getsockopt(cfd, IPPROTO_TCP, TCP_MAXSEG, &mss, &mss_len) == 0) {
|
2023-01-12 12:42:49 -05:00
|
|
|
mss += l->bind_conf->maxseg; /* remember, it's < 0 */
|
2015-04-05 11:56:47 -04:00
|
|
|
setsockopt(cfd, IPPROTO_TCP, TCP_MAXSEG, &mss, sizeof(mss));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (global.tune.client_sndbuf)
|
|
|
|
|
setsockopt(cfd, SOL_SOCKET, SO_SNDBUF, &global.tune.client_sndbuf, sizeof(global.tune.client_sndbuf));
|
|
|
|
|
|
|
|
|
|
if (global.tune.client_rcvbuf)
|
|
|
|
|
setsockopt(cfd, SOL_SOCKET, SO_RCVBUF, &global.tune.client_rcvbuf, sizeof(global.tune.client_rcvbuf));
|
|
|
|
|
|
BUG/MEDIUM: quic: fix crash when "option nolinger" is set in the frontend
Commit 0aba11e9e ("MINOR: quic: remove unnecessary quic_session_accept()")
overlooked one problem, in session_accept_fd() at the end, there's a bunch
of FD-specific stuff that either sets up or resets the socket at the TCP
level. The tests are mostly performed for AF_INET/AF_INET6 families but
they're only for one part (i.e. to avoid setting up TCP options on UNIX
sockets). Other pieces continue to configure the socket regardless of its
family. All of this directly acts on the FD, which is not correct since
the FD is not valid here, it corresponds to the QUIC handle. The issue
is much more visible when "option nolinger" is enabled in the frontend,
because the access to fdatb[cfd].state immediately crashes on the first
connection, as can be seen in github issue #2030.
This patch bypasses this setup for FD-less connections, such as QUIC.
However some of them could definitely be relevant to the QUIC stack, or
even to UNIX sockets sometimes. A better long-term solution would consist
in implementing a setsockopt() equivalent at the protocol layer that would
be used to configure the socket, either the FD or the QUIC conn depending
on the case. Some of them would not always be implemented but that would
allow to unify all this code.
This fix must be backported everywhere the commit above is backported,
namely 2.6 and 2.7.
Thanks to github user @twomoses for the nicely detailed report.
2023-02-09 11:53:41 -05:00
|
|
|
skip_fd_setup:
|
2017-08-28 13:02:51 -04:00
|
|
|
/* OK, now either we have a pending handshake to execute with and then
|
|
|
|
|
* we must return to the I/O layer, or we can proceed with the end of
|
|
|
|
|
* the stream initialization. In case of handshake, we also set the I/O
|
|
|
|
|
* timeout to the frontend's client timeout and register a task in the
|
|
|
|
|
* session for this purpose. The connection's owner is left to the
|
|
|
|
|
* session during this period.
|
2015-04-04 12:50:31 -04:00
|
|
|
*
|
|
|
|
|
* At this point we set the relation between sess/task/conn this way :
|
|
|
|
|
*
|
2017-08-28 13:02:51 -04:00
|
|
|
* +----------------- task
|
|
|
|
|
* | |
|
|
|
|
|
* orig -- sess <-- context |
|
|
|
|
|
* | ^ | |
|
|
|
|
|
* v | | |
|
|
|
|
|
* conn -- owner ---> task <-----+
|
2015-04-04 12:50:31 -04:00
|
|
|
*/
|
2020-01-23 10:27:54 -05:00
|
|
|
if (cli_conn->flags & (CO_FL_WAIT_XPRT | CO_FL_EARLY_SSL_HS)) {
|
2023-11-15 08:24:10 -05:00
|
|
|
int timeout;
|
|
|
|
|
int clt_tmt = p->timeout.client;
|
2023-11-17 12:03:20 -05:00
|
|
|
int hs_tmt = p->timeout.client_hs;
|
2023-11-15 08:24:10 -05:00
|
|
|
|
2021-10-01 12:23:30 -04:00
|
|
|
if (unlikely((sess->task = task_new_here()) == NULL))
|
2017-08-28 10:22:54 -04:00
|
|
|
goto out_free_sess;
|
|
|
|
|
|
2023-11-15 08:24:10 -05:00
|
|
|
/* Handshake timeout as default timeout */
|
|
|
|
|
timeout = hs_tmt ? hs_tmt : clt_tmt;
|
2017-08-28 13:02:51 -04:00
|
|
|
sess->task->context = sess;
|
2023-01-12 13:32:45 -05:00
|
|
|
sess->task->nice = l->bind_conf->nice;
|
2017-08-28 13:02:51 -04:00
|
|
|
sess->task->process = session_expire_embryonic;
|
2023-11-15 08:24:10 -05:00
|
|
|
sess->task->expire = tick_add_ifset(now_ms, timeout);
|
2017-08-28 13:02:51 -04:00
|
|
|
task_queue(sess->task);
|
2015-04-04 12:50:31 -04:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-04 19:04:01 -04:00
|
|
|
/* OK let's complete stream initialization since there is no handshake */
|
2017-09-15 04:06:28 -04:00
|
|
|
if (conn_complete_session(cli_conn) >= 0)
|
|
|
|
|
return 1;
|
2015-04-04 12:50:31 -04:00
|
|
|
|
2020-01-07 12:03:09 -05:00
|
|
|
/* if we reach here we have deliberately decided not to keep this
|
|
|
|
|
* session (e.g. tcp-request rule), so that's not an error we should
|
|
|
|
|
* try to protect against.
|
|
|
|
|
*/
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
2017-09-15 04:06:28 -04:00
|
|
|
/* error unrolling */
|
2015-04-04 12:50:31 -04:00
|
|
|
out_free_sess:
|
BUG/MINOR: listener: Don't decrease actconn twice when a new session is rejected
When a freshly created session is rejected, for any reason, during the accept in
the function "session_accept_fd", the variable "actconn" is decreased twice. The
first time when the rejected session is released, then in the function
"listener_accpect", because of the failure. So it is possible to have an
negative value for actconn. Note that, in this case, we will also have a negatve
value for the current number of connections on the listener rejecting the
session (actconn and l->nbconn are in/decreased in same time).
It is easy to reproduce the bug with this small configuration:
global
stats socket /tmp/haproxy
listen test
bind *:12345
tcp-request connection reject if TRUE
A "show info" on the stat socket, after a connection attempt, will show a very
high value (the unsigned representation of -1).
To fix the bug, if the function "session_accept_fd" returns an error, it
decrements the right counters and "listener_accpect" leaves them untouched.
This patch must be backported in 1.8.
2018-03-23 10:11:55 -04:00
|
|
|
/* prevent call to listener_release during session_free. It will be
|
|
|
|
|
* done below, for all errors. */
|
|
|
|
|
sess->listener = NULL;
|
2015-04-04 12:50:31 -04:00
|
|
|
session_free(sess);
|
2020-10-15 01:11:14 -04:00
|
|
|
|
2015-04-04 12:50:31 -04:00
|
|
|
out_free_conn:
|
2019-07-17 10:53:19 -04:00
|
|
|
if (ret < 0 && l->bind_conf->xprt == xprt_get(XPRT_RAW) &&
|
BUG/MEDIUM: quic: fix crash when "option nolinger" is set in the frontend
Commit 0aba11e9e ("MINOR: quic: remove unnecessary quic_session_accept()")
overlooked one problem, in session_accept_fd() at the end, there's a bunch
of FD-specific stuff that either sets up or resets the socket at the TCP
level. The tests are mostly performed for AF_INET/AF_INET6 families but
they're only for one part (i.e. to avoid setting up TCP options on UNIX
sockets). Other pieces continue to configure the socket regardless of its
family. All of this directly acts on the FD, which is not correct since
the FD is not valid here, it corresponds to the QUIC handle. The issue
is much more visible when "option nolinger" is enabled in the frontend,
because the access to fdatb[cfd].state immediately crashes on the first
connection, as can be seen in github issue #2030.
This patch bypasses this setup for FD-less connections, such as QUIC.
However some of them could definitely be relevant to the QUIC stack, or
even to UNIX sockets sometimes. A better long-term solution would consist
in implementing a setsockopt() equivalent at the protocol layer that would
be used to configure the socket, either the FD or the QUIC conn depending
on the case. Some of them would not always be implemented but that would
allow to unify all this code.
This fix must be backported everywhere the commit above is backported,
namely 2.6 and 2.7.
Thanks to github user @twomoses for the nicely detailed report.
2023-02-09 11:53:41 -05:00
|
|
|
p->mode == PR_MODE_HTTP && l->bind_conf->mux_proto == NULL &&
|
|
|
|
|
!(cli_conn->flags & CO_FL_FDLESS)) {
|
2015-04-04 12:50:31 -04:00
|
|
|
/* critical error, no more memory, try to emit a 500 response */
|
2019-07-17 15:36:33 -04:00
|
|
|
send(cfd, http_err_msgs[HTTP_ERR_500], strlen(http_err_msgs[HTTP_ERR_500]),
|
2018-07-13 04:54:26 -04:00
|
|
|
MSG_DONTWAIT|MSG_NOSIGNAL);
|
2015-04-04 12:50:31 -04:00
|
|
|
}
|
|
|
|
|
|
2023-08-23 12:02:51 -04:00
|
|
|
if (cli_conn->mux) {
|
|
|
|
|
/* Mux is already initialized for active reversed connection. */
|
|
|
|
|
cli_conn->mux->destroy(cli_conn->ctx);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
conn_stop_tracking(cli_conn);
|
|
|
|
|
conn_full_close(cli_conn);
|
|
|
|
|
conn_free(cli_conn);
|
|
|
|
|
}
|
2020-10-15 01:11:14 -04:00
|
|
|
listener_release(l);
|
2015-04-04 12:50:31 -04:00
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* prepare the trash with a log prefix for session <sess>. It only works with
|
|
|
|
|
* embryonic sessions based on a real connection. This function requires that
|
|
|
|
|
* at sess->origin points to the incoming connection.
|
|
|
|
|
*/
|
|
|
|
|
static void session_prepare_log_prefix(struct session *sess)
|
|
|
|
|
{
|
2021-10-22 11:47:14 -04:00
|
|
|
const struct sockaddr_storage *src;
|
2015-04-04 12:50:31 -04:00
|
|
|
struct tm tm;
|
|
|
|
|
char pn[INET6_ADDRSTRLEN];
|
|
|
|
|
int ret;
|
|
|
|
|
char *end;
|
|
|
|
|
|
2021-10-22 11:47:14 -04:00
|
|
|
src = sess_src(sess);
|
|
|
|
|
ret = (src ? addr_to_str(src, pn, sizeof(pn)) : 0);
|
2015-04-04 12:50:31 -04:00
|
|
|
if (ret <= 0)
|
|
|
|
|
chunk_printf(&trash, "unknown [");
|
|
|
|
|
else if (ret == AF_UNIX)
|
|
|
|
|
chunk_printf(&trash, "%s:%d [", pn, sess->listener->luid);
|
|
|
|
|
else
|
2021-10-22 11:47:14 -04:00
|
|
|
chunk_printf(&trash, "%s:%d [", pn, get_host_port(src));
|
2015-04-04 12:50:31 -04:00
|
|
|
|
|
|
|
|
get_localtime(sess->accept_date.tv_sec, &tm);
|
2018-07-13 04:54:26 -04:00
|
|
|
end = date2str_log(trash.area + trash.data, &tm, &(sess->accept_date),
|
|
|
|
|
trash.size - trash.data);
|
|
|
|
|
trash.data = end - trash.area;
|
2015-04-04 12:50:31 -04:00
|
|
|
if (sess->listener->name)
|
|
|
|
|
chunk_appendf(&trash, "] %s/%s", sess->fe->id, sess->listener->name);
|
|
|
|
|
else
|
|
|
|
|
chunk_appendf(&trash, "] %s/%d", sess->fe->id, sess->listener->luid);
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-12 11:13:46 -04:00
|
|
|
|
|
|
|
|
/* fill the trash buffer with the string to use for send_log during
|
|
|
|
|
* session_kill_embryonic(). Add log prefix and error string.
|
|
|
|
|
*
|
|
|
|
|
* The function is able to dump an SSL error string when CO_ER_SSL_HANDSHAKE
|
|
|
|
|
* is met.
|
|
|
|
|
*/
|
|
|
|
|
static void session_build_err_string(struct session *sess)
|
|
|
|
|
{
|
|
|
|
|
struct connection *conn = __objt_conn(sess->origin);
|
|
|
|
|
const char *err_msg;
|
|
|
|
|
struct ssl_sock_ctx __maybe_unused *ssl_ctx;
|
|
|
|
|
|
|
|
|
|
err_msg = conn_err_code_str(conn);
|
|
|
|
|
session_prepare_log_prefix(sess); /* use trash buffer */
|
|
|
|
|
|
|
|
|
|
#ifdef USE_OPENSSL
|
|
|
|
|
ssl_ctx = conn_get_ssl_sock_ctx(conn);
|
|
|
|
|
|
2023-06-12 10:23:29 -04:00
|
|
|
/* when the SSL error code is present and during a SSL Handshake failure,
|
|
|
|
|
* try to dump the error string from OpenSSL */
|
|
|
|
|
if (conn->err_code == CO_ER_SSL_HANDSHAKE && ssl_ctx && ssl_ctx->error_code != 0) {
|
|
|
|
|
chunk_appendf(&trash, ": SSL handshake failure (");
|
|
|
|
|
ERR_error_string_n(ssl_ctx->error_code, b_orig(&trash)+b_data(&trash), b_room(&trash));
|
|
|
|
|
trash.data = strlen(b_orig(&trash));
|
|
|
|
|
chunk_appendf(&trash, ")\n");
|
2023-05-12 11:13:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
#endif /* ! USE_OPENSSL */
|
|
|
|
|
|
|
|
|
|
if (err_msg)
|
|
|
|
|
chunk_appendf(&trash, ": %s\n", err_msg);
|
|
|
|
|
else
|
|
|
|
|
chunk_appendf(&trash, ": unknown connection error (code=%d flags=%08x)\n",
|
|
|
|
|
conn->err_code, conn->flags);
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-04-04 12:50:31 -04:00
|
|
|
/* This function kills an existing embryonic session. It stops the connection's
|
|
|
|
|
* transport layer, releases assigned resources, resumes the listener if it was
|
|
|
|
|
* disabled and finally kills the file descriptor. This function requires that
|
|
|
|
|
* sess->origin points to the incoming connection.
|
|
|
|
|
*/
|
2021-03-02 10:09:26 -05:00
|
|
|
static void session_kill_embryonic(struct session *sess, unsigned int state)
|
2015-04-04 12:50:31 -04:00
|
|
|
{
|
|
|
|
|
int level = LOG_INFO;
|
|
|
|
|
struct connection *conn = __objt_conn(sess->origin);
|
2017-08-28 13:02:51 -04:00
|
|
|
struct task *task = sess->task;
|
2015-04-04 12:50:31 -04:00
|
|
|
unsigned int log = sess->fe->to_log;
|
|
|
|
|
|
|
|
|
|
if (sess->fe->options2 & PR_O2_LOGERRORS)
|
|
|
|
|
level = LOG_ERR;
|
|
|
|
|
|
|
|
|
|
if (log && (sess->fe->options & PR_O_NULLNOLOG)) {
|
|
|
|
|
/* with "option dontlognull", we don't log connections with no transfer */
|
|
|
|
|
if (!conn->err_code ||
|
|
|
|
|
conn->err_code == CO_ER_PRX_EMPTY || conn->err_code == CO_ER_PRX_ABORT ||
|
2016-06-04 10:11:10 -04:00
|
|
|
conn->err_code == CO_ER_CIP_EMPTY || conn->err_code == CO_ER_CIP_ABORT ||
|
2015-04-04 12:50:31 -04:00
|
|
|
conn->err_code == CO_ER_SSL_EMPTY || conn->err_code == CO_ER_SSL_ABORT)
|
|
|
|
|
log = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (log) {
|
2018-11-05 09:09:47 -05:00
|
|
|
if (!conn->err_code && (state & TASK_WOKEN_TIMER)) {
|
2015-04-04 12:50:31 -04:00
|
|
|
if (conn->flags & CO_FL_ACCEPT_PROXY)
|
|
|
|
|
conn->err_code = CO_ER_PRX_TIMEOUT;
|
2016-06-04 10:11:10 -04:00
|
|
|
else if (conn->flags & CO_FL_ACCEPT_CIP)
|
|
|
|
|
conn->err_code = CO_ER_CIP_TIMEOUT;
|
2015-04-04 12:50:31 -04:00
|
|
|
else if (conn->flags & CO_FL_SSL_WAIT_HS)
|
|
|
|
|
conn->err_code = CO_ER_SSL_TIMEOUT;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-31 06:08:52 -04:00
|
|
|
if(!LIST_ISEMPTY(&sess->fe->logformat_error)) {
|
|
|
|
|
/* Display a log line following the configured error-log-format. */
|
2021-07-29 03:45:53 -04:00
|
|
|
sess_log(sess);
|
|
|
|
|
}
|
|
|
|
|
else {
|
2023-05-12 11:13:46 -04:00
|
|
|
session_build_err_string(sess);
|
|
|
|
|
send_log(sess->fe, level, "%s", trash.area);
|
2021-07-29 03:45:53 -04:00
|
|
|
}
|
2015-04-04 12:50:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* kill the connection now */
|
2017-10-05 12:12:51 -04:00
|
|
|
conn_stop_tracking(conn);
|
|
|
|
|
conn_full_close(conn);
|
2015-04-04 12:50:31 -04:00
|
|
|
conn_free(conn);
|
2018-11-13 10:48:36 -05:00
|
|
|
sess->origin = NULL;
|
2015-04-04 12:50:31 -04:00
|
|
|
|
2019-04-17 16:51:06 -04:00
|
|
|
task_destroy(task);
|
2015-04-04 12:50:31 -04:00
|
|
|
session_free(sess);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Manages the embryonic session timeout. It is only called when the timeout
|
2021-01-29 06:27:57 -05:00
|
|
|
* strikes and performs the required cleanup. It's only exported to make it
|
|
|
|
|
* resolve in "show tasks".
|
2015-04-04 12:50:31 -04:00
|
|
|
*/
|
2021-03-02 10:09:26 -05:00
|
|
|
struct task *session_expire_embryonic(struct task *t, void *context, unsigned int state)
|
2015-04-04 12:50:31 -04:00
|
|
|
{
|
2018-05-25 08:04:04 -04:00
|
|
|
struct session *sess = context;
|
2015-04-04 12:50:31 -04:00
|
|
|
|
2018-08-16 13:03:50 -04:00
|
|
|
if (!(state & TASK_WOKEN_TIMER))
|
2015-04-04 12:50:31 -04:00
|
|
|
return t;
|
|
|
|
|
|
2018-11-05 09:09:47 -05:00
|
|
|
session_kill_embryonic(sess, state);
|
2015-04-04 12:50:31 -04:00
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Finish initializing a session from a connection, or kills it if the
|
2017-09-15 04:06:28 -04:00
|
|
|
* connection shows and error. Returns <0 if the connection was killed. It may
|
2020-01-22 12:08:48 -05:00
|
|
|
* be called either asynchronously when ssl handshake is done with an embryonic
|
2017-09-15 04:06:28 -04:00
|
|
|
* session, or synchronously to finalize the session. The distinction is made
|
|
|
|
|
* on sess->task which is only set in the embryonic session case.
|
2015-04-04 12:50:31 -04:00
|
|
|
*/
|
2020-01-22 12:08:48 -05:00
|
|
|
int conn_complete_session(struct connection *conn)
|
2015-04-04 12:50:31 -04:00
|
|
|
{
|
2017-08-28 13:02:51 -04:00
|
|
|
struct session *sess = conn->owner;
|
2015-04-04 12:50:31 -04:00
|
|
|
|
2023-04-28 03:16:15 -04:00
|
|
|
sess->t_handshake = ns_to_ms(now_ns - sess->accept_ts);
|
2018-09-05 05:56:48 -04:00
|
|
|
|
2015-04-05 18:25:48 -04:00
|
|
|
if (conn->flags & CO_FL_ERROR)
|
|
|
|
|
goto fail;
|
|
|
|
|
|
2015-04-08 12:18:15 -04:00
|
|
|
/* if logs require transport layer information, note it on the connection */
|
|
|
|
|
if (sess->fe->to_log & LW_XPRT)
|
|
|
|
|
conn->flags |= CO_FL_XPRT_TRACKED;
|
|
|
|
|
|
2016-10-21 10:37:51 -04:00
|
|
|
/* we may have some tcp-request-session rules */
|
2023-01-12 14:03:38 -05:00
|
|
|
if (!LIST_ISEMPTY(&sess->fe->tcp_req.l5_rules) && !tcp_exec_l5_rules(sess))
|
2016-10-21 10:37:51 -04:00
|
|
|
goto fail;
|
|
|
|
|
|
2015-04-08 12:10:49 -04:00
|
|
|
session_count_new(sess);
|
2023-08-23 12:02:51 -04:00
|
|
|
if (!conn->mux) {
|
|
|
|
|
if (conn_install_mux_fe(conn, NULL) < 0)
|
|
|
|
|
goto fail;
|
|
|
|
|
}
|
2015-04-05 18:25:48 -04:00
|
|
|
|
2017-08-28 10:22:54 -04:00
|
|
|
/* the embryonic session's task is not needed anymore */
|
2019-05-07 13:05:35 -04:00
|
|
|
task_destroy(sess->task);
|
|
|
|
|
sess->task = NULL;
|
2017-10-08 05:26:30 -04:00
|
|
|
conn_set_owner(conn, sess, conn_session_free);
|
|
|
|
|
|
2015-04-05 18:25:48 -04:00
|
|
|
return 0;
|
2015-04-04 12:50:31 -04:00
|
|
|
|
2015-04-05 18:25:48 -04:00
|
|
|
fail:
|
2017-09-15 04:06:28 -04:00
|
|
|
if (sess->task)
|
2018-11-05 09:09:47 -05:00
|
|
|
session_kill_embryonic(sess, 0);
|
2015-04-04 12:50:31 -04:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-19 11:25:18 -05:00
|
|
|
/* Add <inc> to the number of cumulated glitches in the tracked counters for
|
|
|
|
|
* session <sess> which is known for being tracked, and implicitly update the
|
|
|
|
|
* rate if also tracked.
|
|
|
|
|
*/
|
|
|
|
|
void __session_add_glitch_ctr(struct session *sess, uint inc)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < global.tune.nb_stk_ctr; i++)
|
|
|
|
|
stkctr_add_glitch_ctr(&sess->stkctr[i], inc);
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-03 07:53:24 -04:00
|
|
|
/*
|
|
|
|
|
* Local variables:
|
|
|
|
|
* c-indent-level: 8
|
|
|
|
|
* c-basic-offset: 8
|
|
|
|
|
* End:
|
|
|
|
|
*/
|