Hi,

in order to reduce globals so that we can run more parts of pf in
parallel, this diff removes the pfr_sin, pfr_sin6 and pfr_mask
globals.  Those are instead allocated on the stack.

ok?

Patrick

diff --git a/sys/net/pf_table.c b/sys/net/pf_table.c
index 708bd68cbcd..2cdff265ff5 100644
--- a/sys/net/pf_table.c
+++ b/sys/net/pf_table.c
@@ -140,11 +140,6 @@ struct pfr_walktree {
 struct pool             pfr_ktable_pl;
 struct pool             pfr_kentry_pl[PFRKE_MAX];
 struct pool             pfr_kcounters_pl;
-struct sockaddr_in      pfr_sin;
-#ifdef INET6
-struct sockaddr_in6     pfr_sin6;
-#endif /* INET6 */
-union sockaddr_union    pfr_mask;
 struct pf_addr          pfr_ffaddr;
 
 int                     pfr_gcd(int, int);
@@ -235,13 +230,6 @@ pfr_initialize(void)
        pool_init(&pfr_kcounters_pl, sizeof(struct pfr_kcounters),
            0, IPL_SOFTNET, 0, "pfrkcounters", NULL);
 
-       pfr_sin.sin_len = sizeof(pfr_sin);
-       pfr_sin.sin_family = AF_INET;
-#ifdef INET6
-       pfr_sin6.sin6_len = sizeof(pfr_sin6);
-       pfr_sin6.sin6_family = AF_INET6;
-#endif /* INET6 */
-
        memset(&pfr_ffaddr, 0xff, sizeof(pfr_ffaddr));
 }
 
@@ -1168,6 +1156,7 @@ pfr_walktree(struct radix_node *rn, void *arg, u_int id)
 {
        struct pfr_kentry       *ke = (struct pfr_kentry *)rn;
        struct pfr_walktree     *w = arg;
+       union sockaddr_union     mask;
        int                      flags = w->pfrw_flags;
 
        switch (w->pfrw_op) {
@@ -1229,21 +1218,21 @@ pfr_walktree(struct radix_node *rn, void *arg, u_int id)
                case AF_INET:
                        if (w->pfrw_dyn->pfid_acnt4++ > 0)
                                break;
-                       pfr_prepare_network(&pfr_mask, AF_INET, ke->pfrke_net);
+                       pfr_prepare_network(&mask, AF_INET, ke->pfrke_net);
                        w->pfrw_dyn->pfid_addr4 = *SUNION2PF(
                            &ke->pfrke_sa, AF_INET);
                        w->pfrw_dyn->pfid_mask4 = *SUNION2PF(
-                           &pfr_mask, AF_INET);
+                           &mask, AF_INET);
                        break;
 #ifdef INET6
                case AF_INET6:
                        if (w->pfrw_dyn->pfid_acnt6++ > 0)
                                break;
-                       pfr_prepare_network(&pfr_mask, AF_INET6, ke->pfrke_net);
+                       pfr_prepare_network(&mask, AF_INET6, ke->pfrke_net);
                        w->pfrw_dyn->pfid_addr6 = *SUNION2PF(
                            &ke->pfrke_sa, AF_INET6);
                        w->pfrw_dyn->pfid_mask6 = *SUNION2PF(
-                           &pfr_mask, AF_INET6);
+                           &mask, AF_INET6);
                        break;
 #endif /* INET6 */
                default:
@@ -2091,6 +2080,10 @@ int
 pfr_match_addr(struct pfr_ktable *kt, struct pf_addr *a, sa_family_t af)
 {
        struct pfr_kentry       *ke = NULL;
+       struct sockaddr_in       tmp4;
+#ifdef INET6
+       struct sockaddr_in6      tmp6;
+#endif /* INET6 */
        int                      match;
 
        if (!(kt->pfrkt_flags & PFR_TFLAG_ACTIVE) && kt->pfrkt_root != NULL)
@@ -2100,13 +2093,19 @@ pfr_match_addr(struct pfr_ktable *kt, struct pf_addr 
*a, sa_family_t af)
 
        switch (af) {
        case AF_INET:
-               pfr_sin.sin_addr.s_addr = a->addr32[0];
-               ke = (struct pfr_kentry *)rn_match(&pfr_sin, kt->pfrkt_ip4);
+               bzero(&tmp4, sizeof(tmp4));
+               tmp4.sin_len = sizeof(tmp4);
+               tmp4.sin_family = AF_INET;
+               tmp4.sin_addr.s_addr = a->addr32[0];
+               ke = (struct pfr_kentry *)rn_match(&tmp4, kt->pfrkt_ip4);
                break;
 #ifdef INET6
        case AF_INET6:
-               bcopy(a, &pfr_sin6.sin6_addr, sizeof(pfr_sin6.sin6_addr));
-               ke = (struct pfr_kentry *)rn_match(&pfr_sin6, kt->pfrkt_ip6);
+               bzero(&tmp6, sizeof(tmp6));
+               tmp6.sin6_len = sizeof(tmp6);
+               tmp6.sin6_family = AF_INET6;
+               bcopy(a, &tmp6.sin6_addr, sizeof(tmp6.sin6_addr));
+               ke = (struct pfr_kentry *)rn_match(&tmp6, kt->pfrkt_ip6);
                break;
 #endif /* INET6 */
        default:
@@ -2125,6 +2124,10 @@ pfr_update_stats(struct pfr_ktable *kt, struct pf_addr 
*a, struct pf_pdesc *pd,
     int op, int notrule)
 {
        struct pfr_kentry       *ke = NULL;
+       struct sockaddr_in       tmp4;
+#ifdef INET6
+       struct sockaddr_in6      tmp6;
+#endif /* INET6 */
        sa_family_t              af = pd->af;
        u_int64_t                len = pd->tot_len;
        int                      dir_idx = (pd->dir == PF_OUT);
@@ -2137,13 +2140,19 @@ pfr_update_stats(struct pfr_ktable *kt, struct pf_addr 
*a, struct pf_pdesc *pd,
 
        switch (af) {
        case AF_INET:
-               pfr_sin.sin_addr.s_addr = a->addr32[0];
-               ke = (struct pfr_kentry *)rn_match(&pfr_sin, kt->pfrkt_ip4);
+               bzero(&tmp4, sizeof(tmp4));
+               tmp4.sin_len = sizeof(tmp4);
+               tmp4.sin_family = AF_INET;
+               tmp4.sin_addr.s_addr = a->addr32[0];
+               ke = (struct pfr_kentry *)rn_match(&tmp4, kt->pfrkt_ip4);
                break;
 #ifdef INET6
        case AF_INET6:
-               bcopy(a, &pfr_sin6.sin6_addr, sizeof(pfr_sin6.sin6_addr));
-               ke = (struct pfr_kentry *)rn_match(&pfr_sin6, kt->pfrkt_ip6);
+               bzero(&tmp6, sizeof(tmp6));
+               tmp6.sin6_len = sizeof(tmp6);
+               tmp6.sin6_family = AF_INET6;
+               bcopy(a, &tmp6.sin6_addr, sizeof(tmp6.sin6_addr));
+               ke = (struct pfr_kentry *)rn_match(&tmp6, kt->pfrkt_ip6);
                break;
 #endif /* INET6 */
        default:
@@ -2248,15 +2257,25 @@ pfr_pool_get(struct pf_pool *rpool, struct pf_addr 
**raddr,
        struct pfr_kentry       *ke, *ke2;
        struct pf_addr          *addr, *counter;
        union sockaddr_union     mask;
+       struct sockaddr_in       tmp4;
+#ifdef INET6
+       struct sockaddr_in6      tmp6;
+#endif
        int                      startidx, idx = -1, loop = 0, use_counter = 0;
 
        switch (af) {
        case AF_INET:
-               addr = (struct pf_addr *)&pfr_sin.sin_addr;
+               bzero(&tmp4, sizeof(tmp4));
+               tmp4.sin_len = sizeof(tmp4);
+               tmp4.sin_family = AF_INET;
+               addr = (struct pf_addr *)&tmp4.sin_addr;
                break;
 #ifdef INET6
        case AF_INET6:
-               addr = (struct pf_addr *)&pfr_sin6.sin6_addr;
+               bzero(&tmp6, sizeof(tmp6));
+               tmp6.sin6_len = sizeof(tmp6);
+               tmp6.sin6_family = AF_INET6;
+               addr = (struct pf_addr *)&tmp6.sin6_addr;
                break;
 #endif /* INET6 */
        default:
@@ -2307,9 +2326,9 @@ pfr_pool_get(struct pf_pool *rpool, struct pf_addr 
**raddr,
                        rpool->curweight = kt->pfrkt_maxweight;
        }
 
-       pfr_prepare_network(&pfr_mask, af, ke->pfrke_net);
+       pfr_prepare_network(&mask, af, ke->pfrke_net);
        *raddr = SUNION2PF(&ke->pfrke_sa, af);
-       *rmask = SUNION2PF(&pfr_mask, af);
+       *rmask = SUNION2PF(&mask, af);
 
        if (use_counter && !PF_AZERO(counter, af)) {
                /* is supplied address within block? */
@@ -2355,12 +2374,12 @@ pfr_pool_get(struct pf_pool *rpool, struct pf_addr 
**raddr,
                /* we don't want to use a nested block */
                switch (af) {
                case AF_INET:
-                       ke2 = (struct pfr_kentry *)rn_match(&pfr_sin,
+                       ke2 = (struct pfr_kentry *)rn_match(&tmp4,
                            kt->pfrkt_ip4);
                        break;
 #ifdef INET6
                case AF_INET6:
-                       ke2 = (struct pfr_kentry *)rn_match(&pfr_sin6,
+                       ke2 = (struct pfr_kentry *)rn_match(&tmp6,
                            kt->pfrkt_ip6);
                        break;
 #endif /* INET6 */

Reply via email to