diff --git a/package/mtk/applications/luci-app-turboacc-mtk/Makefile b/package/mtk/applications/luci-app-turboacc-mtk/Makefile new file mode 100644 index 0000000000..3170ad82ac --- /dev/null +++ b/package/mtk/applications/luci-app-turboacc-mtk/Makefile @@ -0,0 +1,16 @@ +# SPDX-Identifier-License: GPL-3.0-only +# +# Copyright (C) 2018 Lean +# Copyright (C) 2019-2022 ImmortalWrt.org + +include $(TOPDIR)/rules.mk + +PKG_LICENSE:=GPL-3.0-only + +LUCI_TITLE:=LuCI support for MTK HNAT +LUCI_DEPENDS:=+kmod-tcp-bbr @!PACKAGE_luci-app-turboacc +LUCI_PKGARCH:=all + +include $(TOPDIR)/feeds/luci/luci.mk + +# call BuildPackage - OpenWrt buildroot signature diff --git a/package/mtk/applications/luci-app-turboacc-mtk/htdocs/luci-static/resources/view/turboacc.js b/package/mtk/applications/luci-app-turboacc-mtk/htdocs/luci-static/resources/view/turboacc.js new file mode 100644 index 0000000000..73769b4ba3 --- /dev/null +++ b/package/mtk/applications/luci-app-turboacc-mtk/htdocs/luci-static/resources/view/turboacc.js @@ -0,0 +1,204 @@ +/* Copyright (C) 2022 ImmortalWrt.org */ + +'use strict'; +'require form'; +'require fs'; +'require poll'; +'require rpc'; +'require uci'; +'require view'; + +var getSystemFeatures = rpc.declare({ + object: 'luci.turboacc', + method: 'getSystemFeatures', + expect: { '': {} } +}); + +var getFastPathStat = rpc.declare({ + object: 'luci.turboacc', + method: 'getFastPathStat', + expect: { '': {} } +}); + +var getFullConeStat = rpc.declare({ + object: 'luci.turboacc', + method: 'getFullConeStat', + expect: { '': {} } +}); + +var getTCPCCAStat = rpc.declare({ + object: 'luci.turboacc', + method: 'getTCPCCAStat', + expect: { '': {} } +}); + +function getServiceStatus() { + return Promise.all([ + L.resolveDefault(getFastPathStat(), {}), + L.resolveDefault(getFullConeStat(), {}), + L.resolveDefault(getTCPCCAStat(), {}) + ]); +} + +function renderStatus(stats) { + var spanTemp = '%s'; + var renderHTML = []; + for (var stat of stats) + if (stat.type) { + if (stat.type.includes(' / ')) { + var types = stat.type.split(' / '); + var inner = spanTemp.format('green', types[0]); + for (var i of types.slice(1)) + inner += spanTemp.format('none', ' / ') + spanTemp.format('red', i); + renderHTML.push(inner); + } else + renderHTML.push(spanTemp.format('green', stat.type)); + } else + renderHTML.push(spanTemp.format('red', _('Disabled'))); + return renderHTML; +} + +return view.extend({ + load: function() { + return Promise.all([ + uci.load('turboacc'), + L.resolveDefault(getSystemFeatures(), {}) + ]); + }, + + render: function(data) { + var m, s, o; + var features = data[1]; + + m = new form.Map('turboacc', _('TurboACC settings'), + _('Open source flow offloading engine (fast path or hardware NAT).')); + + s = m.section(form.TypedSection); + s.anonymous = true; + s.render = function () { + poll.add(function () { + return L.resolveDefault(getServiceStatus()).then(function (res) { + var stats = renderStatus(res); + var tds = [ 'fastpath_state', 'fullcone_state', 'tcpcca_state' ]; + for (var i in tds) { + var view = document.getElementById(tds[i]); + view.innerHTML = stats[i]; + } + }); + }); + + return E('fieldset', { 'class': 'cbi-section' }, [ + E('legend', {}, _('Acceleration Status')), + E('table', { 'class': 'table', 'width': '100%', 'cellspacing': '10' }, [ + E('tr', {}, [ + E('td', { 'width': '33%' }, _('FastPath Engine')), + E('td', { 'id': 'fastpath_state' }, E('em', {}, _('Collecting data...'))) + ]), + E('tr', {}, [ + E('td', { 'width': '33%' }, _('Full Cone NAT')), + E('td', { 'id': 'fullcone_state' }, E('em', {}, _('Collecting data...'))) + ]), + E('tr', {}, [ + E('td', { 'width': '33%' }, _('TCP CCA')), + E('td', { 'id': 'tcpcca_state' }, E('em', {}, _('Collecting data...'))) + ]) + ]) + ]); + } + + /* Mark user edited */ + s = m.section(form.NamedSection, 'global', 'turboacc'); + o = s.option(form.HiddenValue, 'set'); + o.load = (/* ... */) => { return 1 }; + o.readonly = true; + o.rmempty = false; + + s = m.section(form.NamedSection, 'config', 'turboacc'); + + o = s.option(form.ListValue, 'fastpath', _('Fastpath engine'), + _('The offloading engine for routing/NAT.')); + o.value('disabled', _('Disable')); + if (features.hasFLOWOFFLOADING) + o.value('flow_offloading', _('Flow offloading')); + if (features.hasFASTCLASSIFIER) + o.value('fast_classifier', _('Fast classifier')); + if (features.hasSHORTCUTFECM) + o.value('shortcut_fe_cm', _('SFE connection manager')); + if (features.hasMEDIATEKHNAT) + o.value('mediatek_hnat', _('MediaTek HNAT')); + o.default = 'disabled'; + o.rmempty = false; + o.onchange = function(ev, section_id, value) { + var desc = ev.target.nextElementSibling; + if (value === 'flow_offloading') + desc.innerHTML = _('Software based offloading for routing/NAT.'); + else if (value === 'fast_classifier') + desc.innerHTML = _('Fast classifier connection manager for the shortcut forwarding engine.'); + else if (value === 'shortcut_fe_cm') + desc.innerHTML = _('Simple connection manager for the shortcut forwarding engine.'); + else if (value === 'mediatek_hnat') + desc.innerHTML = _('MediaTek\'s open source hardware offloading engine.'); + else + desc.innerHTML = _('The offloading engine for routing/NAT.'); + } + + o = s.option(form.Flag, 'fastpath_fo_hw', _('Hardware flow offloading'), + _('Requires hardware NAT support. Implemented at least for mt7621.')); + o.default = o.disabled; + o.rmempty = false; + o.depends('fastpath', 'flow_offloading'); + + o = s.option(form.Flag, 'fastpath_fc_br', _('Bridge Acceleration'), + _('Enable bridge acceleration (may be functional conflict with bridge-mode VPN server).')); + o.default = o.disabled; + o.rmempty = false; + o.depends('fastpath', 'fast_classifier'); + + if (features.hasIPV6) { + o = s.option(form.Flag, 'fastpath_fc_ipv6', _('IPv6 acceleration'), + _('Enable IPv6 Acceleration.')); + o.default = o.disabled; + o.rmempty = false; + o.depends('fastpath', 'fast_classifier'); + } + + o = s.option(form.Flag, 'fastpath_mh_eth_hnat', _('Enable ethernet HNAT'), + _('Enable hardware offloading for wired connections.')); + o.default = o.enabled; + o.rmempty = false; + o.depends('fastpath', 'mediatek_hnat'); + + o = s.option(form.Flag, 'fastpath_mh_eth_hnat_v6', _('Enable ethernet IPv6 HNAT'), + _('Enable hardware offloading for wired IPv6 connections.')); + o.default = o.enabled; + o.rmempty = false; + o.depends('fastpath_mh_eth_hnat', '1'); + + o = s.option(form.Button, '_fastpath_mh_wireless_hnat', _('Enable wireless HNAT'), + _('Enable hardware offloading for wireless connections.')); + o.inputtitle = _('Redirect to wireless settings'); + o.inputstyle = 'reload'; + o.onclick = function() { + window.location.href = L.url('admin/network/wifi'); + }; + o.depends('fastpath', 'mediatek_hnat'); + + o = s.option(form.ListValue, 'fullcone', _('Full cone NAT'), + _('Full cone NAT (NAT1) can improve gaming performance effectively.')); + o.value('0', _('Disable')) + if (features.hasXTFULLCONENAT) + o.value('1', _('xt_FULLCONENAT')); + o.value('2', _('Boardcom fullcone')); + o.default = '0'; + o.rmempty = false; + + o = s.option(form.ListValue, 'tcpcca', _('TCP CCA'), + _('TCP congestion control algorithm.')); + for (var i of features.hasTCPCCA.split(' ').sort()) + o.value(i); + o.default = 'cubic'; + o.rmempty = false; + + return m.render(); + } +}); diff --git a/package/mtk/applications/luci-app-turboacc-mtk/po/templates/turboacc.pot b/package/mtk/applications/luci-app-turboacc-mtk/po/templates/turboacc.pot new file mode 100644 index 0000000000..86ed525f1c --- /dev/null +++ b/package/mtk/applications/luci-app-turboacc-mtk/po/templates/turboacc.pot @@ -0,0 +1,165 @@ +msgid "" +msgstr "Content-Type: text/plain; charset=UTF-8" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:91 +msgid "Acceleration Status" +msgstr "" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:191 +msgid "Boardcom fullcone" +msgstr "" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:151 +msgid "Bridge Acceleration" +msgstr "" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:95 +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:99 +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:103 +msgid "Collecting data..." +msgstr "" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:120 +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:188 +msgid "Disable" +msgstr "" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:57 +msgid "Disabled" +msgstr "" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:159 +msgid "Enable IPv6 Acceleration." +msgstr "" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:152 +msgid "" +"Enable bridge acceleration (may be functional conflict with bridge-mode VPN " +"server)." +msgstr "" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:165 +msgid "Enable ethernet HNAT" +msgstr "" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:171 +msgid "Enable ethernet IPv6 HNAT" +msgstr "" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:172 +msgid "Enable hardware offloading for wired IPv6 connections." +msgstr "" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:166 +msgid "Enable hardware offloading for wired connections." +msgstr "" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:178 +msgid "Enable hardware offloading for wireless connections." +msgstr "" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:177 +msgid "Enable wireless HNAT" +msgstr "" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:124 +msgid "Fast classifier" +msgstr "" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:136 +msgid "Fast classifier connection manager for the shortcut forwarding engine." +msgstr "" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:94 +msgid "FastPath Engine" +msgstr "" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:118 +msgid "Fastpath engine" +msgstr "" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:122 +msgid "Flow offloading" +msgstr "" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:98 +msgid "Full Cone NAT" +msgstr "" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:186 +msgid "Full cone NAT" +msgstr "" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:187 +msgid "Full cone NAT (NAT1) can improve gaming performance effectively." +msgstr "" + +#: applications/luci-app-turboacc/root/usr/share/rpcd/acl.d/luci-app-turboacc.json:3 +msgid "Grant UCI access for luci-app-turboacc" +msgstr "" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:145 +msgid "Hardware flow offloading" +msgstr "" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:158 +msgid "IPv6 acceleration" +msgstr "" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:128 +msgid "MediaTek HNAT" +msgstr "" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:140 +msgid "MediaTek's open source hardware offloading engine." +msgstr "" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:74 +msgid "Open source flow offloading engine (fast path or hardware NAT)." +msgstr "" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:179 +msgid "Redirect to wireless settings" +msgstr "" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:146 +msgid "Requires hardware NAT support. Implemented at least for mt7621." +msgstr "" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:126 +msgid "SFE connection manager" +msgstr "" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:138 +msgid "Simple connection manager for the shortcut forwarding engine." +msgstr "" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:134 +msgid "Software based offloading for routing/NAT." +msgstr "" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:102 +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:195 +msgid "TCP CCA" +msgstr "" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:196 +msgid "TCP congestion control algorithm." +msgstr "" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:119 +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:142 +msgid "The offloading engine for routing/NAT." +msgstr "" + +#: applications/luci-app-turboacc/root/usr/share/luci/menu.d/luci-app-turboacc.json:3 +msgid "TurboACC" +msgstr "" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:73 +msgid "TurboACC settings" +msgstr "" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:190 +msgid "xt_FULLCONENAT" +msgstr "" diff --git a/package/mtk/applications/luci-app-turboacc-mtk/po/zh_Hans/turboacc.po b/package/mtk/applications/luci-app-turboacc-mtk/po/zh_Hans/turboacc.po new file mode 100644 index 0000000000..5e5a7c5af5 --- /dev/null +++ b/package/mtk/applications/luci-app-turboacc-mtk/po/zh_Hans/turboacc.po @@ -0,0 +1,172 @@ +msgid "" +msgstr "" +"Content-Type: text/plain; charset=UTF-8\n" +"Project-Id-Version: PACKAGE VERSION\n" +"Last-Translator: Automatically generated\n" +"Language-Team: none\n" +"Language: zh-Hans\n" +"MIME-Version: 1.0\n" +"Content-Transfer-Encoding: 8bit\n" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:91 +msgid "Acceleration Status" +msgstr "加速状态" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:191 +msgid "Boardcom fullcone" +msgstr "Boardcom fullcone" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:151 +msgid "Bridge Acceleration" +msgstr "桥接加速" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:95 +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:99 +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:103 +msgid "Collecting data..." +msgstr "正在收集数据…" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:120 +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:188 +msgid "Disable" +msgstr "禁用" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:57 +msgid "Disabled" +msgstr "已禁用" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:159 +msgid "Enable IPv6 Acceleration." +msgstr "启用 IPv6 加速。" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:152 +msgid "" +"Enable bridge acceleration (may be functional conflict with bridge-mode VPN " +"server)." +msgstr "启用桥接加速(可能会与桥接模式的 VPN 服务器冲突)。" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:165 +msgid "Enable ethernet HNAT" +msgstr "启用以太网 HNAT" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:171 +msgid "Enable ethernet IPv6 HNAT" +msgstr "启用以太网 IPv6 HNAT" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:172 +msgid "Enable hardware offloading for wired IPv6 connections." +msgstr "为有线 IPv6 连接启用硬件加速。" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:166 +msgid "Enable hardware offloading for wired connections." +msgstr "为有线连接启用硬件加速。" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:178 +msgid "Enable hardware offloading for wireless connections." +msgstr "为无线连接启用硬件加速。" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:177 +msgid "Enable wireless HNAT" +msgstr "启用无线 HNAT" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:124 +msgid "Fast classifier" +msgstr "Fast classifier" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:136 +msgid "Fast classifier connection manager for the shortcut forwarding engine." +msgstr "快速转发引擎(SFE)的 fast classifier 连接管理器。" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:94 +msgid "FastPath Engine" +msgstr "快速转发引擎" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:118 +msgid "Fastpath engine" +msgstr "快速转发引擎" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:122 +msgid "Flow offloading" +msgstr "Flow offloading" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:98 +msgid "Full Cone NAT" +msgstr "全锥形 NAT" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:186 +msgid "Full cone NAT" +msgstr "全锥形 NAT" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:187 +msgid "Full cone NAT (NAT1) can improve gaming performance effectively." +msgstr "Full cone NAT(NAT1)可以有效提升游戏体验。" + +#: applications/luci-app-turboacc/root/usr/share/rpcd/acl.d/luci-app-turboacc.json:3 +msgid "Grant UCI access for luci-app-turboacc" +msgstr "授予 luci-app-turboacc 访问 UCI 配置的权限。" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:145 +msgid "Hardware flow offloading" +msgstr "硬件流量分载" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:158 +msgid "IPv6 acceleration" +msgstr "IPv6 加速" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:128 +msgid "MediaTek HNAT" +msgstr "MediaTek HNAT" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:140 +msgid "MediaTek's open source hardware offloading engine." +msgstr "由联发科实现的开源硬件流量分载引擎。" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:74 +msgid "Open source flow offloading engine (fast path or hardware NAT)." +msgstr "开源流量分载引擎(快速转发或硬件 NAT)。" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:179 +msgid "Redirect to wireless settings" +msgstr "跳转到无线设置" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:146 +msgid "Requires hardware NAT support. Implemented at least for mt7621." +msgstr "需要硬件 NAT 支持。目前 mt7621 已实现。" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:126 +msgid "SFE connection manager" +msgstr "SFE connection manager" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:138 +msgid "Simple connection manager for the shortcut forwarding engine." +msgstr "快速转发引擎(SFE)的简单连接管理器。" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:134 +msgid "Software based offloading for routing/NAT." +msgstr "基于软件的 路由/NAT 分载。" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:102 +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:195 +msgid "TCP CCA" +msgstr "TCP 拥塞控制算法" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:196 +msgid "TCP congestion control algorithm." +msgstr "TCP 拥塞控制算法。" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:119 +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:142 +msgid "The offloading engine for routing/NAT." +msgstr "用于 路由/NAT 的分载引擎。" + +#: applications/luci-app-turboacc/root/usr/share/luci/menu.d/luci-app-turboacc.json:3 +msgid "TurboACC" +msgstr "网络加速" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:73 +msgid "TurboACC settings" +msgstr "网络加速设置" + +#: applications/luci-app-turboacc/htdocs/luci-static/resources/view/turboacc.js:190 +msgid "xt_FULLCONENAT" +msgstr "xt_FULLCONENAT" diff --git a/package/mtk/applications/luci-app-turboacc-mtk/root/etc/config/turboacc b/package/mtk/applications/luci-app-turboacc-mtk/root/etc/config/turboacc new file mode 100644 index 0000000000..b5900d3c9b --- /dev/null +++ b/package/mtk/applications/luci-app-turboacc-mtk/root/etc/config/turboacc @@ -0,0 +1,6 @@ + +config turboacc 'global' + option set '0' + +config turboacc 'config' + diff --git a/package/mtk/applications/luci-app-turboacc-mtk/root/etc/init.d/turboacc b/package/mtk/applications/luci-app-turboacc-mtk/root/etc/init.d/turboacc new file mode 100755 index 0000000000..29fef4e9ef --- /dev/null +++ b/package/mtk/applications/luci-app-turboacc-mtk/root/etc/init.d/turboacc @@ -0,0 +1,67 @@ +#!/bin/sh /etc/rc.common +# Copyright (C) 2018 Lean +# Copyright (C) 2019-2022 Tianling Shen + +START=90 +STOP=10 + +start() { + config_load "turboacc" + + local fastpath + config_get fastpath "config" "fastpath" + + if [ "$fastpath" != "fast_classifier" ] && lsmod | grep -q "fast_classifier"; then + echo "0" > "/sys/fast_classifier/skip_to_bridge_ingress" 2>"/dev/null" + rm -f "/dev/sfe_ipv6" + rmmod "fast_classifier" 2>"/dev/null" + fi + + if [ "$fastpath" != "shortcut_fe_cm" ] && lsmod | grep -q "shortcut_fe_cm"; then + rmmod "shortcut_fe_cm" 2>"/dev/null" + fi + + if [ "$fastpath" != "mediatek_hnat" ] && lsmod | grep -q "mtkhnat"; then + echo "0" > "/sys/kernel/debug/hnat/hook_toggle" 2>"/dev/null" + fi + + case "$fastpath" in + "fast_classifier") + local fastpath_fc_br fastpath_fc_ipv6 + config_get_bool fastpath_fc_br "config" "fastpath_fc_br" "0" + config_get_bool fastpath_fc_ipv6 "config" "fastpath_fc_ipv6" "0" + + lsmod | grep -q "fast_classifier" || modprobe "fast_classifier" 2>"/dev/null" + echo "$fastpath_fc_br" > "/sys/fast_classifier/skip_to_bridge_ingress" 2>"/dev/null" + if [ "$fastpath_fc_ipv6" -eq "1" ]; then + [ -e "/dev/sfe_ipv6" ] || mknod "/dev/sfe_ipv6" "c" "$(cat "/sys/sfe_ipv6/debug_dev")" "0" + else + [ ! -e "/dev/sfe_ipv6" ] || rm -f "/dev/sfe_ipv6" + fi + ;; + "shortcut_fe_cm") + lsmod |grep -q "shortcut_fe_cm" || modprobe "shortcut_fe_cm" 2>"/dev/null" + ;; + "mediatek_hnat") + local fastpath_mh_eth_hnat fastpath_mh_eth_hnat_v6 + config_get_bool fastpath_mh_eth_hnat "config" "fastpath_mh_eth_hnat" "1" + local hnat_path="/sys/kernel/debug/hnat" + echo "$fastpath_mh_eth_hnat" > "$hnat_path/hook_toggle" + if [ "$fastpath_mh_eth_hnat" -eq "1" ]; then + config_get_bool fastpath_mh_eth_hnat_v6 "config" "fastpath_mh_eth_hnat_v6" "1" + echo "8 $fastpath_mh_eth_hnat_v6" > "$hnat_path/hnat_setting" + fi + ;; + esac + + local fullcone + config_get "fullcone" "config" "fullcone" "0" + uci -q set "firewall.@defaults[0].fullcone"="$fullcone" + + local tcpcca + config_get "tcpcca" "config" "tcpcca" "cubic" + sysctl -w net.ipv4.tcp_congestion_control="$tcpcca" >"/dev/null" + + uci -q commit "firewall" + /etc/init.d/firewall restart >"/dev/null" 2>&1 +} diff --git a/package/mtk/applications/luci-app-turboacc-mtk/root/etc/uci-defaults/turboacc b/package/mtk/applications/luci-app-turboacc-mtk/root/etc/uci-defaults/turboacc new file mode 100644 index 0000000000..392b4a6790 --- /dev/null +++ b/package/mtk/applications/luci-app-turboacc-mtk/root/etc/uci-defaults/turboacc @@ -0,0 +1,46 @@ +#!/bin/sh + +[ "$(uci -q get "turboacc.global.set")" -eq "1" ] && exit 0 + +cat <<-EOF > "/etc/config/turboacc" + +config turboacc 'global' + option set '0' + +config turboacc 'config' + option tcpcca 'cubic' + +EOF + +kernel_ver="$(uname -r)" + +if [ -e "/lib/modules/$kernel_ver/mtkhnat.ko" ]; then + uci -q set "turboacc.config.fastpath"="mediatek_hnat" + uci -q set "turboacc.config.fastpath_mh_eth_hnat"="1" + uci -q set "turboacc.config.fastpath_mh_eth_hnat_v6"="1" +elif [ -e "/lib/modules/$kernel_ver/fast-classifier.ko" ]; then + uci -q set "turboacc.config.fastpath"="fast_classifier" + uci -q set "turboacc.config.fastpath_fc_br"="1" + if [ -d "/proc/sys/net/ipv6" ]; then + uci -q set "turboacc.config.fastpath_fc_ipv6"="1" + else + uci -q set "turboacc.config.fastpath_fc_ipv6"="0" + fi +elif [ -e "/lib/modules/$kernel_ver/shortcut-fe-cm.ko" ]; then + uci -q set "turboacc.config.fastpath"="shortcut_fe_cm" +else + uci -q set "turboacc.config.fastpath"="none" +fi + +uci -q set "turboacc.config.fullcone"="0" + +uci -q commit "turboacc" + +uci -q batch <<-EOF >"/dev/null" + delete ucitrack.@turboacc[-1] + add ucitrack turboacc + set ucitrack.@turboacc[-1].init=turboacc + commit ucitrack +EOF + +exit 0 diff --git a/package/mtk/applications/luci-app-turboacc-mtk/root/usr/libexec/rpcd/luci.turboacc b/package/mtk/applications/luci-app-turboacc-mtk/root/usr/libexec/rpcd/luci.turboacc new file mode 100755 index 0000000000..f4741a0d41 --- /dev/null +++ b/package/mtk/applications/luci-app-turboacc-mtk/root/usr/libexec/rpcd/luci.turboacc @@ -0,0 +1,135 @@ +#!/usr/bin/env lua +-- Copyright (C) 2022 ImmortalWrt.org + +local json = require "luci.jsonc" +local fs = require "nixio.fs" +local util = require "luci.util" +local sys = require "luci.sys" + +string.trim = util.trim + +local function readfile(path) + local s = fs.readfile(path) + return s and (s:gsub("^%s+", ""):gsub("%s+$", "")) +end + +local methods = { + getSystemFeatures = { + call = function() + local boardinfo = util.ubus("system", "board") or {} + local features = { + hasIPV6 = fs.access("/proc/net/ipv6_route"), + -- disable FLOWOFFLOADING for mt798x + hasFLOWOFFLOADING = false, + hasFASTCLASSIFIER = fs.access("/lib/modules/" .. boardinfo.kernel .. "/fast-classifier.ko"), + hasSHORTCUTFECM = fs.access("/lib/modules/" .. boardinfo.kernel .. "/shortcut-fe-cm.ko"), + hasMEDIATEKHNAT = fs.access("/lib/modules/" .. boardinfo.kernel .. "/mtkhnat.ko"), + hasXTFULLCONENAT = fs.access("/lib/modules/" .. boardinfo.kernel .. "/xt_FULLCONENAT.ko"), + hasTCPCCA = readfile("/proc/sys/net/ipv4/tcp_available_congestion_control") + } + print(json.stringify(features)) + end + }, + getFastPathStat = { + call = function() + local fptype + if fs.access("/sys/module/xt_FLOWOFFLOAD/refcnt") and + (readfile("/sys/module/xt_FLOWOFFLOAD/refcnt") or "0") ~= "0" then + fptype = "Flow offloading" + elseif fs.stat("/sys/module/fast_classifier", "type") == "dir" then + fptype = "Fast classifier" + elseif fs.stat("/sys/module/shortcut_fe_cm", "type") == "dir" then + fptype = "Shortcut-FE CM" + elseif fs.stat("/sys/kernel/debug/hnat", "type") == "dir" then + local ethernet_hnat = readfile("/sys/kernel/debug/hnat/hook_toggle") + ethernet_hnat = (ethernet_hnat ~= "enabled") and " / Ethernet HNAT Disabled" or "" + + local wireless_hnat = (sys.call("grep -q 'WHNAT=1' '/etc/wireless/mediatek/'*_card*.dat") ~= 0) and " / Wireless HNAT Disabled" or "" + if (ethernet_hnat == "") or (wireless_hnat == "") then + fptype = "MediaTek HNAT" .. ethernet_hnat .. wireless_hnat + end + end + print(json.stringify({ type = fptype })) + end + }, + getFullConeStat = { + call = function() + local fctype + if fs.access("/sys/module/xt_FULLCONENAT/refcnt") and + (readfile("/sys/module/xt_FULLCONENAT/refcnt") or "0") ~= "0" then + fctype = "xt_FULLCONENAT" + elseif sys.call("iptables -t nat -L zone_wan_postrouting | grep -q fullcone") == 0 then + fctype = "Boardcom Fullcone" + end + print(json.stringify({ type = fctype })) + end + }, + getTCPCCAStat = { + call = function() + local ccatype = readfile("/proc/sys/net/ipv4/tcp_congestion_control") + ccatype = ccatype and ccatype:upper() or nil + print(json.stringify({ type = ccatype })) + end + } +} + +local function parseInput() + local parse = json.new() + local done, err + + while true do + local chunk = io.read(4096) + if not chunk then + break + elseif not done and not err then + done, err = parse:parse(chunk) + end + end + + if not done then + print(json.stringify({ error = err or "Incomplete input" })) + os.exit(1) + end + + return parse:get() +end + +local function validateArgs(func, uargs) + local method = methods[func] + if not method then + print(json.stringify({ error = "Method not found" })) + os.exit(1) + end + + if type(uargs) ~= "table" then + print(json.stringify({ error = "Invalid arguments" })) + os.exit(1) + end + + uargs.ubus_rpc_session = nil + + local k, v + local margs = method.args or {} + for k, v in pairs(uargs) do + if margs[k] == nil or + (v ~= nil and type(v) ~= type(margs[k])) + then + print(json.stringify({ error = "Invalid arguments" })) + os.exit(1) + end + end + + return method +end + +if arg[1] == "list" then + local _, method, rv = nil, nil, {} + for _, method in pairs(methods) do rv[_] = method.args or {} end + print((json.stringify(rv):gsub(":%[%]", ":{}"))) +elseif arg[1] == "call" then + local args = parseInput() + local method = validateArgs(arg[2], args) + local result, code = method.call(args) + print((json.stringify(result):gsub("^%[%]$", "{}"))) + os.exit(code or 0) +end diff --git a/package/mtk/applications/luci-app-turboacc-mtk/root/usr/share/luci/menu.d/luci-app-turboacc.json b/package/mtk/applications/luci-app-turboacc-mtk/root/usr/share/luci/menu.d/luci-app-turboacc.json new file mode 100644 index 0000000000..167b628a32 --- /dev/null +++ b/package/mtk/applications/luci-app-turboacc-mtk/root/usr/share/luci/menu.d/luci-app-turboacc.json @@ -0,0 +1,13 @@ +{ + "admin/network/turboacc": { + "title": "TurboACC", + "action": { + "type": "view", + "path": "turboacc" + }, + "depends": { + "acl": [ "luci-app-turboacc" ], + "uci": { "turboacc": true } + } + } +} diff --git a/package/mtk/applications/luci-app-turboacc-mtk/root/usr/share/rpcd/acl.d/luci-app-turboacc.json b/package/mtk/applications/luci-app-turboacc-mtk/root/usr/share/rpcd/acl.d/luci-app-turboacc.json new file mode 100644 index 0000000000..d509e44eb3 --- /dev/null +++ b/package/mtk/applications/luci-app-turboacc-mtk/root/usr/share/rpcd/acl.d/luci-app-turboacc.json @@ -0,0 +1,14 @@ +{ + "luci-app-turboacc": { + "description": "Grant UCI access for luci-app-turboacc", + "read": { + "ubus": { + "luci.turboacc": [ "getSystemFeatures", "getFastPathStat", "getFullConeStat", "getTCPCCAStat" ] + }, + "uci": [ "turboacc" ] + }, + "write": { + "uci": [ "turboacc" ] + } + } +}