Просмотр исходного кода

luci: support bind muti devices

Nick Peng 2 лет назад
Родитель
Сommit
3ed8150ac6

+ 1 - 1
package/luci-compat/files/luci/i18n/smartdns.zh-cn.po

@@ -234,7 +234,7 @@ msgid "List of files to download."
 msgstr "下载的文件列表。"
 
 msgid "Listen only on the specified interfaces."
-msgstr "监听在指定的设备上,避免非网络的DNS查询请求。"
+msgstr "监听在指定的设备上,避免非本地网络的DNS查询请求。"
 
 msgid "Local Port"
 msgstr "本地端口"

+ 1 - 1
package/luci/files/luci/i18n/smartdns.zh-cn.po

@@ -260,7 +260,7 @@ msgid "List of files to download."
 msgstr "下载文件列表"
 
 msgid "Listen only on the specified interfaces."
-msgstr "监听在指定的设备上,避免非网络的DNS查询请求。"
+msgstr "监听在指定的设备上,避免非本地网络的DNS查询请求。"
 
 msgid "Local Port"
 msgstr "本地端口"

+ 39 - 29
package/openwrt/files/etc/init.d/smartdns

@@ -348,6 +348,40 @@ load_domain_rule_list()
 	conf_append "domain-rules" "/domain-set:domain-rule-list-${domain_set_name}/ $domain_set_args"	
 }
 
+conf_append_bind()
+{
+	local ADDR=""
+	local port="$1"
+	local devices="$2"
+	local tcp_server="$3"
+	local ipv6_server="$4"
+	local ARGS="$5"
+
+	if [ "$ipv6_server" = "1" ]; then
+		ADDR="[::]"
+	else
+		ADDR=""
+	fi
+
+	devices=$(echo "$devices" | sed 's/,/ /g')
+	[ ! -z "$devices" ] && devices="$devices lo"
+	[ -z "$devices" ] && devices="-"
+
+	for device in $devices; do
+		device="@$device"
+		[ "$device" = "@-" ] && device=""
+		conf_append "bind" "$ADDR:$port$device $ARGS"
+	done
+
+	[ "$tcp_server" = "1" ] && {
+		for device in $devices; do
+			device="@$device"
+			[ "$device" = "@-" ] && device=""
+			conf_append "bind-tcp" "$ADDR:$port$device $ARGS"
+		done
+	}
+}
+
 load_second_server()
 {
 	local section="$1"
@@ -389,20 +423,12 @@ load_second_server()
 
 	config_get_bool bind_device "$section" "bind_device" "0"
 	config_get bind_device_name "$section" "bind_device_name" "${lan_device}"
-	[ ! -z "$bind_device_name" ] && [ "$bind_device" = "1" ] && device="@${bind_device_name}"
+	[ ! -z "$bind_device_name" ] && [ "$bind_device" = "1" ] && device="${bind_device_name}"
 
+	config_get_bool "seconddns_tcp_server" "$section" "seconddns_tcp_server" "1"
 	config_get ipv6_server "$section" "ipv6_server" "1"
-	if [ "$ipv6_server" = "1" ]; then
-		ADDR="[::]"
-	else
-		ADDR=""
-	fi
 
-	conf_append "bind" "$ADDR:$seconddns_port$device $ARGS"
-	[ ! -z "$device" ] && conf_append "bind" "$ADDR:$seconddns_port@lo $ARGS"
-	config_get_bool "seconddns_tcp_server" "$section" "seconddns_tcp_server" "1"
-	[ "$seconddns_tcp_server" = "1" ] && conf_append "bind-tcp" "$ADDR:$seconddns_port$device $ARGS"
-	[ "$seconddns_tcp_server" = "1" ] && [ ! -z "$device" ] && conf_append "bind-tcp" "$ADDR:$seconddns_port@lo $ARGS"
+	conf_append_bind "$seconddns_port" "$device" "$seconddns_tcp_server" "$ipv6_server" "$ARGS"
 }
 
 conf_append_conf_files()
@@ -506,7 +532,7 @@ load_service()
 
 	config_get_bool bind_device "$section" "bind_device" "0"
 	config_get bind_device_name "$section" "bind_device_name" "${lan_device}"
-	[ ! -z "$bind_device_name" ] && [ "$bind_device" = "1" ] && device="@${bind_device_name}"
+	[ ! -z "$bind_device_name" ] && [ "$bind_device" = "1" ] && device="${bind_device_name}"
 	
 	config_get redirect "$section" "redirect" ""
 	config_get old_port "$section" "old_port" "0"
@@ -574,23 +600,7 @@ load_service()
 		[ "$auto_set_dnsmasq" = "0" ] && [ "$old_auto_set_dnsmasq" = "1" ] && stop_forward_dnsmasq "$old_port" "0"
 	}
 
-	if [ "$ipv6_server" = "1" ]; then
-		conf_append "bind" "[::]:$port$device"
-		[ ! -z "$device" ] && conf_append "bind" "[::]:$port@lo"
-	else
-		conf_append "bind" ":$port$device"
-		[ ! -z "$device" ] && conf_append "bind" ":$port@lo"
-	fi
-
-	[ "$tcp_server" = "1" ] && {
-		if [ "$ipv6_server" = "1" ]; then
-			conf_append "bind-tcp" "[::]:$port$device"
-			[ ! -z "$device" ] && conf_append "bind-tcp" "[::]:$port@lo"
-		else
-			conf_append "bind-tcp" ":$port$device"
-			[ ! -z "$device" ] && conf_append "bind-tcp" ":$port@lo"
-		fi
-	}
+	conf_append_bind "$port" "$device" "$tcp_server" "$ipv6_server" "$ARGS"
 
 	load_second_server $section
 

+ 1 - 1
src/dns_client.c

@@ -1715,7 +1715,7 @@ static int _dns_client_create_socket_udp_proxy(struct dns_server_info *server_in
 
 	ret = proxy_conn_connect(proxy);
 	if (ret != 0) {
-		if (errno == ENETUNREACH) {
+		if (errno == ENETUNREACH || errno == EHOSTUNREACH || errno == EPERM || errno == EACCES) {
 			tlog(TLOG_DEBUG, "connect %s failed, %s", server_info->ip, strerror(errno));
 			goto errout;
 		}

+ 8 - 5
src/dns_server.c

@@ -327,7 +327,6 @@ static int _dns_server_epoll_ctl(struct dns_server_conn_head *head, int op, uint
 	event.data.ptr = head;
 
 	if (epoll_ctl(server.epoll_fd, op, head->fd, &event) != 0) {
-		tlog(TLOG_ERROR, "epoll ctl failed, fd = %d, %s", head->fd, strerror(errno));
 		return -1;
 	}
 
@@ -1002,7 +1001,7 @@ static int _dns_server_reply_udp(struct dns_request *request, struct dns_server_
 use_send:
 	send_len = sendto(udpserver->head.fd, inpacket, inpacket_len, 0, &request->addr, request->addr_len);
 	if (send_len != inpacket_len) {
-		tlog(TLOG_ERROR, "send failed, %s", strerror(errno));
+		tlog(TLOG_DEBUG, "send failed, %s", strerror(errno));
 		return -1;
 	}
 
@@ -4775,6 +4774,10 @@ static int _dns_server_tcp_recv(struct dns_server_conn_tcp_client *tcpclient)
 			if (errno == EAGAIN) {
 				return RECV_ERROR_AGAIN;
 			}
+			
+			if (errno == ECONNRESET) {
+				return RECV_ERROR_CLOSE;
+			}
 
 			tlog(TLOG_ERROR, "recv failed, %s\n", strerror(errno));
 			return RECV_ERROR_FAIL;
@@ -4916,7 +4919,7 @@ static int _dns_server_process_tcp(struct dns_server_conn_tcp_client *dnsserver,
 			if (ret == RECV_ERROR_CLOSE) {
 				return 0;
 			}
-			tlog(TLOG_ERROR, "process tcp request failed.");
+			tlog(TLOG_DEBUG, "process tcp request failed.");
 			return RECV_ERROR_FAIL;
 		}
 	}
@@ -4924,7 +4927,7 @@ static int _dns_server_process_tcp(struct dns_server_conn_tcp_client *dnsserver,
 	if (event->events & EPOLLOUT) {
 		if (_dns_server_tcp_send(dnsserver) != 0) {
 			_dns_server_client_close(&dnsserver->head);
-			tlog(TLOG_ERROR, "send tcp failed.");
+			tlog(TLOG_DEBUG, "send tcp failed.");
 			return RECV_ERROR_FAIL;
 		}
 	}
@@ -4948,7 +4951,7 @@ static int _dns_server_process(struct dns_server_conn_head *conn, struct epoll_e
 		ret = _dns_server_process_tcp(tcpclient, event, now);
 		if (ret != 0) {
 			char name[DNS_MAX_CNAME_LEN];
-			tlog(TLOG_ERROR, "process TCP packet from %s failed.",
+			tlog(TLOG_DEBUG, "process TCP packet from %s failed.",
 				 gethost_by_addr(name, sizeof(name), (struct sockaddr *)&tcpclient->addr));
 		}
 	} else if (conn->type == DNS_CONN_TYPE_TLS_SERVER) {

+ 1 - 1
src/fast_ping.c

@@ -525,7 +525,7 @@ static int _fast_ping_sendping_v6(struct ping_host_struct *ping_host)
 			goto errout;
 		}
 
-		if (errno == EACCES) {
+		if (errno == EACCES || errno == EPERM) {
 			if (bool_print_log == 0) {
 				goto errout;
 			}