From c58285c247c7c3833fc6e1126d53293e8090e8ad Mon Sep 17 00:00:00 2001 From: "R. Christian McDonald" Date: Thu, 24 Jul 2025 16:11:16 -0400 Subject: [PATCH] FreeBSD: Introduce `vlan-pcp` option for VLAN PCP tagging --- src/bpf.c | 11 +++++++++++ src/if-options.c | 19 +++++++++++++++++++ src/if-options.h | 8 ++++++++ src/if.h | 2 ++ 4 files changed, 40 insertions(+) diff --git a/src/bpf.c b/src/bpf.c index 7c521261..23e7b894 100644 --- a/src/bpf.c +++ b/src/bpf.c @@ -162,6 +162,9 @@ bpf_open(const struct interface *ifp, #ifdef BIOCIMMEDIATE unsigned int flags; #endif +#ifdef BIOCSETVLANPCP + unsigned int vlan_pcp; +#endif #ifndef O_CLOEXEC int fd_opts; #endif @@ -207,6 +210,14 @@ bpf_open(const struct interface *ifp, if (ioctl(bpf->bpf_fd, BIOCSETIF, &ifr) == -1) goto eexit; +#ifdef BIOCSETVLANPCP + if (ifp->options->vlan_pcp != -1) { + vlan_pcp = (u_int)ifp->options->vlan_pcp; + if (ioctl(bpf->bpf_fd, BIOCSETVLANPCP, &vlan_pcp) == -1) + goto eexit; + } +#endif + #ifdef BIOCIMMEDIATE flags = 1; if (ioctl(bpf->bpf_fd, BIOCIMMEDIATE, &flags) == -1) diff --git a/src/if-options.c b/src/if-options.c index 3cb89f35..2f293f4b 100644 --- a/src/if-options.c +++ b/src/if-options.c @@ -30,6 +30,7 @@ #include #include +#include #include #include @@ -176,6 +177,9 @@ const struct option cf_options[] = { {"fallback_time", required_argument, NULL, O_FALLBACK_TIME}, {"ipv4ll_time", required_argument, NULL, O_IPV4LL_TIME}, {"nosyslog", no_argument, NULL, O_NOSYSLOG}, +#ifdef BIOCSETVLANPCP + {"vlan_pcp", required_argument, NULL, O_VLANPCP}, +#endif {NULL, 0, NULL, '\0'} }; @@ -2571,6 +2575,16 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo, logsetopts(logopts); } break; +#ifdef BIOCSETVLANPCP + case O_VLANPCP: + ARG_REQUIRED; + ifo->vlan_pcp = + (int)strtoi(arg, NULL, 0, 0, VLAN_PCP_MAX, &e); + if (e) { + logerrx("invalid vlan-pcp: %s", arg); + return -1; + } +#endif default: return 0; } @@ -2666,6 +2680,11 @@ default_config(struct dhcpcd_ctx *ctx) TAILQ_INIT(&ifo->auth.tokens); #endif +#ifdef BIOCSETVLANPCP + /* Disable PCP tagging */ + ifo->vlan_pcp = -1; +#endif + /* Inherit some global defaults */ if (ctx->options & DHCPCD_CONFIGURE) ifo->options |= DHCPCD_CONFIGURE; diff --git a/src/if-options.h b/src/if-options.h index a92697e1..b2ebab41 100644 --- a/src/if-options.h +++ b/src/if-options.h @@ -33,6 +33,7 @@ #include #include #include +#include #include #include @@ -190,6 +191,9 @@ #define O_VSIO O_BASE + 57 #define O_VSIO6 O_BASE + 58 #define O_NOSYSLOG O_BASE + 59 +#ifdef BIOCSETVLANPCP +#define O_VLANPCP O_BASE + 60 +#endif extern const struct option cf_options[]; @@ -313,6 +317,10 @@ struct if_options { #endif struct auth auth; + +#ifdef BIOCSETVLANPCP + int vlan_pcp; +#endif }; struct if_options *read_config(struct dhcpcd_ctx *, diff --git a/src/if.h b/src/if.h index 8d1aeccf..577fe885 100644 --- a/src/if.h +++ b/src/if.h @@ -73,6 +73,8 @@ typedef unsigned long ioctl_request_t; #include "ipv6.h" #include "route.h" +#define VLAN_PCP_MAX 7 + #define EUI64_ADDR_LEN 8 #define INFINIBAND_ADDR_LEN 20