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