Correct BSD License clause numbering from 1-2-4 to 1-2-3.
[dragonfly.git] / sys / netproto / ipx / spx_debug.c
1 /*
2  * Copyright (c) 1995, Mike Mitchell
3  * Copyright (c) 1984, 1985, 1986, 1987, 1993
4  *      The Regents of the University of California.  All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. Neither the name of the University nor the names of its contributors
15  *    may be used to endorse or promote products derived from this software
16  *    without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28  * SUCH DAMAGE.
29  *
30  *      @(#)spx_debug.c
31  *
32  * $FreeBSD: src/sys/netipx/spx_debug.c,v 1.14 1999/08/28 00:49:43 peter Exp $
33  */
34
35 #include "opt_inet.h"
36 #include "opt_tcpdebug.h"
37
38 #include <sys/param.h>
39 #include <sys/systm.h>
40 #include <sys/protosw.h>
41
42 #include <netinet/in_systm.h>
43 #include <netinet/tcp_fsm.h>
44
45 #include "ipx.h"
46 #include "ipx_var.h"
47 #include "spx.h"
48 #define SPXTIMERS
49 #include "spx_timer.h"
50 #define SANAMES
51 #include "spx_debug.h"
52
53 #ifdef TCPDEBUG
54 static  int spxconsdebug = 0;
55 static  struct spx_debug spx_debug[SPX_NDEBUG];
56 static  int spx_debx;
57 #endif
58
59 /*
60  * spx debug routines
61  */
62 void
63 spx_trace(int act, int ostate, struct spxpcb *sp, struct spx *si, int req)
64 {
65 #ifdef INET
66 #ifdef TCPDEBUG
67         u_short seq, ack, len, alo;
68         int flags;
69         struct spx_debug *sd = &spx_debug[spx_debx++];
70
71         if (spx_debx == SPX_NDEBUG)
72                 spx_debx = 0;
73         sd->sd_time = iptime();
74         sd->sd_act = act;
75         sd->sd_ostate = ostate;
76         sd->sd_cb = (caddr_t)sp;
77         if (sp != NULL)
78                 sd->sd_sp = *sp;
79         else
80                 bzero((caddr_t)&sd->sd_sp, sizeof(*sp));
81         if (si != NULL)
82                 sd->sd_si = *si;
83         else
84                 bzero((caddr_t)&sd->sd_si, sizeof(*si));
85         sd->sd_req = req;
86         if (spxconsdebug == 0)
87                 return;
88         if (ostate >= TCP_NSTATES)
89                 ostate = 0;
90         if (act >= SA_DROP)
91                 act = SA_DROP;
92         if (sp != NULL)
93                 kprintf("%p %s:", (void *)sp, tcpstates[ostate]);
94         else
95                 kprintf("???????? ");
96         kprintf("%s ", spxnames[act]);
97         switch (act) {
98
99         case SA_RESPOND:
100         case SA_INPUT:
101         case SA_OUTPUT:
102         case SA_DROP:
103                 if (si == NULL)
104                         break;
105                 seq = si->si_seq;
106                 ack = si->si_ack;
107                 alo = si->si_alo;
108                 len = si->si_len;
109                 if (act == SA_OUTPUT) {
110                         seq = ntohs(seq);
111                         ack = ntohs(ack);
112                         alo = ntohs(alo);
113                         len = ntohs(len);
114                 }
115 #define p1(f)  { kprintf("%s = %x, ", "f", f); }
116                 p1(seq); p1(ack); p1(alo); p1(len);
117                 flags = si->si_cc;
118                 if (flags) {
119                         char *cp = "<";
120 #define pf(f) { if (flags & SPX_ ## f) { kprintf("%s%s", cp, "f"); cp = ","; } }
121                         pf(SP); pf(SA); pf(OB); pf(EM);
122                         kprintf(">");
123                 }
124 #define p2(f)  { kprintf("%s = %x, ", "f", si->si_ ## f); }
125                 p2(sid);p2(did);p2(dt);p2(pt);
126                 ipx_printhost(&si->si_sna);
127                 ipx_printhost(&si->si_dna);
128
129                 if (act == SA_RESPOND) {
130                         kprintf("ipx_len = %x, ",
131                                 ((struct ipx *)si)->ipx_len);
132                 }
133                 break;
134
135         case SA_USER:
136                 kprintf("%s", prurequests[req&0xff]);
137                 if ((req & 0xff) == PRU_SLOWTIMO)
138                         kprintf("<%s>", spxtimers[req>>8]);
139                 break;
140         }
141         if (sp)
142                 kprintf(" -> %s", tcpstates[sp->s_state]);
143         /* print out internal state of sp !?! */
144         kprintf("\n");
145         if (sp == NULL)
146                 return;
147 #define p3(f)  { kprintf("%s = %x, ", "f", sp->s_ ## f); }
148         kprintf("\t"); p3(rack);p3(ralo);p3(smax);p3(flags); kprintf("\n");
149 #endif /* TCPDEBUG */
150 #endif /* INET */
151 }