pf: Factor out pf_krule_free()

Reviewed by:	melifaro@
MFC after:	1 week
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D29194
This commit is contained in:
Kristof Provost 2021-03-10 11:10:04 +01:00
parent 17b14d8f77
commit 5e9dae8e14
2 changed files with 23 additions and 29 deletions

View File

@ -1641,6 +1641,8 @@ void pf_remove_if_empty_kruleset(struct pf_kruleset *);
struct pf_kruleset *pf_find_kruleset(const char *);
struct pf_kruleset *pf_find_or_create_kruleset(const char *);
void pf_rs_initialize(void);
void pf_krule_free(struct pf_krule *);
#endif
/* The fingerprint functions can be linked into userland programs (tcpdump) */

View File

@ -466,15 +466,8 @@ pf_free_rule(struct pf_krule *rule)
pfi_kkif_unref(rule->kif);
pf_kanchor_remove(rule);
pf_empty_kpool(&rule->rpool.list);
counter_u64_free(rule->evaluations);
for (int i = 0; i < 2; 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);
counter_u64_free(rule->src_nodes);
free(rule, M_PFRULE);
pf_krule_free(rule);
}
static void
@ -1435,6 +1428,23 @@ pf_altq_get_nth_active(u_int32_t n)
}
#endif /* ALTQ */
void
pf_krule_free(struct pf_krule *rule)
{
if (rule == NULL)
return;
counter_u64_free(rule->evaluations);
for (int i = 0; i < 2; 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);
counter_u64_free(rule->src_nodes);
free(rule, M_PFRULE);
}
static void
pf_kpooladdr_to_pooladdr(const struct pf_kpooladdr *kpool,
struct pf_pooladdr *pool)
@ -1990,15 +2000,7 @@ pfioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flags, struct thread *td
#undef ERROUT
DIOCADDRULE_error:
PF_RULES_WUNLOCK();
counter_u64_free(rule->evaluations);
for (int i = 0; i < 2; 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);
counter_u64_free(rule->src_nodes);
free(rule, M_PFRULE);
pf_krule_free(rule);
if (kif)
pf_kkif_free(kif);
break;
@ -2297,17 +2299,7 @@ pfioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flags, struct thread *td
#undef ERROUT
DIOCCHANGERULE_error:
PF_RULES_WUNLOCK();
if (newrule != NULL) {
counter_u64_free(newrule->evaluations);
for (int i = 0; i < 2; i++) {
counter_u64_free(newrule->packets[i]);
counter_u64_free(newrule->bytes[i]);
}
counter_u64_free(newrule->states_cur);
counter_u64_free(newrule->states_tot);
counter_u64_free(newrule->src_nodes);
free(newrule, M_PFRULE);
}
pf_krule_free(newrule);
if (kif != NULL)
pf_kkif_free(kif);
break;