source: lib/libtrace_int.h @ d5879cc

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

Fix various issues

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