Skip to content

Commit 20ab814

Browse files
committed
ffda-mesh-vpn-fastd-sqm: add package
This package allows to enable SQM instead of simple-tc on fastd mesh vpn interfaces. SQM is only enabled if the device has a sufficient amount of system-memory, namely at least 256MB. Signed-off-by: David Bauer <[email protected]>
1 parent 43c4e6b commit 20ab814

File tree

3 files changed

+83
-0
lines changed

3 files changed

+83
-0
lines changed

ffda-mesh-vpn-fastd-sqm/Makefile

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
include $(TOPDIR)/rules.mk
2+
3+
PKG_NAME:=ffda-mesh-vpn-fastd-sqm
4+
PKG_VERSION:=1.0.0
5+
PKG_RELEASE:=1
6+
7+
PKG_MAINTAINER:=David Bauer <[email protected]>
8+
PKG_LICENSE:=GPL-2.0-or-later
9+
10+
include $(TOPDIR)/../package/gluon.mk
11+
12+
define Package/ffda-mesh-vpn-fastd-sqm
13+
TITLE:=Enable SQM instead of simple-tc on fastd mesh vpn interface
14+
DEPENDS:=+gluon-mesh-vpn-fastd +sqm-scripts
15+
endef
16+
17+
define Package/ffda-mesh-vpn-fastd-sqm/description
18+
Enable SQM instead of simple-tc on fastd mesh vpn interface
19+
endef
20+
21+
$(eval $(call BuildPackageGluon,ffda-mesh-vpn-fastd-sqm))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
config settings settings
2+
option enabled '0'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/lua
2+
3+
-- Run this after 500-mesh-vpn!
4+
5+
local uci = require('simple-uci').cursor()
6+
7+
local site = require 'gluon.site'
8+
local vpn_core = require 'gluon.mesh-vpn'
9+
10+
local function get_mem_total()
11+
for line in io.lines('/proc/meminfo') do
12+
local match = line:match('^MemTotal:%s+(%d+)')
13+
if match then
14+
return tonumber(match)
15+
end
16+
end
17+
end
18+
19+
local function configure_sqm()
20+
local limit_enabled = uci:get_bool('gluon', 'mesh_vpn', 'limit_enabled')
21+
local limit_downstream = uci:get('gluon', 'mesh_vpn', 'limit_ingress')
22+
local limit_upstream = uci:get('gluon', 'mesh_vpn', 'limit_egress')
23+
24+
-- Only enable if we have sufficient RAM (256MB or more)
25+
if get_mem_total() < 240*1024 then
26+
return
27+
end
28+
29+
-- Only enable if we actually have a limit configured
30+
if not limit_enabled then
31+
return
32+
end
33+
34+
-- Disable simple-tc
35+
uci:set('simple-tc', 'mesh_vpn', 'enabled', '0')
36+
37+
-- Create SQM configuration
38+
uci:section('sqm', 'queue', 'mesh_vpn', {
39+
interface = vpn_core.get_interface(),
40+
enabled = true,
41+
upload = limit_upstream,
42+
download = limit_downstream,
43+
qdisc = 'cake',
44+
script = 'piece_of_cake.qos',
45+
debug_logging = '0',
46+
verbosity = '5',
47+
})
48+
end
49+
50+
-- Ensure existing SQM settings are cleared
51+
uci:delete('sqm', 'mesh_vpn')
52+
53+
-- Enable SQM if configured in site.conf or user-enabled in uci
54+
local site_state = site.mesh_vpn.fastd.sqm()
55+
if uci:get_bool('ffda-mesh-vpn-sqm', 'settings', 'enabled') or site_state == true then
56+
configure_sqm()
57+
end
58+
59+
uci:save('simple-tc')
60+
uci:save('sqm')

0 commit comments

Comments
 (0)