Home | History | Annotate | Line # | Download | only in libnpf
npf.h revision 1.10
      1 /*	$NetBSD: npf.h,v 1.10 2012/08/12 03:35:14 rmind Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2011-2012 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 #ifdef _NPF_TESTING
     39 #include "testing.h"
     40 #endif
     41 
     42 __BEGIN_DECLS
     43 
     44 struct nl_config;
     45 struct nl_rule;
     46 struct nl_rproc;
     47 struct nl_table;
     48 
     49 typedef struct nl_config	nl_config_t;
     50 typedef struct nl_rule		nl_rule_t;
     51 typedef struct nl_rproc		nl_rproc_t;
     52 typedef struct nl_table		nl_table_t;
     53 
     54 typedef struct nl_rule		nl_nat_t;
     55 
     56 #ifdef _NPF_PRIVATE
     57 
     58 typedef struct {
     59 	int		ne_id;
     60 	char *		ne_source_file;
     61 	u_int		ne_source_line;
     62 	int		ne_ncode_error;
     63 	int		ne_ncode_errat;
     64 } nl_error_t;
     65 
     66 typedef void (*nl_rule_callback_t)(nl_rule_t *, unsigned);
     67 typedef void (*nl_table_callback_t)(unsigned, int);
     68 
     69 #endif
     70 
     71 #define	NPF_CODE_NCODE		1
     72 #define	NPF_CODE_BPF		2
     73 
     74 #define	NPF_PRI_NEXT		(-1)
     75 
     76 #define	NPF_MAX_TABLE_ID	(16)
     77 
     78 nl_config_t *	npf_config_create(void);
     79 int		npf_config_submit(nl_config_t *, int);
     80 void		npf_config_destroy(nl_config_t *);
     81 nl_config_t *	npf_config_retrieve(int, bool *, bool *);
     82 int		npf_config_flush(int);
     83 
     84 nl_rule_t *	npf_rule_create(const char *, uint32_t, u_int);
     85 int		npf_rule_setcode(nl_rule_t *, int, const void *, size_t);
     86 int		npf_rule_setproc(nl_config_t *, nl_rule_t *, const char *);
     87 bool		npf_rule_exists_p(nl_config_t *, const char *);
     88 int		npf_rule_insert(nl_config_t *, nl_rule_t *, nl_rule_t *, pri_t);
     89 void		npf_rule_destroy(nl_rule_t *);
     90 
     91 nl_rproc_t *	npf_rproc_create(const char *);
     92 bool		npf_rproc_exists_p(nl_config_t *, const char *);
     93 int		npf_rproc_insert(nl_config_t *, nl_rproc_t *);
     94 
     95 nl_nat_t *	npf_nat_create(int, u_int, u_int, npf_addr_t *, int, in_port_t);
     96 int		npf_nat_insert(nl_config_t *, nl_nat_t *, pri_t);
     97 
     98 nl_table_t *	npf_table_create(u_int, int);
     99 int		npf_table_add_entry(nl_table_t *, const int,
    100 		    const npf_addr_t *, const npf_netmask_t);
    101 bool		npf_table_exists_p(nl_config_t *, u_int);
    102 int		npf_table_insert(nl_config_t *, nl_table_t *);
    103 void		npf_table_destroy(nl_table_t *);
    104 
    105 int		npf_update_rule(int, const char *, nl_rule_t *);
    106 int		npf_sessions_send(int, const char *);
    107 int		npf_sessions_recv(int, const char *);
    108 
    109 #ifdef _NPF_PRIVATE
    110 
    111 #include <ifaddrs.h>
    112 
    113 void		_npf_config_error(nl_config_t *, nl_error_t *);
    114 void		_npf_config_setsubmit(nl_config_t *, const char *);
    115 int		_npf_rule_foreach(nl_config_t *, nl_rule_callback_t);
    116 pri_t		_npf_rule_getinfo(nl_rule_t *, const char **, uint32_t *,
    117 		    u_int *);
    118 const void *	_npf_rule_ncode(nl_rule_t *, size_t *);
    119 const char *	_npf_rule_rproc(nl_rule_t *);
    120 int		_npf_nat_foreach(nl_config_t *, nl_rule_callback_t);
    121 void		_npf_nat_getinfo(nl_nat_t *, int *, u_int *, npf_addr_t *,
    122 		    size_t *, in_port_t *);
    123 int		_npf_rproc_setnorm(nl_rproc_t *, bool, bool, u_int, u_int);
    124 int		_npf_rproc_setlog(nl_rproc_t *, u_int);
    125 void		_npf_table_foreach(nl_config_t *, nl_table_callback_t);
    126 
    127 void		_npf_debug_addif(nl_config_t *, struct ifaddrs *, u_int);
    128 #endif
    129 
    130 __END_DECLS
    131 
    132 #endif	/* _NPF_LIB_H_ */
    133