Annotation of fwsync/driver/fwsync.h, revision 1.10.2.1
1.10 misho 1: /*-
2: * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3: *
4: * Copyright (c) 2022 Michael Pounov <misho@elwix.org>, CloudSigma AG
5: *
6: * Redistribution and use in source and binary forms, with or without
7: * modification, are permitted provided that the following conditions
8: * are met:
9: * 1. Redistributions of source code must retain the above copyright
10: * notice, this list of conditions and the following disclaimer.
11: * 2. Redistributions in binary form must reproduce the above copyright
12: * notice, this list of conditions and the following disclaimer in the
13: * documentation and/or other materials provided with the distribution.
14: *
15: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18: * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25: * SUCH DAMAGE.
26: */
1.1 misho 27: #ifndef __FWSYNC_H
28: #define __FWSYNC_H
29:
30: #include <sys/types.h>
31: #include <sys/param.h>
32: #include <sys/systm.h>
33: #include <sys/errno.h>
34: #include <sys/kernel.h>
35: #include <sys/module.h>
36: #include <sys/conf.h>
37: #include <machine/atomic.h>
38: #include <sys/malloc.h>
39: #include <sys/sysctl.h>
40: #include <sys/mbuf.h>
41: #include <sys/socket.h>
42: #include <sys/socketvar.h>
43: #include <sys/un.h>
44: #include <sys/module.h>
45: #include <sys/kthread.h>
1.2 misho 46: #include <sys/priority.h>
1.1 misho 47: #include <sys/taskqueue.h>
1.2 misho 48: #include <sys/queue.h>
1.4 misho 49: #include <sys/tree.h>
1.2 misho 50: #include <sys/mutex.h>
1.1 misho 51: #include <sys/uio.h>
52: #include <sys/poll.h>
1.9 misho 53:
54: #include <netinet/libalias/alias.h>
55: #include <netinet/libalias/alias_local.h>
56: #include <netinet/libalias/alias_db.h>
57:
1.1 misho 58: #include <net/if.h>
59: #include <net/if_var.h>
60: #include <net/if_dl.h>
61: #include <netinet/in.h>
62: #include <netinet/ip.h>
63: #include <netinet/ip_var.h>
64: #include <netinet/udp.h>
1.9 misho 65: #include <netinet/ip_fw.h>
1.1 misho 66:
67: #include <netpfil/ipfw/ip_fw_private.h>
68:
69: #include "fwsync_proto.h"
70: #include "fwsync_workers.h"
71:
72:
73: #define IFT_FWSYNC 0xfc
74:
75: #define DRV_NAME "fwsync"
76: #define DRV_VERSION 1
77: #define DRV_BUFSIZ 4096
78:
79: #ifndef DRV_DEBUG
80: #define DRV_DEBUG 0
81: #endif
82:
83: #ifndef STRSIZ
84: #define STRSIZ 256
85: #endif
86: #ifndef BUFSIZ
87: #define BUFSIZ 1024
88: #endif
89:
90: MALLOC_DECLARE(M_FWSYNC);
91:
92: SYSCTL_DECL(_net_inet_ip);
93: SYSCTL_DECL(_net_inet_ip_fwsync);
94:
95: #define FWS_DEBUG(x, fmt, ...) if ((x) <= fwsync_debug) printf((fmt), ## __VA_ARGS__)
96: #define DTRACE() FWS_DEBUG(9, "I'm in %s at line %d into file %s\n", \
97: __func__, __LINE__, __FILE__)
98:
99: struct cfg_sync {
100: union {
101: struct {
102: u_int on:2;
103: u_int edge:1;
104: u_int collector:1;
105: u_int reserved:20;
106: u_int addrs:8;
107: } cfg;
108: u_int cfg_mode;
109: };
110: struct {
111: union {
112: struct sockaddr addr;
113: struct sockaddr_in ip4;
114: struct sockaddr_in6 ip6;
115: };
116: } cfg_addr[3];
117: };
118: #define CFG_SYNC_ADDR_EDGE 0
119: #define CFG_SYNC_ADDR_COLLECTOR_1 1
120: #define CFG_SYNC_ADDR_COLLECTOR_2 2
121:
122: typedef union {
123: struct sockaddr_storage ss;
124: struct sockaddr sa;
125: struct sockaddr_un sun;
126: struct sockaddr_in sin;
127: struct sockaddr_in6 sin6;
128: struct sockaddr_dl sdl;
129: } sockaddr_t;
130: #define E_SOCKADDR_INIT { .ss = { 0 } }
131:
132: struct fwsync_context {
133: u_int config;
134:
135: u_long edge_count;
136:
137: struct socket *sockz[3];
138: struct proc *procz[3];
139: };
140: #define CTX_CFG_EDGE 0x1
141: #define CTX_CFG_COLLECTOR_1 0x2
142: #define CTX_CFG_COLLECTOR_2 0x4
143: #define CTX_EDGE_READY 0x8
144: #define CTX_COLLECTOR_1_READY 0x10
145: #define CTX_COLLECTOR_2_READY 0x20
146: #define CTX_EDGE_ONLINE 0x40
147: #define CTX_COLLECTOR_1_ONLINE 0x80
148: #define CTX_COLLECTOR_2_ONLINE 0x100
149:
1.2 misho 150: struct fws_sndpkt {
151: struct fws_proto sp_proto;
152: TAILQ_ENTRY(fws_sndpkt) sp_next;
153: };
154:
155: typedef TAILQ_HEAD(, fws_sndpkt) fwsync_sndpkt_t;
156:
1.10.2.1! misho 157: struct fws_acct {
! 158: uint64_t states[2];
! 159: uint64_t aliases[2];
! 160: };
! 161:
1.1 misho 162: extern int fwsync_debug;
163: extern struct fwsync_context fws_ctx;
164: extern struct cfg_sync fws_cfg;
165: extern struct task fws_sndpkt_task;
1.2 misho 166: extern struct taskqueue *fws_tq;
1.6 misho 167: extern struct callout fws_co;
1.8 misho 168: extern struct mtx fws_mtx_c, fws_mtx_e, fws_mtx_u, fws_mtx_n;
1.2 misho 169: extern struct mbuf *fws_sndpkt;
1.8 misho 170: extern fwsync_sndpkt_t fwsync_sndpkt, fwsync_updpkt, fwsync_natpkt;
1.10.2.1! misho 171: extern struct fws_acct fws_acct;
1.1 misho 172:
173: int fwsync_cfg(struct ip_fw_chain *ch, ip_fw3_opheader *op3, struct sockopt_data *sd);
174: int fwsync_destroy(struct ip_fw_chain *ch, ip_fw3_opheader *op3, struct sockopt_data *sd);
175: int fwsync_get_cfg(struct ip_fw_chain *ch, ip_fw3_opheader *op3, struct sockopt_data *sd);
176: int fwsync_list(struct ip_fw_chain *ch, ip_fw3_opheader *op3, struct sockopt_data *sd);
177: int fwsync_start(struct ip_fw_chain *ch, ip_fw3_opheader *op3, struct sockopt_data *sd);
178: int fwsync_stop(struct ip_fw_chain *ch, ip_fw3_opheader *op3, struct sockopt_data *sd);
179:
180:
181: #endif
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>