2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 1982, 1986, 1988, 1993
5 * The Regents of the University of California.
6 * Copyright (c) 2006-2007 Robert N. M. Watson
7 * Copyright (c) 2010-2011 Juniper Networks, Inc.
10 * Portions of this software were developed by Robert N. M. Watson under
11 * contract to Juniper Networks, Inc.
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its contributors
22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * From: @(#)tcp_usrreq.c 8.2 (Berkeley) 1/3/94
40 #include <sys/cdefs.h>
41 __FBSDID("$FreeBSD$");
45 #include "opt_inet6.h"
46 #include "opt_ipsec.h"
47 #include "opt_kern_tls.h"
48 #include "opt_tcpdebug.h"
50 #include <sys/param.h>
51 #include <sys/systm.h>
53 #include <sys/limits.h>
54 #include <sys/malloc.h>
55 #include <sys/refcount.h>
56 #include <sys/kernel.h>
58 #include <sys/qmath.h>
59 #include <sys/sysctl.h>
62 #include <sys/domain.h>
64 #include <sys/socket.h>
65 #include <sys/socketvar.h>
66 #include <sys/protosw.h>
69 #include <sys/syslog.h>
70 #include <sys/stats.h>
77 #include <net/if_var.h>
78 #include <net/route.h>
81 #include <netinet/in.h>
82 #include <netinet/in_kdtrace.h>
83 #include <netinet/in_pcb.h>
84 #include <netinet/in_systm.h>
85 #include <netinet/in_var.h>
86 #include <netinet/ip_var.h>
88 #include <netinet/ip6.h>
89 #include <netinet6/in6_pcb.h>
90 #include <netinet6/ip6_var.h>
91 #include <netinet6/scope6_var.h>
93 #include <netinet/tcp.h>
94 #include <netinet/tcp_fsm.h>
95 #include <netinet/tcp_seq.h>
96 #include <netinet/tcp_timer.h>
97 #include <netinet/tcp_var.h>
98 #include <netinet/tcp_log_buf.h>
99 #include <netinet/tcpip.h>
100 #include <netinet/cc/cc.h>
101 #include <netinet/tcp_fastopen.h>
102 #include <netinet/tcp_hpts.h>
104 #include <netinet/tcp_pcap.h>
107 #include <netinet/tcp_debug.h>
110 #include <netinet/tcp_offload.h>
112 #include <netipsec/ipsec_support.h>
115 #include <vm/vm_param.h>
117 #include <vm/vm_extern.h>
118 #include <vm/vm_map.h>
119 #include <vm/vm_page.h>
122 * TCP protocol interface to socket abstraction.
125 static int tcp_connect(struct tcpcb *, struct sockaddr *,
129 static int tcp6_connect(struct tcpcb *, struct sockaddr *,
132 static void tcp_disconnect(struct tcpcb *);
133 static void tcp_usrclosed(struct tcpcb *);
134 static void tcp_fill_info(struct tcpcb *, struct tcp_info *);
137 #define TCPDEBUG0 int ostate = 0
138 #define TCPDEBUG1() ostate = tp ? tp->t_state : 0
139 #define TCPDEBUG2(req) if (tp && (so->so_options & SO_DEBUG)) \
140 tcp_trace(TA_USER, ostate, tp, 0, 0, req)
144 #define TCPDEBUG2(req)
148 * TCP attaches to socket via pru_attach(), reserving space,
149 * and an internet control block.
152 tcp_usr_attach(struct socket *so, int proto, struct thread *td)
155 struct tcpcb *tp = NULL;
160 KASSERT(inp == NULL, ("tcp_usr_attach: inp != NULL"));
163 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
164 error = soreserve(so, V_tcp_sendspace, V_tcp_recvspace);
169 so->so_rcv.sb_flags |= SB_AUTOSIZE;
170 so->so_snd.sb_flags |= SB_AUTOSIZE;
171 error = in_pcballoc(so, &V_tcbinfo);
176 if (inp->inp_vflag & INP_IPV6PROTO) {
177 inp->inp_vflag |= INP_IPV6;
178 if ((inp->inp_flags & IN6P_IPV6_V6ONLY) == 0)
179 inp->inp_vflag |= INP_IPV4;
180 inp->in6p_hops = -1; /* use kernel default */
184 inp->inp_vflag |= INP_IPV4;
185 tp = tcp_newtcpcb(inp);
192 tp->t_state = TCPS_CLOSED;
194 TCPSTATES_INC(TCPS_CLOSED);
195 if ((so->so_options & SO_LINGER) && so->so_linger == 0)
196 so->so_linger = TCP_LINGERTIME;
198 TCPDEBUG2(PRU_ATTACH);
199 TCP_PROBE2(debug__user, tp, PRU_ATTACH);
204 * tcp_usr_detach is called when the socket layer loses its final reference
205 * to the socket, be it a file descriptor reference, a reference from TCP,
206 * etc. At this point, there is only one case in which we will keep around
207 * inpcb state: time wait.
210 tcp_usr_detach(struct socket *so)
216 KASSERT(inp != NULL, ("%s: inp == NULL", __func__));
218 KASSERT(so->so_pcb == inp && inp->inp_socket == so,
219 ("%s: socket %p inp %p mismatch", __func__, so, inp));
223 if (inp->inp_flags & INP_TIMEWAIT) {
225 * There are two cases to handle: one in which the time wait
226 * state is being discarded (INP_DROPPED), and one in which
227 * this connection will remain in timewait. In the former,
228 * it is time to discard all state (except tcptw, which has
229 * already been discarded by the timewait close code, which
230 * should be further up the call stack somewhere). In the
231 * latter case, we detach from the socket, but leave the pcb
232 * present until timewait ends.
234 * XXXRW: Would it be cleaner to free the tcptw here?
236 * Astute question indeed, from twtcp perspective there are
237 * four cases to consider:
239 * #1 tcp_usr_detach is called at tcptw creation time by
240 * tcp_twstart, then do not discard the newly created tcptw
241 * and leave inpcb present until timewait ends
242 * #2 tcp_usr_detach is called at tcptw creation time by
243 * tcp_twstart, but connection is local and tw will be
244 * discarded immediately
245 * #3 tcp_usr_detach is called at timewait end (or reuse) by
246 * tcp_twclose, then the tcptw has already been discarded
247 * (or reused) and inpcb is freed here
248 * #4 tcp_usr_detach is called() after timewait ends (or reuse)
249 * (e.g. by soclose), then tcptw has already been discarded
250 * (or reused) and inpcb is freed here
252 * In all three cases the tcptw should not be freed here.
254 if (inp->inp_flags & INP_DROPPED) {
256 if (__predict_true(tp == NULL)) {
260 * This case should not happen as in TIMEWAIT
261 * state the inp should not be destroyed before
262 * its tcptw. If INVARIANTS is defined, panic.
265 panic("%s: Panic before an inp double-free: "
266 "INP_TIMEWAIT && INP_DROPPED && tp != NULL"
269 log(LOG_ERR, "%s: Avoid an inp double-free: "
270 "INP_TIMEWAIT && INP_DROPPED && tp != NULL"
281 * If the connection is not in timewait, we consider two
282 * two conditions: one in which no further processing is
283 * necessary (dropped || embryonic), and one in which TCP is
284 * not yet done, but no longer requires the socket, so the
285 * pcb will persist for the time being.
287 * XXXRW: Does the second case still occur?
289 if (inp->inp_flags & INP_DROPPED ||
290 tp->t_state < TCPS_SYN_SENT) {
303 * Give the socket an address.
306 tcp_usr_bind(struct socket *so, struct sockaddr *nam, struct thread *td)
310 struct tcpcb *tp = NULL;
311 struct sockaddr_in *sinp;
313 sinp = (struct sockaddr_in *)nam;
314 if (nam->sa_len != sizeof (*sinp))
317 * Must check for multicast addresses and disallow binding
320 if (sinp->sin_family == AF_INET &&
321 IN_MULTICAST(ntohl(sinp->sin_addr.s_addr)))
322 return (EAFNOSUPPORT);
326 KASSERT(inp != NULL, ("tcp_usr_bind: inp == NULL"));
328 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
334 INP_HASH_WLOCK(&V_tcbinfo);
335 error = in_pcbbind(inp, nam, td->td_ucred);
336 INP_HASH_WUNLOCK(&V_tcbinfo);
339 TCP_PROBE2(debug__user, tp, PRU_BIND);
348 tcp6_usr_bind(struct socket *so, struct sockaddr *nam, struct thread *td)
352 struct tcpcb *tp = NULL;
353 struct sockaddr_in6 *sin6;
356 sin6 = (struct sockaddr_in6 *)nam;
357 if (nam->sa_len != sizeof (*sin6))
360 * Must check for multicast addresses and disallow binding
363 if (sin6->sin6_family == AF_INET6 &&
364 IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr))
365 return (EAFNOSUPPORT);
369 KASSERT(inp != NULL, ("tcp6_usr_bind: inp == NULL"));
371 vflagsav = inp->inp_vflag;
372 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
378 INP_HASH_WLOCK(&V_tcbinfo);
379 inp->inp_vflag &= ~INP_IPV4;
380 inp->inp_vflag |= INP_IPV6;
382 if ((inp->inp_flags & IN6P_IPV6_V6ONLY) == 0) {
383 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr))
384 inp->inp_vflag |= INP_IPV4;
385 else if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
386 struct sockaddr_in sin;
388 in6_sin6_2_sin(&sin, sin6);
389 if (IN_MULTICAST(ntohl(sin.sin_addr.s_addr))) {
390 error = EAFNOSUPPORT;
391 INP_HASH_WUNLOCK(&V_tcbinfo);
394 inp->inp_vflag |= INP_IPV4;
395 inp->inp_vflag &= ~INP_IPV6;
396 error = in_pcbbind(inp, (struct sockaddr *)&sin,
398 INP_HASH_WUNLOCK(&V_tcbinfo);
403 error = in6_pcbbind(inp, nam, td->td_ucred);
404 INP_HASH_WUNLOCK(&V_tcbinfo);
407 inp->inp_vflag = vflagsav;
409 TCP_PROBE2(debug__user, tp, PRU_BIND);
417 * Prepare to accept connections.
420 tcp_usr_listen(struct socket *so, int backlog, struct thread *td)
424 struct tcpcb *tp = NULL;
428 KASSERT(inp != NULL, ("tcp_usr_listen: inp == NULL"));
430 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
437 error = solisten_proto_check(so);
438 INP_HASH_WLOCK(&V_tcbinfo);
439 if (error == 0 && inp->inp_lport == 0)
440 error = in_pcbbind(inp, (struct sockaddr *)0, td->td_ucred);
441 INP_HASH_WUNLOCK(&V_tcbinfo);
443 tcp_state_change(tp, TCPS_LISTEN);
444 solisten_proto(so, backlog);
446 if ((so->so_options & SO_NO_OFFLOAD) == 0)
447 tcp_offload_listen_start(tp);
452 if (IS_FASTOPEN(tp->t_flags))
453 tp->t_tfo_pending = tcp_fastopen_alloc_counter();
456 TCPDEBUG2(PRU_LISTEN);
457 TCP_PROBE2(debug__user, tp, PRU_LISTEN);
465 tcp6_usr_listen(struct socket *so, int backlog, struct thread *td)
469 struct tcpcb *tp = NULL;
474 KASSERT(inp != NULL, ("tcp6_usr_listen: inp == NULL"));
476 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
480 vflagsav = inp->inp_vflag;
484 error = solisten_proto_check(so);
485 INP_HASH_WLOCK(&V_tcbinfo);
486 if (error == 0 && inp->inp_lport == 0) {
487 inp->inp_vflag &= ~INP_IPV4;
488 if ((inp->inp_flags & IN6P_IPV6_V6ONLY) == 0)
489 inp->inp_vflag |= INP_IPV4;
490 error = in6_pcbbind(inp, (struct sockaddr *)0, td->td_ucred);
492 INP_HASH_WUNLOCK(&V_tcbinfo);
494 tcp_state_change(tp, TCPS_LISTEN);
495 solisten_proto(so, backlog);
497 if ((so->so_options & SO_NO_OFFLOAD) == 0)
498 tcp_offload_listen_start(tp);
503 if (IS_FASTOPEN(tp->t_flags))
504 tp->t_tfo_pending = tcp_fastopen_alloc_counter();
507 inp->inp_vflag = vflagsav;
510 TCPDEBUG2(PRU_LISTEN);
511 TCP_PROBE2(debug__user, tp, PRU_LISTEN);
519 * Initiate connection to peer.
520 * Create a template for use in transmissions on this connection.
521 * Enter SYN_SENT state, and mark socket as connecting.
522 * Start keep-alive timer, and seed output sequence space.
523 * Send initial segment on connection.
526 tcp_usr_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
528 struct epoch_tracker et;
531 struct tcpcb *tp = NULL;
532 struct sockaddr_in *sinp;
534 sinp = (struct sockaddr_in *)nam;
535 if (nam->sa_len != sizeof (*sinp))
538 * Must disallow TCP ``connections'' to multicast addresses.
540 if (sinp->sin_family == AF_INET
541 && IN_MULTICAST(ntohl(sinp->sin_addr.s_addr)))
542 return (EAFNOSUPPORT);
543 if ((error = prison_remote_ip4(td->td_ucred, &sinp->sin_addr)) != 0)
548 KASSERT(inp != NULL, ("tcp_usr_connect: inp == NULL"));
550 if (inp->inp_flags & INP_TIMEWAIT) {
554 if (inp->inp_flags & INP_DROPPED) {
555 error = ECONNREFUSED;
560 if ((error = tcp_connect(tp, nam, td)) != 0)
563 if (registered_toedevs > 0 &&
564 (so->so_options & SO_NO_OFFLOAD) == 0 &&
565 (error = tcp_offload_connect(so, nam)) == 0)
568 tcp_timer_activate(tp, TT_KEEP, TP_KEEPINIT(tp));
570 error = tp->t_fb->tfb_tcp_output(tp);
573 TCPDEBUG2(PRU_CONNECT);
574 TCP_PROBE2(debug__user, tp, PRU_CONNECT);
582 tcp6_usr_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
584 struct epoch_tracker et;
587 struct tcpcb *tp = NULL;
588 struct sockaddr_in6 *sin6;
594 sin6 = (struct sockaddr_in6 *)nam;
595 if (nam->sa_len != sizeof (*sin6))
598 * Must disallow TCP ``connections'' to multicast addresses.
600 if (sin6->sin6_family == AF_INET6
601 && IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr))
602 return (EAFNOSUPPORT);
605 KASSERT(inp != NULL, ("tcp6_usr_connect: inp == NULL"));
607 vflagsav = inp->inp_vflag;
608 incflagsav = inp->inp_inc.inc_flags;
609 if (inp->inp_flags & INP_TIMEWAIT) {
613 if (inp->inp_flags & INP_DROPPED) {
614 error = ECONNREFUSED;
621 * XXXRW: Some confusion: V4/V6 flags relate to binding, and
622 * therefore probably require the hash lock, which isn't held here.
623 * Is this a significant problem?
625 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
626 struct sockaddr_in sin;
628 if ((inp->inp_flags & IN6P_IPV6_V6ONLY) != 0) {
632 if ((inp->inp_vflag & INP_IPV4) == 0) {
633 error = EAFNOSUPPORT;
637 in6_sin6_2_sin(&sin, sin6);
638 if (IN_MULTICAST(ntohl(sin.sin_addr.s_addr))) {
639 error = EAFNOSUPPORT;
642 if ((error = prison_remote_ip4(td->td_ucred,
643 &sin.sin_addr)) != 0)
645 inp->inp_vflag |= INP_IPV4;
646 inp->inp_vflag &= ~INP_IPV6;
647 if ((error = tcp_connect(tp, (struct sockaddr *)&sin, td)) != 0)
650 if (registered_toedevs > 0 &&
651 (so->so_options & SO_NO_OFFLOAD) == 0 &&
652 (error = tcp_offload_connect(so, nam)) == 0)
656 error = tp->t_fb->tfb_tcp_output(tp);
660 if ((inp->inp_vflag & INP_IPV6) == 0) {
661 error = EAFNOSUPPORT;
666 if ((error = prison_remote_ip6(td->td_ucred, &sin6->sin6_addr)) != 0)
668 inp->inp_vflag &= ~INP_IPV4;
669 inp->inp_vflag |= INP_IPV6;
670 inp->inp_inc.inc_flags |= INC_ISIPV6;
671 if ((error = tcp6_connect(tp, nam, td)) != 0)
674 if (registered_toedevs > 0 &&
675 (so->so_options & SO_NO_OFFLOAD) == 0 &&
676 (error = tcp_offload_connect(so, nam)) == 0)
679 tcp_timer_activate(tp, TT_KEEP, TP_KEEPINIT(tp));
681 error = tp->t_fb->tfb_tcp_output(tp);
685 * If the implicit bind in the connect call fails, restore
686 * the flags we modified.
688 if (error != 0 && inp->inp_lport == 0) {
689 inp->inp_vflag = vflagsav;
690 inp->inp_inc.inc_flags = incflagsav;
693 TCPDEBUG2(PRU_CONNECT);
694 TCP_PROBE2(debug__user, tp, PRU_CONNECT);
701 * Initiate disconnect from peer.
702 * If connection never passed embryonic stage, just drop;
703 * else if don't need to let data drain, then can just drop anyways,
704 * else have to begin TCP shutdown process: mark socket disconnecting,
705 * drain unread data, state switch to reflect user close, and
706 * send segment (e.g. FIN) to peer. Socket will be really disconnected
707 * when peer sends FIN and acks ours.
709 * SHOULD IMPLEMENT LATER PRU_CONNECT VIA REALLOC TCPCB.
712 tcp_usr_disconnect(struct socket *so)
715 struct tcpcb *tp = NULL;
716 struct epoch_tracker et;
722 KASSERT(inp != NULL, ("tcp_usr_disconnect: inp == NULL"));
724 if (inp->inp_flags & INP_TIMEWAIT)
726 if (inp->inp_flags & INP_DROPPED) {
734 TCPDEBUG2(PRU_DISCONNECT);
735 TCP_PROBE2(debug__user, tp, PRU_DISCONNECT);
743 * Accept a connection. Essentially all the work is done at higher levels;
744 * just return the address of the peer, storing through addr.
747 tcp_usr_accept(struct socket *so, struct sockaddr **nam)
750 struct inpcb *inp = NULL;
751 struct tcpcb *tp = NULL;
756 if (so->so_state & SS_ISDISCONNECTED)
757 return (ECONNABORTED);
760 KASSERT(inp != NULL, ("tcp_usr_accept: inp == NULL"));
762 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
763 error = ECONNABORTED;
770 * We inline in_getpeeraddr and COMMON_END here, so that we can
771 * copy the data of interest and defer the malloc until after we
774 port = inp->inp_fport;
775 addr = inp->inp_faddr;
778 TCPDEBUG2(PRU_ACCEPT);
779 TCP_PROBE2(debug__user, tp, PRU_ACCEPT);
782 *nam = in_sockaddr(port, &addr);
789 tcp6_usr_accept(struct socket *so, struct sockaddr **nam)
791 struct inpcb *inp = NULL;
793 struct tcpcb *tp = NULL;
795 struct in6_addr addr6;
796 struct epoch_tracker et;
801 if (so->so_state & SS_ISDISCONNECTED)
802 return (ECONNABORTED);
805 KASSERT(inp != NULL, ("tcp6_usr_accept: inp == NULL"));
808 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
809 error = ECONNABORTED;
816 * We inline in6_mapped_peeraddr and COMMON_END here, so that we can
817 * copy the data of interest and defer the malloc until after we
820 if (inp->inp_vflag & INP_IPV4) {
822 port = inp->inp_fport;
823 addr = inp->inp_faddr;
825 port = inp->inp_fport;
826 addr6 = inp->in6p_faddr;
830 TCPDEBUG2(PRU_ACCEPT);
831 TCP_PROBE2(debug__user, tp, PRU_ACCEPT);
836 *nam = in6_v4mapsin6_sockaddr(port, &addr);
838 *nam = in6_sockaddr(port, &addr6);
845 * Mark the connection as being incapable of further output.
848 tcp_usr_shutdown(struct socket *so)
852 struct tcpcb *tp = NULL;
853 struct epoch_tracker et;
858 KASSERT(inp != NULL, ("inp == NULL"));
860 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
868 if (!(inp->inp_flags & INP_DROPPED))
869 error = tp->t_fb->tfb_tcp_output(tp);
872 TCPDEBUG2(PRU_SHUTDOWN);
873 TCP_PROBE2(debug__user, tp, PRU_SHUTDOWN);
881 * After a receive, possibly send window update to peer.
884 tcp_usr_rcvd(struct socket *so, int flags)
886 struct epoch_tracker et;
888 struct tcpcb *tp = NULL;
893 KASSERT(inp != NULL, ("tcp_usr_rcvd: inp == NULL"));
895 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
902 * For passively-created TFO connections, don't attempt a window
903 * update while still in SYN_RECEIVED as this may trigger an early
904 * SYN|ACK. It is preferable to have the SYN|ACK be sent along with
905 * application response data, or failing that, when the DELACK timer
908 if (IS_FASTOPEN(tp->t_flags) &&
909 (tp->t_state == TCPS_SYN_RECEIVED))
912 if (tp->t_flags & TF_TOE)
913 tcp_offload_rcvd(tp);
917 tp->t_fb->tfb_tcp_output(tp);
921 TCP_PROBE2(debug__user, tp, PRU_RCVD);
927 * Do a send by putting data in output queue and updating urgent
928 * marker if URG set. Possibly send more data. Unlike the other
929 * pru_*() routines, the mbuf chains are our responsibility. We
930 * must either enqueue them or free them. The other pru_* routines
931 * generally are caller-frees.
934 tcp_usr_send(struct socket *so, int flags, struct mbuf *m,
935 struct sockaddr *nam, struct mbuf *control, struct thread *td)
937 struct epoch_tracker et;
940 struct tcpcb *tp = NULL;
943 struct sockaddr_in sin;
945 struct sockaddr_in *sinp;
956 * We require the pcbinfo "read lock" if we will close the socket
957 * as part of this call.
961 KASSERT(inp != NULL, ("tcp_usr_send: inp == NULL"));
963 vflagsav = inp->inp_vflag;
964 incflagsav = inp->inp_inc.inc_flags;
965 restoreflags = false;
966 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
970 * In case of PRUS_NOTREADY, tcp_usr_ready() is responsible
971 * for freeing memory.
973 if (m && (flags & PRUS_NOTREADY) == 0)
980 if (nam != NULL && tp->t_state < TCPS_SYN_SENT) {
981 switch (nam->sa_family) {
984 sinp = (struct sockaddr_in *)nam;
985 if (sinp->sin_len != sizeof(struct sockaddr_in)) {
991 if ((inp->inp_vflag & INP_IPV6) != 0) {
994 error = EAFNOSUPPORT;
997 if (IN_MULTICAST(ntohl(sinp->sin_addr.s_addr))) {
1000 error = EAFNOSUPPORT;
1003 if ((error = prison_remote_ip4(td->td_ucred,
1004 &sinp->sin_addr))) {
1017 struct sockaddr_in6 *sin6;
1019 sin6 = (struct sockaddr_in6 *)nam;
1020 if (sin6->sin6_len != sizeof(*sin6)) {
1026 if (IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr)) {
1029 error = EAFNOSUPPORT;
1032 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
1034 if ((inp->inp_flags & IN6P_IPV6_V6ONLY) != 0) {
1040 if ((inp->inp_vflag & INP_IPV4) == 0) {
1041 error = EAFNOSUPPORT;
1046 restoreflags = true;
1047 inp->inp_vflag &= ~INP_IPV6;
1049 in6_sin6_2_sin(sinp, sin6);
1051 ntohl(sinp->sin_addr.s_addr))) {
1052 error = EAFNOSUPPORT;
1057 if ((error = prison_remote_ip4(td->td_ucred,
1058 &sinp->sin_addr))) {
1065 error = EAFNOSUPPORT;
1071 if ((inp->inp_vflag & INP_IPV6) == 0) {
1074 error = EAFNOSUPPORT;
1077 restoreflags = true;
1078 inp->inp_vflag &= ~INP_IPV4;
1079 inp->inp_inc.inc_flags |= INC_ISIPV6;
1080 if ((error = prison_remote_ip6(td->td_ucred,
1081 &sin6->sin6_addr))) {
1094 error = EAFNOSUPPORT;
1099 /* TCP doesn't do control messages (rights, creds, etc) */
1100 if (control->m_len) {
1107 m_freem(control); /* empty control, just free it */
1109 if (!(flags & PRUS_OOB)) {
1110 sbappendstream(&so->so_snd, m, flags);
1111 if (nam && tp->t_state < TCPS_SYN_SENT) {
1113 * Do implied connect if not yet connected,
1114 * initialize window to default value, and
1115 * initialize maxseg using peer's cached MSS.
1119 error = tcp6_connect(tp, nam, td);
1121 #if defined(INET6) && defined(INET)
1125 error = tcp_connect(tp,
1126 (struct sockaddr *)sinp, td);
1129 * The bind operation in tcp_connect succeeded. We
1130 * no longer want to restore the flags if later
1133 if (error == 0 || inp->inp_lport != 0)
1134 restoreflags = false;
1138 if (IS_FASTOPEN(tp->t_flags))
1139 tcp_fastopen_connect(tp);
1141 tp->snd_wnd = TTCP_CLIENT_SND_WND;
1145 if (flags & PRUS_EOF) {
1147 * Close the send side of the connection after
1153 if (!(inp->inp_flags & INP_DROPPED) &&
1154 !(flags & PRUS_NOTREADY)) {
1155 if (flags & PRUS_MORETOCOME)
1156 tp->t_flags |= TF_MORETOCOME;
1157 error = tp->t_fb->tfb_tcp_output(tp);
1158 if (flags & PRUS_MORETOCOME)
1159 tp->t_flags &= ~TF_MORETOCOME;
1163 * XXXRW: PRUS_EOF not implemented with PRUS_OOB?
1165 SOCKBUF_LOCK(&so->so_snd);
1166 if (sbspace(&so->so_snd) < -512) {
1167 SOCKBUF_UNLOCK(&so->so_snd);
1173 * According to RFC961 (Assigned Protocols),
1174 * the urgent pointer points to the last octet
1175 * of urgent data. We continue, however,
1176 * to consider it to indicate the first octet
1177 * of data past the urgent section.
1178 * Otherwise, snd_up should be one lower.
1180 sbappendstream_locked(&so->so_snd, m, flags);
1181 SOCKBUF_UNLOCK(&so->so_snd);
1182 if (nam && tp->t_state < TCPS_SYN_SENT) {
1184 * Do implied connect if not yet connected,
1185 * initialize window to default value, and
1186 * initialize maxseg using peer's cached MSS.
1190 * Not going to contemplate SYN|URG
1192 if (IS_FASTOPEN(tp->t_flags))
1193 tp->t_flags &= ~TF_FASTOPEN;
1196 error = tcp6_connect(tp, nam, td);
1198 #if defined(INET6) && defined(INET)
1202 error = tcp_connect(tp,
1203 (struct sockaddr *)sinp, td);
1206 * The bind operation in tcp_connect succeeded. We
1207 * no longer want to restore the flags if later
1210 if (error == 0 || inp->inp_lport != 0)
1211 restoreflags = false;
1215 tp->snd_wnd = TTCP_CLIENT_SND_WND;
1218 tp->snd_up = tp->snd_una + sbavail(&so->so_snd);
1219 if (!(flags & PRUS_NOTREADY)) {
1220 tp->t_flags |= TF_FORCEDATA;
1221 error = tp->t_fb->tfb_tcp_output(tp);
1222 tp->t_flags &= ~TF_FORCEDATA;
1225 TCP_LOG_EVENT(tp, NULL,
1226 &inp->inp_socket->so_rcv,
1227 &inp->inp_socket->so_snd,
1228 TCP_LOG_USERSEND, error,
1232 * If the request was unsuccessful and we changed flags,
1233 * restore the original flags.
1235 if (error != 0 && restoreflags) {
1236 inp->inp_vflag = vflagsav;
1237 inp->inp_inc.inc_flags = incflagsav;
1239 TCPDEBUG2((flags & PRUS_OOB) ? PRU_SENDOOB :
1240 ((flags & PRUS_EOF) ? PRU_SEND_EOF : PRU_SEND));
1241 TCP_PROBE2(debug__user, tp, (flags & PRUS_OOB) ? PRU_SENDOOB :
1242 ((flags & PRUS_EOF) ? PRU_SEND_EOF : PRU_SEND));
1249 tcp_usr_ready(struct socket *so, struct mbuf *m, int count)
1251 struct epoch_tracker et;
1256 inp = sotoinpcb(so);
1258 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
1260 mb_free_notready(m, count);
1261 return (ECONNRESET);
1263 tp = intotcpcb(inp);
1265 SOCKBUF_LOCK(&so->so_snd);
1266 error = sbready(&so->so_snd, m, count);
1267 SOCKBUF_UNLOCK(&so->so_snd);
1269 NET_EPOCH_ENTER(et);
1270 error = tp->t_fb->tfb_tcp_output(tp);
1279 * Abort the TCP. Drop the connection abruptly.
1282 tcp_usr_abort(struct socket *so)
1285 struct tcpcb *tp = NULL;
1286 struct epoch_tracker et;
1289 inp = sotoinpcb(so);
1290 KASSERT(inp != NULL, ("tcp_usr_abort: inp == NULL"));
1292 NET_EPOCH_ENTER(et);
1294 KASSERT(inp->inp_socket != NULL,
1295 ("tcp_usr_abort: inp_socket == NULL"));
1298 * If we still have full TCP state, and we're not dropped, drop.
1300 if (!(inp->inp_flags & INP_TIMEWAIT) &&
1301 !(inp->inp_flags & INP_DROPPED)) {
1302 tp = intotcpcb(inp);
1304 tp = tcp_drop(tp, ECONNABORTED);
1307 TCPDEBUG2(PRU_ABORT);
1308 TCP_PROBE2(debug__user, tp, PRU_ABORT);
1310 if (!(inp->inp_flags & INP_DROPPED)) {
1312 so->so_state |= SS_PROTOREF;
1314 inp->inp_flags |= INP_SOCKREF;
1322 * TCP socket is closed. Start friendly disconnect.
1325 tcp_usr_close(struct socket *so)
1328 struct tcpcb *tp = NULL;
1329 struct epoch_tracker et;
1332 inp = sotoinpcb(so);
1333 KASSERT(inp != NULL, ("tcp_usr_close: inp == NULL"));
1335 NET_EPOCH_ENTER(et);
1337 KASSERT(inp->inp_socket != NULL,
1338 ("tcp_usr_close: inp_socket == NULL"));
1341 * If we still have full TCP state, and we're not dropped, initiate
1344 if (!(inp->inp_flags & INP_TIMEWAIT) &&
1345 !(inp->inp_flags & INP_DROPPED)) {
1346 tp = intotcpcb(inp);
1349 TCPDEBUG2(PRU_CLOSE);
1350 TCP_PROBE2(debug__user, tp, PRU_CLOSE);
1352 if (!(inp->inp_flags & INP_DROPPED)) {
1354 so->so_state |= SS_PROTOREF;
1356 inp->inp_flags |= INP_SOCKREF;
1363 * Receive out-of-band data.
1366 tcp_usr_rcvoob(struct socket *so, struct mbuf *m, int flags)
1370 struct tcpcb *tp = NULL;
1373 inp = sotoinpcb(so);
1374 KASSERT(inp != NULL, ("tcp_usr_rcvoob: inp == NULL"));
1376 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
1380 tp = intotcpcb(inp);
1382 if ((so->so_oobmark == 0 &&
1383 (so->so_rcv.sb_state & SBS_RCVATMARK) == 0) ||
1384 so->so_options & SO_OOBINLINE ||
1385 tp->t_oobflags & TCPOOB_HADDATA) {
1389 if ((tp->t_oobflags & TCPOOB_HAVEDATA) == 0) {
1390 error = EWOULDBLOCK;
1394 *mtod(m, caddr_t) = tp->t_iobc;
1395 if ((flags & MSG_PEEK) == 0)
1396 tp->t_oobflags ^= (TCPOOB_HAVEDATA | TCPOOB_HADDATA);
1399 TCPDEBUG2(PRU_RCVOOB);
1400 TCP_PROBE2(debug__user, tp, PRU_RCVOOB);
1406 struct pr_usrreqs tcp_usrreqs = {
1407 .pru_abort = tcp_usr_abort,
1408 .pru_accept = tcp_usr_accept,
1409 .pru_attach = tcp_usr_attach,
1410 .pru_bind = tcp_usr_bind,
1411 .pru_connect = tcp_usr_connect,
1412 .pru_control = in_control,
1413 .pru_detach = tcp_usr_detach,
1414 .pru_disconnect = tcp_usr_disconnect,
1415 .pru_listen = tcp_usr_listen,
1416 .pru_peeraddr = in_getpeeraddr,
1417 .pru_rcvd = tcp_usr_rcvd,
1418 .pru_rcvoob = tcp_usr_rcvoob,
1419 .pru_send = tcp_usr_send,
1420 .pru_ready = tcp_usr_ready,
1421 .pru_shutdown = tcp_usr_shutdown,
1422 .pru_sockaddr = in_getsockaddr,
1423 .pru_sosetlabel = in_pcbsosetlabel,
1424 .pru_close = tcp_usr_close,
1429 struct pr_usrreqs tcp6_usrreqs = {
1430 .pru_abort = tcp_usr_abort,
1431 .pru_accept = tcp6_usr_accept,
1432 .pru_attach = tcp_usr_attach,
1433 .pru_bind = tcp6_usr_bind,
1434 .pru_connect = tcp6_usr_connect,
1435 .pru_control = in6_control,
1436 .pru_detach = tcp_usr_detach,
1437 .pru_disconnect = tcp_usr_disconnect,
1438 .pru_listen = tcp6_usr_listen,
1439 .pru_peeraddr = in6_mapped_peeraddr,
1440 .pru_rcvd = tcp_usr_rcvd,
1441 .pru_rcvoob = tcp_usr_rcvoob,
1442 .pru_send = tcp_usr_send,
1443 .pru_ready = tcp_usr_ready,
1444 .pru_shutdown = tcp_usr_shutdown,
1445 .pru_sockaddr = in6_mapped_sockaddr,
1446 .pru_sosetlabel = in_pcbsosetlabel,
1447 .pru_close = tcp_usr_close,
1453 * Common subroutine to open a TCP connection to remote host specified
1454 * by struct sockaddr_in in mbuf *nam. Call in_pcbbind to assign a local
1455 * port number if needed. Call in_pcbconnect_setup to do the routing and
1456 * to choose a local host address (interface). If there is an existing
1457 * incarnation of the same connection in TIME-WAIT state and if the remote
1458 * host was sending CC options and if the connection duration was < MSL, then
1459 * truncate the previous TIME-WAIT state and proceed.
1460 * Initialize connection parameters and enter SYN-SENT state.
1463 tcp_connect(struct tcpcb *tp, struct sockaddr *nam, struct thread *td)
1465 struct inpcb *inp = tp->t_inpcb, *oinp;
1466 struct socket *so = inp->inp_socket;
1467 struct in_addr laddr;
1471 INP_WLOCK_ASSERT(inp);
1472 INP_HASH_WLOCK(&V_tcbinfo);
1474 if (inp->inp_lport == 0) {
1475 error = in_pcbbind(inp, (struct sockaddr *)0, td->td_ucred);
1481 * Cannot simply call in_pcbconnect, because there might be an
1482 * earlier incarnation of this same connection still in
1483 * TIME_WAIT state, creating an ADDRINUSE error.
1485 laddr = inp->inp_laddr;
1486 lport = inp->inp_lport;
1487 error = in_pcbconnect_setup(inp, nam, &laddr.s_addr, &lport,
1488 &inp->inp_faddr.s_addr, &inp->inp_fport, &oinp, td->td_ucred);
1489 if (error && oinp == NULL)
1495 inp->inp_laddr = laddr;
1497 INP_HASH_WUNLOCK(&V_tcbinfo);
1500 * Compute window scaling to request:
1501 * Scale to fit into sweet spot. See tcp_syncache.c.
1502 * XXX: This should move to tcp_output().
1504 while (tp->request_r_scale < TCP_MAX_WINSHIFT &&
1505 (TCP_MAXWIN << tp->request_r_scale) < sb_max)
1506 tp->request_r_scale++;
1509 TCPSTAT_INC(tcps_connattempt);
1510 tcp_state_change(tp, TCPS_SYN_SENT);
1511 tp->iss = tcp_new_isn(&inp->inp_inc);
1512 if (tp->t_flags & TF_REQ_TSTMP)
1513 tp->ts_offset = tcp_new_ts_offset(&inp->inp_inc);
1514 tcp_sendseqinit(tp);
1519 INP_HASH_WUNLOCK(&V_tcbinfo);
1526 tcp6_connect(struct tcpcb *tp, struct sockaddr *nam, struct thread *td)
1528 struct inpcb *inp = tp->t_inpcb;
1531 INP_WLOCK_ASSERT(inp);
1532 INP_HASH_WLOCK(&V_tcbinfo);
1534 if (inp->inp_lport == 0) {
1535 error = in6_pcbbind(inp, (struct sockaddr *)0, td->td_ucred);
1539 error = in6_pcbconnect(inp, nam, td->td_ucred);
1542 INP_HASH_WUNLOCK(&V_tcbinfo);
1544 /* Compute window scaling to request. */
1545 while (tp->request_r_scale < TCP_MAX_WINSHIFT &&
1546 (TCP_MAXWIN << tp->request_r_scale) < sb_max)
1547 tp->request_r_scale++;
1549 soisconnecting(inp->inp_socket);
1550 TCPSTAT_INC(tcps_connattempt);
1551 tcp_state_change(tp, TCPS_SYN_SENT);
1552 tp->iss = tcp_new_isn(&inp->inp_inc);
1553 if (tp->t_flags & TF_REQ_TSTMP)
1554 tp->ts_offset = tcp_new_ts_offset(&inp->inp_inc);
1555 tcp_sendseqinit(tp);
1560 INP_HASH_WUNLOCK(&V_tcbinfo);
1566 * Export TCP internal state information via a struct tcp_info, based on the
1567 * Linux 2.6 API. Not ABI compatible as our constants are mapped differently
1568 * (TCP state machine, etc). We export all information using FreeBSD-native
1569 * constants -- for example, the numeric values for tcpi_state will differ
1573 tcp_fill_info(struct tcpcb *tp, struct tcp_info *ti)
1576 INP_WLOCK_ASSERT(tp->t_inpcb);
1577 bzero(ti, sizeof(*ti));
1579 ti->tcpi_state = tp->t_state;
1580 if ((tp->t_flags & TF_REQ_TSTMP) && (tp->t_flags & TF_RCVD_TSTMP))
1581 ti->tcpi_options |= TCPI_OPT_TIMESTAMPS;
1582 if (tp->t_flags & TF_SACK_PERMIT)
1583 ti->tcpi_options |= TCPI_OPT_SACK;
1584 if ((tp->t_flags & TF_REQ_SCALE) && (tp->t_flags & TF_RCVD_SCALE)) {
1585 ti->tcpi_options |= TCPI_OPT_WSCALE;
1586 ti->tcpi_snd_wscale = tp->snd_scale;
1587 ti->tcpi_rcv_wscale = tp->rcv_scale;
1589 if (tp->t_flags2 & TF2_ECN_PERMIT)
1590 ti->tcpi_options |= TCPI_OPT_ECN;
1592 ti->tcpi_rto = tp->t_rxtcur * tick;
1593 ti->tcpi_last_data_recv = ((uint32_t)ticks - tp->t_rcvtime) * tick;
1594 ti->tcpi_rtt = ((u_int64_t)tp->t_srtt * tick) >> TCP_RTT_SHIFT;
1595 ti->tcpi_rttvar = ((u_int64_t)tp->t_rttvar * tick) >> TCP_RTTVAR_SHIFT;
1597 ti->tcpi_snd_ssthresh = tp->snd_ssthresh;
1598 ti->tcpi_snd_cwnd = tp->snd_cwnd;
1601 * FreeBSD-specific extension fields for tcp_info.
1603 ti->tcpi_rcv_space = tp->rcv_wnd;
1604 ti->tcpi_rcv_nxt = tp->rcv_nxt;
1605 ti->tcpi_snd_wnd = tp->snd_wnd;
1606 ti->tcpi_snd_bwnd = 0; /* Unused, kept for compat. */
1607 ti->tcpi_snd_nxt = tp->snd_nxt;
1608 ti->tcpi_snd_mss = tp->t_maxseg;
1609 ti->tcpi_rcv_mss = tp->t_maxseg;
1610 ti->tcpi_snd_rexmitpack = tp->t_sndrexmitpack;
1611 ti->tcpi_rcv_ooopack = tp->t_rcvoopack;
1612 ti->tcpi_snd_zerowin = tp->t_sndzerowin;
1614 if (tp->t_flags & TF_TOE) {
1615 ti->tcpi_options |= TCPI_OPT_TOE;
1616 tcp_offload_tcp_info(tp, ti);
1622 * tcp_ctloutput() must drop the inpcb lock before performing copyin on
1623 * socket option arguments. When it re-acquires the lock after the copy, it
1624 * has to revalidate that the connection is still valid for the socket
1627 #define INP_WLOCK_RECHECK_CLEANUP(inp, cleanup) do { \
1629 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) { \
1632 return (ECONNRESET); \
1634 tp = intotcpcb(inp); \
1636 #define INP_WLOCK_RECHECK(inp) INP_WLOCK_RECHECK_CLEANUP((inp), /* noop */)
1639 tcp_ctloutput(struct socket *so, struct sockopt *sopt)
1644 struct tcp_function_block *blk;
1645 struct tcp_function_set fsn;
1648 inp = sotoinpcb(so);
1649 KASSERT(inp != NULL, ("tcp_ctloutput: inp == NULL"));
1650 if (sopt->sopt_level != IPPROTO_TCP) {
1652 if (inp->inp_vflag & INP_IPV6PROTO) {
1653 error = ip6_ctloutput(so, sopt);
1655 * In case of the IPV6_USE_MIN_MTU socket option,
1656 * the INC_IPV6MINMTU flag to announce a corresponding
1657 * MSS during the initial handshake.
1658 * If the TCP connection is not in the front states,
1659 * just reduce the MSS being used.
1660 * This avoids the sending of TCP segments which will
1661 * be fragmented at the IPv6 layer.
1664 (sopt->sopt_dir == SOPT_SET) &&
1665 (sopt->sopt_level == IPPROTO_IPV6) &&
1666 (sopt->sopt_name == IPV6_USE_MIN_MTU)) {
1668 if ((inp->inp_flags &
1669 (INP_TIMEWAIT | INP_DROPPED))) {
1671 return (ECONNRESET);
1673 inp->inp_inc.inc_flags |= INC_IPV6MINMTU;
1674 tp = intotcpcb(inp);
1675 if ((tp->t_state >= TCPS_SYN_SENT) &&
1676 (inp->inp_inc.inc_flags & INC_ISIPV6)) {
1677 struct ip6_pktopts *opt;
1679 opt = inp->in6p_outputopts;
1680 if ((opt != NULL) &&
1681 (opt->ip6po_minmtu ==
1682 IP6PO_MINMTU_ALL)) {
1683 if (tp->t_maxseg > TCP6_MSS) {
1684 tp->t_maxseg = TCP6_MSS;
1692 #if defined(INET6) && defined(INET)
1697 error = ip_ctloutput(so, sopt);
1703 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
1705 return (ECONNRESET);
1707 tp = intotcpcb(inp);
1709 * Protect the TCP option TCP_FUNCTION_BLK so
1710 * that a sub-function can *never* overwrite this.
1712 if ((sopt->sopt_dir == SOPT_SET) &&
1713 (sopt->sopt_name == TCP_FUNCTION_BLK)) {
1715 error = sooptcopyin(sopt, &fsn, sizeof fsn,
1719 INP_WLOCK_RECHECK(inp);
1720 blk = find_and_ref_tcp_functions(&fsn);
1725 if (tp->t_fb == blk) {
1726 /* You already have this */
1727 refcount_release(&blk->tfb_refcnt);
1731 if (tp->t_state != TCPS_CLOSED) {
1733 * The user has advanced the state
1734 * past the initial point, we may not
1735 * be able to switch.
1737 if (blk->tfb_tcp_handoff_ok != NULL) {
1739 * Does the stack provide a
1740 * query mechanism, if so it may
1741 * still be possible?
1743 error = (*blk->tfb_tcp_handoff_ok)(tp);
1747 refcount_release(&blk->tfb_refcnt);
1752 if (blk->tfb_flags & TCP_FUNC_BEING_REMOVED) {
1753 refcount_release(&blk->tfb_refcnt);
1758 * Release the old refcnt, the
1759 * lookup acquired a ref on the
1762 if (tp->t_fb->tfb_tcp_fb_fini) {
1764 * Tell the stack to cleanup with 0 i.e.
1765 * the tcb is not going away.
1767 (*tp->t_fb->tfb_tcp_fb_fini)(tp, 0);
1770 /* Assure that we are not on any hpts */
1771 tcp_hpts_remove(tp->t_inpcb, HPTS_REMOVE_ALL);
1773 if (blk->tfb_tcp_fb_init) {
1774 error = (*blk->tfb_tcp_fb_init)(tp);
1776 refcount_release(&blk->tfb_refcnt);
1777 if (tp->t_fb->tfb_tcp_fb_init) {
1778 if((*tp->t_fb->tfb_tcp_fb_init)(tp) != 0) {
1779 /* Fall back failed, drop the connection */
1788 refcount_release(&tp->t_fb->tfb_refcnt);
1791 if (tp->t_flags & TF_TOE) {
1792 tcp_offload_ctloutput(tp, sopt->sopt_dir,
1799 } else if ((sopt->sopt_dir == SOPT_GET) &&
1800 (sopt->sopt_name == TCP_FUNCTION_BLK)) {
1801 strncpy(fsn.function_set_name, tp->t_fb->tfb_tcp_block_name,
1802 TCP_FUNCTION_NAME_LEN_MAX);
1803 fsn.function_set_name[TCP_FUNCTION_NAME_LEN_MAX - 1] = '\0';
1804 fsn.pcbcnt = tp->t_fb->tfb_refcnt;
1806 error = sooptcopyout(sopt, &fsn, sizeof fsn);
1809 /* Pass in the INP locked, called must unlock it */
1810 return (tp->t_fb->tfb_tcp_ctloutput(so, sopt, inp, tp));
1814 * If this assert becomes untrue, we need to change the size of the buf
1815 * variable in tcp_default_ctloutput().
1818 CTASSERT(TCP_CA_NAME_MAX <= TCP_LOG_ID_LEN);
1819 CTASSERT(TCP_LOG_REASON_LEN <= TCP_LOG_ID_LEN);
1823 tcp_default_ctloutput(struct socket *so, struct sockopt *sopt, struct inpcb *inp, struct tcpcb *tp)
1825 int error, opt, optval;
1829 struct tls_enable tls;
1831 struct cc_algo *algo;
1832 char *pbuf, buf[TCP_LOG_ID_LEN];
1834 struct statsblob *sbp;
1839 * For TCP_CCALGOOPT forward the control to CC module, for both
1840 * SOPT_SET and SOPT_GET.
1842 switch (sopt->sopt_name) {
1845 if (sopt->sopt_valsize > CC_ALGOOPT_LIMIT)
1847 pbuf = malloc(sopt->sopt_valsize, M_TEMP, M_WAITOK | M_ZERO);
1848 error = sooptcopyin(sopt, pbuf, sopt->sopt_valsize,
1849 sopt->sopt_valsize);
1854 INP_WLOCK_RECHECK_CLEANUP(inp, free(pbuf, M_TEMP));
1855 if (CC_ALGO(tp)->ctl_output != NULL)
1856 error = CC_ALGO(tp)->ctl_output(tp->ccv, sopt, pbuf);
1860 if (error == 0 && sopt->sopt_dir == SOPT_GET)
1861 error = sooptcopyout(sopt, pbuf, sopt->sopt_valsize);
1866 switch (sopt->sopt_dir) {
1868 switch (sopt->sopt_name) {
1869 #if defined(IPSEC_SUPPORT) || defined(TCP_SIGNATURE)
1871 if (!TCPMD5_ENABLED()) {
1873 return (ENOPROTOOPT);
1875 error = TCPMD5_PCBCTL(inp, sopt);
1878 goto unlock_and_done;
1884 error = sooptcopyin(sopt, &optval, sizeof optval,
1889 INP_WLOCK_RECHECK(inp);
1890 switch (sopt->sopt_name) {
1898 opt = 0; /* dead code to fool gcc */
1905 tp->t_flags &= ~opt;
1908 if (tp->t_flags & TF_TOE) {
1909 tcp_offload_ctloutput(tp, sopt->sopt_dir,
1918 error = sooptcopyin(sopt, &optval, sizeof optval,
1923 INP_WLOCK_RECHECK(inp);
1925 tp->t_flags |= TF_NOPUSH;
1926 else if (tp->t_flags & TF_NOPUSH) {
1927 tp->t_flags &= ~TF_NOPUSH;
1928 if (TCPS_HAVEESTABLISHED(tp->t_state)) {
1929 struct epoch_tracker et;
1931 NET_EPOCH_ENTER(et);
1932 error = tp->t_fb->tfb_tcp_output(tp);
1936 goto unlock_and_done;
1940 error = sooptcopyin(sopt, &optval, sizeof optval,
1945 INP_WLOCK_RECHECK(inp);
1946 if (optval > 0 && optval <= tp->t_maxseg &&
1947 optval + 40 >= V_tcp_minmss)
1948 tp->t_maxseg = optval;
1951 goto unlock_and_done;
1961 error = sooptcopyin(sopt, &optval, sizeof optval,
1967 sbp = stats_blob_alloc(
1968 V_tcp_perconn_stats_dflt_tpl, 0);
1972 INP_WLOCK_RECHECK(inp);
1973 if ((tp->t_stats != NULL && sbp == NULL) ||
1974 (tp->t_stats == NULL && sbp != NULL)) {
1975 struct statsblob *t = tp->t_stats;
1981 stats_blob_destroy(sbp);
1983 return (EOPNOTSUPP);
1987 case TCP_CONGESTION:
1989 error = sooptcopyin(sopt, buf, TCP_CA_NAME_MAX - 1, 1);
1992 buf[sopt->sopt_valsize] = '\0';
1993 INP_WLOCK_RECHECK(inp);
1995 STAILQ_FOREACH(algo, &cc_list, entries)
1996 if (strncmp(buf, algo->name,
1997 TCP_CA_NAME_MAX) == 0)
2006 * We hold a write lock over the tcb so it's safe to
2007 * do these things without ordering concerns.
2009 if (CC_ALGO(tp)->cb_destroy != NULL)
2010 CC_ALGO(tp)->cb_destroy(tp->ccv);
2014 * If something goes pear shaped initialising the new
2015 * algo, fall back to newreno (which does not
2016 * require initialisation).
2018 if (algo->cb_init != NULL &&
2019 algo->cb_init(tp->ccv) != 0) {
2020 CC_ALGO(tp) = &newreno_cc_algo;
2022 * The only reason init should fail is
2023 * because of malloc.
2031 case TCP_TXTLS_ENABLE:
2033 error = sooptcopyin(sopt, &tls, sizeof(tls),
2037 error = ktls_enable_tx(so, &tls);
2039 case TCP_TXTLS_MODE:
2041 error = sooptcopyin(sopt, &ui, sizeof(ui), sizeof(ui));
2045 INP_WLOCK_RECHECK(inp);
2046 error = ktls_set_tx_mode(so, ui);
2055 error = sooptcopyin(sopt, &ui, sizeof(ui), sizeof(ui));
2059 if (ui > (UINT_MAX / hz)) {
2065 INP_WLOCK_RECHECK(inp);
2066 switch (sopt->sopt_name) {
2068 tp->t_keepidle = ui;
2070 * XXX: better check current remaining
2071 * timeout and "merge" it with new value.
2073 if ((tp->t_state > TCPS_LISTEN) &&
2074 (tp->t_state <= TCPS_CLOSING))
2075 tcp_timer_activate(tp, TT_KEEP,
2079 tp->t_keepintvl = ui;
2080 if ((tp->t_state == TCPS_FIN_WAIT_2) &&
2081 (TP_MAXIDLE(tp) > 0))
2082 tcp_timer_activate(tp, TT_2MSL,
2086 tp->t_keepinit = ui;
2087 if (tp->t_state == TCPS_SYN_RECEIVED ||
2088 tp->t_state == TCPS_SYN_SENT)
2089 tcp_timer_activate(tp, TT_KEEP,
2093 goto unlock_and_done;
2097 error = sooptcopyin(sopt, &ui, sizeof(ui), sizeof(ui));
2101 INP_WLOCK_RECHECK(inp);
2103 if ((tp->t_state == TCPS_FIN_WAIT_2) &&
2104 (TP_MAXIDLE(tp) > 0))
2105 tcp_timer_activate(tp, TT_2MSL,
2107 goto unlock_and_done;
2113 error = sooptcopyin(sopt, &optval, sizeof optval,
2118 INP_WLOCK_RECHECK(inp);
2120 tcp_pcap_set_sock_max(TCP_PCAP_OUT ?
2121 &(tp->t_outpkts) : &(tp->t_inpkts),
2125 goto unlock_and_done;
2128 case TCP_FASTOPEN: {
2129 struct tcp_fastopen tfo_optval;
2132 if (!V_tcp_fastopen_client_enable &&
2133 !V_tcp_fastopen_server_enable)
2136 error = sooptcopyin(sopt, &tfo_optval,
2137 sizeof(tfo_optval), sizeof(int));
2141 INP_WLOCK_RECHECK(inp);
2142 if (tfo_optval.enable) {
2143 if (tp->t_state == TCPS_LISTEN) {
2144 if (!V_tcp_fastopen_server_enable) {
2146 goto unlock_and_done;
2149 tp->t_flags |= TF_FASTOPEN;
2150 if (tp->t_tfo_pending == NULL)
2152 tcp_fastopen_alloc_counter();
2155 * If a pre-shared key was provided,
2156 * stash it in the client cookie
2157 * field of the tcpcb for use during
2160 if (sopt->sopt_valsize ==
2161 sizeof(tfo_optval)) {
2162 memcpy(tp->t_tfo_cookie.client,
2164 TCP_FASTOPEN_PSK_LEN);
2165 tp->t_tfo_client_cookie_len =
2166 TCP_FASTOPEN_PSK_LEN;
2168 tp->t_flags |= TF_FASTOPEN;
2171 tp->t_flags &= ~TF_FASTOPEN;
2172 goto unlock_and_done;
2178 error = sooptcopyin(sopt, &optval, sizeof optval,
2183 INP_WLOCK_RECHECK(inp);
2184 error = tcp_log_state_change(tp, optval);
2185 goto unlock_and_done;
2194 error = sooptcopyin(sopt, buf, TCP_LOG_ID_LEN - 1, 0);
2197 buf[sopt->sopt_valsize] = '\0';
2198 INP_WLOCK_RECHECK(inp);
2199 error = tcp_log_set_id(tp, buf);
2200 /* tcp_log_set_id() unlocks the INP. */
2207 sooptcopyin(sopt, buf, TCP_LOG_REASON_LEN - 1, 0);
2210 buf[sopt->sopt_valsize] = '\0';
2211 INP_WLOCK_RECHECK(inp);
2212 if (sopt->sopt_name == TCP_LOGDUMP) {
2213 error = tcp_log_dump_tp_logbuf(tp, buf,
2217 tcp_log_dump_tp_bucket_logbufs(tp, buf);
2219 * tcp_log_dump_tp_bucket_logbufs() drops the
2228 error = ENOPROTOOPT;
2234 tp = intotcpcb(inp);
2235 switch (sopt->sopt_name) {
2236 #if defined(IPSEC_SUPPORT) || defined(TCP_SIGNATURE)
2238 if (!TCPMD5_ENABLED()) {
2240 return (ENOPROTOOPT);
2242 error = TCPMD5_PCBCTL(inp, sopt);
2247 optval = tp->t_flags & TF_NODELAY;
2249 error = sooptcopyout(sopt, &optval, sizeof optval);
2252 optval = tp->t_maxseg;
2254 error = sooptcopyout(sopt, &optval, sizeof optval);
2257 optval = tp->t_flags & TF_NOOPT;
2259 error = sooptcopyout(sopt, &optval, sizeof optval);
2262 optval = tp->t_flags & TF_NOPUSH;
2264 error = sooptcopyout(sopt, &optval, sizeof optval);
2267 tcp_fill_info(tp, &ti);
2269 error = sooptcopyout(sopt, &ti, sizeof ti);
2275 TYPEOF_MEMBER(struct statsblob, flags) sbflags = 0;
2278 socklen_t outsbsz = sopt->sopt_valsize;
2279 if (tp->t_stats == NULL)
2281 else if (outsbsz >= tp->t_stats->cursz)
2282 outsbsz = tp->t_stats->cursz;
2283 else if (outsbsz >= sizeof(struct statsblob))
2284 outsbsz = sizeof(struct statsblob);
2291 sbp = sopt->sopt_val;
2292 nheld = atop(round_page(((vm_offset_t)sbp) +
2293 (vm_size_t)outsbsz) - trunc_page((vm_offset_t)sbp));
2294 vm_page_t ma[nheld];
2295 if (vm_fault_quick_hold_pages(
2296 &curproc->p_vmspace->vm_map, (vm_offset_t)sbp,
2297 outsbsz, VM_PROT_READ | VM_PROT_WRITE, ma,
2303 if ((error = copyin_nofault(&(sbp->flags), &sbflags,
2304 SIZEOF_MEMBER(struct statsblob, flags))))
2307 INP_WLOCK_RECHECK(inp);
2308 error = stats_blob_snapshot(&sbp, outsbsz, tp->t_stats,
2309 sbflags | SB_CLONE_USRDSTNOFAULT);
2311 sopt->sopt_valsize = outsbsz;
2313 vm_page_unhold_pages(ma, nheld);
2320 case TCP_CONGESTION:
2321 len = strlcpy(buf, CC_ALGO(tp)->name, TCP_CA_NAME_MAX);
2323 error = sooptcopyout(sopt, buf, len + 1);
2329 switch (sopt->sopt_name) {
2331 ui = TP_KEEPIDLE(tp) / hz;
2334 ui = TP_KEEPINTVL(tp) / hz;
2337 ui = TP_KEEPINIT(tp) / hz;
2340 ui = TP_KEEPCNT(tp);
2344 error = sooptcopyout(sopt, &ui, sizeof(ui));
2349 optval = tcp_pcap_get_sock_max(TCP_PCAP_OUT ?
2350 &(tp->t_outpkts) : &(tp->t_inpkts));
2352 error = sooptcopyout(sopt, &optval, sizeof optval);
2356 optval = tp->t_flags & TF_FASTOPEN;
2358 error = sooptcopyout(sopt, &optval, sizeof optval);
2362 optval = tp->t_logstate;
2364 error = sooptcopyout(sopt, &optval, sizeof(optval));
2367 /* tcp_log_getlogbuf() does INP_WUNLOCK(inp) */
2368 error = tcp_log_getlogbuf(sopt, tp);
2371 len = tcp_log_get_id(tp, buf);
2373 error = sooptcopyout(sopt, buf, len + 1);
2382 case TCP_TXTLS_MODE:
2383 optval = ktls_get_tx_mode(so);
2385 error = sooptcopyout(sopt, &optval, sizeof(optval));
2390 error = ENOPROTOOPT;
2397 #undef INP_WLOCK_RECHECK
2398 #undef INP_WLOCK_RECHECK_CLEANUP
2401 * Initiate (or continue) disconnect.
2402 * If embryonic state, just send reset (once).
2403 * If in ``let data drain'' option and linger null, just drop.
2404 * Otherwise (hard), mark socket disconnecting and drop
2405 * current input data; switch states based on user close, and
2406 * send segment to peer (with FIN).
2409 tcp_disconnect(struct tcpcb *tp)
2411 struct inpcb *inp = tp->t_inpcb;
2412 struct socket *so = inp->inp_socket;
2415 INP_WLOCK_ASSERT(inp);
2418 * Neither tcp_close() nor tcp_drop() should return NULL, as the
2419 * socket is still open.
2421 if (tp->t_state < TCPS_ESTABLISHED &&
2422 !(tp->t_state > TCPS_LISTEN && IS_FASTOPEN(tp->t_flags))) {
2425 ("tcp_disconnect: tcp_close() returned NULL"));
2426 } else if ((so->so_options & SO_LINGER) && so->so_linger == 0) {
2427 tp = tcp_drop(tp, 0);
2429 ("tcp_disconnect: tcp_drop() returned NULL"));
2431 soisdisconnecting(so);
2432 sbflush(&so->so_rcv);
2434 if (!(inp->inp_flags & INP_DROPPED))
2435 tp->t_fb->tfb_tcp_output(tp);
2440 * User issued close, and wish to trail through shutdown states:
2441 * if never received SYN, just forget it. If got a SYN from peer,
2442 * but haven't sent FIN, then go to FIN_WAIT_1 state to send peer a FIN.
2443 * If already got a FIN from peer, then almost done; go to LAST_ACK
2444 * state. In all other cases, have already sent FIN to peer (e.g.
2445 * after PRU_SHUTDOWN), and just have to play tedious game waiting
2446 * for peer to send FIN or not respond to keep-alives, etc.
2447 * We can let the user exit from the close as soon as the FIN is acked.
2450 tcp_usrclosed(struct tcpcb *tp)
2454 INP_WLOCK_ASSERT(tp->t_inpcb);
2456 switch (tp->t_state) {
2459 tcp_offload_listen_stop(tp);
2461 tcp_state_change(tp, TCPS_CLOSED);
2466 * tcp_close() should never return NULL here as the socket is
2470 ("tcp_usrclosed: tcp_close() returned NULL"));
2474 case TCPS_SYN_RECEIVED:
2475 tp->t_flags |= TF_NEEDFIN;
2478 case TCPS_ESTABLISHED:
2479 tcp_state_change(tp, TCPS_FIN_WAIT_1);
2482 case TCPS_CLOSE_WAIT:
2483 tcp_state_change(tp, TCPS_LAST_ACK);
2486 if (tp->t_state >= TCPS_FIN_WAIT_2) {
2487 soisdisconnected(tp->t_inpcb->inp_socket);
2488 /* Prevent the connection hanging in FIN_WAIT_2 forever. */
2489 if (tp->t_state == TCPS_FIN_WAIT_2) {
2492 timeout = (tcp_fast_finwait2_recycle) ?
2493 tcp_finwait2_timeout : TP_MAXIDLE(tp);
2494 tcp_timer_activate(tp, TT_2MSL, timeout);
2501 db_print_indent(int indent)
2505 for (i = 0; i < indent; i++)
2510 db_print_tstate(int t_state)
2515 db_printf("TCPS_CLOSED");
2519 db_printf("TCPS_LISTEN");
2523 db_printf("TCPS_SYN_SENT");
2526 case TCPS_SYN_RECEIVED:
2527 db_printf("TCPS_SYN_RECEIVED");
2530 case TCPS_ESTABLISHED:
2531 db_printf("TCPS_ESTABLISHED");
2534 case TCPS_CLOSE_WAIT:
2535 db_printf("TCPS_CLOSE_WAIT");
2538 case TCPS_FIN_WAIT_1:
2539 db_printf("TCPS_FIN_WAIT_1");
2543 db_printf("TCPS_CLOSING");
2547 db_printf("TCPS_LAST_ACK");
2550 case TCPS_FIN_WAIT_2:
2551 db_printf("TCPS_FIN_WAIT_2");
2554 case TCPS_TIME_WAIT:
2555 db_printf("TCPS_TIME_WAIT");
2559 db_printf("unknown");
2565 db_print_tflags(u_int t_flags)
2570 if (t_flags & TF_ACKNOW) {
2571 db_printf("%sTF_ACKNOW", comma ? ", " : "");
2574 if (t_flags & TF_DELACK) {
2575 db_printf("%sTF_DELACK", comma ? ", " : "");
2578 if (t_flags & TF_NODELAY) {
2579 db_printf("%sTF_NODELAY", comma ? ", " : "");
2582 if (t_flags & TF_NOOPT) {
2583 db_printf("%sTF_NOOPT", comma ? ", " : "");
2586 if (t_flags & TF_SENTFIN) {
2587 db_printf("%sTF_SENTFIN", comma ? ", " : "");
2590 if (t_flags & TF_REQ_SCALE) {
2591 db_printf("%sTF_REQ_SCALE", comma ? ", " : "");
2594 if (t_flags & TF_RCVD_SCALE) {
2595 db_printf("%sTF_RECVD_SCALE", comma ? ", " : "");
2598 if (t_flags & TF_REQ_TSTMP) {
2599 db_printf("%sTF_REQ_TSTMP", comma ? ", " : "");
2602 if (t_flags & TF_RCVD_TSTMP) {
2603 db_printf("%sTF_RCVD_TSTMP", comma ? ", " : "");
2606 if (t_flags & TF_SACK_PERMIT) {
2607 db_printf("%sTF_SACK_PERMIT", comma ? ", " : "");
2610 if (t_flags & TF_NEEDSYN) {
2611 db_printf("%sTF_NEEDSYN", comma ? ", " : "");
2614 if (t_flags & TF_NEEDFIN) {
2615 db_printf("%sTF_NEEDFIN", comma ? ", " : "");
2618 if (t_flags & TF_NOPUSH) {
2619 db_printf("%sTF_NOPUSH", comma ? ", " : "");
2622 if (t_flags & TF_MORETOCOME) {
2623 db_printf("%sTF_MORETOCOME", comma ? ", " : "");
2626 if (t_flags & TF_LQ_OVERFLOW) {
2627 db_printf("%sTF_LQ_OVERFLOW", comma ? ", " : "");
2630 if (t_flags & TF_LASTIDLE) {
2631 db_printf("%sTF_LASTIDLE", comma ? ", " : "");
2634 if (t_flags & TF_RXWIN0SENT) {
2635 db_printf("%sTF_RXWIN0SENT", comma ? ", " : "");
2638 if (t_flags & TF_FASTRECOVERY) {
2639 db_printf("%sTF_FASTRECOVERY", comma ? ", " : "");
2642 if (t_flags & TF_CONGRECOVERY) {
2643 db_printf("%sTF_CONGRECOVERY", comma ? ", " : "");
2646 if (t_flags & TF_WASFRECOVERY) {
2647 db_printf("%sTF_WASFRECOVERY", comma ? ", " : "");
2650 if (t_flags & TF_SIGNATURE) {
2651 db_printf("%sTF_SIGNATURE", comma ? ", " : "");
2654 if (t_flags & TF_FORCEDATA) {
2655 db_printf("%sTF_FORCEDATA", comma ? ", " : "");
2658 if (t_flags & TF_TSO) {
2659 db_printf("%sTF_TSO", comma ? ", " : "");
2662 if (t_flags & TF_FASTOPEN) {
2663 db_printf("%sTF_FASTOPEN", comma ? ", " : "");
2669 db_print_tflags2(u_int t_flags2)
2674 if (t_flags2 & TF2_ECN_PERMIT) {
2675 db_printf("%sTF2_ECN_PERMIT", comma ? ", " : "");
2682 db_print_toobflags(char t_oobflags)
2687 if (t_oobflags & TCPOOB_HAVEDATA) {
2688 db_printf("%sTCPOOB_HAVEDATA", comma ? ", " : "");
2691 if (t_oobflags & TCPOOB_HADDATA) {
2692 db_printf("%sTCPOOB_HADDATA", comma ? ", " : "");
2698 db_print_tcpcb(struct tcpcb *tp, const char *name, int indent)
2701 db_print_indent(indent);
2702 db_printf("%s at %p\n", name, tp);
2706 db_print_indent(indent);
2707 db_printf("t_segq first: %p t_segqlen: %d t_dupacks: %d\n",
2708 TAILQ_FIRST(&tp->t_segq), tp->t_segqlen, tp->t_dupacks);
2710 db_print_indent(indent);
2711 db_printf("tt_rexmt: %p tt_persist: %p tt_keep: %p\n",
2712 &tp->t_timers->tt_rexmt, &tp->t_timers->tt_persist, &tp->t_timers->tt_keep);
2714 db_print_indent(indent);
2715 db_printf("tt_2msl: %p tt_delack: %p t_inpcb: %p\n", &tp->t_timers->tt_2msl,
2716 &tp->t_timers->tt_delack, tp->t_inpcb);
2718 db_print_indent(indent);
2719 db_printf("t_state: %d (", tp->t_state);
2720 db_print_tstate(tp->t_state);
2723 db_print_indent(indent);
2724 db_printf("t_flags: 0x%x (", tp->t_flags);
2725 db_print_tflags(tp->t_flags);
2728 db_print_indent(indent);
2729 db_printf("t_flags2: 0x%x (", tp->t_flags2);
2730 db_print_tflags2(tp->t_flags2);
2733 db_print_indent(indent);
2734 db_printf("snd_una: 0x%08x snd_max: 0x%08x snd_nxt: x0%08x\n",
2735 tp->snd_una, tp->snd_max, tp->snd_nxt);
2737 db_print_indent(indent);
2738 db_printf("snd_up: 0x%08x snd_wl1: 0x%08x snd_wl2: 0x%08x\n",
2739 tp->snd_up, tp->snd_wl1, tp->snd_wl2);
2741 db_print_indent(indent);
2742 db_printf("iss: 0x%08x irs: 0x%08x rcv_nxt: 0x%08x\n",
2743 tp->iss, tp->irs, tp->rcv_nxt);
2745 db_print_indent(indent);
2746 db_printf("rcv_adv: 0x%08x rcv_wnd: %u rcv_up: 0x%08x\n",
2747 tp->rcv_adv, tp->rcv_wnd, tp->rcv_up);
2749 db_print_indent(indent);
2750 db_printf("snd_wnd: %u snd_cwnd: %u\n",
2751 tp->snd_wnd, tp->snd_cwnd);
2753 db_print_indent(indent);
2754 db_printf("snd_ssthresh: %u snd_recover: "
2755 "0x%08x\n", tp->snd_ssthresh, tp->snd_recover);
2757 db_print_indent(indent);
2758 db_printf("t_rcvtime: %u t_startime: %u\n",
2759 tp->t_rcvtime, tp->t_starttime);
2761 db_print_indent(indent);
2762 db_printf("t_rttime: %u t_rtsq: 0x%08x\n",
2763 tp->t_rtttime, tp->t_rtseq);
2765 db_print_indent(indent);
2766 db_printf("t_rxtcur: %d t_maxseg: %u t_srtt: %d\n",
2767 tp->t_rxtcur, tp->t_maxseg, tp->t_srtt);
2769 db_print_indent(indent);
2770 db_printf("t_rttvar: %d t_rxtshift: %d t_rttmin: %u "
2771 "t_rttbest: %u\n", tp->t_rttvar, tp->t_rxtshift, tp->t_rttmin,
2774 db_print_indent(indent);
2775 db_printf("t_rttupdated: %lu max_sndwnd: %u t_softerror: %d\n",
2776 tp->t_rttupdated, tp->max_sndwnd, tp->t_softerror);
2778 db_print_indent(indent);
2779 db_printf("t_oobflags: 0x%x (", tp->t_oobflags);
2780 db_print_toobflags(tp->t_oobflags);
2781 db_printf(") t_iobc: 0x%02x\n", tp->t_iobc);
2783 db_print_indent(indent);
2784 db_printf("snd_scale: %u rcv_scale: %u request_r_scale: %u\n",
2785 tp->snd_scale, tp->rcv_scale, tp->request_r_scale);
2787 db_print_indent(indent);
2788 db_printf("ts_recent: %u ts_recent_age: %u\n",
2789 tp->ts_recent, tp->ts_recent_age);
2791 db_print_indent(indent);
2792 db_printf("ts_offset: %u last_ack_sent: 0x%08x snd_cwnd_prev: "
2793 "%u\n", tp->ts_offset, tp->last_ack_sent, tp->snd_cwnd_prev);
2795 db_print_indent(indent);
2796 db_printf("snd_ssthresh_prev: %u snd_recover_prev: 0x%08x "
2797 "t_badrxtwin: %u\n", tp->snd_ssthresh_prev,
2798 tp->snd_recover_prev, tp->t_badrxtwin);
2800 db_print_indent(indent);
2801 db_printf("snd_numholes: %d snd_holes first: %p\n",
2802 tp->snd_numholes, TAILQ_FIRST(&tp->snd_holes));
2804 db_print_indent(indent);
2805 db_printf("snd_fack: 0x%08x rcv_numsacks: %d sack_newdata: "
2806 "0x%08x\n", tp->snd_fack, tp->rcv_numsacks, tp->sack_newdata);
2808 /* Skip sackblks, sackhint. */
2810 db_print_indent(indent);
2811 db_printf("t_rttlow: %d rfbuf_ts: %u rfbuf_cnt: %d\n",
2812 tp->t_rttlow, tp->rfbuf_ts, tp->rfbuf_cnt);
2815 DB_SHOW_COMMAND(tcpcb, db_show_tcpcb)
2820 db_printf("usage: show tcpcb <addr>\n");
2823 tp = (struct tcpcb *)addr;
2825 db_print_tcpcb(tp, "tcpcb", 0);