You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by ki...@apache.org on 2018/04/19 17:06:18 UTC
[trafficserver] branch master updated: ts_lua -- Exposes the TS API
function TSHttpTxnNextHopAddrGet()
This is an automated email from the ASF dual-hosted git repository.
kichan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/master by this push:
new e163947 ts_lua -- Exposes the TS API function TSHttpTxnNextHopAddrGet()
e163947 is described below
commit e1639478da2d70ba764348b35cccbaf473b98c1b
Author: Peter Chou <pb...@labs.att.com>
AuthorDate: Tue Feb 20 13:55:44 2018 -0800
ts_lua -- Exposes the TS API function TSHttpTxnNextHopAddrGet()
This change exposes the TS API function TSHttpTxnNextHopAddrGet()
to the Lua plugin as ts.server_request.server_addr.get_nexthop_addr().
---
doc/admin-guide/plugins/ts_lua.en.rst | 23 ++++++++++++
.../experimental/ts_lua/ts_lua_server_request.c | 41 ++++++++++++++++++++++
2 files changed, 64 insertions(+)
diff --git a/doc/admin-guide/plugins/ts_lua.en.rst b/doc/admin-guide/plugins/ts_lua.en.rst
index 9f0a08b..8ada7c8 100644
--- a/doc/admin-guide/plugins/ts_lua.en.rst
+++ b/doc/admin-guide/plugins/ts_lua.en.rst
@@ -1539,6 +1539,29 @@ Here is an example:
`TOP <#ts-lua-plugin>`_
+ts.server_request.server_addr.get_nexthop_addr
+----------------------------------------------
+**syntax:** *ts.server_request.server_addr.get_nexthop_addr()*
+
+**context:** function @ TS_LUA_HOOK_SEND_REQUEST_HDR hook point or later
+
+**description**: This function can be used to get socket address of the next hop to the origin server.
+
+The ts.server_request.server_addr.get_nexthop_addr function returns three values, ip is a string, port and family is number.
+
+Here is an example:
+
+::
+
+ function do_global_send_request()
+ ip, port, family = ts.server_request.server_addr.get_nexthop_addr()
+ print(ip) -- 192.168.231.17
+ print(port) -- 80
+ print(family) -- 2(AF_INET)
+ end
+
+`TOP <#ts-lua-plugin>`_
+
ts.server_request.server_addr.get_ip
------------------------------------
**syntax:** *ts.server_request.server_addr.get_ip()*
diff --git a/plugins/experimental/ts_lua/ts_lua_server_request.c b/plugins/experimental/ts_lua/ts_lua_server_request.c
index 9cccade..3c52cc6 100644
--- a/plugins/experimental/ts_lua/ts_lua_server_request.c
+++ b/plugins/experimental/ts_lua/ts_lua_server_request.c
@@ -74,6 +74,7 @@ static int ts_lua_server_request_server_addr_get_addr(lua_State *L);
static int ts_lua_server_request_server_addr_set_addr(lua_State *L);
static int ts_lua_server_request_server_addr_get_outgoing_port(lua_State *L);
static int ts_lua_server_request_server_addr_set_outgoing_addr(lua_State *L);
+static int ts_lua_server_request_server_addr_get_nexthop_addr(lua_State *L);
void
ts_lua_inject_server_request_api(lua_State *L)
@@ -124,6 +125,9 @@ ts_lua_inject_server_request_server_addr_api(lua_State *L)
lua_pushcfunction(L, ts_lua_server_request_server_addr_set_outgoing_addr);
lua_setfield(L, -2, "set_outgoing_addr");
+ lua_pushcfunction(L, ts_lua_server_request_server_addr_get_nexthop_addr);
+ lua_setfield(L, -2, "get_nexthop_addr");
+
lua_setfield(L, -2, "server_addr");
lua_pushinteger(L, AF_INET);
@@ -770,6 +774,43 @@ ts_lua_server_request_server_addr_get_addr(lua_State *L)
}
static int
+ts_lua_server_request_server_addr_get_nexthop_addr(lua_State *L)
+{
+ struct sockaddr const *server_ip;
+ ts_lua_http_ctx *http_ctx;
+ int port;
+ int family;
+ char sip[128];
+
+ GET_HTTP_CONTEXT(http_ctx, L);
+
+ server_ip = TSHttpTxnNextHopAddrGet(http_ctx->txnp);
+
+ if (server_ip == NULL) {
+ lua_pushnil(L);
+ lua_pushnil(L);
+ lua_pushnil(L);
+
+ } else {
+ if (server_ip->sa_family == AF_INET) {
+ port = ntohs(((struct sockaddr_in *)server_ip)->sin_port);
+ inet_ntop(AF_INET, (const void *)&((struct sockaddr_in *)server_ip)->sin_addr, sip, sizeof(sip));
+ family = AF_INET;
+ } else {
+ port = ntohs(((struct sockaddr_in6 *)server_ip)->sin6_port);
+ inet_ntop(AF_INET6, (const void *)&((struct sockaddr_in6 *)server_ip)->sin6_addr, sip, sizeof(sip));
+ family = AF_INET6;
+ }
+
+ lua_pushstring(L, sip);
+ lua_pushnumber(L, port);
+ lua_pushnumber(L, family);
+ }
+
+ return 3;
+}
+
+static int
ts_lua_server_request_server_addr_set_addr(lua_State *L)
{
union {
--
To stop receiving notification emails like this one, please contact
kichan@apache.org.