Skip to content
Snippets Groups Projects
Unverified Commit c2a5f57c authored by Matthias Schiffer's avatar Matthias Schiffer
Browse files

treewide: regenerate network and system configs on every reconfigure

parent eea49a28
No related branches found
No related tags found
No related merge requests found
Showing
with 110 additions and 89 deletions
...@@ -6,26 +6,13 @@ local util = require 'gluon.util' ...@@ -6,26 +6,13 @@ local util = require 'gluon.util'
local uci = require('simple-uci').cursor() local uci = require('simple-uci').cursor()
local interfaces = uci:get('network', 'client', 'ifname') or {} local interfaces = { 'local-port' }
if type(interfaces) == 'string' then
local ifname = interfaces
interfaces = {}
for iface in ifname:gmatch('%S+') do
util.add_to_set(interfaces, iface)
end
end
if sysconfig.lan_ifname and uci:get_bool('network', 'mesh_lan', 'disabled') then if sysconfig.lan_ifname and uci:get_bool('network', 'mesh_lan', 'disabled') then
for lanif in sysconfig.lan_ifname:gmatch('%S+') do for lanif in sysconfig.lan_ifname:gmatch('%S+') do
util.add_to_set(interfaces, lanif) util.add_to_set(interfaces, lanif)
end end
end end
util.add_to_set(interfaces, 'local-port')
uci:delete('network', 'client')
uci:section('network', 'interface', 'client', { uci:section('network', 'interface', 'client', {
type = 'bridge', type = 'bridge',
ifname = interfaces, ifname = interfaces,
......
...@@ -10,7 +10,6 @@ local uci = require('simple-uci').cursor() ...@@ -10,7 +10,6 @@ local uci = require('simple-uci').cursor()
local next_node = site.next_node({}) local next_node = site.next_node({})
uci:delete('network', 'local_node_dev')
uci:section('network', 'device', 'local_node_dev', { uci:section('network', 'device', 'local_node_dev', {
type = 'veth', type = 'veth',
name = 'local-node', name = 'local-node',
...@@ -31,7 +30,6 @@ if next_node.ip6 then ...@@ -31,7 +30,6 @@ if next_node.ip6 then
ip6 = next_node.ip6 .. '/128' ip6 = next_node.ip6 .. '/128'
end end
uci:delete('network', 'local_node')
uci:section('network', 'interface', 'local_node', { uci:section('network', 'interface', 'local_node', {
ifname = 'local-node', ifname = 'local-node',
proto = 'static', proto = 'static',
......
#!/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
...@@ -4,3 +4,6 @@ uci -q batch <<-EOF ...@@ -4,3 +4,6 @@ uci -q batch <<-EOF
delete gluon.core.reconfigure delete gluon.core.reconfigure
commit commit
EOF EOF
# New config is saved, we can delete the old one
rm -f /etc/config/*_gluon-old
#!/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')
...@@ -79,9 +79,7 @@ else ...@@ -79,9 +79,7 @@ else
end end
uci:delete('network', 'lan')
uci:delete('network', 'wan')
uci:delete_all('network', 'device') uci:delete_all('network', 'device')
uci:delete_all('network', 'interface')
uci:save('network') uci:save('network')
...@@ -3,8 +3,21 @@ ...@@ -3,8 +3,21 @@
local uci = require('simple-uci').cursor() local uci = require('simple-uci').cursor()
local sysconfig = require 'gluon.sysconfig' 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', { uci:section('network', 'interface', 'wan', {
proto = wan.proto or 'dhcp',
ipaddr = wan.ipaddr,
netmask = wan.netmask,
gateway = wan.gateway,
ifname = sysconfig.wan_ifname, ifname = sysconfig.wan_ifname,
type = 'bridge', type = 'bridge',
igmp_snooping = true, igmp_snooping = true,
...@@ -13,12 +26,10 @@ uci:section('network', 'interface', 'wan', { ...@@ -13,12 +26,10 @@ uci:section('network', 'interface', 'wan', {
auto = true, auto = true,
}) })
if not uci:get('network', 'wan', 'proto') then
uci:set('network', 'wan', 'proto', 'dhcp')
end
uci:section('network', 'interface', 'wan6', { uci:section('network', 'interface', 'wan6', {
proto = wan6.proto or 'dhcpv6',
ip6addr = wan6.ip6addr,
ip6gw = wan6.ip6gw,
ifname = 'br-wan', ifname = 'br-wan',
peerdns = false, peerdns = false,
ip6table = 1, ip6table = 1,
...@@ -26,11 +37,6 @@ uci:section('network', 'interface', 'wan6', { ...@@ -26,11 +37,6 @@ uci:section('network', 'interface', 'wan6', {
reqprefix = 'no', reqprefix = 'no',
}) })
if not uci:get('network', 'wan6', 'proto') then
uci:set('network', 'wan6', 'proto', 'dhcpv6')
end
uci:section('network', 'rule6', 'wan6_lookup', { uci:section('network', 'rule6', 'wan6_lookup', {
mark = '0x01/0x01', mark = '0x01/0x01',
lookup = 1, lookup = 1,
......
...@@ -106,8 +106,6 @@ end ...@@ -106,8 +106,6 @@ end
local function delete_ibss(radio_name) local function delete_ibss(radio_name)
local name = 'ibss_' .. radio_name local name = 'ibss_' .. radio_name
uci:delete('network', name)
uci:delete('network', name .. '_vlan')
uci:delete('wireless', name) uci:delete('wireless', name)
end end
...@@ -118,8 +116,6 @@ local function configure_mesh(config, radio, index, suffix, disabled) ...@@ -118,8 +116,6 @@ local function configure_mesh(config, radio, index, suffix, disabled)
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')
uci:delete('network', name)
uci:delete('network', name .. '_vlan')
uci:delete('wireless', name) uci:delete('wireless', name)
if not config then if not config then
......
...@@ -3,23 +3,23 @@ ...@@ -3,23 +3,23 @@
local site = require 'gluon.site' local site = require 'gluon.site'
local uci = require('simple-uci').cursor() local uci = require('simple-uci').cursor()
uci:section('network', 'interface', 'mesh_wan', { local disabled = uci:get('network_gluon-old', 'mesh_wan', 'disabled')
ifname = 'br-wan', if disabled == nil then
proto = 'gluon_wired', disabled = not site.mesh_on_wan(false)
index = 0,
vxlan = site.mesh.vxlan(true),
})
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 end
uci:set('network', 'mesh_wan', 'disabled', not enable)
if uci:get('network', 'mesh_wan', 'transitive') == nil then local transitive = uci:get('network_gluon-old', 'mesh_wan', 'transitive')
uci:set('network', 'mesh_wan', 'transitive', true) if transitive == nil then
transitive = true
end end
uci:section('network', 'interface', 'mesh_wan', {
ifname = 'br-wan',
proto = 'gluon_wired',
index = 0,
vxlan = site.mesh.vxlan(true),
disabled = disabled,
transitive = transitive,
})
uci:save('network') uci:save('network')
#!/usr/bin/lua #!/usr/bin/lua
local site = require 'gluon.site' local site = require 'gluon.site'
local util = require 'gluon.util'
local sysconfig = require 'gluon.sysconfig' local sysconfig = require 'gluon.sysconfig'
local uci = require('simple-uci').cursor() local uci = require('simple-uci').cursor()
...@@ -10,44 +9,30 @@ if not sysconfig.lan_ifname then ...@@ -10,44 +9,30 @@ if not sysconfig.lan_ifname then
os.exit(0) os.exit(0)
end end
uci:section('network', 'interface', 'mesh_lan', { local type
ifname = sysconfig.lan_ifname,
igmp_snooping = false,
proto = 'gluon_wired',
index = 4,
vxlan = site.mesh.vxlan(true),
})
if sysconfig.lan_ifname:match(' ') then if sysconfig.lan_ifname:match(' ') then
uci:set('network', 'mesh_lan', 'type', 'bridge') type = 'bridge'
else
uci:delete('network', 'mesh_lan', 'type')
end end
local enable = site.mesh_on_lan(false) local disabled = uci:get('network_gluon-old', 'mesh_lan', 'disabled')
local old_auto = uci:get('network', 'mesh_lan', 'auto') if disabled == nil then
local old_disabled = uci:get('network', 'mesh_lan', 'disabled') disabled = not site.mesh_on_lan(false)
if old_auto ~= nil or old_disabled ~= nil then
enable = old_auto ~= '0' and old_disabled ~= '1'
end end
if enable then local transitive = uci:get('network_gluon-old', 'mesh_lan', 'transitive')
local interfaces = uci:get_list('network', 'client', 'ifname') if transitive == nil then
transitive = true
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 end
uci:set('network', 'mesh_lan', 'disabled', not enable) uci:section('network', 'interface', 'mesh_lan', {
ifname = sysconfig.lan_ifname,
if uci:get('network', 'mesh_lan', 'transitive') == nil then type = type,
uci:set('network', 'mesh_lan', 'transitive', true) igmp_snooping = false,
end proto = 'gluon_wired',
index = 4,
vxlan = site.mesh.vxlan(true),
disabled = disabled,
transitive = transitive,
})
uci:save('network') uci:save('network')
...@@ -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,6 @@ local uci = require('simple-uci').cursor() ...@@ -8,8 +8,6 @@ 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)) uci:set('network', 'mesh_lan', 'macaddr', util.generate_mac(4))
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"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment