npf.h revision 1.10 1 1.10 rmind /* $NetBSD: npf.h,v 1.10 2012/08/12 03:35:14 rmind Exp $ */
2 1.1 rmind
3 1.1 rmind /*-
4 1.7 rmind * Copyright (c) 2011-2012 The NetBSD Foundation, Inc.
5 1.1 rmind * All rights reserved.
6 1.1 rmind *
7 1.1 rmind * This material is based upon work partially supported by The
8 1.1 rmind * NetBSD Foundation under a contract with Mindaugas Rasiukevicius.
9 1.1 rmind *
10 1.1 rmind * Redistribution and use in source and binary forms, with or without
11 1.1 rmind * modification, are permitted provided that the following conditions
12 1.1 rmind * are met:
13 1.1 rmind * 1. Redistributions of source code must retain the above copyright
14 1.1 rmind * notice, this list of conditions and the following disclaimer.
15 1.1 rmind * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 rmind * notice, this list of conditions and the following disclaimer in the
17 1.1 rmind * documentation and/or other materials provided with the distribution.
18 1.1 rmind *
19 1.1 rmind * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1 rmind * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1 rmind * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1 rmind * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1 rmind * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1 rmind * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1 rmind * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 rmind * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1 rmind * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1 rmind * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 rmind * POSSIBILITY OF SUCH DAMAGE.
30 1.1 rmind */
31 1.1 rmind
32 1.1 rmind #ifndef _NPF_LIB_H_
33 1.1 rmind #define _NPF_LIB_H_
34 1.1 rmind
35 1.1 rmind #include <sys/types.h>
36 1.1 rmind #include <net/npf.h>
37 1.1 rmind
38 1.1 rmind #ifdef _NPF_TESTING
39 1.1 rmind #include "testing.h"
40 1.1 rmind #endif
41 1.1 rmind
42 1.1 rmind __BEGIN_DECLS
43 1.1 rmind
44 1.1 rmind struct nl_config;
45 1.1 rmind struct nl_rule;
46 1.1 rmind struct nl_rproc;
47 1.1 rmind struct nl_table;
48 1.1 rmind
49 1.1 rmind typedef struct nl_config nl_config_t;
50 1.1 rmind typedef struct nl_rule nl_rule_t;
51 1.1 rmind typedef struct nl_rproc nl_rproc_t;
52 1.1 rmind typedef struct nl_table nl_table_t;
53 1.1 rmind
54 1.1 rmind typedef struct nl_rule nl_nat_t;
55 1.1 rmind
56 1.6 rmind #ifdef _NPF_PRIVATE
57 1.6 rmind
58 1.6 rmind typedef struct {
59 1.6 rmind int ne_id;
60 1.6 rmind char * ne_source_file;
61 1.6 rmind u_int ne_source_line;
62 1.6 rmind int ne_ncode_error;
63 1.6 rmind int ne_ncode_errat;
64 1.6 rmind } nl_error_t;
65 1.6 rmind
66 1.7 rmind typedef void (*nl_rule_callback_t)(nl_rule_t *, unsigned);
67 1.8 rmind typedef void (*nl_table_callback_t)(unsigned, int);
68 1.7 rmind
69 1.6 rmind #endif
70 1.6 rmind
71 1.1 rmind #define NPF_CODE_NCODE 1
72 1.1 rmind #define NPF_CODE_BPF 2
73 1.1 rmind
74 1.1 rmind #define NPF_PRI_NEXT (-1)
75 1.1 rmind
76 1.1 rmind #define NPF_MAX_TABLE_ID (16)
77 1.1 rmind
78 1.1 rmind nl_config_t * npf_config_create(void);
79 1.1 rmind int npf_config_submit(nl_config_t *, int);
80 1.1 rmind void npf_config_destroy(nl_config_t *);
81 1.7 rmind nl_config_t * npf_config_retrieve(int, bool *, bool *);
82 1.5 rmind int npf_config_flush(int);
83 1.1 rmind
84 1.1 rmind nl_rule_t * npf_rule_create(const char *, uint32_t, u_int);
85 1.1 rmind int npf_rule_setcode(nl_rule_t *, int, const void *, size_t);
86 1.1 rmind int npf_rule_setproc(nl_config_t *, nl_rule_t *, const char *);
87 1.1 rmind bool npf_rule_exists_p(nl_config_t *, const char *);
88 1.1 rmind int npf_rule_insert(nl_config_t *, nl_rule_t *, nl_rule_t *, pri_t);
89 1.1 rmind void npf_rule_destroy(nl_rule_t *);
90 1.1 rmind
91 1.1 rmind nl_rproc_t * npf_rproc_create(const char *);
92 1.1 rmind bool npf_rproc_exists_p(nl_config_t *, const char *);
93 1.1 rmind int npf_rproc_insert(nl_config_t *, nl_rproc_t *);
94 1.1 rmind
95 1.4 christos nl_nat_t * npf_nat_create(int, u_int, u_int, npf_addr_t *, int, in_port_t);
96 1.1 rmind int npf_nat_insert(nl_config_t *, nl_nat_t *, pri_t);
97 1.1 rmind
98 1.4 christos nl_table_t * npf_table_create(u_int, int);
99 1.9 rmind int npf_table_add_entry(nl_table_t *, const int,
100 1.9 rmind const npf_addr_t *, const npf_netmask_t);
101 1.1 rmind bool npf_table_exists_p(nl_config_t *, u_int);
102 1.1 rmind int npf_table_insert(nl_config_t *, nl_table_t *);
103 1.1 rmind void npf_table_destroy(nl_table_t *);
104 1.1 rmind
105 1.4 christos int npf_update_rule(int, const char *, nl_rule_t *);
106 1.1 rmind int npf_sessions_send(int, const char *);
107 1.1 rmind int npf_sessions_recv(int, const char *);
108 1.1 rmind
109 1.8 rmind #ifdef _NPF_PRIVATE
110 1.10 rmind
111 1.10 rmind #include <ifaddrs.h>
112 1.10 rmind
113 1.8 rmind void _npf_config_error(nl_config_t *, nl_error_t *);
114 1.8 rmind void _npf_config_setsubmit(nl_config_t *, const char *);
115 1.8 rmind int _npf_rule_foreach(nl_config_t *, nl_rule_callback_t);
116 1.8 rmind pri_t _npf_rule_getinfo(nl_rule_t *, const char **, uint32_t *,
117 1.8 rmind u_int *);
118 1.8 rmind const void * _npf_rule_ncode(nl_rule_t *, size_t *);
119 1.8 rmind const char * _npf_rule_rproc(nl_rule_t *);
120 1.8 rmind int _npf_nat_foreach(nl_config_t *, nl_rule_callback_t);
121 1.8 rmind void _npf_nat_getinfo(nl_nat_t *, int *, u_int *, npf_addr_t *,
122 1.8 rmind size_t *, in_port_t *);
123 1.8 rmind int _npf_rproc_setnorm(nl_rproc_t *, bool, bool, u_int, u_int);
124 1.8 rmind int _npf_rproc_setlog(nl_rproc_t *, u_int);
125 1.8 rmind void _npf_table_foreach(nl_config_t *, nl_table_callback_t);
126 1.10 rmind
127 1.10 rmind void _npf_debug_addif(nl_config_t *, struct ifaddrs *, u_int);
128 1.8 rmind #endif
129 1.8 rmind
130 1.1 rmind __END_DECLS
131 1.1 rmind
132 1.1 rmind #endif /* _NPF_LIB_H_ */
133