add OLSR_FOR_ALL_NBR_ENTRIES macro, misc. code-style cleanups
authorHannes Gredler <hannes@gredler.at>
Sat, 8 Mar 2008 23:29:31 +0000 (00:29 +0100)
committerHannes Gredler <hannes@gredler.at>
Sat, 8 Mar 2008 23:29:31 +0000 (00:29 +0100)
lib/dot_draw/src/olsrd_dot_draw.c
lib/httpinfo/src/olsrd_httpinfo.c
lib/pgraph/src/olsrd_pgraph.c
lib/txtinfo/src/olsrd_txtinfo.c
src/lq_mpr.c
src/lq_packet.c
src/lq_route.c
src/mpr.c
src/neighbor_table.h
src/packet.c

index 26c9866..16cb374 100644 (file)
@@ -280,25 +280,21 @@ pcf_event(int changes_neighborhood,
          int changes_topology,
          int changes_hna)
 {
-  int res = 0;
-  if(changes_neighborhood || changes_topology || changes_hna) {
-    struct neighbor_entry *neighbor_table_tmp;
-    struct tc_entry *tc;
-    struct tc_edge_entry *tc_edge;
-    struct ip_prefix_list *hna;
-    int idx;
+  struct neighbor_entry *neighbor_table_tmp;
+  struct tc_entry *tc;
+  struct tc_edge_entry *tc_edge;
+  struct ip_prefix_list *hna;
+  int idx, res = 0;
+
+  if (changes_neighborhood || changes_topology || changes_hna) {
     
     /* Print tables to IPC socket */
     ipc_send_str("digraph topology\n{\n");
 
     /* Neighbors */
-    for (idx = 0; idx < HASHSIZE; idx++) {       
-      for(neighbor_table_tmp = neighbortable[idx].next;
-          neighbor_table_tmp != &neighbortable[idx];
-          neighbor_table_tmp = neighbor_table_tmp->next){
-        ipc_print_neigh_link( neighbor_table_tmp );
-      }
-    }
+    OLSR_FOR_ALL_NBR_ENTRIES(neighbor_table_tmp) {
+      ipc_print_neigh_link( neighbor_table_tmp );
+    } OLSR_FOR_ALL_NBR_ENTRIES_END(neighbor_table_tmp);
 
     /* Topology */  
     OLSR_FOR_ALL_TC_ENTRIES(tc) {
@@ -395,3 +391,9 @@ ipc_send_fmt(const char *format, ...)
     ipc_send(buf, len);
   }
 }
+
+/*
+ * Local Variables:
+ * c-basic-offset: 2
+ * End:
+ */
index 6e03168..96329f2 100644 (file)
@@ -966,7 +966,7 @@ static int build_neigh_body(char *buf, olsr_u32_t bufsize)
 {
   struct neighbor_entry *neigh;
   struct link_entry *link = NULL;
-  int size = 0, idx;
+  int size = 0;
   const char *colspan = resolve_ip_addresses ? " colspan=\"2\"" : "";
 
   size += section_title(&buf[size], bufsize-size, "Links");
@@ -1007,33 +1007,36 @@ static int build_neigh_body(char *buf, olsr_u32_t bufsize)
   size += snprintf(&buf[size], bufsize-size,
                    "<tr><th align=\"center\"%s>IP Address</th><th align=\"center\">SYM</th><th align=\"center\">MPR</th><th align=\"center\">MPRS</th><th align=\"center\">Willingness</th><th>2 Hop Neighbors</th></tr>\n", colspan);
   /* Neighbors */
-  for (idx = 0; idx < HASHSIZE; idx++) {
-    for (neigh = neighbortable[idx].next; neigh != &neighbortable[idx]; neigh = neigh->next) {
-      struct neighbor_2_list_entry *list_2;
-      int thop_cnt;
-      size += snprintf(&buf[size], bufsize-size, "<tr>");
-      size += build_ipaddr_with_link(&buf[size], bufsize, &neigh->neighbor_main_addr, -1);
-      size += snprintf(&buf[size], bufsize-size,
-                       "<td align=\"center\">%s</td>"
-                       "<td align=\"center\">%s</td>"
-                       "<td align=\"center\">%s</td>"
-                       "<td align=\"center\">%d</td>",
-                       (neigh->status == SYM) ? "YES" : "NO",
-                       neigh->is_mpr ? "YES" : "NO",
-                       olsr_lookup_mprs_set(&neigh->neighbor_main_addr) ? "YES" : "NO",
-                       neigh->willingness);
+  OLSR_FOR_ALL_NBR_ENTRIES(neigh) {
 
-      size += snprintf(&buf[size], bufsize-size, "<td><select>\n"
-                       "<option>IP ADDRESS</option>\n");
-
-
-      for (list_2 = neigh->neighbor_2_list.next, thop_cnt = 0; list_2 != &neigh->neighbor_2_list; list_2 = list_2->next, thop_cnt++) {
-        struct ipaddr_str strbuf;
-        size += snprintf(&buf[size], bufsize-size, "<option>%s</option>\n", olsr_ip_to_string(&strbuf, &list_2->neighbor_2->neighbor_2_addr));
-      }
-      size += snprintf(&buf[size], bufsize-size, "</select> (%d)</td></tr>\n", thop_cnt);
+    struct neighbor_2_list_entry *list_2;
+    int thop_cnt;
+    size += snprintf(&buf[size], bufsize-size, "<tr>");
+    size += build_ipaddr_with_link(&buf[size], bufsize, &neigh->neighbor_main_addr, -1);
+    size += snprintf(&buf[size], bufsize-size,
+                     "<td align=\"center\">%s</td>"
+                     "<td align=\"center\">%s</td>"
+                     "<td align=\"center\">%s</td>"
+                     "<td align=\"center\">%d</td>",
+                     (neigh->status == SYM) ? "YES" : "NO",
+                     neigh->is_mpr ? "YES" : "NO",
+                     olsr_lookup_mprs_set(&neigh->neighbor_main_addr) ? "YES" : "NO",
+                     neigh->willingness);
+
+    size += snprintf(&buf[size], bufsize-size, "<td><select>\n"
+                     "<option>IP ADDRESS</option>\n");
+
+
+    for (list_2 = neigh->neighbor_2_list.next, thop_cnt = 0;
+         list_2 != &neigh->neighbor_2_list;
+         list_2 = list_2->next, thop_cnt++) {
+      struct ipaddr_str strbuf;
+      size += snprintf(&buf[size], bufsize-size, "<option>%s</option>\n",
+                       olsr_ip_to_string(&strbuf, &list_2->neighbor_2->neighbor_2_addr));
     }
-  }
+    size += snprintf(&buf[size], bufsize-size, "</select> (%d)</td></tr>\n", thop_cnt);
+  } OLSR_FOR_ALL_NBR_ENTRIES_END(neigh);
+
   size += snprintf(&buf[size], bufsize-size, "</table>\n");
   return size;
 }
@@ -1274,3 +1277,9 @@ static ssize_t writen(int fd, const void *buf, size_t count)
     }
     return count;
 }
+
+/*
+ * Local Variables:
+ * c-basic-offset: 2
+ * End:
+ */
index dde246c..64e9f05 100644 (file)
@@ -313,42 +313,32 @@ static int pcf_event(int changes_neighborhood,
                      int changes_hna __attribute__((unused)))
 {
   int res;
-  olsr_u8_t index;
   struct neighbor_entry *neighbor_table_tmp;
   struct tc_entry *tc;
   struct tc_edge_entry *tc_edge;
 
   res = 0;
 
-  //if(changes_neighborhood || changes_topology || changes_hna)
-  if(changes_neighborhood || changes_topology)
-    {
-      /* Print tables to IPC socket */
+  if (changes_neighborhood || changes_topology) {
+    /* Print tables to IPC socket */
 
-      //ipc_send("start ", strlen("start "));
+    //ipc_send("start ", strlen("start "));
 
-      /* Neighbors */
-      for(index=0;index<HASHSIZE;index++)
-       {
-         
-         for(neighbor_table_tmp = neighbortable[index].next;
-             neighbor_table_tmp != &neighbortable[index];
-             neighbor_table_tmp = neighbor_table_tmp->next)
-           {
-             ipc_print_neigh_link( neighbor_table_tmp );
-           }
-       }
+    /* Neighbors */
+    OLSR_FOR_ALL_NBR_ENTRIES(neighbor_table_tmp) {
+      ipc_print_neigh_link( neighbor_table_tmp );
+    } OLSR_FOR_ALL_NBR_ENTRIES_END(neighbor_table_tmp);
 
-      /* Topology */  
-      OLSR_FOR_ALL_TC_ENTRIES(tc) {
-          OLSR_FOR_ALL_TC_EDGE_ENTRIES(tc, tc_edge) {
-              ipc_print_tc_link(tc, tc_edge);
-          } OLSR_FOR_ALL_TC_EDGE_ENTRIES_END(tc, tc_edge);
-      } OLSR_FOR_ALL_TC_ENTRIES_END(tc);
+    /* Topology */  
+    OLSR_FOR_ALL_TC_ENTRIES(tc) {
+      OLSR_FOR_ALL_TC_EDGE_ENTRIES(tc, tc_edge) {
+        ipc_print_tc_link(tc, tc_edge);
+      } OLSR_FOR_ALL_TC_EDGE_ENTRIES_END(tc, tc_edge);
+    } OLSR_FOR_ALL_TC_ENTRIES_END(tc);
 
-      ipc_send(" end ", strlen(" end "));
+    ipc_send(" end ", strlen(" end "));
 
-      /* HNA entries */
+    /* HNA entries */
 //      for(index=0;index<HASHSIZE;index++)
 //     {
 //       tmp_hna = hna_set[index].next;
@@ -372,12 +362,12 @@ static int pcf_event(int changes_neighborhood,
 
 //      ipc_send("}\n\n", strlen("}\n\n"));
 
-      res = 1;
-    }
-
+    res = 1;
+  }
 
-  if(ipc_socket == -1)
+  if (ipc_socket == -1) {
     plugin_ipc_init();
+  }
 
   return res;
 }
@@ -415,3 +405,9 @@ static int ipc_send(const char *data, int size)
 
   return 1;
 }
+
+/*
+ * Local Variables:
+ * c-basic-offset: 2
+ * End:
+ */
index 94d7855..bc495e2 100644 (file)
@@ -318,33 +318,29 @@ static void ipc_print_neigh(void)
     struct ipaddr_str buf1;
     struct neighbor_entry *neigh;
     struct neighbor_2_list_entry *list_2;
-    int index, thop_cnt;
+    int thop_cnt;
 
     ipc_sendf("\nTable: Neighbors\nIP address\tSYM\tMPR\tMPRS\tWillingness\t2 Hop Neighbors\n");
 
     /* Neighbors */
-    for(index = 0; index < HASHSIZE; index++) {
-        for(neigh = neighbortable[index].next;
-            neigh != &neighbortable[index];
-            neigh = neigh->next) {
-            ipc_sendf("%s\t%s\t%s\t%s\t%d\t", 
-                      olsr_ip_to_string(&buf1, &neigh->neighbor_main_addr),
-                      (neigh->status == SYM) ? "YES" : "NO",
-                      neigh->is_mpr ? "YES" : "NO",
-                      olsr_lookup_mprs_set(&neigh->neighbor_main_addr) ? "YES" : "NO",
-                      neigh->willingness);
-            thop_cnt = 0;
-
-            for(list_2 = neigh->neighbor_2_list.next;
-                list_2 != &neigh->neighbor_2_list;
-                list_2 = list_2->next)
-                {
-                    //size += sprintf(&buf[size], "<option>%s</option>\n", olsr_ip_to_string(&buf1, &list_2->neighbor_2->neighbor_2_addr));
-                    thop_cnt ++;
-                }
-            ipc_sendf("%d\n", thop_cnt);
-       }
-    }
+    OLSR_FOR_ALL_NBR_ENTRIES(neigh) {
+        ipc_sendf("%s\t%s\t%s\t%s\t%d\t", 
+                  olsr_ip_to_string(&buf1, &neigh->neighbor_main_addr),
+                  (neigh->status == SYM) ? "YES" : "NO",
+                  neigh->is_mpr ? "YES" : "NO",
+                  olsr_lookup_mprs_set(&neigh->neighbor_main_addr) ? "YES" : "NO",
+                  neigh->willingness);
+        thop_cnt = 0;
+
+        for(list_2 = neigh->neighbor_2_list.next;
+            list_2 != &neigh->neighbor_2_list;
+            list_2 = list_2->next)
+        {
+            //size += sprintf(&buf[size], "<option>%s</option>\n", olsr_ip_to_string(&buf1, &list_2->neighbor_2->neighbor_2_addr));
+            thop_cnt ++;
+        }
+        ipc_sendf("%d\n", thop_cnt);
+    } OLSR_FOR_ALL_NBR_ENTRIES_END(neigh);
     ipc_sendf("\n");
 }
 
index ce30d4f..b4de652 100644 (file)
@@ -58,33 +58,30 @@ void olsr_calculate_lq_mpr(void)
 #endif
   olsr_bool mpr_changes = OLSR_FALSE;
 
-  for(i = 0; i < HASHSIZE; i++)
-    {
-      for (neigh = neighbortable[i].next;
-           neigh != &neighbortable[i];
-           neigh = neigh->next)
-        { 
-          // memorize previous MPR status
+  OLSR_FOR_ALL_NBR_ENTRIES(neigh) {
 
-          neigh->was_mpr = neigh->is_mpr;
+    /* Memorize previous MPR status. */
 
-          // clear current MPR status
+    neigh->was_mpr = neigh->is_mpr;
 
-          neigh->is_mpr = OLSR_FALSE;
+    /* Clear current MPR status. */
 
-          // in this pass we are only interested in WILL_ALWAYS neighbours
+    neigh->is_mpr = OLSR_FALSE;
 
-          if(neigh->status == NOT_SYM ||
-             neigh->willingness != WILL_ALWAYS)
-            continue;
+    /* In this pass we are only interested in WILL_ALWAYS neighbours */
 
-          neigh->is_mpr = OLSR_TRUE;
+    if (neigh->status == NOT_SYM || neigh->willingness != WILL_ALWAYS) {
+      continue;
+    }
 
-          if (neigh->is_mpr != neigh->was_mpr)
-            mpr_changes = OLSR_TRUE;
-        }
+    neigh->is_mpr = OLSR_TRUE;
+
+    if (neigh->is_mpr != neigh->was_mpr) {
+      mpr_changes = OLSR_TRUE;
     }
 
+  } OLSR_FOR_ALL_NBR_ENTRIES_END(neigh);
+
   for(i = 0; i < HASHSIZE; i++)
     {
       // loop through all 2-hop neighbours
@@ -198,3 +195,9 @@ void olsr_calculate_lq_mpr(void)
   if (mpr_changes && olsr_cnf->tc_redundancy > 0)
     signal_link_changes(OLSR_TRUE);
 }
+
+/*
+ * Local Variables:
+ * c-basic-offset: 2
+ * End:
+ */
index 2e84917..148b99d 100644 (file)
@@ -152,7 +152,9 @@ destroy_lq_hello(struct lq_hello_message *lq_hello)
 static void
 create_lq_tc(struct lq_tc_message *lq_tc, struct interface *outif)
 {
-  int i;
+  struct link_entry *lnk;
+  struct neighbor_entry *walker;
+  struct tc_mpr_addr *neigh;
   static int ttl_list[] = { 2, 8, 2, 16, 2, 8, 2, MAX_TTL};
 
   // remember that we have generated an LQ TC message; this is
@@ -191,63 +193,67 @@ create_lq_tc(struct lq_tc_message *lq_tc, struct interface *outif)
 
   lq_tc->neigh = NULL;
  
-  // loop through all neighbours
-  
-  for(i = 0; i < HASHSIZE; i++)
-    {
-      struct neighbor_entry *walker;
-      struct tc_mpr_addr    *neigh;
-      for(walker = neighbortable[i].next; walker != &neighbortable[i];
-          walker = walker->next)
-        {
-          struct link_entry *lnk;
-          // only consider symmetric neighbours
-
-          if(walker->status != SYM)
-            continue;
-
-          // TC redundancy == 1: only consider MPRs and MPR selectors
+  OLSR_FOR_ALL_NBR_ENTRIES(walker) {
+
+    /*
+     * TC redundancy 2
+     *
+     * Only consider symmetric neighbours.
+     */
+    if (walker->status != SYM) {
+      continue;
+    }
 
-          if (olsr_cnf->tc_redundancy == 1 && !walker->is_mpr &&
-              olsr_lookup_mprs_set(&walker->neighbor_main_addr) == NULL)
-            continue;
+    /*
+     * TC redundancy 1
+     *
+     * Only consider MPRs and MPR selectors
+     */
+    if (olsr_cnf->tc_redundancy == 1 && !walker->is_mpr &&
+        !olsr_lookup_mprs_set(&walker->neighbor_main_addr)) {
+      continue;
+    }
 
-          // TC redundancy == 0: only consider MPR selectors
-          if (olsr_cnf->tc_redundancy == 0 &&
-              olsr_lookup_mprs_set(&walker->neighbor_main_addr) == NULL)
-            continue;
+    /*
+     * TC redundancy 0
+     *
+     * Only consider MPR selectors
+     */
+    if (olsr_cnf->tc_redundancy == 0 &&
+        !olsr_lookup_mprs_set(&walker->neighbor_main_addr)) {
+      continue;
+    }
 
-          // allocate a neighbour entry          
-          neigh = olsr_malloc(sizeof (struct tc_mpr_addr), "Build LQ_TC");
+    /* Allocate a neighbour entry. */
+    neigh = olsr_malloc(sizeof (struct tc_mpr_addr), "Build LQ_TC");
 
-          // set the entry's main address
+    /* Set the entry's main address. */
+    neigh->address = walker->neighbor_main_addr;
 
-          neigh->address = walker->neighbor_main_addr;
+    /* Set the entry's link quality */
+    lnk = get_best_link_to_neighbor(&neigh->address);
 
-          // set the entry's link quality
-          lnk = get_best_link_to_neighbor(&neigh->address);
+    if (lnk) {
+      neigh->link_quality = lnk->loss_link_quality;
+      neigh->neigh_link_quality = lnk->neigh_link_quality;
+    }
 
-          if (lnk) {
-            neigh->link_quality = lnk->loss_link_quality;
-            neigh->neigh_link_quality = lnk->neigh_link_quality;
-          }
-          else {
-            OLSR_PRINTF(0, "Error: link_qualtiy undefined");
+    else {
+      OLSR_PRINTF(0, "Error: link_qualtiy undefined");
 #ifdef USE_FPM
-            neigh->link_quality = itofpm(0);
-            neigh->neigh_link_quality = itofpm(0);
+      neigh->link_quality = itofpm(0);
+      neigh->neigh_link_quality = itofpm(0);
 #else
-            neigh->link_quality = 0.0;
-            neigh->neigh_link_quality = 0.0;
+      neigh->link_quality = 0.0;
+      neigh->neigh_link_quality = 0.0;
 #endif
-          }          
+    }          
 
-          // queue the neighbour entry
+    /* Queue the neighbour entry. */
+    neigh->next = lq_tc->neigh;
+    lq_tc->neigh = neigh;
 
-          neigh->next = lq_tc->neigh;
-          lq_tc->neigh = neigh;
-        }
-    }
+  } OLSR_FOR_ALL_NBR_ENTRIES_END(walker);
 }
 
 static void
index 31243d3..b30d252 100644 (file)
@@ -344,12 +344,12 @@ olsr_calculate_routing_table (void *context __attribute__((unused)))
   struct avl_tree cand_tree;
   struct avl_node *rtp_tree_node;
   struct list_node path_list; /* head of the path_list */
-  int i, path_count = 0;
   struct tc_entry *tc;
   struct rt_path *rtp;
   struct tc_edge_entry *tc_edge;
   struct neighbor_entry *neigh;
   struct link_entry *link;
+  int path_count = 0;
 
   /* We are done if our backoff timer is running */
   if (!spf_backoff_timer) {
@@ -390,56 +390,54 @@ olsr_calculate_routing_table (void *context __attribute__((unused)))
   /*
    * add edges to and from our neighbours.
    */
-  for (i = 0; i < HASHSIZE; i++)
-    for (neigh = neighbortable[i].next; neigh != &neighbortable[i];
-         neigh = neigh->next) {
-
-      if (neigh->status == SYM) {
-
-        tc_edge = olsr_lookup_tc_edge(tc_myself, &neigh->neighbor_main_addr);
-        link = get_best_link_to_neighbor(&neigh->neighbor_main_addr);
-       if (!link) {
-
-          /*
-           * If there is no best link to this neighbor
-           * and we had an edge before then flush the edge.
-           */
-          if (tc_edge) {
-            olsr_delete_tc_edge_entry(tc_edge);
-          }
-         continue;
-        }
+  OLSR_FOR_ALL_NBR_ENTRIES(neigh) {
 
-        /* find the interface for the link */
-        if (link->if_name) {
-          link->inter = if_ifwithname(link->if_name);
-        } else {
-          link->inter = if_ifwithaddr(&link->local_iface_addr);
-        }
+    if (neigh->status == SYM) {
+
+      tc_edge = olsr_lookup_tc_edge(tc_myself, &neigh->neighbor_main_addr);
+      link = get_best_link_to_neighbor(&neigh->neighbor_main_addr);
+      if (!link) {
 
         /*
-         * Set the next-hops of our neighbors. 
+         * If there is no best link to this neighbor
+         * and we had an edge before then flush the edge.
          */
-        if (!tc_edge) {
-          tc_edge = olsr_add_tc_edge_entry(tc_myself, &neigh->neighbor_main_addr,
-                                           0, link->vtime,
-                                           link->loss_link_quality2,
-                                           link->neigh_link_quality2);
-        } else {
-
-          /*
-           * Update LQ and timers, such that the edge does not get deleted.
-           */
-          tc_edge->link_quality = link->loss_link_quality2;
-          tc_edge->inverse_link_quality = link->neigh_link_quality2;
-          olsr_set_tc_edge_timer(tc_edge, link->vtime*1000);
-          olsr_calc_tc_edge_entry_etx(tc_edge);
-        }
-        if (tc_edge->edge_inv) {
-          tc_edge->edge_inv->tc->next_hop = link;
+        if (tc_edge) {
+          olsr_delete_tc_edge_entry(tc_edge);
         }
+        continue;
+      }
+
+      /* find the interface for the link */
+      if (link->if_name) {
+        link->inter = if_ifwithname(link->if_name);
+      } else {
+        link->inter = if_ifwithaddr(&link->local_iface_addr);
+      }
+
+      /*
+       * Set the next-hops of our neighbors. 
+       */
+      if (!tc_edge) {
+        tc_edge = olsr_add_tc_edge_entry(tc_myself, &neigh->neighbor_main_addr,
+                                         0, link->vtime,
+                                         link->loss_link_quality2,
+                                         link->neigh_link_quality2);
+      } else {
+
+        /*
+         * Update LQ and timers, such that the edge does not get deleted.
+         */
+        tc_edge->link_quality = link->loss_link_quality2;
+        tc_edge->inverse_link_quality = link->neigh_link_quality2;
+        olsr_set_tc_edge_timer(tc_edge, link->vtime*1000);
+        olsr_calc_tc_edge_entry_etx(tc_edge);
+      }
+      if (tc_edge->edge_inv) {
+        tc_edge->edge_inv->tc->next_hop = link;
       }
     }
+  } OLSR_FOR_ALL_NBR_ENTRIES_END(neigh);
 
 #ifdef SPF_PROFILING
   gettimeofday(&t2, NULL);
index 5d2c834..87a5440 100644 (file)
--- a/src/mpr.c
+++ b/src/mpr.c
@@ -241,36 +241,31 @@ static struct neighbor_entry *
 olsr_find_maximum_covered(int willingness)
 {
   olsr_u16_t                  maximum;
-  olsr_u8_t                   index;
   struct neighbor_entry       *a_neighbor;
-  struct neighbor_entry       *mpr_candidate=NULL;
+  struct neighbor_entry       *mpr_candidate = NULL;
    
   maximum = 0;
-  
-  for (index=0;index<HASHSIZE;index++)
-    {
-      for(a_neighbor = neighbortable[index].next;
-         a_neighbor != &neighbortable[index];
-         a_neighbor = a_neighbor->next)
-       {
-         /*      
-         printf("[%s] nocov: %d mpr: %d will: %d max: %d\n\n", 
-                olsr_ip_to_string(&buf, &a_neighbor->neighbor_main_addr), 
-                a_neighbor->neighbor_2_nocov,
-                a_neighbor->is_mpr,
-                a_neighbor->willingness,
-                maximum);
-         */
-         if((!a_neighbor->is_mpr) &&
-            (a_neighbor->willingness == willingness) && 
-            (maximum < a_neighbor->neighbor_2_nocov))
-           {
-             //printf("ADDING\n");
-             maximum = a_neighbor->neighbor_2_nocov;
-             mpr_candidate = a_neighbor;
-           }
-       }
-    }
+
+  OLSR_FOR_ALL_NBR_ENTRIES(a_neighbor) {
+
+#if 0
+      printf("[%s] nocov: %d mpr: %d will: %d max: %d\n\n", 
+             olsr_ip_to_string(&buf, &a_neighbor->neighbor_main_addr), 
+             a_neighbor->neighbor_2_nocov,
+             a_neighbor->is_mpr,
+             a_neighbor->willingness,
+             maximum);
+#endif
+
+      if ((!a_neighbor->is_mpr) &&
+          (a_neighbor->willingness == willingness) && 
+          (maximum < a_neighbor->neighbor_2_nocov)) {
+
+          maximum = a_neighbor->neighbor_2_nocov;
+          mpr_candidate = a_neighbor;
+      }
+  } OLSR_FOR_ALL_NBR_ENTRIES_END(a_neighbor);
+
   return mpr_candidate;
 }
 
@@ -281,32 +276,25 @@ olsr_find_maximum_covered(int willingness)
 static void
 olsr_clear_mprs(void)
 {
-  olsr_u32_t index;
-  
-  for (index=0;index<HASHSIZE;index++)
-    {
-      struct neighbor_entry   *a_neighbor;
-      for(a_neighbor = neighbortable[index].next;
-         a_neighbor != &neighbortable[index];
-         a_neighbor = a_neighbor->next)
-       {
-          struct neighbor_2_list_entry *two_hop_list;
-         /* Clear MPR selection */
-         if(a_neighbor->is_mpr)
-           {
-             a_neighbor->was_mpr = OLSR_TRUE;
-             a_neighbor->is_mpr = OLSR_FALSE;
-           }
+  struct neighbor_entry *a_neighbor;
+  struct neighbor_2_list_entry *two_hop_list;
 
-         /* Clear two hop neighbors coverage count */
-         for(two_hop_list = a_neighbor->neighbor_2_list.next;
-             two_hop_list != &a_neighbor->neighbor_2_list;
-             two_hop_list = two_hop_list->next)
-           {
-             two_hop_list->neighbor_2->mpr_covered_count = 0;
-           }
-       }
+  OLSR_FOR_ALL_NBR_ENTRIES(a_neighbor) {
+
+    /* Clear MPR selection. */
+    if (a_neighbor->is_mpr) {
+      a_neighbor->was_mpr = OLSR_TRUE;
+      a_neighbor->is_mpr = OLSR_FALSE;
+    }
+
+    /* Clear two hop neighbors coverage count/ */
+    for (two_hop_list = a_neighbor->neighbor_2_list.next;
+         two_hop_list != &a_neighbor->neighbor_2_list;
+         two_hop_list = two_hop_list->next) {
+      two_hop_list->neighbor_2->mpr_covered_count = 0;
     }
+
+  } OLSR_FOR_ALL_NBR_ENTRIES_END(a_neighbor);
 }
 
 
@@ -318,26 +306,21 @@ olsr_clear_mprs(void)
 static int
 olsr_check_mpr_changes(void)
 {
-  olsr_u32_t index;
+  struct neighbor_entry *a_neighbor;
   int retval;
 
   retval = 0;
   
-  for (index=0;index<HASHSIZE;index++)
-    {
-      struct neighbor_entry *a_neighbor;
-      for(a_neighbor = neighbortable[index].next;
-         a_neighbor != &neighbortable[index];
-         a_neighbor = a_neighbor->next)
-       {
-         if(a_neighbor->was_mpr)
-           {
-             a_neighbor->was_mpr = OLSR_FALSE;
-             if(!a_neighbor->is_mpr)
-               retval = 1;
-           }
-       }
+  OLSR_FOR_ALL_NBR_ENTRIES(a_neighbor) {
+
+    if (a_neighbor->was_mpr) {
+      a_neighbor->was_mpr = OLSR_FALSE;
+
+      if (!a_neighbor->is_mpr) {
+        retval = 1;
+      }
     }
+  } OLSR_FOR_ALL_NBR_ENTRIES_END(a_neighbor);
 
   return retval;
 }
@@ -373,49 +356,42 @@ olsr_clear_two_hop_processed(void)
 static olsr_u16_t
 olsr_calculate_two_hop_neighbors(void)
 {
-  olsr_u8_t                    index;
-  olsr_u16_t                   sum = 0;
+  struct neighbor_entry *a_neighbor, *dup_neighbor;
+  struct neighbor_2_list_entry *twohop_neighbors;
+  olsr_u16_t count = 0;
+  olsr_u16_t n_count = 0;
+  olsr_u16_t sum = 0;
   
   /* Clear 2 hop neighs */
   olsr_clear_two_hop_processed();
 
-  for(index=0;index<HASHSIZE;index++)
-    {
-      struct neighbor_entry *a_neighbor;
-      for(a_neighbor = neighbortable[index].next; a_neighbor != &neighbortable[index]; a_neighbor = a_neighbor->next)
-       { 
-          struct neighbor_2_list_entry *twohop_neighbors;
-          olsr_u16_t                   count = 0;
-          olsr_u16_t                   n_count = 0;
-          if(a_neighbor->status == NOT_SYM)
-           {       
-             a_neighbor->neighbor_2_nocov = count;
-             continue;
-           }
+  OLSR_FOR_ALL_NBR_ENTRIES(a_neighbor) {
 
-         for(twohop_neighbors = a_neighbor->neighbor_2_list.next;
-             twohop_neighbors != &a_neighbor->neighbor_2_list;
-             twohop_neighbors = twohop_neighbors->next)
-           {
-             //printf("\tChecking %s....", olsr_ip_to_string(&buf, &twohop_neighbors->neighbor_2->neighbor_2_addr));
-              struct neighbor_entry *dup_neighbor = olsr_lookup_neighbor_table(&twohop_neighbors->neighbor_2->neighbor_2_addr);
+    if (a_neighbor->status == NOT_SYM) {           
+      a_neighbor->neighbor_2_nocov = count;
+      continue;
+    }
+
+    for (twohop_neighbors = a_neighbor->neighbor_2_list.next;
+         twohop_neighbors != &a_neighbor->neighbor_2_list;
+         twohop_neighbors = twohop_neighbors->next) {
+
+      dup_neighbor = olsr_lookup_neighbor_table(&twohop_neighbors->neighbor_2->neighbor_2_addr);
              
-             if((dup_neighbor == NULL) || (dup_neighbor->status != SYM))
-               {
-                 n_count++;
-                 if(!twohop_neighbors->neighbor_2->processed)
-                   {
-                     count++;
-                     twohop_neighbors->neighbor_2->processed = 1;
-                   }
-               }
-           }
-         a_neighbor->neighbor_2_nocov = n_count;
-         
-         /* Add the two hop count */
-         sum += count;
-       }
+      if ((dup_neighbor == NULL) || (dup_neighbor->status != SYM)) {
+        n_count++;
+        if (!twohop_neighbors->neighbor_2->processed) {
+          count++;
+          twohop_neighbors->neighbor_2->processed = 1;
+        }
+      }
     }
+    a_neighbor->neighbor_2_nocov = n_count;
+         
+    /* Add the two hop count */
+    sum += count;
+
+  } OLSR_FOR_ALL_NBR_ENTRIES_END(a_neighbor);
   
   OLSR_PRINTF(3, "Two hop neighbors: %d\n", sum);
   return sum;
@@ -430,32 +406,31 @@ olsr_calculate_two_hop_neighbors(void)
 static olsr_u16_t
 add_will_always_nodes(void)
 {
-  olsr_u16_t                   count = 0;
-  olsr_u8_t                    idx;
+  struct neighbor_entry *a_neighbor;
+  olsr_u16_t count = 0;
 
-  //printf("\nAdding WILL ALWAYS nodes....\n");
+#if 0
+  printf("\nAdding WILL ALWAYS nodes....\n");
+#endif
 
-  for(idx=0;idx<HASHSIZE;idx++)
-    {
-      struct neighbor_entry        *a_neighbor;
-      for(a_neighbor = neighbortable[idx].next;
-         a_neighbor != &neighbortable[idx];
-         a_neighbor = a_neighbor->next)
-       { 
+  OLSR_FOR_ALL_NBR_ENTRIES(a_neighbor) {
 #ifndef NODEBUG
-          struct ipaddr_str buf;
+    struct ipaddr_str buf;
 #endif
-         if((a_neighbor->status == NOT_SYM) || (a_neighbor->willingness != WILL_ALWAYS)) {
-           continue;
-          }
-         olsr_chosen_mpr(a_neighbor, &count); 
+    if ((a_neighbor->status == NOT_SYM) ||
+        (a_neighbor->willingness != WILL_ALWAYS)) {
+      continue;
+    }
+    olsr_chosen_mpr(a_neighbor, &count); 
 
-         OLSR_PRINTF(3, "Adding WILL_ALWAYS: %s\n", olsr_ip_to_string(&buf, &a_neighbor->neighbor_main_addr));
+    OLSR_PRINTF(3, "Adding WILL_ALWAYS: %s\n",
+                olsr_ip_to_string(&buf, &a_neighbor->neighbor_main_addr));
 
-       }
-    }
-  
-  //OLSR_PRINTF(1, "Count: %d\n", count);
+  } OLSR_FOR_ALL_NBR_ENTRIES_END(a_neighbor);
+
+#if 0  
+  OLSR_PRINTF(1, "Count: %d\n", count);
+#endif
   return count;
 }
 
@@ -547,58 +522,52 @@ olsr_calculate_mpr(void)
 static void
 olsr_optimize_mpr_set(void)
 {
+  struct neighbor_entry *a_neighbor, *dup_neighbor;
+  struct neighbor_2_list_entry *two_hop_list;
   int i, remove;
 
-  //printf("\n**MPR OPTIMIZING**\n\n");
+#if 0
+  printf("\n**MPR OPTIMIZING**\n\n");
+#endif
 
-  for(i = WILL_NEVER + 1; i < WILL_ALWAYS; i++)
-    {
-      int idx;
-      for(idx=0;idx<HASHSIZE;idx++)
-       {
-          struct neighbor_entry *a_neighbor;
-         for(a_neighbor = neighbortable[idx].next;
-             a_neighbor != &neighbortable[idx];
-             a_neighbor = a_neighbor->next)
-           {
+  for(i = WILL_NEVER + 1; i < WILL_ALWAYS; i++) {
+
+    OLSR_FOR_ALL_NBR_ENTRIES(a_neighbor) {
              
-             if(a_neighbor->willingness != i)
-               continue;
+      if (a_neighbor->willingness != i) {
+        continue;
+      }
              
-             if(a_neighbor->is_mpr)
-               {
-                  struct neighbor_2_list_entry *two_hop_list;
-                 //printf("\tChecking %s\n", olsr_ip_to_string(&buf, &a_neighbor->neighbor_main_addr));
-                 remove = 1;
+      if (a_neighbor->is_mpr) {
+        remove = 1;
 
-                 for(two_hop_list = a_neighbor->neighbor_2_list.next;
-                     two_hop_list != &a_neighbor->neighbor_2_list;
-                     two_hop_list = two_hop_list->next)
-                   {
+        for (two_hop_list = a_neighbor->neighbor_2_list.next;
+             two_hop_list != &a_neighbor->neighbor_2_list;
+             two_hop_list = two_hop_list->next) {
                      
-                      const struct neighbor_entry * const dup_neighbor = olsr_lookup_neighbor_table(&two_hop_list->neighbor_2->neighbor_2_addr);
+          dup_neighbor = olsr_lookup_neighbor_table(&two_hop_list->neighbor_2->neighbor_2_addr);
                      
-                     if((dup_neighbor != NULL) && (dup_neighbor->status != NOT_SYM))
-                       continue;
-                     
-                     //printf("\t[%s] coverage %d\n", olsr_ip_to_string(&buf, &two_hop_list->neighbor_2->neighbor_2_addr), two_hop_list->neighbor_2->mpr_covered_count);
-                     /* Do not remove if we find a entry which need this MPR */
-                     if(two_hop_list->neighbor_2->mpr_covered_count <= olsr_cnf->mpr_coverage)
-                       remove = 0;
+          if ((dup_neighbor != NULL) && (dup_neighbor->status != NOT_SYM)) {
+            continue;
+          }
                      
-                   }
-                 if(remove)
-                   {
+          //printf("\t[%s] coverage %d\n", olsr_ip_to_string(&buf, &two_hop_list->neighbor_2->neighbor_2_addr), two_hop_list->neighbor_2->mpr_covered_count);
+          /* Do not remove if we find a entry which need this MPR */
+          if (two_hop_list->neighbor_2->mpr_covered_count <= olsr_cnf->mpr_coverage) {
+            remove = 0;
+          }      
+        }
+
+        if (remove) {
 #ifndef NODEBUG
-                      struct ipaddr_str buf;
+          struct ipaddr_str buf;
 #endif
-                     OLSR_PRINTF(3, "MPR OPTIMIZE: removiong mpr %s\n\n", olsr_ip_to_string(&buf, &a_neighbor->neighbor_main_addr));
-                     a_neighbor->is_mpr = OLSR_FALSE;
-                   }
-               }
-           }
-       }
-    }
+          OLSR_PRINTF(3, "MPR OPTIMIZE: removiong mpr %s\n\n", olsr_ip_to_string(&buf, &a_neighbor->neighbor_main_addr));
+          a_neighbor->is_mpr = OLSR_FALSE;
+        }
+      }
+    } OLSR_FOR_ALL_NBR_ENTRIES_END(a_neighbor);
+  }
 }
 
 void
@@ -606,22 +575,27 @@ olsr_print_mpr_set(void)
 {
 #ifndef NODEBUG
   /* The whole function makes no sense without it. */
-  int idx;
+  struct neighbor_entry *a_neighbor;
 
   OLSR_PRINTF(1, "MPR SET: ");
 
-  for(idx = 0; idx < HASHSIZE; idx++) {
-    struct neighbor_entry *a_neighbor;
-    for(a_neighbor = neighbortable[idx].next; a_neighbor != &neighbortable[idx]; a_neighbor = a_neighbor->next) { 
-      /* 
-       * Remove MPR settings
-       */
-      if(a_neighbor->is_mpr) {
-        struct ipaddr_str buf;
-        OLSR_PRINTF(1, "[%s] ", olsr_ip_to_string(&buf, &a_neighbor->neighbor_main_addr));
-      }
+  OLSR_FOR_ALL_NBR_ENTRIES(a_neighbor) {
+
+    /* 
+     * Remove MPR settings
+     */
+    if (a_neighbor->is_mpr) {
+      struct ipaddr_str buf;
+      OLSR_PRINTF(1, "[%s] ", olsr_ip_to_string(&buf, &a_neighbor->neighbor_main_addr));
     }
-  }
+  } OLSR_FOR_ALL_NBR_ENTRIES_END(a_neighbor);
+
   OLSR_PRINTF(1, "\n");
 #endif
 }
+
+/*
+ * Local Variables:
+ * c-basic-offset: 2
+ * End:
+ */
index 224f1be..9ddecb8 100644 (file)
@@ -72,6 +72,15 @@ struct neighbor_entry
   struct neighbor_entry        *prev;
 };
 
+#define OLSR_FOR_ALL_NBR_ENTRIES(nbr) \
+{ \
+  int _idx; \
+  for (_idx = 0; _idx < HASHSIZE; _idx++) { \
+    for(nbr = neighbortable[_idx].next; \
+        nbr != &neighbortable[_idx]; \
+        nbr = nbr->next)
+#define OLSR_FOR_ALL_NBR_ENTRIES_END(nbr) }}
+
 
 /*
  * The neighbor table
index 7385c30..5ac3517 100644 (file)
@@ -89,7 +89,6 @@ olsr_build_hello_packet(struct hello_message *message, struct interface *outif)
   struct hello_neighbor   *message_neighbor, *tmp_neigh;
   struct link_entry       *links;
   struct neighbor_entry   *neighbor;
-  int                     idx;
 
 #ifdef DEBUG
   OLSR_PRINTF(3, "\tBuilding HELLO on interface \"%s\"\n", outif->int_name ? outif->int_name : "<null>");
@@ -125,13 +124,12 @@ olsr_build_hello_packet(struct hello_message *message, struct interface *outif)
     /* Update the status */
       
     /* Check if this link tuple is registered on the outgoing interface */
-    if(!ipequal(&links->local_iface_addr, &outif->ip_addr)) {
+    if (!ipequal(&links->local_iface_addr, &outif->ip_addr)) {
       continue;
     }
 
     message_neighbor = olsr_malloc(sizeof(struct hello_neighbor), "Build HELLO");
       
-
     /* Find the link status */
     message_neighbor->link = lnk;
 
@@ -144,8 +142,7 @@ olsr_build_hello_packet(struct hello_message *message, struct interface *outif)
      *
      *            Neighbor Type = MPR_NEIGH
      */
-    if(links->neighbor->is_mpr)
-    {
+    if (links->neighbor->is_mpr) {
       message_neighbor->status = MPR_NEIGH;
     }
     /*
@@ -158,26 +155,24 @@ olsr_build_hello_packet(struct hello_message *message, struct interface *outif)
      * due to the extentions made in the link sensing
      * regarding main addresses.
      */
-    else
-    {
+    else {
+
       /*
        *   2.2.1
        *        if N_status == SYM
        *
        *             Neighbor Type = SYM_NEIGH
        */
-      if(links->neighbor->status == SYM)
-      {
+      if (links->neighbor->status == SYM) {
         message_neighbor->status = SYM_NEIGH;
       }
+
       /*
        *   2.2.2
        *        Otherwise, if N_status == NOT_SYM
        *             Neighbor Type = NOT_NEIGH
        */
-      else
-        if(links->neighbor->status == NOT_SYM)
-        {
+      else if (links->neighbor->status == NOT_SYM) {
           message_neighbor->status = NOT_NEIGH;
         }
     }
@@ -197,103 +192,91 @@ olsr_build_hello_packet(struct hello_message *message, struct interface *outif)
   
   /* Add the links */
 
-
-
 #ifdef DEBUG
     OLSR_PRINTF(5, "Not on link:\n");
 #endif
 
   /* Add the rest of the neighbors if running on multiple interfaces */
   
-  if(ifnet != NULL && ifnet->int_next != NULL)
-    for(idx=0;idx<HASHSIZE;idx++)
-      {       
-       for(neighbor = neighbortable[idx].next;
-           neighbor != &neighbortable[idx];
-           neighbor=neighbor->next)
-         {
+  if (ifnet != NULL && ifnet->int_next != NULL)
+    OLSR_FOR_ALL_NBR_ENTRIES(neighbor) {
+
 #if !defined(NODEBUG) && defined(DEBUG)
-            struct ipaddr_str buf;
+    struct ipaddr_str buf;
 #endif
-           /* Check that the neighbor is not added yet */
-           tmp_neigh = message->neighbors;
-           //printf("Checking that the neighbor is not yet added\n");
-           while(tmp_neigh)
-             {
-               if(ipequal(&tmp_neigh->main_address, &neighbor->neighbor_main_addr))
-                 {
-                   //printf("Not adding duplicate neighbor %s\n", olsr_ip_to_string(&neighbor->neighbor_main_addr));
-                   break;
-                 }
-               tmp_neigh = tmp_neigh->next;
-             }
-
-           if(tmp_neigh)
-             continue;
-           
-           message_neighbor = olsr_malloc(sizeof(struct hello_neighbor), "Build HELLO 2");
+    /* Check that the neighbor is not added yet */
+    tmp_neigh = message->neighbors;
+    //printf("Checking that the neighbor is not yet added\n");
+    while (tmp_neigh) {
+      if (ipequal(&tmp_neigh->main_address, &neighbor->neighbor_main_addr)) {
+        //printf("Not adding duplicate neighbor %s\n", olsr_ip_to_string(&neighbor->neighbor_main_addr));
+        break;
+      }
+      tmp_neigh = tmp_neigh->next;
+    }
+
+    if (tmp_neigh) {
+      continue;
+    }
            
-           message_neighbor->link = UNSPEC_LINK;
+    message_neighbor = olsr_malloc(sizeof(struct hello_neighbor), "Build HELLO 2");
            
-           /*
-            * Calculate neighbor status
-            */
-           /* 
-            * 2.1  If the main address, corresponding to
-            *      L_neighbor_iface_addr, is included in the MPR set:
-            *
-            *            Neighbor Type = MPR_NEIGH
-            */
-           if(neighbor->is_mpr)
-             {
-               message_neighbor->status = MPR_NEIGH;
-             }
-           /*
-            *  2.2  Otherwise, if the main address, corresponding to
-            *       L_neighbor_iface_addr, is included in the neighbor set:
-            */
+    message_neighbor->link = UNSPEC_LINK;
            
-           /* NOTE:
-            * It is garanteed to be included when come this far
-            * due to the extentions made in the link sensing
-            * regarding main addresses.
-            */
-           else
-             {
-               /*
-                *   2.2.1
-                *        if N_status == SYM
-                *
-                *             Neighbor Type = SYM_NEIGH
-                */
-               if(neighbor->status == SYM)
-                 {
-                   message_neighbor->status = SYM_NEIGH;
-                 }
-               /*
-                *   2.2.2
-                *        Otherwise, if N_status == NOT_SYM
-                *             Neighbor Type = NOT_NEIGH
-                */
-               else
-                 if(neighbor->status == NOT_SYM)
-                   {
-                     message_neighbor->status = NOT_NEIGH;                   
-                   }
-             }
+    /*
+     * Calculate neighbor status
+     */
+    /* 
+     * 2.1  If the main address, corresponding to
+     *      L_neighbor_iface_addr, is included in the MPR set:
+     *
+     *            Neighbor Type = MPR_NEIGH
+     */
+    if (neighbor->is_mpr) {
+      message_neighbor->status = MPR_NEIGH;
+    }
+    /*
+     *  2.2  Otherwise, if the main address, corresponding to
+     *       L_neighbor_iface_addr, is included in the neighbor set:
+     */
            
+    /* NOTE:
+     * It is garanteed to be included when come this far
+     * due to the extentions made in the link sensing
+     * regarding main addresses.
+     */
+    else {
 
-           message_neighbor->address = neighbor->neighbor_main_addr;
+      /*
+       *   2.2.1
+       *        if N_status == SYM
+       *
+       *             Neighbor Type = SYM_NEIGH
+       */
+      if (neighbor->status == SYM) {
+        message_neighbor->status = SYM_NEIGH;
+      }
 
-           message_neighbor->main_address = neighbor->neighbor_main_addr;
-#ifdef DEBUG
-           OLSR_PRINTF(5, "Added: %s -  status  %d\n", olsr_ip_to_string(&buf, &message_neighbor->address), message_neighbor->status);
-#endif
-           message_neighbor->next=message->neighbors;
-           message->neighbors=message_neighbor;            
-         }
+      /*
+       *   2.2.2
+       *        Otherwise, if N_status == NOT_SYM
+       *             Neighbor Type = NOT_NEIGH
+       */
+      else if (neighbor->status == NOT_SYM) {
+        message_neighbor->status = NOT_NEIGH;                
       }
+    }
+           
 
+    message_neighbor->address = neighbor->neighbor_main_addr;
+    message_neighbor->main_address = neighbor->neighbor_main_addr;
+#ifdef DEBUG
+    OLSR_PRINTF(5, "Added: %s -  status  %d\n", olsr_ip_to_string(&buf, &message_neighbor->address), message_neighbor->status);
+#endif
+    message_neighbor->next=message->neighbors;
+    message->neighbors=message_neighbor;       
+    
+  } OLSR_FOR_ALL_NBR_ENTRIES_END(neighbor);
 
   return 0;
 }
@@ -333,10 +316,7 @@ int
 olsr_build_tc_packet(struct tc_message *message)
 {
   struct tc_mpr_addr     *message_mpr;
-  //struct mpr_selector       *mprs;
-  int                     idx;
   struct neighbor_entry  *entry;
-  //struct mpr_selector_hash  *mprs_hash;
   olsr_bool entry_added = OLSR_FALSE;
 
   message->multipoint_relay_selector_address=NULL;
@@ -351,82 +331,67 @@ olsr_build_tc_packet(struct tc_message *message)
   
 
   /* Loop trough all neighbors */  
-  for(idx=0;idx<HASHSIZE;idx++)
+  OLSR_FOR_ALL_NBR_ENTRIES(entry) {
+    if (entry->status != SYM) {
+      continue;
+    }
+
+    switch (olsr_cnf->tc_redundancy) {
+    case(2):
     {
-      for(entry = neighbortable[idx].next;
-         entry != &neighbortable[idx];
-         entry = entry->next)
-       {
-         if(entry->status != SYM)
-           continue;
-
-         switch(olsr_cnf->tc_redundancy)
-           {
-           case(2):
-             {
-               /* 2 = Add all neighbors */
-               //printf("\t%s\n", olsr_ip_to_string(&mprs->mpr_selector_addr));
-               message_mpr = olsr_malloc(sizeof(struct tc_mpr_addr), "Build TC");
-               
-               message_mpr->address = entry->neighbor_main_addr;
-               message_mpr->next = message->multipoint_relay_selector_address;
-               message->multipoint_relay_selector_address = message_mpr;
-               entry_added = OLSR_TRUE;
+      /* 2 = Add all neighbors */
+      //printf("\t%s\n", olsr_ip_to_string(&mprs->mpr_selector_addr));
+      message_mpr = olsr_malloc(sizeof(struct tc_mpr_addr), "Build TC");
                
-               break;
-             }
-           case(1):
-             {
-               /* 1 = Add all MPR selectors and selected MPRs */
-               if((entry->is_mpr) ||
-                  (olsr_lookup_mprs_set(&entry->neighbor_main_addr) != NULL))
-                 {
-                   //printf("\t%s\n", olsr_ip_to_string(&mprs->mpr_selector_addr));
-                   message_mpr = olsr_malloc(sizeof(struct tc_mpr_addr), "Build TC 2");
-                   
-                   message_mpr->address = entry->neighbor_main_addr;
-                   message_mpr->next = message->multipoint_relay_selector_address;
-                   message->multipoint_relay_selector_address = message_mpr;
-                   entry_added = OLSR_TRUE;
-                 }
-               break;
-             }
-           default:
-             {
-               /* 0 = Add only MPR selectors(default) */
-               if(olsr_lookup_mprs_set(&entry->neighbor_main_addr) != NULL)
-                 {
-                   //printf("\t%s\n", olsr_ip_to_string(&mprs->mpr_selector_addr));
-                   message_mpr = olsr_malloc(sizeof(struct tc_mpr_addr), "Build TC 3");
-                   
-                   message_mpr->address = entry->neighbor_main_addr;
-                   message_mpr->next = message->multipoint_relay_selector_address;
-                   message->multipoint_relay_selector_address = message_mpr;
-                   entry_added = OLSR_TRUE;
-                 }
-               break;
-             }         
-         
-           } /* Switch */
-       } /* For */
-    } /* For idx */
-
-  if(entry_added)
+      message_mpr->address = entry->neighbor_main_addr;
+      message_mpr->next = message->multipoint_relay_selector_address;
+      message->multipoint_relay_selector_address = message_mpr;
+      entry_added = OLSR_TRUE;         
+      break;
+    }
+    case(1):
     {
-      sending_tc = OLSR_TRUE;
+      /* 1 = Add all MPR selectors and selected MPRs */
+      if ((entry->is_mpr) ||
+          (olsr_lookup_mprs_set(&entry->neighbor_main_addr) != NULL)) {
+        //printf("\t%s\n", olsr_ip_to_string(&mprs->mpr_selector_addr));
+        message_mpr = olsr_malloc(sizeof(struct tc_mpr_addr), "Build TC 2");
+                   
+        message_mpr->address = entry->neighbor_main_addr;
+        message_mpr->next = message->multipoint_relay_selector_address;
+        message->multipoint_relay_selector_address = message_mpr;
+        entry_added = OLSR_TRUE;
+      }
+      break;
     }
-  else
+    default:
     {
-      if(sending_tc)
-       {
-         /* Send empty TC */
-         OLSR_PRINTF(3, "No more MPR selectors - will send empty TCs\n");
-         set_empty_tc_timer(GET_TIMESTAMP((olsr_cnf->max_tc_vtime*3)*1000));
-
-         sending_tc = OLSR_FALSE;
-       }
+      /* 0 = Add only MPR selectors(default) */
+      if (olsr_lookup_mprs_set(&entry->neighbor_main_addr) != NULL) {
+        //printf("\t%s\n", olsr_ip_to_string(&mprs->mpr_selector_addr));
+        message_mpr = olsr_malloc(sizeof(struct tc_mpr_addr), "Build TC 3");
+                   
+        message_mpr->address = entry->neighbor_main_addr;
+        message_mpr->next = message->multipoint_relay_selector_address;
+        message->multipoint_relay_selector_address = message_mpr;
+        entry_added = OLSR_TRUE;
+      }
+      break;
+    }          
+         
+    } /* Switch */
+  } OLSR_FOR_ALL_NBR_ENTRIES_END(entry);
+
+  if (entry_added) {
+    sending_tc = OLSR_TRUE;
+  } else {
+    if (sending_tc) {
+      /* Send empty TC */
+      OLSR_PRINTF(3, "No more MPR selectors - will send empty TCs\n");
+      set_empty_tc_timer(GET_TIMESTAMP((olsr_cnf->max_tc_vtime*3)*1000));
+      sending_tc = OLSR_FALSE;
     }
-
+  }
 
   return 0;
 }