From: dlg Date: Wed, 4 Jan 2023 02:00:49 +0000 (+0000) Subject: move the pf_state_tree rb tree type from pfvar.h to pfvar_priv.h X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=211190b84f6802d85490bd4ef6b3ac434dd683fd;p=openbsd move the pf_state_tree rb tree type from pfvar.h to pfvar_priv.h the pf_state_tree types are kernel private, and are not used by userland. make build agrees with me. while here, move the pf_state_tree from the RB macros to the RBT functions. this shaves about 13k off pf.o on amd64. ok sashan@ --- diff --git a/sys/net/pf.c b/sys/net/pf.c index fb6af610d5d..b729382a670 100644 --- a/sys/net/pf.c +++ b/sys/net/pf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pf.c,v 1.1165 2023/01/02 05:32:40 dlg Exp $ */ +/* $OpenBSD: pf.c,v 1.1166 2023/01/04 02:00:49 dlg Exp $ */ /* * Copyright (c) 2001 Daniel Hartmeier @@ -303,8 +303,8 @@ struct pf_pool_limit pf_pool_limits[PF_LIMIT_MAX] = { } while (0) static __inline int pf_src_compare(struct pf_src_node *, struct pf_src_node *); -static __inline int pf_state_compare_key(struct pf_state_key *, - struct pf_state_key *); +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 *); #ifdef INET6 @@ -319,12 +319,13 @@ struct pf_state_tree_id tree_id; struct pf_state_list pf_state_list = PF_STATE_LIST_INITIALIZER(pf_state_list); RB_GENERATE(pf_src_tree, pf_src_node, entry, pf_src_compare); -RB_GENERATE(pf_state_tree, pf_state_key, sk_entry, pf_state_compare_key); +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); -__inline int -pf_addr_compare(struct pf_addr *a, struct pf_addr *b, sa_family_t af) +int +pf_addr_compare(const struct pf_addr *a, const struct pf_addr *b, + sa_family_t af) { switch (af) { case AF_INET: @@ -689,8 +690,9 @@ pf_state_rm_src_node(struct pf_state *s, struct pf_src_node *sn) /* state table stuff */ -static __inline int -pf_state_compare_key(struct pf_state_key *a, struct pf_state_key *b) +static inline int +pf_state_compare_key(const struct pf_state_key *a, + const struct pf_state_key *b) { int diff; @@ -743,7 +745,7 @@ pf_state_key_attach(struct pf_state_key *sk, struct pf_state *s, int idx) KASSERT(s->key[idx] == NULL); sk->sk_removed = 0; - cur = RB_INSERT(pf_state_tree, &pf_statetbl, sk); + cur = RBT_INSERT(pf_state_tree, &pf_statetbl, sk); if (cur != NULL) { sk->sk_removed = 1; /* key exists. check for same kif, if none, add to key */ @@ -798,7 +800,7 @@ pf_state_key_attach(struct pf_state_key *sk, struct pf_state *s, int idx) if ((si = pool_get(&pf_state_item_pl, PR_NOWAIT)) == NULL) { if (TAILQ_EMPTY(&sk->sk_states)) { KASSERT(cur == NULL); - RB_REMOVE(pf_state_tree, &pf_statetbl, sk); + RBT_REMOVE(pf_state_tree, &pf_statetbl, sk); sk->sk_removed = 1; pf_state_key_unref(sk); } @@ -856,7 +858,7 @@ pf_state_key_detach(struct pf_state *s, int idx) pool_put(&pf_state_item_pl, si); if (TAILQ_EMPTY(&sk->sk_states)) { - RB_REMOVE(pf_state_tree, &pf_statetbl, sk); + RBT_REMOVE(pf_state_tree, &pf_statetbl, sk); sk->sk_removed = 1; pf_state_key_unlink_reverse(sk); pf_state_key_unlink_inpcb(sk); @@ -1165,7 +1167,7 @@ pf_find_state(struct pf_pdesc *pd, struct pf_state_key_cmp *key, } if (sk == NULL) { - if ((sk = RB_FIND(pf_state_tree, &pf_statetbl, + if ((sk = RBT_FIND(pf_state_tree, &pf_statetbl, (struct pf_state_key *)key)) == NULL) return (PF_DROP); if (pd->dir == PF_OUT && pkt_sk && @@ -1220,7 +1222,7 @@ pf_find_state_all(struct pf_state_key_cmp *key, u_int dir, int *more) pf_status.fcounters[FCNT_STATE_SEARCH]++; - sk = RB_FIND(pf_state_tree, &pf_statetbl, (struct pf_state_key *)key); + sk = RBT_FIND(pf_state_tree, &pf_statetbl, (struct pf_state_key *)key); if (sk != NULL) { TAILQ_FOREACH(si, &sk->sk_states, si_entry) { diff --git a/sys/net/pf_ioctl.c b/sys/net/pf_ioctl.c index e1081f3b931..302984d889d 100644 --- a/sys/net/pf_ioctl.c +++ b/sys/net/pf_ioctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pf_ioctl.c,v 1.393 2022/12/21 02:23:10 dlg Exp $ */ +/* $OpenBSD: pf_ioctl.c,v 1.394 2023/01/04 02:00:49 dlg Exp $ */ /* * Copyright (c) 2001 Daniel Hartmeier @@ -1758,7 +1758,8 @@ pfioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct proc *p) key.port[sidx] = psk->psk_src.port[0]; key.port[didx] = psk->psk_dst.port[0]; - sk = RB_FIND(pf_state_tree, &pf_statetbl, &key); + sk = RBT_FIND(pf_state_tree, &pf_statetbl, + &key); if (sk == NULL) continue; diff --git a/sys/net/pfvar.h b/sys/net/pfvar.h index b169f0a0510..0ac0adbdda1 100644 --- a/sys/net/pfvar.h +++ b/sys/net/pfvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: pfvar.h,v 1.525 2022/12/22 05:59:27 dlg Exp $ */ +/* $OpenBSD: pfvar.h,v 1.526 2023/01/04 02:00:49 dlg Exp $ */ /* * Copyright (c) 2001 Daniel Hartmeier @@ -1033,9 +1033,6 @@ struct pfr_ktable { #define pfrkt_nomatch pfrkt_ts.pfrts_nomatch #define pfrkt_tzero pfrkt_ts.pfrts_tzero -RB_HEAD(pf_state_tree, pf_state_key); -RB_PROTOTYPE(pf_state_tree, pf_state_key, sk_entry, pf_state_compare_key) - RB_HEAD(pf_state_tree_ext_gwy, pf_state_key); RB_PROTOTYPE(pf_state_tree_ext_gwy, pf_state_key, entry_ext_gwy, pf_state_compare_ext_gwy) @@ -1792,8 +1789,8 @@ void pf_tag2tagname(u_int16_t, char *); void pf_tag_ref(u_int16_t); void pf_tag_unref(u_int16_t); void pf_tag_packet(struct mbuf *, int, int); -int pf_addr_compare(struct pf_addr *, struct pf_addr *, - sa_family_t); +int pf_addr_compare(const struct pf_addr *, + const struct pf_addr *, sa_family_t); const struct pfq_ops *pf_queue_manager(struct pf_queuespec *); diff --git a/sys/net/pfvar_priv.h b/sys/net/pfvar_priv.h index 51cc0f66f25..209a2e7ee63 100644 --- a/sys/net/pfvar_priv.h +++ b/sys/net/pfvar_priv.h @@ -1,4 +1,4 @@ -/* $OpenBSD: pfvar_priv.h,v 1.27 2022/12/22 05:59:27 dlg Exp $ */ +/* $OpenBSD: pfvar_priv.h,v 1.28 2023/01/04 02:00:49 dlg Exp $ */ /* * Copyright (c) 2001 Daniel Hartmeier @@ -63,6 +63,10 @@ struct pf_state_key { pf_refcnt_t sk_refcnt; u_int8_t sk_removed; }; + +RBT_HEAD(pf_state_tree, pf_state_key); +RBT_PROTOTYPE(pf_state_tree, pf_state_key, sk_entry, pf_state_compare_key); + #define PF_REVERSED_KEY(key, family) \ ((key[PF_SK_WIRE]->af != key[PF_SK_STACK]->af) && \ (key[PF_SK_WIRE]->af != (family)))