From nobody Tue Sep 10 14:59:31 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 4X36LD03Xqz5Vy6g; Tue, 10 Sep 2024 14:59:32 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4X36LC62bYz4d8q; Tue, 10 Sep 2024 14:59:31 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1725980371; 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=247H1fy2ZchnrPdgeuq88xM4dctCl/hOlZXJy5l7qJM=; b=JAEIqIBfvONrAo9M6dSP1W2pvujJAfWyhNdJ3pCNpkQgrGOIt3lFMGst6pKT7IFjpbvKFR dGHbqN/hXcwI1NPcvEFROih2P/lWb+MMZ9pDdMAKNuNpWIWJj744n3Tqb32XLsQK5a3Fck HZlex1FPewN/JI/eW4YeTiEKDgHBGhP3k/i0J3/o0KObwODTESja3YcB+DIaE7DJ4oopQk VwYOUuIqzWug9S6A4ropT10ob8CLLGClSFb0QORWXWNn0Z3pEcZ8yoLSO07tFRc0trnlom sybFpRk7yol7Rtyc1pjXo82f7CSCyJVzva2zu4POXeGM+wKzqLi25H8LDv5M4A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1725980371; a=rsa-sha256; cv=none; b=IsomuM5G/xlwf4iP/U8FfkhrdhkVlkCUhtiMBZ8WiDiiDvUYX4Ti/eD5Q2pJy+B8TDC89O VgXVVu1f7YDToAn8wyqlg9dlJ4TDF8sZxTqKm5grcn6CY5rYZNghueVUUG9Z0d8qSgXIdl me//sAdzjzJel8ScqXFqNDPx+w0d2vM3QXHoLn9rwWWHejlnolgQxsM3ZRMHultlaKcRyl q9l/tneJc33kcs5gMlpKbpoMI/7+1ceQ5hNZFnxUibwxfmZha3QPnA0/JJxJRFDquT11DB LA7seWBsweMIt7/k4e7qrG2XjV7SdHSQjCv01eeL7O68WFxW4vWZveUhr6wgDg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1725980371; 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=247H1fy2ZchnrPdgeuq88xM4dctCl/hOlZXJy5l7qJM=; b=QX4IOw34619NcEzSgZVUE4vmQ2JVsZygrYzfktd6t9odZcOBSYxnuuo5Le0PGVcxkOviTc 5T4SRPi6Gg1BiLGRLQLzG7gDlXSc7SgNFS+iA7otV7pKtarkXwmAr8RGeXsywRTgMwUCXO mSwJwyuN2tenYdntgtiHX37wh+JnLn/2WUXiOEYyprU8J1GqqrOpKVZUVhwpE+7naihW4j KAWeQBns0hXo+5NgzfNsAbZbnru6o2slrsiDeyoDvaGNOilUIyEfH6mNObDdtioTdIoaEL qpyFF/qsK6p/UNCe+7Nfcr0zs9PS7X10NxJ0wCsN6oMQSDa1+cwiBOhSfe1smQ== 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 4X36LC5fnhzrXp; Tue, 10 Sep 2024 14:59:31 +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 48AExVPJ080590; Tue, 10 Sep 2024 14:59:31 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 48AExVSZ080587; Tue, 10 Sep 2024 14:59:31 GMT (envelope-from git) Date: Tue, 10 Sep 2024 14:59:31 GMT Message-Id: <202409101459.48AExVSZ080587@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: 9569fddd8d0e - main - 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/main X-Git-Reftype: branch X-Git-Commit: 9569fddd8d0e48211e67fdc63dd72eba83883525 Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=9569fddd8d0e48211e67fdc63dd72eba83883525 commit 9569fddd8d0e48211e67fdc63dd72eba83883525 Author: Mark Johnston AuthorDate: 2024-09-10 14:34:45 +0000 Commit: Mark Johnston CommitDate: 2024-09-10 14:59:13 +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 --- 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 dbd85d530bb7..6541a42aa236 100644 --- a/sys/netpfil/pf/pf_lb.c +++ b/sys/netpfil/pf/pf_lb.c @@ -442,7 +442,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; @@ -908,10 +908,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,