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 socket {
   52         struct  vm_zone *so_zone;       /* zone we were allocated from */
   53         short   so_type;                /* generic type, see socket.h */
   54         short   so_options;             /* from socket call, see socket.h */
   55         short   so_linger;              /* time to linger while closing */
   56         short   so_state;               /* internal state flags SS_*, below */
   57         caddr_t so_pcb;                 /* protocol control block */
   58         struct  protosw *so_proto;      /* protocol handle */
   59 /*
   60  * Variables for connection queuing.
   61  * Socket where accepts occur is so_head in all subsidiary sockets.
   62  * If so_head is 0, socket is not related to an accept.
   63  * For head socket so_q0 queues partially completed connections,
   64  * while so_q is a queue of connections ready to be accepted.
   65  * If a connection is aborted and it has so_head set, then
   66  * it has to be pulled out of either so_q0 or so_q.
   67  * We allow connections to queue up based on current queue lengths
   68  * and limit on number of queued connections for this socket.
   69  */
   70         struct  socket *so_head;        /* back pointer to accept socket */
   71         TAILQ_HEAD(, socket) so_incomp; /* queue of partial unaccepted connections */
   72         TAILQ_HEAD(, socket) so_comp;   /* queue of complete unaccepted connections */
   73         TAILQ_ENTRY(socket) so_list;    /* list of unaccepted connections */
   74         short   so_qlen;                /* number of unaccepted connections */
   75         short   so_incqlen;             /* number of unaccepted incomplete
   76                                            connections */
   77         short   so_qlimit;              /* max number queued connections */
   78         short   so_timeo;               /* connection timeout */
   79         u_short so_error;               /* error affecting connection */
   80         struct  sigio *so_sigio;        /* information for async I/O or
   81                                            out of band data (SIGURG) */
   82         u_long  so_oobmark;             /* chars to oob mark */
   83 /*
   84  * Variables for socket buffering.
   85  */
   86         struct  sockbuf {
   87                 u_long  sb_cc;          /* actual chars in buffer */
   88                 u_long  sb_hiwat;       /* max actual char count */
   89                 u_long  sb_mbcnt;       /* chars of mbufs used */
   90                 u_long  sb_mbmax;       /* max chars of mbufs to use */
   91                 long    sb_lowat;       /* low water mark */
   92                 struct  mbuf *sb_mb;    /* the mbuf chain */
   93                 struct  selinfo sb_sel; /* process selecting read/write */
   94                 short   sb_flags;       /* flags, see below */
   95                 short   sb_timeo;       /* timeout for read/write */
   96         } so_rcv, so_snd;
   97 #define SB_MAX          (256*1024)      /* default for max chars in sockbuf */
   98 #define SB_LOCK         0x01            /* lock on data queue */
   99 #define SB_WANT         0x02            /* someone is waiting to lock */
  100 #define SB_WAIT         0x04            /* someone is waiting for data/space */
  101 #define SB_SEL          0x08            /* someone is selecting */
  102 #define SB_ASYNC        0x10            /* ASYNC I/O, need signals */
  103 #define SB_UPCALL       0x20            /* someone wants an upcall */
  104 #define SB_NOINTR       0x40            /* operations not interruptible */
  105 
  106         void    (*so_upcall) __P((struct socket *, void *, int));
  107         void    *so_upcallarg;
  108         struct  pcred *so_cred;         /* user credentials of the opener */
  109         /* NB: generation count must not be first; easiest to make it last. */
  110         so_gen_t so_gencnt;             /* generation count */
  111 };
  112 
  113 /*
  114  * Socket state bits.
  115  */
  116 #define SS_NOFDREF              0x0001  /* no file table ref any more */
  117 #define SS_ISCONNECTED          0x0002  /* socket connected to a peer */
  118 #define SS_ISCONNECTING         0x0004  /* in process of connecting to peer */
  119 #define SS_ISDISCONNECTING      0x0008  /* in process of disconnecting */
  120 #define SS_CANTSENDMORE         0x0010  /* can't send more data to peer */
  121 #define SS_CANTRCVMORE          0x0020  /* can't receive more data from peer */
  122 #define SS_RCVATMARK            0x0040  /* at mark on input */
  123 
  124 #define SS_NBIO                 0x0100  /* non-blocking ops */
  125 #define SS_ASYNC                0x0200  /* async i/o notify */
  126 #define SS_ISCONFIRMING         0x0400  /* deciding to accept connection req */
  127 
  128 #define SS_INCOMP               0x0800  /* unaccepted, incomplete connection */
  129 #define SS_COMP                 0x1000  /* unaccepted, complete connection */
  130 #define SS_ISDISCONNECTED       0x2000  /* socket disconnected from peer */
  131 
  132 /*
  133  * Externalized form of struct socket used by the sysctl(3) interface.
  134  */
  135 struct  xsocket {
  136         size_t  xso_len;        /* length of this structure */
  137         struct  socket *xso_so; /* makes a convenient handle sometimes */
  138         short   so_type;
  139         short   so_options;
  140         short   so_linger;
  141         short   so_state;
  142         caddr_t so_pcb;         /* another convenient handle */
  143         int     xso_protocol;
  144         int     xso_family;
  145         short   so_qlen;
  146         short   so_incqlen;
  147         short   so_qlimit;
  148         short   so_timeo;
  149         u_short so_error;
  150         pid_t   so_pgid;
  151         u_long  so_oobmark;
  152         struct  xsockbuf {
  153                 u_long  sb_cc;
  154                 u_long  sb_hiwat;
  155                 u_long  sb_mbcnt;
  156                 u_long  sb_mbmax;
  157                 long    sb_lowat;
  158                 short   sb_flags;
  159                 short   sb_timeo;
  160         } so_rcv, so_snd;
  161         uid_t   so_uid;         /* XXX */
  162 };
  163 
  164 /*
  165  * Macros for sockets and socket buffering.
  166  */
  167 
  168 /*
  169  * Do we need to notify the other side when I/O is possible?
  170  */
  171 #define sb_notify(sb)   (((sb)->sb_flags & (SB_WAIT|SB_SEL|SB_ASYNC|SB_UPCALL)) != 0)
  172 
  173 /*
  174  * How much space is there in a socket buffer (so->so_snd or so->so_rcv)?
  175  * This is problematical if the fields are unsigned, as the space might
  176  * still be negative (cc > hiwat or mbcnt > mbmax).  Should detect
  177  * overflow and return 0.  Should use "lmin" but it doesn't exist now.
  178  */
  179 #define sbspace(sb) \
  180     ((long) imin((int)((sb)->sb_hiwat - (sb)->sb_cc), \
  181          (int)((sb)->sb_mbmax - (sb)->sb_mbcnt)))
  182 
  183 /* do we have to send all at once on a socket? */
  184 #define sosendallatonce(so) \
  185     ((so)->so_proto->pr_flags & PR_ATOMIC)
  186 
  187 /* can we read something from so? */
  188 #define soreadable(so) \
  189     ((so)->so_rcv.sb_cc >= (so)->so_rcv.sb_lowat || \
  190         ((so)->so_state & SS_CANTRCVMORE) || \
  191         (so)->so_comp.tqh_first || (so)->so_error)
  192 
  193 /* can we write something to so? */
  194 #define sowriteable(so) \
  195     ((sbspace(&(so)->so_snd) >= (so)->so_snd.sb_lowat && \
  196         (((so)->so_state&SS_ISCONNECTED) || \
  197           ((so)->so_proto->pr_flags&PR_CONNREQUIRED)==0)) || \
  198      ((so)->so_state & SS_CANTSENDMORE) || \
  199      (so)->so_error)
  200 
  201 /* adjust counters in sb reflecting allocation of m */
  202 #define sballoc(sb, m) { \
  203         (sb)->sb_cc += (m)->m_len; \
  204         (sb)->sb_mbcnt += MSIZE; \
  205         if ((m)->m_flags & M_EXT) \
  206                 (sb)->sb_mbcnt += (m)->m_ext.ext_size; \
  207 }
  208 
  209 /* adjust counters in sb reflecting freeing of m */
  210 #define sbfree(sb, m) { \
  211         (sb)->sb_cc -= (m)->m_len; \
  212         (sb)->sb_mbcnt -= MSIZE; \
  213         if ((m)->m_flags & M_EXT) \
  214                 (sb)->sb_mbcnt -= (m)->m_ext.ext_size; \
  215 }
  216 
  217 /*
  218  * Set lock on sockbuf sb; sleep if lock is already held.
  219  * Unless SB_NOINTR is set on sockbuf, sleep is interruptible.
  220  * Returns error without lock if sleep is interrupted.
  221  */
  222 #define sblock(sb, wf) ((sb)->sb_flags & SB_LOCK ? \
  223                 (((wf) == M_WAITOK) ? sb_lock(sb) : EWOULDBLOCK) : \
  224                 ((sb)->sb_flags |= SB_LOCK), 0)
  225 
  226 /* release lock on sockbuf sb */
  227 #define sbunlock(sb) { \
  228         (sb)->sb_flags &= ~SB_LOCK; \
  229         if ((sb)->sb_flags & SB_WANT) { \
  230                 (sb)->sb_flags &= ~SB_WANT; \
  231                 wakeup((caddr_t)&(sb)->sb_flags); \
  232         } \
  233 }
  234 
  235 #define sorwakeup(so)   do { \
  236                           if (sb_notify(&(so)->so_rcv)) \
  237                             sowakeup((so), &(so)->so_rcv); \
  238                         } while (0)
  239 
  240 #define sowwakeup(so)   do { \
  241                           if (sb_notify(&(so)->so_snd)) \
  242                             sowakeup((so), &(so)->so_snd); \
  243                         } while (0)
  244 
  245 #ifdef KERNEL
  246 
  247 /*
  248  * Argument structure for sosetopt et seq.  This is in the KERNEL
  249  * section because it will never be visible to user code.
  250  */
  251 enum sopt_dir { SOPT_GET, SOPT_SET };
  252 struct sockopt {
  253         enum    sopt_dir sopt_dir; /* is this a get or a set? */
  254         int     sopt_level;     /* second arg of [gs]etsockopt */
  255         int     sopt_name;      /* third arg of [gs]etsockopt */
  256         void   *sopt_val;       /* fourth arg of [gs]etsockopt */
  257         size_t  sopt_valsize;   /* (almost) fifth arg of [gs]etsockopt */
  258         struct  proc *sopt_p;   /* calling process or null if kernel */
  259 };
  260 
  261 struct sf_buf {
  262         SLIST_ENTRY(sf_buf) free_list;  /* list of free buffer slots */
  263         int             refcnt;         /* reference count */
  264         struct          vm_page *m;     /* currently mapped page */
  265         vm_offset_t     kva;            /* va of mapping */
  266 };
  267 
  268 #ifdef MALLOC_DECLARE
  269 MALLOC_DECLARE(M_PCB);
  270 MALLOC_DECLARE(M_SONAME);
  271 #endif
  272 
  273 extern int      maxsockets;
  274 extern u_long   sb_max;
  275 extern struct   vm_zone *socket_zone;
  276 extern so_gen_t so_gencnt;
  277 
  278 struct file;
  279 struct filedesc;
  280 struct mbuf;
  281 struct sockaddr;
  282 struct stat;
  283 struct ucred;
  284 struct uio;
  285 
  286 /*
  287  * File operations on sockets.
  288  */
  289 int     soo_ioctl __P((struct file *fp, u_long cmd, caddr_t data,
  290             struct proc *p));
  291 int     soo_poll __P((struct file *fp, int events, struct ucred *cred,
  292             struct proc *p));
  293 int     soo_stat __P((struct socket *so, struct stat *ub));
  294 
  295 /*
  296  * From uipc_socket and friends
  297  */
  298 struct  sockaddr *dup_sockaddr __P((struct sockaddr *sa, int canwait));
  299 int     getsock __P((struct filedesc *fdp, int fdes, struct file **fpp));
  300 int     sockargs __P((struct mbuf **mp, caddr_t buf, int buflen, int type));
  301 int     getsockaddr __P((struct sockaddr **namp, caddr_t uaddr, size_t len));
  302 void    sbappend __P((struct sockbuf *sb, struct mbuf *m));
  303 int     sbappendaddr __P((struct sockbuf *sb, struct sockaddr *asa,
  304             struct mbuf *m0, struct mbuf *control));
  305 int     sbappendcontrol __P((struct sockbuf *sb, struct mbuf *m0,
  306             struct mbuf *control));
  307 void    sbappendrecord __P((struct sockbuf *sb, struct mbuf *m0));
  308 void    sbcheck __P((struct sockbuf *sb));
  309 void    sbcompress __P((struct sockbuf *sb, struct mbuf *m, struct mbuf *n));
  310 struct mbuf *
  311         sbcreatecontrol __P((caddr_t p, int size, int type, int level));
  312 void    sbdrop __P((struct sockbuf *sb, int len));
  313 void    sbdroprecord __P((struct sockbuf *sb));
  314 void    sbflush __P((struct sockbuf *sb));
  315 void    sbinsertoob __P((struct sockbuf *sb, struct mbuf *m0));
  316 void    sbrelease __P((struct sockbuf *sb));
  317 int     sbreserve __P((struct sockbuf *sb, u_long cc));
  318 void    sbtoxsockbuf __P((struct sockbuf *sb, struct xsockbuf *xsb));
  319 int     sbwait __P((struct sockbuf *sb));
  320 int     sb_lock __P((struct sockbuf *sb));
  321 int     soabort __P((struct socket *so));
  322 int     soaccept __P((struct socket *so, struct sockaddr **nam));
  323 struct  socket *soalloc __P((int waitok));
  324 int     sobind __P((struct socket *so, struct sockaddr *nam, struct proc *p));
  325 void    socantrcvmore __P((struct socket *so));
  326 void    socantsendmore __P((struct socket *so));
  327 int     soclose __P((struct socket *so));
  328 int     soconnect __P((struct socket *so, struct sockaddr *nam, struct proc *p));
  329 int     soconnect2 __P((struct socket *so1, struct socket *so2));
  330 int     socreate __P((int dom, struct socket **aso, int type, int proto,
  331             struct proc *p));
  332 void    sodealloc __P((struct socket *so));
  333 int     sodisconnect __P((struct socket *so));
  334 void    sofree __P((struct socket *so));
  335 int     sogetopt __P((struct socket *so, struct sockopt *sopt));
  336 void    sohasoutofband __P((struct socket *so));
  337 void    soisconnected __P((struct socket *so));
  338 void    soisconnecting __P((struct socket *so));
  339 void    soisdisconnected __P((struct socket *so));
  340 void    soisdisconnecting __P((struct socket *so));
  341 int     solisten __P((struct socket *so, int backlog, struct proc *p));
  342 struct socket *
  343         sodropablereq __P((struct socket *head));
  344 struct socket *
  345         sonewconn __P((struct socket *head, int connstatus));
  346 int     sooptcopyin __P((struct sockopt *sopt, void *buf, size_t len,
  347                          size_t minlen));
  348 int     sooptcopyout __P((struct sockopt *sopt, void *buf, size_t len));
  349 int     sopoll __P((struct socket *so, int events, struct ucred *cred,
  350                     struct proc *p));
  351 int     soreceive __P((struct socket *so, struct sockaddr **paddr,
  352                        struct uio *uio, struct mbuf **mp0,
  353                        struct mbuf **controlp, int *flagsp));
  354 int     soreserve __P((struct socket *so, u_long sndcc, u_long rcvcc));
  355 void    sorflush __P((struct socket *so));
  356 int     sosend __P((struct socket *so, struct sockaddr *addr, struct uio *uio,
  357                     struct mbuf *top, struct mbuf *control, int flags,
  358                     struct proc *p));
  359 int     sosetopt __P((struct socket *so, struct sockopt *sopt));
  360 int     soshutdown __P((struct socket *so, int how));
  361 void    sotoxsocket __P((struct socket *so, struct xsocket *xso));
  362 void    sowakeup __P((struct socket *so, struct sockbuf *sb));
  363 
  364 #endif /* KERNEL */
  365 
  366 #endif /* !_SYS_SOCKETVAR_H_ */

Cache object: b136d46576705bf779e018ce802202f3


[ 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.