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 int isipv6 = INP_CHECK_SOCKAF(so, AF_INET6) != 0;
162 INP_INFO_WLOCK_ASSERT(&tcbinfo);
163 INP_LOCK_ASSERT(inp);
165 KASSERT(so->so_pcb == inp, ("tcp_detach: so_pcb != inp"));
166 KASSERT(inp->inp_socket == so, ("tcp_detach: inp_socket != so"));
170 if (inp->inp_vflag & INP_TIMEWAIT) {
172 * There are two cases to handle: one in which the time wait
173 * state is being discarded (INP_DROPPED), and one in which
174 * this connection will remain in timewait. In the former,
175 * it is time to discard all state (except tcptw, which has
176 * already been discarded by the timewait close code, which
177 * should be further up the call stack somewhere). In the
178 * latter case, we detach from the socket, but leave the pcb
179 * present until timewait ends.
181 * XXXRW: Would it be cleaner to free the tcptw here?
183 if (inp->inp_vflag & INP_DROPPED) {
184 KASSERT(tp == NULL, ("tcp_detach: INP_TIMEWAIT && "
185 "INP_DROPPED && tp != NULL"));
208 * If the connection is not in timewait, we consider two
209 * two conditions: one in which no further processing is
210 * necessary (dropped || embryonic), and one in which TCP is
211 * not yet done, but no longer requires the socket, so the
212 * pcb will persist for the time being.
214 * XXXRW: Does the second case still occur?
216 if (inp->inp_vflag & INP_DROPPED ||
217 tp->t_state < TCPS_SYN_SENT) {
242 * pru_detach() detaches the TCP protocol from the socket.
243 * If the protocol state is non-embryonic, then can't
244 * do this directly: have to initiate a pru_disconnect(),
245 * which may finish later; embryonic TCB's can just
249 tcp_usr_detach(struct socket *so)
254 KASSERT(inp != NULL, ("tcp_usr_detach: inp == NULL"));
255 INP_INFO_WLOCK(&tcbinfo);
257 KASSERT(inp->inp_socket != NULL,
258 ("tcp_usr_detach: inp_socket == NULL"));
260 INP_INFO_WUNLOCK(&tcbinfo);
264 * Give the socket an address.
267 tcp_usr_bind(struct socket *so, struct sockaddr *nam, struct thread *td)
271 struct tcpcb *tp = NULL;
272 struct sockaddr_in *sinp;
274 sinp = (struct sockaddr_in *)nam;
275 if (nam->sa_len != sizeof (*sinp))
278 * Must check for multicast addresses and disallow binding
281 if (sinp->sin_family == AF_INET &&
282 IN_MULTICAST(ntohl(sinp->sin_addr.s_addr)))
283 return (EAFNOSUPPORT);
286 INP_INFO_WLOCK(&tcbinfo);
288 KASSERT(inp != NULL, ("tcp_usr_bind: inp == NULL"));
290 if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) {
296 error = in_pcbbind(inp, nam, td->td_ucred);
300 INP_INFO_WUNLOCK(&tcbinfo);
307 tcp6_usr_bind(struct socket *so, struct sockaddr *nam, struct thread *td)
311 struct tcpcb *tp = NULL;
312 struct sockaddr_in6 *sin6p;
314 sin6p = (struct sockaddr_in6 *)nam;
315 if (nam->sa_len != sizeof (*sin6p))
318 * Must check for multicast addresses and disallow binding
321 if (sin6p->sin6_family == AF_INET6 &&
322 IN6_IS_ADDR_MULTICAST(&sin6p->sin6_addr))
323 return (EAFNOSUPPORT);
326 INP_INFO_WLOCK(&tcbinfo);
328 KASSERT(inp != NULL, ("tcp6_usr_bind: inp == NULL"));
330 if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) {
336 inp->inp_vflag &= ~INP_IPV4;
337 inp->inp_vflag |= INP_IPV6;
338 if ((inp->inp_flags & IN6P_IPV6_V6ONLY) == 0) {
339 if (IN6_IS_ADDR_UNSPECIFIED(&sin6p->sin6_addr))
340 inp->inp_vflag |= INP_IPV4;
341 else if (IN6_IS_ADDR_V4MAPPED(&sin6p->sin6_addr)) {
342 struct sockaddr_in sin;
344 in6_sin6_2_sin(&sin, sin6p);
345 inp->inp_vflag |= INP_IPV4;
346 inp->inp_vflag &= ~INP_IPV6;
347 error = in_pcbbind(inp, (struct sockaddr *)&sin,
352 error = in6_pcbbind(inp, nam, td->td_ucred);
356 INP_INFO_WUNLOCK(&tcbinfo);
362 * Prepare to accept connections.
365 tcp_usr_listen(struct socket *so, int backlog, struct thread *td)
369 struct tcpcb *tp = NULL;
372 INP_INFO_WLOCK(&tcbinfo);
374 KASSERT(inp != NULL, ("tcp_usr_listen: inp == NULL"));
376 if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) {
383 error = solisten_proto_check(so);
384 if (error == 0 && inp->inp_lport == 0)
385 error = in_pcbbind(inp, (struct sockaddr *)0, td->td_ucred);
387 tp->t_state = TCPS_LISTEN;
388 solisten_proto(so, backlog);
389 tcp_offload_listen_open(tp);
394 TCPDEBUG2(PRU_LISTEN);
396 INP_INFO_WUNLOCK(&tcbinfo);
402 tcp6_usr_listen(struct socket *so, int backlog, struct thread *td)
406 struct tcpcb *tp = NULL;
409 INP_INFO_WLOCK(&tcbinfo);
411 KASSERT(inp != NULL, ("tcp6_usr_listen: inp == NULL"));
413 if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) {
420 error = solisten_proto_check(so);
421 if (error == 0 && inp->inp_lport == 0) {
422 inp->inp_vflag &= ~INP_IPV4;
423 if ((inp->inp_flags & IN6P_IPV6_V6ONLY) == 0)
424 inp->inp_vflag |= INP_IPV4;
425 error = in6_pcbbind(inp, (struct sockaddr *)0, td->td_ucred);
428 tp->t_state = TCPS_LISTEN;
429 solisten_proto(so, backlog);
434 TCPDEBUG2(PRU_LISTEN);
436 INP_INFO_WUNLOCK(&tcbinfo);
442 * Initiate connection to peer.
443 * Create a template for use in transmissions on this connection.
444 * Enter SYN_SENT state, and mark socket as connecting.
445 * Start keep-alive timer, and seed output sequence space.
446 * Send initial segment on connection.
449 tcp_usr_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
453 struct tcpcb *tp = NULL;
454 struct sockaddr_in *sinp;
456 sinp = (struct sockaddr_in *)nam;
457 if (nam->sa_len != sizeof (*sinp))
460 * Must disallow TCP ``connections'' to multicast addresses.
462 if (sinp->sin_family == AF_INET
463 && IN_MULTICAST(ntohl(sinp->sin_addr.s_addr)))
464 return (EAFNOSUPPORT);
465 if (jailed(td->td_ucred))
466 prison_remote_ip(td->td_ucred, 0, &sinp->sin_addr.s_addr);
469 INP_INFO_WLOCK(&tcbinfo);
471 KASSERT(inp != NULL, ("tcp_usr_connect: inp == NULL"));
473 if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) {
479 if ((error = tcp_connect(tp, nam, td)) != 0)
481 error = tcp_output_connect(so, nam);
483 TCPDEBUG2(PRU_CONNECT);
485 INP_INFO_WUNLOCK(&tcbinfo);
491 tcp6_usr_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
495 struct tcpcb *tp = NULL;
496 struct sockaddr_in6 *sin6p;
500 sin6p = (struct sockaddr_in6 *)nam;
501 if (nam->sa_len != sizeof (*sin6p))
504 * Must disallow TCP ``connections'' to multicast addresses.
506 if (sin6p->sin6_family == AF_INET6
507 && IN6_IS_ADDR_MULTICAST(&sin6p->sin6_addr))
508 return (EAFNOSUPPORT);
510 INP_INFO_WLOCK(&tcbinfo);
512 KASSERT(inp != NULL, ("tcp6_usr_connect: inp == NULL"));
514 if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) {
520 if (IN6_IS_ADDR_V4MAPPED(&sin6p->sin6_addr)) {
521 struct sockaddr_in sin;
523 if ((inp->inp_flags & IN6P_IPV6_V6ONLY) != 0) {
528 in6_sin6_2_sin(&sin, sin6p);
529 inp->inp_vflag |= INP_IPV4;
530 inp->inp_vflag &= ~INP_IPV6;
531 if ((error = tcp_connect(tp, (struct sockaddr *)&sin, td)) != 0)
533 error = tcp_output_connect(so, nam);
536 inp->inp_vflag &= ~INP_IPV4;
537 inp->inp_vflag |= INP_IPV6;
538 inp->inp_inc.inc_isipv6 = 1;
539 if ((error = tcp6_connect(tp, nam, td)) != 0)
541 error = tcp_output_connect(so, nam);
544 TCPDEBUG2(PRU_CONNECT);
546 INP_INFO_WUNLOCK(&tcbinfo);
552 * Initiate disconnect from peer.
553 * If connection never passed embryonic stage, just drop;
554 * else if don't need to let data drain, then can just drop anyways,
555 * else have to begin TCP shutdown process: mark socket disconnecting,
556 * drain unread data, state switch to reflect user close, and
557 * send segment (e.g. FIN) to peer. Socket will be really disconnected
558 * when peer sends FIN and acks ours.
560 * SHOULD IMPLEMENT LATER PRU_CONNECT VIA REALLOC TCPCB.
563 tcp_usr_disconnect(struct socket *so)
566 struct tcpcb *tp = NULL;
570 INP_INFO_WLOCK(&tcbinfo);
572 KASSERT(inp != NULL, ("tcp_usr_disconnect: inp == NULL"));
574 if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) {
582 TCPDEBUG2(PRU_DISCONNECT);
584 INP_INFO_WUNLOCK(&tcbinfo);
589 * Accept a connection. Essentially all the work is
590 * done at higher levels; just return the address
591 * of the peer, storing through addr.
594 tcp_usr_accept(struct socket *so, struct sockaddr **nam)
597 struct inpcb *inp = NULL;
598 struct tcpcb *tp = NULL;
603 if (so->so_state & SS_ISDISCONNECTED)
604 return (ECONNABORTED);
607 KASSERT(inp != NULL, ("tcp_usr_accept: inp == NULL"));
608 INP_INFO_RLOCK(&tcbinfo);
610 if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) {
611 error = ECONNABORTED;
618 * We inline in_getpeeraddr and COMMON_END here, so that we can
619 * copy the data of interest and defer the malloc until after we
622 port = inp->inp_fport;
623 addr = inp->inp_faddr;
626 TCPDEBUG2(PRU_ACCEPT);
628 INP_INFO_RUNLOCK(&tcbinfo);
630 *nam = in_sockaddr(port, &addr);
636 tcp6_usr_accept(struct socket *so, struct sockaddr **nam)
638 struct inpcb *inp = NULL;
640 struct tcpcb *tp = NULL;
642 struct in6_addr addr6;
647 if (so->so_state & SS_ISDISCONNECTED)
648 return (ECONNABORTED);
651 KASSERT(inp != NULL, ("tcp6_usr_accept: inp == NULL"));
653 if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) {
654 error = ECONNABORTED;
661 * We inline in6_mapped_peeraddr and COMMON_END here, so that we can
662 * copy the data of interest and defer the malloc until after we
665 if (inp->inp_vflag & INP_IPV4) {
667 port = inp->inp_fport;
668 addr = inp->inp_faddr;
670 port = inp->inp_fport;
671 addr6 = inp->in6p_faddr;
675 TCPDEBUG2(PRU_ACCEPT);
679 *nam = in6_v4mapsin6_sockaddr(port, &addr);
681 *nam = in6_sockaddr(port, &addr6);
688 * Mark the connection as being incapable of further output.
691 tcp_usr_shutdown(struct socket *so)
695 struct tcpcb *tp = NULL;
698 INP_INFO_WLOCK(&tcbinfo);
700 KASSERT(inp != NULL, ("inp == NULL"));
702 if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) {
710 error = tcp_output_disconnect(tp);
713 TCPDEBUG2(PRU_SHUTDOWN);
715 INP_INFO_WUNLOCK(&tcbinfo);
721 * After a receive, possibly send window update to peer.
724 tcp_usr_rcvd(struct socket *so, int flags)
727 struct tcpcb *tp = NULL;
732 KASSERT(inp != NULL, ("tcp_usr_rcvd: inp == NULL"));
734 if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) {
749 * Do a send by putting data in output queue and updating urgent
750 * marker if URG set. Possibly send more data. Unlike the other
751 * pru_*() routines, the mbuf chains are our responsibility. We
752 * must either enqueue them or free them. The other pru_* routines
753 * generally are caller-frees.
756 tcp_usr_send(struct socket *so, int flags, struct mbuf *m,
757 struct sockaddr *nam, struct mbuf *control, struct thread *td)
761 struct tcpcb *tp = NULL;
769 * We require the pcbinfo lock in two cases:
771 * (1) An implied connect is taking place, which can result in
772 * binding IPs and ports and hence modification of the pcb hash
775 * (2) PRUS_EOF is set, resulting in explicit close on the send.
777 if ((nam != NULL) || (flags & PRUS_EOF)) {
778 INP_INFO_WLOCK(&tcbinfo);
782 KASSERT(inp != NULL, ("tcp_usr_send: inp == NULL"));
784 if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) {
793 isipv6 = nam && nam->sa_family == AF_INET6;
798 /* TCP doesn't do control messages (rights, creds, etc) */
799 if (control->m_len) {
806 m_freem(control); /* empty control, just free it */
808 if (!(flags & PRUS_OOB)) {
809 sbappendstream(&so->so_snd, m);
810 if (nam && tp->t_state < TCPS_SYN_SENT) {
812 * Do implied connect if not yet connected,
813 * initialize window to default value, and
814 * initialize maxseg/maxopd using peer's cached
817 INP_INFO_WLOCK_ASSERT(&tcbinfo);
820 error = tcp6_connect(tp, nam, td);
823 error = tcp_connect(tp, nam, td);
826 tp->snd_wnd = TTCP_CLIENT_SND_WND;
829 if (flags & PRUS_EOF) {
831 * Close the send side of the connection after
834 INP_INFO_WLOCK_ASSERT(&tcbinfo);
839 INP_INFO_WUNLOCK(&tcbinfo);
843 if (flags & PRUS_MORETOCOME)
844 tp->t_flags |= TF_MORETOCOME;
845 error = tcp_output_send(tp);
846 if (flags & PRUS_MORETOCOME)
847 tp->t_flags &= ~TF_MORETOCOME;
851 * XXXRW: PRUS_EOF not implemented with PRUS_OOB?
853 SOCKBUF_LOCK(&so->so_snd);
854 if (sbspace(&so->so_snd) < -512) {
855 SOCKBUF_UNLOCK(&so->so_snd);
861 * According to RFC961 (Assigned Protocols),
862 * the urgent pointer points to the last octet
863 * of urgent data. We continue, however,
864 * to consider it to indicate the first octet
865 * of data past the urgent section.
866 * Otherwise, snd_up should be one lower.
868 sbappendstream_locked(&so->so_snd, m);
869 SOCKBUF_UNLOCK(&so->so_snd);
870 if (nam && tp->t_state < TCPS_SYN_SENT) {
872 * Do implied connect if not yet connected,
873 * initialize window to default value, and
874 * initialize maxseg/maxopd using peer's cached
877 INP_INFO_WLOCK_ASSERT(&tcbinfo);
880 error = tcp6_connect(tp, nam, td);
883 error = tcp_connect(tp, nam, td);
886 tp->snd_wnd = TTCP_CLIENT_SND_WND;
888 INP_INFO_WUNLOCK(&tcbinfo);
891 INP_INFO_WUNLOCK(&tcbinfo);
894 tp->snd_up = tp->snd_una + so->so_snd.sb_cc;
895 tp->t_flags |= TF_FORCEDATA;
896 error = tcp_output_send(tp);
897 tp->t_flags &= ~TF_FORCEDATA;
900 TCPDEBUG2((flags & PRUS_OOB) ? PRU_SENDOOB :
901 ((flags & PRUS_EOF) ? PRU_SEND_EOF : PRU_SEND));
904 INP_INFO_WUNLOCK(&tcbinfo);
909 * Abort the TCP. Drop the connection abruptly.
912 tcp_usr_abort(struct socket *so)
915 struct tcpcb *tp = NULL;
919 KASSERT(inp != NULL, ("tcp_usr_abort: inp == NULL"));
921 INP_INFO_WLOCK(&tcbinfo);
923 KASSERT(inp->inp_socket != NULL,
924 ("tcp_usr_abort: inp_socket == NULL"));
927 * If we still have full TCP state, and we're not dropped, drop.
929 if (!(inp->inp_vflag & INP_TIMEWAIT) &&
930 !(inp->inp_vflag & INP_DROPPED)) {
933 tcp_drop(tp, ECONNABORTED);
934 TCPDEBUG2(PRU_ABORT);
936 if (!(inp->inp_vflag & INP_DROPPED)) {
938 so->so_state |= SS_PROTOREF;
940 inp->inp_vflag |= INP_SOCKREF;
943 INP_INFO_WUNLOCK(&tcbinfo);
947 * TCP socket is closed. Start friendly disconnect.
950 tcp_usr_close(struct socket *so)
953 struct tcpcb *tp = NULL;
957 KASSERT(inp != NULL, ("tcp_usr_close: inp == NULL"));
959 INP_INFO_WLOCK(&tcbinfo);
961 KASSERT(inp->inp_socket != NULL,
962 ("tcp_usr_close: inp_socket == NULL"));
965 * If we still have full TCP state, and we're not dropped, initiate
968 if (!(inp->inp_vflag & INP_TIMEWAIT) &&
969 !(inp->inp_vflag & INP_DROPPED)) {
973 TCPDEBUG2(PRU_CLOSE);
975 if (!(inp->inp_vflag & INP_DROPPED)) {
977 so->so_state |= SS_PROTOREF;
979 inp->inp_vflag |= INP_SOCKREF;
982 INP_INFO_WUNLOCK(&tcbinfo);
986 * Receive out-of-band data.
989 tcp_usr_rcvoob(struct socket *so, struct mbuf *m, int flags)
993 struct tcpcb *tp = NULL;
997 KASSERT(inp != NULL, ("tcp_usr_rcvoob: inp == NULL"));
999 if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) {
1003 tp = intotcpcb(inp);
1005 if ((so->so_oobmark == 0 &&
1006 (so->so_rcv.sb_state & SBS_RCVATMARK) == 0) ||
1007 so->so_options & SO_OOBINLINE ||
1008 tp->t_oobflags & TCPOOB_HADDATA) {
1012 if ((tp->t_oobflags & TCPOOB_HAVEDATA) == 0) {
1013 error = EWOULDBLOCK;
1017 *mtod(m, caddr_t) = tp->t_iobc;
1018 if ((flags & MSG_PEEK) == 0)
1019 tp->t_oobflags ^= (TCPOOB_HAVEDATA | TCPOOB_HADDATA);
1022 TCPDEBUG2(PRU_RCVOOB);
1027 struct pr_usrreqs tcp_usrreqs = {
1028 .pru_abort = tcp_usr_abort,
1029 .pru_accept = tcp_usr_accept,
1030 .pru_attach = tcp_usr_attach,
1031 .pru_bind = tcp_usr_bind,
1032 .pru_connect = tcp_usr_connect,
1033 .pru_control = in_control,
1034 .pru_detach = tcp_usr_detach,
1035 .pru_disconnect = tcp_usr_disconnect,
1036 .pru_listen = tcp_usr_listen,
1037 .pru_peeraddr = in_getpeeraddr,
1038 .pru_rcvd = tcp_usr_rcvd,
1039 .pru_rcvoob = tcp_usr_rcvoob,
1040 .pru_send = tcp_usr_send,
1041 .pru_shutdown = tcp_usr_shutdown,
1042 .pru_sockaddr = in_getsockaddr,
1043 .pru_sosetlabel = in_pcbsosetlabel,
1044 .pru_close = tcp_usr_close,
1048 struct pr_usrreqs tcp6_usrreqs = {
1049 .pru_abort = tcp_usr_abort,
1050 .pru_accept = tcp6_usr_accept,
1051 .pru_attach = tcp_usr_attach,
1052 .pru_bind = tcp6_usr_bind,
1053 .pru_connect = tcp6_usr_connect,
1054 .pru_control = in6_control,
1055 .pru_detach = tcp_usr_detach,
1056 .pru_disconnect = tcp_usr_disconnect,
1057 .pru_listen = tcp6_usr_listen,
1058 .pru_peeraddr = in6_mapped_peeraddr,
1059 .pru_rcvd = tcp_usr_rcvd,
1060 .pru_rcvoob = tcp_usr_rcvoob,
1061 .pru_send = tcp_usr_send,
1062 .pru_shutdown = tcp_usr_shutdown,
1063 .pru_sockaddr = in6_mapped_sockaddr,
1064 .pru_sosetlabel = in_pcbsosetlabel,
1065 .pru_close = tcp_usr_close,
1070 * Common subroutine to open a TCP connection to remote host specified
1071 * by struct sockaddr_in in mbuf *nam. Call in_pcbbind to assign a local
1072 * port number if needed. Call in_pcbconnect_setup to do the routing and
1073 * to choose a local host address (interface). If there is an existing
1074 * incarnation of the same connection in TIME-WAIT state and if the remote
1075 * host was sending CC options and if the connection duration was < MSL, then
1076 * truncate the previous TIME-WAIT state and proceed.
1077 * Initialize connection parameters and enter SYN-SENT state.
1080 tcp_connect(struct tcpcb *tp, struct sockaddr *nam, struct thread *td)
1082 struct inpcb *inp = tp->t_inpcb, *oinp;
1083 struct socket *so = inp->inp_socket;
1084 struct in_addr laddr;
1088 INP_INFO_WLOCK_ASSERT(&tcbinfo);
1089 INP_LOCK_ASSERT(inp);
1091 if (inp->inp_lport == 0) {
1092 error = in_pcbbind(inp, (struct sockaddr *)0, td->td_ucred);
1098 * Cannot simply call in_pcbconnect, because there might be an
1099 * earlier incarnation of this same connection still in
1100 * TIME_WAIT state, creating an ADDRINUSE error.
1102 laddr = inp->inp_laddr;
1103 lport = inp->inp_lport;
1104 error = in_pcbconnect_setup(inp, nam, &laddr.s_addr, &lport,
1105 &inp->inp_faddr.s_addr, &inp->inp_fport, &oinp, td->td_ucred);
1106 if (error && oinp == NULL)
1110 inp->inp_laddr = laddr;
1114 * Compute window scaling to request:
1115 * Scale to fit into sweet spot. See tcp_syncache.c.
1116 * XXX: This should move to tcp_output().
1118 while (tp->request_r_scale < TCP_MAX_WINSHIFT &&
1119 (TCP_MAXWIN << tp->request_r_scale) < sb_max)
1120 tp->request_r_scale++;
1123 tcpstat.tcps_connattempt++;
1124 tp->t_state = TCPS_SYN_SENT;
1125 tcp_timer_activate(tp, TT_KEEP, tcp_keepinit);
1126 tp->iss = tcp_new_isn(tp);
1127 tp->t_bw_rtseq = tp->iss;
1128 tcp_sendseqinit(tp);
1135 tcp6_connect(struct tcpcb *tp, struct sockaddr *nam, struct thread *td)
1137 struct inpcb *inp = tp->t_inpcb, *oinp;
1138 struct socket *so = inp->inp_socket;
1139 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)nam;
1140 struct in6_addr *addr6;
1143 INP_INFO_WLOCK_ASSERT(&tcbinfo);
1144 INP_LOCK_ASSERT(inp);
1146 if (inp->inp_lport == 0) {
1147 error = in6_pcbbind(inp, (struct sockaddr *)0, td->td_ucred);
1153 * Cannot simply call in_pcbconnect, because there might be an
1154 * earlier incarnation of this same connection still in
1155 * TIME_WAIT state, creating an ADDRINUSE error.
1156 * in6_pcbladdr() also handles scope zone IDs.
1158 error = in6_pcbladdr(inp, nam, &addr6);
1161 oinp = in6_pcblookup_hash(inp->inp_pcbinfo,
1162 &sin6->sin6_addr, sin6->sin6_port,
1163 IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_laddr)
1166 inp->inp_lport, 0, NULL);
1169 if (IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_laddr))
1170 inp->in6p_laddr = *addr6;
1171 inp->in6p_faddr = sin6->sin6_addr;
1172 inp->inp_fport = sin6->sin6_port;
1173 /* update flowinfo - draft-itojun-ipv6-flowlabel-api-00 */
1174 inp->in6p_flowinfo &= ~IPV6_FLOWLABEL_MASK;
1175 if (inp->in6p_flags & IN6P_AUTOFLOWLABEL)
1176 inp->in6p_flowinfo |=
1177 (htonl(ip6_randomflowlabel()) & IPV6_FLOWLABEL_MASK);
1180 /* Compute window scaling to request. */
1181 while (tp->request_r_scale < TCP_MAX_WINSHIFT &&
1182 (TCP_MAXWIN << tp->request_r_scale) < so->so_rcv.sb_hiwat)
1183 tp->request_r_scale++;
1186 tcpstat.tcps_connattempt++;
1187 tp->t_state = TCPS_SYN_SENT;
1188 tcp_timer_activate(tp, TT_KEEP, tcp_keepinit);
1189 tp->iss = tcp_new_isn(tp);
1190 tp->t_bw_rtseq = tp->iss;
1191 tcp_sendseqinit(tp);
1198 * Export TCP internal state information via a struct tcp_info, based on the
1199 * Linux 2.6 API. Not ABI compatible as our constants are mapped differently
1200 * (TCP state machine, etc). We export all information using FreeBSD-native
1201 * constants -- for example, the numeric values for tcpi_state will differ
1205 tcp_fill_info(struct tcpcb *tp, struct tcp_info *ti)
1208 INP_LOCK_ASSERT(tp->t_inpcb);
1209 bzero(ti, sizeof(*ti));
1211 ti->tcpi_state = tp->t_state;
1212 if ((tp->t_flags & TF_REQ_TSTMP) && (tp->t_flags & TF_RCVD_TSTMP))
1213 ti->tcpi_options |= TCPI_OPT_TIMESTAMPS;
1214 if (tp->t_flags & TF_SACK_PERMIT)
1215 ti->tcpi_options |= TCPI_OPT_SACK;
1216 if ((tp->t_flags & TF_REQ_SCALE) && (tp->t_flags & TF_RCVD_SCALE)) {
1217 ti->tcpi_options |= TCPI_OPT_WSCALE;
1218 ti->tcpi_snd_wscale = tp->snd_scale;
1219 ti->tcpi_rcv_wscale = tp->rcv_scale;
1222 ti->tcpi_rtt = ((u_int64_t)tp->t_srtt * tick) >> TCP_RTT_SHIFT;
1223 ti->tcpi_rttvar = ((u_int64_t)tp->t_rttvar * tick) >> TCP_RTTVAR_SHIFT;
1225 ti->tcpi_snd_ssthresh = tp->snd_ssthresh;
1226 ti->tcpi_snd_cwnd = tp->snd_cwnd;
1229 * FreeBSD-specific extension fields for tcp_info.
1231 ti->tcpi_rcv_space = tp->rcv_wnd;
1232 ti->tcpi_snd_wnd = tp->snd_wnd;
1233 ti->tcpi_snd_bwnd = tp->snd_bwnd;
1237 * tcp_ctloutput() must drop the inpcb lock before performing copyin on
1238 * socket option arguments. When it re-acquires the lock after the copy, it
1239 * has to revalidate that the connection is still valid for the socket
1242 #define INP_LOCK_RECHECK(inp) do { \
1244 if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) { \
1246 return (ECONNRESET); \
1248 tp = intotcpcb(inp); \
1252 tcp_ctloutput(struct socket *so, struct sockopt *sopt)
1254 int error, opt, optval;
1260 inp = sotoinpcb(so);
1261 KASSERT(inp != NULL, ("tcp_ctloutput: inp == NULL"));
1263 if (sopt->sopt_level != IPPROTO_TCP) {
1265 if (INP_CHECK_SOCKAF(so, AF_INET6)) {
1267 error = ip6_ctloutput(so, sopt);
1271 error = ip_ctloutput(so, sopt);
1277 if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) {
1279 return (ECONNRESET);
1282 switch (sopt->sopt_dir) {
1284 switch (sopt->sopt_name) {
1285 #ifdef TCP_SIGNATURE
1288 error = sooptcopyin(sopt, &optval, sizeof optval,
1293 INP_LOCK_RECHECK(inp);
1295 tp->t_flags |= TF_SIGNATURE;
1297 tp->t_flags &= ~TF_SIGNATURE;
1300 #endif /* TCP_SIGNATURE */
1304 error = sooptcopyin(sopt, &optval, sizeof optval,
1309 INP_LOCK_RECHECK(inp);
1310 switch (sopt->sopt_name) {
1318 opt = 0; /* dead code to fool gcc */
1325 tp->t_flags &= ~opt;
1331 error = sooptcopyin(sopt, &optval, sizeof optval,
1336 INP_LOCK_RECHECK(inp);
1338 tp->t_flags |= TF_NOPUSH;
1340 tp->t_flags &= ~TF_NOPUSH;
1341 error = tcp_output(tp);
1348 error = sooptcopyin(sopt, &optval, sizeof optval,
1353 INP_LOCK_RECHECK(inp);
1354 if (optval > 0 && optval <= tp->t_maxseg &&
1355 optval + 40 >= tcp_minmss)
1356 tp->t_maxseg = optval;
1369 error = ENOPROTOOPT;
1375 tp = intotcpcb(inp);
1376 switch (sopt->sopt_name) {
1377 #ifdef TCP_SIGNATURE
1379 optval = (tp->t_flags & TF_SIGNATURE) ? 1 : 0;
1381 error = sooptcopyout(sopt, &optval, sizeof optval);
1386 optval = tp->t_flags & TF_NODELAY;
1388 error = sooptcopyout(sopt, &optval, sizeof optval);
1391 optval = tp->t_maxseg;
1393 error = sooptcopyout(sopt, &optval, sizeof optval);
1396 optval = tp->t_flags & TF_NOOPT;
1398 error = sooptcopyout(sopt, &optval, sizeof optval);
1401 optval = tp->t_flags & TF_NOPUSH;
1403 error = sooptcopyout(sopt, &optval, sizeof optval);
1406 tcp_fill_info(tp, &ti);
1408 error = sooptcopyout(sopt, &ti, sizeof ti);
1412 error = ENOPROTOOPT;
1419 #undef INP_LOCK_RECHECK
1422 * tcp_sendspace and tcp_recvspace are the default send and receive window
1423 * sizes, respectively. These are obsolescent (this information should
1424 * be set by the route).
1426 u_long tcp_sendspace = 1024*32;
1427 SYSCTL_ULONG(_net_inet_tcp, TCPCTL_SENDSPACE, sendspace, CTLFLAG_RW,
1428 &tcp_sendspace , 0, "Maximum outgoing TCP datagram size");
1429 u_long tcp_recvspace = 1024*64;
1430 SYSCTL_ULONG(_net_inet_tcp, TCPCTL_RECVSPACE, recvspace, CTLFLAG_RW,
1431 &tcp_recvspace , 0, "Maximum incoming TCP datagram size");
1434 * Attach TCP protocol to socket, allocating
1435 * internet protocol control block, tcp control block,
1436 * bufer space, and entering LISTEN state if to accept connections.
1439 tcp_attach(struct socket *so)
1445 int isipv6 = INP_CHECK_SOCKAF(so, AF_INET6) != 0;
1448 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
1449 error = soreserve(so, tcp_sendspace, tcp_recvspace);
1453 so->so_rcv.sb_flags |= SB_AUTOSIZE;
1454 so->so_snd.sb_flags |= SB_AUTOSIZE;
1455 INP_INFO_WLOCK(&tcbinfo);
1456 error = in_pcballoc(so, &tcbinfo);
1458 INP_INFO_WUNLOCK(&tcbinfo);
1461 inp = sotoinpcb(so);
1464 inp->inp_vflag |= INP_IPV6;
1465 inp->in6p_hops = -1; /* use kernel default */
1469 inp->inp_vflag |= INP_IPV4;
1470 tp = tcp_newtcpcb(inp);
1483 INP_INFO_WUNLOCK(&tcbinfo);
1486 tp->t_state = TCPS_CLOSED;
1488 INP_INFO_WUNLOCK(&tcbinfo);
1493 * Initiate (or continue) disconnect.
1494 * If embryonic state, just send reset (once).
1495 * If in ``let data drain'' option and linger null, just drop.
1496 * Otherwise (hard), mark socket disconnecting and drop
1497 * current input data; switch states based on user close, and
1498 * send segment to peer (with FIN).
1501 tcp_disconnect(struct tcpcb *tp)
1503 struct inpcb *inp = tp->t_inpcb;
1504 struct socket *so = inp->inp_socket;
1506 INP_INFO_WLOCK_ASSERT(&tcbinfo);
1507 INP_LOCK_ASSERT(inp);
1510 * Neither tcp_close() nor tcp_drop() should return NULL, as the
1511 * socket is still open.
1513 if (tp->t_state < TCPS_ESTABLISHED) {
1516 ("tcp_disconnect: tcp_close() returned NULL"));
1517 } else if ((so->so_options & SO_LINGER) && so->so_linger == 0) {
1518 tp = tcp_drop(tp, 0);
1520 ("tcp_disconnect: tcp_drop() returned NULL"));
1522 soisdisconnecting(so);
1523 sbflush(&so->so_rcv);
1525 if (!(inp->inp_vflag & INP_DROPPED))
1526 tcp_output_disconnect(tp);
1531 * User issued close, and wish to trail through shutdown states:
1532 * if never received SYN, just forget it. If got a SYN from peer,
1533 * but haven't sent FIN, then go to FIN_WAIT_1 state to send peer a FIN.
1534 * If already got a FIN from peer, then almost done; go to LAST_ACK
1535 * state. In all other cases, have already sent FIN to peer (e.g.
1536 * after PRU_SHUTDOWN), and just have to play tedious game waiting
1537 * for peer to send FIN or not respond to keep-alives, etc.
1538 * We can let the user exit from the close as soon as the FIN is acked.
1541 tcp_usrclosed(struct tcpcb *tp)
1544 INP_INFO_WLOCK_ASSERT(&tcbinfo);
1545 INP_LOCK_ASSERT(tp->t_inpcb);
1547 switch (tp->t_state) {
1549 tcp_offload_listen_close(tp);
1552 tp->t_state = TCPS_CLOSED;
1555 * tcp_close() should never return NULL here as the socket is
1559 ("tcp_usrclosed: tcp_close() returned NULL"));
1563 case TCPS_SYN_RECEIVED:
1564 tp->t_flags |= TF_NEEDFIN;
1567 case TCPS_ESTABLISHED:
1568 tp->t_state = TCPS_FIN_WAIT_1;
1571 case TCPS_CLOSE_WAIT:
1572 tp->t_state = TCPS_LAST_ACK;
1575 if (tp->t_state >= TCPS_FIN_WAIT_2) {
1576 soisdisconnected(tp->t_inpcb->inp_socket);
1577 /* Prevent the connection hanging in FIN_WAIT_2 forever. */
1578 if (tp->t_state == TCPS_FIN_WAIT_2) {
1581 timeout = (tcp_fast_finwait2_recycle) ?
1582 tcp_finwait2_timeout : tcp_maxidle;
1583 tcp_timer_activate(tp, TT_2MSL, timeout);
1590 db_print_indent(int indent)
1594 for (i = 0; i < indent; i++)
1599 db_print_tstate(int t_state)
1604 db_printf("TCPS_CLOSED");
1608 db_printf("TCPS_LISTEN");
1612 db_printf("TCPS_SYN_SENT");
1615 case TCPS_SYN_RECEIVED:
1616 db_printf("TCPS_SYN_RECEIVED");
1619 case TCPS_ESTABLISHED:
1620 db_printf("TCPS_ESTABLISHED");
1623 case TCPS_CLOSE_WAIT:
1624 db_printf("TCPS_CLOSE_WAIT");
1627 case TCPS_FIN_WAIT_1:
1628 db_printf("TCPS_FIN_WAIT_1");
1632 db_printf("TCPS_CLOSING");
1636 db_printf("TCPS_LAST_ACK");
1639 case TCPS_FIN_WAIT_2:
1640 db_printf("TCPS_FIN_WAIT_2");
1643 case TCPS_TIME_WAIT:
1644 db_printf("TCPS_TIME_WAIT");
1648 db_printf("unknown");
1654 db_print_tflags(u_int t_flags)
1659 if (t_flags & TF_ACKNOW) {
1660 db_printf("%sTF_ACKNOW", comma ? ", " : "");
1663 if (t_flags & TF_DELACK) {
1664 db_printf("%sTF_DELACK", comma ? ", " : "");
1667 if (t_flags & TF_NODELAY) {
1668 db_printf("%sTF_NODELAY", comma ? ", " : "");
1671 if (t_flags & TF_NOOPT) {
1672 db_printf("%sTF_NOOPT", comma ? ", " : "");
1675 if (t_flags & TF_SENTFIN) {
1676 db_printf("%sTF_SENTFIN", comma ? ", " : "");
1679 if (t_flags & TF_REQ_SCALE) {
1680 db_printf("%sTF_REQ_SCALE", comma ? ", " : "");
1683 if (t_flags & TF_RCVD_SCALE) {
1684 db_printf("%sTF_RECVD_SCALE", comma ? ", " : "");
1687 if (t_flags & TF_REQ_TSTMP) {
1688 db_printf("%sTF_REQ_TSTMP", comma ? ", " : "");
1691 if (t_flags & TF_RCVD_TSTMP) {
1692 db_printf("%sTF_RCVD_TSTMP", comma ? ", " : "");
1695 if (t_flags & TF_SACK_PERMIT) {
1696 db_printf("%sTF_SACK_PERMIT", comma ? ", " : "");
1699 if (t_flags & TF_NEEDSYN) {
1700 db_printf("%sTF_NEEDSYN", comma ? ", " : "");
1703 if (t_flags & TF_NEEDFIN) {
1704 db_printf("%sTF_NEEDFIN", comma ? ", " : "");
1707 if (t_flags & TF_NOPUSH) {
1708 db_printf("%sTF_NOPUSH", comma ? ", " : "");
1711 if (t_flags & TF_NOPUSH) {
1712 db_printf("%sTF_NOPUSH", comma ? ", " : "");
1715 if (t_flags & TF_MORETOCOME) {
1716 db_printf("%sTF_MORETOCOME", comma ? ", " : "");
1719 if (t_flags & TF_LQ_OVERFLOW) {
1720 db_printf("%sTF_LQ_OVERFLOW", comma ? ", " : "");
1723 if (t_flags & TF_LASTIDLE) {
1724 db_printf("%sTF_LASTIDLE", comma ? ", " : "");
1727 if (t_flags & TF_RXWIN0SENT) {
1728 db_printf("%sTF_RXWIN0SENT", comma ? ", " : "");
1731 if (t_flags & TF_FASTRECOVERY) {
1732 db_printf("%sTF_FASTRECOVERY", comma ? ", " : "");
1735 if (t_flags & TF_WASFRECOVERY) {
1736 db_printf("%sTF_WASFRECOVERY", comma ? ", " : "");
1739 if (t_flags & TF_SIGNATURE) {
1740 db_printf("%sTF_SIGNATURE", comma ? ", " : "");
1743 if (t_flags & TF_FORCEDATA) {
1744 db_printf("%sTF_FORCEDATA", comma ? ", " : "");
1747 if (t_flags & TF_TSO) {
1748 db_printf("%sTF_TSO", comma ? ", " : "");
1754 db_print_toobflags(char t_oobflags)
1759 if (t_oobflags & TCPOOB_HAVEDATA) {
1760 db_printf("%sTCPOOB_HAVEDATA", comma ? ", " : "");
1763 if (t_oobflags & TCPOOB_HADDATA) {
1764 db_printf("%sTCPOOB_HADDATA", comma ? ", " : "");
1770 db_print_tcpcb(struct tcpcb *tp, const char *name, int indent)
1773 db_print_indent(indent);
1774 db_printf("%s at %p\n", name, tp);
1778 db_print_indent(indent);
1779 db_printf("t_segq first: %p t_segqlen: %d t_dupacks: %d\n",
1780 LIST_FIRST(&tp->t_segq), tp->t_segqlen, tp->t_dupacks);
1782 db_print_indent(indent);
1783 db_printf("tt_rexmt: %p tt_persist: %p tt_keep: %p\n",
1784 &tp->t_timers->tt_rexmt, &tp->t_timers->tt_persist, &tp->t_timers->tt_keep);
1786 db_print_indent(indent);
1787 db_printf("tt_2msl: %p tt_delack: %p t_inpcb: %p\n", &tp->t_timers->tt_2msl,
1788 &tp->t_timers->tt_delack, tp->t_inpcb);
1790 db_print_indent(indent);
1791 db_printf("t_state: %d (", tp->t_state);
1792 db_print_tstate(tp->t_state);
1795 db_print_indent(indent);
1796 db_printf("t_flags: 0x%x (", tp->t_flags);
1797 db_print_tflags(tp->t_flags);
1800 db_print_indent(indent);
1801 db_printf("snd_una: 0x%08x snd_max: 0x%08x snd_nxt: x0%08x\n",
1802 tp->snd_una, tp->snd_max, tp->snd_nxt);
1804 db_print_indent(indent);
1805 db_printf("snd_up: 0x%08x snd_wl1: 0x%08x snd_wl2: 0x%08x\n",
1806 tp->snd_up, tp->snd_wl1, tp->snd_wl2);
1808 db_print_indent(indent);
1809 db_printf("iss: 0x%08x irs: 0x%08x rcv_nxt: 0x%08x\n",
1810 tp->iss, tp->irs, tp->rcv_nxt);
1812 db_print_indent(indent);
1813 db_printf("rcv_adv: 0x%08x rcv_wnd: %lu rcv_up: 0x%08x\n",
1814 tp->rcv_adv, tp->rcv_wnd, tp->rcv_up);
1816 db_print_indent(indent);
1817 db_printf("snd_wnd: %lu snd_cwnd: %lu snd_bwnd: %lu\n",
1818 tp->snd_wnd, tp->snd_cwnd, tp->snd_bwnd);
1820 db_print_indent(indent);
1821 db_printf("snd_ssthresh: %lu snd_bandwidth: %lu snd_recover: "
1822 "0x%08x\n", tp->snd_ssthresh, tp->snd_bandwidth,
1825 db_print_indent(indent);
1826 db_printf("t_maxopd: %u t_rcvtime: %lu t_startime: %lu\n",
1827 tp->t_maxopd, tp->t_rcvtime, tp->t_starttime);
1829 db_print_indent(indent);
1830 db_printf("t_rttime: %d t_rtsq: 0x%08x t_bw_rtttime: %d\n",
1831 tp->t_rtttime, tp->t_rtseq, tp->t_bw_rtttime);
1833 db_print_indent(indent);
1834 db_printf("t_bw_rtseq: 0x%08x t_rxtcur: %d t_maxseg: %u "
1835 "t_srtt: %d\n", tp->t_bw_rtseq, tp->t_rxtcur, tp->t_maxseg,
1838 db_print_indent(indent);
1839 db_printf("t_rttvar: %d t_rxtshift: %d t_rttmin: %u "
1840 "t_rttbest: %u\n", tp->t_rttvar, tp->t_rxtshift, tp->t_rttmin,
1843 db_print_indent(indent);
1844 db_printf("t_rttupdated: %lu max_sndwnd: %lu t_softerror: %d\n",
1845 tp->t_rttupdated, tp->max_sndwnd, tp->t_softerror);
1847 db_print_indent(indent);
1848 db_printf("t_oobflags: 0x%x (", tp->t_oobflags);
1849 db_print_toobflags(tp->t_oobflags);
1850 db_printf(") t_iobc: 0x%02x\n", tp->t_iobc);
1852 db_print_indent(indent);
1853 db_printf("snd_scale: %u rcv_scale: %u request_r_scale: %u\n",
1854 tp->snd_scale, tp->rcv_scale, tp->request_r_scale);
1856 db_print_indent(indent);
1857 db_printf("ts_recent: %u ts_recent_age: %lu\n",
1858 tp->ts_recent, tp->ts_recent_age);
1860 db_print_indent(indent);
1861 db_printf("ts_offset: %u last_ack_sent: 0x%08x snd_cwnd_prev: "
1862 "%lu\n", tp->ts_offset, tp->last_ack_sent, tp->snd_cwnd_prev);
1864 db_print_indent(indent);
1865 db_printf("snd_ssthresh_prev: %lu snd_recover_prev: 0x%08x "
1866 "t_badrxtwin: %lu\n", tp->snd_ssthresh_prev,
1867 tp->snd_recover_prev, tp->t_badrxtwin);
1869 db_print_indent(indent);
1870 db_printf("snd_numholes: %d snd_holes first: %p\n",
1871 tp->snd_numholes, TAILQ_FIRST(&tp->snd_holes));
1873 db_print_indent(indent);
1874 db_printf("snd_fack: 0x%08x rcv_numsacks: %d sack_newdata: "
1875 "0x%08x\n", tp->snd_fack, tp->rcv_numsacks, tp->sack_newdata);
1877 /* Skip sackblks, sackhint. */
1879 db_print_indent(indent);
1880 db_printf("t_rttlow: %d rfbuf_ts: %u rfbuf_cnt: %d\n",
1881 tp->t_rttlow, tp->rfbuf_ts, tp->rfbuf_cnt);
1884 DB_SHOW_COMMAND(tcpcb, db_show_tcpcb)
1889 db_printf("usage: show tcpcb <addr>\n");
1892 tp = (struct tcpcb *)addr;
1894 db_print_tcpcb(tp, "tcpcb", 0);