42 #ifndef LIBTRACE_INT_H
43 #define LIBTRACE_INT_H
57 #pragma warning(disable:4996)
59 #pragma warning(disable:4142)
62 #ifdef HAVE_INTTYPES_H
63 # include <inttypes.h>
72 # error "Can't find stddev.h -- do you define ptrdiff_t elsewhere?"
84 #ifdef HAVE_PCAP_BPF_H
85 # include <pcap-bpf.h>
92 # ifdef HAVE_PCAP_INT_H
93 # include <pcap-int.h>
101 #if !HAVE_DECL_STRNDUP
102 char *strndup(
const char *s,
size_t size);
105 #if !HAVE_DECL_STRNCASECMP
106 # ifndef HAVE__STRNICMP
108 int strncasecmp(
const char *str1,
const char *str2,
size_t n);
110 # define strncasecmp _strnicmp
114 #if !HAVE_DECL_SNPRINTF
115 # ifndef HAVE_SPRINTF_S
117 int snprintf(
char *str,
size_t size,
const char *format, ...);
119 # define snprintf sprintf_s
128 # if DAG_VERSION == 24
139 #include "bpf-jit/bpf-jit.h"
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"
154 #define LIBTRACE_MAX_REPLAY_SPEEDUP 1000
199 uint64_t accepted_packets;
200 uint64_t filtered_packets;
205 int64_t tracetime_offset_usec;
212 enum thread_types type;
213 enum thread_states state;
218 } ALIGN_STRUCT(CACHE_LINE_SIZE);
227 pthread_spinlock_t lock;
236 #define TRACE_STATES \
253 #define X(a) case a: return #a;
254 static inline char *get_trace_state_name(
enum trace_state ts){
264 #define READ_ERROR -1
265 #define READ_MESSAGE -2
275 size_t thread_cache_size;
278 size_t tick_interval;
280 size_t perpkt_threads;
281 size_t hasher_queue_size;
283 bool reporter_polling;
284 size_t reporter_thold;
287 #define ZERO_USER_CONFIG(config) memset(&config, 0, sizeof(struct user_configuration));
363 enum hash_owner hasher_owner;
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;
392 #define LIBTRACE_STAT_MAGIC 0x41
445 #ifndef PF_RULESET_NAME_SIZE
446 #define PF_RULESET_NAME_SIZE 16
460 char ifname[IFNAMSIZ];
461 char ruleset[PF_RULESET_NAME_SIZE];
999 #define NON_PARALLEL(live) \
1025 static inline int is_halted(
libtrace_t *trace) {
1026 if (!(libtrace_halt || trace->
state == STATE_PAUSING)) {
1028 }
else if (libtrace_halt) {
1031 return READ_MESSAGE;
1046 uint64_t
tv_to_usec(
const struct timeval *tv);
1176 uint16_t *arphrd_type,
1177 uint16_t *next_header,
1178 uint32_t *remaining);
1201 uint32_t *remaining);
1213 struct bpf_program filter;
1214 char * filterstring;
1216 struct bpf_jit_t *jitfilter;
1234 void dag_constructor(
void);
1264 void bpf_constructor(
void);
1268 void dpdk_constructor(
void);
1271 void dpdkndag_constructor(
void);
1287 #define TRACE_RADIOTAP_F_FCS 0x10
void tsh_constructor(void)
Constructor for the TSH format module.
Definition: format_tsh.c:323
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
Tuning the parallel sizes See the user documentation trace_set_x.
Definition: libtrace_int.h:273
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 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
libtrace_direction_t
Trace directions.
Definition: libtrace.h:583
Storage to note time value against each.
Definition: libtrace_int.h:226
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
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
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...
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
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
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
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
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
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 snprintf(char *str, size_t size, const char *format,...)
A local implementation of snprintf (as some systems do not have it)
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
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
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
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
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)
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
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.
struct libtrace_event_status_t event
Details of the most recent PACKET event reported by the trace.
Definition: libtrace_int.h:310
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
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
libtrace_err_t err
Error information for the trace.
Definition: libtrace_int.h:336
Definition: object_cache.h:34
void pcapfile_constructor(void)
Constructor for the PCAP File format module.
Definition: format_pcapfile.c:730
hasher_types
The hasher types that are available to libtrace applications.
Definition: libtrace_parallel.h:260
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
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
struct libtrace_format_t * format
The capture format for the input trace.
Definition: libtrace_int.h:308
Flags.
Definition: dagformat.h:81
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
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
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.
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
bool waiting
Whether there is a packet stored in *packet above waiting for an event to occur.
Definition: libtrace_int.h:171