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 static int tcp_attach(struct socket *);
91 static int tcp_connect(struct tcpcb *, struct sockaddr *,
94 static int tcp6_connect(struct tcpcb *, struct sockaddr *,
97 static void tcp_disconnect(struct tcpcb *);
98 static void tcp_usrclosed(struct tcpcb *);
99 static void tcp_fill_info(struct tcpcb *, struct tcp_info *);
102 #define TCPDEBUG0 int ostate = 0
103 #define TCPDEBUG1() ostate = tp ? tp->t_state : 0
104 #define TCPDEBUG2(req) if (tp && (so->so_options & SO_DEBUG)) \
105 tcp_trace(TA_USER, ostate, tp, 0, 0, req)
109 #define TCPDEBUG2(req)
113 * TCP attaches to socket via pru_attach(), reserving space,
114 * and an internet control block.
117 tcp_usr_attach(struct socket *so, int proto, struct thread *td)
120 struct tcpcb *tp = NULL;
125 KASSERT(inp == NULL, ("tcp_usr_attach: inp != NULL"));
128 error = tcp_attach(so);
132 if ((so->so_options & SO_LINGER) && so->so_linger == 0)
133 so->so_linger = TCP_LINGERTIME;
138 TCPDEBUG2(PRU_ATTACH);
143 * tcp_detach is called when the socket layer loses its final reference
144 * to the socket, be it a file descriptor reference, a reference from TCP,
145 * etc. At this point, there is only one case in which we will keep around
146 * inpcb state: time wait.
148 * This function can probably be re-absorbed back into tcp_usr_detach() now
149 * that there is a single detach path.
152 tcp_detach(struct socket *so, struct inpcb *inp)
156 int isipv6 = INP_CHECK_SOCKAF(so, AF_INET6) != 0;
159 INP_INFO_WLOCK_ASSERT(&tcbinfo);
160 INP_LOCK_ASSERT(inp);
162 KASSERT(so->so_pcb == inp, ("tcp_detach: so_pcb != inp"));
163 KASSERT(inp->inp_socket == so, ("tcp_detach: inp_socket != so"));
167 if (inp->inp_vflag & INP_TIMEWAIT) {
169 * There are two cases to handle: one in which the time wait
170 * state is being discarded (INP_DROPPED), and one in which
171 * this connection will remain in timewait. In the former,
172 * it is time to discard all state (except tcptw, which has
173 * already been discarded by the timewait close code, which
174 * should be further up the call stack somewhere). In the
175 * latter case, we detach from the socket, but leave the pcb
176 * present until timewait ends.
178 * XXXRW: Would it be cleaner to free the tcptw here?
180 if (inp->inp_vflag & INP_DROPPED) {
181 KASSERT(tp == NULL, ("tcp_detach: INP_TIMEWAIT && "
182 "INP_DROPPED && tp != NULL"));
205 * If the connection is not in timewait, we consider two
206 * two conditions: one in which no further processing is
207 * necessary (dropped || embryonic), and one in which TCP is
208 * not yet done, but no longer requires the socket, so the
209 * pcb will persist for the time being.
211 * XXXRW: Does the second case still occur?
213 if (inp->inp_vflag & INP_DROPPED ||
214 tp->t_state < TCPS_SYN_SENT) {
239 * pru_detach() detaches the TCP protocol from the socket.
240 * If the protocol state is non-embryonic, then can't
241 * do this directly: have to initiate a pru_disconnect(),
242 * which may finish later; embryonic TCB's can just
246 tcp_usr_detach(struct socket *so)
251 KASSERT(inp != NULL, ("tcp_usr_detach: inp == NULL"));
252 INP_INFO_WLOCK(&tcbinfo);
254 KASSERT(inp->inp_socket != NULL,
255 ("tcp_usr_detach: inp_socket == NULL"));
257 INP_INFO_WUNLOCK(&tcbinfo);
261 * Give the socket an address.
264 tcp_usr_bind(struct socket *so, struct sockaddr *nam, struct thread *td)
268 struct tcpcb *tp = NULL;
269 struct sockaddr_in *sinp;
271 sinp = (struct sockaddr_in *)nam;
272 if (nam->sa_len != sizeof (*sinp))
275 * Must check for multicast addresses and disallow binding
278 if (sinp->sin_family == AF_INET &&
279 IN_MULTICAST(ntohl(sinp->sin_addr.s_addr)))
280 return (EAFNOSUPPORT);
283 INP_INFO_WLOCK(&tcbinfo);
285 KASSERT(inp != NULL, ("tcp_usr_bind: inp == NULL"));
287 if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) {
293 error = in_pcbbind(inp, nam, td->td_ucred);
297 INP_INFO_WUNLOCK(&tcbinfo);
304 tcp6_usr_bind(struct socket *so, struct sockaddr *nam, struct thread *td)
308 struct tcpcb *tp = NULL;
309 struct sockaddr_in6 *sin6p;
311 sin6p = (struct sockaddr_in6 *)nam;
312 if (nam->sa_len != sizeof (*sin6p))
315 * Must check for multicast addresses and disallow binding
318 if (sin6p->sin6_family == AF_INET6 &&
319 IN6_IS_ADDR_MULTICAST(&sin6p->sin6_addr))
320 return (EAFNOSUPPORT);
323 INP_INFO_WLOCK(&tcbinfo);
325 KASSERT(inp != NULL, ("tcp6_usr_bind: inp == NULL"));
327 if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) {
333 inp->inp_vflag &= ~INP_IPV4;
334 inp->inp_vflag |= INP_IPV6;
335 if ((inp->inp_flags & IN6P_IPV6_V6ONLY) == 0) {
336 if (IN6_IS_ADDR_UNSPECIFIED(&sin6p->sin6_addr))
337 inp->inp_vflag |= INP_IPV4;
338 else if (IN6_IS_ADDR_V4MAPPED(&sin6p->sin6_addr)) {
339 struct sockaddr_in sin;
341 in6_sin6_2_sin(&sin, sin6p);
342 inp->inp_vflag |= INP_IPV4;
343 inp->inp_vflag &= ~INP_IPV6;
344 error = in_pcbbind(inp, (struct sockaddr *)&sin,
349 error = in6_pcbbind(inp, nam, td->td_ucred);
353 INP_INFO_WUNLOCK(&tcbinfo);
359 * Prepare to accept connections.
362 tcp_usr_listen(struct socket *so, int backlog, struct thread *td)
366 struct tcpcb *tp = NULL;
369 INP_INFO_WLOCK(&tcbinfo);
371 KASSERT(inp != NULL, ("tcp_usr_listen: inp == NULL"));
373 if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) {
380 error = solisten_proto_check(so);
381 if (error == 0 && inp->inp_lport == 0)
382 error = in_pcbbind(inp, (struct sockaddr *)0, td->td_ucred);
384 tp->t_state = TCPS_LISTEN;
385 solisten_proto(so, backlog);
390 TCPDEBUG2(PRU_LISTEN);
392 INP_INFO_WUNLOCK(&tcbinfo);
398 tcp6_usr_listen(struct socket *so, int backlog, struct thread *td)
402 struct tcpcb *tp = NULL;
405 INP_INFO_WLOCK(&tcbinfo);
407 KASSERT(inp != NULL, ("tcp6_usr_listen: inp == NULL"));
409 if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) {
416 error = solisten_proto_check(so);
417 if (error == 0 && inp->inp_lport == 0) {
418 inp->inp_vflag &= ~INP_IPV4;
419 if ((inp->inp_flags & IN6P_IPV6_V6ONLY) == 0)
420 inp->inp_vflag |= INP_IPV4;
421 error = in6_pcbbind(inp, (struct sockaddr *)0, td->td_ucred);
424 tp->t_state = TCPS_LISTEN;
425 solisten_proto(so, backlog);
430 TCPDEBUG2(PRU_LISTEN);
432 INP_INFO_WUNLOCK(&tcbinfo);
438 * Initiate connection to peer.
439 * Create a template for use in transmissions on this connection.
440 * Enter SYN_SENT state, and mark socket as connecting.
441 * Start keep-alive timer, and seed output sequence space.
442 * Send initial segment on connection.
445 tcp_usr_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
449 struct tcpcb *tp = NULL;
450 struct sockaddr_in *sinp;
452 sinp = (struct sockaddr_in *)nam;
453 if (nam->sa_len != sizeof (*sinp))
456 * Must disallow TCP ``connections'' to multicast addresses.
458 if (sinp->sin_family == AF_INET
459 && IN_MULTICAST(ntohl(sinp->sin_addr.s_addr)))
460 return (EAFNOSUPPORT);
461 if (jailed(td->td_ucred))
462 prison_remote_ip(td->td_ucred, 0, &sinp->sin_addr.s_addr);
465 INP_INFO_WLOCK(&tcbinfo);
467 KASSERT(inp != NULL, ("tcp_usr_connect: inp == NULL"));
469 if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) {
475 if ((error = tcp_connect(tp, nam, td)) != 0)
477 error = tcp_output(tp);
479 TCPDEBUG2(PRU_CONNECT);
481 INP_INFO_WUNLOCK(&tcbinfo);
487 tcp6_usr_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
491 struct tcpcb *tp = NULL;
492 struct sockaddr_in6 *sin6p;
496 sin6p = (struct sockaddr_in6 *)nam;
497 if (nam->sa_len != sizeof (*sin6p))
500 * Must disallow TCP ``connections'' to multicast addresses.
502 if (sin6p->sin6_family == AF_INET6
503 && IN6_IS_ADDR_MULTICAST(&sin6p->sin6_addr))
504 return (EAFNOSUPPORT);
506 INP_INFO_WLOCK(&tcbinfo);
508 KASSERT(inp != NULL, ("tcp6_usr_connect: inp == NULL"));
510 if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) {
516 if (IN6_IS_ADDR_V4MAPPED(&sin6p->sin6_addr)) {
517 struct sockaddr_in sin;
519 if ((inp->inp_flags & IN6P_IPV6_V6ONLY) != 0) {
524 in6_sin6_2_sin(&sin, sin6p);
525 inp->inp_vflag |= INP_IPV4;
526 inp->inp_vflag &= ~INP_IPV6;
527 if ((error = tcp_connect(tp, (struct sockaddr *)&sin, td)) != 0)
529 error = tcp_output(tp);
532 inp->inp_vflag &= ~INP_IPV4;
533 inp->inp_vflag |= INP_IPV6;
534 inp->inp_inc.inc_isipv6 = 1;
535 if ((error = tcp6_connect(tp, nam, td)) != 0)
537 error = tcp_output(tp);
540 TCPDEBUG2(PRU_CONNECT);
542 INP_INFO_WUNLOCK(&tcbinfo);
548 * Initiate disconnect from peer.
549 * If connection never passed embryonic stage, just drop;
550 * else if don't need to let data drain, then can just drop anyways,
551 * else have to begin TCP shutdown process: mark socket disconnecting,
552 * drain unread data, state switch to reflect user close, and
553 * send segment (e.g. FIN) to peer. Socket will be really disconnected
554 * when peer sends FIN and acks ours.
556 * SHOULD IMPLEMENT LATER PRU_CONNECT VIA REALLOC TCPCB.
559 tcp_usr_disconnect(struct socket *so)
562 struct tcpcb *tp = NULL;
566 INP_INFO_WLOCK(&tcbinfo);
568 KASSERT(inp != NULL, ("tcp_usr_disconnect: inp == NULL"));
570 if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) {
578 TCPDEBUG2(PRU_DISCONNECT);
580 INP_INFO_WUNLOCK(&tcbinfo);
585 * Accept a connection. Essentially all the work is
586 * done at higher levels; just return the address
587 * of the peer, storing through addr.
590 tcp_usr_accept(struct socket *so, struct sockaddr **nam)
593 struct inpcb *inp = NULL;
594 struct tcpcb *tp = NULL;
599 if (so->so_state & SS_ISDISCONNECTED)
600 return (ECONNABORTED);
603 KASSERT(inp != NULL, ("tcp_usr_accept: inp == NULL"));
605 if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) {
606 error = ECONNABORTED;
613 * We inline in_getpeeraddr and COMMON_END here, so that we can
614 * copy the data of interest and defer the malloc until after we
617 port = inp->inp_fport;
618 addr = inp->inp_faddr;
621 TCPDEBUG2(PRU_ACCEPT);
624 *nam = in_sockaddr(port, &addr);
630 tcp6_usr_accept(struct socket *so, struct sockaddr **nam)
632 struct inpcb *inp = NULL;
634 struct tcpcb *tp = NULL;
636 struct in6_addr addr6;
641 if (so->so_state & SS_ISDISCONNECTED)
642 return (ECONNABORTED);
645 KASSERT(inp != NULL, ("tcp6_usr_accept: inp == NULL"));
647 if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) {
648 error = ECONNABORTED;
655 * We inline in6_mapped_peeraddr and COMMON_END here, so that we can
656 * copy the data of interest and defer the malloc until after we
659 if (inp->inp_vflag & INP_IPV4) {
661 port = inp->inp_fport;
662 addr = inp->inp_faddr;
664 port = inp->inp_fport;
665 addr6 = inp->in6p_faddr;
669 TCPDEBUG2(PRU_ACCEPT);
673 *nam = in6_v4mapsin6_sockaddr(port, &addr);
675 *nam = in6_sockaddr(port, &addr6);
682 * Mark the connection as being incapable of further output.
685 tcp_usr_shutdown(struct socket *so)
689 struct tcpcb *tp = NULL;
692 INP_INFO_WLOCK(&tcbinfo);
694 KASSERT(inp != NULL, ("inp == NULL"));
696 if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) {
704 error = tcp_output(tp);
707 TCPDEBUG2(PRU_SHUTDOWN);
709 INP_INFO_WUNLOCK(&tcbinfo);
715 * After a receive, possibly send window update to peer.
718 tcp_usr_rcvd(struct socket *so, int flags)
721 struct tcpcb *tp = NULL;
726 KASSERT(inp != NULL, ("tcp_usr_rcvd: inp == NULL"));
728 if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) {
743 * Do a send by putting data in output queue and updating urgent
744 * marker if URG set. Possibly send more data. Unlike the other
745 * pru_*() routines, the mbuf chains are our responsibility. We
746 * must either enqueue them or free them. The other pru_* routines
747 * generally are caller-frees.
750 tcp_usr_send(struct socket *so, int flags, struct mbuf *m,
751 struct sockaddr *nam, struct mbuf *control, struct thread *td)
755 struct tcpcb *tp = NULL;
763 * We require the pcbinfo lock in two cases:
765 * (1) An implied connect is taking place, which can result in
766 * binding IPs and ports and hence modification of the pcb hash
769 * (2) PRUS_EOF is set, resulting in explicit close on the send.
771 if ((nam != NULL) || (flags & PRUS_EOF)) {
772 INP_INFO_WLOCK(&tcbinfo);
776 KASSERT(inp != NULL, ("tcp_usr_send: inp == NULL"));
778 if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) {
787 isipv6 = nam && nam->sa_family == AF_INET6;
792 /* TCP doesn't do control messages (rights, creds, etc) */
793 if (control->m_len) {
800 m_freem(control); /* empty control, just free it */
802 if (!(flags & PRUS_OOB)) {
803 sbappendstream(&so->so_snd, m);
804 if (nam && tp->t_state < TCPS_SYN_SENT) {
806 * Do implied connect if not yet connected,
807 * initialize window to default value, and
808 * initialize maxseg/maxopd using peer's cached
811 INP_INFO_WLOCK_ASSERT(&tcbinfo);
814 error = tcp6_connect(tp, nam, td);
817 error = tcp_connect(tp, nam, td);
820 tp->snd_wnd = TTCP_CLIENT_SND_WND;
823 if (flags & PRUS_EOF) {
825 * Close the send side of the connection after
828 INP_INFO_WLOCK_ASSERT(&tcbinfo);
833 INP_INFO_WUNLOCK(&tcbinfo);
837 if (flags & PRUS_MORETOCOME)
838 tp->t_flags |= TF_MORETOCOME;
839 error = tcp_output(tp);
840 if (flags & PRUS_MORETOCOME)
841 tp->t_flags &= ~TF_MORETOCOME;
845 * XXXRW: PRUS_EOF not implemented with PRUS_OOB?
847 SOCKBUF_LOCK(&so->so_snd);
848 if (sbspace(&so->so_snd) < -512) {
849 SOCKBUF_UNLOCK(&so->so_snd);
855 * According to RFC961 (Assigned Protocols),
856 * the urgent pointer points to the last octet
857 * of urgent data. We continue, however,
858 * to consider it to indicate the first octet
859 * of data past the urgent section.
860 * Otherwise, snd_up should be one lower.
862 sbappendstream_locked(&so->so_snd, m);
863 SOCKBUF_UNLOCK(&so->so_snd);
864 if (nam && tp->t_state < TCPS_SYN_SENT) {
866 * Do implied connect if not yet connected,
867 * initialize window to default value, and
868 * initialize maxseg/maxopd using peer's cached
871 INP_INFO_WLOCK_ASSERT(&tcbinfo);
874 error = tcp6_connect(tp, nam, td);
877 error = tcp_connect(tp, nam, td);
880 tp->snd_wnd = TTCP_CLIENT_SND_WND;
882 INP_INFO_WUNLOCK(&tcbinfo);
885 INP_INFO_WUNLOCK(&tcbinfo);
888 tp->snd_up = tp->snd_una + so->so_snd.sb_cc;
889 tp->t_flags |= TF_FORCEDATA;
890 error = tcp_output(tp);
891 tp->t_flags &= ~TF_FORCEDATA;
894 TCPDEBUG2((flags & PRUS_OOB) ? PRU_SENDOOB :
895 ((flags & PRUS_EOF) ? PRU_SEND_EOF : PRU_SEND));
898 INP_INFO_WUNLOCK(&tcbinfo);
903 * Abort the TCP. Drop the connection abruptly.
906 tcp_usr_abort(struct socket *so)
909 struct tcpcb *tp = NULL;
913 KASSERT(inp != NULL, ("tcp_usr_abort: inp == NULL"));
915 INP_INFO_WLOCK(&tcbinfo);
917 KASSERT(inp->inp_socket != NULL,
918 ("tcp_usr_abort: inp_socket == NULL"));
921 * If we still have full TCP state, and we're not dropped, drop.
923 if (!(inp->inp_vflag & INP_TIMEWAIT) &&
924 !(inp->inp_vflag & INP_DROPPED)) {
927 tcp_drop(tp, ECONNABORTED);
928 TCPDEBUG2(PRU_ABORT);
930 if (!(inp->inp_vflag & INP_DROPPED)) {
932 so->so_state |= SS_PROTOREF;
934 inp->inp_vflag |= INP_SOCKREF;
937 INP_INFO_WUNLOCK(&tcbinfo);
941 * TCP socket is closed. Start friendly disconnect.
944 tcp_usr_close(struct socket *so)
947 struct tcpcb *tp = NULL;
951 KASSERT(inp != NULL, ("tcp_usr_close: inp == NULL"));
953 INP_INFO_WLOCK(&tcbinfo);
955 KASSERT(inp->inp_socket != NULL,
956 ("tcp_usr_close: inp_socket == NULL"));
959 * If we still have full TCP state, and we're not dropped, initiate
962 if (!(inp->inp_vflag & INP_TIMEWAIT) &&
963 !(inp->inp_vflag & INP_DROPPED)) {
967 TCPDEBUG2(PRU_CLOSE);
969 if (!(inp->inp_vflag & INP_DROPPED)) {
971 so->so_state |= SS_PROTOREF;
973 inp->inp_vflag |= INP_SOCKREF;
976 INP_INFO_WUNLOCK(&tcbinfo);
980 * Receive out-of-band data.
983 tcp_usr_rcvoob(struct socket *so, struct mbuf *m, int flags)
987 struct tcpcb *tp = NULL;
991 KASSERT(inp != NULL, ("tcp_usr_rcvoob: inp == NULL"));
993 if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) {
999 if ((so->so_oobmark == 0 &&
1000 (so->so_rcv.sb_state & SBS_RCVATMARK) == 0) ||
1001 so->so_options & SO_OOBINLINE ||
1002 tp->t_oobflags & TCPOOB_HADDATA) {
1006 if ((tp->t_oobflags & TCPOOB_HAVEDATA) == 0) {
1007 error = EWOULDBLOCK;
1011 *mtod(m, caddr_t) = tp->t_iobc;
1012 if ((flags & MSG_PEEK) == 0)
1013 tp->t_oobflags ^= (TCPOOB_HAVEDATA | TCPOOB_HADDATA);
1016 TCPDEBUG2(PRU_RCVOOB);
1021 struct pr_usrreqs tcp_usrreqs = {
1022 .pru_abort = tcp_usr_abort,
1023 .pru_accept = tcp_usr_accept,
1024 .pru_attach = tcp_usr_attach,
1025 .pru_bind = tcp_usr_bind,
1026 .pru_connect = tcp_usr_connect,
1027 .pru_control = in_control,
1028 .pru_detach = tcp_usr_detach,
1029 .pru_disconnect = tcp_usr_disconnect,
1030 .pru_listen = tcp_usr_listen,
1031 .pru_peeraddr = in_getpeeraddr,
1032 .pru_rcvd = tcp_usr_rcvd,
1033 .pru_rcvoob = tcp_usr_rcvoob,
1034 .pru_send = tcp_usr_send,
1035 .pru_shutdown = tcp_usr_shutdown,
1036 .pru_sockaddr = in_getsockaddr,
1037 .pru_sosetlabel = in_pcbsosetlabel,
1038 .pru_close = tcp_usr_close,
1042 struct pr_usrreqs tcp6_usrreqs = {
1043 .pru_abort = tcp_usr_abort,
1044 .pru_accept = tcp6_usr_accept,
1045 .pru_attach = tcp_usr_attach,
1046 .pru_bind = tcp6_usr_bind,
1047 .pru_connect = tcp6_usr_connect,
1048 .pru_control = in6_control,
1049 .pru_detach = tcp_usr_detach,
1050 .pru_disconnect = tcp_usr_disconnect,
1051 .pru_listen = tcp6_usr_listen,
1052 .pru_peeraddr = in6_mapped_peeraddr,
1053 .pru_rcvd = tcp_usr_rcvd,
1054 .pru_rcvoob = tcp_usr_rcvoob,
1055 .pru_send = tcp_usr_send,
1056 .pru_shutdown = tcp_usr_shutdown,
1057 .pru_sockaddr = in6_mapped_sockaddr,
1058 .pru_sosetlabel = in_pcbsosetlabel,
1059 .pru_close = tcp_usr_close,
1064 * Common subroutine to open a TCP connection to remote host specified
1065 * by struct sockaddr_in in mbuf *nam. Call in_pcbbind to assign a local
1066 * port number if needed. Call in_pcbconnect_setup to do the routing and
1067 * to choose a local host address (interface). If there is an existing
1068 * incarnation of the same connection in TIME-WAIT state and if the remote
1069 * host was sending CC options and if the connection duration was < MSL, then
1070 * truncate the previous TIME-WAIT state and proceed.
1071 * Initialize connection parameters and enter SYN-SENT state.
1074 tcp_connect(struct tcpcb *tp, struct sockaddr *nam, struct thread *td)
1076 struct inpcb *inp = tp->t_inpcb, *oinp;
1077 struct socket *so = inp->inp_socket;
1078 struct in_addr laddr;
1082 INP_INFO_WLOCK_ASSERT(&tcbinfo);
1083 INP_LOCK_ASSERT(inp);
1085 if (inp->inp_lport == 0) {
1086 error = in_pcbbind(inp, (struct sockaddr *)0, td->td_ucred);
1092 * Cannot simply call in_pcbconnect, because there might be an
1093 * earlier incarnation of this same connection still in
1094 * TIME_WAIT state, creating an ADDRINUSE error.
1096 laddr = inp->inp_laddr;
1097 lport = inp->inp_lport;
1098 error = in_pcbconnect_setup(inp, nam, &laddr.s_addr, &lport,
1099 &inp->inp_faddr.s_addr, &inp->inp_fport, &oinp, td->td_ucred);
1100 if (error && oinp == NULL)
1104 inp->inp_laddr = laddr;
1108 * Compute window scaling to request:
1109 * Scale to fit into sweet spot. See tcp_syncache.c.
1110 * XXX: This should move to tcp_output().
1111 * XXX: This should be based on the actual MSS.
1113 while (tp->request_r_scale < TCP_MAX_WINSHIFT &&
1114 (0x1 << tp->request_r_scale) < tcp_minmss)
1115 tp->request_r_scale++;
1118 tcpstat.tcps_connattempt++;
1119 tp->t_state = TCPS_SYN_SENT;
1120 tcp_timer_activate(tp, TT_KEEP, tcp_keepinit);
1121 tp->iss = tcp_new_isn(tp);
1122 tp->t_bw_rtseq = tp->iss;
1123 tcp_sendseqinit(tp);
1130 tcp6_connect(struct tcpcb *tp, struct sockaddr *nam, struct thread *td)
1132 struct inpcb *inp = tp->t_inpcb, *oinp;
1133 struct socket *so = inp->inp_socket;
1134 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)nam;
1135 struct in6_addr *addr6;
1138 INP_INFO_WLOCK_ASSERT(&tcbinfo);
1139 INP_LOCK_ASSERT(inp);
1141 if (inp->inp_lport == 0) {
1142 error = in6_pcbbind(inp, (struct sockaddr *)0, td->td_ucred);
1148 * Cannot simply call in_pcbconnect, because there might be an
1149 * earlier incarnation of this same connection still in
1150 * TIME_WAIT state, creating an ADDRINUSE error.
1151 * in6_pcbladdr() also handles scope zone IDs.
1153 error = in6_pcbladdr(inp, nam, &addr6);
1156 oinp = in6_pcblookup_hash(inp->inp_pcbinfo,
1157 &sin6->sin6_addr, sin6->sin6_port,
1158 IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_laddr)
1161 inp->inp_lport, 0, NULL);
1164 if (IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_laddr))
1165 inp->in6p_laddr = *addr6;
1166 inp->in6p_faddr = sin6->sin6_addr;
1167 inp->inp_fport = sin6->sin6_port;
1168 /* update flowinfo - draft-itojun-ipv6-flowlabel-api-00 */
1169 inp->in6p_flowinfo &= ~IPV6_FLOWLABEL_MASK;
1170 if (inp->in6p_flags & IN6P_AUTOFLOWLABEL)
1171 inp->in6p_flowinfo |=
1172 (htonl(ip6_randomflowlabel()) & IPV6_FLOWLABEL_MASK);
1175 /* Compute window scaling to request. */
1176 while (tp->request_r_scale < TCP_MAX_WINSHIFT &&
1177 (TCP_MAXWIN << tp->request_r_scale) < so->so_rcv.sb_hiwat)
1178 tp->request_r_scale++;
1181 tcpstat.tcps_connattempt++;
1182 tp->t_state = TCPS_SYN_SENT;
1183 tcp_timer_activate(tp, TT_KEEP, tcp_keepinit);
1184 tp->iss = tcp_new_isn(tp);
1185 tp->t_bw_rtseq = tp->iss;
1186 tcp_sendseqinit(tp);
1193 * Export TCP internal state information via a struct tcp_info, based on the
1194 * Linux 2.6 API. Not ABI compatible as our constants are mapped differently
1195 * (TCP state machine, etc). We export all information using FreeBSD-native
1196 * constants -- for example, the numeric values for tcpi_state will differ
1200 tcp_fill_info(struct tcpcb *tp, struct tcp_info *ti)
1203 INP_LOCK_ASSERT(tp->t_inpcb);
1204 bzero(ti, sizeof(*ti));
1206 ti->tcpi_state = tp->t_state;
1207 if ((tp->t_flags & TF_REQ_TSTMP) && (tp->t_flags & TF_RCVD_TSTMP))
1208 ti->tcpi_options |= TCPI_OPT_TIMESTAMPS;
1209 if (tp->t_flags & TF_SACK_PERMIT)
1210 ti->tcpi_options |= TCPI_OPT_SACK;
1211 if ((tp->t_flags & TF_REQ_SCALE) && (tp->t_flags & TF_RCVD_SCALE)) {
1212 ti->tcpi_options |= TCPI_OPT_WSCALE;
1213 ti->tcpi_snd_wscale = tp->snd_scale;
1214 ti->tcpi_rcv_wscale = tp->rcv_scale;
1217 ti->tcpi_rtt = ((u_int64_t)tp->t_srtt * tick) >> TCP_RTT_SHIFT;
1218 ti->tcpi_rttvar = ((u_int64_t)tp->t_rttvar * tick) >> TCP_RTTVAR_SHIFT;
1220 ti->tcpi_snd_ssthresh = tp->snd_ssthresh;
1221 ti->tcpi_snd_cwnd = tp->snd_cwnd;
1224 * FreeBSD-specific extension fields for tcp_info.
1226 ti->tcpi_rcv_space = tp->rcv_wnd;
1227 ti->tcpi_snd_wnd = tp->snd_wnd;
1228 ti->tcpi_snd_bwnd = tp->snd_bwnd;
1232 * The new sockopt interface makes it possible for us to block in the
1233 * copyin/out step (if we take a page fault). Taking a page fault at
1234 * splnet() is probably a Bad Thing. (Since sockets and pcbs both now
1235 * use TSM, there probably isn't any need for this function to run at
1236 * splnet() any more. This needs more examination.)
1238 * XXXRW: The locking here is wrong; we may take a page fault while holding
1242 tcp_ctloutput(struct socket *so, struct sockopt *sopt)
1244 int error, opt, optval;
1250 inp = sotoinpcb(so);
1251 KASSERT(inp != NULL, ("tcp_ctloutput: inp == NULL"));
1253 if (sopt->sopt_level != IPPROTO_TCP) {
1256 if (INP_CHECK_SOCKAF(so, AF_INET6))
1257 error = ip6_ctloutput(so, sopt);
1260 error = ip_ctloutput(so, sopt);
1263 if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) {
1267 tp = intotcpcb(inp);
1269 switch (sopt->sopt_dir) {
1271 switch (sopt->sopt_name) {
1272 #ifdef TCP_SIGNATURE
1274 error = sooptcopyin(sopt, &optval, sizeof optval,
1280 tp->t_flags |= TF_SIGNATURE;
1282 tp->t_flags &= ~TF_SIGNATURE;
1284 #endif /* TCP_SIGNATURE */
1287 error = sooptcopyin(sopt, &optval, sizeof optval,
1292 switch (sopt->sopt_name) {
1300 opt = 0; /* dead code to fool gcc */
1307 tp->t_flags &= ~opt;
1311 error = sooptcopyin(sopt, &optval, sizeof optval,
1317 tp->t_flags |= TF_NOPUSH;
1319 tp->t_flags &= ~TF_NOPUSH;
1320 error = tcp_output(tp);
1325 error = sooptcopyin(sopt, &optval, sizeof optval,
1330 if (optval > 0 && optval <= tp->t_maxseg &&
1331 optval + 40 >= tcp_minmss)
1332 tp->t_maxseg = optval;
1342 error = ENOPROTOOPT;
1348 switch (sopt->sopt_name) {
1349 #ifdef TCP_SIGNATURE
1351 optval = (tp->t_flags & TF_SIGNATURE) ? 1 : 0;
1352 error = sooptcopyout(sopt, &optval, sizeof optval);
1356 optval = tp->t_flags & TF_NODELAY;
1357 error = sooptcopyout(sopt, &optval, sizeof optval);
1360 optval = tp->t_maxseg;
1361 error = sooptcopyout(sopt, &optval, sizeof optval);
1364 optval = tp->t_flags & TF_NOOPT;
1365 error = sooptcopyout(sopt, &optval, sizeof optval);
1368 optval = tp->t_flags & TF_NOPUSH;
1369 error = sooptcopyout(sopt, &optval, sizeof optval);
1372 tcp_fill_info(tp, &ti);
1373 error = sooptcopyout(sopt, &ti, sizeof ti);
1376 error = ENOPROTOOPT;
1387 * tcp_sendspace and tcp_recvspace are the default send and receive window
1388 * sizes, respectively. These are obsolescent (this information should
1389 * be set by the route).
1391 u_long tcp_sendspace = 1024*32;
1392 SYSCTL_ULONG(_net_inet_tcp, TCPCTL_SENDSPACE, sendspace, CTLFLAG_RW,
1393 &tcp_sendspace , 0, "Maximum outgoing TCP datagram size");
1394 u_long tcp_recvspace = 1024*64;
1395 SYSCTL_ULONG(_net_inet_tcp, TCPCTL_RECVSPACE, recvspace, CTLFLAG_RW,
1396 &tcp_recvspace , 0, "Maximum incoming TCP datagram size");
1399 * Attach TCP protocol to socket, allocating
1400 * internet protocol control block, tcp control block,
1401 * bufer space, and entering LISTEN state if to accept connections.
1404 tcp_attach(struct socket *so)
1410 int isipv6 = INP_CHECK_SOCKAF(so, AF_INET6) != 0;
1413 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
1414 error = soreserve(so, tcp_sendspace, tcp_recvspace);
1418 so->so_rcv.sb_flags |= SB_AUTOSIZE;
1419 so->so_snd.sb_flags |= SB_AUTOSIZE;
1420 INP_INFO_WLOCK(&tcbinfo);
1421 error = in_pcballoc(so, &tcbinfo);
1423 INP_INFO_WUNLOCK(&tcbinfo);
1426 inp = sotoinpcb(so);
1429 inp->inp_vflag |= INP_IPV6;
1430 inp->in6p_hops = -1; /* use kernel default */
1434 inp->inp_vflag |= INP_IPV4;
1435 tp = tcp_newtcpcb(inp);
1448 INP_INFO_WUNLOCK(&tcbinfo);
1451 tp->t_state = TCPS_CLOSED;
1453 INP_INFO_WUNLOCK(&tcbinfo);
1458 * Initiate (or continue) disconnect.
1459 * If embryonic state, just send reset (once).
1460 * If in ``let data drain'' option and linger null, just drop.
1461 * Otherwise (hard), mark socket disconnecting and drop
1462 * current input data; switch states based on user close, and
1463 * send segment to peer (with FIN).
1466 tcp_disconnect(struct tcpcb *tp)
1468 struct inpcb *inp = tp->t_inpcb;
1469 struct socket *so = inp->inp_socket;
1471 INP_INFO_WLOCK_ASSERT(&tcbinfo);
1472 INP_LOCK_ASSERT(inp);
1475 * Neither tcp_close() nor tcp_drop() should return NULL, as the
1476 * socket is still open.
1478 if (tp->t_state < TCPS_ESTABLISHED) {
1481 ("tcp_disconnect: tcp_close() returned NULL"));
1482 } else if ((so->so_options & SO_LINGER) && so->so_linger == 0) {
1483 tp = tcp_drop(tp, 0);
1485 ("tcp_disconnect: tcp_drop() returned NULL"));
1487 soisdisconnecting(so);
1488 sbflush(&so->so_rcv);
1490 if (!(inp->inp_vflag & INP_DROPPED))
1496 * User issued close, and wish to trail through shutdown states:
1497 * if never received SYN, just forget it. If got a SYN from peer,
1498 * but haven't sent FIN, then go to FIN_WAIT_1 state to send peer a FIN.
1499 * If already got a FIN from peer, then almost done; go to LAST_ACK
1500 * state. In all other cases, have already sent FIN to peer (e.g.
1501 * after PRU_SHUTDOWN), and just have to play tedious game waiting
1502 * for peer to send FIN or not respond to keep-alives, etc.
1503 * We can let the user exit from the close as soon as the FIN is acked.
1506 tcp_usrclosed(struct tcpcb *tp)
1509 INP_INFO_WLOCK_ASSERT(&tcbinfo);
1510 INP_LOCK_ASSERT(tp->t_inpcb);
1512 switch (tp->t_state) {
1515 tp->t_state = TCPS_CLOSED;
1518 * tcp_close() should never return NULL here as the socket is
1522 ("tcp_usrclosed: tcp_close() returned NULL"));
1526 case TCPS_SYN_RECEIVED:
1527 tp->t_flags |= TF_NEEDFIN;
1530 case TCPS_ESTABLISHED:
1531 tp->t_state = TCPS_FIN_WAIT_1;
1534 case TCPS_CLOSE_WAIT:
1535 tp->t_state = TCPS_LAST_ACK;
1538 if (tp->t_state >= TCPS_FIN_WAIT_2) {
1539 soisdisconnected(tp->t_inpcb->inp_socket);
1540 /* Prevent the connection hanging in FIN_WAIT_2 forever. */
1541 if (tp->t_state == TCPS_FIN_WAIT_2) {
1544 timeout = (tcp_fast_finwait2_recycle) ?
1545 tcp_finwait2_timeout : tcp_maxidle;
1546 tcp_timer_activate(tp, TT_2MSL, timeout);
1553 db_print_indent(int indent)
1557 for (i = 0; i < indent; i++)
1562 db_print_tstate(int t_state)
1567 db_printf("TCPS_CLOSED");
1571 db_printf("TCPS_LISTEN");
1575 db_printf("TCPS_SYN_SENT");
1578 case TCPS_SYN_RECEIVED:
1579 db_printf("TCPS_SYN_RECEIVED");
1582 case TCPS_ESTABLISHED:
1583 db_printf("TCPS_ESTABLISHED");
1586 case TCPS_CLOSE_WAIT:
1587 db_printf("TCPS_CLOSE_WAIT");
1590 case TCPS_FIN_WAIT_1:
1591 db_printf("TCPS_FIN_WAIT_1");
1595 db_printf("TCPS_CLOSING");
1599 db_printf("TCPS_LAST_ACK");
1602 case TCPS_FIN_WAIT_2:
1603 db_printf("TCPS_FIN_WAIT_2");
1606 case TCPS_TIME_WAIT:
1607 db_printf("TCPS_TIME_WAIT");
1611 db_printf("unknown");
1617 db_print_tflags(u_int t_flags)
1622 if (t_flags & TF_ACKNOW) {
1623 db_printf("%sTF_ACKNOW", comma ? ", " : "");
1626 if (t_flags & TF_DELACK) {
1627 db_printf("%sTF_DELACK", comma ? ", " : "");
1630 if (t_flags & TF_NODELAY) {
1631 db_printf("%sTF_NODELAY", comma ? ", " : "");
1634 if (t_flags & TF_NOOPT) {
1635 db_printf("%sTF_NOOPT", comma ? ", " : "");
1638 if (t_flags & TF_SENTFIN) {
1639 db_printf("%sTF_SENTFIN", comma ? ", " : "");
1642 if (t_flags & TF_REQ_SCALE) {
1643 db_printf("%sTF_REQ_SCALE", comma ? ", " : "");
1646 if (t_flags & TF_RCVD_SCALE) {
1647 db_printf("%sTF_RECVD_SCALE", comma ? ", " : "");
1650 if (t_flags & TF_REQ_TSTMP) {
1651 db_printf("%sTF_REQ_TSTMP", comma ? ", " : "");
1654 if (t_flags & TF_RCVD_TSTMP) {
1655 db_printf("%sTF_RCVD_TSTMP", comma ? ", " : "");
1658 if (t_flags & TF_SACK_PERMIT) {
1659 db_printf("%sTF_SACK_PERMIT", comma ? ", " : "");
1662 if (t_flags & TF_NEEDSYN) {
1663 db_printf("%sTF_NEEDSYN", comma ? ", " : "");
1666 if (t_flags & TF_NEEDFIN) {
1667 db_printf("%sTF_NEEDFIN", comma ? ", " : "");
1670 if (t_flags & TF_NOPUSH) {
1671 db_printf("%sTF_NOPUSH", comma ? ", " : "");
1674 if (t_flags & TF_NOPUSH) {
1675 db_printf("%sTF_NOPUSH", comma ? ", " : "");
1678 if (t_flags & TF_MORETOCOME) {
1679 db_printf("%sTF_MORETOCOME", comma ? ", " : "");
1682 if (t_flags & TF_LQ_OVERFLOW) {
1683 db_printf("%sTF_LQ_OVERFLOW", comma ? ", " : "");
1686 if (t_flags & TF_LASTIDLE) {
1687 db_printf("%sTF_LASTIDLE", comma ? ", " : "");
1690 if (t_flags & TF_RXWIN0SENT) {
1691 db_printf("%sTF_RXWIN0SENT", comma ? ", " : "");
1694 if (t_flags & TF_FASTRECOVERY) {
1695 db_printf("%sTF_FASTRECOVERY", comma ? ", " : "");
1698 if (t_flags & TF_WASFRECOVERY) {
1699 db_printf("%sTF_WASFRECOVERY", comma ? ", " : "");
1702 if (t_flags & TF_SIGNATURE) {
1703 db_printf("%sTF_SIGNATURE", comma ? ", " : "");
1706 if (t_flags & TF_FORCEDATA) {
1707 db_printf("%sTF_FORCEDATA", comma ? ", " : "");
1710 if (t_flags & TF_TSO) {
1711 db_printf("%sTF_TSO", comma ? ", " : "");
1717 db_print_toobflags(char t_oobflags)
1722 if (t_oobflags & TCPOOB_HAVEDATA) {
1723 db_printf("%sTCPOOB_HAVEDATA", comma ? ", " : "");
1726 if (t_oobflags & TCPOOB_HADDATA) {
1727 db_printf("%sTCPOOB_HADDATA", comma ? ", " : "");
1733 db_print_tcpcb(struct tcpcb *tp, const char *name, int indent)
1736 db_print_indent(indent);
1737 db_printf("%s at %p\n", name, tp);
1741 db_print_indent(indent);
1742 db_printf("t_segq first: %p t_segqlen: %d t_dupacks: %d\n",
1743 LIST_FIRST(&tp->t_segq), tp->t_segqlen, tp->t_dupacks);
1745 db_print_indent(indent);
1746 db_printf("tt_rexmt: %p tt_persist: %p tt_keep: %p\n",
1747 &tp->t_timers->tt_rexmt, &tp->t_timers->tt_persist, &tp->t_timers->tt_keep);
1749 db_print_indent(indent);
1750 db_printf("tt_2msl: %p tt_delack: %p t_inpcb: %p\n", &tp->t_timers->tt_2msl,
1751 &tp->t_timers->tt_delack, tp->t_inpcb);
1753 db_print_indent(indent);
1754 db_printf("t_state: %d (", tp->t_state);
1755 db_print_tstate(tp->t_state);
1758 db_print_indent(indent);
1759 db_printf("t_flags: 0x%x (", tp->t_flags);
1760 db_print_tflags(tp->t_flags);
1763 db_print_indent(indent);
1764 db_printf("snd_una: 0x%08x snd_max: 0x%08x snd_nxt: x0%08x\n",
1765 tp->snd_una, tp->snd_max, tp->snd_nxt);
1767 db_print_indent(indent);
1768 db_printf("snd_up: 0x%08x snd_wl1: 0x%08x snd_wl2: 0x%08x\n",
1769 tp->snd_up, tp->snd_wl1, tp->snd_wl2);
1771 db_print_indent(indent);
1772 db_printf("iss: 0x%08x irs: 0x%08x rcv_nxt: 0x%08x\n",
1773 tp->iss, tp->irs, tp->rcv_nxt);
1775 db_print_indent(indent);
1776 db_printf("rcv_adv: 0x%08x rcv_wnd: %lu rcv_up: 0x%08x\n",
1777 tp->rcv_adv, tp->rcv_wnd, tp->rcv_up);
1779 db_print_indent(indent);
1780 db_printf("snd_wnd: %lu snd_cwnd: %lu snd_bwnd: %lu\n",
1781 tp->snd_wnd, tp->snd_cwnd, tp->snd_bwnd);
1783 db_print_indent(indent);
1784 db_printf("snd_ssthresh: %lu snd_bandwidth: %lu snd_recover: "
1785 "0x%08x\n", tp->snd_ssthresh, tp->snd_bandwidth,
1788 db_print_indent(indent);
1789 db_printf("t_maxopd: %u t_rcvtime: %lu t_startime: %lu\n",
1790 tp->t_maxopd, tp->t_rcvtime, tp->t_starttime);
1792 db_print_indent(indent);
1793 db_printf("t_rttime: %d t_rtsq: 0x%08x t_bw_rtttime: %d\n",
1794 tp->t_rtttime, tp->t_rtseq, tp->t_bw_rtttime);
1796 db_print_indent(indent);
1797 db_printf("t_bw_rtseq: 0x%08x t_rxtcur: %d t_maxseg: %u "
1798 "t_srtt: %d\n", tp->t_bw_rtseq, tp->t_rxtcur, tp->t_maxseg,
1801 db_print_indent(indent);
1802 db_printf("t_rttvar: %d t_rxtshift: %d t_rttmin: %u "
1803 "t_rttbest: %u\n", tp->t_rttvar, tp->t_rxtshift, tp->t_rttmin,
1806 db_print_indent(indent);
1807 db_printf("t_rttupdated: %lu max_sndwnd: %lu t_softerror: %d\n",
1808 tp->t_rttupdated, tp->max_sndwnd, tp->t_softerror);
1810 db_print_indent(indent);
1811 db_printf("t_oobflags: 0x%x (", tp->t_oobflags);
1812 db_print_toobflags(tp->t_oobflags);
1813 db_printf(") t_iobc: 0x%02x\n", tp->t_iobc);
1815 db_print_indent(indent);
1816 db_printf("snd_scale: %u rcv_scale: %u request_r_scale: %u\n",
1817 tp->snd_scale, tp->rcv_scale, tp->request_r_scale);
1819 db_print_indent(indent);
1820 db_printf("ts_recent: %u ts_recent_age: %lu\n",
1821 tp->ts_recent, tp->ts_recent_age);
1823 db_print_indent(indent);
1824 db_printf("ts_offset: %u last_ack_sent: 0x%08x snd_cwnd_prev: "
1825 "%lu\n", tp->ts_offset, tp->last_ack_sent, tp->snd_cwnd_prev);
1827 db_print_indent(indent);
1828 db_printf("snd_ssthresh_prev: %lu snd_recover_prev: 0x%08x "
1829 "t_badrxtwin: %lu\n", tp->snd_ssthresh_prev,
1830 tp->snd_recover_prev, tp->t_badrxtwin);
1832 db_print_indent(indent);
1833 db_printf("snd_numholes: %d snd_holes first: %p\n",
1834 tp->snd_numholes, TAILQ_FIRST(&tp->snd_holes));
1836 db_print_indent(indent);
1837 db_printf("snd_fack: 0x%08x rcv_numsacks: %d sack_newdata: "
1838 "0x%08x\n", tp->snd_fack, tp->rcv_numsacks, tp->sack_newdata);
1840 /* Skip sackblks, sackhint. */
1842 db_print_indent(indent);
1843 db_printf("t_rttlow: %d rfbuf_ts: %u rfbuf_cnt: %d\n",
1844 tp->t_rttlow, tp->rfbuf_ts, tp->rfbuf_cnt);
1847 DB_SHOW_COMMAND(tcpcb, db_show_tcpcb)
1852 db_printf("usage: show tcpcb <addr>\n");
1855 tp = (struct tcpcb *)addr;
1857 db_print_tcpcb(tp, "tcpcb", 0);