cl
This commit is contained in:
parent
580a78fd1d
commit
4544ccf5db
@ -1,10 +0,0 @@
|
|||||||
#!/usr/bin/lua
|
|
||||||
|
|
||||||
local uci = require('simple-uci').cursor()
|
|
||||||
|
|
||||||
-- this hack directly uses the mesh interface as I haven't figured out teql and ddhcpd now and this shit should just work already
|
|
||||||
|
|
||||||
if uci:get('wireless', 'client_radio0', 'network') then
|
|
||||||
uci:set('wireless', 'client_radio0', 'network', 'mesh_radio0')
|
|
||||||
uci:save('wireless')
|
|
||||||
end
|
|
@ -1,102 +0,0 @@
|
|||||||
#!/usr/bin/lua
|
|
||||||
|
|
||||||
local uci = require('simple-uci').cursor()
|
|
||||||
local site = require 'gluon.site'
|
|
||||||
local wireless = require 'gluon.wireless'
|
|
||||||
local ip = require 'luci.ip' -- luci-lib-ip
|
|
||||||
local util = require 'gluon.util'
|
|
||||||
|
|
||||||
IPV4_PREFIX_MAX = 32
|
|
||||||
|
|
||||||
local tmp4 = ip.new(site.tmpIpPrefix4())
|
|
||||||
|
|
||||||
function startswith(text, prefix)
|
|
||||||
return text:find(prefix, 1, true) == 1
|
|
||||||
end
|
|
||||||
|
|
||||||
local function static_ip_4(name, ifname, macaddr, actually_use)
|
|
||||||
-- actually_use = if ip should be applied to interface or not
|
|
||||||
-- if set and actually_use=false then it will be removed
|
|
||||||
local static4 = uci:get('gluon-static-ip', name, 'ip4')
|
|
||||||
|
|
||||||
if not static4 then
|
|
||||||
local prefixOverflow = IPV4_PREFIX_MAX - tmp4:prefix()
|
|
||||||
-- magic that turns mac into random number
|
|
||||||
local ipnum = math.fmod(tonumber(macaddr:gsub(':', ''):sub(-6), 16), 2 ^ prefixOverflow)
|
|
||||||
|
|
||||||
-- the rare case where we get 0 or 1 as our mac based number
|
|
||||||
if ipnum < 2 then
|
|
||||||
ipnum = 2
|
|
||||||
end
|
|
||||||
|
|
||||||
static4 = tmp4:add(ipnum):string()
|
|
||||||
uci:section('gluon-static-ip', 'interface', name, {
|
|
||||||
ip4 = static4,
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
if actually_use then
|
|
||||||
ip4 = ip.new(static4)
|
|
||||||
-- we have to set proto to static as otherwise we won't have the ip assigned
|
|
||||||
-- TODO: maybe modify the protos instead to allow reading static ips and using them?
|
|
||||||
-- NOTE: wan also uses dhcp/static directly
|
|
||||||
uci:set('network', name, 'proto', 'static')
|
|
||||||
uci:set('network', name, 'ipaddr', ip4:host():string())
|
|
||||||
uci:set('network', name, 'netmask', ip4:mask():string())
|
|
||||||
else
|
|
||||||
if uci:get('network', name, 'proto') == 'static' then
|
|
||||||
uci:del('network', name, 'ipaddr')
|
|
||||||
uci:del('network', name, 'netmask')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
wireless.foreach_radio(uci, function(radio, index, config)
|
|
||||||
net = 'mesh_' .. radio['.name']
|
|
||||||
|
|
||||||
if uci:get('network', net, 'proto') == nil then
|
|
||||||
uci:section('network', 'interface', net, {
|
|
||||||
proto = 'static',
|
|
||||||
type = 'bridge',
|
|
||||||
ifname = net,
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
use = uci:get('wifi-iface', net, 'disabled') ~= '1'
|
|
||||||
static_ip_4(net, uci:get('wifi-iface', net, 'ifname'), uci:get('wifi-iface', net, 'macaddr'), use)
|
|
||||||
end)
|
|
||||||
|
|
||||||
local function apply_network(name, use, mac)
|
|
||||||
if not uci:get('network', name, 'proto') then
|
|
||||||
print('warn: non-existent network ' .. name)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
not_disabled = uci:get('network', name, 'disabled') ~= '1'
|
|
||||||
if use == nil then
|
|
||||||
use = not_disabled
|
|
||||||
end
|
|
||||||
macaddr = uci:get('network', name, 'macaddr')
|
|
||||||
if not macaddr then
|
|
||||||
macaddr = util.generate_mac(mac)
|
|
||||||
uci:set('network', name, 'macaddr', macaddr)
|
|
||||||
end
|
|
||||||
static_ip_4(name, uci:get('network', name, 'ifname'), macaddr, use)
|
|
||||||
end
|
|
||||||
|
|
||||||
if pcall(function() require 'gluon.mesh-vpn' end) then
|
|
||||||
local vpn_core = require 'gluon.mesh-vpn'
|
|
||||||
|
|
||||||
apply_network('mesh_vpn', vpn_core.enabled(), 7)
|
|
||||||
end
|
|
||||||
|
|
||||||
local wan_mesh = not uci:get_bool('network', 'mesh_wan', 'disabled')
|
|
||||||
apply_network('mesh_wan', wan_mesh, 10)
|
|
||||||
|
|
||||||
if uci:get('network', 'mesh_lan', 'proto') then
|
|
||||||
local lan_mesh = not uci:get_bool('network', 'mesh_lan', 'disabled')
|
|
||||||
apply_network('mesh_lan', lan_mesh, 11)
|
|
||||||
end
|
|
||||||
|
|
||||||
uci:save('gluon-static-ip')
|
|
||||||
uci:save('network')
|
|
Loading…
Reference in New Issue
Block a user