File:  [ELWIX - Embedded LightWeight unIX -] / fwsync / driver / fwsync.h
Revision 1.10.2.2: download - view: text, annotated - select for diffs - revision graph
Fri Aug 26 13:59:41 2022 UTC (21 months ago) by misho
Branches: fwsync1_1
finish implementation of accounting counters for handled records

    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:  */
   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>
   46: #include <sys/priority.h>
   47: #include <sys/taskqueue.h>
   48: #include <sys/queue.h>
   49: #include <sys/tree.h>
   50: #include <sys/mutex.h>
   51: #include <sys/uio.h>
   52: #include <sys/poll.h>
   53: 
   54: #include <netinet/libalias/alias.h>
   55: #include <netinet/libalias/alias_local.h>
   56: #include <netinet/libalias/alias_db.h>
   57: 
   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>
   65: #include <netinet/ip_fw.h>
   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: #define IFT_FWSYNC_ACCT	0xfd
   75: 
   76: #define DRV_NAME	"fwsync"
   77: #define DRV_VERSION	1
   78: #define DRV_BUFSIZ	4096
   79: 
   80: #ifndef DRV_DEBUG
   81: #define DRV_DEBUG	0
   82: #endif
   83: 
   84: #ifndef STRSIZ
   85: #define STRSIZ		256
   86: #endif
   87: #ifndef BUFSIZ
   88: #define BUFSIZ		1024
   89: #endif
   90: 
   91: MALLOC_DECLARE(M_FWSYNC);
   92: 
   93: SYSCTL_DECL(_net_inet_ip);
   94: SYSCTL_DECL(_net_inet_ip_fwsync);
   95: 
   96: #define FWS_DEBUG(x, fmt, ...)	if ((x) <= fwsync_debug) printf((fmt), ## __VA_ARGS__)
   97: #define DTRACE()		FWS_DEBUG(9, "I'm in %s at line %d into file %s\n", \
   98: 						__func__, __LINE__, __FILE__)
   99: 
  100: struct cfg_sync {
  101: 	union {
  102: 		struct {
  103: 			u_int 	on:2;
  104: 			u_int 	edge:1;
  105: 			u_int 	collector:1;
  106: 			u_int 	reserved:20;
  107: 			u_int 	addrs:8;
  108: 		} cfg;
  109: 		u_int 	cfg_mode;
  110: 	};
  111: 	struct {
  112: 		union {
  113: 			struct sockaddr		addr;
  114: 			struct sockaddr_in	ip4;
  115: 			struct sockaddr_in6	ip6;
  116: 		};
  117: 	}		cfg_addr[3];
  118: };
  119: #define CFG_SYNC_ADDR_EDGE		0
  120: #define CFG_SYNC_ADDR_COLLECTOR_1	1
  121: #define CFG_SYNC_ADDR_COLLECTOR_2	2
  122: 
  123: typedef union {
  124: 	struct sockaddr_storage	ss;
  125: 	struct sockaddr		sa;
  126: 	struct sockaddr_un	sun;
  127: 	struct sockaddr_in	sin;
  128: 	struct sockaddr_in6	sin6;
  129: 	struct sockaddr_dl	sdl;
  130: } sockaddr_t;
  131: #define E_SOCKADDR_INIT	{ .ss = { 0 } }
  132: 
  133: struct fwsync_context {
  134: 	u_int config;
  135: 
  136: 	u_long edge_count;
  137: 
  138: 	struct socket *sockz[3];
  139: 	struct proc *procz[3];
  140: };
  141: #define CTX_CFG_EDGE		0x1
  142: #define CTX_CFG_COLLECTOR_1	0x2
  143: #define CTX_CFG_COLLECTOR_2	0x4
  144: #define CTX_EDGE_READY		0x8
  145: #define CTX_COLLECTOR_1_READY	0x10
  146: #define CTX_COLLECTOR_2_READY	0x20
  147: #define CTX_EDGE_ONLINE		0x40
  148: #define CTX_COLLECTOR_1_ONLINE	0x80
  149: #define CTX_COLLECTOR_2_ONLINE	0x100
  150: 
  151: struct fws_sndpkt {
  152: 	struct fws_proto	sp_proto;
  153: 	TAILQ_ENTRY(fws_sndpkt)	sp_next;
  154: };
  155: 
  156: typedef TAILQ_HEAD(, fws_sndpkt) fwsync_sndpkt_t;
  157: 
  158: struct fws_acct {
  159: 	uint64_t	states[2];
  160: 	uint64_t	aliases[2];
  161: };
  162: 
  163: extern int fwsync_debug;
  164: extern struct fwsync_context fws_ctx;
  165: extern struct cfg_sync fws_cfg;
  166: extern struct task fws_sndpkt_task;
  167: extern struct taskqueue *fws_tq;
  168: extern struct callout fws_co;
  169: extern struct mtx fws_mtx_c, fws_mtx_e, fws_mtx_u, fws_mtx_n;
  170: extern struct mbuf *fws_sndpkt;
  171: extern fwsync_sndpkt_t fwsync_sndpkt, fwsync_updpkt, fwsync_natpkt; 
  172: extern struct fws_acct fws_acct;
  173: 
  174: int fwsync_cfg(struct ip_fw_chain *ch, ip_fw3_opheader *op3, struct sockopt_data *sd);
  175: int fwsync_destroy(struct ip_fw_chain *ch, ip_fw3_opheader *op3, struct sockopt_data *sd);
  176: int fwsync_get_cfg(struct ip_fw_chain *ch, ip_fw3_opheader *op3, struct sockopt_data *sd);
  177: int fwsync_list(struct ip_fw_chain *ch, ip_fw3_opheader *op3, struct sockopt_data *sd);
  178: int fwsync_start(struct ip_fw_chain *ch, ip_fw3_opheader *op3, struct sockopt_data *sd);
  179: int fwsync_stop(struct ip_fw_chain *ch, ip_fw3_opheader *op3, struct sockopt_data *sd);
  180: 
  181: 
  182: #endif

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