interface: callback to manage extra MAC addresses
[vpp.git] / src / vnet / interface_output.c
index 8eb2e67..707b116 100644 (file)
@@ -802,7 +802,6 @@ static_always_inline void vnet_interface_pcap_tx_trace
 {
   u32 n_left_from, *from;
   u32 sw_if_index;
-  vnet_main_t *vnm;
   vnet_pcap_t *pp = &vlib_global_main.pcap;
 
   if (PREDICT_TRUE (pp->pcap_tx_enable == 0))
@@ -816,7 +815,6 @@ static_always_inline void vnet_interface_pcap_tx_trace
   else
     sw_if_index = ~0;
 
-  vnm = vnet_get_main ();
   n_left_from = frame->n_vectors;
   from = vlib_frame_vector_args (frame);
 
@@ -828,12 +826,11 @@ static_always_inline void vnet_interface_pcap_tx_trace
       from++;
       n_left_from--;
 
-      if (vec_len (vnm->classify_filter_table_indices))
+      if (pp->filter_classify_table_index != ~0)
        {
          classify_filter_result =
            vnet_is_packet_traced_inline
-           (b0, vnm->classify_filter_table_indices[0],
-            0 /* full classify */ );
+           (b0, pp->filter_classify_table_index, 0 /* full classify */ );
          if (classify_filter_result)
            pcap_add_buffer (&pp->pcap_main, vm, bi0, pp->max_bytes_per_pkt);
          continue;
@@ -1177,6 +1174,9 @@ 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;
+  int do_trace = 0;
+
 
   from = vlib_frame_vector_args (f);
 
@@ -1198,9 +1198,18 @@ pcap_drop_trace (vlib_main_t * vm,
          && hash_get (im->pcap_drop_filter_hash, b0->error))
        continue;
 
+      do_trace = (pp->pcap_sw_if_index == 0) ||
+       pp->pcap_sw_if_index == vnet_buffer (b0)->sw_if_index[VLIB_RX];
+
+      if (PREDICT_FALSE
+         (do_trace == 0 && pp->filter_classify_table_index != ~0))
+       {
+         do_trace = vnet_is_packet_traced_inline
+           (b0, pp->filter_classify_table_index, 0 /* full classify */ );
+       }
+
       /* Trace all drops, or drops received on a specific interface */
-      if (pp->pcap_sw_if_index == 0 ||
-         pp->pcap_sw_if_index == vnet_buffer (b0)->sw_if_index[VLIB_RX])
+      if (do_trace)
        {
          save_current_data = b0->current_data;
          save_current_length = b0->current_length;
@@ -1222,6 +1231,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;