1 /* $NetBSD: tcp_usrreq.c,v 1.157 2009/09/16 15:23:05 pooka Exp $ */
4 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
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 project 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 PROJECT 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 PROJECT 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
33 * Copyright (c) 1997, 1998, 2005, 2006 The NetBSD Foundation, Inc.
34 * All rights reserved.
36 * This code is derived from software contributed to The NetBSD Foundation
37 * by Jason R. Thorpe and Kevin M. Lahey of the Numerical Aerospace Simulation
38 * Facility, NASA Ames Research Center.
39 * This code is derived from software contributed to The NetBSD Foundation
40 * by Charles M. Hannum.
41 * This code is derived from software contributed to The NetBSD Foundation
44 * Redistribution and use in source and binary forms, with or without
45 * modification, are permitted provided that the following conditions
47 * 1. Redistributions of source code must retain the above copyright
48 * notice, this list of conditions and the following disclaimer.
49 * 2. Redistributions in binary form must reproduce the above copyright
50 * notice, this list of conditions and the following disclaimer in the
51 * documentation and/or other materials provided with the distribution.
53 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
54 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
55 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
56 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
57 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
58 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
59 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
60 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
61 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
62 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
63 * POSSIBILITY OF SUCH DAMAGE.
67 * Copyright (c) 1982, 1986, 1988, 1993, 1995
68 * The Regents of the University of California. All rights reserved.
70 * Redistribution and use in source and binary forms, with or without
71 * modification, are permitted provided that the following conditions
73 * 1. Redistributions of source code must retain the above copyright
74 * notice, this list of conditions and the following disclaimer.
75 * 2. Redistributions in binary form must reproduce the above copyright
76 * notice, this list of conditions and the following disclaimer in the
77 * documentation and/or other materials provided with the distribution.
78 * 3. Neither the name of the University nor the names of its contributors
79 * may be used to endorse or promote products derived from this software
80 * without specific prior written permission.
82 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
83 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
84 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
85 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
86 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
87 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
88 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
89 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
90 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
91 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
94 * @(#)tcp_usrreq.c 8.5 (Berkeley) 6/21/95
97 #include <sys/cdefs.h>
98 __KERNEL_RCSID(0, "$NetBSD: tcp_usrreq.c,v 1.157 2009/09/16 15:23:05 pooka Exp $");
100 #include "opt_inet.h"
101 #include "opt_ipsec.h"
102 #include "opt_tcp_debug.h"
103 #include "opt_mbuftrace.h"
106 #include <sys/param.h>
107 #include <sys/systm.h>
108 #include <sys/kernel.h>
109 #include <sys/malloc.h>
110 #include <sys/mbuf.h>
111 #include <sys/socket.h>
112 #include <sys/socketvar.h>
113 #include <sys/protosw.h>
114 #include <sys/errno.h>
115 #include <sys/stat.h>
116 #include <sys/proc.h>
117 #include <sys/domain.h>
118 #include <sys/sysctl.h>
119 #include <sys/kauth.h>
120 #include <sys/uidinfo.h>
123 #include <net/route.h>
125 #include <netinet/in.h>
126 #include <netinet/in_systm.h>
127 #include <netinet/in_var.h>
128 #include <netinet/ip.h>
129 #include <netinet/in_pcb.h>
130 #include <netinet/ip_var.h>
131 #include <netinet/in_offload.h>
135 #include <netinet/in.h>
137 #include <netinet/ip6.h>
138 #include <netinet6/in6_pcb.h>
139 #include <netinet6/ip6_var.h>
140 #include <netinet6/scope6_var.h>
143 #include <netinet/tcp.h>
144 #include <netinet/tcp_fsm.h>
145 #include <netinet/tcp_seq.h>
146 #include <netinet/tcp_timer.h>
147 #include <netinet/tcp_var.h>
148 #include <netinet/tcp_private.h>
149 #include <netinet/tcp_congctl.h>
150 #include <netinet/tcpip.h>
151 #include <netinet/tcp_debug.h>
153 #include "opt_tcp_space.h"
156 #include <netinet6/ipsec.h>
160 * TCP protocol interface to socket abstraction.
164 * Process a TCP user request for TCP tb. If this is a send request
165 * then m is the mbuf chain of send data. If this is a timer expiration
166 * (called from the software clock routine), then timertype tells which timer.
170 tcp_usrreq(struct socket
*so
, int req
,
171 struct mbuf
*m
, struct mbuf
*nam
, struct mbuf
*control
, struct lwp
*l
)
177 struct tcpcb
*tp
= NULL
;
183 int family
; /* family of the socket */
185 family
= so
->so_proto
->pr_domain
->dom_family
;
187 if (req
== PRU_CONTROL
) {
191 return (in_control(so
, (long)m
, (void *)nam
,
192 (struct ifnet
*)control
, l
));
196 return (in6_control(so
, (long)m
, (void *)nam
,
197 (struct ifnet
*)control
, l
));
206 if (req
== PRU_PURGEIF
) {
207 mutex_enter(softnet_lock
);
211 in_pcbpurgeif0(&tcbtable
, (struct ifnet
*)control
);
212 in_purgeif((struct ifnet
*)control
);
213 in_pcbpurgeif(&tcbtable
, (struct ifnet
*)control
);
218 in6_pcbpurgeif0(&tcbtable
, (struct ifnet
*)control
);
219 in6_purgeif((struct ifnet
*)control
);
220 in6_pcbpurgeif(&tcbtable
, (struct ifnet
*)control
);
224 mutex_exit(softnet_lock
);
226 return (EAFNOSUPPORT
);
228 mutex_exit(softnet_lock
);
233 if (req
== PRU_ATTACH
)
248 in6p
= sotoin6pcb(so
);
259 panic("tcp_usrreq: both inp and in6p set to non-NULL");
261 if (req
!= PRU_SEND
&& req
!= PRU_SENDOOB
&& control
)
262 panic("tcp_usrreq: unexpected control mbuf");
265 * When a TCP is attached to a socket, then there will be
266 * a (struct inpcb) pointed at by the socket, and this
267 * structure will point at a subsidary (struct tcpcb).
270 if (inp
== 0 && req
!= PRU_ATTACH
)
272 if ((inp
== 0 && in6p
== 0) && req
!= PRU_ATTACH
)
281 /* WHAT IF TP IS 0? */
283 tcp_acounts
[tp
->t_state
][req
]++;
286 ostate
= tp
->t_state
;
292 tp
= in6totcpcb(in6p
);
293 /* WHAT IF TP IS 0? */
295 tcp_acounts
[tp
->t_state
][req
]++;
298 ostate
= tp
->t_state
;
306 * TCP attaches to socket via PRU_ATTACH, reserving space,
307 * and an internet control block.
313 if (inp
!= 0 || in6p
!= 0)
319 error
= tcp_attach(so
);
322 if ((so
->so_options
& SO_LINGER
) && so
->so_linger
== 0)
323 so
->so_linger
= TCP_LINGERTIME
;
328 * PRU_DETACH detaches the TCP protocol from the socket.
331 tp
= tcp_disconnect(tp
);
335 * Give the socket an address.
341 error
= in_pcbbind(inp
, nam
, l
);
346 error
= in6_pcbbind(in6p
, nam
, l
);
348 /* mapped addr case */
349 if (IN6_IS_ADDR_V4MAPPED(&in6p
->in6p_laddr
))
350 tp
->t_family
= AF_INET
;
352 tp
->t_family
= AF_INET6
;
360 * Prepare to accept connections.
364 if (inp
&& inp
->inp_lport
== 0) {
365 error
= in_pcbbind(inp
, NULL
, l
);
371 if (in6p
&& in6p
->in6p_lport
== 0) {
372 error
= in6_pcbbind(in6p
, NULL
, l
);
377 tp
->t_state
= TCPS_LISTEN
;
381 * Initiate connection to peer.
382 * Create a template for use in transmissions on this connection.
383 * Enter SYN_SENT state, and mark socket as connecting.
384 * Start keep-alive timer, and seed output sequence space.
385 * Send initial segment on connection.
390 if (inp
->inp_lport
== 0) {
391 error
= in_pcbbind(inp
, NULL
, l
);
395 error
= in_pcbconnect(inp
, nam
, l
);
400 if (in6p
->in6p_lport
== 0) {
401 error
= in6_pcbbind(in6p
, NULL
, l
);
405 error
= in6_pcbconnect(in6p
, nam
, l
);
407 /* mapped addr case */
408 if (IN6_IS_ADDR_V4MAPPED(&in6p
->in6p_faddr
))
409 tp
->t_family
= AF_INET
;
411 tp
->t_family
= AF_INET6
;
417 tp
->t_template
= tcp_template(tp
);
418 if (tp
->t_template
== 0) {
421 in_pcbdisconnect(inp
);
425 in6_pcbdisconnect(in6p
);
431 * Compute window scaling to request.
432 * XXX: This should be moved to tcp_output().
434 while (tp
->request_r_scale
< TCP_MAX_WINSHIFT
&&
435 (TCP_MAXWIN
<< tp
->request_r_scale
) < sb_max
)
436 tp
->request_r_scale
++;
438 TCP_STATINC(TCP_STAT_CONNATTEMPT
);
439 tp
->t_state
= TCPS_SYN_SENT
;
440 TCP_TIMER_ARM(tp
, TCPT_KEEP
, tp
->t_keepinit
);
441 tp
->iss
= tcp_new_iss(tp
, 0);
443 error
= tcp_output(tp
);
447 * Create a TCP connection between two sockets.
454 * Initiate disconnect from peer.
455 * If connection never passed embryonic stage, just drop;
456 * else if don't need to let data drain, then can just drop anyways,
457 * else have to begin TCP shutdown process: mark socket disconnecting,
458 * drain unread data, state switch to reflect user close, and
459 * send segment (e.g. FIN) to peer. Socket will be really disconnected
460 * when peer sends FIN and acks ours.
462 * SHOULD IMPLEMENT LATER PRU_CONNECT VIA REALLOC TCPCB.
465 tp
= tcp_disconnect(tp
);
469 * Accept a connection. Essentially all the work is
470 * done at higher levels; just return the address
471 * of the peer, storing through addr.
476 in_setpeeraddr(inp
, nam
);
480 in6_setpeeraddr(in6p
, nam
);
485 * Mark the connection as being incapable of further output.
489 tp
= tcp_usrclosed(tp
);
491 error
= tcp_output(tp
);
495 * After a receive, possibly send window update to peer.
499 * soreceive() calls this function when a user receives
500 * ancillary data on a listening socket. We don't call
501 * tcp_output in such a case, since there is no header
502 * template for a listening socket and hence the kernel
505 if ((so
->so_state
& (SS_ISCONNECTED
|SS_ISCONNECTING
)) != 0)
506 (void) tcp_output(tp
);
510 * Do a send by putting data in output queue and updating urgent
511 * marker if URG set. Possibly send more data.
514 if (control
&& control
->m_len
) {
520 sbappendstream(&so
->so_snd
, m
);
521 error
= tcp_output(tp
);
528 tp
= tcp_drop(tp
, ECONNABORTED
);
533 * stat: don't bother with a blocksize.
539 if (control
&& control
->m_len
) {
545 if ((so
->so_oobmark
== 0 &&
546 (so
->so_state
& SS_RCVATMARK
) == 0) ||
547 so
->so_options
& SO_OOBINLINE
||
548 tp
->t_oobflags
& TCPOOB_HADDATA
) {
552 if ((tp
->t_oobflags
& TCPOOB_HAVEDATA
) == 0) {
557 *mtod(m
, char *) = tp
->t_iobc
;
558 if (((long)nam
& MSG_PEEK
) == 0)
559 tp
->t_oobflags
^= (TCPOOB_HAVEDATA
| TCPOOB_HADDATA
);
563 if (sbspace(&so
->so_snd
) < -512) {
569 * According to RFC961 (Assigned Protocols),
570 * the urgent pointer points to the last octet
571 * of urgent data. We continue, however,
572 * to consider it to indicate the first octet
573 * of data past the urgent section.
574 * Otherwise, snd_up should be one lower.
576 sbappendstream(&so
->so_snd
, m
);
577 tp
->snd_up
= tp
->snd_una
+ so
->so_snd
.sb_cc
;
579 error
= tcp_output(tp
);
586 in_setsockaddr(inp
, nam
);
590 in6_setsockaddr(in6p
, nam
);
597 in_setpeeraddr(inp
, nam
);
601 in6_setpeeraddr(in6p
, nam
);
609 if (tp
&& (so
->so_options
& SO_DEBUG
))
610 tcp_trace(TA_USER
, ostate
, tp
, NULL
, req
);
619 change_keepalive(struct socket
*so
, struct tcpcb
*tp
)
621 tp
->t_maxidle
= tp
->t_keepcnt
* tp
->t_keepintvl
;
622 TCP_TIMER_DISARM(tp
, TCPT_KEEP
);
623 TCP_TIMER_DISARM(tp
, TCPT_2MSL
);
625 if (tp
->t_state
== TCPS_SYN_RECEIVED
||
626 tp
->t_state
== TCPS_SYN_SENT
) {
627 TCP_TIMER_ARM(tp
, TCPT_KEEP
, tp
->t_keepinit
);
628 } else if (so
->so_options
& SO_KEEPALIVE
&&
629 tp
->t_state
<= TCPS_CLOSE_WAIT
) {
630 TCP_TIMER_ARM(tp
, TCPT_KEEP
, tp
->t_keepintvl
);
632 TCP_TIMER_ARM(tp
, TCPT_KEEP
, tp
->t_keepidle
);
635 if ((tp
->t_state
== TCPS_FIN_WAIT_2
) && (tp
->t_maxidle
> 0))
636 TCP_TIMER_ARM(tp
, TCPT_2MSL
, tp
->t_maxidle
);
641 tcp_ctloutput(int op
, struct socket
*so
, struct sockopt
*sopt
)
650 int family
; /* family of the socket */
651 int level
, optname
, optval
;
653 level
= sopt
->sopt_level
;
654 optname
= sopt
->sopt_name
;
656 family
= so
->so_proto
->pr_domain
->dom_family
;
671 in6p
= sotoin6pcb(so
);
676 panic("%s: af %d", __func__
, family
);
681 if (inp
== NULL
&& in6p
== NULL
)
687 if (level
!= IPPROTO_TCP
) {
691 error
= ip_ctloutput(op
, so
, sopt
);
696 error
= ip6_ctloutput(op
, so
, sopt
);
707 tp
= in6totcpcb(in6p
);
717 error
= sockopt_getint(sopt
, &optval
);
721 tp
->t_flags
|= TF_SIGNATURE
;
723 tp
->t_flags
&= ~TF_SIGNATURE
;
725 #endif /* TCP_SIGNATURE */
728 error
= sockopt_getint(sopt
, &optval
);
732 tp
->t_flags
|= TF_NODELAY
;
734 tp
->t_flags
&= ~TF_NODELAY
;
738 error
= sockopt_getint(sopt
, &optval
);
741 if (optval
> 0 && optval
<= tp
->t_peermss
)
742 tp
->t_peermss
= optval
; /* limit on send size */
748 /* XXX string overflow XXX */
749 error
= tcp_congctl_select(tp
, sopt
->sopt_data
);
754 error
= sockopt_get(sopt
, &ui
, sizeof(ui
));
759 change_keepalive(so
, tp
);
765 error
= sockopt_get(sopt
, &ui
, sizeof(ui
));
769 tp
->t_keepintvl
= ui
;
770 change_keepalive(so
, tp
);
776 error
= sockopt_get(sopt
, &ui
, sizeof(ui
));
781 change_keepalive(so
, tp
);
787 error
= sockopt_get(sopt
, &ui
, sizeof(ui
));
792 change_keepalive(so
, tp
);
807 optval
= (tp
->t_flags
& TF_SIGNATURE
) ? 1 : 0;
808 error
= sockopt_set(sopt
, &optval
, sizeof(optval
));
812 optval
= tp
->t_flags
& TF_NODELAY
;
813 error
= sockopt_set(sopt
, &optval
, sizeof(optval
));
816 optval
= tp
->t_peermss
;
817 error
= sockopt_set(sopt
, &optval
, sizeof(optval
));
833 #ifndef TCP_SENDSPACE
834 #define TCP_SENDSPACE 1024*32
836 int tcp_sendspace
= TCP_SENDSPACE
;
837 #ifndef TCP_RECVSPACE
838 #define TCP_RECVSPACE 1024*32
840 int tcp_recvspace
= TCP_RECVSPACE
;
843 * Attach TCP protocol to socket, allocating
844 * internet protocol control block, tcp control block,
845 * bufer space, and entering LISTEN state if to accept connections.
848 tcp_attach(struct socket
*so
)
856 int family
; /* family of the socket */
858 family
= so
->so_proto
->pr_domain
->dom_family
;
861 so
->so_mowner
= &tcp_sock_mowner
;
862 so
->so_rcv
.sb_mowner
= &tcp_sock_rx_mowner
;
863 so
->so_snd
.sb_mowner
= &tcp_sock_tx_mowner
;
865 if (so
->so_snd
.sb_hiwat
== 0 || so
->so_rcv
.sb_hiwat
== 0) {
866 error
= soreserve(so
, tcp_sendspace
, tcp_recvspace
);
871 so
->so_rcv
.sb_flags
|= SB_AUTOSIZE
;
872 so
->so_snd
.sb_flags
|= SB_AUTOSIZE
;
877 error
= in_pcballoc(so
, &tcbtable
);
888 error
= in6_pcballoc(so
, &tcbtable
);
892 in6p
= sotoin6pcb(so
);
899 tp
= tcp_newtcpcb(family
, (void *)inp
);
902 tp
= tcp_newtcpcb(family
, (void *)in6p
);
908 int nofd
= so
->so_state
& SS_NOFDREF
; /* XXX */
910 so
->so_state
&= ~SS_NOFDREF
; /* don't free the socket yet */
919 so
->so_state
|= nofd
;
922 tp
->t_state
= TCPS_CLOSED
;
927 * Initiate (or continue) disconnect.
928 * If embryonic state, just send reset (once).
929 * If in ``let data drain'' option and linger null, just drop.
930 * Otherwise (hard), mark socket disconnecting and drop
931 * current input data; switch states based on user close, and
932 * send segment to peer (with FIN).
935 tcp_disconnect(struct tcpcb
*tp
)
940 so
= tp
->t_inpcb
->inp_socket
;
942 else if (tp
->t_in6pcb
)
943 so
= tp
->t_in6pcb
->in6p_socket
;
948 if (TCPS_HAVEESTABLISHED(tp
->t_state
) == 0)
950 else if ((so
->so_options
& SO_LINGER
) && so
->so_linger
== 0)
951 tp
= tcp_drop(tp
, 0);
953 soisdisconnecting(so
);
954 sbflush(&so
->so_rcv
);
955 tp
= tcp_usrclosed(tp
);
957 (void) tcp_output(tp
);
963 * User issued close, and wish to trail through shutdown states:
964 * if never received SYN, just forget it. If got a SYN from peer,
965 * but haven't sent FIN, then go to FIN_WAIT_1 state to send peer a FIN.
966 * If already got a FIN from peer, then almost done; go to LAST_ACK
967 * state. In all other cases, have already sent FIN to peer (e.g.
968 * after PRU_SHUTDOWN), and just have to play tedious game waiting
969 * for peer to send FIN or not respond to keep-alives, etc.
970 * We can let the user exit from the close as soon as the FIN is acked.
973 tcp_usrclosed(struct tcpcb
*tp
)
976 switch (tp
->t_state
) {
981 tp
->t_state
= TCPS_CLOSED
;
985 case TCPS_SYN_RECEIVED
:
986 case TCPS_ESTABLISHED
:
987 tp
->t_state
= TCPS_FIN_WAIT_1
;
990 case TCPS_CLOSE_WAIT
:
991 tp
->t_state
= TCPS_LAST_ACK
;
994 if (tp
&& tp
->t_state
>= TCPS_FIN_WAIT_2
) {
997 so
= tp
->t_inpcb
->inp_socket
;
999 else if (tp
->t_in6pcb
)
1000 so
= tp
->t_in6pcb
->in6p_socket
;
1005 soisdisconnected(so
);
1007 * If we are in FIN_WAIT_2, we arrived here because the
1008 * application did a shutdown of the send side. Like the
1009 * case of a transition from FIN_WAIT_1 to FIN_WAIT_2 after
1010 * a full close, we start a timer to make sure sockets are
1011 * not left in FIN_WAIT_2 forever.
1013 if ((tp
->t_state
== TCPS_FIN_WAIT_2
) && (tp
->t_maxidle
> 0))
1014 TCP_TIMER_ARM(tp
, TCPT_2MSL
, tp
->t_maxidle
);
1020 * sysctl helper routine for net.inet.ip.mssdflt. it can't be less
1024 sysctl_net_inet_tcp_mssdflt(SYSCTLFN_ARGS
)
1027 struct sysctlnode node
;
1029 mssdflt
= tcp_mssdflt
;
1031 node
.sysctl_data
= &mssdflt
;
1032 error
= sysctl_lookup(SYSCTLFN_CALL(&node
));
1033 if (error
|| newp
== NULL
)
1038 tcp_mssdflt
= mssdflt
;
1044 * sysctl helper routine for setting port related values under
1045 * net.inet.ip and net.inet6.ip6. does basic range checking and does
1046 * additional checks for each type. this code has placed in
1047 * tcp_input.c since INET and INET6 both use the same tcp code.
1049 * this helper is not static so that both inet and inet6 can use it.
1052 sysctl_net_inet_ip_ports(SYSCTLFN_ARGS
)
1056 #ifndef IPNOPRIVPORTS
1058 #endif /* IPNOPRIVPORTS */
1059 struct sysctlnode node
;
1067 apmin
= anonportmin
;
1068 apmax
= anonportmax
;
1069 #ifndef IPNOPRIVPORTS
1072 #endif /* IPNOPRIVPORTS */
1077 apmin
= ip6_anonportmin
;
1078 apmax
= ip6_anonportmax
;
1079 #ifndef IPNOPRIVPORTS
1080 lpmin
= ip6_lowportmin
;
1081 lpmax
= ip6_lowportmax
;
1082 #endif /* IPNOPRIVPORTS */
1090 * insert temporary copy into node, perform lookup on
1091 * temporary, then restore pointer
1094 tmp
= *(int*)rnode
->sysctl_data
;
1095 node
.sysctl_data
= &tmp
;
1096 error
= sysctl_lookup(SYSCTLFN_CALL(&node
));
1097 if (error
|| newp
== NULL
)
1101 * simple port range check
1103 if (tmp
< 0 || tmp
> 65535)
1107 * per-node range checks
1109 switch (rnode
->sysctl_num
) {
1110 case IPCTL_ANONPORTMIN
:
1111 case IPV6CTL_ANONPORTMIN
:
1114 #ifndef IPNOPRIVPORTS
1115 if (tmp
< IPPORT_RESERVED
)
1117 #endif /* IPNOPRIVPORTS */
1120 case IPCTL_ANONPORTMAX
:
1121 case IPV6CTL_ANONPORTMAX
:
1124 #ifndef IPNOPRIVPORTS
1125 if (tmp
< IPPORT_RESERVED
)
1127 #endif /* IPNOPRIVPORTS */
1130 #ifndef IPNOPRIVPORTS
1131 case IPCTL_LOWPORTMIN
:
1132 case IPV6CTL_LOWPORTMIN
:
1134 tmp
> IPPORT_RESERVEDMAX
||
1135 tmp
< IPPORT_RESERVEDMIN
)
1139 case IPCTL_LOWPORTMAX
:
1140 case IPV6CTL_LOWPORTMAX
:
1142 tmp
> IPPORT_RESERVEDMAX
||
1143 tmp
< IPPORT_RESERVEDMIN
)
1146 #endif /* IPNOPRIVPORTS */
1152 *(int*)rnode
->sysctl_data
= tmp
;
1158 copyout_uid(struct socket
*sockp
, void *oldp
, size_t *oldlenp
)
1164 uid
= kauth_cred_geteuid(sockp
->so_cred
);
1166 sz
= MIN(sizeof(uid
), *oldlenp
);
1167 error
= copyout(&uid
, oldp
, sz
);
1171 *oldlenp
= sizeof(uid
);
1176 inet4_ident_core(struct in_addr raddr
, u_int rport
,
1177 struct in_addr laddr
, u_int lport
,
1178 void *oldp
, size_t *oldlenp
,
1179 struct lwp
*l
, int dodrop
)
1182 struct socket
*sockp
;
1184 inp
= in_pcblookup_connect(&tcbtable
, raddr
, rport
, laddr
, lport
);
1186 if (inp
== NULL
|| (sockp
= inp
->inp_socket
) == NULL
)
1193 if (inp
== NULL
|| (tp
= intotcpcb(inp
)) == NULL
||
1194 (inp
->inp_socket
->so_options
& SO_ACCEPTCONN
) != 0)
1197 error
= kauth_authorize_network(l
->l_cred
, KAUTH_NETWORK_SOCKET
,
1198 KAUTH_REQ_NETWORK_SOCKET_DROP
, inp
->inp_socket
, tp
, NULL
);
1202 (void)tcp_drop(tp
, ECONNABORTED
);
1206 return copyout_uid(sockp
, oldp
, oldlenp
);
1211 inet6_ident_core(struct in6_addr
*raddr
, u_int rport
,
1212 struct in6_addr
*laddr
, u_int lport
,
1213 void *oldp
, size_t *oldlenp
,
1214 struct lwp
*l
, int dodrop
)
1216 struct in6pcb
*in6p
;
1217 struct socket
*sockp
;
1219 in6p
= in6_pcblookup_connect(&tcbtable
, raddr
, rport
, laddr
, lport
, 0);
1221 if (in6p
== NULL
|| (sockp
= in6p
->in6p_socket
) == NULL
)
1228 if (in6p
== NULL
|| (tp
= in6totcpcb(in6p
)) == NULL
||
1229 (in6p
->in6p_socket
->so_options
& SO_ACCEPTCONN
) != 0)
1232 error
= kauth_authorize_network(l
->l_cred
, KAUTH_NETWORK_SOCKET
,
1233 KAUTH_REQ_NETWORK_SOCKET_DROP
, in6p
->in6p_socket
, tp
, NULL
);
1237 (void)tcp_drop(tp
, ECONNABORTED
);
1241 return copyout_uid(sockp
, oldp
, oldlenp
);
1246 * sysctl helper routine for the net.inet.tcp.drop and
1247 * net.inet6.tcp6.drop nodes.
1249 #define sysctl_net_inet_tcp_drop sysctl_net_inet_tcp_ident
1252 * sysctl helper routine for the net.inet.tcp.ident and
1253 * net.inet6.tcp6.ident nodes. contains backwards compat code for the
1254 * old way of looking up the ident information for ipv4 which involves
1255 * stuffing the port/addr pairs into the mib lookup.
1258 sysctl_net_inet_tcp_ident(SYSCTLFN_ARGS
)
1261 struct sockaddr_in
*si4
[2];
1264 struct sockaddr_in6
*si6
[2];
1266 struct sockaddr_storage sa
[2];
1267 int error
, pf
, dodrop
;
1269 dodrop
= name
[-1] == TCPCTL_DROP
;
1271 if (oldp
!= NULL
|| *oldlenp
!= 0)
1275 if (newlen
< sizeof(sa
))
1278 if (namelen
!= 4 && namelen
!= 0)
1280 if (name
[-2] != IPPROTO_TCP
)
1284 /* old style lookup, ipv4 only */
1287 struct in_addr laddr
, raddr
;
1291 return EPROTONOSUPPORT
;
1292 raddr
.s_addr
= (uint32_t)name
[0];
1293 rport
= (u_int
)name
[1];
1294 laddr
.s_addr
= (uint32_t)name
[2];
1295 lport
= (u_int
)name
[3];
1297 mutex_enter(softnet_lock
);
1298 error
= inet4_ident_core(raddr
, rport
, laddr
, lport
,
1299 oldp
, oldlenp
, l
, dodrop
);
1300 mutex_exit(softnet_lock
);
1307 if (newp
== NULL
|| newlen
!= sizeof(sa
))
1309 error
= copyin(newp
, &sa
, newlen
);
1314 * requested families must match
1316 if (pf
!= sa
[0].ss_family
|| sa
[0].ss_family
!= sa
[1].ss_family
)
1322 si6
[0] = (struct sockaddr_in6
*)&sa
[0];
1323 si6
[1] = (struct sockaddr_in6
*)&sa
[1];
1324 if (si6
[0]->sin6_len
!= sizeof(*si6
[0]) ||
1325 si6
[1]->sin6_len
!= sizeof(*si6
[1]))
1328 if (!IN6_IS_ADDR_V4MAPPED(&si6
[0]->sin6_addr
) &&
1329 !IN6_IS_ADDR_V4MAPPED(&si6
[1]->sin6_addr
)) {
1330 error
= sa6_embedscope(si6
[0], ip6_use_defzone
);
1333 error
= sa6_embedscope(si6
[1], ip6_use_defzone
);
1337 mutex_enter(softnet_lock
);
1338 error
= inet6_ident_core(&si6
[0]->sin6_addr
,
1339 si6
[0]->sin6_port
, &si6
[1]->sin6_addr
,
1340 si6
[1]->sin6_port
, oldp
, oldlenp
, l
, dodrop
);
1341 mutex_exit(softnet_lock
);
1345 if (IN6_IS_ADDR_V4MAPPED(&si6
[0]->sin6_addr
) !=
1346 IN6_IS_ADDR_V4MAPPED(&si6
[1]->sin6_addr
))
1349 in6_sin6_2_sin_in_sock((struct sockaddr
*)&sa
[0]);
1350 in6_sin6_2_sin_in_sock((struct sockaddr
*)&sa
[1]);
1355 si4
[0] = (struct sockaddr_in
*)&sa
[0];
1356 si4
[1] = (struct sockaddr_in
*)&sa
[1];
1357 if (si4
[0]->sin_len
!= sizeof(*si4
[0]) ||
1358 si4
[0]->sin_len
!= sizeof(*si4
[1]))
1361 mutex_enter(softnet_lock
);
1362 error
= inet4_ident_core(si4
[0]->sin_addr
, si4
[0]->sin_port
,
1363 si4
[1]->sin_addr
, si4
[1]->sin_port
,
1364 oldp
, oldlenp
, l
, dodrop
);
1365 mutex_exit(softnet_lock
);
1369 return EPROTONOSUPPORT
;
1374 * sysctl helper for the inet and inet6 pcblists. handles tcp/udp and
1375 * inet/inet6, as well as raw pcbs for each. specifically not
1376 * declared static so that raw sockets and udp/udp6 can use it as
1380 sysctl_inpcblist(SYSCTLFN_ARGS
)
1383 struct sockaddr_in
*in
;
1384 const struct inpcb
*inp
;
1387 struct sockaddr_in6
*in6
;
1388 const struct in6pcb
*in6p
;
1391 * sysctl_data is const, but CIRCLEQ_FOREACH can't use a const
1392 * struct inpcbtable pointer, so we have to discard const. :-/
1394 struct inpcbtable
*pcbtbl
= __UNCONST(rnode
->sysctl_data
);
1395 const struct inpcb_hdr
*inph
;
1397 struct kinfo_pcb pcb
;
1400 size_t len
, needed
, elem_size
, out_size
;
1401 int error
, elem_count
, pf
, proto
, pf2
;
1408 elem_size
= name
[2];
1409 elem_count
= name
[3];
1410 if (elem_size
!= sizeof(pcb
))
1414 elem_count
= INT_MAX
;
1415 elem_size
= sizeof(pcb
);
1421 out_size
= elem_size
;
1424 if (namelen
== 1 && name
[0] == CTL_QUERY
)
1425 return (sysctl_query(SYSCTLFN_CALL(rnode
)));
1427 if (name
- oname
!= 4)
1432 pf2
= (oldp
!= NULL
) ? pf
: 0;
1434 mutex_enter(softnet_lock
);
1436 CIRCLEQ_FOREACH(inph
, &pcbtbl
->inpt_queue
, inph_queue
) {
1438 inp
= (const struct inpcb
*)inph
;
1441 in6p
= (const struct in6pcb
*)inph
;
1444 if (inph
->inph_af
!= pf
)
1447 if (kauth_authorize_network(l
->l_cred
, KAUTH_NETWORK_SOCKET
,
1448 KAUTH_REQ_NETWORK_SOCKET_CANSEE
, inph
->inph_socket
, NULL
,
1452 memset(&pcb
, 0, sizeof(pcb
));
1455 pcb
.ki_type
= proto
;
1459 /* just probing for size */
1463 pcb
.ki_family
= inp
->inp_socket
->so_proto
->
1464 pr_domain
->dom_family
;
1465 pcb
.ki_type
= inp
->inp_socket
->so_proto
->
1467 pcb
.ki_protocol
= inp
->inp_socket
->so_proto
->
1469 pcb
.ki_pflags
= inp
->inp_flags
;
1471 pcb
.ki_sostate
= inp
->inp_socket
->so_state
;
1472 pcb
.ki_prstate
= inp
->inp_state
;
1473 if (proto
== IPPROTO_TCP
) {
1474 tp
= intotcpcb(inp
);
1475 pcb
.ki_tstate
= tp
->t_state
;
1476 pcb
.ki_tflags
= tp
->t_flags
;
1479 pcb
.ki_pcbaddr
= PTRTOUINT64(inp
);
1480 pcb
.ki_ppcbaddr
= PTRTOUINT64(inp
->inp_ppcb
);
1481 pcb
.ki_sockaddr
= PTRTOUINT64(inp
->inp_socket
);
1483 pcb
.ki_rcvq
= inp
->inp_socket
->so_rcv
.sb_cc
;
1484 pcb
.ki_sndq
= inp
->inp_socket
->so_snd
.sb_cc
;
1486 in
= satosin(&pcb
.ki_src
);
1487 in
->sin_len
= sizeof(*in
);
1488 in
->sin_family
= pf
;
1489 in
->sin_port
= inp
->inp_lport
;
1490 in
->sin_addr
= inp
->inp_laddr
;
1491 if (pcb
.ki_prstate
>= INP_CONNECTED
) {
1492 in
= satosin(&pcb
.ki_dst
);
1493 in
->sin_len
= sizeof(*in
);
1494 in
->sin_family
= pf
;
1495 in
->sin_port
= inp
->inp_fport
;
1496 in
->sin_addr
= inp
->inp_faddr
;
1502 pcb
.ki_family
= in6p
->in6p_socket
->so_proto
->
1503 pr_domain
->dom_family
;
1504 pcb
.ki_type
= in6p
->in6p_socket
->so_proto
->pr_type
;
1505 pcb
.ki_protocol
= in6p
->in6p_socket
->so_proto
->
1507 pcb
.ki_pflags
= in6p
->in6p_flags
;
1509 pcb
.ki_sostate
= in6p
->in6p_socket
->so_state
;
1510 pcb
.ki_prstate
= in6p
->in6p_state
;
1511 if (proto
== IPPROTO_TCP
) {
1512 tp
= in6totcpcb(in6p
);
1513 pcb
.ki_tstate
= tp
->t_state
;
1514 pcb
.ki_tflags
= tp
->t_flags
;
1517 pcb
.ki_pcbaddr
= PTRTOUINT64(in6p
);
1518 pcb
.ki_ppcbaddr
= PTRTOUINT64(in6p
->in6p_ppcb
);
1519 pcb
.ki_sockaddr
= PTRTOUINT64(in6p
->in6p_socket
);
1521 pcb
.ki_rcvq
= in6p
->in6p_socket
->so_rcv
.sb_cc
;
1522 pcb
.ki_sndq
= in6p
->in6p_socket
->so_snd
.sb_cc
;
1524 in6
= satosin6(&pcb
.ki_src
);
1525 in6
->sin6_len
= sizeof(*in6
);
1526 in6
->sin6_family
= pf
;
1527 in6
->sin6_port
= in6p
->in6p_lport
;
1528 in6
->sin6_flowinfo
= in6p
->in6p_flowinfo
;
1529 in6
->sin6_addr
= in6p
->in6p_laddr
;
1530 in6
->sin6_scope_id
= 0; /* XXX? */
1532 if (pcb
.ki_prstate
>= IN6P_CONNECTED
) {
1533 in6
= satosin6(&pcb
.ki_dst
);
1534 in6
->sin6_len
= sizeof(*in6
);
1535 in6
->sin6_family
= pf
;
1536 in6
->sin6_port
= in6p
->in6p_fport
;
1537 in6
->sin6_flowinfo
= in6p
->in6p_flowinfo
;
1538 in6
->sin6_addr
= in6p
->in6p_faddr
;
1539 in6
->sin6_scope_id
= 0; /* XXX? */
1545 if (len
>= elem_size
&& elem_count
> 0) {
1546 error
= copyout(&pcb
, dp
, out_size
);
1548 mutex_exit(softnet_lock
);
1554 needed
+= elem_size
;
1555 if (elem_count
> 0 && elem_count
!= INT_MAX
)
1561 *oldlenp
+= PCB_SLOP
* sizeof(struct kinfo_pcb
);
1563 mutex_exit(softnet_lock
);
1569 sysctl_tcp_congctl(SYSCTLFN_ARGS
)
1571 struct sysctlnode node
;
1573 char newname
[TCPCC_MAXLEN
];
1575 strlcpy(newname
, tcp_congctl_global_name
, sizeof(newname
) - 1);
1578 node
.sysctl_data
= newname
;
1579 node
.sysctl_size
= sizeof(newname
);
1581 error
= sysctl_lookup(SYSCTLFN_CALL(&node
));
1585 strncmp(newname
, tcp_congctl_global_name
, sizeof(newname
)) == 0)
1588 mutex_enter(softnet_lock
);
1589 error
= tcp_congctl_select(NULL
, newname
);
1590 mutex_exit(softnet_lock
);
1596 sysctl_tcp_keep(SYSCTLFN_ARGS
)
1600 struct sysctlnode node
;
1603 tmp
= *(u_int
*)rnode
->sysctl_data
;
1604 node
.sysctl_data
= &tmp
;
1606 error
= sysctl_lookup(SYSCTLFN_CALL(&node
));
1607 if (error
|| newp
== NULL
)
1610 mutex_enter(softnet_lock
);
1612 *(u_int
*)rnode
->sysctl_data
= tmp
;
1613 tcp_tcpcb_template(); /* update the template */
1615 mutex_exit(softnet_lock
);
1620 sysctl_net_inet_tcp_stats(SYSCTLFN_ARGS
)
1623 return (NETSTAT_SYSCTL(tcpstat_percpu
, TCP_NSTATS
));
1627 * this (second stage) setup routine is a replacement for tcp_sysctl()
1628 * (which is currently used for ipv4 and ipv6)
1631 sysctl_net_inet_tcp_setup2(struct sysctllog
**clog
, int pf
, const char *pfname
,
1632 const char *tcpname
)
1634 const struct sysctlnode
*sack_node
;
1635 const struct sysctlnode
*abc_node
;
1636 const struct sysctlnode
*ecn_node
;
1637 const struct sysctlnode
*congctl_node
;
1639 extern struct tcp_debug tcp_debug
[TCP_NDEBUG
];
1640 extern int tcp_debx
;
1643 sysctl_createv(clog
, 0, NULL
, NULL
,
1645 CTLTYPE_NODE
, "net", NULL
,
1648 sysctl_createv(clog
, 0, NULL
, NULL
,
1650 CTLTYPE_NODE
, pfname
, NULL
,
1652 CTL_NET
, pf
, CTL_EOL
);
1653 sysctl_createv(clog
, 0, NULL
, NULL
,
1655 CTLTYPE_NODE
, tcpname
,
1656 SYSCTL_DESCR("TCP related settings"),
1658 CTL_NET
, pf
, IPPROTO_TCP
, CTL_EOL
);
1660 sysctl_createv(clog
, 0, NULL
, NULL
,
1661 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
1662 CTLTYPE_INT
, "rfc1323",
1663 SYSCTL_DESCR("Enable RFC1323 TCP extensions"),
1664 NULL
, 0, &tcp_do_rfc1323
, 0,
1665 CTL_NET
, pf
, IPPROTO_TCP
, TCPCTL_RFC1323
, CTL_EOL
);
1666 sysctl_createv(clog
, 0, NULL
, NULL
,
1667 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
1668 CTLTYPE_INT
, "sendspace",
1669 SYSCTL_DESCR("Default TCP send buffer size"),
1670 NULL
, 0, &tcp_sendspace
, 0,
1671 CTL_NET
, pf
, IPPROTO_TCP
, TCPCTL_SENDSPACE
, CTL_EOL
);
1672 sysctl_createv(clog
, 0, NULL
, NULL
,
1673 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
1674 CTLTYPE_INT
, "recvspace",
1675 SYSCTL_DESCR("Default TCP receive buffer size"),
1676 NULL
, 0, &tcp_recvspace
, 0,
1677 CTL_NET
, pf
, IPPROTO_TCP
, TCPCTL_RECVSPACE
, CTL_EOL
);
1678 sysctl_createv(clog
, 0, NULL
, NULL
,
1679 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
1680 CTLTYPE_INT
, "mssdflt",
1681 SYSCTL_DESCR("Default maximum segment size"),
1682 sysctl_net_inet_tcp_mssdflt
, 0, &tcp_mssdflt
, 0,
1683 CTL_NET
, pf
, IPPROTO_TCP
, TCPCTL_MSSDFLT
, CTL_EOL
);
1684 sysctl_createv(clog
, 0, NULL
, NULL
,
1685 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
1686 CTLTYPE_INT
, "minmss",
1687 SYSCTL_DESCR("Lower limit for TCP maximum segment size"),
1688 NULL
, 0, &tcp_minmss
, 0,
1689 CTL_NET
, pf
, IPPROTO_TCP
, CTL_CREATE
, CTL_EOL
);
1690 sysctl_createv(clog
, 0, NULL
, NULL
,
1691 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
1693 SYSCTL_DESCR("Maximum Segment Life"),
1694 NULL
, 0, &tcp_msl
, 0,
1695 CTL_NET
, pf
, IPPROTO_TCP
, TCPCTL_MSL
, CTL_EOL
);
1696 sysctl_createv(clog
, 0, NULL
, NULL
,
1697 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
1698 CTLTYPE_INT
, "syn_cache_limit",
1699 SYSCTL_DESCR("Maximum number of entries in the TCP "
1700 "compressed state engine"),
1701 NULL
, 0, &tcp_syn_cache_limit
, 0,
1702 CTL_NET
, pf
, IPPROTO_TCP
, TCPCTL_SYN_CACHE_LIMIT
,
1704 sysctl_createv(clog
, 0, NULL
, NULL
,
1705 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
1706 CTLTYPE_INT
, "syn_bucket_limit",
1707 SYSCTL_DESCR("Maximum number of entries per hash "
1708 "bucket in the TCP compressed state "
1710 NULL
, 0, &tcp_syn_bucket_limit
, 0,
1711 CTL_NET
, pf
, IPPROTO_TCP
, TCPCTL_SYN_BUCKET_LIMIT
,
1713 #if 0 /* obsoleted */
1714 sysctl_createv(clog
, 0, NULL
, NULL
,
1715 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
1716 CTLTYPE_INT
, "syn_cache_interval",
1717 SYSCTL_DESCR("TCP compressed state engine's timer interval"),
1718 NULL
, 0, &tcp_syn_cache_interval
, 0,
1719 CTL_NET
, pf
, IPPROTO_TCP
, TCPCTL_SYN_CACHE_INTER
,
1722 sysctl_createv(clog
, 0, NULL
, NULL
,
1723 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
1724 CTLTYPE_INT
, "init_win",
1725 SYSCTL_DESCR("Initial TCP congestion window"),
1726 NULL
, 0, &tcp_init_win
, 0,
1727 CTL_NET
, pf
, IPPROTO_TCP
, TCPCTL_INIT_WIN
, CTL_EOL
);
1728 sysctl_createv(clog
, 0, NULL
, NULL
,
1729 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
1730 CTLTYPE_INT
, "mss_ifmtu",
1731 SYSCTL_DESCR("Use interface MTU for calculating MSS"),
1732 NULL
, 0, &tcp_mss_ifmtu
, 0,
1733 CTL_NET
, pf
, IPPROTO_TCP
, TCPCTL_MSS_IFMTU
, CTL_EOL
);
1734 sysctl_createv(clog
, 0, NULL
, &sack_node
,
1736 CTLTYPE_NODE
, "sack",
1737 SYSCTL_DESCR("RFC2018 Selective ACKnowledgement tunables"),
1739 CTL_NET
, pf
, IPPROTO_TCP
, TCPCTL_SACK
, CTL_EOL
);
1741 /* Congctl subtree */
1742 sysctl_createv(clog
, 0, NULL
, &congctl_node
,
1744 CTLTYPE_NODE
, "congctl",
1745 SYSCTL_DESCR("TCP Congestion Control"),
1747 CTL_NET
, pf
, IPPROTO_TCP
, CTL_CREATE
, CTL_EOL
);
1748 sysctl_createv(clog
, 0, &congctl_node
, NULL
,
1750 CTLTYPE_STRING
, "available",
1751 SYSCTL_DESCR("Available Congestion Control Mechanisms"),
1752 NULL
, 0, &tcp_congctl_avail
, 0, CTL_CREATE
, CTL_EOL
);
1753 sysctl_createv(clog
, 0, &congctl_node
, NULL
,
1754 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
1755 CTLTYPE_STRING
, "selected",
1756 SYSCTL_DESCR("Selected Congestion Control Mechanism"),
1757 sysctl_tcp_congctl
, 0, NULL
, TCPCC_MAXLEN
,
1758 CTL_CREATE
, CTL_EOL
);
1760 sysctl_createv(clog
, 0, NULL
, NULL
,
1761 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
1762 CTLTYPE_INT
, "win_scale",
1763 SYSCTL_DESCR("Use RFC1323 window scale options"),
1764 NULL
, 0, &tcp_do_win_scale
, 0,
1765 CTL_NET
, pf
, IPPROTO_TCP
, TCPCTL_WSCALE
, CTL_EOL
);
1766 sysctl_createv(clog
, 0, NULL
, NULL
,
1767 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
1768 CTLTYPE_INT
, "timestamps",
1769 SYSCTL_DESCR("Use RFC1323 time stamp options"),
1770 NULL
, 0, &tcp_do_timestamps
, 0,
1771 CTL_NET
, pf
, IPPROTO_TCP
, TCPCTL_TSTAMP
, CTL_EOL
);
1772 sysctl_createv(clog
, 0, NULL
, NULL
,
1773 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
1774 CTLTYPE_INT
, "compat_42",
1775 SYSCTL_DESCR("Enable workarounds for 4.2BSD TCP bugs"),
1776 NULL
, 0, &tcp_compat_42
, 0,
1777 CTL_NET
, pf
, IPPROTO_TCP
, TCPCTL_COMPAT_42
, CTL_EOL
);
1778 sysctl_createv(clog
, 0, NULL
, NULL
,
1779 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
1781 SYSCTL_DESCR("Hughes/Touch/Heidemann Congestion Window "
1783 NULL
, 0, &tcp_cwm
, 0,
1784 CTL_NET
, pf
, IPPROTO_TCP
, TCPCTL_CWM
, CTL_EOL
);
1785 sysctl_createv(clog
, 0, NULL
, NULL
,
1786 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
1787 CTLTYPE_INT
, "cwm_burstsize",
1788 SYSCTL_DESCR("Congestion Window Monitoring allowed "
1789 "burst count in packets"),
1790 NULL
, 0, &tcp_cwm_burstsize
, 0,
1791 CTL_NET
, pf
, IPPROTO_TCP
, TCPCTL_CWM_BURSTSIZE
,
1793 sysctl_createv(clog
, 0, NULL
, NULL
,
1794 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
1795 CTLTYPE_INT
, "ack_on_push",
1796 SYSCTL_DESCR("Immediately return ACK when PSH is "
1798 NULL
, 0, &tcp_ack_on_push
, 0,
1799 CTL_NET
, pf
, IPPROTO_TCP
, TCPCTL_ACK_ON_PUSH
, CTL_EOL
);
1800 sysctl_createv(clog
, 0, NULL
, NULL
,
1801 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
1802 CTLTYPE_INT
, "keepidle",
1803 SYSCTL_DESCR("Allowed connection idle ticks before a "
1804 "keepalive probe is sent"),
1805 sysctl_tcp_keep
, 0, &tcp_keepidle
, 0,
1806 CTL_NET
, pf
, IPPROTO_TCP
, TCPCTL_KEEPIDLE
, CTL_EOL
);
1807 sysctl_createv(clog
, 0, NULL
, NULL
,
1808 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
1809 CTLTYPE_INT
, "keepintvl",
1810 SYSCTL_DESCR("Ticks before next keepalive probe is sent"),
1811 sysctl_tcp_keep
, 0, &tcp_keepintvl
, 0,
1812 CTL_NET
, pf
, IPPROTO_TCP
, TCPCTL_KEEPINTVL
, CTL_EOL
);
1813 sysctl_createv(clog
, 0, NULL
, NULL
,
1814 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
1815 CTLTYPE_INT
, "keepcnt",
1816 SYSCTL_DESCR("Number of keepalive probes to send"),
1817 sysctl_tcp_keep
, 0, &tcp_keepcnt
, 0,
1818 CTL_NET
, pf
, IPPROTO_TCP
, TCPCTL_KEEPCNT
, CTL_EOL
);
1819 sysctl_createv(clog
, 0, NULL
, NULL
,
1820 CTLFLAG_PERMANENT
|CTLFLAG_IMMEDIATE
,
1821 CTLTYPE_INT
, "slowhz",
1822 SYSCTL_DESCR("Keepalive ticks per second"),
1823 NULL
, PR_SLOWHZ
, NULL
, 0,
1824 CTL_NET
, pf
, IPPROTO_TCP
, TCPCTL_SLOWHZ
, CTL_EOL
);
1825 sysctl_createv(clog
, 0, NULL
, NULL
,
1826 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
1827 CTLTYPE_INT
, "log_refused",
1828 SYSCTL_DESCR("Log refused TCP connections"),
1829 NULL
, 0, &tcp_log_refused
, 0,
1830 CTL_NET
, pf
, IPPROTO_TCP
, TCPCTL_LOG_REFUSED
, CTL_EOL
);
1831 #if 0 /* obsoleted */
1832 sysctl_createv(clog
, 0, NULL
, NULL
,
1833 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
1834 CTLTYPE_INT
, "rstratelimit", NULL
,
1835 NULL
, 0, &tcp_rst_ratelim
, 0,
1836 CTL_NET
, pf
, IPPROTO_TCP
, TCPCTL_RSTRATELIMIT
, CTL_EOL
);
1838 sysctl_createv(clog
, 0, NULL
, NULL
,
1839 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
1840 CTLTYPE_INT
, "rstppslimit",
1841 SYSCTL_DESCR("Maximum number of RST packets to send "
1843 NULL
, 0, &tcp_rst_ppslim
, 0,
1844 CTL_NET
, pf
, IPPROTO_TCP
, TCPCTL_RSTPPSLIMIT
, CTL_EOL
);
1845 sysctl_createv(clog
, 0, NULL
, NULL
,
1846 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
1847 CTLTYPE_INT
, "delack_ticks",
1848 SYSCTL_DESCR("Number of ticks to delay sending an ACK"),
1849 NULL
, 0, &tcp_delack_ticks
, 0,
1850 CTL_NET
, pf
, IPPROTO_TCP
, TCPCTL_DELACK_TICKS
, CTL_EOL
);
1851 sysctl_createv(clog
, 0, NULL
, NULL
,
1852 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
1853 CTLTYPE_INT
, "init_win_local",
1854 SYSCTL_DESCR("Initial TCP window size (in segments)"),
1855 NULL
, 0, &tcp_init_win_local
, 0,
1856 CTL_NET
, pf
, IPPROTO_TCP
, TCPCTL_INIT_WIN_LOCAL
,
1858 sysctl_createv(clog
, 0, NULL
, NULL
,
1859 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
1860 CTLTYPE_STRUCT
, "ident",
1861 SYSCTL_DESCR("RFC1413 Identification Protocol lookups"),
1862 sysctl_net_inet_tcp_ident
, 0, NULL
, sizeof(uid_t
),
1863 CTL_NET
, pf
, IPPROTO_TCP
, TCPCTL_IDENT
, CTL_EOL
);
1864 sysctl_createv(clog
, 0, NULL
, NULL
,
1865 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
1866 CTLTYPE_INT
, "do_loopback_cksum",
1867 SYSCTL_DESCR("Perform TCP checksum on loopback"),
1868 NULL
, 0, &tcp_do_loopback_cksum
, 0,
1869 CTL_NET
, pf
, IPPROTO_TCP
, TCPCTL_LOOPBACKCKSUM
,
1871 sysctl_createv(clog
, 0, NULL
, NULL
,
1873 CTLTYPE_STRUCT
, "pcblist",
1874 SYSCTL_DESCR("TCP protocol control block list"),
1875 sysctl_inpcblist
, 0, &tcbtable
, 0,
1876 CTL_NET
, pf
, IPPROTO_TCP
, CTL_CREATE
,
1878 sysctl_createv(clog
, 0, NULL
, NULL
,
1879 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
1880 CTLTYPE_INT
, "keepinit",
1881 SYSCTL_DESCR("Ticks before initial tcp connection times out"),
1882 sysctl_tcp_keep
, 0, &tcp_keepinit
, 0,
1883 CTL_NET
, pf
, IPPROTO_TCP
, CTL_CREATE
, CTL_EOL
);
1885 /* TCP socket buffers auto-sizing nodes */
1886 sysctl_createv(clog
, 0, NULL
, NULL
,
1887 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
1888 CTLTYPE_INT
, "recvbuf_auto",
1889 SYSCTL_DESCR("Enable automatic receive "
1890 "buffer sizing (experimental)"),
1891 NULL
, 0, &tcp_do_autorcvbuf
, 0,
1892 CTL_NET
, pf
, IPPROTO_TCP
, CTL_CREATE
, CTL_EOL
);
1893 sysctl_createv(clog
, 0, NULL
, NULL
,
1894 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
1895 CTLTYPE_INT
, "recvbuf_inc",
1896 SYSCTL_DESCR("Incrementor step size of "
1897 "automatic receive buffer"),
1898 NULL
, 0, &tcp_autorcvbuf_inc
, 0,
1899 CTL_NET
, pf
, IPPROTO_TCP
, CTL_CREATE
, CTL_EOL
);
1900 sysctl_createv(clog
, 0, NULL
, NULL
,
1901 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
1902 CTLTYPE_INT
, "recvbuf_max",
1903 SYSCTL_DESCR("Max size of automatic receive buffer"),
1904 NULL
, 0, &tcp_autorcvbuf_max
, 0,
1905 CTL_NET
, pf
, IPPROTO_TCP
, CTL_CREATE
, CTL_EOL
);
1907 sysctl_createv(clog
, 0, NULL
, NULL
,
1908 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
1909 CTLTYPE_INT
, "sendbuf_auto",
1910 SYSCTL_DESCR("Enable automatic send "
1911 "buffer sizing (experimental)"),
1912 NULL
, 0, &tcp_do_autosndbuf
, 0,
1913 CTL_NET
, pf
, IPPROTO_TCP
, CTL_CREATE
, CTL_EOL
);
1914 sysctl_createv(clog
, 0, NULL
, NULL
,
1915 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
1916 CTLTYPE_INT
, "sendbuf_inc",
1917 SYSCTL_DESCR("Incrementor step size of "
1918 "automatic send buffer"),
1919 NULL
, 0, &tcp_autosndbuf_inc
, 0,
1920 CTL_NET
, pf
, IPPROTO_TCP
, CTL_CREATE
, CTL_EOL
);
1921 sysctl_createv(clog
, 0, NULL
, NULL
,
1922 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
1923 CTLTYPE_INT
, "sendbuf_max",
1924 SYSCTL_DESCR("Max size of automatic send buffer"),
1925 NULL
, 0, &tcp_autosndbuf_max
, 0,
1926 CTL_NET
, pf
, IPPROTO_TCP
, CTL_CREATE
, CTL_EOL
);
1929 sysctl_createv(clog
, 0, NULL
, &ecn_node
,
1931 CTLTYPE_NODE
, "ecn",
1932 SYSCTL_DESCR("RFC3168 Explicit Congestion Notification"),
1934 CTL_NET
, pf
, IPPROTO_TCP
, CTL_CREATE
, CTL_EOL
);
1935 sysctl_createv(clog
, 0, &ecn_node
, NULL
,
1936 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
1937 CTLTYPE_INT
, "enable",
1938 SYSCTL_DESCR("Enable TCP Explicit Congestion "
1940 NULL
, 0, &tcp_do_ecn
, 0, CTL_CREATE
, CTL_EOL
);
1941 sysctl_createv(clog
, 0, &ecn_node
, NULL
,
1942 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
1943 CTLTYPE_INT
, "maxretries",
1944 SYSCTL_DESCR("Number of times to retry ECN setup "
1945 "before disabling ECN on the connection"),
1946 NULL
, 0, &tcp_ecn_maxretries
, 0, CTL_CREATE
, CTL_EOL
);
1948 /* SACK gets it's own little subtree. */
1949 sysctl_createv(clog
, 0, NULL
, &sack_node
,
1950 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
1951 CTLTYPE_INT
, "enable",
1952 SYSCTL_DESCR("Enable RFC2018 Selective ACKnowledgement"),
1953 NULL
, 0, &tcp_do_sack
, 0,
1954 CTL_NET
, pf
, IPPROTO_TCP
, TCPCTL_SACK
, CTL_CREATE
, CTL_EOL
);
1955 sysctl_createv(clog
, 0, NULL
, &sack_node
,
1956 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
1957 CTLTYPE_INT
, "maxholes",
1958 SYSCTL_DESCR("Maximum number of TCP SACK holes allowed per connection"),
1959 NULL
, 0, &tcp_sack_tp_maxholes
, 0,
1960 CTL_NET
, pf
, IPPROTO_TCP
, TCPCTL_SACK
, CTL_CREATE
, CTL_EOL
);
1961 sysctl_createv(clog
, 0, NULL
, &sack_node
,
1962 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
1963 CTLTYPE_INT
, "globalmaxholes",
1964 SYSCTL_DESCR("Global maximum number of TCP SACK holes"),
1965 NULL
, 0, &tcp_sack_globalmaxholes
, 0,
1966 CTL_NET
, pf
, IPPROTO_TCP
, TCPCTL_SACK
, CTL_CREATE
, CTL_EOL
);
1967 sysctl_createv(clog
, 0, NULL
, &sack_node
,
1969 CTLTYPE_INT
, "globalholes",
1970 SYSCTL_DESCR("Global number of TCP SACK holes"),
1971 NULL
, 0, &tcp_sack_globalholes
, 0,
1972 CTL_NET
, pf
, IPPROTO_TCP
, TCPCTL_SACK
, CTL_CREATE
, CTL_EOL
);
1974 sysctl_createv(clog
, 0, NULL
, NULL
,
1976 CTLTYPE_STRUCT
, "stats",
1977 SYSCTL_DESCR("TCP statistics"),
1978 sysctl_net_inet_tcp_stats
, 0, NULL
, 0,
1979 CTL_NET
, pf
, IPPROTO_TCP
, TCPCTL_STATS
,
1982 sysctl_createv(clog
, 0, NULL
, NULL
,
1984 CTLTYPE_STRUCT
, "debug",
1985 SYSCTL_DESCR("TCP sockets debug information"),
1986 NULL
, 0, &tcp_debug
, sizeof(tcp_debug
),
1987 CTL_NET
, pf
, IPPROTO_TCP
, TCPCTL_DEBUG
,
1989 sysctl_createv(clog
, 0, NULL
, NULL
,
1991 CTLTYPE_INT
, "debx",
1992 SYSCTL_DESCR("Number of TCP debug sockets messages"),
1993 NULL
, 0, &tcp_debx
, sizeof(tcp_debx
),
1994 CTL_NET
, pf
, IPPROTO_TCP
, TCPCTL_DEBX
,
1997 sysctl_createv(clog
, 0, NULL
, NULL
,
1998 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
1999 CTLTYPE_STRUCT
, "drop",
2000 SYSCTL_DESCR("TCP drop connection"),
2001 sysctl_net_inet_tcp_drop
, 0, NULL
, 0,
2002 CTL_NET
, pf
, IPPROTO_TCP
, TCPCTL_DROP
, CTL_EOL
);
2004 sysctl_createv(clog
, 0, NULL
, NULL
,
2005 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
2006 CTLTYPE_INT
, "iss_hash",
2007 SYSCTL_DESCR("Enable RFC 1948 ISS by cryptographic "
2008 "hash computation"),
2009 NULL
, 0, &tcp_do_rfc1948
, sizeof(tcp_do_rfc1948
),
2010 CTL_NET
, pf
, IPPROTO_TCP
, CTL_CREATE
,
2016 sysctl_createv(clog
, 0, NULL
, &abc_node
,
2017 CTLFLAG_PERMANENT
, CTLTYPE_NODE
, "abc",
2018 SYSCTL_DESCR("RFC3465 Appropriate Byte Counting (ABC)"),
2020 CTL_NET
, pf
, IPPROTO_TCP
, CTL_CREATE
, CTL_EOL
);
2021 sysctl_createv(clog
, 0, &abc_node
, NULL
,
2022 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
2023 CTLTYPE_INT
, "enable",
2024 SYSCTL_DESCR("Enable RFC3465 Appropriate Byte Counting"),
2025 NULL
, 0, &tcp_do_abc
, 0, CTL_CREATE
, CTL_EOL
);
2026 sysctl_createv(clog
, 0, &abc_node
, NULL
,
2027 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
2028 CTLTYPE_INT
, "aggressive",
2029 SYSCTL_DESCR("1: L=2*SMSS 0: L=1*SMSS"),
2030 NULL
, 0, &tcp_abc_aggressive
, 0, CTL_CREATE
, CTL_EOL
);
2034 tcp_usrreq_init(void)
2038 sysctl_net_inet_tcp_setup2(NULL
, PF_INET
, "inet", "tcp");
2041 sysctl_net_inet_tcp_setup2(NULL
, PF_INET6
, "inet6", "tcp6");