| 382 | } |
| 383 | |
| 384 | static enum flm_op_result |
| 385 | bsearch4_build_array(struct bsearch4_array *dst_array, struct bsearch4_array *src_array) |
| 386 | { |
| 387 | |
| 388 | /* |
| 389 | * During iteration, we keep track of all prefixes in rtable |
| 390 | * we currently match, by maintaining stack. As there can be only |
| 391 | * 32 prefixes for a single address, pre-allocate stack of size 32. |
| 392 | */ |
| 393 | struct bsearch4_array stack = { |
| 394 | .alloc_items = 32, |
| 395 | .arr = mallocarray(32, sizeof(struct bsearch4_record), M_TEMP, M_NOWAIT | M_ZERO), |
| 396 | }; |
| 397 | if (stack.arr == NULL) |
| 398 | return (FLM_REBUILD); |
| 399 | |
| 400 | for (int i = 0; i < src_array->num_items; i++) { |
| 401 | struct bsearch4_record *rib_entry = &src_array->arr[i]; |
| 402 | |
| 403 | if (!bsearch4_process_record(dst_array, &stack, rib_entry)) { |
| 404 | free(stack.arr, M_TEMP); |
| 405 | return (FLM_REBUILD); |
| 406 | } |
| 407 | } |
| 408 | |
| 409 | /* |
| 410 | * We know that last record is contained in the top stack entry. |
| 411 | */ |
| 412 | while (stack.num_items > 0) { |
| 413 | if (!pop_stack_entry(dst_array, &stack)) |
| 414 | return (FLM_REBUILD); |
| 415 | } |
| 416 | free(stack.arr, M_TEMP); |
| 417 | |
| 418 | return (FLM_SUCCESS); |
| 419 | } |
| 420 | |
| 421 | static enum flm_op_result |
| 422 | bsearch4_build(struct bsearch4_data *bd) |
no test coverage detected