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
37 #include "opt_inet6.h"
38 #include "opt_tcpdebug.h"
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/malloc.h>
43 #include <sys/kernel.h>
44 #include <sys/sysctl.h>
47 #include <sys/domain.h>
49 #include <sys/socket.h>
50 #include <sys/socketvar.h>
51 #include <sys/protosw.h>
60 #include <net/route.h>
62 #include <netinet/in.h>
63 #include <netinet/in_systm.h>
65 #include <netinet/ip6.h>
67 #include <netinet/in_pcb.h>
69 #include <netinet6/in6_pcb.h>
71 #include <netinet/in_var.h>
72 #include <netinet/ip_var.h>
74 #include <netinet6/ip6_var.h>
75 #include <netinet6/scope6_var.h>
77 #include <netinet/tcp.h>
78 #include <netinet/tcp_fsm.h>
79 #include <netinet/tcp_seq.h>
80 #include <netinet/tcp_timer.h>
81 #include <netinet/tcp_var.h>
82 #include <netinet/tcpip.h>
84 #include <netinet/tcp_debug.h>
88 * TCP protocol interface to socket abstraction.
90 extern char *tcpstates[]; /* XXX ??? */
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)
255 KASSERT(inp != NULL, ("tcp_usr_detach: inp == NULL"));
256 INP_INFO_WLOCK(&tcbinfo);
258 KASSERT(inp->inp_socket != NULL,
259 ("tcp_usr_detach: inp_socket == NULL"));
264 TCPDEBUG2(PRU_DETACH);
265 INP_INFO_WUNLOCK(&tcbinfo);
269 * Give the socket an address.
272 tcp_usr_bind(struct socket *so, struct sockaddr *nam, struct thread *td)
276 struct tcpcb *tp = NULL;
277 struct sockaddr_in *sinp;
279 sinp = (struct sockaddr_in *)nam;
280 if (nam->sa_len != sizeof (*sinp))
283 * Must check for multicast addresses and disallow binding
286 if (sinp->sin_family == AF_INET &&
287 IN_MULTICAST(ntohl(sinp->sin_addr.s_addr)))
288 return (EAFNOSUPPORT);
291 INP_INFO_WLOCK(&tcbinfo);
293 KASSERT(inp != NULL, ("tcp_usr_bind: inp == NULL"));
295 if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) {
301 error = in_pcbbind(inp, nam, td->td_ucred);
305 INP_INFO_WUNLOCK(&tcbinfo);
312 tcp6_usr_bind(struct socket *so, struct sockaddr *nam, struct thread *td)
316 struct tcpcb *tp = NULL;
317 struct sockaddr_in6 *sin6p;
319 sin6p = (struct sockaddr_in6 *)nam;
320 if (nam->sa_len != sizeof (*sin6p))
323 * Must check for multicast addresses and disallow binding
326 if (sin6p->sin6_family == AF_INET6 &&
327 IN6_IS_ADDR_MULTICAST(&sin6p->sin6_addr))
328 return (EAFNOSUPPORT);
331 INP_INFO_WLOCK(&tcbinfo);
333 KASSERT(inp != NULL, ("tcp6_usr_bind: inp == NULL"));
335 if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) {
341 inp->inp_vflag &= ~INP_IPV4;
342 inp->inp_vflag |= INP_IPV6;
343 if ((inp->inp_flags & IN6P_IPV6_V6ONLY) == 0) {
344 if (IN6_IS_ADDR_UNSPECIFIED(&sin6p->sin6_addr))
345 inp->inp_vflag |= INP_IPV4;
346 else if (IN6_IS_ADDR_V4MAPPED(&sin6p->sin6_addr)) {
347 struct sockaddr_in sin;
349 in6_sin6_2_sin(&sin, sin6p);
350 inp->inp_vflag |= INP_IPV4;
351 inp->inp_vflag &= ~INP_IPV6;
352 error = in_pcbbind(inp, (struct sockaddr *)&sin,
357 error = in6_pcbbind(inp, nam, td->td_ucred);
361 INP_INFO_WUNLOCK(&tcbinfo);
367 * Prepare to accept connections.
370 tcp_usr_listen(struct socket *so, int backlog, struct thread *td)
374 struct tcpcb *tp = NULL;
377 INP_INFO_WLOCK(&tcbinfo);
379 KASSERT(inp != NULL, ("tcp_usr_listen: inp == NULL"));
381 if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) {
388 error = solisten_proto_check(so);
389 if (error == 0 && inp->inp_lport == 0)
390 error = in_pcbbind(inp, (struct sockaddr *)0, td->td_ucred);
392 tp->t_state = TCPS_LISTEN;
393 solisten_proto(so, backlog);
398 TCPDEBUG2(PRU_LISTEN);
400 INP_INFO_WUNLOCK(&tcbinfo);
406 tcp6_usr_listen(struct socket *so, int backlog, struct thread *td)
410 struct tcpcb *tp = NULL;
413 INP_INFO_WLOCK(&tcbinfo);
415 KASSERT(inp != NULL, ("tcp6_usr_listen: inp == NULL"));
417 if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) {
424 error = solisten_proto_check(so);
425 if (error == 0 && inp->inp_lport == 0) {
426 inp->inp_vflag &= ~INP_IPV4;
427 if ((inp->inp_flags & IN6P_IPV6_V6ONLY) == 0)
428 inp->inp_vflag |= INP_IPV4;
429 error = in6_pcbbind(inp, (struct sockaddr *)0, td->td_ucred);
432 tp->t_state = TCPS_LISTEN;
433 solisten_proto(so, backlog);
438 TCPDEBUG2(PRU_LISTEN);
440 INP_INFO_WUNLOCK(&tcbinfo);
446 * Initiate connection to peer.
447 * Create a template for use in transmissions on this connection.
448 * Enter SYN_SENT state, and mark socket as connecting.
449 * Start keep-alive timer, and seed output sequence space.
450 * Send initial segment on connection.
453 tcp_usr_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
457 struct tcpcb *tp = NULL;
458 struct sockaddr_in *sinp;
460 sinp = (struct sockaddr_in *)nam;
461 if (nam->sa_len != sizeof (*sinp))
464 * Must disallow TCP ``connections'' to multicast addresses.
466 if (sinp->sin_family == AF_INET
467 && IN_MULTICAST(ntohl(sinp->sin_addr.s_addr)))
468 return (EAFNOSUPPORT);
469 if (jailed(td->td_ucred))
470 prison_remote_ip(td->td_ucred, 0, &sinp->sin_addr.s_addr);
473 INP_INFO_WLOCK(&tcbinfo);
475 KASSERT(inp != NULL, ("tcp_usr_connect: inp == NULL"));
477 if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) {
483 if ((error = tcp_connect(tp, nam, td)) != 0)
485 error = tcp_output(tp);
487 TCPDEBUG2(PRU_CONNECT);
489 INP_INFO_WUNLOCK(&tcbinfo);
495 tcp6_usr_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
499 struct tcpcb *tp = NULL;
500 struct sockaddr_in6 *sin6p;
504 sin6p = (struct sockaddr_in6 *)nam;
505 if (nam->sa_len != sizeof (*sin6p))
508 * Must disallow TCP ``connections'' to multicast addresses.
510 if (sin6p->sin6_family == AF_INET6
511 && IN6_IS_ADDR_MULTICAST(&sin6p->sin6_addr))
512 return (EAFNOSUPPORT);
514 INP_INFO_WLOCK(&tcbinfo);
516 KASSERT(inp != NULL, ("tcp6_usr_connect: inp == NULL"));
518 if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) {
524 if (IN6_IS_ADDR_V4MAPPED(&sin6p->sin6_addr)) {
525 struct sockaddr_in sin;
527 if ((inp->inp_flags & IN6P_IPV6_V6ONLY) != 0) {
532 in6_sin6_2_sin(&sin, sin6p);
533 inp->inp_vflag |= INP_IPV4;
534 inp->inp_vflag &= ~INP_IPV6;
535 if ((error = tcp_connect(tp, (struct sockaddr *)&sin, td)) != 0)
537 error = tcp_output(tp);
540 inp->inp_vflag &= ~INP_IPV4;
541 inp->inp_vflag |= INP_IPV6;
542 inp->inp_inc.inc_isipv6 = 1;
543 if ((error = tcp6_connect(tp, nam, td)) != 0)
545 error = tcp_output(tp);
548 TCPDEBUG2(PRU_CONNECT);
550 INP_INFO_WUNLOCK(&tcbinfo);
556 * Initiate disconnect from peer.
557 * If connection never passed embryonic stage, just drop;
558 * else if don't need to let data drain, then can just drop anyways,
559 * else have to begin TCP shutdown process: mark socket disconnecting,
560 * drain unread data, state switch to reflect user close, and
561 * send segment (e.g. FIN) to peer. Socket will be really disconnected
562 * when peer sends FIN and acks ours.
564 * SHOULD IMPLEMENT LATER PRU_CONNECT VIA REALLOC TCPCB.
567 tcp_usr_disconnect(struct socket *so)
570 struct tcpcb *tp = NULL;
574 INP_INFO_WLOCK(&tcbinfo);
576 KASSERT(inp != NULL, ("tcp_usr_disconnect: inp == NULL"));
578 if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) {
586 TCPDEBUG2(PRU_DISCONNECT);
588 INP_INFO_WUNLOCK(&tcbinfo);
593 * Accept a connection. Essentially all the work is
594 * done at higher levels; just return the address
595 * of the peer, storing through addr.
598 tcp_usr_accept(struct socket *so, struct sockaddr **nam)
601 struct inpcb *inp = NULL;
602 struct tcpcb *tp = NULL;
607 if (so->so_state & SS_ISDISCONNECTED)
608 return (ECONNABORTED);
611 KASSERT(inp != NULL, ("tcp_usr_accept: inp == NULL"));
613 if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) {
614 error = ECONNABORTED;
621 * We inline in_getpeeraddr and COMMON_END here, so that we can
622 * copy the data of interest and defer the malloc until after we
625 port = inp->inp_fport;
626 addr = inp->inp_faddr;
629 TCPDEBUG2(PRU_ACCEPT);
632 *nam = in_sockaddr(port, &addr);
638 tcp6_usr_accept(struct socket *so, struct sockaddr **nam)
640 struct inpcb *inp = NULL;
642 struct tcpcb *tp = NULL;
644 struct in6_addr addr6;
649 if (so->so_state & SS_ISDISCONNECTED)
650 return (ECONNABORTED);
653 KASSERT(inp != NULL, ("tcp6_usr_accept: inp == NULL"));
655 if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) {
656 error = ECONNABORTED;
663 * We inline in6_mapped_peeraddr and COMMON_END here, so that we can
664 * copy the data of interest and defer the malloc until after we
667 if (inp->inp_vflag & INP_IPV4) {
669 port = inp->inp_fport;
670 addr = inp->inp_faddr;
672 port = inp->inp_fport;
673 addr6 = inp->in6p_faddr;
677 TCPDEBUG2(PRU_ACCEPT);
681 *nam = in6_v4mapsin6_sockaddr(port, &addr);
683 *nam = in6_sockaddr(port, &addr6);
690 * Mark the connection as being incapable of further output.
693 tcp_usr_shutdown(struct socket *so)
697 struct tcpcb *tp = NULL;
700 INP_INFO_WLOCK(&tcbinfo);
702 KASSERT(inp != NULL, ("inp == NULL"));
704 if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) {
712 error = tcp_output(tp);
715 TCPDEBUG2(PRU_SHUTDOWN);
717 INP_INFO_WUNLOCK(&tcbinfo);
723 * After a receive, possibly send window update to peer.
726 tcp_usr_rcvd(struct socket *so, int flags)
729 struct tcpcb *tp = NULL;
734 KASSERT(inp != NULL, ("tcp_usr_rcvd: inp == NULL"));
736 if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) {
751 * Do a send by putting data in output queue and updating urgent
752 * marker if URG set. Possibly send more data. Unlike the other
753 * pru_*() routines, the mbuf chains are our responsibility. We
754 * must either enqueue them or free them. The other pru_* routines
755 * generally are caller-frees.
758 tcp_usr_send(struct socket *so, int flags, struct mbuf *m,
759 struct sockaddr *nam, struct mbuf *control, struct thread *td)
763 struct tcpcb *tp = NULL;
771 * We require the pcbinfo lock in two cases:
773 * (1) An implied connect is taking place, which can result in
774 * binding IPs and ports and hence modification of the pcb hash
777 * (2) PRUS_EOF is set, resulting in explicit close on the send.
779 if ((nam != NULL) || (flags & PRUS_EOF)) {
780 INP_INFO_WLOCK(&tcbinfo);
784 KASSERT(inp != NULL, ("tcp_usr_send: inp == NULL"));
786 if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) {
795 isipv6 = nam && nam->sa_family == AF_INET6;
800 /* TCP doesn't do control messages (rights, creds, etc) */
801 if (control->m_len) {
808 m_freem(control); /* empty control, just free it */
810 if (!(flags & PRUS_OOB)) {
811 sbappendstream(&so->so_snd, m);
812 if (nam && tp->t_state < TCPS_SYN_SENT) {
814 * Do implied connect if not yet connected,
815 * initialize window to default value, and
816 * initialize maxseg/maxopd using peer's cached
819 INP_INFO_WLOCK_ASSERT(&tcbinfo);
822 error = tcp6_connect(tp, nam, td);
825 error = tcp_connect(tp, nam, td);
828 tp->snd_wnd = TTCP_CLIENT_SND_WND;
831 if (flags & PRUS_EOF) {
833 * Close the send side of the connection after
836 INP_INFO_WLOCK_ASSERT(&tcbinfo);
841 INP_INFO_WUNLOCK(&tcbinfo);
845 if (flags & PRUS_MORETOCOME)
846 tp->t_flags |= TF_MORETOCOME;
847 error = tcp_output(tp);
848 if (flags & PRUS_MORETOCOME)
849 tp->t_flags &= ~TF_MORETOCOME;
853 * XXXRW: PRUS_EOF not implemented with PRUS_OOB?
855 SOCKBUF_LOCK(&so->so_snd);
856 if (sbspace(&so->so_snd) < -512) {
857 SOCKBUF_UNLOCK(&so->so_snd);
863 * According to RFC961 (Assigned Protocols),
864 * the urgent pointer points to the last octet
865 * of urgent data. We continue, however,
866 * to consider it to indicate the first octet
867 * of data past the urgent section.
868 * Otherwise, snd_up should be one lower.
870 sbappendstream_locked(&so->so_snd, m);
871 SOCKBUF_UNLOCK(&so->so_snd);
872 if (nam && tp->t_state < TCPS_SYN_SENT) {
874 * Do implied connect if not yet connected,
875 * initialize window to default value, and
876 * initialize maxseg/maxopd using peer's cached
879 INP_INFO_WLOCK_ASSERT(&tcbinfo);
882 error = tcp6_connect(tp, nam, td);
885 error = tcp_connect(tp, nam, td);
888 tp->snd_wnd = TTCP_CLIENT_SND_WND;
890 INP_INFO_WUNLOCK(&tcbinfo);
893 INP_INFO_WUNLOCK(&tcbinfo);
896 tp->snd_up = tp->snd_una + so->so_snd.sb_cc;
897 tp->t_flags |= TF_FORCEDATA;
898 error = tcp_output(tp);
899 tp->t_flags &= ~TF_FORCEDATA;
902 TCPDEBUG2((flags & PRUS_OOB) ? PRU_SENDOOB :
903 ((flags & PRUS_EOF) ? PRU_SEND_EOF : PRU_SEND));
906 INP_INFO_WUNLOCK(&tcbinfo);
911 * Abort the TCP. Drop the connection abruptly.
914 tcp_usr_abort(struct socket *so)
917 struct tcpcb *tp = NULL;
921 KASSERT(inp != NULL, ("tcp_usr_abort: inp == NULL"));
923 INP_INFO_WLOCK(&tcbinfo);
925 KASSERT(inp->inp_socket != NULL,
926 ("tcp_usr_abort: inp_socket == NULL"));
929 * If we still have full TCP state, and we're not dropped, drop.
931 if (!(inp->inp_vflag & INP_TIMEWAIT) &&
932 !(inp->inp_vflag & INP_DROPPED)) {
935 tcp_drop(tp, ECONNABORTED);
936 TCPDEBUG2(PRU_ABORT);
938 if (!(inp->inp_vflag & INP_DROPPED)) {
940 so->so_state |= SS_PROTOREF;
942 inp->inp_vflag |= INP_SOCKREF;
945 INP_INFO_WUNLOCK(&tcbinfo);
949 * TCP socket is closed. Start friendly disconnect.
952 tcp_usr_close(struct socket *so)
955 struct tcpcb *tp = NULL;
959 KASSERT(inp != NULL, ("tcp_usr_close: inp == NULL"));
961 INP_INFO_WLOCK(&tcbinfo);
963 KASSERT(inp->inp_socket != NULL,
964 ("tcp_usr_close: inp_socket == NULL"));
967 * If we still have full TCP state, and we're not dropped, initiate
970 if (!(inp->inp_vflag & INP_TIMEWAIT) &&
971 !(inp->inp_vflag & INP_DROPPED)) {
975 TCPDEBUG2(PRU_CLOSE);
977 if (!(inp->inp_vflag & INP_DROPPED)) {
979 so->so_state |= SS_PROTOREF;
981 inp->inp_vflag |= INP_SOCKREF;
984 INP_INFO_WUNLOCK(&tcbinfo);
988 * Receive out-of-band data.
991 tcp_usr_rcvoob(struct socket *so, struct mbuf *m, int flags)
995 struct tcpcb *tp = NULL;
999 KASSERT(inp != NULL, ("tcp_usr_rcvoob: inp == NULL"));
1001 if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) {
1005 tp = intotcpcb(inp);
1007 if ((so->so_oobmark == 0 &&
1008 (so->so_rcv.sb_state & SBS_RCVATMARK) == 0) ||
1009 so->so_options & SO_OOBINLINE ||
1010 tp->t_oobflags & TCPOOB_HADDATA) {
1014 if ((tp->t_oobflags & TCPOOB_HAVEDATA) == 0) {
1015 error = EWOULDBLOCK;
1019 *mtod(m, caddr_t) = tp->t_iobc;
1020 if ((flags & MSG_PEEK) == 0)
1021 tp->t_oobflags ^= (TCPOOB_HAVEDATA | TCPOOB_HADDATA);
1024 TCPDEBUG2(PRU_RCVOOB);
1029 struct pr_usrreqs tcp_usrreqs = {
1030 .pru_abort = tcp_usr_abort,
1031 .pru_accept = tcp_usr_accept,
1032 .pru_attach = tcp_usr_attach,
1033 .pru_bind = tcp_usr_bind,
1034 .pru_connect = tcp_usr_connect,
1035 .pru_control = in_control,
1036 .pru_detach = tcp_usr_detach,
1037 .pru_disconnect = tcp_usr_disconnect,
1038 .pru_listen = tcp_usr_listen,
1039 .pru_peeraddr = in_getpeeraddr,
1040 .pru_rcvd = tcp_usr_rcvd,
1041 .pru_rcvoob = tcp_usr_rcvoob,
1042 .pru_send = tcp_usr_send,
1043 .pru_shutdown = tcp_usr_shutdown,
1044 .pru_sockaddr = in_getsockaddr,
1045 .pru_sosetlabel = in_pcbsosetlabel,
1046 .pru_close = tcp_usr_close,
1050 struct pr_usrreqs tcp6_usrreqs = {
1051 .pru_abort = tcp_usr_abort,
1052 .pru_accept = tcp6_usr_accept,
1053 .pru_attach = tcp_usr_attach,
1054 .pru_bind = tcp6_usr_bind,
1055 .pru_connect = tcp6_usr_connect,
1056 .pru_control = in6_control,
1057 .pru_detach = tcp_usr_detach,
1058 .pru_disconnect = tcp_usr_disconnect,
1059 .pru_listen = tcp6_usr_listen,
1060 .pru_peeraddr = in6_mapped_peeraddr,
1061 .pru_rcvd = tcp_usr_rcvd,
1062 .pru_rcvoob = tcp_usr_rcvoob,
1063 .pru_send = tcp_usr_send,
1064 .pru_shutdown = tcp_usr_shutdown,
1065 .pru_sockaddr = in6_mapped_sockaddr,
1066 .pru_sosetlabel = in_pcbsosetlabel,
1067 .pru_close = tcp_usr_close,
1072 * Common subroutine to open a TCP connection to remote host specified
1073 * by struct sockaddr_in in mbuf *nam. Call in_pcbbind to assign a local
1074 * port number if needed. Call in_pcbconnect_setup to do the routing and
1075 * to choose a local host address (interface). If there is an existing
1076 * incarnation of the same connection in TIME-WAIT state and if the remote
1077 * host was sending CC options and if the connection duration was < MSL, then
1078 * truncate the previous TIME-WAIT state and proceed.
1079 * Initialize connection parameters and enter SYN-SENT state.
1082 tcp_connect(struct tcpcb *tp, struct sockaddr *nam, struct thread *td)
1084 struct inpcb *inp = tp->t_inpcb, *oinp;
1085 struct socket *so = inp->inp_socket;
1086 struct in_addr laddr;
1090 INP_INFO_WLOCK_ASSERT(&tcbinfo);
1091 INP_LOCK_ASSERT(inp);
1093 if (inp->inp_lport == 0) {
1094 error = in_pcbbind(inp, (struct sockaddr *)0, td->td_ucred);
1100 * Cannot simply call in_pcbconnect, because there might be an
1101 * earlier incarnation of this same connection still in
1102 * TIME_WAIT state, creating an ADDRINUSE error.
1104 laddr = inp->inp_laddr;
1105 lport = inp->inp_lport;
1106 error = in_pcbconnect_setup(inp, nam, &laddr.s_addr, &lport,
1107 &inp->inp_faddr.s_addr, &inp->inp_fport, &oinp, td->td_ucred);
1108 if (error && oinp == NULL)
1112 inp->inp_laddr = laddr;
1116 * Compute window scaling to request:
1117 * Scale to fit into sweet spot. See tcp_syncache.c.
1118 * XXX: This should move to tcp_output().
1119 * XXX: This should be based on the actual MSS.
1121 while (tp->request_r_scale < TCP_MAX_WINSHIFT &&
1122 (0x1 << tp->request_r_scale) < tcp_minmss)
1123 tp->request_r_scale++;
1126 tcpstat.tcps_connattempt++;
1127 tp->t_state = TCPS_SYN_SENT;
1128 tcp_timer_activate(tp, TT_KEEP, tcp_keepinit);
1129 tp->iss = tcp_new_isn(tp);
1130 tp->t_bw_rtseq = tp->iss;
1131 tcp_sendseqinit(tp);
1138 tcp6_connect(struct tcpcb *tp, struct sockaddr *nam, struct thread *td)
1140 struct inpcb *inp = tp->t_inpcb, *oinp;
1141 struct socket *so = inp->inp_socket;
1142 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)nam;
1143 struct in6_addr *addr6;
1146 INP_INFO_WLOCK_ASSERT(&tcbinfo);
1147 INP_LOCK_ASSERT(inp);
1149 if (inp->inp_lport == 0) {
1150 error = in6_pcbbind(inp, (struct sockaddr *)0, td->td_ucred);
1156 * Cannot simply call in_pcbconnect, because there might be an
1157 * earlier incarnation of this same connection still in
1158 * TIME_WAIT state, creating an ADDRINUSE error.
1159 * in6_pcbladdr() also handles scope zone IDs.
1161 error = in6_pcbladdr(inp, nam, &addr6);
1164 oinp = in6_pcblookup_hash(inp->inp_pcbinfo,
1165 &sin6->sin6_addr, sin6->sin6_port,
1166 IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_laddr)
1169 inp->inp_lport, 0, NULL);
1172 if (IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_laddr))
1173 inp->in6p_laddr = *addr6;
1174 inp->in6p_faddr = sin6->sin6_addr;
1175 inp->inp_fport = sin6->sin6_port;
1176 /* update flowinfo - draft-itojun-ipv6-flowlabel-api-00 */
1177 inp->in6p_flowinfo &= ~IPV6_FLOWLABEL_MASK;
1178 if (inp->in6p_flags & IN6P_AUTOFLOWLABEL)
1179 inp->in6p_flowinfo |=
1180 (htonl(ip6_randomflowlabel()) & IPV6_FLOWLABEL_MASK);
1183 /* Compute window scaling to request. */
1184 while (tp->request_r_scale < TCP_MAX_WINSHIFT &&
1185 (TCP_MAXWIN << tp->request_r_scale) < so->so_rcv.sb_hiwat)
1186 tp->request_r_scale++;
1189 tcpstat.tcps_connattempt++;
1190 tp->t_state = TCPS_SYN_SENT;
1191 tcp_timer_activate(tp, TT_KEEP, tcp_keepinit);
1192 tp->iss = tcp_new_isn(tp);
1193 tp->t_bw_rtseq = tp->iss;
1194 tcp_sendseqinit(tp);
1201 * Export TCP internal state information via a struct tcp_info, based on the
1202 * Linux 2.6 API. Not ABI compatible as our constants are mapped differently
1203 * (TCP state machine, etc). We export all information using FreeBSD-native
1204 * constants -- for example, the numeric values for tcpi_state will differ
1208 tcp_fill_info(struct tcpcb *tp, struct tcp_info *ti)
1211 INP_LOCK_ASSERT(tp->t_inpcb);
1212 bzero(ti, sizeof(*ti));
1214 ti->tcpi_state = tp->t_state;
1215 if ((tp->t_flags & TF_REQ_TSTMP) && (tp->t_flags & TF_RCVD_TSTMP))
1216 ti->tcpi_options |= TCPI_OPT_TIMESTAMPS;
1217 if (tp->t_flags & TF_SACK_PERMIT)
1218 ti->tcpi_options |= TCPI_OPT_SACK;
1219 if ((tp->t_flags & TF_REQ_SCALE) && (tp->t_flags & TF_RCVD_SCALE)) {
1220 ti->tcpi_options |= TCPI_OPT_WSCALE;
1221 ti->tcpi_snd_wscale = tp->snd_scale;
1222 ti->tcpi_rcv_wscale = tp->rcv_scale;
1225 ti->tcpi_rtt = ((u_int64_t)tp->t_srtt * tick) >> TCP_RTT_SHIFT;
1226 ti->tcpi_rttvar = ((u_int64_t)tp->t_rttvar * tick) >> TCP_RTTVAR_SHIFT;
1228 ti->tcpi_snd_ssthresh = tp->snd_ssthresh;
1229 ti->tcpi_snd_cwnd = tp->snd_cwnd;
1232 * FreeBSD-specific extension fields for tcp_info.
1234 ti->tcpi_rcv_space = tp->rcv_wnd;
1235 ti->tcpi_snd_wnd = tp->snd_wnd;
1236 ti->tcpi_snd_bwnd = tp->snd_bwnd;
1240 * The new sockopt interface makes it possible for us to block in the
1241 * copyin/out step (if we take a page fault). Taking a page fault at
1242 * splnet() is probably a Bad Thing. (Since sockets and pcbs both now
1243 * use TSM, there probably isn't any need for this function to run at
1244 * splnet() any more. This needs more examination.)
1246 * XXXRW: The locking here is wrong; we may take a page fault while holding
1250 tcp_ctloutput(struct socket *so, struct sockopt *sopt)
1252 int error, opt, optval;
1258 inp = sotoinpcb(so);
1259 KASSERT(inp != NULL, ("tcp_ctloutput: inp == NULL"));
1261 if (sopt->sopt_level != IPPROTO_TCP) {
1264 if (INP_CHECK_SOCKAF(so, AF_INET6))
1265 error = ip6_ctloutput(so, sopt);
1268 error = ip_ctloutput(so, sopt);
1271 if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) {
1275 tp = intotcpcb(inp);
1277 switch (sopt->sopt_dir) {
1279 switch (sopt->sopt_name) {
1280 #ifdef TCP_SIGNATURE
1282 error = sooptcopyin(sopt, &optval, sizeof optval,
1288 tp->t_flags |= TF_SIGNATURE;
1290 tp->t_flags &= ~TF_SIGNATURE;
1292 #endif /* TCP_SIGNATURE */
1295 error = sooptcopyin(sopt, &optval, sizeof optval,
1300 switch (sopt->sopt_name) {
1308 opt = 0; /* dead code to fool gcc */
1315 tp->t_flags &= ~opt;
1319 error = sooptcopyin(sopt, &optval, sizeof optval,
1325 tp->t_flags |= TF_NOPUSH;
1327 tp->t_flags &= ~TF_NOPUSH;
1328 error = tcp_output(tp);
1333 error = sooptcopyin(sopt, &optval, sizeof optval,
1338 if (optval > 0 && optval <= tp->t_maxseg &&
1339 optval + 40 >= tcp_minmss)
1340 tp->t_maxseg = optval;
1350 error = ENOPROTOOPT;
1356 switch (sopt->sopt_name) {
1357 #ifdef TCP_SIGNATURE
1359 optval = (tp->t_flags & TF_SIGNATURE) ? 1 : 0;
1360 error = sooptcopyout(sopt, &optval, sizeof optval);
1364 optval = tp->t_flags & TF_NODELAY;
1365 error = sooptcopyout(sopt, &optval, sizeof optval);
1368 optval = tp->t_maxseg;
1369 error = sooptcopyout(sopt, &optval, sizeof optval);
1372 optval = tp->t_flags & TF_NOOPT;
1373 error = sooptcopyout(sopt, &optval, sizeof optval);
1376 optval = tp->t_flags & TF_NOPUSH;
1377 error = sooptcopyout(sopt, &optval, sizeof optval);
1380 tcp_fill_info(tp, &ti);
1381 error = sooptcopyout(sopt, &ti, sizeof ti);
1384 error = ENOPROTOOPT;
1395 * tcp_sendspace and tcp_recvspace are the default send and receive window
1396 * sizes, respectively. These are obsolescent (this information should
1397 * be set by the route).
1399 u_long tcp_sendspace = 1024*32;
1400 SYSCTL_ULONG(_net_inet_tcp, TCPCTL_SENDSPACE, sendspace, CTLFLAG_RW,
1401 &tcp_sendspace , 0, "Maximum outgoing TCP datagram size");
1402 u_long tcp_recvspace = 1024*64;
1403 SYSCTL_ULONG(_net_inet_tcp, TCPCTL_RECVSPACE, recvspace, CTLFLAG_RW,
1404 &tcp_recvspace , 0, "Maximum incoming TCP datagram size");
1407 * Attach TCP protocol to socket, allocating
1408 * internet protocol control block, tcp control block,
1409 * bufer space, and entering LISTEN state if to accept connections.
1412 tcp_attach(struct socket *so)
1418 int isipv6 = INP_CHECK_SOCKAF(so, AF_INET6) != 0;
1421 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
1422 error = soreserve(so, tcp_sendspace, tcp_recvspace);
1426 so->so_rcv.sb_flags |= SB_AUTOSIZE;
1427 so->so_snd.sb_flags |= SB_AUTOSIZE;
1428 INP_INFO_WLOCK(&tcbinfo);
1429 error = in_pcballoc(so, &tcbinfo);
1431 INP_INFO_WUNLOCK(&tcbinfo);
1434 inp = sotoinpcb(so);
1437 inp->inp_vflag |= INP_IPV6;
1438 inp->in6p_hops = -1; /* use kernel default */
1442 inp->inp_vflag |= INP_IPV4;
1443 tp = tcp_newtcpcb(inp);
1456 INP_INFO_WUNLOCK(&tcbinfo);
1459 tp->t_state = TCPS_CLOSED;
1461 INP_INFO_WUNLOCK(&tcbinfo);
1466 * Initiate (or continue) disconnect.
1467 * If embryonic state, just send reset (once).
1468 * If in ``let data drain'' option and linger null, just drop.
1469 * Otherwise (hard), mark socket disconnecting and drop
1470 * current input data; switch states based on user close, and
1471 * send segment to peer (with FIN).
1474 tcp_disconnect(struct tcpcb *tp)
1476 struct inpcb *inp = tp->t_inpcb;
1477 struct socket *so = inp->inp_socket;
1479 INP_INFO_WLOCK_ASSERT(&tcbinfo);
1480 INP_LOCK_ASSERT(inp);
1483 * Neither tcp_close() nor tcp_drop() should return NULL, as the
1484 * socket is still open.
1486 if (tp->t_state < TCPS_ESTABLISHED) {
1489 ("tcp_disconnect: tcp_close() returned NULL"));
1490 } else if ((so->so_options & SO_LINGER) && so->so_linger == 0) {
1491 tp = tcp_drop(tp, 0);
1493 ("tcp_disconnect: tcp_drop() returned NULL"));
1495 soisdisconnecting(so);
1496 sbflush(&so->so_rcv);
1498 if (!(inp->inp_vflag & INP_DROPPED))
1504 * User issued close, and wish to trail through shutdown states:
1505 * if never received SYN, just forget it. If got a SYN from peer,
1506 * but haven't sent FIN, then go to FIN_WAIT_1 state to send peer a FIN.
1507 * If already got a FIN from peer, then almost done; go to LAST_ACK
1508 * state. In all other cases, have already sent FIN to peer (e.g.
1509 * after PRU_SHUTDOWN), and just have to play tedious game waiting
1510 * for peer to send FIN or not respond to keep-alives, etc.
1511 * We can let the user exit from the close as soon as the FIN is acked.
1514 tcp_usrclosed(struct tcpcb *tp)
1517 INP_INFO_WLOCK_ASSERT(&tcbinfo);
1518 INP_LOCK_ASSERT(tp->t_inpcb);
1520 switch (tp->t_state) {
1523 tp->t_state = TCPS_CLOSED;
1526 * tcp_close() should never return NULL here as the socket is
1530 ("tcp_usrclosed: tcp_close() returned NULL"));
1534 case TCPS_SYN_RECEIVED:
1535 tp->t_flags |= TF_NEEDFIN;
1538 case TCPS_ESTABLISHED:
1539 tp->t_state = TCPS_FIN_WAIT_1;
1542 case TCPS_CLOSE_WAIT:
1543 tp->t_state = TCPS_LAST_ACK;
1546 if (tp->t_state >= TCPS_FIN_WAIT_2) {
1547 soisdisconnected(tp->t_inpcb->inp_socket);
1548 /* Prevent the connection hanging in FIN_WAIT_2 forever. */
1549 if (tp->t_state == TCPS_FIN_WAIT_2) {
1552 timeout = (tcp_fast_finwait2_recycle) ?
1553 tcp_finwait2_timeout : tcp_maxidle;
1554 tcp_timer_activate(tp, TT_2MSL, timeout);
1561 db_print_indent(int indent)
1565 for (i = 0; i < indent; i++)
1570 db_print_tstate(int t_state)
1575 db_printf("TCPS_CLOSED");
1579 db_printf("TCPS_LISTEN");
1583 db_printf("TCPS_SYN_SENT");
1586 case TCPS_SYN_RECEIVED:
1587 db_printf("TCPS_SYN_RECEIVED");
1590 case TCPS_ESTABLISHED:
1591 db_printf("TCPS_ESTABLISHED");
1594 case TCPS_CLOSE_WAIT:
1595 db_printf("TCPS_CLOSE_WAIT");
1598 case TCPS_FIN_WAIT_1:
1599 db_printf("TCPS_FIN_WAIT_1");
1603 db_printf("TCPS_CLOSING");
1607 db_printf("TCPS_LAST_ACK");
1610 case TCPS_FIN_WAIT_2:
1611 db_printf("TCPS_FIN_WAIT_2");
1614 case TCPS_TIME_WAIT:
1615 db_printf("TCPS_TIME_WAIT");
1619 db_printf("unknown");
1625 db_print_tflags(u_int t_flags)
1630 if (t_flags & TF_ACKNOW) {
1631 db_printf("%sTF_ACKNOW", comma ? ", " : "");
1634 if (t_flags & TF_DELACK) {
1635 db_printf("%sTF_DELACK", comma ? ", " : "");
1638 if (t_flags & TF_NODELAY) {
1639 db_printf("%sTF_NODELAY", comma ? ", " : "");
1642 if (t_flags & TF_NOOPT) {
1643 db_printf("%sTF_NOOPT", comma ? ", " : "");
1646 if (t_flags & TF_SENTFIN) {
1647 db_printf("%sTF_SENTFIN", comma ? ", " : "");
1650 if (t_flags & TF_REQ_SCALE) {
1651 db_printf("%sTF_REQ_SCALE", comma ? ", " : "");
1654 if (t_flags & TF_RCVD_SCALE) {
1655 db_printf("%sTF_RECVD_SCALE", comma ? ", " : "");
1658 if (t_flags & TF_REQ_TSTMP) {
1659 db_printf("%sTF_REQ_TSTMP", comma ? ", " : "");
1662 if (t_flags & TF_RCVD_TSTMP) {
1663 db_printf("%sTF_RCVD_TSTMP", comma ? ", " : "");
1666 if (t_flags & TF_SACK_PERMIT) {
1667 db_printf("%sTF_SACK_PERMIT", comma ? ", " : "");
1670 if (t_flags & TF_NEEDSYN) {
1671 db_printf("%sTF_NEEDSYN", comma ? ", " : "");
1674 if (t_flags & TF_NEEDFIN) {
1675 db_printf("%sTF_NEEDFIN", comma ? ", " : "");
1678 if (t_flags & TF_NOPUSH) {
1679 db_printf("%sTF_NOPUSH", comma ? ", " : "");
1682 if (t_flags & TF_NOPUSH) {
1683 db_printf("%sTF_NOPUSH", comma ? ", " : "");
1686 if (t_flags & TF_MORETOCOME) {
1687 db_printf("%sTF_MORETOCOME", comma ? ", " : "");
1690 if (t_flags & TF_LQ_OVERFLOW) {
1691 db_printf("%sTF_LQ_OVERFLOW", comma ? ", " : "");
1694 if (t_flags & TF_LASTIDLE) {
1695 db_printf("%sTF_LASTIDLE", comma ? ", " : "");
1698 if (t_flags & TF_RXWIN0SENT) {
1699 db_printf("%sTF_RXWIN0SENT", comma ? ", " : "");
1702 if (t_flags & TF_FASTRECOVERY) {
1703 db_printf("%sTF_FASTRECOVERY", comma ? ", " : "");
1706 if (t_flags & TF_WASFRECOVERY) {
1707 db_printf("%sTF_WASFRECOVERY", comma ? ", " : "");
1710 if (t_flags & TF_SIGNATURE) {
1711 db_printf("%sTF_SIGNATURE", comma ? ", " : "");
1714 if (t_flags & TF_FORCEDATA) {
1715 db_printf("%sTF_FORCEDATA", comma ? ", " : "");
1718 if (t_flags & TF_TSO) {
1719 db_printf("%sTF_TSO", comma ? ", " : "");
1725 db_print_toobflags(char t_oobflags)
1730 if (t_oobflags & TCPOOB_HAVEDATA) {
1731 db_printf("%sTCPOOB_HAVEDATA", comma ? ", " : "");
1734 if (t_oobflags & TCPOOB_HADDATA) {
1735 db_printf("%sTCPOOB_HADDATA", comma ? ", " : "");
1741 db_print_tcpcb(struct tcpcb *tp, const char *name, int indent)
1744 db_print_indent(indent);
1745 db_printf("%s at %p\n", name, tp);
1749 db_print_indent(indent);
1750 db_printf("t_segq first: %p t_segqlen: %d t_dupacks: %d\n",
1751 LIST_FIRST(&tp->t_segq), tp->t_segqlen, tp->t_dupacks);
1753 db_print_indent(indent);
1754 db_printf("t_inpcb: %p t_timers: %p tt_active: %x\n",
1755 tp->t_inpcb, tp->t_timers, tp->t_timers->tt_active);
1757 db_print_indent(indent);
1758 db_printf("tt_delack: %i tt_rexmt: %i tt_keep: %i "
1759 "tt_persist: %i tt_2msl: %i\n",
1760 tp->t_timers->tt_delack, tp->t_timers->tt_rexmt,
1761 tp->t_timers->tt_keep, tp->t_timers->tt_persist,
1762 tp->t_timers->tt_2msl);
1764 db_print_indent(indent);
1765 db_printf("t_state: %d (", tp->t_state);
1766 db_print_tstate(tp->t_state);
1769 db_print_indent(indent);
1770 db_printf("t_flags: 0x%x (", tp->t_flags);
1771 db_print_tflags(tp->t_flags);
1774 db_print_indent(indent);
1775 db_printf("snd_una: 0x%08x snd_max: 0x%08x snd_nxt: x0%08x\n",
1776 tp->snd_una, tp->snd_max, tp->snd_nxt);
1778 db_print_indent(indent);
1779 db_printf("snd_up: 0x%08x snd_wl1: 0x%08x snd_wl2: 0x%08x\n",
1780 tp->snd_up, tp->snd_wl1, tp->snd_wl2);
1782 db_print_indent(indent);
1783 db_printf("iss: 0x%08x irs: 0x%08x rcv_nxt: 0x%08x\n",
1784 tp->iss, tp->irs, tp->rcv_nxt);
1786 db_print_indent(indent);
1787 db_printf("rcv_adv: 0x%08x rcv_wnd: %lu rcv_up: 0x%08x\n",
1788 tp->rcv_adv, tp->rcv_wnd, tp->rcv_up);
1790 db_print_indent(indent);
1791 db_printf("snd_wnd: %lu snd_cwnd: %lu snd_bwnd: %lu\n",
1792 tp->snd_wnd, tp->snd_cwnd, tp->snd_bwnd);
1794 db_print_indent(indent);
1795 db_printf("snd_ssthresh: %lu snd_bandwidth: %lu snd_recover: "
1796 "0x%08x\n", tp->snd_ssthresh, tp->snd_bandwidth,
1799 db_print_indent(indent);
1800 db_printf("t_maxopd: %u t_rcvtime: %lu t_startime: %lu\n",
1801 tp->t_maxopd, tp->t_rcvtime, tp->t_starttime);
1803 db_print_indent(indent);
1804 db_printf("t_rttime: %d t_rtsq: 0x%08x t_bw_rtttime: %d\n",
1805 tp->t_rtttime, tp->t_rtseq, tp->t_bw_rtttime);
1807 db_print_indent(indent);
1808 db_printf("t_bw_rtseq: 0x%08x t_rxtcur: %d t_maxseg: %u "
1809 "t_srtt: %d\n", tp->t_bw_rtseq, tp->t_rxtcur, tp->t_maxseg,
1812 db_print_indent(indent);
1813 db_printf("t_rttvar: %d t_rxtshift: %d t_rttmin: %u "
1814 "t_rttbest: %u\n", tp->t_rttvar, tp->t_rxtshift, tp->t_rttmin,
1817 db_print_indent(indent);
1818 db_printf("t_rttupdated: %lu max_sndwnd: %lu t_softerror: %d\n",
1819 tp->t_rttupdated, tp->max_sndwnd, tp->t_softerror);
1821 db_print_indent(indent);
1822 db_printf("t_oobflags: 0x%x (", tp->t_oobflags);
1823 db_print_toobflags(tp->t_oobflags);
1824 db_printf(") t_iobc: 0x%02x\n", tp->t_iobc);
1826 db_print_indent(indent);
1827 db_printf("snd_scale: %u rcv_scale: %u request_r_scale: %u\n",
1828 tp->snd_scale, tp->rcv_scale, tp->request_r_scale);
1830 db_print_indent(indent);
1831 db_printf("ts_recent: %u ts_recent_age: %lu\n",
1832 tp->ts_recent, tp->ts_recent_age);
1834 db_print_indent(indent);
1835 db_printf("ts_offset: %u last_ack_sent: 0x%08x snd_cwnd_prev: "
1836 "%lu\n", tp->ts_offset, tp->last_ack_sent, tp->snd_cwnd_prev);
1838 db_print_indent(indent);
1839 db_printf("snd_ssthresh_prev: %lu snd_recover_prev: 0x%08x "
1840 "t_badrxtwin: %lu\n", tp->snd_ssthresh_prev,
1841 tp->snd_recover_prev, tp->t_badrxtwin);
1843 db_print_indent(indent);
1844 db_printf("snd_numholes: %d snd_holes first: %p\n",
1845 tp->snd_numholes, TAILQ_FIRST(&tp->snd_holes));
1847 db_print_indent(indent);
1848 db_printf("snd_fack: 0x%08x rcv_numsacks: %d sack_newdata: "
1849 "0x%08x\n", tp->snd_fack, tp->rcv_numsacks, tp->sack_newdata);
1851 /* Skip sackblks, sackhint. */
1853 db_print_indent(indent);
1854 db_printf("t_rttlow: %d rfbuf_ts: %u rfbuf_cnt: %d\n",
1855 tp->t_rttlow, tp->rfbuf_ts, tp->rfbuf_cnt);
1858 DB_SHOW_COMMAND(tcpcb, db_show_tcpcb)
1863 db_printf("usage: show tcpcb <addr>\n");
1866 tp = (struct tcpcb *)addr;
1868 db_print_tcpcb(tp, "tcpcb", 0);