]> git.saurik.com Git - apple/xnu.git/blobdiff - bsd/net/radix.c
xnu-792.17.14.tar.gz
[apple/xnu.git] / bsd / net / radix.c
index 1fb667e17e234861b5c4da5ca2c9f96a2aad0921..ace852581da0bb921cfef41e6cf5277004fd1e58 100644 (file)
@@ -1,16 +1,19 @@
 /*
  * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
  *
- * @APPLE_LICENSE_HEADER_START@
- * 
- * Copyright (c) 1999-2003 Apple Computer, Inc.  All Rights Reserved.
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
  * 
  * 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. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * 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
@@ -20,7 +23,7 @@
  * Please see the License for the specific language governing rights and
  * limitations under the License.
  * 
- * @APPLE_LICENSE_HEADER_END@
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
  */
 /*
  * Copyright (c) 1988, 1989, 1993
 #endif
 #include <sys/syslog.h>
 #include <net/radix.h>
+#include <sys/socket.h>
+#include <sys/socketvar.h>
+#include <kern/locks.h>
 #endif
 
-static int     rn_walktree_from __P((struct radix_node_head *h, void *a,
-                                     void *m, walktree_f_t *f, void *w));
-static int rn_walktree __P((struct radix_node_head *, walktree_f_t *, void *));
+static int     rn_walktree_from(struct radix_node_head *h, void *a,
+                                     void *m, walktree_f_t *f, void *w);
+static int rn_walktree(struct radix_node_head *, walktree_f_t *, void *);
 static struct radix_node
-        *rn_insert __P((void *, struct radix_node_head *, int *,
-                       struct radix_node [2])),
-        *rn_newpair __P((void *, int, struct radix_node[2])),
-        *rn_search __P((void *, struct radix_node *)),
-        *rn_search_m __P((void *, struct radix_node *, void *));
+        *rn_insert(void *, struct radix_node_head *, int *,
+                       struct radix_node [2]),
+        *rn_newpair(void *, int, struct radix_node[2]),
+        *rn_search(void *, struct radix_node *),
+        *rn_search_m(void *, struct radix_node *, void *);
 
 static int     max_keylen;
 static struct radix_mask *rn_mkfreelist;
@@ -92,17 +98,22 @@ static char *addmask_key;
 static char normal_chars[] = {0, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, -1};
 static char *rn_zeros, *rn_ones;
 
+
+extern lck_grp_t       *domain_proto_mtx_grp;
+extern lck_attr_t      *domain_proto_mtx_attr;
+lck_mtx_t *rn_mutex;
+
 #define rn_masktop (mask_rnhead->rnh_treetop)
 #undef Bcmp
 #define Bcmp(a, b, l) \
        (l == 0 ? 0 : bcmp((caddr_t)(a), (caddr_t)(b), (u_long)l))
 
-static int     rn_lexobetter __P((void *m_arg, void *n_arg));
+static int     rn_lexobetter(void *m_arg, void *n_arg);
 static struct radix_mask *
-               rn_new_radix_mask __P((struct radix_node *tt,
-                                      struct radix_mask *next));
-static int     rn_satsifies_leaf __P((char *trial, struct radix_node *leaf,
-                                      int skip));
+               rn_new_radix_mask(struct radix_node *tt,
+                                      struct radix_mask *next);
+static int     rn_satsifies_leaf(char *trial, struct radix_node *leaf,
+                                      int skip);
 
 /*
  * The data structure for the keys is a radix tree with one way
@@ -499,7 +510,7 @@ rn_addmask(n_arg, search, skip)
        x = rn_insert(cp, mask_rnhead, &maskduplicated, x);
        if (maskduplicated) {
                log(LOG_ERR, "rn_addmask: mask impossibly already in tree");
-               Free(saved_x);
+               R_Free(saved_x);
                return (x);
        }
        /*
@@ -1087,6 +1098,7 @@ rn_init()
 #ifdef KERNEL
        struct domain *dom;
 
+       /* lock already held when rn_init is called */
        for (dom = domains; dom; dom = dom->dom_next)
                if (dom->dom_maxrtkey > max_keylen)
                        max_keylen = dom->dom_maxrtkey;
@@ -1106,4 +1118,41 @@ rn_init()
                *cp++ = -1;
        if (rn_inithead((void **)&mask_rnhead, 0) == 0)
                panic("rn_init 2");
+
+       rn_mutex = lck_mtx_alloc_init(domain_proto_mtx_grp, domain_proto_mtx_attr);
+}
+int
+rn_lock(so, refcount, lr)
+       struct socket *so;
+       int refcount;
+       int lr;
+{
+//     printf("rn_lock: (global) so=%x ref=%d lr=%x\n", so, so->so_usecount, lr);
+       lck_mtx_assert(rn_mutex, LCK_MTX_ASSERT_NOTOWNED);
+       lck_mtx_lock(rn_mutex);
+       if (refcount)
+               so->so_usecount++;
+       return (0);
+}
+
+int
+rn_unlock(so, refcount, lr)
+       struct socket *so;
+       int refcount;
+       int lr;
+{
+//     printf("rn_unlock: (global) so=%x ref=%d lr=%x\n", so, so->so_usecount, lr);
+       if (refcount)
+               so->so_usecount--;
+       lck_mtx_assert(rn_mutex, LCK_MTX_ASSERT_OWNED);
+       lck_mtx_unlock(rn_mutex);
+       return (0);
+}
+lck_mtx_t *
+rn_getlock(so, locktype)
+       struct socket *so;
+       int locktype;
+{
+//     printf("rn_getlock: (global) so=%x\n", so);
+       return (rn_mutex);
 }