2017-01-29 03:15:54 +03:00
|
|
|
/* $NetBSD: npf_impl.h,v 1.68 2017/01/29 00:15:54 christos Exp $ */
|
2010-08-22 22:56:18 +04:00
|
|
|
|
|
|
|
/*-
|
2014-02-13 07:34:40 +04:00
|
|
|
* Copyright (c) 2009-2014 The NetBSD Foundation, Inc.
|
2010-08-22 22:56:18 +04:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This material is based upon work partially supported by The
|
|
|
|
* NetBSD Foundation under a contract with Mindaugas Rasiukevicius.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Private NPF structures and interfaces.
|
|
|
|
* For internal use within NPF core only.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _NPF_IMPL_H_
|
|
|
|
#define _NPF_IMPL_H_
|
|
|
|
|
2016-12-27 02:05:05 +03:00
|
|
|
#if !defined(_KERNEL) && !defined(_NPF_STANDALONE)
|
2011-02-02 05:20:24 +03:00
|
|
|
#error "Kernel-level header only"
|
|
|
|
#endif
|
|
|
|
|
2012-07-02 03:21:06 +04:00
|
|
|
#ifdef _KERNEL_OPT
|
|
|
|
/* For INET/INET6 definitions. */
|
|
|
|
#include "opt_inet.h"
|
|
|
|
#include "opt_inet6.h"
|
|
|
|
#endif
|
|
|
|
|
2016-12-27 02:05:05 +03:00
|
|
|
#ifdef _KERNEL
|
2010-08-22 22:56:18 +04:00
|
|
|
#include <sys/types.h>
|
2010-11-11 09:30:39 +03:00
|
|
|
#include <sys/queue.h>
|
2016-12-27 02:05:05 +03:00
|
|
|
#include <sys/rbtree.h>
|
2013-09-19 05:04:45 +04:00
|
|
|
|
|
|
|
#include <net/bpf.h>
|
|
|
|
#include <net/bpfjit.h>
|
2011-01-18 23:33:45 +03:00
|
|
|
#include <net/if.h>
|
2016-12-27 02:05:05 +03:00
|
|
|
#endif
|
2010-08-22 22:56:18 +04:00
|
|
|
|
|
|
|
#include "npf.h"
|
2016-12-27 02:05:05 +03:00
|
|
|
#include "npfkern.h"
|
2010-08-22 22:56:18 +04:00
|
|
|
|
2011-01-18 23:33:45 +03:00
|
|
|
#ifdef _NPF_DEBUG
|
|
|
|
#define NPF_PRINTF(x) printf x
|
|
|
|
#else
|
|
|
|
#define NPF_PRINTF(x)
|
|
|
|
#endif
|
|
|
|
|
2010-08-22 22:56:18 +04:00
|
|
|
/*
|
|
|
|
* STRUCTURE DECLARATIONS.
|
|
|
|
*/
|
|
|
|
|
2011-02-02 05:20:24 +03:00
|
|
|
struct npf_ruleset;
|
|
|
|
struct npf_rule;
|
2013-02-09 07:35:31 +04:00
|
|
|
struct npf_rprocset;
|
2010-08-22 22:56:18 +04:00
|
|
|
struct npf_nat;
|
2014-07-19 22:24:16 +04:00
|
|
|
struct npf_conn;
|
2016-12-27 02:05:05 +03:00
|
|
|
struct npf_config;
|
2010-08-22 22:56:18 +04:00
|
|
|
|
2011-02-02 05:20:24 +03:00
|
|
|
typedef struct npf_ruleset npf_ruleset_t;
|
|
|
|
typedef struct npf_rule npf_rule_t;
|
2010-08-22 22:56:18 +04:00
|
|
|
typedef struct npf_nat npf_nat_t;
|
2013-02-09 07:35:31 +04:00
|
|
|
typedef struct npf_rprocset npf_rprocset_t;
|
2010-08-22 22:56:18 +04:00
|
|
|
typedef struct npf_alg npf_alg_t;
|
|
|
|
typedef struct npf_natpolicy npf_natpolicy_t;
|
2014-07-19 22:24:16 +04:00
|
|
|
typedef struct npf_conn npf_conn_t;
|
2016-12-27 02:05:05 +03:00
|
|
|
typedef struct npf_config npf_config_t;
|
2010-08-22 22:56:18 +04:00
|
|
|
|
2014-07-19 22:24:16 +04:00
|
|
|
struct npf_conndb;
|
2010-08-22 22:56:18 +04:00
|
|
|
struct npf_table;
|
2013-11-12 04:46:34 +04:00
|
|
|
struct npf_tableset;
|
2016-12-27 02:05:05 +03:00
|
|
|
struct npf_algset;
|
|
|
|
struct npf_ifmap;
|
2010-08-22 22:56:18 +04:00
|
|
|
|
2014-07-19 22:24:16 +04:00
|
|
|
typedef struct npf_conndb npf_conndb_t;
|
2010-08-22 22:56:18 +04:00
|
|
|
typedef struct npf_table npf_table_t;
|
2013-11-12 04:46:34 +04:00
|
|
|
typedef struct npf_tableset npf_tableset_t;
|
2016-12-27 02:05:05 +03:00
|
|
|
typedef struct npf_algset npf_algset_t;
|
2010-08-22 22:56:18 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* DEFINITIONS.
|
|
|
|
*/
|
|
|
|
|
2016-12-27 02:05:05 +03:00
|
|
|
typedef void (*npf_workfunc_t)(npf_t *);
|
2010-08-22 22:56:18 +04:00
|
|
|
|
2013-12-06 05:33:37 +04:00
|
|
|
/*
|
|
|
|
* Some artificial limits.
|
|
|
|
* Note: very unlikely to have many ALGs.
|
|
|
|
*/
|
2013-10-27 20:22:08 +04:00
|
|
|
#define NPF_MAX_RULES (1024 * 1024)
|
2013-11-12 04:46:34 +04:00
|
|
|
#define NPF_MAX_TABLES 128
|
|
|
|
#define NPF_MAX_RPROCS 128
|
2013-11-08 04:38:26 +04:00
|
|
|
#define NPF_MAX_IFMAP 64
|
2016-12-27 02:05:05 +03:00
|
|
|
#define NPF_MAX_ALGS 4
|
|
|
|
#define NPF_MAX_WORKS 4
|
2010-08-22 22:56:18 +04:00
|
|
|
|
2010-11-11 09:30:39 +03:00
|
|
|
/*
|
2014-08-10 23:09:43 +04:00
|
|
|
* CONNECTION STATE STRUCTURES
|
2010-11-11 09:30:39 +03:00
|
|
|
*/
|
|
|
|
|
2011-11-30 00:05:30 +04:00
|
|
|
#define NPF_FLOW_FORW 0
|
|
|
|
#define NPF_FLOW_BACK 1
|
|
|
|
|
2010-11-11 09:30:39 +03:00
|
|
|
typedef struct {
|
2011-11-30 00:05:30 +04:00
|
|
|
uint32_t nst_end;
|
|
|
|
uint32_t nst_maxend;
|
|
|
|
uint32_t nst_maxwin;
|
|
|
|
int nst_wscale;
|
2010-11-11 09:30:39 +03:00
|
|
|
} npf_tcpstate_t;
|
|
|
|
|
|
|
|
typedef struct {
|
2013-11-05 02:17:21 +04:00
|
|
|
u_int nst_state;
|
2010-11-11 09:30:39 +03:00
|
|
|
npf_tcpstate_t nst_tcpst[2];
|
|
|
|
} npf_state_t;
|
|
|
|
|
2014-02-17 02:10:40 +04:00
|
|
|
/*
|
|
|
|
* ALG FUNCTIONS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
typedef struct {
|
2014-07-20 04:37:41 +04:00
|
|
|
bool (*match)(npf_cache_t *, npf_nat_t *, int);
|
|
|
|
bool (*translate)(npf_cache_t *, npf_nat_t *, bool);
|
|
|
|
npf_conn_t * (*inspect)(npf_cache_t *, int);
|
2014-02-17 02:10:40 +04:00
|
|
|
} npfa_funcs_t;
|
|
|
|
|
2016-12-27 02:05:05 +03:00
|
|
|
/*
|
|
|
|
* NBUF STRUCTURE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct nbuf {
|
|
|
|
struct mbuf * nb_mbuf0;
|
|
|
|
struct mbuf * nb_mbuf;
|
|
|
|
void * nb_nptr;
|
|
|
|
const ifnet_t * nb_ifp;
|
|
|
|
unsigned nb_ifid;
|
|
|
|
int nb_flags;
|
|
|
|
const npf_mbufops_t *nb_mops;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* NPF INSTANCE (CONTEXT) STRUCTURE AND AUXILIARY OPERATIONS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct npf {
|
|
|
|
/* Active NPF configuration. */
|
|
|
|
kmutex_t config_lock;
|
|
|
|
pserialize_t qsbr;
|
|
|
|
npf_config_t * config;
|
|
|
|
|
|
|
|
/* BPF byte-code context. */
|
|
|
|
bpf_ctx_t * bpfctx;
|
|
|
|
const npf_mbufops_t * mbufops;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Connection tracking state: disabled (off) or enabled (on).
|
|
|
|
* Connection tracking database, connection cache and the lock.
|
|
|
|
*/
|
|
|
|
volatile int conn_tracking;
|
|
|
|
kmutex_t conn_lock;
|
|
|
|
npf_conndb_t * conn_db;
|
|
|
|
pool_cache_t conn_cache;
|
|
|
|
|
|
|
|
/* ALGs. */
|
|
|
|
npf_algset_t * algset;
|
|
|
|
|
|
|
|
/* Interface mapping. */
|
|
|
|
const npf_ifops_t * ifops;
|
|
|
|
struct npf_ifmap * ifmap;
|
|
|
|
unsigned ifmap_cnt;
|
|
|
|
|
|
|
|
/* Associated worker thread. */
|
|
|
|
unsigned worker_id;
|
|
|
|
void * worker_entry;
|
|
|
|
|
|
|
|
/* List of extensions and its lock. */
|
|
|
|
LIST_HEAD(, npf_ext) ext_list;
|
|
|
|
kmutex_t ext_lock;
|
|
|
|
|
|
|
|
/* Statistics. */
|
|
|
|
percpu_t * stats_percpu;
|
|
|
|
};
|
|
|
|
|
2010-08-22 22:56:18 +04:00
|
|
|
/*
|
|
|
|
* INTERFACES.
|
|
|
|
*/
|
|
|
|
|
2013-02-09 07:35:31 +04:00
|
|
|
/* NPF config, statistics, etc. */
|
2016-12-27 02:05:05 +03:00
|
|
|
void npf_config_init(npf_t *);
|
|
|
|
void npf_config_fini(npf_t *);
|
2013-02-09 07:35:31 +04:00
|
|
|
|
2016-12-27 02:05:05 +03:00
|
|
|
void npf_config_enter(npf_t *);
|
|
|
|
void npf_config_exit(npf_t *);
|
|
|
|
void npf_config_sync(npf_t *);
|
|
|
|
bool npf_config_locked_p(npf_t *);
|
2013-02-09 07:35:31 +04:00
|
|
|
int npf_config_read_enter(void);
|
2016-12-27 02:05:05 +03:00
|
|
|
void npf_config_read_exit(int s);
|
2013-02-09 07:35:31 +04:00
|
|
|
|
2016-12-27 02:05:05 +03:00
|
|
|
void npf_config_load(npf_t *, npf_ruleset_t *, npf_tableset_t *,
|
2014-08-11 05:54:12 +04:00
|
|
|
npf_ruleset_t *, npf_rprocset_t *, npf_conndb_t *, bool);
|
2016-12-27 02:05:05 +03:00
|
|
|
npf_ruleset_t * npf_config_ruleset(npf_t *npf);
|
|
|
|
npf_ruleset_t * npf_config_natset(npf_t *npf);
|
|
|
|
npf_tableset_t *npf_config_tableset(npf_t *npf);
|
|
|
|
npf_rprocset_t *npf_config_rprocs(npf_t *);
|
|
|
|
bool npf_default_pass(npf_t *);
|
2010-12-18 04:07:25 +03:00
|
|
|
|
2016-12-27 02:05:05 +03:00
|
|
|
int npf_worker_sysinit(unsigned);
|
2013-06-02 06:20:04 +04:00
|
|
|
void npf_worker_sysfini(void);
|
2016-12-27 02:05:05 +03:00
|
|
|
void npf_worker_signal(npf_t *);
|
|
|
|
void npf_worker_register(npf_t *, npf_workfunc_t);
|
|
|
|
void npf_worker_unregister(npf_t *, npf_workfunc_t);
|
2013-06-02 06:20:04 +04:00
|
|
|
|
2010-08-22 22:56:18 +04:00
|
|
|
int npfctl_switch(void *);
|
|
|
|
int npfctl_reload(u_long, void *);
|
2016-12-27 02:05:05 +03:00
|
|
|
int npfctl_save(npf_t *, u_long, void *);
|
|
|
|
int npfctl_load(npf_t *, u_long, void *);
|
|
|
|
int npfctl_rule(npf_t *, u_long, void *);
|
|
|
|
int npfctl_conn_lookup(npf_t *, u_long, void *);
|
|
|
|
int npfctl_table(npf_t *, void *);
|
|
|
|
|
|
|
|
void npf_stats_inc(npf_t *, npf_stats_t);
|
|
|
|
void npf_stats_dec(npf_t *, npf_stats_t);
|
|
|
|
|
|
|
|
void npf_ifmap_init(npf_t *, const npf_ifops_t *);
|
|
|
|
void npf_ifmap_fini(npf_t *);
|
|
|
|
u_int npf_ifmap_register(npf_t *, const char *);
|
|
|
|
void npf_ifmap_flush(npf_t *);
|
|
|
|
u_int npf_ifmap_getid(npf_t *, const ifnet_t *);
|
|
|
|
const char * npf_ifmap_getname(npf_t *, const u_int);
|
2013-11-08 04:38:26 +04:00
|
|
|
|
2017-01-03 00:49:51 +03:00
|
|
|
void npf_ifaddr_sync(npf_t *, ifnet_t *);
|
|
|
|
void npf_ifaddr_flush(npf_t *, ifnet_t *);
|
2017-01-03 03:58:05 +03:00
|
|
|
void npf_ifaddr_syncall(npf_t *);
|
2017-01-03 00:49:51 +03:00
|
|
|
|
2010-08-22 22:56:18 +04:00
|
|
|
/* Packet filter hooks. */
|
2013-11-08 04:38:26 +04:00
|
|
|
int npf_pfil_register(bool);
|
|
|
|
void npf_pfil_unregister(bool);
|
2012-03-11 22:27:59 +04:00
|
|
|
bool npf_pfil_registered_p(void);
|
2010-08-22 22:56:18 +04:00
|
|
|
|
|
|
|
/* Protocol helpers. */
|
2014-07-20 04:37:41 +04:00
|
|
|
int npf_cache_all(npf_cache_t *);
|
|
|
|
void npf_recache(npf_cache_t *);
|
2010-08-22 22:56:18 +04:00
|
|
|
|
2013-12-06 05:33:37 +04:00
|
|
|
bool npf_rwrip(const npf_cache_t *, u_int, const npf_addr_t *);
|
|
|
|
bool npf_rwrport(const npf_cache_t *, u_int, const in_port_t);
|
|
|
|
bool npf_rwrcksum(const npf_cache_t *, u_int,
|
2012-12-24 23:05:42 +04:00
|
|
|
const npf_addr_t *, const in_port_t);
|
2014-02-19 07:51:31 +04:00
|
|
|
int npf_napt_rwr(const npf_cache_t *, u_int, const npf_addr_t *,
|
|
|
|
const in_addr_t);
|
2014-02-13 07:34:40 +04:00
|
|
|
int npf_npt66_rwr(const npf_cache_t *, u_int, const npf_addr_t *,
|
|
|
|
npf_netmask_t, uint16_t);
|
2010-08-22 22:56:18 +04:00
|
|
|
|
|
|
|
uint16_t npf_fixup16_cksum(uint16_t, uint16_t, uint16_t);
|
|
|
|
uint16_t npf_fixup32_cksum(uint16_t, uint32_t, uint32_t);
|
2012-12-24 23:05:42 +04:00
|
|
|
uint16_t npf_addr_cksum(uint16_t, int, const npf_addr_t *,
|
|
|
|
const npf_addr_t *);
|
2013-11-22 05:24:21 +04:00
|
|
|
uint32_t npf_addr_mix(const int, const npf_addr_t *, const npf_addr_t *);
|
2012-06-22 17:43:17 +04:00
|
|
|
int npf_addr_cmp(const npf_addr_t *, const npf_netmask_t,
|
2012-07-02 03:21:06 +04:00
|
|
|
const npf_addr_t *, const npf_netmask_t, const int);
|
2012-06-22 17:43:17 +04:00
|
|
|
void npf_addr_mask(const npf_addr_t *, const npf_netmask_t,
|
2012-07-02 03:21:06 +04:00
|
|
|
const int, npf_addr_t *);
|
2012-06-22 17:43:17 +04:00
|
|
|
|
|
|
|
int npf_tcpsaw(const npf_cache_t *, tcp_seq *, tcp_seq *,
|
|
|
|
uint32_t *);
|
2014-07-20 04:37:41 +04:00
|
|
|
bool npf_fetch_tcpopts(npf_cache_t *, uint16_t *, int *);
|
|
|
|
bool npf_return_block(npf_cache_t *, const int);
|
2010-09-16 08:53:27 +04:00
|
|
|
|
2013-09-19 05:04:45 +04:00
|
|
|
/* BPF interface. */
|
|
|
|
void npf_bpf_sysinit(void);
|
|
|
|
void npf_bpf_sysfini(void);
|
2014-07-20 04:37:41 +04:00
|
|
|
void npf_bpf_prepare(npf_cache_t *, bpf_args_t *, uint32_t *);
|
2013-11-23 23:32:20 +04:00
|
|
|
int npf_bpf_filter(bpf_args_t *, const void *, bpfjit_func_t);
|
2013-11-16 05:18:58 +04:00
|
|
|
void * npf_bpf_compile(void *, size_t);
|
2013-09-19 05:04:45 +04:00
|
|
|
bool npf_bpf_validate(const void *, size_t);
|
|
|
|
|
2010-08-22 22:56:18 +04:00
|
|
|
/* Tableset interface. */
|
2010-12-18 04:07:25 +03:00
|
|
|
void npf_tableset_sysinit(void);
|
2010-08-22 22:56:18 +04:00
|
|
|
void npf_tableset_sysfini(void);
|
|
|
|
|
2013-11-12 04:46:34 +04:00
|
|
|
npf_tableset_t *npf_tableset_create(u_int);
|
2010-08-22 22:56:18 +04:00
|
|
|
void npf_tableset_destroy(npf_tableset_t *);
|
|
|
|
int npf_tableset_insert(npf_tableset_t *, npf_table_t *);
|
2013-11-12 04:46:34 +04:00
|
|
|
npf_table_t * npf_tableset_getbyname(npf_tableset_t *, const char *);
|
|
|
|
npf_table_t * npf_tableset_getbyid(npf_tableset_t *, u_int);
|
2017-01-03 00:49:51 +03:00
|
|
|
npf_table_t * npf_tableset_swap(npf_tableset_t *, npf_table_t *);
|
2016-12-27 02:05:05 +03:00
|
|
|
void npf_tableset_reload(npf_t *, npf_tableset_t *, npf_tableset_t *);
|
|
|
|
int npf_tableset_export(npf_t *, const npf_tableset_t *, prop_array_t);
|
2010-08-22 22:56:18 +04:00
|
|
|
|
2014-02-06 06:51:28 +04:00
|
|
|
npf_table_t * npf_table_create(const char *, u_int, int, void *, size_t);
|
2010-08-22 22:56:18 +04:00
|
|
|
void npf_table_destroy(npf_table_t *);
|
|
|
|
|
2017-01-03 00:49:51 +03:00
|
|
|
u_int npf_table_getid(npf_table_t *);
|
2013-11-12 04:46:34 +04:00
|
|
|
int npf_table_check(npf_tableset_t *, const char *, u_int, int);
|
|
|
|
int npf_table_insert(npf_table_t *, const int,
|
|
|
|
const npf_addr_t *, const npf_netmask_t);
|
|
|
|
int npf_table_remove(npf_table_t *, const int,
|
|
|
|
const npf_addr_t *, const npf_netmask_t);
|
|
|
|
int npf_table_lookup(npf_table_t *, const int, const npf_addr_t *);
|
|
|
|
int npf_table_list(npf_table_t *, void *, size_t);
|
|
|
|
int npf_table_flush(npf_table_t *);
|
2010-08-22 22:56:18 +04:00
|
|
|
|
|
|
|
/* Ruleset interface. */
|
2013-02-09 07:35:31 +04:00
|
|
|
npf_ruleset_t * npf_ruleset_create(size_t);
|
2010-08-22 22:56:18 +04:00
|
|
|
void npf_ruleset_destroy(npf_ruleset_t *);
|
|
|
|
void npf_ruleset_insert(npf_ruleset_t *, npf_rule_t *);
|
2016-12-27 02:05:05 +03:00
|
|
|
void npf_ruleset_reload(npf_t *, npf_ruleset_t *,
|
|
|
|
npf_ruleset_t *, bool);
|
2011-01-18 23:33:45 +03:00
|
|
|
npf_rule_t * npf_ruleset_sharepm(npf_ruleset_t *, npf_natpolicy_t *);
|
2014-07-23 05:25:34 +04:00
|
|
|
npf_natpolicy_t *npf_ruleset_findnat(npf_ruleset_t *, uint64_t);
|
2012-07-15 04:22:58 +04:00
|
|
|
void npf_ruleset_freealg(npf_ruleset_t *, npf_alg_t *);
|
2016-12-27 02:05:05 +03:00
|
|
|
int npf_ruleset_export(npf_t *, const npf_ruleset_t *, prop_array_t);
|
2010-08-22 22:56:18 +04:00
|
|
|
|
2013-02-09 07:35:31 +04:00
|
|
|
int npf_ruleset_add(npf_ruleset_t *, const char *, npf_rule_t *);
|
2013-02-17 01:11:12 +04:00
|
|
|
int npf_ruleset_remove(npf_ruleset_t *, const char *, uint64_t);
|
2013-02-11 03:47:37 +04:00
|
|
|
int npf_ruleset_remkey(npf_ruleset_t *, const char *,
|
2013-02-09 07:35:31 +04:00
|
|
|
const void *, size_t);
|
2016-12-27 02:05:05 +03:00
|
|
|
prop_dictionary_t npf_ruleset_list(npf_t *, npf_ruleset_t *, const char *);
|
2013-02-11 03:47:37 +04:00
|
|
|
int npf_ruleset_flush(npf_ruleset_t *, const char *);
|
|
|
|
void npf_ruleset_gc(npf_ruleset_t *);
|
2013-02-09 07:35:31 +04:00
|
|
|
|
2014-07-20 04:37:41 +04:00
|
|
|
npf_rule_t * npf_ruleset_inspect(npf_cache_t *, const npf_ruleset_t *,
|
|
|
|
const int, const int);
|
2017-01-29 03:15:54 +03:00
|
|
|
int npf_rule_conclude(const npf_rule_t *, npf_match_info_t *);
|
2010-08-22 22:56:18 +04:00
|
|
|
|
2011-02-02 05:20:24 +03:00
|
|
|
/* Rule interface. */
|
2016-12-27 02:05:05 +03:00
|
|
|
npf_rule_t * npf_rule_alloc(npf_t *, prop_dictionary_t);
|
2013-02-09 07:35:31 +04:00
|
|
|
void npf_rule_setcode(npf_rule_t *, int, void *, size_t);
|
|
|
|
void npf_rule_setrproc(npf_rule_t *, npf_rproc_t *);
|
2011-02-02 05:20:24 +03:00
|
|
|
void npf_rule_free(npf_rule_t *);
|
2013-02-17 01:11:12 +04:00
|
|
|
uint64_t npf_rule_getid(const npf_rule_t *);
|
2010-08-22 22:56:18 +04:00
|
|
|
npf_natpolicy_t *npf_rule_getnat(const npf_rule_t *);
|
|
|
|
void npf_rule_setnat(npf_rule_t *, npf_natpolicy_t *);
|
2013-12-04 05:38:49 +04:00
|
|
|
npf_rproc_t * npf_rule_getrproc(const npf_rule_t *);
|
2010-08-22 22:56:18 +04:00
|
|
|
|
2016-12-27 02:05:05 +03:00
|
|
|
void npf_ext_init(npf_t *);
|
|
|
|
void npf_ext_fini(npf_t *);
|
|
|
|
int npf_ext_construct(npf_t *, const char *,
|
2012-09-16 17:47:41 +04:00
|
|
|
npf_rproc_t *, prop_dictionary_t);
|
|
|
|
|
2013-02-09 07:35:31 +04:00
|
|
|
npf_rprocset_t *npf_rprocset_create(void);
|
|
|
|
void npf_rprocset_destroy(npf_rprocset_t *);
|
|
|
|
npf_rproc_t * npf_rprocset_lookup(npf_rprocset_t *, const char *);
|
|
|
|
void npf_rprocset_insert(npf_rprocset_t *, npf_rproc_t *);
|
2014-08-11 05:54:12 +04:00
|
|
|
int npf_rprocset_export(const npf_rprocset_t *, prop_array_t);
|
2013-02-09 07:35:31 +04:00
|
|
|
|
2010-12-18 04:07:25 +03:00
|
|
|
npf_rproc_t * npf_rproc_create(prop_dictionary_t);
|
2012-02-07 03:30:14 +04:00
|
|
|
void npf_rproc_acquire(npf_rproc_t *);
|
2010-12-18 04:07:25 +03:00
|
|
|
void npf_rproc_release(npf_rproc_t *);
|
2016-12-29 00:55:04 +03:00
|
|
|
const char * npf_rproc_getname(const npf_rproc_t *);
|
2017-01-29 03:15:54 +03:00
|
|
|
bool npf_rproc_run(npf_cache_t *, npf_rproc_t *,
|
|
|
|
const npf_match_info_t *, int *);
|
2010-12-18 04:07:25 +03:00
|
|
|
|
2010-11-11 09:30:39 +03:00
|
|
|
/* State handling. */
|
2014-07-20 04:37:41 +04:00
|
|
|
bool npf_state_init(npf_cache_t *, npf_state_t *);
|
|
|
|
bool npf_state_inspect(npf_cache_t *, npf_state_t *, const bool);
|
2010-11-11 09:30:39 +03:00
|
|
|
int npf_state_etime(const npf_state_t *, const int);
|
|
|
|
void npf_state_destroy(npf_state_t *);
|
|
|
|
|
2014-07-20 04:37:41 +04:00
|
|
|
bool npf_state_tcp(npf_cache_t *, npf_state_t *, int);
|
2011-11-30 00:05:30 +04:00
|
|
|
int npf_state_tcp_timeout(const npf_state_t *);
|
|
|
|
|
2010-08-22 22:56:18 +04:00
|
|
|
/* NAT. */
|
|
|
|
void npf_nat_sysinit(void);
|
|
|
|
void npf_nat_sysfini(void);
|
2016-12-27 02:05:05 +03:00
|
|
|
npf_natpolicy_t *npf_nat_newpolicy(npf_t *, prop_dictionary_t, npf_ruleset_t *);
|
2014-08-10 23:09:43 +04:00
|
|
|
int npf_nat_policyexport(const npf_natpolicy_t *, prop_dictionary_t);
|
2010-08-22 22:56:18 +04:00
|
|
|
void npf_nat_freepolicy(npf_natpolicy_t *);
|
2014-07-23 05:25:34 +04:00
|
|
|
bool npf_nat_cmppolicy(npf_natpolicy_t *, npf_natpolicy_t *);
|
2011-01-18 23:33:45 +03:00
|
|
|
bool npf_nat_sharepm(npf_natpolicy_t *, npf_natpolicy_t *);
|
2014-07-23 05:25:34 +04:00
|
|
|
void npf_nat_setid(npf_natpolicy_t *, uint64_t);
|
|
|
|
uint64_t npf_nat_getid(const npf_natpolicy_t *);
|
2012-07-15 04:22:58 +04:00
|
|
|
void npf_nat_freealg(npf_natpolicy_t *, npf_alg_t *);
|
2010-08-22 22:56:18 +04:00
|
|
|
|
2014-07-20 04:37:41 +04:00
|
|
|
int npf_do_nat(npf_cache_t *, npf_conn_t *, const int);
|
2013-12-04 05:38:49 +04:00
|
|
|
void npf_nat_destroy(npf_nat_t *);
|
2010-11-11 09:30:39 +03:00
|
|
|
void npf_nat_getorig(npf_nat_t *, npf_addr_t **, in_port_t *);
|
2010-12-18 04:07:25 +03:00
|
|
|
void npf_nat_gettrans(npf_nat_t *, npf_addr_t **, in_port_t *);
|
2010-08-22 22:56:18 +04:00
|
|
|
void npf_nat_setalg(npf_nat_t *, npf_alg_t *, uintptr_t);
|
|
|
|
|
2014-07-23 05:25:34 +04:00
|
|
|
void npf_nat_export(prop_dictionary_t, npf_nat_t *);
|
2016-12-27 02:05:05 +03:00
|
|
|
npf_nat_t * npf_nat_import(npf_t *, prop_dictionary_t, npf_ruleset_t *,
|
2014-07-23 05:25:34 +04:00
|
|
|
npf_conn_t *);
|
2010-12-18 04:07:25 +03:00
|
|
|
|
2010-08-22 22:56:18 +04:00
|
|
|
/* ALG interface. */
|
2016-12-27 02:05:05 +03:00
|
|
|
void npf_alg_init(npf_t *);
|
|
|
|
void npf_alg_fini(npf_t *);
|
|
|
|
npf_alg_t * npf_alg_register(npf_t *, const char *, const npfa_funcs_t *);
|
|
|
|
int npf_alg_unregister(npf_t *, npf_alg_t *);
|
|
|
|
npf_alg_t * npf_alg_construct(npf_t *, const char *);
|
2014-07-20 04:37:41 +04:00
|
|
|
bool npf_alg_match(npf_cache_t *, npf_nat_t *, int);
|
|
|
|
void npf_alg_exec(npf_cache_t *, npf_nat_t *, bool);
|
|
|
|
npf_conn_t * npf_alg_conn(npf_cache_t *, int);
|
2016-12-27 02:05:05 +03:00
|
|
|
prop_array_t npf_alg_export(npf_t *);
|
2010-08-22 22:56:18 +04:00
|
|
|
|
|
|
|
/* Debugging routines. */
|
2014-07-19 22:24:16 +04:00
|
|
|
const char * npf_addr_dump(const npf_addr_t *, int);
|
2012-07-02 03:21:06 +04:00
|
|
|
void npf_state_dump(const npf_state_t *);
|
|
|
|
void npf_nat_dump(const npf_nat_t *);
|
2016-12-27 02:05:05 +03:00
|
|
|
void npf_ruleset_dump(npf_t *, const char *);
|
2012-08-15 23:47:38 +04:00
|
|
|
void npf_state_setsampler(void (*)(npf_state_t *, bool));
|
2010-08-22 22:56:18 +04:00
|
|
|
|
2016-12-27 02:05:05 +03:00
|
|
|
/* In-kernel routines. */
|
|
|
|
void npf_setkernctx(npf_t *);
|
|
|
|
npf_t * npf_getkernctx(void);
|
|
|
|
|
|
|
|
#ifdef __NetBSD__
|
|
|
|
#define pserialize_register(x)
|
|
|
|
#define pserialize_checkpoint(x)
|
|
|
|
#endif
|
|
|
|
|
2011-02-02 05:20:24 +03:00
|
|
|
#endif /* _NPF_IMPL_H_ */
|