Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
+static int nw_port_validate(nw_port* port) {
+ int r = 0;
+
+ // Validate the port configuration
+ if (NW_PORT_TYPE(port)->validate) {
+ r = NW_PORT_TYPE(port)->validate(port);
+ if (r < 0)
+ ERROR("Could not check configuration for %s: %s\n", port->name, strerror(-r));
+ }
+
+ return r;
+}
+
int nw_port_create(nw_port** port, nw_daemon* daemon,
const nw_port_type_id_t type, const char* name, nw_config* config) {
int r;
int nw_port_create(nw_port** port, nw_daemon* daemon,
const nw_port_type_id_t type, const char* name, nw_config* config) {
int r;
+ // Validate the configuration
+ r = nw_port_validate(p);
+ switch (r) {
+ // Configuration is valid
+ case 0:
+ break;
+
+ // Configuration is invalid
+ case 1:
+ ERROR("%s: Invalid configuration\n", p->name);
+ goto ERROR;
+
+ // Error
+ default:
+ goto ERROR;
+ }
+
// Configuration
int (*setup)(nw_port* port);
// Configuration
int (*setup)(nw_port* port);
+ int (*validate)(nw_port* port);
// Get Parent Port
nw_port* (*get_parent_port)(nw_port* port);
// Get Parent Port
nw_port* (*get_parent_port)(nw_port* port);