]> code.ossystems Code Review - openembedded-core.git/commitdiff
runqemu-ifdown: clean up the remaining iptables rules
authorChen Qi <Qi.Chen@windriver.com>
Wed, 28 Aug 2013 02:52:03 +0000 (10:52 +0800)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Fri, 30 Aug 2013 15:21:15 +0000 (16:21 +0100)
The iptables rules for the tap interface are added by runqemu-ifup
everytime we use runqemu to start a qemu target. But it's not cleaned
up when runqemu exits.

This patch cleans up the remaining iptables rules for the tap interface
in runqemu-ifdown.

[YOCTO #5047]

Signed-off-by: Chen Qi <Qi.Chen@windriver.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
scripts/runqemu-ifdown

index 8b8c5a4a7aceb66f7cb5ef257192f2ba441f92af..8f66cfa2a9bdb047ed3839ced32cb6b8c89a282d 100755 (executable)
@@ -50,3 +50,17 @@ if [ ! -e "$TUNCTL" ]; then
 fi
 
 $TUNCTL -d $TAP
+
+# cleanup the remaining iptables rules
+IPTABLES=`which iptables 2> /dev/null`
+if [ "x$IPTABLES" = "x" ]; then
+       IPTABLES=/sbin/iptables
+fi
+if [ ! -x "$IPTABLES" ]; then
+       echo "$IPTABLES cannot be executed"
+       exit 1
+fi
+n=$[ (`echo $TAP | sed 's/tap//'` * 2) + 1 ]
+dest=$[ (`echo $TAP | sed 's/tap//'` * 2) + 2 ]
+$IPTABLES -D POSTROUTING -t nat -j MASQUERADE -s 192.168.7.$n/32
+$IPTABLES -D POSTROUTING -t nat -j MASQUERADE -s 192.168.7.$dest/32