aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/in.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/in.h')
-rw-r--r--include/linux/in.h87
1 files changed, 74 insertions, 13 deletions
diff --git a/include/linux/in.h b/include/linux/in.h
index a8f00cac8f79..f8d607379017 100644
--- a/include/linux/in.h
+++ b/include/linux/in.h
@@ -246,21 +246,82 @@ struct sockaddr_in {
246#include <asm/byteorder.h> 246#include <asm/byteorder.h>
247 247
248#ifdef __KERNEL__ 248#ifdef __KERNEL__
249/* Some random defines to make it easier in the kernel.. */ 249
250#define LOOPBACK(x) (((x) & htonl(0xff000000)) == htonl(0x7f000000)) 250static inline bool ipv4_is_loopback(__be32 addr)
251#define MULTICAST(x) (((x) & htonl(0xf0000000)) == htonl(0xe0000000)) 251{
252#define BADCLASS(x) (((x) & htonl(0xf0000000)) == htonl(0xf0000000)) 252 return (addr & htonl(0xff000000)) == htonl(0x7f000000);
253#define ZERONET(x) (((x) & htonl(0xff000000)) == htonl(0x00000000)) 253}
254#define LOCAL_MCAST(x) (((x) & htonl(0xFFFFFF00)) == htonl(0xE0000000)) 254
255static inline bool ipv4_is_multicast(__be32 addr)
256{
257 return (addr & htonl(0xf0000000)) == htonl(0xe0000000);
258}
259
260static inline bool ipv4_is_local_multicast(__be32 addr)
261{
262 return (addr & htonl(0xffffff00)) == htonl(0xe0000000);
263}
264
265static inline bool ipv4_is_badclass(__be32 addr)
266{
267 return (addr & htonl(0xf0000000)) == htonl(0xf0000000);
268}
269
270static inline bool ipv4_is_zeronet(__be32 addr)
271{
272 return (addr & htonl(0xff000000)) == htonl(0x00000000);
273}
274
275#define LOOPBACK(x) ipv4_is_loopback(x)
276#define MULTICAST(x) ipv4_is_multicast(x)
277#define BADCLASS(x) ipv4_is_badclass(x)
278#define ZERONET(x) ipv4_is_zeronet(x)
279#define LOCAL_MCAST(x) ipv4_is_local_multicast(x)
255 280
256/* Special-Use IPv4 Addresses (RFC3330) */ 281/* Special-Use IPv4 Addresses (RFC3330) */
257#define PRIVATE_10(x) (((x) & htonl(0xff000000)) == htonl(0x0A000000)) 282
258#define LINKLOCAL_169(x) (((x) & htonl(0xffff0000)) == htonl(0xA9FE0000)) 283static inline bool ipv4_is_private_10(__be32 addr)
259#define PRIVATE_172(x) (((x) & htonl(0xfff00000)) == htonl(0xAC100000)) 284{
260#define TEST_192(x) (((x) & htonl(0xffffff00)) == htonl(0xC0000200)) 285 return (addr & htonl(0xff000000)) == htonl(0x0a000000);
261#define ANYCAST_6TO4(x) (((x) & htonl(0xffffff00)) == htonl(0xC0586300)) 286}
262#define PRIVATE_192(x) (((x) & htonl(0xffff0000)) == htonl(0xC0A80000)) 287
263#define TEST_198(x) (((x) & htonl(0xfffe0000)) == htonl(0xC6120000)) 288static inline bool ipv4_is_private_172(__be32 addr)
289{
290 return (addr & htonl(0xfff00000)) == htonl(0xac100000);
291}
292
293static inline bool ipv4_is_private_192(__be32 addr)
294{
295 return (addr & htonl(0xffff0000)) == htonl(0xc0a80000);
296}
297
298static inline bool ipv4_is_linklocal_169(__be32 addr)
299{
300 return (addr & htonl(0xffff0000)) == htonl(0xa9fe0000);
301}
302
303static inline bool ipv4_is_anycast_6to4(__be32 addr)
304{
305 return (addr & htonl(0xffffff00)) == htonl(0xc0586300);
306}
307
308static inline bool ipv4_is_test_192(__be32 addr)
309{
310 return (addr & htonl(0xffffff00)) == htonl(0xc0000200);
311}
312
313static inline bool ipv4_is_test_198(__be32 addr)
314{
315 return (addr & htonl(0xfffe0000)) == htonl(0xc6120000);
316}
264#endif 317#endif
265 318
319#define PRIVATE_10(x) ipv4_is_private_10(x)
320#define LINKLOCAL_169(x) ipv4_is_linklocal_169(x)
321#define PRIVATE_172(x) ipv4_is_private_172(x)
322#define TEST_192(x) ipv4_is_test_192(x)
323#define ANYCAST_6TO4(x) ipv4_is_anycast_6to4(x)
324#define PRIVATE_192(x) ipv4_is_private_192(x)
325#define TEST_198(x) ipv4_is_test_198(x)
326
266#endif /* _LINUX_IN_H */ 327#endif /* _LINUX_IN_H */