/** * Clean temporary map files. */ void clean_tmp_files(void) { mapstruct *m, *tmp; /* We save the maps - it may not be intuitive why, but if there are * unique items, we need to save the map so they get saved off. */ DL_FOREACH_SAFE(first_map, m, tmp) { if (m->in_memory == MAP_IN_MEMORY) { if (settings.recycle_tmp_maps) { swap_map(m, 0); } else { new_save_map(m, 0); clean_tmp_map(m); } } } /* Write the clock */ write_todclock(); if (settings.recycle_tmp_maps) { write_map_log(); } }
/* * Add a new rule to the list. Copy the rule into a malloc'ed area, then * possibly create a rule number and add the rule to the list. * Update the rule_number in the input struct so the caller knows it as well. * XXX DO NOT USE FOR THE DEFAULT RULE. * Must be called without IPFW_UH held */ int ipfw_add_rule(struct ip_fw_chain *chain, struct ip_fw *input_rule) { struct ip_fw *rule; int i, l, insert_before; struct ip_fw **map; /* the new array of pointers */ if (chain->rules == NULL || input_rule->rulenum > IPFW_DEFAULT_RULE-1) return (EINVAL); l = RULESIZE(input_rule); rule = malloc(l, M_IPFW, M_WAITOK | M_ZERO); if (rule == NULL) return (ENOSPC); /* get_map returns with IPFW_UH_WLOCK if successful */ map = get_map(chain, 1, 0 /* not locked */); if (map == NULL) { free(rule, M_IPFW); return ENOSPC; } bcopy(input_rule, rule, l); /* clear fields not settable from userland */ rule->x_next = NULL; rule->next_rule = NULL; rule->pcnt = 0; rule->bcnt = 0; rule->timestamp = 0; if (V_autoinc_step < 1) V_autoinc_step = 1; else if (V_autoinc_step > 1000) V_autoinc_step = 1000; /* find the insertion point, we will insert before */ insert_before = rule->rulenum ? rule->rulenum + 1 : IPFW_DEFAULT_RULE; i = ipfw_find_rule(chain, insert_before, 0); /* duplicate first part */ if (i > 0) bcopy(chain->map, map, i * sizeof(struct ip_fw *)); map[i] = rule; /* duplicate remaining part, we always have the default rule */ bcopy(chain->map + i, map + i + 1, sizeof(struct ip_fw *) *(chain->n_rules - i)); if (rule->rulenum == 0) { /* write back the number */ rule->rulenum = i > 0 ? map[i-1]->rulenum : 0; if (rule->rulenum < IPFW_DEFAULT_RULE - V_autoinc_step) rule->rulenum += V_autoinc_step; input_rule->rulenum = rule->rulenum; } rule->id = chain->id + 1; map = swap_map(chain, map, chain->n_rules + 1); chain->static_len += l; IPFW_UH_WUNLOCK(chain); if (map) free(map, M_IPFW); return (0); }
int swapwrite(uint16_t dev, blkno_t blkno, unsigned int nbytes, uint16_t buf, uint16_t page) { swapbase = swap_map(buf); swapcnt = nbytes; swapblk = blkno; swappage = page; return ((*dev_tab[major(dev)].dev_write) (minor(dev), 2, 0)); }
/** * Sets map timeout value. * @param map * The map to set the timeout for. */ void set_map_timeout(mapstruct *map) { #if MAP_DEFAULTTIMEOUT uint32_t swap_time = MAP_SWAP_TIME(map); if (swap_time == 0) { swap_time = MAP_DEFAULTTIMEOUT; } if (swap_time >= MAP_MAXTIMEOUT) { swap_time = MAP_MAXTIMEOUT; } map->timeout = swap_time; #else /* Save out the map. */ swap_map(map, 0); #endif }