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) ...@@ -11,6 +11,10 @@ local function get(_, name)
end end
local function set(_, name, val) local function set(_, name, val)
if val == get(nil, name) then
return
end
if val then if val then
local f = io.open(sysconfigdir .. name, 'w+') local f = io.open(sysconfigdir .. name, 'w+')
f:write(val, '\n') f:write(val, '\n')
......
...@@ -138,6 +138,34 @@ function M.get_mesh_devices(uconn) ...@@ -138,6 +138,34 @@ function M.get_mesh_devices(uconn)
return devices return devices
end 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 -- Safe glob: returns an empty table when the glob fails because of
-- a non-existing path -- a non-existing path
function M.glob(pattern) function M.glob(pattern)
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
local uci = require('simple-uci').cursor() local uci = require('simple-uci').cursor()
uci:delete('network', 'mmfd')
uci:section('network', 'interface', 'mmfd', { uci:section('network', 'interface', 'mmfd', {
proto = 'static', proto = 'static',
ifname = 'mmfd0', ifname = 'mmfd0',
......
...@@ -9,14 +9,12 @@ local uci = require('simple-uci').cursor() ...@@ -9,14 +9,12 @@ local uci = require('simple-uci').cursor()
uci:delete('batman-adv', 'bat0') uci:delete('batman-adv', 'bat0')
uci:save('batman-adv') uci:save('batman-adv')
local gw_mode = uci:get('network', 'gluon_bat0', 'gw_mode') or 'client' local gw_mode = uci:get('network_gluon-old', 'gluon_bat0', 'gw_mode') or 'client'
uci:delete('network', 'gluon_bat0')
uci:section('network', 'interface', 'gluon_bat0', { uci:section('network', 'interface', 'gluon_bat0', {
proto = 'gluon_bat0', proto = 'gluon_bat0',
gw_mode = gw_mode, gw_mode = gw_mode,
}) })
uci:delete('network', 'bat0')
uci:section('network', 'interface', 'bat0', { uci:section('network', 'interface', 'bat0', {
ifname = 'bat0', ifname = 'bat0',
proto = 'none', proto = 'none',
......
...@@ -21,7 +21,6 @@ uci:section('network', 'interface', 'client', { ...@@ -21,7 +21,6 @@ uci:section('network', 'interface', 'client', {
query_response_interval = 500, query_response_interval = 500,
}) })
uci:delete('network', 'local_node_route6')
uci:section('network', 'route6', 'local_node_route6', { uci:section('network', 'route6', 'local_node_route6', {
interface = 'client', interface = 'client',
target = site.prefix6(), target = site.prefix6(),
......
...@@ -8,8 +8,8 @@ local uci = require('simple-uci').cursor() ...@@ -8,8 +8,8 @@ local uci = require('simple-uci').cursor()
-- fix up potentially duplicate MAC addresses (for meshing) -- fix up potentially duplicate MAC addresses (for meshing)
if not site.mesh.vxlan(true) then if not site.mesh.vxlan(true) then
uci:set('network', 'wan', 'macaddr', util.generate_mac(0)) uci:set('network', 'wan', 'macaddr', util.generate_mac(0))
else
uci:delete('network', 'wan', 'macaddr')
end 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') uci:save('network')
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
local uci = require('simple-uci').cursor() local uci = require('simple-uci').cursor()
local site = require 'gluon.site' 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 if not private_key or not private_key:match("^" .. ("[%a%d+/]"):rep(42) .. "[AEIMQUYcgkosw480]=$") then
private_key = "generate" private_key = "generate"
......
...@@ -3,13 +3,8 @@ ...@@ -3,13 +3,8 @@
local platform = require 'gluon.platform' local platform = require 'gluon.platform'
local sysconfig = require 'gluon.sysconfig' local sysconfig = require 'gluon.sysconfig'
if sysconfig.setup_ifname then
os.exit(0)
end
if platform.is_outdoor_device() then 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 else
sysconfig.setup_ifname = sysconfig.lan_ifname or sysconfig.wan_ifname sysconfig.setup_ifname = sysconfig.single_ifname or sysconfig.lan_ifname
end end
...@@ -28,6 +28,9 @@ msgstr "PoE-Passthrough aktivieren" ...@@ -28,6 +28,9 @@ msgstr "PoE-Passthrough aktivieren"
msgid "Enable PoE Power Port %s" msgid "Enable PoE Power Port %s"
msgstr "PoE-Ausgabe auf Port %s aktivieren" 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" msgid "Enable meshing on the LAN interface"
msgstr "Mesh auf dem LAN-Port aktivieren" msgstr "Mesh auf dem LAN-Port aktivieren"
......
...@@ -28,6 +28,9 @@ msgstr "" ...@@ -28,6 +28,9 @@ msgstr ""
msgid "Enable PoE Power Port %s" msgid "Enable PoE Power Port %s"
msgstr "" msgstr ""
msgid "Enable meshing on the Ethernet interface"
msgstr ""
msgid "Enable meshing on the LAN interface" msgid "Enable meshing on the LAN interface"
msgstr "Activer le réseau MESH sur le port LAN" msgstr "Activer le réseau MESH sur le port LAN"
......
...@@ -19,6 +19,9 @@ msgstr "" ...@@ -19,6 +19,9 @@ msgstr ""
msgid "Enable PoE Power Port %s" msgid "Enable PoE Power Port %s"
msgstr "" msgstr ""
msgid "Enable meshing on the Ethernet interface"
msgstr ""
msgid "Enable meshing on the LAN interface" msgid "Enable meshing on the LAN interface"
msgstr "" msgstr ""
......
...@@ -76,36 +76,37 @@ end ...@@ -76,36 +76,37 @@ end
s = f:section(Section) s = f:section(Section)
local mesh_wan = s:option(Flag, "mesh_wan", translate("Enable meshing on the WAN interface")) local wired_mesh_help = {
mesh_wan.default = not uci:get_bool("network", "mesh_wan", "disabled") single = translate('Enable meshing on the Ethernet interface'),
wan = translate('Enable meshing on the WAN interface'),
function mesh_wan:write(data) lan = translate('Enable meshing on the LAN interface'),
uci:set("network", "mesh_wan", "disabled", not data) }
end
local function wired_mesh(iface)
if sysconfig.lan_ifname then if not sysconfig[iface .. '_ifname'] then return end
s = f:section(Section) local iface_roles = uci:get_list('gluon', 'iface_' .. iface, 'role')
local mesh_lan = s:option(Flag, "mesh_lan", translate("Enable meshing on the LAN interface")) local option = s:option(Flag, 'mesh_' .. iface, wired_mesh_help[iface])
mesh_lan.default = not uci:get_bool("network", "mesh_lan", "disabled") option.default = util.contains(iface_roles, 'mesh') ~= false
function mesh_lan:write(data) function option:write(data)
uci:set("network", "mesh_lan", "disabled", not data) local roles = uci:get_list('gluon', 'iface_' .. iface, 'role')
if data then
local interfaces = uci:get_list("network", "client", "ifname") util.add_to_set(roles, 'mesh')
else
for lanif in sysconfig.lan_ifname:gmatch('%S+') do util.remove_from_set(roles, 'mesh')
if data then
util.remove_from_set(interfaces, lanif)
else
util.add_to_set(interfaces, lanif)
end
end 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
end end
wired_mesh('single')
wired_mesh('wan')
wired_mesh('lan')
local section local section
uci:foreach("system", "gpio_switch", function(si) uci:foreach("system", "gpio_switch", function(si)
if si[".name"]:match("poe") then if si[".name"]:match("poe") then
...@@ -160,7 +161,7 @@ function f:write() ...@@ -160,7 +161,7 @@ function f:write()
uci:delete("network", "wan6", "ip6gw") uci:delete("network", "wan6", "ip6gw")
end end
uci:commit('gluon')
uci:commit("network") uci:commit("network")
uci:commit('system') uci:commit('system')
end end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment