source: lib/libtrace_int.h @ ab4cb04

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

Cleanup struct libtrace_Format_data_t

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