TS-1239 Fixed missing implementation of TSHttpTxnServerAddrSet
Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/904de854 Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/904de854 Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/904de854 Branch: refs/heads/master Commit: 904de854a1aad100d2445962c30ccb18d071eaa1 Parents: 0e20aad Author: Bart Wyatt <[email protected]> Authored: Thu May 3 15:14:31 2012 -0500 Committer: Bart Wyatt <[email protected]> Committed: Thu May 3 15:14:31 2012 -0500 ---------------------------------------------------------------------- proxy/InkAPI.cc | 15 +++++++++++++++ proxy/http/HttpSM.cc | 21 ++++++++++++++++++--- proxy/http/HttpTransact.h | 2 ++ 3 files changed, 35 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/trafficserver/blob/904de854/proxy/InkAPI.cc ---------------------------------------------------------------------- diff --git a/proxy/InkAPI.cc b/proxy/InkAPI.cc index 1027288..4b3ed35 100644 --- a/proxy/InkAPI.cc +++ b/proxy/InkAPI.cc @@ -5307,6 +5307,21 @@ TSHttpTxnServerAddrGet(TSHttpTxn txnp) return &sm->t_state.server_info.addr.sa; } +TSReturnCode +TSHttpTxnServerAddrSet(TSHttpTxn txnp, struct sockaddr const* addr) +{ + sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS); + + HttpSM *sm = reinterpret_cast<HttpSM *>(txnp); + if (ats_ip_copy(&sm->t_state.server_info.addr.sa, addr)) { + sm->t_state.api_server_addr_set = true; + return TS_SUCCESS; + } else { + return TS_ERROR; + } +} + + // [amc] This might use the port. The code path should do that but it // hasn't been tested. TSReturnCode http://git-wip-us.apache.org/repos/asf/trafficserver/blob/904de854/proxy/http/HttpSM.cc ---------------------------------------------------------------------- diff --git a/proxy/http/HttpSM.cc b/proxy/http/HttpSM.cc index e014afa..8e85793 100644 --- a/proxy/http/HttpSM.cc +++ b/proxy/http/HttpSM.cc @@ -4114,11 +4114,15 @@ HttpSM::do_http_server_open(bool raw) t_state.req_flavor == HttpTransact::REQ_FLAVOR_REVPROXY); ink_assert(pending_action == NULL); - ink_assert(t_state.current.server->port > 0); HSMresult_t shared_result; - t_state.current.server->addr.port() = htons(t_state.current.server->port); + if (false == t_state.api_server_addr_set) { + ink_assert(t_state.current.server->port > 0); + t_state.current.server->addr.port() = htons(t_state.current.server->port); + } else { + ink_assert(ats_ip_port_cast(&t_state.current.server->addr) != 0); + } char addrbuf[INET6_ADDRPORTSTRLEN]; DebugSM("http", "[%" PRId64 "] open connection to %s: %s", @@ -6460,7 +6464,18 @@ HttpSM::set_next_state() { sockaddr const* addr; - if (url_remap_mode == 2 && t_state.first_dns_lookup) { + if (t_state.api_server_addr_set) { + /* If the API has set the server address before the OS DNS lookup + * then we can skip the lookup + */ + ip_text_buffer ipb; + DebugSM("dns", "[HttpTransact::HandleRequest] Skipping DNS lookup for API supplied target %s.\n", ats_ip_ntop(&t_state.server_info.addr, ipb, sizeof(ipb))); + // this seems wasteful as we will just copy it right back + ats_ip_copy(t_state.host_db_info.ip(), &t_state.server_info.addr); + t_state.dns_info.lookup_success = true; + call_transact_and_set_next_state(NULL); + break; + } else if (url_remap_mode == 2 && t_state.first_dns_lookup) { DebugSM("cdn", "Skipping DNS Lookup"); // skip the DNS lookup t_state.first_dns_lookup = false; http://git-wip-us.apache.org/repos/asf/trafficserver/blob/904de854/proxy/http/HttpTransact.h ---------------------------------------------------------------------- diff --git a/proxy/http/HttpTransact.h b/proxy/http/HttpTransact.h index 0a9f7dd..694ac04 100644 --- a/proxy/http/HttpTransact.h +++ b/proxy/http/HttpTransact.h @@ -1025,6 +1025,7 @@ public: bool api_server_request_body_set; bool api_req_cacheable; bool api_resp_cacheable; + bool api_server_addr_set; UpdateCachedObject_t api_update_cached_object; LockUrl_t api_lock_url; StateMachineAction_t saved_update_next_action; @@ -1128,6 +1129,7 @@ public: api_server_request_body_set(false), api_req_cacheable(false), api_resp_cacheable(false), + api_server_addr_set(false), api_update_cached_object(UPDATE_CACHED_OBJECT_NONE), api_lock_url(LOCK_URL_FIRST), saved_update_next_action(STATE_MACHINE_ACTION_UNDEFINED),
