Annotation of fwsync/driver/fwsync.h, revision 1.10
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:
150: #if 0
151: #define DRETFLUSH _IOW('D', 1, u_char)
152: #define DRETADDFILT _IOW('D', 2, struct dret_filter)
153: #define DRETDELFILT _IOW('D', 3, struct dret_filter)
154: #define DRETACCTFLUSH _IOW('D', 4, u_char)
155: #define DRETACCTDEL _IOW('D', 5, struct tagAccount)
156: #define DRETACCTGET _IOWR('D', 6, struct tagAccount)
157:
158: #define DRETDIROFF 0
159: #define DRETDIRIN 1
160: #define DRETDIROUT 2
161: #define DRETDIRANY 3
162: #define DRETACCT 4
163:
164: struct dret_filter {
165: u_char filt_dir;
166: u_int filt_proto[8];
167: char filt_iface[IFNAMSIZ];
168: netaddr_t filt_net;
169: };
170: #define FP_MASK(n) ((u_int) 1 << ((n) % 32))
171: #define FP_ISSET(n, a) ((a)[(n) / 32] & FP_MASK(n))
172: #define FP_CLR(n, a) ((a)[(n) / 32] &= ~FP_MASK(n))
173: #define FP_SET(n, a) ((a)[(n) / 32] |= FP_MASK(n))
174: #define FP_ZERO(a) do { int _i = 8; \
175: while (_i > 0) \
176: (a)[--_i] = 0; \
177: } while (0)
178: #endif
179:
1.2 misho 180: struct fws_sndpkt {
181: struct fws_proto sp_proto;
182: TAILQ_ENTRY(fws_sndpkt) sp_next;
183: };
184:
185: typedef TAILQ_HEAD(, fws_sndpkt) fwsync_sndpkt_t;
186:
1.1 misho 187: extern int fwsync_debug;
188: extern struct fwsync_context fws_ctx;
189: extern struct cfg_sync fws_cfg;
190: extern struct task fws_sndpkt_task;
1.2 misho 191: extern struct taskqueue *fws_tq;
1.6 misho 192: extern struct callout fws_co;
1.8 misho 193: extern struct mtx fws_mtx_c, fws_mtx_e, fws_mtx_u, fws_mtx_n;
1.2 misho 194: extern struct mbuf *fws_sndpkt;
1.8 misho 195: extern fwsync_sndpkt_t fwsync_sndpkt, fwsync_updpkt, fwsync_natpkt;
1.1 misho 196:
197: int fwsync_cfg(struct ip_fw_chain *ch, ip_fw3_opheader *op3, struct sockopt_data *sd);
198: int fwsync_destroy(struct ip_fw_chain *ch, ip_fw3_opheader *op3, struct sockopt_data *sd);
199: int fwsync_get_cfg(struct ip_fw_chain *ch, ip_fw3_opheader *op3, struct sockopt_data *sd);
200: int fwsync_list(struct ip_fw_chain *ch, ip_fw3_opheader *op3, struct sockopt_data *sd);
201: int fwsync_start(struct ip_fw_chain *ch, ip_fw3_opheader *op3, struct sockopt_data *sd);
202: int fwsync_stop(struct ip_fw_chain *ch, ip_fw3_opheader *op3, struct sockopt_data *sd);
203:
204:
205: #endif
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>