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_tcpdebug.h"
49 #include <sys/param.h>
50 #include <sys/systm.h>
51 #include <sys/limits.h>
52 #include <sys/malloc.h>
53 #include <sys/refcount.h>
54 #include <sys/kernel.h>
55 #include <sys/sysctl.h>
58 #include <sys/domain.h>
60 #include <sys/socket.h>
61 #include <sys/socketvar.h>
62 #include <sys/protosw.h>
65 #include <sys/syslog.h>
72 #include <net/if_var.h>
73 #include <net/route.h>
76 #include <netinet/in.h>
77 #include <netinet/in_kdtrace.h>
78 #include <netinet/in_pcb.h>
79 #include <netinet/in_systm.h>
80 #include <netinet/in_var.h>
81 #include <netinet/ip_var.h>
83 #include <netinet/ip6.h>
84 #include <netinet6/in6_pcb.h>
85 #include <netinet6/ip6_var.h>
86 #include <netinet6/scope6_var.h>
88 #include <netinet/tcp.h>
89 #include <netinet/tcp_fsm.h>
90 #include <netinet/tcp_seq.h>
91 #include <netinet/tcp_timer.h>
92 #include <netinet/tcp_var.h>
93 #include <netinet/tcp_log_buf.h>
94 #include <netinet/tcpip.h>
95 #include <netinet/cc/cc.h>
96 #include <netinet/tcp_fastopen.h>
97 #include <netinet/tcp_hpts.h>
99 #include <netinet/tcp_pcap.h>
102 #include <netinet/tcp_debug.h>
105 #include <netinet/tcp_offload.h>
107 #include <netipsec/ipsec_support.h>
110 * TCP protocol interface to socket abstraction.
112 static int tcp_attach(struct socket *);
114 static int tcp_connect(struct tcpcb *, struct sockaddr *,
118 static int tcp6_connect(struct tcpcb *, struct sockaddr *,
121 static void tcp_disconnect(struct tcpcb *);
122 static void tcp_usrclosed(struct tcpcb *);
123 static void tcp_fill_info(struct tcpcb *, struct tcp_info *);
126 #define TCPDEBUG0 int ostate = 0
127 #define TCPDEBUG1() ostate = tp ? tp->t_state : 0
128 #define TCPDEBUG2(req) if (tp && (so->so_options & SO_DEBUG)) \
129 tcp_trace(TA_USER, ostate, tp, 0, 0, req)
133 #define TCPDEBUG2(req)
137 * tcp_require_unique port requires a globally-unique source port for each
138 * outgoing connection. The default is to require the 4-tuple to be unique.
140 VNET_DEFINE(int, tcp_require_unique_port) = 0;
141 SYSCTL_INT(_net_inet_tcp, OID_AUTO, require_unique_port,
142 CTLFLAG_VNET | CTLFLAG_RW, &VNET_NAME(tcp_require_unique_port), 0,
143 "Require globally-unique ephemeral port for outgoing connections");
144 #define V_tcp_require_unique_port VNET(tcp_require_unique_port)
147 * TCP attaches to socket via pru_attach(), reserving space,
148 * and an internet control block.
151 tcp_usr_attach(struct socket *so, int proto, struct thread *td)
154 struct tcpcb *tp = NULL;
159 KASSERT(inp == NULL, ("tcp_usr_attach: inp != NULL"));
162 error = tcp_attach(so);
166 if ((so->so_options & SO_LINGER) && so->so_linger == 0)
167 so->so_linger = TCP_LINGERTIME;
172 TCPDEBUG2(PRU_ATTACH);
173 TCP_PROBE2(debug__user, tp, PRU_ATTACH);
178 * tcp_detach is called when the socket layer loses its final reference
179 * to the socket, be it a file descriptor reference, a reference from TCP,
180 * etc. At this point, there is only one case in which we will keep around
181 * inpcb state: time wait.
183 * This function can probably be re-absorbed back into tcp_usr_detach() now
184 * that there is a single detach path.
187 tcp_detach(struct socket *so, struct inpcb *inp)
191 INP_INFO_LOCK_ASSERT(&V_tcbinfo);
192 INP_WLOCK_ASSERT(inp);
194 KASSERT(so->so_pcb == inp, ("tcp_detach: so_pcb != inp"));
195 KASSERT(inp->inp_socket == so, ("tcp_detach: inp_socket != so"));
199 if (inp->inp_flags & INP_TIMEWAIT) {
201 * There are two cases to handle: one in which the time wait
202 * state is being discarded (INP_DROPPED), and one in which
203 * this connection will remain in timewait. In the former,
204 * it is time to discard all state (except tcptw, which has
205 * already been discarded by the timewait close code, which
206 * should be further up the call stack somewhere). In the
207 * latter case, we detach from the socket, but leave the pcb
208 * present until timewait ends.
210 * XXXRW: Would it be cleaner to free the tcptw here?
212 * Astute question indeed, from twtcp perspective there are
213 * four cases to consider:
215 * #1 tcp_detach is called at tcptw creation time by
216 * tcp_twstart, then do not discard the newly created tcptw
217 * and leave inpcb present until timewait ends
218 * #2 tcp_detach is called at tcptw creation time by
219 * tcp_twstart, but connection is local and tw will be
220 * discarded immediately
221 * #3 tcp_detach is called at timewait end (or reuse) by
222 * tcp_twclose, then the tcptw has already been discarded
223 * (or reused) and inpcb is freed here
224 * #4 tcp_detach is called() after timewait ends (or reuse)
225 * (e.g. by soclose), then tcptw has already been discarded
226 * (or reused) and inpcb is freed here
228 * In all three cases the tcptw should not be freed here.
230 if (inp->inp_flags & INP_DROPPED) {
232 if (__predict_true(tp == NULL)) {
236 * This case should not happen as in TIMEWAIT
237 * state the inp should not be destroyed before
238 * its tcptw. If INVARIANTS is defined, panic.
241 panic("%s: Panic before an inp double-free: "
242 "INP_TIMEWAIT && INP_DROPPED && tp != NULL"
245 log(LOG_ERR, "%s: Avoid an inp double-free: "
246 "INP_TIMEWAIT && INP_DROPPED && tp != NULL"
257 * If the connection is not in timewait, we consider two
258 * two conditions: one in which no further processing is
259 * necessary (dropped || embryonic), and one in which TCP is
260 * not yet done, but no longer requires the socket, so the
261 * pcb will persist for the time being.
263 * XXXRW: Does the second case still occur?
265 if (inp->inp_flags & INP_DROPPED ||
266 tp->t_state < TCPS_SYN_SENT) {
278 * pru_detach() detaches the TCP protocol from the socket.
279 * If the protocol state is non-embryonic, then can't
280 * do this directly: have to initiate a pru_disconnect(),
281 * which may finish later; embryonic TCB's can just
285 tcp_usr_detach(struct socket *so)
289 struct epoch_tracker et;
292 KASSERT(inp != NULL, ("tcp_usr_detach: inp == NULL"));
293 if (!INP_INFO_WLOCKED(&V_tcbinfo)) {
294 INP_INFO_RLOCK_ET(&V_tcbinfo, et);
298 KASSERT(inp->inp_socket != NULL,
299 ("tcp_usr_detach: inp_socket == NULL"));
302 INP_INFO_RUNLOCK_ET(&V_tcbinfo, et);
307 * Give the socket an address.
310 tcp_usr_bind(struct socket *so, struct sockaddr *nam, struct thread *td)
314 struct tcpcb *tp = NULL;
315 struct sockaddr_in *sinp;
317 sinp = (struct sockaddr_in *)nam;
318 if (nam->sa_len != sizeof (*sinp))
321 * Must check for multicast addresses and disallow binding
324 if (sinp->sin_family == AF_INET &&
325 IN_MULTICAST(ntohl(sinp->sin_addr.s_addr)))
326 return (EAFNOSUPPORT);
330 KASSERT(inp != NULL, ("tcp_usr_bind: inp == NULL"));
332 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
338 INP_HASH_WLOCK(&V_tcbinfo);
339 error = in_pcbbind(inp, nam, td->td_ucred);
340 INP_HASH_WUNLOCK(&V_tcbinfo);
343 TCP_PROBE2(debug__user, tp, PRU_BIND);
352 tcp6_usr_bind(struct socket *so, struct sockaddr *nam, struct thread *td)
356 struct tcpcb *tp = NULL;
357 struct sockaddr_in6 *sin6;
360 sin6 = (struct sockaddr_in6 *)nam;
361 if (nam->sa_len != sizeof (*sin6))
364 * Must check for multicast addresses and disallow binding
367 if (sin6->sin6_family == AF_INET6 &&
368 IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr))
369 return (EAFNOSUPPORT);
373 KASSERT(inp != NULL, ("tcp6_usr_bind: inp == NULL"));
375 vflagsav = inp->inp_vflag;
376 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
382 INP_HASH_WLOCK(&V_tcbinfo);
383 inp->inp_vflag &= ~INP_IPV4;
384 inp->inp_vflag |= INP_IPV6;
386 if ((inp->inp_flags & IN6P_IPV6_V6ONLY) == 0) {
387 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr))
388 inp->inp_vflag |= INP_IPV4;
389 else if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
390 struct sockaddr_in sin;
392 in6_sin6_2_sin(&sin, sin6);
393 if (IN_MULTICAST(ntohl(sin.sin_addr.s_addr))) {
394 error = EAFNOSUPPORT;
395 INP_HASH_WUNLOCK(&V_tcbinfo);
398 inp->inp_vflag |= INP_IPV4;
399 inp->inp_vflag &= ~INP_IPV6;
400 error = in_pcbbind(inp, (struct sockaddr *)&sin,
402 INP_HASH_WUNLOCK(&V_tcbinfo);
407 error = in6_pcbbind(inp, nam, td->td_ucred);
408 INP_HASH_WUNLOCK(&V_tcbinfo);
411 inp->inp_vflag = vflagsav;
413 TCP_PROBE2(debug__user, tp, PRU_BIND);
421 * Prepare to accept connections.
424 tcp_usr_listen(struct socket *so, int backlog, struct thread *td)
428 struct tcpcb *tp = NULL;
432 KASSERT(inp != NULL, ("tcp_usr_listen: inp == NULL"));
434 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
441 error = solisten_proto_check(so);
442 INP_HASH_WLOCK(&V_tcbinfo);
443 if (error == 0 && inp->inp_lport == 0)
444 error = in_pcbbind(inp, (struct sockaddr *)0, td->td_ucred);
445 INP_HASH_WUNLOCK(&V_tcbinfo);
447 tcp_state_change(tp, TCPS_LISTEN);
448 solisten_proto(so, backlog);
450 if ((so->so_options & SO_NO_OFFLOAD) == 0)
451 tcp_offload_listen_start(tp);
456 if (IS_FASTOPEN(tp->t_flags))
457 tp->t_tfo_pending = tcp_fastopen_alloc_counter();
460 TCPDEBUG2(PRU_LISTEN);
461 TCP_PROBE2(debug__user, tp, PRU_LISTEN);
469 tcp6_usr_listen(struct socket *so, int backlog, struct thread *td)
473 struct tcpcb *tp = NULL;
478 KASSERT(inp != NULL, ("tcp6_usr_listen: inp == NULL"));
480 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
484 vflagsav = inp->inp_vflag;
488 error = solisten_proto_check(so);
489 INP_HASH_WLOCK(&V_tcbinfo);
490 if (error == 0 && inp->inp_lport == 0) {
491 inp->inp_vflag &= ~INP_IPV4;
492 if ((inp->inp_flags & IN6P_IPV6_V6ONLY) == 0)
493 inp->inp_vflag |= INP_IPV4;
494 error = in6_pcbbind(inp, (struct sockaddr *)0, td->td_ucred);
496 INP_HASH_WUNLOCK(&V_tcbinfo);
498 tcp_state_change(tp, TCPS_LISTEN);
499 solisten_proto(so, backlog);
501 if ((so->so_options & SO_NO_OFFLOAD) == 0)
502 tcp_offload_listen_start(tp);
507 if (IS_FASTOPEN(tp->t_flags))
508 tp->t_tfo_pending = tcp_fastopen_alloc_counter();
511 inp->inp_vflag = vflagsav;
514 TCPDEBUG2(PRU_LISTEN);
515 TCP_PROBE2(debug__user, tp, PRU_LISTEN);
523 * Initiate connection to peer.
524 * Create a template for use in transmissions on this connection.
525 * Enter SYN_SENT state, and mark socket as connecting.
526 * Start keep-alive timer, and seed output sequence space.
527 * Send initial segment on connection.
530 tcp_usr_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
534 struct tcpcb *tp = NULL;
535 struct sockaddr_in *sinp;
537 sinp = (struct sockaddr_in *)nam;
538 if (nam->sa_len != sizeof (*sinp))
541 * Must disallow TCP ``connections'' to multicast addresses.
543 if (sinp->sin_family == AF_INET
544 && IN_MULTICAST(ntohl(sinp->sin_addr.s_addr)))
545 return (EAFNOSUPPORT);
546 if ((error = prison_remote_ip4(td->td_ucred, &sinp->sin_addr)) != 0)
551 KASSERT(inp != NULL, ("tcp_usr_connect: inp == NULL"));
553 if (inp->inp_flags & INP_TIMEWAIT) {
557 if (inp->inp_flags & INP_DROPPED) {
558 error = ECONNREFUSED;
563 if ((error = tcp_connect(tp, nam, td)) != 0)
566 if (registered_toedevs > 0 &&
567 (so->so_options & SO_NO_OFFLOAD) == 0 &&
568 (error = tcp_offload_connect(so, nam)) == 0)
571 tcp_timer_activate(tp, TT_KEEP, TP_KEEPINIT(tp));
572 error = tp->t_fb->tfb_tcp_output(tp);
574 TCPDEBUG2(PRU_CONNECT);
575 TCP_PROBE2(debug__user, tp, PRU_CONNECT);
583 tcp6_usr_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
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)
655 error = tp->t_fb->tfb_tcp_output(tp);
658 if ((inp->inp_vflag & INP_IPV6) == 0) {
659 error = EAFNOSUPPORT;
664 if ((error = prison_remote_ip6(td->td_ucred, &sin6->sin6_addr)) != 0)
666 inp->inp_vflag &= ~INP_IPV4;
667 inp->inp_vflag |= INP_IPV6;
668 inp->inp_inc.inc_flags |= INC_ISIPV6;
669 if ((error = tcp6_connect(tp, nam, td)) != 0)
672 if (registered_toedevs > 0 &&
673 (so->so_options & SO_NO_OFFLOAD) == 0 &&
674 (error = tcp_offload_connect(so, nam)) == 0)
677 tcp_timer_activate(tp, TT_KEEP, TP_KEEPINIT(tp));
678 error = tp->t_fb->tfb_tcp_output(tp);
682 * If the implicit bind in the connect call fails, restore
683 * the flags we modified.
685 if (error != 0 && inp->inp_lport == 0) {
686 inp->inp_vflag = vflagsav;
687 inp->inp_inc.inc_flags = incflagsav;
690 TCPDEBUG2(PRU_CONNECT);
691 TCP_PROBE2(debug__user, tp, PRU_CONNECT);
698 * Initiate disconnect from peer.
699 * If connection never passed embryonic stage, just drop;
700 * else if don't need to let data drain, then can just drop anyways,
701 * else have to begin TCP shutdown process: mark socket disconnecting,
702 * drain unread data, state switch to reflect user close, and
703 * send segment (e.g. FIN) to peer. Socket will be really disconnected
704 * when peer sends FIN and acks ours.
706 * SHOULD IMPLEMENT LATER PRU_CONNECT VIA REALLOC TCPCB.
709 tcp_usr_disconnect(struct socket *so)
712 struct tcpcb *tp = NULL;
713 struct epoch_tracker et;
717 INP_INFO_RLOCK_ET(&V_tcbinfo, et);
719 KASSERT(inp != NULL, ("tcp_usr_disconnect: inp == NULL"));
721 if (inp->inp_flags & INP_TIMEWAIT)
723 if (inp->inp_flags & INP_DROPPED) {
731 TCPDEBUG2(PRU_DISCONNECT);
732 TCP_PROBE2(debug__user, tp, PRU_DISCONNECT);
734 INP_INFO_RUNLOCK_ET(&V_tcbinfo, et);
740 * Accept a connection. Essentially all the work is done at higher levels;
741 * just return the address of the peer, storing through addr.
744 tcp_usr_accept(struct socket *so, struct sockaddr **nam)
747 struct inpcb *inp = NULL;
748 struct tcpcb *tp = NULL;
753 if (so->so_state & SS_ISDISCONNECTED)
754 return (ECONNABORTED);
757 KASSERT(inp != NULL, ("tcp_usr_accept: inp == NULL"));
759 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
760 error = ECONNABORTED;
767 * We inline in_getpeeraddr and COMMON_END here, so that we can
768 * copy the data of interest and defer the malloc until after we
771 port = inp->inp_fport;
772 addr = inp->inp_faddr;
775 TCPDEBUG2(PRU_ACCEPT);
776 TCP_PROBE2(debug__user, tp, PRU_ACCEPT);
779 *nam = in_sockaddr(port, &addr);
786 tcp6_usr_accept(struct socket *so, struct sockaddr **nam)
788 struct inpcb *inp = NULL;
790 struct tcpcb *tp = NULL;
792 struct in6_addr addr6;
793 struct epoch_tracker et;
798 if (so->so_state & SS_ISDISCONNECTED)
799 return (ECONNABORTED);
802 KASSERT(inp != NULL, ("tcp6_usr_accept: inp == NULL"));
803 INP_INFO_RLOCK_ET(&V_tcbinfo, et);
805 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
806 error = ECONNABORTED;
813 * We inline in6_mapped_peeraddr and COMMON_END here, so that we can
814 * copy the data of interest and defer the malloc until after we
817 if (inp->inp_vflag & INP_IPV4) {
819 port = inp->inp_fport;
820 addr = inp->inp_faddr;
822 port = inp->inp_fport;
823 addr6 = inp->in6p_faddr;
827 TCPDEBUG2(PRU_ACCEPT);
828 TCP_PROBE2(debug__user, tp, PRU_ACCEPT);
830 INP_INFO_RUNLOCK_ET(&V_tcbinfo, et);
833 *nam = in6_v4mapsin6_sockaddr(port, &addr);
835 *nam = in6_sockaddr(port, &addr6);
842 * Mark the connection as being incapable of further output.
845 tcp_usr_shutdown(struct socket *so)
849 struct tcpcb *tp = NULL;
850 struct epoch_tracker et;
853 INP_INFO_RLOCK_ET(&V_tcbinfo, et);
855 KASSERT(inp != NULL, ("inp == NULL"));
857 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
865 if (!(inp->inp_flags & INP_DROPPED))
866 error = tp->t_fb->tfb_tcp_output(tp);
869 TCPDEBUG2(PRU_SHUTDOWN);
870 TCP_PROBE2(debug__user, tp, PRU_SHUTDOWN);
872 INP_INFO_RUNLOCK_ET(&V_tcbinfo, et);
878 * After a receive, possibly send window update to peer.
881 tcp_usr_rcvd(struct socket *so, int flags)
884 struct tcpcb *tp = NULL;
889 KASSERT(inp != NULL, ("tcp_usr_rcvd: inp == NULL"));
891 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
898 * For passively-created TFO connections, don't attempt a window
899 * update while still in SYN_RECEIVED as this may trigger an early
900 * SYN|ACK. It is preferable to have the SYN|ACK be sent along with
901 * application response data, or failing that, when the DELACK timer
904 if (IS_FASTOPEN(tp->t_flags) &&
905 (tp->t_state == TCPS_SYN_RECEIVED))
908 if (tp->t_flags & TF_TOE)
909 tcp_offload_rcvd(tp);
912 tp->t_fb->tfb_tcp_output(tp);
916 TCP_PROBE2(debug__user, tp, PRU_RCVD);
922 * Do a send by putting data in output queue and updating urgent
923 * marker if URG set. Possibly send more data. Unlike the other
924 * pru_*() routines, the mbuf chains are our responsibility. We
925 * must either enqueue them or free them. The other pru_* routines
926 * generally are caller-frees.
929 tcp_usr_send(struct socket *so, int flags, struct mbuf *m,
930 struct sockaddr *nam, struct mbuf *control, struct thread *td)
934 struct tcpcb *tp = NULL;
935 struct epoch_tracker net_et;
938 struct sockaddr_in sin;
940 struct sockaddr_in *sinp;
951 * We require the pcbinfo lock if we will close the socket as part of
954 if (flags & PRUS_EOF)
955 INP_INFO_RLOCK_ET(&V_tcbinfo, net_et);
957 KASSERT(inp != NULL, ("tcp_usr_send: inp == NULL"));
959 vflagsav = inp->inp_vflag;
960 incflagsav = inp->inp_inc.inc_flags;
961 restoreflags = false;
962 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
966 * In case of PRUS_NOTREADY, tcp_usr_ready() is responsible
967 * for freeing memory.
969 if (m && (flags & PRUS_NOTREADY) == 0)
976 if (nam != NULL && tp->t_state < TCPS_SYN_SENT) {
977 switch (nam->sa_family) {
980 sinp = (struct sockaddr_in *)nam;
981 if (sinp->sin_len != sizeof(struct sockaddr_in)) {
987 if ((inp->inp_vflag & INP_IPV6) != 0) {
990 error = EAFNOSUPPORT;
993 if (IN_MULTICAST(ntohl(sinp->sin_addr.s_addr))) {
996 error = EAFNOSUPPORT;
999 if ((error = prison_remote_ip4(td->td_ucred,
1000 &sinp->sin_addr))) {
1013 struct sockaddr_in6 *sin6;
1015 sin6 = (struct sockaddr_in6 *)nam;
1016 if (sin6->sin6_len != sizeof(*sin6)) {
1022 if (IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr)) {
1025 error = EAFNOSUPPORT;
1028 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
1030 if ((inp->inp_flags & IN6P_IPV6_V6ONLY) != 0) {
1036 if ((inp->inp_vflag & INP_IPV4) == 0) {
1037 error = EAFNOSUPPORT;
1042 restoreflags = true;
1043 inp->inp_vflag &= ~INP_IPV6;
1045 in6_sin6_2_sin(sinp, sin6);
1047 ntohl(sinp->sin_addr.s_addr))) {
1048 error = EAFNOSUPPORT;
1053 if ((error = prison_remote_ip4(td->td_ucred,
1054 &sinp->sin_addr))) {
1061 error = EAFNOSUPPORT;
1067 if ((inp->inp_vflag & INP_IPV6) == 0) {
1070 error = EAFNOSUPPORT;
1073 restoreflags = true;
1074 inp->inp_vflag &= ~INP_IPV4;
1075 inp->inp_inc.inc_flags |= INC_ISIPV6;
1076 if ((error = prison_remote_ip6(td->td_ucred,
1077 &sin6->sin6_addr))) {
1090 error = EAFNOSUPPORT;
1095 /* TCP doesn't do control messages (rights, creds, etc) */
1096 if (control->m_len) {
1103 m_freem(control); /* empty control, just free it */
1105 if (!(flags & PRUS_OOB)) {
1106 sbappendstream(&so->so_snd, m, flags);
1107 if (nam && tp->t_state < TCPS_SYN_SENT) {
1109 * Do implied connect if not yet connected,
1110 * initialize window to default value, and
1111 * initialize maxseg using peer's cached MSS.
1115 error = tcp6_connect(tp, nam, td);
1117 #if defined(INET6) && defined(INET)
1121 error = tcp_connect(tp,
1122 (struct sockaddr *)sinp, td);
1125 * The bind operation in tcp_connect succeeded. We
1126 * no longer want to restore the flags if later
1129 if (error == 0 || inp->inp_lport != 0)
1130 restoreflags = false;
1134 if (IS_FASTOPEN(tp->t_flags))
1135 tcp_fastopen_connect(tp);
1137 tp->snd_wnd = TTCP_CLIENT_SND_WND;
1141 if (flags & PRUS_EOF) {
1143 * Close the send side of the connection after
1146 INP_INFO_RLOCK_ASSERT(&V_tcbinfo);
1150 if (!(inp->inp_flags & INP_DROPPED) &&
1151 !(flags & PRUS_NOTREADY)) {
1152 if (flags & PRUS_MORETOCOME)
1153 tp->t_flags |= TF_MORETOCOME;
1154 error = tp->t_fb->tfb_tcp_output(tp);
1155 if (flags & PRUS_MORETOCOME)
1156 tp->t_flags &= ~TF_MORETOCOME;
1160 * XXXRW: PRUS_EOF not implemented with PRUS_OOB?
1162 SOCKBUF_LOCK(&so->so_snd);
1163 if (sbspace(&so->so_snd) < -512) {
1164 SOCKBUF_UNLOCK(&so->so_snd);
1170 * According to RFC961 (Assigned Protocols),
1171 * the urgent pointer points to the last octet
1172 * of urgent data. We continue, however,
1173 * to consider it to indicate the first octet
1174 * of data past the urgent section.
1175 * Otherwise, snd_up should be one lower.
1177 sbappendstream_locked(&so->so_snd, m, flags);
1178 SOCKBUF_UNLOCK(&so->so_snd);
1179 if (nam && tp->t_state < TCPS_SYN_SENT) {
1181 * Do implied connect if not yet connected,
1182 * initialize window to default value, and
1183 * initialize maxseg using peer's cached MSS.
1187 * Not going to contemplate SYN|URG
1189 if (IS_FASTOPEN(tp->t_flags))
1190 tp->t_flags &= ~TF_FASTOPEN;
1193 error = tcp6_connect(tp, nam, td);
1195 #if defined(INET6) && defined(INET)
1199 error = tcp_connect(tp,
1200 (struct sockaddr *)sinp, td);
1203 * The bind operation in tcp_connect succeeded. We
1204 * no longer want to restore the flags if later
1207 if (error == 0 || inp->inp_lport != 0)
1208 restoreflags = false;
1212 tp->snd_wnd = TTCP_CLIENT_SND_WND;
1215 tp->snd_up = tp->snd_una + sbavail(&so->so_snd);
1216 if (!(flags & PRUS_NOTREADY)) {
1217 tp->t_flags |= TF_FORCEDATA;
1218 error = tp->t_fb->tfb_tcp_output(tp);
1219 tp->t_flags &= ~TF_FORCEDATA;
1222 TCP_LOG_EVENT(tp, NULL,
1223 &inp->inp_socket->so_rcv,
1224 &inp->inp_socket->so_snd,
1225 TCP_LOG_USERSEND, error,
1229 * If the request was unsuccessful and we changed flags,
1230 * restore the original flags.
1232 if (error != 0 && restoreflags) {
1233 inp->inp_vflag = vflagsav;
1234 inp->inp_inc.inc_flags = incflagsav;
1236 TCPDEBUG2((flags & PRUS_OOB) ? PRU_SENDOOB :
1237 ((flags & PRUS_EOF) ? PRU_SEND_EOF : PRU_SEND));
1238 TCP_PROBE2(debug__user, tp, (flags & PRUS_OOB) ? PRU_SENDOOB :
1239 ((flags & PRUS_EOF) ? PRU_SEND_EOF : PRU_SEND));
1241 if (flags & PRUS_EOF)
1242 INP_INFO_RUNLOCK_ET(&V_tcbinfo, net_et);
1247 tcp_usr_ready(struct socket *so, struct mbuf *m, int count)
1253 inp = sotoinpcb(so);
1255 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
1257 for (int i = 0; i < count; i++)
1259 return (ECONNRESET);
1261 tp = intotcpcb(inp);
1263 SOCKBUF_LOCK(&so->so_snd);
1264 error = sbready(&so->so_snd, m, count);
1265 SOCKBUF_UNLOCK(&so->so_snd);
1267 error = tp->t_fb->tfb_tcp_output(tp);
1274 * Abort the TCP. Drop the connection abruptly.
1277 tcp_usr_abort(struct socket *so)
1280 struct tcpcb *tp = NULL;
1281 struct epoch_tracker et;
1284 inp = sotoinpcb(so);
1285 KASSERT(inp != NULL, ("tcp_usr_abort: inp == NULL"));
1287 INP_INFO_RLOCK_ET(&V_tcbinfo, et);
1289 KASSERT(inp->inp_socket != NULL,
1290 ("tcp_usr_abort: inp_socket == NULL"));
1293 * If we still have full TCP state, and we're not dropped, drop.
1295 if (!(inp->inp_flags & INP_TIMEWAIT) &&
1296 !(inp->inp_flags & INP_DROPPED)) {
1297 tp = intotcpcb(inp);
1299 tp = tcp_drop(tp, ECONNABORTED);
1302 TCPDEBUG2(PRU_ABORT);
1303 TCP_PROBE2(debug__user, tp, PRU_ABORT);
1305 if (!(inp->inp_flags & INP_DROPPED)) {
1307 so->so_state |= SS_PROTOREF;
1309 inp->inp_flags |= INP_SOCKREF;
1313 INP_INFO_RUNLOCK_ET(&V_tcbinfo, et);
1317 * TCP socket is closed. Start friendly disconnect.
1320 tcp_usr_close(struct socket *so)
1323 struct tcpcb *tp = NULL;
1324 struct epoch_tracker et;
1327 inp = sotoinpcb(so);
1328 KASSERT(inp != NULL, ("tcp_usr_close: inp == NULL"));
1330 INP_INFO_RLOCK_ET(&V_tcbinfo, et);
1332 KASSERT(inp->inp_socket != NULL,
1333 ("tcp_usr_close: inp_socket == NULL"));
1336 * If we still have full TCP state, and we're not dropped, initiate
1339 if (!(inp->inp_flags & INP_TIMEWAIT) &&
1340 !(inp->inp_flags & INP_DROPPED)) {
1341 tp = intotcpcb(inp);
1344 TCPDEBUG2(PRU_CLOSE);
1345 TCP_PROBE2(debug__user, tp, PRU_CLOSE);
1347 if (!(inp->inp_flags & INP_DROPPED)) {
1349 so->so_state |= SS_PROTOREF;
1351 inp->inp_flags |= INP_SOCKREF;
1354 INP_INFO_RUNLOCK_ET(&V_tcbinfo, et);
1358 * Receive out-of-band data.
1361 tcp_usr_rcvoob(struct socket *so, struct mbuf *m, int flags)
1365 struct tcpcb *tp = NULL;
1368 inp = sotoinpcb(so);
1369 KASSERT(inp != NULL, ("tcp_usr_rcvoob: inp == NULL"));
1371 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
1375 tp = intotcpcb(inp);
1377 if ((so->so_oobmark == 0 &&
1378 (so->so_rcv.sb_state & SBS_RCVATMARK) == 0) ||
1379 so->so_options & SO_OOBINLINE ||
1380 tp->t_oobflags & TCPOOB_HADDATA) {
1384 if ((tp->t_oobflags & TCPOOB_HAVEDATA) == 0) {
1385 error = EWOULDBLOCK;
1389 *mtod(m, caddr_t) = tp->t_iobc;
1390 if ((flags & MSG_PEEK) == 0)
1391 tp->t_oobflags ^= (TCPOOB_HAVEDATA | TCPOOB_HADDATA);
1394 TCPDEBUG2(PRU_RCVOOB);
1395 TCP_PROBE2(debug__user, tp, PRU_RCVOOB);
1401 struct pr_usrreqs tcp_usrreqs = {
1402 .pru_abort = tcp_usr_abort,
1403 .pru_accept = tcp_usr_accept,
1404 .pru_attach = tcp_usr_attach,
1405 .pru_bind = tcp_usr_bind,
1406 .pru_connect = tcp_usr_connect,
1407 .pru_control = in_control,
1408 .pru_detach = tcp_usr_detach,
1409 .pru_disconnect = tcp_usr_disconnect,
1410 .pru_listen = tcp_usr_listen,
1411 .pru_peeraddr = in_getpeeraddr,
1412 .pru_rcvd = tcp_usr_rcvd,
1413 .pru_rcvoob = tcp_usr_rcvoob,
1414 .pru_send = tcp_usr_send,
1415 .pru_ready = tcp_usr_ready,
1416 .pru_shutdown = tcp_usr_shutdown,
1417 .pru_sockaddr = in_getsockaddr,
1418 .pru_sosetlabel = in_pcbsosetlabel,
1419 .pru_close = tcp_usr_close,
1424 struct pr_usrreqs tcp6_usrreqs = {
1425 .pru_abort = tcp_usr_abort,
1426 .pru_accept = tcp6_usr_accept,
1427 .pru_attach = tcp_usr_attach,
1428 .pru_bind = tcp6_usr_bind,
1429 .pru_connect = tcp6_usr_connect,
1430 .pru_control = in6_control,
1431 .pru_detach = tcp_usr_detach,
1432 .pru_disconnect = tcp_usr_disconnect,
1433 .pru_listen = tcp6_usr_listen,
1434 .pru_peeraddr = in6_mapped_peeraddr,
1435 .pru_rcvd = tcp_usr_rcvd,
1436 .pru_rcvoob = tcp_usr_rcvoob,
1437 .pru_send = tcp_usr_send,
1438 .pru_ready = tcp_usr_ready,
1439 .pru_shutdown = tcp_usr_shutdown,
1440 .pru_sockaddr = in6_mapped_sockaddr,
1441 .pru_sosetlabel = in_pcbsosetlabel,
1442 .pru_close = tcp_usr_close,
1448 * Common subroutine to open a TCP connection to remote host specified
1449 * by struct sockaddr_in in mbuf *nam. Call in_pcbbind to assign a local
1450 * port number if needed. Call in_pcbconnect_setup to do the routing and
1451 * to choose a local host address (interface). If there is an existing
1452 * incarnation of the same connection in TIME-WAIT state and if the remote
1453 * host was sending CC options and if the connection duration was < MSL, then
1454 * truncate the previous TIME-WAIT state and proceed.
1455 * Initialize connection parameters and enter SYN-SENT state.
1458 tcp_connect(struct tcpcb *tp, struct sockaddr *nam, struct thread *td)
1460 struct inpcb *inp = tp->t_inpcb, *oinp;
1461 struct socket *so = inp->inp_socket;
1462 struct in_addr laddr;
1466 INP_WLOCK_ASSERT(inp);
1467 INP_HASH_WLOCK(&V_tcbinfo);
1469 if (V_tcp_require_unique_port && inp->inp_lport == 0) {
1470 error = in_pcbbind(inp, (struct sockaddr *)0, td->td_ucred);
1476 * Cannot simply call in_pcbconnect, because there might be an
1477 * earlier incarnation of this same connection still in
1478 * TIME_WAIT state, creating an ADDRINUSE error.
1480 laddr = inp->inp_laddr;
1481 lport = inp->inp_lport;
1482 error = in_pcbconnect_setup(inp, nam, &laddr.s_addr, &lport,
1483 &inp->inp_faddr.s_addr, &inp->inp_fport, &oinp, td->td_ucred);
1484 if (error && oinp == NULL)
1490 /* Handle initial bind if it hadn't been done in advance. */
1491 if (inp->inp_lport == 0) {
1492 inp->inp_lport = lport;
1493 if (in_pcbinshash(inp) != 0) {
1499 inp->inp_laddr = laddr;
1501 INP_HASH_WUNLOCK(&V_tcbinfo);
1504 * Compute window scaling to request:
1505 * Scale to fit into sweet spot. See tcp_syncache.c.
1506 * XXX: This should move to tcp_output().
1508 while (tp->request_r_scale < TCP_MAX_WINSHIFT &&
1509 (TCP_MAXWIN << tp->request_r_scale) < sb_max)
1510 tp->request_r_scale++;
1513 TCPSTAT_INC(tcps_connattempt);
1514 tcp_state_change(tp, TCPS_SYN_SENT);
1515 tp->iss = tcp_new_isn(&inp->inp_inc);
1516 if (tp->t_flags & TF_REQ_TSTMP)
1517 tp->ts_offset = tcp_new_ts_offset(&inp->inp_inc);
1518 tcp_sendseqinit(tp);
1523 INP_HASH_WUNLOCK(&V_tcbinfo);
1530 tcp6_connect(struct tcpcb *tp, struct sockaddr *nam, struct thread *td)
1532 struct inpcb *inp = tp->t_inpcb;
1535 INP_WLOCK_ASSERT(inp);
1536 INP_HASH_WLOCK(&V_tcbinfo);
1538 if (V_tcp_require_unique_port && inp->inp_lport == 0) {
1539 error = in6_pcbbind(inp, (struct sockaddr *)0, td->td_ucred);
1543 error = in6_pcbconnect(inp, nam, td->td_ucred);
1546 INP_HASH_WUNLOCK(&V_tcbinfo);
1548 /* Compute window scaling to request. */
1549 while (tp->request_r_scale < TCP_MAX_WINSHIFT &&
1550 (TCP_MAXWIN << tp->request_r_scale) < sb_max)
1551 tp->request_r_scale++;
1553 soisconnecting(inp->inp_socket);
1554 TCPSTAT_INC(tcps_connattempt);
1555 tcp_state_change(tp, TCPS_SYN_SENT);
1556 tp->iss = tcp_new_isn(&inp->inp_inc);
1557 if (tp->t_flags & TF_REQ_TSTMP)
1558 tp->ts_offset = tcp_new_ts_offset(&inp->inp_inc);
1559 tcp_sendseqinit(tp);
1564 INP_HASH_WUNLOCK(&V_tcbinfo);
1570 * Export TCP internal state information via a struct tcp_info, based on the
1571 * Linux 2.6 API. Not ABI compatible as our constants are mapped differently
1572 * (TCP state machine, etc). We export all information using FreeBSD-native
1573 * constants -- for example, the numeric values for tcpi_state will differ
1577 tcp_fill_info(struct tcpcb *tp, struct tcp_info *ti)
1580 INP_WLOCK_ASSERT(tp->t_inpcb);
1581 bzero(ti, sizeof(*ti));
1583 ti->tcpi_state = tp->t_state;
1584 if ((tp->t_flags & TF_REQ_TSTMP) && (tp->t_flags & TF_RCVD_TSTMP))
1585 ti->tcpi_options |= TCPI_OPT_TIMESTAMPS;
1586 if (tp->t_flags & TF_SACK_PERMIT)
1587 ti->tcpi_options |= TCPI_OPT_SACK;
1588 if ((tp->t_flags & TF_REQ_SCALE) && (tp->t_flags & TF_RCVD_SCALE)) {
1589 ti->tcpi_options |= TCPI_OPT_WSCALE;
1590 ti->tcpi_snd_wscale = tp->snd_scale;
1591 ti->tcpi_rcv_wscale = tp->rcv_scale;
1593 if (tp->t_flags & TF_ECN_PERMIT)
1594 ti->tcpi_options |= TCPI_OPT_ECN;
1596 ti->tcpi_rto = tp->t_rxtcur * tick;
1597 ti->tcpi_last_data_recv = ((uint32_t)ticks - tp->t_rcvtime) * tick;
1598 ti->tcpi_rtt = ((u_int64_t)tp->t_srtt * tick) >> TCP_RTT_SHIFT;
1599 ti->tcpi_rttvar = ((u_int64_t)tp->t_rttvar * tick) >> TCP_RTTVAR_SHIFT;
1601 ti->tcpi_snd_ssthresh = tp->snd_ssthresh;
1602 ti->tcpi_snd_cwnd = tp->snd_cwnd;
1605 * FreeBSD-specific extension fields for tcp_info.
1607 ti->tcpi_rcv_space = tp->rcv_wnd;
1608 ti->tcpi_rcv_nxt = tp->rcv_nxt;
1609 ti->tcpi_snd_wnd = tp->snd_wnd;
1610 ti->tcpi_snd_bwnd = 0; /* Unused, kept for compat. */
1611 ti->tcpi_snd_nxt = tp->snd_nxt;
1612 ti->tcpi_snd_mss = tp->t_maxseg;
1613 ti->tcpi_rcv_mss = tp->t_maxseg;
1614 ti->tcpi_snd_rexmitpack = tp->t_sndrexmitpack;
1615 ti->tcpi_rcv_ooopack = tp->t_rcvoopack;
1616 ti->tcpi_snd_zerowin = tp->t_sndzerowin;
1618 if (tp->t_flags & TF_TOE) {
1619 ti->tcpi_options |= TCPI_OPT_TOE;
1620 tcp_offload_tcp_info(tp, ti);
1626 * tcp_ctloutput() must drop the inpcb lock before performing copyin on
1627 * socket option arguments. When it re-acquires the lock after the copy, it
1628 * has to revalidate that the connection is still valid for the socket
1631 #define INP_WLOCK_RECHECK_CLEANUP(inp, cleanup) do { \
1633 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) { \
1636 return (ECONNRESET); \
1638 tp = intotcpcb(inp); \
1640 #define INP_WLOCK_RECHECK(inp) INP_WLOCK_RECHECK_CLEANUP((inp), /* noop */)
1643 tcp_ctloutput(struct socket *so, struct sockopt *sopt)
1648 struct tcp_function_block *blk;
1649 struct tcp_function_set fsn;
1652 inp = sotoinpcb(so);
1653 KASSERT(inp != NULL, ("tcp_ctloutput: inp == NULL"));
1654 if (sopt->sopt_level != IPPROTO_TCP) {
1656 if (inp->inp_vflag & INP_IPV6PROTO) {
1657 error = ip6_ctloutput(so, sopt);
1659 * In case of the IPV6_USE_MIN_MTU socket option,
1660 * the INC_IPV6MINMTU flag to announce a corresponding
1661 * MSS during the initial handshake.
1662 * If the TCP connection is not in the front states,
1663 * just reduce the MSS being used.
1664 * This avoids the sending of TCP segments which will
1665 * be fragmented at the IPv6 layer.
1668 (sopt->sopt_dir == SOPT_SET) &&
1669 (sopt->sopt_level == IPPROTO_IPV6) &&
1670 (sopt->sopt_name == IPV6_USE_MIN_MTU)) {
1672 if ((inp->inp_flags &
1673 (INP_TIMEWAIT | INP_DROPPED))) {
1675 return (ECONNRESET);
1677 inp->inp_inc.inc_flags |= INC_IPV6MINMTU;
1678 tp = intotcpcb(inp);
1679 if ((tp->t_state >= TCPS_SYN_SENT) &&
1680 (inp->inp_inc.inc_flags & INC_ISIPV6)) {
1681 struct ip6_pktopts *opt;
1683 opt = inp->in6p_outputopts;
1684 if ((opt != NULL) &&
1685 (opt->ip6po_minmtu ==
1686 IP6PO_MINMTU_ALL)) {
1687 if (tp->t_maxseg > TCP6_MSS) {
1688 tp->t_maxseg = TCP6_MSS;
1696 #if defined(INET6) && defined(INET)
1701 error = ip_ctloutput(so, sopt);
1707 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
1709 return (ECONNRESET);
1711 tp = intotcpcb(inp);
1713 * Protect the TCP option TCP_FUNCTION_BLK so
1714 * that a sub-function can *never* overwrite this.
1716 if ((sopt->sopt_dir == SOPT_SET) &&
1717 (sopt->sopt_name == TCP_FUNCTION_BLK)) {
1719 error = sooptcopyin(sopt, &fsn, sizeof fsn,
1723 INP_WLOCK_RECHECK(inp);
1724 blk = find_and_ref_tcp_functions(&fsn);
1729 if (tp->t_fb == blk) {
1730 /* You already have this */
1731 refcount_release(&blk->tfb_refcnt);
1735 if (tp->t_state != TCPS_CLOSED) {
1737 * The user has advanced the state
1738 * past the initial point, we may not
1739 * be able to switch.
1741 if (blk->tfb_tcp_handoff_ok != NULL) {
1743 * Does the stack provide a
1744 * query mechanism, if so it may
1745 * still be possible?
1747 error = (*blk->tfb_tcp_handoff_ok)(tp);
1751 refcount_release(&blk->tfb_refcnt);
1756 if (blk->tfb_flags & TCP_FUNC_BEING_REMOVED) {
1757 refcount_release(&blk->tfb_refcnt);
1762 * Release the old refcnt, the
1763 * lookup acquired a ref on the
1766 if (tp->t_fb->tfb_tcp_fb_fini) {
1768 * Tell the stack to cleanup with 0 i.e.
1769 * the tcb is not going away.
1771 (*tp->t_fb->tfb_tcp_fb_fini)(tp, 0);
1774 /* Assure that we are not on any hpts */
1775 tcp_hpts_remove(tp->t_inpcb, HPTS_REMOVE_ALL);
1777 if (blk->tfb_tcp_fb_init) {
1778 error = (*blk->tfb_tcp_fb_init)(tp);
1780 refcount_release(&blk->tfb_refcnt);
1781 if (tp->t_fb->tfb_tcp_fb_init) {
1782 if((*tp->t_fb->tfb_tcp_fb_init)(tp) != 0) {
1783 /* Fall back failed, drop the connection */
1792 refcount_release(&tp->t_fb->tfb_refcnt);
1795 if (tp->t_flags & TF_TOE) {
1796 tcp_offload_ctloutput(tp, sopt->sopt_dir,
1803 } else if ((sopt->sopt_dir == SOPT_GET) &&
1804 (sopt->sopt_name == TCP_FUNCTION_BLK)) {
1805 strncpy(fsn.function_set_name, tp->t_fb->tfb_tcp_block_name,
1806 TCP_FUNCTION_NAME_LEN_MAX);
1807 fsn.function_set_name[TCP_FUNCTION_NAME_LEN_MAX - 1] = '\0';
1808 fsn.pcbcnt = tp->t_fb->tfb_refcnt;
1810 error = sooptcopyout(sopt, &fsn, sizeof fsn);
1813 /* Pass in the INP locked, called must unlock it */
1814 return (tp->t_fb->tfb_tcp_ctloutput(so, sopt, inp, tp));
1818 * If this assert becomes untrue, we need to change the size of the buf
1819 * variable in tcp_default_ctloutput().
1822 CTASSERT(TCP_CA_NAME_MAX <= TCP_LOG_ID_LEN);
1823 CTASSERT(TCP_LOG_REASON_LEN <= TCP_LOG_ID_LEN);
1827 tcp_default_ctloutput(struct socket *so, struct sockopt *sopt, struct inpcb *inp, struct tcpcb *tp)
1829 int error, opt, optval;
1832 struct cc_algo *algo;
1833 char *pbuf, buf[TCP_LOG_ID_LEN];
1837 * For TCP_CCALGOOPT forward the control to CC module, for both
1838 * SOPT_SET and SOPT_GET.
1840 switch (sopt->sopt_name) {
1843 if (sopt->sopt_valsize > CC_ALGOOPT_LIMIT)
1845 pbuf = malloc(sopt->sopt_valsize, M_TEMP, M_WAITOK | M_ZERO);
1846 error = sooptcopyin(sopt, pbuf, sopt->sopt_valsize,
1847 sopt->sopt_valsize);
1852 INP_WLOCK_RECHECK_CLEANUP(inp, free(pbuf, M_TEMP));
1853 if (CC_ALGO(tp)->ctl_output != NULL)
1854 error = CC_ALGO(tp)->ctl_output(tp->ccv, sopt, pbuf);
1858 if (error == 0 && sopt->sopt_dir == SOPT_GET)
1859 error = sooptcopyout(sopt, pbuf, sopt->sopt_valsize);
1864 switch (sopt->sopt_dir) {
1866 switch (sopt->sopt_name) {
1867 #if defined(IPSEC_SUPPORT) || defined(TCP_SIGNATURE)
1869 if (!TCPMD5_ENABLED()) {
1871 return (ENOPROTOOPT);
1873 error = TCPMD5_PCBCTL(inp, sopt);
1876 goto unlock_and_done;
1882 error = sooptcopyin(sopt, &optval, sizeof optval,
1887 INP_WLOCK_RECHECK(inp);
1888 switch (sopt->sopt_name) {
1896 opt = 0; /* dead code to fool gcc */
1903 tp->t_flags &= ~opt;
1906 if (tp->t_flags & TF_TOE) {
1907 tcp_offload_ctloutput(tp, sopt->sopt_dir,
1916 error = sooptcopyin(sopt, &optval, sizeof optval,
1921 INP_WLOCK_RECHECK(inp);
1923 tp->t_flags |= TF_NOPUSH;
1924 else if (tp->t_flags & TF_NOPUSH) {
1925 tp->t_flags &= ~TF_NOPUSH;
1926 if (TCPS_HAVEESTABLISHED(tp->t_state))
1927 error = tp->t_fb->tfb_tcp_output(tp);
1929 goto unlock_and_done;
1933 error = sooptcopyin(sopt, &optval, sizeof optval,
1938 INP_WLOCK_RECHECK(inp);
1939 if (optval > 0 && optval <= tp->t_maxseg &&
1940 optval + 40 >= V_tcp_minmss)
1941 tp->t_maxseg = optval;
1944 goto unlock_and_done;
1951 case TCP_CONGESTION:
1953 error = sooptcopyin(sopt, buf, TCP_CA_NAME_MAX - 1, 1);
1956 buf[sopt->sopt_valsize] = '\0';
1957 INP_WLOCK_RECHECK(inp);
1959 STAILQ_FOREACH(algo, &cc_list, entries)
1960 if (strncmp(buf, algo->name,
1961 TCP_CA_NAME_MAX) == 0)
1970 * We hold a write lock over the tcb so it's safe to
1971 * do these things without ordering concerns.
1973 if (CC_ALGO(tp)->cb_destroy != NULL)
1974 CC_ALGO(tp)->cb_destroy(tp->ccv);
1978 * If something goes pear shaped initialising the new
1979 * algo, fall back to newreno (which does not
1980 * require initialisation).
1982 if (algo->cb_init != NULL &&
1983 algo->cb_init(tp->ccv) != 0) {
1984 CC_ALGO(tp) = &newreno_cc_algo;
1986 * The only reason init should fail is
1987 * because of malloc.
1998 error = sooptcopyin(sopt, &ui, sizeof(ui), sizeof(ui));
2002 if (ui > (UINT_MAX / hz)) {
2008 INP_WLOCK_RECHECK(inp);
2009 switch (sopt->sopt_name) {
2011 tp->t_keepidle = ui;
2013 * XXX: better check current remaining
2014 * timeout and "merge" it with new value.
2016 if ((tp->t_state > TCPS_LISTEN) &&
2017 (tp->t_state <= TCPS_CLOSING))
2018 tcp_timer_activate(tp, TT_KEEP,
2022 tp->t_keepintvl = ui;
2023 if ((tp->t_state == TCPS_FIN_WAIT_2) &&
2024 (TP_MAXIDLE(tp) > 0))
2025 tcp_timer_activate(tp, TT_2MSL,
2029 tp->t_keepinit = ui;
2030 if (tp->t_state == TCPS_SYN_RECEIVED ||
2031 tp->t_state == TCPS_SYN_SENT)
2032 tcp_timer_activate(tp, TT_KEEP,
2036 goto unlock_and_done;
2040 error = sooptcopyin(sopt, &ui, sizeof(ui), sizeof(ui));
2044 INP_WLOCK_RECHECK(inp);
2046 if ((tp->t_state == TCPS_FIN_WAIT_2) &&
2047 (TP_MAXIDLE(tp) > 0))
2048 tcp_timer_activate(tp, TT_2MSL,
2050 goto unlock_and_done;
2056 error = sooptcopyin(sopt, &optval, sizeof optval,
2061 INP_WLOCK_RECHECK(inp);
2063 tcp_pcap_set_sock_max(TCP_PCAP_OUT ?
2064 &(tp->t_outpkts) : &(tp->t_inpkts),
2068 goto unlock_and_done;
2071 case TCP_FASTOPEN: {
2072 struct tcp_fastopen tfo_optval;
2075 if (!V_tcp_fastopen_client_enable &&
2076 !V_tcp_fastopen_server_enable)
2079 error = sooptcopyin(sopt, &tfo_optval,
2080 sizeof(tfo_optval), sizeof(int));
2084 INP_WLOCK_RECHECK(inp);
2085 if (tfo_optval.enable) {
2086 if (tp->t_state == TCPS_LISTEN) {
2087 if (!V_tcp_fastopen_server_enable) {
2089 goto unlock_and_done;
2092 tp->t_flags |= TF_FASTOPEN;
2093 if (tp->t_tfo_pending == NULL)
2095 tcp_fastopen_alloc_counter();
2098 * If a pre-shared key was provided,
2099 * stash it in the client cookie
2100 * field of the tcpcb for use during
2103 if (sopt->sopt_valsize ==
2104 sizeof(tfo_optval)) {
2105 memcpy(tp->t_tfo_cookie.client,
2107 TCP_FASTOPEN_PSK_LEN);
2108 tp->t_tfo_client_cookie_len =
2109 TCP_FASTOPEN_PSK_LEN;
2111 tp->t_flags |= TF_FASTOPEN;
2114 tp->t_flags &= ~TF_FASTOPEN;
2115 goto unlock_and_done;
2121 error = sooptcopyin(sopt, &optval, sizeof optval,
2126 INP_WLOCK_RECHECK(inp);
2127 error = tcp_log_state_change(tp, optval);
2128 goto unlock_and_done;
2137 error = sooptcopyin(sopt, buf, TCP_LOG_ID_LEN - 1, 0);
2140 buf[sopt->sopt_valsize] = '\0';
2141 INP_WLOCK_RECHECK(inp);
2142 error = tcp_log_set_id(tp, buf);
2143 /* tcp_log_set_id() unlocks the INP. */
2150 sooptcopyin(sopt, buf, TCP_LOG_REASON_LEN - 1, 0);
2153 buf[sopt->sopt_valsize] = '\0';
2154 INP_WLOCK_RECHECK(inp);
2155 if (sopt->sopt_name == TCP_LOGDUMP) {
2156 error = tcp_log_dump_tp_logbuf(tp, buf,
2160 tcp_log_dump_tp_bucket_logbufs(tp, buf);
2162 * tcp_log_dump_tp_bucket_logbufs() drops the
2171 error = ENOPROTOOPT;
2177 tp = intotcpcb(inp);
2178 switch (sopt->sopt_name) {
2179 #if defined(IPSEC_SUPPORT) || defined(TCP_SIGNATURE)
2181 if (!TCPMD5_ENABLED()) {
2183 return (ENOPROTOOPT);
2185 error = TCPMD5_PCBCTL(inp, sopt);
2190 optval = tp->t_flags & TF_NODELAY;
2192 error = sooptcopyout(sopt, &optval, sizeof optval);
2195 optval = tp->t_maxseg;
2197 error = sooptcopyout(sopt, &optval, sizeof optval);
2200 optval = tp->t_flags & TF_NOOPT;
2202 error = sooptcopyout(sopt, &optval, sizeof optval);
2205 optval = tp->t_flags & TF_NOPUSH;
2207 error = sooptcopyout(sopt, &optval, sizeof optval);
2210 tcp_fill_info(tp, &ti);
2212 error = sooptcopyout(sopt, &ti, sizeof ti);
2214 case TCP_CONGESTION:
2215 len = strlcpy(buf, CC_ALGO(tp)->name, TCP_CA_NAME_MAX);
2217 error = sooptcopyout(sopt, buf, len + 1);
2223 switch (sopt->sopt_name) {
2225 ui = TP_KEEPIDLE(tp) / hz;
2228 ui = TP_KEEPINTVL(tp) / hz;
2231 ui = TP_KEEPINIT(tp) / hz;
2234 ui = TP_KEEPCNT(tp);
2238 error = sooptcopyout(sopt, &ui, sizeof(ui));
2243 optval = tcp_pcap_get_sock_max(TCP_PCAP_OUT ?
2244 &(tp->t_outpkts) : &(tp->t_inpkts));
2246 error = sooptcopyout(sopt, &optval, sizeof optval);
2250 optval = tp->t_flags & TF_FASTOPEN;
2252 error = sooptcopyout(sopt, &optval, sizeof optval);
2256 optval = tp->t_logstate;
2258 error = sooptcopyout(sopt, &optval, sizeof(optval));
2261 /* tcp_log_getlogbuf() does INP_WUNLOCK(inp) */
2262 error = tcp_log_getlogbuf(sopt, tp);
2265 len = tcp_log_get_id(tp, buf);
2267 error = sooptcopyout(sopt, buf, len + 1);
2277 error = ENOPROTOOPT;
2284 #undef INP_WLOCK_RECHECK
2285 #undef INP_WLOCK_RECHECK_CLEANUP
2288 * Attach TCP protocol to socket, allocating
2289 * internet protocol control block, tcp control block,
2290 * bufer space, and entering LISTEN state if to accept connections.
2293 tcp_attach(struct socket *so)
2297 struct epoch_tracker et;
2300 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
2301 error = soreserve(so, V_tcp_sendspace, V_tcp_recvspace);
2305 so->so_rcv.sb_flags |= SB_AUTOSIZE;
2306 so->so_snd.sb_flags |= SB_AUTOSIZE;
2307 INP_INFO_RLOCK_ET(&V_tcbinfo, et);
2308 error = in_pcballoc(so, &V_tcbinfo);
2310 INP_INFO_RUNLOCK_ET(&V_tcbinfo, et);
2313 inp = sotoinpcb(so);
2315 if (inp->inp_vflag & INP_IPV6PROTO) {
2316 inp->inp_vflag |= INP_IPV6;
2317 if ((inp->inp_flags & IN6P_IPV6_V6ONLY) == 0)
2318 inp->inp_vflag |= INP_IPV4;
2319 inp->in6p_hops = -1; /* use kernel default */
2323 inp->inp_vflag |= INP_IPV4;
2324 tp = tcp_newtcpcb(inp);
2328 INP_INFO_RUNLOCK_ET(&V_tcbinfo, et);
2331 tp->t_state = TCPS_CLOSED;
2333 INP_INFO_RUNLOCK_ET(&V_tcbinfo, et);
2334 TCPSTATES_INC(TCPS_CLOSED);
2339 * Initiate (or continue) disconnect.
2340 * If embryonic state, just send reset (once).
2341 * If in ``let data drain'' option and linger null, just drop.
2342 * Otherwise (hard), mark socket disconnecting and drop
2343 * current input data; switch states based on user close, and
2344 * send segment to peer (with FIN).
2347 tcp_disconnect(struct tcpcb *tp)
2349 struct inpcb *inp = tp->t_inpcb;
2350 struct socket *so = inp->inp_socket;
2352 INP_INFO_RLOCK_ASSERT(&V_tcbinfo);
2353 INP_WLOCK_ASSERT(inp);
2356 * Neither tcp_close() nor tcp_drop() should return NULL, as the
2357 * socket is still open.
2359 if (tp->t_state < TCPS_ESTABLISHED &&
2360 !(tp->t_state > TCPS_LISTEN && IS_FASTOPEN(tp->t_flags))) {
2363 ("tcp_disconnect: tcp_close() returned NULL"));
2364 } else if ((so->so_options & SO_LINGER) && so->so_linger == 0) {
2365 tp = tcp_drop(tp, 0);
2367 ("tcp_disconnect: tcp_drop() returned NULL"));
2369 soisdisconnecting(so);
2370 sbflush(&so->so_rcv);
2372 if (!(inp->inp_flags & INP_DROPPED))
2373 tp->t_fb->tfb_tcp_output(tp);
2378 * User issued close, and wish to trail through shutdown states:
2379 * if never received SYN, just forget it. If got a SYN from peer,
2380 * but haven't sent FIN, then go to FIN_WAIT_1 state to send peer a FIN.
2381 * If already got a FIN from peer, then almost done; go to LAST_ACK
2382 * state. In all other cases, have already sent FIN to peer (e.g.
2383 * after PRU_SHUTDOWN), and just have to play tedious game waiting
2384 * for peer to send FIN or not respond to keep-alives, etc.
2385 * We can let the user exit from the close as soon as the FIN is acked.
2388 tcp_usrclosed(struct tcpcb *tp)
2391 INP_INFO_RLOCK_ASSERT(&V_tcbinfo);
2392 INP_WLOCK_ASSERT(tp->t_inpcb);
2394 switch (tp->t_state) {
2397 tcp_offload_listen_stop(tp);
2399 tcp_state_change(tp, TCPS_CLOSED);
2404 * tcp_close() should never return NULL here as the socket is
2408 ("tcp_usrclosed: tcp_close() returned NULL"));
2412 case TCPS_SYN_RECEIVED:
2413 tp->t_flags |= TF_NEEDFIN;
2416 case TCPS_ESTABLISHED:
2417 tcp_state_change(tp, TCPS_FIN_WAIT_1);
2420 case TCPS_CLOSE_WAIT:
2421 tcp_state_change(tp, TCPS_LAST_ACK);
2424 if (tp->t_state >= TCPS_FIN_WAIT_2) {
2425 soisdisconnected(tp->t_inpcb->inp_socket);
2426 /* Prevent the connection hanging in FIN_WAIT_2 forever. */
2427 if (tp->t_state == TCPS_FIN_WAIT_2) {
2430 timeout = (tcp_fast_finwait2_recycle) ?
2431 tcp_finwait2_timeout : TP_MAXIDLE(tp);
2432 tcp_timer_activate(tp, TT_2MSL, timeout);
2439 db_print_indent(int indent)
2443 for (i = 0; i < indent; i++)
2448 db_print_tstate(int t_state)
2453 db_printf("TCPS_CLOSED");
2457 db_printf("TCPS_LISTEN");
2461 db_printf("TCPS_SYN_SENT");
2464 case TCPS_SYN_RECEIVED:
2465 db_printf("TCPS_SYN_RECEIVED");
2468 case TCPS_ESTABLISHED:
2469 db_printf("TCPS_ESTABLISHED");
2472 case TCPS_CLOSE_WAIT:
2473 db_printf("TCPS_CLOSE_WAIT");
2476 case TCPS_FIN_WAIT_1:
2477 db_printf("TCPS_FIN_WAIT_1");
2481 db_printf("TCPS_CLOSING");
2485 db_printf("TCPS_LAST_ACK");
2488 case TCPS_FIN_WAIT_2:
2489 db_printf("TCPS_FIN_WAIT_2");
2492 case TCPS_TIME_WAIT:
2493 db_printf("TCPS_TIME_WAIT");
2497 db_printf("unknown");
2503 db_print_tflags(u_int t_flags)
2508 if (t_flags & TF_ACKNOW) {
2509 db_printf("%sTF_ACKNOW", comma ? ", " : "");
2512 if (t_flags & TF_DELACK) {
2513 db_printf("%sTF_DELACK", comma ? ", " : "");
2516 if (t_flags & TF_NODELAY) {
2517 db_printf("%sTF_NODELAY", comma ? ", " : "");
2520 if (t_flags & TF_NOOPT) {
2521 db_printf("%sTF_NOOPT", comma ? ", " : "");
2524 if (t_flags & TF_SENTFIN) {
2525 db_printf("%sTF_SENTFIN", comma ? ", " : "");
2528 if (t_flags & TF_REQ_SCALE) {
2529 db_printf("%sTF_REQ_SCALE", comma ? ", " : "");
2532 if (t_flags & TF_RCVD_SCALE) {
2533 db_printf("%sTF_RECVD_SCALE", comma ? ", " : "");
2536 if (t_flags & TF_REQ_TSTMP) {
2537 db_printf("%sTF_REQ_TSTMP", comma ? ", " : "");
2540 if (t_flags & TF_RCVD_TSTMP) {
2541 db_printf("%sTF_RCVD_TSTMP", comma ? ", " : "");
2544 if (t_flags & TF_SACK_PERMIT) {
2545 db_printf("%sTF_SACK_PERMIT", comma ? ", " : "");
2548 if (t_flags & TF_NEEDSYN) {
2549 db_printf("%sTF_NEEDSYN", comma ? ", " : "");
2552 if (t_flags & TF_NEEDFIN) {
2553 db_printf("%sTF_NEEDFIN", comma ? ", " : "");
2556 if (t_flags & TF_NOPUSH) {
2557 db_printf("%sTF_NOPUSH", comma ? ", " : "");
2560 if (t_flags & TF_MORETOCOME) {
2561 db_printf("%sTF_MORETOCOME", comma ? ", " : "");
2564 if (t_flags & TF_LQ_OVERFLOW) {
2565 db_printf("%sTF_LQ_OVERFLOW", comma ? ", " : "");
2568 if (t_flags & TF_LASTIDLE) {
2569 db_printf("%sTF_LASTIDLE", comma ? ", " : "");
2572 if (t_flags & TF_RXWIN0SENT) {
2573 db_printf("%sTF_RXWIN0SENT", comma ? ", " : "");
2576 if (t_flags & TF_FASTRECOVERY) {
2577 db_printf("%sTF_FASTRECOVERY", comma ? ", " : "");
2580 if (t_flags & TF_CONGRECOVERY) {
2581 db_printf("%sTF_CONGRECOVERY", comma ? ", " : "");
2584 if (t_flags & TF_WASFRECOVERY) {
2585 db_printf("%sTF_WASFRECOVERY", comma ? ", " : "");
2588 if (t_flags & TF_SIGNATURE) {
2589 db_printf("%sTF_SIGNATURE", comma ? ", " : "");
2592 if (t_flags & TF_FORCEDATA) {
2593 db_printf("%sTF_FORCEDATA", comma ? ", " : "");
2596 if (t_flags & TF_TSO) {
2597 db_printf("%sTF_TSO", comma ? ", " : "");
2600 if (t_flags & TF_ECN_PERMIT) {
2601 db_printf("%sTF_ECN_PERMIT", comma ? ", " : "");
2604 if (t_flags & TF_FASTOPEN) {
2605 db_printf("%sTF_FASTOPEN", comma ? ", " : "");
2611 db_print_toobflags(char t_oobflags)
2616 if (t_oobflags & TCPOOB_HAVEDATA) {
2617 db_printf("%sTCPOOB_HAVEDATA", comma ? ", " : "");
2620 if (t_oobflags & TCPOOB_HADDATA) {
2621 db_printf("%sTCPOOB_HADDATA", comma ? ", " : "");
2627 db_print_tcpcb(struct tcpcb *tp, const char *name, int indent)
2630 db_print_indent(indent);
2631 db_printf("%s at %p\n", name, tp);
2635 db_print_indent(indent);
2636 db_printf("t_segq first: %p t_segqlen: %d t_dupacks: %d\n",
2637 TAILQ_FIRST(&tp->t_segq), tp->t_segqlen, tp->t_dupacks);
2639 db_print_indent(indent);
2640 db_printf("tt_rexmt: %p tt_persist: %p tt_keep: %p\n",
2641 &tp->t_timers->tt_rexmt, &tp->t_timers->tt_persist, &tp->t_timers->tt_keep);
2643 db_print_indent(indent);
2644 db_printf("tt_2msl: %p tt_delack: %p t_inpcb: %p\n", &tp->t_timers->tt_2msl,
2645 &tp->t_timers->tt_delack, tp->t_inpcb);
2647 db_print_indent(indent);
2648 db_printf("t_state: %d (", tp->t_state);
2649 db_print_tstate(tp->t_state);
2652 db_print_indent(indent);
2653 db_printf("t_flags: 0x%x (", tp->t_flags);
2654 db_print_tflags(tp->t_flags);
2657 db_print_indent(indent);
2658 db_printf("snd_una: 0x%08x snd_max: 0x%08x snd_nxt: x0%08x\n",
2659 tp->snd_una, tp->snd_max, tp->snd_nxt);
2661 db_print_indent(indent);
2662 db_printf("snd_up: 0x%08x snd_wl1: 0x%08x snd_wl2: 0x%08x\n",
2663 tp->snd_up, tp->snd_wl1, tp->snd_wl2);
2665 db_print_indent(indent);
2666 db_printf("iss: 0x%08x irs: 0x%08x rcv_nxt: 0x%08x\n",
2667 tp->iss, tp->irs, tp->rcv_nxt);
2669 db_print_indent(indent);
2670 db_printf("rcv_adv: 0x%08x rcv_wnd: %u rcv_up: 0x%08x\n",
2671 tp->rcv_adv, tp->rcv_wnd, tp->rcv_up);
2673 db_print_indent(indent);
2674 db_printf("snd_wnd: %u snd_cwnd: %u\n",
2675 tp->snd_wnd, tp->snd_cwnd);
2677 db_print_indent(indent);
2678 db_printf("snd_ssthresh: %u snd_recover: "
2679 "0x%08x\n", tp->snd_ssthresh, tp->snd_recover);
2681 db_print_indent(indent);
2682 db_printf("t_rcvtime: %u t_startime: %u\n",
2683 tp->t_rcvtime, tp->t_starttime);
2685 db_print_indent(indent);
2686 db_printf("t_rttime: %u t_rtsq: 0x%08x\n",
2687 tp->t_rtttime, tp->t_rtseq);
2689 db_print_indent(indent);
2690 db_printf("t_rxtcur: %d t_maxseg: %u t_srtt: %d\n",
2691 tp->t_rxtcur, tp->t_maxseg, tp->t_srtt);
2693 db_print_indent(indent);
2694 db_printf("t_rttvar: %d t_rxtshift: %d t_rttmin: %u "
2695 "t_rttbest: %u\n", tp->t_rttvar, tp->t_rxtshift, tp->t_rttmin,
2698 db_print_indent(indent);
2699 db_printf("t_rttupdated: %lu max_sndwnd: %u t_softerror: %d\n",
2700 tp->t_rttupdated, tp->max_sndwnd, tp->t_softerror);
2702 db_print_indent(indent);
2703 db_printf("t_oobflags: 0x%x (", tp->t_oobflags);
2704 db_print_toobflags(tp->t_oobflags);
2705 db_printf(") t_iobc: 0x%02x\n", tp->t_iobc);
2707 db_print_indent(indent);
2708 db_printf("snd_scale: %u rcv_scale: %u request_r_scale: %u\n",
2709 tp->snd_scale, tp->rcv_scale, tp->request_r_scale);
2711 db_print_indent(indent);
2712 db_printf("ts_recent: %u ts_recent_age: %u\n",
2713 tp->ts_recent, tp->ts_recent_age);
2715 db_print_indent(indent);
2716 db_printf("ts_offset: %u last_ack_sent: 0x%08x snd_cwnd_prev: "
2717 "%u\n", tp->ts_offset, tp->last_ack_sent, tp->snd_cwnd_prev);
2719 db_print_indent(indent);
2720 db_printf("snd_ssthresh_prev: %u snd_recover_prev: 0x%08x "
2721 "t_badrxtwin: %u\n", tp->snd_ssthresh_prev,
2722 tp->snd_recover_prev, tp->t_badrxtwin);
2724 db_print_indent(indent);
2725 db_printf("snd_numholes: %d snd_holes first: %p\n",
2726 tp->snd_numholes, TAILQ_FIRST(&tp->snd_holes));
2728 db_print_indent(indent);
2729 db_printf("snd_fack: 0x%08x rcv_numsacks: %d sack_newdata: "
2730 "0x%08x\n", tp->snd_fack, tp->rcv_numsacks, tp->sack_newdata);
2732 /* Skip sackblks, sackhint. */
2734 db_print_indent(indent);
2735 db_printf("t_rttlow: %d rfbuf_ts: %u rfbuf_cnt: %d\n",
2736 tp->t_rttlow, tp->rfbuf_ts, tp->rfbuf_cnt);
2739 DB_SHOW_COMMAND(tcpcb, db_show_tcpcb)
2744 db_printf("usage: show tcpcb <addr>\n");
2747 tp = (struct tcpcb *)addr;
2749 db_print_tcpcb(tp, "tcpcb", 0);