diff --git a/binaries/aarch64/tpws b/binaries/aarch64/tpws index 628e833..b08bef2 100755 Binary files a/binaries/aarch64/tpws and b/binaries/aarch64/tpws differ diff --git a/binaries/arm/tpws b/binaries/arm/tpws index 4d8d54f..6780b0f 100755 Binary files a/binaries/arm/tpws and b/binaries/arm/tpws differ diff --git a/binaries/freebsd-x64/tpws b/binaries/freebsd-x64/tpws index c03ea79..af4530a 100755 Binary files a/binaries/freebsd-x64/tpws and b/binaries/freebsd-x64/tpws differ diff --git a/binaries/mac64/tpws b/binaries/mac64/tpws index 68b60d6..e2e26b0 100755 Binary files a/binaries/mac64/tpws and b/binaries/mac64/tpws differ diff --git a/binaries/mips32r1-lsb/tpws b/binaries/mips32r1-lsb/tpws index 253a87c..75b5409 100755 Binary files a/binaries/mips32r1-lsb/tpws and b/binaries/mips32r1-lsb/tpws differ diff --git a/binaries/mips32r1-msb/tpws b/binaries/mips32r1-msb/tpws index be5329c..c460be5 100755 Binary files a/binaries/mips32r1-msb/tpws and b/binaries/mips32r1-msb/tpws differ diff --git a/binaries/mips64r2-msb/tpws b/binaries/mips64r2-msb/tpws index 1e6ef72..9fe09e2 100755 Binary files a/binaries/mips64r2-msb/tpws and b/binaries/mips64r2-msb/tpws differ diff --git a/binaries/ppc/tpws b/binaries/ppc/tpws index 482a9ce..62f3e7c 100755 Binary files a/binaries/ppc/tpws and b/binaries/ppc/tpws differ diff --git a/binaries/x86/tpws b/binaries/x86/tpws index e533f08..cfa0cb0 100755 Binary files a/binaries/x86/tpws and b/binaries/x86/tpws differ diff --git a/binaries/x86_64/tpws b/binaries/x86_64/tpws index a7fc684..f1238fd 100755 Binary files a/binaries/x86_64/tpws and b/binaries/x86_64/tpws differ diff --git a/binaries/x86_64/tpws_wsl.tgz b/binaries/x86_64/tpws_wsl.tgz index 002d3e1..f95ff9c 100644 Binary files a/binaries/x86_64/tpws_wsl.tgz and b/binaries/x86_64/tpws_wsl.tgz differ diff --git a/tpws/tpws_conn.c b/tpws/tpws_conn.c index 8cfc40f..0d6f822 100644 --- a/tpws/tpws_conn.c +++ b/tpws/tpws_conn.c @@ -91,25 +91,6 @@ static bool socks_send_rep_errno(uint8_t ver, int fd, int errn) { return ver==5 ? socks5_send_rep_errno(fd,errn) : socks4_send_rep_errno(fd, errn); } -static bool proxy_remote_conn_ack(tproxy_conn_t *conn, int sock_err) -{ - // if proxy mode acknowledge connection request - // conn = remote. conn->partner = local - if (!conn->remote || !conn->partner) return false; - bool bres = true; - switch(conn->partner->conn_type) - { - case CONN_TYPE_SOCKS: - if (conn->partner->socks_state==S_WAIT_CONNECTION) - { - conn->partner->socks_state=S_TCP; - bres = socks_send_rep_errno(conn->partner->socks_ver,conn->partner->fd,sock_err); - DBGPRINT("socks connection acknowledgement. bres=%d remote_errn=%d remote_fd=%d local_fd=%d",bres,sock_err,conn->fd,conn->partner->fd) - } - break; - } - return bres; -} ssize_t send_with_ttl(int fd, const void *buf, size_t len, int flags, int ttl) @@ -329,6 +310,26 @@ bool set_socket_buffers(int fd, int rcvbuf, int sndbuf) return true; } +static bool proxy_remote_conn_ack(tproxy_conn_t *conn, int sock_err) +{ + // if proxy mode acknowledge connection request + // conn = remote. conn->partner = local + if (!conn->remote || !conn_partner_alive(conn)) return false; + bool bres = true; + switch(conn->partner->conn_type) + { + case CONN_TYPE_SOCKS: + if (conn->partner->socks_state==S_WAIT_CONNECTION) + { + conn->partner->socks_state=S_TCP; + bres = socks_send_rep_errno(conn->partner->socks_ver,conn->partner->fd,sock_err); + DBGPRINT("socks connection acknowledgement. bres=%d remote_errn=%d remote_fd=%d local_fd=%d",bres,sock_err,conn->fd,conn->partner->fd) + } + break; + } + return bres; +} + //Createas a socket and initiates the connection to the host specified by //remote_addr. //Returns -1 if something fails, >0 on success (socket fd). @@ -595,13 +596,6 @@ static bool check_connection_attempt(tproxy_conn_t *conn, int efd) return true; } - if (!conn_partner_alive(conn)) - { - // local leg died ? - VPRINT("check_connection_attempt : fd=%d (remote) : local leg died. failing this connection attempt.", conn->fd) - return false; - } - // check the connection was sucessfull. it means its not in in SO_ERROR state if(getsockopt(conn->fd, SOL_SOCKET, SO_ERROR, &errn, &optlen) == -1) { @@ -611,11 +605,14 @@ static bool check_connection_attempt(tproxy_conn_t *conn, int efd) if (!errn) { VPRINT("Socket fd=%d (remote) connected", conn->fd) - if (!epoll_set_flow(conn, true, false) || !epoll_set_flow(conn->partner, true, false)) + if (!epoll_set_flow(conn, true, false) || conn_partner_alive(conn) && !epoll_set_flow(conn->partner, true, false)) + { return false; + } conn->state = CONN_AVAILABLE; } - return proxy_remote_conn_ack(conn,get_so_error(conn->fd)) && !errn; + proxy_remote_conn_ack(conn,get_so_error(conn->fd)); + return !errn; } @@ -1132,13 +1129,13 @@ static bool read_all_and_buffer(tproxy_conn_t *conn, int buffer_number) { conn->trd+=rd; conn->partner->wr_buf[buffer_number].len = rd; - + conn->partner->bFlowOut = true; - + size_t split_pos; - + tamper(conn, conn->partner->wr_buf[buffer_number].data, numbytes+5, &conn->partner->wr_buf[buffer_number].len, &split_pos); - + if (epoll_update_flow(conn->partner)) return true;