From 2cc7e981af27b12a6a3d4f08728281febeb450c9 Mon Sep 17 00:00:00 2001 From: Tom Gundersen Date: Thu, 8 May 2014 20:42:22 +0200 Subject: [PATCH] networkd: netdev - introduce LINGER state and netdev_drop() We need the LINGER state in case we still have references to the netdev after it has been dropped. --- src/network/networkd-netdev.c | 13 +++++++++++++ src/network/networkd.h | 2 ++ 2 files changed, 15 insertions(+) diff --git a/src/network/networkd-netdev.c b/src/network/networkd-netdev.c index ed4bc191f35..c7bec74aa36 100644 --- a/src/network/networkd-netdev.c +++ b/src/network/networkd-netdev.c @@ -108,6 +108,19 @@ NetDev *netdev_ref(NetDev *netdev) { return netdev; } +void netdev_drop(NetDev *netdev) { + if (!netdev || netdev->state == NETDEV_STATE_LINGER) + return; + + netdev->state = NETDEV_STATE_LINGER; + + netdev_cancel_callbacks(netdev); + + netdev_unref(netdev); + + return; +} + int netdev_get(Manager *manager, const char *name, NetDev **ret) { NetDev *netdev; diff --git a/src/network/networkd.h b/src/network/networkd.h index cff0136bcce..bdf98087216 100644 --- a/src/network/networkd.h +++ b/src/network/networkd.h @@ -76,6 +76,7 @@ typedef enum NetDevState { NETDEV_STATE_FAILED, NETDEV_STATE_CREATING, NETDEV_STATE_READY, + NETDEV_STATE_LINGER, _NETDEV_STATE_MAX, _NETDEV_STATE_INVALID = -1, } NetDevState; @@ -271,6 +272,7 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_free); /* NetDev */ int netdev_load(Manager *manager); +void netdev_drop(NetDev *netdev); NetDev *netdev_unref(NetDev *netdev); NetDev *netdev_ref(NetDev *netdev);