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