trace.h revision 27244
1283625Sdim/*
2283625Sdim * Copyright (c) 1983, 1993
3353358Sdim *	The Regents of the University of California.  All rights reserved.
4353358Sdim *
5353358Sdim * Copyright (c) 1995 John Hay.  All rights reserved.
6283625Sdim *
7283625Sdim * This file includes significant work done at Cornell University by
8283625Sdim * Bill Nesheim.  That work included by permission.
9283625Sdim *
10283625Sdim * Redistribution and use in source and binary forms, with or without
11283625Sdim * modification, are permitted provided that the following conditions
12283625Sdim * are met:
13283625Sdim * 1. Redistributions of source code must retain the above copyright
14283625Sdim *    notice, this list of conditions and the following disclaimer.
15283625Sdim * 2. Redistributions in binary form must reproduce the above copyright
16283625Sdim *    notice, this list of conditions and the following disclaimer in the
17283625Sdim *    documentation and/or other materials provided with the distribution.
18283625Sdim * 3. All advertising materials mentioning features or use of this software
19283625Sdim *    must display the following acknowledgement:
20283625Sdim *	This product includes software developed by the University of
21283625Sdim *	California, Berkeley and its contributors.
22283625Sdim * 4. Neither the name of the University nor the names of its contributors
23283625Sdim *    may be used to endorse or promote products derived from this software
24283625Sdim *    without specific prior written permission.
25283625Sdim *
26283625Sdim * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27283625Sdim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28283625Sdim * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29283625Sdim * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30283625Sdim * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31283625Sdim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32283625Sdim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33283625Sdim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34283625Sdim * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35283625Sdim * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36283625Sdim * SUCH DAMAGE.
37283625Sdim *
38283625Sdim *	@(#)trace.h	8.1 (Berkeley) 6/5/93
39283625Sdim *
40283625Sdim *	$Id: trace.h,v 1.5 1997/02/22 16:01:04 peter Exp $
41283625Sdim */
42283625Sdim
43283625Sdim/*
44283625Sdim * IPX Routing Information Protocol.
45283625Sdim */
46283625Sdim
47283625Sdim/*
48283625Sdim * Trace record format.
49283625Sdim */
50283625Sdimstruct	iftrace {
51283625Sdim	time_t	ift_stamp;		/* time stamp */
52309124Sdim	struct	sockaddr ift_who;	/* from/to */
53309124Sdim	char	*ift_packet;		/* pointer to packet */
54309124Sdim	short	ift_size;		/* size of packet */
55309124Sdim	short	ift_metric;		/* metric  */
56309124Sdim};
57309124Sdim
58309124Sdim/*
59309124Sdim * Per interface packet tracing buffers.  An incoming and
60309124Sdim * outgoing circular buffer of packets is maintained, per
61283625Sdim * interface, for debugging.  Buffers are dumped whenever
62283625Sdim * an interface is marked down.
63314564Sdim */
64341825Sdimstruct	ifdebug {
65309124Sdim	struct	iftrace *ifd_records;	/* array of trace records */
66283625Sdim	struct	iftrace *ifd_front;	/* next empty trace record */
67283625Sdim	int	ifd_count;		/* number of unprinted records */
68283625Sdim	struct	interface *ifd_if;	/* for locating stuff */
69283625Sdim};
70360784Sdim
71283625Sdim/*
72283625Sdim * Packet tracing stuff.
73283625Sdim */
74283625Sdimint	tracepackets;		/* watch packets as they go by */
75283625Sdimint	tracing;		/* on/off */
76283625SdimFILE	*ftrace;		/* output trace file */
77283625Sdim
78283625Sdim#define	TRACE_ACTION(action, route) { \
79283625Sdim	  if (tracing) \
80283625Sdim		traceaction(ftrace, "action", route); \
81283625Sdim	  traceactionlog(action, route); \
82283625Sdim	}
83283625Sdim#define TRACE_SAP_ACTION(action, service) { \
84283625Sdim	  tracesapactionlog(action, service); \
85283625Sdim	}
86283625Sdim#define	TRACE_INPUT(ifp, src, size) { \
87283625Sdim	  if (tracing) { \
88283625Sdim		ifp = if_iflookup(src); \
89283625Sdim		if (ifp) \
90283625Sdim			trace(&ifp->int_input, src, \
91283625Sdim				&packet[sizeof(struct ipx)], size, \
92283625Sdim				ntohl(ifp->int_metric)); \
93283625Sdim	  } \
94283625Sdim	  if (tracepackets && ftrace) \
95283625Sdim		dumppacket(ftrace, "from", src, \
96309124Sdim				&packet[sizeof(struct ipx)], size); \
97309124Sdim	}
98309124Sdim#define	TRACE_OUTPUT(ifp, dst, size) { \
99309124Sdim	  if (tracing) { \
100309124Sdim		ifp = if_iflookup(dst); \
101309124Sdim		if (ifp) \
102283625Sdim		    trace(&ifp->int_output, dst, \
103309124Sdim				&packet[sizeof(struct ipx)], \
104314564Sdim				size, ifp->int_metric); \
105314564Sdim	  } \
106314564Sdim	  if (tracepackets && ftrace) \
107314564Sdim		dumppacket(ftrace, "to", dst, \
108314564Sdim				&packet[sizeof(struct ipx)], size); \
109314564Sdim	}
110314564Sdim
111283625Sdim#define	TRACE_SAP_OUTPUT(ifp, dst, size) { \
112314564Sdim	  if (tracing) { \
113314564Sdim		ifp = if_iflookup(dst); \
114283625Sdim		if (ifp) \
115314564Sdim		    trace(&ifp->int_output, dst, \
116314564Sdim				&packet[sizeof(struct ipx)], \
117314564Sdim				size, ifp->int_metric); \
118314564Sdim	  } \
119314564Sdim	  if (tracepackets && ftrace) \
120314564Sdim		dumpsappacket(ftrace, "to", dst, \
121309124Sdim				&packet[sizeof(struct ipx)], size); \
122314564Sdim	}
123314564Sdim
124314564Sdimvoid traceinit(struct interface *);
125283625Sdimvoid traceon(char *file);
126314564Sdimvoid traceoff(void);
127283625Sdimvoid traceaction(FILE *, char *, struct rt_entry *);
128283625Sdimvoid traceactionlog(char *, struct rt_entry *);
129283625Sdimvoid tracesapactionlog(char *action, struct sap_entry *sap);
130314564Sdimvoid trace(struct ifdebug *, struct sockaddr *, char *, int, int);
131314564Sdimvoid dumppacket(FILE *, char *, struct sockaddr *, char *, int);
132283625Sdimvoid dumpsappacket(FILE *, char *, struct sockaddr *, char *, int);
133283625Sdimvoid dumpsaptable(FILE *fd, struct sap_hash *sh);
134314564Sdimvoid dumpriptable(FILE *fd);
135309124Sdim
136283625Sdimchar *ipxdp_nettoa(union ipx_net);
137314564Sdimchar *ipxdp_ntoa(struct ipx_addr *);
138283625Sdim
139309124Sdim