Convert to critical sections.
authorJoerg Sonnenberger <joerg@dragonflybsd.org>
Wed, 15 Jun 2005 16:32:58 +0000 (16:32 +0000)
committerJoerg Sonnenberger <joerg@dragonflybsd.org>
Wed, 15 Jun 2005 16:32:58 +0000 (16:32 +0000)
sys/net/pf/if_pflog.c
sys/net/pf/if_pfsync.c
sys/net/pf/pf.c
sys/net/pf/pf_if.c
sys/net/pf/pf_ioctl.c
sys/net/pf/pf_table.c
sys/net/pf/pfvar.h

index 7ece0b0..3784570 100644 (file)
@@ -1,6 +1,6 @@
 /*     $FreeBSD: src/sys/contrib/pf/net/if_pflog.c,v 1.9 2004/06/22 20:13:24 brooks Exp $      */
 /*     $OpenBSD: if_pflog.c,v 1.11 2003/12/31 11:18:25 cedric Exp $    */
-/*     $DragonFly: src/sys/net/pf/if_pflog.c,v 1.2 2004/11/14 17:27:31 joerg Exp $ */
+/*     $DragonFly: src/sys/net/pf/if_pflog.c,v 1.3 2005/06/15 16:32:58 joerg Exp $ */
 
 /*
  * The authors of this code are John Ioannidis (ji@tla.org),
@@ -50,6 +50,7 @@
 #include <sys/malloc.h>
 #include <sys/module.h>
 #include <sys/sockio.h>
+#include <sys/thread2.h>
 #include <vm/vm_zone.h>
 
 #include <net/if.h>
@@ -146,12 +147,10 @@ pflog_clone_create(struct if_clone *ifc, int unit)
 void
 pflogstart(struct ifnet *ifp)
 {
-       int s;
-
-       s = splimp();
+       crit_enter();
        IF_DROP(&ifp->if_snd);
        IF_DRAIN(&ifp->if_snd);
-       splx(s);
+       crit_exit();
 }
 
 int
index f32637f..05798cc 100644 (file)
@@ -1,6 +1,6 @@
 /*     $FreeBSD: src/sys/contrib/pf/net/if_pfsync.c,v 1.11 2004/08/14 15:32:40 dwmalone Exp $  */
 /*     $OpenBSD: if_pfsync.c,v 1.26 2004/03/28 18:14:20 mcbride Exp $  */
-/*     $DragonFly: src/sys/net/pf/if_pfsync.c,v 1.1 2004/09/19 22:32:47 joerg Exp $ */
+/*     $DragonFly: src/sys/net/pf/if_pfsync.c,v 1.2 2005/06/15 16:32:58 joerg Exp $ */
 
 /*
  * Copyright (c) 2004 The DragonFly Project.  All rights reserved.
@@ -43,6 +43,7 @@
 #include <sys/malloc.h>
 #include <sys/module.h>
 #include <sys/sockio.h>
+#include <sys/thread2.h>
 #include <vm/vm_zone.h>
 
 #include <machine/inttypes.h>
@@ -170,12 +171,10 @@ pfsync_clone_create(struct if_clone *ifc, int unit)
 void
 pfsyncstart(struct ifnet *ifp)
 {
-       int s;
-
-       s = splimp();
+       crit_enter();
        IF_DROP(&ifp->if_snd);
        IF_DRAIN(&ifp->if_snd);
-       splx(s);
+       crit_exit();
 }
 
 int
@@ -265,7 +264,7 @@ pfsync_input(struct mbuf *m, ...)
        struct pfsync_state_bus *bus;
        struct in_addr src;
        struct mbuf *mp;
-       int iplen, action, error, i, s, count, offp;
+       int iplen, action, error, i, count, offp;
 
        pfsyncstats.pfsyncs_ipackets++;
 
@@ -331,7 +330,7 @@ pfsync_input(struct mbuf *m, ...)
                cp = (struct pfsync_state_clr *)(mp->m_data + offp);
                creatorid = cp->creatorid;
 
-               s = splsoftnet();
+               crit_enter();
                if (cp->ifname[0] == '\0') {
                        RB_FOREACH(st, pf_state_tree_id, &tree_id) {
                                if (st->creatorid == creatorid)
@@ -343,7 +342,7 @@ pfsync_input(struct mbuf *m, ...)
                                if (pf_status.debug >= PF_DEBUG_MISC)
                                        printf("pfsync_input: PFSYNC_ACT_CLR "
                                            "bad interface: %s\n", cp->ifname);
-                               splx(s);
+                               crit_exit();
                                goto done;
                        }
                        RB_FOREACH(st, pf_state_tree_lan_ext,
@@ -353,7 +352,7 @@ pfsync_input(struct mbuf *m, ...)
                        }
                }
                pf_purge_expired_states();
-               splx(s);
+               crit_exit();
 
                break;
        }
@@ -364,7 +363,7 @@ pfsync_input(struct mbuf *m, ...)
                        return;
                }
 
-               s = splsoftnet();
+               crit_enter();
                for (i = 0, sp = (struct pfsync_state *)(mp->m_data + offp);
                    i < count; i++, sp++) {
                        /* check for invalid values */
@@ -382,13 +381,13 @@ pfsync_input(struct mbuf *m, ...)
 
                        if ((error = pfsync_insert_net_state(sp))) {
                                if (error == ENOMEM) {
-                                       splx(s);
+                                       crit_exit();
                                        goto done;
                                }
                                continue;
                        }
                }
-               splx(s);
+               crit_exit();
                break;
        case PFSYNC_ACT_UPD:
                if ((mp = m_pulldown(m, iplen + sizeof(*ph),
@@ -397,7 +396,7 @@ pfsync_input(struct mbuf *m, ...)
                        return;
                }
 
-               s = splsoftnet();
+               crit_enter();
                for (i = 0, sp = (struct pfsync_state *)(mp->m_data + offp);
                    i < count; i++, sp++) {
                        /* check for invalid values */
@@ -427,7 +426,7 @@ pfsync_input(struct mbuf *m, ...)
                        st->timeout = sp->timeout;
 
                }
-               splx(s);
+               crit_exit();
                break;
        /*
         * It's not strictly necessary for us to support the "uncompressed"
@@ -440,7 +439,7 @@ pfsync_input(struct mbuf *m, ...)
                        return;
                }
 
-               s = splsoftnet();
+               crit_enter();
                for (i = 0, sp = (struct pfsync_state *)(mp->m_data + offp);
                    i < count; i++, sp++) {
                        bcopy(sp->id, &key.id, sizeof(key.id));
@@ -460,7 +459,7 @@ pfsync_input(struct mbuf *m, ...)
                        st->sync_flags |= PFSTATE_FROMSYNC;
                }
                pf_purge_expired_states();
-               splx(s);
+               crit_exit();
                break;
        case PFSYNC_ACT_UPD_C: {
                int update_requested = 0;
@@ -471,7 +470,7 @@ pfsync_input(struct mbuf *m, ...)
                        return;
                }
 
-               s = splsoftnet();
+               crit_enter();
                for (i = 0, up = (struct pfsync_state_upd *)(mp->m_data + offp);
                    i < count; i++, up++) {
                        /* check for invalid values */
@@ -504,7 +503,7 @@ pfsync_input(struct mbuf *m, ...)
                }
                if (update_requested)
                        pfsync_sendout(sc);
-               splx(s);
+               crit_exit();
                break;
        }
        case PFSYNC_ACT_DEL_C:
@@ -514,7 +513,7 @@ pfsync_input(struct mbuf *m, ...)
                        return;
                }
 
-               s = splsoftnet();
+               crit_enter();
                for (i = 0, dp = (struct pfsync_state_del *)(mp->m_data + offp);
                    i < count; i++, dp++) {
                        bcopy(dp->id, &key.id, sizeof(key.id));
@@ -534,7 +533,7 @@ pfsync_input(struct mbuf *m, ...)
                        st->sync_flags |= PFSTATE_FROMSYNC;
                }
                pf_purge_expired_states();
-               splx(s);
+               crit_exit();
                break;
        case PFSYNC_ACT_INS_F:
        case PFSYNC_ACT_DEL_F:
@@ -547,7 +546,7 @@ pfsync_input(struct mbuf *m, ...)
                        return;
                }
 
-               s = splsoftnet();
+               crit_enter();
                /* XXX send existing. pfsync_pack_state should handle this. */
                if (sc->sc_mbuf != NULL)
                        pfsync_sendout(sc);
@@ -577,7 +576,7 @@ pfsync_input(struct mbuf *m, ...)
                }
                if (sc->sc_mbuf != NULL)
                        pfsync_sendout(sc);
-               splx(s);
+               crit_exit();
                break;
        case PFSYNC_ACT_BUS:
                /* If we're not waiting for a bulk update, who cares. */
@@ -643,7 +642,7 @@ pfsyncioctl(struct ifnet *ifp, u_long cmd, caddr_t data, struct ucred *cr)
        struct ip_moptions *imo = &sc->sc_imo;
        struct pfsyncreq pfsyncr;
        struct ifnet    *sifp;
-       int s, error;
+       int error;
 
        switch (cmd) {
        case SIOCSIFADDR:
@@ -660,11 +659,11 @@ pfsyncioctl(struct ifnet *ifp, u_long cmd, caddr_t data, struct ucred *cr)
                        return (EINVAL);
                if (ifr->ifr_mtu > MCLBYTES)
                        ifr->ifr_mtu = MCLBYTES;
-               s = splnet();
+               crit_enter();
                if (ifr->ifr_mtu < ifp->if_mtu)
                        pfsync_sendout(sc);
                pfsync_setmtu(sc, ifr->ifr_mtu);
-               splx(s);
+               crit_exit();
                break;
        case SIOCGETPFSYNC:
                bzero(&pfsyncr, sizeof(pfsyncr));
@@ -689,11 +688,11 @@ pfsyncioctl(struct ifnet *ifp, u_long cmd, caddr_t data, struct ucred *cr)
                        sc->sc_sync_ifp = NULL;
                        if (sc->sc_mbuf_net != NULL) {
                                /* Don't keep stale pfsync packets around. */
-                               s = splnet();
+                               crit_enter();
                                m_freem(sc->sc_mbuf_net);
                                sc->sc_mbuf_net = NULL;
                                sc->sc_statep_net.s = NULL;
-                               splx(s);
+                               crit_exit();
                        }
                        break;
                }
@@ -702,7 +701,7 @@ pfsyncioctl(struct ifnet *ifp, u_long cmd, caddr_t data, struct ucred *cr)
                else if (sifp == sc->sc_sync_ifp)
                        break;
 
-               s = splnet();
+               crit_enter();
                if (sifp->if_mtu < sc->sc_if.if_mtu ||
                    (sc->sc_sync_ifp != NULL &&
                    sifp->if_mtu < sc->sc_sync_ifp->if_mtu) ||
@@ -724,7 +723,7 @@ pfsyncioctl(struct ifnet *ifp, u_long cmd, caddr_t data, struct ucred *cr)
                        /* XXX do we only use one group? Also see above */
                        if ((imo->imo_membership[0] =
                            in_addmulti(&addr, sc->sc_sync_ifp)) == NULL) {
-                               splx(s);
+                               crit_exit();
                                return (ENOBUFS);
                        }
                        imo->imo_num_memberships++;
@@ -742,7 +741,7 @@ pfsyncioctl(struct ifnet *ifp, u_long cmd, caddr_t data, struct ucred *cr)
                        pfsync_request_update(NULL, NULL);
                        pfsync_sendout(sc);
                }
-               splx(s);
+               crit_exit();
 
                break;
 
@@ -847,7 +846,7 @@ pfsync_pack_state(u_int8_t action, struct pf_state *st, int compress)
        struct pfsync_state_del *dp = NULL;
        struct pf_rule *r;
        u_long secs;
-       int s, ret = 0;
+       int ret = 0;
        u_int8_t i = 255, newaction = 0;
 
        /*
@@ -867,11 +866,11 @@ pfsync_pack_state(u_int8_t action, struct pf_state *st, int compress)
        if (action >= PFSYNC_ACT_MAX)
                return (EINVAL);
 
-       s = splnet();
+       crit_enter();
        if (sc->sc_mbuf == NULL) {
                if ((sc->sc_mbuf = pfsync_get_mbuf(sc, action,
                    (void *)&sc->sc_statep.s)) == NULL) {
-                       splx(s);
+                       crit_exit();
                        return (ENOMEM);
                }
                h = mtod(sc->sc_mbuf, struct pfsync_header *);
@@ -881,7 +880,7 @@ pfsync_pack_state(u_int8_t action, struct pf_state *st, int compress)
                        pfsync_sendout(sc);
                        if ((sc->sc_mbuf = pfsync_get_mbuf(sc, action,
                            (void *)&sc->sc_statep.s)) == NULL) {
-                               splx(s);
+                               crit_exit();
                                return (ENOMEM);
                        }
                        h = mtod(sc->sc_mbuf, struct pfsync_header *);
@@ -983,7 +982,7 @@ pfsync_pack_state(u_int8_t action, struct pf_state *st, int compress)
                if (sc->sc_mbuf_net == NULL) {
                        if ((sc->sc_mbuf_net = pfsync_get_mbuf(sc, newaction,
                            (void *)&sc->sc_statep_net.s)) == NULL) {
-                               splx(s);
+                               crit_exit();
                                return (ENOMEM);
                        }
                }
@@ -1027,7 +1026,7 @@ pfsync_pack_state(u_int8_t action, struct pf_state *st, int compress)
            (sc->sc_maxupdates && (sp->updates >= sc->sc_maxupdates)))
                ret = pfsync_sendout(sc);
 
-       splx(s);
+       crit_exit();
        return (ret);
 }
 
@@ -1039,12 +1038,11 @@ pfsync_request_update(struct pfsync_state_upd *up, struct in_addr *src)
        struct pfsync_header *h;
        struct pfsync_softc *sc = ifp->if_softc;
        struct pfsync_state_upd_req *rup;
-       int s = 0, ret = 0;
+       int ret = 0;
 
        if (sc->sc_mbuf == NULL) {
                if ((sc->sc_mbuf = pfsync_get_mbuf(sc, PFSYNC_ACT_UREQ,
                    (void *)&sc->sc_statep.s)) == NULL) {
-                       splx(s);
                        return (ENOMEM);
                }
                h = mtod(sc->sc_mbuf, struct pfsync_header *);
@@ -1054,7 +1052,6 @@ pfsync_request_update(struct pfsync_state_upd *up, struct in_addr *src)
                        pfsync_sendout(sc);
                        if ((sc->sc_mbuf = pfsync_get_mbuf(sc, PFSYNC_ACT_UREQ,
                            (void *)&sc->sc_statep.s)) == NULL) {
-                               splx(s);
                                return (ENOMEM);
                        }
                        h = mtod(sc->sc_mbuf, struct pfsync_header *);
@@ -1084,14 +1081,14 @@ pfsync_clear_states(u_int32_t creatorid, char *ifname)
        struct ifnet *ifp = &(LIST_FIRST(&pfsync_list))->sc_if;
        struct pfsync_softc *sc = ifp->if_softc;
        struct pfsync_state_clr *cp;
-       int s, ret;
+       int ret;
 
-       s = splnet();
+       crit_enter();
        if (sc->sc_mbuf != NULL)
                pfsync_sendout(sc);
        if ((sc->sc_mbuf = pfsync_get_mbuf(sc, PFSYNC_ACT_CLR,
            (void *)&sc->sc_statep.c)) == NULL) {
-               splx(s);
+               crit_exit();
                return (ENOMEM);
        }
        sc->sc_mbuf->m_pkthdr.len = sc->sc_mbuf->m_len += sizeof(*cp);
@@ -1101,7 +1098,7 @@ pfsync_clear_states(u_int32_t creatorid, char *ifname)
                strlcpy(cp->ifname, ifname, IFNAMSIZ);
 
        ret = (pfsync_sendout(sc));
-       splx(s);
+       crit_exit();
        return (ret);
 }
 
@@ -1109,11 +1106,10 @@ void
 pfsync_timeout(void *v)
 {
        struct pfsync_softc *sc = v;
-       int s;
 
-       s = splnet();
+       crit_enter();
        pfsync_sendout(sc);
-       splx(s);
+       crit_exit();
 }
 
 void
@@ -1140,10 +1136,10 @@ void
 pfsync_bulk_update(void *v)
 {
        struct pfsync_softc *sc = v;
-       int s, i = 0;
+       int i = 0;
        struct pf_state *state;
 
-       s = splnet();
+       crit_enter();
        if (sc->sc_mbuf != NULL)
                pfsync_sendout(sc);
 
@@ -1177,7 +1173,7 @@ pfsync_bulk_update(void *v)
        }
        if (sc->sc_mbuf != NULL)
                pfsync_sendout(sc);
-       splx(s);
+       crit_exit();
 }
 
 void
index a7a8f3f..1b7ee7c 100644 (file)
@@ -1,7 +1,7 @@
 /*     $FreeBSD: src/sys/contrib/pf/net/pf.c,v 1.19 2004/09/11 11:18:25 mlaier Exp $   */
 /*     $OpenBSD: pf.c,v 1.433.2.2 2004/07/17 03:22:34 brad Exp $ */
 /* add $OpenBSD: pf.c,v 1.448 2004/05/11 07:34:11 dhartmei Exp $ */
-/*     $DragonFly: src/sys/net/pf/pf.c,v 1.4 2005/02/11 22:25:57 joerg Exp $ */
+/*     $DragonFly: src/sys/net/pf/pf.c,v 1.5 2005/06/15 16:32:58 joerg Exp $ */
 
 /*
  * Copyright (c) 2004 The DragonFly Project.  All rights reserved.
@@ -696,13 +696,12 @@ void
 pf_purge_timeout(void *arg)
 {
        struct callout  *to = arg;
-       int              s;
 
-       s = splsoftnet();
+       crit_enter();
        pf_purge_expired_states();
        pf_purge_expired_fragments();
        pf_purge_expired_src_nodes();
-       splx(s);
+       crit_exit();
 
        callout_reset(to, pf_default_rule.timeout[PFTM_INTERVAL] * hz,
            pf_purge_timeout, to);
index fc154a7..c282609 100644 (file)
@@ -1,7 +1,7 @@
 /*     $FreeBSD: src/sys/contrib/pf/net/pf_if.c,v 1.6 2004/09/14 15:20:24 mlaier Exp $ */
 /*     $OpenBSD: pf_if.c,v 1.11 2004/03/15 11:38:23 cedric Exp $ */
 /* add $OpenBSD: pf_if.c,v 1.19 2004/08/11 12:06:44 henning Exp $ */
-/*     $DragonFly: src/sys/net/pf/pf_if.c,v 1.3 2004/09/28 16:22:41 joerg Exp $ */
+/*     $DragonFly: src/sys/net/pf/pf_if.c,v 1.4 2005/06/15 16:32:58 joerg Exp $ */
 
 /*
  * Copyright (c) 2004 The DragonFly Project.  All rights reserved.
@@ -47,6 +47,7 @@
 #include <sys/socket.h>
 #include <sys/socketvar.h>
 #include <sys/kernel.h>
+#include <sys/thread2.h>
 #include <sys/time.h>
 #include <vm/vm_zone.h>
 
@@ -228,11 +229,10 @@ void
 pfi_attach_ifnet(struct ifnet *ifp)
 {
        struct pfi_kif  *p, *q, key;
-       int              s;
        int              realname;
 
        pfi_initialize();
-       s = splsoftnet();
+       crit_enter();
        pfi_update++;
        if (ifp->if_index >= pfi_indexlim) {
                /*
@@ -318,23 +318,22 @@ pfi_attach_ifnet(struct ifnet *ifp)
            pfi_kifaddr_update_event, p, EVENTHANDLER_PRI_ANY);
        pfi_index2kif[ifp->if_index] = p;
        pfi_dohooks(p);
-       splx(s);
+       crit_exit();
 }
 
 void
 pfi_detach_ifnet(struct ifnet *ifp)
 {
        struct pfi_kif  *p, *q, key;
-       int              s;
 
        strlcpy(key.pfik_name, ifp->if_xname, sizeof(key.pfik_name));
 
-       s = splsoftnet();
+       crit_enter();
        pfi_update++;
        p = RB_FIND(pfi_ifhead, &pfi_ifs, &key);
        if (p == NULL) {
                printf("pfi_detach_ifnet: cannot find %s", ifp->if_xname);
-               splx(s);
+               crit_exit();
                return;
        }
        EVENTHANDLER_DEREGISTER(ifaddr_event, p->pfik_ah_cookie);
@@ -344,16 +343,15 @@ pfi_detach_ifnet(struct ifnet *ifp)
        pfi_index2kif[ifp->if_index] = NULL;
        pfi_dohooks(p);
        pfi_maybe_destroy(p);
-       splx(s);
+       crit_exit();
 }
 
 struct pfi_kif *
 pfi_lookup_create(const char *name)
 {
        struct pfi_kif  *p, *q, key;
-       int              s;
 
-       s = splsoftnet();
+       crit_enter();
        p = pfi_lookup_if(name);
        if (p == NULL) {
                pfi_copy_group(key.pfik_name, name, sizeof(key.pfik_name));
@@ -367,7 +365,7 @@ pfi_lookup_create(const char *name)
                            PFI_IFLAG_PLACEHOLDER);
                }
        }
-       splx(s);
+       crit_exit();
        return (p);
 }
 
@@ -421,7 +419,7 @@ pfi_dynaddr_setup(struct pf_addr_wrap *aw, sa_family_t af)
        struct pfi_dynaddr      *dyn;
        char                     tblname[PF_TABLE_NAME_SIZE];
        struct pf_ruleset       *ruleset = NULL;
-       int                      s, rv = 0;
+       int                      rv = 0;
 
        if (aw->type != PF_ADDR_DYNIFTL)
                return (0);
@@ -430,7 +428,7 @@ pfi_dynaddr_setup(struct pf_addr_wrap *aw, sa_family_t af)
                return (1);
        bzero(dyn, sizeof(*dyn));
 
-       s = splsoftnet();
+       crit_enter();
        dyn->pfid_kif = pfi_attach_rule(aw->v.ifname);
        if (dyn->pfid_kif == NULL)
                senderr(1);
@@ -469,7 +467,7 @@ pfi_dynaddr_setup(struct pf_addr_wrap *aw, sa_family_t af)
 
        aw->p.dyn = dyn;
        pfi_dynaddr_update(aw->p.dyn);
-       splx(s);
+       crit_exit();
        return (0);
 
 _bad:
@@ -480,7 +478,7 @@ _bad:
        if (dyn->pfid_kif != NULL)
                pfi_detach_rule(dyn->pfid_kif);
        pool_put(&pfi_addr_pl, dyn);
-       splx(s);
+       crit_exit();
        return (rv);
 }
 
@@ -649,13 +647,11 @@ pfi_address_add(struct sockaddr *sa, int af, int net)
 void
 pfi_dynaddr_remove(struct pf_addr_wrap *aw)
 {
-       int     s;
-
        if (aw->type != PF_ADDR_DYNIFTL || aw->p.dyn == NULL ||
            aw->p.dyn->pfid_kif == NULL || aw->p.dyn->pfid_kt == NULL)
                return;
 
-       s = splsoftnet();
+       crit_enter();
        hook_disestablish(aw->p.dyn->pfid_kif->pfik_ah_head,
            aw->p.dyn->pfid_hook_cookie);
        pfi_detach_rule(aw->p.dyn->pfid_kif);
@@ -664,7 +660,7 @@ pfi_dynaddr_remove(struct pf_addr_wrap *aw)
        aw->p.dyn->pfid_kt = NULL;
        pool_put(&pfi_addr_pl, aw->p.dyn);
        aw->p.dyn = NULL;
-       splx(s);
+       crit_exit();
 }
 
 void
@@ -679,12 +675,10 @@ pfi_dynaddr_copyout(struct pf_addr_wrap *aw)
 void
 pfi_kifaddr_update(void *v)
 {
-       int              s;
-
-       s = splsoftnet();
+       crit_enter();
        pfi_update++;
        pfi_dohooks(v);
-       splx(s);
+       crit_exit();
 }
 
 int
@@ -730,7 +724,7 @@ pfi_if_create(const char *name, struct pfi_kif *q, int flags)
 int
 pfi_maybe_destroy(struct pfi_kif *p)
 {
-       int              i, j, k, s;
+       int              i, j, k;
        struct pfi_kif  *q = p->pfik_parent;
 
        if ((p->pfik_flags & (PFI_IFLAG_ATTACHED | PFI_IFLAG_GROUP)) ||
@@ -738,7 +732,7 @@ pfi_maybe_destroy(struct pfi_kif *p)
                if (!(p->pfik_flags & PFI_IFLAG_PLACEHOLDER))
                        return (0);
 
-       s = splsoftnet();
+       crit_enter();
        if (q != NULL) {
                for (i = 0; i < 2; i++)
                        for (j = 0; j < 2; j++)
@@ -760,11 +754,12 @@ pfi_maybe_destroy(struct pfi_kif *p)
                pfi_dummy->pfik_addcnt++;
                TAILQ_INSERT_TAIL(&pfi_dummy->pfik_grouphead, p,
                    pfik_instances);
+               crit_exit();
                return (0);
        }
        pfi_ifcnt--;
        RB_REMOVE(pfi_ifhead, &pfi_ifs, p);
-       splx(s);
+       crit_exit();
 
        free(p->pfik_ah_head, PFI_MTYPE);
        free(p, PFI_MTYPE);
@@ -817,13 +812,13 @@ void
 pfi_fill_oldstatus(struct pf_status *pfs)
 {
        struct pfi_kif  *p, key;
-       int              i, j, k, s;
+       int              i, j, k;
 
        strlcpy(key.pfik_name, pfs->ifname, sizeof(key.pfik_name));
-       s = splsoftnet();
+       crit_enter();
        p = RB_FIND(pfi_ifhead, &pfi_ifs, &key);
        if (p == NULL) {
-               splx(s);
+               crit_exit();
                return;
        }
        bzero(pfs->pcounters, sizeof(pfs->pcounters));
@@ -836,17 +831,17 @@ pfi_fill_oldstatus(struct pf_status *pfs)
                                pfs->bcounters[i][j] +=
                                        p->pfik_bytes[i][j][k];
                        }
-       splx(s);
+       crit_exit();
 }
 
 int
 pfi_clr_istats(const char *name, int *nzero, int flags)
 {
        struct pfi_kif  *p;
-       int              n = 0, s;
+       int              n = 0;
        long             tzero = time_second;
 
-       s = splsoftnet();
+       crit_enter();
        ACCEPT_FLAGS(PFI_FLAG_GROUP|PFI_FLAG_INSTANCE);
        RB_FOREACH(p, pfi_ifhead, &pfi_ifs) {
                if (pfi_skip_if(name, p, flags))
@@ -856,7 +851,7 @@ pfi_clr_istats(const char *name, int *nzero, int flags)
                p->pfik_tzero = tzero;
                n++;
        }
-       splx(s);
+       crit_exit();
        if (nzero != NULL)
                *nzero = n;
        return (0);
@@ -866,10 +861,10 @@ int
 pfi_get_ifaces(const char *name, struct pfi_if *buf, int *size, int flags)
 {
        struct pfi_kif  *p;
-       int              s, n = 0;
+       int              n = 0;
 
        ACCEPT_FLAGS(PFI_FLAG_GROUP|PFI_FLAG_INSTANCE);
-       s = splsoftnet();
+       crit_enter();
        RB_FOREACH(p, pfi_ifhead, &pfi_ifs) {
                if (pfi_skip_if(name, p, flags))
                        continue;
@@ -877,12 +872,12 @@ pfi_get_ifaces(const char *name, struct pfi_if *buf, int *size, int flags)
                        if (!p->pfik_tzero)
                                p->pfik_tzero = boottime.tv_sec;
                        if (copyout(p, buf++, sizeof(*buf))) {
-                               splx(s);
+                               crit_exit();
                                return (EFAULT);
                        }
                }
        }
-       splx(s);
+       crit_exit();
        *size = n;
        return (0);
 }
index 804a061..341b0fb 100644 (file)
@@ -1,6 +1,6 @@
 /*     $FreeBSD: src/sys/contrib/pf/net/pf_ioctl.c,v 1.12 2004/08/12 14:15:42 mlaier Exp $     */
 /*     $OpenBSD: pf_ioctl.c,v 1.112.2.2 2004/07/24 18:28:12 brad Exp $ */
-/*     $DragonFly: src/sys/net/pf/pf_ioctl.c,v 1.4 2005/02/11 22:25:57 joerg Exp $ */
+/*     $DragonFly: src/sys/net/pf/pf_ioctl.c,v 1.5 2005/06/15 16:32:58 joerg Exp $ */
 
 /*
  * Copyright (c) 2004 The DragonFly Project.  All rights reserved.
@@ -51,6 +51,7 @@
 #include <sys/socket.h>
 #include <sys/socketvar.h>
 #include <sys/kernel.h>
+#include <sys/thread2.h>
 #include <sys/time.h>
 #include <sys/malloc.h>
 #include <sys/module.h>
@@ -731,13 +732,13 @@ pf_commit_altq(u_int32_t ticket)
 {
        struct pf_altqqueue     *old_altqs;
        struct pf_altq          *altq;
-       int                      s, err, error = 0;
+       int                      err, error = 0;
 
        if (!altqs_inactive_open || ticket != ticket_altqs_inactive)
                return (EBUSY);
 
        /* swap altqs, keep the old. */
-       s = splsoftnet();
+       crit_enter();
        old_altqs = pf_altqs_active;
        pf_altqs_active = pf_altqs_inactive;
        pf_altqs_inactive = old_altqs;
@@ -749,7 +750,7 @@ pf_commit_altq(u_int32_t ticket)
                        /* attach the discipline */
                        error = altq_pfattach(altq);
                        if (error) {
-                               splx(s);
+                               crit_exit();
                                return (error);
                        }
                }
@@ -770,7 +771,7 @@ pf_commit_altq(u_int32_t ticket)
                        pf_qid_unref(altq->qid);
                pool_put(&pf_altq_pl, altq);
        }
-       splx(s);
+       crit_exit();
 
        altqs_inactive_open = 0;
        return (error);
@@ -819,7 +820,6 @@ pf_commit_rules(u_int32_t ticket, int rs_num, char *anchor, char *ruleset)
        struct pf_ruleset       *rs;
        struct pf_rule          *rule;
        struct pf_rulequeue     *old_rules;
-       int                      s;
 
        if (rs_num < 0 || rs_num >= PF_RULESET_MAX)
                return (EINVAL);
@@ -829,7 +829,7 @@ pf_commit_rules(u_int32_t ticket, int rs_num, char *anchor, char *ruleset)
                return (EBUSY);
 
        /* Swap rules, keep the old. */
-       s = splsoftnet();
+       crit_enter();
        old_rules = rs->rules[rs_num].active.ptr;
        rs->rules[rs_num].active.ptr =
            rs->rules[rs_num].inactive.ptr;
@@ -844,7 +844,7 @@ pf_commit_rules(u_int32_t ticket, int rs_num, char *anchor, char *ruleset)
        rs->rules[rs_num].inactive.open = 0;
        pf_remove_if_empty_ruleset(rs);
        pf_update_anchor_rules();
-       splx(s);
+       crit_exit();
        return (0);
 }
 
@@ -853,7 +853,6 @@ pfioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct thread *td)
 {
        struct pf_pooladdr      *pa = NULL;
        struct pf_pool          *pool = NULL;
-       int                      s;
        int                      error = 0;
 
        /* XXX keep in sync with switch() below */
@@ -1152,7 +1151,7 @@ pfioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct thread *td)
                        error = EINVAL;
                        break;
                }
-               s = splsoftnet();
+               crit_enter();
                tail = TAILQ_LAST(ruleset->rules[rs_num].active.ptr,
                    pf_rulequeue);
                if (tail)
@@ -1160,7 +1159,7 @@ pfioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct thread *td)
                else
                        pr->nr = 0;
                pr->ticket = ruleset->rules[rs_num].active.ticket;
-               splx(s);
+               crit_exit();
                break;
        }
 
@@ -1184,13 +1183,13 @@ pfioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct thread *td)
                        error = EBUSY;
                        break;
                }
-               s = splsoftnet();
+               crit_enter();
                rule = TAILQ_FIRST(ruleset->rules[rs_num].active.ptr);
                while ((rule != NULL) && (rule->nr != pr->nr))
                        rule = TAILQ_NEXT(rule, entries);
                if (rule == NULL) {
                        error = EBUSY;
-                       splx(s);
+                       crit_exit();
                        break;
                }
                bcopy(rule, &pr->rule, sizeof(struct pf_rule));
@@ -1204,7 +1203,7 @@ pfioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct thread *td)
                        else
                                pr->rule.skip[i].nr =
                                    rule->skip[i].ptr->nr;
-               splx(s);
+               crit_exit();
                break;
        }
 
@@ -1341,7 +1340,7 @@ pfioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct thread *td)
                }
                pf_empty_pool(&pf_pabuf);
 
-               s = splsoftnet();
+               crit_enter();
 
                if (pcr->action == PF_CHANGE_ADD_HEAD)
                        oldrule = TAILQ_FIRST(
@@ -1357,7 +1356,7 @@ pfioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct thread *td)
                        if (oldrule == NULL) {
                                pf_rm_rule(NULL, newrule);
                                error = EINVAL;
-                               splx(s);
+                               crit_exit();
                                break;
                        }
                }
@@ -1388,7 +1387,7 @@ pfioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct thread *td)
                pf_update_anchor_rules();
 
                ruleset->rules[rs_num].active.ticket++;
-               splx(s);
+               crit_exit();
                break;
        }
 
@@ -1397,7 +1396,7 @@ pfioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct thread *td)
                struct pfioc_state_kill *psk = (struct pfioc_state_kill *)addr;
                int                      killed = 0;
 
-               s = splsoftnet();
+               crit_enter();
                RB_FOREACH(state, pf_state_tree_id, &tree_id) {
                        if (!psk->psk_ifname[0] || !strcmp(psk->psk_ifname,
                            state->u.s.kif->pfik_name)) {
@@ -1415,7 +1414,7 @@ pfioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct thread *td)
 #if NPFSYNC
                pfsync_clear_states(pf_status.hostid, psk->psk_ifname);
 #endif
-               splx(s);
+               crit_exit();
                break;
        }
 
@@ -1424,7 +1423,7 @@ pfioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct thread *td)
                struct pfioc_state_kill *psk = (struct pfioc_state_kill *)addr;
                int                      killed = 0;
 
-               s = splsoftnet();
+               crit_enter();
                RB_FOREACH(state, pf_state_tree_id, &tree_id) {
                        if ((!psk->psk_af || state->af == psk->psk_af)
                            && (!psk->psk_proto || psk->psk_proto ==
@@ -1452,7 +1451,7 @@ pfioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct thread *td)
                        }
                }
                pf_purge_expired_states();
-               splx(s);
+               crit_exit();
                psk->psk_af = killed;
                break;
        }
@@ -1472,12 +1471,12 @@ pfioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct thread *td)
                        error = ENOMEM;
                        break;
                }
-               s = splsoftnet();
+               crit_enter();
                kif = pfi_lookup_create(ps->state.u.ifname);
                if (kif == NULL) {
                        pool_put(&pf_state_pl, state);
                        error = ENOENT;
-                       splx(s);
+                       crit_exit();
                        break;
                }
                bcopy(&ps->state, state, sizeof(struct pf_state));
@@ -1496,7 +1495,7 @@ pfioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct thread *td)
                        pool_put(&pf_state_pl, state);
                        error = ENOMEM;
                }
-               splx(s);
+               crit_exit();
                break;
        }
 
@@ -1506,7 +1505,7 @@ pfioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct thread *td)
                u_int32_t                nr;
 
                nr = 0;
-               s = splsoftnet();
+               crit_enter();
                RB_FOREACH(state, pf_state_tree_id, &tree_id) {
                        if (nr >= ps->nr)
                                break;
@@ -1514,7 +1513,7 @@ pfioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct thread *td)
                }
                if (state == NULL) {
                        error = EBUSY;
-                       splx(s);
+                       crit_exit();
                        break;
                }
                bcopy(state, &ps->state, sizeof(struct pf_state));
@@ -1523,7 +1522,7 @@ pfioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct thread *td)
                    (uint32_t)(-1) : state->nat_rule.ptr->nr;
                ps->state.anchor.nr = (state->anchor.ptr == NULL) ?
                    (uint32_t)(-1) : state->anchor.ptr->nr;
-               splx(s);
+               crit_exit();
                ps->state.expire = pf_state_expires(state);
                if (ps->state.expire > time_second)
                        ps->state.expire -= time_second;
@@ -1541,15 +1540,15 @@ pfioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct thread *td)
                int                      space = ps->ps_len;
 
                if (space == 0) {
-                       s = splsoftnet();
+                       crit_enter();
                        TAILQ_FOREACH(kif, &pfi_statehead, pfik_w_states)
                                nr += kif->pfik_states;
-                       splx(s);
+                       crit_exit();
                        ps->ps_len = sizeof(struct pf_state) * nr;
                        return (0);
                }
 
-               s = splsoftnet();
+               crit_enter();
                p = ps->ps_states;
                TAILQ_FOREACH(kif, &pfi_statehead, pfik_w_states)
                        RB_FOREACH(state, pf_state_tree_ext_gwy,
@@ -1577,14 +1576,14 @@ pfioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct thread *td)
                                        pstore.expire = 0;
                                error = copyout(&pstore, p, sizeof(*p));
                                if (error) {
-                                       splx(s);
+                                       crit_exit();
                                        goto fail;
                                }
                                p++;
                                nr++;
                        }
                ps->ps_len = sizeof(struct pf_state) * nr;
-               splx(s);
+               crit_exit();
                break;
        }
 
@@ -1635,7 +1634,7 @@ pfioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct thread *td)
                    !pnl->dport || !pnl->sport)
                        error = EINVAL;
                else {
-                       s = splsoftnet();
+                       crit_enter();
 
                        /*
                         * userland gives us source and dest of connection,
@@ -1676,7 +1675,7 @@ pfioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct thread *td)
                                }
                        } else
                                error = ENOENT;
-                       splx(s);
+                       crit_exit();
                }
                break;
        }
@@ -1746,12 +1745,12 @@ pfioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct thread *td)
                struct pf_ruleset       *ruleset = &pf_main_ruleset;
                struct pf_rule          *rule;
 
-               s = splsoftnet();
+               crit_enter();
                TAILQ_FOREACH(rule,
                    ruleset->rules[PF_RULESET_FILTER].active.ptr, entries)
                        rule->evaluations = rule->packets =
                            rule->bytes = 0;
-               splx(s);
+               crit_exit();
                break;
        }
 
@@ -1779,7 +1778,7 @@ pfioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct thread *td)
                struct tb_profile        tb;
 
                /* enable all altq interfaces on active list */
-               s = splsoftnet();
+               crit_enter();
                TAILQ_FOREACH(altq, pf_altqs_active, entries) {
                        if (altq->qname[0] == 0) {
                                if ((ifp = ifunit(altq->ifname)) == NULL) {
@@ -1798,7 +1797,7 @@ pfioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct thread *td)
                                        break;
                        }
                }
-               splx(s);
+               crit_exit();
                DPFPRINTF(PF_DEBUG_MISC, ("altq: started\n"));
                break;
        }
@@ -1810,7 +1809,7 @@ pfioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct thread *td)
                int                      err;
 
                /* disable all altq interfaces on active list */
-               s = splsoftnet();
+               crit_enter();
                TAILQ_FOREACH(altq, pf_altqs_active, entries) {
                        if (altq->qname[0] == 0) {
                                if ((ifp = ifunit(altq->ifname)) == NULL) {
@@ -1829,7 +1828,7 @@ pfioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct thread *td)
                                        error = err;
                        }
                }
-               splx(s);
+               crit_exit();
                DPFPRINTF(PF_DEBUG_MISC, ("altq: stopped\n"));
                break;
        }
@@ -1898,11 +1897,11 @@ pfioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct thread *td)
                struct pf_altq          *altq;
 
                pa->nr = 0;
-               s = splsoftnet();
+               crit_enter();
                TAILQ_FOREACH(altq, pf_altqs_active, entries)
                        pa->nr++;
                pa->ticket = ticket_altqs_active;
-               splx(s);
+               crit_exit();
                break;
        }
 
@@ -1916,7 +1915,7 @@ pfioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct thread *td)
                        break;
                }
                nr = 0;
-               s = splsoftnet();
+               crit_enter();
                altq = TAILQ_FIRST(pf_altqs_active);
                while ((altq != NULL) && (nr < pa->nr)) {
                        altq = TAILQ_NEXT(altq, entries);
@@ -1924,11 +1923,11 @@ pfioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct thread *td)
                }
                if (altq == NULL) {
                        error = EBUSY;
-                       splx(s);
+                       crit_exit();
                        break;
                }
                bcopy(altq, &pa->altq, sizeof(struct pf_altq));
-               splx(s);
+               crit_exit();
                break;
        }
 
@@ -1949,7 +1948,7 @@ pfioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct thread *td)
                }
                nbytes = pq->nbytes;
                nr = 0;
-               s = splsoftnet();
+               crit_enter();
                altq = TAILQ_FIRST(pf_altqs_active);
                while ((altq != NULL) && (nr < pq->nr)) {
                        altq = TAILQ_NEXT(altq, entries);
@@ -1957,11 +1956,11 @@ pfioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct thread *td)
                }
                if (altq == NULL) {
                        error = EBUSY;
-                       splx(s);
+                       crit_exit();
                        break;
                }
                error = altq_getqstats(altq, pq->buf, &nbytes);
-               splx(s);
+               crit_exit();
                if (error == 0) {
                        pq->scheduler = altq->scheduler;
                        pq->nbytes = nbytes;
@@ -2028,17 +2027,17 @@ pfioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct thread *td)
                struct pfioc_pooladdr   *pp = (struct pfioc_pooladdr *)addr;
 
                pp->nr = 0;
-               s = splsoftnet();
+               crit_enter();
                pool = pf_get_pool(pp->anchor, pp->ruleset, pp->ticket,
                    pp->r_action, pp->r_num, 0, 1, 0);
                if (pool == NULL) {
                        error = EBUSY;
-                       splx(s);
+                       crit_exit();
                        break;
                }
                TAILQ_FOREACH(pa, &pool->list, entries)
                        pp->nr++;
-               splx(s);
+               crit_exit();
                break;
        }
 
@@ -2046,12 +2045,12 @@ pfioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct thread *td)
                struct pfioc_pooladdr   *pp = (struct pfioc_pooladdr *)addr;
                u_int32_t                nr = 0;
 
-               s = splsoftnet();
+               crit_enter();
                pool = pf_get_pool(pp->anchor, pp->ruleset, pp->ticket,
                    pp->r_action, pp->r_num, 0, 1, 1);
                if (pool == NULL) {
                        error = EBUSY;
-                       splx(s);
+                       crit_exit();
                        break;
                }
                pa = TAILQ_FIRST(&pool->list);
@@ -2061,13 +2060,13 @@ pfioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct thread *td)
                }
                if (pa == NULL) {
                        error = EBUSY;
-                       splx(s);
+                       crit_exit();
                        break;
                }
                bcopy(pa, &pp->addr, sizeof(struct pf_pooladdr));
                pfi_dynaddr_copyout(&pp->addr.addr);
                pf_tbladdr_copyout(&pp->addr.addr);
-               splx(s);
+               crit_exit();
                break;
        }
 
@@ -2139,7 +2138,7 @@ pfioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct thread *td)
                        }
                }
 
-               s = splsoftnet();
+               crit_enter();
 
                if (pca->action == PF_CHANGE_ADD_HEAD)
                        oldpa = TAILQ_FIRST(&pool->list);
@@ -2155,7 +2154,7 @@ pfioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct thread *td)
                        }
                        if (oldpa == NULL) {
                                error = EINVAL;
-                               splx(s);
+                               crit_exit();
                                break;
                        }
                }
@@ -2180,7 +2179,7 @@ pfioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct thread *td)
                pool->cur = TAILQ_FIRST(&pool->list);
                PF_ACPY(&pool->counter, &pool->cur->addr.v.a.addr,
                    pca->af);
-               splx(s);
+               crit_exit();
                break;
        }
 
@@ -2476,17 +2475,17 @@ pfioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct thread *td)
 
        case DIOCOSFPADD: {
                struct pf_osfp_ioctl *io = (struct pf_osfp_ioctl *)addr;
-               s = splsoftnet();
+               crit_enter();
                error = pf_osfp_add(io);
-               splx(s);
+               crit_exit();
                break;
        }
 
        case DIOCOSFPGET: {
                struct pf_osfp_ioctl *io = (struct pf_osfp_ioctl *)addr;
-               s = splsoftnet();
+               crit_enter();
                error = pf_osfp_get(io);
-               splx(s);
+               crit_exit();
                break;
        }
 
@@ -2683,15 +2682,15 @@ pfioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct thread *td)
                int                      space = psn->psn_len;
 
                if (space == 0) {
-                       s = splsoftnet();
+                       crit_enter();
                        RB_FOREACH(n, pf_src_tree, &tree_src_tracking)
                                nr++;
-                       splx(s);
+                       crit_exit();
                        psn->psn_len = sizeof(struct pf_src_node) * nr;
                        return (0);
                }
 
-               s = splsoftnet();
+               crit_enter();
                p = psn->psn_src_nodes;
                RB_FOREACH(n, pf_src_tree, &tree_src_tracking) {
                        int     secs = time_second;
@@ -2709,14 +2708,14 @@ pfioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct thread *td)
                                pstore.expire = 0;
                        error = copyout(&pstore, p, sizeof(*p));
                        if (error) {
-                               splx(s);
+                               crit_exit();
                                goto fail;
                        }
                        p++;
                        nr++;
                }
                psn->psn_len = sizeof(struct pf_src_node) * nr;
-               splx(s);
+               crit_exit();
                break;
        }
 
@@ -2724,7 +2723,7 @@ pfioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct thread *td)
                struct pf_src_node      *n;
                struct pf_state         *state;
 
-               s = splsoftnet();
+               crit_enter();
                RB_FOREACH(state, pf_state_tree_id, &tree_id) {
                        state->src_node = NULL;
                        state->nat_src_node = NULL;
@@ -2735,7 +2734,7 @@ pfioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct thread *td)
                }
                pf_purge_expired_src_nodes();
                pf_status.src_nodes = 0;
-               splx(s);
+               crit_exit();
                break;
        }
 
@@ -2751,9 +2750,9 @@ pfioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct thread *td)
        }
 
        case DIOCOSFPFLUSH:
-               s = splsoftnet();
+               crit_enter();
                pf_osfp_flush();
-               splx(s);
+               crit_exit();
                break;
 
        case DIOCIGETIFACES: {
index 7503ff8..8eaee24 100644 (file)
@@ -1,6 +1,6 @@
 /*     $FreeBSD: src/sys/contrib/pf/net/pf_table.c,v 1.5 2004/07/28 06:14:44 kan Exp $ */
 /*     $OpenBSD: pf_table.c,v 1.47 2004/03/09 21:44:41 mcbride Exp $   */
-/*     $DragonFly: src/sys/net/pf/pf_table.c,v 1.2 2004/12/14 18:46:08 hsu Exp $ */
+/*     $DragonFly: src/sys/net/pf/pf_table.c,v 1.3 2005/06/15 16:32:58 joerg Exp $ */
 
 /*
  * Copyright (c) 2004 The DragonFly Project.  All rights reserved.
@@ -43,6 +43,7 @@
 #include <sys/mbuf.h>
 #include <sys/kernel.h>
 #include <sys/malloc.h>
+#include <sys/thread2.h>
 #include <vm/vm_zone.h>
 
 #include <net/if.h>
@@ -207,7 +208,6 @@ pfr_clr_addrs(struct pfr_table *tbl, int *ndel, int flags)
 {
        struct pfr_ktable       *kt;
        struct pfr_kentryworkq   workq;
-       int                      s = 0;
 
        ACCEPT_FLAGS(PFR_FLAG_ATOMIC+PFR_FLAG_DUMMY);
        if (pfr_validate_table(tbl, 0, flags & PFR_FLAG_USERIOCTL))
@@ -221,10 +221,10 @@ pfr_clr_addrs(struct pfr_table *tbl, int *ndel, int flags)
 
        if (!(flags & PFR_FLAG_DUMMY)) {
                if (flags & PFR_FLAG_ATOMIC)
-                       s = splsoftnet();
+                       crit_enter();
                pfr_remove_kentries(kt, &workq);
                if (flags & PFR_FLAG_ATOMIC)
-                       splx(s);
+                       crit_exit();
                if (kt->pfrkt_cnt) {
                        printf("pfr_clr_addrs: corruption detected (%d).\n",
                            kt->pfrkt_cnt);
@@ -242,7 +242,7 @@ pfr_add_addrs(struct pfr_table *tbl, struct pfr_addr *addr, int size,
        struct pfr_kentryworkq   workq;
        struct pfr_kentry       *p, *q;
        struct pfr_addr          ad;
-       int                      i, rv, s = 0, xadd = 0;
+       int                      i, rv, xadd = 0;
        long                     tzero = time_second;
 
        ACCEPT_FLAGS(PFR_FLAG_ATOMIC+PFR_FLAG_DUMMY+PFR_FLAG_FEEDBACK);
@@ -293,10 +293,10 @@ pfr_add_addrs(struct pfr_table *tbl, struct pfr_addr *addr, int size,
        pfr_clean_node_mask(tmpkt, &workq);
        if (!(flags & PFR_FLAG_DUMMY)) {
                if (flags & PFR_FLAG_ATOMIC)
-                       s = splsoftnet();
+                       crit_enter();
                pfr_insert_kentries(kt, &workq, tzero);
                if (flags & PFR_FLAG_ATOMIC)
-                       splx(s);
+                       crit_exit();
        } else
                pfr_destroy_kentries(&workq);
        if (nadd != NULL)
@@ -320,7 +320,7 @@ pfr_del_addrs(struct pfr_table *tbl, struct pfr_addr *addr, int size,
        struct pfr_kentryworkq   workq;
        struct pfr_kentry       *p;
        struct pfr_addr          ad;
-       int                      i, rv, s = 0, xdel = 0;
+       int                      i, rv, xdel = 0;
 
        ACCEPT_FLAGS(PFR_FLAG_ATOMIC+PFR_FLAG_DUMMY+PFR_FLAG_FEEDBACK);
        if (pfr_validate_table(tbl, 0, flags & PFR_FLAG_USERIOCTL))
@@ -360,10 +360,10 @@ pfr_del_addrs(struct pfr_table *tbl, struct pfr_addr *addr, int size,
        }
        if (!(flags & PFR_FLAG_DUMMY)) {
                if (flags & PFR_FLAG_ATOMIC)
-                       s = splsoftnet();
+                       crit_enter();
                pfr_remove_kentries(kt, &workq);
                if (flags & PFR_FLAG_ATOMIC)
-                       splx(s);
+                       crit_exit();
        }
        if (ndel != NULL)
                *ndel = xdel;
@@ -382,7 +382,7 @@ pfr_set_addrs(struct pfr_table *tbl, struct pfr_addr *addr, int size,
        struct pfr_kentryworkq   addq, delq, changeq;
        struct pfr_kentry       *p, *q;
        struct pfr_addr          ad;
-       int                      i, rv, s = 0, xadd = 0, xdel = 0, xchange = 0;
+       int                      i, rv, xadd = 0, xdel = 0, xchange = 0;
        long                     tzero = time_second;
 
        ACCEPT_FLAGS(PFR_FLAG_ATOMIC+PFR_FLAG_DUMMY+PFR_FLAG_FEEDBACK);
@@ -459,12 +459,12 @@ _skip:
        pfr_clean_node_mask(tmpkt, &addq);
        if (!(flags & PFR_FLAG_DUMMY)) {
                if (flags & PFR_FLAG_ATOMIC)
-                       s = splsoftnet();
+                       crit_enter();
                pfr_insert_kentries(kt, &addq, tzero);
                pfr_remove_kentries(kt, &delq);
                pfr_clstats_kentries(&changeq, tzero, INVERT_NEG_FLAG);
                if (flags & PFR_FLAG_ATOMIC)
-                       splx(s);
+                       crit_exit();
        } else
                pfr_destroy_kentries(&addq);
        if (nadd != NULL)
@@ -570,7 +570,7 @@ pfr_get_astats(struct pfr_table *tbl, struct pfr_astats *addr, int *size,
        struct pfr_ktable       *kt;
        struct pfr_walktree      w;
        struct pfr_kentryworkq   workq;
-       int                      rv, s = 0;
+       int                      rv;
        long                     tzero = time_second;
 
        ACCEPT_FLAGS(PFR_FLAG_ATOMIC); /* XXX PFR_FLAG_CLSTATS disabled */
@@ -590,7 +590,7 @@ pfr_get_astats(struct pfr_table *tbl, struct pfr_astats *addr, int *size,
        w.pfrw_free = kt->pfrkt_cnt;
        w.pfrw_flags = flags;
        if (flags & PFR_FLAG_ATOMIC)
-               s = splsoftnet();
+               crit_enter();
        rv = kt->pfrkt_ip4->rnh_walktree(kt->pfrkt_ip4, pfr_walktree, &w);
        if (!rv)
                rv = kt->pfrkt_ip6->rnh_walktree(kt->pfrkt_ip6, pfr_walktree, &w);
@@ -599,7 +599,7 @@ pfr_get_astats(struct pfr_table *tbl, struct pfr_astats *addr, int *size,
                pfr_clstats_kentries(&workq, tzero, 0);
        }
        if (flags & PFR_FLAG_ATOMIC)
-               splx(s);
+               crit_exit();
        if (rv)
                return (rv);
 
@@ -620,7 +620,7 @@ pfr_clr_astats(struct pfr_table *tbl, struct pfr_addr *addr, int size,
        struct pfr_kentryworkq   workq;
        struct pfr_kentry       *p;
        struct pfr_addr          ad;
-       int                      i, rv, s = 0, xzero = 0;
+       int                      i, rv, xzero = 0;
 
        ACCEPT_FLAGS(PFR_FLAG_ATOMIC+PFR_FLAG_DUMMY+PFR_FLAG_FEEDBACK);
        if (pfr_validate_table(tbl, 0, 0))
@@ -649,10 +649,10 @@ pfr_clr_astats(struct pfr_table *tbl, struct pfr_addr *addr, int size,
 
        if (!(flags & PFR_FLAG_DUMMY)) {
                if (flags & PFR_FLAG_ATOMIC)
-                       s = splsoftnet();
+                       crit_enter();
                pfr_clstats_kentries(&workq, 0, 0);
                if (flags & PFR_FLAG_ATOMIC)
-                       splx(s);
+                       crit_exit();
        }
        if (nzero != NULL)
                *nzero = xzero;
@@ -733,7 +733,6 @@ pfr_lookup_addr(struct pfr_ktable *kt, struct pfr_addr *ad, int exact)
        union sockaddr_union     sa, mask;
        struct radix_node_head  *head;
        struct pfr_kentry       *ke;
-       int                      s;
 
        bzero(&sa, sizeof(sa));
        if (ad->pfra_af == AF_INET) {
@@ -745,10 +744,10 @@ pfr_lookup_addr(struct pfr_ktable *kt, struct pfr_addr *ad, int exact)
        }
        if (ADDR_NETWORK(ad)) {
                pfr_prepare_network(&mask, ad->pfra_af, ad->pfra_net);
-               s = splsoftnet(); /* rn_lookup makes use of globals */
+               crit_enter(); /* rn_lookup makes use of globals */
                ke = (struct pfr_kentry *)rn_lookup((char *)&sa, (char *)&mask,
                    head);
-               splx(s);
+               crit_exit();
                if (ke && KENTRY_RNF_ROOT(ke))
                        ke = NULL;
        } else {
@@ -847,15 +846,14 @@ void
 pfr_clstats_kentries(struct pfr_kentryworkq *workq, long tzero, int negchange)
 {
        struct pfr_kentry       *p;
-       int                      s;
 
        SLIST_FOREACH(p, workq, pfrke_workq) {
-               s = splsoftnet();
+               crit_enter();
                if (negchange)
                        p->pfrke_not = !p->pfrke_not;
                bzero(p->pfrke_packets, sizeof(p->pfrke_packets));
                bzero(p->pfrke_bytes, sizeof(p->pfrke_bytes));
-               splx(s);
+               crit_exit();
                p->pfrke_tzero = tzero;
        }
 }
@@ -906,7 +904,6 @@ pfr_route_kentry(struct pfr_ktable *kt, struct pfr_kentry *ke)
        union sockaddr_union     mask;
        struct radix_node       *rn;
        struct radix_node_head  *head;
-       int                      s;
 
        bzero(ke->pfrke_node, sizeof(ke->pfrke_node));
        if (ke->pfrke_af == AF_INET)
@@ -914,7 +911,7 @@ pfr_route_kentry(struct pfr_ktable *kt, struct pfr_kentry *ke)
        else
                head = kt->pfrkt_ip6;
 
-       s = splsoftnet();
+       crit_enter();
        if (KENTRY_NETWORK(ke)) {
                pfr_prepare_network(&mask, ke->pfrke_af, ke->pfrke_net);
                rn = rn_addroute((char *)&ke->pfrke_sa, (char *)&mask, head,
@@ -922,7 +919,7 @@ pfr_route_kentry(struct pfr_ktable *kt, struct pfr_kentry *ke)
        } else
                rn = rn_addroute((char *)&ke->pfrke_sa, NULL, head,
                    ke->pfrke_node);
-       splx(s);
+       crit_exit();
 
        return (rn == NULL ? -1 : 0);
 }
@@ -933,20 +930,19 @@ pfr_unroute_kentry(struct pfr_ktable *kt, struct pfr_kentry *ke)
        union sockaddr_union     mask;
        struct radix_node       *rn;
        struct radix_node_head  *head;
-       int                      s;
 
        if (ke->pfrke_af == AF_INET)
                head = kt->pfrkt_ip4;
        else
                head = kt->pfrkt_ip6;
 
-       s = splsoftnet();
+       crit_enter();
        if (KENTRY_NETWORK(ke)) {
                pfr_prepare_network(&mask, ke->pfrke_af, ke->pfrke_net);
                rn = rn_delete((char *)&ke->pfrke_sa, (char *)&mask, head);
        } else
                rn = rn_delete((char *)&ke->pfrke_sa, NULL, head);
-       splx(s);
+       crit_exit();
 
        if (rn == NULL) {
                printf("pfr_unroute_kentry: delete failed.\n");
@@ -975,7 +971,7 @@ pfr_walktree(struct radix_node *rn, void *arg)
 {
        struct pfr_kentry       *ke = (struct pfr_kentry *)rn;
        struct pfr_walktree     *w = arg;
-       int                      s, flags = w->pfrw_flags;
+       int                      flags = w->pfrw_flags;
 
        switch (w->pfrw_op) {
        case PFRW_MARK:
@@ -1005,12 +1001,12 @@ pfr_walktree(struct radix_node *rn, void *arg)
 
                        pfr_copyout_addr(&as.pfras_a, ke);
 
-                       s = splsoftnet();
+                       crit_enter();
                        bcopy(ke->pfrke_packets, as.pfras_packets,
                            sizeof(as.pfras_packets));
                        bcopy(ke->pfrke_bytes, as.pfras_bytes,
                            sizeof(as.pfras_bytes));
-                       splx(s);
+                       crit_exit();
                        as.pfras_tzero = ke->pfrke_tzero;
 
                        if (COPYOUT(&as, w->pfrw_astats, sizeof(as)))
@@ -1054,7 +1050,7 @@ pfr_clr_tables(struct pfr_table *filter, int *ndel, int flags)
 {
        struct pfr_ktableworkq   workq;
        struct pfr_ktable       *p;
-       int                      s = 0, xdel = 0;
+       int                      xdel = 0;
 
        ACCEPT_FLAGS(PFR_FLAG_ATOMIC+PFR_FLAG_DUMMY+PFR_FLAG_ALLRSETS);
        if (pfr_table_count(filter, flags) < 0)
@@ -1074,10 +1070,10 @@ pfr_clr_tables(struct pfr_table *filter, int *ndel, int flags)
        }
        if (!(flags & PFR_FLAG_DUMMY)) {
                if (flags & PFR_FLAG_ATOMIC)
-                       s = splsoftnet();
+                       crit_enter();
                pfr_setflags_ktables(&workq);
                if (flags & PFR_FLAG_ATOMIC)
-                       splx(s);
+                       crit_exit();
        }
        if (ndel != NULL)
                *ndel = xdel;
@@ -1089,7 +1085,7 @@ pfr_add_tables(struct pfr_table *tbl, int size, int *nadd, int flags)
 {
        struct pfr_ktableworkq   addq, changeq;
        struct pfr_ktable       *p, *q, *r, key;
-       int                      i, rv, s = 0, xadd = 0;
+       int                      i, rv, xadd = 0;
        long                     tzero = time_second;
 
        ACCEPT_FLAGS(PFR_FLAG_ATOMIC+PFR_FLAG_DUMMY);
@@ -1150,11 +1146,11 @@ _skip:
        }
        if (!(flags & PFR_FLAG_DUMMY)) {
                if (flags & PFR_FLAG_ATOMIC)
-                       s = splsoftnet();
+                       crit_enter();
                pfr_insert_ktables(&addq);
                pfr_setflags_ktables(&changeq);
                if (flags & PFR_FLAG_ATOMIC)
-                       splx(s);
+                       crit_exit();
        } else
                 pfr_destroy_ktables(&addq, 0);
        if (nadd != NULL)
@@ -1170,7 +1166,7 @@ pfr_del_tables(struct pfr_table *tbl, int size, int *ndel, int flags)
 {
        struct pfr_ktableworkq   workq;
        struct pfr_ktable       *p, *q, key;
-       int                      i, s = 0, xdel = 0;
+       int                      i, xdel = 0;
 
        ACCEPT_FLAGS(PFR_FLAG_ATOMIC+PFR_FLAG_DUMMY);
        SLIST_INIT(&workq);
@@ -1195,10 +1191,10 @@ _skip:
 
        if (!(flags & PFR_FLAG_DUMMY)) {
                if (flags & PFR_FLAG_ATOMIC)
-                       s = splsoftnet();
+                       crit_enter();
                pfr_setflags_ktables(&workq);
                if (flags & PFR_FLAG_ATOMIC)
-                       splx(s);
+                       crit_exit();
        }
        if (ndel != NULL)
                *ndel = xdel;
@@ -1242,7 +1238,7 @@ pfr_get_tstats(struct pfr_table *filter, struct pfr_tstats *tbl, int *size,
 {
        struct pfr_ktable       *p;
        struct pfr_ktableworkq   workq;
-       int                      s = 0, n, nn;
+       int                      n, nn;
        long                     tzero = time_second;
 
        ACCEPT_FLAGS(PFR_FLAG_ATOMIC|PFR_FLAG_ALLRSETS);
@@ -1256,27 +1252,27 @@ pfr_get_tstats(struct pfr_table *filter, struct pfr_tstats *tbl, int *size,
        }
        SLIST_INIT(&workq);
        if (flags & PFR_FLAG_ATOMIC)
-               s = splsoftnet();
+               crit_enter();
        RB_FOREACH(p, pfr_ktablehead, &pfr_ktables) {
                if (pfr_skip_table(filter, p, flags))
                        continue;
                if (n-- <= 0)
                        continue;
                if (!(flags & PFR_FLAG_ATOMIC))
-                       s = splsoftnet();
+                       crit_enter();
                if (COPYOUT(&p->pfrkt_ts, tbl++, sizeof(*tbl))) {
-                       splx(s);
+                       crit_exit();
                        return (EFAULT);
                }
                if (!(flags & PFR_FLAG_ATOMIC))
-                       splx(s);
+                       crit_exit();
                SLIST_INSERT_HEAD(&workq, p, pfrkt_workq);
        }
        if (flags & PFR_FLAG_CLSTATS)
                pfr_clstats_ktables(&workq, tzero,
                    flags & PFR_FLAG_ADDRSTOO);
        if (flags & PFR_FLAG_ATOMIC)
-               splx(s);
+               crit_exit();
        if (n) {
                printf("pfr_get_tstats: corruption detected (%d).\n", n);
                return (ENOTTY);
@@ -1290,7 +1286,7 @@ pfr_clr_tstats(struct pfr_table *tbl, int size, int *nzero, int flags)
 {
        struct pfr_ktableworkq   workq;
        struct pfr_ktable       *p, key;
-       int                      i, s = 0, xzero = 0;
+       int                      i, xzero = 0;
        long                     tzero = time_second;
 
        ACCEPT_FLAGS(PFR_FLAG_ATOMIC+PFR_FLAG_DUMMY+PFR_FLAG_ADDRSTOO);
@@ -1308,10 +1304,10 @@ pfr_clr_tstats(struct pfr_table *tbl, int size, int *nzero, int flags)
        }
        if (!(flags & PFR_FLAG_DUMMY)) {
                if (flags & PFR_FLAG_ATOMIC)
-                       s = splsoftnet();
+                       crit_enter();
                pfr_clstats_ktables(&workq, tzero, flags & PFR_FLAG_ADDRSTOO);
                if (flags & PFR_FLAG_ATOMIC)
-                       splx(s);
+                       crit_exit();
        }
        if (nzero != NULL)
                *nzero = xzero;
@@ -1324,7 +1320,7 @@ pfr_set_tflags(struct pfr_table *tbl, int size, int setflag, int clrflag,
 {
        struct pfr_ktableworkq   workq;
        struct pfr_ktable       *p, *q, key;
-       int                      i, s = 0, xchange = 0, xdel = 0;
+       int                      i, xchange = 0, xdel = 0;
 
        ACCEPT_FLAGS(PFR_FLAG_ATOMIC+PFR_FLAG_DUMMY);
        if ((setflag & ~PFR_TFLAG_USRMASK) ||
@@ -1360,10 +1356,10 @@ _skip:
        }
        if (!(flags & PFR_FLAG_DUMMY)) {
                if (flags & PFR_FLAG_ATOMIC)
-                       s = splsoftnet();
+                       crit_enter();
                pfr_setflags_ktables(&workq);
                if (flags & PFR_FLAG_ATOMIC)
-                       splx(s);
+                       crit_exit();
        }
        if (nchange != NULL)
                *nchange = xchange;
@@ -1543,7 +1539,7 @@ pfr_ina_commit(struct pfr_table *trs, u_int32_t ticket, int *nadd,
        struct pfr_ktable       *p;
        struct pfr_ktableworkq   workq;
        struct pf_ruleset       *rs;
-       int                      s = 0, xadd = 0, xchange = 0;
+       int                      xadd = 0, xchange = 0;
        long                     tzero = time_second;
 
        ACCEPT_FLAGS(PFR_FLAG_ATOMIC+PFR_FLAG_DUMMY);
@@ -1565,11 +1561,11 @@ pfr_ina_commit(struct pfr_table *trs, u_int32_t ticket, int *nadd,
 
        if (!(flags & PFR_FLAG_DUMMY)) {
                if (flags & PFR_FLAG_ATOMIC)
-                       s = splsoftnet();
+                       crit_enter();
                SLIST_FOREACH(p, &workq, pfrkt_workq)
                        pfr_commit_ktable(p, tzero);
                if (flags & PFR_FLAG_ATOMIC)
-                       splx(s);
+                       crit_exit();
                rs->topen = 0;
                pf_remove_if_empty_ruleset(rs);
        }
@@ -1769,17 +1765,16 @@ void
 pfr_clstats_ktable(struct pfr_ktable *kt, long tzero, int recurse)
 {
        struct pfr_kentryworkq   addrq;
-       int                      s;
 
        if (recurse) {
                pfr_enqueue_addrs(kt, &addrq, NULL, 0);
                pfr_clstats_kentries(&addrq, tzero, 0);
        }
-       s = splsoftnet();
+       crit_enter();
        bzero(kt->pfrkt_packets, sizeof(kt->pfrkt_packets));
        bzero(kt->pfrkt_bytes, sizeof(kt->pfrkt_bytes));
        kt->pfrkt_match = kt->pfrkt_nomatch = 0;
-       splx(s);
+       crit_exit();
        kt->pfrkt_tzero = tzero;
 }
 
@@ -2105,18 +2100,17 @@ void
 pfr_dynaddr_update(struct pfr_ktable *kt, struct pfi_dynaddr *dyn)
 {
        struct pfr_walktree     w;
-       int                     s;
 
        bzero(&w, sizeof(w));
        w.pfrw_op = PFRW_DYNADDR_UPDATE;
        w.pfrw_dyn = dyn;
 
-       s = splsoftnet();
+       crit_enter();
        dyn->pfid_acnt4 = 0;
        dyn->pfid_acnt6 = 0;
        if (!dyn->pfid_af || dyn->pfid_af == AF_INET)
                kt->pfrkt_ip4->rnh_walktree(kt->pfrkt_ip4, pfr_walktree, &w);
        if (!dyn->pfid_af || dyn->pfid_af == AF_INET6)
                kt->pfrkt_ip6->rnh_walktree(kt->pfrkt_ip6, pfr_walktree, &w);
-       splx(s);
+       crit_exit();
 }
index ce6e256..8d9c3a1 100644 (file)
@@ -1,7 +1,7 @@
 /*     $FreeBSD: src/sys/contrib/pf/net/pfvar.h,v 1.8 2004/08/12 13:59:44 mlaier Exp $ */
 /*     $OpenBSD: pfvar.h,v 1.187 2004/03/22 04:54:18 mcbride Exp $ */
 /* add $OpenBSD: pfvar.h,v 1.194 2004/05/11 07:34:11 dhartmei Exp $ */
-/*     $DragonFly: src/sys/net/pf/pfvar.h,v 1.2 2005/02/11 22:25:57 joerg Exp $ */
+/*     $DragonFly: src/sys/net/pf/pfvar.h,v 1.3 2005/06/15 16:32:58 joerg Exp $ */
 
 /*
  * Copyright (c) 2004 The DragonFly Project.  All rights reserved.
@@ -166,8 +166,6 @@ struct pfi_dynaddr {
  * Address manipulation macros
  */
 
-#define        splsoftnet()    splnet()
-
 /* XXX correct values for zinit? */
 #define        ZONE_CREATE(var, type, desc)                            \
                var = zinit(desc, sizeof(type), 1, 0, 1);       \