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;
162 while ((n != NULL) && (n != end) && (m->m_flags & M_EOR) == 0 &&
164 (m->m_flags & M_EXTPG) == 0 &&
165 !mbuf_has_tls_session(n) &&
166 !mbuf_has_tls_session(m) &&
167 n->m_len <= MCLBYTES / 4 && /* XXX: Don't copy too much */
168 n->m_len <= M_TRAILINGSPACE(m) &&
169 m->m_type == n->m_type) {
170 KASSERT(sb->sb_lastrecord != n,
171 ("%s: merging start of record (%p) into previous mbuf (%p)",
173 m_copydata(n, 0, n->m_len, mtodo(m, m->m_len));
174 m->m_len += n->m_len;
175 m->m_next = n->m_next;
176 m->m_flags |= n->m_flags & M_EOR;
177 if (sb->sb_mbtail == n)
180 sb->sb_mbcnt -= MSIZE;
182 if (n->m_flags & M_EXT) {
183 sb->sb_mbcnt -= n->m_ext.ext_size;
195 * Mark ready "count" units of I/O starting with "m". Most mbufs
196 * count as a single unit of I/O except for M_EXTPG mbufs which
197 * are backed by multiple pages.
200 sbready(struct sockbuf *sb, struct mbuf *m0, int count)
205 SOCKBUF_LOCK_ASSERT(sb);
206 KASSERT(sb->sb_fnrdy != NULL, ("%s: sb %p NULL fnrdy", __func__, sb));
207 KASSERT(count > 0, ("%s: invalid count %d", __func__, count));
210 blocker = (sb->sb_fnrdy == m) ? M_BLOCKED : 0;
213 KASSERT(m->m_flags & M_NOTREADY,
214 ("%s: m %p !M_NOTREADY", __func__, m));
215 if ((m->m_flags & M_EXTPG) != 0 && m->m_epg_npgs != 0) {
216 if (count < m->m_epg_nrdy) {
217 m->m_epg_nrdy -= count;
221 count -= m->m_epg_nrdy;
226 m->m_flags &= ~(M_NOTREADY | blocker);
228 sb->sb_acc += m->m_len;
233 * If the first mbuf is still not fully ready because only
234 * some of its backing pages were readied, no further progress
238 MPASS(m->m_flags & M_NOTREADY);
239 return (EINPROGRESS);
243 sbready_compress(sb, m0, m);
244 return (EINPROGRESS);
247 /* This one was blocking all the queue. */
248 for (; m && (m->m_flags & M_NOTREADY) == 0; m = m->m_next) {
249 KASSERT(m->m_flags & M_BLOCKED,
250 ("%s: m %p !M_BLOCKED", __func__, m));
251 m->m_flags &= ~M_BLOCKED;
252 sb->sb_acc += m->m_len;
256 sbready_compress(sb, m0, m);
262 * Adjust sockbuf state reflecting allocation of m.
265 sballoc(struct sockbuf *sb, struct mbuf *m)
268 SOCKBUF_LOCK_ASSERT(sb);
270 sb->sb_ccc += m->m_len;
272 if (sb->sb_fnrdy == NULL) {
273 if (m->m_flags & M_NOTREADY)
276 sb->sb_acc += m->m_len;
278 m->m_flags |= M_BLOCKED;
280 if (m->m_type != MT_DATA && m->m_type != MT_OOBDATA)
281 sb->sb_ctl += m->m_len;
283 sb->sb_mbcnt += MSIZE;
286 if (m->m_flags & M_EXT) {
287 sb->sb_mbcnt += m->m_ext.ext_size;
293 * Adjust sockbuf state reflecting freeing of m.
296 sbfree(struct sockbuf *sb, struct mbuf *m)
299 #if 0 /* XXX: not yet: soclose() call path comes here w/o lock. */
300 SOCKBUF_LOCK_ASSERT(sb);
303 sb->sb_ccc -= m->m_len;
305 if (!(m->m_flags & M_NOTAVAIL))
306 sb->sb_acc -= m->m_len;
308 if (m == sb->sb_fnrdy) {
311 KASSERT(m->m_flags & M_NOTREADY,
312 ("%s: m %p !M_NOTREADY", __func__, m));
315 while (n != NULL && !(n->m_flags & M_NOTREADY)) {
316 n->m_flags &= ~M_BLOCKED;
317 sb->sb_acc += n->m_len;
323 if (m->m_type != MT_DATA && m->m_type != MT_OOBDATA)
324 sb->sb_ctl -= m->m_len;
326 sb->sb_mbcnt -= MSIZE;
328 if (m->m_flags & M_EXT) {
329 sb->sb_mbcnt -= m->m_ext.ext_size;
333 if (sb->sb_sndptr == m) {
334 sb->sb_sndptr = NULL;
335 sb->sb_sndptroff = 0;
337 if (sb->sb_sndptroff != 0)
338 sb->sb_sndptroff -= m->m_len;
343 * Similar to sballoc/sbfree but does not adjust state associated with
344 * the sb_mb chain such as sb_fnrdy or sb_sndptr*. Also assumes mbufs
348 sballoc_ktls_rx(struct sockbuf *sb, struct mbuf *m)
351 SOCKBUF_LOCK_ASSERT(sb);
353 sb->sb_ccc += m->m_len;
354 sb->sb_tlscc += m->m_len;
356 sb->sb_mbcnt += MSIZE;
359 if (m->m_flags & M_EXT) {
360 sb->sb_mbcnt += m->m_ext.ext_size;
366 sbfree_ktls_rx(struct sockbuf *sb, struct mbuf *m)
369 #if 0 /* XXX: not yet: soclose() call path comes here w/o lock. */
370 SOCKBUF_LOCK_ASSERT(sb);
373 sb->sb_ccc -= m->m_len;
374 sb->sb_tlscc -= m->m_len;
376 sb->sb_mbcnt -= MSIZE;
379 if (m->m_flags & M_EXT) {
380 sb->sb_mbcnt -= m->m_ext.ext_size;
387 * Socantsendmore indicates that no more data will be sent on the socket; it
388 * would normally be applied to a socket when the user informs the system
389 * that no more data is to be sent, by the protocol code (in case
390 * PRU_SHUTDOWN). Socantrcvmore indicates that no more data will be
391 * received, and will normally be applied to the socket by a protocol when it
392 * detects that the peer will send no more data. Data queued for reading in
393 * the socket may yet be read.
396 socantsendmore_locked(struct socket *so)
399 SOCK_SENDBUF_LOCK_ASSERT(so);
401 so->so_snd.sb_state |= SBS_CANTSENDMORE;
402 sowwakeup_locked(so);
403 SOCK_SENDBUF_UNLOCK_ASSERT(so);
407 socantsendmore(struct socket *so)
410 SOCK_SENDBUF_LOCK(so);
411 socantsendmore_locked(so);
412 SOCK_SENDBUF_UNLOCK_ASSERT(so);
416 socantrcvmore_locked(struct socket *so)
419 SOCK_RECVBUF_LOCK_ASSERT(so);
421 so->so_rcv.sb_state |= SBS_CANTRCVMORE;
423 if (so->so_rcv.sb_flags & SB_TLS_RX)
424 ktls_check_rx(&so->so_rcv);
426 sorwakeup_locked(so);
427 SOCK_RECVBUF_UNLOCK_ASSERT(so);
431 socantrcvmore(struct socket *so)
434 SOCK_RECVBUF_LOCK(so);
435 socantrcvmore_locked(so);
436 SOCK_RECVBUF_UNLOCK_ASSERT(so);
440 soroverflow_locked(struct socket *so)
443 SOCK_RECVBUF_LOCK_ASSERT(so);
445 if (so->so_options & SO_RERROR) {
446 so->so_rerror = ENOBUFS;
447 sorwakeup_locked(so);
449 SOCK_RECVBUF_UNLOCK(so);
451 SOCK_RECVBUF_UNLOCK_ASSERT(so);
455 soroverflow(struct socket *so)
458 SOCK_RECVBUF_LOCK(so);
459 soroverflow_locked(so);
460 SOCK_RECVBUF_UNLOCK_ASSERT(so);
464 * Wait for data to arrive at/drain from a socket buffer.
467 sbwait(struct socket *so, sb_which which)
471 SOCK_BUF_LOCK_ASSERT(so, which);
473 sb = sobuf(so, which);
474 sb->sb_flags |= SB_WAIT;
475 return (msleep_sbt(&sb->sb_acc, soeventmtx(so, which),
476 (sb->sb_flags & SB_NOINTR) ? PSOCK : PSOCK | PCATCH, "sbwait",
477 sb->sb_timeo, 0, 0));
481 * Wakeup processes waiting on a socket buffer. Do asynchronous notification
482 * via SIGIO if the socket has the SS_ASYNC flag set.
484 * Called with the socket buffer lock held; will release the lock by the end
485 * of the function. This allows the caller to acquire the socket buffer lock
486 * while testing for the need for various sorts of wakeup and hold it through
487 * to the point where it's no longer required. We currently hold the lock
488 * through calls out to other subsystems (with the exception of kqueue), and
489 * then release it to avoid lock order issues. It's not clear that's
492 static __always_inline void
493 sowakeup(struct socket *so, const sb_which which)
498 SOCK_BUF_LOCK_ASSERT(so, which);
500 sb = sobuf(so, which);
501 selwakeuppri(sb->sb_sel, PSOCK);
502 if (!SEL_WAITING(sb->sb_sel))
503 sb->sb_flags &= ~SB_SEL;
504 if (sb->sb_flags & SB_WAIT) {
505 sb->sb_flags &= ~SB_WAIT;
508 KNOTE_LOCKED(&sb->sb_sel->si_note, 0);
509 if (sb->sb_upcall != NULL) {
510 ret = sb->sb_upcall(so, sb->sb_upcallarg, M_NOWAIT);
511 if (ret == SU_ISCONNECTED) {
512 KASSERT(sb == &so->so_rcv,
513 ("SO_SND upcall returned SU_ISCONNECTED"));
514 soupcall_clear(so, SO_RCV);
518 if (sb->sb_flags & SB_AIO)
519 sowakeup_aio(so, which);
520 SOCK_BUF_UNLOCK(so, which);
521 if (ret == SU_ISCONNECTED)
523 if ((so->so_state & SS_ASYNC) && so->so_sigio != NULL)
524 pgsigio(&so->so_sigio, SIGIO, 0);
525 SOCK_BUF_UNLOCK_ASSERT(so, which);
529 * Do we need to notify the other side when I/O is possible?
531 static __always_inline bool
532 sb_notify(const struct sockbuf *sb)
534 return ((sb->sb_flags & (SB_WAIT | SB_SEL | SB_ASYNC |
535 SB_UPCALL | SB_AIO | SB_KNOTE)) != 0);
539 sorwakeup_locked(struct socket *so)
541 SOCK_RECVBUF_LOCK_ASSERT(so);
542 if (sb_notify(&so->so_rcv))
543 sowakeup(so, SO_RCV);
545 SOCK_RECVBUF_UNLOCK(so);
549 sowwakeup_locked(struct socket *so)
551 SOCK_SENDBUF_LOCK_ASSERT(so);
552 if (sb_notify(&so->so_snd))
553 sowakeup(so, SO_SND);
555 SOCK_SENDBUF_UNLOCK(so);
559 * Socket buffer (struct sockbuf) utility routines.
561 * Each socket contains two socket buffers: one for sending data and one for
562 * receiving data. Each buffer contains a queue of mbufs, information about
563 * the number of mbufs and amount of data in the queue, and other fields
564 * allowing select() statements and notification on data availability to be
567 * Data stored in a socket buffer is maintained as a list of records. Each
568 * record is a list of mbufs chained together with the m_next field. Records
569 * are chained together with the m_nextpkt field. The upper level routine
570 * soreceive() expects the following conventions to be observed when placing
571 * information in the receive buffer:
573 * 1. If the protocol requires each message be preceded by the sender's name,
574 * then a record containing that name must be present before any
575 * associated data (mbuf's must be of type MT_SONAME).
576 * 2. If the protocol supports the exchange of ``access rights'' (really just
577 * additional data associated with the message), and there are ``rights''
578 * to be received, then a record containing this data should be present
579 * (mbuf's must be of type MT_RIGHTS).
580 * 3. If a name or rights record exists, then it must be followed by a data
581 * record, perhaps of zero length.
583 * Before using a new socket structure it is first necessary to reserve
584 * buffer space to the socket, by calling sbreserve(). This should commit
585 * some of the available buffer space in the system buffer pool for the
586 * socket (currently, it does nothing but enforce limits). The space should
587 * be released by calling sbrelease() when the socket is destroyed.
590 soreserve(struct socket *so, u_long sndcc, u_long rcvcc)
592 struct thread *td = curthread;
594 SOCK_SENDBUF_LOCK(so);
595 SOCK_RECVBUF_LOCK(so);
596 if (sbreserve_locked(so, SO_SND, sndcc, td) == 0)
598 if (sbreserve_locked(so, SO_RCV, rcvcc, td) == 0)
600 if (so->so_rcv.sb_lowat == 0)
601 so->so_rcv.sb_lowat = 1;
602 if (so->so_snd.sb_lowat == 0)
603 so->so_snd.sb_lowat = MCLBYTES;
604 if (so->so_snd.sb_lowat > so->so_snd.sb_hiwat)
605 so->so_snd.sb_lowat = so->so_snd.sb_hiwat;
606 SOCK_RECVBUF_UNLOCK(so);
607 SOCK_SENDBUF_UNLOCK(so);
610 sbrelease_locked(so, SO_SND);
612 SOCK_RECVBUF_UNLOCK(so);
613 SOCK_SENDBUF_UNLOCK(so);
618 sysctl_handle_sb_max(SYSCTL_HANDLER_ARGS)
621 u_long tmp_sb_max = sb_max;
623 error = sysctl_handle_long(oidp, &tmp_sb_max, arg2, req);
624 if (error || !req->newptr)
626 if (tmp_sb_max < MSIZE + MCLBYTES)
629 sb_max_adj = (u_quad_t)sb_max * MCLBYTES / (MSIZE + MCLBYTES);
634 * Allot mbufs to a sockbuf. Attempt to scale mbmax so that mbcnt doesn't
635 * become limiting if buffering efficiency is near the normal case.
638 sbreserve_locked(struct socket *so, sb_which which, u_long cc,
641 struct sockbuf *sb = sobuf(so, which);
644 SOCK_BUF_LOCK_ASSERT(so, which);
647 * When a thread is passed, we take into account the thread's socket
648 * buffer size limit. The caller will generally pass curthread, but
649 * in the TCP input path, NULL will be passed to indicate that no
650 * appropriate thread resource limits are available. In that case,
651 * we don't apply a process limit.
656 sbsize_limit = lim_cur(td, RLIMIT_SBSIZE);
658 sbsize_limit = RLIM_INFINITY;
659 if (!chgsbsize(so->so_cred->cr_uidinfo, &sb->sb_hiwat, cc,
662 sb->sb_mbmax = min(cc * sb_efficiency, sb_max);
663 if (sb->sb_lowat > sb->sb_hiwat)
664 sb->sb_lowat = sb->sb_hiwat;
669 sbsetopt(struct socket *so, int cmd, u_long cc)
674 u_int *hiwat, *lowat;
679 if (SOLISTENING(so)) {
683 lowat = &so->sol_sbsnd_lowat;
684 hiwat = &so->sol_sbsnd_hiwat;
685 flags = &so->sol_sbsnd_flags;
689 lowat = &so->sol_sbrcv_lowat;
690 hiwat = &so->sol_sbrcv_hiwat;
691 flags = &so->sol_sbrcv_flags;
707 flags = &sb->sb_flags;
708 hiwat = &sb->sb_hiwat;
709 lowat = &sb->sb_lowat;
710 SOCK_BUF_LOCK(so, wh);
717 if (SOLISTENING(so)) {
718 if (cc > sb_max_adj) {
726 if (!sbreserve_locked(so, wh, cc, curthread))
730 *flags &= ~SB_AUTOSIZE;
735 * Make sure the low-water is never greater than the
738 *lowat = (cc > *hiwat) ? *hiwat : cc;
742 if (!SOLISTENING(so))
743 SOCK_BUF_UNLOCK(so, wh);
749 * Free mbufs held by a socket, and reserved mbuf space.
752 sbrelease_internal(struct socket *so, sb_which which)
754 struct sockbuf *sb = sobuf(so, which);
756 sbflush_internal(sb);
757 (void)chgsbsize(so->so_cred->cr_uidinfo, &sb->sb_hiwat, 0,
763 sbrelease_locked(struct socket *so, sb_which which)
766 SOCK_BUF_LOCK_ASSERT(so, which);
768 sbrelease_internal(so, which);
772 sbrelease(struct socket *so, sb_which which)
775 SOCK_BUF_LOCK(so, which);
776 sbrelease_locked(so, which);
777 SOCK_BUF_UNLOCK(so, which);
781 sbdestroy(struct socket *so, sb_which which)
784 struct sockbuf *sb = sobuf(so, which);
786 if (sb->sb_tls_info != NULL)
787 ktls_free(sb->sb_tls_info);
788 sb->sb_tls_info = NULL;
790 sbrelease_internal(so, which);
794 * Routines to add and remove data from an mbuf queue.
796 * The routines sbappend() or sbappendrecord() are normally called to append
797 * new mbufs to a socket buffer, after checking that adequate space is
798 * available, comparing the function sbspace() with the amount of data to be
799 * added. sbappendrecord() differs from sbappend() in that data supplied is
800 * treated as the beginning of a new record. To place a sender's address,
801 * optional access rights, and data in a socket receive buffer,
802 * sbappendaddr() should be used. To place access rights and data in a
803 * socket receive buffer, sbappendrights() should be used. In either case,
804 * the new data begins a new record. Note that unlike sbappend() and
805 * sbappendrecord(), these routines check for the caller that there will be
806 * enough space to store the data. Each fails if there is not enough space,
807 * or if it cannot find mbufs to store additional information in.
809 * Reliable protocols may use the socket send buffer to hold data awaiting
810 * acknowledgement. Data is normally copied from a socket send buffer in a
811 * protocol with m_copy for output to a peer, and then removing the data from
812 * the socket buffer with sbdrop() or sbdroprecord() when the data is
813 * acknowledged by the peer.
817 sblastrecordchk(struct sockbuf *sb, const char *file, int line)
819 struct mbuf *m = sb->sb_mb;
821 SOCKBUF_LOCK_ASSERT(sb);
823 while (m && m->m_nextpkt)
826 if (m != sb->sb_lastrecord) {
827 printf("%s: sb_mb %p sb_lastrecord %p last %p\n",
828 __func__, sb->sb_mb, sb->sb_lastrecord, m);
829 printf("packet chain:\n");
830 for (m = sb->sb_mb; m != NULL; m = m->m_nextpkt)
832 panic("%s from %s:%u", __func__, file, line);
837 sblastmbufchk(struct sockbuf *sb, const char *file, int line)
839 struct mbuf *m = sb->sb_mb;
842 SOCKBUF_LOCK_ASSERT(sb);
844 while (m && m->m_nextpkt)
847 while (m && m->m_next)
850 if (m != sb->sb_mbtail) {
851 printf("%s: sb_mb %p sb_mbtail %p last %p\n",
852 __func__, sb->sb_mb, sb->sb_mbtail, m);
853 printf("packet tree:\n");
854 for (m = sb->sb_mb; m != NULL; m = m->m_nextpkt) {
856 for (n = m; n != NULL; n = n->m_next)
860 panic("%s from %s:%u", __func__, file, line);
865 while (m && m->m_next)
868 if (m != sb->sb_mtlstail) {
869 printf("%s: sb_mtls %p sb_mtlstail %p last %p\n",
870 __func__, sb->sb_mtls, sb->sb_mtlstail, m);
871 printf("TLS packet tree:\n");
873 for (m = sb->sb_mtls; m != NULL; m = m->m_next) {
877 panic("%s from %s:%u", __func__, file, line);
881 #endif /* SOCKBUF_DEBUG */
883 #define SBLINKRECORD(sb, m0) do { \
884 SOCKBUF_LOCK_ASSERT(sb); \
885 if ((sb)->sb_lastrecord != NULL) \
886 (sb)->sb_lastrecord->m_nextpkt = (m0); \
888 (sb)->sb_mb = (m0); \
889 (sb)->sb_lastrecord = (m0); \
890 } while (/*CONSTCOND*/0)
893 * Append mbuf chain m to the last record in the socket buffer sb. The
894 * additional space associated the mbuf chain is recorded in sb. Empty mbufs
895 * are discarded and mbufs are compacted where possible.
898 sbappend_locked(struct sockbuf *sb, struct mbuf *m, int flags)
902 SOCKBUF_LOCK_ASSERT(sb);
906 sbm_clrprotoflags(m, flags);
913 if (n->m_flags & M_EOR) {
914 sbappendrecord_locked(sb, m); /* XXXXXX!!!! */
917 } while (n->m_next && (n = n->m_next));
920 * XXX Would like to simply use sb_mbtail here, but
921 * XXX I need to verify that I won't miss an EOR that
924 if ((n = sb->sb_lastrecord) != NULL) {
926 if (n->m_flags & M_EOR) {
927 sbappendrecord_locked(sb, m); /* XXXXXX!!!! */
930 } while (n->m_next && (n = n->m_next));
933 * If this is the first record in the socket buffer,
934 * it's also the last record.
936 sb->sb_lastrecord = m;
939 sbcompress(sb, m, n);
944 * Append mbuf chain m to the last record in the socket buffer sb. The
945 * additional space associated the mbuf chain is recorded in sb. Empty mbufs
946 * are discarded and mbufs are compacted where possible.
949 sbappend(struct sockbuf *sb, struct mbuf *m, int flags)
953 sbappend_locked(sb, m, flags);
959 * Append an mbuf containing encrypted TLS data. The data
960 * is marked M_NOTREADY until it has been decrypted and
961 * stored as a TLS record.
964 sbappend_ktls_rx(struct sockbuf *sb, struct mbuf *m)
970 /* Remove all packet headers and mbuf tags to get a pure data chain. */
973 for (n = m; n != NULL; n = n->m_next)
974 n->m_flags |= M_NOTREADY;
975 sbcompress_ktls_rx(sb, m, sb->sb_mtlstail);
981 * This version of sbappend() should only be used when the caller absolutely
982 * knows that there will never be more than one record in the socket buffer,
983 * that is, a stream protocol (such as TCP).
986 sbappendstream_locked(struct sockbuf *sb, struct mbuf *m, int flags)
988 SOCKBUF_LOCK_ASSERT(sb);
990 KASSERT(m->m_nextpkt == NULL,("sbappendstream 0"));
994 * Decrypted TLS records are appended as records via
995 * sbappendrecord(). TCP passes encrypted TLS records to this
996 * function which must be scheduled for decryption.
998 if (sb->sb_flags & SB_TLS_RX) {
999 sbappend_ktls_rx(sb, m);
1004 KASSERT(sb->sb_mb == sb->sb_lastrecord,("sbappendstream 1"));
1009 if (sb->sb_tls_info != NULL)
1013 /* Remove all packet headers and mbuf tags to get a pure data chain. */
1014 m_demote(m, 1, flags & PRUS_NOTREADY ? M_NOTREADY : 0);
1016 sbcompress(sb, m, sb->sb_mbtail);
1018 sb->sb_lastrecord = sb->sb_mb;
1019 SBLASTRECORDCHK(sb);
1023 * This version of sbappend() should only be used when the caller absolutely
1024 * knows that there will never be more than one record in the socket buffer,
1025 * that is, a stream protocol (such as TCP).
1028 sbappendstream(struct sockbuf *sb, struct mbuf *m, int flags)
1032 sbappendstream_locked(sb, m, flags);
1036 #ifdef SOCKBUF_DEBUG
1038 sbcheck(struct sockbuf *sb, const char *file, int line)
1040 struct mbuf *m, *n, *fnrdy;
1041 u_long acc, ccc, mbcnt;
1046 SOCKBUF_LOCK_ASSERT(sb);
1048 acc = ccc = mbcnt = 0;
1051 for (m = sb->sb_mb; m; m = n) {
1053 for (; m; m = m->m_next) {
1054 if (m->m_len == 0) {
1055 printf("sb %p empty mbuf %p\n", sb, m);
1058 if ((m->m_flags & M_NOTREADY) && fnrdy == NULL) {
1059 if (m != sb->sb_fnrdy) {
1060 printf("sb %p: fnrdy %p != m %p\n",
1061 sb, sb->sb_fnrdy, m);
1067 if (!(m->m_flags & M_NOTAVAIL)) {
1068 printf("sb %p: fnrdy %p, m %p is avail\n",
1069 sb, sb->sb_fnrdy, m);
1076 if (m->m_flags & M_EXT) /*XXX*/ /* pretty sure this is bogus */
1077 mbcnt += m->m_ext.ext_size;
1082 * Account for mbufs "detached" by ktls_detach_record() while
1083 * they are decrypted by ktls_decrypt(). tlsdcc gives a count
1084 * of the detached bytes that are included in ccc. The mbufs
1085 * and clusters are not included in the socket buffer
1088 ccc += sb->sb_tlsdcc;
1091 for (m = sb->sb_mtls; m; m = m->m_next) {
1092 if (m->m_nextpkt != NULL) {
1093 printf("sb %p TLS mbuf %p with nextpkt\n", sb, m);
1096 if ((m->m_flags & M_NOTREADY) == 0) {
1097 printf("sb %p TLS mbuf %p ready\n", sb, m);
1103 if (m->m_flags & M_EXT) /*XXX*/ /* pretty sure this is bogus */
1104 mbcnt += m->m_ext.ext_size;
1107 if (sb->sb_tlscc != tlscc) {
1108 printf("tlscc %ld/%u dcc %u\n", tlscc, sb->sb_tlscc,
1113 if (acc != sb->sb_acc || ccc != sb->sb_ccc || mbcnt != sb->sb_mbcnt) {
1114 printf("acc %ld/%u ccc %ld/%u mbcnt %ld/%u\n",
1115 acc, sb->sb_acc, ccc, sb->sb_ccc, mbcnt, sb->sb_mbcnt);
1117 printf("tlscc %ld/%u dcc %u\n", tlscc, sb->sb_tlscc,
1124 panic("%s from %s:%u", __func__, file, line);
1129 * As above, except the mbuf chain begins a new record.
1132 sbappendrecord_locked(struct sockbuf *sb, struct mbuf *m0)
1136 SOCKBUF_LOCK_ASSERT(sb);
1140 m_clrprotoflags(m0);
1142 * Put the first mbuf on the queue. Note this permits zero length
1146 SBLASTRECORDCHK(sb);
1147 SBLINKRECORD(sb, m0);
1151 if (m && (m0->m_flags & M_EOR)) {
1152 m0->m_flags &= ~M_EOR;
1153 m->m_flags |= M_EOR;
1155 /* always call sbcompress() so it can do SBLASTMBUFCHK() */
1156 sbcompress(sb, m, m0);
1160 * As above, except the mbuf chain begins a new record.
1163 sbappendrecord(struct sockbuf *sb, struct mbuf *m0)
1167 sbappendrecord_locked(sb, m0);
1171 /* Helper routine that appends data, control, and address to a sockbuf. */
1173 sbappendaddr_locked_internal(struct sockbuf *sb, const struct sockaddr *asa,
1174 struct mbuf *m0, struct mbuf *control, struct mbuf *ctrl_last)
1176 struct mbuf *m, *n, *nlast;
1178 if (asa->sa_len > MLEN)
1181 m = m_get(M_NOWAIT, MT_SONAME);
1184 m->m_len = asa->sa_len;
1185 bcopy(asa, mtod(m, caddr_t), asa->sa_len);
1187 M_ASSERT_NO_SND_TAG(m0);
1188 m_clrprotoflags(m0);
1189 m_tag_delete_chain(m0, NULL);
1191 * Clear some persistent info from pkthdr.
1192 * We don't use m_demote(), because some netgraph consumers
1193 * expect M_PKTHDR presence.
1195 m0->m_pkthdr.rcvif = NULL;
1196 m0->m_pkthdr.flowid = 0;
1197 m0->m_pkthdr.csum_flags = 0;
1198 m0->m_pkthdr.fibnum = 0;
1199 m0->m_pkthdr.rsstype = 0;
1202 ctrl_last->m_next = m0; /* concatenate data to control */
1205 m->m_next = control;
1206 for (n = m; n->m_next != NULL; n = n->m_next)
1210 SBLINKRECORD(sb, m);
1212 sb->sb_mbtail = nlast;
1215 SBLASTRECORDCHK(sb);
1220 * Append address and data, and optionally, control (ancillary) data to the
1221 * receive queue of a socket. If present, m0 must include a packet header
1222 * with total length. Returns 0 if no space in sockbuf or insufficient
1226 sbappendaddr_locked(struct sockbuf *sb, const struct sockaddr *asa,
1227 struct mbuf *m0, struct mbuf *control)
1229 struct mbuf *ctrl_last;
1230 int space = asa->sa_len;
1232 SOCKBUF_LOCK_ASSERT(sb);
1234 if (m0 && (m0->m_flags & M_PKTHDR) == 0)
1235 panic("sbappendaddr_locked");
1237 space += m0->m_pkthdr.len;
1238 space += m_length(control, &ctrl_last);
1240 if (space > sbspace(sb))
1242 return (sbappendaddr_locked_internal(sb, asa, m0, control, ctrl_last));
1246 * Append address and data, and optionally, control (ancillary) data to the
1247 * receive queue of a socket. If present, m0 must include a packet header
1248 * with total length. Returns 0 if insufficient mbufs. Does not validate space
1249 * on the receiving sockbuf.
1252 sbappendaddr_nospacecheck_locked(struct sockbuf *sb, const struct sockaddr *asa,
1253 struct mbuf *m0, struct mbuf *control)
1255 struct mbuf *ctrl_last;
1257 SOCKBUF_LOCK_ASSERT(sb);
1259 ctrl_last = (control == NULL) ? NULL : m_last(control);
1260 return (sbappendaddr_locked_internal(sb, asa, m0, control, ctrl_last));
1264 * Append address and data, and optionally, control (ancillary) data to the
1265 * receive queue of a socket. If present, m0 must include a packet header
1266 * with total length. Returns 0 if no space in sockbuf or insufficient
1270 sbappendaddr(struct sockbuf *sb, const struct sockaddr *asa,
1271 struct mbuf *m0, struct mbuf *control)
1276 retval = sbappendaddr_locked(sb, asa, m0, control);
1282 sbappendcontrol_locked(struct sockbuf *sb, struct mbuf *m0,
1283 struct mbuf *control, int flags)
1285 struct mbuf *m, *mlast;
1287 sbm_clrprotoflags(m0, flags);
1288 m_last(control)->m_next = m0;
1290 SBLASTRECORDCHK(sb);
1292 for (m = control; m->m_next; m = m->m_next)
1296 SBLINKRECORD(sb, control);
1298 sb->sb_mbtail = mlast;
1301 SBLASTRECORDCHK(sb);
1305 sbappendcontrol(struct sockbuf *sb, struct mbuf *m0, struct mbuf *control,
1310 sbappendcontrol_locked(sb, m0, control, flags);
1315 * Append the data in mbuf chain (m) into the socket buffer sb following mbuf
1316 * (n). If (n) is NULL, the buffer is presumed empty.
1318 * When the data is compressed, mbufs in the chain may be handled in one of
1321 * (1) The mbuf may simply be dropped, if it contributes nothing (no data, no
1322 * record boundary, and no change in data type).
1324 * (2) The mbuf may be coalesced -- i.e., data in the mbuf may be copied into
1325 * an mbuf already in the socket buffer. This can occur if an
1326 * appropriate mbuf exists, there is room, both mbufs are not marked as
1327 * not ready, and no merging of data types will occur.
1329 * (3) The mbuf may be appended to the end of the existing mbuf chain.
1331 * If any of the new mbufs is marked as M_EOR, mark the last mbuf appended as
1335 sbcompress(struct sockbuf *sb, struct mbuf *m, struct mbuf *n)
1340 SOCKBUF_LOCK_ASSERT(sb);
1343 eor |= m->m_flags & M_EOR;
1344 if (m->m_len == 0 &&
1346 (((o = m->m_next) || (o = n)) &&
1347 o->m_type == m->m_type))) {
1348 if (sb->sb_lastrecord == m)
1349 sb->sb_lastrecord = m->m_next;
1353 if (n && (n->m_flags & M_EOR) == 0 &&
1355 ((sb->sb_flags & SB_NOCOALESCE) == 0) &&
1356 !(m->m_flags & M_NOTREADY) &&
1357 !(n->m_flags & (M_NOTREADY | M_EXTPG)) &&
1358 !mbuf_has_tls_session(m) &&
1359 !mbuf_has_tls_session(n) &&
1360 m->m_len <= MCLBYTES / 4 && /* XXX: Don't copy too much */
1361 m->m_len <= M_TRAILINGSPACE(n) &&
1362 n->m_type == m->m_type) {
1363 m_copydata(m, 0, m->m_len, mtodo(n, n->m_len));
1364 n->m_len += m->m_len;
1365 sb->sb_ccc += m->m_len;
1366 if (sb->sb_fnrdy == NULL)
1367 sb->sb_acc += m->m_len;
1368 if (m->m_type != MT_DATA && m->m_type != MT_OOBDATA)
1369 /* XXX: Probably don't need.*/
1370 sb->sb_ctl += m->m_len;
1374 if (m->m_len <= MLEN && (m->m_flags & M_EXTPG) &&
1375 (m->m_flags & M_NOTREADY) == 0 &&
1376 !mbuf_has_tls_session(m))
1377 (void)mb_unmapped_compress(m);
1385 m->m_flags &= ~M_EOR;
1390 KASSERT(n != NULL, ("sbcompress: eor && n == NULL"));
1398 * A version of sbcompress() for encrypted TLS RX mbufs. These mbufs
1399 * are appended to the 'sb_mtls' chain instead of 'sb_mb' and are also
1400 * a bit simpler (no EOR markers, always MT_DATA, etc.).
1403 sbcompress_ktls_rx(struct sockbuf *sb, struct mbuf *m, struct mbuf *n)
1406 SOCKBUF_LOCK_ASSERT(sb);
1409 KASSERT((m->m_flags & M_EOR) == 0,
1410 ("TLS RX mbuf %p with EOR", m));
1411 KASSERT(m->m_type == MT_DATA,
1412 ("TLS RX mbuf %p is not MT_DATA", m));
1413 KASSERT((m->m_flags & M_NOTREADY) != 0,
1414 ("TLS RX mbuf %p ready", m));
1415 KASSERT((m->m_flags & M_EXTPG) == 0,
1416 ("TLS RX mbuf %p unmapped", m));
1418 if (m->m_len == 0) {
1424 * Even though both 'n' and 'm' are NOTREADY, it's ok
1425 * to coalesce the data.
1429 ((sb->sb_flags & SB_NOCOALESCE) == 0) &&
1430 !(n->m_flags & (M_EXTPG)) &&
1431 m->m_len <= MCLBYTES / 4 && /* XXX: Don't copy too much */
1432 m->m_len <= M_TRAILINGSPACE(n)) {
1433 m_copydata(m, 0, m->m_len, mtodo(n, n->m_len));
1434 n->m_len += m->m_len;
1435 sb->sb_ccc += m->m_len;
1436 sb->sb_tlscc += m->m_len;
1444 sb->sb_mtlstail = m;
1445 sballoc_ktls_rx(sb, m);
1455 * Free all mbufs in a sockbuf. Check that all resources are reclaimed.
1458 sbflush_internal(struct sockbuf *sb)
1461 while (sb->sb_mbcnt || sb->sb_tlsdcc) {
1463 * Don't call sbcut(sb, 0) if the leading mbuf is non-empty:
1464 * we would loop forever. Panic instead.
1466 if (sb->sb_ccc == 0 && (sb->sb_mb == NULL || sb->sb_mb->m_len))
1468 m_freem(sbcut_internal(sb, (int)sb->sb_ccc));
1470 KASSERT(sb->sb_ccc == 0 && sb->sb_mb == 0 && sb->sb_mbcnt == 0,
1471 ("%s: ccc %u mb %p mbcnt %u", __func__,
1472 sb->sb_ccc, (void *)sb->sb_mb, sb->sb_mbcnt));
1476 sbflush_locked(struct sockbuf *sb)
1479 SOCKBUF_LOCK_ASSERT(sb);
1480 sbflush_internal(sb);
1484 sbflush(struct sockbuf *sb)
1493 * Cut data from (the front of) a sockbuf.
1495 static struct mbuf *
1496 sbcut_internal(struct sockbuf *sb, int len)
1498 struct mbuf *m, *next, *mfree;
1501 KASSERT(len >= 0, ("%s: len is %d but it is supposed to be >= 0",
1503 KASSERT(len <= sb->sb_ccc, ("%s: len: %d is > ccc: %u",
1504 __func__, len, sb->sb_ccc));
1506 next = (m = sb->sb_mb) ? m->m_nextpkt : 0;
1513 if (next == NULL && !is_tls) {
1514 if (sb->sb_tlsdcc != 0) {
1515 MPASS(len >= sb->sb_tlsdcc);
1516 len -= sb->sb_tlsdcc;
1517 sb->sb_ccc -= sb->sb_tlsdcc;
1526 KASSERT(next, ("%s: no next, len %d", __func__, len));
1528 next = m->m_nextpkt;
1530 if (m->m_len > len) {
1531 KASSERT(!(m->m_flags & M_NOTAVAIL),
1532 ("%s: m %p M_NOTAVAIL", __func__, m));
1537 if (sb->sb_sndptroff != 0)
1538 sb->sb_sndptroff -= len;
1539 if (m->m_type != MT_DATA && m->m_type != MT_OOBDATA)
1546 sbfree_ktls_rx(sb, m);
1551 * Do not put M_NOTREADY buffers to the free list, they
1552 * are referenced from outside.
1554 if (m->m_flags & M_NOTREADY && !is_tls)
1566 * Free any zero-length mbufs from the buffer.
1567 * For SOCK_DGRAM sockets such mbufs represent empty records.
1568 * XXX: For SOCK_STREAM sockets such mbufs can appear in the buffer,
1569 * when sosend_generic() needs to send only control data.
1571 while (m && m->m_len == 0) {
1585 sb->sb_mtlstail = NULL;
1590 m->m_nextpkt = next;
1594 * First part is an inline SB_EMPTY_FIXUP(). Second part makes sure
1595 * sb_lastrecord is up-to-date if we dropped part of the last record.
1599 sb->sb_mbtail = NULL;
1600 sb->sb_lastrecord = NULL;
1601 } else if (m->m_nextpkt == NULL) {
1602 sb->sb_lastrecord = m;
1609 * Drop data from (the front of) a sockbuf.
1612 sbdrop_locked(struct sockbuf *sb, int len)
1615 SOCKBUF_LOCK_ASSERT(sb);
1616 m_freem(sbcut_internal(sb, len));
1620 * Drop data from (the front of) a sockbuf,
1621 * and return it to caller.
1624 sbcut_locked(struct sockbuf *sb, int len)
1627 SOCKBUF_LOCK_ASSERT(sb);
1628 return (sbcut_internal(sb, len));
1632 sbdrop(struct sockbuf *sb, int len)
1637 mfree = sbcut_internal(sb, len);
1644 sbsndptr_noadv(struct sockbuf *sb, uint32_t off, uint32_t *moff)
1648 KASSERT(sb->sb_mb != NULL, ("%s: sb_mb is NULL", __func__));
1649 if (sb->sb_sndptr == NULL || sb->sb_sndptroff > off) {
1651 if (sb->sb_sndptr == NULL) {
1652 sb->sb_sndptr = sb->sb_mb;
1653 sb->sb_sndptroff = 0;
1658 off -= sb->sb_sndptroff;
1665 sbsndptr_adv(struct sockbuf *sb, struct mbuf *mb, uint32_t len)
1668 * A small copy was done, advance forward the sb_sbsndptr to cover
1673 if (mb != sb->sb_sndptr) {
1674 /* Did not copyout at the same mbuf */
1678 while (m && (len > 0)) {
1679 if (len >= m->m_len) {
1682 sb->sb_sndptroff += m->m_len;
1683 sb->sb_sndptr = m->m_next;
1693 * Return the first mbuf and the mbuf data offset for the provided
1694 * send offset without changing the "sb_sndptroff" field.
1697 sbsndmbuf(struct sockbuf *sb, u_int off, u_int *moff)
1701 KASSERT(sb->sb_mb != NULL, ("%s: sb_mb is NULL", __func__));
1704 * If the "off" is below the stored offset, which happens on
1705 * retransmits, just use "sb_mb":
1707 if (sb->sb_sndptr == NULL || sb->sb_sndptroff > off) {
1711 off -= sb->sb_sndptroff;
1713 while (off > 0 && m != NULL) {
1724 * Drop a record off the front of a sockbuf and move the next record to the
1728 sbdroprecord_locked(struct sockbuf *sb)
1732 SOCKBUF_LOCK_ASSERT(sb);
1736 sb->sb_mb = m->m_nextpkt;
1746 * Drop a record off the front of a sockbuf and move the next record to the
1750 sbdroprecord(struct sockbuf *sb)
1754 sbdroprecord_locked(sb);
1759 * Create a "control" mbuf containing the specified data with the specified
1760 * type for presentation on a socket buffer.
1763 sbcreatecontrol_how(void *p, int size, int type, int level, int wait)
1768 MBUF_CHECKSLEEP(wait);
1769 if (CMSG_SPACE((u_int)size) > MCLBYTES)
1770 return ((struct mbuf *) NULL);
1771 if (CMSG_SPACE((u_int)size) > MLEN)
1772 m = m_getcl(wait, MT_CONTROL, 0);
1774 m = m_get(wait, MT_CONTROL);
1776 return ((struct mbuf *) NULL);
1777 cp = mtod(m, struct cmsghdr *);
1779 KASSERT(CMSG_SPACE((u_int)size) <= M_TRAILINGSPACE(m),
1780 ("sbcreatecontrol: short mbuf"));
1782 * Don't leave the padding between the msg header and the
1783 * cmsg data and the padding after the cmsg data un-initialized.
1785 bzero(cp, CMSG_SPACE((u_int)size));
1787 (void)memcpy(CMSG_DATA(cp), p, size);
1788 m->m_len = CMSG_SPACE(size);
1789 cp->cmsg_len = CMSG_LEN(size);
1790 cp->cmsg_level = level;
1791 cp->cmsg_type = type;
1796 sbcreatecontrol(caddr_t p, int size, int type, int level)
1799 return (sbcreatecontrol_how(p, size, type, level, M_NOWAIT));
1803 * This does the same for socket buffers that sotoxsocket does for sockets:
1804 * generate an user-format data structure describing the socket buffer. Note
1805 * that the xsockbuf structure, since it is always embedded in a socket, does
1806 * not include a self pointer nor a length. We make this entry point public
1807 * in case some other mechanism needs it.
1810 sbtoxsockbuf(struct sockbuf *sb, struct xsockbuf *xsb)
1813 xsb->sb_cc = sb->sb_ccc;
1814 xsb->sb_hiwat = sb->sb_hiwat;
1815 xsb->sb_mbcnt = sb->sb_mbcnt;
1816 xsb->sb_mcnt = sb->sb_mcnt;
1817 xsb->sb_ccnt = sb->sb_ccnt;
1818 xsb->sb_mbmax = sb->sb_mbmax;
1819 xsb->sb_lowat = sb->sb_lowat;
1820 xsb->sb_flags = sb->sb_flags;
1821 xsb->sb_timeo = sb->sb_timeo;
1824 /* This takes the place of kern.maxsockbuf, which moved to kern.ipc. */
1826 SYSCTL_INT(_kern, KERN_DUMMY, dummy, CTLFLAG_RW | CTLFLAG_SKIP, &dummy, 0, "");
1827 SYSCTL_OID(_kern_ipc, KIPC_MAXSOCKBUF, maxsockbuf,
1828 CTLTYPE_ULONG | CTLFLAG_RW | CTLFLAG_MPSAFE, &sb_max, 0,
1829 sysctl_handle_sb_max, "LU",
1830 "Maximum socket buffer size");
1831 SYSCTL_ULONG(_kern_ipc, KIPC_SOCKBUF_WASTE, sockbuf_waste_factor, CTLFLAG_RW,
1832 &sb_efficiency, 0, "Socket buffer size waste factor");