1/* trace.h 2 3 Definitions for omapi tracing facility... */ 4 5/* 6 * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") 7 * Copyright (c) 2001-2003 by Internet Software Consortium 8 * 9 * Permission to use, copy, modify, and distribute this software for any 10 * purpose with or without fee is hereby granted, provided that the above 11 * copyright notice and this permission notice appear in all copies. 12 * 13 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES 14 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 15 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR 16 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 17 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 18 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT 19 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 20 * 21 * Internet Systems Consortium, Inc. 22 * 950 Charter Street 23 * Redwood City, CA 94063 24 * <info@isc.org> 25 * http://www.isc.org/ 26 * 27 * This software has been written for Internet Systems Consortium 28 * by Ted Lemon, as part of a project for Nominum, Inc. To learn more 29 * about Internet Systems Consortium, see http://www.isc.org/. To 30 * learn more about Nominum, Inc., see ``http://www.nominum.com''. 31 */ 32 33#define TRACEFILE_MAGIC 0x64484370UL /* dHCp */ 34#define TRACEFILE_VERSION 1 35 36/* The first thing in a trace file is the header, which basically just 37 defines the version of the file. */ 38typedef struct { 39 u_int32_t magic; /* Magic number for trace file. */ 40 u_int32_t version; /* Version of file. */ 41 int32_t hlen; /* Length of this header. */ 42 int32_t phlen; /* Length of packet headers. */ 43} tracefile_header_t; 44 45/* The trace file is composed of a bunch of trace packets. Each such packet 46 has a type, followed by a length, followed by a timestamp, followed by 47 the actual contents of the packet. The type indexes are not fixed - 48 they are allocated either on readback or when writing a trace file. 49 One index type is reserved - type zero means that this record is a type 50 name to index mapping. */ 51typedef struct { 52 u_int32_t type_index; /* Index to the type of handler that this 53 packet needs. */ 54 u_int32_t length; /* Length of the packet. This includes 55 everything except the fixed header. */ 56 u_int32_t when; /* When the packet was written. */ 57 u_int32_t pad; /* Round this out to a quad boundary. */ 58} tracepacket_t; 59 60#define TRACE_INDEX_MAPPING_SIZE 4 /* trace_index_mapping_t less name. */ 61typedef struct { 62 u_int32_t index; 63 char name [1]; 64} trace_index_mapping_t; 65 66struct trace_type; /* forward */ 67typedef struct trace_type trace_type_t; 68 69struct trace_type { 70 trace_type_t *next; 71 int index; 72 char *name; 73 void *baggage; 74 void (*have_packet) (trace_type_t *, unsigned, char *); 75 void (*stop_tracing) (trace_type_t *); 76}; 77 78typedef struct trace_iov { 79 const char *buf; 80 unsigned len; 81} trace_iov_t; 82 83typedef struct { 84 u_int16_t addrtype; 85 u_int16_t addrlen; 86 u_int8_t address [16]; 87 u_int16_t port; 88} trace_addr_t; 89 90void trace_free_all (void); 91int trace_playback (void); 92int trace_record (void); 93isc_result_t trace_init (void (*set_time) (u_int32_t), const char *, int); 94isc_result_t trace_begin (const char *, const char *, int); 95isc_result_t trace_write_packet (trace_type_t *, unsigned, const char *, 96 const char *, int); 97isc_result_t trace_write_packet_iov (trace_type_t *, int, trace_iov_t *, 98 const char *, int); 99void trace_type_stash (trace_type_t *); 100trace_type_t *trace_type_register (const char *, void *, 101 void (*) (trace_type_t *, 102 unsigned, char *), 103 void (*) (trace_type_t *), 104 const char *, int); 105void trace_stop (void); 106void trace_index_map_input (trace_type_t *, unsigned, char *); 107void trace_index_stop_tracing (trace_type_t *); 108void trace_replay_init (void); 109void trace_file_replay (const char *); 110isc_result_t trace_get_next_packet (trace_type_t **, tracepacket_t *, 111 char **, unsigned *, unsigned *); 112isc_result_t trace_get_file (trace_type_t *, 113 const char *, unsigned *, char **); 114isc_result_t trace_get_packet (trace_type_t **, unsigned *, char **); 115time_t trace_snoop_time (trace_type_t **); 116