14408d548SBill Yuan /*
24408d548SBill Yuan  * Copyright (c) 2015 - 2018 The DragonFly Project.  All rights reserved.
34408d548SBill Yuan  *
44408d548SBill Yuan  * This code is derived from software contributed to The DragonFly Project
54408d548SBill Yuan  * by Bill Yuan <bycn82@dragonflybsd.org>
64408d548SBill Yuan  *
74408d548SBill Yuan  * Redistribution and use in source and binary forms, with or without
84408d548SBill Yuan  * modification, are permitted provided that the following conditions
94408d548SBill Yuan  * are met:
104408d548SBill Yuan  *
114408d548SBill Yuan  * 1. Redistributions of source code must retain the above copyright
124408d548SBill Yuan  *    notice, this list of conditions and the following disclaimer.
134408d548SBill Yuan  * 2. Redistributions in binary form must reproduce the above copyright
144408d548SBill Yuan  *    notice, this list of conditions and the following disclaimer in
154408d548SBill Yuan  *    the documentation and/or other materials provided with the
164408d548SBill Yuan  *    distribution.
174408d548SBill Yuan  * 3. Neither the name of The DragonFly Project nor the names of its
184408d548SBill Yuan  *    contributors may be used to endorse or promote products derived
194408d548SBill Yuan  *    from this software without specific, prior written permission.
204408d548SBill Yuan  *
214408d548SBill Yuan  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
224408d548SBill Yuan  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
234408d548SBill Yuan  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
244408d548SBill Yuan  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
254408d548SBill Yuan  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
264408d548SBill Yuan  * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
274408d548SBill Yuan  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
284408d548SBill Yuan  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
294408d548SBill Yuan  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
304408d548SBill Yuan  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
314408d548SBill Yuan  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
324408d548SBill Yuan  * SUCH DAMAGE.
334408d548SBill Yuan  *
344408d548SBill Yuan  */
354408d548SBill Yuan 
364408d548SBill Yuan #ifndef _IP_FW3_TABLE_H_
374408d548SBill Yuan #define _IP_FW3_TABLE_H_
384408d548SBill Yuan 
394408d548SBill Yuan #define IPFW_TABLES_MAX		32
404408d548SBill Yuan #define IPFW_TABLE_NAME_LEN	32
414408d548SBill Yuan 
424408d548SBill Yuan struct ipfw_ioc_table_ip_entry {
434408d548SBill Yuan 	in_addr_t	addr;		/* network address */
444408d548SBill Yuan 	u_int8_t	masklen;	/* mask length */
454408d548SBill Yuan };
464408d548SBill Yuan 
474408d548SBill Yuan struct ipfw_ioc_table_mac_entry {
484408d548SBill Yuan         struct ether_addr       addr;
494408d548SBill Yuan };
504408d548SBill Yuan 
514408d548SBill Yuan struct ipfw_ioc_table {
524408d548SBill Yuan 	int	id;
534408d548SBill Yuan 	int 	type;
544408d548SBill Yuan 	int	count;
554408d548SBill Yuan 	char	name[IPFW_TABLE_NAME_LEN];
564408d548SBill Yuan 	struct ipfw_ioc_table_ip_entry ip_ent[0];
574408d548SBill Yuan 	struct ipfw_ioc_table_mac_entry mac_ent[0];
584408d548SBill Yuan };
594408d548SBill Yuan 
604408d548SBill Yuan #ifdef _KERNEL
61*b272101aSAaron LI 
624408d548SBill Yuan struct ipfw3_table_context {
634408d548SBill Yuan 	struct	radix_node_head *node;
644408d548SBill Yuan 	struct	radix_node_head *mask;
654408d548SBill Yuan 	char	name[IPFW_TABLE_NAME_LEN];
664408d548SBill Yuan 	int	count;
674408d548SBill Yuan 	int 	type;
684408d548SBill Yuan };
694408d548SBill Yuan 
704408d548SBill Yuan struct table_ip_entry {
714408d548SBill Yuan 	struct radix_node	rn[2];
724408d548SBill Yuan 	struct sockaddr_in	addr;
734408d548SBill Yuan 	struct sockaddr_in	mask;
744408d548SBill Yuan };
754408d548SBill Yuan 
764408d548SBill Yuan struct table_mac_entry {
774408d548SBill Yuan 	struct radix_node	rn[2];
784408d548SBill Yuan         struct sockaddr         addr;
794408d548SBill Yuan         struct sockaddr         mask;
804408d548SBill Yuan };
814408d548SBill Yuan 
824408d548SBill Yuan struct netmsg_table {
834408d548SBill Yuan 	struct netmsg_base base;
844408d548SBill Yuan 	struct ipfw_ioc_table *ioc_table;
854408d548SBill Yuan 	int retval;
864408d548SBill Yuan };
874408d548SBill Yuan 
889d11a266SBill Yuan void table_create_dispatch(netmsg_t nmsg);
899d11a266SBill Yuan void table_delete_dispatch(netmsg_t nmsg);
909d11a266SBill Yuan void table_append_dispatch(netmsg_t nmsg);
919d11a266SBill Yuan void table_remove_dispatch(netmsg_t nmsg);
920d7b85c8SAaron LI void flush_table_entry(struct radix_node *rn);
939d11a266SBill Yuan void table_flush_dispatch(netmsg_t nmsg);
949d11a266SBill Yuan void table_rename_dispatch(netmsg_t nmsg);
954408d548SBill Yuan int ip_fw3_ctl_table_list(struct sockopt *sopt);
964408d548SBill Yuan int ip_fw3_ctl_table_remove(struct sockopt *sopt);
974408d548SBill Yuan int ip_fw3_ctl_table_flush(struct sockopt *sopt);
984408d548SBill Yuan int dump_table_ip_entry(struct radix_node *rn, void *arg);
994408d548SBill Yuan int dump_table_mac_entry(struct radix_node *rn, void *arg);
1004408d548SBill Yuan int ip_fw3_ctl_table_show(struct sockopt *sopt);
1014408d548SBill Yuan int ip_fw3_ctl_table_test(struct sockopt *sopt);
1024408d548SBill Yuan int ip_fw3_ctl_table_create(struct sockopt *sopt);
1034408d548SBill Yuan int ip_fw3_ctl_table_delete(struct sockopt *sopt);
1044408d548SBill Yuan int ip_fw3_ctl_table_append(struct sockopt *sopt);
1059d11a266SBill Yuan int ip_fw3_ctl_table_rename(struct sockopt *sopt);
1064408d548SBill Yuan int ip_fw3_ctl_table_sockopt(struct sockopt *sopt);
107de23f38fSBill Yuan void ip_fw3_table_init_dispatch(netmsg_t nmsg);
108de23f38fSBill Yuan void ip_fw3_table_fini_dispatch(netmsg_t nmsg);
109de23f38fSBill Yuan void ip_fw3_table_fini(void);
1109d11a266SBill Yuan void ip_fw3_table_init(void);
111de23f38fSBill Yuan void ip_fw3_table_modevent(int type);
1124408d548SBill Yuan 
1134408d548SBill Yuan #endif	/* _KERNEL */
114*b272101aSAaron LI 
1154408d548SBill Yuan #endif /* _IP_FW3_TABLE_H_ */
116