Patchwork [V2,1/3] runqemu-ifdown: clean up the remaining iptables rules

login
register
mail settings
Submitter Qi.Chen@windriver.com
Date Aug. 28, 2013, 2:52 a.m.
Message ID <e071a6a03a66f2765c8943e737de00215a9a4b7c.1377658086.git.Qi.Chen@windriver.com>
Download mbox | patch
Permalink /patch/56781/
State New
Headers show

Comments

Qi.Chen@windriver.com - Aug. 28, 2013, 2:52 a.m.
From: Chen Qi <Qi.Chen@windriver.com>

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>
---
 scripts/runqemu-ifdown |   14 ++++++++++++++
 1 file changed, 14 insertions(+)

Patch

diff --git a/scripts/runqemu-ifdown b/scripts/runqemu-ifdown
index 8b8c5a4..8f66cfa2 100755
--- a/scripts/runqemu-ifdown
+++ b/scripts/runqemu-ifdown
@@ -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