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:
Willy Tarreau 2015-04-04 14:46:56 +02:00
parent 15b5e14faa
commit 7ea671b914
4 changed files with 20 additions and 12 deletions

View File

@ -39,6 +39,8 @@ struct session {
struct proxy *fe; /* the proxy this session depends on for the client side */ struct proxy *fe; /* the proxy this session depends on for the client side */
struct listener *listener; /* the listener by which the request arrived */ struct listener *listener; /* the listener by which the request arrived */
enum obj_type *origin; /* the connection / applet which initiated this session */ 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 */ #endif /* _TYPES_SESSION_H */

View File

@ -2033,6 +2033,8 @@ __LJMP static int hlua_socket_new(lua_State *L)
goto out_fail_conf; 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); socket->s = pool_alloc2(pool2_stream);
if (!socket->s) { if (!socket->s) {
hlua_pusherror(L, "socket: out of memory"); hlua_pusherror(L, "socket: out of memory");
@ -2151,8 +2153,9 @@ __LJMP static int hlua_socket_new(lua_State *L)
/* Configure logs. */ /* Configure logs. */
socket->s->logs.logwait = 0; socket->s->logs.logwait = 0;
socket->s->logs.level = 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; socket->s->do_log = NULL;
/* Function used if an error is occured. */ /* Function used if an error is occured. */

View File

@ -1125,6 +1125,8 @@ static struct stream *peer_session_create(struct peer *peer, struct peer_session
sess->listener = l; sess->listener = l;
sess->fe = p; 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 */ if ((s = pool_alloc2(pool2_stream)) == NULL) { /* disable this proxy for a while */
Alert("out of memory in peer_session_create().\n"); 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.logwait = 0;
s->logs.level = 0; s->logs.level = 0;
s->logs.accept_date = date; /* user-visible date for logging */ s->logs.accept_date = sess->accept_date; /* user-visible date for logging */
s->logs.tv_accept = now; /* corrected date for internal use */ s->logs.tv_accept = sess->tv_accept; /* corrected date for internal use */
s->do_log = NULL; s->do_log = NULL;
/* default error reporting function, may be changed by analysers */ /* default error reporting function, may be changed by analysers */

View File

@ -105,6 +105,8 @@ int stream_accept(struct listener *l, int cfd, struct sockaddr_storage *addr)
sess->listener = l; sess->listener = l;
sess->fe = p; sess->fe = p;
sess->origin = &cli_conn->obj_type; 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)) if (unlikely((s = pool_alloc2(pool2_stream)) == NULL))
goto out_free_sess; 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[0].flags = SI_FL_NONE;
s->si[1].flags = SI_FL_ISBACK; s->si[1].flags = SI_FL_ISBACK;
s->logs.accept_date = date; /* user-visible date for logging */ s->logs.accept_date = sess->accept_date; /* user-visible date for logging */
s->logs.tv_accept = now; /* corrected date for internal use */ s->logs.tv_accept = sess->tv_accept; /* corrected date for internal use */
s->uniq_id = global.req_count++; s->uniq_id = global.req_count++;
p->feconn++; p->feconn++;
/* This stream was accepted, count it now */ /* 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 * embryonic streams based on a real connection. This function requires that
* at sess->origin points to the incoming connection. * 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; struct tm tm;
char pn[INET6_ADDRSTRLEN]; char pn[INET6_ADDRSTRLEN];
int ret; int ret;
char *end; char *end;
struct session *sess = s->sess;
struct connection *cli_conn = __objt_conn(sess->origin); struct connection *cli_conn = __objt_conn(sess->origin);
ret = addr_to_str(&cli_conn->addr.from, pn, sizeof(pn)); 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 else
chunk_printf(&trash, "%s:%d [", pn, get_host_port(&cli_conn->addr.from)); chunk_printf(&trash, "%s:%d [", pn, get_host_port(&cli_conn->addr.from));
get_localtime(s->logs.accept_date.tv_sec, &tm); get_localtime(sess->accept_date.tv_sec, &tm);
end = date2str_log(trash.str + trash.len, &tm, &(s->logs.accept_date), trash.size - trash.len); end = date2str_log(trash.str + trash.len, &tm, &(sess->accept_date), trash.size - trash.len);
trash.len = end - trash.str; trash.len = end - trash.str;
if (sess->listener->name) if (sess->listener->name)
chunk_appendf(&trash, "] %s/%s", sess->fe->id, 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; 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); err_msg = conn_err_code_str(conn);
if (err_msg) if (err_msg)
send_log(sess->fe, level, "%s: %s\n", trash.str, err_msg); send_log(sess->fe, level, "%s: %s\n", trash.str, err_msg);