gluon-core: rename iterate_radios() to foreach_radio(), pass whole radio section
Allows to remove some redundant UCI lookups.
This commit is contained in:
parent
ffa5bdd716
commit
d61f6a1e85
@ -13,13 +13,18 @@ local function is_disabled(config, name)
|
|||||||
return config.disabled(false)
|
return config.disabled(false)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function configure_client(config, radio, index, suffix)
|
util.foreach_radio(uci, function(radio, index, config)
|
||||||
local name = 'client_' .. radio
|
local radio_name = radio['.name']
|
||||||
local disabled = is_disabled(config, name)
|
|
||||||
|
local name = 'client_' .. radio_name
|
||||||
|
local suffix = radio_name:match('^radio(%d+)$')
|
||||||
|
|
||||||
|
local ap = config.ap
|
||||||
|
local disabled = is_disabled(ap, name)
|
||||||
|
|
||||||
uci:delete('wireless', name)
|
uci:delete('wireless', name)
|
||||||
|
|
||||||
if not config() then
|
if not ap() then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -29,22 +34,14 @@ local function configure_client(config, radio, index, suffix)
|
|||||||
end
|
end
|
||||||
|
|
||||||
uci:section('wireless', 'wifi-iface', name, {
|
uci:section('wireless', 'wifi-iface', name, {
|
||||||
device = radio,
|
device = radio_name,
|
||||||
network = 'client',
|
network = 'client',
|
||||||
mode = 'ap',
|
mode = 'ap',
|
||||||
ssid = config.ssid(),
|
ssid = ap.ssid(),
|
||||||
macaddr = macaddr,
|
macaddr = macaddr,
|
||||||
ifname = suffix and 'client' .. suffix,
|
ifname = suffix and 'client' .. suffix,
|
||||||
disabled = disabled or false,
|
disabled = disabled or false,
|
||||||
})
|
})
|
||||||
end
|
end)
|
||||||
|
|
||||||
local function configure_radio(radio, index, config)
|
|
||||||
local suffix = radio:match('^radio(%d+)$')
|
|
||||||
|
|
||||||
configure_client(config.ap, radio, index, suffix)
|
|
||||||
end
|
|
||||||
|
|
||||||
util.iterate_radios(uci, configure_radio)
|
|
||||||
|
|
||||||
uci:save('wireless')
|
uci:save('wireless')
|
||||||
|
@ -14,7 +14,7 @@ end
|
|||||||
local function get_channel(radio, config)
|
local function get_channel(radio, config)
|
||||||
local channel
|
local channel
|
||||||
if uci:get_first('gluon-core', 'wireless', 'preserve_channels') then
|
if uci:get_first('gluon-core', 'wireless', 'preserve_channels') then
|
||||||
channel = uci:get('wireless', radio, 'channel')
|
channel = radio.channel
|
||||||
end
|
end
|
||||||
|
|
||||||
return channel or config.channel()
|
return channel or config.channel()
|
||||||
@ -39,7 +39,8 @@ end
|
|||||||
|
|
||||||
|
|
||||||
local function configure_ibss(config, radio, index, suffix, disabled)
|
local function configure_ibss(config, radio, index, suffix, disabled)
|
||||||
local name = 'ibss_' .. radio
|
local radio_name = radio['.name']
|
||||||
|
local name = 'ibss_' .. radio_name
|
||||||
|
|
||||||
uci:delete('network', name)
|
uci:delete('network', name)
|
||||||
uci:delete('network', name .. '_vlan')
|
uci:delete('network', name .. '_vlan')
|
||||||
@ -70,7 +71,7 @@ local function configure_ibss(config, radio, index, suffix, disabled)
|
|||||||
end
|
end
|
||||||
|
|
||||||
uci:section('wireless', 'wifi-iface', name, {
|
uci:section('wireless', 'wifi-iface', name, {
|
||||||
device = radio,
|
device = radio_name,
|
||||||
network = name,
|
network = name,
|
||||||
mode = 'adhoc',
|
mode = 'adhoc',
|
||||||
ssid = config.ssid,
|
ssid = config.ssid,
|
||||||
@ -83,7 +84,9 @@ local function configure_ibss(config, radio, index, suffix, disabled)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function configure_mesh(config, radio, index, suffix, disabled)
|
local function configure_mesh(config, radio, index, suffix, disabled)
|
||||||
local name = 'mesh_' .. radio
|
local radio_name = radio['.name']
|
||||||
|
local name = 'mesh_' .. radio_name
|
||||||
|
|
||||||
local macfilter = uci:get('wireless', name, 'macfilter')
|
local macfilter = uci:get('wireless', name, 'macfilter')
|
||||||
local maclist = uci:get('wireless', name, 'maclist')
|
local maclist = uci:get('wireless', name, 'maclist')
|
||||||
|
|
||||||
@ -105,7 +108,7 @@ local function configure_mesh(config, radio, index, suffix, disabled)
|
|||||||
})
|
})
|
||||||
|
|
||||||
uci:section('wireless', 'wifi-iface', name, {
|
uci:section('wireless', 'wifi-iface', name, {
|
||||||
device = radio,
|
device = radio_name,
|
||||||
network = name,
|
network = name,
|
||||||
mode = 'mesh',
|
mode = 'mesh',
|
||||||
mesh_id = config.id,
|
mesh_id = config.id,
|
||||||
@ -120,7 +123,8 @@ local function configure_mesh(config, radio, index, suffix, disabled)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function fixup_wan(radio, index)
|
local function fixup_wan(radio, index)
|
||||||
local name = 'wan_' .. radio
|
local radio_name = radio['.name']
|
||||||
|
local name = 'wan_' .. radio_name
|
||||||
|
|
||||||
if not uci:get('wireless', name) then
|
if not uci:get('wireless', name) then
|
||||||
return
|
return
|
||||||
@ -134,31 +138,33 @@ local function fixup_wan(radio, index)
|
|||||||
uci:set('wireless', name, 'macaddr', macaddr)
|
uci:set('wireless', name, 'macaddr', macaddr)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function configure_radio(radio, index, config)
|
util.foreach_radio(uci, function(radio, index, config)
|
||||||
|
local radio_name = radio['.name']
|
||||||
|
|
||||||
if not config() then
|
if not config() then
|
||||||
uci:set('wireless', radio, 'disabled', true)
|
uci:set('wireless', radio_name, 'disabled', true)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local suffix = radio:match('^radio(%d+)$')
|
local suffix = radio_name:match('^radio(%d+)$')
|
||||||
if not suffix then
|
if not suffix then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local channel = get_channel(radio, config)
|
local channel = get_channel(radio, config)
|
||||||
|
|
||||||
uci:delete('wireless', radio, 'disabled')
|
uci:delete('wireless', radio_name, 'disabled')
|
||||||
|
|
||||||
uci:set('wireless', radio, 'channel', channel)
|
uci:set('wireless', radio_name, 'channel', channel)
|
||||||
uci:set('wireless', radio, 'htmode', 'HT20')
|
uci:set('wireless', radio_name, 'htmode', 'HT20')
|
||||||
uci:set('wireless', radio, 'country', site.regdom())
|
uci:set('wireless', radio_name, 'country', site.regdom())
|
||||||
|
|
||||||
uci:set_list('wireless', radio, 'supported_rates', config.supported_rates())
|
uci:set_list('wireless', radio_name, 'supported_rates', config.supported_rates())
|
||||||
uci:set_list('wireless', radio, 'basic_rate', config.basic_rate())
|
uci:set_list('wireless', radio_name, 'basic_rate', config.basic_rate())
|
||||||
|
|
||||||
|
|
||||||
local ibss_disabled = is_disabled('ibss_' .. radio)
|
local ibss_disabled = is_disabled('ibss_' .. radio_name)
|
||||||
local mesh_disabled = is_disabled('mesh_' .. radio)
|
local mesh_disabled = is_disabled('mesh_' .. radio_name)
|
||||||
|
|
||||||
configure_ibss(config.ibss(), radio, index, suffix,
|
configure_ibss(config.ibss(), radio, index, suffix,
|
||||||
first_non_nil(
|
first_non_nil(
|
||||||
@ -176,9 +182,7 @@ local function configure_radio(radio, index, config)
|
|||||||
)
|
)
|
||||||
|
|
||||||
fixup_wan(radio, index)
|
fixup_wan(radio, index)
|
||||||
end
|
end)
|
||||||
|
|
||||||
util.iterate_radios(uci, configure_radio)
|
|
||||||
|
|
||||||
|
|
||||||
if uci:get('system', 'rssid_wlan0') then
|
if uci:get('system', 'rssid_wlan0') then
|
||||||
|
@ -181,7 +181,7 @@ function find_phy(config)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function get_addresses(uci, radio)
|
local function get_addresses(uci, radio)
|
||||||
local phy = find_phy(uci:get_all('wireless', radio))
|
local phy = find_phy(radio)
|
||||||
if not phy then
|
if not phy then
|
||||||
return function() end
|
return function() end
|
||||||
end
|
end
|
||||||
@ -250,15 +250,15 @@ end
|
|||||||
-- Iterate over all radios defined in UCI calling
|
-- Iterate over all radios defined in UCI calling
|
||||||
-- f(radio, index, site.wifiX) for each radio found while passing
|
-- f(radio, index, site.wifiX) for each radio found while passing
|
||||||
-- site.wifi24 for 2.4 GHz devices and site.wifi5 for 5 GHz ones.
|
-- site.wifi24 for 2.4 GHz devices and site.wifi5 for 5 GHz ones.
|
||||||
function iterate_radios(uci, f)
|
function foreach_radio(uci, f)
|
||||||
local radios = {}
|
local radios = {}
|
||||||
|
|
||||||
uci:foreach('wireless', 'wifi-device', function(s)
|
uci:foreach('wireless', 'wifi-device', function(radio)
|
||||||
table.insert(radios, s['.name'])
|
table.insert(radios, radio)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
for index, radio in ipairs(radios) do
|
for index, radio in ipairs(radios) do
|
||||||
local hwmode = uci:get('wireless', radio, 'hwmode')
|
local hwmode = radio.hwmode
|
||||||
|
|
||||||
if hwmode == '11g' or hwmode == '11ng' then
|
if hwmode == '11g' or hwmode == '11ng' then
|
||||||
f(radio, index, site.wifi24)
|
f(radio, index, site.wifi24)
|
||||||
|
@ -27,14 +27,15 @@ key.datatype = "wpakey"
|
|||||||
key.default = uci:get('wireless', primary_iface, "key")
|
key.default = uci:get('wireless', primary_iface, "key")
|
||||||
|
|
||||||
function f:write()
|
function f:write()
|
||||||
util.iterate_radios(uci, function(radio, index)
|
util.foreach_radio(uci, function(radio, index)
|
||||||
local name = "wan_" .. radio
|
local radio_name = radio['.name']
|
||||||
|
local name = "wan_" .. radio_name
|
||||||
|
|
||||||
if enabled.data then
|
if enabled.data then
|
||||||
local macaddr = util.get_wlan_mac(uci, radio, index, 4)
|
local macaddr = util.get_wlan_mac(uci, radio, index, 4)
|
||||||
|
|
||||||
uci:section('wireless', "wifi-iface", name, {
|
uci:section('wireless', "wifi-iface", name, {
|
||||||
device = radio,
|
device = radio_name,
|
||||||
network = "wan",
|
network = "wan",
|
||||||
mode = 'ap',
|
mode = 'ap',
|
||||||
encryption = 'psk2',
|
encryption = 'psk2',
|
||||||
|
Loading…
Reference in New Issue
Block a user