From: Ian Campbell Subject: Re: [PATCH 4/5] hotplug/linux: Add IPv6 support to the iptables logic Date: Thu, 15 May 2014 17:19:19 +0100 Message-ID: <1400170759.883.14.camel@kazak.uk.xensource.com> References: <1400081005-23895-1-git-send-email-s.munaut@whatever-company.com> <1400081005-23895-5-git-send-email-s.munaut@whatever-company.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta4.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1WkyNl-0000Wh-3t for xen-devel@lists.xenproject.org; Thu, 15 May 2014 16:19:45 +0000 In-Reply-To: <1400081005-23895-5-git-send-email-s.munaut@whatever-company.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Sylvain Munaut Cc: xen-devel@lists.xenproject.org List-Id: xen-devel@lists.xenproject.org On Wed, 2014-05-14 at 17:23 +0200, Sylvain Munaut wrote: > This adds the same functions for ip6tables as the one for iptables. > The 'ip' variable can now contain ipv6s for the domain and add > appropriate rules > > - If the 'ip' var is empty then both full IPv4 and IPv6 are allowed. > - If only IPv4 ips are present, then IPv6 will be completely disallowed. > - If only IPv6 ips are present, then IPv4 will be completely disallowed. > - You can use ::0/0 or 0.0.0.0/0 to allow v6 or v4 globally but filter > the other one. Sounds sensible. Can you give examples of the rulesets create in each case? > This gracefully handles if the dom0 doesn't have IPv6. If > the call to ip6tables doesn't succeed, it just ignores any > IPv6 stuff. > > By default, domains aren't allows to send Router Advertisement > or DHCP responses, see the ipv6_allow_ra to enable them. How does one go about setting this? > +## > +# Check if the given IP is IPv6 or not > +# > +is_ipv6() > +{ > + echo "$1" | perl -wane '/:/ && print "yes"' Annoyingly I don't think we currently require Perl in the runtime environment (it is used at build time). Luckily I think you can implement this as case $addr in *:*) ipv6_addrs="$addrs $ipv6_addrs";; *) ipv4.... ;; esac (probably inline in the handle_iptable function, no need for this helper in that case) > @@ -182,25 +252,41 @@ handle_iptable() > return > fi > > + # User has a working IPv4 iptables, but maybe no IPv6 support ... > + local do_ipv6="yes" > + > + if ! ip6tables -L -n >&/dev/null > + then > + do_ipv6="no" > + fi > + > # Scan through the addresses > local ipv4_addrs > + local ipv6_addrs > > if [ "$ip" != "" ] > then > local addr > for addr in $ip I see now why you had a loop in the previous patch. > do > + result=$(is_ipv6 "$addr") > + if [ -z "$result" ] ; then > ipv4_addrs="$addr $ipv4_addrs" > + else > + ipv6_addrs="$addr $ipv6_addrs" > + fi > done > else > # No IP addresses have been specified, so allow anything. > ipv4_addrs="any" > + ipv6_addrs="any" > fi > > # Actually add the rules > claim_lock "iptables" > > [ "$ipv4_addrs" != "" ] && frob_iptable "$ipv4_addrs" > + [ "$ipv6_addrs" != "" -a "$do_ipv6" = "yes" ] && frob_ip6table "$ipv6_addrs" > > release_lock "iptables" > }