diff options
author | Dave Barach <dave@barachs.net> | 2019-09-23 16:03:49 -0400 |
---|---|---|
committer | Damjan Marion <dmarion@me.com> | 2019-09-25 22:19:59 +0000 |
commit | a2aa83ca93c865f5ddcbe060efaa99aecc696208 (patch) | |
tree | 3fe4b84c69852951c4d978ef725121cc73bde935 /src/vnet | |
parent | 731312df93534d9695b2d22fc9071a860868f87d (diff) |
misc: improve pcap drop trace output
Append <nodename>: <error-string> to pcap drop traces.
The data displays perfectly fine in [vanilla] wireshark, and makes it
100% obvious which node dropped the packet, and why.
Type: feature
Ticket: VPP-1776
Signed-off-by: Dave Barach <dave@barachs.net>
Change-Id: I9b964b99da4011b93723354db6ef0b128fca20cb
(cherry picked from commit 9382ad9b390e17c8bfd8229342656348d059becb)
Diffstat (limited to 'src/vnet')
-rw-r--r-- | src/vnet/interface_output.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/vnet/interface_output.c b/src/vnet/interface_output.c index 6a11f16918c..6de31dedb9c 100644 --- a/src/vnet/interface_output.c +++ b/src/vnet/interface_output.c @@ -1177,6 +1177,7 @@ pcap_drop_trace (vlib_main_t * vm, u32 bi0; i16 save_current_data; u16 save_current_length; + vlib_error_main_t *em = &vm->error_main; from = vlib_frame_vector_args (f); @@ -1222,6 +1223,59 @@ pcap_drop_trace (vlib_main_t * vm, else if (b0->current_data > 0) vlib_buffer_advance (b0, (word) - b0->current_data); + { + vlib_buffer_t *last = b0; + u32 error_node_index; + int drop_string_len; + vlib_node_t *n; + /* Length of the error string */ + int error_string_len = + clib_strnlen (em->error_strings_heap[b0->error], 128); + + /* Dig up the drop node */ + error_node_index = vm->node_main.node_by_error[b0->error]; + n = vlib_get_node (vm, error_node_index); + + /* Length of full drop string, w/ "nodename: " prepended */ + drop_string_len = error_string_len + vec_len (n->name) + 2; + + /* Find the last buffer in the chain */ + while (last->flags & VLIB_BUFFER_NEXT_PRESENT) + last = vlib_get_buffer (vm, last->next_buffer); + + /* + * Append <nodename>: <error-string> to the capture, + * only if we can do that without allocating a new buffer. + */ + if (PREDICT_TRUE ((last->current_data + last->current_length) + < (VLIB_BUFFER_DEFAULT_DATA_SIZE + - drop_string_len))) + { + clib_memcpy_fast (last->data + last->current_data + + last->current_length, n->name, + vec_len (n->name)); + clib_memcpy_fast (last->data + last->current_data + + last->current_length + vec_len (n->name), + ": ", 2); + clib_memcpy_fast (last->data + last->current_data + + last->current_length + vec_len (n->name) + + 2, em->error_strings_heap[b0->error], + error_string_len); + last->current_length += drop_string_len; + b0->flags &= ~(VLIB_BUFFER_TOTAL_LENGTH_VALID); + pcap_add_buffer (&pp->pcap_main, vm, bi0, + pp->max_bytes_per_pkt); + last->current_length -= drop_string_len; + b0->current_data = save_current_data; + b0->current_length = save_current_length; + continue; + } + } + + /* + * Didn't have space in the last buffer, here's the dropped + * packet as-is + */ pcap_add_buffer (&pp->pcap_main, vm, bi0, pp->max_bytes_per_pkt); b0->current_data = save_current_data; |