Changeset View
Changeset View
Standalone View
Standalone View
sys/net/route/route_tables.c
Show First 20 Lines • Show All 165 Lines • ▼ Show 20 Lines | |||||
* Grows up the number of routing tables in the current fib. | * Grows up the number of routing tables in the current fib. | ||||
* Function creates new index array for all rtables and allocates | * Function creates new index array for all rtables and allocates | ||||
* remaining routing tables. | * remaining routing tables. | ||||
*/ | */ | ||||
static void | static void | ||||
grow_rtables(uint32_t num_tables) | grow_rtables(uint32_t num_tables) | ||||
{ | { | ||||
struct domain *dom; | struct domain *dom; | ||||
struct rib_head **prnh; | struct rib_head **prnh, *rh; | ||||
struct rib_head **new_rt_tables, **old_rt_tables; | struct rib_head **new_rt_tables, **old_rt_tables; | ||||
int family; | int family; | ||||
RTABLES_LOCK_ASSERT(); | RTABLES_LOCK_ASSERT(); | ||||
KASSERT(num_tables >= V_rt_numfibs, ("num_tables(%u) < rt_numfibs(%u)\n", | KASSERT(num_tables >= V_rt_numfibs, ("num_tables(%u) < rt_numfibs(%u)\n", | ||||
num_tables, V_rt_numfibs)); | num_tables, V_rt_numfibs)); | ||||
new_rt_tables = mallocarray(num_tables * (AF_MAX + 1), sizeof(void *), | new_rt_tables = mallocarray(num_tables * (AF_MAX + 1), sizeof(void *), | ||||
M_RTABLE, M_WAITOK | M_ZERO); | M_RTABLE, M_WAITOK | M_ZERO); | ||||
if ((num_tables > 1) && (V_rt_add_addr_allfibs == 0)) | if ((num_tables > 1) && (V_rt_add_addr_allfibs == 0)) | ||||
printf("WARNING: Adding ifaddrs to all fibs has been turned off " | printf("WARNING: Adding ifaddrs to all fibs has been turned off " | ||||
"by default. Consider tuning %s if needed\n", | "by default. Consider tuning %s if needed\n", | ||||
"net.add_addr_allfibs"); | "net.add_addr_allfibs"); | ||||
fib_grow_rtables(num_tables); | |||||
/* | /* | ||||
* Current rt_tables layout: | * Current rt_tables layout: | ||||
* fib0[af0, af1, af2, .., AF_MAX]fib1[af0, af1, af2, .., Af_MAX].. | * fib0[af0, af1, af2, .., AF_MAX]fib1[af0, af1, af2, .., Af_MAX].. | ||||
* this allows to copy existing tables data by using memcpy() | * this allows to copy existing tables data by using memcpy() | ||||
*/ | */ | ||||
if (V_rt_tables != NULL) | if (V_rt_tables != NULL) | ||||
memcpy(new_rt_tables, V_rt_tables, | memcpy(new_rt_tables, V_rt_tables, | ||||
V_rt_numfibs * (AF_MAX + 1) * sizeof(void *)); | V_rt_numfibs * (AF_MAX + 1) * sizeof(void *)); | ||||
/* Populate the remainders */ | /* Populate the remainders */ | ||||
for (dom = domains; dom; dom = dom->dom_next) { | for (dom = domains; dom; dom = dom->dom_next) { | ||||
if (dom->dom_rtattach == NULL) | if (dom->dom_rtattach == NULL) | ||||
continue; | continue; | ||||
family = dom->dom_family; | family = dom->dom_family; | ||||
for (int i = 0; i < num_tables; i++) { | for (int i = 0; i < num_tables; i++) { | ||||
prnh = &new_rt_tables[i * (AF_MAX + 1) + family]; | prnh = &new_rt_tables[i * (AF_MAX + 1) + family]; | ||||
if (*prnh != NULL) | if (*prnh != NULL) | ||||
continue; | continue; | ||||
*prnh = dom->dom_rtattach(i); | rh = dom->dom_rtattach(i); | ||||
if (*prnh == NULL) | if (rh == NULL) | ||||
log(LOG_ERR, "unable to create routing tables for domain %d\n", | log(LOG_ERR, "unable to create routing table for %d.%d\n", | ||||
dom->dom_family); | dom->dom_family, i); | ||||
if (fib_select_algo_initial(rh) != 0) { | |||||
log(LOG_ERR, "unable to select algo for table %d.%d\n", | |||||
dom->dom_family, i); | |||||
// TODO: detach table | |||||
} | |||||
*prnh = rh; | |||||
} | } | ||||
} | } | ||||
/* | /* | ||||
* Update rtables pointer. | * Update rtables pointer. | ||||
* Ensure all writes to new_rt_tables has been completed before | * Ensure all writes to new_rt_tables has been completed before | ||||
* switching pointer. | * switching pointer. | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 111 Lines • Show Last 20 Lines |