#!/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" ] 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 ## 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 ## set splash # 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 $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