git: 666a7f460270 - stable/12 - vlan: deduplicate bpf_setpcp() and pf_ieee8021q_setpcp()
Kristof Provost
kp at FreeBSD.org
Mon Aug 2 15:04:10 UTC 2021
The branch stable/12 has been updated by kp:
URL: https://cgit.FreeBSD.org/src/commit/?id=666a7f4602708cb730c784c5d4a9ef34b620f721
commit 666a7f4602708cb730c784c5d4a9ef34b620f721
Author: Kristof Provost <kp at FreeBSD.org>
AuthorDate: 2021-07-22 08:35:08 +0000
Commit: Kristof Provost <kp at FreeBSD.org>
CommitDate: 2021-08-02 15:03:03 +0000
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
(cherry picked from commit 9ef8cd0b7906371803421aa897056b6fc0710fcb)
---
sys/net/bpf.c | 23 +----------------------
sys/net/if_vlan.c | 2 +-
sys/net/if_vlan_var.h | 26 ++++++++++++++++++++++++++
sys/netpfil/pf/pf.c | 25 ++-----------------------
4 files changed, 30 insertions(+), 46 deletions(-)
diff --git a/sys/net/bpf.c b/sys/net/bpf.c
index 7e0af0cfebc0..5ca92a97f74f 100644
--- a/sys/net/bpf.c
+++ b/sys/net/bpf.c
@@ -1121,27 +1121,6 @@ bpf_ready(struct bpf_d *d)
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)
{
@@ -1221,7 +1200,7 @@ bpfwrite(struct cdev *dev, struct uio *uio, int ioflag)
}
if (d->bd_pcp != 0)
- bpf_setpcp(m, d->bd_pcp);
+ vlan_set_pcp(m, d->bd_pcp);
error = (*ifp->if_output)(ifp, m, &dst, &ro);
if (error)
diff --git a/sys/net/if_vlan.c b/sys/net/if_vlan.c
index 2f1b1dec9603..a055c978c32f 100644
--- a/sys/net/if_vlan.c
+++ b/sys/net/if_vlan.c
@@ -1943,7 +1943,7 @@ vlan_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
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
index 0b66ec0a0a1e..aaf64efe3d7f 100644
--- 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 <sys/mbuf.h>
+
/* Set the VLAN ID in an mbuf packet header non-destructively. */
#define EVL_APPLY_VLID(m, vlid) \
do { \
@@ -123,6 +125,8 @@ struct vlanreq {
#define MTAG_8021Q_PCP_IN 0 /* Input priority. */
#define MTAG_8021Q_PCP_OUT 1 /* Output priority. */
+#define VLAN_PCP_MAX 7
+
#define VLAN_CAPABILITIES(_ifp) do { \
if ((_ifp)->if_vlantrunk != NULL) \
(*vlan_trunk_cap_p)(_ifp); \
@@ -158,6 +162,28 @@ EVENTHANDLER_DECLARE(vlan_config, vlan_config_fn);
EVENTHANDLER_DECLARE(vlan_unconfig, vlan_unconfig_fn);
#endif /* _SYS_EVENTHANDLER_H_ */
+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
index 7b2812a952ce..caae2b92f0d6 100644
--- a/sys/netpfil/pf/pf.c
+++ b/sys/netpfil/pf/pf.c
@@ -2717,27 +2717,6 @@ pf_return(struct pf_krule *r, struct pf_krule *nr, struct pf_pdesc *pd,
}
-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)
{
@@ -6351,7 +6330,7 @@ done:
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;
@@ -6803,7 +6782,7 @@ done:
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;
More information about the dev-commits-src-all
mailing list