source: lib/libtrace_int.h @ 0d57541

4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivegetfragoffhelplibtrace4ndag_formatpfringrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change on this file since 0d57541 was 0d57541, checked in by Perry Lorier <perry@…>, 15 years ago

Add preliminary seek support

  • Property mode set to 100644
File size: 11.1 KB
Line 
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/** @file */
31
32#ifndef LIBTRACE_INT_H
33#define LIBTRACE_INT_H
34
35#ifdef __cplusplus
36extern "C" {
37#endif
38
39#include "common.h"
40#include "config.h"
41#include "libtrace.h"
42#include "fifo.h"
43#include "rt_protocol.h"
44       
45#if HAVE_PCAP_BPF_H
46#  include <pcap-bpf.h>
47#else
48#  ifdef HAVE_NET_BPF_H
49#    include <net/bpf.h>
50#  endif
51#endif
52
53#if HAVE_PCAP_H
54#  include <pcap.h>
55#  ifdef HAVE_PCAP_INT_H
56#    include <pcap-int.h>
57#  endif
58#endif
59
60#ifdef HAVE_ZLIB_H
61#  include <zlib.h>
62#endif
63
64
65#include "wag.h"
66#include "daglegacy.h"
67       
68#ifdef HAVE_DAG_API
69#  include "dagnew.h"
70#  include "dagapi.h"
71#else
72#  include "dagformat.h"
73#endif
74
75#include <stdbool.h>
76
77
78
79#define RP_BUFSIZE 65536
80
81struct libtrace_event_t {
82        libtrace_packet_t *packet;
83        int psize;
84        double tdelta;
85        double trace_last_ts;
86};
87
88/** The information about traces that are open
89 * @internal
90 */
91struct libtrace_t {
92        struct libtrace_format_t *format; /**< format driver pointer */
93        void *format_data; /**<format data pointer */
94        bool started;                   /**< if this trace has started */
95        libtrace_err_t err;             /**< error information */
96        struct libtrace_event_t event;  /**< the next event */
97        char *uridata;                  /**< the uri of this trace */
98        struct tracefifo_t *fifo;       /**< fifo used in this trace */
99        struct libtrace_filter_t *filter; /**< used by libtrace if the module
100                                            * doesn't support filters natively
101                                            */
102        int snaplen;                    /**< used by libtrace if the module
103                                          * doesn't support snapping natively
104                                          */
105};
106
107/** Information about output traces
108 * @internal
109 */
110struct libtrace_out_t {
111        struct libtrace_format_t *format;       /**< format driver */
112        void *format_data;              /**< format data */
113        bool started;                   /**< trace started */
114        libtrace_err_t err;             /**< Associated error */
115        char *uridata;                  /**< URI associated with this trace */
116};
117
118void trace_set_err(libtrace_t *trace, int errcode,const char *msg,...);
119void trace_set_err_out(libtrace_out_t *trace, int errcode, const char *msg,...);
120
121struct trace_sll_header_t {
122        uint16_t pkttype;               /* packet type */
123        uint16_t hatype;                /* link-layer address type */
124        uint16_t halen;                 /* link-layer address length */
125        char addr[8];                   /* link-layer address */
126        uint16_t protocol;              /* protocol */
127};
128
129#ifndef PF_RULESET_NAME_SIZE
130#define PF_RULESET_NAME_SIZE 16
131#endif
132
133#ifndef IFNAMSIZ
134#define IFNAMSIZ 16
135#endif
136
137struct trace_pflog_header_t {
138        uint8_t    length;
139        sa_family_t   af;
140        uint8_t    action;
141        uint8_t    reason;
142        char       ifname[IFNAMSIZ];
143        char       ruleset[PF_RULESET_NAME_SIZE];
144        uint32_t   rulenr;
145        uint32_t   subrulenr;
146        uint8_t    dir;
147        uint8_t    pad[3];
148};
149
150
151
152/** Module definition structure */
153/* all of these should return -1, or NULL on failure */
154struct libtrace_format_t {
155        /** the uri name of this module */
156        char *name;
157        /** the version of this module */
158        char *version;
159        /** the RT protocol type of this module */
160        enum base_format_t type;
161        /** stuff that deals with input @{ */
162        /** initialise an trace (or NULL if input is not supported) */
163        int (*init_input)(libtrace_t *libtrace);
164        /** configure an trace (or NULL if input is not supported) */
165        int (*config_input)(libtrace_t *libtrace,trace_option_t option,void *value);
166        /** start/unpause an trace (or NULL if input not supported) */
167        int (*start_input)(libtrace_t *libtrace);
168        /** pause an trace (or NULL if input not supported) */
169        int (*pause_input)(libtrace_t *libtrace);
170        /** @} */
171        /** stuff that deals with output @{ */
172        /** initialise output traces (or NULL if output not supported) */
173        int (*init_output)(libtrace_out_t *libtrace);
174        /** configure output traces (or NULL if output not supported) */
175        int (*config_output)(libtrace_out_t *libtrace, trace_option_output_t, void *);
176        /** start output traces (or NULL if output not supported)
177         * There is no pause for output traces, as packets are not arriving
178         * asyncronously
179         */
180        int (*start_output)(libtrace_out_t *libtrace);
181        /** @} */
182        /** finish an input trace, cleanup (or NULL if input not supported)
183         * if the trace is not paused, libtrace will pause the trace before
184         * calling this function.
185         */
186        int (*fin_input)(libtrace_t *libtrace);
187        /** finish an output trace, cleanup (or NULL if output not supported) */
188        int (*fin_output)(libtrace_out_t *libtrace);
189        /** read a packet from a trace into the provided packet structure
190         * @returns -1 on error, or get_framing_length()+get_capture_length() \
191         * on success.
192         * if this function is not supported, this field may be NULL.
193         */
194        int (*read_packet)(libtrace_t *libtrace, struct libtrace_packet_t *packet);
195        /** write a packet to a trace from the provided packet
196         * (or NULL if output not supported)
197         */
198        int (*write_packet)(libtrace_out_t *libtrace, const libtrace_packet_t *packet);
199        /** return the libtrace link type for this packet
200         * @return the libtrace link type, or -1 if this link type is unknown
201         */ 
202        libtrace_linktype_t (*get_link_type)(const libtrace_packet_t *packet);
203        /** return the direction of this packet
204         * @note This callback may be NULL if not supported.
205         */ 
206        int8_t (*get_direction)(const libtrace_packet_t *packet);
207        /** set the direction of this packet
208         * @note This callback may be NULL if not supported.
209         */ 
210        int8_t (*set_direction)(const libtrace_packet_t *packet, int8_t direction);
211        /** return the erf timestamp of the packet.
212         * @return the 64bit erf timestamp
213         * This field may be NULL in the structure, and libtrace will
214         * synthesise the result from get_timeval or get_seconds if they
215         * exist.  AT least one of get_erf_timestamp, get_timeval or
216         * get_seconds must be implemented.
217         */
218        uint64_t (*get_erf_timestamp)(const libtrace_packet_t *packet);
219        /** return the timeval of this packet.
220         * @return the timeval
221         * This field may be NULL in the structure, and libtrace will
222         * synthesise the result from get_erf_timestamp or get_seconds if they
223         * exist.  AT least one of get_erf_timestamp, get_timeval or
224         * get_seconds must be implemented.
225         */
226        struct timeval (*get_timeval)(const libtrace_packet_t *packet);
227        /** return the timestamp of this packet.
228         * @return the floating point seconds since 1970-01-01 00:00:00
229         * This field may be NULL in the structure, and libtrace will
230         * synthesise the result from get_timeval or get_erf_timestamp if they
231         * exist.  AT least one of get_erf_timestamp, get_timeval or
232         * get_seconds must be implemented.
233         */
234        double (*get_seconds)(const libtrace_packet_t *packet);
235        /** move the pointer within the trace.
236         * @return 0 on success, -1 on failure.
237         * The next packet returned by read_packet be the first
238         * packet in the trace to have a timestamp equal or greater than
239         * timestamp.
240         * @note this function may be NULL if the format does not support
241         * this feature.  If the format implements seek_timeval and/or
242         * seek_seconds then libtrace will call those functions instead.
243         */
244        int (*seek_erf)(libtrace_t *trace, uint64_t timestamp);
245        /** move the pointer within the trace.
246         * @return 0 on success, -1 on failure.
247         * The next packet returned by read_packet be the first
248         * packet in the trace to have a timestamp equal or greater than
249         * timestamp.
250         * @note this function may be NULL if the format does not support
251         * this feature.  If the format implements seek_erf and/or
252         * seek_seconds then libtrace will call those functions instead.
253         */
254        int (*seek_timeval)(libtrace_t *trace, struct timeval tv);
255        /** move the pointer within the trace.
256         * @return 0 on success, -1 on failure.
257         * The next packet returned by read_packet be the first
258         * packet in the trace to have a timestamp equal or greater than
259         * tv.
260         * @note this function may be NULL if the format does not support
261         * this feature.  If the format implements seek_erf and/or
262         * seek_timeval then libtrace will call those functions instead.
263         */
264        int (*seek_seconds)(libtrace_t *trace, double seconds);
265        /** return the captured payload length
266         * @return the amount of data captured in a trace.
267         * This is the number of bytes actually in the trace.  This does not
268         * include the trace framing length.  This is usually shorter or
269         * equal to the wire length.
270         */
271        int (*get_capture_length)(const libtrace_packet_t *packet);
272        /** return the original length of the packet on the wire.
273         * @return the length of the packet on the wire before truncation.
274         * This is the number of bytes actually in the trace.  This does not
275         * include the trace framing length.  This is usually shorter or
276         * equal to the wire length.
277         */
278        int (*get_wire_length)(const libtrace_packet_t *packet);
279        /** return the length of the trace framing header
280         * @return the length of the framing header
281         * The framing header is the extra metadata a trace stores about
282         * a packet.  This does not include the wire or capture length
283         * of the packet.  Usually get_framing_length()+get_capture_length()
284         * is the size returned by read_packet
285         */
286        int (*get_framing_length)(const libtrace_packet_t *packet);
287        /** truncate (snap) the packet
288         * @returns the new size
289         * @note This callback may be NULL if not supported.
290         */
291        size_t (*set_capture_length)(struct libtrace_packet_t *packet,size_t size);
292        /** return the filedescriptor associated with this interface.
293         * @note This callback may be NULL if not supported.
294         * This function is only needed if you use trace_event_interface
295         * as the pointer for trace_event
296         */
297        int (*get_fd)(const libtrace_t *trace);
298        /** return the next event from this source
299         * @note may be NULL if not supported.
300         */
301        struct libtrace_eventobj_t (*trace_event)(libtrace_t *trace, libtrace_packet_t *packet);       
302        /** return information about this trace format to standard out */
303        void (*help)();
304};
305
306extern struct libtrace_format_t *form;
307
308void register_format(struct libtrace_format_t *format);
309
310libtrace_linktype_t pcap_dlt_to_libtrace(int dlt);
311char libtrace_to_pcap_dlt(libtrace_linktype_t type);
312libtrace_linktype_t erf_type_to_libtrace(char erf);
313char libtrace_to_erf_type(libtrace_linktype_t linktype);
314
315#if HAVE_BPF
316/* A type encapsulating a bpf filter
317 * This type covers the compiled bpf filter, as well as the original filter
318 * string
319 *
320 */
321struct libtrace_filter_t {
322        struct bpf_program filter;
323        int flag;
324        char * filterstring;
325};
326#endif
327       
328#ifdef __cplusplus
329}
330#endif
331
332#endif /* LIBTRACE_INT_H */
Note: See TracBrowser for help on using the repository browser.