summaryrefslogtreecommitdiff
path: root/files/common/etc/fsm/inetable/trans/queen.enter
blob: 8bcf968460ca27e707704171f2f87082d936ef49 (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/sh -e
. ../common.sh

gwiptbl=/tmp/p2ptbl/gwip
NodeId="$(cat /etc/nodeid)"

## setup gateway IPv4
# 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" ]
net_mesh=$(uci get cloud.cur.net_mesh)
gwip=$(      ipcalc.sh $net_mesh $(($oct3 * 256 + 1))   1 | grep ^START | cut -f2 -d=)
dhcp_start=$(ipcalc.sh $net_mesh $(($oct3 * 256 + 2))   1 | grep ^START | cut -f2 -d=)
dhcp_end=$(  ipcalc.sh $net_mesh $(($oct3 * 256 + 254)) 1 | grep ^START | cut -f2 -d=)

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

## 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=$dhcp_start
set dhcp.mesh.end_ip=$dhcp_end
" | uci batch
/etc/init.d/dnsmasq restart

## set splash
# start redirection httpd (for splash), add GW IP to the addrs service
# httpd listens on
echo "http://$gwip/cgi-bin/splash.html? /usr/sbin/urlencode" > /tmp/redirection_target
enable_httpd redirection    $gwip:81
change_service_httpd_listen $gwip:80
/etc/init.d/uhttpd restart

# fill splash table
splash_sync "$1"

# redirect tcp to local httpd, dns to local ns
iptables -t nat -F prerouting_inet_unsplashed
iptables -t nat -A prerouting_inet_unsplashed -p tcp            -j DNAT --to $gwip:81
iptables -t nat -A prerouting_inet_unsplashed -p udp --dport 53 -j DNAT --to $gwip:53
# TODO: discard any other UDP traffic

## start N2N
/etc/init.d/n2n start
contact: Jan Huwald // Impressum