1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-06 04:31:29 +00:00

Don't associate nsock logging info to a nspool.

Make current loglevel and current log callback global
to the library. Attaching them to the nsock pool doesn't
bring any benefit and prevents from logging activity in
code sections that don't have access to a pool (such as
proxy chain specification parsing).

Updated external calls and nsock tests accordingly.
This commit is contained in:
henri
2015-06-27 08:21:53 +00:00
parent b75233ce98
commit b55ff2d68f
34 changed files with 222 additions and 209 deletions

View File

@@ -191,8 +191,8 @@ void FPNetworkControl::init(const char *ifname, devtype iftype) {
if ((this->nsp = nsock_pool_new(NULL)) == NULL)
fatal("Unable to obtain an Nsock pool");
nsock_set_log_function(this->nsp, nmap_nsock_stderr_logger);
nmap_adjust_loglevel(this->nsp, o.packetTrace());
nsock_set_log_function(nmap_nsock_stderr_logger);
nmap_adjust_loglevel(o.packetTrace());
nsock_pool_set_device(nsp, o.device);
@@ -420,7 +420,7 @@ int FPNetworkControl::setup_sniffer(const char *iface, const char *bpf_filter) {
/* This method makes the controller process pending events (like packet
* transmissions or packet captures). */
void FPNetworkControl::handle_events() {
nmap_adjust_loglevel(nsp, o.packetTrace());
nmap_adjust_loglevel(o.packetTrace());
nsock_loop(nsp, 50);
}

View File

@@ -879,13 +879,13 @@ int ncat_connect(void)
bye("Failed to create nsock_pool.");
if (o.debug >= 6)
nsock_set_loglevel(mypool, NSOCK_LOG_DBG_ALL);
nsock_set_loglevel(NSOCK_LOG_DBG_ALL);
else if (o.debug >= 3)
nsock_set_loglevel(mypool, NSOCK_LOG_DBG);
nsock_set_loglevel(NSOCK_LOG_DBG);
else if (o.debug >= 1)
nsock_set_loglevel(mypool, NSOCK_LOG_INFO);
nsock_set_loglevel(NSOCK_LOG_INFO);
else
nsock_set_loglevel(mypool, NSOCK_LOG_ERROR);
nsock_set_loglevel(NSOCK_LOG_ERROR);
/* Allow connections to broadcast addresses. */
nsock_pool_set_broadcast(mypool, 1);

View File

@@ -1216,8 +1216,8 @@ static void nmap_mass_rdns_core(Target **targets, int num_targets) {
if ((dnspool = nsock_pool_new(NULL)) == NULL)
fatal("Unable to create nsock pool in %s()", __func__);
nsock_set_log_function(dnspool, nmap_nsock_stderr_logger);
nmap_adjust_loglevel(dnspool, o.packetTrace());
nsock_set_log_function(nmap_nsock_stderr_logger);
nmap_adjust_loglevel(o.packetTrace());
nsock_pool_set_device(dnspool, o.device);
@@ -1241,7 +1241,7 @@ static void nmap_mass_rdns_core(Target **targets, int num_targets) {
if (total_reqs <= 0) break;
/* Because this can change with runtime interaction */
nmap_adjust_loglevel(dnspool, o.packetTrace());
nmap_adjust_loglevel(o.packetTrace());
nsock_loop(dnspool, timeout);
}

View File

@@ -1451,9 +1451,9 @@ int EchoServer::start() {
/* Set nsock trace level */
gettimeofday(&now, NULL);
if( o.getDebugging() == DBG_5 )
nsock_set_loglevel(nsp, NSOCK_LOG_INFO);
nsock_set_loglevel(NSOCK_LOG_INFO);
else if( o.getDebugging() > DBG_5 )
nsock_set_loglevel(nsp, NSOCK_LOG_DBG_ALL);
nsock_set_loglevel(NSOCK_LOG_DBG_ALL);
/* Create new IOD for pcap */
if ((pcap_nsi = nsock_iod_new(nsp, NULL)) == NULL)

View File

@@ -162,9 +162,9 @@ int ProbeMode::init_nsock(){
/* Set nsock trace level */
gettimeofday(&now, NULL);
if( o.getDebugging() == DBG_5)
nsock_set_loglevel(nsp, NSOCK_LOG_INFO);
nsock_set_loglevel(NSOCK_LOG_INFO);
else if( o.getDebugging() > DBG_5 )
nsock_set_loglevel(nsp, NSOCK_LOG_DBG_ALL);
nsock_set_loglevel(NSOCK_LOG_DBG_ALL);
/* Flag it as already initialized so we don't do it again */
nsock_init=true;
}

View File

@@ -81,8 +81,8 @@ static nsock_pool new_pool (lua_State *L)
nsock_pool *nspp;
/* configure logging */
nsock_set_log_function(nsp, nmap_nsock_stderr_logger);
nmap_adjust_loglevel(nsp, o.scriptTrace());
nsock_set_log_function(nmap_nsock_stderr_logger);
nmap_adjust_loglevel(o.scriptTrace());
nsock_pool_set_device(nsp, o.device);
@@ -418,7 +418,7 @@ static int l_loop (lua_State *L)
socket_unlock(L); /* clean up old socket locks */
nmap_adjust_loglevel(nsp, o.scriptTrace());
nmap_adjust_loglevel(o.scriptTrace());
if (nsock_loop(nsp, tout) == NSOCK_LOOP_ERROR)
return luaL_error(L, "a fatal error occurred in nsock_loop");
return 0;

View File

@@ -171,7 +171,7 @@ struct nsock_log_rec {
/* Nsock logging function. This function receives all nsock log records whose
* level is greater than or equal to nsp loglevel. The rec structure is
* allocated and freed by nsock. */
typedef void (*nsock_logger_t)(nsock_pool nsp, const struct nsock_log_rec *rec);
typedef void (*nsock_logger_t)(const struct nsock_log_rec *rec);
/* ------------------- PROTOTYPES ------------------- */
@@ -200,7 +200,7 @@ void nsock_loop_quit(nsock_pool nsp);
/* This next function returns the errno style error code -- which is only valid
* if the status is NSOCK_LOOP_ERROR was returned by nsock_loop() */
int nsock_pool_get_errorcode(nsock_pool nsp);
int nsock_pool_get_error(nsock_pool nsp);
nsock_ssl nsock_iod_get_ssl(nsock_iod nsockiod);
@@ -274,11 +274,12 @@ nsock_pool nsock_pool_new(void *udata);
void nsock_pool_delete(nsock_pool nsp);
/* Logging subsystem: set custom logging function.
* A NULL logger will reset the default (stderr) logger.
* (See nsock_logger_t type definition). */
void nsock_set_log_function(nsock_pool nsp, nsock_logger_t logger);
void nsock_set_log_function(nsock_logger_t logger);
nsock_loglevel_t nsock_get_loglevel(nsock_pool nsp);
void nsock_set_loglevel(nsock_pool nsp, nsock_loglevel_t loglevel);
nsock_loglevel_t nsock_get_loglevel(void);
void nsock_set_loglevel(nsock_loglevel_t loglevel);
/* Parse a proxy chain description string and build a nsock_proxychain object
* accordingly. If the optional nsock_pool parameter is passed in, it gets

View File

@@ -265,7 +265,7 @@ int epoll_loop(struct npool *nsp, int msec_timeout) {
do {
struct nevent *nse;
nsock_log_debug_all(nsp, "wait for events");
nsock_log_debug_all("wait for events");
nse = next_expirable_event(nsp);
if (!nse)
@@ -306,7 +306,7 @@ int epoll_loop(struct npool *nsp, int msec_timeout) {
} while (results_left == -1 && sock_err == EINTR); /* repeat only if signal occurred */
if (results_left == -1 && sock_err != EINTR) {
nsock_log_error(nsp, "nsock_loop error %d: %s", sock_err, socket_strerror(sock_err));
nsock_log_error("nsock_loop error %d: %s", sock_err, socket_strerror(sock_err));
nsp->errnum = sock_err;
return -1;
}

View File

@@ -239,7 +239,7 @@ int kqueue_loop(struct npool *nsp, int msec_timeout) {
do {
struct nevent *nse;
nsock_log_debug_all(nsp, "wait for events");
nsock_log_debug_all("wait for events");
nse = next_expirable_event(nsp);
if (!nse)
@@ -290,7 +290,7 @@ int kqueue_loop(struct npool *nsp, int msec_timeout) {
} while (results_left == -1 && sock_err == EINTR); /* repeat only if signal occurred */
if (results_left == -1 && sock_err != EINTR) {
nsock_log_error(nsp, "nsock_loop error %d: %s", sock_err, socket_strerror(sock_err));
nsock_log_error("nsock_loop error %d: %s", sock_err, socket_strerror(sock_err));
nsp->errnum = sock_err;
return -1;
}

View File

@@ -315,7 +315,7 @@ int poll_loop(struct npool *nsp, int msec_timeout) {
do {
struct nevent *nse;
nsock_log_debug_all(nsp, "wait for events");
nsock_log_debug_all("wait for events");
nse = next_expirable_event(nsp);
if (!nse)
@@ -356,7 +356,7 @@ int poll_loop(struct npool *nsp, int msec_timeout) {
} while (results_left == -1 && sock_err == EINTR); /* repeat only if signal occurred */
if (results_left == -1 && sock_err != EINTR) {
nsock_log_error(nsp, "nsock_loop error %d: %s", sock_err, socket_strerror(sock_err));
nsock_log_error("nsock_loop error %d: %s", sock_err, socket_strerror(sock_err));
nsp->errnum = sock_err;
return -1;
}

View File

@@ -254,7 +254,7 @@ int select_loop(struct npool *nsp, int msec_timeout) {
do {
struct nevent *nse;
nsock_log_debug_all(nsp, "wait for events");
nsock_log_debug_all("wait for events");
nse = next_expirable_event(nsp);
if (!nse)
@@ -316,7 +316,7 @@ int select_loop(struct npool *nsp, int msec_timeout) {
} while (results_left == -1 && sock_err == EINTR); /* repeat only if signal occurred */
if (results_left == -1 && sock_err != EINTR) {
nsock_log_error(nsp, "nsock_loop error %d: %s", sock_err, socket_strerror(sock_err));
nsock_log_error("nsock_loop error %d: %s", sock_err, socket_strerror(sock_err));
nsp->errnum = sock_err;
return -1;
}

View File

@@ -73,16 +73,16 @@ static int mksock_bind_addr(struct npool *ms, struct niod *iod) {
if (rc == -1) {
int err = socket_errno();
nsock_log_error(ms, "Setting of SO_REUSEADDR failed (#%li): %s (%d)", iod->id,
nsock_log_error("Setting of SO_REUSEADDR failed (#%li): %s (%d)", iod->id,
socket_strerror(err), err);
}
nsock_log_info(ms, "Binding to %s (IOD #%li)", get_localaddr_string(iod), iod->id);
nsock_log_info("Binding to %s (IOD #%li)", get_localaddr_string(iod), iod->id);
rc = bind(iod->sd, (struct sockaddr *)&iod->local, (int) iod->locallen);
if (rc == -1) {
int err = socket_errno();
nsock_log_error(ms, "Bind to %s failed (IOD #%li): %s (%d)",
nsock_log_error("Bind to %s failed (IOD #%li): %s (%d)",
get_localaddr_string(iod), iod->id,
socket_strerror(err), err);
}
@@ -98,7 +98,7 @@ static int mksock_set_ipopts(struct npool *ms, struct niod *iod) {
if (rc == -1) {
int err = socket_errno();
nsock_log_error(ms, "Setting of IP options failed (IOD #%li): %s (%d)",
nsock_log_error("Setting of IP options failed (IOD #%li): %s (%d)",
iod->id, socket_strerror(err), err);
}
return 0;
@@ -112,10 +112,10 @@ static int mksock_bind_device(struct npool *ms, struct niod *iod) {
int err = socket_errno();
if (err != EPERM)
nsock_log_error(ms, "Setting of SO_BINDTODEVICE failed (IOD #%li): %s (%d)",
nsock_log_error("Setting of SO_BINDTODEVICE failed (IOD #%li): %s (%d)",
iod->id, socket_strerror(err), err);
else
nsock_log_debug_all(ms, "Setting of SO_BINDTODEVICE failed (IOD #%li): %s (%d)",
nsock_log_debug_all("Setting of SO_BINDTODEVICE failed (IOD #%li): %s (%d)",
iod->id, socket_strerror(err), err);
}
return 0;
@@ -130,7 +130,7 @@ static int mksock_set_broadcast(struct npool *ms, struct niod *iod) {
if (rc == -1) {
int err = socket_errno();
nsock_log_error(ms, "Setting of SO_BROADCAST failed (IOD #%li): %s (%d)",
nsock_log_error("Setting of SO_BROADCAST failed (IOD #%li): %s (%d)",
iod->id, socket_strerror(err), err);
}
return 0;
@@ -145,7 +145,7 @@ static int nsock_make_socket(struct npool *ms, struct niod *iod, int family, int
/* inheritable_socket is from nbase */
iod->sd = (int)inheritable_socket(family, type, proto);
if (iod->sd == -1) {
nsock_log_error(ms, "Socket trouble: %s", socket_strerror(socket_errno()));
nsock_log_error("Socket trouble: %s", socket_strerror(socket_errno()));
return -1;
}
@@ -176,7 +176,7 @@ int nsock_setup_udp(nsock_pool nsp, nsock_iod ms_iod, int af) {
assert(nsi->state == NSIOD_STATE_INITIAL || nsi->state == NSIOD_STATE_UNKNOWN);
nsock_log_info(ms, "UDP unconnected socket (IOD #%li)", nsi->id);
nsock_log_info("UDP unconnected socket (IOD #%li)", nsi->id);
if (nsock_make_socket(ms, nsi, af, SOCK_DGRAM, IPPROTO_UDP) == -1)
return -1;
@@ -200,7 +200,7 @@ void nsock_connect_internal(struct npool *ms, struct nevent *nse, int type, int
&& (nse->handler != nsock_proxy_ev_dispatch)) { /* for reentrancy */
struct proxy_node *current;
nsock_log_debug_all(ms, "TCP connection request (EID %lu) redirected through proxy chain",
nsock_log_debug_all("TCP connection request (EID %lu) redirected through proxy chain",
(long)nse->id);
current = iod->px_ctx->px_current;
@@ -284,7 +284,7 @@ nsock_event_id nsock_connect_unixsock_stream(nsock_pool nsp, nsock_iod nsiod, ns
nse = event_new(ms, NSE_TYPE_CONNECT, nsi, timeout_msecs, handler, userdata);
assert(nse);
nsock_log_info(ms, "UNIX domain socket (STREAM) connection requested to %s (IOD #%li) EID %li",
nsock_log_info("UNIX domain socket (STREAM) connection requested to %s (IOD #%li) EID %li",
get_unixsock_path(ss), nsi->id, nse->id);
nsock_connect_internal(ms, nse, SOCK_STREAM, 0, ss, sslen, 0);
@@ -310,7 +310,7 @@ nsock_event_id nsock_connect_unixsock_datagram(nsock_pool nsp, nsock_iod nsiod,
nse = event_new(ms, NSE_TYPE_CONNECT, nsi, -1, handler, userdata);
assert(nse);
nsock_log_info(ms, "UNIX domain socket (DGRAM) connection requested to %s (IOD #%li) EID %li",
nsock_log_info("UNIX domain socket (DGRAM) connection requested to %s (IOD #%li) EID %li",
get_unixsock_path(ss), nsi->id, nse->id);
nsock_connect_internal(ms, nse, SOCK_DGRAM, 0, ss, sslen, 0);
@@ -338,7 +338,7 @@ nsock_event_id nsock_connect_tcp(nsock_pool nsp, nsock_iod ms_iod, nsock_ev_hand
nse = event_new(ms, NSE_TYPE_CONNECT, nsi, timeout_msecs, handler, userdata);
assert(nse);
nsock_log_info(ms, "TCP connection requested to %s:%hu (IOD #%li) EID %li",
nsock_log_info("TCP connection requested to %s:%hu (IOD #%li) EID %li",
inet_ntop_ez(ss, sslen), port, nsi->id, nse->id);
/* Do the actual connect() */
@@ -366,7 +366,7 @@ nsock_event_id nsock_connect_sctp(nsock_pool nsp, nsock_iod ms_iod, nsock_ev_han
nse = event_new(ms, NSE_TYPE_CONNECT, nsi, timeout_msecs, handler, userdata);
assert(nse);
nsock_log_info(ms, "SCTP association requested to %s:%hu (IOD #%li) EID %li",
nsock_log_info("SCTP association requested to %s:%hu (IOD #%li) EID %li",
inet_ntop_ez(ss, sslen), port, nsi->id, nse->id);
/* Do the actual connect() */
@@ -407,7 +407,7 @@ nsock_event_id nsock_connect_ssl(nsock_pool nsp, nsock_iod nsiod, nsock_ev_handl
/* Set our SSL_SESSION so we can benefit from session-id reuse. */
nsi_set_ssl_session(nsi, (SSL_SESSION *)ssl_session);
nsock_log_info(ms, "SSL connection requested to %s:%hu/%s (IOD #%li) EID %li",
nsock_log_info("SSL connection requested to %s:%hu/%s (IOD #%li) EID %li",
inet_ntop_ez(ss, sslen), port, (proto == IPPROTO_TCP ? "tcp" : "sctp"),
nsi->id, nse->id);
@@ -443,7 +443,7 @@ nsock_event_id nsock_reconnect_ssl(nsock_pool nsp, nsock_iod nsiod, nsock_ev_han
/* Set our SSL_SESSION so we can benefit from session-id reuse. */
nsi_set_ssl_session(nsi, (SSL_SESSION *)ssl_session);
nsock_log_info(ms, "SSL reconnection requested (IOD #%li) EID %li",
nsock_log_info("SSL reconnection requested (IOD #%li) EID %li",
nsi->id, nse->id);
/* Do the actual connect() */
@@ -482,7 +482,7 @@ nsock_event_id nsock_connect_udp(nsock_pool nsp, nsock_iod nsiod, nsock_ev_handl
nse = event_new(ms, NSE_TYPE_CONNECT, nsi, -1, handler, userdata);
assert(nse);
nsock_log_info(ms, "UDP connection requested to %s:%hu (IOD #%li) EID %li",
nsock_log_info("UDP connection requested to %s:%hu (IOD #%li) EID %li",
inet_ntop_ez(ss, sslen), port, nsi->id, nse->id);
nsock_connect_internal(ms, nse, SOCK_DGRAM, IPPROTO_UDP, ss, sslen, port);

View File

@@ -435,7 +435,7 @@ void handle_connect_result(struct npool *ms, struct nevent *nse, enum nse_status
if (iod->ssl_session) {
rc = SSL_set_session(iod->ssl, iod->ssl_session);
if (rc == 0)
nsock_log_error(ms, "Uh-oh: SSL_set_session() failed - please tell dev@nmap.org");
nsock_log_error("Uh-oh: SSL_set_session() failed - please tell dev@nmap.org");
iod->ssl_session = NULL; /* No need for this any more */
}
@@ -456,7 +456,7 @@ void handle_connect_result(struct npool *ms, struct nevent *nse, enum nse_status
if (nsi_ssl_post_connect_verify(iod)) {
nse->status = NSE_STATUS_SUCCESS;
} else {
nsock_log_error(ms, "certificate verification error for EID %li: %s",
nsock_log_error("certificate verification error for EID %li: %s",
nse->id, ERR_error_string(ERR_get_error(), NULL));
nse->status = NSE_STATUS_ERROR;
}
@@ -480,7 +480,7 @@ void handle_connect_result(struct npool *ms, struct nevent *nse, enum nse_status
* was initialized with nsock_pool_ssl_init_max_speed. Try reconnecting
* with SSL_OP_NO_SSLv2. Never downgrade a NO_SSLv2 connection to one
* that might use SSLv2. */
nsock_log_info(ms, "EID %li reconnecting with SSL_OP_NO_SSLv2", nse->id);
nsock_log_info("EID %li reconnecting with SSL_OP_NO_SSLv2", nse->id);
saved_ev = iod->watched_events;
nsock_engine_iod_unregister(ms, iod);
@@ -499,7 +499,7 @@ void handle_connect_result(struct npool *ms, struct nevent *nse, enum nse_status
update_events(iod, ms, EV_READ|EV_WRITE, EV_NONE);
nse->sslinfo.ssl_desire = SSL_ERROR_WANT_CONNECT;
} else {
nsock_log_info(ms, "EID %li %s",
nsock_log_info("EID %li %s",
nse->id, ERR_error_string(ERR_get_error(), NULL));
nse->event_done = 1;
nse->status = NSE_STATUS_ERROR;
@@ -717,7 +717,7 @@ static int do_actual_read(struct npool *ms, struct nevent *nse) {
nse->event_done = 1;
nse->status = NSE_STATUS_ERROR;
nse->errnum = EIO;
nsock_log_info(ms, "SSL_read() failed for reason %s on NSI %li",
nsock_log_info("SSL_read() failed for reason %s on NSI %li",
ERR_reason_error_string(err), iod->id);
return -1;
}
@@ -902,10 +902,10 @@ enum nsock_loopstatus nsock_loop(nsock_pool nsp, int msec_timeout) {
msecs_left = msec_timeout;
if (msec_timeout >= 0)
nsock_log_debug(ms, "nsock_loop() started (timeout=%dms). %d events pending",
nsock_log_debug("nsock_loop() started (timeout=%dms). %d events pending",
msec_timeout, ms->events_pending);
else
nsock_log_debug(ms, "nsock_loop() started (no timeout). %d events pending",
nsock_log_debug("nsock_loop() started (no timeout). %d events pending",
ms->events_pending);
while (1) {
@@ -950,7 +950,7 @@ void process_event(struct npool *nsp, gh_list_t *evlist, struct nevent *nse, int
int desire_r = 0, desire_w = 0;
#endif
nsock_log_debug_all(nsp, "Processing event %lu (timeout in %ldms, done=%d)",
nsock_log_debug_all("Processing event %lu (timeout in %ldms, done=%d)",
nse->id,
(long)TIMEVAL_MSEC_SUBTRACT(nse->timeout, nsock_tod),
nse->event_done);
@@ -1006,7 +1006,7 @@ void process_event(struct npool *nsp, gh_list_t *evlist, struct nevent *nse, int
#if HAVE_PCAP
case NSE_TYPE_PCAP_READ:{
nsock_log_debug_all(nsp, "PCAP iterating %lu", nse->id);
nsock_log_debug_all("PCAP iterating %lu", nse->id);
if (ev & EV_READ) {
/* buffer empty? check it! */
@@ -1035,7 +1035,7 @@ void process_event(struct npool *nsp, gh_list_t *evlist, struct nevent *nse, int
update_first_events(nse);
gh_list_remove(&nsp->pcap_read_events, &nse->nodeq_pcap);
nsock_log_debug_all(nsp, "PCAP NSE #%lu: Removing event from PCAP_READ_EVENTS",
nsock_log_debug_all("PCAP NSE #%lu: Removing event from PCAP_READ_EVENTS",
nse->id);
}
if (((mspcap *)nse->iod->pcap)->pcap_desc >= 0
@@ -1043,7 +1043,7 @@ void process_event(struct npool *nsp, gh_list_t *evlist, struct nevent *nse, int
&& evlist == &nsp->pcap_read_events) {
update_first_events(nse);
gh_list_remove(&nsp->read_events, &nse->nodeq_io);
nsock_log_debug_all(nsp, "PCAP NSE #%lu: Removing event from READ_EVENTS",
nsock_log_debug_all("PCAP NSE #%lu: Removing event from READ_EVENTS",
nse->id);
}
#endif
@@ -1061,7 +1061,7 @@ void process_event(struct npool *nsp, gh_list_t *evlist, struct nevent *nse, int
if (nse->type == NSE_TYPE_CONNECT_SSL && nse->status == NSE_STATUS_SUCCESS)
assert(nse->iod->ssl != NULL);
nsock_log_debug_all(nsp, "NSE #%lu: Sending event", nse->id);
nsock_log_debug_all("NSE #%lu: Sending event", nse->id);
/* WooHoo! The event is ready to be sent */
event_dispatch_and_delete(nsp, nse, 1);
@@ -1092,7 +1092,7 @@ void process_iod_events(struct npool *nsp, struct niod *nsi, int ev) {
};
assert(nsp == nsi->nsp);
nsock_log_debug_all(nsp, "Processing events on IOD %lu (ev=%d)", nsi->id, ev);
nsock_log_debug_all("Processing events on IOD %lu (ev=%d)", nsi->id, ev);
/* We keep the events separate because we want to handle them in the
* order: connect => read => write => timer for several reasons:
@@ -1238,7 +1238,7 @@ const struct timeval *nsock_gettimeofday() {
* adjusting the descriptor select/poll lists, registering the timeout value,
* etc. */
void nsock_pool_add_event(struct npool *nsp, struct nevent *nse) {
nsock_log_debug(nsp, "NSE #%lu: Adding event (timeout in %ldms)",
nsock_log_debug("NSE #%lu: Adding event (timeout in %ldms)",
nse->id,
(long)TIMEVAL_MSEC_SUBTRACT(nse->timeout, nsock_tod));
@@ -1302,17 +1302,17 @@ void nsock_pool_add_event(struct npool *nsp, struct nevent *nse) {
socket_count_readpcap_inc(nse->iod);
update_events(nse->iod, nsp, EV_READ, EV_NONE);
}
nsock_log_debug_all(nsp, "PCAP NSE #%lu: Adding event to READ_EVENTS", nse->id);
nsock_log_debug_all("PCAP NSE #%lu: Adding event to READ_EVENTS", nse->id);
#if PCAP_BSD_SELECT_HACK
/* when using BSD hack we must do pcap_next() after select().
* Let's insert this pcap to bot queues, to selectable and nonselectable.
* This will result in doing pcap_next_ex() just before select() */
nsock_log_debug_all(nsp, "PCAP NSE #%lu: Adding event to PCAP_READ_EVENTS", nse->id);
nsock_log_debug_all("PCAP NSE #%lu: Adding event to PCAP_READ_EVENTS", nse->id);
#endif
} else {
/* pcap isn't selectable. Add it to pcap-specific queue. */
nsock_log_debug_all(nsp, "PCAP NSE #%lu: Adding event to PCAP_READ_EVENTS", nse->id);
nsock_log_debug_all("PCAP NSE #%lu: Adding event to PCAP_READ_EVENTS", nse->id);
}
iod_add_event(nse->iod, nse);
break;
@@ -1341,7 +1341,7 @@ void nsock_trace_handler_callback(struct npool *ms, struct nevent *nse) {
char displaystr[256];
char errstr[256];
if (ms->loglevel > NSOCK_LOG_INFO)
if (NsockLogLevel > NSOCK_LOG_INFO)
return;
nsi = nse->iod;
@@ -1356,14 +1356,14 @@ void nsock_trace_handler_callback(struct npool *ms, struct nevent *nse) {
switch (nse->type) {
case NSE_TYPE_CONNECT:
case NSE_TYPE_CONNECT_SSL:
nsock_log_info(ms, "Callback: %s %s %sfor EID %li [%s]",
nsock_log_info("Callback: %s %s %sfor EID %li [%s]",
nse_type2str(nse->type), nse_status2str(nse->status),
errstr, nse->id, get_peeraddr_string(nsi));
break;
case NSE_TYPE_READ:
if (nse->status != NSE_STATUS_SUCCESS) {
nsock_log_info(ms, "Callback: %s %s %sfor EID %li [%s]",
nsock_log_info("Callback: %s %s %sfor EID %li [%s]",
nse_type2str(nse->type), nse_status2str(nse->status),
errstr, nse->id, get_peeraddr_string(nsi));
} else {
@@ -1376,7 +1376,7 @@ void nsock_trace_handler_callback(struct npool *ms, struct nevent *nse) {
} else {
displaystr[0] = '\0';
}
nsock_log_info(ms, "Callback: %s %s for EID %li [%s] %s(%d bytes)%s",
nsock_log_info("Callback: %s %s for EID %li [%s] %s(%d bytes)%s",
nse_type2str(nse->type), nse_status2str(nse->status),
nse->id,
get_peeraddr_string(nsi),
@@ -1385,20 +1385,20 @@ void nsock_trace_handler_callback(struct npool *ms, struct nevent *nse) {
break;
case NSE_TYPE_WRITE:
nsock_log_info(ms, "Callback: %s %s %sfor EID %li [%s]",
nsock_log_info("Callback: %s %s %sfor EID %li [%s]",
nse_type2str(nse->type), nse_status2str(nse->status),
errstr, nse->id, get_peeraddr_string(nsi));
break;
case NSE_TYPE_TIMER:
nsock_log_info(ms, "Callback: %s %s %sfor EID %li",
nsock_log_info("Callback: %s %s %sfor EID %li",
nse_type2str(nse->type), nse_status2str(nse->status),
errstr, nse->id);
break;
#if HAVE_PCAP
case NSE_TYPE_PCAP_READ:
nsock_log_info(ms, "Callback: %s %s %sfor EID %li ",
nsock_log_info("Callback: %s %s %sfor EID %li ",
nse_type2str(nse->type), nse_status2str(nse->status),
errstr, nse->id);
break;

View File

@@ -193,7 +193,7 @@ int nsock_event_cancel(nsock_pool ms_pool, nsock_event_id id, int notify) {
assert(nsp);
type = get_event_id_type(id);
nsock_log_info(nsp, "Event #%li (type %s) cancelled", id, nse_type2str(type));
nsock_log_info("Event #%li (type %s) cancelled", id, nse_type2str(type));
/* First we figure out what list it is in */
switch (type) {
@@ -271,7 +271,7 @@ int nevent_delete(struct npool *nsp, struct nevent *nse, gh_list_t *event_list,
return 0;
}
nsock_log_info(nsp, "%s on event #%li (type %s)", __func__, nse->id,
nsock_log_info("%s on event #%li (type %s)", __func__, nse->id,
nse_type2str(nse->type));
/* Now that we found the event... we go through the motions of cleanly
@@ -316,12 +316,12 @@ int nevent_delete(struct npool *nsp, struct nevent *nse, gh_list_t *event_list,
gh_list_append(&nsp->free_events, &nse->nodeq_io);
nsock_log_debug_all(nsp, "NSE #%lu: Removing event from list", nse->id);
nsock_log_debug_all("NSE #%lu: Removing event from list", nse->id);
#if HAVE_PCAP
#if PCAP_BSD_SELECT_HACK
if (nse->type == NSE_TYPE_PCAP_READ) {
nsock_log_debug_all(nsp, "PCAP NSE #%lu: CANCEL TEST pcap=%p read=%p curr=%p sd=%i",
nsock_log_debug_all("PCAP NSE #%lu: CANCEL TEST pcap=%p read=%p curr=%p sd=%i",
nse->id, &nsp->pcap_read_events, &nsp->read_events,
event_list,((mspcap *)nse->iod->pcap)->pcap_desc);
@@ -333,7 +333,7 @@ int nevent_delete(struct npool *nsp, struct nevent *nse, gh_list_t *event_list,
/* event is done, list is read_events and we're in BSD_HACK mode. So unlink
* event from pcap_read_events */
gh_list_remove(&nsp->pcap_read_events, &nse->nodeq_pcap);
nsock_log_debug_all(nsp, "PCAP NSE #%lu: Removing event from PCAP_READ_EVENTS", nse->id);
nsock_log_debug_all("PCAP NSE #%lu: Removing event from PCAP_READ_EVENTS", nse->id);
}
if (((mspcap *)nse->iod->pcap)->pcap_desc >= 0 && event_list == &nsp->pcap_read_events) {
@@ -341,7 +341,7 @@ int nevent_delete(struct npool *nsp, struct nevent *nse, gh_list_t *event_list,
* So unlink event from read_events */
gh_list_remove(&nsp->read_events, &nse->nodeq_io);
nsock_log_debug_all(nsp, "PCAP NSE #%lu: Removing event from READ_EVENTS", nse->id);
nsock_log_debug_all("PCAP NSE #%lu: Removing event from READ_EVENTS", nse->id);
}
}
#endif
@@ -469,9 +469,9 @@ struct nevent *event_new(struct npool *nsp, enum nse_type type,
nse->userdata = userdata;
if (nse->iod == NULL)
nsock_log_debug(nsp, "%s (IOD #NULL) (EID #%li)", __func__, nse->id);
nsock_log_debug("%s (IOD #NULL) (EID #%li)", __func__, nse->id);
else
nsock_log_debug(nsp, "%s (IOD #%li) (EID #%li)", __func__, nse->iod->id,
nsock_log_debug("%s (IOD #%li) (EID #%li)", __func__, nse->iod->id,
nse->id);
return nse;
}
@@ -482,9 +482,9 @@ struct nevent *event_new(struct npool *nsp, enum nse_type type,
* remember to do this if you call event_delete() directly */
void event_delete(struct npool *nsp, struct nevent *nse) {
if (nse->iod == NULL)
nsock_log_debug(nsp, "%s (IOD #NULL) (EID #%li)", __func__, nse->id);
nsock_log_debug("%s (IOD #NULL) (EID #%li)", __func__, nse->id);
else
nsock_log_debug(nsp, "%s (IOD #%li) (EID #%li)", __func__, nse->iod->id, nse->id);
nsock_log_debug("%s (IOD #%li) (EID #%li)", __func__, nse->iod->id, nse->id);
/* First free the IOBuf inside it if necessary */
if (nse->type == NSE_TYPE_READ || nse->type == NSE_TYPE_WRITE) {
@@ -493,7 +493,7 @@ void event_delete(struct npool *nsp, struct nevent *nse) {
#if HAVE_PCAP
if (nse->type == NSE_TYPE_PCAP_READ) {
fs_free(&nse->iobuf);
nsock_log_debug_all(nsp, "PCAP removed %lu", nse->id);
nsock_log_debug_all("PCAP removed %lu", nse->id);
}
#endif

View File

@@ -189,10 +189,6 @@ struct npool {
* error (errnum fashion) */
int errnum;
/* Logging information. */
nsock_logger_t logger;
nsock_loglevel_t loglevel;
/* If true, new sockets will have SO_BROADCAST set */
int broadcast;

View File

@@ -153,7 +153,7 @@ nsock_iod nsock_iod_new2(nsock_pool nsockp, int sd, void *userdata) {
/* The nsp keeps track of active iods so it can delete them if it is deleted */
gh_list_append(&nsp->active_iods, &nsi->nodeq);
nsock_log_info(nsp, "nsock_iod_new (IOD #%lu)", nsi->id);
nsock_log_info("nsock_iod_new (IOD #%lu)", nsi->id);
return (nsock_iod)nsi;
}
@@ -184,7 +184,7 @@ void nsock_iod_delete(nsock_iod nsockiod, enum nsock_del_mode pending_response)
return;
}
nsock_log_info(nsi->nsp, "nsock_iod_delete (IOD #%lu)", nsi->id);
nsock_log_info("nsock_iod_delete (IOD #%lu)", nsi->id);
if (nsi->events_pending > 0) {
/* shit -- they killed the struct niod while an event was still pending on it.
@@ -242,7 +242,7 @@ void nsock_iod_delete(nsock_iod nsockiod, enum nsock_del_mode pending_response)
#endif
if (SSL_shutdown(nsi->ssl) == -1) {
nsock_log_info(nsi->nsp, "nsock_iod_delete: SSL shutdown failed (%s) on NSI %li",
nsock_log_info("nsock_iod_delete: SSL shutdown failed (%s) on NSI %li",
ERR_reason_error_string(SSL_get_error(nsi->ssl, -1)), nsi->id);
}

View File

@@ -66,35 +66,38 @@
#include "nsock_internal.h"
#include "nsock_log.h"
static void nsock_stderr_logger(const struct nsock_log_rec *rec);
extern struct timeval nsock_tod;
nsock_loglevel_t NsockLogLevel = NSOCK_LOOP_ERROR;
nsock_logger_t NsockLogger = nsock_stderr_logger;
void nsock_set_log_function(nsock_pool nsp, nsock_logger_t logger) {
struct npool *ms = (struct npool *)nsp;
ms->logger = logger;
nsock_log_debug(ms, "Registered external logging function: %p", logger);
void nsock_set_log_function(nsock_logger_t logger) {
if (logger != NULL)
NsockLogger = logger;
else
NsockLogger = nsock_stderr_logger;
nsock_log_debug("Registered external logging function: %p", NsockLogger);
}
nsock_loglevel_t nsock_get_loglevel(nsock_pool nsp) {
struct npool *ms = (struct npool *)nsp;
return ms->loglevel;
nsock_loglevel_t nsock_get_loglevel(void) {
return NsockLogLevel;
}
void nsock_set_loglevel(nsock_pool nsp, nsock_loglevel_t loglevel) {
struct npool *ms = (struct npool *)nsp;
ms->loglevel = loglevel;
void nsock_set_loglevel(nsock_loglevel_t loglevel) {
NsockLogLevel = loglevel;
nsock_log_debug("Set log level to %s", nsock_loglevel2str(loglevel));
}
void nsock_stderr_logger(nsock_pool nsp, const struct nsock_log_rec *rec) {
void nsock_stderr_logger(const struct nsock_log_rec *rec) {
fprintf(stderr, "libnsock %s(): %s\n", rec->func, rec->msg);
}
void __nsock_log_internal(nsock_pool nsp, nsock_loglevel_t loglevel,
const char *file, int line, const char *func,
const char *format, ...) {
void __nsock_log_internal(nsock_loglevel_t loglevel, const char *file, int line,
const char *func, const char *format, ...) {
struct nsock_log_rec rec;
va_list args;
int rc;
@@ -109,9 +112,7 @@ void __nsock_log_internal(nsock_pool nsp, nsock_loglevel_t loglevel,
rc = vasprintf(&rec.msg, format, args);
if (rc >= 0) {
struct npool *ms = (struct npool *)nsp;
ms->logger(nsp, &rec);
NsockLogger(&rec);
free(rec.msg);
}
va_end(args);

View File

@@ -60,43 +60,60 @@
#include "nsock.h"
extern nsock_loglevel_t NsockLogLevel;
extern nsock_logger_t NsockLogger;
#define NSOCK_LOG_WRAP(nsp, lvl, ...) \
#define NSOCK_LOG_WRAP(lvl, ...) \
do { \
if ((nsp)->logger && (lvl) >= (nsp)->loglevel) { \
__nsock_log_internal((nsp), (lvl), __FILE__, __LINE__, __func__, __VA_ARGS__); \
if (NsockLogger && (lvl) >= NsockLogLevel) { \
__nsock_log_internal((lvl), __FILE__, __LINE__, __func__, __VA_ARGS__); \
} \
} while (0)
static inline const char *nsock_loglevel2str(nsock_loglevel_t level)
{
switch (level) {
case NSOCK_LOG_DBG_ALL:
return "FULL DEBUG";
case NSOCK_LOG_DBG:
return "DEBUG";
case NSOCK_LOG_INFO:
return "INFO";
case NSOCK_LOG_ERROR:
return "ERROR";
default:
return "???";
}
}
/* -- Internal logging macros -- */
/**
* Most detailed debug messages, like allocating or moving objects.
*/
#define nsock_log_debug_all(nsp, ...) NSOCK_LOG_WRAP(nsp, NSOCK_LOG_DBG_ALL, __VA_ARGS__)
#define nsock_log_debug_all(...) NSOCK_LOG_WRAP(NSOCK_LOG_DBG_ALL, __VA_ARGS__)
/**
* Detailed debug messages, describing internal operations.
*/
#define nsock_log_debug(nsp, ...) NSOCK_LOG_WRAP(nsp, NSOCK_LOG_DBG, __VA_ARGS__)
#define nsock_log_debug(...) NSOCK_LOG_WRAP(NSOCK_LOG_DBG, __VA_ARGS__)
/**
* High level debug messages, describing top level operations and external
* requests.
*/
#define nsock_log_info(nsp, ...) NSOCK_LOG_WRAP(nsp, NSOCK_LOG_INFO, __VA_ARGS__)
#define nsock_log_info(...) NSOCK_LOG_WRAP(NSOCK_LOG_INFO, __VA_ARGS__)
/**
* Error messages.
*/
#define nsock_log_error(nsp, ...) NSOCK_LOG_WRAP(nsp, NSOCK_LOG_ERROR, __VA_ARGS__)
#define nsock_log_error(...) NSOCK_LOG_WRAP(NSOCK_LOG_ERROR, __VA_ARGS__)
void __nsock_log_internal(nsock_pool nsp, nsock_loglevel_t loglevel,
const char *file, int line, const char *func,
const char *format, ...) __attribute__((format (printf, 6, 7)));
void nsock_stderr_logger(nsock_pool nsp, const struct nsock_log_rec *rec);
void __nsock_log_internal(nsock_loglevel_t loglevel, const char *file, int line,
const char *func, const char *format, ...)
__attribute__((format (printf, 5, 6)));
#endif /* NSOCK_LOG_H */

View File

@@ -109,13 +109,13 @@ static int nsock_pcap_set_filter(struct npool *nsp, pcap_t *pt, const char *devi
rc = pcap_compile(pt, &fcode, (char *)bpf, 1, PCAP_NETMASK_UNKNOWN);
if (rc) {
nsock_log_error(nsp, "Error compiling pcap filter: %s", pcap_geterr(pt));
nsock_log_error("Error compiling pcap filter: %s", pcap_geterr(pt));
return rc;
}
rc = pcap_setfilter(pt, &fcode);
if (rc) {
nsock_log_error(nsp, "Failed to set the pcap filter: %s", pcap_geterr(pt));
nsock_log_error("Failed to set the pcap filter: %s", pcap_geterr(pt));
return rc;
}
@@ -202,7 +202,7 @@ static int nsock_pcap_try_open(struct npool *nsp, mspcap *mp, const char *dev,
char *errbuf) {
mp->pt = pcap_open_live(dev, snaplen, promisc, timeout_ms, errbuf);
if (!mp->pt) {
nsock_log_error(nsp, "pcap_open_live(%s, %d, %d, %d) failed with error: %s",
nsock_log_error("pcap_open_live(%s, %d, %d, %d) failed with error: %s",
dev, snaplen, promisc, timeout_ms, errbuf);
return -1;
}
@@ -245,7 +245,7 @@ int nsock_pcap_open(nsock_pool nsp, nsock_iod nsiod, const char *pcap_device,
gettimeofday(&nsock_tod, NULL);
if (mp) {
nsock_log_error(ms, "This nsi already has pcap device opened");
nsock_log_error("This nsi already has pcap device opened");
return -1;
}
@@ -257,11 +257,11 @@ int nsock_pcap_open(nsock_pool nsp, nsock_iod nsiod, const char *pcap_device,
va_end(ap);
if (rc >= (int)sizeof(bpf)) {
nsock_log_error(ms, "Too-large bpf filter argument");
nsock_log_error("Too-large bpf filter argument");
return -1;
}
nsock_log_info(ms, "PCAP requested on device '%s' with berkeley filter '%s' "
nsock_log_info("PCAP requested on device '%s' with berkeley filter '%s' "
"(promisc=%i snaplen=%i to_ms=%i) (IOD #%li)",
pcap_device,bpf, promisc, snaplen, to_ms, nsi->id);
@@ -270,16 +270,16 @@ int nsock_pcap_open(nsock_pool nsp, nsock_iod nsiod, const char *pcap_device,
rc = nsock_pcap_try_open(ms, mp, pcap_device, snaplen, promisc, to_ms, errbuf);
if (rc) {
failed++;
nsock_log_error(ms, "Will wait %d seconds then retry.", 4 * failed);
nsock_log_error("Will wait %d seconds then retry.", 4 * failed);
sleep(4 * failed);
}
} while (rc && failed < PCAP_OPEN_MAX_RETRIES);
if (rc) {
nsock_log_error(ms, "pcap_open_live(%s, %d, %d, %d) failed %d times.",
nsock_log_error("pcap_open_live(%s, %d, %d, %d) failed %d times.",
pcap_device, snaplen, promisc, to_ms, failed);
nsock_log_error(ms, PCAP_FAILURE_EXPL_MESSAGE);
nsock_log_error(ms, "Can't open pcap! Are you root?");
nsock_log_error(PCAP_FAILURE_EXPL_MESSAGE);
nsock_log_error("Can't open pcap! Are you root?");
return -1;
}
@@ -327,16 +327,16 @@ int nsock_pcap_open(nsock_pool nsp, nsock_iod nsiod, const char *pcap_device,
if (mp->pcap_desc < 0)
#endif
{
nsock_log_error(ms, "Failed to set pcap descriptor on device %s "
nsock_log_error("Failed to set pcap descriptor on device %s "
"to nonblocking mode: %s", pcap_device, errbuf);
return -1;
}
/* in other case, we can accept blocking pcap */
nsock_log_info(ms, "Failed to set pcap descriptor on device %s "
nsock_log_info("Failed to set pcap descriptor on device %s "
"to nonblocking state: %s", pcap_device, errbuf);
}
if (ms->loglevel <= NSOCK_LOG_INFO) {
if (NsockLogLevel <= NSOCK_LOG_INFO) {
#if PCAP_BSD_SELECT_HACK
int bsd_select_hack = 1;
#else
@@ -349,7 +349,7 @@ int nsock_pcap_open(nsock_pool nsp, nsock_iod nsiod, const char *pcap_device,
int recv_timeval_valid = 0;
#endif
nsock_log_info(ms, "PCAP created successfully on device '%s' "
nsock_log_info("PCAP created successfully on device '%s' "
"(pcap_desc=%i bsd_hack=%i to_valid=%i l3_offset=%i) (IOD #%li)",
pcap_device, mp->pcap_desc, bsd_select_hack,
recv_timeval_valid, mp->l3_offset, nsi->id);
@@ -368,7 +368,7 @@ nsock_event_id nsock_pcap_read_packet(nsock_pool nsp, nsock_iod nsiod,
nse = event_new(ms, NSE_TYPE_PCAP_READ, nsi, timeout_msecs, handler, userdata);
assert(nse);
nsock_log_info(ms, "Pcap read request from IOD #%li EID %li", nsi->id, nse->id);
nsock_log_info("Pcap read request from IOD #%li EID %li", nsi->id, nse->id);
nsock_pool_add_event(ms, nse);
@@ -386,7 +386,7 @@ int do_actual_pcap_read(struct nevent *nse) {
memset(&npp, 0, sizeof(nsock_pcap));
nsock_log_debug_all(nse->iod->nsp, "PCAP %s TEST (IOD #%li) (EID #%li)",
nsock_log_debug_all("PCAP %s TEST (IOD #%li) (EID #%li)",
__func__, nse->iod->id, nse->id);
assert(fs_length(&(nse->iobuf)) == 0);
@@ -410,8 +410,7 @@ int do_actual_pcap_read(struct nevent *nse) {
n = (nsock_pcap *)fs_str(&(nse->iobuf));
n->packet = (unsigned char *)fs_str(&(nse->iobuf)) + sizeof(npp);
nsock_log_debug_all(nse->iod->nsp,
"PCAP %s READ (IOD #%li) (EID #%li) size=%i",
nsock_log_debug_all("PCAP %s READ (IOD #%li) (EID #%li) size=%i",
__func__, nse->iod->id, nse->id, pkt_header->caplen);
rc = 1;
break;

View File

@@ -89,7 +89,7 @@ static void nsock_library_initialize(void);
/* This next function returns the errno style error code -- which is only
* valid if the status NSOCK_LOOP_ERROR was returned by nsock_loop() */
int nsock_pool_get_errorcode(nsock_pool nsp) {
int nsock_pool_get_error(nsock_pool nsp) {
struct npool *mt = (struct npool *)nsp;
return mt->errnum;
}
@@ -150,9 +150,6 @@ nsock_pool nsock_pool_new(void *userdata) {
gettimeofday(&nsock_tod, NULL);
nsp->loglevel = NSOCK_LOG_ERROR;
nsp->logger = (nsock_logger_t)nsock_stderr_logger;
nsp->userdata = userdata;
nsp->engine = get_io_engine();

View File

@@ -141,7 +141,7 @@ int nsock_pool_set_proxychain(nsock_pool nspool, nsock_proxychain chain) {
struct npool *nsp = (struct npool *)nspool;
if (nsp && nsp->px_chain) {
nsock_log_error(nsp, "Invalid call. Existing proxychain on this nsock_pool");
nsock_log_error("Invalid call. Existing proxychain on this nsock_pool");
return -1;
}
@@ -426,7 +426,7 @@ void forward_event(nsock_pool nspool, nsock_event nsevent, void *udata) {
if (nse->status != NSE_STATUS_SUCCESS)
nse->status = NSE_STATUS_PROXYERROR;
nsock_log_info(nsp, "Forwarding event upstream: TCP connect %s (IOD #%li) EID %li",
nsock_log_info("Forwarding event upstream: TCP connect %s (IOD #%li) EID %li",
nse_status2str(nse->status), nse->iod->id, nse->id);
nse->iod->px_ctx->target_handler(nsp, nse, udata);

View File

@@ -75,7 +75,7 @@ nsock_event_id nsock_readlines(nsock_pool nsp, nsock_iod ms_iod,
nse = event_new(ms, NSE_TYPE_READ, nsi, timeout_msecs, handler, userdata);
assert(nse);
nsock_log_info(ms, "Read request for %d lines from IOD #%li [%s] EID %li",
nsock_log_info("Read request for %d lines from IOD #%li [%s] EID %li",
nlines, nsi->id, get_peeraddr_string(nsi), nse->id);
nse->readinfo.read_type = NSOCK_READLINES;
@@ -98,7 +98,7 @@ nsock_event_id nsock_readbytes(nsock_pool nsp, nsock_iod ms_iod,
nse = event_new(ms, NSE_TYPE_READ, nsi, timeout_msecs, handler, userdata);
assert(nse);
nsock_log_info(ms, "Read request for %d bytes from IOD #%li [%s] EID %li",
nsock_log_info("Read request for %d bytes from IOD #%li [%s] EID %li",
nbytes, nsi->id, get_peeraddr_string(nsi), nse->id);
nse->readinfo.read_type = NSOCK_READBYTES;
@@ -122,7 +122,7 @@ nsock_event_id nsock_read(nsock_pool nsp, nsock_iod ms_iod,
nse = event_new(ms, NSE_TYPE_READ, nsi, timeout_msecs, handler, userdata);
assert(nse);
nsock_log_info(ms, "Read request from IOD #%li [%s] (timeout: %dms) EID %li",
nsock_log_info("Read request from IOD #%li [%s] (timeout: %dms) EID %li",
nsi->id, get_peeraddr_string(nsi), timeout_msecs, nse->id);
nse->readinfo.read_type = NSOCK_READ;

View File

@@ -70,7 +70,7 @@ nsock_event_id nsock_timer_create(nsock_pool ms_pool, nsock_ev_handler handler,
nse = event_new(nsp, NSE_TYPE_TIMER, NULL, timeout_msecs, handler, userdata);
assert(nse);
nsock_log_info(nsp, "Timer created - %dms from now. EID %li", timeout_msecs,
nsock_log_info("Timer created - %dms from now. EID %li", timeout_msecs,
nse->id);
nsock_pool_add_event(nsp, nse);

View File

@@ -104,7 +104,7 @@ nsock_event_id nsock_sendto(nsock_pool ms_pool, nsock_iod ms_iod, nsock_ev_handl
if (datalen < 0)
datalen = (int) strlen(data);
if (nsp->loglevel == NSOCK_LOG_DBG_ALL && datalen < 80) {
if (NsockLogLevel == NSOCK_LOG_DBG_ALL && datalen < 80) {
memcpy(displaystr, ": ", 2);
memcpy(displaystr + 2, data, datalen);
displaystr[2 + datalen] = '\0';
@@ -112,8 +112,9 @@ nsock_event_id nsock_sendto(nsock_pool ms_pool, nsock_iod ms_iod, nsock_ev_handl
} else {
displaystr[0] = '\0';
}
nsock_log_debug(nsp, "Sendto request for %d bytes to IOD #%li EID %li [%s]%s",
datalen, nsi->id, nse->id, get_peeraddr_string(nse->iod), displaystr);
nsock_log_info("Sendto request for %d bytes to IOD #%li EID %li [%s]%s",
datalen, nsi->id, nse->id, get_peeraddr_string(nse->iod),
displaystr);
fs_cat(&nse->iobuf, data, datalen);
@@ -141,7 +142,7 @@ nsock_event_id nsock_write(nsock_pool ms_pool, nsock_iod ms_iod,
if (datalen < 0)
datalen = (int)strlen(data);
if (nsp->loglevel == NSOCK_LOG_DBG_ALL && datalen < 80) {
if (NsockLogLevel == NSOCK_LOG_DBG_ALL && datalen < 80) {
memcpy(displaystr, ": ", 2);
memcpy(displaystr + 2, data, datalen);
displaystr[2 + datalen] = '\0';
@@ -150,8 +151,9 @@ nsock_event_id nsock_write(nsock_pool ms_pool, nsock_iod ms_iod,
displaystr[0] = '\0';
}
nsock_log_debug(nsp, "Write request for %d bytes to IOD #%li EID %li [%s]%s",
datalen, nsi->id, nse->id, get_peeraddr_string(nsi), displaystr);
nsock_log_info("Write request for %d bytes to IOD #%li EID %li [%s]%s",
datalen, nsi->id, nse->id, get_peeraddr_string(nsi),
displaystr);
fs_cat(&nse->iobuf, data, datalen);
@@ -209,7 +211,9 @@ nsock_event_id nsock_printf(nsock_pool ms_pool, nsock_iod ms_iod,
}
}
if (nsp->loglevel == NSOCK_LOG_DBG_ALL && nse->status != NSE_STATUS_ERROR && strlength < 80) {
if (NsockLogLevel == NSOCK_LOG_DBG_ALL &&
nse->status != NSE_STATUS_ERROR &&
strlength < 80) {
memcpy(displaystr, ": ", 2);
memcpy(displaystr + 2, buf2, strlength);
displaystr[2 + strlength] = '\0';
@@ -218,8 +222,9 @@ nsock_event_id nsock_printf(nsock_pool ms_pool, nsock_iod ms_iod,
displaystr[0] = '\0';
}
nsock_log_debug(nsp, "Write request for %d bytes to IOD #%li EID %li [%s]%s",
strlength, nsi->id, nse->id, get_peeraddr_string(nsi), displaystr);
nsock_log_info("Write request for %d bytes to IOD #%li EID %li [%s]%s",
strlength, nsi->id, nse->id, get_peeraddr_string(nsi),
displaystr);
if (buf2 != buf)
free(buf2);

View File

@@ -154,7 +154,7 @@ static int handle_state_tcp_connected(struct npool *nsp, struct nevent *nse, voi
if (!((reslen >= 15) && strstr(res, "200 OK"))) {
struct proxy_node *node = px_ctx->px_current;
nsock_log_debug(nsp, "Connection refused from proxy %s", node->nodestr);
nsock_log_debug("Connection refused from proxy %s", node->nodestr);
return -EINVAL;
}

View File

@@ -185,7 +185,7 @@ static int handle_state_tcp_connected(struct npool *nsp, struct nevent *nse, voi
if (!(reslen == 8 && res[1] == 90)) {
struct proxy_node *node = px_ctx->px_current;
nsock_log_debug(nsp, "Ignoring invalid socks4 reply from proxy %s",
nsock_log_debug("Ignoring invalid socks4 reply from proxy %s",
node->nodestr);
return -EINVAL;
}

View File

@@ -17,7 +17,7 @@ static int basic_setup(void **tdata) {
if (btd == NULL)
return -ENOMEM;
btd->nsp = nsp_new(NULL);
btd->nsp = nsock_pool_new(NULL);
*tdata = btd;
return 0;
@@ -27,7 +27,7 @@ static int basic_teardown(void *tdata) {
struct basic_test_data *btd = (struct basic_test_data *)tdata;
if (tdata) {
nsp_delete(btd->nsp);
nsock_pool_delete(btd->nsp);
free(tdata);
}
return 0;
@@ -36,9 +36,9 @@ static int basic_teardown(void *tdata) {
static int basic_udata(void *tdata) {
struct basic_test_data *btd = (struct basic_test_data *)tdata;
AssertEqual(nsp_getud(btd->nsp), NULL);
nsp_setud(btd->nsp, btd);
AssertEqual(nsp_getud(btd->nsp), btd);
AssertEqual(nsock_pool_get_udata(btd->nsp), NULL);
nsock_pool_set_udata(btd->nsp, btd);
AssertEqual(nsock_pool_get_udata(btd->nsp), btd);
return 0;
}

View File

@@ -25,7 +25,7 @@ static int cancel_setup(void **tdata) {
if (btd == NULL)
return -ENOMEM;
btd->nsp = nsp_new(NULL);
btd->nsp = nsock_pool_new(NULL);
*tdata = btd;
return 0;
@@ -35,7 +35,7 @@ static int cancel_teardown(void *tdata) {
struct basic_test_data *btd = (struct basic_test_data *)tdata;
if (tdata) {
nsp_delete(btd->nsp);
nsock_pool_delete(btd->nsp);
free(tdata);
}
return 0;
@@ -48,7 +48,7 @@ static int cancel_tcp_run(void *tdata) {
nsock_event_id id;
int done = 0;
iod = nsi_new(btd->nsp, NULL);
iod = nsock_iod_new(btd->nsp, NULL);
AssertNonNull(iod);
memset(&peer, 0, sizeof(peer));
@@ -59,7 +59,7 @@ static int cancel_tcp_run(void *tdata) {
(struct sockaddr *)&peer, sizeof(peer), PORT_TCP);
nsock_event_cancel(btd->nsp, id, 1);
nsi_delete(iod, NSOCK_PENDING_SILENT);
nsock_iod_delete(iod, NSOCK_PENDING_SILENT);
return (done == 1) ? 0 : -ENOEXEC;
}
@@ -71,7 +71,7 @@ static int cancel_udp_run(void *tdata) {
nsock_event_id id;
int done = 0;
iod = nsi_new(btd->nsp, NULL);
iod = nsock_iod_new(btd->nsp, NULL);
AssertNonNull(iod);
memset(&peer, 0, sizeof(peer));
@@ -82,7 +82,7 @@ static int cancel_udp_run(void *tdata) {
(struct sockaddr *)&peer, sizeof(peer), PORT_UDP);
nsock_event_cancel(btd->nsp, id, 1);
nsi_delete(iod, NSOCK_PENDING_SILENT);
nsock_iod_delete(iod, NSOCK_PENDING_SILENT);
return (done == 1) ? 0 : -ENOEXEC;
}
@@ -94,7 +94,7 @@ static int cancel_ssl_run(void *tdata) {
nsock_event_id id;
int done = 0;
iod = nsi_new(btd->nsp, NULL);
iod = nsock_iod_new(btd->nsp, NULL);
AssertNonNull(iod);
memset(&peer, 0, sizeof(peer));
@@ -106,7 +106,7 @@ static int cancel_ssl_run(void *tdata) {
PORT_TCPSSL, NULL);
nsock_event_cancel(btd->nsp, id, 1);
nsi_delete(iod, NSOCK_PENDING_SILENT);
nsock_iod_delete(iod, NSOCK_PENDING_SILENT);
return (done == 1) ? 0 : -ENOEXEC;
}

View File

@@ -16,7 +16,7 @@ struct connect_test_data {
static void connect_handler(nsock_pool nsp, nsock_event nse, void *udata) {
struct connect_test_data *ctd;
ctd = (struct connect_test_data *)nsp_getud(nsp);
ctd = (struct connect_test_data *)nsock_pool_get_udata(nsp);
switch(nse_status(nse)) {
case NSE_STATUS_SUCCESS:
@@ -44,10 +44,10 @@ static int connect_setup(void **tdata) {
if (ctd == NULL)
return -ENOMEM;
ctd->nsp = nsp_new(ctd);
ctd->nsp = nsock_pool_new(ctd);
AssertNonNull(ctd->nsp);
ctd->nsi = nsi_new(ctd->nsp, NULL);
ctd->nsi = nsock_iod_new(ctd->nsp, NULL);
AssertNonNull(ctd->nsi);
*tdata = ctd;
@@ -58,8 +58,8 @@ static int connect_teardown(void *tdata) {
struct connect_test_data *ctd = (struct connect_test_data *)tdata;
if (tdata) {
nsi_delete(ctd->nsi, NSOCK_PENDING_SILENT); /* nsp_delete would also handle it */
nsp_delete(ctd->nsp);
nsock_iod_delete(ctd->nsi, NSOCK_PENDING_SILENT); /* nsock_pool_delete would also handle it */
nsock_pool_delete(ctd->nsp);
free(tdata);
}
return 0;

View File

@@ -17,45 +17,41 @@ struct log_test_data {
int errcode;
};
static struct log_test_data *GlobalLTD;
static void log_handler(nsock_pool nsp, const struct nsock_log_rec *rec) {
struct log_test_data *ltd;
ltd = (struct log_test_data *)nsp_getud(nsp);
ltd->total++;
static void log_handler(const struct nsock_log_rec *rec) {
GlobalLTD->total++;
switch(rec->level) {
case NSOCK_LOG_DBG_ALL:
ltd->got_dbgfull = 1;
GlobalLTD->got_dbgfull = 1;
break;
case NSOCK_LOG_DBG:
ltd->got_dbg = 1;
GlobalLTD->got_dbg = 1;
break;
case NSOCK_LOG_INFO:
ltd->got_info = 1;
GlobalLTD->got_info = 1;
break;
case NSOCK_LOG_ERROR:
ltd->got_error = 1;
GlobalLTD->got_error = 1;
break;
default:
fprintf(stderr, "UNEXPECTED LOG LEVEL (%d)!\n", (int)rec->level);
ltd->errcode = -EINVAL;
GlobalLTD->errcode = -EINVAL;
}
}
static void nop_handler(nsock_pool nsp, nsock_event nse, void *udata) {
return;
}
static int check_loglevel(struct log_test_data *ltd, nsock_loglevel_t level) {
int rc = 0;
nsock_event_id id;
nsock_set_loglevel(ltd->nsp, level);
nsock_set_loglevel(level);
ltd->current_level = level;
@@ -82,7 +78,7 @@ static int check_loglevel(struct log_test_data *ltd, nsock_loglevel_t level) {
static int check_errlevel(struct log_test_data *ltd, nsock_loglevel_t level) {
nsock_event_id id;
nsock_set_loglevel(ltd->nsp, level);
nsock_set_loglevel(level);
ltd->current_level = level;
@@ -113,10 +109,10 @@ static int log_setup(void **tdata) {
if (ltd == NULL)
return -ENOMEM;
ltd->nsp = nsp_new(ltd);
ltd->nsp = nsock_pool_new(ltd);
AssertNonNull(ltd->nsp);
*tdata = ltd;
*tdata = GlobalLTD = ltd;
return 0;
}
@@ -124,9 +120,10 @@ static int log_teardown(void *tdata) {
struct log_test_data *ltd = (struct log_test_data *)tdata;
if (tdata) {
nsp_delete(ltd->nsp);
nsock_pool_delete(ltd->nsp);
free(tdata);
}
GlobalLTD = NULL;
return 0;
}
@@ -135,7 +132,7 @@ static int log_check_std_levels(void *tdata) {
nsock_loglevel_t lvl;
int rc = 0;
nsock_set_log_function(ltd->nsp, log_handler);
nsock_set_log_function(log_handler);
for (lvl = NSOCK_LOG_DBG_ALL; lvl < NSOCK_LOG_ERROR; lvl++) {
rc = check_loglevel(ltd, lvl);
@@ -151,7 +148,7 @@ static int log_check_err_levels(void *tdata) {
nsock_loglevel_t lvl;
int rc = 0;
nsock_set_log_function(ltd->nsp, log_handler);
nsock_set_log_function(log_handler);
for (lvl = NSOCK_LOG_ERROR; lvl <= NSOCK_LOG_NONE; lvl++) {
rc = check_errlevel(ltd, NSOCK_LOG_ERROR);

View File

@@ -32,7 +32,7 @@ static void timer_handler(nsock_pool nsp, nsock_event nse, void *tdata) {
int rnd, rnd2;
if (nse_status(nse) != NSE_STATUS_SUCCESS) {
ttd->stop = -nsp_geterrorcode(nsp);
ttd->stop = -nsock_pool_get_error(nsp);
return;
}
@@ -74,7 +74,7 @@ static int timer_setup(void **tdata) {
if (ttd == NULL)
return -ENOMEM;
ttd->nsp = nsp_new(NULL);
ttd->nsp = nsock_pool_new(NULL);
AssertNonNull(ttd->nsp);
*tdata = ttd;
@@ -85,7 +85,7 @@ static int timer_teardown(void *tdata) {
struct timer_test_data *ttd = (struct timer_test_data *)tdata;
if (tdata) {
nsp_delete(ttd->nsp);
nsock_pool_delete(ttd->nsp);
free(tdata);
}
return 0;
@@ -114,7 +114,7 @@ static int timer_totalmess(void *tdata) {
return 0;
default:
return -(nsp_geterrorcode(ttd->nsp));
return -(nsock_pool_get_error(ttd->nsp));
}
}
return ttd->stop;

View File

@@ -2677,7 +2677,7 @@ static inline const char *nslog2str(nsock_loglevel_t loglevel) {
};
}
void nmap_adjust_loglevel(nsock_pool nsp, bool trace) {
void nmap_adjust_loglevel(bool trace) {
nsock_loglevel_t nsock_loglevel;
if (o.debugging >= 7)
@@ -2689,10 +2689,10 @@ void nmap_adjust_loglevel(nsock_pool nsp, bool trace) {
else
nsock_loglevel = NSOCK_LOG_ERROR;
nsock_set_loglevel(nsp, nsock_loglevel);
nsock_set_loglevel(nsock_loglevel);
}
void nmap_nsock_stderr_logger(nsock_pool nsp, const struct nsock_log_rec *rec) {
void nmap_nsock_stderr_logger(const struct nsock_log_rec *rec) {
int elapsed_time;
elapsed_time = TIMEVAL_MSEC_SUBTRACT(rec->time, *(o.getStartTime()));

View File

@@ -284,8 +284,8 @@ void printfinaloutput();
void printdatafilepaths();
/* nsock logging interface */
void nmap_adjust_loglevel(nsock_pool nsp, bool trace);
void nmap_nsock_stderr_logger(nsock_pool nsp, const struct nsock_log_rec *rec);
void nmap_adjust_loglevel(bool trace);
void nmap_nsock_stderr_logger(const struct nsock_log_rec *rec);
#endif /* OUTPUT_H */

View File

@@ -2127,7 +2127,7 @@ static int scanThroughTunnel(nsock_pool nsp, nsock_iod nsi, ServiceGroup *SG,
static void considerPrintingStats(nsock_pool nsp, ServiceGroup *SG) {
/* Check for status requests */
if (keyWasPressed()) {
nmap_adjust_loglevel(nsp, o.versionTrace());
nmap_adjust_loglevel(o.versionTrace());
SG->SPM->printStats(SG->services_finished.size() /
((double)SG->services_remaining.size() + SG->services_in_progress.size() +
SG->services_finished.size()), nsock_gettimeofday());
@@ -2757,8 +2757,8 @@ int service_scan(std::vector<Target *> &Targets) {
if ((nsp = nsock_pool_new(SG)) == NULL) {
fatal("%s() failed to create new nsock pool.", __func__);
}
nsock_set_log_function(nsp, nmap_nsock_stderr_logger);
nmap_adjust_loglevel(nsp, o.versionTrace());
nsock_set_log_function(nmap_nsock_stderr_logger);
nmap_adjust_loglevel(o.versionTrace());
nsock_pool_set_device(nsp, o.device);
@@ -2780,7 +2780,7 @@ int service_scan(std::vector<Target *> &Targets) {
// OK! Lets start our main loop!
looprc = nsock_loop(nsp, timeout);
if (looprc == NSOCK_LOOP_ERROR) {
int err = nsock_pool_get_errorcode(nsp);
int err = nsock_pool_get_error(nsp);
fatal("Unexpected nsock_loop error. Error code %d (%s)", err, socket_strerror(err));
}