xref: /csrg-svn/sys/netns/spp_debug.c (revision 33371)
1 /*
2  * Copyright (c) 1984, 1985, 1986, 1987 Regents of the University of California.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms are permitted
6  * provided that this notice is preserved and that due credit is given
7  * to the University of California at Berkeley. The name of the University
8  * may not be used to endorse or promote products derived from this
9  * software without specific prior written permission. This software
10  * is provided ``as is'' without express or implied warranty.
11  *
12  *      @(#)spp_debug.c	7.3 (Berkeley) 01/20/88
13  */
14 
15 #include "param.h"
16 #include "systm.h"
17 #include "mbuf.h"
18 #include "socket.h"
19 #include "socketvar.h"
20 #include "protosw.h"
21 #include "errno.h"
22 
23 #include "../net/route.h"
24 #include "../net/if.h"
25 #include "../netinet/tcp_fsm.h"
26 #include "../netinet/tcp_timer.h"
27 
28 #include "ns.h"
29 #include "ns_pcb.h"
30 #include "idp.h"
31 #include "idp_var.h"
32 #include "sp.h"
33 #include "spidp.h"
34 #include "spp_var.h"
35 #define	SANAMES
36 #include "spp_debug.h"
37 
38 int	sppconsdebug = 0;
39 /*
40  * spp debug routines
41  */
42 spp_trace(act, ostate, sp, si, req)
43 	short act;
44 	u_char ostate;
45 	struct sppcb *sp;
46 	struct spidp *si;
47 	int req;
48 {
49 #ifdef INET
50 	u_short seq, ack, len, alo;
51 	unsigned long iptime();
52 	int flags;
53 	struct spp_debug *sd = &spp_debug[spp_debx++];
54 	extern char *prurequests[];
55 	extern char *sanames[];
56 	extern char *tcpstates[];
57 	extern char *tcptimers[];
58 
59 	if (spp_debx == SPP_NDEBUG)
60 		spp_debx = 0;
61 	sd->sd_time = iptime();
62 	sd->sd_act = act;
63 	sd->sd_ostate = ostate;
64 	sd->sd_cb = (caddr_t)sp;
65 	if (sp)
66 		sd->sd_sp = *sp;
67 	else
68 		bzero((caddr_t)&sd->sd_sp, sizeof (*sp));
69 	if (si)
70 		sd->sd_si = *si;
71 	else
72 		bzero((caddr_t)&sd->sd_si, sizeof (*si));
73 	sd->sd_req = req;
74 	if (sppconsdebug == 0)
75 		return;
76 	if (ostate >= TCP_NSTATES) ostate = 0;
77 	if (act >= SA_DROP) act = SA_DROP;
78 	if (sp)
79 		printf("%x %s:", sp, tcpstates[ostate]);
80 	else
81 		printf("???????? ");
82 	printf("%s ", sanames[act]);
83 	switch (act) {
84 
85 	case SA_RESPOND:
86 	case SA_INPUT:
87 	case SA_OUTPUT:
88 	case SA_DROP:
89 		if (si == 0)
90 			break;
91 		seq = si->si_seq;
92 		ack = si->si_ack;
93 		alo = si->si_alo;
94 		len = si->si_len;
95 		if (act == SA_OUTPUT) {
96 			seq = ntohs(seq);
97 			ack = ntohs(ack);
98 			alo = ntohs(alo);
99 			len = ntohs(len);
100 		}
101 #ifndef lint
102 #define p1(f)  { printf("%s = %x, ", "f", f); }
103 		p1(seq); p1(ack); p1(alo); p1(len);
104 #endif
105 		flags = si->si_cc;
106 		if (flags) {
107 			char *cp = "<";
108 #ifndef lint
109 #define pf(f) { if (flags&SP_/**/f) { printf("%s%s", cp, "f"); cp = ","; } }
110 			pf(SP); pf(SA); pf(OB); pf(EM);
111 #else
112 			cp = cp;
113 #endif
114 			printf(">");
115 		}
116 #ifndef lint
117 #define p2(f)  { printf("%s = %x, ", "f", si->si_/**/f); }
118 		p2(sid);p2(did);p2(dt);p2(pt);
119 #endif
120 		ns_printhost(&si->si_sna);
121 		ns_printhost(&si->si_dna);
122 
123 		if (act==SA_RESPOND) {
124 			printf("idp_len = %x, ",
125 				((struct idp *)si)->idp_len);
126 		}
127 		break;
128 
129 	case SA_USER:
130 		printf("%s", prurequests[req&0xff]);
131 		if ((req & 0xff) == PRU_SLOWTIMO)
132 			printf("<%s>", tcptimers[req>>8]);
133 		break;
134 	}
135 	if (sp)
136 		printf(" -> %s", tcpstates[sp->s_state]);
137 	/* print out internal state of sp !?! */
138 	printf("\n");
139 	if (sp == 0)
140 		return;
141 #ifndef lint
142 #define p3(f)  { printf("%s = %x, ", "f", sp->s_/**/f); }
143 	printf("\t"); p3(rack);p3(ralo);p3(smax);p3(flags); printf("\n");
144 #endif
145 #endif
146 }
147