ifupdown: skip interface config/deconfig based on refcounts

This commit is contained in:
Ariadne Conill 2020-09-08 19:10:20 -06:00
parent 8de83fdd9a
commit efe9b60e37

View file

@ -93,6 +93,26 @@ acquire_state_lock(const char *state_path, const char *lifname)
return fd; 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 bool
change_interface(struct lif_interface *iface, struct lif_dict *collection, struct lif_dict *state, const char *ifname) 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; return false;
} }
if (skip_interface(iface, ifname))
{
if (lockfd != -1)
close(lockfd);
return true;
}
if (exec_opts.verbose) if (exec_opts.verbose)
{ {
fprintf(stderr, "%s: changing state of interface %s to '%s'\n", fprintf(stderr, "%s: changing state of interface %s to '%s'\n",