2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 1982, 1986, 1988, 1993
5 * The Regents of the University of California.
6 * Copyright (c) 2006-2007 Robert N. M. Watson
7 * Copyright (c) 2010-2011 Juniper Networks, Inc.
10 * Portions of this software were developed by Robert N. M. Watson under
11 * contract to Juniper Networks, Inc.
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its contributors
22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * From: @(#)tcp_usrreq.c 8.2 (Berkeley) 1/3/94
40 #include <sys/cdefs.h>
41 __FBSDID("$FreeBSD$");
45 #include "opt_inet6.h"
46 #include "opt_ipsec.h"
47 #include "opt_kern_tls.h"
48 #include "opt_tcpdebug.h"
50 #include <sys/param.h>
51 #include <sys/systm.h>
52 #include <sys/limits.h>
53 #include <sys/malloc.h>
54 #include <sys/refcount.h>
55 #include <sys/kernel.h>
57 #include <sys/sysctl.h>
60 #include <sys/domain.h>
62 #include <sys/socket.h>
63 #include <sys/socketvar.h>
64 #include <sys/protosw.h>
67 #include <sys/syslog.h>
74 #include <net/if_var.h>
75 #include <net/route.h>
78 #include <netinet/in.h>
79 #include <netinet/in_kdtrace.h>
80 #include <netinet/in_pcb.h>
81 #include <netinet/in_systm.h>
82 #include <netinet/in_var.h>
83 #include <netinet/ip_var.h>
85 #include <netinet/ip6.h>
86 #include <netinet6/in6_pcb.h>
87 #include <netinet6/ip6_var.h>
88 #include <netinet6/scope6_var.h>
90 #include <netinet/tcp.h>
91 #include <netinet/tcp_fsm.h>
92 #include <netinet/tcp_seq.h>
93 #include <netinet/tcp_timer.h>
94 #include <netinet/tcp_var.h>
95 #include <netinet/tcp_log_buf.h>
96 #include <netinet/tcpip.h>
97 #include <netinet/cc/cc.h>
98 #include <netinet/tcp_fastopen.h>
99 #include <netinet/tcp_hpts.h>
101 #include <netinet/tcp_pcap.h>
104 #include <netinet/tcp_debug.h>
107 #include <netinet/tcp_offload.h>
109 #include <netipsec/ipsec_support.h>
112 * TCP protocol interface to socket abstraction.
114 static int tcp_attach(struct socket *);
116 static int tcp_connect(struct tcpcb *, struct sockaddr *,
120 static int tcp6_connect(struct tcpcb *, struct sockaddr *,
123 static void tcp_disconnect(struct tcpcb *);
124 static void tcp_usrclosed(struct tcpcb *);
125 static void tcp_fill_info(struct tcpcb *, struct tcp_info *);
128 #define TCPDEBUG0 int ostate = 0
129 #define TCPDEBUG1() ostate = tp ? tp->t_state : 0
130 #define TCPDEBUG2(req) if (tp && (so->so_options & SO_DEBUG)) \
131 tcp_trace(TA_USER, ostate, tp, 0, 0, req)
135 #define TCPDEBUG2(req)
139 * TCP attaches to socket via pru_attach(), reserving space,
140 * and an internet control block.
143 tcp_usr_attach(struct socket *so, int proto, struct thread *td)
146 struct tcpcb *tp = NULL;
151 KASSERT(inp == NULL, ("tcp_usr_attach: inp != NULL"));
154 error = tcp_attach(so);
158 if ((so->so_options & SO_LINGER) && so->so_linger == 0)
159 so->so_linger = TCP_LINGERTIME;
164 TCPDEBUG2(PRU_ATTACH);
165 TCP_PROBE2(debug__user, tp, PRU_ATTACH);
170 * tcp_detach is called when the socket layer loses its final reference
171 * to the socket, be it a file descriptor reference, a reference from TCP,
172 * etc. At this point, there is only one case in which we will keep around
173 * inpcb state: time wait.
175 * This function can probably be re-absorbed back into tcp_usr_detach() now
176 * that there is a single detach path.
179 tcp_detach(struct socket *so, struct inpcb *inp)
183 INP_INFO_LOCK_ASSERT(&V_tcbinfo);
184 INP_WLOCK_ASSERT(inp);
186 KASSERT(so->so_pcb == inp, ("tcp_detach: so_pcb != inp"));
187 KASSERT(inp->inp_socket == so, ("tcp_detach: inp_socket != so"));
191 if (inp->inp_flags & INP_TIMEWAIT) {
193 * There are two cases to handle: one in which the time wait
194 * state is being discarded (INP_DROPPED), and one in which
195 * this connection will remain in timewait. In the former,
196 * it is time to discard all state (except tcptw, which has
197 * already been discarded by the timewait close code, which
198 * should be further up the call stack somewhere). In the
199 * latter case, we detach from the socket, but leave the pcb
200 * present until timewait ends.
202 * XXXRW: Would it be cleaner to free the tcptw here?
204 * Astute question indeed, from twtcp perspective there are
205 * four cases to consider:
207 * #1 tcp_detach is called at tcptw creation time by
208 * tcp_twstart, then do not discard the newly created tcptw
209 * and leave inpcb present until timewait ends
210 * #2 tcp_detach is called at tcptw creation time by
211 * tcp_twstart, but connection is local and tw will be
212 * discarded immediately
213 * #3 tcp_detach is called at timewait end (or reuse) by
214 * tcp_twclose, then the tcptw has already been discarded
215 * (or reused) and inpcb is freed here
216 * #4 tcp_detach is called() after timewait ends (or reuse)
217 * (e.g. by soclose), then tcptw has already been discarded
218 * (or reused) and inpcb is freed here
220 * In all three cases the tcptw should not be freed here.
222 if (inp->inp_flags & INP_DROPPED) {
224 if (__predict_true(tp == NULL)) {
228 * This case should not happen as in TIMEWAIT
229 * state the inp should not be destroyed before
230 * its tcptw. If INVARIANTS is defined, panic.
233 panic("%s: Panic before an inp double-free: "
234 "INP_TIMEWAIT && INP_DROPPED && tp != NULL"
237 log(LOG_ERR, "%s: Avoid an inp double-free: "
238 "INP_TIMEWAIT && INP_DROPPED && tp != NULL"
249 * If the connection is not in timewait, we consider two
250 * two conditions: one in which no further processing is
251 * necessary (dropped || embryonic), and one in which TCP is
252 * not yet done, but no longer requires the socket, so the
253 * pcb will persist for the time being.
255 * XXXRW: Does the second case still occur?
257 if (inp->inp_flags & INP_DROPPED ||
258 tp->t_state < TCPS_SYN_SENT) {
270 * pru_detach() detaches the TCP protocol from the socket.
271 * If the protocol state is non-embryonic, then can't
272 * do this directly: have to initiate a pru_disconnect(),
273 * which may finish later; embryonic TCB's can just
277 tcp_usr_detach(struct socket *so)
281 struct epoch_tracker et;
284 KASSERT(inp != NULL, ("tcp_usr_detach: inp == NULL"));
285 if (!INP_INFO_WLOCKED(&V_tcbinfo)) {
290 KASSERT(inp->inp_socket != NULL,
291 ("tcp_usr_detach: inp_socket == NULL"));
299 * Give the socket an address.
302 tcp_usr_bind(struct socket *so, struct sockaddr *nam, struct thread *td)
306 struct tcpcb *tp = NULL;
307 struct sockaddr_in *sinp;
309 sinp = (struct sockaddr_in *)nam;
310 if (nam->sa_len != sizeof (*sinp))
313 * Must check for multicast addresses and disallow binding
316 if (sinp->sin_family == AF_INET &&
317 IN_MULTICAST(ntohl(sinp->sin_addr.s_addr)))
318 return (EAFNOSUPPORT);
322 KASSERT(inp != NULL, ("tcp_usr_bind: inp == NULL"));
324 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
330 INP_HASH_WLOCK(&V_tcbinfo);
331 error = in_pcbbind(inp, nam, td->td_ucred);
332 INP_HASH_WUNLOCK(&V_tcbinfo);
335 TCP_PROBE2(debug__user, tp, PRU_BIND);
344 tcp6_usr_bind(struct socket *so, struct sockaddr *nam, struct thread *td)
348 struct tcpcb *tp = NULL;
349 struct sockaddr_in6 *sin6;
352 sin6 = (struct sockaddr_in6 *)nam;
353 if (nam->sa_len != sizeof (*sin6))
356 * Must check for multicast addresses and disallow binding
359 if (sin6->sin6_family == AF_INET6 &&
360 IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr))
361 return (EAFNOSUPPORT);
365 KASSERT(inp != NULL, ("tcp6_usr_bind: inp == NULL"));
367 vflagsav = inp->inp_vflag;
368 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
374 INP_HASH_WLOCK(&V_tcbinfo);
375 inp->inp_vflag &= ~INP_IPV4;
376 inp->inp_vflag |= INP_IPV6;
378 if ((inp->inp_flags & IN6P_IPV6_V6ONLY) == 0) {
379 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr))
380 inp->inp_vflag |= INP_IPV4;
381 else if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
382 struct sockaddr_in sin;
384 in6_sin6_2_sin(&sin, sin6);
385 if (IN_MULTICAST(ntohl(sin.sin_addr.s_addr))) {
386 error = EAFNOSUPPORT;
387 INP_HASH_WUNLOCK(&V_tcbinfo);
390 inp->inp_vflag |= INP_IPV4;
391 inp->inp_vflag &= ~INP_IPV6;
392 error = in_pcbbind(inp, (struct sockaddr *)&sin,
394 INP_HASH_WUNLOCK(&V_tcbinfo);
399 error = in6_pcbbind(inp, nam, td->td_ucred);
400 INP_HASH_WUNLOCK(&V_tcbinfo);
403 inp->inp_vflag = vflagsav;
405 TCP_PROBE2(debug__user, tp, PRU_BIND);
413 * Prepare to accept connections.
416 tcp_usr_listen(struct socket *so, int backlog, struct thread *td)
420 struct tcpcb *tp = NULL;
424 KASSERT(inp != NULL, ("tcp_usr_listen: inp == NULL"));
426 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
433 error = solisten_proto_check(so);
434 INP_HASH_WLOCK(&V_tcbinfo);
435 if (error == 0 && inp->inp_lport == 0)
436 error = in_pcbbind(inp, (struct sockaddr *)0, td->td_ucred);
437 INP_HASH_WUNLOCK(&V_tcbinfo);
439 tcp_state_change(tp, TCPS_LISTEN);
440 solisten_proto(so, backlog);
442 if ((so->so_options & SO_NO_OFFLOAD) == 0)
443 tcp_offload_listen_start(tp);
448 if (IS_FASTOPEN(tp->t_flags))
449 tp->t_tfo_pending = tcp_fastopen_alloc_counter();
452 TCPDEBUG2(PRU_LISTEN);
453 TCP_PROBE2(debug__user, tp, PRU_LISTEN);
461 tcp6_usr_listen(struct socket *so, int backlog, struct thread *td)
465 struct tcpcb *tp = NULL;
470 KASSERT(inp != NULL, ("tcp6_usr_listen: inp == NULL"));
472 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
476 vflagsav = inp->inp_vflag;
480 error = solisten_proto_check(so);
481 INP_HASH_WLOCK(&V_tcbinfo);
482 if (error == 0 && inp->inp_lport == 0) {
483 inp->inp_vflag &= ~INP_IPV4;
484 if ((inp->inp_flags & IN6P_IPV6_V6ONLY) == 0)
485 inp->inp_vflag |= INP_IPV4;
486 error = in6_pcbbind(inp, (struct sockaddr *)0, td->td_ucred);
488 INP_HASH_WUNLOCK(&V_tcbinfo);
490 tcp_state_change(tp, TCPS_LISTEN);
491 solisten_proto(so, backlog);
493 if ((so->so_options & SO_NO_OFFLOAD) == 0)
494 tcp_offload_listen_start(tp);
499 if (IS_FASTOPEN(tp->t_flags))
500 tp->t_tfo_pending = tcp_fastopen_alloc_counter();
503 inp->inp_vflag = vflagsav;
506 TCPDEBUG2(PRU_LISTEN);
507 TCP_PROBE2(debug__user, tp, PRU_LISTEN);
515 * Initiate connection to peer.
516 * Create a template for use in transmissions on this connection.
517 * Enter SYN_SENT state, and mark socket as connecting.
518 * Start keep-alive timer, and seed output sequence space.
519 * Send initial segment on connection.
522 tcp_usr_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
526 struct tcpcb *tp = NULL;
527 struct sockaddr_in *sinp;
529 sinp = (struct sockaddr_in *)nam;
530 if (nam->sa_len != sizeof (*sinp))
533 * Must disallow TCP ``connections'' to multicast addresses.
535 if (sinp->sin_family == AF_INET
536 && IN_MULTICAST(ntohl(sinp->sin_addr.s_addr)))
537 return (EAFNOSUPPORT);
538 if ((error = prison_remote_ip4(td->td_ucred, &sinp->sin_addr)) != 0)
543 KASSERT(inp != NULL, ("tcp_usr_connect: inp == NULL"));
545 if (inp->inp_flags & INP_TIMEWAIT) {
549 if (inp->inp_flags & INP_DROPPED) {
550 error = ECONNREFUSED;
555 if ((error = tcp_connect(tp, nam, td)) != 0)
558 if (registered_toedevs > 0 &&
559 (so->so_options & SO_NO_OFFLOAD) == 0 &&
560 (error = tcp_offload_connect(so, nam)) == 0)
563 tcp_timer_activate(tp, TT_KEEP, TP_KEEPINIT(tp));
564 error = tp->t_fb->tfb_tcp_output(tp);
566 TCPDEBUG2(PRU_CONNECT);
567 TCP_PROBE2(debug__user, tp, PRU_CONNECT);
575 tcp6_usr_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
579 struct tcpcb *tp = NULL;
580 struct sockaddr_in6 *sin6;
586 sin6 = (struct sockaddr_in6 *)nam;
587 if (nam->sa_len != sizeof (*sin6))
590 * Must disallow TCP ``connections'' to multicast addresses.
592 if (sin6->sin6_family == AF_INET6
593 && IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr))
594 return (EAFNOSUPPORT);
597 KASSERT(inp != NULL, ("tcp6_usr_connect: inp == NULL"));
599 vflagsav = inp->inp_vflag;
600 incflagsav = inp->inp_inc.inc_flags;
601 if (inp->inp_flags & INP_TIMEWAIT) {
605 if (inp->inp_flags & INP_DROPPED) {
606 error = ECONNREFUSED;
613 * XXXRW: Some confusion: V4/V6 flags relate to binding, and
614 * therefore probably require the hash lock, which isn't held here.
615 * Is this a significant problem?
617 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
618 struct sockaddr_in sin;
620 if ((inp->inp_flags & IN6P_IPV6_V6ONLY) != 0) {
624 if ((inp->inp_vflag & INP_IPV4) == 0) {
625 error = EAFNOSUPPORT;
629 in6_sin6_2_sin(&sin, sin6);
630 if (IN_MULTICAST(ntohl(sin.sin_addr.s_addr))) {
631 error = EAFNOSUPPORT;
634 if ((error = prison_remote_ip4(td->td_ucred,
635 &sin.sin_addr)) != 0)
637 inp->inp_vflag |= INP_IPV4;
638 inp->inp_vflag &= ~INP_IPV6;
639 if ((error = tcp_connect(tp, (struct sockaddr *)&sin, td)) != 0)
642 if (registered_toedevs > 0 &&
643 (so->so_options & SO_NO_OFFLOAD) == 0 &&
644 (error = tcp_offload_connect(so, nam)) == 0)
647 error = tp->t_fb->tfb_tcp_output(tp);
650 if ((inp->inp_vflag & INP_IPV6) == 0) {
651 error = EAFNOSUPPORT;
656 if ((error = prison_remote_ip6(td->td_ucred, &sin6->sin6_addr)) != 0)
658 inp->inp_vflag &= ~INP_IPV4;
659 inp->inp_vflag |= INP_IPV6;
660 inp->inp_inc.inc_flags |= INC_ISIPV6;
661 if ((error = tcp6_connect(tp, nam, td)) != 0)
664 if (registered_toedevs > 0 &&
665 (so->so_options & SO_NO_OFFLOAD) == 0 &&
666 (error = tcp_offload_connect(so, nam)) == 0)
669 tcp_timer_activate(tp, TT_KEEP, TP_KEEPINIT(tp));
670 error = tp->t_fb->tfb_tcp_output(tp);
674 * If the implicit bind in the connect call fails, restore
675 * the flags we modified.
677 if (error != 0 && inp->inp_lport == 0) {
678 inp->inp_vflag = vflagsav;
679 inp->inp_inc.inc_flags = incflagsav;
682 TCPDEBUG2(PRU_CONNECT);
683 TCP_PROBE2(debug__user, tp, PRU_CONNECT);
690 * Initiate disconnect from peer.
691 * If connection never passed embryonic stage, just drop;
692 * else if don't need to let data drain, then can just drop anyways,
693 * else have to begin TCP shutdown process: mark socket disconnecting,
694 * drain unread data, state switch to reflect user close, and
695 * send segment (e.g. FIN) to peer. Socket will be really disconnected
696 * when peer sends FIN and acks ours.
698 * SHOULD IMPLEMENT LATER PRU_CONNECT VIA REALLOC TCPCB.
701 tcp_usr_disconnect(struct socket *so)
704 struct tcpcb *tp = NULL;
705 struct epoch_tracker et;
711 KASSERT(inp != NULL, ("tcp_usr_disconnect: inp == NULL"));
713 if (inp->inp_flags & INP_TIMEWAIT)
715 if (inp->inp_flags & INP_DROPPED) {
723 TCPDEBUG2(PRU_DISCONNECT);
724 TCP_PROBE2(debug__user, tp, PRU_DISCONNECT);
732 * Accept a connection. Essentially all the work is done at higher levels;
733 * just return the address of the peer, storing through addr.
736 tcp_usr_accept(struct socket *so, struct sockaddr **nam)
739 struct inpcb *inp = NULL;
740 struct tcpcb *tp = NULL;
745 if (so->so_state & SS_ISDISCONNECTED)
746 return (ECONNABORTED);
749 KASSERT(inp != NULL, ("tcp_usr_accept: inp == NULL"));
751 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
752 error = ECONNABORTED;
759 * We inline in_getpeeraddr and COMMON_END here, so that we can
760 * copy the data of interest and defer the malloc until after we
763 port = inp->inp_fport;
764 addr = inp->inp_faddr;
767 TCPDEBUG2(PRU_ACCEPT);
768 TCP_PROBE2(debug__user, tp, PRU_ACCEPT);
771 *nam = in_sockaddr(port, &addr);
778 tcp6_usr_accept(struct socket *so, struct sockaddr **nam)
780 struct inpcb *inp = NULL;
782 struct tcpcb *tp = NULL;
784 struct in6_addr addr6;
785 struct epoch_tracker et;
790 if (so->so_state & SS_ISDISCONNECTED)
791 return (ECONNABORTED);
794 KASSERT(inp != NULL, ("tcp6_usr_accept: inp == NULL"));
797 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
798 error = ECONNABORTED;
805 * We inline in6_mapped_peeraddr and COMMON_END here, so that we can
806 * copy the data of interest and defer the malloc until after we
809 if (inp->inp_vflag & INP_IPV4) {
811 port = inp->inp_fport;
812 addr = inp->inp_faddr;
814 port = inp->inp_fport;
815 addr6 = inp->in6p_faddr;
819 TCPDEBUG2(PRU_ACCEPT);
820 TCP_PROBE2(debug__user, tp, PRU_ACCEPT);
825 *nam = in6_v4mapsin6_sockaddr(port, &addr);
827 *nam = in6_sockaddr(port, &addr6);
834 * Mark the connection as being incapable of further output.
837 tcp_usr_shutdown(struct socket *so)
841 struct tcpcb *tp = NULL;
842 struct epoch_tracker et;
847 KASSERT(inp != NULL, ("inp == NULL"));
849 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
857 if (!(inp->inp_flags & INP_DROPPED))
858 error = tp->t_fb->tfb_tcp_output(tp);
861 TCPDEBUG2(PRU_SHUTDOWN);
862 TCP_PROBE2(debug__user, tp, PRU_SHUTDOWN);
870 * After a receive, possibly send window update to peer.
873 tcp_usr_rcvd(struct socket *so, int flags)
876 struct tcpcb *tp = NULL;
881 KASSERT(inp != NULL, ("tcp_usr_rcvd: inp == NULL"));
883 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
890 * For passively-created TFO connections, don't attempt a window
891 * update while still in SYN_RECEIVED as this may trigger an early
892 * SYN|ACK. It is preferable to have the SYN|ACK be sent along with
893 * application response data, or failing that, when the DELACK timer
896 if (IS_FASTOPEN(tp->t_flags) &&
897 (tp->t_state == TCPS_SYN_RECEIVED))
900 if (tp->t_flags & TF_TOE)
901 tcp_offload_rcvd(tp);
904 tp->t_fb->tfb_tcp_output(tp);
908 TCP_PROBE2(debug__user, tp, PRU_RCVD);
914 * Do a send by putting data in output queue and updating urgent
915 * marker if URG set. Possibly send more data. Unlike the other
916 * pru_*() routines, the mbuf chains are our responsibility. We
917 * must either enqueue them or free them. The other pru_* routines
918 * generally are caller-frees.
921 tcp_usr_send(struct socket *so, int flags, struct mbuf *m,
922 struct sockaddr *nam, struct mbuf *control, struct thread *td)
924 struct epoch_tracker et;
927 struct tcpcb *tp = NULL;
930 struct sockaddr_in sin;
932 struct sockaddr_in *sinp;
943 * We require the pcbinfo "read lock" if we will close the socket
944 * as part of this call.
946 if (flags & PRUS_EOF)
949 KASSERT(inp != NULL, ("tcp_usr_send: inp == NULL"));
951 vflagsav = inp->inp_vflag;
952 incflagsav = inp->inp_inc.inc_flags;
953 restoreflags = false;
954 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
958 * In case of PRUS_NOTREADY, tcp_usr_ready() is responsible
959 * for freeing memory.
961 if (m && (flags & PRUS_NOTREADY) == 0)
968 if (nam != NULL && tp->t_state < TCPS_SYN_SENT) {
969 switch (nam->sa_family) {
972 sinp = (struct sockaddr_in *)nam;
973 if (sinp->sin_len != sizeof(struct sockaddr_in)) {
979 if ((inp->inp_vflag & INP_IPV6) != 0) {
982 error = EAFNOSUPPORT;
985 if (IN_MULTICAST(ntohl(sinp->sin_addr.s_addr))) {
988 error = EAFNOSUPPORT;
991 if ((error = prison_remote_ip4(td->td_ucred,
1005 struct sockaddr_in6 *sin6;
1007 sin6 = (struct sockaddr_in6 *)nam;
1008 if (sin6->sin6_len != sizeof(*sin6)) {
1014 if (IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr)) {
1017 error = EAFNOSUPPORT;
1020 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
1022 if ((inp->inp_flags & IN6P_IPV6_V6ONLY) != 0) {
1028 if ((inp->inp_vflag & INP_IPV4) == 0) {
1029 error = EAFNOSUPPORT;
1034 restoreflags = true;
1035 inp->inp_vflag &= ~INP_IPV6;
1037 in6_sin6_2_sin(sinp, sin6);
1039 ntohl(sinp->sin_addr.s_addr))) {
1040 error = EAFNOSUPPORT;
1045 if ((error = prison_remote_ip4(td->td_ucred,
1046 &sinp->sin_addr))) {
1053 error = EAFNOSUPPORT;
1059 if ((inp->inp_vflag & INP_IPV6) == 0) {
1062 error = EAFNOSUPPORT;
1065 restoreflags = true;
1066 inp->inp_vflag &= ~INP_IPV4;
1067 inp->inp_inc.inc_flags |= INC_ISIPV6;
1068 if ((error = prison_remote_ip6(td->td_ucred,
1069 &sin6->sin6_addr))) {
1082 error = EAFNOSUPPORT;
1087 /* TCP doesn't do control messages (rights, creds, etc) */
1088 if (control->m_len) {
1095 m_freem(control); /* empty control, just free it */
1097 if (!(flags & PRUS_OOB)) {
1098 sbappendstream(&so->so_snd, m, flags);
1099 if (nam && tp->t_state < TCPS_SYN_SENT) {
1101 * Do implied connect if not yet connected,
1102 * initialize window to default value, and
1103 * initialize maxseg using peer's cached MSS.
1107 error = tcp6_connect(tp, nam, td);
1109 #if defined(INET6) && defined(INET)
1113 error = tcp_connect(tp,
1114 (struct sockaddr *)sinp, td);
1117 * The bind operation in tcp_connect succeeded. We
1118 * no longer want to restore the flags if later
1121 if (error == 0 || inp->inp_lport != 0)
1122 restoreflags = false;
1126 if (IS_FASTOPEN(tp->t_flags))
1127 tcp_fastopen_connect(tp);
1129 tp->snd_wnd = TTCP_CLIENT_SND_WND;
1133 if (flags & PRUS_EOF) {
1135 * Close the send side of the connection after
1142 if (!(inp->inp_flags & INP_DROPPED) &&
1143 !(flags & PRUS_NOTREADY)) {
1144 if (flags & PRUS_MORETOCOME)
1145 tp->t_flags |= TF_MORETOCOME;
1146 error = tp->t_fb->tfb_tcp_output(tp);
1147 if (flags & PRUS_MORETOCOME)
1148 tp->t_flags &= ~TF_MORETOCOME;
1152 * XXXRW: PRUS_EOF not implemented with PRUS_OOB?
1154 SOCKBUF_LOCK(&so->so_snd);
1155 if (sbspace(&so->so_snd) < -512) {
1156 SOCKBUF_UNLOCK(&so->so_snd);
1162 * According to RFC961 (Assigned Protocols),
1163 * the urgent pointer points to the last octet
1164 * of urgent data. We continue, however,
1165 * to consider it to indicate the first octet
1166 * of data past the urgent section.
1167 * Otherwise, snd_up should be one lower.
1169 sbappendstream_locked(&so->so_snd, m, flags);
1170 SOCKBUF_UNLOCK(&so->so_snd);
1171 if (nam && tp->t_state < TCPS_SYN_SENT) {
1173 * Do implied connect if not yet connected,
1174 * initialize window to default value, and
1175 * initialize maxseg using peer's cached MSS.
1179 * Not going to contemplate SYN|URG
1181 if (IS_FASTOPEN(tp->t_flags))
1182 tp->t_flags &= ~TF_FASTOPEN;
1185 error = tcp6_connect(tp, nam, td);
1187 #if defined(INET6) && defined(INET)
1191 error = tcp_connect(tp,
1192 (struct sockaddr *)sinp, td);
1195 * The bind operation in tcp_connect succeeded. We
1196 * no longer want to restore the flags if later
1199 if (error == 0 || inp->inp_lport != 0)
1200 restoreflags = false;
1204 tp->snd_wnd = TTCP_CLIENT_SND_WND;
1207 tp->snd_up = tp->snd_una + sbavail(&so->so_snd);
1208 if (!(flags & PRUS_NOTREADY)) {
1209 tp->t_flags |= TF_FORCEDATA;
1210 error = tp->t_fb->tfb_tcp_output(tp);
1211 tp->t_flags &= ~TF_FORCEDATA;
1214 TCP_LOG_EVENT(tp, NULL,
1215 &inp->inp_socket->so_rcv,
1216 &inp->inp_socket->so_snd,
1217 TCP_LOG_USERSEND, error,
1221 * If the request was unsuccessful and we changed flags,
1222 * restore the original flags.
1224 if (error != 0 && restoreflags) {
1225 inp->inp_vflag = vflagsav;
1226 inp->inp_inc.inc_flags = incflagsav;
1228 TCPDEBUG2((flags & PRUS_OOB) ? PRU_SENDOOB :
1229 ((flags & PRUS_EOF) ? PRU_SEND_EOF : PRU_SEND));
1230 TCP_PROBE2(debug__user, tp, (flags & PRUS_OOB) ? PRU_SENDOOB :
1231 ((flags & PRUS_EOF) ? PRU_SEND_EOF : PRU_SEND));
1233 if (flags & PRUS_EOF)
1239 tcp_usr_ready(struct socket *so, struct mbuf *m, int count)
1245 inp = sotoinpcb(so);
1247 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
1249 mb_free_notready(m, count);
1250 return (ECONNRESET);
1252 tp = intotcpcb(inp);
1254 SOCKBUF_LOCK(&so->so_snd);
1255 error = sbready(&so->so_snd, m, count);
1256 SOCKBUF_UNLOCK(&so->so_snd);
1258 error = tp->t_fb->tfb_tcp_output(tp);
1265 * Abort the TCP. Drop the connection abruptly.
1268 tcp_usr_abort(struct socket *so)
1271 struct tcpcb *tp = NULL;
1272 struct epoch_tracker et;
1275 inp = sotoinpcb(so);
1276 KASSERT(inp != NULL, ("tcp_usr_abort: inp == NULL"));
1278 NET_EPOCH_ENTER(et);
1280 KASSERT(inp->inp_socket != NULL,
1281 ("tcp_usr_abort: inp_socket == NULL"));
1284 * If we still have full TCP state, and we're not dropped, drop.
1286 if (!(inp->inp_flags & INP_TIMEWAIT) &&
1287 !(inp->inp_flags & INP_DROPPED)) {
1288 tp = intotcpcb(inp);
1290 tp = tcp_drop(tp, ECONNABORTED);
1293 TCPDEBUG2(PRU_ABORT);
1294 TCP_PROBE2(debug__user, tp, PRU_ABORT);
1296 if (!(inp->inp_flags & INP_DROPPED)) {
1298 so->so_state |= SS_PROTOREF;
1300 inp->inp_flags |= INP_SOCKREF;
1308 * TCP socket is closed. Start friendly disconnect.
1311 tcp_usr_close(struct socket *so)
1314 struct tcpcb *tp = NULL;
1315 struct epoch_tracker et;
1318 inp = sotoinpcb(so);
1319 KASSERT(inp != NULL, ("tcp_usr_close: inp == NULL"));
1321 NET_EPOCH_ENTER(et);
1323 KASSERT(inp->inp_socket != NULL,
1324 ("tcp_usr_close: inp_socket == NULL"));
1327 * If we still have full TCP state, and we're not dropped, initiate
1330 if (!(inp->inp_flags & INP_TIMEWAIT) &&
1331 !(inp->inp_flags & INP_DROPPED)) {
1332 tp = intotcpcb(inp);
1335 TCPDEBUG2(PRU_CLOSE);
1336 TCP_PROBE2(debug__user, tp, PRU_CLOSE);
1338 if (!(inp->inp_flags & INP_DROPPED)) {
1340 so->so_state |= SS_PROTOREF;
1342 inp->inp_flags |= INP_SOCKREF;
1349 * Receive out-of-band data.
1352 tcp_usr_rcvoob(struct socket *so, struct mbuf *m, int flags)
1356 struct tcpcb *tp = NULL;
1359 inp = sotoinpcb(so);
1360 KASSERT(inp != NULL, ("tcp_usr_rcvoob: inp == NULL"));
1362 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
1366 tp = intotcpcb(inp);
1368 if ((so->so_oobmark == 0 &&
1369 (so->so_rcv.sb_state & SBS_RCVATMARK) == 0) ||
1370 so->so_options & SO_OOBINLINE ||
1371 tp->t_oobflags & TCPOOB_HADDATA) {
1375 if ((tp->t_oobflags & TCPOOB_HAVEDATA) == 0) {
1376 error = EWOULDBLOCK;
1380 *mtod(m, caddr_t) = tp->t_iobc;
1381 if ((flags & MSG_PEEK) == 0)
1382 tp->t_oobflags ^= (TCPOOB_HAVEDATA | TCPOOB_HADDATA);
1385 TCPDEBUG2(PRU_RCVOOB);
1386 TCP_PROBE2(debug__user, tp, PRU_RCVOOB);
1392 struct pr_usrreqs tcp_usrreqs = {
1393 .pru_abort = tcp_usr_abort,
1394 .pru_accept = tcp_usr_accept,
1395 .pru_attach = tcp_usr_attach,
1396 .pru_bind = tcp_usr_bind,
1397 .pru_connect = tcp_usr_connect,
1398 .pru_control = in_control,
1399 .pru_detach = tcp_usr_detach,
1400 .pru_disconnect = tcp_usr_disconnect,
1401 .pru_listen = tcp_usr_listen,
1402 .pru_peeraddr = in_getpeeraddr,
1403 .pru_rcvd = tcp_usr_rcvd,
1404 .pru_rcvoob = tcp_usr_rcvoob,
1405 .pru_send = tcp_usr_send,
1406 .pru_ready = tcp_usr_ready,
1407 .pru_shutdown = tcp_usr_shutdown,
1408 .pru_sockaddr = in_getsockaddr,
1409 .pru_sosetlabel = in_pcbsosetlabel,
1410 .pru_close = tcp_usr_close,
1415 struct pr_usrreqs tcp6_usrreqs = {
1416 .pru_abort = tcp_usr_abort,
1417 .pru_accept = tcp6_usr_accept,
1418 .pru_attach = tcp_usr_attach,
1419 .pru_bind = tcp6_usr_bind,
1420 .pru_connect = tcp6_usr_connect,
1421 .pru_control = in6_control,
1422 .pru_detach = tcp_usr_detach,
1423 .pru_disconnect = tcp_usr_disconnect,
1424 .pru_listen = tcp6_usr_listen,
1425 .pru_peeraddr = in6_mapped_peeraddr,
1426 .pru_rcvd = tcp_usr_rcvd,
1427 .pru_rcvoob = tcp_usr_rcvoob,
1428 .pru_send = tcp_usr_send,
1429 .pru_ready = tcp_usr_ready,
1430 .pru_shutdown = tcp_usr_shutdown,
1431 .pru_sockaddr = in6_mapped_sockaddr,
1432 .pru_sosetlabel = in_pcbsosetlabel,
1433 .pru_close = tcp_usr_close,
1439 * Common subroutine to open a TCP connection to remote host specified
1440 * by struct sockaddr_in in mbuf *nam. Call in_pcbbind to assign a local
1441 * port number if needed. Call in_pcbconnect_setup to do the routing and
1442 * to choose a local host address (interface). If there is an existing
1443 * incarnation of the same connection in TIME-WAIT state and if the remote
1444 * host was sending CC options and if the connection duration was < MSL, then
1445 * truncate the previous TIME-WAIT state and proceed.
1446 * Initialize connection parameters and enter SYN-SENT state.
1449 tcp_connect(struct tcpcb *tp, struct sockaddr *nam, struct thread *td)
1451 struct inpcb *inp = tp->t_inpcb, *oinp;
1452 struct socket *so = inp->inp_socket;
1453 struct in_addr laddr;
1457 INP_WLOCK_ASSERT(inp);
1458 INP_HASH_WLOCK(&V_tcbinfo);
1460 if (inp->inp_lport == 0) {
1461 error = in_pcbbind(inp, (struct sockaddr *)0, td->td_ucred);
1467 * Cannot simply call in_pcbconnect, because there might be an
1468 * earlier incarnation of this same connection still in
1469 * TIME_WAIT state, creating an ADDRINUSE error.
1471 laddr = inp->inp_laddr;
1472 lport = inp->inp_lport;
1473 error = in_pcbconnect_setup(inp, nam, &laddr.s_addr, &lport,
1474 &inp->inp_faddr.s_addr, &inp->inp_fport, &oinp, td->td_ucred);
1475 if (error && oinp == NULL)
1481 inp->inp_laddr = laddr;
1483 INP_HASH_WUNLOCK(&V_tcbinfo);
1486 * Compute window scaling to request:
1487 * Scale to fit into sweet spot. See tcp_syncache.c.
1488 * XXX: This should move to tcp_output().
1490 while (tp->request_r_scale < TCP_MAX_WINSHIFT &&
1491 (TCP_MAXWIN << tp->request_r_scale) < sb_max)
1492 tp->request_r_scale++;
1495 TCPSTAT_INC(tcps_connattempt);
1496 tcp_state_change(tp, TCPS_SYN_SENT);
1497 tp->iss = tcp_new_isn(&inp->inp_inc);
1498 if (tp->t_flags & TF_REQ_TSTMP)
1499 tp->ts_offset = tcp_new_ts_offset(&inp->inp_inc);
1500 tcp_sendseqinit(tp);
1505 INP_HASH_WUNLOCK(&V_tcbinfo);
1512 tcp6_connect(struct tcpcb *tp, struct sockaddr *nam, struct thread *td)
1514 struct inpcb *inp = tp->t_inpcb;
1517 INP_WLOCK_ASSERT(inp);
1518 INP_HASH_WLOCK(&V_tcbinfo);
1520 if (inp->inp_lport == 0) {
1521 error = in6_pcbbind(inp, (struct sockaddr *)0, td->td_ucred);
1525 error = in6_pcbconnect(inp, nam, td->td_ucred);
1528 INP_HASH_WUNLOCK(&V_tcbinfo);
1530 /* Compute window scaling to request. */
1531 while (tp->request_r_scale < TCP_MAX_WINSHIFT &&
1532 (TCP_MAXWIN << tp->request_r_scale) < sb_max)
1533 tp->request_r_scale++;
1535 soisconnecting(inp->inp_socket);
1536 TCPSTAT_INC(tcps_connattempt);
1537 tcp_state_change(tp, TCPS_SYN_SENT);
1538 tp->iss = tcp_new_isn(&inp->inp_inc);
1539 if (tp->t_flags & TF_REQ_TSTMP)
1540 tp->ts_offset = tcp_new_ts_offset(&inp->inp_inc);
1541 tcp_sendseqinit(tp);
1546 INP_HASH_WUNLOCK(&V_tcbinfo);
1552 * Export TCP internal state information via a struct tcp_info, based on the
1553 * Linux 2.6 API. Not ABI compatible as our constants are mapped differently
1554 * (TCP state machine, etc). We export all information using FreeBSD-native
1555 * constants -- for example, the numeric values for tcpi_state will differ
1559 tcp_fill_info(struct tcpcb *tp, struct tcp_info *ti)
1562 INP_WLOCK_ASSERT(tp->t_inpcb);
1563 bzero(ti, sizeof(*ti));
1565 ti->tcpi_state = tp->t_state;
1566 if ((tp->t_flags & TF_REQ_TSTMP) && (tp->t_flags & TF_RCVD_TSTMP))
1567 ti->tcpi_options |= TCPI_OPT_TIMESTAMPS;
1568 if (tp->t_flags & TF_SACK_PERMIT)
1569 ti->tcpi_options |= TCPI_OPT_SACK;
1570 if ((tp->t_flags & TF_REQ_SCALE) && (tp->t_flags & TF_RCVD_SCALE)) {
1571 ti->tcpi_options |= TCPI_OPT_WSCALE;
1572 ti->tcpi_snd_wscale = tp->snd_scale;
1573 ti->tcpi_rcv_wscale = tp->rcv_scale;
1575 if (tp->t_flags & TF_ECN_PERMIT)
1576 ti->tcpi_options |= TCPI_OPT_ECN;
1578 ti->tcpi_rto = tp->t_rxtcur * tick;
1579 ti->tcpi_last_data_recv = ((uint32_t)ticks - tp->t_rcvtime) * tick;
1580 ti->tcpi_rtt = ((u_int64_t)tp->t_srtt * tick) >> TCP_RTT_SHIFT;
1581 ti->tcpi_rttvar = ((u_int64_t)tp->t_rttvar * tick) >> TCP_RTTVAR_SHIFT;
1583 ti->tcpi_snd_ssthresh = tp->snd_ssthresh;
1584 ti->tcpi_snd_cwnd = tp->snd_cwnd;
1587 * FreeBSD-specific extension fields for tcp_info.
1589 ti->tcpi_rcv_space = tp->rcv_wnd;
1590 ti->tcpi_rcv_nxt = tp->rcv_nxt;
1591 ti->tcpi_snd_wnd = tp->snd_wnd;
1592 ti->tcpi_snd_bwnd = 0; /* Unused, kept for compat. */
1593 ti->tcpi_snd_nxt = tp->snd_nxt;
1594 ti->tcpi_snd_mss = tp->t_maxseg;
1595 ti->tcpi_rcv_mss = tp->t_maxseg;
1596 ti->tcpi_snd_rexmitpack = tp->t_sndrexmitpack;
1597 ti->tcpi_rcv_ooopack = tp->t_rcvoopack;
1598 ti->tcpi_snd_zerowin = tp->t_sndzerowin;
1600 if (tp->t_flags & TF_TOE) {
1601 ti->tcpi_options |= TCPI_OPT_TOE;
1602 tcp_offload_tcp_info(tp, ti);
1608 * tcp_ctloutput() must drop the inpcb lock before performing copyin on
1609 * socket option arguments. When it re-acquires the lock after the copy, it
1610 * has to revalidate that the connection is still valid for the socket
1613 #define INP_WLOCK_RECHECK_CLEANUP(inp, cleanup) do { \
1615 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) { \
1618 return (ECONNRESET); \
1620 tp = intotcpcb(inp); \
1622 #define INP_WLOCK_RECHECK(inp) INP_WLOCK_RECHECK_CLEANUP((inp), /* noop */)
1625 tcp_ctloutput(struct socket *so, struct sockopt *sopt)
1630 struct tcp_function_block *blk;
1631 struct tcp_function_set fsn;
1634 inp = sotoinpcb(so);
1635 KASSERT(inp != NULL, ("tcp_ctloutput: inp == NULL"));
1636 if (sopt->sopt_level != IPPROTO_TCP) {
1638 if (inp->inp_vflag & INP_IPV6PROTO) {
1639 error = ip6_ctloutput(so, sopt);
1641 * In case of the IPV6_USE_MIN_MTU socket option,
1642 * the INC_IPV6MINMTU flag to announce a corresponding
1643 * MSS during the initial handshake.
1644 * If the TCP connection is not in the front states,
1645 * just reduce the MSS being used.
1646 * This avoids the sending of TCP segments which will
1647 * be fragmented at the IPv6 layer.
1650 (sopt->sopt_dir == SOPT_SET) &&
1651 (sopt->sopt_level == IPPROTO_IPV6) &&
1652 (sopt->sopt_name == IPV6_USE_MIN_MTU)) {
1654 if ((inp->inp_flags &
1655 (INP_TIMEWAIT | INP_DROPPED))) {
1657 return (ECONNRESET);
1659 inp->inp_inc.inc_flags |= INC_IPV6MINMTU;
1660 tp = intotcpcb(inp);
1661 if ((tp->t_state >= TCPS_SYN_SENT) &&
1662 (inp->inp_inc.inc_flags & INC_ISIPV6)) {
1663 struct ip6_pktopts *opt;
1665 opt = inp->in6p_outputopts;
1666 if ((opt != NULL) &&
1667 (opt->ip6po_minmtu ==
1668 IP6PO_MINMTU_ALL)) {
1669 if (tp->t_maxseg > TCP6_MSS) {
1670 tp->t_maxseg = TCP6_MSS;
1678 #if defined(INET6) && defined(INET)
1683 error = ip_ctloutput(so, sopt);
1689 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
1691 return (ECONNRESET);
1693 tp = intotcpcb(inp);
1695 * Protect the TCP option TCP_FUNCTION_BLK so
1696 * that a sub-function can *never* overwrite this.
1698 if ((sopt->sopt_dir == SOPT_SET) &&
1699 (sopt->sopt_name == TCP_FUNCTION_BLK)) {
1701 error = sooptcopyin(sopt, &fsn, sizeof fsn,
1705 INP_WLOCK_RECHECK(inp);
1706 blk = find_and_ref_tcp_functions(&fsn);
1711 if (tp->t_fb == blk) {
1712 /* You already have this */
1713 refcount_release(&blk->tfb_refcnt);
1717 if (tp->t_state != TCPS_CLOSED) {
1719 * The user has advanced the state
1720 * past the initial point, we may not
1721 * be able to switch.
1723 if (blk->tfb_tcp_handoff_ok != NULL) {
1725 * Does the stack provide a
1726 * query mechanism, if so it may
1727 * still be possible?
1729 error = (*blk->tfb_tcp_handoff_ok)(tp);
1733 refcount_release(&blk->tfb_refcnt);
1738 if (blk->tfb_flags & TCP_FUNC_BEING_REMOVED) {
1739 refcount_release(&blk->tfb_refcnt);
1744 * Release the old refcnt, the
1745 * lookup acquired a ref on the
1748 if (tp->t_fb->tfb_tcp_fb_fini) {
1750 * Tell the stack to cleanup with 0 i.e.
1751 * the tcb is not going away.
1753 (*tp->t_fb->tfb_tcp_fb_fini)(tp, 0);
1756 /* Assure that we are not on any hpts */
1757 tcp_hpts_remove(tp->t_inpcb, HPTS_REMOVE_ALL);
1759 if (blk->tfb_tcp_fb_init) {
1760 error = (*blk->tfb_tcp_fb_init)(tp);
1762 refcount_release(&blk->tfb_refcnt);
1763 if (tp->t_fb->tfb_tcp_fb_init) {
1764 if((*tp->t_fb->tfb_tcp_fb_init)(tp) != 0) {
1765 /* Fall back failed, drop the connection */
1774 refcount_release(&tp->t_fb->tfb_refcnt);
1777 if (tp->t_flags & TF_TOE) {
1778 tcp_offload_ctloutput(tp, sopt->sopt_dir,
1785 } else if ((sopt->sopt_dir == SOPT_GET) &&
1786 (sopt->sopt_name == TCP_FUNCTION_BLK)) {
1787 strncpy(fsn.function_set_name, tp->t_fb->tfb_tcp_block_name,
1788 TCP_FUNCTION_NAME_LEN_MAX);
1789 fsn.function_set_name[TCP_FUNCTION_NAME_LEN_MAX - 1] = '\0';
1790 fsn.pcbcnt = tp->t_fb->tfb_refcnt;
1792 error = sooptcopyout(sopt, &fsn, sizeof fsn);
1795 /* Pass in the INP locked, called must unlock it */
1796 return (tp->t_fb->tfb_tcp_ctloutput(so, sopt, inp, tp));
1800 * If this assert becomes untrue, we need to change the size of the buf
1801 * variable in tcp_default_ctloutput().
1804 CTASSERT(TCP_CA_NAME_MAX <= TCP_LOG_ID_LEN);
1805 CTASSERT(TCP_LOG_REASON_LEN <= TCP_LOG_ID_LEN);
1809 tcp_default_ctloutput(struct socket *so, struct sockopt *sopt, struct inpcb *inp, struct tcpcb *tp)
1811 int error, opt, optval;
1815 struct tls_enable tls;
1817 struct cc_algo *algo;
1818 char *pbuf, buf[TCP_LOG_ID_LEN];
1822 * For TCP_CCALGOOPT forward the control to CC module, for both
1823 * SOPT_SET and SOPT_GET.
1825 switch (sopt->sopt_name) {
1828 if (sopt->sopt_valsize > CC_ALGOOPT_LIMIT)
1830 pbuf = malloc(sopt->sopt_valsize, M_TEMP, M_WAITOK | M_ZERO);
1831 error = sooptcopyin(sopt, pbuf, sopt->sopt_valsize,
1832 sopt->sopt_valsize);
1837 INP_WLOCK_RECHECK_CLEANUP(inp, free(pbuf, M_TEMP));
1838 if (CC_ALGO(tp)->ctl_output != NULL)
1839 error = CC_ALGO(tp)->ctl_output(tp->ccv, sopt, pbuf);
1843 if (error == 0 && sopt->sopt_dir == SOPT_GET)
1844 error = sooptcopyout(sopt, pbuf, sopt->sopt_valsize);
1849 switch (sopt->sopt_dir) {
1851 switch (sopt->sopt_name) {
1852 #if defined(IPSEC_SUPPORT) || defined(TCP_SIGNATURE)
1854 if (!TCPMD5_ENABLED()) {
1856 return (ENOPROTOOPT);
1858 error = TCPMD5_PCBCTL(inp, sopt);
1861 goto unlock_and_done;
1867 error = sooptcopyin(sopt, &optval, sizeof optval,
1872 INP_WLOCK_RECHECK(inp);
1873 switch (sopt->sopt_name) {
1881 opt = 0; /* dead code to fool gcc */
1888 tp->t_flags &= ~opt;
1891 if (tp->t_flags & TF_TOE) {
1892 tcp_offload_ctloutput(tp, sopt->sopt_dir,
1901 error = sooptcopyin(sopt, &optval, sizeof optval,
1906 INP_WLOCK_RECHECK(inp);
1908 tp->t_flags |= TF_NOPUSH;
1909 else if (tp->t_flags & TF_NOPUSH) {
1910 tp->t_flags &= ~TF_NOPUSH;
1911 if (TCPS_HAVEESTABLISHED(tp->t_state))
1912 error = tp->t_fb->tfb_tcp_output(tp);
1914 goto unlock_and_done;
1918 error = sooptcopyin(sopt, &optval, sizeof optval,
1923 INP_WLOCK_RECHECK(inp);
1924 if (optval > 0 && optval <= tp->t_maxseg &&
1925 optval + 40 >= V_tcp_minmss)
1926 tp->t_maxseg = optval;
1929 goto unlock_and_done;
1936 case TCP_CONGESTION:
1938 error = sooptcopyin(sopt, buf, TCP_CA_NAME_MAX - 1, 1);
1941 buf[sopt->sopt_valsize] = '\0';
1942 INP_WLOCK_RECHECK(inp);
1944 STAILQ_FOREACH(algo, &cc_list, entries)
1945 if (strncmp(buf, algo->name,
1946 TCP_CA_NAME_MAX) == 0)
1955 * We hold a write lock over the tcb so it's safe to
1956 * do these things without ordering concerns.
1958 if (CC_ALGO(tp)->cb_destroy != NULL)
1959 CC_ALGO(tp)->cb_destroy(tp->ccv);
1963 * If something goes pear shaped initialising the new
1964 * algo, fall back to newreno (which does not
1965 * require initialisation).
1967 if (algo->cb_init != NULL &&
1968 algo->cb_init(tp->ccv) != 0) {
1969 CC_ALGO(tp) = &newreno_cc_algo;
1971 * The only reason init should fail is
1972 * because of malloc.
1980 case TCP_TXTLS_ENABLE:
1982 error = sooptcopyin(sopt, &tls, sizeof(tls),
1986 error = ktls_enable_tx(so, &tls);
1988 case TCP_TXTLS_MODE:
1990 error = sooptcopyin(sopt, &ui, sizeof(ui), sizeof(ui));
1994 INP_WLOCK_RECHECK(inp);
1995 error = ktls_set_tx_mode(so, ui);
2004 error = sooptcopyin(sopt, &ui, sizeof(ui), sizeof(ui));
2008 if (ui > (UINT_MAX / hz)) {
2014 INP_WLOCK_RECHECK(inp);
2015 switch (sopt->sopt_name) {
2017 tp->t_keepidle = ui;
2019 * XXX: better check current remaining
2020 * timeout and "merge" it with new value.
2022 if ((tp->t_state > TCPS_LISTEN) &&
2023 (tp->t_state <= TCPS_CLOSING))
2024 tcp_timer_activate(tp, TT_KEEP,
2028 tp->t_keepintvl = ui;
2029 if ((tp->t_state == TCPS_FIN_WAIT_2) &&
2030 (TP_MAXIDLE(tp) > 0))
2031 tcp_timer_activate(tp, TT_2MSL,
2035 tp->t_keepinit = ui;
2036 if (tp->t_state == TCPS_SYN_RECEIVED ||
2037 tp->t_state == TCPS_SYN_SENT)
2038 tcp_timer_activate(tp, TT_KEEP,
2042 goto unlock_and_done;
2046 error = sooptcopyin(sopt, &ui, sizeof(ui), sizeof(ui));
2050 INP_WLOCK_RECHECK(inp);
2052 if ((tp->t_state == TCPS_FIN_WAIT_2) &&
2053 (TP_MAXIDLE(tp) > 0))
2054 tcp_timer_activate(tp, TT_2MSL,
2056 goto unlock_and_done;
2062 error = sooptcopyin(sopt, &optval, sizeof optval,
2067 INP_WLOCK_RECHECK(inp);
2069 tcp_pcap_set_sock_max(TCP_PCAP_OUT ?
2070 &(tp->t_outpkts) : &(tp->t_inpkts),
2074 goto unlock_and_done;
2077 case TCP_FASTOPEN: {
2078 struct tcp_fastopen tfo_optval;
2081 if (!V_tcp_fastopen_client_enable &&
2082 !V_tcp_fastopen_server_enable)
2085 error = sooptcopyin(sopt, &tfo_optval,
2086 sizeof(tfo_optval), sizeof(int));
2090 INP_WLOCK_RECHECK(inp);
2091 if (tfo_optval.enable) {
2092 if (tp->t_state == TCPS_LISTEN) {
2093 if (!V_tcp_fastopen_server_enable) {
2095 goto unlock_and_done;
2098 tp->t_flags |= TF_FASTOPEN;
2099 if (tp->t_tfo_pending == NULL)
2101 tcp_fastopen_alloc_counter();
2104 * If a pre-shared key was provided,
2105 * stash it in the client cookie
2106 * field of the tcpcb for use during
2109 if (sopt->sopt_valsize ==
2110 sizeof(tfo_optval)) {
2111 memcpy(tp->t_tfo_cookie.client,
2113 TCP_FASTOPEN_PSK_LEN);
2114 tp->t_tfo_client_cookie_len =
2115 TCP_FASTOPEN_PSK_LEN;
2117 tp->t_flags |= TF_FASTOPEN;
2120 tp->t_flags &= ~TF_FASTOPEN;
2121 goto unlock_and_done;
2127 error = sooptcopyin(sopt, &optval, sizeof optval,
2132 INP_WLOCK_RECHECK(inp);
2133 error = tcp_log_state_change(tp, optval);
2134 goto unlock_and_done;
2143 error = sooptcopyin(sopt, buf, TCP_LOG_ID_LEN - 1, 0);
2146 buf[sopt->sopt_valsize] = '\0';
2147 INP_WLOCK_RECHECK(inp);
2148 error = tcp_log_set_id(tp, buf);
2149 /* tcp_log_set_id() unlocks the INP. */
2156 sooptcopyin(sopt, buf, TCP_LOG_REASON_LEN - 1, 0);
2159 buf[sopt->sopt_valsize] = '\0';
2160 INP_WLOCK_RECHECK(inp);
2161 if (sopt->sopt_name == TCP_LOGDUMP) {
2162 error = tcp_log_dump_tp_logbuf(tp, buf,
2166 tcp_log_dump_tp_bucket_logbufs(tp, buf);
2168 * tcp_log_dump_tp_bucket_logbufs() drops the
2177 error = ENOPROTOOPT;
2183 tp = intotcpcb(inp);
2184 switch (sopt->sopt_name) {
2185 #if defined(IPSEC_SUPPORT) || defined(TCP_SIGNATURE)
2187 if (!TCPMD5_ENABLED()) {
2189 return (ENOPROTOOPT);
2191 error = TCPMD5_PCBCTL(inp, sopt);
2196 optval = tp->t_flags & TF_NODELAY;
2198 error = sooptcopyout(sopt, &optval, sizeof optval);
2201 optval = tp->t_maxseg;
2203 error = sooptcopyout(sopt, &optval, sizeof optval);
2206 optval = tp->t_flags & TF_NOOPT;
2208 error = sooptcopyout(sopt, &optval, sizeof optval);
2211 optval = tp->t_flags & TF_NOPUSH;
2213 error = sooptcopyout(sopt, &optval, sizeof optval);
2216 tcp_fill_info(tp, &ti);
2218 error = sooptcopyout(sopt, &ti, sizeof ti);
2220 case TCP_CONGESTION:
2221 len = strlcpy(buf, CC_ALGO(tp)->name, TCP_CA_NAME_MAX);
2223 error = sooptcopyout(sopt, buf, len + 1);
2229 switch (sopt->sopt_name) {
2231 ui = TP_KEEPIDLE(tp) / hz;
2234 ui = TP_KEEPINTVL(tp) / hz;
2237 ui = TP_KEEPINIT(tp) / hz;
2240 ui = TP_KEEPCNT(tp);
2244 error = sooptcopyout(sopt, &ui, sizeof(ui));
2249 optval = tcp_pcap_get_sock_max(TCP_PCAP_OUT ?
2250 &(tp->t_outpkts) : &(tp->t_inpkts));
2252 error = sooptcopyout(sopt, &optval, sizeof optval);
2256 optval = tp->t_flags & TF_FASTOPEN;
2258 error = sooptcopyout(sopt, &optval, sizeof optval);
2262 optval = tp->t_logstate;
2264 error = sooptcopyout(sopt, &optval, sizeof(optval));
2267 /* tcp_log_getlogbuf() does INP_WUNLOCK(inp) */
2268 error = tcp_log_getlogbuf(sopt, tp);
2271 len = tcp_log_get_id(tp, buf);
2273 error = sooptcopyout(sopt, buf, len + 1);
2282 case TCP_TXTLS_MODE:
2283 optval = ktls_get_tx_mode(so);
2285 error = sooptcopyout(sopt, &optval, sizeof(optval));
2290 error = ENOPROTOOPT;
2297 #undef INP_WLOCK_RECHECK
2298 #undef INP_WLOCK_RECHECK_CLEANUP
2301 * Attach TCP protocol to socket, allocating
2302 * internet protocol control block, tcp control block,
2303 * bufer space, and entering LISTEN state if to accept connections.
2306 tcp_attach(struct socket *so)
2310 struct epoch_tracker et;
2313 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
2314 error = soreserve(so, V_tcp_sendspace, V_tcp_recvspace);
2318 so->so_rcv.sb_flags |= SB_AUTOSIZE;
2319 so->so_snd.sb_flags |= SB_AUTOSIZE;
2320 NET_EPOCH_ENTER(et);
2321 error = in_pcballoc(so, &V_tcbinfo);
2326 inp = sotoinpcb(so);
2328 if (inp->inp_vflag & INP_IPV6PROTO) {
2329 inp->inp_vflag |= INP_IPV6;
2330 if ((inp->inp_flags & IN6P_IPV6_V6ONLY) == 0)
2331 inp->inp_vflag |= INP_IPV4;
2332 inp->in6p_hops = -1; /* use kernel default */
2336 inp->inp_vflag |= INP_IPV4;
2337 tp = tcp_newtcpcb(inp);
2344 tp->t_state = TCPS_CLOSED;
2347 TCPSTATES_INC(TCPS_CLOSED);
2352 * Initiate (or continue) disconnect.
2353 * If embryonic state, just send reset (once).
2354 * If in ``let data drain'' option and linger null, just drop.
2355 * Otherwise (hard), mark socket disconnecting and drop
2356 * current input data; switch states based on user close, and
2357 * send segment to peer (with FIN).
2360 tcp_disconnect(struct tcpcb *tp)
2362 struct inpcb *inp = tp->t_inpcb;
2363 struct socket *so = inp->inp_socket;
2366 INP_WLOCK_ASSERT(inp);
2369 * Neither tcp_close() nor tcp_drop() should return NULL, as the
2370 * socket is still open.
2372 if (tp->t_state < TCPS_ESTABLISHED &&
2373 !(tp->t_state > TCPS_LISTEN && IS_FASTOPEN(tp->t_flags))) {
2376 ("tcp_disconnect: tcp_close() returned NULL"));
2377 } else if ((so->so_options & SO_LINGER) && so->so_linger == 0) {
2378 tp = tcp_drop(tp, 0);
2380 ("tcp_disconnect: tcp_drop() returned NULL"));
2382 soisdisconnecting(so);
2383 sbflush(&so->so_rcv);
2385 if (!(inp->inp_flags & INP_DROPPED))
2386 tp->t_fb->tfb_tcp_output(tp);
2391 * User issued close, and wish to trail through shutdown states:
2392 * if never received SYN, just forget it. If got a SYN from peer,
2393 * but haven't sent FIN, then go to FIN_WAIT_1 state to send peer a FIN.
2394 * If already got a FIN from peer, then almost done; go to LAST_ACK
2395 * state. In all other cases, have already sent FIN to peer (e.g.
2396 * after PRU_SHUTDOWN), and just have to play tedious game waiting
2397 * for peer to send FIN or not respond to keep-alives, etc.
2398 * We can let the user exit from the close as soon as the FIN is acked.
2401 tcp_usrclosed(struct tcpcb *tp)
2405 INP_WLOCK_ASSERT(tp->t_inpcb);
2407 switch (tp->t_state) {
2410 tcp_offload_listen_stop(tp);
2412 tcp_state_change(tp, TCPS_CLOSED);
2417 * tcp_close() should never return NULL here as the socket is
2421 ("tcp_usrclosed: tcp_close() returned NULL"));
2425 case TCPS_SYN_RECEIVED:
2426 tp->t_flags |= TF_NEEDFIN;
2429 case TCPS_ESTABLISHED:
2430 tcp_state_change(tp, TCPS_FIN_WAIT_1);
2433 case TCPS_CLOSE_WAIT:
2434 tcp_state_change(tp, TCPS_LAST_ACK);
2437 if (tp->t_state >= TCPS_FIN_WAIT_2) {
2438 soisdisconnected(tp->t_inpcb->inp_socket);
2439 /* Prevent the connection hanging in FIN_WAIT_2 forever. */
2440 if (tp->t_state == TCPS_FIN_WAIT_2) {
2443 timeout = (tcp_fast_finwait2_recycle) ?
2444 tcp_finwait2_timeout : TP_MAXIDLE(tp);
2445 tcp_timer_activate(tp, TT_2MSL, timeout);
2452 db_print_indent(int indent)
2456 for (i = 0; i < indent; i++)
2461 db_print_tstate(int t_state)
2466 db_printf("TCPS_CLOSED");
2470 db_printf("TCPS_LISTEN");
2474 db_printf("TCPS_SYN_SENT");
2477 case TCPS_SYN_RECEIVED:
2478 db_printf("TCPS_SYN_RECEIVED");
2481 case TCPS_ESTABLISHED:
2482 db_printf("TCPS_ESTABLISHED");
2485 case TCPS_CLOSE_WAIT:
2486 db_printf("TCPS_CLOSE_WAIT");
2489 case TCPS_FIN_WAIT_1:
2490 db_printf("TCPS_FIN_WAIT_1");
2494 db_printf("TCPS_CLOSING");
2498 db_printf("TCPS_LAST_ACK");
2501 case TCPS_FIN_WAIT_2:
2502 db_printf("TCPS_FIN_WAIT_2");
2505 case TCPS_TIME_WAIT:
2506 db_printf("TCPS_TIME_WAIT");
2510 db_printf("unknown");
2516 db_print_tflags(u_int t_flags)
2521 if (t_flags & TF_ACKNOW) {
2522 db_printf("%sTF_ACKNOW", comma ? ", " : "");
2525 if (t_flags & TF_DELACK) {
2526 db_printf("%sTF_DELACK", comma ? ", " : "");
2529 if (t_flags & TF_NODELAY) {
2530 db_printf("%sTF_NODELAY", comma ? ", " : "");
2533 if (t_flags & TF_NOOPT) {
2534 db_printf("%sTF_NOOPT", comma ? ", " : "");
2537 if (t_flags & TF_SENTFIN) {
2538 db_printf("%sTF_SENTFIN", comma ? ", " : "");
2541 if (t_flags & TF_REQ_SCALE) {
2542 db_printf("%sTF_REQ_SCALE", comma ? ", " : "");
2545 if (t_flags & TF_RCVD_SCALE) {
2546 db_printf("%sTF_RECVD_SCALE", comma ? ", " : "");
2549 if (t_flags & TF_REQ_TSTMP) {
2550 db_printf("%sTF_REQ_TSTMP", comma ? ", " : "");
2553 if (t_flags & TF_RCVD_TSTMP) {
2554 db_printf("%sTF_RCVD_TSTMP", comma ? ", " : "");
2557 if (t_flags & TF_SACK_PERMIT) {
2558 db_printf("%sTF_SACK_PERMIT", comma ? ", " : "");
2561 if (t_flags & TF_NEEDSYN) {
2562 db_printf("%sTF_NEEDSYN", comma ? ", " : "");
2565 if (t_flags & TF_NEEDFIN) {
2566 db_printf("%sTF_NEEDFIN", comma ? ", " : "");
2569 if (t_flags & TF_NOPUSH) {
2570 db_printf("%sTF_NOPUSH", comma ? ", " : "");
2573 if (t_flags & TF_MORETOCOME) {
2574 db_printf("%sTF_MORETOCOME", comma ? ", " : "");
2577 if (t_flags & TF_LQ_OVERFLOW) {
2578 db_printf("%sTF_LQ_OVERFLOW", comma ? ", " : "");
2581 if (t_flags & TF_LASTIDLE) {
2582 db_printf("%sTF_LASTIDLE", comma ? ", " : "");
2585 if (t_flags & TF_RXWIN0SENT) {
2586 db_printf("%sTF_RXWIN0SENT", comma ? ", " : "");
2589 if (t_flags & TF_FASTRECOVERY) {
2590 db_printf("%sTF_FASTRECOVERY", comma ? ", " : "");
2593 if (t_flags & TF_CONGRECOVERY) {
2594 db_printf("%sTF_CONGRECOVERY", comma ? ", " : "");
2597 if (t_flags & TF_WASFRECOVERY) {
2598 db_printf("%sTF_WASFRECOVERY", comma ? ", " : "");
2601 if (t_flags & TF_SIGNATURE) {
2602 db_printf("%sTF_SIGNATURE", comma ? ", " : "");
2605 if (t_flags & TF_FORCEDATA) {
2606 db_printf("%sTF_FORCEDATA", comma ? ", " : "");
2609 if (t_flags & TF_TSO) {
2610 db_printf("%sTF_TSO", comma ? ", " : "");
2613 if (t_flags & TF_ECN_PERMIT) {
2614 db_printf("%sTF_ECN_PERMIT", comma ? ", " : "");
2617 if (t_flags & TF_FASTOPEN) {
2618 db_printf("%sTF_FASTOPEN", comma ? ", " : "");
2624 db_print_toobflags(char t_oobflags)
2629 if (t_oobflags & TCPOOB_HAVEDATA) {
2630 db_printf("%sTCPOOB_HAVEDATA", comma ? ", " : "");
2633 if (t_oobflags & TCPOOB_HADDATA) {
2634 db_printf("%sTCPOOB_HADDATA", comma ? ", " : "");
2640 db_print_tcpcb(struct tcpcb *tp, const char *name, int indent)
2643 db_print_indent(indent);
2644 db_printf("%s at %p\n", name, tp);
2648 db_print_indent(indent);
2649 db_printf("t_segq first: %p t_segqlen: %d t_dupacks: %d\n",
2650 TAILQ_FIRST(&tp->t_segq), tp->t_segqlen, tp->t_dupacks);
2652 db_print_indent(indent);
2653 db_printf("tt_rexmt: %p tt_persist: %p tt_keep: %p\n",
2654 &tp->t_timers->tt_rexmt, &tp->t_timers->tt_persist, &tp->t_timers->tt_keep);
2656 db_print_indent(indent);
2657 db_printf("tt_2msl: %p tt_delack: %p t_inpcb: %p\n", &tp->t_timers->tt_2msl,
2658 &tp->t_timers->tt_delack, tp->t_inpcb);
2660 db_print_indent(indent);
2661 db_printf("t_state: %d (", tp->t_state);
2662 db_print_tstate(tp->t_state);
2665 db_print_indent(indent);
2666 db_printf("t_flags: 0x%x (", tp->t_flags);
2667 db_print_tflags(tp->t_flags);
2670 db_print_indent(indent);
2671 db_printf("snd_una: 0x%08x snd_max: 0x%08x snd_nxt: x0%08x\n",
2672 tp->snd_una, tp->snd_max, tp->snd_nxt);
2674 db_print_indent(indent);
2675 db_printf("snd_up: 0x%08x snd_wl1: 0x%08x snd_wl2: 0x%08x\n",
2676 tp->snd_up, tp->snd_wl1, tp->snd_wl2);
2678 db_print_indent(indent);
2679 db_printf("iss: 0x%08x irs: 0x%08x rcv_nxt: 0x%08x\n",
2680 tp->iss, tp->irs, tp->rcv_nxt);
2682 db_print_indent(indent);
2683 db_printf("rcv_adv: 0x%08x rcv_wnd: %u rcv_up: 0x%08x\n",
2684 tp->rcv_adv, tp->rcv_wnd, tp->rcv_up);
2686 db_print_indent(indent);
2687 db_printf("snd_wnd: %u snd_cwnd: %u\n",
2688 tp->snd_wnd, tp->snd_cwnd);
2690 db_print_indent(indent);
2691 db_printf("snd_ssthresh: %u snd_recover: "
2692 "0x%08x\n", tp->snd_ssthresh, tp->snd_recover);
2694 db_print_indent(indent);
2695 db_printf("t_rcvtime: %u t_startime: %u\n",
2696 tp->t_rcvtime, tp->t_starttime);
2698 db_print_indent(indent);
2699 db_printf("t_rttime: %u t_rtsq: 0x%08x\n",
2700 tp->t_rtttime, tp->t_rtseq);
2702 db_print_indent(indent);
2703 db_printf("t_rxtcur: %d t_maxseg: %u t_srtt: %d\n",
2704 tp->t_rxtcur, tp->t_maxseg, tp->t_srtt);
2706 db_print_indent(indent);
2707 db_printf("t_rttvar: %d t_rxtshift: %d t_rttmin: %u "
2708 "t_rttbest: %u\n", tp->t_rttvar, tp->t_rxtshift, tp->t_rttmin,
2711 db_print_indent(indent);
2712 db_printf("t_rttupdated: %lu max_sndwnd: %u t_softerror: %d\n",
2713 tp->t_rttupdated, tp->max_sndwnd, tp->t_softerror);
2715 db_print_indent(indent);
2716 db_printf("t_oobflags: 0x%x (", tp->t_oobflags);
2717 db_print_toobflags(tp->t_oobflags);
2718 db_printf(") t_iobc: 0x%02x\n", tp->t_iobc);
2720 db_print_indent(indent);
2721 db_printf("snd_scale: %u rcv_scale: %u request_r_scale: %u\n",
2722 tp->snd_scale, tp->rcv_scale, tp->request_r_scale);
2724 db_print_indent(indent);
2725 db_printf("ts_recent: %u ts_recent_age: %u\n",
2726 tp->ts_recent, tp->ts_recent_age);
2728 db_print_indent(indent);
2729 db_printf("ts_offset: %u last_ack_sent: 0x%08x snd_cwnd_prev: "
2730 "%u\n", tp->ts_offset, tp->last_ack_sent, tp->snd_cwnd_prev);
2732 db_print_indent(indent);
2733 db_printf("snd_ssthresh_prev: %u snd_recover_prev: 0x%08x "
2734 "t_badrxtwin: %u\n", tp->snd_ssthresh_prev,
2735 tp->snd_recover_prev, tp->t_badrxtwin);
2737 db_print_indent(indent);
2738 db_printf("snd_numholes: %d snd_holes first: %p\n",
2739 tp->snd_numholes, TAILQ_FIRST(&tp->snd_holes));
2741 db_print_indent(indent);
2742 db_printf("snd_fack: 0x%08x rcv_numsacks: %d sack_newdata: "
2743 "0x%08x\n", tp->snd_fack, tp->rcv_numsacks, tp->sack_newdata);
2745 /* Skip sackblks, sackhint. */
2747 db_print_indent(indent);
2748 db_printf("t_rttlow: %d rfbuf_ts: %u rfbuf_cnt: %d\n",
2749 tp->t_rttlow, tp->rfbuf_ts, tp->rfbuf_cnt);
2752 DB_SHOW_COMMAND(tcpcb, db_show_tcpcb)
2757 db_printf("usage: show tcpcb <addr>\n");
2760 tp = (struct tcpcb *)addr;
2762 db_print_tcpcb(tp, "tcpcb", 0);