2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 1982, 1986, 1988, 1993
5 * The Regents of the University of California.
6 * Copyright (c) 2006-2007 Robert N. M. Watson
7 * Copyright (c) 2010-2011 Juniper Networks, Inc.
10 * Portions of this software were developed by Robert N. M. Watson under
11 * contract to Juniper Networks, Inc.
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its contributors
22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * From: @(#)tcp_usrreq.c 8.2 (Berkeley) 1/3/94
40 #include <sys/cdefs.h>
41 __FBSDID("$FreeBSD$");
45 #include "opt_inet6.h"
46 #include "opt_ipsec.h"
47 #include "opt_tcpdebug.h"
49 #include <sys/param.h>
50 #include <sys/systm.h>
51 #include <sys/limits.h>
52 #include <sys/malloc.h>
53 #include <sys/refcount.h>
54 #include <sys/kernel.h>
55 #include <sys/sysctl.h>
58 #include <sys/domain.h>
60 #include <sys/socket.h>
61 #include <sys/socketvar.h>
62 #include <sys/protosw.h>
65 #include <sys/syslog.h>
72 #include <net/if_var.h>
73 #include <net/route.h>
76 #include <netinet/in.h>
77 #include <netinet/in_kdtrace.h>
78 #include <netinet/in_pcb.h>
79 #include <netinet/in_systm.h>
80 #include <netinet/in_var.h>
81 #include <netinet/ip_var.h>
83 #include <netinet/ip6.h>
84 #include <netinet6/in6_pcb.h>
85 #include <netinet6/ip6_var.h>
86 #include <netinet6/scope6_var.h>
88 #include <netinet/tcp.h>
89 #include <netinet/tcp_fsm.h>
90 #include <netinet/tcp_seq.h>
91 #include <netinet/tcp_timer.h>
92 #include <netinet/tcp_var.h>
93 #include <netinet/tcp_log_buf.h>
94 #include <netinet/tcpip.h>
95 #include <netinet/cc/cc.h>
96 #include <netinet/tcp_fastopen.h>
97 #include <netinet/tcp_hpts.h>
99 #include <netinet/tcp_pcap.h>
102 #include <netinet/tcp_debug.h>
105 #include <netinet/tcp_offload.h>
107 #include <netipsec/ipsec_support.h>
110 * TCP protocol interface to socket abstraction.
112 static int tcp_attach(struct socket *);
114 static int tcp_connect(struct tcpcb *, struct sockaddr *,
118 static int tcp6_connect(struct tcpcb *, struct sockaddr *,
121 static void tcp_disconnect(struct tcpcb *);
122 static void tcp_usrclosed(struct tcpcb *);
123 static void tcp_fill_info(struct tcpcb *, struct tcp_info *);
126 #define TCPDEBUG0 int ostate = 0
127 #define TCPDEBUG1() ostate = tp ? tp->t_state : 0
128 #define TCPDEBUG2(req) if (tp && (so->so_options & SO_DEBUG)) \
129 tcp_trace(TA_USER, ostate, tp, 0, 0, req)
133 #define TCPDEBUG2(req)
137 * TCP attaches to socket via pru_attach(), reserving space,
138 * and an internet control block.
141 tcp_usr_attach(struct socket *so, int proto, struct thread *td)
144 struct tcpcb *tp = NULL;
149 KASSERT(inp == NULL, ("tcp_usr_attach: inp != NULL"));
152 error = tcp_attach(so);
156 if ((so->so_options & SO_LINGER) && so->so_linger == 0)
157 so->so_linger = TCP_LINGERTIME;
162 TCPDEBUG2(PRU_ATTACH);
163 TCP_PROBE2(debug__user, tp, PRU_ATTACH);
168 * tcp_detach is called when the socket layer loses its final reference
169 * to the socket, be it a file descriptor reference, a reference from TCP,
170 * etc. At this point, there is only one case in which we will keep around
171 * inpcb state: time wait.
173 * This function can probably be re-absorbed back into tcp_usr_detach() now
174 * that there is a single detach path.
177 tcp_detach(struct socket *so, struct inpcb *inp)
181 INP_INFO_LOCK_ASSERT(&V_tcbinfo);
182 INP_WLOCK_ASSERT(inp);
184 KASSERT(so->so_pcb == inp, ("tcp_detach: so_pcb != inp"));
185 KASSERT(inp->inp_socket == so, ("tcp_detach: inp_socket != so"));
189 if (inp->inp_flags & INP_TIMEWAIT) {
191 * There are two cases to handle: one in which the time wait
192 * state is being discarded (INP_DROPPED), and one in which
193 * this connection will remain in timewait. In the former,
194 * it is time to discard all state (except tcptw, which has
195 * already been discarded by the timewait close code, which
196 * should be further up the call stack somewhere). In the
197 * latter case, we detach from the socket, but leave the pcb
198 * present until timewait ends.
200 * XXXRW: Would it be cleaner to free the tcptw here?
202 * Astute question indeed, from twtcp perspective there are
203 * four cases to consider:
205 * #1 tcp_detach is called at tcptw creation time by
206 * tcp_twstart, then do not discard the newly created tcptw
207 * and leave inpcb present until timewait ends
208 * #2 tcp_detach is called at tcptw creation time by
209 * tcp_twstart, but connection is local and tw will be
210 * discarded immediately
211 * #3 tcp_detach is called at timewait end (or reuse) by
212 * tcp_twclose, then the tcptw has already been discarded
213 * (or reused) and inpcb is freed here
214 * #4 tcp_detach is called() after timewait ends (or reuse)
215 * (e.g. by soclose), then tcptw has already been discarded
216 * (or reused) and inpcb is freed here
218 * In all three cases the tcptw should not be freed here.
220 if (inp->inp_flags & INP_DROPPED) {
222 if (__predict_true(tp == NULL)) {
226 * This case should not happen as in TIMEWAIT
227 * state the inp should not be destroyed before
228 * its tcptw. If INVARIANTS is defined, panic.
231 panic("%s: Panic before an inp double-free: "
232 "INP_TIMEWAIT && INP_DROPPED && tp != NULL"
235 log(LOG_ERR, "%s: Avoid an inp double-free: "
236 "INP_TIMEWAIT && INP_DROPPED && tp != NULL"
247 * If the connection is not in timewait, we consider two
248 * two conditions: one in which no further processing is
249 * necessary (dropped || embryonic), and one in which TCP is
250 * not yet done, but no longer requires the socket, so the
251 * pcb will persist for the time being.
253 * XXXRW: Does the second case still occur?
255 if (inp->inp_flags & INP_DROPPED ||
256 tp->t_state < TCPS_SYN_SENT) {
268 * pru_detach() detaches the TCP protocol from the socket.
269 * If the protocol state is non-embryonic, then can't
270 * do this directly: have to initiate a pru_disconnect(),
271 * which may finish later; embryonic TCB's can just
275 tcp_usr_detach(struct socket *so)
279 struct epoch_tracker et;
282 KASSERT(inp != NULL, ("tcp_usr_detach: inp == NULL"));
283 if (!INP_INFO_WLOCKED(&V_tcbinfo)) {
284 INP_INFO_RLOCK_ET(&V_tcbinfo, et);
288 KASSERT(inp->inp_socket != NULL,
289 ("tcp_usr_detach: inp_socket == NULL"));
292 INP_INFO_RUNLOCK_ET(&V_tcbinfo, et);
297 * Give the socket an address.
300 tcp_usr_bind(struct socket *so, struct sockaddr *nam, struct thread *td)
304 struct tcpcb *tp = NULL;
305 struct sockaddr_in *sinp;
307 sinp = (struct sockaddr_in *)nam;
308 if (nam->sa_len != sizeof (*sinp))
311 * Must check for multicast addresses and disallow binding
314 if (sinp->sin_family == AF_INET &&
315 IN_MULTICAST(ntohl(sinp->sin_addr.s_addr)))
316 return (EAFNOSUPPORT);
320 KASSERT(inp != NULL, ("tcp_usr_bind: inp == NULL"));
322 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
328 INP_HASH_WLOCK(&V_tcbinfo);
329 error = in_pcbbind(inp, nam, td->td_ucred);
330 INP_HASH_WUNLOCK(&V_tcbinfo);
333 TCP_PROBE2(debug__user, tp, PRU_BIND);
342 tcp6_usr_bind(struct socket *so, struct sockaddr *nam, struct thread *td)
346 struct tcpcb *tp = NULL;
347 struct sockaddr_in6 *sin6;
350 sin6 = (struct sockaddr_in6 *)nam;
351 if (nam->sa_len != sizeof (*sin6))
354 * Must check for multicast addresses and disallow binding
357 if (sin6->sin6_family == AF_INET6 &&
358 IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr))
359 return (EAFNOSUPPORT);
363 KASSERT(inp != NULL, ("tcp6_usr_bind: inp == NULL"));
365 vflagsav = inp->inp_vflag;
366 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
372 INP_HASH_WLOCK(&V_tcbinfo);
373 inp->inp_vflag &= ~INP_IPV4;
374 inp->inp_vflag |= INP_IPV6;
376 if ((inp->inp_flags & IN6P_IPV6_V6ONLY) == 0) {
377 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr))
378 inp->inp_vflag |= INP_IPV4;
379 else if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
380 struct sockaddr_in sin;
382 in6_sin6_2_sin(&sin, sin6);
383 if (IN_MULTICAST(ntohl(sin.sin_addr.s_addr))) {
384 error = EAFNOSUPPORT;
385 INP_HASH_WUNLOCK(&V_tcbinfo);
388 inp->inp_vflag |= INP_IPV4;
389 inp->inp_vflag &= ~INP_IPV6;
390 error = in_pcbbind(inp, (struct sockaddr *)&sin,
392 INP_HASH_WUNLOCK(&V_tcbinfo);
397 error = in6_pcbbind(inp, nam, td->td_ucred);
398 INP_HASH_WUNLOCK(&V_tcbinfo);
401 inp->inp_vflag = vflagsav;
403 TCP_PROBE2(debug__user, tp, PRU_BIND);
411 * Prepare to accept connections.
414 tcp_usr_listen(struct socket *so, int backlog, struct thread *td)
418 struct tcpcb *tp = NULL;
422 KASSERT(inp != NULL, ("tcp_usr_listen: inp == NULL"));
424 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
431 error = solisten_proto_check(so);
432 INP_HASH_WLOCK(&V_tcbinfo);
433 if (error == 0 && inp->inp_lport == 0)
434 error = in_pcbbind(inp, (struct sockaddr *)0, td->td_ucred);
435 INP_HASH_WUNLOCK(&V_tcbinfo);
437 tcp_state_change(tp, TCPS_LISTEN);
438 solisten_proto(so, backlog);
440 if ((so->so_options & SO_NO_OFFLOAD) == 0)
441 tcp_offload_listen_start(tp);
446 if (IS_FASTOPEN(tp->t_flags))
447 tp->t_tfo_pending = tcp_fastopen_alloc_counter();
450 TCPDEBUG2(PRU_LISTEN);
451 TCP_PROBE2(debug__user, tp, PRU_LISTEN);
459 tcp6_usr_listen(struct socket *so, int backlog, struct thread *td)
463 struct tcpcb *tp = NULL;
468 KASSERT(inp != NULL, ("tcp6_usr_listen: inp == NULL"));
470 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
474 vflagsav = inp->inp_vflag;
478 error = solisten_proto_check(so);
479 INP_HASH_WLOCK(&V_tcbinfo);
480 if (error == 0 && inp->inp_lport == 0) {
481 inp->inp_vflag &= ~INP_IPV4;
482 if ((inp->inp_flags & IN6P_IPV6_V6ONLY) == 0)
483 inp->inp_vflag |= INP_IPV4;
484 error = in6_pcbbind(inp, (struct sockaddr *)0, td->td_ucred);
486 INP_HASH_WUNLOCK(&V_tcbinfo);
488 tcp_state_change(tp, TCPS_LISTEN);
489 solisten_proto(so, backlog);
491 if ((so->so_options & SO_NO_OFFLOAD) == 0)
492 tcp_offload_listen_start(tp);
497 if (IS_FASTOPEN(tp->t_flags))
498 tp->t_tfo_pending = tcp_fastopen_alloc_counter();
501 inp->inp_vflag = vflagsav;
504 TCPDEBUG2(PRU_LISTEN);
505 TCP_PROBE2(debug__user, tp, PRU_LISTEN);
513 * Initiate connection to peer.
514 * Create a template for use in transmissions on this connection.
515 * Enter SYN_SENT state, and mark socket as connecting.
516 * Start keep-alive timer, and seed output sequence space.
517 * Send initial segment on connection.
520 tcp_usr_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
524 struct tcpcb *tp = NULL;
525 struct sockaddr_in *sinp;
527 sinp = (struct sockaddr_in *)nam;
528 if (nam->sa_len != sizeof (*sinp))
531 * Must disallow TCP ``connections'' to multicast addresses.
533 if (sinp->sin_family == AF_INET
534 && IN_MULTICAST(ntohl(sinp->sin_addr.s_addr)))
535 return (EAFNOSUPPORT);
536 if ((error = prison_remote_ip4(td->td_ucred, &sinp->sin_addr)) != 0)
541 KASSERT(inp != NULL, ("tcp_usr_connect: inp == NULL"));
543 if (inp->inp_flags & INP_TIMEWAIT) {
547 if (inp->inp_flags & INP_DROPPED) {
548 error = ECONNREFUSED;
553 if ((error = tcp_connect(tp, nam, td)) != 0)
556 if (registered_toedevs > 0 &&
557 (so->so_options & SO_NO_OFFLOAD) == 0 &&
558 (error = tcp_offload_connect(so, nam)) == 0)
561 tcp_timer_activate(tp, TT_KEEP, TP_KEEPINIT(tp));
562 error = tp->t_fb->tfb_tcp_output(tp);
564 TCPDEBUG2(PRU_CONNECT);
565 TCP_PROBE2(debug__user, tp, PRU_CONNECT);
573 tcp6_usr_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
577 struct tcpcb *tp = NULL;
578 struct sockaddr_in6 *sin6;
584 sin6 = (struct sockaddr_in6 *)nam;
585 if (nam->sa_len != sizeof (*sin6))
588 * Must disallow TCP ``connections'' to multicast addresses.
590 if (sin6->sin6_family == AF_INET6
591 && IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr))
592 return (EAFNOSUPPORT);
595 KASSERT(inp != NULL, ("tcp6_usr_connect: inp == NULL"));
597 vflagsav = inp->inp_vflag;
598 incflagsav = inp->inp_inc.inc_flags;
599 if (inp->inp_flags & INP_TIMEWAIT) {
603 if (inp->inp_flags & INP_DROPPED) {
604 error = ECONNREFUSED;
611 * XXXRW: Some confusion: V4/V6 flags relate to binding, and
612 * therefore probably require the hash lock, which isn't held here.
613 * Is this a significant problem?
615 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
616 struct sockaddr_in sin;
618 if ((inp->inp_flags & IN6P_IPV6_V6ONLY) != 0) {
622 if ((inp->inp_vflag & INP_IPV4) == 0) {
623 error = EAFNOSUPPORT;
627 in6_sin6_2_sin(&sin, sin6);
628 if (IN_MULTICAST(ntohl(sin.sin_addr.s_addr))) {
629 error = EAFNOSUPPORT;
632 if ((error = prison_remote_ip4(td->td_ucred,
633 &sin.sin_addr)) != 0)
635 inp->inp_vflag |= INP_IPV4;
636 inp->inp_vflag &= ~INP_IPV6;
637 if ((error = tcp_connect(tp, (struct sockaddr *)&sin, td)) != 0)
640 if (registered_toedevs > 0 &&
641 (so->so_options & SO_NO_OFFLOAD) == 0 &&
642 (error = tcp_offload_connect(so, nam)) == 0)
645 error = tp->t_fb->tfb_tcp_output(tp);
648 if ((inp->inp_vflag & INP_IPV6) == 0) {
649 error = EAFNOSUPPORT;
654 if ((error = prison_remote_ip6(td->td_ucred, &sin6->sin6_addr)) != 0)
656 inp->inp_vflag &= ~INP_IPV4;
657 inp->inp_vflag |= INP_IPV6;
658 inp->inp_inc.inc_flags |= INC_ISIPV6;
659 if ((error = tcp6_connect(tp, nam, td)) != 0)
662 if (registered_toedevs > 0 &&
663 (so->so_options & SO_NO_OFFLOAD) == 0 &&
664 (error = tcp_offload_connect(so, nam)) == 0)
667 tcp_timer_activate(tp, TT_KEEP, TP_KEEPINIT(tp));
668 error = tp->t_fb->tfb_tcp_output(tp);
672 * If the implicit bind in the connect call fails, restore
673 * the flags we modified.
675 if (error != 0 && inp->inp_lport == 0) {
676 inp->inp_vflag = vflagsav;
677 inp->inp_inc.inc_flags = incflagsav;
680 TCPDEBUG2(PRU_CONNECT);
681 TCP_PROBE2(debug__user, tp, PRU_CONNECT);
688 * Initiate disconnect from peer.
689 * If connection never passed embryonic stage, just drop;
690 * else if don't need to let data drain, then can just drop anyways,
691 * else have to begin TCP shutdown process: mark socket disconnecting,
692 * drain unread data, state switch to reflect user close, and
693 * send segment (e.g. FIN) to peer. Socket will be really disconnected
694 * when peer sends FIN and acks ours.
696 * SHOULD IMPLEMENT LATER PRU_CONNECT VIA REALLOC TCPCB.
699 tcp_usr_disconnect(struct socket *so)
702 struct tcpcb *tp = NULL;
703 struct epoch_tracker et;
707 INP_INFO_RLOCK_ET(&V_tcbinfo, et);
709 KASSERT(inp != NULL, ("tcp_usr_disconnect: inp == NULL"));
711 if (inp->inp_flags & INP_TIMEWAIT)
713 if (inp->inp_flags & INP_DROPPED) {
721 TCPDEBUG2(PRU_DISCONNECT);
722 TCP_PROBE2(debug__user, tp, PRU_DISCONNECT);
724 INP_INFO_RUNLOCK_ET(&V_tcbinfo, et);
730 * Accept a connection. Essentially all the work is done at higher levels;
731 * just return the address of the peer, storing through addr.
734 tcp_usr_accept(struct socket *so, struct sockaddr **nam)
737 struct inpcb *inp = NULL;
738 struct tcpcb *tp = NULL;
743 if (so->so_state & SS_ISDISCONNECTED)
744 return (ECONNABORTED);
747 KASSERT(inp != NULL, ("tcp_usr_accept: inp == NULL"));
749 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
750 error = ECONNABORTED;
757 * We inline in_getpeeraddr and COMMON_END here, so that we can
758 * copy the data of interest and defer the malloc until after we
761 port = inp->inp_fport;
762 addr = inp->inp_faddr;
765 TCPDEBUG2(PRU_ACCEPT);
766 TCP_PROBE2(debug__user, tp, PRU_ACCEPT);
769 *nam = in_sockaddr(port, &addr);
776 tcp6_usr_accept(struct socket *so, struct sockaddr **nam)
778 struct inpcb *inp = NULL;
780 struct tcpcb *tp = NULL;
782 struct in6_addr addr6;
783 struct epoch_tracker et;
788 if (so->so_state & SS_ISDISCONNECTED)
789 return (ECONNABORTED);
792 KASSERT(inp != NULL, ("tcp6_usr_accept: inp == NULL"));
793 INP_INFO_RLOCK_ET(&V_tcbinfo, et);
795 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
796 error = ECONNABORTED;
803 * We inline in6_mapped_peeraddr and COMMON_END here, so that we can
804 * copy the data of interest and defer the malloc until after we
807 if (inp->inp_vflag & INP_IPV4) {
809 port = inp->inp_fport;
810 addr = inp->inp_faddr;
812 port = inp->inp_fport;
813 addr6 = inp->in6p_faddr;
817 TCPDEBUG2(PRU_ACCEPT);
818 TCP_PROBE2(debug__user, tp, PRU_ACCEPT);
820 INP_INFO_RUNLOCK_ET(&V_tcbinfo, et);
823 *nam = in6_v4mapsin6_sockaddr(port, &addr);
825 *nam = in6_sockaddr(port, &addr6);
832 * Mark the connection as being incapable of further output.
835 tcp_usr_shutdown(struct socket *so)
839 struct tcpcb *tp = NULL;
840 struct epoch_tracker et;
843 INP_INFO_RLOCK_ET(&V_tcbinfo, et);
845 KASSERT(inp != NULL, ("inp == NULL"));
847 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
855 if (!(inp->inp_flags & INP_DROPPED))
856 error = tp->t_fb->tfb_tcp_output(tp);
859 TCPDEBUG2(PRU_SHUTDOWN);
860 TCP_PROBE2(debug__user, tp, PRU_SHUTDOWN);
862 INP_INFO_RUNLOCK_ET(&V_tcbinfo, et);
868 * After a receive, possibly send window update to peer.
871 tcp_usr_rcvd(struct socket *so, int flags)
874 struct tcpcb *tp = NULL;
879 KASSERT(inp != NULL, ("tcp_usr_rcvd: inp == NULL"));
881 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
888 * For passively-created TFO connections, don't attempt a window
889 * update while still in SYN_RECEIVED as this may trigger an early
890 * SYN|ACK. It is preferable to have the SYN|ACK be sent along with
891 * application response data, or failing that, when the DELACK timer
894 if (IS_FASTOPEN(tp->t_flags) &&
895 (tp->t_state == TCPS_SYN_RECEIVED))
898 if (tp->t_flags & TF_TOE)
899 tcp_offload_rcvd(tp);
902 tp->t_fb->tfb_tcp_output(tp);
906 TCP_PROBE2(debug__user, tp, PRU_RCVD);
912 * Do a send by putting data in output queue and updating urgent
913 * marker if URG set. Possibly send more data. Unlike the other
914 * pru_*() routines, the mbuf chains are our responsibility. We
915 * must either enqueue them or free them. The other pru_* routines
916 * generally are caller-frees.
919 tcp_usr_send(struct socket *so, int flags, struct mbuf *m,
920 struct sockaddr *nam, struct mbuf *control, struct thread *td)
924 struct tcpcb *tp = NULL;
925 struct epoch_tracker net_et;
928 struct sockaddr_in sin;
930 struct sockaddr_in *sinp;
941 * We require the pcbinfo lock if we will close the socket as part of
944 if (flags & PRUS_EOF)
945 INP_INFO_RLOCK_ET(&V_tcbinfo, net_et);
947 KASSERT(inp != NULL, ("tcp_usr_send: inp == NULL"));
949 vflagsav = inp->inp_vflag;
950 incflagsav = inp->inp_inc.inc_flags;
951 restoreflags = false;
952 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
956 * In case of PRUS_NOTREADY, tcp_usr_ready() is responsible
957 * for freeing memory.
959 if (m && (flags & PRUS_NOTREADY) == 0)
966 if (nam != NULL && tp->t_state < TCPS_SYN_SENT) {
967 switch (nam->sa_family) {
970 sinp = (struct sockaddr_in *)nam;
971 if (sinp->sin_len != sizeof(struct sockaddr_in)) {
977 if ((inp->inp_vflag & INP_IPV6) != 0) {
980 error = EAFNOSUPPORT;
983 if (IN_MULTICAST(ntohl(sinp->sin_addr.s_addr))) {
986 error = EAFNOSUPPORT;
989 if ((error = prison_remote_ip4(td->td_ucred,
1003 struct sockaddr_in6 *sin6;
1005 sin6 = (struct sockaddr_in6 *)nam;
1006 if (sin6->sin6_len != sizeof(*sin6)) {
1012 if (IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr)) {
1015 error = EAFNOSUPPORT;
1018 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
1020 if ((inp->inp_flags & IN6P_IPV6_V6ONLY) != 0) {
1026 if ((inp->inp_vflag & INP_IPV4) == 0) {
1027 error = EAFNOSUPPORT;
1032 restoreflags = true;
1033 inp->inp_vflag &= ~INP_IPV6;
1035 in6_sin6_2_sin(sinp, sin6);
1037 ntohl(sinp->sin_addr.s_addr))) {
1038 error = EAFNOSUPPORT;
1043 if ((error = prison_remote_ip4(td->td_ucred,
1044 &sinp->sin_addr))) {
1051 error = EAFNOSUPPORT;
1057 if ((inp->inp_vflag & INP_IPV6) == 0) {
1060 error = EAFNOSUPPORT;
1063 restoreflags = true;
1064 inp->inp_vflag &= ~INP_IPV4;
1065 inp->inp_inc.inc_flags |= INC_ISIPV6;
1066 if ((error = prison_remote_ip6(td->td_ucred,
1067 &sin6->sin6_addr))) {
1080 error = EAFNOSUPPORT;
1085 /* TCP doesn't do control messages (rights, creds, etc) */
1086 if (control->m_len) {
1093 m_freem(control); /* empty control, just free it */
1095 if (!(flags & PRUS_OOB)) {
1096 sbappendstream(&so->so_snd, m, flags);
1097 if (nam && tp->t_state < TCPS_SYN_SENT) {
1099 * Do implied connect if not yet connected,
1100 * initialize window to default value, and
1101 * initialize maxseg using peer's cached MSS.
1105 error = tcp6_connect(tp, nam, td);
1107 #if defined(INET6) && defined(INET)
1111 error = tcp_connect(tp,
1112 (struct sockaddr *)sinp, td);
1115 * The bind operation in tcp_connect succeeded. We
1116 * no longer want to restore the flags if later
1119 if (error == 0 || inp->inp_lport != 0)
1120 restoreflags = false;
1124 if (IS_FASTOPEN(tp->t_flags))
1125 tcp_fastopen_connect(tp);
1127 tp->snd_wnd = TTCP_CLIENT_SND_WND;
1131 if (flags & PRUS_EOF) {
1133 * Close the send side of the connection after
1136 INP_INFO_RLOCK_ASSERT(&V_tcbinfo);
1140 if (!(inp->inp_flags & INP_DROPPED) &&
1141 !(flags & PRUS_NOTREADY)) {
1142 if (flags & PRUS_MORETOCOME)
1143 tp->t_flags |= TF_MORETOCOME;
1144 error = tp->t_fb->tfb_tcp_output(tp);
1145 if (flags & PRUS_MORETOCOME)
1146 tp->t_flags &= ~TF_MORETOCOME;
1150 * XXXRW: PRUS_EOF not implemented with PRUS_OOB?
1152 SOCKBUF_LOCK(&so->so_snd);
1153 if (sbspace(&so->so_snd) < -512) {
1154 SOCKBUF_UNLOCK(&so->so_snd);
1160 * According to RFC961 (Assigned Protocols),
1161 * the urgent pointer points to the last octet
1162 * of urgent data. We continue, however,
1163 * to consider it to indicate the first octet
1164 * of data past the urgent section.
1165 * Otherwise, snd_up should be one lower.
1167 sbappendstream_locked(&so->so_snd, m, flags);
1168 SOCKBUF_UNLOCK(&so->so_snd);
1169 if (nam && tp->t_state < TCPS_SYN_SENT) {
1171 * Do implied connect if not yet connected,
1172 * initialize window to default value, and
1173 * initialize maxseg using peer's cached MSS.
1177 * Not going to contemplate SYN|URG
1179 if (IS_FASTOPEN(tp->t_flags))
1180 tp->t_flags &= ~TF_FASTOPEN;
1183 error = tcp6_connect(tp, nam, td);
1185 #if defined(INET6) && defined(INET)
1189 error = tcp_connect(tp,
1190 (struct sockaddr *)sinp, td);
1193 * The bind operation in tcp_connect succeeded. We
1194 * no longer want to restore the flags if later
1197 if (error == 0 || inp->inp_lport != 0)
1198 restoreflags = false;
1202 tp->snd_wnd = TTCP_CLIENT_SND_WND;
1205 tp->snd_up = tp->snd_una + sbavail(&so->so_snd);
1206 if (!(flags & PRUS_NOTREADY)) {
1207 tp->t_flags |= TF_FORCEDATA;
1208 error = tp->t_fb->tfb_tcp_output(tp);
1209 tp->t_flags &= ~TF_FORCEDATA;
1212 TCP_LOG_EVENT(tp, NULL,
1213 &inp->inp_socket->so_rcv,
1214 &inp->inp_socket->so_snd,
1215 TCP_LOG_USERSEND, error,
1219 * If the request was unsuccessful and we changed flags,
1220 * restore the original flags.
1222 if (error != 0 && restoreflags) {
1223 inp->inp_vflag = vflagsav;
1224 inp->inp_inc.inc_flags = incflagsav;
1226 TCPDEBUG2((flags & PRUS_OOB) ? PRU_SENDOOB :
1227 ((flags & PRUS_EOF) ? PRU_SEND_EOF : PRU_SEND));
1228 TCP_PROBE2(debug__user, tp, (flags & PRUS_OOB) ? PRU_SENDOOB :
1229 ((flags & PRUS_EOF) ? PRU_SEND_EOF : PRU_SEND));
1231 if (flags & PRUS_EOF)
1232 INP_INFO_RUNLOCK_ET(&V_tcbinfo, net_et);
1237 tcp_usr_ready(struct socket *so, struct mbuf *m, int count)
1243 inp = sotoinpcb(so);
1245 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
1247 for (int i = 0; i < count; i++)
1249 return (ECONNRESET);
1251 tp = intotcpcb(inp);
1253 SOCKBUF_LOCK(&so->so_snd);
1254 error = sbready(&so->so_snd, m, count);
1255 SOCKBUF_UNLOCK(&so->so_snd);
1257 error = tp->t_fb->tfb_tcp_output(tp);
1264 * Abort the TCP. Drop the connection abruptly.
1267 tcp_usr_abort(struct socket *so)
1270 struct tcpcb *tp = NULL;
1271 struct epoch_tracker et;
1274 inp = sotoinpcb(so);
1275 KASSERT(inp != NULL, ("tcp_usr_abort: inp == NULL"));
1277 INP_INFO_RLOCK_ET(&V_tcbinfo, et);
1279 KASSERT(inp->inp_socket != NULL,
1280 ("tcp_usr_abort: inp_socket == NULL"));
1283 * If we still have full TCP state, and we're not dropped, drop.
1285 if (!(inp->inp_flags & INP_TIMEWAIT) &&
1286 !(inp->inp_flags & INP_DROPPED)) {
1287 tp = intotcpcb(inp);
1289 tp = tcp_drop(tp, ECONNABORTED);
1292 TCPDEBUG2(PRU_ABORT);
1293 TCP_PROBE2(debug__user, tp, PRU_ABORT);
1295 if (!(inp->inp_flags & INP_DROPPED)) {
1297 so->so_state |= SS_PROTOREF;
1299 inp->inp_flags |= INP_SOCKREF;
1303 INP_INFO_RUNLOCK_ET(&V_tcbinfo, et);
1307 * TCP socket is closed. Start friendly disconnect.
1310 tcp_usr_close(struct socket *so)
1313 struct tcpcb *tp = NULL;
1314 struct epoch_tracker et;
1317 inp = sotoinpcb(so);
1318 KASSERT(inp != NULL, ("tcp_usr_close: inp == NULL"));
1320 INP_INFO_RLOCK_ET(&V_tcbinfo, et);
1322 KASSERT(inp->inp_socket != NULL,
1323 ("tcp_usr_close: inp_socket == NULL"));
1326 * If we still have full TCP state, and we're not dropped, initiate
1329 if (!(inp->inp_flags & INP_TIMEWAIT) &&
1330 !(inp->inp_flags & INP_DROPPED)) {
1331 tp = intotcpcb(inp);
1334 TCPDEBUG2(PRU_CLOSE);
1335 TCP_PROBE2(debug__user, tp, PRU_CLOSE);
1337 if (!(inp->inp_flags & INP_DROPPED)) {
1339 so->so_state |= SS_PROTOREF;
1341 inp->inp_flags |= INP_SOCKREF;
1344 INP_INFO_RUNLOCK_ET(&V_tcbinfo, et);
1348 * Receive out-of-band data.
1351 tcp_usr_rcvoob(struct socket *so, struct mbuf *m, int flags)
1355 struct tcpcb *tp = NULL;
1358 inp = sotoinpcb(so);
1359 KASSERT(inp != NULL, ("tcp_usr_rcvoob: inp == NULL"));
1361 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
1365 tp = intotcpcb(inp);
1367 if ((so->so_oobmark == 0 &&
1368 (so->so_rcv.sb_state & SBS_RCVATMARK) == 0) ||
1369 so->so_options & SO_OOBINLINE ||
1370 tp->t_oobflags & TCPOOB_HADDATA) {
1374 if ((tp->t_oobflags & TCPOOB_HAVEDATA) == 0) {
1375 error = EWOULDBLOCK;
1379 *mtod(m, caddr_t) = tp->t_iobc;
1380 if ((flags & MSG_PEEK) == 0)
1381 tp->t_oobflags ^= (TCPOOB_HAVEDATA | TCPOOB_HADDATA);
1384 TCPDEBUG2(PRU_RCVOOB);
1385 TCP_PROBE2(debug__user, tp, PRU_RCVOOB);
1391 struct pr_usrreqs tcp_usrreqs = {
1392 .pru_abort = tcp_usr_abort,
1393 .pru_accept = tcp_usr_accept,
1394 .pru_attach = tcp_usr_attach,
1395 .pru_bind = tcp_usr_bind,
1396 .pru_connect = tcp_usr_connect,
1397 .pru_control = in_control,
1398 .pru_detach = tcp_usr_detach,
1399 .pru_disconnect = tcp_usr_disconnect,
1400 .pru_listen = tcp_usr_listen,
1401 .pru_peeraddr = in_getpeeraddr,
1402 .pru_rcvd = tcp_usr_rcvd,
1403 .pru_rcvoob = tcp_usr_rcvoob,
1404 .pru_send = tcp_usr_send,
1405 .pru_ready = tcp_usr_ready,
1406 .pru_shutdown = tcp_usr_shutdown,
1407 .pru_sockaddr = in_getsockaddr,
1408 .pru_sosetlabel = in_pcbsosetlabel,
1409 .pru_close = tcp_usr_close,
1414 struct pr_usrreqs tcp6_usrreqs = {
1415 .pru_abort = tcp_usr_abort,
1416 .pru_accept = tcp6_usr_accept,
1417 .pru_attach = tcp_usr_attach,
1418 .pru_bind = tcp6_usr_bind,
1419 .pru_connect = tcp6_usr_connect,
1420 .pru_control = in6_control,
1421 .pru_detach = tcp_usr_detach,
1422 .pru_disconnect = tcp_usr_disconnect,
1423 .pru_listen = tcp6_usr_listen,
1424 .pru_peeraddr = in6_mapped_peeraddr,
1425 .pru_rcvd = tcp_usr_rcvd,
1426 .pru_rcvoob = tcp_usr_rcvoob,
1427 .pru_send = tcp_usr_send,
1428 .pru_ready = tcp_usr_ready,
1429 .pru_shutdown = tcp_usr_shutdown,
1430 .pru_sockaddr = in6_mapped_sockaddr,
1431 .pru_sosetlabel = in_pcbsosetlabel,
1432 .pru_close = tcp_usr_close,
1438 * Common subroutine to open a TCP connection to remote host specified
1439 * by struct sockaddr_in in mbuf *nam. Call in_pcbbind to assign a local
1440 * port number if needed. Call in_pcbconnect_setup to do the routing and
1441 * to choose a local host address (interface). If there is an existing
1442 * incarnation of the same connection in TIME-WAIT state and if the remote
1443 * host was sending CC options and if the connection duration was < MSL, then
1444 * truncate the previous TIME-WAIT state and proceed.
1445 * Initialize connection parameters and enter SYN-SENT state.
1448 tcp_connect(struct tcpcb *tp, struct sockaddr *nam, struct thread *td)
1450 struct inpcb *inp = tp->t_inpcb, *oinp;
1451 struct socket *so = inp->inp_socket;
1452 struct in_addr laddr;
1456 INP_WLOCK_ASSERT(inp);
1457 INP_HASH_WLOCK(&V_tcbinfo);
1459 if (inp->inp_lport == 0) {
1460 error = in_pcbbind(inp, (struct sockaddr *)0, td->td_ucred);
1466 * Cannot simply call in_pcbconnect, because there might be an
1467 * earlier incarnation of this same connection still in
1468 * TIME_WAIT state, creating an ADDRINUSE error.
1470 laddr = inp->inp_laddr;
1471 lport = inp->inp_lport;
1472 error = in_pcbconnect_setup(inp, nam, &laddr.s_addr, &lport,
1473 &inp->inp_faddr.s_addr, &inp->inp_fport, &oinp, td->td_ucred);
1474 if (error && oinp == NULL)
1480 inp->inp_laddr = laddr;
1482 INP_HASH_WUNLOCK(&V_tcbinfo);
1485 * Compute window scaling to request:
1486 * Scale to fit into sweet spot. See tcp_syncache.c.
1487 * XXX: This should move to tcp_output().
1489 while (tp->request_r_scale < TCP_MAX_WINSHIFT &&
1490 (TCP_MAXWIN << tp->request_r_scale) < sb_max)
1491 tp->request_r_scale++;
1494 TCPSTAT_INC(tcps_connattempt);
1495 tcp_state_change(tp, TCPS_SYN_SENT);
1496 tp->iss = tcp_new_isn(&inp->inp_inc);
1497 if (tp->t_flags & TF_REQ_TSTMP)
1498 tp->ts_offset = tcp_new_ts_offset(&inp->inp_inc);
1499 tcp_sendseqinit(tp);
1504 INP_HASH_WUNLOCK(&V_tcbinfo);
1511 tcp6_connect(struct tcpcb *tp, struct sockaddr *nam, struct thread *td)
1513 struct inpcb *inp = tp->t_inpcb;
1516 INP_WLOCK_ASSERT(inp);
1517 INP_HASH_WLOCK(&V_tcbinfo);
1519 if (inp->inp_lport == 0) {
1520 error = in6_pcbbind(inp, (struct sockaddr *)0, td->td_ucred);
1524 error = in6_pcbconnect(inp, nam, td->td_ucred);
1527 INP_HASH_WUNLOCK(&V_tcbinfo);
1529 /* Compute window scaling to request. */
1530 while (tp->request_r_scale < TCP_MAX_WINSHIFT &&
1531 (TCP_MAXWIN << tp->request_r_scale) < sb_max)
1532 tp->request_r_scale++;
1534 soisconnecting(inp->inp_socket);
1535 TCPSTAT_INC(tcps_connattempt);
1536 tcp_state_change(tp, TCPS_SYN_SENT);
1537 tp->iss = tcp_new_isn(&inp->inp_inc);
1538 if (tp->t_flags & TF_REQ_TSTMP)
1539 tp->ts_offset = tcp_new_ts_offset(&inp->inp_inc);
1540 tcp_sendseqinit(tp);
1545 INP_HASH_WUNLOCK(&V_tcbinfo);
1551 * Export TCP internal state information via a struct tcp_info, based on the
1552 * Linux 2.6 API. Not ABI compatible as our constants are mapped differently
1553 * (TCP state machine, etc). We export all information using FreeBSD-native
1554 * constants -- for example, the numeric values for tcpi_state will differ
1558 tcp_fill_info(struct tcpcb *tp, struct tcp_info *ti)
1561 INP_WLOCK_ASSERT(tp->t_inpcb);
1562 bzero(ti, sizeof(*ti));
1564 ti->tcpi_state = tp->t_state;
1565 if ((tp->t_flags & TF_REQ_TSTMP) && (tp->t_flags & TF_RCVD_TSTMP))
1566 ti->tcpi_options |= TCPI_OPT_TIMESTAMPS;
1567 if (tp->t_flags & TF_SACK_PERMIT)
1568 ti->tcpi_options |= TCPI_OPT_SACK;
1569 if ((tp->t_flags & TF_REQ_SCALE) && (tp->t_flags & TF_RCVD_SCALE)) {
1570 ti->tcpi_options |= TCPI_OPT_WSCALE;
1571 ti->tcpi_snd_wscale = tp->snd_scale;
1572 ti->tcpi_rcv_wscale = tp->rcv_scale;
1574 if (tp->t_flags & TF_ECN_PERMIT)
1575 ti->tcpi_options |= TCPI_OPT_ECN;
1577 ti->tcpi_rto = tp->t_rxtcur * tick;
1578 ti->tcpi_last_data_recv = ((uint32_t)ticks - tp->t_rcvtime) * tick;
1579 ti->tcpi_rtt = ((u_int64_t)tp->t_srtt * tick) >> TCP_RTT_SHIFT;
1580 ti->tcpi_rttvar = ((u_int64_t)tp->t_rttvar * tick) >> TCP_RTTVAR_SHIFT;
1582 ti->tcpi_snd_ssthresh = tp->snd_ssthresh;
1583 ti->tcpi_snd_cwnd = tp->snd_cwnd;
1586 * FreeBSD-specific extension fields for tcp_info.
1588 ti->tcpi_rcv_space = tp->rcv_wnd;
1589 ti->tcpi_rcv_nxt = tp->rcv_nxt;
1590 ti->tcpi_snd_wnd = tp->snd_wnd;
1591 ti->tcpi_snd_bwnd = 0; /* Unused, kept for compat. */
1592 ti->tcpi_snd_nxt = tp->snd_nxt;
1593 ti->tcpi_snd_mss = tp->t_maxseg;
1594 ti->tcpi_rcv_mss = tp->t_maxseg;
1595 ti->tcpi_snd_rexmitpack = tp->t_sndrexmitpack;
1596 ti->tcpi_rcv_ooopack = tp->t_rcvoopack;
1597 ti->tcpi_snd_zerowin = tp->t_sndzerowin;
1599 if (tp->t_flags & TF_TOE) {
1600 ti->tcpi_options |= TCPI_OPT_TOE;
1601 tcp_offload_tcp_info(tp, ti);
1607 * tcp_ctloutput() must drop the inpcb lock before performing copyin on
1608 * socket option arguments. When it re-acquires the lock after the copy, it
1609 * has to revalidate that the connection is still valid for the socket
1612 #define INP_WLOCK_RECHECK_CLEANUP(inp, cleanup) do { \
1614 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) { \
1617 return (ECONNRESET); \
1619 tp = intotcpcb(inp); \
1621 #define INP_WLOCK_RECHECK(inp) INP_WLOCK_RECHECK_CLEANUP((inp), /* noop */)
1624 tcp_ctloutput(struct socket *so, struct sockopt *sopt)
1629 struct tcp_function_block *blk;
1630 struct tcp_function_set fsn;
1633 inp = sotoinpcb(so);
1634 KASSERT(inp != NULL, ("tcp_ctloutput: inp == NULL"));
1635 if (sopt->sopt_level != IPPROTO_TCP) {
1637 if (inp->inp_vflag & INP_IPV6PROTO) {
1638 error = ip6_ctloutput(so, sopt);
1640 * In case of the IPV6_USE_MIN_MTU socket option,
1641 * the INC_IPV6MINMTU flag to announce a corresponding
1642 * MSS during the initial handshake.
1643 * If the TCP connection is not in the front states,
1644 * just reduce the MSS being used.
1645 * This avoids the sending of TCP segments which will
1646 * be fragmented at the IPv6 layer.
1649 (sopt->sopt_dir == SOPT_SET) &&
1650 (sopt->sopt_level == IPPROTO_IPV6) &&
1651 (sopt->sopt_name == IPV6_USE_MIN_MTU)) {
1653 if ((inp->inp_flags &
1654 (INP_TIMEWAIT | INP_DROPPED))) {
1656 return (ECONNRESET);
1658 inp->inp_inc.inc_flags |= INC_IPV6MINMTU;
1659 tp = intotcpcb(inp);
1660 if ((tp->t_state >= TCPS_SYN_SENT) &&
1661 (inp->inp_inc.inc_flags & INC_ISIPV6)) {
1662 struct ip6_pktopts *opt;
1664 opt = inp->in6p_outputopts;
1665 if ((opt != NULL) &&
1666 (opt->ip6po_minmtu ==
1667 IP6PO_MINMTU_ALL)) {
1668 if (tp->t_maxseg > TCP6_MSS) {
1669 tp->t_maxseg = TCP6_MSS;
1677 #if defined(INET6) && defined(INET)
1682 error = ip_ctloutput(so, sopt);
1688 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
1690 return (ECONNRESET);
1692 tp = intotcpcb(inp);
1694 * Protect the TCP option TCP_FUNCTION_BLK so
1695 * that a sub-function can *never* overwrite this.
1697 if ((sopt->sopt_dir == SOPT_SET) &&
1698 (sopt->sopt_name == TCP_FUNCTION_BLK)) {
1700 error = sooptcopyin(sopt, &fsn, sizeof fsn,
1704 INP_WLOCK_RECHECK(inp);
1705 blk = find_and_ref_tcp_functions(&fsn);
1710 if (tp->t_fb == blk) {
1711 /* You already have this */
1712 refcount_release(&blk->tfb_refcnt);
1716 if (tp->t_state != TCPS_CLOSED) {
1718 * The user has advanced the state
1719 * past the initial point, we may not
1720 * be able to switch.
1722 if (blk->tfb_tcp_handoff_ok != NULL) {
1724 * Does the stack provide a
1725 * query mechanism, if so it may
1726 * still be possible?
1728 error = (*blk->tfb_tcp_handoff_ok)(tp);
1732 refcount_release(&blk->tfb_refcnt);
1737 if (blk->tfb_flags & TCP_FUNC_BEING_REMOVED) {
1738 refcount_release(&blk->tfb_refcnt);
1743 * Release the old refcnt, the
1744 * lookup acquired a ref on the
1747 if (tp->t_fb->tfb_tcp_fb_fini) {
1749 * Tell the stack to cleanup with 0 i.e.
1750 * the tcb is not going away.
1752 (*tp->t_fb->tfb_tcp_fb_fini)(tp, 0);
1755 /* Assure that we are not on any hpts */
1756 tcp_hpts_remove(tp->t_inpcb, HPTS_REMOVE_ALL);
1758 if (blk->tfb_tcp_fb_init) {
1759 error = (*blk->tfb_tcp_fb_init)(tp);
1761 refcount_release(&blk->tfb_refcnt);
1762 if (tp->t_fb->tfb_tcp_fb_init) {
1763 if((*tp->t_fb->tfb_tcp_fb_init)(tp) != 0) {
1764 /* Fall back failed, drop the connection */
1773 refcount_release(&tp->t_fb->tfb_refcnt);
1776 if (tp->t_flags & TF_TOE) {
1777 tcp_offload_ctloutput(tp, sopt->sopt_dir,
1784 } else if ((sopt->sopt_dir == SOPT_GET) &&
1785 (sopt->sopt_name == TCP_FUNCTION_BLK)) {
1786 strncpy(fsn.function_set_name, tp->t_fb->tfb_tcp_block_name,
1787 TCP_FUNCTION_NAME_LEN_MAX);
1788 fsn.function_set_name[TCP_FUNCTION_NAME_LEN_MAX - 1] = '\0';
1789 fsn.pcbcnt = tp->t_fb->tfb_refcnt;
1791 error = sooptcopyout(sopt, &fsn, sizeof fsn);
1794 /* Pass in the INP locked, called must unlock it */
1795 return (tp->t_fb->tfb_tcp_ctloutput(so, sopt, inp, tp));
1799 * If this assert becomes untrue, we need to change the size of the buf
1800 * variable in tcp_default_ctloutput().
1803 CTASSERT(TCP_CA_NAME_MAX <= TCP_LOG_ID_LEN);
1804 CTASSERT(TCP_LOG_REASON_LEN <= TCP_LOG_ID_LEN);
1808 tcp_default_ctloutput(struct socket *so, struct sockopt *sopt, struct inpcb *inp, struct tcpcb *tp)
1810 int error, opt, optval;
1813 struct cc_algo *algo;
1814 char *pbuf, buf[TCP_LOG_ID_LEN];
1818 * For TCP_CCALGOOPT forward the control to CC module, for both
1819 * SOPT_SET and SOPT_GET.
1821 switch (sopt->sopt_name) {
1824 if (sopt->sopt_valsize > CC_ALGOOPT_LIMIT)
1826 pbuf = malloc(sopt->sopt_valsize, M_TEMP, M_WAITOK | M_ZERO);
1827 error = sooptcopyin(sopt, pbuf, sopt->sopt_valsize,
1828 sopt->sopt_valsize);
1833 INP_WLOCK_RECHECK_CLEANUP(inp, free(pbuf, M_TEMP));
1834 if (CC_ALGO(tp)->ctl_output != NULL)
1835 error = CC_ALGO(tp)->ctl_output(tp->ccv, sopt, pbuf);
1839 if (error == 0 && sopt->sopt_dir == SOPT_GET)
1840 error = sooptcopyout(sopt, pbuf, sopt->sopt_valsize);
1845 switch (sopt->sopt_dir) {
1847 switch (sopt->sopt_name) {
1848 #if defined(IPSEC_SUPPORT) || defined(TCP_SIGNATURE)
1850 if (!TCPMD5_ENABLED()) {
1852 return (ENOPROTOOPT);
1854 error = TCPMD5_PCBCTL(inp, sopt);
1857 goto unlock_and_done;
1863 error = sooptcopyin(sopt, &optval, sizeof optval,
1868 INP_WLOCK_RECHECK(inp);
1869 switch (sopt->sopt_name) {
1877 opt = 0; /* dead code to fool gcc */
1884 tp->t_flags &= ~opt;
1887 if (tp->t_flags & TF_TOE) {
1888 tcp_offload_ctloutput(tp, sopt->sopt_dir,
1897 error = sooptcopyin(sopt, &optval, sizeof optval,
1902 INP_WLOCK_RECHECK(inp);
1904 tp->t_flags |= TF_NOPUSH;
1905 else if (tp->t_flags & TF_NOPUSH) {
1906 tp->t_flags &= ~TF_NOPUSH;
1907 if (TCPS_HAVEESTABLISHED(tp->t_state))
1908 error = tp->t_fb->tfb_tcp_output(tp);
1910 goto unlock_and_done;
1914 error = sooptcopyin(sopt, &optval, sizeof optval,
1919 INP_WLOCK_RECHECK(inp);
1920 if (optval > 0 && optval <= tp->t_maxseg &&
1921 optval + 40 >= V_tcp_minmss)
1922 tp->t_maxseg = optval;
1925 goto unlock_and_done;
1932 case TCP_CONGESTION:
1934 error = sooptcopyin(sopt, buf, TCP_CA_NAME_MAX - 1, 1);
1937 buf[sopt->sopt_valsize] = '\0';
1938 INP_WLOCK_RECHECK(inp);
1940 STAILQ_FOREACH(algo, &cc_list, entries)
1941 if (strncmp(buf, algo->name,
1942 TCP_CA_NAME_MAX) == 0)
1951 * We hold a write lock over the tcb so it's safe to
1952 * do these things without ordering concerns.
1954 if (CC_ALGO(tp)->cb_destroy != NULL)
1955 CC_ALGO(tp)->cb_destroy(tp->ccv);
1959 * If something goes pear shaped initialising the new
1960 * algo, fall back to newreno (which does not
1961 * require initialisation).
1963 if (algo->cb_init != NULL &&
1964 algo->cb_init(tp->ccv) != 0) {
1965 CC_ALGO(tp) = &newreno_cc_algo;
1967 * The only reason init should fail is
1968 * because of malloc.
1979 error = sooptcopyin(sopt, &ui, sizeof(ui), sizeof(ui));
1983 if (ui > (UINT_MAX / hz)) {
1989 INP_WLOCK_RECHECK(inp);
1990 switch (sopt->sopt_name) {
1992 tp->t_keepidle = ui;
1994 * XXX: better check current remaining
1995 * timeout and "merge" it with new value.
1997 if ((tp->t_state > TCPS_LISTEN) &&
1998 (tp->t_state <= TCPS_CLOSING))
1999 tcp_timer_activate(tp, TT_KEEP,
2003 tp->t_keepintvl = ui;
2004 if ((tp->t_state == TCPS_FIN_WAIT_2) &&
2005 (TP_MAXIDLE(tp) > 0))
2006 tcp_timer_activate(tp, TT_2MSL,
2010 tp->t_keepinit = ui;
2011 if (tp->t_state == TCPS_SYN_RECEIVED ||
2012 tp->t_state == TCPS_SYN_SENT)
2013 tcp_timer_activate(tp, TT_KEEP,
2017 goto unlock_and_done;
2021 error = sooptcopyin(sopt, &ui, sizeof(ui), sizeof(ui));
2025 INP_WLOCK_RECHECK(inp);
2027 if ((tp->t_state == TCPS_FIN_WAIT_2) &&
2028 (TP_MAXIDLE(tp) > 0))
2029 tcp_timer_activate(tp, TT_2MSL,
2031 goto unlock_and_done;
2037 error = sooptcopyin(sopt, &optval, sizeof optval,
2042 INP_WLOCK_RECHECK(inp);
2044 tcp_pcap_set_sock_max(TCP_PCAP_OUT ?
2045 &(tp->t_outpkts) : &(tp->t_inpkts),
2049 goto unlock_and_done;
2052 case TCP_FASTOPEN: {
2053 struct tcp_fastopen tfo_optval;
2056 if (!V_tcp_fastopen_client_enable &&
2057 !V_tcp_fastopen_server_enable)
2060 error = sooptcopyin(sopt, &tfo_optval,
2061 sizeof(tfo_optval), sizeof(int));
2065 INP_WLOCK_RECHECK(inp);
2066 if (tfo_optval.enable) {
2067 if (tp->t_state == TCPS_LISTEN) {
2068 if (!V_tcp_fastopen_server_enable) {
2070 goto unlock_and_done;
2073 tp->t_flags |= TF_FASTOPEN;
2074 if (tp->t_tfo_pending == NULL)
2076 tcp_fastopen_alloc_counter();
2079 * If a pre-shared key was provided,
2080 * stash it in the client cookie
2081 * field of the tcpcb for use during
2084 if (sopt->sopt_valsize ==
2085 sizeof(tfo_optval)) {
2086 memcpy(tp->t_tfo_cookie.client,
2088 TCP_FASTOPEN_PSK_LEN);
2089 tp->t_tfo_client_cookie_len =
2090 TCP_FASTOPEN_PSK_LEN;
2092 tp->t_flags |= TF_FASTOPEN;
2095 tp->t_flags &= ~TF_FASTOPEN;
2096 goto unlock_and_done;
2102 error = sooptcopyin(sopt, &optval, sizeof optval,
2107 INP_WLOCK_RECHECK(inp);
2108 error = tcp_log_state_change(tp, optval);
2109 goto unlock_and_done;
2118 error = sooptcopyin(sopt, buf, TCP_LOG_ID_LEN - 1, 0);
2121 buf[sopt->sopt_valsize] = '\0';
2122 INP_WLOCK_RECHECK(inp);
2123 error = tcp_log_set_id(tp, buf);
2124 /* tcp_log_set_id() unlocks the INP. */
2131 sooptcopyin(sopt, buf, TCP_LOG_REASON_LEN - 1, 0);
2134 buf[sopt->sopt_valsize] = '\0';
2135 INP_WLOCK_RECHECK(inp);
2136 if (sopt->sopt_name == TCP_LOGDUMP) {
2137 error = tcp_log_dump_tp_logbuf(tp, buf,
2141 tcp_log_dump_tp_bucket_logbufs(tp, buf);
2143 * tcp_log_dump_tp_bucket_logbufs() drops the
2152 error = ENOPROTOOPT;
2158 tp = intotcpcb(inp);
2159 switch (sopt->sopt_name) {
2160 #if defined(IPSEC_SUPPORT) || defined(TCP_SIGNATURE)
2162 if (!TCPMD5_ENABLED()) {
2164 return (ENOPROTOOPT);
2166 error = TCPMD5_PCBCTL(inp, sopt);
2171 optval = tp->t_flags & TF_NODELAY;
2173 error = sooptcopyout(sopt, &optval, sizeof optval);
2176 optval = tp->t_maxseg;
2178 error = sooptcopyout(sopt, &optval, sizeof optval);
2181 optval = tp->t_flags & TF_NOOPT;
2183 error = sooptcopyout(sopt, &optval, sizeof optval);
2186 optval = tp->t_flags & TF_NOPUSH;
2188 error = sooptcopyout(sopt, &optval, sizeof optval);
2191 tcp_fill_info(tp, &ti);
2193 error = sooptcopyout(sopt, &ti, sizeof ti);
2195 case TCP_CONGESTION:
2196 len = strlcpy(buf, CC_ALGO(tp)->name, TCP_CA_NAME_MAX);
2198 error = sooptcopyout(sopt, buf, len + 1);
2204 switch (sopt->sopt_name) {
2206 ui = TP_KEEPIDLE(tp) / hz;
2209 ui = TP_KEEPINTVL(tp) / hz;
2212 ui = TP_KEEPINIT(tp) / hz;
2215 ui = TP_KEEPCNT(tp);
2219 error = sooptcopyout(sopt, &ui, sizeof(ui));
2224 optval = tcp_pcap_get_sock_max(TCP_PCAP_OUT ?
2225 &(tp->t_outpkts) : &(tp->t_inpkts));
2227 error = sooptcopyout(sopt, &optval, sizeof optval);
2231 optval = tp->t_flags & TF_FASTOPEN;
2233 error = sooptcopyout(sopt, &optval, sizeof optval);
2237 optval = tp->t_logstate;
2239 error = sooptcopyout(sopt, &optval, sizeof(optval));
2242 /* tcp_log_getlogbuf() does INP_WUNLOCK(inp) */
2243 error = tcp_log_getlogbuf(sopt, tp);
2246 len = tcp_log_get_id(tp, buf);
2248 error = sooptcopyout(sopt, buf, len + 1);
2258 error = ENOPROTOOPT;
2265 #undef INP_WLOCK_RECHECK
2266 #undef INP_WLOCK_RECHECK_CLEANUP
2269 * Attach TCP protocol to socket, allocating
2270 * internet protocol control block, tcp control block,
2271 * bufer space, and entering LISTEN state if to accept connections.
2274 tcp_attach(struct socket *so)
2278 struct epoch_tracker et;
2281 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
2282 error = soreserve(so, V_tcp_sendspace, V_tcp_recvspace);
2286 so->so_rcv.sb_flags |= SB_AUTOSIZE;
2287 so->so_snd.sb_flags |= SB_AUTOSIZE;
2288 INP_INFO_RLOCK_ET(&V_tcbinfo, et);
2289 error = in_pcballoc(so, &V_tcbinfo);
2291 INP_INFO_RUNLOCK_ET(&V_tcbinfo, et);
2294 inp = sotoinpcb(so);
2296 if (inp->inp_vflag & INP_IPV6PROTO) {
2297 inp->inp_vflag |= INP_IPV6;
2298 if ((inp->inp_flags & IN6P_IPV6_V6ONLY) == 0)
2299 inp->inp_vflag |= INP_IPV4;
2300 inp->in6p_hops = -1; /* use kernel default */
2304 inp->inp_vflag |= INP_IPV4;
2305 tp = tcp_newtcpcb(inp);
2309 INP_INFO_RUNLOCK_ET(&V_tcbinfo, et);
2312 tp->t_state = TCPS_CLOSED;
2314 INP_INFO_RUNLOCK_ET(&V_tcbinfo, et);
2315 TCPSTATES_INC(TCPS_CLOSED);
2320 * Initiate (or continue) disconnect.
2321 * If embryonic state, just send reset (once).
2322 * If in ``let data drain'' option and linger null, just drop.
2323 * Otherwise (hard), mark socket disconnecting and drop
2324 * current input data; switch states based on user close, and
2325 * send segment to peer (with FIN).
2328 tcp_disconnect(struct tcpcb *tp)
2330 struct inpcb *inp = tp->t_inpcb;
2331 struct socket *so = inp->inp_socket;
2333 INP_INFO_RLOCK_ASSERT(&V_tcbinfo);
2334 INP_WLOCK_ASSERT(inp);
2337 * Neither tcp_close() nor tcp_drop() should return NULL, as the
2338 * socket is still open.
2340 if (tp->t_state < TCPS_ESTABLISHED &&
2341 !(tp->t_state > TCPS_LISTEN && IS_FASTOPEN(tp->t_flags))) {
2344 ("tcp_disconnect: tcp_close() returned NULL"));
2345 } else if ((so->so_options & SO_LINGER) && so->so_linger == 0) {
2346 tp = tcp_drop(tp, 0);
2348 ("tcp_disconnect: tcp_drop() returned NULL"));
2350 soisdisconnecting(so);
2351 sbflush(&so->so_rcv);
2353 if (!(inp->inp_flags & INP_DROPPED))
2354 tp->t_fb->tfb_tcp_output(tp);
2359 * User issued close, and wish to trail through shutdown states:
2360 * if never received SYN, just forget it. If got a SYN from peer,
2361 * but haven't sent FIN, then go to FIN_WAIT_1 state to send peer a FIN.
2362 * If already got a FIN from peer, then almost done; go to LAST_ACK
2363 * state. In all other cases, have already sent FIN to peer (e.g.
2364 * after PRU_SHUTDOWN), and just have to play tedious game waiting
2365 * for peer to send FIN or not respond to keep-alives, etc.
2366 * We can let the user exit from the close as soon as the FIN is acked.
2369 tcp_usrclosed(struct tcpcb *tp)
2372 INP_INFO_RLOCK_ASSERT(&V_tcbinfo);
2373 INP_WLOCK_ASSERT(tp->t_inpcb);
2375 switch (tp->t_state) {
2378 tcp_offload_listen_stop(tp);
2380 tcp_state_change(tp, TCPS_CLOSED);
2385 * tcp_close() should never return NULL here as the socket is
2389 ("tcp_usrclosed: tcp_close() returned NULL"));
2393 case TCPS_SYN_RECEIVED:
2394 tp->t_flags |= TF_NEEDFIN;
2397 case TCPS_ESTABLISHED:
2398 tcp_state_change(tp, TCPS_FIN_WAIT_1);
2401 case TCPS_CLOSE_WAIT:
2402 tcp_state_change(tp, TCPS_LAST_ACK);
2405 if (tp->t_state >= TCPS_FIN_WAIT_2) {
2406 soisdisconnected(tp->t_inpcb->inp_socket);
2407 /* Prevent the connection hanging in FIN_WAIT_2 forever. */
2408 if (tp->t_state == TCPS_FIN_WAIT_2) {
2411 timeout = (tcp_fast_finwait2_recycle) ?
2412 tcp_finwait2_timeout : TP_MAXIDLE(tp);
2413 tcp_timer_activate(tp, TT_2MSL, timeout);
2420 db_print_indent(int indent)
2424 for (i = 0; i < indent; i++)
2429 db_print_tstate(int t_state)
2434 db_printf("TCPS_CLOSED");
2438 db_printf("TCPS_LISTEN");
2442 db_printf("TCPS_SYN_SENT");
2445 case TCPS_SYN_RECEIVED:
2446 db_printf("TCPS_SYN_RECEIVED");
2449 case TCPS_ESTABLISHED:
2450 db_printf("TCPS_ESTABLISHED");
2453 case TCPS_CLOSE_WAIT:
2454 db_printf("TCPS_CLOSE_WAIT");
2457 case TCPS_FIN_WAIT_1:
2458 db_printf("TCPS_FIN_WAIT_1");
2462 db_printf("TCPS_CLOSING");
2466 db_printf("TCPS_LAST_ACK");
2469 case TCPS_FIN_WAIT_2:
2470 db_printf("TCPS_FIN_WAIT_2");
2473 case TCPS_TIME_WAIT:
2474 db_printf("TCPS_TIME_WAIT");
2478 db_printf("unknown");
2484 db_print_tflags(u_int t_flags)
2489 if (t_flags & TF_ACKNOW) {
2490 db_printf("%sTF_ACKNOW", comma ? ", " : "");
2493 if (t_flags & TF_DELACK) {
2494 db_printf("%sTF_DELACK", comma ? ", " : "");
2497 if (t_flags & TF_NODELAY) {
2498 db_printf("%sTF_NODELAY", comma ? ", " : "");
2501 if (t_flags & TF_NOOPT) {
2502 db_printf("%sTF_NOOPT", comma ? ", " : "");
2505 if (t_flags & TF_SENTFIN) {
2506 db_printf("%sTF_SENTFIN", comma ? ", " : "");
2509 if (t_flags & TF_REQ_SCALE) {
2510 db_printf("%sTF_REQ_SCALE", comma ? ", " : "");
2513 if (t_flags & TF_RCVD_SCALE) {
2514 db_printf("%sTF_RECVD_SCALE", comma ? ", " : "");
2517 if (t_flags & TF_REQ_TSTMP) {
2518 db_printf("%sTF_REQ_TSTMP", comma ? ", " : "");
2521 if (t_flags & TF_RCVD_TSTMP) {
2522 db_printf("%sTF_RCVD_TSTMP", comma ? ", " : "");
2525 if (t_flags & TF_SACK_PERMIT) {
2526 db_printf("%sTF_SACK_PERMIT", comma ? ", " : "");
2529 if (t_flags & TF_NEEDSYN) {
2530 db_printf("%sTF_NEEDSYN", comma ? ", " : "");
2533 if (t_flags & TF_NEEDFIN) {
2534 db_printf("%sTF_NEEDFIN", comma ? ", " : "");
2537 if (t_flags & TF_NOPUSH) {
2538 db_printf("%sTF_NOPUSH", comma ? ", " : "");
2541 if (t_flags & TF_MORETOCOME) {
2542 db_printf("%sTF_MORETOCOME", comma ? ", " : "");
2545 if (t_flags & TF_LQ_OVERFLOW) {
2546 db_printf("%sTF_LQ_OVERFLOW", comma ? ", " : "");
2549 if (t_flags & TF_LASTIDLE) {
2550 db_printf("%sTF_LASTIDLE", comma ? ", " : "");
2553 if (t_flags & TF_RXWIN0SENT) {
2554 db_printf("%sTF_RXWIN0SENT", comma ? ", " : "");
2557 if (t_flags & TF_FASTRECOVERY) {
2558 db_printf("%sTF_FASTRECOVERY", comma ? ", " : "");
2561 if (t_flags & TF_CONGRECOVERY) {
2562 db_printf("%sTF_CONGRECOVERY", comma ? ", " : "");
2565 if (t_flags & TF_WASFRECOVERY) {
2566 db_printf("%sTF_WASFRECOVERY", comma ? ", " : "");
2569 if (t_flags & TF_SIGNATURE) {
2570 db_printf("%sTF_SIGNATURE", comma ? ", " : "");
2573 if (t_flags & TF_FORCEDATA) {
2574 db_printf("%sTF_FORCEDATA", comma ? ", " : "");
2577 if (t_flags & TF_TSO) {
2578 db_printf("%sTF_TSO", comma ? ", " : "");
2581 if (t_flags & TF_ECN_PERMIT) {
2582 db_printf("%sTF_ECN_PERMIT", comma ? ", " : "");
2585 if (t_flags & TF_FASTOPEN) {
2586 db_printf("%sTF_FASTOPEN", comma ? ", " : "");
2592 db_print_toobflags(char t_oobflags)
2597 if (t_oobflags & TCPOOB_HAVEDATA) {
2598 db_printf("%sTCPOOB_HAVEDATA", comma ? ", " : "");
2601 if (t_oobflags & TCPOOB_HADDATA) {
2602 db_printf("%sTCPOOB_HADDATA", comma ? ", " : "");
2608 db_print_tcpcb(struct tcpcb *tp, const char *name, int indent)
2611 db_print_indent(indent);
2612 db_printf("%s at %p\n", name, tp);
2616 db_print_indent(indent);
2617 db_printf("t_segq first: %p t_segqlen: %d t_dupacks: %d\n",
2618 TAILQ_FIRST(&tp->t_segq), tp->t_segqlen, tp->t_dupacks);
2620 db_print_indent(indent);
2621 db_printf("tt_rexmt: %p tt_persist: %p tt_keep: %p\n",
2622 &tp->t_timers->tt_rexmt, &tp->t_timers->tt_persist, &tp->t_timers->tt_keep);
2624 db_print_indent(indent);
2625 db_printf("tt_2msl: %p tt_delack: %p t_inpcb: %p\n", &tp->t_timers->tt_2msl,
2626 &tp->t_timers->tt_delack, tp->t_inpcb);
2628 db_print_indent(indent);
2629 db_printf("t_state: %d (", tp->t_state);
2630 db_print_tstate(tp->t_state);
2633 db_print_indent(indent);
2634 db_printf("t_flags: 0x%x (", tp->t_flags);
2635 db_print_tflags(tp->t_flags);
2638 db_print_indent(indent);
2639 db_printf("snd_una: 0x%08x snd_max: 0x%08x snd_nxt: x0%08x\n",
2640 tp->snd_una, tp->snd_max, tp->snd_nxt);
2642 db_print_indent(indent);
2643 db_printf("snd_up: 0x%08x snd_wl1: 0x%08x snd_wl2: 0x%08x\n",
2644 tp->snd_up, tp->snd_wl1, tp->snd_wl2);
2646 db_print_indent(indent);
2647 db_printf("iss: 0x%08x irs: 0x%08x rcv_nxt: 0x%08x\n",
2648 tp->iss, tp->irs, tp->rcv_nxt);
2650 db_print_indent(indent);
2651 db_printf("rcv_adv: 0x%08x rcv_wnd: %u rcv_up: 0x%08x\n",
2652 tp->rcv_adv, tp->rcv_wnd, tp->rcv_up);
2654 db_print_indent(indent);
2655 db_printf("snd_wnd: %u snd_cwnd: %u\n",
2656 tp->snd_wnd, tp->snd_cwnd);
2658 db_print_indent(indent);
2659 db_printf("snd_ssthresh: %u snd_recover: "
2660 "0x%08x\n", tp->snd_ssthresh, tp->snd_recover);
2662 db_print_indent(indent);
2663 db_printf("t_rcvtime: %u t_startime: %u\n",
2664 tp->t_rcvtime, tp->t_starttime);
2666 db_print_indent(indent);
2667 db_printf("t_rttime: %u t_rtsq: 0x%08x\n",
2668 tp->t_rtttime, tp->t_rtseq);
2670 db_print_indent(indent);
2671 db_printf("t_rxtcur: %d t_maxseg: %u t_srtt: %d\n",
2672 tp->t_rxtcur, tp->t_maxseg, tp->t_srtt);
2674 db_print_indent(indent);
2675 db_printf("t_rttvar: %d t_rxtshift: %d t_rttmin: %u "
2676 "t_rttbest: %u\n", tp->t_rttvar, tp->t_rxtshift, tp->t_rttmin,
2679 db_print_indent(indent);
2680 db_printf("t_rttupdated: %lu max_sndwnd: %u t_softerror: %d\n",
2681 tp->t_rttupdated, tp->max_sndwnd, tp->t_softerror);
2683 db_print_indent(indent);
2684 db_printf("t_oobflags: 0x%x (", tp->t_oobflags);
2685 db_print_toobflags(tp->t_oobflags);
2686 db_printf(") t_iobc: 0x%02x\n", tp->t_iobc);
2688 db_print_indent(indent);
2689 db_printf("snd_scale: %u rcv_scale: %u request_r_scale: %u\n",
2690 tp->snd_scale, tp->rcv_scale, tp->request_r_scale);
2692 db_print_indent(indent);
2693 db_printf("ts_recent: %u ts_recent_age: %u\n",
2694 tp->ts_recent, tp->ts_recent_age);
2696 db_print_indent(indent);
2697 db_printf("ts_offset: %u last_ack_sent: 0x%08x snd_cwnd_prev: "
2698 "%u\n", tp->ts_offset, tp->last_ack_sent, tp->snd_cwnd_prev);
2700 db_print_indent(indent);
2701 db_printf("snd_ssthresh_prev: %u snd_recover_prev: 0x%08x "
2702 "t_badrxtwin: %u\n", tp->snd_ssthresh_prev,
2703 tp->snd_recover_prev, tp->t_badrxtwin);
2705 db_print_indent(indent);
2706 db_printf("snd_numholes: %d snd_holes first: %p\n",
2707 tp->snd_numholes, TAILQ_FIRST(&tp->snd_holes));
2709 db_print_indent(indent);
2710 db_printf("snd_fack: 0x%08x rcv_numsacks: %d sack_newdata: "
2711 "0x%08x\n", tp->snd_fack, tp->rcv_numsacks, tp->sack_newdata);
2713 /* Skip sackblks, sackhint. */
2715 db_print_indent(indent);
2716 db_printf("t_rttlow: %d rfbuf_ts: %u rfbuf_cnt: %d\n",
2717 tp->t_rttlow, tp->rfbuf_ts, tp->rfbuf_cnt);
2720 DB_SHOW_COMMAND(tcpcb, db_show_tcpcb)
2725 db_printf("usage: show tcpcb <addr>\n");
2728 tp = (struct tcpcb *)addr;
2730 db_print_tcpcb(tp, "tcpcb", 0);