git: 9e7d55570f69 - main - pf: remove armv7-specific counter code
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 30 Oct 2026 12:21:39 UTC
The branch main has been updated by kp:
URL: https://cgit.FreeBSD.org/src/commit/?id=9e7d55570f6993ba4092ce7919a0a731c7f8e734
commit 9e7d55570f6993ba4092ce7919a0a731c7f8e734
Author: Kristof Provost <kp@FreeBSD.org>
AuthorDate: 2026-10-23 11:50:35 +0000
Commit: Kristof Provost <kp@FreeBSD.org>
CommitDate: 2026-10-30 12:21:11 +0000
pf: remove armv7-specific counter code
The armv7 specific counter code is less useful now that armv7 is
basically end-of-life.
This removes a lot of armv7-specific code.
Sponsored by: Rubicon Communications, LLC ("Netgate")
---
sys/net/pfvar.h | 268 ++--------------------------------------------
sys/netpfil/pf/pf.c | 176 ++++--------------------------
sys/netpfil/pf/pf_if.c | 61 +++--------
sys/netpfil/pf/pf_ioctl.c | 152 +++++++-------------------
sys/netpfil/pf/pf_lb.c | 2 +-
sys/netpfil/pf/pf_nl.c | 31 ++----
sys/netpfil/pf/pf_norm.c | 32 +++---
sys/netpfil/pf/pf_nv.c | 6 +-
8 files changed, 103 insertions(+), 625 deletions(-)
diff --git a/sys/net/pfvar.h b/sys/net/pfvar.h
index ba2bb8bf5bce..9b524083ab65 100644
--- a/sys/net/pfvar.h
+++ b/sys/net/pfvar.h
@@ -72,237 +72,6 @@
#define PF_PFIL_NOREFRAGMENT 0x80000000
-#if defined(__arm__)
-#define PF_WANT_32_TO_64_COUNTER
-#endif
-
-/*
- * A hybrid of 32-bit and 64-bit counters which can be used on platforms where
- * counter(9) is very expensive.
- *
- * As 32-bit counters are expected to overflow, a periodic job sums them up to
- * a saved 64-bit state. Fetching the value still walks all CPUs to get the most
- * current snapshot.
- */
-#ifdef PF_WANT_32_TO_64_COUNTER
-struct pf_counter_u64_pcpu {
- u_int32_t current;
- u_int32_t snapshot;
-};
-
-struct pf_counter_u64 {
- struct pf_counter_u64_pcpu *pfcu64_pcpu;
- u_int64_t pfcu64_value;
- seqc_t pfcu64_seqc;
-};
-
-static inline int
-pf_counter_u64_init(struct pf_counter_u64 *pfcu64, int flags)
-{
-
- pfcu64->pfcu64_value = 0;
- pfcu64->pfcu64_seqc = 0;
- pfcu64->pfcu64_pcpu = uma_zalloc_pcpu(pcpu_zone_8, flags | M_ZERO);
- if (__predict_false(pfcu64->pfcu64_pcpu == NULL))
- return (ENOMEM);
- return (0);
-}
-
-static inline void
-pf_counter_u64_deinit(struct pf_counter_u64 *pfcu64)
-{
-
- uma_zfree_pcpu(pcpu_zone_8, pfcu64->pfcu64_pcpu);
-}
-
-static inline void
-pf_counter_u64_critical_enter(void)
-{
-
- critical_enter();
-}
-
-static inline void
-pf_counter_u64_critical_exit(void)
-{
-
- critical_exit();
-}
-
-static inline void
-pf_counter_u64_rollup_protected(struct pf_counter_u64 *pfcu64, uint64_t n)
-{
-
- MPASS(curthread->td_critnest > 0);
- pfcu64->pfcu64_value += n;
-}
-
-static inline void
-pf_counter_u64_add_protected(struct pf_counter_u64 *pfcu64, uint32_t n)
-{
- struct pf_counter_u64_pcpu *pcpu;
- u_int32_t val;
-
- MPASS(curthread->td_critnest > 0);
- pcpu = zpcpu_get(pfcu64->pfcu64_pcpu);
- val = atomic_load_int(&pcpu->current);
- atomic_store_int(&pcpu->current, val + n);
-}
-
-static inline void
-pf_counter_u64_add(struct pf_counter_u64 *pfcu64, uint32_t n)
-{
-
- critical_enter();
- pf_counter_u64_add_protected(pfcu64, n);
- critical_exit();
-}
-
-static inline u_int64_t
-pf_counter_u64_periodic(struct pf_counter_u64 *pfcu64)
-{
- struct pf_counter_u64_pcpu *pcpu;
- u_int64_t sum;
- u_int32_t val;
- int cpu;
-
- MPASS(curthread->td_critnest > 0);
- seqc_write_begin(&pfcu64->pfcu64_seqc);
- sum = pfcu64->pfcu64_value;
- CPU_FOREACH(cpu) {
- pcpu = zpcpu_get_cpu(pfcu64->pfcu64_pcpu, cpu);
- val = atomic_load_int(&pcpu->current);
- sum += (uint32_t)(val - pcpu->snapshot);
- pcpu->snapshot = val;
- }
- pfcu64->pfcu64_value = sum;
- seqc_write_end(&pfcu64->pfcu64_seqc);
- return (sum);
-}
-
-static inline u_int64_t
-pf_counter_u64_fetch(const struct pf_counter_u64 *pfcu64)
-{
- struct pf_counter_u64_pcpu *pcpu;
- u_int64_t sum;
- seqc_t seqc;
- int cpu;
-
- for (;;) {
- seqc = seqc_read(&pfcu64->pfcu64_seqc);
- sum = 0;
- CPU_FOREACH(cpu) {
- pcpu = zpcpu_get_cpu(pfcu64->pfcu64_pcpu, cpu);
- sum += (uint32_t)(atomic_load_int(&pcpu->current) -pcpu->snapshot);
- }
- sum += pfcu64->pfcu64_value;
- if (seqc_consistent(&pfcu64->pfcu64_seqc, seqc))
- break;
- }
- return (sum);
-}
-
-static inline void
-pf_counter_u64_zero_protected(struct pf_counter_u64 *pfcu64)
-{
- struct pf_counter_u64_pcpu *pcpu;
- int cpu;
-
- MPASS(curthread->td_critnest > 0);
- seqc_write_begin(&pfcu64->pfcu64_seqc);
- CPU_FOREACH(cpu) {
- pcpu = zpcpu_get_cpu(pfcu64->pfcu64_pcpu, cpu);
- pcpu->snapshot = atomic_load_int(&pcpu->current);
- }
- pfcu64->pfcu64_value = 0;
- seqc_write_end(&pfcu64->pfcu64_seqc);
-}
-
-static inline void
-pf_counter_u64_zero(struct pf_counter_u64 *pfcu64)
-{
-
- critical_enter();
- pf_counter_u64_zero_protected(pfcu64);
- critical_exit();
-}
-#else
-struct pf_counter_u64 {
- counter_u64_t counter;
-};
-
-static inline int
-pf_counter_u64_init(struct pf_counter_u64 *pfcu64, int flags)
-{
-
- pfcu64->counter = counter_u64_alloc(flags);
- if (__predict_false(pfcu64->counter == NULL))
- return (ENOMEM);
- return (0);
-}
-
-static inline void
-pf_counter_u64_deinit(struct pf_counter_u64 *pfcu64)
-{
-
- counter_u64_free(pfcu64->counter);
-}
-
-static inline void
-pf_counter_u64_critical_enter(void)
-{
-
-}
-
-static inline void
-pf_counter_u64_critical_exit(void)
-{
-
-}
-
-static inline void
-pf_counter_u64_rollup_protected(struct pf_counter_u64 *pfcu64, uint64_t n)
-{
-
- counter_u64_add(pfcu64->counter, n);
-}
-
-static inline void
-pf_counter_u64_add_protected(struct pf_counter_u64 *pfcu64, uint32_t n)
-{
-
- counter_u64_add(pfcu64->counter, n);
-}
-
-static inline void
-pf_counter_u64_add(struct pf_counter_u64 *pfcu64, uint32_t n)
-{
-
- pf_counter_u64_add_protected(pfcu64, n);
-}
-
-static inline u_int64_t
-pf_counter_u64_fetch(const struct pf_counter_u64 *pfcu64)
-{
-
- return (counter_u64_fetch(pfcu64->counter));
-}
-
-static inline void
-pf_counter_u64_zero_protected(struct pf_counter_u64 *pfcu64)
-{
-
- counter_u64_zero(pfcu64->counter);
-}
-
-static inline void
-pf_counter_u64_zero(struct pf_counter_u64 *pfcu64)
-{
-
- pf_counter_u64_zero_protected(pfcu64);
-}
-#endif
-
#define pf_get_timestamp(prule)({ \
uint32_t _ts = 0; \
uint32_t __ts; \
@@ -817,9 +586,9 @@ struct pf_krule {
struct pf_kpool route;
struct pf_kthreshold pktrate;
- struct pf_counter_u64 evaluations;
- struct pf_counter_u64 packets[2];
- struct pf_counter_u64 bytes[2];
+ counter_u64_t evaluations;
+ counter_u64_t packets[2];
+ counter_u64_t bytes[2];
time_t *timestamp;
struct pfi_kkif *kif;
@@ -912,10 +681,6 @@ struct pf_krule {
u_int8_t md5sum[PF_MD5_DIGEST_LENGTH];
RB_ENTRY(pf_krule) entry_global;
-#ifdef PF_WANT_32_TO_64_COUNTER
- LIST_ENTRY(pf_krule) allrulelist;
- bool allrulelinked;
-#endif
time_t exptime;
};
@@ -1907,17 +1672,14 @@ struct pfi_kkif {
} _pfik_glue;
#define pfik_tree _pfik_glue._pfik_tree
#define pfik_list _pfik_glue._pfik_list
- struct pf_counter_u64 pfik_packets[2][2][2];
- struct pf_counter_u64 pfik_bytes[2][2][2];
+ counter_u64_t pfik_packets[2][2][2];
+ counter_u64_t pfik_bytes[2][2][2];
time_t pfik_tzero;
u_int pfik_flags;
struct ifnet *pfik_ifp;
struct ifg_group *pfik_group;
u_int pfik_rulerefs;
TAILQ_HEAD(, pfi_dynaddr) pfik_dynaddrs;
-#ifdef PF_WANT_32_TO_64_COUNTER
- LIST_ENTRY(pfi_kkif) pfik_allkiflist;
-#endif
};
#endif
@@ -2198,7 +1960,7 @@ int pf_source_clr(struct pfioc_source_kill *);
struct pf_kstatus {
counter_u64_t counters[PFRES_MAX]; /* reason for passing/dropping */
counter_u64_t lcounters[KLCNT_MAX]; /* limit counters */
- struct pf_counter_u64 fcounters[FCNT_MAX]; /* state operation counters */
+ counter_u64_t fcounters[FCNT_MAX]; /* state operation counters */
counter_u64_t scounters[SCNT_MAX]; /* src_node operation counters */
counter_u64_t ncounters[NCNT_MAX];
uint32_t states;
@@ -2703,24 +2465,6 @@ VNET_DECLARE(struct pf_altqqueue *, pf_altq_ifs_inactive);
VNET_DECLARE(struct pf_krulequeue, pf_unlinked_rules);
#define V_pf_unlinked_rules VNET(pf_unlinked_rules)
-#ifdef PF_WANT_32_TO_64_COUNTER
-LIST_HEAD(allkiflist_head, pfi_kkif);
-VNET_DECLARE(struct allkiflist_head, pf_allkiflist);
-#define V_pf_allkiflist VNET(pf_allkiflist)
-VNET_DECLARE(size_t, pf_allkifcount);
-#define V_pf_allkifcount VNET(pf_allkifcount)
-VNET_DECLARE(struct pfi_kkif *, pf_kifmarker);
-#define V_pf_kifmarker VNET(pf_kifmarker)
-
-LIST_HEAD(allrulelist_head, pf_krule);
-VNET_DECLARE(struct allrulelist_head, pf_allrulelist);
-#define V_pf_allrulelist VNET(pf_allrulelist)
-VNET_DECLARE(size_t, pf_allrulecount);
-#define V_pf_allrulecount VNET(pf_allrulecount)
-VNET_DECLARE(struct pf_krule *, pf_rulemarker);
-#define V_pf_rulemarker VNET(pf_rulemarker)
-#endif
-
int pf_start(void);
int pf_stop(void);
void pf_initialize(void);
diff --git a/sys/netpfil/pf/pf.c b/sys/netpfil/pf/pf.c
index f688bf82ddbc..db21fefd9595 100644
--- a/sys/netpfil/pf/pf.c
+++ b/sys/netpfil/pf/pf.c
@@ -195,15 +195,6 @@ VNET_DECLARE(int, pf_vnet_active);
VNET_DEFINE_STATIC(uint32_t, pf_purge_idx);
#define V_pf_purge_idx VNET(pf_purge_idx)
-#ifdef PF_WANT_32_TO_64_COUNTER
-VNET_DEFINE_STATIC(uint32_t, pf_counter_periodic_iter);
-#define V_pf_counter_periodic_iter VNET(pf_counter_periodic_iter)
-
-VNET_DEFINE(struct allrulelist_head, pf_allrulelist);
-VNET_DEFINE(size_t, pf_allrulecount);
-VNET_DEFINE(struct pf_krule *, pf_rulemarker);
-#endif
-
#define PF_SCTP_MAX_ENDPOINTS 8
struct pf_sctp_endpoint;
@@ -2202,7 +2193,7 @@ pf_state_insert(struct pfi_kkif *kif, struct pfi_kkif *orig_kif,
/* One for keys, one for ID hash. */
refcount_init(&s->refs, 2);
- pf_counter_u64_add(&V_pf_status.fcounters[FCNT_STATE_INSERT], 1);
+ counter_u64_add(V_pf_status.fcounters[FCNT_STATE_INSERT], 1);
if (V_pfsync_insert_state_ptr != NULL)
V_pfsync_insert_state_ptr(s);
@@ -2219,7 +2210,7 @@ pf_find_state_byid(uint64_t id, uint32_t creatorid)
struct pf_idhash *ih;
struct pf_kstate *s;
- pf_counter_u64_add(&V_pf_status.fcounters[FCNT_STATE_SEARCH], 1);
+ counter_u64_add(V_pf_status.fcounters[FCNT_STATE_SEARCH], 1);
ih = &V_pf_idhash[PF_IDHASHID(id)];
@@ -2249,7 +2240,7 @@ pf_find_state(struct pf_pdesc *pd, const struct pf_state_key_cmp *key,
*state = NULL;
- pf_counter_u64_add(&V_pf_status.fcounters[FCNT_STATE_SEARCH], 1);
+ counter_u64_add(V_pf_status.fcounters[FCNT_STATE_SEARCH], 1);
kh = &V_pf_keyhash[pf_hashkey((const struct pf_state_key *)key)];
@@ -2346,7 +2337,7 @@ pf_find_state_all(const struct pf_state_key_cmp *key, u_int dir, int *more)
if (more != NULL)
*more = 0;
- pf_counter_u64_add(&V_pf_status.fcounters[FCNT_STATE_SEARCH], 1);
+ counter_u64_add(V_pf_status.fcounters[FCNT_STATE_SEARCH], 1);
kh = &V_pf_keyhash[pf_hashkey((const struct pf_state_key *)key)];
@@ -2871,122 +2862,6 @@ pf_intr(void *v)
#define pf_purge_thread_period (hz / 10)
-#ifdef PF_WANT_32_TO_64_COUNTER
-static void
-pf_status_counter_u64_periodic(void)
-{
-
- PF_RULES_RASSERT();
-
- if ((V_pf_counter_periodic_iter % (pf_purge_thread_period * 10 * 60)) != 0) {
- return;
- }
-
- for (int i = 0; i < FCNT_MAX; i++) {
- pf_counter_u64_periodic(&V_pf_status.fcounters[i]);
- }
-}
-
-static void
-pf_kif_counter_u64_periodic(void)
-{
- struct pfi_kkif *kif;
- size_t r, run;
-
- PF_RULES_RASSERT();
-
- if (__predict_false(V_pf_allkifcount == 0)) {
- return;
- }
-
- if ((V_pf_counter_periodic_iter % (pf_purge_thread_period * 10 * 300)) != 0) {
- return;
- }
-
- run = V_pf_allkifcount / 10;
- if (run < 5)
- run = 5;
-
- for (r = 0; r < run; r++) {
- kif = LIST_NEXT(V_pf_kifmarker, pfik_allkiflist);
- if (kif == NULL) {
- LIST_REMOVE(V_pf_kifmarker, pfik_allkiflist);
- LIST_INSERT_HEAD(&V_pf_allkiflist, V_pf_kifmarker, pfik_allkiflist);
- break;
- }
-
- LIST_REMOVE(V_pf_kifmarker, pfik_allkiflist);
- LIST_INSERT_AFTER(kif, V_pf_kifmarker, pfik_allkiflist);
-
- for (int i = 0; i < 2; i++) {
- for (int j = 0; j < 2; j++) {
- for (int k = 0; k < 2; k++) {
- pf_counter_u64_periodic(&kif->pfik_packets[i][j][k]);
- pf_counter_u64_periodic(&kif->pfik_bytes[i][j][k]);
- }
- }
- }
- }
-}
-
-static void
-pf_rule_counter_u64_periodic(void)
-{
- struct pf_krule *rule;
- size_t r, run;
-
- PF_RULES_RASSERT();
-
- if (__predict_false(V_pf_allrulecount == 0)) {
- return;
- }
-
- if ((V_pf_counter_periodic_iter % (pf_purge_thread_period * 10 * 300)) != 0) {
- return;
- }
-
- run = V_pf_allrulecount / 10;
- if (run < 5)
- run = 5;
-
- for (r = 0; r < run; r++) {
- rule = LIST_NEXT(V_pf_rulemarker, allrulelist);
- if (rule == NULL) {
- LIST_REMOVE(V_pf_rulemarker, allrulelist);
- LIST_INSERT_HEAD(&V_pf_allrulelist, V_pf_rulemarker, allrulelist);
- break;
- }
-
- LIST_REMOVE(V_pf_rulemarker, allrulelist);
- LIST_INSERT_AFTER(rule, V_pf_rulemarker, allrulelist);
-
- pf_counter_u64_periodic(&rule->evaluations);
- for (int i = 0; i < 2; i++) {
- pf_counter_u64_periodic(&rule->packets[i]);
- pf_counter_u64_periodic(&rule->bytes[i]);
- }
- }
-}
-
-static void
-pf_counter_u64_periodic_main(void)
-{
- PF_RULES_RLOCK_TRACKER;
-
- V_pf_counter_periodic_iter++;
-
- PF_RULES_RLOCK();
- pf_counter_u64_critical_enter();
- pf_status_counter_u64_periodic();
- pf_kif_counter_u64_periodic();
- pf_rule_counter_u64_periodic();
- pf_counter_u64_critical_exit();
- PF_RULES_RUNLOCK();
-}
-#else
-#define pf_counter_u64_periodic_main() do { } while (0)
-#endif
-
void
pf_purge_thread(void *unused __unused)
{
@@ -3009,8 +2884,6 @@ pf_purge_thread(void *unused __unused)
continue;
}
- pf_counter_u64_periodic_main();
-
/*
* Process 1/interval fraction of the state
* table every run.
@@ -3328,7 +3201,7 @@ pf_free_state(struct pf_kstate *cur)
pf_free_match_rules(&(cur->match_rules));
pf_normalize_tcp_cleanup(cur);
uma_zfree(V_pf_state_z, cur);
- pf_counter_u64_add(&V_pf_status.fcounters[FCNT_STATE_REMOVALS], 1);
+ counter_u64_add(V_pf_status.fcounters[FCNT_STATE_REMOVALS], 1);
}
static inline void
@@ -6106,7 +5979,7 @@ pf_match_rule(struct pf_test_ctx *ctx, struct pf_kruleset *ruleset)
PF_TEST_ATTRIB(r->rule_flag & PFRULE_EXPIRED,
TAILQ_NEXT(r, entries));
/* Don't count expired rule evaluations. */
- pf_counter_u64_add(&r->evaluations, 1);
+ counter_u64_add(r->evaluations, 1);
PF_TEST_ATTRIB(pfi_kkif_match(r->kif, pd->kif) == r->ifnot,
r->skip[PF_SKIP_IFP]);
PF_TEST_ATTRIB(r->direction && r->direction != pd->dir,
@@ -10060,14 +9933,12 @@ pf_route(struct pf_krule *r, struct ifnet *oifp,
if (skip_test) {
struct pfi_kkif *out_kif = (struct pfi_kkif *)ifp->if_pf_kif;
MPASS(s != NULL);
- pf_counter_u64_critical_enter();
- pf_counter_u64_add_protected(
- &out_kif->pfik_bytes[pd->naf == AF_INET6][1]
+ counter_u64_add(
+ out_kif->pfik_bytes[pd->naf == AF_INET6][1]
[action != PF_PASS && action != PF_AFRT], pd->tot_len);
- pf_counter_u64_add_protected(
- &out_kif->pfik_packets[pd->naf == AF_INET6][1]
+ counter_u64_add(
+ out_kif->pfik_packets[pd->naf == AF_INET6][1]
[action != PF_PASS && action != PF_AFRT], 1);
- pf_counter_u64_critical_exit();
} else {
if (pf_test(AF_INET, PF_OUT, PFIL_FWD, ifp, &m0, inp,
&pd->act) != PF_PASS) {
@@ -10406,14 +10277,12 @@ pf_route6(struct pf_krule *r, struct ifnet *oifp,
if (skip_test) {
struct pfi_kkif *out_kif = (struct pfi_kkif *)ifp->if_pf_kif;
MPASS(s != NULL);
- pf_counter_u64_critical_enter();
- pf_counter_u64_add_protected(
- &out_kif->pfik_bytes[pd->naf == AF_INET6][1]
+ counter_u64_add(
+ out_kif->pfik_bytes[pd->naf == AF_INET6][1]
[action != PF_PASS && action != PF_AFRT], pd->tot_len);
- pf_counter_u64_add_protected(
- &out_kif->pfik_packets[pd->naf == AF_INET6][1]
+ counter_u64_add(
+ out_kif->pfik_packets[pd->naf == AF_INET6][1]
[action != PF_PASS && action != PF_AFRT], 1);
- pf_counter_u64_critical_exit();
} else {
if (pf_test(AF_INET6, PF_OUT, PFIL_FWD | PF_PFIL_NOREFRAGMENT,
ifp, &m0, inp, &pd->act) != PF_PASS) {
@@ -11603,8 +11472,8 @@ pf_rule_counters_inc(struct pf_pdesc *pd, struct pf_krule *r, int dir_out,
int op_pass, sa_family_t af, struct pf_addr *src_host,
struct pf_addr *dst_host)
{
- pf_counter_u64_add_protected(&(r->packets[dir_out]), 1);
- pf_counter_u64_add_protected(&(r->bytes[dir_out]), pd->tot_len);
+ counter_u64_add(r->packets[dir_out], 1);
+ counter_u64_add(r->bytes[dir_out], pd->tot_len);
pf_update_timestamp(r);
if (r->src.addr.type == PF_ADDR_TABLE)
@@ -11631,8 +11500,6 @@ pf_counters_inc(int action, struct pf_pdesc *pd, struct pf_kstate *s,
int s_dir_in, s_dir_out, s_dir_rev;
sa_family_t af = pd->af;
- pf_counter_u64_critical_enter();
-
/*
* Set AF for interface counters, it will be later overwritten for
* rule and state counters with value from proper state key.
@@ -11643,16 +11510,15 @@ pf_counters_inc(int action, struct pf_pdesc *pd, struct pf_kstate *s,
af = pd->naf;
}
- pf_counter_u64_add_protected(
- &pd->kif->pfik_bytes[af == AF_INET6][dir_out][!op_pass],
+ counter_u64_add(
+ pd->kif->pfik_bytes[af == AF_INET6][dir_out][!op_pass],
pd->tot_len);
- pf_counter_u64_add_protected(
- &pd->kif->pfik_packets[af == AF_INET6][dir_out][!op_pass],
+ counter_u64_add(
+ pd->kif->pfik_packets[af == AF_INET6][dir_out][!op_pass],
1);
/* If the rule has failed to apply, don't increase its counters */
if (!(op_pass || r->action == PF_DROP)) {
- pf_counter_u64_critical_exit();
return;
}
@@ -11751,8 +11617,6 @@ pf_counters_inc(int action, struct pf_pdesc *pd, struct pf_kstate *s,
src_host, dst_host);
}
- pf_counter_u64_critical_exit();
-
if (s == NULL) {
pf_free_match_rules(mr);
}
diff --git a/sys/netpfil/pf/pf_if.c b/sys/netpfil/pf/pf_if.c
index 7528e920e433..57dfb0a8031d 100644
--- a/sys/netpfil/pf/pf_if.c
+++ b/sys/netpfil/pf/pf_if.c
@@ -68,12 +68,6 @@ VNET_DEFINE_STATIC(int, pfi_buffer_max);
#define V_pfi_buffer_cnt VNET(pfi_buffer_cnt)
#define V_pfi_buffer_max VNET(pfi_buffer_max)
-#ifdef PF_WANT_32_TO_64_COUNTER
-VNET_DEFINE(struct allkiflist_head, pf_allkiflist);
-VNET_DEFINE(size_t, pf_allkifcount);
-VNET_DEFINE(struct pfi_kkif *, pf_kifmarker);
-#endif
-
static eventhandler_tag pfi_attach_cookie;
static eventhandler_tag pfi_detach_cookie;
static eventhandler_tag pfi_rename_cookie;
@@ -232,9 +226,6 @@ struct pfi_kkif*
pf_kkif_create(int flags)
{
struct pfi_kkif *kif;
-#ifdef PF_WANT_32_TO_64_COUNTER
- bool wowned;
-#endif
kif = malloc(sizeof(*kif), PFI_MTYPE, flags | M_ZERO);
if (! kif)
@@ -243,12 +234,13 @@ pf_kkif_create(int flags)
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
for (int k = 0; k < 2; k++) {
- if (pf_counter_u64_init(&kif->pfik_packets[i][j][k], flags) != 0) {
- pf_kkif_free(kif);
- return (NULL);
- }
+ kif->pfik_packets[i][j][k] =
+ counter_u64_alloc(flags);
+ kif->pfik_bytes[i][j][k] =
+ counter_u64_alloc(flags);
- if (pf_counter_u64_init(&kif->pfik_bytes[i][j][k], flags) != 0) {
+ if (! kif->pfik_packets[i][j][k] ||
+ ! kif->pfik_bytes[i][j][k]) {
pf_kkif_free(kif);
return (NULL);
}
@@ -256,25 +248,12 @@ pf_kkif_create(int flags)
}
}
-#ifdef PF_WANT_32_TO_64_COUNTER
- wowned = PF_RULES_WOWNED();
- if (!wowned)
- PF_RULES_WLOCK();
- LIST_INSERT_HEAD(&V_pf_allkiflist, kif, pfik_allkiflist);
- V_pf_allkifcount++;
- if (!wowned)
- PF_RULES_WUNLOCK();
-#endif
-
return (kif);
}
void
pf_kkif_free(struct pfi_kkif *kif)
{
-#ifdef PF_WANT_32_TO_64_COUNTER
- bool wowned;
-#endif
if (! kif)
return;
@@ -286,21 +265,11 @@ pf_kkif_free(struct pfi_kkif *kif)
}
#endif
-#ifdef PF_WANT_32_TO_64_COUNTER
- wowned = PF_RULES_WOWNED();
- if (!wowned)
- PF_RULES_WLOCK();
- LIST_REMOVE(kif, pfik_allkiflist);
- V_pf_allkifcount--;
- if (!wowned)
- PF_RULES_WUNLOCK();
-#endif
-
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
for (int k = 0; k < 2; k++) {
- pf_counter_u64_deinit(&kif->pfik_packets[i][j][k]);
- pf_counter_u64_deinit(&kif->pfik_bytes[i][j][k]);
+ counter_u64_free(kif->pfik_packets[i][j][k]);
+ counter_u64_free(kif->pfik_bytes[i][j][k]);
}
}
}
@@ -315,8 +284,8 @@ pf_kkif_zero(struct pfi_kkif *kif)
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
for (int k = 0; k < 2; k++) {
- pf_counter_u64_zero(&kif->pfik_packets[i][j][k]);
- pf_counter_u64_zero(&kif->pfik_bytes[i][j][k]);
+ counter_u64_zero(kif->pfik_packets[i][j][k]);
+ counter_u64_zero(kif->pfik_bytes[i][j][k]);
}
}
}
@@ -917,15 +886,15 @@ pfi_update_status(const char *name, struct pf_status *pfs)
for (j = 0; j < 2; j++)
for (k = 0; k < 2; k++) {
pfs->pcounters[i][j][k] +=
- pf_counter_u64_fetch(&p->pfik_packets[i][j][k]);
+ counter_u64_fetch(p->pfik_packets[i][j][k]);
pfs->bcounters[i][j] +=
- pf_counter_u64_fetch(&p->pfik_bytes[i][j][k]);
+ counter_u64_fetch(p->pfik_bytes[i][j][k]);
}
}
}
static void
-pf_kkif_to_kif(struct pfi_kkif *kkif, struct pfi_kif *kif)
+pf_kkif_to_kif(const struct pfi_kkif *kkif, struct pfi_kif *kif)
{
memset(kif, 0, sizeof(*kif));
@@ -934,9 +903,9 @@ pf_kkif_to_kif(struct pfi_kkif *kkif, struct pfi_kif *kif)
for (int j = 0; j < 2; j++) {
for (int k = 0; k < 2; k++) {
kif->pfik_packets[i][j][k] =
- pf_counter_u64_fetch(&kkif->pfik_packets[i][j][k]);
+ counter_u64_fetch(kkif->pfik_packets[i][j][k]);
kif->pfik_bytes[i][j][k] =
- pf_counter_u64_fetch(&kkif->pfik_bytes[i][j][k]);
+ counter_u64_fetch(kkif->pfik_bytes[i][j][k]);
}
}
}
diff --git a/sys/netpfil/pf/pf_ioctl.c b/sys/netpfil/pf/pf_ioctl.c
index 27a6528d7e91..3dda0a17754d 100644
--- a/sys/netpfil/pf/pf_ioctl.c
+++ b/sys/netpfil/pf/pf_ioctl.c
@@ -352,10 +352,10 @@ pfattach_vnet(void)
V_pf_default_rule.nr = (uint32_t)-1;
V_pf_default_rule.rtableid = -1;
- pf_counter_u64_init(&V_pf_default_rule.evaluations, M_WAITOK);
+ V_pf_default_rule.evaluations = counter_u64_alloc(M_WAITOK);
for (int i = 0; i < 2; i++) {
- pf_counter_u64_init(&V_pf_default_rule.packets[i], M_WAITOK);
- pf_counter_u64_init(&V_pf_default_rule.bytes[i], M_WAITOK);
+ V_pf_default_rule.packets[i] = counter_u64_alloc(M_WAITOK);
+ V_pf_default_rule.bytes[i] = counter_u64_alloc(M_WAITOK);
}
V_pf_default_rule.states_cur = counter_u64_alloc(M_WAITOK);
V_pf_default_rule.states_tot = counter_u64_alloc(M_WAITOK);
@@ -365,17 +365,6 @@ pfattach_vnet(void)
V_pf_default_rule.timestamp = uma_zalloc_pcpu(pf_timestamp_pcpu_zone,
M_WAITOK | M_ZERO);
-#ifdef PF_WANT_32_TO_64_COUNTER
- V_pf_kifmarker = malloc(sizeof(*V_pf_kifmarker), PFI_MTYPE, M_WAITOK | M_ZERO);
- V_pf_rulemarker = malloc(sizeof(*V_pf_rulemarker), M_PFRULE, M_WAITOK | M_ZERO);
- PF_RULES_WLOCK();
- LIST_INSERT_HEAD(&V_pf_allkiflist, V_pf_kifmarker, pfik_allkiflist);
- LIST_INSERT_HEAD(&V_pf_allrulelist, &V_pf_default_rule, allrulelist);
- V_pf_allrulecount++;
- LIST_INSERT_HEAD(&V_pf_allrulelist, V_pf_rulemarker, allrulelist);
- PF_RULES_WUNLOCK();
-#endif
-
/* initialize default timeouts */
my_timeout[PFTM_TCP_FIRST_PACKET] = PFTM_TCP_FIRST_PACKET_VAL;
my_timeout[PFTM_TCP_OPENING] = PFTM_TCP_OPENING_VAL;
@@ -424,7 +413,7 @@ pfattach_vnet(void)
for (int i = 0; i < KLCNT_MAX; i++)
V_pf_status.lcounters[i] = counter_u64_alloc(M_WAITOK);
for (int i = 0; i < FCNT_MAX; i++)
- pf_counter_u64_init(&V_pf_status.fcounters[i], M_WAITOK);
+ V_pf_status.fcounters[i] = counter_u64_alloc(M_WAITOK);
for (int i = 0; i < SCNT_MAX; i++)
V_pf_status.scounters[i] = counter_u64_alloc(M_WAITOK);
for (int i = 0; i < NCNT_MAX; i++)
@@ -1577,18 +1566,16 @@ pf_commit_rules(u_int32_t ticket, int rs_num, char *anchor)
if (old_rule == NULL) {
continue;
}
- pf_counter_u64_critical_enter();
- pf_counter_u64_rollup_protected(&rule->evaluations,
- pf_counter_u64_fetch(&old_rule->evaluations));
- pf_counter_u64_rollup_protected(&rule->packets[0],
- pf_counter_u64_fetch(&old_rule->packets[0]));
- pf_counter_u64_rollup_protected(&rule->packets[1],
- pf_counter_u64_fetch(&old_rule->packets[1]));
- pf_counter_u64_rollup_protected(&rule->bytes[0],
- pf_counter_u64_fetch(&old_rule->bytes[0]));
- pf_counter_u64_rollup_protected(&rule->bytes[1],
- pf_counter_u64_fetch(&old_rule->bytes[1]));
- pf_counter_u64_critical_exit();
+ counter_u64_add(rule->evaluations,
+ counter_u64_fetch(old_rule->evaluations));
+ counter_u64_add(rule->packets[0],
+ counter_u64_fetch(old_rule->packets[0]));
+ counter_u64_add(rule->packets[1],
+ counter_u64_fetch(old_rule->packets[1]));
+ counter_u64_add(rule->bytes[0],
+ counter_u64_fetch(old_rule->bytes[0]));
+ counter_u64_add(rule->bytes[1],
+ counter_u64_fetch(old_rule->bytes[1]));
}
}
@@ -2735,29 +2722,13 @@ pf_krule_alloc(void)
void
pf_krule_free(struct pf_krule *rule)
{
-#ifdef PF_WANT_32_TO_64_COUNTER
- bool wowned;
-#endif
-
if (rule == NULL)
return;
-#ifdef PF_WANT_32_TO_64_COUNTER
- if (rule->allrulelinked) {
- wowned = PF_RULES_WOWNED();
- if (!wowned)
- PF_RULES_WLOCK();
- LIST_REMOVE(rule, allrulelist);
- V_pf_allrulecount--;
- if (!wowned)
- PF_RULES_WUNLOCK();
- }
-#endif
-
- pf_counter_u64_deinit(&rule->evaluations);
+ counter_u64_free(rule->evaluations);
for (int i = 0; i < 2; i++) {
- pf_counter_u64_deinit(&rule->packets[i]);
- pf_counter_u64_deinit(&rule->bytes[i]);
+ counter_u64_free(rule->packets[i]);
+ counter_u64_free(rule->bytes[i]);
}
counter_u64_free(rule->states_cur);
counter_u64_free(rule->states_tot);
@@ -2775,10 +2746,10 @@ pf_krule_free(struct pf_krule *rule)
void
pf_krule_clear_counters(struct pf_krule *rule)
{
- pf_counter_u64_zero(&rule->evaluations);
+ counter_u64_zero(rule->evaluations);
for (int i = 0; i < 2; i++) {
- pf_counter_u64_zero(&rule->packets[i]);
- pf_counter_u64_zero(&rule->bytes[i]);
+ counter_u64_zero(rule->packets[i]);
+ counter_u64_zero(rule->bytes[i]);
}
counter_u64_zero(rule->states_tot);
}
@@ -3060,10 +3031,10 @@ pf_ioctl_addrule(struct pf_krule *rule, uint32_t ticket,
kif = pf_kkif_create(M_WAITOK);
if (rule->rcv_ifname[0])
rcv_kif = pf_kkif_create(M_WAITOK);
- pf_counter_u64_init(&rule->evaluations, M_WAITOK);
+ rule->evaluations = counter_u64_alloc(M_WAITOK);
for (int i = 0; i < 2; i++) {
- pf_counter_u64_init(&rule->packets[i], M_WAITOK);
- pf_counter_u64_init(&rule->bytes[i], M_WAITOK);
+ rule->packets[i] = counter_u64_alloc(M_WAITOK);
+ rule->bytes[i] = counter_u64_alloc(M_WAITOK);
}
rule->states_cur = counter_u64_alloc(M_WAITOK);
rule->states_tot = counter_u64_alloc(M_WAITOK);
@@ -3077,12 +3048,6 @@ pf_ioctl_addrule(struct pf_krule *rule, uint32_t ticket,
PF_CONFIG_LOCK();
PF_RULES_WLOCK();
-#ifdef PF_WANT_32_TO_64_COUNTER
- LIST_INSERT_HEAD(&V_pf_allrulelist, rule, allrulelist);
- MPASS(!rule->allrulelinked);
- rule->allrulelinked = true;
- V_pf_allrulecount++;
-#endif
ruleset = pf_find_kruleset(anchor);
if (ruleset == NULL)
ERROUT(EINVAL);
@@ -3445,7 +3410,7 @@ pf_ioctl_clear_status(void)
for (int i = 0; i < PFRES_MAX; i++)
counter_u64_zero(V_pf_status.counters[i]);
for (int i = 0; i < FCNT_MAX; i++)
- pf_counter_u64_zero(&V_pf_status.fcounters[i]);
+ counter_u64_zero(V_pf_status.fcounters[i]);
for (int i = 0; i < SCNT_MAX; i++)
counter_u64_zero(V_pf_status.scounters[i]);
for (int i = 0; i < NCNT_MAX; i++)
@@ -4939,10 +4904,12 @@ DIOCGETRULENV_error:
}
if (newrule->ifname[0])
kif = pf_kkif_create(M_WAITOK);
- pf_counter_u64_init(&newrule->evaluations, M_WAITOK);
+ newrule->evaluations = counter_u64_alloc(M_WAITOK);
for (int i = 0; i < 2; i++) {
- pf_counter_u64_init(&newrule->packets[i], M_WAITOK);
- pf_counter_u64_init(&newrule->bytes[i], M_WAITOK);
+ newrule->packets[i] =
+ counter_u64_alloc(M_WAITOK);
+ newrule->bytes[i] =
+ counter_u64_alloc(M_WAITOK);
}
newrule->states_cur = counter_u64_alloc(M_WAITOK);
newrule->states_tot = counter_u64_alloc(M_WAITOK);
@@ -4958,14 +4925,6 @@ DIOCGETRULENV_error:
PF_CONFIG_LOCK();
PF_RULES_WLOCK();
-#ifdef PF_WANT_32_TO_64_COUNTER
- if (newrule != NULL) {
- LIST_INSERT_HEAD(&V_pf_allrulelist, newrule, allrulelist);
- newrule->allrulelinked = true;
- V_pf_allrulecount++;
- }
-#endif
-
if (!(pcr->action == PF_CHANGE_REMOVE ||
pcr->action == PF_CHANGE_GET_TICKET) &&
pcr->pool_ticket != V_ticket_pabuf)
@@ -5446,10 +5405,10 @@ DIOCGETSTATESV2_full:
PF_RULES_WLOCK();
TAILQ_FOREACH(rule,
ruleset->rules[PF_RULESET_FILTER].active.ptr, entries) {
- pf_counter_u64_zero(&rule->evaluations);
+ counter_u64_zero(rule->evaluations);
for (int i = 0; i < 2; i++) {
- pf_counter_u64_zero(&rule->packets[i]);
- pf_counter_u64_zero(&rule->bytes[i]);
+ counter_u64_zero(rule->packets[i]);
+ counter_u64_zero(rule->bytes[i]);
}
}
PF_RULES_WUNLOCK();
@@ -6964,21 +6923,10 @@ pf_getstatus(struct pfioc_nv *nv)
ERROUT(error);
/* fcounters */
*** 247 LINES SKIPPED ***