gluon-wan-dnsmasq: don't rewrite resolv.conf when its content hasn't changed
This avoids poking dnsmasq every time a DHCP lease is obtained or a router advertisement received.
This commit is contained in:
parent
9f4770fd62
commit
112c9d5c9d
@ -9,27 +9,38 @@ local uci = require('luci.model.uci').cursor()
|
|||||||
local fs = require 'nixio.fs'
|
local fs = require 'nixio.fs'
|
||||||
|
|
||||||
|
|
||||||
local function write_servers(f, servers)
|
local new_servers = ''
|
||||||
|
|
||||||
|
|
||||||
|
local function append_servers(servers)
|
||||||
for _, server in ipairs(servers) do
|
for _, server in ipairs(servers) do
|
||||||
f:write('nameserver ', server, '\n')
|
new_servers = new_servers .. 'nameserver ' .. server .. '\n'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function write_interface_servers(f, iface)
|
local function append_interface_servers(iface)
|
||||||
write_servers(f, ubus:call('network.interface.' .. iface, 'status', {}).inactive['dns-server'])
|
append_servers(ubus:call('network.interface.' .. iface, 'status', {}).inactive['dns-server'])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
fs.mkdirr(RESOLV_CONF_DIR)
|
|
||||||
local f = io.open(RESOLV_CONF, 'w+')
|
|
||||||
|
|
||||||
local static = uci:get_first('gluon-wan-dnsmasq', 'static', 'server')
|
local static = uci:get_first('gluon-wan-dnsmasq', 'static', 'server')
|
||||||
|
|
||||||
if type(static) == 'table' and #static > 0 then
|
if type(static) == 'table' and #static > 0 then
|
||||||
write_servers(f, static)
|
append_servers(static)
|
||||||
else
|
else
|
||||||
pcall(write_interface_servers, f, 'wan6')
|
pcall(append_interface_servers, 'wan6')
|
||||||
pcall(write_interface_servers, f, 'wan')
|
pcall(append_interface_servers, 'wan')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
fs.mkdirr(RESOLV_CONF_DIR)
|
||||||
|
|
||||||
|
local old_servers = fs.readfile(RESOLV_CONF)
|
||||||
|
|
||||||
|
if new_servers ~= old_servers then
|
||||||
|
local f = io.open(RESOLV_CONF .. '.tmp', 'w')
|
||||||
|
f:write(new_servers)
|
||||||
f:close()
|
f:close()
|
||||||
|
|
||||||
|
fs.rename(RESOLV_CONF .. '.tmp', RESOLV_CONF)
|
||||||
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user