fix record route; don't forward funny stuff; drop if ttl reaches 0
[unix-history] / usr / src / sys / netinet / tcp_debug.c
CommitLineData
8ae0e4b4 1/*
0880b18e 2 * Copyright (c) 1982, 1986 Regents of the University of California.
8ae0e4b4
KM
3 * All rights reserved. The Berkeley software License Agreement
4 * specifies the terms and conditions for redistribution.
5 *
0880b18e 6 * @(#)tcp_debug.c 7.1 (Berkeley) %G%
8ae0e4b4 7 */
24342857 8
20666ad3
JB
9#include "param.h"
10#include "systm.h"
11#include "mbuf.h"
12#include "socket.h"
13#include "socketvar.h"
24342857 14#define PRUREQUESTS
20666ad3
JB
15#include "protosw.h"
16#include "errno.h"
f4d55810 17
c124e997 18#include "../net/route.h"
f4d55810
SL
19#include "../net/if.h"
20
20666ad3
JB
21#include "in.h"
22#include "in_pcb.h"
23#include "in_systm.h"
24#include "ip.h"
25#include "ip_var.h"
26#include "tcp.h"
24342857 27#define TCPSTATES
20666ad3
JB
28#include "tcp_fsm.h"
29#include "tcp_seq.h"
24342857 30#define TCPTIMERS
20666ad3
JB
31#include "tcp_timer.h"
32#include "tcp_var.h"
33#include "tcpip.h"
24342857 34#define TANAMES
20666ad3 35#include "tcp_debug.h"
24342857
BJ
36
37int tcpconsdebug = 0;
38/*
39 * Tcp debug routines
40 */
41tcp_trace(act, ostate, tp, ti, req)
42 short act, ostate;
43 struct tcpcb *tp;
44 struct tcpiphdr *ti;
45 int req;
46{
47 tcp_seq seq, ack;
48 int len, flags;
24342857
BJ
49 struct tcp_debug *td = &tcp_debug[tcp_debx++];
50
51 if (tcp_debx == TCP_NDEBUG)
52 tcp_debx = 0;
53 td->td_time = iptime();
54 td->td_act = act;
55 td->td_ostate = ostate;
56 td->td_tcb = (caddr_t)tp;
57 if (tp)
58 td->td_cb = *tp;
59 else
60 bzero((caddr_t)&td->td_cb, sizeof (*tp));
61 if (ti)
62 td->td_ti = *ti;
63 else
64 bzero((caddr_t)&td->td_ti, sizeof (*ti));
65 td->td_req = req;
66 if (tcpconsdebug == 0)
67 return;
68 if (tp)
69 printf("%x %s:", tp, tcpstates[ostate]);
70 else
71 printf("???????? ");
72 printf("%s ", tanames[act]);
73 switch (act) {
74
75 case TA_INPUT:
76 case TA_OUTPUT:
b78c1941
SL
77 case TA_DROP:
78 if (ti == 0)
79 break;
24342857
BJ
80 seq = ti->ti_seq;
81 ack = ti->ti_ack;
82 len = ti->ti_len;
24342857
BJ
83 if (act == TA_OUTPUT) {
84 seq = ntohl(seq);
85 ack = ntohl(ack);
668cc26d 86 len = ntohs((u_short)len);
24342857 87 }
24342857
BJ
88 if (act == TA_OUTPUT)
89 len -= sizeof (struct tcphdr);
90 if (len)
91 printf("[%x..%x)", seq, seq+len);
92 else
93 printf("%x", seq);
b78c1941 94 printf("@%x, urp=%x", ack, ti->ti_urp);
24342857
BJ
95 flags = ti->ti_flags;
96 if (flags) {
668cc26d 97#ifndef lint
24342857
BJ
98 char *cp = "<";
99#define pf(f) { if (ti->ti_flags&TH_/**/f) { printf("%s%s", cp, "f"); cp = ","; } }
b78c1941 100 pf(SYN); pf(ACK); pf(FIN); pf(RST); pf(PUSH); pf(URG);
668cc26d 101#endif
24342857
BJ
102 printf(">");
103 }
104 break;
105
106 case TA_USER:
107 printf("%s", prurequests[req&0xff]);
108 if ((req & 0xff) == PRU_SLOWTIMO)
109 printf("<%s>", tcptimers[req>>8]);
110 break;
111 }
112 if (tp)
113 printf(" -> %s", tcpstates[tp->t_state]);
114 /* print out internal state of tp !?! */
115 printf("\n");
116 if (tp == 0)
117 return;
b78c1941
SL
118 printf("\trcv_(nxt,wnd,up) (%x,%x,%x) snd_(una,nxt,max) (%x,%x,%x)\n",
119 tp->rcv_nxt, tp->rcv_wnd, tp->rcv_up, tp->snd_una, tp->snd_nxt,
120 tp->snd_max);
24342857
BJ
121 printf("\tsnd_(wl1,wl2,wnd) (%x,%x,%x)\n",
122 tp->snd_wl1, tp->snd_wl2, tp->snd_wnd);
123}