[BACK]Return to socketvar.h CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / sys / sys

Annotation of src/sys/sys/socketvar.h, Revision 1.105

1.105   ! ad          1: /*     $NetBSD: socketvar.h,v 1.104 2008/03/21 21:55:01 ad Exp $       */
        !             2:
        !             3: /*-
        !             4:  * Copyright (c) 2008 The NetBSD Foundation, Inc.
        !             5:  * All rights reserved.
        !             6:  *
        !             7:  * Redistribution and use in source and binary forms, with or without
        !             8:  * modification, are permitted provided that the following conditions
        !             9:  * are met:
        !            10:  * 1. Redistributions of source code must retain the above copyright
        !            11:  *    notice, this list of conditions and the following disclaimer.
        !            12:  * 2. Redistributions in binary form must reproduce the above copyright
        !            13:  *    notice, this list of conditions and the following disclaimer in the
        !            14:  *    documentation and/or other materials provided with the distribution.
        !            15:  * 3. All advertising materials mentioning features or use of this software
        !            16:  *    must display the following acknowledgement:
        !            17:  *     This product includes software developed by the NetBSD
        !            18:  *     Foundation, Inc. and its contributors.
        !            19:  * 4. Neither the name of The NetBSD Foundation nor the names of its
        !            20:  *    contributors may be used to endorse or promote products derived
        !            21:  *    from this software without specific prior written permission.
        !            22:  *
        !            23:  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
        !            24:  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
        !            25:  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
        !            26:  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
        !            27:  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
        !            28:  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
        !            29:  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
        !            30:  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
        !            31:  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
        !            32:  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
        !            33:  * POSSIBILITY OF SUCH DAMAGE.
        !            34:  */
1.11      cgd        35:
1.1       cgd        36: /*-
1.8       mycroft    37:  * Copyright (c) 1982, 1986, 1990, 1993
                     38:  *     The Regents of the University of California.  All rights reserved.
1.1       cgd        39:  *
                     40:  * Redistribution and use in source and binary forms, with or without
                     41:  * modification, are permitted provided that the following conditions
                     42:  * are met:
                     43:  * 1. Redistributions of source code must retain the above copyright
                     44:  *    notice, this list of conditions and the following disclaimer.
                     45:  * 2. Redistributions in binary form must reproduce the above copyright
                     46:  *    notice, this list of conditions and the following disclaimer in the
                     47:  *    documentation and/or other materials provided with the distribution.
1.65      agc        48:  * 3. Neither the name of the University nor the names of its contributors
1.1       cgd        49:  *    may be used to endorse or promote products derived from this software
                     50:  *    without specific prior written permission.
                     51:  *
                     52:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     53:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     54:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     55:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     56:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     57:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     58:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     59:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     60:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     61:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     62:  * SUCH DAMAGE.
                     63:  *
1.28      fvdl       64:  *     @(#)socketvar.h 8.3 (Berkeley) 2/19/95
1.1       cgd        65:  */
                     66:
1.24      mikel      67: #ifndef _SYS_SOCKETVAR_H_
1.42      lukem      68: #define        _SYS_SOCKETVAR_H_
1.24      mikel      69:
1.81      kleink     70: #include <sys/select.h>
                     71: #include <sys/selinfo.h>               /* for struct selinfo */
1.27      thorpej    72: #include <sys/queue.h>
1.105   ! ad         73: #include <sys/mutex.h>
        !            74: #include <sys/condvar.h>
1.27      thorpej    75:
1.38      simonb     76: #if !defined(_KERNEL) || defined(LKM)
1.29      matt       77: struct uio;
1.85      christos   78: struct lwp;
1.82      christos   79: struct uidinfo;
1.29      matt       80: #endif
                     81:
1.27      thorpej    82: TAILQ_HEAD(soqhead, socket);
1.3       mycroft    83:
1.1       cgd        84: /*
1.58      matt       85:  * Variables for socket buffering.
                     86:  */
                     87: struct sockbuf {
1.66      wrstuden   88:        struct selinfo sb_sel;          /* process selecting read/write */
                     89:        struct mowner *sb_mowner;       /* who owns data for this sockbuf */
1.105   ! ad         90:        struct socket *sb_so;           /* back pointer to socket */
        !            91:        kcondvar_t sb_cv;               /* notifier */
1.66      wrstuden   92:        /* When re-zeroing this struct, we zero from sb_startzero to the end */
                     93: #define        sb_startzero    sb_cc
1.58      matt       94:        u_long  sb_cc;                  /* actual chars in buffer */
                     95:        u_long  sb_hiwat;               /* max actual char count */
                     96:        u_long  sb_mbcnt;               /* chars of mbufs used */
                     97:        u_long  sb_mbmax;               /* max chars of mbufs to use */
                     98:        long    sb_lowat;               /* low water mark */
                     99:        struct mbuf *sb_mb;             /* the mbuf chain */
                    100:        struct mbuf *sb_mbtail;         /* the last mbuf in the chain */
                    101:        struct mbuf *sb_lastrecord;     /* first mbuf of last record in
                    102:                                           socket buffer */
1.79      yamt      103:        int     sb_flags;               /* flags, see below */
                    104:        int     sb_timeo;               /* timeout for read/write */
1.80      darrenr   105:        u_long  sb_overflowed;          /* # of drops due to full buffer */
1.58      matt      106: };
                    107:
                    108: #ifndef SB_MAX
                    109: #define        SB_MAX          (256*1024)      /* default for max chars in sockbuf */
                    110: #endif
                    111:
                    112: #define        SB_LOCK         0x01            /* lock on data queue */
1.105   ! ad        113: #define        SB_NOTIFY       0x04            /* someone is waiting for data/space */
1.58      matt      114: #define        SB_ASYNC        0x10            /* ASYNC I/O, need signals */
                    115: #define        SB_UPCALL       0x20            /* someone wants an upcall */
                    116: #define        SB_NOINTR       0x40            /* operations not interruptible */
                    117: #define        SB_KNOTE        0x100           /* kernel note attached */
1.98      rmind     118: #define        SB_AUTOSIZE     0x800           /* automatically size socket buffer */
1.58      matt      119:
                    120: /*
1.1       cgd       121:  * Kernel structure per socket.
                    122:  * Contains send and receive buffer queues,
                    123:  * handle on protocol and pointer to protocol
                    124:  * private data and error information.
                    125:  */
                    126: struct socket {
1.105   ! ad        127:        kmutex_t * volatile so_lock;    /* pointer to lock on structure */
        !           128:        kcondvar_t      so_cv;          /* notifier */
1.42      lukem     129:        short           so_type;        /* generic type, see socket.h */
                    130:        short           so_options;     /* from socket call, see socket.h */
1.92      christos  131:        u_short         so_linger;      /* time to linger while closing */
1.42      lukem     132:        short           so_state;       /* internal state flags SS_*, below */
1.102     ad        133:        int             so_nbio;        /* non-blocking I/O enabled */
1.42      lukem     134:        void            *so_pcb;        /* protocol control block */
1.74      matt      135:        const struct protosw *so_proto; /* protocol handle */
1.1       cgd       136: /*
                    137:  * Variables for connection queueing.
                    138:  * Socket where accepts occur is so_head in all subsidiary sockets.
                    139:  * If so_head is 0, socket is not related to an accept.
                    140:  * For head socket so_q0 queues partially completed connections,
                    141:  * while so_q is a queue of connections ready to be accepted.
                    142:  * If a connection is aborted and it has so_head set, then
                    143:  * it has to be pulled out of either so_q0 or so_q.
                    144:  * We allow connections to queue up based on current queue lengths
                    145:  * and limit on number of queued connections for this socket.
                    146:  */
1.42      lukem     147:        struct socket   *so_head;       /* back pointer to accept socket */
                    148:        struct soqhead  *so_onq;        /* queue (q or q0) that we're on */
                    149:        struct soqhead  so_q0;          /* queue of partial connections */
                    150:        struct soqhead  so_q;           /* queue of incoming connections */
1.27      thorpej   151:        TAILQ_ENTRY(socket) so_qe;      /* our queue entry (q or q0) */
1.42      lukem     152:        short           so_q0len;       /* partials on so_q0 */
                    153:        short           so_qlen;        /* number of connections on so_q */
                    154:        short           so_qlimit;      /* max number queued connections */
                    155:        short           so_timeo;       /* connection timeout */
                    156:        u_short         so_error;       /* error affecting connection */
                    157:        pid_t           so_pgid;        /* pgid for signals */
                    158:        u_long          so_oobmark;     /* chars to oob mark */
1.58      matt      159:        struct sockbuf  so_snd;         /* send buffer */
                    160:        struct sockbuf  so_rcv;         /* receive buffer */
1.1       cgd       161:
1.42      lukem     162:        void            *so_internal;   /* Space for svr4 stream data */
1.93      christos  163:        void            (*so_upcall) (struct socket *, void *, int);
                    164:        void *          so_upcallarg;   /* Arg for above */
1.71      matt      165:        int             (*so_send) (struct socket *, struct mbuf *,
1.64      itojun    166:                                        struct uio *, struct mbuf *,
1.83      christos  167:                                        struct mbuf *, int, struct lwp *);
1.71      matt      168:        int             (*so_receive) (struct socket *,
1.64      itojun    169:                                        struct mbuf **,
                    170:                                        struct uio *, struct mbuf **,
1.71      matt      171:                                        struct mbuf **, int *);
1.58      matt      172:        struct mowner   *so_mowner;     /* who owns mbufs for this socket */
1.82      christos  173:        struct uidinfo  *so_uidinfo;    /* who opened the socket */
1.1       cgd       174: };
                    175:
1.54      thorpej   176: #define        SB_EMPTY_FIXUP(sb)                                              \
1.52      thorpej   177: do {                                                                   \
1.105   ! ad        178:        KASSERT(solocked((sb)->sb_so));                                 \
1.52      thorpej   179:        if ((sb)->sb_mb == NULL) {                                      \
                    180:                (sb)->sb_mbtail = NULL;                                 \
                    181:                (sb)->sb_lastrecord = NULL;                             \
                    182:        }                                                               \
                    183: } while (/*CONSTCOND*/0)
                    184:
1.1       cgd       185: /*
                    186:  * Socket state bits.
                    187:  */
                    188: #define        SS_NOFDREF              0x001   /* no file table ref any more */
                    189: #define        SS_ISCONNECTED          0x002   /* socket connected to a peer */
                    190: #define        SS_ISCONNECTING         0x004   /* in process of connecting to peer */
                    191: #define        SS_ISDISCONNECTING      0x008   /* in process of disconnecting */
                    192: #define        SS_CANTSENDMORE         0x010   /* can't send more data to peer */
                    193: #define        SS_CANTRCVMORE          0x020   /* can't receive more data from peer */
                    194: #define        SS_RCVATMARK            0x040   /* at mark on input */
1.33      mycroft   195: #define        SS_ISDISCONNECTED       0x800   /* socket disconnected from peer */
1.1       cgd       196:
1.19      mycroft   197: #define        SS_ASYNC                0x100   /* async i/o notify */
                    198: #define        SS_ISCONFIRMING         0x200   /* deciding to accept connection req */
1.42      lukem     199: #define        SS_MORETOCOME           0x400   /*
                    200:                                         * hint from sosend to lower layer;
                    201:                                         * more data coming
                    202:                                         */
1.94      yamt      203: #define        SS_ISAPIPE              0x1000  /* socket is implementing a pipe */
1.1       cgd       204:
1.105   ! ad        205: #ifdef _KERNEL
1.1       cgd       206:
1.42      lukem     207: extern u_long          sb_max;
1.63      ragge     208: extern int             somaxkva;
1.88      yamt      209: extern int             sock_loan_thresh;
1.105   ! ad        210: extern kmutex_t                *softnet_lock;
1.31      thorpej   211:
1.17      christos  212: struct mbuf;
                    213: struct sockaddr;
1.84      christos  214: struct lwp;
1.17      christos  215: struct msghdr;
                    216: struct stat;
1.55      jdolecek  217: struct knote;
1.17      christos  218:
1.99      dyoung    219: struct mbuf *m_intopt(struct socket *, int);
1.100     dyoung    220: struct mbuf *getsombuf(struct socket *, int);
1.99      dyoung    221:
1.1       cgd       222: /*
                    223:  * File operations on sockets.
                    224:  */
1.104     ad        225: int    soo_read(file_t *, off_t *, struct uio *, kauth_cred_t, int);
                    226: int    soo_write(file_t *, off_t *, struct uio *, kauth_cred_t, int);
                    227: int    soo_fcntl(file_t *, u_int cmd, void *);
                    228: int    soo_ioctl(file_t *, u_long cmd, void *);
                    229: int    soo_poll(file_t *, int);
                    230: int    soo_kqfilter(file_t *, struct knote *);
                    231: int    soo_close(file_t *);
                    232: int    soo_stat(file_t *, struct stat *);
1.64      itojun    233: void   sbappend(struct sockbuf *, struct mbuf *);
                    234: void   sbappendstream(struct sockbuf *, struct mbuf *);
1.73      matt      235: int    sbappendaddr(struct sockbuf *, const struct sockaddr *, struct mbuf *,
1.64      itojun    236:            struct mbuf *);
1.76      jonathan  237: int    sbappendaddrchain(struct sockbuf *, const struct sockaddr *,
                    238:             struct mbuf *, int);
1.64      itojun    239: int    sbappendcontrol(struct sockbuf *, struct mbuf *, struct mbuf *);
                    240: void   sbappendrecord(struct sockbuf *, struct mbuf *);
                    241: void   sbcheck(struct sockbuf *);
                    242: void   sbcompress(struct sockbuf *, struct mbuf *, struct mbuf *);
1.23      thorpej   243: struct mbuf *
1.93      christos  244:        sbcreatecontrol(void *, int, int, int);
1.64      itojun    245: void   sbdrop(struct sockbuf *, int);
                    246: void   sbdroprecord(struct sockbuf *);
                    247: void   sbflush(struct sockbuf *);
                    248: void   sbinsertoob(struct sockbuf *, struct mbuf *);
1.70      christos  249: void   sbrelease(struct sockbuf *, struct socket *);
                    250: int    sbreserve(struct sockbuf *, u_long, struct socket *);
1.64      itojun    251: int    sbwait(struct sockbuf *);
1.68      thorpej   252: int    sb_max_set(u_long);
1.42      lukem     253: void   soinit(void);
1.64      itojun    254: int    soabort(struct socket *);
                    255: int    soaccept(struct socket *, struct mbuf *);
1.83      christos  256: int    sobind(struct socket *, struct mbuf *, struct lwp *);
1.64      itojun    257: void   socantrcvmore(struct socket *);
                    258: void   socantsendmore(struct socket *);
                    259: int    soclose(struct socket *);
1.83      christos  260: int    soconnect(struct socket *, struct mbuf *, struct lwp *);
1.64      itojun    261: int    soconnect2(struct socket *, struct socket *);
1.105   ! ad        262: int    socreate(int, struct socket **, int, int, struct lwp *,
        !           263:                 struct socket *);
1.99      dyoung    264: int    fsocreate(int, struct socket **, int, int, struct lwp *, int *);
1.64      itojun    265: int    sodisconnect(struct socket *);
                    266: void   sofree(struct socket *);
                    267: int    sogetopt(struct socket *, int, int, struct mbuf **);
                    268: void   sohasoutofband(struct socket *);
                    269: void   soisconnected(struct socket *);
                    270: void   soisconnecting(struct socket *);
                    271: void   soisdisconnected(struct socket *);
                    272: void   soisdisconnecting(struct socket *);
1.101     elad      273: int    solisten(struct socket *, int, struct lwp *);
1.7       mycroft   274: struct socket *
1.89      plunky    275:        sonewconn(struct socket *, int);
1.64      itojun    276: void   soqinsque(struct socket *, struct socket *, int);
                    277: int    soqremque(struct socket *, int);
                    278: int    soreceive(struct socket *, struct mbuf **, struct uio *,
                    279:            struct mbuf **, struct mbuf **, int *);
                    280: int    soreserve(struct socket *, u_long, u_long);
                    281: void   sorflush(struct socket *);
                    282: int    sosend(struct socket *, struct mbuf *, struct uio *,
1.83      christos  283:            struct mbuf *, struct mbuf *, int, struct lwp *);
1.64      itojun    284: int    sosetopt(struct socket *, int, int, struct mbuf *);
                    285: int    soshutdown(struct socket *, int);
1.67      christos  286: void   sowakeup(struct socket *, struct sockbuf *, int);
1.49      matt      287: int    sockargs(struct mbuf **, const void *, size_t, int);
1.103     ad        288: int    sopoll(struct socket *, int);
1.105   ! ad        289: struct socket *soget(bool);
        !           290: void   soput(struct socket *);
        !           291: bool   solocked(struct socket *);
        !           292: bool   solocked2(struct socket *, struct socket *);
        !           293: int    sblock(struct sockbuf *, int);
        !           294: void   sbunlock(struct sockbuf *);
        !           295: int    sowait(struct socket *, int);
        !           296: void   solockretry(struct socket *, kmutex_t *);
        !           297: void   sosetlock(struct socket *);
1.42      lukem     298:
1.96      dsl       299: int    copyout_sockname(struct sockaddr *, unsigned int *, int, struct mbuf *);
                    300: int    copyout_msg_control(struct lwp *, struct msghdr *, struct mbuf *);
                    301: void   free_control_mbuf(struct lwp *, struct mbuf *, struct mbuf *);
                    302:
                    303: int    do_sys_getsockname(struct lwp *, int, int, struct mbuf **);
1.95      dsl       304: int    do_sys_sendmsg(struct lwp *, int, struct msghdr *, int, register_t *);
1.96      dsl       305: int    do_sys_recvmsg(struct lwp *, int, struct msghdr *, struct mbuf **,
                    306:            struct mbuf **, register_t *);
1.52      thorpej   307:
1.96      dsl       308: int    do_sys_bind(struct lwp *, int, struct mbuf *);
                    309: int    do_sys_connect(struct lwp *, int, struct mbuf *);
                    310: int    do_sys_accept(struct lwp *, int, struct mbuf **, register_t *);
1.95      dsl       311:
1.105   ! ad        312: /*
        !           313:  * Inline functions for sockets and socket buffering.
        !           314:  */
        !           315:
        !           316: #include <sys/protosw.h>
        !           317: #include <sys/mbuf.h>
        !           318:
        !           319: /*
        !           320:  * Do we need to notify the other side when I/O is possible?
        !           321:  */
        !           322: static inline int
        !           323: sb_notify(struct sockbuf *sb)
        !           324: {
        !           325:
        !           326:        KASSERT(solocked(sb->sb_so));
        !           327:
        !           328:        return sb->sb_flags & (SB_NOTIFY | SB_ASYNC | SB_UPCALL | SB_KNOTE);
        !           329: }
        !           330:
        !           331: /*
        !           332:  * How much space is there in a socket buffer (so->so_snd or so->so_rcv)?
        !           333:  * This is problematical if the fields are unsigned, as the space might
        !           334:  * still be negative (cc > hiwat or mbcnt > mbmax).  Should detect
        !           335:  * overflow and return 0.
        !           336:  */
        !           337: static inline u_long
        !           338: sbspace(struct sockbuf *sb)
        !           339: {
        !           340:
        !           341:        KASSERT(solocked(sb->sb_so));
        !           342:
        !           343:        return lmin(sb->sb_hiwat - sb->sb_cc, sb->sb_mbmax - sb->sb_mbcnt);
        !           344: }
        !           345:
        !           346: /* do we have to send all at once on a socket? */
        !           347: static inline int
        !           348: sosendallatonce(struct socket *so)
        !           349: {
        !           350:
        !           351:        return so->so_proto->pr_flags & PR_ATOMIC;
        !           352: }
        !           353:
        !           354: /* can we read something from so? */
        !           355: static inline int
        !           356: soreadable(struct socket *so)
        !           357: {
        !           358:
        !           359:        KASSERT(solocked(so));
        !           360:
        !           361:        return so->so_rcv.sb_cc >= so->so_rcv.sb_lowat ||
        !           362:            (so->so_state & SS_CANTRCVMORE) != 0 ||
        !           363:            so->so_qlen != 0 || so->so_error != 0;
        !           364: }
        !           365:
        !           366: /* can we write something to so? */
        !           367: static inline int
        !           368: sowritable(struct socket *so)
        !           369: {
        !           370:
        !           371:        KASSERT(solocked(so));
        !           372:
        !           373:        return (sbspace(&so->so_snd) >= so->so_snd.sb_lowat &&
        !           374:            ((so->so_state & SS_ISCONNECTED) != 0 ||
        !           375:            (so->so_proto->pr_flags & PR_CONNREQUIRED) == 0)) ||
        !           376:            (so->so_state & SS_CANTSENDMORE) != 0 ||
        !           377:            so->so_error != 0;
        !           378: }
        !           379:
        !           380: /* adjust counters in sb reflecting allocation of m */
        !           381: static inline void
        !           382: sballoc(struct sockbuf *sb, struct mbuf *m)
        !           383: {
        !           384:
        !           385:        KASSERT(solocked(sb->sb_so));
        !           386:
        !           387:        sb->sb_cc += m->m_len;
        !           388:        sb->sb_mbcnt += MSIZE;
        !           389:        if (m->m_flags & M_EXT)
        !           390:                sb->sb_mbcnt += m->m_ext.ext_size;
        !           391: }
        !           392:
        !           393: /* adjust counters in sb reflecting freeing of m */
        !           394: static inline void
        !           395: sbfree(struct sockbuf *sb, struct mbuf *m)
        !           396: {
        !           397:
        !           398:        KASSERT(solocked(sb->sb_so));
        !           399:
        !           400:        sb->sb_cc -= m->m_len;
        !           401:        sb->sb_mbcnt -= MSIZE;
        !           402:        if (m->m_flags & M_EXT)
        !           403:                sb->sb_mbcnt -= m->m_ext.ext_size;
        !           404: }
        !           405:
        !           406: static inline void
        !           407: sorwakeup(struct socket *so)
        !           408: {
        !           409:
        !           410:        KASSERT(solocked(so));
        !           411:
        !           412:        if (sb_notify(&so->so_rcv))
        !           413:                sowakeup(so, &so->so_rcv, POLL_IN);
        !           414: }
        !           415:
        !           416: static inline void
        !           417: sowwakeup(struct socket *so)
        !           418: {
        !           419:
        !           420:        KASSERT(solocked(so));
        !           421:
        !           422:        if (sb_notify(&so->so_snd))
        !           423:                sowakeup(so, &so->so_snd, POLL_OUT);
        !           424: }
        !           425:
        !           426: static inline void
        !           427: solock(struct socket *so)
        !           428: {
        !           429:        kmutex_t *lock;
        !           430:
        !           431:        lock = so->so_lock;
        !           432:        mutex_enter(lock);
        !           433:        if (__predict_false(lock != so->so_lock))
        !           434:                solockretry(so, lock);
        !           435: }
        !           436:
        !           437: static inline void
        !           438: sounlock(struct socket *so)
        !           439: {
        !           440:
        !           441:        mutex_exit(so->so_lock);
        !           442: }
1.95      dsl       443:
1.52      thorpej   444: #ifdef SOCKBUF_DEBUG
1.78      yamt      445: /*
                    446:  * SBLASTRECORDCHK: check sb->sb_lastrecord is maintained correctly.
                    447:  * SBLASTMBUFCHK: check sb->sb_mbtail is maintained correctly.
                    448:  *
                    449:  * => panic if the socket buffer is inconsistent.
                    450:  * => 'where' is used for a panic message.
                    451:  */
1.52      thorpej   452: void   sblastrecordchk(struct sockbuf *, const char *);
                    453: #define        SBLASTRECORDCHK(sb, where)      sblastrecordchk((sb), (where))
                    454:
                    455: void   sblastmbufchk(struct sockbuf *, const char *);
                    456: #define        SBLASTMBUFCHK(sb, where)        sblastmbufchk((sb), (where))
1.105   ! ad        457: #define        SBCHECK(sb)                     sbcheck(sb)
1.52      thorpej   458: #else
                    459: #define        SBLASTRECORDCHK(sb, where)      /* nothing */
                    460: #define        SBLASTMBUFCHK(sb, where)        /* nothing */
1.105   ! ad        461: #define        SBCHECK(sb)                     /* nothing */
1.52      thorpej   462: #endif /* SOCKBUF_DEBUG */
1.60      yamt      463:
                    464: /* sosend loan */
                    465: vaddr_t        sokvaalloc(vsize_t, struct socket *);
                    466: void   sokvafree(vaddr_t, vsize_t);
1.93      christos  467: void   soloanfree(struct mbuf *, void *, size_t, void *);
1.17      christos  468:
1.76      jonathan  469: /*
                    470:  * Values for socket-buffer-append priority argument to sbappendaddrchain().
                    471:  * The following flags are reserved for future implementation:
                    472:  *
                    473:  *  SB_PRIO_NONE:  honour normal socket-buffer limits.
                    474:  *
                    475:  *  SB_PRIO_ONESHOT_OVERFLOW:  if the socket has any space,
                    476:  *     deliver the entire chain. Intended for large requests
                    477:  *      that should be delivered in their entirety, or not at all.
                    478:  *
                    479:  * SB_PRIO_OVERDRAFT:  allow a small (2*MLEN) overflow, over and
                    480:  *     aboce normal socket limits. Intended messages indicating
                    481:  *      buffer overflow in earlier normal/lower-priority messages .
                    482:  *
                    483:  * SB_PRIO_BESTEFFORT: Ignore  limits entirely.  Intended only for
                    484:  *     kernel-generated messages to specially-marked scokets which
                    485:  *     require "reliable" delivery, nd where the source socket/protocol
                    486:  *     message generator enforce some hard limit (but possibly well
                    487:  *     above kern.sbmax). It is entirely up to the in-kernel source to
                    488:  *     avoid complete mbuf exhaustion or DoS scenarios.
                    489:  */
                    490: #define SB_PRIO_NONE           0
                    491: #define SB_PRIO_ONESHOT_OVERFLOW 1
                    492: #define SB_PRIO_OVERDRAFT      2
                    493: #define SB_PRIO_BESTEFFORT     3
                    494:
1.14      jtc       495: #endif /* _KERNEL */
1.24      mikel     496:
                    497: #endif /* !_SYS_SOCKETVAR_H_ */

CVSweb <webmaster@jp.NetBSD.org>