X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/4452a7af2eac33dbad800bcc91f2399d62c18f53..6601e61aa18bf4f09af135ff61fc7f4771d23b06:/bsd/net/route.c diff --git a/bsd/net/route.c b/bsd/net/route.c index 7bb3d89be..aaa13c7b8 100644 --- a/bsd/net/route.c +++ b/bsd/net/route.c @@ -1,29 +1,23 @@ /* * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. * - * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ + * @APPLE_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. 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. + * 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. * - * 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 + * 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, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. * - * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ + * @APPLE_LICENSE_HEADER_END@ */ /* * Copyright (c) 1980, 1986, 1991, 1993 @@ -69,6 +63,7 @@ #include #include #include +#include #include #include @@ -93,9 +88,15 @@ lck_grp_attr_t *rt_mtx_grp_attr; lck_mtx_t *route_domain_mtx; /*### global routing tables mutex for now */ __private_extern__ int rttrash = 0; /* routes not in table but not freed */ +static struct zone *rte_zone; /* special zone for rtentry */ +#define RTE_ZONE_MAX 65536 /* maximum elements in zone */ +#define RTE_ZONE_NAME "rtentry" /* name of rtentry zone */ + static void rt_maskedcopy(struct sockaddr *, struct sockaddr *, struct sockaddr *); static void rtable_init(void **); +static struct rtentry *rte_alloc(void); +static void rte_free(struct rtentry *); __private_extern__ u_long route_generation = 0; extern int use_routegenid; @@ -117,10 +118,14 @@ route_init() { rt_mtx_grp_attr = lck_grp_attr_alloc_init(); + lck_grp_attr_setdefault(rt_mtx_grp_attr); + rt_mtx_grp = lck_grp_alloc_init("route", rt_mtx_grp_attr); rt_mtx_attr = lck_attr_alloc_init(); + lck_attr_setdefault(rt_mtx_attr); + if ((rt_mtx = lck_mtx_alloc_init(rt_mtx_grp, rt_mtx_attr)) == NULL) { printf("route_init: can't alloc rt_mtx\n"); return; @@ -131,6 +136,13 @@ route_init() lck_mtx_unlock(rt_mtx); rtable_init((void **)rt_tables); route_domain_mtx = routedomain.dom_mtx; + + rte_zone = zinit(sizeof (struct rtentry), + RTE_ZONE_MAX * sizeof (struct rtentry), 0, RTE_ZONE_NAME); + if (rte_zone == NULL) + panic("route_init: failed allocating rte_zone"); + + zone_change(rte_zone, Z_EXPAND, TRUE); } /* @@ -338,7 +350,7 @@ rtfree_locked(rt) /* * and the rtentry itself of course */ - R_Free(rt); + rte_free(rt); } } @@ -760,8 +772,7 @@ rtrequest_locked( senderr(ENETUNREACH); makeroute: - R_Malloc(rt, struct rtentry *, sizeof(*rt)); - if (rt == 0) + if ((rt = rte_alloc()) == NULL) senderr(ENOBUFS); Bzero(rt, sizeof(*rt)); rt->rt_flags = RTF_UP | flags; @@ -770,7 +781,7 @@ rtrequest_locked( * also add the rt_gwroute if possible. */ if ((error = rt_setgate(rt, dst, gateway)) != 0) { - R_Free(rt); + rte_free(rt); senderr(error); } @@ -835,7 +846,7 @@ rtrequest_locked( ifafree(rt->rt_ifa); } R_Free(rt_key(rt)); - R_Free(rt); + rte_free(rt); senderr(EEXIST); } @@ -1340,3 +1351,19 @@ rtinit_locked(ifa, cmd, flags) } return (error); } + +static struct rtentry * +rte_alloc(void) +{ + return ((struct rtentry *)zalloc(rte_zone)); +} + +static void +rte_free(struct rtentry *p) +{ + if (p->rt_refcnt != 0) + panic("rte_free: rte=%p refcnt=%d non-zero\n", p, p->rt_refcnt); + + bzero((caddr_t)p, sizeof (*p)); + zfree(rte_zone, p); +}