1/* 2 * Copyright (c) 1980, 1986, 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 13 unchanged lines hidden (view full) --- 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * 29 * @(#)route.c 8.3.1.1 (Berkeley) 2/23/95 |
30 * $FreeBSD: head/sys/net/route.c 133513 2004-08-11 17:26:56Z andre $ |
31 */ 32 33#include "opt_inet.h" 34#include "opt_mrouting.h" 35 36#include <sys/param.h> 37#include <sys/systm.h> 38#include <sys/malloc.h> 39#include <sys/mbuf.h> 40#include <sys/socket.h> 41#include <sys/domain.h> 42#include <sys/kernel.h> 43 44#include <net/if.h> 45#include <net/route.h> 46 47#include <netinet/in.h> 48#include <netinet/ip_mroute.h> 49 |
50#include <vm/uma.h> 51 |
52static struct rtstat rtstat; 53struct radix_node_head *rt_tables[AF_MAX+1]; 54 55static int rttrash; /* routes not in table but not freed */ 56 57static void rt_maskedcopy(struct sockaddr *, 58 struct sockaddr *, struct sockaddr *); 59static void rtable_init(void **); --- 18 unchanged lines hidden (view full) --- 78{ 79 struct domain *dom; 80 for (dom = domains; dom; dom = dom->dom_next) 81 if (dom->dom_rtattach) 82 dom->dom_rtattach(&table[dom->dom_family], 83 dom->dom_rtoffset); 84} 85 |
86static uma_zone_t rtzone; /* Routing table UMA zone. */ 87 |
88static void 89route_init(void) 90{ |
91 rtzone = uma_zcreate("rtentry", sizeof(struct rtentry), NULL, NULL, 92 NULL, NULL, UMA_ALIGN_PTR, 0); |
93 rn_init(); /* initialize all zeroes, all ones, mask table */ 94 rtable_init((void **)rt_tables); 95} 96 97/* 98 * Packet routing routines. 99 */ 100void --- 192 unchanged lines hidden (view full) --- 293 * together. 294 */ 295 Free(rt_key(rt)); 296 297 /* 298 * and the rtentry itself of course 299 */ 300 RT_LOCK_DESTROY(rt); |
301 uma_zfree(rtzone, rt); |
302 return; 303 } 304done: 305 RT_UNLOCK(rt); 306} 307 308 309/* --- 429 unchanged lines hidden (view full) --- 739 if ((flags & RTF_GATEWAY) && !gateway) 740 panic("rtrequest: GATEWAY but no gateway"); 741 742 if (info->rti_ifa == NULL && (error = rt_getifa(info))) 743 senderr(error); 744 ifa = info->rti_ifa; 745 746 makeroute: |
747 rt = uma_zalloc(rtzone, M_NOWAIT | M_ZERO); |
748 if (rt == NULL) 749 senderr(ENOBUFS); 750 RT_LOCK_INIT(rt); 751 rt->rt_flags = RTF_UP | flags; 752 /* 753 * Add the gateway. Possibly re-malloc-ing the storage for it 754 * also add the rt_gwroute if possible. 755 */ 756 RT_LOCK(rt); 757 if ((error = rt_setgate(rt, dst, gateway)) != 0) { 758 RT_LOCK_DESTROY(rt); |
759 uma_zfree(rtzone, rt); |
760 senderr(error); 761 } 762 763 /* 764 * point to the (possibly newly malloc'd) dest address. 765 */ 766 ndst = (struct sockaddr *)rt_key(rt); 767 --- 43 unchanged lines hidden (view full) --- 811 */ 812 if (rn == NULL) { 813 if (rt->rt_gwroute) 814 RTFREE(rt->rt_gwroute); 815 if (rt->rt_ifa) 816 IFAFREE(rt->rt_ifa); 817 Free(rt_key(rt)); 818 RT_LOCK_DESTROY(rt); |
819 uma_zfree(rtzone, rt); |
820 senderr(EEXIST); 821 } 822 823 rt->rt_parent = NULL; 824 825 /* 826 * If we got here from RESOLVE, then we are cloning 827 * so clone the rest, and note that we --- 482 unchanged lines hidden --- |