Skip to content

Commit

Permalink
openwrt: allow bind to multiple addrs and ports
Browse files Browse the repository at this point in the history
We could have more than the second bind port.
  • Loading branch information
hizukiayaka committed Nov 9, 2024
1 parent 9e2e200 commit 26763e8
Showing 1 changed file with 78 additions and 4 deletions.
82 changes: 78 additions & 4 deletions package/openwrt/files/etc/init.d/smartdns
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,79 @@ load_second_server()
[ "$seconddns_tcp_server" = "1" ] && conf_append_bind "bind-tcp" "$seconddns_port" "$device" "$ipv6_server" "$ARGS"
}

load_second_service()
{
local section="$1"
local server_flags=""
local ADDR=""
local device=""

config_get_bool enabled "$section" "enabled" "0"
[ "$enabled" = "0" ] && return

config_get port "$section" "port" "6553"

config_get_bool no_speed_check "$section" "no_speed_check" "0"
[ "$no_speed_check" = "1" ] && server_flags="$server_flags -no-speed-check"

config_get server_group "$section" "server_group" ""
[ -z "$server_group" ] || server_flags="$server_flags -group $server_group"

config_get_bool no_rule_addr "$section" "no_rule_addr" "0"
[ "$no_rule_addr" = "1" ] && server_flags="$server_flags -no-rule-addr"

config_get_bool no_rule_nameserver "$section" "no_rule_nameserver" "0"
[ "$no_rule_nameserver" = "1" ] && server_flags="$server_flags -no-rule-nameserver"

config_get_bool no_rule_ipset "$section" "no_rule_ipset" "0"
[ "$no_rule_ipset" = "1" ] && server_flags="$server_flags -no-rule-ipset"

config_get_bool no_rule_soa "$section" "no_rule_soa" "0"
[ "$no_rule_soa" = "1" ] && server_flags="$server_flags -no-rule-soa"

config_get_bool no_dualstack_selection "$section" "no_dualstack_selection" "0"
[ "$no_dualstack_selection" = "1" ] && server_flags="$server_flags -no-dualstack-selection"

config_get_bool no_cache "$section" "no_cache" "0"
[ "$no_cache" = "1" ] && server_flags="$server_flags -no-cache"

config_get_bool force_aaaa_soa "$section" "force_aaaa_soa" "0"
[ "$force_aaaa_soa" = "1" ] && server_flags="$server_flags -force-aaaa-soa"

config_get_bool force_https_soa "$section" "force_https_soa" "0"
[ "$force_https_soa" = "1" ] && server_flags="$server_flags -force-https-soa"

config_get_bool no_ip_alias "$section" "no_ip_alias" "0"
[ "$no_ip_alias" = "1" ] && server_flags="$server_flags -no-ip-alias"

config_get ipset_name "$section" "ipset_name" ""
[ -z "$ipset_name" ] || server_flags="$server_flags -ipset $ipset_name"

config_get nftset_name "$section" "nftset_name" ""
[ -z "$nftset_name" ] || server_flags="$server_flags -nftset $nftset_name"

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}"
config_get bind_interfaces "$section" "bind_interface" ""

config_get_bool "tcp_server" "$section" "tcp_server" "1"
config_get ipv6_server "$section" "ipv6_server" "1"

config_get server_flags "$section" "server_flags" ""
[ -z "$server_flags" ] || server_flags="$server_flags $server_flags"
local __conf_bind_func
if [ ! -z $bind_interfaces ]; then
__conf_bind_func="conf_append_bind_interface"
device=${bind_interfaces}
else
__conf_bind_func="conf_append_bind"
fi

$__conf_bind_func "bind" "$port" "$device" "$ipv6_server" "$server_flags"
[ "$tcp_server" = "1" ] && $__conf_bind_func "bind-tcp" "$port" "$device" "$ipv6_server" "$server_flags"
}

conf_append_conf_files()
{
local conf_file="$1"
Expand Down Expand Up @@ -692,7 +765,7 @@ load_service()
[ ! -z "$speed_check_mode" ] && conf_append "speed-check-mode" "$speed_check_mode"

config_get dualstack_ip_selection "$section" "dualstack_ip_selection" "0"
[ "$dualstack_ip_selection" = "0" ] && conf_append "dualstack-ip-selection" "no"
[ "$dualstack_ip_selection" = "0" ] && server_flags="$server_flags -no-dualstack-selection"

config_get prefetch_domain "$section" "prefetch_domain" "0"
[ "$prefetch_domain" = "1" ] && conf_append "prefetch-domain" "yes"
Expand All @@ -707,10 +780,10 @@ load_service()
[ "$resolve_local_hostnames" = "1" ] && conf_append "dnsmasq-lease-file" "$dnsmasq_lease_file"

config_get force_aaaa_soa "$section" "force_aaaa_soa" "0"
[ "$force_aaaa_soa" = "1" ] && qtype_soa_list="$qtype_soa_list 28"
[ "$force_aaaa_soa" = "1" ] && server_flags="$server_flags -force-aaaa-soa"

config_get force_https_soa "$section" "force_https_soa" "1"
[ "$force_https_soa" = "1" ] && qtype_soa_list="$qtype_soa_list 65"
config_get force_https_soa "$section" "force_https_soa" "0"
[ "$force_https_soa" = "1" ] && server_flags="$server_flags -force-https-soa"

config_get auto_set_dnsmasq "$section" "auto_set_dnsmasq" "1"

Expand Down Expand Up @@ -885,6 +958,7 @@ load_service()
[ ! -z "$bind_cert_key_pass" ] && conf_append "bind-cert-key-pass" "$bind_cert_key_pass"

load_second_server "$section"
config_foreach load_second_service "service"

config_foreach load_server "server"

Expand Down

0 comments on commit 26763e8

Please sign in to comment.