gluon-mesh-batman-adv-core: move config not specific to batman-adv to gluon-core

This commit is contained in:
Matthias Schiffer 2016-05-01 14:12:23 +02:00
parent d1e6dfb7e3
commit 8434896014
No known key found for this signature in database
GPG Key ID: 16EF3F64CB201D9C
6 changed files with 177 additions and 187 deletions

View File

@ -1,10 +1,11 @@
#!/usr/bin/lua
local util = require 'gluon.util'
local uci = require('luci.model.uci').cursor()
local site = require 'gluon.site_config'
local sysconfig = require 'gluon.sysconfig'
local uci = require('luci.model.uci').cursor()
-- Initial
if not sysconfig.gluon_version then
uci:delete_all('wireless', 'wifi-iface')
@ -18,30 +19,178 @@ local function get_channel(radio, config)
end
end
local function configure_radio(radio, index, config)
if config then
local channel = get_channel(radio, config)
uci:delete('wireless', radio, 'disabled')
uci:set('wireless', radio, 'channel', channel)
uci:set('wireless', radio, 'htmode', 'HT20')
uci:set('wireless', radio, 'country', site.regdom)
if config.supported_rates then
uci:set_list('wireless', radio, 'supported_rates', config.supported_rates)
else
uci:delete('wireless', radio, 'supported_rates')
end
if config.basic_rate then
uci:set_list('wireless', radio, 'basic_rate', config.basic_rate)
else
uci:delete('wireless', radio, 'basic_rate')
end
local function is_disabled(name)
if uci:get('wireless', name) then
return uci:get_bool('wireless', name, 'disabled')
end
end
-- Returns the first argument that is not nil; don't call without any non-nil arguments!
local function first_non_nil(first, ...)
if first ~= nil then
return first
else
return first_non_nil(...)
end
end
local function configure_ibss(config, radio, index, suffix, disabled)
local name = 'ibss_' .. radio
uci:delete('network', name)
uci:delete('network', name .. '_vlan')
uci:delete('wireless', name)
if not config then
return
end
local macaddr = util.get_wlan_mac(radio, index, 3)
if not macaddr then
return
end
if config.vlan then
uci:section('network', 'interface', name,
{
proto = 'none',
}
)
uci:section('network', 'interface', name .. '_vlan',
{
ifname = '@' .. name .. '.' .. config.vlan,
proto = 'gluon_mesh',
}
)
else
uci:section('network', 'interface', name,
{
proto = 'gluon_mesh',
}
)
end
uci:section('wireless', 'wifi-iface', name,
{
device = radio,
network = name,
mode = 'adhoc',
ssid = config.ssid,
bssid = config.bssid,
macaddr = macaddr,
mcast_rate = config.mcast_rate,
ifname = suffix and 'ibss' .. suffix,
disabled = disabled and 1 or 0,
}
)
end
local function configure_mesh(config, radio, index, suffix, disabled)
local name = 'mesh_' .. radio
local macfilter = uci:get('wireless', name, 'macfilter')
local maclist = uci:get('wireless', name, 'maclist')
uci:delete('network', name)
uci:delete('wireless', name)
if not config then
return
end
local macaddr = util.get_wlan_mac(radio, index, 2)
if not macaddr then
return
end
uci:section('network', 'interface', name,
{
proto = 'gluon_mesh',
}
)
uci:section('wireless', 'wifi-iface', name,
{
device = radio,
network = name,
mode = 'mesh',
mesh_id = config.id,
mesh_fwding = 0,
macaddr = macaddr,
mcast_rate = config.mcast_rate,
ifname = suffix and 'mesh' .. suffix,
disabled = disabled and 1 or 0,
macfilter = macfilter,
maclist = maclist,
}
)
end
local function configure_radio(radio, index, config)
if not config then
return
end
local suffix = radio:match('^radio(%d+)$')
if not suffix then
return
end
local channel = get_channel(radio, config)
uci:delete('wireless', radio, 'disabled')
uci:set('wireless', radio, 'channel', channel)
uci:set('wireless', radio, 'htmode', 'HT20')
uci:set('wireless', radio, 'country', site.regdom)
if config.supported_rates then
uci:set_list('wireless', radio, 'supported_rates', config.supported_rates)
else
uci:delete('wireless', radio, 'supported_rates')
end
if config.basic_rate then
uci:set_list('wireless', radio, 'basic_rate', config.basic_rate)
else
uci:delete('wireless', radio, 'basic_rate')
end
local ibss_disabled = is_disabled('ibss_' .. radio)
local mesh_disabled = is_disabled('mesh_' .. radio)
configure_ibss(config.ibss, radio, index, suffix,
first_non_nil(
ibss_disabled,
mesh_disabled,
(config.ibss or {}).disabled, -- will be nil if config.ibss or config.ibss.disabled is unset
false
)
)
configure_mesh(config.mesh, radio, index, suffix,
first_non_nil(
mesh_disabled,
ibss_disabled,
(config.mesh or {}).disabled, -- will be nil if config.mesh or config.mesh.disabled is unset
false
)
)
end
util.iterate_radios(configure_radio)
if uci:get('system', 'rssid_wlan0') then
if uci:get('wireless', 'mesh_radio0') then
uci:set('system', 'rssid_wlan0', 'dev', 'mesh0')
else
uci:set('system', 'rssid_wlan0', 'dev', 'ibss0')
end
uci:save('system')
end
uci:save('wireless')
uci:save('network')

View File

@ -1,12 +1,10 @@
#!/usr/bin/lua
local site = require 'gluon.site_config'
local uci = require 'luci.model.uci'
local uci = require('luci.model.uci').cursor()
local c = uci.cursor()
if not c:get('network', 'mesh_wan') then
c:section('network', 'interface', 'mesh_wan', {
if not uci:get('network', 'mesh_wan') then
uci:section('network', 'interface', 'mesh_wan', {
ifname = 'br-wan',
proto = 'gluon_mesh',
transitive = 1,
@ -15,4 +13,4 @@ if not c:get('network', 'mesh_wan') then
})
end
c:save('network')
uci:save('network')

View File

@ -18,7 +18,6 @@ uci:section('network', 'interface', 'mesh_lan', {
proto = 'gluon_mesh',
transitive = 1,
fixed_mtu = 1,
macaddr = util.get_mac(2),
})
if uci:get('network', 'mesh_lan', 'auto') == nil then

View File

@ -4,6 +4,7 @@ local util = require 'gluon.util'
local uci = require('luci.model.uci').cursor()
-- fix up duplicate mac addresses (for mesh-on-WAN)
-- fix up duplicate mac addresses (for meshing)
uci:set('network', 'wan', 'macaddr', util.get_mac(1))
uci:set('network', 'mesh_lan', 'macaddr', util.get_mac(2))
uci:save('network')

View File

@ -1,144 +0,0 @@
#!/usr/bin/lua
local site = require 'gluon.site_config'
local util = require 'gluon.util'
local uci = require('luci.model.uci').cursor()
local function is_disabled(name)
if uci:get('wireless', name) then
return uci:get_bool('wireless', name, 'disabled')
end
end
-- Returns the first argument that is not nil; don't call without any non-nil arguments!
local function first_non_nil(first, ...)
if first ~= nil then
return first
else
return first_non_nil(...)
end
end
local function configure_ibss(config, radio, index, suffix, disabled)
local name = 'ibss_' .. radio
uci:delete('network', name)
uci:delete('network', name .. '_vlan')
uci:delete('wireless', name)
if not config then
return
end
local macaddr = util.get_wlan_mac(radio, index, 3)
if not macaddr then
return
end
if config.vlan then
uci:section('network', 'interface', name,
{
proto = 'none',
}
)
uci:section('network', 'interface', name .. '_vlan',
{
ifname = '@' .. name .. '.' .. config.vlan,
proto = 'gluon_mesh',
}
)
else
uci:section('network', 'interface', name,
{
proto = 'gluon_mesh',
}
)
end
uci:section('wireless', 'wifi-iface', name,
{
device = radio,
network = name,
mode = 'adhoc',
ssid = config.ssid,
bssid = config.bssid,
macaddr = macaddr,
mcast_rate = config.mcast_rate,
ifname = suffix and 'ibss' .. suffix,
disabled = disabled and 1 or 0,
}
)
end
local function configure_mesh(config, radio, index, suffix, disabled)
local name = 'mesh_' .. radio
local macfilter = uci:get('wireless', name, 'macfilter')
local maclist = uci:get('wireless', name, 'maclist')
uci:delete('network', name)
uci:delete('wireless', name)
if not config then
return
end
local macaddr = util.get_wlan_mac(radio, index, 2)
if not macaddr then
return
end
uci:section('network', 'interface', name,
{
proto = 'gluon_mesh',
}
)
uci:section('wireless', 'wifi-iface', name,
{
device = radio,
network = name,
mode = 'mesh',
mesh_id = config.id,
mesh_fwding = 0,
macaddr = macaddr,
mcast_rate = config.mcast_rate,
ifname = suffix and 'mesh' .. suffix,
disabled = disabled and 1 or 0,
macfilter = macfilter,
maclist = maclist,
}
)
end
local function configure_radio(radio, index, config)
local suffix = radio:match('^radio(%d+)$')
local ibss_disabled = is_disabled('ibss_' .. radio)
local mesh_disabled = is_disabled('mesh_' .. radio)
configure_ibss(config.ibss, radio, index, suffix,
first_non_nil(
ibss_disabled,
mesh_disabled,
(config.ibss or {}).disabled, -- will be nil if config.ibss or config.ibss.disabled is unset
false
)
)
configure_mesh(config.mesh, radio, index, suffix,
first_non_nil(
mesh_disabled,
ibss_disabled,
(config.mesh or {}).disabled, -- will be nil if config.mesh or config.mesh.disabled is unset
false
)
)
end
util.iterate_radios(configure_radio)
uci:save('wireless')
uci:save('network')

View File

@ -1,13 +0,0 @@
#!/usr/bin/lua
local uci = require('luci.model.uci').cursor()
if uci:get('system', 'rssid_wlan0') then
if uci:get('wireless', 'mesh_radio0') then
uci:set('system', 'rssid_wlan0', 'dev', 'mesh0')
else
uci:set('system', 'rssid_wlan0', 'dev', 'ibss0')
end
uci:save('system')
end