From 2f4fe9a997acbce5ebf31611fae4d2017655d441 Mon Sep 17 00:00:00 2001 From: Anya Lin Date: Wed, 21 Aug 2024 20:08:32 +0800 Subject: [PATCH 1/3] feat(generator/client): add `proxy_protocol` option for `direct` outbound --- htdocs/luci-static/resources/view/homeproxy/node.js | 12 ++++++++++++ root/etc/homeproxy/scripts/generate_client.uc | 4 ++++ 2 files changed, 16 insertions(+) diff --git a/htdocs/luci-static/resources/view/homeproxy/node.js b/htdocs/luci-static/resources/view/homeproxy/node.js index ea5fd851..a7e269aa 100644 --- a/htdocs/luci-static/resources/view/homeproxy/node.js +++ b/htdocs/luci-static/resources/view/homeproxy/node.js @@ -468,6 +468,18 @@ function renderNodeSettings(section, data, features, main_node, routing_mode) { o.datatype = 'port'; o.depends('type', 'direct'); + o = s.option(form.Flag, 'proxy_protocol', _('Proxy protocol'), + _('Write proxy protocol in the connection header.')); + o.depends('type', 'direct'); + o.modalonly = true; + + o = s.option(form.ListValue, 'proxy_protocol_version', _('Proxy protocol version')); + o.value('1', _('v1')); + o.value('2', _('v2')); + o.default = '2'; + o.depends('proxy_protocol', '1'); + o.modalonly = true; + /* Hysteria (2) config start */ o = s.option(form.ListValue, 'hysteria_protocol', _('Protocol')); o.value('udp'); diff --git a/root/etc/homeproxy/scripts/generate_client.uc b/root/etc/homeproxy/scripts/generate_client.uc index f51fff61..bd72628d 100755 --- a/root/etc/homeproxy/scripts/generate_client.uc +++ b/root/etc/homeproxy/scripts/generate_client.uc @@ -160,6 +160,10 @@ function generate_outbound(node) { /* Direct */ override_address: node.override_address, override_port: strToInt(node.override_port), + proxy_protocol: (node.proxy_protocol === '1') ? { + enabled: true, + version: strToInt(node.proxy_protocol_version) + } : null, /* Hysteria (2) */ up_mbps: strToInt(node.hysteria_up_mbps), down_mbps: strToInt(node.hysteria_down_mbps), From 345911ee11dd8979bb3b9b30140ab534746fb777 Mon Sep 17 00:00:00 2001 From: Anya Lin Date: Wed, 21 Aug 2024 21:30:30 +0800 Subject: [PATCH 2/3] fix(server): fix typo --- htdocs/luci-static/resources/view/homeproxy/server.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/luci-static/resources/view/homeproxy/server.js b/htdocs/luci-static/resources/view/homeproxy/server.js index b3d5f64b..21bb3f92 100644 --- a/htdocs/luci-static/resources/view/homeproxy/server.js +++ b/htdocs/luci-static/resources/view/homeproxy/server.js @@ -277,7 +277,7 @@ return view.extend({ o.depends('type', 'tuic'); o.modalonly = true; - o = s.option(form.ListValue, 'tuic_auth_timeout', _('Auth timeout'), + o = s.option(form.Value, 'tuic_auth_timeout', _('Auth timeout'), _('How long the server should wait for the client to send the authentication command (in seconds).')); o.datatype = 'uinteger'; o.default = '3'; From b392edd4ed99c1ef76fef3c275b5bbbf9611a27b Mon Sep 17 00:00:00 2001 From: Anya Lin Date: Wed, 21 Aug 2024 20:40:54 +0800 Subject: [PATCH 3/3] feat(generator): add `udp_timeout` option --- htdocs/luci-static/resources/view/homeproxy/client.js | 9 +++++++++ htdocs/luci-static/resources/view/homeproxy/server.js | 7 +++++++ root/etc/config/homeproxy | 1 + root/etc/homeproxy/scripts/generate_client.uc | 8 +++++++- root/etc/homeproxy/scripts/generate_server.uc | 1 + 5 files changed, 25 insertions(+), 1 deletion(-) diff --git a/htdocs/luci-static/resources/view/homeproxy/client.js b/htdocs/luci-static/resources/view/homeproxy/client.js index acc1c164..e0202611 100644 --- a/htdocs/luci-static/resources/view/homeproxy/client.js +++ b/htdocs/luci-static/resources/view/homeproxy/client.js @@ -313,6 +313,15 @@ return view.extend({ so.depends('tcpip_stack', 'gvisor'); so.rmempty = false; + so = ss.option(form.Value, 'udp_timeout', _('UDP NAT expiration time'), + _('In seconds. 300 is used by default.')); + so.datatype = 'uinteger'; + so.default = '300'; + so.depends('homeproxy.config.proxy_mode', 'redirect_tproxy'); + so.depends('homeproxy.config.proxy_mode', 'redirect_tun'); + so.depends('homeproxy.config.proxy_mode', 'tun'); + so.rmempty = false; + so = ss.option(form.Flag, 'bypass_cn_traffic', _('Bypass CN traffic'), _('Bypass mainland China traffic via firewall rules by default.')); so.default = so.disabled; diff --git a/htdocs/luci-static/resources/view/homeproxy/server.js b/htdocs/luci-static/resources/view/homeproxy/server.js index 21bb3f92..bd22eb76 100644 --- a/htdocs/luci-static/resources/view/homeproxy/server.js +++ b/htdocs/luci-static/resources/view/homeproxy/server.js @@ -716,6 +716,13 @@ return view.extend({ o.depends({'network': 'tcp', '!reverse': true}); o.modalonly = true; + o = s.option(form.Value, 'udp_timeout', _('UDP NAT expiration time'), + _('In seconds. 300 is used by default.')); + o.datatype = 'uinteger'; + o.default = '300'; + o.depends({'network': 'tcp', '!reverse': true}); + o.modalonly = true; + o = s.option(form.Flag, 'sniff_override', _('Override destination'), _('Override the connection destination address with the sniffed domain.')); o.rmempty = false; diff --git a/root/etc/config/homeproxy b/root/etc/config/homeproxy index d8438f0a..cc6a0ead 100644 --- a/root/etc/config/homeproxy +++ b/root/etc/config/homeproxy @@ -7,6 +7,7 @@ config homeproxy 'infra' option tproxy_port '5332' option dns_port '5333' option china_dns_port '5334' + option udp_timeout '' option tun_name 'singtun0' option tun_addr4 '172.19.0.1/30' option tun_addr6 'fdfe:dcba:9876::1/126' diff --git a/root/etc/homeproxy/scripts/generate_client.uc b/root/etc/homeproxy/scripts/generate_client.uc index bd72628d..348b1f55 100755 --- a/root/etc/homeproxy/scripts/generate_client.uc +++ b/root/etc/homeproxy/scripts/generate_client.uc @@ -93,7 +93,10 @@ const cache_file_store_rdrc = uci.get(uciconfig, uciexp, 'cache_file_store_rdrc' const mixed_port = uci.get(uciconfig, uciinfra, 'mixed_port') || '5330'; let self_mark, redirect_port, tproxy_port, tun_name, tun_addr4, tun_addr6, tun_mtu, tun_gso, - tcpip_stack, endpoint_independent_nat; + tcpip_stack, endpoint_independent_nat, udp_timeout; +udp_timeout = uci.get(uciconfig, 'infra', 'udp_timeout'); +if (routing_mode === 'custom') + udp_timeout = uci.get(uciconfig, uciroutingsetting, 'udp_timeout'); if (match(proxy_mode, /redirect/)) { self_mark = uci.get(uciconfig, 'infra', 'self_mark') || '100'; redirect_port = uci.get(uciconfig, 'infra', 'redirect_port') || '5331'; @@ -486,6 +489,7 @@ push(config.inbounds, { tag: 'mixed-in', listen: '::', listen_port: int(mixed_port), + udp_timeout: udp_timeout ? (udp_timeout + 's') : null, sniff: true, sniff_override_destination: (sniff_override === '1'), set_system_proxy: false @@ -509,6 +513,7 @@ if (match(proxy_mode, /tproxy/)) listen: '::', listen_port: int(tproxy_port), network: 'udp', + udp_timeout: udp_timeout ? (udp_timeout + 's') : null, sniff: true, sniff_override_destination: (sniff_override === '1') }); @@ -524,6 +529,7 @@ if (match(proxy_mode, /tun/)) gso: (tun_gso === '1'), auto_route: false, endpoint_independent_nat: strToBool(endpoint_independent_nat), + udp_timeout: udp_timeout ? (udp_timeout + 's') : null, stack: tcpip_stack, sniff: true, sniff_override_destination: (sniff_override === '1'), diff --git a/root/etc/homeproxy/scripts/generate_server.uc b/root/etc/homeproxy/scripts/generate_server.uc index 077f6898..7e9b735b 100755 --- a/root/etc/homeproxy/scripts/generate_server.uc +++ b/root/etc/homeproxy/scripts/generate_server.uc @@ -49,6 +49,7 @@ uci.foreach(uciconfig, uciserver, (cfg) => { tcp_fast_open: strToBool(cfg.tcp_fast_open), tcp_multi_path: strToBool(cfg.tcp_multi_path), udp_fragment: strToBool(cfg.udp_fragment), + udp_timeout: cfg.udp_timeout ? (cfg.udp_timeout + 's') : null, sniff: true, sniff_override_destination: (cfg.sniff_override === '1'), domain_strategy: cfg.domain_strategy,