bonding: memory leak on parsing bad CLI command
[vpp.git] / src / vnet / bonding / cli.c
index 9f9ac53..d20c686 100644 (file)
@@ -184,7 +184,7 @@ bond_dump_ifs (bond_interface_details_t ** out_bondifs)
   bond_interface_details_t *bondif = NULL;
 
   /* *INDENT-OFF* */
-  pool_foreach (bif, bm->interfaces,
+  pool_foreach (bif, bm->interfaces) {
     vec_add2(r_bondifs, bondif, 1);
     clib_memset (bondif, 0, sizeof (*bondif));
     bondif->id = bif->id;
@@ -200,7 +200,7 @@ bond_dump_ifs (bond_interface_details_t ** out_bondifs)
     bondif->numa_only = bif->numa_only;
     bondif->active_members = vec_len (bif->active_members);
     bondif->members = vec_len (bif->members);
-  );
+  }
   /* *INDENT-ON* */
 
   *out_bondifs = r_bondifs;
@@ -376,11 +376,11 @@ 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;
   bond_if_t *bif;
-  vnet_hw_interface_t *hw;
 
   if ((args->mode == BOND_MODE_LACP) && bm->lacp_plugin_loaded == 0)
     {
@@ -440,32 +440,26 @@ 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;
   bif->group = bif->sw_if_index;
   bif->numa_only = args->numa_only;
 
-  hw = vnet_get_hw_interface (vnm, bif->hw_if_index);
   /*
    * Add GSO and Checksum offload flags if GSO is enabled on Bond
    */
   if (args->gso)
     {
-      hw->flags |= (VNET_HW_INTERFACE_FLAG_SUPPORTS_GSO |
-                   VNET_HW_INTERFACE_FLAG_SUPPORTS_TX_L4_CKSUM_OFFLOAD);
+      vnet_hw_if_set_caps (vnm, bif->hw_if_index,
+                          VNET_HW_IF_CAP_TCP_GSO |
+                            VNET_HW_IF_CAP_TX_TCP_CKSUM |
+                            VNET_HW_IF_CAP_TX_UDP_CKSUM);
     }
   if (vlib_get_thread_main ()->n_vlib_mains > 1)
     clib_spinlock_init (&bif->lockp);
@@ -516,12 +510,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);
 
@@ -631,7 +631,7 @@ bond_add_member (vlib_main_t * vm, bond_add_member_args_t * args)
        clib_error_return (0, "bond interface cannot be added as member");
       return;
     }
-  if (bif->gso && !(mif_hw->flags & VNET_HW_INTERFACE_FLAG_SUPPORTS_GSO))
+  if (bif->gso && !(mif_hw->caps & VNET_HW_IF_CAP_TCP_GSO))
     {
       args->rv = VNET_API_ERROR_INVALID_INTERFACE;
       args->error =
@@ -899,14 +899,14 @@ show_bond (vlib_main_t * vm)
                   "load balance", "active members", "members");
 
   /* *INDENT-OFF* */
-  pool_foreach (bif, bm->interfaces,
-  ({
+  pool_foreach (bif, bm->interfaces)
+   {
     vlib_cli_output (vm, "%-16U %-12d %-13U %-13U %-14u %u",
                     format_bond_interface_name, bif->dev_instance,
                     bif->sw_if_index, format_bond_mode, bif->mode,
                     format_bond_load_balance, bif->lb,
                     vec_len (bif->active_members), vec_len (bif->members));
-  }));
+  }
   /* *INDENT-ON* */
 }
 
@@ -918,8 +918,8 @@ show_bond_details (vlib_main_t * vm)
   u32 *sw_if_index;
 
   /* *INDENT-OFF* */
-  pool_foreach (bif, bm->interfaces,
-  ({
+  pool_foreach (bif, bm->interfaces)
+   {
     vlib_cli_output (vm, "%U", format_bond_interface_name, bif->dev_instance);
     vlib_cli_output (vm, "  mode: %U",
                     format_bond_mode, bif->mode);
@@ -955,7 +955,7 @@ show_bond_details (vlib_main_t * vm)
     vlib_cli_output (vm, "  interface id: %d", bif->id);
     vlib_cli_output (vm, "  sw_if_index: %d", bif->sw_if_index);
     vlib_cli_output (vm, "  hw_if_index: %d", bif->hw_if_index);
-  }));
+  }
   /* *INDENT-ON* */
 }