From nobody Tue Jan 14 10:37:51 2025 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 4YXQZ82RpPz5kVqd; Tue, 14 Jan 2025 10:37:52 +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 4YXQZ74zBnz4B8P; Tue, 14 Jan 2025 10:37:51 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1736851071; 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=h5K2ueOyYp9saZ/wP0XM71RVNHOnWet3s86aDVIm3ZE=; b=DG7KUI5UnmQHYxuAS6odokBSIA3M7pM2MIutCR4J44Z6D7UEWDl2yridLyfQIVv9Egvs2r r/b4+eBBHS/Frr2g3J5R73kZyJQWltnPYf4RXSKMUKKBqa8B2KZ3b5/RTPcXfl9EWtwvF/ hx8DIsaTn0106K7JHvFPkLVqfG3Qf9jyRNJ8WoyOa/OSNASaWoZ0aJFYJl41vtQisTZcmn s2lO7BH3oiyBJAWwoaRhqL6ex26ZXBK4yCHPr1ai5Bh/m/4ouIJUSfTjWLHezsTVcDRpe+ X0ZyKLc2d5ft1tISQYo0MqEhJrxrJs1GGJhqbIy+5YKTePDkewXaIHspd7tCog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1736851071; 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=h5K2ueOyYp9saZ/wP0XM71RVNHOnWet3s86aDVIm3ZE=; b=C7xYTHkQhTiGUL0Fo68UA4UlMBNXYYh3kDPfxexj/1wKNqf88wh8mGInnwBIDF2joPNN9c jFinMKHycRX3wAW4y0QdLZ7W8amze1hNFBU2L4OXrUDD68GqJyYF3gc1yShplWb1w6msh5 +eA401X8diBy60HKzxCZ9huYLNqQjZopEFWkdnqQkG2A0t4080eF7w9mAVOeK667rXj+UJ kPz+SL96ekVrFK3dUQB4A958q3LOcdc7QjBWp0Le/ZRZKf9nRtoeMzxxB0FKCC+bu6b8Lu V+DhLAI9XetSliflquxPn80/Kv4hWWHXzBesHFmgASKXX9i1HqY0f8u1gIeWMw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1736851071; a=rsa-sha256; cv=none; b=NEWKijkWgvfFn4+Zo2NYZPEF3PgvonHsW27CepHu2o1MrgGnaA/iOSgETl1b8fgFfX9Nz0 r0oyqZxDwN37a5xy3Qr48XaWVafp7gQbJey4DDUuve4mhDZm5JPb9xsTpSg2BBNqCBt118 oQzrTRpKEACzyRZoE2x75jBllHuOmG0uIySC5rb24pwO6i2Yeyqd/ZNbLeXo1vJvAcxpBm bjvSqjkTWdwEQBDAwscTh8ZNZXi/Kq63ULEbzw0O2mcNELPNORwFCyXFw+7cC9EL9SzlcX NoYD5sUQqUq7nTKp+PmEKWcJGLr/irIeekpPDE8lJOKoFaxb5eWHobjplU3Stg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none 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 4YXQZ74ZMlz1CNs; Tue, 14 Jan 2025 10:37:51 +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 50EAbpmB048004; Tue, 14 Jan 2025 10:37:51 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 50EAbpQT048001; Tue, 14 Jan 2025 10:37:51 GMT (envelope-from git) Date: Tue, 14 Jan 2025 10:37:51 GMT Message-Id: <202501141037.50EAbpQT048001@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: f2a1e40bb19b - main - pf: simplify state key setup 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: kp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: f2a1e40bb19b780467beb4ff98dca3f8b30a953d Auto-Submitted: auto-generated The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=f2a1e40bb19b780467beb4ff98dca3f8b30a953d commit f2a1e40bb19b780467beb4ff98dca3f8b30a953d Author: Kristof Provost AuthorDate: 2025-01-07 14:21:48 +0000 Commit: Kristof Provost CommitDate: 2025-01-14 08:54:18 +0000 pf: simplify state key setup Just use pd->sidx and pd->didx to reverse the state key arguments in pf_test_state_*(). This needs less code and is more consistent. OK mikeb, markus, henning. Obtained from: OpenBSD, mpf , 2c0d332046 Sponsored by: Rubicon Communications, LLC ("Netgate") --- sys/netpfil/pf/pf.c | 57 ++++++++++++++--------------------------------------- 1 file changed, 15 insertions(+), 42 deletions(-) diff --git a/sys/netpfil/pf/pf.c b/sys/netpfil/pf/pf.c index bee5690e02c4..3d1ba8e8deb4 100644 --- a/sys/netpfil/pf/pf.c +++ b/sys/netpfil/pf/pf.c @@ -6900,17 +6900,10 @@ pf_test_state_tcp(struct pf_kstate **state, struct pf_pdesc *pd, bzero(&key, sizeof(key)); key.af = pd->af; key.proto = IPPROTO_TCP; - if (pd->dir == PF_IN) { /* wire side, straight */ - PF_ACPY(&key.addr[0], pd->src, key.af); - PF_ACPY(&key.addr[1], pd->dst, key.af); - key.port[0] = th->th_sport; - key.port[1] = th->th_dport; - } else { /* stack side, reverse */ - PF_ACPY(&key.addr[1], pd->src, key.af); - PF_ACPY(&key.addr[0], pd->dst, key.af); - key.port[1] = th->th_sport; - key.port[0] = th->th_dport; - } + PF_ACPY(&key.addr[pd->sidx], pd->src, key.af); + PF_ACPY(&key.addr[pd->didx], pd->dst, key.af); + key.port[pd->sidx] = th->th_sport; + key.port[pd->didx] = th->th_dport; STATE_LOOKUP(&key, *state, pd); @@ -7010,17 +7003,10 @@ pf_test_state_udp(struct pf_kstate **state, struct pf_pdesc *pd) bzero(&key, sizeof(key)); key.af = pd->af; key.proto = IPPROTO_UDP; - if (pd->dir == PF_IN) { /* wire side, straight */ - PF_ACPY(&key.addr[0], pd->src, key.af); - PF_ACPY(&key.addr[1], pd->dst, key.af); - key.port[0] = uh->uh_sport; - key.port[1] = uh->uh_dport; - } else { /* stack side, reverse */ - PF_ACPY(&key.addr[1], pd->src, key.af); - PF_ACPY(&key.addr[0], pd->dst, key.af); - key.port[1] = uh->uh_sport; - key.port[0] = uh->uh_dport; - } + PF_ACPY(&key.addr[pd->sidx], pd->src, key.af); + PF_ACPY(&key.addr[pd->didx], pd->dst, key.af); + key.port[pd->sidx] = uh->uh_sport; + key.port[pd->didx] = uh->uh_dport; STATE_LOOKUP(&key, *state, pd); @@ -7127,17 +7113,10 @@ pf_test_state_sctp(struct pf_kstate **state, struct pf_pdesc *pd, bzero(&key, sizeof(key)); key.af = pd->af; key.proto = IPPROTO_SCTP; - if (pd->dir == PF_IN) { /* wire side, straight */ - PF_ACPY(&key.addr[0], pd->src, key.af); - PF_ACPY(&key.addr[1], pd->dst, key.af); - key.port[0] = sh->src_port; - key.port[1] = sh->dest_port; - } else { /* stack side, reverse */ - PF_ACPY(&key.addr[1], pd->src, key.af); - PF_ACPY(&key.addr[0], pd->dst, key.af); - key.port[1] = sh->src_port; - key.port[0] = sh->dest_port; - } + PF_ACPY(&key.addr[pd->sidx], pd->src, key.af); + PF_ACPY(&key.addr[pd->didx], pd->dst, key.af); + key.port[pd->sidx] = sh->src_port; + key.port[pd->didx] = sh->dest_port; STATE_LOOKUP(&key, *state, pd); @@ -8670,15 +8649,9 @@ pf_test_state_other(struct pf_kstate **state, struct pf_pdesc *pd) bzero(&key, sizeof(key)); key.af = pd->af; key.proto = pd->proto; - if (pd->dir == PF_IN) { - PF_ACPY(&key.addr[0], pd->src, key.af); - PF_ACPY(&key.addr[1], pd->dst, key.af); - key.port[0] = key.port[1] = 0; - } else { - PF_ACPY(&key.addr[1], pd->src, key.af); - PF_ACPY(&key.addr[0], pd->dst, key.af); - key.port[1] = key.port[0] = 0; - } + PF_ACPY(&key.addr[pd->sidx], pd->src, key.af); + PF_ACPY(&key.addr[pd->didx], pd->dst, key.af); + key.port[0] = key.port[1] = 0; STATE_LOOKUP(&key, *state, pd);