WAND Trace processing  4.0.5
libtrace_int.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 2007-2016 The University of Waikato, Hamilton, New Zealand.
4  * All rights reserved.
5  *
6  * This file is part of libtrace.
7  *
8  * This code has been developed by the University of Waikato WAND
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
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
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
19  * GNU Lesser General Public License for more details.
20  *
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/>.
23  *
24  *
25  */
42 #ifndef LIBTRACE_INT_H
43 #define LIBTRACE_INT_H
44 
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48 
49 #include "config.h"
50 #include "common.h"
51 #include "libtrace_parallel.h"
52 #include "wandio.h"
53 #include "lt_bswap.h"
54 
55 #ifdef _MSC_VER
56 // warning: deprecated function
57 #pragma warning(disable:4996)
58 // warning: benign redefinitions of types
59 #pragma warning(disable:4142)
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 
77 #include "rt_protocol.h"
78 
79 /* Prefer net/bpf.h over pcap-bpf.h for format_bpf.c on MacOS */
80 #ifdef HAVE_NET_BPF_H
81 # include <net/bpf.h>
82 # define HAVE_BPF 1
83 #else
84 #ifdef HAVE_PCAP_BPF_H
85 # include <pcap-bpf.h>
86 # define HAVE_BPF 1
87 #endif
88 #endif
89 
90 #ifdef HAVE_PCAP_H
91 # include <pcap.h>
92 # ifdef HAVE_PCAP_INT_H
93 # include <pcap-int.h>
94 # endif
95 #endif
96 
97 #ifdef HAVE_ZLIB_H
98 # include <zlib.h>
99 #endif
100 
101 #if !HAVE_DECL_STRNDUP
102 char *strndup(const char *s, size_t size);
103 #endif
104 
105 #if !HAVE_DECL_STRNCASECMP
106 # ifndef HAVE__STRNICMP
107 
108 int strncasecmp(const char *str1, const char *str2, size_t n);
109 # else
110 # define strncasecmp _strnicmp
111 # endif
112 #endif
113 
114 #if !HAVE_DECL_SNPRINTF
115 # ifndef HAVE_SPRINTF_S
116 
117 int snprintf(char *str, size_t size, const char *format, ...);
118 # else
119 # define snprintf sprintf_s
120 # endif
121 #endif
122 
123 #include "daglegacy.h"
124 
125 #ifdef HAVE_DAG_API
126 # include "dagnew.h"
127 # include "dagapi.h"
128 # if DAG_VERSION == 24
129 # include <erftypes.h>
130 # else
131 # include <daginf.h>
132 # endif
133 # include "erftypes.h"
134 #else
135 # include "dagformat.h"
136 #endif
137 
138 #ifdef HAVE_LLVM
139 #include "bpf-jit/bpf-jit.h"
140 #endif
141 
142 #include "data-struct/ring_buffer.h"
143 #include "data-struct/object_cache.h"
144 #include "data-struct/vector.h"
145 #include "data-struct/message_queue.h"
146 #include "data-struct/deque.h"
147 #include "data-struct/linked_list.h"
148 #include "data-struct/sliding_window.h"
149 #include "data-struct/buckets.h"
150 #include "pthread_spinlock.h"
151 
152 //#define RP_BUFSIZE 65536U
153 
154 #define LIBTRACE_MAX_REPLAY_SPEEDUP 1000
155 
160 
161  /* The walltime when we processed the first packet from the trace */
162  double first_now;
163 
164  /* The tracetime of the first packet in the trace */
165  double first_ts;
166 
168  int psize;
171  bool waiting;
172 };
173 
174 enum thread_types {
175  THREAD_EMPTY,
176  THREAD_HASHER,
177  THREAD_PERPKT,
178  THREAD_REPORTER,
179  THREAD_KEEPALIVE
180 };
181 
182 enum thread_states {
183  THREAD_RUNNING,
184  THREAD_FINISHING,
185  THREAD_FINISHED,
186  THREAD_PAUSED,
187  THREAD_STATE_MAX
188 };
189 
190 enum hash_owner {
191  HASH_OWNED_LIBTRACE,
192  HASH_OWNED_EXTERNAL,
193 };
194 
199  uint64_t accepted_packets; // The number of packets accepted only used if pread
200  uint64_t filtered_packets;
201  // is retreving packets
202  // Set to true once the first packet has been stored
203  bool recorded_first;
204  // For thread safety reason we actually must store this here
205  int64_t tracetime_offset_usec;
206  void* user_data; // TLS for the user to use
207  void* format_data; // TLS for the format to use
208  libtrace_message_queue_t messages; // Message handling
209  libtrace_ringbuffer_t rbuffer; // Input
210  libtrace_t * trace;
211  void* ret;
212  enum thread_types type;
213  enum thread_states state;
214  pthread_t tid;
215  int perpkt_num; // A number from 0-X that represents this perpkt threads number
216  // in the table, intended to quickly identify this thread
217  // -1 represents NA (such as the case this is not a perpkt thread)
218 } ALIGN_STRUCT(CACHE_LINE_SIZE);
219 
227  pthread_spinlock_t lock;
228  size_t count; // If == perpkt_thread_count threads we have all
229  size_t first; // Valid if count != 0
230  struct {
231  libtrace_packet_t * packet;
232  struct timeval tv;
233  } * packets;
234 };
235 
236 #define TRACE_STATES \
237  X(STATE_NEW) \
238  X(STATE_RUNNING) \
239  X(STATE_PAUSING) \
240  X(STATE_PAUSED) \
241  X(STATE_FINISHED) \
242  X(STATE_FINISHING) \
243  X(STATE_DESTROYED) \
244  X(STATE_JOINED) \
245  X(STATE_ERROR)
246 
247 #define X(a) a,
248 enum trace_state {
249  TRACE_STATES
250 };
251 #undef X
252 
253 #define X(a) case a: return #a;
254 static inline char *get_trace_state_name(enum trace_state ts){
255  switch(ts) {
256  TRACE_STATES
257  default:
258  return "UNKNOWN";
259  }
260 }
261 #undef X
262 
263 #define READ_EOF 0
264 #define READ_ERROR -1
265 #define READ_MESSAGE -2
266 // Used for inband tick message
267 #define READ_TICK -3
268 
274  size_t cache_size;
275  size_t thread_cache_size;
276  bool fixed_count;
277  size_t burst_size;
278  size_t tick_interval;
279  size_t tick_count;
280  size_t perpkt_threads;
281  size_t hasher_queue_size;
282  bool hasher_polling;
283  bool reporter_polling;
284  size_t reporter_thold;
285  bool debug_state;
286 };
287 #define ZERO_USER_CONFIG(config) memset(&config, 0, sizeof(struct user_configuration));
288 
289 struct callback_set {
290 
291  fn_cb_starting message_starting;
292  fn_cb_dataless message_stopping;
293  fn_cb_dataless message_resuming;
294  fn_cb_dataless message_pausing;
295  fn_cb_packet message_packet;
296  fn_cb_result message_result;
297  fn_cb_first_packet message_first_packet;
298  fn_cb_tick message_tick_count;
299  fn_cb_tick message_tick_interval;
300  fn_cb_usermessage message_user;
301 };
302 
306 struct libtrace_t {
312  void *format_data;
318  size_t snaplen;
327  uint64_t sequence_number;
332  char *uridata;
334  io_t *io;
338  bool started;
342  pthread_mutex_t libtrace_lock;
344  pthread_mutex_t read_packet_lock;
346  enum trace_state state;
348  pthread_cond_t perpkt_cond;
350  int perpkt_thread_states[THREAD_STATE_MAX];
351 
355  void* global_blob;
362  void *hasher_data;
363  enum hash_owner hasher_owner;
366 
367  libtrace_thread_t hasher_thread;
368  libtrace_thread_t reporter_thread;
369  libtrace_thread_t keepalive_thread;
370  int perpkt_thread_count;
371  libtrace_thread_t * perpkt_threads; // All our perpkt threads
372  // Used to keep track of the first packet seen on each thread
374  int tracetime;
375 
376  /*
377  * Caches statistic counters in the case that our trace is
378  * paused or stopped before this counter is taken
379  */
380  libtrace_stat_t *stats;
381  struct user_configuration config;
382  libtrace_combine_t combiner;
383 
384  /* Set of callbacks to be executed by per packet threads in response
385  * to various messages. */
386  struct callback_set *perpkt_cbs;
387  /* Set of callbacks to be executed by the reporter thread in response
388  * to various messages. */
389  struct callback_set *reporter_cbs;
390 };
391 
392 #define LIBTRACE_STAT_MAGIC 0x41
393 
394 void trace_fin_packet(libtrace_packet_t *packet);
395 void libtrace_zero_thread(libtrace_thread_t * t);
397 libtrace_thread_t * get_thread_table(libtrace_t *libtrace);
398 
399 
400 void send_message(libtrace_t *trace, libtrace_thread_t *target,
401  const enum libtrace_messages type,
402  libtrace_generic_t data, libtrace_thread_t *sender);
403 
411  void *format_data;
413  char *uridata;
417  bool started;
418 };
419 
426 void trace_set_err(libtrace_t *trace, int errcode,const char *msg,...)
427 
428  PRINTF(3,4);
435 void trace_set_err_out(libtrace_out_t *trace, int errcode, const char *msg,...)
436  PRINTF(3,4);
437 
443 
444 
445 #ifndef PF_RULESET_NAME_SIZE
446 #define PF_RULESET_NAME_SIZE 16
447 #endif
448 
449 #ifndef IFNAMSIZ
450 #define IFNAMSIZ 16
451 #endif
452 
453 
455 typedef struct libtrace_pflog_header_t {
456  uint8_t length;
457  sa_family_t af;
458  uint8_t action;
459  uint8_t reason;
460  char ifname[IFNAMSIZ];
461  char ruleset[PF_RULESET_NAME_SIZE];
462  uint32_t rulenr;
463  uint32_t subrulenr;
464  uint8_t dir;
465  uint8_t pad[3];
466 } PACKED libtrace_pflog_header_t;
467 
469 /* All functions should return -1, or NULL on failure */
473  const char *name;
475  const char *version;
478 
479 
487  int (*probe_filename)(const char *fname);
488 
496  int (*probe_magic)(io_t *io);
497 
503  int (*init_input)(libtrace_t *libtrace);
504 
514  int (*config_input)(libtrace_t *libtrace,trace_option_t option,void *value);
520  int (*start_input)(libtrace_t *libtrace);
521 
528  int (*pause_input)(libtrace_t *libtrace);
529 
535  int (*init_output)(libtrace_out_t *libtrace);
536 
546  int (*config_output)(libtrace_out_t *libtrace, trace_option_output_t option, void *value);
547 
557  int (*start_output)(libtrace_out_t *libtrace);
558 
567  int (*fin_input)(libtrace_t *libtrace);
568 
574  int (*fin_output)(libtrace_out_t *libtrace);
575 
589  int (*read_packet)(libtrace_t *libtrace, libtrace_packet_t *packet);
590 
610  int (*prepare_packet)(libtrace_t *libtrace, libtrace_packet_t *packet,
611  void *buffer, libtrace_rt_types_t rt_type,
612  uint32_t flags);
613 
619  void (*fin_packet)(libtrace_packet_t *packet);
620 
627  int (*write_packet)(libtrace_out_t *libtrace, libtrace_packet_t *packet);
628 
633  int (*flush_output)(libtrace_out_t *libtrace);
634 
641 
649 
661 
676  uint64_t (*get_erf_timestamp)(const libtrace_packet_t *packet);
677 
691  struct timeval (*get_timeval)(const libtrace_packet_t *packet);
692 
706  struct timespec (*get_timespec)(const libtrace_packet_t *packet);
707 
722  double (*get_seconds)(const libtrace_packet_t *packet);
723 
744  int (*seek_erf)(libtrace_t *trace, uint64_t timestamp);
765  int (*seek_timeval)(libtrace_t *trace, struct timeval tv);
766 
788  int (*seek_seconds)(libtrace_t *trace, double seconds);
789 
800  int (*get_capture_length)(const libtrace_packet_t *packet);
801 
812  int (*get_wire_length)(const libtrace_packet_t *packet);
813 
824  int (*get_framing_length)(const libtrace_packet_t *packet);
825 
837  size_t (*set_capture_length)(struct libtrace_packet_t *packet,size_t size);
847 
856 
865 
879 
886  int (*get_fd)(const libtrace_t *trace);
887 
902 
904  void (*help)(void);
905 
909 
912 
923  int (*pstart_input)(libtrace_t *trace);
924 
938  int (*pread_packets)(libtrace_t *trace, libtrace_thread_t *t, libtrace_packet_t **packets, size_t nb_packets);
939 
944  int (*ppause_input)(libtrace_t *trace);
945 
950  int (*pfin_input)(libtrace_t *trace);
951 
971  int (*pregister_thread)(libtrace_t *libtrace, libtrace_thread_t *t, bool reader);
972 
979 
995  libtrace_stat_t *stat);
996 };
997 
999 #define NON_PARALLEL(live) \
1000  {live, 1}, /* trace info */ \
1001  NULL, /* pstart_input */ \
1002  NULL, /* pread_packet */ \
1003  NULL, /* ppause_input */ \
1004  NULL, /* pfin_input */ \
1005  NULL, /* pregister_thread */ \
1006  NULL, /* punregister_thread */ \
1007  NULL, /* get_thread_statistics */
1008 
1010 //extern struct libtrace_format_t *form;
1011 
1015 extern volatile int libtrace_halt;
1016 
1025 static inline int is_halted(libtrace_t *trace) {
1026  if (!(libtrace_halt || trace->state == STATE_PAUSING)) {
1027  return -1;
1028  } else if (libtrace_halt) {
1029  return READ_EOF;
1030  } else {
1031  return READ_MESSAGE;
1032  }
1033 }
1034 
1039 void register_format(struct libtrace_format_t *format);
1040 
1046 uint64_t tv_to_usec(const struct timeval *tv);
1047 
1055 
1062 
1069 
1077 
1085 
1092 
1099 
1107 
1114 uint8_t libtrace_to_erf_type(libtrace_linktype_t linktype);
1115 
1122 libtrace_linktype_t arphrd_type_to_libtrace(unsigned int arphrd);
1123 
1130 unsigned int libtrace_to_arphrd_type(libtrace_linktype_t type);
1131 
1141 void promote_packet(libtrace_packet_t *packet);
1142 
1152 bool demote_packet(libtrace_packet_t *packet);
1153 
1175 void *trace_get_payload_from_linux_sll(const void *link,
1176  uint16_t *arphrd_type,
1177  uint16_t *next_header,
1178  uint32_t *remaining);
1179 
1200 DLLEXPORT void *trace_get_payload_from_atm(void *link, uint8_t *type,
1201  uint32_t *remaining);
1202 
1203 
1204 #ifdef HAVE_BPF
1205 /* A type encapsulating a bpf filter
1206  * This type covers the compiled bpf filter, as well as the original filter
1207  * string
1208  *
1209  */
1210 
1212 struct libtrace_filter_t {
1213  struct bpf_program filter;
1214  char * filterstring;
1215  int flag;
1216  struct bpf_jit_t *jitfilter;
1217 };
1218 #else
1219 
1222 #endif
1223 
1226  uint32_t ts_sec; /* Seconds portion of the timestamp */
1227  uint32_t ts_usec; /* Microseconds portion of the timestamp */
1228  uint32_t caplen; /* Capture length of the packet */
1229  uint32_t wirelen; /* The wire length of the packet */
1231 
1232 #ifdef HAVE_DAG
1233 
1234 void dag_constructor(void);
1235 #endif
1236 
1237 void erf_constructor(void);
1239 void tsh_constructor(void);
1241 void legacy_constructor(void);
1243 void linuxnative_constructor(void);
1245 void linuxring_constructor(void);
1247 void pcap_constructor(void);
1249 void pcapfile_constructor(void);
1251 void pcapng_constructor(void);
1253 void rt_constructor(void);
1255 void duck_constructor(void);
1257 void atmhdr_constructor(void);
1259 void ndag_constructor(void);
1261 void etsilive_constructor(void);
1262 #ifdef HAVE_BPF
1263 
1264 void bpf_constructor(void);
1265 #endif
1266 #if HAVE_DPDK
1267 
1268 void dpdk_constructor(void);
1269 
1271 void dpdkndag_constructor(void);
1272 
1273 #endif
1274 
1286 bool trace_get_wireless_flags(void *link, libtrace_linktype_t linktype, uint8_t *flags);
1287 #define TRACE_RADIOTAP_F_FCS 0x10
1288 
1289 #ifdef __cplusplus
1290 }
1291 #endif
1292 
1293 #endif /* LIBTRACE_INT_H */
void tsh_constructor(void)
Constructor for the TSH format module.
Definition: format_tsh.c:323
int(* ppause_input)(libtrace_t *trace)
Pause a parallel trace.
Definition: libtrace_int.h:944
libtrace_linktype_t
Enumeration of link layer types supported by libtrace.
Definition: libtrace.h:349
void(* fn_cb_usermessage)(libtrace_t *libtrace, libtrace_thread_t *t, void *global, void *tls, int mesg, libtrace_generic_t data, libtrace_thread_t *sender)
Callback for handling any user-defined message types.
Definition: libtrace_parallel.h:547
int(* pstart_input)(libtrace_t *trace)
Starts or unpauses an input trace in parallel mode - note that this function is often the one that op...
Definition: libtrace_int.h:923
Tuning the parallel sizes See the user documentation trace_set_x.
Definition: libtrace_int.h:273
int(* flush_output)(libtrace_out_t *libtrace)
Flush any buffered output for an output trace.
Definition: libtrace_int.h:633
A libtrace capture format module.
Definition: libtrace_int.h:470
int(* prepare_packet)(libtrace_t *libtrace, libtrace_packet_t *packet, void *buffer, libtrace_rt_types_t rt_type, uint32_t flags)
Converts a buffer containing a packet record into a libtrace packet.
Definition: libtrace_int.h:610
int(* pread)(libtrace_t *, libtrace_thread_t *, libtrace_packet_t **, size_t)
The pread_packet choosen path for the configuration.
Definition: libtrace_int.h:365
int startcount
Number of times this trace has been started.
Definition: libtrace_int.h:340
volatile int libtrace_halt
The list of registered capture formats.
Definition: trace.c:102
uint64_t sequence_number
The sequence is like accepted_packets but we don't reset this after a pause.
Definition: libtrace_int.h:327
void * format_data
Pointer to the "global" data for the capture format module.
Definition: libtrace_int.h:312
libtrace_linktype_t(* get_link_type)(const libtrace_packet_t *packet)
Returns the libtrace link type for a packet.
Definition: libtrace_int.h:640
int(* seek_timeval)(libtrace_t *trace, struct timeval tv)
Moves the read pointer to a certain timestamp represented using a timeval within an input trace file...
Definition: libtrace_int.h:765
libtrace_linktype_t arphrd_type_to_libtrace(unsigned int arphrd)
Converts an ARPHRD type into a libtrace link type.
Definition: linktypes.c:223
The methods we use to combine the results from multiple processing threads into a single output...
Definition: libtrace_parallel.h:320
int(* write_packet)(libtrace_out_t *libtrace, libtrace_packet_t *packet)
Write a libtrace packet to an output trace.
Definition: libtrace_int.h:627
libtrace_direction_t
Trace directions.
Definition: libtrace.h:583
struct libtrace_format_t * next
Next pointer, should always be NULL - used by the format module manager.
Definition: libtrace_int.h:908
int(* seek_erf)(libtrace_t *trace, uint64_t timestamp)
Moves the read pointer to a certain ERF timestamp within an input trace file.
Definition: libtrace_int.h:744
Storage to note time value against each.
Definition: libtrace_int.h:226
int(* pread_packets)(libtrace_t *trace, libtrace_thread_t *t, libtrace_packet_t **packets, size_t nb_packets)
Read a batch of packets from the input stream related to thread.
Definition: libtrace_int.h:938
pthread_cond_t perpkt_cond
Use to control pausing threads and finishing threads etc always used with libtrace_lock.
Definition: libtrace_int.h:348
A libtrace input trace.
Definition: libtrace_int.h:306
libtrace_dlt_t
Enumeration of DLTs supported by libtrace.
Definition: libtrace.h:314
int(* start_input)(libtrace_t *libtrace)
Starts or unpauses an input trace - note that this function is often the one that opens the file or d...
Definition: libtrace_int.h:520
size_t snaplen
The snap length to be applied to all packets read by the trace - used only if the capture format does...
Definition: libtrace_int.h:318
uint64_t filtered_packets
Count of the number of packets filtered by libtrace.
Definition: libtrace_int.h:325
struct libtrace_eventobj_t(* trace_event)(libtrace_t *trace, libtrace_packet_t *packet)
Returns the next libtrace event for the input trace.
Definition: libtrace_int.h:901
int perpkt_thread_states[THREAD_STATE_MAX]
Keeps track of counts of threads in any given state.
Definition: libtrace_int.h:350
struct libtrace_pcapfile_pkt_hdr_t libtrace_pcapfile_pkt_hdr_t
Local definition of a PCAP header.
void promote_packet(libtrace_packet_t *packet)
Converts a libtrace packet to the Linux SLL type.
Definition: linktypes.c:258
void rt_constructor(void)
Constructor for the RT format module.
Definition: format_rt.c:873
void linuxring_constructor(void)
Constructor for the Linux Ring format module.
Definition: format_linux_ring.c:875
Local definition of a PCAP header.
Definition: libtrace_int.h:1225
void atmhdr_constructor(void)
Constructor for the ATM Header format module.
Definition: format_atmhdr.c:231
DLLEXPORT void * trace_get_payload_from_atm(void *link, uint8_t *type, uint32_t *remaining)
Returns a pointer to the header following an ATM header.
Definition: protocols_l2.c:541
Header file containing all the possible GPP record types.
bool trace_get_wireless_flags(void *link, libtrace_linktype_t linktype, uint8_t *flags)
Extracts the RadioTap flags from a wireless link header.
Definition: link_wireless.c:203
Header file containing definitions of functions and macros that deal with byteswapping within libtrac...
int(* get_capture_length)(const libtrace_packet_t *packet)
Returns the payload length of the captured packet record.
Definition: libtrace_int.h:800
Definition: libtrace_int.h:289
Libtrace error information.
Definition: libtrace.h:277
libtrace_err_t err
Error information for the output trace.
Definition: libtrace_int.h:415
int(* probe_magic)(io_t *io)
Given a file, looks at the start of the file to determine if this is the capture format.
Definition: libtrace_int.h:496
int(* seek_seconds)(libtrace_t *trace, double seconds)
Moves the read pointer to a certain timestamp represented using floating point seconds within an inpu...
Definition: libtrace_int.h:788
A collection of types for convenience used in place of a simple void* to allow any type of data to be...
Definition: libtrace_parallel.h:62
int(* fin_output)(libtrace_out_t *libtrace)
Concludes an output trace and cleans up the capture format data.
Definition: libtrace_int.h:574
libtrace_dlt_t rt_to_pcap_linktype(libtrace_rt_types_t rt_type)
Converts an RT protocol type into a PCAP DLT.
Definition: linktypes.c:150
bool demote_packet(libtrace_packet_t *packet)
Attempts to demote a packet by removing the first header.
Definition: linktypes.c:328
void trace_fin_packet(libtrace_packet_t *packet)
Removes any possible data stored againt the trace and releases any data.
Definition: trace.c:916
struct libtrace_format_t * format
The capture format for the output trace.
Definition: libtrace_int.h:409
const char * name
The name of this module, used in the libtrace URI to identify the capture format. ...
Definition: libtrace_int.h:473
void ndag_constructor(void)
Constructor for the network DAG format module.
Definition: format_ndag.c:1484
trace_option_t
Valid configuration options for input traces.
Definition: libtrace.h:1306
libtrace_packet_t *(* fn_cb_packet)(libtrace_t *libtrace, libtrace_thread_t *t, void *global, void *tls, libtrace_packet_t *packet)
A callback function triggered when a processing thread receives a packet.
Definition: libtrace_parallel.h:514
base_format_t
RT protocol base format identifiers.
Definition: libtrace.h:381
int(* init_input)(libtrace_t *libtrace)
Initialises an input trace using the capture format.
Definition: libtrace_int.h:503
int(* read_packet)(libtrace_t *libtrace, libtrace_packet_t *packet)
Reads the next packet from an input trace into the provided packet structure.
Definition: libtrace_int.h:589
void(* fn_cb_dataless)(libtrace_t *libtrace, libtrace_thread_t *t, void *global, void *tls)
A callback function for any message that does not require any specific data, e.g. ...
Definition: libtrace_parallel.h:466
libtrace_packet_t * last_packet
The packet read out by the trace, backwards compatibility to allow us to finalise a packet when the t...
Definition: libtrace_int.h:330
void trace_set_err(libtrace_t *trace, int errcode, const char *msg,...) PRINTF(3
Sets the error status on an input trace.
libtrace_linktype_t erf_type_to_libtrace(uint8_t erf)
Converts an ERF type into a libtrace link type.
Definition: linktypes.c:168
uint64_t(* get_erf_timestamp)(const libtrace_packet_t *packet)
Returns the timestamp for a packet in the ERF timestamp format.
Definition: libtrace_int.h:676
struct libtrace_filter_t * filter
A BPF filter to be applied to all packets read by the trace - used only if the capture format does no...
Definition: libtrace_int.h:315
void * trace_get_payload_from_linux_sll(const void *link, uint16_t *arphrd_type, uint16_t *next_header, uint32_t *remaining)
Returns a pointer to the header following a Linux SLL header.
Definition: protocols_pktmeta.c:46
trace_option_output_t
Valid configuration options for output traces.
Definition: libtrace.h:1400
void * global_blob
Global storage for this trace, shared among all the threads.
Definition: libtrace_int.h:355
int psize
The size of the current PACKET event.
Definition: libtrace_int.h:168
void register_format(struct libtrace_format_t *format)
Registers a new capture format module.
Definition: trace.c:2424
struct libtrace_t * trace
Pointer to the trace.
Definition: libtrace.h:544
enum hasher_types hasher_type
The hasher function.
Definition: libtrace_int.h:359
uint64_t accepted_packets
Count of the number of packets returned to the libtrace user.
Definition: libtrace_int.h:323
int(* init_output)(libtrace_out_t *libtrace)
Initialises an output trace using the capture format.
Definition: libtrace_int.h:535
int snprintf(char *str, size_t size, const char *format,...)
A local implementation of snprintf (as some systems do not have it)
void(* punregister_thread)(libtrace_t *libtrace, libtrace_thread_t *t)
If needed any memory allocated with pregister_thread can be released in this function.
Definition: libtrace_int.h:978
libtrace_rt_types_t bpf_linktype_to_rt(libtrace_dlt_t linktype)
Converts a PCAP DLT into an RT protocol type for the BPF format.
Definition: linktypes.c:140
libtrace_direction_t(* get_direction)(const libtrace_packet_t *packet)
Returns the direction of a packet.
Definition: libtrace_int.h:648
bool started
Boolean flag indicating whether the trace has been started.
Definition: libtrace_int.h:417
The libtrace packet structure.
Definition: libtrace.h:543
pthread_mutex_t libtrace_lock
Synchronise writes/reads across this format object and attached threads etc.
Definition: libtrace_int.h:342
void linuxnative_constructor(void)
Constructor for the Linux Native format module.
Definition: format_linux_int.c:586
int(* fin_input)(libtrace_t *libtrace)
Concludes an input trace and cleans up the capture format data.
Definition: libtrace_int.h:567
int(* config_input)(libtrace_t *libtrace, trace_option_t option, void *value)
Applies a configuration option to an input trace.
Definition: libtrace_int.h:514
Information of this thread.
Definition: libtrace_int.h:198
void(* fn_cb_tick)(libtrace_t *libtrace, libtrace_thread_t *t, void *global, void *tls, uint64_t order)
A callback function for handling a tick message within a processing thread.
Definition: libtrace_parallel.h:495
int(* get_wire_length)(const libtrace_packet_t *packet)
Returns the original length of the packet as it was on the wire.
Definition: libtrace_int.h:812
Header file containing definitions for structures and functions related to the parallel framework...
libtrace_rt_types_t
RT protocol packet types.
Definition: libtrace.h:406
int(* pfin_input)(libtrace_t *trace)
Called after all threads have been paused, Finish (close) a parallel trace.
Definition: libtrace_int.h:950
void(* fn_cb_first_packet)(libtrace_t *libtrace, libtrace_thread_t *t, void *global, void *tls, libtrace_thread_t *sender)
A callback function for a first packet message seen by a processing thread.
Definition: libtrace_parallel.h:479
Structure returned by libtrace_event explaining what the current event is.
Definition: libtrace.h:1870
uint8_t libtrace_to_erf_type(libtrace_linktype_t linktype)
Converts a libtrace link type into an ERF type.
Definition: linktypes.c:185
int strncasecmp(const char *str1, const char *str2, size_t n)
A local implementation of strncasecmp (as some systems do not have it)
uint64_t(* get_dropped_packets)(libtrace_t *trace)
Returns the number of packets dropped by an input trace.
Definition: libtrace_int.h:864
const char * version
The version of this module.
Definition: libtrace_int.h:475
pthread_mutex_t read_packet_lock
Packet read lock, seperate from libtrace_lock as to not block while reading a burst.
Definition: libtrace_int.h:344
void * format_data
Pointer to the "global" data for the capture format module.
Definition: libtrace_int.h:411
void etsilive_constructor(void)
Constructor for the live ETSI over TCP format module.
Definition: format_etsilive.c:665
Data about the most recent event from a trace file.
Definition: libtrace_int.h:157
void legacy_constructor(void)
Constructor for the Legacy DAG format module.
Definition: format_legacy.c:686
void void void trace_clear_cache(libtrace_packet_t *packet)
Clears the cached values for a libtrace packet.
Definition: trace.c:2402
libtrace_ocache_t packet_freelist
The actual freelist.
Definition: libtrace_int.h:357
libtrace_rt_types_t pcap_linktype_to_rt(libtrace_dlt_t linktype)
Converts a PCAP DLT into an RT protocol type.
Definition: linktypes.c:134
void pcap_constructor(void)
Constructor for the PCAP format module.
Definition: message_queue.h:35
Header that provides local definitions of the various format identifiers used for printing various nu...
Statistic counters are cumulative from the time the trace is started.
Definition: libtrace.h:1432
void erf_constructor(void)
Constructor for the ERF format module.
Definition: format_erf.c:962
BPF not supported by this system, but we still need to define a structure for the filter...
Definition: libtrace_int.h:1221
double(* get_seconds)(const libtrace_packet_t *packet)
Returns the timestamp for a packet in floating point seconds.
Definition: libtrace_int.h:722
int(* probe_filename)(const char *fname)
Given a filename, return if this is the most likely capture format (used for devices).
Definition: libtrace_int.h:487
void store_first_packet(libtrace_t *libtrace, libtrace_packet_t *packet, libtrace_thread_t *t)
For the first packet of each queue we keep a copy and note the system time it was received at...
Definition: trace_parallel.c:1010
void pcapng_constructor(void)
Constructor for the PCAP-NG File format module.
Definition: format_pcapng.c:1393
Definition: ring_buffer.h:39
unsigned int libtrace_to_arphrd_type(libtrace_linktype_t type)
Converts a libtrace link type into an ARPHRD type.
Definition: linktypes.c:239
Header file describing the framing formats used by old legacy DAG implementations.
Header file containing definitions required to process DAG / ERF traces.
struct libtrace_event_status_t event
Details of the most recent PACKET event reported by the trace.
Definition: libtrace_int.h:310
int(* pregister_thread)(libtrace_t *libtrace, libtrace_thread_t *t, bool reader)
Register a thread for use with the format or using the packets produced by it.
Definition: libtrace_int.h:971
uint64_t(* fn_hasher)(const libtrace_packet_t *packet, void *data)
The definition for a hasher function, allowing matching packets to be directed to the correct thread ...
Definition: libtrace_parallel.h:415
void *(* fn_cb_starting)(libtrace_t *libtrace, libtrace_thread_t *t, void *global)
The starting callback for a processing or reporting thread.
Definition: libtrace_parallel.h:453
void(* fin_packet)(libtrace_packet_t *packet)
Frees any resources allocated by the capture format module for a libtrace packet. ...
Definition: libtrace_int.h:619
libtrace_rt_types_t pcapng_linktype_to_rt(libtrace_dlt_t linktype)
Converts a PCAP-NG DLT into an RT protocol type.
Definition: linktypes.c:145
enum base_format_t type
The RT protocol type of this module.
Definition: libtrace_int.h:477
libtrace_err_t err
Error information for the trace.
Definition: libtrace_int.h:336
Definition: object_cache.h:34
void(* get_statistics)(libtrace_t *trace, libtrace_stat_t *stat)
Returns statistics about a trace.
Definition: libtrace_int.h:878
void pcapfile_constructor(void)
Constructor for the PCAP File format module.
Definition: format_pcapfile.c:730
int(* pause_input)(libtrace_t *libtrace)
Pauses an input trace - this function should close or detach the file or device that is being read fr...
Definition: libtrace_int.h:528
hasher_types
The hasher types that are available to libtrace applications.
Definition: libtrace_parallel.h:260
void(* get_thread_statistics)(libtrace_t *libtrace, libtrace_thread_t *t, libtrace_stat_t *stat)
Returns statistics for a single thread.
Definition: libtrace_int.h:993
Header file containing definitions specific to the RT protocol that can be used to transport captured...
int replayspeedup
Speed up the packet rate when using trace_event() to process trace files by this factor.
Definition: libtrace_int.h:321
int(* config_output)(libtrace_out_t *libtrace, trace_option_output_t option, void *value)
Applies a configuration option to an output trace.
Definition: libtrace_int.h:546
io_t * io
The libtrace IO reader for this trace (if applicable)
Definition: libtrace_int.h:334
void void trace_set_err_out(libtrace_out_t *trace, int errcode, const char *msg,...) PRINTF(3
Sets the error status on an output trace.
libtrace_messages
The libtrace_messages enum All libtrace messages are defined and documented here. ...
Definition: libtrace_parallel.h:132
bool perpkt_queue_full
Set to indicate a perpkt's queue is full as such the writing perpkt cannot proceed.
Definition: libtrace_int.h:353
libtrace_dlt_t libtrace_to_pcap_dlt(libtrace_linktype_t type)
Converts a libtrace link type into a PCAP DLT.
Definition: linktypes.c:71
libtrace_dlt_t libtrace_to_pcap_linktype(libtrace_linktype_t type)
Converts a libtrace link type into a PCAP linktype.
Definition: linktypes.c:129
void duck_constructor(void)
Constructor for the DUCK format module.
Definition: format_duck.c:365
void(* help)(void)
Prints some useful help information to standard output.
Definition: libtrace_int.h:904
struct libtrace_format_t * format
The capture format for the input trace.
Definition: libtrace_int.h:308
size_t(* set_capture_length)(struct libtrace_packet_t *packet, size_t size)
Sets the capture length for a packet.
Definition: libtrace_int.h:837
struct timeval(* get_timeval)(const libtrace_packet_t *packet)
Returns the timestamp for a packet in the timeval format.
Definition: libtrace_int.h:691
Flags.
Definition: dagformat.h:81
uint64_t(* get_received_packets)(libtrace_t *trace)
Returns the number of packets observed by an input trace.
Definition: libtrace_int.h:846
enum trace_state state
State.
Definition: libtrace_int.h:346
uint64_t tv_to_usec(const struct timeval *tv)
Converts a timeval into a timestamp in microseconds since the epoch.
Definition: trace_parallel.c:1104
Definition: libtrace_parallel.h:292
int(* start_output)(libtrace_out_t *libtrace)
Starts an output trace - note that this function is often the one that opens the file or device for w...
Definition: libtrace_int.h:557
fn_hasher hasher
The hasher function - NULL implies they don't care or balance.
Definition: libtrace_int.h:361
void(* fn_cb_result)(libtrace_t *libtrace, libtrace_thread_t *sender, void *global, void *tls, libtrace_result_t *result)
Callback for handling a result message.
Definition: libtrace_parallel.h:531
char * uridata
The filename for the uri for the output trace.
Definition: libtrace_int.h:413
bool started
Boolean flag indicating whether the trace has been started.
Definition: libtrace_int.h:338
int(* get_fd)(const libtrace_t *trace)
Returns the file descriptor used by the input trace.
Definition: libtrace_int.h:886
uint64_t(* get_filtered_packets)(libtrace_t *trace)
Returns the number of packets filtered by an input trace.
Definition: libtrace_int.h:855
libtrace_direction_t(* set_direction)(libtrace_packet_t *packet, libtrace_direction_t direction)
Sets the direction of a packet.
Definition: libtrace_int.h:660
char * uridata
The filename from the uri for the trace.
Definition: libtrace_int.h:332
A libtrace output trace.
Definition: libtrace_int.h:407
struct libtrace_pflog_header_t libtrace_pflog_header_t
A local definition of a PFLOG header.
int(* get_framing_length)(const libtrace_packet_t *packet)
Returns the length of the capture format framing header.
Definition: libtrace_int.h:824
libtrace_packet_t * packet
A libtrace packet to store the packet when a PACKET event occurs.
Definition: libtrace_int.h:159
libtrace_linktype_t pcap_linktype_to_libtrace(libtrace_dlt_t linktype)
Converts a PCAP DLT into a libtrace link type.
Definition: linktypes.c:45
A local definition of a PFLOG header.
Definition: libtrace_int.h:455
bool waiting
Whether there is a packet stored in *packet above waiting for an event to occur.
Definition: libtrace_int.h:171
struct libtrace_info_t info
Holds information about the trace format.
Definition: libtrace_int.h:911
struct timespec(* get_timespec)(const libtrace_packet_t *packet)
Returns the timestamp for a packet in the timespec format.
Definition: libtrace_int.h:706