From 288976f015f8f15aa34759f092949ce399e0c463 Mon Sep 17 00:00:00 2001 From: Ariadne Conill Date: Tue, 8 Sep 2020 15:05:02 -0600 Subject: [PATCH] libifupdown: introduce lif_state_ref_if() and lif_state_unref_if(). --- libifupdown/state.c | 18 ++++++++++++++++++ libifupdown/state.h | 2 ++ 2 files changed, 20 insertions(+) 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);