Fix EXPIRED message bug, other fixes and improvements

pull/13/head
Soner Tari 7 years ago
parent a1c5d05143
commit 137f017cb5

@ -70,11 +70,6 @@
*/
#define OUTBUF_LIMIT (128*1024)
/*
* Print helper for logging code.
*/
#define STRORDASH(x) (((x)&&*(x))?(x):"-")
/*
* Context used for all server sessions.
*/
@ -2679,8 +2674,8 @@ pxy_connected_enable(struct bufferevent *bev, pxy_conn_ctx_t *ctx)
}
if (WANT_CONTENT_LOG(ctx)) {
if (log_content_open(&ctx->logctx, ctx->opts,
ctx->srchost_str, ctx->srcport_str,
ctx->dsthost_str, ctx->dstport_str,
STRORDASH(ctx->srchost_str), STRORDASH(ctx->srcport_str),
STRORDASH(ctx->dsthost_str), STRORDASH(ctx->dstport_str),
#ifdef HAVE_LOCAL_PROCINFO
ctx->lproc.exec_path,
ctx->lproc.user,
@ -2778,7 +2773,8 @@ pxy_connected_enable(struct bufferevent *bev, pxy_conn_ctx_t *ctx)
return 0;
}
snprintf(ctx->header_str, header_len, "%s [%s]:%u,[%s]:%s,[%s]:%s,%s",
SSLPROXY_KEY, addr, ntohs(child_listener_addr.sin_port), ctx->srchost_str, ctx->srcport_str, ctx->dsthost_str, ctx->dstport_str, ctx->spec->ssl ? "s":"p");
SSLPROXY_KEY, addr, ntohs(child_listener_addr.sin_port), STRORNONE(ctx->srchost_str), STRORNONE(ctx->srcport_str),
STRORNONE(ctx->dsthost_str), STRORNONE(ctx->dstport_str), ctx->spec->ssl ? "s":"p");
#ifdef DEBUG_PROXY
log_dbg_level_printf(LOG_DBG_MODE_FINEST, "pxy_connected_enable: Enable src, SSLproxy header= %s, fd=%d, child_fd=%d\n", ctx->header_str, fd, ctx->child_fd);
@ -2818,12 +2814,8 @@ pxy_connected_enable(struct bufferevent *bev, pxy_conn_ctx_t *ctx)
" %s %s\n",
bev == ctx->srv_dst.bev ?
"to" : "from",
bev == ctx->srv_dst.bev ?
ctx->dsthost_str :
ctx->srchost_str,
bev == ctx->srv_dst.bev ?
ctx->dstport_str :
ctx->srcport_str,
bev == ctx->srv_dst.bev ? STRORDASH(ctx->dsthost_str) : STRORDASH(ctx->srchost_str),
bev == ctx->srv_dst.bev ? STRORDASH(ctx->dstport_str) : STRORDASH(ctx->srcport_str),
SSL_get_version(this->ssl),
SSL_get_cipher(this->ssl));
} else {
@ -2833,11 +2825,9 @@ pxy_connected_enable(struct bufferevent *bev, pxy_conn_ctx_t *ctx)
* in order not to confuse anyone who might be
* looking closely at the output */
log_dbg_printf("pxy_connected_enable: TCP connected to [%s]:%s\n",
ctx->dsthost_str,
ctx->dstport_str);
STRORDASH(ctx->dsthost_str), STRORDASH(ctx->dstport_str));
log_dbg_printf("pxy_connected_enable: TCP connected from [%s]:%s\n",
ctx->srchost_str,
ctx->srcport_str);
STRORDASH(ctx->srchost_str), STRORDASH(ctx->srcport_str));
}
}
}
@ -3187,10 +3177,10 @@ leave:
if (OPTS_DEBUG(ctx->opts)) {
log_dbg_printf("pxy_bev_eventcb: %s disconnected to [%s]:%s, fd=%d\n",
this->ssl ? "SSL" : "TCP",
ctx->dsthost_str, ctx->dstport_str, ctx->fd);
STRORDASH(ctx->dsthost_str), STRORDASH(ctx->dstport_str), ctx->fd);
log_dbg_printf("pxy_bev_eventcb: %s disconnected from [%s]:%s, fd=%d\n",
this->ssl ? "SSL" : "TCP",
ctx->srchost_str, ctx->srcport_str, ctx->fd);
STRORDASH(ctx->srchost_str), STRORDASH(ctx->srcport_str), ctx->fd);
}
this->closed = 1;
@ -3325,10 +3315,10 @@ leave:
if (OPTS_DEBUG(parent->opts)) {
log_dbg_printf("pxy_bev_eventcb_child: %s disconnected to [%s]:%s, fd=%d, pfd=%d\n",
this->ssl ? "SSL" : "TCP",
parent->dsthost_str, parent->dstport_str, ctx->fd, parent->fd);
STRORDASH(parent->dsthost_str), STRORDASH(parent->dstport_str), ctx->fd, parent->fd);
log_dbg_printf("pxy_bev_eventcb_child: %s disconnected from [%s]:%s, fd=%d, pfd=%d\n",
this->ssl ? "SSL" : "TCP",
parent->srchost_str, parent->srcport_str, ctx->fd, parent->fd);
STRORDASH(parent->srchost_str), STRORDASH(parent->srcport_str), ctx->fd, parent->fd);
}
this->closed = 1;

@ -40,6 +40,12 @@
#include <event2/event.h>
#include <event2/util.h>
/*
* Print helper for logging code.
*/
#define STRORDASH(x) (((x)&&*(x))?(x):"-")
#define STRORNONE(x) (((x)&&*(x))?(x):"")
typedef struct pxy_conn_child_ctx pxy_conn_child_ctx_t;
/* single socket bufferevent descriptor */

@ -71,14 +71,14 @@ pxy_thrmgr_get_thr_expired_conns(pxy_thr_ctx_t *tctx, pxy_conn_ctx_t **expired_c
ctx = *expired_conns;
while (ctx) {
src_addr = NULL;
if (ctx->srchost_str) {
if (ctx->srchost_str && ctx->srcport_str) {
if (asprintf(&src_addr, ", src_addr=%s:%s", ctx->srchost_str, ctx->srcport_str) < 0) {
goto leave;
}
}
dst_addr = NULL;
if (ctx->dsthost_str) {
if (ctx->dsthost_str && ctx->dstport_str) {
if (asprintf(&dst_addr, ", dst_addr=%s:%s", ctx->dsthost_str, ctx->dstport_str) < 0) {
goto leave;
}
@ -86,18 +86,23 @@ pxy_thrmgr_get_thr_expired_conns(pxy_thr_ctx_t *tctx, pxy_conn_ctx_t **expired_c
#ifdef DEBUG_PROXY
log_dbg_level_printf(LOG_DBG_MODE_FINEST, "pxy_thrmgr_get_expired_conns: thr=%d, fd=%d, child_fd=%d, time=%lld%s%s\n",
ctx->thr->thridx, ctx->fd, ctx->child_fd, (long int) now - ctx->atime, src_addr, dst_addr);
ctx->thr->thridx, ctx->fd, ctx->child_fd, (long int) now - ctx->atime, STRORNONE(src_addr), STRORNONE(dst_addr));
#endif /* DEBUG_PROXY */
char *msg;
if (asprintf(&msg, "EXPIRED: thr=%d, time=%lld%s%s\n",
ctx->thr->thridx, (long int) now - ctx->atime, src_addr, dst_addr)) {
ctx->thr->thridx, (long int) now - ctx->atime, STRORNONE(src_addr), STRORNONE(dst_addr)) < 0) {
goto leave;
}
free(src_addr);
src_addr = NULL;
free(dst_addr);
dst_addr = NULL;
if (src_addr) {
free(src_addr);
src_addr = NULL;
}
if (dst_addr) {
free(dst_addr);
dst_addr = NULL;
}
if (log_stats(msg) == -1) {
log_err_level_printf(LOG_WARNING, "Stats logging failed\n");
@ -168,14 +173,14 @@ pxy_thrmgr_print_thr_info(pxy_thr_ctx_t *tctx)
time_t atime = now - ctx->atime;
time_t ctime = now - ctx->ctime;
char *src_addr = NULL;
if (ctx->srchost_str) {
src_addr = NULL;
if (ctx->srchost_str && ctx->srcport_str) {
if (asprintf(&src_addr, ", src_addr=%s:%s", ctx->srchost_str, ctx->srcport_str) < 0) {
goto leave;
}
}
char *dst_addr = NULL;
if (ctx->dsthost_str) {
dst_addr = NULL;
if (ctx->dsthost_str && ctx->dstport_str) {
if (asprintf(&dst_addr, ", dst_addr=%s:%s", ctx->dsthost_str, ctx->dstport_str) < 0) {
goto leave;
}
@ -185,7 +190,7 @@ pxy_thrmgr_print_thr_info(pxy_thr_ctx_t *tctx)
if (asprintf(&lmsg, "PARENT CONN: thr=%d, id=%u, fd=%d, child_fd=%d, dst=%d, srv_dst=%d, child_src=%d, child_dst=%d, p=%d-%d-%d c=%d-%d, ce=%d cc=%d, at=%lld ct=%lld%s%s\n",
tctx->thridx, idx, ctx->fd, ctx->child_fd, ctx->dst_fd, ctx->srv_dst_fd, ctx->child_src_fd, ctx->child_dst_fd,
ctx->src.closed, ctx->dst.closed, ctx->srv_dst.closed, ctx->children ? ctx->children->src.closed : 0, ctx->children ? ctx->children->dst.closed : 0,
ctx->children ? 1:0, ctx->child_count, atime, ctime, src_addr ? src_addr : "", dst_addr ? dst_addr : "") < 0) {
ctx->children ? 1:0, ctx->child_count, atime, ctime, STRORNONE(src_addr), STRORNONE(dst_addr)) < 0) {
goto leave;
}
log_dbg_level_printf(LOG_DBG_MODE_FINEST, "pxy_thrmgr_print_thr_info: %s", lmsg);
@ -196,7 +201,7 @@ pxy_thrmgr_print_thr_info(pxy_thr_ctx_t *tctx)
// @attention Report idle connections only, i.e. the conns which have been idle since the last time we checked for expired conns
if (atime >= tctx->thrmgr->opts->expired_conn_check_period) {
if (asprintf(&smsg, "IDLE: thr=%d, id=%u, ce=%d cc=%d, at=%lld ct=%lld%s%s\n",
tctx->thridx, idx, ctx->children ? 1:0, ctx->child_count, atime, ctime, src_addr ? src_addr : "", dst_addr ? dst_addr : "") < 0) {
tctx->thridx, idx, ctx->children ? 1:0, ctx->child_count, atime, ctime, STRORNONE(src_addr), STRORNONE(dst_addr)) < 0) {
goto leave;
}
@ -207,10 +212,14 @@ pxy_thrmgr_print_thr_info(pxy_thr_ctx_t *tctx)
smsg = NULL;
}
free(src_addr);
src_addr = NULL;
free(dst_addr);
dst_addr = NULL;
if (src_addr) {
free(src_addr);
src_addr = NULL;
}
if (dst_addr) {
free(dst_addr);
dst_addr = NULL;
}
max_fd = MAX(max_fd, MAX(ctx->fd, MAX(ctx->child_fd, MAX(ctx->dst_fd, MAX(ctx->srv_dst_fd, MAX(ctx->child_src_fd, ctx->child_dst_fd))))));
max_atime = MAX(max_atime, atime);

Loading…
Cancel
Save