in.h revision 93514
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
3450477Speter * $FreeBSD: head/sys/netinet/in.h 93514 2002-04-01 08:12:25Z mike $
351541Srgrimes */
361541Srgrimes
372169Spaul#ifndef _NETINET_IN_H_
382169Spaul#define _NETINET_IN_H_
392169Spaul
4093514Smike#include <sys/_types.h>
4193514Smike
421541Srgrimes/*
431541Srgrimes * Constants and structures defined by the internet system,
441541Srgrimes * Per RFC 790, September 1981, and numerous additions.
451541Srgrimes */
461541Srgrimes
471541Srgrimes/*
4833804Sjulian * Protocols (RFC 1700)
491541Srgrimes */
501541Srgrimes#define	IPPROTO_IP		0		/* dummy for IP */
5152904Sshin#define	IPPROTO_HOPOPTS		0		/* IP6 hop-by-hop options */
521541Srgrimes#define	IPPROTO_ICMP		1		/* control message protocol */
531541Srgrimes#define	IPPROTO_IGMP		2		/* group mgmt protocol */
541541Srgrimes#define	IPPROTO_GGP		3		/* gateway^2 (deprecated) */
5552904Sshin#define IPPROTO_IPV4		4 		/* IPv4 encapsulation */
5652904Sshin#define IPPROTO_IPIP		IPPROTO_IPV4	/* for compatibility */
571541Srgrimes#define	IPPROTO_TCP		6		/* tcp */
5833804Sjulian#define	IPPROTO_ST		7		/* Stream protocol II */
591541Srgrimes#define	IPPROTO_EGP		8		/* exterior gateway protocol */
6033804Sjulian#define	IPPROTO_PIGP		9		/* private interior gateway */
6133804Sjulian#define	IPPROTO_RCCMON		10		/* BBN RCC Monitoring */
6233804Sjulian#define	IPPROTO_NVPII		11		/* network voice protocol*/
631541Srgrimes#define	IPPROTO_PUP		12		/* pup */
6433804Sjulian#define	IPPROTO_ARGUS		13		/* Argus */
6533804Sjulian#define	IPPROTO_EMCON		14		/* EMCON */
6633804Sjulian#define	IPPROTO_XNET		15		/* Cross Net Debugger */
6733804Sjulian#define	IPPROTO_CHAOS		16		/* Chaos*/
681541Srgrimes#define	IPPROTO_UDP		17		/* user datagram protocol */
6933804Sjulian#define	IPPROTO_MUX		18		/* Multiplexing */
7033804Sjulian#define	IPPROTO_MEAS		19		/* DCN Measurement Subsystems */
7133804Sjulian#define	IPPROTO_HMP		20		/* Host Monitoring */
7233804Sjulian#define	IPPROTO_PRM		21		/* Packet Radio Measurement */
731541Srgrimes#define	IPPROTO_IDP		22		/* xns idp */
7433804Sjulian#define	IPPROTO_TRUNK1		23		/* Trunk-1 */
7533804Sjulian#define	IPPROTO_TRUNK2		24		/* Trunk-2 */
7633804Sjulian#define	IPPROTO_LEAF1		25		/* Leaf-1 */
7733804Sjulian#define	IPPROTO_LEAF2		26		/* Leaf-2 */
7833804Sjulian#define	IPPROTO_RDP		27		/* Reliable Data */
7933804Sjulian#define	IPPROTO_IRTP		28		/* Reliable Transaction */
801541Srgrimes#define	IPPROTO_TP		29 		/* tp-4 w/ class negotiation */
8133804Sjulian#define	IPPROTO_BLT		30		/* Bulk Data Transfer */
8233804Sjulian#define	IPPROTO_NSP		31		/* Network Services */
8333804Sjulian#define	IPPROTO_INP		32		/* Merit Internodal */
8433804Sjulian#define	IPPROTO_SEP		33		/* Sequential Exchange */
8533804Sjulian#define	IPPROTO_3PC		34		/* Third Party Connect */
8633804Sjulian#define	IPPROTO_IDPR		35		/* InterDomain Policy Routing */
8733804Sjulian#define	IPPROTO_XTP		36		/* XTP */
8833804Sjulian#define	IPPROTO_DDP		37		/* Datagram Delivery */
8933804Sjulian#define	IPPROTO_CMTP		38		/* Control Message Transport */
9033804Sjulian#define	IPPROTO_TPXX		39		/* TP++ Transport */
9133804Sjulian#define	IPPROTO_IL		40		/* IL transport protocol */
9252904Sshin#define	IPPROTO_IPV6		41		/* IP6 header */
9333804Sjulian#define	IPPROTO_SDRP		42		/* Source Demand Routing */
9452904Sshin#define	IPPROTO_ROUTING		43		/* IP6 routing header */
9552904Sshin#define	IPPROTO_FRAGMENT	44		/* IP6 fragmentation header */
9633804Sjulian#define	IPPROTO_IDRP		45		/* InterDomain Routing*/
9752904Sshin#define	IPPROTO_RSVP		46 		/* resource reservation */
9833804Sjulian#define	IPPROTO_GRE		47		/* General Routing Encap. */
9933804Sjulian#define	IPPROTO_MHRP		48		/* Mobile Host Routing */
10033804Sjulian#define	IPPROTO_BHA		49		/* BHA */
10152904Sshin#define	IPPROTO_ESP		50		/* IP6 Encap Sec. Payload */
10252904Sshin#define	IPPROTO_AH		51		/* IP6 Auth Header */
10333804Sjulian#define	IPPROTO_INLSP		52		/* Integ. Net Layer Security */
10433804Sjulian#define	IPPROTO_SWIPE		53		/* IP with encryption */
10533804Sjulian#define	IPPROTO_NHRP		54		/* Next Hop Resolution */
10672486Sasmodai#define IPPROTO_MOBILE		55		/* IP Mobility */
10772486Sasmodai#define IPPROTO_TLSP		56		/* Transport Layer Security */
10872486Sasmodai#define IPPROTO_SKIP		57		/* SKIP */
10952904Sshin#define	IPPROTO_ICMPV6		58		/* ICMP6 */
11052904Sshin#define	IPPROTO_NONE		59		/* IP6 no next header */
11152904Sshin#define	IPPROTO_DSTOPTS		60		/* IP6 destination option */
11233804Sjulian#define	IPPROTO_AHIP		61		/* any host internal protocol */
11333804Sjulian#define	IPPROTO_CFTP		62		/* CFTP */
11433804Sjulian#define	IPPROTO_HELLO		63		/* "hello" routing protocol */
11533804Sjulian#define	IPPROTO_SATEXPAK	64		/* SATNET/Backroom EXPAK */
11633804Sjulian#define	IPPROTO_KRYPTOLAN	65		/* Kryptolan */
11733804Sjulian#define	IPPROTO_RVD		66		/* Remote Virtual Disk */
11833804Sjulian#define	IPPROTO_IPPC		67		/* Pluribus Packet Core */
11933804Sjulian#define	IPPROTO_ADFS		68		/* Any distributed FS */
12033804Sjulian#define	IPPROTO_SATMON		69		/* Satnet Monitoring */
12133804Sjulian#define	IPPROTO_VISA		70		/* VISA Protocol */
12233804Sjulian#define	IPPROTO_IPCV		71		/* Packet Core Utility */
12333804Sjulian#define	IPPROTO_CPNX		72		/* Comp. Prot. Net. Executive */
12433804Sjulian#define	IPPROTO_CPHB		73		/* Comp. Prot. HeartBeat */
12533804Sjulian#define	IPPROTO_WSN		74		/* Wang Span Network */
12633804Sjulian#define	IPPROTO_PVP		75		/* Packet Video Protocol */
12733804Sjulian#define	IPPROTO_BRSATMON	76		/* BackRoom SATNET Monitoring */
12833804Sjulian#define	IPPROTO_ND		77		/* Sun net disk proto (temp.) */
12933804Sjulian#define	IPPROTO_WBMON		78		/* WIDEBAND Monitoring */
13033804Sjulian#define	IPPROTO_WBEXPAK		79		/* WIDEBAND EXPAK */
1311541Srgrimes#define	IPPROTO_EON		80		/* ISO cnlp */
13233804Sjulian#define	IPPROTO_VMTP		81		/* VMTP */
13333804Sjulian#define	IPPROTO_SVMTP		82		/* Secure VMTP */
13433804Sjulian#define	IPPROTO_VINES		83		/* Banyon VINES */
13533804Sjulian#define	IPPROTO_TTP		84		/* TTP */
13633804Sjulian#define	IPPROTO_IGP		85		/* NSFNET-IGP */
13733804Sjulian#define	IPPROTO_DGP		86		/* dissimilar gateway prot. */
13833814Sjulian#define	IPPROTO_TCF		87		/* TCF */
13933804Sjulian#define	IPPROTO_IGRP		88		/* Cisco/GXS IGRP */
14033804Sjulian#define	IPPROTO_OSPFIGP		89		/* OSPFIGP */
14133804Sjulian#define	IPPROTO_SRPC		90		/* Strite RPC protocol */
14233804Sjulian#define	IPPROTO_LARP		91		/* Locus Address Resoloution */
14333804Sjulian#define	IPPROTO_MTP		92		/* Multicast Transport */
14433804Sjulian#define	IPPROTO_AX25		93		/* AX.25 Frames */
14533804Sjulian#define	IPPROTO_IPEIP		94		/* IP encapsulated in IP */
14633804Sjulian#define	IPPROTO_MICP		95		/* Mobile Int.ing control */
14733804Sjulian#define	IPPROTO_SCCSP		96		/* Semaphore Comm. security */
14833804Sjulian#define	IPPROTO_ETHERIP		97		/* Ethernet IP encapsulation */
1491541Srgrimes#define	IPPROTO_ENCAP		98		/* encapsulation header */
15033804Sjulian#define	IPPROTO_APES		99		/* any private encr. scheme */
15133804Sjulian#define	IPPROTO_GMTP		100		/* GMTP*/
15252904Sshin#define	IPPROTO_IPCOMP		108		/* payload compression (IPComp) */
15346420Sluigi/* 101-254: Partly Unassigned */
15452904Sshin#define	IPPROTO_PIM		103		/* Protocol Independent Mcast */
15546420Sluigi#define	IPPROTO_PGM		113		/* PGM */
15633804Sjulian/* 255: Reserved */
15733804Sjulian/* BSD Private, local use, namespace incursion */
15817072Sjulian#define	IPPROTO_DIVERT		254		/* divert pseudo-protocol */
1591541Srgrimes#define	IPPROTO_RAW		255		/* raw IP packet */
1601541Srgrimes#define	IPPROTO_MAX		256
1611541Srgrimes
16252904Sshin/* last return value of *_input(), meaning "all job for this pkt is done".  */
16352904Sshin#define	IPPROTO_DONE		257
1641541Srgrimes
1651541Srgrimes/*
1661541Srgrimes * Local port number conventions:
16714195Speter *
16814195Speter * When a user does a bind(2) or connect(2) with a port number of zero,
16914195Speter * a non-conflicting local port address is chosen.
17014195Speter * The default range is IPPORT_RESERVED through
17114195Speter * IPPORT_USERRESERVED, although that is settable by sysctl.
17214195Speter *
17314195Speter * A user may set the IPPROTO_IP option IP_PORTRANGE to change this
17414195Speter * default assignment range.
17514195Speter *
17614195Speter * The value IP_PORTRANGE_DEFAULT causes the default behavior.
17714195Speter *
17814195Speter * The value IP_PORTRANGE_HIGH changes the range of candidate port numbers
17914195Speter * into the "high" range.  These are reserved for client outbound connections
18014195Speter * which do not want to be filtered by any firewalls.
18114195Speter *
18214195Speter * The value IP_PORTRANGE_LOW changes the range to the "low" are
18314195Speter * that is (by convention) restricted to privileged processes.  This
18414195Speter * convention is based on "vouchsafe" principles only.  It is only secure
18514195Speter * if you trust the remote host to restrict these ports.
18614195Speter *
18714195Speter * The default range of ports and the high range can be changed by
18817541Speter * sysctl(3).  (net.inet.ip.port{hi,low}{first,last}_auto)
18914195Speter *
19014195Speter * Changing those values has bad security implications if you are
19114195Speter * using a a stateless firewall that is allowing packets outside of that
19214195Speter * range in order to allow transparent outgoing connections.
19314195Speter *
19414195Speter * Such a firewall configuration will generally depend on the use of these
19514195Speter * default values.  If you change them, you may find your Security
19614195Speter * Administrator looking for you with a heavy object.
19735304Sphk *
19835304Sphk * For a slightly more orthodox text view on this:
19935304Sphk *
20035304Sphk *            ftp://ftp.isi.edu/in-notes/iana/assignments/port-numbers
20135304Sphk *
20235304Sphk *    port numbers are divided into three ranges:
20335304Sphk *
20435304Sphk *                0 -  1023 Well Known Ports
20535304Sphk *             1024 - 49151 Registered Ports
20635304Sphk *            49152 - 65535 Dynamic and/or Private Ports
20735304Sphk *
20814195Speter */
20914195Speter
21014195Speter/*
2111541Srgrimes * Ports < IPPORT_RESERVED are reserved for
21214195Speter * privileged processes (e.g. root).         (IP_PORTRANGE_LOW)
2131541Srgrimes * Ports > IPPORT_USERRESERVED are reserved
21414195Speter * for servers, not necessarily privileged.  (IP_PORTRANGE_DEFAULT)
2151541Srgrimes */
2161541Srgrimes#define	IPPORT_RESERVED		1024
2171541Srgrimes#define	IPPORT_USERRESERVED	5000
2181541Srgrimes
2191541Srgrimes/*
22014195Speter * Default local port range to use by setting IP_PORTRANGE_HIGH
22113491Speter */
22235304Sphk#define	IPPORT_HIFIRSTAUTO	49152
22335304Sphk#define	IPPORT_HILASTAUTO	65535
22413491Speter
22513491Speter/*
22617541Speter * Scanning for a free reserved port return a value below IPPORT_RESERVED,
22717541Speter * but higher than IPPORT_RESERVEDSTART.  Traditionally the start value was
22817541Speter * 512, but that conflicts with some well-known-services that firewalls may
22917541Speter * have a fit if we use.
23017541Speter */
23117541Speter#define IPPORT_RESERVEDSTART	600
23217541Speter
23387158Smike#define	IPPORT_MAX		65535
23487158Smike
23593514Smike#ifndef _UINT8_T_DECLARED
23693514Smiketypedef	__uint8_t		uint8_t;
23793514Smike#define	_UINT8_T_DECLARED
23887158Smike#endif
23987158Smike
24093514Smike#ifndef _UINT16_T_DECLARED
24193514Smiketypedef	__uint16_t		uint16_t;
24293514Smike#define	_UINT16_T_DECLARED
24387158Smike#endif
24487158Smike
24593514Smike#ifndef _UINT32_T_DECLARED
24693514Smiketypedef	__uint32_t		uint32_t;
24793514Smike#define	_UINT32_T_DECLARED
24893514Smike#endif
24993514Smike
25093514Smike#ifndef _IN_ADDR_T_DECLARED
25193514Smiketypedef	uint32_t		in_addr_t;
25293514Smike#define	_IN_ADDR_T_DECLARED
25393514Smike#endif
25493514Smike
25593514Smike#ifndef _IN_PORT_T_DECLARED
25693514Smiketypedef	uint16_t		in_port_t;
25793514Smike#define	_IN_PORT_T_DECLARED
25893514Smike#endif
25993514Smike
26017541Speter/*
2611541Srgrimes * Internet address (a structure for historical reasons)
2621541Srgrimes */
26387158Smike#ifndef	_STRUCT_IN_ADDR_DECLARED
2641541Srgrimesstruct in_addr {
26574700Sume	in_addr_t s_addr;
2661541Srgrimes};
26787158Smike#define	_STRUCT_IN_ADDR_DECLARED
26887158Smike#endif
2691541Srgrimes
2701541Srgrimes/*
2711541Srgrimes * Definitions of bits in internet address integers.
2721541Srgrimes * On subnets, the decomposition of addresses to host and net parts
2731541Srgrimes * is done according to subnet mask, not the masks here.
2741541Srgrimes */
27535919Sjb#define	IN_CLASSA(i)		(((u_int32_t)(i) & 0x80000000) == 0)
2761541Srgrimes#define	IN_CLASSA_NET		0xff000000
2771541Srgrimes#define	IN_CLASSA_NSHIFT	24
2781541Srgrimes#define	IN_CLASSA_HOST		0x00ffffff
2791541Srgrimes#define	IN_CLASSA_MAX		128
2801541Srgrimes
28135919Sjb#define	IN_CLASSB(i)		(((u_int32_t)(i) & 0xc0000000) == 0x80000000)
2821541Srgrimes#define	IN_CLASSB_NET		0xffff0000
2831541Srgrimes#define	IN_CLASSB_NSHIFT	16
2841541Srgrimes#define	IN_CLASSB_HOST		0x0000ffff
2851541Srgrimes#define	IN_CLASSB_MAX		65536
2861541Srgrimes
28735919Sjb#define	IN_CLASSC(i)		(((u_int32_t)(i) & 0xe0000000) == 0xc0000000)
2881541Srgrimes#define	IN_CLASSC_NET		0xffffff00
2891541Srgrimes#define	IN_CLASSC_NSHIFT	8
2901541Srgrimes#define	IN_CLASSC_HOST		0x000000ff
2911541Srgrimes
29235919Sjb#define	IN_CLASSD(i)		(((u_int32_t)(i) & 0xf0000000) == 0xe0000000)
2931541Srgrimes#define	IN_CLASSD_NET		0xf0000000	/* These ones aren't really */
2941541Srgrimes#define	IN_CLASSD_NSHIFT	28		/* net and host fields, but */
2951541Srgrimes#define	IN_CLASSD_HOST		0x0fffffff	/* routing needn't know.    */
2961541Srgrimes#define	IN_MULTICAST(i)		IN_CLASSD(i)
2971541Srgrimes
29835919Sjb#define	IN_EXPERIMENTAL(i)	(((u_int32_t)(i) & 0xf0000000) == 0xf0000000)
29935919Sjb#define	IN_BADCLASS(i)		(((u_int32_t)(i) & 0xf0000000) == 0xf0000000)
3001541Srgrimes
30135919Sjb#define	INADDR_ANY		(u_int32_t)0x00000000
30235919Sjb#define	INADDR_LOOPBACK		(u_int32_t)0x7f000001
30335919Sjb#define	INADDR_BROADCAST	(u_int32_t)0xffffffff	/* must be masked */
30455205Speter#ifndef _KERNEL
3051541Srgrimes#define	INADDR_NONE		0xffffffff		/* -1 return */
3061541Srgrimes#endif
3071541Srgrimes
30835919Sjb#define	INADDR_UNSPEC_GROUP	(u_int32_t)0xe0000000	/* 224.0.0.0 */
30935919Sjb#define	INADDR_ALLHOSTS_GROUP	(u_int32_t)0xe0000001	/* 224.0.0.1 */
31035919Sjb#define	INADDR_ALLRTRS_GROUP	(u_int32_t)0xe0000002	/* 224.0.0.2 */
31135919Sjb#define	INADDR_MAX_LOCAL_GROUP	(u_int32_t)0xe00000ff	/* 224.0.0.255 */
3121541Srgrimes
3131541Srgrimes#define	IN_LOOPBACKNET		127			/* official! */
3141541Srgrimes
3151541Srgrimes/*
3161541Srgrimes * Socket address, internet style.
3171541Srgrimes */
3181541Srgrimesstruct sockaddr_in {
3191541Srgrimes	u_char	sin_len;
3201541Srgrimes	u_char	sin_family;
3211541Srgrimes	u_short	sin_port;
3221541Srgrimes	struct	in_addr sin_addr;
3231541Srgrimes	char	sin_zero[8];
3241541Srgrimes};
3251541Srgrimes
32691984Smike#ifndef INET_ADDRSTRLEN
32752904Sshin#define	INET_ADDRSTRLEN                 16
32891984Smike#endif
32952904Sshin
3301541Srgrimes/*
3311541Srgrimes * Options for use with [gs]etsockopt at the IP level.
3321541Srgrimes * First word of comment is data type; bool is stored in int.
3331541Srgrimes */
3341541Srgrimes#define	IP_OPTIONS		1    /* buf/ip_opts; set/get IP options */
3351541Srgrimes#define	IP_HDRINCL		2    /* int; header is included with data */
3361541Srgrimes#define	IP_TOS			3    /* int; IP type of service and preced. */
3371541Srgrimes#define	IP_TTL			4    /* int; IP time to live */
3381541Srgrimes#define	IP_RECVOPTS		5    /* bool; receive all IP opts w/dgram */
3391541Srgrimes#define	IP_RECVRETOPTS		6    /* bool; receive IP opts for response */
3401541Srgrimes#define	IP_RECVDSTADDR		7    /* bool; receive IP dst addr w/dgram */
3411541Srgrimes#define	IP_RETOPTS		8    /* ip_opts; set/get IP options */
3421541Srgrimes#define	IP_MULTICAST_IF		9    /* u_char; set/get IP multicast i/f  */
3431541Srgrimes#define	IP_MULTICAST_TTL	10   /* u_char; set/get IP multicast ttl */
3441541Srgrimes#define	IP_MULTICAST_LOOP	11   /* u_char; set/get IP multicast loopback */
3451541Srgrimes#define	IP_ADD_MEMBERSHIP	12   /* ip_mreq; add an IP group membership */
3461541Srgrimes#define	IP_DROP_MEMBERSHIP	13   /* ip_mreq; drop an IP group membership */
3472531Swollman#define IP_MULTICAST_VIF	14   /* set/get IP mcast virt. iface */
3482531Swollman#define IP_RSVP_ON		15   /* enable RSVP in kernel */
3492531Swollman#define IP_RSVP_OFF		16   /* disable RSVP in kernel */
3509209Swollman#define IP_RSVP_VIF_ON		17   /* set RSVP per-vif socket */
3519209Swollman#define IP_RSVP_VIF_OFF		18   /* unset RSVP per-vif socket */
35214195Speter#define IP_PORTRANGE		19   /* int; range to choose for unspec port */
35319622Sfenner#define	IP_RECVIF		20   /* bool; receive reception if w/dgram */
35452904Sshin/* for IPSEC */
35552904Sshin#define	IP_IPSEC_POLICY		21   /* int; set/get security policy */
35652904Sshin#define	IP_FAITH		22   /* bool; accept FAITH'ed connections */
3571541Srgrimes
35852904Sshin#define	IP_FW_ADD     		50   /* add a firewall rule to chain */
35952904Sshin#define	IP_FW_DEL    		51   /* delete a firewall rule from chain */
36052904Sshin#define	IP_FW_FLUSH   		52   /* flush firewall rule chain */
36152904Sshin#define	IP_FW_ZERO    		53   /* clear single/all firewall counter(s) */
36252904Sshin#define	IP_FW_GET     		54   /* get entire firewall rule chain */
36352904Sshin#define	IP_FW_RESETLOG		55   /* reset logging counters */
36417758Ssos
36541793Sluigi#define	IP_DUMMYNET_CONFIGURE	60   /* add/configure a dummynet pipe */
36641793Sluigi#define	IP_DUMMYNET_DEL		61   /* delete a dummynet pipe from chain */
36741793Sluigi#define	IP_DUMMYNET_FLUSH	62   /* flush dummynet */
36841793Sluigi#define	IP_DUMMYNET_GET		64   /* get entire dummynet pipes */
36941793Sluigi
3701541Srgrimes/*
3711541Srgrimes * Defaults and limits for options
3721541Srgrimes */
3731541Srgrimes#define	IP_DEFAULT_MULTICAST_TTL  1	/* normally limit m'casts to 1 hop  */
3741541Srgrimes#define	IP_DEFAULT_MULTICAST_LOOP 1	/* normally hear sends if a member  */
3759209Swollman#define	IP_MAX_MEMBERSHIPS	20	/* per socket */
3761541Srgrimes
3771541Srgrimes/*
3781541Srgrimes * Argument structure for IP_ADD_MEMBERSHIP and IP_DROP_MEMBERSHIP.
3791541Srgrimes */
3801541Srgrimesstruct ip_mreq {
3811541Srgrimes	struct	in_addr imr_multiaddr;	/* IP multicast address of group */
3821541Srgrimes	struct	in_addr imr_interface;	/* local IP address of interface */
3831541Srgrimes};
3841541Srgrimes
3851541Srgrimes/*
38614195Speter * Argument for IP_PORTRANGE:
38714195Speter * - which range to search when port is unspecified at bind() or connect()
38814195Speter */
38914195Speter#define	IP_PORTRANGE_DEFAULT	0	/* default range */
39014195Speter#define	IP_PORTRANGE_HIGH	1	/* "high" - request firewall bypass */
39114195Speter#define	IP_PORTRANGE_LOW	2	/* "low" - vouchsafe security */
39214195Speter
39314195Speter/*
3941541Srgrimes * Definitions for inet sysctl operations.
3951541Srgrimes *
3961541Srgrimes * Third level is protocol number.
3971541Srgrimes * Fourth level is desired variable within that protocol.
3981541Srgrimes */
39962587Sitojun#define	IPPROTO_MAXID	(IPPROTO_AH + 1)	/* don't list to IPPROTO_MAX */
4001541Srgrimes
4011541Srgrimes#define	CTL_IPPROTO_NAMES { \
4021541Srgrimes	{ "ip", CTLTYPE_NODE }, \
4031541Srgrimes	{ "icmp", CTLTYPE_NODE }, \
4041541Srgrimes	{ "igmp", CTLTYPE_NODE }, \
4051541Srgrimes	{ "ggp", CTLTYPE_NODE }, \
4061541Srgrimes	{ 0, 0 }, \
4071541Srgrimes	{ 0, 0 }, \
4081541Srgrimes	{ "tcp", CTLTYPE_NODE }, \
4091541Srgrimes	{ 0, 0 }, \
4101541Srgrimes	{ "egp", CTLTYPE_NODE }, \
4111541Srgrimes	{ 0, 0 }, \
4121541Srgrimes	{ 0, 0 }, \
4131541Srgrimes	{ 0, 0 }, \
4141541Srgrimes	{ "pup", CTLTYPE_NODE }, \
4151541Srgrimes	{ 0, 0 }, \
4161541Srgrimes	{ 0, 0 }, \
4171541Srgrimes	{ 0, 0 }, \
4181541Srgrimes	{ 0, 0 }, \
4191541Srgrimes	{ "udp", CTLTYPE_NODE }, \
4201541Srgrimes	{ 0, 0 }, \
4211541Srgrimes	{ 0, 0 }, \
4221541Srgrimes	{ 0, 0 }, \
4231541Srgrimes	{ 0, 0 }, \
4241541Srgrimes	{ "idp", CTLTYPE_NODE }, \
42562587Sitojun	{ 0, 0 }, \
42662587Sitojun	{ 0, 0 }, \
42762587Sitojun	{ 0, 0 }, \
42862587Sitojun	{ 0, 0 }, \
42962587Sitojun	{ 0, 0 }, \
43062587Sitojun	{ 0, 0 }, \
43162587Sitojun	{ 0, 0 }, \
43262587Sitojun	{ 0, 0 }, \
43362587Sitojun	{ 0, 0 }, \
43462587Sitojun	{ 0, 0 }, \
43562587Sitojun	{ 0, 0 }, \
43662587Sitojun	{ 0, 0 }, \
43762587Sitojun	{ 0, 0 }, \
43862587Sitojun	{ 0, 0 }, \
43962587Sitojun	{ 0, 0 }, \
44062587Sitojun	{ 0, 0 }, \
44162587Sitojun	{ 0, 0 }, \
44262587Sitojun	{ 0, 0 }, \
44362587Sitojun	{ 0, 0 }, \
44462587Sitojun	{ 0, 0 }, \
44562587Sitojun	{ 0, 0 }, \
44662587Sitojun	{ 0, 0 }, \
44762587Sitojun	{ 0, 0 }, \
44862587Sitojun	{ 0, 0 }, \
44962587Sitojun	{ 0, 0 }, \
45062587Sitojun	{ 0, 0 }, \
45162587Sitojun	{ 0, 0 }, \
45262587Sitojun	{ 0, 0 }, \
45362587Sitojun	{ "ipsec", CTLTYPE_NODE }, \
4541541Srgrimes}
4551541Srgrimes
4561541Srgrimes/*
4571541Srgrimes * Names for IP sysctl objects
4581541Srgrimes */
4591541Srgrimes#define	IPCTL_FORWARDING	1	/* act as router */
4601541Srgrimes#define	IPCTL_SENDREDIRECTS	2	/* may send redirects when forwarding */
4611541Srgrimes#define	IPCTL_DEFTTL		3	/* default TTL */
4621541Srgrimes#ifdef notyet
4631541Srgrimes#define	IPCTL_DEFMTU		4	/* default MTU */
4641541Srgrimes#endif
4655109Swollman#define IPCTL_RTEXPIRE		5	/* cloned route expiration time */
4666399Swollman#define IPCTL_RTMINEXPIRE	6	/* min value for expiration time */
4676399Swollman#define IPCTL_RTMAXCACHE	7	/* trigger level for dynamic expire */
4687091Swollman#define	IPCTL_SOURCEROUTE	8	/* may perform source routes */
4699575Speter#define	IPCTL_DIRECTEDBROADCAST	9	/* may re-broadcast received packets */
47012003Swollman#define IPCTL_INTRQMAXLEN	10	/* max length of netisr queue */
47152904Sshin#define	IPCTL_INTRQDROPS	11	/* number of netisr q drops */
47229838Swollman#define	IPCTL_STATS		12	/* ipstat structure */
47333440Sguido#define	IPCTL_ACCEPTSOURCEROUTE	13	/* may accept source routed packets */
47452904Sshin#define	IPCTL_FASTFORWARDING	14	/* use fast IP forwarding code */
47555009Sshin#define	IPCTL_KEEPFAITH		15	/* FAITH IPv4->IPv6 translater ctl */
47652904Sshin#define	IPCTL_GIF_TTL		16	/* default TTL for gif encap packet */
47752904Sshin#define	IPCTL_MAXID		17
4781541Srgrimes
4791541Srgrimes#define	IPCTL_NAMES { \
4801541Srgrimes	{ 0, 0 }, \
4811541Srgrimes	{ "forwarding", CTLTYPE_INT }, \
4821541Srgrimes	{ "redirect", CTLTYPE_INT }, \
4831541Srgrimes	{ "ttl", CTLTYPE_INT }, \
4841541Srgrimes	{ "mtu", CTLTYPE_INT }, \
4855109Swollman	{ "rtexpire", CTLTYPE_INT }, \
4866399Swollman	{ "rtminexpire", CTLTYPE_INT }, \
4876399Swollman	{ "rtmaxcache", CTLTYPE_INT }, \
4887091Swollman	{ "sourceroute", CTLTYPE_INT }, \
4899575Speter 	{ "directed-broadcast", CTLTYPE_INT }, \
49012003Swollman	{ "intr-queue-maxlen", CTLTYPE_INT }, \
49112003Swollman	{ "intr-queue-drops", CTLTYPE_INT }, \
49229838Swollman	{ "stats", CTLTYPE_STRUCT }, \
49333440Sguido	{ "accept_sourceroute", CTLTYPE_INT }, \
49436192Sdg	{ "fastforwarding", CTLTYPE_INT }, \
4951541Srgrimes}
4961541Srgrimes
49778243Speter#ifdef _KERNEL
49878243Speterstruct ifnet; struct mbuf;	/* forward declarations for Standard C */
49978243Speter#endif
50078243Speter
50152904Sshin/* INET6 stuff */
50257120Sshin#define	__KAME_NETINET_IN_H_INCLUDED_
50352904Sshin#include <netinet6/in6.h>
50457120Sshin#undef __KAME_NETINET_IN_H_INCLUDED_
5051541Srgrimes
50655205Speter#ifdef _KERNEL
5077088Swollman
50892723Salfredint	 in_broadcast(struct in_addr, struct ifnet *);
50992723Salfredint	 in_canforward(struct in_addr);
51092723Salfredint	 in_localaddr(struct in_addr);
51192723Salfredchar 	*inet_ntoa(struct in_addr); /* in libkern */
51292723Salfredchar	*inet_ntoa_r(struct in_addr ina, char *buf); /* in libkern */
5132169Spaul
51484101Sjlemon#define satosin(sa)	((struct sockaddr_in *)(sa))
51584101Sjlemon#define sintosa(sin)	((struct sockaddr *)(sin))
51684101Sjlemon#define ifatoia(ifa)	((struct in_ifaddr *)(ifa))
51784101Sjlemon
51890868Smike#else /* !_KERNEL */
51990868Smike
52091959Smike#ifndef _BYTEORDER_PROTOTYPED
52191959Smike#define	_BYTEORDER_PROTOTYPED
52291959Smike__BEGIN_DECLS
52393514Smikeuint32_t	htonl(uint32_t);
52493514Smikeuint16_t	htons(uint16_t);
52593514Smikeuint32_t	ntohl(uint32_t);
52693514Smikeuint16_t	ntohs(uint16_t);
52791959Smike__END_DECLS
52891959Smike#endif
52991959Smike
53090868Smike#ifndef _BYTEORDER_FUNC_DEFINED
53190868Smike#define	_BYTEORDER_FUNC_DEFINED
53290868Smike#define	htonl(x)	__htonl(x)
53390868Smike#define	htons(x)	__htons(x)
53490868Smike#define	ntohl(x)	__ntohl(x)
53590868Smike#define	ntohs(x)	__ntohs(x)
53655205Speter#endif
53715026Sphk
53890868Smike#endif /* _KERNEL */
53990868Smike
5402169Spaul#endif
541