diff options
author | Joseph Henry <joseph.henry@zerotier.com> | 2015-09-10 20:34:48 -0400 |
---|---|---|
committer | Joseph Henry <joseph.henry@zerotier.com> | 2015-09-10 20:34:48 -0400 |
commit | cc4a2bb0c31e37cca79b7e31f3edd70227c4fd18 (patch) | |
tree | 007e6c66a57faf8d7ca08d9b6dc086bb59edcfc4 | |
parent | e4dc46741f7fee7b255d484a6493dbfd27c3abbf (diff) | |
download | infinitytier-cc4a2bb0c31e37cca79b7e31f3edd70227c4fd18.tar.gz infinitytier-cc4a2bb0c31e37cca79b7e31f3edd70227c4fd18.zip |
filled out hendlers
-rw-r--r-- | make-linux.mk | 2 | ||||
-rw-r--r-- | netcon/NetconEthernetTap.cpp | 122 | ||||
-rw-r--r-- | netcon/NetconEthernetTap.hpp | 9 | ||||
-rw-r--r-- | netcon/NetconService.hpp | 5 |
4 files changed, 58 insertions, 80 deletions
diff --git a/make-linux.mk b/make-linux.mk index e30f210c..06991c46 100644 --- a/make-linux.mk +++ b/make-linux.mk @@ -85,7 +85,7 @@ else CFLAGS+=-Wall -fPIE -fvisibility=hidden -pthread $(INCLUDES) -DNDEBUG $(DEFS) CXXFLAGS?=-O3 -fstack-protector CXXFLAGS+=-Wall -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 endif diff --git a/netcon/NetconEthernetTap.cpp b/netcon/NetconEthernetTap.cpp index b0050580..959bb1dd 100644 --- a/netcon/NetconEthernetTap.cpp +++ b/netcon/NetconEthernetTap.cpp @@ -220,14 +220,11 @@ void NetconEthernetTap::threadMain() unsigned long curr_time; unsigned long since_tcp; unsigned long since_etharp; - struct timeval tv; - //struct timeval tv_sel; while (_run) { gettimeofday(&tv, NULL); curr_time = (unsigned long)(tv.tv_sec) * 1000 + (unsigned long)(tv.tv_usec) / 1000; - since_tcp = curr_time - prev_tcp_time; since_etharp = curr_time - prev_etharp_time; int min_time = min(since_tcp, since_etharp) * 1000; // usec @@ -237,16 +234,11 @@ void NetconEthernetTap::threadMain() prev_tcp_time = curr_time+1; lwipstack->tcp_tmr(); } - if(since_etharp > etharp_time) { prev_etharp_time = curr_time; lwipstack->etharp_tmr(); } - // should be set every time since tv_sel is modified after each select() call - //tv_sel.tv_sec = 0; - //tv_sel.tv_usec = min_time; - _phy.poll(min_time * 1000); // conversion from usec to millisec, TODO: double check } @@ -256,12 +248,24 @@ void NetconEthernetTap::threadMain() void NetconEthernetTap::phyOnSocketPairEndpointClose(PhySocket *sock, void **uptr) { - + NetconClient *client = (NetconClient*)*uptr; + client->closeConnection(sock); } + void NetconEthernetTap::phyOnSocketPairEndpointData(PhySocket *sock, void **uptr, void *buf, unsigned long n) { - + int r; + NetconConnection *c = ((NetconClient*)*uptr)->getConnection(sock); + if(c) { + if(c->idx < DEFAULT_READ_BUFFER_SIZE) { + if((r = read(_phy.getDescriptor(c->sock), (&c->buf)+c->idx, DEFAULT_READ_BUFFER_SIZE-(c->idx))) > 0) { + c->idx += r; + handle_write(c); + } + } + } } + void NetconEthernetTap::phyOnSocketPairEndpointWritable(PhySocket *sock, void **uptr) { @@ -290,60 +294,41 @@ void NetconEthernetTap::phyOnUnixClose(PhySocket *sock,void **uptr) void NetconEthernetTap::phyOnUnixData(PhySocket *sock,void **uptr,void *data,unsigned long len) { unsigned char *buf = (unsigned char*)data; - - NetconConnection *c = ((NetconClient*)*uptr)->getConnection(sock); - int r; - if(c->type == BUFFER) { - if(c) { - if(c->idx < DEFAULT_READ_BUFFER_SIZE) { - if((r = read(_phy.getDescriptor(c->sock), (&c->buf)+c->idx, DEFAULT_READ_BUFFER_SIZE-(c->idx))) > 0) { - c->idx += r; - handle_write(c); - } - } - } - else { - // can't find connection for this fd - } - } - if(c->type == RPC) + NetconClient *client = (NetconClient*)*uptr; + switch(buf[0]) { - NetconClient *client = (NetconClient*)*uptr; - switch(buf[0]) - { - case RPC_SOCKET: - struct socket_st socket_rpc; - memcpy(&socket_rpc, &buf[1], sizeof(struct socket_st)); - client->tid = socket_rpc.__tid; - handle_socket(client, &socket_rpc); - break; - case RPC_LISTEN: - struct listen_st listen_rpc; - memcpy(&listen_rpc, &buf[1], sizeof(struct listen_st)); - client->tid = listen_rpc.__tid; - handle_listen(client, &listen_rpc); - break; - case RPC_BIND: - struct bind_st bind_rpc; - memcpy(&bind_rpc, &buf[1], sizeof(struct bind_st)); - client->tid = bind_rpc.__tid; - handle_bind(client, &bind_rpc); - break; - case RPC_KILL_INTERCEPT: - client->closeClient(); - break; - case RPC_CONNECT: - struct connect_st connect_rpc; - memcpy(&connect_rpc, &buf[1], sizeof(struct connect_st)); - client->tid = connect_rpc.__tid; - handle_connect(client, &connect_rpc); - break; - case RPC_FD_MAP_COMPLETION: - handle_retval(client, buf); - break; - default: - break; - } + case RPC_SOCKET: + struct socket_st socket_rpc; + memcpy(&socket_rpc, &buf[1], sizeof(struct socket_st)); + client->tid = socket_rpc.__tid; + handle_socket(client, &socket_rpc); + break; + case RPC_LISTEN: + struct listen_st listen_rpc; + memcpy(&listen_rpc, &buf[1], sizeof(struct listen_st)); + client->tid = listen_rpc.__tid; + handle_listen(client, &listen_rpc); + break; + case RPC_BIND: + struct bind_st bind_rpc; + memcpy(&bind_rpc, &buf[1], sizeof(struct bind_st)); + client->tid = bind_rpc.__tid; + handle_bind(client, &bind_rpc); + break; + case RPC_KILL_INTERCEPT: + client->closeClient(); + break; + case RPC_CONNECT: + struct connect_st connect_rpc; + memcpy(&connect_rpc, &buf[1], sizeof(struct connect_st)); + client->tid = connect_rpc.__tid; + handle_connect(client, &connect_rpc); + break; + case RPC_FD_MAP_COMPLETION: + handle_retval(client, buf); + break; + default: + break; } } @@ -403,20 +388,13 @@ err_t NetconEthernetTap::nc_recved(void *arg, struct tcp_pcb *tpcb, struct pbuf struct pbuf* q = p; int our_fd = tap->_phy.getDescriptor(c->sock); - if(c) { - //dwr(c->owner->tid, "nc_recved(%d)\n", (intptr_t)arg); - } - else { - //dwr(-1, "nc_recved(%d): unable to locate connection\n", (intptr_t)arg); + if(!c) { return ERR_OK; // ? } if(p == NULL) { - //dwr(c->owner->tid, "nc_recved()\n"); if(c) { - //dwr(c->owner->tid, "closing connection\n"); nc_close(tpcb); - close(our_fd); /* TODO: Check logic */ - //nc_service->remove_connection(c); + close(our_fd); // TODO: Check logic c->owner->closeConnection(c); } else { diff --git a/netcon/NetconEthernetTap.hpp b/netcon/NetconEthernetTap.hpp index 86fa14e3..b93ad9c6 100644 --- a/netcon/NetconEthernetTap.hpp +++ b/netcon/NetconEthernetTap.hpp @@ -86,6 +86,7 @@ public: private: + // LWIP callbacks static err_t nc_poll(void* arg, struct tcp_pcb *tpcb); static err_t nc_accept(void *arg, struct tcp_pcb *newpcb, err_t err); static err_t nc_recved(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err); @@ -132,21 +133,15 @@ private: return conn_addr; } - - - void (*_handler)(void *,uint64_t,const MAC &,const MAC &,unsigned int,unsigned int,const void *,unsigned int); void *_arg; - // client helpers - + // Client helpers NetconConnection *getConnectionByThisFD(int fd); NetconConnection *getConnectionByPCB(struct tcp_pcb *pcb); NetconClient *getClientByPCB(struct tcp_pcb *pcb); void closeClient(NetconClient *client); - // Logging helper - Phy<NetconEthernetTap *> _phy; PhySocket *_unixListenSocket; diff --git a/netcon/NetconService.hpp b/netcon/NetconService.hpp index 93431f75..aae76b70 100644 --- a/netcon/NetconService.hpp +++ b/netcon/NetconService.hpp @@ -136,6 +136,11 @@ namespace ZeroTier { // -- PhySocket } + void closeConnection(PhySocket *sock) + { + + } + void closeClient() { |