source: lib/libtrace_int.h @ 67a14d4

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

Move more types to the libtrace standard (typedef'd libtrace_*_t)
Add casts where appropriate
Remove default:'s from enum'd switch()'s

  • Property mode set to 100644
File size: 11.5 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_status_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_status_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
121typedef struct libtrace_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} libtrace_sll_header_t;
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
137typedef struct libtrace_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} libtrace_pflog_header_t;
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        /** finalise a packet
196         * cleanup any resources used by a packet that can't be reused for
197         * the next packet.
198         */
199        void (*fin_packet)(libtrace_packet_t *packet);
200        /** write a packet to a trace from the provided packet
201         * (or NULL if output not supported)
202         */
203        int (*write_packet)(libtrace_out_t *libtrace, const libtrace_packet_t *packet);
204        /** return the libtrace link type for this packet
205         * @return the libtrace link type, or -1 if this link type is unknown
206         */ 
207        libtrace_linktype_t (*get_link_type)(const libtrace_packet_t *packet);
208        /** return the direction of this packet
209         * @note This callback may be NULL if not supported.
210         */ 
211        int8_t (*get_direction)(const libtrace_packet_t *packet);
212        /** set the direction of this packet
213         * @note This callback may be NULL if not supported.
214         */ 
215        int8_t (*set_direction)(const libtrace_packet_t *packet, int8_t direction);
216        /** return the erf timestamp of the packet.
217         * @return the 64bit erf timestamp
218         * This field may be NULL in the structure, and libtrace will
219         * synthesise the result from get_timeval or get_seconds if they
220         * exist.  AT least one of get_erf_timestamp, get_timeval or
221         * get_seconds must be implemented.
222         */
223        uint64_t (*get_erf_timestamp)(const libtrace_packet_t *packet);
224        /** return the timeval of this packet.
225         * @return the timeval
226         * This field may be NULL in the structure, and libtrace will
227         * synthesise the result from get_erf_timestamp or get_seconds if they
228         * exist.  AT least one of get_erf_timestamp, get_timeval or
229         * get_seconds must be implemented.
230         */
231        struct timeval (*get_timeval)(const libtrace_packet_t *packet);
232        /** return the timestamp of this packet.
233         * @return the floating point seconds since 1970-01-01 00:00:00
234         * This field may be NULL in the structure, and libtrace will
235         * synthesise the result from get_timeval or get_erf_timestamp if they
236         * exist.  AT least one of get_erf_timestamp, get_timeval or
237         * get_seconds must be implemented.
238         */
239        double (*get_seconds)(const libtrace_packet_t *packet);
240        /** move the pointer within the trace.
241         * @return 0 on success, -1 on failure.
242         * The next packet returned by read_packet be the first
243         * packet in the trace to have a timestamp equal or greater than
244         * timestamp.
245         * @note this function may be NULL if the format does not support
246         * this feature.  If the format implements seek_timeval and/or
247         * seek_seconds then libtrace will call those functions instead.
248         */
249        int (*seek_erf)(libtrace_t *trace, uint64_t timestamp);
250        /** move the pointer within the trace.
251         * @return 0 on success, -1 on failure.
252         * The next packet returned by read_packet be the first
253         * packet in the trace to have a timestamp equal or greater than
254         * timestamp.
255         * @note this function may be NULL if the format does not support
256         * this feature.  If the format implements seek_erf and/or
257         * seek_seconds then libtrace will call those functions instead.
258         */
259        int (*seek_timeval)(libtrace_t *trace, struct timeval tv);
260        /** move the pointer within the trace.
261         * @return 0 on success, -1 on failure.
262         * The next packet returned by read_packet be the first
263         * packet in the trace to have a timestamp equal or greater than
264         * tv.
265         * @note this function may be NULL if the format does not support
266         * this feature.  If the format implements seek_erf and/or
267         * seek_timeval then libtrace will call those functions instead.
268         */
269        int (*seek_seconds)(libtrace_t *trace, double seconds);
270        /** return the captured payload length
271         * @return the amount of data captured in a trace.
272         * This is the number of bytes actually in the trace.  This does not
273         * include the trace framing length.  This is usually shorter or
274         * equal to the wire length.
275         */
276        int (*get_capture_length)(const libtrace_packet_t *packet);
277        /** return the original length of the packet on the wire.
278         * @return the length of the packet on the wire before truncation.
279         * This is the number of bytes actually in the trace.  This does not
280         * include the trace framing length.  This is usually shorter or
281         * equal to the wire length.
282         */
283        int (*get_wire_length)(const libtrace_packet_t *packet);
284        /** return the length of the trace framing header
285         * @return the length of the framing header
286         * The framing header is the extra metadata a trace stores about
287         * a packet.  This does not include the wire or capture length
288         * of the packet.  Usually get_framing_length()+get_capture_length()
289         * is the size returned by read_packet
290         */
291        int (*get_framing_length)(const libtrace_packet_t *packet);
292        /** truncate (snap) the packet
293         * @returns the new size
294         * @note This callback may be NULL if not supported.
295         */
296        size_t (*set_capture_length)(struct libtrace_packet_t *packet,size_t size);
297        /** return the filedescriptor associated with this interface.
298         * @note This callback may be NULL if not supported.
299         * This function is only needed if you use trace_event_interface
300         * as the pointer for trace_event
301         */
302        int (*get_fd)(const libtrace_t *trace);
303        /** return the next event from this source
304         * @note may be NULL if not supported.
305         */
306        struct libtrace_eventobj_t (*trace_event)(libtrace_t *trace, libtrace_packet_t *packet);       
307        /** return information about this trace format to standard out */
308        void (*help)();
309        /** next pointer, should be NULL */
310        struct libtrace_format_t *next;
311};
312
313extern struct libtrace_format_t *form;
314
315void register_format(struct libtrace_format_t *format);
316
317libtrace_linktype_t pcap_dlt_to_libtrace(int dlt);
318char libtrace_to_pcap_dlt(libtrace_linktype_t type);
319enum rt_field_t pcap_dlt_to_rt(int dlt);
320int rt_to_pcap_dlt(enum rt_field_t rt_type);
321libtrace_linktype_t erf_type_to_libtrace(char erf);
322char libtrace_to_erf_type(libtrace_linktype_t linktype);
323
324#if HAVE_BPF
325/* A type encapsulating a bpf filter
326 * This type covers the compiled bpf filter, as well as the original filter
327 * string
328 *
329 */
330struct libtrace_filter_t {
331        struct bpf_program filter;
332        int flag;
333        char * filterstring;
334};
335#endif
336       
337#ifdef __cplusplus
338}
339#endif
340
341#endif /* LIBTRACE_INT_H */
Note: See TracBrowser for help on using the repository browser.