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>] [day] [month] [year] [list]
Message-Id: <1195540903.4675.92.camel@localhost>
Date:	Mon, 19 Nov 2007 22:41:43 -0800
From:	Joe Perches <joe@...ches.com>
To:	David Miller <davem@...emloft.net>
Cc:	netdev <netdev@...r.kernel.org>,
	"Pekka Savola (ipv6)" <pekkas@...core.fi>,
	Alexey Kuznetsov <kuznet@....inr.ac.ru>,
	Hideaki YOSHIFUJI <yoshfuji@...ux-ipv6.org>,
	James Morris <jmorris@...ei.org>,
	Patrick McHardy <kaber@...eworks.de>
Subject: [PATCH net-2.6.25 1/4] include - Convert IP4 address class macros
	to inline functions

Change LOOPBACK MULTICAST LOCAL_MCAST BADCLASS and ZERONET
macros to inline functions ipv4_is_<type>(__be32 addr)

Adds some type safety and arguably some readability

No change in compiled image size

Signed-off-by: Joe Perches <joe@...ches.com>

---

 include/linux/in.h |   45 ++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 40 insertions(+), 5 deletions(-)

diff --git a/include/linux/in.h b/include/linux/in.h
index 3975cbf..ac6eff1 100644
--- a/include/linux/in.h
+++ b/include/linux/in.h
@@ -246,12 +246,47 @@ struct sockaddr_in {
 #include <asm/byteorder.h> 
 
 #ifdef __KERNEL__
+
+static inline __be32 ipv4_addr_octets(unsigned char a, unsigned char b, unsigned char c, unsigned char d)
+{
+	return htonl((((__u32)(a & 0xff)) << 24) |
+		     (((__u32)(b & 0xff)) << 16) |
+		     (((__u32)(c & 0xff)) << 8) |
+		     (((__u32)(d & 0xff)) << 0));
+}
+
+static inline bool ipv4_is_loopback(__be32 addr)
+{
+	return (addr & ipv4_addr_octets(255,0,0,0)) == ipv4_addr_octets(127,0,0,0);
+}
+
+static inline bool ipv4_is_multicast(__be32 addr)
+{
+	return (addr & ipv4_addr_octets(240,0,0,0)) == ipv4_addr_octets(224,0,0,0);
+}
+
+static inline bool ipv4_is_local_multicast(__be32 addr)
+{
+	return (addr & ipv4_addr_octets(255,255,255,0)) == ipv4_addr_octets(224,0,0,0);
+}
+
+static inline bool ipv4_is_badclass(__be32 addr)
+{
+	return (addr & ipv4_addr_octets(240,0,0,0)) == ipv4_addr_octets(240,0,0,0);
+}
+
+static inline bool ipv4_is_zeronet(__be32 addr)
+{
+	return (addr & ipv4_addr_octets(255,0,0,0)) == ipv4_addr_octets(0,0,0,0);
+}
+
 /* Some random defines to make it easier in the kernel.. */
-#define LOOPBACK(x)	(((x) & htonl(0xff000000)) == htonl(0x7f000000))
-#define MULTICAST(x)	(((x) & htonl(0xf0000000)) == htonl(0xe0000000))
-#define BADCLASS(x)	(((x) & htonl(0xf0000000)) == htonl(0xf0000000))
-#define ZERONET(x)	(((x) & htonl(0xff000000)) == htonl(0x00000000))
-#define LOCAL_MCAST(x)	(((x) & htonl(0xFFFFFF00)) == htonl(0xE0000000))
+
+#define LOOPBACK(x)	ipv4_is_loopback(x)
+#define MULTICAST(x)	ipv4_is_multicast(x)
+#define LOCAL_MCAST(x)	ipv4_is_local_multicast(x)
+#define BADCLASS(x)	ipv4_is_badclass(x)
+#define ZERONET(x)	ipv4_is_zeronet(x)
 
 #endif
 


-
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