avoid using thread local storage for thread index
[vpp.git] / src / vnet / bonding / device.c
index 8ddec80..53123dd 100644 (file)
@@ -23,6 +23,8 @@
 #include <vnet/ip/ip6_hop_by_hop_packet.h>
 #include <vnet/bonding/node.h>
 #include <vppinfra/lb_hash_hash.h>
+#include <vnet/ip/ip.h>
+#include <vnet/ethernet/arp_packet.h>
 
 #define foreach_bond_tx_error     \
   _(NONE, "no error")             \
@@ -138,7 +140,7 @@ bond_load_balance_broadcast (vlib_main_t * vm, vlib_node_runtime_t * node,
   u32 *to_next = 0;
   u32 sw_if_index;
   vlib_frame_t *f;
-  u16 thread_index = vlib_get_thread_index ();
+  u16 thread_index = vm->thread_index;
 
   for (port = 1; port < slave_count; port++)
     {
@@ -401,7 +403,7 @@ bond_tx_fn (vlib_main_t * vm, vlib_node_runtime_t * node,
   u32 sw_if_index, sw_if_index1, sw_if_index2, sw_if_index3;
   bond_packet_trace_t *t0;
   uword n_trace = vlib_get_trace_count (vm, node);
-  u16 thread_index = vlib_get_thread_index ();
+  u16 thread_index = vm->thread_index;
   vnet_main_t *vnm = vnet_get_main ();
   u32 *to_next;
   u32 sif_if_index, sif_if_index1, sif_if_index2, sif_if_index3;
@@ -700,6 +702,52 @@ bond_tx_fn (vlib_main_t * vm, vlib_node_runtime_t * node,
   return frame->n_vectors;
 }
 
+static walk_rc_t
+bond_active_interface_switch_cb (vnet_main_t * vnm, u32 sw_if_index,
+                                void *arg)
+{
+  bond_main_t *bm = &bond_main;
+
+  send_ip4_garp (bm->vlib_main, sw_if_index);
+  send_ip6_na (bm->vlib_main, sw_if_index);
+
+  return (WALK_CONTINUE);
+}
+
+static uword
+bond_process (vlib_main_t * vm, vlib_node_runtime_t * rt, vlib_frame_t * f)
+{
+  vnet_main_t *vnm = vnet_get_main ();
+  uword event_type, *event_data = 0;
+
+  while (1)
+    {
+      u32 i;
+      u32 hw_if_index;
+
+      vlib_process_wait_for_event (vm);
+      event_type = vlib_process_get_events (vm, &event_data);
+      ASSERT (event_type == BOND_SEND_GARP_NA);
+      for (i = 0; i < vec_len (event_data); i++)
+       {
+         hw_if_index = event_data[i];
+         /* walk hw interface to process all subinterfaces */
+         vnet_hw_interface_walk_sw (vnm, hw_if_index,
+                                    bond_active_interface_switch_cb, 0);
+       }
+      vec_reset_length (event_data);
+    }
+  return 0;
+}
+
+/* *INDENT-OFF* */
+VLIB_REGISTER_NODE (bond_process_node) = {
+  .function = bond_process,
+  .type = VLIB_NODE_TYPE_PROCESS,
+  .name = "bond-process",
+};
+/* *INDENT-ON* */
+
 /* *INDENT-OFF* */
 VNET_DEVICE_CLASS (bond_dev_class) = {
   .name = "bond",