20 #ifndef included_vnet_mpcap_h 21 #define included_vnet_mpcap_h 24 #include <sys/types.h> 38 #define foreach_vnet_mpcap_packet_type \ 47 #define _(f,n) MPCAP_PACKET_TYPE_##f = (n), 52 #define foreach_mpcap_file_header \ 58 _ (u16, major_version) \ 59 _ (u16, minor_version) \ 68 _ (u32, max_packet_size_in_bytes) \ 81 #define foreach_mpcap_packet_header \ 83 _ (u32, time_in_sec) \ 85 _ (u32, time_in_usec) \ 88 _ (u32, n_packet_bytes_stored_in_file) \ 90 _ (u32, n_bytes_in_packet) 136 #define MPCAP_FLAG_INIT_DONE (1 << 0) 137 #define MPCAP_FLAG_THREAD_SAFE (1 << 1) 138 #define MPCAP_FLAG_WRITE_ENABLE (1 << 2) 154 #define MPCAP_DEFAULT_FILE_SIZE (10<<20) 178 f64 time_now,
u32 n_bytes_in_trace,
u32 n_bytes_in_packet)
188 pm->
current_va +=
sizeof (h[0]) + n_bytes_in_trace;
194 h->time_in_sec = time_now;
195 h->time_in_usec = 1e6 * (time_now - h->time_in_sec);
196 h->n_packet_bytes_stored_in_file = n_bytes_in_trace;
197 h->n_bytes_in_packet = n_bytes_in_packet;
215 f64 time_now,
u32 buffer_index,
u32 n_bytes_in_trace)
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index, VLIB_BUFFER_IS_TRACED: trace this buffer.
u32 min_packet_bytes
Min/Max Packet bytes.
#define foreach_mpcap_file_header
#define foreach_vnet_mpcap_packet_type
Packet types supported by MPCAP.
#define MPCAP_FLAG_INIT_DONE
u8 * file_baseva
Base address.
static void * mpcap_add_packet(mpcap_main_t *pm, f64 time_now, u32 n_bytes_in_trace, u32 n_bytes_in_packet)
Add packet.
i16 current_data
signed offset in data[], pre_data[] that we are currently processing.
static_always_inline void clib_spinlock_unlock_if_init(clib_spinlock_t *p)
u16 current_length
Nbytes between current data and the end of this buffer.
clib_error_t * mpcap_map(mpcap_main_t *pm)
mmap a mpcap data file.
u32 n_mpcap_data_written
Bytes written.
static uword vlib_buffer_length_in_chain(vlib_main_t *vm, vlib_buffer_t *b)
Get length in bytes of the buffer chain.
#define foreach_mpcap_packet_header
#define clib_memcpy(d, s, n)
clib_error_t * mpcap_close(mpcap_main_t *pm)
Flush / unmap a mpcap file.
char * file_name
File name of mpcap output.
static void mpcap_add_buffer(mpcap_main_t *pm, vlib_main_t *vm, f64 time_now, u32 buffer_index, u32 n_bytes_in_trace)
Add buffer (vlib_buffer_t) to the trace.
MPCAP main state data structure.
u32 n_packets_captured
Number of packets currently captured.
clib_error_t * mpcap_init(mpcap_main_t *pm)
initialize a mpcap file (for writing)
clib_spinlock_t lock
spinlock, initialized if flagged MPCAP_FLAG_THREAD_SAFE
mpcap_file_header_t * file_header
Pointer to file header in svm, for ease of updating.
u8 * mpcap_data
Vector of mpcap data.
mpcap_packet_type_t packet_type
Packet type.
u64 packets_read
Packets in mapped mpcap file.
u32 next_buffer
Next buffer for this linked-list of buffers.
VLIB buffer representation.
u32 n_packets_to_capture
Number of packets to capture.
u64 max_file_size
Maximum file size.
static_always_inline void clib_spinlock_lock_if_init(clib_spinlock_t *p)
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
u8 * current_va
current memory address