2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 1982, 1986, 1988, 1993
5 * The Regents of the University of California.
6 * Copyright (c) 2006-2007 Robert N. M. Watson
7 * Copyright (c) 2010-2011 Juniper Networks, Inc.
10 * Portions of this software were developed by Robert N. M. Watson under
11 * contract to Juniper Networks, Inc.
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its contributors
22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * From: @(#)tcp_usrreq.c 8.2 (Berkeley) 1/3/94
40 #include <sys/cdefs.h>
41 __FBSDID("$FreeBSD$");
45 #include "opt_inet6.h"
46 #include "opt_ipsec.h"
47 #include "opt_kern_tls.h"
48 #include "opt_tcpdebug.h"
50 #include <sys/param.h>
51 #include <sys/systm.h>
53 #include <sys/limits.h>
54 #include <sys/malloc.h>
55 #include <sys/refcount.h>
56 #include <sys/kernel.h>
58 #include <sys/qmath.h>
59 #include <sys/sysctl.h>
62 #include <sys/domain.h>
64 #include <sys/socket.h>
65 #include <sys/socketvar.h>
66 #include <sys/protosw.h>
69 #include <sys/syslog.h>
70 #include <sys/stats.h>
77 #include <net/if_var.h>
78 #include <net/route.h>
81 #include <netinet/in.h>
82 #include <netinet/in_kdtrace.h>
83 #include <netinet/in_pcb.h>
84 #include <netinet/in_systm.h>
85 #include <netinet/in_var.h>
86 #include <netinet/ip_var.h>
88 #include <netinet/ip6.h>
89 #include <netinet6/in6_pcb.h>
90 #include <netinet6/ip6_var.h>
91 #include <netinet6/scope6_var.h>
93 #include <netinet/tcp.h>
94 #include <netinet/tcp_fsm.h>
95 #include <netinet/tcp_seq.h>
96 #include <netinet/tcp_timer.h>
97 #include <netinet/tcp_var.h>
98 #include <netinet/tcp_log_buf.h>
99 #include <netinet/tcpip.h>
100 #include <netinet/cc/cc.h>
101 #include <netinet/tcp_fastopen.h>
102 #include <netinet/tcp_hpts.h>
104 #include <netinet/tcp_pcap.h>
107 #include <netinet/tcp_debug.h>
110 #include <netinet/tcp_offload.h>
112 #include <netipsec/ipsec_support.h>
115 #include <vm/vm_param.h>
117 #include <vm/vm_extern.h>
118 #include <vm/vm_map.h>
119 #include <vm/vm_page.h>
122 * TCP protocol interface to socket abstraction.
125 static int tcp_connect(struct tcpcb *, struct sockaddr *,
129 static int tcp6_connect(struct tcpcb *, struct sockaddr *,
132 static void tcp_disconnect(struct tcpcb *);
133 static void tcp_usrclosed(struct tcpcb *);
134 static void tcp_fill_info(struct tcpcb *, struct tcp_info *);
137 #define TCPDEBUG0 int ostate = 0
138 #define TCPDEBUG1() ostate = tp ? tp->t_state : 0
139 #define TCPDEBUG2(req) if (tp && (so->so_options & SO_DEBUG)) \
140 tcp_trace(TA_USER, ostate, tp, 0, 0, req)
144 #define TCPDEBUG2(req)
148 * TCP attaches to socket via pru_attach(), reserving space,
149 * and an internet control block.
152 tcp_usr_attach(struct socket *so, int proto, struct thread *td)
155 struct tcpcb *tp = NULL;
160 KASSERT(inp == NULL, ("tcp_usr_attach: inp != NULL"));
163 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
164 error = soreserve(so, V_tcp_sendspace, V_tcp_recvspace);
169 so->so_rcv.sb_flags |= SB_AUTOSIZE;
170 so->so_snd.sb_flags |= SB_AUTOSIZE;
171 error = in_pcballoc(so, &V_tcbinfo);
176 if (inp->inp_vflag & INP_IPV6PROTO) {
177 inp->inp_vflag |= INP_IPV6;
178 if ((inp->inp_flags & IN6P_IPV6_V6ONLY) == 0)
179 inp->inp_vflag |= INP_IPV4;
180 inp->in6p_hops = -1; /* use kernel default */
184 inp->inp_vflag |= INP_IPV4;
185 tp = tcp_newtcpcb(inp);
192 tp->t_state = TCPS_CLOSED;
194 TCPSTATES_INC(TCPS_CLOSED);
195 if ((so->so_options & SO_LINGER) && so->so_linger == 0)
196 so->so_linger = TCP_LINGERTIME;
198 TCPDEBUG2(PRU_ATTACH);
199 TCP_PROBE2(debug__user, tp, PRU_ATTACH);
204 * tcp_usr_detach is called when the socket layer loses its final reference
205 * to the socket, be it a file descriptor reference, a reference from TCP,
206 * etc. At this point, there is only one case in which we will keep around
207 * inpcb state: time wait.
210 tcp_usr_detach(struct socket *so)
216 KASSERT(inp != NULL, ("%s: inp == NULL", __func__));
218 KASSERT(so->so_pcb == inp && inp->inp_socket == so,
219 ("%s: socket %p inp %p mismatch", __func__, so, inp));
223 if (inp->inp_flags & INP_TIMEWAIT) {
225 * There are two cases to handle: one in which the time wait
226 * state is being discarded (INP_DROPPED), and one in which
227 * this connection will remain in timewait. In the former,
228 * it is time to discard all state (except tcptw, which has
229 * already been discarded by the timewait close code, which
230 * should be further up the call stack somewhere). In the
231 * latter case, we detach from the socket, but leave the pcb
232 * present until timewait ends.
234 * XXXRW: Would it be cleaner to free the tcptw here?
236 * Astute question indeed, from twtcp perspective there are
237 * four cases to consider:
239 * #1 tcp_usr_detach is called at tcptw creation time by
240 * tcp_twstart, then do not discard the newly created tcptw
241 * and leave inpcb present until timewait ends
242 * #2 tcp_usr_detach is called at tcptw creation time by
243 * tcp_twstart, but connection is local and tw will be
244 * discarded immediately
245 * #3 tcp_usr_detach is called at timewait end (or reuse) by
246 * tcp_twclose, then the tcptw has already been discarded
247 * (or reused) and inpcb is freed here
248 * #4 tcp_usr_detach is called() after timewait ends (or reuse)
249 * (e.g. by soclose), then tcptw has already been discarded
250 * (or reused) and inpcb is freed here
252 * In all three cases the tcptw should not be freed here.
254 if (inp->inp_flags & INP_DROPPED) {
256 if (__predict_true(tp == NULL)) {
260 * This case should not happen as in TIMEWAIT
261 * state the inp should not be destroyed before
262 * its tcptw. If INVARIANTS is defined, panic.
265 panic("%s: Panic before an inp double-free: "
266 "INP_TIMEWAIT && INP_DROPPED && tp != NULL"
269 log(LOG_ERR, "%s: Avoid an inp double-free: "
270 "INP_TIMEWAIT && INP_DROPPED && tp != NULL"
281 * If the connection is not in timewait, we consider two
282 * two conditions: one in which no further processing is
283 * necessary (dropped || embryonic), and one in which TCP is
284 * not yet done, but no longer requires the socket, so the
285 * pcb will persist for the time being.
287 * XXXRW: Does the second case still occur?
289 if (inp->inp_flags & INP_DROPPED ||
290 tp->t_state < TCPS_SYN_SENT) {
303 * Give the socket an address.
306 tcp_usr_bind(struct socket *so, struct sockaddr *nam, struct thread *td)
310 struct tcpcb *tp = NULL;
311 struct sockaddr_in *sinp;
313 sinp = (struct sockaddr_in *)nam;
314 if (nam->sa_len != sizeof (*sinp))
317 * Must check for multicast addresses and disallow binding
320 if (sinp->sin_family == AF_INET &&
321 IN_MULTICAST(ntohl(sinp->sin_addr.s_addr)))
322 return (EAFNOSUPPORT);
326 KASSERT(inp != NULL, ("tcp_usr_bind: inp == NULL"));
328 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
334 INP_HASH_WLOCK(&V_tcbinfo);
335 error = in_pcbbind(inp, nam, td->td_ucred);
336 INP_HASH_WUNLOCK(&V_tcbinfo);
339 TCP_PROBE2(debug__user, tp, PRU_BIND);
348 tcp6_usr_bind(struct socket *so, struct sockaddr *nam, struct thread *td)
352 struct tcpcb *tp = NULL;
353 struct sockaddr_in6 *sin6;
356 sin6 = (struct sockaddr_in6 *)nam;
357 if (nam->sa_len != sizeof (*sin6))
360 * Must check for multicast addresses and disallow binding
363 if (sin6->sin6_family == AF_INET6 &&
364 IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr))
365 return (EAFNOSUPPORT);
369 KASSERT(inp != NULL, ("tcp6_usr_bind: inp == NULL"));
371 vflagsav = inp->inp_vflag;
372 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
378 INP_HASH_WLOCK(&V_tcbinfo);
379 inp->inp_vflag &= ~INP_IPV4;
380 inp->inp_vflag |= INP_IPV6;
382 if ((inp->inp_flags & IN6P_IPV6_V6ONLY) == 0) {
383 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr))
384 inp->inp_vflag |= INP_IPV4;
385 else if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
386 struct sockaddr_in sin;
388 in6_sin6_2_sin(&sin, sin6);
389 if (IN_MULTICAST(ntohl(sin.sin_addr.s_addr))) {
390 error = EAFNOSUPPORT;
391 INP_HASH_WUNLOCK(&V_tcbinfo);
394 inp->inp_vflag |= INP_IPV4;
395 inp->inp_vflag &= ~INP_IPV6;
396 error = in_pcbbind(inp, (struct sockaddr *)&sin,
398 INP_HASH_WUNLOCK(&V_tcbinfo);
403 error = in6_pcbbind(inp, nam, td->td_ucred);
404 INP_HASH_WUNLOCK(&V_tcbinfo);
407 inp->inp_vflag = vflagsav;
409 TCP_PROBE2(debug__user, tp, PRU_BIND);
417 * Prepare to accept connections.
420 tcp_usr_listen(struct socket *so, int backlog, struct thread *td)
424 struct tcpcb *tp = NULL;
428 KASSERT(inp != NULL, ("tcp_usr_listen: inp == NULL"));
430 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
437 error = solisten_proto_check(so);
438 INP_HASH_WLOCK(&V_tcbinfo);
439 if (error == 0 && inp->inp_lport == 0)
440 error = in_pcbbind(inp, (struct sockaddr *)0, td->td_ucred);
441 INP_HASH_WUNLOCK(&V_tcbinfo);
443 tcp_state_change(tp, TCPS_LISTEN);
444 solisten_proto(so, backlog);
446 if ((so->so_options & SO_NO_OFFLOAD) == 0)
447 tcp_offload_listen_start(tp);
452 if (IS_FASTOPEN(tp->t_flags))
453 tp->t_tfo_pending = tcp_fastopen_alloc_counter();
456 TCPDEBUG2(PRU_LISTEN);
457 TCP_PROBE2(debug__user, tp, PRU_LISTEN);
465 tcp6_usr_listen(struct socket *so, int backlog, struct thread *td)
469 struct tcpcb *tp = NULL;
474 KASSERT(inp != NULL, ("tcp6_usr_listen: inp == NULL"));
476 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
480 vflagsav = inp->inp_vflag;
484 error = solisten_proto_check(so);
485 INP_HASH_WLOCK(&V_tcbinfo);
486 if (error == 0 && inp->inp_lport == 0) {
487 inp->inp_vflag &= ~INP_IPV4;
488 if ((inp->inp_flags & IN6P_IPV6_V6ONLY) == 0)
489 inp->inp_vflag |= INP_IPV4;
490 error = in6_pcbbind(inp, (struct sockaddr *)0, td->td_ucred);
492 INP_HASH_WUNLOCK(&V_tcbinfo);
494 tcp_state_change(tp, TCPS_LISTEN);
495 solisten_proto(so, backlog);
497 if ((so->so_options & SO_NO_OFFLOAD) == 0)
498 tcp_offload_listen_start(tp);
503 if (IS_FASTOPEN(tp->t_flags))
504 tp->t_tfo_pending = tcp_fastopen_alloc_counter();
507 inp->inp_vflag = vflagsav;
510 TCPDEBUG2(PRU_LISTEN);
511 TCP_PROBE2(debug__user, tp, PRU_LISTEN);
519 * Initiate connection to peer.
520 * Create a template for use in transmissions on this connection.
521 * Enter SYN_SENT state, and mark socket as connecting.
522 * Start keep-alive timer, and seed output sequence space.
523 * Send initial segment on connection.
526 tcp_usr_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
528 struct epoch_tracker et;
531 struct tcpcb *tp = NULL;
532 struct sockaddr_in *sinp;
534 sinp = (struct sockaddr_in *)nam;
535 if (nam->sa_len != sizeof (*sinp))
538 * Must disallow TCP ``connections'' to multicast addresses.
540 if (sinp->sin_family == AF_INET
541 && IN_MULTICAST(ntohl(sinp->sin_addr.s_addr)))
542 return (EAFNOSUPPORT);
543 if ((error = prison_remote_ip4(td->td_ucred, &sinp->sin_addr)) != 0)
548 KASSERT(inp != NULL, ("tcp_usr_connect: inp == NULL"));
550 if (inp->inp_flags & INP_TIMEWAIT) {
554 if (inp->inp_flags & INP_DROPPED) {
555 error = ECONNREFUSED;
561 if ((error = tcp_connect(tp, nam, td)) != 0)
564 if (registered_toedevs > 0 &&
565 (so->so_options & SO_NO_OFFLOAD) == 0 &&
566 (error = tcp_offload_connect(so, nam)) == 0)
569 tcp_timer_activate(tp, TT_KEEP, TP_KEEPINIT(tp));
570 error = tp->t_fb->tfb_tcp_output(tp);
574 TCPDEBUG2(PRU_CONNECT);
575 TCP_PROBE2(debug__user, tp, PRU_CONNECT);
583 tcp6_usr_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
585 struct epoch_tracker et;
588 struct tcpcb *tp = NULL;
589 struct sockaddr_in6 *sin6;
595 sin6 = (struct sockaddr_in6 *)nam;
596 if (nam->sa_len != sizeof (*sin6))
599 * Must disallow TCP ``connections'' to multicast addresses.
601 if (sin6->sin6_family == AF_INET6
602 && IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr))
603 return (EAFNOSUPPORT);
606 KASSERT(inp != NULL, ("tcp6_usr_connect: inp == NULL"));
608 vflagsav = inp->inp_vflag;
609 incflagsav = inp->inp_inc.inc_flags;
610 if (inp->inp_flags & INP_TIMEWAIT) {
614 if (inp->inp_flags & INP_DROPPED) {
615 error = ECONNREFUSED;
622 * XXXRW: Some confusion: V4/V6 flags relate to binding, and
623 * therefore probably require the hash lock, which isn't held here.
624 * Is this a significant problem?
626 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
627 struct sockaddr_in sin;
629 if ((inp->inp_flags & IN6P_IPV6_V6ONLY) != 0) {
633 if ((inp->inp_vflag & INP_IPV4) == 0) {
634 error = EAFNOSUPPORT;
638 in6_sin6_2_sin(&sin, sin6);
639 if (IN_MULTICAST(ntohl(sin.sin_addr.s_addr))) {
640 error = EAFNOSUPPORT;
643 if ((error = prison_remote_ip4(td->td_ucred,
644 &sin.sin_addr)) != 0)
646 inp->inp_vflag |= INP_IPV4;
647 inp->inp_vflag &= ~INP_IPV6;
649 if ((error = tcp_connect(tp, (struct sockaddr *)&sin, td)) != 0)
652 if (registered_toedevs > 0 &&
653 (so->so_options & SO_NO_OFFLOAD) == 0 &&
654 (error = tcp_offload_connect(so, nam)) == 0)
657 error = tp->t_fb->tfb_tcp_output(tp);
660 if ((inp->inp_vflag & INP_IPV6) == 0) {
661 error = EAFNOSUPPORT;
666 if ((error = prison_remote_ip6(td->td_ucred, &sin6->sin6_addr)) != 0)
668 inp->inp_vflag &= ~INP_IPV4;
669 inp->inp_vflag |= INP_IPV6;
670 inp->inp_inc.inc_flags |= INC_ISIPV6;
671 if ((error = tcp6_connect(tp, nam, td)) != 0)
674 if (registered_toedevs > 0 &&
675 (so->so_options & SO_NO_OFFLOAD) == 0 &&
676 (error = tcp_offload_connect(so, nam)) == 0)
679 tcp_timer_activate(tp, TT_KEEP, TP_KEEPINIT(tp));
681 error = tp->t_fb->tfb_tcp_output(tp);
688 * If the implicit bind in the connect call fails, restore
689 * the flags we modified.
691 if (error != 0 && inp->inp_lport == 0) {
692 inp->inp_vflag = vflagsav;
693 inp->inp_inc.inc_flags = incflagsav;
696 TCPDEBUG2(PRU_CONNECT);
697 TCP_PROBE2(debug__user, tp, PRU_CONNECT);
704 * Initiate disconnect from peer.
705 * If connection never passed embryonic stage, just drop;
706 * else if don't need to let data drain, then can just drop anyways,
707 * else have to begin TCP shutdown process: mark socket disconnecting,
708 * drain unread data, state switch to reflect user close, and
709 * send segment (e.g. FIN) to peer. Socket will be really disconnected
710 * when peer sends FIN and acks ours.
712 * SHOULD IMPLEMENT LATER PRU_CONNECT VIA REALLOC TCPCB.
715 tcp_usr_disconnect(struct socket *so)
718 struct tcpcb *tp = NULL;
719 struct epoch_tracker et;
725 KASSERT(inp != NULL, ("tcp_usr_disconnect: inp == NULL"));
727 if (inp->inp_flags & INP_TIMEWAIT)
729 if (inp->inp_flags & INP_DROPPED) {
737 TCPDEBUG2(PRU_DISCONNECT);
738 TCP_PROBE2(debug__user, tp, PRU_DISCONNECT);
746 * Accept a connection. Essentially all the work is done at higher levels;
747 * just return the address of the peer, storing through addr.
750 tcp_usr_accept(struct socket *so, struct sockaddr **nam)
753 struct inpcb *inp = NULL;
754 struct tcpcb *tp = NULL;
759 if (so->so_state & SS_ISDISCONNECTED)
760 return (ECONNABORTED);
763 KASSERT(inp != NULL, ("tcp_usr_accept: inp == NULL"));
765 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
766 error = ECONNABORTED;
773 * We inline in_getpeeraddr and COMMON_END here, so that we can
774 * copy the data of interest and defer the malloc until after we
777 port = inp->inp_fport;
778 addr = inp->inp_faddr;
781 TCPDEBUG2(PRU_ACCEPT);
782 TCP_PROBE2(debug__user, tp, PRU_ACCEPT);
785 *nam = in_sockaddr(port, &addr);
792 tcp6_usr_accept(struct socket *so, struct sockaddr **nam)
794 struct inpcb *inp = NULL;
796 struct tcpcb *tp = NULL;
798 struct in6_addr addr6;
799 struct epoch_tracker et;
804 if (so->so_state & SS_ISDISCONNECTED)
805 return (ECONNABORTED);
808 KASSERT(inp != NULL, ("tcp6_usr_accept: inp == NULL"));
811 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
812 error = ECONNABORTED;
819 * We inline in6_mapped_peeraddr and COMMON_END here, so that we can
820 * copy the data of interest and defer the malloc until after we
823 if (inp->inp_vflag & INP_IPV4) {
825 port = inp->inp_fport;
826 addr = inp->inp_faddr;
828 port = inp->inp_fport;
829 addr6 = inp->in6p_faddr;
833 TCPDEBUG2(PRU_ACCEPT);
834 TCP_PROBE2(debug__user, tp, PRU_ACCEPT);
839 *nam = in6_v4mapsin6_sockaddr(port, &addr);
841 *nam = in6_sockaddr(port, &addr6);
848 * Mark the connection as being incapable of further output.
851 tcp_usr_shutdown(struct socket *so)
855 struct tcpcb *tp = NULL;
856 struct epoch_tracker et;
861 KASSERT(inp != NULL, ("inp == NULL"));
863 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
871 if (!(inp->inp_flags & INP_DROPPED))
872 error = tp->t_fb->tfb_tcp_output(tp);
875 TCPDEBUG2(PRU_SHUTDOWN);
876 TCP_PROBE2(debug__user, tp, PRU_SHUTDOWN);
884 * After a receive, possibly send window update to peer.
887 tcp_usr_rcvd(struct socket *so, int flags)
889 struct epoch_tracker et;
891 struct tcpcb *tp = NULL;
896 KASSERT(inp != NULL, ("tcp_usr_rcvd: inp == NULL"));
898 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
905 * For passively-created TFO connections, don't attempt a window
906 * update while still in SYN_RECEIVED as this may trigger an early
907 * SYN|ACK. It is preferable to have the SYN|ACK be sent along with
908 * application response data, or failing that, when the DELACK timer
911 if (IS_FASTOPEN(tp->t_flags) &&
912 (tp->t_state == TCPS_SYN_RECEIVED))
916 if (tp->t_flags & TF_TOE)
917 tcp_offload_rcvd(tp);
920 tp->t_fb->tfb_tcp_output(tp);
924 TCP_PROBE2(debug__user, tp, PRU_RCVD);
930 * Do a send by putting data in output queue and updating urgent
931 * marker if URG set. Possibly send more data. Unlike the other
932 * pru_*() routines, the mbuf chains are our responsibility. We
933 * must either enqueue them or free them. The other pru_* routines
934 * generally are caller-frees.
937 tcp_usr_send(struct socket *so, int flags, struct mbuf *m,
938 struct sockaddr *nam, struct mbuf *control, struct thread *td)
940 struct epoch_tracker et;
943 struct tcpcb *tp = NULL;
946 struct sockaddr_in sin;
948 struct sockaddr_in *sinp;
959 * We require the pcbinfo "read lock" if we will close the socket
960 * as part of this call.
964 KASSERT(inp != NULL, ("tcp_usr_send: inp == NULL"));
966 vflagsav = inp->inp_vflag;
967 incflagsav = inp->inp_inc.inc_flags;
968 restoreflags = false;
969 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
973 * In case of PRUS_NOTREADY, tcp_usr_ready() is responsible
974 * for freeing memory.
976 if (m && (flags & PRUS_NOTREADY) == 0)
983 if (nam != NULL && tp->t_state < TCPS_SYN_SENT) {
984 switch (nam->sa_family) {
987 sinp = (struct sockaddr_in *)nam;
988 if (sinp->sin_len != sizeof(struct sockaddr_in)) {
994 if ((inp->inp_vflag & INP_IPV6) != 0) {
997 error = EAFNOSUPPORT;
1000 if (IN_MULTICAST(ntohl(sinp->sin_addr.s_addr))) {
1003 error = EAFNOSUPPORT;
1006 if ((error = prison_remote_ip4(td->td_ucred,
1007 &sinp->sin_addr))) {
1020 struct sockaddr_in6 *sin6;
1022 sin6 = (struct sockaddr_in6 *)nam;
1023 if (sin6->sin6_len != sizeof(*sin6)) {
1029 if (IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr)) {
1032 error = EAFNOSUPPORT;
1035 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
1037 if ((inp->inp_flags & IN6P_IPV6_V6ONLY) != 0) {
1043 if ((inp->inp_vflag & INP_IPV4) == 0) {
1044 error = EAFNOSUPPORT;
1049 restoreflags = true;
1050 inp->inp_vflag &= ~INP_IPV6;
1052 in6_sin6_2_sin(sinp, sin6);
1054 ntohl(sinp->sin_addr.s_addr))) {
1055 error = EAFNOSUPPORT;
1060 if ((error = prison_remote_ip4(td->td_ucred,
1061 &sinp->sin_addr))) {
1068 error = EAFNOSUPPORT;
1074 if ((inp->inp_vflag & INP_IPV6) == 0) {
1077 error = EAFNOSUPPORT;
1080 restoreflags = true;
1081 inp->inp_vflag &= ~INP_IPV4;
1082 inp->inp_inc.inc_flags |= INC_ISIPV6;
1083 if ((error = prison_remote_ip6(td->td_ucred,
1084 &sin6->sin6_addr))) {
1097 error = EAFNOSUPPORT;
1102 /* TCP doesn't do control messages (rights, creds, etc) */
1103 if (control->m_len) {
1110 m_freem(control); /* empty control, just free it */
1112 if (!(flags & PRUS_OOB)) {
1113 sbappendstream(&so->so_snd, m, flags);
1114 if (nam && tp->t_state < TCPS_SYN_SENT) {
1116 * Do implied connect if not yet connected,
1117 * initialize window to default value, and
1118 * initialize maxseg using peer's cached MSS.
1122 error = tcp6_connect(tp, nam, td);
1124 #if defined(INET6) && defined(INET)
1128 error = tcp_connect(tp,
1129 (struct sockaddr *)sinp, td);
1132 * The bind operation in tcp_connect succeeded. We
1133 * no longer want to restore the flags if later
1136 if (error == 0 || inp->inp_lport != 0)
1137 restoreflags = false;
1141 if (IS_FASTOPEN(tp->t_flags))
1142 tcp_fastopen_connect(tp);
1144 tp->snd_wnd = TTCP_CLIENT_SND_WND;
1148 if (flags & PRUS_EOF) {
1150 * Close the send side of the connection after
1156 if (!(inp->inp_flags & INP_DROPPED) &&
1157 !(flags & PRUS_NOTREADY)) {
1158 if (flags & PRUS_MORETOCOME)
1159 tp->t_flags |= TF_MORETOCOME;
1160 error = tp->t_fb->tfb_tcp_output(tp);
1161 if (flags & PRUS_MORETOCOME)
1162 tp->t_flags &= ~TF_MORETOCOME;
1166 * XXXRW: PRUS_EOF not implemented with PRUS_OOB?
1168 SOCKBUF_LOCK(&so->so_snd);
1169 if (sbspace(&so->so_snd) < -512) {
1170 SOCKBUF_UNLOCK(&so->so_snd);
1176 * According to RFC961 (Assigned Protocols),
1177 * the urgent pointer points to the last octet
1178 * of urgent data. We continue, however,
1179 * to consider it to indicate the first octet
1180 * of data past the urgent section.
1181 * Otherwise, snd_up should be one lower.
1183 sbappendstream_locked(&so->so_snd, m, flags);
1184 SOCKBUF_UNLOCK(&so->so_snd);
1185 if (nam && tp->t_state < TCPS_SYN_SENT) {
1187 * Do implied connect if not yet connected,
1188 * initialize window to default value, and
1189 * initialize maxseg using peer's cached MSS.
1193 * Not going to contemplate SYN|URG
1195 if (IS_FASTOPEN(tp->t_flags))
1196 tp->t_flags &= ~TF_FASTOPEN;
1199 error = tcp6_connect(tp, nam, td);
1201 #if defined(INET6) && defined(INET)
1205 error = tcp_connect(tp,
1206 (struct sockaddr *)sinp, td);
1209 * The bind operation in tcp_connect succeeded. We
1210 * no longer want to restore the flags if later
1213 if (error == 0 || inp->inp_lport != 0)
1214 restoreflags = false;
1218 tp->snd_wnd = TTCP_CLIENT_SND_WND;
1221 tp->snd_up = tp->snd_una + sbavail(&so->so_snd);
1222 if (!(flags & PRUS_NOTREADY)) {
1223 tp->t_flags |= TF_FORCEDATA;
1224 error = tp->t_fb->tfb_tcp_output(tp);
1225 tp->t_flags &= ~TF_FORCEDATA;
1228 TCP_LOG_EVENT(tp, NULL,
1229 &inp->inp_socket->so_rcv,
1230 &inp->inp_socket->so_snd,
1231 TCP_LOG_USERSEND, error,
1235 * If the request was unsuccessful and we changed flags,
1236 * restore the original flags.
1238 if (error != 0 && restoreflags) {
1239 inp->inp_vflag = vflagsav;
1240 inp->inp_inc.inc_flags = incflagsav;
1242 TCPDEBUG2((flags & PRUS_OOB) ? PRU_SENDOOB :
1243 ((flags & PRUS_EOF) ? PRU_SEND_EOF : PRU_SEND));
1244 TCP_PROBE2(debug__user, tp, (flags & PRUS_OOB) ? PRU_SENDOOB :
1245 ((flags & PRUS_EOF) ? PRU_SEND_EOF : PRU_SEND));
1252 tcp_usr_ready(struct socket *so, struct mbuf *m, int count)
1254 struct epoch_tracker et;
1259 inp = sotoinpcb(so);
1261 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
1263 mb_free_notready(m, count);
1264 return (ECONNRESET);
1266 tp = intotcpcb(inp);
1268 SOCKBUF_LOCK(&so->so_snd);
1269 error = sbready(&so->so_snd, m, count);
1270 SOCKBUF_UNLOCK(&so->so_snd);
1272 NET_EPOCH_ENTER(et);
1273 error = tp->t_fb->tfb_tcp_output(tp);
1282 * Abort the TCP. Drop the connection abruptly.
1285 tcp_usr_abort(struct socket *so)
1288 struct tcpcb *tp = NULL;
1289 struct epoch_tracker et;
1292 inp = sotoinpcb(so);
1293 KASSERT(inp != NULL, ("tcp_usr_abort: inp == NULL"));
1295 NET_EPOCH_ENTER(et);
1297 KASSERT(inp->inp_socket != NULL,
1298 ("tcp_usr_abort: inp_socket == NULL"));
1301 * If we still have full TCP state, and we're not dropped, drop.
1303 if (!(inp->inp_flags & INP_TIMEWAIT) &&
1304 !(inp->inp_flags & INP_DROPPED)) {
1305 tp = intotcpcb(inp);
1307 tp = tcp_drop(tp, ECONNABORTED);
1310 TCPDEBUG2(PRU_ABORT);
1311 TCP_PROBE2(debug__user, tp, PRU_ABORT);
1313 if (!(inp->inp_flags & INP_DROPPED)) {
1315 so->so_state |= SS_PROTOREF;
1317 inp->inp_flags |= INP_SOCKREF;
1325 * TCP socket is closed. Start friendly disconnect.
1328 tcp_usr_close(struct socket *so)
1331 struct tcpcb *tp = NULL;
1332 struct epoch_tracker et;
1335 inp = sotoinpcb(so);
1336 KASSERT(inp != NULL, ("tcp_usr_close: inp == NULL"));
1338 NET_EPOCH_ENTER(et);
1340 KASSERT(inp->inp_socket != NULL,
1341 ("tcp_usr_close: inp_socket == NULL"));
1344 * If we still have full TCP state, and we're not dropped, initiate
1347 if (!(inp->inp_flags & INP_TIMEWAIT) &&
1348 !(inp->inp_flags & INP_DROPPED)) {
1349 tp = intotcpcb(inp);
1352 TCPDEBUG2(PRU_CLOSE);
1353 TCP_PROBE2(debug__user, tp, PRU_CLOSE);
1355 if (!(inp->inp_flags & INP_DROPPED)) {
1357 so->so_state |= SS_PROTOREF;
1359 inp->inp_flags |= INP_SOCKREF;
1366 * Receive out-of-band data.
1369 tcp_usr_rcvoob(struct socket *so, struct mbuf *m, int flags)
1373 struct tcpcb *tp = NULL;
1376 inp = sotoinpcb(so);
1377 KASSERT(inp != NULL, ("tcp_usr_rcvoob: inp == NULL"));
1379 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
1383 tp = intotcpcb(inp);
1385 if ((so->so_oobmark == 0 &&
1386 (so->so_rcv.sb_state & SBS_RCVATMARK) == 0) ||
1387 so->so_options & SO_OOBINLINE ||
1388 tp->t_oobflags & TCPOOB_HADDATA) {
1392 if ((tp->t_oobflags & TCPOOB_HAVEDATA) == 0) {
1393 error = EWOULDBLOCK;
1397 *mtod(m, caddr_t) = tp->t_iobc;
1398 if ((flags & MSG_PEEK) == 0)
1399 tp->t_oobflags ^= (TCPOOB_HAVEDATA | TCPOOB_HADDATA);
1402 TCPDEBUG2(PRU_RCVOOB);
1403 TCP_PROBE2(debug__user, tp, PRU_RCVOOB);
1409 struct pr_usrreqs tcp_usrreqs = {
1410 .pru_abort = tcp_usr_abort,
1411 .pru_accept = tcp_usr_accept,
1412 .pru_attach = tcp_usr_attach,
1413 .pru_bind = tcp_usr_bind,
1414 .pru_connect = tcp_usr_connect,
1415 .pru_control = in_control,
1416 .pru_detach = tcp_usr_detach,
1417 .pru_disconnect = tcp_usr_disconnect,
1418 .pru_listen = tcp_usr_listen,
1419 .pru_peeraddr = in_getpeeraddr,
1420 .pru_rcvd = tcp_usr_rcvd,
1421 .pru_rcvoob = tcp_usr_rcvoob,
1422 .pru_send = tcp_usr_send,
1423 .pru_ready = tcp_usr_ready,
1424 .pru_shutdown = tcp_usr_shutdown,
1425 .pru_sockaddr = in_getsockaddr,
1426 .pru_sosetlabel = in_pcbsosetlabel,
1427 .pru_close = tcp_usr_close,
1432 struct pr_usrreqs tcp6_usrreqs = {
1433 .pru_abort = tcp_usr_abort,
1434 .pru_accept = tcp6_usr_accept,
1435 .pru_attach = tcp_usr_attach,
1436 .pru_bind = tcp6_usr_bind,
1437 .pru_connect = tcp6_usr_connect,
1438 .pru_control = in6_control,
1439 .pru_detach = tcp_usr_detach,
1440 .pru_disconnect = tcp_usr_disconnect,
1441 .pru_listen = tcp6_usr_listen,
1442 .pru_peeraddr = in6_mapped_peeraddr,
1443 .pru_rcvd = tcp_usr_rcvd,
1444 .pru_rcvoob = tcp_usr_rcvoob,
1445 .pru_send = tcp_usr_send,
1446 .pru_ready = tcp_usr_ready,
1447 .pru_shutdown = tcp_usr_shutdown,
1448 .pru_sockaddr = in6_mapped_sockaddr,
1449 .pru_sosetlabel = in_pcbsosetlabel,
1450 .pru_close = tcp_usr_close,
1456 * Common subroutine to open a TCP connection to remote host specified
1457 * by struct sockaddr_in in mbuf *nam. Call in_pcbbind to assign a local
1458 * port number if needed. Call in_pcbconnect_setup to do the routing and
1459 * to choose a local host address (interface). If there is an existing
1460 * incarnation of the same connection in TIME-WAIT state and if the remote
1461 * host was sending CC options and if the connection duration was < MSL, then
1462 * truncate the previous TIME-WAIT state and proceed.
1463 * Initialize connection parameters and enter SYN-SENT state.
1466 tcp_connect(struct tcpcb *tp, struct sockaddr *nam, struct thread *td)
1468 struct inpcb *inp = tp->t_inpcb, *oinp;
1469 struct socket *so = inp->inp_socket;
1470 struct in_addr laddr;
1475 INP_WLOCK_ASSERT(inp);
1476 INP_HASH_WLOCK(&V_tcbinfo);
1478 if (inp->inp_lport == 0) {
1479 error = in_pcbbind(inp, (struct sockaddr *)0, td->td_ucred);
1485 * Cannot simply call in_pcbconnect, because there might be an
1486 * earlier incarnation of this same connection still in
1487 * TIME_WAIT state, creating an ADDRINUSE error.
1489 laddr = inp->inp_laddr;
1490 lport = inp->inp_lport;
1491 error = in_pcbconnect_setup(inp, nam, &laddr.s_addr, &lport,
1492 &inp->inp_faddr.s_addr, &inp->inp_fport, &oinp, td->td_ucred);
1493 if (error && oinp == NULL)
1499 inp->inp_laddr = laddr;
1501 INP_HASH_WUNLOCK(&V_tcbinfo);
1504 * Compute window scaling to request:
1505 * Scale to fit into sweet spot. See tcp_syncache.c.
1506 * XXX: This should move to tcp_output().
1508 while (tp->request_r_scale < TCP_MAX_WINSHIFT &&
1509 (TCP_MAXWIN << tp->request_r_scale) < sb_max)
1510 tp->request_r_scale++;
1513 TCPSTAT_INC(tcps_connattempt);
1514 tcp_state_change(tp, TCPS_SYN_SENT);
1515 tp->iss = tcp_new_isn(&inp->inp_inc);
1516 if (tp->t_flags & TF_REQ_TSTMP)
1517 tp->ts_offset = tcp_new_ts_offset(&inp->inp_inc);
1518 tcp_sendseqinit(tp);
1523 INP_HASH_WUNLOCK(&V_tcbinfo);
1530 tcp6_connect(struct tcpcb *tp, struct sockaddr *nam, struct thread *td)
1532 struct inpcb *inp = tp->t_inpcb;
1535 INP_WLOCK_ASSERT(inp);
1536 INP_HASH_WLOCK(&V_tcbinfo);
1538 if (inp->inp_lport == 0) {
1539 error = in6_pcbbind(inp, (struct sockaddr *)0, td->td_ucred);
1543 error = in6_pcbconnect(inp, nam, td->td_ucred);
1546 INP_HASH_WUNLOCK(&V_tcbinfo);
1548 /* Compute window scaling to request. */
1549 while (tp->request_r_scale < TCP_MAX_WINSHIFT &&
1550 (TCP_MAXWIN << tp->request_r_scale) < sb_max)
1551 tp->request_r_scale++;
1553 soisconnecting(inp->inp_socket);
1554 TCPSTAT_INC(tcps_connattempt);
1555 tcp_state_change(tp, TCPS_SYN_SENT);
1556 tp->iss = tcp_new_isn(&inp->inp_inc);
1557 if (tp->t_flags & TF_REQ_TSTMP)
1558 tp->ts_offset = tcp_new_ts_offset(&inp->inp_inc);
1559 tcp_sendseqinit(tp);
1564 INP_HASH_WUNLOCK(&V_tcbinfo);
1570 * Export TCP internal state information via a struct tcp_info, based on the
1571 * Linux 2.6 API. Not ABI compatible as our constants are mapped differently
1572 * (TCP state machine, etc). We export all information using FreeBSD-native
1573 * constants -- for example, the numeric values for tcpi_state will differ
1577 tcp_fill_info(struct tcpcb *tp, struct tcp_info *ti)
1580 INP_WLOCK_ASSERT(tp->t_inpcb);
1581 bzero(ti, sizeof(*ti));
1583 ti->tcpi_state = tp->t_state;
1584 if ((tp->t_flags & TF_REQ_TSTMP) && (tp->t_flags & TF_RCVD_TSTMP))
1585 ti->tcpi_options |= TCPI_OPT_TIMESTAMPS;
1586 if (tp->t_flags & TF_SACK_PERMIT)
1587 ti->tcpi_options |= TCPI_OPT_SACK;
1588 if ((tp->t_flags & TF_REQ_SCALE) && (tp->t_flags & TF_RCVD_SCALE)) {
1589 ti->tcpi_options |= TCPI_OPT_WSCALE;
1590 ti->tcpi_snd_wscale = tp->snd_scale;
1591 ti->tcpi_rcv_wscale = tp->rcv_scale;
1593 if (tp->t_flags2 & TF2_ECN_PERMIT)
1594 ti->tcpi_options |= TCPI_OPT_ECN;
1596 ti->tcpi_rto = tp->t_rxtcur * tick;
1597 ti->tcpi_last_data_recv = ((uint32_t)ticks - tp->t_rcvtime) * tick;
1598 ti->tcpi_rtt = ((u_int64_t)tp->t_srtt * tick) >> TCP_RTT_SHIFT;
1599 ti->tcpi_rttvar = ((u_int64_t)tp->t_rttvar * tick) >> TCP_RTTVAR_SHIFT;
1601 ti->tcpi_snd_ssthresh = tp->snd_ssthresh;
1602 ti->tcpi_snd_cwnd = tp->snd_cwnd;
1605 * FreeBSD-specific extension fields for tcp_info.
1607 ti->tcpi_rcv_space = tp->rcv_wnd;
1608 ti->tcpi_rcv_nxt = tp->rcv_nxt;
1609 ti->tcpi_snd_wnd = tp->snd_wnd;
1610 ti->tcpi_snd_bwnd = 0; /* Unused, kept for compat. */
1611 ti->tcpi_snd_nxt = tp->snd_nxt;
1612 ti->tcpi_snd_mss = tp->t_maxseg;
1613 ti->tcpi_rcv_mss = tp->t_maxseg;
1614 ti->tcpi_snd_rexmitpack = tp->t_sndrexmitpack;
1615 ti->tcpi_rcv_ooopack = tp->t_rcvoopack;
1616 ti->tcpi_snd_zerowin = tp->t_sndzerowin;
1618 if (tp->t_flags & TF_TOE) {
1619 ti->tcpi_options |= TCPI_OPT_TOE;
1620 tcp_offload_tcp_info(tp, ti);
1626 * tcp_ctloutput() must drop the inpcb lock before performing copyin on
1627 * socket option arguments. When it re-acquires the lock after the copy, it
1628 * has to revalidate that the connection is still valid for the socket
1631 #define INP_WLOCK_RECHECK_CLEANUP(inp, cleanup) do { \
1633 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) { \
1636 return (ECONNRESET); \
1638 tp = intotcpcb(inp); \
1640 #define INP_WLOCK_RECHECK(inp) INP_WLOCK_RECHECK_CLEANUP((inp), /* noop */)
1643 tcp_ctloutput(struct socket *so, struct sockopt *sopt)
1648 struct tcp_function_block *blk;
1649 struct tcp_function_set fsn;
1652 inp = sotoinpcb(so);
1653 KASSERT(inp != NULL, ("tcp_ctloutput: inp == NULL"));
1654 if (sopt->sopt_level != IPPROTO_TCP) {
1656 if (inp->inp_vflag & INP_IPV6PROTO) {
1657 error = ip6_ctloutput(so, sopt);
1659 * In case of the IPV6_USE_MIN_MTU socket option,
1660 * the INC_IPV6MINMTU flag to announce a corresponding
1661 * MSS during the initial handshake.
1662 * If the TCP connection is not in the front states,
1663 * just reduce the MSS being used.
1664 * This avoids the sending of TCP segments which will
1665 * be fragmented at the IPv6 layer.
1668 (sopt->sopt_dir == SOPT_SET) &&
1669 (sopt->sopt_level == IPPROTO_IPV6) &&
1670 (sopt->sopt_name == IPV6_USE_MIN_MTU)) {
1672 if ((inp->inp_flags &
1673 (INP_TIMEWAIT | INP_DROPPED))) {
1675 return (ECONNRESET);
1677 inp->inp_inc.inc_flags |= INC_IPV6MINMTU;
1678 tp = intotcpcb(inp);
1679 if ((tp->t_state >= TCPS_SYN_SENT) &&
1680 (inp->inp_inc.inc_flags & INC_ISIPV6)) {
1681 struct ip6_pktopts *opt;
1683 opt = inp->in6p_outputopts;
1684 if ((opt != NULL) &&
1685 (opt->ip6po_minmtu ==
1686 IP6PO_MINMTU_ALL)) {
1687 if (tp->t_maxseg > TCP6_MSS) {
1688 tp->t_maxseg = TCP6_MSS;
1696 #if defined(INET6) && defined(INET)
1701 error = ip_ctloutput(so, sopt);
1707 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
1709 return (ECONNRESET);
1711 tp = intotcpcb(inp);
1713 * Protect the TCP option TCP_FUNCTION_BLK so
1714 * that a sub-function can *never* overwrite this.
1716 if ((sopt->sopt_dir == SOPT_SET) &&
1717 (sopt->sopt_name == TCP_FUNCTION_BLK)) {
1719 error = sooptcopyin(sopt, &fsn, sizeof fsn,
1723 INP_WLOCK_RECHECK(inp);
1724 blk = find_and_ref_tcp_functions(&fsn);
1729 if (tp->t_fb == blk) {
1730 /* You already have this */
1731 refcount_release(&blk->tfb_refcnt);
1735 if (tp->t_state != TCPS_CLOSED) {
1737 * The user has advanced the state
1738 * past the initial point, we may not
1739 * be able to switch.
1741 if (blk->tfb_tcp_handoff_ok != NULL) {
1743 * Does the stack provide a
1744 * query mechanism, if so it may
1745 * still be possible?
1747 error = (*blk->tfb_tcp_handoff_ok)(tp);
1751 refcount_release(&blk->tfb_refcnt);
1756 if (blk->tfb_flags & TCP_FUNC_BEING_REMOVED) {
1757 refcount_release(&blk->tfb_refcnt);
1762 * Release the old refcnt, the
1763 * lookup acquired a ref on the
1766 if (tp->t_fb->tfb_tcp_fb_fini) {
1768 * Tell the stack to cleanup with 0 i.e.
1769 * the tcb is not going away.
1771 (*tp->t_fb->tfb_tcp_fb_fini)(tp, 0);
1774 /* Assure that we are not on any hpts */
1775 tcp_hpts_remove(tp->t_inpcb, HPTS_REMOVE_ALL);
1777 if (blk->tfb_tcp_fb_init) {
1778 error = (*blk->tfb_tcp_fb_init)(tp);
1780 refcount_release(&blk->tfb_refcnt);
1781 if (tp->t_fb->tfb_tcp_fb_init) {
1782 if((*tp->t_fb->tfb_tcp_fb_init)(tp) != 0) {
1783 /* Fall back failed, drop the connection */
1792 refcount_release(&tp->t_fb->tfb_refcnt);
1795 if (tp->t_flags & TF_TOE) {
1796 tcp_offload_ctloutput(tp, sopt->sopt_dir,
1803 } else if ((sopt->sopt_dir == SOPT_GET) &&
1804 (sopt->sopt_name == TCP_FUNCTION_BLK)) {
1805 strncpy(fsn.function_set_name, tp->t_fb->tfb_tcp_block_name,
1806 TCP_FUNCTION_NAME_LEN_MAX);
1807 fsn.function_set_name[TCP_FUNCTION_NAME_LEN_MAX - 1] = '\0';
1808 fsn.pcbcnt = tp->t_fb->tfb_refcnt;
1810 error = sooptcopyout(sopt, &fsn, sizeof fsn);
1813 /* Pass in the INP locked, called must unlock it */
1814 return (tp->t_fb->tfb_tcp_ctloutput(so, sopt, inp, tp));
1818 * If this assert becomes untrue, we need to change the size of the buf
1819 * variable in tcp_default_ctloutput().
1822 CTASSERT(TCP_CA_NAME_MAX <= TCP_LOG_ID_LEN);
1823 CTASSERT(TCP_LOG_REASON_LEN <= TCP_LOG_ID_LEN);
1827 tcp_default_ctloutput(struct socket *so, struct sockopt *sopt, struct inpcb *inp, struct tcpcb *tp)
1829 int error, opt, optval;
1833 struct tls_enable tls;
1835 struct cc_algo *algo;
1836 char *pbuf, buf[TCP_LOG_ID_LEN];
1838 struct statsblob *sbp;
1843 * For TCP_CCALGOOPT forward the control to CC module, for both
1844 * SOPT_SET and SOPT_GET.
1846 switch (sopt->sopt_name) {
1849 if (sopt->sopt_valsize > CC_ALGOOPT_LIMIT)
1851 pbuf = malloc(sopt->sopt_valsize, M_TEMP, M_WAITOK | M_ZERO);
1852 error = sooptcopyin(sopt, pbuf, sopt->sopt_valsize,
1853 sopt->sopt_valsize);
1858 INP_WLOCK_RECHECK_CLEANUP(inp, free(pbuf, M_TEMP));
1859 if (CC_ALGO(tp)->ctl_output != NULL)
1860 error = CC_ALGO(tp)->ctl_output(tp->ccv, sopt, pbuf);
1864 if (error == 0 && sopt->sopt_dir == SOPT_GET)
1865 error = sooptcopyout(sopt, pbuf, sopt->sopt_valsize);
1870 switch (sopt->sopt_dir) {
1872 switch (sopt->sopt_name) {
1873 #if defined(IPSEC_SUPPORT) || defined(TCP_SIGNATURE)
1875 if (!TCPMD5_ENABLED()) {
1877 return (ENOPROTOOPT);
1879 error = TCPMD5_PCBCTL(inp, sopt);
1882 goto unlock_and_done;
1888 error = sooptcopyin(sopt, &optval, sizeof optval,
1893 INP_WLOCK_RECHECK(inp);
1894 switch (sopt->sopt_name) {
1902 opt = 0; /* dead code to fool gcc */
1909 tp->t_flags &= ~opt;
1912 if (tp->t_flags & TF_TOE) {
1913 tcp_offload_ctloutput(tp, sopt->sopt_dir,
1922 error = sooptcopyin(sopt, &optval, sizeof optval,
1927 INP_WLOCK_RECHECK(inp);
1929 tp->t_flags |= TF_NOPUSH;
1930 else if (tp->t_flags & TF_NOPUSH) {
1931 tp->t_flags &= ~TF_NOPUSH;
1932 if (TCPS_HAVEESTABLISHED(tp->t_state)) {
1933 struct epoch_tracker et;
1935 NET_EPOCH_ENTER(et);
1936 error = tp->t_fb->tfb_tcp_output(tp);
1940 goto unlock_and_done;
1944 error = sooptcopyin(sopt, &optval, sizeof optval,
1949 INP_WLOCK_RECHECK(inp);
1950 if (optval > 0 && optval <= tp->t_maxseg &&
1951 optval + 40 >= V_tcp_minmss)
1952 tp->t_maxseg = optval;
1955 goto unlock_and_done;
1965 error = sooptcopyin(sopt, &optval, sizeof optval,
1971 sbp = stats_blob_alloc(
1972 V_tcp_perconn_stats_dflt_tpl, 0);
1976 INP_WLOCK_RECHECK(inp);
1977 if ((tp->t_stats != NULL && sbp == NULL) ||
1978 (tp->t_stats == NULL && sbp != NULL)) {
1979 struct statsblob *t = tp->t_stats;
1985 stats_blob_destroy(sbp);
1987 return (EOPNOTSUPP);
1991 case TCP_CONGESTION:
1993 error = sooptcopyin(sopt, buf, TCP_CA_NAME_MAX - 1, 1);
1996 buf[sopt->sopt_valsize] = '\0';
1997 INP_WLOCK_RECHECK(inp);
1999 STAILQ_FOREACH(algo, &cc_list, entries)
2000 if (strncmp(buf, algo->name,
2001 TCP_CA_NAME_MAX) == 0)
2010 * We hold a write lock over the tcb so it's safe to
2011 * do these things without ordering concerns.
2013 if (CC_ALGO(tp)->cb_destroy != NULL)
2014 CC_ALGO(tp)->cb_destroy(tp->ccv);
2018 * If something goes pear shaped initialising the new
2019 * algo, fall back to newreno (which does not
2020 * require initialisation).
2022 if (algo->cb_init != NULL &&
2023 algo->cb_init(tp->ccv) != 0) {
2024 CC_ALGO(tp) = &newreno_cc_algo;
2026 * The only reason init should fail is
2027 * because of malloc.
2035 case TCP_TXTLS_ENABLE:
2037 error = sooptcopyin(sopt, &tls, sizeof(tls),
2041 error = ktls_enable_tx(so, &tls);
2043 case TCP_TXTLS_MODE:
2045 error = sooptcopyin(sopt, &ui, sizeof(ui), sizeof(ui));
2049 INP_WLOCK_RECHECK(inp);
2050 error = ktls_set_tx_mode(so, ui);
2059 error = sooptcopyin(sopt, &ui, sizeof(ui), sizeof(ui));
2063 if (ui > (UINT_MAX / hz)) {
2069 INP_WLOCK_RECHECK(inp);
2070 switch (sopt->sopt_name) {
2072 tp->t_keepidle = ui;
2074 * XXX: better check current remaining
2075 * timeout and "merge" it with new value.
2077 if ((tp->t_state > TCPS_LISTEN) &&
2078 (tp->t_state <= TCPS_CLOSING))
2079 tcp_timer_activate(tp, TT_KEEP,
2083 tp->t_keepintvl = ui;
2084 if ((tp->t_state == TCPS_FIN_WAIT_2) &&
2085 (TP_MAXIDLE(tp) > 0))
2086 tcp_timer_activate(tp, TT_2MSL,
2090 tp->t_keepinit = ui;
2091 if (tp->t_state == TCPS_SYN_RECEIVED ||
2092 tp->t_state == TCPS_SYN_SENT)
2093 tcp_timer_activate(tp, TT_KEEP,
2097 goto unlock_and_done;
2101 error = sooptcopyin(sopt, &ui, sizeof(ui), sizeof(ui));
2105 INP_WLOCK_RECHECK(inp);
2107 if ((tp->t_state == TCPS_FIN_WAIT_2) &&
2108 (TP_MAXIDLE(tp) > 0))
2109 tcp_timer_activate(tp, TT_2MSL,
2111 goto unlock_and_done;
2117 error = sooptcopyin(sopt, &optval, sizeof optval,
2122 INP_WLOCK_RECHECK(inp);
2124 tcp_pcap_set_sock_max(TCP_PCAP_OUT ?
2125 &(tp->t_outpkts) : &(tp->t_inpkts),
2129 goto unlock_and_done;
2132 case TCP_FASTOPEN: {
2133 struct tcp_fastopen tfo_optval;
2136 if (!V_tcp_fastopen_client_enable &&
2137 !V_tcp_fastopen_server_enable)
2140 error = sooptcopyin(sopt, &tfo_optval,
2141 sizeof(tfo_optval), sizeof(int));
2145 INP_WLOCK_RECHECK(inp);
2146 if (tfo_optval.enable) {
2147 if (tp->t_state == TCPS_LISTEN) {
2148 if (!V_tcp_fastopen_server_enable) {
2150 goto unlock_and_done;
2153 tp->t_flags |= TF_FASTOPEN;
2154 if (tp->t_tfo_pending == NULL)
2156 tcp_fastopen_alloc_counter();
2159 * If a pre-shared key was provided,
2160 * stash it in the client cookie
2161 * field of the tcpcb for use during
2164 if (sopt->sopt_valsize ==
2165 sizeof(tfo_optval)) {
2166 memcpy(tp->t_tfo_cookie.client,
2168 TCP_FASTOPEN_PSK_LEN);
2169 tp->t_tfo_client_cookie_len =
2170 TCP_FASTOPEN_PSK_LEN;
2172 tp->t_flags |= TF_FASTOPEN;
2175 tp->t_flags &= ~TF_FASTOPEN;
2176 goto unlock_and_done;
2182 error = sooptcopyin(sopt, &optval, sizeof optval,
2187 INP_WLOCK_RECHECK(inp);
2188 error = tcp_log_state_change(tp, optval);
2189 goto unlock_and_done;
2198 error = sooptcopyin(sopt, buf, TCP_LOG_ID_LEN - 1, 0);
2201 buf[sopt->sopt_valsize] = '\0';
2202 INP_WLOCK_RECHECK(inp);
2203 error = tcp_log_set_id(tp, buf);
2204 /* tcp_log_set_id() unlocks the INP. */
2211 sooptcopyin(sopt, buf, TCP_LOG_REASON_LEN - 1, 0);
2214 buf[sopt->sopt_valsize] = '\0';
2215 INP_WLOCK_RECHECK(inp);
2216 if (sopt->sopt_name == TCP_LOGDUMP) {
2217 error = tcp_log_dump_tp_logbuf(tp, buf,
2221 tcp_log_dump_tp_bucket_logbufs(tp, buf);
2223 * tcp_log_dump_tp_bucket_logbufs() drops the
2232 error = ENOPROTOOPT;
2238 tp = intotcpcb(inp);
2239 switch (sopt->sopt_name) {
2240 #if defined(IPSEC_SUPPORT) || defined(TCP_SIGNATURE)
2242 if (!TCPMD5_ENABLED()) {
2244 return (ENOPROTOOPT);
2246 error = TCPMD5_PCBCTL(inp, sopt);
2251 optval = tp->t_flags & TF_NODELAY;
2253 error = sooptcopyout(sopt, &optval, sizeof optval);
2256 optval = tp->t_maxseg;
2258 error = sooptcopyout(sopt, &optval, sizeof optval);
2261 optval = tp->t_flags & TF_NOOPT;
2263 error = sooptcopyout(sopt, &optval, sizeof optval);
2266 optval = tp->t_flags & TF_NOPUSH;
2268 error = sooptcopyout(sopt, &optval, sizeof optval);
2271 tcp_fill_info(tp, &ti);
2273 error = sooptcopyout(sopt, &ti, sizeof ti);
2279 TYPEOF_MEMBER(struct statsblob, flags) sbflags = 0;
2282 socklen_t outsbsz = sopt->sopt_valsize;
2283 if (tp->t_stats == NULL)
2285 else if (outsbsz >= tp->t_stats->cursz)
2286 outsbsz = tp->t_stats->cursz;
2287 else if (outsbsz >= sizeof(struct statsblob))
2288 outsbsz = sizeof(struct statsblob);
2295 sbp = sopt->sopt_val;
2296 nheld = atop(round_page(((vm_offset_t)sbp) +
2297 (vm_size_t)outsbsz) - trunc_page((vm_offset_t)sbp));
2298 vm_page_t ma[nheld];
2299 if (vm_fault_quick_hold_pages(
2300 &curproc->p_vmspace->vm_map, (vm_offset_t)sbp,
2301 outsbsz, VM_PROT_READ | VM_PROT_WRITE, ma,
2307 if ((error = copyin_nofault(&(sbp->flags), &sbflags,
2308 SIZEOF_MEMBER(struct statsblob, flags))))
2311 INP_WLOCK_RECHECK(inp);
2312 error = stats_blob_snapshot(&sbp, outsbsz, tp->t_stats,
2313 sbflags | SB_CLONE_USRDSTNOFAULT);
2315 sopt->sopt_valsize = outsbsz;
2317 vm_page_unhold_pages(ma, nheld);
2324 case TCP_CONGESTION:
2325 len = strlcpy(buf, CC_ALGO(tp)->name, TCP_CA_NAME_MAX);
2327 error = sooptcopyout(sopt, buf, len + 1);
2333 switch (sopt->sopt_name) {
2335 ui = TP_KEEPIDLE(tp) / hz;
2338 ui = TP_KEEPINTVL(tp) / hz;
2341 ui = TP_KEEPINIT(tp) / hz;
2344 ui = TP_KEEPCNT(tp);
2348 error = sooptcopyout(sopt, &ui, sizeof(ui));
2353 optval = tcp_pcap_get_sock_max(TCP_PCAP_OUT ?
2354 &(tp->t_outpkts) : &(tp->t_inpkts));
2356 error = sooptcopyout(sopt, &optval, sizeof optval);
2360 optval = tp->t_flags & TF_FASTOPEN;
2362 error = sooptcopyout(sopt, &optval, sizeof optval);
2366 optval = tp->t_logstate;
2368 error = sooptcopyout(sopt, &optval, sizeof(optval));
2371 /* tcp_log_getlogbuf() does INP_WUNLOCK(inp) */
2372 error = tcp_log_getlogbuf(sopt, tp);
2375 len = tcp_log_get_id(tp, buf);
2377 error = sooptcopyout(sopt, buf, len + 1);
2386 case TCP_TXTLS_MODE:
2387 optval = ktls_get_tx_mode(so);
2389 error = sooptcopyout(sopt, &optval, sizeof(optval));
2394 error = ENOPROTOOPT;
2401 #undef INP_WLOCK_RECHECK
2402 #undef INP_WLOCK_RECHECK_CLEANUP
2405 * Initiate (or continue) disconnect.
2406 * If embryonic state, just send reset (once).
2407 * If in ``let data drain'' option and linger null, just drop.
2408 * Otherwise (hard), mark socket disconnecting and drop
2409 * current input data; switch states based on user close, and
2410 * send segment to peer (with FIN).
2413 tcp_disconnect(struct tcpcb *tp)
2415 struct inpcb *inp = tp->t_inpcb;
2416 struct socket *so = inp->inp_socket;
2419 INP_WLOCK_ASSERT(inp);
2422 * Neither tcp_close() nor tcp_drop() should return NULL, as the
2423 * socket is still open.
2425 if (tp->t_state < TCPS_ESTABLISHED &&
2426 !(tp->t_state > TCPS_LISTEN && IS_FASTOPEN(tp->t_flags))) {
2429 ("tcp_disconnect: tcp_close() returned NULL"));
2430 } else if ((so->so_options & SO_LINGER) && so->so_linger == 0) {
2431 tp = tcp_drop(tp, 0);
2433 ("tcp_disconnect: tcp_drop() returned NULL"));
2435 soisdisconnecting(so);
2436 sbflush(&so->so_rcv);
2438 if (!(inp->inp_flags & INP_DROPPED))
2439 tp->t_fb->tfb_tcp_output(tp);
2444 * User issued close, and wish to trail through shutdown states:
2445 * if never received SYN, just forget it. If got a SYN from peer,
2446 * but haven't sent FIN, then go to FIN_WAIT_1 state to send peer a FIN.
2447 * If already got a FIN from peer, then almost done; go to LAST_ACK
2448 * state. In all other cases, have already sent FIN to peer (e.g.
2449 * after PRU_SHUTDOWN), and just have to play tedious game waiting
2450 * for peer to send FIN or not respond to keep-alives, etc.
2451 * We can let the user exit from the close as soon as the FIN is acked.
2454 tcp_usrclosed(struct tcpcb *tp)
2458 INP_WLOCK_ASSERT(tp->t_inpcb);
2460 switch (tp->t_state) {
2463 tcp_offload_listen_stop(tp);
2465 tcp_state_change(tp, TCPS_CLOSED);
2470 * tcp_close() should never return NULL here as the socket is
2474 ("tcp_usrclosed: tcp_close() returned NULL"));
2478 case TCPS_SYN_RECEIVED:
2479 tp->t_flags |= TF_NEEDFIN;
2482 case TCPS_ESTABLISHED:
2483 tcp_state_change(tp, TCPS_FIN_WAIT_1);
2486 case TCPS_CLOSE_WAIT:
2487 tcp_state_change(tp, TCPS_LAST_ACK);
2490 if (tp->t_state >= TCPS_FIN_WAIT_2) {
2491 soisdisconnected(tp->t_inpcb->inp_socket);
2492 /* Prevent the connection hanging in FIN_WAIT_2 forever. */
2493 if (tp->t_state == TCPS_FIN_WAIT_2) {
2496 timeout = (tcp_fast_finwait2_recycle) ?
2497 tcp_finwait2_timeout : TP_MAXIDLE(tp);
2498 tcp_timer_activate(tp, TT_2MSL, timeout);
2505 db_print_indent(int indent)
2509 for (i = 0; i < indent; i++)
2514 db_print_tstate(int t_state)
2519 db_printf("TCPS_CLOSED");
2523 db_printf("TCPS_LISTEN");
2527 db_printf("TCPS_SYN_SENT");
2530 case TCPS_SYN_RECEIVED:
2531 db_printf("TCPS_SYN_RECEIVED");
2534 case TCPS_ESTABLISHED:
2535 db_printf("TCPS_ESTABLISHED");
2538 case TCPS_CLOSE_WAIT:
2539 db_printf("TCPS_CLOSE_WAIT");
2542 case TCPS_FIN_WAIT_1:
2543 db_printf("TCPS_FIN_WAIT_1");
2547 db_printf("TCPS_CLOSING");
2551 db_printf("TCPS_LAST_ACK");
2554 case TCPS_FIN_WAIT_2:
2555 db_printf("TCPS_FIN_WAIT_2");
2558 case TCPS_TIME_WAIT:
2559 db_printf("TCPS_TIME_WAIT");
2563 db_printf("unknown");
2569 db_print_tflags(u_int t_flags)
2574 if (t_flags & TF_ACKNOW) {
2575 db_printf("%sTF_ACKNOW", comma ? ", " : "");
2578 if (t_flags & TF_DELACK) {
2579 db_printf("%sTF_DELACK", comma ? ", " : "");
2582 if (t_flags & TF_NODELAY) {
2583 db_printf("%sTF_NODELAY", comma ? ", " : "");
2586 if (t_flags & TF_NOOPT) {
2587 db_printf("%sTF_NOOPT", comma ? ", " : "");
2590 if (t_flags & TF_SENTFIN) {
2591 db_printf("%sTF_SENTFIN", comma ? ", " : "");
2594 if (t_flags & TF_REQ_SCALE) {
2595 db_printf("%sTF_REQ_SCALE", comma ? ", " : "");
2598 if (t_flags & TF_RCVD_SCALE) {
2599 db_printf("%sTF_RECVD_SCALE", comma ? ", " : "");
2602 if (t_flags & TF_REQ_TSTMP) {
2603 db_printf("%sTF_REQ_TSTMP", comma ? ", " : "");
2606 if (t_flags & TF_RCVD_TSTMP) {
2607 db_printf("%sTF_RCVD_TSTMP", comma ? ", " : "");
2610 if (t_flags & TF_SACK_PERMIT) {
2611 db_printf("%sTF_SACK_PERMIT", comma ? ", " : "");
2614 if (t_flags & TF_NEEDSYN) {
2615 db_printf("%sTF_NEEDSYN", comma ? ", " : "");
2618 if (t_flags & TF_NEEDFIN) {
2619 db_printf("%sTF_NEEDFIN", comma ? ", " : "");
2622 if (t_flags & TF_NOPUSH) {
2623 db_printf("%sTF_NOPUSH", comma ? ", " : "");
2626 if (t_flags & TF_MORETOCOME) {
2627 db_printf("%sTF_MORETOCOME", comma ? ", " : "");
2630 if (t_flags & TF_LQ_OVERFLOW) {
2631 db_printf("%sTF_LQ_OVERFLOW", comma ? ", " : "");
2634 if (t_flags & TF_LASTIDLE) {
2635 db_printf("%sTF_LASTIDLE", comma ? ", " : "");
2638 if (t_flags & TF_RXWIN0SENT) {
2639 db_printf("%sTF_RXWIN0SENT", comma ? ", " : "");
2642 if (t_flags & TF_FASTRECOVERY) {
2643 db_printf("%sTF_FASTRECOVERY", comma ? ", " : "");
2646 if (t_flags & TF_CONGRECOVERY) {
2647 db_printf("%sTF_CONGRECOVERY", comma ? ", " : "");
2650 if (t_flags & TF_WASFRECOVERY) {
2651 db_printf("%sTF_WASFRECOVERY", comma ? ", " : "");
2654 if (t_flags & TF_SIGNATURE) {
2655 db_printf("%sTF_SIGNATURE", comma ? ", " : "");
2658 if (t_flags & TF_FORCEDATA) {
2659 db_printf("%sTF_FORCEDATA", comma ? ", " : "");
2662 if (t_flags & TF_TSO) {
2663 db_printf("%sTF_TSO", comma ? ", " : "");
2666 if (t_flags & TF_FASTOPEN) {
2667 db_printf("%sTF_FASTOPEN", comma ? ", " : "");
2673 db_print_tflags2(u_int t_flags2)
2678 if (t_flags2 & TF2_ECN_PERMIT) {
2679 db_printf("%sTF2_ECN_PERMIT", comma ? ", " : "");
2686 db_print_toobflags(char t_oobflags)
2691 if (t_oobflags & TCPOOB_HAVEDATA) {
2692 db_printf("%sTCPOOB_HAVEDATA", comma ? ", " : "");
2695 if (t_oobflags & TCPOOB_HADDATA) {
2696 db_printf("%sTCPOOB_HADDATA", comma ? ", " : "");
2702 db_print_tcpcb(struct tcpcb *tp, const char *name, int indent)
2705 db_print_indent(indent);
2706 db_printf("%s at %p\n", name, tp);
2710 db_print_indent(indent);
2711 db_printf("t_segq first: %p t_segqlen: %d t_dupacks: %d\n",
2712 TAILQ_FIRST(&tp->t_segq), tp->t_segqlen, tp->t_dupacks);
2714 db_print_indent(indent);
2715 db_printf("tt_rexmt: %p tt_persist: %p tt_keep: %p\n",
2716 &tp->t_timers->tt_rexmt, &tp->t_timers->tt_persist, &tp->t_timers->tt_keep);
2718 db_print_indent(indent);
2719 db_printf("tt_2msl: %p tt_delack: %p t_inpcb: %p\n", &tp->t_timers->tt_2msl,
2720 &tp->t_timers->tt_delack, tp->t_inpcb);
2722 db_print_indent(indent);
2723 db_printf("t_state: %d (", tp->t_state);
2724 db_print_tstate(tp->t_state);
2727 db_print_indent(indent);
2728 db_printf("t_flags: 0x%x (", tp->t_flags);
2729 db_print_tflags(tp->t_flags);
2732 db_print_indent(indent);
2733 db_printf("t_flags2: 0x%x (", tp->t_flags2);
2734 db_print_tflags2(tp->t_flags2);
2737 db_print_indent(indent);
2738 db_printf("snd_una: 0x%08x snd_max: 0x%08x snd_nxt: x0%08x\n",
2739 tp->snd_una, tp->snd_max, tp->snd_nxt);
2741 db_print_indent(indent);
2742 db_printf("snd_up: 0x%08x snd_wl1: 0x%08x snd_wl2: 0x%08x\n",
2743 tp->snd_up, tp->snd_wl1, tp->snd_wl2);
2745 db_print_indent(indent);
2746 db_printf("iss: 0x%08x irs: 0x%08x rcv_nxt: 0x%08x\n",
2747 tp->iss, tp->irs, tp->rcv_nxt);
2749 db_print_indent(indent);
2750 db_printf("rcv_adv: 0x%08x rcv_wnd: %u rcv_up: 0x%08x\n",
2751 tp->rcv_adv, tp->rcv_wnd, tp->rcv_up);
2753 db_print_indent(indent);
2754 db_printf("snd_wnd: %u snd_cwnd: %u\n",
2755 tp->snd_wnd, tp->snd_cwnd);
2757 db_print_indent(indent);
2758 db_printf("snd_ssthresh: %u snd_recover: "
2759 "0x%08x\n", tp->snd_ssthresh, tp->snd_recover);
2761 db_print_indent(indent);
2762 db_printf("t_rcvtime: %u t_startime: %u\n",
2763 tp->t_rcvtime, tp->t_starttime);
2765 db_print_indent(indent);
2766 db_printf("t_rttime: %u t_rtsq: 0x%08x\n",
2767 tp->t_rtttime, tp->t_rtseq);
2769 db_print_indent(indent);
2770 db_printf("t_rxtcur: %d t_maxseg: %u t_srtt: %d\n",
2771 tp->t_rxtcur, tp->t_maxseg, tp->t_srtt);
2773 db_print_indent(indent);
2774 db_printf("t_rttvar: %d t_rxtshift: %d t_rttmin: %u "
2775 "t_rttbest: %u\n", tp->t_rttvar, tp->t_rxtshift, tp->t_rttmin,
2778 db_print_indent(indent);
2779 db_printf("t_rttupdated: %lu max_sndwnd: %u t_softerror: %d\n",
2780 tp->t_rttupdated, tp->max_sndwnd, tp->t_softerror);
2782 db_print_indent(indent);
2783 db_printf("t_oobflags: 0x%x (", tp->t_oobflags);
2784 db_print_toobflags(tp->t_oobflags);
2785 db_printf(") t_iobc: 0x%02x\n", tp->t_iobc);
2787 db_print_indent(indent);
2788 db_printf("snd_scale: %u rcv_scale: %u request_r_scale: %u\n",
2789 tp->snd_scale, tp->rcv_scale, tp->request_r_scale);
2791 db_print_indent(indent);
2792 db_printf("ts_recent: %u ts_recent_age: %u\n",
2793 tp->ts_recent, tp->ts_recent_age);
2795 db_print_indent(indent);
2796 db_printf("ts_offset: %u last_ack_sent: 0x%08x snd_cwnd_prev: "
2797 "%u\n", tp->ts_offset, tp->last_ack_sent, tp->snd_cwnd_prev);
2799 db_print_indent(indent);
2800 db_printf("snd_ssthresh_prev: %u snd_recover_prev: 0x%08x "
2801 "t_badrxtwin: %u\n", tp->snd_ssthresh_prev,
2802 tp->snd_recover_prev, tp->t_badrxtwin);
2804 db_print_indent(indent);
2805 db_printf("snd_numholes: %d snd_holes first: %p\n",
2806 tp->snd_numholes, TAILQ_FIRST(&tp->snd_holes));
2808 db_print_indent(indent);
2809 db_printf("snd_fack: 0x%08x rcv_numsacks: %d\n",
2810 tp->snd_fack, tp->rcv_numsacks);
2812 /* Skip sackblks, sackhint. */
2814 db_print_indent(indent);
2815 db_printf("t_rttlow: %d rfbuf_ts: %u rfbuf_cnt: %d\n",
2816 tp->t_rttlow, tp->rfbuf_ts, tp->rfbuf_cnt);
2819 DB_SHOW_COMMAND(tcpcb, db_show_tcpcb)
2824 db_printf("usage: show tcpcb <addr>\n");
2827 tp = (struct tcpcb *)addr;
2829 db_print_tcpcb(tp, "tcpcb", 0);