]> CyberLeo.Net >> Repos - FreeBSD/releng/7.2.git/blob - sys/netipx/spx_debug.c
Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.
[FreeBSD/releng/7.2.git] / sys / netipx / spx_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  * 4. Neither the name of the University nor the names of its contributors
14  *    may be used to endorse or promote products derived from this software
15  *    without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * Copyright (c) 1995, Mike Mitchell
30  *
31  * Redistribution and use in source and binary forms, with or without
32  * modification, are permitted provided that the following conditions
33  * are met:
34  * 1. Redistributions of source code must retain the above copyright
35  *    notice, this list of conditions and the following disclaimer.
36  * 2. Redistributions in binary form must reproduce the above copyright
37  *    notice, this list of conditions and the following disclaimer in the
38  *    documentation and/or other materials provided with the distribution.
39  * 3. All advertising materials mentioning features or use of this software
40  *    must display the following acknowledgement:
41  *      This product includes software developed by the University of
42  *      California, Berkeley and its contributors.
43  * 4. Neither the name of the University nor the names of its contributors
44  *    may be used to endorse or promote products derived from this software
45  *    without specific prior written permission.
46  *
47  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
48  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
49  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
50  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
51  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
52  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
53  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
54  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
55  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
56  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
57  * SUCH DAMAGE.
58  *
59  *      @(#)spx_debug.c
60  */
61
62 #include <sys/cdefs.h>
63 __FBSDID("$FreeBSD$");
64
65 #include "opt_inet.h"
66 #include "opt_tcpdebug.h"
67
68 #include <sys/param.h>
69 #include <sys/systm.h>
70 #include <sys/protosw.h>
71
72 #define TCPSTATES               /* for logging */
73
74 #include <netinet/in_systm.h>
75 #include <netinet/tcp_fsm.h>
76
77 #include <netipx/ipx.h>
78 #include <netipx/ipx_var.h>
79 #include <netipx/spx.h>
80 #define SPXTIMERS
81 #include <netipx/spx_timer.h>
82 #define SANAMES
83 #include <netipx/spx_debug.h>
84
85 #ifdef TCPDEBUG
86 static  int spxconsdebug = 0;
87 static  struct spx_debug spx_debug[SPX_NDEBUG];
88 static  int spx_debx;
89 #endif
90
91 /*
92  * spx debug routines
93  */
94 void
95 spx_trace(short act, u_char ostate, struct spxpcb *sp, struct spx *si,
96     int req)
97 {
98 #ifdef INET
99 #ifdef TCPDEBUG
100         u_short seq, ack, len, alo;
101         int flags;
102         struct spx_debug *sd = &spx_debug[spx_debx++];
103
104         if (spx_debx == SPX_NDEBUG)
105                 spx_debx = 0;
106         sd->sd_time = iptime();
107         sd->sd_act = act;
108         sd->sd_ostate = ostate;
109         sd->sd_cb = (caddr_t)sp;
110         if (sp != NULL)
111                 sd->sd_sp = *sp;
112         else
113                 bzero((caddr_t)&sd->sd_sp, sizeof(*sp));
114         if (si != NULL)
115                 sd->sd_si = *si;
116         else
117                 bzero((caddr_t)&sd->sd_si, sizeof(*si));
118         sd->sd_req = req;
119         if (spxconsdebug == 0)
120                 return;
121         if (ostate >= TCP_NSTATES)
122                 ostate = 0;
123         if (act >= SA_DROP)
124                 act = SA_DROP;
125         if (sp != NULL)
126                 printf("%p %s:", (void *)sp, tcpstates[ostate]);
127         else
128                 printf("???????? ");
129         printf("%s ", spxnames[act]);
130         switch (act) {
131
132         case SA_RESPOND:
133         case SA_INPUT:
134         case SA_OUTPUT:
135         case SA_DROP:
136                 if (si == NULL)
137                         break;
138                 seq = si->si_seq;
139                 ack = si->si_ack;
140                 alo = si->si_alo;
141                 len = si->si_len;
142                 if (act == SA_OUTPUT) {
143                         seq = ntohs(seq);
144                         ack = ntohs(ack);
145                         alo = ntohs(alo);
146                         len = ntohs(len);
147                 }
148 #ifndef lint
149 #define p1(f)  { printf("%s = %x, ", "f", f); }
150                 p1(seq); p1(ack); p1(alo); p1(len);
151 #endif
152                 flags = si->si_cc;
153                 if (flags) {
154                         char *cp = "<";
155 #ifndef lint
156 #define pf(f) { if (flags & SPX_ ## f) { printf("%s%s", cp, "f"); cp = ","; } }
157                         pf(SP); pf(SA); pf(OB); pf(EM);
158 #else
159                         cp = cp;
160 #endif
161                         printf(">");
162                 }
163 #ifndef lint
164 #define p2(f)  { printf("%s = %x, ", "f", si->si_ ## f); }
165                 p2(sid);p2(did);p2(dt);p2(pt);
166 #endif
167                 ipx_printhost(&si->si_sna);
168                 ipx_printhost(&si->si_dna);
169
170                 if (act == SA_RESPOND) {
171                         printf("ipx_len = %x, ",
172                                 ((struct ipx *)si)->ipx_len);
173                 }
174                 break;
175
176         case SA_USER:
177                 printf("%s", prurequests[req&0xff]);
178                 if ((req & 0xff) == PRU_SLOWTIMO)
179                         printf("<%s>", spxtimers[req>>8]);
180                 break;
181         }
182         if (sp)
183                 printf(" -> %s", tcpstates[sp->s_state]);
184         /* print out internal state of sp !?! */
185         printf("\n");
186         if (sp == 0)
187                 return;
188 #ifndef lint
189 #define p3(f)  { printf("%s = %x, ", "f", sp->s_ ## f); }
190         printf("\t"); p3(rack);p3(ralo);p3(smax);p3(flags); printf("\n");
191 #endif
192 #endif
193 #endif
194 }