route.c (262758) | route.c (262763) |
---|---|
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 262758 2014-03-04 23:55:04Z gnn $ | 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 | 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 |
|
205static void | 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 |
|
206vnet_route_init(const void *unused __unused) 207{ 208 struct domain *dom; 209 struct radix_node_head **rnh; 210 int table; 211 int fam; 212 213 V_rt_tables = malloc(rt_numfibs * (AF_MAX+1) * 214 sizeof(struct radix_node_head *), M_RTABLE, M_WAITOK|M_ZERO); 215 | 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 |
216 V_rtzone = uma_zcreate("rtentry", sizeof(struct rtentry), NULL, NULL, 217 NULL, NULL, UMA_ALIGN_PTR, 0); | 250 V_rtzone = uma_zcreate("rtentry", sizeof(struct rtentry), 251 rtentry_ctor, NULL, 252 rtentry_zinit, rtentry_zfini, UMA_ALIGN_PTR, 0); |
218 for (dom = domains; dom; dom = dom->dom_next) { 219 if (dom->dom_rtattach == NULL) 220 continue; 221 222 for (table = 0; table < rt_numfibs; table++) { 223 fam = dom->dom_family; 224 if (table != 0 && fam != AF_INET6 && fam != AF_INET) 225 break; --- 260 unchanged lines hidden (view full) --- 486 * This also frees the gateway, as they are always malloc'd 487 * together. 488 */ 489 Free(rt_key(rt)); 490 491 /* 492 * and the rtentry itself of course 493 */ | 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 */ |
494 RT_LOCK_DESTROY(rt); | |
495 uma_zfree(V_rtzone, rt); 496 return; 497 } 498done: 499 RT_UNLOCK(rt); 500} 501 502 --- 719 unchanged lines hidden (view full) --- 1222 1223 if (info->rti_ifa == NULL) { 1224 error = rt_getifa_fib(info, fibnum); 1225 if (error) 1226 senderr(error); 1227 } else 1228 ifa_ref(info->rti_ifa); 1229 ifa = info->rti_ifa; | 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; |
1230 rt = uma_zalloc(V_rtzone, M_NOWAIT | M_ZERO); | 1264 rt = uma_zalloc(V_rtzone, M_NOWAIT); |
1231 if (rt == NULL) { 1232 ifa_free(ifa); 1233 senderr(ENOBUFS); 1234 } | 1265 if (rt == NULL) { 1266 ifa_free(ifa); 1267 senderr(ENOBUFS); 1268 } |
1235 RT_LOCK_INIT(rt); | |
1236 rt->rt_flags = RTF_UP | flags; 1237 rt->rt_fibnum = fibnum; 1238 /* 1239 * Add the gateway. Possibly re-malloc-ing the storage for it. 1240 */ 1241 RT_LOCK(rt); 1242 if ((error = rt_setgate(rt, dst, gateway)) != 0) { | 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) { |
1243 RT_LOCK_DESTROY(rt); | |
1244 ifa_free(ifa); 1245 uma_zfree(V_rtzone, rt); 1246 senderr(error); 1247 } 1248 1249 /* 1250 * point to the (possibly newly malloc'd) dest address. 1251 */ --- 9 unchanged lines hidden (view full) --- 1261 1262 /* 1263 * We use the ifa reference returned by rt_getifa_fib(). 1264 * This moved from below so that rnh->rnh_addaddr() can 1265 * examine the ifa and ifa->ifa_ifp if it so desires. 1266 */ 1267 rt->rt_ifa = ifa; 1268 rt->rt_ifp = ifa->ifa_ifp; | 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; |
1269 rt->rt_rmx.rmx_weight = 1; | 1301 rt->rt_weight = 1; |
1270 1271#ifdef RADIX_MPATH 1272 /* do not permit exactly the same dst/mask/gw pair */ 1273 if (rn_mpath_capable(rnh) && 1274 rt_mpath_conflict(rnh, rt, netmask)) { 1275 ifa_free(rt->rt_ifa); 1276 Free(rt_key(rt)); | 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)); |
1277 RT_LOCK_DESTROY(rt); | |
1278 uma_zfree(V_rtzone, rt); 1279 senderr(EEXIST); 1280 } 1281#endif 1282 1283#ifdef FLOWTABLE 1284 rt0 = NULL; 1285 /* "flow-table" only supports IPv6 and IPv4 at the moment. */ --- 51 unchanged lines hidden (view full) --- 1337 rn = rnh->rnh_addaddr(ndst, netmask, rnh, rt->rt_nodes); 1338 /* 1339 * If it still failed to go into the tree, 1340 * then un-make it (this should be a function) 1341 */ 1342 if (rn == NULL) { 1343 ifa_free(rt->rt_ifa); 1344 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)); |
1345 RT_LOCK_DESTROY(rt); | |
1346 uma_zfree(V_rtzone, rt); 1347#ifdef FLOWTABLE 1348 if (rt0 != NULL) 1349 RTFREE(rt0); 1350#endif 1351 senderr(EEXIST); 1352 } 1353#ifdef FLOWTABLE --- 464 unchanged lines hidden --- | 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 --- |