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 262763 2014-03-05 01:17:47Z glebius $ |
31 */ 32/************************************************************************ 33 * Note: In this file a 'fib' is a "forwarding information base" * 34 * Which is the new name for an in kernel routing (next hop) table. * 35 ***********************************************************************/ 36 37#include "opt_inet.h" 38#include "opt_inet6.h" --- 158 unchanged lines hidden (view full) --- 197 /* whack the tunable ints into line. */ 198 if (rt_numfibs > RT_MAXFIBS) 199 rt_numfibs = RT_MAXFIBS; 200 if (rt_numfibs == 0) 201 rt_numfibs = 1; 202} 203SYSINIT(route_init, SI_SUB_PROTO_DOMAIN, SI_ORDER_THIRD, route_init, 0); 204 |
205static int 206rtentry_zinit(void *mem, int size, int how) 207{ 208 struct rtentry *rt = mem; 209 210 rt->rt_pksent = counter_u64_alloc(how); 211 if (rt->rt_pksent == NULL) 212 return (ENOMEM); 213 214 RT_LOCK_INIT(rt); 215 216 return (0); 217} 218 |
219static void |
220rtentry_zfini(void *mem, int size) 221{ 222 struct rtentry *rt = mem; 223 224 RT_LOCK_DESTROY(rt); 225 counter_u64_free(rt->rt_pksent); 226} 227 228static int 229rtentry_ctor(void *mem, int size, void *arg, int how) 230{ 231 struct rtentry *rt = mem; 232 233 bzero(rt, offsetof(struct rtentry, rt_endzero)); 234 counter_u64_zero(rt->rt_pksent); 235 236 return (0); 237} 238 239static void |
240vnet_route_init(const void *unused __unused) 241{ 242 struct domain *dom; 243 struct radix_node_head **rnh; 244 int table; 245 int fam; 246 247 V_rt_tables = malloc(rt_numfibs * (AF_MAX+1) * 248 sizeof(struct radix_node_head *), M_RTABLE, M_WAITOK|M_ZERO); 249 |
250 V_rtzone = uma_zcreate("rtentry", sizeof(struct rtentry), 251 rtentry_ctor, NULL, 252 rtentry_zinit, rtentry_zfini, UMA_ALIGN_PTR, 0); |
253 for (dom = domains; dom; dom = dom->dom_next) { 254 if (dom->dom_rtattach == NULL) 255 continue; 256 257 for (table = 0; table < rt_numfibs; table++) { 258 fam = dom->dom_family; 259 if (table != 0 && fam != AF_INET6 && fam != AF_INET) 260 break; --- 260 unchanged lines hidden (view full) --- 521 * This also frees the gateway, as they are always malloc'd 522 * together. 523 */ 524 Free(rt_key(rt)); 525 526 /* 527 * and the rtentry itself of course 528 */ |
529 uma_zfree(V_rtzone, rt); 530 return; 531 } 532done: 533 RT_UNLOCK(rt); 534} 535 536 --- 719 unchanged lines hidden (view full) --- 1256 1257 if (info->rti_ifa == NULL) { 1258 error = rt_getifa_fib(info, fibnum); 1259 if (error) 1260 senderr(error); 1261 } else 1262 ifa_ref(info->rti_ifa); 1263 ifa = info->rti_ifa; |
1264 rt = uma_zalloc(V_rtzone, M_NOWAIT); |
1265 if (rt == NULL) { 1266 ifa_free(ifa); 1267 senderr(ENOBUFS); 1268 } |
1269 rt->rt_flags = RTF_UP | flags; 1270 rt->rt_fibnum = fibnum; 1271 /* 1272 * Add the gateway. Possibly re-malloc-ing the storage for it. 1273 */ 1274 RT_LOCK(rt); 1275 if ((error = rt_setgate(rt, dst, gateway)) != 0) { |
1276 ifa_free(ifa); 1277 uma_zfree(V_rtzone, rt); 1278 senderr(error); 1279 } 1280 1281 /* 1282 * point to the (possibly newly malloc'd) dest address. 1283 */ --- 9 unchanged lines hidden (view full) --- 1293 1294 /* 1295 * We use the ifa reference returned by rt_getifa_fib(). 1296 * This moved from below so that rnh->rnh_addaddr() can 1297 * examine the ifa and ifa->ifa_ifp if it so desires. 1298 */ 1299 rt->rt_ifa = ifa; 1300 rt->rt_ifp = ifa->ifa_ifp; |
1301 rt->rt_weight = 1; |
1302 1303#ifdef RADIX_MPATH 1304 /* do not permit exactly the same dst/mask/gw pair */ 1305 if (rn_mpath_capable(rnh) && 1306 rt_mpath_conflict(rnh, rt, netmask)) { 1307 ifa_free(rt->rt_ifa); 1308 Free(rt_key(rt)); |
1309 uma_zfree(V_rtzone, rt); 1310 senderr(EEXIST); 1311 } 1312#endif 1313 1314#ifdef FLOWTABLE 1315 rt0 = NULL; 1316 /* "flow-table" only supports IPv6 and IPv4 at the moment. */ --- 51 unchanged lines hidden (view full) --- 1368 rn = rnh->rnh_addaddr(ndst, netmask, rnh, rt->rt_nodes); 1369 /* 1370 * If it still failed to go into the tree, 1371 * then un-make it (this should be a function) 1372 */ 1373 if (rn == NULL) { 1374 ifa_free(rt->rt_ifa); 1375 Free(rt_key(rt)); |
1376 uma_zfree(V_rtzone, rt); 1377#ifdef FLOWTABLE 1378 if (rt0 != NULL) 1379 RTFREE(rt0); 1380#endif 1381 senderr(EEXIST); 1382 } 1383#ifdef FLOWTABLE --- 464 unchanged lines hidden --- |