home *** CD-ROM | disk | FTP | other *** search
/ H4CK3R 4 / hacker04 / 04_HACK04.ISO / darwin / darwinx86.iso / usr / include / sys / socketvar.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-09-30  |  14.7 KB  |  401 lines

  1. /*
  2.  * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
  3.  *
  4.  * @APPLE_LICENSE_HEADER_START@
  5.  * 
  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.
  11.  * 
  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
  18.  * under the License.
  19.  * 
  20.  * @APPLE_LICENSE_HEADER_END@
  21.  */
  22. /* Copyright (c) 1998, 1999 Apple Computer, Inc. All Rights Reserved */
  23. /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
  24. /*-
  25.  * Copyright (c) 1982, 1986, 1990, 1993
  26.  *    The Regents of the University of California.  All rights reserved.
  27.  *
  28.  * Redistribution and use in source and binary forms, with or without
  29.  * modification, are permitted provided that the following conditions
  30.  * are met:
  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.
  43.  *
  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
  54.  * SUCH DAMAGE.
  55.  *
  56.  *    @(#)socketvar.h    8.1 (Berkeley) 6/2/93
  57.  */
  58.  
  59. #ifndef    _SYS_SOCKETVAR_H_
  60. #define _SYS_SOCKETVAR_H_
  61.  
  62. #include <sys/select.h>            /* for struct selinfo */
  63. #include <sys/queue.h>
  64. #include <net/kext_net.h>
  65. #include <sys/ev.h>
  66. /*
  67.  * Hacks to get around compiler complaints
  68.  */
  69. struct mbuf;
  70. struct socket;
  71. struct uio;
  72. struct sockbuf;
  73. struct sockaddr;
  74. struct kextcb;
  75. struct protosw;
  76. struct sockif;
  77. struct sockutil;
  78.  
  79. /* strings for sleep message: */
  80. extern    char netio[], netcon[], netcls[];
  81. #define SOCKET_CACHE_ON    
  82. #define SO_CACHE_FLUSH_INTERVAL 1    /* Seconds */
  83. #define SO_CACHE_TIME_LIMIT    (120/SO_CACHE_FLUSH_INTERVAL) /* Seconds */
  84. #define SO_CACHE_MAX_FREE_BATCH    50
  85. #define MAX_CACHED_SOCKETS    60000
  86. #define TEMPDEBUG        0
  87.  
  88. /*
  89.  * Kernel structure per socket.
  90.  * Contains send and receive buffer queues,
  91.  * handle on protocol and pointer to protocol
  92.  * private data and error information.
  93.  */
  94. typedef    u_quad_t so_gen_t;
  95.  
  96. struct socket {
  97.     int     so_zone;    /* zone we were allocated from */
  98.     short    so_type;        /* generic type, see socket.h */
  99.     short    so_options;        /* from socket call, see socket.h */
  100.     short    so_linger;        /* time to linger while closing */
  101.     short    so_state;        /* internal state flags SS_*, below */
  102.     caddr_t    so_pcb;            /* protocol control block */
  103.     struct    protosw *so_proto;    /* protocol handle */
  104. /*
  105.  * Variables for connection queueing.
  106.  * Socket where accepts occur is so_head in all subsidiary sockets.
  107.  * If so_head is 0, socket is not related to an accept.
  108.  * For head socket so_q0 queues partially completed connections,
  109.  * while so_q is a queue of connections ready to be accepted.
  110.  * If a connection is aborted and it has so_head set, then
  111.  * it has to be pulled out of either so_q0 or so_q.
  112.  * We allow connections to queue up based on current queue lengths
  113.  * and limit on number of queued connections for this socket.
  114.  */
  115.     struct    socket *so_head;    /* back pointer to accept socket */
  116.     TAILQ_HEAD(, socket) so_incomp;    /* queue of partial unaccepted connections */
  117.     TAILQ_HEAD(, socket) so_comp;    /* queue of complete unaccepted connections */
  118.     TAILQ_ENTRY(socket) so_list;    /* list of unaccepted connections */
  119.     short    so_qlen;        /* number of unaccepted connections */
  120.     short    so_incqlen;        /* number of unaccepted incomplete
  121.                        connections */
  122.     short    so_qlimit;        /* max number queued connections */
  123.     short    so_timeo;        /* connection timeout */
  124.     u_short    so_error;        /* error affecting connection */
  125.     pid_t    so_pgid;        /* pgid for signals */
  126.     u_long    so_oobmark;        /* chars to oob mark */
  127. /*
  128.  * Variables for socket buffering.
  129.  */
  130.     struct    sockbuf {
  131.         u_long    sb_cc;        /* actual chars in buffer */
  132.         u_long    sb_hiwat;    /* max actual char count */
  133.         u_long    sb_mbcnt;    /* chars of mbufs used */
  134.         u_long    sb_mbmax;    /* max chars of mbufs to use */
  135.         long    sb_lowat;    /* low water mark */
  136.         struct    mbuf *sb_mb;    /* the mbuf chain */
  137.             struct  socket *sb_so;  /* socket back ptr */
  138.         struct    selinfo sb_sel;    /* process selecting read/write */
  139.         short    sb_flags;    /* flags, see below */
  140.         short    sb_timeo;    /* timeout for read/write */
  141.         void    *reserved1;    /* for future use if needed */
  142.         void    *reserved2;
  143.     } so_rcv, so_snd;
  144. #define    SB_MAX        (256*1024)    /* default for max chars in sockbuf */
  145. #define    SB_LOCK        0x01        /* lock on data queue */
  146. #define    SB_WANT        0x02        /* someone is waiting to lock */
  147. #define    SB_WAIT        0x04        /* someone is waiting for data/space */
  148. #define    SB_SEL        0x08        /* someone is selecting */
  149. #define    SB_ASYNC    0x10        /* ASYNC I/O, need signals */
  150. #define    SB_NOTIFY    (SB_WAIT|SB_SEL|SB_ASYNC)
  151. #define    SB_UPCALL    0x20        /* someone wants an upcall */
  152. #define    SB_NOINTR    0x40        /* operations not interruptible */
  153. #define SB_RECV        0x8000        /* this is rcv sb */
  154.  
  155.     caddr_t    so_tpcb;        /* Wisc. protocol control block XXX */
  156.     void    (*so_upcall) __P((struct socket *so, caddr_t arg, int waitf));
  157.     caddr_t    so_upcallarg;        /* Arg for above */
  158.     uid_t    so_uid;            /* who opened the socket */
  159.     /* NB: generation count must not be first; easiest to make it last. */
  160.     so_gen_t so_gencnt;        /* generation count */
  161.     TAILQ_HEAD(,eventqelt) so_evlist;
  162.     int    cached_in_sock_layer;    /* Is socket bundled with pcb/pcb.inp_ppcb? */
  163.     struct    socket    *cache_next;
  164.     struct    socket    *cache_prev;
  165.     u_long        cache_timestamp;
  166.     caddr_t        so_saved_pcb;    /* Saved pcb when cacheing */
  167.     struct    mbuf *so_temp;        /* Holding area for outbound frags */
  168.     /* Plug-in support - make the socket interface overridable */
  169.     struct    mbuf *so_tail;
  170.     struct    kextcb *so_ext;        /* NKE hook */
  171.     void    *reserved1;        /* for future use if needed */
  172.     void    *reserved2;
  173.     void    *reserved3;
  174.     void    *reserved4;
  175. };
  176.  
  177. /*
  178.  * Socket state bits.
  179.  */
  180. #define    SS_NOFDREF        0x001    /* no file table ref any more */
  181. #define    SS_ISCONNECTED        0x002    /* socket connected to a peer */
  182. #define    SS_ISCONNECTING        0x004    /* in process of connecting to peer */
  183. #define    SS_ISDISCONNECTING    0x008    /* in process of disconnecting */
  184. #define    SS_CANTSENDMORE        0x010    /* can't send more data to peer */
  185. #define    SS_CANTRCVMORE        0x020    /* can't receive more data from peer */
  186. #define    SS_RCVATMARK        0x040    /* at mark on input */
  187.  
  188. #define    SS_PRIV            0x080    /* privileged for broadcast, raw... */
  189. #define    SS_NBIO            0x100    /* non-blocking ops */
  190. #define    SS_ASYNC        0x200    /* async i/o notify */
  191. #define    SS_ISCONFIRMING        0x400    /* deciding to accept connection req */
  192. #define    SS_INCOMP        0x800    /* Unaccepted, incomplete connection */
  193. #define    SS_COMP            0x1000    /* unaccepted, complete connection */
  194.  
  195. /*
  196.  * Externalized form of struct socket used by the sysctl(3) interface.
  197.  */
  198. struct    xsocket {
  199.     size_t    xso_len;    /* length of this structure */
  200.     struct    socket *xso_so;    /* makes a convenient handle sometimes */
  201.     short    so_type;
  202.     short    so_options;
  203.     short    so_linger;
  204.     short    so_state;
  205.     caddr_t    so_pcb;        /* another convenient handle */
  206.     int    xso_protocol;
  207.     int    xso_family;
  208.     short    so_qlen;
  209.     short    so_incqlen;
  210.     short    so_qlimit;
  211.     short    so_timeo;
  212.     u_short    so_error;
  213.     pid_t    so_pgid;
  214.     u_long    so_oobmark;
  215.     struct    xsockbuf {
  216.         u_long    sb_cc;
  217.         u_long    sb_hiwat;
  218.         u_long    sb_mbcnt;
  219.         u_long    sb_mbmax;
  220.         long    sb_lowat;
  221.         short    sb_flags;
  222.         short    sb_timeo;
  223.     } so_rcv, so_snd;
  224.     uid_t    so_uid;        /* XXX */
  225. };
  226.  
  227. /*
  228.  * Macros for sockets and socket buffering.
  229.  */
  230. #define sbtoso(sb) (sb->sb_so)
  231.  
  232.  
  233. /*
  234.  * Socket extension mechanism: control block hooks:
  235.  * This is the "head" of any control block for an extenstion
  236.  * Note: we separate intercept function dispatch vectors from
  237.  *  the NFDescriptor to permit selective replacement during
  238.  *  operation, e.g., to disable some functions.
  239.  */
  240. struct kextcb
  241. {    struct kextcb *e_next;        /* Next kext control block */
  242.     void *e_fcb;            /* Real filter control block */
  243.     struct NFDescriptor *e_nfd;    /* NKE Descriptor */
  244.     /* Plug-in support - intercept functions */
  245.     struct sockif *e_soif;        /* Socket functions */
  246.     struct sockutil *e_sout;    /* Sockbuf utility functions */
  247. };
  248. #define EXT_NULL    0x0        /* STATE: Not in use */
  249. #define sotokextcb(so) (so ? so->so_ext : 0)
  250.  
  251. #ifdef KERNEL
  252. /*
  253.  * Argument structure for sosetopt et seq.  This is in the KERNEL
  254.  * section because it will never be visible to user code.
  255.  */
  256. enum sopt_dir { SOPT_GET, SOPT_SET };
  257. struct sockopt {
  258.     enum    sopt_dir sopt_dir; /* is this a get or a set? */
  259.     int    sopt_level;    /* second arg of [gs]etsockopt */
  260.     int    sopt_name;    /* third arg of [gs]etsockopt */
  261.     void   *sopt_val;    /* fourth arg of [gs]etsockopt */
  262.     size_t    sopt_valsize;    /* (almost) fifth arg of [gs]etsockopt */
  263.     struct    proc *sopt_p;    /* calling process or null if kernel */
  264. };
  265.  
  266. #if SENDFILE
  267.  
  268. struct sf_buf {
  269.     SLIST_ENTRY(sf_buf) free_list;    /* list of free buffer slots */
  270.     int        refcnt;        /* reference count */
  271.     struct        vm_page *m;    /* currently mapped page */
  272.     vm_offset_t    kva;        /* va of mapping */
  273. };
  274.  
  275. #endif
  276.  
  277. #ifdef MALLOC_DECLARE
  278. MALLOC_DECLARE(M_PCB);
  279. MALLOC_DECLARE(M_SONAME);
  280. #endif
  281.  
  282. extern int    maxsockets;
  283. extern u_long    sb_max;
  284. extern int socket_zone;
  285. extern so_gen_t so_gencnt;
  286.  
  287. struct file;
  288. struct filedesc;
  289. struct mbuf;
  290. struct sockaddr;
  291. struct stat;
  292. struct ucred;
  293. struct uio;
  294.  
  295. /*
  296.  * File operations on sockets.
  297.  */
  298. int    soo_read __P((struct file *fp, struct uio *uio, struct ucred *cred));
  299. int    soo_write __P((struct file *fp, struct uio *uio, struct ucred *cred));
  300. int    soo_ioctl __P((struct file *fp, u_long cmd, caddr_t data,
  301.         struct proc *p));
  302. int    soo_select __P((struct file *fp, int which, void * wql, struct proc *p));
  303. int    soo_stat __P((struct socket *so, struct stat *ub));
  304.  
  305. int     soo_close __P((struct file *fp, struct proc *p));
  306.  
  307.  
  308. /*
  309.  * From uipc_socket and friends
  310.  */
  311. struct    sockaddr *dup_sockaddr __P((struct sockaddr *sa, int canwait));
  312. int    getsock __P((struct filedesc *fdp, int fd, struct file **fpp));
  313. int    sockargs __P((struct mbuf **mp, caddr_t buf, int buflen, int type));
  314. int    getsockaddr __P((struct sockaddr **namp, caddr_t uaddr, size_t len));
  315. void    sbappend __P((struct sockbuf *sb, struct mbuf *m));
  316. int    sbappendaddr __P((struct sockbuf *sb, struct sockaddr *asa,
  317.         struct mbuf *m0, struct mbuf *control));
  318. int    sbappendcontrol __P((struct sockbuf *sb, struct mbuf *m0,
  319.         struct mbuf *control));
  320. void    sbappendrecord __P((struct sockbuf *sb, struct mbuf *m0));
  321. void    sbcheck __P((struct sockbuf *sb));
  322. void    sbcompress __P((struct sockbuf *sb, struct mbuf *m, struct mbuf *n));
  323. struct mbuf *
  324.     sbcreatecontrol __P((caddr_t p, int size, int type, int level));
  325. void    sbdrop __P((struct sockbuf *sb, int len));
  326. void    sbdroprecord __P((struct sockbuf *sb));
  327. void    sbflush __P((struct sockbuf *sb));
  328. void    sbinsertoob __P((struct sockbuf *sb, struct mbuf *m0));
  329. void    sbrelease __P((struct sockbuf *sb));
  330. int    sbreserve __P((struct sockbuf *sb, u_long cc));
  331. void    sbtoxsockbuf __P((struct sockbuf *sb, struct xsockbuf *xsb));
  332. int    sbwait __P((struct sockbuf *sb));
  333. int    sb_lock __P((struct sockbuf *sb));
  334. int    soabort __P((struct socket *so));
  335. int    soaccept __P((struct socket *so, struct sockaddr **nam));
  336. struct    socket *soalloc __P((int waitok, int dom, int type));
  337. int    sobind __P((struct socket *so, struct sockaddr *nam));
  338. void    socantrcvmore __P((struct socket *so));
  339. void    socantsendmore __P((struct socket *so));
  340. int    soclose __P((struct socket *so));
  341. int    soconnect __P((struct socket *so, struct sockaddr *nam));
  342. int    soconnect2 __P((struct socket *so1, struct socket *so2));
  343. int    socreate __P((int dom, struct socket **aso, int type, int proto));
  344. void    sodealloc __P((struct socket *so));
  345. int    sodisconnect __P((struct socket *so));
  346. void    sofree __P((struct socket *so));
  347. int    sogetopt __P((struct socket *so, struct sockopt *sopt));
  348. void    sohasoutofband __P((struct socket *so));
  349. void    soisconnected __P((struct socket *so));
  350. void    soisconnecting __P((struct socket *so));
  351. void    soisdisconnected __P((struct socket *so));
  352. void    soisdisconnecting __P((struct socket *so));
  353. int    solisten __P((struct socket *so, int backlog));
  354. struct socket *
  355.     sodropablereq __P((struct socket *head));
  356. struct socket *
  357.     sonewconn __P((struct socket *head, int connstatus));
  358. int    sooptcopyin __P((struct sockopt *sopt, void *buf, size_t len,
  359.              size_t minlen));
  360. int    sooptcopyout __P((struct sockopt *sopt, void *buf, size_t len));
  361. int    sopoll __P((struct socket *so, int events, struct ucred *cred, void *wql));
  362. int    soreceive __P((struct socket *so, struct sockaddr **paddr,
  363.                struct uio *uio, struct mbuf **mp0,
  364.                struct mbuf **controlp, int *flagsp));
  365. int    soreserve __P((struct socket *so, u_long sndcc, u_long rcvcc));
  366. void    sorflush __P((struct socket *so));
  367. int    sosend __P((struct socket *so, struct sockaddr *addr, struct uio *uio,
  368.             struct mbuf *top, struct mbuf *control, int flags));
  369.  
  370. int    sosetopt __P((struct socket *so, struct sockopt *sopt));
  371.  
  372.  
  373. int    soshutdown __P((struct socket *so, int how));
  374. void    sotoxsocket __P((struct socket *so, struct xsocket *xso));
  375. void    sowakeup __P((struct socket *so, struct sockbuf *sb));
  376. int    sb_notify __P((struct sockbuf *sb));
  377. long    sbspace    __P((struct sockbuf *sb));
  378. int    sosendallatonce __P((struct socket *so));
  379. int    soreadable __P((struct socket *so));
  380. int    sowriteable __P((struct socket *so));
  381. void    sballoc __P((struct sockbuf *sb, struct mbuf *m));
  382. void    sbfree __P((struct sockbuf *sb, struct mbuf *m));
  383. int    sblock __P((struct sockbuf *sb, int wf));
  384. void    sbunlock __P((struct sockbuf *sb));
  385. void    sorwakeup __P((struct socket * so));
  386. void    sowwakeup __P((struct socket * so));
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393.  
  394.  
  395.  
  396.  
  397.  
  398.  
  399. #endif /* KERNEL */
  400. #endif /* !_SYS_SOCKETVAR_H_ */
  401.