bonding: refactor bonding hash functions to vnet/hash
[vpp.git] / src / vnet / bonding / cli.c
index 2045ff4..c3593ab 100644 (file)
@@ -376,6 +376,7 @@ bond_delete_if (vlib_main_t * vm, u32 sw_if_index)
 void
 bond_create_if (vlib_main_t * vm, bond_create_if_args_t * args)
 {
+  vnet_eth_interface_registration_t eir = {};
   bond_main_t *bm = &bond_main;
   vnet_main_t *vnm = vnet_get_main ();
   vnet_sw_interface_t *sw;
@@ -407,6 +408,16 @@ bond_create_if (vlib_main_t * vm, bond_create_if_args_t * args)
   bif->mode = args->mode;
   bif->gso = args->gso;
 
+  if (bif->lb == BOND_LB_L2)
+    bif->hash_func =
+      vnet_hash_function_from_name ("hash-eth-l2", VNET_HASH_FN_TYPE_ETHERNET);
+  else if (bif->lb == BOND_LB_L34)
+    bif->hash_func = vnet_hash_function_from_name ("hash-eth-l34",
+                                                  VNET_HASH_FN_TYPE_ETHERNET);
+  else if (bif->lb == BOND_LB_L23)
+    bif->hash_func = vnet_hash_function_from_name ("hash-eth-l23",
+                                                  VNET_HASH_FN_TYPE_ETHERNET);
+
   // Adjust requested interface id
   if (bif->id == ~0)
     bif->id = bif->dev_instance;
@@ -439,18 +450,11 @@ bond_create_if (vlib_main_t * vm, bond_create_if_args_t * args)
       args->hw_addr[1] = 0xfe;
     }
   memcpy (bif->hw_address, args->hw_addr, 6);
-  args->error = ethernet_register_interface
-    (vnm, bond_dev_class.index, bif->dev_instance /* device instance */ ,
-     bif->hw_address /* ethernet address */ ,
-     &bif->hw_if_index, 0 /* flag change */ );
 
-  if (args->error)
-    {
-      args->rv = VNET_API_ERROR_INVALID_REGISTRATION;
-      hash_unset (bm->id_used, bif->id);
-      pool_put (bm->interfaces, bif);
-      return;
-    }
+  eir.dev_class_index = bond_dev_class.index;
+  eir.dev_instance = bif->dev_instance;
+  eir.address = bif->hw_address;
+  bif->hw_if_index = vnet_eth_register_interface (vnm, &eir);
 
   sw = vnet_get_hw_sw_interface (vnm, bif->hw_if_index);
   bif->sw_if_index = sw->sw_if_index;
@@ -516,12 +520,18 @@ bond_create_command_fn (vlib_main_t * vm, unformat_input_t * input,
          if (args.mode == BOND_MODE_LACP)
            args.numa_only = 1;
          else
-           return clib_error_return (0,
-                                     "Only lacp mode supports numa-only so far!");
+           {
+             unformat_free (line_input);
+             return clib_error_return (
+               0, "Only lacp mode supports numa-only so far!");
+           }
        }
       else
-       return clib_error_return (0, "unknown input `%U'",
-                                 format_unformat_error, input);
+       {
+         unformat_free (line_input);
+         return clib_error_return (0, "unknown input `%U'",
+                                   format_unformat_error, input);
+       }
     }
   unformat_free (line_input);