From 4986965bf9338066926452c12ce80de6479471d0 Mon Sep 17 00:00:00 2001 From: Joerg Sonnenberger Date: Wed, 15 Jun 2005 19:29:30 +0000 Subject: [PATCH] Convert to critical sections. --- sys/net/if.c | 72 +++++++++++++++++++-------------------- sys/net/if_atmsubr.c | 8 ++--- sys/net/if_ethersubr.c | 18 +++++----- sys/net/if_iso88025subr.c | 10 +++--- sys/net/if_loop.c | 14 ++++---- sys/net/if_mib.c | 10 +++--- sys/net/if_var.h | 12 ++++--- sys/net/ifq_var.h | 10 +++--- sys/net/intrq.c | 9 ++--- sys/net/route.c | 8 ++--- 10 files changed, 88 insertions(+), 83 deletions(-) diff --git a/sys/net/if.c b/sys/net/if.c index ac3b3fea7c..610f23a609 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -32,7 +32,7 @@ * * @(#)if.c 8.3 (Berkeley) 1/4/94 * $FreeBSD: src/sys/net/if.c,v 1.185 2004/03/13 02:35:03 brooks Exp $ - * $DragonFly: src/sys/net/if.c,v 1.39 2005/06/05 12:35:24 joerg Exp $ + * $DragonFly: src/sys/net/if.c,v 1.40 2005/06/15 19:29:30 joerg Exp $ */ #include "opt_compat.h" @@ -141,18 +141,17 @@ void ifinit(void *dummy) { struct ifnet *ifp; - int s; callout_init(&if_slowtimo_timer); - s = splimp(); + crit_enter(); TAILQ_FOREACH(ifp, &ifnet, if_link) { if (ifp->if_snd.ifq_maxlen == 0) { if_printf(ifp, "XXX: driver didn't set ifq_maxlen\n"); ifp->if_snd.ifq_maxlen = ifqmaxlen; } } - splx(s); + crit_exit(); if_slowtimo(0); } @@ -264,12 +263,11 @@ static void if_attachdomain(void *dummy) { struct ifnet *ifp; - int s; - s = splnet(); - for (ifp = TAILQ_FIRST(&ifnet); ifp; ifp = TAILQ_NEXT(ifp, if_list)) + crit_enter(); + TAILQ_FOREACH(ifp, &ifnet, if_list) if_attachdomain1(ifp); - splx(s); + crit_exit(); } SYSINIT(domainifattach, SI_SUB_PROTO_IFATTACHDOMAIN, SI_ORDER_FIRST, if_attachdomain, NULL); @@ -278,9 +276,8 @@ static void if_attachdomain1(struct ifnet *ifp) { struct domain *dp; - int s; - s = splnet(); + crit_enter(); /* address family dependent data region */ bzero(ifp->if_afdata, sizeof(ifp->if_afdata)); @@ -288,7 +285,7 @@ if_attachdomain1(struct ifnet *ifp) if (dp->dom_ifattach) ifp->if_afdata[dp->dom_family] = (*dp->dom_ifattach)(ifp); - splx(s); + crit_exit(); } /* @@ -300,7 +297,6 @@ if_detach(struct ifnet *ifp) { struct ifaddr *ifa; struct radix_node_head *rnh; - int s; int i; struct domain *dp; @@ -309,7 +305,7 @@ if_detach(struct ifnet *ifp) /* * Remove routes and flush queues. */ - s = splnet(); + crit_enter(); #ifdef DEVICE_POLLING if (ifp->if_flags & IFF_POLLING) ether_poll_deregister(ifp); @@ -398,7 +394,7 @@ if_detach(struct ifnet *ifp) if_index--; TAILQ_REMOVE(&ifnet, ifp, if_link); - splx(s); + crit_exit(); } /* @@ -968,7 +964,8 @@ static void if_slowtimo(void *arg) { struct ifnet *ifp; - int s = splimp(); + + crit_enter(); TAILQ_FOREACH(ifp, &ifnet, if_link) { if (ifp->if_timer == 0 || --ifp->if_timer) @@ -976,7 +973,9 @@ if_slowtimo(void *arg) if (ifp->if_watchdog) (*ifp->if_watchdog)(ifp); } - splx(s); + + crit_exit(); + callout_reset(&if_slowtimo_timer, hz / IFNET_SLOWHZ, if_slowtimo, NULL); } @@ -1103,14 +1102,14 @@ ifioctl(struct socket *so, u_long cmd, caddr_t data, struct thread *td) /* Smart drivers twiddle their own routes */ } else if (ifp->if_flags & IFF_UP && (new_flags & IFF_UP) == 0) { - int s = splimp(); + crit_enter(); if_down(ifp); - splx(s); + crit_exit(); } else if (new_flags & IFF_UP && (ifp->if_flags & IFF_UP) == 0) { - int s = splimp(); + crit_enter(); if_up(ifp); - splx(s); + crit_exit(); } #ifdef DEVICE_POLLING @@ -1359,9 +1358,9 @@ ifioctl(struct socket *so, u_long cmd, caddr_t data, struct thread *td) #ifdef INET6 DELAY(100);/* XXX: temporary workaround for fxp issue*/ if (ifp->if_flags & IFF_UP) { - int s = splimp(); + crit_enter(); in6_if_up(ifp); - splx(s); + crit_exit(); } #endif } @@ -1516,9 +1515,10 @@ int if_allmulti(struct ifnet *ifp, int onswitch) { int error = 0; - int s = splimp(); struct ifreq ifr; + crit_enter(); + if (onswitch) { if (ifp->if_amcount++ == 0) { ifp->if_flags |= IFF_ALLMULTI; @@ -1539,7 +1539,8 @@ if_allmulti(struct ifnet *ifp, int onswitch) (struct ucred *)NULL); } } - splx(s); + + crit_exit(); if (error == 0) rt_ifmsg(ifp); @@ -1557,7 +1558,7 @@ if_addmulti( struct ifmultiaddr **retifma) { struct sockaddr *llsa, *dupsa; - int error, s; + int error; struct ifmultiaddr *ifma; /* @@ -1600,9 +1601,9 @@ if_addmulti( * Some network interfaces can scan the address list at * interrupt time; lock them out. */ - s = splimp(); + crit_enter(); LIST_INSERT_HEAD(&ifp->if_multiaddrs, ifma, ifma_link); - splx(s); + crit_exit(); *retifma = ifma; if (llsa != 0) { @@ -1621,18 +1622,18 @@ if_addmulti( ifma->ifma_addr = dupsa; ifma->ifma_ifp = ifp; ifma->ifma_refcount = 1; - s = splimp(); + crit_enter(); LIST_INSERT_HEAD(&ifp->if_multiaddrs, ifma, ifma_link); - splx(s); + crit_exit(); } } /* * We are certain we have added something, so call down to the * interface to let them know about it. */ - s = splimp(); + crit_enter(); ifp->if_ioctl(ifp, SIOCADDMULTI, 0, (struct ucred *)NULL); - splx(s); + crit_exit(); return 0; } @@ -1645,7 +1646,6 @@ int if_delmulti(struct ifnet *ifp, struct sockaddr *sa) { struct ifmultiaddr *ifma; - int s; LIST_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) if (sa_equal(sa, ifma->ifma_addr)) @@ -1660,7 +1660,7 @@ if_delmulti(struct ifnet *ifp, struct sockaddr *sa) rt_newmaddrmsg(RTM_DELMADDR, ifma); sa = ifma->ifma_lladdr; - s = splimp(); + crit_enter(); LIST_REMOVE(ifma, ifma_link); /* * Make sure the interface driver is notified @@ -1668,7 +1668,7 @@ if_delmulti(struct ifnet *ifp, struct sockaddr *sa) */ if (ifma->ifma_addr->sa_family == AF_LINK && sa == 0) ifp->if_ioctl(ifp, SIOCDELMULTI, 0, (struct ucred *)NULL); - splx(s); + crit_exit(); free(ifma->ifma_addr, M_IFMADDR); free(ifma, M_IFMADDR); if (sa == 0) @@ -1696,10 +1696,10 @@ if_delmulti(struct ifnet *ifp, struct sockaddr *sa) return 0; } - s = splimp(); + crit_enter(); LIST_REMOVE(ifma, ifma_link); ifp->if_ioctl(ifp, SIOCDELMULTI, 0, (struct ucred *)NULL); - splx(s); + crit_exit(); free(ifma->ifma_addr, M_IFMADDR); free(sa, M_IFMADDR); free(ifma, M_IFMADDR); diff --git a/sys/net/if_atmsubr.c b/sys/net/if_atmsubr.c index c6c5724f09..07fbd6f861 100644 --- a/sys/net/if_atmsubr.c +++ b/sys/net/if_atmsubr.c @@ -32,7 +32,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/net/if_atmsubr.c,v 1.10.2.1 2001/03/06 00:29:26 obrien Exp $ - * $DragonFly: src/sys/net/if_atmsubr.c,v 1.13 2005/05/08 17:52:06 joerg Exp $ + * $DragonFly: src/sys/net/if_atmsubr.c,v 1.14 2005/06/15 19:29:30 joerg Exp $ */ /* @@ -48,6 +48,7 @@ #include #include #include +#include #include #include @@ -232,7 +233,6 @@ atm_input(ifp, ah, m, rxhand) { u_int16_t etype = ETHERTYPE_IP; /* default */ int isr; - int s; if (!(ifp->if_flags & IFF_UP)) { m_freem(m); @@ -243,9 +243,9 @@ atm_input(ifp, ah, m, rxhand) if (rxhand) { #ifdef NATM struct natmpcb *npcb = rxhand; - s = splimp(); /* in case 2 atm cards @ diff lvls */ + crit_enter(); /* in case 2 atm cards @ diff lvls */ npcb->npcb_inq++; /* count # in queue */ - splx(s); + crit_exit(); isr = NETISR_NATM; m->m_pkthdr.rcvif = rxhand; /* XXX: overload */ #else diff --git a/sys/net/if_ethersubr.c b/sys/net/if_ethersubr.c index 1aade03e59..6ab369ede8 100644 --- a/sys/net/if_ethersubr.c +++ b/sys/net/if_ethersubr.c @@ -32,7 +32,7 @@ * * @(#)if_ethersubr.c 8.1 (Berkeley) 6/10/93 * $FreeBSD: src/sys/net/if_ethersubr.c,v 1.70.2.33 2003/04/28 15:45:53 archie Exp $ - * $DragonFly: src/sys/net/if_ethersubr.c,v 1.31 2005/06/03 23:23:03 joerg Exp $ + * $DragonFly: src/sys/net/if_ethersubr.c,v 1.32 2005/06/15 19:29:30 joerg Exp $ */ #include "opt_atalk.h" @@ -364,7 +364,6 @@ ether_output_frame(struct ifnet *ifp, struct mbuf *m) { struct ip_fw *rule = NULL; int error = 0; - int s; struct altq_pktattr pktattr; /* Extract info from dummynet tag, ignore others */ @@ -392,7 +391,7 @@ ether_output_frame(struct ifnet *ifp, struct mbuf *m) no_bridge: if (ifq_is_enabled(&ifp->if_snd)) altq_etherclassify(&ifp->if_snd, m, &pktattr); - s = splimp(); + crit_enter(); if (IPFW_LOADED && ether_ipfw != 0) { struct ether_header save_eh, *eh; @@ -400,6 +399,7 @@ no_bridge: save_eh = *eh; m_adj(m, ETHER_HDR_LEN); if (!ether_ipfw_chk(&m, ifp, &rule, eh, FALSE)) { + crit_exit(); if (m != NULL) { m_freem(m); return ENOBUFS; /* pkt dropped */ @@ -414,8 +414,10 @@ no_bridge: m->m_pkthdr.len += ETHER_HDR_LEN ; } else { M_PREPEND(m, ETHER_HDR_LEN, MB_DONTWAIT); - if (m == NULL) /* nope... */ + if (m == NULL) /* nope... */ { + crit_exit(); return ENOBUFS; + } bcopy(&save_eh, mtod(m, struct ether_header *), ETHER_HDR_LEN); } @@ -426,7 +428,7 @@ no_bridge: * successful, and start output if interface not yet active. */ error = ifq_handoff(ifp, m, &pktattr); - splx(s); + crit_exit(); return (error); } @@ -842,11 +844,9 @@ ether_ifattach_bpf(struct ifnet *ifp, uint8_t *lla, u_int dlt, u_int hdrlen) void ether_ifdetach(struct ifnet *ifp) { - int s; - - s = splnet(); + crit_enter(); if_down(ifp); - splx(s); + crit_exit(); if (ng_ether_detach_p != NULL) (*ng_ether_detach_p)(ifp); diff --git a/sys/net/if_iso88025subr.c b/sys/net/if_iso88025subr.c index 038b593ac1..ccd6f5ff70 100644 --- a/sys/net/if_iso88025subr.c +++ b/sys/net/if_iso88025subr.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/net/if_iso88025subr.c,v 1.7.2.7 2002/06/18 00:15:31 kbyanc Exp $ - * $DragonFly: src/sys/net/Attic/if_iso88025subr.c,v 1.12 2005/06/03 23:23:03 joerg Exp $ + * $DragonFly: src/sys/net/Attic/if_iso88025subr.c,v 1.13 2005/06/15 19:29:30 joerg Exp $ * */ @@ -166,7 +166,7 @@ iso88025_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst, struct iso88025_sockaddr_data *sd = (struct iso88025_sockaddr_data *)dst->sa_data; struct llc *l; struct sockaddr_dl *sdl = NULL; - int s, error = 0, rif_len = 0; + int error = 0, rif_len = 0; u_char edst[6]; struct rtentry *rt; int len = m->m_pkthdr.len, loop_copy = 0; @@ -278,7 +278,7 @@ iso88025_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst, } } - s = splimp(); + crit_enter(); /* * Queue message on interface, and start output if interface * not yet active. @@ -286,7 +286,7 @@ iso88025_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst, if (IF_QFULL(&ifp->if_snd)) { printf("iso88025_output: packet dropped QFULL.\n"); IF_DROP(&ifp->if_snd); - splx(s); + crit_exit(); senderr(ENOBUFS); } if (m->m_flags & M_MCAST) @@ -294,7 +294,7 @@ iso88025_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst, IF_ENQUEUE(&ifp->if_snd, m); if (!(ifp->if_flags & IFF_OACTIVE)) (*ifp->if_start)(ifp); - splx(s); + crit_exit(); ifp->if_obytes += len + ISO88025_HDR_LEN + 8; return (error); diff --git a/sys/net/if_loop.c b/sys/net/if_loop.c index ae7a205a43..0a14afb4d2 100644 --- a/sys/net/if_loop.c +++ b/sys/net/if_loop.c @@ -32,7 +32,7 @@ * * @(#)if_loop.c 8.1 (Berkeley) 6/10/93 * $FreeBSD: src/sys/net/if_loop.c,v 1.47.2.8 2003/06/01 01:46:11 silby Exp $ - * $DragonFly: src/sys/net/if_loop.c,v 1.16 2005/05/05 22:57:45 swildner Exp $ + * $DragonFly: src/sys/net/if_loop.c,v 1.17 2005/06/15 19:29:30 joerg Exp $ */ /* @@ -241,7 +241,7 @@ if_simloop(struct ifnet *ifp, struct mbuf *m, int af, int hlen) if (ifq_is_enabled(&ifp->if_snd) && ifp->if_start == lo_altqstart) { struct altq_pktattr pktattr; int32_t *afp; - int error, s; + int error; /* * if the queueing discipline needs packet classification, @@ -255,10 +255,10 @@ if_simloop(struct ifnet *ifp, struct mbuf *m, int af, int hlen) afp = mtod(m, int32_t *); *afp = (int32_t)af; - s = splimp(); + crit_enter(); error = ifq_enqueue(&ifp->if_snd, m, &pktattr); (*ifp->if_start)(ifp); - splx(s); + crit_exit(); return (error); } #endif /* ALTQ */ @@ -309,12 +309,12 @@ lo_altqstart(struct ifnet *ifp) { struct mbuf *m; int32_t af, *afp; - int s, isr; + int isr; while (1) { - s = splimp(); + crit_enter(); m = ifq_dequeue(&ifp->if_snd); - splx(s); + crit_exit(); if (m == NULL) return; diff --git a/sys/net/if_mib.c b/sys/net/if_mib.c index dbaa5a1862..10d082b181 100644 --- a/sys/net/if_mib.c +++ b/sys/net/if_mib.c @@ -27,7 +27,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/net/if_mib.c,v 1.8.2.1 2000/08/03 00:09:34 ps Exp $ - * $DragonFly: src/sys/net/if_mib.c,v 1.6 2005/06/05 00:25:10 joerg Exp $ + * $DragonFly: src/sys/net/if_mib.c,v 1.7 2005/06/15 19:29:30 joerg Exp $ */ #include @@ -72,7 +72,7 @@ static int sysctl_ifdata(SYSCTL_HANDLER_ARGS) /* XXX bad syntax! */ { int *name = (int *)arg1; - int error, s; + int error; u_int namelen = arg2; struct ifnet *ifp; struct ifmibdata ifmd; @@ -80,15 +80,15 @@ sysctl_ifdata(SYSCTL_HANDLER_ARGS) /* XXX bad syntax! */ if (namelen != 2) return EINVAL; - s = splnet(); + crit_enter(); if (name[0] <= 0 || name[0] > if_index || ifindex2ifnet[name[0]] == NULL) { - splx(s); + crit_exit(); return ENOENT; } ifp = ifindex2ifnet[name[0]]; - splx(s); + crit_exit(); switch(name[1]) { default: diff --git a/sys/net/if_var.h b/sys/net/if_var.h index 851be5517a..9b974bc802 100644 --- a/sys/net/if_var.h +++ b/sys/net/if_var.h @@ -32,7 +32,7 @@ * * From: @(#)if.h 8.1 (Berkeley) 6/10/93 * $FreeBSD: src/sys/net/if_var.h,v 1.18.2.16 2003/04/15 18:11:19 fjoe Exp $ - * $DragonFly: src/sys/net/if_var.h,v 1.29 2005/06/05 12:35:24 joerg Exp $ + * $DragonFly: src/sys/net/if_var.h,v 1.30 2005/06/15 19:29:30 joerg Exp $ */ #ifndef _NET_IF_VAR_H_ @@ -84,6 +84,7 @@ struct ucred; #include #include #include /* XXX */ +#include #endif /* _KERNEL */ #define IF_DUNIT_NONE -1 @@ -276,11 +277,12 @@ if_handoff(struct ifqueue *_ifq, struct mbuf *_m, struct ifnet *_ifp, int _adjust) { int _need_if_start = 0; - int _s = splimp(); - + + crit_enter(); + if (IF_QFULL(_ifq)) { IF_DROP(_ifq); - splx(_s); + crit_exit(); m_freem(_m); return (0); } @@ -293,7 +295,7 @@ if_handoff(struct ifqueue *_ifq, struct mbuf *_m, struct ifnet *_ifp, IF_ENQUEUE(_ifq, _m); if (_need_if_start) (*_ifp->if_start)(_ifp); - splx(_s); + crit_exit(); return (1); } diff --git a/sys/net/ifq_var.h b/sys/net/ifq_var.h index c1c50b8f50..d3ede42d71 100644 --- a/sys/net/ifq_var.h +++ b/sys/net/ifq_var.h @@ -28,11 +28,13 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sys/net/ifq_var.h,v 1.3 2005/04/04 17:08:16 joerg Exp $ + * $DragonFly: src/sys/net/ifq_var.h,v 1.4 2005/06/15 19:29:30 joerg Exp $ */ #ifndef _NET_IFQ_VAR_H #define _NET_IFQ_VAR_H +#include + #ifdef ALTQ static __inline int ifq_is_enabled(struct ifaltq *_ifq) @@ -118,9 +120,9 @@ ifq_classify(struct ifaltq *_ifq, struct mbuf *_m, uint8_t _af, static __inline int ifq_handoff(struct ifnet *_ifp, struct mbuf *_m, struct altq_pktattr *_pa) { - int _error, _s; + int _error; - _s = splimp(); + crit_enter(); _error = ifq_enqueue(&_ifp->if_snd, _m, _pa); if (_error == 0) { _ifp->if_obytes += _m->m_pkthdr.len; @@ -129,7 +131,7 @@ ifq_handoff(struct ifnet *_ifp, struct mbuf *_m, struct altq_pktattr *_pa) if ((_ifp->if_flags & IFF_OACTIVE) == 0) (*_ifp->if_start)(_ifp); } - splx(_s); + crit_exit(); return(_error); } diff --git a/sys/net/intrq.c b/sys/net/intrq.c index 1083c2281d..a4f9ccf271 100644 --- a/sys/net/intrq.c +++ b/sys/net/intrq.c @@ -24,13 +24,14 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/net/intrq.c,v 1.3 2000/01/29 16:13:08 peter Exp $ - * $DragonFly: src/sys/net/Attic/intrq.c,v 1.4 2003/09/15 23:38:13 hsu Exp $ + * $DragonFly: src/sys/net/Attic/intrq.c,v 1.5 2005/06/15 19:29:30 joerg Exp $ */ #include #include #include #include +#include #include #include @@ -98,15 +99,15 @@ family_enqueue(family, m) for (entry = 0; entry < sizeof queue / sizeof queue[0]; entry++) if (queue[entry].family == family) { if (queue[entry].present) { - s = splimp(); + crit_enter(); if (IF_QFULL(queue[entry].q)) { IF_DROP(queue[entry].q); - splx(s); + crit_exit(); m_freem(m); return ENOBUFS; } IF_ENQUEUE(queue[entry].q, m); - splx(s); + crit_exit(); schednetisr(queue[entry].isr); return 0; } else diff --git a/sys/net/route.c b/sys/net/route.c index c4da53f8bf..59b49648ef 100644 --- a/sys/net/route.c +++ b/sys/net/route.c @@ -82,7 +82,7 @@ * * @(#)route.c 8.3 (Berkeley) 1/9/95 * $FreeBSD: src/sys/net/route.c,v 1.59.2.10 2003/01/17 08:04:00 ru Exp $ - * $DragonFly: src/sys/net/route.c,v 1.21 2005/05/02 00:56:48 y0netan1 Exp $ + * $DragonFly: src/sys/net/route.c,v 1.22 2005/06/15 19:29:30 joerg Exp $ */ #include "opt_inet.h" @@ -97,6 +97,7 @@ #include #include #include +#include #include #include @@ -557,11 +558,10 @@ rtrequest1(int req, struct rt_addrinfo *rtinfo, struct rtentry **ret_nrt) struct ifaddr *ifa; struct sockaddr *ndst; int error = 0; - int s; #define gotoerr(x) { error = x ; goto bad; } - s = splnet(); + crit_enter(); /* * Find the correct routing tree to use for this Address Family */ @@ -767,7 +767,7 @@ makeroute: error = EOPNOTSUPP; } bad: - splx(s); + crit_exit(); return (error); } -- 2.41.0