xref: /linux-6.15/include/linux/in.h (revision 96125bf9)
12874c5fdSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */
21da177e4SLinus Torvalds /*
31da177e4SLinus Torvalds  * INET		An implementation of the TCP/IP protocol suite for the LINUX
41da177e4SLinus Torvalds  *		operating system.  INET is implemented using the  BSD Socket
51da177e4SLinus Torvalds  *		interface as the means of communication with the user level.
61da177e4SLinus Torvalds  *
71da177e4SLinus Torvalds  *		Definitions of the Internet Protocol.
81da177e4SLinus Torvalds  *
91da177e4SLinus Torvalds  * Version:	@(#)in.h	1.0.1	04/21/93
101da177e4SLinus Torvalds  *
111da177e4SLinus Torvalds  * Authors:	Original taken from the GNU Project <netinet/in.h> file.
121da177e4SLinus Torvalds  *		Fred N. van Kempen, <[email protected]>
131da177e4SLinus Torvalds  */
141da177e4SLinus Torvalds #ifndef _LINUX_IN_H
151da177e4SLinus Torvalds #define _LINUX_IN_H
161da177e4SLinus Torvalds 
172658fa80SJoe Perches 
18e760702eSChangli Gao #include <linux/errno.h>
19607ca46eSDavid Howells #include <uapi/linux/in.h>
20e760702eSChangli Gao 
proto_ports_offset(int proto)21e760702eSChangli Gao static inline int proto_ports_offset(int proto)
22e760702eSChangli Gao {
23e760702eSChangli Gao 	switch (proto) {
24e760702eSChangli Gao 	case IPPROTO_TCP:
25e760702eSChangli Gao 	case IPPROTO_UDP:
26e760702eSChangli Gao 	case IPPROTO_DCCP:
27e760702eSChangli Gao 	case IPPROTO_ESP:	/* SPI */
28e760702eSChangli Gao 	case IPPROTO_SCTP:
29e760702eSChangli Gao 	case IPPROTO_UDPLITE:
30e760702eSChangli Gao 		return 0;
31e760702eSChangli Gao 	case IPPROTO_AH:	/* SPI */
32e760702eSChangli Gao 		return 4;
33e760702eSChangli Gao 	default:
34e760702eSChangli Gao 		return -EINVAL;
35e760702eSChangli Gao 	}
36e760702eSChangli Gao }
37e760702eSChangli Gao 
ipv4_is_loopback(__be32 addr)382658fa80SJoe Perches static inline bool ipv4_is_loopback(__be32 addr)
392658fa80SJoe Perches {
402658fa80SJoe Perches 	return (addr & htonl(0xff000000)) == htonl(0x7f000000);
412658fa80SJoe Perches }
422658fa80SJoe Perches 
ipv4_is_multicast(__be32 addr)432658fa80SJoe Perches static inline bool ipv4_is_multicast(__be32 addr)
442658fa80SJoe Perches {
452658fa80SJoe Perches 	return (addr & htonl(0xf0000000)) == htonl(0xe0000000);
462658fa80SJoe Perches }
472658fa80SJoe Perches 
ipv4_is_local_multicast(__be32 addr)482658fa80SJoe Perches static inline bool ipv4_is_local_multicast(__be32 addr)
492658fa80SJoe Perches {
502658fa80SJoe Perches 	return (addr & htonl(0xffffff00)) == htonl(0xe0000000);
512658fa80SJoe Perches }
522658fa80SJoe Perches 
ipv4_is_lbcast(__be32 addr)531e637c74SJan Engelhardt static inline bool ipv4_is_lbcast(__be32 addr)
542658fa80SJoe Perches {
551e637c74SJan Engelhardt 	/* limited broadcast */
560ff9663cSAl Viro 	return addr == htonl(INADDR_BROADCAST);
572658fa80SJoe Perches }
582658fa80SJoe Perches 
ipv4_is_all_snoopers(__be32 addr)594b3087c7SLinus Lüssing static inline bool ipv4_is_all_snoopers(__be32 addr)
604b3087c7SLinus Lüssing {
614b3087c7SLinus Lüssing 	return addr == htonl(INADDR_ALLSNOOPERS_GROUP);
624b3087c7SLinus Lüssing }
634b3087c7SLinus Lüssing 
ipv4_is_zeronet(__be32 addr)642658fa80SJoe Perches static inline bool ipv4_is_zeronet(__be32 addr)
652658fa80SJoe Perches {
66*96125bf9SDave Taht 	return (addr == 0);
672658fa80SJoe Perches }
682658fa80SJoe Perches 
69c7dc89c0SFred L. Templin /* Special-Use IPv4 Addresses (RFC3330) */
702658fa80SJoe Perches 
ipv4_is_private_10(__be32 addr)712658fa80SJoe Perches static inline bool ipv4_is_private_10(__be32 addr)
722658fa80SJoe Perches {
732658fa80SJoe Perches 	return (addr & htonl(0xff000000)) == htonl(0x0a000000);
742658fa80SJoe Perches }
752658fa80SJoe Perches 
ipv4_is_private_172(__be32 addr)762658fa80SJoe Perches static inline bool ipv4_is_private_172(__be32 addr)
772658fa80SJoe Perches {
782658fa80SJoe Perches 	return (addr & htonl(0xfff00000)) == htonl(0xac100000);
792658fa80SJoe Perches }
802658fa80SJoe Perches 
ipv4_is_private_192(__be32 addr)812658fa80SJoe Perches static inline bool ipv4_is_private_192(__be32 addr)
822658fa80SJoe Perches {
832658fa80SJoe Perches 	return (addr & htonl(0xffff0000)) == htonl(0xc0a80000);
842658fa80SJoe Perches }
852658fa80SJoe Perches 
ipv4_is_linklocal_169(__be32 addr)862658fa80SJoe Perches static inline bool ipv4_is_linklocal_169(__be32 addr)
872658fa80SJoe Perches {
882658fa80SJoe Perches 	return (addr & htonl(0xffff0000)) == htonl(0xa9fe0000);
892658fa80SJoe Perches }
902658fa80SJoe Perches 
ipv4_is_anycast_6to4(__be32 addr)912658fa80SJoe Perches static inline bool ipv4_is_anycast_6to4(__be32 addr)
922658fa80SJoe Perches {
932658fa80SJoe Perches 	return (addr & htonl(0xffffff00)) == htonl(0xc0586300);
942658fa80SJoe Perches }
952658fa80SJoe Perches 
ipv4_is_test_192(__be32 addr)962658fa80SJoe Perches static inline bool ipv4_is_test_192(__be32 addr)
972658fa80SJoe Perches {
982658fa80SJoe Perches 	return (addr & htonl(0xffffff00)) == htonl(0xc0000200);
992658fa80SJoe Perches }
1002658fa80SJoe Perches 
ipv4_is_test_198(__be32 addr)1012658fa80SJoe Perches static inline bool ipv4_is_test_198(__be32 addr)
1022658fa80SJoe Perches {
1032658fa80SJoe Perches 	return (addr & htonl(0xfffe0000)) == htonl(0xc6120000);
1042658fa80SJoe Perches }
1051da177e4SLinus Torvalds #endif	/* _LINUX_IN_H */
106