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",