dev: initial set of APIs
[vpp.git] / src / vnet / dev / config.c
index c98524c..8883e72 100644 (file)
@@ -41,6 +41,9 @@ vnet_dev_config_one_interface (vlib_main_t *vm, unformat_input_t *input,
       else if (unformat (input, "flags %U", unformat_vnet_dev_port_flags,
                         &args->flags))
        ;
+      else if (unformat (input, "args %U", unformat_single_quoted_string,
+                        &args->args))
+       ;
       else
        {
          err = clib_error_return (0, "unknown input '%U'",
@@ -50,7 +53,6 @@ vnet_dev_config_one_interface (vlib_main_t *vm, unformat_input_t *input,
     }
   return err;
 }
-
 static clib_error_t *
 vnet_dev_config_one_device (vlib_main_t *vm, unformat_input_t *input,
                            char *device_id)
@@ -71,6 +73,9 @@ vnet_dev_config_one_device (vlib_main_t *vm, unformat_input_t *input,
       else if (unformat (input, "flags %U", unformat_vnet_dev_flags,
                         &args.flags))
        ;
+      else if (unformat (input, "args %U", unformat_single_quoted_string,
+                        &args.args))
+       ;
       else if (unformat (input, "port %u %U", &n, unformat_vlib_cli_sub_input,
                         &sub_input))
        {
@@ -96,22 +101,22 @@ vnet_dev_config_one_device (vlib_main_t *vm, unformat_input_t *input,
 
       clib_memcpy (args.device_id, device_id, sizeof (args.device_id));
       rv = vnet_dev_api_attach (vm, &args);
+      vec_free (args.args);
 
       if (rv == VNET_DEV_OK)
        {
          vec_foreach (if_args, if_args_vec)
            {
-             clib_memcpy (if_args->device_id, device_id,
-                          sizeof (if_args->device_id));
+             if_args->dev_index = args.dev_index;
              rv = vnet_dev_api_create_port_if (vm, if_args);
              if (rv != VNET_DEV_OK)
                break;
            }
-
-         if (rv != VNET_DEV_OK)
-           err = clib_error_return (0, "error: %U for device '%s'",
-                                    format_vnet_dev_rv, rv, device_id);
        }
+
+      if (rv != VNET_DEV_OK)
+       err = clib_error_return (0, "error: %U for device '%s'",
+                                format_vnet_dev_rv, rv, device_id);
     }
 
   vec_free (if_args_vec);
@@ -132,7 +137,7 @@ dev_config_process_node_fn (vlib_main_t *vm, vlib_node_runtime_t *rt,
   unformat_init_vector (&input, dm->startup_config);
   dm->startup_config = 0;
 
-  while (unformat_check_input (&input) != UNFORMAT_END_OF_INPUT)
+  while (!err && unformat_check_input (&input) != UNFORMAT_END_OF_INPUT)
     {
       unformat_input_t sub_input;
       vnet_dev_device_id_t device_id;
@@ -142,19 +147,28 @@ dev_config_process_node_fn (vlib_main_t *vm, vlib_node_runtime_t *rt,
        {
          err = vnet_dev_config_one_device (vm, &sub_input, device_id);
          unformat_free (&sub_input);
-         if (err)
-           break;
        }
-      else
+      else if (unformat (&input, "dev %U", unformat_c_string_array, device_id,
+                        sizeof (device_id)))
        {
-         err = clib_error_return (0, "unknown input '%U'",
-                                  format_unformat_error, input);
-         break;
+         unformat_input_t no_input = {};
+         unformat_init_vector (&no_input, 0);
+         err = vnet_dev_config_one_device (vm, &no_input, device_id);
+         unformat_free (&no_input);
        }
+      else
+       err = clib_error_return (0, "unknown input '%U'",
+                                format_unformat_error, &input);
     }
 
   unformat_free (&input);
 
+  if (err)
+    {
+      log_err (0, "%U", format_clib_error, err);
+      clib_error_free (err);
+    }
+
   vlib_node_set_state (vm, rt->node_index, VLIB_NODE_STATE_DISABLED);
   vlib_node_rename (vm, rt->node_index, "deleted-%u", rt->node_index);
   vec_add1 (dm->free_process_node_indices, rt->node_index);