treewide: regenerate network and system configs on every reconfigure

This commit is contained in:
Matthias Schiffer 2022-01-09 16:32:00 +01:00
parent eea49a2834
commit c2a5f57c40
No known key found for this signature in database
GPG Key ID: 16EF3F64CB201D9C
15 changed files with 114 additions and 93 deletions

View File

@ -6,26 +6,13 @@ local util = require 'gluon.util'
local uci = require('simple-uci').cursor()
local interfaces = uci:get('network', 'client', 'ifname') or {}
if type(interfaces) == 'string' then
local ifname = interfaces
interfaces = {}
for iface in ifname:gmatch('%S+') do
util.add_to_set(interfaces, iface)
end
end
local interfaces = { 'local-port' }
if sysconfig.lan_ifname and uci:get_bool('network', 'mesh_lan', 'disabled') then
for lanif in sysconfig.lan_ifname:gmatch('%S+') do
util.add_to_set(interfaces, lanif)
end
end
util.add_to_set(interfaces, 'local-port')
uci:delete('network', 'client')
uci:section('network', 'interface', 'client', {
type = 'bridge',
ifname = interfaces,

View File

@ -10,7 +10,6 @@ local uci = require('simple-uci').cursor()
local next_node = site.next_node({})
uci:delete('network', 'local_node_dev')
uci:section('network', 'device', 'local_node_dev', {
type = 'veth',
name = 'local-node',
@ -31,7 +30,6 @@ if next_node.ip6 then
ip6 = next_node.ip6 .. '/128'
end
uci:delete('network', 'local_node')
uci:section('network', 'interface', 'local_node', {
ifname = 'local-node',
proto = 'static',

View File

@ -0,0 +1,23 @@
#!/bin/sh
NETWORK_CFG='/etc/config/network'
NETWORK_SAVED="${NETWORK_CFG}_gluon-old"
SYSTEM_CFG='/etc/config/system'
SYSTEM_SAVED="${SYSTEM_CFG}_gluon-old"
# Make sure everything is saved before we move away the config files
uci commit
# Save old configs (unless there is already a saved config,
# which means that the previous upgrade was interrupted)
if [ -s "$NETWORK_CFG" ] && ! [ -s "$NETWORK_SAVED" ]; then
mv -f "$NETWORK_CFG" "$NETWORK_SAVED"
fi
if [ -s "$SYSTEM_CFG" ] && ! [ -s "$SYSTEM_SAVED" ]; then
mv -f "$SYSTEM_CFG" "$SYSTEM_SAVED"
fi
# Generate a new network config
rm -f /etc/board.json "$NETWORK_CFG" "$SYSTEM_CFG"
config_generate

View File

@ -4,3 +4,6 @@ uci -q batch <<-EOF
delete gluon.core.reconfigure
commit
EOF
# New config is saved, we can delete the old one
rm -f /etc/config/*_gluon-old

View File

@ -0,0 +1,31 @@
#!/usr/bin/lua
local uci = require('simple-uci').cursor()
-- Migrate system section
local system = uci:get_all('system_gluon-old', '@system[0]')
if system then
uci:tset('system', '@system[0]', system)
end
-- Migrate ntp section
local ntp = uci:get_all('system_gluon-old', 'ntp')
if ntp then
uci:tset('system', 'ntp', ntp)
end
-- Migrate gpio_switch sections
--
-- Only the value is copied from the old config, so updates to names and
-- pins are preserved
uci:foreach('system', 'gpio_switch', function(s)
local name = s['.name']
local value = uci:get('system_gluon-old', name, 'value')
if value then
uci:set('system', name, 'value', value)
end
end)
-- No other sections are migrated, so updated LED and RSSI configs can take effect
uci:save('system')

View File

@ -79,9 +79,7 @@ else
end
uci:delete('network', 'lan')
uci:delete('network', 'wan')
uci:delete_all('network', 'device')
uci:delete_all('network', 'interface')
uci:save('network')

View File

@ -3,8 +3,21 @@
local uci = require('simple-uci').cursor()
local sysconfig = require 'gluon.sysconfig'
local wan = uci:get_all('network_gluon-old', 'wan') or {}
local wan6 = uci:get_all('network_gluon-old', 'wan6') or {}
uci:section('network', 'interface', 'loopback', {
ifname = 'lo',
proto = 'static',
ipaddr = '127.0.0.1',
netmask = '255.0.0.0',
})
uci:section('network', 'interface', 'wan', {
proto = wan.proto or 'dhcp',
ipaddr = wan.ipaddr,
netmask = wan.netmask,
gateway = wan.gateway,
ifname = sysconfig.wan_ifname,
type = 'bridge',
igmp_snooping = true,
@ -13,12 +26,10 @@ uci:section('network', 'interface', 'wan', {
auto = true,
})
if not uci:get('network', 'wan', 'proto') then
uci:set('network', 'wan', 'proto', 'dhcp')
end
uci:section('network', 'interface', 'wan6', {
proto = wan6.proto or 'dhcpv6',
ip6addr = wan6.ip6addr,
ip6gw = wan6.ip6gw,
ifname = 'br-wan',
peerdns = false,
ip6table = 1,
@ -26,11 +37,6 @@ uci:section('network', 'interface', 'wan6', {
reqprefix = 'no',
})
if not uci:get('network', 'wan6', 'proto') then
uci:set('network', 'wan6', 'proto', 'dhcpv6')
end
uci:section('network', 'rule6', 'wan6_lookup', {
mark = '0x01/0x01',
lookup = 1,

View File

@ -106,8 +106,6 @@ end
local function delete_ibss(radio_name)
local name = 'ibss_' .. radio_name
uci:delete('network', name)
uci:delete('network', name .. '_vlan')
uci:delete('wireless', name)
end
@ -118,8 +116,6 @@ local function configure_mesh(config, radio, index, suffix, disabled)
local macfilter = uci:get('wireless', name, 'macfilter')
local maclist = uci:get('wireless', name, 'maclist')
uci:delete('network', name)
uci:delete('network', name .. '_vlan')
uci:delete('wireless', name)
if not config then

View File

@ -3,23 +3,23 @@
local site = require 'gluon.site'
local uci = require('simple-uci').cursor()
local disabled = uci:get('network_gluon-old', 'mesh_wan', 'disabled')
if disabled == nil then
disabled = not site.mesh_on_wan(false)
end
local transitive = uci:get('network_gluon-old', 'mesh_wan', 'transitive')
if transitive == nil then
transitive = true
end
uci:section('network', 'interface', 'mesh_wan', {
ifname = 'br-wan',
proto = 'gluon_wired',
index = 0,
vxlan = site.mesh.vxlan(true),
disabled = disabled,
transitive = transitive,
})
local enable = site.mesh_on_wan(false)
local old_auto = uci:get('network', 'mesh_wan', 'auto')
local old_disabled = uci:get('network', 'mesh_wan', 'disabled')
if old_auto ~= nil or old_disabled ~= nil then
enable = old_auto ~= '0' and old_disabled ~= '1'
end
uci:set('network', 'mesh_wan', 'disabled', not enable)
if uci:get('network', 'mesh_wan', 'transitive') == nil then
uci:set('network', 'mesh_wan', 'transitive', true)
end
uci:save('network')

View File

@ -1,7 +1,6 @@
#!/usr/bin/lua
local site = require 'gluon.site'
local util = require 'gluon.util'
local sysconfig = require 'gluon.sysconfig'
local uci = require('simple-uci').cursor()
@ -10,44 +9,30 @@ if not sysconfig.lan_ifname then
os.exit(0)
end
local type
if sysconfig.lan_ifname:match(' ') then
type = 'bridge'
end
local disabled = uci:get('network_gluon-old', 'mesh_lan', 'disabled')
if disabled == nil then
disabled = not site.mesh_on_lan(false)
end
local transitive = uci:get('network_gluon-old', 'mesh_lan', 'transitive')
if transitive == nil then
transitive = true
end
uci:section('network', 'interface', 'mesh_lan', {
ifname = sysconfig.lan_ifname,
type = type,
igmp_snooping = false,
proto = 'gluon_wired',
index = 4,
vxlan = site.mesh.vxlan(true),
disabled = disabled,
transitive = transitive,
})
if sysconfig.lan_ifname:match(' ') then
uci:set('network', 'mesh_lan', 'type', 'bridge')
else
uci:delete('network', 'mesh_lan', 'type')
end
local enable = site.mesh_on_lan(false)
local old_auto = uci:get('network', 'mesh_lan', 'auto')
local old_disabled = uci:get('network', 'mesh_lan', 'disabled')
if old_auto ~= nil or old_disabled ~= nil then
enable = old_auto ~= '0' and old_disabled ~= '1'
end
if enable then
local interfaces = uci:get_list('network', 'client', 'ifname')
if interfaces then
for lanif in sysconfig.lan_ifname:gmatch('%S+') do
if util.contains(interfaces, lanif) then
enable = false
break
end
end
end
end
uci:set('network', 'mesh_lan', 'disabled', not enable)
if uci:get('network', 'mesh_lan', 'transitive') == nil then
uci:set('network', 'mesh_lan', 'transitive', true)
end
uci:save('network')

View File

@ -2,7 +2,6 @@
local uci = require('simple-uci').cursor()
uci:delete('network', 'mmfd')
uci:section('network', 'interface', 'mmfd', {
proto = 'static',
ifname = 'mmfd0',

View File

@ -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',

View File

@ -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(),

View File

@ -8,8 +8,6 @@ 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))
uci:save('network')

View File

@ -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"