]> git.saurik.com Git - apple/xnu.git/blame - bsd/sys/socketvar.h
xnu-517.3.15.tar.gz
[apple/xnu.git] / bsd / sys / socketvar.h
CommitLineData
1c79356b 1/*
55e303ae 2 * Copyright (c) 2000-2003 Apple Computer, Inc. All rights reserved.
1c79356b
A
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
43866e37 6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
1c79356b 7 *
43866e37
A
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
1c79356b
A
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
43866e37
A
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
1c79356b
A
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25/* Copyright (c) 1998, 1999 Apple Computer, Inc. All Rights Reserved */
26/* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
27/*-
28 * Copyright (c) 1982, 1986, 1990, 1993
29 * The Regents of the University of California. All rights reserved.
30 *
31 * Redistribution and use in source and binary forms, with or without
32 * modification, are permitted provided that the following conditions
33 * are met:
34 * 1. Redistributions of source code must retain the above copyright
35 * notice, this list of conditions and the following disclaimer.
36 * 2. Redistributions in binary form must reproduce the above copyright
37 * notice, this list of conditions and the following disclaimer in the
38 * documentation and/or other materials provided with the distribution.
39 * 3. All advertising materials mentioning features or use of this software
40 * must display the following acknowledgement:
41 * This product includes software developed by the University of
42 * California, Berkeley and its contributors.
43 * 4. Neither the name of the University nor the names of its contributors
44 * may be used to endorse or promote products derived from this software
45 * without specific prior written permission.
46 *
47 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
48 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
49 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
50 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
51 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
52 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
53 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
54 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
55 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
56 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
57 * SUCH DAMAGE.
58 *
9bccf70c
A
59 * @(#)socketvar.h 8.3 (Berkeley) 2/19/95
60 * $FreeBSD: src/sys/sys/socketvar.h,v 1.46.2.6 2001/08/31 13:45:49 jlemon Exp $
1c79356b
A
61 */
62
9bccf70c 63#ifndef _SYS_SOCKETVAR_H_
1c79356b
A
64#define _SYS_SOCKETVAR_H_
65
9bccf70c
A
66#include <sys/appleapiopts.h>
67#include <sys/queue.h> /* for TAILQ macros */
1c79356b 68#include <sys/select.h> /* for struct selinfo */
1c79356b
A
69#include <net/kext_net.h>
70#include <sys/ev.h>
71/*
72 * Hacks to get around compiler complaints
73 */
74struct mbuf;
1c79356b
A
75struct kextcb;
76struct protosw;
77struct sockif;
78struct sockutil;
79
80/* strings for sleep message: */
9bccf70c 81#ifdef __APPLE_API_UNSTABLE
1c79356b
A
82extern char netio[], netcon[], netcls[];
83#define SOCKET_CACHE_ON
84#define SO_CACHE_FLUSH_INTERVAL 1 /* Seconds */
85#define SO_CACHE_TIME_LIMIT (120/SO_CACHE_FLUSH_INTERVAL) /* Seconds */
86#define SO_CACHE_MAX_FREE_BATCH 50
87#define MAX_CACHED_SOCKETS 60000
88#define TEMPDEBUG 0
89
90/*
91 * Kernel structure per socket.
92 * Contains send and receive buffer queues,
93 * handle on protocol and pointer to protocol
94 * private data and error information.
95 */
96typedef u_quad_t so_gen_t;
97
9bccf70c
A
98#ifndef __APPLE__
99/* We don't support BSD style socket filters */
100struct accept_filter;
101#endif
102
1c79356b 103struct socket {
9bccf70c
A
104 int so_zone; /* zone we were allocated from */
105 short so_type; /* generic type, see socket.h */
1c79356b
A
106 short so_options; /* from socket call, see socket.h */
107 short so_linger; /* time to linger while closing */
9bccf70c 108 short so_state; /* internal state flags SS_*, below */
1c79356b
A
109 caddr_t so_pcb; /* protocol control block */
110 struct protosw *so_proto; /* protocol handle */
111/*
9bccf70c 112 * Variables for connection queuing.
1c79356b
A
113 * Socket where accepts occur is so_head in all subsidiary sockets.
114 * If so_head is 0, socket is not related to an accept.
9bccf70c
A
115 * For head socket so_incomp queues partially completed connections,
116 * while so_comp is a queue of connections ready to be accepted.
1c79356b 117 * If a connection is aborted and it has so_head set, then
9bccf70c 118 * it has to be pulled out of either so_incomp or so_comp.
1c79356b
A
119 * We allow connections to queue up based on current queue lengths
120 * and limit on number of queued connections for this socket.
121 */
122 struct socket *so_head; /* back pointer to accept socket */
123 TAILQ_HEAD(, socket) so_incomp; /* queue of partial unaccepted connections */
124 TAILQ_HEAD(, socket) so_comp; /* queue of complete unaccepted connections */
125 TAILQ_ENTRY(socket) so_list; /* list of unaccepted connections */
126 short so_qlen; /* number of unaccepted connections */
127 short so_incqlen; /* number of unaccepted incomplete
128 connections */
129 short so_qlimit; /* max number queued connections */
130 short so_timeo; /* connection timeout */
131 u_short so_error; /* error affecting connection */
132 pid_t so_pgid; /* pgid for signals */
133 u_long so_oobmark; /* chars to oob mark */
9bccf70c
A
134#ifndef __APPLE__
135 /* We don't support AIO ops */
136 TAILQ_HEAD(, aiocblist) so_aiojobq; /* AIO ops waiting on socket */
137#endif
1c79356b
A
138/*
139 * Variables for socket buffering.
140 */
141 struct sockbuf {
142 u_long sb_cc; /* actual chars in buffer */
143 u_long sb_hiwat; /* max actual char count */
144 u_long sb_mbcnt; /* chars of mbufs used */
145 u_long sb_mbmax; /* max chars of mbufs to use */
146 long sb_lowat; /* low water mark */
147 struct mbuf *sb_mb; /* the mbuf chain */
9bccf70c
A
148#if __APPLE__
149 struct socket *sb_so; /* socket back ptr for kexts */
150#endif
1c79356b
A
151 struct selinfo sb_sel; /* process selecting read/write */
152 short sb_flags; /* flags, see below */
153 short sb_timeo; /* timeout for read/write */
0b4e3aa0
A
154 void *reserved1; /* for future use if needed */
155 void *reserved2;
1c79356b
A
156 } so_rcv, so_snd;
157#define SB_MAX (256*1024) /* default for max chars in sockbuf */
158#define SB_LOCK 0x01 /* lock on data queue */
159#define SB_WANT 0x02 /* someone is waiting to lock */
160#define SB_WAIT 0x04 /* someone is waiting for data/space */
0b4e3aa0 161#define SB_SEL 0x08 /* someone is selecting */
9bccf70c
A
162#define SB_ASYNC 0x10 /* ASYNC I/O, need signals */
163#define SB_UPCALL 0x20 /* someone wants an upcall */
164#define SB_NOINTR 0x40 /* operations not interruptible */
55e303ae 165#define SB_KNOTE 0x100 /* kernel note attached */
9bccf70c
A
166#ifndef __APPLE__
167#define SB_AIO 0x80 /* AIO operations queued */
9bccf70c 168#else
0b4e3aa0 169#define SB_NOTIFY (SB_WAIT|SB_SEL|SB_ASYNC)
1c79356b
A
170#define SB_RECV 0x8000 /* this is rcv sb */
171
9bccf70c
A
172 caddr_t so_tpcb; /* Wisc. protocol control block - XXX unused? */
173#endif
174
1c79356b
A
175 void (*so_upcall) __P((struct socket *so, caddr_t arg, int waitf));
176 caddr_t so_upcallarg; /* Arg for above */
177 uid_t so_uid; /* who opened the socket */
178 /* NB: generation count must not be first; easiest to make it last. */
179 so_gen_t so_gencnt; /* generation count */
9bccf70c
A
180#ifndef __APPLE__
181 void *so_emuldata; /* private data for emulators */
182 struct so_accf {
183 struct accept_filter *so_accept_filter;
184 void *so_accept_filter_arg; /* saved filter args */
185 char *so_accept_filter_str; /* saved user args */
186 } *so_accf;
187#else
1c79356b
A
188 TAILQ_HEAD(,eventqelt) so_evlist;
189 int cached_in_sock_layer; /* Is socket bundled with pcb/pcb.inp_ppcb? */
190 struct socket *cache_next;
191 struct socket *cache_prev;
192 u_long cache_timestamp;
193 caddr_t so_saved_pcb; /* Saved pcb when cacheing */
194 struct mbuf *so_temp; /* Holding area for outbound frags */
195 /* Plug-in support - make the socket interface overridable */
196 struct mbuf *so_tail;
197 struct kextcb *so_ext; /* NKE hook */
9bccf70c
A
198 u_long so_flags; /* Flags */
199#define SOF_NOSIGPIPE 0x00000001
55e303ae 200#define SOF_NOADDRAVAIL 0x00000002 /* returns EADDRNOTAVAIL if src address is gone */
0b4e3aa0
A
201 void *reserved2;
202 void *reserved3;
203 void *reserved4;
9bccf70c 204#endif
1c79356b 205};
9bccf70c 206#endif /* __APPLE_API_UNSTABLE */
1c79356b
A
207
208/*
209 * Socket state bits.
210 */
211#define SS_NOFDREF 0x001 /* no file table ref any more */
212#define SS_ISCONNECTED 0x002 /* socket connected to a peer */
213#define SS_ISCONNECTING 0x004 /* in process of connecting to peer */
214#define SS_ISDISCONNECTING 0x008 /* in process of disconnecting */
215#define SS_CANTSENDMORE 0x010 /* can't send more data to peer */
216#define SS_CANTRCVMORE 0x020 /* can't receive more data from peer */
217#define SS_RCVATMARK 0x040 /* at mark on input */
218
219#define SS_PRIV 0x080 /* privileged for broadcast, raw... */
220#define SS_NBIO 0x100 /* non-blocking ops */
221#define SS_ASYNC 0x200 /* async i/o notify */
222#define SS_ISCONFIRMING 0x400 /* deciding to accept connection req */
223#define SS_INCOMP 0x800 /* Unaccepted, incomplete connection */
224#define SS_COMP 0x1000 /* unaccepted, complete connection */
9bccf70c 225#define SS_ISDISCONNECTED 0x2000 /* socket disconnected from peer */
1c79356b
A
226
227/*
228 * Externalized form of struct socket used by the sysctl(3) interface.
229 */
230struct xsocket {
231 size_t xso_len; /* length of this structure */
232 struct socket *xso_so; /* makes a convenient handle sometimes */
233 short so_type;
234 short so_options;
235 short so_linger;
236 short so_state;
237 caddr_t so_pcb; /* another convenient handle */
238 int xso_protocol;
239 int xso_family;
240 short so_qlen;
241 short so_incqlen;
242 short so_qlimit;
243 short so_timeo;
244 u_short so_error;
245 pid_t so_pgid;
246 u_long so_oobmark;
247 struct xsockbuf {
248 u_long sb_cc;
249 u_long sb_hiwat;
250 u_long sb_mbcnt;
251 u_long sb_mbmax;
252 long sb_lowat;
253 short sb_flags;
254 short sb_timeo;
255 } so_rcv, so_snd;
256 uid_t so_uid; /* XXX */
257};
258
259/*
260 * Macros for sockets and socket buffering.
261 */
9bccf70c
A
262#ifdef __APPLE__
263#ifdef __APPLE_API_UNSTABLE
1c79356b
A
264#define sbtoso(sb) (sb->sb_so)
265
9bccf70c
A
266/*
267 * Functions for sockets and socket buffering.
268 * These are macros on FreeBSD. On Darwin the
269 * implementation is in bsd/kern/uipc_socket2.c
270 */
271int sb_notify __P((struct sockbuf *sb));
272long sbspace __P((struct sockbuf *sb));
273int sosendallatonce __P((struct socket *so));
274int soreadable __P((struct socket *so));
275int sowriteable __P((struct socket *so));
276void sballoc __P((struct sockbuf *sb, struct mbuf *m));
277void sbfree __P((struct sockbuf *sb, struct mbuf *m));
278int sblock __P((struct sockbuf *sb, int wf));
279void sbunlock __P((struct sockbuf *sb));
280void sorwakeup __P((struct socket * so));
281void sowwakeup __P((struct socket * so));
1c79356b
A
282
283/*
284 * Socket extension mechanism: control block hooks:
285 * This is the "head" of any control block for an extenstion
286 * Note: we separate intercept function dispatch vectors from
287 * the NFDescriptor to permit selective replacement during
288 * operation, e.g., to disable some functions.
289 */
290struct kextcb
291{ struct kextcb *e_next; /* Next kext control block */
292 void *e_fcb; /* Real filter control block */
293 struct NFDescriptor *e_nfd; /* NKE Descriptor */
294 /* Plug-in support - intercept functions */
295 struct sockif *e_soif; /* Socket functions */
296 struct sockutil *e_sout; /* Sockbuf utility functions */
297};
298#define EXT_NULL 0x0 /* STATE: Not in use */
299#define sotokextcb(so) (so ? so->so_ext : 0)
9bccf70c 300#endif /* __APPLE___ */
1c79356b
A
301
302#ifdef KERNEL
9bccf70c 303
1c79356b
A
304/*
305 * Argument structure for sosetopt et seq. This is in the KERNEL
306 * section because it will never be visible to user code.
307 */
308enum sopt_dir { SOPT_GET, SOPT_SET };
309struct sockopt {
310 enum sopt_dir sopt_dir; /* is this a get or a set? */
311 int sopt_level; /* second arg of [gs]etsockopt */
312 int sopt_name; /* third arg of [gs]etsockopt */
313 void *sopt_val; /* fourth arg of [gs]etsockopt */
314 size_t sopt_valsize; /* (almost) fifth arg of [gs]etsockopt */
315 struct proc *sopt_p; /* calling process or null if kernel */
316};
317
318#if SENDFILE
1c79356b
A
319struct sf_buf {
320 SLIST_ENTRY(sf_buf) free_list; /* list of free buffer slots */
321 int refcnt; /* reference count */
322 struct vm_page *m; /* currently mapped page */
323 vm_offset_t kva; /* va of mapping */
324};
1c79356b
A
325#endif
326
327#ifdef MALLOC_DECLARE
328MALLOC_DECLARE(M_PCB);
329MALLOC_DECLARE(M_SONAME);
330#endif
331
332extern int maxsockets;
333extern u_long sb_max;
334extern int socket_zone;
335extern so_gen_t so_gencnt;
336
337struct file;
338struct filedesc;
339struct mbuf;
340struct sockaddr;
341struct stat;
342struct ucred;
343struct uio;
9bccf70c 344struct knote;
1c79356b
A
345
346/*
347 * File operations on sockets.
348 */
9bccf70c
A
349int soo_read __P((struct file *fp, struct uio *uio, struct ucred *cred,
350 int flags, struct proc *p));
351int soo_write __P((struct file *fp, struct uio *uio, struct ucred *cred,
352 int flags, struct proc *p));
353int soo_close __P((struct file *fp, struct proc *p));
1c79356b
A
354int soo_ioctl __P((struct file *fp, u_long cmd, caddr_t data,
355 struct proc *p));
1c79356b 356int soo_stat __P((struct socket *so, struct stat *ub));
9bccf70c 357int soo_select __P((struct file *fp, int which, void * wql, struct proc *p));
55e303ae
A
358int soo_kqfilter __P((struct file *fp, struct knote *kn, struct proc *p));
359
1c79356b
A
360
361/*
362 * From uipc_socket and friends
363 */
364struct sockaddr *dup_sockaddr __P((struct sockaddr *sa, int canwait));
365int getsock __P((struct filedesc *fdp, int fd, struct file **fpp));
366int sockargs __P((struct mbuf **mp, caddr_t buf, int buflen, int type));
367int getsockaddr __P((struct sockaddr **namp, caddr_t uaddr, size_t len));
368void sbappend __P((struct sockbuf *sb, struct mbuf *m));
369int sbappendaddr __P((struct sockbuf *sb, struct sockaddr *asa,
370 struct mbuf *m0, struct mbuf *control));
371int sbappendcontrol __P((struct sockbuf *sb, struct mbuf *m0,
372 struct mbuf *control));
373void sbappendrecord __P((struct sockbuf *sb, struct mbuf *m0));
374void sbcheck __P((struct sockbuf *sb));
375void sbcompress __P((struct sockbuf *sb, struct mbuf *m, struct mbuf *n));
376struct mbuf *
377 sbcreatecontrol __P((caddr_t p, int size, int type, int level));
378void sbdrop __P((struct sockbuf *sb, int len));
379void sbdroprecord __P((struct sockbuf *sb));
380void sbflush __P((struct sockbuf *sb));
381void sbinsertoob __P((struct sockbuf *sb, struct mbuf *m0));
382void sbrelease __P((struct sockbuf *sb));
383int sbreserve __P((struct sockbuf *sb, u_long cc));
384void sbtoxsockbuf __P((struct sockbuf *sb, struct xsockbuf *xsb));
385int sbwait __P((struct sockbuf *sb));
386int sb_lock __P((struct sockbuf *sb));
387int soabort __P((struct socket *so));
388int soaccept __P((struct socket *so, struct sockaddr **nam));
389struct socket *soalloc __P((int waitok, int dom, int type));
390int sobind __P((struct socket *so, struct sockaddr *nam));
391void socantrcvmore __P((struct socket *so));
392void socantsendmore __P((struct socket *so));
393int soclose __P((struct socket *so));
394int soconnect __P((struct socket *so, struct sockaddr *nam));
395int soconnect2 __P((struct socket *so1, struct socket *so2));
396int socreate __P((int dom, struct socket **aso, int type, int proto));
397void sodealloc __P((struct socket *so));
398int sodisconnect __P((struct socket *so));
399void sofree __P((struct socket *so));
400int sogetopt __P((struct socket *so, struct sockopt *sopt));
401void sohasoutofband __P((struct socket *so));
402void soisconnected __P((struct socket *so));
403void soisconnecting __P((struct socket *so));
404void soisdisconnected __P((struct socket *so));
405void soisdisconnecting __P((struct socket *so));
406int solisten __P((struct socket *so, int backlog));
407struct socket *
408 sodropablereq __P((struct socket *head));
409struct socket *
410 sonewconn __P((struct socket *head, int connstatus));
411int sooptcopyin __P((struct sockopt *sopt, void *buf, size_t len,
412 size_t minlen));
413int sooptcopyout __P((struct sockopt *sopt, void *buf, size_t len));
9bccf70c
A
414
415/*
416 * XXX; prepare mbuf for (__FreeBSD__ < 3) routines.
417 * Used primarily in IPSec and IPv6 code.
418 */
419int soopt_getm __P((struct sockopt *sopt, struct mbuf **mp));
420int soopt_mcopyin __P((struct sockopt *sopt, struct mbuf *m));
421int soopt_mcopyout __P((struct sockopt *sopt, struct mbuf *m));
422
0b4e3aa0 423int sopoll __P((struct socket *so, int events, struct ucred *cred, void *wql));
1c79356b
A
424int soreceive __P((struct socket *so, struct sockaddr **paddr,
425 struct uio *uio, struct mbuf **mp0,
426 struct mbuf **controlp, int *flagsp));
427int soreserve __P((struct socket *so, u_long sndcc, u_long rcvcc));
428void sorflush __P((struct socket *so));
429int sosend __P((struct socket *so, struct sockaddr *addr, struct uio *uio,
430 struct mbuf *top, struct mbuf *control, int flags));
431
432int sosetopt __P((struct socket *so, struct sockopt *sopt));
1c79356b
A
433int soshutdown __P((struct socket *so, int how));
434void sotoxsocket __P((struct socket *so, struct xsocket *xso));
435void sowakeup __P((struct socket *so, struct sockbuf *sb));
436
9bccf70c
A
437#ifndef __APPLE__
438/* accept filter functions */
439int accept_filt_add __P((struct accept_filter *filt));
440int accept_filt_del __P((char *name));
441struct accept_filter * accept_filt_get __P((char *name));
442#ifdef ACCEPT_FILTER_MOD
443int accept_filt_generic_mod_event __P((module_t mod, int event, void *data));
444SYSCTL_DECL(_net_inet_accf);
445#endif /* ACCEPT_FILTER_MOD */
446#endif /* !defined(__APPLE__) */
1c79356b
A
447
448#endif /* KERNEL */
9bccf70c
A
449#endif /* __APPLE_API_UNSTABLE */
450
1c79356b 451#endif /* !_SYS_SOCKETVAR_H_ */