File:  [ELWIX - Embedded LightWeight unIX -] / fwsync / driver / fwsync.h
Revision 1.11: download - view: text, annotated - select for diffs - revision graph
Fri Aug 26 14:47:36 2022 UTC (20 months, 1 week ago) by misho
Branches: MAIN
CVS tags: fwsync1_2, HEAD, FWSYNC1_1
version 1.1
 - adds list command

/*-
 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
 *
 * Copyright (c) 2022 Michael Pounov <misho@elwix.org>, CloudSigma AG
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */
#ifndef __FWSYNC_H
#define __FWSYNC_H

#include <sys/types.h>
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/errno.h>
#include <sys/kernel.h>
#include <sys/module.h>
#include <sys/conf.h>
#include <machine/atomic.h>
#include <sys/malloc.h>
#include <sys/sysctl.h>
#include <sys/mbuf.h>
#include <sys/socket.h>
#include <sys/socketvar.h>
#include <sys/un.h>
#include <sys/module.h>
#include <sys/kthread.h>
#include <sys/priority.h>
#include <sys/taskqueue.h>
#include <sys/queue.h>
#include <sys/tree.h>
#include <sys/mutex.h>
#include <sys/uio.h>
#include <sys/poll.h>

#include <netinet/libalias/alias.h>
#include <netinet/libalias/alias_local.h>
#include <netinet/libalias/alias_db.h>

#include <net/if.h>
#include <net/if_var.h>
#include <net/if_dl.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <netinet/ip_var.h>
#include <netinet/udp.h>
#include <netinet/ip_fw.h>

#include <netpfil/ipfw/ip_fw_private.h>

#include "fwsync_proto.h"
#include "fwsync_workers.h"


#define IFT_FWSYNC	0xfc
#define IFT_FWSYNC_ACCT	0xfd

#define DRV_NAME	"fwsync"
#define DRV_VERSION	1
#define DRV_BUFSIZ	4096

#ifndef DRV_DEBUG
#define DRV_DEBUG	0
#endif

#ifndef STRSIZ
#define STRSIZ		256
#endif
#ifndef BUFSIZ
#define BUFSIZ		1024
#endif

MALLOC_DECLARE(M_FWSYNC);

SYSCTL_DECL(_net_inet_ip);
SYSCTL_DECL(_net_inet_ip_fwsync);

#define FWS_DEBUG(x, fmt, ...)	if ((x) <= fwsync_debug) printf((fmt), ## __VA_ARGS__)
#define DTRACE()		FWS_DEBUG(9, "I'm in %s at line %d into file %s\n", \
						__func__, __LINE__, __FILE__)

struct cfg_sync {
	union {
		struct {
			u_int 	on:2;
			u_int 	edge:1;
			u_int 	collector:1;
			u_int 	reserved:20;
			u_int 	addrs:8;
		} cfg;
		u_int 	cfg_mode;
	};
	struct {
		union {
			struct sockaddr		addr;
			struct sockaddr_in	ip4;
			struct sockaddr_in6	ip6;
		};
	}		cfg_addr[3];
};
#define CFG_SYNC_ADDR_EDGE		0
#define CFG_SYNC_ADDR_COLLECTOR_1	1
#define CFG_SYNC_ADDR_COLLECTOR_2	2

typedef union {
	struct sockaddr_storage	ss;
	struct sockaddr		sa;
	struct sockaddr_un	sun;
	struct sockaddr_in	sin;
	struct sockaddr_in6	sin6;
	struct sockaddr_dl	sdl;
} sockaddr_t;
#define E_SOCKADDR_INIT	{ .ss = { 0 } }

struct fwsync_context {
	u_int config;

	u_long edge_count;

	struct socket *sockz[3];
	struct proc *procz[3];
};
#define CTX_CFG_EDGE		0x1
#define CTX_CFG_COLLECTOR_1	0x2
#define CTX_CFG_COLLECTOR_2	0x4
#define CTX_EDGE_READY		0x8
#define CTX_COLLECTOR_1_READY	0x10
#define CTX_COLLECTOR_2_READY	0x20
#define CTX_EDGE_ONLINE		0x40
#define CTX_COLLECTOR_1_ONLINE	0x80
#define CTX_COLLECTOR_2_ONLINE	0x100

struct fws_sndpkt {
	struct fws_proto	sp_proto;
	TAILQ_ENTRY(fws_sndpkt)	sp_next;
};

typedef TAILQ_HEAD(, fws_sndpkt) fwsync_sndpkt_t;

struct fws_acct {
	uint64_t	states[2];
	uint64_t	aliases[2];
};

extern int fwsync_debug;
extern struct fwsync_context fws_ctx;
extern struct cfg_sync fws_cfg;
extern struct task fws_sndpkt_task;
extern struct taskqueue *fws_tq;
extern struct callout fws_co;
extern struct mtx fws_mtx_c, fws_mtx_e, fws_mtx_u, fws_mtx_n;
extern struct mbuf *fws_sndpkt;
extern fwsync_sndpkt_t fwsync_sndpkt, fwsync_updpkt, fwsync_natpkt; 
extern struct fws_acct fws_acct;

int fwsync_cfg(struct ip_fw_chain *ch, ip_fw3_opheader *op3, struct sockopt_data *sd);
int fwsync_destroy(struct ip_fw_chain *ch, ip_fw3_opheader *op3, struct sockopt_data *sd);
int fwsync_get_cfg(struct ip_fw_chain *ch, ip_fw3_opheader *op3, struct sockopt_data *sd);
int fwsync_list(struct ip_fw_chain *ch, ip_fw3_opheader *op3, struct sockopt_data *sd);
int fwsync_start(struct ip_fw_chain *ch, ip_fw3_opheader *op3, struct sockopt_data *sd);
int fwsync_stop(struct ip_fw_chain *ch, ip_fw3_opheader *op3, struct sockopt_data *sd);


#endif

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