1 /* 2 pmacct (Promiscuous mode IP Accounting package) 3 pmacct is Copyright (C) 2003-2020 by Paolo Lucente 4 */ 5 6 /* 7 This program is free software; you can redistribute it and/or modify 8 it under the terms of the GNU General Public License as published by 9 the Free Software Foundation; either version 2 of the License, or 10 (at your option) any later version. 11 12 This program is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with this program; if not, write to the Free Software 19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 20 */ 21 22 /* includes */ 23 #include <zmq.h> 24 25 /* defines */ 26 #define PLUGIN_PIPE_ZMQ_NONE 0 27 #define PLUGIN_PIPE_ZMQ_MICRO 1 28 #define PLUGIN_PIPE_ZMQ_SMALL 2 29 #define PLUGIN_PIPE_ZMQ_MEDIUM 3 30 #define PLUGIN_PIPE_ZMQ_LARGE 4 31 #define PLUGIN_PIPE_ZMQ_XLARGE 5 32 33 #define PLUGIN_PIPE_ZMQ_MICRO_SIZE 0 34 #define PLUGIN_PIPE_ZMQ_SMALL_SIZE 10000 35 #define PLUGIN_PIPE_ZMQ_MEDIUM_SIZE 100000 36 #define PLUGIN_PIPE_ZMQ_LARGE_SIZE 1000000 37 #define PLUGIN_PIPE_ZMQ_XLARGE_SIZE 10000000 38 39 #define PM_ZMQ_EVENTS_RETRIES 3 40 #define PM_ZMQ_DEFAULT_RETRY 1000 /* 1 sec */ 41 #define PM_ZMQ_DEFAULT_FLOW_HWM 100000 /* ~150MB @ 1500 bytes/packet */ 42 43 /* structures */ 44 struct p_zmq_sock { 45 void *obj; /* XXX: to be removed */ 46 void *obj_tx; 47 void *obj_rx; 48 char str[SHORTBUFLEN]; 49 }; 50 51 struct p_zmq_zap { 52 struct p_zmq_sock sock; 53 void *thread; 54 char username[SHORTBUFLEN]; 55 char password[SHORTBUFLEN]; 56 }; 57 58 struct p_zmq_router_worker { 59 void **threads; 60 void (*func)(void *, void *); 61 }; 62 63 struct p_zmq_host { 64 void *ctx; 65 struct p_zmq_zap zap; 66 char log_id[SHORTBUFLEN]; 67 68 struct p_zmq_sock sock; 69 struct p_zmq_sock sock_inproc; 70 struct p_zmq_router_worker router_worker; 71 72 u_int8_t topic; 73 int hwm; 74 }; 75 76 /* prototypes */ 77 extern void p_zmq_set_address(struct p_zmq_host *, char *); 78 extern void p_zmq_set_topic(struct p_zmq_host *, u_int8_t); 79 extern void p_zmq_set_retry_timeout(struct p_zmq_host *, int); 80 extern void p_zmq_set_username(struct p_zmq_host *, char *); 81 extern void p_zmq_set_password(struct p_zmq_host *, char *); 82 extern void p_zmq_set_random_username(struct p_zmq_host *); 83 extern void p_zmq_set_random_password(struct p_zmq_host *); 84 extern void p_zmq_set_hwm(struct p_zmq_host *, int); 85 extern void p_zmq_set_log_id(struct p_zmq_host *, char *); 86 87 extern char *p_zmq_get_address(struct p_zmq_host *); 88 extern u_int8_t p_zmq_get_topic(struct p_zmq_host *); 89 extern void *p_zmq_get_sock(struct p_zmq_host *); 90 extern int p_zmq_get_fd(struct p_zmq_host *); 91 92 extern int p_zmq_connect(struct p_zmq_host *); 93 extern int p_zmq_bind(struct p_zmq_host *); 94 95 extern void p_zmq_init_pub(struct p_zmq_host *, char *, u_int8_t); 96 extern void p_zmq_init_sub(struct p_zmq_host *); 97 extern void p_zmq_init_push(struct p_zmq_host *, char *); 98 extern void p_zmq_init_pull(struct p_zmq_host *); 99 extern int p_zmq_recv_poll(struct p_zmq_sock *, int); 100 extern int p_zmq_topic_recv(struct p_zmq_host *, void *, u_int64_t); 101 extern int p_zmq_topic_send(struct p_zmq_host *, void *, u_int64_t); 102 extern void p_zmq_close(struct p_zmq_host *); 103 104 extern void p_zmq_plugin_pipe_init_core(struct p_zmq_host *, u_int8_t, char *, char *); 105 extern void p_zmq_plugin_pipe_init_plugin(struct p_zmq_host *); 106 extern int p_zmq_plugin_pipe_set_profile(struct configuration *, char *); 107 extern void p_zmq_ctx_setup(struct p_zmq_host *); 108 extern void p_zmq_pull_setup(struct p_zmq_host *); 109 extern void p_zmq_pull_bind_setup(struct p_zmq_host *); 110 extern void p_zmq_sub_setup(struct p_zmq_host *); 111 extern void p_zmq_push_setup(struct p_zmq_host *); 112 extern void p_zmq_push_connect_setup(struct p_zmq_host *); 113 extern void p_zmq_pub_setup(struct p_zmq_host *); 114 extern void p_zmq_zap_setup(struct p_zmq_host *); 115 extern void p_zmq_recv_setup(struct p_zmq_host *, int, int); 116 extern void p_zmq_send_setup(struct p_zmq_host *, int, int); 117 118 extern void p_zmq_router_setup(struct p_zmq_host *, char *, int); 119 extern void p_zmq_dealer_inproc_setup(struct p_zmq_host *); 120 extern void p_zmq_proxy_setup(struct p_zmq_host *); 121 extern void p_zmq_router_backend_setup(struct p_zmq_host *, int); 122 extern void p_zmq_router_worker(void *); 123 124 extern char *p_zmq_recv_str(struct p_zmq_sock *); 125 extern int p_zmq_send_str(struct p_zmq_sock *, char *); 126 extern int p_zmq_sendmore_str(struct p_zmq_sock *, char *); 127 extern int p_zmq_recv_bin(struct p_zmq_sock *, void *, size_t); 128 extern int p_zmq_send_bin(struct p_zmq_sock *, void *, size_t, int); 129 extern int p_zmq_sendmore_bin(struct p_zmq_sock *, void *, size_t, int); 130 131 extern void p_zmq_zap_handler(void *); 132 133 /* global vars */ 134 extern struct p_zmq_host nfacctd_zmq_host; 135 extern struct p_zmq_host telemetry_zmq_host; 136