2 * Copyright (c) 1982, 1986, 1988, 1993
3 * The Regents of the University of California.
4 * Copyright (c) 2006-2007 Robert N. M. Watson
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 4. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * From: @(#)tcp_usrreq.c 8.2 (Berkeley) 1/3/94
34 #include <sys/cdefs.h>
35 __FBSDID("$FreeBSD$");
39 #include "opt_inet6.h"
40 #include "opt_tcpdebug.h"
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/malloc.h>
45 #include <sys/kernel.h>
46 #include <sys/sysctl.h>
49 #include <sys/domain.h>
51 #include <sys/socket.h>
52 #include <sys/socketvar.h>
53 #include <sys/protosw.h>
62 #include <net/route.h>
64 #include <netinet/in.h>
65 #include <netinet/in_systm.h>
67 #include <netinet/ip6.h>
69 #include <netinet/in_pcb.h>
71 #include <netinet6/in6_pcb.h>
73 #include <netinet/in_var.h>
74 #include <netinet/ip_var.h>
76 #include <netinet6/ip6_var.h>
77 #include <netinet6/scope6_var.h>
79 #include <netinet/tcp.h>
80 #include <netinet/tcp_fsm.h>
81 #include <netinet/tcp_seq.h>
82 #include <netinet/tcp_timer.h>
83 #include <netinet/tcp_var.h>
84 #include <netinet/tcpip.h>
86 #include <netinet/tcp_debug.h>
88 #include <netinet/tcp_offload.h>
91 * TCP protocol interface to socket abstraction.
93 static int tcp_attach(struct socket *);
94 static int tcp_connect(struct tcpcb *, struct sockaddr *,
97 static int tcp6_connect(struct tcpcb *, struct sockaddr *,
100 static void tcp_disconnect(struct tcpcb *);
101 static void tcp_usrclosed(struct tcpcb *);
102 static void tcp_fill_info(struct tcpcb *, struct tcp_info *);
105 #define TCPDEBUG0 int ostate = 0
106 #define TCPDEBUG1() ostate = tp ? tp->t_state : 0
107 #define TCPDEBUG2(req) if (tp && (so->so_options & SO_DEBUG)) \
108 tcp_trace(TA_USER, ostate, tp, 0, 0, req)
112 #define TCPDEBUG2(req)
116 * TCP attaches to socket via pru_attach(), reserving space,
117 * and an internet control block.
120 tcp_usr_attach(struct socket *so, int proto, struct thread *td)
123 struct tcpcb *tp = NULL;
128 KASSERT(inp == NULL, ("tcp_usr_attach: inp != NULL"));
131 error = tcp_attach(so);
135 if ((so->so_options & SO_LINGER) && so->so_linger == 0)
136 so->so_linger = TCP_LINGERTIME;
141 TCPDEBUG2(PRU_ATTACH);
146 * tcp_detach is called when the socket layer loses its final reference
147 * to the socket, be it a file descriptor reference, a reference from TCP,
148 * etc. At this point, there is only one case in which we will keep around
149 * inpcb state: time wait.
151 * This function can probably be re-absorbed back into tcp_usr_detach() now
152 * that there is a single detach path.
155 tcp_detach(struct socket *so, struct inpcb *inp)
159 INP_INFO_WLOCK_ASSERT(&tcbinfo);
160 INP_WLOCK_ASSERT(inp);
162 KASSERT(so->so_pcb == inp, ("tcp_detach: so_pcb != inp"));
163 KASSERT(inp->inp_socket == so, ("tcp_detach: inp_socket != so"));
167 if (inp->inp_flags & INP_TIMEWAIT) {
169 * There are two cases to handle: one in which the time wait
170 * state is being discarded (INP_DROPPED), and one in which
171 * this connection will remain in timewait. In the former,
172 * it is time to discard all state (except tcptw, which has
173 * already been discarded by the timewait close code, which
174 * should be further up the call stack somewhere). In the
175 * latter case, we detach from the socket, but leave the pcb
176 * present until timewait ends.
178 * XXXRW: Would it be cleaner to free the tcptw here?
180 if (inp->inp_flags & INP_DROPPED) {
181 KASSERT(tp == NULL, ("tcp_detach: INP_TIMEWAIT && "
182 "INP_DROPPED && tp != NULL"));
191 * If the connection is not in timewait, we consider two
192 * two conditions: one in which no further processing is
193 * necessary (dropped || embryonic), and one in which TCP is
194 * not yet done, but no longer requires the socket, so the
195 * pcb will persist for the time being.
197 * XXXRW: Does the second case still occur?
199 if (inp->inp_flags & INP_DROPPED ||
200 tp->t_state < TCPS_SYN_SENT) {
210 * pru_detach() detaches the TCP protocol from the socket.
211 * If the protocol state is non-embryonic, then can't
212 * do this directly: have to initiate a pru_disconnect(),
213 * which may finish later; embryonic TCB's can just
217 tcp_usr_detach(struct socket *so)
222 KASSERT(inp != NULL, ("tcp_usr_detach: inp == NULL"));
223 INP_INFO_WLOCK(&tcbinfo);
225 KASSERT(inp->inp_socket != NULL,
226 ("tcp_usr_detach: inp_socket == NULL"));
228 INP_INFO_WUNLOCK(&tcbinfo);
232 * Give the socket an address.
235 tcp_usr_bind(struct socket *so, struct sockaddr *nam, struct thread *td)
239 struct tcpcb *tp = NULL;
240 struct sockaddr_in *sinp;
242 sinp = (struct sockaddr_in *)nam;
243 if (nam->sa_len != sizeof (*sinp))
246 * Must check for multicast addresses and disallow binding
249 if (sinp->sin_family == AF_INET &&
250 IN_MULTICAST(ntohl(sinp->sin_addr.s_addr)))
251 return (EAFNOSUPPORT);
254 INP_INFO_WLOCK(&tcbinfo);
256 KASSERT(inp != NULL, ("tcp_usr_bind: inp == NULL"));
258 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
264 error = in_pcbbind(inp, nam, td->td_ucred);
268 INP_INFO_WUNLOCK(&tcbinfo);
275 tcp6_usr_bind(struct socket *so, struct sockaddr *nam, struct thread *td)
279 struct tcpcb *tp = NULL;
280 struct sockaddr_in6 *sin6p;
282 sin6p = (struct sockaddr_in6 *)nam;
283 if (nam->sa_len != sizeof (*sin6p))
286 * Must check for multicast addresses and disallow binding
289 if (sin6p->sin6_family == AF_INET6 &&
290 IN6_IS_ADDR_MULTICAST(&sin6p->sin6_addr))
291 return (EAFNOSUPPORT);
294 INP_INFO_WLOCK(&tcbinfo);
296 KASSERT(inp != NULL, ("tcp6_usr_bind: inp == NULL"));
298 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
304 inp->inp_vflag &= ~INP_IPV4;
305 inp->inp_vflag |= INP_IPV6;
306 if ((inp->inp_flags & IN6P_IPV6_V6ONLY) == 0) {
307 if (IN6_IS_ADDR_UNSPECIFIED(&sin6p->sin6_addr))
308 inp->inp_vflag |= INP_IPV4;
309 else if (IN6_IS_ADDR_V4MAPPED(&sin6p->sin6_addr)) {
310 struct sockaddr_in sin;
312 in6_sin6_2_sin(&sin, sin6p);
313 inp->inp_vflag |= INP_IPV4;
314 inp->inp_vflag &= ~INP_IPV6;
315 error = in_pcbbind(inp, (struct sockaddr *)&sin,
320 error = in6_pcbbind(inp, nam, td->td_ucred);
324 INP_INFO_WUNLOCK(&tcbinfo);
330 * Prepare to accept connections.
333 tcp_usr_listen(struct socket *so, int backlog, struct thread *td)
337 struct tcpcb *tp = NULL;
340 INP_INFO_WLOCK(&tcbinfo);
342 KASSERT(inp != NULL, ("tcp_usr_listen: inp == NULL"));
344 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
351 error = solisten_proto_check(so);
352 if (error == 0 && inp->inp_lport == 0)
353 error = in_pcbbind(inp, (struct sockaddr *)0, td->td_ucred);
355 tp->t_state = TCPS_LISTEN;
356 solisten_proto(so, backlog);
357 tcp_offload_listen_open(tp);
362 TCPDEBUG2(PRU_LISTEN);
364 INP_INFO_WUNLOCK(&tcbinfo);
370 tcp6_usr_listen(struct socket *so, int backlog, struct thread *td)
374 struct tcpcb *tp = NULL;
377 INP_INFO_WLOCK(&tcbinfo);
379 KASSERT(inp != NULL, ("tcp6_usr_listen: inp == NULL"));
381 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
388 error = solisten_proto_check(so);
389 if (error == 0 && inp->inp_lport == 0) {
390 inp->inp_vflag &= ~INP_IPV4;
391 if ((inp->inp_flags & IN6P_IPV6_V6ONLY) == 0)
392 inp->inp_vflag |= INP_IPV4;
393 error = in6_pcbbind(inp, (struct sockaddr *)0, td->td_ucred);
396 tp->t_state = TCPS_LISTEN;
397 solisten_proto(so, backlog);
402 TCPDEBUG2(PRU_LISTEN);
404 INP_INFO_WUNLOCK(&tcbinfo);
410 * Initiate connection to peer.
411 * Create a template for use in transmissions on this connection.
412 * Enter SYN_SENT state, and mark socket as connecting.
413 * Start keep-alive timer, and seed output sequence space.
414 * Send initial segment on connection.
417 tcp_usr_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
421 struct tcpcb *tp = NULL;
422 struct sockaddr_in *sinp;
424 sinp = (struct sockaddr_in *)nam;
425 if (nam->sa_len != sizeof (*sinp))
428 * Must disallow TCP ``connections'' to multicast addresses.
430 if (sinp->sin_family == AF_INET
431 && IN_MULTICAST(ntohl(sinp->sin_addr.s_addr)))
432 return (EAFNOSUPPORT);
433 if ((error = prison_remote_ip4(td->td_ucred, &sinp->sin_addr)) != 0)
437 INP_INFO_WLOCK(&tcbinfo);
439 KASSERT(inp != NULL, ("tcp_usr_connect: inp == NULL"));
441 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
447 if ((error = tcp_connect(tp, nam, td)) != 0)
449 error = tcp_output_connect(so, nam);
451 TCPDEBUG2(PRU_CONNECT);
453 INP_INFO_WUNLOCK(&tcbinfo);
459 tcp6_usr_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
463 struct tcpcb *tp = NULL;
464 struct sockaddr_in6 *sin6p;
468 sin6p = (struct sockaddr_in6 *)nam;
469 if (nam->sa_len != sizeof (*sin6p))
472 * Must disallow TCP ``connections'' to multicast addresses.
474 if (sin6p->sin6_family == AF_INET6
475 && IN6_IS_ADDR_MULTICAST(&sin6p->sin6_addr))
476 return (EAFNOSUPPORT);
478 INP_INFO_WLOCK(&tcbinfo);
480 KASSERT(inp != NULL, ("tcp6_usr_connect: inp == NULL"));
482 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
488 if (IN6_IS_ADDR_V4MAPPED(&sin6p->sin6_addr)) {
489 struct sockaddr_in sin;
491 if ((inp->inp_flags & IN6P_IPV6_V6ONLY) != 0) {
496 in6_sin6_2_sin(&sin, sin6p);
497 inp->inp_vflag |= INP_IPV4;
498 inp->inp_vflag &= ~INP_IPV6;
499 if ((error = prison_remote_ip4(td->td_ucred,
500 &sin.sin_addr)) != 0)
502 if ((error = tcp_connect(tp, (struct sockaddr *)&sin, td)) != 0)
504 error = tcp_output_connect(so, nam);
507 inp->inp_vflag &= ~INP_IPV4;
508 inp->inp_vflag |= INP_IPV6;
509 inp->inp_inc.inc_flags |= INC_ISIPV6;
510 if ((error = prison_remote_ip6(td->td_ucred, &sin6p->sin6_addr)) != 0)
512 if ((error = tcp6_connect(tp, nam, td)) != 0)
514 error = tcp_output_connect(so, nam);
517 TCPDEBUG2(PRU_CONNECT);
519 INP_INFO_WUNLOCK(&tcbinfo);
525 * Initiate disconnect from peer.
526 * If connection never passed embryonic stage, just drop;
527 * else if don't need to let data drain, then can just drop anyways,
528 * else have to begin TCP shutdown process: mark socket disconnecting,
529 * drain unread data, state switch to reflect user close, and
530 * send segment (e.g. FIN) to peer. Socket will be really disconnected
531 * when peer sends FIN and acks ours.
533 * SHOULD IMPLEMENT LATER PRU_CONNECT VIA REALLOC TCPCB.
536 tcp_usr_disconnect(struct socket *so)
539 struct tcpcb *tp = NULL;
543 INP_INFO_WLOCK(&tcbinfo);
545 KASSERT(inp != NULL, ("tcp_usr_disconnect: inp == NULL"));
547 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
555 TCPDEBUG2(PRU_DISCONNECT);
557 INP_INFO_WUNLOCK(&tcbinfo);
562 * Accept a connection. Essentially all the work is
563 * done at higher levels; just return the address
564 * of the peer, storing through addr.
567 tcp_usr_accept(struct socket *so, struct sockaddr **nam)
570 struct inpcb *inp = NULL;
571 struct tcpcb *tp = NULL;
576 if (so->so_state & SS_ISDISCONNECTED)
577 return (ECONNABORTED);
580 KASSERT(inp != NULL, ("tcp_usr_accept: inp == NULL"));
581 INP_INFO_RLOCK(&tcbinfo);
583 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
584 error = ECONNABORTED;
591 * We inline in_getpeeraddr and COMMON_END here, so that we can
592 * copy the data of interest and defer the malloc until after we
595 port = inp->inp_fport;
596 addr = inp->inp_faddr;
599 TCPDEBUG2(PRU_ACCEPT);
601 INP_INFO_RUNLOCK(&tcbinfo);
603 *nam = in_sockaddr(port, &addr);
609 tcp6_usr_accept(struct socket *so, struct sockaddr **nam)
611 struct inpcb *inp = NULL;
613 struct tcpcb *tp = NULL;
615 struct in6_addr addr6;
620 if (so->so_state & SS_ISDISCONNECTED)
621 return (ECONNABORTED);
624 KASSERT(inp != NULL, ("tcp6_usr_accept: inp == NULL"));
626 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
627 error = ECONNABORTED;
634 * We inline in6_mapped_peeraddr and COMMON_END here, so that we can
635 * copy the data of interest and defer the malloc until after we
638 if (inp->inp_vflag & INP_IPV4) {
640 port = inp->inp_fport;
641 addr = inp->inp_faddr;
643 port = inp->inp_fport;
644 addr6 = inp->in6p_faddr;
648 TCPDEBUG2(PRU_ACCEPT);
652 *nam = in6_v4mapsin6_sockaddr(port, &addr);
654 *nam = in6_sockaddr(port, &addr6);
661 * Mark the connection as being incapable of further output.
664 tcp_usr_shutdown(struct socket *so)
668 struct tcpcb *tp = NULL;
671 INP_INFO_WLOCK(&tcbinfo);
673 KASSERT(inp != NULL, ("inp == NULL"));
675 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
683 if (!(inp->inp_flags & INP_DROPPED))
684 error = tcp_output_disconnect(tp);
687 TCPDEBUG2(PRU_SHUTDOWN);
689 INP_INFO_WUNLOCK(&tcbinfo);
695 * After a receive, possibly send window update to peer.
698 tcp_usr_rcvd(struct socket *so, int flags)
701 struct tcpcb *tp = NULL;
706 KASSERT(inp != NULL, ("tcp_usr_rcvd: inp == NULL"));
708 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
723 * Do a send by putting data in output queue and updating urgent
724 * marker if URG set. Possibly send more data. Unlike the other
725 * pru_*() routines, the mbuf chains are our responsibility. We
726 * must either enqueue them or free them. The other pru_* routines
727 * generally are caller-frees.
730 tcp_usr_send(struct socket *so, int flags, struct mbuf *m,
731 struct sockaddr *nam, struct mbuf *control, struct thread *td)
735 struct tcpcb *tp = NULL;
743 * We require the pcbinfo lock in two cases:
745 * (1) An implied connect is taking place, which can result in
746 * binding IPs and ports and hence modification of the pcb hash
749 * (2) PRUS_EOF is set, resulting in explicit close on the send.
751 if ((nam != NULL) || (flags & PRUS_EOF)) {
752 INP_INFO_WLOCK(&tcbinfo);
756 KASSERT(inp != NULL, ("tcp_usr_send: inp == NULL"));
758 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
767 isipv6 = nam && nam->sa_family == AF_INET6;
772 /* TCP doesn't do control messages (rights, creds, etc) */
773 if (control->m_len) {
780 m_freem(control); /* empty control, just free it */
782 if (!(flags & PRUS_OOB)) {
783 sbappendstream(&so->so_snd, m);
784 if (nam && tp->t_state < TCPS_SYN_SENT) {
786 * Do implied connect if not yet connected,
787 * initialize window to default value, and
788 * initialize maxseg/maxopd using peer's cached
791 INP_INFO_WLOCK_ASSERT(&tcbinfo);
794 error = tcp6_connect(tp, nam, td);
797 error = tcp_connect(tp, nam, td);
800 tp->snd_wnd = TTCP_CLIENT_SND_WND;
803 if (flags & PRUS_EOF) {
805 * Close the send side of the connection after
808 INP_INFO_WLOCK_ASSERT(&tcbinfo);
813 INP_INFO_WUNLOCK(&tcbinfo);
816 if (!(inp->inp_flags & INP_DROPPED)) {
817 if (flags & PRUS_MORETOCOME)
818 tp->t_flags |= TF_MORETOCOME;
819 error = tcp_output_send(tp);
820 if (flags & PRUS_MORETOCOME)
821 tp->t_flags &= ~TF_MORETOCOME;
825 * XXXRW: PRUS_EOF not implemented with PRUS_OOB?
827 SOCKBUF_LOCK(&so->so_snd);
828 if (sbspace(&so->so_snd) < -512) {
829 SOCKBUF_UNLOCK(&so->so_snd);
835 * According to RFC961 (Assigned Protocols),
836 * the urgent pointer points to the last octet
837 * of urgent data. We continue, however,
838 * to consider it to indicate the first octet
839 * of data past the urgent section.
840 * Otherwise, snd_up should be one lower.
842 sbappendstream_locked(&so->so_snd, m);
843 SOCKBUF_UNLOCK(&so->so_snd);
844 if (nam && tp->t_state < TCPS_SYN_SENT) {
846 * Do implied connect if not yet connected,
847 * initialize window to default value, and
848 * initialize maxseg/maxopd using peer's cached
851 INP_INFO_WLOCK_ASSERT(&tcbinfo);
854 error = tcp6_connect(tp, nam, td);
857 error = tcp_connect(tp, nam, td);
860 tp->snd_wnd = TTCP_CLIENT_SND_WND;
862 INP_INFO_WUNLOCK(&tcbinfo);
865 INP_INFO_WUNLOCK(&tcbinfo);
868 tp->snd_up = tp->snd_una + so->so_snd.sb_cc;
869 tp->t_flags |= TF_FORCEDATA;
870 error = tcp_output_send(tp);
871 tp->t_flags &= ~TF_FORCEDATA;
874 TCPDEBUG2((flags & PRUS_OOB) ? PRU_SENDOOB :
875 ((flags & PRUS_EOF) ? PRU_SEND_EOF : PRU_SEND));
878 INP_INFO_WUNLOCK(&tcbinfo);
883 * Abort the TCP. Drop the connection abruptly.
886 tcp_usr_abort(struct socket *so)
889 struct tcpcb *tp = NULL;
893 KASSERT(inp != NULL, ("tcp_usr_abort: inp == NULL"));
895 INP_INFO_WLOCK(&tcbinfo);
897 KASSERT(inp->inp_socket != NULL,
898 ("tcp_usr_abort: inp_socket == NULL"));
901 * If we still have full TCP state, and we're not dropped, drop.
903 if (!(inp->inp_flags & INP_TIMEWAIT) &&
904 !(inp->inp_flags & INP_DROPPED)) {
907 tcp_drop(tp, ECONNABORTED);
908 TCPDEBUG2(PRU_ABORT);
910 if (!(inp->inp_flags & INP_DROPPED)) {
912 so->so_state |= SS_PROTOREF;
914 inp->inp_flags |= INP_SOCKREF;
917 INP_INFO_WUNLOCK(&tcbinfo);
921 * TCP socket is closed. Start friendly disconnect.
924 tcp_usr_close(struct socket *so)
927 struct tcpcb *tp = NULL;
931 KASSERT(inp != NULL, ("tcp_usr_close: inp == NULL"));
933 INP_INFO_WLOCK(&tcbinfo);
935 KASSERT(inp->inp_socket != NULL,
936 ("tcp_usr_close: inp_socket == NULL"));
939 * If we still have full TCP state, and we're not dropped, initiate
942 if (!(inp->inp_flags & INP_TIMEWAIT) &&
943 !(inp->inp_flags & INP_DROPPED)) {
947 TCPDEBUG2(PRU_CLOSE);
949 if (!(inp->inp_flags & INP_DROPPED)) {
951 so->so_state |= SS_PROTOREF;
953 inp->inp_flags |= INP_SOCKREF;
956 INP_INFO_WUNLOCK(&tcbinfo);
960 * Receive out-of-band data.
963 tcp_usr_rcvoob(struct socket *so, struct mbuf *m, int flags)
967 struct tcpcb *tp = NULL;
971 KASSERT(inp != NULL, ("tcp_usr_rcvoob: inp == NULL"));
973 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
979 if ((so->so_oobmark == 0 &&
980 (so->so_rcv.sb_state & SBS_RCVATMARK) == 0) ||
981 so->so_options & SO_OOBINLINE ||
982 tp->t_oobflags & TCPOOB_HADDATA) {
986 if ((tp->t_oobflags & TCPOOB_HAVEDATA) == 0) {
991 *mtod(m, caddr_t) = tp->t_iobc;
992 if ((flags & MSG_PEEK) == 0)
993 tp->t_oobflags ^= (TCPOOB_HAVEDATA | TCPOOB_HADDATA);
996 TCPDEBUG2(PRU_RCVOOB);
1001 struct pr_usrreqs tcp_usrreqs = {
1002 .pru_abort = tcp_usr_abort,
1003 .pru_accept = tcp_usr_accept,
1004 .pru_attach = tcp_usr_attach,
1005 .pru_bind = tcp_usr_bind,
1006 .pru_connect = tcp_usr_connect,
1007 .pru_control = in_control,
1008 .pru_detach = tcp_usr_detach,
1009 .pru_disconnect = tcp_usr_disconnect,
1010 .pru_listen = tcp_usr_listen,
1011 .pru_peeraddr = in_getpeeraddr,
1012 .pru_rcvd = tcp_usr_rcvd,
1013 .pru_rcvoob = tcp_usr_rcvoob,
1014 .pru_send = tcp_usr_send,
1015 .pru_shutdown = tcp_usr_shutdown,
1016 .pru_sockaddr = in_getsockaddr,
1017 .pru_sosetlabel = in_pcbsosetlabel,
1018 .pru_close = tcp_usr_close,
1022 struct pr_usrreqs tcp6_usrreqs = {
1023 .pru_abort = tcp_usr_abort,
1024 .pru_accept = tcp6_usr_accept,
1025 .pru_attach = tcp_usr_attach,
1026 .pru_bind = tcp6_usr_bind,
1027 .pru_connect = tcp6_usr_connect,
1028 .pru_control = in6_control,
1029 .pru_detach = tcp_usr_detach,
1030 .pru_disconnect = tcp_usr_disconnect,
1031 .pru_listen = tcp6_usr_listen,
1032 .pru_peeraddr = in6_mapped_peeraddr,
1033 .pru_rcvd = tcp_usr_rcvd,
1034 .pru_rcvoob = tcp_usr_rcvoob,
1035 .pru_send = tcp_usr_send,
1036 .pru_shutdown = tcp_usr_shutdown,
1037 .pru_sockaddr = in6_mapped_sockaddr,
1038 .pru_sosetlabel = in_pcbsosetlabel,
1039 .pru_close = tcp_usr_close,
1044 * Common subroutine to open a TCP connection to remote host specified
1045 * by struct sockaddr_in in mbuf *nam. Call in_pcbbind to assign a local
1046 * port number if needed. Call in_pcbconnect_setup to do the routing and
1047 * to choose a local host address (interface). If there is an existing
1048 * incarnation of the same connection in TIME-WAIT state and if the remote
1049 * host was sending CC options and if the connection duration was < MSL, then
1050 * truncate the previous TIME-WAIT state and proceed.
1051 * Initialize connection parameters and enter SYN-SENT state.
1054 tcp_connect(struct tcpcb *tp, struct sockaddr *nam, struct thread *td)
1056 struct inpcb *inp = tp->t_inpcb, *oinp;
1057 struct socket *so = inp->inp_socket;
1058 struct in_addr laddr;
1062 INP_INFO_WLOCK_ASSERT(&tcbinfo);
1063 INP_WLOCK_ASSERT(inp);
1065 if (inp->inp_lport == 0) {
1066 error = in_pcbbind(inp, (struct sockaddr *)0, td->td_ucred);
1072 * Cannot simply call in_pcbconnect, because there might be an
1073 * earlier incarnation of this same connection still in
1074 * TIME_WAIT state, creating an ADDRINUSE error.
1076 laddr = inp->inp_laddr;
1077 lport = inp->inp_lport;
1078 error = in_pcbconnect_setup(inp, nam, &laddr.s_addr, &lport,
1079 &inp->inp_faddr.s_addr, &inp->inp_fport, &oinp, td->td_ucred);
1080 if (error && oinp == NULL)
1084 inp->inp_laddr = laddr;
1088 * Compute window scaling to request:
1089 * Scale to fit into sweet spot. See tcp_syncache.c.
1090 * XXX: This should move to tcp_output().
1092 while (tp->request_r_scale < TCP_MAX_WINSHIFT &&
1093 (TCP_MAXWIN << tp->request_r_scale) < sb_max)
1094 tp->request_r_scale++;
1097 tcpstat.tcps_connattempt++;
1098 tp->t_state = TCPS_SYN_SENT;
1099 tcp_timer_activate(tp, TT_KEEP, tcp_keepinit);
1100 tp->iss = tcp_new_isn(tp);
1101 tp->t_bw_rtseq = tp->iss;
1102 tcp_sendseqinit(tp);
1109 tcp6_connect(struct tcpcb *tp, struct sockaddr *nam, struct thread *td)
1111 struct inpcb *inp = tp->t_inpcb, *oinp;
1112 struct socket *so = inp->inp_socket;
1113 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)nam;
1114 struct in6_addr *addr6;
1117 INP_INFO_WLOCK_ASSERT(&tcbinfo);
1118 INP_WLOCK_ASSERT(inp);
1120 if (inp->inp_lport == 0) {
1121 error = in6_pcbbind(inp, (struct sockaddr *)0, td->td_ucred);
1127 * Cannot simply call in_pcbconnect, because there might be an
1128 * earlier incarnation of this same connection still in
1129 * TIME_WAIT state, creating an ADDRINUSE error.
1130 * in6_pcbladdr() also handles scope zone IDs.
1132 error = in6_pcbladdr(inp, nam, &addr6);
1135 oinp = in6_pcblookup_hash(inp->inp_pcbinfo,
1136 &sin6->sin6_addr, sin6->sin6_port,
1137 IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_laddr)
1140 inp->inp_lport, 0, NULL);
1143 if (IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_laddr))
1144 inp->in6p_laddr = *addr6;
1145 inp->in6p_faddr = sin6->sin6_addr;
1146 inp->inp_fport = sin6->sin6_port;
1147 /* update flowinfo - draft-itojun-ipv6-flowlabel-api-00 */
1148 inp->inp_flow &= ~IPV6_FLOWLABEL_MASK;
1149 if (inp->inp_flags & IN6P_AUTOFLOWLABEL)
1151 (htonl(ip6_randomflowlabel()) & IPV6_FLOWLABEL_MASK);
1154 /* Compute window scaling to request. */
1155 while (tp->request_r_scale < TCP_MAX_WINSHIFT &&
1156 (TCP_MAXWIN << tp->request_r_scale) < sb_max)
1157 tp->request_r_scale++;
1160 tcpstat.tcps_connattempt++;
1161 tp->t_state = TCPS_SYN_SENT;
1162 tcp_timer_activate(tp, TT_KEEP, tcp_keepinit);
1163 tp->iss = tcp_new_isn(tp);
1164 tp->t_bw_rtseq = tp->iss;
1165 tcp_sendseqinit(tp);
1172 * Export TCP internal state information via a struct tcp_info, based on the
1173 * Linux 2.6 API. Not ABI compatible as our constants are mapped differently
1174 * (TCP state machine, etc). We export all information using FreeBSD-native
1175 * constants -- for example, the numeric values for tcpi_state will differ
1179 tcp_fill_info(struct tcpcb *tp, struct tcp_info *ti)
1182 INP_WLOCK_ASSERT(tp->t_inpcb);
1183 bzero(ti, sizeof(*ti));
1185 ti->tcpi_state = tp->t_state;
1186 if ((tp->t_flags & TF_REQ_TSTMP) && (tp->t_flags & TF_RCVD_TSTMP))
1187 ti->tcpi_options |= TCPI_OPT_TIMESTAMPS;
1188 if (tp->t_flags & TF_SACK_PERMIT)
1189 ti->tcpi_options |= TCPI_OPT_SACK;
1190 if ((tp->t_flags & TF_REQ_SCALE) && (tp->t_flags & TF_RCVD_SCALE)) {
1191 ti->tcpi_options |= TCPI_OPT_WSCALE;
1192 ti->tcpi_snd_wscale = tp->snd_scale;
1193 ti->tcpi_rcv_wscale = tp->rcv_scale;
1196 ti->tcpi_rtt = ((u_int64_t)tp->t_srtt * tick) >> TCP_RTT_SHIFT;
1197 ti->tcpi_rttvar = ((u_int64_t)tp->t_rttvar * tick) >> TCP_RTTVAR_SHIFT;
1199 ti->tcpi_snd_ssthresh = tp->snd_ssthresh;
1200 ti->tcpi_snd_cwnd = tp->snd_cwnd;
1203 * FreeBSD-specific extension fields for tcp_info.
1205 ti->tcpi_rcv_space = tp->rcv_wnd;
1206 ti->tcpi_rcv_nxt = tp->rcv_nxt;
1207 ti->tcpi_snd_wnd = tp->snd_wnd;
1208 ti->tcpi_snd_bwnd = tp->snd_bwnd;
1209 ti->tcpi_snd_nxt = tp->snd_nxt;
1210 ti->__tcpi_snd_mss = tp->t_maxseg;
1211 ti->__tcpi_rcv_mss = tp->t_maxseg;
1212 if (tp->t_flags & TF_TOE)
1213 ti->tcpi_options |= TCPI_OPT_TOE;
1217 * tcp_ctloutput() must drop the inpcb lock before performing copyin on
1218 * socket option arguments. When it re-acquires the lock after the copy, it
1219 * has to revalidate that the connection is still valid for the socket
1222 #define INP_WLOCK_RECHECK(inp) do { \
1224 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) { \
1226 return (ECONNRESET); \
1228 tp = intotcpcb(inp); \
1232 tcp_ctloutput(struct socket *so, struct sockopt *sopt)
1234 int error, opt, optval;
1240 inp = sotoinpcb(so);
1241 KASSERT(inp != NULL, ("tcp_ctloutput: inp == NULL"));
1243 if (sopt->sopt_level != IPPROTO_TCP) {
1245 if (inp->inp_vflag & INP_IPV6PROTO) {
1247 error = ip6_ctloutput(so, sopt);
1251 error = ip_ctloutput(so, sopt);
1257 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
1259 return (ECONNRESET);
1262 switch (sopt->sopt_dir) {
1264 switch (sopt->sopt_name) {
1265 #ifdef TCP_SIGNATURE
1268 error = sooptcopyin(sopt, &optval, sizeof optval,
1273 INP_WLOCK_RECHECK(inp);
1275 tp->t_flags |= TF_SIGNATURE;
1277 tp->t_flags &= ~TF_SIGNATURE;
1280 #endif /* TCP_SIGNATURE */
1284 error = sooptcopyin(sopt, &optval, sizeof optval,
1289 INP_WLOCK_RECHECK(inp);
1290 switch (sopt->sopt_name) {
1298 opt = 0; /* dead code to fool gcc */
1305 tp->t_flags &= ~opt;
1311 error = sooptcopyin(sopt, &optval, sizeof optval,
1316 INP_WLOCK_RECHECK(inp);
1318 tp->t_flags |= TF_NOPUSH;
1320 tp->t_flags &= ~TF_NOPUSH;
1321 error = tcp_output(tp);
1328 error = sooptcopyin(sopt, &optval, sizeof optval,
1333 INP_WLOCK_RECHECK(inp);
1334 if (optval > 0 && optval <= tp->t_maxseg &&
1335 optval + 40 >= tcp_minmss)
1336 tp->t_maxseg = optval;
1349 error = ENOPROTOOPT;
1355 tp = intotcpcb(inp);
1356 switch (sopt->sopt_name) {
1357 #ifdef TCP_SIGNATURE
1359 optval = (tp->t_flags & TF_SIGNATURE) ? 1 : 0;
1361 error = sooptcopyout(sopt, &optval, sizeof optval);
1366 optval = tp->t_flags & TF_NODELAY;
1368 error = sooptcopyout(sopt, &optval, sizeof optval);
1371 optval = tp->t_maxseg;
1373 error = sooptcopyout(sopt, &optval, sizeof optval);
1376 optval = tp->t_flags & TF_NOOPT;
1378 error = sooptcopyout(sopt, &optval, sizeof optval);
1381 optval = tp->t_flags & TF_NOPUSH;
1383 error = sooptcopyout(sopt, &optval, sizeof optval);
1386 tcp_fill_info(tp, &ti);
1388 error = sooptcopyout(sopt, &ti, sizeof ti);
1392 error = ENOPROTOOPT;
1399 #undef INP_WLOCK_RECHECK
1402 * tcp_sendspace and tcp_recvspace are the default send and receive window
1403 * sizes, respectively. These are obsolescent (this information should
1404 * be set by the route).
1406 u_long tcp_sendspace = 1024*32;
1407 SYSCTL_ULONG(_net_inet_tcp, TCPCTL_SENDSPACE, sendspace, CTLFLAG_RW,
1408 &tcp_sendspace , 0, "Maximum outgoing TCP datagram size");
1409 u_long tcp_recvspace = 1024*64;
1410 SYSCTL_ULONG(_net_inet_tcp, TCPCTL_RECVSPACE, recvspace, CTLFLAG_RW,
1411 &tcp_recvspace , 0, "Maximum incoming TCP datagram size");
1414 * Attach TCP protocol to socket, allocating
1415 * internet protocol control block, tcp control block,
1416 * bufer space, and entering LISTEN state if to accept connections.
1419 tcp_attach(struct socket *so)
1425 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
1426 error = soreserve(so, tcp_sendspace, tcp_recvspace);
1430 so->so_rcv.sb_flags |= SB_AUTOSIZE;
1431 so->so_snd.sb_flags |= SB_AUTOSIZE;
1432 INP_INFO_WLOCK(&tcbinfo);
1433 error = in_pcballoc(so, &tcbinfo);
1435 INP_INFO_WUNLOCK(&tcbinfo);
1438 inp = sotoinpcb(so);
1440 if (inp->inp_vflag & INP_IPV6PROTO) {
1441 inp->inp_vflag |= INP_IPV6;
1442 inp->in6p_hops = -1; /* use kernel default */
1446 inp->inp_vflag |= INP_IPV4;
1447 tp = tcp_newtcpcb(inp);
1451 INP_INFO_WUNLOCK(&tcbinfo);
1454 tp->t_state = TCPS_CLOSED;
1456 INP_INFO_WUNLOCK(&tcbinfo);
1461 * Initiate (or continue) disconnect.
1462 * If embryonic state, just send reset (once).
1463 * If in ``let data drain'' option and linger null, just drop.
1464 * Otherwise (hard), mark socket disconnecting and drop
1465 * current input data; switch states based on user close, and
1466 * send segment to peer (with FIN).
1469 tcp_disconnect(struct tcpcb *tp)
1471 struct inpcb *inp = tp->t_inpcb;
1472 struct socket *so = inp->inp_socket;
1474 INP_INFO_WLOCK_ASSERT(&tcbinfo);
1475 INP_WLOCK_ASSERT(inp);
1478 * Neither tcp_close() nor tcp_drop() should return NULL, as the
1479 * socket is still open.
1481 if (tp->t_state < TCPS_ESTABLISHED) {
1484 ("tcp_disconnect: tcp_close() returned NULL"));
1485 } else if ((so->so_options & SO_LINGER) && so->so_linger == 0) {
1486 tp = tcp_drop(tp, 0);
1488 ("tcp_disconnect: tcp_drop() returned NULL"));
1490 soisdisconnecting(so);
1491 sbflush(&so->so_rcv);
1493 if (!(inp->inp_flags & INP_DROPPED))
1494 tcp_output_disconnect(tp);
1499 * User issued close, and wish to trail through shutdown states:
1500 * if never received SYN, just forget it. If got a SYN from peer,
1501 * but haven't sent FIN, then go to FIN_WAIT_1 state to send peer a FIN.
1502 * If already got a FIN from peer, then almost done; go to LAST_ACK
1503 * state. In all other cases, have already sent FIN to peer (e.g.
1504 * after PRU_SHUTDOWN), and just have to play tedious game waiting
1505 * for peer to send FIN or not respond to keep-alives, etc.
1506 * We can let the user exit from the close as soon as the FIN is acked.
1509 tcp_usrclosed(struct tcpcb *tp)
1512 INP_INFO_WLOCK_ASSERT(&tcbinfo);
1513 INP_WLOCK_ASSERT(tp->t_inpcb);
1515 switch (tp->t_state) {
1517 tcp_offload_listen_close(tp);
1520 tp->t_state = TCPS_CLOSED;
1523 * tcp_close() should never return NULL here as the socket is
1527 ("tcp_usrclosed: tcp_close() returned NULL"));
1531 case TCPS_SYN_RECEIVED:
1532 tp->t_flags |= TF_NEEDFIN;
1535 case TCPS_ESTABLISHED:
1536 tp->t_state = TCPS_FIN_WAIT_1;
1539 case TCPS_CLOSE_WAIT:
1540 tp->t_state = TCPS_LAST_ACK;
1543 if (tp->t_state >= TCPS_FIN_WAIT_2) {
1544 soisdisconnected(tp->t_inpcb->inp_socket);
1545 /* Prevent the connection hanging in FIN_WAIT_2 forever. */
1546 if (tp->t_state == TCPS_FIN_WAIT_2) {
1549 timeout = (tcp_fast_finwait2_recycle) ?
1550 tcp_finwait2_timeout : tcp_maxidle;
1551 tcp_timer_activate(tp, TT_2MSL, timeout);
1558 db_print_indent(int indent)
1562 for (i = 0; i < indent; i++)
1567 db_print_tstate(int t_state)
1572 db_printf("TCPS_CLOSED");
1576 db_printf("TCPS_LISTEN");
1580 db_printf("TCPS_SYN_SENT");
1583 case TCPS_SYN_RECEIVED:
1584 db_printf("TCPS_SYN_RECEIVED");
1587 case TCPS_ESTABLISHED:
1588 db_printf("TCPS_ESTABLISHED");
1591 case TCPS_CLOSE_WAIT:
1592 db_printf("TCPS_CLOSE_WAIT");
1595 case TCPS_FIN_WAIT_1:
1596 db_printf("TCPS_FIN_WAIT_1");
1600 db_printf("TCPS_CLOSING");
1604 db_printf("TCPS_LAST_ACK");
1607 case TCPS_FIN_WAIT_2:
1608 db_printf("TCPS_FIN_WAIT_2");
1611 case TCPS_TIME_WAIT:
1612 db_printf("TCPS_TIME_WAIT");
1616 db_printf("unknown");
1622 db_print_tflags(u_int t_flags)
1627 if (t_flags & TF_ACKNOW) {
1628 db_printf("%sTF_ACKNOW", comma ? ", " : "");
1631 if (t_flags & TF_DELACK) {
1632 db_printf("%sTF_DELACK", comma ? ", " : "");
1635 if (t_flags & TF_NODELAY) {
1636 db_printf("%sTF_NODELAY", comma ? ", " : "");
1639 if (t_flags & TF_NOOPT) {
1640 db_printf("%sTF_NOOPT", comma ? ", " : "");
1643 if (t_flags & TF_SENTFIN) {
1644 db_printf("%sTF_SENTFIN", comma ? ", " : "");
1647 if (t_flags & TF_REQ_SCALE) {
1648 db_printf("%sTF_REQ_SCALE", comma ? ", " : "");
1651 if (t_flags & TF_RCVD_SCALE) {
1652 db_printf("%sTF_RECVD_SCALE", comma ? ", " : "");
1655 if (t_flags & TF_REQ_TSTMP) {
1656 db_printf("%sTF_REQ_TSTMP", comma ? ", " : "");
1659 if (t_flags & TF_RCVD_TSTMP) {
1660 db_printf("%sTF_RCVD_TSTMP", comma ? ", " : "");
1663 if (t_flags & TF_SACK_PERMIT) {
1664 db_printf("%sTF_SACK_PERMIT", comma ? ", " : "");
1667 if (t_flags & TF_NEEDSYN) {
1668 db_printf("%sTF_NEEDSYN", comma ? ", " : "");
1671 if (t_flags & TF_NEEDFIN) {
1672 db_printf("%sTF_NEEDFIN", comma ? ", " : "");
1675 if (t_flags & TF_NOPUSH) {
1676 db_printf("%sTF_NOPUSH", comma ? ", " : "");
1679 if (t_flags & TF_NOPUSH) {
1680 db_printf("%sTF_NOPUSH", comma ? ", " : "");
1683 if (t_flags & TF_MORETOCOME) {
1684 db_printf("%sTF_MORETOCOME", comma ? ", " : "");
1687 if (t_flags & TF_LQ_OVERFLOW) {
1688 db_printf("%sTF_LQ_OVERFLOW", comma ? ", " : "");
1691 if (t_flags & TF_LASTIDLE) {
1692 db_printf("%sTF_LASTIDLE", comma ? ", " : "");
1695 if (t_flags & TF_RXWIN0SENT) {
1696 db_printf("%sTF_RXWIN0SENT", comma ? ", " : "");
1699 if (t_flags & TF_FASTRECOVERY) {
1700 db_printf("%sTF_FASTRECOVERY", comma ? ", " : "");
1703 if (t_flags & TF_WASFRECOVERY) {
1704 db_printf("%sTF_WASFRECOVERY", comma ? ", " : "");
1707 if (t_flags & TF_SIGNATURE) {
1708 db_printf("%sTF_SIGNATURE", comma ? ", " : "");
1711 if (t_flags & TF_FORCEDATA) {
1712 db_printf("%sTF_FORCEDATA", comma ? ", " : "");
1715 if (t_flags & TF_TSO) {
1716 db_printf("%sTF_TSO", comma ? ", " : "");
1722 db_print_toobflags(char t_oobflags)
1727 if (t_oobflags & TCPOOB_HAVEDATA) {
1728 db_printf("%sTCPOOB_HAVEDATA", comma ? ", " : "");
1731 if (t_oobflags & TCPOOB_HADDATA) {
1732 db_printf("%sTCPOOB_HADDATA", comma ? ", " : "");
1738 db_print_tcpcb(struct tcpcb *tp, const char *name, int indent)
1741 db_print_indent(indent);
1742 db_printf("%s at %p\n", name, tp);
1746 db_print_indent(indent);
1747 db_printf("t_segq first: %p t_segqlen: %d t_dupacks: %d\n",
1748 LIST_FIRST(&tp->t_segq), tp->t_segqlen, tp->t_dupacks);
1750 db_print_indent(indent);
1751 db_printf("tt_rexmt: %p tt_persist: %p tt_keep: %p\n",
1752 &tp->t_timers->tt_rexmt, &tp->t_timers->tt_persist, &tp->t_timers->tt_keep);
1754 db_print_indent(indent);
1755 db_printf("tt_2msl: %p tt_delack: %p t_inpcb: %p\n", &tp->t_timers->tt_2msl,
1756 &tp->t_timers->tt_delack, tp->t_inpcb);
1758 db_print_indent(indent);
1759 db_printf("t_state: %d (", tp->t_state);
1760 db_print_tstate(tp->t_state);
1763 db_print_indent(indent);
1764 db_printf("t_flags: 0x%x (", tp->t_flags);
1765 db_print_tflags(tp->t_flags);
1768 db_print_indent(indent);
1769 db_printf("snd_una: 0x%08x snd_max: 0x%08x snd_nxt: x0%08x\n",
1770 tp->snd_una, tp->snd_max, tp->snd_nxt);
1772 db_print_indent(indent);
1773 db_printf("snd_up: 0x%08x snd_wl1: 0x%08x snd_wl2: 0x%08x\n",
1774 tp->snd_up, tp->snd_wl1, tp->snd_wl2);
1776 db_print_indent(indent);
1777 db_printf("iss: 0x%08x irs: 0x%08x rcv_nxt: 0x%08x\n",
1778 tp->iss, tp->irs, tp->rcv_nxt);
1780 db_print_indent(indent);
1781 db_printf("rcv_adv: 0x%08x rcv_wnd: %lu rcv_up: 0x%08x\n",
1782 tp->rcv_adv, tp->rcv_wnd, tp->rcv_up);
1784 db_print_indent(indent);
1785 db_printf("snd_wnd: %lu snd_cwnd: %lu snd_bwnd: %lu\n",
1786 tp->snd_wnd, tp->snd_cwnd, tp->snd_bwnd);
1788 db_print_indent(indent);
1789 db_printf("snd_ssthresh: %lu snd_bandwidth: %lu snd_recover: "
1790 "0x%08x\n", tp->snd_ssthresh, tp->snd_bandwidth,
1793 db_print_indent(indent);
1794 db_printf("t_maxopd: %u t_rcvtime: %lu t_startime: %lu\n",
1795 tp->t_maxopd, tp->t_rcvtime, tp->t_starttime);
1797 db_print_indent(indent);
1798 db_printf("t_rttime: %d t_rtsq: 0x%08x t_bw_rtttime: %d\n",
1799 tp->t_rtttime, tp->t_rtseq, tp->t_bw_rtttime);
1801 db_print_indent(indent);
1802 db_printf("t_bw_rtseq: 0x%08x t_rxtcur: %d t_maxseg: %u "
1803 "t_srtt: %d\n", tp->t_bw_rtseq, tp->t_rxtcur, tp->t_maxseg,
1806 db_print_indent(indent);
1807 db_printf("t_rttvar: %d t_rxtshift: %d t_rttmin: %u "
1808 "t_rttbest: %u\n", tp->t_rttvar, tp->t_rxtshift, tp->t_rttmin,
1811 db_print_indent(indent);
1812 db_printf("t_rttupdated: %lu max_sndwnd: %lu t_softerror: %d\n",
1813 tp->t_rttupdated, tp->max_sndwnd, tp->t_softerror);
1815 db_print_indent(indent);
1816 db_printf("t_oobflags: 0x%x (", tp->t_oobflags);
1817 db_print_toobflags(tp->t_oobflags);
1818 db_printf(") t_iobc: 0x%02x\n", tp->t_iobc);
1820 db_print_indent(indent);
1821 db_printf("snd_scale: %u rcv_scale: %u request_r_scale: %u\n",
1822 tp->snd_scale, tp->rcv_scale, tp->request_r_scale);
1824 db_print_indent(indent);
1825 db_printf("ts_recent: %u ts_recent_age: %lu\n",
1826 tp->ts_recent, tp->ts_recent_age);
1828 db_print_indent(indent);
1829 db_printf("ts_offset: %u last_ack_sent: 0x%08x snd_cwnd_prev: "
1830 "%lu\n", tp->ts_offset, tp->last_ack_sent, tp->snd_cwnd_prev);
1832 db_print_indent(indent);
1833 db_printf("snd_ssthresh_prev: %lu snd_recover_prev: 0x%08x "
1834 "t_badrxtwin: %lu\n", tp->snd_ssthresh_prev,
1835 tp->snd_recover_prev, tp->t_badrxtwin);
1837 db_print_indent(indent);
1838 db_printf("snd_numholes: %d snd_holes first: %p\n",
1839 tp->snd_numholes, TAILQ_FIRST(&tp->snd_holes));
1841 db_print_indent(indent);
1842 db_printf("snd_fack: 0x%08x rcv_numsacks: %d sack_newdata: "
1843 "0x%08x\n", tp->snd_fack, tp->rcv_numsacks, tp->sack_newdata);
1845 /* Skip sackblks, sackhint. */
1847 db_print_indent(indent);
1848 db_printf("t_rttlow: %d rfbuf_ts: %u rfbuf_cnt: %d\n",
1849 tp->t_rttlow, tp->rfbuf_ts, tp->rfbuf_cnt);
1852 DB_SHOW_COMMAND(tcpcb, db_show_tcpcb)
1857 db_printf("usage: show tcpcb <addr>\n");
1860 tp = (struct tcpcb *)addr;
1862 db_print_tcpcb(tp, "tcpcb", 0);