Home | History | Annotate | Download | only in npf

Lines Matching refs:npf

32  * NPF network interface handling.
34 * NPF uses its own interface IDs (npf-if-id). These IDs start from 1.
40 * - Bind a symbolic interface name to NPF interface ID.
41 * - Associate NPF interface ID when the network interface is attached.
43 * When NPF configuration is (re)loaded, each referenced network interface
49 * To avoid race conditions when an active NPF configuration is updated or
74 #define NPF_IFMAP_SLOT2ID(npf, slot) ((npf)->ifmap_off + (slot) + 1)
75 #define NPF_IFMAP_ID2SLOT(npf, id) \
76 ((id) - atomic_load_relaxed(&(npf)->ifmap_off) - 1)
79 npf_ifmap_init(npf_t *npf, const npf_ifops_t *ifops)
84 ifops->flush(npf, (void *)(uintptr_t)0);
86 mutex_init(&npf->ifmap_lock, MUTEX_DEFAULT, IPL_SOFTNET);
87 npf->ifmap = kmem_zalloc(nbytes, KM_SLEEP);
88 npf->ifmap_cnt = 0;
89 npf->ifmap_off = 0;
90 npf->ifops = ifops;
94 npf_ifmap_fini(npf_t *npf)
97 mutex_destroy(&npf->ifmap_lock);
98 kmem_free(npf->ifmap, nbytes);
102 npf_ifmap_lookup(npf_t *npf, const char *ifname)
104 KASSERT(mutex_owned(&npf->ifmap_lock));
106 for (unsigned i = 0; i < npf->ifmap_cnt; i++) {
107 npf_ifmap_t *ifmap = &npf->ifmap[i];
110 return NPF_IFMAP_SLOT2ID(npf, i);
118 * NPF network ID on success (non-zero).
120 * This routine is mostly called on NPF configuration (re)load for the
124 npf_ifmap_register(npf_t *npf, const char *ifname)
130 mutex_enter(&npf->ifmap_lock);
131 if ((id = npf_ifmap_lookup(npf, ifname)) != NPF_IFMAP_NOID) {
134 if (npf->ifmap_cnt == NPF_MAX_IFMAP) {
139 KASSERT(npf->ifmap_cnt < NPF_MAX_IFMAP);
142 i = npf->ifmap_cnt++;
143 ifmap = &npf->ifmap[i];
145 id = NPF_IFMAP_SLOT2ID(npf, i);
147 if ((ifp = npf->ifops->lookup(npf, ifname)) != NULL) {
148 npf->ifops->setmeta(npf, ifp, (void *)(uintptr_t)id);
151 mutex_exit(&npf->ifmap_lock);
156 npf_ifmap_flush(npf_t *npf)
158 mutex_enter(&npf->ifmap_lock);
159 npf->ifops->flush(npf, (void *)(uintptr_t)NPF_IFMAP_NOID);
160 for (unsigned i = 0; i < npf->ifmap_cnt; i++) {
161 npf->ifmap[i].ifname[0] = '\0';
163 npf->ifmap_cnt = 0;
169 if (npf->ifmap_off < (UINT_MAX - NPF_MAX_IFMAP)) {
170 npf->ifmap_off += NPF_MAX_IFMAP;
172 npf->ifmap_off = 0;
174 mutex_exit(&npf->ifmap_lock);
183 * => This routine is lock-free; if the NPF configuration is flushed
188 npf_ifmap_getid(npf_t *npf, const ifnet_t *ifp)
190 const unsigned id = (uintptr_t)npf->ifops->getmeta(npf, ifp);
199 npf_ifmap_copylogname(npf_t *npf, unsigned id, char *buf, size_t len)
201 const unsigned i = NPF_IFMAP_ID2SLOT(npf, id);
210 const npf_ifmap_t *ifmap = &npf->ifmap[i];
218 npf_ifmap_copyname(npf_t *npf, unsigned id, char *buf, size_t len)
220 mutex_enter(&npf->ifmap_lock);
221 npf_ifmap_copylogname(npf, id, buf, len);
222 mutex_exit(&npf->ifmap_lock);
226 npfk_ifmap_attach(npf_t *npf, ifnet_t *ifp)
228 const npf_ifops_t *ifops = npf->ifops;
231 mutex_enter(&npf->ifmap_lock);
232 id = npf_ifmap_lookup(npf, ifops->getname(npf, ifp));
233 ifops->setmeta(npf, ifp, (void *)(uintptr_t)id);
234 mutex_exit(&npf->ifmap_lock);
238 npfk_ifmap_detach(npf_t *npf, ifnet_t *ifp)
241 mutex_enter(&npf->ifmap_lock);
242 npf->ifops->setmeta(npf, ifp, (void *)(uintptr_t)NPF_IFMAP_NOID);
243 mutex_exit(&npf->ifmap_lock);