return 0;
}
-struct device *device_get(const char *name, bool create)
+static struct device *
+device_create_default(const char *name)
+{
+ struct device *dev;
+
+ D(DEVICE, "Create simple device '%s'\n", name);
+ dev = calloc(1, sizeof(*dev));
+ device_init(dev, &simple_device_type, name);
+ dev->default_config = true;
+ return dev;
+}
+
+struct device *
+device_get(const char *name, bool create)
{
struct device *dev;
if (!create)
return NULL;
- D(DEVICE, "Create simple device '%s'\n", name);
- dev = calloc(1, sizeof(*dev));
- device_init(dev, &simple_device_type, name);
-
- return dev;
+ return device_create_default(name);
}
static void
static void
__device_free_unused(struct device *dev)
{
- if (!list_empty(&dev->users))
+ if (!list_empty(&dev->users) || dev->current_config)
return;
device_free(dev);
device_set_present(dev, true);
}
+void
+device_reset_config(void)
+{
+ struct device *dev;
+
+ avl_for_each_element(&devices, dev, avl)
+ dev->current_config = false;
+}
+
+void
+device_reset_old(void)
+{
+ struct device *dev, *tmp, *ndev;
+
+ avl_for_each_element_safe(&devices, dev, avl, tmp) {
+ if (dev->current_config || dev->default_config)
+ continue;
+
+ if (dev->type != &simple_device_type)
+ continue;
+
+ ndev = device_create_default(dev->ifname);
+ device_replace(ndev, dev);
+ }
+}
+
struct device *
device_create(const char *name, const struct device_type *type,
struct blob_attr *config)
odev = device_get(name, false);
if (odev) {
+ odev->current_config = true;
change = device_check_config(odev, type, config);
switch (change) {
case DEV_CONFIG_APPLIED:
if (!dev)
return NULL;
+ dev->current_config = true;
dev->config = config;
if (odev)
device_replace(dev, odev);
bool present;
int active;
+ bool current_config;
+ bool default_config;
+
/* set interface up or down */
device_state_cb set_state;
void device_init_settings(struct device *dev, struct blob_attr **tb);
void device_init_pending(void);
+void device_reset_config(void);
+void device_reset_old(void);
+
void device_init_virtual(struct device *dev, const struct device_type *type, const char *name);
int device_init(struct device *iface, const struct device_type *type, const char *ifname);
void device_cleanup(struct device *iface);