]> git.ipfire.org Git - people/ms/network.git/commitdiff
ports: Implement scaffolding for configuration
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 8 Jun 2023 16:35:33 +0000 (16:35 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 8 Jun 2023 16:35:33 +0000 (16:35 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/networkd/port.c
src/networkd/port.h

index c14d439ec2ef79636d982142e525ffb3221e14a2..fb5d418911193527367cb10b5b41f9a1b6377f86 100644 (file)
@@ -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;
 
index b96b13ebe7b16cadcc288b7faf2dfa4e47a6c95f..7c2e43668e282bf15ebbe2750b8b0aada68ea2a1 100644 (file)
@@ -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);