xref: /illumos-gate/usr/src/boot/sys/sys/socket.h (revision 199767f8)
1*199767f8SToomas Soome /*-
2*199767f8SToomas Soome  * Copyright (c) 1982, 1985, 1986, 1988, 1993, 1994
3*199767f8SToomas Soome  *	The Regents of the University of California.  All rights reserved.
4*199767f8SToomas Soome  *
5*199767f8SToomas Soome  * Redistribution and use in source and binary forms, with or without
6*199767f8SToomas Soome  * modification, are permitted provided that the following conditions
7*199767f8SToomas Soome  * are met:
8*199767f8SToomas Soome  * 1. Redistributions of source code must retain the above copyright
9*199767f8SToomas Soome  *    notice, this list of conditions and the following disclaimer.
10*199767f8SToomas Soome  * 2. Redistributions in binary form must reproduce the above copyright
11*199767f8SToomas Soome  *    notice, this list of conditions and the following disclaimer in the
12*199767f8SToomas Soome  *    documentation and/or other materials provided with the distribution.
13*199767f8SToomas Soome  * 4. Neither the name of the University nor the names of its contributors
14*199767f8SToomas Soome  *    may be used to endorse or promote products derived from this software
15*199767f8SToomas Soome  *    without specific prior written permission.
16*199767f8SToomas Soome  *
27*199767f8SToomas Soome  * SUCH DAMAGE.
28*199767f8SToomas Soome  *
29*199767f8SToomas Soome  *	@(#)socket.h	8.4 (Berkeley) 2/21/94
30*199767f8SToomas Soome  * $FreeBSD$
31*199767f8SToomas Soome  */
32*199767f8SToomas Soome 
33*199767f8SToomas Soome #ifndef _SYS_SOCKET_H_
34*199767f8SToomas Soome #define	_SYS_SOCKET_H_
35*199767f8SToomas Soome 
36*199767f8SToomas Soome #include <sys/cdefs.h>
37*199767f8SToomas Soome #include <sys/_types.h>
38*199767f8SToomas Soome #include <sys/_iovec.h>
39*199767f8SToomas Soome #include <machine/_align.h>
40*199767f8SToomas Soome 
41*199767f8SToomas Soome /*
42*199767f8SToomas Soome  * Definitions related to sockets: types, address families, options.
43*199767f8SToomas Soome  */
44*199767f8SToomas Soome 
45*199767f8SToomas Soome /*
46*199767f8SToomas Soome  * Data types.
47*199767f8SToomas Soome  */
48*199767f8SToomas Soome #if __BSD_VISIBLE
49*199767f8SToomas Soome #ifndef _GID_T_DECLARED
50*199767f8SToomas Soome typedef	__gid_t		gid_t;
51*199767f8SToomas Soome #define	_GID_T_DECLARED
52*199767f8SToomas Soome #endif
53*199767f8SToomas Soome 
54*199767f8SToomas Soome #ifndef _OFF_T_DECLARED
55*199767f8SToomas Soome typedef	__off_t		off_t;
56*199767f8SToomas Soome #define	_OFF_T_DECLARED
57*199767f8SToomas Soome #endif
58*199767f8SToomas Soome 
59*199767f8SToomas Soome #ifndef _PID_T_DECLARED
60*199767f8SToomas Soome typedef	__pid_t		pid_t;
61*199767f8SToomas Soome #define	_PID_T_DECLARED
62*199767f8SToomas Soome #endif
63*199767f8SToomas Soome #endif
64*199767f8SToomas Soome 
65*199767f8SToomas Soome #ifndef _SA_FAMILY_T_DECLARED
66*199767f8SToomas Soome typedef	__sa_family_t	sa_family_t;
67*199767f8SToomas Soome #define	_SA_FAMILY_T_DECLARED
68*199767f8SToomas Soome #endif
69*199767f8SToomas Soome 
70*199767f8SToomas Soome #ifndef _SOCKLEN_T_DECLARED
71*199767f8SToomas Soome typedef	__socklen_t	socklen_t;
72*199767f8SToomas Soome #define	_SOCKLEN_T_DECLARED
73*199767f8SToomas Soome #endif
74*199767f8SToomas Soome 
75*199767f8SToomas Soome #ifndef _SSIZE_T_DECLARED
76*199767f8SToomas Soome typedef	__ssize_t	ssize_t;
77*199767f8SToomas Soome #define	_SSIZE_T_DECLARED
78*199767f8SToomas Soome #endif
79*199767f8SToomas Soome 
80*199767f8SToomas Soome #if __BSD_VISIBLE
81*199767f8SToomas Soome #ifndef _UID_T_DECLARED
82*199767f8SToomas Soome typedef	__uid_t		uid_t;
83*199767f8SToomas Soome #define	_UID_T_DECLARED
84*199767f8SToomas Soome #endif
85*199767f8SToomas Soome #endif
86*199767f8SToomas Soome 
87*199767f8SToomas Soome #ifndef _UINT32_T_DECLARED
88*199767f8SToomas Soome typedef	__uint32_t	uint32_t;
89*199767f8SToomas Soome #define	_UINT32_T_DECLARED
90*199767f8SToomas Soome #endif
91*199767f8SToomas Soome 
92*199767f8SToomas Soome #ifndef _UINTPTR_T_DECLARED
93*199767f8SToomas Soome typedef	__uintptr_t	uintptr_t;
94*199767f8SToomas Soome #define	_UINTPTR_T_DECLARED
95*199767f8SToomas Soome #endif
96*199767f8SToomas Soome 
97*199767f8SToomas Soome /*
98*199767f8SToomas Soome  * Types
99*199767f8SToomas Soome  */
100*199767f8SToomas Soome #define	SOCK_STREAM	1		/* stream socket */
101*199767f8SToomas Soome #define	SOCK_DGRAM	2		/* datagram socket */
102*199767f8SToomas Soome #define	SOCK_RAW	3		/* raw-protocol interface */
103*199767f8SToomas Soome #if __BSD_VISIBLE
104*199767f8SToomas Soome #define	SOCK_RDM	4		/* reliably-delivered message */
105*199767f8SToomas Soome #endif
106*199767f8SToomas Soome #define	SOCK_SEQPACKET	5		/* sequenced packet stream */
107*199767f8SToomas Soome 
108*199767f8SToomas Soome #if __BSD_VISIBLE
109*199767f8SToomas Soome /*
110*199767f8SToomas Soome  * Creation flags, OR'ed into socket() and socketpair() type argument.
111*199767f8SToomas Soome  */
112*199767f8SToomas Soome #define	SOCK_CLOEXEC	0x10000000
113*199767f8SToomas Soome #define	SOCK_NONBLOCK	0x20000000
114*199767f8SToomas Soome #endif
115*199767f8SToomas Soome 
116*199767f8SToomas Soome /*
117*199767f8SToomas Soome  * Option flags per-socket.
118*199767f8SToomas Soome  */
119*199767f8SToomas Soome #define	SO_DEBUG	0x0001		/* turn on debugging info recording */
120*199767f8SToomas Soome #define	SO_ACCEPTCONN	0x0002		/* socket has had listen() */
121*199767f8SToomas Soome #define	SO_REUSEADDR	0x0004		/* allow local address reuse */
122*199767f8SToomas Soome #define	SO_KEEPALIVE	0x0008		/* keep connections alive */
123*199767f8SToomas Soome #define	SO_DONTROUTE	0x0010		/* just use interface addresses */
124*199767f8SToomas Soome #define	SO_BROADCAST	0x0020		/* permit sending of broadcast msgs */
125*199767f8SToomas Soome #if __BSD_VISIBLE
126*199767f8SToomas Soome #define	SO_USELOOPBACK	0x0040		/* bypass hardware when possible */
127*199767f8SToomas Soome #endif
128*199767f8SToomas Soome #define	SO_LINGER	0x0080		/* linger on close if data present */
129*199767f8SToomas Soome #define	SO_OOBINLINE	0x0100		/* leave received OOB data in line */
130*199767f8SToomas Soome #if __BSD_VISIBLE
131*199767f8SToomas Soome #define	SO_REUSEPORT	0x0200		/* allow local address & port reuse */
132*199767f8SToomas Soome #define	SO_TIMESTAMP	0x0400		/* timestamp received dgram traffic */
133*199767f8SToomas Soome #define	SO_NOSIGPIPE	0x0800		/* no SIGPIPE from EPIPE */
134*199767f8SToomas Soome #define	SO_ACCEPTFILTER	0x1000		/* there is an accept filter */
135*199767f8SToomas Soome #define	SO_BINTIME	0x2000		/* timestamp received dgram traffic */
136*199767f8SToomas Soome #endif
137*199767f8SToomas Soome #define	SO_NO_OFFLOAD	0x4000		/* socket cannot be offloaded */
138*199767f8SToomas Soome #define	SO_NO_DDP	0x8000		/* disable direct data placement */
139*199767f8SToomas Soome 
140*199767f8SToomas Soome /*
141*199767f8SToomas Soome  * Additional options, not kept in so_options.
142*199767f8SToomas Soome  */
143*199767f8SToomas Soome #define	SO_SNDBUF	0x1001		/* send buffer size */
144*199767f8SToomas Soome #define	SO_RCVBUF	0x1002		/* receive buffer size */
145*199767f8SToomas Soome #define	SO_SNDLOWAT	0x1003		/* send low-water mark */
146*199767f8SToomas Soome #define	SO_RCVLOWAT	0x1004		/* receive low-water mark */
147*199767f8SToomas Soome #define	SO_SNDTIMEO	0x1005		/* send timeout */
148*199767f8SToomas Soome #define	SO_RCVTIMEO	0x1006		/* receive timeout */
149*199767f8SToomas Soome #define	SO_ERROR	0x1007		/* get error status and clear */
150*199767f8SToomas Soome #define	SO_TYPE		0x1008		/* get socket type */
151*199767f8SToomas Soome #if __BSD_VISIBLE
152*199767f8SToomas Soome #define	SO_LABEL	0x1009		/* socket's MAC label */
153*199767f8SToomas Soome #define	SO_PEERLABEL	0x1010		/* socket's peer's MAC label */
154*199767f8SToomas Soome #define	SO_LISTENQLIMIT	0x1011		/* socket's backlog limit */
155*199767f8SToomas Soome #define	SO_LISTENQLEN	0x1012		/* socket's complete queue length */
156*199767f8SToomas Soome #define	SO_LISTENINCQLEN	0x1013	/* socket's incomplete queue length */
157*199767f8SToomas Soome #define	SO_SETFIB	0x1014		/* use this FIB to route */
158*199767f8SToomas Soome #define	SO_USER_COOKIE	0x1015		/* user cookie (dummynet etc.) */
159*199767f8SToomas Soome #define	SO_PROTOCOL	0x1016		/* get socket protocol (Linux name) */
160*199767f8SToomas Soome #define	SO_PROTOTYPE	SO_PROTOCOL	/* alias for SO_PROTOCOL (SunOS name) */
161*199767f8SToomas Soome #endif
162*199767f8SToomas Soome 
163*199767f8SToomas Soome /*
164*199767f8SToomas Soome  * Space reserved for new socket options added by third-party vendors.
165*199767f8SToomas Soome  * This range applies to all socket option levels.  New socket options
166*199767f8SToomas Soome  * in FreeBSD should always use an option value less than SO_VENDOR.
167*199767f8SToomas Soome  */
168*199767f8SToomas Soome #if __BSD_VISIBLE
169*199767f8SToomas Soome #define	SO_VENDOR	0x80000000
170*199767f8SToomas Soome #endif
171*199767f8SToomas Soome 
172*199767f8SToomas Soome /*
173*199767f8SToomas Soome  * Structure used for manipulating linger option.
174*199767f8SToomas Soome  */
175*199767f8SToomas Soome struct linger {
176*199767f8SToomas Soome 	int	l_onoff;		/* option on/off */
177*199767f8SToomas Soome 	int	l_linger;		/* linger time */
178*199767f8SToomas Soome };
179*199767f8SToomas Soome 
180*199767f8SToomas Soome #if __BSD_VISIBLE
181*199767f8SToomas Soome struct accept_filter_arg {
182*199767f8SToomas Soome 	char	af_name[16];
183*199767f8SToomas Soome 	char	af_arg[256-16];
184*199767f8SToomas Soome };
185*199767f8SToomas Soome #endif
186*199767f8SToomas Soome 
187*199767f8SToomas Soome /*
188*199767f8SToomas Soome  * Level number for (get/set)sockopt() to apply to socket itself.
189*199767f8SToomas Soome  */
190*199767f8SToomas Soome #define	SOL_SOCKET	0xffff		/* options for socket level */
191*199767f8SToomas Soome 
192*199767f8SToomas Soome /*
193*199767f8SToomas Soome  * Address families.
194*199767f8SToomas Soome  */
195*199767f8SToomas Soome #define	AF_UNSPEC	0		/* unspecified */
196*199767f8SToomas Soome #if __BSD_VISIBLE
197*199767f8SToomas Soome #define	AF_LOCAL	AF_UNIX		/* local to host (pipes, portals) */
198*199767f8SToomas Soome #endif
199*199767f8SToomas Soome #define	AF_UNIX		1		/* standardized name for AF_LOCAL */
200*199767f8SToomas Soome #define	AF_INET		2		/* internetwork: UDP, TCP, etc. */
201*199767f8SToomas Soome #if __BSD_VISIBLE
202*199767f8SToomas Soome #define	AF_IMPLINK	3		/* arpanet imp addresses */
203*199767f8SToomas Soome #define	AF_PUP		4		/* pup protocols: e.g. BSP */
204*199767f8SToomas Soome #define	AF_CHAOS	5		/* mit CHAOS protocols */
205*199767f8SToomas Soome #define	AF_NETBIOS	6		/* SMB protocols */
206*199767f8SToomas Soome #define	AF_ISO		7		/* ISO protocols */
207*199767f8SToomas Soome #define	AF_OSI		AF_ISO
208*199767f8SToomas Soome #define	AF_ECMA		8		/* European computer manufacturers */
209*199767f8SToomas Soome #define	AF_DATAKIT	9		/* datakit protocols */
210*199767f8SToomas Soome #define	AF_CCITT	10		/* CCITT protocols, X.25 etc */
211*199767f8SToomas Soome #define	AF_SNA		11		/* IBM SNA */
212*199767f8SToomas Soome #define AF_DECnet	12		/* DECnet */
213*199767f8SToomas Soome #define AF_DLI		13		/* DEC Direct data link interface */
214*199767f8SToomas Soome #define AF_LAT		14		/* LAT */
215*199767f8SToomas Soome #define	AF_HYLINK	15		/* NSC Hyperchannel */
216*199767f8SToomas Soome #define	AF_APPLETALK	16		/* Apple Talk */
217*199767f8SToomas Soome #define	AF_ROUTE	17		/* Internal Routing Protocol */
218*199767f8SToomas Soome #define	AF_LINK		18		/* Link layer interface */
219*199767f8SToomas Soome #define	pseudo_AF_XTP	19		/* eXpress Transfer Protocol (no AF) */
220*199767f8SToomas Soome #define	AF_COIP		20		/* connection-oriented IP, aka ST II */
221*199767f8SToomas Soome #define	AF_CNT		21		/* Computer Network Technology */
222*199767f8SToomas Soome #define pseudo_AF_RTIP	22		/* Help Identify RTIP packets */
223*199767f8SToomas Soome #define	AF_IPX		23		/* Novell Internet Protocol */
224*199767f8SToomas Soome #define	AF_SIP		24		/* Simple Internet Protocol */
225*199767f8SToomas Soome #define	pseudo_AF_PIP	25		/* Help Identify PIP packets */
226*199767f8SToomas Soome #define	AF_ISDN		26		/* Integrated Services Digital Network*/
227*199767f8SToomas Soome #define	AF_E164		AF_ISDN		/* CCITT E.164 recommendation */
228*199767f8SToomas Soome #define	pseudo_AF_KEY	27		/* Internal key-management function */
229*199767f8SToomas Soome #endif
230*199767f8SToomas Soome #define	AF_INET6	28		/* IPv6 */
231*199767f8SToomas Soome #if __BSD_VISIBLE
232*199767f8SToomas Soome #define	AF_NATM		29		/* native ATM access */
233*199767f8SToomas Soome #define	AF_ATM		30		/* ATM */
234*199767f8SToomas Soome #define pseudo_AF_HDRCMPLT 31		/* Used by BPF to not rewrite headers
235*199767f8SToomas Soome 					 * in interface output routine
236*199767f8SToomas Soome 					 */
237*199767f8SToomas Soome #define	AF_NETGRAPH	32		/* Netgraph sockets */
238*199767f8SToomas Soome #define	AF_SLOW		33		/* 802.3ad slow protocol */
239*199767f8SToomas Soome #define	AF_SCLUSTER	34		/* Sitara cluster protocol */
240*199767f8SToomas Soome #define	AF_ARP		35
241*199767f8SToomas Soome #define	AF_BLUETOOTH	36		/* Bluetooth sockets */
242*199767f8SToomas Soome #define	AF_IEEE80211	37		/* IEEE 802.11 protocol */
243*199767f8SToomas Soome #define	AF_INET_SDP	40		/* OFED Socket Direct Protocol ipv4 */
244*199767f8SToomas Soome #define	AF_INET6_SDP	42		/* OFED Socket Direct Protocol ipv6 */
245*199767f8SToomas Soome #define	AF_MAX		42
246*199767f8SToomas Soome /*
247*199767f8SToomas Soome  * When allocating a new AF_ constant, please only allocate
248*199767f8SToomas Soome  * even numbered constants for FreeBSD until 134 as odd numbered AF_
249*199767f8SToomas Soome  * constants 39-133 are now reserved for vendors.
250*199767f8SToomas Soome  */
251*199767f8SToomas Soome #define AF_VENDOR00 39
252*199767f8SToomas Soome #define AF_VENDOR01 41
253*199767f8SToomas Soome #define AF_VENDOR02 43
254*199767f8SToomas Soome #define AF_VENDOR03 45
255*199767f8SToomas Soome #define AF_VENDOR04 47
256*199767f8SToomas Soome #define AF_VENDOR05 49
257*199767f8SToomas Soome #define AF_VENDOR06 51
258*199767f8SToomas Soome #define AF_VENDOR07 53
259*199767f8SToomas Soome #define AF_VENDOR08 55
260*199767f8SToomas Soome #define AF_VENDOR09 57
261*199767f8SToomas Soome #define AF_VENDOR10 59
262*199767f8SToomas Soome #define AF_VENDOR11 61
263*199767f8SToomas Soome #define AF_VENDOR12 63
264*199767f8SToomas Soome #define AF_VENDOR13 65
265*199767f8SToomas Soome #define AF_VENDOR14 67
266*199767f8SToomas Soome #define AF_VENDOR15 69
267*199767f8SToomas Soome #define AF_VENDOR16 71
268*199767f8SToomas Soome #define AF_VENDOR17 73
269*199767f8SToomas Soome #define AF_VENDOR18 75
270*199767f8SToomas Soome #define AF_VENDOR19 77
271*199767f8SToomas Soome #define AF_VENDOR20 79
272*199767f8SToomas Soome #define AF_VENDOR21 81
273*199767f8SToomas Soome #define AF_VENDOR22 83
274*199767f8SToomas Soome #define AF_VENDOR23 85
275*199767f8SToomas Soome #define AF_VENDOR24 87
276*199767f8SToomas Soome #define AF_VENDOR25 89
277*199767f8SToomas Soome #define AF_VENDOR26 91
278*199767f8SToomas Soome #define AF_VENDOR27 93
279*199767f8SToomas Soome #define AF_VENDOR28 95
280*199767f8SToomas Soome #define AF_VENDOR29 97
281*199767f8SToomas Soome #define AF_VENDOR30 99
282*199767f8SToomas Soome #define AF_VENDOR31 101
283*199767f8SToomas Soome #define AF_VENDOR32 103
284*199767f8SToomas Soome #define AF_VENDOR33 105
285*199767f8SToomas Soome #define AF_VENDOR34 107
286*199767f8SToomas Soome #define AF_VENDOR35 109
287*199767f8SToomas Soome #define AF_VENDOR36 111
288*199767f8SToomas Soome #define AF_VENDOR37 113
289*199767f8SToomas Soome #define AF_VENDOR38 115
290*199767f8SToomas Soome #define AF_VENDOR39 117
291*199767f8SToomas Soome #define AF_VENDOR40 119
292*199767f8SToomas Soome #define AF_VENDOR41 121
293*199767f8SToomas Soome #define AF_VENDOR42 123
294*199767f8SToomas Soome #define AF_VENDOR43 125
295*199767f8SToomas Soome #define AF_VENDOR44 127
296*199767f8SToomas Soome #define AF_VENDOR45 129
297*199767f8SToomas Soome #define AF_VENDOR46 131
298*199767f8SToomas Soome #define AF_VENDOR47 133
299*199767f8SToomas Soome #endif
300*199767f8SToomas Soome 
301*199767f8SToomas Soome /*
302*199767f8SToomas Soome  * Structure used by kernel to store most
303*199767f8SToomas Soome  * addresses.
304*199767f8SToomas Soome  */
305*199767f8SToomas Soome struct sockaddr {
306*199767f8SToomas Soome 	unsigned char	sa_len;		/* total length */
307*199767f8SToomas Soome 	sa_family_t	sa_family;	/* address family */
308*199767f8SToomas Soome 	char		sa_data[14];	/* actually longer; address value */
309*199767f8SToomas Soome };
310*199767f8SToomas Soome #if __BSD_VISIBLE
311*199767f8SToomas Soome #define	SOCK_MAXADDRLEN	255		/* longest possible addresses */
312*199767f8SToomas Soome 
313*199767f8SToomas Soome /*
314*199767f8SToomas Soome  * Structure used by kernel to pass protocol
315*199767f8SToomas Soome  * information in raw sockets.
316*199767f8SToomas Soome  */
317*199767f8SToomas Soome struct sockproto {
318*199767f8SToomas Soome 	unsigned short	sp_family;		/* address family */
319*199767f8SToomas Soome 	unsigned short	sp_protocol;		/* protocol */
320*199767f8SToomas Soome };
321*199767f8SToomas Soome #endif
322*199767f8SToomas Soome 
323*199767f8SToomas Soome #include <sys/_sockaddr_storage.h>
324*199767f8SToomas Soome 
325*199767f8SToomas Soome #if __BSD_VISIBLE
326*199767f8SToomas Soome /*
327*199767f8SToomas Soome  * Protocol families, same as address families for now.
328*199767f8SToomas Soome  */
329*199767f8SToomas Soome #define	PF_UNSPEC	AF_UNSPEC
330*199767f8SToomas Soome #define	PF_LOCAL	AF_LOCAL
331*199767f8SToomas Soome #define	PF_UNIX		PF_LOCAL	/* backward compatibility */
332*199767f8SToomas Soome #define	PF_INET		AF_INET
333*199767f8SToomas Soome #define	PF_IMPLINK	AF_IMPLINK
334*199767f8SToomas Soome #define	PF_PUP		AF_PUP
335*199767f8SToomas Soome #define	PF_CHAOS	AF_CHAOS
336*199767f8SToomas Soome #define	PF_NETBIOS	AF_NETBIOS
337*199767f8SToomas Soome #define	PF_ISO		AF_ISO
338*199767f8SToomas Soome #define	PF_OSI		AF_ISO
339*199767f8SToomas Soome #define	PF_ECMA		AF_ECMA
340*199767f8SToomas Soome #define	PF_DATAKIT	AF_DATAKIT
341*199767f8SToomas Soome #define	PF_CCITT	AF_CCITT
342*199767f8SToomas Soome #define	PF_SNA		AF_SNA
343*199767f8SToomas Soome #define PF_DECnet	AF_DECnet
344*199767f8SToomas Soome #define PF_DLI		AF_DLI
345*199767f8SToomas Soome #define PF_LAT		AF_LAT
346*199767f8SToomas Soome #define	PF_HYLINK	AF_HYLINK
347*199767f8SToomas Soome #define	PF_APPLETALK	AF_APPLETALK
348*199767f8SToomas Soome #define	PF_ROUTE	AF_ROUTE
349*199767f8SToomas Soome #define	PF_LINK		AF_LINK
350*199767f8SToomas Soome #define	PF_XTP		pseudo_AF_XTP	/* really just proto family, no AF */
351*199767f8SToomas Soome #define	PF_COIP		AF_COIP
352*199767f8SToomas Soome #define	PF_CNT		AF_CNT
353*199767f8SToomas Soome #define	PF_SIP		AF_SIP
354*199767f8SToomas Soome #define	PF_IPX		AF_IPX
355*199767f8SToomas Soome #define PF_RTIP		pseudo_AF_RTIP	/* same format as AF_INET */
356*199767f8SToomas Soome #define PF_PIP		pseudo_AF_PIP
357*199767f8SToomas Soome #define	PF_ISDN		AF_ISDN
358*199767f8SToomas Soome #define	PF_KEY		pseudo_AF_KEY
359*199767f8SToomas Soome #define	PF_INET6	AF_INET6
360*199767f8SToomas Soome #define	PF_NATM		AF_NATM
361*199767f8SToomas Soome #define	PF_ATM		AF_ATM
362*199767f8SToomas Soome #define	PF_NETGRAPH	AF_NETGRAPH
363*199767f8SToomas Soome #define	PF_SLOW		AF_SLOW
364*199767f8SToomas Soome #define PF_SCLUSTER	AF_SCLUSTER
365*199767f8SToomas Soome #define	PF_ARP		AF_ARP
366*199767f8SToomas Soome #define	PF_BLUETOOTH	AF_BLUETOOTH
367*199767f8SToomas Soome #define	PF_IEEE80211	AF_IEEE80211
368*199767f8SToomas Soome #define	PF_INET_SDP	AF_INET_SDP
369*199767f8SToomas Soome #define	PF_INET6_SDP	AF_INET6_SDP
370*199767f8SToomas Soome 
371*199767f8SToomas Soome #define	PF_MAX		AF_MAX
372*199767f8SToomas Soome 
373*199767f8SToomas Soome /*
374*199767f8SToomas Soome  * Definitions for network related sysctl, CTL_NET.
375*199767f8SToomas Soome  *
376*199767f8SToomas Soome  * Second level is protocol family.
377*199767f8SToomas Soome  * Third level is protocol number.
378*199767f8SToomas Soome  *
379*199767f8SToomas Soome  * Further levels are defined by the individual families.
380*199767f8SToomas Soome  */
381*199767f8SToomas Soome 
382*199767f8SToomas Soome /*
383*199767f8SToomas Soome  * PF_ROUTE - Routing table
384*199767f8SToomas Soome  *
385*199767f8SToomas Soome  * Three additional levels are defined:
386*199767f8SToomas Soome  *	Fourth: address family, 0 is wildcard
387*199767f8SToomas Soome  *	Fifth: type of info, defined below
388*199767f8SToomas Soome  *	Sixth: flag(s) to mask with for NET_RT_FLAGS
389*199767f8SToomas Soome  */
390*199767f8SToomas Soome #define NET_RT_DUMP	1		/* dump; may limit to a.f. */
391*199767f8SToomas Soome #define NET_RT_FLAGS	2		/* by flags, e.g. RESOLVING */
392*199767f8SToomas Soome #define NET_RT_IFLIST	3		/* survey interface list */
393*199767f8SToomas Soome #define	NET_RT_IFMALIST	4		/* return multicast address list */
394*199767f8SToomas Soome #define	NET_RT_IFLISTL	5		/* Survey interface list, using 'l'en
395*199767f8SToomas Soome 					 * versions of msghdr structs. */
396*199767f8SToomas Soome #endif /* __BSD_VISIBLE */
397*199767f8SToomas Soome 
398*199767f8SToomas Soome /*
399*199767f8SToomas Soome  * Maximum queue length specifiable by listen.
400*199767f8SToomas Soome  */
401*199767f8SToomas Soome #define	SOMAXCONN	128
402*199767f8SToomas Soome 
403*199767f8SToomas Soome /*
404*199767f8SToomas Soome  * Message header for recvmsg and sendmsg calls.
405*199767f8SToomas Soome  * Used value-result for recvmsg, value only for sendmsg.
406*199767f8SToomas Soome  */
407*199767f8SToomas Soome struct msghdr {
408*199767f8SToomas Soome 	void		*msg_name;		/* optional address */
409*199767f8SToomas Soome 	socklen_t	 msg_namelen;		/* size of address */
410*199767f8SToomas Soome 	struct iovec	*msg_iov;		/* scatter/gather array */
411*199767f8SToomas Soome 	int		 msg_iovlen;		/* # elements in msg_iov */
412*199767f8SToomas Soome 	void		*msg_control;		/* ancillary data, see below */
413*199767f8SToomas Soome 	socklen_t	 msg_controllen;	/* ancillary data buffer len */
414*199767f8SToomas Soome 	int		 msg_flags;		/* flags on received message */
415*199767f8SToomas Soome };
416*199767f8SToomas Soome 
417*199767f8SToomas Soome #define	MSG_OOB		0x1		/* process out-of-band data */
418*199767f8SToomas Soome #define	MSG_PEEK	0x2		/* peek at incoming message */
419*199767f8SToomas Soome #define	MSG_DONTROUTE	0x4		/* send without using routing tables */
420*199767f8SToomas Soome #define	MSG_EOR		0x8		/* data completes record */
421*199767f8SToomas Soome #define	MSG_TRUNC	0x10		/* data discarded before delivery */
422*199767f8SToomas Soome #define	MSG_CTRUNC	0x20		/* control data lost before delivery */
423*199767f8SToomas Soome #define	MSG_WAITALL	0x40		/* wait for full request or error */
424*199767f8SToomas Soome #if __POSIX_VISIBLE >= 200809
425*199767f8SToomas Soome #define	MSG_NOSIGNAL	0x20000		/* do not generate SIGPIPE on EOF */
426*199767f8SToomas Soome #endif
427*199767f8SToomas Soome #if __BSD_VISIBLE
428*199767f8SToomas Soome #define	MSG_DONTWAIT	0x80		/* this message should be nonblocking */
429*199767f8SToomas Soome #define	MSG_EOF		0x100		/* data completes connection */
430*199767f8SToomas Soome #define	MSG_NOTIFICATION 0x2000         /* SCTP notification */
431*199767f8SToomas Soome #define	MSG_NBIO	0x4000		/* FIONBIO mode, used by fifofs */
432*199767f8SToomas Soome #define	MSG_COMPAT      0x8000		/* used in sendit() */
433*199767f8SToomas Soome #define	MSG_CMSG_CLOEXEC 0x40000	/* make received fds close-on-exec */
434*199767f8SToomas Soome #define	MSG_WAITFORONE	0x80000		/* for recvmmsg() */
435*199767f8SToomas Soome #endif
436*199767f8SToomas Soome #ifdef _KERNEL
437*199767f8SToomas Soome #define	MSG_SOCALLBCK   0x10000		/* for use by socket callbacks - soreceive (TCP) */
438*199767f8SToomas Soome #endif
439*199767f8SToomas Soome 
440*199767f8SToomas Soome /*
441*199767f8SToomas Soome  * Header for ancillary data objects in msg_control buffer.
442*199767f8SToomas Soome  * Used for additional information with/about a datagram
443*199767f8SToomas Soome  * not expressible by flags.  The format is a sequence
444*199767f8SToomas Soome  * of message elements headed by cmsghdr structures.
445*199767f8SToomas Soome  */
446*199767f8SToomas Soome struct cmsghdr {
447*199767f8SToomas Soome 	socklen_t	cmsg_len;		/* data byte count, including hdr */
448*199767f8SToomas Soome 	int		cmsg_level;		/* originating protocol */
449*199767f8SToomas Soome 	int		cmsg_type;		/* protocol-specific type */
450*199767f8SToomas Soome /* followed by	u_char  cmsg_data[]; */
451*199767f8SToomas Soome };
452*199767f8SToomas Soome 
453*199767f8SToomas Soome #if __BSD_VISIBLE
454*199767f8SToomas Soome /*
455*199767f8SToomas Soome  * While we may have more groups than this, the cmsgcred struct must
456*199767f8SToomas Soome  * be able to fit in an mbuf and we have historically supported a
457*199767f8SToomas Soome  * maximum of 16 groups.
458*199767f8SToomas Soome */
459*199767f8SToomas Soome #define CMGROUP_MAX 16
460*199767f8SToomas Soome 
461*199767f8SToomas Soome /*
462*199767f8SToomas Soome  * Credentials structure, used to verify the identity of a peer
463*199767f8SToomas Soome  * process that has sent us a message. This is allocated by the
464*199767f8SToomas Soome  * peer process but filled in by the kernel. This prevents the
465*199767f8SToomas Soome  * peer from lying about its identity. (Note that cmcred_groups[0]
466*199767f8SToomas Soome  * is the effective GID.)
467*199767f8SToomas Soome  */
468*199767f8SToomas Soome struct cmsgcred {
469*199767f8SToomas Soome 	pid_t	cmcred_pid;		/* PID of sending process */
470*199767f8SToomas Soome 	uid_t	cmcred_uid;		/* real UID of sending process */
471*199767f8SToomas Soome 	uid_t	cmcred_euid;		/* effective UID of sending process */
472*199767f8SToomas Soome 	gid_t	cmcred_gid;		/* real GID of sending process */
473*199767f8SToomas Soome 	short	cmcred_ngroups;		/* number or groups */
474*199767f8SToomas Soome 	gid_t	cmcred_groups[CMGROUP_MAX];	/* groups */
475*199767f8SToomas Soome };
476*199767f8SToomas Soome 
477*199767f8SToomas Soome /*
478*199767f8SToomas Soome  * Socket credentials.
479*199767f8SToomas Soome  */
480*199767f8SToomas Soome struct sockcred {
481*199767f8SToomas Soome 	uid_t	sc_uid;			/* real user id */
482*199767f8SToomas Soome 	uid_t	sc_euid;		/* effective user id */
483*199767f8SToomas Soome 	gid_t	sc_gid;			/* real group id */
484*199767f8SToomas Soome 	gid_t	sc_egid;		/* effective group id */
485*199767f8SToomas Soome 	int	sc_ngroups;		/* number of supplemental groups */
486*199767f8SToomas Soome 	gid_t	sc_groups[1];		/* variable length */
487*199767f8SToomas Soome };
488*199767f8SToomas Soome 
489*199767f8SToomas Soome /*
490*199767f8SToomas Soome  * Compute size of a sockcred structure with groups.
491*199767f8SToomas Soome  */
492*199767f8SToomas Soome #define	SOCKCREDSIZE(ngrps) \
493*199767f8SToomas Soome 	(sizeof(struct sockcred) + (sizeof(gid_t) * ((ngrps) - 1)))
494*199767f8SToomas Soome 
495*199767f8SToomas Soome #endif /* __BSD_VISIBLE */
496*199767f8SToomas Soome 
497*199767f8SToomas Soome /* given pointer to struct cmsghdr, return pointer to data */
498*199767f8SToomas Soome #define	CMSG_DATA(cmsg)		((unsigned char *)(cmsg) + \
499*199767f8SToomas Soome 				 _ALIGN(sizeof(struct cmsghdr)))
500*199767f8SToomas Soome 
501*199767f8SToomas Soome /* given pointer to struct cmsghdr, return pointer to next cmsghdr */
502*199767f8SToomas Soome #define	CMSG_NXTHDR(mhdr, cmsg)	\
503*199767f8SToomas Soome 	((char *)(cmsg) == NULL ? CMSG_FIRSTHDR(mhdr) : \
504*199767f8SToomas Soome 	    ((char *)(cmsg) + _ALIGN(((struct cmsghdr *)(cmsg))->cmsg_len) + \
505*199767f8SToomas Soome 	  _ALIGN(sizeof(struct cmsghdr)) > \
506*199767f8SToomas Soome 	    (char *)(mhdr)->msg_control + (mhdr)->msg_controllen) ? \
507*199767f8SToomas Soome 	    (struct cmsghdr *)0 : \
508*199767f8SToomas Soome 	    (struct cmsghdr *)(void *)((char *)(cmsg) + \
509*199767f8SToomas Soome 	    _ALIGN(((struct cmsghdr *)(cmsg))->cmsg_len)))
510*199767f8SToomas Soome 
511*199767f8SToomas Soome /*
512*199767f8SToomas Soome  * RFC 2292 requires to check msg_controllen, in case that the kernel returns
513*199767f8SToomas Soome  * an empty list for some reasons.
514*199767f8SToomas Soome  */
515*199767f8SToomas Soome #define	CMSG_FIRSTHDR(mhdr) \
516*199767f8SToomas Soome 	((mhdr)->msg_controllen >= sizeof(struct cmsghdr) ? \
517*199767f8SToomas Soome 	 (struct cmsghdr *)(mhdr)->msg_control : \
518*199767f8SToomas Soome 	 (struct cmsghdr *)NULL)
519*199767f8SToomas Soome 
520*199767f8SToomas Soome #if __BSD_VISIBLE
521*199767f8SToomas Soome /* RFC 2292 additions */
522*199767f8SToomas Soome #define	CMSG_SPACE(l)		(_ALIGN(sizeof(struct cmsghdr)) + _ALIGN(l))
523*199767f8SToomas Soome #define	CMSG_LEN(l)		(_ALIGN(sizeof(struct cmsghdr)) + (l))
524*199767f8SToomas Soome #endif
525*199767f8SToomas Soome 
526*199767f8SToomas Soome #ifdef _KERNEL
527*199767f8SToomas Soome #define	CMSG_ALIGN(n)	_ALIGN(n)
528*199767f8SToomas Soome #endif
529*199767f8SToomas Soome 
530*199767f8SToomas Soome /* "Socket"-level control message types: */
531*199767f8SToomas Soome #define	SCM_RIGHTS	0x01		/* access rights (array of int) */
532*199767f8SToomas Soome #if __BSD_VISIBLE
533*199767f8SToomas Soome #define	SCM_TIMESTAMP	0x02		/* timestamp (struct timeval) */
534*199767f8SToomas Soome #define	SCM_CREDS	0x03		/* process creds (struct cmsgcred) */
535*199767f8SToomas Soome #define	SCM_BINTIME	0x04		/* timestamp (struct bintime) */
536*199767f8SToomas Soome #endif
537*199767f8SToomas Soome 
538*199767f8SToomas Soome #if __BSD_VISIBLE
539*199767f8SToomas Soome /*
540*199767f8SToomas Soome  * 4.3 compat sockaddr, move to compat file later
541*199767f8SToomas Soome  */
542*199767f8SToomas Soome struct osockaddr {
543*199767f8SToomas Soome 	unsigned short sa_family;	/* address family */
544*199767f8SToomas Soome 	char	sa_data[14];		/* up to 14 bytes of direct address */
545*199767f8SToomas Soome };
546*199767f8SToomas Soome 
547*199767f8SToomas Soome /*
548*199767f8SToomas Soome  * 4.3-compat message header (move to compat file later).
549*199767f8SToomas Soome  */
550*199767f8SToomas Soome struct omsghdr {
551*199767f8SToomas Soome 	char	*msg_name;		/* optional address */
552*199767f8SToomas Soome 	int	msg_namelen;		/* size of address */
553*199767f8SToomas Soome 	struct	iovec *msg_iov;		/* scatter/gather array */
554*199767f8SToomas Soome 	int	msg_iovlen;		/* # elements in msg_iov */
555*199767f8SToomas Soome 	char	*msg_accrights;		/* access rights sent/received */
556*199767f8SToomas Soome 	int	msg_accrightslen;
557*199767f8SToomas Soome };
558*199767f8SToomas Soome #endif
559*199767f8SToomas Soome 
560*199767f8SToomas Soome /*
561*199767f8SToomas Soome  * howto arguments for shutdown(2), specified by Posix.1g.
562*199767f8SToomas Soome  */
563*199767f8SToomas Soome #define	SHUT_RD		0		/* shut down the reading side */
564*199767f8SToomas Soome #define	SHUT_WR		1		/* shut down the writing side */
565*199767f8SToomas Soome #define	SHUT_RDWR	2		/* shut down both sides */
566*199767f8SToomas Soome 
567*199767f8SToomas Soome #if __BSD_VISIBLE
568*199767f8SToomas Soome /* for SCTP */
569*199767f8SToomas Soome /* we cheat and use the SHUT_XX defines for these */
570*199767f8SToomas Soome #define PRU_FLUSH_RD     SHUT_RD
571*199767f8SToomas Soome #define PRU_FLUSH_WR     SHUT_WR
572*199767f8SToomas Soome #define PRU_FLUSH_RDWR   SHUT_RDWR
573*199767f8SToomas Soome #endif
574*199767f8SToomas Soome 
575*199767f8SToomas Soome 
576*199767f8SToomas Soome #if __BSD_VISIBLE
577*199767f8SToomas Soome /*
578*199767f8SToomas Soome  * sendfile(2) header/trailer struct
579*199767f8SToomas Soome  */
580*199767f8SToomas Soome struct sf_hdtr {
581*199767f8SToomas Soome 	struct iovec *headers;	/* pointer to an array of header struct iovec's */
582*199767f8SToomas Soome 	int hdr_cnt;		/* number of header iovec's */
583*199767f8SToomas Soome 	struct iovec *trailers;	/* pointer to an array of trailer struct iovec's */
584*199767f8SToomas Soome 	int trl_cnt;		/* number of trailer iovec's */
585*199767f8SToomas Soome };
586*199767f8SToomas Soome 
587*199767f8SToomas Soome /*
588*199767f8SToomas Soome  * Sendfile-specific flag(s)
589*199767f8SToomas Soome  */
590*199767f8SToomas Soome #define	SF_NODISKIO     0x00000001
591*199767f8SToomas Soome #define	SF_MNOWAIT	0x00000002	/* obsolete */
592*199767f8SToomas Soome #define	SF_SYNC		0x00000004
593*199767f8SToomas Soome #define	SF_NOCACHE	0x00000010
594*199767f8SToomas Soome #define	SF_FLAGS(rh, flags)	(((rh) << 16) | (flags))
595*199767f8SToomas Soome 
596*199767f8SToomas Soome #ifdef _KERNEL
597*199767f8SToomas Soome #define	SFK_COMPAT	0x00000001
598*199767f8SToomas Soome #define	SF_READAHEAD(flags)	((flags) >> 16)
599*199767f8SToomas Soome #endif /* _KERNEL */
600*199767f8SToomas Soome 
601*199767f8SToomas Soome /*
602*199767f8SToomas Soome  * Sendmmsg/recvmmsg specific structure(s)
603*199767f8SToomas Soome  */
604*199767f8SToomas Soome struct mmsghdr {
605*199767f8SToomas Soome 	struct msghdr	msg_hdr;		/* message header */
606*199767f8SToomas Soome 	ssize_t		msg_len;		/* message length */
607*199767f8SToomas Soome };
608*199767f8SToomas Soome #endif /* __BSD_VISIBLE */
609*199767f8SToomas Soome 
610*199767f8SToomas Soome #ifndef	_KERNEL
611*199767f8SToomas Soome 
612*199767f8SToomas Soome #include <sys/cdefs.h>
613*199767f8SToomas Soome 
614*199767f8SToomas Soome __BEGIN_DECLS
615*199767f8SToomas Soome int	accept(int, struct sockaddr * __restrict, socklen_t * __restrict);
616*199767f8SToomas Soome int	bind(int, const struct sockaddr *, socklen_t);
617*199767f8SToomas Soome int	connect(int, const struct sockaddr *, socklen_t);
618*199767f8SToomas Soome #if __BSD_VISIBLE
619*199767f8SToomas Soome int	accept4(int, struct sockaddr * __restrict, socklen_t * __restrict, int);
620*199767f8SToomas Soome int	bindat(int, int, const struct sockaddr *, socklen_t);
621*199767f8SToomas Soome int	connectat(int, int, const struct sockaddr *, socklen_t);
622*199767f8SToomas Soome #endif
623*199767f8SToomas Soome int	getpeername(int, struct sockaddr * __restrict, socklen_t * __restrict);
624*199767f8SToomas Soome int	getsockname(int, struct sockaddr * __restrict, socklen_t * __restrict);
625*199767f8SToomas Soome int	getsockopt(int, int, int, void * __restrict, socklen_t * __restrict);
626*199767f8SToomas Soome int	listen(int, int);
627*199767f8SToomas Soome ssize_t	recv(int, void *, size_t, int);
628*199767f8SToomas Soome ssize_t	recvfrom(int, void *, size_t, int, struct sockaddr * __restrict, socklen_t * __restrict);
629*199767f8SToomas Soome ssize_t	recvmsg(int, struct msghdr *, int);
630*199767f8SToomas Soome #if __BSD_VISIBLE
631*199767f8SToomas Soome struct timespec;
632*199767f8SToomas Soome ssize_t	recvmmsg(int, struct mmsghdr * __restrict, size_t, int,
633*199767f8SToomas Soome     const struct timespec * __restrict);
634*199767f8SToomas Soome #endif
635*199767f8SToomas Soome ssize_t	send(int, const void *, size_t, int);
636*199767f8SToomas Soome ssize_t	sendto(int, const void *,
637*199767f8SToomas Soome 	    size_t, int, const struct sockaddr *, socklen_t);
638*199767f8SToomas Soome ssize_t	sendmsg(int, const struct msghdr *, int);
639*199767f8SToomas Soome #if __BSD_VISIBLE
640*199767f8SToomas Soome int	sendfile(int, int, off_t, size_t, struct sf_hdtr *, off_t *, int);
641*199767f8SToomas Soome ssize_t	sendmmsg(int, struct mmsghdr * __restrict, size_t, int);
642*199767f8SToomas Soome int	setfib(int);
643*199767f8SToomas Soome #endif
644*199767f8SToomas Soome int	setsockopt(int, int, int, const void *, socklen_t);
645*199767f8SToomas Soome int	shutdown(int, int);
646*199767f8SToomas Soome int	sockatmark(int);
647*199767f8SToomas Soome int	socket(int, int, int);
648*199767f8SToomas Soome int	socketpair(int, int, int, int *);
649*199767f8SToomas Soome __END_DECLS
650*199767f8SToomas Soome 
651*199767f8SToomas Soome #endif /* !_KERNEL */
652*199767f8SToomas Soome 
653*199767f8SToomas Soome #ifdef _KERNEL
654*199767f8SToomas Soome struct socket;
655*199767f8SToomas Soome 
656*199767f8SToomas Soome struct tcpcb *so_sototcpcb(struct socket *so);
657*199767f8SToomas Soome struct inpcb *so_sotoinpcb(struct socket *so);
658*199767f8SToomas Soome struct sockbuf *so_sockbuf_snd(struct socket *);
659*199767f8SToomas Soome struct sockbuf *so_sockbuf_rcv(struct socket *);
660*199767f8SToomas Soome 
661*199767f8SToomas Soome int so_state_get(const struct socket *);
662*199767f8SToomas Soome void so_state_set(struct socket *, int);
663*199767f8SToomas Soome 
664*199767f8SToomas Soome int so_options_get(const struct socket *);
665*199767f8SToomas Soome void so_options_set(struct socket *, int);
666*199767f8SToomas Soome 
667*199767f8SToomas Soome int so_error_get(const struct socket *);
668*199767f8SToomas Soome void so_error_set(struct socket *, int);
669*199767f8SToomas Soome 
670*199767f8SToomas Soome int so_linger_get(const struct socket *);
671*199767f8SToomas Soome void so_linger_set(struct socket *, int);
672*199767f8SToomas Soome 
673*199767f8SToomas Soome struct protosw *so_protosw_get(const struct socket *);
674*199767f8SToomas Soome void so_protosw_set(struct socket *, struct protosw *);
675*199767f8SToomas Soome 
676*199767f8SToomas Soome void so_sorwakeup_locked(struct socket *so);
677*199767f8SToomas Soome void so_sowwakeup_locked(struct socket *so);
678*199767f8SToomas Soome 
679*199767f8SToomas Soome void so_sorwakeup(struct socket *so);
680*199767f8SToomas Soome void so_sowwakeup(struct socket *so);
681*199767f8SToomas Soome 
682*199767f8SToomas Soome void so_lock(struct socket *so);
683*199767f8SToomas Soome void so_unlock(struct socket *so);
684*199767f8SToomas Soome 
685*199767f8SToomas Soome void so_listeners_apply_all(struct socket *so, void (*func)(struct socket *, void *), void *arg);
686*199767f8SToomas Soome 
687*199767f8SToomas Soome #endif
688*199767f8SToomas Soome 
689*199767f8SToomas Soome 
690*199767f8SToomas Soome #endif /* !_SYS_SOCKET_H_ */