const char * npf_ifmap_getname(npf_t *npf, const u_int id) { const char *ifname; KASSERT(npf_config_locked_p(npf)); KASSERT(id > 0 && id <= npf->ifmap_cnt); ifname = npf->ifmap[id - 1].n_ifname; KASSERT(ifname[0] != '\0'); return ifname; }
static u_int npf_ifmap_lookup(npf_t *npf, const char *ifname) { KASSERT(npf_config_locked_p(npf)); for (u_int i = 0; i < npf->ifmap_cnt; i++) { npf_ifmap_t *nim = &npf->ifmap[i]; if (nim->n_ifname[0] && strcmp(nim->n_ifname, ifname) == 0) return i + 1; } return 0; }
void npf_ifmap_flush(npf_t *npf) { ifnet_t *ifp; KASSERT(npf_config_locked_p(npf)); for (u_int i = 0; i < npf->ifmap_cnt; i++) { npf->ifmap[i].n_ifname[0] = '\0'; } npf->ifmap_cnt = 0; npf->ifops->flush((void *)(uintptr_t)0); }
static u_int npf_ifmap_new(npf_t *npf) { KASSERT(npf_config_locked_p(npf)); for (u_int i = 0; i < npf->ifmap_cnt; i++) if (npf->ifmap[i].n_ifname[0] == '\0') return i + 1; if (npf->ifmap_cnt == NPF_MAX_IFMAP) { printf("npf_ifmap_new: out of slots; bump NPF_MAX_IFMAP\n"); return 0; } return ++npf->ifmap_cnt; }
void npf_config_sync(void) { KASSERT(npf_config_locked_p()); pserialize_perform(npf_config_psz); }