[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20071108.031214.124029872.yoshfuji@linux-ipv6.org>
Date: Thu, 08 Nov 2007 03:12:14 +0900 (JST)
From: YOSHIFUJI Hideaki / 吉藤英明
<yoshfuji@...ux-ipv6.org>
To: netdev@...eo.de
Cc: Fred.L.Templin@...ing.com, netdev@...r.kernel.org,
yoshfuji@...ux-ipv6.org
Subject: Re: [PATCH 02/05] ipv6: RFC4214 Support
Hello.
In article <200711071658.59478.netdev@...eo.de> (at Wed, 7 Nov 2007 16:58:59 +0100), Ingo Oeser <netdev@...eo.de> says:
> > + eui[0] = 0;
> > +
> > + /* Check for RFC3330 global address ranges */
> > + if (((ipv4 >= 0x01000000) && (ipv4 < 0x0a000000)) ||
> > + ((ipv4 >= 0x0b000000) && (ipv4 < 0x7f000000)) ||
> > + ((ipv4 >= 0x80000000) && (ipv4 < 0xa9fe0000)) ||
> > + ((ipv4 >= 0xa9ff0000) && (ipv4 < 0xac100000)) ||
> > + ((ipv4 >= 0xac200000) && (ipv4 < 0xc0a80000)) ||
> > + ((ipv4 >= 0xc0a90000) && (ipv4 < 0xc6120000)) ||
> > + ((ipv4 >= 0xc6140000) && (ipv4 < 0xe0000000))) eui[0] |=
> > 0x2;
> > +
>
> Instead of converting network to host byte order at runtime
> and comparing the results to constants, let the compiler convert
> the constants to network byte order and compare in network order.
>
> so use:
>
> if (((*addr >= htonl(0x01000000)) && (*addr < htonl(0x0a000000))) || ....
>
> instead. The compiler will notice that "0x01000000" is a constant and will
> use "_constant_htonl()" automatically.
No, you cannot do this.
When you check the "range", you need to use host-byte order.
> > +
> > +static inline int ipv6_addr_is_isatap(const struct in6_addr *addr)
> > +{
> > + return (addr->s6_addr32[2] == __constant_htonl(0x02005EFE) ||
> > + addr->s6_addr32[2] == __constant_htonl(0x00005EFE));
> > +}
> > +#endif
>
> The compiler will notice that "0x01000000" is a constant and will
> use "_constant_htonl()" automatically. Please use simply htonl().
Right. And, maybe, you can write as follows:
return ((addr->s6_addr32[2] | htonl(0x02000000)) == htonl(0x02005EFE));
--yoshfuji
-
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Powered by blists - more mailing lists