From 3a9fe0cb9fa812bdecdf0a6f2d5e81877fe8cd1b Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Tue, 5 Apr 2011 02:35:29 +0200 Subject: [PATCH] prevent autostart of interfaces during config init --- config.c | 5 +++++ interface.c | 13 ++++++++++++- interface.h | 2 ++ netifd.h | 1 + 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/config.c b/config.c index 66cee84..51e355c 100644 --- a/config.c +++ b/config.c @@ -6,6 +6,7 @@ #include "interface.h" struct uci_context *uci_ctx; +bool config_init = false; static void config_parse_interface(struct uci_section *s) { @@ -40,6 +41,7 @@ void config_init_interfaces(const char *name) return; } + config_init = true; uci_foreach_element(&p->sections, e) { struct uci_section *s = uci_to_section(e); @@ -49,4 +51,7 @@ void config_init_interfaces(const char *name) if (!strcmp(s->type, "interface")) config_parse_interface(s); } + config_init = false; + + start_pending_interfaces(); } diff --git a/interface.c b/interface.c index 823a06f..06a36ed 100644 --- a/interface.c +++ b/interface.c @@ -130,7 +130,7 @@ interface_cb(struct device_user *dep, enum device_event ev) iface->active = new_state; if (new_state) { - if (iface->autostart) + if (iface->autostart && !config_init) set_interface_up(iface); } else __set_interface_down(iface, true); @@ -277,3 +277,14 @@ set_interface_down(struct interface *iface) return 0; } + +void +start_pending_interfaces(void) +{ + struct interface *iface; + + list_for_each_entry(iface, &interfaces, list) { + if (iface->active && iface->autostart) + set_interface_up(iface); + } +} diff --git a/interface.h b/interface.h index 6bd8761..92bae5a 100644 --- a/interface.h +++ b/interface.h @@ -69,4 +69,6 @@ void interface_add_error(struct interface *iface, const char *subsystem, int interface_attach_bridge(struct interface *iface, struct uci_section *s); +void start_pending_interfaces(void); + #endif diff --git a/netifd.h b/netifd.h index 17b839b..160ea3b 100644 --- a/netifd.h +++ b/netifd.h @@ -23,6 +23,7 @@ struct device; struct interface; extern struct uci_context *uci_ctx; +extern bool config_init; void config_init_interfaces(const char *name); -- 2.11.0