blob: 31b493734763df02cb16d4480787adf4bc927ed3 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * INET An implementation of the TCP/IP protocol suite for the LINUX
3 * operating system. INET is implemented using the BSD Socket
4 * interface as the means of communication with the user level.
5 *
6 * Definitions of the Internet Protocol.
7 *
8 * Version: @(#)in.h 1.0.1 04/21/93
9 *
10 * Authors: Original taken from the GNU Project <netinet/in.h> file.
11 * Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version
16 * 2 of the License, or (at your option) any later version.
17 */
18#ifndef _LINUX_IN_H
19#define _LINUX_IN_H
20
Joe Perches2658fa82007-12-16 13:42:49 -080021
Changli Gaoe7607022010-08-17 19:03:44 +000022#include <linux/errno.h>
David Howells607ca462012-10-13 10:46:48 +010023#include <uapi/linux/in.h>
Changli Gaoe7607022010-08-17 19:03:44 +000024
25static inline int proto_ports_offset(int proto)
26{
27 switch (proto) {
28 case IPPROTO_TCP:
29 case IPPROTO_UDP:
30 case IPPROTO_DCCP:
31 case IPPROTO_ESP: /* SPI */
32 case IPPROTO_SCTP:
33 case IPPROTO_UDPLITE:
34 return 0;
35 case IPPROTO_AH: /* SPI */
36 return 4;
37 default:
38 return -EINVAL;
39 }
40}
41
Joe Perches2658fa82007-12-16 13:42:49 -080042static inline bool ipv4_is_loopback(__be32 addr)
43{
44 return (addr & htonl(0xff000000)) == htonl(0x7f000000);
45}
46
47static inline bool ipv4_is_multicast(__be32 addr)
48{
49 return (addr & htonl(0xf0000000)) == htonl(0xe0000000);
50}
51
52static inline bool ipv4_is_local_multicast(__be32 addr)
53{
54 return (addr & htonl(0xffffff00)) == htonl(0xe0000000);
55}
56
Jan Engelhardt1e637c72008-01-21 03:18:08 -080057static inline bool ipv4_is_lbcast(__be32 addr)
Joe Perches2658fa82007-12-16 13:42:49 -080058{
Jan Engelhardt1e637c72008-01-21 03:18:08 -080059 /* limited broadcast */
Al Viro0ff96632008-03-17 22:48:46 -070060 return addr == htonl(INADDR_BROADCAST);
Joe Perches2658fa82007-12-16 13:42:49 -080061}
62
63static inline bool ipv4_is_zeronet(__be32 addr)
64{
65 return (addr & htonl(0xff000000)) == htonl(0x00000000);
66}
67
Fred L. Templinc7dc89c2007-11-29 22:11:40 +110068/* Special-Use IPv4 Addresses (RFC3330) */
Joe Perches2658fa82007-12-16 13:42:49 -080069
70static inline bool ipv4_is_private_10(__be32 addr)
71{
72 return (addr & htonl(0xff000000)) == htonl(0x0a000000);
73}
74
75static inline bool ipv4_is_private_172(__be32 addr)
76{
77 return (addr & htonl(0xfff00000)) == htonl(0xac100000);
78}
79
80static inline bool ipv4_is_private_192(__be32 addr)
81{
82 return (addr & htonl(0xffff0000)) == htonl(0xc0a80000);
83}
84
85static inline bool ipv4_is_linklocal_169(__be32 addr)
86{
87 return (addr & htonl(0xffff0000)) == htonl(0xa9fe0000);
88}
89
90static inline bool ipv4_is_anycast_6to4(__be32 addr)
91{
92 return (addr & htonl(0xffffff00)) == htonl(0xc0586300);
93}
94
95static inline bool ipv4_is_test_192(__be32 addr)
96{
97 return (addr & htonl(0xffffff00)) == htonl(0xc0000200);
98}
99
100static inline bool ipv4_is_test_198(__be32 addr)
101{
102 return (addr & htonl(0xfffe0000)) == htonl(0xc6120000);
103}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104#endif /* _LINUX_IN_H */