Permalink
Browse files

Initial commit of /etc/ifplugd/action.d/mesh, which is basically our

custom ifplugd script that sets up and tears down gateways.  This is
an additional copy which is Debian specific, and it's been tailored for
Debian's idiosyncracies.

Signed-off-by: The Doctor <drwho@virtadpt.net>
  • Loading branch information...
1 parent c505d6a commit 921e2d1ef01e4a9f940f477bca47d0f54da93b9f @virtadpt virtadpt committed Apr 6, 2013
Showing with 59 additions and 0 deletions.
  1. +59 −0 porteus/ifplugd/etc/ifplugd/action.d/mesh
View
59 porteus/ifplugd/etc/ifplugd/action.d/mesh
@@ -0,0 +1,59 @@
+#!/bin/sh
+
+# Figure out what network interface olsrd is listening on.
+mesh=`ps ax | grep [o]lsrd | awk '{print $NF}'`
+
+if [ "$2" = "up" ]; then
+ # Configure the network interface.
+ dhcpcd -C resolv.conf -L -q $1
+
+ # Kill olsrd.
+ killall olsrd
+
+ # Add the gateway route.
+ echo "Hna4 {0.0.0.0 0.0.0.0}" >> /etc/olsrd/olsrd.conf
+
+ # Set up NAT rules.
+ /sbin/iptables -t nat -A POSTROUTING -o $1 -j MASQUERADE
+ /sbin/iptables -A FORWARD -i $1 -o $mesh -m state --state ESTABLISHED,RELATED -j ACCEPT
+ /sbin/iptables -A FORWARD -i $mesh -o $1 -j ACCEPT
+
+ # Set up the resolv.conf file.
+ rm -f /etc/resolv.conf
+ ln -s /etc/resolv.conf.gateway /etc/resolv.conf
+
+ # Sleep for a few seconds to give everything a chance to settle.
+ sleep 3
+
+ # Restart olsrd.
+ olsrd -i $mesh
+fi
+
+if [ "$2" = "down" ]; then
+ # Kill olsrd.
+ killall olsrd && logger "olsrd killed" || logger "\[killall olsrd\] returned: $?"
+
+ # Deconfigure the network interface by killing dhcpcd.
+ dhcpcd -x $1 && logger "dhcpcd killed" || logger "\[dhcpcd -x $1\] returned: $?"
+
+ # Remove the gateway route from olsrd.conf.
+ mv /etc/olsrd/olsrd.conf /etc/olsrd/olsrd.conf.bak
+ grep -v "^Hna4 {" /etc/olsrd/olsrd.conf.bak > /etc/olsrd/olsrd.conf
+
+ # Wipe out the contents of resolv.conf because that function of dhcpcd is disabled.
+ rm -f /etc/resolv.conf
+ echo "" > /etc/resolv.conf
+
+ # Remove NAT rules.
+ /sbin/iptables -t nat -D POSTROUTING -o $1 -j MASQUERADE || logger "iptables returned: $?"
+ /sbin/iptables -D FORWARD -i $1 -o $mesh -m state --state ESTABLISHED,RELATED -j ACCEPT || logger "iptables returned: $?"
+ /sbin/iptables -D FORWARD -i $mesh -o $1 -j ACCEPT || logger "iptables returned: $?"
+
+ # Restart olsrd.
+ olsrd -i $mesh && logger "olsrd started" || logger "\[olsrd -i $mesh\] returned: $?"
+fi
+
+# Bounce avahi-daemon to propagate the new DNSes.
+/usr/sbin/avahi-daemon -r
+
+exit 1

0 comments on commit 921e2d1

Please sign in to comment.