comparison mod_dnsupdate/mod_dnsupdate.lua @ 6220: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 429be658c0bb
children 52e239aa96af
comparison
equal deleted inserted replaced
6219:4d040f506c6c 6220:b6e390a97c85
100 print("zone", domain); 100 print("zone", domain);
101 print("server", primary); 101 print("server", primary);
102 print("ttl " .. tostring(opts.ttl or 60 * 60)); 102 print("ttl " .. tostring(opts.ttl or 60 * 60));
103 103
104 for _, service in ipairs(services) do 104 for _, service in ipairs(services) do
105 local ports = set.new(configured_ports[service]); 105 local config_ports = set.new(configured_ports[service]);
106 local records = (async.wait_for(existing_srv[service])); 106 local dns_ports = set.new();
107 if opts.remove or opts.reset then 107
108 if (opts.reset or opts.remove) and not opts.each then
108 print(("del _%s._tcp.%s IN SRV"):format(service, ihost)); 109 print(("del _%s._tcp.%s IN SRV"):format(service, ihost));
109 else 110 else
111 local records = (async.wait_for(existing_srv[service]));
110 for _, rr in ipairs(records) do 112 for _, rr in ipairs(records) do
111 if ports:contains(rr.srv.port) and target == nameprep(rr.srv.target):gsub("%.$", "") then 113 if target == nameprep(rr.srv.target):gsub("%.$", "") then
112 ports:remove(rr.srv.port) 114 dns_ports:add(rr.srv.port)
113 elseif not opts.each then 115 elseif opts.each then
114 print(("del _%s._tcp.%s IN SRV"):format(service, ihost));
115 break
116 else
117 print(("del _%s._tcp.%s IN SRV %s"):format(service, ihost, rr)); 116 print(("del _%s._tcp.%s IN SRV %s"):format(service, ihost, rr));
118 end 117 end
119 end 118 end
120 end 119 end
120
121 if not opts.remove then 121 if not opts.remove then
122 for port in ports do print(("add _%s._tcp.%s IN SRV 1 1 %d %s"):format(service, ihost, port, target)); end 122 if config_ports:empty() then
123 print(("add _%s._tcp.%s IN SRV 0 0 0 ."):format(service, ihost));
124 else
125 for port in (config_ports - dns_ports) do
126 print(("add _%s._tcp.%s IN SRV 1 1 %d %s"):format(service, ihost, port, target));
127 end
128 end
123 end 129 end
124 if ports:empty() then print(("add _%s._tcp.%s IN SRV 0 0 0 ."):format(service, ihost)); end
125 end 130 end
126 131
127 print("show"); 132 print("show");
128 print("send"); 133 print("send");
129 print("answer"); 134 print("answer");