hello reception: remove duplicate neighbors
authorIwan G. Flameling <iwanovich@gmail.com>
Fri, 3 Feb 2017 13:33:55 +0000 (14:33 +0100)
committerFerry Huberts <ferry.huberts@pelagic.nl>
Tue, 7 Feb 2017 12:37:58 +0000 (13:37 +0100)
See the explanations in the descriptions of commits 2f38613 and
5089a79.

To fix the issue more thoroughly we need to ensure that no duplicate
neighbours are sent or received because that confuses the receiver.
This is especially true when the HELLO messages are fragmented, and
even more so when the fragments have some delay between them since
that causes link instability.

This commit fixes that for the receiving side.

Signed-off-by: Iwan G. Flameling <iwanovich@gmail.com>
Signed-off-by: Ferry Huberts <ferry.huberts@pelagic.nl>
src/process_package.c

index bd6932b..7f4e229 100644 (file)
@@ -385,6 +385,29 @@ deserialize_hello(struct hello_message *hello, const void *ser)
     }
   }
 
+  {
+    struct hello_neighbor *neigh;
+    for (neigh = hello->neighbors; neigh; neigh = neigh->next) {
+      struct hello_neighbor *neigh_cull;
+      struct hello_neighbor *neigh_cull_prev;
+      struct hello_neighbor *neigh_cull_next;
+
+      for (neigh_cull_prev = neigh, neigh_cull = neigh->next;
+           neigh_cull;
+           neigh_cull = neigh_cull_next) {
+        neigh_cull_next = neigh_cull->next;
+
+        if (!ipequal(&neigh_cull->address, &neigh->address)) {
+          neigh_cull_prev = neigh_cull;
+          continue;
+        }
+
+        neigh_cull_prev->next = neigh_cull_next;
+        free(neigh_cull);
+      }
+    }
+  }
+
   return 0;
 }