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