]> git.ipfire.org Git - people/ms/network.git/commitdiff
ports: VLAN: Validate configuration
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 8 Jun 2023 16:41:13 +0000 (16:41 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 8 Jun 2023 16:41:13 +0000 (16:41 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/networkd/port-vlan.c

index 06047abad66e9120d9740a556f0aeb0a332ff0f4..25a59eed28ca50f821ca8245441b80dd24f32e03 100644 (file)
@@ -60,6 +60,27 @@ static int nw_port_vlan_setup(nw_port* port) {
        return 0;
 }
 
+static int nw_port_vlan_validate(nw_port* port) {
+       // Check if the VLAN ID is within range
+       if (port->vlan.id < NW_VLAN_ID_MIN || port->vlan.id > NW_VLAN_ID_MAX) {
+               ERROR("%s: Invalid VLAN ID %d\n", port->name, port->vlan.id);
+               return 1;
+       }
+
+       // Validate protocol
+       switch (port->vlan.proto) {
+               case NW_VLAN_PROTO_8021Q:
+               case NW_VLAN_PROTO_8021AD:
+                       break;
+
+               default:
+                       ERROR("%p: Invalid VLAN protocol\n", port->name);
+                       return 1;
+       }
+
+       return 0;
+}
+
 static int nw_port_vlan_create_link(nw_port* port, sd_netlink_message* m) {
        int r;
 
@@ -111,6 +132,7 @@ const nw_port_type_t nw_port_type_vlan = {
 
        // Configuration
        .setup = nw_port_vlan_setup,
+       .validate = nw_port_vlan_validate,
 
        .get_parent_port = nw_port_get_vlan_parent,