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 struct ipfw3_table_context { 62 struct radix_node_head *node; 63 struct radix_node_head *mask; 64 char name[IPFW_TABLE_NAME_LEN]; 65 int count; 66 int type; 67 }; 68 69 struct table_ip_entry{ 70 struct radix_node rn[2]; 71 struct sockaddr_in addr; 72 struct sockaddr_in mask; 73 }; 74 75 struct table_mac_entry { 76 struct radix_node rn[2]; 77 struct sockaddr addr; 78 struct sockaddr mask; 79 }; 80 81 struct netmsg_table { 82 struct netmsg_base base; 83 struct ipfw_ioc_table *ioc_table; 84 int retval; 85 }; 86 87 int ip_fw3_ctl_table_list(struct sockopt *sopt); 88 int ip_fw3_ctl_table_remove(struct sockopt *sopt); 89 int ip_fw3_ctl_table_flush(struct sockopt *sopt); 90 int flush_table_ip_entry(struct radix_node *rn, void *arg); 91 int flush_table_mac_entry(struct radix_node *rn, void *arg); 92 int dump_table_ip_entry(struct radix_node *rn, void *arg); 93 int dump_table_mac_entry(struct radix_node *rn, void *arg); 94 int ip_fw3_ctl_table_show(struct sockopt *sopt); 95 int ip_fw3_ctl_table_test(struct sockopt *sopt); 96 int ip_fw3_ctl_table_rename(struct sockopt *sopt); 97 int ip_fw3_ctl_table_create(struct sockopt *sopt); 98 int ip_fw3_ctl_table_delete(struct sockopt *sopt); 99 int ip_fw3_ctl_table_append(struct sockopt *sopt); 100 int ip_fw3_ctl_table_sockopt(struct sockopt *sopt); 101 102 void table_init_dispatch(netmsg_t nmsg); 103 void table_fini(void); 104 105 #endif /* _KERNEL */ 106 #endif /* _IP_FW3_TABLE_H_ */ 107