The branch main has been updated by mjg: URL: https://cgit.FreeBSD.org/src/commit/?id=ccb17a21041e9206b80fa9f64b6ec20233df6403
commit ccb17a21041e9206b80fa9f64b6ec20233df6403 Author: Mateusz Guzik <[email protected]> AuthorDate: 2021-06-28 12:22:31 +0000 Commit: Mateusz Guzik <[email protected]> CommitDate: 2021-06-28 15:49:20 +0000 pf: factor out state allocation into pf_alloc_state Reviewed by: kp Sponsored by: Rubicon Communications, LLC ("Netgate") --- sys/netpfil/pf/pf.c | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/sys/netpfil/pf/pf.c b/sys/netpfil/pf/pf.c index 02d0809f738d..26989adfb613 100644 --- a/sys/netpfil/pf/pf.c +++ b/sys/netpfil/pf/pf.c @@ -1736,6 +1736,28 @@ pf_unlink_state(struct pf_state *s, u_int flags) return (pf_release_staten(s, 2)); } +static struct pf_state * +pf_alloc_state(int flags) +{ + struct pf_state *s; + + s = uma_zalloc(V_pf_state_z, flags | M_ZERO); + if (__predict_false(s == NULL)) + return (NULL); + + for (int i = 0; i < 2; i++) { + s->bytes[i] = counter_u64_alloc(M_NOWAIT); + s->packets[i] = counter_u64_alloc(M_NOWAIT); + + if (s->bytes[i] == NULL || s->packets[i] == NULL) { + pf_free_state(s); + return (NULL); + } + } + + return (s); +} + void pf_free_state(struct pf_state *cur) { @@ -3730,21 +3752,11 @@ pf_create_state(struct pf_krule *r, struct pf_krule *nr, struct pf_krule *a, REASON_SET(&reason, PFRES_SRCLIMIT); goto csfailed; } - s = uma_zalloc(V_pf_state_z, M_NOWAIT | M_ZERO); + s = pf_alloc_state(M_NOWAIT); if (s == NULL) { REASON_SET(&reason, PFRES_MEMORY); goto csfailed; } - for (int i = 0; i < 2; i++) { - s->bytes[i] = counter_u64_alloc(M_NOWAIT); - s->packets[i] = counter_u64_alloc(M_NOWAIT); - - if (s->bytes[i] == NULL || s->packets[i] == NULL) { - pf_free_state(s); - REASON_SET(&reason, PFRES_MEMORY); - goto csfailed; - } - } s->rule.ptr = r; s->nat_rule.ptr = nr; s->anchor.ptr = a; _______________________________________________ [email protected] mailing list https://lists.freebsd.org/mailman/listinfo/dev-commits-src-all To unsubscribe, send any mail to "[email protected]"
