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 attaches to socket via pru_attach(), reserving space,
138 * and an internet control block.
141 tcp_usr_attach(struct socket *so, int proto, struct thread *td)
144 struct tcpcb *tp = NULL;
149 KASSERT(inp == NULL, ("tcp_usr_attach: inp != NULL"));
152 error = tcp_attach(so);
156 if ((so->so_options & SO_LINGER) && so->so_linger == 0)
157 so->so_linger = TCP_LINGERTIME;
162 TCPDEBUG2(PRU_ATTACH);
163 TCP_PROBE2(debug__user, tp, PRU_ATTACH);
168 * tcp_detach is called when the socket layer loses its final reference
169 * to the socket, be it a file descriptor reference, a reference from TCP,
170 * etc. At this point, there is only one case in which we will keep around
171 * inpcb state: time wait.
173 * This function can probably be re-absorbed back into tcp_usr_detach() now
174 * that there is a single detach path.
177 tcp_detach(struct socket *so, struct inpcb *inp)
181 INP_INFO_LOCK_ASSERT(&V_tcbinfo);
182 INP_WLOCK_ASSERT(inp);
184 KASSERT(so->so_pcb == inp, ("tcp_detach: so_pcb != inp"));
185 KASSERT(inp->inp_socket == so, ("tcp_detach: inp_socket != so"));
189 if (inp->inp_flags & INP_TIMEWAIT) {
191 * There are two cases to handle: one in which the time wait
192 * state is being discarded (INP_DROPPED), and one in which
193 * this connection will remain in timewait. In the former,
194 * it is time to discard all state (except tcptw, which has
195 * already been discarded by the timewait close code, which
196 * should be further up the call stack somewhere). In the
197 * latter case, we detach from the socket, but leave the pcb
198 * present until timewait ends.
200 * XXXRW: Would it be cleaner to free the tcptw here?
202 * Astute question indeed, from twtcp perspective there are
203 * four cases to consider:
205 * #1 tcp_detach is called at tcptw creation time by
206 * tcp_twstart, then do not discard the newly created tcptw
207 * and leave inpcb present until timewait ends
208 * #2 tcp_detach is called at tcptw creation time by
209 * tcp_twstart, but connection is local and tw will be
210 * discarded immediately
211 * #3 tcp_detach is called at timewait end (or reuse) by
212 * tcp_twclose, then the tcptw has already been discarded
213 * (or reused) and inpcb is freed here
214 * #4 tcp_detach is called() after timewait ends (or reuse)
215 * (e.g. by soclose), then tcptw has already been discarded
216 * (or reused) and inpcb is freed here
218 * In all three cases the tcptw should not be freed here.
220 if (inp->inp_flags & INP_DROPPED) {
222 if (__predict_true(tp == NULL)) {
226 * This case should not happen as in TIMEWAIT
227 * state the inp should not be destroyed before
228 * its tcptw. If INVARIANTS is defined, panic.
231 panic("%s: Panic before an inp double-free: "
232 "INP_TIMEWAIT && INP_DROPPED && tp != NULL"
235 log(LOG_ERR, "%s: Avoid an inp double-free: "
236 "INP_TIMEWAIT && INP_DROPPED && tp != NULL"
247 * If the connection is not in timewait, we consider two
248 * two conditions: one in which no further processing is
249 * necessary (dropped || embryonic), and one in which TCP is
250 * not yet done, but no longer requires the socket, so the
251 * pcb will persist for the time being.
253 * XXXRW: Does the second case still occur?
255 if (inp->inp_flags & INP_DROPPED ||
256 tp->t_state < TCPS_SYN_SENT) {
268 * pru_detach() detaches the TCP protocol from the socket.
269 * If the protocol state is non-embryonic, then can't
270 * do this directly: have to initiate a pru_disconnect(),
271 * which may finish later; embryonic TCB's can just
275 tcp_usr_detach(struct socket *so)
279 struct epoch_tracker et;
282 KASSERT(inp != NULL, ("tcp_usr_detach: inp == NULL"));
283 if (!INP_INFO_WLOCKED(&V_tcbinfo)) {
284 INP_INFO_RLOCK_ET(&V_tcbinfo, et);
288 KASSERT(inp->inp_socket != NULL,
289 ("tcp_usr_detach: inp_socket == NULL"));
292 INP_INFO_RUNLOCK_ET(&V_tcbinfo, et);
297 * Give the socket an address.
300 tcp_usr_bind(struct socket *so, struct sockaddr *nam, struct thread *td)
304 struct tcpcb *tp = NULL;
305 struct sockaddr_in *sinp;
307 sinp = (struct sockaddr_in *)nam;
308 if (nam->sa_len != sizeof (*sinp))
311 * Must check for multicast addresses and disallow binding
314 if (sinp->sin_family == AF_INET &&
315 IN_MULTICAST(ntohl(sinp->sin_addr.s_addr)))
316 return (EAFNOSUPPORT);
320 KASSERT(inp != NULL, ("tcp_usr_bind: inp == NULL"));
322 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
328 INP_HASH_WLOCK(&V_tcbinfo);
329 error = in_pcbbind(inp, nam, td->td_ucred);
330 INP_HASH_WUNLOCK(&V_tcbinfo);
333 TCP_PROBE2(debug__user, tp, PRU_BIND);
342 tcp6_usr_bind(struct socket *so, struct sockaddr *nam, struct thread *td)
346 struct tcpcb *tp = NULL;
347 struct sockaddr_in6 *sin6;
349 sin6 = (struct sockaddr_in6 *)nam;
350 if (nam->sa_len != sizeof (*sin6))
353 * Must check for multicast addresses and disallow binding
356 if (sin6->sin6_family == AF_INET6 &&
357 IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr))
358 return (EAFNOSUPPORT);
362 KASSERT(inp != NULL, ("tcp6_usr_bind: inp == NULL"));
364 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
370 INP_HASH_WLOCK(&V_tcbinfo);
371 inp->inp_vflag &= ~INP_IPV4;
372 inp->inp_vflag |= INP_IPV6;
374 if ((inp->inp_flags & IN6P_IPV6_V6ONLY) == 0) {
375 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr))
376 inp->inp_vflag |= INP_IPV4;
377 else if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
378 struct sockaddr_in sin;
380 in6_sin6_2_sin(&sin, sin6);
381 if (IN_MULTICAST(ntohl(sin.sin_addr.s_addr))) {
382 error = EAFNOSUPPORT;
383 INP_HASH_WUNLOCK(&V_tcbinfo);
386 inp->inp_vflag |= INP_IPV4;
387 inp->inp_vflag &= ~INP_IPV6;
388 error = in_pcbbind(inp, (struct sockaddr *)&sin,
390 INP_HASH_WUNLOCK(&V_tcbinfo);
395 error = in6_pcbbind(inp, nam, td->td_ucred);
396 INP_HASH_WUNLOCK(&V_tcbinfo);
399 TCP_PROBE2(debug__user, tp, PRU_BIND);
407 * Prepare to accept connections.
410 tcp_usr_listen(struct socket *so, int backlog, struct thread *td)
414 struct tcpcb *tp = NULL;
418 KASSERT(inp != NULL, ("tcp_usr_listen: inp == NULL"));
420 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
427 error = solisten_proto_check(so);
428 INP_HASH_WLOCK(&V_tcbinfo);
429 if (error == 0 && inp->inp_lport == 0)
430 error = in_pcbbind(inp, (struct sockaddr *)0, td->td_ucred);
431 INP_HASH_WUNLOCK(&V_tcbinfo);
433 tcp_state_change(tp, TCPS_LISTEN);
434 solisten_proto(so, backlog);
436 if ((so->so_options & SO_NO_OFFLOAD) == 0)
437 tcp_offload_listen_start(tp);
442 if (IS_FASTOPEN(tp->t_flags))
443 tp->t_tfo_pending = tcp_fastopen_alloc_counter();
446 TCPDEBUG2(PRU_LISTEN);
447 TCP_PROBE2(debug__user, tp, PRU_LISTEN);
455 tcp6_usr_listen(struct socket *so, int backlog, struct thread *td)
459 struct tcpcb *tp = NULL;
463 KASSERT(inp != NULL, ("tcp6_usr_listen: inp == NULL"));
465 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
472 error = solisten_proto_check(so);
473 INP_HASH_WLOCK(&V_tcbinfo);
474 if (error == 0 && inp->inp_lport == 0) {
475 inp->inp_vflag &= ~INP_IPV4;
476 if ((inp->inp_flags & IN6P_IPV6_V6ONLY) == 0)
477 inp->inp_vflag |= INP_IPV4;
478 error = in6_pcbbind(inp, (struct sockaddr *)0, td->td_ucred);
480 INP_HASH_WUNLOCK(&V_tcbinfo);
482 tcp_state_change(tp, TCPS_LISTEN);
483 solisten_proto(so, backlog);
485 if ((so->so_options & SO_NO_OFFLOAD) == 0)
486 tcp_offload_listen_start(tp);
491 if (IS_FASTOPEN(tp->t_flags))
492 tp->t_tfo_pending = tcp_fastopen_alloc_counter();
495 TCPDEBUG2(PRU_LISTEN);
496 TCP_PROBE2(debug__user, tp, PRU_LISTEN);
504 * Initiate connection to peer.
505 * Create a template for use in transmissions on this connection.
506 * Enter SYN_SENT state, and mark socket as connecting.
507 * Start keep-alive timer, and seed output sequence space.
508 * Send initial segment on connection.
511 tcp_usr_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
515 struct tcpcb *tp = NULL;
516 struct sockaddr_in *sinp;
518 sinp = (struct sockaddr_in *)nam;
519 if (nam->sa_len != sizeof (*sinp))
522 * Must disallow TCP ``connections'' to multicast addresses.
524 if (sinp->sin_family == AF_INET
525 && IN_MULTICAST(ntohl(sinp->sin_addr.s_addr)))
526 return (EAFNOSUPPORT);
527 if ((error = prison_remote_ip4(td->td_ucred, &sinp->sin_addr)) != 0)
532 KASSERT(inp != NULL, ("tcp_usr_connect: inp == NULL"));
534 if (inp->inp_flags & INP_TIMEWAIT) {
538 if (inp->inp_flags & INP_DROPPED) {
539 error = ECONNREFUSED;
544 if ((error = tcp_connect(tp, nam, td)) != 0)
547 if (registered_toedevs > 0 &&
548 (so->so_options & SO_NO_OFFLOAD) == 0 &&
549 (error = tcp_offload_connect(so, nam)) == 0)
552 tcp_timer_activate(tp, TT_KEEP, TP_KEEPINIT(tp));
553 error = tp->t_fb->tfb_tcp_output(tp);
555 TCPDEBUG2(PRU_CONNECT);
556 TCP_PROBE2(debug__user, tp, PRU_CONNECT);
564 tcp6_usr_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
568 struct tcpcb *tp = NULL;
569 struct sockaddr_in6 *sin6;
573 sin6 = (struct sockaddr_in6 *)nam;
574 if (nam->sa_len != sizeof (*sin6))
577 * Must disallow TCP ``connections'' to multicast addresses.
579 if (sin6->sin6_family == AF_INET6
580 && IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr))
581 return (EAFNOSUPPORT);
584 KASSERT(inp != NULL, ("tcp6_usr_connect: inp == NULL"));
586 if (inp->inp_flags & INP_TIMEWAIT) {
590 if (inp->inp_flags & INP_DROPPED) {
591 error = ECONNREFUSED;
598 * XXXRW: Some confusion: V4/V6 flags relate to binding, and
599 * therefore probably require the hash lock, which isn't held here.
600 * Is this a significant problem?
602 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
603 struct sockaddr_in sin;
605 if ((inp->inp_flags & IN6P_IPV6_V6ONLY) != 0) {
609 if ((inp->inp_vflag & INP_IPV4) == 0) {
610 error = EAFNOSUPPORT;
614 in6_sin6_2_sin(&sin, sin6);
615 if (IN_MULTICAST(ntohl(sin.sin_addr.s_addr))) {
616 error = EAFNOSUPPORT;
619 inp->inp_vflag |= INP_IPV4;
620 inp->inp_vflag &= ~INP_IPV6;
621 if ((error = prison_remote_ip4(td->td_ucred,
622 &sin.sin_addr)) != 0)
624 if ((error = tcp_connect(tp, (struct sockaddr *)&sin, td)) != 0)
627 if (registered_toedevs > 0 &&
628 (so->so_options & SO_NO_OFFLOAD) == 0 &&
629 (error = tcp_offload_connect(so, nam)) == 0)
632 error = tp->t_fb->tfb_tcp_output(tp);
635 if ((inp->inp_vflag & INP_IPV6) == 0) {
636 error = EAFNOSUPPORT;
641 inp->inp_vflag &= ~INP_IPV4;
642 inp->inp_vflag |= INP_IPV6;
643 inp->inp_inc.inc_flags |= INC_ISIPV6;
644 if ((error = prison_remote_ip6(td->td_ucred, &sin6->sin6_addr)) != 0)
646 if ((error = tcp6_connect(tp, nam, td)) != 0)
649 if (registered_toedevs > 0 &&
650 (so->so_options & SO_NO_OFFLOAD) == 0 &&
651 (error = tcp_offload_connect(so, nam)) == 0)
654 tcp_timer_activate(tp, TT_KEEP, TP_KEEPINIT(tp));
655 error = tp->t_fb->tfb_tcp_output(tp);
658 TCPDEBUG2(PRU_CONNECT);
659 TCP_PROBE2(debug__user, tp, PRU_CONNECT);
666 * Initiate disconnect from peer.
667 * If connection never passed embryonic stage, just drop;
668 * else if don't need to let data drain, then can just drop anyways,
669 * else have to begin TCP shutdown process: mark socket disconnecting,
670 * drain unread data, state switch to reflect user close, and
671 * send segment (e.g. FIN) to peer. Socket will be really disconnected
672 * when peer sends FIN and acks ours.
674 * SHOULD IMPLEMENT LATER PRU_CONNECT VIA REALLOC TCPCB.
677 tcp_usr_disconnect(struct socket *so)
680 struct tcpcb *tp = NULL;
681 struct epoch_tracker et;
685 INP_INFO_RLOCK_ET(&V_tcbinfo, et);
687 KASSERT(inp != NULL, ("tcp_usr_disconnect: inp == NULL"));
689 if (inp->inp_flags & INP_TIMEWAIT)
691 if (inp->inp_flags & INP_DROPPED) {
699 TCPDEBUG2(PRU_DISCONNECT);
700 TCP_PROBE2(debug__user, tp, PRU_DISCONNECT);
702 INP_INFO_RUNLOCK_ET(&V_tcbinfo, et);
708 * Accept a connection. Essentially all the work is done at higher levels;
709 * just return the address of the peer, storing through addr.
712 tcp_usr_accept(struct socket *so, struct sockaddr **nam)
715 struct inpcb *inp = NULL;
716 struct tcpcb *tp = NULL;
721 if (so->so_state & SS_ISDISCONNECTED)
722 return (ECONNABORTED);
725 KASSERT(inp != NULL, ("tcp_usr_accept: inp == NULL"));
727 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
728 error = ECONNABORTED;
735 * We inline in_getpeeraddr and COMMON_END here, so that we can
736 * copy the data of interest and defer the malloc until after we
739 port = inp->inp_fport;
740 addr = inp->inp_faddr;
743 TCPDEBUG2(PRU_ACCEPT);
744 TCP_PROBE2(debug__user, tp, PRU_ACCEPT);
747 *nam = in_sockaddr(port, &addr);
754 tcp6_usr_accept(struct socket *so, struct sockaddr **nam)
756 struct inpcb *inp = NULL;
758 struct tcpcb *tp = NULL;
760 struct in6_addr addr6;
761 struct epoch_tracker et;
766 if (so->so_state & SS_ISDISCONNECTED)
767 return (ECONNABORTED);
770 KASSERT(inp != NULL, ("tcp6_usr_accept: inp == NULL"));
771 INP_INFO_RLOCK_ET(&V_tcbinfo, et);
773 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
774 error = ECONNABORTED;
781 * We inline in6_mapped_peeraddr and COMMON_END here, so that we can
782 * copy the data of interest and defer the malloc until after we
785 if (inp->inp_vflag & INP_IPV4) {
787 port = inp->inp_fport;
788 addr = inp->inp_faddr;
790 port = inp->inp_fport;
791 addr6 = inp->in6p_faddr;
795 TCPDEBUG2(PRU_ACCEPT);
796 TCP_PROBE2(debug__user, tp, PRU_ACCEPT);
798 INP_INFO_RUNLOCK_ET(&V_tcbinfo, et);
801 *nam = in6_v4mapsin6_sockaddr(port, &addr);
803 *nam = in6_sockaddr(port, &addr6);
810 * Mark the connection as being incapable of further output.
813 tcp_usr_shutdown(struct socket *so)
817 struct tcpcb *tp = NULL;
818 struct epoch_tracker et;
821 INP_INFO_RLOCK_ET(&V_tcbinfo, et);
823 KASSERT(inp != NULL, ("inp == NULL"));
825 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
833 if (!(inp->inp_flags & INP_DROPPED))
834 error = tp->t_fb->tfb_tcp_output(tp);
837 TCPDEBUG2(PRU_SHUTDOWN);
838 TCP_PROBE2(debug__user, tp, PRU_SHUTDOWN);
840 INP_INFO_RUNLOCK_ET(&V_tcbinfo, et);
846 * After a receive, possibly send window update to peer.
849 tcp_usr_rcvd(struct socket *so, int flags)
852 struct tcpcb *tp = NULL;
857 KASSERT(inp != NULL, ("tcp_usr_rcvd: inp == NULL"));
859 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
866 * For passively-created TFO connections, don't attempt a window
867 * update while still in SYN_RECEIVED as this may trigger an early
868 * SYN|ACK. It is preferable to have the SYN|ACK be sent along with
869 * application response data, or failing that, when the DELACK timer
872 if (IS_FASTOPEN(tp->t_flags) &&
873 (tp->t_state == TCPS_SYN_RECEIVED))
876 if (tp->t_flags & TF_TOE)
877 tcp_offload_rcvd(tp);
880 tp->t_fb->tfb_tcp_output(tp);
884 TCP_PROBE2(debug__user, tp, PRU_RCVD);
890 * Do a send by putting data in output queue and updating urgent
891 * marker if URG set. Possibly send more data. Unlike the other
892 * pru_*() routines, the mbuf chains are our responsibility. We
893 * must either enqueue them or free them. The other pru_* routines
894 * generally are caller-frees.
897 tcp_usr_send(struct socket *so, int flags, struct mbuf *m,
898 struct sockaddr *nam, struct mbuf *control, struct thread *td)
902 struct tcpcb *tp = NULL;
903 struct epoch_tracker net_et;
906 struct sockaddr_in sin;
908 struct sockaddr_in *sinp;
916 * We require the pcbinfo lock if we will close the socket as part of
919 if (flags & PRUS_EOF)
920 INP_INFO_RLOCK_ET(&V_tcbinfo, net_et);
922 KASSERT(inp != NULL, ("tcp_usr_send: inp == NULL"));
924 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
928 * In case of PRUS_NOTREADY, tcp_usr_ready() is responsible
929 * for freeing memory.
931 if (m && (flags & PRUS_NOTREADY) == 0)
938 if (nam != NULL && tp->t_state < TCPS_SYN_SENT) {
939 switch (nam->sa_family) {
942 sinp = (struct sockaddr_in *)nam;
943 if (sinp->sin_len != sizeof(struct sockaddr_in)) {
949 if ((inp->inp_vflag & INP_IPV6) != 0) {
952 error = EAFNOSUPPORT;
955 if (IN_MULTICAST(ntohl(sinp->sin_addr.s_addr))) {
958 error = EAFNOSUPPORT;
961 if ((error = prison_remote_ip4(td->td_ucred,
975 struct sockaddr_in6 *sin6;
977 sin6 = (struct sockaddr_in6 *)nam;
978 if (sin6->sin6_len != sizeof(*sin6)) {
984 if (IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr)) {
987 error = EAFNOSUPPORT;
990 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
992 if ((inp->inp_flags & IN6P_IPV6_V6ONLY) != 0) {
998 if ((inp->inp_vflag & INP_IPV4) == 0) {
999 error = EAFNOSUPPORT;
1004 inp->inp_vflag &= ~INP_IPV6;
1006 in6_sin6_2_sin(sinp, sin6);
1008 ntohl(sinp->sin_addr.s_addr))) {
1009 error = EAFNOSUPPORT;
1014 if ((error = prison_remote_ip4(td->td_ucred,
1015 &sinp->sin_addr))) {
1022 error = EAFNOSUPPORT;
1028 if ((inp->inp_vflag & INP_IPV6) == 0) {
1031 error = EAFNOSUPPORT;
1034 inp->inp_vflag &= ~INP_IPV4;
1035 inp->inp_inc.inc_flags |= INC_ISIPV6;
1036 if ((error = prison_remote_ip6(td->td_ucred,
1037 &sin6->sin6_addr))) {
1050 error = EAFNOSUPPORT;
1055 /* TCP doesn't do control messages (rights, creds, etc) */
1056 if (control->m_len) {
1063 m_freem(control); /* empty control, just free it */
1065 if (!(flags & PRUS_OOB)) {
1066 sbappendstream(&so->so_snd, m, flags);
1067 if (nam && tp->t_state < TCPS_SYN_SENT) {
1069 * Do implied connect if not yet connected,
1070 * initialize window to default value, and
1071 * initialize maxseg using peer's cached MSS.
1075 error = tcp6_connect(tp, nam, td);
1077 #if defined(INET6) && defined(INET)
1081 error = tcp_connect(tp,
1082 (struct sockaddr *)sinp, td);
1086 if (IS_FASTOPEN(tp->t_flags))
1087 tcp_fastopen_connect(tp);
1089 tp->snd_wnd = TTCP_CLIENT_SND_WND;
1093 if (flags & PRUS_EOF) {
1095 * Close the send side of the connection after
1098 INP_INFO_RLOCK_ASSERT(&V_tcbinfo);
1102 if (!(inp->inp_flags & INP_DROPPED) &&
1103 !(flags & PRUS_NOTREADY)) {
1104 if (flags & PRUS_MORETOCOME)
1105 tp->t_flags |= TF_MORETOCOME;
1106 error = tp->t_fb->tfb_tcp_output(tp);
1107 if (flags & PRUS_MORETOCOME)
1108 tp->t_flags &= ~TF_MORETOCOME;
1112 * XXXRW: PRUS_EOF not implemented with PRUS_OOB?
1114 SOCKBUF_LOCK(&so->so_snd);
1115 if (sbspace(&so->so_snd) < -512) {
1116 SOCKBUF_UNLOCK(&so->so_snd);
1122 * According to RFC961 (Assigned Protocols),
1123 * the urgent pointer points to the last octet
1124 * of urgent data. We continue, however,
1125 * to consider it to indicate the first octet
1126 * of data past the urgent section.
1127 * Otherwise, snd_up should be one lower.
1129 sbappendstream_locked(&so->so_snd, m, flags);
1130 SOCKBUF_UNLOCK(&so->so_snd);
1131 if (nam && tp->t_state < TCPS_SYN_SENT) {
1133 * Do implied connect if not yet connected,
1134 * initialize window to default value, and
1135 * initialize maxseg using peer's cached MSS.
1139 * Not going to contemplate SYN|URG
1141 if (IS_FASTOPEN(tp->t_flags))
1142 tp->t_flags &= ~TF_FASTOPEN;
1145 error = tcp6_connect(tp, nam, td);
1147 #if defined(INET6) && defined(INET)
1151 error = tcp_connect(tp,
1152 (struct sockaddr *)sinp, td);
1156 tp->snd_wnd = TTCP_CLIENT_SND_WND;
1159 tp->snd_up = tp->snd_una + sbavail(&so->so_snd);
1160 if (!(flags & PRUS_NOTREADY)) {
1161 tp->t_flags |= TF_FORCEDATA;
1162 error = tp->t_fb->tfb_tcp_output(tp);
1163 tp->t_flags &= ~TF_FORCEDATA;
1166 TCP_LOG_EVENT(tp, NULL,
1167 &inp->inp_socket->so_rcv,
1168 &inp->inp_socket->so_snd,
1169 TCP_LOG_USERSEND, error,
1172 TCPDEBUG2((flags & PRUS_OOB) ? PRU_SENDOOB :
1173 ((flags & PRUS_EOF) ? PRU_SEND_EOF : PRU_SEND));
1174 TCP_PROBE2(debug__user, tp, (flags & PRUS_OOB) ? PRU_SENDOOB :
1175 ((flags & PRUS_EOF) ? PRU_SEND_EOF : PRU_SEND));
1177 if (flags & PRUS_EOF)
1178 INP_INFO_RUNLOCK_ET(&V_tcbinfo, net_et);
1183 tcp_usr_ready(struct socket *so, struct mbuf *m, int count)
1189 inp = sotoinpcb(so);
1191 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
1193 mb_free_notready(m, count);
1194 return (ECONNRESET);
1196 tp = intotcpcb(inp);
1198 SOCKBUF_LOCK(&so->so_snd);
1199 error = sbready(&so->so_snd, m, count);
1200 SOCKBUF_UNLOCK(&so->so_snd);
1202 error = tp->t_fb->tfb_tcp_output(tp);
1209 * Abort the TCP. Drop the connection abruptly.
1212 tcp_usr_abort(struct socket *so)
1215 struct tcpcb *tp = NULL;
1216 struct epoch_tracker et;
1219 inp = sotoinpcb(so);
1220 KASSERT(inp != NULL, ("tcp_usr_abort: inp == NULL"));
1222 INP_INFO_RLOCK_ET(&V_tcbinfo, et);
1224 KASSERT(inp->inp_socket != NULL,
1225 ("tcp_usr_abort: inp_socket == NULL"));
1228 * If we still have full TCP state, and we're not dropped, drop.
1230 if (!(inp->inp_flags & INP_TIMEWAIT) &&
1231 !(inp->inp_flags & INP_DROPPED)) {
1232 tp = intotcpcb(inp);
1234 tp = tcp_drop(tp, ECONNABORTED);
1237 TCPDEBUG2(PRU_ABORT);
1238 TCP_PROBE2(debug__user, tp, PRU_ABORT);
1240 if (!(inp->inp_flags & INP_DROPPED)) {
1242 so->so_state |= SS_PROTOREF;
1244 inp->inp_flags |= INP_SOCKREF;
1248 INP_INFO_RUNLOCK_ET(&V_tcbinfo, et);
1252 * TCP socket is closed. Start friendly disconnect.
1255 tcp_usr_close(struct socket *so)
1258 struct tcpcb *tp = NULL;
1259 struct epoch_tracker et;
1262 inp = sotoinpcb(so);
1263 KASSERT(inp != NULL, ("tcp_usr_close: inp == NULL"));
1265 INP_INFO_RLOCK_ET(&V_tcbinfo, et);
1267 KASSERT(inp->inp_socket != NULL,
1268 ("tcp_usr_close: inp_socket == NULL"));
1271 * If we still have full TCP state, and we're not dropped, initiate
1274 if (!(inp->inp_flags & INP_TIMEWAIT) &&
1275 !(inp->inp_flags & INP_DROPPED)) {
1276 tp = intotcpcb(inp);
1279 TCPDEBUG2(PRU_CLOSE);
1280 TCP_PROBE2(debug__user, tp, PRU_CLOSE);
1282 if (!(inp->inp_flags & INP_DROPPED)) {
1284 so->so_state |= SS_PROTOREF;
1286 inp->inp_flags |= INP_SOCKREF;
1289 INP_INFO_RUNLOCK_ET(&V_tcbinfo, et);
1293 * Receive out-of-band data.
1296 tcp_usr_rcvoob(struct socket *so, struct mbuf *m, int flags)
1300 struct tcpcb *tp = NULL;
1303 inp = sotoinpcb(so);
1304 KASSERT(inp != NULL, ("tcp_usr_rcvoob: inp == NULL"));
1306 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
1310 tp = intotcpcb(inp);
1312 if ((so->so_oobmark == 0 &&
1313 (so->so_rcv.sb_state & SBS_RCVATMARK) == 0) ||
1314 so->so_options & SO_OOBINLINE ||
1315 tp->t_oobflags & TCPOOB_HADDATA) {
1319 if ((tp->t_oobflags & TCPOOB_HAVEDATA) == 0) {
1320 error = EWOULDBLOCK;
1324 *mtod(m, caddr_t) = tp->t_iobc;
1325 if ((flags & MSG_PEEK) == 0)
1326 tp->t_oobflags ^= (TCPOOB_HAVEDATA | TCPOOB_HADDATA);
1329 TCPDEBUG2(PRU_RCVOOB);
1330 TCP_PROBE2(debug__user, tp, PRU_RCVOOB);
1336 struct pr_usrreqs tcp_usrreqs = {
1337 .pru_abort = tcp_usr_abort,
1338 .pru_accept = tcp_usr_accept,
1339 .pru_attach = tcp_usr_attach,
1340 .pru_bind = tcp_usr_bind,
1341 .pru_connect = tcp_usr_connect,
1342 .pru_control = in_control,
1343 .pru_detach = tcp_usr_detach,
1344 .pru_disconnect = tcp_usr_disconnect,
1345 .pru_listen = tcp_usr_listen,
1346 .pru_peeraddr = in_getpeeraddr,
1347 .pru_rcvd = tcp_usr_rcvd,
1348 .pru_rcvoob = tcp_usr_rcvoob,
1349 .pru_send = tcp_usr_send,
1350 .pru_ready = tcp_usr_ready,
1351 .pru_shutdown = tcp_usr_shutdown,
1352 .pru_sockaddr = in_getsockaddr,
1353 .pru_sosetlabel = in_pcbsosetlabel,
1354 .pru_close = tcp_usr_close,
1359 struct pr_usrreqs tcp6_usrreqs = {
1360 .pru_abort = tcp_usr_abort,
1361 .pru_accept = tcp6_usr_accept,
1362 .pru_attach = tcp_usr_attach,
1363 .pru_bind = tcp6_usr_bind,
1364 .pru_connect = tcp6_usr_connect,
1365 .pru_control = in6_control,
1366 .pru_detach = tcp_usr_detach,
1367 .pru_disconnect = tcp_usr_disconnect,
1368 .pru_listen = tcp6_usr_listen,
1369 .pru_peeraddr = in6_mapped_peeraddr,
1370 .pru_rcvd = tcp_usr_rcvd,
1371 .pru_rcvoob = tcp_usr_rcvoob,
1372 .pru_send = tcp_usr_send,
1373 .pru_ready = tcp_usr_ready,
1374 .pru_shutdown = tcp_usr_shutdown,
1375 .pru_sockaddr = in6_mapped_sockaddr,
1376 .pru_sosetlabel = in_pcbsosetlabel,
1377 .pru_close = tcp_usr_close,
1383 * Common subroutine to open a TCP connection to remote host specified
1384 * by struct sockaddr_in in mbuf *nam. Call in_pcbbind to assign a local
1385 * port number if needed. Call in_pcbconnect_setup to do the routing and
1386 * to choose a local host address (interface). If there is an existing
1387 * incarnation of the same connection in TIME-WAIT state and if the remote
1388 * host was sending CC options and if the connection duration was < MSL, then
1389 * truncate the previous TIME-WAIT state and proceed.
1390 * Initialize connection parameters and enter SYN-SENT state.
1393 tcp_connect(struct tcpcb *tp, struct sockaddr *nam, struct thread *td)
1395 struct inpcb *inp = tp->t_inpcb, *oinp;
1396 struct socket *so = inp->inp_socket;
1397 struct in_addr laddr;
1401 INP_WLOCK_ASSERT(inp);
1402 INP_HASH_WLOCK(&V_tcbinfo);
1404 if (inp->inp_lport == 0) {
1405 error = in_pcbbind(inp, (struct sockaddr *)0, td->td_ucred);
1411 * Cannot simply call in_pcbconnect, because there might be an
1412 * earlier incarnation of this same connection still in
1413 * TIME_WAIT state, creating an ADDRINUSE error.
1415 laddr = inp->inp_laddr;
1416 lport = inp->inp_lport;
1417 error = in_pcbconnect_setup(inp, nam, &laddr.s_addr, &lport,
1418 &inp->inp_faddr.s_addr, &inp->inp_fport, &oinp, td->td_ucred);
1419 if (error && oinp == NULL)
1425 inp->inp_laddr = laddr;
1427 INP_HASH_WUNLOCK(&V_tcbinfo);
1430 * Compute window scaling to request:
1431 * Scale to fit into sweet spot. See tcp_syncache.c.
1432 * XXX: This should move to tcp_output().
1434 while (tp->request_r_scale < TCP_MAX_WINSHIFT &&
1435 (TCP_MAXWIN << tp->request_r_scale) < sb_max)
1436 tp->request_r_scale++;
1439 TCPSTAT_INC(tcps_connattempt);
1440 tcp_state_change(tp, TCPS_SYN_SENT);
1441 tp->iss = tcp_new_isn(&inp->inp_inc);
1442 if (tp->t_flags & TF_REQ_TSTMP)
1443 tp->ts_offset = tcp_new_ts_offset(&inp->inp_inc);
1444 tcp_sendseqinit(tp);
1449 INP_HASH_WUNLOCK(&V_tcbinfo);
1456 tcp6_connect(struct tcpcb *tp, struct sockaddr *nam, struct thread *td)
1458 struct inpcb *inp = tp->t_inpcb;
1461 INP_WLOCK_ASSERT(inp);
1462 INP_HASH_WLOCK(&V_tcbinfo);
1464 if (inp->inp_lport == 0) {
1465 error = in6_pcbbind(inp, (struct sockaddr *)0, td->td_ucred);
1469 error = in6_pcbconnect(inp, nam, td->td_ucred);
1472 INP_HASH_WUNLOCK(&V_tcbinfo);
1474 /* Compute window scaling to request. */
1475 while (tp->request_r_scale < TCP_MAX_WINSHIFT &&
1476 (TCP_MAXWIN << tp->request_r_scale) < sb_max)
1477 tp->request_r_scale++;
1479 soisconnecting(inp->inp_socket);
1480 TCPSTAT_INC(tcps_connattempt);
1481 tcp_state_change(tp, TCPS_SYN_SENT);
1482 tp->iss = tcp_new_isn(&inp->inp_inc);
1483 if (tp->t_flags & TF_REQ_TSTMP)
1484 tp->ts_offset = tcp_new_ts_offset(&inp->inp_inc);
1485 tcp_sendseqinit(tp);
1490 INP_HASH_WUNLOCK(&V_tcbinfo);
1496 * Export TCP internal state information via a struct tcp_info, based on the
1497 * Linux 2.6 API. Not ABI compatible as our constants are mapped differently
1498 * (TCP state machine, etc). We export all information using FreeBSD-native
1499 * constants -- for example, the numeric values for tcpi_state will differ
1503 tcp_fill_info(struct tcpcb *tp, struct tcp_info *ti)
1506 INP_WLOCK_ASSERT(tp->t_inpcb);
1507 bzero(ti, sizeof(*ti));
1509 ti->tcpi_state = tp->t_state;
1510 if ((tp->t_flags & TF_REQ_TSTMP) && (tp->t_flags & TF_RCVD_TSTMP))
1511 ti->tcpi_options |= TCPI_OPT_TIMESTAMPS;
1512 if (tp->t_flags & TF_SACK_PERMIT)
1513 ti->tcpi_options |= TCPI_OPT_SACK;
1514 if ((tp->t_flags & TF_REQ_SCALE) && (tp->t_flags & TF_RCVD_SCALE)) {
1515 ti->tcpi_options |= TCPI_OPT_WSCALE;
1516 ti->tcpi_snd_wscale = tp->snd_scale;
1517 ti->tcpi_rcv_wscale = tp->rcv_scale;
1519 if (tp->t_flags & TF_ECN_PERMIT)
1520 ti->tcpi_options |= TCPI_OPT_ECN;
1522 ti->tcpi_rto = tp->t_rxtcur * tick;
1523 ti->tcpi_last_data_recv = ((uint32_t)ticks - tp->t_rcvtime) * tick;
1524 ti->tcpi_rtt = ((u_int64_t)tp->t_srtt * tick) >> TCP_RTT_SHIFT;
1525 ti->tcpi_rttvar = ((u_int64_t)tp->t_rttvar * tick) >> TCP_RTTVAR_SHIFT;
1527 ti->tcpi_snd_ssthresh = tp->snd_ssthresh;
1528 ti->tcpi_snd_cwnd = tp->snd_cwnd;
1531 * FreeBSD-specific extension fields for tcp_info.
1533 ti->tcpi_rcv_space = tp->rcv_wnd;
1534 ti->tcpi_rcv_nxt = tp->rcv_nxt;
1535 ti->tcpi_snd_wnd = tp->snd_wnd;
1536 ti->tcpi_snd_bwnd = 0; /* Unused, kept for compat. */
1537 ti->tcpi_snd_nxt = tp->snd_nxt;
1538 ti->tcpi_snd_mss = tp->t_maxseg;
1539 ti->tcpi_rcv_mss = tp->t_maxseg;
1540 ti->tcpi_snd_rexmitpack = tp->t_sndrexmitpack;
1541 ti->tcpi_rcv_ooopack = tp->t_rcvoopack;
1542 ti->tcpi_snd_zerowin = tp->t_sndzerowin;
1544 if (tp->t_flags & TF_TOE) {
1545 ti->tcpi_options |= TCPI_OPT_TOE;
1546 tcp_offload_tcp_info(tp, ti);
1552 * tcp_ctloutput() must drop the inpcb lock before performing copyin on
1553 * socket option arguments. When it re-acquires the lock after the copy, it
1554 * has to revalidate that the connection is still valid for the socket
1557 #define INP_WLOCK_RECHECK_CLEANUP(inp, cleanup) do { \
1559 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) { \
1562 return (ECONNRESET); \
1564 tp = intotcpcb(inp); \
1566 #define INP_WLOCK_RECHECK(inp) INP_WLOCK_RECHECK_CLEANUP((inp), /* noop */)
1569 tcp_ctloutput(struct socket *so, struct sockopt *sopt)
1574 struct tcp_function_block *blk;
1575 struct tcp_function_set fsn;
1578 inp = sotoinpcb(so);
1579 KASSERT(inp != NULL, ("tcp_ctloutput: inp == NULL"));
1580 if (sopt->sopt_level != IPPROTO_TCP) {
1582 if (inp->inp_vflag & INP_IPV6PROTO) {
1583 error = ip6_ctloutput(so, sopt);
1585 * In case of the IPV6_USE_MIN_MTU socket option,
1586 * the INC_IPV6MINMTU flag to announce a corresponding
1587 * MSS during the initial handshake.
1588 * If the TCP connection is not in the front states,
1589 * just reduce the MSS being used.
1590 * This avoids the sending of TCP segments which will
1591 * be fragmented at the IPv6 layer.
1594 (sopt->sopt_dir == SOPT_SET) &&
1595 (sopt->sopt_level == IPPROTO_IPV6) &&
1596 (sopt->sopt_name == IPV6_USE_MIN_MTU)) {
1598 if ((inp->inp_flags &
1599 (INP_TIMEWAIT | INP_DROPPED))) {
1601 return (ECONNRESET);
1603 inp->inp_inc.inc_flags |= INC_IPV6MINMTU;
1604 tp = intotcpcb(inp);
1605 if ((tp->t_state >= TCPS_SYN_SENT) &&
1606 (inp->inp_inc.inc_flags & INC_ISIPV6)) {
1607 struct ip6_pktopts *opt;
1609 opt = inp->in6p_outputopts;
1610 if ((opt != NULL) &&
1611 (opt->ip6po_minmtu ==
1612 IP6PO_MINMTU_ALL)) {
1613 if (tp->t_maxseg > TCP6_MSS) {
1614 tp->t_maxseg = TCP6_MSS;
1622 #if defined(INET6) && defined(INET)
1627 error = ip_ctloutput(so, sopt);
1633 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
1635 return (ECONNRESET);
1637 tp = intotcpcb(inp);
1639 * Protect the TCP option TCP_FUNCTION_BLK so
1640 * that a sub-function can *never* overwrite this.
1642 if ((sopt->sopt_dir == SOPT_SET) &&
1643 (sopt->sopt_name == TCP_FUNCTION_BLK)) {
1645 error = sooptcopyin(sopt, &fsn, sizeof fsn,
1649 INP_WLOCK_RECHECK(inp);
1650 blk = find_and_ref_tcp_functions(&fsn);
1655 if (tp->t_fb == blk) {
1656 /* You already have this */
1657 refcount_release(&blk->tfb_refcnt);
1661 if (tp->t_state != TCPS_CLOSED) {
1663 * The user has advanced the state
1664 * past the initial point, we may not
1665 * be able to switch.
1667 if (blk->tfb_tcp_handoff_ok != NULL) {
1669 * Does the stack provide a
1670 * query mechanism, if so it may
1671 * still be possible?
1673 error = (*blk->tfb_tcp_handoff_ok)(tp);
1677 refcount_release(&blk->tfb_refcnt);
1682 if (blk->tfb_flags & TCP_FUNC_BEING_REMOVED) {
1683 refcount_release(&blk->tfb_refcnt);
1688 * Release the old refcnt, the
1689 * lookup acquired a ref on the
1692 if (tp->t_fb->tfb_tcp_fb_fini) {
1694 * Tell the stack to cleanup with 0 i.e.
1695 * the tcb is not going away.
1697 (*tp->t_fb->tfb_tcp_fb_fini)(tp, 0);
1700 /* Assure that we are not on any hpts */
1701 tcp_hpts_remove(tp->t_inpcb, HPTS_REMOVE_ALL);
1703 if (blk->tfb_tcp_fb_init) {
1704 error = (*blk->tfb_tcp_fb_init)(tp);
1706 refcount_release(&blk->tfb_refcnt);
1707 if (tp->t_fb->tfb_tcp_fb_init) {
1708 if((*tp->t_fb->tfb_tcp_fb_init)(tp) != 0) {
1709 /* Fall back failed, drop the connection */
1718 refcount_release(&tp->t_fb->tfb_refcnt);
1721 if (tp->t_flags & TF_TOE) {
1722 tcp_offload_ctloutput(tp, sopt->sopt_dir,
1729 } else if ((sopt->sopt_dir == SOPT_GET) &&
1730 (sopt->sopt_name == TCP_FUNCTION_BLK)) {
1731 strncpy(fsn.function_set_name, tp->t_fb->tfb_tcp_block_name,
1732 TCP_FUNCTION_NAME_LEN_MAX);
1733 fsn.function_set_name[TCP_FUNCTION_NAME_LEN_MAX - 1] = '\0';
1734 fsn.pcbcnt = tp->t_fb->tfb_refcnt;
1736 error = sooptcopyout(sopt, &fsn, sizeof fsn);
1739 /* Pass in the INP locked, called must unlock it */
1740 return (tp->t_fb->tfb_tcp_ctloutput(so, sopt, inp, tp));
1744 * If this assert becomes untrue, we need to change the size of the buf
1745 * variable in tcp_default_ctloutput().
1748 CTASSERT(TCP_CA_NAME_MAX <= TCP_LOG_ID_LEN);
1749 CTASSERT(TCP_LOG_REASON_LEN <= TCP_LOG_ID_LEN);
1753 tcp_default_ctloutput(struct socket *so, struct sockopt *sopt, struct inpcb *inp, struct tcpcb *tp)
1755 int error, opt, optval;
1758 struct cc_algo *algo;
1759 char *pbuf, buf[TCP_LOG_ID_LEN];
1763 * For TCP_CCALGOOPT forward the control to CC module, for both
1764 * SOPT_SET and SOPT_GET.
1766 switch (sopt->sopt_name) {
1769 if (sopt->sopt_valsize > CC_ALGOOPT_LIMIT)
1771 pbuf = malloc(sopt->sopt_valsize, M_TEMP, M_WAITOK | M_ZERO);
1772 error = sooptcopyin(sopt, pbuf, sopt->sopt_valsize,
1773 sopt->sopt_valsize);
1778 INP_WLOCK_RECHECK_CLEANUP(inp, free(pbuf, M_TEMP));
1779 if (CC_ALGO(tp)->ctl_output != NULL)
1780 error = CC_ALGO(tp)->ctl_output(tp->ccv, sopt, pbuf);
1784 if (error == 0 && sopt->sopt_dir == SOPT_GET)
1785 error = sooptcopyout(sopt, pbuf, sopt->sopt_valsize);
1790 switch (sopt->sopt_dir) {
1792 switch (sopt->sopt_name) {
1793 #if defined(IPSEC_SUPPORT) || defined(TCP_SIGNATURE)
1795 if (!TCPMD5_ENABLED()) {
1797 return (ENOPROTOOPT);
1799 error = TCPMD5_PCBCTL(inp, sopt);
1802 goto unlock_and_done;
1808 error = sooptcopyin(sopt, &optval, sizeof optval,
1813 INP_WLOCK_RECHECK(inp);
1814 switch (sopt->sopt_name) {
1822 opt = 0; /* dead code to fool gcc */
1829 tp->t_flags &= ~opt;
1832 if (tp->t_flags & TF_TOE) {
1833 tcp_offload_ctloutput(tp, sopt->sopt_dir,
1842 error = sooptcopyin(sopt, &optval, sizeof optval,
1847 INP_WLOCK_RECHECK(inp);
1849 tp->t_flags |= TF_NOPUSH;
1850 else if (tp->t_flags & TF_NOPUSH) {
1851 tp->t_flags &= ~TF_NOPUSH;
1852 if (TCPS_HAVEESTABLISHED(tp->t_state))
1853 error = tp->t_fb->tfb_tcp_output(tp);
1855 goto unlock_and_done;
1859 error = sooptcopyin(sopt, &optval, sizeof optval,
1864 INP_WLOCK_RECHECK(inp);
1865 if (optval > 0 && optval <= tp->t_maxseg &&
1866 optval + 40 >= V_tcp_minmss)
1867 tp->t_maxseg = optval;
1870 goto unlock_and_done;
1877 case TCP_CONGESTION:
1879 error = sooptcopyin(sopt, buf, TCP_CA_NAME_MAX - 1, 1);
1882 buf[sopt->sopt_valsize] = '\0';
1883 INP_WLOCK_RECHECK(inp);
1885 STAILQ_FOREACH(algo, &cc_list, entries)
1886 if (strncmp(buf, algo->name,
1887 TCP_CA_NAME_MAX) == 0)
1896 * We hold a write lock over the tcb so it's safe to
1897 * do these things without ordering concerns.
1899 if (CC_ALGO(tp)->cb_destroy != NULL)
1900 CC_ALGO(tp)->cb_destroy(tp->ccv);
1904 * If something goes pear shaped initialising the new
1905 * algo, fall back to newreno (which does not
1906 * require initialisation).
1908 if (algo->cb_init != NULL &&
1909 algo->cb_init(tp->ccv) != 0) {
1910 CC_ALGO(tp) = &newreno_cc_algo;
1912 * The only reason init should fail is
1913 * because of malloc.
1924 error = sooptcopyin(sopt, &ui, sizeof(ui), sizeof(ui));
1928 if (ui > (UINT_MAX / hz)) {
1934 INP_WLOCK_RECHECK(inp);
1935 switch (sopt->sopt_name) {
1937 tp->t_keepidle = ui;
1939 * XXX: better check current remaining
1940 * timeout and "merge" it with new value.
1942 if ((tp->t_state > TCPS_LISTEN) &&
1943 (tp->t_state <= TCPS_CLOSING))
1944 tcp_timer_activate(tp, TT_KEEP,
1948 tp->t_keepintvl = ui;
1949 if ((tp->t_state == TCPS_FIN_WAIT_2) &&
1950 (TP_MAXIDLE(tp) > 0))
1951 tcp_timer_activate(tp, TT_2MSL,
1955 tp->t_keepinit = ui;
1956 if (tp->t_state == TCPS_SYN_RECEIVED ||
1957 tp->t_state == TCPS_SYN_SENT)
1958 tcp_timer_activate(tp, TT_KEEP,
1962 goto unlock_and_done;
1966 error = sooptcopyin(sopt, &ui, sizeof(ui), sizeof(ui));
1970 INP_WLOCK_RECHECK(inp);
1972 if ((tp->t_state == TCPS_FIN_WAIT_2) &&
1973 (TP_MAXIDLE(tp) > 0))
1974 tcp_timer_activate(tp, TT_2MSL,
1976 goto unlock_and_done;
1982 error = sooptcopyin(sopt, &optval, sizeof optval,
1987 INP_WLOCK_RECHECK(inp);
1989 tcp_pcap_set_sock_max(TCP_PCAP_OUT ?
1990 &(tp->t_outpkts) : &(tp->t_inpkts),
1994 goto unlock_and_done;
1997 case TCP_FASTOPEN: {
1998 struct tcp_fastopen tfo_optval;
2001 if (!V_tcp_fastopen_client_enable &&
2002 !V_tcp_fastopen_server_enable)
2005 error = sooptcopyin(sopt, &tfo_optval,
2006 sizeof(tfo_optval), sizeof(int));
2010 INP_WLOCK_RECHECK(inp);
2011 if (tfo_optval.enable) {
2012 if (tp->t_state == TCPS_LISTEN) {
2013 if (!V_tcp_fastopen_server_enable) {
2015 goto unlock_and_done;
2018 tp->t_flags |= TF_FASTOPEN;
2019 if (tp->t_tfo_pending == NULL)
2021 tcp_fastopen_alloc_counter();
2024 * If a pre-shared key was provided,
2025 * stash it in the client cookie
2026 * field of the tcpcb for use during
2029 if (sopt->sopt_valsize ==
2030 sizeof(tfo_optval)) {
2031 memcpy(tp->t_tfo_cookie.client,
2033 TCP_FASTOPEN_PSK_LEN);
2034 tp->t_tfo_client_cookie_len =
2035 TCP_FASTOPEN_PSK_LEN;
2037 tp->t_flags |= TF_FASTOPEN;
2040 tp->t_flags &= ~TF_FASTOPEN;
2041 goto unlock_and_done;
2047 error = sooptcopyin(sopt, &optval, sizeof optval,
2052 INP_WLOCK_RECHECK(inp);
2053 error = tcp_log_state_change(tp, optval);
2054 goto unlock_and_done;
2063 error = sooptcopyin(sopt, buf, TCP_LOG_ID_LEN - 1, 0);
2066 buf[sopt->sopt_valsize] = '\0';
2067 INP_WLOCK_RECHECK(inp);
2068 error = tcp_log_set_id(tp, buf);
2069 /* tcp_log_set_id() unlocks the INP. */
2076 sooptcopyin(sopt, buf, TCP_LOG_REASON_LEN - 1, 0);
2079 buf[sopt->sopt_valsize] = '\0';
2080 INP_WLOCK_RECHECK(inp);
2081 if (sopt->sopt_name == TCP_LOGDUMP) {
2082 error = tcp_log_dump_tp_logbuf(tp, buf,
2086 tcp_log_dump_tp_bucket_logbufs(tp, buf);
2088 * tcp_log_dump_tp_bucket_logbufs() drops the
2097 error = ENOPROTOOPT;
2103 tp = intotcpcb(inp);
2104 switch (sopt->sopt_name) {
2105 #if defined(IPSEC_SUPPORT) || defined(TCP_SIGNATURE)
2107 if (!TCPMD5_ENABLED()) {
2109 return (ENOPROTOOPT);
2111 error = TCPMD5_PCBCTL(inp, sopt);
2116 optval = tp->t_flags & TF_NODELAY;
2118 error = sooptcopyout(sopt, &optval, sizeof optval);
2121 optval = tp->t_maxseg;
2123 error = sooptcopyout(sopt, &optval, sizeof optval);
2126 optval = tp->t_flags & TF_NOOPT;
2128 error = sooptcopyout(sopt, &optval, sizeof optval);
2131 optval = tp->t_flags & TF_NOPUSH;
2133 error = sooptcopyout(sopt, &optval, sizeof optval);
2136 tcp_fill_info(tp, &ti);
2138 error = sooptcopyout(sopt, &ti, sizeof ti);
2140 case TCP_CONGESTION:
2141 len = strlcpy(buf, CC_ALGO(tp)->name, TCP_CA_NAME_MAX);
2143 error = sooptcopyout(sopt, buf, len + 1);
2149 switch (sopt->sopt_name) {
2151 ui = TP_KEEPIDLE(tp) / hz;
2154 ui = TP_KEEPINTVL(tp) / hz;
2157 ui = TP_KEEPINIT(tp) / hz;
2160 ui = TP_KEEPCNT(tp);
2164 error = sooptcopyout(sopt, &ui, sizeof(ui));
2169 optval = tcp_pcap_get_sock_max(TCP_PCAP_OUT ?
2170 &(tp->t_outpkts) : &(tp->t_inpkts));
2172 error = sooptcopyout(sopt, &optval, sizeof optval);
2176 optval = tp->t_flags & TF_FASTOPEN;
2178 error = sooptcopyout(sopt, &optval, sizeof optval);
2182 optval = tp->t_logstate;
2184 error = sooptcopyout(sopt, &optval, sizeof(optval));
2187 /* tcp_log_getlogbuf() does INP_WUNLOCK(inp) */
2188 error = tcp_log_getlogbuf(sopt, tp);
2191 len = tcp_log_get_id(tp, buf);
2193 error = sooptcopyout(sopt, buf, len + 1);
2203 error = ENOPROTOOPT;
2210 #undef INP_WLOCK_RECHECK
2211 #undef INP_WLOCK_RECHECK_CLEANUP
2214 * Attach TCP protocol to socket, allocating
2215 * internet protocol control block, tcp control block,
2216 * bufer space, and entering LISTEN state if to accept connections.
2219 tcp_attach(struct socket *so)
2223 struct epoch_tracker et;
2226 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
2227 error = soreserve(so, V_tcp_sendspace, V_tcp_recvspace);
2231 so->so_rcv.sb_flags |= SB_AUTOSIZE;
2232 so->so_snd.sb_flags |= SB_AUTOSIZE;
2233 INP_INFO_RLOCK_ET(&V_tcbinfo, et);
2234 error = in_pcballoc(so, &V_tcbinfo);
2236 INP_INFO_RUNLOCK_ET(&V_tcbinfo, et);
2239 inp = sotoinpcb(so);
2241 if (inp->inp_vflag & INP_IPV6PROTO) {
2242 inp->inp_vflag |= INP_IPV6;
2243 if ((inp->inp_flags & IN6P_IPV6_V6ONLY) == 0)
2244 inp->inp_vflag |= INP_IPV4;
2245 inp->in6p_hops = -1; /* use kernel default */
2249 inp->inp_vflag |= INP_IPV4;
2250 tp = tcp_newtcpcb(inp);
2254 INP_INFO_RUNLOCK_ET(&V_tcbinfo, et);
2257 tp->t_state = TCPS_CLOSED;
2259 INP_INFO_RUNLOCK_ET(&V_tcbinfo, et);
2260 TCPSTATES_INC(TCPS_CLOSED);
2265 * Initiate (or continue) disconnect.
2266 * If embryonic state, just send reset (once).
2267 * If in ``let data drain'' option and linger null, just drop.
2268 * Otherwise (hard), mark socket disconnecting and drop
2269 * current input data; switch states based on user close, and
2270 * send segment to peer (with FIN).
2273 tcp_disconnect(struct tcpcb *tp)
2275 struct inpcb *inp = tp->t_inpcb;
2276 struct socket *so = inp->inp_socket;
2278 INP_INFO_RLOCK_ASSERT(&V_tcbinfo);
2279 INP_WLOCK_ASSERT(inp);
2282 * Neither tcp_close() nor tcp_drop() should return NULL, as the
2283 * socket is still open.
2285 if (tp->t_state < TCPS_ESTABLISHED &&
2286 !(tp->t_state > TCPS_LISTEN && IS_FASTOPEN(tp->t_flags))) {
2289 ("tcp_disconnect: tcp_close() returned NULL"));
2290 } else if ((so->so_options & SO_LINGER) && so->so_linger == 0) {
2291 tp = tcp_drop(tp, 0);
2293 ("tcp_disconnect: tcp_drop() returned NULL"));
2295 soisdisconnecting(so);
2296 sbflush(&so->so_rcv);
2298 if (!(inp->inp_flags & INP_DROPPED))
2299 tp->t_fb->tfb_tcp_output(tp);
2304 * User issued close, and wish to trail through shutdown states:
2305 * if never received SYN, just forget it. If got a SYN from peer,
2306 * but haven't sent FIN, then go to FIN_WAIT_1 state to send peer a FIN.
2307 * If already got a FIN from peer, then almost done; go to LAST_ACK
2308 * state. In all other cases, have already sent FIN to peer (e.g.
2309 * after PRU_SHUTDOWN), and just have to play tedious game waiting
2310 * for peer to send FIN or not respond to keep-alives, etc.
2311 * We can let the user exit from the close as soon as the FIN is acked.
2314 tcp_usrclosed(struct tcpcb *tp)
2317 INP_INFO_RLOCK_ASSERT(&V_tcbinfo);
2318 INP_WLOCK_ASSERT(tp->t_inpcb);
2320 switch (tp->t_state) {
2323 tcp_offload_listen_stop(tp);
2325 tcp_state_change(tp, TCPS_CLOSED);
2330 * tcp_close() should never return NULL here as the socket is
2334 ("tcp_usrclosed: tcp_close() returned NULL"));
2338 case TCPS_SYN_RECEIVED:
2339 tp->t_flags |= TF_NEEDFIN;
2342 case TCPS_ESTABLISHED:
2343 tcp_state_change(tp, TCPS_FIN_WAIT_1);
2346 case TCPS_CLOSE_WAIT:
2347 tcp_state_change(tp, TCPS_LAST_ACK);
2350 if (tp->t_state >= TCPS_FIN_WAIT_2) {
2351 soisdisconnected(tp->t_inpcb->inp_socket);
2352 /* Prevent the connection hanging in FIN_WAIT_2 forever. */
2353 if (tp->t_state == TCPS_FIN_WAIT_2) {
2356 timeout = (tcp_fast_finwait2_recycle) ?
2357 tcp_finwait2_timeout : TP_MAXIDLE(tp);
2358 tcp_timer_activate(tp, TT_2MSL, timeout);
2365 db_print_indent(int indent)
2369 for (i = 0; i < indent; i++)
2374 db_print_tstate(int t_state)
2379 db_printf("TCPS_CLOSED");
2383 db_printf("TCPS_LISTEN");
2387 db_printf("TCPS_SYN_SENT");
2390 case TCPS_SYN_RECEIVED:
2391 db_printf("TCPS_SYN_RECEIVED");
2394 case TCPS_ESTABLISHED:
2395 db_printf("TCPS_ESTABLISHED");
2398 case TCPS_CLOSE_WAIT:
2399 db_printf("TCPS_CLOSE_WAIT");
2402 case TCPS_FIN_WAIT_1:
2403 db_printf("TCPS_FIN_WAIT_1");
2407 db_printf("TCPS_CLOSING");
2411 db_printf("TCPS_LAST_ACK");
2414 case TCPS_FIN_WAIT_2:
2415 db_printf("TCPS_FIN_WAIT_2");
2418 case TCPS_TIME_WAIT:
2419 db_printf("TCPS_TIME_WAIT");
2423 db_printf("unknown");
2429 db_print_tflags(u_int t_flags)
2434 if (t_flags & TF_ACKNOW) {
2435 db_printf("%sTF_ACKNOW", comma ? ", " : "");
2438 if (t_flags & TF_DELACK) {
2439 db_printf("%sTF_DELACK", comma ? ", " : "");
2442 if (t_flags & TF_NODELAY) {
2443 db_printf("%sTF_NODELAY", comma ? ", " : "");
2446 if (t_flags & TF_NOOPT) {
2447 db_printf("%sTF_NOOPT", comma ? ", " : "");
2450 if (t_flags & TF_SENTFIN) {
2451 db_printf("%sTF_SENTFIN", comma ? ", " : "");
2454 if (t_flags & TF_REQ_SCALE) {
2455 db_printf("%sTF_REQ_SCALE", comma ? ", " : "");
2458 if (t_flags & TF_RCVD_SCALE) {
2459 db_printf("%sTF_RECVD_SCALE", comma ? ", " : "");
2462 if (t_flags & TF_REQ_TSTMP) {
2463 db_printf("%sTF_REQ_TSTMP", comma ? ", " : "");
2466 if (t_flags & TF_RCVD_TSTMP) {
2467 db_printf("%sTF_RCVD_TSTMP", comma ? ", " : "");
2470 if (t_flags & TF_SACK_PERMIT) {
2471 db_printf("%sTF_SACK_PERMIT", comma ? ", " : "");
2474 if (t_flags & TF_NEEDSYN) {
2475 db_printf("%sTF_NEEDSYN", comma ? ", " : "");
2478 if (t_flags & TF_NEEDFIN) {
2479 db_printf("%sTF_NEEDFIN", comma ? ", " : "");
2482 if (t_flags & TF_NOPUSH) {
2483 db_printf("%sTF_NOPUSH", comma ? ", " : "");
2486 if (t_flags & TF_MORETOCOME) {
2487 db_printf("%sTF_MORETOCOME", comma ? ", " : "");
2490 if (t_flags & TF_LQ_OVERFLOW) {
2491 db_printf("%sTF_LQ_OVERFLOW", comma ? ", " : "");
2494 if (t_flags & TF_LASTIDLE) {
2495 db_printf("%sTF_LASTIDLE", comma ? ", " : "");
2498 if (t_flags & TF_RXWIN0SENT) {
2499 db_printf("%sTF_RXWIN0SENT", comma ? ", " : "");
2502 if (t_flags & TF_FASTRECOVERY) {
2503 db_printf("%sTF_FASTRECOVERY", comma ? ", " : "");
2506 if (t_flags & TF_CONGRECOVERY) {
2507 db_printf("%sTF_CONGRECOVERY", comma ? ", " : "");
2510 if (t_flags & TF_WASFRECOVERY) {
2511 db_printf("%sTF_WASFRECOVERY", comma ? ", " : "");
2514 if (t_flags & TF_SIGNATURE) {
2515 db_printf("%sTF_SIGNATURE", comma ? ", " : "");
2518 if (t_flags & TF_FORCEDATA) {
2519 db_printf("%sTF_FORCEDATA", comma ? ", " : "");
2522 if (t_flags & TF_TSO) {
2523 db_printf("%sTF_TSO", comma ? ", " : "");
2526 if (t_flags & TF_ECN_PERMIT) {
2527 db_printf("%sTF_ECN_PERMIT", comma ? ", " : "");
2530 if (t_flags & TF_FASTOPEN) {
2531 db_printf("%sTF_FASTOPEN", comma ? ", " : "");
2537 db_print_toobflags(char t_oobflags)
2542 if (t_oobflags & TCPOOB_HAVEDATA) {
2543 db_printf("%sTCPOOB_HAVEDATA", comma ? ", " : "");
2546 if (t_oobflags & TCPOOB_HADDATA) {
2547 db_printf("%sTCPOOB_HADDATA", comma ? ", " : "");
2553 db_print_tcpcb(struct tcpcb *tp, const char *name, int indent)
2556 db_print_indent(indent);
2557 db_printf("%s at %p\n", name, tp);
2561 db_print_indent(indent);
2562 db_printf("t_segq first: %p t_segqlen: %d t_dupacks: %d\n",
2563 TAILQ_FIRST(&tp->t_segq), tp->t_segqlen, tp->t_dupacks);
2565 db_print_indent(indent);
2566 db_printf("tt_rexmt: %p tt_persist: %p tt_keep: %p\n",
2567 &tp->t_timers->tt_rexmt, &tp->t_timers->tt_persist, &tp->t_timers->tt_keep);
2569 db_print_indent(indent);
2570 db_printf("tt_2msl: %p tt_delack: %p t_inpcb: %p\n", &tp->t_timers->tt_2msl,
2571 &tp->t_timers->tt_delack, tp->t_inpcb);
2573 db_print_indent(indent);
2574 db_printf("t_state: %d (", tp->t_state);
2575 db_print_tstate(tp->t_state);
2578 db_print_indent(indent);
2579 db_printf("t_flags: 0x%x (", tp->t_flags);
2580 db_print_tflags(tp->t_flags);
2583 db_print_indent(indent);
2584 db_printf("snd_una: 0x%08x snd_max: 0x%08x snd_nxt: x0%08x\n",
2585 tp->snd_una, tp->snd_max, tp->snd_nxt);
2587 db_print_indent(indent);
2588 db_printf("snd_up: 0x%08x snd_wl1: 0x%08x snd_wl2: 0x%08x\n",
2589 tp->snd_up, tp->snd_wl1, tp->snd_wl2);
2591 db_print_indent(indent);
2592 db_printf("iss: 0x%08x irs: 0x%08x rcv_nxt: 0x%08x\n",
2593 tp->iss, tp->irs, tp->rcv_nxt);
2595 db_print_indent(indent);
2596 db_printf("rcv_adv: 0x%08x rcv_wnd: %u rcv_up: 0x%08x\n",
2597 tp->rcv_adv, tp->rcv_wnd, tp->rcv_up);
2599 db_print_indent(indent);
2600 db_printf("snd_wnd: %u snd_cwnd: %u\n",
2601 tp->snd_wnd, tp->snd_cwnd);
2603 db_print_indent(indent);
2604 db_printf("snd_ssthresh: %u snd_recover: "
2605 "0x%08x\n", tp->snd_ssthresh, tp->snd_recover);
2607 db_print_indent(indent);
2608 db_printf("t_rcvtime: %u t_startime: %u\n",
2609 tp->t_rcvtime, tp->t_starttime);
2611 db_print_indent(indent);
2612 db_printf("t_rttime: %u t_rtsq: 0x%08x\n",
2613 tp->t_rtttime, tp->t_rtseq);
2615 db_print_indent(indent);
2616 db_printf("t_rxtcur: %d t_maxseg: %u t_srtt: %d\n",
2617 tp->t_rxtcur, tp->t_maxseg, tp->t_srtt);
2619 db_print_indent(indent);
2620 db_printf("t_rttvar: %d t_rxtshift: %d t_rttmin: %u "
2621 "t_rttbest: %u\n", tp->t_rttvar, tp->t_rxtshift, tp->t_rttmin,
2624 db_print_indent(indent);
2625 db_printf("t_rttupdated: %lu max_sndwnd: %u t_softerror: %d\n",
2626 tp->t_rttupdated, tp->max_sndwnd, tp->t_softerror);
2628 db_print_indent(indent);
2629 db_printf("t_oobflags: 0x%x (", tp->t_oobflags);
2630 db_print_toobflags(tp->t_oobflags);
2631 db_printf(") t_iobc: 0x%02x\n", tp->t_iobc);
2633 db_print_indent(indent);
2634 db_printf("snd_scale: %u rcv_scale: %u request_r_scale: %u\n",
2635 tp->snd_scale, tp->rcv_scale, tp->request_r_scale);
2637 db_print_indent(indent);
2638 db_printf("ts_recent: %u ts_recent_age: %u\n",
2639 tp->ts_recent, tp->ts_recent_age);
2641 db_print_indent(indent);
2642 db_printf("ts_offset: %u last_ack_sent: 0x%08x snd_cwnd_prev: "
2643 "%u\n", tp->ts_offset, tp->last_ack_sent, tp->snd_cwnd_prev);
2645 db_print_indent(indent);
2646 db_printf("snd_ssthresh_prev: %u snd_recover_prev: 0x%08x "
2647 "t_badrxtwin: %u\n", tp->snd_ssthresh_prev,
2648 tp->snd_recover_prev, tp->t_badrxtwin);
2650 db_print_indent(indent);
2651 db_printf("snd_numholes: %d snd_holes first: %p\n",
2652 tp->snd_numholes, TAILQ_FIRST(&tp->snd_holes));
2654 db_print_indent(indent);
2655 db_printf("snd_fack: 0x%08x rcv_numsacks: %d sack_newdata: "
2656 "0x%08x\n", tp->snd_fack, tp->rcv_numsacks, tp->sack_newdata);
2658 /* Skip sackblks, sackhint. */
2660 db_print_indent(indent);
2661 db_printf("t_rttlow: %d rfbuf_ts: %u rfbuf_cnt: %d\n",
2662 tp->t_rttlow, tp->rfbuf_ts, tp->rfbuf_cnt);
2665 DB_SHOW_COMMAND(tcpcb, db_show_tcpcb)
2670 db_printf("usage: show tcpcb <addr>\n");
2673 tp = (struct tcpcb *)addr;
2675 db_print_tcpcb(tp, "tcpcb", 0);