1 /* 2 * Copyright (c) 2015 - 2018 The DragonFly Project. All rights reserved. 3 * 4 * This code is derived from software contributed to The DragonFly Project 5 * by Bill Yuan <bycn82@dragonflybsd.org> 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 * 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in 15 * the documentation and/or other materials provided with the 16 * distribution. 17 * 3. Neither the name of The DragonFly Project nor the names of its 18 * contributors may be used to endorse or promote products derived 19 * from this software without specific, prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 25 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 26 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, 27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 31 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 * 34 */ 35 36 #ifndef _IP_FW3_TABLE_H_ 37 #define _IP_FW3_TABLE_H_ 38 39 #define IPFW_TABLES_MAX 32 40 #define IPFW_TABLE_NAME_LEN 32 41 42 struct ipfw_ioc_table_ip_entry { 43 in_addr_t addr; /* network address */ 44 u_int8_t masklen; /* mask length */ 45 }; 46 47 struct ipfw_ioc_table_mac_entry { 48 struct ether_addr addr; 49 }; 50 51 struct ipfw_ioc_table { 52 int id; 53 int type; 54 int count; 55 char name[IPFW_TABLE_NAME_LEN]; 56 struct ipfw_ioc_table_ip_entry ip_ent[0]; 57 struct ipfw_ioc_table_mac_entry mac_ent[0]; 58 }; 59 60 #ifdef _KERNEL 61 62 struct ipfw3_table_context { 63 struct radix_node_head *node; 64 struct radix_node_head *mask; 65 char name[IPFW_TABLE_NAME_LEN]; 66 int count; 67 int type; 68 }; 69 70 struct table_ip_entry { 71 struct radix_node rn[2]; 72 struct sockaddr_in addr; 73 struct sockaddr_in mask; 74 }; 75 76 struct table_mac_entry { 77 struct radix_node rn[2]; 78 struct sockaddr addr; 79 struct sockaddr mask; 80 }; 81 82 struct netmsg_table { 83 struct netmsg_base base; 84 struct ipfw_ioc_table *ioc_table; 85 int retval; 86 }; 87 88 void table_create_dispatch(netmsg_t nmsg); 89 void table_delete_dispatch(netmsg_t nmsg); 90 void table_append_dispatch(netmsg_t nmsg); 91 void table_remove_dispatch(netmsg_t nmsg); 92 void flush_table_entry(struct radix_node *rn); 93 void table_flush_dispatch(netmsg_t nmsg); 94 void table_rename_dispatch(netmsg_t nmsg); 95 int ip_fw3_ctl_table_list(struct sockopt *sopt); 96 int ip_fw3_ctl_table_remove(struct sockopt *sopt); 97 int ip_fw3_ctl_table_flush(struct sockopt *sopt); 98 int dump_table_ip_entry(struct radix_node *rn, void *arg); 99 int dump_table_mac_entry(struct radix_node *rn, void *arg); 100 int ip_fw3_ctl_table_show(struct sockopt *sopt); 101 int ip_fw3_ctl_table_test(struct sockopt *sopt); 102 int ip_fw3_ctl_table_create(struct sockopt *sopt); 103 int ip_fw3_ctl_table_delete(struct sockopt *sopt); 104 int ip_fw3_ctl_table_append(struct sockopt *sopt); 105 int ip_fw3_ctl_table_rename(struct sockopt *sopt); 106 int ip_fw3_ctl_table_sockopt(struct sockopt *sopt); 107 void ip_fw3_table_init_dispatch(netmsg_t nmsg); 108 void ip_fw3_table_fini_dispatch(netmsg_t nmsg); 109 void ip_fw3_table_fini(void); 110 void ip_fw3_table_init(void); 111 void ip_fw3_table_modevent(int type); 112 113 #endif /* _KERNEL */ 114 115 #endif /* _IP_FW3_TABLE_H_ */ 116