aboutsummaryrefslogtreecommitdiffstats
path: root/gg_map/gg_map.c
diff options
context:
space:
mode:
authorLaurent Ghigonis <laurent@p1sec.com>2013-07-06 02:27:56 +0200
committerLaurent Ghigonis <laurent@p1sec.com>2013-07-06 02:27:56 +0200
commit2b575ec093dcd84d8d5c816fe41dd5b7363228e6 (patch)
tree7f32e89871b99edb4e6556007d9515353a266b06 /gg_map/gg_map.c
parentgg_map: printf use %p for pointers (diff)
downloadglouglou-2b575ec093dcd84d8d5c816fe41dd5b7363228e6.tar.xz
glouglou-2b575ec093dcd84d8d5c816fe41dd5b7363228e6.zip
WIP traceroute integration, disabled by default
gg_map is not graphing correctly the route for now
Diffstat (limited to '')
-rw-r--r--gg_map/gg_map.c74
1 files changed, 74 insertions, 0 deletions
diff --git a/gg_map/gg_map.c b/gg_map/gg_map.c
index 221b915..511d791 100644
--- a/gg_map/gg_map.c
+++ b/gg_map/gg_map.c
@@ -73,6 +73,37 @@ _cb_ggnet_delgroup(struct ggnet *net, struct ggnet_nodegroup *group)
egraph_vertice_del(_egraph, vgroup);
}
+void
+_cb_ggnet_link(struct ggnet *net, struct ggnet_node *a, struct ggnet_node *b)
+{
+ Egraph_Edge *e;
+
+ e = egraph_edge_add(_egraph, ggnet_node_usrdata_get(a),
+ ggnet_node_usrdata_get(b), NULL);
+ if (!e) {
+ printf("gg_map: WARNING: _cb_link cannot create edge !\n");
+ return;
+ }
+ egraph_edge_type_set(_egraph, e, "edge_group");
+}
+
+void
+_cb_ggnet_unlink(struct ggnet *net, struct ggnet_node *a, struct ggnet_node *b)
+{
+ Egraph_Edge *e;
+ const char *type;
+
+ e = egraph_edge_find(_egraph, ggnet_node_usrdata_get(a), ggnet_node_usrdata_get(b));
+ if (!e) {
+ printf("gg_map: WARNING: _cb_unlink on non existing edge !\n");
+ return;
+ }
+ egraph_edge_type_get(_egraph, e, &type);
+ if (strncmp(type, "edge_group", EGRAPH_TYPE_MAXLEN))
+ return;
+ egraph_edge_del(_egraph, e);
+}
+
static Egraph_Vertice *
_node_to_vertice(struct ggnet_node *n)
{
@@ -230,6 +261,37 @@ _conn_name(u_int32_t addr, u_int8_t pktsize, u_char *fqdn) {
egraph_vertice_rename(_egraph, ggnet_node_usrdata_get(n), (char *)fqdn);
}
+static void
+_conn_trace(u_int32_t addr, u_int8_t hopcount, struct gg_packet *pkt) {
+ struct gg_packet_tracehop *h;
+ struct ggnet_node *n, *np;
+ struct in_addr ip;
+ Egraph_Vertice *v;
+ int i;
+
+ ip.s_addr = addr;
+ np = ggnet_node_find(_ggnet, &ip);
+ if (!np)
+ return;
+ for (i=0; i<hopcount; i++) {
+ h = &pkt->trace_hops[i];
+ ip.s_addr = h->addr;
+ n = ggnet_node_find(_ggnet, &ip);
+ if (!n) {
+ n = ggnet_node_add(_ggnet, &ip);
+ v = _node_to_vertice(n);
+ if (v)
+ egraph_vertice_type_set(_egraph, v,
+ "vertice_group");
+ else
+ printf("gg_map: ERROR: could not create trace vertice !\n");
+
+ }
+ ggnet_node_path_link(np, n);
+ np = n;
+ }
+}
+
static int
_cb_packet(struct gg_client *cli, struct gg_packet *pkt)
{
@@ -278,6 +340,16 @@ _cb_packet(struct gg_client *cli, struct gg_packet *pkt)
_conn_name(pkt->name_addr, pkt->name_len, pkt->name_fqdn);
break;
+
+ case PACKET_TRACE:
+ if (_loglevel >= 1) {
+ printf(" type PACKET_TRACE\n");
+ printf(" trace_addr %4x\n", pkt->trace_addr);
+ printf(" trace_hopcount %d\n", pkt->trace_hopcount);
+ }
+
+ _conn_trace(pkt->trace_addr, pkt->trace_hopcount, pkt);
+ break;
}
return 0;
@@ -482,6 +554,8 @@ elm_main(int argc, char **argv)
goto quit;
ggnet_set_grouping(_ggnet, GGNET_GROUPING_TRUE,
_cb_ggnet_addgroup, _cb_ggnet_delgroup);
+ ggnet_setcb_traceroute(_ggnet,
+ _cb_ggnet_link, _cb_ggnet_unlink);
_ev_base = event_base_new();
ggcli = gg_client_connect(_ev_base, gg_serv_ip, gg_serv_port,