small method changes

This commit is contained in:
Joseph Henry 2015-09-11 14:00:42 -04:00
parent cc4a2bb0c3
commit 5a5a513b18
4 changed files with 22 additions and 18 deletions

View File

@ -84,7 +84,7 @@ else
CFLAGS?=-O3 -fstack-protector CFLAGS?=-O3 -fstack-protector
CFLAGS+=-Wall -fPIE -fvisibility=hidden -pthread $(INCLUDES) -DNDEBUG $(DEFS) CFLAGS+=-Wall -fPIE -fvisibility=hidden -pthread $(INCLUDES) -DNDEBUG $(DEFS)
CXXFLAGS?=-O3 -fstack-protector CXXFLAGS?=-O3 -fstack-protector
CXXFLAGS+=-Wall -fPIE -fvisibility=hidden -fno-rtti -pthread $(INCLUDES) -DNDEBUG $(DEFS) CXXFLAGS+=-Wall -Wreorder -fPIE -fvisibility=hidden -fno-rtti -pthread $(INCLUDES) -DNDEBUG $(DEFS)
LDFLAGS=-ldl -pie -Wl,-z,relro,-z,now LDFLAGS=-ldl -pie -Wl,-z,relro,-z,now
STRIP=strip --strip-all STRIP=strip --strip-all
endif endif

View File

@ -31,7 +31,6 @@
#include <utility> #include <utility>
#include <dlfcn.h> #include <dlfcn.h>
#include "NetconEthernetTap.hpp" #include "NetconEthernetTap.hpp"
#include "../node/Utils.hpp" #include "../node/Utils.hpp"
@ -200,6 +199,14 @@ void NetconEthernetTap::closeClient(NetconClient *client)
client->closeClient(); client->closeClient();
} }
void NetconEthernetTap::closeConnection(NetconConnection *conn)
{
NetconClient *client = conn->owner;
_phy.close(conn->sock);
lwipstack->tcp_close(conn->pcb);
client->removeConnection(conn->sock);
}
void NetconEthernetTap::threadMain() void NetconEthernetTap::threadMain()
throw() throw()
@ -239,9 +246,8 @@ void NetconEthernetTap::threadMain()
prev_etharp_time = curr_time; prev_etharp_time = curr_time;
lwipstack->etharp_tmr(); lwipstack->etharp_tmr();
} }
_phy.poll(min_time * 1000); // conversion from usec to millisec, TODO: double check _phy.poll(min_time / 1000); // conversion from usec to millisec, TODO: double check
} }
// TODO: cleanup -- destroy LWIP state, kill any clients, unload .so, etc. // TODO: cleanup -- destroy LWIP state, kill any clients, unload .so, etc.
} }
@ -249,7 +255,7 @@ void NetconEthernetTap::threadMain()
void NetconEthernetTap::phyOnSocketPairEndpointClose(PhySocket *sock, void **uptr) void NetconEthernetTap::phyOnSocketPairEndpointClose(PhySocket *sock, void **uptr)
{ {
NetconClient *client = (NetconClient*)*uptr; NetconClient *client = (NetconClient*)*uptr;
client->closeConnection(sock); closeConnection(client->getConnection(sock));
} }
void NetconEthernetTap::phyOnSocketPairEndpointData(PhySocket *sock, void **uptr, void *buf, unsigned long n) void NetconEthernetTap::phyOnSocketPairEndpointData(PhySocket *sock, void **uptr, void *buf, unsigned long n)
@ -268,7 +274,7 @@ void NetconEthernetTap::phyOnSocketPairEndpointData(PhySocket *sock, void **uptr
void NetconEthernetTap::phyOnSocketPairEndpointWritable(PhySocket *sock, void **uptr) void NetconEthernetTap::phyOnSocketPairEndpointWritable(PhySocket *sock, void **uptr)
{ {
//_phy.setNotifyWritable(sock, false);
} }
// Unused -- no UDP or TCP from this thread/Phy<> // Unused -- no UDP or TCP from this thread/Phy<>
@ -395,7 +401,7 @@ err_t NetconEthernetTap::nc_recved(void *arg, struct tcp_pcb *tpcb, struct pbuf
if(c) { if(c) {
nc_close(tpcb); nc_close(tpcb);
close(our_fd); // TODO: Check logic close(our_fd); // TODO: Check logic
c->owner->closeConnection(c); tap->closeConnection(c);
} }
else { else {
// can't locate connection via (arg) // can't locate connection via (arg)
@ -409,6 +415,7 @@ err_t NetconEthernetTap::nc_recved(void *arg, struct tcp_pcb *tpcb, struct pbuf
if((n = write(our_fd, p->payload, p->len)) > 0) { if((n = write(our_fd, p->payload, p->len)) > 0) {
if(n < p->len) { if(n < p->len) {
// ERROR: unable to write entire pbuf to buffer // ERROR: unable to write entire pbuf to buffer
//tap->_phy.setNotifyWritable(l->sock, true);
} }
tap->lwipstack->tcp_recved(tpcb, n); tap->lwipstack->tcp_recved(tpcb, n);
} }
@ -427,7 +434,7 @@ void NetconEthernetTap::nc_err(void *arg, err_t err)
NetconEthernetTap *tap = l->tap; NetconEthernetTap *tap = l->tap;
NetconConnection *c = tap->getConnectionByThisFD(tap->_phy.getDescriptor(l->sock)); NetconConnection *c = tap->getConnectionByThisFD(tap->_phy.getDescriptor(l->sock));
if(c) { if(c) {
c->owner->closeConnection(c); l->tap->closeConnection(c);
//tcp_close(c->pcb); //tcp_close(c->pcb);
} }
else { else {

View File

@ -84,6 +84,8 @@ public:
void threadMain() void threadMain()
throw(); throw();
LWIPStack *lwipstack;
private: private:
// LWIP callbacks // LWIP callbacks
@ -141,11 +143,11 @@ private:
NetconConnection *getConnectionByPCB(struct tcp_pcb *pcb); NetconConnection *getConnectionByPCB(struct tcp_pcb *pcb);
NetconClient *getClientByPCB(struct tcp_pcb *pcb); NetconClient *getClientByPCB(struct tcp_pcb *pcb);
void closeClient(NetconClient *client); void closeClient(NetconClient *client);
void closeConnection(NetconConnection *conn);
Phy<NetconEthernetTap *> _phy; Phy<NetconEthernetTap *> _phy;
PhySocket *_unixListenSocket; PhySocket *_unixListenSocket;
LWIPStack *lwipstack;
std::vector<NetconClient*> clients; std::vector<NetconClient*> clients;
uint64_t _nwid; uint64_t _nwid;

View File

@ -129,16 +129,11 @@ namespace ZeroTier {
return NULL; return NULL;
} }
void closeConnection(NetconConnection *c) void removeConnection(PhySocket *sock)
{ {
// close all connections for(size_t i=0; i<connections.size(); i++) {
// -- pcb if(connections[i]->sock == sock) { connections.erase(connections.begin() + i); }
// -- PhySocket }
}
void closeConnection(PhySocket *sock)
{
} }
void closeClient() void closeClient()