#include <stdlib.h>
#include <string.h>
#include <sys/queue.h>
+#include <unistd.h>
#include "config.h"
#include "logging.h"
return NULL;
}
+int nw_config_destroy(nw_config* config) {
+ int r;
+
+ // Drop all entries
+ r = nw_config_flush(config);
+ if (r)
+ return r;
+
+ return unlink(config->path);
+}
+
const char* nw_config_path(nw_config* config) {
if (*config->path)
return config->path;
nw_config* nw_config_ref(nw_config* config);
nw_config* nw_config_unref(nw_config* config);
+int nw_config_destroy(nw_config* config);
+
const char* nw_config_path(nw_config* config);
int nw_config_flush(nw_config* config);
return 1;
}
+#if 0
// Fetch operstate
r = sd_netlink_message_read_u8(message, IFLA_OPERSTATE, &operstate);
if (r < 1) {
ERROR("Could not read operstate: %m\n");
return 1;
}
+#endif
// End here if there have been no changes
if (link->flags == flags && link->operstate == operstate)
return NULL;
}
+int nw_port_destroy(nw_port* port) {
+ int r;
+
+ DEBUG("Destroying port %s\n", port->name);
+
+ // Destroy the physical link (if exists)
+ if (port->link) {
+ r = nw_link_destroy(port->link);
+ if (r)
+ return r;
+ }
+
+ // Dereference the port from other ports
+ r = nw_daemon_ports_walk(port->daemon, __nw_port_drop_port, port);
+ if (r)
+ return r;
+
+ // Dereference the port from other zones
+ r = nw_daemon_zones_walk(port->daemon, __nw_zone_drop_port, port);
+ if (r)
+ return r;
+
+ // Destroy the configuration
+ r = nw_config_destroy(port->config);
+ if (r)
+ return r;
+
+ // Reset type
+ port->type = NW_PORT_UNKNOWN;
+
+ return 0;
+}
+
+int __nw_port_drop_port(nw_daemon* daemon, nw_port* port, void* data) {
+ nw_port* dropped_port = (nw_port*)data;
+ int r;
+
+ switch (port->type) {
+ case NW_PORT_VLAN:
+ if (port->vlan.parent == dropped_port) {
+ r = nw_port_set_vlan_parent(port, NULL);
+ if (r)
+ return r;
+ }
+ break;
+
+ case NW_PORT_DUMMY:
+ case NW_PORT_UNKNOWN:
+ break;
+ }
+
+ return 0;
+}
+
static int nw_port_save_vlan(nw_port* port) {
int r;
nw_port* nw_port_ref(nw_port* port);
nw_port* nw_port_unref(nw_port* port);
+int nw_port_destroy(nw_port* port);
+int __nw_port_drop_port(nw_daemon* daemon, nw_port* port, void* data);
+
int nw_port_save(nw_port* port);
const char* nw_port_name(nw_port* port);
return NULL;
}
+int __nw_zone_drop_port(nw_daemon* daemon, nw_zone* zone, void* data) {
+ nw_port* dropped_port = (nw_port*)data;
+
+ // XXX TODO
+ (void)dropped_port;
+
+ return 0;
+}
+
int nw_zone_save(nw_zone* zone) {
int r;
nw_zone* nw_zone_ref(nw_zone* zone);
nw_zone* nw_zone_unref(nw_zone* zone);
+int __nw_zone_drop_port(nw_daemon* daemon, nw_zone* zone, void* data);
+
int nw_zone_save(nw_zone* zone);
const char* nw_zone_name(nw_zone* zone);