lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1321974652.2474.27.camel@edumazet-HP-Compaq-6005-Pro-SFF-PC>
Date:	Tue, 22 Nov 2011 16:10:52 +0100
From:	Eric Dumazet <eric.dumazet@...il.com>
To:	Alexey Dobriyan <adobriyan@...il.com>
Cc:	David Laight <David.Laight@...LAB.COM>, davem@...emloft.net,
	netdev@...r.kernel.org
Subject: Re: [PATCH] xfrm: optimize ipv4 selector matching

Le mardi 22 novembre 2011 à 17:59 +0300, Alexey Dobriyan a écrit :
> On Tue, Nov 22, 2011 at 02:50:59PM -0000, David Laight wrote:
> >  
> > > +static inline int addr4_match(const __be32 a1, const __be32 
> > > a2, const u8 prefixlen)
> > > +{
> > > +	/* C99 6.5.7 (3): u32 << 32 is undefined behaviour */
> > > +	if (prefixlen == 0) {
> > > +		/* Matching constants result in smaller assembly. */
> > > +		return 0xFFFFFFFFu;
> > > +	}
> > > +	return !((a1 ^ a2) & htonl(0xFFFFFFFFu << (32 - prefixlen)));
> > > +}
> > > +
> > 
> > It would probably be clearer to 'return 1' when prefixlen is zero.
> 
> "return 1" results in bigger code.
> This function used only in boolean context, so exact return value doesn't matter.


Thats too ugly, sorry.

Also, using "const" attributes on integral types (not pointers) make
code less clear. Caller doesnt care if the implementation wants to
change a1 or a2 or prefixlen.

Please use :

+static inline bool addr4_match(__be32 a1, __be32 a2, u8 prefixlen)
+{
+       /* C99 6.5.7 (3): u32 << 32 is undefined behaviour */
+       if (prefixlen == 0)
+               return true;
+       return !((a1 ^ a2) & htonl(0xFFFFFFFFu << (32 - prefixlen)));
+}


--
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

Powered by Openwall GNU/*/Linux Powered by OpenVZ