The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/sys/socketvar.h

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*-
    2  * Copyright (c) 1982, 1986, 1990, 1993
    3  *      The Regents of the University of California.  All rights reserved.
    4  *
    5  * Redistribution and use in source and binary forms, with or without
    6  * modification, are permitted provided that the following conditions
    7  * are met:
    8  * 1. Redistributions of source code must retain the above copyright
    9  *    notice, this list of conditions and the following disclaimer.
   10  * 2. Redistributions in binary form must reproduce the above copyright
   11  *    notice, this list of conditions and the following disclaimer in the
   12  *    documentation and/or other materials provided with the distribution.
   13  * 3. All advertising materials mentioning features or use of this software
   14  *    must display the following acknowledgement:
   15  *      This product includes software developed by the University of
   16  *      California, Berkeley and its contributors.
   17  * 4. Neither the name of the University nor the names of its contributors
   18  *    may be used to endorse or promote products derived from this software
   19  *    without specific prior written permission.
   20  *
   21  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
   22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   31  * SUCH DAMAGE.
   32  *
   33  *      @(#)socketvar.h 8.3 (Berkeley) 2/19/95
   34  * $FreeBSD$
   35  */
   36 
   37 #ifndef _SYS_SOCKETVAR_H_
   38 #define _SYS_SOCKETVAR_H_
   39 
   40 #include <sys/queue.h>                  /* for TAILQ macros */
   41 #include <sys/select.h>                 /* for struct selinfo */
   42 
   43 /*
   44  * Kernel structure per socket.
   45  * Contains send and receive buffer queues,
   46  * handle on protocol and pointer to protocol
   47  * private data and error information.
   48  */
   49 typedef u_quad_t so_gen_t;
   50 
   51 struct accept_filter;
   52 
   53 struct socket {
   54         short   so_type;                /* generic type, see socket.h */
   55         short   so_options;             /* from socket call, see socket.h */
   56         short   so_linger;              /* time to linger while closing */
   57         short   so_state;               /* internal state flags SS_*, below */
   58         caddr_t so_pcb;                 /* protocol control block */
   59         struct  protosw *so_proto;      /* protocol handle */
   60 /*
   61  * Variables for connection queuing.
   62  * Socket where accepts occur is so_head in all subsidiary sockets.
   63  * If so_head is 0, socket is not related to an accept.
   64  * For head socket so_incomp queues partially completed connections,
   65  * while so_comp is a queue of connections ready to be accepted.
   66  * If a connection is aborted and it has so_head set, then
   67  * it has to be pulled out of either so_incomp or so_comp.
   68  * We allow connections to queue up based on current queue lengths
   69  * and limit on number of queued connections for this socket.
   70  */
   71         struct  socket *so_head;        /* back pointer to accept socket */
   72         TAILQ_HEAD(, socket) so_incomp; /* queue of partial unaccepted connections */
   73         TAILQ_HEAD(, socket) so_comp;   /* queue of complete unaccepted connections */
   74         TAILQ_ENTRY(socket) so_list;    /* list of unaccepted connections */
   75         short   so_qlen;                /* number of unaccepted connections */
   76         short   so_incqlen;             /* number of unaccepted incomplete
   77                                            connections */
   78         short   so_qlimit;              /* max number queued connections */
   79         short   so_timeo;               /* connection timeout */
   80         u_short so_error;               /* error affecting connection */
   81         struct  sigio *so_sigio;        /* information for async I/O or
   82                                            out of band data (SIGURG) */
   83         u_long  so_oobmark;             /* chars to oob mark */
   84         TAILQ_HEAD(, aiocblist) so_aiojobq; /* AIO ops waiting on socket */
   85 /*
   86  * Variables for socket buffering.
   87  */
   88         struct  sockbuf {
   89                 u_long  sb_cc;          /* actual chars in buffer */
   90                 u_long  sb_hiwat;       /* max actual char count */
   91                 u_long  sb_mbcnt;       /* chars of mbufs used */
   92                 u_long  sb_mbmax;       /* max chars of mbufs to use */
   93                 long    sb_lowat;       /* low water mark */
   94                 struct  mbuf *sb_mb;    /* the mbuf chain */
   95                 struct  mbuf *sb_mbtail; /* the last mbuf in the chain */
   96                 struct  mbuf *sb_lastrecord;    /* first mbuf of last record in
   97                                                  * socket buffer */
   98                 struct  selinfo sb_sel; /* process selecting read/write */
   99                 short   sb_flags;       /* flags, see below */
  100                 short   sb_timeo;       /* timeout for read/write */
  101         } so_rcv, so_snd;
  102 #define SB_MAX          (256*1024)      /* default for max chars in sockbuf */
  103 #define SB_LOCK         0x01            /* lock on data queue */
  104 #define SB_WANT         0x02            /* someone is waiting to lock */
  105 #define SB_WAIT         0x04            /* someone is waiting for data/space */
  106 #define SB_SEL          0x08            /* someone is selecting */
  107 #define SB_ASYNC        0x10            /* ASYNC I/O, need signals */
  108 #define SB_UPCALL       0x20            /* someone wants an upcall */
  109 #define SB_NOINTR       0x40            /* operations not interruptible */
  110 #define SB_AIO          0x80            /* AIO operations queued */
  111 #define SB_KNOTE        0x100           /* kernel note attached */
  112 
  113         void    (*so_upcall) __P((struct socket *, void *, int));
  114         void    *so_upcallarg;
  115         struct  ucred *so_cred;         /* user credentials */
  116         /* NB: generation count must not be first; easiest to make it last. */
  117         so_gen_t so_gencnt;             /* generation count */
  118         void    *so_emuldata;           /* private data for emulators */
  119         struct  so_accf { 
  120                 struct  accept_filter *so_accept_filter;
  121                 void    *so_accept_filter_arg;  /* saved filter args */
  122                 char    *so_accept_filter_str;  /* saved user args */
  123         } *so_accf;
  124 };
  125 
  126 #define SB_EMPTY_FIXUP(sb) do {                                         \
  127         if ((sb)->sb_mb == NULL) {                                      \
  128                 (sb)->sb_mbtail = NULL;                                 \
  129                 (sb)->sb_lastrecord = NULL;                             \
  130         }                                                               \
  131 } while (/*CONSTCOND*/0)
  132 
  133 /*
  134  * Socket state bits.
  135  */
  136 #define SS_NOFDREF              0x0001  /* no file table ref any more */
  137 #define SS_ISCONNECTED          0x0002  /* socket connected to a peer */
  138 #define SS_ISCONNECTING         0x0004  /* in process of connecting to peer */
  139 #define SS_ISDISCONNECTING      0x0008  /* in process of disconnecting */
  140 #define SS_CANTSENDMORE         0x0010  /* can't send more data to peer */
  141 #define SS_CANTRCVMORE          0x0020  /* can't receive more data from peer */
  142 #define SS_RCVATMARK            0x0040  /* at mark on input */
  143 
  144 #define SS_NBIO                 0x0100  /* non-blocking ops */
  145 #define SS_ASYNC                0x0200  /* async i/o notify */
  146 #define SS_ISCONFIRMING         0x0400  /* deciding to accept connection req */
  147 
  148 #define SS_INCOMP               0x0800  /* unaccepted, incomplete connection */
  149 #define SS_COMP                 0x1000  /* unaccepted, complete connection */
  150 #define SS_ISDISCONNECTED       0x2000  /* socket disconnected from peer */
  151 
  152 /*
  153  * Externalized form of struct socket used by the sysctl(3) interface.
  154  */
  155 struct  xsocket {
  156         size_t  xso_len;        /* length of this structure */
  157         struct  socket *xso_so; /* makes a convenient handle sometimes */
  158         short   so_type;
  159         short   so_options;
  160         short   so_linger;
  161         short   so_state;
  162         caddr_t so_pcb;         /* another convenient handle */
  163         int     xso_protocol;
  164         int     xso_family;
  165         short   so_qlen;
  166         short   so_incqlen;
  167         short   so_qlimit;
  168         short   so_timeo;
  169         u_short so_error;
  170         pid_t   so_pgid;
  171         u_long  so_oobmark;
  172         struct  xsockbuf {
  173                 u_long  sb_cc;
  174                 u_long  sb_hiwat;
  175                 u_long  sb_mbcnt;
  176                 u_long  sb_mbmax;
  177                 long    sb_lowat;
  178                 short   sb_flags;
  179                 short   sb_timeo;
  180         } so_rcv, so_snd;
  181         uid_t   so_uid;         /* XXX */
  182 };
  183 
  184 /*
  185  * Macros for sockets and socket buffering.
  186  */
  187 
  188 /*
  189  * Do we need to notify the other side when I/O is possible?
  190  */
  191 #define sb_notify(sb)   (((sb)->sb_flags & (SB_WAIT | SB_SEL | SB_ASYNC | \
  192     SB_UPCALL | SB_AIO | SB_KNOTE)) != 0)
  193 
  194 /*
  195  * How much space is there in a socket buffer (so->so_snd or so->so_rcv)?
  196  * This is problematical if the fields are unsigned, as the space might
  197  * still be negative (cc > hiwat or mbcnt > mbmax).  Should detect
  198  * overflow and return 0.  Should use "lmin" but it doesn't exist now.
  199  */
  200 #define sbspace(sb) \
  201     ((long) imin((int)((sb)->sb_hiwat - (sb)->sb_cc), \
  202          (int)((sb)->sb_mbmax - (sb)->sb_mbcnt)))
  203 
  204 /* do we have to send all at once on a socket? */
  205 #define sosendallatonce(so) \
  206     ((so)->so_proto->pr_flags & PR_ATOMIC)
  207 
  208 /* can we read something from so? */
  209 #define soreadable(so) \
  210     ((so)->so_rcv.sb_cc >= (so)->so_rcv.sb_lowat || \
  211         ((so)->so_state & SS_CANTRCVMORE) || \
  212         (so)->so_comp.tqh_first || (so)->so_error)
  213 
  214 /* can we write something to so? */
  215 #define sowriteable(so) \
  216     ((sbspace(&(so)->so_snd) >= (so)->so_snd.sb_lowat && \
  217         (((so)->so_state&SS_ISCONNECTED) || \
  218           ((so)->so_proto->pr_flags&PR_CONNREQUIRED)==0)) || \
  219      ((so)->so_state & SS_CANTSENDMORE) || \
  220      (so)->so_error)
  221 
  222 /* adjust counters in sb reflecting allocation of m */
  223 #define sballoc(sb, m) { \
  224         (sb)->sb_cc += (m)->m_len; \
  225         (sb)->sb_mbcnt += MSIZE; \
  226         if ((m)->m_flags & M_EXT) \
  227                 (sb)->sb_mbcnt += (m)->m_ext.ext_size; \
  228 }
  229 
  230 /* adjust counters in sb reflecting freeing of m */
  231 #define sbfree(sb, m) { \
  232         (sb)->sb_cc -= (m)->m_len; \
  233         (sb)->sb_mbcnt -= MSIZE; \
  234         if ((m)->m_flags & M_EXT) \
  235                 (sb)->sb_mbcnt -= (m)->m_ext.ext_size; \
  236 }
  237 
  238 /*
  239  * Set lock on sockbuf sb; sleep if lock is already held.
  240  * Unless SB_NOINTR is set on sockbuf, sleep is interruptible.
  241  * Returns error without lock if sleep is interrupted.
  242  */
  243 #define sblock(sb, wf) ((sb)->sb_flags & SB_LOCK ? \
  244                 (((wf) == M_WAITOK) ? sb_lock(sb) : EWOULDBLOCK) : \
  245                 ((sb)->sb_flags |= SB_LOCK), 0)
  246 
  247 /* release lock on sockbuf sb */
  248 #define sbunlock(sb) { \
  249         (sb)->sb_flags &= ~SB_LOCK; \
  250         if ((sb)->sb_flags & SB_WANT) { \
  251                 (sb)->sb_flags &= ~SB_WANT; \
  252                 wakeup((caddr_t)&(sb)->sb_flags); \
  253         } \
  254 }
  255 
  256 #define sorwakeup(so)   do { \
  257                           if (sb_notify(&(so)->so_rcv)) \
  258                             sowakeup((so), &(so)->so_rcv); \
  259                         } while (0)
  260 
  261 #define sowwakeup(so)   do { \
  262                           if (sb_notify(&(so)->so_snd)) \
  263                             sowakeup((so), &(so)->so_snd); \
  264                         } while (0)
  265 
  266 #ifdef _KERNEL
  267 
  268 /*
  269  * Argument structure for sosetopt et seq.  This is in the KERNEL
  270  * section because it will never be visible to user code.
  271  */
  272 enum sopt_dir { SOPT_GET, SOPT_SET };
  273 struct sockopt {
  274         enum    sopt_dir sopt_dir; /* is this a get or a set? */
  275         int     sopt_level;     /* second arg of [gs]etsockopt */
  276         int     sopt_name;      /* third arg of [gs]etsockopt */
  277         void   *sopt_val;       /* fourth arg of [gs]etsockopt */
  278         size_t  sopt_valsize;   /* (almost) fifth arg of [gs]etsockopt */
  279         struct  proc *sopt_p;   /* calling process or null if kernel */
  280 };
  281 
  282 struct sf_buf {
  283         SLIST_ENTRY(sf_buf) free_list;  /* list of free buffer slots */
  284         int             refcnt;         /* reference count */
  285         struct          vm_page *m;     /* currently mapped page */
  286         vm_offset_t     kva;            /* va of mapping */
  287 };
  288 
  289 struct accept_filter {
  290         char    accf_name[16];
  291         void    (*accf_callback)
  292                 __P((struct socket *so, void *arg, int waitflag));
  293         void *  (*accf_create)
  294                 __P((struct socket *so, char *arg));
  295         void    (*accf_destroy)
  296                 __P((struct socket *so));
  297         SLIST_ENTRY(accept_filter) accf_next;   /* next on the list */
  298 };
  299 
  300 #ifdef MALLOC_DECLARE
  301 MALLOC_DECLARE(M_PCB);
  302 MALLOC_DECLARE(M_SONAME);
  303 MALLOC_DECLARE(M_ACCF);
  304 #endif
  305 
  306 extern int      maxsockets;
  307 extern u_long   sb_max;
  308 extern struct   vm_zone *socket_zone;
  309 extern so_gen_t so_gencnt;
  310 
  311 struct file;
  312 struct filedesc;
  313 struct mbuf;
  314 struct sockaddr;
  315 struct stat;
  316 struct ucred;
  317 struct uio;
  318 struct knote;
  319 
  320 /*
  321  * File operations on sockets.
  322  */
  323 int     soo_read __P((struct file *fp, struct uio *uio, struct ucred *cred,
  324             int flags, struct proc *p));
  325 int     soo_write __P((struct file *fp, struct uio *uio, struct ucred *cred,
  326             int flags, struct proc *p));
  327 int     soo_close __P((struct file *fp, struct proc *p));
  328 int     soo_ioctl __P((struct file *fp, u_long cmd, caddr_t data,
  329             struct proc *p));
  330 int     soo_poll __P((struct file *fp, int events, struct ucred *cred,
  331             struct proc *p));
  332 int     soo_stat __P((struct file *fp, struct stat *ub, struct proc *p));
  333 int     sokqfilter __P((struct file *fp, struct knote *kn));
  334 
  335 /*
  336  * From uipc_socket and friends
  337  */
  338 struct  sockaddr *dup_sockaddr __P((struct sockaddr *sa, int canwait));
  339 int     holdsock __P((struct filedesc *fdp, int fdes, struct file **fpp));
  340 int     sockargs __P((struct mbuf **mp, caddr_t buf, int buflen, int type));
  341 int     getsockaddr __P((struct sockaddr **namp, caddr_t uaddr, size_t len));
  342 void    sbappend __P((struct sockbuf *sb, struct mbuf *m));
  343 void    sbappendstream(struct sockbuf *sb, struct mbuf *m);
  344 int     sbappendaddr __P((struct sockbuf *sb, struct sockaddr *asa,
  345             struct mbuf *m0, struct mbuf *control));
  346 int     sbappendcontrol __P((struct sockbuf *sb, struct mbuf *m0,
  347             struct mbuf *control));
  348 void    sbappendrecord __P((struct sockbuf *sb, struct mbuf *m0));
  349 void    sbcheck __P((struct sockbuf *sb));
  350 void    sbcompress __P((struct sockbuf *sb, struct mbuf *m, struct mbuf *n));
  351 struct mbuf *
  352         sbcreatecontrol __P((caddr_t p, int size, int type, int level));
  353 void    sbdrop __P((struct sockbuf *sb, int len));
  354 void    sbdroprecord __P((struct sockbuf *sb));
  355 void    sbflush __P((struct sockbuf *sb));
  356 void    sbinsertoob __P((struct sockbuf *sb, struct mbuf *m0));
  357 void    sbrelease __P((struct sockbuf *sb, struct socket *so));
  358 int     sbreserve __P((struct sockbuf *sb, u_long cc, struct socket *so,
  359                        struct proc *p));
  360 void    sbtoxsockbuf __P((struct sockbuf *sb, struct xsockbuf *xsb));
  361 int     sbwait __P((struct sockbuf *sb));
  362 int     sb_lock __P((struct sockbuf *sb));
  363 struct sf_buf *
  364         sf_buf_alloc(void);
  365 void    sf_buf_free(caddr_t addr, u_int size);
  366 void    sf_buf_ref(caddr_t addr, u_int size);
  367 int     soabort __P((struct socket *so));
  368 int     soaccept __P((struct socket *so, struct sockaddr **nam));
  369 struct  socket *soalloc __P((int waitok));
  370 int     sobind __P((struct socket *so, struct sockaddr *nam, struct proc *p));
  371 void    socantrcvmore __P((struct socket *so));
  372 void    socantsendmore __P((struct socket *so));
  373 int     soclose __P((struct socket *so));
  374 int     soconnect __P((struct socket *so, struct sockaddr *nam, struct proc *p));
  375 int     soconnect2 __P((struct socket *so1, struct socket *so2));
  376 int     socreate __P((int dom, struct socket **aso, int type, int proto,
  377             struct proc *p));
  378 void    sodealloc __P((struct socket *so));
  379 int     sodisconnect __P((struct socket *so));
  380 void    sofree __P((struct socket *so));
  381 int     sogetopt __P((struct socket *so, struct sockopt *sopt));
  382 void    sohasoutofband __P((struct socket *so));
  383 void    soisconnected __P((struct socket *so));
  384 void    soisconnecting __P((struct socket *so));
  385 void    soisdisconnected __P((struct socket *so));
  386 void    soisdisconnecting __P((struct socket *so));
  387 int     solisten __P((struct socket *so, int backlog, struct proc *p));
  388 struct socket *
  389         sonewconn __P((struct socket *head, int connstatus));
  390 struct socket *
  391         sonewconn3 __P((struct socket *head, int connstatus, struct proc *p));
  392 int     sooptcopyin __P((struct sockopt *sopt, void *buf, size_t len,
  393                          size_t minlen));
  394 int     sooptcopyout __P((struct sockopt *sopt, const void *buf, size_t len));
  395 
  396 /* XXX; prepare mbuf for (__FreeBSD__ < 3) routines. */
  397 int     soopt_getm __P((struct sockopt *sopt, struct mbuf **mp));
  398 int     soopt_mcopyin __P((struct sockopt *sopt, struct mbuf *m));
  399 int     soopt_mcopyout __P((struct sockopt *sopt, struct mbuf *m));
  400 
  401 int     sopoll __P((struct socket *so, int events, struct ucred *cred,
  402                     struct proc *p));
  403 int     soreceive __P((struct socket *so, struct sockaddr **paddr,
  404                        struct uio *uio, struct mbuf **mp0,
  405                        struct mbuf **controlp, int *flagsp));
  406 int     soreserve __P((struct socket *so, u_long sndcc, u_long rcvcc));
  407 void    sorflush __P((struct socket *so));
  408 int     sosend __P((struct socket *so, struct sockaddr *addr, struct uio *uio,
  409                     struct mbuf *top, struct mbuf *control, int flags,
  410                     struct proc *p));
  411 int     sosetopt __P((struct socket *so, struct sockopt *sopt));
  412 int     soshutdown __P((struct socket *so, int how));
  413 void    sotoxsocket __P((struct socket *so, struct xsocket *xso));
  414 void    sowakeup __P((struct socket *so, struct sockbuf *sb));
  415 
  416 /* accept filter functions */
  417 int     accept_filt_add __P((struct accept_filter *filt));
  418 int     accept_filt_del __P((char *name));
  419 struct accept_filter *  accept_filt_get __P((char *name));
  420 
  421 #ifdef SOCKBUF_DEBUG
  422 void    sblastrecordchk(struct sockbuf *, const char *, int);
  423 #define SBLASTRECORDCHK(sb)     sblastrecordchk((sb), __FILE__, __LINE__)
  424 
  425 void    sblastmbufchk(struct sockbuf *, const char *, int);
  426 #define SBLASTMBUFCHK(sb)       sblastmbufchk((sb), __FILE__, __LINE__)
  427 #else
  428 #define SBLASTRECORDCHK(sb)      /* nothing */
  429 #define SBLASTMBUFCHK(sb)        /* nothing */
  430 #endif /* SOCKBUF_DEBUG */
  431 
  432 #ifdef ACCEPT_FILTER_MOD
  433 int accept_filt_generic_mod_event __P((module_t mod, int event, void *data));
  434 SYSCTL_DECL(_net_inet_accf);
  435 #endif /* ACCEPT_FILTER_MOD */
  436 
  437 #endif /* _KERNEL */
  438 
  439 #endif /* !_SYS_SOCKETVAR_H_ */

Cache object: cdeb8217fa69aeecfdfe1b641d1b8510


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.