1 /* 2 * Copyright (c) 2016 - 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_SYNC_H_ 37 #define _IP_FW3_SYNC_H_ 38 39 #define MAX_EDGES 10 40 41 #define SYNC_TYPE_SEND_TEST 0 /* testing sync status */ 42 #define SYNC_TYPE_SEND_STATE 1 /* syncing state */ 43 #define SYNC_TYPE_SEND_NAT 2 /* syncing nat */ 44 45 46 struct ipfw3_sync_edge { 47 in_addr_t addr; 48 u_short port; 49 }; 50 #define LEN_SYNC_EDGE sizeof(struct ipfw3_sync_edge) 51 52 struct ipfw3_ioc_sync_context { 53 int edge_port; /* edge listening port */ 54 int hw_same; /* duplicate to all CPU when hardware different */ 55 int count; /* count of edge */ 56 struct ipfw3_sync_edge edges[0]; /* edge */ 57 }; 58 59 struct ipfw3_ioc_sync_centre { 60 int count; /* count of edge */ 61 struct ipfw3_sync_edge edges[0]; /* edge */ 62 }; 63 64 struct ipfw3_ioc_sync_edge { 65 int port; 66 int hw_same; 67 }; 68 69 struct ipfw3_sync_context{ 70 int edge_port; /* edge listening port */ 71 int hw_same; /* duplicate to all CPU when hardware different */ 72 int count; /* count of edge */ 73 int running; /* edge 01, centre 10 */ 74 struct ipfw3_sync_edge *edges; /* edge */ 75 struct thread *edge_td; /* edge handler thread */ 76 struct socket *edge_sock; /* edge sock */ 77 struct socket *centre_socks[MAX_EDGES]; /* centre socks */ 78 }; 79 80 81 82 #ifdef _KERNEL 83 84 #include <net/ipfw3_basic/ip_fw3_basic.h> 85 86 void ip_fw3_sync_modevent(int type); 87 88 struct cmd_send_test { 89 int type; 90 int num; 91 }; 92 93 struct cmd_send_state { 94 int type; /* test, state or NAT */ 95 struct ipfw_flow_id flow; 96 uint32_t expiry; 97 uint16_t lifetime; 98 int rulenum; 99 int cpu; 100 int hash; 101 }; 102 103 struct cmd_send_nat { 104 int type; /* test, state, or NAT */ 105 }; 106 107 struct netmsg_sync { 108 struct netmsg_base base; 109 struct ipfw3_ioc_sync_centre *centre; 110 int retval; 111 }; 112 113 typedef void ipfw_sync_send_state_t(struct ipfw3_state *, int cpu, int hash); 114 typedef void ipfw_sync_install_state_t(struct cmd_send_state *cmd); 115 116 void ip_fw3_sync_install_state(struct cmd_send_state *cmd); 117 118 void ip_fw3_sync_centre_conf_dispath(netmsg_t nmsg); 119 int ip_fw3_ctl_sync_centre_conf(struct sockopt *sopt); 120 int ip_fw3_ctl_sync_show_conf(struct sockopt *sopt); 121 int ip_fw3_ctl_sync_show_status(struct sockopt *sopt); 122 int ip_fw3_ctl_sync_edge_conf(struct sockopt *sopt); 123 void ip_fw3_sync_edge_socket_handler(void *dummy); 124 int ip_fw3_ctl_sync_edge_start(struct sockopt *sopt); 125 int ip_fw3_ctl_sync_edge_test(struct sockopt *sopt); 126 int ip_fw3_ctl_sync_centre_start(struct sockopt *sopt); 127 int ip_fw3_ctl_sync_centre_test(struct sockopt *sopt); 128 int ip_fw3_ctl_sync_edge_stop(struct sockopt *sopt); 129 int ip_fw3_ctl_sync_centre_stop(struct sockopt *sopt); 130 int ip_fw3_ctl_sync_edge_clear(struct sockopt *sopt); 131 int ip_fw3_ctl_sync_centre_clear(struct sockopt *sopt); 132 int ip_fw3_ctl_sync_sockopt(struct sockopt *sopt); 133 void ip_fw3_sync_send_state(struct ipfw3_state *state, int cpu, int hash); 134 135 #endif /* _KERNEL */ 136 #endif /* _IP_FW3_SYNC_H_ */ 137