system-linux: fix a glob related memleak
[project/netifd.git] / device.c
index 6a770ac..b29d73b 100644 (file)
--- a/device.c
+++ b/device.c
@@ -37,6 +37,8 @@ static const struct blobmsg_policy dev_attrs[__DEV_ATTR_MAX] = {
        [DEV_ATTR_MACADDR] = { .name = "macaddr", .type = BLOBMSG_TYPE_STRING },
        [DEV_ATTR_TXQUEUELEN] = { .name = "txqueuelen", .type = BLOBMSG_TYPE_INT32 },
        [DEV_ATTR_ENABLED] = { .name = "enabled", .type = BLOBMSG_TYPE_BOOL },
+       [DEV_ATTR_IPV6] = { .name = "ipv6", .type = BLOBMSG_TYPE_BOOL },
+       [DEV_ATTR_PROMISC] = { .name = "promisc", .type = BLOBMSG_TYPE_BOOL },
 };
 
 const struct uci_blob_param_list device_attr_list = {
@@ -60,6 +62,9 @@ void device_unlock(void)
 
 static int set_device_state(struct device *dev, bool state)
 {
+       if (dev->external)
+               return 0;
+
        if (state)
                system_if_up(dev);
        else
@@ -139,6 +144,8 @@ device_merge_settings(struct device *dev, struct device_settings *n)
        memcpy(n->macaddr,
                (s->flags & DEV_OPT_MACADDR ? s->macaddr : os->macaddr),
                sizeof(n->macaddr));
+       n->ipv6 = s->flags & DEV_OPT_IPV6 ? s->ipv6 : os->ipv6;
+       n->promisc = s->flags & DEV_OPT_PROMISC ? s->promisc : os->promisc;
        n->flags = s->flags | os->flags;
 }
 
@@ -172,6 +179,16 @@ device_init_settings(struct device *dev, struct blob_attr **tb)
                }
        }
 
+       if ((cur = tb[DEV_ATTR_IPV6])) {
+               s->ipv6 = blobmsg_get_bool(cur);
+               s->flags |= DEV_OPT_IPV6;
+       }
+
+       if ((cur = tb[DEV_ATTR_PROMISC])) {
+               s->promisc = blobmsg_get_bool(cur);
+               s->flags |= DEV_OPT_PROMISC;
+       }
+
        device_set_disabled(dev, disabled);
 }
 
@@ -244,7 +261,7 @@ void device_release(struct device_user *dep)
                return;
 
        device_broadcast_event(dev, DEV_EVENT_TEARDOWN);
-       if (!dep->hotplug)
+       if (!dev->external)
                dev->set_state(dev, false);
        device_broadcast_event(dev, DEV_EVENT_DOWN);
 }
@@ -252,7 +269,7 @@ void device_release(struct device_user *dep)
 int device_check_state(struct device *dev)
 {
        if (!dev->type->check_state)
-               return 0;
+               return simple_device_type.check_state(dev);
 
        return dev->type->check_state(dev);
 }
@@ -623,7 +640,7 @@ device_create(const char *name, const struct device_type *type,
                odev->current_config = true;
                change = device_set_config(odev, type, config);
                if (odev->external) {
-                       system_if_apply_settings(odev, &odev->settings);
+                       system_if_apply_settings(odev, &odev->settings, odev->settings.flags);
                        change = DEV_CONFIG_APPLIED;
                }
                switch (change) {
@@ -705,6 +722,10 @@ device_dump_status(struct blob_buf *b, struct device *dev)
                        blobmsg_add_string(b, "macaddr", format_macaddr(st.macaddr));
                if (st.flags & DEV_OPT_TXQUEUELEN)
                        blobmsg_add_u32(b, "txqueuelen", st.txqueuelen);
+               if (st.flags & DEV_OPT_IPV6)
+                       blobmsg_add_u8(b, "ipv6", st.ipv6);
+               if (st.flags & DEV_OPT_PROMISC)
+                       blobmsg_add_u8(b, "promisc", st.promisc);
        }
 
        s = blobmsg_open_table(b, "statistics");