Don't apply ports-{max,keep} to protocols.
[darkstat] / hosts_db.h
1 /* darkstat 3
2 * copyright (c) 2001-2008 Emil Mikulic.
3 *
4 * hosts_db.h: database of hosts, ports, protocols.
5 *
6 * You may use, modify and redistribute this file under the terms of the
7 * GNU General Public License version 2. (see COPYING.GPL)
8 */
9
10 #include <sys/types.h>
11 #include <netinet/in.h>
12 #include "str.h"
13
14 struct hashtable;
15
16 struct host {
17 in_addr_t ip;
18 char *dns;
19 uint8_t mac_addr[6];
20 time_t last_seen;
21 struct hashtable *ports_tcp, *ports_udp, *ip_protos;
22 };
23
24 struct port_tcp {
25 uint16_t port;
26 uint64_t syn;
27 };
28
29 struct port_udp {
30 uint16_t port;
31 };
32
33 struct ip_proto {
34 uint8_t proto;
35 };
36
37 struct bucket {
38 struct bucket *next;
39 uint64_t in, out, total;
40 union {
41 struct host host;
42 struct port_tcp port_tcp;
43 struct port_udp port_udp;
44 struct ip_proto ip_proto;
45 } u;
46 };
47
48 enum sort_dir { IN, OUT, TOTAL };
49
50 extern int show_mac_addrs;
51
52 /*
53 * Table reduction - when the number of entries is about to exceed <max>, we
54 * reduce the table to the top <keep> entries.
55 */
56 extern unsigned int hosts_max, hosts_keep, ports_max, ports_keep;
57
58 void hosts_db_init(void);
59 void hosts_db_reduce(void);
60 void hosts_db_reset(void);
61 void hosts_db_free(void);
62 int hosts_db_import(const int fd);
63 int hosts_db_export(const int fd);
64
65 struct bucket *host_find(const in_addr_t ip); /* can return NULL */
66 struct bucket *host_get(const in_addr_t ip);
67 struct bucket *host_get_port_tcp(struct bucket *host, const uint16_t port);
68 struct bucket *host_get_port_udp(struct bucket *host, const uint16_t port);
69 struct bucket *host_get_ip_proto(struct bucket *host, const uint8_t proto);
70
71 /* Web pages. */
72 struct str *html_hosts(const char *uri, const char *query);
73
74 /* From hosts_sort */
75 void qsort_buckets(const struct bucket **a, size_t n,
76 size_t left, size_t right, const enum sort_dir d);
77
78 /* vim:set ts=3 sw=3 tw=78 expandtab: */