diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2021-11-07 12:49:50 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2021-11-07 12:54:14 +0000 |
commit | 49768177cfb52e9bf9ea3c5376d26d1247c73b3a (patch) | |
tree | 184211096b4beb72a7ec32208b9cb3cbb7fd91a4 /src | |
parent | d027742ff9aaef3ea2db8370f33bd533640b836a (diff) | |
download | rspamd-49768177cfb52e9bf9ea3c5376d26d1247c73b3a.tar.gz rspamd-49768177cfb52e9bf9ea3c5376d26d1247c73b3a.zip |
[Minor] Allow to get a port for a specific upstream
Diffstat (limited to 'src')
-rw-r--r-- | src/libutil/upstream.c | 9 | ||||
-rw-r--r-- | src/libutil/upstream.h | 7 | ||||
-rw-r--r-- | src/lua/lua_upstream.c | 23 |
3 files changed, 39 insertions, 0 deletions
diff --git a/src/libutil/upstream.c b/src/libutil/upstream.c index 8c194eb79..578efd0f4 100644 --- a/src/libutil/upstream.c +++ b/src/libutil/upstream.c @@ -1021,6 +1021,15 @@ rspamd_upstream_name (struct upstream *up) return up->name; } +gint +rspamd_upstream_port (struct upstream *up) +{ + struct upstream_addr_elt *elt; + + elt = g_ptr_array_index (up->addrs.addr, up->addrs.cur); + return rspamd_inet_address_get_port (elt->addr); +} + gboolean rspamd_upstreams_add_upstream (struct upstream_list *ups, const gchar *str, guint16 def_port, enum rspamd_upstream_parse_type parse_type, diff --git a/src/libutil/upstream.h b/src/libutil/upstream.h index 72a768892..e81fa2ed7 100644 --- a/src/libutil/upstream.h +++ b/src/libutil/upstream.h @@ -249,6 +249,13 @@ gboolean rspamd_upstream_add_addr (struct upstream *up, const gchar *rspamd_upstream_name (struct upstream *up); /** + * Returns the port of the current addres for the upstream + * @param up + * @return + */ +gint rspamd_upstream_port (struct upstream *up); + +/** * Sets opaque user data associated with this upstream * @param up * @param data diff --git a/src/lua/lua_upstream.c b/src/lua/lua_upstream.c index 322b242f8..5019f28d3 100644 --- a/src/lua/lua_upstream.c +++ b/src/lua/lua_upstream.c @@ -79,12 +79,14 @@ LUA_FUNCTION_DEF (upstream, ok); LUA_FUNCTION_DEF (upstream, fail); LUA_FUNCTION_DEF (upstream, get_addr); LUA_FUNCTION_DEF (upstream, get_name); +LUA_FUNCTION_DEF (upstream, get_port); LUA_FUNCTION_DEF (upstream, destroy); static const struct luaL_reg upstream_m[] = { LUA_INTERFACE_DEF (upstream, ok), LUA_INTERFACE_DEF (upstream, fail), LUA_INTERFACE_DEF (upstream, get_addr), + LUA_INTERFACE_DEF (upstream, get_port), LUA_INTERFACE_DEF (upstream, get_name), {"__tostring", rspamd_lua_class_tostring}, {"__gc", lua_upstream_destroy}, @@ -150,6 +152,27 @@ lua_upstream_get_name (lua_State *L) } /*** + * @method upstream:get_port() + * Get port of upstream + * @return {int} port of the upstream + */ +static gint +lua_upstream_get_port (lua_State *L) +{ + LUA_TRACE_POINT; + struct rspamd_lua_upstream *up = lua_check_upstream (L); + + if (up) { + lua_pushinteger (L, rspamd_upstream_port (up->up)); + } + else { + lua_pushnil (L); + } + + return 1; +} + +/*** * @method upstream:fail() * Indicate upstream failure. After certain amount of failures during specified time frame, an upstream is marked as down and does not participate in rotations. */ |