/* usr/lib/lua/ddmesh.lua */

This commit is contained in:
W01f 2014-09-08 09:07:01 +00:00
parent cde634ac9e
commit 8039e3ca89
1 changed files with 28 additions and 22 deletions

View File

@ -119,13 +119,14 @@ function ipcalc.rCalcIp(ip)
middle = a[3]
if a[2]=="201" then middle = middle + 256 end
minor = math.floor(a[4]/64) --x>>6
minor = math.floor(a[4]/64) --x>>6
node = middle*4+minor --x<<2
if node < 0 or node > ipcalc.data.max then return -1 end
return node
end
function ipcalc.calc(node)
--node has to be a number n \in N_0, 0 <= n <= 2048
if node==nil or node=="" then return -1 end
node=tonumber(node)
if node==nil or node=="" then return -1 end
@ -133,20 +134,23 @@ function ipcalc.calc(node)
local domain = "freifunk-dresden.de"
--Ternary Operator in use
-- major network for nodes n < 1024: 200, for nodes > 1023: 201
local major = node >= 1024 and 201 or 200 --a[2]
-- etc.
local middle = node >= 1024 and math.floor((node-1024) / 4) or math.floor(node / 4) --a[3]
local minor = (node % 4) * 64
local minor = (node % 4) * 64
local meshnet = "10"
local nodeip = meshnet .. "." .. major .. "." .. middle .. "." .. minor + 1
local nodeip = meshnet .. "." .. major .. "." .. middle .. "." .. minor + 1
local meshnetmask = "255.0.0.0"
local meshpre = 15
local meshbroadcast = "10.255.255.255"
local meshnetwork = "10.200.0.0"
local dhcpstart = meshnet .. "." .. major .. "." .. middle .. "." .. minor + 2
local dhcpend = meshnet .. "." .. major .. "." .. middle .. "." .. minor + 63
local dhcpoffset = 1 --used by config/dhcp
local dhcpend = meshnet .. "." .. major .. "." .. middle .. "." .. minor + 63
local dhcpoffset = 1 --used by config/dhcp
local dhcplimit = 62 --used by config/dhcp
local dhcprangepre = 26
local dhcprangemask = "255.255.255.192"
@ -159,27 +163,28 @@ function ipcalc.calc(node)
local mesh6net = "fd11:11ae:7466::"
-- client range
local mesh6nodenet= "fd11:11ae:7466:" .. string.format("%x", node) .. "::"
local mesh6ip = mesh6nodenet .. "1"
local mesh6ip = mesh6nodenet .. "1"
local mesh6nodepre= "64"
-- preparing variabled to be expoted
ipcalc.data.node = node
ipcalc.data.domain = domain
ipcalc.data.domain = domain
ipcalc.data.hostname = "r" .. node
ipcalc.data.ip = nodeip
ipcalc.data.network = meshnetwork
ipcalc.data.ip = nodeip
ipcalc.data.network = meshnetwork
ipcalc.data.netpre = meshpre
ipcalc.data.netmask = meshnetmask
ipcalc.data.broadcast = meshbroadcast
ipcalc.data.netmask = meshnetmask
ipcalc.data.broadcast = meshbroadcast
ipcalc.data.dhcpstart = dhcpstart
ipcalc.data.dhcpend = dhcpend
ipcalc.data.dhcpoffset = dhcpoffset
ipcalc.data.dhcplimit = dhcplimit
ipcalc.data.dhcprangepre = dhcprangepre
ipcalc.data.dhcprangemask = dhcprangemask
ipcalc.data.dhcpnetwork = dhcpnetwork
ipcalc.data.dhcpbroadcast = dhcpbroadcast
ipcalc.data.dhcpnetmask = dhcpnetmask
ipcalc.data.clienthna = hna
ipcalc.data.dhcprangepre = dhcprangepre
ipcalc.data.dhcprangemask = dhcprangemask
ipcalc.data.dhcpnetwork = dhcpnetwork
ipcalc.data.dhcpbroadcast = dhcpbroadcast
ipcalc.data.dhcpnetmask = dhcpnetmask
ipcalc.data.clienthna = hna
ipcalc.data.mesh6ip = mesh6ip
ipcalc.data.mesh6net = mesh6net
ipcalc.data.mesh6pre = mesh6pre
@ -195,12 +200,12 @@ function ipcalc.print(node)
if node < 0 or node > ipcalc.data.max then return -1 end
ipcalc.calc(node)
for k,v in pairs(ipcalc.data)
do
for k,v in pairs(ipcalc.data) do
print("export _ddmesh_"..k.."="..v)
end
end
--not needed for ip address calculation
function iplookup(ip)
if ip==nil then return -1 end
n=ipcalc.rCalcIp(ip)
@ -209,11 +214,12 @@ function iplookup(ip)
return ipcalc.data.hostname
end
--not needed for ip address calculation
function lookup(node)
if node==nil then return -1 end
if string.sub(node,1,1) == "r" then
n=tonumber(string.sub(node,2))
else
if string.sub(node,1,1) == "r" then
n=tonumber(string.sub(node,2))
else
n=tonumber(node)
end
if n==nil then return -1 end