Repository: trafficserver Updated Branches: refs/heads/master ab4da857d -> 9c4dbffb5
[TS-3414]: Add new TS API TSHttpTxnOutgoingAddrGet Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/efae3a4f Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/efae3a4f Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/efae3a4f Branch: refs/heads/master Commit: efae3a4f914a7dda7b3f586a0c09c93435b90efb Parents: ab4da85 Author: Sudheer Vinukonda <[email protected]> Authored: Tue Mar 3 16:50:42 2015 +0000 Committer: Sudheer Vinukonda <[email protected]> Committed: Tue Mar 3 16:50:42 2015 +0000 ---------------------------------------------------------------------- iocore/net/UnixNetVConnection.cc | 1 + .../experimental/ts_lua/ts_lua_server_request.c | 33 +++++++++++++++++++- proxy/InkAPI.cc | 20 ++++++++++++ proxy/api/ts/ts.h | 9 ++++++ proxy/http/HttpSM.h | 7 +++++ 5 files changed, 69 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/trafficserver/blob/efae3a4f/iocore/net/UnixNetVConnection.cc ---------------------------------------------------------------------- diff --git a/iocore/net/UnixNetVConnection.cc b/iocore/net/UnixNetVConnection.cc index 7148d68..bb46c8b 100644 --- a/iocore/net/UnixNetVConnection.cc +++ b/iocore/net/UnixNetVConnection.cc @@ -1187,6 +1187,7 @@ UnixNetVConnection::connectUp(EThread *t, int fd) ink_assert(!inactivity_timeout_in); ink_assert(!active_timeout_in); + this->set_local_addr(); action_.continuation->handleEvent(NET_EVENT_OPEN, this); return CONNECT_SUCCESS; http://git-wip-us.apache.org/repos/asf/trafficserver/blob/efae3a4f/plugins/experimental/ts_lua/ts_lua_server_request.c ---------------------------------------------------------------------- diff --git a/plugins/experimental/ts_lua/ts_lua_server_request.c b/plugins/experimental/ts_lua/ts_lua_server_request.c index 062cf28..7cd6ec7 100644 --- a/plugins/experimental/ts_lua/ts_lua_server_request.c +++ b/plugins/experimental/ts_lua/ts_lua_server_request.c @@ -67,6 +67,7 @@ static int ts_lua_server_request_get_uri_args(lua_State * L); static int ts_lua_server_request_server_addr_get_ip(lua_State * L); static int ts_lua_server_request_server_addr_get_port(lua_State * L); static int ts_lua_server_request_server_addr_get_addr(lua_State * L); +static int ts_lua_server_request_server_addr_get_outgoing_port(lua_State * L); void ts_lua_inject_server_request_api(lua_State * L) @@ -105,6 +106,9 @@ ts_lua_inject_server_request_server_addr_api(lua_State * L) lua_pushcfunction(L, ts_lua_server_request_server_addr_get_addr); lua_setfield(L, -2, "get_addr"); + lua_pushcfunction(L, ts_lua_server_request_server_addr_get_outgoing_port); + lua_setfield(L, -2, "get_outgoing_port"); + lua_setfield(L, -2, "server_addr"); } @@ -485,7 +489,34 @@ ts_lua_server_request_server_addr_get_port(lua_State * L) port = ((struct sockaddr_in6 *) server_ip)->sin6_port; } - lua_pushnumber(L, port); + lua_pushnumber(L, ntohs(port)); + } + + return 1; +} + +static int +ts_lua_server_request_server_addr_get_outgoing_port(lua_State * L) +{ + struct sockaddr const *outgoing_addr; + ts_lua_http_ctx *http_ctx; + int port; + + http_ctx = ts_lua_get_http_ctx(L); + + outgoing_addr = TSHttpTxnOutgoingAddrGet(http_ctx->txnp); + + if (outgoing_addr == NULL) { + lua_pushnil(L); + + } else { + if (outgoing_addr->sa_family == AF_INET) { + port = ((struct sockaddr_in *) outgoing_addr)->sin_port; + } else { + port = ((struct sockaddr_in6 *) outgoing_addr)->sin6_port; + } + + lua_pushnumber(L, ntohs(port)); } return 1; http://git-wip-us.apache.org/repos/asf/trafficserver/blob/efae3a4f/proxy/InkAPI.cc ---------------------------------------------------------------------- diff --git a/proxy/InkAPI.cc b/proxy/InkAPI.cc index efd6572..6084b59 100644 --- a/proxy/InkAPI.cc +++ b/proxy/InkAPI.cc @@ -5265,6 +5265,26 @@ TSHttpTxnIncomingAddrGet(TSHttpTxn txnp) } sockaddr const* +TSHttpTxnOutgoingAddrGet(TSHttpTxn txnp) +{ + sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS); + + HttpSM *sm = reinterpret_cast<HttpSM *>(txnp); + + HttpServerSession *ssn = sm->get_server_session(); + if (ssn == NULL) { + return 0; + } + + NetVConnection *vc = ssn->get_netvc(); + if (vc == NULL) { + return 0; + } + + return vc->get_local_addr(); +} + +sockaddr const* TSHttpTxnServerAddrGet(TSHttpTxn txnp) { sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS); http://git-wip-us.apache.org/repos/asf/trafficserver/blob/efae3a4f/proxy/api/ts/ts.h ---------------------------------------------------------------------- diff --git a/proxy/api/ts/ts.h b/proxy/api/ts/ts.h index 8093c3a..ea97f65 100644 --- a/proxy/api/ts/ts.h +++ b/proxy/api/ts/ts.h @@ -1327,6 +1327,15 @@ extern "C" @return Local address of the client connection for transaction @a txnp. */ tsapi struct sockaddr const* TSHttpTxnIncomingAddrGet(TSHttpTxn txnp); + /** Get the outgoing address. + + @note The pointer is valid only for the current callback. Clients + that need to keep the value across callbacks must maintain their + own storage. + + @return Local address of the server connection for transaction @a txnp. + */ + tsapi struct sockaddr const* TSHttpTxnOutgoingAddrGet(TSHttpTxn txnp); /** Get the origin server address. * @note The pointer is valid only for the current callback. Clients http://git-wip-us.apache.org/repos/asf/trafficserver/blob/efae3a4f/proxy/http/HttpSM.h ---------------------------------------------------------------------- diff --git a/proxy/http/HttpSM.h b/proxy/http/HttpSM.h index d04f40b..a76d079 100644 --- a/proxy/http/HttpSM.h +++ b/proxy/http/HttpSM.h @@ -209,6 +209,13 @@ public: // holding the lock for the server session void attach_server_session(HttpServerSession * s); + // Used to read attributes of + // the current active server session + HttpServerSession* get_server_session() + { + return server_session; + } + // Called by transact. Updates are fire and forget // so there are no callbacks and are safe to do // directly from transact
