* Grows up the number of routing tables in the current fib. * Function creates new index array for all rtables and allocates * remaining routing tables. */
| 168 | * remaining routing tables. |
| 169 | */ |
| 170 | static void |
| 171 | grow_rtables(uint32_t num_tables) |
| 172 | { |
| 173 | struct domain *dom; |
| 174 | struct rib_head **prnh, *rh; |
| 175 | struct rib_head **new_rt_tables, **old_rt_tables; |
| 176 | int family; |
| 177 | |
| 178 | RTABLES_LOCK_ASSERT(); |
| 179 | |
| 180 | KASSERT(num_tables >= V_rt_numfibs, ("num_tables(%u) < rt_numfibs(%u)\n", |
| 181 | num_tables, V_rt_numfibs)); |
| 182 | |
| 183 | new_rt_tables = mallocarray(num_tables * (AF_MAX + 1), sizeof(void *), |
| 184 | M_RTABLE, M_WAITOK | M_ZERO); |
| 185 | |
| 186 | if ((num_tables > 1) && (V_rt_add_addr_allfibs == 0)) |
| 187 | printf("WARNING: Adding ifaddrs to all fibs has been turned off " |
| 188 | "by default. Consider tuning %s if needed\n", |
| 189 | "net.add_addr_allfibs"); |
| 190 | |
| 191 | #ifdef FIB_ALGO |
| 192 | fib_grow_rtables(num_tables); |
| 193 | #endif |
| 194 | |
| 195 | /* |
| 196 | * Current rt_tables layout: |
| 197 | * fib0[af0, af1, af2, .., AF_MAX]fib1[af0, af1, af2, .., Af_MAX].. |
| 198 | * this allows to copy existing tables data by using memcpy() |
| 199 | */ |
| 200 | if (V_rt_tables != NULL) |
| 201 | memcpy(new_rt_tables, V_rt_tables, |
| 202 | V_rt_numfibs * (AF_MAX + 1) * sizeof(void *)); |
| 203 | |
| 204 | /* Populate the remainders */ |
| 205 | for (dom = domains; dom; dom = dom->dom_next) { |
| 206 | if (dom->dom_rtattach == NULL) |
| 207 | continue; |
| 208 | family = dom->dom_family; |
| 209 | for (int i = 0; i < num_tables; i++) { |
| 210 | prnh = &new_rt_tables[i * (AF_MAX + 1) + family]; |
| 211 | if (*prnh != NULL) |
| 212 | continue; |
| 213 | rh = dom->dom_rtattach(i); |
| 214 | if (rh == NULL) |
| 215 | log(LOG_ERR, "unable to create routing table for %d.%d\n", |
| 216 | dom->dom_family, i); |
| 217 | #ifdef FIB_ALGO |
| 218 | if (fib_select_algo_initial(rh) != 0) { |
| 219 | log(LOG_ERR, "unable to select algo for table %d.%d\n", |
| 220 | dom->dom_family, i); |
| 221 | // TODO: detach table |
| 222 | } |
| 223 | #endif |
| 224 | *prnh = rh; |
| 225 | } |
| 226 | } |
| 227 |
no test coverage detected