nw_daemon* daemon;
int nrefs;
+ // Link
+ nw_link* link;
+
char name[IF_NAMESIZE];
nw_port_type_t type;
}
static void nw_port_free(nw_port* port) {
+ if (port->link)
+ nw_link_unref(port->link);
if (port->config)
nw_config_unref(port->config);
if (port->daemon)
char path[PATH_MAX];
int r;
+ // Find the link
+ port->link = nw_daemon_get_link_by_name(port->daemon, port->name);
+ if (port->link) {
+ DEBUG("%s: Found matching link %d\n", port->name, nw_link_ifindex(port->link));
+ } else {
+ DEBUG("%s: Could not find matching link\n", port->name);
+ }
+
// Compose the path to the main configuration file
r = nw_path_join(path, PORT_CONFIG_DIR, port->name);
if (r)
}
static nw_link* nw_port_get_link(nw_port* port) {
- return nw_daemon_get_link_by_name(port->daemon, port->name);
+ if (!port->link)
+ return NULL;
+
+ return nw_link_ref(port->link);
}
const nw_address_t* nw_port_get_address(nw_port* port) {
}
int nw_port_has_carrier(nw_port* port) {
- int has_carrier = 0;
-
- // Fetch link
- nw_link* link = nw_port_get_link(port);
- if (link) {
- has_carrier = nw_link_has_carrier(link);
- nw_link_unref(link);
- }
+ if (!port->link)
+ return 0;
- return has_carrier;
+ return nw_link_has_carrier(port->link);
}