]> git.saurik.com Git - apple/xnu.git/blobdiff - bsd/netat/ddp_nbp.c
xnu-792.12.6.tar.gz
[apple/xnu.git] / bsd / netat / ddp_nbp.c
index dabcee8c527778575238ff2ddf5a6c661f444714..f959f6b57c954ccefc5c9704137f125e1cfbcfae 100644 (file)
@@ -1,23 +1,31 @@
 /*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
- *
- * @APPLE_LICENSE_HEADER_START@
- * 
- * The contents of this file constitute Original Code as defined in and
- * are subject to the Apple Public Source License Version 1.1 (the
- * "License").  You may not use this file except in compliance with the
- * License.  Please obtain a copy of the License at
- * http://www.apple.com/publicsource and read it before using this file.
+ * Copyright (c) 2006 Apple Computer, Inc. All Rights Reserved.
  * 
- * This Original Code and all software distributed under the License are
- * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
- * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
- * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
- * License for the specific language governing rights and limitations
- * under the License.
+ * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
  * 
- * @APPLE_LICENSE_HEADER_END@
+ * This file contains Original Code and/or Modifications of Original Code 
+ * as defined in and that are subject to the Apple Public Source License 
+ * Version 2.0 (the 'License'). You may not use this file except in 
+ * compliance with the License.  The rights granted to you under the 
+ * License may not be used to create, or enable the creation or 
+ * redistribution of, unlawful or unlicensed copies of an Apple operating 
+ * system, or to circumvent, violate, or enable the circumvention or 
+ * violation of, any terms of an Apple operating system software license 
+ * agreement.
+ *
+ * Please obtain a copy of the License at 
+ * http://www.opensource.apple.com/apsl/ and read it before using this 
+ * file.
+ *
+ * The Original Code and all software distributed under the License are 
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 
+ * Please see the License for the specific language governing rights and 
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
  */
 /*
  *     Copyright (c) 1988, 1989, 1997, 1998 Apple Computer, Inc. 
@@ -76,6 +84,7 @@ extern at_ifaddr_t *ifID_home;
 
 TAILQ_HEAD(name_registry, _nve_) name_registry;
 
+atlock_t       nve_lock;
 
 /* statics */
 static int             errno;
@@ -116,12 +125,14 @@ void nbp_shutdown()
        /* delete all NVE's and release buffers */
        register nve_entry_t    *nve_entry, *nve_next;
 
-       for ((nve_entry = TAILQ_FIRST(&name_registry)); nve_entry; nve_entry = nve_next) {
-                       nve_next = TAILQ_NEXT(nve_entry, nve_link);
+       ATDISABLE(nve_lock_pri,NVE_LOCK);
+        for ((nve_entry = TAILQ_FIRST(&name_registry)); nve_entry; nve_entry = nve_next) {
+                nve_next = TAILQ_NEXT(nve_entry, nve_link);
 
                 /* NB: nbp_delete_entry calls TAILQ_REMOVE */
                nbp_delete_entry(nve_entry);
        }
+       ATENABLE(nve_lock_pri,NVE_LOCK);
 
        if (lzones) {
                gbuf_freem(lzones);
@@ -400,7 +411,7 @@ void nbp_input(m, ifID)
                                   ("nbp_input: BRREQ: src changed to %d.%d.%d\n",
                                        ifID->ifThisNode.s_net,
                                        ifID->ifThisNode.s_node, ourSkt));
-                               nbp->tuple[0].enu_addr.net = htons(ifID->ifThisNode.s_net);
+                               nbp->tuple[0].enu_addr.net = ifID->ifThisNode.s_net;
                                nbp->tuple[0].enu_addr.node = ifID->ifThisNode.s_node;
                                nbp->tuple[0].enu_addr.socket = ourSkt; 
                                ddp->src_socket = NBP_SOCKET;
@@ -496,7 +507,7 @@ static      int     nbp_validate_n_hash (nbp_req, wild_ok, checkLocal)
 #ifdef COMMENTED_OUT
        {
                int net,node,skt;
-               net = ntohs(tuple->enu_addr.net);
+               net = tuple->enu_addr.net;
                node = tuple->enu_addr.node;
                skt = tuple->enu_addr.socket;
                dPrintf(D_M_NBP_LOW,D_L_USR4,
@@ -711,6 +722,7 @@ static      nve_entry_t *nbp_search_nve (nbp_req, ifID)
                                (u_int) nbp_req->response));
        }
 #endif /* NBP_DEBUG */
+       ATDISABLE(nve_lock_pri,NVE_LOCK);
        TAILQ_FOREACH(nve_entry, &name_registry, nve_link) {
                if ((nbp_req->nve.zone_hash) && 
                        ((nbp_req->nve.zone_hash != 
@@ -796,11 +808,15 @@ static    nve_entry_t *nbp_search_nve (nbp_req, ifID)
                if (nbp_req->func != NULL) {
                        if ((*(nbp_req->func))(nbp_req, nve_entry) != 0) {
                                /* errno expected to be set by func */
+                               ATENABLE(nve_lock_pri,NVE_LOCK);
                                return (NULL);
                        }
-               } else
+               } else {
+                       ATENABLE(nve_lock_pri,NVE_LOCK);
                        return (nve_entry);
+               }
        }
+       ATENABLE(nve_lock_pri,NVE_LOCK);
 
        errno = 0;
        return (NULL);
@@ -840,9 +856,7 @@ register nve_entry_t        *nve_entry;
         * tuple we want to write. Write it!
         */
        tuple = (at_nbptuple_t *)gbuf_wptr(nbp_req->response);
-       tuple->enu_addr.net = htons(nve_entry->address.net);
-       tuple->enu_addr.node = nve_entry->address.node;
-       tuple->enu_addr.socket = nve_entry->address.socket;
+       tuple->enu_addr = nve_entry->address;
        tuple->enu_enum = nve_entry->enumerator;
 
         /* tuple is in the compressed (no "filler") format */
@@ -963,7 +977,7 @@ register nbp_req_t  *nbp_req;
        case NBP_LKUP :
                ddp->dst_socket = nbp_req->nve.address.socket;
                ddp->dst_node = nbp_req->nve.address.node;
-               NET_ASSIGN_NOSWAP(ddp->dst_net, nbp_req->nve.address.net);
+               NET_ASSIGN(ddp->dst_net, nbp_req->nve.address.net);
                nbp->control = NBP_LKUP_REPLY;
                break;
        }
@@ -1041,8 +1055,10 @@ getNbpTableSize()
        register nve_entry_t *nve;
        register int i=0;
 
+       ATDISABLE(nve_lock_pri,NVE_LOCK);
        for (nve = TAILQ_FIRST(&name_registry); nve; nve = TAILQ_NEXT(nve, nve_link), i++)
                i++;
+       ATENABLE(nve_lock_pri,NVE_LOCK);
        return(i);
 }
 
@@ -1065,6 +1081,7 @@ getNbpTable(p, s, c)
        else
                nve = TAILQ_FIRST(&name_registry);
 
+       ATDISABLE(nve_lock_pri,NVE_LOCK);
        for ( ; nve && c ; nve = TAILQ_NEXT(nve, nve_link), p++,i++) {
                if (i>= s) {
                        p->nbpe_object = nve->object;
@@ -1072,6 +1089,7 @@ getNbpTable(p, s, c)
                        c--;
                }
        }
+       ATENABLE(nve_lock_pri,NVE_LOCK);
        if (nve) {
                next = nve;
                nextNo = i;
@@ -1313,6 +1331,7 @@ nve_entry_t *nbp_find_nve(nve)
 {
        register nve_entry_t    *nve_entry;
 
+       ATDISABLE(nve_lock_pri,NVE_LOCK);
        TAILQ_FOREACH(nve_entry, &name_registry, nve_link) {
                if (nve->zone_hash &&
                    ((nve->zone_hash != nve_entry->zone_hash) &&
@@ -1332,8 +1351,10 @@ nve_entry_t *nbp_find_nve(nve)
                        continue;
 
                /* Found a match! */
+               ATENABLE(nve_lock_pri,NVE_LOCK);
                return (nve_entry);
        }
+       ATENABLE(nve_lock_pri,NVE_LOCK);
 
        return (NULL);
 } /* nbp_find_nve */
@@ -1344,19 +1365,22 @@ static int nbp_enum_gen (nve_entry)
        register int            new_enum = 0;
        register nve_entry_t    *ne;
 
+       ATDISABLE(nve_lock_pri,NVE_LOCK);
 re_do:
        TAILQ_FOREACH(ne, &name_registry, nve_link) {
                if ((*(int *)&ne->address == *(int *)&nve_entry->address) &&
                        (ne->enumerator == new_enum)) {
-                       if (new_enum == 255)
+                       if (new_enum == 255) {
+                               ATENABLE(nve_lock_pri,NVE_LOCK);
                                return(EADDRNOTAVAIL);
-                       else {
+                       else {
                                new_enum++;
                                goto re_do;
                        }
                }
        }
 
+       ATENABLE(nve_lock_pri,NVE_LOCK);
        nve_entry->enumerator = new_enum;
        return (0);
 }
@@ -1409,7 +1433,9 @@ int nbp_new_nve_entry(nve_entry, ifID)
        new_entry->tag = tag;
        new_entry->pid =  proc_selfpid();
 
+       ATDISABLE(nve_lock_pri,NVE_LOCK);
        TAILQ_INSERT_TAIL(&name_registry, new_entry, nve_link);
+       ATENABLE(nve_lock_pri,NVE_LOCK);
        at_state.flags |= AT_ST_NBP_CHANGED;
 
 #ifdef NBP_DEBUG