Date: Mon, 28 Jun 2021 15:49:24 GMT From: Mateusz Guzik <mjg@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Subject: git: d09388d01330 - main - pf: add pf_release_staten and use it in pf_unlink_state Message-ID: <202106281549.15SFnOvQ016051@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch main has been updated by mjg: URL: https://cgit.FreeBSD.org/src/commit/?id=d09388d013300fc4aa1ee1a6bc24260cd400aff3 commit d09388d013300fc4aa1ee1a6bc24260cd400aff3 Author: Mateusz Guzik <mjg@FreeBSD.org> AuthorDate: 2021-06-28 12:18:43 +0000 Commit: Mateusz Guzik <mjg@FreeBSD.org> CommitDate: 2021-06-28 15:49:20 +0000 pf: add pf_release_staten and use it in pf_unlink_state Saves one atomic op. Reviewed by: kp Sponsored by: Rubicon Communications, LLC ("Netgate") --- sys/net/pfvar.h | 11 +++++++++++ sys/netpfil/pf/pf.c | 7 ++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/sys/net/pfvar.h b/sys/net/pfvar.h index e07016f7b66c..9578ec0a701f 100644 --- a/sys/net/pfvar.h +++ b/sys/net/pfvar.h @@ -1510,6 +1510,17 @@ pf_release_state(struct pf_state *s) return (0); } +static __inline int +pf_release_staten(struct pf_state *s, u_int n) +{ + + if (refcount_releasen(&s->refs, n)) { + pf_free_state(s); + return (1); + } else + return (0); +} + extern struct pf_state *pf_find_state_byid(uint64_t, uint32_t); extern struct pf_state *pf_find_state_all(struct pf_state_key_cmp *, u_int, int *); diff --git a/sys/netpfil/pf/pf.c b/sys/netpfil/pf/pf.c index 7e187a358783..02d0809f738d 100644 --- a/sys/netpfil/pf/pf.c +++ b/sys/netpfil/pf/pf.c @@ -1732,11 +1732,8 @@ pf_unlink_state(struct pf_state *s, u_int flags) PF_HASHROW_UNLOCK(ih); pf_detach_state(s); - /* pf_state_insert() initialises refs to 2, so we can never release the - * last reference here, only in pf_release_state(). */ - (void)refcount_release(&s->refs); - - return (pf_release_state(s)); + /* pf_state_insert() initialises refs to 2 */ + return (pf_release_staten(s, 2)); } void
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202106281549.15SFnOvQ016051>