Add ipv6 option
This commit is contained in:
@@ -21,14 +21,21 @@ end
|
|||||||
|
|
||||||
function act_status()
|
function act_status()
|
||||||
local e={}
|
local e={}
|
||||||
|
local ipv6_server;
|
||||||
e.ipv6_works = 2;
|
e.ipv6_works = 2;
|
||||||
e.ipv4_works = 2;
|
e.ipv4_works = 2;
|
||||||
|
e.ipv6_server = 1;
|
||||||
e.redirect = smartdns.get_config_option("smartdns", "smartdns", "redirect", nil);
|
e.redirect = smartdns.get_config_option("smartdns", "smartdns", "redirect", nil);
|
||||||
e.local_port = smartdns.get_config_option("smartdns", "smartdns", "port", nil);
|
e.local_port = smartdns.get_config_option("smartdns", "smartdns", "port", nil);
|
||||||
|
ipv6_server = smartdns.get_config_option("smartdns", "smartdns", "ipv6_server", nil);
|
||||||
if e.redirect == "1" then
|
if e.redirect == "1" then
|
||||||
if e.local_port ~= nil and e.local_port ~= "53" then
|
if e.local_port ~= nil and e.local_port ~= "53" then
|
||||||
e.ipv4_works = luci.sys.call("iptables -t nat -nL PREROUTING 2>/dev/null | grep REDIRECT | grep dpt:53 | grep %q >/dev/null 2>&1" % e.local_port) == 0
|
e.ipv4_works = luci.sys.call("iptables -t nat -nL PREROUTING 2>/dev/null | 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 2>/dev/null| grep REDIRECT | grep dpt:53 | grep %q >/dev/null 2>&1" % e.local_port) == 0
|
if ipv6_server == "1" then
|
||||||
|
e.ipv6_works = luci.sys.call("ip6tables -t nat -nL PREROUTING 2>/dev/null| grep REDIRECT | grep dpt:53 | grep %q >/dev/null 2>&1" % e.local_port) == 0
|
||||||
|
else
|
||||||
|
e.ipv6_works = 2
|
||||||
|
end
|
||||||
else
|
else
|
||||||
e.redirect = 0
|
e.redirect = 0
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -40,6 +40,12 @@ msgstr "IPV4 53端口重定向失败"
|
|||||||
msgid "IPV6 53 Port Redirect Failure"
|
msgid "IPV6 53 Port Redirect Failure"
|
||||||
msgstr "IPV6 53端口重定向失败"
|
msgstr "IPV6 53端口重定向失败"
|
||||||
|
|
||||||
|
msgid "IPV6 Server"
|
||||||
|
msgstr "IPV6服务器"
|
||||||
|
|
||||||
|
msgid "Enable IPV6 DNS Server"
|
||||||
|
msgstr "启用IPV6服务器"
|
||||||
|
|
||||||
msgid "Redirect"
|
msgid "Redirect"
|
||||||
msgstr "重定向"
|
msgstr "重定向"
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,14 @@ o.default = 5353
|
|||||||
o.datatype = "port"
|
o.datatype = "port"
|
||||||
o.rempty = false
|
o.rempty = false
|
||||||
|
|
||||||
|
---- Support IPV6
|
||||||
|
o = s:taboption("settings", Flag, "ipv6_server", translate("IPV6 Server"), translate("Enable IPV6 DNS Server"))
|
||||||
|
o.rmempty = false
|
||||||
|
o.default = o.enabled
|
||||||
|
o.cfgvalue = function(...)
|
||||||
|
return Flag.cfgvalue(...) or "1"
|
||||||
|
end
|
||||||
|
|
||||||
o = s:taboption("settings", Flag, "redirect", translate("Redirect"), translate("Redirect standard dns query from 53 to smartdns, as default DNS server"))
|
o = s:taboption("settings", Flag, "redirect", translate("Redirect"), translate("Redirect standard dns query from 53 to smartdns, as default DNS server"))
|
||||||
o.rmempty = false
|
o.rmempty = false
|
||||||
o.default = o.enabled
|
o.default = o.enabled
|
||||||
|
|||||||
@@ -10,9 +10,11 @@ XHR.poll(3, '<%=luci.dispatcher.build_url("admin", "services", "smartdns", "stat
|
|||||||
if (data.ipv4_works == 0) {
|
if (data.ipv4_works == 0) {
|
||||||
links += "<br></br><b><font color=red><%:IPV4 53 Port Redirect Failure%></font></b>"
|
links += "<br></br><b><font color=red><%:IPV4 53 Port Redirect Failure%></font></b>"
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.ipv6_works == 0) {
|
if (data.ipv6_works != 2) {
|
||||||
links += "<br></br><b><font color=red><%:IPV6 53 Port Redirect Failure%></font></b>"
|
if (data.ipv6_works == 0) {
|
||||||
|
links += "<br></br><b><font color=red><%:IPV6 53 Port Redirect Failure%></font></b>"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -13,12 +13,17 @@ SMARTDNS_CONF_TMP="${SMARTDNS_CONF}.tmp"
|
|||||||
|
|
||||||
set_iptable()
|
set_iptable()
|
||||||
{
|
{
|
||||||
IPS="`ifconfig | grep "inet addr" | grep -v ":127" | grep "Bcast" | awk '{print $2}' | awk -F: '{print $2}'`"
|
local ipv6_server=$1
|
||||||
|
IPS="`ifconfig | grep "inet addr" | grep -v ":127" | grep "Bcast" | awk '{print $2}' | awk -F : '{print $2}'`"
|
||||||
for IP in $IPS
|
for IP in $IPS
|
||||||
do
|
do
|
||||||
iptables -t nat -A PREROUTING -p udp -d $IP --dport 53 -j REDIRECT --to-ports $SMARTDNS_PORT >/dev/null 2>&1
|
iptables -t nat -A PREROUTING -p udp -d $IP --dport 53 -j REDIRECT --to-ports $SMARTDNS_PORT >/dev/null 2>&1
|
||||||
done
|
done
|
||||||
|
|
||||||
|
if [ "$ipv6_server" == 0 ]; then
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
IPS="`ifconfig | grep "inet6 addr" | grep -v " fe80::" | grep -v " ::1" | grep "Global" | awk '{print $3}'`"
|
IPS="`ifconfig | grep "inet6 addr" | grep -v " fe80::" | grep -v " ::1" | grep "Global" | awk '{print $3}'`"
|
||||||
for IP in $IPS
|
for IP in $IPS
|
||||||
do
|
do
|
||||||
@@ -29,12 +34,17 @@ set_iptable()
|
|||||||
|
|
||||||
clear_iptable()
|
clear_iptable()
|
||||||
{
|
{
|
||||||
IPS="`ifconfig | grep "inet addr" | grep -v ":127" | grep "Bcast" | awk '{print $2}' | awk -F: '{print $2}'`"
|
local ipv6_server=$1
|
||||||
|
IPS="`ifconfig | grep "inet addr" | grep -v ":127" | grep "Bcast" | awk '{print $2}' | awk -F : '{print $2}'`"
|
||||||
for IP in $IPS
|
for IP in $IPS
|
||||||
do
|
do
|
||||||
iptables -t nat -D PREROUTING -p udp -d $IP --dport 53 -j REDIRECT --to-ports $SMARTDNS_PORT >/dev/null 2>&1
|
iptables -t nat -D PREROUTING -p udp -d $IP --dport 53 -j REDIRECT --to-ports $SMARTDNS_PORT >/dev/null 2>&1
|
||||||
done
|
done
|
||||||
|
|
||||||
|
if [ "$ipv6_server" == 0 ]; then
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
IPS="`ifconfig | grep "inet6 addr" | grep -v " fe80::" | grep -v " ::1" | grep "Global" | awk '{print $3}'`"
|
IPS="`ifconfig | grep "inet6 addr" | grep -v " fe80::" | grep -v " ::1" | grep "Global" | awk '{print $3}'`"
|
||||||
for IP in $IPS
|
for IP in $IPS
|
||||||
do
|
do
|
||||||
@@ -89,7 +99,12 @@ start_service() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
config_get "port" "$section" "port" "5353"
|
config_get "port" "$section" "port" "5353"
|
||||||
conf_append "bind" "[::]:$port"
|
config_get "ipv6_server" "$section" "ipv6_server" "1"
|
||||||
|
if [ "$ipv6_server" = "1" ]; then
|
||||||
|
conf_append "bind" "[::]:$port"
|
||||||
|
else
|
||||||
|
conf_append "bind" ":$port"
|
||||||
|
fi
|
||||||
SMARTDNS_PORT="$port"
|
SMARTDNS_PORT="$port"
|
||||||
|
|
||||||
mkdir -p $(dirname $SMARTDNS_CONF)
|
mkdir -p $(dirname $SMARTDNS_CONF)
|
||||||
@@ -137,7 +152,7 @@ start_service() {
|
|||||||
clear_iptable
|
clear_iptable
|
||||||
config_get_bool "redirect" "$section" "redirect" '0'
|
config_get_bool "redirect" "$section" "redirect" '0'
|
||||||
if [ "$redirect" -eq 1 ]; then
|
if [ "$redirect" -eq 1 ]; then
|
||||||
set_iptable
|
set_iptable $ipv6_server
|
||||||
fi
|
fi
|
||||||
|
|
||||||
config_foreach load_server "server"
|
config_foreach load_server "server"
|
||||||
|
|||||||
@@ -109,6 +109,7 @@ struct fast_ping_struct {
|
|||||||
|
|
||||||
static struct fast_ping_struct ping;
|
static struct fast_ping_struct ping;
|
||||||
static atomic_t ping_sid = ATOMIC_INIT(0);
|
static atomic_t ping_sid = ATOMIC_INIT(0);
|
||||||
|
static int bool_print_log = 1;
|
||||||
|
|
||||||
uint16_t _fast_ping_checksum(uint16_t *header, size_t len)
|
uint16_t _fast_ping_checksum(uint16_t *header, size_t len)
|
||||||
{
|
{
|
||||||
@@ -325,6 +326,14 @@ static int _fast_ping_sendping_v6(struct ping_host_struct *ping_host)
|
|||||||
if (errno == ENETUNREACH) {
|
if (errno == ENETUNREACH) {
|
||||||
goto errout;
|
goto errout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (errno == EACCES) {
|
||||||
|
if (bool_print_log == 0) {
|
||||||
|
goto errout;
|
||||||
|
}
|
||||||
|
bool_print_log = 0;
|
||||||
|
}
|
||||||
|
|
||||||
char ping_host_name[PING_MAX_HOSTLEN];
|
char ping_host_name[PING_MAX_HOSTLEN];
|
||||||
tlog(TLOG_ERROR, "sendto %s, id %d, %s", gethost_by_addr(ping_host_name, (struct sockaddr *)&ping_host->addr, ping_host->addr_len), ping_host->sid,
|
tlog(TLOG_ERROR, "sendto %s, id %d, %s", gethost_by_addr(ping_host_name, (struct sockaddr *)&ping_host->addr, ping_host->addr_len), ping_host->sid,
|
||||||
strerror(err));
|
strerror(err));
|
||||||
@@ -398,6 +407,14 @@ static int _fast_ping_sendping_tcp(struct ping_host_struct *ping_host)
|
|||||||
if (errno == ENETUNREACH) {
|
if (errno == ENETUNREACH) {
|
||||||
goto errout;
|
goto errout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (errno == EACCES) {
|
||||||
|
if (bool_print_log == 0) {
|
||||||
|
goto errout;
|
||||||
|
}
|
||||||
|
bool_print_log = 0;
|
||||||
|
}
|
||||||
|
|
||||||
tlog(TLOG_ERROR, "connect %s, id %d, %s", gethost_by_addr(ping_host_name, (struct sockaddr *)&ping_host->addr, ping_host->addr_len), ping_host->sid,
|
tlog(TLOG_ERROR, "connect %s, id %d, %s", gethost_by_addr(ping_host_name, (struct sockaddr *)&ping_host->addr, ping_host->addr_len), ping_host->sid,
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
goto errout;
|
goto errout;
|
||||||
@@ -1048,6 +1065,7 @@ int fast_ping_init(void)
|
|||||||
pthread_attr_t attr;
|
pthread_attr_t attr;
|
||||||
int epollfd = -1;
|
int epollfd = -1;
|
||||||
int ret;
|
int ret;
|
||||||
|
bool_print_log = 1;
|
||||||
|
|
||||||
if (ping.epoll_fd > 0) {
|
if (ping.epoll_fd > 0) {
|
||||||
return -1;
|
return -1;
|
||||||
|
|||||||
@@ -198,8 +198,8 @@ int smartdns_init(void)
|
|||||||
goto errout;
|
goto errout;
|
||||||
}
|
}
|
||||||
|
|
||||||
tlog_setlogscreen(1);
|
/* tlog_setlogscreen(1); */
|
||||||
tlog_setlevel(TLOG_INFO);
|
tlog_setlevel(dns_conf_log_level);
|
||||||
|
|
||||||
if (dns_conf_server_num <= 0) {
|
if (dns_conf_server_num <= 0) {
|
||||||
if (smartdns_load_from_resolv() != 0) {
|
if (smartdns_load_from_resolv() != 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user