diff --git a/libifupdown/state.c b/libifupdown/state.c index 4509031..f3a4260 100644 --- a/libifupdown/state.c +++ b/libifupdown/state.c @@ -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) { diff --git a/libifupdown/state.h b/libifupdown/state.h index 8c46a63..bec039c 100644 --- a/libifupdown/state.h +++ b/libifupdown/state.h @@ -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);