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>
52 #include <sys/limits.h>
53 #include <sys/malloc.h>
54 #include <sys/refcount.h>
55 #include <sys/kernel.h>
57 #include <sys/sysctl.h>
60 #include <sys/domain.h>
62 #include <sys/socket.h>
63 #include <sys/socketvar.h>
64 #include <sys/protosw.h>
67 #include <sys/syslog.h>
74 #include <net/if_var.h>
75 #include <net/route.h>
78 #include <netinet/in.h>
79 #include <netinet/in_kdtrace.h>
80 #include <netinet/in_pcb.h>
81 #include <netinet/in_systm.h>
82 #include <netinet/in_var.h>
83 #include <netinet/ip_var.h>
85 #include <netinet/ip6.h>
86 #include <netinet6/in6_pcb.h>
87 #include <netinet6/ip6_var.h>
88 #include <netinet6/scope6_var.h>
90 #include <netinet/tcp.h>
91 #include <netinet/tcp_fsm.h>
92 #include <netinet/tcp_seq.h>
93 #include <netinet/tcp_timer.h>
94 #include <netinet/tcp_var.h>
95 #include <netinet/tcp_log_buf.h>
96 #include <netinet/tcpip.h>
97 #include <netinet/cc/cc.h>
98 #include <netinet/tcp_fastopen.h>
99 #include <netinet/tcp_hpts.h>
101 #include <netinet/tcp_pcap.h>
104 #include <netinet/tcp_debug.h>
107 #include <netinet/tcp_offload.h>
109 #include <netipsec/ipsec_support.h>
112 * TCP protocol interface to socket abstraction.
114 static int tcp_attach(struct socket *);
116 static int tcp_connect(struct tcpcb *, struct sockaddr *,
120 static int tcp6_connect(struct tcpcb *, struct sockaddr *,
123 static void tcp_disconnect(struct tcpcb *);
124 static void tcp_usrclosed(struct tcpcb *);
125 static void tcp_fill_info(struct tcpcb *, struct tcp_info *);
128 #define TCPDEBUG0 int ostate = 0
129 #define TCPDEBUG1() ostate = tp ? tp->t_state : 0
130 #define TCPDEBUG2(req) if (tp && (so->so_options & SO_DEBUG)) \
131 tcp_trace(TA_USER, ostate, tp, 0, 0, req)
135 #define TCPDEBUG2(req)
139 * TCP attaches to socket via pru_attach(), reserving space,
140 * and an internet control block.
143 tcp_usr_attach(struct socket *so, int proto, struct thread *td)
146 struct tcpcb *tp = NULL;
151 KASSERT(inp == NULL, ("tcp_usr_attach: inp != NULL"));
154 error = tcp_attach(so);
158 if ((so->so_options & SO_LINGER) && so->so_linger == 0)
159 so->so_linger = TCP_LINGERTIME;
164 TCPDEBUG2(PRU_ATTACH);
165 TCP_PROBE2(debug__user, tp, PRU_ATTACH);
170 * tcp_detach is called when the socket layer loses its final reference
171 * to the socket, be it a file descriptor reference, a reference from TCP,
172 * etc. At this point, there is only one case in which we will keep around
173 * inpcb state: time wait.
175 * This function can probably be re-absorbed back into tcp_usr_detach() now
176 * that there is a single detach path.
179 tcp_detach(struct socket *so, struct inpcb *inp)
183 INP_INFO_LOCK_ASSERT(&V_tcbinfo);
184 INP_WLOCK_ASSERT(inp);
186 KASSERT(so->so_pcb == inp, ("tcp_detach: so_pcb != inp"));
187 KASSERT(inp->inp_socket == so, ("tcp_detach: inp_socket != so"));
191 if (inp->inp_flags & INP_TIMEWAIT) {
193 * There are two cases to handle: one in which the time wait
194 * state is being discarded (INP_DROPPED), and one in which
195 * this connection will remain in timewait. In the former,
196 * it is time to discard all state (except tcptw, which has
197 * already been discarded by the timewait close code, which
198 * should be further up the call stack somewhere). In the
199 * latter case, we detach from the socket, but leave the pcb
200 * present until timewait ends.
202 * XXXRW: Would it be cleaner to free the tcptw here?
204 * Astute question indeed, from twtcp perspective there are
205 * four cases to consider:
207 * #1 tcp_detach is called at tcptw creation time by
208 * tcp_twstart, then do not discard the newly created tcptw
209 * and leave inpcb present until timewait ends
210 * #2 tcp_detach is called at tcptw creation time by
211 * tcp_twstart, but connection is local and tw will be
212 * discarded immediately
213 * #3 tcp_detach is called at timewait end (or reuse) by
214 * tcp_twclose, then the tcptw has already been discarded
215 * (or reused) and inpcb is freed here
216 * #4 tcp_detach is called() after timewait ends (or reuse)
217 * (e.g. by soclose), then tcptw has already been discarded
218 * (or reused) and inpcb is freed here
220 * In all three cases the tcptw should not be freed here.
222 if (inp->inp_flags & INP_DROPPED) {
224 if (__predict_true(tp == NULL)) {
228 * This case should not happen as in TIMEWAIT
229 * state the inp should not be destroyed before
230 * its tcptw. If INVARIANTS is defined, panic.
233 panic("%s: Panic before an inp double-free: "
234 "INP_TIMEWAIT && INP_DROPPED && tp != NULL"
237 log(LOG_ERR, "%s: Avoid an inp double-free: "
238 "INP_TIMEWAIT && INP_DROPPED && tp != NULL"
249 * If the connection is not in timewait, we consider two
250 * two conditions: one in which no further processing is
251 * necessary (dropped || embryonic), and one in which TCP is
252 * not yet done, but no longer requires the socket, so the
253 * pcb will persist for the time being.
255 * XXXRW: Does the second case still occur?
257 if (inp->inp_flags & INP_DROPPED ||
258 tp->t_state < TCPS_SYN_SENT) {
270 * pru_detach() detaches the TCP protocol from the socket.
271 * If the protocol state is non-embryonic, then can't
272 * do this directly: have to initiate a pru_disconnect(),
273 * which may finish later; embryonic TCB's can just
277 tcp_usr_detach(struct socket *so)
281 struct epoch_tracker et;
284 KASSERT(inp != NULL, ("tcp_usr_detach: inp == NULL"));
285 if (!INP_INFO_WLOCKED(&V_tcbinfo)) {
286 INP_INFO_RLOCK_ET(&V_tcbinfo, et);
290 KASSERT(inp->inp_socket != NULL,
291 ("tcp_usr_detach: inp_socket == NULL"));
294 INP_INFO_RUNLOCK_ET(&V_tcbinfo, et);
299 * Give the socket an address.
302 tcp_usr_bind(struct socket *so, struct sockaddr *nam, struct thread *td)
306 struct tcpcb *tp = NULL;
307 struct sockaddr_in *sinp;
309 sinp = (struct sockaddr_in *)nam;
310 if (nam->sa_len != sizeof (*sinp))
313 * Must check for multicast addresses and disallow binding
316 if (sinp->sin_family == AF_INET &&
317 IN_MULTICAST(ntohl(sinp->sin_addr.s_addr)))
318 return (EAFNOSUPPORT);
322 KASSERT(inp != NULL, ("tcp_usr_bind: inp == NULL"));
324 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
330 INP_HASH_WLOCK(&V_tcbinfo);
331 error = in_pcbbind(inp, nam, td->td_ucred);
332 INP_HASH_WUNLOCK(&V_tcbinfo);
335 TCP_PROBE2(debug__user, tp, PRU_BIND);
344 tcp6_usr_bind(struct socket *so, struct sockaddr *nam, struct thread *td)
348 struct tcpcb *tp = NULL;
349 struct sockaddr_in6 *sin6;
351 sin6 = (struct sockaddr_in6 *)nam;
352 if (nam->sa_len != sizeof (*sin6))
355 * Must check for multicast addresses and disallow binding
358 if (sin6->sin6_family == AF_INET6 &&
359 IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr))
360 return (EAFNOSUPPORT);
364 KASSERT(inp != NULL, ("tcp6_usr_bind: inp == NULL"));
366 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
372 INP_HASH_WLOCK(&V_tcbinfo);
373 inp->inp_vflag &= ~INP_IPV4;
374 inp->inp_vflag |= INP_IPV6;
376 if ((inp->inp_flags & IN6P_IPV6_V6ONLY) == 0) {
377 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr))
378 inp->inp_vflag |= INP_IPV4;
379 else if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
380 struct sockaddr_in sin;
382 in6_sin6_2_sin(&sin, sin6);
383 if (IN_MULTICAST(ntohl(sin.sin_addr.s_addr))) {
384 error = EAFNOSUPPORT;
385 INP_HASH_WUNLOCK(&V_tcbinfo);
388 inp->inp_vflag |= INP_IPV4;
389 inp->inp_vflag &= ~INP_IPV6;
390 error = in_pcbbind(inp, (struct sockaddr *)&sin,
392 INP_HASH_WUNLOCK(&V_tcbinfo);
397 error = in6_pcbbind(inp, nam, td->td_ucred);
398 INP_HASH_WUNLOCK(&V_tcbinfo);
401 TCP_PROBE2(debug__user, tp, PRU_BIND);
409 * Prepare to accept connections.
412 tcp_usr_listen(struct socket *so, int backlog, struct thread *td)
416 struct tcpcb *tp = NULL;
420 KASSERT(inp != NULL, ("tcp_usr_listen: inp == NULL"));
422 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
429 error = solisten_proto_check(so);
430 INP_HASH_WLOCK(&V_tcbinfo);
431 if (error == 0 && inp->inp_lport == 0)
432 error = in_pcbbind(inp, (struct sockaddr *)0, td->td_ucred);
433 INP_HASH_WUNLOCK(&V_tcbinfo);
435 tcp_state_change(tp, TCPS_LISTEN);
436 solisten_proto(so, backlog);
438 if ((so->so_options & SO_NO_OFFLOAD) == 0)
439 tcp_offload_listen_start(tp);
444 if (IS_FASTOPEN(tp->t_flags))
445 tp->t_tfo_pending = tcp_fastopen_alloc_counter();
448 TCPDEBUG2(PRU_LISTEN);
449 TCP_PROBE2(debug__user, tp, PRU_LISTEN);
457 tcp6_usr_listen(struct socket *so, int backlog, struct thread *td)
461 struct tcpcb *tp = NULL;
465 KASSERT(inp != NULL, ("tcp6_usr_listen: inp == NULL"));
467 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
474 error = solisten_proto_check(so);
475 INP_HASH_WLOCK(&V_tcbinfo);
476 if (error == 0 && inp->inp_lport == 0) {
477 inp->inp_vflag &= ~INP_IPV4;
478 if ((inp->inp_flags & IN6P_IPV6_V6ONLY) == 0)
479 inp->inp_vflag |= INP_IPV4;
480 error = in6_pcbbind(inp, (struct sockaddr *)0, td->td_ucred);
482 INP_HASH_WUNLOCK(&V_tcbinfo);
484 tcp_state_change(tp, TCPS_LISTEN);
485 solisten_proto(so, backlog);
487 if ((so->so_options & SO_NO_OFFLOAD) == 0)
488 tcp_offload_listen_start(tp);
493 if (IS_FASTOPEN(tp->t_flags))
494 tp->t_tfo_pending = tcp_fastopen_alloc_counter();
497 TCPDEBUG2(PRU_LISTEN);
498 TCP_PROBE2(debug__user, tp, PRU_LISTEN);
506 * Initiate connection to peer.
507 * Create a template for use in transmissions on this connection.
508 * Enter SYN_SENT state, and mark socket as connecting.
509 * Start keep-alive timer, and seed output sequence space.
510 * Send initial segment on connection.
513 tcp_usr_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
517 struct tcpcb *tp = NULL;
518 struct sockaddr_in *sinp;
520 sinp = (struct sockaddr_in *)nam;
521 if (nam->sa_len != sizeof (*sinp))
524 * Must disallow TCP ``connections'' to multicast addresses.
526 if (sinp->sin_family == AF_INET
527 && IN_MULTICAST(ntohl(sinp->sin_addr.s_addr)))
528 return (EAFNOSUPPORT);
529 if ((error = prison_remote_ip4(td->td_ucred, &sinp->sin_addr)) != 0)
534 KASSERT(inp != NULL, ("tcp_usr_connect: inp == NULL"));
536 if (inp->inp_flags & INP_TIMEWAIT) {
540 if (inp->inp_flags & INP_DROPPED) {
541 error = ECONNREFUSED;
546 if ((error = tcp_connect(tp, nam, td)) != 0)
549 if (registered_toedevs > 0 &&
550 (so->so_options & SO_NO_OFFLOAD) == 0 &&
551 (error = tcp_offload_connect(so, nam)) == 0)
554 tcp_timer_activate(tp, TT_KEEP, TP_KEEPINIT(tp));
555 error = tp->t_fb->tfb_tcp_output(tp);
557 TCPDEBUG2(PRU_CONNECT);
558 TCP_PROBE2(debug__user, tp, PRU_CONNECT);
566 tcp6_usr_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
570 struct tcpcb *tp = NULL;
571 struct sockaddr_in6 *sin6;
575 sin6 = (struct sockaddr_in6 *)nam;
576 if (nam->sa_len != sizeof (*sin6))
579 * Must disallow TCP ``connections'' to multicast addresses.
581 if (sin6->sin6_family == AF_INET6
582 && IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr))
583 return (EAFNOSUPPORT);
586 KASSERT(inp != NULL, ("tcp6_usr_connect: inp == NULL"));
588 if (inp->inp_flags & INP_TIMEWAIT) {
592 if (inp->inp_flags & INP_DROPPED) {
593 error = ECONNREFUSED;
600 * XXXRW: Some confusion: V4/V6 flags relate to binding, and
601 * therefore probably require the hash lock, which isn't held here.
602 * Is this a significant problem?
604 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
605 struct sockaddr_in sin;
607 if ((inp->inp_flags & IN6P_IPV6_V6ONLY) != 0) {
611 if ((inp->inp_vflag & INP_IPV4) == 0) {
612 error = EAFNOSUPPORT;
616 in6_sin6_2_sin(&sin, sin6);
617 if (IN_MULTICAST(ntohl(sin.sin_addr.s_addr))) {
618 error = EAFNOSUPPORT;
621 inp->inp_vflag |= INP_IPV4;
622 inp->inp_vflag &= ~INP_IPV6;
623 if ((error = prison_remote_ip4(td->td_ucred,
624 &sin.sin_addr)) != 0)
626 if ((error = tcp_connect(tp, (struct sockaddr *)&sin, td)) != 0)
629 if (registered_toedevs > 0 &&
630 (so->so_options & SO_NO_OFFLOAD) == 0 &&
631 (error = tcp_offload_connect(so, nam)) == 0)
634 error = tp->t_fb->tfb_tcp_output(tp);
637 if ((inp->inp_vflag & INP_IPV6) == 0) {
638 error = EAFNOSUPPORT;
643 inp->inp_vflag &= ~INP_IPV4;
644 inp->inp_vflag |= INP_IPV6;
645 inp->inp_inc.inc_flags |= INC_ISIPV6;
646 if ((error = prison_remote_ip6(td->td_ucred, &sin6->sin6_addr)) != 0)
648 if ((error = tcp6_connect(tp, nam, td)) != 0)
651 if (registered_toedevs > 0 &&
652 (so->so_options & SO_NO_OFFLOAD) == 0 &&
653 (error = tcp_offload_connect(so, nam)) == 0)
656 tcp_timer_activate(tp, TT_KEEP, TP_KEEPINIT(tp));
657 error = tp->t_fb->tfb_tcp_output(tp);
660 TCPDEBUG2(PRU_CONNECT);
661 TCP_PROBE2(debug__user, tp, PRU_CONNECT);
668 * Initiate disconnect from peer.
669 * If connection never passed embryonic stage, just drop;
670 * else if don't need to let data drain, then can just drop anyways,
671 * else have to begin TCP shutdown process: mark socket disconnecting,
672 * drain unread data, state switch to reflect user close, and
673 * send segment (e.g. FIN) to peer. Socket will be really disconnected
674 * when peer sends FIN and acks ours.
676 * SHOULD IMPLEMENT LATER PRU_CONNECT VIA REALLOC TCPCB.
679 tcp_usr_disconnect(struct socket *so)
682 struct tcpcb *tp = NULL;
683 struct epoch_tracker et;
687 INP_INFO_RLOCK_ET(&V_tcbinfo, et);
689 KASSERT(inp != NULL, ("tcp_usr_disconnect: inp == NULL"));
691 if (inp->inp_flags & INP_TIMEWAIT)
693 if (inp->inp_flags & INP_DROPPED) {
701 TCPDEBUG2(PRU_DISCONNECT);
702 TCP_PROBE2(debug__user, tp, PRU_DISCONNECT);
704 INP_INFO_RUNLOCK_ET(&V_tcbinfo, et);
710 * Accept a connection. Essentially all the work is done at higher levels;
711 * just return the address of the peer, storing through addr.
714 tcp_usr_accept(struct socket *so, struct sockaddr **nam)
717 struct inpcb *inp = NULL;
718 struct tcpcb *tp = NULL;
723 if (so->so_state & SS_ISDISCONNECTED)
724 return (ECONNABORTED);
727 KASSERT(inp != NULL, ("tcp_usr_accept: inp == NULL"));
729 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
730 error = ECONNABORTED;
737 * We inline in_getpeeraddr and COMMON_END here, so that we can
738 * copy the data of interest and defer the malloc until after we
741 port = inp->inp_fport;
742 addr = inp->inp_faddr;
745 TCPDEBUG2(PRU_ACCEPT);
746 TCP_PROBE2(debug__user, tp, PRU_ACCEPT);
749 *nam = in_sockaddr(port, &addr);
756 tcp6_usr_accept(struct socket *so, struct sockaddr **nam)
758 struct inpcb *inp = NULL;
760 struct tcpcb *tp = NULL;
762 struct in6_addr addr6;
763 struct epoch_tracker et;
768 if (so->so_state & SS_ISDISCONNECTED)
769 return (ECONNABORTED);
772 KASSERT(inp != NULL, ("tcp6_usr_accept: inp == NULL"));
773 INP_INFO_RLOCK_ET(&V_tcbinfo, et);
775 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
776 error = ECONNABORTED;
783 * We inline in6_mapped_peeraddr and COMMON_END here, so that we can
784 * copy the data of interest and defer the malloc until after we
787 if (inp->inp_vflag & INP_IPV4) {
789 port = inp->inp_fport;
790 addr = inp->inp_faddr;
792 port = inp->inp_fport;
793 addr6 = inp->in6p_faddr;
797 TCPDEBUG2(PRU_ACCEPT);
798 TCP_PROBE2(debug__user, tp, PRU_ACCEPT);
800 INP_INFO_RUNLOCK_ET(&V_tcbinfo, et);
803 *nam = in6_v4mapsin6_sockaddr(port, &addr);
805 *nam = in6_sockaddr(port, &addr6);
812 * Mark the connection as being incapable of further output.
815 tcp_usr_shutdown(struct socket *so)
819 struct tcpcb *tp = NULL;
820 struct epoch_tracker et;
823 INP_INFO_RLOCK_ET(&V_tcbinfo, et);
825 KASSERT(inp != NULL, ("inp == NULL"));
827 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
835 if (!(inp->inp_flags & INP_DROPPED))
836 error = tp->t_fb->tfb_tcp_output(tp);
839 TCPDEBUG2(PRU_SHUTDOWN);
840 TCP_PROBE2(debug__user, tp, PRU_SHUTDOWN);
842 INP_INFO_RUNLOCK_ET(&V_tcbinfo, et);
848 * After a receive, possibly send window update to peer.
851 tcp_usr_rcvd(struct socket *so, int flags)
854 struct tcpcb *tp = NULL;
859 KASSERT(inp != NULL, ("tcp_usr_rcvd: inp == NULL"));
861 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
868 * For passively-created TFO connections, don't attempt a window
869 * update while still in SYN_RECEIVED as this may trigger an early
870 * SYN|ACK. It is preferable to have the SYN|ACK be sent along with
871 * application response data, or failing that, when the DELACK timer
874 if (IS_FASTOPEN(tp->t_flags) &&
875 (tp->t_state == TCPS_SYN_RECEIVED))
878 if (tp->t_flags & TF_TOE)
879 tcp_offload_rcvd(tp);
882 tp->t_fb->tfb_tcp_output(tp);
886 TCP_PROBE2(debug__user, tp, PRU_RCVD);
892 * Do a send by putting data in output queue and updating urgent
893 * marker if URG set. Possibly send more data. Unlike the other
894 * pru_*() routines, the mbuf chains are our responsibility. We
895 * must either enqueue them or free them. The other pru_* routines
896 * generally are caller-frees.
899 tcp_usr_send(struct socket *so, int flags, struct mbuf *m,
900 struct sockaddr *nam, struct mbuf *control, struct thread *td)
904 struct tcpcb *tp = NULL;
905 struct epoch_tracker net_et;
908 struct sockaddr_in sin;
910 struct sockaddr_in *sinp;
918 * We require the pcbinfo lock if we will close the socket as part of
921 if (flags & PRUS_EOF)
922 INP_INFO_RLOCK_ET(&V_tcbinfo, net_et);
924 KASSERT(inp != NULL, ("tcp_usr_send: inp == NULL"));
926 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
930 * In case of PRUS_NOTREADY, tcp_usr_ready() is responsible
931 * for freeing memory.
933 if (m && (flags & PRUS_NOTREADY) == 0)
940 if (nam != NULL && tp->t_state < TCPS_SYN_SENT) {
941 switch (nam->sa_family) {
944 sinp = (struct sockaddr_in *)nam;
945 if (sinp->sin_len != sizeof(struct sockaddr_in)) {
951 if ((inp->inp_vflag & INP_IPV6) != 0) {
954 error = EAFNOSUPPORT;
957 if (IN_MULTICAST(ntohl(sinp->sin_addr.s_addr))) {
960 error = EAFNOSUPPORT;
963 if ((error = prison_remote_ip4(td->td_ucred,
977 struct sockaddr_in6 *sin6;
979 sin6 = (struct sockaddr_in6 *)nam;
980 if (sin6->sin6_len != sizeof(*sin6)) {
986 if (IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr)) {
989 error = EAFNOSUPPORT;
992 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
994 if ((inp->inp_flags & IN6P_IPV6_V6ONLY) != 0) {
1000 if ((inp->inp_vflag & INP_IPV4) == 0) {
1001 error = EAFNOSUPPORT;
1006 inp->inp_vflag &= ~INP_IPV6;
1008 in6_sin6_2_sin(sinp, sin6);
1010 ntohl(sinp->sin_addr.s_addr))) {
1011 error = EAFNOSUPPORT;
1016 if ((error = prison_remote_ip4(td->td_ucred,
1017 &sinp->sin_addr))) {
1024 error = EAFNOSUPPORT;
1030 if ((inp->inp_vflag & INP_IPV6) == 0) {
1033 error = EAFNOSUPPORT;
1036 inp->inp_vflag &= ~INP_IPV4;
1037 inp->inp_inc.inc_flags |= INC_ISIPV6;
1038 if ((error = prison_remote_ip6(td->td_ucred,
1039 &sin6->sin6_addr))) {
1052 error = EAFNOSUPPORT;
1057 /* TCP doesn't do control messages (rights, creds, etc) */
1058 if (control->m_len) {
1065 m_freem(control); /* empty control, just free it */
1067 if (!(flags & PRUS_OOB)) {
1068 sbappendstream(&so->so_snd, m, flags);
1069 if (nam && tp->t_state < TCPS_SYN_SENT) {
1071 * Do implied connect if not yet connected,
1072 * initialize window to default value, and
1073 * initialize maxseg using peer's cached MSS.
1077 error = tcp6_connect(tp, nam, td);
1079 #if defined(INET6) && defined(INET)
1083 error = tcp_connect(tp,
1084 (struct sockaddr *)sinp, td);
1088 if (IS_FASTOPEN(tp->t_flags))
1089 tcp_fastopen_connect(tp);
1091 tp->snd_wnd = TTCP_CLIENT_SND_WND;
1095 if (flags & PRUS_EOF) {
1097 * Close the send side of the connection after
1100 INP_INFO_RLOCK_ASSERT(&V_tcbinfo);
1104 if (!(inp->inp_flags & INP_DROPPED) &&
1105 !(flags & PRUS_NOTREADY)) {
1106 if (flags & PRUS_MORETOCOME)
1107 tp->t_flags |= TF_MORETOCOME;
1108 error = tp->t_fb->tfb_tcp_output(tp);
1109 if (flags & PRUS_MORETOCOME)
1110 tp->t_flags &= ~TF_MORETOCOME;
1114 * XXXRW: PRUS_EOF not implemented with PRUS_OOB?
1116 SOCKBUF_LOCK(&so->so_snd);
1117 if (sbspace(&so->so_snd) < -512) {
1118 SOCKBUF_UNLOCK(&so->so_snd);
1124 * According to RFC961 (Assigned Protocols),
1125 * the urgent pointer points to the last octet
1126 * of urgent data. We continue, however,
1127 * to consider it to indicate the first octet
1128 * of data past the urgent section.
1129 * Otherwise, snd_up should be one lower.
1131 sbappendstream_locked(&so->so_snd, m, flags);
1132 SOCKBUF_UNLOCK(&so->so_snd);
1133 if (nam && tp->t_state < TCPS_SYN_SENT) {
1135 * Do implied connect if not yet connected,
1136 * initialize window to default value, and
1137 * initialize maxseg using peer's cached MSS.
1141 * Not going to contemplate SYN|URG
1143 if (IS_FASTOPEN(tp->t_flags))
1144 tp->t_flags &= ~TF_FASTOPEN;
1147 error = tcp6_connect(tp, nam, td);
1149 #if defined(INET6) && defined(INET)
1153 error = tcp_connect(tp,
1154 (struct sockaddr *)sinp, td);
1158 tp->snd_wnd = TTCP_CLIENT_SND_WND;
1161 tp->snd_up = tp->snd_una + sbavail(&so->so_snd);
1162 if (!(flags & PRUS_NOTREADY)) {
1163 tp->t_flags |= TF_FORCEDATA;
1164 error = tp->t_fb->tfb_tcp_output(tp);
1165 tp->t_flags &= ~TF_FORCEDATA;
1168 TCP_LOG_EVENT(tp, NULL,
1169 &inp->inp_socket->so_rcv,
1170 &inp->inp_socket->so_snd,
1171 TCP_LOG_USERSEND, error,
1174 TCPDEBUG2((flags & PRUS_OOB) ? PRU_SENDOOB :
1175 ((flags & PRUS_EOF) ? PRU_SEND_EOF : PRU_SEND));
1176 TCP_PROBE2(debug__user, tp, (flags & PRUS_OOB) ? PRU_SENDOOB :
1177 ((flags & PRUS_EOF) ? PRU_SEND_EOF : PRU_SEND));
1179 if (flags & PRUS_EOF)
1180 INP_INFO_RUNLOCK_ET(&V_tcbinfo, net_et);
1185 tcp_usr_ready(struct socket *so, struct mbuf *m, int count)
1191 inp = sotoinpcb(so);
1193 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
1195 mb_free_notready(m, count);
1196 return (ECONNRESET);
1198 tp = intotcpcb(inp);
1200 SOCKBUF_LOCK(&so->so_snd);
1201 error = sbready(&so->so_snd, m, count);
1202 SOCKBUF_UNLOCK(&so->so_snd);
1204 error = tp->t_fb->tfb_tcp_output(tp);
1211 * Abort the TCP. Drop the connection abruptly.
1214 tcp_usr_abort(struct socket *so)
1217 struct tcpcb *tp = NULL;
1218 struct epoch_tracker et;
1221 inp = sotoinpcb(so);
1222 KASSERT(inp != NULL, ("tcp_usr_abort: inp == NULL"));
1224 INP_INFO_RLOCK_ET(&V_tcbinfo, et);
1226 KASSERT(inp->inp_socket != NULL,
1227 ("tcp_usr_abort: inp_socket == NULL"));
1230 * If we still have full TCP state, and we're not dropped, drop.
1232 if (!(inp->inp_flags & INP_TIMEWAIT) &&
1233 !(inp->inp_flags & INP_DROPPED)) {
1234 tp = intotcpcb(inp);
1236 tp = tcp_drop(tp, ECONNABORTED);
1239 TCPDEBUG2(PRU_ABORT);
1240 TCP_PROBE2(debug__user, tp, PRU_ABORT);
1242 if (!(inp->inp_flags & INP_DROPPED)) {
1244 so->so_state |= SS_PROTOREF;
1246 inp->inp_flags |= INP_SOCKREF;
1250 INP_INFO_RUNLOCK_ET(&V_tcbinfo, et);
1254 * TCP socket is closed. Start friendly disconnect.
1257 tcp_usr_close(struct socket *so)
1260 struct tcpcb *tp = NULL;
1261 struct epoch_tracker et;
1264 inp = sotoinpcb(so);
1265 KASSERT(inp != NULL, ("tcp_usr_close: inp == NULL"));
1267 INP_INFO_RLOCK_ET(&V_tcbinfo, et);
1269 KASSERT(inp->inp_socket != NULL,
1270 ("tcp_usr_close: inp_socket == NULL"));
1273 * If we still have full TCP state, and we're not dropped, initiate
1276 if (!(inp->inp_flags & INP_TIMEWAIT) &&
1277 !(inp->inp_flags & INP_DROPPED)) {
1278 tp = intotcpcb(inp);
1281 TCPDEBUG2(PRU_CLOSE);
1282 TCP_PROBE2(debug__user, tp, PRU_CLOSE);
1284 if (!(inp->inp_flags & INP_DROPPED)) {
1286 so->so_state |= SS_PROTOREF;
1288 inp->inp_flags |= INP_SOCKREF;
1291 INP_INFO_RUNLOCK_ET(&V_tcbinfo, et);
1295 * Receive out-of-band data.
1298 tcp_usr_rcvoob(struct socket *so, struct mbuf *m, int flags)
1302 struct tcpcb *tp = NULL;
1305 inp = sotoinpcb(so);
1306 KASSERT(inp != NULL, ("tcp_usr_rcvoob: inp == NULL"));
1308 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
1312 tp = intotcpcb(inp);
1314 if ((so->so_oobmark == 0 &&
1315 (so->so_rcv.sb_state & SBS_RCVATMARK) == 0) ||
1316 so->so_options & SO_OOBINLINE ||
1317 tp->t_oobflags & TCPOOB_HADDATA) {
1321 if ((tp->t_oobflags & TCPOOB_HAVEDATA) == 0) {
1322 error = EWOULDBLOCK;
1326 *mtod(m, caddr_t) = tp->t_iobc;
1327 if ((flags & MSG_PEEK) == 0)
1328 tp->t_oobflags ^= (TCPOOB_HAVEDATA | TCPOOB_HADDATA);
1331 TCPDEBUG2(PRU_RCVOOB);
1332 TCP_PROBE2(debug__user, tp, PRU_RCVOOB);
1338 struct pr_usrreqs tcp_usrreqs = {
1339 .pru_abort = tcp_usr_abort,
1340 .pru_accept = tcp_usr_accept,
1341 .pru_attach = tcp_usr_attach,
1342 .pru_bind = tcp_usr_bind,
1343 .pru_connect = tcp_usr_connect,
1344 .pru_control = in_control,
1345 .pru_detach = tcp_usr_detach,
1346 .pru_disconnect = tcp_usr_disconnect,
1347 .pru_listen = tcp_usr_listen,
1348 .pru_peeraddr = in_getpeeraddr,
1349 .pru_rcvd = tcp_usr_rcvd,
1350 .pru_rcvoob = tcp_usr_rcvoob,
1351 .pru_send = tcp_usr_send,
1352 .pru_ready = tcp_usr_ready,
1353 .pru_shutdown = tcp_usr_shutdown,
1354 .pru_sockaddr = in_getsockaddr,
1355 .pru_sosetlabel = in_pcbsosetlabel,
1356 .pru_close = tcp_usr_close,
1361 struct pr_usrreqs tcp6_usrreqs = {
1362 .pru_abort = tcp_usr_abort,
1363 .pru_accept = tcp6_usr_accept,
1364 .pru_attach = tcp_usr_attach,
1365 .pru_bind = tcp6_usr_bind,
1366 .pru_connect = tcp6_usr_connect,
1367 .pru_control = in6_control,
1368 .pru_detach = tcp_usr_detach,
1369 .pru_disconnect = tcp_usr_disconnect,
1370 .pru_listen = tcp6_usr_listen,
1371 .pru_peeraddr = in6_mapped_peeraddr,
1372 .pru_rcvd = tcp_usr_rcvd,
1373 .pru_rcvoob = tcp_usr_rcvoob,
1374 .pru_send = tcp_usr_send,
1375 .pru_ready = tcp_usr_ready,
1376 .pru_shutdown = tcp_usr_shutdown,
1377 .pru_sockaddr = in6_mapped_sockaddr,
1378 .pru_sosetlabel = in_pcbsosetlabel,
1379 .pru_close = tcp_usr_close,
1385 * Common subroutine to open a TCP connection to remote host specified
1386 * by struct sockaddr_in in mbuf *nam. Call in_pcbbind to assign a local
1387 * port number if needed. Call in_pcbconnect_setup to do the routing and
1388 * to choose a local host address (interface). If there is an existing
1389 * incarnation of the same connection in TIME-WAIT state and if the remote
1390 * host was sending CC options and if the connection duration was < MSL, then
1391 * truncate the previous TIME-WAIT state and proceed.
1392 * Initialize connection parameters and enter SYN-SENT state.
1395 tcp_connect(struct tcpcb *tp, struct sockaddr *nam, struct thread *td)
1397 struct inpcb *inp = tp->t_inpcb, *oinp;
1398 struct socket *so = inp->inp_socket;
1399 struct in_addr laddr;
1403 INP_WLOCK_ASSERT(inp);
1404 INP_HASH_WLOCK(&V_tcbinfo);
1406 if (inp->inp_lport == 0) {
1407 error = in_pcbbind(inp, (struct sockaddr *)0, td->td_ucred);
1413 * Cannot simply call in_pcbconnect, because there might be an
1414 * earlier incarnation of this same connection still in
1415 * TIME_WAIT state, creating an ADDRINUSE error.
1417 laddr = inp->inp_laddr;
1418 lport = inp->inp_lport;
1419 error = in_pcbconnect_setup(inp, nam, &laddr.s_addr, &lport,
1420 &inp->inp_faddr.s_addr, &inp->inp_fport, &oinp, td->td_ucred);
1421 if (error && oinp == NULL)
1427 inp->inp_laddr = laddr;
1429 INP_HASH_WUNLOCK(&V_tcbinfo);
1432 * Compute window scaling to request:
1433 * Scale to fit into sweet spot. See tcp_syncache.c.
1434 * XXX: This should move to tcp_output().
1436 while (tp->request_r_scale < TCP_MAX_WINSHIFT &&
1437 (TCP_MAXWIN << tp->request_r_scale) < sb_max)
1438 tp->request_r_scale++;
1441 TCPSTAT_INC(tcps_connattempt);
1442 tcp_state_change(tp, TCPS_SYN_SENT);
1443 tp->iss = tcp_new_isn(&inp->inp_inc);
1444 if (tp->t_flags & TF_REQ_TSTMP)
1445 tp->ts_offset = tcp_new_ts_offset(&inp->inp_inc);
1446 tcp_sendseqinit(tp);
1451 INP_HASH_WUNLOCK(&V_tcbinfo);
1458 tcp6_connect(struct tcpcb *tp, struct sockaddr *nam, struct thread *td)
1460 struct inpcb *inp = tp->t_inpcb;
1463 INP_WLOCK_ASSERT(inp);
1464 INP_HASH_WLOCK(&V_tcbinfo);
1466 if (inp->inp_lport == 0) {
1467 error = in6_pcbbind(inp, (struct sockaddr *)0, td->td_ucred);
1471 error = in6_pcbconnect(inp, nam, td->td_ucred);
1474 INP_HASH_WUNLOCK(&V_tcbinfo);
1476 /* Compute window scaling to request. */
1477 while (tp->request_r_scale < TCP_MAX_WINSHIFT &&
1478 (TCP_MAXWIN << tp->request_r_scale) < sb_max)
1479 tp->request_r_scale++;
1481 soisconnecting(inp->inp_socket);
1482 TCPSTAT_INC(tcps_connattempt);
1483 tcp_state_change(tp, TCPS_SYN_SENT);
1484 tp->iss = tcp_new_isn(&inp->inp_inc);
1485 if (tp->t_flags & TF_REQ_TSTMP)
1486 tp->ts_offset = tcp_new_ts_offset(&inp->inp_inc);
1487 tcp_sendseqinit(tp);
1492 INP_HASH_WUNLOCK(&V_tcbinfo);
1498 * Export TCP internal state information via a struct tcp_info, based on the
1499 * Linux 2.6 API. Not ABI compatible as our constants are mapped differently
1500 * (TCP state machine, etc). We export all information using FreeBSD-native
1501 * constants -- for example, the numeric values for tcpi_state will differ
1505 tcp_fill_info(struct tcpcb *tp, struct tcp_info *ti)
1508 INP_WLOCK_ASSERT(tp->t_inpcb);
1509 bzero(ti, sizeof(*ti));
1511 ti->tcpi_state = tp->t_state;
1512 if ((tp->t_flags & TF_REQ_TSTMP) && (tp->t_flags & TF_RCVD_TSTMP))
1513 ti->tcpi_options |= TCPI_OPT_TIMESTAMPS;
1514 if (tp->t_flags & TF_SACK_PERMIT)
1515 ti->tcpi_options |= TCPI_OPT_SACK;
1516 if ((tp->t_flags & TF_REQ_SCALE) && (tp->t_flags & TF_RCVD_SCALE)) {
1517 ti->tcpi_options |= TCPI_OPT_WSCALE;
1518 ti->tcpi_snd_wscale = tp->snd_scale;
1519 ti->tcpi_rcv_wscale = tp->rcv_scale;
1521 if (tp->t_flags & TF_ECN_PERMIT)
1522 ti->tcpi_options |= TCPI_OPT_ECN;
1524 ti->tcpi_rto = tp->t_rxtcur * tick;
1525 ti->tcpi_last_data_recv = ((uint32_t)ticks - tp->t_rcvtime) * tick;
1526 ti->tcpi_rtt = ((u_int64_t)tp->t_srtt * tick) >> TCP_RTT_SHIFT;
1527 ti->tcpi_rttvar = ((u_int64_t)tp->t_rttvar * tick) >> TCP_RTTVAR_SHIFT;
1529 ti->tcpi_snd_ssthresh = tp->snd_ssthresh;
1530 ti->tcpi_snd_cwnd = tp->snd_cwnd;
1533 * FreeBSD-specific extension fields for tcp_info.
1535 ti->tcpi_rcv_space = tp->rcv_wnd;
1536 ti->tcpi_rcv_nxt = tp->rcv_nxt;
1537 ti->tcpi_snd_wnd = tp->snd_wnd;
1538 ti->tcpi_snd_bwnd = 0; /* Unused, kept for compat. */
1539 ti->tcpi_snd_nxt = tp->snd_nxt;
1540 ti->tcpi_snd_mss = tp->t_maxseg;
1541 ti->tcpi_rcv_mss = tp->t_maxseg;
1542 ti->tcpi_snd_rexmitpack = tp->t_sndrexmitpack;
1543 ti->tcpi_rcv_ooopack = tp->t_rcvoopack;
1544 ti->tcpi_snd_zerowin = tp->t_sndzerowin;
1546 if (tp->t_flags & TF_TOE) {
1547 ti->tcpi_options |= TCPI_OPT_TOE;
1548 tcp_offload_tcp_info(tp, ti);
1554 * tcp_ctloutput() must drop the inpcb lock before performing copyin on
1555 * socket option arguments. When it re-acquires the lock after the copy, it
1556 * has to revalidate that the connection is still valid for the socket
1559 #define INP_WLOCK_RECHECK_CLEANUP(inp, cleanup) do { \
1561 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) { \
1564 return (ECONNRESET); \
1566 tp = intotcpcb(inp); \
1568 #define INP_WLOCK_RECHECK(inp) INP_WLOCK_RECHECK_CLEANUP((inp), /* noop */)
1571 tcp_ctloutput(struct socket *so, struct sockopt *sopt)
1576 struct tcp_function_block *blk;
1577 struct tcp_function_set fsn;
1580 inp = sotoinpcb(so);
1581 KASSERT(inp != NULL, ("tcp_ctloutput: inp == NULL"));
1582 if (sopt->sopt_level != IPPROTO_TCP) {
1584 if (inp->inp_vflag & INP_IPV6PROTO) {
1585 error = ip6_ctloutput(so, sopt);
1587 * In case of the IPV6_USE_MIN_MTU socket option,
1588 * the INC_IPV6MINMTU flag to announce a corresponding
1589 * MSS during the initial handshake.
1590 * If the TCP connection is not in the front states,
1591 * just reduce the MSS being used.
1592 * This avoids the sending of TCP segments which will
1593 * be fragmented at the IPv6 layer.
1596 (sopt->sopt_dir == SOPT_SET) &&
1597 (sopt->sopt_level == IPPROTO_IPV6) &&
1598 (sopt->sopt_name == IPV6_USE_MIN_MTU)) {
1600 if ((inp->inp_flags &
1601 (INP_TIMEWAIT | INP_DROPPED))) {
1603 return (ECONNRESET);
1605 inp->inp_inc.inc_flags |= INC_IPV6MINMTU;
1606 tp = intotcpcb(inp);
1607 if ((tp->t_state >= TCPS_SYN_SENT) &&
1608 (inp->inp_inc.inc_flags & INC_ISIPV6)) {
1609 struct ip6_pktopts *opt;
1611 opt = inp->in6p_outputopts;
1612 if ((opt != NULL) &&
1613 (opt->ip6po_minmtu ==
1614 IP6PO_MINMTU_ALL)) {
1615 if (tp->t_maxseg > TCP6_MSS) {
1616 tp->t_maxseg = TCP6_MSS;
1624 #if defined(INET6) && defined(INET)
1629 error = ip_ctloutput(so, sopt);
1635 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
1637 return (ECONNRESET);
1639 tp = intotcpcb(inp);
1641 * Protect the TCP option TCP_FUNCTION_BLK so
1642 * that a sub-function can *never* overwrite this.
1644 if ((sopt->sopt_dir == SOPT_SET) &&
1645 (sopt->sopt_name == TCP_FUNCTION_BLK)) {
1647 error = sooptcopyin(sopt, &fsn, sizeof fsn,
1651 INP_WLOCK_RECHECK(inp);
1652 blk = find_and_ref_tcp_functions(&fsn);
1657 if (tp->t_fb == blk) {
1658 /* You already have this */
1659 refcount_release(&blk->tfb_refcnt);
1663 if (tp->t_state != TCPS_CLOSED) {
1665 * The user has advanced the state
1666 * past the initial point, we may not
1667 * be able to switch.
1669 if (blk->tfb_tcp_handoff_ok != NULL) {
1671 * Does the stack provide a
1672 * query mechanism, if so it may
1673 * still be possible?
1675 error = (*blk->tfb_tcp_handoff_ok)(tp);
1679 refcount_release(&blk->tfb_refcnt);
1684 if (blk->tfb_flags & TCP_FUNC_BEING_REMOVED) {
1685 refcount_release(&blk->tfb_refcnt);
1690 * Release the old refcnt, the
1691 * lookup acquired a ref on the
1694 if (tp->t_fb->tfb_tcp_fb_fini) {
1696 * Tell the stack to cleanup with 0 i.e.
1697 * the tcb is not going away.
1699 (*tp->t_fb->tfb_tcp_fb_fini)(tp, 0);
1702 /* Assure that we are not on any hpts */
1703 tcp_hpts_remove(tp->t_inpcb, HPTS_REMOVE_ALL);
1705 if (blk->tfb_tcp_fb_init) {
1706 error = (*blk->tfb_tcp_fb_init)(tp);
1708 refcount_release(&blk->tfb_refcnt);
1709 if (tp->t_fb->tfb_tcp_fb_init) {
1710 if((*tp->t_fb->tfb_tcp_fb_init)(tp) != 0) {
1711 /* Fall back failed, drop the connection */
1720 refcount_release(&tp->t_fb->tfb_refcnt);
1723 if (tp->t_flags & TF_TOE) {
1724 tcp_offload_ctloutput(tp, sopt->sopt_dir,
1731 } else if ((sopt->sopt_dir == SOPT_GET) &&
1732 (sopt->sopt_name == TCP_FUNCTION_BLK)) {
1733 strncpy(fsn.function_set_name, tp->t_fb->tfb_tcp_block_name,
1734 TCP_FUNCTION_NAME_LEN_MAX);
1735 fsn.function_set_name[TCP_FUNCTION_NAME_LEN_MAX - 1] = '\0';
1736 fsn.pcbcnt = tp->t_fb->tfb_refcnt;
1738 error = sooptcopyout(sopt, &fsn, sizeof fsn);
1741 /* Pass in the INP locked, called must unlock it */
1742 return (tp->t_fb->tfb_tcp_ctloutput(so, sopt, inp, tp));
1746 * If this assert becomes untrue, we need to change the size of the buf
1747 * variable in tcp_default_ctloutput().
1750 CTASSERT(TCP_CA_NAME_MAX <= TCP_LOG_ID_LEN);
1751 CTASSERT(TCP_LOG_REASON_LEN <= TCP_LOG_ID_LEN);
1755 tcp_default_ctloutput(struct socket *so, struct sockopt *sopt, struct inpcb *inp, struct tcpcb *tp)
1757 int error, opt, optval;
1761 struct tls_enable tls;
1763 struct cc_algo *algo;
1764 char *pbuf, buf[TCP_LOG_ID_LEN];
1768 * For TCP_CCALGOOPT forward the control to CC module, for both
1769 * SOPT_SET and SOPT_GET.
1771 switch (sopt->sopt_name) {
1774 if (sopt->sopt_valsize > CC_ALGOOPT_LIMIT)
1776 pbuf = malloc(sopt->sopt_valsize, M_TEMP, M_WAITOK | M_ZERO);
1777 error = sooptcopyin(sopt, pbuf, sopt->sopt_valsize,
1778 sopt->sopt_valsize);
1783 INP_WLOCK_RECHECK_CLEANUP(inp, free(pbuf, M_TEMP));
1784 if (CC_ALGO(tp)->ctl_output != NULL)
1785 error = CC_ALGO(tp)->ctl_output(tp->ccv, sopt, pbuf);
1789 if (error == 0 && sopt->sopt_dir == SOPT_GET)
1790 error = sooptcopyout(sopt, pbuf, sopt->sopt_valsize);
1795 switch (sopt->sopt_dir) {
1797 switch (sopt->sopt_name) {
1798 #if defined(IPSEC_SUPPORT) || defined(TCP_SIGNATURE)
1800 if (!TCPMD5_ENABLED()) {
1802 return (ENOPROTOOPT);
1804 error = TCPMD5_PCBCTL(inp, sopt);
1807 goto unlock_and_done;
1813 error = sooptcopyin(sopt, &optval, sizeof optval,
1818 INP_WLOCK_RECHECK(inp);
1819 switch (sopt->sopt_name) {
1827 opt = 0; /* dead code to fool gcc */
1834 tp->t_flags &= ~opt;
1837 if (tp->t_flags & TF_TOE) {
1838 tcp_offload_ctloutput(tp, sopt->sopt_dir,
1847 error = sooptcopyin(sopt, &optval, sizeof optval,
1852 INP_WLOCK_RECHECK(inp);
1854 tp->t_flags |= TF_NOPUSH;
1855 else if (tp->t_flags & TF_NOPUSH) {
1856 tp->t_flags &= ~TF_NOPUSH;
1857 if (TCPS_HAVEESTABLISHED(tp->t_state))
1858 error = tp->t_fb->tfb_tcp_output(tp);
1860 goto unlock_and_done;
1864 error = sooptcopyin(sopt, &optval, sizeof optval,
1869 INP_WLOCK_RECHECK(inp);
1870 if (optval > 0 && optval <= tp->t_maxseg &&
1871 optval + 40 >= V_tcp_minmss)
1872 tp->t_maxseg = optval;
1875 goto unlock_and_done;
1882 case TCP_CONGESTION:
1884 error = sooptcopyin(sopt, buf, TCP_CA_NAME_MAX - 1, 1);
1887 buf[sopt->sopt_valsize] = '\0';
1888 INP_WLOCK_RECHECK(inp);
1890 STAILQ_FOREACH(algo, &cc_list, entries)
1891 if (strncmp(buf, algo->name,
1892 TCP_CA_NAME_MAX) == 0)
1901 * We hold a write lock over the tcb so it's safe to
1902 * do these things without ordering concerns.
1904 if (CC_ALGO(tp)->cb_destroy != NULL)
1905 CC_ALGO(tp)->cb_destroy(tp->ccv);
1909 * If something goes pear shaped initialising the new
1910 * algo, fall back to newreno (which does not
1911 * require initialisation).
1913 if (algo->cb_init != NULL &&
1914 algo->cb_init(tp->ccv) != 0) {
1915 CC_ALGO(tp) = &newreno_cc_algo;
1917 * The only reason init should fail is
1918 * because of malloc.
1926 case TCP_TXTLS_ENABLE:
1928 error = sooptcopyin(sopt, &tls, sizeof(tls),
1932 error = ktls_enable_tx(so, &tls);
1934 case TCP_TXTLS_MODE:
1936 error = sooptcopyin(sopt, &ui, sizeof(ui), sizeof(ui));
1939 if (ui != TCP_TLS_MODE_SW && ui != TCP_TLS_MODE_IFNET)
1942 INP_WLOCK_RECHECK(inp);
1943 error = ktls_set_tx_mode(so, ui);
1952 error = sooptcopyin(sopt, &ui, sizeof(ui), sizeof(ui));
1956 if (ui > (UINT_MAX / hz)) {
1962 INP_WLOCK_RECHECK(inp);
1963 switch (sopt->sopt_name) {
1965 tp->t_keepidle = ui;
1967 * XXX: better check current remaining
1968 * timeout and "merge" it with new value.
1970 if ((tp->t_state > TCPS_LISTEN) &&
1971 (tp->t_state <= TCPS_CLOSING))
1972 tcp_timer_activate(tp, TT_KEEP,
1976 tp->t_keepintvl = ui;
1977 if ((tp->t_state == TCPS_FIN_WAIT_2) &&
1978 (TP_MAXIDLE(tp) > 0))
1979 tcp_timer_activate(tp, TT_2MSL,
1983 tp->t_keepinit = ui;
1984 if (tp->t_state == TCPS_SYN_RECEIVED ||
1985 tp->t_state == TCPS_SYN_SENT)
1986 tcp_timer_activate(tp, TT_KEEP,
1990 goto unlock_and_done;
1994 error = sooptcopyin(sopt, &ui, sizeof(ui), sizeof(ui));
1998 INP_WLOCK_RECHECK(inp);
2000 if ((tp->t_state == TCPS_FIN_WAIT_2) &&
2001 (TP_MAXIDLE(tp) > 0))
2002 tcp_timer_activate(tp, TT_2MSL,
2004 goto unlock_and_done;
2010 error = sooptcopyin(sopt, &optval, sizeof optval,
2015 INP_WLOCK_RECHECK(inp);
2017 tcp_pcap_set_sock_max(TCP_PCAP_OUT ?
2018 &(tp->t_outpkts) : &(tp->t_inpkts),
2022 goto unlock_and_done;
2025 case TCP_FASTOPEN: {
2026 struct tcp_fastopen tfo_optval;
2029 if (!V_tcp_fastopen_client_enable &&
2030 !V_tcp_fastopen_server_enable)
2033 error = sooptcopyin(sopt, &tfo_optval,
2034 sizeof(tfo_optval), sizeof(int));
2038 INP_WLOCK_RECHECK(inp);
2039 if (tfo_optval.enable) {
2040 if (tp->t_state == TCPS_LISTEN) {
2041 if (!V_tcp_fastopen_server_enable) {
2043 goto unlock_and_done;
2046 tp->t_flags |= TF_FASTOPEN;
2047 if (tp->t_tfo_pending == NULL)
2049 tcp_fastopen_alloc_counter();
2052 * If a pre-shared key was provided,
2053 * stash it in the client cookie
2054 * field of the tcpcb for use during
2057 if (sopt->sopt_valsize ==
2058 sizeof(tfo_optval)) {
2059 memcpy(tp->t_tfo_cookie.client,
2061 TCP_FASTOPEN_PSK_LEN);
2062 tp->t_tfo_client_cookie_len =
2063 TCP_FASTOPEN_PSK_LEN;
2065 tp->t_flags |= TF_FASTOPEN;
2068 tp->t_flags &= ~TF_FASTOPEN;
2069 goto unlock_and_done;
2075 error = sooptcopyin(sopt, &optval, sizeof optval,
2080 INP_WLOCK_RECHECK(inp);
2081 error = tcp_log_state_change(tp, optval);
2082 goto unlock_and_done;
2091 error = sooptcopyin(sopt, buf, TCP_LOG_ID_LEN - 1, 0);
2094 buf[sopt->sopt_valsize] = '\0';
2095 INP_WLOCK_RECHECK(inp);
2096 error = tcp_log_set_id(tp, buf);
2097 /* tcp_log_set_id() unlocks the INP. */
2104 sooptcopyin(sopt, buf, TCP_LOG_REASON_LEN - 1, 0);
2107 buf[sopt->sopt_valsize] = '\0';
2108 INP_WLOCK_RECHECK(inp);
2109 if (sopt->sopt_name == TCP_LOGDUMP) {
2110 error = tcp_log_dump_tp_logbuf(tp, buf,
2114 tcp_log_dump_tp_bucket_logbufs(tp, buf);
2116 * tcp_log_dump_tp_bucket_logbufs() drops the
2125 error = ENOPROTOOPT;
2131 tp = intotcpcb(inp);
2132 switch (sopt->sopt_name) {
2133 #if defined(IPSEC_SUPPORT) || defined(TCP_SIGNATURE)
2135 if (!TCPMD5_ENABLED()) {
2137 return (ENOPROTOOPT);
2139 error = TCPMD5_PCBCTL(inp, sopt);
2144 optval = tp->t_flags & TF_NODELAY;
2146 error = sooptcopyout(sopt, &optval, sizeof optval);
2149 optval = tp->t_maxseg;
2151 error = sooptcopyout(sopt, &optval, sizeof optval);
2154 optval = tp->t_flags & TF_NOOPT;
2156 error = sooptcopyout(sopt, &optval, sizeof optval);
2159 optval = tp->t_flags & TF_NOPUSH;
2161 error = sooptcopyout(sopt, &optval, sizeof optval);
2164 tcp_fill_info(tp, &ti);
2166 error = sooptcopyout(sopt, &ti, sizeof ti);
2168 case TCP_CONGESTION:
2169 len = strlcpy(buf, CC_ALGO(tp)->name, TCP_CA_NAME_MAX);
2171 error = sooptcopyout(sopt, buf, len + 1);
2177 switch (sopt->sopt_name) {
2179 ui = TP_KEEPIDLE(tp) / hz;
2182 ui = TP_KEEPINTVL(tp) / hz;
2185 ui = TP_KEEPINIT(tp) / hz;
2188 ui = TP_KEEPCNT(tp);
2192 error = sooptcopyout(sopt, &ui, sizeof(ui));
2197 optval = tcp_pcap_get_sock_max(TCP_PCAP_OUT ?
2198 &(tp->t_outpkts) : &(tp->t_inpkts));
2200 error = sooptcopyout(sopt, &optval, sizeof optval);
2204 optval = tp->t_flags & TF_FASTOPEN;
2206 error = sooptcopyout(sopt, &optval, sizeof optval);
2210 optval = tp->t_logstate;
2212 error = sooptcopyout(sopt, &optval, sizeof(optval));
2215 /* tcp_log_getlogbuf() does INP_WUNLOCK(inp) */
2216 error = tcp_log_getlogbuf(sopt, tp);
2219 len = tcp_log_get_id(tp, buf);
2221 error = sooptcopyout(sopt, buf, len + 1);
2230 case TCP_TXTLS_MODE:
2231 optval = ktls_get_tx_mode(so);
2233 error = sooptcopyout(sopt, &optval, sizeof(optval));
2238 error = ENOPROTOOPT;
2245 #undef INP_WLOCK_RECHECK
2246 #undef INP_WLOCK_RECHECK_CLEANUP
2249 * Attach TCP protocol to socket, allocating
2250 * internet protocol control block, tcp control block,
2251 * bufer space, and entering LISTEN state if to accept connections.
2254 tcp_attach(struct socket *so)
2258 struct epoch_tracker et;
2261 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
2262 error = soreserve(so, V_tcp_sendspace, V_tcp_recvspace);
2266 so->so_rcv.sb_flags |= SB_AUTOSIZE;
2267 so->so_snd.sb_flags |= SB_AUTOSIZE;
2268 INP_INFO_RLOCK_ET(&V_tcbinfo, et);
2269 error = in_pcballoc(so, &V_tcbinfo);
2271 INP_INFO_RUNLOCK_ET(&V_tcbinfo, et);
2274 inp = sotoinpcb(so);
2276 if (inp->inp_vflag & INP_IPV6PROTO) {
2277 inp->inp_vflag |= INP_IPV6;
2278 if ((inp->inp_flags & IN6P_IPV6_V6ONLY) == 0)
2279 inp->inp_vflag |= INP_IPV4;
2280 inp->in6p_hops = -1; /* use kernel default */
2284 inp->inp_vflag |= INP_IPV4;
2285 tp = tcp_newtcpcb(inp);
2289 INP_INFO_RUNLOCK_ET(&V_tcbinfo, et);
2292 tp->t_state = TCPS_CLOSED;
2294 INP_INFO_RUNLOCK_ET(&V_tcbinfo, et);
2295 TCPSTATES_INC(TCPS_CLOSED);
2300 * Initiate (or continue) disconnect.
2301 * If embryonic state, just send reset (once).
2302 * If in ``let data drain'' option and linger null, just drop.
2303 * Otherwise (hard), mark socket disconnecting and drop
2304 * current input data; switch states based on user close, and
2305 * send segment to peer (with FIN).
2308 tcp_disconnect(struct tcpcb *tp)
2310 struct inpcb *inp = tp->t_inpcb;
2311 struct socket *so = inp->inp_socket;
2313 INP_INFO_RLOCK_ASSERT(&V_tcbinfo);
2314 INP_WLOCK_ASSERT(inp);
2317 * Neither tcp_close() nor tcp_drop() should return NULL, as the
2318 * socket is still open.
2320 if (tp->t_state < TCPS_ESTABLISHED &&
2321 !(tp->t_state > TCPS_LISTEN && IS_FASTOPEN(tp->t_flags))) {
2324 ("tcp_disconnect: tcp_close() returned NULL"));
2325 } else if ((so->so_options & SO_LINGER) && so->so_linger == 0) {
2326 tp = tcp_drop(tp, 0);
2328 ("tcp_disconnect: tcp_drop() returned NULL"));
2330 soisdisconnecting(so);
2331 sbflush(&so->so_rcv);
2333 if (!(inp->inp_flags & INP_DROPPED))
2334 tp->t_fb->tfb_tcp_output(tp);
2339 * User issued close, and wish to trail through shutdown states:
2340 * if never received SYN, just forget it. If got a SYN from peer,
2341 * but haven't sent FIN, then go to FIN_WAIT_1 state to send peer a FIN.
2342 * If already got a FIN from peer, then almost done; go to LAST_ACK
2343 * state. In all other cases, have already sent FIN to peer (e.g.
2344 * after PRU_SHUTDOWN), and just have to play tedious game waiting
2345 * for peer to send FIN or not respond to keep-alives, etc.
2346 * We can let the user exit from the close as soon as the FIN is acked.
2349 tcp_usrclosed(struct tcpcb *tp)
2352 INP_INFO_RLOCK_ASSERT(&V_tcbinfo);
2353 INP_WLOCK_ASSERT(tp->t_inpcb);
2355 switch (tp->t_state) {
2358 tcp_offload_listen_stop(tp);
2360 tcp_state_change(tp, TCPS_CLOSED);
2365 * tcp_close() should never return NULL here as the socket is
2369 ("tcp_usrclosed: tcp_close() returned NULL"));
2373 case TCPS_SYN_RECEIVED:
2374 tp->t_flags |= TF_NEEDFIN;
2377 case TCPS_ESTABLISHED:
2378 tcp_state_change(tp, TCPS_FIN_WAIT_1);
2381 case TCPS_CLOSE_WAIT:
2382 tcp_state_change(tp, TCPS_LAST_ACK);
2385 if (tp->t_state >= TCPS_FIN_WAIT_2) {
2386 soisdisconnected(tp->t_inpcb->inp_socket);
2387 /* Prevent the connection hanging in FIN_WAIT_2 forever. */
2388 if (tp->t_state == TCPS_FIN_WAIT_2) {
2391 timeout = (tcp_fast_finwait2_recycle) ?
2392 tcp_finwait2_timeout : TP_MAXIDLE(tp);
2393 tcp_timer_activate(tp, TT_2MSL, timeout);
2400 db_print_indent(int indent)
2404 for (i = 0; i < indent; i++)
2409 db_print_tstate(int t_state)
2414 db_printf("TCPS_CLOSED");
2418 db_printf("TCPS_LISTEN");
2422 db_printf("TCPS_SYN_SENT");
2425 case TCPS_SYN_RECEIVED:
2426 db_printf("TCPS_SYN_RECEIVED");
2429 case TCPS_ESTABLISHED:
2430 db_printf("TCPS_ESTABLISHED");
2433 case TCPS_CLOSE_WAIT:
2434 db_printf("TCPS_CLOSE_WAIT");
2437 case TCPS_FIN_WAIT_1:
2438 db_printf("TCPS_FIN_WAIT_1");
2442 db_printf("TCPS_CLOSING");
2446 db_printf("TCPS_LAST_ACK");
2449 case TCPS_FIN_WAIT_2:
2450 db_printf("TCPS_FIN_WAIT_2");
2453 case TCPS_TIME_WAIT:
2454 db_printf("TCPS_TIME_WAIT");
2458 db_printf("unknown");
2464 db_print_tflags(u_int t_flags)
2469 if (t_flags & TF_ACKNOW) {
2470 db_printf("%sTF_ACKNOW", comma ? ", " : "");
2473 if (t_flags & TF_DELACK) {
2474 db_printf("%sTF_DELACK", comma ? ", " : "");
2477 if (t_flags & TF_NODELAY) {
2478 db_printf("%sTF_NODELAY", comma ? ", " : "");
2481 if (t_flags & TF_NOOPT) {
2482 db_printf("%sTF_NOOPT", comma ? ", " : "");
2485 if (t_flags & TF_SENTFIN) {
2486 db_printf("%sTF_SENTFIN", comma ? ", " : "");
2489 if (t_flags & TF_REQ_SCALE) {
2490 db_printf("%sTF_REQ_SCALE", comma ? ", " : "");
2493 if (t_flags & TF_RCVD_SCALE) {
2494 db_printf("%sTF_RECVD_SCALE", comma ? ", " : "");
2497 if (t_flags & TF_REQ_TSTMP) {
2498 db_printf("%sTF_REQ_TSTMP", comma ? ", " : "");
2501 if (t_flags & TF_RCVD_TSTMP) {
2502 db_printf("%sTF_RCVD_TSTMP", comma ? ", " : "");
2505 if (t_flags & TF_SACK_PERMIT) {
2506 db_printf("%sTF_SACK_PERMIT", comma ? ", " : "");
2509 if (t_flags & TF_NEEDSYN) {
2510 db_printf("%sTF_NEEDSYN", comma ? ", " : "");
2513 if (t_flags & TF_NEEDFIN) {
2514 db_printf("%sTF_NEEDFIN", comma ? ", " : "");
2517 if (t_flags & TF_NOPUSH) {
2518 db_printf("%sTF_NOPUSH", comma ? ", " : "");
2521 if (t_flags & TF_MORETOCOME) {
2522 db_printf("%sTF_MORETOCOME", comma ? ", " : "");
2525 if (t_flags & TF_LQ_OVERFLOW) {
2526 db_printf("%sTF_LQ_OVERFLOW", comma ? ", " : "");
2529 if (t_flags & TF_LASTIDLE) {
2530 db_printf("%sTF_LASTIDLE", comma ? ", " : "");
2533 if (t_flags & TF_RXWIN0SENT) {
2534 db_printf("%sTF_RXWIN0SENT", comma ? ", " : "");
2537 if (t_flags & TF_FASTRECOVERY) {
2538 db_printf("%sTF_FASTRECOVERY", comma ? ", " : "");
2541 if (t_flags & TF_CONGRECOVERY) {
2542 db_printf("%sTF_CONGRECOVERY", comma ? ", " : "");
2545 if (t_flags & TF_WASFRECOVERY) {
2546 db_printf("%sTF_WASFRECOVERY", comma ? ", " : "");
2549 if (t_flags & TF_SIGNATURE) {
2550 db_printf("%sTF_SIGNATURE", comma ? ", " : "");
2553 if (t_flags & TF_FORCEDATA) {
2554 db_printf("%sTF_FORCEDATA", comma ? ", " : "");
2557 if (t_flags & TF_TSO) {
2558 db_printf("%sTF_TSO", comma ? ", " : "");
2561 if (t_flags & TF_ECN_PERMIT) {
2562 db_printf("%sTF_ECN_PERMIT", comma ? ", " : "");
2565 if (t_flags & TF_FASTOPEN) {
2566 db_printf("%sTF_FASTOPEN", comma ? ", " : "");
2572 db_print_toobflags(char t_oobflags)
2577 if (t_oobflags & TCPOOB_HAVEDATA) {
2578 db_printf("%sTCPOOB_HAVEDATA", comma ? ", " : "");
2581 if (t_oobflags & TCPOOB_HADDATA) {
2582 db_printf("%sTCPOOB_HADDATA", comma ? ", " : "");
2588 db_print_tcpcb(struct tcpcb *tp, const char *name, int indent)
2591 db_print_indent(indent);
2592 db_printf("%s at %p\n", name, tp);
2596 db_print_indent(indent);
2597 db_printf("t_segq first: %p t_segqlen: %d t_dupacks: %d\n",
2598 TAILQ_FIRST(&tp->t_segq), tp->t_segqlen, tp->t_dupacks);
2600 db_print_indent(indent);
2601 db_printf("tt_rexmt: %p tt_persist: %p tt_keep: %p\n",
2602 &tp->t_timers->tt_rexmt, &tp->t_timers->tt_persist, &tp->t_timers->tt_keep);
2604 db_print_indent(indent);
2605 db_printf("tt_2msl: %p tt_delack: %p t_inpcb: %p\n", &tp->t_timers->tt_2msl,
2606 &tp->t_timers->tt_delack, tp->t_inpcb);
2608 db_print_indent(indent);
2609 db_printf("t_state: %d (", tp->t_state);
2610 db_print_tstate(tp->t_state);
2613 db_print_indent(indent);
2614 db_printf("t_flags: 0x%x (", tp->t_flags);
2615 db_print_tflags(tp->t_flags);
2618 db_print_indent(indent);
2619 db_printf("snd_una: 0x%08x snd_max: 0x%08x snd_nxt: x0%08x\n",
2620 tp->snd_una, tp->snd_max, tp->snd_nxt);
2622 db_print_indent(indent);
2623 db_printf("snd_up: 0x%08x snd_wl1: 0x%08x snd_wl2: 0x%08x\n",
2624 tp->snd_up, tp->snd_wl1, tp->snd_wl2);
2626 db_print_indent(indent);
2627 db_printf("iss: 0x%08x irs: 0x%08x rcv_nxt: 0x%08x\n",
2628 tp->iss, tp->irs, tp->rcv_nxt);
2630 db_print_indent(indent);
2631 db_printf("rcv_adv: 0x%08x rcv_wnd: %u rcv_up: 0x%08x\n",
2632 tp->rcv_adv, tp->rcv_wnd, tp->rcv_up);
2634 db_print_indent(indent);
2635 db_printf("snd_wnd: %u snd_cwnd: %u\n",
2636 tp->snd_wnd, tp->snd_cwnd);
2638 db_print_indent(indent);
2639 db_printf("snd_ssthresh: %u snd_recover: "
2640 "0x%08x\n", tp->snd_ssthresh, tp->snd_recover);
2642 db_print_indent(indent);
2643 db_printf("t_rcvtime: %u t_startime: %u\n",
2644 tp->t_rcvtime, tp->t_starttime);
2646 db_print_indent(indent);
2647 db_printf("t_rttime: %u t_rtsq: 0x%08x\n",
2648 tp->t_rtttime, tp->t_rtseq);
2650 db_print_indent(indent);
2651 db_printf("t_rxtcur: %d t_maxseg: %u t_srtt: %d\n",
2652 tp->t_rxtcur, tp->t_maxseg, tp->t_srtt);
2654 db_print_indent(indent);
2655 db_printf("t_rttvar: %d t_rxtshift: %d t_rttmin: %u "
2656 "t_rttbest: %u\n", tp->t_rttvar, tp->t_rxtshift, tp->t_rttmin,
2659 db_print_indent(indent);
2660 db_printf("t_rttupdated: %lu max_sndwnd: %u t_softerror: %d\n",
2661 tp->t_rttupdated, tp->max_sndwnd, tp->t_softerror);
2663 db_print_indent(indent);
2664 db_printf("t_oobflags: 0x%x (", tp->t_oobflags);
2665 db_print_toobflags(tp->t_oobflags);
2666 db_printf(") t_iobc: 0x%02x\n", tp->t_iobc);
2668 db_print_indent(indent);
2669 db_printf("snd_scale: %u rcv_scale: %u request_r_scale: %u\n",
2670 tp->snd_scale, tp->rcv_scale, tp->request_r_scale);
2672 db_print_indent(indent);
2673 db_printf("ts_recent: %u ts_recent_age: %u\n",
2674 tp->ts_recent, tp->ts_recent_age);
2676 db_print_indent(indent);
2677 db_printf("ts_offset: %u last_ack_sent: 0x%08x snd_cwnd_prev: "
2678 "%u\n", tp->ts_offset, tp->last_ack_sent, tp->snd_cwnd_prev);
2680 db_print_indent(indent);
2681 db_printf("snd_ssthresh_prev: %u snd_recover_prev: 0x%08x "
2682 "t_badrxtwin: %u\n", tp->snd_ssthresh_prev,
2683 tp->snd_recover_prev, tp->t_badrxtwin);
2685 db_print_indent(indent);
2686 db_printf("snd_numholes: %d snd_holes first: %p\n",
2687 tp->snd_numholes, TAILQ_FIRST(&tp->snd_holes));
2689 db_print_indent(indent);
2690 db_printf("snd_fack: 0x%08x rcv_numsacks: %d sack_newdata: "
2691 "0x%08x\n", tp->snd_fack, tp->rcv_numsacks, tp->sack_newdata);
2693 /* Skip sackblks, sackhint. */
2695 db_print_indent(indent);
2696 db_printf("t_rttlow: %d rfbuf_ts: %u rfbuf_cnt: %d\n",
2697 tp->t_rttlow, tp->rfbuf_ts, tp->rfbuf_cnt);
2700 DB_SHOW_COMMAND(tcpcb, db_show_tcpcb)
2705 db_printf("usage: show tcpcb <addr>\n");
2708 tp = (struct tcpcb *)addr;
2710 db_print_tcpcb(tp, "tcpcb", 0);