39 s =
format (s,
"SPAN: mirrored %U -> %U",
46 #define foreach_span_error \ 47 _(HITS, "SPAN incoming packets processed") 51 #define _(sym,str) SPAN_ERROR_##sym, 58 #define _(sym,string) string, 71 u32 *to_mirror_next = 0;
92 if (mirror_frames[i] == 0)
94 if (sf == SPAN_FEAT_L2)
95 mirror_frames[i] = vlib_get_frame_to_node (vm, l2output_node.index);
97 mirror_frames[i] = vnet_get_frame_to_sw_interface (vnm, i);
100 to_mirror_next += mirror_frames[
i]->
n_vectors;
106 c0->
flags |= VNET_BUFFER_F_SPAN_CLONE;
108 vnet_buffer (c0)->l2.feature_bitmap = L2OUTPUT_FEAT_OUTPUT;
122 c0->
flags |= VLIB_BUFFER_IS_TRACED;
137 u32 n_left_from, *from, *to_next;
138 u32 n_span_packets = 0;
150 while (n_left_from > 0)
156 while (n_left_from >= 4 && n_left_to_next >= 2)
168 to_next[0] = bi0 = from[0];
169 to_next[1] = bi1 = from[1];
177 sw_if_index0 =
vnet_buffer (b0)->sw_if_index[rxtx];
178 sw_if_index1 =
vnet_buffer (b1)->sw_if_index[rxtx];
180 span_mirror (vm, node, sw_if_index0, b0, mirror_frames, rxtx, sf);
181 span_mirror (vm, node, sw_if_index1, b1, mirror_frames, rxtx, sf);
210 to_next, n_left_to_next,
211 bi0, bi1, next0, next1);
213 while (n_left_from > 0 && n_left_to_next > 0)
221 to_next[0] = bi0 = from[0];
228 sw_if_index0 =
vnet_buffer (b0)->sw_if_index[rxtx];
230 span_mirror (vm, node, sw_if_index0, b0, mirror_frames, rxtx, sf);
250 n_left_to_next, bi0, next0);
257 for (sw_if_index = 0; sw_if_index <
vec_len (mirror_frames); sw_if_index++)
303 #define span_node_defs \ 304 .vector_size = sizeof (u32), \ 305 .format_trace = format_span_trace, \ 306 .type = VLIB_NODE_TYPE_INTERNAL, \ 307 .n_errors = ARRAY_LEN(span_error_strings), \ 308 .error_strings = span_error_strings, \ 318 .name =
"span-input",
326 .name =
"span-output",
334 .name =
"span-l2-input",
342 .name =
"span-l2-output",
372 #undef span_node_defs
char ** l2output_get_feat_names(void)
span_mirror_t mirror_rxtx[SPAN_FEAT_N][VLIB_N_RX_TX]
vnet_main_t * vnet_get_main(void)
vlib_node_registration_t l2output_node
(constructor) VLIB_REGISTER_NODE (l2output_node)
static char * span_error_strings[]
static uword span_l2_output_node_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
#define vec_validate_aligned(V, I, A)
Make sure vector is long enough for given index (no header, specified alignment)
vlib_node_registration_t span_l2_output_node
(constructor) VLIB_REGISTER_NODE (span_l2_output_node)
format_function_t format_vnet_sw_if_index_name
static vlib_buffer_t * vlib_buffer_copy(vlib_main_t *vm, vlib_buffer_t *b)
static u32 vnet_l2_feature_next(vlib_buffer_t *b, u32 *next_nodes, u32 feat_bit)
Return the graph node index for the feature corresponding to the next set bit after clearing the curr...
vlib_node_registration_t span_input_node
(constructor) VLIB_REGISTER_NODE (span_input_node)
clib_bitmap_t * mirror_ports
vlib_node_registration_t span_l2_input_node
(constructor) VLIB_REGISTER_NODE (span_l2_input_node)
#define static_always_inline
#define VLIB_INIT_FUNCTION(x)
static_always_inline uword span_node_inline_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame, vlib_rx_or_tx_t rxtx, span_feat_t sf)
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
clib_error_t * span_init(vlib_main_t *vm)
static u32 vlib_get_buffer_index(vlib_main_t *vm, void *p)
Translate buffer pointer into buffer index.
static uword span_device_input_node_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
#define VLIB_NODE_FUNCTION_MULTIARCH(node, fn)
static uword span_device_output_node_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
u8 * format_span_trace(u8 *s, va_list *args)
#define clib_bitmap_foreach(i, ai, body)
Macro to iterate across set bits in a bitmap.
vlib_node_registration_t span_output_node
(constructor) VLIB_REGISTER_NODE (span_output_node)
span_interface_t * interfaces
void vlib_put_frame_to_node(vlib_main_t *vm, u32 to_node_index, vlib_frame_t *f)
vlib_node_registration_t span_node
#define vlib_validate_buffer_enqueue_x2(vm, node, next_index, to_next, n_left_to_next, bi0, bi1, next0, next1)
Finish enqueueing two buffers forward in the graph.
#define vlib_validate_buffer_enqueue_x1(vm, node, next_index, to_next, n_left_to_next, bi0, next0)
Finish enqueueing one buffer forward in the graph.
#define vlib_get_next_frame(vm, node, next_index, vectors, n_vectors_left)
Get pointer to next frame vector data by (vlib_node_runtime_t, next_index).
static void vlib_node_increment_counter(vlib_main_t *vm, u32 node_index, u32 counter_index, u64 increment)
The fine-grained event logger allows lightweight, thread-safe event logging at minimum cost...
#define VLIB_REGISTER_NODE(x,...)
static void vnet_put_frame_to_sw_interface(vnet_main_t *vnm, u32 sw_if_index, vlib_frame_t *f)
static_always_inline void vnet_feature_next(u32 *next0, vlib_buffer_t *b0)
static void feat_bitmap_init_next_nodes(vlib_main_t *vm, u32 node_index, u32 num_features, char **feat_names, u32 *next_nodes)
Initialize the feature next-node indexes of a graph node.
void vlib_put_next_frame(vlib_main_t *vm, vlib_node_runtime_t *r, u32 next_index, u32 n_vectors_left)
Release pointer to next frame vector data.
u16 cached_next_index
Next frame index that vector arguments were last enqueued to last time this node ran.
static_always_inline void span_mirror(vlib_main_t *vm, vlib_node_runtime_t *node, u32 sw_if_index0, vlib_buffer_t *b0, vlib_frame_t **mirror_frames, vlib_rx_or_tx_t rxtx, span_feat_t sf)
static void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
struct _vlib_node_registration vlib_node_registration_t
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
static uword span_l2_input_node_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
#define foreach_span_error
#define CLIB_CACHE_LINE_BYTES
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index, VLIB_BUFFER_IS_TRACED: trace this buffer.
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.