From nobody Thu Sep 08 16:21:30 2022 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 4MNks62vMCz4cQtt; Thu, 8 Sep 2022 16:21:30 +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 4MNks62JHLz3V87; Thu, 8 Sep 2022 16:21:30 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1662654090; 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=hwEwCEfDDIPqUPd8Nz/UQIV8cE0V3nXrjjfX/ZS6VCc=; b=f78dmzvKM6josunfiDwKKbbsJA+pJpt8JTwYISbk8FtSPu3oWe4U0+JjEihsJgY39tdZMy SvPGK41t8girOJ4AAfHe9F9qRRx44AgWI46QkxatMefIuMH6lY7TrLLdwAvxGOeoZ9pfoS wzVB+6kC0tsZGEjkqmWIUQqQFj5tFoi0ppL2vrIRGbupZdvvN7OMjA9vYXH+rzq/K9vZIv 3v0/j7kOAahZZIU7+2KZ24qhlaD0dU0qU7cdCDTDpdEmGhnHg+no9z1HpO7LXGaMwXRGU8 t91hvVvpU6oZtUt1FxZkAhAJoj1JQUTTUvvy/ZxTyjuuX5aGkyoJ77rdF3UQhQ== 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 4MNks61LrXzwVk; Thu, 8 Sep 2022 16:21:30 +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 288GLU4e085872; Thu, 8 Sep 2022 16:21:30 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 288GLUik085871; Thu, 8 Sep 2022 16:21:30 GMT (envelope-from git) Date: Thu, 8 Sep 2022 16:21:30 GMT Message-Id: <202209081621.288GLUik085871@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mateusz Guzik Subject: git: 0b70e3e78b02 - main - net: add pfil_mbuf_{in,out} 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: mjg X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 0b70e3e78b0279c66be06dea27bcdaf5eadf663d Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1662654090; 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=hwEwCEfDDIPqUPd8Nz/UQIV8cE0V3nXrjjfX/ZS6VCc=; b=XFdefSetIJrYFsYXzCmZSZrQ+9JZEiavba5+h/Aba0+gCkokxe1ZZZ9SG0X8A2BWNezO6i QVrLP8PXzglQncrn0CUetfoWFUPQeMpV10aePloXkHkFHR9Y3hunBoINwqIa2b/FT6IIQS gQlF+C9l9cZFMmMqfJwj/r6wDXtKJbAd4hUw2HHM5zPh3yYJiNXm1ucRi1cf4nMWrNxNki ng+OClM/4BL2mIPAkvbTtxheo324f4mo3/PuMCA4FIwWHh1d2KQhbDjyFEiCOeo0cXaz89 sMPxNyYvKjI8Rjcrebz6QQVfKXIcInwsDzpY85A9K17knqvGRyURffDWT7eGaw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1662654090; a=rsa-sha256; cv=none; b=a0uahcz9jhWy5KSnKHFbFxSYCmLOaiExBImsQaEHYUGTm/1MMYaK/7XdL+hQzw6BNFbVWj vbaRoKgYK4GFxclVV6kKQEkZYq772YyQgomVGUlEIrIhn3Ci1tiGAqA7TN2xJo9bhB0gYa NLO882aq60AA4nmfds6ilwQW18rQIsVshxrhWabWHL8DYkza7qs5vH2+RwMYbp80mRwD6V bCvYwxLn/DxVnqthw5bCI84VgowriyfvR5TOEtB7ioh4f5t6QNMmQSo6C4nAsoCMOJqn7A lQlcKV7AY5mJkx80B932riFrMB7/NXjB0aFqa+ETSg1/uhEXCEFH7MXZroJS5Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by mjg: URL: https://cgit.FreeBSD.org/src/commit/?id=0b70e3e78b0279c66be06dea27bcdaf5eadf663d commit 0b70e3e78b0279c66be06dea27bcdaf5eadf663d Author: Mateusz Guzik AuthorDate: 2022-09-02 16:23:54 +0000 Commit: Mateusz Guzik CommitDate: 2022-09-08 16:20:43 +0000 net: add pfil_mbuf_{in,out} This shaves a lot of branching due to MEMPTR flag. Reviewed by: glebius Sponsored by: Rubicon Communications, LLC ("Netgate") Differential Revision: https://reviews.freebsd.org/D36454 --- sys/net/pfil.c | 36 ++++++++++++++++++++++++++++++++++++ sys/net/pfil.h | 4 ++++ 2 files changed, 40 insertions(+) diff --git a/sys/net/pfil.c b/sys/net/pfil.c index 85a0f031006b..b68fbe8db5c5 100644 --- a/sys/net/pfil.c +++ b/sys/net/pfil.c @@ -198,6 +198,42 @@ pfil_run_hooks(struct pfil_head *head, pfil_packet_t p, struct ifnet *ifp, return (rv); } +static __always_inline int +pfil_mbuf_common(pfil_chain_t *pch, pfil_packet_t p, struct ifnet *ifp, + int flags, struct inpcb *inp) +{ + struct pfil_link *link; + pfil_return_t rv; + + NET_EPOCH_ASSERT(); + KASSERT(flags == PFIL_IN || flags == PFIL_OUT, + ("%s: unsupported flags %d", __func__, flags)); + + rv = PFIL_PASS; + CK_STAILQ_FOREACH(link, pch, link_chain) { + rv = (*link->link_func)(p, ifp, flags, link->link_ruleset, inp); + if (rv == PFIL_DROPPED || rv == PFIL_CONSUMED) + break; + } + return (rv); +} + +int +pfil_mbuf_in(struct pfil_head *head, pfil_packet_t p, struct ifnet *ifp, + struct inpcb *inp) +{ + + return (pfil_mbuf_common(&head->head_in, p, ifp, PFIL_IN, inp)); +} + +int +pfil_mbuf_out(struct pfil_head *head, pfil_packet_t p, struct ifnet *ifp, + struct inpcb *inp) +{ + + return (pfil_mbuf_common(&head->head_out, p, ifp, PFIL_OUT, inp)); +} + /* * pfil_head_register() registers a pfil_head with the packet filter hook * mechanism. diff --git a/sys/net/pfil.h b/sys/net/pfil.h index 5caee0e715f9..d5e9eadd8b8c 100644 --- a/sys/net/pfil.h +++ b/sys/net/pfil.h @@ -194,6 +194,10 @@ void pfil_head_unregister(pfil_head_t); /* Public functions to run the packet inspection by inspection points. */ int pfil_run_hooks(struct pfil_head *, pfil_packet_t, struct ifnet *, int, struct inpcb *inp); +int pfil_mbuf_in(struct pfil_head *, pfil_packet_t, struct ifnet *, + struct inpcb *inp); +int pfil_mbuf_out(struct pfil_head *, pfil_packet_t, struct ifnet *, + struct inpcb *inp); /* * Minimally exposed structure to avoid function call in case of absence * of any filters by protocols and macros to do the check.