MCPcopy Create free account
hub / github.com/F-Stack/f-stack / bsearch4_build_array

Function bsearch4_build_array

freebsd/netinet/in_fib_algo.c:384–419  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

382}
383
384static enum flm_op_result
385bsearch4_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
421static enum flm_op_result
422bsearch4_build(struct bsearch4_data *bd)

Callers 1

bsearch4_buildFunction · 0.85

Calls 4

bsearch4_process_recordFunction · 0.85
pop_stack_entryFunction · 0.85
mallocarrayFunction · 0.50
freeFunction · 0.50

Tested by

no test coverage detected