the pf_state_tree_id type is private to the kernel.
while here, move it from being an RB tree to an RBT tree. this saves
about 12k in pf.o on amd64.
ok sashan@
-/* $OpenBSD: if_pfsync.c,v 1.311 2022/11/11 11:47:13 dlg Exp $ */
+/* $OpenBSD: if_pfsync.c,v 1.312 2023/01/04 10:31:55 dlg Exp $ */
/*
* Copyright (c) 2002 Michael Shalayeff
continue;
PF_STATE_ENTER_WRITE();
- for (st = RB_MIN(pf_state_tree_id, &tree_id); st; st = nexts) {
- nexts = RB_NEXT(pf_state_tree_id, &tree_id, st);
+ RBT_FOREACH_SAFE(st, pf_state_tree_id, &tree_id, nexts) {
if (st->creatorid == creatorid &&
((kif && st->kif == kif) || !kif)) {
SET(st->state_flags, PFSTATE_NOSYNC);
-/* $OpenBSD: pf.c,v 1.1166 2023/01/04 02:00:49 dlg Exp $ */
+/* $OpenBSD: pf.c,v 1.1167 2023/01/04 10:31:55 dlg Exp $ */
/*
* Copyright (c) 2001 Daniel Hartmeier
static __inline int pf_src_compare(struct pf_src_node *, struct pf_src_node *);
static inline int pf_state_compare_key(const struct pf_state_key *,
const struct pf_state_key *);
-static __inline int pf_state_compare_id(struct pf_state *,
- struct pf_state *);
+static inline int pf_state_compare_id(const struct pf_state *,
+ const struct pf_state *);
#ifdef INET6
static __inline void pf_cksum_uncover(u_int16_t *, u_int16_t, u_int8_t);
static __inline void pf_cksum_cover(u_int16_t *, u_int16_t, u_int8_t);
RB_GENERATE(pf_src_tree, pf_src_node, entry, pf_src_compare);
RBT_GENERATE(pf_state_tree, pf_state_key, sk_entry, pf_state_compare_key);
-RB_GENERATE(pf_state_tree_id, pf_state,
- entry_id, pf_state_compare_id);
+RBT_GENERATE(pf_state_tree_id, pf_state, entry_id, pf_state_compare_id);
int
pf_addr_compare(const struct pf_addr *a, const struct pf_addr *b,
struct pf_state *st;
pf_status.lcounters[LCNT_OVERLOAD_FLUSH]++;
- RB_FOREACH(st, pf_state_tree_id, &tree_id) {
+ RBT_FOREACH(st, pf_state_tree_id, &tree_id) {
sk = st->key[PF_SK_WIRE];
/*
* Kill states from this source. (Only those
return (0);
}
-static __inline int
-pf_state_compare_id(struct pf_state *a, struct pf_state *b)
+static inline int
+pf_state_compare_id(const struct pf_state *a, const struct pf_state *b)
{
if (a->id > b->id)
return (1);
s->id = htobe64(pf_status.stateid++);
s->creatorid = pf_status.hostid;
}
- if (RB_INSERT(pf_state_tree_id, &tree_id, s) != NULL) {
+ if (RBT_INSERT(pf_state_tree_id, &tree_id, s) != NULL) {
if (pf_status.debug >= LOG_NOTICE) {
log(LOG_NOTICE, "pf: state insert failed: "
"id: %016llx creatorid: %08x",
{
pf_status.fcounters[FCNT_STATE_SEARCH]++;
- return (RB_FIND(pf_state_tree_id, &tree_id, (struct pf_state *)key));
+ return (RBT_FIND(pf_state_tree_id, &tree_id, (struct pf_state *)key));
}
int
if (cur->key[PF_SK_STACK]->proto == IPPROTO_TCP)
pf_set_protostate(cur, PF_PEER_BOTH, TCPS_CLOSED);
- RB_REMOVE(pf_state_tree_id, &tree_id, cur);
+ RBT_REMOVE(pf_state_tree_id, &tree_id, cur);
#if NPFLOW > 0
if (cur->state_flags & PFSTATE_PFLOW)
export_pflow(cur);
-/* $OpenBSD: pf_ioctl.c,v 1.394 2023/01/04 02:00:49 dlg Exp $ */
+/* $OpenBSD: pf_ioctl.c,v 1.395 2023/01/04 10:31:55 dlg Exp $ */
/*
* Copyright (c) 2001 Daniel Hartmeier
NET_LOCK();
PF_LOCK();
PF_STATE_ENTER_WRITE();
- for (s = RB_MIN(pf_state_tree_id, &tree_id); s;
- s = nexts) {
- nexts = RB_NEXT(pf_state_tree_id, &tree_id, s);
-
+ RBT_FOREACH_SAFE(s, pf_state_tree_id, &tree_id, nexts) {
if (s->direction == PF_OUT) {
sk = s->key[PF_SK_STACK];
srcaddr = &sk->addr[1];
NET_LOCK();
PF_LOCK();
PF_STATE_ENTER_WRITE();
- RB_FOREACH(state, pf_state_tree_id, &tree_id)
+ RBT_FOREACH(state, pf_state_tree_id, &tree_id)
pf_src_tree_remove_state(state);
PF_STATE_EXIT_WRITE();
RB_FOREACH(n, pf_src_tree, &tree_src_tracking)
if (sn->states != 0) {
PF_ASSERT_LOCKED();
PF_STATE_ENTER_WRITE();
- RB_FOREACH(s, pf_state_tree_id,
+ RBT_FOREACH(s, pf_state_tree_id,
&tree_id)
pf_state_rm_src_node(s, sn);
PF_STATE_EXIT_WRITE();
-/* $OpenBSD: pf_lb.c,v 1.72 2022/08/31 11:29:12 benno Exp $ */
+/* $OpenBSD: pf_lb.c,v 1.73 2023/01/04 10:31:55 dlg Exp $ */
/*
* Copyright (c) 2001 Daniel Hartmeier
}
if (sns[type]->states != 0) {
/* XXX expensive */
- RB_FOREACH(s, pf_state_tree_id,
- &tree_id)
- pf_state_rm_src_node(s,
- sns[type]);
+ RBT_FOREACH(s, pf_state_tree_id, &tree_id)
+ pf_state_rm_src_node(s, sns[type]);
}
sns[type]->expire = 1;
pf_remove_src_node(sns[type]);
-/* $OpenBSD: pfvar.h,v 1.526 2023/01/04 02:00:49 dlg Exp $ */
+/* $OpenBSD: pfvar.h,v 1.527 2023/01/04 10:31:55 dlg Exp $ */
/*
* Copyright (c) 2001 Daniel Hartmeier
RB_PROTOTYPE(pf_src_tree, pf_src_node, entry, pf_src_compare);
extern struct pf_src_tree tree_src_tracking;
-RB_HEAD(pf_state_tree_id, pf_state);
-RB_PROTOTYPE(pf_state_tree_id, pf_state,
- entry_id, pf_state_compare_id);
-extern struct pf_state_tree_id tree_id;
extern struct pf_state_list pf_state_list;
TAILQ_HEAD(pf_queuehead, pf_queuespec);
-/* $OpenBSD: pfvar_priv.h,v 1.28 2023/01/04 02:00:49 dlg Exp $ */
+/* $OpenBSD: pfvar_priv.h,v 1.29 2023/01/04 10:31:55 dlg Exp $ */
/*
* Copyright (c) 2001 Daniel Hartmeier
u_int8_t snapped; /* [S] */
};
+RBT_HEAD(pf_state_tree_id, pf_state);
+RBT_PROTOTYPE(pf_state_tree_id, pf_state, entry_id, pf_state_compare_id);
+extern struct pf_state_tree_id tree_id;
+
/*
*
* states are linked into a global list to support the following