+local ip = require "luci.ip"
+
+local function mksubnet(community, meship)
+ local subnet_prefix = tonumber(uci:get("freifunk", community, "splash_prefix")) or 27
+ local pool_network = uci:get("freifunk", community, "splash_network") or "10.104.0.0/16"
+ local pool = luci.ip.IPv4(pool_network)
+
+ if pool then
+ local hosts_per_subnet = 2^(32 - subnet_prefix)
+ local number_of_subnets = (2^pool:prefix())/hosts_per_subnet
+
+ local seed1, seed2 = meship:match("(%d+)%.(%d+)$")
+ math.randomseed(seed1 * seed2)
+
+ local subnet = pool:add(hosts_per_subnet * math.random(number_of_subnets))
+
+ local subnet_ipaddr = subnet:network(subnet_prefix):add(1):string()
+ local subnet_netmask = subnet:mask(subnet_prefix):string()
+
+ return subnet_ipaddr, subnet_netmask
+ end
+end