extend vlist code to allow keeping the old data structure instead of the new one...
[project/netifd.git] / device.c
index e206a76..6b333fb 100644 (file)
--- a/device.c
+++ b/device.c
@@ -7,6 +7,10 @@
 #include <sys/socket.h>
 #include <net/ethernet.h>
 
+#ifdef linux
+#include <netinet/ether.h>
+#endif
+
 #include "netifd.h"
 #include "system.h"
 #include "config.h"
@@ -179,7 +183,7 @@ void device_init_virtual(struct device *dev, const struct device_type *type, con
        if (name)
                strncpy(dev->ifname, name, IFNAMSIZ);
 
-       fprintf(stderr, "Initialize device '%s'\n", dev->ifname);
+       DPRINTF("Initialize device '%s'\n", dev->ifname);
        INIT_LIST_HEAD(&dev->users);
        dev->type = type;
 }
@@ -228,7 +232,7 @@ void device_cleanup(struct device *dev)
 {
        struct device_user *dep, *tmp;
 
-       fprintf(stderr, "Clean up device '%s'\n", dev->ifname);
+       DPRINTF("Clean up device '%s'\n", dev->ifname);
        list_for_each_entry_safe(dep, tmp, &dev->users, list) {
                if (!dep->cb)
                        continue;
@@ -261,6 +265,15 @@ void device_add_user(struct device_user *dep, struct device *dev)
        }
 }
 
+static void
+__device_free_unused(struct device *dev)
+{
+       if (!list_empty(&dev->users))
+               return;
+
+       device_free(dev);
+}
+
 void device_remove_user(struct device_user *dep)
 {
        struct device *dev = dep->dev;
@@ -269,22 +282,8 @@ void device_remove_user(struct device_user *dep)
                device_release(dep);
 
        list_del(&dep->list);
-
-       if (list_empty(&dev->users)) {
-               /* all references have gone away, remove this device */
-               device_free(dev);
-       }
-
        dep->dev = NULL;
-}
-
-static void
-__device_free_unused(struct device *dev)
-{
-       if (!list_empty(&dev->users))
-               return;
-
-       device_free(dev);
+       __device_free_unused(dev);
 }
 
 void