From: Felix Fietkau Date: Thu, 20 Oct 2011 17:20:43 +0000 (+0200) Subject: do not clear device state for devices created by proto-up with address-external set X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=fb0e4138070d7c2ce723af5780e763af3a1353d8;p=oweals%2Fnetifd.git do not clear device state for devices created by proto-up with address-external set --- diff --git a/device.c b/device.c index 717993a..428d001 100644 --- a/device.c +++ b/device.c @@ -308,12 +308,13 @@ int device_init(struct device *dev, const struct device_type *type, const char * } static struct device * -device_create_default(const char *name) +device_create_default(const char *name, bool external) { struct device *dev; D(DEVICE, "Create simple device '%s'\n", name); dev = calloc(1, sizeof(*dev)); + dev->external = external; device_init(dev, &simple_device_type, name); dev->default_config = true; return dev; @@ -332,7 +333,7 @@ device_alias_get(const char *name) } struct device * -device_get(const char *name, bool create) +device_get(const char *name, int create) { struct device *dev; @@ -349,7 +350,7 @@ device_get(const char *name, bool create) if (!create) return NULL; - return device_create_default(name); + return device_create_default(name, create > 1); } static void @@ -527,7 +528,7 @@ device_reset_old(void) if (dev->type != &simple_device_type) continue; - ndev = device_create_default(dev->ifname); + ndev = device_create_default(dev->ifname, dev->external); device_replace(ndev, dev); } } diff --git a/device.h b/device.h index 3d233d7..057506b 100644 --- a/device.h +++ b/device.h @@ -62,6 +62,7 @@ struct device { bool config_pending; bool present; int active; + bool external; bool current_config; bool default_config; @@ -133,7 +134,7 @@ 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); -struct device *device_get(const char *name, bool create); +struct device *device_get(const char *name, int create); void device_add_user(struct device_user *dep, struct device *iface); void device_remove_user(struct device_user *dep); diff --git a/proto-shell.c b/proto-shell.c index 9ad28ac..a22c0e3 100644 --- a/proto-shell.c +++ b/proto-shell.c @@ -242,6 +242,7 @@ proto_shell_update_link(struct proto_shell_state *state, struct blob_attr **tb) { struct interface_ip_settings *ip; struct blob_attr *cur; + int dev_create = 1; bool addr_ext = false; bool up; @@ -254,6 +255,12 @@ proto_shell_update_link(struct proto_shell_state *state, struct blob_attr **tb) return 0; } + if ((cur = tb[NOTIFY_ADDR_EXT]) != NULL) { + addr_ext = blobmsg_get_bool(cur); + if (addr_ext) + dev_create = 2; + } + if (!tb[NOTIFY_IFNAME]) { if (!state->proto.iface->main_dev.dev) return UBUS_STATUS_INVALID_ARGUMENT; @@ -262,7 +269,7 @@ proto_shell_update_link(struct proto_shell_state *state, struct blob_attr **tb) device_remove_user(&state->l3_dev); device_add_user(&state->l3_dev, - device_get(blobmsg_data(tb[NOTIFY_IFNAME]), true)); + device_get(blobmsg_data(tb[NOTIFY_IFNAME]), dev_create)); state->proto.iface->l3_dev = &state->l3_dev; device_claim(&state->l3_dev); } @@ -270,9 +277,6 @@ proto_shell_update_link(struct proto_shell_state *state, struct blob_attr **tb) ip = &state->proto.iface->proto_ip; interface_update_start(state->proto.iface); - if ((cur = tb[NOTIFY_ADDR_EXT]) != NULL) - addr_ext = blobmsg_get_bool(cur); - if ((cur = tb[NOTIFY_IPADDR]) != NULL) proto_shell_parse_addr_list(ip, cur, false, addr_ext); diff --git a/system-linux.c b/system-linux.c index 2a85b28..44332a2 100644 --- a/system-linux.c +++ b/system-linux.c @@ -370,6 +370,9 @@ void system_if_clear_state(struct device *dev) char buf[256]; char *bridge; + if (dev->external) + return; + dev->ifindex = system_if_resolve(dev); if (!dev->ifindex) return;