+/* Initializes 'netdev_dev' as a netdev device named 'name' of the
+ * specified 'class'.
+ *
+ * This function adds 'netdev_dev' to a netdev-owned shash, so it is
+ * very important that 'netdev_dev' only be freed after calling
+ * the refcount drops to zero. */
+void
+netdev_dev_init(struct netdev_dev *netdev_dev, const char *name,
+ const struct netdev_class *class)
+{
+ assert(!shash_find(&netdev_dev_shash, name));
+
+ netdev_dev->class = class;
+ netdev_dev->ref_cnt = 0;
+ netdev_dev->name = xstrdup(name);
+ netdev_dev->node = shash_add(&netdev_dev_shash, name, netdev_dev);
+}
+
+/* Undoes the results of initialization.
+ *
+ * Normally this function does not need to be called as netdev_close has
+ * the same effect when the refcount drops to zero.
+ * However, it may be called by providers due to an error on creation
+ * that occurs after initialization. It this case netdev_close() would
+ * never be called. */
+void
+netdev_dev_uninit(struct netdev_dev *netdev_dev, bool destroy)
+{
+ char *name = netdev_dev->name;
+
+ assert(!netdev_dev->ref_cnt);
+
+ shash_delete(&netdev_dev_shash, netdev_dev->node);
+
+ if (destroy) {
+ netdev_dev->class->destroy(netdev_dev);
+ }
+ free(name);
+}
+
+/* Returns the class type of 'netdev_dev'.
+ *
+ * The caller must not free the returned value. */
+const char *
+netdev_dev_get_type(const struct netdev_dev *netdev_dev)
+{
+ return netdev_dev->class->type;
+}
+
+/* Returns the name of 'netdev_dev'.
+ *
+ * The caller must not free the returned value. */
+const char *
+netdev_dev_get_name(const struct netdev_dev *netdev_dev)
+{
+ return netdev_dev->name;
+}
+
+/* Initializes 'netdev' as a instance of the netdev_dev.