diff --git a/sys/net/bpf.c b/sys/net/bpf.c --- a/sys/net/bpf.c +++ b/sys/net/bpf.c @@ -1172,27 +1172,6 @@ return (0); } -static int -bpf_setpcp(struct mbuf *m, u_int8_t prio) -{ - struct m_tag *mtag; - - KASSERT(prio <= BPF_PRIO_MAX, - ("%s with invalid pcp", __func__)); - - mtag = m_tag_locate(m, MTAG_8021Q, MTAG_8021Q_PCP_OUT, NULL); - if (mtag == NULL) { - mtag = m_tag_alloc(MTAG_8021Q, MTAG_8021Q_PCP_OUT, - sizeof(uint8_t), M_NOWAIT); - if (mtag == NULL) - return (ENOMEM); - m_tag_prepend(m, mtag); - } - - *(uint8_t *)(mtag + 1) = prio; - return (0); -} - static int bpfwrite(struct cdev *dev, struct uio *uio, int ioflag) { @@ -1294,7 +1273,7 @@ } if (d->bd_pcp != 0) - bpf_setpcp(m, d->bd_pcp); + vlan_set_pcp(m, d->bd_pcp); /* Avoid possible recursion on BPFD_LOCK(). */ NET_EPOCH_ENTER(et); diff --git a/sys/net/if_vlan.c b/sys/net/if_vlan.c --- a/sys/net/if_vlan.c +++ b/sys/net/if_vlan.c @@ -2040,7 +2040,7 @@ error = priv_check(curthread, PRIV_NET_SETVLANPCP); if (error) break; - if (ifr->ifr_vlan_pcp > 7) { + if (ifr->ifr_vlan_pcp > VLAN_PCP_MAX) { error = EINVAL; break; } diff --git a/sys/net/if_vlan_var.h b/sys/net/if_vlan_var.h --- a/sys/net/if_vlan_var.h +++ b/sys/net/if_vlan_var.h @@ -32,6 +32,8 @@ #ifndef _NET_IF_VLAN_VAR_H_ #define _NET_IF_VLAN_VAR_H_ 1 +#include + /* Set the VLAN ID in an mbuf packet header non-destructively. */ #define EVL_APPLY_VLID(m, vlid) \ do { \ @@ -124,6 +126,8 @@ #define MTAG_8021Q_PCP_IN 0 /* Input priority. */ #define MTAG_8021Q_PCP_OUT 1 /* Output priority. */ +#define VLAN_PCP_MAX 7 + /* * 802.1q full tag. Proto and vid are stored in host byte order. */ @@ -168,6 +172,28 @@ EVENTHANDLER_DECLARE(vlan_config, vlan_config_fn); EVENTHANDLER_DECLARE(vlan_unconfig, vlan_unconfig_fn); +static inline int +vlan_set_pcp(struct mbuf *m, uint8_t prio) +{ + struct m_tag *mtag; + + KASSERT(prio <= VLAN_PCP_MAX, + ("%s with invalid pcp", __func__)); + + mtag = m_tag_locate(m, MTAG_8021Q, MTAG_8021Q_PCP_OUT, NULL); + if (mtag == NULL) { + mtag = m_tag_alloc(MTAG_8021Q, MTAG_8021Q_PCP_OUT, + sizeof(uint8_t), M_NOWAIT); + if (mtag == NULL) + return (ENOMEM); + m_tag_prepend(m, mtag); + } + + *(uint8_t *)(mtag + 1) = prio; + + return (0); +} + #endif /* _KERNEL */ #endif /* _NET_IF_VLAN_VAR_H_ */ diff --git a/sys/netpfil/pf/pf.c b/sys/netpfil/pf/pf.c --- a/sys/netpfil/pf/pf.c +++ b/sys/netpfil/pf/pf.c @@ -2838,27 +2838,6 @@ r->return_icmp6 & 255, af, r); } -static int -pf_ieee8021q_setpcp(struct mbuf *m, u_int8_t prio) -{ - struct m_tag *mtag; - - KASSERT(prio <= PF_PRIO_MAX, - ("%s with invalid pcp", __func__)); - - mtag = m_tag_locate(m, MTAG_8021Q, MTAG_8021Q_PCP_OUT, NULL); - if (mtag == NULL) { - mtag = m_tag_alloc(MTAG_8021Q, MTAG_8021Q_PCP_OUT, - sizeof(uint8_t), M_NOWAIT); - if (mtag == NULL) - return (ENOMEM); - m_tag_prepend(m, mtag); - } - - *(uint8_t *)(mtag + 1) = prio; - return (0); -} - static int pf_match_ieee8021q_pcp(u_int8_t prio, struct mbuf *m) { @@ -6393,7 +6372,7 @@ if (r->scrub_flags & PFSTATE_SETPRIO) { if (pd.tos & IPTOS_LOWDELAY) pqid = 1; - if (pf_ieee8021q_setpcp(m, r->set_prio[pqid])) { + if (vlan_set_pcp(m, r->set_prio[pqid])) { action = PF_DROP; REASON_SET(&reason, PFRES_MEMORY); log = 1; @@ -6842,7 +6821,7 @@ if (r->scrub_flags & PFSTATE_SETPRIO) { if (pd.tos & IPTOS_LOWDELAY) pqid = 1; - if (pf_ieee8021q_setpcp(m, r->set_prio[pqid])) { + if (vlan_set_pcp(m, r->set_prio[pqid])) { action = PF_DROP; REASON_SET(&reason, PFRES_MEMORY); log = 1;