ifnet: Make rest of ifnet accessing MPSAFE
authorSepherosa Ziehau <sephe@dragonflybsd.org>
Mon, 2 Mar 2015 14:36:36 +0000 (22:36 +0800)
committerSepherosa Ziehau <sephe@dragonflybsd.org>
Tue, 3 Mar 2015 00:55:17 +0000 (08:55 +0800)
sys/netgraph7/ether/ng_ether.c
sys/netgraph7/ng_gif.c
sys/netproto/ipsec/xform_ipip.c
sys/platform/pc32/i386/autoconf.c
sys/platform/vkernel/i386/autoconf.c
sys/platform/vkernel64/x86_64/autoconf.c
sys/vfs/nfs/bootp_subr.c

index 9c6cfdc..a4614b2 100644 (file)
@@ -752,13 +752,13 @@ ng_ether_mod_event(module_t mod, int event, void *data)
 #endif
 
                /* Create nodes for any already-existing Ethernet interfaces */
-               IFNET_RLOCK();
-               TAILQ_FOREACH(ifp, &ifnet, if_link) {
+               ifnet_lock();
+               TAILQ_FOREACH(ifp, &ifnetlist, if_link) {
                        if (ifp->if_type == IFT_ETHER
                            || ifp->if_type == IFT_L2VLAN)
                                ng_ether_attach(ifp);
                }
-               IFNET_RUNLOCK();
+               ifnet_unlock();
                break;
 
        case MOD_UNLOAD:
index e15d16d..7dad4a4 100644 (file)
@@ -560,12 +560,12 @@ ng_gif_mod_event(module_t mod, int event, void *data)
                ng_gif_input_orphan_p = ng_gif_input_orphan;
 
                /* Create nodes for any already-existing gif interfaces */
-               IFNET_RLOCK();
-               TAILQ_FOREACH(ifp, &ifnet, if_link) {
+               ifnet_lock();
+               TAILQ_FOREACH(ifp, &ifnetlist, if_link) {
                        if (ifp->if_type == IFT_GIF)
                                ng_gif_attach(ifp);
                }
-               IFNET_RUNLOCK();
+               ifnet_unlock();
                break;
 
        case MOD_UNLOAD:
index 9a5d23c..204b77a 100644 (file)
@@ -158,7 +158,6 @@ static void
 _ipip_input(struct mbuf *m, int iphlen, struct ifnet *gifp)
 {
        struct sockaddr_in *sin;
-       struct ifnet *ifp;
        struct ifaddr *ifa;
        struct ip *ipo;
 #ifdef INET6
@@ -307,8 +306,14 @@ _ipip_input(struct mbuf *m, int iphlen, struct ifnet *gifp)
        if ((m->m_pkthdr.rcvif == NULL ||
            !(m->m_pkthdr.rcvif->if_flags & IFF_LOOPBACK)) &&
            ipip_allow != 2) {
-               TAILQ_FOREACH(ifp, &ifnet, if_link) {
+               struct ifnet_array *arr;
+               int i;
+
+               arr = ifnet_array_get();
+               for (i = 0; i < arr->ifnet_count; ++i) {
+                       struct ifnet *ifp = arr->ifnet_arr[i];
                        struct ifaddr_container *ifac;
+
                        TAILQ_FOREACH(ifac, &ifp->if_addrheads[mycpuid], ifa_link) {
                                ifa = ifac->ifa;
 #ifdef INET
index 27a2630..c4d5d52 100644 (file)
@@ -435,7 +435,8 @@ pxe_setup_nfsdiskless(void)
                kprintf("PXE: no hardware address\n");
                return;
        }
-       TAILQ_FOREACH(ifp, &ifnet, if_link) {
+       ifnet_lock();
+       TAILQ_FOREACH(ifp, &ifnetlist, if_link) {
                struct ifaddr_container *ifac;
 
                TAILQ_FOREACH(ifac, &ifp->if_addrheads[mycpuid], ifa_link) {
@@ -447,16 +448,20 @@ pxe_setup_nfsdiskless(void)
                                    (sdl->sdl_alen == ourdl.sdl_alen) &&
                                    !bcmp(sdl->sdl_data + sdl->sdl_nlen,
                                          ourdl.sdl_data + ourdl.sdl_nlen, 
-                                         sdl->sdl_alen))
-                                   goto match_done;
+                                         sdl->sdl_alen)) {
+                                       strlcpy(nd->myif.ifra_name,
+                                           ifp->if_xname,
+                                           sizeof(nd->myif.ifra_name));
+                                       ifnet_unlock();
+                                       goto match_done;
+                               }
                        }
                }
        }
+       ifnet_unlock();
        kprintf("PXE: no interface\n");
        return; /* no matching interface */
 match_done:
-       strlcpy(nd->myif.ifra_name, ifp->if_xname, sizeof(nd->myif.ifra_name));
-       
        /* set up gateway */
        inaddr_to_sockaddr("boot.netif.gateway", &nd->mygateway);
 
index fa9d092..c8a3cd7 100644 (file)
@@ -481,12 +481,15 @@ pxe_setup_nfsdiskless(void)
        bcopy(&netmask, &nd->myif.ifra_mask, sizeof(netmask));
 
        if ((cp = kgetenv("boot.netif.name")) != NULL) {
-               TAILQ_FOREACH(ifp, &ifnet, if_link) {
-                       if (strcmp(cp, ifp->if_xname) == 0)
-                               break;
-               }
-               if (ifp)
+               ifnet_lock();
+               ifp = ifunit(cp);
+               if (ifp) {
+                       strlcpy(nd->myif.ifra_name, ifp->if_xname,
+                           sizeof(nd->myif.ifra_name));
+                       ifnet_unlock();
                        goto match_done;
+               }
+               ifnet_unlock();
                kprintf("PXE: cannot find interface %s\n", cp);
                return;
        }
@@ -496,7 +499,8 @@ pxe_setup_nfsdiskless(void)
                return;
        }
        ifa = NULL;
-       TAILQ_FOREACH(ifp, &ifnet, if_link) {
+       ifnet_lock();
+       TAILQ_FOREACH(ifp, &ifnetlist, if_link) {
                struct ifaddr_container *ifac;
 
                TAILQ_FOREACH(ifac, &ifp->if_addrheads[mycpuid], ifa_link) {
@@ -508,16 +512,20 @@ pxe_setup_nfsdiskless(void)
                                    (sdl->sdl_alen == ourdl.sdl_alen) &&
                                    !bcmp(sdl->sdl_data + sdl->sdl_nlen,
                                          ourdl.sdl_data + ourdl.sdl_nlen, 
-                                         sdl->sdl_alen))
-                                   goto match_done;
+                                         sdl->sdl_alen)) {
+                                       strlcpy(nd->myif.ifra_name,
+                                           ifp->if_xname,
+                                           sizeof(nd->myif.ifra_name));
+                                       ifnet_unlock();
+                                       goto match_done;
+                               }
                        }
                }
        }
+       ifnet_unlock();
        kprintf("PXE: no interface\n");
        return; /* no matching interface */
 match_done:
-       strlcpy(nd->myif.ifra_name, ifp->if_xname, sizeof(nd->myif.ifra_name));
-       
        /* set up gateway */
        inaddr_to_sockaddr("boot.netif.gateway", &nd->mygateway);
 
index 5d605cd..dcff982 100644 (file)
@@ -478,12 +478,15 @@ pxe_setup_nfsdiskless(void)
        bcopy(&netmask, &nd->myif.ifra_mask, sizeof(netmask));
 
        if ((cp = kgetenv("boot.netif.name")) != NULL) {
-               TAILQ_FOREACH(ifp, &ifnet, if_link) {
-                       if (strcmp(cp, ifp->if_xname) == 0)
-                               break;
-               }
-               if (ifp)
+               ifnet_lock();
+               ifp = ifunit(cp);
+               if (ifp) {
+                       strlcpy(nd->myif.ifra_name, ifp->if_xname,
+                           sizeof(nd->myif.ifra_name));
+                       ifnet_unlock();
                        goto match_done;
+               }
+               ifnet_unlock();
                kprintf("PXE: cannot find interface %s\n", cp);
                return;
        }
@@ -493,7 +496,8 @@ pxe_setup_nfsdiskless(void)
                return;
        }
        ifa = NULL;
-       TAILQ_FOREACH(ifp, &ifnet, if_link) {
+       ifnet_lock();
+       TAILQ_FOREACH(ifp, &ifnetlist, if_link) {
                struct ifaddr_container *ifac;
 
                TAILQ_FOREACH(ifac, &ifp->if_addrheads[mycpuid], ifa_link) {
@@ -505,16 +509,20 @@ pxe_setup_nfsdiskless(void)
                                    (sdl->sdl_alen == ourdl.sdl_alen) &&
                                    !bcmp(sdl->sdl_data + sdl->sdl_nlen,
                                          ourdl.sdl_data + ourdl.sdl_nlen,
-                                         sdl->sdl_alen))
-                                   goto match_done;
+                                         sdl->sdl_alen)) {
+                                       strlcpy(nd->myif.ifra_name,
+                                           ifp->if_xname,
+                                           sizeof(nd->myif.ifra_name));
+                                       ifnet_unlock();
+                                       goto match_done;
+                               }
                        }
                }
        }
+       ifnet_unlock();
        kprintf("PXE: no interface\n");
        return; /* no matching interface */
 match_done:
-       strlcpy(nd->myif.ifra_name, ifp->if_xname, sizeof(nd->myif.ifra_name));
-
        /* set up gateway */
        inaddr_to_sockaddr("boot.netif.gateway", &nd->mygateway);
 
index 9ac8a23..8f30ca5 100644 (file)
@@ -393,7 +393,8 @@ bootpboot_p_iflist(void)
        struct ifaddr_container *ifac;
        
        kprintf("Interface list:\n");
-       TAILQ_FOREACH(ifp, &ifnet, if_link) {
+       ifnet_lock();
+       TAILQ_FOREACH(ifp, &ifnetlist, if_link) {
                TAILQ_FOREACH(ifac, &ifp->if_addrheads[mycpuid], ifa_link) {
                        struct ifaddr *ifa = ifac->ifa;
 
@@ -401,6 +402,7 @@ bootpboot_p_iflist(void)
                                bootpboot_p_if(ifp, ifa);
                }
        }
+       ifnet_unlock();
 }
 #endif /* defined(BOOTP_DEBUG) */