aboutsummaryrefslogtreecommitdiffstats
path: root/src/lua/lua_ip.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2020-04-24 20:13:56 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2020-04-24 20:13:56 +0100
commit215882ae3decb3ae3d2c00161b69754b5faa0de0 (patch)
tree500ab732286d9450bcb85c837892061fe00c453d /src/lua/lua_ip.c
parent4e269dc2f8c58fe923b42717b7ea5bcc55bde25d (diff)
downloadrspamd-215882ae3decb3ae3d2c00161b69754b5faa0de0.tar.gz
rspamd-215882ae3decb3ae3d2c00161b69754b5faa0de0.zip
[Minor] Lua_ip: Add address comparison method
Diffstat (limited to 'src/lua/lua_ip.c')
-rw-r--r--src/lua/lua_ip.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/lua/lua_ip.c b/src/lua/lua_ip.c
index 2604aa100..dc51a83e9 100644
--- a/src/lua/lua_ip.c
+++ b/src/lua/lua_ip.c
@@ -165,6 +165,13 @@ LUA_FUNCTION_DEF (ip, get_port);
*/
LUA_FUNCTION_DEF (ip, is_local);
+/***
+ * @method ip:less_than(other)
+ * Returns true if address is less than other
+ * @return {boolean}
+ */
+LUA_FUNCTION_DEF (ip, less_than);
+
static const struct luaL_reg iplib_m[] = {
LUA_INTERFACE_DEF (ip, to_string),
LUA_INTERFACE_DEF (ip, to_table),
@@ -183,6 +190,7 @@ static const struct luaL_reg iplib_m[] = {
{"__tostring", lua_ip_to_string},
{"__eq", lua_ip_equal},
{"__gc", lua_ip_destroy},
+ {"__lt", lua_ip_less_than},
{NULL, NULL}
};
@@ -557,6 +565,24 @@ lua_ip_is_local (lua_State *L)
return 1;
}
+static gint
+lua_ip_less_than (lua_State *L)
+{
+ LUA_TRACE_POINT;
+ struct rspamd_lua_ip *ip = lua_check_ip (L, 1),
+ *other = lua_check_ip (L, 2);
+
+ if (ip && other) {
+ lua_pushboolean (L,
+ rspamd_inet_address_compare (ip->addr, other->addr, true) < 0);
+ }
+ else {
+ lua_pushnil (L);
+ }
+
+ return 1;
+}
+
void
rspamd_lua_ip_push (lua_State *L, rspamd_inet_addr_t *addr)
{