Configure unique MAC addresses for all WLAN interfaces
This commit is contained in:
parent
b51e1063b7
commit
1803525745
@ -66,8 +66,8 @@ end
|
|||||||
-- Functions and IDs defined so far:
|
-- Functions and IDs defined so far:
|
||||||
-- (1, 0): WAN (for mesh-on-WAN)
|
-- (1, 0): WAN (for mesh-on-WAN)
|
||||||
-- (1, 1): LAN (for mesh-on-LAN)
|
-- (1, 1): LAN (for mesh-on-LAN)
|
||||||
-- (2, X): client interface for radioX
|
-- (2, n): client interface for the n'th radio
|
||||||
-- (3, X): adhoc interface for radioX
|
-- (3, n): adhoc interface for n'th radio
|
||||||
-- (4, 0): mesh VPN
|
-- (4, 0): mesh VPN
|
||||||
function generate_mac(f, i)
|
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)')
|
local m1, m2, m3, m4, m5, m6 = string.match(sysconfig.primary_mac, '(%x%x):(%x%x):(%x%x):(%x%x):(%x%x):(%x%x)')
|
||||||
|
@ -1,44 +1,33 @@
|
|||||||
#!/usr/bin/lua
|
#!/usr/bin/lua
|
||||||
|
|
||||||
local site = require 'gluon.site_config'
|
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 function configure_radio(radio, index, config)
|
||||||
local radio = device['.name']
|
uci:delete('wireless', radio, 'disabled')
|
||||||
local hwmode = c:get('wireless', radio, 'hwmode')
|
|
||||||
|
|
||||||
local config
|
uci:set('wireless', radio, 'channel', config.channel)
|
||||||
if hwmode == '11g' or hwmode == '11ng' then
|
uci:set('wireless', radio, 'htmode', config.htmode)
|
||||||
config = site.wifi24
|
uci:set('wireless', radio, 'country', site.regdom)
|
||||||
elseif hwmode == '11a' or hwmode == '11na' then
|
|
||||||
config = site.wifi5
|
|
||||||
else
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
c:delete('wireless', radio, 'disabled')
|
|
||||||
|
|
||||||
c:set('wireless', radio, 'channel', config.channel)
|
|
||||||
c:set('wireless', radio, 'htmode', config.htmode)
|
|
||||||
c:set('wireless', radio, 'country', site.regdom)
|
|
||||||
|
|
||||||
local client = 'client_' .. radio
|
local client = 'client_' .. radio
|
||||||
c:delete('wireless', client)
|
uci:delete('wireless', client)
|
||||||
c:section('wireless', 'wifi-iface', client,
|
uci:section('wireless', 'wifi-iface', client,
|
||||||
{
|
{
|
||||||
device = radio,
|
device = radio,
|
||||||
network = 'client',
|
network = 'client',
|
||||||
mode = 'ap',
|
mode = 'ap',
|
||||||
ssid = config.ssid,
|
ssid = config.ssid,
|
||||||
|
macaddr = util.generate_mac(2, index),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
local mesh = 'mesh_' .. radio
|
local mesh = 'mesh_' .. radio
|
||||||
c:delete('network', mesh)
|
uci:delete('network', mesh)
|
||||||
c:section('network', 'interface', mesh,
|
uci:section('network', 'interface', mesh,
|
||||||
{
|
{
|
||||||
proto = 'batadv',
|
proto = 'batadv',
|
||||||
mtu = '1528',
|
mtu = '1528',
|
||||||
@ -46,24 +35,42 @@ local function configure_radio(device)
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
c:delete('wireless', mesh)
|
uci:delete('wireless', mesh)
|
||||||
c:section('wireless', 'wifi-iface', mesh,
|
uci:section('wireless', 'wifi-iface', mesh,
|
||||||
{
|
{
|
||||||
device = radio,
|
device = radio,
|
||||||
network = mesh,
|
network = mesh,
|
||||||
mode = 'adhoc',
|
mode = 'adhoc',
|
||||||
ssid = config.mesh_ssid,
|
ssid = config.mesh_ssid,
|
||||||
bssid = config.mesh_bssid,
|
bssid = config.mesh_bssid,
|
||||||
|
macaddr = util.generate_mac(3, index),
|
||||||
mcast_rate = config.mesh_mcast_rate,
|
mcast_rate = config.mesh_mcast_rate,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
return true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
c:foreach('wireless', 'wifi-device', configure_radio)
|
|
||||||
|
|
||||||
c:save('wireless')
|
local radios = {}
|
||||||
c:save('network')
|
|
||||||
c:commit('wireless')
|
uci:foreach('wireless', 'wifi-device',
|
||||||
c:commit('network')
|
function(s)
|
||||||
|
table.insert(radios, s['.name'])
|
||||||
|
end
|
||||||
|
)
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
uci:save('wireless')
|
||||||
|
uci:save('network')
|
||||||
|
uci:commit('wireless')
|
||||||
|
uci:commit('network')
|
||||||
|
Loading…
Reference in New Issue
Block a user