Updated getsockopt/setsockopt, removed unused code

This commit is contained in:
Joseph Henry 2016-01-13 15:52:15 -08:00
parent 7bba867ce8
commit 5e30eabd30
2 changed files with 14 additions and 30 deletions

View File

@ -88,16 +88,6 @@ static int connected_to_service(int sockfd)
return 0;
}
/*static void my_dest(void) __attribute__ ((destructor));
static void my_dest(void) {
dwr(MSG_DEBUG,"closing connections to service...\n");
rpc_mutex_destroy();
}*/
/* Private Function Prototypes */
/*static void _init(void) __attribute__ ((constructor));
static void _init(void) { set_up_intercept(); } */
/* get symbols and initialize mutexes */
static int set_up_intercept()
{
@ -137,18 +127,13 @@ int setsockopt(SETSOCKOPT_SIG)
return realsetsockopt(socket, level, option_name, option_value, option_len);
dwr(MSG_DEBUG,"setsockopt(%d)\n", socket);
/* return(realsetsockopt(socket, level, option_name, option_value, option_len)); */
if(level == SOL_IPV6 && option_name == IPV6_V6ONLY)
return 0;
if(level == SOL_IP && option_name == IP_TTL)
if(level == SOL_IP && (option_name == IP_TTL || option_name == IP_TOS))
return 0;
if(level == IPPROTO_TCP || (level == SOL_SOCKET && option_name == SO_KEEPALIVE))
return 0;
/* make sure we don't touch any standard outputs */
if(socket == STDIN_FILENO || socket == STDOUT_FILENO || socket == STDERR_FILENO)
return(realsetsockopt(socket, level, option_name, option_value, option_len));
int err = realsetsockopt(socket, level, option_name, option_value, option_len);
if(err < 0)
if(realsetsockopt(socket, level, option_name, option_value, option_len) < 0)
perror("setsockopt():\n");
return 0;
}
@ -160,13 +145,9 @@ int setsockopt(SETSOCKOPT_SIG)
/* int sockfd, int level, int optname, void *optval, socklen_t *optlen */
int getsockopt(GETSOCKOPT_SIG)
{
if (!set_up_intercept())
return realgetsockopt(sockfd, level, optname, optval, optlen);
dwr(MSG_DEBUG,"getsockopt(%d)\n", sockfd);
if(!connected_to_service(sockfd)) {
if (!set_up_intercept() || !connected_to_service(sockfd))
return realgetsockopt(sockfd, level, optname, optval, optlen);
}
if(optname == SO_TYPE) {
int* val = (int*)optval;
*val = 2;
@ -508,7 +489,7 @@ int getsockname(GETSOCKNAME_SIG)
if(rpcfd > -1)
if(read(rpcfd, &addrbuf, sizeof(struct sockaddr_storage)) > 0)
close(rpcfd);
struct sockaddr_storage sock_storage;
memcpy(&sock_storage, addrbuf, sizeof(struct sockaddr_storage));
*addrlen = sizeof(struct sockaddr_in);

View File

@ -56,8 +56,8 @@
#define APPLICATION_POLL_FREQ 2
#define ZT_LWIP_TCP_TIMER_INTERVAL 5
#define STATUS_TMR_INTERVAL 250 // How often we check connection statuses (in ms)
#define DEFAULT_READ_BUFFER_SIZE 1024 * 1024
#define STATUS_TMR_INTERVAL 1000 // How often we check connection statuses (in ms)
#define DEFAULT_READ_BUFFER_SIZE 1024 * 1024 * 2
namespace ZeroTier {
@ -360,7 +360,7 @@ void NetconEthernetTap::threadMain()
fcntl(fd, F_SETFL, O_NONBLOCK);
unsigned char tmpbuf[BUF_SZ];
int n = read(fd,&tmpbuf,BUF_SZ);
//dwr(MSG_DEBUG," tap_thread(): <%x> n = %d\n", tcp_connections[i]->sock, n);
dwr(MSG_DEBUG," tap_thread(): <%x> conn->idx = %d\n", tcp_connections[i]->sock, tcp_connections[i]->idx);
if(tcp_connections[i]->pcb->state == SYN_SENT) {
dwr(MSG_DEBUG," tap_thread(): <%x> state = SYN_SENT, candidate for removal\n", tcp_connections[i]->sock);
}
@ -460,6 +460,7 @@ void NetconEthernetTap::closeConnection(PhySocket *sock)
dwr(MSG_DEBUG," closeConnection(): invalid PCB state (SYN_SENT) -- cannot close right now\n");
return;
}
dwr(MSG_DEBUG," closeConnection(): PCB->state = %d\n", conn->pcb->state);
if(lwipstack->_tcp_close(conn->pcb) != ERR_OK) {
dwr(MSG_ERROR," closeConnection(): Error while calling tcp_close()\n");
}
@ -791,7 +792,6 @@ err_t NetconEthernetTap::nc_accept(void *arg, struct tcp_pcb *newpcb, err_t err)
*/
err_t NetconEthernetTap::nc_recved(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err)
{
dwr(MSG_DEBUG," nc_recved()\n");
Larg *l = (Larg*)arg;
int n;
struct pbuf* q = p;
@ -818,6 +818,8 @@ err_t NetconEthernetTap::nc_recved(void *arg, struct tcp_pcb *tpcb, struct pbuf
while(p != NULL) { // Cycle through pbufs and write them to the socket
if(p->len <= 0)
break;
else
dwr(MSG_DEBUG," nc_recved(): p->len = %d\n", p->len);
if((n = l->tap->_phy.streamSend(l->conn->sock,p->payload, p->len)) > 0) {
if(n < p->len) {
dwr(MSG_INFO," nc_recved(): unable to write entire pbuf to stream\n");
@ -825,8 +827,10 @@ err_t NetconEthernetTap::nc_recved(void *arg, struct tcp_pcb *tpcb, struct pbuf
l->tap->lwipstack->_tcp_recved(tpcb, n);
dwr(MSG_DEBUG," nc_recved(): wrote %d bytes to <%x>\n", n, l->conn->sock);
}
else
dwr(MSG_INFO," nc_recved(): No data written to stream <%d>\n", l->conn->sock);
else{
perror("\n");
dwr(MSG_INFO," nc_recved(): No data written to stream <%x>\n", l->conn->sock);
}
p = p->next;
}
l->tap->lwipstack->_pbuf_free(q); // free pbufs
@ -927,7 +931,6 @@ void NetconEthernetTap::nc_err(void *arg, err_t err)
*/
err_t NetconEthernetTap::nc_poll(void* arg, struct tcp_pcb *tpcb)
{
dwr(MSG_DEBUG," nc_poll()\n");
return ERR_OK;
}