The branch main has been updated by mjg:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=803dfe3da0e30520227a791ba5c2b93da16e1cf5

commit 803dfe3da0e30520227a791ba5c2b93da16e1cf5
Author:     Mateusz Guzik <[email protected]>
AuthorDate: 2021-06-28 18:18:26 +0000
Commit:     Mateusz Guzik <[email protected]>
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;
_______________________________________________
[email protected] mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-all
To unsubscribe, send any mail to "[email protected]"

Reply via email to