changeset 6353:83355cfcad1d

mod_s2s_failclose: Report outgoing connection failures to remote servers Plugin form of Prosody trunk rev d4a7cc295363 for earlier versions.
author Kim Alvefur <zash@zash.se>
date Tue, 30 Dec 2025 23:32:50 +0100
parents 525655adfd3e
children 7bca4f5935d6
files mod_s2s_failclose/README.md mod_s2s_failclose/mod_s2s_failclose.lua
diffstat 2 files changed, 23 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mod_s2s_failclose/README.md	Tue Dec 30 23:32:50 2025 +0100
@@ -0,0 +1,9 @@
+This module helps operators of other servers notice when there is a problem with their DNS, firewall, port forwarding or other connectivity issue.
+If their server manages to establish a connection in yours, but your server can't connect back, this module closes the first connection with an error.
+Hopefully that error shows up in the logs on the other end, where the operator can notice and attempt to resolve the issues.
+
+  Prosody version          status
+  ------------------------ --------------------------
+  trunk as of 2025-12-31   This feature is included
+  13.0                     Works
+  0.12                     Not tested
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mod_s2s_failclose/mod_s2s_failclose.lua	Tue Dec 30 23:32:50 2025 +0100
@@ -0,0 +1,14 @@
+module:set_global();
+local errors = require "prosody.util.error";
+local incoming_s2s = prosody.incoming_s2s;
+
+-- When an outgoing connection fails, close a corresponding incoming connection with a stream error to indicate the problem to the remote
+module:hook("s2s-destroyed", function(event)
+	local s2sout = event.session;
+	if s2sout.type ~= "s2sout_unauthed" then return end
+	for s2sin in pairs(incoming_s2s) do
+		if s2sin.from_host == s2sout.to_host and s2sin.to_host == s2sout.from_host then
+			s2sin:close(errors.new({ condition = "reset", text = "Could not deliver return stanzas, please check your DNS and firewall" }));
+		end
+	end
+end);