Minor debug updates

This commit is contained in:
Joseph Henry 2015-11-12 14:49:20 -08:00
parent fa7220ec0e
commit 6af54c5943
5 changed files with 21 additions and 29 deletions

View File

@ -39,11 +39,12 @@
#include <fcntl.h> #include <fcntl.h>
#define DEBUG_LEVEL 5 #define DEBUG_LEVEL 2
#define MSG_ERROR 0 // Errors #define MSG_ERROR 0 // Errors
#define MSG_INFO 1 // Information which is generally useful to any user #define MSG_INFO 1 // Information which is generally useful to any user
#define MSG_DEBUG 2 // Information which is only useful to someone debugging #define MSG_DEBUG 2 // Information which is only useful to someone debugging
#define MSG_DEBUG_EXTRA 3 //
#ifdef NETCON_INTERCEPT #ifdef NETCON_INTERCEPT
@ -78,22 +79,18 @@ void print_addr(struct sockaddr *addr)
#endif #endif
void dwr(int level, char *fmt, ... ) void dwr(int level, char *fmt, ... )
{ {
#ifdef NETCON_SERVICE
if(level > DEBUG_LEVEL) if(level > DEBUG_LEVEL)
return; return;
#endif
int saveerr; int saveerr;
saveerr = errno; saveerr = errno;
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
#ifdef VERBOSE // So we can cut out some clutter in the strace output while debugging
char timestring[20]; char timestring[20];
time_t timestamp; time_t timestamp;
timestamp = time(NULL); timestamp = time(NULL);
strftime(timestring, sizeof(timestring), "%H:%M:%S", localtime(&timestamp)); strftime(timestring, sizeof(timestring), "%H:%M:%S", localtime(&timestamp));
pid_t pid = getpid(); pid_t pid = getpid();
#ifdef VERBOSE
fprintf(stderr, "%s [pid=%7d] ", timestring, pid); fprintf(stderr, "%s [pid=%7d] ", timestring, pid);
#endif #endif
vfprintf(stderr, fmt, ap); vfprintf(stderr, fmt, ap);

View File

@ -980,7 +980,7 @@ int dup3(DUP3_SIG)
long syscall(SYSCALL_SIG) long syscall(SYSCALL_SIG)
{ {
dwr(MSG_DEBUG,"syscall(%u, ...):\n", number); dwr(MSG_DEBUG_EXTRA,"syscall(%u, ...):\n", number);
va_list ap; va_list ap;
uintptr_t a,b,c,d,e,f; uintptr_t a,b,c,d,e,f;

View File

@ -87,7 +87,7 @@ NetconEthernetTap::NetconEthernetTap(
lwipstack->lwip_init(); lwipstack->lwip_init();
_unixListenSocket = _phy.unixListen(sockPath,(void *)this); _unixListenSocket = _phy.unixListen(sockPath,(void *)this);
dwr(1, " NetconEthernetTap(): RPC listening on: %d\n", _phy.getDescriptor(_unixListenSocket)); dwr(MSG_INFO, " NetconEthernetTap initialized!\n", _phy.getDescriptor(_unixListenSocket));
if (!_unixListenSocket) if (!_unixListenSocket)
throw std::runtime_error(std::string("unable to bind to ")+sockPath); throw std::runtime_error(std::string("unable to bind to ")+sockPath);
_thread = Thread::start(this); _thread = Thread::start(this);
@ -187,7 +187,7 @@ void NetconEthernetTap::put(const MAC &from,const MAC &to,unsigned int etherType
// First pbuf gets ethernet header at start // First pbuf gets ethernet header at start
q = p; q = p;
if (q->len < sizeof(ethhdr)) { if (q->len < sizeof(ethhdr)) {
dwr(1, "_put(): Dropped packet: first pbuf smaller than ethernet header\n"); dwr(MSG_ERROR, "_put(): Dropped packet: first pbuf smaller than ethernet header\n");
return; return;
} }
memcpy(q->payload,&ethhdr,sizeof(ethhdr)); memcpy(q->payload,&ethhdr,sizeof(ethhdr));
@ -200,25 +200,23 @@ void NetconEthernetTap::put(const MAC &from,const MAC &to,unsigned int etherType
dataptr += q->len; dataptr += q->len;
} }
} else { } else {
dwr(1, "put(): Dropped packet: no pbufs available\n"); dwr(MSG_ERROR, "put(): Dropped packet: no pbufs available\n");
return; return;
} }
{ {
Mutex::Lock _l2(lwipstack->_lock); Mutex::Lock _l2(lwipstack->_lock);
if(interface.input(p, &interface) != ERR_OK) { if(interface.input(p, &interface) != ERR_OK) {
dwr(1, "put(): Error while RXing packet (netif->input)\n"); dwr(MSG_ERROR, "put(): Error while RXing packet (netif->input)\n");
} }
} }
} }
std::string NetconEthernetTap::deviceName() const std::string NetconEthernetTap::deviceName() const {
{
return _dev; return _dev;
} }
void NetconEthernetTap::setFriendlyName(const char *friendlyName) void NetconEthernetTap::setFriendlyName(const char *friendlyName) {
{
} }
void NetconEthernetTap::scanMulticastGroups(std::vector<MulticastGroup> &added,std::vector<MulticastGroup> &removed) void NetconEthernetTap::scanMulticastGroups(std::vector<MulticastGroup> &added,std::vector<MulticastGroup> &removed)
@ -361,7 +359,7 @@ void NetconEthernetTap::closeConnection(TcpConnection *conn)
//lwipstack->_tcp_poll(conn->pcb, NULL, 0); //lwipstack->_tcp_poll(conn->pcb, NULL, 0);
//lwipstack->_tcp_arg(conn->pcb, NULL); //lwipstack->_tcp_arg(conn->pcb, NULL);
if(lwipstack->_tcp_close(conn->pcb) != ERR_OK) { if(lwipstack->_tcp_close(conn->pcb) != ERR_OK) {
dwr(3, " closeConnection(): Error while calling tcp_close()\n"); dwr(MSG_ERROR, " closeConnection(): Error while calling tcp_close()\n");
exit(0); exit(0);
} }
else { else {
@ -631,7 +629,6 @@ void NetconEthernetTap::phyOnUnixData(PhySocket *sock,void **uptr,void *data,uns
default: default:
break; break;
} }
//memset(data, '\0', 256);
} }
/* /*
@ -714,7 +711,7 @@ int NetconEthernetTap::send_return_value(int fd, int retval, int _errno = 0)
*/ */
err_t NetconEthernetTap::nc_accept(void *arg, struct tcp_pcb *newpcb, err_t err) err_t NetconEthernetTap::nc_accept(void *arg, struct tcp_pcb *newpcb, err_t err)
{ {
dwr(MSG_DEBUG, "nc_accept()\n"); dwr(MSG_DEBUG, " nc_accept()\n");
Larg *l = (Larg*)arg; Larg *l = (Larg*)arg;
TcpConnection *conn = l->conn; TcpConnection *conn = l->conn;
NetconEthernetTap *tap = l->tap; NetconEthernetTap *tap = l->tap;
@ -725,7 +722,7 @@ err_t NetconEthernetTap::nc_accept(void *arg, struct tcp_pcb *newpcb, err_t err)
if(socketpair(PF_LOCAL, SOCK_STREAM, 0, fds) < 0) { if(socketpair(PF_LOCAL, SOCK_STREAM, 0, fds) < 0) {
if(errno < 0) { if(errno < 0) {
l->tap->send_return_value(conn, -1, errno); l->tap->send_return_value(conn, -1, errno);
dwr(MSG_ERROR, "nc_accept(): unable to create socketpair\n"); dwr(MSG_ERROR, " nc_accept(): unable to create socketpair\n");
return ERR_MEM; return ERR_MEM;
} }
} }
@ -735,7 +732,7 @@ err_t NetconEthernetTap::nc_accept(void *arg, struct tcp_pcb *newpcb, err_t err)
new_tcp_conn->pcb = newpcb; new_tcp_conn->pcb = newpcb;
new_tcp_conn->their_fd = fds[1]; new_tcp_conn->their_fd = fds[1];
tap->tcp_connections.push_back(new_tcp_conn); tap->tcp_connections.push_back(new_tcp_conn);
dwr(MSG_DEBUG, "socketpair = {%d, %d}\n", fds[0], fds[1]); dwr(MSG_DEBUG, " nc_accept(): socketpair = {%d, %d}\n", fds[0], fds[1]);
int n, send_fd = tap->_phy.getDescriptor(conn->rpcSock); int n, send_fd = tap->_phy.getDescriptor(conn->rpcSock);
if((n = send(listening_fd, "z", 1, MSG_NOSIGNAL)) < 0) { if((n = send(listening_fd, "z", 1, MSG_NOSIGNAL)) < 0) {
dwr(MSG_ERROR, " nc_accept(): Error: [send(listening_fd,...) = MSG_NOSIGNAL].\n"); dwr(MSG_ERROR, " nc_accept(): Error: [send(listening_fd,...) = MSG_NOSIGNAL].\n");
@ -747,11 +744,11 @@ err_t NetconEthernetTap::nc_accept(void *arg, struct tcp_pcb *newpcb, err_t err)
new_tcp_conn->pending = true; new_tcp_conn->pending = true;
} }
else { else {
dwr(MSG_ERROR, "nc_accept(%d): unable to send fd to client\n", listening_fd); dwr(MSG_ERROR, " nc_accept(%d): unable to send fd to client\n", listening_fd);
} }
} }
else { else {
dwr(MSG_ERROR, "nc_accept(%d): error writing signal byte (send_fd = %d, perceived_fd = %d)\n", listening_fd, send_fd, fds[1]); dwr(MSG_ERROR, " nc_accept(%d): error writing signal byte (send_fd = %d, perceived_fd = %d)\n", listening_fd, send_fd, fds[1]);
return -1; return -1;
} }
tap->lwipstack->_tcp_arg(newpcb, new Larg(tap, new_tcp_conn)); tap->lwipstack->_tcp_arg(newpcb, new Larg(tap, new_tcp_conn));
@ -763,7 +760,7 @@ err_t NetconEthernetTap::nc_accept(void *arg, struct tcp_pcb *newpcb, err_t err)
return ERR_OK; return ERR_OK;
} }
else { else {
dwr(MSG_ERROR, "nc_accept(%d): can't locate Connection object for PCB.\n", listening_fd); dwr(MSG_ERROR, " nc_accept(%d): can't locate Connection object for PCB.\n", listening_fd);
} }
return -1; return -1;
} }
@ -985,8 +982,6 @@ void NetconEthernetTap::unload_rpc(void *data, pid_t &pid, pid_t &tid, int &rpc_
memcpy(&rpc_count, &buf[IDX_COUNT], sizeof(int)); memcpy(&rpc_count, &buf[IDX_COUNT], sizeof(int));
memcpy(timestamp, &buf[IDX_TIME], 20); memcpy(timestamp, &buf[IDX_TIME], 20);
memcpy(&cmd, &buf[IDX_PAYLOAD], sizeof(char)); memcpy(&cmd, &buf[IDX_PAYLOAD], sizeof(char));
payload = buf+IDX_PAYLOAD+1;
//dwr("RX: (pid=%d, tid=%d, rpc_count=%d, timestamp=%s, cmd=%d\n", pid, tid, rpc_count, timestamp, cmd);
} }
/* /*

Binary file not shown.

View File

@ -27,7 +27,7 @@
SHCC=gcc SHCC=gcc
intercept_CFLAGS = -c -fPIC -g -O2 -Wall -std=c99 -DERRORS_ARE_FATAL -DDEBUG_RPC -DVERBOSE -DCHECKS -D_GNU_SOURCE -DNETCON_INTERCEPT intercept_CFLAGS = -c -fPIC -g -O2 -Wall -std=c99 -DERRORS_ARE_FATAL -DDEBUG_RPC -DCHECKS -D_GNU_SOURCE -DNETCON_INTERCEPT
LIB_NAME = intercept LIB_NAME = intercept
SHLIB_EXT=dylib SHLIB_EXT=dylib
SHLIB_MAJOR = 1 SHLIB_MAJOR = 1