2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 1982, 1986, 1988, 1993
5 * The Regents of the University of California.
6 * Copyright (c) 2006-2007 Robert N. M. Watson
7 * Copyright (c) 2010-2011 Juniper Networks, Inc.
10 * Portions of this software were developed by Robert N. M. Watson under
11 * contract to Juniper Networks, Inc.
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its contributors
22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * From: @(#)tcp_usrreq.c 8.2 (Berkeley) 1/3/94
40 #include <sys/cdefs.h>
41 __FBSDID("$FreeBSD$");
45 #include "opt_inet6.h"
46 #include "opt_ipsec.h"
47 #include "opt_kern_tls.h"
48 #include "opt_tcpdebug.h"
50 #include <sys/param.h>
51 #include <sys/systm.h>
53 #include <sys/limits.h>
54 #include <sys/malloc.h>
55 #include <sys/refcount.h>
56 #include <sys/kernel.h>
58 #include <sys/qmath.h>
59 #include <sys/sysctl.h>
62 #include <sys/domain.h>
64 #include <sys/socket.h>
65 #include <sys/socketvar.h>
66 #include <sys/protosw.h>
69 #include <sys/syslog.h>
70 #include <sys/stats.h>
77 #include <net/if_var.h>
78 #include <net/route.h>
81 #include <netinet/in.h>
82 #include <netinet/in_kdtrace.h>
83 #include <netinet/in_pcb.h>
84 #include <netinet/in_systm.h>
85 #include <netinet/in_var.h>
86 #include <netinet/ip_var.h>
88 #include <netinet/ip6.h>
89 #include <netinet6/in6_pcb.h>
90 #include <netinet6/ip6_var.h>
91 #include <netinet6/scope6_var.h>
93 #include <netinet/tcp.h>
94 #include <netinet/tcp_fsm.h>
95 #include <netinet/tcp_seq.h>
96 #include <netinet/tcp_timer.h>
97 #include <netinet/tcp_var.h>
98 #include <netinet/tcp_log_buf.h>
99 #include <netinet/tcpip.h>
100 #include <netinet/cc/cc.h>
101 #include <netinet/tcp_fastopen.h>
102 #include <netinet/tcp_hpts.h>
104 #include <netinet/tcp_pcap.h>
107 #include <netinet/tcp_debug.h>
110 #include <netinet/tcp_offload.h>
112 #include <netipsec/ipsec_support.h>
115 #include <vm/vm_param.h>
117 #include <vm/vm_extern.h>
118 #include <vm/vm_map.h>
119 #include <vm/vm_page.h>
122 * TCP protocol interface to socket abstraction.
125 static int tcp_connect(struct tcpcb *, struct sockaddr *,
129 static int tcp6_connect(struct tcpcb *, struct sockaddr *,
132 static void tcp_disconnect(struct tcpcb *);
133 static void tcp_usrclosed(struct tcpcb *);
134 static void tcp_fill_info(struct tcpcb *, struct tcp_info *);
137 #define TCPDEBUG0 int ostate = 0
138 #define TCPDEBUG1() ostate = tp ? tp->t_state : 0
139 #define TCPDEBUG2(req) if (tp && (so->so_options & SO_DEBUG)) \
140 tcp_trace(TA_USER, ostate, tp, 0, 0, req)
144 #define TCPDEBUG2(req)
148 * TCP attaches to socket via pru_attach(), reserving space,
149 * and an internet control block.
152 tcp_usr_attach(struct socket *so, int proto, struct thread *td)
154 struct epoch_tracker et;
156 struct tcpcb *tp = NULL;
161 KASSERT(inp == NULL, ("tcp_usr_attach: inp != NULL"));
164 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
165 error = soreserve(so, V_tcp_sendspace, V_tcp_recvspace);
170 so->so_rcv.sb_flags |= SB_AUTOSIZE;
171 so->so_snd.sb_flags |= SB_AUTOSIZE;
173 error = in_pcballoc(so, &V_tcbinfo);
180 if (inp->inp_vflag & INP_IPV6PROTO) {
181 inp->inp_vflag |= INP_IPV6;
182 if ((inp->inp_flags & IN6P_IPV6_V6ONLY) == 0)
183 inp->inp_vflag |= INP_IPV4;
184 inp->in6p_hops = -1; /* use kernel default */
188 inp->inp_vflag |= INP_IPV4;
189 tp = tcp_newtcpcb(inp);
197 tp->t_state = TCPS_CLOSED;
200 TCPSTATES_INC(TCPS_CLOSED);
201 if ((so->so_options & SO_LINGER) && so->so_linger == 0)
202 so->so_linger = TCP_LINGERTIME;
204 TCPDEBUG2(PRU_ATTACH);
205 TCP_PROBE2(debug__user, tp, PRU_ATTACH);
210 * tcp_detach is called when the socket layer loses its final reference
211 * to the socket, be it a file descriptor reference, a reference from TCP,
212 * etc. At this point, there is only one case in which we will keep around
213 * inpcb state: time wait.
215 * This function can probably be re-absorbed back into tcp_usr_detach() now
216 * that there is a single detach path.
219 tcp_detach(struct socket *so, struct inpcb *inp)
223 INP_INFO_LOCK_ASSERT(&V_tcbinfo);
224 INP_WLOCK_ASSERT(inp);
226 KASSERT(so->so_pcb == inp, ("tcp_detach: so_pcb != inp"));
227 KASSERT(inp->inp_socket == so, ("tcp_detach: inp_socket != so"));
231 if (inp->inp_flags & INP_TIMEWAIT) {
233 * There are two cases to handle: one in which the time wait
234 * state is being discarded (INP_DROPPED), and one in which
235 * this connection will remain in timewait. In the former,
236 * it is time to discard all state (except tcptw, which has
237 * already been discarded by the timewait close code, which
238 * should be further up the call stack somewhere). In the
239 * latter case, we detach from the socket, but leave the pcb
240 * present until timewait ends.
242 * XXXRW: Would it be cleaner to free the tcptw here?
244 * Astute question indeed, from twtcp perspective there are
245 * four cases to consider:
247 * #1 tcp_detach is called at tcptw creation time by
248 * tcp_twstart, then do not discard the newly created tcptw
249 * and leave inpcb present until timewait ends
250 * #2 tcp_detach is called at tcptw creation time by
251 * tcp_twstart, but connection is local and tw will be
252 * discarded immediately
253 * #3 tcp_detach is called at timewait end (or reuse) by
254 * tcp_twclose, then the tcptw has already been discarded
255 * (or reused) and inpcb is freed here
256 * #4 tcp_detach is called() after timewait ends (or reuse)
257 * (e.g. by soclose), then tcptw has already been discarded
258 * (or reused) and inpcb is freed here
260 * In all three cases the tcptw should not be freed here.
262 if (inp->inp_flags & INP_DROPPED) {
264 if (__predict_true(tp == NULL)) {
268 * This case should not happen as in TIMEWAIT
269 * state the inp should not be destroyed before
270 * its tcptw. If INVARIANTS is defined, panic.
273 panic("%s: Panic before an inp double-free: "
274 "INP_TIMEWAIT && INP_DROPPED && tp != NULL"
277 log(LOG_ERR, "%s: Avoid an inp double-free: "
278 "INP_TIMEWAIT && INP_DROPPED && tp != NULL"
289 * If the connection is not in timewait, we consider two
290 * two conditions: one in which no further processing is
291 * necessary (dropped || embryonic), and one in which TCP is
292 * not yet done, but no longer requires the socket, so the
293 * pcb will persist for the time being.
295 * XXXRW: Does the second case still occur?
297 if (inp->inp_flags & INP_DROPPED ||
298 tp->t_state < TCPS_SYN_SENT) {
310 * pru_detach() detaches the TCP protocol from the socket.
311 * If the protocol state is non-embryonic, then can't
312 * do this directly: have to initiate a pru_disconnect(),
313 * which may finish later; embryonic TCB's can just
317 tcp_usr_detach(struct socket *so)
321 struct epoch_tracker et;
324 KASSERT(inp != NULL, ("tcp_usr_detach: inp == NULL"));
325 if (!INP_INFO_WLOCKED(&V_tcbinfo)) {
330 KASSERT(inp->inp_socket != NULL,
331 ("tcp_usr_detach: inp_socket == NULL"));
339 * Give the socket an address.
342 tcp_usr_bind(struct socket *so, struct sockaddr *nam, struct thread *td)
346 struct tcpcb *tp = NULL;
347 struct sockaddr_in *sinp;
349 sinp = (struct sockaddr_in *)nam;
350 if (nam->sa_len != sizeof (*sinp))
353 * Must check for multicast addresses and disallow binding
356 if (sinp->sin_family == AF_INET &&
357 IN_MULTICAST(ntohl(sinp->sin_addr.s_addr)))
358 return (EAFNOSUPPORT);
362 KASSERT(inp != NULL, ("tcp_usr_bind: inp == NULL"));
364 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
370 INP_HASH_WLOCK(&V_tcbinfo);
371 error = in_pcbbind(inp, nam, td->td_ucred);
372 INP_HASH_WUNLOCK(&V_tcbinfo);
375 TCP_PROBE2(debug__user, tp, PRU_BIND);
384 tcp6_usr_bind(struct socket *so, struct sockaddr *nam, struct thread *td)
388 struct tcpcb *tp = NULL;
389 struct sockaddr_in6 *sin6;
392 sin6 = (struct sockaddr_in6 *)nam;
393 if (nam->sa_len != sizeof (*sin6))
396 * Must check for multicast addresses and disallow binding
399 if (sin6->sin6_family == AF_INET6 &&
400 IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr))
401 return (EAFNOSUPPORT);
405 KASSERT(inp != NULL, ("tcp6_usr_bind: inp == NULL"));
407 vflagsav = inp->inp_vflag;
408 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
414 INP_HASH_WLOCK(&V_tcbinfo);
415 inp->inp_vflag &= ~INP_IPV4;
416 inp->inp_vflag |= INP_IPV6;
418 if ((inp->inp_flags & IN6P_IPV6_V6ONLY) == 0) {
419 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr))
420 inp->inp_vflag |= INP_IPV4;
421 else if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
422 struct sockaddr_in sin;
424 in6_sin6_2_sin(&sin, sin6);
425 if (IN_MULTICAST(ntohl(sin.sin_addr.s_addr))) {
426 error = EAFNOSUPPORT;
427 INP_HASH_WUNLOCK(&V_tcbinfo);
430 inp->inp_vflag |= INP_IPV4;
431 inp->inp_vflag &= ~INP_IPV6;
432 error = in_pcbbind(inp, (struct sockaddr *)&sin,
434 INP_HASH_WUNLOCK(&V_tcbinfo);
439 error = in6_pcbbind(inp, nam, td->td_ucred);
440 INP_HASH_WUNLOCK(&V_tcbinfo);
443 inp->inp_vflag = vflagsav;
445 TCP_PROBE2(debug__user, tp, PRU_BIND);
453 * Prepare to accept connections.
456 tcp_usr_listen(struct socket *so, int backlog, struct thread *td)
460 struct tcpcb *tp = NULL;
464 KASSERT(inp != NULL, ("tcp_usr_listen: inp == NULL"));
466 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
473 error = solisten_proto_check(so);
474 INP_HASH_WLOCK(&V_tcbinfo);
475 if (error == 0 && inp->inp_lport == 0)
476 error = in_pcbbind(inp, (struct sockaddr *)0, td->td_ucred);
477 INP_HASH_WUNLOCK(&V_tcbinfo);
479 tcp_state_change(tp, TCPS_LISTEN);
480 solisten_proto(so, backlog);
482 if ((so->so_options & SO_NO_OFFLOAD) == 0)
483 tcp_offload_listen_start(tp);
488 if (IS_FASTOPEN(tp->t_flags))
489 tp->t_tfo_pending = tcp_fastopen_alloc_counter();
492 TCPDEBUG2(PRU_LISTEN);
493 TCP_PROBE2(debug__user, tp, PRU_LISTEN);
501 tcp6_usr_listen(struct socket *so, int backlog, struct thread *td)
505 struct tcpcb *tp = NULL;
510 KASSERT(inp != NULL, ("tcp6_usr_listen: inp == NULL"));
512 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
516 vflagsav = inp->inp_vflag;
520 error = solisten_proto_check(so);
521 INP_HASH_WLOCK(&V_tcbinfo);
522 if (error == 0 && inp->inp_lport == 0) {
523 inp->inp_vflag &= ~INP_IPV4;
524 if ((inp->inp_flags & IN6P_IPV6_V6ONLY) == 0)
525 inp->inp_vflag |= INP_IPV4;
526 error = in6_pcbbind(inp, (struct sockaddr *)0, td->td_ucred);
528 INP_HASH_WUNLOCK(&V_tcbinfo);
530 tcp_state_change(tp, TCPS_LISTEN);
531 solisten_proto(so, backlog);
533 if ((so->so_options & SO_NO_OFFLOAD) == 0)
534 tcp_offload_listen_start(tp);
539 if (IS_FASTOPEN(tp->t_flags))
540 tp->t_tfo_pending = tcp_fastopen_alloc_counter();
543 inp->inp_vflag = vflagsav;
546 TCPDEBUG2(PRU_LISTEN);
547 TCP_PROBE2(debug__user, tp, PRU_LISTEN);
555 * Initiate connection to peer.
556 * Create a template for use in transmissions on this connection.
557 * Enter SYN_SENT state, and mark socket as connecting.
558 * Start keep-alive timer, and seed output sequence space.
559 * Send initial segment on connection.
562 tcp_usr_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
564 struct epoch_tracker et;
567 struct tcpcb *tp = NULL;
568 struct sockaddr_in *sinp;
570 sinp = (struct sockaddr_in *)nam;
571 if (nam->sa_len != sizeof (*sinp))
574 * Must disallow TCP ``connections'' to multicast addresses.
576 if (sinp->sin_family == AF_INET
577 && IN_MULTICAST(ntohl(sinp->sin_addr.s_addr)))
578 return (EAFNOSUPPORT);
579 if ((error = prison_remote_ip4(td->td_ucred, &sinp->sin_addr)) != 0)
584 KASSERT(inp != NULL, ("tcp_usr_connect: inp == NULL"));
586 if (inp->inp_flags & INP_TIMEWAIT) {
590 if (inp->inp_flags & INP_DROPPED) {
591 error = ECONNREFUSED;
596 if ((error = tcp_connect(tp, nam, td)) != 0)
599 if (registered_toedevs > 0 &&
600 (so->so_options & SO_NO_OFFLOAD) == 0 &&
601 (error = tcp_offload_connect(so, nam)) == 0)
604 tcp_timer_activate(tp, TT_KEEP, TP_KEEPINIT(tp));
606 error = tp->t_fb->tfb_tcp_output(tp);
609 TCPDEBUG2(PRU_CONNECT);
610 TCP_PROBE2(debug__user, tp, PRU_CONNECT);
618 tcp6_usr_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
620 struct epoch_tracker et;
623 struct tcpcb *tp = NULL;
624 struct sockaddr_in6 *sin6;
630 sin6 = (struct sockaddr_in6 *)nam;
631 if (nam->sa_len != sizeof (*sin6))
634 * Must disallow TCP ``connections'' to multicast addresses.
636 if (sin6->sin6_family == AF_INET6
637 && IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr))
638 return (EAFNOSUPPORT);
641 KASSERT(inp != NULL, ("tcp6_usr_connect: inp == NULL"));
643 vflagsav = inp->inp_vflag;
644 incflagsav = inp->inp_inc.inc_flags;
645 if (inp->inp_flags & INP_TIMEWAIT) {
649 if (inp->inp_flags & INP_DROPPED) {
650 error = ECONNREFUSED;
657 * XXXRW: Some confusion: V4/V6 flags relate to binding, and
658 * therefore probably require the hash lock, which isn't held here.
659 * Is this a significant problem?
661 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
662 struct sockaddr_in sin;
664 if ((inp->inp_flags & IN6P_IPV6_V6ONLY) != 0) {
668 if ((inp->inp_vflag & INP_IPV4) == 0) {
669 error = EAFNOSUPPORT;
673 in6_sin6_2_sin(&sin, sin6);
674 if (IN_MULTICAST(ntohl(sin.sin_addr.s_addr))) {
675 error = EAFNOSUPPORT;
678 if ((error = prison_remote_ip4(td->td_ucred,
679 &sin.sin_addr)) != 0)
681 inp->inp_vflag |= INP_IPV4;
682 inp->inp_vflag &= ~INP_IPV6;
683 if ((error = tcp_connect(tp, (struct sockaddr *)&sin, td)) != 0)
686 if (registered_toedevs > 0 &&
687 (so->so_options & SO_NO_OFFLOAD) == 0 &&
688 (error = tcp_offload_connect(so, nam)) == 0)
692 error = tp->t_fb->tfb_tcp_output(tp);
696 if ((inp->inp_vflag & INP_IPV6) == 0) {
697 error = EAFNOSUPPORT;
702 if ((error = prison_remote_ip6(td->td_ucred, &sin6->sin6_addr)) != 0)
704 inp->inp_vflag &= ~INP_IPV4;
705 inp->inp_vflag |= INP_IPV6;
706 inp->inp_inc.inc_flags |= INC_ISIPV6;
707 if ((error = tcp6_connect(tp, nam, td)) != 0)
710 if (registered_toedevs > 0 &&
711 (so->so_options & SO_NO_OFFLOAD) == 0 &&
712 (error = tcp_offload_connect(so, nam)) == 0)
715 tcp_timer_activate(tp, TT_KEEP, TP_KEEPINIT(tp));
717 error = tp->t_fb->tfb_tcp_output(tp);
721 * If the implicit bind in the connect call fails, restore
722 * the flags we modified.
724 if (error != 0 && inp->inp_lport == 0) {
725 inp->inp_vflag = vflagsav;
726 inp->inp_inc.inc_flags = incflagsav;
729 TCPDEBUG2(PRU_CONNECT);
730 TCP_PROBE2(debug__user, tp, PRU_CONNECT);
737 * Initiate disconnect from peer.
738 * If connection never passed embryonic stage, just drop;
739 * else if don't need to let data drain, then can just drop anyways,
740 * else have to begin TCP shutdown process: mark socket disconnecting,
741 * drain unread data, state switch to reflect user close, and
742 * send segment (e.g. FIN) to peer. Socket will be really disconnected
743 * when peer sends FIN and acks ours.
745 * SHOULD IMPLEMENT LATER PRU_CONNECT VIA REALLOC TCPCB.
748 tcp_usr_disconnect(struct socket *so)
751 struct tcpcb *tp = NULL;
752 struct epoch_tracker et;
758 KASSERT(inp != NULL, ("tcp_usr_disconnect: inp == NULL"));
760 if (inp->inp_flags & INP_TIMEWAIT)
762 if (inp->inp_flags & INP_DROPPED) {
770 TCPDEBUG2(PRU_DISCONNECT);
771 TCP_PROBE2(debug__user, tp, PRU_DISCONNECT);
779 * Accept a connection. Essentially all the work is done at higher levels;
780 * just return the address of the peer, storing through addr.
783 tcp_usr_accept(struct socket *so, struct sockaddr **nam)
786 struct inpcb *inp = NULL;
787 struct tcpcb *tp = NULL;
792 if (so->so_state & SS_ISDISCONNECTED)
793 return (ECONNABORTED);
796 KASSERT(inp != NULL, ("tcp_usr_accept: inp == NULL"));
798 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
799 error = ECONNABORTED;
806 * We inline in_getpeeraddr and COMMON_END here, so that we can
807 * copy the data of interest and defer the malloc until after we
810 port = inp->inp_fport;
811 addr = inp->inp_faddr;
814 TCPDEBUG2(PRU_ACCEPT);
815 TCP_PROBE2(debug__user, tp, PRU_ACCEPT);
818 *nam = in_sockaddr(port, &addr);
825 tcp6_usr_accept(struct socket *so, struct sockaddr **nam)
827 struct inpcb *inp = NULL;
829 struct tcpcb *tp = NULL;
831 struct in6_addr addr6;
832 struct epoch_tracker et;
837 if (so->so_state & SS_ISDISCONNECTED)
838 return (ECONNABORTED);
841 KASSERT(inp != NULL, ("tcp6_usr_accept: inp == NULL"));
844 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
845 error = ECONNABORTED;
852 * We inline in6_mapped_peeraddr and COMMON_END here, so that we can
853 * copy the data of interest and defer the malloc until after we
856 if (inp->inp_vflag & INP_IPV4) {
858 port = inp->inp_fport;
859 addr = inp->inp_faddr;
861 port = inp->inp_fport;
862 addr6 = inp->in6p_faddr;
866 TCPDEBUG2(PRU_ACCEPT);
867 TCP_PROBE2(debug__user, tp, PRU_ACCEPT);
872 *nam = in6_v4mapsin6_sockaddr(port, &addr);
874 *nam = in6_sockaddr(port, &addr6);
881 * Mark the connection as being incapable of further output.
884 tcp_usr_shutdown(struct socket *so)
888 struct tcpcb *tp = NULL;
889 struct epoch_tracker et;
894 KASSERT(inp != NULL, ("inp == NULL"));
896 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
904 if (!(inp->inp_flags & INP_DROPPED))
905 error = tp->t_fb->tfb_tcp_output(tp);
908 TCPDEBUG2(PRU_SHUTDOWN);
909 TCP_PROBE2(debug__user, tp, PRU_SHUTDOWN);
917 * After a receive, possibly send window update to peer.
920 tcp_usr_rcvd(struct socket *so, int flags)
922 struct epoch_tracker et;
924 struct tcpcb *tp = NULL;
929 KASSERT(inp != NULL, ("tcp_usr_rcvd: inp == NULL"));
931 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
938 * For passively-created TFO connections, don't attempt a window
939 * update while still in SYN_RECEIVED as this may trigger an early
940 * SYN|ACK. It is preferable to have the SYN|ACK be sent along with
941 * application response data, or failing that, when the DELACK timer
944 if (IS_FASTOPEN(tp->t_flags) &&
945 (tp->t_state == TCPS_SYN_RECEIVED))
948 if (tp->t_flags & TF_TOE)
949 tcp_offload_rcvd(tp);
953 tp->t_fb->tfb_tcp_output(tp);
957 TCP_PROBE2(debug__user, tp, PRU_RCVD);
963 * Do a send by putting data in output queue and updating urgent
964 * marker if URG set. Possibly send more data. Unlike the other
965 * pru_*() routines, the mbuf chains are our responsibility. We
966 * must either enqueue them or free them. The other pru_* routines
967 * generally are caller-frees.
970 tcp_usr_send(struct socket *so, int flags, struct mbuf *m,
971 struct sockaddr *nam, struct mbuf *control, struct thread *td)
973 struct epoch_tracker et;
976 struct tcpcb *tp = NULL;
979 struct sockaddr_in sin;
981 struct sockaddr_in *sinp;
992 * We require the pcbinfo "read lock" if we will close the socket
993 * as part of this call.
997 KASSERT(inp != NULL, ("tcp_usr_send: inp == NULL"));
999 vflagsav = inp->inp_vflag;
1000 incflagsav = inp->inp_inc.inc_flags;
1001 restoreflags = false;
1002 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
1006 * In case of PRUS_NOTREADY, tcp_usr_ready() is responsible
1007 * for freeing memory.
1009 if (m && (flags & PRUS_NOTREADY) == 0)
1014 tp = intotcpcb(inp);
1016 if (nam != NULL && tp->t_state < TCPS_SYN_SENT) {
1017 switch (nam->sa_family) {
1020 sinp = (struct sockaddr_in *)nam;
1021 if (sinp->sin_len != sizeof(struct sockaddr_in)) {
1027 if ((inp->inp_vflag & INP_IPV6) != 0) {
1030 error = EAFNOSUPPORT;
1033 if (IN_MULTICAST(ntohl(sinp->sin_addr.s_addr))) {
1036 error = EAFNOSUPPORT;
1039 if ((error = prison_remote_ip4(td->td_ucred,
1040 &sinp->sin_addr))) {
1053 struct sockaddr_in6 *sin6;
1055 sin6 = (struct sockaddr_in6 *)nam;
1056 if (sin6->sin6_len != sizeof(*sin6)) {
1062 if (IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr)) {
1065 error = EAFNOSUPPORT;
1068 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
1070 if ((inp->inp_flags & IN6P_IPV6_V6ONLY) != 0) {
1076 if ((inp->inp_vflag & INP_IPV4) == 0) {
1077 error = EAFNOSUPPORT;
1082 restoreflags = true;
1083 inp->inp_vflag &= ~INP_IPV6;
1085 in6_sin6_2_sin(sinp, sin6);
1087 ntohl(sinp->sin_addr.s_addr))) {
1088 error = EAFNOSUPPORT;
1093 if ((error = prison_remote_ip4(td->td_ucred,
1094 &sinp->sin_addr))) {
1101 error = EAFNOSUPPORT;
1107 if ((inp->inp_vflag & INP_IPV6) == 0) {
1110 error = EAFNOSUPPORT;
1113 restoreflags = true;
1114 inp->inp_vflag &= ~INP_IPV4;
1115 inp->inp_inc.inc_flags |= INC_ISIPV6;
1116 if ((error = prison_remote_ip6(td->td_ucred,
1117 &sin6->sin6_addr))) {
1130 error = EAFNOSUPPORT;
1135 /* TCP doesn't do control messages (rights, creds, etc) */
1136 if (control->m_len) {
1143 m_freem(control); /* empty control, just free it */
1145 if (!(flags & PRUS_OOB)) {
1146 sbappendstream(&so->so_snd, m, flags);
1147 if (nam && tp->t_state < TCPS_SYN_SENT) {
1149 * Do implied connect if not yet connected,
1150 * initialize window to default value, and
1151 * initialize maxseg using peer's cached MSS.
1155 error = tcp6_connect(tp, nam, td);
1157 #if defined(INET6) && defined(INET)
1161 error = tcp_connect(tp,
1162 (struct sockaddr *)sinp, td);
1165 * The bind operation in tcp_connect succeeded. We
1166 * no longer want to restore the flags if later
1169 if (error == 0 || inp->inp_lport != 0)
1170 restoreflags = false;
1174 if (IS_FASTOPEN(tp->t_flags))
1175 tcp_fastopen_connect(tp);
1177 tp->snd_wnd = TTCP_CLIENT_SND_WND;
1181 if (flags & PRUS_EOF) {
1183 * Close the send side of the connection after
1190 if (!(inp->inp_flags & INP_DROPPED) &&
1191 !(flags & PRUS_NOTREADY)) {
1192 if (flags & PRUS_MORETOCOME)
1193 tp->t_flags |= TF_MORETOCOME;
1194 error = tp->t_fb->tfb_tcp_output(tp);
1195 if (flags & PRUS_MORETOCOME)
1196 tp->t_flags &= ~TF_MORETOCOME;
1200 * XXXRW: PRUS_EOF not implemented with PRUS_OOB?
1202 SOCKBUF_LOCK(&so->so_snd);
1203 if (sbspace(&so->so_snd) < -512) {
1204 SOCKBUF_UNLOCK(&so->so_snd);
1210 * According to RFC961 (Assigned Protocols),
1211 * the urgent pointer points to the last octet
1212 * of urgent data. We continue, however,
1213 * to consider it to indicate the first octet
1214 * of data past the urgent section.
1215 * Otherwise, snd_up should be one lower.
1217 sbappendstream_locked(&so->so_snd, m, flags);
1218 SOCKBUF_UNLOCK(&so->so_snd);
1219 if (nam && tp->t_state < TCPS_SYN_SENT) {
1221 * Do implied connect if not yet connected,
1222 * initialize window to default value, and
1223 * initialize maxseg using peer's cached MSS.
1227 * Not going to contemplate SYN|URG
1229 if (IS_FASTOPEN(tp->t_flags))
1230 tp->t_flags &= ~TF_FASTOPEN;
1233 error = tcp6_connect(tp, nam, td);
1235 #if defined(INET6) && defined(INET)
1239 error = tcp_connect(tp,
1240 (struct sockaddr *)sinp, td);
1243 * The bind operation in tcp_connect succeeded. We
1244 * no longer want to restore the flags if later
1247 if (error == 0 || inp->inp_lport != 0)
1248 restoreflags = false;
1252 tp->snd_wnd = TTCP_CLIENT_SND_WND;
1255 tp->snd_up = tp->snd_una + sbavail(&so->so_snd);
1256 if (!(flags & PRUS_NOTREADY)) {
1257 tp->t_flags |= TF_FORCEDATA;
1258 error = tp->t_fb->tfb_tcp_output(tp);
1259 tp->t_flags &= ~TF_FORCEDATA;
1262 TCP_LOG_EVENT(tp, NULL,
1263 &inp->inp_socket->so_rcv,
1264 &inp->inp_socket->so_snd,
1265 TCP_LOG_USERSEND, error,
1269 * If the request was unsuccessful and we changed flags,
1270 * restore the original flags.
1272 if (error != 0 && restoreflags) {
1273 inp->inp_vflag = vflagsav;
1274 inp->inp_inc.inc_flags = incflagsav;
1276 TCPDEBUG2((flags & PRUS_OOB) ? PRU_SENDOOB :
1277 ((flags & PRUS_EOF) ? PRU_SEND_EOF : PRU_SEND));
1278 TCP_PROBE2(debug__user, tp, (flags & PRUS_OOB) ? PRU_SENDOOB :
1279 ((flags & PRUS_EOF) ? PRU_SEND_EOF : PRU_SEND));
1286 tcp_usr_ready(struct socket *so, struct mbuf *m, int count)
1288 struct epoch_tracker et;
1293 inp = sotoinpcb(so);
1295 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
1297 mb_free_notready(m, count);
1298 return (ECONNRESET);
1300 tp = intotcpcb(inp);
1302 SOCKBUF_LOCK(&so->so_snd);
1303 error = sbready(&so->so_snd, m, count);
1304 SOCKBUF_UNLOCK(&so->so_snd);
1306 NET_EPOCH_ENTER(et);
1307 error = tp->t_fb->tfb_tcp_output(tp);
1316 * Abort the TCP. Drop the connection abruptly.
1319 tcp_usr_abort(struct socket *so)
1322 struct tcpcb *tp = NULL;
1323 struct epoch_tracker et;
1326 inp = sotoinpcb(so);
1327 KASSERT(inp != NULL, ("tcp_usr_abort: inp == NULL"));
1329 NET_EPOCH_ENTER(et);
1331 KASSERT(inp->inp_socket != NULL,
1332 ("tcp_usr_abort: inp_socket == NULL"));
1335 * If we still have full TCP state, and we're not dropped, drop.
1337 if (!(inp->inp_flags & INP_TIMEWAIT) &&
1338 !(inp->inp_flags & INP_DROPPED)) {
1339 tp = intotcpcb(inp);
1341 tp = tcp_drop(tp, ECONNABORTED);
1344 TCPDEBUG2(PRU_ABORT);
1345 TCP_PROBE2(debug__user, tp, PRU_ABORT);
1347 if (!(inp->inp_flags & INP_DROPPED)) {
1349 so->so_state |= SS_PROTOREF;
1351 inp->inp_flags |= INP_SOCKREF;
1359 * TCP socket is closed. Start friendly disconnect.
1362 tcp_usr_close(struct socket *so)
1365 struct tcpcb *tp = NULL;
1366 struct epoch_tracker et;
1369 inp = sotoinpcb(so);
1370 KASSERT(inp != NULL, ("tcp_usr_close: inp == NULL"));
1372 NET_EPOCH_ENTER(et);
1374 KASSERT(inp->inp_socket != NULL,
1375 ("tcp_usr_close: inp_socket == NULL"));
1378 * If we still have full TCP state, and we're not dropped, initiate
1381 if (!(inp->inp_flags & INP_TIMEWAIT) &&
1382 !(inp->inp_flags & INP_DROPPED)) {
1383 tp = intotcpcb(inp);
1386 TCPDEBUG2(PRU_CLOSE);
1387 TCP_PROBE2(debug__user, tp, PRU_CLOSE);
1389 if (!(inp->inp_flags & INP_DROPPED)) {
1391 so->so_state |= SS_PROTOREF;
1393 inp->inp_flags |= INP_SOCKREF;
1400 * Receive out-of-band data.
1403 tcp_usr_rcvoob(struct socket *so, struct mbuf *m, int flags)
1407 struct tcpcb *tp = NULL;
1410 inp = sotoinpcb(so);
1411 KASSERT(inp != NULL, ("tcp_usr_rcvoob: inp == NULL"));
1413 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
1417 tp = intotcpcb(inp);
1419 if ((so->so_oobmark == 0 &&
1420 (so->so_rcv.sb_state & SBS_RCVATMARK) == 0) ||
1421 so->so_options & SO_OOBINLINE ||
1422 tp->t_oobflags & TCPOOB_HADDATA) {
1426 if ((tp->t_oobflags & TCPOOB_HAVEDATA) == 0) {
1427 error = EWOULDBLOCK;
1431 *mtod(m, caddr_t) = tp->t_iobc;
1432 if ((flags & MSG_PEEK) == 0)
1433 tp->t_oobflags ^= (TCPOOB_HAVEDATA | TCPOOB_HADDATA);
1436 TCPDEBUG2(PRU_RCVOOB);
1437 TCP_PROBE2(debug__user, tp, PRU_RCVOOB);
1443 struct pr_usrreqs tcp_usrreqs = {
1444 .pru_abort = tcp_usr_abort,
1445 .pru_accept = tcp_usr_accept,
1446 .pru_attach = tcp_usr_attach,
1447 .pru_bind = tcp_usr_bind,
1448 .pru_connect = tcp_usr_connect,
1449 .pru_control = in_control,
1450 .pru_detach = tcp_usr_detach,
1451 .pru_disconnect = tcp_usr_disconnect,
1452 .pru_listen = tcp_usr_listen,
1453 .pru_peeraddr = in_getpeeraddr,
1454 .pru_rcvd = tcp_usr_rcvd,
1455 .pru_rcvoob = tcp_usr_rcvoob,
1456 .pru_send = tcp_usr_send,
1457 .pru_ready = tcp_usr_ready,
1458 .pru_shutdown = tcp_usr_shutdown,
1459 .pru_sockaddr = in_getsockaddr,
1460 .pru_sosetlabel = in_pcbsosetlabel,
1461 .pru_close = tcp_usr_close,
1466 struct pr_usrreqs tcp6_usrreqs = {
1467 .pru_abort = tcp_usr_abort,
1468 .pru_accept = tcp6_usr_accept,
1469 .pru_attach = tcp_usr_attach,
1470 .pru_bind = tcp6_usr_bind,
1471 .pru_connect = tcp6_usr_connect,
1472 .pru_control = in6_control,
1473 .pru_detach = tcp_usr_detach,
1474 .pru_disconnect = tcp_usr_disconnect,
1475 .pru_listen = tcp6_usr_listen,
1476 .pru_peeraddr = in6_mapped_peeraddr,
1477 .pru_rcvd = tcp_usr_rcvd,
1478 .pru_rcvoob = tcp_usr_rcvoob,
1479 .pru_send = tcp_usr_send,
1480 .pru_ready = tcp_usr_ready,
1481 .pru_shutdown = tcp_usr_shutdown,
1482 .pru_sockaddr = in6_mapped_sockaddr,
1483 .pru_sosetlabel = in_pcbsosetlabel,
1484 .pru_close = tcp_usr_close,
1490 * Common subroutine to open a TCP connection to remote host specified
1491 * by struct sockaddr_in in mbuf *nam. Call in_pcbbind to assign a local
1492 * port number if needed. Call in_pcbconnect_setup to do the routing and
1493 * to choose a local host address (interface). If there is an existing
1494 * incarnation of the same connection in TIME-WAIT state and if the remote
1495 * host was sending CC options and if the connection duration was < MSL, then
1496 * truncate the previous TIME-WAIT state and proceed.
1497 * Initialize connection parameters and enter SYN-SENT state.
1500 tcp_connect(struct tcpcb *tp, struct sockaddr *nam, struct thread *td)
1502 struct inpcb *inp = tp->t_inpcb, *oinp;
1503 struct socket *so = inp->inp_socket;
1504 struct in_addr laddr;
1508 INP_WLOCK_ASSERT(inp);
1509 INP_HASH_WLOCK(&V_tcbinfo);
1511 if (inp->inp_lport == 0) {
1512 error = in_pcbbind(inp, (struct sockaddr *)0, td->td_ucred);
1518 * Cannot simply call in_pcbconnect, because there might be an
1519 * earlier incarnation of this same connection still in
1520 * TIME_WAIT state, creating an ADDRINUSE error.
1522 laddr = inp->inp_laddr;
1523 lport = inp->inp_lport;
1524 error = in_pcbconnect_setup(inp, nam, &laddr.s_addr, &lport,
1525 &inp->inp_faddr.s_addr, &inp->inp_fport, &oinp, td->td_ucred);
1526 if (error && oinp == NULL)
1532 inp->inp_laddr = laddr;
1534 INP_HASH_WUNLOCK(&V_tcbinfo);
1537 * Compute window scaling to request:
1538 * Scale to fit into sweet spot. See tcp_syncache.c.
1539 * XXX: This should move to tcp_output().
1541 while (tp->request_r_scale < TCP_MAX_WINSHIFT &&
1542 (TCP_MAXWIN << tp->request_r_scale) < sb_max)
1543 tp->request_r_scale++;
1546 TCPSTAT_INC(tcps_connattempt);
1547 tcp_state_change(tp, TCPS_SYN_SENT);
1548 tp->iss = tcp_new_isn(&inp->inp_inc);
1549 if (tp->t_flags & TF_REQ_TSTMP)
1550 tp->ts_offset = tcp_new_ts_offset(&inp->inp_inc);
1551 tcp_sendseqinit(tp);
1556 INP_HASH_WUNLOCK(&V_tcbinfo);
1563 tcp6_connect(struct tcpcb *tp, struct sockaddr *nam, struct thread *td)
1565 struct inpcb *inp = tp->t_inpcb;
1568 INP_WLOCK_ASSERT(inp);
1569 INP_HASH_WLOCK(&V_tcbinfo);
1571 if (inp->inp_lport == 0) {
1572 error = in6_pcbbind(inp, (struct sockaddr *)0, td->td_ucred);
1576 error = in6_pcbconnect(inp, nam, td->td_ucred);
1579 INP_HASH_WUNLOCK(&V_tcbinfo);
1581 /* Compute window scaling to request. */
1582 while (tp->request_r_scale < TCP_MAX_WINSHIFT &&
1583 (TCP_MAXWIN << tp->request_r_scale) < sb_max)
1584 tp->request_r_scale++;
1586 soisconnecting(inp->inp_socket);
1587 TCPSTAT_INC(tcps_connattempt);
1588 tcp_state_change(tp, TCPS_SYN_SENT);
1589 tp->iss = tcp_new_isn(&inp->inp_inc);
1590 if (tp->t_flags & TF_REQ_TSTMP)
1591 tp->ts_offset = tcp_new_ts_offset(&inp->inp_inc);
1592 tcp_sendseqinit(tp);
1597 INP_HASH_WUNLOCK(&V_tcbinfo);
1603 * Export TCP internal state information via a struct tcp_info, based on the
1604 * Linux 2.6 API. Not ABI compatible as our constants are mapped differently
1605 * (TCP state machine, etc). We export all information using FreeBSD-native
1606 * constants -- for example, the numeric values for tcpi_state will differ
1610 tcp_fill_info(struct tcpcb *tp, struct tcp_info *ti)
1613 INP_WLOCK_ASSERT(tp->t_inpcb);
1614 bzero(ti, sizeof(*ti));
1616 ti->tcpi_state = tp->t_state;
1617 if ((tp->t_flags & TF_REQ_TSTMP) && (tp->t_flags & TF_RCVD_TSTMP))
1618 ti->tcpi_options |= TCPI_OPT_TIMESTAMPS;
1619 if (tp->t_flags & TF_SACK_PERMIT)
1620 ti->tcpi_options |= TCPI_OPT_SACK;
1621 if ((tp->t_flags & TF_REQ_SCALE) && (tp->t_flags & TF_RCVD_SCALE)) {
1622 ti->tcpi_options |= TCPI_OPT_WSCALE;
1623 ti->tcpi_snd_wscale = tp->snd_scale;
1624 ti->tcpi_rcv_wscale = tp->rcv_scale;
1626 if (tp->t_flags2 & TF2_ECN_PERMIT)
1627 ti->tcpi_options |= TCPI_OPT_ECN;
1629 ti->tcpi_rto = tp->t_rxtcur * tick;
1630 ti->tcpi_last_data_recv = ((uint32_t)ticks - tp->t_rcvtime) * tick;
1631 ti->tcpi_rtt = ((u_int64_t)tp->t_srtt * tick) >> TCP_RTT_SHIFT;
1632 ti->tcpi_rttvar = ((u_int64_t)tp->t_rttvar * tick) >> TCP_RTTVAR_SHIFT;
1634 ti->tcpi_snd_ssthresh = tp->snd_ssthresh;
1635 ti->tcpi_snd_cwnd = tp->snd_cwnd;
1638 * FreeBSD-specific extension fields for tcp_info.
1640 ti->tcpi_rcv_space = tp->rcv_wnd;
1641 ti->tcpi_rcv_nxt = tp->rcv_nxt;
1642 ti->tcpi_snd_wnd = tp->snd_wnd;
1643 ti->tcpi_snd_bwnd = 0; /* Unused, kept for compat. */
1644 ti->tcpi_snd_nxt = tp->snd_nxt;
1645 ti->tcpi_snd_mss = tp->t_maxseg;
1646 ti->tcpi_rcv_mss = tp->t_maxseg;
1647 ti->tcpi_snd_rexmitpack = tp->t_sndrexmitpack;
1648 ti->tcpi_rcv_ooopack = tp->t_rcvoopack;
1649 ti->tcpi_snd_zerowin = tp->t_sndzerowin;
1651 if (tp->t_flags & TF_TOE) {
1652 ti->tcpi_options |= TCPI_OPT_TOE;
1653 tcp_offload_tcp_info(tp, ti);
1659 * tcp_ctloutput() must drop the inpcb lock before performing copyin on
1660 * socket option arguments. When it re-acquires the lock after the copy, it
1661 * has to revalidate that the connection is still valid for the socket
1664 #define INP_WLOCK_RECHECK_CLEANUP(inp, cleanup) do { \
1666 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) { \
1669 return (ECONNRESET); \
1671 tp = intotcpcb(inp); \
1673 #define INP_WLOCK_RECHECK(inp) INP_WLOCK_RECHECK_CLEANUP((inp), /* noop */)
1676 tcp_ctloutput(struct socket *so, struct sockopt *sopt)
1681 struct tcp_function_block *blk;
1682 struct tcp_function_set fsn;
1685 inp = sotoinpcb(so);
1686 KASSERT(inp != NULL, ("tcp_ctloutput: inp == NULL"));
1687 if (sopt->sopt_level != IPPROTO_TCP) {
1689 if (inp->inp_vflag & INP_IPV6PROTO) {
1690 error = ip6_ctloutput(so, sopt);
1692 * In case of the IPV6_USE_MIN_MTU socket option,
1693 * the INC_IPV6MINMTU flag to announce a corresponding
1694 * MSS during the initial handshake.
1695 * If the TCP connection is not in the front states,
1696 * just reduce the MSS being used.
1697 * This avoids the sending of TCP segments which will
1698 * be fragmented at the IPv6 layer.
1701 (sopt->sopt_dir == SOPT_SET) &&
1702 (sopt->sopt_level == IPPROTO_IPV6) &&
1703 (sopt->sopt_name == IPV6_USE_MIN_MTU)) {
1705 if ((inp->inp_flags &
1706 (INP_TIMEWAIT | INP_DROPPED))) {
1708 return (ECONNRESET);
1710 inp->inp_inc.inc_flags |= INC_IPV6MINMTU;
1711 tp = intotcpcb(inp);
1712 if ((tp->t_state >= TCPS_SYN_SENT) &&
1713 (inp->inp_inc.inc_flags & INC_ISIPV6)) {
1714 struct ip6_pktopts *opt;
1716 opt = inp->in6p_outputopts;
1717 if ((opt != NULL) &&
1718 (opt->ip6po_minmtu ==
1719 IP6PO_MINMTU_ALL)) {
1720 if (tp->t_maxseg > TCP6_MSS) {
1721 tp->t_maxseg = TCP6_MSS;
1729 #if defined(INET6) && defined(INET)
1734 error = ip_ctloutput(so, sopt);
1740 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
1742 return (ECONNRESET);
1744 tp = intotcpcb(inp);
1746 * Protect the TCP option TCP_FUNCTION_BLK so
1747 * that a sub-function can *never* overwrite this.
1749 if ((sopt->sopt_dir == SOPT_SET) &&
1750 (sopt->sopt_name == TCP_FUNCTION_BLK)) {
1752 error = sooptcopyin(sopt, &fsn, sizeof fsn,
1756 INP_WLOCK_RECHECK(inp);
1757 blk = find_and_ref_tcp_functions(&fsn);
1762 if (tp->t_fb == blk) {
1763 /* You already have this */
1764 refcount_release(&blk->tfb_refcnt);
1768 if (tp->t_state != TCPS_CLOSED) {
1770 * The user has advanced the state
1771 * past the initial point, we may not
1772 * be able to switch.
1774 if (blk->tfb_tcp_handoff_ok != NULL) {
1776 * Does the stack provide a
1777 * query mechanism, if so it may
1778 * still be possible?
1780 error = (*blk->tfb_tcp_handoff_ok)(tp);
1784 refcount_release(&blk->tfb_refcnt);
1789 if (blk->tfb_flags & TCP_FUNC_BEING_REMOVED) {
1790 refcount_release(&blk->tfb_refcnt);
1795 * Release the old refcnt, the
1796 * lookup acquired a ref on the
1799 if (tp->t_fb->tfb_tcp_fb_fini) {
1801 * Tell the stack to cleanup with 0 i.e.
1802 * the tcb is not going away.
1804 (*tp->t_fb->tfb_tcp_fb_fini)(tp, 0);
1807 /* Assure that we are not on any hpts */
1808 tcp_hpts_remove(tp->t_inpcb, HPTS_REMOVE_ALL);
1810 if (blk->tfb_tcp_fb_init) {
1811 error = (*blk->tfb_tcp_fb_init)(tp);
1813 refcount_release(&blk->tfb_refcnt);
1814 if (tp->t_fb->tfb_tcp_fb_init) {
1815 if((*tp->t_fb->tfb_tcp_fb_init)(tp) != 0) {
1816 /* Fall back failed, drop the connection */
1825 refcount_release(&tp->t_fb->tfb_refcnt);
1828 if (tp->t_flags & TF_TOE) {
1829 tcp_offload_ctloutput(tp, sopt->sopt_dir,
1836 } else if ((sopt->sopt_dir == SOPT_GET) &&
1837 (sopt->sopt_name == TCP_FUNCTION_BLK)) {
1838 strncpy(fsn.function_set_name, tp->t_fb->tfb_tcp_block_name,
1839 TCP_FUNCTION_NAME_LEN_MAX);
1840 fsn.function_set_name[TCP_FUNCTION_NAME_LEN_MAX - 1] = '\0';
1841 fsn.pcbcnt = tp->t_fb->tfb_refcnt;
1843 error = sooptcopyout(sopt, &fsn, sizeof fsn);
1846 /* Pass in the INP locked, called must unlock it */
1847 return (tp->t_fb->tfb_tcp_ctloutput(so, sopt, inp, tp));
1851 * If this assert becomes untrue, we need to change the size of the buf
1852 * variable in tcp_default_ctloutput().
1855 CTASSERT(TCP_CA_NAME_MAX <= TCP_LOG_ID_LEN);
1856 CTASSERT(TCP_LOG_REASON_LEN <= TCP_LOG_ID_LEN);
1860 tcp_default_ctloutput(struct socket *so, struct sockopt *sopt, struct inpcb *inp, struct tcpcb *tp)
1862 int error, opt, optval;
1866 struct tls_enable tls;
1868 struct cc_algo *algo;
1869 char *pbuf, buf[TCP_LOG_ID_LEN];
1871 struct statsblob *sbp;
1876 * For TCP_CCALGOOPT forward the control to CC module, for both
1877 * SOPT_SET and SOPT_GET.
1879 switch (sopt->sopt_name) {
1882 if (sopt->sopt_valsize > CC_ALGOOPT_LIMIT)
1884 pbuf = malloc(sopt->sopt_valsize, M_TEMP, M_WAITOK | M_ZERO);
1885 error = sooptcopyin(sopt, pbuf, sopt->sopt_valsize,
1886 sopt->sopt_valsize);
1891 INP_WLOCK_RECHECK_CLEANUP(inp, free(pbuf, M_TEMP));
1892 if (CC_ALGO(tp)->ctl_output != NULL)
1893 error = CC_ALGO(tp)->ctl_output(tp->ccv, sopt, pbuf);
1897 if (error == 0 && sopt->sopt_dir == SOPT_GET)
1898 error = sooptcopyout(sopt, pbuf, sopt->sopt_valsize);
1903 switch (sopt->sopt_dir) {
1905 switch (sopt->sopt_name) {
1906 #if defined(IPSEC_SUPPORT) || defined(TCP_SIGNATURE)
1908 if (!TCPMD5_ENABLED()) {
1910 return (ENOPROTOOPT);
1912 error = TCPMD5_PCBCTL(inp, sopt);
1915 goto unlock_and_done;
1921 error = sooptcopyin(sopt, &optval, sizeof optval,
1926 INP_WLOCK_RECHECK(inp);
1927 switch (sopt->sopt_name) {
1935 opt = 0; /* dead code to fool gcc */
1942 tp->t_flags &= ~opt;
1945 if (tp->t_flags & TF_TOE) {
1946 tcp_offload_ctloutput(tp, sopt->sopt_dir,
1955 error = sooptcopyin(sopt, &optval, sizeof optval,
1960 INP_WLOCK_RECHECK(inp);
1962 tp->t_flags |= TF_NOPUSH;
1963 else if (tp->t_flags & TF_NOPUSH) {
1964 tp->t_flags &= ~TF_NOPUSH;
1965 if (TCPS_HAVEESTABLISHED(tp->t_state)) {
1966 struct epoch_tracker et;
1968 NET_EPOCH_ENTER(et);
1969 error = tp->t_fb->tfb_tcp_output(tp);
1973 goto unlock_and_done;
1977 error = sooptcopyin(sopt, &optval, sizeof optval,
1982 INP_WLOCK_RECHECK(inp);
1983 if (optval > 0 && optval <= tp->t_maxseg &&
1984 optval + 40 >= V_tcp_minmss)
1985 tp->t_maxseg = optval;
1988 goto unlock_and_done;
1998 error = sooptcopyin(sopt, &optval, sizeof optval,
2004 sbp = stats_blob_alloc(
2005 V_tcp_perconn_stats_dflt_tpl, 0);
2009 INP_WLOCK_RECHECK(inp);
2010 if ((tp->t_stats != NULL && sbp == NULL) ||
2011 (tp->t_stats == NULL && sbp != NULL)) {
2012 struct statsblob *t = tp->t_stats;
2018 stats_blob_destroy(sbp);
2020 return (EOPNOTSUPP);
2024 case TCP_CONGESTION:
2026 error = sooptcopyin(sopt, buf, TCP_CA_NAME_MAX - 1, 1);
2029 buf[sopt->sopt_valsize] = '\0';
2030 INP_WLOCK_RECHECK(inp);
2032 STAILQ_FOREACH(algo, &cc_list, entries)
2033 if (strncmp(buf, algo->name,
2034 TCP_CA_NAME_MAX) == 0)
2043 * We hold a write lock over the tcb so it's safe to
2044 * do these things without ordering concerns.
2046 if (CC_ALGO(tp)->cb_destroy != NULL)
2047 CC_ALGO(tp)->cb_destroy(tp->ccv);
2051 * If something goes pear shaped initialising the new
2052 * algo, fall back to newreno (which does not
2053 * require initialisation).
2055 if (algo->cb_init != NULL &&
2056 algo->cb_init(tp->ccv) != 0) {
2057 CC_ALGO(tp) = &newreno_cc_algo;
2059 * The only reason init should fail is
2060 * because of malloc.
2068 case TCP_TXTLS_ENABLE:
2070 error = sooptcopyin(sopt, &tls, sizeof(tls),
2074 error = ktls_enable_tx(so, &tls);
2076 case TCP_TXTLS_MODE:
2078 error = sooptcopyin(sopt, &ui, sizeof(ui), sizeof(ui));
2082 INP_WLOCK_RECHECK(inp);
2083 error = ktls_set_tx_mode(so, ui);
2092 error = sooptcopyin(sopt, &ui, sizeof(ui), sizeof(ui));
2096 if (ui > (UINT_MAX / hz)) {
2102 INP_WLOCK_RECHECK(inp);
2103 switch (sopt->sopt_name) {
2105 tp->t_keepidle = ui;
2107 * XXX: better check current remaining
2108 * timeout and "merge" it with new value.
2110 if ((tp->t_state > TCPS_LISTEN) &&
2111 (tp->t_state <= TCPS_CLOSING))
2112 tcp_timer_activate(tp, TT_KEEP,
2116 tp->t_keepintvl = ui;
2117 if ((tp->t_state == TCPS_FIN_WAIT_2) &&
2118 (TP_MAXIDLE(tp) > 0))
2119 tcp_timer_activate(tp, TT_2MSL,
2123 tp->t_keepinit = ui;
2124 if (tp->t_state == TCPS_SYN_RECEIVED ||
2125 tp->t_state == TCPS_SYN_SENT)
2126 tcp_timer_activate(tp, TT_KEEP,
2130 goto unlock_and_done;
2134 error = sooptcopyin(sopt, &ui, sizeof(ui), sizeof(ui));
2138 INP_WLOCK_RECHECK(inp);
2140 if ((tp->t_state == TCPS_FIN_WAIT_2) &&
2141 (TP_MAXIDLE(tp) > 0))
2142 tcp_timer_activate(tp, TT_2MSL,
2144 goto unlock_and_done;
2150 error = sooptcopyin(sopt, &optval, sizeof optval,
2155 INP_WLOCK_RECHECK(inp);
2157 tcp_pcap_set_sock_max(TCP_PCAP_OUT ?
2158 &(tp->t_outpkts) : &(tp->t_inpkts),
2162 goto unlock_and_done;
2165 case TCP_FASTOPEN: {
2166 struct tcp_fastopen tfo_optval;
2169 if (!V_tcp_fastopen_client_enable &&
2170 !V_tcp_fastopen_server_enable)
2173 error = sooptcopyin(sopt, &tfo_optval,
2174 sizeof(tfo_optval), sizeof(int));
2178 INP_WLOCK_RECHECK(inp);
2179 if (tfo_optval.enable) {
2180 if (tp->t_state == TCPS_LISTEN) {
2181 if (!V_tcp_fastopen_server_enable) {
2183 goto unlock_and_done;
2186 tp->t_flags |= TF_FASTOPEN;
2187 if (tp->t_tfo_pending == NULL)
2189 tcp_fastopen_alloc_counter();
2192 * If a pre-shared key was provided,
2193 * stash it in the client cookie
2194 * field of the tcpcb for use during
2197 if (sopt->sopt_valsize ==
2198 sizeof(tfo_optval)) {
2199 memcpy(tp->t_tfo_cookie.client,
2201 TCP_FASTOPEN_PSK_LEN);
2202 tp->t_tfo_client_cookie_len =
2203 TCP_FASTOPEN_PSK_LEN;
2205 tp->t_flags |= TF_FASTOPEN;
2208 tp->t_flags &= ~TF_FASTOPEN;
2209 goto unlock_and_done;
2215 error = sooptcopyin(sopt, &optval, sizeof optval,
2220 INP_WLOCK_RECHECK(inp);
2221 error = tcp_log_state_change(tp, optval);
2222 goto unlock_and_done;
2231 error = sooptcopyin(sopt, buf, TCP_LOG_ID_LEN - 1, 0);
2234 buf[sopt->sopt_valsize] = '\0';
2235 INP_WLOCK_RECHECK(inp);
2236 error = tcp_log_set_id(tp, buf);
2237 /* tcp_log_set_id() unlocks the INP. */
2244 sooptcopyin(sopt, buf, TCP_LOG_REASON_LEN - 1, 0);
2247 buf[sopt->sopt_valsize] = '\0';
2248 INP_WLOCK_RECHECK(inp);
2249 if (sopt->sopt_name == TCP_LOGDUMP) {
2250 error = tcp_log_dump_tp_logbuf(tp, buf,
2254 tcp_log_dump_tp_bucket_logbufs(tp, buf);
2256 * tcp_log_dump_tp_bucket_logbufs() drops the
2265 error = ENOPROTOOPT;
2271 tp = intotcpcb(inp);
2272 switch (sopt->sopt_name) {
2273 #if defined(IPSEC_SUPPORT) || defined(TCP_SIGNATURE)
2275 if (!TCPMD5_ENABLED()) {
2277 return (ENOPROTOOPT);
2279 error = TCPMD5_PCBCTL(inp, sopt);
2284 optval = tp->t_flags & TF_NODELAY;
2286 error = sooptcopyout(sopt, &optval, sizeof optval);
2289 optval = tp->t_maxseg;
2291 error = sooptcopyout(sopt, &optval, sizeof optval);
2294 optval = tp->t_flags & TF_NOOPT;
2296 error = sooptcopyout(sopt, &optval, sizeof optval);
2299 optval = tp->t_flags & TF_NOPUSH;
2301 error = sooptcopyout(sopt, &optval, sizeof optval);
2304 tcp_fill_info(tp, &ti);
2306 error = sooptcopyout(sopt, &ti, sizeof ti);
2312 TYPEOF_MEMBER(struct statsblob, flags) sbflags = 0;
2315 socklen_t outsbsz = sopt->sopt_valsize;
2316 if (tp->t_stats == NULL)
2318 else if (outsbsz >= tp->t_stats->cursz)
2319 outsbsz = tp->t_stats->cursz;
2320 else if (outsbsz >= sizeof(struct statsblob))
2321 outsbsz = sizeof(struct statsblob);
2328 sbp = sopt->sopt_val;
2329 nheld = atop(round_page(((vm_offset_t)sbp) +
2330 (vm_size_t)outsbsz) - trunc_page((vm_offset_t)sbp));
2331 vm_page_t ma[nheld];
2332 if (vm_fault_quick_hold_pages(
2333 &curproc->p_vmspace->vm_map, (vm_offset_t)sbp,
2334 outsbsz, VM_PROT_READ | VM_PROT_WRITE, ma,
2340 if ((error = copyin_nofault(&(sbp->flags), &sbflags,
2341 SIZEOF_MEMBER(struct statsblob, flags))))
2344 INP_WLOCK_RECHECK(inp);
2345 error = stats_blob_snapshot(&sbp, outsbsz, tp->t_stats,
2346 sbflags | SB_CLONE_USRDSTNOFAULT);
2348 sopt->sopt_valsize = outsbsz;
2350 vm_page_unhold_pages(ma, nheld);
2357 case TCP_CONGESTION:
2358 len = strlcpy(buf, CC_ALGO(tp)->name, TCP_CA_NAME_MAX);
2360 error = sooptcopyout(sopt, buf, len + 1);
2366 switch (sopt->sopt_name) {
2368 ui = TP_KEEPIDLE(tp) / hz;
2371 ui = TP_KEEPINTVL(tp) / hz;
2374 ui = TP_KEEPINIT(tp) / hz;
2377 ui = TP_KEEPCNT(tp);
2381 error = sooptcopyout(sopt, &ui, sizeof(ui));
2386 optval = tcp_pcap_get_sock_max(TCP_PCAP_OUT ?
2387 &(tp->t_outpkts) : &(tp->t_inpkts));
2389 error = sooptcopyout(sopt, &optval, sizeof optval);
2393 optval = tp->t_flags & TF_FASTOPEN;
2395 error = sooptcopyout(sopt, &optval, sizeof optval);
2399 optval = tp->t_logstate;
2401 error = sooptcopyout(sopt, &optval, sizeof(optval));
2404 /* tcp_log_getlogbuf() does INP_WUNLOCK(inp) */
2405 error = tcp_log_getlogbuf(sopt, tp);
2408 len = tcp_log_get_id(tp, buf);
2410 error = sooptcopyout(sopt, buf, len + 1);
2419 case TCP_TXTLS_MODE:
2420 optval = ktls_get_tx_mode(so);
2422 error = sooptcopyout(sopt, &optval, sizeof(optval));
2427 error = ENOPROTOOPT;
2434 #undef INP_WLOCK_RECHECK
2435 #undef INP_WLOCK_RECHECK_CLEANUP
2438 * Initiate (or continue) disconnect.
2439 * If embryonic state, just send reset (once).
2440 * If in ``let data drain'' option and linger null, just drop.
2441 * Otherwise (hard), mark socket disconnecting and drop
2442 * current input data; switch states based on user close, and
2443 * send segment to peer (with FIN).
2446 tcp_disconnect(struct tcpcb *tp)
2448 struct inpcb *inp = tp->t_inpcb;
2449 struct socket *so = inp->inp_socket;
2452 INP_WLOCK_ASSERT(inp);
2455 * Neither tcp_close() nor tcp_drop() should return NULL, as the
2456 * socket is still open.
2458 if (tp->t_state < TCPS_ESTABLISHED &&
2459 !(tp->t_state > TCPS_LISTEN && IS_FASTOPEN(tp->t_flags))) {
2462 ("tcp_disconnect: tcp_close() returned NULL"));
2463 } else if ((so->so_options & SO_LINGER) && so->so_linger == 0) {
2464 tp = tcp_drop(tp, 0);
2466 ("tcp_disconnect: tcp_drop() returned NULL"));
2468 soisdisconnecting(so);
2469 sbflush(&so->so_rcv);
2471 if (!(inp->inp_flags & INP_DROPPED))
2472 tp->t_fb->tfb_tcp_output(tp);
2477 * User issued close, and wish to trail through shutdown states:
2478 * if never received SYN, just forget it. If got a SYN from peer,
2479 * but haven't sent FIN, then go to FIN_WAIT_1 state to send peer a FIN.
2480 * If already got a FIN from peer, then almost done; go to LAST_ACK
2481 * state. In all other cases, have already sent FIN to peer (e.g.
2482 * after PRU_SHUTDOWN), and just have to play tedious game waiting
2483 * for peer to send FIN or not respond to keep-alives, etc.
2484 * We can let the user exit from the close as soon as the FIN is acked.
2487 tcp_usrclosed(struct tcpcb *tp)
2491 INP_WLOCK_ASSERT(tp->t_inpcb);
2493 switch (tp->t_state) {
2496 tcp_offload_listen_stop(tp);
2498 tcp_state_change(tp, TCPS_CLOSED);
2503 * tcp_close() should never return NULL here as the socket is
2507 ("tcp_usrclosed: tcp_close() returned NULL"));
2511 case TCPS_SYN_RECEIVED:
2512 tp->t_flags |= TF_NEEDFIN;
2515 case TCPS_ESTABLISHED:
2516 tcp_state_change(tp, TCPS_FIN_WAIT_1);
2519 case TCPS_CLOSE_WAIT:
2520 tcp_state_change(tp, TCPS_LAST_ACK);
2523 if (tp->t_state >= TCPS_FIN_WAIT_2) {
2524 soisdisconnected(tp->t_inpcb->inp_socket);
2525 /* Prevent the connection hanging in FIN_WAIT_2 forever. */
2526 if (tp->t_state == TCPS_FIN_WAIT_2) {
2529 timeout = (tcp_fast_finwait2_recycle) ?
2530 tcp_finwait2_timeout : TP_MAXIDLE(tp);
2531 tcp_timer_activate(tp, TT_2MSL, timeout);
2538 db_print_indent(int indent)
2542 for (i = 0; i < indent; i++)
2547 db_print_tstate(int t_state)
2552 db_printf("TCPS_CLOSED");
2556 db_printf("TCPS_LISTEN");
2560 db_printf("TCPS_SYN_SENT");
2563 case TCPS_SYN_RECEIVED:
2564 db_printf("TCPS_SYN_RECEIVED");
2567 case TCPS_ESTABLISHED:
2568 db_printf("TCPS_ESTABLISHED");
2571 case TCPS_CLOSE_WAIT:
2572 db_printf("TCPS_CLOSE_WAIT");
2575 case TCPS_FIN_WAIT_1:
2576 db_printf("TCPS_FIN_WAIT_1");
2580 db_printf("TCPS_CLOSING");
2584 db_printf("TCPS_LAST_ACK");
2587 case TCPS_FIN_WAIT_2:
2588 db_printf("TCPS_FIN_WAIT_2");
2591 case TCPS_TIME_WAIT:
2592 db_printf("TCPS_TIME_WAIT");
2596 db_printf("unknown");
2602 db_print_tflags(u_int t_flags)
2607 if (t_flags & TF_ACKNOW) {
2608 db_printf("%sTF_ACKNOW", comma ? ", " : "");
2611 if (t_flags & TF_DELACK) {
2612 db_printf("%sTF_DELACK", comma ? ", " : "");
2615 if (t_flags & TF_NODELAY) {
2616 db_printf("%sTF_NODELAY", comma ? ", " : "");
2619 if (t_flags & TF_NOOPT) {
2620 db_printf("%sTF_NOOPT", comma ? ", " : "");
2623 if (t_flags & TF_SENTFIN) {
2624 db_printf("%sTF_SENTFIN", comma ? ", " : "");
2627 if (t_flags & TF_REQ_SCALE) {
2628 db_printf("%sTF_REQ_SCALE", comma ? ", " : "");
2631 if (t_flags & TF_RCVD_SCALE) {
2632 db_printf("%sTF_RECVD_SCALE", comma ? ", " : "");
2635 if (t_flags & TF_REQ_TSTMP) {
2636 db_printf("%sTF_REQ_TSTMP", comma ? ", " : "");
2639 if (t_flags & TF_RCVD_TSTMP) {
2640 db_printf("%sTF_RCVD_TSTMP", comma ? ", " : "");
2643 if (t_flags & TF_SACK_PERMIT) {
2644 db_printf("%sTF_SACK_PERMIT", comma ? ", " : "");
2647 if (t_flags & TF_NEEDSYN) {
2648 db_printf("%sTF_NEEDSYN", comma ? ", " : "");
2651 if (t_flags & TF_NEEDFIN) {
2652 db_printf("%sTF_NEEDFIN", comma ? ", " : "");
2655 if (t_flags & TF_NOPUSH) {
2656 db_printf("%sTF_NOPUSH", comma ? ", " : "");
2659 if (t_flags & TF_MORETOCOME) {
2660 db_printf("%sTF_MORETOCOME", comma ? ", " : "");
2663 if (t_flags & TF_LQ_OVERFLOW) {
2664 db_printf("%sTF_LQ_OVERFLOW", comma ? ", " : "");
2667 if (t_flags & TF_LASTIDLE) {
2668 db_printf("%sTF_LASTIDLE", comma ? ", " : "");
2671 if (t_flags & TF_RXWIN0SENT) {
2672 db_printf("%sTF_RXWIN0SENT", comma ? ", " : "");
2675 if (t_flags & TF_FASTRECOVERY) {
2676 db_printf("%sTF_FASTRECOVERY", comma ? ", " : "");
2679 if (t_flags & TF_CONGRECOVERY) {
2680 db_printf("%sTF_CONGRECOVERY", comma ? ", " : "");
2683 if (t_flags & TF_WASFRECOVERY) {
2684 db_printf("%sTF_WASFRECOVERY", comma ? ", " : "");
2687 if (t_flags & TF_SIGNATURE) {
2688 db_printf("%sTF_SIGNATURE", comma ? ", " : "");
2691 if (t_flags & TF_FORCEDATA) {
2692 db_printf("%sTF_FORCEDATA", comma ? ", " : "");
2695 if (t_flags & TF_TSO) {
2696 db_printf("%sTF_TSO", comma ? ", " : "");
2699 if (t_flags & TF_FASTOPEN) {
2700 db_printf("%sTF_FASTOPEN", comma ? ", " : "");
2706 db_print_tflags2(u_int t_flags2)
2711 if (t_flags2 & TF2_ECN_PERMIT) {
2712 db_printf("%sTF2_ECN_PERMIT", comma ? ", " : "");
2719 db_print_toobflags(char t_oobflags)
2724 if (t_oobflags & TCPOOB_HAVEDATA) {
2725 db_printf("%sTCPOOB_HAVEDATA", comma ? ", " : "");
2728 if (t_oobflags & TCPOOB_HADDATA) {
2729 db_printf("%sTCPOOB_HADDATA", comma ? ", " : "");
2735 db_print_tcpcb(struct tcpcb *tp, const char *name, int indent)
2738 db_print_indent(indent);
2739 db_printf("%s at %p\n", name, tp);
2743 db_print_indent(indent);
2744 db_printf("t_segq first: %p t_segqlen: %d t_dupacks: %d\n",
2745 TAILQ_FIRST(&tp->t_segq), tp->t_segqlen, tp->t_dupacks);
2747 db_print_indent(indent);
2748 db_printf("tt_rexmt: %p tt_persist: %p tt_keep: %p\n",
2749 &tp->t_timers->tt_rexmt, &tp->t_timers->tt_persist, &tp->t_timers->tt_keep);
2751 db_print_indent(indent);
2752 db_printf("tt_2msl: %p tt_delack: %p t_inpcb: %p\n", &tp->t_timers->tt_2msl,
2753 &tp->t_timers->tt_delack, tp->t_inpcb);
2755 db_print_indent(indent);
2756 db_printf("t_state: %d (", tp->t_state);
2757 db_print_tstate(tp->t_state);
2760 db_print_indent(indent);
2761 db_printf("t_flags: 0x%x (", tp->t_flags);
2762 db_print_tflags(tp->t_flags);
2765 db_print_indent(indent);
2766 db_printf("t_flags2: 0x%x (", tp->t_flags2);
2767 db_print_tflags2(tp->t_flags2);
2770 db_print_indent(indent);
2771 db_printf("snd_una: 0x%08x snd_max: 0x%08x snd_nxt: x0%08x\n",
2772 tp->snd_una, tp->snd_max, tp->snd_nxt);
2774 db_print_indent(indent);
2775 db_printf("snd_up: 0x%08x snd_wl1: 0x%08x snd_wl2: 0x%08x\n",
2776 tp->snd_up, tp->snd_wl1, tp->snd_wl2);
2778 db_print_indent(indent);
2779 db_printf("iss: 0x%08x irs: 0x%08x rcv_nxt: 0x%08x\n",
2780 tp->iss, tp->irs, tp->rcv_nxt);
2782 db_print_indent(indent);
2783 db_printf("rcv_adv: 0x%08x rcv_wnd: %u rcv_up: 0x%08x\n",
2784 tp->rcv_adv, tp->rcv_wnd, tp->rcv_up);
2786 db_print_indent(indent);
2787 db_printf("snd_wnd: %u snd_cwnd: %u\n",
2788 tp->snd_wnd, tp->snd_cwnd);
2790 db_print_indent(indent);
2791 db_printf("snd_ssthresh: %u snd_recover: "
2792 "0x%08x\n", tp->snd_ssthresh, tp->snd_recover);
2794 db_print_indent(indent);
2795 db_printf("t_rcvtime: %u t_startime: %u\n",
2796 tp->t_rcvtime, tp->t_starttime);
2798 db_print_indent(indent);
2799 db_printf("t_rttime: %u t_rtsq: 0x%08x\n",
2800 tp->t_rtttime, tp->t_rtseq);
2802 db_print_indent(indent);
2803 db_printf("t_rxtcur: %d t_maxseg: %u t_srtt: %d\n",
2804 tp->t_rxtcur, tp->t_maxseg, tp->t_srtt);
2806 db_print_indent(indent);
2807 db_printf("t_rttvar: %d t_rxtshift: %d t_rttmin: %u "
2808 "t_rttbest: %u\n", tp->t_rttvar, tp->t_rxtshift, tp->t_rttmin,
2811 db_print_indent(indent);
2812 db_printf("t_rttupdated: %lu max_sndwnd: %u t_softerror: %d\n",
2813 tp->t_rttupdated, tp->max_sndwnd, tp->t_softerror);
2815 db_print_indent(indent);
2816 db_printf("t_oobflags: 0x%x (", tp->t_oobflags);
2817 db_print_toobflags(tp->t_oobflags);
2818 db_printf(") t_iobc: 0x%02x\n", tp->t_iobc);
2820 db_print_indent(indent);
2821 db_printf("snd_scale: %u rcv_scale: %u request_r_scale: %u\n",
2822 tp->snd_scale, tp->rcv_scale, tp->request_r_scale);
2824 db_print_indent(indent);
2825 db_printf("ts_recent: %u ts_recent_age: %u\n",
2826 tp->ts_recent, tp->ts_recent_age);
2828 db_print_indent(indent);
2829 db_printf("ts_offset: %u last_ack_sent: 0x%08x snd_cwnd_prev: "
2830 "%u\n", tp->ts_offset, tp->last_ack_sent, tp->snd_cwnd_prev);
2832 db_print_indent(indent);
2833 db_printf("snd_ssthresh_prev: %u snd_recover_prev: 0x%08x "
2834 "t_badrxtwin: %u\n", tp->snd_ssthresh_prev,
2835 tp->snd_recover_prev, tp->t_badrxtwin);
2837 db_print_indent(indent);
2838 db_printf("snd_numholes: %d snd_holes first: %p\n",
2839 tp->snd_numholes, TAILQ_FIRST(&tp->snd_holes));
2841 db_print_indent(indent);
2842 db_printf("snd_fack: 0x%08x rcv_numsacks: %d sack_newdata: "
2843 "0x%08x\n", tp->snd_fack, tp->rcv_numsacks, tp->sack_newdata);
2845 /* Skip sackblks, sackhint. */
2847 db_print_indent(indent);
2848 db_printf("t_rttlow: %d rfbuf_ts: %u rfbuf_cnt: %d\n",
2849 tp->t_rttlow, tp->rfbuf_ts, tp->rfbuf_cnt);
2852 DB_SHOW_COMMAND(tcpcb, db_show_tcpcb)
2857 db_printf("usage: show tcpcb <addr>\n");
2860 tp = (struct tcpcb *)addr;
2862 db_print_tcpcb(tp, "tcpcb", 0);