summaryrefslogtreecommitdiff
path: root/files/common/etc/fsm/inetable/trans
diff options
context:
space:
mode:
Diffstat (limited to 'files/common/etc/fsm/inetable/trans')
-rwxr-xr-xfiles/common/etc/fsm/inetable/trans/boot.leave11
-rwxr-xr-xfiles/common/etc/fsm/inetable/trans/ghost-queen.trans14
-rwxr-xr-xfiles/common/etc/fsm/inetable/trans/ghost.enter3
-rwxr-xr-xfiles/common/etc/fsm/inetable/trans/ghost.leave17
-rwxr-xr-xfiles/common/etc/fsm/inetable/trans/queen-ghost.trans15
-rwxr-xr-xfiles/common/etc/fsm/inetable/trans/queen.enter45
-rwxr-xr-xfiles/common/etc/fsm/inetable/trans/queen.leave16
-rwxr-xr-xfiles/common/etc/fsm/inetable/trans/robinson.enter31
-rwxr-xr-xfiles/common/etc/fsm/inetable/trans/robinson.leave12
9 files changed, 164 insertions, 0 deletions
diff --git a/files/common/etc/fsm/inetable/trans/boot.leave b/files/common/etc/fsm/inetable/trans/boot.leave
new file mode 100755
index 0000000..233ef9e
--- /dev/null
+++ b/files/common/etc/fsm/inetable/trans/boot.leave
@@ -0,0 +1,11 @@
+#!/bin/sh -e
+
+# init gwid table by merging it with a hand-crafted table in which all
+# available IPs are stored as free with version zero. This guarantees
+# that any update on any node will have a higher version.
+for i in $(seq 0 254); do
+ echo -e "$i\t0\tfree"
+done > /tmp/gwip-init
+p2ptbl init /tmp/p2ptbl/gwip
+p2ptbl merge /tmp/p2ptbl/gwip /tmp/gwip-init
+rm /tmp/gwip-init
diff --git a/files/common/etc/fsm/inetable/trans/ghost-queen.trans b/files/common/etc/fsm/inetable/trans/ghost-queen.trans
new file mode 100755
index 0000000..117aab9
--- /dev/null
+++ b/files/common/etc/fsm/inetable/trans/ghost-queen.trans
@@ -0,0 +1,14 @@
+#!/bin/sh -e
+. ../common_queen.sh
+
+rm /tmp/ghost_since
+
+# announce our gw again
+batctl gw server
+
+# update status of our gateway ip
+if we_own_our_ip; then
+ p2ptbl update $gwiptbl $oct3 "queen\t$NodeId" br-mesh
+fi
+
+# TODO: remove traffic redirection \ No newline at end of file
diff --git a/files/common/etc/fsm/inetable/trans/ghost.enter b/files/common/etc/fsm/inetable/trans/ghost.enter
new file mode 100755
index 0000000..60bff11
--- /dev/null
+++ b/files/common/etc/fsm/inetable/trans/ghost.enter
@@ -0,0 +1,3 @@
+#!/bin/sh -e
+
+date +%s > /tmp/ghost_since
diff --git a/files/common/etc/fsm/inetable/trans/ghost.leave b/files/common/etc/fsm/inetable/trans/ghost.leave
new file mode 100755
index 0000000..747a05d
--- /dev/null
+++ b/files/common/etc/fsm/inetable/trans/ghost.leave
@@ -0,0 +1,17 @@
+#!/bin/sh -e
+
+rm /tmp/ghost_since
+
+# free our gw ip
+ifconfig br-mesh 0.0.0.0
+
+# update status of our gateway ip
+if we_own_our_ip; then
+ p2ptbl update $gwiptbl $oct3 free br-mesh
+fi
+
+# disable DHCP
+uci delete dhcp.mesh
+/etc/init.d/dnsmasq restart
+
+# TODO: remove internet redirection & splash iptable \ No newline at end of file
diff --git a/files/common/etc/fsm/inetable/trans/queen-ghost.trans b/files/common/etc/fsm/inetable/trans/queen-ghost.trans
new file mode 100755
index 0000000..7cd791d
--- /dev/null
+++ b/files/common/etc/fsm/inetable/trans/queen-ghost.trans
@@ -0,0 +1,15 @@
+#!/bin/sh -e
+. ../common_queen.sh
+
+# store since when we are a ghost
+date +%s >/tmp/ghost_since
+
+# do not announce gateway anymore
+batctl gw client
+
+# update status of our gateway ip
+if we_own_our_ip; then
+ p2ptbl update $gwiptbl $oct3 "ghost\t$NodeId" br-mesh
+fi
+
+# TODO: setup redirection of all traffic to another gateway
diff --git a/files/common/etc/fsm/inetable/trans/queen.enter b/files/common/etc/fsm/inetable/trans/queen.enter
new file mode 100755
index 0000000..a8a1a8e
--- /dev/null
+++ b/files/common/etc/fsm/inetable/trans/queen.enter
@@ -0,0 +1,45 @@
+#!/bin/sh -e
+
+gwiptbl=/tmp/p2ptbl/gwip
+
+# determine gw IP from p2ptable
+getoct () {
+ p2ptbl show $gwiptbl \
+ | cut -f1,2 \
+ | egrep "[0-9]*"$'\t'"$1" \
+ | $2 \
+ | head -n1
+}
+# 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
+ifconfig br-mesh 10.17.$oct3.1
+
+# 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 \ No newline at end of file
diff --git a/files/common/etc/fsm/inetable/trans/queen.leave b/files/common/etc/fsm/inetable/trans/queen.leave
new file mode 100755
index 0000000..660f2e2
--- /dev/null
+++ b/files/common/etc/fsm/inetable/trans/queen.leave
@@ -0,0 +1,16 @@
+#!/bin/sh -e
+. ../common_queen.sh
+
+# do not announce gateway anymore
+batctl gw client
+
+# release IP in p2ptable (if we still own it)
+if we_own_our_ip; then
+ p2ptbl update $gwiptbl $oct3 free br-mesh
+fi
+
+# disable DHCP
+uci delete dhcp.mesh
+/etc/init.d/dnsmasq restart
+
+# TODO remove splash iptable
diff --git a/files/common/etc/fsm/inetable/trans/robinson.enter b/files/common/etc/fsm/inetable/trans/robinson.enter
new file mode 100755
index 0000000..7ea0001
--- /dev/null
+++ b/files/common/etc/fsm/inetable/trans/robinson.enter
@@ -0,0 +1,31 @@
+#!/bin/sh -e
+
+# setup random ip
+gen_randnet () {
+ randnet=21.$(($RANDOM % 256)).$(($RANDOM % 256))
+}
+
+gen_randnet
+while ! arping -I br-mesh -D -c 5 -q $randnet.1; do
+ gen_randnet
+done
+ifconfig br-mesh $randnet.1
+
+# setup dhcp
+echo "
+set dhcp.mesh=dhcp
+set dhcp.mesh.start=2
+set dhcp.mesh.limit=254
+set dhcp.mesh.leasetime=60
+set dhcp.mesh.interface=mesh
+set dhcp.mesh.start_ip=$randnet.2
+set dhcp.mesh.end_ip=$randnet.254
+" | uci batch
+/etc/init.d/dnsmasq restart
+
+# announce fake gateway; TODO: announce only tiny bandwith
+batctl gw server
+
+# TODO: start fake dns
+
+# TODO: redirect all inet traffic to local httpd
diff --git a/files/common/etc/fsm/inetable/trans/robinson.leave b/files/common/etc/fsm/inetable/trans/robinson.leave
new file mode 100755
index 0000000..b7f49b8
--- /dev/null
+++ b/files/common/etc/fsm/inetable/trans/robinson.leave
@@ -0,0 +1,12 @@
+#!/bin/sh -e
+
+# stop announcing fake gateway
+batctl gw client
+
+# stop DHCP server
+uci delete dhcp.mesh
+/etc/init.d/dnsmasq restart
+
+# TODO: stop fake dns
+
+# TODO: stop redirecting all inet traffic to local httpd
contact: Jan Huwald // Impressum