add the OLSR_FOR_ALL_HNA_ENTRIES walking macro
authorHannes Gredler <hannes@gredler.at>
Tue, 1 Apr 2008 21:15:51 +0000 (23:15 +0200)
committerHannes Gredler <hannes@gredler.at>
Tue, 1 Apr 2008 21:15:51 +0000 (23:15 +0200)
contrib/netsimpcap/bin/netsimpcap
lib/dot_draw/src/olsrd_dot_draw.c
lib/txtinfo/src/olsrd_txtinfo.c
src/hna_set.c
src/hna_set.h

index 7fc62eb..d46166c 100755 (executable)
Binary files a/contrib/netsimpcap/bin/netsimpcap and b/contrib/netsimpcap/bin/netsimpcap differ
index 16cb374..34eaf0b 100644 (file)
@@ -283,8 +283,10 @@ pcf_event(int changes_neighborhood,
   struct neighbor_entry *neighbor_table_tmp;
   struct tc_entry *tc;
   struct tc_edge_entry *tc_edge;
+  struct hna_entry *tmp_hna;
+  struct hna_net *tmp_net;
   struct ip_prefix_list *hna;
-  int idx, res = 0;
+  int res = 0;
 
   if (changes_neighborhood || changes_topology || changes_hna) {
     
@@ -304,19 +306,17 @@ pcf_event(int changes_neighborhood,
     } OLSR_FOR_ALL_TC_ENTRIES_END(tc);
 
     /* HNA entries */
-    for (idx = 0; idx < HASHSIZE; idx++) {
-      struct hna_entry *tmp_hna;
-      /* Check all entrys */
-      for (tmp_hna = hna_set[idx].next; tmp_hna != &hna_set[idx]; tmp_hna = tmp_hna->next) {
-        /* Check all networks */
-        struct hna_net *tmp_net;
-        for (tmp_net = tmp_hna->networks.next; tmp_net != &tmp_hna->networks; tmp_net = tmp_net->next) {
-          ipc_print_net(&tmp_hna->A_gateway_addr, 
-                        &tmp_net->A_network_addr, 
-                        tmp_net->prefixlen);
-        }
+    OLSR_FOR_ALL_HNA_ENTRIES(tmp_hna) {
+
+      /* Check all networks */
+      for (tmp_net = tmp_hna->networks.next;
+           tmp_net != &tmp_hna->networks;
+           tmp_net = tmp_net->next) {
+        ipc_print_net(&tmp_hna->A_gateway_addr, 
+                      &tmp_net->A_network_addr, 
+                      tmp_net->prefixlen);
       }
-    }
+    } OLSR_FOR_ALL_HNA_ENTRIES_END(tmp_hna);
 
     /* Local HNA entries */
     for (hna = olsr_cnf->hna_entries; hna != NULL; hna = hna->next) {
index bc495e2..7bd3a48 100644 (file)
@@ -423,6 +423,9 @@ static void ipc_print_hna(void)
     int size;
     int index;
     struct ip_prefix_list *hna;
+    struct hna_entry *tmp_hna;
+    struct hna_net *tmp_net;
+    struct ipaddr_str addrbuf, mainaddrbuf;
 
     size = 0;
 
@@ -448,21 +451,20 @@ static void ipc_print_hna(void)
     }
 
     /* HNA entries */
-    for(index = 0; index < HASHSIZE; index++) {
-        struct hna_entry *tmp_hna;
-        /* Check all entrys */
-        for (tmp_hna = hna_set[index].next; tmp_hna != &hna_set[index]; tmp_hna = tmp_hna->next) {
-            /* Check all networks */
-            struct hna_net *tmp_net;
-            for (tmp_net = tmp_hna->networks.next; tmp_net != &tmp_hna->networks; tmp_net = tmp_net->next) {
-                struct ipaddr_str addrbuf, mainaddrbuf;
-                ipc_sendf("%s\t%d\t%s\n",
-                          olsr_ip_to_string(&addrbuf, &tmp_net->A_network_addr),
-                          tmp_net->prefixlen,
-                          olsr_ip_to_string(&mainaddrbuf, &tmp_hna->A_gateway_addr));
-            }
-       }
-    }
+    OLSR_FOR_ALL_HNA_ENTRIES(tmp_hna) {
+
+        /* Check all networks */
+        for (tmp_net = tmp_hna->networks.next;
+             tmp_net != &tmp_hna->networks;
+             tmp_net = tmp_net->next) {
+
+            ipc_sendf("%s\t%d\t%s\n",
+                      olsr_ip_to_string(&addrbuf, &tmp_net->A_network_addr),
+                      tmp_net->prefixlen,
+                      olsr_ip_to_string(&mainaddrbuf, &tmp_hna->A_gateway_addr));
+        }
+    } OLSR_FOR_ALL_HNA_ENTRIES_END(tmp_hna);
+
     ipc_sendf("\n");
 }
 
index cf8bd49..2a0df61 100644 (file)
 struct hna_entry hna_set[HASHSIZE];
 
 /**
- *Initialize the HNA set
+ * Initialize the HNA set
  */
 int
 olsr_init_hna_set(void)
 {
   int idx;
 
-  for(idx=0;idx<HASHSIZE;idx++)
-    {
-      hna_set[idx].next = &hna_set[idx];
-      hna_set[idx].prev = &hna_set[idx];
-    }
+  for(idx=0;idx<HASHSIZE;idx++) {
+    hna_set[idx].next = &hna_set[idx];
+    hna_set[idx].prev = &hna_set[idx];
+  }
 
   return 1;
 }
@@ -75,7 +74,8 @@ olsr_init_hna_set(void)
  *@return the localted entry or NULL of not found
  */
 struct hna_net *
-olsr_lookup_hna_net(const struct hna_net *nets, const union olsr_ip_addr *net, olsr_u8_t prefixlen)
+olsr_lookup_hna_net(const struct hna_net *nets, const union olsr_ip_addr *net,
+                    olsr_u8_t prefixlen)
 {
   struct hna_net *tmp;
   /* Loop trough entrys */
@@ -90,11 +90,10 @@ olsr_lookup_hna_net(const struct hna_net *nets, const union olsr_ip_addr *net, o
 
 
 /**
- *Lookup a gateway entry
- *
- *@param gw the address of the gateway
+ * Lookup a gateway entry
  *
- *@return the located entry or NULL if not found
+ * @param gw the address of the gateway
+ * @return the located entry or NULL if not found
  */
 struct hna_entry *
 olsr_lookup_hna_gw(const union olsr_ip_addr *gw)
@@ -105,15 +104,15 @@ olsr_lookup_hna_gw(const union olsr_ip_addr *gw)
 #if 0
   OLSR_PRINTF(5, "HNA: lookup entry\n");
 #endif
-  
-  /* Check for registered entry */
+    /* Check for registered entry */
+
   for(tmp_hna = hna_set[hash].next;
       tmp_hna != &hna_set[hash];
-      tmp_hna = tmp_hna->next)
-    {
-      if(ipequal(&tmp_hna->A_gateway_addr, gw))
-       return tmp_hna;
+      tmp_hna = tmp_hna->next) {
+    if(ipequal(&tmp_hna->A_gateway_addr, gw)) {
+      return tmp_hna;
     }
+  }
   
   /* Not found */
   return NULL;
index 704956a..1d268f7 100644 (file)
@@ -69,6 +69,14 @@ struct hna_entry
   struct hna_entry   *prev;
 };
 
+#define OLSR_FOR_ALL_HNA_ENTRIES(hna) \
+{ \
+  int _idx; \
+  for (_idx = 0; _idx < HASHSIZE; _idx++) { \
+    for(hna = hna_set[_idx].next; \
+        hna != &hna_set[_idx]; \
+        hna = hna->next)
+#define OLSR_FOR_ALL_HNA_ENTRIES_END(hna) }}
 
 extern struct hna_entry hna_set[HASHSIZE];