From 6d49aa6ffaff1e5a2ff3abe70c453cc8b47adb73 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Sun, 22 Apr 2007 01:13:17 +0000 Subject: [PATCH] Give the sockbuf structure its own header file and supporting source file. Move all sockbuf-specific functions from kern/uipc_socket2.c into the new kern/uipc_sockbuf.c and move all the sockbuf-specific structures from sys/socketvar.h to sys/sockbuf.h. Change the sockbuf structure to only contain those fields required to properly management a chain of mbufs. Create a signalsockbuf structure to hold the remaining fields (e.g. selinfo, mbmax, etc). Change the so_rcv and so_snd structures in the struct socket from a sockbuf to a signalsockbuf. Remove the recently added sorecv_direct structure which was being used to provide a direct mbuf path to consumers for socket I/O. Use the newly revamped sockbuf base structure instead. This gives mbuf consumers direct access to the sockbuf API functions for use outside of a struct socket. This will also allow new API functions to be added to the sockbuf interface to ease the job of parsing data out of chained mbufs. --- sys/conf/files | 3 +- sys/kern/sys_socket.c | 16 +- sys/kern/uipc_msg.c | 16 +- sys/kern/uipc_sockbuf.c | 564 +++++++++++++++++++++ sys/kern/uipc_socket.c | 214 ++++---- sys/kern/uipc_socket2.c | 804 +++++------------------------- sys/kern/uipc_syscalls.c | 34 +- sys/kern/uipc_usrreq.c | 46 +- sys/kern/vfs_aio.c | 20 +- sys/net/accf_data/accf_data.c | 4 +- sys/net/accf_http/accf_http.c | 37 +- sys/net/ip_mroute/ip_mroute.c | 10 +- sys/net/netmsg.h | 4 +- sys/net/raw_usrreq.c | 6 +- sys/netgraph/ksocket/ng_ksocket.c | 30 +- sys/netgraph/socket/ng_socket.c | 6 +- sys/netinet/ip_divert.c | 4 +- sys/netinet/raw_ip.c | 6 +- sys/netinet/sctp_indata.c | 44 +- sys/netinet/sctp_input.c | 10 +- sys/netinet/sctp_output.c | 66 +-- sys/netinet/sctp_pcb.c | 12 +- sys/netinet/sctp_usrreq.c | 14 +- sys/netinet/sctp_var.h | 4 +- sys/netinet/sctputil.c | 206 ++------ sys/netinet/sctputil.h | 4 +- sys/netinet/tcp_input.c | 42 +- sys/netinet/tcp_output.c | 28 +- sys/netinet/tcp_sack.c | 4 +- sys/netinet/tcp_subr.c | 10 +- sys/netinet/tcp_syncache.c | 10 +- sys/netinet/tcp_usrreq.c | 18 +- sys/netinet/udp_usrreq.c | 6 +- sys/netinet6/icmp6.c | 6 +- sys/netinet6/ip6_mroute.c | 4 +- sys/netinet6/raw_ip6.c | 6 +- sys/netinet6/sctp6_usrreq.c | 6 +- sys/netinet6/udp6_usrreq.c | 12 +- sys/netproto/atalk/ddp_input.c | 4 +- sys/netproto/atm/atm_aal5.c | 10 +- sys/netproto/atm/atm_socket.c | 4 +- sys/netproto/ipsec/keysock.c | 8 +- sys/netproto/ipx/ipx_usrreq.c | 4 +- sys/netproto/ipx/spx_usrreq.c | 58 +-- sys/netproto/key/keysock.c | 8 +- sys/netproto/natm/natm.c | 12 +- sys/netproto/natm/natm.h | 4 +- sys/netproto/ncp/ncp_ncp.c | 14 +- sys/netproto/ncp/ncp_sock.c | 22 +- sys/netproto/ncp/ncp_sock.h | 4 +- sys/netproto/ns/idp_usrreq.c | 4 +- sys/netproto/ns/spp_usrreq.c | 58 +-- sys/netproto/smb/smb_trantcp.c | 38 +- sys/sys/aio.h | 6 +- sys/sys/protosw.h | 8 +- sys/sys/sockbuf.h | 124 +++++ sys/sys/socketops.h | 4 +- sys/sys/socketvar.h | 268 +++++----- sys/vfs/fifofs/fifo_vnops.c | 27 +- sys/vfs/nfs/krpc_subr.c | 10 +- sys/vfs/nfs/nfs_socket.c | 66 +-- sys/vfs/nfs/nfs_syscalls.c | 14 +- sys/vfs/portal/portal_vnops.c | 18 +- 63 files changed, 1551 insertions(+), 1582 deletions(-) create mode 100644 sys/kern/uipc_sockbuf.c create mode 100644 sys/sys/sockbuf.h diff --git a/sys/conf/files b/sys/conf/files index eaf8e437b8..e2e0c1fbb8 100644 --- a/sys/conf/files +++ b/sys/conf/files @@ -1,5 +1,5 @@ # $FreeBSD: src/sys/conf/files,v 1.340.2.137 2003/06/04 17:10:30 sam Exp $ -# $DragonFly: src/sys/conf/files,v 1.156 2007/04/09 17:09:56 dillon Exp $ +# $DragonFly: src/sys/conf/files,v 1.157 2007/04/22 01:13:08 dillon Exp $ # # The long compile-with and dependency lines are required because of # limitations in config: backslash-newline doesn't work in strings, and @@ -613,6 +613,7 @@ kern/uipc_accf.c optional inet kern/uipc_domain.c standard kern/uipc_mbuf.c standard kern/uipc_mbuf2.c standard +kern/uipc_sockbuf.c standard kern/uipc_msg.c standard kern/uipc_proto.c standard kern/uipc_socket.c standard diff --git a/sys/kern/sys_socket.c b/sys/kern/sys_socket.c index dad3d77012..0cc3b7803a 100644 --- a/sys/kern/sys_socket.c +++ b/sys/kern/sys_socket.c @@ -32,7 +32,7 @@ * * @(#)sys_socket.c 8.1 (Berkeley) 6/10/93 * $FreeBSD: src/sys/kern/sys_socket.c,v 1.28.2.2 2001/02/26 04:23:16 jlemon Exp $ - * $DragonFly: src/sys/kern/sys_socket.c,v 1.13 2006/08/02 01:25:25 dillon Exp $ + * $DragonFly: src/sys/kern/sys_socket.c,v 1.14 2007/04/22 01:13:10 dillon Exp $ */ #include @@ -135,17 +135,17 @@ soo_ioctl(struct file *fp, u_long cmd, caddr_t data, struct ucred *cred) case FIOASYNC: if (*(int *)data) { so->so_state |= SS_ASYNC; - so->so_rcv.sb_flags |= SB_ASYNC; - so->so_snd.sb_flags |= SB_ASYNC; + so->so_rcv.ssb_flags |= SSB_ASYNC; + so->so_snd.ssb_flags |= SSB_ASYNC; } else { so->so_state &= ~SS_ASYNC; - so->so_rcv.sb_flags &= ~SB_ASYNC; - so->so_snd.sb_flags &= ~SB_ASYNC; + so->so_rcv.ssb_flags &= ~SSB_ASYNC; + so->so_snd.ssb_flags &= ~SSB_ASYNC; } error = 0; break; case FIONREAD: - *(int *)data = so->so_rcv.sb_cc; + *(int *)data = so->so_rcv.ssb_cc; error = 0; break; case FIOSETOWN: @@ -218,11 +218,11 @@ soo_stat(struct file *fp, struct stat *ub, struct ucred *cred) * receive buffer, the socket is still readable. */ if ((so->so_state & SS_CANTRCVMORE) == 0 || - so->so_rcv.sb_cc != 0) + so->so_rcv.ssb_cc != 0) ub->st_mode |= S_IRUSR | S_IRGRP | S_IROTH; if ((so->so_state & SS_CANTSENDMORE) == 0) ub->st_mode |= S_IWUSR | S_IWGRP | S_IWOTH; - ub->st_size = so->so_rcv.sb_cc; + ub->st_size = so->so_rcv.ssb_cc; ub->st_uid = so->so_cred->cr_uid; ub->st_gid = so->so_cred->cr_gid; error = so_pru_sense(so, ub); diff --git a/sys/kern/uipc_msg.c b/sys/kern/uipc_msg.c index a60e3ed5f2..b683a355d4 100644 --- a/sys/kern/uipc_msg.c +++ b/sys/kern/uipc_msg.c @@ -30,7 +30,7 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sys/kern/uipc_msg.c,v 1.15 2007/03/04 18:51:59 swildner Exp $ + * $DragonFly: src/sys/kern/uipc_msg.c,v 1.16 2007/04/22 01:13:10 dillon Exp $ */ #include @@ -597,9 +597,9 @@ int netmsg_so_notify(lwkt_msg_t lmsg) { struct netmsg_so_notify *msg = (void *)lmsg; - struct sockbuf *sb; + struct signalsockbuf *ssb; - sb = (msg->nm_etype & NM_REVENT) ? + ssb = (msg->nm_etype & NM_REVENT) ? &msg->nm_so->so_rcv : &msg->nm_so->so_snd; @@ -610,8 +610,8 @@ netmsg_so_notify(lwkt_msg_t lmsg) if (msg->nm_predicate((struct netmsg *)msg)) { lwkt_replymsg(lmsg, lmsg->ms_error); } else { - TAILQ_INSERT_TAIL(&sb->sb_sel.si_mlist, msg, nm_list); - sb->sb_flags |= SB_MEVENT; + TAILQ_INSERT_TAIL(&ssb->ssb_sel.si_mlist, msg, nm_list); + ssb->ssb_flags |= SSB_MEVENT; } return(EASYNC); } @@ -626,12 +626,12 @@ int netmsg_so_notify_abort(lwkt_msg_t lmsg) { struct netmsg_so_notify *msg = (void *)lmsg; - struct sockbuf *sb; + struct signalsockbuf *ssb; - sb = (msg->nm_etype & NM_REVENT) ? + ssb = (msg->nm_etype & NM_REVENT) ? &msg->nm_so->so_rcv : &msg->nm_so->so_snd; - TAILQ_REMOVE(&sb->sb_sel.si_mlist, msg, nm_list); + TAILQ_REMOVE(&ssb->ssb_sel.si_mlist, msg, nm_list); lwkt_replymsg(lmsg, EINTR); return(EASYNC); } diff --git a/sys/kern/uipc_sockbuf.c b/sys/kern/uipc_sockbuf.c new file mode 100644 index 0000000000..1c7dd3de52 --- /dev/null +++ b/sys/kern/uipc_sockbuf.c @@ -0,0 +1,564 @@ +/* + * Copyright (c) 2005 Jeffrey M. Hsu. All rights reserved. + * Copyright (c) 1982, 1986, 1988, 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)uipc_socket2.c 8.1 (Berkeley) 6/10/93 + * $FreeBSD: src/sys/kern/uipc_socket2.c,v 1.55.2.17 2002/08/31 19:04:55 dwmalone Exp $ + * $DragonFly: src/sys/kern/uipc_sockbuf.c,v 1.1 2007/04/22 01:13:10 dillon Exp $ + */ + +#include "opt_param.h" +#include +#include +#include +#include /* for maxfiles */ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +/* + * Routines to add and remove + * data from an mbuf queue. + * + * The routines sbappend() or sbappendrecord() are normally called to + * append new mbufs to a socket buffer, after checking that adequate + * space is available, comparing the function sbspace() with the amount + * of data to be added. sbappendrecord() differs from sbappend() in + * that data supplied is treated as the beginning of a new record. + * To place a sender's address, optional access rights, and data in a + * socket receive buffer, sbappendaddr() should be used. To place + * access rights and data in a socket receive buffer, sbappendrights() + * should be used. In either case, the new data begins a new record. + * Note that unlike sbappend() and sbappendrecord(), these routines check + * for the caller that there will be enough space to store the data. + * Each fails if there is not enough space, or if it cannot find mbufs + * to store additional information in. + * + * Reliable protocols may use the socket send buffer to hold data + * awaiting acknowledgement. Data is normally copied from a socket + * send buffer in a protocol with m_copy for output to a peer, + * and then removing the data from the socket buffer with sbdrop() + * or sbdroprecord() when the data is acknowledged by the peer. + */ + +/* + * Append mbuf chain m to the last record in the + * socket buffer sb. The additional space associated + * the mbuf chain is recorded in sb. Empty mbufs are + * discarded and mbufs are compacted where possible. + */ +void +sbappend(struct sockbuf *sb, struct mbuf *m) +{ + struct mbuf *n; + + if (m) { + n = sb->sb_mb; + if (n) { + while (n->m_nextpkt) + n = n->m_nextpkt; + do { + if (n->m_flags & M_EOR) { + /* XXXXXX!!!! */ + sbappendrecord(sb, m); + return; + } + } while (n->m_next && (n = n->m_next)); + } + sbcompress(sb, m, n); + } +} + +/* + * sbappendstream() is an optimized form of sbappend() for protocols + * such as TCP that only have one record in the socket buffer, are + * not PR_ATOMIC, nor allow MT_CONTROL data. A protocol that uses + * sbappendstream() must use sbappendstream() exclusively. + */ +void +sbappendstream(struct sockbuf *sb, struct mbuf *m) +{ + KKASSERT(m->m_nextpkt == NULL); + sbcompress(sb, m, sb->sb_lastmbuf); +} + +#ifdef SOCKBUF_DEBUG + +void +_sbcheck(struct sockbuf *sb) +{ + struct mbuf *m; + struct mbuf *n = NULL; + u_long len = 0, mbcnt = 0; + + for (m = sb->sb_mb; m; m = n) { + n = m->m_nextpkt; + if (n == NULL && sb->sb_lastrecord != m) { + kprintf("sockbuf %p mismatched lastrecord %p vs %p\n", sb, sb->sb_lastrecord, m); + panic("sbcheck1"); + + } + for (; m; m = m->m_next) { + len += m->m_len; + mbcnt += MSIZE; + if (m->m_flags & M_EXT) /*XXX*/ /* pretty sure this is bogus */ + mbcnt += m->m_ext.ext_size; + if (n == NULL && m->m_next == NULL) { + if (sb->sb_lastmbuf != m) { + kprintf("sockbuf %p mismatched lastmbuf %p vs %p\n", sb, sb->sb_lastmbuf, m); + panic("sbcheck2"); + } + } + } + } + if (sb->sb_mb == NULL) { + if (sb->sb_lastrecord != NULL) { + kprintf("sockbuf %p is empty, lastrecord not NULL: %p\n", + sb, sb->sb_lastrecord); + panic("sbcheck3"); + } + if (sb->sb_lastmbuf != NULL) { + kprintf("sockbuf %p is empty, lastmbuf not NULL: %p\n", + sb, sb->sb_lastmbuf); + panic("sbcheck4"); + } + } + if (len != sb->sb_cc || mbcnt != sb->sb_mbcnt) { + kprintf("sockbuf %p cc %ld != %ld || mbcnt %ld != %ld\n", + sb, len, sb->sb_cc, mbcnt, sb->sb_mbcnt); + panic("sbcheck5"); + } +} + +#endif + +/* + * Same as sbappend(), except the mbuf chain begins a new record. + */ +void +sbappendrecord(struct sockbuf *sb, struct mbuf *m0) +{ + struct mbuf *firstmbuf; + struct mbuf *secondmbuf; + + if (m0 == NULL) + return; + + sbcheck(sb); + + /* + * Break the first mbuf off from the rest of the mbuf chain. + */ + firstmbuf = m0; + secondmbuf = m0->m_next; + m0->m_next = NULL; + + /* + * Insert the first mbuf of the m0 mbuf chain as the last record of + * the sockbuf. Note this permits zero length records! Keep the + * sockbuf state consistent. + */ + if (sb->sb_mb == NULL) + sb->sb_mb = firstmbuf; + else + sb->sb_lastrecord->m_nextpkt = firstmbuf; + sb->sb_lastrecord = firstmbuf; /* update hint for new last record */ + sb->sb_lastmbuf = firstmbuf; /* update hint for new last mbuf */ + + if ((firstmbuf->m_flags & M_EOR) && (secondmbuf != NULL)) { + /* propagate the EOR flag */ + firstmbuf->m_flags &= ~M_EOR; + secondmbuf->m_flags |= M_EOR; + } + + /* + * The succeeding call to sbcompress() omits accounting for + * the first mbuf, so do it here. + */ + sballoc(sb, firstmbuf); + + /* Compact the rest of the mbuf chain in after the first mbuf. */ + sbcompress(sb, secondmbuf, firstmbuf); +} + +/* + * Append address and data, and optionally, control (ancillary) data + * to the receive queue of a socket. If present, + * m0 must include a packet header with total length. + * Returns 0 if no space in sockbuf or insufficient mbufs. + */ +int +sbappendaddr(struct sockbuf *sb, const struct sockaddr *asa, struct mbuf *m0, + struct mbuf *control) +{ + struct mbuf *m, *n; + int space = asa->sa_len; + + if (m0 && (m0->m_flags & M_PKTHDR) == 0) + panic("sbappendaddr"); + sbcheck(sb); + + if (m0) + space += m0->m_pkthdr.len; + for (n = control; n; n = n->m_next) { + space += n->m_len; + if (n->m_next == 0) /* keep pointer to last control buf */ + break; + } +#if 0 + if (space > sbspace(sb)) + return (0); +#endif + if (asa->sa_len > MLEN) + return (0); + MGET(m, MB_DONTWAIT, MT_SONAME); + if (m == NULL) + return (0); + KKASSERT(m->m_nextpkt == NULL); + m->m_len = asa->sa_len; + bcopy(asa, mtod(m, caddr_t), asa->sa_len); + if (n) + n->m_next = m0; /* concatenate data to control */ + else + control = m0; + m->m_next = control; + for (n = m; n; n = n->m_next) + sballoc(sb, n); + + if (sb->sb_mb == NULL) + sb->sb_mb = m; + else + sb->sb_lastrecord->m_nextpkt = m; + sb->sb_lastrecord = m; + while (m->m_next) + m = m->m_next; + sb->sb_lastmbuf = m; + + return (1); +} + +/* + * Append control information followed by data. + * control must be non-null. + */ +int +sbappendcontrol(struct sockbuf *sb, struct mbuf *m0, struct mbuf *control) +{ + struct mbuf *n; + u_int length, cmbcnt, m0mbcnt; + + KASSERT(control != NULL, ("sbappendcontrol")); + KKASSERT(control->m_nextpkt == NULL); + sbcheck(sb); + + length = m_countm(control, &n, &cmbcnt) + m_countm(m0, NULL, &m0mbcnt); +#if 0 + if (length > sbspace(sb)) + return (0); +#endif + + n->m_next = m0; /* concatenate data to control */ + + if (sb->sb_mb == NULL) + sb->sb_mb = control; + else + sb->sb_lastrecord->m_nextpkt = control; + sb->sb_lastrecord = control; + sb->sb_lastmbuf = m0; + + sb->sb_cc += length; + sb->sb_mbcnt += cmbcnt + m0mbcnt; + + return (1); +} + +/* + * Compress mbuf chain m into the socket buffer sb following mbuf tailm. + * If tailm is null, the buffer is presumed empty. Also, as a side-effect, + * increment the sockbuf counts for each mbuf in the chain. + */ +void +sbcompress(struct sockbuf *sb, struct mbuf *m, struct mbuf *tailm) +{ + int eor = 0; + struct mbuf *free_chain = NULL; + + sbcheck(sb); + while (m) { + struct mbuf *o; + + eor |= m->m_flags & M_EOR; + /* + * Disregard empty mbufs as long as we don't encounter + * an end-of-record or there is a trailing mbuf of + * the same type to propagate the EOR flag to. + * + * Defer the m_free() call because it can block and break + * the atomicy of the sockbuf. + */ + if (m->m_len == 0 && + (eor == 0 || + (((o = m->m_next) || (o = tailm)) && + o->m_type == m->m_type))) { + o = m->m_next; + m->m_next = free_chain; + free_chain = m; + m = o; + continue; + } + + /* See if we can coalesce with preceding mbuf. */ + if (tailm && !(tailm->m_flags & M_EOR) && M_WRITABLE(tailm) && + m->m_len <= MCLBYTES / 4 && /* XXX: Don't copy too much */ + m->m_len <= M_TRAILINGSPACE(tailm) && + tailm->m_type == m->m_type) { + bcopy(mtod(m, caddr_t), + mtod(tailm, caddr_t) + tailm->m_len, + (unsigned)m->m_len); + tailm->m_len += m->m_len; + sb->sb_cc += m->m_len; /* update sb counter */ + o = m->m_next; + m->m_next = free_chain; + free_chain = m; + m = o; + continue; + } + + /* Insert whole mbuf. */ + if (tailm == NULL) { + KASSERT(sb->sb_mb == NULL, + ("sbcompress: sb_mb not NULL")); + sb->sb_mb = m; /* only mbuf in sockbuf */ + sb->sb_lastrecord = m; /* new last record */ + } else { + tailm->m_next = m; /* tack m on following tailm */ + } + sb->sb_lastmbuf = m; /* update last mbuf hint */ + + tailm = m; /* just inserted mbuf becomes the new tail */ + m = m->m_next; /* advance to next mbuf */ + tailm->m_next = NULL; /* split inserted mbuf off from chain */ + + /* update sb counters for just added mbuf */ + sballoc(sb, tailm); + + /* clear EOR on intermediate mbufs */ + tailm->m_flags &= ~M_EOR; + } + + /* + * Propogate EOR to the last mbuf + */ + if (eor) { + if (tailm) + tailm->m_flags |= eor; + else + kprintf("semi-panic: sbcompress"); + } + + /* + * Clean up any defered frees. + */ + while (free_chain) + free_chain = m_free(free_chain); + + sbcheck(sb); +} + +/* + * Free all mbufs in a sockbuf. + * Check that all resources are reclaimed. + */ +void +sbflush(struct sockbuf *sb) +{ + while (sb->sb_mbcnt) { + /* + * Don't call sbdrop(sb, 0) if the leading mbuf is non-empty: + * we would loop forever. Panic instead. + */ + if (!sb->sb_cc && (sb->sb_mb == NULL || sb->sb_mb->m_len)) + break; + sbdrop(sb, (int)sb->sb_cc); + } + KASSERT(!(sb->sb_cc || sb->sb_mb || sb->sb_mbcnt || sb->sb_lastmbuf), + ("sbflush: cc %ld || mb %p || mbcnt %ld || lastmbuf %p", + sb->sb_cc, sb->sb_mb, sb->sb_mbcnt, sb->sb_lastmbuf)); +} + +/* + * Drop data from (the front of) a sockbuf. + */ +void +sbdrop(struct sockbuf *sb, int len) +{ + struct mbuf *m; + struct mbuf *free_chain = NULL; + + sbcheck(sb); + crit_enter(); + + /* + * Remove mbufs from multiple records until the count is exhausted. + */ + m = sb->sb_mb; + while (m && len > 0) { + if (m->m_len > len) { + m->m_len -= len; + m->m_data += len; + sb->sb_cc -= len; + break; + } + len -= m->m_len; + m = sbunlinkmbuf(sb, m, &free_chain); + if (m == NULL && len) + m = sb->sb_mb; + } + + /* + * Remove any trailing 0-length mbufs in the current record. If + * the last record for which data was removed is now empty, m will be + * NULL. + */ + while (m && m->m_len == 0) { + m = sbunlinkmbuf(sb, m, &free_chain); + } + crit_exit(); + if (free_chain) + m_freem(free_chain); + sbcheck(sb); +} + +/* + * Drop a record off the front of a sockbuf and move the next record + * to the front. + * + * Must be called while holding a critical section. + */ +void +sbdroprecord(struct sockbuf *sb) +{ + struct mbuf *m; + struct mbuf *n; + + sbcheck(sb); + m = sb->sb_mb; + if (m) { + if ((sb->sb_mb = m->m_nextpkt) == NULL) { + sb->sb_lastrecord = NULL; + sb->sb_lastmbuf = NULL; + } + m->m_nextpkt = NULL; + for (n = m; n; n = n->m_next) + sbfree(sb, n); + m_freem(m); + sbcheck(sb); + } +} + +/* + * Drop the first mbuf off the sockbuf and move the next mbuf to the front. + * Currently only the head mbuf of the sockbuf may be dropped this way. + * + * The next mbuf in the same record as the mbuf being removed is returned + * or NULL if the record is exhausted. Note that other records may remain + * in the sockbuf when NULL is returned. + * + * Must be called while holding a critical section. + */ +struct mbuf * +sbunlinkmbuf(struct sockbuf *sb, struct mbuf *m, struct mbuf **free_chain) +{ + struct mbuf *n; + + KKASSERT(sb->sb_mb == m); + sbfree(sb, m); + n = m->m_next; + if (n) { + sb->sb_mb = n; + if (sb->sb_lastrecord == m) + sb->sb_lastrecord = n; + KKASSERT(sb->sb_lastmbuf != m); + n->m_nextpkt = m->m_nextpkt; + } else { + sb->sb_mb = m->m_nextpkt; + if (sb->sb_lastrecord == m) { + KKASSERT(sb->sb_mb == NULL); + sb->sb_lastrecord = NULL; + } + if (sb->sb_mb == NULL) + sb->sb_lastmbuf = NULL; + } + m->m_nextpkt = NULL; + if (free_chain) { + m->m_next = *free_chain; + *free_chain = m; + } else { + m->m_next = NULL; + } + return(n); +} + +/* + * Create a "control" mbuf containing the specified data + * with the specified type for presentation on a socket buffer. + */ +struct mbuf * +sbcreatecontrol(caddr_t p, int size, int type, int level) +{ + struct cmsghdr *cp; + struct mbuf *m; + + if (CMSG_SPACE((u_int)size) > MCLBYTES) + return (NULL); + m = m_getl(CMSG_SPACE((u_int)size), MB_DONTWAIT, MT_CONTROL, 0, NULL); + if (m == NULL) + return (NULL); + m->m_len = CMSG_SPACE(size); + cp = mtod(m, struct cmsghdr *); + if (p != NULL) + memcpy(CMSG_DATA(cp), p, size); + cp->cmsg_len = CMSG_LEN(size); + cp->cmsg_level = level; + cp->cmsg_type = type; + return (m); +} + diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c index ffa8cf05d7..284348667a 100644 --- a/sys/kern/uipc_socket.c +++ b/sys/kern/uipc_socket.c @@ -65,7 +65,7 @@ * * @(#)uipc_socket.c 8.3 (Berkeley) 4/15/94 * $FreeBSD: src/sys/kern/uipc_socket.c,v 1.68.2.24 2003/11/11 17:18:18 silby Exp $ - * $DragonFly: src/sys/kern/uipc_socket.c,v 1.44 2007/04/20 05:42:20 dillon Exp $ + * $DragonFly: src/sys/kern/uipc_socket.c,v 1.45 2007/04/22 01:13:10 dillon Exp $ */ #include "opt_inet.h" @@ -150,8 +150,8 @@ soalloc(int waitok) /* XXX race condition for reentrant kernel */ bzero(so, sizeof *so); TAILQ_INIT(&so->so_aiojobq); - TAILQ_INIT(&so->so_rcv.sb_sel.si_mlist); - TAILQ_INIT(&so->so_snd.sb_sel.si_mlist); + TAILQ_INIT(&so->so_rcv.ssb_sel.si_mlist); + TAILQ_INIT(&so->so_snd.ssb_sel.si_mlist); } return so; } @@ -220,12 +220,12 @@ sobind(struct socket *so, struct sockaddr *nam, struct thread *td) void sodealloc(struct socket *so) { - if (so->so_rcv.sb_hiwat) + if (so->so_rcv.ssb_hiwat) (void)chgsbsize(so->so_cred->cr_uidinfo, - &so->so_rcv.sb_hiwat, 0, RLIM_INFINITY); - if (so->so_snd.sb_hiwat) + &so->so_rcv.ssb_hiwat, 0, RLIM_INFINITY); + if (so->so_snd.ssb_hiwat) (void)chgsbsize(so->so_cred->cr_uidinfo, - &so->so_snd.sb_hiwat, 0, RLIM_INFINITY); + &so->so_snd.ssb_hiwat, 0, RLIM_INFINITY); #ifdef INET /* remove accept filter if present */ if (so->so_accf != NULL) @@ -302,7 +302,7 @@ sofree(struct socket *so) so->so_state &= ~SS_INCOMP; so->so_head = NULL; } - sbrelease(&so->so_snd, so); + ssb_release(&so->so_snd, so); sorflush(so); sodealloc(so); } @@ -524,7 +524,7 @@ sosend(struct socket *so, struct sockaddr *addr, struct uio *uio, #define gotoerr(errcode) { error = errcode; crit_exit(); goto release; } restart: - error = sblock(&so->so_snd, SBLOCKWAIT(flags)); + error = ssb_lock(&so->so_snd, SBLOCKWAIT(flags)); if (error) goto out; do { @@ -553,18 +553,18 @@ restart: gotoerr(so->so_proto->pr_flags & PR_CONNREQUIRED ? ENOTCONN : EDESTADDRREQ); } - space = sbspace(&so->so_snd); + space = ssb_space(&so->so_snd); if (flags & MSG_OOB) space += 1024; - if ((atomic && resid > so->so_snd.sb_hiwat) || - clen > so->so_snd.sb_hiwat) + if ((atomic && resid > so->so_snd.ssb_hiwat) || + clen > so->so_snd.ssb_hiwat) gotoerr(EMSGSIZE); if (space < resid + clen && uio && - (atomic || space < so->so_snd.sb_lowat || space < clen)) { + (atomic || space < so->so_snd.ssb_lowat || space < clen)) { if (flags & (MSG_FNONBLOCKING|MSG_DONTWAIT)) gotoerr(EWOULDBLOCK); - sbunlock(&so->so_snd); - error = sbwait(&so->so_snd); + ssb_unlock(&so->so_snd); + error = ssb_wait(&so->so_snd); crit_exit(); if (error) goto out; @@ -655,7 +655,7 @@ restart: } while (resid); release: - sbunlock(&so->so_snd); + ssb_unlock(&so->so_snd); out: if (top) m_freem(top); @@ -692,7 +692,7 @@ sosendudp(struct socket *so, struct sockaddr *addr, struct uio *uio, resid = uio ? uio->uio_resid : top->m_pkthdr.len; restart: - error = sblock(&so->so_snd, SBLOCKWAIT(flags)); + error = ssb_lock(&so->so_snd, SBLOCKWAIT(flags)); if (error) goto out; @@ -707,13 +707,13 @@ restart: } if (!(so->so_state & SS_ISCONNECTED) && addr == NULL) gotoerr(EDESTADDRREQ); - if (resid > so->so_snd.sb_hiwat) + if (resid > so->so_snd.ssb_hiwat) gotoerr(EMSGSIZE); - if (uio && sbspace(&so->so_snd) < resid) { + if (uio && ssb_space(&so->so_snd) < resid) { if (flags & (MSG_FNONBLOCKING|MSG_DONTWAIT)) gotoerr(EWOULDBLOCK); - sbunlock(&so->so_snd); - error = sbwait(&so->so_snd); + ssb_unlock(&so->so_snd); + error = ssb_wait(&so->so_snd); crit_exit(); if (error) goto out; @@ -738,7 +738,7 @@ restart: so->so_options &= ~SO_DONTROUTE; release: - sbunlock(&so->so_snd); + ssb_unlock(&so->so_snd); out: if (top) m_freem(top); @@ -747,15 +747,15 @@ out: /* * Implement receive operations on a socket. - * We depend on the way that records are added to the sockbuf + * We depend on the way that records are added to the signalsockbuf * by sbappend*. In particular, each record (mbufs linked through m_next) * must begin with an address if the protocol so specifies, * followed by an optional mbuf or mbufs containing ancillary data, * and then zero or more mbufs of data. * In order to avoid blocking network interrupts for the entire time here, * we exit the critical section while doing the actual copy to user space. - * Although the sockbuf is locked, new data may still be appended, - * and thus we must maintain consistency of the sockbuf during that time. + * Although the signalsockbuf is locked, new data may still be appended, + * and thus we must maintain consistency of the signalsockbuf during that time. * * The caller may receive the data as a single mbuf chain by supplying * an mbuf **mp0 for use in returning the chain. The uio is then used @@ -763,7 +763,7 @@ out: */ int soreceive(struct socket *so, struct sockaddr **psa, struct uio *uio, - struct sorecv_direct *sio, struct mbuf **controlp, int *flagsp) + struct sockbuf *sio, struct mbuf **controlp, int *flagsp) { struct mbuf *m, *n; struct mbuf *free_chain = NULL; @@ -775,7 +775,7 @@ soreceive(struct socket *so, struct sockaddr **psa, struct uio *uio, if (uio) resid = uio->uio_resid; else - resid = sio->maxlen - sio->len; + resid = (int)(sio->sb_climit - sio->sb_cc); orig_resid = resid; if (psa) @@ -795,12 +795,8 @@ soreceive(struct socket *so, struct sockaddr **psa, struct uio *uio, goto bad; if (sio) { do { - *sio->mapp = m; - sio->mapp = &m->m_next; - m = m->m_next; - *sio->mapp = NULL; + sbappend(sio, m); resid -= m->m_len; - sio->len += m->m_len; } while (resid > 0 && m); } else { do { @@ -821,11 +817,11 @@ bad: restart: crit_enter(); - error = sblock(&so->so_rcv, SBLOCKWAIT(flags)); + error = ssb_lock(&so->so_rcv, SBLOCKWAIT(flags)); if (error) goto done; - m = so->so_rcv.sb_mb; + m = so->so_rcv.ssb_mb; /* * If we have less data than requested, block awaiting more * (subject to any timeout) if: @@ -838,11 +834,11 @@ restart: * a short count if a timeout or signal occurs after we start. */ if (m == NULL || (((flags & MSG_DONTWAIT) == 0 && - so->so_rcv.sb_cc < resid) && - (so->so_rcv.sb_cc < so->so_rcv.sb_lowat || - ((flags & MSG_WAITALL) && resid <= so->so_rcv.sb_hiwat)) && + so->so_rcv.ssb_cc < resid) && + (so->so_rcv.ssb_cc < so->so_rcv.ssb_lowat || + ((flags & MSG_WAITALL) && resid <= so->so_rcv.ssb_hiwat)) && m->m_nextpkt == 0 && (pr->pr_flags & PR_ATOMIC) == 0)) { - KASSERT(m != NULL || !so->so_rcv.sb_cc, ("receive 1")); + KASSERT(m != NULL || !so->so_rcv.ssb_cc, ("receive 1")); if (so->so_error) { if (m) goto dontblock; @@ -859,7 +855,7 @@ restart: } for (; m; m = m->m_next) { if (m->m_type == MT_OOBDATA || (m->m_flags & M_EOR)) { - m = so->so_rcv.sb_mb; + m = so->so_rcv.ssb_mb; goto dontblock; } } @@ -874,8 +870,8 @@ restart: error = EWOULDBLOCK; goto release; } - sbunlock(&so->so_rcv); - error = sbwait(&so->so_rcv); + ssb_unlock(&so->so_rcv); + error = ssb_wait(&so->so_rcv); if (error) goto done; crit_exit(); @@ -890,7 +886,7 @@ dontblock: * cleaning up. Note that calling m_free*() will break out critical * section. */ - KKASSERT(m == so->so_rcv.sb_mb); + KKASSERT(m == so->so_rcv.ssb_mb); /* * Skip any address mbufs prepending the record. @@ -903,7 +899,7 @@ dontblock: if (flags & MSG_PEEK) m = m->m_next; else - m = sbunlinkmbuf(&so->so_rcv, m, &free_chain); + m = sbunlinkmbuf(&so->so_rcv.sb, m, &free_chain); } /* @@ -922,7 +918,7 @@ dontblock: if (flags & MSG_PEEK) m = m->m_next; else - m = sbunlinkmbuf(&so->so_rcv, m, &free_chain); + m = sbunlinkmbuf(&so->so_rcv.sb, m, &free_chain); } } #endif /* SCTP */ @@ -933,7 +929,7 @@ dontblock: m = m->m_next; /* XXX race */ } else { if (controlp) { - n = sbunlinkmbuf(&so->so_rcv, m, NULL); + n = sbunlinkmbuf(&so->so_rcv.sb, m, NULL); if (pr->pr_domain->dom_externalize && mtod(m, struct cmsghdr *)->cmsg_type == SCM_RIGHTS) @@ -941,7 +937,7 @@ dontblock: *controlp = m; m = n; } else { - m = sbunlinkmbuf(&so->so_rcv, m, &free_chain); + m = sbunlinkmbuf(&so->so_rcv.sb, m, &free_chain); } } if (controlp && *controlp) { @@ -1012,13 +1008,11 @@ dontblock: moff = 0; } else { if (sio) { - n = sbunlinkmbuf(&so->so_rcv, m, NULL); - *sio->mapp = m; - sio->mapp = &m->m_next; - sio->len += m->m_len; + n = sbunlinkmbuf(&so->so_rcv.sb, m, NULL); + sbappend(sio, m); m = n; } else { - m = sbunlinkmbuf(&so->so_rcv, m, &free_chain); + m = sbunlinkmbuf(&so->so_rcv.sb, m, &free_chain); } } } else { @@ -1026,13 +1020,13 @@ dontblock: moff += len; } else { if (sio) { - *sio->mapp= m_copym(m, 0, len, MB_WAIT); - sio->mapp = &m->m_next; - sio->len += len; + n = m_copym(m, 0, len, MB_WAIT); + if (n) + sbappend(sio, n); } m->m_data += len; m->m_len -= len; - so->so_rcv.sb_cc -= len; + so->so_rcv.ssb_cc -= len; } } if (so->so_oobmark) { @@ -1055,11 +1049,11 @@ dontblock: * we must not quit until resid == 0 or an error * termination. If a signal/timeout occurs, return * with a short count but without error. - * Keep sockbuf locked against other readers. + * Keep signalsockbuf locked against other readers. */ while ((flags & MSG_WAITALL) && m == NULL && resid > 0 && !sosendallatonce(so) && - so->so_rcv.sb_mb == NULL) { + so->so_rcv.ssb_mb == NULL) { if (so->so_error || so->so_state & SS_CANTRCVMORE) break; /* @@ -1070,13 +1064,13 @@ dontblock: */ if (pr->pr_flags & PR_WANTRCVD && so->so_pcb) so_pru_rcvd(so, flags); - error = sbwait(&so->so_rcv); + error = ssb_wait(&so->so_rcv); if (error) { - sbunlock(&so->so_rcv); + ssb_unlock(&so->so_rcv); error = 0; goto done; } - m = so->so_rcv.sb_mb; + m = so->so_rcv.ssb_mb; } } @@ -1092,14 +1086,14 @@ dontblock: */ if ((flags & MSG_PEEK) == 0) { if (m && (pr->pr_flags & PR_ATOMIC)) - sbdroprecord(&so->so_rcv); + sbdroprecord(&so->so_rcv.sb); if ((pr->pr_flags & PR_WANTRCVD) && so->so_pcb) so_pru_rcvd(so, flags); } if (orig_resid == resid && orig_resid && (flags & MSG_EOR) == 0 && (so->so_state & SS_CANTRCVMORE) == 0) { - sbunlock(&so->so_rcv); + ssb_unlock(&so->so_rcv); crit_exit(); goto restart; } @@ -1107,7 +1101,7 @@ dontblock: if (flagsp) *flagsp |= flags; release: - sbunlock(&so->so_rcv); + ssb_unlock(&so->so_rcv); done: crit_exit(); if (free_chain) @@ -1131,27 +1125,27 @@ soshutdown(struct socket *so, int how) void sorflush(struct socket *so) { - struct sockbuf *sb = &so->so_rcv; + struct signalsockbuf *ssb = &so->so_rcv; struct protosw *pr = so->so_proto; - struct sockbuf asb; + struct signalsockbuf asb; - sb->sb_flags |= SB_NOINTR; - (void) sblock(sb, M_WAITOK); + ssb->ssb_flags |= SSB_NOINTR; + (void) ssb_lock(ssb, M_WAITOK); crit_enter(); socantrcvmore(so); - sbunlock(sb); - asb = *sb; - bzero((caddr_t)sb, sizeof (*sb)); - if (asb.sb_flags & SB_KNOTE) { - sb->sb_sel.si_note = asb.sb_sel.si_note; - sb->sb_flags = SB_KNOTE; + ssb_unlock(ssb); + asb = *ssb; + bzero((caddr_t)ssb, sizeof (*ssb)); + if (asb.ssb_flags & SSB_KNOTE) { + ssb->ssb_sel.si_note = asb.ssb_sel.si_note; + ssb->ssb_flags = SSB_KNOTE; } crit_exit(); if (pr->pr_flags & PR_RIGHTS && pr->pr_domain->dom_dispose) - (*pr->pr_domain->dom_dispose)(asb.sb_mb); - sbrelease(&asb, so); + (*pr->pr_domain->dom_dispose)(asb.ssb_mb); + ssb_release(&asb, so); } #ifdef INET @@ -1337,7 +1331,7 @@ sosetopt(struct socket *so, struct sockopt *sopt) switch (sopt->sopt_name) { case SO_SNDBUF: case SO_RCVBUF: - if (sbreserve(sopt->sopt_name == SO_SNDBUF ? + if (ssb_reserve(sopt->sopt_name == SO_SNDBUF ? &so->so_snd : &so->so_rcv, (u_long)optval, so, &curproc->p_rlimit[RLIMIT_SBSIZE]) == 0) { @@ -1351,14 +1345,14 @@ sosetopt(struct socket *so, struct sockopt *sopt) * the high-water. */ case SO_SNDLOWAT: - so->so_snd.sb_lowat = - (optval > so->so_snd.sb_hiwat) ? - so->so_snd.sb_hiwat : optval; + so->so_snd.ssb_lowat = + (optval > so->so_snd.ssb_hiwat) ? + so->so_snd.ssb_hiwat : optval; break; case SO_RCVLOWAT: - so->so_rcv.sb_lowat = - (optval > so->so_rcv.sb_hiwat) ? - so->so_rcv.sb_hiwat : optval; + so->so_rcv.ssb_lowat = + (optval > so->so_rcv.ssb_hiwat) ? + so->so_rcv.ssb_hiwat : optval; break; } break; @@ -1388,10 +1382,10 @@ sosetopt(struct socket *so, struct sockopt *sopt) switch (sopt->sopt_name) { case SO_SNDTIMEO: - so->so_snd.sb_timeo = val; + so->so_snd.ssb_timeo = val; break; case SO_RCVTIMEO: - so->so_rcv.sb_timeo = val; + so->so_rcv.ssb_timeo = val; break; } break; @@ -1502,25 +1496,25 @@ integer: goto integer; case SO_SNDBUF: - optval = so->so_snd.sb_hiwat; + optval = so->so_snd.ssb_hiwat; goto integer; case SO_RCVBUF: - optval = so->so_rcv.sb_hiwat; + optval = so->so_rcv.ssb_hiwat; goto integer; case SO_SNDLOWAT: - optval = so->so_snd.sb_lowat; + optval = so->so_snd.ssb_lowat; goto integer; case SO_RCVLOWAT: - optval = so->so_rcv.sb_lowat; + optval = so->so_rcv.ssb_lowat; goto integer; case SO_SNDTIMEO: case SO_RCVTIMEO: optval = (sopt->sopt_name == SO_SNDTIMEO ? - so->so_snd.sb_timeo : so->so_rcv.sb_timeo); + so->so_snd.ssb_timeo : so->so_rcv.ssb_timeo); tv.tv_sec = optval / hz; tv.tv_usec = (optval % hz) * tick; @@ -1635,7 +1629,7 @@ sohasoutofband(struct socket *so) { if (so->so_sigio != NULL) pgsigio(so->so_sigio, SIGURG, 0); - selwakeup(&so->so_rcv.sb_sel); + selwakeup(&so->so_rcv.ssb_sel); } int @@ -1650,7 +1644,7 @@ sopoll(struct socket *so, int events, struct ucred *cred, struct thread *td) revents |= events & (POLLIN | POLLRDNORM); if (events & POLLINIGNEOF) - if (so->so_rcv.sb_cc >= so->so_rcv.sb_lowat || + if (so->so_rcv.ssb_cc >= so->so_rcv.ssb_lowat || !TAILQ_EMPTY(&so->so_comp) || so->so_error) revents |= POLLINIGNEOF; @@ -1666,13 +1660,13 @@ sopoll(struct socket *so, int events, struct ucred *cred, struct thread *td) if (events & (POLLIN | POLLINIGNEOF | POLLPRI | POLLRDNORM | POLLRDBAND)) { - selrecord(td, &so->so_rcv.sb_sel); - so->so_rcv.sb_flags |= SB_SEL; + selrecord(td, &so->so_rcv.ssb_sel); + so->so_rcv.ssb_flags |= SSB_SEL; } if (events & (POLLOUT | POLLWRNORM)) { - selrecord(td, &so->so_snd.sb_sel); - so->so_snd.sb_flags |= SB_SEL; + selrecord(td, &so->so_snd.ssb_sel); + so->so_snd.ssb_flags |= SSB_SEL; } } @@ -1684,7 +1678,7 @@ int sokqfilter(struct file *fp, struct knote *kn) { struct socket *so = (struct socket *)kn->kn_fp->f_data; - struct sockbuf *sb; + struct signalsockbuf *ssb; switch (kn->kn_filter) { case EVFILT_READ: @@ -1692,19 +1686,19 @@ sokqfilter(struct file *fp, struct knote *kn) kn->kn_fop = &solisten_filtops; else kn->kn_fop = &soread_filtops; - sb = &so->so_rcv; + ssb = &so->so_rcv; break; case EVFILT_WRITE: kn->kn_fop = &sowrite_filtops; - sb = &so->so_snd; + ssb = &so->so_snd; break; default: return (1); } crit_enter(); - SLIST_INSERT_HEAD(&sb->sb_sel.si_note, kn, kn_selnext); - sb->sb_flags |= SB_KNOTE; + SLIST_INSERT_HEAD(&ssb->ssb_sel.si_note, kn, kn_selnext); + ssb->ssb_flags |= SSB_KNOTE; crit_exit(); return (0); } @@ -1715,9 +1709,9 @@ filt_sordetach(struct knote *kn) struct socket *so = (struct socket *)kn->kn_fp->f_data; crit_enter(); - SLIST_REMOVE(&so->so_rcv.sb_sel.si_note, kn, knote, kn_selnext); - if (SLIST_EMPTY(&so->so_rcv.sb_sel.si_note)) - so->so_rcv.sb_flags &= ~SB_KNOTE; + SLIST_REMOVE(&so->so_rcv.ssb_sel.si_note, kn, knote, kn_selnext); + if (SLIST_EMPTY(&so->so_rcv.ssb_sel.si_note)) + so->so_rcv.ssb_flags &= ~SSB_KNOTE; crit_exit(); } @@ -1727,7 +1721,7 @@ filt_soread(struct knote *kn, long hint) { struct socket *so = (struct socket *)kn->kn_fp->f_data; - kn->kn_data = so->so_rcv.sb_cc; + kn->kn_data = so->so_rcv.ssb_cc; if (so->so_state & SS_CANTRCVMORE) { kn->kn_flags |= EV_EOF; kn->kn_fflags = so->so_error; @@ -1737,7 +1731,7 @@ filt_soread(struct knote *kn, long hint) return (1); if (kn->kn_sfflags & NOTE_LOWAT) return (kn->kn_data >= kn->kn_sdata); - return (kn->kn_data >= so->so_rcv.sb_lowat); + return (kn->kn_data >= so->so_rcv.ssb_lowat); } static void @@ -1746,9 +1740,9 @@ filt_sowdetach(struct knote *kn) struct socket *so = (struct socket *)kn->kn_fp->f_data; crit_enter(); - SLIST_REMOVE(&so->so_snd.sb_sel.si_note, kn, knote, kn_selnext); - if (SLIST_EMPTY(&so->so_snd.sb_sel.si_note)) - so->so_snd.sb_flags &= ~SB_KNOTE; + SLIST_REMOVE(&so->so_snd.ssb_sel.si_note, kn, knote, kn_selnext); + if (SLIST_EMPTY(&so->so_snd.ssb_sel.si_note)) + so->so_snd.ssb_flags &= ~SSB_KNOTE; crit_exit(); } @@ -1758,7 +1752,7 @@ filt_sowrite(struct knote *kn, long hint) { struct socket *so = (struct socket *)kn->kn_fp->f_data; - kn->kn_data = sbspace(&so->so_snd); + kn->kn_data = ssb_space(&so->so_snd); if (so->so_state & SS_CANTSENDMORE) { kn->kn_flags |= EV_EOF; kn->kn_fflags = so->so_error; @@ -1771,7 +1765,7 @@ filt_sowrite(struct knote *kn, long hint) return (0); if (kn->kn_sfflags & NOTE_LOWAT) return (kn->kn_data >= kn->kn_sdata); - return (kn->kn_data >= so->so_snd.sb_lowat); + return (kn->kn_data >= so->so_snd.ssb_lowat); } /*ARGSUSED*/ diff --git a/sys/kern/uipc_socket2.c b/sys/kern/uipc_socket2.c index 4659502ddd..32b40dac19 100644 --- a/sys/kern/uipc_socket2.c +++ b/sys/kern/uipc_socket2.c @@ -33,7 +33,7 @@ * * @(#)uipc_socket2.c 8.1 (Berkeley) 6/10/93 * $FreeBSD: src/sys/kern/uipc_socket2.c,v 1.55.2.17 2002/08/31 19:04:55 dwmalone Exp $ - * $DragonFly: src/sys/kern/uipc_socket2.c,v 1.26 2006/12/23 23:47:54 swildner Exp $ + * $DragonFly: src/sys/kern/uipc_socket2.c,v 1.27 2007/04/22 01:13:10 dillon Exp $ */ #include "opt_param.h" @@ -70,40 +70,97 @@ u_long sb_max_adj = static u_long sb_efficiency = 8; /* parameter for sbreserve() */ +/************************************************************************ + * signalsockbuf procedures * + ************************************************************************/ + +/* + * Wait for data to arrive at/drain from a socket buffer. + */ +int +ssb_wait(struct signalsockbuf *ssb) +{ + + ssb->ssb_flags |= SSB_WAIT; + return (tsleep((caddr_t)&ssb->ssb_cc, + ((ssb->ssb_flags & SSB_NOINTR) ? 0 : PCATCH), + "sbwait", + ssb->ssb_timeo)); +} + +/* + * Lock a sockbuf already known to be locked; + * return any error returned from sleep (EINTR). + */ +int +_ssb_lock(struct signalsockbuf *ssb) +{ + int error; + + while (ssb->ssb_flags & SSB_LOCK) { + ssb->ssb_flags |= SSB_WANT; + error = tsleep((caddr_t)&ssb->ssb_flags, + ((ssb->ssb_flags & SSB_NOINTR) ? 0 : PCATCH), + "sblock", 0); + if (error) + return (error); + } + ssb->ssb_flags |= SSB_LOCK; + return (0); +} + /* - * Procedures to manipulate state flags of socket - * and do appropriate wakeups. Normal sequence from the - * active (originating) side is that soisconnecting() is - * called during processing of connect() call, - * resulting in an eventual call to soisconnected() if/when the - * connection is established. When the connection is torn down - * soisdisconnecting() is called during processing of disconnect() call, - * and soisdisconnected() is called when the connection to the peer - * is totally severed. The semantics of these routines are such that - * connectionless protocols can call soisconnected() and soisdisconnected() - * only, bypassing the in-progress calls when setting up a ``connection'' - * takes no time. + * This does the same for sockbufs. Note that the xsockbuf structure, + * since it is always embedded in a socket, does not include a self + * pointer nor a length. We make this entry point public in case + * some other mechanism needs it. + */ +void +ssbtoxsockbuf(struct signalsockbuf *ssb, struct xsockbuf *xsb) +{ + xsb->sb_cc = ssb->ssb_cc; + xsb->sb_hiwat = ssb->ssb_hiwat; + xsb->sb_mbcnt = ssb->ssb_mbcnt; + xsb->sb_mbmax = ssb->ssb_mbmax; + xsb->sb_lowat = ssb->ssb_lowat; + xsb->sb_flags = ssb->ssb_flags; + xsb->sb_timeo = ssb->ssb_timeo; +} + + +/************************************************************************ + * Procedures which manipulate socket state flags, wakeups, etc. * + ************************************************************************ + * + * Normal sequence from the active (originating) side is that + * soisconnecting() is called during processing of connect() call, resulting + * in an eventual call to soisconnected() if/when the connection is + * established. When the connection is torn down soisdisconnecting() is + * called during processing of disconnect() call, and soisdisconnected() is + * called when the connection to the peer is totally severed. * - * From the passive side, a socket is created with - * two queues of sockets: so_incomp for connections in progress - * and so_comp for connections already made and awaiting user acceptance. - * As a protocol is preparing incoming connections, it creates a socket - * structure queued on so_incomp by calling sonewconn(). When the connection - * is established, soisconnected() is called, and transfers the - * socket structure to so_comp, making it available to accept(). + * The semantics of these routines are such that connectionless protocols + * can call soisconnected() and soisdisconnected() only, bypassing the + * in-progress calls when setting up a ``connection'' takes no time. * - * If a socket is closed with sockets on either - * so_incomp or so_comp, these sockets are dropped. + * From the passive side, a socket is created with two queues of sockets: + * so_incomp for connections in progress and so_comp for connections + * already made and awaiting user acceptance. As a protocol is preparing + * incoming connections, it creates a socket structure queued on so_incomp + * by calling sonewconn(). When the connection is established, + * soisconnected() is called, and transfers the socket structure to so_comp, + * making it available to accept(). * - * If higher level protocols are implemented in - * the kernel, the wakeups done here will sometimes - * cause software-interrupt process scheduling. + * If a socket is closed with sockets on either so_incomp or so_comp, these + * sockets are dropped. + * + * If higher level protocols are implemented in the kernel, the wakeups + * done here will sometimes cause software-interrupt process scheduling. */ void soisconnecting(struct socket *so) { - so->so_state &= ~(SS_ISCONNECTED|SS_ISDISCONNECTING); so->so_state |= SS_ISCONNECTING; } @@ -119,7 +176,7 @@ soisconnected(struct socket *so) if ((so->so_options & SO_ACCEPTFILTER) != 0) { so->so_upcall = head->so_accf->so_accept_filter->accf_callback; so->so_upcallarg = head->so_accf->so_accept_filter_arg; - so->so_rcv.sb_flags |= SB_UPCALL; + so->so_rcv.ssb_flags |= SSB_UPCALL; so->so_options &= ~SO_ACCEPTFILTER; so->so_upcall(so, so->so_upcallarg, 0); return; @@ -142,7 +199,6 @@ soisconnected(struct socket *so) void soisdisconnecting(struct socket *so) { - so->so_state &= ~SS_ISCONNECTING; so->so_state |= (SS_ISDISCONNECTING|SS_CANTRCVMORE|SS_CANTSENDMORE); wakeup((caddr_t)&so->so_timeo); @@ -153,11 +209,10 @@ soisdisconnecting(struct socket *so) void soisdisconnected(struct socket *so) { - so->so_state &= ~(SS_ISCONNECTING|SS_ISCONNECTED|SS_ISDISCONNECTING); so->so_state |= (SS_CANTRCVMORE|SS_CANTSENDMORE|SS_ISDISCONNECTED); wakeup((caddr_t)&so->so_timeo); - sbdrop(&so->so_snd, so->so_snd.sb_cc); + sbdrop(&so->so_snd.sb, so->so_snd.ssb_cc); sowwakeup(so); sorwakeup(so); } @@ -194,7 +249,7 @@ sonewconn(struct socket *head, int connstatus) ai.sb_rlimit = NULL; ai.p_ucred = NULL; ai.fd_rdir = NULL; /* jail code cruft XXX JH */ - if (soreserve(so, head->so_snd.sb_hiwat, head->so_rcv.sb_hiwat, NULL) || + if (soreserve(so, head->so_snd.ssb_hiwat, head->so_rcv.ssb_hiwat, NULL) || /* Directly call function since we're already at protocol level. */ (*so->so_proto->pr_usrreqs->pru_attach)(so, 0, &ai)) { sodealloc(so); @@ -232,11 +287,9 @@ sonewconn(struct socket *head, int connstatus) * protocol when it detects that the peer will send no more data. * Data queued for reading in the socket may yet be read. */ - void socantsendmore(struct socket *so) { - so->so_state |= SS_CANTSENDMORE; sowwakeup(so); } @@ -244,69 +297,33 @@ socantsendmore(struct socket *so) void socantrcvmore(struct socket *so) { - so->so_state |= SS_CANTRCVMORE; sorwakeup(so); } -/* - * Wait for data to arrive at/drain from a socket buffer. - */ -int -sbwait(struct sockbuf *sb) -{ - - sb->sb_flags |= SB_WAIT; - return (tsleep((caddr_t)&sb->sb_cc, - ((sb->sb_flags & SB_NOINTR) ? 0 : PCATCH), - "sbwait", - sb->sb_timeo)); -} - -/* - * Lock a sockbuf already known to be locked; - * return any error returned from sleep (EINTR). - */ -int -sb_lock(struct sockbuf *sb) -{ - int error; - - while (sb->sb_flags & SB_LOCK) { - sb->sb_flags |= SB_WANT; - error = tsleep((caddr_t)&sb->sb_flags, - ((sb->sb_flags & SB_NOINTR) ? 0 : PCATCH), - "sblock", 0); - if (error) - return (error); - } - sb->sb_flags |= SB_LOCK; - return (0); -} - /* * Wakeup processes waiting on a socket buffer. Do asynchronous notification * via SIGIO if the socket has the SS_ASYNC flag set. */ void -sowakeup(struct socket *so, struct sockbuf *sb) +sowakeup(struct socket *so, struct signalsockbuf *ssb) { - struct selinfo *selinfo = &sb->sb_sel; + struct selinfo *selinfo = &ssb->ssb_sel; selwakeup(selinfo); - sb->sb_flags &= ~SB_SEL; - if (sb->sb_flags & SB_WAIT) { - sb->sb_flags &= ~SB_WAIT; - wakeup((caddr_t)&sb->sb_cc); + ssb->ssb_flags &= ~SSB_SEL; + if (ssb->ssb_flags & SSB_WAIT) { + ssb->ssb_flags &= ~SSB_WAIT; + wakeup((caddr_t)&ssb->ssb_cc); } if ((so->so_state & SS_ASYNC) && so->so_sigio != NULL) pgsigio(so->so_sigio, SIGIO, 0); - if (sb->sb_flags & SB_UPCALL) + if (ssb->ssb_flags & SSB_UPCALL) (*so->so_upcall)(so, so->so_upcallarg, MB_DONTWAIT); - if (sb->sb_flags & SB_AIO) - aio_swake(so, sb); + if (ssb->ssb_flags & SSB_AIO) + aio_swake(so, ssb); KNOTE(&selinfo->si_note, 0); - if (sb->sb_flags & SB_MEVENT) { + if (ssb->ssb_flags & SSB_MEVENT) { struct netmsg_so_notify *msg, *nmsg; TAILQ_FOREACH_MUTABLE(msg, &selinfo->si_mlist, nm_list, nmsg) { @@ -316,13 +333,13 @@ sowakeup(struct socket *so, struct sockbuf *sb) msg->nm_lmsg.ms_error); } } - if (TAILQ_EMPTY(&sb->sb_sel.si_mlist)) - sb->sb_flags &= ~SB_MEVENT; + if (TAILQ_EMPTY(&ssb->ssb_sel.si_mlist)) + ssb->ssb_flags &= ~SSB_MEVENT; } } /* - * Socket buffer (struct sockbuf) utility routines. + * Socket buffer (struct signalsockbuf) utility routines. * * Each socket contains two socket buffers: one for sending data and * one for receiving data. Each buffer contains a queue of mbufs, @@ -350,25 +367,24 @@ sowakeup(struct socket *so, struct sockbuf *sb) * buffer space to the socket, by calling sbreserve(). This should commit * some of the available buffer space in the system buffer pool for the * socket (currently, it does nothing but enforce limits). The space - * should be released by calling sbrelease() when the socket is destroyed. + * should be released by calling ssb_release() when the socket is destroyed. */ - int soreserve(struct socket *so, u_long sndcc, u_long rcvcc, struct rlimit *rl) { - if (sbreserve(&so->so_snd, sndcc, so, rl) == 0) + if (ssb_reserve(&so->so_snd, sndcc, so, rl) == 0) goto bad; - if (sbreserve(&so->so_rcv, rcvcc, so, rl) == 0) + if (ssb_reserve(&so->so_rcv, rcvcc, so, rl) == 0) goto bad2; - if (so->so_rcv.sb_lowat == 0) - so->so_rcv.sb_lowat = 1; - if (so->so_snd.sb_lowat == 0) - so->so_snd.sb_lowat = MCLBYTES; - if (so->so_snd.sb_lowat > so->so_snd.sb_hiwat) - so->so_snd.sb_lowat = so->so_snd.sb_hiwat; + if (so->so_rcv.ssb_lowat == 0) + so->so_rcv.ssb_lowat = 1; + if (so->so_snd.ssb_lowat == 0) + so->so_snd.ssb_lowat = MCLBYTES; + if (so->so_snd.ssb_lowat > so->so_snd.ssb_hiwat) + so->so_snd.ssb_lowat = so->so_snd.ssb_hiwat; return (0); bad2: - sbrelease(&so->so_snd, so); + ssb_release(&so->so_snd, so); bad: return (ENOBUFS); } @@ -394,27 +410,27 @@ sysctl_handle_sb_max(SYSCTL_HANDLER_ARGS) } /* - * Allot mbufs to a sockbuf. + * Allot mbufs to a signalsockbuf. * Attempt to scale mbmax so that mbcnt doesn't become limiting * if buffering efficiency is near the normal case. */ int -sbreserve(struct sockbuf *sb, u_long cc, struct socket *so, struct rlimit *rl) +ssb_reserve(struct signalsockbuf *ssb, u_long cc, struct socket *so, + struct rlimit *rl) { - /* * rl will only be NULL when we're in an interrupt (eg, in tcp_input) * or when called from netgraph (ie, ngd_attach) */ if (cc > sb_max_adj) return (0); - if (!chgsbsize(so->so_cred->cr_uidinfo, &sb->sb_hiwat, cc, + if (!chgsbsize(so->so_cred->cr_uidinfo, &ssb->ssb_hiwat, cc, rl ? rl->rlim_cur : RLIM_INFINITY)) { return (0); } - sb->sb_mbmax = min(cc * sb_efficiency, sb_max); - if (sb->sb_lowat > sb->sb_hiwat) - sb->sb_lowat = sb->sb_hiwat; + ssb->ssb_mbmax = min(cc * sb_efficiency, sb_max); + if (ssb->ssb_lowat > ssb->ssb_hiwat) + ssb->ssb_lowat = ssb->ssb_hiwat; return (1); } @@ -422,568 +438,12 @@ sbreserve(struct sockbuf *sb, u_long cc, struct socket *so, struct rlimit *rl) * Free mbufs held by a socket, and reserved mbuf space. */ void -sbrelease(struct sockbuf *sb, struct socket *so) +ssb_release(struct signalsockbuf *ssb, struct socket *so) { - - sbflush(sb); - (void)chgsbsize(so->so_cred->cr_uidinfo, &sb->sb_hiwat, 0, + sbflush(&ssb->sb); + (void)chgsbsize(so->so_cred->cr_uidinfo, &ssb->ssb_hiwat, 0, RLIM_INFINITY); - sb->sb_mbmax = 0; -} - -/* - * Routines to add and remove - * data from an mbuf queue. - * - * The routines sbappend() or sbappendrecord() are normally called to - * append new mbufs to a socket buffer, after checking that adequate - * space is available, comparing the function sbspace() with the amount - * of data to be added. sbappendrecord() differs from sbappend() in - * that data supplied is treated as the beginning of a new record. - * To place a sender's address, optional access rights, and data in a - * socket receive buffer, sbappendaddr() should be used. To place - * access rights and data in a socket receive buffer, sbappendrights() - * should be used. In either case, the new data begins a new record. - * Note that unlike sbappend() and sbappendrecord(), these routines check - * for the caller that there will be enough space to store the data. - * Each fails if there is not enough space, or if it cannot find mbufs - * to store additional information in. - * - * Reliable protocols may use the socket send buffer to hold data - * awaiting acknowledgement. Data is normally copied from a socket - * send buffer in a protocol with m_copy for output to a peer, - * and then removing the data from the socket buffer with sbdrop() - * or sbdroprecord() when the data is acknowledged by the peer. - */ - -/* - * Append mbuf chain m to the last record in the - * socket buffer sb. The additional space associated - * the mbuf chain is recorded in sb. Empty mbufs are - * discarded and mbufs are compacted where possible. - */ -void -sbappend(struct sockbuf *sb, struct mbuf *m) -{ - struct mbuf *n; - - if (m) { - n = sb->sb_mb; - if (n) { - while (n->m_nextpkt) - n = n->m_nextpkt; - do { - if (n->m_flags & M_EOR) { - /* XXXXXX!!!! */ - sbappendrecord(sb, m); - return; - } - } while (n->m_next && (n = n->m_next)); - } - sbcompress(sb, m, n); - } -} - -/* - * sbappendstream() is an optimized form of sbappend() for protocols - * such as TCP that only have one record in the socket buffer, are - * not PR_ATOMIC, nor allow MT_CONTROL data. A protocol that uses - * sbappendstream() must use sbappendstream() exclusively. - */ -void -sbappendstream(struct sockbuf *sb, struct mbuf *m) -{ - KKASSERT(m->m_nextpkt == NULL); - sbcompress(sb, m, sb->sb_lastmbuf); -} - -#ifdef SOCKBUF_DEBUG - -void -_sbcheck(struct sockbuf *sb) -{ - struct mbuf *m; - struct mbuf *n = NULL; - u_long len = 0, mbcnt = 0; - - for (m = sb->sb_mb; m; m = n) { - n = m->m_nextpkt; - if (n == NULL && sb->sb_lastrecord != m) { - kprintf("sockbuf %p mismatched lastrecord %p vs %p\n", sb, sb->sb_lastrecord, m); - panic("sbcheck1"); - - } - for (; m; m = m->m_next) { - len += m->m_len; - mbcnt += MSIZE; - if (m->m_flags & M_EXT) /*XXX*/ /* pretty sure this is bogus */ - mbcnt += m->m_ext.ext_size; - if (n == NULL && m->m_next == NULL) { - if (sb->sb_lastmbuf != m) { - kprintf("sockbuf %p mismatched lastmbuf %p vs %p\n", sb, sb->sb_lastmbuf, m); - panic("sbcheck2"); - } - } - } - } - if (sb->sb_mb == NULL) { - if (sb->sb_lastrecord != NULL) { - kprintf("sockbuf %p is empty, lastrecord not NULL: %p\n", - sb, sb->sb_lastrecord); - panic("sbcheck3"); - } - if (sb->sb_lastmbuf != NULL) { - kprintf("sockbuf %p is empty, lastmbuf not NULL: %p\n", - sb, sb->sb_lastmbuf); - panic("sbcheck4"); - } - } - if (len != sb->sb_cc || mbcnt != sb->sb_mbcnt) { - kprintf("sockbuf %p cc %ld != %ld || mbcnt %ld != %ld\n", - sb, len, sb->sb_cc, mbcnt, sb->sb_mbcnt); - panic("sbcheck5"); - } -} - -#endif - -/* - * Same as sbappend(), except the mbuf chain begins a new record. - */ -void -sbappendrecord(struct sockbuf *sb, struct mbuf *m0) -{ - struct mbuf *firstmbuf; - struct mbuf *secondmbuf; - - if (m0 == NULL) - return; - - sbcheck(sb); - - /* - * Break the first mbuf off from the rest of the mbuf chain. - */ - firstmbuf = m0; - secondmbuf = m0->m_next; - m0->m_next = NULL; - - /* - * Insert the first mbuf of the m0 mbuf chain as the last record of - * the sockbuf. Note this permits zero length records! Keep the - * sockbuf state consistent. - */ - if (sb->sb_mb == NULL) - sb->sb_mb = firstmbuf; - else - sb->sb_lastrecord->m_nextpkt = firstmbuf; - sb->sb_lastrecord = firstmbuf; /* update hint for new last record */ - sb->sb_lastmbuf = firstmbuf; /* update hint for new last mbuf */ - - if ((firstmbuf->m_flags & M_EOR) && (secondmbuf != NULL)) { - /* propagate the EOR flag */ - firstmbuf->m_flags &= ~M_EOR; - secondmbuf->m_flags |= M_EOR; - } - - /* - * The succeeding call to sbcompress() omits accounting for - * the first mbuf, so do it here. - */ - sballoc(sb, firstmbuf); - - /* Compact the rest of the mbuf chain in after the first mbuf. */ - sbcompress(sb, secondmbuf, firstmbuf); -} - -#if 0 -/* - * As above except that OOB data is inserted at the beginning of the sockbuf, - * but after any other OOB data. - */ -void -sbinsertoob(struct sockbuf *sb, struct mbuf *m0) -{ - struct mbuf *m; - struct mbuf **mp; - - if (m0 == NULL) - return; - for (mp = &sb->sb_mb; *mp ; mp = &((*mp)->m_nextpkt)) { - m = *mp; - again: - switch (m->m_type) { - - case MT_OOBDATA: - continue; /* WANT next train */ - - case MT_CONTROL: - m = m->m_next; - if (m) - goto again; /* inspect THIS train further */ - } - break; - } - /* - * Put the first mbuf on the queue. - * Note this permits zero length records. - */ - sballoc(sb, m0); - m0->m_nextpkt = *mp; - *mp = m0; - if (m0->m_nextpkt == NULL) - sb->sb_lastrecord = m0; - - m = m0->m_next; - m0->m_next = NULL; - if (m && (m0->m_flags & M_EOR)) { - m0->m_flags &= ~M_EOR; - m->m_flags |= M_EOR; - } - sbcompress(sb, m, m0); -} -#endif - -/* - * Append address and data, and optionally, control (ancillary) data - * to the receive queue of a socket. If present, - * m0 must include a packet header with total length. - * Returns 0 if no space in sockbuf or insufficient mbufs. - */ -int -sbappendaddr(struct sockbuf *sb, const struct sockaddr *asa, struct mbuf *m0, - struct mbuf *control) -{ - struct mbuf *m, *n; - int space = asa->sa_len; - - if (m0 && (m0->m_flags & M_PKTHDR) == 0) - panic("sbappendaddr"); - sbcheck(sb); - - if (m0) - space += m0->m_pkthdr.len; - for (n = control; n; n = n->m_next) { - space += n->m_len; - if (n->m_next == 0) /* keep pointer to last control buf */ - break; - } - if (space > sbspace(sb)) - return (0); - if (asa->sa_len > MLEN) - return (0); - MGET(m, MB_DONTWAIT, MT_SONAME); - if (m == NULL) - return (0); - KKASSERT(m->m_nextpkt == NULL); - m->m_len = asa->sa_len; - bcopy(asa, mtod(m, caddr_t), asa->sa_len); - if (n) - n->m_next = m0; /* concatenate data to control */ - else - control = m0; - m->m_next = control; - for (n = m; n; n = n->m_next) - sballoc(sb, n); - - if (sb->sb_mb == NULL) - sb->sb_mb = m; - else - sb->sb_lastrecord->m_nextpkt = m; - sb->sb_lastrecord = m; - while (m->m_next) - m = m->m_next; - sb->sb_lastmbuf = m; - - return (1); -} - -/* - * Append control information followed by data. - * control must be non-null. - */ -int -sbappendcontrol(struct sockbuf *sb, struct mbuf *m0, struct mbuf *control) -{ - struct mbuf *n; - u_int length, cmbcnt, m0mbcnt; - - KASSERT(control != NULL, ("sbappendcontrol")); - KKASSERT(control->m_nextpkt == NULL); - sbcheck(sb); - - length = m_countm(control, &n, &cmbcnt) + m_countm(m0, NULL, &m0mbcnt); - if (length > sbspace(sb)) - return (0); - - n->m_next = m0; /* concatenate data to control */ - - if (sb->sb_mb == NULL) - sb->sb_mb = control; - else - sb->sb_lastrecord->m_nextpkt = control; - sb->sb_lastrecord = control; - sb->sb_lastmbuf = m0; - - sb->sb_cc += length; - sb->sb_mbcnt += cmbcnt + m0mbcnt; - - return (1); -} - -/* - * Compress mbuf chain m into the socket buffer sb following mbuf tailm. - * If tailm is null, the buffer is presumed empty. Also, as a side-effect, - * increment the sockbuf counts for each mbuf in the chain. - */ -void -sbcompress(struct sockbuf *sb, struct mbuf *m, struct mbuf *tailm) -{ - int eor = 0; - struct mbuf *free_chain = NULL; - - sbcheck(sb); - while (m) { - struct mbuf *o; - - eor |= m->m_flags & M_EOR; - /* - * Disregard empty mbufs as long as we don't encounter - * an end-of-record or there is a trailing mbuf of - * the same type to propagate the EOR flag to. - * - * Defer the m_free() call because it can block and break - * the atomicy of the sockbuf. - */ - if (m->m_len == 0 && - (eor == 0 || - (((o = m->m_next) || (o = tailm)) && - o->m_type == m->m_type))) { - o = m->m_next; - m->m_next = free_chain; - free_chain = m; - m = o; - continue; - } - - /* See if we can coalesce with preceding mbuf. */ - if (tailm && !(tailm->m_flags & M_EOR) && M_WRITABLE(tailm) && - m->m_len <= MCLBYTES / 4 && /* XXX: Don't copy too much */ - m->m_len <= M_TRAILINGSPACE(tailm) && - tailm->m_type == m->m_type) { - bcopy(mtod(m, caddr_t), - mtod(tailm, caddr_t) + tailm->m_len, - (unsigned)m->m_len); - tailm->m_len += m->m_len; - sb->sb_cc += m->m_len; /* update sb counter */ - o = m->m_next; - m->m_next = free_chain; - free_chain = m; - m = o; - continue; - } - - /* Insert whole mbuf. */ - if (tailm == NULL) { - KASSERT(sb->sb_mb == NULL, - ("sbcompress: sb_mb not NULL")); - sb->sb_mb = m; /* only mbuf in sockbuf */ - sb->sb_lastrecord = m; /* new last record */ - } else { - tailm->m_next = m; /* tack m on following tailm */ - } - sb->sb_lastmbuf = m; /* update last mbuf hint */ - - tailm = m; /* just inserted mbuf becomes the new tail */ - m = m->m_next; /* advance to next mbuf */ - tailm->m_next = NULL; /* split inserted mbuf off from chain */ - - /* update sb counters for just added mbuf */ - sballoc(sb, tailm); - - /* clear EOR on intermediate mbufs */ - tailm->m_flags &= ~M_EOR; - } - - /* - * Propogate EOR to the last mbuf - */ - if (eor) { - if (tailm) - tailm->m_flags |= eor; - else - kprintf("semi-panic: sbcompress"); - } - - /* - * Clean up any defered frees. - */ - while (free_chain) - free_chain = m_free(free_chain); - - sbcheck(sb); -} - -/* - * Free all mbufs in a sockbuf. - * Check that all resources are reclaimed. - */ -void -sbflush(struct sockbuf *sb) -{ - - if (sb->sb_flags & SB_LOCK) - panic("sbflush: locked"); - while (sb->sb_mbcnt) { - /* - * Don't call sbdrop(sb, 0) if the leading mbuf is non-empty: - * we would loop forever. Panic instead. - */ - if (!sb->sb_cc && (sb->sb_mb == NULL || sb->sb_mb->m_len)) - break; - sbdrop(sb, (int)sb->sb_cc); - } - KASSERT(!(sb->sb_cc || sb->sb_mb || sb->sb_mbcnt || sb->sb_lastmbuf), - ("sbflush: cc %ld || mb %p || mbcnt %ld || lastmbuf %p", - sb->sb_cc, sb->sb_mb, sb->sb_mbcnt, sb->sb_lastmbuf)); -} - -/* - * Drop data from (the front of) a sockbuf. - */ -void -sbdrop(struct sockbuf *sb, int len) -{ - struct mbuf *m; - struct mbuf *free_chain = NULL; - - sbcheck(sb); - crit_enter(); - - /* - * Remove mbufs from multiple records until the count is exhausted. - */ - m = sb->sb_mb; - while (m && len > 0) { - if (m->m_len > len) { - m->m_len -= len; - m->m_data += len; - sb->sb_cc -= len; - break; - } - len -= m->m_len; - m = sbunlinkmbuf(sb, m, &free_chain); - if (m == NULL && len) - m = sb->sb_mb; - } - - /* - * Remove any trailing 0-length mbufs in the current record. If - * the last record for which data was removed is now empty, m will be - * NULL. - */ - while (m && m->m_len == 0) { - m = sbunlinkmbuf(sb, m, &free_chain); - } - crit_exit(); - if (free_chain) - m_freem(free_chain); - sbcheck(sb); -} - -/* - * Drop a record off the front of a sockbuf and move the next record - * to the front. - * - * Must be called while holding a critical section. - */ -void -sbdroprecord(struct sockbuf *sb) -{ - struct mbuf *m; - struct mbuf *n; - - sbcheck(sb); - m = sb->sb_mb; - if (m) { - if ((sb->sb_mb = m->m_nextpkt) == NULL) { - sb->sb_lastrecord = NULL; - sb->sb_lastmbuf = NULL; - } - m->m_nextpkt = NULL; - for (n = m; n; n = n->m_next) - sbfree(sb, n); - m_freem(m); - sbcheck(sb); - } -} - -/* - * Drop the first mbuf off the sockbuf and move the next mbuf to the front. - * Currently only the head mbuf of the sockbuf may be dropped this way. - * - * The next mbuf in the same record as the mbuf being removed is returned - * or NULL if the record is exhausted. Note that other records may remain - * in the sockbuf when NULL is returned. - * - * Must be called while holding a critical section. - */ -struct mbuf * -sbunlinkmbuf(struct sockbuf *sb, struct mbuf *m, struct mbuf **free_chain) -{ - struct mbuf *n; - - KKASSERT(sb->sb_mb == m); - sbfree(sb, m); - n = m->m_next; - if (n) { - sb->sb_mb = n; - if (sb->sb_lastrecord == m) - sb->sb_lastrecord = n; - KKASSERT(sb->sb_lastmbuf != m); - n->m_nextpkt = m->m_nextpkt; - } else { - sb->sb_mb = m->m_nextpkt; - if (sb->sb_lastrecord == m) { - KKASSERT(sb->sb_mb == NULL); - sb->sb_lastrecord = NULL; - } - if (sb->sb_mb == NULL) - sb->sb_lastmbuf = NULL; - } - m->m_nextpkt = NULL; - if (free_chain) { - m->m_next = *free_chain; - *free_chain = m; - } else { - m->m_next = NULL; - } - return(n); -} - -/* - * Create a "control" mbuf containing the specified data - * with the specified type for presentation on a socket buffer. - */ -struct mbuf * -sbcreatecontrol(caddr_t p, int size, int type, int level) -{ - struct cmsghdr *cp; - struct mbuf *m; - - if (CMSG_SPACE((u_int)size) > MCLBYTES) - return (NULL); - m = m_getl(CMSG_SPACE((u_int)size), MB_DONTWAIT, MT_CONTROL, 0, NULL); - if (m == NULL) - return (NULL); - m->m_len = CMSG_SPACE(size); - cp = mtod(m, struct cmsghdr *); - if (p != NULL) - memcpy(CMSG_DATA(cp), p, size); - cp->cmsg_len = CMSG_LEN(size); - cp->cmsg_level = level; - cp->cmsg_type = type; - return (m); + ssb->ssb_mbmax = 0; } /* @@ -1040,7 +500,7 @@ pru_rcvoob_notsupp(struct socket *so, struct mbuf *m, int flags) int pru_sense_null(struct socket *so, struct stat *sb) { - sb->st_blksize = so->so_snd.sb_hiwat; + sb->st_blksize = so->so_snd.ssb_hiwat; return 0; } @@ -1086,29 +546,11 @@ sotoxsocket(struct socket *so, struct xsocket *xso) xso->so_error = so->so_error; xso->so_pgid = so->so_sigio ? so->so_sigio->sio_pgid : 0; xso->so_oobmark = so->so_oobmark; - sbtoxsockbuf(&so->so_snd, &xso->so_snd); - sbtoxsockbuf(&so->so_rcv, &xso->so_rcv); + ssbtoxsockbuf(&so->so_snd, &xso->so_snd); + ssbtoxsockbuf(&so->so_rcv, &xso->so_rcv); xso->so_uid = so->so_cred->cr_uid; } -/* - * This does the same for sockbufs. Note that the xsockbuf structure, - * since it is always embedded in a socket, does not include a self - * pointer nor a length. We make this entry point public in case - * some other mechanism needs it. - */ -void -sbtoxsockbuf(struct sockbuf *sb, struct xsockbuf *xsb) -{ - xsb->sb_cc = sb->sb_cc; - xsb->sb_hiwat = sb->sb_hiwat; - xsb->sb_mbcnt = sb->sb_mbcnt; - xsb->sb_mbmax = sb->sb_mbmax; - xsb->sb_lowat = sb->sb_lowat; - xsb->sb_flags = sb->sb_flags; - xsb->sb_timeo = sb->sb_timeo; -} - /* * Here is the definition of some of the basic objects in the kern.ipc * branch of the MIB. diff --git a/sys/kern/uipc_syscalls.c b/sys/kern/uipc_syscalls.c index 2be754cbe5..95a862f4a7 100644 --- a/sys/kern/uipc_syscalls.c +++ b/sys/kern/uipc_syscalls.c @@ -35,7 +35,7 @@ * * @(#)uipc_syscalls.c 8.4 (Berkeley) 2/21/94 * $FreeBSD: src/sys/kern/uipc_syscalls.c,v 1.65.2.17 2003/04/04 17:11:16 tegge Exp $ - * $DragonFly: src/sys/kern/uipc_syscalls.c,v 1.79 2007/02/22 15:50:49 corecode Exp $ + * $DragonFly: src/sys/kern/uipc_syscalls.c,v 1.80 2007/04/22 01:13:10 dillon Exp $ */ #include "opt_ktrace.h" @@ -307,7 +307,7 @@ kern_accept(int s, int fflags, struct sockaddr **name, int *namelen, int *res) fflag = lfp->f_flag; /* connection has been removed from the listen queue */ - KNOTE(&head->so_rcv.sb_sel.si_note, 0); + KNOTE(&head->so_rcv.ssb_sel.si_note, 0); so->so_state &= ~SS_COMP; so->so_head = NULL; @@ -1524,7 +1524,7 @@ kern_sendfile(struct vnode *vp, int sfd, off_t offset, size_t nbytes, /* * Protect against multiple writers to the socket. */ - (void) sblock(&so->so_snd, M_WAITOK); + ssb_lock(&so->so_snd, M_WAITOK); /* * Loop through the pages in the file, starting with the requested @@ -1556,12 +1556,12 @@ retry_lookup: * Optimize the non-blocking case by looking at the socket space * before going to the extra work of constituting the sf_buf. */ - if ((fp->f_flag & FNONBLOCK) && sbspace(&so->so_snd) <= 0) { + if ((fp->f_flag & FNONBLOCK) && ssb_space(&so->so_snd) <= 0) { if (so->so_state & SS_CANTSENDMORE) error = EPIPE; else error = EAGAIN; - sbunlock(&so->so_snd); + ssb_unlock(&so->so_snd); goto done; } /* @@ -1630,7 +1630,7 @@ retry_lookup: vm_page_unwire(pg, 0); vm_page_try_to_free(pg); crit_exit(); - sbunlock(&so->so_snd); + ssb_unlock(&so->so_snd); goto done; } } @@ -1645,7 +1645,7 @@ retry_lookup: vm_page_unwire(pg, 0); vm_page_try_to_free(pg); crit_exit(); - sbunlock(&so->so_snd); + ssb_unlock(&so->so_snd); error = EINTR; goto done; } @@ -1657,7 +1657,7 @@ retry_lookup: if (m == NULL) { error = ENOBUFS; sf_buf_free(sf); - sbunlock(&so->so_snd); + ssb_unlock(&so->so_snd); goto done; } @@ -1712,32 +1712,32 @@ retry_space: so->so_error = 0; } m_freem(m); - sbunlock(&so->so_snd); + ssb_unlock(&so->so_snd); crit_exit(); goto done; } /* * Wait for socket space to become available. We do this just * after checking the connection state above in order to avoid - * a race condition with sbwait(). + * a race condition with ssb_wait(). */ - if (sbspace(&so->so_snd) < so->so_snd.sb_lowat) { + if (ssb_space(&so->so_snd) < so->so_snd.ssb_lowat) { if (fp->f_flag & FNONBLOCK) { m_freem(m); - sbunlock(&so->so_snd); + ssb_unlock(&so->so_snd); crit_exit(); error = EAGAIN; goto done; } - error = sbwait(&so->so_snd); + error = ssb_wait(&so->so_snd); /* - * An error from sbwait usually indicates that we've + * An error from ssb_wait usually indicates that we've * been interrupted by a signal. If we've sent anything * then return bytes sent, otherwise return the error. */ if (error) { m_freem(m); - sbunlock(&so->so_snd); + ssb_unlock(&so->so_snd); crit_exit(); goto done; } @@ -1746,7 +1746,7 @@ retry_space: error = so_pru_send(so, 0, m, NULL, NULL, td); crit_exit(); if (error) { - sbunlock(&so->so_snd); + ssb_unlock(&so->so_snd); goto done; } } @@ -1755,7 +1755,7 @@ retry_space: error = so_pru_send(so, 0, mheader, NULL, NULL, td); mheader = NULL; } - sbunlock(&so->so_snd); + ssb_unlock(&so->so_snd); done: fdrop(fp); diff --git a/sys/kern/uipc_usrreq.c b/sys/kern/uipc_usrreq.c index 5ea586daf7..756a2a8b08 100644 --- a/sys/kern/uipc_usrreq.c +++ b/sys/kern/uipc_usrreq.c @@ -32,7 +32,7 @@ * * From: @(#)uipc_usrreq.c 8.3 (Berkeley) 1/4/94 * $FreeBSD: src/sys/kern/uipc_usrreq.c,v 1.54.2.10 2003/03/04 17:28:09 nectar Exp $ - * $DragonFly: src/sys/kern/uipc_usrreq.c,v 1.33 2007/04/21 02:26:46 dillon Exp $ + * $DragonFly: src/sys/kern/uipc_usrreq.c,v 1.34 2007/04/22 01:13:10 dillon Exp $ */ #include @@ -250,13 +250,13 @@ uipc_rcvd(struct socket *so, int flags) * Adjust backpressure on sender * and wakeup any waiting to write. */ - so2->so_snd.sb_mbmax += unp->unp_mbcnt - so->so_rcv.sb_mbcnt; - unp->unp_mbcnt = so->so_rcv.sb_mbcnt; + so2->so_snd.ssb_mbmax += unp->unp_mbcnt - so->so_rcv.ssb_mbcnt; + unp->unp_mbcnt = so->so_rcv.ssb_mbcnt; newhiwat = - so2->so_snd.sb_hiwat + unp->unp_cc - so->so_rcv.sb_cc; - chgsbsize(so2->so_cred->cr_uidinfo, &so2->so_snd.sb_hiwat, + so2->so_snd.ssb_hiwat + unp->unp_cc - so->so_rcv.ssb_cc; + chgsbsize(so2->so_cred->cr_uidinfo, &so2->so_snd.ssb_hiwat, newhiwat, RLIM_INFINITY); - unp->unp_cc = so->so_rcv.sb_cc; + unp->unp_cc = so->so_rcv.ssb_cc; sowwakeup(so2); break; @@ -313,12 +313,13 @@ uipc_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *nam, from = (struct sockaddr *)unp->unp_addr; else from = &sun_noname; - if (sbappendaddr(&so2->so_rcv, from, m, control)) { + if (ssb_appendaddr(&so2->so_rcv, from, m, control)) { sorwakeup(so2); m = NULL; control = NULL; - } else + } else { error = ENOBUFS; + } if (nam) unp_disconnect(unp); break; @@ -354,18 +355,19 @@ uipc_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *nam, * Wake up readers. */ if (control) { - if (sbappendcontrol(&so2->so_rcv, m, control)) + if (ssb_appendcontrol(&so2->so_rcv, m, control)) control = NULL; - } else - sbappend(&so2->so_rcv, m); - so->so_snd.sb_mbmax -= - so2->so_rcv.sb_mbcnt - unp->unp_conn->unp_mbcnt; - unp->unp_conn->unp_mbcnt = so2->so_rcv.sb_mbcnt; - newhiwat = so->so_snd.sb_hiwat - - (so2->so_rcv.sb_cc - unp->unp_conn->unp_cc); - chgsbsize(so->so_cred->cr_uidinfo, &so->so_snd.sb_hiwat, + } else { + sbappend(&so2->so_rcv.sb, m); + } + so->so_snd.ssb_mbmax -= + so2->so_rcv.ssb_mbcnt - unp->unp_conn->unp_mbcnt; + unp->unp_conn->unp_mbcnt = so2->so_rcv.ssb_mbcnt; + newhiwat = so->so_snd.ssb_hiwat - + (so2->so_rcv.ssb_cc - unp->unp_conn->unp_cc); + chgsbsize(so->so_cred->cr_uidinfo, &so->so_snd.ssb_hiwat, newhiwat, RLIM_INFINITY); - unp->unp_conn->unp_cc = so2->so_rcv.sb_cc; + unp->unp_conn->unp_cc = so2->so_rcv.ssb_cc; sorwakeup(so2); m = NULL; break; @@ -401,10 +403,10 @@ uipc_sense(struct socket *so, struct stat *sb) if (unp == NULL) return EINVAL; - sb->st_blksize = so->so_snd.sb_hiwat; + sb->st_blksize = so->so_snd.ssb_hiwat; if (so->so_type == SOCK_STREAM && unp->unp_conn != NULL) { so2 = unp->unp_conn->unp_socket; - sb->st_blksize += so2->so_rcv.sb_cc; + sb->st_blksize += so2->so_rcv.ssb_cc; } sb->st_dev = NOUDEV; if (unp->unp_ino == 0) /* make up a non-zero inode number */ @@ -533,7 +535,7 @@ unp_attach(struct socket *so, struct pru_attach_info *ai) struct unpcb *unp; int error; - if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) { + if (so->so_snd.ssb_hiwat == 0 || so->so_rcv.ssb_hiwat == 0) { switch (so->so_type) { case SOCK_STREAM: @@ -1335,7 +1337,7 @@ unp_gc_checkmarks(struct file *fp, void *data) */ info->locked_fp = fp; /* spin_lock_wr(&so->so_rcv.sb_spin); */ - unp_scan(so->so_rcv.sb_mb, unp_mark, info); + unp_scan(so->so_rcv.ssb_mb, unp_mark, info); /* spin_unlock_wr(&so->so_rcv.sb_spin);*/ return (0); } diff --git a/sys/kern/vfs_aio.c b/sys/kern/vfs_aio.c index 3c2e1d6964..fde6657e5f 100644 --- a/sys/kern/vfs_aio.c +++ b/sys/kern/vfs_aio.c @@ -14,7 +14,7 @@ * of the author. This software is distributed AS-IS. * * $FreeBSD: src/sys/kern/vfs_aio.c,v 1.70.2.28 2003/05/29 06:15:35 alc Exp $ - * $DragonFly: src/sys/kern/vfs_aio.c,v 1.37 2007/03/01 16:18:11 swildner Exp $ + * $DragonFly: src/sys/kern/vfs_aio.c,v 1.38 2007/04/22 01:13:10 dillon Exp $ */ /* @@ -433,8 +433,8 @@ aio_proc_rundown(struct proc *p) so = (struct socket *)fp->f_data; TAILQ_REMOVE(&so->so_aiojobq, aiocbe, list); if (TAILQ_EMPTY(&so->so_aiojobq)) { - so->so_snd.sb_flags &= ~SB_AIO; - so->so_rcv.sb_flags &= ~SB_AIO; + so->so_snd.ssb_flags &= ~SSB_AIO; + so->so_rcv.ssb_flags &= ~SSB_AIO; } } TAILQ_REMOVE(&ki->kaio_sockqueue, aiocbe, plist); @@ -1074,7 +1074,7 @@ aio_fphysio(struct aiocblist *iocb) * Wake up aio requests that may be serviceable now. */ void -aio_swake(struct socket *so, struct sockbuf *sb) +aio_swake(struct socket *so, struct signalsockbuf *ssb) { #ifndef VFS_AIO return; @@ -1085,12 +1085,12 @@ aio_swake(struct socket *so, struct sockbuf *sb) int opcode, wakecount = 0; struct aioproclist *aiop; - if (sb == &so->so_snd) { + if (ssb == &so->so_snd) { opcode = LIO_WRITE; - so->so_snd.sb_flags &= ~SB_AIO; + so->so_snd.ssb_flags &= ~SSB_AIO; } else { opcode = LIO_READ; - so->so_rcv.sb_flags &= ~SB_AIO; + so->so_rcv.ssb_flags &= ~SSB_AIO; } for (cb = TAILQ_FIRST(&so->so_aiojobq); cb; cb = cbn) { @@ -1290,7 +1290,7 @@ no_kqueue: * operation). * * If it is not ready for io, then queue the aiocbe on the - * socket, and set the flags so we get a call when sbnotify() + * socket, and set the flags so we get a call when ssb_notify() * happens. */ so = (struct socket *)fp->f_data; @@ -1300,9 +1300,9 @@ no_kqueue: TAILQ_INSERT_TAIL(&so->so_aiojobq, aiocbe, list); TAILQ_INSERT_TAIL(&ki->kaio_sockqueue, aiocbe, plist); if (opcode == LIO_READ) - so->so_rcv.sb_flags |= SB_AIO; + so->so_rcv.ssb_flags |= SSB_AIO; else - so->so_snd.sb_flags |= SB_AIO; + so->so_snd.ssb_flags |= SSB_AIO; aiocbe->jobstate = JOBST_JOBQGLOBAL; /* XXX */ ki->kaio_queue_count++; num_queue_count++; diff --git a/sys/net/accf_data/accf_data.c b/sys/net/accf_data/accf_data.c index b874172118..8bc978c4ae 100644 --- a/sys/net/accf_data/accf_data.c +++ b/sys/net/accf_data/accf_data.c @@ -24,7 +24,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/netinet/accf_data.c,v 1.1.2.2 2000/09/20 21:34:13 ps Exp $ - * $DragonFly: src/sys/net/accf_data/accf_data.c,v 1.2 2003/06/17 04:28:51 dillon Exp $ + * $DragonFly: src/sys/net/accf_data/accf_data.c,v 1.3 2007/04/22 01:13:12 dillon Exp $ */ #define ACCEPT_FILTER_MOD @@ -76,7 +76,7 @@ sohasdata(struct socket *so, void *arg, int waitflag) } so->so_upcall = NULL; - so->so_rcv.sb_flags &= ~SB_UPCALL; + so->so_rcv.ssb_flags &= ~SSB_UPCALL; soisconnected(so); return; } diff --git a/sys/net/accf_http/accf_http.c b/sys/net/accf_http/accf_http.c index afd13e9683..1b750c0e06 100644 --- a/sys/net/accf_http/accf_http.c +++ b/sys/net/accf_http/accf_http.c @@ -25,7 +25,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/netinet/accf_http.c,v 1.1.2.4 2002/05/01 08:34:37 alfred Exp $ - * $DragonFly: src/sys/net/accf_http/accf_http.c,v 1.3 2006/12/22 23:44:55 swildner Exp $ + * $DragonFly: src/sys/net/accf_http/accf_http.c,v 1.4 2007/04/22 01:13:13 dillon Exp $ */ #define ACCEPT_FILTER_MOD @@ -61,7 +61,7 @@ static int mbufstrcmp(struct mbuf *m, struct mbuf *npkt, int offset, char *cmp); static int mbufstrncmp(struct mbuf *m, struct mbuf *npkt, int offset, int max, char *cmp); /* socketbuffer is full */ -static int sbfull(struct sockbuf *sb); +static int sbfull(struct signalsockbuf *sb); static struct accept_filter accf_http_filter = { "httpready", @@ -96,13 +96,14 @@ SYSCTL_INT(_net_inet_accf_http, OID_AUTO, parsehttpversion, CTLFLAG_RW, #endif static int -sbfull(struct sockbuf *sb) +sbfull(struct signalsockbuf *ssb) { DPRINT("sbfull, cc(%ld) >= hiwat(%ld): %d, mbcnt(%ld) >= mbmax(%ld): %d", - sb->sb_cc, sb->sb_hiwat, sb->sb_cc >= sb->sb_hiwat, - sb->sb_mbcnt, sb->sb_mbmax, sb->sb_mbcnt >= sb->sb_mbmax); - return(sb->sb_cc >= sb->sb_hiwat || sb->sb_mbcnt >= sb->sb_mbmax); + ssb->ssb_cc, ssb->ssb_hiwat, ssb->ssb_cc >= ssb->ssb_hiwat, + ssb->ssb_mbcnt, ssb->ssb_mbmax, ssb->ssb_mbcnt >= ssb->ssb_mbmax); + return(ssb->ssb_cc >= ssb->ssb_hiwat || + ssb->ssb_mbcnt >= ssb->ssb_mbmax); } /* @@ -179,8 +180,8 @@ sohashttpget(struct socket *so, void *arg, int waitflag) char *cmp; int cmplen, cc; - m = so->so_rcv.sb_mb; - cc = so->so_rcv.sb_cc - 1; + m = so->so_rcv.ssb_mb; + cc = so->so_rcv.ssb_cc - 1; if (cc < 1) return; switch (*mtod(m, char *)) { @@ -216,7 +217,7 @@ sohashttpget(struct socket *so, void *arg, int waitflag) fallout: DPRINT("fallout"); so->so_upcall = NULL; - so->so_rcv.sb_flags &= ~SB_UPCALL; + so->so_rcv.ssb_flags &= ~SSB_UPCALL; soisconnected(so); return; } @@ -230,10 +231,10 @@ soparsehttpvers(struct socket *so, void *arg, int waitflag) if ((so->so_state & SS_CANTRCVMORE) != 0 || sbfull(&so->so_rcv)) goto fallout; - m = so->so_rcv.sb_mb; - cc = so->so_rcv.sb_cc; + m = so->so_rcv.ssb_mb; + cc = so->so_rcv.ssb_cc; inspaces = spaces = 0; - for (m = so->so_rcv.sb_mb; m; m = n) { + for (m = so->so_rcv.ssb_mb; m; m = n) { n = m->m_nextpkt; for (; m; m = m->m_next) { for (i = 0; i < m->m_len; i++, cc--) { @@ -282,13 +283,13 @@ readmore: * we don't understand or a newline, so try again */ so->so_upcall = soparsehttpvers; - so->so_rcv.sb_flags |= SB_UPCALL; + so->so_rcv.ssb_flags |= SSB_UPCALL; return; fallout: DPRINT("fallout"); so->so_upcall = NULL; - so->so_rcv.sb_flags &= ~SB_UPCALL; + so->so_rcv.ssb_flags &= ~SSB_UPCALL; soisconnected(so); return; } @@ -315,11 +316,11 @@ soishttpconnected(struct socket *so, void *arg, int waitflag) * have NCHRS left */ copied = 0; - ccleft = so->so_rcv.sb_cc; + ccleft = so->so_rcv.ssb_cc; if (ccleft < NCHRS) goto readmore; a = b = c = '\0'; - for (m = so->so_rcv.sb_mb; m; m = n) { + for (m = so->so_rcv.ssb_mb; m; m = n) { n = m->m_nextpkt; for (; m; m = m->m_next) { ccleft -= m->m_len; @@ -353,12 +354,12 @@ soishttpconnected(struct socket *so, void *arg, int waitflag) readmore: so->so_upcall = soishttpconnected; - so->so_rcv.sb_flags |= SB_UPCALL; + so->so_rcv.ssb_flags |= SSB_UPCALL; return; gotit: so->so_upcall = NULL; - so->so_rcv.sb_flags &= ~SB_UPCALL; + so->so_rcv.ssb_flags &= ~SSB_UPCALL; soisconnected(so); return; } diff --git a/sys/net/ip_mroute/ip_mroute.c b/sys/net/ip_mroute/ip_mroute.c index 3e20e2211f..5356d8bc80 100644 --- a/sys/net/ip_mroute/ip_mroute.c +++ b/sys/net/ip_mroute/ip_mroute.c @@ -18,7 +18,7 @@ * bandwidth metering and signaling * * $FreeBSD: src/sys/netinet/ip_mroute.c,v 1.56.2.10 2003/08/24 21:37:34 hsu Exp $ - * $DragonFly: src/sys/net/ip_mroute/ip_mroute.c,v 1.21 2006/12/22 23:44:56 swildner Exp $ + * $DragonFly: src/sys/net/ip_mroute/ip_mroute.c,v 1.22 2007/04/22 01:13:13 dillon Exp $ */ #include "opt_mrouting.h" @@ -1126,7 +1126,7 @@ static int socket_send(struct socket *s, struct mbuf *mm, struct sockaddr_in *src) { if (s) { - if (sbappendaddr(&s->so_rcv, (struct sockaddr *)src, mm, NULL) != 0) { + if (ssb_appendaddr(&s->so_rcv, (struct sockaddr *)src, mm, NULL) != 0) { sorwakeup(s); return 0; } @@ -2180,8 +2180,8 @@ X_rsvp_input(struct mbuf *m, ...) rsvp_src.sin_addr = ip->ip_src; if (rsvpdebug && m) - kprintf("rsvp_input: m->m_len = %d, sbspace() = %ld\n", - m->m_len,sbspace(&(viftable[vifi].v_rsvpd->so_rcv))); + kprintf("rsvp_input: m->m_len = %d, ssb_space() = %ld\n", + m->m_len,ssb_space(&(viftable[vifi].v_rsvpd->so_rcv))); #ifdef ALTQ opts = NULL; @@ -2189,7 +2189,7 @@ X_rsvp_input(struct mbuf *m, ...) if (inp->inp_flags & INP_CONTROLOPTS || inp->inp_socket->so_options & SO_TIMESTAMP) ip_savecontrol(inp, &opts, ip, m); - if (sbappendaddr(&so->so_rcv, + if (ssb_appendaddr(&so->so_rcv, (struct sockaddr *)&rsvp_src,m, opts) == 0) { m_freem(m); if (opts) diff --git a/sys/net/netmsg.h b/sys/net/netmsg.h index 29f24eaaf1..fb424442cf 100644 --- a/sys/net/netmsg.h +++ b/sys/net/netmsg.h @@ -27,7 +27,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $DragonFly: src/sys/net/netmsg.h,v 1.4 2007/04/20 05:42:21 dillon Exp $ + * $DragonFly: src/sys/net/netmsg.h,v 1.5 2007/04/22 01:13:11 dillon Exp $ */ #ifndef _NET_NETMSG_H_ @@ -188,7 +188,7 @@ struct netmsg_pru_soreceive { struct socket *nm_so; struct sockaddr **nm_paddr; struct uio *nm_uio; - struct sorecv_direct *nm_sio; + struct sockbuf *nm_sio; struct mbuf **nm_controlp; int *nm_flagsp; }; diff --git a/sys/net/raw_usrreq.c b/sys/net/raw_usrreq.c index a4a288b2c5..284c0faa3a 100644 --- a/sys/net/raw_usrreq.c +++ b/sys/net/raw_usrreq.c @@ -32,7 +32,7 @@ * * @(#)raw_usrreq.c 8.1 (Berkeley) 6/10/93 * $FreeBSD: src/sys/net/raw_usrreq.c,v 1.18 1999/08/28 00:48:28 peter Exp $ - * $DragonFly: src/sys/net/raw_usrreq.c,v 1.12 2007/04/21 02:26:47 dillon Exp $ + * $DragonFly: src/sys/net/raw_usrreq.c,v 1.13 2007/04/22 01:13:11 dillon Exp $ */ #include @@ -95,7 +95,7 @@ raw_input(struct mbuf *m0, struct sockproto *proto, const struct sockaddr *src, n = m_copypacket(m, MB_DONTWAIT); if (n != NULL) { - if (sbappendaddr(&last->so_rcv, src, n, + if (ssb_appendaddr(&last->so_rcv, src, n, (struct mbuf *)0) == 0) { /* should notify about lost packet */ m_freem(n); @@ -107,7 +107,7 @@ raw_input(struct mbuf *m0, struct sockproto *proto, const struct sockaddr *src, last = rp->rcb_socket; } if (last) { - if (sbappendaddr(&last->so_rcv, src, m, (struct mbuf *)0) == 0) + if (ssb_appendaddr(&last->so_rcv, src, m, (struct mbuf *)0) == 0) m_freem(m); else sorwakeup(last); diff --git a/sys/netgraph/ksocket/ng_ksocket.c b/sys/netgraph/ksocket/ng_ksocket.c index 75b2934843..891251fd7f 100644 --- a/sys/netgraph/ksocket/ng_ksocket.c +++ b/sys/netgraph/ksocket/ng_ksocket.c @@ -37,7 +37,7 @@ * Author: Archie Cobbs * * $FreeBSD: src/sys/netgraph/ng_ksocket.c,v 1.5.2.14 2003/08/24 08:24:38 hsu Exp $ - * $DragonFly: src/sys/netgraph/ksocket/ng_ksocket.c,v 1.13 2007/04/20 05:42:22 dillon Exp $ + * $DragonFly: src/sys/netgraph/ksocket/ng_ksocket.c,v 1.14 2007/04/22 01:13:13 dillon Exp $ * $Whistle: ng_ksocket.c,v 1.1 1999/11/16 20:04:40 archie Exp $ */ @@ -613,8 +613,8 @@ ng_ksocket_newhook(node_p node, hook_p hook, const char *name0) /* Add our hook for incoming data and other events */ priv->so->so_upcallarg = (caddr_t)node; priv->so->so_upcall = ng_ksocket_incoming; - priv->so->so_rcv.sb_flags |= SB_UPCALL; - priv->so->so_snd.sb_flags |= SB_UPCALL; + priv->so->so_rcv.ssb_flags |= SSB_UPCALL; + priv->so->so_snd.ssb_flags |= SSB_UPCALL; } /* OK */ @@ -937,8 +937,8 @@ ng_ksocket_rmnode(node_p node) /* Close our socket (if any) */ if (priv->so != NULL) { priv->so->so_upcall = NULL; - priv->so->so_rcv.sb_flags &= ~SB_UPCALL; - priv->so->so_snd.sb_flags &= ~SB_UPCALL; + priv->so->so_rcv.ssb_flags &= ~SSB_UPCALL; + priv->so->so_snd.ssb_flags &= ~SSB_UPCALL; soclose(priv->so, FNONBLOCK); priv->so = NULL; } @@ -1051,12 +1051,12 @@ ng_ksocket_incoming(struct socket *so, void *arg, int waitflag) /* Read and forward available mbuf's */ while (1) { struct sockaddr *sa = NULL; - struct sorecv_direct sio; + struct sockbuf sio; meta_p meta = NULL; struct mbuf *n; int flags; - sorecv_direct_init(&sio, 1000000000); + sbinit(&sio, 1000000000); flags = MSG_DONTWAIT; /* Try to get next packet from socket */ @@ -1067,7 +1067,7 @@ ng_ksocket_incoming(struct socket *so, void *arg, int waitflag) break; /* See if we got anything */ - if (sio.m0 == NULL) { + if (sio.sb_mb == NULL) { if (sa != NULL) FREE(sa, M_SONAME); break; @@ -1075,9 +1075,9 @@ ng_ksocket_incoming(struct socket *so, void *arg, int waitflag) /* Don't trust the various socket layers to get the packet header and length correct (eg. kern/15175) */ - sio.m0->m_pkthdr.len = 0; - for (n = sio.m0; n != NULL; n = n->m_next) - sio.m0->m_pkthdr.len += n->m_len; + sio.sb_mb->m_pkthdr.len = 0; + for (n = sio.sb_mb; n != NULL; n = n->m_next) + sio.sb_mb->m_pkthdr.len += n->m_len; /* Put peer's socket address (if any) into a meta info blob */ if (sa != NULL) { @@ -1102,7 +1102,7 @@ ng_ksocket_incoming(struct socket *so, void *arg, int waitflag) FREE(sa, M_SONAME); } sendit: /* Forward data with optional peer sockaddr as meta info */ - NG_SEND_DATA(error, priv->hook, sio.m0, meta); + NG_SEND_DATA(error, priv->hook, sio.sb_mb, meta); } /* @@ -1167,7 +1167,7 @@ ng_ksocket_finish_accept(priv_p priv, struct ng_mesg **rptr) TAILQ_REMOVE(&head->so_comp, so, so_list); head->so_qlen--; - /* XXX KNOTE(&head->so_rcv.sb_sel.si_note, 0); */ + /* XXX KNOTE(&head->so_rcv.ssb_sel.si_note, 0); */ so->so_state &= ~SS_COMP; so->so_head = NULL; @@ -1207,8 +1207,8 @@ ng_ksocket_finish_accept(priv_p priv, struct ng_mesg **rptr) so->so_upcallarg = (caddr_t)node2; so->so_upcall = ng_ksocket_incoming; - so->so_rcv.sb_flags |= SB_UPCALL; - so->so_snd.sb_flags |= SB_UPCALL; + so->so_rcv.ssb_flags |= SSB_UPCALL; + so->so_snd.ssb_flags |= SSB_UPCALL; /* Fill in the response data and send it or return it to the caller */ resp_data = (struct ng_ksocket_accept *)resp->data; diff --git a/sys/netgraph/socket/ng_socket.c b/sys/netgraph/socket/ng_socket.c index 55373edf19..9aef3ac6d4 100644 --- a/sys/netgraph/socket/ng_socket.c +++ b/sys/netgraph/socket/ng_socket.c @@ -37,7 +37,7 @@ * Author: Julian Elischer * * $FreeBSD: src/sys/netgraph/ng_socket.c,v 1.11.2.6 2002/07/02 22:17:18 archie Exp $ - * $DragonFly: src/sys/netgraph/socket/ng_socket.c,v 1.12 2007/04/21 02:26:47 dillon Exp $ + * $DragonFly: src/sys/netgraph/socket/ng_socket.c,v 1.13 2007/04/22 01:13:13 dillon Exp $ * $Whistle: ng_socket.c,v 1.28 1999/11/01 09:24:52 julian Exp $ */ @@ -706,7 +706,7 @@ ship_msg(struct ngpcb *pcbp, struct ng_mesg *msg, struct sockaddr_ng *addr) } /* Send it up to the socket */ - if (sbappendaddr(&so->so_rcv, + if (ssb_appendaddr(&so->so_rcv, (struct sockaddr *) addr, mdata, NULL) == 0) { TRAP_ERROR; m_freem(mdata); @@ -825,7 +825,7 @@ ngs_rcvdata(hook_p hook, struct mbuf *m, meta_p meta) NG_FREE_META(meta); /* Try to tell the socket which hook it came in on */ - if (sbappendaddr(&so->so_rcv, (struct sockaddr *) addr, m, NULL) == 0) { + if (ssb_appendaddr(&so->so_rcv, (struct sockaddr *) addr, m, NULL) == 0) { m_freem(m); TRAP_ERROR; return (ENOBUFS); diff --git a/sys/netinet/ip_divert.c b/sys/netinet/ip_divert.c index 1db6083abc..dc2d73a1d6 100644 --- a/sys/netinet/ip_divert.c +++ b/sys/netinet/ip_divert.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/netinet/ip_divert.c,v 1.42.2.6 2003/01/23 21:06:45 sam Exp $ - * $DragonFly: src/sys/netinet/ip_divert.c,v 1.27 2007/04/21 02:26:48 dillon Exp $ + * $DragonFly: src/sys/netinet/ip_divert.c,v 1.28 2007/04/22 01:13:14 dillon Exp $ */ #include "opt_inet.h" @@ -226,7 +226,7 @@ divert_packet(struct mbuf *m, int incoming, int port) sa = inp->inp_socket; } if (sa) { - if (sbappendaddr(&sa->so_rcv, (struct sockaddr *)&divsrc, m, + if (ssb_appendaddr(&sa->so_rcv, (struct sockaddr *)&divsrc, m, (struct mbuf *)NULL) == 0) m_freem(m); else diff --git a/sys/netinet/raw_ip.c b/sys/netinet/raw_ip.c index 30c0d8d5f7..cb61c86eb8 100644 --- a/sys/netinet/raw_ip.c +++ b/sys/netinet/raw_ip.c @@ -32,7 +32,7 @@ * * @(#)raw_ip.c 8.7 (Berkeley) 5/15/95 * $FreeBSD: src/sys/netinet/raw_ip.c,v 1.64.2.16 2003/08/24 08:24:38 hsu Exp $ - * $DragonFly: src/sys/netinet/raw_ip.c,v 1.25 2007/04/21 02:26:48 dillon Exp $ + * $DragonFly: src/sys/netinet/raw_ip.c,v 1.26 2007/04/22 01:13:14 dillon Exp $ */ #include "opt_inet6.h" @@ -194,7 +194,7 @@ rip_input(struct mbuf *m, ...) if (last->inp_flags & INP_CONTROLOPTS || last->inp_socket->so_options & SO_TIMESTAMP) ip_savecontrol(last, &opts, ip, n); - if (sbappendaddr(&last->inp_socket->so_rcv, + if (ssb_appendaddr(&last->inp_socket->so_rcv, (struct sockaddr *)&ripsrc, n, opts) == 0) { /* should notify about lost packet */ @@ -233,7 +233,7 @@ rip_input(struct mbuf *m, ...) if (last->inp_flags & INP_CONTROLOPTS || last->inp_socket->so_options & SO_TIMESTAMP) ip_savecontrol(last, &opts, ip, m); - if (sbappendaddr(&last->inp_socket->so_rcv, + if (ssb_appendaddr(&last->inp_socket->so_rcv, (struct sockaddr *)&ripsrc, m, opts) == 0) { m_freem(m); if (opts) diff --git a/sys/netinet/sctp_indata.c b/sys/netinet/sctp_indata.c index f604217d8c..105c6469a5 100644 --- a/sys/netinet/sctp_indata.c +++ b/sys/netinet/sctp_indata.c @@ -1,5 +1,5 @@ /* $KAME: sctp_indata.c,v 1.35 2004/08/17 04:06:17 itojun Exp $ */ -/* $DragonFly: src/sys/netinet/sctp_indata.c,v 1.6 2006/12/22 23:57:52 swildner Exp $ */ +/* $DragonFly: src/sys/netinet/sctp_indata.c,v 1.7 2007/04/22 01:13:14 dillon Exp $ */ /* * Copyright (C) 2002, 2003, 2004 Cisco Systems Inc, @@ -125,11 +125,11 @@ sctp_set_rwnd(struct sctp_tcb *stcb, struct sctp_association *asoc) #ifdef SCTP_DEBUG if (sctp_debug_on & SCTP_DEBUG_INDATA4) { kprintf("cc:%lu hiwat:%lu lowat:%lu mbcnt:%lu mbmax:%lu\n", - (u_long)stcb->sctp_socket->so_rcv.sb_cc, - (u_long)stcb->sctp_socket->so_rcv.sb_hiwat, - (u_long)stcb->sctp_socket->so_rcv.sb_lowat, - (u_long)stcb->sctp_socket->so_rcv.sb_mbcnt, - (u_long)stcb->sctp_socket->so_rcv.sb_mbmax); + (u_long)stcb->sctp_socket->so_rcv.ssb_cc, + (u_long)stcb->sctp_socket->so_rcv.ssb_hiwat, + (u_long)stcb->sctp_socket->so_rcv.ssb_lowat, + (u_long)stcb->sctp_socket->so_rcv.ssb_mbcnt, + (u_long)stcb->sctp_socket->so_rcv.ssb_mbmax); kprintf("Setting rwnd to: sb:%ld - (del:%d + reasm:%d str:%d)\n", sctp_sbspace(&stcb->sctp_socket->so_rcv), asoc->size_on_delivery_queue, @@ -137,12 +137,12 @@ sctp_set_rwnd(struct sctp_tcb *stcb, struct sctp_association *asoc) asoc->size_on_all_streams); } #endif - if (stcb->sctp_socket->so_rcv.sb_cc == 0 && + if (stcb->sctp_socket->so_rcv.ssb_cc == 0 && asoc->size_on_delivery_queue == 0 && asoc->size_on_reasm_queue == 0 && asoc->size_on_all_streams == 0) { /* Full rwnd granted */ - asoc->my_rwnd = max(stcb->sctp_socket->so_rcv.sb_hiwat, + asoc->my_rwnd = max(stcb->sctp_socket->so_rcv.ssb_hiwat, SCTP_MINIMAL_RWND); return; } @@ -382,7 +382,7 @@ sctp_deliver_data(struct sctp_tcb *stcb, struct sctp_association *asoc, return (0); } - if (stcb->sctp_socket->so_rcv.sb_cc >= stcb->sctp_socket->so_rcv.sb_hiwat) { + if (stcb->sctp_socket->so_rcv.ssb_cc >= stcb->sctp_socket->so_rcv.ssb_hiwat) { /* Boy, there really is NO room */ if (hold_locks == 0) SCTP_INP_WUNLOCK(stcb->sctp_ep); @@ -459,7 +459,7 @@ sctp_deliver_data(struct sctp_tcb *stcb, struct sctp_association *asoc, } goto skip; } - if (!sbappendaddr_nocheck(&stcb->sctp_socket->so_rcv, + if (!sctp_sbappendaddr_nocheck(&stcb->sctp_socket->so_rcv, to, chk->data, control, stcb->asoc.my_vtag, stcb->sctp_ep)) { /* Gak not enough room */ @@ -483,7 +483,7 @@ sctp_deliver_data(struct sctp_tcb *stcb, struct sctp_association *asoc, /* append to a already started message. */ if (sctp_sbspace(&stcb->sctp_socket->so_rcv) >= (long)chk->send_size) { - sbappend(&stcb->sctp_socket->so_rcv, chk->data); + ssb_append(&stcb->sctp_socket->so_rcv, chk->data); free_it = 1; } } @@ -569,8 +569,8 @@ sctp_service_reassembly(struct sctp_tcb *stcb, struct sctp_association *asoc, in return; } do { - if (stcb->sctp_socket->so_rcv.sb_cc >= - stcb->sctp_socket->so_rcv.sb_hiwat) { + if (stcb->sctp_socket->so_rcv.ssb_cc >= + stcb->sctp_socket->so_rcv.ssb_hiwat) { if (cntDel) { sctp_sorwakeup(stcb->sctp_ep, stcb->sctp_socket); @@ -684,7 +684,7 @@ sctp_service_reassembly(struct sctp_tcb *stcb, struct sctp_association *asoc, in SCTP_INP_WUNLOCK(stcb->sctp_ep); return; } - if (!sbappendaddr_nocheck(&stcb->sctp_socket->so_rcv, + if (!sctp_sbappendaddr_nocheck(&stcb->sctp_socket->so_rcv, to, chk->data, control, stcb->asoc.my_vtag, stcb->sctp_ep)) { /* Gak not enough room */ @@ -711,7 +711,7 @@ sctp_service_reassembly(struct sctp_tcb *stcb, struct sctp_association *asoc, in } else { if (sctp_sbspace(&stcb->sctp_socket->so_rcv) >= (long)chk->send_size) { - sbappend(&stcb->sctp_socket->so_rcv, chk->data); + ssb_append(&stcb->sctp_socket->so_rcv, chk->data); cntDel++; } else { /* out of space in the sb */ @@ -1592,7 +1592,7 @@ sctp_queue_data_for_reasm(struct sctp_tcb *stcb, struct sctp_association *asoc, if (TAILQ_EMPTY(&asoc->delivery_queue) && (sctp_is_all_msg_on_reasm(asoc, &tsize) || (asoc->size_on_reasm_queue >= - (stcb->sctp_socket->so_rcv.sb_hiwat >> 2) && + (stcb->sctp_socket->so_rcv.ssb_hiwat >> 2) && tsize))) { /* * Yes, we setup to @@ -1775,7 +1775,7 @@ sctp_process_a_data_chunk(struct sctp_tcb *stcb, struct sctp_association *asoc, * When we have NO room in the rwnd we check * to make sure the reader is doing its job... */ - if (stcb->sctp_socket->so_rcv.sb_cc) { + if (stcb->sctp_socket->so_rcv.ssb_cc) { /* some to read, wake-up */ sctp_sorwakeup(stcb->sctp_ep, stcb->sctp_socket); } @@ -1909,8 +1909,8 @@ sctp_process_a_data_chunk(struct sctp_tcb *stcb, struct sctp_association *asoc, ((ch->ch.chunk_flags & SCTP_DATA_UNORDERED) || ((asoc->strmin[strmno].last_sequence_delivered + 1) == strmseq && TAILQ_EMPTY(&asoc->strmin[strmno].inqueue))) && - ((long)(stcb->sctp_socket->so_rcv.sb_hiwat - - stcb->sctp_socket->so_rcv.sb_cc) >= (long)the_len)) { + ((long)(stcb->sctp_socket->so_rcv.ssb_hiwat - + stcb->sctp_socket->so_rcv.ssb_cc) >= (long)the_len)) { /* Candidate for express delivery */ /* * Its not fragmented, @@ -1996,7 +1996,7 @@ sctp_process_a_data_chunk(struct sctp_tcb *stcb, struct sctp_association *asoc, SCTP_TCB_UNLOCK(stcb); SCTP_INP_WLOCK(stcb->sctp_ep); SCTP_TCB_LOCK(stcb); - if (!sbappendaddr_nocheck(&stcb->sctp_socket->so_rcv, to, dmbuf, + if (!sctp_sbappendaddr_nocheck(&stcb->sctp_socket->so_rcv, to, dmbuf, control, stcb->asoc.my_vtag, stcb->sctp_ep)) { if (control) { sctp_m_freem(control); @@ -2463,7 +2463,7 @@ sctp_service_queues(struct sctp_tcb *stcb, struct sctp_association *asoc, int ho * have some on the sb hold queue. */ do { - if (stcb->sctp_socket->so_rcv.sb_cc >= stcb->sctp_socket->so_rcv.sb_hiwat) { + if (stcb->sctp_socket->so_rcv.ssb_cc >= stcb->sctp_socket->so_rcv.ssb_hiwat) { if (cntDel == 0) sctp_sorwakeup(stcb->sctp_ep, stcb->sctp_socket); break; @@ -2506,7 +2506,7 @@ sctp_service_queues(struct sctp_tcb *stcb, struct sctp_association *asoc, int ho if (TAILQ_EMPTY(&asoc->delivery_queue) && (sctp_is_all_msg_on_reasm(asoc, &tsize) || (asoc->size_on_reasm_queue >= - (stcb->sctp_socket->so_rcv.sb_hiwat >> 2) && tsize))) { + (stcb->sctp_socket->so_rcv.ssb_hiwat >> 2) && tsize))) { asoc->fragmented_delivery_inprogress = 1; asoc->tsn_last_delivered = chk->rec.data.TSN_seq-1; asoc->str_of_pdapi = chk->rec.data.stream_number; diff --git a/sys/netinet/sctp_input.c b/sys/netinet/sctp_input.c index 4bf680a2c4..4a4ebe99fa 100644 --- a/sys/netinet/sctp_input.c +++ b/sys/netinet/sctp_input.c @@ -1,5 +1,5 @@ /* $KAME: sctp_input.c,v 1.27 2005/03/06 16:04:17 itojun Exp $ */ -/* $DragonFly: src/sys/netinet/sctp_input.c,v 1.10 2006/12/22 23:57:52 swildner Exp $ */ +/* $DragonFly: src/sys/netinet/sctp_input.c,v 1.11 2007/04/22 01:13:14 dillon Exp $ */ /* * Copyright (C) 2002, 2003, 2004 Cisco Systems Inc, @@ -683,8 +683,8 @@ sctp_handle_shutdown_ack(struct sctp_shutdown_ack_chunk *cp, (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { stcb->sctp_ep->sctp_flags &= ~SCTP_PCB_FLAGS_CONNECTED; /* Set the connected flag to disconnected */ - stcb->sctp_ep->sctp_socket->so_snd.sb_cc = 0; - stcb->sctp_ep->sctp_socket->so_snd.sb_mbcnt = 0; + stcb->sctp_ep->sctp_socket->so_snd.ssb_cc = 0; + stcb->sctp_ep->sctp_socket->so_snd.ssb_mbcnt = 0; soisdisconnected(stcb->sctp_ep->sctp_socket); } /* free the TCB but first save off the ep */ @@ -2382,8 +2382,8 @@ sctp_handle_shutdown_complete(struct sctp_shutdown_complete_chunk *cp, if ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { stcb->sctp_ep->sctp_flags &= ~SCTP_PCB_FLAGS_CONNECTED; - stcb->sctp_ep->sctp_socket->so_snd.sb_cc = 0; - stcb->sctp_ep->sctp_socket->so_snd.sb_mbcnt = 0; + stcb->sctp_ep->sctp_socket->so_snd.ssb_cc = 0; + stcb->sctp_ep->sctp_socket->so_snd.ssb_mbcnt = 0; soisdisconnected(stcb->sctp_ep->sctp_socket); } /* are the queues empty? they should be */ diff --git a/sys/netinet/sctp_output.c b/sys/netinet/sctp_output.c index fade02f258..4997970e38 100644 --- a/sys/netinet/sctp_output.c +++ b/sys/netinet/sctp_output.c @@ -1,5 +1,5 @@ /* $KAME: sctp_output.c,v 1.46 2005/03/06 16:04:17 itojun Exp $ */ -/* $DragonFly: src/sys/netinet/sctp_output.c,v 1.10 2007/01/02 19:30:57 tgen Exp $ */ +/* $DragonFly: src/sys/netinet/sctp_output.c,v 1.11 2007/04/22 01:13:14 dillon Exp $ */ /* * Copyright (C) 2002, 2003, 2004 Cisco Systems Inc, @@ -2732,7 +2732,7 @@ sctp_send_initiate(struct sctp_inpcb *inp, struct sctp_tcb *stcb) /* place in my tag */ initm->msg.init.initiate_tag = htonl(stcb->asoc.my_vtag); /* set up some of the credits. */ - initm->msg.init.a_rwnd = htonl(max(inp->sctp_socket->so_rcv.sb_hiwat, + initm->msg.init.a_rwnd = htonl(max(inp->sctp_socket->so_rcv.ssb_hiwat, SCTP_MINIMAL_RWND)); initm->msg.init.num_outbound_streams = htons(stcb->asoc.pre_open_streams); @@ -3690,7 +3690,7 @@ sctp_send_initiate_ack(struct sctp_inpcb *inp, struct sctp_tcb *stcb, stc.my_vtag = initackm_out->msg.init.initiate_tag; /* set up some of the credits. */ - initackm_out->msg.init.a_rwnd = htonl(max(inp->sctp_socket->so_rcv.sb_hiwat, SCTP_MINIMAL_RWND)); + initackm_out->msg.init.a_rwnd = htonl(max(inp->sctp_socket->so_rcv.ssb_hiwat, SCTP_MINIMAL_RWND)); /* set what I want */ his_limit = ntohs(init_chk->init.num_inbound_streams); /* choose what I want */ @@ -4309,11 +4309,11 @@ sctp_msg_append(struct sctp_tcb *stcb, /* lock the socket buf */ SOCKBUF_LOCK(&so->so_snd); - error = sblock(&so->so_snd, SBLOCKWAIT(flags)); + error = ssb_lock(&so->so_snd, SBLOCKWAIT(flags)); if (error) goto out_locked; - if (dataout > so->so_snd.sb_hiwat) { + if (dataout > so->so_snd.ssb_hiwat) { /* It will NEVER fit */ error = EMSGSIZE; goto release; @@ -4324,21 +4324,21 @@ sctp_msg_append(struct sctp_tcb *stcb, ) { goto zap_by_it_all; } - if ((so->so_snd.sb_hiwat < + if ((so->so_snd.ssb_hiwat < (dataout + asoc->total_output_queue_size)) || (asoc->chunks_on_out_queue > sctp_max_chunks_on_queue) || (asoc->total_output_mbuf_queue_size > - so->so_snd.sb_mbmax) + so->so_snd.ssb_mbmax) ) { /* XXX Buffer space hunt for data to skip */ if (asoc->peer_supports_prsctp) { sctp_prune_prsctp(stcb, asoc, srcv, dataout); } - while ((so->so_snd.sb_hiwat < + while ((so->so_snd.ssb_hiwat < (dataout + asoc->total_output_queue_size)) || (asoc->chunks_on_out_queue > sctp_max_chunks_on_queue) || (asoc->total_output_mbuf_queue_size > - so->so_snd.sb_mbmax)) { + so->so_snd.ssb_mbmax)) { struct sctp_inpcb *inp; /* Now did we free up enough room? */ if (flags & (MSG_FNONBLOCKING|MSG_DONTWAIT)) { @@ -4365,8 +4365,8 @@ sctp_msg_append(struct sctp_tcb *stcb, inp->sctp_tcb_at_block = (void *)stcb; inp->error_on_block = 0; - sbunlock(&so->so_snd); - error = sbwait(&so->so_snd); + ssb_unlock(&so->so_snd); + error = ssb_wait(&so->so_snd); /* * XXX: This is ugly but I have * recreated most of what goes on to @@ -4384,7 +4384,7 @@ sctp_msg_append(struct sctp_tcb *stcb, if (error) { goto out_locked; } - error = sblock(&so->so_snd, M_WAITOK); + error = ssb_lock(&so->so_snd, M_WAITOK); if (error) goto out_locked; /* Otherwise we cycle back and recheck @@ -4658,8 +4658,8 @@ zap_by_it_all: asoc->total_output_mbuf_queue_size += mbcnt; if ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { - so->so_snd.sb_cc += dataout; - so->so_snd.sb_mbcnt += mbcnt; + so->so_snd.ssb_cc += dataout; + so->so_snd.ssb_mbcnt += mbcnt; } #ifdef SCTP_DEBUG @@ -4671,7 +4671,7 @@ zap_by_it_all: #endif release: - sbunlock(&so->so_snd); + ssb_unlock(&so->so_snd); out_locked: SOCKBUF_UNLOCK(&so->so_snd); out: @@ -5111,7 +5111,7 @@ sctp_move_to_outqueue(struct sctp_tcb *stcb, /* A new mbuf was added, account for it */ if ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { - stcb->sctp_socket->so_snd.sb_mbcnt += MSIZE; + stcb->sctp_socket->so_snd.ssb_mbcnt += MSIZE; } #ifdef SCTP_MBCNT_LOGGING sctp_log_mbcnt(SCTP_LOG_MBCNT_INCREASE, @@ -6412,7 +6412,7 @@ sctp_send_shutdown(struct sctp_tcb *stcb, struct sctp_nets *net) if ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { - stcb->sctp_ep->sctp_socket->so_snd.sb_cc = 0; + stcb->sctp_ep->sctp_socket->so_snd.ssb_cc = 0; soisdisconnecting(stcb->sctp_ep->sctp_socket); } return (0); @@ -8147,7 +8147,7 @@ sctp_send_shutdown_complete(struct sctp_tcb *stcb, if ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { stcb->sctp_ep->sctp_flags &= ~SCTP_PCB_FLAGS_CONNECTED; - stcb->sctp_ep->sctp_socket->so_snd.sb_cc = 0; + stcb->sctp_ep->sctp_socket->so_snd.ssb_cc = 0; soisdisconnected(stcb->sctp_ep->sctp_socket); } return (0); @@ -8734,7 +8734,7 @@ sctp_send_packet_dropped(struct sctp_tcb *stcb, struct sctp_nets *net, chk->rec.chunk_id = SCTP_PACKET_DROPPED; drp->ch.chunk_type = SCTP_PACKET_DROPPED; drp->ch.chunk_length = htons(chk->send_size); - spc = stcb->sctp_socket->so_rcv.sb_hiwat; + spc = stcb->sctp_socket->so_rcv.ssb_hiwat; if (spc < 0) { spc = 0; } @@ -8743,7 +8743,7 @@ sctp_send_packet_dropped(struct sctp_tcb *stcb, struct sctp_nets *net, asoc->size_on_reasm_queue + asoc->size_on_all_streams + asoc->my_rwnd_control_len + - stcb->sctp_socket->so_rcv.sb_cc); + stcb->sctp_socket->so_rcv.ssb_cc); drp->reserved = 0; datap = drp->data; m_copydata(m, iphlen, len, datap); @@ -9516,23 +9516,23 @@ sctp_copy_it_in(struct sctp_inpcb *inp, sndlen = uio->uio_resid; /* lock the socket buf */ SOCKBUF_LOCK(&so->so_snd); - error = sblock(&so->so_snd, SBLOCKWAIT(flags)); + error = ssb_lock(&so->so_snd, SBLOCKWAIT(flags)); if (error) goto out_locked; /* will it ever fit ? */ - if (sndlen > so->so_snd.sb_hiwat) { + if (sndlen > so->so_snd.ssb_hiwat) { /* It will NEVER fit */ error = EMSGSIZE; crit_exit(); goto release; } /* Do I need to block? */ - if ((so->so_snd.sb_hiwat < + if ((so->so_snd.ssb_hiwat < (sndlen + asoc->total_output_queue_size)) || (asoc->chunks_on_out_queue > sctp_max_chunks_on_queue) || (asoc->total_output_mbuf_queue_size > - so->so_snd.sb_mbmax) + so->so_snd.ssb_mbmax) ) { /* prune any prsctp bufs out */ if (asoc->peer_supports_prsctp) { @@ -9545,12 +9545,12 @@ sctp_copy_it_in(struct sctp_inpcb *inp, * been reset and our stcb destroyed. Returning * an error will flow back to the user... */ - while ((so->so_snd.sb_hiwat < + while ((so->so_snd.ssb_hiwat < (sndlen + asoc->total_output_queue_size)) || (asoc->chunks_on_out_queue > sctp_max_chunks_on_queue) || (asoc->total_output_mbuf_queue_size > - so->so_snd.sb_mbmax) + so->so_snd.ssb_mbmax) ) { if (flags & (MSG_FNONBLOCKING|MSG_DONTWAIT)) { /* Non-blocking io in place */ @@ -9563,9 +9563,9 @@ sctp_copy_it_in(struct sctp_inpcb *inp, sctp_log_block(SCTP_BLOCK_LOG_INTO_BLK, so, asoc); #endif - sbunlock(&so->so_snd); + ssb_unlock(&so->so_snd); SCTP_TCB_UNLOCK(stcb); - error = sbwait(&so->so_snd); + error = ssb_wait(&so->so_snd); SCTP_INP_RLOCK(inp); if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) || (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) { @@ -9602,7 +9602,7 @@ sctp_copy_it_in(struct sctp_inpcb *inp, crit_exit(); goto out_locked; } - error = sblock(&so->so_snd, M_WAITOK); + error = ssb_lock(&so->so_snd, M_WAITOK); if (error) { /* Can't aquire the lock */ crit_exit(); @@ -9682,7 +9682,7 @@ sctp_copy_it_in(struct sctp_inpcb *inp, mm = NULL; } } - sbunlock(&so->so_snd); + ssb_unlock(&so->so_snd); SOCKBUF_UNLOCK(&so->so_snd); sctp_abort_an_association(stcb->sctp_ep, stcb, SCTP_RESPONSE_TO_USER_REQ, @@ -9949,8 +9949,8 @@ zap_by_it_now: asoc->total_output_mbuf_queue_size += mbcnt; if ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { - so->so_snd.sb_cc += dataout; - so->so_snd.sb_mbcnt += mbcnt; + so->so_snd.ssb_cc += dataout; + so->so_snd.ssb_mbcnt += mbcnt; } if ((srcv->sinfo_flags & MSG_EOF) && (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) @@ -10012,7 +10012,7 @@ zap_by_it_now: #endif release: - sbunlock(&so->so_snd); + ssb_unlock(&so->so_snd); out_locked: SOCKBUF_UNLOCK(&so->so_snd); out_notlocked: diff --git a/sys/netinet/sctp_pcb.c b/sys/netinet/sctp_pcb.c index ccab176e52..5e394ad065 100644 --- a/sys/netinet/sctp_pcb.c +++ b/sys/netinet/sctp_pcb.c @@ -1,5 +1,5 @@ /* $KAME: sctp_pcb.c,v 1.37 2004/08/17 06:28:02 t-momose Exp $ */ -/* $DragonFly: src/sys/netinet/sctp_pcb.c,v 1.11 2006/12/22 23:57:52 swildner Exp $ */ +/* $DragonFly: src/sys/netinet/sctp_pcb.c,v 1.12 2007/04/22 01:13:14 dillon Exp $ */ /* * Copyright (c) 2001, 2002, 2003, 2004 Cisco Systems, Inc. @@ -2285,7 +2285,7 @@ sctp_inpcb_free(struct sctp_inpcb *inp, int immediate) if ((asoc->asoc.size_on_delivery_queue > 0) || (asoc->asoc.size_on_reasm_queue > 0) || (asoc->asoc.size_on_all_streams > 0) || - (so && (so->so_rcv.sb_cc > 0)) + (so && (so->so_rcv.ssb_cc > 0)) ) { /* Left with Data unread */ struct mbuf *op_err; @@ -3594,11 +3594,11 @@ sctp_free_assoc(struct sctp_inpcb *inp, struct sctp_tcb *stcb) /* now clean up the tasoc itself */ SCTP_ZONE_FREE(sctppcbinfo.ipi_zone_asoc, stcb); sctppcbinfo.ipi_count_asoc--; - if ((inp->sctp_socket->so_snd.sb_cc) || - (inp->sctp_socket->so_snd.sb_mbcnt)) { + if ((inp->sctp_socket->so_snd.ssb_cc) || + (inp->sctp_socket->so_snd.ssb_mbcnt)) { /* This will happen when a abort is done */ - inp->sctp_socket->so_snd.sb_cc = 0; - inp->sctp_socket->so_snd.sb_mbcnt = 0; + inp->sctp_socket->so_snd.ssb_cc = 0; + inp->sctp_socket->so_snd.ssb_mbcnt = 0; } if (inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) { if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) == 0) { diff --git a/sys/netinet/sctp_usrreq.c b/sys/netinet/sctp_usrreq.c index d7a31337dd..c281308ee8 100644 --- a/sys/netinet/sctp_usrreq.c +++ b/sys/netinet/sctp_usrreq.c @@ -1,5 +1,5 @@ /* $KAME: sctp_usrreq.c,v 1.47 2005/03/06 16:04:18 itojun Exp $ */ -/* $DragonFly: src/sys/netinet/sctp_usrreq.c,v 1.11 2007/04/21 02:26:48 dillon Exp $ */ +/* $DragonFly: src/sys/netinet/sctp_usrreq.c,v 1.12 2007/04/22 01:13:14 dillon Exp $ */ /* * Copyright (c) 2001, 2002, 2003, 2004 Cisco Systems, Inc. @@ -812,7 +812,7 @@ sctp_detach(struct socket *so) return EINVAL; crit_enter(); if (((so->so_options & SO_LINGER) && (so->so_linger == 0)) || - (so->so_rcv.sb_cc > 0)) { + (so->so_rcv.ssb_cc > 0)) { sctp_inpcb_free(inp, 1); } else { sctp_inpcb_free(inp, 0); @@ -968,7 +968,7 @@ sctp_disconnect(struct socket *so) SCTP_TCB_LOCK(stcb); if (((so->so_options & SO_LINGER) && (so->so_linger == 0)) || - (so->so_rcv.sb_cc > 0)) { + (so->so_rcv.ssb_cc > 0)) { if (SCTP_GET_STATE(asoc) != SCTP_STATE_COOKIE_WAIT) { /* Left with Data unread */ @@ -2553,7 +2553,7 @@ sctp_optsget(struct socket *so, sasoc->sasoc_asocmaxrxt = inp->sctp_ep.max_send_times; sasoc->sasoc_number_peer_destinations = 0; sasoc->sasoc_peer_rwnd = 0; - sasoc->sasoc_local_rwnd = sbspace(&inp->sctp_socket->so_rcv); + sasoc->sasoc_local_rwnd = ssb_space(&inp->sctp_socket->so_rcv); sasoc->sasoc_cookie_life = inp->sctp_ep.def_cookie_life; SCTP_INP_RUNLOCK(inp); } @@ -3915,7 +3915,7 @@ sctp_usr_recvd(struct socket *so, int flags) incr = 0; } if (((uint32_t)incr >= (stcb->asoc.smallest_mtu * SCTP_SEG_TO_RWND_UPD)) || - ((((uint32_t)incr)*SCTP_SCALE_OF_RWND_TO_UPD) >= so->so_rcv.sb_hiwat)) { + ((((uint32_t)incr)*SCTP_SCALE_OF_RWND_TO_UPD) >= so->so_rcv.ssb_hiwat)) { if (callout_pending(&stcb->asoc.dack_timer.timer)) { /* If the timer is up, stop it */ sctp_timer_stop(SCTP_TIMER_TYPE_RECV, @@ -3933,12 +3933,12 @@ sctp_usr_recvd(struct socket *so, int flags) } } SOCKBUF_LOCK(&so->so_rcv); - if (( so->so_rcv.sb_mb == NULL ) && + if (( so->so_rcv.ssb_mb == NULL ) && (TAILQ_EMPTY(&inp->sctp_queue_list) == 0)) { int sq_cnt=0; #ifdef SCTP_DEBUG if (sctp_debug_on & SCTP_DEBUG_USRREQ2) - kprintf("Something off, inp:%x so->so_rcv->sb_mb is empty and sockq is not.. cleaning\n", + kprintf("Something off, inp:%x so->so_rcv->ssb_mb is empty and sockq is not.. cleaning\n", (u_int)inp); #endif if (((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) == 0) diff --git a/sys/netinet/sctp_var.h b/sys/netinet/sctp_var.h index 932852b1b9..8931d7d135 100644 --- a/sys/netinet/sctp_var.h +++ b/sys/netinet/sctp_var.h @@ -1,5 +1,5 @@ /* $KAME: sctp_var.h,v 1.23 2004/10/27 07:57:49 itojun Exp $ */ -/* $DragonFly: src/sys/netinet/sctp_var.h,v 1.3 2006/01/14 11:33:50 swildner Exp $ */ +/* $DragonFly: src/sys/netinet/sctp_var.h,v 1.4 2007/04/22 01:13:14 dillon Exp $ */ /* * Copyright (c) 2001, 2002, 2003, 2004 Cisco Systems, Inc. @@ -162,7 +162,7 @@ int sctp_usrreq(struct socket *, int, struct mbuf *, struct mbuf *, struct mbuf *); #endif -#define sctp_sbspace(sb) ((long) (((sb)->sb_hiwat > (sb)->sb_cc) ? ((sb)->sb_hiwat - (sb)->sb_cc) : 0)) +#define sctp_sbspace(ssb) ((long) (((ssb)->ssb_hiwat > (ssb)->ssb_cc) ? ((ssb)->ssb_hiwat - (ssb)->ssb_cc) : 0)) #define sctp_sbspace_sub(a,b) ((a > b) ? (a - b) : 0) diff --git a/sys/netinet/sctputil.c b/sys/netinet/sctputil.c index a506f082f2..d74b9754e2 100644 --- a/sys/netinet/sctputil.c +++ b/sys/netinet/sctputil.c @@ -1,5 +1,5 @@ /* $KAME: sctputil.c,v 1.36 2005/03/06 16:04:19 itojun Exp $ */ -/* $DragonFly: src/sys/netinet/sctputil.c,v 1.7 2006/12/22 23:57:52 swildner Exp $ */ +/* $DragonFly: src/sys/netinet/sctputil.c,v 1.8 2007/04/22 01:13:14 dillon Exp $ */ /* * Copyright (c) 2001, 2002, 2003, 2004 Cisco Systems, Inc. @@ -319,9 +319,9 @@ sctp_log_block(uint8_t from, struct socket *so, struct sctp_association *asoc) sctp_clog[sctp_cwnd_log_at].from = (u_int8_t)from; sctp_clog[sctp_cwnd_log_at].event_type = (u_int8_t)SCTP_LOG_EVENT_BLOCK; - sctp_clog[sctp_cwnd_log_at].x.blk.maxmb = (u_int16_t)(so->so_snd.sb_mbmax/1024); + sctp_clog[sctp_cwnd_log_at].x.blk.maxmb = (u_int16_t)(so->so_snd.ssb_mbmax/1024); sctp_clog[sctp_cwnd_log_at].x.blk.onmb = asoc->total_output_mbuf_queue_size; - sctp_clog[sctp_cwnd_log_at].x.blk.maxsb = (u_int16_t)(so->so_snd.sb_hiwat/1024); + sctp_clog[sctp_cwnd_log_at].x.blk.maxsb = (u_int16_t)(so->so_snd.ssb_hiwat/1024); sctp_clog[sctp_cwnd_log_at].x.blk.onsb = asoc->total_output_queue_size; sctp_clog[sctp_cwnd_log_at].x.blk.send_sent_qcnt = (u_int16_t)(asoc->send_queue_cnt + asoc->sent_queue_cnt); sctp_clog[sctp_cwnd_log_at].x.blk.stream_qcnt = (u_int16_t)asoc->stream_queue_cnt; @@ -809,8 +809,8 @@ sctp_init_asoc(struct sctp_inpcb *m, struct sctp_association *asoc, } - asoc->my_rwnd = max(m->sctp_socket->so_rcv.sb_hiwat, SCTP_MINIMAL_RWND); - asoc->peers_rwnd = m->sctp_socket->so_rcv.sb_hiwat; + asoc->my_rwnd = max(m->sctp_socket->so_rcv.ssb_hiwat, SCTP_MINIMAL_RWND); + asoc->peers_rwnd = m->sctp_socket->so_rcv.ssb_hiwat; asoc->smallest_mtu = m->sctp_frag_point; asoc->minrto = m->sctp_ep.sctp_minrto; @@ -2189,7 +2189,7 @@ sctp_notify_assoc_change(u_int32_t event, struct sctp_tcb *stcb, SCTP_TCB_UNLOCK(stcb); SCTP_INP_WLOCK(stcb->sctp_ep); SCTP_TCB_LOCK(stcb); - if (!sbappendaddr_nocheck(&stcb->sctp_socket->so_rcv, + if (!sctp_sbappendaddr_nocheck(&stcb->sctp_socket->so_rcv, to, m_notify, NULL, stcb->asoc.my_vtag, stcb->sctp_ep)) { /* not enough room */ sctp_m_freem(m_notify); @@ -2281,7 +2281,7 @@ sctp_notify_peer_addr_change(struct sctp_tcb *stcb, uint32_t state, SCTP_TCB_UNLOCK(stcb); SCTP_INP_WLOCK(stcb->sctp_ep); SCTP_TCB_LOCK(stcb); - if (!sbappendaddr_nocheck(&stcb->sctp_socket->so_rcv, to, + if (!sctp_sbappendaddr_nocheck(&stcb->sctp_socket->so_rcv, to, m_notify, NULL, stcb->asoc.my_vtag, stcb->sctp_ep)) { /* not enough room */ sctp_m_freem(m_notify); @@ -2382,7 +2382,7 @@ sctp_notify_send_failed(struct sctp_tcb *stcb, u_int32_t error, SCTP_TCB_UNLOCK(stcb); SCTP_INP_WLOCK(stcb->sctp_ep); SCTP_TCB_LOCK(stcb); - if (!sbappendaddr_nocheck(&stcb->sctp_socket->so_rcv, to, + if (!sctp_sbappendaddr_nocheck(&stcb->sctp_socket->so_rcv, to, m_notify, NULL, stcb->asoc.my_vtag, stcb->sctp_ep)) { /* not enough room */ sctp_m_freem(m_notify); @@ -2458,7 +2458,7 @@ sctp_notify_adaption_layer(struct sctp_tcb *stcb, SCTP_TCB_UNLOCK(stcb); SCTP_INP_WLOCK(stcb->sctp_ep); SCTP_TCB_LOCK(stcb); - if (!sbappendaddr_nocheck(&stcb->sctp_socket->so_rcv, to, + if (!sctp_sbappendaddr_nocheck(&stcb->sctp_socket->so_rcv, to, m_notify, NULL, stcb->asoc.my_vtag, stcb->sctp_ep)) { /* not enough room */ sctp_m_freem(m_notify); @@ -2534,7 +2534,7 @@ sctp_notify_partial_delivery_indication(struct sctp_tcb *stcb, SCTP_TCB_UNLOCK(stcb); SCTP_INP_WLOCK(stcb->sctp_ep); SCTP_TCB_LOCK(stcb); - if (!sbappendaddr_nocheck(&stcb->sctp_socket->so_rcv, to, + if (!sctp_sbappendaddr_nocheck(&stcb->sctp_socket->so_rcv, to, m_notify, NULL, stcb->asoc.my_vtag, stcb->sctp_ep)) { /* not enough room */ sctp_m_freem(m_notify); @@ -2619,7 +2619,7 @@ sctp_notify_shutdown_event(struct sctp_tcb *stcb) SCTP_TCB_UNLOCK(stcb); SCTP_INP_WLOCK(stcb->sctp_ep); SCTP_TCB_LOCK(stcb); - if (!sbappendaddr_nocheck(&stcb->sctp_socket->so_rcv, to, + if (!sctp_sbappendaddr_nocheck(&stcb->sctp_socket->so_rcv, to, m_notify, NULL, stcb->asoc.my_vtag, stcb->sctp_ep)) { /* not enough room */ sctp_m_freem(m_notify); @@ -2717,7 +2717,7 @@ sctp_notify_stream_reset(struct sctp_tcb *stcb, SCTP_TCB_UNLOCK(stcb); SCTP_INP_WLOCK(stcb->sctp_ep); SCTP_TCB_LOCK(stcb); - if (!sbappendaddr_nocheck(&stcb->sctp_socket->so_rcv, to, + if (!sctp_sbappendaddr_nocheck(&stcb->sctp_socket->so_rcv, to, m_notify, NULL, stcb->asoc.my_vtag, stcb->sctp_ep)) { /* not enough room */ sctp_m_freem(m_notify); @@ -3246,78 +3246,15 @@ sctp_print_address_pkt(struct ip *iph, struct sctphdr *sh) int -sbappendaddr_nocheck(struct sockbuf *sb, struct sockaddr *asa, struct mbuf *m0, +sctp_sbappendaddr_nocheck(struct signalsockbuf *ssb, struct sockaddr *asa, struct mbuf *m0, struct mbuf *control, u_int32_t tag, struct sctp_inpcb *inp) { -#ifdef __NetBSD__ - struct mbuf *m, *n; - - if (m0 && (m0->m_flags & M_PKTHDR) == 0) - panic("sbappendaddr_nocheck"); - - m0->m_pkthdr.csum_data = (int)tag; - - for (n = control; n; n = n->m_next) { - if (n->m_next == 0) /* keep pointer to last control buf */ - break; - } - if (((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) == 0) || - ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)== 0)) { - MGETHDR(m, MB_DONTWAIT, MT_SONAME); - if (m == 0) - return (0); - m->m_len = 0; - if (asa->sa_len > MHLEN) { - MEXTMALLOC(m, asa->sa_len, M_NOWAIT); - if ((m->m_flags & M_EXT) == 0) { - m_free(m); - return (0); - } - } - m->m_len = asa->sa_len; - memcpy(mtod(m, caddr_t), (caddr_t)asa, asa->sa_len); - } else { - m = NULL; - } - if (n) { - n->m_next = m0; /* concatenate data to control */ - }else { - control = m0; - } - if (m) - m->m_next = control; - else - m = control; - m->m_pkthdr.csum_data = tag; - - for (n = m; n; n = n->m_next) - sballoc(sb, n); - if ((n = sb->sb_mb) != NULL) { - if ((n->m_nextpkt != inp->sb_last_mpkt) && (n->m_nextpkt == NULL)) { - inp->sb_last_mpkt = NULL; - } - if (inp->sb_last_mpkt) - inp->sb_last_mpkt->m_nextpkt = m; - else { - while (n->m_nextpkt) { - n = n->m_nextpkt; - } - n->m_nextpkt = m; - } - inp->sb_last_mpkt = m; - } else { - inp->sb_last_mpkt = sb->sb_mb = m; - inp->sctp_vtag_first = tag; - } - return (1); -#endif -#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__) struct mbuf *m, *n, *nlast; int cnt=0; if (m0 && (m0->m_flags & M_PKTHDR) == 0) - panic("sbappendaddr_nocheck"); + panic("sctp_sbappendaddr_nocheck"); for (n = control; n; n = n->m_next) { if (n->m_next == 0) /* get pointer to last control buf */ @@ -3358,73 +3295,14 @@ sbappendaddr_nocheck(struct sockbuf *sb, struct sockaddr *asa, struct mbuf *m0, m = control; m->m_pkthdr.csum_data = (int)tag; - SOCKBUF_LOCK(sb); + SOCKBUF_LOCK(ssb); for (n = m; n; n = n->m_next) - sballoc(sb, n); + sballoc(&ssb->sb, n); nlast = n; - if (sb->sb_mb == NULL) { - inp->sctp_vtag_first = tag; - } - -#ifdef __FREEBSD__ - if (sb->sb_mb == NULL) + if (ssb->ssb_mb == NULL) { inp->sctp_vtag_first = tag; - SCTP_SBLINKRECORD(sb, m); - sb->sb_mbtail = nlast; -#else - if ((n = sb->sb_mb) != NULL) { - if ((n->m_nextpkt != inp->sb_last_mpkt) && (n->m_nextpkt == NULL)) { - inp->sb_last_mpkt = NULL; - } - if (inp->sb_last_mpkt) - inp->sb_last_mpkt->m_nextpkt = m; - else { - while (n->m_nextpkt) { - n = n->m_nextpkt; - } - n->m_nextpkt = m; - } - inp->sb_last_mpkt = m; - } else { - inp->sb_last_mpkt = sb->sb_mb = m; - inp->sctp_vtag_first = tag; - } -#endif - SOCKBUF_UNLOCK(sb); - return (1); -#endif -#ifdef __OpenBSD__ - struct mbuf *m, *n; - - if (m0 && (m0->m_flags & M_PKTHDR) == 0) - panic("sbappendaddr_nocheck"); - m0->m_pkthdr.csum = (int)tag; - for (n = control; n; n = n->m_next) { - if (n->m_next == 0) /* keep pointer to last control buf */ - break; } - if (((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) == 0) || - ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)== 0)) { - if (asa->sa_len > MHLEN) - return (0); - MGETHDR(m, MB_DONTWAIT, MT_SONAME); - if (m == 0) - return (0); - m->m_len = asa->sa_len; - bcopy((caddr_t)asa, mtod(m, caddr_t), asa->sa_len); - } else { - m = NULL; - } - if (n) - n->m_next = m0; /* concatenate data to control */ - else - control = m0; - - m->m_pkthdr.csum = (int)tag; - m->m_next = control; - for (n = m; n; n = n->m_next) - sballoc(sb, n); - if ((n = sb->sb_mb) != NULL) { + if ((n = ssb->ssb_mb) != NULL) { if ((n->m_nextpkt != inp->sb_last_mpkt) && (n->m_nextpkt == NULL)) { inp->sb_last_mpkt = NULL; } @@ -3438,11 +3316,11 @@ sbappendaddr_nocheck(struct sockbuf *sb, struct sockaddr *asa, struct mbuf *m0, } inp->sb_last_mpkt = m; } else { - inp->sb_last_mpkt = sb->sb_mb = m; + inp->sb_last_mpkt = ssb->ssb_mb = m; inp->sctp_vtag_first = tag; } + SOCKBUF_UNLOCK(ssb); return (1); -#endif } /*************HOLD THIS COMMENT FOR PATCH FILE OF @@ -3507,9 +3385,9 @@ sctp_get_first_vtag_from_sb(struct socket *so) u_int32_t retval; retval = 0; - if (so->so_rcv.sb_mb) { + if (so->so_rcv.ssb_mb) { /* grubbing time */ - this = so->so_rcv.sb_mb; + this = so->so_rcv.ssb_mb; while (this) { at = this; /* get to the m_pkthdr */ @@ -3551,14 +3429,14 @@ sctp_grub_through_socket_buffer(struct sctp_inpcb *inp, struct socket *old, struct socket *new, struct sctp_tcb *stcb) { struct mbuf **put, **take, *next, *this; - struct sockbuf *old_sb, *new_sb; + struct signalsockbuf *old_sb, *new_sb; struct sctp_association *asoc; int moved_top = 0; asoc = &stcb->asoc; old_sb = &old->so_rcv; new_sb = &new->so_rcv; - if (old_sb->sb_mb == NULL) { + if (old_sb->ssb_mb == NULL) { /* Nothing to move */ return; } @@ -3568,26 +3446,26 @@ sctp_grub_through_socket_buffer(struct sctp_inpcb *inp, struct socket *old, if (inp->sctp_vtag_first == asoc->my_vtag) { /* First one must be moved */ struct mbuf *mm; - for (mm = old_sb->sb_mb; mm; mm = mm->m_next) { + for (mm = old_sb->ssb_mb; mm; mm = mm->m_next) { /* * Go down the chain and fix * the space allocation of the * two sockets. */ - sbfree(old_sb, mm); - sballoc(new_sb, mm); + sbfree(&old_sb->sb, mm); + sballoc(&new_sb->sb, mm); } - new_sb->sb_mb = old_sb->sb_mb; - old_sb->sb_mb = new_sb->sb_mb->m_nextpkt; - new_sb->sb_mb->m_nextpkt = NULL; - put = &new_sb->sb_mb->m_nextpkt; + new_sb->ssb_mb = old_sb->ssb_mb; + old_sb->ssb_mb = new_sb->ssb_mb->m_nextpkt; + new_sb->ssb_mb->m_nextpkt = NULL; + put = &new_sb->ssb_mb->m_nextpkt; moved_top = 1; } else { - put = &new_sb->sb_mb; + put = &new_sb->ssb_mb; } - take = &old_sb->sb_mb; - next = old_sb->sb_mb; + take = &old_sb->ssb_mb; + next = old_sb->ssb_mb; while (next) { this = next; /* postion for next one */ @@ -3605,8 +3483,8 @@ sctp_grub_through_socket_buffer(struct sctp_inpcb *inp, struct socket *old, * the space allocation of the * two sockets. */ - sbfree(old_sb, mm); - sballoc(new_sb, mm); + sbfree(&old_sb->sb, mm); + sballoc(&new_sb->sb, mm); } put = &this->m_nextpkt; @@ -3655,16 +3533,16 @@ sctp_free_bufspace(struct sctp_tcb *stcb, struct sctp_association *asoc, } if ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { - if (stcb->sctp_socket->so_snd.sb_cc >= tp1->book_size) { - stcb->sctp_socket->so_snd.sb_cc -= tp1->book_size; + if (stcb->sctp_socket->so_snd.ssb_cc >= tp1->book_size) { + stcb->sctp_socket->so_snd.ssb_cc -= tp1->book_size; } else { - stcb->sctp_socket->so_snd.sb_cc = 0; + stcb->sctp_socket->so_snd.ssb_cc = 0; } - if (stcb->sctp_socket->so_snd.sb_mbcnt >= tp1->mbcnt) { - stcb->sctp_socket->so_snd.sb_mbcnt -= tp1->mbcnt; + if (stcb->sctp_socket->so_snd.ssb_mbcnt >= tp1->mbcnt) { + stcb->sctp_socket->so_snd.ssb_mbcnt -= tp1->mbcnt; } else { - stcb->sctp_socket->so_snd.sb_mbcnt = 0; + stcb->sctp_socket->so_snd.ssb_mbcnt = 0; } } } diff --git a/sys/netinet/sctputil.h b/sys/netinet/sctputil.h index ae7794dafa..db389fd79c 100644 --- a/sys/netinet/sctputil.h +++ b/sys/netinet/sctputil.h @@ -1,5 +1,5 @@ /* $KAME: sctputil.h,v 1.14 2004/08/17 04:06:21 itojun Exp $ */ -/* $DragonFly: src/sys/netinet/sctputil.h,v 1.5 2006/12/22 23:57:52 swildner Exp $ */ +/* $DragonFly: src/sys/netinet/sctputil.h,v 1.6 2007/04/22 01:13:14 dillon Exp $ */ #ifndef _NETINET_SCTPUTIL_H_ #define _NETINET_SCTPUTIL_H_ @@ -231,7 +231,7 @@ int sctp_cmpaddr(struct sockaddr *, struct sockaddr *); void sctp_print_address(struct sockaddr *); void sctp_print_address_pkt(struct ip *, struct sctphdr *); -int sbappendaddr_nocheck(struct sockbuf *, struct sockaddr *, +int sctp_sbappendaddr_nocheck(struct signalsockbuf *, struct sockaddr *, struct mbuf *, struct mbuf *, u_int32_t, struct sctp_inpcb *); diff --git a/sys/netinet/tcp_input.c b/sys/netinet/tcp_input.c index a5651370fe..d3f951cf63 100644 --- a/sys/netinet/tcp_input.c +++ b/sys/netinet/tcp_input.c @@ -65,7 +65,7 @@ * * @(#)tcp_input.c 8.12 (Berkeley) 5/24/95 * $FreeBSD: src/sys/netinet/tcp_input.c,v 1.107.2.38 2003/05/21 04:46:41 cjc Exp $ - * $DragonFly: src/sys/netinet/tcp_input.c,v 1.66 2007/04/17 17:28:04 dillon Exp $ + * $DragonFly: src/sys/netinet/tcp_input.c,v 1.67 2007/04/22 01:13:14 dillon Exp $ */ #include "opt_ipfw.h" /* for ipfw_fwd */ @@ -455,7 +455,7 @@ present: if (so->so_state & SS_CANTRCVMORE) m_freem(q->tqe_m); else - sbappendstream(&so->so_rcv, q->tqe_m); + ssb_appendstream(&so->so_rcv, q->tqe_m); kfree(q, M_TSEGQ); tcp_reass_qsize--; ND6_HINT(tp); @@ -1184,7 +1184,7 @@ after_listen: acked = th->th_ack - tp->snd_una; tcpstat.tcps_rcvackpack++; tcpstat.tcps_rcvackbyte += acked; - sbdrop(&so->so_snd, acked); + sbdrop(&so->so_snd.sb, acked); tp->snd_recover = th->th_ack - 1; tp->snd_una = th->th_ack; tp->t_dupacks = 0; @@ -1221,14 +1221,14 @@ after_listen: tp->t_rxtcur, tcp_timer_rexmt, tp); sowwakeup(so); - if (so->so_snd.sb_cc > 0) + if (so->so_snd.ssb_cc > 0) tcp_output(tp); return; } } else if (tiwin == tp->snd_wnd && th->th_ack == tp->snd_una && LIST_EMPTY(&tp->t_segq) && - tlen <= sbspace(&so->so_rcv)) { + tlen <= ssb_space(&so->so_rcv)) { /* * This is a pure, in-sequence data packet * with nothing on the reassembly queue and @@ -1246,7 +1246,7 @@ after_listen: m_freem(m); } else { m_adj(m, drop_hdrlen); /* delayed header drop */ - sbappendstream(&so->so_rcv, m); + ssb_appendstream(&so->so_rcv, m); } sorwakeup(so); /* @@ -1298,7 +1298,7 @@ after_listen: * Receive window is amount of space in rcv queue, * but not less than advertised window. */ - recvwin = sbspace(&so->so_rcv); + recvwin = ssb_space(&so->so_rcv); if (recvwin < 0) recvwin = 0; tp->rcv_wnd = imax(recvwin, (int)(tp->rcv_adv - tp->rcv_nxt)); @@ -2140,12 +2140,12 @@ process_ACK: /* Stop looking for an acceptable ACK since one was received. */ tp->t_flags &= ~(TF_FIRSTACCACK | TF_FASTREXMT | TF_EARLYREXMT); - if (acked > so->so_snd.sb_cc) { - tp->snd_wnd -= so->so_snd.sb_cc; - sbdrop(&so->so_snd, (int)so->so_snd.sb_cc); + if (acked > so->so_snd.ssb_cc) { + tp->snd_wnd -= so->so_snd.ssb_cc; + sbdrop(&so->so_snd.sb, (int)so->so_snd.ssb_cc); ourfinisacked = TRUE; } else { - sbdrop(&so->so_snd, acked); + sbdrop(&so->so_snd.sb, acked); tp->snd_wnd -= acked; ourfinisacked = FALSE; } @@ -2355,7 +2355,7 @@ step6: * soreceive. It's hard to imagine someone * actually wanting to send this much urgent data. */ - if (th->th_urp + so->so_rcv.sb_cc > sb_max) { + if (th->th_urp + so->so_rcv.ssb_cc > sb_max) { th->th_urp = 0; /* XXX */ thflags &= ~TH_URG; /* XXX */ goto dodata; /* XXX */ @@ -2376,7 +2376,7 @@ step6: */ if (SEQ_GT(th->th_seq + th->th_urp, tp->rcv_up)) { tp->rcv_up = th->th_seq + th->th_urp; - so->so_oobmark = so->so_rcv.sb_cc + + so->so_oobmark = so->so_rcv.ssb_cc + (tp->rcv_up - tp->rcv_nxt) - 1; if (so->so_oobmark == 0) so->so_state |= SS_RCVATMARK; @@ -2443,7 +2443,7 @@ dodata: /* XXX */ if (so->so_state & SS_CANTRCVMORE) m_freem(m); else - sbappendstream(&so->so_rcv, m); + ssb_appendstream(&so->so_rcv, m); sorwakeup(so); } else { if (!(tp->t_flags & TF_DUPSEG)) { @@ -2461,7 +2461,7 @@ dodata: /* XXX */ * our window, in order to estimate the sender's * buffer size. */ - len = so->so_rcv.sb_hiwat - (tp->rcv_adv - tp->rcv_nxt); + len = so->so_rcv.ssb_hiwat - (tp->rcv_adv - tp->rcv_nxt); } else { m_freem(m); thflags &= ~TH_FIN; @@ -3030,28 +3030,28 @@ tcp_mss(struct tcpcb *tp, int offer) #ifdef RTV_SPIPE if ((bufsize = rt->rt_rmx.rmx_sendpipe) == 0) #endif - bufsize = so->so_snd.sb_hiwat; + bufsize = so->so_snd.ssb_hiwat; if (bufsize < mss) mss = bufsize; else { bufsize = roundup(bufsize, mss); if (bufsize > sb_max) bufsize = sb_max; - if (bufsize > so->so_snd.sb_hiwat) - sbreserve(&so->so_snd, bufsize, so, NULL); + if (bufsize > so->so_snd.ssb_hiwat) + ssb_reserve(&so->so_snd, bufsize, so, NULL); } tp->t_maxseg = mss; #ifdef RTV_RPIPE if ((bufsize = rt->rt_rmx.rmx_recvpipe) == 0) #endif - bufsize = so->so_rcv.sb_hiwat; + bufsize = so->so_rcv.ssb_hiwat; if (bufsize > mss) { bufsize = roundup(bufsize, mss); if (bufsize > sb_max) bufsize = sb_max; - if (bufsize > so->so_rcv.sb_hiwat) - sbreserve(&so->so_rcv, bufsize, so, NULL); + if (bufsize > so->so_rcv.ssb_hiwat) + ssb_reserve(&so->so_rcv, bufsize, so, NULL); } /* diff --git a/sys/netinet/tcp_output.c b/sys/netinet/tcp_output.c index cf67e86518..8bd87abb0e 100644 --- a/sys/netinet/tcp_output.c +++ b/sys/netinet/tcp_output.c @@ -65,7 +65,7 @@ * * @(#)tcp_output.c 8.4 (Berkeley) 5/24/95 * $FreeBSD: src/sys/netinet/tcp_output.c,v 1.39.2.20 2003/01/29 22:45:36 hsu Exp $ - * $DragonFly: src/sys/netinet/tcp_output.c,v 1.33 2007/03/04 18:51:59 swildner Exp $ + * $DragonFly: src/sys/netinet/tcp_output.c,v 1.34 2007/04/22 01:13:14 dillon Exp $ */ #include "opt_inet6.h" @@ -243,7 +243,7 @@ again: * to send then the probe will be the FIN * itself. */ - if (off < so->so_snd.sb_cc) + if (off < so->so_snd.ssb_cc) flags &= ~TH_FIN; sendwin = 1; } else { @@ -254,7 +254,7 @@ again: /* * If snd_nxt == snd_max and we have transmitted a FIN, the - * offset will be > 0 even if so_snd.sb_cc is 0, resulting in + * offset will be > 0 even if so_snd.ssb_cc is 0, resulting in * a negative length. This can also occur when TCP opens up * its congestion window while receiving additional duplicate * acks after fast-retransmit because TCP will reset snd_nxt @@ -264,7 +264,7 @@ again: * be set to snd_una, the offset will be 0, and the length may * wind up 0. */ - len = (long)ulmin(so->so_snd.sb_cc, sendwin) - off; + len = (long)ulmin(so->so_snd.ssb_cc, sendwin) - off; /* * Lop off SYN bit if it has already been sent. However, if this @@ -323,10 +323,10 @@ again: len = tp->t_maxseg; sendalot = TRUE; } - if (SEQ_LT(tp->snd_nxt + len, tp->snd_una + so->so_snd.sb_cc)) + if (SEQ_LT(tp->snd_nxt + len, tp->snd_una + so->so_snd.ssb_cc)) flags &= ~TH_FIN; - recvwin = sbspace(&so->so_rcv); + recvwin = ssb_space(&so->so_rcv); /* * Sender silly window avoidance. We transmit under the following @@ -352,7 +352,7 @@ again: */ if (!(tp->t_flags & TF_MORETOCOME) && /* normal case */ (idle || (tp->t_flags & TF_NODELAY)) && - len + off >= so->so_snd.sb_cc && + len + off >= so->so_snd.ssb_cc && !(tp->t_flags & TF_NOPUSH)) { goto send; } @@ -399,7 +399,7 @@ again: if (adv >= (long) (2 * tp->t_maxseg)) goto send; } - if (2 * adv >= (long) so->so_rcv.sb_hiwat) + if (2 * adv >= (long) so->so_rcv.ssb_hiwat) goto send; } @@ -444,7 +444,7 @@ again: * if window is nonzero, transmit what we can, * otherwise force out a byte. */ - if (so->so_snd.sb_cc > 0 && + if (so->so_snd.ssb_cc > 0 && !callout_active(tp->tt_rexmt) && !callout_active(tp->tt_persist)) { tp->t_rxtshift = 0; tcp_setpersist(tp); @@ -663,7 +663,7 @@ send: tcpstat.tcps_sndbyte += len; } #ifdef notyet - if ((m = m_copypack(so->so_snd.sb_mb, off, (int)len, + if ((m = m_copypack(so->so_snd.ssb_mb, off, (int)len, max_linkhdr + hdrlen)) == NULL) { error = ENOBUFS; goto out; @@ -687,11 +687,11 @@ send: m->m_data += max_linkhdr; m->m_len = hdrlen; if (len <= MHLEN - hdrlen - max_linkhdr) { - m_copydata(so->so_snd.sb_mb, off, (int) len, + m_copydata(so->so_snd.ssb_mb, off, (int) len, mtod(m, caddr_t) + hdrlen); m->m_len += len; } else { - m->m_next = m_copy(so->so_snd.sb_mb, off, (int) len); + m->m_next = m_copy(so->so_snd.ssb_mb, off, (int) len); if (m->m_next == NULL) { m_free(m); error = ENOBUFS; @@ -705,7 +705,7 @@ send: * give data to the user when a buffer fills or * a PUSH comes in.) */ - if (off + len == so->so_snd.sb_cc) + if (off + len == so->so_snd.ssb_cc) flags |= TH_PUSH; } else { if (tp->t_flags & TF_ACKNOW) @@ -777,7 +777,7 @@ send: * Calculate receive window. Don't shrink window, * but avoid silly window syndrome. */ - if (recvwin < (long)(so->so_rcv.sb_hiwat / 4) && + if (recvwin < (long)(so->so_rcv.ssb_hiwat / 4) && recvwin < (long)tp->t_maxseg) recvwin = 0; if (recvwin < (long)(tp->rcv_adv - tp->rcv_nxt)) diff --git a/sys/netinet/tcp_sack.c b/sys/netinet/tcp_sack.c index c9ea0ec0cb..4492ad36bf 100644 --- a/sys/netinet/tcp_sack.c +++ b/sys/netinet/tcp_sack.c @@ -30,7 +30,7 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sys/netinet/tcp_sack.c,v 1.5 2007/03/04 18:51:59 swildner Exp $ + * $DragonFly: src/sys/netinet/tcp_sack.c,v 1.6 2007/04/22 01:13:14 dillon Exp $ */ #include @@ -503,7 +503,7 @@ sendunsacked: /* See if unsent data available within send window. */ off = tp->snd_max - tp->snd_una; - len = (long) ulmin(so->so_snd.sb_cc, tp->snd_wnd) - off; + len = (long) ulmin(so->so_snd.ssb_cc, tp->snd_wnd) - off; if (len > 0) { *nextrexmt = tp->snd_max; /* Send new data. */ *plen = tp->t_maxseg; diff --git a/sys/netinet/tcp_subr.c b/sys/netinet/tcp_subr.c index 222258ab91..f409e7fb6a 100644 --- a/sys/netinet/tcp_subr.c +++ b/sys/netinet/tcp_subr.c @@ -65,7 +65,7 @@ * * @(#)tcp_subr.c 8.2 (Berkeley) 5/24/95 * $FreeBSD: src/sys/netinet/tcp_subr.c,v 1.73.2.31 2003/01/24 05:11:34 sam Exp $ - * $DragonFly: src/sys/netinet/tcp_subr.c,v 1.56 2007/03/04 18:51:59 swildner Exp $ + * $DragonFly: src/sys/netinet/tcp_subr.c,v 1.57 2007/04/22 01:13:14 dillon Exp $ */ #include "opt_compat.h" @@ -517,7 +517,7 @@ tcp_respond(struct tcpcb *tp, void *ipgen, struct tcphdr *th, struct mbuf *m, if (tp != NULL) { if (!(flags & TH_RST)) { - win = sbspace(&tp->t_inpcb->inp_socket->so_rcv); + win = ssb_space(&tp->t_inpcb->inp_socket->so_rcv); if (win > (long)TCP_MAXWIN << tp->rcv_scale) win = (long)TCP_MAXWIN << tp->rcv_scale; } @@ -888,7 +888,7 @@ tcp_close(struct tcpcb *tp) if (rt->rt_rmx.rmx_sendpipe != 0) dosavessthresh = (i < rt->rt_rmx.rmx_sendpipe/2); else - dosavessthresh = (i < so->so_snd.sb_hiwat/2); + dosavessthresh = (i < so->so_snd.ssb_hiwat/2); if (dosavessthresh || (!(rt->rt_rmx.rmx_locks & RTV_SSTHRESH) && (i != 0) && (rt->rt_rmx.rmx_ssthresh != 0))) { @@ -1633,8 +1633,8 @@ tcp_mtudisc(struct inpcb *inp, int mtu) mss = (mss / MCLBYTES) * MCLBYTES; #endif - if (so->so_snd.sb_hiwat < mss) - mss = so->so_snd.sb_hiwat; + if (so->so_snd.ssb_hiwat < mss) + mss = so->so_snd.ssb_hiwat; tp->t_maxseg = mss; tp->t_rtttime = 0; diff --git a/sys/netinet/tcp_syncache.c b/sys/netinet/tcp_syncache.c index bf9d2e687b..fa199ef527 100644 --- a/sys/netinet/tcp_syncache.c +++ b/sys/netinet/tcp_syncache.c @@ -69,7 +69,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/netinet/tcp_syncache.c,v 1.5.2.14 2003/02/24 04:02:27 silby Exp $ - * $DragonFly: src/sys/netinet/tcp_syncache.c,v 1.28 2007/03/04 18:51:59 swildner Exp $ + * $DragonFly: src/sys/netinet/tcp_syncache.c,v 1.29 2007/04/22 01:13:14 dillon Exp $ */ #include "opt_inet6.h" @@ -985,8 +985,8 @@ syncache_add(struct in_conninfo *inc, struct tcpopt *to, struct tcphdr *th, else sc->sc_iss = karc4random(); - /* Initial receive window: clip sbspace to [0 .. TCP_MAXWIN] */ - win = sbspace(&so->so_rcv); + /* Initial receive window: clip ssb_space to [0 .. TCP_MAXWIN] */ + win = ssb_space(&so->so_rcv); win = imax(win, 0); win = imin(win, TCP_MAXWIN); sc->sc_wnd = win; @@ -1005,7 +1005,7 @@ syncache_add(struct in_conninfo *inc, struct tcpopt *to, struct tcphdr *th, /* Compute proper scaling value from buffer space */ while (wscale < TCP_MAX_WINSHIFT && - (TCP_MAXWIN << wscale) < so->so_rcv.sb_hiwat) + (TCP_MAXWIN << wscale) < so->so_rcv.ssb_hiwat) wscale++; sc->sc_request_r_scale = wscale; sc->sc_requested_s_scale = to->to_requested_s_scale; @@ -1439,7 +1439,7 @@ syncookie_lookup(struct in_conninfo *inc, struct tcphdr *th, struct socket *so) } sc->sc_irs = th->th_seq - 1; sc->sc_iss = th->th_ack - 1; - wnd = sbspace(&so->so_rcv); + wnd = ssb_space(&so->so_rcv); wnd = imax(wnd, 0); wnd = imin(wnd, TCP_MAXWIN); sc->sc_wnd = wnd; diff --git a/sys/netinet/tcp_usrreq.c b/sys/netinet/tcp_usrreq.c index 7f60e74c83..611d7237ed 100644 --- a/sys/netinet/tcp_usrreq.c +++ b/sys/netinet/tcp_usrreq.c @@ -65,7 +65,7 @@ * * From: @(#)tcp_usrreq.c 8.2 (Berkeley) 1/3/94 * $FreeBSD: src/sys/netinet/tcp_usrreq.c,v 1.51.2.17 2002/10/11 11:46:44 ume Exp $ - * $DragonFly: src/sys/netinet/tcp_usrreq.c,v 1.41 2007/04/21 02:26:48 dillon Exp $ + * $DragonFly: src/sys/netinet/tcp_usrreq.c,v 1.42 2007/04/22 01:13:14 dillon Exp $ */ #include "opt_ipsec.h" @@ -684,7 +684,7 @@ tcp_usr_send(struct socket *so, int flags, struct mbuf *m, m_freem(control); /* empty control, just free it */ } if(!(flags & PRUS_OOB)) { - sbappendstream(&so->so_snd, m); + ssb_appendstream(&so->so_snd, m); if (nam && tp->t_state < TCPS_SYN_SENT) { /* * Do implied connect if not yet connected, @@ -720,7 +720,7 @@ tcp_usr_send(struct socket *so, int flags, struct mbuf *m, tp->t_flags &= ~TF_MORETOCOME; } } else { - if (sbspace(&so->so_snd) < -512) { + if (ssb_space(&so->so_snd) < -512) { m_freem(m); error = ENOBUFS; goto out; @@ -733,7 +733,7 @@ tcp_usr_send(struct socket *so, int flags, struct mbuf *m, * of data past the urgent section. * Otherwise, snd_up should be one lower. */ - sbappendstream(&so->so_snd, m); + ssb_appendstream(&so->so_snd, m); if (nam && tp->t_state < TCPS_SYN_SENT) { /* * Do implied connect if not yet connected, @@ -752,7 +752,7 @@ tcp_usr_send(struct socket *so, int flags, struct mbuf *m, tp->snd_wnd = TTCP_CLIENT_SND_WND; tcp_mss(tp, -1); } - tp->snd_up = tp->snd_una + so->so_snd.sb_cc; + tp->snd_up = tp->snd_una + so->so_snd.ssb_cc; tp->t_flags |= TF_FORCE; error = tcp_output(tp); tp->t_flags &= ~TF_FORCE; @@ -887,7 +887,7 @@ tcp_connect_oncpu(struct tcpcb *tp, struct sockaddr_in *sin, /* Compute window scaling to request. */ while (tp->request_r_scale < TCP_MAX_WINSHIFT && - (TCP_MAXWIN << tp->request_r_scale) < so->so_rcv.sb_hiwat) + (TCP_MAXWIN << tp->request_r_scale) < so->so_rcv.ssb_hiwat) tp->request_r_scale++; soisconnecting(so); @@ -1049,7 +1049,7 @@ tcp6_connect(struct tcpcb *tp, struct sockaddr *nam, struct thread *td) /* Compute window scaling to request. */ while (tp->request_r_scale < TCP_MAX_WINSHIFT && - (TCP_MAXWIN << tp->request_r_scale) < so->so_rcv.sb_hiwat) + (TCP_MAXWIN << tp->request_r_scale) < so->so_rcv.ssb_hiwat) tp->request_r_scale++; soisconnecting(so); @@ -1228,7 +1228,7 @@ tcp_attach(struct socket *so, struct pru_attach_info *ai) int isipv6 = INP_CHECK_SOCKAF(so, AF_INET6) != NULL; #endif - if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) { + if (so->so_snd.ssb_hiwat == 0 || so->so_rcv.ssb_hiwat == 0) { error = soreserve(so, tcp_sendspace, tcp_recvspace, ai->sb_rlimit); if (error) @@ -1284,7 +1284,7 @@ tcp_disconnect(struct tcpcb *tp) tp = tcp_drop(tp, 0); else { soisdisconnecting(so); - sbflush(&so->so_rcv); + sbflush(&so->so_rcv.sb); tp = tcp_usrclosed(tp); if (tp) tcp_output(tp); diff --git a/sys/netinet/udp_usrreq.c b/sys/netinet/udp_usrreq.c index 3cd357a865..c62adfa1b2 100644 --- a/sys/netinet/udp_usrreq.c +++ b/sys/netinet/udp_usrreq.c @@ -65,7 +65,7 @@ * * @(#)udp_usrreq.c 8.6 (Berkeley) 5/23/95 * $FreeBSD: src/sys/netinet/udp_usrreq.c,v 1.64.2.18 2003/01/24 05:11:34 sam Exp $ - * $DragonFly: src/sys/netinet/udp_usrreq.c,v 1.41 2007/04/21 02:26:48 dillon Exp $ + * $DragonFly: src/sys/netinet/udp_usrreq.c,v 1.42 2007/04/22 01:13:14 dillon Exp $ */ #include "opt_ipsec.h" @@ -509,7 +509,7 @@ udp_input(struct mbuf *m, ...) } else #endif append_sa = (struct sockaddr *)&udp_in; - if (sbappendaddr(&inp->inp_socket->so_rcv, append_sa, m, opts) == 0) { + if (ssb_appendaddr(&inp->inp_socket->so_rcv, append_sa, m, opts) == 0) { udpstat.udps_fullsock++; goto bad; } @@ -578,7 +578,7 @@ udp_append(struct inpcb *last, struct ip *ip, struct mbuf *n, int off) #endif append_sa = (struct sockaddr *)&udp_in; m_adj(n, off); - if (sbappendaddr(&last->inp_socket->so_rcv, append_sa, n, opts) == 0) { + if (ssb_appendaddr(&last->inp_socket->so_rcv, append_sa, n, opts) == 0) { m_freem(n); if (opts) m_freem(opts); diff --git a/sys/netinet6/icmp6.c b/sys/netinet6/icmp6.c index 1d90fdcbcf..1aaaf8d4ce 100644 --- a/sys/netinet6/icmp6.c +++ b/sys/netinet6/icmp6.c @@ -1,5 +1,5 @@ /* $FreeBSD: src/sys/netinet6/icmp6.c,v 1.6.2.13 2003/05/06 06:46:58 suz Exp $ */ -/* $DragonFly: src/sys/netinet6/icmp6.c,v 1.25 2006/12/29 18:02:56 victor Exp $ */ +/* $DragonFly: src/sys/netinet6/icmp6.c,v 1.26 2007/04/22 01:13:14 dillon Exp $ */ /* $KAME: icmp6.c,v 1.211 2001/04/04 05:56:20 itojun Exp $ */ /* @@ -1889,7 +1889,7 @@ icmp6_rip6_input(struct mbuf **mp, int off) ip6_savecontrol(last, &opts, ip6, n); /* strip intermediate headers */ m_adj(n, off); - if (sbappendaddr(&last->in6p_socket->so_rcv, + if (ssb_appendaddr(&last->in6p_socket->so_rcv, (struct sockaddr *)&rip6src, n, opts) == 0) { /* should notify about lost packet */ @@ -1909,7 +1909,7 @@ icmp6_rip6_input(struct mbuf **mp, int off) ip6_savecontrol(last, &opts, ip6, m); /* strip intermediate headers */ m_adj(m, off); - if (sbappendaddr(&last->in6p_socket->so_rcv, + if (ssb_appendaddr(&last->in6p_socket->so_rcv, (struct sockaddr *)&rip6src, m, opts) == 0) { m_freem(m); if (opts) diff --git a/sys/netinet6/ip6_mroute.c b/sys/netinet6/ip6_mroute.c index 64d3d30111..d6f0261531 100644 --- a/sys/netinet6/ip6_mroute.c +++ b/sys/netinet6/ip6_mroute.c @@ -1,5 +1,5 @@ /* $FreeBSD: src/sys/netinet6/ip6_mroute.c,v 1.2.2.9 2003/01/23 21:06:47 sam Exp $ */ -/* $DragonFly: src/sys/netinet6/ip6_mroute.c,v 1.14 2006/10/24 06:18:42 hsu Exp $ */ +/* $DragonFly: src/sys/netinet6/ip6_mroute.c,v 1.15 2007/04/22 01:13:14 dillon Exp $ */ /* $KAME: ip6_mroute.c,v 1.58 2001/12/18 02:36:31 itojun Exp $ */ /* @@ -862,7 +862,7 @@ static int socket_send(struct socket *s, struct mbuf *mm, struct sockaddr_in6 *src) { if (s) { - if (sbappendaddr(&s->so_rcv, + if (ssb_appendaddr(&s->so_rcv, (struct sockaddr *)src, mm, (struct mbuf *)0) != 0) { sorwakeup(s); diff --git a/sys/netinet6/raw_ip6.c b/sys/netinet6/raw_ip6.c index a965b25f25..96d1f26e21 100644 --- a/sys/netinet6/raw_ip6.c +++ b/sys/netinet6/raw_ip6.c @@ -27,7 +27,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/netinet6/raw_ip6.c,v 1.7.2.7 2003/01/24 05:11:35 sam Exp $ - * $DragonFly: src/sys/netinet6/raw_ip6.c,v 1.24 2007/04/21 02:26:48 dillon Exp $ + * $DragonFly: src/sys/netinet6/raw_ip6.c,v 1.25 2007/04/22 01:13:14 dillon Exp $ */ /* @@ -199,7 +199,7 @@ rip6_input(struct mbuf **mp, int *offp, int proto) ip6_savecontrol(last, &opts, ip6, n); /* strip intermediate headers */ m_adj(n, *offp); - if (sbappendaddr(&last->in6p_socket->so_rcv, + if (ssb_appendaddr(&last->in6p_socket->so_rcv, (struct sockaddr *)&rip6src, n, opts) == 0) { m_freem(n); @@ -240,7 +240,7 @@ rip6_input(struct mbuf **mp, int *offp, int proto) ip6_savecontrol(last, &opts, ip6, m); /* strip intermediate headers */ m_adj(m, *offp); - if (sbappendaddr(&last->in6p_socket->so_rcv, + if (ssb_appendaddr(&last->in6p_socket->so_rcv, (struct sockaddr *)&rip6src, m, opts) == 0) { m_freem(m); if (opts) diff --git a/sys/netinet6/sctp6_usrreq.c b/sys/netinet6/sctp6_usrreq.c index f5dae598e5..707e548f52 100644 --- a/sys/netinet6/sctp6_usrreq.c +++ b/sys/netinet6/sctp6_usrreq.c @@ -1,5 +1,5 @@ /* $KAME: sctp6_usrreq.c,v 1.35 2004/08/17 06:28:03 t-momose Exp $ */ -/* $DragonFly: src/sys/netinet6/sctp6_usrreq.c,v 1.9 2007/04/21 02:26:48 dillon Exp $ */ +/* $DragonFly: src/sys/netinet6/sctp6_usrreq.c,v 1.10 2007/04/22 01:13:14 dillon Exp $ */ /* * Copyright (c) 2001, 2002, 2003, 2004 Cisco Systems, Inc. @@ -757,7 +757,7 @@ sctp6_attach(struct socket *so, int proto, struct proc *p) if (inp != NULL) return EINVAL; - if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) { + if (so->so_snd.ssb_hiwat == 0 || so->so_rcv.ssb_hiwat == 0) { error = soreserve(so, sctp_sendspace, sctp_recvspace, NULL); if (error) return error; @@ -935,7 +935,7 @@ sctp6_detach(struct socket *so) return EINVAL; crit_enter(); if (((so->so_options & SO_LINGER) && (so->so_linger == 0)) || - (so->so_rcv.sb_cc > 0)) + (so->so_rcv.ssb_cc > 0)) sctp_inpcb_free(inp, 1); else sctp_inpcb_free(inp, 0); diff --git a/sys/netinet6/udp6_usrreq.c b/sys/netinet6/udp6_usrreq.c index 382fa2f6a2..ffb4908a0c 100644 --- a/sys/netinet6/udp6_usrreq.c +++ b/sys/netinet6/udp6_usrreq.c @@ -1,5 +1,5 @@ /* $FreeBSD: src/sys/netinet6/udp6_usrreq.c,v 1.6.2.13 2003/01/24 05:11:35 sam Exp $ */ -/* $DragonFly: src/sys/netinet6/udp6_usrreq.c,v 1.25 2007/04/21 02:26:48 dillon Exp $ */ +/* $DragonFly: src/sys/netinet6/udp6_usrreq.c,v 1.26 2007/04/22 01:13:14 dillon Exp $ */ /* $KAME: udp6_usrreq.c,v 1.27 2001/05/21 05:45:10 jinmei Exp $ */ /* @@ -274,7 +274,7 @@ udp6_input(struct mbuf **mp, int *offp, int proto) /* * KAME NOTE: do not * m_copy(m, offset, ...) above. - * sbappendaddr() expects M_PKTHDR, + * ssb_appendaddr() expects M_PKTHDR, * and m_copy() will copy M_PKTHDR * only if offset is 0. */ @@ -284,7 +284,7 @@ udp6_input(struct mbuf **mp, int *offp, int proto) ip6, n); m_adj(n, off + sizeof(struct udphdr)); - if (sbappendaddr(&last->in6p_socket->so_rcv, + if (ssb_appendaddr(&last->in6p_socket->so_rcv, (struct sockaddr *)&udp_in6, n, opts) == 0) { m_freem(n); @@ -342,7 +342,7 @@ udp6_input(struct mbuf **mp, int *offp, int proto) ip6_savecontrol(last, &opts, ip6, m); m_adj(m, off + sizeof(struct udphdr)); - if (sbappendaddr(&last->in6p_socket->so_rcv, + if (ssb_appendaddr(&last->in6p_socket->so_rcv, (struct sockaddr *)&udp_in6, m, opts) == 0) { udpstat.udps_fullsock++; @@ -404,7 +404,7 @@ udp6_input(struct mbuf **mp, int *offp, int proto) || in6p->in6p_socket->so_options & SO_TIMESTAMP) ip6_savecontrol(in6p, &opts, ip6, m); m_adj(m, off + sizeof(struct udphdr)); - if (sbappendaddr(&in6p->in6p_socket->so_rcv, + if (ssb_appendaddr(&in6p->in6p_socket->so_rcv, (struct sockaddr *)&udp_in6, m, opts) == 0) { udpstat.udps_fullsock++; @@ -547,7 +547,7 @@ udp6_attach(struct socket *so, int proto, struct pru_attach_info *ai) if (inp != NULL) return EINVAL; - if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) { + if (so->so_snd.ssb_hiwat == 0 || so->so_rcv.ssb_hiwat == 0) { error = soreserve(so, udp_sendspace, udp_recvspace, ai->sb_rlimit); if (error) diff --git a/sys/netproto/atalk/ddp_input.c b/sys/netproto/atalk/ddp_input.c index 506f038dc9..a7bbd8c6fb 100644 --- a/sys/netproto/atalk/ddp_input.c +++ b/sys/netproto/atalk/ddp_input.c @@ -3,7 +3,7 @@ * All Rights Reserved. See COPYRIGHT. * * $FreeBSD: src/sys/netatalk/ddp_input.c,v 1.12 2000/02/13 03:31:58 peter Exp $ - * $DragonFly: src/sys/netproto/atalk/ddp_input.c,v 1.12 2006/12/22 23:57:53 swildner Exp $ + * $DragonFly: src/sys/netproto/atalk/ddp_input.c,v 1.13 2007/04/22 01:13:15 dillon Exp $ */ #include @@ -370,7 +370,7 @@ ddp_input(struct mbuf *m, struct ifnet *ifp, struct elaphdr *elh, int phase) /* * If we found one, deliver th epacket to the socket */ - if ( sbappendaddr( &ddp->ddp_socket->so_rcv, (struct sockaddr *)&from, + if (ssb_appendaddr( &ddp->ddp_socket->so_rcv, (struct sockaddr *)&from, m, (struct mbuf *)0 ) == 0 ) { /* * If the socket is full (or similar error) dump the packet. diff --git a/sys/netproto/atm/atm_aal5.c b/sys/netproto/atm/atm_aal5.c index 35799f4898..b1a761f50d 100644 --- a/sys/netproto/atm/atm_aal5.c +++ b/sys/netproto/atm/atm_aal5.c @@ -24,7 +24,7 @@ * notice must be reproduced on all copies. * * @(#) $FreeBSD: src/sys/netatm/atm_aal5.c,v 1.6 1999/10/09 23:24:59 green Exp $ - * @(#) $DragonFly: src/sys/netproto/atm/atm_aal5.c,v 1.12 2007/04/21 02:26:48 dillon Exp $ + * @(#) $DragonFly: src/sys/netproto/atm/atm_aal5.c,v 1.13 2007/04/22 01:13:15 dillon Exp $ */ /* @@ -352,7 +352,7 @@ atm_aal5_connect(struct socket *so, struct sockaddr *addr, thread_t td) size = atp->atp_attr.aal.v.aal5.forward_max_SDU_size; if (size != T_ATM_ABSENT) - if (!sbreserve(&so->so_snd, size, so, + if (!ssb_reserve(&so->so_snd, size, so, &td->td_proc->p_rlimit[RLIMIT_SBSIZE])) { err = ENOBUFS; ATM_OUTRO(); @@ -586,7 +586,7 @@ atm_aal5_sense(struct socket *so, struct stat *st) /* * Just return the max sdu size for the connection */ - st->st_blksize = so->so_snd.sb_hiwat; + st->st_blksize = so->so_snd.ssb_hiwat; ATM_OUTRO(); } @@ -725,7 +725,7 @@ atm_aal5_cpcs_data(void *tok, KBuffer *m) */ if (((so->so_state & SS_ISCONNECTED) == 0) || (so->so_state & SS_CANTRCVMORE) || - (len > sbspace(&so->so_rcv))) { + (len > ssb_space(&so->so_rcv))) { atm_sock_stat.as_indrop[atp->atp_type]++; KB_FREEALL(m); return; @@ -734,7 +734,7 @@ atm_aal5_cpcs_data(void *tok, KBuffer *m) /* * Queue the data and notify the user */ - sbappendrecord(&so->so_rcv, m); + ssb_appendrecord(&so->so_rcv, m); sorwakeup(so); return; diff --git a/sys/netproto/atm/atm_socket.c b/sys/netproto/atm/atm_socket.c index 5c140bf2b7..eb7b4dbff9 100644 --- a/sys/netproto/atm/atm_socket.c +++ b/sys/netproto/atm/atm_socket.c @@ -24,7 +24,7 @@ * notice must be reproduced on all copies. * * @(#) $FreeBSD: src/sys/netatm/atm_socket.c,v 1.4 1999/08/28 00:48:37 peter Exp $ - * @(#) $DragonFly: src/sys/netproto/atm/atm_socket.c,v 1.9 2006/12/20 18:14:43 dillon Exp $ + * @(#) $DragonFly: src/sys/netproto/atm/atm_socket.c,v 1.10 2007/04/22 01:13:15 dillon Exp $ */ /* @@ -96,7 +96,7 @@ atm_sock_attach(struct socket *so, u_long send, u_long recv, struct rlimit *rl) /* * Reserve socket buffer space, if not already done */ - if ((so->so_snd.sb_hiwat == 0) || (so->so_rcv.sb_hiwat == 0)) { + if ((so->so_snd.ssb_hiwat == 0) || (so->so_rcv.ssb_hiwat == 0)) { err = soreserve(so, send, recv, rl); if (err) return (err); diff --git a/sys/netproto/ipsec/keysock.c b/sys/netproto/ipsec/keysock.c index f992f95c7d..5fb793767d 100644 --- a/sys/netproto/ipsec/keysock.c +++ b/sys/netproto/ipsec/keysock.c @@ -1,5 +1,5 @@ /* $FreeBSD: src/sys/netipsec/keysock.c,v 1.3.2.1 2003/01/24 05:11:36 sam Exp $ */ -/* $DragonFly: src/sys/netproto/ipsec/keysock.c,v 1.16 2007/04/21 02:26:48 dillon Exp $ */ +/* $DragonFly: src/sys/netproto/ipsec/keysock.c,v 1.17 2007/04/22 01:13:15 dillon Exp $ */ /* $KAME: keysock.c,v 1.25 2001/08/13 20:07:41 itojun Exp $ */ /* @@ -161,7 +161,7 @@ key_sendup0(struct rawcb *rp, struct mbuf *m, int promisc) pfkeystat.in_msgtype[pmsg->sadb_msg_type]++; } - if (!sbappendaddr(&rp->rcb_socket->so_rcv, (struct sockaddr *)&key_src, + if (!ssb_appendaddr(&rp->rcb_socket->so_rcv, (struct sockaddr *)&key_src, m, NULL)) { pfkeystat.in_nomem++; m_freem(m); @@ -204,8 +204,8 @@ key_sendup(struct socket *so, struct sadb_msg *msg, u_int len, int target) * Get mbuf chain whenever possible (not clusters), * to save socket buffer. We'll be generating many SADB_ACQUIRE * messages to listening key sockets. If we simply allocate clusters, - * sbappendaddr() will raise ENOBUFS due to too little sbspace(). - * sbspace() computes # of actual data bytes AND mbuf region. + * ssb_appendaddr() will raise ENOBUFS due to too little ssb_space(). + * ssb_space() computes # of actual data bytes AND mbuf region. * * TODO: SADB_ACQUIRE filters should be implemented. */ diff --git a/sys/netproto/ipx/ipx_usrreq.c b/sys/netproto/ipx/ipx_usrreq.c index c75ac08114..f3ad748a00 100644 --- a/sys/netproto/ipx/ipx_usrreq.c +++ b/sys/netproto/ipx/ipx_usrreq.c @@ -34,7 +34,7 @@ * @(#)ipx_usrreq.c * * $FreeBSD: src/sys/netipx/ipx_usrreq.c,v 1.26.2.1 2001/02/22 09:44:18 bp Exp $ - * $DragonFly: src/sys/netproto/ipx/ipx_usrreq.c,v 1.11 2007/04/21 02:26:48 dillon Exp $ + * $DragonFly: src/sys/netproto/ipx/ipx_usrreq.c,v 1.12 2007/04/22 01:13:15 dillon Exp $ */ #include "opt_ipx.h" @@ -174,7 +174,7 @@ ipx_input(struct mbuf *m, struct ipxpcb *ipxp) m->m_pkthdr.len -= sizeof(struct ipx); m->m_data += sizeof(struct ipx); } - if (sbappendaddr(&ipxp->ipxp_socket->so_rcv, (struct sockaddr *)&ipx_ipx, + if (ssb_appendaddr(&ipxp->ipxp_socket->so_rcv, (struct sockaddr *)&ipx_ipx, m, (struct mbuf *)NULL) == 0) goto bad; sorwakeup(ipxp->ipxp_socket); diff --git a/sys/netproto/ipx/spx_usrreq.c b/sys/netproto/ipx/spx_usrreq.c index 6a2e589994..ae89427449 100644 --- a/sys/netproto/ipx/spx_usrreq.c +++ b/sys/netproto/ipx/spx_usrreq.c @@ -34,7 +34,7 @@ * @(#)spx_usrreq.h * * $FreeBSD: src/sys/netipx/spx_usrreq.c,v 1.27.2.1 2001/02/22 09:44:18 bp Exp $ - * $DragonFly: src/sys/netproto/ipx/spx_usrreq.c,v 1.19 2007/04/21 02:26:48 dillon Exp $ + * $DragonFly: src/sys/netproto/ipx/spx_usrreq.c,v 1.20 2007/04/22 01:13:15 dillon Exp $ */ #include @@ -487,9 +487,9 @@ spx_reass(struct spxpcb *cb, struct spx *si, struct mbuf *si_m) /* * Trim Acked data from output queue. */ - while ((m = so->so_snd.sb_mb) != NULL) { + while ((m = so->so_snd.ssb_mb) != NULL) { if (SSEQ_LT((mtod(m, struct spx *))->si_seq, si->si_ack)) - sbdroprecord(&so->so_snd); + sbdroprecord(&so->so_snd.sb); else break; } @@ -600,8 +600,8 @@ present: m = q->si_mbuf; if (SI(q)->si_cc & SPX_OB) { cb->s_oobflags &= ~SF_IOOB; - if (so->so_rcv.sb_cc) - so->so_oobmark = so->so_rcv.sb_cc; + if (so->so_rcv.ssb_cc) + so->so_oobmark = so->so_rcv.ssb_cc; else so->so_state |= SS_RCVATMARK; } @@ -628,7 +628,7 @@ present: s[0] = 5; s[1] = 1; *(u_char *)(&s[2]) = dt; - sbappend(&so->so_rcv, mm); + sbappend(&so->so_rcv.sb, mm); } } if (sp->spx_cc & SPX_OB) { @@ -643,20 +643,20 @@ present: m->m_pkthdr.len -= SPINC; } if ((sp->spx_cc & SPX_EM) || packetp) { - sbappendrecord(&so->so_rcv, m); + sbappendrecord(&so->so_rcv.sb, m); spx_newchecks[9]++; } else - sbappend(&so->so_rcv, m); + sbappend(&so->so_rcv.sb, m); } else #endif if (packetp) { - sbappendrecord(&so->so_rcv, m); + sbappendrecord(&so->so_rcv.sb, m); } else { cb->s_rhdr = *mtod(m, struct spxhdr *); m->m_data += SPINC; m->m_len -= SPINC; m->m_pkthdr.len -= SPINC; - sbappend(&so->so_rcv, m); + sbappend(&so->so_rcv.sb, m); } } else break; @@ -703,7 +703,7 @@ spx_fixmtu(struct ipxpcb *ipxp) struct mbuf *m; struct spx *si; struct ipx_errp *ep; - struct sockbuf *sb; + struct signalsockbuf *ssb; int badseq, len; struct mbuf *firstbad, *m0; @@ -721,10 +721,10 @@ spx_fixmtu(struct ipxpcb *ipxp) * data at our destination will be discarded. */ ep = (struct ipx_errp *)ipxp->ipxp_notify_param; - sb = &ipxp->ipxp_socket->so_snd; + ssb = &ipxp->ipxp_socket->so_snd; cb->s_mtu = ep->ipx_err_param; badseq = ep->ipx_err_ipx.si_seq; - for (m = sb->sb_mb; m != NULL; m = m->m_nextpkt) { + for (m = ssb->ssb_mb; m != NULL; m = m->m_nextpkt) { si = mtod(m, struct spx *); if (si->si_seq == badseq) break; @@ -750,7 +750,7 @@ spx_output(struct spxpcb *cb, struct mbuf *m0) struct socket *so = cb->s_ipxpcb->ipxp_socket; struct mbuf *m = NULL; struct spx *si = NULL; - struct sockbuf *sb = &so->so_snd; + struct signalsockbuf *ssb = &so->so_snd; int len = 0, win, rcv_win; short span, off, recordp = 0; u_short alo; @@ -885,7 +885,7 @@ spx_output(struct spxpcb *cb, struct mbuf *m0) /* * queue stuff up for output */ - sbappendrecord(sb, m); + sbappendrecord(&ssb->sb, m); cb->s_seq++; } #ifdef notdef @@ -928,7 +928,7 @@ again: } if (len > 1) sendalot = 1; - rcv_win = sbspace(&so->so_rcv); + rcv_win = ssb_space(&so->so_rcv); /* * Send if we owe peer an ACK. @@ -963,8 +963,8 @@ again: u_short delta = 1 + cb->s_alo - cb->s_ack; int adv = rcv_win - (delta * cb->s_mtu); - if ((so->so_rcv.sb_cc == 0 && adv >= (2 * cb->s_mtu)) || - (100 * adv / so->so_rcv.sb_hiwat >= 35)) { + if ((so->so_rcv.ssb_cc == 0 && adv >= (2 * cb->s_mtu)) || + (100 * adv / so->so_rcv.ssb_hiwat >= 35)) { spxstat.spxs_sndwinup++; cb->s_flags |= SF_ACKNOW; goto send; @@ -980,7 +980,7 @@ again: * if window is nonzero, transmit what we can, * otherwise send a probe. */ - if (so->so_snd.sb_cc && cb->s_timer[SPXT_REXMT] == 0 && + if (so->so_snd.ssb_cc && cb->s_timer[SPXT_REXMT] == 0 && cb->s_timer[SPXT_PERSIST] == 0) { cb->s_rxtshift = 0; spx_setpersist(cb); @@ -998,7 +998,7 @@ send: si = NULL; if (len > 0) { cb->s_want = cb->s_snxt; - for (m = sb->sb_mb; m != NULL; m = m->m_nextpkt) { + for (m = ssb->ssb_mb; m != NULL; m = m->m_nextpkt) { si = mtod(m, struct spx *); if (SSEQ_LEQ(cb->s_snxt, si->si_seq)) break; @@ -1338,7 +1338,7 @@ spx_attach(struct socket *so, int proto, struct pru_attach_info *ai) struct ipxpcb *ipxp; struct spxpcb *cb; struct mbuf *mm; - struct sockbuf *sb; + struct signalsockbuf *ssb; ipxp = sotoipxpcb(so); cb = ipxtospxpcb(ipxp); @@ -1349,7 +1349,7 @@ spx_attach(struct socket *so, int proto, struct pru_attach_info *ai) error = ipx_pcballoc(so, &ipxpcb); if (error) goto spx_attach_end; - if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) { + if (so->so_snd.ssb_hiwat == 0 || so->so_rcv.ssb_hiwat == 0) { error = soreserve(so, (u_long) 3072, (u_long) 3072, ai->sb_rlimit); if (error) @@ -1358,7 +1358,7 @@ spx_attach(struct socket *so, int proto, struct pru_attach_info *ai) ipxp = sotoipxpcb(so); MALLOC(cb, struct spxpcb *, sizeof *cb, M_PCB, M_INTWAIT | M_ZERO); - sb = &so->so_snd; + ssb = &so->so_snd; mm = m_getclr(MB_DONTWAIT, MT_HEADER); if (mm == NULL) { @@ -1374,9 +1374,9 @@ spx_attach(struct socket *so, int proto, struct pru_attach_info *ai) cb->s_q.si_next = cb->s_q.si_prev = &cb->s_q; cb->s_ipxpcb = ipxp; cb->s_mtu = 576 - sizeof(struct spx); - cb->s_cwnd = sbspace(sb) * CUNIT / cb->s_mtu; + cb->s_cwnd = ssb_space(ssb) * CUNIT / cb->s_mtu; cb->s_ssthresh = cb->s_cwnd; - cb->s_cwmx = sbspace(sb) * CUNIT / (2 * sizeof(struct spx)); + cb->s_cwmx = ssb_space(ssb) * CUNIT / (2 * sizeof(struct spx)); /* Above is recomputed when connecting to account for changed buffering or mtu's */ cb->s_rtt = SPXTV_SRTTBASE; @@ -1558,7 +1558,7 @@ spx_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr, crit_enter(); if (flags & PRUS_OOB) { - if (sbspace(&so->so_snd) < -512) { + if (ssb_space(&so->so_snd) < -512) { error = ENOBUFS; goto spx_send_end; } @@ -1631,7 +1631,7 @@ spx_template(struct spxpcb *cb) { struct ipxpcb *ipxp = cb->s_ipxpcb; struct ipx *ipx = cb->s_ipx; - struct sockbuf *sb = &(ipxp->ipxp_socket->so_snd); + struct signalsockbuf *ssb = &(ipxp->ipxp_socket->so_snd); ipx->ipx_pt = IPXPROTO_SPX; ipx->ipx_sna = ipxp->ipxp_laddr; @@ -1639,10 +1639,10 @@ spx_template(struct spxpcb *cb) cb->s_sid = htons(spx_iss); spx_iss += SPX_ISSINCR/2; cb->s_alo = 1; - cb->s_cwnd = (sbspace(sb) * CUNIT) / cb->s_mtu; + cb->s_cwnd = (ssb_space(ssb) * CUNIT) / cb->s_mtu; cb->s_ssthresh = cb->s_cwnd; /* Try to expand fast to full complement of large packets */ - cb->s_cwmx = (sbspace(sb) * CUNIT) / (2 * sizeof(struct spx)); + cb->s_cwmx = (ssb_space(ssb) * CUNIT) / (2 * sizeof(struct spx)); cb->s_cwmx = max(cb->s_cwmx, cb->s_cwnd); /* But allow for lots of little packets as well */ } diff --git a/sys/netproto/key/keysock.c b/sys/netproto/key/keysock.c index 3fb368bbdc..0af4e3b95b 100644 --- a/sys/netproto/key/keysock.c +++ b/sys/netproto/key/keysock.c @@ -1,5 +1,5 @@ /* $FreeBSD: src/sys/netkey/keysock.c,v 1.1.2.4 2003/01/11 19:10:59 ume Exp $ */ -/* $DragonFly: src/sys/netproto/key/keysock.c,v 1.17 2006/12/22 23:57:54 swildner Exp $ */ +/* $DragonFly: src/sys/netproto/key/keysock.c,v 1.18 2007/04/22 01:13:15 dillon Exp $ */ /* $KAME: keysock.c,v 1.25 2001/08/13 20:07:41 itojun Exp $ */ /* @@ -153,7 +153,7 @@ key_sendup0(struct rawcb *rp, struct mbuf *m, int promisc) pfkeystat.in_msgtype[pmsg->sadb_msg_type]++; } - if (!sbappendaddr(&rp->rcb_socket->so_rcv, (struct sockaddr *)&key_src, + if (!ssb_appendaddr(&rp->rcb_socket->so_rcv, (struct sockaddr *)&key_src, m, NULL)) { pfkeystat.in_nomem++; m_freem(m); @@ -197,8 +197,8 @@ key_sendup(struct socket *so, struct sadb_msg *msg, u_int len, * Get mbuf chain whenever possible (not clusters), * to save socket buffer. We'll be generating many SADB_ACQUIRE * messages to listening key sockets. If we simply allocate clusters, - * sbappendaddr() will raise ENOBUFS due to too little sbspace(). - * sbspace() computes # of actual data bytes AND mbuf region. + * ssb_appendaddr() will raise ENOBUFS due to too little ssb_space(). + * ssb_space() computes # of actual data bytes AND mbuf region. * * TODO: SADB_ACQUIRE filters should be implemented. */ diff --git a/sys/netproto/natm/natm.c b/sys/netproto/natm/natm.c index 6155ba5c05..c7b55713fb 100644 --- a/sys/netproto/natm/natm.c +++ b/sys/netproto/natm/natm.c @@ -1,6 +1,6 @@ /* $NetBSD: natm.c,v 1.5 1996/11/09 03:26:26 chuck Exp $ */ /* $FreeBSD: src/sys/netnatm/natm.c,v 1.12 2000/02/13 03:32:03 peter Exp $ */ -/* $DragonFly: src/sys/netproto/natm/natm.c,v 1.24 2007/04/21 02:26:48 dillon Exp $ */ +/* $DragonFly: src/sys/netproto/natm/natm.c,v 1.25 2007/04/22 01:13:15 dillon Exp $ */ /* * @@ -104,7 +104,7 @@ natm_usr_attach(struct socket *so, int proto, struct pru_attach_info *ai) goto out; } - if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) { + if (so->so_snd.ssb_hiwat == 0 || so->so_rcv.ssb_hiwat == 0) { if (proto == PROTO_NATMAAL5) error = soreserve(so, natm5_sendspace, natm5_recvspace, ai->sb_rlimit); @@ -480,7 +480,7 @@ natm_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, break; } - if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) { + if (so->so_snd.ssb_hiwat == 0 || so->so_rcv.ssb_hiwat == 0) { if (proto == PROTO_NATMAAL5) error = soreserve(so, natm5_sendspace, natm5_recvspace); else @@ -808,13 +808,13 @@ m->m_pkthdr.rcvif = NULL; /* null it out to be safe */ #endif #endif - if (sbspace(&so->so_rcv) > m->m_pkthdr.len || - ((npcb->npcb_flags & NPCB_RAW) != 0 && so->so_rcv.sb_cc < NPCB_RAWCC) ) { + if (ssb_space(&so->so_rcv) > m->m_pkthdr.len || + ((npcb->npcb_flags & NPCB_RAW) != 0 && so->so_rcv.ssb_cc < NPCB_RAWCC) ) { #ifdef NATM_STAT natm_sookcnt++; natm_sookbytes += m->m_pkthdr.len; #endif - sbappendrecord(&so->so_rcv, m); + sbappendrecord(&so->so_rcv.sb, m); sorwakeup(so); } else { #ifdef NATM_STAT diff --git a/sys/netproto/natm/natm.h b/sys/netproto/natm/natm.h index 050a75355b..92b63f020f 100644 --- a/sys/netproto/natm/natm.h +++ b/sys/netproto/natm/natm.h @@ -1,6 +1,6 @@ /* $NetBSD: natm.h,v 1.1 1996/07/04 03:20:12 chuck Exp $ */ /* $FreeBSD: src/sys/netnatm/natm.h,v 1.3 1999/12/29 04:46:14 peter Exp $ */ -/* $DragonFly: src/sys/netproto/natm/natm.h,v 1.5 2004/02/06 09:17:41 rob Exp $ */ +/* $DragonFly: src/sys/netproto/natm/natm.h,v 1.6 2007/04/22 01:13:15 dillon Exp $ */ /* * @@ -99,7 +99,7 @@ struct natmpcb { /* * NPCB_RAWCC is a hack which applies to connections in 'raw' mode. it - * is used to override the sbspace() macro when you *really* don't want + * is used to override the ssb_space() macro when you *really* don't want * to drop rcv data. the recv socket buffer size is raised to this value. * * XXX: socket buffering needs to be looked at. diff --git a/sys/netproto/ncp/ncp_ncp.c b/sys/netproto/ncp/ncp_ncp.c index 5252e3fd8d..be34147fb4 100644 --- a/sys/netproto/ncp/ncp_ncp.c +++ b/sys/netproto/ncp/ncp_ncp.c @@ -30,7 +30,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/netncp/ncp_ncp.c,v 1.3 1999/10/29 10:21:07 bp Exp $ - * $DragonFly: src/sys/netproto/ncp/ncp_ncp.c,v 1.14 2007/04/20 05:42:23 dillon Exp $ + * $DragonFly: src/sys/netproto/ncp/ncp_ncp.c,v 1.15 2007/04/22 01:13:16 dillon Exp $ * * Core of NCP protocol */ @@ -212,13 +212,13 @@ ncp_do_request(struct ncp_conn *conn, struct ncp_rq *rqp) { */ crit_enter(); while (1/*so->so_rcv.sb_cc*/) { - struct sorecv_direct sio; + struct sockbuf sio; if (ncp_poll(so, POLLIN) == 0) break; if (ncp_sock_recv(so, &sio) != 0) break; - m_freem(sio.m0); + sbflush(&sio); } rq = mtod(rqp->rq,struct ncp_rqhdr *); rq->seq = conn->seq; @@ -276,14 +276,14 @@ ncp_do_request(struct ncp_conn *conn, struct ncp_rq *rqp) { gotpacket = 0; /* nothing good found */ dosend = 1; /* resend rq if error */ for (;;) { - struct sorecv_direct sio; + struct sockbuf sio; error = 0; if (ncp_poll(so,POLLIN) == 0) break; error = ncp_sock_recv(so, &sio); if (error) break; /* must be more checks !!! */ - m = sio.m0; + m = sio.sb_mb; if (m->m_len < sizeof(*rp)) { m = m_pullup(m, sizeof(*rp)); if (m == NULL) { @@ -292,7 +292,7 @@ ncp_do_request(struct ncp_conn *conn, struct ncp_rq *rqp) { } } rp = mtod(m, struct ncp_rphdr*); - if (sio.len == sizeof(*rp) && rp->type == NCP_POSITIVE_ACK) { + if (sio.sb_cc == sizeof(*rp) && rp->type == NCP_POSITIVE_ACK) { NCPSDEBUG("got positive acknowledge\n"); m_freem(m); rqp->rexmit = conn->li.retry_count; @@ -317,7 +317,7 @@ ncp_do_request(struct ncp_conn *conn, struct ncp_rq *rqp) { } else { gotpacket = 1; mreply = m; - plen = sio.len; + plen = sio.sb_cc; } continue; /* look up other for other packets */ } diff --git a/sys/netproto/ncp/ncp_sock.c b/sys/netproto/ncp/ncp_sock.c index bf1dab19bd..99e5a2024c 100644 --- a/sys/netproto/ncp/ncp_sock.c +++ b/sys/netproto/ncp/ncp_sock.c @@ -30,7 +30,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/netncp/ncp_sock.c,v 1.2 1999/10/12 10:36:59 bp Exp $ - * $DragonFly: src/sys/netproto/ncp/ncp_sock.c,v 1.17 2007/04/20 05:42:23 dillon Exp $ + * $DragonFly: src/sys/netproto/ncp/ncp_sock.c,v 1.18 2007/04/22 01:13:16 dillon Exp $ * * Low level socket routines */ @@ -139,13 +139,11 @@ ncp_getsockname(struct socket *so, caddr_t asa, int *alen) { } #endif int -ncp_sock_recv(struct socket *so, struct sorecv_direct *sio) +ncp_sock_recv(struct socket *so, struct sockbuf *sio) { - struct thread *td = curthread; /* XXX */ int error, flags; - sio->len = 1000000; /* limit data returned (inexact, hint only) */ - sio->m0 = NULL; + sbinit(sio, 1000000); /* limit data returned (inexact, hint only) */ flags = MSG_DONTWAIT; error = so_pru_soreceive(so, NULL, NULL, sio, NULL, &flags); @@ -396,30 +394,30 @@ ncp_watchdog(struct ncp_conn *conn) { int error, len, flags; struct socket *so; struct sockaddr *sa; - struct sorecv_direct sio; + struct sockbuf sio; sa = NULL; while (conn->wdg_so) { /* not a loop */ so = conn->wdg_so; - sorecv_direct_init(&sio, 1000000); + sbinit(&sio, 1000000); flags = MSG_DONTWAIT; error = so_pru_soreceive(so, (struct sockaddr**)&sa, NULL, &sio, NULL, &flags); if (error) break; - len = sio.len; + len = sio.sb_cc; NCPSDEBUG("got watch dog %d\n",len); if (len != 2) { - m_freem(sio.m0); + m_freem(sio.sb_mb); break; } - buf = mtod(sio.m0, char *); + buf = mtod(sio.sb_mb, char *); if (buf[1] != '?') { - m_freem(sio.m0); + m_freem(sio.sb_mb); break; } buf[1] = 'Y'; - error = so_pru_sosend(so, sa, NULL, sio.m0, NULL, 0, curthread); + error = so_pru_sosend(so, sa, NULL, sio.sb_mb, NULL, 0, curthread); NCPSDEBUG("send watch dog %d\n",error); break; } diff --git a/sys/netproto/ncp/ncp_sock.h b/sys/netproto/ncp/ncp_sock.h index d7b5c967b6..8bc79b3a4d 100644 --- a/sys/netproto/ncp/ncp_sock.h +++ b/sys/netproto/ncp/ncp_sock.h @@ -30,7 +30,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/netncp/ncp_sock.h,v 1.3 2000/01/14 19:54:39 bde Exp $ - * $DragonFly: src/sys/netproto/ncp/ncp_sock.h,v 1.4 2007/04/20 05:42:23 dillon Exp $ + * $DragonFly: src/sys/netproto/ncp/ncp_sock.h,v 1.5 2007/04/22 01:13:16 dillon Exp $ */ #ifndef _NETNCP_NCP_SOCK_H_ #define _NETNCP_NCP_SOCK_H_ @@ -45,7 +45,7 @@ struct timeval; int ncp_sock_connect_ipx(struct ncp_conn *); int ncp_sock_connect_in(struct ncp_conn *); -int ncp_sock_recv(struct socket *so, struct sorecv_direct *sio); +int ncp_sock_recv(struct socket *so, struct sockbuf *sio); int ncp_sock_send(struct socket *so, struct mbuf *data, struct ncp_rq *rqp); int ncp_sock_disconnect(struct ncp_conn *conn); int ncp_poll(struct socket *so, int events); diff --git a/sys/netproto/ns/idp_usrreq.c b/sys/netproto/ns/idp_usrreq.c index 5057d2b8fe..75217910d9 100644 --- a/sys/netproto/ns/idp_usrreq.c +++ b/sys/netproto/ns/idp_usrreq.c @@ -32,7 +32,7 @@ * * @(#)idp_usrreq.c 8.1 (Berkeley) 6/10/93 * $FreeBSD: src/sys/netns/idp_usrreq.c,v 1.9 1999/08/28 00:49:47 peter Exp $ - * $DragonFly: src/sys/netproto/ns/idp_usrreq.c,v 1.13 2007/04/21 02:26:48 dillon Exp $ + * $DragonFly: src/sys/netproto/ns/idp_usrreq.c,v 1.14 2007/04/22 01:13:16 dillon Exp $ */ #include @@ -108,7 +108,7 @@ idp_input(struct mbuf *m, ...) m->m_pkthdr.len -= sizeof (struct idp); m->m_data += sizeof (struct idp); } - if (sbappendaddr(&nsp->nsp_socket->so_rcv, (struct sockaddr *)&idp_ns, + if (ssb_appendaddr(&nsp->nsp_socket->so_rcv, (struct sockaddr *)&idp_ns, m, (struct mbuf *)0) == 0) goto bad; sorwakeup(nsp->nsp_socket); diff --git a/sys/netproto/ns/spp_usrreq.c b/sys/netproto/ns/spp_usrreq.c index c1982c6a30..2b2e5a13b0 100644 --- a/sys/netproto/ns/spp_usrreq.c +++ b/sys/netproto/ns/spp_usrreq.c @@ -32,7 +32,7 @@ * * @(#)spp_usrreq.c 8.1 (Berkeley) 6/10/93 * $FreeBSD: src/sys/netns/spp_usrreq.c,v 1.11 1999/08/28 00:49:53 peter Exp $ - * $DragonFly: src/sys/netproto/ns/spp_usrreq.c,v 1.21 2007/04/21 02:26:48 dillon Exp $ + * $DragonFly: src/sys/netproto/ns/spp_usrreq.c,v 1.22 2007/04/22 01:13:16 dillon Exp $ */ #include @@ -423,9 +423,9 @@ spp_reass(struct sppcb *cb, struct spidp *si, struct mbuf *si_m) /* * Trim Acked data from output queue. */ - while ((m = so->so_snd.sb_mb) != NULL) { + while ((m = so->so_snd.ssb_mb) != NULL) { if (SSEQ_LT((mtod(m, struct spidp *))->si_seq, si->si_ack)) - sbdroprecord(&so->so_snd); + sbdroprecord(&so->so_snd.sb); else break; } @@ -537,8 +537,8 @@ present: m = q->si_mbuf; if (SI(q)->si_cc & SP_OB) { cb->s_oobflags &= ~SF_IOOB; - if (so->so_rcv.sb_cc) - so->so_oobmark = so->so_rcv.sb_cc; + if (so->so_rcv.ssb_cc) + so->so_oobmark = so->so_rcv.ssb_cc; else so->so_state |= SS_RCVATMARK; } @@ -565,7 +565,7 @@ present: s[0] = 5; s[1] = 1; *(u_char *)(&s[2]) = dt; - sbappend(&so->so_rcv, mm); + sbappend(&so->so_rcv.sb, mm); } } if (sp->sp_cc & SP_OB) { @@ -580,20 +580,20 @@ present: m->m_pkthdr.len -= SPINC; } if ((sp->sp_cc & SP_EM) || packetp) { - sbappendrecord(&so->so_rcv, m); + sbappendrecord(&so->so_rcv.sb, m); spp_newchecks[9]++; } else - sbappend(&so->so_rcv, m); + sbappend(&so->so_rcv.sb, m); } else #endif if (packetp) { - sbappendrecord(&so->so_rcv, m); + sbappendrecord(&so->so_rcv.sb, m); } else { cb->s_rhdr = *mtod(m, struct sphdr *); m->m_data += SPINC; m->m_len -= SPINC; m->m_pkthdr.len -= SPINC; - sbappend(&so->so_rcv, m); + sbappend(&so->so_rcv.sb, m); } } else break; @@ -679,7 +679,7 @@ spp_fixmtu(struct nspcb *nsp) struct mbuf *m; struct spidp *si; struct ns_errp *ep; - struct sockbuf *sb; + struct signalsockbuf *ssb; int badseq, len; struct mbuf *firstbad, *m0; @@ -697,10 +697,10 @@ spp_fixmtu(struct nspcb *nsp) * data at our destination will be discarded. */ ep = (struct ns_errp *)nsp->nsp_notify_param; - sb = &nsp->nsp_socket->so_snd; + ssb = &nsp->nsp_socket->so_snd; cb->s_mtu = ep->ns_err_param; badseq = ep->ns_err_idp.si_seq; - for (m = sb->sb_mb; m; m = m->m_nextpkt) { + for (m = ssb->ssb_mb; m; m = m->m_nextpkt) { si = mtod(m, struct spidp *); if (si->si_seq == badseq) break; @@ -725,7 +725,7 @@ spp_output(struct sppcb *cb, struct mbuf *m0) struct socket *so = cb->s_nspcb->nsp_socket; struct mbuf *m = NULL; struct spidp *si = NULL; - struct sockbuf *sb = &so->so_snd; + struct signalsockbuf *ssb = &so->so_snd; int len = 0, win, rcv_win; short span, off, recordp = 0; u_short alo; @@ -860,7 +860,7 @@ spp_output(struct sppcb *cb, struct mbuf *m0) /* * queue stuff up for output */ - sbappendrecord(sb, m); + sbappendrecord(&ssb->sb, m); cb->s_seq++; } #ifdef notdef @@ -903,7 +903,7 @@ again: } if (len > 1) sendalot = 1; - rcv_win = sbspace(&so->so_rcv); + rcv_win = ssb_space(&so->so_rcv); /* * Send if we owe peer an ACK. @@ -938,8 +938,8 @@ again: u_short delta = 1 + cb->s_alo - cb->s_ack; int adv = rcv_win - (delta * cb->s_mtu); - if ((so->so_rcv.sb_cc == 0 && adv >= (2 * cb->s_mtu)) || - (100 * adv / so->so_rcv.sb_hiwat >= 35)) { + if ((so->so_rcv.ssb_cc == 0 && adv >= (2 * cb->s_mtu)) || + (100 * adv / so->so_rcv.ssb_hiwat >= 35)) { sppstat.spps_sndwinup++; cb->s_flags |= SF_ACKNOW; goto send; @@ -955,7 +955,7 @@ again: * if window is nonzero, transmit what we can, * otherwise send a probe. */ - if (so->so_snd.sb_cc && cb->s_timer[SPPT_REXMT] == 0 && + if (so->so_snd.ssb_cc && cb->s_timer[SPPT_REXMT] == 0 && cb->s_timer[SPPT_PERSIST] == 0) { cb->s_rxtshift = 0; spp_setpersist(cb); @@ -973,7 +973,7 @@ send: si = NULL; if (len > 0) { cb->s_want = cb->s_snxt; - for (m = sb->sb_mb; m; m = m->m_nextpkt) { + for (m = ssb->ssb_mb; m; m = m->m_nextpkt) { si = mtod(m, struct spidp *); if (SSEQ_LEQ(cb->s_snxt, si->si_seq)) break; @@ -1318,20 +1318,20 @@ spp_attach(struct socket *so, int proto, struct pru_attach_info *ai) { struct nspcb *nsp = sotonspcb(so); struct sppcb *cb; - struct sockbuf *sb; + struct signalsockbuf *ssb; int error; if (nsp != NULL) return(EISCONN); if ((error = ns_pcballoc(so, &nspcb)) != 0) return(error); - if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) { + if (so->so_snd.ssb_hiwat == 0 || so->so_rcv.ssb_hiwat == 0) { if ((error = soreserve(so, 3072, 3072, ai->sb_rlimit)) != 0) return(error); } nsp = sotonspcb(so); - sb = &so->so_snd; + ssb = &so->so_snd; cb = kmalloc(sizeof(struct sppcb), M_SPPCB, M_WAITOK|M_ZERO); cb->s_idp = kmalloc(sizeof(struct idp), M_IDP, M_WAITOK|M_ZERO); cb->s_state = TCPS_LISTEN; @@ -1340,9 +1340,9 @@ spp_attach(struct socket *so, int proto, struct pru_attach_info *ai) cb->s_q.si_next = cb->s_q.si_prev = &cb->s_q; cb->s_nspcb = nsp; cb->s_mtu = 576 - sizeof (struct spidp); - cb->s_cwnd = sbspace(sb) * CUNIT / cb->s_mtu; + cb->s_cwnd = ssb_space(ssb) * CUNIT / cb->s_mtu; cb->s_ssthresh = cb->s_cwnd; - cb->s_cwmx = sbspace(sb) * CUNIT / (2 * sizeof (struct spidp)); + cb->s_cwmx = ssb_space(ssb) * CUNIT / (2 * sizeof (struct spidp)); /* * Above is recomputed when connecting to account @@ -1556,7 +1556,7 @@ spp_send(struct socket *so, int flags, struct mbuf *m, cb = nstosppcb(nsp); error = 0; if (flags & PRUS_OOB) { - if (sbspace(&so->so_snd) < -512) { + if (ssb_space(&so->so_snd) < -512) { error = ENOBUFS; } else { cb->s_oobflags |= SF_SOOB; @@ -1679,7 +1679,7 @@ spp_template(struct sppcb *cb) { struct nspcb *nsp = cb->s_nspcb; struct idp *idp = cb->s_idp; - struct sockbuf *sb = &(nsp->nsp_socket->so_snd); + struct signalsockbuf *ssb = &(nsp->nsp_socket->so_snd); idp->idp_pt = NSPROTO_SPP; idp->idp_sna = nsp->nsp_laddr; @@ -1687,10 +1687,10 @@ spp_template(struct sppcb *cb) cb->s_sid = htons(spp_iss); spp_iss += SPP_ISSINCR/2; cb->s_alo = 1; - cb->s_cwnd = (sbspace(sb) * CUNIT) / cb->s_mtu; + cb->s_cwnd = (ssb_space(ssb) * CUNIT) / cb->s_mtu; cb->s_ssthresh = cb->s_cwnd; /* Try to expand fast to full complement of large packets */ - cb->s_cwmx = (sbspace(sb) * CUNIT) / (2 * sizeof(struct spidp)); + cb->s_cwmx = (ssb_space(ssb) * CUNIT) / (2 * sizeof(struct spidp)); cb->s_cwmx = max(cb->s_cwmx, cb->s_cwnd); /* But allow for lots of little packets as well */ } diff --git a/sys/netproto/smb/smb_trantcp.c b/sys/netproto/smb/smb_trantcp.c index 2eb287a2c6..c80c7ae2b9 100644 --- a/sys/netproto/smb/smb_trantcp.c +++ b/sys/netproto/smb/smb_trantcp.c @@ -30,7 +30,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/netsmb/smb_trantcp.c,v 1.3.2.1 2001/05/22 08:32:34 bp Exp $ - * $DragonFly: src/sys/netproto/smb/smb_trantcp.c,v 1.18 2007/04/20 05:42:24 dillon Exp $ + * $DragonFly: src/sys/netproto/smb/smb_trantcp.c,v 1.19 2007/04/22 01:13:16 dillon Exp $ */ #include #include @@ -207,25 +207,25 @@ nb_connect_in(struct nbpcb *nbp, struct sockaddr_in *to, struct thread *td) nbp->nbp_tso = so; so->so_upcallarg = (caddr_t)nbp; so->so_upcall = nb_upcall; - so->so_rcv.sb_flags |= SB_UPCALL; - so->so_rcv.sb_timeo = (5 * hz); - so->so_snd.sb_timeo = (5 * hz); + so->so_rcv.ssb_flags |= SSB_UPCALL; + so->so_rcv.ssb_timeo = (5 * hz); + so->so_snd.ssb_timeo = (5 * hz); error = soreserve(so, nbp->nbp_sndbuf, nbp->nbp_rcvbuf, &td->td_proc->p_rlimit[RLIMIT_SBSIZE]); if (error) goto bad; nb_setsockopt_int(so, SOL_SOCKET, SO_KEEPALIVE, 1); nb_setsockopt_int(so, IPPROTO_TCP, TCP_NODELAY, 1); - so->so_rcv.sb_flags &= ~SB_NOINTR; - so->so_snd.sb_flags &= ~SB_NOINTR; + so->so_rcv.ssb_flags &= ~SSB_NOINTR; + so->so_snd.ssb_flags &= ~SSB_NOINTR; error = soconnect(so, (struct sockaddr*)to, td); /* * If signals are allowed nbssn_recv() can wind up in a hard loop * on EWOULDBLOCK. */ - so->so_rcv.sb_flags |= SB_NOINTR; - so->so_snd.sb_flags |= SB_NOINTR; + so->so_rcv.ssb_flags |= SSB_NOINTR; + so->so_snd.ssb_flags |= SSB_NOINTR; if (error) goto bad; crit_enter(); @@ -371,15 +371,14 @@ nbssn_recv(struct nbpcb *nbp, struct mbuf **mpp, int *lenp, u_int8_t *rpcodep, struct thread *td) { struct socket *so = nbp->nbp_tso; - struct sorecv_direct sio; + struct sockbuf sio; u_int8_t rpcode; int error, rcvflg, savelen; if (so == NULL) return ENOTCONN; - sio.len = 0; - sio.m0 = NULL; + sbinit(&sio, 0); if (mpp) *mpp = NULL; @@ -399,7 +398,7 @@ nbssn_recv(struct nbpcb *nbp, struct mbuf **mpp, int *lenp, if (rpcode == NB_SSN_KEEPALIVE) continue; do { - sorecv_direct_init(&sio, savelen); + sbinit(&sio, savelen); rcvflg = MSG_WAITALL; error = so_pru_soreceive(so, NULL, NULL, &sio, NULL, &rcvflg); @@ -407,24 +406,25 @@ nbssn_recv(struct nbpcb *nbp, struct mbuf **mpp, int *lenp, error == ERESTART); if (error) break; - if (sio.len != savelen) { + if (sio.sb_cc != savelen) { SMBERROR("packet is shorter than expected\n"); error = EPIPE; - m_freem(sio.m0); + m_freem(sio.sb_mb); break; } if (nbp->nbp_state == NBST_SESSION && rpcode == NB_SSN_MESSAGE) break; NBDEBUG("non-session packet %x\n", rpcode); - m_freem(sio.m0); - sio.m0 = NULL; + m_freem(sio.sb_mb); + sio.sb_mb = NULL; + sio.sb_cc = 0; } if (error == 0) { if (mpp) - *mpp = sio.m0; + *mpp = sio.sb_mb; else - m_freem(sio.m0); - *lenp = sio.len; + m_freem(sio.sb_mb); + *lenp = sio.sb_cc; *rpcodep = rpcode; } return (error); diff --git a/sys/sys/aio.h b/sys/sys/aio.h index a7d9517bc1..30fa3e76b5 100644 --- a/sys/sys/aio.h +++ b/sys/sys/aio.h @@ -14,7 +14,7 @@ * of the author. This software is distributed AS-IS. * * $FreeBSD: src/sys/sys/aio.h,v 1.13.2.8 2002/08/31 03:18:23 alc Exp $ - * $DragonFly: src/sys/sys/aio.h,v 1.4 2006/05/20 02:42:13 dillon Exp $ + * $DragonFly: src/sys/sys/aio.h,v 1.5 2007/04/22 01:13:16 dillon Exp $ */ #ifndef _SYS_AIO_H_ @@ -164,10 +164,10 @@ struct aiocblist { /* Forward declarations for prototypes below. */ struct socket; -struct sockbuf; +struct signalsockbuf; void aio_proc_rundown(struct proc *p); -void aio_swake(struct socket *, struct sockbuf *); +void aio_swake(struct socket *, struct signalsockbuf *); #endif diff --git a/sys/sys/protosw.h b/sys/sys/protosw.h index a9c94b804b..4167ae0516 100644 --- a/sys/sys/protosw.h +++ b/sys/sys/protosw.h @@ -32,7 +32,7 @@ * * @(#)protosw.h 8.1 (Berkeley) 6/2/93 * $FreeBSD: src/sys/sys/protosw.h,v 1.28.2.2 2001/07/03 11:02:01 ume Exp $ - * $DragonFly: src/sys/sys/protosw.h,v 1.18 2007/04/20 05:42:24 dillon Exp $ + * $DragonFly: src/sys/sys/protosw.h,v 1.19 2007/04/22 01:13:17 dillon Exp $ */ #ifndef _SYS_PROTOSW_H_ @@ -186,7 +186,7 @@ struct ifnet; struct stat; struct ucred; struct uio; -struct sorecv_direct; +struct sockbuf; struct pru_attach_info { struct rlimit *sb_rlimit; @@ -246,7 +246,7 @@ struct pr_usrreqs { int (*pru_soreceive) (struct socket *so, struct sockaddr **paddr, struct uio *uio, - struct sorecv_direct *sio, + struct sockbuf *sio, struct mbuf **controlp, int *flagsp); int (*pru_sopoll) (struct socket *so, int events, struct ucred *cred, struct thread *td); @@ -283,7 +283,7 @@ typedef int (*pru_sosend_fn_t) (struct socket *so, struct sockaddr *addr, struct thread *td); typedef int (*pru_soreceive_fn_t) (struct socket *so, struct sockaddr **paddr, struct uio *uio, - struct sorecv_direct *sio, + struct sockbuf *sio, struct mbuf **controlp, int *flagsp); typedef int (*pru_sopoll_fn_t) (struct socket *so, int events, diff --git a/sys/sys/sockbuf.h b/sys/sys/sockbuf.h new file mode 100644 index 0000000000..8b7d377269 --- /dev/null +++ b/sys/sys/sockbuf.h @@ -0,0 +1,124 @@ +/*- + * Copyright (c) 1982, 1986, 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)socketvar.h 8.3 (Berkeley) 2/19/95 + * $FreeBSD: src/sys/sys/socketvar.h,v 1.46.2.10 2003/08/24 08:24:39 hsu Exp $ + * $DragonFly: src/sys/sys/sockbuf.h,v 1.1 2007/04/22 01:13:17 dillon Exp $ + */ + +#ifndef _SYS_SOCKBUF_H_ +#define _SYS_SOCKBUF_H_ + +#ifndef _SYS_TYPES_H_ +#include +#endif + +#if defined(_KERNEL) || defined(_KERNEL_STRUCTURES) + +/* + * Generic socket buffer for keeping track of mbuf chains. These + * are used primarily to manipulate mbuf chains in standalone pieces + * of code. + */ +struct sockbuf { + u_long sb_cc; /* actual chars in buffer */ + u_long sb_mbcnt; /* chars of mbufs used */ + u_long sb_climit; /* data limit when used for I/O */ + struct mbuf *sb_mb; /* the mbuf chain */ + struct mbuf *sb_lastmbuf; /* last mbuf in sb_mb */ + struct mbuf *sb_lastrecord; /* last record in sb_mb + * valid <=> sb_mb non-NULL */ +}; + +#define SB_MAX (256*1024) /* default for max chars in sockbuf */ + +#endif + +#ifdef _KERNEL + +/* + * Macros for sockets and socket buffering. + */ + +#ifdef SOCKBUF_DEBUG +#define sbcheck(sb) _sbcheck(sb) +#else +#define sbcheck(sb) +#endif + +/* adjust counters in sb reflecting allocation of m */ +#define sballoc(sb, m) { \ + (sb)->sb_cc += (m)->m_len; \ + (sb)->sb_mbcnt += MSIZE; \ + if ((m)->m_flags & M_EXT) \ + (sb)->sb_mbcnt += (m)->m_ext.ext_size; \ +} + +/* adjust counters in sb reflecting freeing of m */ +#define sbfree(sb, m) { \ + (sb)->sb_cc -= (m)->m_len; \ + (sb)->sb_mbcnt -= MSIZE; \ + if ((m)->m_flags & M_EXT) \ + (sb)->sb_mbcnt -= (m)->m_ext.ext_size; \ +} + +static __inline void +sbinit(struct sockbuf *sb, u_long climit) +{ + sb->sb_cc = 0; + sb->sb_mbcnt = 0; + sb->sb_climit = climit; + sb->sb_mb = NULL; + sb->sb_lastmbuf = NULL; + sb->sb_lastrecord = NULL; +} + +void sbappend (struct sockbuf *sb, struct mbuf *m); +int sbappendaddr (struct sockbuf *sb, const struct sockaddr *asa, + struct mbuf *m0, struct mbuf *control); +int sbappendcontrol (struct sockbuf *sb, struct mbuf *m0, + struct mbuf *control); +void sbappendrecord (struct sockbuf *sb, struct mbuf *m0); +void sbappendstream (struct sockbuf *sb, struct mbuf *m); +void _sbcheck (struct sockbuf *sb); +void sbcompress (struct sockbuf *sb, struct mbuf *m, struct mbuf *n); +struct mbuf * + sbcreatecontrol (caddr_t p, int size, int type, int level); +void sbdrop (struct sockbuf *sb, int len); +void sbdroprecord (struct sockbuf *sb); +struct mbuf * + sbunlinkmbuf (struct sockbuf *, struct mbuf *, struct mbuf **); +void sbflush (struct sockbuf *sb); + +#endif /* _KERNEL */ + +#endif /* !_SYS_SOCKBUF_H_ */ diff --git a/sys/sys/socketops.h b/sys/sys/socketops.h index a8601a5734..6c0b5021cb 100644 --- a/sys/sys/socketops.h +++ b/sys/sys/socketops.h @@ -30,7 +30,7 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sys/sys/socketops.h,v 1.10 2007/04/20 05:42:24 dillon Exp $ + * $DragonFly: src/sys/sys/socketops.h,v 1.11 2007/04/22 01:13:17 dillon Exp $ */ #ifndef _SOCKETOPS_H_ @@ -67,7 +67,7 @@ so_pru_sosend(struct socket *so, struct sockaddr *addr, struct uio *uio, static __inline int so_pru_soreceive(struct socket *so, struct sockaddr **paddr, struct uio *uio, - struct sorecv_direct *sio, struct mbuf **controlp, int *flagsp) + struct sockbuf *sio, struct mbuf **controlp, int *flagsp) { return ((*so->so_proto->pr_usrreqs->pru_soreceive)(so, paddr, uio, sio, controlp, flagsp)); diff --git a/sys/sys/socketvar.h b/sys/sys/socketvar.h index 1bd617eef9..92bddc366b 100644 --- a/sys/sys/socketvar.h +++ b/sys/sys/socketvar.h @@ -32,7 +32,7 @@ * * @(#)socketvar.h 8.3 (Berkeley) 2/19/95 * $FreeBSD: src/sys/sys/socketvar.h,v 1.46.2.10 2003/08/24 08:24:39 hsu Exp $ - * $DragonFly: src/sys/sys/socketvar.h,v 1.27 2007/04/20 05:42:24 dillon Exp $ + * $DragonFly: src/sys/sys/socketvar.h,v 1.28 2007/04/22 01:13:17 dillon Exp $ */ #ifndef _SYS_SOCKETVAR_H_ @@ -47,17 +47,47 @@ #ifndef _SYS_SELINFO_H_ #include /* for struct selinfo */ #endif +#ifndef _SYS_SOCKBUF_H_ +#include +#endif #if defined(_KERNEL) || defined(_KERNEL_STRUCTURES) + +struct accept_filter; + /* - * Kernel structure per socket. - * Contains send and receive buffer queues, - * handle on protocol and pointer to protocol - * private data and error information. + * Signaling socket buffers contain additional elements for locking + * and signaling conditions. These are used primarily by sockets. */ +struct signalsockbuf { + struct sockbuf sb; + struct selinfo ssb_sel; /* process selecting read/write */ + short ssb_flags; /* flags, see below */ + short ssb_timeo; /* timeout for read/write */ + long ssb_lowat; /* low water mark */ + u_long ssb_hiwat; /* high water mark / max actual char count */ + u_long ssb_mbmax; /* max chars of mbufs to use */ +}; -struct accept_filter; +#define ssb_cc sb.sb_cc /* commonly used fields */ +#define ssb_mb sb.sb_mb /* commonly used fields */ +#define ssb_mbcnt sb.sb_mbcnt /* commonly used fields */ + +#define SSB_LOCK 0x01 /* lock on data queue */ +#define SSB_WANT 0x02 /* someone is waiting to lock */ +#define SSB_WAIT 0x04 /* someone is waiting for data/space */ +#define SSB_SEL 0x08 /* someone is selecting */ +#define SSB_ASYNC 0x10 /* ASYNC I/O, need signals */ +#define SSB_UPCALL 0x20 /* someone wants an upcall */ +#define SSB_NOINTR 0x40 /* operations not interruptible */ +#define SSB_AIO 0x80 /* AIO operations queued */ +#define SSB_KNOTE 0x100 /* kernel note attached */ +#define SSB_MEVENT 0x200 /* need message event notification */ +/* + * Per-socket kernel structure. Contains universal send and receive queues, + * protocol control handle, and error information. + */ struct socket { short so_type; /* generic type, see socket.h */ short so_options; /* from socket call, see socket.h */ @@ -65,59 +95,30 @@ struct socket { short so_state; /* internal state flags SS_*, below */ void *so_pcb; /* protocol control block */ struct protosw *so_proto; /* protocol handle */ -/* - * Variables for connection queuing. - * Socket where accepts occur is so_head in all subsidiary sockets. - * If so_head is 0, socket is not related to an accept. - * For head socket so_incomp queues partially completed connections, - * while so_comp is a queue of connections ready to be accepted. - * If a connection is aborted and it has so_head set, then - * it has to be pulled out of either so_incomp or so_comp. - * We allow connections to queue up based on current queue lengths - * and limit on number of queued connections for this socket. - */ struct socket *so_head; /* back pointer to accept socket */ - TAILQ_HEAD(, socket) so_incomp; /* queue of partial unaccepted connections */ - TAILQ_HEAD(, socket) so_comp; /* queue of complete unaccepted connections */ + + /* + * These fields are used to manage sockets capable of accepting + * new connections. + */ + TAILQ_HEAD(, socket) so_incomp; /* in-progress, incomplete */ + TAILQ_HEAD(, socket) so_comp; /* completed but not yet accepted */ TAILQ_ENTRY(socket) so_list; /* list of unaccepted connections */ - short so_qlen; /* number of unaccepted connections */ - short so_incqlen; /* number of unaccepted incomplete - connections */ + short so_qlen; /* so_comp count */ + short so_incqlen; /* so_incomp count */ short so_qlimit; /* max number queued connections */ + + /* + * Misc socket support + */ short so_timeo; /* connection timeout */ u_short so_error; /* error affecting connection */ struct sigio *so_sigio; /* information for async I/O or out of band data (SIGURG) */ u_long so_oobmark; /* chars to oob mark */ TAILQ_HEAD(, aiocblist) so_aiojobq; /* AIO ops waiting on socket */ -/* - * Variables for socket buffering. - */ - struct sockbuf { - u_long sb_cc; /* actual chars in buffer */ - u_long sb_hiwat; /* max actual char count */ - u_long sb_mbcnt; /* chars of mbufs used */ - u_long sb_mbmax; /* max chars of mbufs to use */ - long sb_lowat; /* low water mark */ - struct mbuf *sb_mb; /* the mbuf chain */ - struct mbuf *sb_lastmbuf; /* last mbuf in sb_mb */ - struct mbuf *sb_lastrecord; /* last record in sb_mb - * valid <=> sb_mb non-NULL */ - struct selinfo sb_sel; /* process selecting read/write */ - short sb_flags; /* flags, see below */ - short sb_timeo; /* timeout for read/write */ - } so_rcv, so_snd; -#define SB_MAX (256*1024) /* default for max chars in sockbuf */ -#define SB_LOCK 0x01 /* lock on data queue */ -#define SB_WANT 0x02 /* someone is waiting to lock */ -#define SB_WAIT 0x04 /* someone is waiting for data/space */ -#define SB_SEL 0x08 /* someone is selecting */ -#define SB_ASYNC 0x10 /* ASYNC I/O, need signals */ -#define SB_UPCALL 0x20 /* someone wants an upcall */ -#define SB_NOINTR 0x40 /* operations not interruptible */ -#define SB_AIO 0x80 /* AIO operations queued */ -#define SB_KNOTE 0x100 /* kernel note attached */ -#define SB_MEVENT 0x200 /* need message event notification */ + struct signalsockbuf so_rcv; + struct signalsockbuf so_snd; void (*so_upcall) (struct socket *, void *, int); void *so_upcallarg; @@ -188,88 +189,93 @@ struct xsocket { * Macros for sockets and socket buffering. */ -#ifdef SOCKBUF_DEBUG -#define sbcheck(sb) _sbcheck(sb) -#else -#define sbcheck(sb) -#endif - -/* - * Do we need to notify the other side when I/O is possible? - */ -#define sb_notify(sb) \ -(((sb)->sb_flags & \ - (SB_WAIT | SB_SEL | SB_ASYNC | SB_UPCALL | SB_AIO | SB_KNOTE | SB_MEVENT))) - -/* - * How much space is there in a socket buffer (so->so_snd or so->so_rcv)? - * This is problematical if the fields are unsigned, as the space might - * still be negative (cc > hiwat or mbcnt > mbmax). Should detect - * overflow and return 0. Should use "lmin" but it doesn't exist now. - */ -#define sbspace(sb) \ - ((long) imin((int)((sb)->sb_hiwat - (sb)->sb_cc), \ - (int)((sb)->sb_mbmax - (sb)->sb_mbcnt))) - -/* do we have to send all at once on a socket? */ #define sosendallatonce(so) \ ((so)->so_proto->pr_flags & PR_ATOMIC) /* can we read something from so? */ #define soreadable(so) \ - ((so)->so_rcv.sb_cc >= (so)->so_rcv.sb_lowat || \ + ((so)->so_rcv.ssb_cc >= (so)->so_rcv.ssb_lowat || \ ((so)->so_state & SS_CANTRCVMORE) || \ !TAILQ_EMPTY(&(so)->so_comp) || (so)->so_error) /* can we write something to so? */ #define sowriteable(so) \ - ((sbspace(&(so)->so_snd) >= (so)->so_snd.sb_lowat && \ + ((ssb_space(&(so)->so_snd) >= (so)->so_snd.ssb_lowat && \ (((so)->so_state&SS_ISCONNECTED) || \ ((so)->so_proto->pr_flags&PR_CONNREQUIRED)==0)) || \ ((so)->so_state & SS_CANTSENDMORE) || \ (so)->so_error) -/* adjust counters in sb reflecting allocation of m */ -#define sballoc(sb, m) { \ - (sb)->sb_cc += (m)->m_len; \ - (sb)->sb_mbcnt += MSIZE; \ - if ((m)->m_flags & M_EXT) \ - (sb)->sb_mbcnt += (m)->m_ext.ext_size; \ -} - -/* adjust counters in sb reflecting freeing of m */ -#define sbfree(sb, m) { \ - (sb)->sb_cc -= (m)->m_len; \ - (sb)->sb_mbcnt -= MSIZE; \ - if ((m)->m_flags & M_EXT) \ - (sb)->sb_mbcnt -= (m)->m_ext.ext_size; \ -} +/* + * Do we need to notify the other side when I/O is possible? + */ +#define ssb_notify(ssb) \ + (((ssb)->ssb_flags & \ + (SSB_WAIT | SSB_SEL | SSB_ASYNC | SSB_UPCALL | \ + SSB_AIO | SSB_KNOTE | SSB_MEVENT))) +/* do we have to send all at once on a socket? */ /* * Set lock on sockbuf sb; sleep if lock is already held. - * Unless SB_NOINTR is set on sockbuf, sleep is interruptible. + * Unless SSB_NOINTR is set on signalsockbuf, sleep is interruptible. * Returns error without lock if sleep is interrupted. */ -#define sblock(sb, wf) ((sb)->sb_flags & SB_LOCK ? \ - (((wf) == M_WAITOK) ? sb_lock(sb) : EWOULDBLOCK) : \ - ((sb)->sb_flags |= SB_LOCK), 0) - -/* release lock on sockbuf sb */ -#define sbunlock(sb) { \ - (sb)->sb_flags &= ~SB_LOCK; \ - if ((sb)->sb_flags & SB_WANT) { \ - (sb)->sb_flags &= ~SB_WANT; \ - wakeup((caddr_t)&(sb)->sb_flags); \ +#define ssb_lock(ssb, wf) ((ssb)->ssb_flags & SSB_LOCK ? \ + (((wf) == M_WAITOK) ? _ssb_lock(ssb) : EWOULDBLOCK) : \ + ((ssb)->ssb_flags |= SSB_LOCK), 0) + +/* release lock on signalsockbuf sb */ +#define ssb_unlock(ssb) { \ + (ssb)->ssb_flags &= ~SSB_LOCK; \ + if ((ssb)->ssb_flags & SSB_WANT) { \ + (ssb)->ssb_flags &= ~SSB_WANT; \ + wakeup((caddr_t)&(ssb)->ssb_flags); \ } \ } +/* + * How much space is there in a socket buffer (so->so_snd or so->so_rcv)? + * This is problematical if the fields are unsigned, as the space might + * still be negative (cc > hiwat or mbcnt > mbmax). Should detect + * overflow and return 0. Should use "lmin" but it doesn't exist now. + */ +#define ssb_space(ssb) \ + ((long)imin((int)((ssb)->ssb_hiwat - (ssb)->ssb_cc), \ + (int)((ssb)->ssb_mbmax - (ssb)->ssb_mbcnt))) + +#define ssb_append(ssb, m) \ + sbappend(&(ssb)->sb, m) + +#define ssb_appendstream(ssb, m) \ + sbappendstream(&(ssb)->sb, m) + +#define ssb_appendrecord(ssb, m) \ + sbappendrecord(&(ssb)->sb, m) + +#define ssb_appendaddr(ssb, src, m, control) \ + ((ssb_space(ssb) <= 0) ? 1 : sbappendaddr(&(ssb)->sb, src, m, control)) + +#define ssb_appendcontrol(ssb, m, control) \ + ((ssb_space(ssb) <= 0) ? 1 : sbappendcontrol(&(ssb)->sb, m, control)) + +#define ssb_insert_knote(ssb, kn) { \ + SLIST_INSERT_HEAD(&(ssb)->ssb_sel.si_note, kn, kn_selnext); \ + (ssb)->ssb_flags |= SSB_KNOTE; \ +} + +#define ssb_remove_knote(ssb, kn) { \ + SLIST_REMOVE(&(ssb)->ssb_sel.si_note, kn, knote, kn_selnext); \ + if (SLIST_EMPTY(&(ssb)->ssb_sel.si_note)) \ + (ssb)->ssb_flags &= ~SSB_KNOTE; \ +} + #define sorwakeup(so) do { \ - if (sb_notify(&(so)->so_rcv)) \ + if (ssb_notify(&(so)->so_rcv)) \ sowakeup((so), &(so)->so_rcv); \ } while (0) #define sowwakeup(so) do { \ - if (sb_notify(&(so)->so_snd)) \ + if (ssb_notify(&(so)->so_snd)) \ sowakeup((so), &(so)->so_snd); \ } while (0) @@ -300,27 +306,6 @@ struct accept_filter { SLIST_ENTRY(accept_filter) accf_next; /* next on the list */ }; -/* - * Passed to so_pru_soreceive() instead of a UIO to directly obtain an - * mbuf chain. The sorecv_direct API allows mbufs to be directly - * transfered to the caller. - */ -struct sorecv_direct { - int len; - int maxlen; - struct mbuf *m0; - struct mbuf **mapp; -}; - -static __inline void -sorecv_direct_init(struct sorecv_direct *sio, int maxlen) -{ - sio->len = 0; - sio->maxlen = maxlen; - sio->m0 = NULL; - sio->mapp = &sio->m0; -} - #ifdef MALLOC_DECLARE MALLOC_DECLARE(M_PCB); MALLOC_DECLARE(M_SONAME); @@ -362,29 +347,14 @@ int sokqfilter (struct file *fp, struct knote *kn); */ struct sockaddr *dup_sockaddr (const struct sockaddr *sa); int getsockaddr (struct sockaddr **namp, caddr_t uaddr, size_t len); -void sbappend (struct sockbuf *sb, struct mbuf *m); -int sbappendaddr (struct sockbuf *sb, const struct sockaddr *asa, - struct mbuf *m0, struct mbuf *control); -int sbappendcontrol (struct sockbuf *sb, struct mbuf *m0, - struct mbuf *control); -void sbappendrecord (struct sockbuf *sb, struct mbuf *m0); -void sbappendstream (struct sockbuf *sb, struct mbuf *m); -void _sbcheck (struct sockbuf *sb); -void sbcompress (struct sockbuf *sb, struct mbuf *m, struct mbuf *n); -struct mbuf * - sbcreatecontrol (caddr_t p, int size, int type, int level); -void sbdrop (struct sockbuf *sb, int len); -void sbdroprecord (struct sockbuf *sb); -struct mbuf * - sbunlinkmbuf (struct sockbuf *, struct mbuf *, struct mbuf **); -void sbflush (struct sockbuf *sb); -void sbinsertoob (struct sockbuf *sb, struct mbuf *m0); -void sbrelease (struct sockbuf *sb, struct socket *so); -int sbreserve (struct sockbuf *sb, u_long cc, struct socket *so, + +void ssb_release (struct signalsockbuf *ssb, struct socket *so); +int ssb_reserve (struct signalsockbuf *ssb, u_long cc, struct socket *so, struct rlimit *rl); -void sbtoxsockbuf (struct sockbuf *sb, struct xsockbuf *xsb); -int sbwait (struct sockbuf *sb); -int sb_lock (struct sockbuf *sb); +void ssbtoxsockbuf (struct signalsockbuf *sb, struct xsockbuf *xsb); +int ssb_wait (struct signalsockbuf *sb); +int _ssb_lock (struct signalsockbuf *sb); + int soabort (struct socket *so); int soaccept (struct socket *so, struct sockaddr **nam); struct socket *soalloc (int waitok); @@ -419,7 +389,7 @@ int soopt_mcopyout (struct sockopt *sopt, struct mbuf *m); int sopoll (struct socket *so, int events, struct ucred *cred, struct thread *td); int soreceive (struct socket *so, struct sockaddr **paddr, - struct uio *uio, struct sorecv_direct *sio, + struct uio *uio, struct sockbuf *sio, struct mbuf **controlp, int *flagsp); int soreserve (struct socket *so, u_long sndcc, u_long rcvcc, struct rlimit *rl); @@ -433,7 +403,7 @@ int sosendudp (struct socket *so, struct sockaddr *addr, struct uio *uio, int sosetopt (struct socket *so, struct sockopt *sopt); int soshutdown (struct socket *so, int how); void sotoxsocket (struct socket *so, struct xsocket *xso); -void sowakeup (struct socket *so, struct sockbuf *sb); +void sowakeup (struct socket *so, struct signalsockbuf *sb); /* accept filter functions */ int accept_filt_add (struct accept_filter *filt); diff --git a/sys/vfs/fifofs/fifo_vnops.c b/sys/vfs/fifofs/fifo_vnops.c index 1308a260bc..b30a7c3598 100644 --- a/sys/vfs/fifofs/fifo_vnops.c +++ b/sys/vfs/fifofs/fifo_vnops.c @@ -32,7 +32,7 @@ * * @(#)fifo_vnops.c 8.10 (Berkeley) 5/27/95 * $FreeBSD: src/sys/miscfs/fifofs/fifo_vnops.c,v 1.45.2.4 2003/04/22 10:11:24 bde Exp $ - * $DragonFly: src/sys/vfs/fifofs/fifo_vnops.c,v 1.36 2007/04/20 05:42:24 dillon Exp $ + * $DragonFly: src/sys/vfs/fifofs/fifo_vnops.c,v 1.37 2007/04/22 01:13:17 dillon Exp $ */ #include @@ -195,7 +195,7 @@ fifo_open(struct vop_open_args *ap) return (error); } fip->fi_readers = fip->fi_writers = 0; - wso->so_snd.sb_lowat = PIPE_BUF; + wso->so_snd.ssb_lowat = PIPE_BUF; rso->so_state |= SS_CANTRCVMORE; } if (ap->a_mode & FREAD) { @@ -361,18 +361,18 @@ fifo_kqfilter(struct vop_kqfilter_args *ap) { struct fifoinfo *fi = ap->a_vp->v_fifoinfo; struct socket *so; - struct sockbuf *sb; + struct signalsockbuf *ssb; switch (ap->a_kn->kn_filter) { case EVFILT_READ: ap->a_kn->kn_fop = &fiforead_filtops; so = fi->fi_readsock; - sb = &so->so_rcv; + ssb = &so->so_rcv; break; case EVFILT_WRITE: ap->a_kn->kn_fop = &fifowrite_filtops; so = fi->fi_writesock; - sb = &so->so_snd; + ssb = &so->so_snd; break; default: return (1); @@ -380,8 +380,7 @@ fifo_kqfilter(struct vop_kqfilter_args *ap) ap->a_kn->kn_hook = (caddr_t)so; - SLIST_INSERT_HEAD(&sb->sb_sel.si_note, ap->a_kn, kn_selnext); - sb->sb_flags |= SB_KNOTE; + ssb_insert_knote(ssb, ap->a_kn); return (0); } @@ -391,9 +390,7 @@ filt_fifordetach(struct knote *kn) { struct socket *so = (struct socket *)kn->kn_hook; - SLIST_REMOVE(&so->so_rcv.sb_sel.si_note, kn, knote, kn_selnext); - if (SLIST_EMPTY(&so->so_rcv.sb_sel.si_note)) - so->so_rcv.sb_flags &= ~SB_KNOTE; + ssb_remove_knote(&so->so_rcv, kn); } static int @@ -401,7 +398,7 @@ filt_fiforead(struct knote *kn, long hint) { struct socket *so = (struct socket *)kn->kn_hook; - kn->kn_data = so->so_rcv.sb_cc; + kn->kn_data = so->so_rcv.ssb_cc; if (so->so_state & SS_CANTRCVMORE) { kn->kn_flags |= EV_EOF; return (1); @@ -415,9 +412,7 @@ filt_fifowdetach(struct knote *kn) { struct socket *so = (struct socket *)kn->kn_hook; - SLIST_REMOVE(&so->so_snd.sb_sel.si_note, kn, knote, kn_selnext); - if (SLIST_EMPTY(&so->so_snd.sb_sel.si_note)) - so->so_snd.sb_flags &= ~SB_KNOTE; + ssb_remove_knote(&so->so_snd, kn); } static int @@ -425,13 +420,13 @@ filt_fifowrite(struct knote *kn, long hint) { struct socket *so = (struct socket *)kn->kn_hook; - kn->kn_data = sbspace(&so->so_snd); + kn->kn_data = ssb_space(&so->so_snd); if (so->so_state & SS_CANTSENDMORE) { kn->kn_flags |= EV_EOF; return (1); } kn->kn_flags &= ~EV_EOF; - return (kn->kn_data >= so->so_snd.sb_lowat); + return (kn->kn_data >= so->so_snd.ssb_lowat); } /* diff --git a/sys/vfs/nfs/krpc_subr.c b/sys/vfs/nfs/krpc_subr.c index 6dee8b7333..838cbc94d5 100644 --- a/sys/vfs/nfs/krpc_subr.c +++ b/sys/vfs/nfs/krpc_subr.c @@ -1,6 +1,6 @@ /* $NetBSD: krpc_subr.c,v 1.12.4.1 1996/06/07 00:52:26 cgd Exp $ */ /* $FreeBSD: src/sys/nfs/krpc_subr.c,v 1.13.2.1 2000/11/20 21:17:14 tegge Exp $ */ -/* $DragonFly: src/sys/vfs/nfs/krpc_subr.c,v 1.11 2007/04/20 05:42:25 dillon Exp $ */ +/* $DragonFly: src/sys/vfs/nfs/krpc_subr.c,v 1.12 2007/04/22 01:13:17 dillon Exp $ */ /* * Copyright (c) 1995 Gordon Ross, Adam Glass @@ -199,7 +199,7 @@ krpc_call(struct sockaddr_in *sa, u_int prog, u_int vers, u_int func, struct rpc_reply *reply; struct sockopt sopt; struct timeval tv; - struct sorecv_direct sio; + struct sockbuf sio; int error, rcvflg, timo, secs, len; static u_int32_t xid = ~0xFF; u_int16_t tport; @@ -354,7 +354,7 @@ krpc_call(struct sockaddr_in *sa, u_int prog, u_int vers, u_int func, m = NULL; } len = 1 << 16; - sorecv_direct_init(&sio, len); + sbinit(&sio, len); rcvflg = 0; error = soreceive(so, &from, NULL, &sio, NULL, &rcvflg); if (error == EWOULDBLOCK) { @@ -363,8 +363,8 @@ krpc_call(struct sockaddr_in *sa, u_int prog, u_int vers, u_int func, } if (error) goto out; - len -= sio.len; - m = sio.m0; + len -= sio.sb_cc; + m = sio.sb_mb; /* Does the reply contain at least a header? */ if (len < MIN_REPLY_HDR) diff --git a/sys/vfs/nfs/nfs_socket.c b/sys/vfs/nfs/nfs_socket.c index afae07a22d..b74d0f588c 100644 --- a/sys/vfs/nfs/nfs_socket.c +++ b/sys/vfs/nfs/nfs_socket.c @@ -35,7 +35,7 @@ * * @(#)nfs_socket.c 8.5 (Berkeley) 3/30/95 * $FreeBSD: src/sys/nfs/nfs_socket.c,v 1.60.2.6 2003/03/26 01:44:46 alfred Exp $ - * $DragonFly: src/sys/vfs/nfs/nfs_socket.c,v 1.43 2007/04/20 05:42:25 dillon Exp $ + * $DragonFly: src/sys/vfs/nfs/nfs_socket.c,v 1.44 2007/04/22 01:13:17 dillon Exp $ */ /* @@ -299,8 +299,8 @@ nfs_connect(struct nfsmount *nmp, struct nfsreq *rep) } crit_exit(); } - so->so_rcv.sb_timeo = (5 * hz); - so->so_snd.sb_timeo = (5 * hz); + so->so_rcv.ssb_timeo = (5 * hz); + so->so_snd.ssb_timeo = (5 * hz); /* * Get buffer reservation size from sysctl, but impose reasonable @@ -356,8 +356,8 @@ nfs_connect(struct nfsmount *nmp, struct nfsreq *rep) &td->td_proc->p_rlimit[RLIMIT_SBSIZE]); if (error) goto bad; - so->so_rcv.sb_flags |= SB_NOINTR; - so->so_snd.sb_flags |= SB_NOINTR; + so->so_rcv.ssb_flags |= SSB_NOINTR; + so->so_snd.ssb_flags |= SSB_NOINTR; /* Initialize other non-zero congestion variables */ nmp->nm_srtt[0] = nmp->nm_srtt[1] = nmp->nm_srtt[2] = @@ -531,7 +531,7 @@ static int nfs_receive(struct nfsreq *rep, struct sockaddr **aname, struct mbuf **mp) { struct socket *so; - struct sorecv_direct sio; + struct sockbuf sio; struct uio auio; struct iovec aio; struct mbuf *m; @@ -651,22 +651,22 @@ tryagain: /* * Get the rest of the packet as an mbuf chain */ - sorecv_direct_init(&sio, len); + sbinit(&sio, len); do { rcvflg = MSG_WAITALL; error = so_pru_soreceive(so, NULL, NULL, &sio, NULL, &rcvflg); } while (error == EWOULDBLOCK || error == EINTR || error == ERESTART); - if (error == 0 && sio.len != len) { - if (sio.len != 0) + if (error == 0 && sio.sb_cc != len) { + if (sio.sb_cc != 0) log(LOG_INFO, "short receive (%d/%d) from nfs server %s\n", len - auio.uio_resid, len, rep->r_nmp->nm_mountp->mnt_stat.f_mntfromname); error = EPIPE; } - *mp = sio.m0; + *mp = sio.sb_mb; } else { /* * Non-stream, so get the whole packet by not @@ -677,7 +677,7 @@ tryagain: * and then throw them away so we know what is going * on. */ - sorecv_direct_init(&sio, 100000000); + sbinit(&sio, 100000000); do { rcvflg = 0; error = so_pru_soreceive(so, NULL, NULL, &sio, @@ -686,18 +686,18 @@ tryagain: m_freem(control); if (error == EWOULDBLOCK && rep) { if (rep->r_flags & R_SOFTTERM) { - m_freem(sio.m0); + m_freem(sio.sb_mb); return (EINTR); } } } while (error == EWOULDBLOCK || - (error == 0 && sio.m0 == NULL && control)); + (error == 0 && sio.sb_mb == NULL && control)); if ((rcvflg & MSG_EOR) == 0) kprintf("Egad!!\n"); - if (error == 0 && sio.m0 == NULL) + if (error == 0 && sio.sb_mb == NULL) error = EPIPE; - len = sio.len; - *mp = sio.m0; + len = sio.sb_cc; + *mp = sio.sb_mb; } errout: if (error && error != EINTR && error != ERESTART) { @@ -725,19 +725,19 @@ errout: getnam = NULL; else getnam = aname; - sorecv_direct_init(&sio, 100000000); + sbinit(&sio, 100000000); do { rcvflg = 0; error = so_pru_soreceive(so, getnam, NULL, &sio, NULL, &rcvflg); if (error == EWOULDBLOCK && (rep->r_flags & R_SOFTTERM)) { - m_freem(sio.m0); + m_freem(sio.sb_mb); return (EINTR); } } while (error == EWOULDBLOCK); - len = sio.len; - *mp = sio.m0; + len = sio.sb_cc; + *mp = sio.sb_mb; } if (error) { m_freem(*mp); @@ -1428,7 +1428,7 @@ nfs_timer(void *arg /* never used */) * Set r_rtt to -1 in case we fail to send it now. */ rep->r_rtt = -1; - if (sbspace(&so->so_snd) >= rep->r_mreq->m_pkthdr.len && + if (ssb_space(&so->so_snd) >= rep->r_mreq->m_pkthdr.len && ((nmp->nm_flag & NFSMNT_DUMBTIMR) || (rep->r_flags & R_SENT) || nmp->nm_sent < nmp->nm_cwnd) && @@ -2039,7 +2039,7 @@ nfsrv_rcv(struct socket *so, void *arg, int waitflag) struct nfssvc_sock *slp = (struct nfssvc_sock *)arg; struct mbuf *m; struct sockaddr *nam; - struct sorecv_direct sio; + struct sockbuf sio; int flags, error; int nparallel_wakeup = 0; @@ -2093,10 +2093,10 @@ nfsrv_rcv(struct socket *so, void *arg, int waitflag) * Do soreceive(). Pull out as much data as possible without * blocking. */ - sorecv_direct_init(&sio, 1000000000); + sbinit(&sio, 1000000000); flags = MSG_DONTWAIT; error = so_pru_soreceive(so, &nam, NULL, &sio, NULL, &flags); - if (error || sio.m0 == NULL) { + if (error || sio.sb_mb == NULL) { if (error == EWOULDBLOCK) slp->ns_flag |= SLP_NEEDQ; else @@ -2104,13 +2104,13 @@ nfsrv_rcv(struct socket *so, void *arg, int waitflag) slp->ns_flag &= ~SLP_GETSTREAM; goto dorecs; } - m = sio.m0; + m = sio.sb_mb; if (slp->ns_rawend) { slp->ns_rawend->m_next = m; - slp->ns_cc += sio.len; + slp->ns_cc += sio.sb_cc; } else { slp->ns_raw = m; - slp->ns_cc = sio.len; + slp->ns_cc = sio.sb_cc; } while (m->m_next) m = m->m_next; @@ -2134,11 +2134,11 @@ nfsrv_rcv(struct socket *so, void *arg, int waitflag) * to get the whole batch. */ do { - sorecv_direct_init(&sio, 1000000000); + sbinit(&sio, 1000000000); flags = MSG_DONTWAIT; error = so_pru_soreceive(so, &nam, NULL, &sio, NULL, &flags); - if (sio.m0) { + if (sio.sb_mb) { struct nfsrv_rec *rec; int mf = (waitflag & MB_DONTWAIT) ? M_NOWAIT : M_WAITOK; @@ -2147,12 +2147,12 @@ nfsrv_rcv(struct socket *so, void *arg, int waitflag) if (!rec) { if (nam) FREE(nam, M_SONAME); - m_freem(sio.m0); + m_freem(sio.sb_mb); continue; } - nfs_realign(&sio.m0, 10 * NFSX_UNSIGNED); + nfs_realign(&sio.sb_mb, 10 * NFSX_UNSIGNED); rec->nr_address = nam; - rec->nr_packet = sio.m0; + rec->nr_packet = sio.sb_mb; STAILQ_INSERT_TAIL(&slp->ns_rec, rec, nr_link); ++slp->ns_numrec; ++nparallel_wakeup; @@ -2164,7 +2164,7 @@ nfsrv_rcv(struct socket *so, void *arg, int waitflag) goto dorecs; } } - } while (sio.m0); + } while (sio.sb_mb); } /* diff --git a/sys/vfs/nfs/nfs_syscalls.c b/sys/vfs/nfs/nfs_syscalls.c index 90c17b6999..b0bce96403 100644 --- a/sys/vfs/nfs/nfs_syscalls.c +++ b/sys/vfs/nfs/nfs_syscalls.c @@ -35,7 +35,7 @@ * * @(#)nfs_syscalls.c 8.5 (Berkeley) 3/30/95 * $FreeBSD: src/sys/nfs/nfs_syscalls.c,v 1.58.2.1 2000/11/26 02:30:06 dillon Exp $ - * $DragonFly: src/sys/vfs/nfs/nfs_syscalls.c,v 1.28 2006/12/23 00:41:29 swildner Exp $ + * $DragonFly: src/sys/vfs/nfs/nfs_syscalls.c,v 1.29 2007/04/22 01:13:17 dillon Exp $ */ #include @@ -395,10 +395,10 @@ nfssvc_addsock(struct file *fp, struct sockaddr *mynam, struct thread *td) val = 1; sosetopt(so, &sopt); } - so->so_rcv.sb_flags &= ~SB_NOINTR; - so->so_rcv.sb_timeo = 0; - so->so_snd.sb_flags &= ~SB_NOINTR; - so->so_snd.sb_timeo = 0; + so->so_rcv.ssb_flags &= ~SSB_NOINTR; + so->so_rcv.ssb_timeo = 0; + so->so_snd.ssb_flags &= ~SSB_NOINTR; + so->so_snd.ssb_timeo = 0; slp = (struct nfssvc_sock *) kmalloc(sizeof (struct nfssvc_sock), M_NFSSVC, M_WAITOK); @@ -414,7 +414,7 @@ nfssvc_addsock(struct file *fp, struct sockaddr *mynam, struct thread *td) crit_enter(); so->so_upcallarg = (caddr_t)slp; so->so_upcall = nfsrv_rcv; - so->so_rcv.sb_flags |= SB_UPCALL; + so->so_rcv.ssb_flags |= SSB_UPCALL; slp->ns_flag = (SLP_VALID | SLP_NEEDQ); nfsrv_wakenfsd(slp, 1); crit_exit(); @@ -719,7 +719,7 @@ nfsrv_zapsock(struct nfssvc_sock *slp) if (fp) { slp->ns_fp = (struct file *)0; so = slp->ns_so; - so->so_rcv.sb_flags &= ~SB_UPCALL; + so->so_rcv.ssb_flags &= ~SSB_UPCALL; so->so_upcall = NULL; so->so_upcallarg = NULL; soshutdown(so, 2); diff --git a/sys/vfs/portal/portal_vnops.c b/sys/vfs/portal/portal_vnops.c index 9bb58abd76..cdfe4d6993 100644 --- a/sys/vfs/portal/portal_vnops.c +++ b/sys/vfs/portal/portal_vnops.c @@ -36,7 +36,7 @@ * @(#)portal_vnops.c 8.14 (Berkeley) 5/21/95 * * $FreeBSD: src/sys/miscfs/portal/portal_vnops.c,v 1.38 1999/12/21 06:29:00 chris Exp $ - * $DragonFly: src/sys/vfs/portal/portal_vnops.c,v 1.34 2007/04/20 05:42:25 dillon Exp $ + * $DragonFly: src/sys/vfs/portal/portal_vnops.c,v 1.35 2007/04/22 01:13:17 dillon Exp $ */ /* @@ -211,7 +211,7 @@ portal_open(struct vop_open_args *ap) struct vnode *vp = ap->a_vp; struct uio auio; struct iovec aiov[2]; - struct sorecv_direct sio; + struct sockbuf sio; int res; struct mbuf *cm = 0; struct cmsghdr *cmsg; @@ -296,10 +296,10 @@ portal_open(struct vop_open_args *ap) /* * Set miscellaneous flags */ - so->so_rcv.sb_timeo = 0; - so->so_snd.sb_timeo = 0; - so->so_rcv.sb_flags |= SB_NOINTR; - so->so_snd.sb_flags |= SB_NOINTR; + so->so_rcv.ssb_timeo = 0; + so->so_snd.ssb_timeo = 0; + so->so_rcv.ssb_flags |= SSB_NOINTR; + so->so_snd.ssb_flags |= SSB_NOINTR; pcred.pcr_flag = ap->a_mode; @@ -324,7 +324,7 @@ portal_open(struct vop_open_args *ap) goto bad; len = sizeof(int); - sorecv_direct_init(&sio, len); + sbinit(&sio, len); do { struct mbuf *m; int flags; @@ -337,7 +337,7 @@ portal_open(struct vop_open_args *ap) /* * Grab an error code from the mbuf. */ - if ((m = sio.m0) != NULL) { + if ((m = sio.sb_mb) != NULL) { m = m_pullup(m, sizeof(int)); /* Needed? */ if (m) { error = *(mtod(m, int *)); @@ -353,7 +353,7 @@ portal_open(struct vop_open_args *ap) #endif } } - } while (cm == NULL && sio.len == 0 && !error); + } while (cm == NULL && sio.sb_cc == 0 && !error); if (cm == NULL) goto bad; -- 2.41.0