This commit represents a major revamping of the clock interrupt and timebase
[dragonfly.git] / sys / netproto / ns / spp_debug.c
1 /*
2  * Copyright (c) 1984, 1985, 1986, 1987, 1993
3  *      The Regents of the University of California.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. All advertising materials mentioning features or use of this software
14  *    must display the following acknowledgement:
15  *      This product includes software developed by the University of
16  *      California, Berkeley and its contributors.
17  * 4. Neither the name of the University nor the names of its contributors
18  *    may be used to endorse or promote products derived from this software
19  *    without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  *
33  *      @(#)spp_debug.c 8.1 (Berkeley) 6/10/93
34  * $FreeBSD: src/sys/netns/spp_debug.c,v 1.10 1999/08/28 00:49:52 peter Exp $
35  * $DragonFly: src/sys/netproto/ns/spp_debug.c,v 1.4 2003/09/06 21:51:12 drhodus Exp $
36  */
37
38 #include "opt_inet.h"
39
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/mbuf.h>
43 #include <sys/socket.h>
44 #include <sys/socketvar.h>
45 #include <sys/protosw.h>
46 #include <sys/errno.h>
47
48 #include <net/route.h>
49 #include <net/if.h>
50 #include <netinet/tcp_fsm.h>
51
52 #include "ns.h"
53 #include "ns_pcb.h"
54 #include "idp.h"
55 #include "idp_var.h"
56 #include "sp.h"
57 #include "spidp.h"
58 #define SPPTIMERS
59 #include "spp_timer.h"
60 #include "spp_var.h"
61 #define SANAMES
62 #include "spp_debug.h"
63
64 int     sppconsdebug = 0;
65 /*
66  * spp debug routines
67  */
68 void
69 spp_trace(act, ostate, sp, si, req)
70         short act;
71         u_char ostate;
72         struct sppcb *sp;
73         struct spidp *si;
74         int req;
75 {
76 #ifdef INET
77 #ifdef TCPDEBUG
78         u_short seq, ack, len, alo;
79         unsigned long iptime();
80         int flags;
81         struct spp_debug *sd = &spp_debug[spp_debx++];
82         extern char *prurequests[];
83         extern char *sanames[];
84         extern char *tcpstates[];
85         extern char *spptimers[];
86
87         if (spp_debx == SPP_NDEBUG)
88                 spp_debx = 0;
89         sd->sd_time = iptime();
90         sd->sd_act = act;
91         sd->sd_ostate = ostate;
92         sd->sd_cb = (caddr_t)sp;
93         if (sp)
94                 sd->sd_sp = *sp;
95         else
96                 bzero((caddr_t)&sd->sd_sp, sizeof (*sp));
97         if (si)
98                 sd->sd_si = *si;
99         else
100                 bzero((caddr_t)&sd->sd_si, sizeof (*si));
101         sd->sd_req = req;
102         if (sppconsdebug == 0)
103                 return;
104         if (ostate >= TCP_NSTATES) ostate = 0;
105         if (act >= SA_DROP) act = SA_DROP;
106         if (sp)
107                 printf("%x %s:", sp, tcpstates[ostate]);
108         else
109                 printf("???????? ");
110         printf("%s ", sanames[act]);
111         switch (act) {
112
113         case SA_RESPOND:
114         case SA_INPUT:
115         case SA_OUTPUT:
116         case SA_DROP:
117                 if (si == 0)
118                         break;
119                 seq = si->si_seq;
120                 ack = si->si_ack;
121                 alo = si->si_alo;
122                 len = si->si_len;
123                 if (act == SA_OUTPUT) {
124                         seq = ntohs(seq);
125                         ack = ntohs(ack);
126                         alo = ntohs(alo);
127                         len = ntohs(len);
128                 }
129 #ifndef lint
130 #define p1(f)  { printf("%s = %x, ", "f", f); }
131                 p1(seq); p1(ack); p1(alo); p1(len);
132 #endif
133                 flags = si->si_cc;
134                 if (flags) {
135                         char *cp = "<";
136 #ifndef lint
137 #define pf(f) { if (flags&SP_/**/f) { printf("%s%s", cp, "f"); cp = ","; } }
138                         pf(SP); pf(SA); pf(OB); pf(EM);
139 #else
140                         cp = cp;
141 #endif
142                         printf(">");
143                 }
144 #ifndef lint
145 #define p2(f)  { printf("%s = %x, ", "f", si->si_/**/f); }
146                 p2(sid);p2(did);p2(dt);p2(pt);
147 #endif
148                 ns_printhost(&si->si_sna);
149                 ns_printhost(&si->si_dna);
150
151                 if (act==SA_RESPOND) {
152                         printf("idp_len = %x, ",
153                                 ((struct idp *)si)->idp_len);
154                 }
155                 break;
156
157         case SA_USER:
158                 printf("%s", prurequests[req&0xff]);
159                 if ((req & 0xff) == PRU_SLOWTIMO)
160                         printf("<%s>", spptimers[req>>8]);
161                 break;
162         }
163         if (sp)
164                 printf(" -> %s", tcpstates[sp->s_state]);
165         /* print out internal state of sp !?! */
166         printf("\n");
167         if (sp == 0)
168                 return;
169 #ifndef lint
170 #define p3(f)  { printf("%s = %x, ", "f", sp->s_/**/f); }
171         printf("\t"); p3(rack);p3(ralo);p3(smax);p3(flags); printf("\n");
172 #endif
173 #endif
174 #endif
175 }