vif-common.sh to support tap network devices in iptables FORWARD chain
PATCH 1/1 vif-common.sh to support tap network devices in iptables FORWARD chain
Hi Xen Development Team,
I submit the below patch for your consideration. This is useful if antispoof is enabled and tap network devices are used. i.e. HVM windows.
vif-common.sh 2009-07-07 19:19:42.000000000 +0800 renamed from vif-common.sh.orig 2009-07-07 19:09:39.000000000 +0800 +15 -0
@@ -73,6 +73,21 @@ local c="-D" fi + # Added support for tap network devices in iptables FORWARD chain as this + # is required if antispoof is enabled or otherwise all packets to/from tap + # devices will be dropped. + # Start adding by Giam Teck Choon. + local tapif=`echo $vif | sed 's/vif/tap/'` + local checktapif=`cat /proc/net/dev | grep "${tapif}:" | grep -v grep` + + if [ -n "$checktapif" ] ; then + iptables "$c" FORWARD -m physdev --physdev-in "$tapif" "$@" -j ACCEPT \ + 2>/dev/null && + iptables "$c" FORWARD -m state --state RELATED,ESTABLISHED -m physdev \ + --physdev-out "$tapif" -j ACCEPT 2>/dev/null + fi + # End adding by Giam Teck Choon. + iptables "$c" FORWARD -m physdev --physdev-in "$vif" "$@" -j ACCEPT \ 2>/dev/null && iptables "$c" FORWARD -m state --state RELATED,ESTABLISHED -m physdev \
Thanks.
Kindest regards,
Giam Teck Choon
Sorry, the previous patch I sent in only support xm create to add in iptables FORWARD chain but when you xm shutdown the tap related ruleset is not removed from iptables FORWARD chain. Below is the patch which support xm create and xm shutdown.
vif-common.sh 2009-07-07 19:47:48.000000000 +0800 renamed from vif-common.sh.orig 2009-07-07 19:09:39.000000000 +0800 +9 -0
@@ -73,6 +73,24 @@ local c="-D" fi + # Added support for tap network devices in iptables FORWARD chain as this + # is required if antispoof is enabled or otherwise all packets to/from tap + # devices will be dropped. + # Start adding by Giam Teck Choon. + local tapif=`echo $vif | sed 's/vif/tap/'` + # for xm create + local checktapif=`cat /proc/net/dev | grep "${tapif}:" | grep -v grep` + # for xm shutdown + local checktapstate=`iptables -L -n | grep "state
RELATED,ESTABLISHED PHYSDEV match --physdev-out ${tapif}"` +
+ if [ -n "$checktapif" ] || [ -n "$checktapstate" ] ; then
+ iptables "$c" FORWARD -m physdev --physdev-in "$tapif" "$@" -j ACCEPT \
+ 2>/dev/null &&
+ iptables "$c" FORWARD -m state --state RELATED,ESTABLISHED -m physdev \
+ --physdev-out "$tapif" -j ACCEPT 2>/dev/null
+ fi
+ # End adding by Giam Teck Choon.
+
iptables "$c" FORWARD -m physdev --physdev-in "$vif" "$@" -j ACCEPT \
2>/dev/null &&iptables "$c" FORWARD -m state --state RELATED,ESTABLISHED -m physdev \
Thanks.
Kindest regards,
Giam Teck Choon
Hi,
Quoted 8 lines · Teck Choon Giam
Sorry, the previous patch I sent in only support xm create to add in iptables FORWARD chain but when you xm shutdown the tap related ruleset is not removed from iptables FORWARD chain. Below is the patch which support xm create and xm shutdown.
vif-common.sh 2009-07-07 19:47:48.000000000 +0800 line 79
Quoted 7 lines
vif-common.sh 2009-07-07 19:47:48.000000000 +0800 renamed from vif-common.sh.orig 2009-07-07 19:09:39.000000000 +0800 +4
-0@@ -73,6 +73,24 @@ local c="-D" fi + # Added support for tap network devices in iptables FORWARD chain as this + # is required if antispoof is enabled or otherwise all packets to/from tap + # devices will be dropped. + # Start adding by Giam Teck Choon.
Its not necessary to add comments that read like a changelog as they go in the changelog which is included in the version control system. Rather, comments in the code should just explain what the code does.
vif-common.sh 2009-07-07 19:47:48.000000000 +0800 line 82
Quoted 3 lines
vif-common.sh 2009-07-07 19:47:48.000000000 +0800 renamed from vif-common.sh.orig 2009-07-07 19:09:39.000000000 +0800 +3
-0+ local tapif=`echo $vif | sed 's/vif/tap/'` + # for xm create + local checktapif=`cat /proc/net/dev | grep "${tapif}:" | grep -v grep`
Why is the second grep needed?
vif-common.sh 2009-07-07 19:47:48.000000000 +0800
Quoted 11 lines
vif-common.sh 2009-07-07 19:47:48.000000000 +0800 renamed from vif-common.sh.orig 2009-07-07 19:09:39.000000000 +0800 +2
-0+ # for xm shutdown + local checktapstate=`iptables -L -n | grep "stateRELATED,ESTABLISHED PHYSDEV match --physdev-out ${tapif}"`
vif-common.sh 2009-07-07 19:47:48.000000000 +0800 renamed from vif-common.sh.orig 2009-07-07 19:09:39.000000000 +0800 +8
-0+ + if [ -n "$checktapif" ] || [ -n "$checktapstate" ] ; then + iptables "$c" FORWARD -m physdev --physdev-in "$tapif" "$@" -j ACCEPT \ + 2>/dev/null && + iptables "$c" FORWARD -m state --state RELATED,ESTABLISHED -m physdev \ + --physdev-out "$tapif" -j ACCEPT 2>/dev/null + fi + # End adding by Giam Teck Choon.
Comments like this are not necessary either.
Quoted 15 lines
+
iptables "$c" FORWARD -m physdev --physdev-in "$vif" "$@" -j ACCEPT \ 2>/dev/null &&iptables "$c" FORWARD -m state --state RELATED,ESTABLISHED -m physdev \
Thanks.
Kindest regards,
Giam Teck Choon_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Hi,
Quoted 14 lines · Simon Horman
Hi,
Quoted 11 lines · Teck Choon Giam
Sorry, the previous patch I sent in only support xm create to add in iptables FORWARD chain but when you xm shutdown the tap related ruleset is not removed from iptables FORWARD chain. Below is the patch which support xm create and xm shutdown.
vif-common.sh 2009-07-07 19:47:48.000000000 +0800 renamed from vif-common.sh.orig 2009-07-07 19:09:39.000000000 +0800 +0
-0@@ -73,6 +73,24 @@local c="-D"
fi
Quoted 8 lines
Quoted 4 lines
+ # Added support for tap network devices in iptables FORWARD chain as this
+ # is required if antispoof is enabled or otherwise all packets to/from tap
+ # devices will be dropped.
+ # Start adding by Giam Teck Choon.Its not necessary to add comments that read like a changelog as they go in the changelog which is included in the version control system. Rather, comments in the code should just explain what the code does.
Then there isn't a need to have such comments in the patch I submit. I will remove the comments then if the patch is fine.
Quoted 6 lines
Quoted 4 lines
+ local tapif=
echo $vif | sed 's/vif/tap/'
+ # for xm create
+ local checktapif=cat /proc/net/dev | grep "${tapif}:" | grep -v grepWhy is the second grep needed?
This is just my habit to include grep -v grep and you are free to remove it. Some shell scripts I coded needed that if the grep result grep itself especially for ps fauwx related.
Quoted 12 lines
Quoted 11 lines
+ # for xm shutdown
+ local checktapstate=iptables -L -n | grep "state RELATED,ESTABLISHED PHYSDEV match --physdev-out ${tapif}"
+
+ if [ -n "$checktapif" ] || [ -n "$checktapstate" ] ; then
+ iptables "$c" FORWARD -m physdev --physdev-in "$tapif" "$@" -j ACCEPT \
+ 2>/dev/null &&
+ iptables "$c" FORWARD -m state --state RELATED,ESTABLISHED -m physdev \
+ --physdev-out "$tapif" -j ACCEPT 2>/dev/null
+ fi
+ # End adding by Giam Teck Choon.
Quoted 1 line
Comments like this are not necessary either.
Ok noted.
Thanks.
Kindest regards,
Giam Teck Choon