Software /
code /
prosody-modules
Changeset
6254:b6e390a97c85
mod_dnsupdate: Improve handling of existing DNS records
Previously it would print the final service denial record when the
current DNS setup matched the config and no changes were necessary.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 12 May 2025 12:15:10 +0200 |
parents | 6253:4d040f506c6c |
children | 6255:52e239aa96af |
files | mod_dnsupdate/mod_dnsupdate.lua |
diffstat | 1 files changed, 16 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/mod_dnsupdate/mod_dnsupdate.lua Mon May 12 12:13:25 2025 +0200 +++ b/mod_dnsupdate/mod_dnsupdate.lua Mon May 12 12:15:10 2025 +0200 @@ -102,26 +102,31 @@ print("ttl " .. tostring(opts.ttl or 60 * 60)); for _, service in ipairs(services) do - local ports = set.new(configured_ports[service]); - local records = (async.wait_for(existing_srv[service])); - if opts.remove or opts.reset then + local config_ports = set.new(configured_ports[service]); + local dns_ports = set.new(); + + if (opts.reset or opts.remove) and not opts.each then print(("del _%s._tcp.%s IN SRV"):format(service, ihost)); else + local records = (async.wait_for(existing_srv[service])); for _, rr in ipairs(records) do - if ports:contains(rr.srv.port) and target == nameprep(rr.srv.target):gsub("%.$", "") then - ports:remove(rr.srv.port) - elseif not opts.each then - print(("del _%s._tcp.%s IN SRV"):format(service, ihost)); - break - else + if target == nameprep(rr.srv.target):gsub("%.$", "") then + dns_ports:add(rr.srv.port) + elseif opts.each then print(("del _%s._tcp.%s IN SRV %s"):format(service, ihost, rr)); end end end + if not opts.remove then - for port in ports do print(("add _%s._tcp.%s IN SRV 1 1 %d %s"):format(service, ihost, port, target)); end + if config_ports:empty() then + print(("add _%s._tcp.%s IN SRV 0 0 0 ."):format(service, ihost)); + else + for port in (config_ports - dns_ports) do + print(("add _%s._tcp.%s IN SRV 1 1 %d %s"):format(service, ihost, port, target)); + end + end end - if ports:empty() then print(("add _%s._tcp.%s IN SRV 0 0 0 ."):format(service, ihost)); end end print("show");