summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--make-linux.mk2
-rw-r--r--netcon/NetconEthernetTap.cpp21
-rw-r--r--netcon/NetconEthernetTap.hpp4
-rw-r--r--netcon/NetconService.hpp13
4 files changed, 22 insertions, 18 deletions
diff --git a/make-linux.mk b/make-linux.mk
index 06991c46..260bf1e4 100644
--- a/make-linux.mk
+++ b/make-linux.mk
@@ -84,7 +84,7 @@ else
CFLAGS?=-O3 -fstack-protector
CFLAGS+=-Wall -fPIE -fvisibility=hidden -pthread $(INCLUDES) -DNDEBUG $(DEFS)
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
STRIP=strip --strip-all
endif
diff --git a/netcon/NetconEthernetTap.cpp b/netcon/NetconEthernetTap.cpp
index 959bb1dd..0bcbf0a3 100644
--- a/netcon/NetconEthernetTap.cpp
+++ b/netcon/NetconEthernetTap.cpp
@@ -31,7 +31,6 @@
#include <utility>
#include <dlfcn.h>
-
#include "NetconEthernetTap.hpp"
#include "../node/Utils.hpp"
@@ -200,6 +199,14 @@ void NetconEthernetTap::closeClient(NetconClient *client)
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()
throw()
@@ -239,9 +246,8 @@ void NetconEthernetTap::threadMain()
prev_etharp_time = curr_time;
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.
}
@@ -249,7 +255,7 @@ void NetconEthernetTap::threadMain()
void NetconEthernetTap::phyOnSocketPairEndpointClose(PhySocket *sock, void **uptr)
{
NetconClient *client = (NetconClient*)*uptr;
- client->closeConnection(sock);
+ closeConnection(client->getConnection(sock));
}
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)
{
-
+ //_phy.setNotifyWritable(sock, false);
}
// 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) {
nc_close(tpcb);
close(our_fd); // TODO: Check logic
- c->owner->closeConnection(c);
+ tap->closeConnection(c);
}
else {
// 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 < p->len) {
// ERROR: unable to write entire pbuf to buffer
+ //tap->_phy.setNotifyWritable(l->sock, true);
}
tap->lwipstack->tcp_recved(tpcb, n);
}
@@ -427,7 +434,7 @@ void NetconEthernetTap::nc_err(void *arg, err_t err)
NetconEthernetTap *tap = l->tap;
NetconConnection *c = tap->getConnectionByThisFD(tap->_phy.getDescriptor(l->sock));
if(c) {
- c->owner->closeConnection(c);
+ l->tap->closeConnection(c);
//tcp_close(c->pcb);
}
else {
diff --git a/netcon/NetconEthernetTap.hpp b/netcon/NetconEthernetTap.hpp
index b93ad9c6..6e0451ff 100644
--- a/netcon/NetconEthernetTap.hpp
+++ b/netcon/NetconEthernetTap.hpp
@@ -84,6 +84,8 @@ public:
void threadMain()
throw();
+ LWIPStack *lwipstack;
+
private:
// LWIP callbacks
@@ -141,11 +143,11 @@ private:
NetconConnection *getConnectionByPCB(struct tcp_pcb *pcb);
NetconClient *getClientByPCB(struct tcp_pcb *pcb);
void closeClient(NetconClient *client);
+ void closeConnection(NetconConnection *conn);
Phy<NetconEthernetTap *> _phy;
PhySocket *_unixListenSocket;
- LWIPStack *lwipstack;
std::vector<NetconClient*> clients;
uint64_t _nwid;
diff --git a/netcon/NetconService.hpp b/netcon/NetconService.hpp
index aae76b70..0d497ea9 100644
--- a/netcon/NetconService.hpp
+++ b/netcon/NetconService.hpp
@@ -129,16 +129,11 @@ namespace ZeroTier {
return NULL;
}
- void closeConnection(NetconConnection *c)
+ void removeConnection(PhySocket *sock)
{
- // close all connections
- // -- pcb
- // -- PhySocket
- }
-
- void closeConnection(PhySocket *sock)
- {
-
+ for(size_t i=0; i<connections.size(); i++) {
+ if(connections[i]->sock == sock) { connections.erase(connections.begin() + i); }
+ }
}
void closeClient()