vlan: deduplicate bpf_setpcp() and pf_ieee8021q_setpcp()
These two fuctions were identical, so move them into the common vlan_set_pcp() function, exposed in the if_vlan_var.h header. Reviewed by: donner MFC after: 1 week Sponsored by: Rubicon Communications, LLC ("Netgate") Differential Revision: https://reviews.freebsd.org/D31275
This commit is contained in:
parent
1e7fe2fbb9
commit
9ef8cd0b79
@ -1172,27 +1172,6 @@ bpf_ready(struct bpf_d *d)
|
|||||||
return (0);
|
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
|
static int
|
||||||
bpfwrite(struct cdev *dev, struct uio *uio, int ioflag)
|
bpfwrite(struct cdev *dev, struct uio *uio, int ioflag)
|
||||||
{
|
{
|
||||||
@ -1294,7 +1273,7 @@ bpfwrite(struct cdev *dev, struct uio *uio, int ioflag)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (d->bd_pcp != 0)
|
if (d->bd_pcp != 0)
|
||||||
bpf_setpcp(m, d->bd_pcp);
|
vlan_set_pcp(m, d->bd_pcp);
|
||||||
|
|
||||||
/* Avoid possible recursion on BPFD_LOCK(). */
|
/* Avoid possible recursion on BPFD_LOCK(). */
|
||||||
NET_EPOCH_ENTER(et);
|
NET_EPOCH_ENTER(et);
|
||||||
|
@ -2040,7 +2040,7 @@ vlan_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
|
|||||||
error = priv_check(curthread, PRIV_NET_SETVLANPCP);
|
error = priv_check(curthread, PRIV_NET_SETVLANPCP);
|
||||||
if (error)
|
if (error)
|
||||||
break;
|
break;
|
||||||
if (ifr->ifr_vlan_pcp > 7) {
|
if (ifr->ifr_vlan_pcp > VLAN_PCP_MAX) {
|
||||||
error = EINVAL;
|
error = EINVAL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,8 @@
|
|||||||
#ifndef _NET_IF_VLAN_VAR_H_
|
#ifndef _NET_IF_VLAN_VAR_H_
|
||||||
#define _NET_IF_VLAN_VAR_H_ 1
|
#define _NET_IF_VLAN_VAR_H_ 1
|
||||||
|
|
||||||
|
#include <sys/mbuf.h>
|
||||||
|
|
||||||
/* Set the VLAN ID in an mbuf packet header non-destructively. */
|
/* Set the VLAN ID in an mbuf packet header non-destructively. */
|
||||||
#define EVL_APPLY_VLID(m, vlid) \
|
#define EVL_APPLY_VLID(m, vlid) \
|
||||||
do { \
|
do { \
|
||||||
@ -124,6 +126,8 @@ struct vlanreq {
|
|||||||
#define MTAG_8021Q_PCP_IN 0 /* Input priority. */
|
#define MTAG_8021Q_PCP_IN 0 /* Input priority. */
|
||||||
#define MTAG_8021Q_PCP_OUT 1 /* Output 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.
|
* 802.1q full tag. Proto and vid are stored in host byte order.
|
||||||
*/
|
*/
|
||||||
@ -168,6 +172,28 @@ typedef void (*vlan_unconfig_fn)(void *, struct ifnet *, uint16_t);
|
|||||||
EVENTHANDLER_DECLARE(vlan_config, vlan_config_fn);
|
EVENTHANDLER_DECLARE(vlan_config, vlan_config_fn);
|
||||||
EVENTHANDLER_DECLARE(vlan_unconfig, vlan_unconfig_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 /* _KERNEL */
|
||||||
|
|
||||||
#endif /* _NET_IF_VLAN_VAR_H_ */
|
#endif /* _NET_IF_VLAN_VAR_H_ */
|
||||||
|
@ -2838,27 +2838,6 @@ pf_return(struct pf_krule *r, struct pf_krule *nr, struct pf_pdesc *pd,
|
|||||||
r->return_icmp6 & 255, af, r);
|
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
|
static int
|
||||||
pf_match_ieee8021q_pcp(u_int8_t prio, struct mbuf *m)
|
pf_match_ieee8021q_pcp(u_int8_t prio, struct mbuf *m)
|
||||||
{
|
{
|
||||||
@ -6393,7 +6372,7 @@ done:
|
|||||||
if (r->scrub_flags & PFSTATE_SETPRIO) {
|
if (r->scrub_flags & PFSTATE_SETPRIO) {
|
||||||
if (pd.tos & IPTOS_LOWDELAY)
|
if (pd.tos & IPTOS_LOWDELAY)
|
||||||
pqid = 1;
|
pqid = 1;
|
||||||
if (pf_ieee8021q_setpcp(m, r->set_prio[pqid])) {
|
if (vlan_set_pcp(m, r->set_prio[pqid])) {
|
||||||
action = PF_DROP;
|
action = PF_DROP;
|
||||||
REASON_SET(&reason, PFRES_MEMORY);
|
REASON_SET(&reason, PFRES_MEMORY);
|
||||||
log = 1;
|
log = 1;
|
||||||
@ -6842,7 +6821,7 @@ done:
|
|||||||
if (r->scrub_flags & PFSTATE_SETPRIO) {
|
if (r->scrub_flags & PFSTATE_SETPRIO) {
|
||||||
if (pd.tos & IPTOS_LOWDELAY)
|
if (pd.tos & IPTOS_LOWDELAY)
|
||||||
pqid = 1;
|
pqid = 1;
|
||||||
if (pf_ieee8021q_setpcp(m, r->set_prio[pqid])) {
|
if (vlan_set_pcp(m, r->set_prio[pqid])) {
|
||||||
action = PF_DROP;
|
action = PF_DROP;
|
||||||
REASON_SET(&reason, PFRES_MEMORY);
|
REASON_SET(&reason, PFRES_MEMORY);
|
||||||
log = 1;
|
log = 1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user