Home | History | Annotate | Line # | Download | only in libnpf
npf.h revision 1.33
      1 /*	$NetBSD: npf.h,v 1.33 2016/12/27 20:32:58 rmind Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2011-2014 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This material is based upon work partially supported by The
      8  * NetBSD Foundation under a contract with Mindaugas Rasiukevicius.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 #ifndef _NPF_LIB_H_
     33 #define _NPF_LIB_H_
     34 
     35 #include <sys/types.h>
     36 #include <net/npf.h>
     37 
     38 __BEGIN_DECLS
     39 
     40 struct nl_config;
     41 struct nl_rule;
     42 struct nl_rproc;
     43 struct nl_table;
     44 struct nl_ext;
     45 
     46 typedef struct nl_config	nl_config_t;
     47 typedef struct nl_rule		nl_rule_t;
     48 typedef struct nl_rproc		nl_rproc_t;
     49 typedef struct nl_table		nl_table_t;
     50 
     51 typedef struct nl_rule		nl_nat_t;
     52 
     53 typedef struct nl_ext		nl_ext_t;
     54 
     55 typedef int (*npfext_initfunc_t)(void);
     56 typedef nl_ext_t *(*npfext_consfunc_t)(const char *);
     57 typedef int (*npfext_paramfunc_t)(nl_ext_t *, const char *, const char *);
     58 
     59 #ifdef _NPF_PRIVATE
     60 
     61 typedef void (*nl_rule_callback_t)(nl_rule_t *, unsigned);
     62 typedef void (*nl_table_callback_t)(unsigned, int);
     63 
     64 #endif
     65 
     66 #define	NPF_MAX_TABLE_ID	(16)
     67 
     68 nl_config_t *	npf_config_create(void);
     69 void		npf_config_destroy(nl_config_t *);
     70 int		npf_config_submit(nl_config_t *, int, npf_error_t *);
     71 nl_config_t *	npf_config_retrieve(int);
     72 int		npf_config_flush(int);
     73 nl_config_t *	npf_config_import(const void *, size_t);
     74 void *		npf_config_export(nl_config_t *, size_t *);
     75 bool		npf_config_active_p(nl_config_t *);
     76 bool		npf_config_loaded_p(nl_config_t *);
     77 void *		npf_config_build(nl_config_t *);
     78 
     79 int		npf_ruleset_add(int, const char *, nl_rule_t *, uint64_t *);
     80 int		npf_ruleset_remove(int, const char *, uint64_t);
     81 int		npf_ruleset_remkey(int, const char *, const void *, size_t);
     82 int		npf_ruleset_flush(int, const char *);
     83 
     84 nl_ext_t *	npf_ext_construct(const char *name);
     85 void		npf_ext_param_u32(nl_ext_t *, const char *, uint32_t);
     86 void		npf_ext_param_bool(nl_ext_t *, const char *, bool);
     87 void		npf_ext_param_string(nl_ext_t *, const char *, const char *);
     88 
     89 nl_rule_t *	npf_rule_create(const char *, uint32_t, const char *);
     90 int		npf_rule_setcode(nl_rule_t *, int, const void *, size_t);
     91 int		npf_rule_setprio(nl_rule_t *, int);
     92 int		npf_rule_setproc(nl_rule_t *, const char *);
     93 int		npf_rule_setkey(nl_rule_t *, const void *, size_t);
     94 int		npf_rule_setinfo(nl_rule_t *, const void *, size_t);
     95 bool		npf_rule_exists_p(nl_config_t *, const char *);
     96 int		npf_rule_insert(nl_config_t *, nl_rule_t *, nl_rule_t *);
     97 void *		npf_rule_export(nl_rule_t *, size_t *);
     98 void		npf_rule_destroy(nl_rule_t *);
     99 
    100 nl_rproc_t *	npf_rproc_create(const char *);
    101 int		npf_rproc_extcall(nl_rproc_t *, nl_ext_t *);
    102 bool		npf_rproc_exists_p(nl_config_t *, const char *);
    103 int		npf_rproc_insert(nl_config_t *, nl_rproc_t *);
    104 
    105 nl_nat_t *	npf_nat_create(int, u_int, const char *,
    106 		    int, npf_addr_t *, npf_netmask_t, in_port_t);
    107 int		npf_nat_insert(nl_config_t *, nl_nat_t *, int);
    108 int		npf_nat_lookup(int, int, npf_addr_t *[2], in_port_t [2], int, int);
    109 
    110 nl_table_t *	npf_table_create(const char *, u_int, int);
    111 int		npf_table_add_entry(nl_table_t *, int,
    112 		    const npf_addr_t *, const npf_netmask_t);
    113 int		npf_table_setdata(nl_table_t *, const void *, size_t);
    114 int		npf_table_insert(nl_config_t *, nl_table_t *);
    115 void		npf_table_destroy(nl_table_t *);
    116 
    117 #ifdef _NPF_PRIVATE
    118 
    119 #include <ifaddrs.h>
    120 
    121 nl_rule_t *	npf_rule_iterate(nl_config_t *, unsigned *);
    122 const char *	npf_rule_getname(nl_rule_t *);
    123 uint32_t	npf_rule_getattr(nl_rule_t *);
    124 const char *	npf_rule_getinterface(nl_rule_t *);
    125 const void *	npf_rule_getinfo(nl_rule_t *, size_t *);
    126 const char *	npf_rule_getproc(nl_rule_t *);
    127 uint64_t	npf_rule_getid(nl_rule_t *);
    128 const void *	npf_rule_getcode(nl_rule_t *, int *, size_t *);
    129 
    130 nl_table_t *	npf_table_iterate(nl_config_t *);
    131 const char *	npf_table_getname(nl_table_t *);
    132 unsigned	npf_table_getid(nl_table_t *);
    133 int		npf_table_gettype(nl_table_t *);
    134 
    135 nl_nat_t *	npf_nat_iterate(nl_config_t *);
    136 int		npf_nat_gettype(nl_nat_t *);
    137 unsigned	npf_nat_getflags(nl_nat_t *);
    138 void		npf_nat_getmap(nl_nat_t *, npf_addr_t *, size_t *, in_port_t *);
    139 
    140 int		npf_nat_setalgo(nl_nat_t *, u_int);
    141 int		npf_nat_setnpt66(nl_nat_t *, uint16_t);
    142 
    143 nl_rproc_t *	npf_rproc_iterate(nl_config_t *);
    144 const char *	npf_rproc_getname(nl_rproc_t *);
    145 
    146 int		_npf_ruleset_list(int, const char *, nl_config_t *);
    147 void		_npf_debug_addif(nl_config_t *, const char *);
    148 
    149 /* The ALG interface is experimental */
    150 int 		_npf_alg_load(nl_config_t *, const char *);
    151 int		_npf_alg_unload(nl_config_t *, const char *);
    152 
    153 typedef int (*npf_conn_func_t)(unsigned, const npf_addr_t *,
    154     const in_port_t *, const char *, void *);
    155 int		npf_conn_list(int, npf_conn_func_t, void *);
    156 
    157 #endif
    158 
    159 __END_DECLS
    160 
    161 #endif	/* _NPF_LIB_H_ */
    162