Lines Matching defs:npf
32 * NPF connection tracking for stateful filtering and translation.
149 npf_conn_init(npf_t *npf)
151 npf_conn_params_t *params = npf_param_allocgroup(npf,
167 npf_param_register(npf, param_map, __arraycount(param_map));
169 npf->conn_cache[0] = pool_cache_init(
172 npf->conn_cache[1] = pool_cache_init(
176 mutex_init(&npf->conn_lock, MUTEX_DEFAULT, IPL_NONE);
177 atomic_store_relaxed(&npf->conn_tracking, CONN_TRACKING_OFF);
178 npf->conn_db = npf_conndb_create();
179 npf_conndb_sysinit(npf);
181 npf_worker_addfunc(npf, npf_conn_worker);
185 npf_conn_fini(npf_t *npf)
190 KASSERT(atomic_load_relaxed(&npf->conn_tracking) == CONN_TRACKING_OFF);
192 npf_conndb_destroy(npf->conn_db);
193 pool_cache_destroy(npf->conn_cache[0]);
194 pool_cache_destroy(npf->conn_cache[1]);
195 mutex_destroy(&npf->conn_lock);
197 npf_param_freegroup(npf, NPF_PARAMS_CONN, len);
198 npf_conndb_sysfini(npf);
209 npf_conn_load(npf_t *npf, npf_conndb_t *ndb, bool track)
213 KASSERT(npf_config_locked_p(npf));
219 mutex_enter(&npf->conn_lock);
221 KASSERT(atomic_load_relaxed(&npf->conn_tracking)
223 odb = atomic_load_relaxed(&npf->conn_db);
224 atomic_store_release(&npf->conn_db, ndb);
229 atomic_store_relaxed(&npf->conn_tracking, CONN_TRACKING_ON);
231 mutex_exit(&npf->conn_lock);
238 npf_conndb_gc(npf, odb, true, false);
240 pool_cache_invalidate(npf->conn_cache[0]);
241 pool_cache_invalidate(npf->conn_cache[1]);
249 npf_conn_tracking(npf_t *npf, bool track)
251 KASSERT(npf_config_locked_p(npf));
252 atomic_store_relaxed(&npf->conn_tracking,
259 const npf_t *npf = npc->npc_ctx;
265 if (atomic_load_relaxed(&npf->conn_tracking) != CONN_TRACKING_ON) {
328 npf_t *npf = npc->npc_ctx;
337 con = npf_conndb_lookup(npf, &key, flow);
426 npf_t *npf = npc->npc_ctx;
442 con = pool_cache_get(npf->conn_cache[idx], PR_NOWAIT);
444 npf_worker_signal(npf);
447 NPF_PRINTF(("NPF: create conn %p\n", con));
448 npf_stats_inc(npf, NPF_STAT_CONN_CREATE);
462 npf_conn_destroy(npf, con);
476 npf_conn_destroy(npf, con);
494 conn_db = atomic_load_consume(&npf->conn_db);
515 npf_stats_inc(npf, NPF_STAT_RACE_CONN);
517 NPF_PRINTF(("NPF: establish conn %p\n", con));
528 npf_conn_destroy(npf_t *npf, npf_conn_t *con)
548 pool_cache_put(npf->conn_cache[idx], con);
549 npf_stats_inc(npf, NPF_STAT_CONN_DESTROY);
550 NPF_PRINTF(("NPF: conn %p destroyed\n", con));
568 npf_t *npf = npc->npc_ctx;
599 conn_db = atomic_load_consume(&npf->conn_db);
713 npf_conn_expired(npf_t *npf, const npf_conn_t *con, uint64_t tsnow)
716 const int etime = npf_state_etime(npf, &con->c_state, con->c_proto);
762 npf_conn_worker(npf_t *npf)
764 npf_conndb_t *conn_db = atomic_load_consume(&npf->conn_db);
765 npf_conndb_gc(npf, conn_db, false, true);
773 npf_conndb_export(npf_t *npf, nvlist_t *nvl)
782 mutex_enter(&npf->conn_lock);
783 if (atomic_load_relaxed(&npf->conn_tracking) != CONN_TRACKING_ON) {
784 mutex_exit(&npf->conn_lock);
787 conn_db = atomic_load_relaxed(&npf->conn_db);
794 if (npf_conn_export(npf, con, con_nvl) == 0) {
803 mutex_exit(&npf->conn_lock);
811 npf_conn_export(npf_t *npf, npf_conn_t *con, nvlist_t *nvl)
825 npf_ifmap_copyname(npf, con->c_ifid, ifname, sizeof(ifname));
835 knvl = npf_connkey_export(npf, fw);
838 knvl = npf_connkey_export(npf, bk);
845 npf_nat_export(npf, con->c_nat, nvl);
855 npf_conn_import(npf_t *npf, npf_conndb_t *cd, const nvlist_t *cdict,
874 con = pool_cache_get(npf->conn_cache[idx], PR_WAITOK);
877 npf_stats_inc(npf, NPF_STAT_CONN_CREATE);
886 if (ifname && (con->c_ifid = npf_ifmap_register(npf, ifname)) == 0) {
898 (con->c_nat = npf_nat_import(npf, nat, natlist, con)) == NULL) {
907 if (conkey == NULL || !npf_connkey_import(npf, conkey, fw)) {
912 if (conkey == NULL || !npf_connkey_import(npf, conkey, bk)) {
930 NPF_PRINTF(("NPF: imported conn %p\n", con));
934 npf_conn_destroy(npf, con);
942 npf_conn_find(npf_t *npf, const nvlist_t *req, nvlist_t *resp)
951 if (!key_nv || !npf_connkey_import(npf, key_nv, &key)) {
954 con = npf_conndb_lookup(npf, &key, &flow);
962 error = npf_conn_export(npf, con, resp);