File:  [ELWIX - Embedded LightWeight unIX -] / fwsync / driver / fwsync.h
Revision 1.2: download - view: text, annotated - select for diffs - revision graph
Wed Jun 29 19:44:58 2022 UTC (23 months, 2 weeks ago) by misho
Branches: MAIN
CVS tags: HEAD
entirely redesign of collector network engine

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>