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

Function nptv6_foreach

tools/ipfw/nptv6.c:421–457  ·  view source on GitHub ↗

* Retrieves NPTv6 instance list from kernel, * Request: [ ipfw_obj_lheader ] * Reply: [ ipfw_obj_lheader ipfw_nptv6_cfg x N ] */

Source from the content-addressed store, hash-verified

419 * Reply: [ ipfw_obj_lheader ipfw_nptv6_cfg x N ]
420 */
421static int
422nptv6_foreach(nptv6_cb_t *f, const char *name, uint8_t set, int sort)
423{
424 ipfw_obj_lheader *olh;
425 ipfw_nptv6_cfg *cfg;
426 size_t sz;
427 uint32_t i;
428 int error;
429
430 /* Start with reasonable default */
431 sz = sizeof(*olh) + 16 * sizeof(*cfg);
432 for (;;) {
433 if ((olh = calloc(1, sz)) == NULL)
434 return (ENOMEM);
435
436 olh->size = sz;
437 if (do_get3(IP_FW_NPTV6_LIST, &olh->opheader, &sz) != 0) {
438 sz = olh->size;
439 free(olh);
440 if (errno != ENOMEM)
441 return (errno);
442 continue;
443 }
444
445 if (sort != 0)
446 qsort(olh + 1, olh->count, olh->objsize, nptv6name_cmp);
447
448 cfg = (ipfw_nptv6_cfg *)(olh + 1);
449 for (i = 0; i < olh->count; i++) {
450 error = f(cfg, name, set);
451 cfg = (ipfw_nptv6_cfg *)((caddr_t)cfg + olh->objsize);
452 }
453 free(olh);
454 break;
455 }
456 return (0);
457}
458

Callers 1

ipfw_nptv6_handlerFunction · 0.85

Calls 4

callocFunction · 0.85
do_get3Function · 0.85
qsortFunction · 0.85
freeFunction · 0.50

Tested by

no test coverage detected