File:  [ELWIX - Embedded LightWeight unIX -] / fwsync / driver / fwsync.h
Revision 1.1: download - view: text, annotated - select for diffs - revision graph
Wed Jun 22 13:01:55 2022 UTC (2 years ago) by misho
Branches: MAIN
CVS tags: HEAD
Initial revision

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