From nobody Wed Nov 20 21:41:24 2024 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 4Xtvv90mNQz5dnRm; Wed, 20 Nov 2024 21:41:25 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Xtvv86CyMz4vqw; Wed, 20 Nov 2024 21:41:24 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1732138884; 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=x6m60nzs1+9mC5UVglduqx8fFCDDzoN9NTKG1pWd4Ow=; b=xFgDp3/i9LVXPFC+FvwM+ZVsC4z9vz+GdcscpTMagbiIyidNUit91QuFjtnV4H0kn0cjum qbpIxgGncu9LcojaF0Fx62exkq2fA+wXyQGgv0ZYrTIxA4KEMyvV3N6Na2EgbBxWyhH09f XIrVmSnrYkCysyDSG0t0wMr3gZ/ODaNgEZ5sMXUgWZXtNjimGR2KCSydYEZoLSVeZQcyx7 GmZlpJbVWOJWvJ0nFSQUABNHs0FfAgprcN/YBA3mwbAmAZRG34XrZhr/1WmrkOS9MVs2KK uZtsGnZiv6jsofcuk/19/aG2MdU4sHkVozRDZUFRK6muGL4x64vRHfTnUxyzWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1732138884; 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=x6m60nzs1+9mC5UVglduqx8fFCDDzoN9NTKG1pWd4Ow=; b=bLXmk0d3iYiweitdFm6edWqLraSzv5dmv/sOS5wMWE5OZATVm6Dyqu0QYUeIRpKuVFPYhJ TC4Wj0DNJ8SzmmMLvsNq6haceApASjFF0qOxGFYZtOO75s8IYBeRvvJ+iAzu70tLlN3byF IsydhgTQ8Ddtr85/Rn+Nl5+kY2uQ+Zd59CebEhAjgi3x5Sw9gKYPqtweTeUzSd68DJbFmI KtzczKGRa0zIOUFeRLGcOiLLrCrs2ZV7b47fju2desoP1L0gZvwcoJlO+9AA8Dyv0ek85y AOxKnxZzpm2gRBYVuk43Y01VZT7kFf4GY2aPlAT3wCijgqCgoT4DwBExkZHAUg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1732138884; a=rsa-sha256; cv=none; b=yLPh/P0xlnSyI4vTbbL9vCHS695lx1K+PC2UYCqX+U42lm4fciau5qLYgVzze35qLnHOet TUAxW9GwxqhlvtPaUBUX6b2MhKzCsi1+W9WuMQw1Enz8Ce0Umpx3Pirab62QMMp58W/Xvq xb50EL0fMh813vq9bcIe+rbQqxZ/AdCULpj1TJ6AUqRwfPOR3FJnhV+1ps9tyt+gxVpqrK ikTStjmERn7/ysRt7btMWERBF7nP5/F7hiw2LAOG7IP5rTVtRjsy2OWYbN13O18uketgKx i3K3dfM88IsV/rsLOLCxS43dW9/wyR53/SEBPCUe0YhnlOBoY/aZwQRoszmjqg== 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 4Xtvv85D7nz1B6d; Wed, 20 Nov 2024 21:41:24 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 4AKLfOkj022356; Wed, 20 Nov 2024 21:41:24 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4AKLfOJe022352; Wed, 20 Nov 2024 21:41:24 GMT (envelope-from git) Date: Wed, 20 Nov 2024 21:41:24 GMT Message-Id: <202411202141.4AKLfOJe022352@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: f4f4c52c0f46 - stable/14 - pf: Let pf_state_insert() handle redirect state conflicts 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: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: f4f4c52c0f46531082925aded23510f9adeb6fff Auto-Submitted: auto-generated The branch stable/14 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=f4f4c52c0f46531082925aded23510f9adeb6fff commit f4f4c52c0f46531082925aded23510f9adeb6fff Author: Mark Johnston AuthorDate: 2024-09-10 14:34:45 +0000 Commit: Mark Johnston CommitDate: 2024-11-20 21:41:09 +0000 pf: Let pf_state_insert() handle redirect state conflicts When handling a redirect state conflict, pf_get_translation() tries modifying the source port to avoid it. If it fails to find a free port, the translation is aborted. Instead, if we fail to find a free source port, simply press on with the original source port and let pf_state_insert() handle the conflict as it pleases, rather than second-guessing what it will do. In particular, pf_state_insert() has special handling for TCP connections in a terminal state, and might succeed despite a state conflict. Reviewed by: kp MFC after: 3 months Sponsored by: Klara, Inc. Sponsored by: Modirum Differential Revision: https://reviews.freebsd.org/D46612 (cherry picked from commit 9569fddd8d0e48211e67fdc63dd72eba83883525) --- sys/netpfil/pf/pf_lb.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/sys/netpfil/pf/pf_lb.c b/sys/netpfil/pf/pf_lb.c index 6b0b95e9ce01..3f5b3f90a4e4 100644 --- a/sys/netpfil/pf/pf_lb.c +++ b/sys/netpfil/pf/pf_lb.c @@ -370,7 +370,7 @@ pf_map_addr(sa_family_t af, struct pf_krule *r, struct pf_addr *saddr, struct pf_addr *naddr, struct pfi_kkif **nkif, struct pf_addr *init_addr, struct pf_ksrc_node **sn) { - u_short reason = 0; + u_short reason = PFRES_MATCH; struct pf_kpool *rpool = &r->rpool; struct pf_addr *raddr = NULL, *rmask = NULL; struct pf_srchash *sh = NULL; @@ -828,10 +828,15 @@ pf_get_translation(struct pf_pdesc *pd, struct mbuf *m, int off, } } + /* + * We failed to find a match. Push on ahead anyway, let + * pf_state_insert() be the arbiter of whether the state + * conflict is tolerable. In particular, with TCP connections + * the state may be reused if the TCP state is terminal. + */ DPFPRINTF(PF_DEBUG_MISC, ("pf: RDR source port allocation failed\n")); - reason = PFRES_MAPFAILED; - goto notrans; + break; out: DPFPRINTF(PF_DEBUG_MISC,