source: lib/libtrace_int.h @ ee6e802

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

Updated copyright blurb on all source files

In some cases, this meant adding copyright blurbs to files that
had never had them before.

  • Property mode set to 100644
File size: 42.9 KB
RevLine 
[4dedc28]1/*
2 *
[ee6e802]3 * Copyright (c) 2007-2016 The University of Waikato, Hamilton, New Zealand.
[4dedc28]4 * All rights reserved.
5 *
[ee6e802]6 * This file is part of libtrace.
7 *
8 * This code has been developed by the University of Waikato WAND
[4dedc28]9 * research group. For further information please see http://www.wand.net.nz/
10 *
11 * libtrace is free software; you can redistribute it and/or modify
[ee6e802]12 * it under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
[4dedc28]14 * (at your option) any later version.
15 *
16 * libtrace is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
[ee6e802]19 * GNU Lesser General Public License for more details.
[4dedc28]20 *
[ee6e802]21 * You should have received a copy of the GNU Lesser General Public License
22 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
[4dedc28]23 *
24 *
25 */
[8488c15]26/** @file
27 *
28 * @brief Header file containing definitions for structures and functions that
29 * are internal
30 *
31 * @author Daniel Lawson
32 * @author Perry Lorier
33 * @author Shane Alcock
34 *
35 * @version $Id$
36 *
37 * All of the structures and functions defined in this header file are intended
38 * for internal use within Libtrace only. They should not be exported as part
39 * of the library API as we don't want users accessing things like the
40 * contents of the libtrace packet structure directly!
41 */
[9e2a109]42#ifndef LIBTRACE_INT_H
43#define LIBTRACE_INT_H
[4dedc28]44
45#ifdef __cplusplus
46extern "C" {
47#endif
48
49#include "config.h"
[1326d5f]50#include "common.h"
[6a082f8]51#include "libtrace_parallel.h"
[91b72d3]52#include "wandio.h"
[8b49230]53#include "lt_bswap.h"
[af52072]54
55#ifdef _MSC_VER
[6ed6c4a]56// warning: deprecated function
[af52072]57#pragma warning(disable:4996)
[6ed6c4a]58// warning: benign redefinitions of types
59#pragma warning(disable:4142)
[af52072]60#endif
61
62#ifdef HAVE_INTTYPES_H
63# include <inttypes.h>
64#else
65# include "lt_inttypes.h"
66#endif
67
68#ifdef HAVE_STDDEF_H
69# include <stddef.h>
70#else
71#ifndef WIN32
72# error "Can't find stddev.h -- do you define ptrdiff_t elsewhere?"
73#endif
74#endif
75
76
[afd0b73]77#include "rt_protocol.h"
[c1f2553]78       
[1f47cdd]79/* Prefer net/bpf.h over pcap-bpf.h for format_bpf.c on MacOS */
[5361eae]80#ifdef HAVE_NET_BPF_H
81#    include <net/bpf.h>
82#    define HAVE_BPF 1
83#else
[e5c2bc4]84#ifdef HAVE_PCAP_BPF_H
[4dedc28]85#  include <pcap-bpf.h>
[e5c2bc4]86#  define HAVE_BPF 1
[5361eae]87#endif
[4dedc28]88#endif
89
[e5c2bc4]90#ifdef HAVE_PCAP_H
[4dedc28]91#  include <pcap.h>
92#  ifdef HAVE_PCAP_INT_H
93#    include <pcap-int.h>
94#  endif
95#endif
96
[e5c2bc4]97#ifdef HAVE_ZLIB_H
[4dedc28]98#  include <zlib.h>
99#endif
100
[1576a3b]101#ifndef HAVE_STRNDUP
102char *strndup(const char *s, size_t size);
103#endif
104
[39e141f]105#ifndef HAVE_STRNCASECMP
106# ifndef HAVE__STRNICMP
[8488c15]107/** A local implementation of strncasecmp (as some systems do not have it) */
[39e141f]108int strncasecmp(const char *str1, const char *str2, size_t n);
109# else
110# define strncasecmp _strnicmp
111# endif
112#endif
113
114#ifndef HAVE_SNPRINTF
115# ifndef HAVE_SPRINTF_S
[8488c15]116/** A local implementation of snprintf (as some systems do not have it) */
[39e141f]117int snprintf(char *str, size_t size, const char *format, ...);
118# else
119# define snprintf sprintf_s
120# endif
121#endif
[4dedc28]122
[f9374e9]123#include "daglegacy.h"
124       
[4dedc28]125#ifdef HAVE_DAG_API
126#  include "dagnew.h"
127#  include "dagapi.h"
[2317d78]128#       if DAG_VERSION == 24
[2faa57e]129#               include <erftypes.h>
[2317d78]130#       else
131#               include <daginf.h>
[deed208]132#       endif
[ae3779b]133#  include "erftypes.h"
[4dedc28]134#else
135#  include "dagformat.h"
136#endif
137
[31a15db]138#ifdef HAVE_LLVM
139#include "bpf-jit/bpf-jit.h"
140#endif
141
[d6a56b6]142#include "data-struct/ring_buffer.h"
[a49a9eb]143#include "data-struct/object_cache.h"
[d6a56b6]144#include "data-struct/vector.h"
145#include "data-struct/message_queue.h"
146#include "data-struct/deque.h"
[cb39d35]147#include "data-struct/linked_list.h"
[d6a56b6]148#include "data-struct/sliding_window.h"
[d391ce0]149#include "data-struct/buckets.h"
[c63bcdf]150#include "pthread_spinlock.h"
[d6a56b6]151
[8488c15]152//#define RP_BUFSIZE 65536U
[4dedc28]153
[8488c15]154/** Data about the most recent event from a trace file */
[67a14d4]155struct libtrace_event_status_t {
[8488c15]156        /** A libtrace packet to store the packet when a PACKET event occurs */
[0d57541]157        libtrace_packet_t *packet;
[8488c15]158        /** Time between the timestamp for the current packet and the current
159         * walltime */
[4dedc28]160        double tdelta;
[8488c15]161        /** The timestamp of the previous PACKET event */
[4dedc28]162        double trace_last_ts;
[8488c15]163        /** The size of the current PACKET event */
[25024fd]164        int psize;
[9cc1266]165        /** Whether there is a packet stored in *packet above waiting for an
166         * event to occur */
167        bool waiting;
[4dedc28]168};
169
[29bbef0]170enum thread_types {
171        THREAD_EMPTY,
172        THREAD_HASHER,
[17a3dff]173        THREAD_PERPKT,
[f051c1b]174        THREAD_REPORTER,
[82facc5]175        THREAD_KEEPALIVE
[29bbef0]176};
177
178enum thread_states {
179        THREAD_RUNNING,
180        THREAD_FINISHING,
181        THREAD_FINISHED,
[3296252]182        THREAD_PAUSED,
183        THREAD_STATE_MAX
[29bbef0]184};
185
186/**
187 * Information of this thread
188 */
[8c42377]189struct libtrace_thread_t {
[368a1ae]190        uint64_t accepted_packets; // The number of packets accepted only used if pread
191        uint64_t filtered_packets;
[be3f75b]192        // is retreving packets
193        // Set to true once the first packet has been stored
194        bool recorded_first;
195        // For thread safety reason we actually must store this here
196        int64_t tracetime_offset_usec;
197        void* user_data; // TLS for the user to use
198        void* format_data; // TLS for the format to use
199        libtrace_message_queue_t messages; // Message handling
200        libtrace_ringbuffer_t rbuffer; // Input
[29bbef0]201        libtrace_t * trace;
202        void* ret;
203        enum thread_types type;
204        enum thread_states state;
205        pthread_t tid;
[17a3dff]206        int perpkt_num; // A number from 0-X that represents this perpkt threads number
[29bbef0]207                                // in the table, intended to quickly identify this thread
[17a3dff]208                                // -1 represents NA (such as the case this is not a perpkt thread)
[0a52945]209} ALIGN_STRUCT(CACHE_LINE_SIZE);
[29bbef0]210
211/**
212 * Storage to note time value against each.
213 * Used both internally to do trace time playback
214 * and can be used externally to assist applications which need
215 * a trace starting time such as tracertstats.
216 */
217struct first_packets {
218        pthread_spinlock_t lock;
[17a3dff]219        size_t count; // If == perpkt_thread_count threads we have all
[29bbef0]220        size_t first; // Valid if count != 0
[6a6e6a8]221        struct {
[29bbef0]222                libtrace_packet_t * packet;
223                struct timeval tv;
224        } * packets;
225};
226
[fac8c46]227#define TRACE_STATES \
228        X(STATE_NEW) \
229        X(STATE_RUNNING) \
230        X(STATE_PAUSING) \
231        X(STATE_PAUSED) \
[ac65c9f]232        X(STATE_FINISHED) \
233        X(STATE_FINISHING) \
[fac8c46]234        X(STATE_DESTROYED) \
[b13b939]235        X(STATE_JOINED) \
236        X(STATE_ERROR)
[fac8c46]237
238#define X(a) a,
239enum trace_state {
240        TRACE_STATES
241};
242#undef X
243
244#define X(a) case a: return #a;
245static inline char *get_trace_state_name(enum trace_state ts){
246        switch(ts) {
247                TRACE_STATES
248                default:
249                        return "UNKNOWN";
250        }
251}
252#undef X
[29bbef0]253
[6a082f8]254#define READ_EOF 0
255#define READ_ERROR -1
256#define READ_MESSAGE -2
257// Used for inband tick message
258#define READ_TICK -3
259
[6b98325]260/**
261 * Tuning the parallel sizes
262 * See the user documentation trace_set_x
263 */
264struct user_configuration {
265        size_t cache_size;
266        size_t thread_cache_size;
267        bool fixed_count;
268        size_t burst_size;
269        size_t tick_interval;
270        size_t tick_count;
271        size_t perpkt_threads;
272        size_t hasher_queue_size;
273        bool hasher_polling;
274        bool reporter_polling;
275        size_t reporter_thold;
276        bool debug_state;
277};
278#define ZERO_USER_CONFIG(config) memset(&config, 0, sizeof(struct user_configuration));
279
[f625817]280struct callback_set {
281
282        fn_cb_starting message_starting;
283        fn_cb_dataless message_stopping;
284        fn_cb_dataless message_resuming;
285        fn_cb_dataless message_pausing;
286        fn_cb_packet message_packet;
287        fn_cb_result message_result;
288        fn_cb_first_packet message_first_packet;
289        fn_cb_tick message_tick_count;
290        fn_cb_tick message_tick_interval;
291        fn_cb_usermessage message_user;
292};
293
[8488c15]294/** A libtrace input trace
[9e2a109]295 * @internal
296 */
297struct libtrace_t {
[8488c15]298        /** The capture format for the input trace */
299        struct libtrace_format_t *format; 
300        /** Details of the most recent PACKET event reported by the trace */
301        struct libtrace_event_status_t event;
302        /** Pointer to the "global" data for the capture format module */       
303        void *format_data;             
304        /** A BPF filter to be applied to all packets read by the trace -
305         * used only if the capture format does not support filters natively */
306        struct libtrace_filter_t *filter; 
307        /** The snap length to be applied to all packets read by the trace -
308         * used only if the capture format does not support snapping natively */
309        size_t snaplen;                 
310        /** Count of the number of packets returned to the libtrace user */
[91e016c]311        uint64_t accepted_packets;
[8488c15]312        /** Count of the number of packets filtered by libtrace */
[91e016c]313        uint64_t filtered_packets;
314        /** The sequence is like accepted_packets but we don't reset this after a pause. */
315        uint64_t sequence_number;
[2fa43fa]316        /** The packet read out by the trace, backwards compatibility to allow us to finalise
317         * a packet when the trace is destroyed */
318        libtrace_packet_t *last_packet;
[8488c15]319        /** The filename from the uri for the trace */
[29bbef0]320        char *uridata;
[8488c15]321        /** The libtrace IO reader for this trace (if applicable) */
[29bbef0]322        io_t *io;
[8488c15]323        /** Error information for the trace */
[29bbef0]324        libtrace_err_t err;
[8488c15]325        /** Boolean flag indicating whether the trace has been started */
[29bbef0]326        bool started;
327        /** Synchronise writes/reads across this format object and attached threads etc */
328        pthread_mutex_t libtrace_lock;
[fac8c46]329        /** State */
330        enum trace_state state;
[29bbef0]331        /** Use to control pausing threads and finishing threads etc always used with libtrace_lock */
332        pthread_cond_t perpkt_cond;
[91e016c]333        /** Keeps track of counts of threads in any given state */
[3296252]334        int perpkt_thread_states[THREAD_STATE_MAX]; 
[fac8c46]335
[17a3dff]336        /** Set to indicate a perpkt's queue is full as such the writing perpkt cannot proceed */
337        bool perpkt_queue_full;
[29bbef0]338        /** Global storage for this trace, shared among all the threads  */
339        void* global_blob;
340        /** The actual freelist */
[a49a9eb]341        libtrace_ocache_t packet_freelist;
[29bbef0]342        /** The hasher function */
343        enum hasher_types hasher_type;
344        /** The hasher function - NULL implies they don't care or balance */
[10c47a0]345        fn_hasher hasher;
[29bbef0]346        void *hasher_data;
[858ce90]347        /** The pread_packet choosen path for the configuration */
348        int (*pread)(libtrace_t *, libtrace_thread_t *, libtrace_packet_t **, size_t);
349
[29bbef0]350        libtrace_thread_t hasher_thread;
[f051c1b]351        libtrace_thread_t reporter_thread;
[82facc5]352        libtrace_thread_t keepalive_thread;
[17a3dff]353        int perpkt_thread_count;
354        libtrace_thread_t * perpkt_threads; // All our perpkt threads
[29bbef0]355        // Used to keep track of the first packet seen on each thread
356        struct first_packets first_packets;
357        int tracetime;
[be3f75b]358
359        /*
360         * Caches statistic counters in the case that our trace is
361         * paused or stopped before this counter is taken
362         */
[5ab626a]363        libtrace_stat_t *stats;
[f051c1b]364        struct user_configuration config;
[2498008]365        libtrace_combine_t combiner;
[f625817]366       
367        /* Set of callbacks to be executed by per packet threads in response
368         * to various messages. */
369        struct callback_set *perpkt_cbs;
370        /* Set of callbacks to be executed by the reporter thread in response
371         * to various messages. */
372        struct callback_set *reporter_cbs;
[9e2a109]373};
[1fc2f6a]374
[5ab626a]375#define LIBTRACE_STAT_MAGIC 0x41
376
[82facc5]377void trace_fin_packet(libtrace_packet_t *packet);
[5ba34eb]378void libtrace_zero_thread(libtrace_thread_t * t);
379void store_first_packet(libtrace_t *libtrace, libtrace_packet_t *packet, libtrace_thread_t *t);
[17a3dff]380libtrace_thread_t * get_thread_table(libtrace_t *libtrace);
381
[29bbef0]382
[f625817]383void send_message(libtrace_t *trace, libtrace_thread_t *target,
384                const enum libtrace_messages type,
385                libtrace_generic_t data, libtrace_thread_t *sender);
386
[8488c15]387/** A libtrace output trace
[2e223eca]388 * @internal
389 */
[9e2a109]390struct libtrace_out_t {
[8488c15]391        /** The capture format for the output trace */
[29bbef0]392        struct libtrace_format_t *format;
[8488c15]393        /** Pointer to the "global" data for the capture format module */
394        void *format_data;             
395        /** The filename for the uri for the output trace */
396        char *uridata;                 
397        /** Error information for the output trace */
398        libtrace_err_t err;
399        /** Boolean flag indicating whether the trace has been started */
[29bbef0]400        bool started;
[1fc2f6a]401};
402
[8488c15]403/** Sets the error status on an input trace
404 *
405 * @param trace         The input trace to set the error status for
406 * @param errcode       The code for the error - can be a libtrace error code or a regular errno value
407 * @param msg           A message to print when reporting the error
408 */
[e1868fb]409void trace_set_err(libtrace_t *trace, int errcode,const char *msg,...) 
[8488c15]410
[e1868fb]411                                                                PRINTF(3,4);
[8488c15]412/** Sets the error status on an output trace
413 *
414 * @param trace         The output trace to set the error status for
415 * @param errcode       The code for the error - can be a libtrace error code or a regular errno value
416 * @param msg           A message to print when reporting the error
417 */
[e1868fb]418void trace_set_err_out(libtrace_out_t *trace, int errcode, const char *msg,...)
419                                                                PRINTF(3,4);
[1fc2f6a]420
[9cc1266]421/** Clears the cached values for a libtrace packet
422 *
423 * @param packet        The libtrace packet that requires a cache reset
424 */
425void trace_clear_cache(libtrace_packet_t *packet);
[f0fb38f]426
[8488c15]427/** Converts the data provided in buffer into a valid libtrace packet
428 *
429 * @param trace         An input trace of the same format as the "packet"
430 *                      contained in the buffer
431 * @param packet        The libtrace packet to prepare
432 * @param buffer        A buffer containing the packet data, including the
433 *                      capture format header
434 * @param rt_type       The RT type for the packet that is being prepared
435 * @param flags         Used to specify options for the preparation function,
436 *                      e.g. who owns the packet buffer
437 *
438 * @return -1 if an error occurs, 0 otherwise
439 *
440 * Packet preparation is a tricky concept - the idea is to take the data
441 * pointed to by 'buffer' and treat it as a packet record of the same capture
442 * format as that used by the input trace. The provided libtrace packet then
443 * has its internal pointers and values set to describe the packet record in
444 * the buffer.
445 *
446 * The primary use of this function is to allow the RT packet reader to
447 * easily and safely convert packets from the RT format back into the format
448 * that they were originally captured with., essentially removing the RT
449 * encapsulation.
450 *
451 * We've decided not to make this function available via the exported API
452 * because there are several issues that can arise if it is not used very
453 * carefully and it is not very useful outside of internal contexts anyway.
[f0fb38f]454 */
455int trace_prepare_packet(libtrace_t *trace, libtrace_packet_t *packet,
456                void *buffer, libtrace_rt_types_t rt_type, uint32_t flags);
457
[8488c15]458/** Flags for prepare_packet functions */
[590fb30]459enum {
[8488c15]460        /** The buffer memory has been allocated by libtrace and should be
461         * freed when the packet is destroyed. */
[590fb30]462        TRACE_PREP_OWN_BUFFER           =1,
[8488c15]463       
464        /** The buffer memory is externally-owned and must not be freed by
465         * libtrace when the packet is destroyed. */
[590fb30]466        TRACE_PREP_DO_NOT_OWN_BUFFER    =0
467};
468
[1c1e4a2]469
[4dedc28]470#ifndef PF_RULESET_NAME_SIZE
471#define PF_RULESET_NAME_SIZE 16
472#endif
473
474#ifndef IFNAMSIZ
475#define IFNAMSIZ 16
476#endif
477
[8488c15]478
479/** A local definition of a PFLOG header */
[67a14d4]480typedef struct libtrace_pflog_header_t {
[8488c15]481        uint8_t    length;     
[4dedc28]482        sa_family_t   af;
483        uint8_t    action;
484        uint8_t    reason;
485        char       ifname[IFNAMSIZ];
486        char       ruleset[PF_RULESET_NAME_SIZE];
487        uint32_t   rulenr;
488        uint32_t   subrulenr;
489        uint8_t    dir;
490        uint8_t    pad[3];
[25024fd]491} PACKED libtrace_pflog_header_t;
[4dedc28]492
[8488c15]493/** A libtrace capture format module */
494/* All functions should return -1, or NULL on failure */
[9e2a109]495struct libtrace_format_t {
[8488c15]496        /** The name of this module, used in the libtrace URI to identify the
497         * capture format */
[4746c71]498        const char *name;
[8488c15]499        /** The version of this module */
[4746c71]500        const char *version;
[8488c15]501        /** The RT protocol type of this module */
[6dbc47a]502        enum base_format_t type;
[3c26e2a]503
504
[8488c15]505        /** Given a filename, return if this is the most likely capture format
[5ab626a]506         * (used for devices). Used to "guess" the capture format when the
[8488c15]507         * URI is not fully specified.
508         *
509         * @param fname         The name of the device or file to examine
510         * @return 1 if the name matches the capture format, 0 otherwise
[5ab626a]511         */
[91b72d3]512        int (*probe_filename)(const char *fname);
[8488c15]513       
514        /** Given a file, looks at the start of the file to determine if this
515         * is the capture format. Used to "guess" the capture format when the
516         * URI is not fully specified.
517         *
518         * @param io            An open libtrace IO reader for the file to check
519         * @return 1 if the file matches the capture format, 0 otherwise
520         */
[91b72d3]521        int (*probe_magic)(io_t *io);
[8488c15]522
523        /** Initialises an input trace using the capture format.
524         *
525         * @param libtrace      The input trace to be initialised
526         * @return 0 if successful, -1 in the event of error
527         */
[1fbd938]528        int (*init_input)(libtrace_t *libtrace);
[8488c15]529       
530        /** Applies a configuration option to an input trace.
531         *
532         * @param libtrace      The input trace to apply the option to
533         * @param option        The option that is being configured
534         * @param value         A pointer to the value that the option is to be
535         *                      set to
536         * @return 0 if successful, -1 if the option is unsupported or an error
537         * occurs
538         */
[1fbd938]539        int (*config_input)(libtrace_t *libtrace,trace_option_t option,void *value);
[8488c15]540        /** Starts or unpauses an input trace - note that this function is
541         * often the one that opens the file or device for reading.
542         *
543         * @param libtrace      The input trace to be started or unpaused
544         * @return 0 if successful, -1 in the event of error */
[1fbd938]545        int (*start_input)(libtrace_t *libtrace);
[8488c15]546
547        /** Pauses an input trace - this function should close or detach the
548         * file or device that is being read from.
549         *
550         * @param libtrace      The input trace to be paused
551         * @return 0 if successful, -1 in the event of error
552         */
[1fbd938]553        int (*pause_input)(libtrace_t *libtrace);
[8488c15]554
555        /** Initialises an output trace using the capture format.
556         *
557         * @param libtrace      The output trace to be initialised
558         * @return 0 if successful, -1 in the event of error
559         */
[1fbd938]560        int (*init_output)(libtrace_out_t *libtrace);
[8488c15]561       
562        /** Applies a configuration option to an output trace.
563         *
564         * @param libtrace      The output trace to apply the option to
565         * @param option        The option that is being configured
566         * @param value         A pointer to the value that the option is to be
567         *                      set to
568         * @return 0 if successful, -1 if the option is unsupported or an error
569         * occurs
570         * */
571        int (*config_output)(libtrace_out_t *libtrace, trace_option_output_t option, void *value);
572
573        /** Starts an output trace - note that this function is often the one
574         * that opens the file or device for writing.
575         *
576         * @param libtrace      The output trace to be started
577         * @return 0 if successful, -1 if an error occurs
578         *
579         * There is no pause for output traces, as writing is not performed
580         * asynchronously.
[9de8150]581         */
[1fbd938]582        int (*start_output)(libtrace_out_t *libtrace);
[8488c15]583
584        /** Concludes an input trace and cleans up the capture format data.
585         *
586         * @param libtrace      The input trace to be concluded
587         * @return 0 if successful, -1 if an error occurs
588         *
589         * Libtrace will call the pause_input function if the input trace is
590         * currently active prior to calling this function.
[ab4cb04]591         */
[1fbd938]592        int (*fin_input)(libtrace_t *libtrace);
[8488c15]593
594        /** Concludes an output trace and cleans up the capture format data.
595         *
596         * @param libtrace      The output trace to be concluded
597         * @return 0 if successful, -1 if an error occurs
598         */
[1fbd938]599        int (*fin_output)(libtrace_out_t *libtrace);
[8488c15]600
601        /** Reads the next packet from an input trace into the provided packet
602         * structure.
603         *
604         * @param libtrace      The input trace to read from
605         * @param packet        The libtrace packet to read into
606         * @return The size of the packet read (in bytes) including the capture
607         * framing header, or -1 if an error occurs. 0 is returned in the
608         * event of an EOF.
609         *
610         * If no packets are available for reading, this function should block
611         * until one appears or return 0 if the end of a trace file has been
612         * reached.
[9de8150]613         */
[97e39a7]614        int (*read_packet)(libtrace_t *libtrace, libtrace_packet_t *packet);
[8488c15]615       
616        /** Converts a buffer containing a packet record into a libtrace packet
617         *
618         * @param libtrace      An input trace in the capture format for the
619         *                      packet
620         * @param packet        A libtrace packet to put the prepared packet
621         *                      into
622         * @param buffer        The buffer containing the packet record
623         *                      (including the capture format header)
624         * @param rt_type       The RT type for the packet
625         * @param flags         Flags describing properties that should be
626         *                      applied to the new packet
627         * @return 0 if successful, -1 if an error occurs.
628         *
629         * Updates internal trace and packet details, such as payload pointers,
630         * loss counters and packet types to match the packet record provided
631         * in the buffer. This is a zero-copy function.
632         *
[f0fb38f]633         * Intended (at this stage) only for internal use, particularly by
634         * RT which needs to decapsulate RT packets */
635        int (*prepare_packet)(libtrace_t *libtrace, libtrace_packet_t *packet,
636                        void *buffer, libtrace_rt_types_t rt_type, 
637                        uint32_t flags);
[8488c15]638       
639        /** Frees any resources allocated by the capture format module for a
640         * libtrace packet.
641         *
642         * @param The packet to be finalised
643         *       */
[eeab9832]644        void (*fin_packet)(libtrace_packet_t *packet);
[8488c15]645
646        /** Write a libtrace packet to an output trace.
647         *
648         * @param libtrace      The output trace to write the packet to
649         * @param packet        The packet to be written out
650         * @return The number of bytes written, or -1 if an error occurs
[9de8150]651         */
[3a169d7]652        int (*write_packet)(libtrace_out_t *libtrace, libtrace_packet_t *packet);
[8488c15]653        /** Returns the libtrace link type for a packet.
654         *
655         * @param packet        The packet to get the link type for
656         * @return The libtrace link type, or -1 if this link type is unknown
[9de8150]657         */ 
[1fbd938]658        libtrace_linktype_t (*get_link_type)(const libtrace_packet_t *packet);
[8488c15]659
660        /** Returns the direction of a packet.
661         *
662         * @param packet        The packet to get the direction for
663         * @return The direction of the packet, or -1 if no direction tag is
664         * present or an error occurs
[9de8150]665         */ 
[431548c5]666        libtrace_direction_t (*get_direction)(const libtrace_packet_t *packet);
[8488c15]667       
668        /** Sets the direction of a packet.
669         *
670         * @param packet        The packet to set the direction for
671         * @param direction     The direction to assign to the packet
672         * @return The updated direction for the packet, or -1 if an error
673         * occurs
674         *
675         * @note Some capture formats do not feature direction tagging, so it
676         * will not make sense to implement a set_direction function for them.
[9de8150]677         */ 
[431548c5]678        libtrace_direction_t (*set_direction)(libtrace_packet_t *packet, libtrace_direction_t direction);
[8488c15]679       
680        /** Returns the timestamp for a packet in the ERF timestamp format.
681         *
682         * @param packet        The packet to get the timestamp from
683         * @return The 64-bit ERF timestamp
684         *
685         * @note Each format must implement at least one of the four "get
686         * timestamp" functions.
687         *
688         * If not implemented, libtrace will convert the result of one of the
689         * other timestamp functions into the appropriate format instead.
690         * This means each capture format only needs to implement the most
691         * sensible of the four and let libtrace handle any conversions.
692         *
[9de8150]693         */
[1fbd938]694        uint64_t (*get_erf_timestamp)(const libtrace_packet_t *packet);
[8488c15]695
696        /** Returns the timestamp for a packet in the timeval format
697         *
698         * @param packet        The packet to get the timestamp from
699         * @return The timestamp from the packet as a timeval
700         *
701         * @note Each format must implement at least one of the four "get
702         * timestamp" functions.
703         *
704         * If not implemented, libtrace will convert the result of one of the
705         * other timestamp functions into the appropriate format instead.
706         * This means each capture format only needs to implement the most
707         * sensible of the four and let libtrace handle any conversions.
[9de8150]708         */
[1fbd938]709        struct timeval (*get_timeval)(const libtrace_packet_t *packet);
[8488c15]710       
711        /** Returns the timestamp for a packet in the timespec format.
712         *
713         * @param packet        The packet to get the timestamp from
714         * @return The timestamp from the packet as a timespec
715         *
716         * @note Each format must implement at least one of the four "get
717         * timestamp" functions.
718         *
719         * If not implemented, libtrace will convert the result of one of the
720         * other timestamp functions into the appropriate format instead.
721         * This means each capture format only needs to implement the most
722         * sensible of the four and let libtrace handle any conversions.
[1aa4bf7]723         */
724        struct timespec (*get_timespec)(const libtrace_packet_t *packet);
[8488c15]725       
726        /** Returns the timestamp for a packet in floating point seconds.
727         *
728         * @param packet        The packet to get the timestamp from
729         * @return The timestamp from the packet as a floating point number of
730         * seconds since 1970-01-01 00:00:00 UTC
731         *
732         * @note Each format must implement at least one of the four "get
733         * timestamp" functions.
734         *
735         * If not implemented, libtrace will convert the result of one of the
736         * other timestamp functions into the appropriate format instead.
737         * This means each capture format only needs to implement the most
738         * sensible of the four and let libtrace handle any conversions.
[9de8150]739         */
[1fbd938]740        double (*get_seconds)(const libtrace_packet_t *packet);
[8488c15]741       
742        /** Moves the read pointer to a certain ERF timestamp within an input
743         * trace file.
744         *
745         * @param trace         The input trace to seek within
746         * @param timestamp     The timestamp to seek to, as an ERF timestamp
747         *
[9de8150]748         * @return 0 on success, -1 on failure.
[8488c15]749         *
750         * The next packet read from this trace will now be the first packet
751         * to have a timestamp equal to or greater than the provided timestamp.
752         *
753         * @note Each format that supports seeking must implement at least one
754         * of the seek functions.
755         *
756         * If not implemented, libtrace will convert the timestamp into the
757         * appropriate format to use a seek function that has been implemented.
758         * This means each capture format only needs to implement the seek
759         * function that matches the native timestamp format for that capture.
760         *
[9de8150]761         */
[1fbd938]762        int (*seek_erf)(libtrace_t *trace, uint64_t timestamp);
[8488c15]763        /** Moves the read pointer to a certain timestamp represented using a
764         * timeval within an input trace file.
765         *
766         * @param trace         The input trace to seek within
767         * @param timestamp     The timestamp to seek to, as a timeval
768         *
[9de8150]769         * @return 0 on success, -1 on failure.
[8488c15]770         *
771         * The next packet read from this trace will now be the first packet
772         * to have a timestamp equal to or greater than the provided timestamp.
773         *
774         * @note Each format that supports seeking must implement at least one
775         * of the seek functions.
776         *
777         * If not implemented, libtrace will convert the timestamp into the
778         * appropriate format to use a seek function that has been implemented.
779         * This means each capture format only needs to implement the seek
780         * function that matches the native timestamp format for that capture.
781         *
[9de8150]782         */
[1fbd938]783        int (*seek_timeval)(libtrace_t *trace, struct timeval tv);
[8488c15]784       
785        /** Moves the read pointer to a certain timestamp represented using
786         * floating point seconds within an input trace file.
787         *
788         * @param trace         The input trace to seek within
789         * @param timestamp     The timestamp to seek to, as floating point
790         *                      seconds since 1970-01-01 00:00:00 UTC
791         *
[9de8150]792         * @return 0 on success, -1 on failure.
[8488c15]793         *
794         * The next packet read from this trace will now be the first packet
795         * to have a timestamp equal to or greater than the provided timestamp.
796         *
797         * @note Each format that supports seeking must implement at least one
798         * of the seek functions.
799         *
800         * If not implemented, libtrace will convert the timestamp into the
801         * appropriate format to use a seek function that has been implemented.
802         * This means each capture format only needs to implement the seek
803         * function that matches the native timestamp format for that capture.
804         *
[9de8150]805         */
[1fbd938]806        int (*seek_seconds)(libtrace_t *trace, double seconds);
[8488c15]807       
808        /** Returns the payload length of the captured packet record.
809         *
810         * @param packet        The packet to get the capture length from
811         * @return The capture length for the packet, or -1 if an error occurs
812         *
813         * Capture length is the current size of the packet record itself,
814         * following any truncation that may have occurred during the capture
815         * process. This length does not include the capture format framing
816         * header.
[9de8150]817         */
[1fbd938]818        int (*get_capture_length)(const libtrace_packet_t *packet);
[8488c15]819
820        /** Returns the original length of the packet as it was on the wire.
821         *
822         * @param packet        The packet to get the wire length from
823         * @return The length of the packet on the wire at the time of capture,
824         * or -1 if an error occurs
825         *
826         * Wire length is the original size of the packet prior to any
827         * truncation that may have occurred as part of the capture process.
828         * This length does not include the capture format framing header.
[9de8150]829         */
[1fbd938]830        int (*get_wire_length)(const libtrace_packet_t *packet);
[8488c15]831       
832        /** Returns the length of the capture format framing header
833         *
834         * @param packet        The packet to get the framing length from
835         * @return The length of the framing header, or -1 if an error occurs
836         *
837         * The framing header is the extra metadata that the capture process
838         * records about a packet.  The framing length does not include any
839         * of the packet payload itself. The total size of the packet record
840         * can be calculated be adding this value with the capture length.
[9de8150]841         */
[1fbd938]842        int (*get_framing_length)(const libtrace_packet_t *packet);
[8488c15]843
844        /** Sets the capture length for a packet.
845         *
846         * @param packet        The packet to adjust the capture length for.
847         * @param size          The new capture length
848         * @return The new capture length of the packet, or -1 if an error
849         * occurs
850         *
851         * @note This function should only reduce the capture length. If the
852         * provided length is larger than the current capture length, -1 should
853         * be returned.
[9de8150]854         */
[c95b923]855        size_t (*set_capture_length)(struct libtrace_packet_t *packet,size_t size);
[8488c15]856        /** Returns the number of packets observed by an input trace.
857         *
858         * @param trace         The input trace to get the packet count for
859         * @return The number of packets observed by an input trace, or
860         * UINT64_MAX if the number is unknown
861         *
862         * This count includes packets that have been filtered and dropped.
[f2fae49]863         */
[50bbce8]864        uint64_t (*get_received_packets)(libtrace_t *trace);
[8488c15]865
866        /** Returns the number of packets filtered by an input trace.
867         *
868         * @param trace         The input trace to get the filtered count for
869         * @return The number of packets filtered by the input trace, or
870         * UINT64_MAX if the number is unknown
871         *
[f2fae49]872         */
[50bbce8]873        uint64_t (*get_filtered_packets)(libtrace_t *trace);
[8488c15]874       
875        /** Returns the number of packets dropped by an input trace.
876         *
877         * @param trace         The input trace to get the dropped count for
878         * @return The number of packets dropped by the input trace, or
879         * UINT64_MAX if the number is unknown
880         *
881         */
[50bbce8]882        uint64_t (*get_dropped_packets)(libtrace_t *trace);
[5ab626a]883
[526d9d0]884        /** Returns statistics about a trace.
[8488c15]885         *
[5ab626a]886         * @param trace The libtrace object
[526d9d0]887         * @param stat [in,out] A statistics structure ready to be filled
888         *
889         * The filtered and accepted statistics will be set to the values
890         * stored in the library. All other statistics are not set.
891         *
892         * @note If filtering of packets is performed by a trace and the number
893         * of filtered packets is unknown this should be marked as invalid by
894         * the format.
[f2fae49]895         */
[5ab626a]896        void (*get_statistics)(libtrace_t *trace, libtrace_stat_t *stat);
[8488c15]897       
898        /** Returns the file descriptor used by the input trace.
899         *
900         * @param trace         The input trace to get the file descriptor for
901         * @return The file descriptor used by the input trace to read packets
902         *
[9de8150]903         */
[52f8fc2]904        int (*get_fd)(const libtrace_t *trace);
[8488c15]905       
906        /** Returns the next libtrace event for the input trace.
907         *
908         * @param trace         The input trace to get the next event from
909         * @param packet        A libtrace packet to read a packet into
910         * @return A libtrace event describing the event that occured
911         *
912         * The event API allows for non-blocking reading of packets from an
913         * input trace. If a packet is available and ready to be read, a packet
914         * event should be returned. Otherwise a sleep or fd event should be
915         * returned to indicate that the caller needs to wait. If the input
916         * trace has an error or reaches EOF, a terminate event should be
917         * returned.
[9de8150]918         */
[1fbd938]919        struct libtrace_eventobj_t (*trace_event)(libtrace_t *trace, libtrace_packet_t *packet);       
[8488c15]920
921        /** Prints some useful help information to standard output. */
[33d83d4]922        void (*help)(void);
[29bbef0]923       
[b13b939]924        /** Next pointer, should always be NULL - used by the format module
925         * manager. */
926        struct libtrace_format_t *next;
927
928        /** Holds information about the trace format */
929        struct libtrace_info_t info;
930
[04bf7c5]931        /**
932         * Starts or unpauses an input trace in parallel mode - note that
[29bbef0]933         * this function is often the one that opens the file or device for
934         * reading.
935         *
936         * @param libtrace      The input trace to be started or unpaused
[04bf7c5]937         * @return 0 upon success.
938         *         Otherwise in event of an error -1 is returned.
[29bbef0]939         *
940         */
941        int (*pstart_input)(libtrace_t *trace);
942       
[d7fd648]943        /**
944         * Read a batch of packets from the input stream related to thread.
945         * At most read nb_packets, however should return with less if packets
946         * are not waiting. However still must return at least 1, 0 still indicates
947         * EOF.
948         *
949         * @param libtrace      The input trace
950         * @param t     The thread
951         * @param packets       An array of packets
952         * @param nb_packets    The number of packets in the array (the maximum to read)
953         * @return The number of packets read, or 0 in the case of EOF or -1 in error or -2 to represent
954         * interrupted due to message waiting before packets had been read.
955         */
956        int (*pread_packets)(libtrace_t *trace, libtrace_thread_t *t, libtrace_packet_t **packets, size_t nb_packets);
[29bbef0]957       
[b13b939]958        /** Pause a parallel trace
959         *
960         * @param libtrace      The input trace to be paused
961         */
[29bbef0]962        int (*ppause_input)(libtrace_t *trace);
963       
[b13b939]964        /** Called after all threads have been paused, Finish (close) a parallel trace
[d7fd648]965         *
[b13b939]966         * @param libtrace      The input trace to be stopped
967         */
[29bbef0]968        int (*pfin_input)(libtrace_t *trace);
[50ce607]969
970        /**
971         * Register a thread for use with the format or using the packets produced
[12ae766]972         * by it. This is NOT only used for threads reading packets in fact all
[50ce607]973         * threads use this.
974         *
[12ae766]975         * The libtrace lock is not held by this format but can be aquired
976         * by the format.
977         *
[50ce607]978         * Some use cases include setting up any thread local storage required for
979         * to read packets and free packets. For DPDK we require any thread that
980         * may release or read a packet to have have an internal number associated
981         * with it.
982         *
983         * The thread type can be used to see if this thread is going to be used
984         * to read packets or otherwise.
985         *
986         * @return 0 if successful, -1 if the option is unsupported or an error
987         * occurs (such as a maximum of threads being reached)
988         */
989        int (*pregister_thread)(libtrace_t *libtrace, libtrace_thread_t *t, bool reader);
990
991        /**
992         * If needed any memory allocated with pregister_thread can be released
993         * in this function. The thread will be destroyed directly after this
994         * function is called.
995         */
996        void (*punregister_thread)(libtrace_t *libtrace, libtrace_thread_t *t);
[5ab626a]997
[526d9d0]998        /** Returns statistics for a single thread.
999         *
1000         * @param trace The libtrace object
1001         * @param t The thread to return statistics for
1002         * @param stat [in,out] A statistics structure ready to be filled
1003         *
1004         * The filtered and accepted statistics will be set to the values
1005         * stored in the library. All other statistics are not set.
1006         *
1007         * @note If filtering of packets is performed by a trace and the number
1008         * of filtered packets is unknown this should be marked as invalid by
1009         * the format.
[5ab626a]1010         */
1011        void (*get_thread_statistics)(libtrace_t *libtrace,
1012                                      libtrace_thread_t *t,
1013                                      libtrace_stat_t *stat);
[4dedc28]1014};
1015
[b13b939]1016/** Macro to zero out a single thread format */
1017#define NON_PARALLEL(live) \
[5ab626a]1018        {live, 1},              /* trace info */ \
1019        NULL,                   /* pstart_input */ \
1020        NULL,                   /* pread_packet */ \
1021        NULL,                   /* ppause_input */ \
1022        NULL,                   /* pfin_input */ \
1023        NULL,                   /* pregister_thread */ \
1024        NULL,                   /* punregister_thread */ \
1025        NULL,                   /* get_thread_statistics */
[b13b939]1026
[8488c15]1027/** The list of registered capture formats */
[c0506ea]1028//extern struct libtrace_format_t *form;
1029
1030/** Specifies whether any blocking packet readers should cease reading
1031 * immediately
1032 */
[d7fd648]1033extern volatile int libtrace_halt;
[4dedc28]1034
[8488c15]1035/** Registers a new capture format module.
1036 *
1037 * @param format        The format module to be registered
1038 */
[9e2a109]1039void register_format(struct libtrace_format_t *format);
[7068467]1040
[1101175]1041/** Converts a timeval into a timestamp in microseconds since the epoch.
1042 *
1043 * @param tv    The timeval to be converted.
1044 * @return A 64 bit timestamp in microseconds since the epoch.
1045 */
1046uint64_t tv_to_usec(const struct timeval *tv);
1047
[8488c15]1048/** Converts a PCAP DLT into a libtrace link type.
1049 *
1050 * @param linktype      The PCAP DLT to be converted
1051 * @return The libtrace link type that is equivalent to the provided DLT, or
1052 * -1 if the DLT is unknown
1053 */
[4c00a35]1054libtrace_linktype_t pcap_linktype_to_libtrace(libtrace_dlt_t linktype);
[8488c15]1055
1056/** Converts a PCAP DLT into an RT protocol type.
1057 *
1058 * @param linktype      The PCAP DLT to be converted
1059 * @return The RT type that is equivalent to the provided DLT
1060 */
[ce0bf2c]1061libtrace_rt_types_t pcap_linktype_to_rt(libtrace_dlt_t linktype);
[8488c15]1062
1063/** Converts a libtrace link type into a PCAP linktype.
1064 *
1065 * @param type          The libtrace link type to be converted
1066 * @return The PCAP linktype that is equivalent to the provided libtrace link
1067 * type, or -1 if the link type is unknown
1068 */
[4c00a35]1069libtrace_dlt_t libtrace_to_pcap_linktype(libtrace_linktype_t type);
[8488c15]1070
1071/** Converts a libtrace link type into a PCAP DLT.
1072 *
1073 * @param type          The libtrace link type to be converted
1074 * @return The PCAP DLT that is equivalent to the provided libtrace link
1075 * type, or -1 if the link type is unknown
1076 */
[4c00a35]1077libtrace_dlt_t libtrace_to_pcap_dlt(libtrace_linktype_t type);
[8488c15]1078
1079/** Converts an RT protocol type into a PCAP DLT.
1080 *
1081 * @param rt_type       The RT type to be converted
1082 * @return The PCAP DLT that is equivalent to the provided RT protocol
1083 */
[4c00a35]1084libtrace_dlt_t rt_to_pcap_linktype(libtrace_rt_types_t rt_type);
[8488c15]1085
[f00c146]1086/** Converts a PCAP DLT into an RT protocol type for the BPF format.
1087 *
1088 * @param linktype      The PCAP DLT to be converted
1089 * @return The RT type that is equivalent to the provided DLT for BPF
1090 */
1091libtrace_rt_types_t bpf_linktype_to_rt(libtrace_dlt_t linktype);
1092
[8488c15]1093/** Converts an ERF type into a libtrace link type.
1094 *
1095 * @param erf           The ERF type to be converted
1096 * @return The libtrace link type that is equivalent to the provided ERF type,
1097 * or -1 if the ERF type is unknown
1098 */
[4bd8a5b]1099libtrace_linktype_t erf_type_to_libtrace(uint8_t erf);
[8488c15]1100
1101/** Converts a libtrace link type into an ERF type.
1102 *
1103 * @param linktype      The libtrace link type to be converted
1104 * @return The ERF type that is equivalent to the provided libtrace link type,
1105 * or -1 if the link type cannot be matched to an ERF type.
1106 */
[4bd8a5b]1107uint8_t libtrace_to_erf_type(libtrace_linktype_t linktype);
[7068467]1108
[8488c15]1109/** Converts an ARPHRD type into a libtrace link type.
1110 *
1111 * @param arphrd        The ARPHRD type to be converted
1112 * @return The libtrace link type that is equivalent to the provided ARPHRD
1113 * type, or -1 if the ARPHRD type is unknown
1114 */
1115libtrace_linktype_t arphrd_type_to_libtrace(unsigned int arphrd);
1116
1117/** Converts a libtrace link type into an ARPHRD type.
1118 *
1119 * @param type          The libtrace link type to be converted
1120 * @return The ARPHRD type that is equivalent to the provided libtrace link
1121 * type, or -1 if the link type cannot be matched to an ARPHRD type
1122 */
1123unsigned int libtrace_to_arphrd_type(libtrace_linktype_t type);
1124
1125/** Converts a libtrace packet to the Linux SLL type.
1126 *
1127 * @param packet        The packet to be promoted
1128 *
1129 * @note This will involve memcpy() so use sparingly.
1130 *
1131 * This function prepends a Linux SLL header to a packet so that we can store
1132 * direction tagging information.
1133 */
[81f9b6e]1134void promote_packet(libtrace_packet_t *packet);
[8488c15]1135
1136/** Attempts to demote a packet by removing the first header.
1137 *
1138 * @param packet        The packet to be demoted
1139 * @return True if the packet was demoted, false otherwise.
1140 *
1141 * Essentially the opposite of promote_packet, except that it will also remove
1142 * an ATM header as well as Linux SLL.
1143 *
1144 */
[0ff6ddf]1145bool demote_packet(libtrace_packet_t *packet);
[81f9b6e]1146
[8488c15]1147/** Returns a pointer to the header following a Linux SLL header.
1148 *
1149 * @param link          A pointer to the Linux SLL header to be skipped
[9cc1266]1150 * @param[out] arphrd_type      The arp hardware type of the packet
1151 * @param[out] next_header      The ethertype of the next header
[8488c15]1152 * @param[in,out] remaining     Updated with the number of captured bytes
1153 *                              remaining
1154 * @return A pointer to the header following the Linux SLL header, or NULL if
1155 * no subsequent header is present.
1156 *
1157 * Remaining must point to the number of bytes captured from the Linux SLL
1158 * header and beyond.  It will be decremented by the number of bytes skipped
1159 * to find the payload.
1160 *
1161 * If the Linux SLL header is complete but there are zero bytes of payload
1162 * after the end of the header, a pointer to where the payload would be is
1163 * returned and remaining will be set to zero. If the Linux SLL header is
1164 * incomplete (truncated), then NULL is returned and remaining will be set to
1165 * 0. Therefore, it is very important to check the value of remaining after
1166 * calling this function.
1167 */     
[9cc1266]1168void *trace_get_payload_from_linux_sll(const void *link,
1169                uint16_t *arphrd_type, 
1170                uint16_t *next_header, 
[8488c15]1171                uint32_t *remaining);
1172
1173/** Returns a pointer to the header following an ATM header.
1174 *
1175 * @param link          A pointer to the ATM header to be skipped
1176 * @param[out] type     The ethertype of the next header
1177 * @param[in,out] remaining     Updated with the number of captured bytes
1178 *                              remaining
1179 * @return A pointer to the header following the ATM header, or NULL if
1180 * no subsequent header is present.
1181 *
1182 * Remaining must point to the number of bytes captured from the ATM header
1183 * and beyond.  It will be decremented by the number of bytes skipped to find
1184 * the payload.
1185 *
1186 * If the ATM header is complete but there are zero bytes of payload
1187 * after the end of the header, a pointer to where the payload would be is
1188 * returned and remaining will be set to zero. If the ATM header is
1189 * incomplete (truncated), then NULL is returned and remaining will be set to
1190 * 0. Therefore, it is very important to check the value of remaining after
1191 * calling this function.
1192 */     
1193DLLEXPORT void *trace_get_payload_from_atm(void *link, uint8_t *type, 
1194                uint32_t *remaining);
[94af885]1195
1196
[e5c2bc4]1197#ifdef HAVE_BPF
[df338b3]1198/* A type encapsulating a bpf filter
1199 * This type covers the compiled bpf filter, as well as the original filter
1200 * string
1201 *
1202 */
[8488c15]1203
1204/** Internal representation of a BPF filter */
[df338b3]1205struct libtrace_filter_t {
[8488c15]1206        struct bpf_program filter;      /**< The BPF program itself */
1207        char * filterstring;            /**< The filter string */
1208        int flag;                       /**< Indicates if the filter is valid */
[31a15db]1209        struct bpf_jit_t *jitfilter;
[df338b3]1210};
[e5c2bc4]1211#else
[8488c15]1212/** BPF not supported by this system, but we still need to define a structure
1213 * for the filter */
[e5c2bc4]1214struct libtrace_filter_t {};
[df338b3]1215#endif
[45dfddc]1216
[8488c15]1217/** Local definition of a PCAP header */
[45dfddc]1218typedef struct libtrace_pcapfile_pkt_hdr_t {
[8488c15]1219        uint32_t ts_sec;        /* Seconds portion of the timestamp */
1220        uint32_t ts_usec;       /* Microseconds portion of the timestamp */
1221        uint32_t caplen;        /* Capture length of the packet */
1222        uint32_t wirelen;       /* The wire length of the packet */
[45dfddc]1223} libtrace_pcapfile_pkt_hdr_t;
1224
[5d56d34]1225#ifdef HAVE_DAG
[8488c15]1226/** Constructor for the DAG format module */
[5d56d34]1227void dag_constructor(void);
1228#endif
[8488c15]1229/** Constructor for the ERF format module */
[cab58c5]1230void erf_constructor(void);
[8488c15]1231/** Constructor for the TSH format module */
[e01a738]1232void tsh_constructor(void);
[8488c15]1233/** Constructor for the Legacy DAG format module */
[cab58c5]1234void legacy_constructor(void);
[8488c15]1235/** Constructor for the Linux Native format module */
[cab58c5]1236void linuxnative_constructor(void);
[6cf3ca0]1237/** Constructor for the Linux Ring format module */
1238void linuxring_constructor(void);
[8488c15]1239/** Constructor for the PCAP format module */
[cab58c5]1240void pcap_constructor(void);
[8488c15]1241/** Constructor for the PCAP File format module */
[cab58c5]1242void pcapfile_constructor(void);
[8488c15]1243/** Constructor for the RT format module */
[cab58c5]1244void rt_constructor(void);
[8488c15]1245/** Constructor for the DUCK format module */
[cab58c5]1246void duck_constructor(void);
[8488c15]1247/** Constructor for the ATM Header format module */
[e1fdc05]1248void atmhdr_constructor(void);
[3512119]1249#ifdef HAVE_BPF
[8488c15]1250/** Constructor for the BPF format module */
[3512119]1251void bpf_constructor(void);
1252#endif
[c04929c]1253#if HAVE_DPDK
1254/** Constructor for Intels DPDK format module */
1255void dpdk_constructor(void);
1256#endif
[cab58c5]1257
[8488c15]1258/** Extracts the RadioTap flags from a wireless link header
1259 *
1260 * @param link          A pointer to the wireless link header
1261 * @param linktype      The link type of the wireless header
1262 * @param[out] flags    Space to store the extracted flags
1263 * @return True if libtrace was able to extract flags from the link header,
1264 * false otherwise.
1265 *
1266 * This function has been left internal because it is not portable across
1267 * drivers.
1268 */
[f0c639b]1269bool trace_get_wireless_flags(void *link, libtrace_linktype_t linktype, uint8_t *flags);
1270#define TRACE_RADIOTAP_F_FCS 0x10
[4dedc28]1271       
1272#ifdef __cplusplus
1273}
1274#endif
1275
[7068467]1276#endif /* LIBTRACE_INT_H */
Note: See TracBrowser for help on using the repository browser.