From nobody Tue Aug 02 20:05:11 2022 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 4Ly5ZH528Yz4Y7hQ; Tue, 2 Aug 2022 20:05:11 +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 4Ly5ZH4Srqz4K3l; Tue, 2 Aug 2022 20:05:11 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1659470711; 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=UX8WC9tR5U5hTNKO4epPw7LnUCkya2SZHYgdK9N8rnc=; b=lRcl5Lear8NCmjJfMuqbpPtgC0PqABXZ3ji3rzYQ4/ygukADBwiutVDkEtP7edF1nG6gwm ceI8ek60exq279yTV2ClFlsovO/FuGSK+dOU44GUSaDifpJNNi6ttJG5AhSmucX2b8+H9u fWfZ7MOv6pzwyYTT1hgQ9Qe8GE/gFlVM4VaXlwvJmCpIWQ7eJwGkTVBCgy5rmAzl1S/NBQ PQRmEExNy+ROJTKZI1hRClf/3JnuvaO5LmJVSJpd19U55jmkfWxyJoOpnfegSlsacW1/qd GQl8X61bGdYZBDghHtWfmk1HslTPSU6lUjmcGWB6mO6Npz7/730JPrWInmq1ew== 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 4Ly5ZH3WcNzQDs; Tue, 2 Aug 2022 20:05:11 +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 272K5B4s051291; Tue, 2 Aug 2022 20:05:11 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 272K5BQc051290; Tue, 2 Aug 2022 20:05:11 GMT (envelope-from git) Date: Tue, 2 Aug 2022 20:05:11 GMT Message-Id: <202208022005.272K5BQc051290@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mateusz Guzik Subject: git: 170821d5241f - stable/12 - pf: add pf_bcmp_state_key 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mjg X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: 170821d5241fc7b944508b09ff90d4f7b06d67cb Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1659470711; 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=UX8WC9tR5U5hTNKO4epPw7LnUCkya2SZHYgdK9N8rnc=; b=qAEDJsYlHGDM8XKfG2IDEwfTRD/GtH7lHcJn8f0asB7qEjWboB8bpZUP7nDcB/Ne8gNrMc jFLepBXVmTm7fEGv25TB5matkaUfzq5a9x4CMo92GnLVJamKLV4GuSaNjVUb8nTtOctAdt WZL+e+jPHBs1jcF6t64ywRuxW2XlltC3/O67XjDIXXFZ625k0KvXBgblFxtZBWcR6cRj7v HubpV4bHNfE8K8E9dSvPHhtXi+FSFlJZpA4qdMstZm92K/ZUSA0bp4fk7a6/6ckptt1To5 NSVM+xNjKZlTlcmWTv1uuuUMPyjm8kvu/UkFNd5sZw53QVDVnj+fpLAaXn7jeQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1659470711; a=rsa-sha256; cv=none; b=YjEmuB4/06IvlflPTyDSlt+/N4MfSWRlewL5QfBAyXwXiq5Ia46QqlZZxC+aqm+VrxzNxi h3I+fGOjJtkjHnFZtiqi4JvGx7769E9n6Hk7Wd3x8MmaVtWsXS5Udag/ocXri6l/Ht8E3t eXzlL21SAQ+8sbG+Qp8C2cPorOg1GMzDa/7Vz+VW+yxxYArex9wC2kfwXkfyqjb1SnSZpv fJmUeAQM3qgo0Tlb8tBgpaOL/p+CWqXWZmJFCNW5w/yf87YsiWK5wOXZEu5HPJr5mjjeOU kC/Q7kdaVTYlEBjSKkFihwmSJKFq/wrlGEIiazeHgbdTxvwTbCLMHPu7bjn3zQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/12 has been updated by mjg: URL: https://cgit.FreeBSD.org/src/commit/?id=170821d5241fc7b944508b09ff90d4f7b06d67cb commit 170821d5241fc7b944508b09ff90d4f7b06d67cb Author: Mateusz Guzik AuthorDate: 2021-11-24 17:25:18 +0000 Commit: Mateusz Guzik CommitDate: 2022-08-02 20:04:55 +0000 pf: add pf_bcmp_state_key Reviewed by: kp Sponsored by: Rubicon Communications, LLC ("Netgate") Differential Revision: https://reviews.freebsd.org/D33131 (cherry picked from commit b6c8c7b99a750de18509715890615ad3f948b29a) --- sys/netpfil/pf/pf.c | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/sys/netpfil/pf/pf.c b/sys/netpfil/pf/pf.c index 518b082621cb..0a6928e3d4eb 100644 --- a/sys/netpfil/pf/pf.c +++ b/sys/netpfil/pf/pf.c @@ -413,6 +413,40 @@ VNET_DEFINE(struct intr_event *, pf_swi_ie); VNET_DEFINE(uint32_t, pf_hashseed); #define V_pf_hashseed VNET(pf_hashseed) +#ifdef __LP64__ +static int +pf_bcmp_state_key(struct pf_state_key *k1_orig, struct pf_state_key_cmp *k2_orig) +{ + unsigned long *k1 = (unsigned long *)k1_orig; + unsigned long *k2 = (unsigned long *)k2_orig; + + if (k1[0] != k2[0]) + return (1); + + if (k1[1] != k2[1]) + return (1); + + if (k1[2] != k2[2]) + return (1); + + if (k1[3] != k2[3]) + return (1); + + if (k1[4] != k2[4]) + return (1); + + return (0); +} +_Static_assert(sizeof(struct pf_state_key_cmp) == 40, "bad size of pf_state_key_cmp"); +#else +static inline int +pf_bcmp_state_key(struct pf_state_key *k1_orig, struct pf_state_key_cmp *k2_orig) +{ + + return (bcmp(k1_orig, k2_orig, sizeof(struct pf_state_key_cmp))); +} +#endif + int pf_addr_cmp(struct pf_addr *a, struct pf_addr *b, sa_family_t af) { @@ -1168,7 +1202,7 @@ pf_state_key_attach(struct pf_state_key *skw, struct pf_state_key *sks, keyattach: LIST_FOREACH(cur, &kh->keys, entry) - if (bcmp(cur, sk, sizeof(struct pf_state_key_cmp)) == 0) + if (pf_bcmp_state_key(cur, (struct pf_state_key_cmp *)sk) == 0) break; if (cur != NULL) { @@ -1474,7 +1508,7 @@ pf_find_state(struct pfi_kkif *kif, struct pf_state_key_cmp *key, u_int dir) PF_HASHROW_LOCK(kh); LIST_FOREACH(sk, &kh->keys, entry) - if (bcmp(sk, key, sizeof(struct pf_state_key_cmp)) == 0) + if (pf_bcmp_state_key(sk, key) == 0) break; if (sk == NULL) { PF_HASHROW_UNLOCK(kh); @@ -1518,7 +1552,7 @@ pf_find_state_all(struct pf_state_key_cmp *key, u_int dir, int *more) PF_HASHROW_LOCK(kh); LIST_FOREACH(sk, &kh->keys, entry) - if (bcmp(sk, key, sizeof(struct pf_state_key_cmp)) == 0) + if (pf_bcmp_state_key(sk, key) == 0) break; if (sk == NULL) { PF_HASHROW_UNLOCK(kh);