diff --git a/cmd/ifquery.c b/cmd/ifquery.c index ac07cbd..54625b1 100644 --- a/cmd/ifquery.c +++ b/cmd/ifquery.c @@ -63,7 +63,7 @@ print_interface_dot(struct lif_dict *collection, struct lif_interface *iface, st if (!lif_lifecycle_query_dependents(&exec_opts, iface, iface->ifname)) return; - if (iface->is_up) + if (iface->refcount > 0) return; if (parent != NULL) @@ -87,7 +87,7 @@ print_interface_dot(struct lif_dict *collection, struct lif_interface *iface, st struct lif_interface *child_if = lif_interface_collection_find(collection, tokenp); print_interface_dot(collection, child_if, iface); - child_if->is_up = true; + child_if->refcount++; } } diff --git a/libifupdown/interface.h b/libifupdown/interface.h index 3f2c287..a18c4b7 100644 --- a/libifupdown/interface.h +++ b/libifupdown/interface.h @@ -53,7 +53,7 @@ struct lif_interface { struct lif_dict vars; - bool is_up; + size_t refcount; /* >= 0 if up, else 0 */ }; #define LIF_INTERFACE_COLLECTION_FOREACH(iter, collection) \ diff --git a/libifupdown/lifecycle.c b/libifupdown/lifecycle.c index f34041f..2b77ed0 100644 --- a/libifupdown/lifecycle.c +++ b/libifupdown/lifecycle.c @@ -279,7 +279,7 @@ handle_dependents(const struct lif_execute_opts *opts, struct lif_interface *par struct lif_interface *iface = lif_interface_collection_find(collection, tokenp); /* already up or down, skip */ - if (up == iface->is_up) + if (up && iface->refcount > 0) { if (opts->verbose) fprintf(stderr, "ifupdown: skipping dependent interface %s (of %s)\n", @@ -328,7 +328,7 @@ lif_lifecycle_run(const struct lif_execute_opts *opts, struct lif_interface *ifa lif_state_upsert(state, lifname, iface); - iface->is_up = true; + iface->refcount++; } else { @@ -347,7 +347,7 @@ lif_lifecycle_run(const struct lif_execute_opts *opts, struct lif_interface *ifa lif_state_delete(state, lifname); - iface->is_up = false; + iface->refcount--; } return true; diff --git a/libifupdown/state.c b/libifupdown/state.c index 74d0e0c..a05e3dd 100644 --- a/libifupdown/state.c +++ b/libifupdown/state.c @@ -126,7 +126,7 @@ lif_state_sync(struct lif_dict *state, struct lif_dict *if_collection) struct lif_dict_entry *entry = iter->data; struct lif_interface *iface = lif_interface_collection_find(if_collection, entry->key); - iface->is_up = true; + iface->refcount++; } return true;