aboutsummaryrefslogtreecommitdiffstats
path: root/gg_map/gg_map.c
diff options
context:
space:
mode:
authorLaurent Ghigonis <laurent@p1sec.com>2012-12-13 17:22:59 +0100
committerLaurent Ghigonis <laurent@p1sec.com>2012-12-13 17:22:59 +0100
commitbfa2318a6b87eec9288e3a06621a5fbd00f5e4e9 (patch)
treec5e6fc60ca6fad7eb8d8c1e7d339a93d860c6732 /gg_map/gg_map.c
parentkeep track of group connection usage (diff)
downloadglouglou-bfa2318a6b87eec9288e3a06621a5fbd00f5e4e9.tar.xz
glouglou-bfa2318a6b87eec9288e3a06621a5fbd00f5e4e9.zip
attach and detach node groups to "inactive tree" or to current active node
Diffstat (limited to 'gg_map/gg_map.c')
-rw-r--r--gg_map/gg_map.c52
1 files changed, 45 insertions, 7 deletions
diff --git a/gg_map/gg_map.c b/gg_map/gg_map.c
index 2f971a3..2d710de 100644
--- a/gg_map/gg_map.c
+++ b/gg_map/gg_map.c
@@ -79,11 +79,40 @@ _node_to_vertice(struct ggnet_node *n)
}
static void
+_node_attach_parentgroup(struct ggnet_node *n)
+{
+ struct ggnet_nodegroup *g;
+ Egraph_Vertice *vg, *vparentg;
+
+ g = ggnet_node_group_get(n);
+ if (!g || !g->parent)
+ return;
+ vg = ggnet_nodegroup_usrdata_get(g);
+ vparentg = ggnet_nodegroup_usrdata_get(g->parent);
+ egraph_group_vertice_attach(_egraph, vg, vparentg);
+}
+
+static void
+_node_detach_parentgroup(struct ggnet_node *n)
+{
+ struct ggnet_nodegroup *g;
+ Egraph_Vertice *vg, *vparentg;
+
+ g = ggnet_node_group_get(n);
+ if (!g || !g->parent)
+ return;
+ vg = ggnet_nodegroup_usrdata_get(g);
+ vparentg = ggnet_nodegroup_usrdata_get(g->parent);
+ egraph_group_vertice_detach(_egraph, vg, vparentg);
+}
+
+static void
_conn_add(u_int id, u_int src, u_int dst, u_int proto, u_int8_t pktsize)
{
struct ggnet_conn *conn;
- Egraph_Vertice *a, *b;
Egraph_Edge *e;
+ struct ggnet_node *a, *b;
+ Egraph_Vertice *va, *vb;
struct in_addr srcaddr, dstaddr;
int size, response;
@@ -97,13 +126,19 @@ _conn_add(u_int id, u_int src, u_int dst, u_int proto, u_int8_t pktsize)
dstaddr.s_addr = dst;
conn = ggnet_conn_add(_ggnet, &srcaddr, -1, &dstaddr, -1, proto, size, id);
- a = _node_to_vertice(ggnet_conn_src_get(conn));
- b = _node_to_vertice(ggnet_conn_dst_get(conn));
- e = egraph_edge_find(_egraph, a, b);
+ a = ggnet_conn_src_get(conn);
+ b = ggnet_conn_dst_get(conn);
+ va = _node_to_vertice(a);
+ vb = _node_to_vertice(b);
+ e = egraph_edge_find(_egraph, va, vb);
if (_debug)
- printf("_conn_add: a %d b %d e %x id %d\n", a->id, b->id, e, id);
+ printf("_conn_add: a %d b %d e %x id %d\n", va->id, vb->id, e, id);
if (!e) {
- e = egraph_edge_add(_egraph, a, b, conn);
+ if (a->group && a->group->conn_count == 1)
+ _node_detach_parentgroup(a);
+ if (b->group && b->group->conn_count == 1)
+ _node_detach_parentgroup(b);
+ e = egraph_edge_add(_egraph, va, vb, conn);
if (_debug)
printf("_conn_add: egraph edge added %x\n", e);
}
@@ -132,7 +167,10 @@ _conn_del(int id) {
if (_debug)
printf("_conn_del: edge del %x\n", e); // XXX
egraph_edge_del(_egraph, e);
- //if (ggnet_node_is_connected(
+ if (a->group && a->group->conn_count == 0)
+ _node_attach_parentgroup(a);
+ if (b->group && b->group->conn_count == 0)
+ _node_attach_parentgroup(b);
} else {
if (_debug)
printf("_conn_del: not last one, edge %x *not* deleted\n", e);