in.h revision 14195
1294332Sdes/*
2276707Sdes * Copyright (c) 1982, 1986, 1990, 1993
3276707Sdes *	The Regents of the University of California.  All rights reserved.
4276707Sdes *
5276707Sdes * Redistribution and use in source and binary forms, with or without
6276707Sdes * modification, are permitted provided that the following conditions
7276707Sdes * are met:
8276707Sdes * 1. Redistributions of source code must retain the above copyright
9276707Sdes *    notice, this list of conditions and the following disclaimer.
10276707Sdes * 2. Redistributions in binary form must reproduce the above copyright
11276707Sdes *    notice, this list of conditions and the following disclaimer in the
12276707Sdes *    documentation and/or other materials provided with the distribution.
13276707Sdes * 3. All advertising materials mentioning features or use of this software
14276707Sdes *    must display the following acknowledgement:
15276707Sdes *	This product includes software developed by the University of
16276707Sdes *	California, Berkeley and its contributors.
17276707Sdes * 4. Neither the name of the University nor the names of its contributors
18276707Sdes *    may be used to endorse or promote products derived from this software
19276707Sdes *    without specific prior written permission.
20276707Sdes *
21276707Sdes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22276707Sdes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23294332Sdes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24276707Sdes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25276707Sdes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26276707Sdes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27276707Sdes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28276707Sdes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29276707Sdes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30276707Sdes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31276707Sdes * SUCH DAMAGE.
32276707Sdes *
33294332Sdes *	@(#)in.h	8.3 (Berkeley) 1/3/94
34294332Sdes * $Id: in.h,v 1.14 1996/01/19 08:00:57 peter Exp $
35276707Sdes */
36276707Sdes
37294332Sdes#ifndef _NETINET_IN_H_
38276707Sdes#define _NETINET_IN_H_
39276707Sdes
40276707Sdes/*
41276707Sdes * Constants and structures defined by the internet system,
42276707Sdes * Per RFC 790, September 1981, and numerous additions.
43276707Sdes */
44276707Sdes
45276707Sdes/*
46276707Sdes * Protocols
47276707Sdes */
48276707Sdes#define	IPPROTO_IP		0		/* dummy for IP */
49276707Sdes#define	IPPROTO_ICMP		1		/* control message protocol */
50276707Sdes#define	IPPROTO_IGMP		2		/* group mgmt protocol */
51276707Sdes#define	IPPROTO_GGP		3		/* gateway^2 (deprecated) */
52276707Sdes#define IPPROTO_IPIP		4 		/* IP encapsulation in IP */
53276707Sdes#define	IPPROTO_TCP		6		/* tcp */
54276707Sdes#define	IPPROTO_EGP		8		/* exterior gateway protocol */
55276707Sdes#define	IPPROTO_PUP		12		/* pup */
56276707Sdes#define	IPPROTO_UDP		17		/* user datagram protocol */
57276707Sdes#define	IPPROTO_IDP		22		/* xns idp */
58276707Sdes#define	IPPROTO_TP		29 		/* tp-4 w/ class negotiation */
59276707Sdes#define IPPROTO_RSVP		46 		/* resource reservation */
60276707Sdes#define	IPPROTO_EON		80		/* ISO cnlp */
61276707Sdes#define	IPPROTO_ENCAP		98		/* encapsulation header */
62276707Sdes
63276707Sdes#define	IPPROTO_RAW		255		/* raw IP packet */
64276707Sdes#define	IPPROTO_MAX		256
65276707Sdes
66276707Sdes
67276707Sdes/*
68276707Sdes * Local port number conventions:
69276707Sdes *
70276707Sdes * When a user does a bind(2) or connect(2) with a port number of zero,
71276707Sdes * a non-conflicting local port address is chosen.
72276707Sdes * The default range is IPPORT_RESERVED through
73276707Sdes * IPPORT_USERRESERVED, although that is settable by sysctl.
74276707Sdes *
75276707Sdes * A user may set the IPPROTO_IP option IP_PORTRANGE to change this
76276707Sdes * default assignment range.
77276707Sdes *
78276707Sdes * The value IP_PORTRANGE_DEFAULT causes the default behavior.
79276707Sdes *
80276707Sdes * The value IP_PORTRANGE_HIGH changes the range of candidate port numbers
81276707Sdes * into the "high" range.  These are reserved for client outbound connections
82276707Sdes * which do not want to be filtered by any firewalls.
83276707Sdes *
84276707Sdes * The value IP_PORTRANGE_LOW changes the range to the "low" are
85276707Sdes * that is (by convention) restricted to privileged processes.  This
86276707Sdes * convention is based on "vouchsafe" principles only.  It is only secure
87276707Sdes * if you trust the remote host to restrict these ports.
88276707Sdes *
89276707Sdes * The default range of ports and the high range can be changed by
90276707Sdes * sysctl(3).  (net.inet.ip.port{hi}{first,last}_auto)
91276707Sdes *
92276707Sdes * Changing those values has bad security implications if you are
93276707Sdes * using a a stateless firewall that is allowing packets outside of that
94276707Sdes * range in order to allow transparent outgoing connections.
95276707Sdes *
96276707Sdes * Such a firewall configuration will generally depend on the use of these
97276707Sdes * default values.  If you change them, you may find your Security
98276707Sdes * Administrator looking for you with a heavy object.
99276707Sdes */
100276707Sdes
101276707Sdes/*
102294332Sdes * Ports < IPPORT_RESERVED are reserved for
103294332Sdes * privileged processes (e.g. root).         (IP_PORTRANGE_LOW)
104276707Sdes * Ports > IPPORT_USERRESERVED are reserved
105294332Sdes * for servers, not necessarily privileged.  (IP_PORTRANGE_DEFAULT)
106294332Sdes */
107276707Sdes#define	IPPORT_RESERVED		1024
108276707Sdes#define	IPPORT_USERRESERVED	5000
109276707Sdes
110294332Sdes/*
111276707Sdes * Default local port range to use by setting IP_PORTRANGE_HIGH
112276707Sdes */
113294332Sdes#define	IPPORT_HIFIRSTAUTO	40000
114276707Sdes#define	IPPORT_HILASTAUTO	44999
115294332Sdes
116276707Sdes/*
117276707Sdes * Internet address (a structure for historical reasons)
118276707Sdes */
119276707Sdesstruct in_addr {
120294332Sdes	u_long s_addr;
121276707Sdes};
122294332Sdes
123276707Sdes/*
124276707Sdes * Definitions of bits in internet address integers.
125294332Sdes * On subnets, the decomposition of addresses to host and net parts
126276707Sdes * is done according to subnet mask, not the masks here.
127294332Sdes */
128276707Sdes#define	IN_CLASSA(i)		(((long)(i) & 0x80000000) == 0)
129276707Sdes#define	IN_CLASSA_NET		0xff000000
130276707Sdes#define	IN_CLASSA_NSHIFT	24
131276707Sdes#define	IN_CLASSA_HOST		0x00ffffff
132294332Sdes#define	IN_CLASSA_MAX		128
133276707Sdes
134294332Sdes#define	IN_CLASSB(i)		(((long)(i) & 0xc0000000) == 0x80000000)
135276707Sdes#define	IN_CLASSB_NET		0xffff0000
136276707Sdes#define	IN_CLASSB_NSHIFT	16
137294332Sdes#define	IN_CLASSB_HOST		0x0000ffff
138276707Sdes#define	IN_CLASSB_MAX		65536
139294332Sdes
140276707Sdes#define	IN_CLASSC(i)		(((long)(i) & 0xe0000000) == 0xc0000000)
141276707Sdes#define	IN_CLASSC_NET		0xffffff00
142294332Sdes#define	IN_CLASSC_NSHIFT	8
143276707Sdes#define	IN_CLASSC_HOST		0x000000ff
144276707Sdes
145294332Sdes#define	IN_CLASSD(i)		(((long)(i) & 0xf0000000) == 0xe0000000)
146276707Sdes#define	IN_CLASSD_NET		0xf0000000	/* These ones aren't really */
147276707Sdes#define	IN_CLASSD_NSHIFT	28		/* net and host fields, but */
148276707Sdes#define	IN_CLASSD_HOST		0x0fffffff	/* routing needn't know.    */
149276707Sdes#define	IN_MULTICAST(i)		IN_CLASSD(i)
150294332Sdes
151276707Sdes#define	IN_EXPERIMENTAL(i)	(((long)(i) & 0xf0000000) == 0xf0000000)
152294332Sdes#define	IN_BADCLASS(i)		(((long)(i) & 0xf0000000) == 0xf0000000)
153276707Sdes
154276707Sdes#define	INADDR_ANY		(u_long)0x00000000
155294332Sdes#define	INADDR_BROADCAST	(u_long)0xffffffff	/* must be masked */
156276707Sdes#ifndef KERNEL
157294332Sdes#define	INADDR_NONE		0xffffffff		/* -1 return */
158294332Sdes#endif
159294332Sdes
160294332Sdes#define	INADDR_UNSPEC_GROUP	(u_long)0xe0000000	/* 224.0.0.0 */
161294332Sdes#define	INADDR_ALLHOSTS_GROUP	(u_long)0xe0000001	/* 224.0.0.1 */
162276707Sdes#define	INADDR_MAX_LOCAL_GROUP	(u_long)0xe00000ff	/* 224.0.0.255 */
163276707Sdes
164276707Sdes#define	IN_LOOPBACKNET		127			/* official! */
165276707Sdes
166276707Sdes/*
167276707Sdes * Socket address, internet style.
168276707Sdes */
169276707Sdesstruct sockaddr_in {
170276707Sdes	u_char	sin_len;
171276707Sdes	u_char	sin_family;
172276707Sdes	u_short	sin_port;
173276707Sdes	struct	in_addr sin_addr;
174276707Sdes	char	sin_zero[8];
175276707Sdes};
176276707Sdes
177276707Sdes/*
178276707Sdes * Structure used to describe IP options.
179276707Sdes * Used to store options internally, to pass them to a process,
180276707Sdes * or to restore options retrieved earlier.
181276707Sdes * The ip_dst is used for the first-hop gateway when using a source route
182276707Sdes * (this gets put into the header proper).
183294332Sdes */
184294332Sdesstruct ip_opts {
185294332Sdes	struct	in_addr ip_dst;		/* first hop, 0 w/o src rt */
186294332Sdes	char	ip_opts[40];		/* actually variable in size */
187294332Sdes};
188294332Sdes
189294332Sdes/*
190294332Sdes * Options for use with [gs]etsockopt at the IP level.
191294332Sdes * First word of comment is data type; bool is stored in int.
192294332Sdes */
193294332Sdes#define	IP_OPTIONS		1    /* buf/ip_opts; set/get IP options */
194294332Sdes#define	IP_HDRINCL		2    /* int; header is included with data */
195294332Sdes#define	IP_TOS			3    /* int; IP type of service and preced. */
196294332Sdes#define	IP_TTL			4    /* int; IP time to live */
197294332Sdes#define	IP_RECVOPTS		5    /* bool; receive all IP opts w/dgram */
198294332Sdes#define	IP_RECVRETOPTS		6    /* bool; receive IP opts for response */
199294332Sdes#define	IP_RECVDSTADDR		7    /* bool; receive IP dst addr w/dgram */
200294332Sdes#define	IP_RETOPTS		8    /* ip_opts; set/get IP options */
201294332Sdes#define	IP_MULTICAST_IF		9    /* u_char; set/get IP multicast i/f  */
202294332Sdes#define	IP_MULTICAST_TTL	10   /* u_char; set/get IP multicast ttl */
203294332Sdes#define	IP_MULTICAST_LOOP	11   /* u_char; set/get IP multicast loopback */
204294332Sdes#define	IP_ADD_MEMBERSHIP	12   /* ip_mreq; add an IP group membership */
205294332Sdes#define	IP_DROP_MEMBERSHIP	13   /* ip_mreq; drop an IP group membership */
206294332Sdes#define IP_MULTICAST_VIF	14   /* set/get IP mcast virt. iface */
207294332Sdes#define IP_RSVP_ON		15   /* enable RSVP in kernel */
208294332Sdes#define IP_RSVP_OFF		16   /* disable RSVP in kernel */
209294332Sdes#define IP_RSVP_VIF_ON		17   /* set RSVP per-vif socket */
210294332Sdes#define IP_RSVP_VIF_OFF		18   /* unset RSVP per-vif socket */
211294332Sdes#define IP_PORTRANGE		19   /* int; range to choose for unspec port */
212294332Sdes
213294332Sdes/*
214294332Sdes * Defaults and limits for options
215294332Sdes */
216276707Sdes#define	IP_DEFAULT_MULTICAST_TTL  1	/* normally limit m'casts to 1 hop  */
217276707Sdes#define	IP_DEFAULT_MULTICAST_LOOP 1	/* normally hear sends if a member  */
218276707Sdes#define	IP_MAX_MEMBERSHIPS	20	/* per socket */
219276707Sdes
220276707Sdes/*
221276707Sdes * Argument structure for IP_ADD_MEMBERSHIP and IP_DROP_MEMBERSHIP.
222276707Sdes */
223276707Sdesstruct ip_mreq {
224276707Sdes	struct	in_addr imr_multiaddr;	/* IP multicast address of group */
225276707Sdes	struct	in_addr imr_interface;	/* local IP address of interface */
226276707Sdes};
227276707Sdes
228276707Sdes/*
229276707Sdes * Argument for IP_PORTRANGE:
230276707Sdes * - which range to search when port is unspecified at bind() or connect()
231276707Sdes */
232276707Sdes#define	IP_PORTRANGE_DEFAULT	0	/* default range */
233276707Sdes#define	IP_PORTRANGE_HIGH	1	/* "high" - request firewall bypass */
234276707Sdes#define	IP_PORTRANGE_LOW	2	/* "low" - vouchsafe security */
235294332Sdes
236294332Sdes/*
237294332Sdes * Definitions for inet sysctl operations.
238294332Sdes *
239294332Sdes * Third level is protocol number.
240294332Sdes * Fourth level is desired variable within that protocol.
241276707Sdes */
242276707Sdes#define	IPPROTO_MAXID	(IPPROTO_IDP + 1)	/* don't list to IPPROTO_MAX */
243276707Sdes
244276707Sdes#define	CTL_IPPROTO_NAMES { \
245276707Sdes	{ "ip", CTLTYPE_NODE }, \
246276707Sdes	{ "icmp", CTLTYPE_NODE }, \
247276707Sdes	{ "igmp", CTLTYPE_NODE }, \
248294332Sdes	{ "ggp", CTLTYPE_NODE }, \
249294332Sdes	{ 0, 0 }, \
250294332Sdes	{ 0, 0 }, \
251294332Sdes	{ "tcp", CTLTYPE_NODE }, \
252276707Sdes	{ 0, 0 }, \
253276707Sdes	{ "egp", CTLTYPE_NODE }, \
254276707Sdes	{ 0, 0 }, \
255276707Sdes	{ 0, 0 }, \
256276707Sdes	{ 0, 0 }, \
257276707Sdes	{ "pup", CTLTYPE_NODE }, \
258276707Sdes	{ 0, 0 }, \
259276707Sdes	{ 0, 0 }, \
260276707Sdes	{ 0, 0 }, \
261276707Sdes	{ 0, 0 }, \
262276707Sdes	{ "udp", CTLTYPE_NODE }, \
263276707Sdes	{ 0, 0 }, \
264276707Sdes	{ 0, 0 }, \
265276707Sdes	{ 0, 0 }, \
266276707Sdes	{ 0, 0 }, \
267276707Sdes	{ "idp", CTLTYPE_NODE }, \
268276707Sdes}
269276707Sdes
270276707Sdes/*
271276707Sdes * Names for IP sysctl objects
272276707Sdes */
273276707Sdes#define	IPCTL_FORWARDING	1	/* act as router */
274276707Sdes#define	IPCTL_SENDREDIRECTS	2	/* may send redirects when forwarding */
275276707Sdes#define	IPCTL_DEFTTL		3	/* default TTL */
276276707Sdes#ifdef notyet
277276707Sdes#define	IPCTL_DEFMTU		4	/* default MTU */
278276707Sdes#endif
279276707Sdes#define IPCTL_RTEXPIRE		5	/* cloned route expiration time */
280276707Sdes#define IPCTL_RTMINEXPIRE	6	/* min value for expiration time */
281276707Sdes#define IPCTL_RTMAXCACHE	7	/* trigger level for dynamic expire */
282276707Sdes#define	IPCTL_SOURCEROUTE	8	/* may perform source routes */
283276707Sdes#define	IPCTL_DIRECTEDBROADCAST	9	/* may re-broadcast received packets */
284276707Sdes#define IPCTL_INTRQMAXLEN	10	/* max length of netisr queue */
285276707Sdes#define IPCTL_INTRQDROPS	11	/* number of netisr q drops */
286276707Sdes#define	IPCTL_MAXID		12
287276707Sdes
288276707Sdes#define	IPCTL_NAMES { \
289276707Sdes	{ 0, 0 }, \
290276707Sdes	{ "forwarding", CTLTYPE_INT }, \
291276707Sdes	{ "redirect", CTLTYPE_INT }, \
292276707Sdes	{ "ttl", CTLTYPE_INT }, \
293276707Sdes	{ "mtu", CTLTYPE_INT }, \
294276707Sdes	{ "rtexpire", CTLTYPE_INT }, \
295276707Sdes	{ "rtminexpire", CTLTYPE_INT }, \
296276707Sdes	{ "rtmaxcache", CTLTYPE_INT }, \
297276707Sdes	{ "sourceroute", CTLTYPE_INT }, \
298276707Sdes 	{ "directed-broadcast", CTLTYPE_INT }, \
299276707Sdes	{ "intr-queue-maxlen", CTLTYPE_INT }, \
300276707Sdes	{ "intr-queue-drops", CTLTYPE_INT }, \
301276707Sdes}
302276707Sdes
303276707Sdes
304276707Sdes#ifdef KERNEL
305276707Sdesstruct ifnet; struct mbuf;	/* forward declarations for Standard C */
306276707Sdes
307276707Sdesint	 in_broadcast __P((struct in_addr, struct ifnet *));
308276707Sdesint	 in_canforward __P((struct in_addr));
309276707Sdesint	 in_cksum __P((struct mbuf *, int));
310276707Sdesint	 in_localaddr __P((struct in_addr));
311276707Sdeschar 	*inet_ntoa __P((struct in_addr)); /* in libkern */
312276707Sdes#endif
313276707Sdes
314276707Sdes#endif
315276707Sdes
316276707Sdes