1*4408d548SBill Yuan /* 2*4408d548SBill Yuan * Copyright (c) 2016 - 2018 The DragonFly Project. All rights reserved. 3*4408d548SBill Yuan * 4*4408d548SBill Yuan * This code is derived from software contributed to The DragonFly Project 5*4408d548SBill Yuan * by Bill Yuan <bycn82@dragonflybsd.org> 6*4408d548SBill Yuan * 7*4408d548SBill Yuan * Redistribution and use in source and binary forms, with or without 8*4408d548SBill Yuan * modification, are permitted provided that the following conditions 9*4408d548SBill Yuan * are met: 10*4408d548SBill Yuan * 11*4408d548SBill Yuan * 1. Redistributions of source code must retain the above copyright 12*4408d548SBill Yuan * notice, this list of conditions and the following disclaimer. 13*4408d548SBill Yuan * 2. Redistributions in binary form must reproduce the above copyright 14*4408d548SBill Yuan * notice, this list of conditions and the following disclaimer in 15*4408d548SBill Yuan * the documentation and/or other materials provided with the 16*4408d548SBill Yuan * distribution. 17*4408d548SBill Yuan * 3. Neither the name of The DragonFly Project nor the names of its 18*4408d548SBill Yuan * contributors may be used to endorse or promote products derived 19*4408d548SBill Yuan * from this software without specific, prior written permission. 20*4408d548SBill Yuan * 21*4408d548SBill Yuan * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22*4408d548SBill Yuan * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23*4408d548SBill Yuan * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 24*4408d548SBill Yuan * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 25*4408d548SBill Yuan * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 26*4408d548SBill Yuan * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, 27*4408d548SBill Yuan * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28*4408d548SBill Yuan * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 29*4408d548SBill Yuan * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 30*4408d548SBill Yuan * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 31*4408d548SBill Yuan * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32*4408d548SBill Yuan * SUCH DAMAGE. 33*4408d548SBill Yuan * 34*4408d548SBill Yuan */ 35*4408d548SBill Yuan 36*4408d548SBill Yuan #ifndef _IP_FW3_SYNC_H_ 37*4408d548SBill Yuan #define _IP_FW3_SYNC_H_ 38*4408d548SBill Yuan 39*4408d548SBill Yuan #define MAX_EDGES 10 40*4408d548SBill Yuan 41*4408d548SBill Yuan #define SYNC_TYPE_SEND_TEST 0 /* testing sync status */ 42*4408d548SBill Yuan #define SYNC_TYPE_SEND_STATE 1 /* syncing state */ 43*4408d548SBill Yuan #define SYNC_TYPE_SEND_NAT 2 /* syncing nat */ 44*4408d548SBill Yuan 45*4408d548SBill Yuan 46*4408d548SBill Yuan struct ipfw3_sync_edge { 47*4408d548SBill Yuan in_addr_t addr; 48*4408d548SBill Yuan u_short port; 49*4408d548SBill Yuan }; 50*4408d548SBill Yuan #define LEN_SYNC_EDGE sizeof(struct ipfw3_sync_edge) 51*4408d548SBill Yuan 52*4408d548SBill Yuan struct ipfw3_ioc_sync_context { 53*4408d548SBill Yuan int edge_port; /* edge listening port */ 54*4408d548SBill Yuan int hw_same; /* duplicate to all CPU when hardware different */ 55*4408d548SBill Yuan int count; /* count of edge */ 56*4408d548SBill Yuan struct ipfw3_sync_edge edges[0]; /* edge */ 57*4408d548SBill Yuan }; 58*4408d548SBill Yuan 59*4408d548SBill Yuan struct ipfw3_ioc_sync_centre { 60*4408d548SBill Yuan int count; /* count of edge */ 61*4408d548SBill Yuan struct ipfw3_sync_edge edges[0]; /* edge */ 62*4408d548SBill Yuan }; 63*4408d548SBill Yuan 64*4408d548SBill Yuan struct ipfw3_ioc_sync_edge { 65*4408d548SBill Yuan int port; 66*4408d548SBill Yuan int hw_same; 67*4408d548SBill Yuan }; 68*4408d548SBill Yuan 69*4408d548SBill Yuan struct ipfw3_sync_context{ 70*4408d548SBill Yuan int edge_port; /* edge listening port */ 71*4408d548SBill Yuan int hw_same; /* duplicate to all CPU when hardware different */ 72*4408d548SBill Yuan int count; /* count of edge */ 73*4408d548SBill Yuan int running; /* edge 01, centre 10 */ 74*4408d548SBill Yuan struct ipfw3_sync_edge *edges; /* edge */ 75*4408d548SBill Yuan struct thread *edge_td; /* edge handler thread */ 76*4408d548SBill Yuan struct socket *edge_sock; /* edge sock */ 77*4408d548SBill Yuan struct socket *centre_socks[MAX_EDGES]; /* centre socks */ 78*4408d548SBill Yuan }; 79*4408d548SBill Yuan 80*4408d548SBill Yuan 81*4408d548SBill Yuan 82*4408d548SBill Yuan #ifdef _KERNEL 83*4408d548SBill Yuan 84*4408d548SBill Yuan #include <net/ipfw3_basic/ip_fw3_basic.h> 85*4408d548SBill Yuan 86*4408d548SBill Yuan void ip_fw3_sync_modevent(int type); 87*4408d548SBill Yuan 88*4408d548SBill Yuan struct cmd_send_test { 89*4408d548SBill Yuan int type; 90*4408d548SBill Yuan int num; 91*4408d548SBill Yuan }; 92*4408d548SBill Yuan 93*4408d548SBill Yuan struct cmd_send_state { 94*4408d548SBill Yuan int type; /* test, state or NAT */ 95*4408d548SBill Yuan struct ipfw_flow_id flow; 96*4408d548SBill Yuan uint32_t expiry; 97*4408d548SBill Yuan uint16_t lifetime; 98*4408d548SBill Yuan int rulenum; 99*4408d548SBill Yuan int cpu; 100*4408d548SBill Yuan int hash; 101*4408d548SBill Yuan }; 102*4408d548SBill Yuan 103*4408d548SBill Yuan struct cmd_send_nat { 104*4408d548SBill Yuan int type; /* test, state, or NAT */ 105*4408d548SBill Yuan }; 106*4408d548SBill Yuan 107*4408d548SBill Yuan struct netmsg_sync { 108*4408d548SBill Yuan struct netmsg_base base; 109*4408d548SBill Yuan struct ipfw3_ioc_sync_centre *centre; 110*4408d548SBill Yuan int retval; 111*4408d548SBill Yuan }; 112*4408d548SBill Yuan 113*4408d548SBill Yuan typedef void ipfw_sync_send_state_t(struct ipfw3_state *, int cpu, int hash); 114*4408d548SBill Yuan typedef void ipfw_sync_install_state_t(struct cmd_send_state *cmd); 115*4408d548SBill Yuan 116*4408d548SBill Yuan void ip_fw3_sync_install_state(struct cmd_send_state *cmd); 117*4408d548SBill Yuan 118*4408d548SBill Yuan void ip_fw3_sync_centre_conf_dispath(netmsg_t nmsg); 119*4408d548SBill Yuan int ip_fw3_ctl_sync_centre_conf(struct sockopt *sopt); 120*4408d548SBill Yuan int ip_fw3_ctl_sync_show_conf(struct sockopt *sopt); 121*4408d548SBill Yuan int ip_fw3_ctl_sync_show_status(struct sockopt *sopt); 122*4408d548SBill Yuan int ip_fw3_ctl_sync_edge_conf(struct sockopt *sopt); 123*4408d548SBill Yuan void ip_fw3_sync_edge_socket_handler(void *dummy); 124*4408d548SBill Yuan int ip_fw3_ctl_sync_edge_start(struct sockopt *sopt); 125*4408d548SBill Yuan int ip_fw3_ctl_sync_edge_test(struct sockopt *sopt); 126*4408d548SBill Yuan int ip_fw3_ctl_sync_centre_start(struct sockopt *sopt); 127*4408d548SBill Yuan int ip_fw3_ctl_sync_centre_test(struct sockopt *sopt); 128*4408d548SBill Yuan int ip_fw3_ctl_sync_edge_stop(struct sockopt *sopt); 129*4408d548SBill Yuan int ip_fw3_ctl_sync_centre_stop(struct sockopt *sopt); 130*4408d548SBill Yuan int ip_fw3_ctl_sync_edge_clear(struct sockopt *sopt); 131*4408d548SBill Yuan int ip_fw3_ctl_sync_centre_clear(struct sockopt *sopt); 132*4408d548SBill Yuan int ip_fw3_ctl_sync_sockopt(struct sockopt *sopt); 133*4408d548SBill Yuan void ip_fw3_sync_send_state(struct ipfw3_state *state, int cpu, int hash); 134*4408d548SBill Yuan 135*4408d548SBill Yuan #endif /* _KERNEL */ 136*4408d548SBill Yuan #endif /* _IP_FW3_SYNC_H_ */ 137