summaryrefslogtreecommitdiff
path: root/src/network/networkd-link.c
diff options
context:
space:
mode:
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;