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