2 * Copyright (c) 1982, 1986, 1988, 1993
3 * The Regents of the University of California.
4 * Copyright (c) 2006-2007 Robert N. M. Watson
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 4. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * From: @(#)tcp_usrreq.c 8.2 (Berkeley) 1/3/94
37 #include "opt_inet6.h"
38 #include "opt_tcpdebug.h"
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/malloc.h>
43 #include <sys/kernel.h>
44 #include <sys/sysctl.h>
47 #include <sys/domain.h>
49 #include <sys/socket.h>
50 #include <sys/socketvar.h>
51 #include <sys/protosw.h>
60 #include <net/route.h>
62 #include <netinet/in.h>
63 #include <netinet/in_systm.h>
65 #include <netinet/ip6.h>
67 #include <netinet/in_pcb.h>
69 #include <netinet6/in6_pcb.h>
71 #include <netinet/in_var.h>
72 #include <netinet/ip_var.h>
74 #include <netinet6/ip6_var.h>
75 #include <netinet6/scope6_var.h>
77 #include <netinet/tcp.h>
78 #include <netinet/tcp_fsm.h>
79 #include <netinet/tcp_seq.h>
80 #include <netinet/tcp_timer.h>
81 #include <netinet/tcp_var.h>
82 #include <netinet/tcpip.h>
84 #include <netinet/tcp_debug.h>
88 * TCP protocol interface to socket abstraction.
90 extern char *tcpstates[]; /* XXX ??? */
92 static int tcp_attach(struct socket *);
93 static int tcp_connect(struct tcpcb *, struct sockaddr *,
96 static int tcp6_connect(struct tcpcb *, struct sockaddr *,
99 static void tcp_disconnect(struct tcpcb *);
100 static void tcp_usrclosed(struct tcpcb *);
101 static void tcp_fill_info(struct tcpcb *, struct tcp_info *);
104 #define TCPDEBUG0 int ostate = 0
105 #define TCPDEBUG1() ostate = tp ? tp->t_state : 0
106 #define TCPDEBUG2(req) if (tp && (so->so_options & SO_DEBUG)) \
107 tcp_trace(TA_USER, ostate, tp, 0, 0, req)
111 #define TCPDEBUG2(req)
115 * TCP attaches to socket via pru_attach(), reserving space,
116 * and an internet control block.
119 tcp_usr_attach(struct socket *so, int proto, struct thread *td)
122 struct tcpcb *tp = NULL;
127 KASSERT(inp == NULL, ("tcp_usr_attach: inp != NULL"));
130 error = tcp_attach(so);
134 if ((so->so_options & SO_LINGER) && so->so_linger == 0)
135 so->so_linger = TCP_LINGERTIME;
140 TCPDEBUG2(PRU_ATTACH);
145 * tcp_detach is called when the socket layer loses its final reference
146 * to the socket, be it a file descriptor reference, a reference from TCP,
147 * etc. At this point, there is only one case in which we will keep around
148 * inpcb state: time wait.
150 * This function can probably be re-absorbed back into tcp_usr_detach() now
151 * that there is a single detach path.
154 tcp_detach(struct socket *so, struct inpcb *inp)
158 int isipv6 = INP_CHECK_SOCKAF(so, AF_INET6) != 0;
161 INP_INFO_WLOCK_ASSERT(&tcbinfo);
162 INP_LOCK_ASSERT(inp);
164 KASSERT(so->so_pcb == inp, ("tcp_detach: so_pcb != inp"));
165 KASSERT(inp->inp_socket == so, ("tcp_detach: inp_socket != so"));
169 if (inp->inp_vflag & INP_TIMEWAIT) {
171 * There are two cases to handle: one in which the time wait
172 * state is being discarded (INP_DROPPED), and one in which
173 * this connection will remain in timewait. In the former,
174 * it is time to discard all state (except tcptw, which has
175 * already been discarded by the timewait close code, which
176 * should be further up the call stack somewhere). In the
177 * latter case, we detach from the socket, but leave the pcb
178 * present until timewait ends.
180 * XXXRW: Would it be cleaner to free the tcptw here?
182 if (inp->inp_vflag & INP_DROPPED) {
183 KASSERT(tp == NULL, ("tcp_detach: INP_TIMEWAIT && "
184 "INP_DROPPED && tp != NULL"));
207 * If the connection is not in timewait, we consider two
208 * two conditions: one in which no further processing is
209 * necessary (dropped || embryonic), and one in which TCP is
210 * not yet done, but no longer requires the socket, so the
211 * pcb will persist for the time being.
213 * XXXRW: Does the second case still occur?
215 if (inp->inp_vflag & INP_DROPPED ||
216 tp->t_state < TCPS_SYN_SENT) {
241 * pru_detach() detaches the TCP protocol from the socket.
242 * If the protocol state is non-embryonic, then can't
243 * do this directly: have to initiate a pru_disconnect(),
244 * which may finish later; embryonic TCB's can just
248 tcp_usr_detach(struct socket *so)
255 KASSERT(inp != NULL, ("tcp_usr_detach: inp == NULL"));
256 INP_INFO_WLOCK(&tcbinfo);
258 KASSERT(inp->inp_socket != NULL,
259 ("tcp_usr_detach: inp_socket == NULL"));
264 TCPDEBUG2(PRU_DETACH);
265 INP_INFO_WUNLOCK(&tcbinfo);
269 * Give the socket an address.
272 tcp_usr_bind(struct socket *so, struct sockaddr *nam, struct thread *td)
276 struct tcpcb *tp = NULL;
277 struct sockaddr_in *sinp;
279 sinp = (struct sockaddr_in *)nam;
280 if (nam->sa_len != sizeof (*sinp))
283 * Must check for multicast addresses and disallow binding
286 if (sinp->sin_family == AF_INET &&
287 IN_MULTICAST(ntohl(sinp->sin_addr.s_addr)))
288 return (EAFNOSUPPORT);
291 INP_INFO_WLOCK(&tcbinfo);
293 KASSERT(inp != NULL, ("tcp_usr_bind: inp == NULL"));
295 if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) {
301 error = in_pcbbind(inp, nam, td->td_ucred);
305 INP_INFO_WUNLOCK(&tcbinfo);
312 tcp6_usr_bind(struct socket *so, struct sockaddr *nam, struct thread *td)
316 struct tcpcb *tp = NULL;
317 struct sockaddr_in6 *sin6p;
319 sin6p = (struct sockaddr_in6 *)nam;
320 if (nam->sa_len != sizeof (*sin6p))
323 * Must check for multicast addresses and disallow binding
326 if (sin6p->sin6_family == AF_INET6 &&
327 IN6_IS_ADDR_MULTICAST(&sin6p->sin6_addr))
328 return (EAFNOSUPPORT);
331 INP_INFO_WLOCK(&tcbinfo);
333 KASSERT(inp != NULL, ("tcp6_usr_bind: inp == NULL"));
335 if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) {
341 inp->inp_vflag &= ~INP_IPV4;
342 inp->inp_vflag |= INP_IPV6;
343 if ((inp->inp_flags & IN6P_IPV6_V6ONLY) == 0) {
344 if (IN6_IS_ADDR_UNSPECIFIED(&sin6p->sin6_addr))
345 inp->inp_vflag |= INP_IPV4;
346 else if (IN6_IS_ADDR_V4MAPPED(&sin6p->sin6_addr)) {
347 struct sockaddr_in sin;
349 in6_sin6_2_sin(&sin, sin6p);
350 inp->inp_vflag |= INP_IPV4;
351 inp->inp_vflag &= ~INP_IPV6;
352 error = in_pcbbind(inp, (struct sockaddr *)&sin,
357 error = in6_pcbbind(inp, nam, td->td_ucred);
361 INP_INFO_WUNLOCK(&tcbinfo);
367 * Prepare to accept connections.
370 tcp_usr_listen(struct socket *so, int backlog, struct thread *td)
374 struct tcpcb *tp = NULL;
377 INP_INFO_WLOCK(&tcbinfo);
379 KASSERT(inp != NULL, ("tcp_usr_listen: inp == NULL"));
381 if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) {
388 error = solisten_proto_check(so);
389 if (error == 0 && inp->inp_lport == 0)
390 error = in_pcbbind(inp, (struct sockaddr *)0, td->td_ucred);
392 tp->t_state = TCPS_LISTEN;
393 solisten_proto(so, backlog);
398 TCPDEBUG2(PRU_LISTEN);
400 INP_INFO_WUNLOCK(&tcbinfo);
406 tcp6_usr_listen(struct socket *so, int backlog, struct thread *td)
410 struct tcpcb *tp = NULL;
413 INP_INFO_WLOCK(&tcbinfo);
415 KASSERT(inp != NULL, ("tcp6_usr_listen: inp == NULL"));
417 if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) {
424 error = solisten_proto_check(so);
425 if (error == 0 && inp->inp_lport == 0) {
426 inp->inp_vflag &= ~INP_IPV4;
427 if ((inp->inp_flags & IN6P_IPV6_V6ONLY) == 0)
428 inp->inp_vflag |= INP_IPV4;
429 error = in6_pcbbind(inp, (struct sockaddr *)0, td->td_ucred);
432 tp->t_state = TCPS_LISTEN;
433 solisten_proto(so, backlog);
438 TCPDEBUG2(PRU_LISTEN);
440 INP_INFO_WUNLOCK(&tcbinfo);
446 * Initiate connection to peer.
447 * Create a template for use in transmissions on this connection.
448 * Enter SYN_SENT state, and mark socket as connecting.
449 * Start keep-alive timer, and seed output sequence space.
450 * Send initial segment on connection.
453 tcp_usr_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
457 struct tcpcb *tp = NULL;
458 struct sockaddr_in *sinp;
460 sinp = (struct sockaddr_in *)nam;
461 if (nam->sa_len != sizeof (*sinp))
464 * Must disallow TCP ``connections'' to multicast addresses.
466 if (sinp->sin_family == AF_INET
467 && IN_MULTICAST(ntohl(sinp->sin_addr.s_addr)))
468 return (EAFNOSUPPORT);
469 if (jailed(td->td_ucred))
470 prison_remote_ip(td->td_ucred, 0, &sinp->sin_addr.s_addr);
473 INP_INFO_WLOCK(&tcbinfo);
475 KASSERT(inp != NULL, ("tcp_usr_connect: inp == NULL"));
477 if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) {
483 if ((error = tcp_connect(tp, nam, td)) != 0)
485 error = tcp_output(tp);
487 TCPDEBUG2(PRU_CONNECT);
489 INP_INFO_WUNLOCK(&tcbinfo);
495 tcp6_usr_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
499 struct tcpcb *tp = NULL;
500 struct sockaddr_in6 *sin6p;
504 sin6p = (struct sockaddr_in6 *)nam;
505 if (nam->sa_len != sizeof (*sin6p))
508 * Must disallow TCP ``connections'' to multicast addresses.
510 if (sin6p->sin6_family == AF_INET6
511 && IN6_IS_ADDR_MULTICAST(&sin6p->sin6_addr))
512 return (EAFNOSUPPORT);
514 INP_INFO_WLOCK(&tcbinfo);
516 KASSERT(inp != NULL, ("tcp6_usr_connect: inp == NULL"));
518 if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) {
524 if (IN6_IS_ADDR_V4MAPPED(&sin6p->sin6_addr)) {
525 struct sockaddr_in sin;
527 if ((inp->inp_flags & IN6P_IPV6_V6ONLY) != 0) {
532 in6_sin6_2_sin(&sin, sin6p);
533 inp->inp_vflag |= INP_IPV4;
534 inp->inp_vflag &= ~INP_IPV6;
535 if ((error = tcp_connect(tp, (struct sockaddr *)&sin, td)) != 0)
537 error = tcp_output(tp);
540 inp->inp_vflag &= ~INP_IPV4;
541 inp->inp_vflag |= INP_IPV6;
542 inp->inp_inc.inc_isipv6 = 1;
543 if ((error = tcp6_connect(tp, nam, td)) != 0)
545 error = tcp_output(tp);
548 TCPDEBUG2(PRU_CONNECT);
550 INP_INFO_WUNLOCK(&tcbinfo);
556 * Initiate disconnect from peer.
557 * If connection never passed embryonic stage, just drop;
558 * else if don't need to let data drain, then can just drop anyways,
559 * else have to begin TCP shutdown process: mark socket disconnecting,
560 * drain unread data, state switch to reflect user close, and
561 * send segment (e.g. FIN) to peer. Socket will be really disconnected
562 * when peer sends FIN and acks ours.
564 * SHOULD IMPLEMENT LATER PRU_CONNECT VIA REALLOC TCPCB.
567 tcp_usr_disconnect(struct socket *so)
570 struct tcpcb *tp = NULL;
574 INP_INFO_WLOCK(&tcbinfo);
576 KASSERT(inp != NULL, ("tcp_usr_disconnect: inp == NULL"));
578 if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) {
586 TCPDEBUG2(PRU_DISCONNECT);
588 INP_INFO_WUNLOCK(&tcbinfo);
593 * Accept a connection. Essentially all the work is
594 * done at higher levels; just return the address
595 * of the peer, storing through addr.
598 tcp_usr_accept(struct socket *so, struct sockaddr **nam)
601 struct inpcb *inp = NULL;
602 struct tcpcb *tp = NULL;
607 if (so->so_state & SS_ISDISCONNECTED)
608 return (ECONNABORTED);
611 KASSERT(inp != NULL, ("tcp_usr_accept: inp == NULL"));
613 if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) {
614 error = ECONNABORTED;
621 * We inline in_setpeeraddr and COMMON_END here, so that we can
622 * copy the data of interest and defer the malloc until after we
625 port = inp->inp_fport;
626 addr = inp->inp_faddr;
629 TCPDEBUG2(PRU_ACCEPT);
632 *nam = in_sockaddr(port, &addr);
638 tcp6_usr_accept(struct socket *so, struct sockaddr **nam)
640 struct inpcb *inp = NULL;
642 struct tcpcb *tp = NULL;
644 struct in6_addr addr6;
649 if (so->so_state & SS_ISDISCONNECTED)
650 return (ECONNABORTED);
653 KASSERT(inp != NULL, ("tcp6_usr_accept: inp == NULL"));
655 if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) {
656 error = ECONNABORTED;
663 * We inline in6_mapped_peeraddr and COMMON_END here, so that we can
664 * copy the data of interest and defer the malloc until after we
667 if (inp->inp_vflag & INP_IPV4) {
669 port = inp->inp_fport;
670 addr = inp->inp_faddr;
672 port = inp->inp_fport;
673 addr6 = inp->in6p_faddr;
677 TCPDEBUG2(PRU_ACCEPT);
681 *nam = in6_v4mapsin6_sockaddr(port, &addr);
683 *nam = in6_sockaddr(port, &addr6);
690 * This is the wrapper function for in_setsockaddr. We just pass down
691 * the pcbinfo for in_setsockaddr to lock. We don't want to do the locking
692 * here because in_setsockaddr will call malloc and can block.
695 tcp_sockaddr(struct socket *so, struct sockaddr **nam)
697 return (in_setsockaddr(so, nam, &tcbinfo));
701 * This is the wrapper function for in_setpeeraddr. We just pass down
702 * the pcbinfo for in_setpeeraddr to lock.
705 tcp_peeraddr(struct socket *so, struct sockaddr **nam)
707 return (in_setpeeraddr(so, nam, &tcbinfo));
711 * Mark the connection as being incapable of further output.
714 tcp_usr_shutdown(struct socket *so)
718 struct tcpcb *tp = NULL;
721 INP_INFO_WLOCK(&tcbinfo);
723 KASSERT(inp != NULL, ("inp == NULL"));
725 if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) {
733 error = tcp_output(tp);
736 TCPDEBUG2(PRU_SHUTDOWN);
738 INP_INFO_WUNLOCK(&tcbinfo);
744 * After a receive, possibly send window update to peer.
747 tcp_usr_rcvd(struct socket *so, int flags)
750 struct tcpcb *tp = NULL;
755 KASSERT(inp != NULL, ("tcp_usr_rcvd: inp == NULL"));
757 if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) {
772 * Do a send by putting data in output queue and updating urgent
773 * marker if URG set. Possibly send more data. Unlike the other
774 * pru_*() routines, the mbuf chains are our responsibility. We
775 * must either enqueue them or free them. The other pru_* routines
776 * generally are caller-frees.
779 tcp_usr_send(struct socket *so, int flags, struct mbuf *m,
780 struct sockaddr *nam, struct mbuf *control, struct thread *td)
784 struct tcpcb *tp = NULL;
792 * We require the pcbinfo lock in two cases:
794 * (1) An implied connect is taking place, which can result in
795 * binding IPs and ports and hence modification of the pcb hash
798 * (2) PRUS_EOF is set, resulting in explicit close on the send.
800 if ((nam != NULL) || (flags & PRUS_EOF)) {
801 INP_INFO_WLOCK(&tcbinfo);
805 KASSERT(inp != NULL, ("tcp_usr_send: inp == NULL"));
807 if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) {
816 isipv6 = nam && nam->sa_family == AF_INET6;
821 /* TCP doesn't do control messages (rights, creds, etc) */
822 if (control->m_len) {
829 m_freem(control); /* empty control, just free it */
831 if (!(flags & PRUS_OOB)) {
832 sbappendstream(&so->so_snd, m);
833 if (nam && tp->t_state < TCPS_SYN_SENT) {
835 * Do implied connect if not yet connected,
836 * initialize window to default value, and
837 * initialize maxseg/maxopd using peer's cached
840 INP_INFO_WLOCK_ASSERT(&tcbinfo);
843 error = tcp6_connect(tp, nam, td);
846 error = tcp_connect(tp, nam, td);
849 tp->snd_wnd = TTCP_CLIENT_SND_WND;
852 if (flags & PRUS_EOF) {
854 * Close the send side of the connection after
857 INP_INFO_WLOCK_ASSERT(&tcbinfo);
862 INP_INFO_WUNLOCK(&tcbinfo);
866 if (flags & PRUS_MORETOCOME)
867 tp->t_flags |= TF_MORETOCOME;
868 error = tcp_output(tp);
869 if (flags & PRUS_MORETOCOME)
870 tp->t_flags &= ~TF_MORETOCOME;
874 * XXXRW: PRUS_EOF not implemented with PRUS_OOB?
876 SOCKBUF_LOCK(&so->so_snd);
877 if (sbspace(&so->so_snd) < -512) {
878 SOCKBUF_UNLOCK(&so->so_snd);
884 * According to RFC961 (Assigned Protocols),
885 * the urgent pointer points to the last octet
886 * of urgent data. We continue, however,
887 * to consider it to indicate the first octet
888 * of data past the urgent section.
889 * Otherwise, snd_up should be one lower.
891 sbappendstream_locked(&so->so_snd, m);
892 SOCKBUF_UNLOCK(&so->so_snd);
893 if (nam && tp->t_state < TCPS_SYN_SENT) {
895 * Do implied connect if not yet connected,
896 * initialize window to default value, and
897 * initialize maxseg/maxopd using peer's cached
900 INP_INFO_WLOCK_ASSERT(&tcbinfo);
903 error = tcp6_connect(tp, nam, td);
906 error = tcp_connect(tp, nam, td);
909 tp->snd_wnd = TTCP_CLIENT_SND_WND;
911 INP_INFO_WUNLOCK(&tcbinfo);
914 INP_INFO_WUNLOCK(&tcbinfo);
917 tp->snd_up = tp->snd_una + so->so_snd.sb_cc;
918 tp->t_flags |= TF_FORCEDATA;
919 error = tcp_output(tp);
920 tp->t_flags &= ~TF_FORCEDATA;
923 TCPDEBUG2((flags & PRUS_OOB) ? PRU_SENDOOB :
924 ((flags & PRUS_EOF) ? PRU_SEND_EOF : PRU_SEND));
927 INP_INFO_WUNLOCK(&tcbinfo);
932 * Abort the TCP. Drop the connection abruptly.
935 tcp_usr_abort(struct socket *so)
938 struct tcpcb *tp = NULL;
942 KASSERT(inp != NULL, ("tcp_usr_abort: inp == NULL"));
944 INP_INFO_WLOCK(&tcbinfo);
946 KASSERT(inp->inp_socket != NULL,
947 ("tcp_usr_abort: inp_socket == NULL"));
950 * If we still have full TCP state, and we're not dropped, drop.
952 if (!(inp->inp_vflag & INP_TIMEWAIT) &&
953 !(inp->inp_vflag & INP_DROPPED)) {
956 tcp_drop(tp, ECONNABORTED);
957 TCPDEBUG2(PRU_ABORT);
959 if (!(inp->inp_vflag & INP_DROPPED)) {
961 so->so_state |= SS_PROTOREF;
963 inp->inp_vflag |= INP_SOCKREF;
966 INP_INFO_WUNLOCK(&tcbinfo);
970 * TCP socket is closed. Start friendly disconnect.
973 tcp_usr_close(struct socket *so)
976 struct tcpcb *tp = NULL;
980 KASSERT(inp != NULL, ("tcp_usr_close: inp == NULL"));
982 INP_INFO_WLOCK(&tcbinfo);
984 KASSERT(inp->inp_socket != NULL,
985 ("tcp_usr_close: inp_socket == NULL"));
988 * If we still have full TCP state, and we're not dropped, initiate
991 if (!(inp->inp_vflag & INP_TIMEWAIT) &&
992 !(inp->inp_vflag & INP_DROPPED)) {
996 TCPDEBUG2(PRU_CLOSE);
998 if (!(inp->inp_vflag & INP_DROPPED)) {
1000 so->so_state |= SS_PROTOREF;
1002 inp->inp_vflag |= INP_SOCKREF;
1005 INP_INFO_WUNLOCK(&tcbinfo);
1009 * Receive out-of-band data.
1012 tcp_usr_rcvoob(struct socket *so, struct mbuf *m, int flags)
1016 struct tcpcb *tp = NULL;
1019 inp = sotoinpcb(so);
1020 KASSERT(inp != NULL, ("tcp_usr_rcvoob: inp == NULL"));
1022 if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) {
1026 tp = intotcpcb(inp);
1028 if ((so->so_oobmark == 0 &&
1029 (so->so_rcv.sb_state & SBS_RCVATMARK) == 0) ||
1030 so->so_options & SO_OOBINLINE ||
1031 tp->t_oobflags & TCPOOB_HADDATA) {
1035 if ((tp->t_oobflags & TCPOOB_HAVEDATA) == 0) {
1036 error = EWOULDBLOCK;
1040 *mtod(m, caddr_t) = tp->t_iobc;
1041 if ((flags & MSG_PEEK) == 0)
1042 tp->t_oobflags ^= (TCPOOB_HAVEDATA | TCPOOB_HADDATA);
1045 TCPDEBUG2(PRU_RCVOOB);
1050 struct pr_usrreqs tcp_usrreqs = {
1051 .pru_abort = tcp_usr_abort,
1052 .pru_accept = tcp_usr_accept,
1053 .pru_attach = tcp_usr_attach,
1054 .pru_bind = tcp_usr_bind,
1055 .pru_connect = tcp_usr_connect,
1056 .pru_control = in_control,
1057 .pru_detach = tcp_usr_detach,
1058 .pru_disconnect = tcp_usr_disconnect,
1059 .pru_listen = tcp_usr_listen,
1060 .pru_peeraddr = tcp_peeraddr,
1061 .pru_rcvd = tcp_usr_rcvd,
1062 .pru_rcvoob = tcp_usr_rcvoob,
1063 .pru_send = tcp_usr_send,
1064 .pru_shutdown = tcp_usr_shutdown,
1065 .pru_sockaddr = tcp_sockaddr,
1066 .pru_sosetlabel = in_pcbsosetlabel,
1067 .pru_close = tcp_usr_close,
1071 struct pr_usrreqs tcp6_usrreqs = {
1072 .pru_abort = tcp_usr_abort,
1073 .pru_accept = tcp6_usr_accept,
1074 .pru_attach = tcp_usr_attach,
1075 .pru_bind = tcp6_usr_bind,
1076 .pru_connect = tcp6_usr_connect,
1077 .pru_control = in6_control,
1078 .pru_detach = tcp_usr_detach,
1079 .pru_disconnect = tcp_usr_disconnect,
1080 .pru_listen = tcp6_usr_listen,
1081 .pru_peeraddr = in6_mapped_peeraddr,
1082 .pru_rcvd = tcp_usr_rcvd,
1083 .pru_rcvoob = tcp_usr_rcvoob,
1084 .pru_send = tcp_usr_send,
1085 .pru_shutdown = tcp_usr_shutdown,
1086 .pru_sockaddr = in6_mapped_sockaddr,
1087 .pru_sosetlabel = in_pcbsosetlabel,
1088 .pru_close = tcp_usr_close,
1093 * Common subroutine to open a TCP connection to remote host specified
1094 * by struct sockaddr_in in mbuf *nam. Call in_pcbbind to assign a local
1095 * port number if needed. Call in_pcbconnect_setup to do the routing and
1096 * to choose a local host address (interface). If there is an existing
1097 * incarnation of the same connection in TIME-WAIT state and if the remote
1098 * host was sending CC options and if the connection duration was < MSL, then
1099 * truncate the previous TIME-WAIT state and proceed.
1100 * Initialize connection parameters and enter SYN-SENT state.
1103 tcp_connect(struct tcpcb *tp, struct sockaddr *nam, struct thread *td)
1105 struct inpcb *inp = tp->t_inpcb, *oinp;
1106 struct socket *so = inp->inp_socket;
1107 struct in_addr laddr;
1111 INP_INFO_WLOCK_ASSERT(&tcbinfo);
1112 INP_LOCK_ASSERT(inp);
1114 if (inp->inp_lport == 0) {
1115 error = in_pcbbind(inp, (struct sockaddr *)0, td->td_ucred);
1121 * Cannot simply call in_pcbconnect, because there might be an
1122 * earlier incarnation of this same connection still in
1123 * TIME_WAIT state, creating an ADDRINUSE error.
1125 laddr = inp->inp_laddr;
1126 lport = inp->inp_lport;
1127 error = in_pcbconnect_setup(inp, nam, &laddr.s_addr, &lport,
1128 &inp->inp_faddr.s_addr, &inp->inp_fport, &oinp, td->td_ucred);
1129 if (error && oinp == NULL)
1133 inp->inp_laddr = laddr;
1137 * Compute window scaling to request:
1138 * Scale to fit into sweet spot. See tcp_syncache.c.
1139 * XXX: This should move to tcp_output().
1140 * XXX: This should be based on the actual MSS.
1142 while (tp->request_r_scale < TCP_MAX_WINSHIFT &&
1143 (0x1 << tp->request_r_scale) < tcp_minmss)
1144 tp->request_r_scale++;
1147 tcpstat.tcps_connattempt++;
1148 tp->t_state = TCPS_SYN_SENT;
1149 callout_reset(tp->tt_keep, tcp_keepinit, tcp_timer_keep, tp);
1150 tp->iss = tcp_new_isn(tp);
1151 tp->t_bw_rtseq = tp->iss;
1152 tcp_sendseqinit(tp);
1159 tcp6_connect(struct tcpcb *tp, struct sockaddr *nam, struct thread *td)
1161 struct inpcb *inp = tp->t_inpcb, *oinp;
1162 struct socket *so = inp->inp_socket;
1163 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)nam;
1164 struct in6_addr *addr6;
1167 INP_INFO_WLOCK_ASSERT(&tcbinfo);
1168 INP_LOCK_ASSERT(inp);
1170 if (inp->inp_lport == 0) {
1171 error = in6_pcbbind(inp, (struct sockaddr *)0, td->td_ucred);
1177 * Cannot simply call in_pcbconnect, because there might be an
1178 * earlier incarnation of this same connection still in
1179 * TIME_WAIT state, creating an ADDRINUSE error.
1180 * in6_pcbladdr() also handles scope zone IDs.
1182 error = in6_pcbladdr(inp, nam, &addr6);
1185 oinp = in6_pcblookup_hash(inp->inp_pcbinfo,
1186 &sin6->sin6_addr, sin6->sin6_port,
1187 IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_laddr)
1190 inp->inp_lport, 0, NULL);
1193 if (IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_laddr))
1194 inp->in6p_laddr = *addr6;
1195 inp->in6p_faddr = sin6->sin6_addr;
1196 inp->inp_fport = sin6->sin6_port;
1197 /* update flowinfo - draft-itojun-ipv6-flowlabel-api-00 */
1198 inp->in6p_flowinfo &= ~IPV6_FLOWLABEL_MASK;
1199 if (inp->in6p_flags & IN6P_AUTOFLOWLABEL)
1200 inp->in6p_flowinfo |=
1201 (htonl(ip6_randomflowlabel()) & IPV6_FLOWLABEL_MASK);
1204 /* Compute window scaling to request. */
1205 while (tp->request_r_scale < TCP_MAX_WINSHIFT &&
1206 (TCP_MAXWIN << tp->request_r_scale) < so->so_rcv.sb_hiwat)
1207 tp->request_r_scale++;
1210 tcpstat.tcps_connattempt++;
1211 tp->t_state = TCPS_SYN_SENT;
1212 callout_reset(tp->tt_keep, tcp_keepinit, tcp_timer_keep, tp);
1213 tp->iss = tcp_new_isn(tp);
1214 tp->t_bw_rtseq = tp->iss;
1215 tcp_sendseqinit(tp);
1222 * Export TCP internal state information via a struct tcp_info, based on the
1223 * Linux 2.6 API. Not ABI compatible as our constants are mapped differently
1224 * (TCP state machine, etc). We export all information using FreeBSD-native
1225 * constants -- for example, the numeric values for tcpi_state will differ
1229 tcp_fill_info(struct tcpcb *tp, struct tcp_info *ti)
1232 INP_LOCK_ASSERT(tp->t_inpcb);
1233 bzero(ti, sizeof(*ti));
1235 ti->tcpi_state = tp->t_state;
1236 if ((tp->t_flags & TF_REQ_TSTMP) && (tp->t_flags & TF_RCVD_TSTMP))
1237 ti->tcpi_options |= TCPI_OPT_TIMESTAMPS;
1238 if (tp->sack_enable)
1239 ti->tcpi_options |= TCPI_OPT_SACK;
1240 if ((tp->t_flags & TF_REQ_SCALE) && (tp->t_flags & TF_RCVD_SCALE)) {
1241 ti->tcpi_options |= TCPI_OPT_WSCALE;
1242 ti->tcpi_snd_wscale = tp->snd_scale;
1243 ti->tcpi_rcv_wscale = tp->rcv_scale;
1246 ti->tcpi_rtt = ((u_int64_t)tp->t_srtt * tick) >> TCP_RTT_SHIFT;
1247 ti->tcpi_rttvar = ((u_int64_t)tp->t_rttvar * tick) >> TCP_RTTVAR_SHIFT;
1249 ti->tcpi_snd_ssthresh = tp->snd_ssthresh;
1250 ti->tcpi_snd_cwnd = tp->snd_cwnd;
1253 * FreeBSD-specific extension fields for tcp_info.
1255 ti->tcpi_rcv_space = tp->rcv_wnd;
1256 ti->tcpi_snd_wnd = tp->snd_wnd;
1257 ti->tcpi_snd_bwnd = tp->snd_bwnd;
1261 * The new sockopt interface makes it possible for us to block in the
1262 * copyin/out step (if we take a page fault). Taking a page fault at
1263 * splnet() is probably a Bad Thing. (Since sockets and pcbs both now
1264 * use TSM, there probably isn't any need for this function to run at
1265 * splnet() any more. This needs more examination.)
1267 * XXXRW: The locking here is wrong; we may take a page fault while holding
1271 tcp_ctloutput(struct socket *so, struct sockopt *sopt)
1273 int error, opt, optval;
1279 inp = sotoinpcb(so);
1280 KASSERT(inp != NULL, ("tcp_ctloutput: inp == NULL"));
1282 if (sopt->sopt_level != IPPROTO_TCP) {
1285 if (INP_CHECK_SOCKAF(so, AF_INET6))
1286 error = ip6_ctloutput(so, sopt);
1289 error = ip_ctloutput(so, sopt);
1292 if (inp->inp_vflag & (INP_TIMEWAIT | INP_DROPPED)) {
1296 tp = intotcpcb(inp);
1298 switch (sopt->sopt_dir) {
1300 switch (sopt->sopt_name) {
1301 #ifdef TCP_SIGNATURE
1303 error = sooptcopyin(sopt, &optval, sizeof optval,
1309 tp->t_flags |= TF_SIGNATURE;
1311 tp->t_flags &= ~TF_SIGNATURE;
1313 #endif /* TCP_SIGNATURE */
1316 error = sooptcopyin(sopt, &optval, sizeof optval,
1321 switch (sopt->sopt_name) {
1329 opt = 0; /* dead code to fool gcc */
1336 tp->t_flags &= ~opt;
1340 error = sooptcopyin(sopt, &optval, sizeof optval,
1346 tp->t_flags |= TF_NOPUSH;
1348 tp->t_flags &= ~TF_NOPUSH;
1349 error = tcp_output(tp);
1354 error = sooptcopyin(sopt, &optval, sizeof optval,
1359 if (optval > 0 && optval <= tp->t_maxseg &&
1360 optval + 40 >= tcp_minmss)
1361 tp->t_maxseg = optval;
1371 error = ENOPROTOOPT;
1377 switch (sopt->sopt_name) {
1378 #ifdef TCP_SIGNATURE
1380 optval = (tp->t_flags & TF_SIGNATURE) ? 1 : 0;
1381 error = sooptcopyout(sopt, &optval, sizeof optval);
1385 optval = tp->t_flags & TF_NODELAY;
1386 error = sooptcopyout(sopt, &optval, sizeof optval);
1389 optval = tp->t_maxseg;
1390 error = sooptcopyout(sopt, &optval, sizeof optval);
1393 optval = tp->t_flags & TF_NOOPT;
1394 error = sooptcopyout(sopt, &optval, sizeof optval);
1397 optval = tp->t_flags & TF_NOPUSH;
1398 error = sooptcopyout(sopt, &optval, sizeof optval);
1401 tcp_fill_info(tp, &ti);
1402 error = sooptcopyout(sopt, &ti, sizeof ti);
1405 error = ENOPROTOOPT;
1416 * tcp_sendspace and tcp_recvspace are the default send and receive window
1417 * sizes, respectively. These are obsolescent (this information should
1418 * be set by the route).
1420 u_long tcp_sendspace = 1024*32;
1421 SYSCTL_ULONG(_net_inet_tcp, TCPCTL_SENDSPACE, sendspace, CTLFLAG_RW,
1422 &tcp_sendspace , 0, "Maximum outgoing TCP datagram size");
1423 u_long tcp_recvspace = 1024*64;
1424 SYSCTL_ULONG(_net_inet_tcp, TCPCTL_RECVSPACE, recvspace, CTLFLAG_RW,
1425 &tcp_recvspace , 0, "Maximum incoming TCP datagram size");
1428 * Attach TCP protocol to socket, allocating
1429 * internet protocol control block, tcp control block,
1430 * bufer space, and entering LISTEN state if to accept connections.
1433 tcp_attach(struct socket *so)
1439 int isipv6 = INP_CHECK_SOCKAF(so, AF_INET6) != 0;
1442 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
1443 error = soreserve(so, tcp_sendspace, tcp_recvspace);
1447 so->so_rcv.sb_flags |= SB_AUTOSIZE;
1448 so->so_snd.sb_flags |= SB_AUTOSIZE;
1449 INP_INFO_WLOCK(&tcbinfo);
1450 error = in_pcballoc(so, &tcbinfo);
1452 INP_INFO_WUNLOCK(&tcbinfo);
1455 inp = sotoinpcb(so);
1458 inp->inp_vflag |= INP_IPV6;
1459 inp->in6p_hops = -1; /* use kernel default */
1463 inp->inp_vflag |= INP_IPV4;
1464 tp = tcp_newtcpcb(inp);
1477 INP_INFO_WUNLOCK(&tcbinfo);
1480 tp->t_state = TCPS_CLOSED;
1482 INP_INFO_WUNLOCK(&tcbinfo);
1487 * Initiate (or continue) disconnect.
1488 * If embryonic state, just send reset (once).
1489 * If in ``let data drain'' option and linger null, just drop.
1490 * Otherwise (hard), mark socket disconnecting and drop
1491 * current input data; switch states based on user close, and
1492 * send segment to peer (with FIN).
1495 tcp_disconnect(struct tcpcb *tp)
1497 struct inpcb *inp = tp->t_inpcb;
1498 struct socket *so = inp->inp_socket;
1500 INP_INFO_WLOCK_ASSERT(&tcbinfo);
1501 INP_LOCK_ASSERT(inp);
1504 * Neither tcp_close() nor tcp_drop() should return NULL, as the
1505 * socket is still open.
1507 if (tp->t_state < TCPS_ESTABLISHED) {
1510 ("tcp_disconnect: tcp_close() returned NULL"));
1511 } else if ((so->so_options & SO_LINGER) && so->so_linger == 0) {
1512 tp = tcp_drop(tp, 0);
1514 ("tcp_disconnect: tcp_drop() returned NULL"));
1516 soisdisconnecting(so);
1517 sbflush(&so->so_rcv);
1519 if (!(inp->inp_vflag & INP_DROPPED))
1525 * User issued close, and wish to trail through shutdown states:
1526 * if never received SYN, just forget it. If got a SYN from peer,
1527 * but haven't sent FIN, then go to FIN_WAIT_1 state to send peer a FIN.
1528 * If already got a FIN from peer, then almost done; go to LAST_ACK
1529 * state. In all other cases, have already sent FIN to peer (e.g.
1530 * after PRU_SHUTDOWN), and just have to play tedious game waiting
1531 * for peer to send FIN or not respond to keep-alives, etc.
1532 * We can let the user exit from the close as soon as the FIN is acked.
1535 tcp_usrclosed(struct tcpcb *tp)
1538 INP_INFO_WLOCK_ASSERT(&tcbinfo);
1539 INP_LOCK_ASSERT(tp->t_inpcb);
1541 switch (tp->t_state) {
1545 tp->t_state = TCPS_CLOSED;
1548 * tcp_close() should never return NULL here as the socket is
1552 ("tcp_usrclosed: tcp_close() returned NULL"));
1556 case TCPS_SYN_RECEIVED:
1557 tp->t_flags |= TF_NEEDFIN;
1560 case TCPS_ESTABLISHED:
1561 tp->t_state = TCPS_FIN_WAIT_1;
1564 case TCPS_CLOSE_WAIT:
1565 tp->t_state = TCPS_LAST_ACK;
1568 if (tp && tp->t_state >= TCPS_FIN_WAIT_2) {
1569 soisdisconnected(tp->t_inpcb->inp_socket);
1570 /* To prevent the connection hanging in FIN_WAIT_2 forever. */
1571 if (tp->t_state == TCPS_FIN_WAIT_2) {
1574 timeout = (tcp_fast_finwait2_recycle) ?
1575 tcp_finwait2_timeout : tcp_maxidle;
1576 callout_reset(tp->tt_2msl, timeout,
1577 tcp_timer_2msl, tp);
1584 db_print_indent(int indent)
1588 for (i = 0; i < indent; i++)
1593 db_print_tstate(int t_state)
1598 db_printf("TCPS_CLOSED");
1602 db_printf("TCPS_LISTEN");
1606 db_printf("TCPS_SYN_SENT");
1609 case TCPS_SYN_RECEIVED:
1610 db_printf("TCPS_SYN_RECEIVED");
1613 case TCPS_ESTABLISHED:
1614 db_printf("TCPS_ESTABLISHED");
1617 case TCPS_CLOSE_WAIT:
1618 db_printf("TCPS_CLOSE_WAIT");
1621 case TCPS_FIN_WAIT_1:
1622 db_printf("TCPS_FIN_WAIT_1");
1626 db_printf("TCPS_CLOSING");
1630 db_printf("TCPS_LAST_ACK");
1633 case TCPS_FIN_WAIT_2:
1634 db_printf("TCPS_FIN_WAIT_2");
1637 case TCPS_TIME_WAIT:
1638 db_printf("TCPS_TIME_WAIT");
1642 db_printf("unknown");
1648 db_print_tflags(u_int t_flags)
1653 if (t_flags & TF_ACKNOW) {
1654 db_printf("%sTF_ACKNOW", comma ? ", " : "");
1657 if (t_flags & TF_DELACK) {
1658 db_printf("%sTF_DELACK", comma ? ", " : "");
1661 if (t_flags & TF_NODELAY) {
1662 db_printf("%sTF_NODELAY", comma ? ", " : "");
1665 if (t_flags & TF_NOOPT) {
1666 db_printf("%sTF_NOOPT", comma ? ", " : "");
1669 if (t_flags & TF_SENTFIN) {
1670 db_printf("%sTF_SENTFIN", comma ? ", " : "");
1673 if (t_flags & TF_REQ_SCALE) {
1674 db_printf("%sTF_REQ_SCALE", comma ? ", " : "");
1677 if (t_flags & TF_RCVD_SCALE) {
1678 db_printf("%sTF_RECVD_SCALE", comma ? ", " : "");
1681 if (t_flags & TF_REQ_TSTMP) {
1682 db_printf("%sTF_REQ_TSTMP", comma ? ", " : "");
1685 if (t_flags & TF_RCVD_TSTMP) {
1686 db_printf("%sTF_RCVD_TSTMP", comma ? ", " : "");
1689 if (t_flags & TF_SACK_PERMIT) {
1690 db_printf("%sTF_SACK_PERMIT", comma ? ", " : "");
1693 if (t_flags & TF_NEEDSYN) {
1694 db_printf("%sTF_NEEDSYN", comma ? ", " : "");
1697 if (t_flags & TF_NEEDFIN) {
1698 db_printf("%sTF_NEEDFIN", comma ? ", " : "");
1701 if (t_flags & TF_NOPUSH) {
1702 db_printf("%sTF_NOPUSH", comma ? ", " : "");
1705 if (t_flags & TF_NOPUSH) {
1706 db_printf("%sTF_NOPUSH", comma ? ", " : "");
1709 if (t_flags & TF_MORETOCOME) {
1710 db_printf("%sTF_MORETOCOME", comma ? ", " : "");
1713 if (t_flags & TF_LQ_OVERFLOW) {
1714 db_printf("%sTF_LQ_OVERFLOW", comma ? ", " : "");
1717 if (t_flags & TF_LASTIDLE) {
1718 db_printf("%sTF_LASTIDLE", comma ? ", " : "");
1721 if (t_flags & TF_RXWIN0SENT) {
1722 db_printf("%sTF_RXWIN0SENT", comma ? ", " : "");
1725 if (t_flags & TF_FASTRECOVERY) {
1726 db_printf("%sTF_FASTRECOVERY", comma ? ", " : "");
1729 if (t_flags & TF_WASFRECOVERY) {
1730 db_printf("%sTF_WASFRECOVERY", comma ? ", " : "");
1733 if (t_flags & TF_SIGNATURE) {
1734 db_printf("%sTF_SIGNATURE", comma ? ", " : "");
1737 if (t_flags & TF_FORCEDATA) {
1738 db_printf("%sTF_FORCEDATA", comma ? ", " : "");
1741 if (t_flags & TF_TSO) {
1742 db_printf("%sTF_TSO", comma ? ", " : "");
1748 db_print_toobflags(char t_oobflags)
1753 if (t_oobflags & TCPOOB_HAVEDATA) {
1754 db_printf("%sTCPOOB_HAVEDATA", comma ? ", " : "");
1757 if (t_oobflags & TCPOOB_HADDATA) {
1758 db_printf("%sTCPOOB_HADDATA", comma ? ", " : "");
1764 db_print_tcpcb(struct tcpcb *tp, const char *name, int indent)
1767 db_print_indent(indent);
1768 db_printf("%s at %p\n", name, tp);
1772 db_print_indent(indent);
1773 db_printf("t_segq first: %p t_segqlen: %d t_dupacks: %d\n",
1774 LIST_FIRST(&tp->t_segq), tp->t_segqlen, tp->t_dupacks);
1776 db_print_indent(indent);
1777 db_printf("tt_rexmt: %p tt_persist: %p tt_keep: %p\n",
1778 tp->tt_rexmt, tp->tt_persist, tp->tt_keep);
1780 db_print_indent(indent);
1781 db_printf("tt_2msl: %p tt_delack: %p t_inpcb: %p\n", tp->tt_2msl,
1782 tp->tt_delack, tp->t_inpcb);
1784 db_print_indent(indent);
1785 db_printf("t_state: %d (", tp->t_state);
1786 db_print_tstate(tp->t_state);
1789 db_print_indent(indent);
1790 db_printf("t_flags: 0x%x (", tp->t_flags);
1791 db_print_tflags(tp->t_flags);
1794 db_print_indent(indent);
1795 db_printf("snd_una: 0x%08x snd_max: 0x%08x snd_nxt: x0%08x\n",
1796 tp->snd_una, tp->snd_max, tp->snd_nxt);
1798 db_print_indent(indent);
1799 db_printf("snd_up: 0x%08x snd_wl1: 0x%08x snd_wl2: 0x%08x\n",
1800 tp->snd_up, tp->snd_wl1, tp->snd_wl2);
1802 db_print_indent(indent);
1803 db_printf("iss: 0x%08x irs: 0x%08x rcv_nxt: 0x%08x\n",
1804 tp->iss, tp->irs, tp->rcv_nxt);
1806 db_print_indent(indent);
1807 db_printf("rcv_adv: 0x%08x rcv_wnd: %lu rcv_up: 0x%08x\n",
1808 tp->rcv_adv, tp->rcv_wnd, tp->rcv_up);
1810 db_print_indent(indent);
1811 db_printf("snd_wnd: %lu snd_cwnd: %lu snd_bwnd: %lu\n",
1812 tp->snd_wnd, tp->snd_cwnd, tp->snd_bwnd);
1814 db_print_indent(indent);
1815 db_printf("snd_ssthresh: %lu snd_bandwidth: %lu snd_recover: "
1816 "0x%08x\n", tp->snd_ssthresh, tp->snd_bandwidth,
1819 db_print_indent(indent);
1820 db_printf("t_maxopd: %u t_rcvtime: %lu t_startime: %lu\n",
1821 tp->t_maxopd, tp->t_rcvtime, tp->t_starttime);
1823 db_print_indent(indent);
1824 db_printf("t_rttime: %d t_rtsq: 0x%08x t_bw_rtttime: %d\n",
1825 tp->t_rtttime, tp->t_rtseq, tp->t_bw_rtttime);
1827 db_print_indent(indent);
1828 db_printf("t_bw_rtseq: 0x%08x t_rxtcur: %d t_maxseg: %u "
1829 "t_srtt: %d\n", tp->t_bw_rtseq, tp->t_rxtcur, tp->t_maxseg,
1832 db_print_indent(indent);
1833 db_printf("t_rttvar: %d t_rxtshift: %d t_rttmin: %u "
1834 "t_rttbest: %u\n", tp->t_rttvar, tp->t_rxtshift, tp->t_rttmin,
1837 db_print_indent(indent);
1838 db_printf("t_rttupdated: %lu max_sndwnd: %lu t_softerror: %d\n",
1839 tp->t_rttupdated, tp->max_sndwnd, tp->t_softerror);
1841 db_print_indent(indent);
1842 db_printf("t_oobflags: 0x%x (", tp->t_oobflags);
1843 db_print_toobflags(tp->t_oobflags);
1844 db_printf(") t_iobc: 0x%02x\n", tp->t_iobc);
1846 db_print_indent(indent);
1847 db_printf("snd_scale: %u rcv_scale: %u request_r_scale: %u\n",
1848 tp->snd_scale, tp->rcv_scale, tp->request_r_scale);
1850 db_print_indent(indent);
1851 db_printf("requested_s_scale: %u ts_recent: %u ts_recent_age: "
1852 "%lu\n", tp->requested_s_scale, tp->ts_recent, tp->ts_recent_age);
1854 db_print_indent(indent);
1855 db_printf("ts_offset: %u last_ack_sent: 0x%08x snd_cwnd_prev: "
1856 "%lu\n", tp->ts_offset, tp->last_ack_sent, tp->snd_cwnd_prev);
1858 db_print_indent(indent);
1859 db_printf("snd_ssthresh_prev: %lu snd_recover_prev: 0x%08x "
1860 "t_badrxtwin: %lu\n", tp->snd_ssthresh_prev,
1861 tp->snd_recover_prev, tp->t_badrxtwin);
1863 db_print_indent(indent);
1864 db_printf("sack_enable: %d snd_numholes: %d snd_holes first: %p\n",
1865 tp->sack_enable, tp->snd_numholes, TAILQ_FIRST(&tp->snd_holes));
1867 db_print_indent(indent);
1868 db_printf("snd_fack: 0x%08x rcv_numsacks: %d sack_newdata: "
1869 "0x%08x\n", tp->snd_fack, tp->rcv_numsacks, tp->sack_newdata);
1871 /* Skip sackblks, sackhint. */
1873 db_print_indent(indent);
1874 db_printf("t_rttlow: %d rfbuf_ts: %u rfbuf_cnt: %d\n",
1875 tp->t_rttlow, tp->rfbuf_ts, tp->rfbuf_cnt);
1878 DB_SHOW_COMMAND(tcpcb, db_show_tcpcb)
1883 db_printf("usage: show tcpcb <addr>\n");
1886 tp = (struct tcpcb *)addr;
1888 db_print_tcpcb(tp, "tcpcb", 0);