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