From e564ad6e7abf81953d5802da58b9c34f9458f887 Mon Sep 17 00:00:00 2001 From: Oknet Xu Date: Fri, 23 Dec 2016 13:06:22 +0800 Subject: [PATCH] TS-5105: Do vc->con.setRemote(target) before socksEntry->init() --- iocore/net/Socks.cc | 2 +- iocore/net/UnixNetProcessor.cc | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/iocore/net/Socks.cc b/iocore/net/Socks.cc index 825fda12a9d..30e385510e3 100644 --- a/iocore/net/Socks.cc +++ b/iocore/net/Socks.cc @@ -248,7 +248,7 @@ SocksEntry::mainEvent(int event, void *data) p[n_bytes++] = version; p[n_bytes++] = (socks_cmd == NORMAL_SOCKS) ? SOCKS_CONNECT : socks_cmd; - ts = ntohs(ats_ip_port_cast(&target_addr)); + ts = ats_ip_port_cast(&target_addr); if (version == SOCKS5_VERSION) { p[n_bytes++] = 0; // Reserved diff --git a/iocore/net/UnixNetProcessor.cc b/iocore/net/UnixNetProcessor.cc index c3d2fa74380..490d92e963a 100644 --- a/iocore/net/UnixNetProcessor.cc +++ b/iocore/net/UnixNetProcessor.cc @@ -216,11 +216,16 @@ UnixNetProcessor::connect_re_internal(Continuation *cont, sockaddr const *target vc->submit_time = Thread::get_hrtime(); vc->mutex = cont->mutex; Action *result = &vc->action_; + // Copy target to con.addr, + // then con.addr will copy to vc->remote_addr by set_remote_addr() + vc->con.setRemote(target); if (using_socks) { char buff[INET6_ADDRPORTSTRLEN]; Debug("Socks", "Using Socks ip: %s", ats_ip_nptop(target, buff, sizeof(buff))); socksEntry = socksAllocator.alloc(); + // The socksEntry->init() will get the origin server addr by vc->get_remote_addr(), + // and save it to socksEntry->req_data.dest_ip. socksEntry->init(cont->mutex, vc, opt->socks_support, opt->socks_version); /*XXXX remove last two args */ socksEntry->action_ = cont; cont = socksEntry; @@ -229,12 +234,13 @@ UnixNetProcessor::connect_re_internal(Continuation *cont, sockaddr const *target socksEntry->free(); return ACTION_RESULT_DONE; } + // At the end of socksEntry->init(), a socks server will be selected and saved to socksEntry->server_addr. + // Therefore, we should set the remote to socks server in order to establish a connection with socks server. vc->con.setRemote(&socksEntry->server_addr.sa); result = &socksEntry->action_; vc->action_ = socksEntry; } else { Debug("Socks", "Not Using Socks %d ", socks_conf_stuff->socks_needed); - vc->con.setRemote(target); vc->action_ = cont; }