You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Ryan Phillips <ry...@trolocsis.com> on 2008/06/10 01:07:16 UTC

[patch] Add IPV6 'specials' flag to mod_rewrite

So I needed to create some mod_rewrite rules only for IPv6 when httpd is
configured for both ipv4 and ipv6 modes.  This patch adds 
'RewriteCond IPV6 on' support to the ruleset.

I initially tried to see if the incoming socket was APR_INET6, but couldn't
find the right structure within the request to query.

Regards,
Ryan Phillips

Re: [patch] Add IPV6 'specials' flag to mod_rewrite - try 2

Posted by Dan Poirier <po...@pobox.com>.
Paul Querna <ch...@force-elite.com> writes:

> Ryan Phillips wrote:
>> Thanks for the tips.  IN6_IS_ADDR_V4MAPPED is defined in netinet/in.h on
>> unices and APR defines it on windows.  I've modified the patch to check for
>> APR_HAVE_IPV6 support and check for APR_HAVE_NETINET_IN_H. Also, this patch will
>> apply to trunk/.
>
> needs docs, but committed to trunk in r737973.

How about (for trunk):


Index: mod_rewrite.xml
===================================================================
--- mod_rewrite.xml	(revision 738498)
+++ mod_rewrite.xml	(working copy)
@@ -836,6 +836,13 @@
                   can be safely used regardless of whether or not
                   <module>mod_ssl</module> is loaded).</dd>
 
+                  <dt><code>IPV6</code></dt>
+
+                  <dd>Will contain the text "on" if the connection is
+                  using IPv6, or "off" otherwise.  (This variable can
+                  be safely used regardless of whether the server has
+                  IPv6 support.)</dd>
+
                 </dl>
 </note>
         </li>


Re: [patch] Add IPV6 'specials' flag to mod_rewrite - try 2

Posted by Paul Querna <ch...@force-elite.com>.
Ryan Phillips wrote:
> Thanks for the tips.  IN6_IS_ADDR_V4MAPPED is defined in netinet/in.h on
> unices and APR defines it on windows.  I've modified the patch to check for
> APR_HAVE_IPV6 support and check for APR_HAVE_NETINET_IN_H. Also, this patch will
> apply to trunk/.

needs docs, but committed to trunk in r737973.

Thanks,

Paul

Re: [patch] Add IPV6 'specials' flag to mod_rewrite - try 2

Posted by Ryan Phillips <ry...@trolocsis.com>.
Andr? Malo <nd...@perlig.de> said:
> * Ryan Phillips wrote:
> 
> > Ryan Phillips <ry...@trolocsis.com> said:
> > > Jeff Trawick <tr...@gmail.com> said:
> > > > On Mon, Jun 9, 2008 at 9:19 PM, Ryan Phillips 
> <ry...@trolocsis.com> wrote:
> > > > > Ryan Phillips <ry...@trolocsis.com> said:
> > > > >> So I needed to create some mod_rewrite rules only for IPv6 when
> > > > >> httpd is configured for both ipv4 and ipv6 modes.  This patch adds
> > > > >> 'RewriteCond IPV6 on' support to the ruleset.
> > > > >>
> > > > >> I initially tried to see if the incoming socket was APR_INET6, but
> > > > >> couldn't find the right structure within the request to query.
> > > > >
> > > > > Should r->connection->local_addr or remote_addr have the correct
> > > > > socket family?  If I try either of these over an IPv4 connection, I
> > > > > always get a socket family of IPv6.
> > > >
> > > > On most platforms, httpd will handle IPv4 connections on an IPv6
> > > > socket; the address family will be APR_INET6 and the socket address
> > > > will have a special format which indicates that the client is IPv4
> > > > (http://en.wikipedia.org/wiki/IPv4_mapped_address).
> > > >
> > > > Replace "Listen ##" with the combination "Listen 0.0.0.0:##" +
> > > > "Listen [::]:##" and you should be able to distinguish between client
> > > > connection type by checking the address family (not a real solution).
> > > >
> > > > The system macro IN6_IS_ADDR_V4MAPPED() can check if an IPv6 socket
> > > > address represents an IPv4 client connection.  Apparently APR doesn't
> > > > provide an equivalent.
> > >
> > > Jeff,
> > >
> > > Thanks for the detailed explanation.  I wasn't aware of this.
> >
> > Attached is a patch which uses IN6_IS_ADDR_V4MAPPED to see if the client
> > is from an IPv4 socket.
> 
> You should probably add conditionals for both macros (AF_INET6 and 
> IN6_IS_ADDR_V4MAPPED) and deal with non-existance properly. If INET6 is 
> missing, you can safely return "off", I think. If IN6_IS_ADDR_V4MAPPED is 
> missing - well, then "on" might be right.
> 
> Next point - which header files are the macros and structs in? Should we 
> include them explicitly? Or are they provided by APR already (and 
> officially)?
> 
> And finally, "return apr_strdup" should be replaced by "result = ". I know, 
> it's probably pasted from the HTTPS variable stuff, but that's not good 
> there too ;)
> 
> Ah, another last point - is your patch against trunk? It doesn't look like 
> it.

Thanks for the tips.  IN6_IS_ADDR_V4MAPPED is defined in netinet/in.h on
unices and APR defines it on windows.  I've modified the patch to check for
APR_HAVE_IPV6 support and check for APR_HAVE_NETINET_IN_H. Also, this patch will
apply to trunk/.

Thanks,
Ryan

Re: [patch] Add IPV6 'specials' flag to mod_rewrite - try 2

Posted by André Malo <nd...@perlig.de>.
* Ryan Phillips wrote:

> Ryan Phillips <ry...@trolocsis.com> said:
> > Jeff Trawick <tr...@gmail.com> said:
> > > On Mon, Jun 9, 2008 at 9:19 PM, Ryan Phillips 
<ry...@trolocsis.com> wrote:
> > > > Ryan Phillips <ry...@trolocsis.com> said:
> > > >> So I needed to create some mod_rewrite rules only for IPv6 when
> > > >> httpd is configured for both ipv4 and ipv6 modes.  This patch adds
> > > >> 'RewriteCond IPV6 on' support to the ruleset.
> > > >>
> > > >> I initially tried to see if the incoming socket was APR_INET6, but
> > > >> couldn't find the right structure within the request to query.
> > > >
> > > > Should r->connection->local_addr or remote_addr have the correct
> > > > socket family?  If I try either of these over an IPv4 connection, I
> > > > always get a socket family of IPv6.
> > >
> > > On most platforms, httpd will handle IPv4 connections on an IPv6
> > > socket; the address family will be APR_INET6 and the socket address
> > > will have a special format which indicates that the client is IPv4
> > > (http://en.wikipedia.org/wiki/IPv4_mapped_address).
> > >
> > > Replace "Listen ##" with the combination "Listen 0.0.0.0:##" +
> > > "Listen [::]:##" and you should be able to distinguish between client
> > > connection type by checking the address family (not a real solution).
> > >
> > > The system macro IN6_IS_ADDR_V4MAPPED() can check if an IPv6 socket
> > > address represents an IPv4 client connection.  Apparently APR doesn't
> > > provide an equivalent.
> >
> > Jeff,
> >
> > Thanks for the detailed explanation.  I wasn't aware of this.
>
> Attached is a patch which uses IN6_IS_ADDR_V4MAPPED to see if the client
> is from an IPv4 socket.

You should probably add conditionals for both macros (AF_INET6 and 
IN6_IS_ADDR_V4MAPPED) and deal with non-existance properly. If INET6 is 
missing, you can safely return "off", I think. If IN6_IS_ADDR_V4MAPPED is 
missing - well, then "on" might be right.

Next point - which header files are the macros and structs in? Should we 
include them explicitly? Or are they provided by APR already (and 
officially)?

And finally, "return apr_strdup" should be replaced by "result = ". I know, 
it's probably pasted from the HTTPS variable stuff, but that's not good 
there too ;)

Ah, another last point - is your patch against trunk? It doesn't look like 
it.

nd
-- 
If God intended people to be naked, they would be born that way.
  -- Oscar Wilde

Re: [patch] Add IPV6 'specials' flag to mod_rewrite - try 2

Posted by Ryan Phillips <ry...@trolocsis.com>.
Ryan Phillips <ry...@trolocsis.com> said:
> Jeff Trawick <tr...@gmail.com> said:
> > On Mon, Jun 9, 2008 at 9:19 PM, Ryan Phillips <ry...@trolocsis.com> wrote:
> > > Ryan Phillips <ry...@trolocsis.com> said:
> > >> So I needed to create some mod_rewrite rules only for IPv6 when httpd is
> > >> configured for both ipv4 and ipv6 modes.  This patch adds
> > >> 'RewriteCond IPV6 on' support to the ruleset.
> > >>
> > >> I initially tried to see if the incoming socket was APR_INET6, but couldn't
> > >> find the right structure within the request to query.
> > >>
> > >
> > > Should r->connection->local_addr or remote_addr have the correct socket
> > > family?  If I try either of these over an IPv4 connection, I always get a
> > > socket family of IPv6.
> > 
> > On most platforms, httpd will handle IPv4 connections on an IPv6
> > socket; the address family will be APR_INET6 and the socket address
> > will have a special format which indicates that the client is IPv4
> > (http://en.wikipedia.org/wiki/IPv4_mapped_address).
> > 
> > Replace "Listen ##" with the combination "Listen 0.0.0.0:##" + "Listen
> > [::]:##" and you should be able to distinguish between client
> > connection type by checking the address family (not a real solution).
> > 
> > The system macro IN6_IS_ADDR_V4MAPPED() can check if an IPv6 socket
> > address represents an IPv4 client connection.  Apparently APR doesn't
> > provide an equivalent.
> 
> Jeff, 
> 
> Thanks for the detailed explanation.  I wasn't aware of this.

Attached is a patch which uses IN6_IS_ADDR_V4MAPPED to see if the client is
from an IPv4 socket.

Thanks,
Ryan

Re: [patch] Add IPV6 'specials' flag to mod_rewrite

Posted by Ryan Phillips <ry...@trolocsis.com>.
Jeff Trawick <tr...@gmail.com> said:
> On Mon, Jun 9, 2008 at 9:19 PM, Ryan Phillips <ry...@trolocsis.com> wrote:
> > Ryan Phillips <ry...@trolocsis.com> said:
> >> So I needed to create some mod_rewrite rules only for IPv6 when httpd is
> >> configured for both ipv4 and ipv6 modes.  This patch adds
> >> 'RewriteCond IPV6 on' support to the ruleset.
> >>
> >> I initially tried to see if the incoming socket was APR_INET6, but couldn't
> >> find the right structure within the request to query.
> >>
> >
> > Should r->connection->local_addr or remote_addr have the correct socket
> > family?  If I try either of these over an IPv4 connection, I always get a
> > socket family of IPv6.
> 
> On most platforms, httpd will handle IPv4 connections on an IPv6
> socket; the address family will be APR_INET6 and the socket address
> will have a special format which indicates that the client is IPv4
> (http://en.wikipedia.org/wiki/IPv4_mapped_address).
> 
> Replace "Listen ##" with the combination "Listen 0.0.0.0:##" + "Listen
> [::]:##" and you should be able to distinguish between client
> connection type by checking the address family (not a real solution).
> 
> The system macro IN6_IS_ADDR_V4MAPPED() can check if an IPv6 socket
> address represents an IPv4 client connection.  Apparently APR doesn't
> provide an equivalent.

Jeff, 

Thanks for the detailed explanation.  I wasn't aware of this.

Regards,
Ryan

Re: [patch] Add IPV6 'specials' flag to mod_rewrite

Posted by Jeff Trawick <tr...@gmail.com>.
On Mon, Jun 9, 2008 at 9:19 PM, Ryan Phillips <ry...@trolocsis.com> wrote:
> Ryan Phillips <ry...@trolocsis.com> said:
>> So I needed to create some mod_rewrite rules only for IPv6 when httpd is
>> configured for both ipv4 and ipv6 modes.  This patch adds
>> 'RewriteCond IPV6 on' support to the ruleset.
>>
>> I initially tried to see if the incoming socket was APR_INET6, but couldn't
>> find the right structure within the request to query.
>>
>
> Should r->connection->local_addr or remote_addr have the correct socket
> family?  If I try either of these over an IPv4 connection, I always get a
> socket family of IPv6.

On most platforms, httpd will handle IPv4 connections on an IPv6
socket; the address family will be APR_INET6 and the socket address
will have a special format which indicates that the client is IPv4
(http://en.wikipedia.org/wiki/IPv4_mapped_address).

Replace "Listen ##" with the combination "Listen 0.0.0.0:##" + "Listen
[::]:##" and you should be able to distinguish between client
connection type by checking the address family (not a real solution).

The system macro IN6_IS_ADDR_V4MAPPED() can check if an IPv6 socket
address represents an IPv4 client connection.  Apparently APR doesn't
provide an equivalent.

Re: [patch] Add IPV6 'specials' flag to mod_rewrite

Posted by Ryan Phillips <ry...@trolocsis.com>.
Ryan Phillips <ry...@trolocsis.com> said:
> So I needed to create some mod_rewrite rules only for IPv6 when httpd is
> configured for both ipv4 and ipv6 modes.  This patch adds 
> 'RewriteCond IPV6 on' support to the ruleset.
> 
> I initially tried to see if the incoming socket was APR_INET6, but couldn't
> find the right structure within the request to query.
> 

Should r->connection->local_addr or remote_addr have the correct socket
family?  If I try either of these over an IPv4 connection, I always get a
socket family of IPv6.

-Ryan