xref: /original-bsd/sbin/XNSrouted/trace.h (revision e188a54c)
1 /*
2  * Copyright (c) 1983 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * This file includes significant work done at Cornell University by
6  * Bill Nesheim.  That work included by permission.
7  *
8  * Redistribution and use in source and binary forms are permitted
9  * provided that the above copyright notice and this paragraph are
10  * duplicated in all such forms and that any documentation,
11  * advertising materials, and other materials related to such
12  * distribution and use acknowledge that the software was developed
13  * by the University of California, Berkeley.  The name of the
14  * University may not be used to endorse or promote products derived
15  * from this software without specific prior written permission.
16  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
18  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19  *
20  *	@(#)trace.h	5.5 (Berkeley) 09/19/88
21  */
22 
23 /*
24  * Xerox Routing Information Protocol.
25  */
26 
27 /*
28  * Trace record format.
29  */
30 struct	iftrace {
31 	time_t	ift_stamp;		/* time stamp */
32 	struct	sockaddr ift_who;	/* from/to */
33 	char	*ift_packet;		/* pointer to packet */
34 	short	ift_size;		/* size of packet */
35 	short	ift_metric;		/* metric  */
36 };
37 
38 /*
39  * Per interface packet tracing buffers.  An incoming and
40  * outgoing circular buffer of packets is maintained, per
41  * interface, for debugging.  Buffers are dumped whenever
42  * an interface is marked down.
43  */
44 struct	ifdebug {
45 	struct	iftrace *ifd_records;	/* array of trace records */
46 	struct	iftrace *ifd_front;	/* next empty trace record */
47 	int	ifd_count;		/* number of unprinted records */
48 	struct	interface *ifd_if;	/* for locating stuff */
49 };
50 
51 /*
52  * Packet tracing stuff.
53  */
54 int	tracepackets;		/* watch packets as they go by */
55 int	tracing;		/* on/off */
56 FILE	*ftrace;		/* output trace file */
57 
58 #define	TRACE_ACTION(action, route) { \
59 	  if (tracing) \
60 		traceaction(ftrace, "action", route); \
61 	}
62 #define	TRACE_INPUT(ifp, src, size) { \
63 	  if (tracing) { \
64 		ifp = if_iflookup(src); \
65 		if (ifp) \
66 			trace(&ifp->int_input, src, &packet[sizeof(struct idp)], size, \
67 				ntohl(ifp->int_metric)); \
68 	  } \
69 	  if (tracepackets && ftrace) \
70 		dumppacket(ftrace, "from", src, &packet[sizeof(struct idp)], size); \
71 	}
72 #define	TRACE_OUTPUT(ifp, dst, size) { \
73 	  if (tracing) { \
74 		ifp = if_iflookup(dst); \
75 		if (ifp) \
76 		    trace(&ifp->int_output, dst, &packet[sizeof(struct idp)], size, ifp->int_metric); \
77 	  } \
78 	  if (tracepackets && ftrace) \
79 		dumppacket(ftrace, "to", dst, &packet[sizeof(struct idp)], size); \
80 	}
81