From 15eeb86f426c7d171f2a5f80c9ea8f50ee17fadd Mon Sep 17 00:00:00 2001
From: Matthias Schiffer <mschiffer@universe-factory.net>
Date: Sun, 7 Mar 2021 20:13:41 +0100
Subject: [PATCH] gluon-{,web-}mesh-vpn-fastd: add support for null@l2tp method

THe "null" and "null@l2tp" methods are considered equivalent and always
added and removed together when the method list is "configurable".
"null@l2tp" is added before "null", so it is preferred when the peer
supports both.
---
 package/gluon-mesh-vpn-fastd/check_site.lua            |  2 +-
 .../luasrc/lib/gluon/upgrade/400-mesh-vpn-fastd        | 10 ++++++----
 .../gluon/config-mode/model/admin/mesh_vpn_fastd.lua   |  5 +++--
 3 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/package/gluon-mesh-vpn-fastd/check_site.lua b/package/gluon-mesh-vpn-fastd/check_site.lua
index 57cc7bb1c..6f3c0832d 100644
--- a/package/gluon-mesh-vpn-fastd/check_site.lua
+++ b/package/gluon-mesh-vpn-fastd/check_site.lua
@@ -1,4 +1,4 @@
-local fastd_methods = {'salsa2012+umac', 'null+salsa2012+umac', 'null'}
+local fastd_methods = {'salsa2012+umac', 'null+salsa2012+umac', 'null@l2tp', 'null'}
 need_array_of({'mesh_vpn', 'fastd', 'methods'}, fastd_methods)
 need_boolean(in_site({'mesh_vpn', 'fastd', 'configurable'}), false)
 
diff --git a/package/gluon-mesh-vpn-fastd/luasrc/lib/gluon/upgrade/400-mesh-vpn-fastd b/package/gluon-mesh-vpn-fastd/luasrc/lib/gluon/upgrade/400-mesh-vpn-fastd
index 5fed1e8c4..1af8218ef 100755
--- a/package/gluon-mesh-vpn-fastd/luasrc/lib/gluon/upgrade/400-mesh-vpn-fastd
+++ b/package/gluon-mesh-vpn-fastd/luasrc/lib/gluon/upgrade/400-mesh-vpn-fastd
@@ -17,20 +17,22 @@ end
 local methods
 
 if site.mesh_vpn.fastd.configurable(false) then
-	local has_null = util.contains(site.mesh_vpn.fastd.methods(), 'null')
+	local site_methods = site.mesh_vpn.fastd.methods()
+	local has_null = util.contains(site_methods, 'null@l2tp') or util.contains(site_methods, 'null')
 
 	local old_methods = uci:get('fastd', 'mesh_vpn', 'method')
 	if old_methods then
-		has_null = util.contains(old_methods, 'null')
+		has_null = util.contains(old_methods, 'null@l2tp') or util.contains(old_methods, 'null')
 	end
 
 	methods = {}
 	if has_null then
+		table.insert(methods, 'null@l2tp')
 		table.insert(methods, 'null')
 	end
 
-	for _, method in ipairs(site.mesh_vpn.fastd.methods()) do
-		if method ~= 'null' then
+	for _, method in ipairs(site_methods) do
+		if method ~= 'null@l2tp' and method ~= 'null' then
 			table.insert(methods, method)
 		end
 	end
diff --git a/package/gluon-web-mesh-vpn-fastd/luasrc/lib/gluon/config-mode/model/admin/mesh_vpn_fastd.lua b/package/gluon-web-mesh-vpn-fastd/luasrc/lib/gluon/config-mode/model/admin/mesh_vpn_fastd.lua
index ad890c317..9243ec92a 100644
--- a/package/gluon-web-mesh-vpn-fastd/luasrc/lib/gluon/config-mode/model/admin/mesh_vpn_fastd.lua
+++ b/package/gluon-web-mesh-vpn-fastd/luasrc/lib/gluon/config-mode/model/admin/mesh_vpn_fastd.lua
@@ -10,7 +10,7 @@ mode.package = "gluon-web-mesh-vpn-fastd"
 mode.template = "mesh-vpn-fastd"
 
 local methods = uci:get('fastd', 'mesh_vpn', 'method')
-if util.contains(methods, 'null') then
+if util.contains(methods, 'null@l2tp') or util.contains(methods, 'null') then
 	-- performance mode will only be used as default, if it is present in site.mesh_vpn.fastd.methods
 	mode.default = 'performance'
 else
@@ -24,11 +24,12 @@ function mode:write(data)
 	-- if performance mode was selected, and the method 'null' was not present in the original table, it will be added
 	local site_methods = {}
 	if data == 'performance' then
+		table.insert(site_methods, 'null@l2tp')
 		table.insert(site_methods, 'null')
 	end
 
 	for _, method in ipairs(site.mesh_vpn.fastd.methods()) do
-		if method ~= 'null' then
+		if method ~= 'null@l2tp' and method ~= 'null' then
 			table.insert(site_methods, method)
 		end
 	end
-- 
GitLab