2 * Copyright (c) 2005 Jeffrey M. Hsu. All rights reserved.
3 * Copyright (c) 1982, 1986, 1988, 1990, 1993
4 * The Regents of the University of California. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by the University of
17 * California, Berkeley and its contributors.
18 * 4. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * @(#)uipc_socket2.c 8.1 (Berkeley) 6/10/93
35 * $FreeBSD: src/sys/kern/uipc_socket2.c,v 1.55.2.17 2002/08/31 19:04:55 dwmalone Exp $
36 * $DragonFly: src/sys/kern/uipc_socket2.c,v 1.33 2008/09/02 16:17:52 dillon Exp $
39 #include "opt_param.h"
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/domain.h>
43 #include <sys/file.h> /* for maxfiles */
44 #include <sys/kernel.h>
46 #include <sys/malloc.h>
48 #include <sys/protosw.h>
49 #include <sys/resourcevar.h>
51 #include <sys/socket.h>
52 #include <sys/socketvar.h>
53 #include <sys/signalvar.h>
54 #include <sys/sysctl.h>
55 #include <sys/aio.h> /* for aio_swake proto */
56 #include <sys/event.h>
58 #include <sys/thread2.h>
59 #include <sys/msgport2.h>
60 #include <sys/socketvar2.h>
65 * Primitive routines for operating on sockets and socket buffers
68 u_long sb_max = SB_MAX;
70 SB_MAX * MCLBYTES / (MSIZE + MCLBYTES); /* adjusted sb_max */
72 static u_long sb_efficiency = 8; /* parameter for sbreserve() */
74 /************************************************************************
75 * signalsockbuf procedures *
76 ************************************************************************/
79 * Wait for data to arrive at/drain from a socket buffer.
81 * NOTE: Caller must generally hold the ssb_lock (client side lock) since
82 * WAIT/WAKEUP only works for one client at a time.
84 * NOTE: Caller always retries whatever operation it was waiting on.
87 ssb_wait(struct signalsockbuf *ssb)
93 pflags = (ssb->ssb_flags & SSB_NOINTR) ? 0 : PCATCH;
96 flags = ssb->ssb_flags;
100 * WAKEUP and WAIT interlock eachother. We can catch the
101 * race by checking to see if WAKEUP has already been set,
102 * and only setting WAIT if WAKEUP is clear.
104 if (flags & SSB_WAKEUP) {
105 if (atomic_cmpset_int(&ssb->ssb_flags, flags,
106 flags & ~SSB_WAKEUP)) {
114 * Only set WAIT if WAKEUP is clear.
116 tsleep_interlock(&ssb->ssb_cc, pflags);
117 if (atomic_cmpset_int(&ssb->ssb_flags, flags,
119 error = tsleep(&ssb->ssb_cc, pflags | PINTERLOCKED,
120 "sbwait", ssb->ssb_timeo);
128 * Lock a sockbuf already known to be locked;
129 * return any error returned from sleep (EINTR).
132 _ssb_lock(struct signalsockbuf *ssb)
138 pflags = (ssb->ssb_flags & SSB_NOINTR) ? 0 : PCATCH;
141 flags = ssb->ssb_flags;
143 if (flags & SSB_LOCK) {
144 tsleep_interlock(&ssb->ssb_flags, pflags);
145 if (atomic_cmpset_int(&ssb->ssb_flags, flags,
147 error = tsleep(&ssb->ssb_flags,
148 pflags | PINTERLOCKED,
154 if (atomic_cmpset_int(&ssb->ssb_flags, flags,
156 lwkt_gettoken(&ssb->ssb_token);
166 * This does the same for sockbufs. Note that the xsockbuf structure,
167 * since it is always embedded in a socket, does not include a self
168 * pointer nor a length. We make this entry point public in case
169 * some other mechanism needs it.
172 ssbtoxsockbuf(struct signalsockbuf *ssb, struct xsockbuf *xsb)
174 xsb->sb_cc = ssb->ssb_cc;
175 xsb->sb_hiwat = ssb->ssb_hiwat;
176 xsb->sb_mbcnt = ssb->ssb_mbcnt;
177 xsb->sb_mbmax = ssb->ssb_mbmax;
178 xsb->sb_lowat = ssb->ssb_lowat;
179 xsb->sb_flags = ssb->ssb_flags;
180 xsb->sb_timeo = ssb->ssb_timeo;
184 /************************************************************************
185 * Procedures which manipulate socket state flags, wakeups, etc. *
186 ************************************************************************
188 * Normal sequence from the active (originating) side is that
189 * soisconnecting() is called during processing of connect() call, resulting
190 * in an eventual call to soisconnected() if/when the connection is
191 * established. When the connection is torn down soisdisconnecting() is
192 * called during processing of disconnect() call, and soisdisconnected() is
193 * called when the connection to the peer is totally severed.
195 * The semantics of these routines are such that connectionless protocols
196 * can call soisconnected() and soisdisconnected() only, bypassing the
197 * in-progress calls when setting up a ``connection'' takes no time.
199 * From the passive side, a socket is created with two queues of sockets:
200 * so_incomp for connections in progress and so_comp for connections
201 * already made and awaiting user acceptance. As a protocol is preparing
202 * incoming connections, it creates a socket structure queued on so_incomp
203 * by calling sonewconn(). When the connection is established,
204 * soisconnected() is called, and transfers the socket structure to so_comp,
205 * making it available to accept().
207 * If a socket is closed with sockets on either so_incomp or so_comp, these
208 * sockets are dropped.
210 * If higher level protocols are implemented in the kernel, the wakeups
211 * done here will sometimes cause software-interrupt process scheduling.
215 soisconnecting(struct socket *so)
217 soclrstate(so, SS_ISCONNECTED | SS_ISDISCONNECTING);
218 sosetstate(so, SS_ISCONNECTING);
222 soisconnected(struct socket *so)
224 struct socket *head = so->so_head;
226 soclrstate(so, SS_ISCONNECTING | SS_ISDISCONNECTING | SS_ISCONFIRMING);
227 sosetstate(so, SS_ISCONNECTED);
228 if (head && (so->so_state & SS_INCOMP)) {
229 if ((so->so_options & SO_ACCEPTFILTER) != 0) {
230 so->so_upcall = head->so_accf->so_accept_filter->accf_callback;
231 so->so_upcallarg = head->so_accf->so_accept_filter_arg;
232 atomic_set_int(&so->so_rcv.ssb_flags, SSB_UPCALL);
233 so->so_options &= ~SO_ACCEPTFILTER;
234 so->so_upcall(so, so->so_upcallarg, 0);
239 * Listen socket are not per-cpu.
241 lwkt_gettoken(&head->so_rcv.ssb_token);
242 TAILQ_REMOVE(&head->so_incomp, so, so_list);
244 soclrstate(so, SS_INCOMP);
245 TAILQ_INSERT_TAIL(&head->so_comp, so, so_list);
247 sosetstate(so, SS_COMP);
248 lwkt_reltoken(&head->so_rcv.ssb_token);
251 wakeup_one(&head->so_timeo);
253 wakeup(&so->so_timeo);
260 soisdisconnecting(struct socket *so)
262 soclrstate(so, SS_ISCONNECTING);
263 sosetstate(so, SS_ISDISCONNECTING | SS_CANTRCVMORE | SS_CANTSENDMORE);
264 wakeup((caddr_t)&so->so_timeo);
270 soisdisconnected(struct socket *so)
272 soclrstate(so, SS_ISCONNECTING | SS_ISCONNECTED | SS_ISDISCONNECTING);
273 sosetstate(so, SS_CANTRCVMORE | SS_CANTSENDMORE | SS_ISDISCONNECTED);
274 wakeup((caddr_t)&so->so_timeo);
275 sbdrop(&so->so_snd.sb, so->so_snd.ssb_cc);
281 soisreconnecting(struct socket *so)
283 soclrstate(so, SS_ISDISCONNECTING | SS_ISDISCONNECTED |
284 SS_CANTRCVMORE | SS_CANTSENDMORE);
285 sosetstate(so, SS_ISCONNECTING);
289 soisreconnected(struct socket *so)
291 soclrstate(so, SS_ISDISCONNECTED | SS_CANTRCVMORE | SS_CANTSENDMORE);
296 * Set or change the message port a socket receives commands on.
301 sosetport(struct socket *so, lwkt_port_t port)
307 * When an attempt at a new connection is noted on a socket
308 * which accepts connections, sonewconn is called. If the
309 * connection is possible (subject to space constraints, etc.)
310 * then we allocate a new structure, propoerly linked into the
311 * data structure of the original socket, and return this.
312 * Connstatus may be 0, or SO_ISCONFIRMING, or SO_ISCONNECTED.
314 * The new socket is returned with one ref and so_pcb assigned.
315 * The reference is implied by so_pcb.
318 sonewconn(struct socket *head, int connstatus)
322 struct pru_attach_info ai;
324 if (head->so_qlen > 3 * head->so_qlimit / 2)
329 if ((head->so_options & SO_ACCEPTFILTER) != 0)
332 so->so_type = head->so_type;
333 so->so_options = head->so_options &~ SO_ACCEPTCONN;
334 so->so_linger = head->so_linger;
337 * NOTE: Clearing NOFDREF implies referencing the so with
340 so->so_state = head->so_state | SS_NOFDREF;
341 so->so_proto = head->so_proto;
342 so->so_cred = crhold(head->so_cred);
345 ai.fd_rdir = NULL; /* jail code cruft XXX JH */
348 * Reserve space and call pru_attach. We can directl call the
349 * function since we're already in the protocol thread.
351 if (soreserve(so, head->so_snd.ssb_hiwat,
352 head->so_rcv.ssb_hiwat, NULL) ||
353 (*so->so_proto->pr_usrreqs->pru_attach)(so, 0, &ai)) {
355 sofree(so); /* remove implied pcb ref */
358 KKASSERT(so->so_refs == 2); /* attach + our base ref */
360 KKASSERT(so->so_port != NULL);
361 so->so_rcv.ssb_lowat = head->so_rcv.ssb_lowat;
362 so->so_snd.ssb_lowat = head->so_snd.ssb_lowat;
363 so->so_rcv.ssb_timeo = head->so_rcv.ssb_timeo;
364 so->so_snd.ssb_timeo = head->so_snd.ssb_timeo;
365 so->so_rcv.ssb_flags |= head->so_rcv.ssb_flags &
366 (SSB_AUTOSIZE | SSB_AUTOLOWAT);
367 so->so_snd.ssb_flags |= head->so_snd.ssb_flags &
368 (SSB_AUTOSIZE | SSB_AUTOLOWAT);
369 lwkt_gettoken(&head->so_rcv.ssb_token);
371 TAILQ_INSERT_TAIL(&head->so_comp, so, so_list);
372 sosetstate(so, SS_COMP);
375 if (head->so_incqlen > head->so_qlimit) {
376 sp = TAILQ_FIRST(&head->so_incomp);
377 TAILQ_REMOVE(&head->so_incomp, sp, so_list);
379 soclrstate(sp, SS_INCOMP);
383 TAILQ_INSERT_TAIL(&head->so_incomp, so, so_list);
384 sosetstate(so, SS_INCOMP);
387 lwkt_reltoken(&head->so_rcv.ssb_token);
390 wakeup((caddr_t)&head->so_timeo);
391 sosetstate(so, connstatus);
397 * Socantsendmore indicates that no more data will be sent on the
398 * socket; it would normally be applied to a socket when the user
399 * informs the system that no more data is to be sent, by the protocol
400 * code (in case PRU_SHUTDOWN). Socantrcvmore indicates that no more data
401 * will be received, and will normally be applied to the socket by a
402 * protocol when it detects that the peer will send no more data.
403 * Data queued for reading in the socket may yet be read.
406 socantsendmore(struct socket *so)
408 sosetstate(so, SS_CANTSENDMORE);
413 socantrcvmore(struct socket *so)
415 sosetstate(so, SS_CANTRCVMORE);
420 * Wakeup processes waiting on a socket buffer. Do asynchronous notification
421 * via SIGIO if the socket has the SS_ASYNC flag set.
423 * For users waiting on send/recv try to avoid unnecessary context switch
424 * thrashing. Particularly for senders of large buffers (needs to be
425 * extended to sel and aio? XXX)
428 sowakeup(struct socket *so, struct signalsockbuf *ssb)
430 struct kqinfo *kqinfo = &ssb->ssb_kq;
434 * Check conditions, set the WAKEUP flag, and clear and signal if
435 * the WAIT flag is found to be set. This interlocks against the
439 flags = ssb->ssb_flags;
442 if ((ssb == &so->so_snd && ssb_space(ssb) >= ssb->ssb_lowat) ||
443 (ssb == &so->so_rcv && ssb->ssb_cc >= ssb->ssb_lowat) ||
444 (ssb == &so->so_snd && (so->so_state & SS_CANTSENDMORE)) ||
445 (ssb == &so->so_rcv && (so->so_state & SS_CANTRCVMORE))
447 if (atomic_cmpset_int(&ssb->ssb_flags, flags,
448 (flags | SSB_WAKEUP) & ~SSB_WAIT)) {
449 if (flags & SSB_WAIT)
450 wakeup(&ssb->ssb_cc);
461 if ((so->so_state & SS_ASYNC) && so->so_sigio != NULL)
462 pgsigio(so->so_sigio, SIGIO, 0);
463 if (ssb->ssb_flags & SSB_UPCALL)
464 (*so->so_upcall)(so, so->so_upcallarg, MB_DONTWAIT);
465 if (ssb->ssb_flags & SSB_AIO)
467 KNOTE(&kqinfo->ki_note, 0);
468 if (ssb->ssb_flags & SSB_MEVENT) {
469 struct netmsg_so_notify *msg, *nmsg;
471 lwkt_gettoken(&kq_token);
472 TAILQ_FOREACH_MUTABLE(msg, &kqinfo->ki_mlist, nm_list, nmsg) {
473 if (msg->nm_predicate(&msg->nm_netmsg)) {
474 TAILQ_REMOVE(&kqinfo->ki_mlist, msg, nm_list);
475 lwkt_replymsg(&msg->nm_netmsg.nm_lmsg,
476 msg->nm_netmsg.nm_lmsg.ms_error);
479 if (TAILQ_EMPTY(&ssb->ssb_kq.ki_mlist))
480 atomic_clear_int(&ssb->ssb_flags, SSB_MEVENT);
481 lwkt_reltoken(&kq_token);
486 * Socket buffer (struct signalsockbuf) utility routines.
488 * Each socket contains two socket buffers: one for sending data and
489 * one for receiving data. Each buffer contains a queue of mbufs,
490 * information about the number of mbufs and amount of data in the
491 * queue, and other fields allowing kevent()/select()/poll() statements
492 * and notification on data availability to be implemented.
494 * Data stored in a socket buffer is maintained as a list of records.
495 * Each record is a list of mbufs chained together with the m_next
496 * field. Records are chained together with the m_nextpkt field. The upper
497 * level routine soreceive() expects the following conventions to be
498 * observed when placing information in the receive buffer:
500 * 1. If the protocol requires each message be preceded by the sender's
501 * name, then a record containing that name must be present before
502 * any associated data (mbuf's must be of type MT_SONAME).
503 * 2. If the protocol supports the exchange of ``access rights'' (really
504 * just additional data associated with the message), and there are
505 * ``rights'' to be received, then a record containing this data
506 * should be present (mbuf's must be of type MT_RIGHTS).
507 * 3. If a name or rights record exists, then it must be followed by
508 * a data record, perhaps of zero length.
510 * Before using a new socket structure it is first necessary to reserve
511 * buffer space to the socket, by calling sbreserve(). This should commit
512 * some of the available buffer space in the system buffer pool for the
513 * socket (currently, it does nothing but enforce limits). The space
514 * should be released by calling ssb_release() when the socket is destroyed.
517 soreserve(struct socket *so, u_long sndcc, u_long rcvcc, struct rlimit *rl)
519 if (so->so_snd.ssb_lowat == 0)
520 atomic_set_int(&so->so_snd.ssb_flags, SSB_AUTOLOWAT);
521 if (ssb_reserve(&so->so_snd, sndcc, so, rl) == 0)
523 if (ssb_reserve(&so->so_rcv, rcvcc, so, rl) == 0)
525 if (so->so_rcv.ssb_lowat == 0)
526 so->so_rcv.ssb_lowat = 1;
527 if (so->so_snd.ssb_lowat == 0)
528 so->so_snd.ssb_lowat = MCLBYTES;
529 if (so->so_snd.ssb_lowat > so->so_snd.ssb_hiwat)
530 so->so_snd.ssb_lowat = so->so_snd.ssb_hiwat;
533 ssb_release(&so->so_snd, so);
539 sysctl_handle_sb_max(SYSCTL_HANDLER_ARGS)
542 u_long old_sb_max = sb_max;
544 error = SYSCTL_OUT(req, arg1, sizeof(int));
545 if (error || !req->newptr)
547 error = SYSCTL_IN(req, arg1, sizeof(int));
550 if (sb_max < MSIZE + MCLBYTES) {
554 sb_max_adj = (u_quad_t)sb_max * MCLBYTES / (MSIZE + MCLBYTES);
559 * Allot mbufs to a signalsockbuf.
561 * Attempt to scale mbmax so that mbcnt doesn't become limiting
562 * if buffering efficiency is near the normal case.
564 * sb_max only applies to user-sockets (where rl != NULL). It does
565 * not apply to kernel sockets or kernel-controlled sockets. Note
566 * that NFS overrides the sockbuf limits created when nfsd creates
570 ssb_reserve(struct signalsockbuf *ssb, u_long cc, struct socket *so,
574 * rl will only be NULL when we're in an interrupt (eg, in tcp_input)
575 * or when called from netgraph (ie, ngd_attach)
577 if (rl && cc > sb_max_adj)
579 if (!chgsbsize(so->so_cred->cr_uidinfo, &ssb->ssb_hiwat, cc,
580 rl ? rl->rlim_cur : RLIM_INFINITY)) {
584 ssb->ssb_mbmax = min(cc * sb_efficiency, sb_max);
586 ssb->ssb_mbmax = cc * sb_efficiency;
589 * AUTOLOWAT is set on send buffers and prevents large writes
590 * from generating a huge number of context switches.
592 if (ssb->ssb_flags & SSB_AUTOLOWAT) {
593 ssb->ssb_lowat = ssb->ssb_hiwat / 2;
594 if (ssb->ssb_lowat < MCLBYTES)
595 ssb->ssb_lowat = MCLBYTES;
597 if (ssb->ssb_lowat > ssb->ssb_hiwat)
598 ssb->ssb_lowat = ssb->ssb_hiwat;
603 * Free mbufs held by a socket, and reserved mbuf space.
606 ssb_release(struct signalsockbuf *ssb, struct socket *so)
609 (void)chgsbsize(so->so_cred->cr_uidinfo, &ssb->ssb_hiwat, 0,
615 * Some routines that return EOPNOTSUPP for entry points that are not
616 * supported by a protocol. Fill in as needed.
619 pru_accept_notsupp(struct socket *so, struct sockaddr **nam)
625 pru_bind_notsupp(struct socket *so, struct sockaddr *nam, struct thread *td)
631 pru_connect_notsupp(struct socket *so, struct sockaddr *nam, struct thread *td)
637 pru_connect2_notsupp(struct socket *so1, struct socket *so2)
643 pru_control_notsupp(struct socket *so, u_long cmd, caddr_t data,
644 struct ifnet *ifp, struct thread *td)
650 pru_disconnect_notsupp(struct socket *so)
656 pru_listen_notsupp(struct socket *so, struct thread *td)
662 pru_peeraddr_notsupp(struct socket *so, struct sockaddr **nam)
668 pru_rcvd_notsupp(struct socket *so, int flags)
674 pru_rcvoob_notsupp(struct socket *so, struct mbuf *m, int flags)
680 pru_shutdown_notsupp(struct socket *so)
686 pru_sockaddr_notsupp(struct socket *so, struct sockaddr **nam)
692 pru_sosend_notsupp(struct socket *so, struct sockaddr *addr, struct uio *uio,
693 struct mbuf *top, struct mbuf *control, int flags,
704 pru_soreceive_notsupp(struct socket *so, struct sockaddr **paddr,
705 struct uio *uio, struct sockbuf *sio,
706 struct mbuf **controlp, int *flagsp)
712 pru_ctloutput_notsupp(struct socket *so, struct sockopt *sopt)
718 * This isn't really a ``null'' operation, but it's the default one
719 * and doesn't do anything destructive.
722 pru_sense_null(struct socket *so, struct stat *sb)
724 sb->st_blksize = so->so_snd.ssb_hiwat;
729 * Make a copy of a sockaddr in a malloced buffer of type M_SONAME. Callers
730 * of this routine assume that it always succeeds, so we have to use a
731 * blockable allocation even though we might be called from a critical thread.
734 dup_sockaddr(const struct sockaddr *sa)
736 struct sockaddr *sa2;
738 sa2 = kmalloc(sa->sa_len, M_SONAME, M_INTWAIT);
739 bcopy(sa, sa2, sa->sa_len);
744 * Create an external-format (``xsocket'') structure using the information
745 * in the kernel-format socket structure pointed to by so. This is done
746 * to reduce the spew of irrelevant information over this interface,
747 * to isolate user code from changes in the kernel structure, and
748 * potentially to provide information-hiding if we decide that
749 * some of this information should be hidden from users.
752 sotoxsocket(struct socket *so, struct xsocket *xso)
754 xso->xso_len = sizeof *xso;
756 xso->so_type = so->so_type;
757 xso->so_options = so->so_options;
758 xso->so_linger = so->so_linger;
759 xso->so_state = so->so_state;
760 xso->so_pcb = so->so_pcb;
761 xso->xso_protocol = so->so_proto->pr_protocol;
762 xso->xso_family = so->so_proto->pr_domain->dom_family;
763 xso->so_qlen = so->so_qlen;
764 xso->so_incqlen = so->so_incqlen;
765 xso->so_qlimit = so->so_qlimit;
766 xso->so_timeo = so->so_timeo;
767 xso->so_error = so->so_error;
768 xso->so_pgid = so->so_sigio ? so->so_sigio->sio_pgid : 0;
769 xso->so_oobmark = so->so_oobmark;
770 ssbtoxsockbuf(&so->so_snd, &xso->so_snd);
771 ssbtoxsockbuf(&so->so_rcv, &xso->so_rcv);
772 xso->so_uid = so->so_cred->cr_uid;
776 * Here is the definition of some of the basic objects in the kern.ipc
779 SYSCTL_NODE(_kern, KERN_IPC, ipc, CTLFLAG_RW, 0, "IPC");
782 * This takes the place of kern.maxsockbuf, which moved to kern.ipc.
784 * NOTE! sb_max only applies to user-created socket buffers.
787 SYSCTL_INT(_kern, KERN_DUMMY, dummy, CTLFLAG_RW, &dummy, 0, "");
788 SYSCTL_OID(_kern_ipc, KIPC_MAXSOCKBUF, maxsockbuf, CTLTYPE_INT|CTLFLAG_RW,
789 &sb_max, 0, sysctl_handle_sb_max, "I", "Maximum socket buffer size");
790 SYSCTL_INT(_kern_ipc, OID_AUTO, maxsockets, CTLFLAG_RD,
791 &maxsockets, 0, "Maximum number of sockets available");
792 SYSCTL_INT(_kern_ipc, KIPC_SOCKBUF_WASTE, sockbuf_waste_factor, CTLFLAG_RW,
793 &sb_efficiency, 0, "");
796 * Initialize maxsockets
799 init_maxsockets(void *ignored)
801 TUNABLE_INT_FETCH("kern.ipc.maxsockets", &maxsockets);
802 maxsockets = imax(maxsockets, imax(maxfiles, nmbclusters));
804 SYSINIT(param, SI_BOOT1_TUNABLES, SI_ORDER_ANY,
805 init_maxsockets, NULL);