2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 1982, 1986, 1988, 1990, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * @(#)uipc_socket2.c 8.1 (Berkeley) 6/10/93
34 #include <sys/cdefs.h>
35 __FBSDID("$FreeBSD$");
37 #include "opt_kern_tls.h"
38 #include "opt_param.h"
40 #include <sys/param.h>
41 #include <sys/aio.h> /* for aio_swake proto */
42 #include <sys/kernel.h>
45 #include <sys/malloc.h>
47 #include <sys/mutex.h>
49 #include <sys/protosw.h>
50 #include <sys/resourcevar.h>
51 #include <sys/signalvar.h>
52 #include <sys/socket.h>
53 #include <sys/socketvar.h>
55 #include <sys/sysctl.h>
58 * Function pointer set by the AIO routines so that the socket buffer code
59 * can call back into the AIO module if it is loaded.
61 void (*aio_swake)(struct socket *, struct sockbuf *);
64 * Primitive routines for operating on socket buffers
67 u_long sb_max = SB_MAX;
69 (quad_t)SB_MAX * MCLBYTES / (MSIZE + MCLBYTES); /* adjusted sb_max */
71 static u_long sb_efficiency = 8; /* parameter for sbreserve() */
74 static void sbcompress_ktls_rx(struct sockbuf *sb, struct mbuf *m,
77 static struct mbuf *sbcut_internal(struct sockbuf *sb, int len);
78 static void sbflush_internal(struct sockbuf *sb);
81 * Our own version of m_clrprotoflags(), that can preserve M_NOTREADY.
84 sbm_clrprotoflags(struct mbuf *m, int flags)
89 if (flags & PRUS_NOTREADY)
98 * Compress M_NOTREADY mbufs after they have been readied by sbready().
100 * sbcompress() skips M_NOTREADY mbufs since the data is not available to
101 * be copied at the time of sbcompress(). This function combines small
102 * mbufs similar to sbcompress() once mbufs are ready. 'm0' is the first
103 * mbuf sbready() marked ready, and 'end' is the first mbuf still not
107 sbready_compress(struct sockbuf *sb, struct mbuf *m0, struct mbuf *end)
112 SOCKBUF_LOCK_ASSERT(sb);
114 if ((sb->sb_flags & SB_NOCOALESCE) != 0)
117 for (m = m0; m != end; m = m->m_next) {
118 MPASS((m->m_flags & M_NOTREADY) == 0);
120 * NB: In sbcompress(), 'n' is the last mbuf in the
121 * socket buffer and 'm' is the new mbuf being copied
122 * into the trailing space of 'n'. Here, the roles
123 * are reversed and 'n' is the next mbuf after 'm'
124 * that is being copied into the trailing space of
129 /* Try to coalesce adjacent ktls mbuf hdr/trailers. */
130 if ((n != NULL) && (n != end) && (m->m_flags & M_EOR) == 0 &&
131 (m->m_flags & M_EXTPG) &&
132 (n->m_flags & M_EXTPG) &&
133 !mbuf_has_tls_session(m) &&
134 !mbuf_has_tls_session(n)) {
135 int hdr_len, trail_len;
137 hdr_len = n->m_epg_hdrlen;
138 trail_len = m->m_epg_trllen;
139 if (trail_len != 0 && hdr_len != 0 &&
140 trail_len + hdr_len <= MBUF_PEXT_TRAIL_LEN) {
141 /* copy n's header to m's trailer */
142 memcpy(&m->m_epg_trail[trail_len],
143 n->m_epg_hdr, hdr_len);
144 m->m_epg_trllen += hdr_len;
152 /* Compress small unmapped mbufs into plain mbufs. */
153 if ((m->m_flags & M_EXTPG) && m->m_len <= MLEN &&
154 !mbuf_has_tls_session(m)) {
155 ext_size = m->m_ext.ext_size;
156 if (mb_unmapped_compress(m) == 0)
157 sb->sb_mbcnt -= ext_size;
160 while ((n != NULL) && (n != end) && (m->m_flags & M_EOR) == 0 &&
162 (m->m_flags & M_EXTPG) == 0 &&
163 !mbuf_has_tls_session(n) &&
164 !mbuf_has_tls_session(m) &&
165 n->m_len <= MCLBYTES / 4 && /* XXX: Don't copy too much */
166 n->m_len <= M_TRAILINGSPACE(m) &&
167 m->m_type == n->m_type) {
168 KASSERT(sb->sb_lastrecord != n,
169 ("%s: merging start of record (%p) into previous mbuf (%p)",
171 m_copydata(n, 0, n->m_len, mtodo(m, m->m_len));
172 m->m_len += n->m_len;
173 m->m_next = n->m_next;
174 m->m_flags |= n->m_flags & M_EOR;
175 if (sb->sb_mbtail == n)
178 sb->sb_mbcnt -= MSIZE;
179 if (n->m_flags & M_EXT)
180 sb->sb_mbcnt -= n->m_ext.ext_size;
190 * Mark ready "count" units of I/O starting with "m". Most mbufs
191 * count as a single unit of I/O except for M_EXTPG mbufs which
192 * are backed by multiple pages.
195 sbready(struct sockbuf *sb, struct mbuf *m0, int count)
200 SOCKBUF_LOCK_ASSERT(sb);
201 KASSERT(sb->sb_fnrdy != NULL, ("%s: sb %p NULL fnrdy", __func__, sb));
202 KASSERT(count > 0, ("%s: invalid count %d", __func__, count));
205 blocker = (sb->sb_fnrdy == m) ? M_BLOCKED : 0;
208 KASSERT(m->m_flags & M_NOTREADY,
209 ("%s: m %p !M_NOTREADY", __func__, m));
210 if ((m->m_flags & M_EXTPG) != 0 && m->m_epg_npgs != 0) {
211 if (count < m->m_epg_nrdy) {
212 m->m_epg_nrdy -= count;
216 count -= m->m_epg_nrdy;
221 m->m_flags &= ~(M_NOTREADY | blocker);
223 sb->sb_acc += m->m_len;
228 * If the first mbuf is still not fully ready because only
229 * some of its backing pages were readied, no further progress
233 MPASS(m->m_flags & M_NOTREADY);
234 return (EINPROGRESS);
238 sbready_compress(sb, m0, m);
239 return (EINPROGRESS);
242 /* This one was blocking all the queue. */
243 for (; m && (m->m_flags & M_NOTREADY) == 0; m = m->m_next) {
244 KASSERT(m->m_flags & M_BLOCKED,
245 ("%s: m %p !M_BLOCKED", __func__, m));
246 m->m_flags &= ~M_BLOCKED;
247 sb->sb_acc += m->m_len;
251 sbready_compress(sb, m0, m);
257 * Adjust sockbuf state reflecting allocation of m.
260 sballoc(struct sockbuf *sb, struct mbuf *m)
263 SOCKBUF_LOCK_ASSERT(sb);
265 sb->sb_ccc += m->m_len;
267 if (sb->sb_fnrdy == NULL) {
268 if (m->m_flags & M_NOTREADY)
271 sb->sb_acc += m->m_len;
273 m->m_flags |= M_BLOCKED;
275 if (m->m_type != MT_DATA && m->m_type != MT_OOBDATA)
276 sb->sb_ctl += m->m_len;
278 sb->sb_mbcnt += MSIZE;
280 if (m->m_flags & M_EXT)
281 sb->sb_mbcnt += m->m_ext.ext_size;
285 * Adjust sockbuf state reflecting freeing of m.
288 sbfree(struct sockbuf *sb, struct mbuf *m)
291 #if 0 /* XXX: not yet: soclose() call path comes here w/o lock. */
292 SOCKBUF_LOCK_ASSERT(sb);
295 sb->sb_ccc -= m->m_len;
297 if (!(m->m_flags & M_NOTAVAIL))
298 sb->sb_acc -= m->m_len;
300 if (m == sb->sb_fnrdy) {
303 KASSERT(m->m_flags & M_NOTREADY,
304 ("%s: m %p !M_NOTREADY", __func__, m));
307 while (n != NULL && !(n->m_flags & M_NOTREADY)) {
308 n->m_flags &= ~M_BLOCKED;
309 sb->sb_acc += n->m_len;
315 if (m->m_type != MT_DATA && m->m_type != MT_OOBDATA)
316 sb->sb_ctl -= m->m_len;
318 sb->sb_mbcnt -= MSIZE;
319 if (m->m_flags & M_EXT)
320 sb->sb_mbcnt -= m->m_ext.ext_size;
322 if (sb->sb_sndptr == m) {
323 sb->sb_sndptr = NULL;
324 sb->sb_sndptroff = 0;
326 if (sb->sb_sndptroff != 0)
327 sb->sb_sndptroff -= m->m_len;
332 * Similar to sballoc/sbfree but does not adjust state associated with
333 * the sb_mb chain such as sb_fnrdy or sb_sndptr*. Also assumes mbufs
337 sballoc_ktls_rx(struct sockbuf *sb, struct mbuf *m)
340 SOCKBUF_LOCK_ASSERT(sb);
342 sb->sb_ccc += m->m_len;
343 sb->sb_tlscc += m->m_len;
345 sb->sb_mbcnt += MSIZE;
347 if (m->m_flags & M_EXT)
348 sb->sb_mbcnt += m->m_ext.ext_size;
352 sbfree_ktls_rx(struct sockbuf *sb, struct mbuf *m)
355 #if 0 /* XXX: not yet: soclose() call path comes here w/o lock. */
356 SOCKBUF_LOCK_ASSERT(sb);
359 sb->sb_ccc -= m->m_len;
360 sb->sb_tlscc -= m->m_len;
362 sb->sb_mbcnt -= MSIZE;
364 if (m->m_flags & M_EXT)
365 sb->sb_mbcnt -= m->m_ext.ext_size;
370 * Socantsendmore indicates that no more data will be sent on the socket; it
371 * would normally be applied to a socket when the user informs the system
372 * that no more data is to be sent, by the protocol code (in case
373 * PRU_SHUTDOWN). Socantrcvmore indicates that no more data will be
374 * received, and will normally be applied to the socket by a protocol when it
375 * detects that the peer will send no more data. Data queued for reading in
376 * the socket may yet be read.
379 socantsendmore_locked(struct socket *so)
382 SOCK_SENDBUF_LOCK_ASSERT(so);
384 so->so_snd.sb_state |= SBS_CANTSENDMORE;
385 sowwakeup_locked(so);
386 SOCK_SENDBUF_UNLOCK_ASSERT(so);
390 socantsendmore(struct socket *so)
393 SOCK_SENDBUF_LOCK(so);
394 socantsendmore_locked(so);
395 SOCK_SENDBUF_UNLOCK_ASSERT(so);
399 socantrcvmore_locked(struct socket *so)
402 SOCK_RECVBUF_LOCK_ASSERT(so);
404 so->so_rcv.sb_state |= SBS_CANTRCVMORE;
406 if (so->so_rcv.sb_flags & SB_TLS_RX)
407 ktls_check_rx(&so->so_rcv);
409 sorwakeup_locked(so);
410 SOCK_RECVBUF_UNLOCK_ASSERT(so);
414 socantrcvmore(struct socket *so)
417 SOCK_RECVBUF_LOCK(so);
418 socantrcvmore_locked(so);
419 SOCK_RECVBUF_UNLOCK_ASSERT(so);
423 soroverflow_locked(struct socket *so)
426 SOCK_RECVBUF_LOCK_ASSERT(so);
428 if (so->so_options & SO_RERROR) {
429 so->so_rerror = ENOBUFS;
430 sorwakeup_locked(so);
432 SOCK_RECVBUF_UNLOCK(so);
434 SOCK_RECVBUF_UNLOCK_ASSERT(so);
438 soroverflow(struct socket *so)
441 SOCK_RECVBUF_LOCK(so);
442 soroverflow_locked(so);
443 SOCK_RECVBUF_UNLOCK_ASSERT(so);
447 * Wait for data to arrive at/drain from a socket buffer.
450 sbwait(struct socket *so, sb_which which)
454 SOCK_BUF_LOCK_ASSERT(so, which);
456 sb = sobuf(so, which);
457 sb->sb_flags |= SB_WAIT;
458 return (msleep_sbt(&sb->sb_acc, soeventmtx(so, which),
459 (sb->sb_flags & SB_NOINTR) ? PSOCK : PSOCK | PCATCH, "sbwait",
460 sb->sb_timeo, 0, 0));
464 * Wakeup processes waiting on a socket buffer. Do asynchronous notification
465 * via SIGIO if the socket has the SS_ASYNC flag set.
467 * Called with the socket buffer lock held; will release the lock by the end
468 * of the function. This allows the caller to acquire the socket buffer lock
469 * while testing for the need for various sorts of wakeup and hold it through
470 * to the point where it's no longer required. We currently hold the lock
471 * through calls out to other subsystems (with the exception of kqueue), and
472 * then release it to avoid lock order issues. It's not clear that's
475 static __always_inline void
476 sowakeup(struct socket *so, const sb_which which)
481 SOCK_BUF_LOCK_ASSERT(so, which);
483 sb = sobuf(so, which);
484 selwakeuppri(sb->sb_sel, PSOCK);
485 if (!SEL_WAITING(sb->sb_sel))
486 sb->sb_flags &= ~SB_SEL;
487 if (sb->sb_flags & SB_WAIT) {
488 sb->sb_flags &= ~SB_WAIT;
491 KNOTE_LOCKED(&sb->sb_sel->si_note, 0);
492 if (sb->sb_upcall != NULL) {
493 ret = sb->sb_upcall(so, sb->sb_upcallarg, M_NOWAIT);
494 if (ret == SU_ISCONNECTED) {
495 KASSERT(sb == &so->so_rcv,
496 ("SO_SND upcall returned SU_ISCONNECTED"));
497 soupcall_clear(so, SO_RCV);
501 if (sb->sb_flags & SB_AIO)
502 sowakeup_aio(so, which);
503 SOCK_BUF_UNLOCK(so, which);
504 if (ret == SU_ISCONNECTED)
506 if ((so->so_state & SS_ASYNC) && so->so_sigio != NULL)
507 pgsigio(&so->so_sigio, SIGIO, 0);
508 SOCK_BUF_UNLOCK_ASSERT(so, which);
512 * Do we need to notify the other side when I/O is possible?
514 static __always_inline bool
515 sb_notify(const struct sockbuf *sb)
517 return ((sb->sb_flags & (SB_WAIT | SB_SEL | SB_ASYNC |
518 SB_UPCALL | SB_AIO | SB_KNOTE)) != 0);
522 sorwakeup_locked(struct socket *so)
524 SOCK_RECVBUF_LOCK_ASSERT(so);
525 if (sb_notify(&so->so_rcv))
526 sowakeup(so, SO_RCV);
528 SOCK_RECVBUF_UNLOCK(so);
532 sowwakeup_locked(struct socket *so)
534 SOCK_SENDBUF_LOCK_ASSERT(so);
535 if (sb_notify(&so->so_snd))
536 sowakeup(so, SO_SND);
538 SOCK_SENDBUF_UNLOCK(so);
542 * Socket buffer (struct sockbuf) utility routines.
544 * Each socket contains two socket buffers: one for sending data and one for
545 * receiving data. Each buffer contains a queue of mbufs, information about
546 * the number of mbufs and amount of data in the queue, and other fields
547 * allowing select() statements and notification on data availability to be
550 * Data stored in a socket buffer is maintained as a list of records. Each
551 * record is a list of mbufs chained together with the m_next field. Records
552 * are chained together with the m_nextpkt field. The upper level routine
553 * soreceive() expects the following conventions to be observed when placing
554 * information in the receive buffer:
556 * 1. If the protocol requires each message be preceded by the sender's name,
557 * then a record containing that name must be present before any
558 * associated data (mbuf's must be of type MT_SONAME).
559 * 2. If the protocol supports the exchange of ``access rights'' (really just
560 * additional data associated with the message), and there are ``rights''
561 * to be received, then a record containing this data should be present
562 * (mbuf's must be of type MT_RIGHTS).
563 * 3. If a name or rights record exists, then it must be followed by a data
564 * record, perhaps of zero length.
566 * Before using a new socket structure it is first necessary to reserve
567 * buffer space to the socket, by calling sbreserve(). This should commit
568 * some of the available buffer space in the system buffer pool for the
569 * socket (currently, it does nothing but enforce limits). The space should
570 * be released by calling sbrelease() when the socket is destroyed.
573 soreserve(struct socket *so, u_long sndcc, u_long rcvcc)
575 struct thread *td = curthread;
577 SOCK_SENDBUF_LOCK(so);
578 SOCK_RECVBUF_LOCK(so);
579 if (sbreserve_locked(so, SO_SND, sndcc, td) == 0)
581 if (sbreserve_locked(so, SO_RCV, rcvcc, td) == 0)
583 if (so->so_rcv.sb_lowat == 0)
584 so->so_rcv.sb_lowat = 1;
585 if (so->so_snd.sb_lowat == 0)
586 so->so_snd.sb_lowat = MCLBYTES;
587 if (so->so_snd.sb_lowat > so->so_snd.sb_hiwat)
588 so->so_snd.sb_lowat = so->so_snd.sb_hiwat;
589 SOCK_RECVBUF_UNLOCK(so);
590 SOCK_SENDBUF_UNLOCK(so);
593 sbrelease_locked(so, SO_SND);
595 SOCK_RECVBUF_UNLOCK(so);
596 SOCK_SENDBUF_UNLOCK(so);
601 sysctl_handle_sb_max(SYSCTL_HANDLER_ARGS)
604 u_long tmp_sb_max = sb_max;
606 error = sysctl_handle_long(oidp, &tmp_sb_max, arg2, req);
607 if (error || !req->newptr)
609 if (tmp_sb_max < MSIZE + MCLBYTES)
612 sb_max_adj = (u_quad_t)sb_max * MCLBYTES / (MSIZE + MCLBYTES);
617 * Allot mbufs to a sockbuf. Attempt to scale mbmax so that mbcnt doesn't
618 * become limiting if buffering efficiency is near the normal case.
621 sbreserve_locked(struct socket *so, sb_which which, u_long cc,
624 struct sockbuf *sb = sobuf(so, which);
627 SOCK_BUF_LOCK_ASSERT(so, which);
630 * When a thread is passed, we take into account the thread's socket
631 * buffer size limit. The caller will generally pass curthread, but
632 * in the TCP input path, NULL will be passed to indicate that no
633 * appropriate thread resource limits are available. In that case,
634 * we don't apply a process limit.
639 sbsize_limit = lim_cur(td, RLIMIT_SBSIZE);
641 sbsize_limit = RLIM_INFINITY;
642 if (!chgsbsize(so->so_cred->cr_uidinfo, &sb->sb_hiwat, cc,
645 sb->sb_mbmax = min(cc * sb_efficiency, sb_max);
646 if (sb->sb_lowat > sb->sb_hiwat)
647 sb->sb_lowat = sb->sb_hiwat;
652 sbsetopt(struct socket *so, int cmd, u_long cc)
657 u_int *hiwat, *lowat;
662 if (SOLISTENING(so)) {
666 lowat = &so->sol_sbsnd_lowat;
667 hiwat = &so->sol_sbsnd_hiwat;
668 flags = &so->sol_sbsnd_flags;
672 lowat = &so->sol_sbrcv_lowat;
673 hiwat = &so->sol_sbrcv_hiwat;
674 flags = &so->sol_sbrcv_flags;
690 flags = &sb->sb_flags;
691 hiwat = &sb->sb_hiwat;
692 lowat = &sb->sb_lowat;
693 SOCK_BUF_LOCK(so, wh);
700 if (SOLISTENING(so)) {
701 if (cc > sb_max_adj) {
709 if (!sbreserve_locked(so, wh, cc, curthread))
713 *flags &= ~SB_AUTOSIZE;
718 * Make sure the low-water is never greater than the
721 *lowat = (cc > *hiwat) ? *hiwat : cc;
725 if (!SOLISTENING(so))
726 SOCK_BUF_UNLOCK(so, wh);
732 * Free mbufs held by a socket, and reserved mbuf space.
735 sbrelease_internal(struct socket *so, sb_which which)
737 struct sockbuf *sb = sobuf(so, which);
739 sbflush_internal(sb);
740 (void)chgsbsize(so->so_cred->cr_uidinfo, &sb->sb_hiwat, 0,
746 sbrelease_locked(struct socket *so, sb_which which)
749 SOCK_BUF_LOCK_ASSERT(so, which);
751 sbrelease_internal(so, which);
755 sbrelease(struct socket *so, sb_which which)
758 SOCK_BUF_LOCK(so, which);
759 sbrelease_locked(so, which);
760 SOCK_BUF_UNLOCK(so, which);
764 sbdestroy(struct socket *so, sb_which which)
767 struct sockbuf *sb = sobuf(so, which);
769 if (sb->sb_tls_info != NULL)
770 ktls_free(sb->sb_tls_info);
771 sb->sb_tls_info = NULL;
773 sbrelease_internal(so, which);
777 * Routines to add and remove data from an mbuf queue.
779 * The routines sbappend() or sbappendrecord() are normally called to append
780 * new mbufs to a socket buffer, after checking that adequate space is
781 * available, comparing the function sbspace() with the amount of data to be
782 * added. sbappendrecord() differs from sbappend() in that data supplied is
783 * treated as the beginning of a new record. To place a sender's address,
784 * optional access rights, and data in a socket receive buffer,
785 * sbappendaddr() should be used. To place access rights and data in a
786 * socket receive buffer, sbappendrights() should be used. In either case,
787 * the new data begins a new record. Note that unlike sbappend() and
788 * sbappendrecord(), these routines check for the caller that there will be
789 * enough space to store the data. Each fails if there is not enough space,
790 * or if it cannot find mbufs to store additional information in.
792 * Reliable protocols may use the socket send buffer to hold data awaiting
793 * acknowledgement. Data is normally copied from a socket send buffer in a
794 * protocol with m_copy for output to a peer, and then removing the data from
795 * the socket buffer with sbdrop() or sbdroprecord() when the data is
796 * acknowledged by the peer.
800 sblastrecordchk(struct sockbuf *sb, const char *file, int line)
802 struct mbuf *m = sb->sb_mb;
804 SOCKBUF_LOCK_ASSERT(sb);
806 while (m && m->m_nextpkt)
809 if (m != sb->sb_lastrecord) {
810 printf("%s: sb_mb %p sb_lastrecord %p last %p\n",
811 __func__, sb->sb_mb, sb->sb_lastrecord, m);
812 printf("packet chain:\n");
813 for (m = sb->sb_mb; m != NULL; m = m->m_nextpkt)
815 panic("%s from %s:%u", __func__, file, line);
820 sblastmbufchk(struct sockbuf *sb, const char *file, int line)
822 struct mbuf *m = sb->sb_mb;
825 SOCKBUF_LOCK_ASSERT(sb);
827 while (m && m->m_nextpkt)
830 while (m && m->m_next)
833 if (m != sb->sb_mbtail) {
834 printf("%s: sb_mb %p sb_mbtail %p last %p\n",
835 __func__, sb->sb_mb, sb->sb_mbtail, m);
836 printf("packet tree:\n");
837 for (m = sb->sb_mb; m != NULL; m = m->m_nextpkt) {
839 for (n = m; n != NULL; n = n->m_next)
843 panic("%s from %s:%u", __func__, file, line);
848 while (m && m->m_next)
851 if (m != sb->sb_mtlstail) {
852 printf("%s: sb_mtls %p sb_mtlstail %p last %p\n",
853 __func__, sb->sb_mtls, sb->sb_mtlstail, m);
854 printf("TLS packet tree:\n");
856 for (m = sb->sb_mtls; m != NULL; m = m->m_next) {
860 panic("%s from %s:%u", __func__, file, line);
864 #endif /* SOCKBUF_DEBUG */
866 #define SBLINKRECORD(sb, m0) do { \
867 SOCKBUF_LOCK_ASSERT(sb); \
868 if ((sb)->sb_lastrecord != NULL) \
869 (sb)->sb_lastrecord->m_nextpkt = (m0); \
871 (sb)->sb_mb = (m0); \
872 (sb)->sb_lastrecord = (m0); \
873 } while (/*CONSTCOND*/0)
876 * Append mbuf chain m to the last record in the socket buffer sb. The
877 * additional space associated the mbuf chain is recorded in sb. Empty mbufs
878 * are discarded and mbufs are compacted where possible.
881 sbappend_locked(struct sockbuf *sb, struct mbuf *m, int flags)
885 SOCKBUF_LOCK_ASSERT(sb);
889 sbm_clrprotoflags(m, flags);
896 if (n->m_flags & M_EOR) {
897 sbappendrecord_locked(sb, m); /* XXXXXX!!!! */
900 } while (n->m_next && (n = n->m_next));
903 * XXX Would like to simply use sb_mbtail here, but
904 * XXX I need to verify that I won't miss an EOR that
907 if ((n = sb->sb_lastrecord) != NULL) {
909 if (n->m_flags & M_EOR) {
910 sbappendrecord_locked(sb, m); /* XXXXXX!!!! */
913 } while (n->m_next && (n = n->m_next));
916 * If this is the first record in the socket buffer,
917 * it's also the last record.
919 sb->sb_lastrecord = m;
922 sbcompress(sb, m, n);
927 * Append mbuf chain m to the last record in the socket buffer sb. The
928 * additional space associated the mbuf chain is recorded in sb. Empty mbufs
929 * are discarded and mbufs are compacted where possible.
932 sbappend(struct sockbuf *sb, struct mbuf *m, int flags)
936 sbappend_locked(sb, m, flags);
942 * Append an mbuf containing encrypted TLS data. The data
943 * is marked M_NOTREADY until it has been decrypted and
944 * stored as a TLS record.
947 sbappend_ktls_rx(struct sockbuf *sb, struct mbuf *m)
953 /* Remove all packet headers and mbuf tags to get a pure data chain. */
956 for (n = m; n != NULL; n = n->m_next)
957 n->m_flags |= M_NOTREADY;
958 sbcompress_ktls_rx(sb, m, sb->sb_mtlstail);
964 * This version of sbappend() should only be used when the caller absolutely
965 * knows that there will never be more than one record in the socket buffer,
966 * that is, a stream protocol (such as TCP).
969 sbappendstream_locked(struct sockbuf *sb, struct mbuf *m, int flags)
971 SOCKBUF_LOCK_ASSERT(sb);
973 KASSERT(m->m_nextpkt == NULL,("sbappendstream 0"));
977 * Decrypted TLS records are appended as records via
978 * sbappendrecord(). TCP passes encrypted TLS records to this
979 * function which must be scheduled for decryption.
981 if (sb->sb_flags & SB_TLS_RX) {
982 sbappend_ktls_rx(sb, m);
987 KASSERT(sb->sb_mb == sb->sb_lastrecord,("sbappendstream 1"));
992 if (sb->sb_tls_info != NULL)
996 /* Remove all packet headers and mbuf tags to get a pure data chain. */
997 m_demote(m, 1, flags & PRUS_NOTREADY ? M_NOTREADY : 0);
999 sbcompress(sb, m, sb->sb_mbtail);
1001 sb->sb_lastrecord = sb->sb_mb;
1002 SBLASTRECORDCHK(sb);
1006 * This version of sbappend() should only be used when the caller absolutely
1007 * knows that there will never be more than one record in the socket buffer,
1008 * that is, a stream protocol (such as TCP).
1011 sbappendstream(struct sockbuf *sb, struct mbuf *m, int flags)
1015 sbappendstream_locked(sb, m, flags);
1019 #ifdef SOCKBUF_DEBUG
1021 sbcheck(struct sockbuf *sb, const char *file, int line)
1023 struct mbuf *m, *n, *fnrdy;
1024 u_long acc, ccc, mbcnt;
1029 SOCKBUF_LOCK_ASSERT(sb);
1031 acc = ccc = mbcnt = 0;
1034 for (m = sb->sb_mb; m; m = n) {
1036 for (; m; m = m->m_next) {
1037 if (m->m_len == 0) {
1038 printf("sb %p empty mbuf %p\n", sb, m);
1041 if ((m->m_flags & M_NOTREADY) && fnrdy == NULL) {
1042 if (m != sb->sb_fnrdy) {
1043 printf("sb %p: fnrdy %p != m %p\n",
1044 sb, sb->sb_fnrdy, m);
1050 if (!(m->m_flags & M_NOTAVAIL)) {
1051 printf("sb %p: fnrdy %p, m %p is avail\n",
1052 sb, sb->sb_fnrdy, m);
1059 if (m->m_flags & M_EXT) /*XXX*/ /* pretty sure this is bogus */
1060 mbcnt += m->m_ext.ext_size;
1065 * Account for mbufs "detached" by ktls_detach_record() while
1066 * they are decrypted by ktls_decrypt(). tlsdcc gives a count
1067 * of the detached bytes that are included in ccc. The mbufs
1068 * and clusters are not included in the socket buffer
1071 ccc += sb->sb_tlsdcc;
1074 for (m = sb->sb_mtls; m; m = m->m_next) {
1075 if (m->m_nextpkt != NULL) {
1076 printf("sb %p TLS mbuf %p with nextpkt\n", sb, m);
1079 if ((m->m_flags & M_NOTREADY) == 0) {
1080 printf("sb %p TLS mbuf %p ready\n", sb, m);
1086 if (m->m_flags & M_EXT) /*XXX*/ /* pretty sure this is bogus */
1087 mbcnt += m->m_ext.ext_size;
1090 if (sb->sb_tlscc != tlscc) {
1091 printf("tlscc %ld/%u dcc %u\n", tlscc, sb->sb_tlscc,
1096 if (acc != sb->sb_acc || ccc != sb->sb_ccc || mbcnt != sb->sb_mbcnt) {
1097 printf("acc %ld/%u ccc %ld/%u mbcnt %ld/%u\n",
1098 acc, sb->sb_acc, ccc, sb->sb_ccc, mbcnt, sb->sb_mbcnt);
1100 printf("tlscc %ld/%u dcc %u\n", tlscc, sb->sb_tlscc,
1107 panic("%s from %s:%u", __func__, file, line);
1112 * As above, except the mbuf chain begins a new record.
1115 sbappendrecord_locked(struct sockbuf *sb, struct mbuf *m0)
1119 SOCKBUF_LOCK_ASSERT(sb);
1123 m_clrprotoflags(m0);
1125 * Put the first mbuf on the queue. Note this permits zero length
1129 SBLASTRECORDCHK(sb);
1130 SBLINKRECORD(sb, m0);
1134 if (m && (m0->m_flags & M_EOR)) {
1135 m0->m_flags &= ~M_EOR;
1136 m->m_flags |= M_EOR;
1138 /* always call sbcompress() so it can do SBLASTMBUFCHK() */
1139 sbcompress(sb, m, m0);
1143 * As above, except the mbuf chain begins a new record.
1146 sbappendrecord(struct sockbuf *sb, struct mbuf *m0)
1150 sbappendrecord_locked(sb, m0);
1154 /* Helper routine that appends data, control, and address to a sockbuf. */
1156 sbappendaddr_locked_internal(struct sockbuf *sb, const struct sockaddr *asa,
1157 struct mbuf *m0, struct mbuf *control, struct mbuf *ctrl_last)
1159 struct mbuf *m, *n, *nlast;
1161 if (asa->sa_len > MLEN)
1164 m = m_get(M_NOWAIT, MT_SONAME);
1167 m->m_len = asa->sa_len;
1168 bcopy(asa, mtod(m, caddr_t), asa->sa_len);
1170 M_ASSERT_NO_SND_TAG(m0);
1171 m_clrprotoflags(m0);
1172 m_tag_delete_chain(m0, NULL);
1174 * Clear some persistent info from pkthdr.
1175 * We don't use m_demote(), because some netgraph consumers
1176 * expect M_PKTHDR presence.
1178 m0->m_pkthdr.rcvif = NULL;
1179 m0->m_pkthdr.flowid = 0;
1180 m0->m_pkthdr.csum_flags = 0;
1181 m0->m_pkthdr.fibnum = 0;
1182 m0->m_pkthdr.rsstype = 0;
1185 ctrl_last->m_next = m0; /* concatenate data to control */
1188 m->m_next = control;
1189 for (n = m; n->m_next != NULL; n = n->m_next)
1193 SBLINKRECORD(sb, m);
1195 sb->sb_mbtail = nlast;
1198 SBLASTRECORDCHK(sb);
1203 * Append address and data, and optionally, control (ancillary) data to the
1204 * receive queue of a socket. If present, m0 must include a packet header
1205 * with total length. Returns 0 if no space in sockbuf or insufficient
1209 sbappendaddr_locked(struct sockbuf *sb, const struct sockaddr *asa,
1210 struct mbuf *m0, struct mbuf *control)
1212 struct mbuf *ctrl_last;
1213 int space = asa->sa_len;
1215 SOCKBUF_LOCK_ASSERT(sb);
1217 if (m0 && (m0->m_flags & M_PKTHDR) == 0)
1218 panic("sbappendaddr_locked");
1220 space += m0->m_pkthdr.len;
1221 space += m_length(control, &ctrl_last);
1223 if (space > sbspace(sb))
1225 return (sbappendaddr_locked_internal(sb, asa, m0, control, ctrl_last));
1229 * Append address and data, and optionally, control (ancillary) data to the
1230 * receive queue of a socket. If present, m0 must include a packet header
1231 * with total length. Returns 0 if insufficient mbufs. Does not validate space
1232 * on the receiving sockbuf.
1235 sbappendaddr_nospacecheck_locked(struct sockbuf *sb, const struct sockaddr *asa,
1236 struct mbuf *m0, struct mbuf *control)
1238 struct mbuf *ctrl_last;
1240 SOCKBUF_LOCK_ASSERT(sb);
1242 ctrl_last = (control == NULL) ? NULL : m_last(control);
1243 return (sbappendaddr_locked_internal(sb, asa, m0, control, ctrl_last));
1247 * Append address and data, and optionally, control (ancillary) data to the
1248 * receive queue of a socket. If present, m0 must include a packet header
1249 * with total length. Returns 0 if no space in sockbuf or insufficient
1253 sbappendaddr(struct sockbuf *sb, const struct sockaddr *asa,
1254 struct mbuf *m0, struct mbuf *control)
1259 retval = sbappendaddr_locked(sb, asa, m0, control);
1265 sbappendcontrol_locked(struct sockbuf *sb, struct mbuf *m0,
1266 struct mbuf *control, int flags)
1268 struct mbuf *m, *mlast;
1270 sbm_clrprotoflags(m0, flags);
1271 m_last(control)->m_next = m0;
1273 SBLASTRECORDCHK(sb);
1275 for (m = control; m->m_next; m = m->m_next)
1279 SBLINKRECORD(sb, control);
1281 sb->sb_mbtail = mlast;
1284 SBLASTRECORDCHK(sb);
1288 sbappendcontrol(struct sockbuf *sb, struct mbuf *m0, struct mbuf *control,
1293 sbappendcontrol_locked(sb, m0, control, flags);
1298 * Append the data in mbuf chain (m) into the socket buffer sb following mbuf
1299 * (n). If (n) is NULL, the buffer is presumed empty.
1301 * When the data is compressed, mbufs in the chain may be handled in one of
1304 * (1) The mbuf may simply be dropped, if it contributes nothing (no data, no
1305 * record boundary, and no change in data type).
1307 * (2) The mbuf may be coalesced -- i.e., data in the mbuf may be copied into
1308 * an mbuf already in the socket buffer. This can occur if an
1309 * appropriate mbuf exists, there is room, both mbufs are not marked as
1310 * not ready, and no merging of data types will occur.
1312 * (3) The mbuf may be appended to the end of the existing mbuf chain.
1314 * If any of the new mbufs is marked as M_EOR, mark the last mbuf appended as
1318 sbcompress(struct sockbuf *sb, struct mbuf *m, struct mbuf *n)
1323 SOCKBUF_LOCK_ASSERT(sb);
1326 eor |= m->m_flags & M_EOR;
1327 if (m->m_len == 0 &&
1329 (((o = m->m_next) || (o = n)) &&
1330 o->m_type == m->m_type))) {
1331 if (sb->sb_lastrecord == m)
1332 sb->sb_lastrecord = m->m_next;
1336 if (n && (n->m_flags & M_EOR) == 0 &&
1338 ((sb->sb_flags & SB_NOCOALESCE) == 0) &&
1339 !(m->m_flags & M_NOTREADY) &&
1340 !(n->m_flags & (M_NOTREADY | M_EXTPG)) &&
1341 !mbuf_has_tls_session(m) &&
1342 !mbuf_has_tls_session(n) &&
1343 m->m_len <= MCLBYTES / 4 && /* XXX: Don't copy too much */
1344 m->m_len <= M_TRAILINGSPACE(n) &&
1345 n->m_type == m->m_type) {
1346 m_copydata(m, 0, m->m_len, mtodo(n, n->m_len));
1347 n->m_len += m->m_len;
1348 sb->sb_ccc += m->m_len;
1349 if (sb->sb_fnrdy == NULL)
1350 sb->sb_acc += m->m_len;
1351 if (m->m_type != MT_DATA && m->m_type != MT_OOBDATA)
1352 /* XXX: Probably don't need.*/
1353 sb->sb_ctl += m->m_len;
1357 if (m->m_len <= MLEN && (m->m_flags & M_EXTPG) &&
1358 (m->m_flags & M_NOTREADY) == 0 &&
1359 !mbuf_has_tls_session(m))
1360 (void)mb_unmapped_compress(m);
1368 m->m_flags &= ~M_EOR;
1373 KASSERT(n != NULL, ("sbcompress: eor && n == NULL"));
1381 * A version of sbcompress() for encrypted TLS RX mbufs. These mbufs
1382 * are appended to the 'sb_mtls' chain instead of 'sb_mb' and are also
1383 * a bit simpler (no EOR markers, always MT_DATA, etc.).
1386 sbcompress_ktls_rx(struct sockbuf *sb, struct mbuf *m, struct mbuf *n)
1389 SOCKBUF_LOCK_ASSERT(sb);
1392 KASSERT((m->m_flags & M_EOR) == 0,
1393 ("TLS RX mbuf %p with EOR", m));
1394 KASSERT(m->m_type == MT_DATA,
1395 ("TLS RX mbuf %p is not MT_DATA", m));
1396 KASSERT((m->m_flags & M_NOTREADY) != 0,
1397 ("TLS RX mbuf %p ready", m));
1398 KASSERT((m->m_flags & M_EXTPG) == 0,
1399 ("TLS RX mbuf %p unmapped", m));
1401 if (m->m_len == 0) {
1407 * Even though both 'n' and 'm' are NOTREADY, it's ok
1408 * to coalesce the data.
1412 ((sb->sb_flags & SB_NOCOALESCE) == 0) &&
1413 !(n->m_flags & (M_EXTPG)) &&
1414 m->m_len <= MCLBYTES / 4 && /* XXX: Don't copy too much */
1415 m->m_len <= M_TRAILINGSPACE(n)) {
1416 m_copydata(m, 0, m->m_len, mtodo(n, n->m_len));
1417 n->m_len += m->m_len;
1418 sb->sb_ccc += m->m_len;
1419 sb->sb_tlscc += m->m_len;
1427 sb->sb_mtlstail = m;
1428 sballoc_ktls_rx(sb, m);
1438 * Free all mbufs in a sockbuf. Check that all resources are reclaimed.
1441 sbflush_internal(struct sockbuf *sb)
1444 while (sb->sb_mbcnt || sb->sb_tlsdcc) {
1446 * Don't call sbcut(sb, 0) if the leading mbuf is non-empty:
1447 * we would loop forever. Panic instead.
1449 if (sb->sb_ccc == 0 && (sb->sb_mb == NULL || sb->sb_mb->m_len))
1451 m_freem(sbcut_internal(sb, (int)sb->sb_ccc));
1453 KASSERT(sb->sb_ccc == 0 && sb->sb_mb == 0 && sb->sb_mbcnt == 0,
1454 ("%s: ccc %u mb %p mbcnt %u", __func__,
1455 sb->sb_ccc, (void *)sb->sb_mb, sb->sb_mbcnt));
1459 sbflush_locked(struct sockbuf *sb)
1462 SOCKBUF_LOCK_ASSERT(sb);
1463 sbflush_internal(sb);
1467 sbflush(struct sockbuf *sb)
1476 * Cut data from (the front of) a sockbuf.
1478 static struct mbuf *
1479 sbcut_internal(struct sockbuf *sb, int len)
1481 struct mbuf *m, *next, *mfree;
1484 KASSERT(len >= 0, ("%s: len is %d but it is supposed to be >= 0",
1486 KASSERT(len <= sb->sb_ccc, ("%s: len: %d is > ccc: %u",
1487 __func__, len, sb->sb_ccc));
1489 next = (m = sb->sb_mb) ? m->m_nextpkt : 0;
1496 if (next == NULL && !is_tls) {
1497 if (sb->sb_tlsdcc != 0) {
1498 MPASS(len >= sb->sb_tlsdcc);
1499 len -= sb->sb_tlsdcc;
1500 sb->sb_ccc -= sb->sb_tlsdcc;
1509 KASSERT(next, ("%s: no next, len %d", __func__, len));
1511 next = m->m_nextpkt;
1513 if (m->m_len > len) {
1514 KASSERT(!(m->m_flags & M_NOTAVAIL),
1515 ("%s: m %p M_NOTAVAIL", __func__, m));
1520 if (sb->sb_sndptroff != 0)
1521 sb->sb_sndptroff -= len;
1522 if (m->m_type != MT_DATA && m->m_type != MT_OOBDATA)
1529 sbfree_ktls_rx(sb, m);
1534 * Do not put M_NOTREADY buffers to the free list, they
1535 * are referenced from outside.
1537 if (m->m_flags & M_NOTREADY && !is_tls)
1549 * Free any zero-length mbufs from the buffer.
1550 * For SOCK_DGRAM sockets such mbufs represent empty records.
1551 * XXX: For SOCK_STREAM sockets such mbufs can appear in the buffer,
1552 * when sosend_generic() needs to send only control data.
1554 while (m && m->m_len == 0) {
1568 sb->sb_mtlstail = NULL;
1573 m->m_nextpkt = next;
1577 * First part is an inline SB_EMPTY_FIXUP(). Second part makes sure
1578 * sb_lastrecord is up-to-date if we dropped part of the last record.
1582 sb->sb_mbtail = NULL;
1583 sb->sb_lastrecord = NULL;
1584 } else if (m->m_nextpkt == NULL) {
1585 sb->sb_lastrecord = m;
1592 * Drop data from (the front of) a sockbuf.
1595 sbdrop_locked(struct sockbuf *sb, int len)
1598 SOCKBUF_LOCK_ASSERT(sb);
1599 m_freem(sbcut_internal(sb, len));
1603 * Drop data from (the front of) a sockbuf,
1604 * and return it to caller.
1607 sbcut_locked(struct sockbuf *sb, int len)
1610 SOCKBUF_LOCK_ASSERT(sb);
1611 return (sbcut_internal(sb, len));
1615 sbdrop(struct sockbuf *sb, int len)
1620 mfree = sbcut_internal(sb, len);
1627 sbsndptr_noadv(struct sockbuf *sb, uint32_t off, uint32_t *moff)
1631 KASSERT(sb->sb_mb != NULL, ("%s: sb_mb is NULL", __func__));
1632 if (sb->sb_sndptr == NULL || sb->sb_sndptroff > off) {
1634 if (sb->sb_sndptr == NULL) {
1635 sb->sb_sndptr = sb->sb_mb;
1636 sb->sb_sndptroff = 0;
1641 off -= sb->sb_sndptroff;
1648 sbsndptr_adv(struct sockbuf *sb, struct mbuf *mb, uint32_t len)
1651 * A small copy was done, advance forward the sb_sbsndptr to cover
1656 if (mb != sb->sb_sndptr) {
1657 /* Did not copyout at the same mbuf */
1661 while (m && (len > 0)) {
1662 if (len >= m->m_len) {
1665 sb->sb_sndptroff += m->m_len;
1666 sb->sb_sndptr = m->m_next;
1676 * Return the first mbuf and the mbuf data offset for the provided
1677 * send offset without changing the "sb_sndptroff" field.
1680 sbsndmbuf(struct sockbuf *sb, u_int off, u_int *moff)
1684 KASSERT(sb->sb_mb != NULL, ("%s: sb_mb is NULL", __func__));
1687 * If the "off" is below the stored offset, which happens on
1688 * retransmits, just use "sb_mb":
1690 if (sb->sb_sndptr == NULL || sb->sb_sndptroff > off) {
1694 off -= sb->sb_sndptroff;
1696 while (off > 0 && m != NULL) {
1707 * Drop a record off the front of a sockbuf and move the next record to the
1711 sbdroprecord_locked(struct sockbuf *sb)
1715 SOCKBUF_LOCK_ASSERT(sb);
1719 sb->sb_mb = m->m_nextpkt;
1729 * Drop a record off the front of a sockbuf and move the next record to the
1733 sbdroprecord(struct sockbuf *sb)
1737 sbdroprecord_locked(sb);
1742 * Create a "control" mbuf containing the specified data with the specified
1743 * type for presentation on a socket buffer.
1746 sbcreatecontrol(const void *p, u_int size, int type, int level, int wait)
1751 MBUF_CHECKSLEEP(wait);
1753 if (wait == M_NOWAIT) {
1754 if (CMSG_SPACE(size) > MCLBYTES)
1757 KASSERT(CMSG_SPACE(size) <= MCLBYTES,
1758 ("%s: passed CMSG_SPACE(%u) > MCLBYTES", __func__, size));
1760 if (CMSG_SPACE(size) > MLEN)
1761 m = m_getcl(wait, MT_CONTROL, 0);
1763 m = m_get(wait, MT_CONTROL);
1767 KASSERT(CMSG_SPACE(size) <= M_TRAILINGSPACE(m),
1768 ("sbcreatecontrol: short mbuf"));
1770 * Don't leave the padding between the msg header and the
1771 * cmsg data and the padding after the cmsg data un-initialized.
1773 cp = mtod(m, struct cmsghdr *);
1774 bzero(cp, CMSG_SPACE(size));
1776 (void)memcpy(CMSG_DATA(cp), p, size);
1777 m->m_len = CMSG_SPACE(size);
1778 cp->cmsg_len = CMSG_LEN(size);
1779 cp->cmsg_level = level;
1780 cp->cmsg_type = type;
1785 * This does the same for socket buffers that sotoxsocket does for sockets:
1786 * generate an user-format data structure describing the socket buffer. Note
1787 * that the xsockbuf structure, since it is always embedded in a socket, does
1788 * not include a self pointer nor a length. We make this entry point public
1789 * in case some other mechanism needs it.
1792 sbtoxsockbuf(struct sockbuf *sb, struct xsockbuf *xsb)
1795 xsb->sb_cc = sb->sb_ccc;
1796 xsb->sb_hiwat = sb->sb_hiwat;
1797 xsb->sb_mbcnt = sb->sb_mbcnt;
1798 xsb->sb_mbmax = sb->sb_mbmax;
1799 xsb->sb_lowat = sb->sb_lowat;
1800 xsb->sb_flags = sb->sb_flags;
1801 xsb->sb_timeo = sb->sb_timeo;
1804 /* This takes the place of kern.maxsockbuf, which moved to kern.ipc. */
1806 SYSCTL_INT(_kern, KERN_DUMMY, dummy, CTLFLAG_RW | CTLFLAG_SKIP, &dummy, 0, "");
1807 SYSCTL_OID(_kern_ipc, KIPC_MAXSOCKBUF, maxsockbuf,
1808 CTLTYPE_ULONG | CTLFLAG_RW | CTLFLAG_MPSAFE, &sb_max, 0,
1809 sysctl_handle_sb_max, "LU",
1810 "Maximum socket buffer size");
1811 SYSCTL_ULONG(_kern_ipc, KIPC_SOCKBUF_WASTE, sockbuf_waste_factor, CTLFLAG_RW,
1812 &sb_efficiency, 0, "Socket buffer size waste factor");