From owner-dev-commits-src-branches@freebsd.org Tue Feb 23 11:50:38 2021 Return-Path: Delivered-To: dev-commits-src-branches@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 8103D567E76; Tue, 23 Feb 2021 11:50:38 +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 4DlHRy3GtFz4rvQ; Tue, 23 Feb 2021 11:50:38 +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 6364F18BD4; Tue, 23 Feb 2021 11:50:38 +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 11NBoc6X054543; Tue, 23 Feb 2021 11:50:38 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 11NBoc2f054542; Tue, 23 Feb 2021 11:50:38 GMT (envelope-from git) Date: Tue, 23 Feb 2021 11:50:38 GMT Message-Id: <202102231150.11NBoc2f054542@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: 5d3b3e47a68b - stable/13 - pf: duplicate frames only once when using dup-to pf rule 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/13 X-Git-Reftype: branch X-Git-Commit: 5d3b3e47a68bf16b054add5f696d80789d1cb738 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 23 Feb 2021 11:50:38 -0000 The branch stable/13 has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=5d3b3e47a68bf16b054add5f696d80789d1cb738 commit 5d3b3e47a68bf16b054add5f696d80789d1cb738 Author: Yannis Planus AuthorDate: 2021-01-28 13:59:07 +0000 Commit: Kristof Provost CommitDate: 2021-02-23 11:46:24 +0000 pf: duplicate frames only once when using dup-to pf rule When using DUP-TO rule, frames are duplicated 3 times on both output interfaces and duplication interface. Add a flag to not duplicate a duplicated frame. Inspired by a patch from MiƂosz Kaniewski milosz.kaniewski at gmail.com https://lists.freebsd.org/pipermail/freebsd-pf/2015-November/007886.html Reviewed by: kp@ Differential Revision: https://reviews.freebsd.org/D27018 (cherry picked from commit 0c458752ceee14818034df7bfcdfb04129dceeda) --- sys/netpfil/pf/pf.c | 50 ++++++++++++++++++++++++++++++++++++++++++------ sys/netpfil/pf/pf_mtag.h | 1 + 2 files changed, 45 insertions(+), 6 deletions(-) diff --git a/sys/netpfil/pf/pf.c b/sys/netpfil/pf/pf.c index 4cccb0101650..86354e69d11f 100644 --- a/sys/netpfil/pf/pf.c +++ b/sys/netpfil/pf/pf.c @@ -5488,10 +5488,29 @@ pf_route(struct mbuf **m, struct pf_krule *r, int dir, struct ifnet *oifp, } if (r->rt == PF_DUPTO) { - if ((m0 = m_dup(*m, M_NOWAIT)) == NULL) { - if (s) + if ((pd->pf_mtag->flags & PF_DUPLICATED)) { + if (s == NULL) { + ifp = r->rpool.cur->kif ? + r->rpool.cur->kif->pfik_ifp : NULL; + } else { + ifp = s->rt_kif ? s->rt_kif->pfik_ifp : NULL; PF_STATE_UNLOCK(s); - return; + } + if (ifp == oifp) { + /* When the 2nd interface is not skipped */ + return; + } else { + m0 = *m; + *m = NULL; + goto bad; + } + } else { + pd->pf_mtag->flags |= PF_DUPLICATED; + if (((m0 = m_dup(*m, M_NOWAIT)) == NULL)) { + if (s) + PF_STATE_UNLOCK(s); + return; + } } } else { if ((r->rt == PF_REPLYTO) == (r->direction == dir)) { @@ -5649,10 +5668,29 @@ pf_route6(struct mbuf **m, struct pf_krule *r, int dir, struct ifnet *oifp, } if (r->rt == PF_DUPTO) { - if ((m0 = m_dup(*m, M_NOWAIT)) == NULL) { - if (s) + if ((pd->pf_mtag->flags & PF_DUPLICATED)) { + if (s == NULL) { + ifp = r->rpool.cur->kif ? + r->rpool.cur->kif->pfik_ifp : NULL; + } else { + ifp = s->rt_kif ? s->rt_kif->pfik_ifp : NULL; PF_STATE_UNLOCK(s); - return; + } + if (ifp == oifp) { + /* When the 2nd interface is not skipped */ + return; + } else { + m0 = *m; + *m = NULL; + goto bad; + } + } else { + pd->pf_mtag->flags |= PF_DUPLICATED; + if (((m0 = m_dup(*m, M_NOWAIT)) == NULL)) { + if (s) + PF_STATE_UNLOCK(s); + return; + } } } else { if ((r->rt == PF_REPLYTO) == (r->direction == dir)) { diff --git a/sys/netpfil/pf/pf_mtag.h b/sys/netpfil/pf/pf_mtag.h index 67c79350e8eb..ad28ab7a7c30 100644 --- a/sys/netpfil/pf/pf_mtag.h +++ b/sys/netpfil/pf/pf_mtag.h @@ -42,6 +42,7 @@ #define PF_PACKET_LOOPED 0x08 #define PF_FASTFWD_OURS_PRESENT 0x10 #define PF_REASSEMBLED 0x20 +#define PF_DUPLICATED 0x40 struct pf_mtag { void *hdr; /* saved hdr pos in mbuf, for ECN */