From owner-dev-commits-src-all@freebsd.org Mon Aug 2 15:04:10 2021 Return-Path: Delivered-To: dev-commits-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id A252F675AE5; Mon, 2 Aug 2021 15:04:10 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Gdh9P5bs4z4YnS; Mon, 2 Aug 2021 15:04:09 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 59E6321672; Mon, 2 Aug 2021 15:04:09 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 172F49km071579; Mon, 2 Aug 2021 15:04:09 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 172F491L071578; Mon, 2 Aug 2021 15:04:09 GMT (envelope-from git) Date: Mon, 2 Aug 2021 15:04:09 GMT Message-Id: <202108021504.172F491L071578@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kristof Provost Subject: git: 666a7f460270 - stable/12 - vlan: deduplicate bpf_setpcp() and pf_ieee8021q_setpcp() MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kp X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: 666a7f4602708cb730c784c5d4a9ef34b620f721 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 02 Aug 2021 15:04:10 -0000 The branch stable/12 has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=666a7f4602708cb730c784c5d4a9ef34b620f721 commit 666a7f4602708cb730c784c5d4a9ef34b620f721 Author: Kristof Provost AuthorDate: 2021-07-22 08:35:08 +0000 Commit: Kristof Provost 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 + /* 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;