git: 0e3ee7e3a674 - stable/13 - pf: factor out state allocation into pf_alloc_state
Mateusz Guzik
mjg at FreeBSD.org
Mon Jul 5 11:33:49 UTC 2021
The branch stable/13 has been updated by mjg:
URL: https://cgit.FreeBSD.org/src/commit/?id=0e3ee7e3a6744e30f78ed2756f0060367f340179
commit 0e3ee7e3a6744e30f78ed2756f0060367f340179
Author: Mateusz Guzik <mjg at FreeBSD.org>
AuthorDate: 2021-06-28 12:22:31 +0000
Commit: Mateusz Guzik <mjg at FreeBSD.org>
CommitDate: 2021-07-05 11:32:10 +0000
pf: factor out state allocation into pf_alloc_state
Reviewed by: kp
Sponsored by: Rubicon Communications, LLC ("Netgate")
(cherry picked from commit ccb17a21041e9206b80fa9f64b6ec20233df6403)
---
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 8e0c51238f32..53489f5f0113 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;
More information about the dev-commits-src-branches
mailing list