Merge branch 'topic/namespace' of git://git.kernel.org/pub/scm/linux/kernel/git/broon...
[sfrench/cifs-2.6.git] / include / linux / in.h
1 /*
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
21
22 #include <linux/errno.h>
23 #include <uapi/linux/in.h>
24
25 static 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
42 static inline bool ipv4_is_loopback(__be32 addr)
43 {
44         return (addr & htonl(0xff000000)) == htonl(0x7f000000);
45 }
46
47 static inline bool ipv4_is_multicast(__be32 addr)
48 {
49         return (addr & htonl(0xf0000000)) == htonl(0xe0000000);
50 }
51
52 static inline bool ipv4_is_local_multicast(__be32 addr)
53 {
54         return (addr & htonl(0xffffff00)) == htonl(0xe0000000);
55 }
56
57 static inline bool ipv4_is_lbcast(__be32 addr)
58 {
59         /* limited broadcast */
60         return addr == htonl(INADDR_BROADCAST);
61 }
62
63 static inline bool ipv4_is_zeronet(__be32 addr)
64 {
65         return (addr & htonl(0xff000000)) == htonl(0x00000000);
66 }
67
68 /* Special-Use IPv4 Addresses (RFC3330) */
69
70 static inline bool ipv4_is_private_10(__be32 addr)
71 {
72         return (addr & htonl(0xff000000)) == htonl(0x0a000000);
73 }
74
75 static inline bool ipv4_is_private_172(__be32 addr)
76 {
77         return (addr & htonl(0xfff00000)) == htonl(0xac100000);
78 }
79
80 static inline bool ipv4_is_private_192(__be32 addr)
81 {
82         return (addr & htonl(0xffff0000)) == htonl(0xc0a80000);
83 }
84
85 static inline bool ipv4_is_linklocal_169(__be32 addr)
86 {
87         return (addr & htonl(0xffff0000)) == htonl(0xa9fe0000);
88 }
89
90 static inline bool ipv4_is_anycast_6to4(__be32 addr)
91 {
92         return (addr & htonl(0xffffff00)) == htonl(0xc0586300);
93 }
94
95 static inline bool ipv4_is_test_192(__be32 addr)
96 {
97         return (addr & htonl(0xffffff00)) == htonl(0xc0000200);
98 }
99
100 static inline bool ipv4_is_test_198(__be32 addr)
101 {
102         return (addr & htonl(0xfffe0000)) == htonl(0xc6120000);
103 }
104 #endif  /* _LINUX_IN_H */