update 2022-10-02 23:46:41
This commit is contained in:
parent
ae738eb342
commit
1ce2e5068d
|
@ -5,12 +5,12 @@
|
|||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=brook
|
||||
PKG_VERSION:=20220707
|
||||
PKG_VERSION:=20221010
|
||||
PKG_RELEASE:=$(AUTORELEASE)
|
||||
|
||||
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
|
||||
PKG_SOURCE_URL:=https://codeload.github.com/txthinking/brook/tar.gz/v$(PKG_VERSION)?
|
||||
PKG_HASH:=377d6be82a8e122cc2e1c87ea10d2f404be6e4cf85304f329b01654e8f551753
|
||||
PKG_HASH:=987b2ddac349e5ac2b91b40b06f7686dcf316c37bfe82c566fdc7503f0b4d97d
|
||||
|
||||
PKG_MAINTAINER:=Tianling Shen <cnsztl@immortalwrt.org>
|
||||
PKG_LICENSE:=GPL-3.0
|
||||
|
|
|
@ -26,9 +26,9 @@ function act_status()
|
|||
end
|
||||
|
||||
function get_log()
|
||||
luci.http.write(luci.sys.exec("[ -f $(uci -q get mosdns.mosdns.logfile) ] && cat $(uci -q get mosdns.mosdns.logfile)"))
|
||||
luci.http.write(luci.sys.exec("cat $(/etc/mosdns/library.sh logfile)"))
|
||||
end
|
||||
|
||||
function clear_log()
|
||||
luci.sys.call("cat /dev/null > $(uci -q get mosdns.mosdns.logfile)")
|
||||
luci.sys.call("cat /dev/null > $(/etc/mosdns/library.sh logfile)")
|
||||
end
|
||||
|
|
|
@ -100,6 +100,9 @@ msgstr "内置预设"
|
|||
msgid "Cus Config"
|
||||
msgstr "自定义配置"
|
||||
|
||||
msgid "Log Level"
|
||||
msgstr "日志级别"
|
||||
|
||||
msgid "MosDNS Log File"
|
||||
msgstr "日志文件"
|
||||
|
||||
|
|
|
@ -106,7 +106,7 @@ start_service() {
|
|||
delcron
|
||||
setcron
|
||||
adblock
|
||||
cat /dev/null > $(uci -q get mosdns.mosdns.logfile)
|
||||
cat /dev/null > $(/etc/mosdns/library.sh logfile)
|
||||
sysctl -w net.core.rmem_max=2500000
|
||||
v4config
|
||||
procd_open_instance mosdns
|
||||
|
|
|
@ -1,4 +1,15 @@
|
|||
#!/bin/bash
|
||||
|
||||
logfile_path() (
|
||||
configfile=$(uci -q get mosdns.mosdns.configfile)
|
||||
if [ "$configfile" = "./def_config.yaml" ]; then
|
||||
uci -q get mosdns.mosdns.logfile
|
||||
else
|
||||
[ ! -f /etc/mosdns/cus_config.yaml ] && exit 1
|
||||
cat /etc/mosdns/cus_config.yaml | grep -A 4 log | grep file | awk -F ":" '{print $2}' | sed 's/\"//g;s/ //g'
|
||||
fi
|
||||
)
|
||||
|
||||
bakdns() {
|
||||
if [ "$1" == "0" ]; then
|
||||
echo "119.29.29.29"
|
||||
|
@ -43,3 +54,7 @@ L_exist() {
|
|||
uci get vssr.@global[0].global_server &>/dev/null
|
||||
fi
|
||||
}
|
||||
|
||||
if [ "$1" == "logfile" ]; then
|
||||
logfile_path
|
||||
fi
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -10,12 +10,12 @@ PKG_VERSION:=4.55
|
|||
PKG_RELEASE:=1
|
||||
|
||||
PKG_CONFIG_DEPENDS:= \
|
||||
CONFIG_PACKAGE_$(PKG_NAME)_Transparent_Proxy \
|
||||
CONFIG_PACKAGE_$(PKG_NAME)_Iptables_Transparent_Proxy \
|
||||
CONFIG_PACKAGE_$(PKG_NAME)_Nftables_Transparent_Proxy \
|
||||
CONFIG_PACKAGE_$(PKG_NAME)_INCLUDE_Brook \
|
||||
CONFIG_PACKAGE_$(PKG_NAME)_INCLUDE_ChinaDNS_NG \
|
||||
CONFIG_PACKAGE_$(PKG_NAME)_INCLUDE_Haproxy \
|
||||
CONFIG_PACKAGE_$(PKG_NAME)_INCLUDE_Hysteria \
|
||||
CONFIG_PACKAGE_$(PKG_NAME)_INCLUDE_IPv6_Nat \
|
||||
CONFIG_PACKAGE_$(PKG_NAME)_INCLUDE_NaiveProxy \
|
||||
CONFIG_PACKAGE_$(PKG_NAME)_INCLUDE_Shadowsocks_Libev_Client \
|
||||
CONFIG_PACKAGE_$(PKG_NAME)_INCLUDE_Shadowsocks_Libev_Server \
|
||||
|
@ -40,7 +40,6 @@ LUCI_DEPENDS:=+coreutils +coreutils-base64 +coreutils-nohup +curl \
|
|||
+PACKAGE_$(PKG_NAME)_INCLUDE_ChinaDNS_NG:chinadns-ng \
|
||||
+PACKAGE_$(PKG_NAME)_INCLUDE_Haproxy:haproxy \
|
||||
+PACKAGE_$(PKG_NAME)_INCLUDE_Hysteria:hysteria \
|
||||
+PACKAGE_$(PKG_NAME)_INCLUDE_IPv6_Nat:ip6tables-mod-nat \
|
||||
+PACKAGE_$(PKG_NAME)_INCLUDE_NaiveProxy:naiveproxy \
|
||||
+PACKAGE_$(PKG_NAME)_INCLUDE_Shadowsocks_Libev_Client:shadowsocks-libev-ss-local \
|
||||
+PACKAGE_$(PKG_NAME)_INCLUDE_Shadowsocks_Libev_Client:shadowsocks-libev-ss-redir \
|
||||
|
@ -61,8 +60,8 @@ LUCI_DEPENDS:=+coreutils +coreutils-base64 +coreutils-nohup +curl \
|
|||
define Package/$(PKG_NAME)/config
|
||||
menu "Configuration"
|
||||
|
||||
config PACKAGE_$(PKG_NAME)_Transparent_Proxy
|
||||
bool "Transparent Proxy"
|
||||
config PACKAGE_$(PKG_NAME)_Iptables_Transparent_Proxy
|
||||
bool "Iptables Transparent Proxy"
|
||||
select PACKAGE_dnsmasq-full
|
||||
select PACKAGE_ipset
|
||||
select PACKAGE_ipt2socks
|
||||
|
@ -73,7 +72,16 @@ config PACKAGE_$(PKG_NAME)_Transparent_Proxy
|
|||
select PACKAGE_iptables-mod-socket
|
||||
select PACKAGE_iptables-mod-tproxy
|
||||
select PACKAGE_kmod-ipt-nat
|
||||
default y
|
||||
default y if ! PACKAGE_firewall4
|
||||
|
||||
config PACKAGE_$(PKG_NAME)_Nftables_Transparent_Proxy
|
||||
bool "Nftables Transparent Proxy"
|
||||
select PACKAGE_dnsmasq-full
|
||||
select PACKAGE_nftables
|
||||
select PACKAGE_kmod-nft-socket
|
||||
select PACKAGE_kmod-nft-tproxy
|
||||
select PACKAGE_kmod-nft-nat
|
||||
default y if PACKAGE_firewall4
|
||||
|
||||
config PACKAGE_$(PKG_NAME)_INCLUDE_Brook
|
||||
bool "Include Brook"
|
||||
|
@ -81,7 +89,8 @@ config PACKAGE_$(PKG_NAME)_INCLUDE_Brook
|
|||
|
||||
config PACKAGE_$(PKG_NAME)_INCLUDE_ChinaDNS_NG
|
||||
bool "Include ChinaDNS-NG"
|
||||
default y
|
||||
select PACKAGE_ipset
|
||||
default n
|
||||
|
||||
config PACKAGE_$(PKG_NAME)_INCLUDE_Haproxy
|
||||
bool "Include Haproxy"
|
||||
|
@ -91,11 +100,6 @@ config PACKAGE_$(PKG_NAME)_INCLUDE_Hysteria
|
|||
bool "Include Hysteria"
|
||||
default n
|
||||
|
||||
config PACKAGE_$(PKG_NAME)_INCLUDE_IPv6_Nat
|
||||
depends on PACKAGE_ip6tables
|
||||
bool "Include IPv6 Nat"
|
||||
default n
|
||||
|
||||
config PACKAGE_$(PKG_NAME)_INCLUDE_NaiveProxy
|
||||
bool "Include NaiveProxy"
|
||||
depends on !(arc||(arm&&TARGET_gemini)||armeb||mips||mips64||powerpc)
|
||||
|
|
|
@ -95,7 +95,7 @@ o.default = "1:65535"
|
|||
o:value("1:65535", translate("All"))
|
||||
o:value("53", "DNS")
|
||||
|
||||
if os.execute("lsmod | grep -i REDIRECT >/dev/null") == 0 and os.execute("lsmod | grep -i TPROXY >/dev/null") == 0 then
|
||||
if (os.execute("lsmod | grep -i REDIRECT >/dev/null") == 0 and os.execute("lsmod | grep -i TPROXY >/dev/null") == 0) or (os.execute("lsmod | grep -i nft_redir >/dev/null") == 0 and os.execute("lsmod | grep -i nft_tproxy >/dev/null") == 0) then
|
||||
o = s:option(ListValue, "tcp_proxy_way", translate("TCP Proxy Way"))
|
||||
o.default = "redirect"
|
||||
o:value("redirect", "REDIRECT")
|
||||
|
@ -110,7 +110,7 @@ if os.execute("lsmod | grep -i REDIRECT >/dev/null") == 0 and os.execute("lsmod
|
|||
return self.map:set(section, "tcp_proxy_way", value)
|
||||
end
|
||||
|
||||
if os.execute("lsmod | grep -i ip6table_mangle >/dev/null") == 0 then
|
||||
if os.execute("lsmod | grep -i ip6table_mangle >/dev/null") == 0 or os.execute("lsmod | grep -i nft_tproxy >/dev/null") == 0 then
|
||||
---- IPv6 TProxy
|
||||
o = s:option(Flag, "ipv6_tproxy", translate("IPv6 TProxy"),
|
||||
"<font color='red'>" .. translate(
|
||||
|
|
|
@ -1149,7 +1149,7 @@ start_dns() {
|
|||
smartdns)
|
||||
local group_domestic=$(config_t_get global group_domestic)
|
||||
CHINADNS_NG=0
|
||||
source $APP_PATH/helper_smartdns.sh add FLAG="default" DNS_MODE=$DNS_MODE SMARTDNS_CONF=/tmp/etc/smartdns/$CONFIG.conf REMOTE_FAKEDNS=$fakedns DEFAULT_DNS=$DEFAULT_DNS LOCAL_GROUP=$group_domestic TUN_DNS=$TUN_DNS TCP_NODE=$TCP_NODE PROXY_MODE=${TCP_PROXY_MODE}${LOCALHOST_TCP_PROXY_MODE}${ACL_TCP_PROXY_MODE} NO_PROXY_IPV6=${filter_proxy_ipv6}
|
||||
source $APP_PATH/helper_smartdns.sh add FLAG="default" DNS_MODE=$DNS_MODE SMARTDNS_CONF=/tmp/etc/smartdns/$CONFIG.conf REMOTE_FAKEDNS=$fakedns DEFAULT_DNS=$DEFAULT_DNS LOCAL_GROUP=$group_domestic TUN_DNS=$TUN_DNS TCP_NODE=$TCP_NODE PROXY_MODE=${TCP_PROXY_MODE}${LOCALHOST_TCP_PROXY_MODE}${ACL_TCP_PROXY_MODE} NO_PROXY_IPV6=${filter_proxy_ipv6} NFTFLAG=${nftflag}
|
||||
source $APP_PATH/helper_smartdns.sh restart
|
||||
echolog " - 域名解析:使用SmartDNS,请确保配置正常。"
|
||||
;;
|
||||
|
@ -1184,7 +1184,7 @@ start_dns() {
|
|||
|
||||
[ "$DNS_SHUNT" = "dnsmasq" ] && {
|
||||
source $APP_PATH/helper_dnsmasq.sh stretch
|
||||
source $APP_PATH/helper_dnsmasq.sh add FLAG="default" DNS_MODE=$DNS_MODE TMP_DNSMASQ_PATH=$TMP_DNSMASQ_PATH DNSMASQ_CONF_FILE=/tmp/dnsmasq.d/dnsmasq-passwall.conf REMOTE_FAKEDNS=$fakedns DEFAULT_DNS=$DEFAULT_DNS LOCAL_DNS=$LOCAL_DNS TUN_DNS=$TUN_DNS CHINADNS_DNS=$china_ng_listen TCP_NODE=$TCP_NODE PROXY_MODE=${TCP_PROXY_MODE}${LOCALHOST_TCP_PROXY_MODE}${ACL_TCP_PROXY_MODE} NO_PROXY_IPV6=${filter_proxy_ipv6}
|
||||
source $APP_PATH/helper_dnsmasq.sh add FLAG="default" DNS_MODE=$DNS_MODE TMP_DNSMASQ_PATH=$TMP_DNSMASQ_PATH DNSMASQ_CONF_FILE=/tmp/dnsmasq.d/dnsmasq-passwall.conf REMOTE_FAKEDNS=$fakedns DEFAULT_DNS=$DEFAULT_DNS LOCAL_DNS=$LOCAL_DNS TUN_DNS=$TUN_DNS CHINADNS_DNS=$china_ng_listen TCP_NODE=$TCP_NODE PROXY_MODE=${TCP_PROXY_MODE}${LOCALHOST_TCP_PROXY_MODE}${ACL_TCP_PROXY_MODE} NO_PROXY_IPV6=${filter_proxy_ipv6} NFTFLAG=${nftflag}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1348,9 +1348,22 @@ start() {
|
|||
ulimit -n 65535
|
||||
start_haproxy
|
||||
start_socks
|
||||
nftflag=0
|
||||
|
||||
[ "$NO_PROXY" == 1 ] || {
|
||||
if [ -z "$(command -v iptables-legacy || command -v iptables)" ] || [ -z "$(command -v ipset)" ]; then
|
||||
if [ -n "$(command -v fw4)" ] && [ -z "$(dnsmasq --version | grep 'nftset')" ]; then
|
||||
echolog "检测到fw4防火墙,但Dnsmasq软件包不满足nftables透明代理要求,如需使用请确保dnsmasq版本在2.87以上并开启nftset支持。"
|
||||
fi
|
||||
|
||||
if [ -n "$(command -v fw4)" ] && [ -n "$(dnsmasq --version | grep 'nftset')" ]; then
|
||||
echolog "检测fw4防火墙,使用nftables进行透明代理,一些不支持nftables的组件如smartdns分流等将不可用。"
|
||||
nftflag=1
|
||||
start_redir TCP
|
||||
start_redir UDP
|
||||
start_dns
|
||||
source $APP_PATH/nftables.sh start
|
||||
source $APP_PATH/helper_${DNS_N}.sh logic_restart
|
||||
elif [ -z "$(command -v iptables-legacy || command -v iptables)" ] || [ -z "$(command -v ipset)" ]; then
|
||||
echolog "系统未安装iptables或ipset,无法透明代理!"
|
||||
else
|
||||
start_redir TCP
|
||||
|
@ -1366,7 +1379,7 @@ start() {
|
|||
|
||||
stop() {
|
||||
clean_log
|
||||
source $APP_PATH/iptables.sh stop
|
||||
[ -n "$(command -v fw4)" ] && [ -n "$(dnsmasq --version | grep 'nftset')" ] && source $APP_PATH/nftables.sh stop || source $APP_PATH/iptables.sh stop
|
||||
delete_ip2route
|
||||
kill_all v2ray-plugin obfs-local
|
||||
pgrep -f "sleep.*(6s|9s|58s)" | xargs kill -9 >/dev/null 2>&1
|
||||
|
|
|
@ -65,9 +65,9 @@ restart() {
|
|||
}
|
||||
|
||||
add() {
|
||||
local FLAG TMP_DNSMASQ_PATH DNSMASQ_CONF_FILE DEFAULT_DNS LOCAL_DNS TUN_DNS REMOTE_FAKEDNS CHINADNS_DNS TCP_NODE PROXY_MODE NO_PROXY_IPV6 NO_LOGIC_LOG
|
||||
local FLAG TMP_DNSMASQ_PATH DNSMASQ_CONF_FILE DEFAULT_DNS LOCAL_DNS TUN_DNS REMOTE_FAKEDNS CHINADNS_DNS TCP_NODE PROXY_MODE NO_PROXY_IPV6 NO_LOGIC_LOG NFTFLAG
|
||||
eval_set_val $@
|
||||
lua $APP_PATH/helper_dnsmasq_add.lua -FLAG $FLAG -TMP_DNSMASQ_PATH $TMP_DNSMASQ_PATH -DNSMASQ_CONF_FILE $DNSMASQ_CONF_FILE -DEFAULT_DNS $DEFAULT_DNS -LOCAL_DNS $LOCAL_DNS -TUN_DNS $TUN_DNS -REMOTE_FAKEDNS ${REMOTE_FAKEDNS:-0} -CHINADNS_DNS ${CHINADNS_DNS:-0} -TCP_NODE $TCP_NODE -PROXY_MODE $PROXY_MODE -NO_PROXY_IPV6 ${NO_PROXY_IPV6:-0} -NO_LOGIC_LOG ${NO_LOGIC_LOG:-0}
|
||||
lua $APP_PATH/helper_dnsmasq_add.lua -FLAG $FLAG -TMP_DNSMASQ_PATH $TMP_DNSMASQ_PATH -DNSMASQ_CONF_FILE $DNSMASQ_CONF_FILE -DEFAULT_DNS $DEFAULT_DNS -LOCAL_DNS $LOCAL_DNS -TUN_DNS $TUN_DNS -REMOTE_FAKEDNS ${REMOTE_FAKEDNS:-0} -CHINADNS_DNS ${CHINADNS_DNS:-0} -TCP_NODE $TCP_NODE -PROXY_MODE $PROXY_MODE -NO_PROXY_IPV6 ${NO_PROXY_IPV6:-0} -NO_LOGIC_LOG ${NO_LOGIC_LOG:-0} -NFTFLAG ${NFTFLAG}
|
||||
}
|
||||
|
||||
del() {
|
||||
|
|
|
@ -14,6 +14,7 @@ local TCP_NODE = var["-TCP_NODE"]
|
|||
local PROXY_MODE = var["-PROXY_MODE"]
|
||||
local NO_PROXY_IPV6 = var["-NO_PROXY_IPV6"]
|
||||
local NO_LOGIC_LOG = var["-NO_LOGIC_LOG"]
|
||||
local NFTFLAG = var["-NFTFLAG"]
|
||||
local LOG_FILE = api.LOG_FILE
|
||||
local CACHE_PATH = api.CACHE_PATH
|
||||
local CACHE_FLAG = "dns_" .. FLAG
|
||||
|
@ -165,8 +166,9 @@ end
|
|||
local dnsmasq_default_dns
|
||||
|
||||
local cache_text = ""
|
||||
local subscribe_proxy=uci:get(appname, "@global_subscribe[0]", "subscribe_proxy") or "0"
|
||||
local new_rules = luci.sys.exec("echo -n $(find /usr/share/passwall/rules -type f | xargs md5sum)")
|
||||
local new_text = TMP_DNSMASQ_PATH .. DNSMASQ_CONF_FILE .. DEFAULT_DNS .. LOCAL_DNS .. TUN_DNS .. REMOTE_FAKEDNS .. CHINADNS_DNS .. PROXY_MODE .. NO_PROXY_IPV6 .. new_rules
|
||||
local new_text = TMP_DNSMASQ_PATH .. DNSMASQ_CONF_FILE .. DEFAULT_DNS .. LOCAL_DNS .. TUN_DNS .. REMOTE_FAKEDNS .. CHINADNS_DNS .. PROXY_MODE .. NO_PROXY_IPV6 .. subscribe_proxy .. new_rules
|
||||
if fs.access(CACHE_TEXT_FILE) then
|
||||
for line in io.lines(CACHE_TEXT_FILE) do
|
||||
cache_text = line
|
||||
|
@ -191,6 +193,8 @@ if global and (not returnhome and not chnlist and not gfwlist) then
|
|||
only_global = 1
|
||||
end
|
||||
|
||||
local setflag= (NFTFLAG == "1") and "inet#fw4#" or ""
|
||||
|
||||
if not fs.access(CACHE_DNS_PATH) then
|
||||
fs.mkdir("/tmp/dnsmasq.d")
|
||||
fs.mkdir(CACHE_DNS_PATH)
|
||||
|
@ -223,13 +227,13 @@ if not fs.access(CACHE_DNS_PATH) then
|
|||
log(string.format(" - 域名白名单(whitelist):%s", LOCAL_DNS or "默认"))
|
||||
|
||||
local fwd_dns = LOCAL_DNS
|
||||
local ipset_flag = "whitelist,whitelist6"
|
||||
local ipset_flag = setflag.."whitelist,"..setflag.."whitelist6"
|
||||
local no_ipv6
|
||||
if uci:get(appname, "@global_subscribe[0]", "subscribe_proxy") or "0" == "1" then
|
||||
if subscribe_proxy == "1" then
|
||||
fwd_dns = TUN_DNS
|
||||
ipset_flag = "blacklist,blacklist6"
|
||||
ipset_flag = setflag.."blacklist,"..setflag.."blacklist6"
|
||||
if NO_PROXY_IPV6 == "1" then
|
||||
ipset_flag = "blacklist"
|
||||
ipset_flag = setflag.."blacklist"
|
||||
no_ipv6 = true
|
||||
end
|
||||
if not only_global then
|
||||
|
@ -254,10 +258,10 @@ if not fs.access(CACHE_DNS_PATH) then
|
|||
for line in io.lines("/usr/share/passwall/rules/proxy_host") do
|
||||
if line ~= "" and not line:find("#") then
|
||||
add_excluded_domain(line)
|
||||
local ipset_flag = "blacklist,blacklist6"
|
||||
local ipset_flag = setflag.."blacklist,"..setflag.."blacklist6"
|
||||
if NO_PROXY_IPV6 == "1" then
|
||||
set_domain_address(line, "::")
|
||||
ipset_flag = "blacklist"
|
||||
ipset_flag = setflag.."blacklist"
|
||||
end
|
||||
if REMOTE_FAKEDNS == "1" then
|
||||
ipset_flag = nil
|
||||
|
@ -285,12 +289,12 @@ if not fs.access(CACHE_DNS_PATH) then
|
|||
|
||||
if _node_id == "_direct" then
|
||||
fwd_dns = LOCAL_DNS
|
||||
ipset_flag = "whitelist,whitelist6"
|
||||
ipset_flag = setflag.."whitelist,"..setflag.."whitelist6"
|
||||
else
|
||||
fwd_dns = TUN_DNS
|
||||
ipset_flag = "shuntlist,shuntlist6"
|
||||
ipset_flag = setflag.."shuntlist,"..setflag.."shuntlist6"
|
||||
if NO_PROXY_IPV6 == "1" then
|
||||
ipset_flag = "shuntlist"
|
||||
ipset_flag = setflag.."shuntlist"
|
||||
no_ipv6 = true
|
||||
end
|
||||
if not only_global then
|
||||
|
@ -328,9 +332,9 @@ if not fs.access(CACHE_DNS_PATH) then
|
|||
local gfwlist_str = sys.exec('cat /usr/share/passwall/rules/gfwlist | grep -v -E "^#" | grep -v -E "' .. excluded_domain_str .. '"')
|
||||
for line in string.gmatch(gfwlist_str, "[^\r\n]+") do
|
||||
if line ~= "" then
|
||||
local ipset_flag = "gfwlist,gfwlist6"
|
||||
local ipset_flag = setflag.."gfwlist,"..setflag.."gfwlist6"
|
||||
if NO_PROXY_IPV6 == "1" then
|
||||
ipset_flag = "gfwlist"
|
||||
ipset_flag = setflag.."gfwlist"
|
||||
set_domain_address(line, "::")
|
||||
end
|
||||
if not only_global then
|
||||
|
@ -367,9 +371,9 @@ if not fs.access(CACHE_DNS_PATH) then
|
|||
local chnlist_str = sys.exec('cat /usr/share/passwall/rules/chnlist | grep -v -E "^#" | grep -v -E "' .. excluded_domain_str .. '"')
|
||||
for line in string.gmatch(chnlist_str, "[^\r\n]+") do
|
||||
if line ~= "" then
|
||||
local ipset_flag = "chnroute,chnroute6"
|
||||
local ipset_flag = setflag.."chnroute,"..setflag.."chnroute6"
|
||||
if NO_PROXY_IPV6 == "1" then
|
||||
ipset_flag = "chnroute"
|
||||
ipset_flag = setflag.."chnroute"
|
||||
set_domain_address(line, "::")
|
||||
end
|
||||
if not only_global then
|
||||
|
@ -388,6 +392,10 @@ if not fs.access(CACHE_DNS_PATH) then
|
|||
local address_out = io.open(CACHE_DNS_PATH .. "/000-address.conf", "a")
|
||||
local server_out = io.open(CACHE_DNS_PATH .. "/001-server.conf", "a")
|
||||
local ipset_out = io.open(CACHE_DNS_PATH .. "/ipset.conf", "a")
|
||||
local set_name = "ipset"
|
||||
if NFTFLAG == "1" then
|
||||
set_name = "nftset"
|
||||
end
|
||||
for key, value in pairs(list1) do
|
||||
if value.address and #value.address > 0 then
|
||||
address_out:write(string.format("address=/.%s/%s\n", key, value.address))
|
||||
|
@ -403,7 +411,7 @@ if not fs.access(CACHE_DNS_PATH) then
|
|||
ipsets_str = ipsets_str .. ipset .. ","
|
||||
end
|
||||
ipsets_str = ipsets_str:sub(1, #ipsets_str - 1)
|
||||
ipset_out:write(string.format("ipset=/.%s/%s\n", key, ipsets_str))
|
||||
ipset_out:write(string.format("%s=/.%s/%s\n", set_name, key, ipsets_str))
|
||||
end
|
||||
end
|
||||
address_out:close()
|
||||
|
|
|
@ -146,8 +146,9 @@ local function check_excluded_domain(domain)
|
|||
end
|
||||
|
||||
local cache_text = ""
|
||||
local subscribe_proxy=uci:get(appname, "@global_subscribe[0]", "subscribe_proxy") or "0"
|
||||
local new_rules = luci.sys.exec("echo -n $(find /usr/share/passwall/rules -type f | xargs md5sum)")
|
||||
local new_text = SMARTDNS_CONF .. LOCAL_GROUP .. REMOTE_GROUP .. REMOTE_FAKEDNS .. TUN_DNS .. PROXY_MODE .. NO_PROXY_IPV6 ..new_rules
|
||||
local new_text = SMARTDNS_CONF .. LOCAL_GROUP .. REMOTE_GROUP .. REMOTE_FAKEDNS .. TUN_DNS .. PROXY_MODE .. NO_PROXY_IPV6 .. subscribe_proxy .. new_rules
|
||||
if fs.access(CACHE_TEXT_FILE) then
|
||||
for line in io.lines(CACHE_TEXT_FILE) do
|
||||
cache_text = line
|
||||
|
@ -203,7 +204,7 @@ if not fs.access(CACHE_DNS_FILE) then
|
|||
local fwd_group = LOCAL_GROUP
|
||||
local ipset_flag = "#4:whitelist,#6:whitelist6"
|
||||
local no_ipv6
|
||||
if uci:get(appname, "@global_subscribe[0]", "subscribe_proxy") or "0" == "1" then
|
||||
if subscribe_proxy == "1" then
|
||||
fwd_group = REMOTE_GROUP
|
||||
ipset_flag = "#4:blacklist,#6:blacklist6"
|
||||
if NO_PROXY_IPV6 == "1" then
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -9,10 +9,10 @@ include $(TOPDIR)/rules.mk
|
|||
include $(INCLUDE_DIR)/kernel.mk
|
||||
|
||||
PKG_NAME:=natflow
|
||||
PKG_VERSION:=20221008
|
||||
PKG_VERSION:=20221013
|
||||
|
||||
PKG_SOURCE_URL:=https://codeload.github.com/ptpt52/natflow/tar.gz/$(PKG_VERSION)?
|
||||
PKG_HASH:=c3911f8078ca138456751d53d1fd661228ab4d25a810b8808bdd8059912250b2
|
||||
PKG_HASH:=fd9010e21ba6536c37d061e9f4fcc7bdb542f537e5e0e5aaa1a1e8914afc9b9e
|
||||
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
|
||||
|
||||
PKG_MAINTAINER:=Chen Minqiang <ptpt52@gmail.com>
|
||||
|
|
|
@ -1,130 +0,0 @@
|
|||
#
|
||||
# Copyright (C) 2017-2020 Yousong Zhou <yszhou4tech@gmail.com>
|
||||
#
|
||||
# This is free software, licensed under the GNU General Public License v2.
|
||||
# See /LICENSE for more information.
|
||||
#
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
# Checklist when bumping versions
|
||||
#
|
||||
# - update cipher list by checking src/crypto.c:crypto_init()
|
||||
# - check if default mode has changed from being tcp_only
|
||||
#
|
||||
PKG_NAME:=shadowsocks-libev
|
||||
PKG_VERSION:=3.3.5
|
||||
PKG_RELEASE:=7
|
||||
|
||||
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
|
||||
PKG_SOURCE_URL:=https://github.com/shadowsocks/shadowsocks-libev/releases/download/v$(PKG_VERSION)
|
||||
PKG_HASH:=cfc8eded35360f4b67e18dc447b0c00cddb29cc57a3cec48b135e5fb87433488
|
||||
|
||||
PKG_MAINTAINER:=Yousong Zhou <yszhou4tech@gmail.com>
|
||||
|
||||
PKG_LICENSE:=GPL-3.0-or-later
|
||||
PKG_LICENSE_FILES:=LICENSE
|
||||
|
||||
PKG_FIXUP:=autoreconf
|
||||
PKG_INSTALL:=1
|
||||
PKG_USE_MIPS16:=0
|
||||
PKG_BUILD_PARALLEL:=1
|
||||
PKG_BUILD_DEPENDS:=c-ares pcre
|
||||
|
||||
include $(INCLUDE_DIR)/package.mk
|
||||
|
||||
|
||||
define Package/shadowsocks-libev-config
|
||||
SECTION:=net
|
||||
CATEGORY:=Network
|
||||
SUBMENU:=Web Servers/Proxies
|
||||
TITLE:=shadowsocks-libev config scripts
|
||||
URL:=https://github.com/shadowsocks/shadowsocks-libev
|
||||
endef
|
||||
|
||||
define Package/shadowsocks-libev-config/conffiles
|
||||
/etc/config/shadowsocks-libev
|
||||
endef
|
||||
|
||||
define Package/shadowsocks-libev-config/install
|
||||
$(INSTALL_DIR) $(1)/etc/config
|
||||
$(INSTALL_DATA) ./files/shadowsocks-libev.config $(1)/etc/config/shadowsocks-libev
|
||||
$(INSTALL_DIR) $(1)/etc/init.d
|
||||
$(INSTALL_BIN) ./files/shadowsocks-libev.init $(1)/etc/init.d/shadowsocks-libev
|
||||
endef
|
||||
|
||||
|
||||
define Package/shadowsocks-libev/Default
|
||||
define Package/shadowsocks-libev-$(1)
|
||||
SECTION:=net
|
||||
CATEGORY:=Network
|
||||
SUBMENU:=Web Servers/Proxies
|
||||
TITLE:=shadowsocks-libev $(1)
|
||||
URL:=https://github.com/shadowsocks/shadowsocks-libev
|
||||
DEPENDS:=+libev +libmbedtls +libpthread +libsodium +shadowsocks-libev-config $(DEPENDS_$(1))
|
||||
endef
|
||||
|
||||
define Package/shadowsocks-libev-$(1)/install
|
||||
$$(INSTALL_DIR) $$(1)/usr/bin
|
||||
$$(INSTALL_BIN) $$(PKG_INSTALL_DIR)/usr/bin/$(1) $$(1)/usr/bin
|
||||
endef
|
||||
|
||||
endef
|
||||
|
||||
DEPENDS_ss-local = +libpcre
|
||||
DEPENDS_ss-server = +libcares +libpcre
|
||||
|
||||
SHADOWSOCKS_COMPONENTS:=ss-local ss-redir ss-tunnel ss-server
|
||||
define shadowsocks-libev/templates
|
||||
$(foreach component,$(SHADOWSOCKS_COMPONENTS),
|
||||
$(call Package/shadowsocks-libev/Default,$(component))
|
||||
)
|
||||
endef
|
||||
$(eval $(call shadowsocks-libev/templates))
|
||||
|
||||
|
||||
define Package/shadowsocks-libev-ss-rules
|
||||
SECTION:=net
|
||||
CATEGORY:=Network
|
||||
SUBMENU:=Web Servers/Proxies
|
||||
TITLE:=shadowsocks-libev ss-rules
|
||||
URL:=https://github.com/shadowsocks/shadowsocks-libev
|
||||
DEPENDS:=+firewall4 \
|
||||
+ip \
|
||||
+resolveip \
|
||||
+ucode \
|
||||
+ucode-mod-fs \
|
||||
+shadowsocks-libev-ss-redir \
|
||||
+shadowsocks-libev-config \
|
||||
+kmod-nft-tproxy
|
||||
endef
|
||||
|
||||
define Package/shadowsocks-libev-ss-rules/install
|
||||
$(INSTALL_DIR) $(1)/usr/share/ss-rules
|
||||
$(INSTALL_DATA) ./files/ss-rules/* $(1)/usr/share/ss-rules/
|
||||
endef
|
||||
|
||||
define Build/Prepare
|
||||
$(call Build/Prepare/Default)
|
||||
$(FIND) $(PKG_BUILD_DIR) \
|
||||
-name '*.o' \
|
||||
-o -name '*.lo' \
|
||||
-o -name '.deps' \
|
||||
-o -name '.libs' \
|
||||
| $(XARGS) rm -rvf
|
||||
endef
|
||||
|
||||
CONFIGURE_ARGS += \
|
||||
--disable-documentation \
|
||||
--disable-silent-rules \
|
||||
--disable-assert \
|
||||
--disable-ssp \
|
||||
|
||||
TARGET_CFLAGS += -flto
|
||||
TARGET_LDFLAGS += -Wl,--gc-sections,--as-needed
|
||||
|
||||
$(eval $(call BuildPackage,shadowsocks-libev-config))
|
||||
$(eval $(call BuildPackage,shadowsocks-libev-ss-rules))
|
||||
$(foreach component,$(SHADOWSOCKS_COMPONENTS), \
|
||||
$(eval $(call BuildPackage,shadowsocks-libev-$(component))) \
|
||||
)
|
|
@ -1,185 +0,0 @@
|
|||
Skip to [recipes](#recipes) for quick setup instructions
|
||||
|
||||
# components
|
||||
|
||||
`ss-local` provides SOCKS5 proxy with UDP associate support.
|
||||
|
||||
socks5 ss plain
|
||||
--------> tcp:local_address:local_port ----> ss server -------> dest
|
||||
|
||||
`ss-redir`. The REDIRECT and TPROXY part are to be provided by `ss-rules` script. REDIRECT is for tcp traffic (`SO_ORIGINAL_DST` only supports TCP). TPROXY is for udp messages, but it's only available in the PREROUTING chain and as such cannot proxy local out traffic.
|
||||
|
||||
plain plain ss plain
|
||||
---------> REDIRECT ------> tcp:local_address:local_port ----> ss server -----> original dest
|
||||
|
||||
plain plain ss plain
|
||||
---------> TPROXY -------> udp:local_address:local_port -----> ss server -----> original dest
|
||||
|
||||
`ss-tunnel` provides ssh `-L` local-forwarding-like tunnel. Typically it's used to tunnel DNS traffic to the remote.
|
||||
|
||||
plain ss plain
|
||||
---------> tcp|udp:local_address:local_port ------> ss server -------> tunnel_address
|
||||
|
||||
`ss-server`, the "ss server" in the above diagram
|
||||
|
||||
# uci
|
||||
|
||||
Option names are the same as those used in json config files. Check `validate_xxx` func definition of the [service script](files/shadowsocks-libev.init) and shadowsocks-libev's own documentation for supported options and expected value types. A [sample config file](files/shadowsocks-libev.config) is also provided for reference.
|
||||
|
||||
Every section have a `disabled` option to temporarily turn off the component instance or component instances referring to it.
|
||||
|
||||
Section type `server` is for definition of remote shadowsocks servers. They will be referred to from other component sections and as such should be named (as compared to anonymous section).
|
||||
|
||||
Section type `ss_local`, `ss_redir`, `ss_tunnel` are for specification of shadowsocks-libev components. They share mostly a common set of options like `local_port`, `verbose`, `fast_open`, `timeout`, etc.
|
||||
|
||||
Plugin options should be specified in `server` section and will be inherited by other compoenents referring to it.
|
||||
|
||||
We can have multiple instances of component and `server` sections. The relationship between them is many-to-one. This will have the following implications
|
||||
|
||||
- It's possible to have both `ss_local` and `ss_redir` referring to the same `server` definition
|
||||
- It's possible to have multiple instances of `ss_redir` listening on the same address:port with `reuse_port` enabled referring to the same or different `server` sections
|
||||
|
||||
`ss_rules` section is for configuring the behaviour of `ss-rules` script. There can only exist at most one such section with the name also being `ss_rules`
|
||||
|
||||
redir_tcp name of ss_redir section with mode tcp_only or tcp_and_udp
|
||||
redir_udp name of ss_redir section with mode udp_only or tcp_and_udp
|
||||
ifnames only apply rules on packets from these ifnames
|
||||
|
||||
--- for incoming packets having source address in
|
||||
|
||||
src_ips_bypass will bypass the redir chain
|
||||
src_ips_forward will always go through the redir chain
|
||||
src_ips_checkdst will continue to have their destination addresses checked
|
||||
|
||||
--- otherwise, the default action can be specified with
|
||||
|
||||
src_default bypass, forward, [checkdst]
|
||||
|
||||
--- if the previous check result is checkdst,
|
||||
--- then packets having destination address in
|
||||
|
||||
dst_ips_bypass_file
|
||||
dst_ips_bypass will bypass the redir chain
|
||||
dst_ips_forward_file
|
||||
dst_ips_forward will go through the redir chain
|
||||
|
||||
--- otherwise, the default action can be specified with
|
||||
|
||||
dst_default [bypass], forward
|
||||
|
||||
--- for local out tcp packets, the default action can be specified with
|
||||
|
||||
local_default [bypass], forward, checkdst
|
||||
|
||||
ss-rules now uses nft set for storing addresses/networks. Those set names are also part of the API and can be populated by other programs, e.g. dnsmasq with builtin nft set support. Note that while nftables set supports storing cidr networks when `interval` flag is on, it rejects elements with overlaping intervals.
|
||||
|
||||
Extra nftables expressions can be specified with `nft_tcp_extra` and `nft_udp_extra` to apply ss_rules only to selected tcp/udp traffics. E.g. `tcp dport { 80, 443 }`, `udp dport 53`, etc.
|
||||
|
||||
# incompatible changes
|
||||
|
||||
| Commit date | Commit ID | Subject | Comment |
|
||||
| ----------- | --------- | ------- | ------- |
|
||||
| 2022-03-01 | fdaf2de2a | shadowsocks-libev: ss-rules: convert to using nft | ss-rules now uses nftables. UCI option ipt_args and dst_forward_recentrst are now deprecated and removed |
|
||||
| 2020-08-03 | 7d7cbae75 | shadowsocks-libev: support ss-server option local_address_{v4,v6} | ss_server bind_address now deprecated, use local_address |
|
||||
| 2019-05-09 | afe7d3424 | shadowsocks-libev: move plugin options to server section | This is a revision against c19e949 committed 2019-05-06 |
|
||||
| 2017-07-02 | b61af9703 | shadowsocks-libev: rewrite | Packaging of shadowsocks-libev was rewritten from scratch |
|
||||
|
||||
# notes and faq
|
||||
|
||||
Useful paths and commands for debugging
|
||||
|
||||
# check current running status
|
||||
ubus call service list '{"name": "shadowsocks-libev"}'
|
||||
ubus call service list '{"name": "shadowsocks-libev", "verbose": true}'
|
||||
|
||||
# dump validate definition
|
||||
ubus call service validate '{"package": "shadowsocks-libev"}'
|
||||
ubus call service validate '{"package": "shadowsocks-libev"}' \
|
||||
| jsonfilter -e '$["shadowsocks-libev"]["ss_tunnel"]'
|
||||
|
||||
# check json config
|
||||
ls -l /var/etc/shadowsocks-libev/
|
||||
|
||||
# set uci config option verbose to 1, restart the service and follow the log
|
||||
logread -f
|
||||
|
||||
ss-redir needs to open a new socket and setsockopt IP_TRANSPARENT when sending udp reply to client. This requires `CAP_NET_ADMIN` and as such the process cannot run as `nobody`
|
||||
|
||||
ss-local, ss-redir, etc. supports specifying an array of remote ss server, but supporting this in uci seems to be overkill. The workaround can be defining multiple `server` sections and multiple `ss-redir` instances with `reuse_port` enabled
|
||||
|
||||
# recipes
|
||||
|
||||
## forward all
|
||||
|
||||
This will setup firewall rules to forward almost all incoming tcp/udp and locally generated tcp traffic (excluding those to private addresses like 192.168.0.0/16 etc.) through remote shadowsocks server
|
||||
|
||||
Install components.
|
||||
Retry each command till it succeed
|
||||
|
||||
opkg install shadowsocks-libev-ss-redir
|
||||
opkg install shadowsocks-libev-ss-rules
|
||||
opkg install shadowsocks-libev-ss-tunnel
|
||||
|
||||
Edit uci config `/etc/config/shadowsocks-libev`.
|
||||
Replace `config server 'sss0'` section with parameters of your own remote shadowsocks server.
|
||||
As for other options, change them only when you know the effect.
|
||||
|
||||
config server 'sss0'
|
||||
option disabled 0
|
||||
option server '_sss_addr_'
|
||||
option server_port '_sss_port_'
|
||||
option password '********'
|
||||
option method 'aes-256-cfb'
|
||||
|
||||
config ss_tunnel
|
||||
option disabled 0
|
||||
option server 'sss0'
|
||||
option local_address '0.0.0.0'
|
||||
option local_port '8053'
|
||||
option tunnel_address '8.8.8.8:53'
|
||||
option mode 'tcp_and_udp'
|
||||
|
||||
config ss_redir ssr0
|
||||
option disabled 0
|
||||
option server 'sss0'
|
||||
option local_address '0.0.0.0'
|
||||
option local_port '1100'
|
||||
option mode 'tcp_and_udp'
|
||||
option reuse_port 1
|
||||
|
||||
config ss_rules 'ss_rules'
|
||||
option disabled 0
|
||||
option redir_tcp 'ssr0'
|
||||
option redir_udp 'ssr0'
|
||||
option src_default 'checkdst'
|
||||
option dst_default 'forward'
|
||||
option local_default 'forward'
|
||||
|
||||
Restart shadowsocks-libev components
|
||||
|
||||
/etc/init.d/shadowsocks-libev restart
|
||||
|
||||
Check if things are in place
|
||||
|
||||
nft list ruleset | sed -r -n '/^\t[a-z]+ ss_rules[^ ]+ \{/,/^\t\}/p'
|
||||
netstat -lntp | grep -E '8053|1100'
|
||||
ps ww | grep ss-
|
||||
|
||||
Edit `/etc/config/dhcp`, making sure options are present in the first dnsmasq section like the following to let it use local tunnel endpoint for upstream dns query.
|
||||
Option `noresolv` instructs dnsmasq to not use other dns servers like advertised by local isp.
|
||||
Option `localuse` intends to make sure the device you are configuring also uses this dnsmasq instance as the resolver, not the ones from other sources.
|
||||
|
||||
config dnsmasq
|
||||
...
|
||||
list server '127.0.0.1#8053'
|
||||
option noresolv 1
|
||||
option localuse 1
|
||||
|
||||
Restart dnsmasq
|
||||
|
||||
/etc/init.d/dnsmasq restart
|
||||
|
||||
Check network on your computer
|
||||
|
||||
nslookup www.google.com
|
||||
curl -vv https://www.google.com
|
|
@ -1,60 +0,0 @@
|
|||
config ss_local
|
||||
option disabled 1
|
||||
option server 'sss0'
|
||||
option local_address '0.0.0.0'
|
||||
option local_port '1080'
|
||||
option timeout '30'
|
||||
|
||||
config ss_tunnel
|
||||
option disabled 1
|
||||
option server 'sss0'
|
||||
option local_address '0.0.0.0'
|
||||
option local_port '1090'
|
||||
option tunnel_address 'example.com:80'
|
||||
option mode 'tcp_and_udp'
|
||||
option timeout '60'
|
||||
|
||||
config ss_redir hi
|
||||
option disabled 1
|
||||
option server 'sss0'
|
||||
option local_address '0.0.0.0'
|
||||
option local_port '1100'
|
||||
option mode 'tcp_and_udp'
|
||||
option timeout '60'
|
||||
option fast_open 1
|
||||
option verbose 1
|
||||
option reuse_port 1
|
||||
|
||||
config ss_redir hj
|
||||
option disabled 1
|
||||
option server 'sss0'
|
||||
option local_address '0.0.0.0'
|
||||
option local_port '1100'
|
||||
option mode 'tcp_and_udp'
|
||||
option timeout '60'
|
||||
option fast_open 1
|
||||
option verbose 1
|
||||
option reuse_port 1
|
||||
|
||||
config ss_rules 'ss_rules'
|
||||
option disabled 1
|
||||
option redir_tcp 'hi'
|
||||
option redir_udp 'hi'
|
||||
option src_default 'checkdst'
|
||||
option dst_default 'bypass'
|
||||
option local_default 'checkdst'
|
||||
list src_ips_forward '192.168.1.4'
|
||||
list dst_ips_forward '8.8.8.8'
|
||||
|
||||
config server 'sss0'
|
||||
option disabled 1
|
||||
option server '192.168.1.3'
|
||||
option server_port '9001'
|
||||
option password '********'
|
||||
option method 'aes-256-cfb'
|
||||
|
||||
config ss_server
|
||||
option disabled 1
|
||||
option server_port '9001'
|
||||
option password '********'
|
||||
option method 'aes-256-cfb'
|
|
@ -1,317 +0,0 @@
|
|||
#!/bin/sh /etc/rc.common
|
||||
#
|
||||
# Copyright (C) 2017-2019 Yousong Zhou <yszhou4tech@gmail.com>
|
||||
#
|
||||
# This is free software, licensed under the GNU General Public License v3.
|
||||
# See /LICENSE for more information.
|
||||
#
|
||||
|
||||
USE_PROCD=1
|
||||
START=99
|
||||
|
||||
ss_confdir=/var/etc/shadowsocks-libev
|
||||
ss_bindir=/usr/bin
|
||||
|
||||
ssrules_uc="/usr/share/ss-rules/ss-rules.uc"
|
||||
ssrules_nft="/etc/nftables.d/90-ss-rules.nft"
|
||||
|
||||
ss_mkjson_server_conf() {
|
||||
local cfgserver
|
||||
|
||||
config_get cfgserver "$cfg" server
|
||||
[ -n "$cfgserver" ] || return 1
|
||||
eval "$(validate_server_section "$cfg" ss_validate_mklocal)"
|
||||
validate_server_section "$cfgserver" || return 1
|
||||
[ "$disabled" = 0 ] || return 1
|
||||
ss_mkjson_server_conf_ "$cfgserver"
|
||||
}
|
||||
|
||||
ss_mkjson_server_conf_() {
|
||||
[ -n "$server_port" ] || return 1
|
||||
[ -z "$server" ] || json_add_string server "$server"
|
||||
json_add_int server_port "$server_port"
|
||||
[ -z "$method" ] || json_add_string method "$method"
|
||||
[ -z "$key" ] || json_add_string key "$key"
|
||||
[ -z "$password" ] || json_add_string password "$password"
|
||||
[ -z "$plugin" ] || json_add_string plugin "$plugin"
|
||||
[ -z "$plugin_opts" ] || json_add_string plugin_opts "$plugin_opts"
|
||||
}
|
||||
|
||||
ss_mkjson_ss_local_conf() {
|
||||
ss_mkjson_server_conf
|
||||
}
|
||||
|
||||
ss_mkjson_ss_redir_conf() {
|
||||
ss_mkjson_server_conf
|
||||
}
|
||||
|
||||
ss_mkjson_ss_server_conf() {
|
||||
ss_mkjson_server_conf_
|
||||
}
|
||||
|
||||
ss_mkjson_ss_tunnel_conf() {
|
||||
ss_mkjson_server_conf || return 1
|
||||
[ -n "$tunnel_address" ] || return 1
|
||||
json_add_string tunnel_address "$tunnel_address"
|
||||
}
|
||||
|
||||
ss_xxx() {
|
||||
local cfg="$1"
|
||||
local cfgtype="$2"
|
||||
local bin="$ss_bindir/${cfgtype/_/-}"
|
||||
local confjson="$ss_confdir/$cfgtype.$cfg.json"
|
||||
|
||||
[ -x "$bin" ] || return
|
||||
eval "$("validate_${cfgtype}_section" "$cfg" ss_validate_mklocal)"
|
||||
"validate_${cfgtype}_section" "$cfg" || return
|
||||
[ "$disabled" = 0 ] || return
|
||||
|
||||
json_init
|
||||
ss_mkjson_${cfgtype}_conf || return
|
||||
json_add_boolean use_syslog 1
|
||||
json_add_boolean ipv6_first "$ipv6_first"
|
||||
json_add_boolean fast_open "$fast_open"
|
||||
json_add_boolean reuse_port "$reuse_port"
|
||||
json_add_boolean no_delay "$no_delay"
|
||||
[ -z "$local_address" ] || json_add_string local_address "$local_address"
|
||||
[ -z "$local_port" ] || json_add_int local_port "$local_port"
|
||||
[ -z "$local_ipv4_address" ] || json_add_string local_ipv4_address "$local_ipv4_address"
|
||||
[ -z "$local_ipv6_address" ] || json_add_string local_ipv6_address "$local_ipv6_address"
|
||||
[ -z "$mode" ] || json_add_string mode "$mode"
|
||||
[ -z "$mtu" ] || json_add_int mtu "$mtu"
|
||||
[ -z "$timeout" ] || json_add_int timeout "$timeout"
|
||||
[ -z "$user" ] || json_add_string user "$user"
|
||||
json_dump -i >"$confjson"
|
||||
|
||||
procd_open_instance "$cfgtype.$cfg"
|
||||
procd_set_param command "$bin" -c "$confjson"
|
||||
[ "$verbose" = 0 ] || procd_append_param command -v
|
||||
if [ -n "$bind_address" ]; then
|
||||
echo "$cfgtype $cfg: uci option bind_address deprecated, please switch to local_address" >&2
|
||||
procd_append_param command -b "$bind_address"
|
||||
fi
|
||||
procd_set_param file "$confjson"
|
||||
procd_set_param respawn
|
||||
procd_close_instance
|
||||
ss_rules_cb
|
||||
}
|
||||
|
||||
ss_rules_cb() {
|
||||
local cfgserver server
|
||||
|
||||
if [ "$cfgtype" = ss_redir ]; then
|
||||
config_get cfgserver "$cfg" server
|
||||
config_get server "$cfgserver" server
|
||||
ss_redir_servers="$ss_redir_servers $server"
|
||||
if [ "$mode" = tcp_only -o "$mode" = "tcp_and_udp" ]; then
|
||||
eval "ss_rules_redir_tcp_$cfg=$local_port"
|
||||
fi
|
||||
if [ "$mode" = udp_only -o "$mode" = "tcp_and_udp" ]; then
|
||||
eval "ss_rules_redir_udp_$cfg=$local_port"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
ss_rules_nft_gen() {
|
||||
local cfg="ss_rules"
|
||||
local cfgtype
|
||||
local local_port_tcp local_port_udp
|
||||
local remote_servers
|
||||
|
||||
[ -s "$ssrules_uc" ] || return 1
|
||||
|
||||
config_get cfgtype "$cfg" TYPE
|
||||
[ "$cfgtype" = ss_rules ] || return 1
|
||||
|
||||
eval "$(validate_ss_rules_section "$cfg" ss_validate_mklocal)"
|
||||
validate_ss_rules_section "$cfg" || return 1
|
||||
[ "$disabled" = 0 ] || return 2
|
||||
|
||||
eval local_port_tcp="\$ss_rules_redir_tcp_$redir_tcp"
|
||||
eval local_port_udp="\$ss_rules_redir_udp_$redir_udp"
|
||||
[ -n "$local_port_tcp" -o -n "$local_port_udp" ] || return 1
|
||||
remote_servers="$(echo $ss_redir_servers \
|
||||
| tr ' ' '\n' \
|
||||
| sort -u \
|
||||
| xargs -n 1 resolveip \
|
||||
| sort -u)"
|
||||
|
||||
local tmp="/tmp/ssrules"
|
||||
json_init
|
||||
json_add_string o_remote_servers "$remote_servers"
|
||||
json_add_int o_redir_tcp_port "$local_port_tcp"
|
||||
json_add_int o_redir_udp_port "$local_port_udp"
|
||||
json_add_string o_ifnames "$ifnames"
|
||||
json_add_string o_local_default "$local_default"
|
||||
json_add_string o_src_bypass "$src_ips_bypass"
|
||||
json_add_string o_src_forward "$src_ips_forward"
|
||||
json_add_string o_src_checkdst "$src_ips_checkdst"
|
||||
json_add_string o_src_default "$src_default"
|
||||
json_add_string o_dst_bypass "$dst_ips_bypass"
|
||||
json_add_string o_dst_forward "$dst_ips_forward"
|
||||
json_add_string o_dst_bypass_file "$dst_ips_bypass_file"
|
||||
json_add_string o_dst_forward_file "$dst_ips_forward_file"
|
||||
json_add_string o_dst_default "$dst_default"
|
||||
json_add_string o_nft_tcp_extra "$nft_tcp_extra"
|
||||
json_add_string o_nft_udp_extra "$nft_udp_extra"
|
||||
json_dump -i >"$tmp.json"
|
||||
|
||||
if utpl -S -F "$tmp.json" "$ssrules_uc" >"$tmp.nft" \
|
||||
&& ! cmp -s "$tmp.nft" "$ssrules_nft"; then
|
||||
echo "table inet chk {include \"$tmp.nft\";}" >"$tmp.nft.chk"
|
||||
if nft -f "$tmp.nft.chk" -c; then
|
||||
mv "$tmp.nft" "$ssrules_nft"
|
||||
fw4 restart
|
||||
fi
|
||||
rm -f "$tmp.nft.chk"
|
||||
fi
|
||||
rm -f "$tmp.json"
|
||||
rm -f "$tmp.nft"
|
||||
}
|
||||
|
||||
ss_rules_nft_reset() {
|
||||
if [ -f "$ssrules_nft" ]; then
|
||||
rm -f "$ssrules_nft"
|
||||
fw4 restart
|
||||
fi
|
||||
}
|
||||
|
||||
ss_rules() {
|
||||
if ! ss_rules_nft_gen; then
|
||||
ss_rules_nft_reset
|
||||
fi
|
||||
}
|
||||
|
||||
start_service() {
|
||||
local cfgtype
|
||||
|
||||
mkdir -p "$ss_confdir"
|
||||
config_load shadowsocks-libev
|
||||
for cfgtype in ss_local ss_redir ss_server ss_tunnel; do
|
||||
config_foreach ss_xxx "$cfgtype" "$cfgtype"
|
||||
done
|
||||
ss_rules
|
||||
}
|
||||
|
||||
stop_service() {
|
||||
ss_rules_nft_reset
|
||||
rm -rf "$ss_confdir"
|
||||
}
|
||||
|
||||
service_triggers() {
|
||||
procd_add_reload_interface_trigger wan
|
||||
procd_add_reload_trigger shadowsocks-libev
|
||||
procd_open_validate
|
||||
validate_server_section
|
||||
validate_ss_local_section
|
||||
validate_ss_redir_section
|
||||
validate_ss_rules_section
|
||||
validate_ss_server_section
|
||||
validate_ss_tunnel_section
|
||||
procd_close_validate
|
||||
}
|
||||
|
||||
ss_validate_mklocal() {
|
||||
local tuple opts
|
||||
|
||||
shift 2
|
||||
for tuple in "$@"; do
|
||||
opts="${tuple%%:*} $opts"
|
||||
done
|
||||
[ -z "$opts" ] || echo "local $opts"
|
||||
}
|
||||
|
||||
ss_validate() {
|
||||
uci_validate_section shadowsocks-libev "$@"
|
||||
}
|
||||
|
||||
validate_common_server_options_() {
|
||||
local cfgtype="$1"; shift
|
||||
local cfg="$1"; shift
|
||||
local func="$1"; shift
|
||||
local stream_methods='"table", "rc4", "rc4-md5", "aes-128-cfb", "aes-192-cfb", "aes-256-cfb", "aes-128-ctr", "aes-192-ctr", "aes-256-ctr", "bf-cfb", "camellia-128-cfb", "camellia-192-cfb", "camellia-256-cfb", "salsa20", "chacha20", "chacha20-ietf"'
|
||||
local aead_methods='"aes-128-gcm", "aes-192-gcm", "aes-256-gcm", "chacha20-ietf-poly1305", "xchacha20-ietf-poly1305"'
|
||||
|
||||
"${func:-ss_validate}" "$cfgtype" "$cfg" "$@" \
|
||||
'disabled:bool:0' \
|
||||
'server:host' \
|
||||
'server_port:port' \
|
||||
'password:string' \
|
||||
'key:string' \
|
||||
"method:or($stream_methods, $aead_methods)" \
|
||||
'plugin:string' \
|
||||
'plugin_opts:string'
|
||||
}
|
||||
|
||||
validate_common_client_options_() {
|
||||
validate_common_options_ "$@" \
|
||||
'server:uci("shadowsocks-libev", "@server")' \
|
||||
'local_address:ipaddr:0.0.0.0' \
|
||||
'local_port:port'
|
||||
}
|
||||
|
||||
validate_common_options_() {
|
||||
local cfgtype="$1"; shift
|
||||
local cfg="$1"; shift
|
||||
local func="$1"; shift
|
||||
|
||||
"${func:-ss_validate}" "$cfgtype" "$cfg" "$@" \
|
||||
'disabled:bool:0' \
|
||||
'fast_open:bool:0' \
|
||||
'ipv6_first:bool:0' \
|
||||
'no_delay:bool:0' \
|
||||
'reuse_port:bool:0' \
|
||||
'verbose:bool:0' \
|
||||
'mode:or("tcp_only", "udp_only", "tcp_and_udp"):tcp_only' \
|
||||
'mtu:uinteger' \
|
||||
'timeout:uinteger' \
|
||||
'user:string'
|
||||
}
|
||||
|
||||
validate_server_section() {
|
||||
validate_common_server_options_ server "$1" "$2"
|
||||
}
|
||||
|
||||
validate_ss_local_section() {
|
||||
validate_common_client_options_ ss_local "$1" "$2"
|
||||
}
|
||||
|
||||
validate_ss_redir_section() {
|
||||
validate_common_client_options_ ss_redir "$1" "$2"
|
||||
}
|
||||
|
||||
validate_ss_rules_section() {
|
||||
"${2:-ss_validate}" ss_rules "$1" \
|
||||
'disabled:bool:0' \
|
||||
'redir_tcp:uci("shadowsocks-libev", "@ss_redir")' \
|
||||
'redir_udp:uci("shadowsocks-libev", "@ss_redir")' \
|
||||
'src_ips_bypass:or(ipaddr,cidr)' \
|
||||
'src_ips_forward:or(ipaddr,cidr)' \
|
||||
'src_ips_checkdst:or(ipaddr,cidr)' \
|
||||
'dst_ips_bypass_file:file' \
|
||||
'dst_ips_bypass:or(ipaddr,cidr)' \
|
||||
'dst_ips_forward_file:file' \
|
||||
'dst_ips_forward:or(ipaddr,cidr)' \
|
||||
'src_default:or("bypass", "forward", "checkdst"):checkdst' \
|
||||
'dst_default:or("bypass", "forward"):bypass' \
|
||||
'local_default:or("bypass", "forward", "checkdst"):bypass' \
|
||||
'nft_tcp_extra:string' \
|
||||
'nft_udp_extra:string' \
|
||||
'ifnames:maxlength(15)'
|
||||
}
|
||||
|
||||
validate_ss_server_section() {
|
||||
validate_common_server_options_ ss_server "$1" \
|
||||
validate_common_options_ \
|
||||
"$2" \
|
||||
'local_address:ipaddr' \
|
||||
'local_ipv4_address:ip4addr' \
|
||||
'local_ipv6_address:ip6addr' \
|
||||
'bind_address:ipaddr'
|
||||
}
|
||||
|
||||
validate_ss_tunnel_section() {
|
||||
validate_common_client_options_ ss_tunnel "$1" \
|
||||
"$2" \
|
||||
'tunnel_address:regex(".+\:[0-9]+")'
|
||||
}
|
|
@ -1,122 +0,0 @@
|
|||
{%
|
||||
function get_local_verdict() {
|
||||
let v = o_local_default;
|
||||
if (v == "checkdst") {
|
||||
return "goto ss_rules_dst_" + proto;
|
||||
} else if (v == "forward") {
|
||||
return "goto ss_rules_forward_" + proto;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function get_src_default_verdict() {
|
||||
let v = o_src_default;
|
||||
if (v == "checkdst") {
|
||||
return "goto ss_rules_dst_" + proto;
|
||||
} else if (v == "forward") {
|
||||
return "goto ss_rules_forward_" + proto;
|
||||
} else {
|
||||
return "accept";
|
||||
}
|
||||
}
|
||||
|
||||
function get_dst_default_verdict() {
|
||||
let v = o_dst_default;
|
||||
if (v == "forward") {
|
||||
return "goto ss_rules_forward_" + proto;
|
||||
} else {
|
||||
return "accept";
|
||||
}
|
||||
}
|
||||
|
||||
function get_ifnames() {
|
||||
let res = [];
|
||||
for (let ifname in split(o_ifnames, /[ \t\n]/)) {
|
||||
ifname = trim(ifname);
|
||||
if (ifname) push(res, ifname);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
let type, hook, priority, redir_port;
|
||||
if (proto == "tcp") {
|
||||
type = "nat";
|
||||
hook = "prerouting";
|
||||
priority = -1;
|
||||
redir_port = o_redir_tcp_port;
|
||||
} else if (proto == "udp") {
|
||||
type = "filter";
|
||||
hook = "prerouting";
|
||||
priority = "mangle";
|
||||
redir_port = o_redir_udp_port;
|
||||
if (system("
|
||||
set -o errexit
|
||||
iprr() {
|
||||
while ip $1 rule del fwmark 1 lookup 100 2>/dev/null; do true; done
|
||||
ip $1 rule add fwmark 1 lookup 100
|
||||
ip $1 route flush table 100 2>/dev/null || true
|
||||
ip $1 route add local default dev lo table 100
|
||||
}
|
||||
iprr -4
|
||||
iprr -6
|
||||
") != 0) {
|
||||
return ;
|
||||
}
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
%}
|
||||
{% if (redir_port): %}
|
||||
|
||||
chain ss_rules_pre_{{ proto }} {
|
||||
type {{ type }} hook {{ hook }} priority {{ priority }};
|
||||
meta l4proto {{ proto }}{%- let ifnames=get_ifnames(); if (length(ifnames)): %} iifname { {{join(", ", ifnames)}} }{% endif %} goto ss_rules_pre_src_{{ proto }};
|
||||
}
|
||||
|
||||
chain ss_rules_pre_src_{{ proto }} {
|
||||
ip daddr @ss_rules_dst_bypass_ accept;
|
||||
ip6 daddr @ss_rules6_dst_bypass_ accept;
|
||||
goto ss_rules_src_{{ proto }};
|
||||
}
|
||||
|
||||
chain ss_rules_src_{{ proto }} {
|
||||
ip saddr @ss_rules_src_bypass accept;
|
||||
ip saddr @ss_rules_src_forward goto ss_rules_forward_{{ proto }};
|
||||
ip saddr @ss_rules_src_checkdst goto ss_rules_dst_{{ proto }};
|
||||
ip6 saddr @ss_rules6_src_bypass accept;
|
||||
ip6 saddr @ss_rules6_src_forward goto ss_rules_forward_{{ proto }};
|
||||
ip6 saddr @ss_rules6_src_checkdst goto ss_rules_dst_{{ proto }};
|
||||
{{ get_src_default_verdict() }};
|
||||
}
|
||||
|
||||
chain ss_rules_dst_{{ proto }} {
|
||||
ip daddr @ss_rules_dst_bypass accept;
|
||||
ip daddr @ss_rules_dst_forward goto ss_rules_forward_{{ proto }};
|
||||
ip6 daddr @ss_rules6_dst_bypass accept;
|
||||
ip6 daddr @ss_rules6_dst_forward goto ss_rules_forward_{{ proto }};
|
||||
{{ get_dst_default_verdict() }};
|
||||
}
|
||||
|
||||
{% if (proto == "tcp"): %}
|
||||
chain ss_rules_forward_{{ proto }} {
|
||||
meta l4proto tcp {{ o_nft_tcp_extra }} redirect to :{{ redir_port }};
|
||||
}
|
||||
{% let local_verdict = get_local_verdict(); if (local_verdict): %}
|
||||
chain ss_rules_local_out {
|
||||
type {{ type }} hook output priority -1;
|
||||
meta l4proto != tcp accept;
|
||||
ip daddr @ss_rules_dst_bypass_ accept;
|
||||
ip daddr @ss_rules_dst_bypass accept;
|
||||
ip6 daddr @ss_rules6_dst_bypass_ accept;
|
||||
ip6 daddr @ss_rules6_dst_bypass accept;
|
||||
{{ local_verdict }};
|
||||
}
|
||||
{% endif %}
|
||||
{% elif (proto == "udp"): %}
|
||||
chain ss_rules_forward_{{ proto }} {
|
||||
meta l4proto udp {{ o_nft_udp_extra }} meta mark set 1 tproxy to :{{ redir_port }};
|
||||
}
|
||||
{% endif %}
|
||||
{% endif %}
|
|
@ -1,113 +0,0 @@
|
|||
{%
|
||||
let fs = require("fs");
|
||||
|
||||
let o_dst_bypass4_ = "
|
||||
0.0.0.0/8
|
||||
10.0.0.0/8
|
||||
100.64.0.0/10
|
||||
127.0.0.0/8
|
||||
169.254.0.0/16
|
||||
172.16.0.0/12
|
||||
192.0.0.0/24
|
||||
192.0.2.0/24
|
||||
192.31.196.0/24
|
||||
192.52.193.0/24
|
||||
192.88.99.0/24
|
||||
192.168.0.0/16
|
||||
192.175.48.0/24
|
||||
198.18.0.0/15
|
||||
198.51.100.0/24
|
||||
203.0.113.0/24
|
||||
224.0.0.0/4
|
||||
240.0.0.0/4
|
||||
";
|
||||
let o_dst_bypass6_ = "
|
||||
::1/128
|
||||
::/128
|
||||
::ffff:0:0/96
|
||||
64:ff9b:1::/48
|
||||
100::/64
|
||||
fe80::/10
|
||||
2001::/23
|
||||
fc00::/7
|
||||
";
|
||||
let o_dst_bypass_ = o_dst_bypass4_ + " " + o_dst_bypass6_;
|
||||
|
||||
let set_suffix = {
|
||||
"src_bypass": {
|
||||
str: o_src_bypass,
|
||||
},
|
||||
"src_forward": {
|
||||
str: o_src_forward,
|
||||
},
|
||||
"src_checkdst": {
|
||||
str: o_src_checkdst,
|
||||
},
|
||||
"dst_bypass": {
|
||||
str: o_dst_bypass,
|
||||
file: o_dst_bypass_file,
|
||||
},
|
||||
"dst_bypass_": {
|
||||
str: o_dst_bypass_,
|
||||
},
|
||||
"dst_forward": {
|
||||
str: o_dst_forward,
|
||||
file: o_dst_forward_file,
|
||||
},
|
||||
"dst_forward_rrst_": {},
|
||||
};
|
||||
|
||||
function set_name(suf, af) {
|
||||
if (af == 4) {
|
||||
return "ss_rules_"+suf;
|
||||
} else {
|
||||
return "ss_rules6_"+suf;
|
||||
}
|
||||
}
|
||||
|
||||
function set_elements_parse(res, str, af) {
|
||||
for (let addr in split(str, /[ \t\n]/)) {
|
||||
addr = trim(addr);
|
||||
if (!addr) continue;
|
||||
if (af == 4 && index(addr, ":") != -1) continue;
|
||||
if (af == 6 && index(addr, ":") == -1) continue;
|
||||
push(res, addr);
|
||||
}
|
||||
}
|
||||
|
||||
function set_elements(suf, af) {
|
||||
let obj = set_suffix[suf];
|
||||
let res = [];
|
||||
let addr;
|
||||
|
||||
let str = obj["str"];
|
||||
if (str) {
|
||||
set_elements_parse(res, str, af);
|
||||
}
|
||||
|
||||
let file = obj["file"];
|
||||
if (file) {
|
||||
let fd = fs.open(file);
|
||||
if (fd) {
|
||||
str = fd.read("all");
|
||||
set_elements_parse(res, str, af);
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
%}
|
||||
|
||||
{% for (let suf in set_suffix): for (let af in [4, 6]): %}
|
||||
set {{ set_name(suf, af) }} {
|
||||
type ipv{{af}}_addr;
|
||||
flags interval;
|
||||
{% let elems = set_elements(suf, af); if (length(elems)): %}
|
||||
elements = {
|
||||
{% for (let i = 0; i < length(elems); i++): %}
|
||||
{{ elems[i] }}{% if (i < length(elems) - 1): %},{% endif %}{% print("\n") %}
|
||||
{% endfor %}
|
||||
}
|
||||
{% endif %}
|
||||
}
|
||||
{% endfor; endfor %}
|
|
@ -1,8 +0,0 @@
|
|||
{%
|
||||
|
||||
include("set.uc");
|
||||
include("chain.uc", {proto: "tcp"});
|
||||
include("chain.uc", {proto: "udp"});
|
||||
|
||||
%}
|
||||
|
Loading…
Reference in New Issue