From 749b1a85fdbf4ec0ec0ac3b3fe07cdeffd72460c Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Thu, 8 Jun 2023 16:41:13 +0000 Subject: [PATCH] ports: VLAN: Validate configuration Signed-off-by: Michael Tremer --- src/networkd/port-vlan.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/networkd/port-vlan.c b/src/networkd/port-vlan.c index 06047aba..25a59eed 100644 --- a/src/networkd/port-vlan.c +++ b/src/networkd/port-vlan.c @@ -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, -- 2.47.2