xref: /netbsd-src/lib/libnpf/npf.h (revision 1897181a7231d5fc7ab48994d1447fcbc4e13a49)
1 /*	$NetBSD: npf.h,v 1.5 2012/01/15 00:49:47 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 int		npf_config_flush(int);
67 #ifdef _NPF_PRIVATE
68 void		_npf_config_setsubmit(nl_config_t *, const char *);
69 #endif
70 
71 nl_rule_t *	npf_rule_create(const char *, uint32_t, u_int);
72 int		npf_rule_setcode(nl_rule_t *, int, const void *, size_t);
73 int		npf_rule_setproc(nl_config_t *, nl_rule_t *, const char *);
74 bool		npf_rule_exists_p(nl_config_t *, const char *);
75 int		npf_rule_insert(nl_config_t *, nl_rule_t *, nl_rule_t *, pri_t);
76 void		npf_rule_destroy(nl_rule_t *);
77 
78 nl_rproc_t *	npf_rproc_create(const char *);
79 bool		npf_rproc_exists_p(nl_config_t *, const char *);
80 int		npf_rproc_insert(nl_config_t *, nl_rproc_t *);
81 
82 #ifdef _NPF_PRIVATE
83 int		_npf_rproc_setnorm(nl_rproc_t *, bool, bool, u_int, u_int);
84 int		_npf_rproc_setlog(nl_rproc_t *, u_int);
85 #endif
86 
87 nl_nat_t *	npf_nat_create(int, u_int, u_int, npf_addr_t *, int, in_port_t);
88 int		npf_nat_insert(nl_config_t *, nl_nat_t *, pri_t);
89 
90 nl_table_t *	npf_table_create(u_int, int);
91 int		npf_table_add_entry(nl_table_t *, npf_addr_t *, npf_netmask_t);
92 bool		npf_table_exists_p(nl_config_t *, u_int);
93 int		npf_table_insert(nl_config_t *, nl_table_t *);
94 void		npf_table_destroy(nl_table_t *);
95 
96 int		npf_update_rule(int, const char *, nl_rule_t *);
97 int		npf_sessions_send(int, const char *);
98 int		npf_sessions_recv(int, const char *);
99 
100 __END_DECLS
101 
102 #endif	/* _NPF_LIB_H_ */
103