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>
56 #include <sys/vimage.h>
63 #include <net/route.h>
65 #include <netinet/in.h>
66 #include <netinet/in_systm.h>
68 #include <netinet/ip6.h>
70 #include <netinet/in_pcb.h>
72 #include <netinet6/in6_pcb.h>
74 #include <netinet/in_var.h>
75 #include <netinet/ip_var.h>
77 #include <netinet6/ip6_var.h>
78 #include <netinet6/scope6_var.h>
80 #include <netinet/tcp.h>
81 #include <netinet/tcp_fsm.h>
82 #include <netinet/tcp_seq.h>
83 #include <netinet/tcp_timer.h>
84 #include <netinet/tcp_var.h>
85 #include <netinet/tcpip.h>
87 #include <netinet/tcp_debug.h>
89 #include <netinet/tcp_offload.h>
90 #include <netinet/vinet.h>
93 * TCP protocol interface to socket abstraction.
95 static int tcp_attach(struct socket *);
96 static int tcp_connect(struct tcpcb *, struct sockaddr *,
99 static int tcp6_connect(struct tcpcb *, struct sockaddr *,
102 static void tcp_disconnect(struct tcpcb *);
103 static void tcp_usrclosed(struct tcpcb *);
104 static void tcp_fill_info(struct tcpcb *, struct tcp_info *);
107 #define TCPDEBUG0 int ostate = 0
108 #define TCPDEBUG1() ostate = tp ? tp->t_state : 0
109 #define TCPDEBUG2(req) if (tp && (so->so_options & SO_DEBUG)) \
110 tcp_trace(TA_USER, ostate, tp, 0, 0, req)
114 #define TCPDEBUG2(req)
118 * TCP attaches to socket via pru_attach(), reserving space,
119 * and an internet control block.
122 tcp_usr_attach(struct socket *so, int proto, struct thread *td)
125 struct tcpcb *tp = NULL;
130 KASSERT(inp == NULL, ("tcp_usr_attach: inp != NULL"));
133 error = tcp_attach(so);
137 if ((so->so_options & SO_LINGER) && so->so_linger == 0)
138 so->so_linger = TCP_LINGERTIME;
143 TCPDEBUG2(PRU_ATTACH);
148 * tcp_detach is called when the socket layer loses its final reference
149 * to the socket, be it a file descriptor reference, a reference from TCP,
150 * etc. At this point, there is only one case in which we will keep around
151 * inpcb state: time wait.
153 * This function can probably be re-absorbed back into tcp_usr_detach() now
154 * that there is a single detach path.
157 tcp_detach(struct socket *so, struct inpcb *inp)
161 INIT_VNET_INET(so->so_vnet);
164 INP_INFO_WLOCK_ASSERT(&V_tcbinfo);
165 INP_WLOCK_ASSERT(inp);
167 KASSERT(so->so_pcb == inp, ("tcp_detach: so_pcb != inp"));
168 KASSERT(inp->inp_socket == so, ("tcp_detach: inp_socket != so"));
172 if (inp->inp_flags & INP_TIMEWAIT) {
174 * There are two cases to handle: one in which the time wait
175 * state is being discarded (INP_DROPPED), and one in which
176 * this connection will remain in timewait. In the former,
177 * it is time to discard all state (except tcptw, which has
178 * already been discarded by the timewait close code, which
179 * should be further up the call stack somewhere). In the
180 * latter case, we detach from the socket, but leave the pcb
181 * present until timewait ends.
183 * XXXRW: Would it be cleaner to free the tcptw here?
185 if (inp->inp_flags & INP_DROPPED) {
186 KASSERT(tp == NULL, ("tcp_detach: INP_TIMEWAIT && "
187 "INP_DROPPED && tp != NULL"));
196 * If the connection is not in timewait, we consider two
197 * two conditions: one in which no further processing is
198 * necessary (dropped || embryonic), and one in which TCP is
199 * not yet done, but no longer requires the socket, so the
200 * pcb will persist for the time being.
202 * XXXRW: Does the second case still occur?
204 if (inp->inp_flags & INP_DROPPED ||
205 tp->t_state < TCPS_SYN_SENT) {
215 * pru_detach() detaches the TCP protocol from the socket.
216 * If the protocol state is non-embryonic, then can't
217 * do this directly: have to initiate a pru_disconnect(),
218 * which may finish later; embryonic TCB's can just
222 tcp_usr_detach(struct socket *so)
224 INIT_VNET_INET(so->so_vnet);
228 KASSERT(inp != NULL, ("tcp_usr_detach: inp == NULL"));
229 INP_INFO_WLOCK(&V_tcbinfo);
231 KASSERT(inp->inp_socket != NULL,
232 ("tcp_usr_detach: inp_socket == NULL"));
234 INP_INFO_WUNLOCK(&V_tcbinfo);
238 * Give the socket an address.
241 tcp_usr_bind(struct socket *so, struct sockaddr *nam, struct thread *td)
243 INIT_VNET_INET(so->so_vnet);
246 struct tcpcb *tp = NULL;
247 struct sockaddr_in *sinp;
249 sinp = (struct sockaddr_in *)nam;
250 if (nam->sa_len != sizeof (*sinp))
253 * Must check for multicast addresses and disallow binding
256 if (sinp->sin_family == AF_INET &&
257 IN_MULTICAST(ntohl(sinp->sin_addr.s_addr)))
258 return (EAFNOSUPPORT);
261 INP_INFO_WLOCK(&V_tcbinfo);
263 KASSERT(inp != NULL, ("tcp_usr_bind: inp == NULL"));
265 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
271 error = in_pcbbind(inp, nam, td->td_ucred);
275 INP_INFO_WUNLOCK(&V_tcbinfo);
282 tcp6_usr_bind(struct socket *so, struct sockaddr *nam, struct thread *td)
284 INIT_VNET_INET(so->so_vnet);
287 struct tcpcb *tp = NULL;
288 struct sockaddr_in6 *sin6p;
290 sin6p = (struct sockaddr_in6 *)nam;
291 if (nam->sa_len != sizeof (*sin6p))
294 * Must check for multicast addresses and disallow binding
297 if (sin6p->sin6_family == AF_INET6 &&
298 IN6_IS_ADDR_MULTICAST(&sin6p->sin6_addr))
299 return (EAFNOSUPPORT);
302 INP_INFO_WLOCK(&V_tcbinfo);
304 KASSERT(inp != NULL, ("tcp6_usr_bind: inp == NULL"));
306 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
312 inp->inp_vflag &= ~INP_IPV4;
313 inp->inp_vflag |= INP_IPV6;
314 if ((inp->inp_flags & IN6P_IPV6_V6ONLY) == 0) {
315 if (IN6_IS_ADDR_UNSPECIFIED(&sin6p->sin6_addr))
316 inp->inp_vflag |= INP_IPV4;
317 else if (IN6_IS_ADDR_V4MAPPED(&sin6p->sin6_addr)) {
318 struct sockaddr_in sin;
320 in6_sin6_2_sin(&sin, sin6p);
321 inp->inp_vflag |= INP_IPV4;
322 inp->inp_vflag &= ~INP_IPV6;
323 error = in_pcbbind(inp, (struct sockaddr *)&sin,
328 error = in6_pcbbind(inp, nam, td->td_ucred);
332 INP_INFO_WUNLOCK(&V_tcbinfo);
338 * Prepare to accept connections.
341 tcp_usr_listen(struct socket *so, int backlog, struct thread *td)
343 INIT_VNET_INET(so->so_vnet);
346 struct tcpcb *tp = NULL;
349 INP_INFO_WLOCK(&V_tcbinfo);
351 KASSERT(inp != NULL, ("tcp_usr_listen: inp == NULL"));
353 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
360 error = solisten_proto_check(so);
361 if (error == 0 && inp->inp_lport == 0)
362 error = in_pcbbind(inp, (struct sockaddr *)0, td->td_ucred);
364 tp->t_state = TCPS_LISTEN;
365 solisten_proto(so, backlog);
366 tcp_offload_listen_open(tp);
371 TCPDEBUG2(PRU_LISTEN);
373 INP_INFO_WUNLOCK(&V_tcbinfo);
379 tcp6_usr_listen(struct socket *so, int backlog, struct thread *td)
381 INIT_VNET_INET(so->so_vnet);
384 struct tcpcb *tp = NULL;
387 INP_INFO_WLOCK(&V_tcbinfo);
389 KASSERT(inp != NULL, ("tcp6_usr_listen: inp == NULL"));
391 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
398 error = solisten_proto_check(so);
399 if (error == 0 && inp->inp_lport == 0) {
400 inp->inp_vflag &= ~INP_IPV4;
401 if ((inp->inp_flags & IN6P_IPV6_V6ONLY) == 0)
402 inp->inp_vflag |= INP_IPV4;
403 error = in6_pcbbind(inp, (struct sockaddr *)0, td->td_ucred);
406 tp->t_state = TCPS_LISTEN;
407 solisten_proto(so, backlog);
412 TCPDEBUG2(PRU_LISTEN);
414 INP_INFO_WUNLOCK(&V_tcbinfo);
420 * Initiate connection to peer.
421 * Create a template for use in transmissions on this connection.
422 * Enter SYN_SENT state, and mark socket as connecting.
423 * Start keep-alive timer, and seed output sequence space.
424 * Send initial segment on connection.
427 tcp_usr_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
429 INIT_VNET_INET(so->so_vnet);
432 struct tcpcb *tp = NULL;
433 struct sockaddr_in *sinp;
435 sinp = (struct sockaddr_in *)nam;
436 if (nam->sa_len != sizeof (*sinp))
439 * Must disallow TCP ``connections'' to multicast addresses.
441 if (sinp->sin_family == AF_INET
442 && IN_MULTICAST(ntohl(sinp->sin_addr.s_addr)))
443 return (EAFNOSUPPORT);
444 if ((error = prison_remote_ip4(td->td_ucred, &sinp->sin_addr)) != 0)
448 INP_INFO_WLOCK(&V_tcbinfo);
450 KASSERT(inp != NULL, ("tcp_usr_connect: inp == NULL"));
452 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
458 if ((error = tcp_connect(tp, nam, td)) != 0)
460 error = tcp_output_connect(so, nam);
462 TCPDEBUG2(PRU_CONNECT);
464 INP_INFO_WUNLOCK(&V_tcbinfo);
470 tcp6_usr_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
472 INIT_VNET_INET(so->so_vnet);
475 struct tcpcb *tp = NULL;
476 struct sockaddr_in6 *sin6p;
480 sin6p = (struct sockaddr_in6 *)nam;
481 if (nam->sa_len != sizeof (*sin6p))
484 * Must disallow TCP ``connections'' to multicast addresses.
486 if (sin6p->sin6_family == AF_INET6
487 && IN6_IS_ADDR_MULTICAST(&sin6p->sin6_addr))
488 return (EAFNOSUPPORT);
490 INP_INFO_WLOCK(&V_tcbinfo);
492 KASSERT(inp != NULL, ("tcp6_usr_connect: inp == NULL"));
494 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
500 if (IN6_IS_ADDR_V4MAPPED(&sin6p->sin6_addr)) {
501 struct sockaddr_in sin;
503 if ((inp->inp_flags & IN6P_IPV6_V6ONLY) != 0) {
508 in6_sin6_2_sin(&sin, sin6p);
509 inp->inp_vflag |= INP_IPV4;
510 inp->inp_vflag &= ~INP_IPV6;
511 if ((error = prison_remote_ip4(td->td_ucred,
512 &sin.sin_addr)) != 0)
514 if ((error = tcp_connect(tp, (struct sockaddr *)&sin, td)) != 0)
516 error = tcp_output_connect(so, nam);
519 inp->inp_vflag &= ~INP_IPV4;
520 inp->inp_vflag |= INP_IPV6;
521 inp->inp_inc.inc_flags |= INC_ISIPV6;
522 if ((error = prison_remote_ip6(td->td_ucred, &sin6p->sin6_addr)) != 0)
524 if ((error = tcp6_connect(tp, nam, td)) != 0)
526 error = tcp_output_connect(so, nam);
529 TCPDEBUG2(PRU_CONNECT);
531 INP_INFO_WUNLOCK(&V_tcbinfo);
537 * Initiate disconnect from peer.
538 * If connection never passed embryonic stage, just drop;
539 * else if don't need to let data drain, then can just drop anyways,
540 * else have to begin TCP shutdown process: mark socket disconnecting,
541 * drain unread data, state switch to reflect user close, and
542 * send segment (e.g. FIN) to peer. Socket will be really disconnected
543 * when peer sends FIN and acks ours.
545 * SHOULD IMPLEMENT LATER PRU_CONNECT VIA REALLOC TCPCB.
548 tcp_usr_disconnect(struct socket *so)
550 INIT_VNET_INET(so->so_vnet);
552 struct tcpcb *tp = NULL;
556 INP_INFO_WLOCK(&V_tcbinfo);
558 KASSERT(inp != NULL, ("tcp_usr_disconnect: inp == NULL"));
560 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
568 TCPDEBUG2(PRU_DISCONNECT);
570 INP_INFO_WUNLOCK(&V_tcbinfo);
575 * Accept a connection. Essentially all the work is
576 * done at higher levels; just return the address
577 * of the peer, storing through addr.
580 tcp_usr_accept(struct socket *so, struct sockaddr **nam)
582 INIT_VNET_INET(so->so_vnet);
584 struct inpcb *inp = NULL;
585 struct tcpcb *tp = NULL;
590 if (so->so_state & SS_ISDISCONNECTED)
591 return (ECONNABORTED);
594 KASSERT(inp != NULL, ("tcp_usr_accept: inp == NULL"));
595 INP_INFO_RLOCK(&V_tcbinfo);
597 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
598 error = ECONNABORTED;
605 * We inline in_getpeeraddr and COMMON_END here, so that we can
606 * copy the data of interest and defer the malloc until after we
609 port = inp->inp_fport;
610 addr = inp->inp_faddr;
613 TCPDEBUG2(PRU_ACCEPT);
615 INP_INFO_RUNLOCK(&V_tcbinfo);
617 *nam = in_sockaddr(port, &addr);
623 tcp6_usr_accept(struct socket *so, struct sockaddr **nam)
625 struct inpcb *inp = NULL;
627 struct tcpcb *tp = NULL;
629 struct in6_addr addr6;
634 if (so->so_state & SS_ISDISCONNECTED)
635 return (ECONNABORTED);
638 KASSERT(inp != NULL, ("tcp6_usr_accept: inp == NULL"));
640 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
641 error = ECONNABORTED;
648 * We inline in6_mapped_peeraddr and COMMON_END here, so that we can
649 * copy the data of interest and defer the malloc until after we
652 if (inp->inp_vflag & INP_IPV4) {
654 port = inp->inp_fport;
655 addr = inp->inp_faddr;
657 port = inp->inp_fport;
658 addr6 = inp->in6p_faddr;
662 TCPDEBUG2(PRU_ACCEPT);
666 *nam = in6_v4mapsin6_sockaddr(port, &addr);
668 *nam = in6_sockaddr(port, &addr6);
675 * Mark the connection as being incapable of further output.
678 tcp_usr_shutdown(struct socket *so)
680 INIT_VNET_INET(so->so_vnet);
683 struct tcpcb *tp = NULL;
686 INP_INFO_WLOCK(&V_tcbinfo);
688 KASSERT(inp != NULL, ("inp == NULL"));
690 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
698 if (!(inp->inp_flags & INP_DROPPED))
699 error = tcp_output_disconnect(tp);
702 TCPDEBUG2(PRU_SHUTDOWN);
704 INP_INFO_WUNLOCK(&V_tcbinfo);
710 * After a receive, possibly send window update to peer.
713 tcp_usr_rcvd(struct socket *so, int flags)
716 struct tcpcb *tp = NULL;
721 KASSERT(inp != NULL, ("tcp_usr_rcvd: inp == NULL"));
723 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
738 * Do a send by putting data in output queue and updating urgent
739 * marker if URG set. Possibly send more data. Unlike the other
740 * pru_*() routines, the mbuf chains are our responsibility. We
741 * must either enqueue them or free them. The other pru_* routines
742 * generally are caller-frees.
745 tcp_usr_send(struct socket *so, int flags, struct mbuf *m,
746 struct sockaddr *nam, struct mbuf *control, struct thread *td)
748 INIT_VNET_INET(so->so_vnet);
751 struct tcpcb *tp = NULL;
759 * We require the pcbinfo lock in two cases:
761 * (1) An implied connect is taking place, which can result in
762 * binding IPs and ports and hence modification of the pcb hash
765 * (2) PRUS_EOF is set, resulting in explicit close on the send.
767 if ((nam != NULL) || (flags & PRUS_EOF)) {
768 INP_INFO_WLOCK(&V_tcbinfo);
772 KASSERT(inp != NULL, ("tcp_usr_send: inp == NULL"));
774 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
783 isipv6 = nam && nam->sa_family == AF_INET6;
788 /* TCP doesn't do control messages (rights, creds, etc) */
789 if (control->m_len) {
796 m_freem(control); /* empty control, just free it */
798 if (!(flags & PRUS_OOB)) {
799 sbappendstream(&so->so_snd, m);
800 if (nam && tp->t_state < TCPS_SYN_SENT) {
802 * Do implied connect if not yet connected,
803 * initialize window to default value, and
804 * initialize maxseg/maxopd using peer's cached
807 INP_INFO_WLOCK_ASSERT(&V_tcbinfo);
810 error = tcp6_connect(tp, nam, td);
813 error = tcp_connect(tp, nam, td);
816 tp->snd_wnd = TTCP_CLIENT_SND_WND;
819 if (flags & PRUS_EOF) {
821 * Close the send side of the connection after
824 INP_INFO_WLOCK_ASSERT(&V_tcbinfo);
829 INP_INFO_WUNLOCK(&V_tcbinfo);
832 if (!(inp->inp_flags & INP_DROPPED)) {
833 if (flags & PRUS_MORETOCOME)
834 tp->t_flags |= TF_MORETOCOME;
835 error = tcp_output_send(tp);
836 if (flags & PRUS_MORETOCOME)
837 tp->t_flags &= ~TF_MORETOCOME;
841 * XXXRW: PRUS_EOF not implemented with PRUS_OOB?
843 SOCKBUF_LOCK(&so->so_snd);
844 if (sbspace(&so->so_snd) < -512) {
845 SOCKBUF_UNLOCK(&so->so_snd);
851 * According to RFC961 (Assigned Protocols),
852 * the urgent pointer points to the last octet
853 * of urgent data. We continue, however,
854 * to consider it to indicate the first octet
855 * of data past the urgent section.
856 * Otherwise, snd_up should be one lower.
858 sbappendstream_locked(&so->so_snd, m);
859 SOCKBUF_UNLOCK(&so->so_snd);
860 if (nam && tp->t_state < TCPS_SYN_SENT) {
862 * Do implied connect if not yet connected,
863 * initialize window to default value, and
864 * initialize maxseg/maxopd using peer's cached
867 INP_INFO_WLOCK_ASSERT(&V_tcbinfo);
870 error = tcp6_connect(tp, nam, td);
873 error = tcp_connect(tp, nam, td);
876 tp->snd_wnd = TTCP_CLIENT_SND_WND;
878 INP_INFO_WUNLOCK(&V_tcbinfo);
881 INP_INFO_WUNLOCK(&V_tcbinfo);
884 tp->snd_up = tp->snd_una + so->so_snd.sb_cc;
885 tp->t_flags |= TF_FORCEDATA;
886 error = tcp_output_send(tp);
887 tp->t_flags &= ~TF_FORCEDATA;
890 TCPDEBUG2((flags & PRUS_OOB) ? PRU_SENDOOB :
891 ((flags & PRUS_EOF) ? PRU_SEND_EOF : PRU_SEND));
894 INP_INFO_WUNLOCK(&V_tcbinfo);
899 * Abort the TCP. Drop the connection abruptly.
902 tcp_usr_abort(struct socket *so)
904 INIT_VNET_INET(so->so_vnet);
906 struct tcpcb *tp = NULL;
910 KASSERT(inp != NULL, ("tcp_usr_abort: inp == NULL"));
912 INP_INFO_WLOCK(&V_tcbinfo);
914 KASSERT(inp->inp_socket != NULL,
915 ("tcp_usr_abort: inp_socket == NULL"));
918 * If we still have full TCP state, and we're not dropped, drop.
920 if (!(inp->inp_flags & INP_TIMEWAIT) &&
921 !(inp->inp_flags & INP_DROPPED)) {
924 tcp_drop(tp, ECONNABORTED);
925 TCPDEBUG2(PRU_ABORT);
927 if (!(inp->inp_flags & INP_DROPPED)) {
929 so->so_state |= SS_PROTOREF;
931 inp->inp_flags |= INP_SOCKREF;
934 INP_INFO_WUNLOCK(&V_tcbinfo);
938 * TCP socket is closed. Start friendly disconnect.
941 tcp_usr_close(struct socket *so)
943 INIT_VNET_INET(so->so_vnet);
945 struct tcpcb *tp = NULL;
949 KASSERT(inp != NULL, ("tcp_usr_close: inp == NULL"));
951 INP_INFO_WLOCK(&V_tcbinfo);
953 KASSERT(inp->inp_socket != NULL,
954 ("tcp_usr_close: inp_socket == NULL"));
957 * If we still have full TCP state, and we're not dropped, initiate
960 if (!(inp->inp_flags & INP_TIMEWAIT) &&
961 !(inp->inp_flags & INP_DROPPED)) {
965 TCPDEBUG2(PRU_CLOSE);
967 if (!(inp->inp_flags & INP_DROPPED)) {
969 so->so_state |= SS_PROTOREF;
971 inp->inp_flags |= INP_SOCKREF;
974 INP_INFO_WUNLOCK(&V_tcbinfo);
978 * Receive out-of-band data.
981 tcp_usr_rcvoob(struct socket *so, struct mbuf *m, int flags)
985 struct tcpcb *tp = NULL;
989 KASSERT(inp != NULL, ("tcp_usr_rcvoob: inp == NULL"));
991 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
997 if ((so->so_oobmark == 0 &&
998 (so->so_rcv.sb_state & SBS_RCVATMARK) == 0) ||
999 so->so_options & SO_OOBINLINE ||
1000 tp->t_oobflags & TCPOOB_HADDATA) {
1004 if ((tp->t_oobflags & TCPOOB_HAVEDATA) == 0) {
1005 error = EWOULDBLOCK;
1009 *mtod(m, caddr_t) = tp->t_iobc;
1010 if ((flags & MSG_PEEK) == 0)
1011 tp->t_oobflags ^= (TCPOOB_HAVEDATA | TCPOOB_HADDATA);
1014 TCPDEBUG2(PRU_RCVOOB);
1019 struct pr_usrreqs tcp_usrreqs = {
1020 .pru_abort = tcp_usr_abort,
1021 .pru_accept = tcp_usr_accept,
1022 .pru_attach = tcp_usr_attach,
1023 .pru_bind = tcp_usr_bind,
1024 .pru_connect = tcp_usr_connect,
1025 .pru_control = in_control,
1026 .pru_detach = tcp_usr_detach,
1027 .pru_disconnect = tcp_usr_disconnect,
1028 .pru_listen = tcp_usr_listen,
1029 .pru_peeraddr = in_getpeeraddr,
1030 .pru_rcvd = tcp_usr_rcvd,
1031 .pru_rcvoob = tcp_usr_rcvoob,
1032 .pru_send = tcp_usr_send,
1033 .pru_shutdown = tcp_usr_shutdown,
1034 .pru_sockaddr = in_getsockaddr,
1036 .pru_soreceive = soreceive_stream,
1038 .pru_sosetlabel = in_pcbsosetlabel,
1039 .pru_close = tcp_usr_close,
1043 struct pr_usrreqs tcp6_usrreqs = {
1044 .pru_abort = tcp_usr_abort,
1045 .pru_accept = tcp6_usr_accept,
1046 .pru_attach = tcp_usr_attach,
1047 .pru_bind = tcp6_usr_bind,
1048 .pru_connect = tcp6_usr_connect,
1049 .pru_control = in6_control,
1050 .pru_detach = tcp_usr_detach,
1051 .pru_disconnect = tcp_usr_disconnect,
1052 .pru_listen = tcp6_usr_listen,
1053 .pru_peeraddr = in6_mapped_peeraddr,
1054 .pru_rcvd = tcp_usr_rcvd,
1055 .pru_rcvoob = tcp_usr_rcvoob,
1056 .pru_send = tcp_usr_send,
1057 .pru_shutdown = tcp_usr_shutdown,
1058 .pru_sockaddr = in6_mapped_sockaddr,
1060 .pru_soreceive = soreceive_stream,
1062 .pru_sosetlabel = in_pcbsosetlabel,
1063 .pru_close = tcp_usr_close,
1068 * Common subroutine to open a TCP connection to remote host specified
1069 * by struct sockaddr_in in mbuf *nam. Call in_pcbbind to assign a local
1070 * port number if needed. Call in_pcbconnect_setup to do the routing and
1071 * to choose a local host address (interface). If there is an existing
1072 * incarnation of the same connection in TIME-WAIT state and if the remote
1073 * host was sending CC options and if the connection duration was < MSL, then
1074 * truncate the previous TIME-WAIT state and proceed.
1075 * Initialize connection parameters and enter SYN-SENT state.
1078 tcp_connect(struct tcpcb *tp, struct sockaddr *nam, struct thread *td)
1080 struct inpcb *inp = tp->t_inpcb, *oinp;
1081 struct socket *so = inp->inp_socket;
1082 INIT_VNET_INET(so->so_vnet);
1083 struct in_addr laddr;
1087 INP_INFO_WLOCK_ASSERT(&V_tcbinfo);
1088 INP_WLOCK_ASSERT(inp);
1090 if (inp->inp_lport == 0) {
1091 error = in_pcbbind(inp, (struct sockaddr *)0, td->td_ucred);
1097 * Cannot simply call in_pcbconnect, because there might be an
1098 * earlier incarnation of this same connection still in
1099 * TIME_WAIT state, creating an ADDRINUSE error.
1101 laddr = inp->inp_laddr;
1102 lport = inp->inp_lport;
1103 error = in_pcbconnect_setup(inp, nam, &laddr.s_addr, &lport,
1104 &inp->inp_faddr.s_addr, &inp->inp_fport, &oinp, td->td_ucred);
1105 if (error && oinp == NULL)
1109 inp->inp_laddr = laddr;
1113 * Compute window scaling to request:
1114 * Scale to fit into sweet spot. See tcp_syncache.c.
1115 * XXX: This should move to tcp_output().
1117 while (tp->request_r_scale < TCP_MAX_WINSHIFT &&
1118 (TCP_MAXWIN << tp->request_r_scale) < sb_max)
1119 tp->request_r_scale++;
1122 TCPSTAT_INC(tcps_connattempt);
1123 tp->t_state = TCPS_SYN_SENT;
1124 tcp_timer_activate(tp, TT_KEEP, tcp_keepinit);
1125 tp->iss = tcp_new_isn(tp);
1126 tp->t_bw_rtseq = tp->iss;
1127 tcp_sendseqinit(tp);
1134 tcp6_connect(struct tcpcb *tp, struct sockaddr *nam, struct thread *td)
1136 struct inpcb *inp = tp->t_inpcb, *oinp;
1137 struct socket *so = inp->inp_socket;
1138 INIT_VNET_INET(so->so_vnet);
1139 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)nam;
1140 struct in6_addr addr6;
1143 INP_INFO_WLOCK_ASSERT(&V_tcbinfo);
1144 INP_WLOCK_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->inp_flow &= ~IPV6_FLOWLABEL_MASK;
1175 if (inp->inp_flags & IN6P_AUTOFLOWLABEL)
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) < sb_max)
1183 tp->request_r_scale++;
1186 TCPSTAT_INC(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_WLOCK_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_rcv_nxt = tp->rcv_nxt;
1233 ti->tcpi_snd_wnd = tp->snd_wnd;
1234 ti->tcpi_snd_bwnd = tp->snd_bwnd;
1235 ti->tcpi_snd_nxt = tp->snd_nxt;
1236 ti->__tcpi_snd_mss = tp->t_maxseg;
1237 ti->__tcpi_rcv_mss = tp->t_maxseg;
1238 if (tp->t_flags & TF_TOE)
1239 ti->tcpi_options |= TCPI_OPT_TOE;
1243 * tcp_ctloutput() must drop the inpcb lock before performing copyin on
1244 * socket option arguments. When it re-acquires the lock after the copy, it
1245 * has to revalidate that the connection is still valid for the socket
1248 #define INP_WLOCK_RECHECK(inp) do { \
1250 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) { \
1252 return (ECONNRESET); \
1254 tp = intotcpcb(inp); \
1258 tcp_ctloutput(struct socket *so, struct sockopt *sopt)
1260 INIT_VNET_INET(so->so_vnet);
1261 int error, opt, optval;
1267 inp = sotoinpcb(so);
1268 KASSERT(inp != NULL, ("tcp_ctloutput: inp == NULL"));
1270 if (sopt->sopt_level != IPPROTO_TCP) {
1272 if (inp->inp_vflag & INP_IPV6PROTO) {
1274 error = ip6_ctloutput(so, sopt);
1278 error = ip_ctloutput(so, sopt);
1284 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
1286 return (ECONNRESET);
1289 switch (sopt->sopt_dir) {
1291 switch (sopt->sopt_name) {
1292 #ifdef TCP_SIGNATURE
1295 error = sooptcopyin(sopt, &optval, sizeof optval,
1300 INP_WLOCK_RECHECK(inp);
1302 tp->t_flags |= TF_SIGNATURE;
1304 tp->t_flags &= ~TF_SIGNATURE;
1307 #endif /* TCP_SIGNATURE */
1311 error = sooptcopyin(sopt, &optval, sizeof optval,
1316 INP_WLOCK_RECHECK(inp);
1317 switch (sopt->sopt_name) {
1325 opt = 0; /* dead code to fool gcc */
1332 tp->t_flags &= ~opt;
1338 error = sooptcopyin(sopt, &optval, sizeof optval,
1343 INP_WLOCK_RECHECK(inp);
1345 tp->t_flags |= TF_NOPUSH;
1347 tp->t_flags &= ~TF_NOPUSH;
1348 error = tcp_output(tp);
1355 error = sooptcopyin(sopt, &optval, sizeof optval,
1360 INP_WLOCK_RECHECK(inp);
1361 if (optval > 0 && optval <= tp->t_maxseg &&
1362 optval + 40 >= V_tcp_minmss)
1363 tp->t_maxseg = optval;
1376 error = ENOPROTOOPT;
1382 tp = intotcpcb(inp);
1383 switch (sopt->sopt_name) {
1384 #ifdef TCP_SIGNATURE
1386 optval = (tp->t_flags & TF_SIGNATURE) ? 1 : 0;
1388 error = sooptcopyout(sopt, &optval, sizeof optval);
1393 optval = tp->t_flags & TF_NODELAY;
1395 error = sooptcopyout(sopt, &optval, sizeof optval);
1398 optval = tp->t_maxseg;
1400 error = sooptcopyout(sopt, &optval, sizeof optval);
1403 optval = tp->t_flags & TF_NOOPT;
1405 error = sooptcopyout(sopt, &optval, sizeof optval);
1408 optval = tp->t_flags & TF_NOPUSH;
1410 error = sooptcopyout(sopt, &optval, sizeof optval);
1413 tcp_fill_info(tp, &ti);
1415 error = sooptcopyout(sopt, &ti, sizeof ti);
1419 error = ENOPROTOOPT;
1426 #undef INP_WLOCK_RECHECK
1429 * tcp_sendspace and tcp_recvspace are the default send and receive window
1430 * sizes, respectively. These are obsolescent (this information should
1431 * be set by the route).
1433 u_long tcp_sendspace = 1024*32;
1434 SYSCTL_ULONG(_net_inet_tcp, TCPCTL_SENDSPACE, sendspace, CTLFLAG_RW,
1435 &tcp_sendspace , 0, "Maximum outgoing TCP datagram size");
1436 u_long tcp_recvspace = 1024*64;
1437 SYSCTL_ULONG(_net_inet_tcp, TCPCTL_RECVSPACE, recvspace, CTLFLAG_RW,
1438 &tcp_recvspace , 0, "Maximum incoming TCP datagram size");
1441 * Attach TCP protocol to socket, allocating
1442 * internet protocol control block, tcp control block,
1443 * bufer space, and entering LISTEN state if to accept connections.
1446 tcp_attach(struct socket *so)
1448 INIT_VNET_INET(so->so_vnet);
1453 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
1454 error = soreserve(so, tcp_sendspace, tcp_recvspace);
1458 so->so_rcv.sb_flags |= SB_AUTOSIZE;
1459 so->so_snd.sb_flags |= SB_AUTOSIZE;
1460 INP_INFO_WLOCK(&V_tcbinfo);
1461 error = in_pcballoc(so, &V_tcbinfo);
1463 INP_INFO_WUNLOCK(&V_tcbinfo);
1466 inp = sotoinpcb(so);
1468 if (inp->inp_vflag & INP_IPV6PROTO) {
1469 inp->inp_vflag |= INP_IPV6;
1470 inp->in6p_hops = -1; /* use kernel default */
1474 inp->inp_vflag |= INP_IPV4;
1475 tp = tcp_newtcpcb(inp);
1479 INP_INFO_WUNLOCK(&V_tcbinfo);
1482 tp->t_state = TCPS_CLOSED;
1484 INP_INFO_WUNLOCK(&V_tcbinfo);
1489 * Initiate (or continue) disconnect.
1490 * If embryonic state, just send reset (once).
1491 * If in ``let data drain'' option and linger null, just drop.
1492 * Otherwise (hard), mark socket disconnecting and drop
1493 * current input data; switch states based on user close, and
1494 * send segment to peer (with FIN).
1497 tcp_disconnect(struct tcpcb *tp)
1499 struct inpcb *inp = tp->t_inpcb;
1500 struct socket *so = inp->inp_socket;
1502 INIT_VNET_INET(so->so_vnet);
1505 INP_INFO_WLOCK_ASSERT(&V_tcbinfo);
1506 INP_WLOCK_ASSERT(inp);
1509 * Neither tcp_close() nor tcp_drop() should return NULL, as the
1510 * socket is still open.
1512 if (tp->t_state < TCPS_ESTABLISHED) {
1515 ("tcp_disconnect: tcp_close() returned NULL"));
1516 } else if ((so->so_options & SO_LINGER) && so->so_linger == 0) {
1517 tp = tcp_drop(tp, 0);
1519 ("tcp_disconnect: tcp_drop() returned NULL"));
1521 soisdisconnecting(so);
1522 sbflush(&so->so_rcv);
1524 if (!(inp->inp_flags & INP_DROPPED))
1525 tcp_output_disconnect(tp);
1530 * User issued close, and wish to trail through shutdown states:
1531 * if never received SYN, just forget it. If got a SYN from peer,
1532 * but haven't sent FIN, then go to FIN_WAIT_1 state to send peer a FIN.
1533 * If already got a FIN from peer, then almost done; go to LAST_ACK
1534 * state. In all other cases, have already sent FIN to peer (e.g.
1535 * after PRU_SHUTDOWN), and just have to play tedious game waiting
1536 * for peer to send FIN or not respond to keep-alives, etc.
1537 * We can let the user exit from the close as soon as the FIN is acked.
1540 tcp_usrclosed(struct tcpcb *tp)
1543 INIT_VNET_INET(tp->t_inpcb->inp_vnet);
1546 INP_INFO_WLOCK_ASSERT(&V_tcbinfo);
1547 INP_WLOCK_ASSERT(tp->t_inpcb);
1549 switch (tp->t_state) {
1551 tcp_offload_listen_close(tp);
1554 tp->t_state = TCPS_CLOSED;
1557 * tcp_close() should never return NULL here as the socket is
1561 ("tcp_usrclosed: tcp_close() returned NULL"));
1565 case TCPS_SYN_RECEIVED:
1566 tp->t_flags |= TF_NEEDFIN;
1569 case TCPS_ESTABLISHED:
1570 tp->t_state = TCPS_FIN_WAIT_1;
1573 case TCPS_CLOSE_WAIT:
1574 tp->t_state = TCPS_LAST_ACK;
1577 if (tp->t_state >= TCPS_FIN_WAIT_2) {
1578 soisdisconnected(tp->t_inpcb->inp_socket);
1579 /* Prevent the connection hanging in FIN_WAIT_2 forever. */
1580 if (tp->t_state == TCPS_FIN_WAIT_2) {
1583 timeout = (tcp_fast_finwait2_recycle) ?
1584 tcp_finwait2_timeout : tcp_maxidle;
1585 tcp_timer_activate(tp, TT_2MSL, timeout);
1592 db_print_indent(int indent)
1596 for (i = 0; i < indent; i++)
1601 db_print_tstate(int t_state)
1606 db_printf("TCPS_CLOSED");
1610 db_printf("TCPS_LISTEN");
1614 db_printf("TCPS_SYN_SENT");
1617 case TCPS_SYN_RECEIVED:
1618 db_printf("TCPS_SYN_RECEIVED");
1621 case TCPS_ESTABLISHED:
1622 db_printf("TCPS_ESTABLISHED");
1625 case TCPS_CLOSE_WAIT:
1626 db_printf("TCPS_CLOSE_WAIT");
1629 case TCPS_FIN_WAIT_1:
1630 db_printf("TCPS_FIN_WAIT_1");
1634 db_printf("TCPS_CLOSING");
1638 db_printf("TCPS_LAST_ACK");
1641 case TCPS_FIN_WAIT_2:
1642 db_printf("TCPS_FIN_WAIT_2");
1645 case TCPS_TIME_WAIT:
1646 db_printf("TCPS_TIME_WAIT");
1650 db_printf("unknown");
1656 db_print_tflags(u_int t_flags)
1661 if (t_flags & TF_ACKNOW) {
1662 db_printf("%sTF_ACKNOW", comma ? ", " : "");
1665 if (t_flags & TF_DELACK) {
1666 db_printf("%sTF_DELACK", comma ? ", " : "");
1669 if (t_flags & TF_NODELAY) {
1670 db_printf("%sTF_NODELAY", comma ? ", " : "");
1673 if (t_flags & TF_NOOPT) {
1674 db_printf("%sTF_NOOPT", comma ? ", " : "");
1677 if (t_flags & TF_SENTFIN) {
1678 db_printf("%sTF_SENTFIN", comma ? ", " : "");
1681 if (t_flags & TF_REQ_SCALE) {
1682 db_printf("%sTF_REQ_SCALE", comma ? ", " : "");
1685 if (t_flags & TF_RCVD_SCALE) {
1686 db_printf("%sTF_RECVD_SCALE", comma ? ", " : "");
1689 if (t_flags & TF_REQ_TSTMP) {
1690 db_printf("%sTF_REQ_TSTMP", comma ? ", " : "");
1693 if (t_flags & TF_RCVD_TSTMP) {
1694 db_printf("%sTF_RCVD_TSTMP", comma ? ", " : "");
1697 if (t_flags & TF_SACK_PERMIT) {
1698 db_printf("%sTF_SACK_PERMIT", comma ? ", " : "");
1701 if (t_flags & TF_NEEDSYN) {
1702 db_printf("%sTF_NEEDSYN", comma ? ", " : "");
1705 if (t_flags & TF_NEEDFIN) {
1706 db_printf("%sTF_NEEDFIN", comma ? ", " : "");
1709 if (t_flags & TF_NOPUSH) {
1710 db_printf("%sTF_NOPUSH", comma ? ", " : "");
1713 if (t_flags & TF_NOPUSH) {
1714 db_printf("%sTF_NOPUSH", comma ? ", " : "");
1717 if (t_flags & TF_MORETOCOME) {
1718 db_printf("%sTF_MORETOCOME", comma ? ", " : "");
1721 if (t_flags & TF_LQ_OVERFLOW) {
1722 db_printf("%sTF_LQ_OVERFLOW", comma ? ", " : "");
1725 if (t_flags & TF_LASTIDLE) {
1726 db_printf("%sTF_LASTIDLE", comma ? ", " : "");
1729 if (t_flags & TF_RXWIN0SENT) {
1730 db_printf("%sTF_RXWIN0SENT", comma ? ", " : "");
1733 if (t_flags & TF_FASTRECOVERY) {
1734 db_printf("%sTF_FASTRECOVERY", comma ? ", " : "");
1737 if (t_flags & TF_WASFRECOVERY) {
1738 db_printf("%sTF_WASFRECOVERY", comma ? ", " : "");
1741 if (t_flags & TF_SIGNATURE) {
1742 db_printf("%sTF_SIGNATURE", comma ? ", " : "");
1745 if (t_flags & TF_FORCEDATA) {
1746 db_printf("%sTF_FORCEDATA", comma ? ", " : "");
1749 if (t_flags & TF_TSO) {
1750 db_printf("%sTF_TSO", comma ? ", " : "");
1753 if (t_flags & TF_ECN_PERMIT) {
1754 db_printf("%sTF_ECN_PERMIT", comma ? ", " : "");
1760 db_print_toobflags(char t_oobflags)
1765 if (t_oobflags & TCPOOB_HAVEDATA) {
1766 db_printf("%sTCPOOB_HAVEDATA", comma ? ", " : "");
1769 if (t_oobflags & TCPOOB_HADDATA) {
1770 db_printf("%sTCPOOB_HADDATA", comma ? ", " : "");
1776 db_print_tcpcb(struct tcpcb *tp, const char *name, int indent)
1779 db_print_indent(indent);
1780 db_printf("%s at %p\n", name, tp);
1784 db_print_indent(indent);
1785 db_printf("t_segq first: %p t_segqlen: %d t_dupacks: %d\n",
1786 LIST_FIRST(&tp->t_segq), tp->t_segqlen, tp->t_dupacks);
1788 db_print_indent(indent);
1789 db_printf("tt_rexmt: %p tt_persist: %p tt_keep: %p\n",
1790 &tp->t_timers->tt_rexmt, &tp->t_timers->tt_persist, &tp->t_timers->tt_keep);
1792 db_print_indent(indent);
1793 db_printf("tt_2msl: %p tt_delack: %p t_inpcb: %p\n", &tp->t_timers->tt_2msl,
1794 &tp->t_timers->tt_delack, tp->t_inpcb);
1796 db_print_indent(indent);
1797 db_printf("t_state: %d (", tp->t_state);
1798 db_print_tstate(tp->t_state);
1801 db_print_indent(indent);
1802 db_printf("t_flags: 0x%x (", tp->t_flags);
1803 db_print_tflags(tp->t_flags);
1806 db_print_indent(indent);
1807 db_printf("snd_una: 0x%08x snd_max: 0x%08x snd_nxt: x0%08x\n",
1808 tp->snd_una, tp->snd_max, tp->snd_nxt);
1810 db_print_indent(indent);
1811 db_printf("snd_up: 0x%08x snd_wl1: 0x%08x snd_wl2: 0x%08x\n",
1812 tp->snd_up, tp->snd_wl1, tp->snd_wl2);
1814 db_print_indent(indent);
1815 db_printf("iss: 0x%08x irs: 0x%08x rcv_nxt: 0x%08x\n",
1816 tp->iss, tp->irs, tp->rcv_nxt);
1818 db_print_indent(indent);
1819 db_printf("rcv_adv: 0x%08x rcv_wnd: %lu rcv_up: 0x%08x\n",
1820 tp->rcv_adv, tp->rcv_wnd, tp->rcv_up);
1822 db_print_indent(indent);
1823 db_printf("snd_wnd: %lu snd_cwnd: %lu snd_bwnd: %lu\n",
1824 tp->snd_wnd, tp->snd_cwnd, tp->snd_bwnd);
1826 db_print_indent(indent);
1827 db_printf("snd_ssthresh: %lu snd_bandwidth: %lu snd_recover: "
1828 "0x%08x\n", tp->snd_ssthresh, tp->snd_bandwidth,
1831 db_print_indent(indent);
1832 db_printf("t_maxopd: %u t_rcvtime: %u t_startime: %u\n",
1833 tp->t_maxopd, tp->t_rcvtime, tp->t_starttime);
1835 db_print_indent(indent);
1836 db_printf("t_rttime: %u t_rtsq: 0x%08x t_bw_rtttime: %u\n",
1837 tp->t_rtttime, tp->t_rtseq, tp->t_bw_rtttime);
1839 db_print_indent(indent);
1840 db_printf("t_bw_rtseq: 0x%08x t_rxtcur: %d t_maxseg: %u "
1841 "t_srtt: %d\n", tp->t_bw_rtseq, tp->t_rxtcur, tp->t_maxseg,
1844 db_print_indent(indent);
1845 db_printf("t_rttvar: %d t_rxtshift: %d t_rttmin: %u "
1846 "t_rttbest: %u\n", tp->t_rttvar, tp->t_rxtshift, tp->t_rttmin,
1849 db_print_indent(indent);
1850 db_printf("t_rttupdated: %lu max_sndwnd: %lu t_softerror: %d\n",
1851 tp->t_rttupdated, tp->max_sndwnd, tp->t_softerror);
1853 db_print_indent(indent);
1854 db_printf("t_oobflags: 0x%x (", tp->t_oobflags);
1855 db_print_toobflags(tp->t_oobflags);
1856 db_printf(") t_iobc: 0x%02x\n", tp->t_iobc);
1858 db_print_indent(indent);
1859 db_printf("snd_scale: %u rcv_scale: %u request_r_scale: %u\n",
1860 tp->snd_scale, tp->rcv_scale, tp->request_r_scale);
1862 db_print_indent(indent);
1863 db_printf("ts_recent: %u ts_recent_age: %u\n",
1864 tp->ts_recent, tp->ts_recent_age);
1866 db_print_indent(indent);
1867 db_printf("ts_offset: %u last_ack_sent: 0x%08x snd_cwnd_prev: "
1868 "%lu\n", tp->ts_offset, tp->last_ack_sent, tp->snd_cwnd_prev);
1870 db_print_indent(indent);
1871 db_printf("snd_ssthresh_prev: %lu snd_recover_prev: 0x%08x "
1872 "t_badrxtwin: %u\n", tp->snd_ssthresh_prev,
1873 tp->snd_recover_prev, tp->t_badrxtwin);
1875 db_print_indent(indent);
1876 db_printf("snd_numholes: %d snd_holes first: %p\n",
1877 tp->snd_numholes, TAILQ_FIRST(&tp->snd_holes));
1879 db_print_indent(indent);
1880 db_printf("snd_fack: 0x%08x rcv_numsacks: %d sack_newdata: "
1881 "0x%08x\n", tp->snd_fack, tp->rcv_numsacks, tp->sack_newdata);
1883 /* Skip sackblks, sackhint. */
1885 db_print_indent(indent);
1886 db_printf("t_rttlow: %d rfbuf_ts: %u rfbuf_cnt: %d\n",
1887 tp->t_rttlow, tp->rfbuf_ts, tp->rfbuf_cnt);
1890 DB_SHOW_COMMAND(tcpcb, db_show_tcpcb)
1895 db_printf("usage: show tcpcb <addr>\n");
1898 tp = (struct tcpcb *)addr;
1900 db_print_tcpcb(tp, "tcpcb", 0);