diff options
author | Damjan Marion <damarion@cisco.com> | 2021-03-05 14:41:25 +0100 |
---|---|---|
committer | Damjan Marion <damarion@cisco.com> | 2021-03-07 15:58:54 +0100 |
commit | 25ab6c541062f436989b89962cdab10f21f1b4f0 (patch) | |
tree | 9b68793eee358dffd1afd0843f4b92996b717523 /src/vnet/interface_funcs.h | |
parent | 46353f069337051b9299c1a21a7110d19816e66d (diff) |
dispatch-trace: move dispatch trace pcap code to plugin
Type: refactor
Change-Id: I02a527f57853ebff797f0d85761b71127916d6ce
Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'src/vnet/interface_funcs.h')
-rw-r--r-- | src/vnet/interface_funcs.h | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/vnet/interface_funcs.h b/src/vnet/interface_funcs.h index 186e0327884..565dcd5be99 100644 --- a/src/vnet/interface_funcs.h +++ b/src/vnet/interface_funcs.h @@ -510,6 +510,43 @@ u8 *format_vnet_interface_output_trace (u8 * s, va_list * va); serialize_function_t serialize_vnet_interface_state, unserialize_vnet_interface_state; +/** + * @brief Add buffer (vlib_buffer_t) to the trace + * + * @param *pm - pcap_main_t + * @param *vm - vlib_main_t + * @param buffer_index - u32 + * @param n_bytes_in_trace - u32 + * + */ +static inline void +pcap_add_buffer (pcap_main_t *pm, struct vlib_main_t *vm, u32 buffer_index, + u32 n_bytes_in_trace) +{ + vlib_buffer_t *b = vlib_get_buffer (vm, buffer_index); + u32 n = vlib_buffer_length_in_chain (vm, b); + i32 n_left = clib_min (n_bytes_in_trace, n); + f64 time_now = vlib_time_now (vm); + void *d; + + if (PREDICT_TRUE (pm->n_packets_captured < pm->n_packets_to_capture)) + { + clib_spinlock_lock_if_init (&pm->lock); + d = pcap_add_packet (pm, time_now, n_left, n); + while (1) + { + u32 copy_length = clib_min ((u32) n_left, b->current_length); + clib_memcpy_fast (d, b->data + b->current_data, copy_length); + n_left -= b->current_length; + if (n_left <= 0) + break; + d += b->current_length; + ASSERT (b->flags & VLIB_BUFFER_NEXT_PRESENT); + b = vlib_get_buffer (vm, b->next_buffer); + } + clib_spinlock_unlock_if_init (&pm->lock); + } +} #endif /* included_vnet_interface_funcs_h */ /* |