1 /* $NetBSD: npfctl.h,v 1.5 2011/01/18 20:33:45 rmind 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 #ifndef _NPF_TESTING 37 #include <net/npf.h> 38 #include <net/npf_ncode.h> 39 #else 40 #include "npf.h" 41 #include "npf_ncode.h" 42 #endif 43 44 #ifdef DEBUG 45 #define DPRINTF(x) printf x 46 #else 47 #define DPRINTF(x) 48 #endif 49 50 #define NPF_DEV_PATH "/dev/npf" 51 #define NPF_CONF_PATH "/etc/npf.conf" 52 #define NPF_SESSDB_PATH "/var/db/npf_sessions.db" 53 54 typedef struct { 55 char * e_data; 56 void * e_next; 57 } element_t; 58 59 #define VAR_SINGLE 1 60 #define VAR_ARRAY 2 61 #define VAR_TABLE 3 62 63 typedef struct { 64 char * v_key; 65 element_t * v_elements; 66 int v_type; 67 int v_count; 68 void * v_next; 69 } var_t; 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 int npfctl_ioctl_recvse(int); 77 int npfctl_ioctl_sendse(int); 78 int npfctl_ioctl_flushse(int); 79 80 struct ifaddrs *npfctl_getif(char *, unsigned int *, bool); 81 bool npfctl_parse_v4mask(char *, in_addr_t *, in_addr_t *); 82 83 prop_dictionary_t npfctl_mk_rule(bool, prop_dictionary_t); 84 void npfctl_rule_setattr(prop_dictionary_t, int, u_int); 85 void npfctl_rule_protodata(prop_dictionary_t, char *, char *, 86 int, int, var_t *, var_t *, var_t *, var_t *); 87 void npfctl_rule_icmpdata(prop_dictionary_t, var_t *, var_t *); 88 89 prop_dictionary_t npfctl_lookup_table(char *); 90 prop_dictionary_t npfctl_construct_table(int, int); 91 void npfctl_fill_table(prop_dictionary_t, char *); 92 93 prop_dictionary_t npfctl_mk_rproc(void); 94 bool npfctl_find_rproc(prop_dictionary_t, char *); 95 96 prop_dictionary_t npfctl_mk_nat(void); 97 void npfctl_nat_setup(prop_dictionary_t, int, int, 98 u_int, char *, char *); 99 100 size_t npfctl_calc_ncsize(int []); 101 size_t npfctl_failure_offset(int []); 102 103 void npfctl_gennc_ether(void **, int, uint16_t); 104 void npfctl_gennc_v4cidr(void **, int, 105 in_addr_t, in_addr_t, bool); 106 void npfctl_gennc_icmp(void **, int, int, int); 107 void npfctl_gennc_tcpfl(void **, int , uint8_t, uint8_t); 108 void npfctl_gennc_ports(void **, int, 109 in_port_t, in_port_t, bool, bool); 110 void npfctl_gennc_tbl(void **, int, u_int , bool); 111 void npfctl_gennc_complete(void **); 112 113 int npf_parseline(char *); 114 115 #endif 116