+/* Attempts to create a network device object of 'type' with 'name'. 'type'
+ * corresponds to the 'type' field used in the netdev_class * structure.
+ * Arguments for creation are provided in 'args', which may be empty or NULL
+ * if none are needed. */
+int
+netdev_create(const char *name, const char *type, const struct shash *args)
+{
+ struct shash empty_args = SHASH_INITIALIZER(&empty_args);
+ int i;
+
+ netdev_initialize();
+
+ if (!args) {
+ args = &empty_args;
+ }
+
+ if (shash_find(&netdev_obj_shash, name)) {
+ VLOG_WARN("attempted to create a netdev object with bound name: %s",
+ name);
+ return EEXIST;
+ }
+
+ for (i = 0; i < n_netdev_classes; i++) {
+ const struct netdev_class *class = netdev_classes[i];
+ if (!strcmp(type, class->type)) {
+ return class->create(name, type, args, true);
+ }
+ }
+
+ VLOG_WARN("could not create netdev object of unknown type: %s", type);
+
+ return EINVAL;
+}
+
+/* Destroys netdev object 'name'. Netdev objects maintain a reference count
+ * which is incremented on netdev_open() and decremented on netdev_close().
+ * If 'name' has a non-zero reference count, it will not destroy the object
+ * and return EBUSY. */
+int
+netdev_destroy(const char *name)
+{
+ struct shash_node *node;
+ struct netdev_obj *netdev_obj;
+
+ node = shash_find(&netdev_obj_shash, name);
+ if (!node) {
+ return ENODEV;
+ }
+
+ netdev_obj = node->data;
+ if (netdev_obj->ref_cnt != 0) {
+ VLOG_WARN("attempt to destroy open netdev object (%d): %s",
+ netdev_obj->ref_cnt, name);
+ return EBUSY;
+ }
+
+ shash_delete(&netdev_obj_shash, node);
+ netdev_obj->class->destroy(netdev_obj);
+
+ return 0;
+}
+
+/* Reconfigures the device object 'name' with 'args'. 'args' may be empty
+ * or NULL if none are needed. */
+int
+netdev_reconfigure(const char *name, const struct shash *args)
+{
+ struct shash empty_args = SHASH_INITIALIZER(&empty_args);
+ struct netdev_obj *netdev_obj;
+
+ if (!args) {
+ args = &empty_args;
+ }
+
+ netdev_obj = shash_find_data(&netdev_obj_shash, name);
+ if (!netdev_obj) {
+ return ENODEV;
+ }
+
+ if (netdev_obj->class->reconfigure) {
+ return netdev_obj->class->reconfigure(netdev_obj, args);
+ }
+
+ return 0;
+}
+