summaryrefslogtreecommitdiff
path: root/src/network/networkd-link.c
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2014-05-08 18:54:26 +0200
committerTom Gundersen <teg@jklm.no>2014-05-09 14:41:27 +0200
commit14b746f72132324e637c4e39694bd474f85e19f7 (patch)
tree7a99b9d37b073cb5d42bb1769c8639bae47fdc2b /src/network/networkd-link.c
parent68a8723c8592c06b2c978f391cb47db266d9d6de (diff)
networkd: introduce refcounting for Links and NetDevs
Diffstat (limited to 'src/network/networkd-link.c')
-rw-r--r--src/network/networkd-link.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index 74860196a5..525fe1442f 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -37,7 +37,7 @@ static int ipv4ll_address_update(Link *link, bool deprecate);
static bool ipv4ll_is_bound(sd_ipv4ll *ll);
static int link_new(Manager *manager, sd_rtnl_message *message, Link **ret) {
- _cleanup_link_free_ Link *link = NULL;
+ _cleanup_link_unref_ Link *link = NULL;
uint16_t type;
char *ifname;
int r, ifindex;
@@ -67,6 +67,7 @@ static int link_new(Manager *manager, sd_rtnl_message *message, Link **ret) {
if (!link)
return -ENOMEM;
+ link->n_ref = 1;
link->manager = manager;
link->state = LINK_STATE_INITIALIZING;
link->ifindex = ifindex;
@@ -94,7 +95,7 @@ static int link_new(Manager *manager, sd_rtnl_message *message, Link **ret) {
return 0;
}
-void link_free(Link *link) {
+static void link_free(Link *link) {
if (!link)
return;
@@ -120,6 +121,20 @@ void link_free(Link *link) {
free(link);
}
+Link *link_unref(Link *link) {
+ if (link && (-- link->n_ref <= 0))
+ link_free(link);
+
+ return NULL;
+}
+
+Link *link_ref(Link *link) {
+ if (link)
+ assert_se(++ link->n_ref >= 2);
+
+ return link;
+}
+
int link_get(Manager *m, int ifindex, Link **ret) {
Link *link;
uint64_t ifindex_64;