source: lib/libtrace_int.h @ afd0b73

4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivegetfragoffhelplibtrace4ndag_formatpfringrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change on this file since afd0b73 was afd0b73, checked in by Shane Alcock <salcock@…>, 15 years ago

Changed rt protocol to not require subheaders

  • 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        struct libtrace_format_data_t *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        int (*fin_input)(libtrace_t *libtrace);
185        /** finish an output trace, cleanup (or NULL if output not supported) */
186        int (*fin_output)(libtrace_out_t *libtrace);
187        /** read a packet from a trace into the provided packet structure
188         * @returns -1 on error, or get_framing_length()+get_capture_length() \
189         * on success.
190         * if this function is not supported, this field may be NULL.
191         */
192        int (*read_packet)(libtrace_t *libtrace, struct libtrace_packet_t *packet);
193        /** write a packet to a trace from the provided packet
194         * (or NULL if output not supported)
195         */
196        int (*write_packet)(libtrace_out_t *libtrace, const libtrace_packet_t *packet);
197        /** return the libtrace link type for this packet
198         * @return the libtrace link type, or -1 if this link type is unknown
199         */ 
200        libtrace_linktype_t (*get_link_type)(const libtrace_packet_t *packet);
201        /** return the direction of this packet
202         * This function pointer may be NULL if the format does not support
203         * getting a direction.
204         */ 
205        int8_t (*get_direction)(const libtrace_packet_t *packet);
206        /** set the direction of this packet
207         * This function pointer may be NULL if the format does not support
208         * setting a direction.
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.