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

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

CVSweb <webmaster@jp.NetBSD.org>