npfctl.h revision 1.7 1 /* $NetBSD: npfctl.h,v 1.7 2011/11/04 01:00:28 zoltan Exp $ */
2
3 /*-
4 * Copyright (c) 2009-2011 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #ifndef _NPFCTL_H_
30 #define _NPFCTL_H_
31
32 #include <sys/types.h>
33 #include <stdio.h>
34 #include <stdbool.h>
35
36 #include <net/npf_ncode.h>
37 #include <net/npf.h>
38
39 #define _NPF_PRIVATE
40 #include <npf.h>
41
42 #ifdef DEBUG
43 #define DPRINTF(x) printf x
44 #else
45 #define DPRINTF(x)
46 #endif
47
48 #define NPF_DEV_PATH "/dev/npf"
49 #define NPF_CONF_PATH "/etc/npf.conf"
50 #define NPF_SESSDB_PATH "/var/db/npf_sessions.db"
51
52 typedef struct {
53 char * e_data;
54 void * e_next;
55 } element_t;
56
57 #define VAR_SINGLE 1
58 #define VAR_ARRAY 2
59 #define VAR_TABLE 3
60
61 typedef struct {
62 char * v_key;
63 element_t * v_elements;
64 int v_type;
65 int v_count;
66 void * v_next;
67 } var_t;
68
69 extern nl_config_t * npf_conf;
70
71 void * zalloc(size_t);
72 char * xstrdup(const char *);
73
74 void npfctl_init_data(void);
75 int npfctl_ioctl_send(int);
76
77 struct ifaddrs *npfctl_getif(char *, unsigned int *, bool, sa_family_t);
78 void npfctl_create_mask(sa_family_t, u_int, npf_addr_t *);
79 sa_family_t npfctl_get_addrfamily(const char *);
80 sa_family_t npfctl_parse_cidr(char *, sa_family_t, npf_addr_t *, npf_netmask_t *);
81 bool npfctl_parse_port(char *, bool *, in_port_t *, in_port_t *);
82
83 void npfctl_fill_table(nl_table_t *, char *);
84
85 void npfctl_rule_ncode(nl_rule_t *, char *, char *,
86 int, int, var_t *, sa_family_t, var_t *, var_t *, var_t *);
87
88 size_t npfctl_calc_ncsize(int []);
89 size_t npfctl_failure_offset(int []);
90
91 void npfctl_gennc_ether(void **, int, uint16_t);
92 void npfctl_gennc_v4cidr(void **, int,
93 const npf_addr_t *, const npf_netmask_t, bool);
94 void npfctl_gennc_v6cidr(void **, int,
95 const npf_addr_t *, const npf_netmask_t, bool);
96 void npfctl_gennc_icmp(void **, int, int, int);
97 void npfctl_gennc_tcpfl(void **, int , uint8_t, uint8_t);
98 void npfctl_gennc_ports(void **, int,
99 in_port_t, in_port_t, bool, bool);
100 void npfctl_gennc_tbl(void **, int, u_int , bool);
101 void npfctl_gennc_complete(void **);
102
103 int npf_parseline(char *);
104
105 #endif
106