Add debug levels, initial

This commit is contained in:
Soner Tari 2017-06-15 19:07:37 +03:00
parent ab600c8215
commit 9858928b73
7 changed files with 288 additions and 272 deletions

19
log.c
View File

@ -164,9 +164,28 @@ log_dbg_printf(const char *fmt, ...)
return log_dbg_print_free(buf); return log_dbg_print_free(buf);
} }
int
log_dbg_level_printf(int dbg_level, const char *fmt, ...)
{
va_list ap;
char *buf;
int rv;
if (dbg_mode == LOG_DBG_MODE_NONE || dbg_mode < dbg_level)
return 0;
va_start(ap, fmt);
rv = vasprintf(&buf, fmt, ap);
va_end(ap);
if (rv < 0)
return -1;
return log_dbg_print_free(buf);
}
void void
log_dbg_mode(int mode) log_dbg_mode(int mode)
{ {
fprintf(stderr, "Setting debug level to %d.\n", mode);
dbg_mode = mode; dbg_mode = mode;
} }

4
log.h
View File

@ -39,11 +39,15 @@ void log_err_mode(int);
#define LOG_ERR_MODE_SYSLOG 1 #define LOG_ERR_MODE_SYSLOG 1
int log_dbg_printf(const char *, ...) PRINTF(1,2); int log_dbg_printf(const char *, ...) PRINTF(1,2);
int log_dbg_level_printf(int, const char *, ...) PRINTF(2,3);
int log_dbg_print_free(char *); int log_dbg_print_free(char *);
int log_dbg_write_free(void *, size_t); int log_dbg_write_free(void *, size_t);
void log_dbg_mode(int); void log_dbg_mode(int);
#define LOG_DBG_MODE_NONE 0 #define LOG_DBG_MODE_NONE 0
#define LOG_DBG_MODE_ERRLOG 1 #define LOG_DBG_MODE_ERRLOG 1
#define LOG_DBG_MODE_FINE 2
#define LOG_DBG_MODE_FINER 3
#define LOG_DBG_MODE_FINEST 4
extern logger_t *connect_log; extern logger_t *connect_log;
#define log_connect_printf(fmt, ...) \ #define log_connect_printf(fmt, ...) \

27
main.c
View File

@ -303,7 +303,7 @@ main(int argc, char *argv[])
} }
while ((ch = getopt(argc, argv, OPT_g OPT_G OPT_Z OPT_i "k:c:C:K:t:" while ((ch = getopt(argc, argv, OPT_g OPT_G OPT_Z OPT_i "k:c:C:K:t:"
"OPs:r:R:e:Eu:m:j:p:l:L:S:F:dDVhW:w:")) != -1) { "OPs:r:R:e:Eu:m:j:p:l:L:S:F:dD::VhW:w:")) != -1) {
switch (ch) { switch (ch) {
case 'c': case 'c':
if (opts->cacrt) if (opts->cacrt)
@ -670,8 +670,19 @@ main(int argc, char *argv[])
opts->detach = 1; opts->detach = 1;
break; break;
case 'D': case 'D':
log_dbg_mode(LOG_DBG_MODE_ERRLOG);
opts->debug = 1; opts->debug = 1;
fprintf(stderr, "Debug optarg = %s.\n", optarg);
if (optarg && strncmp(optarg, "2", 1) == 0) {
log_dbg_mode(LOG_DBG_MODE_FINE);
} else if (optarg && strncmp(optarg, "3", 1) == 0) {
log_dbg_mode(LOG_DBG_MODE_FINER);
} else if (optarg && strncmp(optarg, "4", 1) == 0) {
log_dbg_mode(LOG_DBG_MODE_FINEST);
} else {
log_dbg_mode(LOG_DBG_MODE_ERRLOG);
}
break; break;
case 'V': case 'V':
main_version(); main_version();
@ -700,9 +711,9 @@ main(int argc, char *argv[])
fprintf(stderr, "%s: no proxyspec specified.\n", argv0); fprintf(stderr, "%s: no proxyspec specified.\n", argv0);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
log_dbg_printf(">>>>> Enter spec for loop\n"); log_dbg_level_printf(LOG_DBG_MODE_FINEST, ">>>>> Enter spec for loop\n");
for (proxyspec_t *spec = opts->spec; spec; spec = spec->next) { for (proxyspec_t *spec = opts->spec; spec; spec = spec->next) {
log_dbg_printf(">>>>> spec for loop: %s\n", spec->natengine); log_dbg_level_printf(LOG_DBG_MODE_FINEST, ">>>>> spec for loop: %s\n", spec->natengine);
if (spec->connect_addrlen || spec->sni_port) if (spec->connect_addrlen || spec->sni_port)
continue; continue;
if (!spec->natengine) { if (!spec->natengine) {
@ -718,7 +729,7 @@ main(int argc, char *argv[])
argv0, spec->natengine); argv0, spec->natengine);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
log_dbg_printf(">>>>> nat_getlookupcb: %s\n", spec->natengine); log_dbg_level_printf(LOG_DBG_MODE_FINEST, ">>>>> nat_getlookupcb: %s\n", spec->natengine);
fprintf(stderr, ">>>>> nat_getlookupcb: %s\n", spec->natengine); fprintf(stderr, ">>>>> nat_getlookupcb: %s\n", spec->natengine);
spec->natlookup = nat_getlookupcb(spec->natengine); spec->natlookup = nat_getlookupcb(spec->natengine);
spec->natsocket = nat_getsocketcb(spec->natengine); spec->natsocket = nat_getsocketcb(spec->natengine);
@ -970,11 +981,11 @@ main(int argc, char *argv[])
} }
rv = EXIT_SUCCESS; rv = EXIT_SUCCESS;
log_dbg_printf(">>>>> Enter proxy_run\n"); log_dbg_level_printf(LOG_DBG_MODE_FINEST, ">>>>> Enter proxy_run\n");
proxy_run(proxy); proxy_run(proxy);
log_dbg_printf(">>>>> Exit proxy_run\n"); log_dbg_level_printf(LOG_DBG_MODE_FINEST, ">>>>> Exit proxy_run\n");
log_dbg_printf(">>>>> main: EXIT closing privsep clisock=%d\n", clisock[0]); log_dbg_level_printf(LOG_DBG_MODE_FINEST, ">>>>> main: EXIT closing privsep clisock=%d\n", clisock[0]);
privsep_client_close(clisock[0]); privsep_client_close(clisock[0]);
proxy_free(proxy); proxy_free(proxy);

View File

@ -244,7 +244,7 @@ privsep_server_opensock_e2(proxyspec_t *spec)
int on = 1; int on = 1;
int rv; int rv;
log_dbg_printf(">>>>> privsep_server_opensock_e2: ENTER\n"); log_dbg_level_printf(LOG_DBG_MODE_FINEST, ">>>>> privsep_server_opensock_e2: ENTER\n");
fd2 = socket(spec->e2dst_addr.ss_family, SOCK_STREAM, IPPROTO_TCP); fd2 = socket(spec->e2dst_addr.ss_family, SOCK_STREAM, IPPROTO_TCP);
if (fd2 == -1) { if (fd2 == -1) {
@ -293,7 +293,7 @@ privsep_server_opensock_e2(proxyspec_t *spec)
return -1; return -1;
} }
log_dbg_printf(">>>>> privsep_server_opensock_e2: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> port = %d\n", ntohs(serv_addr.sin_port)); log_dbg_level_printf(LOG_DBG_MODE_FINER, ">>>>> privsep_server_opensock_e2: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> port = %d\n", ntohs(serv_addr.sin_port));
return fd2; return fd2;
} }
@ -490,7 +490,7 @@ privsep_server_handle_req(opts_t *opts, int srvsock)
proxyspec_t *arg; proxyspec_t *arg;
int s; int s;
log_dbg_printf(">>>>> privsep_server_opensock_e2: PRIVSEP_REQ_OPENSOCK_E2\n"); log_dbg_level_printf(LOG_DBG_MODE_FINEST, ">>>>> privsep_server_opensock_e2: PRIVSEP_REQ_OPENSOCK_E2\n");
if (n != sizeof(char) + sizeof(arg)) { if (n != sizeof(char) + sizeof(arg)) {
ans[0] = PRIVSEP_ANS_INVALID; ans[0] = PRIVSEP_ANS_INVALID;
@ -801,7 +801,7 @@ privsep_client_opensock(int clisock, const proxyspec_t *spec)
int int
privsep_client_opensock_e2(int clisock, const proxyspec_t *spec) privsep_client_opensock_e2(int clisock, const proxyspec_t *spec)
{ {
log_dbg_printf(">>>>> privsep_client_opensock_e2()\n"); log_dbg_level_printf(LOG_DBG_MODE_FINEST, ">>>>> privsep_client_opensock_e2()\n");
char ans[PRIVSEP_MAX_ANS_SIZE]; char ans[PRIVSEP_MAX_ANS_SIZE];
char req[1 + sizeof(spec)]; char req[1 + sizeof(spec)];

50
proxy.c
View File

@ -120,7 +120,7 @@ proxy_listener_ctx_free(proxy_listener_ctx_t *ctx)
static void static void
proxy_listener_errorcb(struct evconnlistener *listener, UNUSED void *ctx) proxy_listener_errorcb(struct evconnlistener *listener, UNUSED void *ctx)
{ {
log_dbg_printf(">############################# proxy_listener_errorcb: ERROR\n"); log_dbg_level_printf(LOG_DBG_MODE_FINE, ">############################# proxy_listener_errorcb: ERROR\n");
struct event_base *evbase = evconnlistener_get_base(listener); struct event_base *evbase = evconnlistener_get_base(listener);
int err = EVUTIL_SOCKET_ERROR(); int err = EVUTIL_SOCKET_ERROR();
log_err_printf("Error %d on listener: %s\n", err, log_err_printf("Error %d on listener: %s\n", err,
@ -141,30 +141,30 @@ proxy_listener_acceptcb_e2(UNUSED struct evconnlistener *listener,
// pxy_conn_ctx_t *parent_ctx = arg; // pxy_conn_ctx_t *parent_ctx = arg;
proxy_conn_meta_ctx_t *mctx = arg; proxy_conn_meta_ctx_t *mctx = arg;
if (!mctx) { if (!mctx) {
log_dbg_printf(">>>>>------------------------------------------------------------------------------------ proxy_listener_acceptcb_e2: NULL mctx <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< GONE\n"); log_dbg_level_printf(LOG_DBG_MODE_FINE, ">>>>>------------------------------------------------------------------------------------ proxy_listener_acceptcb_e2: NULL mctx <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< GONE\n");
return; return;
} }
pthread_mutex_t *cmutex = &mctx->mutex; pthread_mutex_t *cmutex = &mctx->mutex;
int err = pthread_mutex_lock(cmutex); int err = pthread_mutex_lock(cmutex);
log_dbg_printf(">>>>>------------------------------------------------------------------------------------ proxy_listener_acceptcb_e2() lock err=%d\n", err); log_dbg_level_printf(LOG_DBG_MODE_FINEST, ">>>>>------------------------------------------------------------------------------------ proxy_listener_acceptcb_e2() lock err=%d\n", err);
pxy_conn_ctx_t *parent_ctx = mctx->parent_ctx; pxy_conn_ctx_t *parent_ctx = mctx->parent_ctx;
// pthread_mutex_t *cmutex = &parent_ctx->thrmgr->mutex2; // pthread_mutex_t *cmutex = &parent_ctx->thrmgr->mutex2;
if (!parent_ctx) { if (!parent_ctx) {
log_dbg_printf(">>>>>------------------------------------------------------------------------------------ proxy_listener_acceptcb_e2: NULL parent_ctx <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< GONE\n"); log_dbg_level_printf(LOG_DBG_MODE_FINE, ">>>>>------------------------------------------------------------------------------------ proxy_listener_acceptcb_e2: NULL parent_ctx <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< GONE\n");
goto leave; goto leave;
} }
log_dbg_printf(">>>>>------------------------------------------------------------------------------------ proxy_listener_acceptcb_e2(): child fd=%d, parent fd=%d\n", fd, parent_ctx->fd); log_dbg_level_printf(LOG_DBG_MODE_FINEST, ">>>>>------------------------------------------------------------------------------------ proxy_listener_acceptcb_e2(): child fd=%d, parent fd=%d\n", fd, parent_ctx->fd);
char *host, *port; char *host, *port;
if (sys_sockaddr_str(peeraddr, peeraddrlen, &host, &port) != 0) { if (sys_sockaddr_str(peeraddr, peeraddrlen, &host, &port) != 0) {
log_dbg_printf(">>>>>------------------------------------------------------------------------------------ proxy_listener_acceptcb_e2(): PEER failed\n"); log_dbg_level_printf(LOG_DBG_MODE_FINEST, ">>>>>------------------------------------------------------------------------------------ proxy_listener_acceptcb_e2(): PEER failed\n");
} else { } else {
log_dbg_printf(">>>>>------------------------------------------------------------------------------------ proxy_listener_acceptcb_e2(): PEER [%s]:%s <<<<< child fd=%d, parent fd=%d\n", host, port, fd, parent_ctx->fd); log_dbg_level_printf(LOG_DBG_MODE_FINEST, ">>>>>------------------------------------------------------------------------------------ proxy_listener_acceptcb_e2(): PEER [%s]:%s <<<<< child fd=%d, parent fd=%d\n", host, port, fd, parent_ctx->fd);
free(host); free(host);
free(port); free(port);
} }
@ -175,25 +175,25 @@ proxy_listener_acceptcb_e2(UNUSED struct evconnlistener *listener,
pxy_conn_setup_e2(fd, mctx); pxy_conn_setup_e2(fd, mctx);
leave: leave:
log_dbg_printf(">>>>>------------------------------------------------------------------------------------ proxy_listener_acceptcb_e2(): EXIT\n"); log_dbg_level_printf(LOG_DBG_MODE_FINEST, ">>>>>------------------------------------------------------------------------------------ proxy_listener_acceptcb_e2(): EXIT\n");
pthread_mutex_unlock(cmutex); pthread_mutex_unlock(cmutex);
} }
static proxy_conn_meta_ctx_t * static proxy_conn_meta_ctx_t *
pxy_conn_meta_ctx_new() pxy_conn_meta_ctx_new()
{ {
log_dbg_printf(">>>>>................... pxy_conn_meta_ctx_new(): ENTER <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n"); log_dbg_level_printf(LOG_DBG_MODE_FINEST, ">>>>>................... pxy_conn_meta_ctx_new(): ENTER <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");
proxy_conn_meta_ctx_t *ctx = malloc(sizeof(proxy_conn_meta_ctx_t)); proxy_conn_meta_ctx_t *ctx = malloc(sizeof(proxy_conn_meta_ctx_t));
// proxy_conn_meta_ctx_t *ctx = malloc(100); // proxy_conn_meta_ctx_t *ctx = malloc(100);
if (!ctx) if (!ctx)
return NULL; return NULL;
memset(ctx, 0, sizeof(proxy_conn_meta_ctx_t)); memset(ctx, 0, sizeof(proxy_conn_meta_ctx_t));
log_dbg_printf(">>>>> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! pxy_conn_meta_ctx_new: sizeof(proxy_conn_meta_ctx_t)=%d <<<<<<\n", sizeof(proxy_conn_meta_ctx_t)); log_dbg_level_printf(LOG_DBG_MODE_FINEST, ">>>>> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! pxy_conn_meta_ctx_new: sizeof(proxy_conn_meta_ctx_t)=%d <<<<<<\n", sizeof(proxy_conn_meta_ctx_t));
ctx->next = NULL; ctx->next = NULL;
pthread_mutex_init(&ctx->mutex, NULL); pthread_mutex_init(&ctx->mutex, NULL);
log_dbg_printf(">>>>>................... pxy_conn_meta_ctx_new(): EXIT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n"); log_dbg_level_printf(LOG_DBG_MODE_FINEST, ">>>>>................... pxy_conn_meta_ctx_new(): EXIT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");
return ctx; return ctx;
} }
@ -202,24 +202,24 @@ int remove_ctx(proxy_conn_meta_ctx_t **current) {
proxy_conn_meta_ctx_t *tmp = *current; proxy_conn_meta_ctx_t *tmp = *current;
if (tmp->parent_ctx) { if (tmp->parent_ctx) {
log_dbg_printf(">>>>> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! remove_ctx: PARENT NOT NULL !!!!!!!!!!!!!!!!!!! <<<<<<\n"); log_dbg_level_printf(LOG_DBG_MODE_FINEST, ">>>>> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! remove_ctx: PARENT NOT NULL !!!!!!!!!!!!!!!!!!! <<<<<<\n");
return 0; return 0;
} }
if (tmp->child_ctx) { if (tmp->child_ctx) {
log_dbg_printf(">>>>> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! remove_ctx: CHILD NOT NULL !!!!!!!!!!!!!!!!!!! <<<<<<\n"); log_dbg_level_printf(LOG_DBG_MODE_FINEST, ">>>>> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! remove_ctx: CHILD NOT NULL !!!!!!!!!!!!!!!!!!! <<<<<<\n");
return 0; return 0;
} }
*current = (*current)->next; *current = (*current)->next;
log_dbg_printf(">>>>> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! remove_ctx: FREEING META CTX, size=%d <<<<<<\n", sizeof(*tmp)); log_dbg_level_printf(LOG_DBG_MODE_FINEST, ">>>>> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! remove_ctx: FREEING META CTX, size=%d <<<<<<\n", sizeof(*tmp));
pthread_mutex_destroy(&tmp->mutex); pthread_mutex_destroy(&tmp->mutex);
free(tmp); free(tmp);
tmp = NULL; tmp = NULL;
log_dbg_printf(">>>>> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! remove_ctx: EXIT <<<<<<\n"); log_dbg_level_printf(LOG_DBG_MODE_FINEST, ">>>>> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! remove_ctx: EXIT <<<<<<\n");
return 1; return 1;
// } // }
// log_dbg_printf(">>>>> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! remove_ctx: NOT FREEING UNRELEASED META CTX <<<<<<\n"); // log_dbg_level_printf(LOG_DBG_MODE_FINEST, ">>>>> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! remove_ctx: NOT FREEING UNRELEASED META CTX <<<<<<\n");
// return 0; // return 0;
} }
@ -231,23 +231,23 @@ proxy_listener_acceptcb(UNUSED struct evconnlistener *listener,
{ {
proxy_listener_ctx_t *lctx = arg; proxy_listener_ctx_t *lctx = arg;
log_dbg_printf(">>>>> proxy_listener_acceptcb: <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< LOCK\n"); log_dbg_level_printf(LOG_DBG_MODE_FINEST, ">>>>> proxy_listener_acceptcb: <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< LOCK\n");
// pthread_mutex_t *tmutex = &lctx->thrmgr->mutex2; // pthread_mutex_t *tmutex = &lctx->thrmgr->mutex2;
// pthread_mutex_t *lmutex = &lctx->mutex; // pthread_mutex_t *lmutex = &lctx->mutex;
// pthread_mutex_lock(lmutex); // pthread_mutex_lock(lmutex);
// int total = sizeof(pxy_conn_ctx_t *) + sizeof(pxy_conn_ctx_t *) + sizeof(pthread_mutex_t) + sizeof(unsigned int) + sizeof(proxy_conn_meta_ctx_t *); // int total = sizeof(pxy_conn_ctx_t *) + sizeof(pxy_conn_ctx_t *) + sizeof(pthread_mutex_t) + sizeof(unsigned int) + sizeof(proxy_conn_meta_ctx_t *);
// log_dbg_printf(">>>>> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! proxy_listener_acceptcb: TOTAL SIZE=%d <<<<<<\n", total); // log_dbg_level_printf(LOG_DBG_MODE_FINEST, ">>>>> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! proxy_listener_acceptcb: TOTAL SIZE=%d <<<<<<\n", total);
// log_dbg_printf(">>>>> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! proxy_listener_acceptcb: sizeof(pthread_mutex_t)=%d <<<<<<\n", sizeof(pthread_mutex_t)); // log_dbg_level_printf(LOG_DBG_MODE_FINEST, ">>>>> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! proxy_listener_acceptcb: sizeof(pthread_mutex_t)=%d <<<<<<\n", sizeof(pthread_mutex_t));
proxy_conn_meta_ctx_t *mctx = pxy_conn_meta_ctx_new(); proxy_conn_meta_ctx_t *mctx = pxy_conn_meta_ctx_new();
pthread_mutex_lock(&mctx->mutex); pthread_mutex_lock(&mctx->mutex);
mctx->lctx = lctx; mctx->lctx = lctx;
log_dbg_printf(">>>>>------------------------------------------------------------------------------------ proxy_listener_acceptcb(): fd=%d, previous fd2=%d\n", fd, lctx->fd2); log_dbg_level_printf(LOG_DBG_MODE_FINEST, ">>>>>------------------------------------------------------------------------------------ proxy_listener_acceptcb(): fd=%d, previous fd2=%d\n", fd, lctx->fd2);
log_dbg_printf(">>>>> proxy_listener_acceptcb: SETTING UP E2, lctx->clisock=%d\n", lctx->clisock); log_dbg_level_printf(LOG_DBG_MODE_FINEST, ">>>>> proxy_listener_acceptcb: SETTING UP E2, lctx->clisock=%d\n", lctx->clisock);
evutil_socket_t fd2; evutil_socket_t fd2;
if ((fd2 = privsep_client_opensock_e2(lctx->clisock, lctx->spec)) == -1) { if ((fd2 = privsep_client_opensock_e2(lctx->clisock, lctx->spec)) == -1) {
log_err_printf("Error opening socket: %s (%i)\n", log_err_printf("Error opening socket: %s (%i)\n",
@ -255,7 +255,7 @@ proxy_listener_acceptcb(UNUSED struct evconnlistener *listener,
return; return;
} }
log_dbg_printf(">>>>> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! proxy_listener_acceptcb: fd=%d, prev fd2=%d, NEW fd2=%d <<<<<<\n", fd, lctx->fd2, fd2); log_dbg_level_printf(LOG_DBG_MODE_FINEST, ">>>>> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! proxy_listener_acceptcb: fd=%d, prev fd2=%d, NEW fd2=%d <<<<<<\n", fd, lctx->fd2, fd2);
lctx->fd2 = fd2; lctx->fd2 = fd2;
mctx->fd2 = fd2; mctx->fd2 = fd2;
@ -283,10 +283,10 @@ proxy_listener_acceptcb(UNUSED struct evconnlistener *listener,
mctx->evcl2 = evcl2; mctx->evcl2 = evcl2;
evconnlistener_set_error_cb(evcl2, proxy_listener_errorcb); evconnlistener_set_error_cb(evcl2, proxy_listener_errorcb);
// log_dbg_printf(">>>>> proxy_listener_acceptcb: <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< bufferevent_enable(parent_ctx->dst.bev)\n"); // log_dbg_level_printf(LOG_DBG_MODE_FINEST, ">>>>> proxy_listener_acceptcb: <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< bufferevent_enable(parent_ctx->dst.bev)\n");
// bufferevent_enable(parent_ctx->dst.bev, EV_READ|EV_WRITE); // bufferevent_enable(parent_ctx->dst.bev, EV_READ|EV_WRITE);
log_dbg_printf(">>>>> proxy_listener_acceptcb: FINISHED SETTING UP E2 SUCCESS, parent fd=%d, NEW fd2=%d\n", fd, fd2); log_dbg_level_printf(LOG_DBG_MODE_FINE, ">>>>> proxy_listener_acceptcb: FINISHED SETTING UP E2 SUCCESS, parent fd=%d, NEW fd2=%d\n", fd, fd2);
// pthread_mutex_unlock(lmutex); // pthread_mutex_unlock(lmutex);
pthread_mutex_unlock(&mctx->mutex); pthread_mutex_unlock(&mctx->mutex);
} }
@ -316,7 +316,7 @@ static proxy_listener_ctx_t *
proxy_listener_setup(struct event_base *evbase, pxy_thrmgr_ctx_t *thrmgr, proxy_listener_setup(struct event_base *evbase, pxy_thrmgr_ctx_t *thrmgr,
proxyspec_t *spec, opts_t *opts, int clisock) proxyspec_t *spec, opts_t *opts, int clisock)
{ {
log_dbg_printf(">>>>> proxy_listener_setup\n"); log_dbg_level_printf(LOG_DBG_MODE_FINEST, ">>>>> proxy_listener_setup\n");
proxy_listener_ctx_t *lctx; proxy_listener_ctx_t *lctx;
int fd; int fd;

434
pxyconn.c

File diff suppressed because it is too large Load Diff

View File

@ -318,19 +318,19 @@ int
pxy_thrmgr_attach(pxy_thrmgr_ctx_t *ctx, struct event_base **evbase, pxy_thrmgr_attach(pxy_thrmgr_ctx_t *ctx, struct event_base **evbase,
struct evdns_base **dnsbase) struct evdns_base **dnsbase)
{ {
log_dbg_printf(">>>>> ENTER pxy_thrmgr_attach()\n"); log_dbg_level_printf(LOG_DBG_MODE_FINEST, ">>>>> ENTER pxy_thrmgr_attach()\n");
int thridx; int thridx;
size_t minload; size_t minload;
int err = pthread_mutex_lock(&ctx->mutex); int err = pthread_mutex_lock(&ctx->mutex);
log_dbg_printf(">>>>> load pxy_thrmgr_attach() err=%d\n", err); log_dbg_level_printf(LOG_DBG_MODE_FINEST, ">>>>> load pxy_thrmgr_attach() err=%d\n", err);
thridx = 0; thridx = 0;
if (!ctx->thr) { if (!ctx->thr) {
thridx= -1; thridx= -1;
log_dbg_printf(">>>>> pxy_thrmgr_attach() goto exit_attach\n"); log_dbg_level_printf(LOG_DBG_MODE_FINEST, ">>>>> pxy_thrmgr_attach() goto exit_attach\n");
goto exit_attach; goto exit_attach;
} }
@ -340,7 +340,7 @@ pxy_thrmgr_attach(pxy_thrmgr_ctx_t *ctx, struct event_base **evbase,
"thr[%d]: %zu\n", thridx, minload); "thr[%d]: %zu\n", thridx, minload);
#endif /* DEBUG_THREAD */ #endif /* DEBUG_THREAD */
log_dbg_printf(">>>>> for pxy_thrmgr_attach()\n"); log_dbg_level_printf(LOG_DBG_MODE_FINEST, ">>>>> for pxy_thrmgr_attach()\n");
for (int idx = 1; idx < ctx->num_thr; idx++) { for (int idx = 1; idx < ctx->num_thr; idx++) {
#ifdef DEBUG_THREAD #ifdef DEBUG_THREAD
@ -351,9 +351,9 @@ pxy_thrmgr_attach(pxy_thrmgr_ctx_t *ctx, struct event_base **evbase,
thridx = idx; thridx = idx;
} }
} }
log_dbg_printf(">>>>> evbase pxy_thrmgr_attach()\n"); log_dbg_level_printf(LOG_DBG_MODE_FINEST, ">>>>> evbase pxy_thrmgr_attach()\n");
*evbase = ctx->thr[thridx]->evbase; *evbase = ctx->thr[thridx]->evbase;
log_dbg_printf(">>>>> dnsbase pxy_thrmgr_attach()\n"); log_dbg_level_printf(LOG_DBG_MODE_FINEST, ">>>>> dnsbase pxy_thrmgr_attach()\n");
*dnsbase = ctx->thr[thridx]->dnsbase; *dnsbase = ctx->thr[thridx]->dnsbase;
ctx->thr[thridx]->load++; ctx->thr[thridx]->load++;
@ -361,7 +361,7 @@ pxy_thrmgr_attach(pxy_thrmgr_ctx_t *ctx, struct event_base **evbase,
log_dbg_printf("thridx: %d\n", thridx); log_dbg_printf("thridx: %d\n", thridx);
#endif /* DEBUG_THREAD */ #endif /* DEBUG_THREAD */
exit_attach: exit_attach:
log_dbg_printf(">>>>> EXIT pxy_thrmgr_attach()\n"); log_dbg_level_printf(LOG_DBG_MODE_FINEST, ">>>>> EXIT pxy_thrmgr_attach()\n");
pthread_mutex_unlock(&ctx->mutex); pthread_mutex_unlock(&ctx->mutex);
return thridx; return thridx;
} }
@ -373,10 +373,10 @@ exit_attach:
void void
pxy_thrmgr_detach(pxy_thrmgr_ctx_t *ctx, int thridx) pxy_thrmgr_detach(pxy_thrmgr_ctx_t *ctx, int thridx)
{ {
log_dbg_printf(">>>>> pxy_thrmgr_detach()\n"); log_dbg_level_printf(LOG_DBG_MODE_FINEST, ">>>>> pxy_thrmgr_detach()\n");
pthread_mutex_lock(&ctx->mutex); pthread_mutex_lock(&ctx->mutex);
// int err = pthread_mutex_trylock(&ctx->mutex); // int err = pthread_mutex_trylock(&ctx->mutex);
// log_dbg_printf(">>>>> pxy_thrmgr_detach() err=%d\n", err); // log_dbg_level_printf(LOG_DBG_MODE_FINEST, ">>>>> pxy_thrmgr_detach() err=%d\n", err);
ctx->thr[thridx]->load--; ctx->thr[thridx]->load--;
// if (!err) { // if (!err) {