summaryrefslogtreecommitdiffstats
path: root/src/vnet
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2021-03-05 14:41:25 +0100
committerDamjan Marion <damarion@cisco.com>2021-03-07 15:58:54 +0100
commit25ab6c541062f436989b89962cdab10f21f1b4f0 (patch)
tree9b68793eee358dffd1afd0843f4b92996b717523 /src/vnet
parent46353f069337051b9299c1a21a7110d19816e66d (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')
-rw-r--r--src/vnet/buffer.h3
-rw-r--r--src/vnet/interface_funcs.h37
-rw-r--r--src/vnet/vnet.h1
3 files changed, 41 insertions, 0 deletions
diff --git a/src/vnet/buffer.h b/src/vnet/buffer.h
index bd70ea2722f..37db4130514 100644
--- a/src/vnet/buffer.h
+++ b/src/vnet/buffer.h
@@ -520,6 +520,9 @@ STATIC_ASSERT (sizeof (vnet_buffer_opaque2_t) <=
format_function_t format_vnet_buffer;
format_function_t format_vnet_buffer_offload;
+format_function_t format_vnet_buffer_flags;
+format_function_t format_vnet_buffer_opaque;
+format_function_t format_vnet_buffer_opaque2;
static_always_inline void
vnet_buffer_offload_flags_set (vlib_buffer_t *b, u32 oflags)
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 */
/*
diff --git a/src/vnet/vnet.h b/src/vnet/vnet.h
index 38777b9b24f..1deaff66375 100644
--- a/src/vnet/vnet.h
+++ b/src/vnet/vnet.h
@@ -112,6 +112,7 @@ typedef struct vnet_main_t
extern vnet_main_t vnet_main;
+#include <vppinfra/pcap_funcs.h>
#include <vnet/interface_funcs.h>
#include <vnet/global_funcs.h>