xref: /netbsd-src/lib/libnpf/npf.h (revision daf6c4152fcddc27c445489775ed1f66ab4ea9a9)
1 /*	$NetBSD: npf.h,v 1.1 2011/02/02 02:20:25 rmind Exp $	*/
2 
3 /*-
4  * Copyright (c) 2011 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 #define	NPF_CODE_NCODE		1
57 #define	NPF_CODE_BPF		2
58 
59 #define	NPF_PRI_NEXT		(-1)
60 
61 #define	NPF_MAX_TABLE_ID	(16)
62 
63 nl_config_t *	npf_config_create(void);
64 int		npf_config_submit(nl_config_t *, int);
65 void		npf_config_destroy(nl_config_t *);
66 
67 nl_rule_t *	npf_rule_create(const char *, uint32_t, u_int);
68 int		npf_rule_setcode(nl_rule_t *, int, const void *, size_t);
69 int		npf_rule_setproc(nl_config_t *, nl_rule_t *, const char *);
70 bool		npf_rule_exists_p(nl_config_t *, const char *);
71 int		npf_rule_insert(nl_config_t *, nl_rule_t *, nl_rule_t *, pri_t);
72 void		npf_rule_destroy(nl_rule_t *);
73 
74 nl_rproc_t *	npf_rproc_create(const char *);
75 bool		npf_rproc_exists_p(nl_config_t *, const char *);
76 int		npf_rproc_insert(nl_config_t *, nl_rproc_t *);
77 
78 #ifdef _NPF_PRIVATE
79 int		_npf_rproc_setnorm(nl_rproc_t *, bool, bool, int, int);
80 int		_npf_rproc_setlog(nl_rproc_t *, u_int);
81 #endif
82 
83 nl_nat_t *	npf_nat_create(int, int, u_int, npf_addr_t *, int, in_port_t);
84 int		npf_nat_insert(nl_config_t *, nl_nat_t *, pri_t);
85 
86 nl_table_t *	npf_table_create(int, int);
87 int		npf_table_add_entry(nl_table_t *, in_addr_t, in_addr_t);
88 bool		npf_table_exists_p(nl_config_t *, u_int);
89 int		npf_table_insert(nl_config_t *, nl_table_t *);
90 void		npf_table_destroy(nl_table_t *);
91 
92 int		npf_update_rule(int, char *, nl_rule_t *);
93 int		npf_sessions_send(int, const char *);
94 int		npf_sessions_recv(int, const char *);
95 
96 __END_DECLS
97 
98 #endif	/* _NPF_LIB_H_ */
99