xref: /illumos-gate/usr/src/cmd/cmd-inet/usr.lib/in.ripngd/trace.h (revision 86d949f9497332fe19be6b5d711d265eb957439f)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 1999 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
28 /*	  All Rights Reserved  	*/
29 
30 /*
31  * Portions of this source code were derived from Berkeley 4.3 BSD
32  * under license from the Regents of the University of California.
33  */
34 
35 /*
36  * Routing table management daemon.
37  */
38 
39 /*
40  * Trace record format.
41  */
42 struct	iftrace {
43 	time_t	ift_stamp;		/* time stamp */
44 	struct	sockaddr_in6 ift_who;	/* from/to */
45 	char	*ift_packet;		/* pointer to packet */
46 	int	ift_size;		/* size of packet */
47 	int	ift_metric;		/* metric on associated metric */
48 };
49 
50 /*
51  * Per interface packet tracing buffers.  An incoming and
52  * outgoing circular buffer of packets is maintained, per
53  * interface, for debugging.  Buffers are dumped whenever
54  * an interface is marked down.
55  */
56 struct	ifdebug {
57 	struct	iftrace *ifd_records;	/* array of trace records */
58 	struct	iftrace *ifd_front;	/* next empty trace record */
59 	int	ifd_count;		/* number of unprinted records */
60 	struct	interface *ifd_if;	/* for locating stuff */
61 };
62 
63 /*
64  * Packet tracing stuff.
65  */
66 extern FILE		*ftrace;
67 extern boolean_t	tracepackets;
68 extern int		tracing;
69 
70 #define	ACTION_BIT	0x0001
71 #define	INPUT_BIT	0x0002
72 #define	OUTPUT_BIT	0x0004
73 
74 #define	TRACE_ACTION(action, route) { \
75 	if (tracing & ACTION_BIT) \
76 		traceaction(ftrace, (action), (route)); \
77 }
78 
79 #define	TRACE_INPUT(ifp, src, size) { \
80 	if ((tracing & INPUT_BIT) && ((ifp) != NULL)) { \
81 		trace(&(ifp)->int_input, (src), packet, (size), \
82 		    (ifp)->int_metric); \
83 	} \
84 	if (tracepackets) { \
85 		dumppacket(stdout, "from", (struct sockaddr_in6 *)(src), \
86 		    packet, (size)); \
87 	} \
88 }
89 #define	TRACE_OUTPUT(ifp, dst, size) { \
90 	if ((tracing & OUTPUT_BIT) && ((ifp) != NULL)) { \
91 		trace(&(ifp)->int_output, (dst), packet, (size), \
92 		    (ifp)->int_metric); \
93 	} \
94 	if (tracepackets) { \
95 		dumppacket(stdout, "to", (struct sockaddr_in6 *)(dst), \
96 		    packet, (size)); \
97 	} \
98 }
99 
100 extern void	dumppacket(FILE *, char *, struct sockaddr_in6 *, char *, int);
101 extern void	trace(struct ifdebug *, struct sockaddr_in6 *, char *, int,
102     int);
103 extern void	traceaction(FILE *, char *, struct rt_entry *);
104 extern void	traceinit(struct interface *);
105 extern void	traceon(char *);
106 extern void	traceonfp(FILE *);
107