vcl: add read/write udp support
[vpp.git] / src / vnet / bonding / cli.c
index 1768912..91c6e2c 100644 (file)
 void
 bond_disable_collecting_distributing (vlib_main_t * vm, slave_if_t * sif)
 {
+  bond_main_t *bm = &bond_main;
   bond_if_t *bif;
   int i;
   uword p;
+  u8 switching_active = 0;
 
   bif = bond_get_master_by_dev_instance (sif->bif_dev_instance);
   clib_spinlock_lock_if_init (&bif->lockp);
@@ -35,8 +37,18 @@ bond_disable_collecting_distributing (vlib_main_t * vm, slave_if_t * sif)
     p = *vec_elt_at_index (bif->active_slaves, i);
     if (p == sif->sw_if_index)
       {
+       /* Are we disabling the very 1st slave? */
+       if (sif->sw_if_index == *vec_elt_at_index (bif->active_slaves, 0))
+         switching_active = 1;
+
        vec_del1 (bif->active_slaves, i);
        hash_unset (bif->active_slave_by_sw_if_index, sif->sw_if_index);
+
+       /* We got a new slave just becoming active? */
+       if ((vec_len (bif->active_slaves) >= 1) &&
+           (bif->mode == BOND_MODE_ACTIVE_BACKUP) && switching_active)
+         vlib_process_signal_event (bm->vlib_main, bond_process_node.index,
+                                    BOND_SEND_GARP_NA, bif->hw_if_index);
        break;
       }
   }
@@ -47,6 +59,7 @@ void
 bond_enable_collecting_distributing (vlib_main_t * vm, slave_if_t * sif)
 {
   bond_if_t *bif;
+  bond_main_t *bm = &bond_main;
 
   bif = bond_get_master_by_dev_instance (sif->bif_dev_instance);
   clib_spinlock_lock_if_init (&bif->lockp);
@@ -55,6 +68,12 @@ bond_enable_collecting_distributing (vlib_main_t * vm, slave_if_t * sif)
       hash_set (bif->active_slave_by_sw_if_index, sif->sw_if_index,
                sif->sw_if_index);
       vec_add1 (bif->active_slaves, sif->sw_if_index);
+
+      /* First slave becomes active? */
+      if ((vec_len (bif->active_slaves) == 1) &&
+         (bif->mode == BOND_MODE_ACTIVE_BACKUP))
+       vlib_process_signal_event (bm->vlib_main, bond_process_node.index,
+                                  BOND_SEND_GARP_NA, bif->hw_if_index);
     }
   clib_spinlock_unlock_if_init (&bif->lockp);
 }
@@ -135,12 +154,14 @@ bond_delete_neighbor (vlib_main_t * vm, bond_if_t * bif, slave_if_t * sif)
   bond_main_t *bm = &bond_main;
   vnet_main_t *vnm = vnet_get_main ();
   int i;
-  vnet_hw_interface_t *hw;
+  vnet_hw_interface_t *sif_hw;
+
+  sif_hw = vnet_get_sup_hw_interface (vnm, sif->sw_if_index);
 
   bif->port_number_bitmap =
     clib_bitmap_set (bif->port_number_bitmap,
                     ntohs (sif->actor_admin.port_number) - 1, 0);
-  hash_unset (bm->neighbor_by_sw_if_index, sif->sw_if_index);
+  bm->slave_by_sw_if_index[sif->sw_if_index] = 0;
   vec_free (sif->last_marker_pkt);
   vec_free (sif->last_rx_pkt);
   vec_foreach_index (i, bif->slaves)
@@ -156,8 +177,7 @@ bond_delete_neighbor (vlib_main_t * vm, bond_if_t * bif, slave_if_t * sif)
   bond_disable_collecting_distributing (vm, sif);
 
   /* Put back the old mac */
-  hw = vnet_get_sup_hw_interface (vnm, sif->sw_if_index);
-  vnet_hw_interface_change_mac_address (vnm, hw->hw_if_index,
+  vnet_hw_interface_change_mac_address (vnm, sif_hw->hw_if_index,
                                        sif->persistent_hw_address);
 
   pool_put (bm->neighbors, sif);
@@ -406,7 +426,7 @@ bond_enslave (vlib_main_t * vm, bond_enslave_args_t * args)
   bond_if_t *bif;
   slave_if_t *sif;
   vnet_interface_main_t *im = &vnm->interface_main;
-  vnet_hw_interface_t *hw, *hw2;
+  vnet_hw_interface_t *bif_hw, *sif_hw;
   vnet_sw_interface_t *sw;
 
   bif = bond_get_master_by_sw_if_index (args->group);
@@ -423,8 +443,8 @@ bond_enslave (vlib_main_t * vm, bond_enslave_args_t * args)
       args->error = clib_error_return (0, "interface was already enslaved");
       return;
     }
-  hw = vnet_get_sup_hw_interface (vnm, args->slave);
-  if (hw->dev_class_index == bond_dev_class.index)
+  sif_hw = vnet_get_sup_hw_interface (vnm, args->slave);
+  if (sif_hw->dev_class_index == bond_dev_class.index)
     {
       args->rv = VNET_API_ERROR_INVALID_INTERFACE;
       args->error =
@@ -450,16 +470,25 @@ bond_enslave (vlib_main_t * vm, bond_enslave_args_t * args)
   else
     sif->ttl_in_seconds = LACP_SHORT_TIMOUT_TIME;
 
-  hash_set (bm->neighbor_by_sw_if_index, sif->sw_if_index,
-           sif - bm->neighbors);
+  vec_validate_aligned (bm->slave_by_sw_if_index, sif->sw_if_index,
+                       CLIB_CACHE_LINE_BYTES);
+  /*
+   * sif - bm->neighbors may be 0
+   * Left shift it by 1 bit to distinguish the valid entry that we actually
+   * store from the null entries
+   */
+  bm->slave_by_sw_if_index[sif->sw_if_index] =
+    (uword) (((sif - bm->neighbors) << 1) | 1);
   vec_add1 (bif->slaves, sif->sw_if_index);
 
-  hw = vnet_get_sup_hw_interface (vnm, sif->sw_if_index);
+  sif_hw = vnet_get_sup_hw_interface (vnm, sif->sw_if_index);
+
   /* Save the old mac */
-  memcpy (sif->persistent_hw_address, hw->hw_address, 6);
+  memcpy (sif->persistent_hw_address, sif_hw->hw_address, 6);
+  bif_hw = vnet_get_sup_hw_interface (vnm, bif->sw_if_index);
   if (bif->use_custom_mac)
     {
-      vnet_hw_interface_change_mac_address (vnm, hw->hw_if_index,
+      vnet_hw_interface_change_mac_address (vnm, sif_hw->hw_if_index,
                                            bif->hw_address);
     }
   else
@@ -467,19 +496,26 @@ bond_enslave (vlib_main_t * vm, bond_enslave_args_t * args)
       // bond interface gets the mac address from the first slave
       if (vec_len (bif->slaves) == 1)
        {
-         memcpy (bif->hw_address, hw->hw_address, 6);
-         hw2 = vnet_get_sup_hw_interface (vnm, bif->sw_if_index);
-         vnet_hw_interface_change_mac_address (vnm, hw2->hw_if_index,
-                                               hw->hw_address);
+         memcpy (bif->hw_address, sif_hw->hw_address, 6);
+         vnet_hw_interface_change_mac_address (vnm, bif_hw->hw_if_index,
+                                               sif_hw->hw_address);
        }
       else
        {
          // subsequent slaves gets the mac address of the bond interface
-         vnet_hw_interface_change_mac_address (vnm, hw->hw_if_index,
+         vnet_hw_interface_change_mac_address (vnm, sif_hw->hw_if_index,
                                                bif->hw_address);
        }
     }
 
+  if (bif_hw->l2_if_count)
+    {
+      ethernet_set_flags (vnm, sif_hw->hw_if_index,
+                         ETHERNET_INTERFACE_FLAG_ACCEPT_ALL);
+      /* ensure all packets go to ethernet-input */
+      ethernet_set_rx_redirect (vnm, sif_hw, 1);
+    }
+
   if ((bif->mode == BOND_MODE_LACP) && bm->lacp_enable_disable)
     {
       (*bm->lacp_enable_disable) (vm, bif, sif, 1);
@@ -490,7 +526,7 @@ bond_enslave (vlib_main_t * vm, bond_enslave_args_t * args)
     }
 
   args->rv = vnet_feature_enable_disable ("device-input", "bond-input",
-                                         hw->hw_if_index, 1, 0, 0);
+                                         sif_hw->hw_if_index, 1, 0, 0);
 
   if (args->rv)
     {
@@ -716,7 +752,7 @@ bond_cli_init (vlib_main_t * vm)
 
   bm->vlib_main = vm;
   bm->vnet_main = vnet_get_main ();
-  bm->neighbor_by_sw_if_index = hash_create (0, sizeof (uword));
+  vec_validate_aligned (bm->slave_by_sw_if_index, 1, CLIB_CACHE_LINE_BYTES);
 
   return 0;
 }