new signals
[unix-history] / usr / src / sys / netinet / tcp_debug.c
CommitLineData
8ae0e4b4 1/*
0880b18e 2 * Copyright (c) 1982, 1986 Regents of the University of California.
2b6b6284 3 * All rights reserved.
8ae0e4b4 4 *
2b6b6284 5 * Redistribution and use in source and binary forms are permitted
616d42db
KB
6 * provided that the above copyright notice and this paragraph are
7 * duplicated in all such forms and that any documentation,
8 * advertising materials, and other materials related to such
9 * distribution and use acknowledge that the software was developed
10 * by the University of California, Berkeley. The name of the
11 * University may not be used to endorse or promote products derived
12 * from this software without specific prior written permission.
13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
2b6b6284 16 *
616d42db 17 * @(#)tcp_debug.c 7.3 (Berkeley) %G%
8ae0e4b4 18 */
24342857 19
20666ad3
JB
20#include "param.h"
21#include "systm.h"
22#include "mbuf.h"
23#include "socket.h"
24#include "socketvar.h"
24342857 25#define PRUREQUESTS
20666ad3
JB
26#include "protosw.h"
27#include "errno.h"
f4d55810 28
c124e997 29#include "../net/route.h"
f4d55810
SL
30#include "../net/if.h"
31
20666ad3
JB
32#include "in.h"
33#include "in_pcb.h"
34#include "in_systm.h"
35#include "ip.h"
36#include "ip_var.h"
37#include "tcp.h"
24342857 38#define TCPSTATES
20666ad3
JB
39#include "tcp_fsm.h"
40#include "tcp_seq.h"
24342857 41#define TCPTIMERS
20666ad3
JB
42#include "tcp_timer.h"
43#include "tcp_var.h"
44#include "tcpip.h"
24342857 45#define TANAMES
20666ad3 46#include "tcp_debug.h"
24342857
BJ
47
48int tcpconsdebug = 0;
49/*
50 * Tcp debug routines
51 */
52tcp_trace(act, ostate, tp, ti, req)
53 short act, ostate;
54 struct tcpcb *tp;
55 struct tcpiphdr *ti;
56 int req;
57{
58 tcp_seq seq, ack;
59 int len, flags;
24342857
BJ
60 struct tcp_debug *td = &tcp_debug[tcp_debx++];
61
62 if (tcp_debx == TCP_NDEBUG)
63 tcp_debx = 0;
64 td->td_time = iptime();
65 td->td_act = act;
66 td->td_ostate = ostate;
67 td->td_tcb = (caddr_t)tp;
68 if (tp)
69 td->td_cb = *tp;
70 else
71 bzero((caddr_t)&td->td_cb, sizeof (*tp));
72 if (ti)
73 td->td_ti = *ti;
74 else
75 bzero((caddr_t)&td->td_ti, sizeof (*ti));
76 td->td_req = req;
77 if (tcpconsdebug == 0)
78 return;
79 if (tp)
80 printf("%x %s:", tp, tcpstates[ostate]);
81 else
82 printf("???????? ");
83 printf("%s ", tanames[act]);
84 switch (act) {
85
86 case TA_INPUT:
87 case TA_OUTPUT:
b78c1941
SL
88 case TA_DROP:
89 if (ti == 0)
90 break;
24342857
BJ
91 seq = ti->ti_seq;
92 ack = ti->ti_ack;
93 len = ti->ti_len;
24342857
BJ
94 if (act == TA_OUTPUT) {
95 seq = ntohl(seq);
96 ack = ntohl(ack);
668cc26d 97 len = ntohs((u_short)len);
24342857 98 }
24342857
BJ
99 if (act == TA_OUTPUT)
100 len -= sizeof (struct tcphdr);
101 if (len)
102 printf("[%x..%x)", seq, seq+len);
103 else
104 printf("%x", seq);
b78c1941 105 printf("@%x, urp=%x", ack, ti->ti_urp);
24342857
BJ
106 flags = ti->ti_flags;
107 if (flags) {
668cc26d 108#ifndef lint
24342857
BJ
109 char *cp = "<";
110#define pf(f) { if (ti->ti_flags&TH_/**/f) { printf("%s%s", cp, "f"); cp = ","; } }
b78c1941 111 pf(SYN); pf(ACK); pf(FIN); pf(RST); pf(PUSH); pf(URG);
668cc26d 112#endif
24342857
BJ
113 printf(">");
114 }
115 break;
116
117 case TA_USER:
118 printf("%s", prurequests[req&0xff]);
119 if ((req & 0xff) == PRU_SLOWTIMO)
120 printf("<%s>", tcptimers[req>>8]);
121 break;
122 }
123 if (tp)
124 printf(" -> %s", tcpstates[tp->t_state]);
125 /* print out internal state of tp !?! */
126 printf("\n");
127 if (tp == 0)
128 return;
b78c1941
SL
129 printf("\trcv_(nxt,wnd,up) (%x,%x,%x) snd_(una,nxt,max) (%x,%x,%x)\n",
130 tp->rcv_nxt, tp->rcv_wnd, tp->rcv_up, tp->snd_una, tp->snd_nxt,
131 tp->snd_max);
24342857
BJ
132 printf("\tsnd_(wl1,wl2,wnd) (%x,%x,%x)\n",
133 tp->snd_wl1, tp->snd_wl2, tp->snd_wnd);
134}