summaryrefslogtreecommitdiff
path: root/files/common/etc/fsm/inetable/trans/queen.enter
blob: fe0799e3521b9964ccbd5e1556d063e740f3d9f7 (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
#!/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" ]
p2ptbl update $gwiptbl $oct3 "queen\t$NodeId" br-mesh

# activate gw mode
batctl gw server

# set up gw IP
mesh_add_ipv4 10.17.$oct3.1 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
set dhcp.mesh.start_ip=10.17.$oct3.2
set dhcp.mesh.end_ip=10.17.$oct3.254
" | uci batch
/etc/init.d/dnsmasq restart
contact: Jan Huwald // Impressum