Annotation of fwsync/driver/fwsync.h, revision 1.8
1.1 misho 1: /*************************************************************************
2: * (C) 2022 CloudSigma AG - Sofia/Bulgaria
3: * by Michael Pounov <misho@elwix.org>
4: **************************************************************************/
5: #ifndef __FWSYNC_H
6: #define __FWSYNC_H
7:
8: #include <sys/types.h>
9: #include <sys/param.h>
10: #include <sys/systm.h>
11: #include <sys/errno.h>
12: #include <sys/kernel.h>
13: #include <sys/module.h>
14: #include <sys/conf.h>
15: #include <machine/atomic.h>
16: #include <sys/malloc.h>
17: #include <sys/sysctl.h>
18: #include <sys/mbuf.h>
19: #include <sys/socket.h>
20: #include <sys/socketvar.h>
21: #include <sys/un.h>
22: #include <sys/module.h>
23: #include <sys/kthread.h>
1.2 misho 24: #include <sys/priority.h>
1.1 misho 25: #include <sys/taskqueue.h>
1.2 misho 26: #include <sys/queue.h>
1.4 misho 27: #include <sys/tree.h>
1.2 misho 28: #include <sys/mutex.h>
1.1 misho 29: #include <sys/uio.h>
30: #include <sys/poll.h>
31: #include <net/if.h>
32: #include <net/if_var.h>
33: #include <net/if_dl.h>
34: #include <netinet/in.h>
35: #include <netinet/ip.h>
36: #include <netinet/ip_var.h>
37: #include <netinet/udp.h>
1.4 misho 38: #include <netinet/libalias/alias.h>
39: #include <netinet/libalias/alias_local.h>
40: #include <netinet/libalias/alias_db.h>
1.1 misho 41:
42: #define IPFW_INTERNAL
43:
44: #include <netinet/ip_fw.h>
45: #include <netpfil/ipfw/ip_fw_private.h>
46:
47: #include "fwsync_proto.h"
1.5 misho 48: #include "fwsync_utils.h"
1.1 misho 49: #include "fwsync_workers.h"
50:
51:
52: #define IFT_FWSYNC 0xfc
53:
54: #define DRV_NAME "fwsync"
55: #define DRV_VERSION 1
56: #define DRV_BUFSIZ 4096
57:
58: #ifndef DRV_DEBUG
59: #define DRV_DEBUG 0
60: #endif
61:
62: #ifndef STRSIZ
63: #define STRSIZ 256
64: #endif
65: #ifndef BUFSIZ
66: #define BUFSIZ 1024
67: #endif
68:
69: MALLOC_DECLARE(M_FWSYNC);
70:
71: SYSCTL_DECL(_net_inet_ip);
72: SYSCTL_DECL(_net_inet_ip_fwsync);
73:
74: #define FWS_DEBUG(x, fmt, ...) if ((x) <= fwsync_debug) printf((fmt), ## __VA_ARGS__)
75: #define DTRACE() FWS_DEBUG(9, "I'm in %s at line %d into file %s\n", \
76: __func__, __LINE__, __FILE__)
77:
78: struct cfg_sync {
79: union {
80: struct {
81: u_int on:2;
82: u_int edge:1;
83: u_int collector:1;
84: u_int reserved:20;
85: u_int addrs:8;
86: } cfg;
87: u_int cfg_mode;
88: };
89: struct {
90: union {
91: struct sockaddr addr;
92: struct sockaddr_in ip4;
93: struct sockaddr_in6 ip6;
94: };
95: } cfg_addr[3];
96: };
97: #define CFG_SYNC_ADDR_EDGE 0
98: #define CFG_SYNC_ADDR_COLLECTOR_1 1
99: #define CFG_SYNC_ADDR_COLLECTOR_2 2
100:
101: typedef union {
102: struct sockaddr_storage ss;
103: struct sockaddr sa;
104: struct sockaddr_un sun;
105: struct sockaddr_in sin;
106: struct sockaddr_in6 sin6;
107: struct sockaddr_dl sdl;
108: } sockaddr_t;
109: #define E_SOCKADDR_INIT { .ss = { 0 } }
110:
111: struct fwsync_context {
112: u_int config;
113:
114: u_long edge_count;
115:
116: struct socket *sockz[3];
117: struct proc *procz[3];
118: };
119: #define CTX_CFG_EDGE 0x1
120: #define CTX_CFG_COLLECTOR_1 0x2
121: #define CTX_CFG_COLLECTOR_2 0x4
122: #define CTX_EDGE_READY 0x8
123: #define CTX_COLLECTOR_1_READY 0x10
124: #define CTX_COLLECTOR_2_READY 0x20
125: #define CTX_EDGE_ONLINE 0x40
126: #define CTX_COLLECTOR_1_ONLINE 0x80
127: #define CTX_COLLECTOR_2_ONLINE 0x100
128:
129: #if 0
130: #define DRETFLUSH _IOW('D', 1, u_char)
131: #define DRETADDFILT _IOW('D', 2, struct dret_filter)
132: #define DRETDELFILT _IOW('D', 3, struct dret_filter)
133: #define DRETACCTFLUSH _IOW('D', 4, u_char)
134: #define DRETACCTDEL _IOW('D', 5, struct tagAccount)
135: #define DRETACCTGET _IOWR('D', 6, struct tagAccount)
136:
137: #define DRETDIROFF 0
138: #define DRETDIRIN 1
139: #define DRETDIROUT 2
140: #define DRETDIRANY 3
141: #define DRETACCT 4
142:
143: struct dret_filter {
144: u_char filt_dir;
145: u_int filt_proto[8];
146: char filt_iface[IFNAMSIZ];
147: netaddr_t filt_net;
148: };
149: #define FP_MASK(n) ((u_int) 1 << ((n) % 32))
150: #define FP_ISSET(n, a) ((a)[(n) / 32] & FP_MASK(n))
151: #define FP_CLR(n, a) ((a)[(n) / 32] &= ~FP_MASK(n))
152: #define FP_SET(n, a) ((a)[(n) / 32] |= FP_MASK(n))
153: #define FP_ZERO(a) do { int _i = 8; \
154: while (_i > 0) \
155: (a)[--_i] = 0; \
156: } while (0)
157: #endif
158:
1.2 misho 159: struct fws_sndpkt {
160: struct fws_proto sp_proto;
161: TAILQ_ENTRY(fws_sndpkt) sp_next;
162: };
163:
164: typedef TAILQ_HEAD(, fws_sndpkt) fwsync_sndpkt_t;
165:
1.1 misho 166: extern int fwsync_debug;
167: extern struct fwsync_context fws_ctx;
168: extern struct cfg_sync fws_cfg;
169: extern struct task fws_sndpkt_task;
1.2 misho 170: extern struct taskqueue *fws_tq;
1.6 misho 171: extern struct callout fws_co;
1.8 ! misho 172: extern struct mtx fws_mtx_c, fws_mtx_e, fws_mtx_u, fws_mtx_n;
1.2 misho 173: extern struct mbuf *fws_sndpkt;
1.8 ! misho 174: extern fwsync_sndpkt_t fwsync_sndpkt, fwsync_updpkt, fwsync_natpkt;
1.1 misho 175:
176: int fwsync_cfg(struct ip_fw_chain *ch, ip_fw3_opheader *op3, struct sockopt_data *sd);
177: int fwsync_destroy(struct ip_fw_chain *ch, ip_fw3_opheader *op3, struct sockopt_data *sd);
178: int fwsync_get_cfg(struct ip_fw_chain *ch, ip_fw3_opheader *op3, struct sockopt_data *sd);
179: int fwsync_list(struct ip_fw_chain *ch, ip_fw3_opheader *op3, struct sockopt_data *sd);
180: int fwsync_start(struct ip_fw_chain *ch, ip_fw3_opheader *op3, struct sockopt_data *sd);
181: int fwsync_stop(struct ip_fw_chain *ch, ip_fw3_opheader *op3, struct sockopt_data *sd);
182:
183:
184: #endif
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>