Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Tianling Shen <cnsztl@immortalwrt.org>
- Loading branch information
1 parent
0bf98f5
commit fdc0f84
Showing
3 changed files
with
165 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
|
||
# For documents, please see https://github.com/AdguardTeam/dnsproxy#usage | ||
|
||
config dnsproxy 'global' | ||
option enabled '0' | ||
option listen_addr '127.0.0.1' | ||
option listen_port '5353' | ||
option log_file '' | ||
option all_servers '0' | ||
option fastest_addr '0' | ||
option insecure '0' | ||
option ipv6_disabled '0' | ||
option max_go_routines '' | ||
option rate_limit '' | ||
option refuse_any '0' | ||
option udp_buf_size '' | ||
option verbose '0' | ||
|
||
config dnsproxy 'bogus_nxdomain' | ||
list ip_addr '' | ||
|
||
config dnsproxy 'cache' | ||
option enabled '0' | ||
option cache_optimistic '0' | ||
option size '65535' | ||
option min_ttl '' | ||
option max_ttl '' | ||
|
||
config dnsproxy 'dns64' | ||
option enabled '0' | ||
option dns64_prefix '64:ff9b::' | ||
|
||
config dnsproxy 'edns' | ||
option enabled '0' | ||
option edns_addr '' | ||
|
||
config dnsproxy 'servers' | ||
list bootstrap 'tls://8.8.8.8' | ||
list fallback 'tls://9.9.9.9' | ||
list upstream 'tls://1.1.1.1' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
#!/bin/sh /etc/rc.common | ||
# Copyright (C) 2021 Tianling Shen <cnsztl@immortalwrt.org> | ||
|
||
USE_PROCD=1 | ||
START=90 | ||
|
||
CONF="dnsproxy" | ||
PROG="/usr/bin/dnsproxy" | ||
|
||
is_enabled() { | ||
local enabled | ||
config_get enabled "$1" "$2" "0" | ||
if [ "$enabled" -eq "1" ]; then | ||
return 0 | ||
else | ||
return 1 | ||
fi | ||
} | ||
|
||
is_empty() { | ||
local empty | ||
config_get empty "$1" "$2" $3 | ||
if [ -z "$empty" ]; then | ||
return 0 | ||
else | ||
return 1 | ||
fi | ||
} | ||
|
||
append_param() { | ||
procd_append_param command "$1" $2 | ||
} | ||
|
||
append_param_arg() { | ||
local value | ||
config_get value "$1" "$2" $4 | ||
[ -n "$value" ] && append_param "$3" "$value" | ||
} | ||
|
||
append_param_bool() { | ||
is_enabled "$1" "$2" && append_param "--${2//_/-}" | ||
} | ||
|
||
load_config_arg() { | ||
append_param_bool "$1" "all_servers" | ||
append_param_bool "$1" "fastest_addr" | ||
append_param_bool "$1" "insecure" | ||
append_param_bool "$1" "ipv6_disabled" | ||
append_param_bool "$1" "refuse_any" | ||
append_param_bool "$1" "verbose" | ||
} | ||
|
||
load_config_list() { | ||
is_empty "bogus_nxdomain" "ip_addr" || config_list_foreach "bogus_nxdomain" "ip_addr" "append_param '--bogus-nxdomain'" | ||
|
||
for i in "bootstrap" "fallback" "upstream"; do | ||
is_empty "servers" "$i" || config_list_foreach "servers" "$i" "append_param '--$i'" | ||
done | ||
} | ||
|
||
load_config_param() { | ||
append_param_arg "global" "listen_addr" "--listen" "127.0.0.1" | ||
append_param_arg "global" "listen_port" "--port" "5353" | ||
append_param_arg "global" "log_file" "--output" | ||
append_param_arg "global" "max_go_routines" "--max-go-routines" | ||
append_param_arg "global" "rate_limit" "--ratelimit" | ||
append_param_arg "global" "udp_buf_size" "--udp-buf-size" | ||
|
||
is_enabled "cache" "enabled" && { | ||
append_param "--cache" | ||
append_param_bool "cache" "cache_optimistic" | ||
append_param_arg "cache" "size" "--cache-size" | ||
append_param_arg "cache" "min_ttl" "--cache-min-ttl" | ||
append_param_arg "cache" "max_ttl" "--cache-max-ttl" | ||
} | ||
|
||
is_enabled "dns64" "enabled" && { | ||
append_param "--dns64" | ||
append_param_arg "dns64" "dns64_prefix" "--dns64-prefix" | ||
} | ||
|
||
is_enabled "edns" "enabled" && { | ||
append_param "--edns" | ||
append_param_arg "edns" "edns_addr" "--edns-addr" | ||
} | ||
} | ||
|
||
start_service() { | ||
config_load "$CONF" | ||
|
||
is_enabled "global" "enabled" || exit 1 | ||
|
||
procd_open_instance "$CONF" | ||
procd_set_param command "$PROG" | ||
|
||
load_config_arg "global" | ||
load_config_list | ||
load_config_param | ||
|
||
procd_set_param respawn | ||
procd_set_param stdout 1 | ||
procd_set_param stderr 1 | ||
procd_set_param user dnsproxy | ||
|
||
procd_close_instance | ||
} | ||
|
||
reload_service() { | ||
stop | ||
start | ||
} | ||
|
||
service_triggers() { | ||
procd_add_reload_trigger "$CONF" | ||
} |