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

Function nat_foreach

tools/ipfw/nat.c:1040–1080  ·  view source on GitHub ↗

* Retrieves nat list from kernel, * optionally sorts it and calls requested function for each table. * Returns 0 on success. */

Source from the content-addressed store, hash-verified

1038 * Returns 0 on success.
1039 */
1040static int
1041nat_foreach(nat_cb_t *f, void *arg, int sort)
1042{
1043 ipfw_obj_lheader *olh;
1044 struct nat44_cfg_nat *cfg;
1045 size_t sz;
1046 uint32_t i;
1047 int error;
1048
1049 /* Start with reasonable default */
1050 sz = sizeof(*olh) + 16 * sizeof(struct nat44_cfg_nat);
1051
1052 for (;;) {
1053 if ((olh = calloc(1, sz)) == NULL)
1054 return (ENOMEM);
1055
1056 olh->size = sz;
1057 if (do_get3(IP_FW_NAT44_LIST_NAT, &olh->opheader, &sz) != 0) {
1058 sz = olh->size;
1059 free(olh);
1060 if (errno == ENOMEM)
1061 continue;
1062 return (errno);
1063 }
1064
1065 if (sort != 0)
1066 qsort(olh + 1, olh->count, olh->objsize, natname_cmp);
1067
1068 cfg = (struct nat44_cfg_nat*)(olh + 1);
1069 for (i = 0; i < olh->count; i++) {
1070 error = f(cfg, arg); /* Ignore errors for now */
1071 cfg = (struct nat44_cfg_nat *)((caddr_t)cfg +
1072 olh->objsize);
1073 }
1074
1075 free(olh);
1076 break;
1077 }
1078
1079 return (0);
1080}
1081
1082static int
1083nat_get_cmd(char *name, uint16_t cmd, ipfw_obj_header **ooh)

Callers 1

ipfw_show_natFunction · 0.85

Calls 4

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

Tested by

no test coverage detected