From de5058d09b0a5416f0d8cfb880a001e6bd9057fd Mon Sep 17 00:00:00 2001 From: Tianling Shen Date: Sat, 2 Dec 2023 16:40:53 +0800 Subject: [PATCH] feat: add TCP Brutal support --- .../resources/view/homeproxy/node.js | 18 ++++++++++ .../resources/view/homeproxy/server.js | 35 +++++++++++++++++++ root/etc/homeproxy/scripts/generate_client.uc | 7 +++- root/etc/homeproxy/scripts/generate_server.uc | 10 ++++++ root/usr/share/rpcd/ucode/luci.homeproxy | 9 +++-- 5 files changed, 76 insertions(+), 3 deletions(-) diff --git a/htdocs/luci-static/resources/view/homeproxy/node.js b/htdocs/luci-static/resources/view/homeproxy/node.js index 761056cc..701bd002 100644 --- a/htdocs/luci-static/resources/view/homeproxy/node.js +++ b/htdocs/luci-static/resources/view/homeproxy/node.js @@ -1026,6 +1026,24 @@ return view.extend({ so.default = so.disabled; so.depends('multiplex', '1'); so.modalonly = true; + + so = ss.option(form.Flag, 'multiplex_brutal', _('Enable TCP Brutal'), + _('Enable TCP Brutal congestion control algorithm')); + so.default = so.disabled; + so.depends('multiplex', '1'); + so.modalonly = true; + + so = ss.option(form.Value, 'multiplex_brutal_down', _('Download bandwidth'), + _('Download bandwidth in Mbps.')); + so.datatype = 'uinteger'; + so.depends('multiplex_brutal', '1'); + so.modalonly = true; + + so = ss.option(form.Value, 'multiplex_brutal_up', _('Upload bandwidth'), + _('Upload bandwidth in Mbps.')); + so.datatype = 'uinteger'; + so.depends('multiplex_brutal', '1'); + so.modalonly = true; /* Mux config end */ /* TLS config start */ diff --git a/htdocs/luci-static/resources/view/homeproxy/server.js b/htdocs/luci-static/resources/view/homeproxy/server.js index 27b4f443..4ff3f6a0 100644 --- a/htdocs/luci-static/resources/view/homeproxy/server.js +++ b/htdocs/luci-static/resources/view/homeproxy/server.js @@ -414,6 +414,41 @@ return view.extend({ /* Transport config end */ + /* Mux config start */ + o = s.option(form.Flag, 'multiplex', _('Multiplex')); + o.default = o.disabled; + o.depends('type', 'shadowsocks'); + o.depends('type', 'trojan'); + o.depends('type', 'vless'); + o.depends('type', 'vmess'); + o.modalonly = true; + + o = s.option(form.Flag, 'multiplex_padding', _('Enable padding')); + o.default = o.disabled; + o.depends('multiplex', '1'); + o.modalonly = true; + + if (features.hp_has_tcp_brutal) { + o = s.option(form.Flag, 'multiplex_brutal', _('Enable TCP Brutal'), + _('Enable TCP Brutal congestion control algorithm')); + o.default = o.disabled; + o.depends('multiplex', '1'); + o.modalonly = true; + + o = s.option(form.Value, 'multiplex_brutal_down', _('Download bandwidth'), + _('Download bandwidth in Mbps.')); + o.datatype = 'uinteger'; + o.depends('multiplex_brutal', '1'); + o.modalonly = true; + + o = s.option(form.Value, 'multiplex_brutal_up', _('Upload bandwidth'), + _('Upload bandwidth in Mbps.')); + o.datatype = 'uinteger'; + o.depends('multiplex_brutal', '1'); + o.modalonly = true; + } + /* Mux config end */ + /* TLS config start */ o = s.option(form.Flag, 'tls', _('TLS')); o.default = o.disabled; diff --git a/root/etc/homeproxy/scripts/generate_client.uc b/root/etc/homeproxy/scripts/generate_client.uc index be3af278..323c03e6 100755 --- a/root/etc/homeproxy/scripts/generate_client.uc +++ b/root/etc/homeproxy/scripts/generate_client.uc @@ -188,7 +188,12 @@ function generate_outbound(node) { max_connections: strToInt(node.multiplex_max_connections), min_streams: strToInt(node.multiplex_min_streams), max_streams: strToInt(node.multiplex_max_streams), - padding: (node.multiplex_padding === '1') + padding: (node.multiplex_padding === '1'), + brutal: (node.multiplex_brutal === '1') ? { + enabled: true, + up_mbps: node.multiplex_brutal_down, + down_mbps: node.multiplex_brutal_up + } : null } : null, tls: (node.tls === '1') ? { enabled: true, diff --git a/root/etc/homeproxy/scripts/generate_server.uc b/root/etc/homeproxy/scripts/generate_server.uc index bd0138d8..54918e44 100755 --- a/root/etc/homeproxy/scripts/generate_server.uc +++ b/root/etc/homeproxy/scripts/generate_server.uc @@ -98,6 +98,16 @@ uci.foreach(uciconfig, uciserver, (cfg) => { } ] : null, + multiplex: (cfg.multiplex === '1') ? { + enabled: true, + padding: (cfg.multiplex_padding === '1'), + brutal: (cfg.multiplex_brutal === '1') ? { + enabled: true, + up_mbps: cfg.multiplex_brutal_down, + down_mbps: cfg.multiplex_brutal_up + } : null + } : null, + tls: (cfg.tls === '1') ? { enabled: true, server_name: cfg.tls_sni, diff --git a/root/usr/share/rpcd/ucode/luci.homeproxy b/root/usr/share/rpcd/ucode/luci.homeproxy index 75a6c998..1a78ade6 100755 --- a/root/usr/share/rpcd/ucode/luci.homeproxy +++ b/root/usr/share/rpcd/ucode/luci.homeproxy @@ -14,6 +14,10 @@ function shellquote(s) { return `'${replace(s, "'", "'\\''")}'`; } +function hasKernelModule(kmod) { + return (system(sprintf('[ -e "/lib/modules/$(uname -r)"/%s ]', shellquote(kmod))) === 0); +} + const HP_DIR = '/etc/homeproxy'; const RUN_DIR = '/var/run/homeproxy'; @@ -173,8 +177,9 @@ const methods = { features.hp_has_chinadns_ng = access('/usr/bin/chinadns-ng'); features.hp_has_ip_full = access('/usr/libexec/ip-full'); - features.hp_has_tproxy = access('/etc/modules.d/nft-tproxy'); - features.hp_has_tun = access('/etc/modules.d/30-tun'); + features.hp_has_tcp_brutal = hasKernelModule('brutal.ko'); + features.hp_has_tproxy = hasKernelModule('nft_tproxy.ko') || access('/etc/modules.d/nft-tproxy'); + features.hp_has_tun = hasKernelModule('tun.ko') || access('/etc/modules.d/30-tun'); return features; }