1/*
2 * Copyright (c) 1983, 1993
3 *	The Regents of the University of California.  All rights reserved.
4 *
5 * Copyright (c) 1995 John Hay.  All rights reserved.
6 *
7 * This file includes significant work done at Cornell University by
8 * Bill Nesheim.  That work included by permission.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 *    notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 *    notice, this list of conditions and the following disclaimer in the
17 *    documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 *    must display the following acknowledgement:
20 *	This product includes software developed by the University of
21 *	California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 *    may be used to endorse or promote products derived from this software
24 *    without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 *	@(#)trace.h	8.1 (Berkeley) 6/5/93
39 *
40 * $FreeBSD$
41 */
42
43/*
44 * IPX Routing Information Protocol.
45 */
46
47/*
48 * Trace record format.
49 */
50struct	iftrace {
51	time_t	ift_stamp;		/* time stamp */
52	struct	sockaddr ift_who;	/* from/to */
53	char	*ift_packet;		/* pointer to packet */
54	short	ift_size;		/* size of packet */
55	short	ift_metric;		/* metric  */
56};
57
58/*
59 * Per interface packet tracing buffers.  An incoming and
60 * outgoing circular buffer of packets is maintained, per
61 * interface, for debugging.  Buffers are dumped whenever
62 * an interface is marked down.
63 */
64struct	ifdebug {
65	struct	iftrace *ifd_records;	/* array of trace records */
66	struct	iftrace *ifd_front;	/* next empty trace record */
67	int	ifd_count;		/* number of unprinted records */
68	struct	interface *ifd_if;	/* for locating stuff */
69};
70
71/*
72 * Packet tracing stuff.
73 */
74int	tracepackets;		/* watch packets as they go by */
75int	tracing;		/* on/off */
76FILE	*ftrace;		/* output trace file */
77
78#define	TRACE_ACTION(action, route) { \
79	  if (tracing) \
80		traceaction(ftrace, "action", route); \
81	  traceactionlog(action, route); \
82	}
83#define TRACE_SAP_ACTION(action, service) { \
84	  tracesapactionlog(action, service); \
85	}
86#define	TRACE_INPUT(ifp, src, size) { \
87	  if (tracing) { \
88		ifp = if_iflookup(src); \
89		if (ifp) \
90			trace(&ifp->int_input, src, \
91				&packet[sizeof(struct ipx)], size, \
92				ntohl(ifp->int_metric)); \
93	  } \
94	  if (tracepackets && ftrace) \
95		dumppacket(ftrace, "from", src, \
96				&packet[sizeof(struct ipx)], size); \
97	}
98#define	TRACE_OUTPUT(ifp, dst, size) { \
99	  if (tracing) { \
100		ifp = if_iflookup(dst); \
101		if (ifp) \
102		    trace(&ifp->int_output, dst, \
103				&packet[sizeof(struct ipx)], \
104				size, ifp->int_metric); \
105	  } \
106	  if (tracepackets && ftrace) \
107		dumppacket(ftrace, "to", dst, \
108				&packet[sizeof(struct ipx)], size); \
109	}
110
111#define	TRACE_SAP_OUTPUT(ifp, dst, size) { \
112	  if (tracing) { \
113		ifp = if_iflookup(dst); \
114		if (ifp) \
115		    trace(&ifp->int_output, dst, \
116				&packet[sizeof(struct ipx)], \
117				size, ifp->int_metric); \
118	  } \
119	  if (tracepackets && ftrace) \
120		dumpsappacket(ftrace, "to", dst, \
121				&packet[sizeof(struct ipx)], size); \
122	}
123
124void traceinit(struct interface *);
125void traceon(char *file);
126void traceoff(void);
127void traceaction(FILE *, char *, struct rt_entry *);
128void traceactionlog(char *, struct rt_entry *);
129void tracesapactionlog(char *action, struct sap_entry *sap);
130void trace(struct ifdebug *, struct sockaddr *, char *, int, int);
131void dumppacket(FILE *, char *, struct sockaddr *, char *, int);
132void dumpsappacket(FILE *, char *, struct sockaddr *, char *, int);
133void dumpsaptable(FILE *fd, struct sap_hash *sh);
134void dumpriptable(FILE *fd);
135
136char *ipxdp_nettoa(union ipx_net);
137char *ipxdp_ntoa(struct ipx_addr *);
138
139