interface: fix issue that pcap rx/tx trace not available when there are worker threads
[vpp.git] / src / vnet / ethernet / node.c
index 87c447f..4640540 100755 (executable)
@@ -990,7 +990,7 @@ ethernet_input_trace (vlib_main_t * vm, vlib_node_runtime_t * node,
     }
 
   /* rx pcap capture if enabled */
-  if (PREDICT_FALSE (vm->pcap[VLIB_RX].pcap_enable))
+  if (PREDICT_FALSE (vlib_global_main.pcap[VLIB_RX].pcap_enable))
     {
       u32 bi0;
 
@@ -1003,11 +1003,12 @@ ethernet_input_trace (vlib_main_t * vm, vlib_node_runtime_t * node,
          from++;
          b0 = vlib_get_buffer (vm, bi0);
 
-         if (vm->pcap[VLIB_RX].pcap_sw_if_index == 0 ||
-             vm->pcap[VLIB_RX].pcap_sw_if_index
+         if (vlib_global_main.pcap[VLIB_RX].pcap_sw_if_index == 0 ||
+             vlib_global_main.pcap[VLIB_RX].pcap_sw_if_index
              == vnet_buffer (b0)->sw_if_index[VLIB_RX])
            {
-             pcap_add_buffer (&vm->pcap[VLIB_RX].pcap_main, vm, bi0, 512);
+             pcap_add_buffer (&vlib_global_main.pcap[VLIB_RX].pcap_main, vm,
+                              bi0, 512);
            }
          n_left--;
        }
@@ -2025,11 +2026,9 @@ next_by_ethertype_register (next_by_ethertype_t * l3_next,
   return 0;
 }
 
-
-static clib_error_t *
-ethernet_input_init (vlib_main_t * vm)
+void
+ethernet_input_init (vlib_main_t * vm, ethernet_main_t * em)
 {
-  ethernet_main_t *em = &ethernet_main;
   __attribute__ ((unused)) vlan_table_t *invalid_vlan_table;
   __attribute__ ((unused)) qinq_table_t *invalid_qinq_table;
 
@@ -2048,12 +2047,8 @@ ethernet_input_init (vlib_main_t * vm)
   pool_get (em->vlan_pool, invalid_vlan_table);        // first id = 0
   // The first qinq pool will always be reserved for an invalid table
   pool_get (em->qinq_pool, invalid_qinq_table);        // first id = 0
-
-  return 0;
 }
 
-VLIB_INIT_FUNCTION (ethernet_input_init);
-
 void
 ethernet_register_input_type (vlib_main_t * vm,
                              ethernet_type_t type, u32 node_index)
@@ -2069,6 +2064,11 @@ ethernet_register_input_type (vlib_main_t * vm,
   }
 
   ti = ethernet_get_type_info (em, type);
+  if (ti == 0)
+    {
+      clib_warning ("type_info NULL for type %d", type);
+      return;
+    }
   ti->node_index = node_index;
   ti->next_index = vlib_node_add_next (vm,
                                       ethernet_input_node.index, node_index);