1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
#ifndef _LIBGGNET_H_
#define _LIBGGNET_H_
#include <sys/types.h>
#include <netinet/in.h>
#include <event2/dns.h>
#include <event2/util.h>
#include <event2/event.h>
#if defined(__OpenBSD__)
#include <sys/queue.h>
#else
#include <bsd/sys/queue.h>
#endif
#include "libggnet_traceroute.h"
#define GGNET_DNSNAME_MAX 60
#define GGNET_CONN_FREEIDS_COUNT 65536 /* 2^16 as freeids are u_int16_t */
#define GGNET_MANAGE_CONNID_TRUE 1
#define GGNET_MANAGE_CONNID_FALSE 0
#define GGNET_GROUPING_TRUE 1
#define GGNET_GROUPING_FALSE 1
enum ggnet_grouptype {
GROUP_ADDRESS,
GROUP_WHOIS,
GROUP_DNS,
GROUP_ROUTE
};
struct ggnet_nodegroup {
LIST_ENTRY(ggnet_nodegroup) entry;
struct ggnet_nodegroup *parent;
enum ggnet_grouptype type;
struct in_addr addr;
char name[GGNET_DNSNAME_MAX];
int node_count;
int conn_count;
int child_groups_count;
void *usrdata;
};
struct ggnet_node {
LIST_ENTRY(ggnet_node) entry;
LIST_ENTRY(ggnet_node) entry_path;
struct ggnet *net;
struct in_addr addr;
int used_conn;
int used_traceroute;
LIST_HEAD(, ggnet_node) path_to; /* traceroute childs */
struct ggnet_node *path_parent; /* traceroute parent */
time_t lastseen;
struct ggnet_nodegroup *group; /* XXX for now only one group */
char fqdn[GGNET_DNSNAME_MAX];
struct ggnet_dns_req *dns_req;
struct ggnet_traceroute_req *traceroute_req;
void *usrdata;
};
enum ggnet_connstate {
CONNSTATE_ESTABLISHED,
CONNSTATE_TCPFIN,
CONNSTATE_TCPFIN2
};
struct ggnet_conn {
LIST_ENTRY(ggnet_conn) entry;
u_int id;
enum ggnet_connstate state;
struct ggnet_node *src;
u_int src_port;
struct ggnet_node *dst;
u_int dst_port;
u_int proto;
u_int size;
u_int size_response;
time_t lastseen;
void *usrdata;
};
struct ggnet {
LIST_HEAD(, ggnet_conn) conn_list;
LIST_HEAD(, ggnet_node) node_list;
LIST_HEAD(, ggnet_nodegroup) group_list;
int conn_count;
int node_count;
u_int16_t conn_freeids[GGNET_CONN_FREEIDS_COUNT];
int conn_freeids_ptr;
int manage_connid; /* XXX rename to active / passive */
time_t time;
int debug;
/* grouping */
int use_grouping;
void (*cb_addgroup)(struct ggnet *, struct ggnet_nodegroup *, struct ggnet_nodegroup *);
void (*cb_delgroup)(struct ggnet *, struct ggnet_nodegroup *);
/* dns */
int use_dns;
struct ggnet_dns *ggdns;
void (*cb_nodename)(struct ggnet *, struct ggnet_node *);
/* traceroute */
int use_traceroute;
struct ggnet_traceroute *ggtraceroute;
void (*cb_traceroute)(struct ggnet *, struct ggnet_traceroute_req *);
/* traceroute callbacks */
void (*cb_traceroute_link)(struct ggnet *,
struct ggnet_node *,
struct ggnet_node *);
void (*cb_traceroute_unlink)(struct ggnet *,
struct ggnet_node *,
struct ggnet_node *);
};
struct ggnet *ggnet_new(int);
void ggnet_set_grouping(struct ggnet *, int,
void (*cb_addgroup)(struct ggnet *,
struct ggnet_nodegroup *,
struct ggnet_nodegroup *),
void (*cb_delgroup)(struct ggnet *,
struct ggnet_nodegroup *));
void ggnet_setcb_traceroute(struct ggnet *,
void (*cb_link)(struct ggnet *,
struct ggnet_node *,
struct ggnet_node *),
void (*cb_unlink)(struct ggnet *,
struct ggnet_node *,
struct ggnet_node *));
void ggnet_set_dns(struct ggnet *net, int set,
struct event_base *ev_base,
void (*cb_nodename)(struct ggnet *,
struct ggnet_node *));
void ggnet_set_traceroute(struct ggnet *, int, char *,
struct event_base *,
void (*cb_traceroute)(struct ggnet *,
struct ggnet_traceroute_req *));
void ggnet_debug_set(struct ggnet *, int);
void ggnet_free(struct ggnet *);
struct ggnet_node *ggnet_node_add(struct ggnet *, struct in_addr *, int);
void ggnet_node_del(struct ggnet *, struct ggnet_node *);
struct ggnet_node *ggnet_node_find(struct ggnet *, struct in_addr *);
void *ggnet_node_usrdata_get(struct ggnet_node *);
void ggnet_node_usrdata_set(struct ggnet_node *, void *);
struct ggnet_nodegroup *ggnet_node_group_get(struct ggnet_node *);
int ggnet_node_path_link(struct ggnet_node *a,
struct ggnet_node *b);
struct ggnet_conn *ggnet_conn_add(struct ggnet *, struct in_addr *, int,
struct in_addr *, int, int, int, int);
void ggnet_conn_data(struct ggnet *, struct ggnet_conn *,
int, int);
void ggnet_conn_del(struct ggnet *, struct ggnet_conn *);
struct ggnet_conn *ggnet_conn_find(struct ggnet *, struct in_addr *, int,
struct in_addr *, int, int, int *);
struct ggnet_conn *ggnet_conn_find_by_id(struct ggnet *, int);
struct ggnet_conn *ggnet_conn_find_by_node(struct ggnet *,
struct ggnet_node *, struct ggnet_node *);
void *ggnet_conn_usrdata_get(struct ggnet_conn *);
void ggnet_conn_usrdata_set(struct ggnet_conn *, void *);
void *ggnet_conn_src_get(struct ggnet_conn *);
void *ggnet_conn_dst_get(struct ggnet_conn *);
void *ggnet_nodegroup_usrdata_get(struct ggnet_nodegroup *);
void ggnet_nodegroup_usrdata_set(struct ggnet_nodegroup *,
void *);
void ggnet_time_update(struct ggnet *, time_t);
#endif /* _LIBGGNET_H_ */
|