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