Comparison

mod_dnsupdate/mod_dnsupdate.lua @ 4764:a754f7e380b2

mod_dnsupdate: Rewrite port config vs DNS comparison code I'm not sure if it was correct, which means it was hard to understand and thus needed to be simplified. Hope this accomplishes that.
author Kim Alvefur <zash@zash.se>
date Mon, 08 Nov 2021 23:03:14 +0100
parent 4763:91077c928c57
child 4765:3632836f35b0
comparison
equal deleted inserted replaced
4763:91077c928c57 4764:a754f7e380b2
96 print("ttl " .. tostring(opts.ttl or 60 * 60)); 96 print("ttl " .. tostring(opts.ttl or 60 * 60));
97 97
98 for _, service in ipairs(services) do 98 for _, service in ipairs(services) do
99 local ports = set.new(configured_ports[service]); 99 local ports = set.new(configured_ports[service]);
100 local records = (async.wait_for(existing_srv[service])); 100 local records = (async.wait_for(existing_srv[service]));
101 local replace = opts.reset; 101 if opts.reset then
102 for _, rr in ipairs(records) do 102 print(("del _%s._tcp.%s IN SRV"):format(service, ihost));
103 if not ports:contains(rr.srv.port) or target ~= nameprep(rr.srv.target):gsub("%.$", "") then 103 else
104 if not opts.each then 104 for _, rr in ipairs(records) do
105 replace = true; 105 if ports:contains(rr.srv.port) and target == nameprep(rr.srv.target):gsub("%.$", "") then
106 break 106 ports:remove(rr.srv.port)
107 else
108 print(("del _%s._tcp.%s IN SRV %s"):format(service, ihost, rr));
107 end 109 end
108 print(("del _%s._tcp.%s IN SRV %s"):format(service, ihost, rr));
109 end 110 end
110 end 111 end
111 if replace then 112 for port in ports do print(("add _%s._tcp.%s IN SRV 1 1 %d %s"):format(service, ihost, port, target)); end
112 print(("del _%s._tcp.%s IN SRV"):format(service, ihost));
113 for port in ports do print(("add _%s._tcp.%s IN SRV 1 1 %d %s"):format(service, ihost, port, target)); end
114 end
115 end 113 end
116 114
117 print("show"); 115 print("show");
118 print("send"); 116 print("send");
119 print("answer"); 117 print("answer");