From d9cbfa37947bbee7522f25f97a07ecb74190bcd9 Mon Sep 17 00:00:00 2001 From: Lexi Winter Date: Tue, 15 Apr 2025 18:13:33 +0200 Subject: [PATCH] sys/net: add DOT1Q_VID_{MIN,MAX} add a new typedef in if_vlan_var.h to represent the lowest (1) and highest (4095) valid VLAN IDs in a .1q tag. change if_vlan to use DOT1Q_VID_MAX instead of a magic number. Reviewed by: kp Differential Revision: https://reviews.freebsd.org/D49837 (cherry picked from commit c59492025073bd57c7dc3bb5bd843ab0a1391c7a) --- sys/net/if_vlan.c | 2 +- sys/net/if_vlan_var.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/sys/net/if_vlan.c b/sys/net/if_vlan.c index c586b513e00..dce1cff5bc6 100644 --- a/sys/net/if_vlan.c +++ b/sys/net/if_vlan.c @@ -1272,7 +1272,7 @@ vlan_clone_create_nl(struct if_clone *ifc, char *name, size_t len, error = nl_parse_nested(lattrs->ifla_idata, &vlan_parser, npt, &attrs); if (error != 0) return (error); - if (attrs.vlan_id > 4095) { + if (attrs.vlan_id > DOT1Q_VID_MAX) { nlmsg_report_err_msg(npt, "Invalid VID: %d", attrs.vlan_id); return (EINVAL); } diff --git a/sys/net/if_vlan_var.h b/sys/net/if_vlan_var.h index b86ff2efac6..e7171974289 100644 --- a/sys/net/if_vlan_var.h +++ b/sys/net/if_vlan_var.h @@ -130,6 +130,8 @@ struct vlanreq { #define DOT1Q_VID_DEF_PVID 0x1 #define DOT1Q_VID_DEF_SR_PVID 0x2 #define DOT1Q_VID_RSVD_IMPL 0xfff +#define DOT1Q_VID_MIN 1 /* minimum valid vlan id */ +#define DOT1Q_VID_MAX 4095 /* maximum valid vlan id */ /* * 802.1q full tag. Proto and vid are stored in host byte order.