From 9b6cdc5678c228c01c733bbdd012e75ca549d126 Mon Sep 17 00:00:00 2001 From: Lexi Winter Date: Mon, 28 Jul 2025 15:09:29 +0100 Subject: [PATCH] ifconfig/ifbridge.c: add get_vlan_id() This is like get_val() but takes an ether_vlanid_t* and ensures the value is a valid VLAN ID. This avoids redundant comparisons and casting when parsing VLAN IDs. Reviewed by: des Differential Revision: https://reviews.freebsd.org/D51548 (cherry picked from commit 287a5fdcd3c941ce73705c664b5df4932ba3bad4) --- sbin/ifconfig/ifbridge.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/sbin/ifconfig/ifbridge.c b/sbin/ifconfig/ifbridge.c index 2d0af1255a7..973c4f9cfe6 100644 --- a/sbin/ifconfig/ifbridge.c +++ b/sbin/ifconfig/ifbridge.c @@ -79,6 +79,20 @@ get_val(const char *cp, u_long *valp) return (0); } +static int +get_vlan_id(const char *cp, ether_vlanid_t *valp) +{ + u_long val; + + if (get_val(cp, &val) == -1) + return (-1); + if (val < 0x1 || val > 0xffe) + return (-1); + + *valp = (ether_vlanid_t)val; + return (0); +} + static int do_cmd(if_ctx *ctx, u_long op, void *arg, size_t argsize, int set) {