mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-22 14:21:25 +02:00
MINOR: session: store the session's accept date
Doing so ensures we don't need to use the stream anymore to prepare the log information to report a failed handshake on an embryonic session. Thus, prepare_mini_sess_log_prefix() now takes a session in argument.
This commit is contained in:
parent
15b5e14faa
commit
7ea671b914
@ -39,6 +39,8 @@ struct session {
|
||||
struct proxy *fe; /* the proxy this session depends on for the client side */
|
||||
struct listener *listener; /* the listener by which the request arrived */
|
||||
enum obj_type *origin; /* the connection / applet which initiated this session */
|
||||
struct timeval accept_date; /* date of the session's accept() in user date */
|
||||
struct timeval tv_accept; /* date of the session's accept() in internal date (monotonic) */
|
||||
};
|
||||
|
||||
#endif /* _TYPES_SESSION_H */
|
||||
|
@ -2033,6 +2033,8 @@ __LJMP static int hlua_socket_new(lua_State *L)
|
||||
goto out_fail_conf;
|
||||
}
|
||||
|
||||
sess->accept_date = date; /* user-visible date for logging */
|
||||
sess->tv_accept = now; /* corrected date for internal use */
|
||||
socket->s = pool_alloc2(pool2_stream);
|
||||
if (!socket->s) {
|
||||
hlua_pusherror(L, "socket: out of memory");
|
||||
@ -2151,8 +2153,9 @@ __LJMP static int hlua_socket_new(lua_State *L)
|
||||
/* Configure logs. */
|
||||
socket->s->logs.logwait = 0;
|
||||
socket->s->logs.level = 0;
|
||||
socket->s->logs.accept_date = date; /* user-visible date for logging */
|
||||
socket->s->logs.tv_accept = now; /* corrected date for internal use */
|
||||
|
||||
socket->s->logs.accept_date = sess->accept_date; /* user-visible date for logging */
|
||||
socket->s->logs.tv_accept = sess->tv_accept; /* corrected date for internal use */
|
||||
socket->s->do_log = NULL;
|
||||
|
||||
/* Function used if an error is occured. */
|
||||
|
@ -1125,6 +1125,8 @@ static struct stream *peer_session_create(struct peer *peer, struct peer_session
|
||||
|
||||
sess->listener = l;
|
||||
sess->fe = p;
|
||||
sess->accept_date = date; /* user-visible date for logging */
|
||||
sess->tv_accept = now; /* corrected date for internal use */
|
||||
|
||||
if ((s = pool_alloc2(pool2_stream)) == NULL) { /* disable this proxy for a while */
|
||||
Alert("out of memory in peer_session_create().\n");
|
||||
@ -1211,8 +1213,8 @@ static struct stream *peer_session_create(struct peer *peer, struct peer_session
|
||||
|
||||
s->logs.logwait = 0;
|
||||
s->logs.level = 0;
|
||||
s->logs.accept_date = date; /* user-visible date for logging */
|
||||
s->logs.tv_accept = now; /* corrected date for internal use */
|
||||
s->logs.accept_date = sess->accept_date; /* user-visible date for logging */
|
||||
s->logs.tv_accept = sess->tv_accept; /* corrected date for internal use */
|
||||
s->do_log = NULL;
|
||||
|
||||
/* default error reporting function, may be changed by analysers */
|
||||
|
17
src/stream.c
17
src/stream.c
@ -105,6 +105,8 @@ int stream_accept(struct listener *l, int cfd, struct sockaddr_storage *addr)
|
||||
sess->listener = l;
|
||||
sess->fe = p;
|
||||
sess->origin = &cli_conn->obj_type;
|
||||
sess->accept_date = date; /* user-visible date for logging */
|
||||
sess->tv_accept = now; /* corrected date for internal use */
|
||||
|
||||
if (unlikely((s = pool_alloc2(pool2_stream)) == NULL))
|
||||
goto out_free_sess;
|
||||
@ -130,8 +132,8 @@ int stream_accept(struct listener *l, int cfd, struct sockaddr_storage *addr)
|
||||
s->si[0].flags = SI_FL_NONE;
|
||||
s->si[1].flags = SI_FL_ISBACK;
|
||||
|
||||
s->logs.accept_date = date; /* user-visible date for logging */
|
||||
s->logs.tv_accept = now; /* corrected date for internal use */
|
||||
s->logs.accept_date = sess->accept_date; /* user-visible date for logging */
|
||||
s->logs.tv_accept = sess->tv_accept; /* corrected date for internal use */
|
||||
s->uniq_id = global.req_count++;
|
||||
p->feconn++;
|
||||
/* This stream was accepted, count it now */
|
||||
@ -260,17 +262,16 @@ int stream_accept(struct listener *l, int cfd, struct sockaddr_storage *addr)
|
||||
}
|
||||
|
||||
|
||||
/* prepare the trash with a log prefix for stream <s>. It only works with
|
||||
/* prepare the trash with a log prefix for session <sess>. It only works with
|
||||
* embryonic streams based on a real connection. This function requires that
|
||||
* at sess->origin points to the incoming connection.
|
||||
*/
|
||||
static void prepare_mini_sess_log_prefix(struct stream *s)
|
||||
static void prepare_mini_sess_log_prefix(struct session *sess)
|
||||
{
|
||||
struct tm tm;
|
||||
char pn[INET6_ADDRSTRLEN];
|
||||
int ret;
|
||||
char *end;
|
||||
struct session *sess = s->sess;
|
||||
struct connection *cli_conn = __objt_conn(sess->origin);
|
||||
|
||||
ret = addr_to_str(&cli_conn->addr.from, pn, sizeof(pn));
|
||||
@ -281,8 +282,8 @@ static void prepare_mini_sess_log_prefix(struct stream *s)
|
||||
else
|
||||
chunk_printf(&trash, "%s:%d [", pn, get_host_port(&cli_conn->addr.from));
|
||||
|
||||
get_localtime(s->logs.accept_date.tv_sec, &tm);
|
||||
end = date2str_log(trash.str + trash.len, &tm, &(s->logs.accept_date), trash.size - trash.len);
|
||||
get_localtime(sess->accept_date.tv_sec, &tm);
|
||||
end = date2str_log(trash.str + trash.len, &tm, &(sess->accept_date), trash.size - trash.len);
|
||||
trash.len = end - trash.str;
|
||||
if (sess->listener->name)
|
||||
chunk_appendf(&trash, "] %s/%s", sess->fe->id, sess->listener->name);
|
||||
@ -322,7 +323,7 @@ static void kill_mini_session(struct stream *s)
|
||||
conn->err_code = CO_ER_SSL_TIMEOUT;
|
||||
}
|
||||
|
||||
prepare_mini_sess_log_prefix(s);
|
||||
prepare_mini_sess_log_prefix(sess);
|
||||
err_msg = conn_err_code_str(conn);
|
||||
if (err_msg)
|
||||
send_log(sess->fe, level, "%s: %s\n", trash.str, err_msg);
|
||||
|
Loading…
x
Reference in New Issue
Block a user