From d05cee5b55f4c5202516ad1f500986324941323d Mon Sep 17 00:00:00 2001
From: Matthias Schiffer <mschiffer@universe-factory.net>
Date: Wed, 31 Aug 2016 01:18:10 +0200
Subject: [PATCH] gluon-mesh-batman-adv-core: explicitly set primary MAC
 address using a dummy interface

Fixes #834
---
 package/gluon-mesh-batman-adv-core/Makefile   |  2 +-
 .../config_mesh_interface                     | 20 +++++++++++++++++++
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/package/gluon-mesh-batman-adv-core/Makefile b/package/gluon-mesh-batman-adv-core/Makefile
index bd6ab4906..efcf16981 100644
--- a/package/gluon-mesh-batman-adv-core/Makefile
+++ b/package/gluon-mesh-batman-adv-core/Makefile
@@ -13,7 +13,7 @@ define Package/gluon-mesh-batman-adv-core
   SECTION:=gluon
   CATEGORY:=Gluon
   TITLE:=Support for batman-adv meshing (core)
-  DEPENDS:=+gluon-core +libgluonutil +gluon-client-bridge +firewall +libiwinfo
+  DEPENDS:=+gluon-core +libgluonutil +gluon-client-bridge +firewall +libiwinfo +kmod-dummy
 endef
 
 define Build/Prepare
diff --git a/package/gluon-mesh-batman-adv-core/luasrc/lib/gluon/mesh-batman-adv-core/config_mesh_interface b/package/gluon-mesh-batman-adv-core/luasrc/lib/gluon/mesh-batman-adv-core/config_mesh_interface
index ad2d11d4e..bb069497e 100755
--- a/package/gluon-mesh-batman-adv-core/luasrc/lib/gluon/mesh-batman-adv-core/config_mesh_interface
+++ b/package/gluon-mesh-batman-adv-core/luasrc/lib/gluon/mesh-batman-adv-core/config_mesh_interface
@@ -15,6 +15,15 @@ if cmd == 'setup' then
 
 	local mtu = tonumber(arg[2])
 
+	if os.execute('ip link show primary0 >/dev/null 2>&1') ~= 0 then
+		os.execute([[
+			ip link add primary0 type dummy
+			echo 1 > /proc/sys/net/ipv6/conf/primary0/disable_ipv6
+			ip link set primary0 address ]] .. util.generate_mac(3) .. [[ mtu ]] .. mtu .. [[ up
+			echo 'bat0' > /sys/class/net/primary0/batman_adv/mesh_iface
+		]])
+	end
+
 	if fixed_mtu == 0 then
 		local lower = fs.glob('/sys/class/net/' .. ifname .. '/lower_*/wireless')()
 		if lower then
@@ -41,4 +50,15 @@ elseif cmd == 'teardown' then
 		file:close()
 	end
 
+	local other = false
+	for lower in fs.glob('/sys/class/net/bat0/lower_*') do
+		if lower ~= '/sys/class/net/bat0/lower_primary0' then
+			other = true
+			break
+		end
+	end
+
+	if not other then
+		os.execute('ip link del primary0')
+	end
 end
-- 
GitLab