From: Michael Tremer Date: Thu, 8 Jun 2023 16:35:33 +0000 (+0000) Subject: ports: Implement scaffolding for configuration X-Git-Url: http://git.ipfire.org/?p=people%2Fms%2Fnetwork.git;a=commitdiff_plain;h=ea7dc1bbab6162c319ce738161af813f2d1b7241 ports: Implement scaffolding for configuration Signed-off-by: Michael Tremer --- diff --git a/src/networkd/port.c b/src/networkd/port.c index c14d439e..fb5d4189 100644 --- a/src/networkd/port.c +++ b/src/networkd/port.c @@ -127,6 +127,19 @@ ERROR: return r; } +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; @@ -172,6 +185,23 @@ int nw_port_create(nw_port** port, nw_daemon* daemon, if (r) goto ERROR; + // 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; + } + *port = p; return 0; diff --git a/src/networkd/port.h b/src/networkd/port.h index b96b13eb..7c2e4366 100644 --- a/src/networkd/port.h +++ b/src/networkd/port.h @@ -48,6 +48,7 @@ typedef struct nw_port_type { // Configuration int (*setup)(nw_port* port); + int (*validate)(nw_port* port); // Get Parent Port nw_port* (*get_parent_port)(nw_port* port);