mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-02-07 20:00:13 +00:00
Revised fd RX logic
This commit is contained in:
parent
f2289544b7
commit
b0f6dc43b4
@ -39,7 +39,7 @@
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
|
||||||
|
|
||||||
#define DEBUG_LEVEL 2
|
#define DEBUG_LEVEL 3
|
||||||
|
|
||||||
#define MSG_ERROR 0 // Errors
|
#define MSG_ERROR 0 // Errors
|
||||||
#define MSG_INFO 1 // Information which is generally useful to any user
|
#define MSG_INFO 1 // Information which is generally useful to any user
|
||||||
|
@ -156,7 +156,7 @@ int checkpid() {
|
|||||||
if(thispid != getpid()) {
|
if(thispid != getpid()) {
|
||||||
printf("clone/fork detected. re-initializing this instance.\n");
|
printf("clone/fork detected. re-initializing this instance.\n");
|
||||||
set_up_intercept();
|
set_up_intercept();
|
||||||
fdret_sock = init_service_connection();
|
//fdret_sock = init_service_connection();
|
||||||
thispid = getpid();
|
thispid = getpid();
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@ -226,6 +226,16 @@ int get_retval()
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Reads a new file descriptor from the service */
|
||||||
|
int get_new_fd(int oversock)
|
||||||
|
{
|
||||||
|
char buf[BUF_SZ];
|
||||||
|
int newfd;
|
||||||
|
ssize_t size = sock_fd_read(oversock, buf, sizeof(buf), &newfd);
|
||||||
|
dwr(MSG_DEBUG, "get_new_fd(): RX: fd = %d\n", newfd);
|
||||||
|
return newfd;
|
||||||
|
}
|
||||||
|
|
||||||
/* Check whether the socket is mapped to the service or not. We
|
/* Check whether the socket is mapped to the service or not. We
|
||||||
need to know if this is a regular AF_LOCAL socket or an end of a socketpair
|
need to know if this is a regular AF_LOCAL socket or an end of a socketpair
|
||||||
that the service uses. We don't want to keep state in the intercept, so
|
that the service uses. We don't want to keep state in the intercept, so
|
||||||
@ -505,9 +515,8 @@ int socket(SOCKET_SIG)
|
|||||||
|
|
||||||
/* get new fd */
|
/* get new fd */
|
||||||
char rbuf[16];
|
char rbuf[16];
|
||||||
ssize_t sz = sock_fd_read(fdret_sock, rbuf, sizeof(rbuf), &newfd);
|
newfd = get_new_fd(fdret_sock);
|
||||||
dwr(MSG_DEBUG,"read %d bytes (%s)\n", sz, &rbuf);
|
if(newfd > 0)
|
||||||
if(sz > 0)
|
|
||||||
{
|
{
|
||||||
dwr(MSG_DEBUG,"sending fd = %d to Service over (%d)\n", newfd, fdret_sock);
|
dwr(MSG_DEBUG,"sending fd = %d to Service over (%d)\n", newfd, fdret_sock);
|
||||||
/* send our local-fd number back to service so
|
/* send our local-fd number back to service so
|
||||||
@ -800,8 +809,8 @@ int accept(ACCEPT_SIG)
|
|||||||
int n = read(sockfd, c, sizeof(c)); // Read signal byte
|
int n = read(sockfd, c, sizeof(c)); // Read signal byte
|
||||||
if(n > 0)
|
if(n > 0)
|
||||||
{
|
{
|
||||||
ssize_t size = sock_fd_read(fdret_sock, rbuf, sizeof(rbuf), &new_conn_socket);
|
new_conn_socket = get_new_fd(fdret_sock);
|
||||||
if(size > 0) {
|
if(new_conn_socket > 0) {
|
||||||
/* Send our local-fd number back to service so it can complete its mapping table */
|
/* Send our local-fd number back to service so it can complete its mapping table */
|
||||||
memset(cmd, '\0', BUF_SZ);
|
memset(cmd, '\0', BUF_SZ);
|
||||||
cmd[0] = RPC_MAP;
|
cmd[0] = RPC_MAP;
|
||||||
@ -927,7 +936,7 @@ int poll(POLL_SIG)
|
|||||||
// int fd
|
// int fd
|
||||||
int close(CLOSE_SIG)
|
int close(CLOSE_SIG)
|
||||||
{
|
{
|
||||||
checkpid();
|
checkpid(); // Required for httpd-2.4.17-3.x86_64 -- After clone, some symbols aren't initialized yet
|
||||||
dwr(MSG_DEBUG,"close(%d)\n", fd);
|
dwr(MSG_DEBUG,"close(%d)\n", fd);
|
||||||
if(fd == fdret_sock)
|
if(fd == fdret_sock)
|
||||||
return 0; // FIXME: Ignore request to shut down our rpc fd, this is *almost always* safe
|
return 0; // FIXME: Ignore request to shut down our rpc fd, this is *almost always* safe
|
||||||
|
@ -50,10 +50,9 @@
|
|||||||
#include "NetconUtilities.hpp"
|
#include "NetconUtilities.hpp"
|
||||||
#include "Common.c"
|
#include "Common.c"
|
||||||
|
|
||||||
#define APPLICATION_POLL_FREQ 20
|
#define APPLICATION_POLL_FREQ 20
|
||||||
#define ZT_LWIP_TCP_TIMER_INTERVAL 5
|
#define ZT_LWIP_TCP_TIMER_INTERVAL 5
|
||||||
#define STATUS_TMR_INTERVAL 2000 // How often we check connection statuses
|
#define STATUS_TMR_INTERVAL 3000 // How often we check connection statuses
|
||||||
#define DEBUG_LEVEL 3
|
|
||||||
|
|
||||||
namespace ZeroTier {
|
namespace ZeroTier {
|
||||||
|
|
||||||
@ -151,13 +150,10 @@ bool NetconEthernetTap::removeIp(const InetAddress &ip)
|
|||||||
std::vector<InetAddress>::iterator i(std::find(_ips.begin(),_ips.end(),ip));
|
std::vector<InetAddress>::iterator i(std::find(_ips.begin(),_ips.end(),ip));
|
||||||
if (i == _ips.end())
|
if (i == _ips.end())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
_ips.erase(i);
|
_ips.erase(i);
|
||||||
|
|
||||||
if (ip.isV4()) {
|
if (ip.isV4()) {
|
||||||
// TODO: dealloc from LWIP
|
// TODO: dealloc from LWIP
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -259,11 +255,6 @@ TcpConnection *NetconEthernetTap::getConnectionByTheirFD(PhySocket *sock, int fd
|
|||||||
void NetconEthernetTap::compact_dump()
|
void NetconEthernetTap::compact_dump()
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
//
|
|
||||||
refresh();
|
|
||||||
clear();
|
|
||||||
gotoxy(0,0);
|
|
||||||
*/
|
|
||||||
clearscreen();
|
clearscreen();
|
||||||
gotoxy(0,0);
|
gotoxy(0,0);
|
||||||
|
|
||||||
@ -286,6 +277,14 @@ void NetconEthernetTap::compact_dump()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
for(size_t i=0; i<rpc_sockets.size(); i++) {
|
||||||
|
fprintf(stderr, "\n\n\nrpc(%d)\n", _phy.getDescriptor(rpc_sockets[i]));
|
||||||
|
for(size_t j=0; j<tcp_connections.size(); j++) {
|
||||||
|
if(_phy.getDescriptor(tcp_connections[j]->rpcSock) == _phy.getDescriptor(rpc_sockets[i]))
|
||||||
|
fprintf(stderr, "\t(%d) ----> (%d)\n\n", _phy.getDescriptor(tcp_connections[j]->dataSock), tcp_connections[j]->perceived_fd);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -301,7 +300,7 @@ void NetconEthernetTap::dump()
|
|||||||
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());
|
||||||
|
|
||||||
// TODO: Add logic to detect bad mapping conditions
|
// TODO: Add logic to detect bad mapping conditions
|
||||||
for(size_t i=0; i<rpc_sockets.size(); i++) {
|
for(size_t i=0; i<rpc_sockets.size(); i++) {
|
||||||
for(size_t j=0; j<rpc_sockets.size(); j++) {
|
for(size_t j=0; j<rpc_sockets.size(); j++) {
|
||||||
if(j != i && rpc_sockets[i] == rpc_sockets[j]) {
|
if(j != i && rpc_sockets[i] == rpc_sockets[j]) {
|
||||||
@ -353,10 +352,10 @@ void NetconEthernetTap::closeConnection(TcpConnection *conn)
|
|||||||
if(!conn)
|
if(!conn)
|
||||||
return;
|
return;
|
||||||
dwr(MSG_DEBUG, " closeConnection(%x, %d)\n", conn->pcb, _phy.getDescriptor(conn->dataSock));
|
dwr(MSG_DEBUG, " 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);
|
||||||
//lwipstack->_tcp_err(conn->pcb, NULL);
|
//lwipstack->_tcp_err(conn->pcb, NULL);
|
||||||
//lwipstack->_tcp_poll(conn->pcb, NULL, 0);
|
//lwipstack->_tcp_poll(conn->pcb, NULL, 0);
|
||||||
//lwipstack->_tcp_arg(conn->pcb, NULL);
|
//lwipstack->_tcp_arg(conn->pcb, NULL);
|
||||||
if(lwipstack->_tcp_close(conn->pcb) != ERR_OK) {
|
if(lwipstack->_tcp_close(conn->pcb) != ERR_OK) {
|
||||||
dwr(MSG_ERROR, " closeConnection(): Error while calling tcp_close()\n");
|
dwr(MSG_ERROR, " closeConnection(): Error while calling tcp_close()\n");
|
||||||
@ -409,7 +408,6 @@ void NetconEthernetTap::closeAll()
|
|||||||
void NetconEthernetTap::threadMain()
|
void NetconEthernetTap::threadMain()
|
||||||
throw()
|
throw()
|
||||||
{
|
{
|
||||||
//initscr();
|
|
||||||
//signal(SIGPIPE, SIG_IGN);
|
//signal(SIGPIPE, SIG_IGN);
|
||||||
uint64_t prev_tcp_time = 0;
|
uint64_t prev_tcp_time = 0;
|
||||||
uint64_t prev_status_time = 0;
|
uint64_t prev_status_time = 0;
|
||||||
@ -436,7 +434,6 @@ void NetconEthernetTap::threadMain()
|
|||||||
fprintf(stderr, "- IP_TMR_INTERVAL = %d\n", IP_TMR_INTERVAL);
|
fprintf(stderr, "- IP_TMR_INTERVAL = %d\n", IP_TMR_INTERVAL);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
// Main timer loop
|
// Main timer loop
|
||||||
while (_run) {
|
while (_run) {
|
||||||
uint64_t now = OSUtils::now();
|
uint64_t now = OSUtils::now();
|
||||||
@ -449,7 +446,7 @@ void NetconEthernetTap::threadMain()
|
|||||||
|
|
||||||
// Connection prunning
|
// Connection prunning
|
||||||
if (since_status >= STATUS_TMR_INTERVAL) {
|
if (since_status >= STATUS_TMR_INTERVAL) {
|
||||||
//compact_dump();
|
compact_dump();
|
||||||
prev_status_time = now;
|
prev_status_time = now;
|
||||||
if(rpc_sockets.size() || tcp_connections.size()) {
|
if(rpc_sockets.size() || tcp_connections.size()) {
|
||||||
|
|
||||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user