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>
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>
92 * TCP protocol interface to socket abstraction.
94 static int tcp_attach(struct socket *);
95 static int tcp_connect(struct tcpcb *, struct sockaddr *,
98 static int tcp6_connect(struct tcpcb *, struct sockaddr *,
101 static void tcp_disconnect(struct tcpcb *);
102 static void tcp_usrclosed(struct tcpcb *);
103 static void tcp_fill_info(struct tcpcb *, struct tcp_info *);
106 #define TCPDEBUG0 int ostate = 0
107 #define TCPDEBUG1() ostate = tp ? tp->t_state : 0
108 #define TCPDEBUG2(req) if (tp && (so->so_options & SO_DEBUG)) \
109 tcp_trace(TA_USER, ostate, tp, 0, 0, req)
113 #define TCPDEBUG2(req)
117 * TCP attaches to socket via pru_attach(), reserving space,
118 * and an internet control block.
121 tcp_usr_attach(struct socket *so, int proto, struct thread *td)
124 struct tcpcb *tp = NULL;
129 KASSERT(inp == NULL, ("tcp_usr_attach: inp != NULL"));
132 error = tcp_attach(so);
136 if ((so->so_options & SO_LINGER) && so->so_linger == 0)
137 so->so_linger = TCP_LINGERTIME;
142 TCPDEBUG2(PRU_ATTACH);
147 * tcp_detach is called when the socket layer loses its final reference
148 * to the socket, be it a file descriptor reference, a reference from TCP,
149 * etc. At this point, there is only one case in which we will keep around
150 * inpcb state: time wait.
152 * This function can probably be re-absorbed back into tcp_usr_detach() now
153 * that there is a single detach path.
156 tcp_detach(struct socket *so, struct inpcb *inp)
160 INP_INFO_WLOCK_ASSERT(&V_tcbinfo);
161 INP_WLOCK_ASSERT(inp);
163 KASSERT(so->so_pcb == inp, ("tcp_detach: so_pcb != inp"));
164 KASSERT(inp->inp_socket == so, ("tcp_detach: inp_socket != so"));
168 if (inp->inp_flags & INP_TIMEWAIT) {
170 * There are two cases to handle: one in which the time wait
171 * state is being discarded (INP_DROPPED), and one in which
172 * this connection will remain in timewait. In the former,
173 * it is time to discard all state (except tcptw, which has
174 * already been discarded by the timewait close code, which
175 * should be further up the call stack somewhere). In the
176 * latter case, we detach from the socket, but leave the pcb
177 * present until timewait ends.
179 * XXXRW: Would it be cleaner to free the tcptw here?
181 if (inp->inp_flags & INP_DROPPED) {
182 KASSERT(tp == NULL, ("tcp_detach: INP_TIMEWAIT && "
183 "INP_DROPPED && tp != NULL"));
192 * If the connection is not in timewait, we consider two
193 * two conditions: one in which no further processing is
194 * necessary (dropped || embryonic), and one in which TCP is
195 * not yet done, but no longer requires the socket, so the
196 * pcb will persist for the time being.
198 * XXXRW: Does the second case still occur?
200 if (inp->inp_flags & INP_DROPPED ||
201 tp->t_state < TCPS_SYN_SENT) {
211 * pru_detach() detaches the TCP protocol from the socket.
212 * If the protocol state is non-embryonic, then can't
213 * do this directly: have to initiate a pru_disconnect(),
214 * which may finish later; embryonic TCB's can just
218 tcp_usr_detach(struct socket *so)
223 KASSERT(inp != NULL, ("tcp_usr_detach: inp == NULL"));
224 INP_INFO_WLOCK(&V_tcbinfo);
226 KASSERT(inp->inp_socket != NULL,
227 ("tcp_usr_detach: inp_socket == NULL"));
229 INP_INFO_WUNLOCK(&V_tcbinfo);
233 * Give the socket an address.
236 tcp_usr_bind(struct socket *so, struct sockaddr *nam, struct thread *td)
240 struct tcpcb *tp = NULL;
241 struct sockaddr_in *sinp;
243 sinp = (struct sockaddr_in *)nam;
244 if (nam->sa_len != sizeof (*sinp))
247 * Must check for multicast addresses and disallow binding
250 if (sinp->sin_family == AF_INET &&
251 IN_MULTICAST(ntohl(sinp->sin_addr.s_addr)))
252 return (EAFNOSUPPORT);
255 INP_INFO_WLOCK(&V_tcbinfo);
257 KASSERT(inp != NULL, ("tcp_usr_bind: inp == NULL"));
259 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
265 error = in_pcbbind(inp, nam, td->td_ucred);
269 INP_INFO_WUNLOCK(&V_tcbinfo);
276 tcp6_usr_bind(struct socket *so, struct sockaddr *nam, struct thread *td)
280 struct tcpcb *tp = NULL;
281 struct sockaddr_in6 *sin6p;
283 sin6p = (struct sockaddr_in6 *)nam;
284 if (nam->sa_len != sizeof (*sin6p))
287 * Must check for multicast addresses and disallow binding
290 if (sin6p->sin6_family == AF_INET6 &&
291 IN6_IS_ADDR_MULTICAST(&sin6p->sin6_addr))
292 return (EAFNOSUPPORT);
295 INP_INFO_WLOCK(&V_tcbinfo);
297 KASSERT(inp != NULL, ("tcp6_usr_bind: inp == NULL"));
299 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
305 inp->inp_vflag &= ~INP_IPV4;
306 inp->inp_vflag |= INP_IPV6;
307 if ((inp->inp_flags & IN6P_IPV6_V6ONLY) == 0) {
308 if (IN6_IS_ADDR_UNSPECIFIED(&sin6p->sin6_addr))
309 inp->inp_vflag |= INP_IPV4;
310 else if (IN6_IS_ADDR_V4MAPPED(&sin6p->sin6_addr)) {
311 struct sockaddr_in sin;
313 in6_sin6_2_sin(&sin, sin6p);
314 inp->inp_vflag |= INP_IPV4;
315 inp->inp_vflag &= ~INP_IPV6;
316 error = in_pcbbind(inp, (struct sockaddr *)&sin,
321 error = in6_pcbbind(inp, nam, td->td_ucred);
325 INP_INFO_WUNLOCK(&V_tcbinfo);
331 * Prepare to accept connections.
334 tcp_usr_listen(struct socket *so, int backlog, struct thread *td)
338 struct tcpcb *tp = NULL;
341 INP_INFO_WLOCK(&V_tcbinfo);
343 KASSERT(inp != NULL, ("tcp_usr_listen: inp == NULL"));
345 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
352 error = solisten_proto_check(so);
353 if (error == 0 && inp->inp_lport == 0)
354 error = in_pcbbind(inp, (struct sockaddr *)0, td->td_ucred);
356 tp->t_state = TCPS_LISTEN;
357 solisten_proto(so, backlog);
358 tcp_offload_listen_open(tp);
363 TCPDEBUG2(PRU_LISTEN);
365 INP_INFO_WUNLOCK(&V_tcbinfo);
371 tcp6_usr_listen(struct socket *so, int backlog, struct thread *td)
375 struct tcpcb *tp = NULL;
378 INP_INFO_WLOCK(&V_tcbinfo);
380 KASSERT(inp != NULL, ("tcp6_usr_listen: inp == NULL"));
382 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
389 error = solisten_proto_check(so);
390 if (error == 0 && inp->inp_lport == 0) {
391 inp->inp_vflag &= ~INP_IPV4;
392 if ((inp->inp_flags & IN6P_IPV6_V6ONLY) == 0)
393 inp->inp_vflag |= INP_IPV4;
394 error = in6_pcbbind(inp, (struct sockaddr *)0, td->td_ucred);
397 tp->t_state = TCPS_LISTEN;
398 solisten_proto(so, backlog);
403 TCPDEBUG2(PRU_LISTEN);
405 INP_INFO_WUNLOCK(&V_tcbinfo);
411 * Initiate connection to peer.
412 * Create a template for use in transmissions on this connection.
413 * Enter SYN_SENT state, and mark socket as connecting.
414 * Start keep-alive timer, and seed output sequence space.
415 * Send initial segment on connection.
418 tcp_usr_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
422 struct tcpcb *tp = NULL;
423 struct sockaddr_in *sinp;
425 sinp = (struct sockaddr_in *)nam;
426 if (nam->sa_len != sizeof (*sinp))
429 * Must disallow TCP ``connections'' to multicast addresses.
431 if (sinp->sin_family == AF_INET
432 && IN_MULTICAST(ntohl(sinp->sin_addr.s_addr)))
433 return (EAFNOSUPPORT);
434 if ((error = prison_remote_ip4(td->td_ucred, &sinp->sin_addr)) != 0)
438 INP_INFO_WLOCK(&V_tcbinfo);
440 KASSERT(inp != NULL, ("tcp_usr_connect: inp == NULL"));
442 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
448 if ((error = tcp_connect(tp, nam, td)) != 0)
450 error = tcp_output_connect(so, nam);
452 TCPDEBUG2(PRU_CONNECT);
454 INP_INFO_WUNLOCK(&V_tcbinfo);
460 tcp6_usr_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
464 struct tcpcb *tp = NULL;
465 struct sockaddr_in6 *sin6p;
469 sin6p = (struct sockaddr_in6 *)nam;
470 if (nam->sa_len != sizeof (*sin6p))
473 * Must disallow TCP ``connections'' to multicast addresses.
475 if (sin6p->sin6_family == AF_INET6
476 && IN6_IS_ADDR_MULTICAST(&sin6p->sin6_addr))
477 return (EAFNOSUPPORT);
479 INP_INFO_WLOCK(&V_tcbinfo);
481 KASSERT(inp != NULL, ("tcp6_usr_connect: inp == NULL"));
483 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
489 if (IN6_IS_ADDR_V4MAPPED(&sin6p->sin6_addr)) {
490 struct sockaddr_in sin;
492 if ((inp->inp_flags & IN6P_IPV6_V6ONLY) != 0) {
497 in6_sin6_2_sin(&sin, sin6p);
498 inp->inp_vflag |= INP_IPV4;
499 inp->inp_vflag &= ~INP_IPV6;
500 if ((error = prison_remote_ip4(td->td_ucred,
501 &sin.sin_addr)) != 0)
503 if ((error = tcp_connect(tp, (struct sockaddr *)&sin, td)) != 0)
505 error = tcp_output_connect(so, nam);
508 inp->inp_vflag &= ~INP_IPV4;
509 inp->inp_vflag |= INP_IPV6;
510 inp->inp_inc.inc_flags |= INC_ISIPV6;
511 if ((error = prison_remote_ip6(td->td_ucred, &sin6p->sin6_addr)) != 0)
513 if ((error = tcp6_connect(tp, nam, td)) != 0)
515 error = tcp_output_connect(so, nam);
518 TCPDEBUG2(PRU_CONNECT);
520 INP_INFO_WUNLOCK(&V_tcbinfo);
526 * Initiate disconnect from peer.
527 * If connection never passed embryonic stage, just drop;
528 * else if don't need to let data drain, then can just drop anyways,
529 * else have to begin TCP shutdown process: mark socket disconnecting,
530 * drain unread data, state switch to reflect user close, and
531 * send segment (e.g. FIN) to peer. Socket will be really disconnected
532 * when peer sends FIN and acks ours.
534 * SHOULD IMPLEMENT LATER PRU_CONNECT VIA REALLOC TCPCB.
537 tcp_usr_disconnect(struct socket *so)
540 struct tcpcb *tp = NULL;
544 INP_INFO_WLOCK(&V_tcbinfo);
546 KASSERT(inp != NULL, ("tcp_usr_disconnect: inp == NULL"));
548 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
556 TCPDEBUG2(PRU_DISCONNECT);
558 INP_INFO_WUNLOCK(&V_tcbinfo);
563 * Accept a connection. Essentially all the work is
564 * done at higher levels; just return the address
565 * of the peer, storing through addr.
568 tcp_usr_accept(struct socket *so, struct sockaddr **nam)
571 struct inpcb *inp = NULL;
572 struct tcpcb *tp = NULL;
577 if (so->so_state & SS_ISDISCONNECTED)
578 return (ECONNABORTED);
581 KASSERT(inp != NULL, ("tcp_usr_accept: inp == NULL"));
582 INP_INFO_RLOCK(&V_tcbinfo);
584 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
585 error = ECONNABORTED;
592 * We inline in_getpeeraddr and COMMON_END here, so that we can
593 * copy the data of interest and defer the malloc until after we
596 port = inp->inp_fport;
597 addr = inp->inp_faddr;
600 TCPDEBUG2(PRU_ACCEPT);
602 INP_INFO_RUNLOCK(&V_tcbinfo);
604 *nam = in_sockaddr(port, &addr);
610 tcp6_usr_accept(struct socket *so, struct sockaddr **nam)
612 struct inpcb *inp = NULL;
614 struct tcpcb *tp = NULL;
616 struct in6_addr addr6;
621 if (so->so_state & SS_ISDISCONNECTED)
622 return (ECONNABORTED);
625 KASSERT(inp != NULL, ("tcp6_usr_accept: inp == NULL"));
627 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
628 error = ECONNABORTED;
635 * We inline in6_mapped_peeraddr and COMMON_END here, so that we can
636 * copy the data of interest and defer the malloc until after we
639 if (inp->inp_vflag & INP_IPV4) {
641 port = inp->inp_fport;
642 addr = inp->inp_faddr;
644 port = inp->inp_fport;
645 addr6 = inp->in6p_faddr;
649 TCPDEBUG2(PRU_ACCEPT);
653 *nam = in6_v4mapsin6_sockaddr(port, &addr);
655 *nam = in6_sockaddr(port, &addr6);
662 * Mark the connection as being incapable of further output.
665 tcp_usr_shutdown(struct socket *so)
669 struct tcpcb *tp = NULL;
672 INP_INFO_WLOCK(&V_tcbinfo);
674 KASSERT(inp != NULL, ("inp == NULL"));
676 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
684 if (!(inp->inp_flags & INP_DROPPED))
685 error = tcp_output_disconnect(tp);
688 TCPDEBUG2(PRU_SHUTDOWN);
690 INP_INFO_WUNLOCK(&V_tcbinfo);
696 * After a receive, possibly send window update to peer.
699 tcp_usr_rcvd(struct socket *so, int flags)
702 struct tcpcb *tp = NULL;
707 KASSERT(inp != NULL, ("tcp_usr_rcvd: inp == NULL"));
709 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
724 * Do a send by putting data in output queue and updating urgent
725 * marker if URG set. Possibly send more data. Unlike the other
726 * pru_*() routines, the mbuf chains are our responsibility. We
727 * must either enqueue them or free them. The other pru_* routines
728 * generally are caller-frees.
731 tcp_usr_send(struct socket *so, int flags, struct mbuf *m,
732 struct sockaddr *nam, struct mbuf *control, struct thread *td)
736 struct tcpcb *tp = NULL;
744 * We require the pcbinfo lock in two cases:
746 * (1) An implied connect is taking place, which can result in
747 * binding IPs and ports and hence modification of the pcb hash
750 * (2) PRUS_EOF is set, resulting in explicit close on the send.
752 if ((nam != NULL) || (flags & PRUS_EOF)) {
753 INP_INFO_WLOCK(&V_tcbinfo);
757 KASSERT(inp != NULL, ("tcp_usr_send: inp == NULL"));
759 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
768 isipv6 = nam && nam->sa_family == AF_INET6;
773 /* TCP doesn't do control messages (rights, creds, etc) */
774 if (control->m_len) {
781 m_freem(control); /* empty control, just free it */
783 if (!(flags & PRUS_OOB)) {
784 sbappendstream(&so->so_snd, m);
785 if (nam && tp->t_state < TCPS_SYN_SENT) {
787 * Do implied connect if not yet connected,
788 * initialize window to default value, and
789 * initialize maxseg/maxopd using peer's cached
792 INP_INFO_WLOCK_ASSERT(&V_tcbinfo);
795 error = tcp6_connect(tp, nam, td);
798 error = tcp_connect(tp, nam, td);
801 tp->snd_wnd = TTCP_CLIENT_SND_WND;
804 if (flags & PRUS_EOF) {
806 * Close the send side of the connection after
809 INP_INFO_WLOCK_ASSERT(&V_tcbinfo);
814 INP_INFO_WUNLOCK(&V_tcbinfo);
817 if (!(inp->inp_flags & INP_DROPPED)) {
818 if (flags & PRUS_MORETOCOME)
819 tp->t_flags |= TF_MORETOCOME;
820 error = tcp_output_send(tp);
821 if (flags & PRUS_MORETOCOME)
822 tp->t_flags &= ~TF_MORETOCOME;
826 * XXXRW: PRUS_EOF not implemented with PRUS_OOB?
828 SOCKBUF_LOCK(&so->so_snd);
829 if (sbspace(&so->so_snd) < -512) {
830 SOCKBUF_UNLOCK(&so->so_snd);
836 * According to RFC961 (Assigned Protocols),
837 * the urgent pointer points to the last octet
838 * of urgent data. We continue, however,
839 * to consider it to indicate the first octet
840 * of data past the urgent section.
841 * Otherwise, snd_up should be one lower.
843 sbappendstream_locked(&so->so_snd, m);
844 SOCKBUF_UNLOCK(&so->so_snd);
845 if (nam && tp->t_state < TCPS_SYN_SENT) {
847 * Do implied connect if not yet connected,
848 * initialize window to default value, and
849 * initialize maxseg/maxopd using peer's cached
852 INP_INFO_WLOCK_ASSERT(&V_tcbinfo);
855 error = tcp6_connect(tp, nam, td);
858 error = tcp_connect(tp, nam, td);
861 tp->snd_wnd = TTCP_CLIENT_SND_WND;
863 INP_INFO_WUNLOCK(&V_tcbinfo);
866 INP_INFO_WUNLOCK(&V_tcbinfo);
869 tp->snd_up = tp->snd_una + so->so_snd.sb_cc;
870 tp->t_flags |= TF_FORCEDATA;
871 error = tcp_output_send(tp);
872 tp->t_flags &= ~TF_FORCEDATA;
875 TCPDEBUG2((flags & PRUS_OOB) ? PRU_SENDOOB :
876 ((flags & PRUS_EOF) ? PRU_SEND_EOF : PRU_SEND));
879 INP_INFO_WUNLOCK(&V_tcbinfo);
884 * Abort the TCP. Drop the connection abruptly.
887 tcp_usr_abort(struct socket *so)
890 struct tcpcb *tp = NULL;
894 KASSERT(inp != NULL, ("tcp_usr_abort: inp == NULL"));
896 INP_INFO_WLOCK(&V_tcbinfo);
898 KASSERT(inp->inp_socket != NULL,
899 ("tcp_usr_abort: inp_socket == NULL"));
902 * If we still have full TCP state, and we're not dropped, drop.
904 if (!(inp->inp_flags & INP_TIMEWAIT) &&
905 !(inp->inp_flags & INP_DROPPED)) {
908 tcp_drop(tp, ECONNABORTED);
909 TCPDEBUG2(PRU_ABORT);
911 if (!(inp->inp_flags & INP_DROPPED)) {
913 so->so_state |= SS_PROTOREF;
915 inp->inp_flags |= INP_SOCKREF;
918 INP_INFO_WUNLOCK(&V_tcbinfo);
922 * TCP socket is closed. Start friendly disconnect.
925 tcp_usr_close(struct socket *so)
928 struct tcpcb *tp = NULL;
932 KASSERT(inp != NULL, ("tcp_usr_close: inp == NULL"));
934 INP_INFO_WLOCK(&V_tcbinfo);
936 KASSERT(inp->inp_socket != NULL,
937 ("tcp_usr_close: inp_socket == NULL"));
940 * If we still have full TCP state, and we're not dropped, initiate
943 if (!(inp->inp_flags & INP_TIMEWAIT) &&
944 !(inp->inp_flags & INP_DROPPED)) {
948 TCPDEBUG2(PRU_CLOSE);
950 if (!(inp->inp_flags & INP_DROPPED)) {
952 so->so_state |= SS_PROTOREF;
954 inp->inp_flags |= INP_SOCKREF;
957 INP_INFO_WUNLOCK(&V_tcbinfo);
961 * Receive out-of-band data.
964 tcp_usr_rcvoob(struct socket *so, struct mbuf *m, int flags)
968 struct tcpcb *tp = NULL;
972 KASSERT(inp != NULL, ("tcp_usr_rcvoob: inp == NULL"));
974 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
980 if ((so->so_oobmark == 0 &&
981 (so->so_rcv.sb_state & SBS_RCVATMARK) == 0) ||
982 so->so_options & SO_OOBINLINE ||
983 tp->t_oobflags & TCPOOB_HADDATA) {
987 if ((tp->t_oobflags & TCPOOB_HAVEDATA) == 0) {
992 *mtod(m, caddr_t) = tp->t_iobc;
993 if ((flags & MSG_PEEK) == 0)
994 tp->t_oobflags ^= (TCPOOB_HAVEDATA | TCPOOB_HADDATA);
997 TCPDEBUG2(PRU_RCVOOB);
1002 struct pr_usrreqs tcp_usrreqs = {
1003 .pru_abort = tcp_usr_abort,
1004 .pru_accept = tcp_usr_accept,
1005 .pru_attach = tcp_usr_attach,
1006 .pru_bind = tcp_usr_bind,
1007 .pru_connect = tcp_usr_connect,
1008 .pru_control = in_control,
1009 .pru_detach = tcp_usr_detach,
1010 .pru_disconnect = tcp_usr_disconnect,
1011 .pru_listen = tcp_usr_listen,
1012 .pru_peeraddr = in_getpeeraddr,
1013 .pru_rcvd = tcp_usr_rcvd,
1014 .pru_rcvoob = tcp_usr_rcvoob,
1015 .pru_send = tcp_usr_send,
1016 .pru_shutdown = tcp_usr_shutdown,
1017 .pru_sockaddr = in_getsockaddr,
1019 .pru_soreceive = soreceive_stream,
1021 .pru_sosetlabel = in_pcbsosetlabel,
1022 .pru_close = tcp_usr_close,
1026 struct pr_usrreqs tcp6_usrreqs = {
1027 .pru_abort = tcp_usr_abort,
1028 .pru_accept = tcp6_usr_accept,
1029 .pru_attach = tcp_usr_attach,
1030 .pru_bind = tcp6_usr_bind,
1031 .pru_connect = tcp6_usr_connect,
1032 .pru_control = in6_control,
1033 .pru_detach = tcp_usr_detach,
1034 .pru_disconnect = tcp_usr_disconnect,
1035 .pru_listen = tcp6_usr_listen,
1036 .pru_peeraddr = in6_mapped_peeraddr,
1037 .pru_rcvd = tcp_usr_rcvd,
1038 .pru_rcvoob = tcp_usr_rcvoob,
1039 .pru_send = tcp_usr_send,
1040 .pru_shutdown = tcp_usr_shutdown,
1041 .pru_sockaddr = in6_mapped_sockaddr,
1043 .pru_soreceive = soreceive_stream,
1045 .pru_sosetlabel = in_pcbsosetlabel,
1046 .pru_close = tcp_usr_close,
1051 * Common subroutine to open a TCP connection to remote host specified
1052 * by struct sockaddr_in in mbuf *nam. Call in_pcbbind to assign a local
1053 * port number if needed. Call in_pcbconnect_setup to do the routing and
1054 * to choose a local host address (interface). If there is an existing
1055 * incarnation of the same connection in TIME-WAIT state and if the remote
1056 * host was sending CC options and if the connection duration was < MSL, then
1057 * truncate the previous TIME-WAIT state and proceed.
1058 * Initialize connection parameters and enter SYN-SENT state.
1061 tcp_connect(struct tcpcb *tp, struct sockaddr *nam, struct thread *td)
1063 struct inpcb *inp = tp->t_inpcb, *oinp;
1064 struct socket *so = inp->inp_socket;
1065 struct in_addr laddr;
1069 INP_INFO_WLOCK_ASSERT(&V_tcbinfo);
1070 INP_WLOCK_ASSERT(inp);
1072 if (inp->inp_lport == 0) {
1073 error = in_pcbbind(inp, (struct sockaddr *)0, td->td_ucred);
1079 * Cannot simply call in_pcbconnect, because there might be an
1080 * earlier incarnation of this same connection still in
1081 * TIME_WAIT state, creating an ADDRINUSE error.
1083 laddr = inp->inp_laddr;
1084 lport = inp->inp_lport;
1085 error = in_pcbconnect_setup(inp, nam, &laddr.s_addr, &lport,
1086 &inp->inp_faddr.s_addr, &inp->inp_fport, &oinp, td->td_ucred);
1087 if (error && oinp == NULL)
1091 inp->inp_laddr = laddr;
1095 * Compute window scaling to request:
1096 * Scale to fit into sweet spot. See tcp_syncache.c.
1097 * XXX: This should move to tcp_output().
1099 while (tp->request_r_scale < TCP_MAX_WINSHIFT &&
1100 (TCP_MAXWIN << tp->request_r_scale) < sb_max)
1101 tp->request_r_scale++;
1104 TCPSTAT_INC(tcps_connattempt);
1105 tp->t_state = TCPS_SYN_SENT;
1106 tcp_timer_activate(tp, TT_KEEP, tcp_keepinit);
1107 tp->iss = tcp_new_isn(tp);
1108 tp->t_bw_rtseq = tp->iss;
1109 tcp_sendseqinit(tp);
1116 tcp6_connect(struct tcpcb *tp, struct sockaddr *nam, struct thread *td)
1118 struct inpcb *inp = tp->t_inpcb, *oinp;
1119 struct socket *so = inp->inp_socket;
1120 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)nam;
1121 struct in6_addr addr6;
1124 INP_INFO_WLOCK_ASSERT(&V_tcbinfo);
1125 INP_WLOCK_ASSERT(inp);
1127 if (inp->inp_lport == 0) {
1128 error = in6_pcbbind(inp, (struct sockaddr *)0, td->td_ucred);
1134 * Cannot simply call in_pcbconnect, because there might be an
1135 * earlier incarnation of this same connection still in
1136 * TIME_WAIT state, creating an ADDRINUSE error.
1137 * in6_pcbladdr() also handles scope zone IDs.
1139 error = in6_pcbladdr(inp, nam, &addr6);
1142 oinp = in6_pcblookup_hash(inp->inp_pcbinfo,
1143 &sin6->sin6_addr, sin6->sin6_port,
1144 IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_laddr)
1147 inp->inp_lport, 0, NULL);
1150 if (IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_laddr))
1151 inp->in6p_laddr = addr6;
1152 inp->in6p_faddr = sin6->sin6_addr;
1153 inp->inp_fport = sin6->sin6_port;
1154 /* update flowinfo - draft-itojun-ipv6-flowlabel-api-00 */
1155 inp->inp_flow &= ~IPV6_FLOWLABEL_MASK;
1156 if (inp->inp_flags & IN6P_AUTOFLOWLABEL)
1158 (htonl(ip6_randomflowlabel()) & IPV6_FLOWLABEL_MASK);
1161 /* Compute window scaling to request. */
1162 while (tp->request_r_scale < TCP_MAX_WINSHIFT &&
1163 (TCP_MAXWIN << tp->request_r_scale) < sb_max)
1164 tp->request_r_scale++;
1167 TCPSTAT_INC(tcps_connattempt);
1168 tp->t_state = TCPS_SYN_SENT;
1169 tcp_timer_activate(tp, TT_KEEP, tcp_keepinit);
1170 tp->iss = tcp_new_isn(tp);
1171 tp->t_bw_rtseq = tp->iss;
1172 tcp_sendseqinit(tp);
1179 * Export TCP internal state information via a struct tcp_info, based on the
1180 * Linux 2.6 API. Not ABI compatible as our constants are mapped differently
1181 * (TCP state machine, etc). We export all information using FreeBSD-native
1182 * constants -- for example, the numeric values for tcpi_state will differ
1186 tcp_fill_info(struct tcpcb *tp, struct tcp_info *ti)
1189 INP_WLOCK_ASSERT(tp->t_inpcb);
1190 bzero(ti, sizeof(*ti));
1192 ti->tcpi_state = tp->t_state;
1193 if ((tp->t_flags & TF_REQ_TSTMP) && (tp->t_flags & TF_RCVD_TSTMP))
1194 ti->tcpi_options |= TCPI_OPT_TIMESTAMPS;
1195 if (tp->t_flags & TF_SACK_PERMIT)
1196 ti->tcpi_options |= TCPI_OPT_SACK;
1197 if ((tp->t_flags & TF_REQ_SCALE) && (tp->t_flags & TF_RCVD_SCALE)) {
1198 ti->tcpi_options |= TCPI_OPT_WSCALE;
1199 ti->tcpi_snd_wscale = tp->snd_scale;
1200 ti->tcpi_rcv_wscale = tp->rcv_scale;
1203 ti->tcpi_rtt = ((u_int64_t)tp->t_srtt * tick) >> TCP_RTT_SHIFT;
1204 ti->tcpi_rttvar = ((u_int64_t)tp->t_rttvar * tick) >> TCP_RTTVAR_SHIFT;
1206 ti->tcpi_snd_ssthresh = tp->snd_ssthresh;
1207 ti->tcpi_snd_cwnd = tp->snd_cwnd;
1210 * FreeBSD-specific extension fields for tcp_info.
1212 ti->tcpi_rcv_space = tp->rcv_wnd;
1213 ti->tcpi_rcv_nxt = tp->rcv_nxt;
1214 ti->tcpi_snd_wnd = tp->snd_wnd;
1215 ti->tcpi_snd_bwnd = tp->snd_bwnd;
1216 ti->tcpi_snd_nxt = tp->snd_nxt;
1217 ti->__tcpi_snd_mss = tp->t_maxseg;
1218 ti->__tcpi_rcv_mss = tp->t_maxseg;
1219 if (tp->t_flags & TF_TOE)
1220 ti->tcpi_options |= TCPI_OPT_TOE;
1224 * tcp_ctloutput() must drop the inpcb lock before performing copyin on
1225 * socket option arguments. When it re-acquires the lock after the copy, it
1226 * has to revalidate that the connection is still valid for the socket
1229 #define INP_WLOCK_RECHECK(inp) do { \
1231 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) { \
1233 return (ECONNRESET); \
1235 tp = intotcpcb(inp); \
1239 tcp_ctloutput(struct socket *so, struct sockopt *sopt)
1241 int error, opt, optval;
1247 inp = sotoinpcb(so);
1248 KASSERT(inp != NULL, ("tcp_ctloutput: inp == NULL"));
1250 if (sopt->sopt_level != IPPROTO_TCP) {
1252 if (inp->inp_vflag & INP_IPV6PROTO) {
1254 error = ip6_ctloutput(so, sopt);
1258 error = ip_ctloutput(so, sopt);
1264 if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) {
1266 return (ECONNRESET);
1269 switch (sopt->sopt_dir) {
1271 switch (sopt->sopt_name) {
1272 #ifdef TCP_SIGNATURE
1275 error = sooptcopyin(sopt, &optval, sizeof optval,
1280 INP_WLOCK_RECHECK(inp);
1282 tp->t_flags |= TF_SIGNATURE;
1284 tp->t_flags &= ~TF_SIGNATURE;
1287 #endif /* TCP_SIGNATURE */
1291 error = sooptcopyin(sopt, &optval, sizeof optval,
1296 INP_WLOCK_RECHECK(inp);
1297 switch (sopt->sopt_name) {
1305 opt = 0; /* dead code to fool gcc */
1312 tp->t_flags &= ~opt;
1318 error = sooptcopyin(sopt, &optval, sizeof optval,
1323 INP_WLOCK_RECHECK(inp);
1325 tp->t_flags |= TF_NOPUSH;
1327 tp->t_flags &= ~TF_NOPUSH;
1328 error = tcp_output(tp);
1335 error = sooptcopyin(sopt, &optval, sizeof optval,
1340 INP_WLOCK_RECHECK(inp);
1341 if (optval > 0 && optval <= tp->t_maxseg &&
1342 optval + 40 >= V_tcp_minmss)
1343 tp->t_maxseg = optval;
1356 error = ENOPROTOOPT;
1362 tp = intotcpcb(inp);
1363 switch (sopt->sopt_name) {
1364 #ifdef TCP_SIGNATURE
1366 optval = (tp->t_flags & TF_SIGNATURE) ? 1 : 0;
1368 error = sooptcopyout(sopt, &optval, sizeof optval);
1373 optval = tp->t_flags & TF_NODELAY;
1375 error = sooptcopyout(sopt, &optval, sizeof optval);
1378 optval = tp->t_maxseg;
1380 error = sooptcopyout(sopt, &optval, sizeof optval);
1383 optval = tp->t_flags & TF_NOOPT;
1385 error = sooptcopyout(sopt, &optval, sizeof optval);
1388 optval = tp->t_flags & TF_NOPUSH;
1390 error = sooptcopyout(sopt, &optval, sizeof optval);
1393 tcp_fill_info(tp, &ti);
1395 error = sooptcopyout(sopt, &ti, sizeof ti);
1399 error = ENOPROTOOPT;
1406 #undef INP_WLOCK_RECHECK
1409 * tcp_sendspace and tcp_recvspace are the default send and receive window
1410 * sizes, respectively. These are obsolescent (this information should
1411 * be set by the route).
1413 u_long tcp_sendspace = 1024*32;
1414 SYSCTL_ULONG(_net_inet_tcp, TCPCTL_SENDSPACE, sendspace, CTLFLAG_RW,
1415 &tcp_sendspace , 0, "Maximum outgoing TCP datagram size");
1416 u_long tcp_recvspace = 1024*64;
1417 SYSCTL_ULONG(_net_inet_tcp, TCPCTL_RECVSPACE, recvspace, CTLFLAG_RW,
1418 &tcp_recvspace , 0, "Maximum incoming TCP datagram size");
1421 * Attach TCP protocol to socket, allocating
1422 * internet protocol control block, tcp control block,
1423 * bufer space, and entering LISTEN state if to accept connections.
1426 tcp_attach(struct socket *so)
1432 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
1433 error = soreserve(so, tcp_sendspace, tcp_recvspace);
1437 so->so_rcv.sb_flags |= SB_AUTOSIZE;
1438 so->so_snd.sb_flags |= SB_AUTOSIZE;
1439 INP_INFO_WLOCK(&V_tcbinfo);
1440 error = in_pcballoc(so, &V_tcbinfo);
1442 INP_INFO_WUNLOCK(&V_tcbinfo);
1445 inp = sotoinpcb(so);
1447 if (inp->inp_vflag & INP_IPV6PROTO) {
1448 inp->inp_vflag |= INP_IPV6;
1449 inp->in6p_hops = -1; /* use kernel default */
1453 inp->inp_vflag |= INP_IPV4;
1454 tp = tcp_newtcpcb(inp);
1458 INP_INFO_WUNLOCK(&V_tcbinfo);
1461 tp->t_state = TCPS_CLOSED;
1463 INP_INFO_WUNLOCK(&V_tcbinfo);
1468 * Initiate (or continue) disconnect.
1469 * If embryonic state, just send reset (once).
1470 * If in ``let data drain'' option and linger null, just drop.
1471 * Otherwise (hard), mark socket disconnecting and drop
1472 * current input data; switch states based on user close, and
1473 * send segment to peer (with FIN).
1476 tcp_disconnect(struct tcpcb *tp)
1478 struct inpcb *inp = tp->t_inpcb;
1479 struct socket *so = inp->inp_socket;
1481 INP_INFO_WLOCK_ASSERT(&V_tcbinfo);
1482 INP_WLOCK_ASSERT(inp);
1485 * Neither tcp_close() nor tcp_drop() should return NULL, as the
1486 * socket is still open.
1488 if (tp->t_state < TCPS_ESTABLISHED) {
1491 ("tcp_disconnect: tcp_close() returned NULL"));
1492 } else if ((so->so_options & SO_LINGER) && so->so_linger == 0) {
1493 tp = tcp_drop(tp, 0);
1495 ("tcp_disconnect: tcp_drop() returned NULL"));
1497 soisdisconnecting(so);
1498 sbflush(&so->so_rcv);
1500 if (!(inp->inp_flags & INP_DROPPED))
1501 tcp_output_disconnect(tp);
1506 * User issued close, and wish to trail through shutdown states:
1507 * if never received SYN, just forget it. If got a SYN from peer,
1508 * but haven't sent FIN, then go to FIN_WAIT_1 state to send peer a FIN.
1509 * If already got a FIN from peer, then almost done; go to LAST_ACK
1510 * state. In all other cases, have already sent FIN to peer (e.g.
1511 * after PRU_SHUTDOWN), and just have to play tedious game waiting
1512 * for peer to send FIN or not respond to keep-alives, etc.
1513 * We can let the user exit from the close as soon as the FIN is acked.
1516 tcp_usrclosed(struct tcpcb *tp)
1519 INP_INFO_WLOCK_ASSERT(&V_tcbinfo);
1520 INP_WLOCK_ASSERT(tp->t_inpcb);
1522 switch (tp->t_state) {
1524 tcp_offload_listen_close(tp);
1527 tp->t_state = TCPS_CLOSED;
1530 * tcp_close() should never return NULL here as the socket is
1534 ("tcp_usrclosed: tcp_close() returned NULL"));
1538 case TCPS_SYN_RECEIVED:
1539 tp->t_flags |= TF_NEEDFIN;
1542 case TCPS_ESTABLISHED:
1543 tp->t_state = TCPS_FIN_WAIT_1;
1546 case TCPS_CLOSE_WAIT:
1547 tp->t_state = TCPS_LAST_ACK;
1550 if (tp->t_state >= TCPS_FIN_WAIT_2) {
1551 soisdisconnected(tp->t_inpcb->inp_socket);
1552 /* Prevent the connection hanging in FIN_WAIT_2 forever. */
1553 if (tp->t_state == TCPS_FIN_WAIT_2) {
1556 timeout = (tcp_fast_finwait2_recycle) ?
1557 tcp_finwait2_timeout : tcp_maxidle;
1558 tcp_timer_activate(tp, TT_2MSL, timeout);
1565 db_print_indent(int indent)
1569 for (i = 0; i < indent; i++)
1574 db_print_tstate(int t_state)
1579 db_printf("TCPS_CLOSED");
1583 db_printf("TCPS_LISTEN");
1587 db_printf("TCPS_SYN_SENT");
1590 case TCPS_SYN_RECEIVED:
1591 db_printf("TCPS_SYN_RECEIVED");
1594 case TCPS_ESTABLISHED:
1595 db_printf("TCPS_ESTABLISHED");
1598 case TCPS_CLOSE_WAIT:
1599 db_printf("TCPS_CLOSE_WAIT");
1602 case TCPS_FIN_WAIT_1:
1603 db_printf("TCPS_FIN_WAIT_1");
1607 db_printf("TCPS_CLOSING");
1611 db_printf("TCPS_LAST_ACK");
1614 case TCPS_FIN_WAIT_2:
1615 db_printf("TCPS_FIN_WAIT_2");
1618 case TCPS_TIME_WAIT:
1619 db_printf("TCPS_TIME_WAIT");
1623 db_printf("unknown");
1629 db_print_tflags(u_int t_flags)
1634 if (t_flags & TF_ACKNOW) {
1635 db_printf("%sTF_ACKNOW", comma ? ", " : "");
1638 if (t_flags & TF_DELACK) {
1639 db_printf("%sTF_DELACK", comma ? ", " : "");
1642 if (t_flags & TF_NODELAY) {
1643 db_printf("%sTF_NODELAY", comma ? ", " : "");
1646 if (t_flags & TF_NOOPT) {
1647 db_printf("%sTF_NOOPT", comma ? ", " : "");
1650 if (t_flags & TF_SENTFIN) {
1651 db_printf("%sTF_SENTFIN", comma ? ", " : "");
1654 if (t_flags & TF_REQ_SCALE) {
1655 db_printf("%sTF_REQ_SCALE", comma ? ", " : "");
1658 if (t_flags & TF_RCVD_SCALE) {
1659 db_printf("%sTF_RECVD_SCALE", comma ? ", " : "");
1662 if (t_flags & TF_REQ_TSTMP) {
1663 db_printf("%sTF_REQ_TSTMP", comma ? ", " : "");
1666 if (t_flags & TF_RCVD_TSTMP) {
1667 db_printf("%sTF_RCVD_TSTMP", comma ? ", " : "");
1670 if (t_flags & TF_SACK_PERMIT) {
1671 db_printf("%sTF_SACK_PERMIT", comma ? ", " : "");
1674 if (t_flags & TF_NEEDSYN) {
1675 db_printf("%sTF_NEEDSYN", comma ? ", " : "");
1678 if (t_flags & TF_NEEDFIN) {
1679 db_printf("%sTF_NEEDFIN", comma ? ", " : "");
1682 if (t_flags & TF_NOPUSH) {
1683 db_printf("%sTF_NOPUSH", comma ? ", " : "");
1686 if (t_flags & TF_NOPUSH) {
1687 db_printf("%sTF_NOPUSH", comma ? ", " : "");
1690 if (t_flags & TF_MORETOCOME) {
1691 db_printf("%sTF_MORETOCOME", comma ? ", " : "");
1694 if (t_flags & TF_LQ_OVERFLOW) {
1695 db_printf("%sTF_LQ_OVERFLOW", comma ? ", " : "");
1698 if (t_flags & TF_LASTIDLE) {
1699 db_printf("%sTF_LASTIDLE", comma ? ", " : "");
1702 if (t_flags & TF_RXWIN0SENT) {
1703 db_printf("%sTF_RXWIN0SENT", comma ? ", " : "");
1706 if (t_flags & TF_FASTRECOVERY) {
1707 db_printf("%sTF_FASTRECOVERY", comma ? ", " : "");
1710 if (t_flags & TF_WASFRECOVERY) {
1711 db_printf("%sTF_WASFRECOVERY", comma ? ", " : "");
1714 if (t_flags & TF_SIGNATURE) {
1715 db_printf("%sTF_SIGNATURE", comma ? ", " : "");
1718 if (t_flags & TF_FORCEDATA) {
1719 db_printf("%sTF_FORCEDATA", comma ? ", " : "");
1722 if (t_flags & TF_TSO) {
1723 db_printf("%sTF_TSO", comma ? ", " : "");
1726 if (t_flags & TF_ECN_PERMIT) {
1727 db_printf("%sTF_ECN_PERMIT", comma ? ", " : "");
1733 db_print_toobflags(char t_oobflags)
1738 if (t_oobflags & TCPOOB_HAVEDATA) {
1739 db_printf("%sTCPOOB_HAVEDATA", comma ? ", " : "");
1742 if (t_oobflags & TCPOOB_HADDATA) {
1743 db_printf("%sTCPOOB_HADDATA", comma ? ", " : "");
1749 db_print_tcpcb(struct tcpcb *tp, const char *name, int indent)
1752 db_print_indent(indent);
1753 db_printf("%s at %p\n", name, tp);
1757 db_print_indent(indent);
1758 db_printf("t_segq first: %p t_segqlen: %d t_dupacks: %d\n",
1759 LIST_FIRST(&tp->t_segq), tp->t_segqlen, tp->t_dupacks);
1761 db_print_indent(indent);
1762 db_printf("tt_rexmt: %p tt_persist: %p tt_keep: %p\n",
1763 &tp->t_timers->tt_rexmt, &tp->t_timers->tt_persist, &tp->t_timers->tt_keep);
1765 db_print_indent(indent);
1766 db_printf("tt_2msl: %p tt_delack: %p t_inpcb: %p\n", &tp->t_timers->tt_2msl,
1767 &tp->t_timers->tt_delack, tp->t_inpcb);
1769 db_print_indent(indent);
1770 db_printf("t_state: %d (", tp->t_state);
1771 db_print_tstate(tp->t_state);
1774 db_print_indent(indent);
1775 db_printf("t_flags: 0x%x (", tp->t_flags);
1776 db_print_tflags(tp->t_flags);
1779 db_print_indent(indent);
1780 db_printf("snd_una: 0x%08x snd_max: 0x%08x snd_nxt: x0%08x\n",
1781 tp->snd_una, tp->snd_max, tp->snd_nxt);
1783 db_print_indent(indent);
1784 db_printf("snd_up: 0x%08x snd_wl1: 0x%08x snd_wl2: 0x%08x\n",
1785 tp->snd_up, tp->snd_wl1, tp->snd_wl2);
1787 db_print_indent(indent);
1788 db_printf("iss: 0x%08x irs: 0x%08x rcv_nxt: 0x%08x\n",
1789 tp->iss, tp->irs, tp->rcv_nxt);
1791 db_print_indent(indent);
1792 db_printf("rcv_adv: 0x%08x rcv_wnd: %lu rcv_up: 0x%08x\n",
1793 tp->rcv_adv, tp->rcv_wnd, tp->rcv_up);
1795 db_print_indent(indent);
1796 db_printf("snd_wnd: %lu snd_cwnd: %lu snd_bwnd: %lu\n",
1797 tp->snd_wnd, tp->snd_cwnd, tp->snd_bwnd);
1799 db_print_indent(indent);
1800 db_printf("snd_ssthresh: %lu snd_bandwidth: %lu snd_recover: "
1801 "0x%08x\n", tp->snd_ssthresh, tp->snd_bandwidth,
1804 db_print_indent(indent);
1805 db_printf("t_maxopd: %u t_rcvtime: %u t_startime: %u\n",
1806 tp->t_maxopd, tp->t_rcvtime, tp->t_starttime);
1808 db_print_indent(indent);
1809 db_printf("t_rttime: %u t_rtsq: 0x%08x t_bw_rtttime: %u\n",
1810 tp->t_rtttime, tp->t_rtseq, tp->t_bw_rtttime);
1812 db_print_indent(indent);
1813 db_printf("t_bw_rtseq: 0x%08x t_rxtcur: %d t_maxseg: %u "
1814 "t_srtt: %d\n", tp->t_bw_rtseq, tp->t_rxtcur, tp->t_maxseg,
1817 db_print_indent(indent);
1818 db_printf("t_rttvar: %d t_rxtshift: %d t_rttmin: %u "
1819 "t_rttbest: %u\n", tp->t_rttvar, tp->t_rxtshift, tp->t_rttmin,
1822 db_print_indent(indent);
1823 db_printf("t_rttupdated: %lu max_sndwnd: %lu t_softerror: %d\n",
1824 tp->t_rttupdated, tp->max_sndwnd, tp->t_softerror);
1826 db_print_indent(indent);
1827 db_printf("t_oobflags: 0x%x (", tp->t_oobflags);
1828 db_print_toobflags(tp->t_oobflags);
1829 db_printf(") t_iobc: 0x%02x\n", tp->t_iobc);
1831 db_print_indent(indent);
1832 db_printf("snd_scale: %u rcv_scale: %u request_r_scale: %u\n",
1833 tp->snd_scale, tp->rcv_scale, tp->request_r_scale);
1835 db_print_indent(indent);
1836 db_printf("ts_recent: %u ts_recent_age: %u\n",
1837 tp->ts_recent, tp->ts_recent_age);
1839 db_print_indent(indent);
1840 db_printf("ts_offset: %u last_ack_sent: 0x%08x snd_cwnd_prev: "
1841 "%lu\n", tp->ts_offset, tp->last_ack_sent, tp->snd_cwnd_prev);
1843 db_print_indent(indent);
1844 db_printf("snd_ssthresh_prev: %lu snd_recover_prev: 0x%08x "
1845 "t_badrxtwin: %u\n", tp->snd_ssthresh_prev,
1846 tp->snd_recover_prev, tp->t_badrxtwin);
1848 db_print_indent(indent);
1849 db_printf("snd_numholes: %d snd_holes first: %p\n",
1850 tp->snd_numholes, TAILQ_FIRST(&tp->snd_holes));
1852 db_print_indent(indent);
1853 db_printf("snd_fack: 0x%08x rcv_numsacks: %d sack_newdata: "
1854 "0x%08x\n", tp->snd_fack, tp->rcv_numsacks, tp->sack_newdata);
1856 /* Skip sackblks, sackhint. */
1858 db_print_indent(indent);
1859 db_printf("t_rttlow: %d rfbuf_ts: %u rfbuf_cnt: %d\n",
1860 tp->t_rttlow, tp->rfbuf_ts, tp->rfbuf_cnt);
1863 DB_SHOW_COMMAND(tcpcb, db_show_tcpcb)
1868 db_printf("usage: show tcpcb <addr>\n");
1871 tp = (struct tcpcb *)addr;
1873 db_print_tcpcb(tp, "tcpcb", 0);