Skip to content
Snippets Groups Projects
Unverified Commit a3203b26 authored by David Bauer's avatar David Bauer Committed by GitHub
Browse files

Merge pull request #2372 from freifunk-gluon/uci-regen

Regenerate network and system UCI configs on every reconfigure, switch to role-based interface configuration
parents f75bb7ce 210cacdf
No related branches found
No related tags found
No related merge requests found
Showing
with 94 additions and 42 deletions
#!/usr/bin/lua
local uci = require('simple-uci').cursor()
for _, config in ipairs({'system', 'network'}) do
uci:foreach(config .. '_gluon-old', nil, function(s)
if s.gluon_preserve ~= '1' then return end
-- Unnamed sections can't be preserved
if s['.anonymous'] then return end
-- We don't allow overwriting existing sections
if uci:get(config, s['.name']) then return end
uci:section(config, s['.type'], s['.name'], s)
end)
uci:save(config)
end
......@@ -11,6 +11,10 @@ local function get(_, name)
end
local function set(_, name, val)
if val == get(nil, name) then
return
end
if val then
local f = io.open(sysconfigdir .. name, 'w+')
f:write(val, '\n')
......
......@@ -138,6 +138,34 @@ function M.get_mesh_devices(uconn)
return devices
end
-- Returns a list of all interfaces with a given role
--
-- If exclusive is set to true, only interfaces that have no other role
-- are returned; this is used to ensure that the client role is not active
-- at the same time as any other role
function M.get_role_interfaces(uci, role, exclusive)
local ret = {}
local function add(name)
-- Interface names with a / prefix refer to sysconfig interfaces
-- (lan_ifname/wan_ifname/single_ifname)
if string.sub(name, 1, 1) == '/' then
name = sysconfig[string.sub(name, 2) .. '_ifname'] or ''
end
for iface in string.gmatch(name, '%S+') do
M.add_to_set(ret, iface)
end
end
uci:foreach('gluon', 'interface', function(s)
if M.contains(s.role, role) and (not exclusive or #s.role == 1) then
add(s.name)
end
end)
return ret
end
-- Safe glob: returns an empty table when the glob fails because of
-- a non-existing path
function M.glob(pattern)
......
......@@ -2,7 +2,6 @@
local uci = require('simple-uci').cursor()
uci:delete('network', 'mmfd')
uci:section('network', 'interface', 'mmfd', {
proto = 'static',
ifname = 'mmfd0',
......
......@@ -9,14 +9,12 @@ local uci = require('simple-uci').cursor()
uci:delete('batman-adv', 'bat0')
uci:save('batman-adv')
local gw_mode = uci:get('network', 'gluon_bat0', 'gw_mode') or 'client'
uci:delete('network', 'gluon_bat0')
local gw_mode = uci:get('network_gluon-old', 'gluon_bat0', 'gw_mode') or 'client'
uci:section('network', 'interface', 'gluon_bat0', {
proto = 'gluon_bat0',
gw_mode = gw_mode,
})
uci:delete('network', 'bat0')
uci:section('network', 'interface', 'bat0', {
ifname = 'bat0',
proto = 'none',
......
......@@ -21,7 +21,6 @@ uci:section('network', 'interface', 'client', {
query_response_interval = 500,
})
uci:delete('network', 'local_node_route6')
uci:section('network', 'route6', 'local_node_route6', {
interface = 'client',
target = site.prefix6(),
......
......@@ -8,8 +8,8 @@ local uci = require('simple-uci').cursor()
-- fix up potentially duplicate MAC addresses (for meshing)
if not site.mesh.vxlan(true) then
uci:set('network', 'wan', 'macaddr', util.generate_mac(0))
else
uci:delete('network', 'wan', 'macaddr')
end
uci:set('network', 'mesh_lan', 'macaddr', util.generate_mac(4))
if uci:get('network', 'mesh_other') then
uci:set('network', 'mesh_other', 'macaddr', util.generate_mac(4))
end
uci:save('network')
......@@ -3,7 +3,7 @@
local uci = require('simple-uci').cursor()
local site = require 'gluon.site'
local private_key = uci:get("network", 'wg_mesh', "private_key")
local private_key = uci:get("network_gluon-old", 'wg_mesh', "private_key")
if not private_key or not private_key:match("^" .. ("[%a%d+/]"):rep(42) .. "[AEIMQUYcgkosw480]=$") then
private_key = "generate"
......
......@@ -3,13 +3,8 @@
local platform = require 'gluon.platform'
local sysconfig = require 'gluon.sysconfig'
if sysconfig.setup_ifname then
os.exit(0)
end
if platform.is_outdoor_device() then
sysconfig.setup_ifname = sysconfig.wan_ifname or sysconfig.lan_ifname
sysconfig.setup_ifname = sysconfig.single_ifname or sysconfig.wan_ifname
else
sysconfig.setup_ifname = sysconfig.lan_ifname or sysconfig.wan_ifname
sysconfig.setup_ifname = sysconfig.single_ifname or sysconfig.lan_ifname
end
......@@ -28,6 +28,9 @@ msgstr "PoE-Passthrough aktivieren"
msgid "Enable PoE Power Port %s"
msgstr "PoE-Ausgabe auf Port %s aktivieren"
msgid "Enable meshing on the Ethernet interface"
msgstr "Mesh auf dem Ethernet-Port aktivieren"
msgid "Enable meshing on the LAN interface"
msgstr "Mesh auf dem LAN-Port aktivieren"
......
......@@ -28,6 +28,9 @@ msgstr ""
msgid "Enable PoE Power Port %s"
msgstr ""
msgid "Enable meshing on the Ethernet interface"
msgstr ""
msgid "Enable meshing on the LAN interface"
msgstr "Activer le réseau MESH sur le port LAN"
......
......@@ -19,6 +19,9 @@ msgstr ""
msgid "Enable PoE Power Port %s"
msgstr ""
msgid "Enable meshing on the Ethernet interface"
msgstr ""
msgid "Enable meshing on the LAN interface"
msgstr ""
......
......@@ -76,36 +76,37 @@ end
s = f:section(Section)
local mesh_wan = s:option(Flag, "mesh_wan", translate("Enable meshing on the WAN interface"))
mesh_wan.default = not uci:get_bool("network", "mesh_wan", "disabled")
function mesh_wan:write(data)
uci:set("network", "mesh_wan", "disabled", not data)
end
if sysconfig.lan_ifname then
s = f:section(Section)
local mesh_lan = s:option(Flag, "mesh_lan", translate("Enable meshing on the LAN interface"))
mesh_lan.default = not uci:get_bool("network", "mesh_lan", "disabled")
function mesh_lan:write(data)
uci:set("network", "mesh_lan", "disabled", not data)
local interfaces = uci:get_list("network", "client", "ifname")
for lanif in sysconfig.lan_ifname:gmatch('%S+') do
if data then
util.remove_from_set(interfaces, lanif)
else
util.add_to_set(interfaces, lanif)
end
local wired_mesh_help = {
single = translate('Enable meshing on the Ethernet interface'),
wan = translate('Enable meshing on the WAN interface'),
lan = translate('Enable meshing on the LAN interface'),
}
local function wired_mesh(iface)
if not sysconfig[iface .. '_ifname'] then return end
local iface_roles = uci:get_list('gluon', 'iface_' .. iface, 'role')
local option = s:option(Flag, 'mesh_' .. iface, wired_mesh_help[iface])
option.default = util.contains(iface_roles, 'mesh') ~= false
function option:write(data)
local roles = uci:get_list('gluon', 'iface_' .. iface, 'role')
if data then
util.add_to_set(roles, 'mesh')
else
util.remove_from_set(roles, 'mesh')
end
uci:set_list('gluon', 'iface_' .. iface, 'role', roles)
uci:set_list("network", "client", "ifname", interfaces)
-- Reconfigure on next reboot
uci:set('gluon', 'core', 'reconfigure', true)
end
end
wired_mesh('single')
wired_mesh('wan')
wired_mesh('lan')
local section
uci:foreach("system", "gpio_switch", function(si)
if si[".name"]:match("poe") then
......@@ -160,7 +161,7 @@ function f:write()
uci:delete("network", "wan6", "ip6gw")
end
uci:commit('gluon')
uci:commit("network")
uci:commit('system')
end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment