From: Michael Tremer Date: Fri, 14 Apr 2023 12:02:40 +0000 (+0000) Subject: networkd: zones: Keep a permanent reference to links X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4e989bd539cc0aea61345156a6401e7282357d0c;p=network.git networkd: zones: Keep a permanent reference to links Signed-off-by: Michael Tremer --- diff --git a/src/networkd/zone.c b/src/networkd/zone.c index 8fe07c5c..4fda1e5f 100644 --- a/src/networkd/zone.c +++ b/src/networkd/zone.c @@ -25,6 +25,7 @@ #include "config.h" #include "daemon.h" +#include "link.h" #include "logging.h" #include "string.h" #include "zone.h" @@ -33,6 +34,9 @@ struct nw_zone { nw_daemon* daemon; int nrefs; + // Link + nw_link* link; + char name[NETWORK_ZONE_NAME_MAX_LENGTH]; // Configuration @@ -66,6 +70,8 @@ static int __nw_zone_path(nw_zone* zone, char* p, const size_t length, } static void nw_zone_free(nw_zone* zone) { + if (zone->link) + nw_link_unref(zone->link); if (zone->config) nw_config_unref(zone->config); if (zone->daemon) @@ -78,6 +84,14 @@ static int nw_zone_setup(nw_zone* zone) { char path[PATH_MAX]; int r; + // Find the link + zone->link = nw_daemon_get_link_by_name(zone->daemon, zone->name); + if (zone->link) { + DEBUG("%s: Found matching link %d\n", zone->name, nw_link_ifindex(zone->link)); + } else { + DEBUG("%s: Could not find matching link\n", zone->name); + } + // Compose the path to the main configuration file r = nw_zone_path(zone, path, "%s", "settings"); if (r) @@ -164,22 +178,19 @@ char* nw_zone_bus_path(nw_zone* zone) { } static nw_link* nw_zone_get_link(nw_zone* zone) { - return nw_daemon_get_link_by_name(zone->daemon, zone->name); + if (!zone->link) + return NULL; + + return nw_link_ref(zone->link); } // Carrier int nw_zone_has_carrier(nw_zone* zone) { - int has_carrier = 0; - - // Fetch link - nw_link* link = nw_zone_get_link(zone); - if (link) { - has_carrier = nw_link_has_carrier(link); - nw_link_unref(link); - } + if (!zone->link) + return 0; - return has_carrier; + return nw_link_has_carrier(zone->link); } /*