1 /* $NetBSD: npf.h,v 1.7 2012/04/01 19:16:24 rmind Exp $ */ 2 3 /*- 4 * Copyright (c) 2011-2012 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 #ifdef _NPF_PRIVATE 57 58 typedef struct { 59 int ne_id; 60 char * ne_source_file; 61 u_int ne_source_line; 62 int ne_ncode_error; 63 int ne_ncode_errat; 64 } nl_error_t; 65 66 typedef void (*nl_rule_callback_t)(nl_rule_t *, unsigned); 67 68 #endif 69 70 #define NPF_CODE_NCODE 1 71 #define NPF_CODE_BPF 2 72 73 #define NPF_PRI_NEXT (-1) 74 75 #define NPF_MAX_TABLE_ID (16) 76 77 nl_config_t * npf_config_create(void); 78 int npf_config_submit(nl_config_t *, int); 79 void npf_config_destroy(nl_config_t *); 80 nl_config_t * npf_config_retrieve(int, bool *, bool *); 81 int npf_config_flush(int); 82 #ifdef _NPF_PRIVATE 83 void _npf_config_error(nl_config_t *, nl_error_t *); 84 void _npf_config_setsubmit(nl_config_t *, const char *); 85 #endif 86 87 nl_rule_t * npf_rule_create(const char *, uint32_t, u_int); 88 int npf_rule_setcode(nl_rule_t *, int, const void *, size_t); 89 int npf_rule_setproc(nl_config_t *, nl_rule_t *, const char *); 90 bool npf_rule_exists_p(nl_config_t *, const char *); 91 int npf_rule_insert(nl_config_t *, nl_rule_t *, nl_rule_t *, pri_t); 92 #ifdef _NPF_PRIVATE 93 int _npf_rule_foreach(nl_config_t *, nl_rule_callback_t); 94 pri_t _npf_rule_getinfo(nl_rule_t *, const char **, uint32_t *, u_int *); 95 const void * _npf_rule_ncode(nl_rule_t *, size_t *); 96 const char * _npf_rule_rproc(nl_rule_t *); 97 #endif 98 void npf_rule_destroy(nl_rule_t *); 99 100 nl_rproc_t * npf_rproc_create(const char *); 101 bool npf_rproc_exists_p(nl_config_t *, const char *); 102 int npf_rproc_insert(nl_config_t *, nl_rproc_t *); 103 104 #ifdef _NPF_PRIVATE 105 int _npf_rproc_setnorm(nl_rproc_t *, bool, bool, u_int, u_int); 106 int _npf_rproc_setlog(nl_rproc_t *, u_int); 107 #endif 108 109 nl_nat_t * npf_nat_create(int, u_int, u_int, npf_addr_t *, int, in_port_t); 110 int npf_nat_insert(nl_config_t *, nl_nat_t *, pri_t); 111 112 nl_table_t * npf_table_create(u_int, int); 113 int npf_table_add_entry(nl_table_t *, npf_addr_t *, npf_netmask_t); 114 bool npf_table_exists_p(nl_config_t *, u_int); 115 int npf_table_insert(nl_config_t *, nl_table_t *); 116 void npf_table_destroy(nl_table_t *); 117 118 int npf_update_rule(int, const char *, nl_rule_t *); 119 int npf_sessions_send(int, const char *); 120 int npf_sessions_recv(int, const char *); 121 122 __END_DECLS 123 124 #endif /* _NPF_LIB_H_ */ 125