From 9be7a5cad73cbe11af9f90e22995c7d10f40b5ac Mon Sep 17 00:00:00 2001
From: David Bauer <blocktrron@users.noreply.github.com>
Date: Tue, 30 Jun 2020 16:37:09 +0200
Subject: [PATCH] gluon-wan-dnsmasq: read interfaces to update from flag-files
 (#2060)

This commit changes the behavior for the wan-dnsmasq to read the
interfaces to update the DNS servers on from flag-files.

This way, external custom packages which add a custom VPN WAN interface
can update the DNS server gluon is using for WAN resolving.
---
 .../interface.d/050-gluon-wan-dnsmasq          |  2 ++
 .../luasrc/lib/gluon/wan-dnsmasq/update.lua    | 18 ++++++++++++++++--
 2 files changed, 18 insertions(+), 2 deletions(-)
 create mode 100644 package/gluon-wan-dnsmasq/files/lib/gluon/wan-dnsmasq/interface.d/050-gluon-wan-dnsmasq

diff --git a/package/gluon-wan-dnsmasq/files/lib/gluon/wan-dnsmasq/interface.d/050-gluon-wan-dnsmasq b/package/gluon-wan-dnsmasq/files/lib/gluon/wan-dnsmasq/interface.d/050-gluon-wan-dnsmasq
new file mode 100644
index 000000000..585dd7a96
--- /dev/null
+++ b/package/gluon-wan-dnsmasq/files/lib/gluon/wan-dnsmasq/interface.d/050-gluon-wan-dnsmasq
@@ -0,0 +1,2 @@
+wan6
+wan
diff --git a/package/gluon-wan-dnsmasq/luasrc/lib/gluon/wan-dnsmasq/update.lua b/package/gluon-wan-dnsmasq/luasrc/lib/gluon/wan-dnsmasq/update.lua
index edd33f2cb..196a0c2ff 100755
--- a/package/gluon-wan-dnsmasq/luasrc/lib/gluon/wan-dnsmasq/update.lua
+++ b/package/gluon-wan-dnsmasq/luasrc/lib/gluon/wan-dnsmasq/update.lua
@@ -16,6 +16,19 @@ local function append_server(server)
 end
 
 
+local function handled_interfaces()
+  local interfaces = {}
+
+  for _, path in ipairs(util.glob('/lib/gluon/wan-dnsmasq/interface.d/*')) do
+    for interface in io.lines(path) do
+      table.insert(interfaces, interface)
+    end
+  end
+
+  return interfaces
+end
+
+
 local function handle_interface(status)
   local ifname = status.device
   local servers = status.inactive['dns-server']
@@ -41,8 +54,9 @@ if type(static) == 'table' and #static > 0 then
     append_server(server)
   end
 else
-  pcall(append_interface_servers, 'wan6')
-  pcall(append_interface_servers, 'wan')
+  for _, interface in ipairs(handled_interfaces()) do
+      pcall(append_interface_servers, interface)
+  end
 end
 
 
-- 
GitLab