X-Git-Url: https://git.archive.openwrt.org/?p=project%2Fnetifd.git;a=blobdiff_plain;f=device.c;h=0efdba5c90d20e5abf76f90534c56a9e78dc4977;hp=f9cb05878cb38fd223af5fbe55829a3b20f0c93d;hb=cdc92e3fa1f188faecc0d97014866fe9a80d5570;hpb=5483940df7a35d052d195a2fa1db29763f795ad0 diff --git a/device.c b/device.c index f9cb058..0efdba5 100644 --- a/device.c +++ b/device.c @@ -40,15 +40,11 @@ static void broadcast_device_event(struct device *dev, enum device_event ev) static int set_device_state(struct device *dev, bool state) { - if (state) { - broadcast_device_event(dev, DEV_EVENT_SETUP); + if (state) system_if_up(dev); - broadcast_device_event(dev, DEV_EVENT_UP); - } else { - broadcast_device_event(dev, DEV_EVENT_TEARDOWN); + else system_if_down(dev); - broadcast_device_event(dev, DEV_EVENT_DOWN); - } + return 0; } @@ -60,8 +56,11 @@ int claim_device(struct device *dev) if (++dev->active != 1) return 0; + broadcast_device_event(dev, DEV_EVENT_SETUP); ret = dev->set_state(dev, true); - if (ret != 0) + if (ret == 0) + broadcast_device_event(dev, DEV_EVENT_UP); + else dev->active = 0; return ret; @@ -73,8 +72,12 @@ void release_device(struct device *dev) DPRINTF("release device %s, new refcount: %d\n", dev->ifname, dev->active); assert(dev->active >= 0); - if (!dev->active) - dev->set_state(dev, false); + if (dev->active) + return; + + broadcast_device_event(dev, DEV_EVENT_TEARDOWN); + dev->set_state(dev, false); + broadcast_device_event(dev, DEV_EVENT_DOWN); } int check_device_state(struct device *dev) @@ -90,12 +93,12 @@ void init_virtual_device(struct device *dev, const struct device_type *type, con assert(dev); assert(type); + if (name) + strncpy(dev->ifname, name, IFNAMSIZ); + fprintf(stderr, "Initialize interface '%s'\n", dev->ifname); INIT_LIST_HEAD(&dev->users); dev->type = type; - - if (name) - strncpy(dev->ifname, name, IFNAMSIZ); } int init_device(struct device *dev, const struct device_type *type, const char *ifname)