route.c (132780) | route.c (133513) |
---|---|
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 | 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 132780 2004-07-28 06:59:55Z kan $ | 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 | 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 |
|
50static struct rtstat rtstat; 51struct radix_node_head *rt_tables[AF_MAX+1]; 52 53static int rttrash; /* routes not in table but not freed */ 54 55static void rt_maskedcopy(struct sockaddr *, 56 struct sockaddr *, struct sockaddr *); 57static void rtable_init(void **); --- 18 unchanged lines hidden (view full) --- 76{ 77 struct domain *dom; 78 for (dom = domains; dom; dom = dom->dom_next) 79 if (dom->dom_rtattach) 80 dom->dom_rtattach(&table[dom->dom_family], 81 dom->dom_rtoffset); 82} 83 | 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 |
|
84static void 85route_init(void) 86{ | 88static void 89route_init(void) 90{ |
91 rtzone = uma_zcreate("rtentry", sizeof(struct rtentry), NULL, NULL, 92 NULL, NULL, UMA_ALIGN_PTR, 0); |
|
87 rn_init(); /* initialize all zeroes, all ones, mask table */ 88 rtable_init((void **)rt_tables); 89} 90 91/* 92 * Packet routing routines. 93 */ 94void --- 192 unchanged lines hidden (view full) --- 287 * together. 288 */ 289 Free(rt_key(rt)); 290 291 /* 292 * and the rtentry itself of course 293 */ 294 RT_LOCK_DESTROY(rt); | 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); |
295 Free(rt); | 301 uma_zfree(rtzone, rt); |
296 return; 297 } 298done: 299 RT_UNLOCK(rt); 300} 301 302 303/* --- 429 unchanged lines hidden (view full) --- 733 if ((flags & RTF_GATEWAY) && !gateway) 734 panic("rtrequest: GATEWAY but no gateway"); 735 736 if (info->rti_ifa == NULL && (error = rt_getifa(info))) 737 senderr(error); 738 ifa = info->rti_ifa; 739 740 makeroute: | 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: |
741 R_Zalloc(rt, struct rtentry *, sizeof(*rt)); | 747 rt = uma_zalloc(rtzone, M_NOWAIT | M_ZERO); |
742 if (rt == NULL) 743 senderr(ENOBUFS); 744 RT_LOCK_INIT(rt); 745 rt->rt_flags = RTF_UP | flags; 746 /* 747 * Add the gateway. Possibly re-malloc-ing the storage for it 748 * also add the rt_gwroute if possible. 749 */ 750 RT_LOCK(rt); 751 if ((error = rt_setgate(rt, dst, gateway)) != 0) { 752 RT_LOCK_DESTROY(rt); | 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); |
753 Free(rt); | 759 uma_zfree(rtzone, rt); |
754 senderr(error); 755 } 756 757 /* 758 * point to the (possibly newly malloc'd) dest address. 759 */ 760 ndst = (struct sockaddr *)rt_key(rt); 761 --- 43 unchanged lines hidden (view full) --- 805 */ 806 if (rn == NULL) { 807 if (rt->rt_gwroute) 808 RTFREE(rt->rt_gwroute); 809 if (rt->rt_ifa) 810 IFAFREE(rt->rt_ifa); 811 Free(rt_key(rt)); 812 RT_LOCK_DESTROY(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); |
813 Free(rt); | 819 uma_zfree(rtzone, rt); |
814 senderr(EEXIST); 815 } 816 817 rt->rt_parent = NULL; 818 819 /* 820 * If we got here from RESOLVE, then we are cloning 821 * so clone the rest, and note that we --- 482 unchanged lines hidden --- | 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 --- |