1 | /* |
---|
2 | * This file is part of libtrace |
---|
3 | * |
---|
4 | * Copyright (c) 2004 The University of Waikato, Hamilton, New Zealand. |
---|
5 | * Authors: Daniel Lawson |
---|
6 | * Perry Lorier |
---|
7 | * |
---|
8 | * All rights reserved. |
---|
9 | * |
---|
10 | * This code has been developed by the University of Waikato WAND |
---|
11 | * research group. For further information please see http://www.wand.net.nz/ |
---|
12 | * |
---|
13 | * libtrace is free software; you can redistribute it and/or modify |
---|
14 | * it under the terms of the GNU General Public License as published by |
---|
15 | * the Free Software Foundation; either version 2 of the License, or |
---|
16 | * (at your option) any later version. |
---|
17 | * |
---|
18 | * libtrace is distributed in the hope that it will be useful, |
---|
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
21 | * GNU General Public License for more details. |
---|
22 | * |
---|
23 | * You should have received a copy of the GNU General Public License |
---|
24 | * along with libtrace; if not, write to the Free Software |
---|
25 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
26 | * |
---|
27 | * $Id$ |
---|
28 | * |
---|
29 | */ |
---|
30 | |
---|
31 | #ifndef FORMAT_H |
---|
32 | #define FORMAT_H |
---|
33 | |
---|
34 | #ifdef __cplusplus |
---|
35 | extern "C" { |
---|
36 | #endif |
---|
37 | |
---|
38 | #include "common.h" |
---|
39 | #include "config.h" |
---|
40 | #include "libtrace.h" |
---|
41 | #include "fifo.h" |
---|
42 | #include "rtserver.h" |
---|
43 | |
---|
44 | #if HAVE_PCAP_BPF_H |
---|
45 | # include <pcap-bpf.h> |
---|
46 | #else |
---|
47 | # ifdef HAVE_NET_BPF_H |
---|
48 | # include <net/bpf.h> |
---|
49 | # endif |
---|
50 | #endif |
---|
51 | |
---|
52 | #if HAVE_PCAP_H |
---|
53 | # include <pcap.h> |
---|
54 | # ifdef HAVE_PCAP_INT_H |
---|
55 | # include <pcap-int.h> |
---|
56 | # endif |
---|
57 | #endif |
---|
58 | |
---|
59 | #ifdef HAVE_ZLIB_H |
---|
60 | # include <zlib.h> |
---|
61 | #endif |
---|
62 | |
---|
63 | |
---|
64 | #include "wag.h" |
---|
65 | |
---|
66 | #ifdef HAVE_DAG_API |
---|
67 | # include "dagnew.h" |
---|
68 | # include "dagapi.h" |
---|
69 | #else |
---|
70 | # include "dagformat.h" |
---|
71 | #endif |
---|
72 | |
---|
73 | typedef enum {SOCKET, TRACE, STDIN, DEVICE, INTERFACE, RT } source_t; |
---|
74 | |
---|
75 | #define RP_BUFSIZE 65536 |
---|
76 | |
---|
77 | /** The information about traces that are open |
---|
78 | * @internal |
---|
79 | */ |
---|
80 | struct libtrace_t { |
---|
81 | struct format_t *format; /**< format driver pointer */ |
---|
82 | source_t sourcetype; /**< The type (device,file, etc */ |
---|
83 | |
---|
84 | union { |
---|
85 | /** Information about rtclients */ |
---|
86 | struct { |
---|
87 | char *hostname; |
---|
88 | short port; |
---|
89 | } rt; |
---|
90 | char *path; /**< information for local sockets */ |
---|
91 | char *interface; /**< intormation for reading of network |
---|
92 | interfaces */ |
---|
93 | } conn_info; |
---|
94 | /** Information about the current state of the input device */ |
---|
95 | union { |
---|
96 | int fd; |
---|
97 | #if HAVE_ZLIB |
---|
98 | gzFile *file; |
---|
99 | #else |
---|
100 | FILE *file; |
---|
101 | #endif |
---|
102 | #if HAVE_PCAP |
---|
103 | pcap_t *pcap; |
---|
104 | #endif |
---|
105 | } input; |
---|
106 | |
---|
107 | struct fifo_t *fifo; |
---|
108 | struct { |
---|
109 | void *buf; |
---|
110 | unsigned bottom; |
---|
111 | unsigned top; |
---|
112 | unsigned diff; |
---|
113 | unsigned curr; |
---|
114 | unsigned offset; |
---|
115 | } dag; |
---|
116 | struct { |
---|
117 | void *buffer; |
---|
118 | int size; |
---|
119 | } packet; |
---|
120 | double tdelta; |
---|
121 | double trace_start_ts; |
---|
122 | double real_start_ts; |
---|
123 | double trace_last_ts; |
---|
124 | |
---|
125 | double last_ts; |
---|
126 | double start_ts; |
---|
127 | }; |
---|
128 | |
---|
129 | struct libtrace_out_t { |
---|
130 | struct format_t * format; |
---|
131 | |
---|
132 | union { |
---|
133 | struct { |
---|
134 | char *hostname; |
---|
135 | short port; |
---|
136 | } rt; |
---|
137 | char *path; |
---|
138 | char *interface; |
---|
139 | } conn_info; |
---|
140 | |
---|
141 | union { |
---|
142 | int fd; |
---|
143 | struct rtserver_t * rtserver; |
---|
144 | #if HAVE_ZLIB |
---|
145 | gzFile *file; |
---|
146 | #else |
---|
147 | FILE *file; |
---|
148 | #endif |
---|
149 | #if HAVE_PCAP |
---|
150 | pcap_t *pcap; |
---|
151 | #endif |
---|
152 | } output; |
---|
153 | |
---|
154 | struct fifo_t *fifo; |
---|
155 | |
---|
156 | |
---|
157 | }; |
---|
158 | |
---|
159 | |
---|
160 | struct trace_sll_header_t { |
---|
161 | uint16_t pkttype; /* packet type */ |
---|
162 | uint16_t hatype; /* link-layer address type */ |
---|
163 | uint16_t halen; /* link-layer address length */ |
---|
164 | char addr[8]; /* link-layer address */ |
---|
165 | uint16_t protocol; /* protocol */ |
---|
166 | }; |
---|
167 | |
---|
168 | #ifndef PF_RULESET_NAME_SIZE |
---|
169 | #define PF_RULESET_NAME_SIZE 16 |
---|
170 | #endif |
---|
171 | |
---|
172 | #ifndef IFNAMSIZ |
---|
173 | #define IFNAMSIZ 16 |
---|
174 | #endif |
---|
175 | |
---|
176 | struct trace_pflog_header_t { |
---|
177 | uint8_t length; |
---|
178 | sa_family_t af; |
---|
179 | uint8_t action; |
---|
180 | uint8_t reason; |
---|
181 | char ifname[IFNAMSIZ]; |
---|
182 | char ruleset[PF_RULESET_NAME_SIZE]; |
---|
183 | uint32_t rulenr; |
---|
184 | uint32_t subrulenr; |
---|
185 | uint8_t dir; |
---|
186 | uint8_t pad[3]; |
---|
187 | }; |
---|
188 | |
---|
189 | struct format_t { |
---|
190 | char *name; |
---|
191 | char *version; |
---|
192 | int (*init_input)(struct libtrace_t *libtrace); |
---|
193 | int (*init_output)(struct libtrace_out_t *libtrace); |
---|
194 | int (*fin_input)(struct libtrace_t *libtrace); |
---|
195 | int (*fin_output)(struct libtrace_out_t *libtrace); |
---|
196 | int (*read)(struct libtrace_t *libtrace, void *buffer, size_t len); |
---|
197 | int (*read_packet)(struct libtrace_t *libtrace, struct libtrace_packet_t *packet); |
---|
198 | int (*write_packet)(struct libtrace_out_t *libtrace, struct libtrace_packet_t *packet); |
---|
199 | void* (*get_link)(const struct libtrace_packet_t *packet); |
---|
200 | libtrace_linktype_t (*get_link_type)(const struct libtrace_packet_t *packet); |
---|
201 | int8_t (*get_direction)(const struct libtrace_packet_t *packet); |
---|
202 | int8_t (*set_direction)(const struct libtrace_packet_t *packet, int8_t direction); |
---|
203 | uint64_t (*get_erf_timestamp)(const struct libtrace_packet_t *packet); |
---|
204 | struct timeval (*get_timeval)(const struct libtrace_packet_t *packet); |
---|
205 | double (*get_seconds)(const struct libtrace_packet_t *packet); |
---|
206 | int (*get_capture_length)(const struct libtrace_packet_t *packet); |
---|
207 | int (*get_wire_length)(const struct libtrace_packet_t *packet); |
---|
208 | size_t (*truncate_packet)(const struct libtrace_packet_t *packet,size_t size); |
---|
209 | }; |
---|
210 | |
---|
211 | extern struct format_t *form; |
---|
212 | |
---|
213 | void register_format(struct format_t *format); |
---|
214 | |
---|
215 | #ifdef __cplusplus |
---|
216 | } |
---|
217 | #endif |
---|
218 | |
---|
219 | #endif // FORMAT_H |
---|