ソースを参照

Configure unique MAC addresses for all WLAN interfaces

Matthias Schiffer 10 年 前
コミット
1803525745

+ 2 - 2
package/gluon-core/files/usr/lib/lua/gluon/util.lua

@@ -66,8 +66,8 @@ end
 -- Functions and IDs defined so far:
 -- (1, 0): WAN (for mesh-on-WAN)
 -- (1, 1): LAN (for mesh-on-LAN)
--- (2, X): client interface for radioX
--- (3, X): adhoc interface for radioX
+-- (2, n): client interface for the n'th radio
+-- (3, n): adhoc interface for n'th radio
 -- (4, 0): mesh VPN
 function generate_mac(f, i)
   local m1, m2, m3, m4, m5, m6 = string.match(sysconfig.primary_mac, '(%x%x):(%x%x):(%x%x):(%x%x):(%x%x):(%x%x)')

+ 60 - 53
package/gluon-mesh-batman-adv-core/files/lib/gluon/upgrade/mesh-batman-adv-core/invariant/020-wireless

@@ -1,69 +1,76 @@
 #!/usr/bin/lua
 
 local site = require 'gluon.site_config'
-local uci = require 'luci.model.uci'
+local util = require 'gluon.util'
 
-local c = uci.cursor()
+local uci = require('luci.model.uci').cursor()
 
 
-local function configure_radio(device)
-	local radio = device['.name']
-	local hwmode = c:get('wireless', radio, 'hwmode')
+local function configure_radio(radio, index, config)
+  uci:delete('wireless', radio, 'disabled')
 
-	local config
-	if hwmode == '11g' or hwmode == '11ng' then
-		config = site.wifi24
-	elseif hwmode == '11a' or hwmode == '11na' then
-		config = site.wifi5
-	else
-		return true
-	end
+  uci:set('wireless', radio, 'channel', config.channel)
+  uci:set('wireless', radio, 'htmode', config.htmode)
+  uci:set('wireless', radio, 'country', site.regdom)
+
+  local client = 'client_' .. radio
+  uci:delete('wireless', client)
+  uci:section('wireless', 'wifi-iface', client,
+	      {
+		device = radio,
+		network = 'client',
+		mode = 'ap',
+		ssid = config.ssid,
+		macaddr = util.generate_mac(2, index),
+	      }
+  )
 
-	c:delete('wireless', radio, 'disabled')
+  local mesh = 'mesh_' .. radio
+  uci:delete('network', mesh)
+  uci:section('network', 'interface', mesh,
+	      {
+		proto = 'batadv',
+		mtu = '1528',
+		mesh = 'bat0',
+	      }
+  )
 
-	c:set('wireless', radio, 'channel', config.channel)
-	c:set('wireless', radio, 'htmode', config.htmode)
-	c:set('wireless', radio, 'country', site.regdom)
+  uci:delete('wireless', mesh)
+  uci:section('wireless', 'wifi-iface', mesh,
+	      {
+		device = radio,
+		network = mesh,
+		mode = 'adhoc',
+		ssid = config.mesh_ssid,
+		bssid = config.mesh_bssid,
+		macaddr = util.generate_mac(3, index),
+		mcast_rate = config.mesh_mcast_rate,
+	      }
+  )
+end
 
-	local client = 'client_' .. radio
-	c:delete('wireless', client)
-	c:section('wireless', 'wifi-iface', client,
-		  {
-			  device = radio,
-			  network = 'client',
-			  mode = 'ap',
-			  ssid = config.ssid,
-		  }
-	)
 
-	local mesh = 'mesh_' .. radio
-	c:delete('network', mesh)
-	c:section('network', 'interface', mesh,
-		  {
-			  proto = 'batadv',
-			  mtu = '1528',
-			  mesh = 'bat0',
-		  }
-	)
+local radios = {}
 
-	c:delete('wireless', mesh)
-	c:section('wireless', 'wifi-iface', mesh,
-		  {
-			  device = radio,
-			  network = mesh,
-			  mode = 'adhoc',
-			  ssid = config.mesh_ssid,
-			  bssid = config.mesh_bssid,
-			  mcast_rate = config.mesh_mcast_rate,
-		  }
-	)
+uci:foreach('wireless', 'wifi-device',
+	    function(s)
+	      table.insert(radios, s['.name'])
+	    end
+)
 
-	return true
+for index, radio in ipairs(radios) do
+	local hwmode = uci:get('wireless', radio, 'hwmode')
+
+	local config
+	if hwmode == '11g' or hwmode == '11ng' then
+	  configure_radio(radio, index, site.wifi24)
+	elseif hwmode == '11a' or hwmode == '11na' then
+	  configure_radio(radio, index, site.wifi5)
+	end
 end
 
-c:foreach('wireless', 'wifi-device', configure_radio)
 
-c:save('wireless')
-c:save('network')
-c:commit('wireless')
-c:commit('network')
+uci:save('wireless')
+uci:save('network')
+uci:commit('wireless')
+uci:commit('network')