update hashtable of link, when they change theri main_addr
authorMarkus Kittenberger <Markus.Kittenberger@gmx.at>
Tue, 2 Nov 2010 22:01:24 +0000 (23:01 +0100)
committerMarkus Kittenberger <Markus.Kittenberger@gmx.at>
Tue, 2 Nov 2010 22:01:24 +0000 (23:01 +0100)
src/link_set.c
src/neighbor_table.c
src/neighbor_table.h

index a4bf43d..b9cc509 100644 (file)
@@ -660,9 +660,10 @@ lookup_link_entry(const union olsr_ip_addr *remote, const union olsr_ip_addr *re
       if (NULL != remote_main && !ipequal(remote_main, &link->neighbor->neighbor_main_addr)) {
         /* Neighbor has changed it's main_addr, update */
         struct ipaddr_str oldbuf, newbuf;
+
         OLSR_PRINTF(1, "Neighbor changed main_ip, updating %s -> %s\n",
                     olsr_ip_to_string(&oldbuf, &link->neighbor->neighbor_main_addr), olsr_ip_to_string(&newbuf, remote_main));
-        link->neighbor->neighbor_main_addr = *remote_main;
+        olsr_update_neighbor_main_addr(link->neighbor, remote_main);
       }
       return link;
     }
index 38af0dc..c223201 100644 (file)
@@ -148,6 +148,43 @@ olsr_lookup_my_neighbors(const struct neighbor_entry *neighbor, const union olsr
 }
 
 /**
+ * Update a neighbours main_addr inlcuding hash
+*/
+
+int 
+olsr_update_neighbor_main_addr(struct neighbor_entry *entry, const union olsr_ip_addr *new_main_addr)
+{
+  /*uint32_t hash = olsr_ip_hashing(&neigh->neighbor_main_addr);
+  
+  struct neighbor_entry *entry;
+
+  entry = neighbortable[hash].next;
+
+  while (entry != &neighbortable[hash]) {
+    if (ipequal(&entry->neighbor_main_addr, &neigh->neighbor_main_addr))
+      break;
+
+    entry = entry->next;
+  }
+
+  if (entry == &neighbortable[hash])
+    return 0;
+
+  if (entry == neigh) printf("bullshit\n");
+  else printf("updating neighbor has!\n");*/
+
+  //remove from old pos
+  DEQUEUE_ELEM(entry);
+
+  //update entry
+  entry->neighbor_main_addr = *new_main_addr;
+
+  //insert it again
+  QUEUE_ELEM(neighbortable[olsr_ip_hashing(new_main_addr)], entry);
+
+}
+
+/**
  *Delete a neighbr table entry.
  *
  *Remember: Deleting a neighbor entry results
@@ -296,6 +333,27 @@ olsr_lookup_neighbor_table_alias(const union olsr_ip_addr *dst)
 
 }
 
+//check if all neighbour entries are findable in neighbour table
+bool
+olsr_lookup_neighbor_table_check(void)
+{
+  struct ipaddr_str buf1;
+  struct neighbor_entry *entry;
+  printf("\n checking neighbour table: ");
+  /* Neighbors */
+  OLSR_FOR_ALL_NBR_ENTRIES(entry) {
+    printf("%s, ",olsr_ip_to_string(&buf1, &entry->neighbor_main_addr));
+    if (olsr_lookup_neighbor_table_alias(&entry->neighbor_main_addr)==NULL) {
+      struct neighbor_2_list_entry *two_hop_list, *two_hop_to_delete;
+      printf("-> entry has wrong hash!");
+      return true;
+    }
+  }
+  OLSR_FOR_ALL_NBR_ENTRIES_END(neigh);
+  return false;
+}
+
+
 int
 update_neighbor_status(struct neighbor_entry *entry, int lnk)
 {
index 9a2a42c..5602869 100644 (file)
@@ -97,6 +97,8 @@ struct neighbor_entry *olsr_lookup_neighbor_table(const union olsr_ip_addr *);
 
 struct neighbor_entry *olsr_lookup_neighbor_table_alias(const union olsr_ip_addr *);
 
+bool olsr_lookup_neighbor_table_check(void);
+
 void olsr_time_out_two_hop_neighbors(struct neighbor_entry *);
 
 void olsr_time_out_neighborhood_tables(void);
@@ -104,6 +106,8 @@ void olsr_expire_nbr2_list(void *);
 
 void olsr_print_neighbor_table(void);
 
+int olsr_update_neighbor_main_addr(struct neighbor_entry *, const union olsr_ip_addr *);
+
 int update_neighbor_status(struct neighbor_entry *, int);
 
 #endif