From e0a7444640b98562d94c29f8a15e823fd317c79b Mon Sep 17 00:00:00 2001 From: Ariadne Conill Date: Fri, 24 Jul 2020 04:48:50 -0600 Subject: [PATCH] state: add ability to sync a state to if_collection cache --- cmd/ifupdown.c | 10 ++++++++-- libifupdown/state.c | 16 ++++++++++++++++ libifupdown/state.h | 1 + 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/cmd/ifupdown.c b/cmd/ifupdown.c index 575673c..ce2cd63 100644 --- a/cmd/ifupdown.c +++ b/cmd/ifupdown.c @@ -170,13 +170,19 @@ ifupdown_main(int argc, char *argv[]) if (!lif_state_read_path(&state, state_file)) { - fprintf(stderr, "ifquery: could not parse %s\n", state_file); + fprintf(stderr, "%s: could not parse %s\n", argv0, state_file); return EXIT_FAILURE; } if (!lif_interface_file_parse(&collection, interfaces_file)) { - fprintf(stderr, "ifquery: could not parse %s\n", interfaces_file); + fprintf(stderr, "%s: could not parse %s\n", argv0, interfaces_file); + return EXIT_FAILURE; + } + + if (!lif_state_sync(&state, &collection)) + { + fprintf(stderr, "%s: could not sync state\n", argv0); return EXIT_FAILURE; } diff --git a/libifupdown/state.c b/libifupdown/state.c index e9856dd..89ad105 100644 --- a/libifupdown/state.c +++ b/libifupdown/state.c @@ -114,3 +114,19 @@ lif_state_lookup(struct lif_dict *state, struct lif_dict *if_collection, const c return if_entry->data; } + +bool +lif_state_sync(struct lif_dict *state, struct lif_dict *if_collection) +{ + struct lif_node *iter; + + LIF_DICT_FOREACH(iter, state) + { + struct lif_dict_entry *entry = iter->data; + struct lif_interface *iface = lif_interface_collection_find(if_collection, entry->key); + + iface->is_up = true; + } + + return true; +} diff --git a/libifupdown/state.h b/libifupdown/state.h index 36cb59e..584deca 100644 --- a/libifupdown/state.h +++ b/libifupdown/state.h @@ -26,5 +26,6 @@ extern void lif_state_delete(struct lif_dict *state, const char *ifname); extern void lif_state_write(const struct lif_dict *state, FILE *f); extern bool lif_state_write_path(const struct lif_dict *state, const char *path); extern struct lif_interface *lif_state_lookup(struct lif_dict *state, struct lif_dict *if_collection, const char *ifname); +extern bool lif_state_sync(struct lif_dict *state, struct lif_dict *if_collection); #endif