#include "config.h"
#include "daemon.h"
+#include "link.h"
#include "logging.h"
#include "string.h"
#include "zone.h"
nw_daemon* daemon;
int nrefs;
+ // Link
+ nw_link* link;
+
char name[NETWORK_ZONE_NAME_MAX_LENGTH];
// Configuration
}
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)
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)
}
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);
}
/*