From nobody Fri Jun 2 14:56:30 2023 X-Original-To: dev-commits-src-main@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 4QXmKp5SfCz4YfkT; Fri, 2 Jun 2023 14:56: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 4QXmKp52nCz4Gy1; Fri, 2 Jun 2023 14:56:30 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1685717790; 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=J91iwyfqPe7FEhHPRDmHbFYHBEpIEjaBqDph4aJfIFE=; b=ULES3ijmyRrn01RbYCwf5AkIuVzAMUlneeLBZmdgKkPg5wadn/r1VwChdHtcTwDmwO8Ai4 iKtkcwUM2GPj1buOUrVCojWleMfc63h4wxMQW2jw1O1XpIvK7AorA3oG2QMq8eimRFfcXt CG9A/lRk2bGoyvdO3zSGB0fX3qsq20VL2xQUyo+jY0BaJxG+FgzzPvJRdAmKVf5+iUh1Er 9jubKtUSLlBjlaU0maxsg+10lkKNt5ZHzFf0hTRXQllvdKJsSEhv5r7Yct/thjMIiG5rT1 GEGkJn0RTayHdbwRtICj5Fb4YMUDj0Hx9YoD4MhKJLfabwDhjDAr21zVvUAX2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1685717790; 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=J91iwyfqPe7FEhHPRDmHbFYHBEpIEjaBqDph4aJfIFE=; b=H7L9H8xmFNSeo2IHopMUdJzOQiSaR2+0l/3VF8HN8Oc6reS7/x9l0Bd4PekLQ//HAwDJMz 7efY0BzbudvcQ8apF91HUTS6N3e4LQB9hqIAytkfEy2GaugpGpPfzbMC4LXpv05PUE0jzN JpKshiUuYYFi6vCJrWCOGLf/8PfPMog3bhk5qPxdlYJPw/jvHEyNJ5JJ3vFZdqsL5iqE23 3NTfpbNjCpjyzblaJ6C/bAfl8GMGNucXLdGjgdVEfMr5RjYle7QvR1vtM1A7Czy6NsFyJE Km76w/uNiQHJR4bYVEktOadSdUtDZVejhV/gFQz2LHstez1+zYa3arIIW2ZUgA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1685717790; a=rsa-sha256; cv=none; b=wYldUN19GMmACI84UY3IoeB+lARuh6Ba361Q1LvuA3XqjDj/P89FzruqceGugEX3fAGcap wsg9W9h7ZWVXBH4a0VQ+fxrHggBvsTp7Kyz20lFfSy2JtRVEal/h7AOSBdTJnNoFg8r6Yc JIYxDP5pcVIdkHN3XUUQB3k63tSXT37qRe+bqH0eo5opIkshJx+VgDqoZLzCaIDjHUVQfj CnI12uDksGJL/+dFEeDmRHFBE3W6F6TxeFhQpBIBpLzZ3YkA7C2bqrwWIf8P7v0Oj1RxN4 n/PmRi1R+E42ChAC37wYGYGn4mal2OaTAitlvanz1AGZ+T+HsUT7clhD7LX1RQ== 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 4QXmKp489dz13Sf; Fri, 2 Jun 2023 14:56: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 352EuUs9026536; Fri, 2 Jun 2023 14:56:30 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 352EuUoI026535; Fri, 2 Jun 2023 14:56:30 GMT (envelope-from git) Date: Fri, 2 Jun 2023 14:56:30 GMT Message-Id: <202306021456.352EuUoI026535@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kristof Provost Subject: git: 9925aee0aaec - main - pf: carry over rule actions from route-to rules List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org 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/main X-Git-Reftype: branch X-Git-Commit: 9925aee0aaeccabd26f41625694a97b64185a59d Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=9925aee0aaeccabd26f41625694a97b64185a59d commit 9925aee0aaeccabd26f41625694a97b64185a59d Author: Kristof Provost AuthorDate: 2023-05-30 19:17:54 +0000 Commit: Kristof Provost CommitDate: 2023-06-02 14:05:30 +0000 pf: carry over rule actions from route-to rules If we route-to (or dup-to/reply-to) we re-run pf_test(), which will also create states for the connection. This means that we may end up matching a different (i.e. not the state that was created by the route-to rule) state, without the attributes (such as dummynet pipes/queues) set by the route-to rule. Address this by inheriting the pf_rule_actions from the route-to rule while evaluating the connection again in pf_test(). That is, we set default pf_rule_actions based on the route-to rule for the new evaluation. The new rule may still overrule these, but if it does not have such actions the route-to actions are applied. Do the same for IPv6 rules in pf_test6()/pf_route6(). See also: https://redmine.pfsense.org/issues/14039 Sponsored by: Rubicon Communications, LLC ("Netgate") Differential Revision: https://reviews.freebsd.org/D40340 --- sys/net/pfvar.h | 6 ++++-- sys/netpfil/pf/pf.c | 16 +++++++++++----- sys/netpfil/pf/pf_ioctl.c | 9 +++++---- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/sys/net/pfvar.h b/sys/net/pfvar.h index 2f2cc1632edc..a658573cf6f1 100644 --- a/sys/net/pfvar.h +++ b/sys/net/pfvar.h @@ -2230,13 +2230,15 @@ void pf_free_rule(struct pf_krule *); int pf_test_eth(int, int, struct ifnet *, struct mbuf **, struct inpcb *); #ifdef INET -int pf_test(int, int, struct ifnet *, struct mbuf **, struct inpcb *); +int pf_test(int, int, struct ifnet *, struct mbuf **, struct inpcb *, + struct pf_rule_actions *); int pf_normalize_ip(struct mbuf **, int, struct pfi_kkif *, u_short *, struct pf_pdesc *); #endif /* INET */ #ifdef INET6 -int pf_test6(int, int, struct ifnet *, struct mbuf **, struct inpcb *); +int pf_test6(int, int, struct ifnet *, struct mbuf **, struct inpcb *, + struct pf_rule_actions *); int pf_normalize_ip6(struct mbuf **, int, struct pfi_kkif *, u_short *, struct pf_pdesc *); void pf_poolmask(struct pf_addr *, struct pf_addr*, diff --git a/sys/netpfil/pf/pf.c b/sys/netpfil/pf/pf.c index 75c58609318c..78bd8b1dab12 100644 --- a/sys/netpfil/pf/pf.c +++ b/sys/netpfil/pf/pf.c @@ -6546,7 +6546,7 @@ pf_route(struct mbuf **m, struct pf_krule *r, int dir, struct ifnet *oifp, goto bad; if (dir == PF_IN) { - if (pf_test(PF_OUT, 0, ifp, &m0, inp) != PF_PASS) + if (pf_test(PF_OUT, 0, ifp, &m0, inp, &pd->act) != PF_PASS) goto bad; else if (m0 == NULL) goto done; @@ -6762,7 +6762,7 @@ pf_route6(struct mbuf **m, struct pf_krule *r, int dir, struct ifnet *oifp, goto bad; if (dir == PF_IN) { - if (pf_test6(PF_OUT, 0, ifp, &m0, inp) != PF_PASS) + if (pf_test6(PF_OUT, 0, ifp, &m0, inp, &pd->act) != PF_PASS) goto bad; else if (m0 == NULL) goto done; @@ -7120,7 +7120,8 @@ pf_dummynet_route(struct pf_pdesc *pd, int dir, struct pf_kstate *s, #ifdef INET int -pf_test(int dir, int pflags, struct ifnet *ifp, struct mbuf **m0, struct inpcb *inp) +pf_test(int dir, int pflags, struct ifnet *ifp, struct mbuf **m0, + struct inpcb *inp, struct pf_rule_actions *default_actions) { struct pfi_kkif *kif; u_short action, reason = 0, log = 0; @@ -7172,6 +7173,8 @@ pf_test(int dir, int pflags, struct ifnet *ifp, struct mbuf **m0, struct inpcb * } memset(&pd, 0, sizeof(pd)); + if (default_actions != NULL) + memcpy(&pd.act, default_actions, sizeof(pd.act)); pd.pf_mtag = pf_find_mtag(m); if (pd.pf_mtag != NULL && (pd.pf_mtag->flags & PF_TAG_ROUTE_TO)) { @@ -7312,7 +7315,7 @@ pf_test(int dir, int pflags, struct ifnet *ifp, struct mbuf **m0, struct inpcb * break; } - action = pf_test(dir, pflags, ifp, &msyn, inp); + action = pf_test(dir, pflags, ifp, &msyn, inp, &pd.act); m_freem(msyn); if (action == PF_PASS) { @@ -7682,7 +7685,8 @@ done: #ifdef INET6 int -pf_test6(int dir, int pflags, struct ifnet *ifp, struct mbuf **m0, struct inpcb *inp) +pf_test6(int dir, int pflags, struct ifnet *ifp, struct mbuf **m0, struct inpcb *inp, + struct pf_rule_actions *default_actions) { struct pfi_kkif *kif; u_short action, reason = 0, log = 0; @@ -7733,6 +7737,8 @@ pf_test6(int dir, int pflags, struct ifnet *ifp, struct mbuf **m0, struct inpcb } memset(&pd, 0, sizeof(pd)); + if (default_actions != NULL) + memcpy(&pd.act, default_actions, sizeof(pd.act)); pd.pf_mtag = pf_find_mtag(m); if (pd.pf_mtag != NULL && (pd.pf_mtag->flags & PF_TAG_ROUTE_TO)) { diff --git a/sys/netpfil/pf/pf_ioctl.c b/sys/netpfil/pf/pf_ioctl.c index db88c7d2dc0e..cb6d22885ef4 100644 --- a/sys/netpfil/pf/pf_ioctl.c +++ b/sys/netpfil/pf/pf_ioctl.c @@ -6534,7 +6534,7 @@ pf_check_in(struct mbuf **m, struct ifnet *ifp, int flags, { int chk; - chk = pf_test(PF_IN, flags, ifp, m, inp); + chk = pf_test(PF_IN, flags, ifp, m, inp, NULL); return (pf_check_return(chk, m)); } @@ -6545,7 +6545,7 @@ pf_check_out(struct mbuf **m, struct ifnet *ifp, int flags, { int chk; - chk = pf_test(PF_OUT, flags, ifp, m, inp); + chk = pf_test(PF_OUT, flags, ifp, m, inp, NULL); return (pf_check_return(chk, m)); } @@ -6564,7 +6564,8 @@ pf_check6_in(struct mbuf **m, struct ifnet *ifp, int flags, * filtering we have change this to lo0 as it is the case in IPv4. */ CURVNET_SET(ifp->if_vnet); - chk = pf_test6(PF_IN, flags, (*m)->m_flags & M_LOOP ? V_loif : ifp, m, inp); + chk = pf_test6(PF_IN, flags, (*m)->m_flags & M_LOOP ? V_loif : ifp, + m, inp, NULL); CURVNET_RESTORE(); return (pf_check_return(chk, m)); @@ -6577,7 +6578,7 @@ pf_check6_out(struct mbuf **m, struct ifnet *ifp, int flags, int chk; CURVNET_SET(ifp->if_vnet); - chk = pf_test6(PF_OUT, flags, ifp, m, inp); + chk = pf_test6(PF_OUT, flags, ifp, m, inp, NULL); CURVNET_RESTORE(); return (pf_check_return(chk, m));