0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef _LINUX_IN_H
0015 #define _LINUX_IN_H
0016
0017
0018 #include <linux/errno.h>
0019 #include <uapi/linux/in.h>
0020
0021 static inline int proto_ports_offset(int proto)
0022 {
0023 switch (proto) {
0024 case IPPROTO_TCP:
0025 case IPPROTO_UDP:
0026 case IPPROTO_DCCP:
0027 case IPPROTO_ESP:
0028 case IPPROTO_SCTP:
0029 case IPPROTO_UDPLITE:
0030 return 0;
0031 case IPPROTO_AH:
0032 return 4;
0033 default:
0034 return -EINVAL;
0035 }
0036 }
0037
0038 static inline bool ipv4_is_loopback(__be32 addr)
0039 {
0040 return (addr & htonl(0xff000000)) == htonl(0x7f000000);
0041 }
0042
0043 static inline bool ipv4_is_multicast(__be32 addr)
0044 {
0045 return (addr & htonl(0xf0000000)) == htonl(0xe0000000);
0046 }
0047
0048 static inline bool ipv4_is_local_multicast(__be32 addr)
0049 {
0050 return (addr & htonl(0xffffff00)) == htonl(0xe0000000);
0051 }
0052
0053 static inline bool ipv4_is_lbcast(__be32 addr)
0054 {
0055
0056 return addr == htonl(INADDR_BROADCAST);
0057 }
0058
0059 static inline bool ipv4_is_all_snoopers(__be32 addr)
0060 {
0061 return addr == htonl(INADDR_ALLSNOOPERS_GROUP);
0062 }
0063
0064 static inline bool ipv4_is_zeronet(__be32 addr)
0065 {
0066 return (addr == 0);
0067 }
0068
0069
0070
0071 static inline bool ipv4_is_private_10(__be32 addr)
0072 {
0073 return (addr & htonl(0xff000000)) == htonl(0x0a000000);
0074 }
0075
0076 static inline bool ipv4_is_private_172(__be32 addr)
0077 {
0078 return (addr & htonl(0xfff00000)) == htonl(0xac100000);
0079 }
0080
0081 static inline bool ipv4_is_private_192(__be32 addr)
0082 {
0083 return (addr & htonl(0xffff0000)) == htonl(0xc0a80000);
0084 }
0085
0086 static inline bool ipv4_is_linklocal_169(__be32 addr)
0087 {
0088 return (addr & htonl(0xffff0000)) == htonl(0xa9fe0000);
0089 }
0090
0091 static inline bool ipv4_is_anycast_6to4(__be32 addr)
0092 {
0093 return (addr & htonl(0xffffff00)) == htonl(0xc0586300);
0094 }
0095
0096 static inline bool ipv4_is_test_192(__be32 addr)
0097 {
0098 return (addr & htonl(0xffffff00)) == htonl(0xc0000200);
0099 }
0100
0101 static inline bool ipv4_is_test_198(__be32 addr)
0102 {
0103 return (addr & htonl(0xfffe0000)) == htonl(0xc6120000);
0104 }
0105 #endif