>> 1 /* SPDX-License-Identifier: GPL-2.0-or-later */ 1 /* 2 /* 2 * INET An implementation of the TCP/I 3 * INET An implementation of the TCP/IP protocol suite for the LINUX 3 * operating system. INET is imp 4 * operating system. INET is implemented using the BSD Socket 4 * interface as the means of comm 5 * interface as the means of communication with the user level. 5 * 6 * 6 * Definitions of the Internet Pr 7 * Definitions of the Internet Protocol. 7 * 8 * 8 * Version: @(#)in.h 1.0.1 04/21/ 9 * Version: @(#)in.h 1.0.1 04/21/93 9 * 10 * 10 * Authors: Original taken from the GNU Pr 11 * Authors: Original taken from the GNU Project <netinet/in.h> file. 11 * Fred N. van Kempen, <waltje@uW 12 * Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG> 12 * << 13 * This program is free software; << 14 * modify it under the terms of t << 15 * as published by the Free Softw << 16 * 2 of the License, or (at your << 17 */ 13 */ 18 #ifndef _LINUX_IN_H 14 #ifndef _LINUX_IN_H 19 #define _LINUX_IN_H 15 #define _LINUX_IN_H 20 16 21 17 22 #include <linux/errno.h> 18 #include <linux/errno.h> 23 #include <uapi/linux/in.h> 19 #include <uapi/linux/in.h> 24 20 25 static inline int proto_ports_offset(int proto 21 static inline int proto_ports_offset(int proto) 26 { 22 { 27 switch (proto) { 23 switch (proto) { 28 case IPPROTO_TCP: 24 case IPPROTO_TCP: 29 case IPPROTO_UDP: 25 case IPPROTO_UDP: 30 case IPPROTO_DCCP: 26 case IPPROTO_DCCP: 31 case IPPROTO_ESP: /* SPI */ 27 case IPPROTO_ESP: /* SPI */ 32 case IPPROTO_SCTP: 28 case IPPROTO_SCTP: 33 case IPPROTO_UDPLITE: 29 case IPPROTO_UDPLITE: 34 return 0; 30 return 0; 35 case IPPROTO_AH: /* SPI */ 31 case IPPROTO_AH: /* SPI */ 36 return 4; 32 return 4; 37 default: 33 default: 38 return -EINVAL; 34 return -EINVAL; 39 } 35 } 40 } 36 } 41 37 42 static inline bool ipv4_is_loopback(__be32 add 38 static inline bool ipv4_is_loopback(__be32 addr) 43 { 39 { 44 return (addr & htonl(0xff000000)) == h 40 return (addr & htonl(0xff000000)) == htonl(0x7f000000); 45 } 41 } 46 42 47 static inline bool ipv4_is_multicast(__be32 ad 43 static inline bool ipv4_is_multicast(__be32 addr) 48 { 44 { 49 return (addr & htonl(0xf0000000)) == h 45 return (addr & htonl(0xf0000000)) == htonl(0xe0000000); 50 } 46 } 51 47 52 static inline bool ipv4_is_local_multicast(__b 48 static inline bool ipv4_is_local_multicast(__be32 addr) 53 { 49 { 54 return (addr & htonl(0xffffff00)) == h 50 return (addr & htonl(0xffffff00)) == htonl(0xe0000000); 55 } 51 } 56 52 57 static inline bool ipv4_is_lbcast(__be32 addr) 53 static inline bool ipv4_is_lbcast(__be32 addr) 58 { 54 { 59 /* limited broadcast */ 55 /* limited broadcast */ 60 return addr == htonl(INADDR_BROADCAST) 56 return addr == htonl(INADDR_BROADCAST); 61 } 57 } 62 58 >> 59 static inline bool ipv4_is_all_snoopers(__be32 addr) >> 60 { >> 61 return addr == htonl(INADDR_ALLSNOOPERS_GROUP); >> 62 } >> 63 63 static inline bool ipv4_is_zeronet(__be32 addr 64 static inline bool ipv4_is_zeronet(__be32 addr) 64 { 65 { 65 return (addr & htonl(0xff000000)) == h !! 66 return (addr == 0); 66 } 67 } 67 68 68 /* Special-Use IPv4 Addresses (RFC3330) */ 69 /* Special-Use IPv4 Addresses (RFC3330) */ 69 70 70 static inline bool ipv4_is_private_10(__be32 a 71 static inline bool ipv4_is_private_10(__be32 addr) 71 { 72 { 72 return (addr & htonl(0xff000000)) == h 73 return (addr & htonl(0xff000000)) == htonl(0x0a000000); 73 } 74 } 74 75 75 static inline bool ipv4_is_private_172(__be32 76 static inline bool ipv4_is_private_172(__be32 addr) 76 { 77 { 77 return (addr & htonl(0xfff00000)) == h 78 return (addr & htonl(0xfff00000)) == htonl(0xac100000); 78 } 79 } 79 80 80 static inline bool ipv4_is_private_192(__be32 81 static inline bool ipv4_is_private_192(__be32 addr) 81 { 82 { 82 return (addr & htonl(0xffff0000)) == h 83 return (addr & htonl(0xffff0000)) == htonl(0xc0a80000); 83 } 84 } 84 85 85 static inline bool ipv4_is_linklocal_169(__be3 86 static inline bool ipv4_is_linklocal_169(__be32 addr) 86 { 87 { 87 return (addr & htonl(0xffff0000)) == h 88 return (addr & htonl(0xffff0000)) == htonl(0xa9fe0000); 88 } 89 } 89 90 90 static inline bool ipv4_is_anycast_6to4(__be32 91 static inline bool ipv4_is_anycast_6to4(__be32 addr) 91 { 92 { 92 return (addr & htonl(0xffffff00)) == h 93 return (addr & htonl(0xffffff00)) == htonl(0xc0586300); 93 } 94 } 94 95 95 static inline bool ipv4_is_test_192(__be32 add 96 static inline bool ipv4_is_test_192(__be32 addr) 96 { 97 { 97 return (addr & htonl(0xffffff00)) == h 98 return (addr & htonl(0xffffff00)) == htonl(0xc0000200); 98 } 99 } 99 100 100 static inline bool ipv4_is_test_198(__be32 add 101 static inline bool ipv4_is_test_198(__be32 addr) 101 { 102 { 102 return (addr & htonl(0xfffe0000)) == h 103 return (addr & htonl(0xfffe0000)) == htonl(0xc6120000); 103 } 104 } 104 #endif /* _LINUX_IN_H */ 105 #endif /* _LINUX_IN_H */ 105 106
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.