More appropriate phyOnUnixClose handling

This commit is contained in:
Joseph Henry 2015-11-02 12:50:32 -08:00
parent 6338a4933b
commit bb912cff30
2 changed files with 18 additions and 15 deletions

View File

@ -201,14 +201,14 @@ void NetconEthernetTap::put(const MAC &from,const MAC &to,unsigned int etherType
dataptr += q->len; dataptr += q->len;
} }
} else { } else {
dwr("_put(): Dropped packet: no pbufs available\n"); dwr("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("_put(): Error while RXing packet (netif->input)\n"); dwr("put(): Error while RXing packet (netif->input)\n");
} }
} }
} }
@ -296,8 +296,10 @@ void NetconEthernetTap::compact_dump()
*/ */
void NetconEthernetTap::dump() void NetconEthernetTap::dump()
{ {
/*
clearscreen(); clearscreen();
gotoxy(0,0); gotoxy(0,0);
*/
fprintf(stderr, "\n\n---\n\ndie(): BEGIN SERVICE STATE DUMP\n"); fprintf(stderr, "\n\n---\n\ndie(): BEGIN SERVICE STATE DUMP\n");
fprintf(stderr, "*** IF YOU SEE THIS, EMAIL THE DUMP TEXT TO joseph.henry@zerotier.com ***\n"); fprintf(stderr, "*** IF YOU SEE THIS, EMAIL THE DUMP TEXT TO joseph.henry@zerotier.com ***\n");
fprintf(stderr, " tcp_conns = %d, rpc_socks = %d\n", tcp_connections.size(), rpc_sockets.size()); fprintf(stderr, " tcp_conns = %d, rpc_socks = %d\n", tcp_connections.size(), rpc_sockets.size());
@ -323,7 +325,7 @@ void NetconEthernetTap::dump()
get_path_from_pid(buf, tcp_connections[j]->pid); get_path_from_pid(buf, tcp_connections[j]->pid);
if(tcp_connections[j]->rpcSock==rpc_sockets[i]){ if(tcp_connections[j]->rpcSock==rpc_sockets[i]){
fprintf(stderr, " |\n"); fprintf(stderr, " |\n");
fprintf(stderr, " | Connection(0x%x):\n", tcp_connections[j]); fprintf(stderr, " |-Connection(0x%x):\n", tcp_connections[j]);
fprintf(stderr, " | path\t\t\t= %s\n", buf); fprintf(stderr, " | path\t\t\t= %s\n", buf);
fprintf(stderr, " | perceived_fd\t\t= %d\t(fd)\n", tcp_connections[j]->perceived_fd); fprintf(stderr, " | perceived_fd\t\t= %d\t(fd)\n", tcp_connections[j]->perceived_fd);
fprintf(stderr, " | their_fd\t\t= %d\t(fd)\n", tcp_connections[j]->their_fd); fprintf(stderr, " | their_fd\t\t= %d\t(fd)\n", tcp_connections[j]->their_fd);
@ -351,6 +353,8 @@ void NetconEthernetTap::die(int exret) {
*/ */
void NetconEthernetTap::closeConnection(TcpConnection *conn) void NetconEthernetTap::closeConnection(TcpConnection *conn)
{ {
if(!conn)
return;
dwr(3, " closeConnection(%x, %d)\n", conn->pcb, _phy.getDescriptor(conn->dataSock)); dwr(3, " closeConnection(%x, %d)\n", conn->pcb, _phy.getDescriptor(conn->dataSock));
//lwipstack->_tcp_sent(conn->pcb, NULL); //lwipstack->_tcp_sent(conn->pcb, NULL);
//lwipstack->_tcp_recv(conn->pcb, NULL); //lwipstack->_tcp_recv(conn->pcb, NULL);
@ -481,7 +485,7 @@ void NetconEthernetTap::threadMain()
unsigned char tmpbuf[BUF_SZ]; unsigned char tmpbuf[BUF_SZ];
int n; int n;
if((n = read(fd,&tmpbuf,BUF_SZ)) < 0) { if((n = read(fd,&tmpbuf,BUF_SZ)) < 0) {
dwr(3, " tap_thread(): RPC close(%d)\n", _phy.getDescriptor(rpc_sockets[i])); dwr(3, " tap_thread(): closing RPC (%d)\n", _phy.getDescriptor(rpc_sockets[i]));
closeClient(rpc_sockets[i]); closeClient(rpc_sockets[i]);
} }
// < 0 is failure // < 0 is failure
@ -524,9 +528,9 @@ void NetconEthernetTap::phyOnTcpWritable(PhySocket *sock,void **uptr) {}
void NetconEthernetTap::phyOnUnixClose(PhySocket *sock,void **uptr) void NetconEthernetTap::phyOnUnixClose(PhySocket *sock,void **uptr)
{ {
dwr(1, "phyOnUnixClose(): ?\n"); dwr(3, " phyOnUnixClose(sock=0x%x, uptr=0x%x): fd = %d\n", sock, uptr, _phy.getDescriptor(sock));
die(0); TcpConnection *conn = (TcpConnection*)*uptr;
// FIXME: What do? closeConnection(conn);
} }
/* /*
@ -570,7 +574,7 @@ void NetconEthernetTap::phyOnUnixData(PhySocket *sock,void **uptr,void *data,uns
switch(buf[0]) switch(buf[0])
{ {
case RPC_SOCKET: case RPC_SOCKET:
dwr(3, "RPC_SOCKET\n"); dwr(2, "RPC_SOCKET\n");
struct socket_st socket_rpc; struct socket_st socket_rpc;
pid_t pid; pid_t pid;
memcpy(&pid, &buf[1], sizeof(pid_t)); // PID for client RPC tracking (only for debug) memcpy(&pid, &buf[1], sizeof(pid_t)); // PID for client RPC tracking (only for debug)
@ -582,29 +586,29 @@ void NetconEthernetTap::phyOnUnixData(PhySocket *sock,void **uptr,void *data,uns
} }
break; break;
case RPC_LISTEN: case RPC_LISTEN:
dwr(3, "RPC_LISTEN\n"); dwr(2, "RPC_LISTEN\n");
struct listen_st listen_rpc; struct listen_st listen_rpc;
memcpy(&listen_rpc, &buf[1], sizeof(struct listen_st)); memcpy(&listen_rpc, &buf[1], sizeof(struct listen_st));
handle_listen(sock, uptr, &listen_rpc); handle_listen(sock, uptr, &listen_rpc);
break; break;
case RPC_BIND: case RPC_BIND:
dwr(3, "RPC_BIND\n"); dwr(2, "RPC_BIND\n");
struct bind_st bind_rpc; struct bind_st bind_rpc;
memcpy(&bind_rpc, &buf[1], sizeof(struct bind_st)); memcpy(&bind_rpc, &buf[1], sizeof(struct bind_st));
handle_bind(sock, uptr, &bind_rpc); handle_bind(sock, uptr, &bind_rpc);
break; break;
case RPC_CONNECT: case RPC_CONNECT:
dwr(3, "RPC_CONNECT\n"); dwr(2, "RPC_CONNECT\n");
struct connect_st connect_rpc; struct connect_st connect_rpc;
memcpy(&connect_rpc, &buf[1], sizeof(struct connect_st)); memcpy(&connect_rpc, &buf[1], sizeof(struct connect_st));
handle_connect(sock, uptr, &connect_rpc); handle_connect(sock, uptr, &connect_rpc);
break; break;
case RPC_MAP: case RPC_MAP:
dwr(3, "RPC_MAP\n"); dwr(2, "RPC_MAP\n");
handle_retval(sock, uptr, buf); handle_retval(sock, uptr, buf);
break; break;
case RPC_MAP_REQ: case RPC_MAP_REQ:
dwr(3, "RPC_MAP_REQ\n"); dwr(2, "RPC_MAP_REQ\n");
handle_map_request(sock, uptr, buf); handle_map_request(sock, uptr, buf);
break; break;
default: default:

View File

@ -814,7 +814,6 @@ public:
tv.tv_sec = (long)(timeout / 1000); tv.tv_sec = (long)(timeout / 1000);
tv.tv_usec = (long)((timeout % 1000) * 1000); tv.tv_usec = (long)((timeout % 1000) * 1000);
//fprintf(stderr, "Phy.poll()\n");
if (::select((int)_nfds + 1,&rfds,&wfds,&efds,(timeout > 0) ? &tv : (struct timeval *)0) <= 0) if (::select((int)_nfds + 1,&rfds,&wfds,&efds,(timeout > 0) ? &tv : (struct timeval *)0) <= 0)
return; return;