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>
90 * TCP protocol interface to socket abstraction.
92 static int tcp_attach(struct socket *);
93 static int tcp_connect(struct tcpcb *, struct sockaddr *,
96 static int tcp6_connect(struct tcpcb *, struct sockaddr *,
99 static void tcp_disconnect(struct tcpcb *);
100 static void tcp_usrclosed(struct tcpcb *);
101 static void tcp_fill_info(struct tcpcb *, struct tcp_info *);
104 #define TCPDEBUG0 int ostate = 0
105 #define TCPDEBUG1() ostate = tp ? tp->t_state : 0
106 #define TCPDEBUG2(req) if (tp && (so->so_options & SO_DEBUG)) \
107 tcp_trace(TA_USER, ostate, tp, 0, 0, req)
111 #define TCPDEBUG2(req)
115 * TCP attaches to socket via pru_attach(), reserving space,
116 * and an internet control block.
119 tcp_usr_attach(struct socket *so, int proto, struct thread *td)
122 struct tcpcb *tp = NULL;
127 KASSERT(inp == NULL, ("tcp_usr_attach: inp != NULL"));
130 error = tcp_attach(so);
134 if ((so->so_options & SO_LINGER) && so->so_linger == 0)
135 so->so_linger = TCP_LINGERTIME;
140 TCPDEBUG2(PRU_ATTACH);
145 * tcp_detach is called when the socket layer loses its final reference
146 * to the socket, be it a file descriptor reference, a reference from TCP,
147 * etc. At this point, there is only one case in which we will keep around
148 * inpcb state: time wait.
150 * This function can probably be re-absorbed back into tcp_usr_detach() now
151 * that there is a single detach path.
154 tcp_detach(struct socket *so, struct inpcb *inp)
158 int isipv6 = INP_CHECK_SOCKAF(so, AF_INET6) != 0;
161 INP_INFO_WLOCK_ASSERT(&tcbinfo);
162 INP_LOCK_ASSERT(inp);
164 KASSERT(so->so_pcb == inp, ("tcp_detach: so_pcb != inp"));
165 KASSERT(inp->inp_socket == so, ("tcp_detach: inp_socket != so"));
169 if (inp->inp_vflag & INP_TIMEWAIT) {
171 * There are two cases to handle: one in which the time wait
172 * state is being discarded (INP_DROPPED), and one in which
173 * this connection will remain in timewait. In the former,
174 * it is time to discard all state (except tcptw, which has
175 * already been discarded by the timewait close code, which
176 * should be further up the call stack somewhere). In the
177 * latter case, we detach from the socket, but leave the pcb
178 * present until timewait ends.
180 * XXXRW: Would it be cleaner to free the tcptw here?
182 if (inp->inp_vflag & INP_DROPPED) {
183 KASSERT(tp == NULL, ("tcp_detach: INP_TIMEWAIT && "
184 "INP_DROPPED && tp != NULL"));
207 * If the connection is not in timewait, we consider two
208 * two conditions: one in which no further processing is
209 * necessary (dropped || embryonic), and one in which TCP is
210 * not yet done, but no longer requires the socket, so the
211 * pcb will persist for the time being.
213 * XXXRW: Does the second case still occur?
215 if (inp->inp_vflag & INP_DROPPED ||
216 tp->t_state < TCPS_SYN_SENT) {
241 * pru_detach() detaches the TCP protocol from the socket.
242 * If the protocol state is non-embryonic, then can't
243 * do this directly: have to initiate a pru_disconnect(),
244 * which may finish later; embryonic TCB's can just
248 tcp_usr_detach(struct socket *so)
253 KASSERT(inp != NULL, ("tcp_usr_detach: inp == NULL"));
254 INP_INFO_WLOCK(&tcbinfo);
256 KASSERT(inp->inp_socket != NULL,
257 ("tcp_usr_detach: inp_socket == NULL"));
259 INP_INFO_WUNLOCK(&tcbinfo);
263 * Give the socket an address.
266 tcp_usr_bind(struct socket *so, struct sockaddr *nam, struct thread *td)
270 struct tcpcb *tp = NULL;
271 struct sockaddr_in *sinp;
273 sinp = (struct sockaddr_in *)nam;
274 if (nam->sa_len != sizeof (*sinp))
277 * Must check for multicast addresses and disallow binding
280 if (sinp->sin_family == AF_INET &&
281 IN_MULTICAST(ntohl(sinp->sin_addr.s_addr)))
282 return (EAFNOSUPPORT);
285 INP_INFO_WLOCK(&tcbinfo);
287 KASSERT(inp != NULL, ("tcp_usr_bind: inp == NULL"));
289 if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) {
295 error = in_pcbbind(inp, nam, td->td_ucred);
299 INP_INFO_WUNLOCK(&tcbinfo);
306 tcp6_usr_bind(struct socket *so, struct sockaddr *nam, struct thread *td)
310 struct tcpcb *tp = NULL;
311 struct sockaddr_in6 *sin6p;
313 sin6p = (struct sockaddr_in6 *)nam;
314 if (nam->sa_len != sizeof (*sin6p))
317 * Must check for multicast addresses and disallow binding
320 if (sin6p->sin6_family == AF_INET6 &&
321 IN6_IS_ADDR_MULTICAST(&sin6p->sin6_addr))
322 return (EAFNOSUPPORT);
325 INP_INFO_WLOCK(&tcbinfo);
327 KASSERT(inp != NULL, ("tcp6_usr_bind: inp == NULL"));
329 if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) {
335 inp->inp_vflag &= ~INP_IPV4;
336 inp->inp_vflag |= INP_IPV6;
337 if ((inp->inp_flags & IN6P_IPV6_V6ONLY) == 0) {
338 if (IN6_IS_ADDR_UNSPECIFIED(&sin6p->sin6_addr))
339 inp->inp_vflag |= INP_IPV4;
340 else if (IN6_IS_ADDR_V4MAPPED(&sin6p->sin6_addr)) {
341 struct sockaddr_in sin;
343 in6_sin6_2_sin(&sin, sin6p);
344 inp->inp_vflag |= INP_IPV4;
345 inp->inp_vflag &= ~INP_IPV6;
346 error = in_pcbbind(inp, (struct sockaddr *)&sin,
351 error = in6_pcbbind(inp, nam, td->td_ucred);
355 INP_INFO_WUNLOCK(&tcbinfo);
361 * Prepare to accept connections.
364 tcp_usr_listen(struct socket *so, int backlog, struct thread *td)
368 struct tcpcb *tp = NULL;
371 INP_INFO_WLOCK(&tcbinfo);
373 KASSERT(inp != NULL, ("tcp_usr_listen: inp == NULL"));
375 if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) {
382 error = solisten_proto_check(so);
383 if (error == 0 && inp->inp_lport == 0)
384 error = in_pcbbind(inp, (struct sockaddr *)0, td->td_ucred);
386 tp->t_state = TCPS_LISTEN;
387 solisten_proto(so, backlog);
392 TCPDEBUG2(PRU_LISTEN);
394 INP_INFO_WUNLOCK(&tcbinfo);
400 tcp6_usr_listen(struct socket *so, int backlog, struct thread *td)
404 struct tcpcb *tp = NULL;
407 INP_INFO_WLOCK(&tcbinfo);
409 KASSERT(inp != NULL, ("tcp6_usr_listen: inp == NULL"));
411 if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) {
418 error = solisten_proto_check(so);
419 if (error == 0 && inp->inp_lport == 0) {
420 inp->inp_vflag &= ~INP_IPV4;
421 if ((inp->inp_flags & IN6P_IPV6_V6ONLY) == 0)
422 inp->inp_vflag |= INP_IPV4;
423 error = in6_pcbbind(inp, (struct sockaddr *)0, td->td_ucred);
426 tp->t_state = TCPS_LISTEN;
427 solisten_proto(so, backlog);
432 TCPDEBUG2(PRU_LISTEN);
434 INP_INFO_WUNLOCK(&tcbinfo);
440 * Initiate connection to peer.
441 * Create a template for use in transmissions on this connection.
442 * Enter SYN_SENT state, and mark socket as connecting.
443 * Start keep-alive timer, and seed output sequence space.
444 * Send initial segment on connection.
447 tcp_usr_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
451 struct tcpcb *tp = NULL;
452 struct sockaddr_in *sinp;
454 sinp = (struct sockaddr_in *)nam;
455 if (nam->sa_len != sizeof (*sinp))
458 * Must disallow TCP ``connections'' to multicast addresses.
460 if (sinp->sin_family == AF_INET
461 && IN_MULTICAST(ntohl(sinp->sin_addr.s_addr)))
462 return (EAFNOSUPPORT);
463 if (jailed(td->td_ucred))
464 prison_remote_ip(td->td_ucred, 0, &sinp->sin_addr.s_addr);
467 INP_INFO_WLOCK(&tcbinfo);
469 KASSERT(inp != NULL, ("tcp_usr_connect: inp == NULL"));
471 if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) {
477 if ((error = tcp_connect(tp, nam, td)) != 0)
479 error = tcp_output(tp);
481 TCPDEBUG2(PRU_CONNECT);
483 INP_INFO_WUNLOCK(&tcbinfo);
489 tcp6_usr_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
493 struct tcpcb *tp = NULL;
494 struct sockaddr_in6 *sin6p;
498 sin6p = (struct sockaddr_in6 *)nam;
499 if (nam->sa_len != sizeof (*sin6p))
502 * Must disallow TCP ``connections'' to multicast addresses.
504 if (sin6p->sin6_family == AF_INET6
505 && IN6_IS_ADDR_MULTICAST(&sin6p->sin6_addr))
506 return (EAFNOSUPPORT);
508 INP_INFO_WLOCK(&tcbinfo);
510 KASSERT(inp != NULL, ("tcp6_usr_connect: inp == NULL"));
512 if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) {
518 if (IN6_IS_ADDR_V4MAPPED(&sin6p->sin6_addr)) {
519 struct sockaddr_in sin;
521 if ((inp->inp_flags & IN6P_IPV6_V6ONLY) != 0) {
526 in6_sin6_2_sin(&sin, sin6p);
527 inp->inp_vflag |= INP_IPV4;
528 inp->inp_vflag &= ~INP_IPV6;
529 if ((error = tcp_connect(tp, (struct sockaddr *)&sin, td)) != 0)
531 error = tcp_output(tp);
534 inp->inp_vflag &= ~INP_IPV4;
535 inp->inp_vflag |= INP_IPV6;
536 inp->inp_inc.inc_isipv6 = 1;
537 if ((error = tcp6_connect(tp, nam, td)) != 0)
539 error = tcp_output(tp);
542 TCPDEBUG2(PRU_CONNECT);
544 INP_INFO_WUNLOCK(&tcbinfo);
550 * Initiate disconnect from peer.
551 * If connection never passed embryonic stage, just drop;
552 * else if don't need to let data drain, then can just drop anyways,
553 * else have to begin TCP shutdown process: mark socket disconnecting,
554 * drain unread data, state switch to reflect user close, and
555 * send segment (e.g. FIN) to peer. Socket will be really disconnected
556 * when peer sends FIN and acks ours.
558 * SHOULD IMPLEMENT LATER PRU_CONNECT VIA REALLOC TCPCB.
561 tcp_usr_disconnect(struct socket *so)
564 struct tcpcb *tp = NULL;
568 INP_INFO_WLOCK(&tcbinfo);
570 KASSERT(inp != NULL, ("tcp_usr_disconnect: inp == NULL"));
572 if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) {
580 TCPDEBUG2(PRU_DISCONNECT);
582 INP_INFO_WUNLOCK(&tcbinfo);
587 * Accept a connection. Essentially all the work is
588 * done at higher levels; just return the address
589 * of the peer, storing through addr.
592 tcp_usr_accept(struct socket *so, struct sockaddr **nam)
595 struct inpcb *inp = NULL;
596 struct tcpcb *tp = NULL;
601 if (so->so_state & SS_ISDISCONNECTED)
602 return (ECONNABORTED);
605 KASSERT(inp != NULL, ("tcp_usr_accept: inp == NULL"));
607 if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) {
608 error = ECONNABORTED;
615 * We inline in_getpeeraddr and COMMON_END here, so that we can
616 * copy the data of interest and defer the malloc until after we
619 port = inp->inp_fport;
620 addr = inp->inp_faddr;
623 TCPDEBUG2(PRU_ACCEPT);
626 *nam = in_sockaddr(port, &addr);
632 tcp6_usr_accept(struct socket *so, struct sockaddr **nam)
634 struct inpcb *inp = NULL;
636 struct tcpcb *tp = NULL;
638 struct in6_addr addr6;
643 if (so->so_state & SS_ISDISCONNECTED)
644 return (ECONNABORTED);
647 KASSERT(inp != NULL, ("tcp6_usr_accept: inp == NULL"));
649 if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) {
650 error = ECONNABORTED;
657 * We inline in6_mapped_peeraddr and COMMON_END here, so that we can
658 * copy the data of interest and defer the malloc until after we
661 if (inp->inp_vflag & INP_IPV4) {
663 port = inp->inp_fport;
664 addr = inp->inp_faddr;
666 port = inp->inp_fport;
667 addr6 = inp->in6p_faddr;
671 TCPDEBUG2(PRU_ACCEPT);
675 *nam = in6_v4mapsin6_sockaddr(port, &addr);
677 *nam = in6_sockaddr(port, &addr6);
684 * Mark the connection as being incapable of further output.
687 tcp_usr_shutdown(struct socket *so)
691 struct tcpcb *tp = NULL;
694 INP_INFO_WLOCK(&tcbinfo);
696 KASSERT(inp != NULL, ("inp == NULL"));
698 if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) {
706 error = tcp_output(tp);
709 TCPDEBUG2(PRU_SHUTDOWN);
711 INP_INFO_WUNLOCK(&tcbinfo);
717 * After a receive, possibly send window update to peer.
720 tcp_usr_rcvd(struct socket *so, int flags)
723 struct tcpcb *tp = NULL;
728 KASSERT(inp != NULL, ("tcp_usr_rcvd: inp == NULL"));
730 if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) {
745 * Do a send by putting data in output queue and updating urgent
746 * marker if URG set. Possibly send more data. Unlike the other
747 * pru_*() routines, the mbuf chains are our responsibility. We
748 * must either enqueue them or free them. The other pru_* routines
749 * generally are caller-frees.
752 tcp_usr_send(struct socket *so, int flags, struct mbuf *m,
753 struct sockaddr *nam, struct mbuf *control, struct thread *td)
757 struct tcpcb *tp = NULL;
765 * We require the pcbinfo lock in two cases:
767 * (1) An implied connect is taking place, which can result in
768 * binding IPs and ports and hence modification of the pcb hash
771 * (2) PRUS_EOF is set, resulting in explicit close on the send.
773 if ((nam != NULL) || (flags & PRUS_EOF)) {
774 INP_INFO_WLOCK(&tcbinfo);
778 KASSERT(inp != NULL, ("tcp_usr_send: inp == NULL"));
780 if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) {
789 isipv6 = nam && nam->sa_family == AF_INET6;
794 /* TCP doesn't do control messages (rights, creds, etc) */
795 if (control->m_len) {
802 m_freem(control); /* empty control, just free it */
804 if (!(flags & PRUS_OOB)) {
805 sbappendstream(&so->so_snd, m);
806 if (nam && tp->t_state < TCPS_SYN_SENT) {
808 * Do implied connect if not yet connected,
809 * initialize window to default value, and
810 * initialize maxseg/maxopd using peer's cached
813 INP_INFO_WLOCK_ASSERT(&tcbinfo);
816 error = tcp6_connect(tp, nam, td);
819 error = tcp_connect(tp, nam, td);
822 tp->snd_wnd = TTCP_CLIENT_SND_WND;
825 if (flags & PRUS_EOF) {
827 * Close the send side of the connection after
830 INP_INFO_WLOCK_ASSERT(&tcbinfo);
835 INP_INFO_WUNLOCK(&tcbinfo);
839 if (flags & PRUS_MORETOCOME)
840 tp->t_flags |= TF_MORETOCOME;
841 error = tcp_output(tp);
842 if (flags & PRUS_MORETOCOME)
843 tp->t_flags &= ~TF_MORETOCOME;
847 * XXXRW: PRUS_EOF not implemented with PRUS_OOB?
849 SOCKBUF_LOCK(&so->so_snd);
850 if (sbspace(&so->so_snd) < -512) {
851 SOCKBUF_UNLOCK(&so->so_snd);
857 * According to RFC961 (Assigned Protocols),
858 * the urgent pointer points to the last octet
859 * of urgent data. We continue, however,
860 * to consider it to indicate the first octet
861 * of data past the urgent section.
862 * Otherwise, snd_up should be one lower.
864 sbappendstream_locked(&so->so_snd, m);
865 SOCKBUF_UNLOCK(&so->so_snd);
866 if (nam && tp->t_state < TCPS_SYN_SENT) {
868 * Do implied connect if not yet connected,
869 * initialize window to default value, and
870 * initialize maxseg/maxopd using peer's cached
873 INP_INFO_WLOCK_ASSERT(&tcbinfo);
876 error = tcp6_connect(tp, nam, td);
879 error = tcp_connect(tp, nam, td);
882 tp->snd_wnd = TTCP_CLIENT_SND_WND;
884 INP_INFO_WUNLOCK(&tcbinfo);
887 INP_INFO_WUNLOCK(&tcbinfo);
890 tp->snd_up = tp->snd_una + so->so_snd.sb_cc;
891 tp->t_flags |= TF_FORCEDATA;
892 error = tcp_output(tp);
893 tp->t_flags &= ~TF_FORCEDATA;
896 TCPDEBUG2((flags & PRUS_OOB) ? PRU_SENDOOB :
897 ((flags & PRUS_EOF) ? PRU_SEND_EOF : PRU_SEND));
900 INP_INFO_WUNLOCK(&tcbinfo);
905 * Abort the TCP. Drop the connection abruptly.
908 tcp_usr_abort(struct socket *so)
911 struct tcpcb *tp = NULL;
915 KASSERT(inp != NULL, ("tcp_usr_abort: inp == NULL"));
917 INP_INFO_WLOCK(&tcbinfo);
919 KASSERT(inp->inp_socket != NULL,
920 ("tcp_usr_abort: inp_socket == NULL"));
923 * If we still have full TCP state, and we're not dropped, drop.
925 if (!(inp->inp_vflag & INP_TIMEWAIT) &&
926 !(inp->inp_vflag & INP_DROPPED)) {
929 tcp_drop(tp, ECONNABORTED);
930 TCPDEBUG2(PRU_ABORT);
932 if (!(inp->inp_vflag & INP_DROPPED)) {
934 so->so_state |= SS_PROTOREF;
936 inp->inp_vflag |= INP_SOCKREF;
939 INP_INFO_WUNLOCK(&tcbinfo);
943 * TCP socket is closed. Start friendly disconnect.
946 tcp_usr_close(struct socket *so)
949 struct tcpcb *tp = NULL;
953 KASSERT(inp != NULL, ("tcp_usr_close: inp == NULL"));
955 INP_INFO_WLOCK(&tcbinfo);
957 KASSERT(inp->inp_socket != NULL,
958 ("tcp_usr_close: inp_socket == NULL"));
961 * If we still have full TCP state, and we're not dropped, initiate
964 if (!(inp->inp_vflag & INP_TIMEWAIT) &&
965 !(inp->inp_vflag & INP_DROPPED)) {
969 TCPDEBUG2(PRU_CLOSE);
971 if (!(inp->inp_vflag & INP_DROPPED)) {
973 so->so_state |= SS_PROTOREF;
975 inp->inp_vflag |= INP_SOCKREF;
978 INP_INFO_WUNLOCK(&tcbinfo);
982 * Receive out-of-band data.
985 tcp_usr_rcvoob(struct socket *so, struct mbuf *m, int flags)
989 struct tcpcb *tp = NULL;
993 KASSERT(inp != NULL, ("tcp_usr_rcvoob: inp == NULL"));
995 if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) {
1001 if ((so->so_oobmark == 0 &&
1002 (so->so_rcv.sb_state & SBS_RCVATMARK) == 0) ||
1003 so->so_options & SO_OOBINLINE ||
1004 tp->t_oobflags & TCPOOB_HADDATA) {
1008 if ((tp->t_oobflags & TCPOOB_HAVEDATA) == 0) {
1009 error = EWOULDBLOCK;
1013 *mtod(m, caddr_t) = tp->t_iobc;
1014 if ((flags & MSG_PEEK) == 0)
1015 tp->t_oobflags ^= (TCPOOB_HAVEDATA | TCPOOB_HADDATA);
1018 TCPDEBUG2(PRU_RCVOOB);
1023 struct pr_usrreqs tcp_usrreqs = {
1024 .pru_abort = tcp_usr_abort,
1025 .pru_accept = tcp_usr_accept,
1026 .pru_attach = tcp_usr_attach,
1027 .pru_bind = tcp_usr_bind,
1028 .pru_connect = tcp_usr_connect,
1029 .pru_control = in_control,
1030 .pru_detach = tcp_usr_detach,
1031 .pru_disconnect = tcp_usr_disconnect,
1032 .pru_listen = tcp_usr_listen,
1033 .pru_peeraddr = in_getpeeraddr,
1034 .pru_rcvd = tcp_usr_rcvd,
1035 .pru_rcvoob = tcp_usr_rcvoob,
1036 .pru_send = tcp_usr_send,
1037 .pru_shutdown = tcp_usr_shutdown,
1038 .pru_sockaddr = in_getsockaddr,
1039 .pru_sosetlabel = in_pcbsosetlabel,
1040 .pru_close = tcp_usr_close,
1044 struct pr_usrreqs tcp6_usrreqs = {
1045 .pru_abort = tcp_usr_abort,
1046 .pru_accept = tcp6_usr_accept,
1047 .pru_attach = tcp_usr_attach,
1048 .pru_bind = tcp6_usr_bind,
1049 .pru_connect = tcp6_usr_connect,
1050 .pru_control = in6_control,
1051 .pru_detach = tcp_usr_detach,
1052 .pru_disconnect = tcp_usr_disconnect,
1053 .pru_listen = tcp6_usr_listen,
1054 .pru_peeraddr = in6_mapped_peeraddr,
1055 .pru_rcvd = tcp_usr_rcvd,
1056 .pru_rcvoob = tcp_usr_rcvoob,
1057 .pru_send = tcp_usr_send,
1058 .pru_shutdown = tcp_usr_shutdown,
1059 .pru_sockaddr = in6_mapped_sockaddr,
1060 .pru_sosetlabel = in_pcbsosetlabel,
1061 .pru_close = tcp_usr_close,
1066 * Common subroutine to open a TCP connection to remote host specified
1067 * by struct sockaddr_in in mbuf *nam. Call in_pcbbind to assign a local
1068 * port number if needed. Call in_pcbconnect_setup to do the routing and
1069 * to choose a local host address (interface). If there is an existing
1070 * incarnation of the same connection in TIME-WAIT state and if the remote
1071 * host was sending CC options and if the connection duration was < MSL, then
1072 * truncate the previous TIME-WAIT state and proceed.
1073 * Initialize connection parameters and enter SYN-SENT state.
1076 tcp_connect(struct tcpcb *tp, struct sockaddr *nam, struct thread *td)
1078 struct inpcb *inp = tp->t_inpcb, *oinp;
1079 struct socket *so = inp->inp_socket;
1080 struct in_addr laddr;
1084 INP_INFO_WLOCK_ASSERT(&tcbinfo);
1085 INP_LOCK_ASSERT(inp);
1087 if (inp->inp_lport == 0) {
1088 error = in_pcbbind(inp, (struct sockaddr *)0, td->td_ucred);
1094 * Cannot simply call in_pcbconnect, because there might be an
1095 * earlier incarnation of this same connection still in
1096 * TIME_WAIT state, creating an ADDRINUSE error.
1098 laddr = inp->inp_laddr;
1099 lport = inp->inp_lport;
1100 error = in_pcbconnect_setup(inp, nam, &laddr.s_addr, &lport,
1101 &inp->inp_faddr.s_addr, &inp->inp_fport, &oinp, td->td_ucred);
1102 if (error && oinp == NULL)
1106 inp->inp_laddr = laddr;
1110 * Compute window scaling to request:
1111 * Scale to fit into sweet spot. See tcp_syncache.c.
1112 * XXX: This should move to tcp_output().
1114 while (tp->request_r_scale < TCP_MAX_WINSHIFT &&
1115 (TCP_MAXWIN << tp->request_r_scale) < sb_max)
1116 tp->request_r_scale++;
1119 tcpstat.tcps_connattempt++;
1120 tp->t_state = TCPS_SYN_SENT;
1121 tcp_timer_activate(tp, TT_KEEP, tcp_keepinit);
1122 tp->iss = tcp_new_isn(tp);
1123 tp->t_bw_rtseq = tp->iss;
1124 tcp_sendseqinit(tp);
1131 tcp6_connect(struct tcpcb *tp, struct sockaddr *nam, struct thread *td)
1133 struct inpcb *inp = tp->t_inpcb, *oinp;
1134 struct socket *so = inp->inp_socket;
1135 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)nam;
1136 struct in6_addr *addr6;
1139 INP_INFO_WLOCK_ASSERT(&tcbinfo);
1140 INP_LOCK_ASSERT(inp);
1142 if (inp->inp_lport == 0) {
1143 error = in6_pcbbind(inp, (struct sockaddr *)0, td->td_ucred);
1149 * Cannot simply call in_pcbconnect, because there might be an
1150 * earlier incarnation of this same connection still in
1151 * TIME_WAIT state, creating an ADDRINUSE error.
1152 * in6_pcbladdr() also handles scope zone IDs.
1154 error = in6_pcbladdr(inp, nam, &addr6);
1157 oinp = in6_pcblookup_hash(inp->inp_pcbinfo,
1158 &sin6->sin6_addr, sin6->sin6_port,
1159 IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_laddr)
1162 inp->inp_lport, 0, NULL);
1165 if (IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_laddr))
1166 inp->in6p_laddr = *addr6;
1167 inp->in6p_faddr = sin6->sin6_addr;
1168 inp->inp_fport = sin6->sin6_port;
1169 /* update flowinfo - draft-itojun-ipv6-flowlabel-api-00 */
1170 inp->in6p_flowinfo &= ~IPV6_FLOWLABEL_MASK;
1171 if (inp->in6p_flags & IN6P_AUTOFLOWLABEL)
1172 inp->in6p_flowinfo |=
1173 (htonl(ip6_randomflowlabel()) & IPV6_FLOWLABEL_MASK);
1176 /* Compute window scaling to request. */
1177 while (tp->request_r_scale < TCP_MAX_WINSHIFT &&
1178 (TCP_MAXWIN << tp->request_r_scale) < so->so_rcv.sb_hiwat)
1179 tp->request_r_scale++;
1182 tcpstat.tcps_connattempt++;
1183 tp->t_state = TCPS_SYN_SENT;
1184 tcp_timer_activate(tp, TT_KEEP, tcp_keepinit);
1185 tp->iss = tcp_new_isn(tp);
1186 tp->t_bw_rtseq = tp->iss;
1187 tcp_sendseqinit(tp);
1194 * Export TCP internal state information via a struct tcp_info, based on the
1195 * Linux 2.6 API. Not ABI compatible as our constants are mapped differently
1196 * (TCP state machine, etc). We export all information using FreeBSD-native
1197 * constants -- for example, the numeric values for tcpi_state will differ
1201 tcp_fill_info(struct tcpcb *tp, struct tcp_info *ti)
1204 INP_LOCK_ASSERT(tp->t_inpcb);
1205 bzero(ti, sizeof(*ti));
1207 ti->tcpi_state = tp->t_state;
1208 if ((tp->t_flags & TF_REQ_TSTMP) && (tp->t_flags & TF_RCVD_TSTMP))
1209 ti->tcpi_options |= TCPI_OPT_TIMESTAMPS;
1210 if (tp->t_flags & TF_SACK_PERMIT)
1211 ti->tcpi_options |= TCPI_OPT_SACK;
1212 if ((tp->t_flags & TF_REQ_SCALE) && (tp->t_flags & TF_RCVD_SCALE)) {
1213 ti->tcpi_options |= TCPI_OPT_WSCALE;
1214 ti->tcpi_snd_wscale = tp->snd_scale;
1215 ti->tcpi_rcv_wscale = tp->rcv_scale;
1218 ti->tcpi_rtt = ((u_int64_t)tp->t_srtt * tick) >> TCP_RTT_SHIFT;
1219 ti->tcpi_rttvar = ((u_int64_t)tp->t_rttvar * tick) >> TCP_RTTVAR_SHIFT;
1221 ti->tcpi_snd_ssthresh = tp->snd_ssthresh;
1222 ti->tcpi_snd_cwnd = tp->snd_cwnd;
1225 * FreeBSD-specific extension fields for tcp_info.
1227 ti->tcpi_rcv_space = tp->rcv_wnd;
1228 ti->tcpi_snd_wnd = tp->snd_wnd;
1229 ti->tcpi_snd_bwnd = tp->snd_bwnd;
1233 * The new sockopt interface makes it possible for us to block in the
1234 * copyin/out step (if we take a page fault). Taking a page fault at
1235 * splnet() is probably a Bad Thing. (Since sockets and pcbs both now
1236 * use TSM, there probably isn't any need for this function to run at
1237 * splnet() any more. This needs more examination.)
1239 * XXXRW: The locking here is wrong; we may take a page fault while holding
1243 tcp_ctloutput(struct socket *so, struct sockopt *sopt)
1245 int error, opt, optval;
1251 inp = sotoinpcb(so);
1252 KASSERT(inp != NULL, ("tcp_ctloutput: inp == NULL"));
1254 if (sopt->sopt_level != IPPROTO_TCP) {
1257 if (INP_CHECK_SOCKAF(so, AF_INET6))
1258 error = ip6_ctloutput(so, sopt);
1261 error = ip_ctloutput(so, sopt);
1264 if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) {
1268 tp = intotcpcb(inp);
1270 switch (sopt->sopt_dir) {
1272 switch (sopt->sopt_name) {
1273 #ifdef TCP_SIGNATURE
1275 error = sooptcopyin(sopt, &optval, sizeof optval,
1281 tp->t_flags |= TF_SIGNATURE;
1283 tp->t_flags &= ~TF_SIGNATURE;
1285 #endif /* TCP_SIGNATURE */
1288 error = sooptcopyin(sopt, &optval, sizeof optval,
1293 switch (sopt->sopt_name) {
1301 opt = 0; /* dead code to fool gcc */
1308 tp->t_flags &= ~opt;
1312 error = sooptcopyin(sopt, &optval, sizeof optval,
1318 tp->t_flags |= TF_NOPUSH;
1320 tp->t_flags &= ~TF_NOPUSH;
1321 error = tcp_output(tp);
1326 error = sooptcopyin(sopt, &optval, sizeof optval,
1331 if (optval > 0 && optval <= tp->t_maxseg &&
1332 optval + 40 >= tcp_minmss)
1333 tp->t_maxseg = optval;
1343 error = ENOPROTOOPT;
1349 switch (sopt->sopt_name) {
1350 #ifdef TCP_SIGNATURE
1352 optval = (tp->t_flags & TF_SIGNATURE) ? 1 : 0;
1353 error = sooptcopyout(sopt, &optval, sizeof optval);
1357 optval = tp->t_flags & TF_NODELAY;
1358 error = sooptcopyout(sopt, &optval, sizeof optval);
1361 optval = tp->t_maxseg;
1362 error = sooptcopyout(sopt, &optval, sizeof optval);
1365 optval = tp->t_flags & TF_NOOPT;
1366 error = sooptcopyout(sopt, &optval, sizeof optval);
1369 optval = tp->t_flags & TF_NOPUSH;
1370 error = sooptcopyout(sopt, &optval, sizeof optval);
1373 tcp_fill_info(tp, &ti);
1374 error = sooptcopyout(sopt, &ti, sizeof ti);
1377 error = ENOPROTOOPT;
1388 * tcp_sendspace and tcp_recvspace are the default send and receive window
1389 * sizes, respectively. These are obsolescent (this information should
1390 * be set by the route).
1392 u_long tcp_sendspace = 1024*32;
1393 SYSCTL_ULONG(_net_inet_tcp, TCPCTL_SENDSPACE, sendspace, CTLFLAG_RW,
1394 &tcp_sendspace , 0, "Maximum outgoing TCP datagram size");
1395 u_long tcp_recvspace = 1024*64;
1396 SYSCTL_ULONG(_net_inet_tcp, TCPCTL_RECVSPACE, recvspace, CTLFLAG_RW,
1397 &tcp_recvspace , 0, "Maximum incoming TCP datagram size");
1400 * Attach TCP protocol to socket, allocating
1401 * internet protocol control block, tcp control block,
1402 * bufer space, and entering LISTEN state if to accept connections.
1405 tcp_attach(struct socket *so)
1411 int isipv6 = INP_CHECK_SOCKAF(so, AF_INET6) != 0;
1414 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
1415 error = soreserve(so, tcp_sendspace, tcp_recvspace);
1419 so->so_rcv.sb_flags |= SB_AUTOSIZE;
1420 so->so_snd.sb_flags |= SB_AUTOSIZE;
1421 INP_INFO_WLOCK(&tcbinfo);
1422 error = in_pcballoc(so, &tcbinfo);
1424 INP_INFO_WUNLOCK(&tcbinfo);
1427 inp = sotoinpcb(so);
1430 inp->inp_vflag |= INP_IPV6;
1431 inp->in6p_hops = -1; /* use kernel default */
1435 inp->inp_vflag |= INP_IPV4;
1436 tp = tcp_newtcpcb(inp);
1449 INP_INFO_WUNLOCK(&tcbinfo);
1452 tp->t_state = TCPS_CLOSED;
1454 INP_INFO_WUNLOCK(&tcbinfo);
1459 * Initiate (or continue) disconnect.
1460 * If embryonic state, just send reset (once).
1461 * If in ``let data drain'' option and linger null, just drop.
1462 * Otherwise (hard), mark socket disconnecting and drop
1463 * current input data; switch states based on user close, and
1464 * send segment to peer (with FIN).
1467 tcp_disconnect(struct tcpcb *tp)
1469 struct inpcb *inp = tp->t_inpcb;
1470 struct socket *so = inp->inp_socket;
1472 INP_INFO_WLOCK_ASSERT(&tcbinfo);
1473 INP_LOCK_ASSERT(inp);
1476 * Neither tcp_close() nor tcp_drop() should return NULL, as the
1477 * socket is still open.
1479 if (tp->t_state < TCPS_ESTABLISHED) {
1482 ("tcp_disconnect: tcp_close() returned NULL"));
1483 } else if ((so->so_options & SO_LINGER) && so->so_linger == 0) {
1484 tp = tcp_drop(tp, 0);
1486 ("tcp_disconnect: tcp_drop() returned NULL"));
1488 soisdisconnecting(so);
1489 sbflush(&so->so_rcv);
1491 if (!(inp->inp_vflag & INP_DROPPED))
1497 * User issued close, and wish to trail through shutdown states:
1498 * if never received SYN, just forget it. If got a SYN from peer,
1499 * but haven't sent FIN, then go to FIN_WAIT_1 state to send peer a FIN.
1500 * If already got a FIN from peer, then almost done; go to LAST_ACK
1501 * state. In all other cases, have already sent FIN to peer (e.g.
1502 * after PRU_SHUTDOWN), and just have to play tedious game waiting
1503 * for peer to send FIN or not respond to keep-alives, etc.
1504 * We can let the user exit from the close as soon as the FIN is acked.
1507 tcp_usrclosed(struct tcpcb *tp)
1510 INP_INFO_WLOCK_ASSERT(&tcbinfo);
1511 INP_LOCK_ASSERT(tp->t_inpcb);
1513 switch (tp->t_state) {
1516 tp->t_state = TCPS_CLOSED;
1519 * tcp_close() should never return NULL here as the socket is
1523 ("tcp_usrclosed: tcp_close() returned NULL"));
1527 case TCPS_SYN_RECEIVED:
1528 tp->t_flags |= TF_NEEDFIN;
1531 case TCPS_ESTABLISHED:
1532 tp->t_state = TCPS_FIN_WAIT_1;
1535 case TCPS_CLOSE_WAIT:
1536 tp->t_state = TCPS_LAST_ACK;
1539 if (tp->t_state >= TCPS_FIN_WAIT_2) {
1540 soisdisconnected(tp->t_inpcb->inp_socket);
1541 /* Prevent the connection hanging in FIN_WAIT_2 forever. */
1542 if (tp->t_state == TCPS_FIN_WAIT_2) {
1545 timeout = (tcp_fast_finwait2_recycle) ?
1546 tcp_finwait2_timeout : tcp_maxidle;
1547 tcp_timer_activate(tp, TT_2MSL, timeout);
1554 db_print_indent(int indent)
1558 for (i = 0; i < indent; i++)
1563 db_print_tstate(int t_state)
1568 db_printf("TCPS_CLOSED");
1572 db_printf("TCPS_LISTEN");
1576 db_printf("TCPS_SYN_SENT");
1579 case TCPS_SYN_RECEIVED:
1580 db_printf("TCPS_SYN_RECEIVED");
1583 case TCPS_ESTABLISHED:
1584 db_printf("TCPS_ESTABLISHED");
1587 case TCPS_CLOSE_WAIT:
1588 db_printf("TCPS_CLOSE_WAIT");
1591 case TCPS_FIN_WAIT_1:
1592 db_printf("TCPS_FIN_WAIT_1");
1596 db_printf("TCPS_CLOSING");
1600 db_printf("TCPS_LAST_ACK");
1603 case TCPS_FIN_WAIT_2:
1604 db_printf("TCPS_FIN_WAIT_2");
1607 case TCPS_TIME_WAIT:
1608 db_printf("TCPS_TIME_WAIT");
1612 db_printf("unknown");
1618 db_print_tflags(u_int t_flags)
1623 if (t_flags & TF_ACKNOW) {
1624 db_printf("%sTF_ACKNOW", comma ? ", " : "");
1627 if (t_flags & TF_DELACK) {
1628 db_printf("%sTF_DELACK", comma ? ", " : "");
1631 if (t_flags & TF_NODELAY) {
1632 db_printf("%sTF_NODELAY", comma ? ", " : "");
1635 if (t_flags & TF_NOOPT) {
1636 db_printf("%sTF_NOOPT", comma ? ", " : "");
1639 if (t_flags & TF_SENTFIN) {
1640 db_printf("%sTF_SENTFIN", comma ? ", " : "");
1643 if (t_flags & TF_REQ_SCALE) {
1644 db_printf("%sTF_REQ_SCALE", comma ? ", " : "");
1647 if (t_flags & TF_RCVD_SCALE) {
1648 db_printf("%sTF_RECVD_SCALE", comma ? ", " : "");
1651 if (t_flags & TF_REQ_TSTMP) {
1652 db_printf("%sTF_REQ_TSTMP", comma ? ", " : "");
1655 if (t_flags & TF_RCVD_TSTMP) {
1656 db_printf("%sTF_RCVD_TSTMP", comma ? ", " : "");
1659 if (t_flags & TF_SACK_PERMIT) {
1660 db_printf("%sTF_SACK_PERMIT", comma ? ", " : "");
1663 if (t_flags & TF_NEEDSYN) {
1664 db_printf("%sTF_NEEDSYN", comma ? ", " : "");
1667 if (t_flags & TF_NEEDFIN) {
1668 db_printf("%sTF_NEEDFIN", comma ? ", " : "");
1671 if (t_flags & TF_NOPUSH) {
1672 db_printf("%sTF_NOPUSH", comma ? ", " : "");
1675 if (t_flags & TF_NOPUSH) {
1676 db_printf("%sTF_NOPUSH", comma ? ", " : "");
1679 if (t_flags & TF_MORETOCOME) {
1680 db_printf("%sTF_MORETOCOME", comma ? ", " : "");
1683 if (t_flags & TF_LQ_OVERFLOW) {
1684 db_printf("%sTF_LQ_OVERFLOW", comma ? ", " : "");
1687 if (t_flags & TF_LASTIDLE) {
1688 db_printf("%sTF_LASTIDLE", comma ? ", " : "");
1691 if (t_flags & TF_RXWIN0SENT) {
1692 db_printf("%sTF_RXWIN0SENT", comma ? ", " : "");
1695 if (t_flags & TF_FASTRECOVERY) {
1696 db_printf("%sTF_FASTRECOVERY", comma ? ", " : "");
1699 if (t_flags & TF_WASFRECOVERY) {
1700 db_printf("%sTF_WASFRECOVERY", comma ? ", " : "");
1703 if (t_flags & TF_SIGNATURE) {
1704 db_printf("%sTF_SIGNATURE", comma ? ", " : "");
1707 if (t_flags & TF_FORCEDATA) {
1708 db_printf("%sTF_FORCEDATA", comma ? ", " : "");
1711 if (t_flags & TF_TSO) {
1712 db_printf("%sTF_TSO", comma ? ", " : "");
1718 db_print_toobflags(char t_oobflags)
1723 if (t_oobflags & TCPOOB_HAVEDATA) {
1724 db_printf("%sTCPOOB_HAVEDATA", comma ? ", " : "");
1727 if (t_oobflags & TCPOOB_HADDATA) {
1728 db_printf("%sTCPOOB_HADDATA", comma ? ", " : "");
1734 db_print_tcpcb(struct tcpcb *tp, const char *name, int indent)
1737 db_print_indent(indent);
1738 db_printf("%s at %p\n", name, tp);
1742 db_print_indent(indent);
1743 db_printf("t_segq first: %p t_segqlen: %d t_dupacks: %d\n",
1744 LIST_FIRST(&tp->t_segq), tp->t_segqlen, tp->t_dupacks);
1746 db_print_indent(indent);
1747 db_printf("tt_rexmt: %p tt_persist: %p tt_keep: %p\n",
1748 &tp->t_timers->tt_rexmt, &tp->t_timers->tt_persist, &tp->t_timers->tt_keep);
1750 db_print_indent(indent);
1751 db_printf("tt_2msl: %p tt_delack: %p t_inpcb: %p\n", &tp->t_timers->tt_2msl,
1752 &tp->t_timers->tt_delack, tp->t_inpcb);
1754 db_print_indent(indent);
1755 db_printf("t_state: %d (", tp->t_state);
1756 db_print_tstate(tp->t_state);
1759 db_print_indent(indent);
1760 db_printf("t_flags: 0x%x (", tp->t_flags);
1761 db_print_tflags(tp->t_flags);
1764 db_print_indent(indent);
1765 db_printf("snd_una: 0x%08x snd_max: 0x%08x snd_nxt: x0%08x\n",
1766 tp->snd_una, tp->snd_max, tp->snd_nxt);
1768 db_print_indent(indent);
1769 db_printf("snd_up: 0x%08x snd_wl1: 0x%08x snd_wl2: 0x%08x\n",
1770 tp->snd_up, tp->snd_wl1, tp->snd_wl2);
1772 db_print_indent(indent);
1773 db_printf("iss: 0x%08x irs: 0x%08x rcv_nxt: 0x%08x\n",
1774 tp->iss, tp->irs, tp->rcv_nxt);
1776 db_print_indent(indent);
1777 db_printf("rcv_adv: 0x%08x rcv_wnd: %lu rcv_up: 0x%08x\n",
1778 tp->rcv_adv, tp->rcv_wnd, tp->rcv_up);
1780 db_print_indent(indent);
1781 db_printf("snd_wnd: %lu snd_cwnd: %lu snd_bwnd: %lu\n",
1782 tp->snd_wnd, tp->snd_cwnd, tp->snd_bwnd);
1784 db_print_indent(indent);
1785 db_printf("snd_ssthresh: %lu snd_bandwidth: %lu snd_recover: "
1786 "0x%08x\n", tp->snd_ssthresh, tp->snd_bandwidth,
1789 db_print_indent(indent);
1790 db_printf("t_maxopd: %u t_rcvtime: %lu t_startime: %lu\n",
1791 tp->t_maxopd, tp->t_rcvtime, tp->t_starttime);
1793 db_print_indent(indent);
1794 db_printf("t_rttime: %d t_rtsq: 0x%08x t_bw_rtttime: %d\n",
1795 tp->t_rtttime, tp->t_rtseq, tp->t_bw_rtttime);
1797 db_print_indent(indent);
1798 db_printf("t_bw_rtseq: 0x%08x t_rxtcur: %d t_maxseg: %u "
1799 "t_srtt: %d\n", tp->t_bw_rtseq, tp->t_rxtcur, tp->t_maxseg,
1802 db_print_indent(indent);
1803 db_printf("t_rttvar: %d t_rxtshift: %d t_rttmin: %u "
1804 "t_rttbest: %u\n", tp->t_rttvar, tp->t_rxtshift, tp->t_rttmin,
1807 db_print_indent(indent);
1808 db_printf("t_rttupdated: %lu max_sndwnd: %lu t_softerror: %d\n",
1809 tp->t_rttupdated, tp->max_sndwnd, tp->t_softerror);
1811 db_print_indent(indent);
1812 db_printf("t_oobflags: 0x%x (", tp->t_oobflags);
1813 db_print_toobflags(tp->t_oobflags);
1814 db_printf(") t_iobc: 0x%02x\n", tp->t_iobc);
1816 db_print_indent(indent);
1817 db_printf("snd_scale: %u rcv_scale: %u request_r_scale: %u\n",
1818 tp->snd_scale, tp->rcv_scale, tp->request_r_scale);
1820 db_print_indent(indent);
1821 db_printf("ts_recent: %u ts_recent_age: %lu\n",
1822 tp->ts_recent, tp->ts_recent_age);
1824 db_print_indent(indent);
1825 db_printf("ts_offset: %u last_ack_sent: 0x%08x snd_cwnd_prev: "
1826 "%lu\n", tp->ts_offset, tp->last_ack_sent, tp->snd_cwnd_prev);
1828 db_print_indent(indent);
1829 db_printf("snd_ssthresh_prev: %lu snd_recover_prev: 0x%08x "
1830 "t_badrxtwin: %lu\n", tp->snd_ssthresh_prev,
1831 tp->snd_recover_prev, tp->t_badrxtwin);
1833 db_print_indent(indent);
1834 db_printf("snd_numholes: %d snd_holes first: %p\n",
1835 tp->snd_numholes, TAILQ_FIRST(&tp->snd_holes));
1837 db_print_indent(indent);
1838 db_printf("snd_fack: 0x%08x rcv_numsacks: %d sack_newdata: "
1839 "0x%08x\n", tp->snd_fack, tp->rcv_numsacks, tp->sack_newdata);
1841 /* Skip sackblks, sackhint. */
1843 db_print_indent(indent);
1844 db_printf("t_rttlow: %d rfbuf_ts: %u rfbuf_cnt: %d\n",
1845 tp->t_rttlow, tp->rfbuf_ts, tp->rfbuf_cnt);
1848 DB_SHOW_COMMAND(tcpcb, db_show_tcpcb)
1853 db_printf("usage: show tcpcb <addr>\n");
1856 tp = (struct tcpcb *)addr;
1858 db_print_tcpcb(tp, "tcpcb", 0);