summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2021-10-12 13:00:49 +0100
committerGitHub <noreply@github.com>2021-10-12 13:00:49 +0100
commitb68e6b885974acbbf75b244224ca87b2fcf304fc (patch)
tree14bb11bdd4c05d2ac3c2256c5dbe00fb57537422
parent7e1b38c704dc3e25bd1f0c171f4f53effcbef75e (diff)
parentdfacd5dcf9b8e71bb1c7109bd4bdefa4d4ac75b1 (diff)
downloadrspamd-b68e6b885974acbbf75b244224ca87b2fcf304fc.tar.gz
rspamd-b68e6b885974acbbf75b244224ca87b2fcf304fc.zip
Merge pull request #3931 from fatalbanana/fix_external_relay
[Minor] external_relay: use real_ip
-rw-r--r--src/lua/lua_task.c4
-rw-r--r--src/plugins/lua/external_relay.lua31
2 files changed, 14 insertions, 21 deletions
diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c
index 1eb67a430..42cdd22f0 100644
--- a/src/lua/lua_task.c
+++ b/src/lua/lua_task.c
@@ -446,9 +446,9 @@ LUA_FUNCTION_DEF (task, modify_header);
* the following structure:
*
* - `from_hostname` - string that represents hostname provided by a peer
- * - `from_ip` - string representation of IP address as provided by a peer
+ * - `from_ip` - string representation of sending IP address
* - `real_hostname` - hostname as resolved by MTA
- * - `real_ip` - string representation of IP as resolved by PTR request of MTA
+ * - `real_ip` - rspamd_ip object representing sending IP address
* - `by_hostname` - MTA hostname
* - `proto` - protocol, e.g. ESMTP or ESMTPS
* - `timestamp` - received timestamp
diff --git a/src/plugins/lua/external_relay.lua b/src/plugins/lua/external_relay.lua
index dc973b9a6..8b20bbe82 100644
--- a/src/plugins/lua/external_relay.lua
+++ b/src/plugins/lua/external_relay.lua
@@ -24,7 +24,6 @@ end
local lua_maps = require "lua_maps"
local lua_util = require "lua_util"
-local rspamd_ip = require "rspamd_ip"
local rspamd_logger = require "rspamd_logger"
local ts = require("tableshape").types
@@ -66,25 +65,19 @@ local config_schema = ts.shape{
),
}
-local function set_from_rcvd(task, rcvd, remote_rcvd_ip)
- if not remote_rcvd_ip then
- if not rcvd.from_ip then
- rspamd_logger.errx(task, 'no IP in header: %s', rcvd)
- return
- end
- remote_rcvd_ip = rspamd_ip.from_string(rcvd.from_ip)
- if not remote_rcvd_ip and remote_rcvd_ip:is_valid() then
- rspamd_logger.errx(task, 'invalid remote IP: %s', rcvd.from_ip)
- return
- end
+local function set_from_rcvd(task, rcvd)
+ local rcvd_ip = rcvd.real_ip
+ if not (rcvd_ip and rcvd_ip:is_valid()) then
+ rspamd_logger.errx(task, 'no IP in header: %s', rcvd)
+ return
end
- task:set_from_ip(remote_rcvd_ip)
+ task:set_from_ip(rcvd_ip)
if rcvd.from_hostname then
task:set_hostname(rcvd.from_hostname)
task:set_helo(rcvd.from_hostname) -- use fake value for HELO
else
rspamd_logger.warnx(task, "couldn't get hostname from headers")
- local ipstr = string.format('[%s]', rcvd.from_ip)
+ local ipstr = string.format('[%s]', rcvd_ip)
task:set_hostname(ipstr) -- returns nil from task:get_hostname()
task:set_helo(ipstr)
end
@@ -174,7 +167,7 @@ strategies.hostname_map = function(rule)
local rcvd_hdrs = task:get_received_headers()
-- Try find sending hostname in Received headers
for _, rcvd in ipairs(rcvd_hdrs) do
- if rcvd.by_hostname == from_hn and rcvd.from_ip then
+ if rcvd.by_hostname == from_hn and rcvd.real_ip then
if not hostname_map:get_key(rcvd.from_hostname) then
-- Remote hostname is not another relay, use this header
return set_from_rcvd(task, rcvd)
@@ -206,10 +199,10 @@ strategies['local'] = function(rule)
local num_rcvd = #rcvd_hdrs
-- Try find first non-local IP in Received headers
for i, rcvd in ipairs(rcvd_hdrs) do
- if rcvd.from_ip then
- local remote_rcvd_ip = rspamd_ip.from_string(rcvd.from_ip)
- if remote_rcvd_ip and remote_rcvd_ip:is_valid() and (not remote_rcvd_ip:is_local() or i == num_rcvd) then
- return set_from_rcvd(task, rcvd, remote_rcvd_ip)
+ if rcvd.real_ip then
+ local rcvd_ip = rcvd.real_ip
+ if rcvd_ip and rcvd_ip:is_valid() and (not rcvd_ip:is_local() or i == num_rcvd) then
+ return set_from_rcvd(task, rcvd)
end
end
end