From owner-dev-commits-src-all@freebsd.org Tue Jun 29 07:24:59 2021 Return-Path: Delivered-To: dev-commits-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 186EB64506D; Tue, 29 Jun 2021 07:24:59 +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 4GDbbG71g1z4Rn9; Tue, 29 Jun 2021 07:24:58 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 B0ECF14D4E; Tue, 29 Jun 2021 07:24:58 +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 15T7Owaa068164; Tue, 29 Jun 2021 07:24:58 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 15T7OwLL068163; Tue, 29 Jun 2021 07:24:58 GMT (envelope-from git) Date: Tue, 29 Jun 2021 07:24:58 GMT Message-Id: <202106290724.15T7OwLL068163@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mateusz Guzik Subject: git: 803dfe3da0e3 - main - pf: deduplicate V_pf_state_z handling with pfsync 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/main X-Git-Reftype: branch X-Git-Commit: 803dfe3da0e30520227a791ba5c2b93da16e1cf5 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 29 Jun 2021 07:24:59 -0000 The branch main has been updated by mjg: URL: https://cgit.FreeBSD.org/src/commit/?id=803dfe3da0e30520227a791ba5c2b93da16e1cf5 commit 803dfe3da0e30520227a791ba5c2b93da16e1cf5 Author: Mateusz Guzik AuthorDate: 2021-06-28 18:18:26 +0000 Commit: Mateusz Guzik CommitDate: 2021-06-29 07:24:53 +0000 pf: deduplicate V_pf_state_z handling with pfsync Reviewed by: kp Sponsored by: Rubicon Communications, LLC ("Netgate") --- sys/net/pfvar.h | 1 + sys/netpfil/pf/if_pfsync.c | 20 +++----------------- sys/netpfil/pf/pf.c | 2 +- 3 files changed, 5 insertions(+), 18 deletions(-) diff --git a/sys/net/pfvar.h b/sys/net/pfvar.h index 9f0bf002b631..2ce47f926091 100644 --- a/sys/net/pfvar.h +++ b/sys/net/pfvar.h @@ -1495,6 +1495,7 @@ extern int pf_state_insert(struct pfi_kkif *, struct pf_state_key *, struct pf_state_key *, struct pf_state *); +extern struct pf_state *pf_alloc_state(int); extern void pf_free_state(struct pf_state *); static __inline void diff --git a/sys/netpfil/pf/if_pfsync.c b/sys/netpfil/pf/if_pfsync.c index 3514c922c361..16878fe87750 100644 --- a/sys/netpfil/pf/if_pfsync.c +++ b/sys/netpfil/pf/if_pfsync.c @@ -504,16 +504,10 @@ pfsync_state_import(struct pfsync_state *sp, u_int8_t flags) /* * XXXGL: consider M_WAITOK in ioctl path after. */ - if ((st = uma_zalloc(V_pf_state_z, M_NOWAIT | M_ZERO)) == NULL) + st = pf_alloc_state(M_NOWAIT); + if (__predict_false(st == NULL)) goto cleanup; - for (int i = 0; i < 2; i++) { - st->packets[i] = counter_u64_alloc(M_NOWAIT); - st->bytes[i] = counter_u64_alloc(M_NOWAIT); - if (st->packets[i] == NULL || st->bytes[i] == NULL) - goto cleanup; - } - if ((skw = uma_zalloc(V_pf_state_key_z, M_NOWAIT)) == NULL) goto cleanup; @@ -623,15 +617,7 @@ cleanup: cleanup_state: /* pf_state_insert() frees the state keys. */ if (st) { - for (int i = 0; i < 2; i++) { - counter_u64_free(st->packets[i]); - counter_u64_free(st->bytes[i]); - } - if (st->dst.scrub) - uma_zfree(V_pf_state_scrub_z, st->dst.scrub); - if (st->src.scrub) - uma_zfree(V_pf_state_scrub_z, st->src.scrub); - uma_zfree(V_pf_state_z, st); + pf_free_state(st); } return (error); } diff --git a/sys/netpfil/pf/pf.c b/sys/netpfil/pf/pf.c index f05dc69b3dbb..7579b6bbebb0 100644 --- a/sys/netpfil/pf/pf.c +++ b/sys/netpfil/pf/pf.c @@ -1736,7 +1736,7 @@ pf_unlink_state(struct pf_state *s, u_int flags) return (pf_release_staten(s, 2)); } -static struct pf_state * +struct pf_state * pf_alloc_state(int flags) { struct pf_state *s;