xref: /csrg-svn/sys/netns/spp_debug.c (revision 23214)
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.2 (Berkeley) 06/08/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 #endif
105 			printf(">");
106 		}
107 #ifndef lint
108 #define p2(f)  { printf("%s = %x, ", "f", si->si_/**/f); }
109 		p2(sid);p2(did);p2(dt);p2(pt);
110 #endif
111 		ns_printhost(&si->si_sna);
112 		ns_printhost(&si->si_dna);
113 
114 		if (act==SA_RESPOND) {
115 			printf("idp_len = %x, ",
116 				((struct idp *)si)->idp_len);
117 		}
118 		break;
119 
120 	case SA_USER:
121 		printf("%s", prurequests[req&0xff]);
122 		if ((req & 0xff) == PRU_SLOWTIMO)
123 			printf("<%s>", tcptimers[req>>8]);
124 		break;
125 	}
126 	if (sp)
127 		printf(" -> %s", tcpstates[sp->s_state]);
128 	/* print out internal state of sp !?! */
129 	printf("\n");
130 	if (sp == 0)
131 		return;
132 #ifndef lint
133 #define p3(f)  { printf("%s = %x, ", "f", sp->s_/**/f); }
134 	printf("\t"); p3(rack);p3(ralo);p3(snt);p3(flags); printf("\n");
135 #endif
136 }
137