From a50cce4e0975afb9c93ffa40eb361825d407c394 Mon Sep 17 00:00:00 2001
From: Matthias Schiffer <mschiffer@universe-factory.net>
Date: Sat, 2 May 2015 22:55:23 +0200
Subject: [PATCH] gluon-mesh-vpn-fastd: make adding or removing the null method
 survive updates (if desired)

---
 package/gluon-mesh-vpn-fastd/check_site.lua   |  1 +
 .../lib/gluon/upgrade/400-mesh-vpn-fastd      | 30 ++++++++++++++++++-
 2 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/package/gluon-mesh-vpn-fastd/check_site.lua b/package/gluon-mesh-vpn-fastd/check_site.lua
index cade1c17c..7a2c4913d 100644
--- a/package/gluon-mesh-vpn-fastd/check_site.lua
+++ b/package/gluon-mesh-vpn-fastd/check_site.lua
@@ -1,6 +1,7 @@
 need_string_array('fastd_mesh_vpn.methods')
 need_number('fastd_mesh_vpn.mtu')
 need_boolean('fastd_mesh_vpn.enabled', false)
+need_boolean('fastd_mesh_vpn.configurable', false)
 
 
 local function check_peer(prefix)
diff --git a/package/gluon-mesh-vpn-fastd/files/lib/gluon/upgrade/400-mesh-vpn-fastd b/package/gluon-mesh-vpn-fastd/files/lib/gluon/upgrade/400-mesh-vpn-fastd
index f370bbf3a..316546bc9 100755
--- a/package/gluon-mesh-vpn-fastd/files/lib/gluon/upgrade/400-mesh-vpn-fastd
+++ b/package/gluon-mesh-vpn-fastd/files/lib/gluon/upgrade/400-mesh-vpn-fastd
@@ -5,6 +5,7 @@ local users = require 'gluon.users'
 local util = require 'gluon.util'
 
 local uci = require('luci.model.uci').cursor()
+local lutil = require 'luci.util'
 
 
 -- The previously used user is removed, we need root privileges to use the packet_mark option
@@ -20,6 +21,33 @@ if not enabled then
 end
 
 
+local methods
+
+if site.fastd_mesh_vpn.configurable then
+  local has_null = lutil.contains(site.fastd_mesh_vpn.methods, 'null')
+
+  local old_methods = uci:get('fastd', 'mesh_vpn', 'method')
+  if old_methods then
+    has_null = lutil.contains(old_methods, 'null')
+  end
+
+
+  methods = {}
+  if has_null then
+    table.insert(methods, 'null')
+  end
+
+  for _, method in ipairs(site.fastd_mesh_vpn.methods) do
+    if method ~= 'null' then
+      table.insert(methods, method)
+    end
+  end
+
+else
+  methods = site.fastd_mesh_vpn.methods
+end
+
+
 uci:section('fastd', 'fastd', 'mesh_vpn',
 	  {
 		  enabled = enabled,
@@ -29,7 +57,7 @@ uci:section('fastd', 'fastd', 'mesh_vpn',
 		  mode = 'tap',
 		  mtu = site.fastd_mesh_vpn.mtu,
 		  secure_handshakes = 1,
-		  method = site.fastd_mesh_vpn.methods,
+		  method = methods,
 		  packet_mark = 1,
 		  status_socket = '/var/run/fastd.mesh_vpn.socket',
 	  }
-- 
GitLab