From: Teck Choon Giam Subject: Re: Re: [PATCH] vif-common.sh to support tap network devices in iptables FORWARD chain Date: Tue, 14 Jul 2009 12:07:33 +0800 Message-ID: <9b5c9bb30907132107q1799f591kaede488fbe7bdff5@mail.gmail.com> References: <9b5c9bb30907070429m19fa021yacef5f3c9d664ec5@mail.gmail.com> <9b5c9bb30907070449q5cdedd24y56483999f4463b12@mail.gmail.com> <20090713234533.GB10136@verge.net.au> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Return-path: In-Reply-To: <20090713234533.GB10136@verge.net.au> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org Hi, On Tue, Jul 14, 2009 at 7:45 AM, Simon Horman wrote: > Hi, > > On Tue, Jul 07, 2009 at 07:49:15PM +0800, Teck Choon Giam wrote: >> 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. =A0Below is the >> patch which support xm create and xm shutdown. >> >> --- vif-common.sh.orig =A02009-07-07 19:09:39.000000000 +0800 >> +++ vif-common.sh =A0 =A0 =A0 2009-07-07 19:47:48.000000000 +0800 >> @@ -73,6 +73,24 @@ >> =A0 =A0 =A0local c=3D"-D" >> =A0 =A0fi >> >> + =A0# Added support for tap network devices in iptables FORWARD chain a= s this >> + =A0# is required if antispoof is enabled or otherwise all packets to/f= rom tap >> + =A0# devices will be dropped. >> + =A0# 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. > >> + =A0local tapif=3D`echo $vif | sed 's/vif/tap/'` >> + =A0# for xm create >> + =A0local checktapif=3D`cat /proc/net/dev | grep "${tapif}:" | grep -v = grep` > > Why 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. >> + =A0# for xm shutdown >> + =A0local checktapstate=3D`iptables -L -n | grep "state >> RELATED,ESTABLISHED PHYSDEV match --physdev-out ${tapif}"` >> + >> + =A0if [ -n "$checktapif" ] || [ -n "$checktapstate" ] ; then >> + =A0 =A0iptables "$c" FORWARD -m physdev --physdev-in "$tapif" "$@" -j = ACCEPT \ >> + =A0 =A0 =A02>/dev/null && >> + =A0 =A0iptables "$c" FORWARD -m state --state RELATED,ESTABLISHED -m p= hysdev \ >> + =A0 =A0 =A0--physdev-out "$tapif" -j ACCEPT 2>/dev/null >> + =A0fi >> + =A0# End adding by Giam Teck Choon. > > Comments like this are not necessary either. Ok noted. Thanks. Kindest regards, Giam Teck Choon