Annotation of fwsync/driver/fwsync.h, revision 1.3

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

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