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

Function nat64lsn_foreach

tools/ipfw/nat64lsn.c:855–894  ·  view source on GitHub ↗

* Retrieves nat64lsn instance list from kernel, * optionally sorts it and calls requested function for each instance. * * Request: [ ipfw_obj_lheader ] * Reply: [ ipfw_obj_lheader ipfw_nat64lsn_cfg x N ] */

Source from the content-addressed store, hash-verified

853 * Reply: [ ipfw_obj_lheader ipfw_nat64lsn_cfg x N ]
854 */
855static int
856nat64lsn_foreach(nat64lsn_cb_t *f, const char *name, uint8_t set, int sort)
857{
858 ipfw_obj_lheader *olh;
859 ipfw_nat64lsn_cfg *cfg;
860 size_t sz;
861 uint32_t i;
862 int error;
863
864 /* Start with reasonable default */
865 sz = sizeof(*olh) + 16 * sizeof(ipfw_nat64lsn_cfg);
866
867 for (;;) {
868 if ((olh = calloc(1, sz)) == NULL)
869 return (ENOMEM);
870
871 olh->size = sz;
872 if (do_get3(IP_FW_NAT64LSN_LIST, &olh->opheader, &sz) != 0) {
873 sz = olh->size;
874 free(olh);
875 if (errno != ENOMEM)
876 return (errno);
877 continue;
878 }
879
880 if (sort != 0)
881 qsort(olh + 1, olh->count, olh->objsize,
882 nat64name_cmp);
883
884 cfg = (ipfw_nat64lsn_cfg *)(olh + 1);
885 for (i = 0; i < olh->count; i++) {
886 error = f(cfg, name, set); /* Ignore errors for now */
887 cfg = (ipfw_nat64lsn_cfg *)((caddr_t)cfg +
888 olh->objsize);
889 }
890 free(olh);
891 break;
892 }
893 return (0);
894}
895

Callers 2

ipfw_nat64lsn_handlerFunction · 0.85

Calls 4

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

Tested by

no test coverage detected