From efe9b60e371ec4c7420ce2ee65171f8145fe7ee0 Mon Sep 17 00:00:00 2001 From: Ariadne Conill Date: Tue, 8 Sep 2020 19:10:20 -0600 Subject: [PATCH] ifupdown: skip interface config/deconfig based on refcounts --- cmd/ifupdown.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/cmd/ifupdown.c b/cmd/ifupdown.c index bd9a68e..9124320 100644 --- a/cmd/ifupdown.c +++ b/cmd/ifupdown.c @@ -93,6 +93,26 @@ acquire_state_lock(const char *state_path, const char *lifname) return fd; } +bool +skip_interface(struct lif_interface *iface, const char *ifname) +{ + if (up && iface->refcount > 0) + { + fprintf(stderr, "%s: skipping %s (already configured), use --force to force configuration\n", + argv0, ifname); + return true; + } + + if (!up && iface->refcount == 0) + { + fprintf(stderr, "%s: skipping %s (already deconfigured), use --force to force deconfiguration\n", + argv0, ifname); + return true; + } + + return false; +} + bool change_interface(struct lif_interface *iface, struct lif_dict *collection, struct lif_dict *state, const char *ifname) { @@ -104,6 +124,14 @@ change_interface(struct lif_interface *iface, struct lif_dict *collection, struc return false; } + if (skip_interface(iface, ifname)) + { + if (lockfd != -1) + close(lockfd); + + return true; + } + if (exec_opts.verbose) { fprintf(stderr, "%s: changing state of interface %s to '%s'\n",