xref: /original-bsd/sys/netiso/tp_trace.c (revision 3705696b)
1 /*-
2  * Copyright (c) 1991, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  *
7  *	@(#)tp_trace.c	8.1 (Berkeley) 06/10/93
8  */
9 
10 /***********************************************************
11 		Copyright IBM Corporation 1987
12 
13                       All Rights Reserved
14 
15 Permission to use, copy, modify, and distribute this software and its
16 documentation for any purpose and without fee is hereby granted,
17 provided that the above copyright notice appear in all copies and that
18 both that copyright notice and this permission notice appear in
19 supporting documentation, and that the name of IBM not be
20 used in advertising or publicity pertaining to distribution of the
21 software without specific, written prior permission.
22 
23 IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
24 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
25 IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
26 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
27 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
28 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
29 SOFTWARE.
30 
31 ******************************************************************/
32 
33 /*
34  * ARGO Project, Computer Sciences Dept., University of Wisconsin - Madison
35  */
36 /*
37  * ARGO TP
38  *
39  * $Header: tp_trace.c,v 5.3 88/11/18 17:29:14 nhall Exp $
40  * $Source: /usr/argo/sys/netiso/RCS/tp_trace.c,v $
41  *
42  * The whole protocol trace module.
43  * We keep a circular buffer of trace structures, which are big
44  * unions of different structures we might want to see.
45  * Unfortunately this gets too big pretty easily. Pcbs were removed
46  * from the tracing when the kernel got too big to boot.
47  */
48 
49 #define TP_TRACEFILE
50 
51 #include <sys/param.h>
52 #include <sys/systm.h>
53 #include <sys/mbuf.h>
54 #include <sys/socket.h>
55 #include <sys/time.h>
56 
57 #include <netiso/tp_param.h>
58 #include <netiso/tp_timer.h>
59 #include <netiso/tp_stat.h>
60 #include <netiso/tp_param.h>
61 #include <netiso/tp_ip.h>
62 #include <netiso/tp_pcb.h>
63 #include <netiso/tp_tpdu.h>
64 #include <netiso/argo_debug.h>
65 #include <netiso/tp_trace.h>
66 
67 #ifdef TPPT
68 static tp_seq = 0;
69 u_char tp_traceflags[128];
70 
71 /*
72  * The argument tpcb is the obvious.
73  * event here is just the type of trace event - TPPTmisc, etc.
74  * The rest of the arguments have different uses depending
75  * on the type of trace event.
76  */
77 /*ARGSUSED*/
78 /*VARARGS*/
79 
80 void
81 tpTrace(tpcb, event, arg, src, len, arg4, arg5)
82 	struct tp_pcb	*tpcb;
83 	u_int 			event, arg;
84 	u_int	 		src;
85 	u_int	 		len;
86 	u_int	 		arg4;
87 	u_int	 		arg5;
88 {
89 	register struct tp_Trace *tp;
90 
91 	tp = &tp_Trace[tp_Tracen++];
92 	tp_Tracen %= TPTRACEN;
93 
94 	tp->tpt_event = event;
95 	tp->tpt_tseq = tp_seq++;
96 	tp->tpt_arg = arg;
97 	if(tpcb)
98 		tp->tpt_arg2 = tpcb->tp_lref;
99 	bcopy( (caddr_t)&time, (caddr_t)&tp->tpt_time, sizeof(struct timeval) );
100 
101 	switch(event) {
102 
103 	case TPPTertpdu:
104 		bcopy((caddr_t)src, (caddr_t)&tp->tpt_ertpdu,
105 			(unsigned)MIN((int)len, sizeof(struct tp_Trace)));
106 		break;
107 
108 	case TPPTusrreq:
109 	case TPPTmisc:
110 
111 		/* arg is a string */
112 		bcopy((caddr_t)arg, (caddr_t)tp->tpt_str,
113 			(unsigned)MIN(1+strlen((caddr_t) arg), TPTRACE_STRLEN));
114 		tp->tpt_m2 = src;
115 		tp->tpt_m3 = len;
116 		tp->tpt_m4 = arg4;
117 		tp->tpt_m1 = arg5;
118 		break;
119 
120 	case TPPTgotXack:
121 	case TPPTXack:
122 	case TPPTsendack:
123 	case TPPTgotack:
124 	case TPPTack:
125 	case TPPTindicate:
126 	default:
127 	case TPPTdriver:
128 		tp->tpt_m2 = arg;
129 		tp->tpt_m3 = src;
130 		tp->tpt_m4 = len;
131 		tp->tpt_m5 = arg4;
132 		tp->tpt_m1 = arg5;
133 		break;
134 	case TPPTparam:
135 		bcopy((caddr_t)src, (caddr_t)&tp->tpt_param, sizeof(struct tp_param));
136 		break;
137 	case TPPTref:
138 		bcopy((caddr_t)src, (caddr_t)&tp->tpt_ref, sizeof(struct tp_ref));
139 		break;
140 
141 	case TPPTtpduin:
142 	case TPPTtpduout:
143 		tp->tpt_arg2 = arg4;
144 		bcopy((caddr_t)src, (caddr_t)&tp->tpt_tpdu,
145 		      (unsigned)MIN((int)len, sizeof(struct tp_Trace)));
146 		break;
147 	}
148 }
149 #endif /* TPPT */
150