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