Move SS_CANTRCVMORE and SS_RCVATMARK bits from `so_state' to `sb_state' of
authormvs <mvs@openbsd.org>
Sun, 22 Jan 2023 12:05:44 +0000 (12:05 +0000)
committermvs <mvs@openbsd.org>
Sun, 22 Jan 2023 12:05:44 +0000 (12:05 +0000)
receive buffer. As it was done for SS_CANTSENDMORE bit, the definition
kept as is, but now these bits belongs to the `sb_state' of receive
buffer. `sb_state' ored with `so_state' when socket data exporting to the
userland.

ok bluhm@

13 files changed:
sys/kern/kern_sysctl.c
sys/kern/sys_socket.c
sys/kern/uipc_socket.c
sys/kern/uipc_socket2.c
sys/kern/uipc_syscalls.c
sys/miscfs/fifofs/fifo_vnops.c
sys/net/rtsock.c
sys/netinet/raw_ip.c
sys/netinet/tcp_input.c
sys/netinet/tcp_usrreq.c
sys/netinet/udp_usrreq.c
sys/netinet6/raw_ip6.c
sys/sys/socketvar.h

index 94ae40f..226518b 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: kern_sysctl.c,v 1.410 2023/01/21 11:23:23 mvs Exp $   */
+/*     $OpenBSD: kern_sysctl.c,v 1.411 2023/01/22 12:05:44 mvs Exp $   */
 /*     $NetBSD: kern_sysctl.c,v 1.17 1996/05/20 17:49:05 mrg Exp $     */
 
 /*-
@@ -1184,7 +1184,8 @@ fill_file(struct kinfo_file *kf, struct file *fp, struct filedesc *fdp,
                }
 
                kf->so_type = so->so_type;
-               kf->so_state = so->so_state | so->so_snd.sb_state;
+               kf->so_state = so->so_state | so->so_snd.sb_state |
+                   so->so_rcv.sb_state;
                if (show_pointers)
                        kf->so_pcb = PTRTOINT64(so->so_pcb);
                else
index ddf1bef..13cf7c4 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: sys_socket.c,v 1.59 2023/01/21 11:23:23 mvs Exp $     */
+/*     $OpenBSD: sys_socket.c,v 1.60 2023/01/22 12:05:44 mvs Exp $     */
 /*     $NetBSD: sys_socket.c,v 1.13 1995/08/12 23:59:09 mycroft Exp $  */
 
 /*
@@ -119,7 +119,7 @@ soo_ioctl(struct file *fp, u_long cmd, caddr_t data, struct proc *p)
                break;
 
        case SIOCATMARK:
-               *(int *)data = (so->so_state&SS_RCVATMARK) != 0;
+               *(int *)data = (so->so_rcv.sb_state & SS_RCVATMARK) != 0;
                break;
 
        default:
@@ -149,7 +149,8 @@ soo_stat(struct file *fp, struct stat *ub, struct proc *p)
        memset(ub, 0, sizeof (*ub));
        ub->st_mode = S_IFSOCK;
        solock(so);
-       if ((so->so_state & SS_CANTRCVMORE) == 0 || so->so_rcv.sb_cc != 0)
+       if ((so->so_rcv.sb_state & SS_CANTRCVMORE) == 0 ||
+           so->so_rcv.sb_cc != 0)
                ub->st_mode |= S_IRUSR | S_IRGRP | S_IROTH;
        if ((so->so_snd.sb_state & SS_CANTSENDMORE) == 0)
                ub->st_mode |= S_IWUSR | S_IWGRP | S_IWOTH;
index 8b3d008..fdb140e 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: uipc_socket.c,v 1.294 2023/01/21 11:23:23 mvs Exp $   */
+/*     $OpenBSD: uipc_socket.c,v 1.295 2023/01/22 12:05:44 mvs Exp $   */
 /*     $NetBSD: uipc_socket.c,v 1.21 1996/02/04 02:17:52 christos Exp $        */
 
 /*
@@ -867,7 +867,7 @@ restart:
                                so->so_error = 0;
                        goto release;
                }
-               if (so->so_state & SS_CANTRCVMORE) {
+               if (so->so_rcv.sb_state & SS_CANTRCVMORE) {
                        if (m)
                                goto dontblock;
                        else if (so->so_rcv.sb_cc == 0)
@@ -1023,7 +1023,7 @@ dontblock:
                            so, so->so_type, m, m->m_type);
 #endif
                }
-               so->so_state &= ~SS_RCVATMARK;
+               so->so_rcv.sb_state &= ~SS_RCVATMARK;
                len = uio->uio_resid;
                if (so->so_oobmark && len > so->so_oobmark - offset)
                        len = so->so_oobmark - offset;
@@ -1100,7 +1100,7 @@ dontblock:
                        if ((flags & MSG_PEEK) == 0) {
                                so->so_oobmark -= len;
                                if (so->so_oobmark == 0) {
-                                       so->so_state |= SS_RCVATMARK;
+                                       so->so_rcv.sb_state |= SS_RCVATMARK;
                                        break;
                                }
                        } else {
@@ -1120,7 +1120,8 @@ dontblock:
                 */
                while (flags & MSG_WAITALL && m == NULL && uio->uio_resid > 0 &&
                    !sosendallatonce(so) && !nextrecord) {
-                       if (so->so_error || so->so_state & SS_CANTRCVMORE)
+                       if (so->so_rcv.sb_state & SS_CANTRCVMORE ||
+                           so->so_error)
                                break;
                        SBLASTRECORDCHK(&so->so_rcv, "soreceive sbwait 2");
                        SBLASTMBUFCHK(&so->so_rcv, "soreceive sbwait 2");
@@ -1160,7 +1161,8 @@ dontblock:
                        pru_rcvd(so);
        }
        if (orig_resid == uio->uio_resid && orig_resid &&
-           (flags & MSG_EOR) == 0 && (so->so_state & SS_CANTRCVMORE) == 0) {
+           (flags & MSG_EOR) == 0 &&
+           (so->so_rcv.sb_state & SS_CANTRCVMORE) == 0) {
                sbunlock(so, &so->so_rcv);
                goto restart;
        }
@@ -1632,13 +1634,13 @@ somove(struct socket *so, int wait)
                pru_rcvd(so);
 
        /* Receive buffer did shrink by len bytes, adjust oob. */
-       state = so->so_state;
-       so->so_state &= ~SS_RCVATMARK;
+       state = so->so_rcv.sb_state;
+       so->so_rcv.sb_state &= ~SS_RCVATMARK;
        oobmark = so->so_oobmark;
        so->so_oobmark = oobmark > len ? oobmark - len : 0;
        if (oobmark) {
                if (oobmark == len)
-                       so->so_state |= SS_RCVATMARK;
+                       so->so_rcv.sb_state |= SS_RCVATMARK;
                if (oobmark >= len)
                        oobmark = 0;
        }
@@ -1714,7 +1716,8 @@ somove(struct socket *so, int wait)
                error = EFBIG;
        if (error)
                so->so_error = error;
-       if (((so->so_state & SS_CANTRCVMORE) && so->so_rcv.sb_cc == 0) ||
+       if (((so->so_rcv.sb_state & SS_CANTRCVMORE) &&
+           so->so_rcv.sb_cc == 0) ||
            (sosp->so_snd.sb_state & SS_CANTSENDMORE) ||
            maxreached || error) {
                sounsplice(so, sosp, 0);
@@ -1850,7 +1853,7 @@ sosetopt(struct socket *so, int level, int optname, struct mbuf *m)
                                break;
 
                        case SO_RCVBUF:
-                               if (so->so_state & SS_CANTRCVMORE)
+                               if (so->so_rcv.sb_state & SS_CANTRCVMORE)
                                        return (EINVAL);
                                if (sbcheckreserve(cnt, so->so_rcv.sb_wat) ||
                                    sbreserve(so, &so->so_rcv, cnt))
@@ -2151,7 +2154,7 @@ filt_soread(struct knote *kn, long hint)
                rv = 0;
        } else
 #endif /* SOCKET_SPLICE */
-       if (so->so_state & SS_CANTRCVMORE) {
+       if (so->so_rcv.sb_state & SS_CANTRCVMORE) {
                kn->kn_flags |= EV_EOF;
                if (kn->kn_flags & __EV_POLL) {
                        if (so->so_state & SS_ISDISCONNECTED)
@@ -2223,7 +2226,7 @@ filt_soexcept(struct knote *kn, long hint)
        } else
 #endif /* SOCKET_SPLICE */
        if (kn->kn_sfflags & NOTE_OOB) {
-               if (so->so_oobmark || (so->so_state & SS_RCVATMARK)) {
+               if (so->so_oobmark || (so->so_rcv.sb_state & SS_RCVATMARK)) {
                        kn->kn_fflags |= NOTE_OOB;
                        kn->kn_data -= so->so_oobmark;
                        rv = 1;
index 3fb722b..4b6f1e9 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: uipc_socket2.c,v 1.132 2023/01/21 11:23:23 mvs Exp $  */
+/*     $OpenBSD: uipc_socket2.c,v 1.133 2023/01/22 12:05:44 mvs Exp $  */
 /*     $NetBSD: uipc_socket2.c,v 1.11 1996/02/04 02:17:55 christos Exp $       */
 
 /*
@@ -142,7 +142,8 @@ soisdisconnecting(struct socket *so)
 {
        soassertlocked(so);
        so->so_state &= ~SS_ISCONNECTING;
-       so->so_state |= (SS_ISDISCONNECTING|SS_CANTRCVMORE);
+       so->so_state |= SS_ISDISCONNECTING;
+       so->so_rcv.sb_state |= SS_CANTRCVMORE;
        so->so_snd.sb_state |= SS_CANTSENDMORE;
        wakeup(&so->so_timeo);
        sowwakeup(so);
@@ -154,7 +155,8 @@ soisdisconnected(struct socket *so)
 {
        soassertlocked(so);
        so->so_state &= ~(SS_ISCONNECTING|SS_ISCONNECTED|SS_ISDISCONNECTING);
-       so->so_state |= (SS_CANTRCVMORE|SS_ISDISCONNECTED);
+       so->so_state |= SS_ISDISCONNECTED;
+       so->so_rcv.sb_state |= SS_CANTRCVMORE;
        so->so_snd.sb_state |= SS_CANTSENDMORE;
        wakeup(&so->so_timeo);
        sowwakeup(so);
@@ -344,7 +346,7 @@ void
 socantrcvmore(struct socket *so)
 {
        soassertlocked(so);
-       so->so_state |= SS_CANTRCVMORE;
+       so->so_rcv.sb_state |= SS_CANTRCVMORE;
        sorwakeup(so);
 }
 
index 37ee487..8efc1a2 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: uipc_syscalls.c,v 1.208 2023/01/12 10:59:36 mvs Exp $ */
+/*     $OpenBSD: uipc_syscalls.c,v 1.209 2023/01/22 12:05:44 mvs Exp $ */
 /*     $NetBSD: uipc_syscalls.c,v 1.19 1996/02/09 19:00:48 christos Exp $      */
 
 /*
@@ -288,14 +288,14 @@ doaccept(struct proc *p, int sock, struct sockaddr *name, socklen_t *anamelen,
                goto out_unlock;
        }
        if ((headfp->f_flag & FNONBLOCK) && head->so_qlen == 0) {
-               if (head->so_state & SS_CANTRCVMORE)
+               if (head->so_rcv.sb_state & SS_CANTRCVMORE)
                        error = ECONNABORTED;
                else
                        error = EWOULDBLOCK;
                goto out_unlock;
        }
        while (head->so_qlen == 0 && head->so_error == 0) {
-               if (head->so_state & SS_CANTRCVMORE) {
+               if (head->so_rcv.sb_state & SS_CANTRCVMORE) {
                        head->so_error = ECONNABORTED;
                        break;
                }
index 3c60b67..f3f0e96 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: fifo_vnops.c,v 1.99 2023/01/21 11:23:23 mvs Exp $     */
+/*     $OpenBSD: fifo_vnops.c,v 1.100 2023/01/22 12:05:44 mvs Exp $    */
 /*     $NetBSD: fifo_vnops.c,v 1.18 1996/03/16 23:52:42 christos Exp $ */
 
 /*
@@ -199,7 +199,8 @@ fifo_open(void *v)
                }
                if (fip->fi_writers == 1) {
                        solock(rso);
-                       rso->so_state &= ~(SS_CANTRCVMORE|SS_ISDISCONNECTED);
+                       rso->so_state &= ~SS_ISDISCONNECTED;
+                       rso->so_rcv.sb_state &= ~SS_CANTRCVMORE;
                        sounlock(rso);
                        if (fip->fi_readers > 0)
                                wakeup(&fip->fi_readers);
@@ -525,7 +526,7 @@ filt_fiforead(struct knote *kn, long hint)
        soassertlocked(so);
 
        kn->kn_data = so->so_rcv.sb_cc;
-       if (so->so_state & SS_CANTRCVMORE) {
+       if (so->so_rcv.sb_state & SS_CANTRCVMORE) {
                kn->kn_flags |= EV_EOF;
                if (kn->kn_flags & __EV_POLL) {
                        if (so->so_state & SS_ISDISCONNECTED)
index c8c5f1b..19af84f 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: rtsock.c,v 1.358 2022/10/17 14:49:02 mvs Exp $        */
+/*     $OpenBSD: rtsock.c,v 1.359 2023/01/22 12:05:44 mvs Exp $        */
 /*     $NetBSD: rtsock.c,v 1.18 1996/03/29 00:32:10 cgd Exp $  */
 
 /*
@@ -464,7 +464,7 @@ rtm_senddesync(struct socket *so)
         * timeout(9), otherwise timeout_del_barrier(9) can't help us.
         */
        if ((so->so_state & SS_ISCONNECTED) == 0 ||
-           (so->so_state & SS_CANTRCVMORE))
+           (so->so_rcv.sb_state & SS_CANTRCVMORE))
                return;
 
        /* If we are in a DESYNC state, try to send a RTM_DESYNC packet */
@@ -524,7 +524,7 @@ route_input(struct mbuf *m0, struct socket *so0, sa_family_t sa_family)
                 */
                if ((so0 == so && !(so0->so_options & SO_USELOOPBACK)) ||
                    !(so->so_state & SS_ISCONNECTED) ||
-                   (so->so_state & SS_CANTRCVMORE))
+                   (so->so_rcv.sb_state & SS_CANTRCVMORE))
                        goto next;
 
                /* filter messages that the process does not want */
index 86c194a..66597c5 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: raw_ip.c,v 1.150 2022/10/17 14:49:02 mvs Exp $        */
+/*     $OpenBSD: raw_ip.c,v 1.151 2023/01/22 12:05:44 mvs Exp $        */
 /*     $NetBSD: raw_ip.c,v 1.25 1996/02/18 18:58:33 christos Exp $     */
 
 /*
@@ -171,7 +171,7 @@ rip_input(struct mbuf **mp, int *offp, int proto, int af)
        rw_enter_write(&rawcbtable.inpt_notify);
        mtx_enter(&rawcbtable.inpt_mtx);
        TAILQ_FOREACH(inp, &rawcbtable.inpt_queue, inp_queue) {
-               if (inp->inp_socket->so_state & SS_CANTRCVMORE)
+               if (inp->inp_socket->so_rcv.sb_state & SS_CANTRCVMORE)
                        continue;
 #ifdef INET6
                if (inp->inp_flags & INP_IPV6)
index 550a40c..e596477 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: tcp_input.c,v 1.385 2023/01/12 13:09:47 bluhm Exp $   */
+/*     $OpenBSD: tcp_input.c,v 1.386 2023/01/22 12:05:44 mvs Exp $     */
 /*     $NetBSD: tcp_input.c,v 1.23 1996/02/13 23:43:44 christos Exp $  */
 
 /*
@@ -340,7 +340,7 @@ tcp_flush_queue(struct tcpcb *tp)
                nq = TAILQ_NEXT(q, tcpqe_q);
                TAILQ_REMOVE(&tp->t_segq, q, tcpqe_q);
                ND6_HINT(tp);
-               if (so->so_state & SS_CANTRCVMORE)
+               if (so->so_rcv.sb_state & SS_CANTRCVMORE)
                        m_freem(q->tcpqe_m);
                else
                        sbappendstream(so, &so->so_rcv, q->tcpqe_m);
@@ -1041,7 +1041,7 @@ findpcb:
                         * Drop TCP, IP headers and TCP options then add data
                         * to socket buffer.
                         */
-                       if (so->so_state & SS_CANTRCVMORE)
+                       if (so->so_rcv.sb_state & SS_CANTRCVMORE)
                                m_freem(m);
                        else {
                                if (tp->t_srtt != 0 && tp->rfbuf_ts != 0 &&
@@ -1794,7 +1794,7 @@ trimthenstep6:
                                 * specification, but if we don't get a FIN
                                 * we'll hang forever.
                                 */
-                               if (so->so_state & SS_CANTRCVMORE) {
+                               if (so->so_rcv.sb_state & SS_CANTRCVMORE) {
                                        tp->t_flags |= TF_BLOCKOUTPUT;
                                        soisdisconnected(so);
                                        tp->t_flags &= ~TF_BLOCKOUTPUT;
@@ -1903,7 +1903,7 @@ step6:
                        so->so_oobmark = so->so_rcv.sb_cc +
                            (tp->rcv_up - tp->rcv_nxt) - 1;
                        if (so->so_oobmark == 0)
-                               so->so_state |= SS_RCVATMARK;
+                               so->so_rcv.sb_state |= SS_RCVATMARK;
                        sohasoutofband(so);
                        tp->t_oobflags &= ~(TCPOOB_HAVEDATA | TCPOOB_HADDATA);
                }
@@ -1946,7 +1946,7 @@ dodata:                                                   /* XXX */
                        tiflags = th->th_flags & TH_FIN;
                        tcpstat_pkt(tcps_rcvpack, tcps_rcvbyte, tlen);
                        ND6_HINT(tp);
-                       if (so->so_state & SS_CANTRCVMORE)
+                       if (so->so_rcv.sb_state & SS_CANTRCVMORE)
                                m_freem(m);
                        else {
                                m_adj(m, hdroptlen);
index 9ce6f05..3297953 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: tcp_usrreq.c,v 1.215 2023/01/21 11:23:24 mvs Exp $    */
+/*     $OpenBSD: tcp_usrreq.c,v 1.216 2023/01/22 12:05:44 mvs Exp $    */
 /*     $NetBSD: tcp_usrreq.c,v 1.20 1996/02/13 23:44:16 christos Exp $ */
 
 /*
@@ -918,7 +918,7 @@ tcp_rcvoob(struct socket *so, struct mbuf *m, int flags)
                return (error);
 
        if ((so->so_oobmark == 0 &&
-           (so->so_state & SS_RCVATMARK) == 0) ||
+           (so->so_rcv.sb_state & SS_RCVATMARK) == 0) ||
            so->so_options & SO_OOBINLINE ||
            tp->t_oobflags & TCPOOB_HADDATA) {
                error = EINVAL;
index f28df13..89a18a9 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: udp_usrreq.c,v 1.304 2022/10/17 14:49:02 mvs Exp $    */
+/*     $OpenBSD: udp_usrreq.c,v 1.305 2023/01/22 12:05:44 mvs Exp $    */
 /*     $NetBSD: udp_usrreq.c,v 1.28 1996/03/16 23:54:03 christos Exp $ */
 
 /*
@@ -400,7 +400,7 @@ udp_input(struct mbuf **mp, int *offp, int proto, int af)
                rw_enter_write(&udbtable.inpt_notify);
                mtx_enter(&udbtable.inpt_mtx);
                TAILQ_FOREACH(inp, &udbtable.inpt_queue, inp_queue) {
-                       if (inp->inp_socket->so_state & SS_CANTRCVMORE)
+                       if (inp->inp_socket->so_rcv.sb_state & SS_CANTRCVMORE)
                                continue;
 #ifdef INET6
                        /* don't accept it if AF does not match */
index a161cef..1ef5014 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: raw_ip6.c,v 1.171 2022/10/17 14:49:02 mvs Exp $       */
+/*     $OpenBSD: raw_ip6.c,v 1.172 2023/01/22 12:05:44 mvs Exp $       */
 /*     $KAME: raw_ip6.c,v 1.69 2001/03/04 15:55:44 itojun Exp $        */
 
 /*
@@ -183,7 +183,7 @@ rip6_input(struct mbuf **mp, int *offp, int proto, int af)
        rw_enter_write(&rawin6pcbtable.inpt_notify);
        mtx_enter(&rawin6pcbtable.inpt_mtx);
        TAILQ_FOREACH(in6p, &rawin6pcbtable.inpt_queue, inp_queue) {
-               if (in6p->inp_socket->so_state & SS_CANTRCVMORE)
+               if (in6p->inp_socket->so_rcv.sb_state & SS_CANTRCVMORE)
                        continue;
                if (rtable_l2(in6p->inp_rtableid) !=
                    rtable_l2(m->m_pkthdr.ph_rtableid))
index 659a226..c99caac 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: socketvar.h,v 1.115 2023/01/21 11:23:24 mvs Exp $     */
+/*     $OpenBSD: socketvar.h,v 1.116 2023/01/22 12:05:44 mvs Exp $     */
 /*     $NetBSD: socketvar.h,v 1.18 1996/02/09 18:25:38 christos Exp $  */
 
 /*-
@@ -147,6 +147,8 @@ struct socket {
  * buffer `sb_state' only:
  *
  *     SS_CANTSENDMORE         with `so_snd' 
+ *     SS_CANTRCVMORE          with `so_rcv'
+ *     SS_RCVATMARK            with `so_rcv'
  */
 
 #define        SS_NOFDREF              0x001   /* no file table ref any more */
@@ -232,8 +234,8 @@ soreadable(struct socket *so)
        soassertlocked(so);
        if (isspliced(so))
                return 0;
-       return (so->so_state & SS_CANTRCVMORE) || so->so_qlen || so->so_error ||
-           so->so_rcv.sb_cc >= so->so_rcv.sb_lowat;
+       return (so->so_rcv.sb_state & SS_CANTRCVMORE) || so->so_qlen ||
+           so->so_error || so->so_rcv.sb_cc >= so->so_rcv.sb_lowat;
 }
 
 /* can we write something to so? */