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)
This commit is contained in:
Lexi Winter 2025-07-28 15:09:29 +01:00 committed by Franco Fichtner
parent 6ea749503a
commit 9b6cdc5678

View file

@ -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)
{