Skip to content

Commit

Permalink
Reset connections properly
Browse files Browse the repository at this point in the history
  • Loading branch information
madeye committed Jan 31, 2020
1 parent 71cb51a commit 9b09e35
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions tun2socks/SocksUdpGwClient.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ static void dgram_handler_received (SocksUdpGwClient_connection *o, uint8_t *dat
static int conaddr_comparator (void *unused, SocksUdpGwClient_conaddr *v1, SocksUdpGwClient_conaddr *v2);
static SocksUdpGwClient_connection * find_connection (SocksUdpGwClient *o, SocksUdpGwClient_conaddr conaddr);
static SocksUdpGwClient_connection * reuse_connection (SocksUdpGwClient *o, SocksUdpGwClient_conaddr conaddr, int is_dns);
static void reset_connection (SocksUdpGwClient *o, SocksUdpGwClient_connection *con, SocksUdpGwClient_conaddr conaddr, int is_dns);
static int connection_send (SocksUdpGwClient_connection *o, const uint8_t *data, int data_len);
static void connection_first_job_handler (SocksUdpGwClient_connection *con);
static SocksUdpGwClient_connection *connection_init (SocksUdpGwClient *client, SocksUdpGwClient_conaddr conaddr, const uint8_t *data, int data_len, int is_dns);
Expand Down Expand Up @@ -175,6 +176,14 @@ static SocksUdpGwClient_connection * reuse_connection (SocksUdpGwClient *o, Sock
// remove from connections tree by conaddr
BAVL_Remove(&o->connections_tree, &con->connections_tree_node);

// insert to connections tree by conaddr
ASSERT_EXECUTE(BAVL_Insert(&o->connections_tree, &con->connections_tree_node, NULL))

return con;
}

static void reset_connection (SocksUdpGwClient *o, SocksUdpGwClient_connection *con, SocksUdpGwClient_conaddr conaddr, int is_dns)
{
// set new conaddr
con->conaddr = conaddr;
con->is_dns = is_dns;
Expand All @@ -192,10 +201,7 @@ static SocksUdpGwClient_connection * reuse_connection (SocksUdpGwClient *o, Sock
BDatagram_SetSendAddrs(&con->udp_dgram, o->socks_server_addr, ipaddr);
}

// insert to connections tree by conaddr
ASSERT_EXECUTE(BAVL_Insert(&o->connections_tree, &con->connections_tree_node, NULL))

return con;
return;
}

static int connection_send (SocksUdpGwClient_connection *o, const uint8_t *data, int data_len)
Expand Down Expand Up @@ -624,8 +630,8 @@ void SocksUdpGwClient_SubmitPacket (SocksUdpGwClient *o, BAddr local_addr, BAddr
// create new connection
con = connection_init(o, conaddr, data, data_len, is_dns);
} else {
// reset remote addr
con->conaddr.remote_addr = remote_addr;
// reset the connection
reset_connection(o, con, conaddr, is_dns);

// remove connection from list
LinkedList1_Remove(&o->connections_list, &con->connections_list_node);
Expand Down

0 comments on commit 9b09e35

Please sign in to comment.