gluon/package/gluon-client-bridge/luasrc/lib/gluon/upgrade/300-gluon-client-bridge-network

72 lines
1.5 KiB
Plaintext
Raw Normal View History

#!/usr/bin/lua
local site = require 'gluon.site_config'
local sysconfig = require 'gluon.sysconfig'
local util = require 'gluon.util'
local uci = require('simple-uci').cursor()
local ip4, ip6
if site.next_node.ip4 then
local plen = site.prefix4:match('/%d+$')
ip4 = site.next_node.ip4 .. plen
end
if site.next_node.ip6 then
ip6 = site.next_node.ip6 .. '/128'
end
uci:section('network', 'interface', 'client',
{
type = 'bridge',
proto = 'static',
macaddr = site.next_node.mac,
ipaddr = ip4,
ip6addr = ip6,
}
)
uci:delete('network', 'client', 'reqprefix')
uci:delete('network', 'client', 'peerdns')
uci:delete('network', 'client', 'sourcefilter')
uci:delete('network', 'client', 'netmask')
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
if sysconfig.lan_ifname and not ifname and not uci:get_bool('network', 'mesh_lan', 'auto') then
for lanif in sysconfig.lan_ifname:gmatch('%S+') do
util.add_to_set(interfaces, lanif)
end
end
uci:set_list('network', 'client', 'ifname', interfaces)
uci:save('network')
local dnsmasq = uci:get_first('dhcp', 'dnsmasq')
uci:set('dhcp', dnsmasq, 'boguspriv', false)
uci:set('dhcp', dnsmasq, 'localise_queries', false)
uci:set('dhcp', dnsmasq, 'rebind_protection', false)
uci:delete('dhcp', 'client')
uci:section('dhcp', 'dhcp', 'client',
{
interface = 'client',
ignore = true,
}
)
uci:save('dhcp')