From f876254b373a883499a3b15733e26c777d6f3665 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Tue, 18 Oct 2011 17:06:17 +0200 Subject: [PATCH 1/1] add interface users (similar to device users) --- interface.c | 27 +++++++++++++++++++++++++++ interface.h | 11 +++++++++++ 2 files changed, 38 insertions(+) diff --git a/interface.c b/interface.c index 9d6a7c1..0a2afd0 100644 --- a/interface.c +++ b/interface.c @@ -79,6 +79,11 @@ void interface_add_error(struct interface *iface, const char *subsystem, static void interface_event(struct interface *iface, enum interface_event ev) { + struct interface_user *dep, *tmp; + + list_for_each_entry_safe(dep, tmp, &iface->users, list) + dep->cb(dep, IFEV_UP); + interface_queue_event(iface, ev); } @@ -168,6 +173,22 @@ interface_set_available(struct interface *iface, bool new_state) __interface_set_down(iface, true); } +void +interface_add_user(struct interface_user *dep, struct interface *iface) +{ + dep->iface = iface; + list_add(&dep->list, &iface->users); + if (iface->state == IFS_UP) + dep->cb(dep, IFEV_UP); +} + +void +interface_remove_user(struct interface_user *dep) +{ + list_del_init(&dep->list); + dep->iface = NULL; +} + static void interface_claim_device(struct interface *iface) { @@ -185,6 +206,11 @@ interface_claim_device(struct interface *iface) static void interface_cleanup(struct interface *iface) { + struct interface_user *dep, *tmp; + + list_for_each_entry_safe(dep, tmp, &iface->users, list) + interface_remove_user(dep); + interface_clear_dns(iface); interface_clear_errors(iface); if (iface->main_dev.dev) @@ -290,6 +316,7 @@ interface_init(struct interface *iface, const char *name, strncpy(iface->name, name, sizeof(iface->name) - 1); INIT_LIST_HEAD(&iface->errors); + INIT_LIST_HEAD(&iface->users); INIT_LIST_HEAD(&iface->hotplug_list); INIT_LIST_HEAD(&iface->proto_dns_search); INIT_LIST_HEAD(&iface->proto_dns_servers); diff --git a/interface.h b/interface.h index 6620796..7f84060 100644 --- a/interface.h +++ b/interface.h @@ -33,6 +33,12 @@ struct interface_error { const char *data[]; }; +struct interface_user { + struct list_head list; + struct interface *iface; + void (*cb)(struct interface_user *dep, enum interface_event ev); +}; + /* * interface configuration */ @@ -52,6 +58,8 @@ struct interface { enum interface_state state; enum interface_config_state config_state; + struct list_head users; + /* main interface that the interface is bound to */ struct device_user main_dev; @@ -91,6 +99,9 @@ void interface_set_available(struct interface *iface, bool new_state); int interface_set_up(struct interface *iface); int interface_set_down(struct interface *iface); +void interface_add_user(struct interface_user *dep, struct interface *iface); +void interface_remove_user(struct interface_user *dep); + int interface_add_link(struct interface *iface, struct device *llif); void interface_remove_link(struct interface *iface, struct device *llif); -- 2.11.0