blob: c8ec8016df9d32e18ea1fa13b196332bc789d649 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
#!/bin/sh -e
. ../common.sh
gwiptbl=/tmp/p2ptbl/gwip
NodeId="$(cat /etc/nodeid)"
# determine gw IP from p2ptable
getoct () {
p2ptbl show $gwiptbl \
| cut -f1,2 \
| egrep "[0-9]*"$'\t'"$1" \
| $2 \
| head -n1 \
| cut -f1
}
# get the lowest free addr
oct3=$(getoct free "sort -n")
# no free addrs? -> steal an addr from a random ghost
if [ -z "$oct3" ]; then
oct3=$(getoct ghost "shuf")
# no ghost addrs? -> steal an addr from a random queen
if [ -z "$oct3" ]; then
oct3=$(getoct queen "shuf")
fi
# TODO: log warning about IPv4 addr space exhaustion
fi
[ -n "$oct3" ]
gwip=10.17.$oct3.1
p2ptbl update $gwiptbl $oct3 "queen\t$NodeId" br-mesh
# activate gw mode
batctl gw server
# set up gw IP
mesh_add_ipv4 $gwip 255.255.0.0
# TODO: load splash status
# setup DHCP
echo "
set dhcp.mesh=dhcp
set dhcp.mesh.start=2
set dhcp.mesh.limit=254
set dhcp.mesh.leasetime=$DHCPLeaseTime
set dhcp.mesh.interface=mesh
" | uci batch
/etc/init.d/dnsmasq restart
# start redirection httpd (for splash), add GW IP to the addrs service
# httpd listens on
echo "http://$gwip/cgi-bin/splash? /sbin/urlencode" > /tmp/redirection_target
enable_httpd redirection $randnet.1:81
change_service_httpd_listen $gwip:80
/etc/init.d/uhttpd restart
|