npfctl.h revision 1.11.2.11 1 1.11.2.11 riz /* $NetBSD: npfctl.h,v 1.11.2.11 2012/12/16 19:41:37 riz Exp $ */
2 1.1 rmind
3 1.1 rmind /*-
4 1.8 rmind * Copyright (c) 2009-2012 The NetBSD Foundation, Inc.
5 1.1 rmind * All rights reserved.
6 1.1 rmind *
7 1.1 rmind * Redistribution and use in source and binary forms, with or without
8 1.1 rmind * modification, are permitted provided that the following conditions
9 1.1 rmind * are met:
10 1.1 rmind * 1. Redistributions of source code must retain the above copyright
11 1.1 rmind * notice, this list of conditions and the following disclaimer.
12 1.1 rmind * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 rmind * notice, this list of conditions and the following disclaimer in the
14 1.1 rmind * documentation and/or other materials provided with the distribution.
15 1.1 rmind *
16 1.1 rmind * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 1.1 rmind * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 1.1 rmind * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 1.1 rmind * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 1.1 rmind * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 1.1 rmind * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 1.1 rmind * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 1.1 rmind * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 1.1 rmind * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 1.1 rmind * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 1.1 rmind * POSSIBILITY OF SUCH DAMAGE.
27 1.1 rmind */
28 1.1 rmind
29 1.1 rmind #ifndef _NPFCTL_H_
30 1.1 rmind #define _NPFCTL_H_
31 1.1 rmind
32 1.1 rmind #include <stdio.h>
33 1.1 rmind #include <stdbool.h>
34 1.8 rmind #include <inttypes.h>
35 1.11.2.4 riz #include <assert.h>
36 1.11.2.9 riz #include <util.h>
37 1.11.2.9 riz #undef ECHO /* XXX util.h */
38 1.1 rmind
39 1.6 rmind #include <net/npf_ncode.h>
40 1.1 rmind #include <net/npf.h>
41 1.6 rmind
42 1.6 rmind #define _NPF_PRIVATE
43 1.6 rmind #include <npf.h>
44 1.1 rmind
45 1.8 rmind #include "npf_var.h"
46 1.1 rmind
47 1.1 rmind #define NPF_DEV_PATH "/dev/npf"
48 1.1 rmind #define NPF_CONF_PATH "/etc/npf.conf"
49 1.4 rmind #define NPF_SESSDB_PATH "/var/db/npf_sessions.db"
50 1.1 rmind
51 1.8 rmind typedef struct fam_addr_mask {
52 1.8 rmind sa_family_t fam_family;
53 1.8 rmind npf_addr_t fam_addr;
54 1.8 rmind npf_netmask_t fam_mask;
55 1.11.2.10 riz unsigned long fam_ifindex;
56 1.8 rmind } fam_addr_mask_t;
57 1.8 rmind
58 1.11.2.10 riz typedef struct ifnet_addr {
59 1.11.2.10 riz unsigned long ifna_index;
60 1.11.2.10 riz sa_family_t ifna_family;
61 1.11.2.10 riz npfvar_t * ifna_filter;
62 1.11.2.10 riz npfvar_t * ifna_addrs;
63 1.11.2.10 riz } ifnet_addr_t;
64 1.11.2.10 riz
65 1.8 rmind typedef struct port_range {
66 1.8 rmind in_port_t pr_start;
67 1.8 rmind in_port_t pr_end;
68 1.8 rmind } port_range_t;
69 1.8 rmind
70 1.11.2.2 riz typedef struct addr_port {
71 1.11.2.2 riz npfvar_t * ap_netaddr;
72 1.11.2.2 riz npfvar_t * ap_portrange;
73 1.11.2.2 riz } addr_port_t;
74 1.11.2.2 riz
75 1.8 rmind typedef struct filt_opts {
76 1.11.2.2 riz addr_port_t fo_from;
77 1.11.2.2 riz addr_port_t fo_to;
78 1.8 rmind } filt_opts_t;
79 1.8 rmind
80 1.8 rmind typedef struct opt_proto {
81 1.8 rmind int op_proto;
82 1.8 rmind npfvar_t * op_opts;
83 1.8 rmind } opt_proto_t;
84 1.8 rmind
85 1.8 rmind typedef struct rule_group {
86 1.8 rmind const char * rg_name;
87 1.11.2.2 riz uint32_t rg_attr;
88 1.8 rmind u_int rg_ifnum;
89 1.8 rmind } rule_group_t;
90 1.8 rmind
91 1.11.2.7 riz typedef struct proc_call {
92 1.11.2.7 riz const char * pc_name;
93 1.11.2.7 riz npfvar_t * pc_opts;
94 1.11.2.7 riz } proc_call_t;
95 1.11.2.7 riz
96 1.11.2.7 riz typedef struct proc_param {
97 1.11.2.7 riz const char * pp_param;
98 1.11.2.7 riz const char * pp_value;
99 1.11.2.7 riz } proc_param_t;
100 1.6 rmind
101 1.9 joerg void yyerror(const char *, ...) __printflike(1, 2) __dead;
102 1.8 rmind
103 1.11 rmind void npfctl_print_error(const nl_error_t *);
104 1.11.2.8 riz char * npfctl_print_addrmask(int, npf_addr_t *, npf_netmask_t);
105 1.8 rmind bool npfctl_table_exists_p(const char *);
106 1.11.2.3 riz int npfctl_protono(const char *);
107 1.8 rmind in_port_t npfctl_portno(const char *);
108 1.11.2.5 jdc uint8_t npfctl_icmpcode(int, uint8_t, const char *);
109 1.11.2.5 jdc uint8_t npfctl_icmptype(int, const char *);
110 1.8 rmind unsigned long npfctl_find_ifindex(const char *);
111 1.11.2.10 riz npfvar_t * npfctl_parse_ifnet(const char *, const int);
112 1.8 rmind npfvar_t * npfctl_parse_tcpflag(const char *);
113 1.8 rmind npfvar_t * npfctl_parse_table_id(const char *);
114 1.11.2.5 jdc npfvar_t * npfctl_parse_icmp(int, int, int);
115 1.8 rmind npfvar_t * npfctl_parse_port_range(in_port_t, in_port_t);
116 1.11.2.2 riz npfvar_t * npfctl_parse_port_range_variable(const char *);
117 1.8 rmind npfvar_t * npfctl_parse_fam_addr_mask(const char *, const char *,
118 1.8 rmind unsigned long *);
119 1.11.2.4 riz bool npfctl_parse_cidr(char *, fam_addr_mask_t *, int *);
120 1.8 rmind
121 1.8 rmind /*
122 1.11.2.7 riz * NPF extension loading.
123 1.11.2.7 riz */
124 1.11.2.7 riz
125 1.11.2.7 riz typedef struct npf_extmod npf_extmod_t;
126 1.11.2.7 riz
127 1.11.2.7 riz npf_extmod_t * npf_extmod_get(const char *, nl_ext_t **);
128 1.11.2.7 riz int npf_extmod_param(npf_extmod_t *, nl_ext_t *,
129 1.11.2.7 riz const char *, const char *);
130 1.11.2.7 riz
131 1.11.2.7 riz /*
132 1.8 rmind * N-code generation interface.
133 1.8 rmind */
134 1.1 rmind
135 1.8 rmind typedef struct nc_ctx nc_ctx_t;
136 1.1 rmind
137 1.8 rmind #define NC_MATCH_DST 0x01
138 1.8 rmind #define NC_MATCH_SRC 0x02
139 1.8 rmind
140 1.8 rmind #define NC_MATCH_TCP 0x04
141 1.8 rmind #define NC_MATCH_UDP 0x08
142 1.11.2.2 riz #define NC_MATCH_ICMP 0x10
143 1.11.2.5 jdc #define NC_MATCH_ICMP6 0x20
144 1.8 rmind
145 1.8 rmind nc_ctx_t * npfctl_ncgen_create(void);
146 1.8 rmind void * npfctl_ncgen_complete(nc_ctx_t *, size_t *);
147 1.8 rmind void npfctl_ncgen_print(const void *, size_t);
148 1.8 rmind
149 1.8 rmind void npfctl_ncgen_group(nc_ctx_t *);
150 1.8 rmind void npfctl_ncgen_endgroup(nc_ctx_t *);
151 1.8 rmind
152 1.8 rmind void npfctl_gennc_v4cidr(nc_ctx_t *, int, const npf_addr_t *,
153 1.8 rmind const npf_netmask_t);
154 1.8 rmind void npfctl_gennc_v6cidr(nc_ctx_t *, int, const npf_addr_t *,
155 1.8 rmind const npf_netmask_t);
156 1.8 rmind void npfctl_gennc_ports(nc_ctx_t *, int, in_port_t, in_port_t);
157 1.8 rmind void npfctl_gennc_icmp(nc_ctx_t *, int, int);
158 1.11.2.5 jdc void npfctl_gennc_icmp6(nc_ctx_t *, int, int);
159 1.8 rmind void npfctl_gennc_tbl(nc_ctx_t *, int, u_int);
160 1.8 rmind void npfctl_gennc_tcpfl(nc_ctx_t *, uint8_t, uint8_t);
161 1.11.2.3 riz void npfctl_gennc_proto(nc_ctx_t *ctx, uint8_t, uint8_t);
162 1.8 rmind
163 1.8 rmind /*
164 1.11.2.2 riz * N-code disassembler.
165 1.11.2.2 riz */
166 1.11.2.2 riz
167 1.11.2.2 riz typedef struct nc_inf nc_inf_t;
168 1.11.2.2 riz
169 1.11.2.2 riz nc_inf_t * npfctl_ncode_disinf(FILE *);
170 1.11.2.2 riz int npfctl_ncode_disassemble(nc_inf_t *, const void *, size_t);
171 1.11.2.2 riz
172 1.11.2.2 riz /*
173 1.8 rmind * Configuration building interface.
174 1.8 rmind */
175 1.1 rmind
176 1.11.2.2 riz #define NPFCTL_NAT_DYNAMIC 1
177 1.11.2.2 riz #define NPFCTL_NAT_STATIC 2
178 1.8 rmind
179 1.8 rmind void npfctl_config_init(bool);
180 1.11.2.6 riz int npfctl_config_send(int, const char *);
181 1.11.2.11 riz nl_config_t * npfctl_config_ref(void);
182 1.11.2.2 riz int npfctl_config_show(int);
183 1.11.2.6 riz unsigned long npfctl_debug_addif(const char *);
184 1.8 rmind
185 1.8 rmind void npfctl_build_rproc(const char *, npfvar_t *);
186 1.8 rmind void npfctl_build_group(const char *, int, u_int);
187 1.8 rmind void npfctl_build_rule(int, u_int, sa_family_t,
188 1.8 rmind const opt_proto_t *, const filt_opts_t *, const char *);
189 1.11.2.6 riz void npfctl_build_natseg(int, int, u_int, const addr_port_t *,
190 1.11.2.2 riz const addr_port_t *, const filt_opts_t *);
191 1.8 rmind void npfctl_build_table(const char *, u_int, const char *);
192 1.1 rmind
193 1.1 rmind #endif
194