1a50ffc2imp/*-
24736ccfpfg * SPDX-License-Identifier: BSD-3-Clause
34736ccfpfg *
48fb65cergrimes * Copyright (c) 1982, 1986, 1990, 1993
58fb65cergrimes *	The Regents of the University of California.  All rights reserved.
68fb65cergrimes *
78fb65cergrimes * Redistribution and use in source and binary forms, with or without
88fb65cergrimes * modification, are permitted provided that the following conditions
98fb65cergrimes * are met:
108fb65cergrimes * 1. Redistributions of source code must retain the above copyright
118fb65cergrimes *    notice, this list of conditions and the following disclaimer.
128fb65cergrimes * 2. Redistributions in binary form must reproduce the above copyright
138fb65cergrimes *    notice, this list of conditions and the following disclaimer in the
148fb65cergrimes *    documentation and/or other materials provided with the distribution.
157e6cabdimp * 3. Neither the name of the University nor the names of its contributors
168fb65cergrimes *    may be used to endorse or promote products derived from this software
178fb65cergrimes *    without specific prior written permission.
188fb65cergrimes *
198fb65cergrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
208fb65cergrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
218fb65cergrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
228fb65cergrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
238fb65cergrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
248fb65cergrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
258fb65cergrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
268fb65cergrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
278fb65cergrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
288fb65cergrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
298fb65cergrimes * SUCH DAMAGE.
308fb65cergrimes *
318fb65cergrimes *	@(#)in.h	8.3 (Berkeley) 1/3/94
323b842d3peter * $FreeBSD$
338fb65cergrimes */
348fb65cergrimes
358197ce5paul#ifndef _NETINET_IN_H_
36b3c1e80ume#define	_NETINET_IN_H_
378197ce5paul
38491520amike#include <sys/cdefs.h>
39beecc37mike#include <sys/_types.h>
40491520amike#include <machine/endian.h>
41beecc37mike
42491520amike/* Protocols common to RFC 1700, POSIX, and X/Open. */
43491520amike#define	IPPROTO_IP		0		/* dummy for IP */
44491520amike#define	IPPROTO_ICMP		1		/* control message protocol */
45491520amike#define	IPPROTO_TCP		6		/* tcp */
46491520amike#define	IPPROTO_UDP		17		/* user datagram protocol */
47491520amike
481a884d5kevlo#define	INADDR_ANY		((in_addr_t)0x00000000)
491a884d5kevlo#define	INADDR_BROADCAST	((in_addr_t)0xffffffff)	/* must be masked */
50491520amike
51491520amike#ifndef _UINT8_T_DECLARED
52491520amiketypedef	__uint8_t		uint8_t;
53491520amike#define	_UINT8_T_DECLARED
54491520amike#endif
55491520amike
56491520amike#ifndef _UINT16_T_DECLARED
57491520amiketypedef	__uint16_t		uint16_t;
58491520amike#define	_UINT16_T_DECLARED
59491520amike#endif
60491520amike
61491520amike#ifndef _UINT32_T_DECLARED
62491520amiketypedef	__uint32_t		uint32_t;
63491520amike#define	_UINT32_T_DECLARED
64491520amike#endif
65491520amike
66491520amike#ifndef _IN_ADDR_T_DECLARED
67491520amiketypedef	uint32_t		in_addr_t;
68491520amike#define	_IN_ADDR_T_DECLARED
69491520amike#endif
70491520amike
71491520amike#ifndef _IN_PORT_T_DECLARED
72491520amiketypedef	uint16_t		in_port_t;
73491520amike#define	_IN_PORT_T_DECLARED
74491520amike#endif
75491520amike
769e6f796mike#ifndef _SA_FAMILY_T_DECLARED
779e6f796miketypedef	__sa_family_t		sa_family_t;
789e6f796mike#define	_SA_FAMILY_T_DECLARED
79491520amike#endif
80491520amike
81491520amike/* Internet address (a structure for historical reasons). */
82491520amike#ifndef	_STRUCT_IN_ADDR_DECLARED
83491520amikestruct in_addr {
84491520amike	in_addr_t s_addr;
85491520amike};
86491520amike#define	_STRUCT_IN_ADDR_DECLARED
87491520amike#endif
88491520amike
89ffd77d9bms#ifndef	_SOCKLEN_T_DECLARED
90ffd77d9bmstypedef	__socklen_t	socklen_t;
91ffd77d9bms#define	_SOCKLEN_T_DECLARED
92ffd77d9bms#endif
93ffd77d9bms
94c8ab4abphk#include <sys/_sockaddr_storage.h>
95ffd77d9bms
96491520amike/* Socket address, internet style. */
97491520amikestruct sockaddr_in {
98491520amike	uint8_t	sin_len;
99491520amike	sa_family_t	sin_family;
100491520amike	in_port_t	sin_port;
101491520amike	struct	in_addr sin_addr;
102491520amike	char	sin_zero[8];
103491520amike};
104491520amike
1051effdc7jilles#if !defined(_KERNEL) && __POSIX_VISIBLE >= 200112
106491520amike
107491520amike#ifndef _BYTEORDER_PROTOTYPED
108491520amike#define	_BYTEORDER_PROTOTYPED
109491520amike__BEGIN_DECLS
110491520amikeuint32_t	htonl(uint32_t);
111491520amikeuint16_t	htons(uint16_t);
112491520amikeuint32_t	ntohl(uint32_t);
113491520amikeuint16_t	ntohs(uint16_t);
114491520amike__END_DECLS
115491520amike#endif
116491520amike
117491520amike#ifndef _BYTEORDER_FUNC_DEFINED
118491520amike#define	_BYTEORDER_FUNC_DEFINED
119491520amike#define	htonl(x)	__htonl(x)
120491520amike#define	htons(x)	__htons(x)
121491520amike#define	ntohl(x)	__ntohl(x)
122491520amike#define	ntohs(x)	__ntohs(x)
123491520amike#endif
124491520amike
1251effdc7jilles#endif /* !_KERNEL && __POSIX_VISIBLE >= 200112 */
126491520amike
127491520amike#if __POSIX_VISIBLE >= 200112
128fcb6743cperciva#define	IPPROTO_IPV6		41		/* IP6 header */
129491520amike#define	IPPROTO_RAW		255		/* raw IP packet */
130491520amike#define	INET_ADDRSTRLEN		16
131491520amike#endif
132491520amike
133491520amike#if __BSD_VISIBLE
1348fb65cergrimes/*
1358fb65cergrimes * Constants and structures defined by the internet system,
1368fb65cergrimes * Per RFC 790, September 1981, and numerous additions.
1378fb65cergrimes */
1388fb65cergrimes
1398fb65cergrimes/*
1409f72afejulian * Protocols (RFC 1700)
1418fb65cergrimes */
1427efc91cshin#define	IPPROTO_HOPOPTS		0		/* IP6 hop-by-hop options */
1438fb65cergrimes#define	IPPROTO_IGMP		2		/* group mgmt protocol */
1448fb65cergrimes#define	IPPROTO_GGP		3		/* gateway^2 (deprecated) */
14587aa99brwatson#define	IPPROTO_IPV4		4		/* IPv4 encapsulation */
14687aa99brwatson#define	IPPROTO_IPIP		IPPROTO_IPV4	/* for compatibility */
1479f72afejulian#define	IPPROTO_ST		7		/* Stream protocol II */
1488fb65cergrimes#define	IPPROTO_EGP		8		/* exterior gateway protocol */
1499f72afejulian#define	IPPROTO_PIGP		9		/* private interior gateway */
1509f72afejulian#define	IPPROTO_RCCMON		10		/* BBN RCC Monitoring */
1519f72afejulian#define	IPPROTO_NVPII		11		/* network voice protocol*/
1528fb65cergrimes#define	IPPROTO_PUP		12		/* pup */
1539f72afejulian#define	IPPROTO_ARGUS		13		/* Argus */
1549f72afejulian#define	IPPROTO_EMCON		14		/* EMCON */
1559f72afejulian#define	IPPROTO_XNET		15		/* Cross Net Debugger */
1569f72afejulian#define	IPPROTO_CHAOS		16		/* Chaos*/
1579f72afejulian#define	IPPROTO_MUX		18		/* Multiplexing */
1589f72afejulian#define	IPPROTO_MEAS		19		/* DCN Measurement Subsystems */
1599f72afejulian#define	IPPROTO_HMP		20		/* Host Monitoring */
1609f72afejulian#define	IPPROTO_PRM		21		/* Packet Radio Measurement */
1618fb65cergrimes#define	IPPROTO_IDP		22		/* xns idp */
1629f72afejulian#define	IPPROTO_TRUNK1		23		/* Trunk-1 */
1639f72afejulian#define	IPPROTO_TRUNK2		24		/* Trunk-2 */
1649f72afejulian#define	IPPROTO_LEAF1		25		/* Leaf-1 */
1659f72afejulian#define	IPPROTO_LEAF2		26		/* Leaf-2 */
1669f72afejulian#define	IPPROTO_RDP		27		/* Reliable Data */
1679f72afejulian#define	IPPROTO_IRTP		28		/* Reliable Transaction */
16887aa99brwatson#define	IPPROTO_TP		29		/* tp-4 w/ class negotiation */
1699f72afejulian#define	IPPROTO_BLT		30		/* Bulk Data Transfer */
1709f72afejulian#define	IPPROTO_NSP		31		/* Network Services */
1719f72afejulian#define	IPPROTO_INP		32		/* Merit Internodal */
172e262ca6thj#define	IPPROTO_DCCP		33		/* Datagram Congestion Control Protocol */
1739f72afejulian#define	IPPROTO_3PC		34		/* Third Party Connect */
1749f72afejulian#define	IPPROTO_IDPR		35		/* InterDomain Policy Routing */
1759f72afejulian#define	IPPROTO_XTP		36		/* XTP */
1769f72afejulian#define	IPPROTO_DDP		37		/* Datagram Delivery */
1779f72afejulian#define	IPPROTO_CMTP		38		/* Control Message Transport */
1789f72afejulian#define	IPPROTO_TPXX		39		/* TP++ Transport */
1799f72afejulian#define	IPPROTO_IL		40		/* IL transport protocol */
1809f72afejulian#define	IPPROTO_SDRP		42		/* Source Demand Routing */
1817efc91cshin#define	IPPROTO_ROUTING		43		/* IP6 routing header */
1827efc91cshin#define	IPPROTO_FRAGMENT	44		/* IP6 fragmentation header */
1839f72afejulian#define	IPPROTO_IDRP		45		/* InterDomain Routing*/
18487aa99brwatson#define	IPPROTO_RSVP		46		/* resource reservation */
1859f72afejulian#define	IPPROTO_GRE		47		/* General Routing Encap. */
1869f72afejulian#define	IPPROTO_MHRP		48		/* Mobile Host Routing */
1879f72afejulian#define	IPPROTO_BHA		49		/* BHA */
1887efc91cshin#define	IPPROTO_ESP		50		/* IP6 Encap Sec. Payload */
1897efc91cshin#define	IPPROTO_AH		51		/* IP6 Auth Header */
1909f72afejulian#define	IPPROTO_INLSP		52		/* Integ. Net Layer Security */
1919f72afejulian#define	IPPROTO_SWIPE		53		/* IP with encryption */
1929f72afejulian#define	IPPROTO_NHRP		54		/* Next Hop Resolution */
19387aa99brwatson#define	IPPROTO_MOBILE		55		/* IP Mobility */
19487aa99brwatson#define	IPPROTO_TLSP		56		/* Transport Layer Security */
19587aa99brwatson#define	IPPROTO_SKIP		57		/* SKIP */
1967efc91cshin#define	IPPROTO_ICMPV6		58		/* ICMP6 */
1977efc91cshin#define	IPPROTO_NONE		59		/* IP6 no next header */
1987efc91cshin#define	IPPROTO_DSTOPTS		60		/* IP6 destination option */
1999f72afejulian#define	IPPROTO_AHIP		61		/* any host internal protocol */
2009f72afejulian#define	IPPROTO_CFTP		62		/* CFTP */
2019f72afejulian#define	IPPROTO_HELLO		63		/* "hello" routing protocol */
2029f72afejulian#define	IPPROTO_SATEXPAK	64		/* SATNET/Backroom EXPAK */
2039f72afejulian#define	IPPROTO_KRYPTOLAN	65		/* Kryptolan */
2049f72afejulian#define	IPPROTO_RVD		66		/* Remote Virtual Disk */
2059f72afejulian#define	IPPROTO_IPPC		67		/* Pluribus Packet Core */
2069f72afejulian#define	IPPROTO_ADFS		68		/* Any distributed FS */
2079f72afejulian#define	IPPROTO_SATMON		69		/* Satnet Monitoring */
2089f72afejulian#define	IPPROTO_VISA		70		/* VISA Protocol */
2099f72afejulian#define	IPPROTO_IPCV		71		/* Packet Core Utility */
2109f72afejulian#define	IPPROTO_CPNX		72		/* Comp. Prot. Net. Executive */
2119f72afejulian#define	IPPROTO_CPHB		73		/* Comp. Prot. HeartBeat */
2129f72afejulian#define	IPPROTO_WSN		74		/* Wang Span Network */
2139f72afejulian#define	IPPROTO_PVP		75		/* Packet Video Protocol */
2149f72afejulian#define	IPPROTO_BRSATMON	76		/* BackRoom SATNET Monitoring */
2159f72afejulian#define	IPPROTO_ND		77		/* Sun net disk proto (temp.) */
2169f72afejulian#define	IPPROTO_WBMON		78		/* WIDEBAND Monitoring */
2179f72afejulian#define	IPPROTO_WBEXPAK		79		/* WIDEBAND EXPAK */
2188fb65cergrimes#define	IPPROTO_EON		80		/* ISO cnlp */
2199f72afejulian#define	IPPROTO_VMTP		81		/* VMTP */
2209f72afejulian#define	IPPROTO_SVMTP		82		/* Secure VMTP */
2219f72afejulian#define	IPPROTO_VINES		83		/* Banyon VINES */
2229f72afejulian#define	IPPROTO_TTP		84		/* TTP */
2239f72afejulian#define	IPPROTO_IGP		85		/* NSFNET-IGP */
2249f72afejulian#define	IPPROTO_DGP		86		/* dissimilar gateway prot. */
225586efafjulian#define	IPPROTO_TCF		87		/* TCF */
2269f72afejulian#define	IPPROTO_IGRP		88		/* Cisco/GXS IGRP */
2279f72afejulian#define	IPPROTO_OSPFIGP		89		/* OSPFIGP */
2289f72afejulian#define	IPPROTO_SRPC		90		/* Strite RPC protocol */
2299f72afejulian#define	IPPROTO_LARP		91		/* Locus Address Resoloution */
2309f72afejulian#define	IPPROTO_MTP		92		/* Multicast Transport */
2319f72afejulian#define	IPPROTO_AX25		93		/* AX.25 Frames */
2329f72afejulian#define	IPPROTO_IPEIP		94		/* IP encapsulated in IP */
2339f72afejulian#define	IPPROTO_MICP		95		/* Mobile Int.ing control */
2349f72afejulian#define	IPPROTO_SCCSP		96		/* Semaphore Comm. security */
2359f72afejulian#define	IPPROTO_ETHERIP		97		/* Ethernet IP encapsulation */
2368fb65cergrimes#define	IPPROTO_ENCAP		98		/* encapsulation header */
2379f72afejulian#define	IPPROTO_APES		99		/* any private encr. scheme */
2389f72afejulian#define	IPPROTO_GMTP		100		/* GMTP*/
2397efc91cshin#define	IPPROTO_IPCOMP		108		/* payload compression (IPComp) */
2401e54d54delphij#define	IPPROTO_SCTP		132		/* SCTP */
24169ea0c9delphij#define	IPPROTO_MH		135		/* IPv6 Mobility Header */
24245fcb79kevlo#define	IPPROTO_UDPLITE		136		/* UDP-Lite */
24366725babz#define	IPPROTO_HIP		139		/* IP6 Host Identity Protocol */
24466725babz#define	IPPROTO_SHIM6		140		/* IP6 Shim6 Protocol */
2452085d1aluigi/* 101-254: Partly Unassigned */
2467efc91cshin#define	IPPROTO_PIM		103		/* Protocol Independent Mcast */
247e1d2263glebius#define	IPPROTO_CARP		112		/* CARP */
2482085d1aluigi#define	IPPROTO_PGM		113		/* PGM */
2491690c6bemaste#define	IPPROTO_MPLS		137		/* MPLS-in-IP */
25018ff360mlaier#define	IPPROTO_PFSYNC		240		/* PFSYNC */
25166725babz#define	IPPROTO_RESERVED_253	253		/* Reserved */
25266725babz#define	IPPROTO_RESERVED_254	254		/* Reserved */
2539f72afejulian/* 255: Reserved */
25468784e2fenner/* BSD Private, local use, namespace incursion, no longer used */
25568784e2fenner#define	IPPROTO_OLD_DIVERT	254		/* OLD divert pseudo-proto */
2568fb65cergrimes#define	IPPROTO_MAX		256
2578fb65cergrimes
2587efc91cshin/* last return value of *_input(), meaning "all job for this pkt is done".  */
2597efc91cshin#define	IPPROTO_DONE		257
2608fb65cergrimes
26168784e2fenner/* Only used internally, so can be outside the range of valid IP protocols. */
26268784e2fenner#define	IPPROTO_DIVERT		258		/* divert pseudo-protocol */
263c6c2febanchie#define	IPPROTO_SEND		259		/* SeND pseudo-protocol */
26468784e2fenner
2658fb65cergrimes/*
26611ab41aandre * Defined to avoid confusion.  The master value is defined by
26711ab41aandre * PROTO_SPACER in sys/protosw.h.
26811ab41aandre */
26911ab41aandre#define	IPPROTO_SPACER		32767		/* spacer for loadable protos */
27011ab41aandre
27111ab41aandre/*
2728fb65cergrimes * Local port number conventions:
273fe35eacpeter *
274fe35eacpeter * When a user does a bind(2) or connect(2) with a port number of zero,
275fe35eacpeter * a non-conflicting local port address is chosen.
2765339bdcsilby * The default range is IPPORT_HIFIRSTAUTO through
2775339bdcsilby * IPPORT_HILASTAUTO, although that is settable by sysctl.
278fe35eacpeter *
279fe35eacpeter * A user may set the IPPROTO_IP option IP_PORTRANGE to change this
280fe35eacpeter * default assignment range.
281fe35eacpeter *
282fe35eacpeter * The value IP_PORTRANGE_DEFAULT causes the default behavior.
283fe35eacpeter *
284fe35eacpeter * The value IP_PORTRANGE_HIGH changes the range of candidate port numbers
285fe35eacpeter * into the "high" range.  These are reserved for client outbound connections
28674f471arpaulo * which do not want to be filtered by any firewalls.
287fe35eacpeter *
288fe35eacpeter * The value IP_PORTRANGE_LOW changes the range to the "low" are
289fe35eacpeter * that is (by convention) restricted to privileged processes.  This
290fe35eacpeter * convention is based on "vouchsafe" principles only.  It is only secure
291fe35eacpeter * if you trust the remote host to restrict these ports.
292fe35eacpeter *
293fe35eacpeter * The default range of ports and the high range can be changed by
2948930206des * sysctl(3).  (net.inet.ip.portrange.{hi,low,}{first,last})
295fe35eacpeter *
296fe35eacpeter * Changing those values has bad security implications if you are
297d3367c5schweikh * using a stateless firewall that is allowing packets outside of that
298fe35eacpeter * range in order to allow transparent outgoing connections.
299fe35eacpeter *
300fe35eacpeter * Such a firewall configuration will generally depend on the use of these
301fe35eacpeter * default values.  If you change them, you may find your Security
302fe35eacpeter * Administrator looking for you with a heavy object.
3030f961b2phk *
3040f961b2phk * For a slightly more orthodox text view on this:
3050f961b2phk *
3060f961b2phk *            ftp://ftp.isi.edu/in-notes/iana/assignments/port-numbers
3070f961b2phk *
3080f961b2phk *    port numbers are divided into three ranges:
3090f961b2phk *
3100f961b2phk *                0 -  1023 Well Known Ports
3110f961b2phk *             1024 - 49151 Registered Ports
3120f961b2phk *            49152 - 65535 Dynamic and/or Private Ports
3130f961b2phk *
314fe35eacpeter */
315fe35eacpeter
316fe35eacpeter/*
3178fb65cergrimes * Ports < IPPORT_RESERVED are reserved for
318fe35eacpeter * privileged processes (e.g. root).         (IP_PORTRANGE_LOW)
3198fb65cergrimes */
3208fb65cergrimes#define	IPPORT_RESERVED		1024
3218fb65cergrimes
3228fb65cergrimes/*
32374f471arpaulo * Default local port range, used by IP_PORTRANGE_DEFAULT
32474f471arpaulo */
32574f471arpaulo#define IPPORT_EPHEMERALFIRST	10000
3269dd4070rrs#define IPPORT_EPHEMERALLAST	65535
3279dd4070rrs
32874f471arpaulo/*
32974f471arpaulo * Dynamic port range, used by IP_PORTRANGE_HIGH.
3302f93f3dpeter */
3310f961b2phk#define	IPPORT_HIFIRSTAUTO	49152
3320f961b2phk#define	IPPORT_HILASTAUTO	65535
3332f93f3dpeter
3342f93f3dpeter/*
335cff0ceepeter * Scanning for a free reserved port return a value below IPPORT_RESERVED,
336cff0ceepeter * but higher than IPPORT_RESERVEDSTART.  Traditionally the start value was
337cff0ceepeter * 512, but that conflicts with some well-known-services that firewalls may
338cff0ceepeter * have a fit if we use.
339cff0ceepeter */
34087aa99brwatson#define	IPPORT_RESERVEDSTART	600
341cff0ceepeter
34220caccemike#define	IPPORT_MAX		65535
34320caccemike
3448fb65cergrimes/*
3458fb65cergrimes * Definitions of bits in internet address integers.
3468fb65cergrimes * On subnets, the decomposition of addresses to host and net parts
3478fb65cergrimes * is done according to subnet mask, not the masks here.
3488fb65cergrimes */
3491a884d5kevlo#define	IN_CLASSA(i)		(((in_addr_t)(i) & 0x80000000) == 0)
3508fb65cergrimes#define	IN_CLASSA_NET		0xff000000
3518fb65cergrimes#define	IN_CLASSA_NSHIFT	24
3528fb65cergrimes#define	IN_CLASSA_HOST		0x00ffffff
3538fb65cergrimes#define	IN_CLASSA_MAX		128
3548fb65cergrimes
3551a884d5kevlo#define	IN_CLASSB(i)		(((in_addr_t)(i) & 0xc0000000) == 0x80000000)
3568fb65cergrimes#define	IN_CLASSB_NET		0xffff0000
3578fb65cergrimes#define	IN_CLASSB_NSHIFT	16
3588fb65cergrimes#define	IN_CLASSB_HOST		0x0000ffff
3598fb65cergrimes#define	IN_CLASSB_MAX		65536
3608fb65cergrimes
3611a884d5kevlo#define	IN_CLASSC(i)		(((in_addr_t)(i) & 0xe0000000) == 0xc0000000)
3628fb65cergrimes#define	IN_CLASSC_NET		0xffffff00
3638fb65cergrimes#define	IN_CLASSC_NSHIFT	8
3648fb65cergrimes#define	IN_CLASSC_HOST		0x000000ff
3658fb65cergrimes
3661a884d5kevlo#define	IN_CLASSD(i)		(((in_addr_t)(i) & 0xf0000000) == 0xe0000000)
3678fb65cergrimes#define	IN_CLASSD_NET		0xf0000000	/* These ones aren't really */
3688fb65cergrimes#define	IN_CLASSD_NSHIFT	28		/* net and host fields, but */
3698fb65cergrimes#define	IN_CLASSD_HOST		0x0fffffff	/* routing needn't know.    */
3708fb65cergrimes#define	IN_MULTICAST(i)		IN_CLASSD(i)
3718fb65cergrimes
3721a884d5kevlo#define	IN_EXPERIMENTAL(i)	(((in_addr_t)(i) & 0xf0000000) == 0xf0000000)
3731a884d5kevlo#define	IN_BADCLASS(i)		(((in_addr_t)(i) & 0xf0000000) == 0xf0000000)
3748fb65cergrimes
3751a884d5kevlo#define IN_LINKLOCAL(i)		(((in_addr_t)(i) & 0xffff0000) == 0xa9fe0000)
3761a884d5kevlo#define IN_LOOPBACK(i)		(((in_addr_t)(i) & 0xff000000) == 0x7f000000)
3771a884d5kevlo#define IN_ZERONET(i)		(((in_addr_t)(i) & 0xff000000) == 0)
378cad0bb8bms
3791a884d5kevlo#define	IN_PRIVATE(i)	((((in_addr_t)(i) & 0xff000000) == 0x0a000000) || \
3801a884d5kevlo			 (((in_addr_t)(i) & 0xfff00000) == 0xac100000) || \
3811a884d5kevlo			 (((in_addr_t)(i) & 0xffff0000) == 0xc0a80000))
382cad0bb8bms
3831a884d5kevlo#define	IN_LOCAL_GROUP(i)	(((in_addr_t)(i) & 0xffffff00) == 0xe0000000)
3849dd4070rrs
385cad0bb8bms#define	IN_ANY_LOCAL(i)		(IN_LINKLOCAL(i) || IN_LOCAL_GROUP(i))
386cad0bb8bms
3871a884d5kevlo#define	INADDR_LOOPBACK		((in_addr_t)0x7f000001)
38815b9bcbpeter#ifndef _KERNEL
3891a884d5kevlo#define	INADDR_NONE		((in_addr_t)0xffffffff)	/* -1 return */
3908fb65cergrimes#endif
3918fb65cergrimes
3921a884d5kevlo#define	INADDR_UNSPEC_GROUP	((in_addr_t)0xe0000000)	/* 224.0.0.0 */
3931a884d5kevlo#define	INADDR_ALLHOSTS_GROUP	((in_addr_t)0xe0000001)	/* 224.0.0.1 */
3941a884d5kevlo#define	INADDR_ALLRTRS_GROUP	((in_addr_t)0xe0000002)	/* 224.0.0.2 */
3951a884d5kevlo#define	INADDR_ALLRPTS_GROUP	((in_addr_t)0xe0000016)	/* 224.0.0.22, IGMPv3 */
3961a884d5kevlo#define	INADDR_CARP_GROUP	((in_addr_t)0xe0000012)	/* 224.0.0.18 */
3971a884d5kevlo#define	INADDR_PFSYNC_GROUP	((in_addr_t)0xe00000f0)	/* 224.0.0.240 */
3981a884d5kevlo#define	INADDR_ALLMDNS_GROUP	((in_addr_t)0xe00000fb)	/* 224.0.0.251 */
3991a884d5kevlo#define	INADDR_MAX_LOCAL_GROUP	((in_addr_t)0xe00000ff)	/* 224.0.0.255 */
4008fb65cergrimes
4018fb65cergrimes#define	IN_LOOPBACKNET		127			/* official! */
4028fb65cergrimes
4031a884d5kevlo#define	IN_RFC3021_MASK		((in_addr_t)0xfffffffe)
4045bfe254glebius
4058fb65cergrimes/*
4068fb65cergrimes * Options for use with [gs]etsockopt at the IP level.
4078fb65cergrimes * First word of comment is data type; bool is stored in int.
4088fb65cergrimes */
4098fb65cergrimes#define	IP_OPTIONS		1    /* buf/ip_opts; set/get IP options */
4108fb65cergrimes#define	IP_HDRINCL		2    /* int; header is included with data */
4118fb65cergrimes#define	IP_TOS			3    /* int; IP type of service and preced. */
4128fb65cergrimes#define	IP_TTL			4    /* int; IP time to live */
4138fb65cergrimes#define	IP_RECVOPTS		5    /* bool; receive all IP opts w/dgram */
4148fb65cergrimes#define	IP_RECVRETOPTS		6    /* bool; receive IP opts for response */
4158fb65cergrimes#define	IP_RECVDSTADDR		7    /* bool; receive IP dst addr w/dgram */
4164d33feciedowse#define	IP_SENDSRCADDR		IP_RECVDSTADDR /* cmsg_type to set src addr */
4178fb65cergrimes#define	IP_RETOPTS		8    /* ip_opts; set/get IP options */
418ffd77d9bms#define	IP_MULTICAST_IF		9    /* struct in_addr *or* struct ip_mreqn;
419ffd77d9bms				      * set/get IP multicast i/f  */
4208fb65cergrimes#define	IP_MULTICAST_TTL	10   /* u_char; set/get IP multicast ttl */
4218fb65cergrimes#define	IP_MULTICAST_LOOP	11   /* u_char; set/get IP multicast loopback */
4228fb65cergrimes#define	IP_ADD_MEMBERSHIP	12   /* ip_mreq; add an IP group membership */
4238fb65cergrimes#define	IP_DROP_MEMBERSHIP	13   /* ip_mreq; drop an IP group membership */
42487aa99brwatson#define	IP_MULTICAST_VIF	14   /* set/get IP mcast virt. iface */
42587aa99brwatson#define	IP_RSVP_ON		15   /* enable RSVP in kernel */
42687aa99brwatson#define	IP_RSVP_OFF		16   /* disable RSVP in kernel */
42787aa99brwatson#define	IP_RSVP_VIF_ON		17   /* set RSVP per-vif socket */
42887aa99brwatson#define	IP_RSVP_VIF_OFF		18   /* unset RSVP per-vif socket */
42987aa99brwatson#define	IP_PORTRANGE		19   /* int; range to choose for unspec port */
43051fa6f0fenner#define	IP_RECVIF		20   /* bool; receive reception if w/dgram */
4317efc91cshin/* for IPSEC */
4327efc91cshin#define	IP_IPSEC_POLICY		21   /* int; set/get security policy */
433b5d711dmelifaro				     /* unused; was IP_FAITH */
4343af3c5abms#define	IP_ONESBCAST		23   /* bool: send all-ones broadcast */
4355243d2dpjd#define	IP_BINDANY		24   /* bool: allow bind to any address */
436627c686adrian#define	IP_BINDMULTI		25   /* bool: allow multiple listeners on a tuple */
437627c686adrian#define	IP_RSS_LISTEN_BUCKET	26   /* int; set RSS listen bucket */
438f2a480ceri#define	IP_ORIGDSTADDR		27   /* bool: receive IP dst addr/port w/dgram */
439f2a480ceri#define	IP_RECVORIGDSTADDR      IP_ORIGDSTADDR
4403af3c5abms
4410042b1fluigi/*
4420042b1fluigi * Options for controlling the firewall and dummynet.
4430042b1fluigi * Historical options (from 40 to 64) will eventually be
4440042b1fluigi * replaced by only two options, IP_FW3 and IP_DUMMYNET3.
4450042b1fluigi */
44627bed14ru#define	IP_FW_TABLE_ADD		40   /* add entry */
44727bed14ru#define	IP_FW_TABLE_DEL		41   /* delete entry */
44827bed14ru#define	IP_FW_TABLE_FLUSH	42   /* flush table */
44927bed14ru#define	IP_FW_TABLE_GETSIZE	43   /* get table size */
45027bed14ru#define	IP_FW_TABLE_LIST	44   /* list table contents */
45127bed14ru
4520042b1fluigi#define	IP_FW3			48   /* generic ipfw v.3 sockopts */
4530042b1fluigi#define	IP_DUMMYNET3		49   /* generic dummynet v.3 sockopts */
4540042b1fluigi
45587aa99brwatson#define	IP_FW_ADD		50   /* add a firewall rule to chain */
45687aa99brwatson#define	IP_FW_DEL		51   /* delete a firewall rule from chain */
45787aa99brwatson#define	IP_FW_FLUSH		52   /* flush firewall rule chain */
45887aa99brwatson#define	IP_FW_ZERO		53   /* clear single/all firewall counter(s) */
45987aa99brwatson#define	IP_FW_GET		54   /* get entire firewall rule chain */
4607efc91cshin#define	IP_FW_RESETLOG		55   /* reset logging counters */
4616fc54fesos
4620db606apiso#define IP_FW_NAT_CFG           56   /* add/config a nat rule */
4630db606apiso#define IP_FW_NAT_DEL           57   /* delete a nat rule */
4640db606apiso#define IP_FW_NAT_GET_CONFIG    58   /* get configuration of a nat rule */
4650db606apiso#define IP_FW_NAT_GET_LOG       59   /* get log of a nat rule */
4660db606apiso
4674b628faluigi#define	IP_DUMMYNET_CONFIGURE	60   /* add/configure a dummynet pipe */
4684b628faluigi#define	IP_DUMMYNET_DEL		61   /* delete a dummynet pipe from chain */
4694b628faluigi#define	IP_DUMMYNET_FLUSH	62   /* flush dummynet */
4704b628faluigi#define	IP_DUMMYNET_GET		64   /* get entire dummynet pipes */
4714b628faluigi
4726afaafdmdodd#define	IP_RECVTTL		65   /* bool; receive IP TTL w/dgram */
473573a953andre#define	IP_MINTTL		66   /* minimum TTL for packet or drop */
474bedcd4aandre#define	IP_DONTFRAG		67   /* don't fragment packet */
47532041f4tuexen#define	IP_RECVTOS		68   /* bool; receive IP TOS w/dgram */
4766afaafdmdodd
477ffd77d9bms/* IPv4 Source Filter Multicast API [RFC3678] */
478ffd77d9bms#define	IP_ADD_SOURCE_MEMBERSHIP	70   /* join a source-specific group */
479ffd77d9bms#define	IP_DROP_SOURCE_MEMBERSHIP	71   /* drop a single source */
480ffd77d9bms#define	IP_BLOCK_SOURCE			72   /* block a source */
481ffd77d9bms#define	IP_UNBLOCK_SOURCE		73   /* unblock a source */
482ffd77d9bms
483ffd77d9bms/* The following option is private; do not use it from user applications. */
484ffd77d9bms#define	IP_MSFILTER			74   /* set/get filter list */
485ffd77d9bms
486e5e4cd3rscheff/* The following option deals with the 802.1Q Ethernet Priority Code Point */
487e5e4cd3rscheff#define	IP_VLAN_PCP		75   /* int; set/get PCP used for packet, */
488e5e4cd3rscheff				     /*      -1 use interface default */
489e5e4cd3rscheff
490ffd77d9bms/* Protocol Independent Multicast API [RFC3678] */
491ffd77d9bms#define	MCAST_JOIN_GROUP		80   /* join an any-source group */
492ffd77d9bms#define	MCAST_LEAVE_GROUP		81   /* leave all sources for group */
493ffd77d9bms#define	MCAST_JOIN_SOURCE_GROUP		82   /* join a source-specific group */
494ffd77d9bms#define	MCAST_LEAVE_SOURCE_GROUP	83   /* leave a single source */
495ffd77d9bms#define	MCAST_BLOCK_SOURCE		84   /* block a source */
496ffd77d9bms#define	MCAST_UNBLOCK_SOURCE		85   /* unblock a source */
497ffd77d9bms
4980e45eb3adrian/* Flow and RSS definitions */
4990e45eb3adrian#define	IP_FLOWID		90   /* get flow id for the given socket/inp */
5000e45eb3adrian#define	IP_FLOWTYPE		91   /* get flow type (M_HASHTYPE) */
5010e45eb3adrian#define	IP_RSSBUCKETID		92   /* get RSS flowid -> bucket mapping */
502e623d51adrian#define	IP_RECVFLOWID		93   /* bool; receive IP flowid/flowtype w/ datagram */
503e623d51adrian#define	IP_RECVRSSBUCKETID	94   /* bool; receive IP RSS bucket id w/ datagram */
5040e45eb3adrian
5058fb65cergrimes/*
5068fb65cergrimes * Defaults and limits for options
5078fb65cergrimes */
5088fb65cergrimes#define	IP_DEFAULT_MULTICAST_TTL  1	/* normally limit m'casts to 1 hop  */
5098fb65cergrimes#define	IP_DEFAULT_MULTICAST_LOOP 1	/* normally hear sends if a member  */
51018895e4bms
51118895e4bms/*
5121a5fd51hselasky * Limit for IPv4 multicast memberships
51318895e4bms */
51418895e4bms#define	IP_MAX_MEMBERSHIPS	4095
51528b42e9bms
51628b42e9bms/*
51728b42e9bms * Default resource limits for IPv4 multicast source filtering.
51828b42e9bms * These may be modified by sysctl.
51928b42e9bms */
52028b42e9bms#define	IP_MAX_GROUP_SRC_FILTER		512	/* sources per group */
52128b42e9bms#define	IP_MAX_SOCK_SRC_FILTER		128	/* sources per socket/group */
5227123340bms#define	IP_MAX_SOCK_MUTE_FILTER		128	/* XXX no longer used */
5238fb65cergrimes
5248fb65cergrimes/*
5258fb65cergrimes * Argument structure for IP_ADD_MEMBERSHIP and IP_DROP_MEMBERSHIP.
5268fb65cergrimes */
5278fb65cergrimesstruct ip_mreq {
5288fb65cergrimes	struct	in_addr imr_multiaddr;	/* IP multicast address of group */
5298fb65cergrimes	struct	in_addr imr_interface;	/* local IP address of interface */
5308fb65cergrimes};
5318fb65cergrimes
5328fb65cergrimes/*
533ffd77d9bms * Modified argument structure for IP_MULTICAST_IF, obtained from Linux.
534ffd77d9bms * This is used to specify an interface index for multicast sends, as
535ffd77d9bms * the IPv4 legacy APIs do not support this (unless IP_SENDIF is available).
536ffd77d9bms */
537ffd77d9bmsstruct ip_mreqn {
538ffd77d9bms	struct	in_addr imr_multiaddr;	/* IP multicast address of group */
539ffd77d9bms	struct	in_addr imr_address;	/* local IP address of interface */
540ffd77d9bms	int		imr_ifindex;	/* Interface index; cast to uint32_t */
541ffd77d9bms};
542ffd77d9bms
543ffd77d9bms/*
544ffd77d9bms * Argument structure for IPv4 Multicast Source Filter APIs. [RFC3678]
545ffd77d9bms */
546ffd77d9bmsstruct ip_mreq_source {
547ffd77d9bms	struct	in_addr imr_multiaddr;	/* IP multicast address of group */
548ffd77d9bms	struct	in_addr imr_sourceaddr;	/* IP address of source */
549ffd77d9bms	struct	in_addr imr_interface;	/* local IP address of interface */
550ffd77d9bms};
551ffd77d9bms
552ffd77d9bms/*
553ffd77d9bms * Argument structures for Protocol-Independent Multicast Source
554ffd77d9bms * Filter APIs. [RFC3678]
555ffd77d9bms */
556ffd77d9bmsstruct group_req {
557ffd77d9bms	uint32_t		gr_interface;	/* interface index */
558ffd77d9bms	struct sockaddr_storage	gr_group;	/* group address */
559ffd77d9bms};
560ffd77d9bms
561ffd77d9bmsstruct group_source_req {
562ffd77d9bms	uint32_t		gsr_interface;	/* interface index */
563ffd77d9bms	struct sockaddr_storage	gsr_group;	/* group address */
564ffd77d9bms	struct sockaddr_storage	gsr_source;	/* source address */
565ffd77d9bms};
566ffd77d9bms
567