in.h revision 13491
11541Srgrimes/*
21541Srgrimes * Copyright (c) 1982, 1986, 1990, 1993
31541Srgrimes *	The Regents of the University of California.  All rights reserved.
41541Srgrimes *
51541Srgrimes * Redistribution and use in source and binary forms, with or without
61541Srgrimes * modification, are permitted provided that the following conditions
71541Srgrimes * are met:
81541Srgrimes * 1. Redistributions of source code must retain the above copyright
91541Srgrimes *    notice, this list of conditions and the following disclaimer.
101541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
111541Srgrimes *    notice, this list of conditions and the following disclaimer in the
121541Srgrimes *    documentation and/or other materials provided with the distribution.
131541Srgrimes * 3. All advertising materials mentioning features or use of this software
141541Srgrimes *    must display the following acknowledgement:
151541Srgrimes *	This product includes software developed by the University of
161541Srgrimes *	California, Berkeley and its contributors.
171541Srgrimes * 4. Neither the name of the University nor the names of its contributors
181541Srgrimes *    may be used to endorse or promote products derived from this software
191541Srgrimes *    without specific prior written permission.
201541Srgrimes *
211541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
221541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
231541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
241541Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
251541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
261541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
271541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
281541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
291541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
301541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
311541Srgrimes * SUCH DAMAGE.
321541Srgrimes *
331541Srgrimes *	@(#)in.h	8.3 (Berkeley) 1/3/94
3413491Speter * $Id: in.h,v 1.13 1995/11/14 20:33:57 phk Exp $
351541Srgrimes */
361541Srgrimes
372169Spaul#ifndef _NETINET_IN_H_
382169Spaul#define _NETINET_IN_H_
392169Spaul
401541Srgrimes/*
411541Srgrimes * Constants and structures defined by the internet system,
421541Srgrimes * Per RFC 790, September 1981, and numerous additions.
431541Srgrimes */
441541Srgrimes
451541Srgrimes/*
461541Srgrimes * Protocols
471541Srgrimes */
481541Srgrimes#define	IPPROTO_IP		0		/* dummy for IP */
491541Srgrimes#define	IPPROTO_ICMP		1		/* control message protocol */
501541Srgrimes#define	IPPROTO_IGMP		2		/* group mgmt protocol */
511541Srgrimes#define	IPPROTO_GGP		3		/* gateway^2 (deprecated) */
529209Swollman#define IPPROTO_IPIP		4 		/* IP encapsulation in IP */
531541Srgrimes#define	IPPROTO_TCP		6		/* tcp */
541541Srgrimes#define	IPPROTO_EGP		8		/* exterior gateway protocol */
551541Srgrimes#define	IPPROTO_PUP		12		/* pup */
561541Srgrimes#define	IPPROTO_UDP		17		/* user datagram protocol */
571541Srgrimes#define	IPPROTO_IDP		22		/* xns idp */
581541Srgrimes#define	IPPROTO_TP		29 		/* tp-4 w/ class negotiation */
592531Swollman#define IPPROTO_RSVP		46 		/* resource reservation */
601541Srgrimes#define	IPPROTO_EON		80		/* ISO cnlp */
611541Srgrimes#define	IPPROTO_ENCAP		98		/* encapsulation header */
621541Srgrimes
631541Srgrimes#define	IPPROTO_RAW		255		/* raw IP packet */
641541Srgrimes#define	IPPROTO_MAX		256
651541Srgrimes
661541Srgrimes
671541Srgrimes/*
681541Srgrimes * Local port number conventions:
691541Srgrimes * Ports < IPPORT_RESERVED are reserved for
701541Srgrimes * privileged processes (e.g. root).
711541Srgrimes * Ports > IPPORT_USERRESERVED are reserved
721541Srgrimes * for servers, not necessarily privileged.
731541Srgrimes */
741541Srgrimes#define	IPPORT_RESERVED		1024
751541Srgrimes#define	IPPORT_USERRESERVED	5000
761541Srgrimes
771541Srgrimes/*
7813491Speter * Range of ports for automatic assignment to local addresses that
7913491Speter * have not explicitly specified an address.
8013491Speter *
8113491Speter * These can be overridden at kernel config time, and are used to init
8213491Speter * sysctl variables.  The sysctl variables can be changed at runtime.
8313491Speter */
8413491Speter#ifndef IPPORT_FIRSTAUTO
8513491Speter#define	IPPORT_FIRSTAUTO	20000
8613491Speter#endif
8713491Speter#ifndef IPPORT_LASTAUTO
8813491Speter#define	IPPORT_LASTAUTO		30000
8913491Speter#endif
9013491Speter
9113491Speter/*
921541Srgrimes * Internet address (a structure for historical reasons)
931541Srgrimes */
941541Srgrimesstruct in_addr {
951541Srgrimes	u_long s_addr;
961541Srgrimes};
971541Srgrimes
981541Srgrimes/*
991541Srgrimes * Definitions of bits in internet address integers.
1001541Srgrimes * On subnets, the decomposition of addresses to host and net parts
1011541Srgrimes * is done according to subnet mask, not the masks here.
1021541Srgrimes */
1031541Srgrimes#define	IN_CLASSA(i)		(((long)(i) & 0x80000000) == 0)
1041541Srgrimes#define	IN_CLASSA_NET		0xff000000
1051541Srgrimes#define	IN_CLASSA_NSHIFT	24
1061541Srgrimes#define	IN_CLASSA_HOST		0x00ffffff
1071541Srgrimes#define	IN_CLASSA_MAX		128
1081541Srgrimes
1091541Srgrimes#define	IN_CLASSB(i)		(((long)(i) & 0xc0000000) == 0x80000000)
1101541Srgrimes#define	IN_CLASSB_NET		0xffff0000
1111541Srgrimes#define	IN_CLASSB_NSHIFT	16
1121541Srgrimes#define	IN_CLASSB_HOST		0x0000ffff
1131541Srgrimes#define	IN_CLASSB_MAX		65536
1141541Srgrimes
1151541Srgrimes#define	IN_CLASSC(i)		(((long)(i) & 0xe0000000) == 0xc0000000)
1161541Srgrimes#define	IN_CLASSC_NET		0xffffff00
1171541Srgrimes#define	IN_CLASSC_NSHIFT	8
1181541Srgrimes#define	IN_CLASSC_HOST		0x000000ff
1191541Srgrimes
1201541Srgrimes#define	IN_CLASSD(i)		(((long)(i) & 0xf0000000) == 0xe0000000)
1211541Srgrimes#define	IN_CLASSD_NET		0xf0000000	/* These ones aren't really */
1221541Srgrimes#define	IN_CLASSD_NSHIFT	28		/* net and host fields, but */
1231541Srgrimes#define	IN_CLASSD_HOST		0x0fffffff	/* routing needn't know.    */
1241541Srgrimes#define	IN_MULTICAST(i)		IN_CLASSD(i)
1251541Srgrimes
1261541Srgrimes#define	IN_EXPERIMENTAL(i)	(((long)(i) & 0xf0000000) == 0xf0000000)
1271541Srgrimes#define	IN_BADCLASS(i)		(((long)(i) & 0xf0000000) == 0xf0000000)
1281541Srgrimes
1291541Srgrimes#define	INADDR_ANY		(u_long)0x00000000
1301541Srgrimes#define	INADDR_BROADCAST	(u_long)0xffffffff	/* must be masked */
1311541Srgrimes#ifndef KERNEL
1321541Srgrimes#define	INADDR_NONE		0xffffffff		/* -1 return */
1331541Srgrimes#endif
1341541Srgrimes
1351541Srgrimes#define	INADDR_UNSPEC_GROUP	(u_long)0xe0000000	/* 224.0.0.0 */
1361541Srgrimes#define	INADDR_ALLHOSTS_GROUP	(u_long)0xe0000001	/* 224.0.0.1 */
1371541Srgrimes#define	INADDR_MAX_LOCAL_GROUP	(u_long)0xe00000ff	/* 224.0.0.255 */
1381541Srgrimes
1391541Srgrimes#define	IN_LOOPBACKNET		127			/* official! */
1401541Srgrimes
1411541Srgrimes/*
1421541Srgrimes * Socket address, internet style.
1431541Srgrimes */
1441541Srgrimesstruct sockaddr_in {
1451541Srgrimes	u_char	sin_len;
1461541Srgrimes	u_char	sin_family;
1471541Srgrimes	u_short	sin_port;
1481541Srgrimes	struct	in_addr sin_addr;
1491541Srgrimes	char	sin_zero[8];
1501541Srgrimes};
1511541Srgrimes
1521541Srgrimes/*
1531541Srgrimes * Structure used to describe IP options.
1541541Srgrimes * Used to store options internally, to pass them to a process,
1551541Srgrimes * or to restore options retrieved earlier.
1561541Srgrimes * The ip_dst is used for the first-hop gateway when using a source route
1571541Srgrimes * (this gets put into the header proper).
1581541Srgrimes */
1591541Srgrimesstruct ip_opts {
1601541Srgrimes	struct	in_addr ip_dst;		/* first hop, 0 w/o src rt */
1611541Srgrimes	char	ip_opts[40];		/* actually variable in size */
1621541Srgrimes};
1631541Srgrimes
1641541Srgrimes/*
1651541Srgrimes * Options for use with [gs]etsockopt at the IP level.
1661541Srgrimes * First word of comment is data type; bool is stored in int.
1671541Srgrimes */
1681541Srgrimes#define	IP_OPTIONS		1    /* buf/ip_opts; set/get IP options */
1691541Srgrimes#define	IP_HDRINCL		2    /* int; header is included with data */
1701541Srgrimes#define	IP_TOS			3    /* int; IP type of service and preced. */
1711541Srgrimes#define	IP_TTL			4    /* int; IP time to live */
1721541Srgrimes#define	IP_RECVOPTS		5    /* bool; receive all IP opts w/dgram */
1731541Srgrimes#define	IP_RECVRETOPTS		6    /* bool; receive IP opts for response */
1741541Srgrimes#define	IP_RECVDSTADDR		7    /* bool; receive IP dst addr w/dgram */
1751541Srgrimes#define	IP_RETOPTS		8    /* ip_opts; set/get IP options */
1761541Srgrimes#define	IP_MULTICAST_IF		9    /* u_char; set/get IP multicast i/f  */
1771541Srgrimes#define	IP_MULTICAST_TTL	10   /* u_char; set/get IP multicast ttl */
1781541Srgrimes#define	IP_MULTICAST_LOOP	11   /* u_char; set/get IP multicast loopback */
1791541Srgrimes#define	IP_ADD_MEMBERSHIP	12   /* ip_mreq; add an IP group membership */
1801541Srgrimes#define	IP_DROP_MEMBERSHIP	13   /* ip_mreq; drop an IP group membership */
1812531Swollman#define IP_MULTICAST_VIF	14   /* set/get IP mcast virt. iface */
1822531Swollman#define IP_RSVP_ON		15   /* enable RSVP in kernel */
1832531Swollman#define IP_RSVP_OFF		16   /* disable RSVP in kernel */
1849209Swollman#define IP_RSVP_VIF_ON		17   /* set RSVP per-vif socket */
1859209Swollman#define IP_RSVP_VIF_OFF		18   /* unset RSVP per-vif socket */
1861541Srgrimes
1871541Srgrimes/*
1881541Srgrimes * Defaults and limits for options
1891541Srgrimes */
1901541Srgrimes#define	IP_DEFAULT_MULTICAST_TTL  1	/* normally limit m'casts to 1 hop  */
1911541Srgrimes#define	IP_DEFAULT_MULTICAST_LOOP 1	/* normally hear sends if a member  */
1929209Swollman#define	IP_MAX_MEMBERSHIPS	20	/* per socket */
1931541Srgrimes
1941541Srgrimes/*
1951541Srgrimes * Argument structure for IP_ADD_MEMBERSHIP and IP_DROP_MEMBERSHIP.
1961541Srgrimes */
1971541Srgrimesstruct ip_mreq {
1981541Srgrimes	struct	in_addr imr_multiaddr;	/* IP multicast address of group */
1991541Srgrimes	struct	in_addr imr_interface;	/* local IP address of interface */
2001541Srgrimes};
2011541Srgrimes
2021541Srgrimes/*
2031541Srgrimes * Definitions for inet sysctl operations.
2041541Srgrimes *
2051541Srgrimes * Third level is protocol number.
2061541Srgrimes * Fourth level is desired variable within that protocol.
2071541Srgrimes */
2081541Srgrimes#define	IPPROTO_MAXID	(IPPROTO_IDP + 1)	/* don't list to IPPROTO_MAX */
2091541Srgrimes
2101541Srgrimes#define	CTL_IPPROTO_NAMES { \
2111541Srgrimes	{ "ip", CTLTYPE_NODE }, \
2121541Srgrimes	{ "icmp", CTLTYPE_NODE }, \
2131541Srgrimes	{ "igmp", CTLTYPE_NODE }, \
2141541Srgrimes	{ "ggp", CTLTYPE_NODE }, \
2151541Srgrimes	{ 0, 0 }, \
2161541Srgrimes	{ 0, 0 }, \
2171541Srgrimes	{ "tcp", CTLTYPE_NODE }, \
2181541Srgrimes	{ 0, 0 }, \
2191541Srgrimes	{ "egp", CTLTYPE_NODE }, \
2201541Srgrimes	{ 0, 0 }, \
2211541Srgrimes	{ 0, 0 }, \
2221541Srgrimes	{ 0, 0 }, \
2231541Srgrimes	{ "pup", CTLTYPE_NODE }, \
2241541Srgrimes	{ 0, 0 }, \
2251541Srgrimes	{ 0, 0 }, \
2261541Srgrimes	{ 0, 0 }, \
2271541Srgrimes	{ 0, 0 }, \
2281541Srgrimes	{ "udp", CTLTYPE_NODE }, \
2291541Srgrimes	{ 0, 0 }, \
2301541Srgrimes	{ 0, 0 }, \
2311541Srgrimes	{ 0, 0 }, \
2321541Srgrimes	{ 0, 0 }, \
2331541Srgrimes	{ "idp", CTLTYPE_NODE }, \
2341541Srgrimes}
2351541Srgrimes
2361541Srgrimes/*
2371541Srgrimes * Names for IP sysctl objects
2381541Srgrimes */
2391541Srgrimes#define	IPCTL_FORWARDING	1	/* act as router */
2401541Srgrimes#define	IPCTL_SENDREDIRECTS	2	/* may send redirects when forwarding */
2411541Srgrimes#define	IPCTL_DEFTTL		3	/* default TTL */
2421541Srgrimes#ifdef notyet
2431541Srgrimes#define	IPCTL_DEFMTU		4	/* default MTU */
2441541Srgrimes#endif
2455109Swollman#define IPCTL_RTEXPIRE		5	/* cloned route expiration time */
2466399Swollman#define IPCTL_RTMINEXPIRE	6	/* min value for expiration time */
2476399Swollman#define IPCTL_RTMAXCACHE	7	/* trigger level for dynamic expire */
2487091Swollman#define	IPCTL_SOURCEROUTE	8	/* may perform source routes */
2499575Speter#define	IPCTL_DIRECTEDBROADCAST	9	/* may re-broadcast received packets */
25012003Swollman#define IPCTL_INTRQMAXLEN	10	/* max length of netisr queue */
25112003Swollman#define IPCTL_INTRQDROPS	11	/* number of netisr q drops */
25212003Swollman#define	IPCTL_MAXID		12
2531541Srgrimes
2541541Srgrimes#define	IPCTL_NAMES { \
2551541Srgrimes	{ 0, 0 }, \
2561541Srgrimes	{ "forwarding", CTLTYPE_INT }, \
2571541Srgrimes	{ "redirect", CTLTYPE_INT }, \
2581541Srgrimes	{ "ttl", CTLTYPE_INT }, \
2591541Srgrimes	{ "mtu", CTLTYPE_INT }, \
2605109Swollman	{ "rtexpire", CTLTYPE_INT }, \
2616399Swollman	{ "rtminexpire", CTLTYPE_INT }, \
2626399Swollman	{ "rtmaxcache", CTLTYPE_INT }, \
2637091Swollman	{ "sourceroute", CTLTYPE_INT }, \
2649575Speter 	{ "directed-broadcast", CTLTYPE_INT }, \
26512003Swollman	{ "intr-queue-maxlen", CTLTYPE_INT }, \
26612003Swollman	{ "intr-queue-drops", CTLTYPE_INT }, \
2671541Srgrimes}
2681541Srgrimes
2691541Srgrimes
2701541Srgrimes#ifdef KERNEL
2717088Swollmanstruct ifnet; struct mbuf;	/* forward declarations for Standard C */
2727088Swollman
2731541Srgrimesint	 in_broadcast __P((struct in_addr, struct ifnet *));
2741541Srgrimesint	 in_canforward __P((struct in_addr));
2751541Srgrimesint	 in_cksum __P((struct mbuf *, int));
2761541Srgrimesint	 in_localaddr __P((struct in_addr));
2777088Swollmanchar 	*inet_ntoa __P((struct in_addr)); /* in libkern */
2781541Srgrimes#endif
2792169Spaul
2802169Spaul#endif
2815109Swollman
282