Home | History | Annotate | Line # | Download | only in npf
      1 /*-
      2  * Copyright (c) 2009-2025 The NetBSD Foundation, Inc.
      3  * All rights reserved.
      4  *
      5  * This material is based upon work partially supported by The
      6  * NetBSD Foundation under a contract with Mindaugas Rasiukevicius.
      7  *
      8  * Redistribution and use in source and binary forms, with or without
      9  * modification, are permitted provided that the following conditions
     10  * are met:
     11  * 1. Redistributions of source code must retain the above copyright
     12  *    notice, this list of conditions and the following disclaimer.
     13  * 2. Redistributions in binary form must reproduce the above copyright
     14  *    notice, this list of conditions and the following disclaimer in the
     15  *    documentation and/or other materials provided with the distribution.
     16  *
     17  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     18  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     19  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     20  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     21  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     27  * POSSIBILITY OF SUCH DAMAGE.
     28  */
     29 
     30 /*
     31  * Private NPF structures and interfaces.
     32  * For internal use within NPF core only.
     33  */
     34 
     35 #ifndef _NPF_IMPL_H_
     36 #define _NPF_IMPL_H_
     37 
     38 #if !defined(_KERNEL) && !defined(_NPF_STANDALONE)
     39 #error "Kernel-level header only"
     40 #endif
     41 
     42 #ifdef _KERNEL_OPT
     43 /* For INET/INET6 definitions. */
     44 #include "opt_inet.h"
     45 #include "opt_inet6.h"
     46 #endif
     47 
     48 #ifdef _KERNEL
     49 #include <sys/types.h>
     50 #include <sys/queue.h>
     51 
     52 #include <net/bpf.h>
     53 #include <net/bpfjit.h>
     54 #include <net/if.h>
     55 #endif
     56 #include <dnv.h>
     57 #include <nv.h>
     58 
     59 #include "npf.h"
     60 #include "npfkern.h"
     61 
     62 #ifdef _NPF_DEBUG
     63 #define	NPF_PRINTF(x)	printf x
     64 #else
     65 #define	NPF_PRINTF(x)
     66 #endif
     67 
     68 /*
     69  * STRUCTURE DECLARATIONS.
     70  */
     71 
     72 struct npf_ruleset;
     73 struct npf_rule;
     74 struct npf_rprocset;
     75 struct npf_portmap;
     76 struct npf_nat;
     77 struct npf_conn;
     78 
     79 typedef struct npf_ruleset	npf_ruleset_t;
     80 typedef struct npf_rule		npf_rule_t;
     81 typedef struct npf_portmap	npf_portmap_t;
     82 typedef struct npf_nat		npf_nat_t;
     83 typedef struct npf_rprocset	npf_rprocset_t;
     84 typedef struct npf_alg		npf_alg_t;
     85 typedef struct npf_natpolicy	npf_natpolicy_t;
     86 typedef struct npf_conn		npf_conn_t;
     87 
     88 struct npf_conndb;
     89 struct npf_table;
     90 struct npf_tableset;
     91 struct npf_algset;
     92 struct npf_ifmap;
     93 
     94 typedef struct npf_conndb	npf_conndb_t;
     95 typedef struct npf_table	npf_table_t;
     96 typedef struct npf_tableset	npf_tableset_t;
     97 typedef struct npf_algset	npf_algset_t;
     98 
     99 typedef uint32_t (*get_rid_t)(kauth_cred_t);
    100 
    101 #ifdef __NetBSD__
    102 typedef void			ebr_t;
    103 #endif
    104 
    105 /*
    106  * DEFINITIONS.
    107  */
    108 
    109 typedef struct {
    110 	npf_ruleset_t *		ruleset;
    111 	npf_ruleset_t *		nat_ruleset;
    112 	npf_rprocset_t *	rule_procs;
    113 	npf_tableset_t *	tableset;
    114 	bool			default_pass;
    115 } npf_config_t;
    116 
    117 typedef void (*npf_workfunc_t)(npf_t *);
    118 
    119 typedef struct {
    120 	uint64_t	mi_rid;
    121 	unsigned	mi_retfl;
    122 	unsigned	mi_di;
    123 } npf_match_info_t;
    124 
    125 /*
    126  * Some artificial limits.
    127  * Note: very unlikely to have many ALGs.
    128  */
    129 #define	NPF_MAX_RULES		(1024 * 1024)
    130 #define	NPF_MAX_TABLES		128
    131 #define	NPF_MAX_RPROCS		128
    132 #define	NPF_MAX_IFMAP		64
    133 #define	NPF_MAX_ALGS		4
    134 #define	NPF_MAX_WORKS		4
    135 
    136 /*
    137  * CONNECTION STATE STRUCTURES
    138  */
    139 
    140 typedef enum {
    141 	NPF_FLOW_FORW = 0,
    142 	NPF_FLOW_BACK = 1,
    143 } npf_flow_t;
    144 
    145 typedef struct {
    146 	uint32_t	nst_end;
    147 	uint32_t	nst_maxend;
    148 	uint32_t	nst_maxwin;
    149 	int		nst_wscale;
    150 } npf_tcpstate_t;
    151 
    152 typedef struct {
    153 	unsigned 	nst_state;
    154 	npf_tcpstate_t	nst_tcpst[2];
    155 } npf_state_t;
    156 
    157 /*
    158  * ALG FUNCTIONS.
    159  */
    160 
    161 typedef struct {
    162 	bool		(*match)(npf_cache_t *, npf_nat_t *, int);
    163 	bool		(*translate)(npf_cache_t *, npf_nat_t *, npf_flow_t);
    164 	npf_conn_t *	(*inspect)(npf_cache_t *, int);
    165 	void		(*destroy)(npf_t *, npf_nat_t *, npf_conn_t *);
    166 } npfa_funcs_t;
    167 
    168 /*
    169  * NBUF STRUCTURE.
    170  */
    171 
    172 struct nbuf {
    173 	struct mbuf *	nb_mbuf0;
    174 	struct mbuf *	nb_mbuf;
    175 	void *		nb_nptr;
    176 	const ifnet_t *	nb_ifp;
    177 	unsigned	nb_ifid;
    178 	int		nb_flags;
    179 	const npf_mbufops_t *nb_mops;
    180 };
    181 
    182 /*
    183  * PARAMS.
    184  */
    185 
    186 typedef struct npf_paraminfo npf_paraminfo_t;
    187 
    188 typedef struct {
    189 	const char *	name;
    190 	int *		valp;
    191 	int		default_val;
    192 	/*
    193 	 * Minimum and maximum allowed values (inclusive).
    194 	 */
    195 	int		min;
    196 	int		max;
    197 } npf_param_t;
    198 
    199 typedef enum {
    200 	NPF_PARAMS_CONN = 0,
    201 	NPF_PARAMS_CONNDB,
    202 	NPF_PARAMS_GENERIC_STATE,
    203 	NPF_PARAMS_TCP_STATE,
    204 	NPF_PARAMS_COUNT
    205 } npf_paramgroup_t;
    206 
    207 /*
    208  * NPF INSTANCE (CONTEXT) STRUCTURE AND AUXILIARY OPERATIONS.
    209  */
    210 
    211 struct npf {
    212 	/* Active NPF configuration. */
    213 	kmutex_t		config_lock;
    214 	ebr_t *			ebr;
    215 	npf_config_t *		config;
    216 
    217 	/*
    218 	 * BPF byte-code context, mbuf operations an arbitrary user argument.
    219 	 */
    220 	bpf_ctx_t *		bpfctx;
    221 	const npf_mbufops_t *	mbufops;
    222 	void *			arg;
    223 
    224 	/* Parameters. */
    225 	npf_paraminfo_t *	paraminfo;
    226 	void *			params[NPF_PARAMS_COUNT];
    227 	int			ip4_reassembly;
    228 	int			ip6_reassembly;
    229 
    230 	/*
    231 	 * Connection tracking state: disabled (off) or enabled (on).
    232 	 * Connection tracking database, connection cache and the lock.
    233 	 * There are two caches (pools): for IPv4 and IPv6.
    234 	 */
    235 	volatile int		conn_tracking;
    236 	kmutex_t		conn_lock;
    237 	npf_conndb_t *		conn_db;
    238 	pool_cache_t		conn_cache[2];
    239 
    240 	/* NAT and ALGs. */
    241 	npf_portmap_t *		portmap;
    242 	npf_algset_t *		algset;
    243 
    244 	/* Interface mapping. */
    245 	const npf_ifops_t *	ifops;
    246 	struct npf_ifmap *	ifmap;
    247 	unsigned		ifmap_cnt;
    248 	unsigned		ifmap_off;
    249 	kmutex_t		ifmap_lock;
    250 
    251 	/* List of extensions and its lock. */
    252 	LIST_HEAD(, npf_ext)	ext_list;
    253 	kmutex_t		ext_lock;
    254 
    255 	/* Associated worker information. */
    256 	unsigned		worker_flags;
    257 	LIST_ENTRY(npf)		worker_entry;
    258 	unsigned		worker_wait_time;
    259 	npf_workfunc_t		worker_funcs[NPF_MAX_WORKS];
    260 
    261 	/* Statistics. */
    262 	percpu_t *		stats_percpu;
    263 };
    264 
    265 /*
    266  * NPF extensions and rule procedure interface.
    267  */
    268 
    269 struct npf_rproc;
    270 typedef struct npf_rproc npf_rproc_t;
    271 
    272 typedef struct {
    273 	u_int	version;
    274 	void *	ctx;
    275 	int	(*ctor)(npf_rproc_t *, const nvlist_t *);
    276 	void	(*dtor)(npf_rproc_t *, void *);
    277 	bool	(*proc)(npf_cache_t *, void *, const npf_match_info_t *, int *);
    278 } npf_ext_ops_t;
    279 
    280 void *		npf_ext_register(npf_t *, const char *, const npf_ext_ops_t *);
    281 int		npf_ext_unregister(npf_t *, void *);
    282 void		npf_rproc_assign(npf_rproc_t *, void *);
    283 
    284 /*
    285  * INTERFACES.
    286  */
    287 
    288 /* NPF config, statistics, etc. */
    289 void		npf_config_init(npf_t *);
    290 void		npf_config_fini(npf_t *);
    291 
    292 npf_config_t *	npf_config_enter(npf_t *);
    293 void		npf_config_exit(npf_t *);
    294 void		npf_config_sync(npf_t *);
    295 bool		npf_config_locked_p(npf_t *);
    296 int		npf_config_read_enter(npf_t *);
    297 void		npf_config_read_exit(npf_t *, int);
    298 
    299 npf_config_t *	npf_config_create(void);
    300 void		npf_config_destroy(npf_config_t *);
    301 void		npf_config_load(npf_t *, npf_config_t *, npf_conndb_t *, bool);
    302 npf_ruleset_t *	npf_config_ruleset(npf_t *npf);
    303 npf_ruleset_t *	npf_config_natset(npf_t *npf);
    304 npf_tableset_t *npf_config_tableset(npf_t *npf);
    305 bool		npf_default_pass(npf_t *);
    306 bool		npf_active_p(void);
    307 
    308 int		npf_worker_sysinit(unsigned);
    309 void		npf_worker_sysfini(void);
    310 int		npf_worker_addfunc(npf_t *, npf_workfunc_t);
    311 void		npf_worker_enlist(npf_t *);
    312 void		npf_worker_discharge(npf_t *);
    313 void		npf_worker_signal(npf_t *);
    314 
    315 int		npfctl_run_op(npf_t *, unsigned, const nvlist_t *, nvlist_t *);
    316 int		npfctl_table(npf_t *, void *);
    317 
    318 void		npf_stats_inc(npf_t *, npf_stats_t);
    319 void		npf_stats_dec(npf_t *, npf_stats_t);
    320 
    321 void		npf_param_init(npf_t *);
    322 void		npf_param_fini(npf_t *);
    323 void		npf_param_register(npf_t *, npf_param_t *, unsigned);
    324 void *		npf_param_allocgroup(npf_t *, npf_paramgroup_t, size_t);
    325 void		npf_param_freegroup(npf_t *, npf_paramgroup_t, size_t);
    326 int		npf_param_check(npf_t *, const char *, int);
    327 int		npf_params_export(const npf_t *, nvlist_t *);
    328 
    329 void		npf_ifmap_init(npf_t *, const npf_ifops_t *);
    330 void		npf_ifmap_fini(npf_t *);
    331 u_int		npf_ifmap_register(npf_t *, const char *);
    332 void		npf_ifmap_flush(npf_t *);
    333 u_int		npf_ifmap_getid(npf_t *, const ifnet_t *);
    334 void		npf_ifmap_copylogname(npf_t *, unsigned, char *, size_t);
    335 void		npf_ifmap_copyname(npf_t *, unsigned, char *, size_t);
    336 
    337 void		npf_ifaddr_sync(npf_t *, ifnet_t *);
    338 void		npf_ifaddr_flush(npf_t *, ifnet_t *);
    339 void		npf_ifaddr_syncall(npf_t *);
    340 
    341 /* Protocol helpers. */
    342 int		npf_cache_all(npf_cache_t *);
    343 void		npf_recache(npf_cache_t *);
    344 int		npf_cache_ether(npf_cache_t *);
    345 
    346 bool		npf_rwrip(const npf_cache_t *, u_int, const npf_addr_t *);
    347 bool		npf_rwrport(const npf_cache_t *, u_int, const in_port_t);
    348 bool		npf_rwrcksum(const npf_cache_t *, u_int,
    349 		    const npf_addr_t *, const in_port_t);
    350 int		npf_napt_rwr(const npf_cache_t *, u_int, const npf_addr_t *,
    351 		    const in_addr_t);
    352 int		npf_npt66_rwr(const npf_cache_t *, u_int, const npf_addr_t *,
    353 		    npf_netmask_t, uint16_t);
    354 
    355 uint16_t	npf_fixup16_cksum(uint16_t, uint16_t, uint16_t);
    356 uint16_t	npf_fixup32_cksum(uint16_t, uint32_t, uint32_t);
    357 uint16_t	npf_addr_cksum(uint16_t, int, const npf_addr_t *,
    358 		    const npf_addr_t *);
    359 uint32_t	npf_addr_mix(const int, const npf_addr_t *, const npf_addr_t *);
    360 int		npf_addr_cmp(const npf_addr_t *, const npf_netmask_t,
    361 		    const npf_addr_t *, const npf_netmask_t, const int);
    362 void		npf_addr_mask(const npf_addr_t *, const npf_netmask_t,
    363 		    const int, npf_addr_t *);
    364 void		npf_addr_bitor(const npf_addr_t *, const npf_netmask_t,
    365 		    const int, npf_addr_t *);
    366 int		npf_netmask_check(const int, npf_netmask_t);
    367 
    368 int		npf_tcpsaw(const npf_cache_t *, tcp_seq *, tcp_seq *,
    369 		    uint32_t *);
    370 bool		npf_fetch_tcpopts(npf_cache_t *, uint16_t *, int *);
    371 bool		npf_set_mss(npf_cache_t *, uint16_t, uint16_t *, uint16_t *,
    372 		    bool *);
    373 bool		npf_return_block(npf_cache_t *, const int);
    374 
    375 /* BPF interface. */
    376 void		npf_bpf_sysinit(void);
    377 void		npf_bpf_sysfini(void);
    378 void		npf_bpf_prepare(npf_cache_t *, bpf_args_t *, uint32_t *);
    379 int		npf_bpf_filter(bpf_args_t *, const void *, bpfjit_func_t);
    380 void *		npf_bpf_compile(void *, size_t);
    381 bool		npf_bpf_validate(const void *, size_t);
    382 
    383 /* Tableset interface. */
    384 void		npf_tableset_sysinit(void);
    385 void		npf_tableset_sysfini(void);
    386 
    387 npf_tableset_t *npf_tableset_create(u_int);
    388 void		npf_tableset_destroy(npf_tableset_t *);
    389 int		npf_tableset_insert(npf_tableset_t *, npf_table_t *);
    390 npf_table_t *	npf_tableset_getbyname(npf_tableset_t *, const char *);
    391 npf_table_t *	npf_tableset_getbyid(npf_tableset_t *, u_int);
    392 npf_table_t *	npf_tableset_swap(npf_tableset_t *, npf_table_t *);
    393 void		npf_tableset_reload(npf_t *, npf_tableset_t *, npf_tableset_t *);
    394 int		npf_tableset_export(npf_t *, const npf_tableset_t *, nvlist_t *);
    395 
    396 npf_table_t *	npf_table_create(const char *, u_int, int, const void *, size_t);
    397 void		npf_table_destroy(npf_table_t *);
    398 
    399 u_int		npf_table_getid(npf_table_t *);
    400 int		npf_table_check(npf_tableset_t *, const char *, uint64_t, uint64_t, bool);
    401 int		npf_table_insert(npf_table_t *, const int,
    402 		    const npf_addr_t *, const npf_netmask_t);
    403 int		npf_table_remove(npf_table_t *, const int,
    404 		    const npf_addr_t *, const npf_netmask_t);
    405 int		npf_table_lookup(npf_table_t *, const int, const npf_addr_t *);
    406 npf_addr_t *	npf_table_getsome(npf_table_t *, const int, unsigned);
    407 int		npf_table_list(npf_table_t *, void *, size_t);
    408 int		npf_table_flush(npf_table_t *);
    409 void		npf_table_gc(npf_t *, npf_table_t *);
    410 
    411 /* Ruleset interface. */
    412 npf_ruleset_t *	npf_ruleset_create(size_t);
    413 void		npf_ruleset_destroy(npf_ruleset_t *);
    414 void		npf_ruleset_insert(npf_ruleset_t *, npf_rule_t *);
    415 void		npf_ruleset_reload(npf_t *, npf_ruleset_t *,
    416 		    npf_ruleset_t *, bool);
    417 npf_natpolicy_t *npf_ruleset_findnat(npf_ruleset_t *, uint64_t);
    418 void		npf_ruleset_freealg(npf_ruleset_t *, npf_alg_t *);
    419 int		npf_ruleset_export(npf_t *, const npf_ruleset_t *,
    420 		    const char *, nvlist_t *);
    421 
    422 npf_rule_t *	npf_ruleset_lookup(npf_ruleset_t *, const char *);
    423 int		npf_ruleset_add(npf_ruleset_t *, const char *, npf_rule_t *);
    424 int		npf_ruleset_remove(npf_ruleset_t *, const char *, uint64_t);
    425 int		npf_ruleset_remkey(npf_ruleset_t *, const char *,
    426 		    const void *, size_t);
    427 int		npf_ruleset_list(npf_t *, npf_ruleset_t *, const char *, nvlist_t *);
    428 int		npf_ruleset_flush(npf_ruleset_t *, const char *);
    429 void		npf_ruleset_gc(npf_ruleset_t *);
    430 
    431 npf_rule_t *	npf_ruleset_inspect(npf_cache_t *, const npf_ruleset_t *,
    432 		    const int, const int);
    433 int		npf_rule_conclude(const npf_rule_t *, npf_match_info_t *);
    434 int		npf_rule_reverse(npf_cache_t *, npf_match_info_t *, int);
    435 
    436 /* Rule interface. */
    437 npf_rule_t *	npf_rule_alloc(npf_t *, const nvlist_t *);
    438 void		npf_rule_setcode(npf_rule_t *, int, void *, size_t);
    439 void		npf_rule_setrproc(npf_rule_t *, npf_rproc_t *);
    440 void		npf_rule_free(npf_rule_t *);
    441 uint64_t	npf_rule_getid(const npf_rule_t *);
    442 npf_natpolicy_t *npf_rule_getnat(const npf_rule_t *);
    443 void		npf_rule_setnat(npf_rule_t *, npf_natpolicy_t *);
    444 npf_rproc_t *	npf_rule_getrproc(const npf_rule_t *);
    445 
    446 int		npf_socket_lookup_rid(npf_cache_t *, get_rid_t, uint32_t *, int);
    447 void		npf_rule_setrid(const nvlist_t *, npf_rule_t *, const char *);
    448 int		npf_rule_match_rid(npf_rule_t *, npf_cache_t *, int);
    449 
    450 void		npf_ext_init(npf_t *);
    451 void		npf_ext_fini(npf_t *);
    452 int		npf_ext_construct(npf_t *, const char *,
    453 		    npf_rproc_t *, const nvlist_t *);
    454 
    455 npf_rprocset_t *npf_rprocset_create(void);
    456 void		npf_rprocset_destroy(npf_rprocset_t *);
    457 npf_rproc_t *	npf_rprocset_lookup(npf_rprocset_t *, const char *);
    458 void		npf_rprocset_insert(npf_rprocset_t *, npf_rproc_t *);
    459 int		npf_rprocset_export(const npf_rprocset_t *, nvlist_t *);
    460 
    461 npf_rproc_t *	npf_rproc_create(const nvlist_t *);
    462 void		npf_rproc_acquire(npf_rproc_t *);
    463 void		npf_rproc_release(npf_rproc_t *);
    464 const char *	npf_rproc_getname(const npf_rproc_t *);
    465 bool		npf_rproc_run(npf_cache_t *, npf_rproc_t *,
    466 		    const npf_match_info_t *, int *);
    467 
    468 /* State handling. */
    469 void		npf_state_sysinit(npf_t *);
    470 void		npf_state_sysfini(npf_t *);
    471 
    472 bool		npf_state_init(npf_cache_t *, npf_state_t *);
    473 bool		npf_state_inspect(npf_cache_t *, npf_state_t *, npf_flow_t);
    474 int		npf_state_etime(npf_t *, const npf_state_t *, const int);
    475 void		npf_state_destroy(npf_state_t *);
    476 void		npf_state_tcp_sysinit(npf_t *);
    477 void		npf_state_tcp_sysfini(npf_t *);
    478 bool		npf_state_tcp(npf_cache_t *, npf_state_t *, npf_flow_t);
    479 int		npf_state_tcp_timeout(npf_t *, const npf_state_t *);
    480 
    481 /* uid/gid process matching */
    482 int		npf_match_rid(rid_t *, uint32_t);
    483 
    484 /* Portmap. */
    485 void		npf_portmap_sysinit(void);
    486 void		npf_portmap_sysfini(void);
    487 
    488 void		npf_portmap_init(npf_t *);
    489 void		npf_portmap_fini(npf_t *);
    490 
    491 npf_portmap_t *	npf_portmap_create(int, int);
    492 void		npf_portmap_destroy(npf_portmap_t *);
    493 
    494 in_port_t	npf_portmap_get(npf_portmap_t *, int, const npf_addr_t *);
    495 bool		npf_portmap_take(npf_portmap_t *, int, const npf_addr_t *, in_port_t);
    496 void		npf_portmap_put(npf_portmap_t *, int, const npf_addr_t *, in_port_t);
    497 void		npf_portmap_flush(npf_portmap_t *);
    498 
    499 /* NAT. */
    500 void		npf_nat_sysinit(void);
    501 void		npf_nat_sysfini(void);
    502 npf_natpolicy_t *npf_natpolicy_create(npf_t *, const nvlist_t *, npf_ruleset_t *);
    503 int		npf_natpolicy_export(const npf_natpolicy_t *, nvlist_t *);
    504 void		npf_natpolicy_destroy(npf_natpolicy_t *);
    505 bool		npf_natpolicy_cmp(npf_natpolicy_t *, npf_natpolicy_t *);
    506 void		npf_nat_setid(npf_natpolicy_t *, uint64_t);
    507 uint64_t	npf_nat_getid(const npf_natpolicy_t *);
    508 void		npf_nat_freealg(npf_natpolicy_t *, npf_alg_t *);
    509 
    510 int		npf_do_nat(npf_cache_t *, npf_conn_t *, const unsigned);
    511 npf_nat_t *	npf_nat_share_policy(npf_cache_t *, npf_conn_t *, npf_nat_t *);
    512 void		npf_nat_destroy(npf_conn_t *, npf_nat_t *);
    513 void		npf_nat_getorig(npf_nat_t *, npf_addr_t **, in_port_t *);
    514 void		npf_nat_gettrans(npf_nat_t *, npf_addr_t **, in_port_t *);
    515 void		npf_nat_setalg(npf_nat_t *, npf_alg_t *, uintptr_t);
    516 npf_alg_t *	npf_nat_getalg(const npf_nat_t *);
    517 uintptr_t	npf_nat_getalgarg(const npf_nat_t *);
    518 
    519 void		npf_nat_export(npf_t *, const npf_nat_t *, nvlist_t *);
    520 npf_nat_t *	npf_nat_import(npf_t *, const nvlist_t *, npf_ruleset_t *,
    521 		    npf_conn_t *);
    522 
    523 /* ALG interface. */
    524 void		npf_alg_sysinit(void);
    525 void		npf_alg_sysfini(void);
    526 void		npf_alg_init(npf_t *);
    527 void		npf_alg_fini(npf_t *);
    528 npf_alg_t *	npf_alg_register(npf_t *, const char *, const npfa_funcs_t *);
    529 int		npf_alg_unregister(npf_t *, npf_alg_t *);
    530 npf_alg_t *	npf_alg_construct(npf_t *, const char *);
    531 bool		npf_alg_match(npf_cache_t *, npf_nat_t *, int);
    532 void		npf_alg_exec(npf_cache_t *, npf_nat_t *, const npf_flow_t);
    533 npf_conn_t *	npf_alg_conn(npf_cache_t *, int);
    534 int		npf_alg_export(npf_t *, nvlist_t *);
    535 void		npf_alg_destroy(npf_t *, npf_alg_t *, npf_nat_t *, npf_conn_t *);
    536 
    537 /* Wrappers for the reclamation mechanism. */
    538 ebr_t *		npf_ebr_create(void);
    539 void		npf_ebr_destroy(ebr_t *);
    540 void		npf_ebr_register(ebr_t *);
    541 void		npf_ebr_unregister(ebr_t *);
    542 int		npf_ebr_enter(ebr_t *);
    543 void		npf_ebr_exit(ebr_t *, int);
    544 void		npf_ebr_full_sync(ebr_t *);
    545 bool		npf_ebr_incrit_p(ebr_t *);
    546 
    547 /* Debugging routines. */
    548 const char *	npf_addr_dump(const npf_addr_t *, int);
    549 void		npf_state_dump(const npf_state_t *);
    550 void		npf_nat_dump(const npf_nat_t *);
    551 void		npf_ruleset_dump(npf_t *, const char *);
    552 void		npf_state_setsampler(void (*)(npf_state_t *, bool));
    553 
    554 /* In-kernel routines. */
    555 void		npf_setkernctx(npf_t *);
    556 npf_t *		npf_getkernctx(void);
    557 
    558 #endif	/* _NPF_IMPL_H_ */
    559