Re: Ip::Address::IsAnyAddr

From: Amos Jeffries <squid3_at_treenet.co.nz>
Date: Sat, 30 Jul 2011 11:22:30 +1200

On 30/07/11 03:50, Alex Rousskov wrote:
> On 07/25/2011 08:59 AM, Tsantilas Christos wrote:
>> I am sending a version 4 of the patch which is the same with Amos patch
>> but is a little smaller. IT is easier to see the changes.
>
>
>> bool
>> Ip::Address::IsIPv4() const
>> {
>> - return IsAnyAddr() || IsNoAddr() || IN6_IS_ADDR_V4MAPPED(&m_SocketAddr.sin6_addr );
>> + return IN6_IS_ADDR_V4MAPPED(&m_SocketAddr.sin6_addr );
>> }
>>
>> bool
>> Ip::Address::IsIPv6() const
>> {
>> - return IsAnyAddr() || IsNoAddr() || !IN6_IS_ADDR_V4MAPPED(&m_SocketAddr.sin6_addr );
>> + return !IN6_IS_ADDR_V4MAPPED(&m_SocketAddr.sin6_addr );
>> }
>
> Can we rewrite IsIPv6() as "return !IsIPv4()", to clarify the intent if
> that is indeed the intent?

Internally maybe. How long until the unix socket address gets stored
there too and breaks that?

>
> Also, the documentation for these two methods seems to imply a different
> relationship, at least in some corner cases:
>
>> /** Test whether content can be used as an IPv4 address
>> \retval true if content was received as an IPv4 address
>> \retval true if content was received as an IPv4-Mapped address
>> \retval false if content was received as a non-mapped IPv6 native address.
>> */
>> bool IsIPv4() const;
>>
>> /** Test whether content can be used as an IPv6 address.
>> \retval true if --enable-ipv6 has been compiled.
>> \retval false if --disable-ipv6 has been compiled.
>> \retval false if --with-ipv6-split-stack has been compiled AND content is I
>> Pv4-mapped.
>> */
>> bool IsIPv6() const;
>
> As far as I can tell, the above definitions make it possible for both
> IsIPv4() and IsIPv6() to return true at the same time in some cases, but
> the implementation does not support that. Thus, the docs or the
> implementation is wrong.

The docs have become wrong. Since we can now convert one to the other in
some cases. That IPv4() should say the content is currenty an IPv4-only
address except for no-addr which may be both simultaneously still.
IPv6() should say its an IP address outside the IPv4-mapped range or
IPv4 no-addr.

Something like that anyway.

Amos

-- 
Please be using
   Current Stable Squid 2.7.STABLE9 or 3.1.14
   Beta testers wanted for 3.2.0.10
Received on Fri Jul 29 2011 - 23:22:37 MDT

This archive was generated by hypermail 2.2.0 : Sat Jul 30 2011 - 12:00:05 MDT