diff --git a/ReadMe.md b/ReadMe.md
index d1aea50..d04cbc5 100755
--- a/ReadMe.md
+++ b/ReadMe.md
@@ -216,6 +216,9 @@ Non-authoritative answer:
* 如已经安装chinaDNS,建议将chinaDNS的上游配置为SmartDNS。
* SmartDNS默认情况,将53端口的请求转发到SmartDNS的本地端口,由`Redirect`配置选项控制。
+6. 界面提示重定向失败:
+* openwrt 15.01系统不支持IPV6重定向,如网络需要支持IPV6,请将DNSMASQ上游改为smartdns,或者将smartdns的端口改为53,并停用dnsmasq。
+* LEDE之后系统,请安装IPV6的nat转发驱动。点击`system`->`Software`,点击`update lists`更新软件列表后,安装`ip6tables-mod-nat`
华硕路由器原生固件
--------------
diff --git a/package/luci/files/luci/controller/smartdns.lua b/package/luci/files/luci/controller/smartdns.lua
index 8f2daef..281fdcc 100644
--- a/package/luci/files/luci/controller/smartdns.lua
+++ b/package/luci/files/luci/controller/smartdns.lua
@@ -1,6 +1,7 @@
-- Copyright 2018 Nick Peng (pymumu@gmail.com)
module("luci.controller.smartdns", package.seeall)
+local smartdns = require "luci.model.smartdns"
function index()
if not nixio.fs.access("/etc/config/smartdns") then
@@ -17,9 +18,23 @@ end
local function is_running()
return luci.sys.call("pidof smartdns >/dev/null") == 0
end
+
function act_status()
local e={}
+ e.ipv6_works = 2;
+ e.ipv4_works = 2;
+ e.redirect = smartdns.get_config_option("smartdns", "smartdns", "redirect", nil);
+ e.local_port = smartdns.get_config_option("smartdns", "smartdns", "port", nil);
+ if e.redirect == "1" then
+ if e.local_port ~= nil and e.local_port ~= "53" then
+ e.ipv4_works = luci.sys.call("iptables -t nat -nL PREROUTING | grep REDIRECT | grep dpt:53 | grep %q >/dev/null 2>&1" % e.local_port) == 0
+ e.ipv6_works = luci.sys.call("ip6tables -t nat -nL PREROUTING | grep REDIRECT | grep dpt:53 | grep %q >/dev/null 2>&1" % e.local_port) == 0
+ else
+ e.redirect = 0
+ end
+ end
e.running = is_running()
+
luci.http.prepare_content("application/json")
luci.http.write_json(e)
end
diff --git a/package/luci/files/luci/i18n/smartdns.zh-cn.po b/package/luci/files/luci/i18n/smartdns.zh-cn.po
index 94bcc70..4eaee73 100644
--- a/package/luci/files/luci/i18n/smartdns.zh-cn.po
+++ b/package/luci/files/luci/i18n/smartdns.zh-cn.po
@@ -31,6 +31,12 @@ msgstr "本地端口"
msgid "Smartdns local server port"
msgstr "SmartDNS本地服务端口"
+msgid "IPV4 53 Port Redirect Failure"
+msgstr "IPV4 53端口重定向失败"
+
+msgid "IPV6 53 Port Redirect Failure"
+msgstr "IPV6 53端口重定向失败"
+
msgid "Redirect"
msgstr "重定向"
diff --git a/package/luci/files/luci/model/smartdns.lua b/package/luci/files/luci/model/smartdns.lua
new file mode 100644
index 0000000..3aaa632
--- /dev/null
+++ b/package/luci/files/luci/model/smartdns.lua
@@ -0,0 +1,17 @@
+-- Copyright 2018 Nick Peng (pymumu@gmail.com)
+
+require ("nixio.fs")
+require ("luci.http")
+require ("luci.dispatcher")
+require ("nixio.fs")
+
+local uci = require "luci.model.uci".cursor()
+
+module("luci.model.smartdns", package.seeall)
+
+function get_config_option(module, section, option, default)
+ return uci:get_first(module, section, option) or default
+end
+
+return m
+
diff --git a/package/luci/files/luci/view/smartdns/smartdns_status.htm b/package/luci/files/luci/view/smartdns/smartdns_status.htm
index 67bb4f6..14de190 100644
--- a/package/luci/files/luci/view/smartdns/smartdns_status.htm
+++ b/package/luci/files/luci/view/smartdns/smartdns_status.htm
@@ -3,12 +3,23 @@ XHR.poll(3, '<%=luci.dispatcher.build_url("admin", "services", "smartdns", "stat
function(x, data) {
var tb = document.getElementById('smartdns_status');
if (data && tb) {
+ var links = "";
if (data.running) {
- var links = 'SmartDNS - <%:RUNNING%>';
- tb.innerHTML = links;
+ links = 'SmartDNS - <%:RUNNING%>';
+ if (data.redirect && data.redirect == 1) {
+ if (data.ipv4_works == 0) {
+ links += "
<%:IPV4 53 Port Redirect Failure%>"
+ }
+
+ if (data.ipv6_works == 0) {
+ links += "
<%:IPV6 53 Port Redirect Failure%>"
+ }
+ }
} else {
- tb.innerHTML = 'SmartDNS - <%:NOT RUNNING%>';
+ links = 'SmartDNS - <%:NOT RUNNING%>';
}
+
+ tb.innerHTML = links;
}
}
);
diff --git a/package/openwrt/files/etc/init.d/smartdns b/package/openwrt/files/etc/init.d/smartdns
index 69103e3..4eca30f 100644
--- a/package/openwrt/files/etc/init.d/smartdns
+++ b/package/openwrt/files/etc/init.d/smartdns
@@ -18,6 +18,12 @@ set_iptable()
iptables -t nat -A PREROUTING -p udp -d $IP --dport 53 -j REDIRECT --to-ports $SMARTDNS_PORT >/dev/null 2>&1
done
+ IPS="`ifconfig | grep "inet6 addr" | grep -v " fe80::" | grep -v " ::1" | grep "Global" | awk '{print $3}'`"
+ for IP in $IPS
+ do
+ ip6tables -t nat -A PREROUTING -p udp -d $IP --dport 53 -j REDIRECT --to-ports $SMARTDNS_PORT >/dev/null 2>&1
+ done
+
}
clear_iptable()
@@ -27,6 +33,12 @@ clear_iptable()
do
iptables -t nat -D PREROUTING -p udp -d $IP --dport 53 -j REDIRECT --to-ports $SMARTDNS_PORT >/dev/null 2>&1
done
+
+ IPS="`ifconfig | grep "inet6 addr" | grep -v " fe80::" | grep -v " ::1" | grep "Global" | awk '{print $3}'`"
+ for IP in $IPS
+ do
+ ip6tables -t nat -D PREROUTING -p udp -d $IP --dport 53 -j REDIRECT --to-ports $SMARTDNS_PORT >/dev/null 2>&1
+ done
}