summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Henry <joseph.henry@zerotier.com>2015-09-24 17:33:25 -0400
committerJoseph Henry <joseph.henry@zerotier.com>2015-09-24 17:33:25 -0400
commit8a8264bc39b97bcce07933c0a5c3158208efcd6c (patch)
tree1023884026caabe3cac822b96b77b90133af21d5
parent1119f64a77a39619c8632ca1f6cbf3811edefa55 (diff)
downloadinfinitytier-8a8264bc39b97bcce07933c0a5c3158208efcd6c.tar.gz
infinitytier-8a8264bc39b97bcce07933c0a5c3158208efcd6c.zip
Fixed their_fd closure bug
-rw-r--r--netcon/NetconEthernetTap.cpp10
-rw-r--r--netcon/NetconService.hpp11
2 files changed, 8 insertions, 13 deletions
diff --git a/netcon/NetconEthernetTap.cpp b/netcon/NetconEthernetTap.cpp
index 460dedcb..da8c0c67 100644
--- a/netcon/NetconEthernetTap.cpp
+++ b/netcon/NetconEthernetTap.cpp
@@ -302,9 +302,9 @@ void NetconEthernetTap::closeConnection(NetconConnection *conn)
lwipstack->_tcp_err(conn->pcb, NULL);
lwipstack->_tcp_poll(conn->pcb, NULL, 0);
close(_phy.getDescriptor(conn->sock));
+ close(conn->their_fd);
_phy.close(conn->sock);
lwipstack->_tcp_close(conn->pcb);
- client->removeConnection(conn->sock);
delete conn;
}
@@ -564,6 +564,7 @@ err_t NetconEthernetTap::nc_accept(void *arg, struct tcp_pcb *newpcb, err_t err)
NetconConnection *new_conn = client->addConnection(BUFFER, tap->_phy.wrapSocket(fds[0], client));
client->connections.push_back(new_conn);
new_conn->pcb = newpcb;
+ new_conn->their_fd = fds[1];
int send_fd = tap->_phy.getDescriptor(client->rpc->sock);
int n = write(larg_fd, "z", 1);
if(n > 0) {
@@ -577,7 +578,7 @@ err_t NetconEthernetTap::nc_accept(void *arg, struct tcp_pcb *newpcb, err_t err)
}
}
else {
- fprintf(stderr, "nc_accept(%d): error writing signal byte (send_fd = %d, their_fd = %d)\n", larg_fd, send_fd, fds[1]);
+ fprintf(stderr, "nc_accept(%d): error writing signal byte (send_fd = %d, perceived_fd = %d)\n", larg_fd, send_fd, fds[1]);
return -1;
}
tap->lwipstack->_tcp_arg(newpcb, new Larg(tap, new_conn->sock));
@@ -797,8 +798,8 @@ void NetconEthernetTap::handle_listen(NetconClient *client, struct listen_st *li
void NetconEthernetTap::handle_retval(NetconClient *client, unsigned char* buf)
{
if(client->unmapped_conn != NULL) {
- memcpy(&(client->unmapped_conn->their_fd), &buf[1], sizeof(int));
- fprintf(stderr, "handle_retval(): Mapping [our=%d -> their=%d]\n", _phy.getDescriptor(client->unmapped_conn->sock), client->unmapped_conn->their_fd);
+ memcpy(&(client->unmapped_conn->perceived_fd), &buf[1], sizeof(int));
+ fprintf(stderr, "handle_retval(): Mapping [our=%d -> their=%d]\n", _phy.getDescriptor(client->unmapped_conn->sock), client->unmapped_conn->perceived_fd);
client->connections.push_back(client->unmapped_conn);
client->unmapped_conn = NULL;
}
@@ -824,6 +825,7 @@ void NetconEthernetTap::handle_socket(NetconClient *client, struct socket_st* so
socketpair(PF_LOCAL, SOCK_STREAM, 0, fds);
NetconConnection *new_conn = client->addConnection(BUFFER, _phy.wrapSocket(fds[0], client));
new_conn->pcb = pcb;
+ new_conn->their_fd = fds[1];
PhySocket *sock = client->rpc->sock;
sock_fd_write(_phy.getDescriptor(sock), fds[1]);
fprintf(stderr, "handle_socket(): socketpair = { our=%d, their=%d}\n", fds[0], fds[1]);
diff --git a/netcon/NetconService.hpp b/netcon/NetconService.hpp
index 451d10cb..5ff575dc 100644
--- a/netcon/NetconService.hpp
+++ b/netcon/NetconService.hpp
@@ -66,6 +66,7 @@ namespace ZeroTier {
class NetconConnection
{
public:
+ int perceived_fd;
int their_fd;
unsigned char buf[DEFAULT_READ_BUFFER_SIZE];
int idx;
@@ -113,7 +114,7 @@ namespace ZeroTier {
NetconConnection *getConnectionByTheirFD(int fd)
{
for(size_t i=0; i<connections.size(); i++) {
- if(connections[i]->their_fd == fd) return connections[i];
+ if(connections[i]->perceived_fd == fd) return connections[i];
}
return NULL;
}
@@ -134,14 +135,6 @@ namespace ZeroTier {
}
return NULL;
}
-
- void removeConnection(PhySocket *sock)
- {
- for(size_t i=0; i<connections.size(); i++) {
- if(connections[i]->sock == sock)
- connections.erase(connections.begin() + i);
- }
- }
};
} // namespace ZeroTier