libifupdown: introduce lif_state_ref_if() and lif_state_unref_if().

This commit is contained in:
Ariadne Conill 2020-09-08 15:05:02 -06:00
parent 865bf7cac6
commit 288976f015
2 changed files with 20 additions and 0 deletions

View file

@ -63,6 +63,24 @@ lif_state_read_path(struct lif_dict *state, const char *path)
return ret;
}
void
lif_state_ref_if(struct lif_dict *state, const char *ifname, struct lif_interface *iface)
{
iface->refcount++;
lif_state_upsert(state, ifname, iface);
}
void
lif_state_unref_if(struct lif_dict *state, const char *ifname, struct lif_interface *iface)
{
iface->refcount--;
if (iface->refcount)
lif_state_upsert(state, ifname, iface);
else
lif_state_delete(state, ifname);
}
void
lif_state_upsert(struct lif_dict *state, const char *ifname, struct lif_interface *iface)
{

View file

@ -27,6 +27,8 @@ struct lif_state_record {
extern bool lif_state_read(struct lif_dict *state, FILE *f);
extern bool lif_state_read_path(struct lif_dict *state, const char *path);
extern void lif_state_upsert(struct lif_dict *state, const char *ifname, struct lif_interface *iface);
extern void lif_state_ref_if(struct lif_dict *state, const char *ifname, struct lif_interface *iface);
extern void lif_state_unref_if(struct lif_dict *state, const char *ifname, struct lif_interface *iface);
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);