From nobody Tue Jan 31 20:03:11 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4P5ww00hNLz3c87l; Tue, 31 Jan 2023 20:03:12 +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 4P5wvz6zgcz3CKt; Tue, 31 Jan 2023 20:03:11 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675195392; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=BzYfXJXGPePAf+NFw59SxGIz25ffqF+E/UdTMUGfo1k=; b=j8eveICt2wiPX+ov9G+K4i/B1/NCXOfevb/m4JbkJDyxjZ2R09CN9guDdjqplY1divHvhe Mf15d7MCZ/EjNzORJ6uExako6WijE8CB7YNf76ALbSCCSNYSVpZDglvXdSwCezOQ0gLzKa pKbbsgjem8LPhctO6n34XdUhUbDkvIa0SIv3oiFkQ8LIEEVmw7INFixM/W1DACRhLiFrLm WGBsAc5EkrKOxPinGPCZY4fy9quKkEr5Oz0KqMa+3coCAlSXZ4Dm3A9dljCqq0n+T0v6YB DBh8s9F2xXOr9gPXDVGS4UyxgmRHwGSkvueiTNa1V/oZLHQrIybPxgDrkpOwOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675195392; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=BzYfXJXGPePAf+NFw59SxGIz25ffqF+E/UdTMUGfo1k=; b=wq4XBQBHri0F3mY0+NtymZEMI9qN5NI2ThaW6/+2pSFQ0XoBAnuJSaGwu1iOpZlXoVKPN2 RJcU2VJwMHrApA5VN45NzXLa1Nj/zcHkR2zXwgjeCUjL7zuBQU/Vg117d5tuEfKFG32O+t WcNEVGB/r3Cf22kLfmo2owa2HoYkl7NA3NddJMorqqp2jWzknEEG7dKbCyaHCdegI+Ij0X Ci4JiCjlRyLIRVpOUvxgrU6+B89G+RTtfT/rO+3U/JhkuMgR+CKWbDzprqfo1Ci9998Rlh n9YpRDFiyUhG4IGFLKcsL5quJJZiIpnUN/2F/5HlEEOwjjnkM8GmUEeJdyKNtw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1675195392; a=rsa-sha256; cv=none; b=GCWBM0qDbxmGDiqyIE4QES9dtppANhCWLOmoeppj5FqDMJ9kHbmSA4lpIsrwpkvyRgNi1f gIJQEz/hJ5quEpavbCk2g+dshblLO5FaWG59lUGXyHDvHi21Y6viAfO2DoUwWhdsmRVkKi X4aR9HoCS6RbRKXHGtt7rFaURPIgDx65sJGO6TB/p3as8Etvr6XSGNb0ZuSrMRpZ7JoAxP y4yEjCPUtzgX+MtlJGMEcZZeb2NQRCufNplCXzKMLqbmdUnGq8joJVoPBbRKmFEfeQSPR0 fc7hwOnMO4wQaAhiO0alZnTuJB8XVHfpDtBOWJdCcYXcBZlEkP31gdBLbd2uxA== 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 4P5wvz62Kdz11kF; Tue, 31 Jan 2023 20:03:11 +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 30VK3Bg9024804; Tue, 31 Jan 2023 20:03:11 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 30VK3BSD024803; Tue, 31 Jan 2023 20:03:11 GMT (envelope-from git) Date: Tue, 31 Jan 2023 20:03:11 GMT Message-Id: <202301312003.30VK3BSD024803@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Justin Hibbits Subject: git: 1bfa548b1f16 - main - ifnet/API: Privatize the implementation of the drbr_* APIs List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhibbits X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 1bfa548b1f1687f16a738590ee88843ed3c73ae8 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by jhibbits: URL: https://cgit.FreeBSD.org/src/commit/?id=1bfa548b1f1687f16a738590ee88843ed3c73ae8 commit 1bfa548b1f1687f16a738590ee88843ed3c73ae8 Author: Justin Hibbits AuthorDate: 2023-01-13 16:40:31 +0000 Commit: Justin Hibbits CommitDate: 2023-01-31 20:02:14 +0000 ifnet/API: Privatize the implementation of the drbr_* APIs When ALTQ is enabled ifnet accessors already need to be called, largely defeating the purpose of the inline. To that extent, make the ALTQ form functions in the netstack proper, and make them always available. Reviewed By: glebius Sponsored by: Juniper Networks, Inc. Differential Revision: https://reviews.freebsd.org/D38104 --- sys/conf/files | 1 + sys/net/ifq.c | 176 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ sys/net/ifq.h | 104 ++++++++-------------------------- 3 files changed, 200 insertions(+), 81 deletions(-) diff --git a/sys/conf/files b/sys/conf/files index b85ab6955adb..6cb4abcd9223 100644 --- a/sys/conf/files +++ b/sys/conf/files @@ -4141,6 +4141,7 @@ net/bpf_zerocopy.c optional bpf net/bridgestp.c optional bridge | if_bridge net/ieee8023ad_lacp.c optional lagg net/if.c standard +net/ifq.c standard net/if_bridge.c optional bridge inet | if_bridge inet net/if_clone.c standard net/if_dead.c standard diff --git a/sys/net/ifq.c b/sys/net/ifq.c new file mode 100644 index 000000000000..0e3159a75d48 --- /dev/null +++ b/sys/net/ifq.c @@ -0,0 +1,176 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1982, 1986, 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * From: @(#)if.h 8.1 (Berkeley) 6/10/93 + */ + +#include +#include + +#ifndef ALTQ +#define ALTQ /* Needed for ifq.h prototypes only. */ +#endif + +#include +#include +#include + +int +drbr_enqueue(struct ifnet *ifp, struct buf_ring *br, struct mbuf *m) +{ + int error = 0; + + if (ALTQ_IS_ENABLED(&ifp->if_snd)) { + IFQ_ENQUEUE(&ifp->if_snd, m, error); + if (error) + if_inc_counter((ifp), IFCOUNTER_OQDROPS, 1); + return (error); + } + error = buf_ring_enqueue(br, m); + if (error) + m_freem(m); + + return (error); +} + +void +drbr_putback(struct ifnet *ifp, struct buf_ring *br, struct mbuf *m_new) +{ + /* + * The top of the list needs to be swapped + * for this one. + */ + if (ifp != NULL && ALTQ_IS_ENABLED(&ifp->if_snd)) { + /* + * Peek in altq case dequeued it + * so put it back. + */ + IFQ_DRV_PREPEND(&ifp->if_snd, m_new); + return; + } + buf_ring_putback_sc(br, m_new); +} + +struct mbuf * +drbr_peek(struct ifnet *ifp, struct buf_ring *br) +{ + struct mbuf *m; + if (ifp != NULL && ALTQ_IS_ENABLED(&ifp->if_snd)) { + /* + * Pull it off like a dequeue + * since drbr_advance() does nothing + * for altq and drbr_putback() will + * use the old prepend function. + */ + IFQ_DEQUEUE(&ifp->if_snd, m); + return (m); + } + return ((struct mbuf *)buf_ring_peek_clear_sc(br)); +} + +void +drbr_flush(struct ifnet *ifp, struct buf_ring *br) +{ + struct mbuf *m; + + if (ifp != NULL && ALTQ_IS_ENABLED(&ifp->if_snd)) + IFQ_PURGE(&ifp->if_snd); + while ((m = (struct mbuf *)buf_ring_dequeue_sc(br)) != NULL) + m_freem(m); +} + +struct mbuf * +drbr_dequeue(struct ifnet *ifp, struct buf_ring *br) +{ + struct mbuf *m; + + if (ifp != NULL && ALTQ_IS_ENABLED(&ifp->if_snd)) { + IFQ_DEQUEUE(&ifp->if_snd, m); + return (m); + } + return ((struct mbuf *)buf_ring_dequeue_sc(br)); +} + +void +drbr_advance(struct ifnet *ifp, struct buf_ring *br) +{ + /* Nothing to do here since peek dequeues in altq case */ + if (ifp != NULL && ALTQ_IS_ENABLED(&ifp->if_snd)) + return; + return (buf_ring_advance_sc(br)); +} + +struct mbuf * +drbr_dequeue_cond(struct ifnet *ifp, struct buf_ring *br, + int (*func) (struct mbuf *, void *), void *arg) +{ + struct mbuf *m; + if (ALTQ_IS_ENABLED(&ifp->if_snd)) { + IFQ_LOCK(&ifp->if_snd); + IFQ_POLL_NOLOCK(&ifp->if_snd, m); + if (m != NULL && func(m, arg) == 0) { + IFQ_UNLOCK(&ifp->if_snd); + return (NULL); + } + IFQ_DEQUEUE_NOLOCK(&ifp->if_snd, m); + IFQ_UNLOCK(&ifp->if_snd); + return (m); + } + m = (struct mbuf *)buf_ring_peek(br); + if (m == NULL || func(m, arg) == 0) + return (NULL); + + return ((struct mbuf *)buf_ring_dequeue_sc(br)); +} + +int +drbr_empty(struct ifnet *ifp, struct buf_ring *br) +{ + if (ALTQ_IS_ENABLED(&ifp->if_snd)) + return (IFQ_IS_EMPTY(&ifp->if_snd)); + return (buf_ring_empty(br)); +} + +int +drbr_needs_enqueue(struct ifnet *ifp, struct buf_ring *br) +{ + if (ALTQ_IS_ENABLED(&ifp->if_snd)) + return (1); + return (!buf_ring_empty(br)); +} + +int +drbr_inuse(struct ifnet *ifp, struct buf_ring *br) +{ + if (ALTQ_IS_ENABLED(&ifp->if_snd)) + return (ifp->if_snd.ifq_len); + return (buf_ring_count(br)); +} + diff --git a/sys/net/ifq.h b/sys/net/ifq.h index 9a8f9a876423..e4dbf8929b1f 100644 --- a/sys/net/ifq.h +++ b/sys/net/ifq.h @@ -315,19 +315,25 @@ do { \ IFQ_PURGE(ifq); \ } while (0) +#ifdef ALTQ +int drbr_enqueue(struct ifnet *ifp, struct buf_ring *br, struct mbuf *m); +void drbr_putback(struct ifnet *ifp, struct buf_ring *br, struct mbuf *m_new); +struct mbuf *drbr_peek(struct ifnet *ifp, struct buf_ring *br); +void drbr_flush(struct ifnet *ifp, struct buf_ring *br); +struct mbuf *drbr_dequeue(struct ifnet *ifp, struct buf_ring *br); +void drbr_advance(struct ifnet *ifp, struct buf_ring *br); +struct mbuf *drbr_dequeue_cond(struct ifnet *ifp, struct buf_ring *br, + int (*func) (struct mbuf *, void *), void *arg); +int drbr_empty(struct ifnet *ifp, struct buf_ring *br); +int drbr_needs_enqueue(struct ifnet *ifp, struct buf_ring *br); +int drbr_inuse(struct ifnet *ifp, struct buf_ring *br); + +#else /* !ALTQ */ static __inline int drbr_enqueue(struct ifnet *ifp, struct buf_ring *br, struct mbuf *m) { int error = 0; -#ifdef ALTQ - if (ALTQ_IS_ENABLED(&ifp->if_snd)) { - IFQ_ENQUEUE(&ifp->if_snd, m, error); - if (error) - if_inc_counter((ifp), IFCOUNTER_OQDROPS, 1); - return (error); - } -#endif error = buf_ring_enqueue(br, m); if (error) m_freem(m); @@ -342,35 +348,12 @@ drbr_putback(struct ifnet *ifp, struct buf_ring *br, struct mbuf *m_new) * The top of the list needs to be swapped * for this one. */ -#ifdef ALTQ - if (ifp != NULL && ALTQ_IS_ENABLED(&ifp->if_snd)) { - /* - * Peek in altq case dequeued it - * so put it back. - */ - IFQ_DRV_PREPEND(&ifp->if_snd, m_new); - return; - } -#endif buf_ring_putback_sc(br, m_new); } static __inline struct mbuf * drbr_peek(struct ifnet *ifp, struct buf_ring *br) { -#ifdef ALTQ - struct mbuf *m; - if (ifp != NULL && ALTQ_IS_ENABLED(&ifp->if_snd)) { - /* - * Pull it off like a dequeue - * since drbr_advance() does nothing - * for altq and drbr_putback() will - * use the old prepend function. - */ - IFQ_DEQUEUE(&ifp->if_snd, m); - return (m); - } -#endif return ((struct mbuf *)buf_ring_peek_clear_sc(br)); } @@ -379,44 +362,19 @@ drbr_flush(struct ifnet *ifp, struct buf_ring *br) { struct mbuf *m; -#ifdef ALTQ - if (ifp != NULL && ALTQ_IS_ENABLED(&ifp->if_snd)) - IFQ_PURGE(&ifp->if_snd); -#endif while ((m = (struct mbuf *)buf_ring_dequeue_sc(br)) != NULL) m_freem(m); } -static __inline void -drbr_free(struct buf_ring *br, struct malloc_type *type) -{ - - drbr_flush(NULL, br); - buf_ring_free(br, type); -} - static __inline struct mbuf * drbr_dequeue(struct ifnet *ifp, struct buf_ring *br) { -#ifdef ALTQ - struct mbuf *m; - - if (ifp != NULL && ALTQ_IS_ENABLED(&ifp->if_snd)) { - IFQ_DEQUEUE(&ifp->if_snd, m); - return (m); - } -#endif return ((struct mbuf *)buf_ring_dequeue_sc(br)); } static __inline void drbr_advance(struct ifnet *ifp, struct buf_ring *br) { -#ifdef ALTQ - /* Nothing to do here since peek dequeues in altq case */ - if (ifp != NULL && ALTQ_IS_ENABLED(&ifp->if_snd)) - return; -#endif return (buf_ring_advance_sc(br)); } @@ -425,19 +383,6 @@ drbr_dequeue_cond(struct ifnet *ifp, struct buf_ring *br, int (*func) (struct mbuf *, void *), void *arg) { struct mbuf *m; -#ifdef ALTQ - if (ALTQ_IS_ENABLED(&ifp->if_snd)) { - IFQ_LOCK(&ifp->if_snd); - IFQ_POLL_NOLOCK(&ifp->if_snd, m); - if (m != NULL && func(m, arg) == 0) { - IFQ_UNLOCK(&ifp->if_snd); - return (NULL); - } - IFQ_DEQUEUE_NOLOCK(&ifp->if_snd, m); - IFQ_UNLOCK(&ifp->if_snd); - return (m); - } -#endif m = (struct mbuf *)buf_ring_peek(br); if (m == NULL || func(m, arg) == 0) return (NULL); @@ -448,32 +393,29 @@ drbr_dequeue_cond(struct ifnet *ifp, struct buf_ring *br, static __inline int drbr_empty(struct ifnet *ifp, struct buf_ring *br) { -#ifdef ALTQ - if (ALTQ_IS_ENABLED(&ifp->if_snd)) - return (IFQ_IS_EMPTY(&ifp->if_snd)); -#endif return (buf_ring_empty(br)); } static __inline int drbr_needs_enqueue(struct ifnet *ifp, struct buf_ring *br) { -#ifdef ALTQ - if (ALTQ_IS_ENABLED(&ifp->if_snd)) - return (1); -#endif return (!buf_ring_empty(br)); } static __inline int drbr_inuse(struct ifnet *ifp, struct buf_ring *br) { -#ifdef ALTQ - if (ALTQ_IS_ENABLED(&ifp->if_snd)) - return (ifp->if_snd.ifq_len); -#endif return (buf_ring_count(br)); } +#endif /* ALTQ */ + +static __inline void +drbr_free(struct buf_ring *br, struct malloc_type *type) +{ + + drbr_flush(NULL, br); + buf_ring_free(br, type); +} extern int ifqmaxlen;