123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237 |
- #ifndef _MON_LIB_DATA_H
- #define _MON_LIB_DATA_H
- #include <sys/queue.h>
- #include <sys/types.h>
- #include <sys/socket.h>
- #include <netinet/in.h>
- #include <limits.h>
- #include "lex.h"
- #define MON_CRCPOLY 0x04c11db7
- #if BYTE_ORDER == BIG_ENDIAN
- #define htonq(n) (n)
- #define ntohq(n) (n)
- #else
- static inline u_int64_t
- htonq (u_int64_t v)
- {
- return (u_int64_t)htonl(v) << 32 | htonl(v >> 32);
- }
- static inline u_int64_t
- ntohq (u_int64_t v)
- {
- return (u_int64_t)ntohl(v) << 32 | ntohl(v >> 32);
- }
- #endif
- #define MON_PACKET_VER 1
- struct monpacket {
- struct {
- u_int64_t timestamp;
- u_int32_t crc;
- u_int16_t length;
- u_int8_t mon_version;
- u_int8_t reserved;
- } header;
- char data[_POSIX2_LINE_MAX];
- };
-
- struct stream {
- int type;
- char *args;
- char *file;
- SLIST_ENTRY(stream) streams;
- };
- SLIST_HEAD(streamlist, stream);
- struct source {
- char *name;
- u_int32_t ip;
- u_int16_t port;
- struct streamlist sl;
- SLIST_ENTRY(source) sources;
- };
- SLIST_HEAD(sourcelist, source);
- struct mux {
- char *name;
- int offset;
- int clientsocket;
- int monsocket;
- struct monpacket packet;
- struct sockaddr_in sockaddr;
- struct streamlist sl;
- u_int32_t senderr;
- u_int32_t ip;
- u_int16_t port;
- SLIST_ENTRY(mux) muxes;
- };
- SLIST_HEAD(muxlist, mux);
- #define PS2STR_PRETTY 0
- #define PS2STR_RRD 1
- #define MT_IO 0
- #define MT_CPU 1
- #define MT_MEM 2
- #define MT_IF 3
- #define MT_PF 4
- #define MT_EOT 5
- #define MON_PS_ARGLEN 16
- struct packedstream {
- int type;
- int padding;
- char args[MON_PS_ARGLEN];
- union {
- struct {
- u_int64_t mtotal_transfers;
- u_int64_t mtotal_seeks;
- u_int64_t mtotal_bytes;
- } ps_io;
- struct {
- u_int16_t muser;
- u_int16_t mnice;
- u_int16_t msystem;
- u_int16_t minterrupt;
- u_int16_t midle;
- } ps_cpu;
- struct {
- u_int32_t mreal_active;
- u_int32_t mreal_total;
- u_int32_t mfree;
- u_int32_t mswap_used;
- u_int32_t mswap_total;
- } ps_mem;
- struct {
- u_int32_t mipackets;
- u_int32_t mopackets;
- u_int32_t mibytes;
- u_int32_t mobytes;
- u_int32_t mimcasts;
- u_int32_t momcasts;
- u_int32_t mierrors;
- u_int32_t moerrors;
- u_int32_t mcolls;
- u_int32_t mdrops;
- } ps_if;
- struct {
- u_int64_t bytes_v4_in;
- u_int64_t bytes_v4_out;
- u_int64_t bytes_v6_in;
- u_int64_t bytes_v6_out;
- u_int64_t packets_v4_in_pass;
- u_int64_t packets_v4_in_drop;
- u_int64_t packets_v4_out_pass;
- u_int64_t packets_v4_out_drop;
- u_int64_t packets_v6_in_pass;
- u_int64_t packets_v6_in_drop;
- u_int64_t packets_v6_out_pass;
- u_int64_t packets_v6_out_drop;
- u_int64_t states_entries;
- u_int64_t states_searches;
- u_int64_t states_inserts;
- u_int64_t states_removals;
- u_int64_t counters_match;
- u_int64_t counters_badoffset;
- u_int64_t counters_fragment;
- u_int64_t counters_short;
- u_int64_t counters_normalize;
- u_int64_t counters_memory;
- } ps_pf;
- } data;
- };
- __BEGIN_DECLS
- const char *type2str(const int);
- const int token2type(const int);
- int calculate_churnbuffer(struct sourcelist *);
- int ps2strn(struct packedstream *, char *, int, int);
- int snpack(char *, int, char*, int, ...);
- int strlentype(int);
- int sunpack(char *, struct packedstream *);
- struct mux *add_mux(struct muxlist *, char *);
- struct mux *find_mux(struct muxlist *, char *);
- struct mux * rename_mux(struct muxlist *, struct mux *, char *);
- struct source *add_source(struct sourcelist *, char *);
- struct source *find_source(struct sourcelist *, char *);
- struct source *find_source_ip(struct sourcelist *, u_int32_t);
- struct stream *add_mux_stream(struct mux *, int, char *);
- struct stream *add_source_stream(struct source *, int, char *);
- struct stream *find_mux_stream(struct mux *, int, char *);
- struct stream *find_source_stream(struct source *, int, char *);
- u_int32_t crc32(const void*, unsigned int);
- void free_muxlist(struct muxlist *);
- void free_sourcelist(struct sourcelist *);
- void free_streamlist(struct streamlist *);
- void init_crc32();
- __END_DECLS
- #endif
|