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

Function bsearch4_build

freebsd/netinet/in_fib_algo.c:421–461  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

419}
420
421static enum flm_op_result
422bsearch4_build(struct bsearch4_data *bd)
423{
424 enum flm_op_result ret;
425
426 struct bsearch4_array prefixes_array = {
427 .alloc_items = bd->alloc_items,
428 .num_items = bd->num_items,
429 .arr = bd->rr,
430 };
431
432 /* Add default route if not exists */
433 bool default_found = false;
434 for (int i = 0; i < prefixes_array.num_items; i++) {
435 if (prefixes_array.arr[i].mask4 == 0) {
436 default_found = true;
437 break;
438 }
439 }
440 if (!default_found) {
441 /* Add default route with NULL nhop */
442 struct bsearch4_record default_entry = {};
443 if (!add_array_entry(&prefixes_array, &default_entry))
444 return (FLM_REBUILD);
445 }
446
447 /* Sort prefixes */
448 qsort(prefixes_array.arr, prefixes_array.num_items, sizeof(struct bsearch4_record), rr_cmp);
449
450 struct bsearch4_array dst_array = {
451 .alloc_items = bd->alloc_items,
452 .arr = bd->br,
453 };
454
455 ret = bsearch4_build_array(&dst_array, &prefixes_array);
456 bd->num_items = dst_array.num_items;
457
458 free(bd->rr, M_TEMP);
459 bd->rr = NULL;
460 return (ret);
461}
462
463
464static enum flm_op_result

Callers 1

bsearch4_end_dumpFunction · 0.85

Calls 4

add_array_entryFunction · 0.85
qsortFunction · 0.85
bsearch4_build_arrayFunction · 0.85
freeFunction · 0.50

Tested by

no test coverage detected