Large cleanup patch...
authorHenning Rogge <hrogge@googlemail.com>
Tue, 1 Sep 2009 17:13:02 +0000 (19:13 +0200)
committerHenning Rogge <hrogge@googlemail.com>
Tue, 1 Sep 2009 17:13:02 +0000 (19:13 +0200)
more sane plugin definition system
simplified AVL-Loop generation

38 files changed:
lib/debuginfo/src/olsrd_debuginfo.c
lib/debuginfo/src/olsrd_debuginfo.h
lib/dot_draw/src/olsrd_dot_draw.c
lib/httpinfo/src/olsrd_httpinfo.c
lib/lq_etx_ff/src/lq_plugin_etx_ff.c
lib/lq_etx_float/src/lq_plugin_etx_float.c
lib/lq_etx_fpm/src/lq_plugin_etx_fpm.c
lib/lq_rfc/src/lq_plugin_rfc.c
lib/nameservice/src/mapwrite.c
lib/obamp/src/olsrd_plugin.c
lib/txtinfo/src/olsrd_txtinfo.c
src/common/avl.h
src/duplicate_set.c
src/duplicate_set.h
src/hna_set.c
src/hna_set.h
src/interfaces.c
src/interfaces.h
src/lq_mpr.c
src/main.c
src/mid_set.h
src/neighbor_table.c
src/neighbor_table.h
src/net_olsr.c
src/net_olsr.h
src/olsr_comport_http.c
src/olsr_comport_http.h
src/olsr_comport_txt.c
src/olsr_comport_txt.h
src/olsr_cookie.c
src/olsr_cookie.h
src/plugin.h
src/plugin_loader.c
src/plugin_loader.h
src/process_routes.c
src/routing_table.h
src/tc_set.c
src/tc_set.h

index 4c96aa4..980d258 100644 (file)
@@ -274,7 +274,7 @@ update_statistics_ptr(void *data __attribute__ ((unused)))
       avl_delete(&stat_msg_tree, &msg->node);
       olsr_cookie_free(statistics_msg_mem, msg);
     }
-  } OLSR_FOR_ALL_MSGTRAFFIC_ENTRIES_END(msg)
+  } OLSR_FOR_ALL_MSGTRAFFIC_ENTRIES_END()
 
   OLSR_FOR_ALL_PKTTRAFFIC_ENTRIES(pkt) {
     /* subtract old values from node count and total count */
@@ -300,7 +300,7 @@ update_statistics_ptr(void *data __attribute__ ((unused)))
       free(pkt->int_name);
       olsr_cookie_free(statistics_pkt_mem, pkt);
     }
-  } OLSR_FOR_ALL_PKTTRAFFIC_ENTRIES_END(pkt)
+  } OLSR_FOR_ALL_PKTTRAFFIC_ENTRIES_END()
 }
 
 /* update message statistics */
@@ -425,7 +425,7 @@ debuginfo_msgstat(struct comport_connection *con,  char *cmd __attribute__ ((unu
       if (debuginfo_print_msgstat(&con->out, &tr->ip, &tr->traffic[current_slot])) {
         return ABUF_ERROR;
       }
-    } OLSR_FOR_ALL_MSGTRAFFIC_ENTRIES_END(tr)
+    } OLSR_FOR_ALL_MSGTRAFFIC_ENTRIES_END()
   }
   else {
     uint32_t mult = 1, divisor = 1;
@@ -462,7 +462,7 @@ debuginfo_msgstat(struct comport_connection *con,  char *cmd __attribute__ ((unu
       if (debuginfo_print_msgstat(&con->out, &tr->ip, &cnt)) {
         return ABUF_ERROR;
       }
-    } OLSR_FOR_ALL_MSGTRAFFIC_ENTRIES_END(tr)
+    } OLSR_FOR_ALL_MSGTRAFFIC_ENTRIES_END()
   }
 
   return CONTINUE;
@@ -497,7 +497,7 @@ debuginfo_pktstat(struct comport_connection *con,  char *cmd __attribute__ ((unu
       if (debuginfo_print_pktstat(&con->out, &tr->ip, tr->int_name, &tr->traffic[current_slot])) {
         return ABUF_ERROR;
       }
-    } OLSR_FOR_ALL_PKTTRAFFIC_ENTRIES_END(tr)
+    } OLSR_FOR_ALL_PKTTRAFFIC_ENTRIES_END()
   }
   else {
     uint32_t mult = 1, divisor = 1;
@@ -534,7 +534,7 @@ debuginfo_pktstat(struct comport_connection *con,  char *cmd __attribute__ ((unu
       if (debuginfo_print_pktstat(&con->out, &tr->ip, tr->int_name, &cnt)) {
         return ABUF_ERROR;
       }
-    } OLSR_FOR_ALL_PKTTRAFFIC_ENTRIES_END(tr)
+    } OLSR_FOR_ALL_PKTTRAFFIC_ENTRIES_END()
   }
 
   return CONTINUE;
@@ -552,7 +552,7 @@ static INLINE bool debuginfo_print_cookies_mem(struct autobuf *buf, const char *
         (unsigned long)c->ci_size, c->ci_usage, c->ci_free_list_usage) < 0) {
       return true;
     }
-  } OLSR_FOR_ALL_COOKIES_END(c)
+  } OLSR_FOR_ALL_COOKIES_END()
   return false;
 }
 
@@ -567,7 +567,7 @@ static INLINE bool debuginfo_print_cookies_timer(struct autobuf *buf, const char
                        c->ci_usage, c->ci_changes) < 0) {
       return true;
     }
-  } OLSR_FOR_ALL_COOKIES_END(c)
+  } OLSR_FOR_ALL_COOKIES_END()
   return false;
 }
 
index 8e1462e..fa164c4 100644 (file)
@@ -100,23 +100,13 @@ struct debug_pkttraffic {
   struct debug_pkttraffic_count traffic[0];
 };
 
-#define OLSR_FOR_ALL_MSGTRAFFIC_ENTRIES(tr) \
-{ \
-  struct avl_node *tr_tree_node, *next_tr_tree_node; \
-  for (tr_tree_node = avl_walk_first(&stat_msg_tree); \
-    tr_tree_node; tr_tree_node = next_tr_tree_node) { \
-    next_tr_tree_node = avl_walk_next(tr_tree_node); \
-    tr = (struct debug_msgtraffic *)(tr_tree_node);
-#define OLSR_FOR_ALL_MSGTRAFFIC_ENTRIES_END(tr) }}
-
-#define OLSR_FOR_ALL_PKTTRAFFIC_ENTRIES(tr) \
-{ \
-  struct avl_node *tr_tree_node, *next_tr_tree_node; \
-  for (tr_tree_node = avl_walk_first(&stat_pkt_tree); \
-    tr_tree_node; tr_tree_node = next_tr_tree_node) { \
-    next_tr_tree_node = avl_walk_next(tr_tree_node); \
-    tr = (struct debug_pkttraffic *)(tr_tree_node);
-#define OLSR_FOR_ALL_PKTTRAFFIC_ENTRIES_END(tr) }}
+AVLNODE2STRUCT(msgnode2traffic, debug_msgtraffic, node);
+#define OLSR_FOR_ALL_MSGTRAFFIC_ENTRIES(tr) OLSR_FOR_ALL_AVL_ENTRIES(&stat_msg_tree, msgnode2traffic, tr)
+#define OLSR_FOR_ALL_MSGTRAFFIC_ENTRIES_END() OLSR_FOR_ALL_AVL_ENTRIES_END()
+
+AVLNODE2STRUCT(pktnode2traffic, debug_pkttraffic, node);
+#define OLSR_FOR_ALL_PKTTRAFFIC_ENTRIES(tr) OLSR_FOR_ALL_AVL_ENTRIES(&stat_pkt_tree, pktnode2traffic, tr)
+#define OLSR_FOR_ALL_PKTTRAFFIC_ENTRIES_END() OLSR_FOR_ALL_AVL_ENTRIES_END()
 
 #endif
 
index 6389937..b2a3e09 100644 (file)
@@ -271,7 +271,7 @@ pcf_event(int ipc_connection, int chgs_neighborhood, int chgs_topology, int chgs
     /* Neighbors */
     OLSR_FOR_ALL_NBR_ENTRIES(neighbor_table_tmp) {
       ipc_print_neigh_link(ipc_connection, neighbor_table_tmp);
-    } OLSR_FOR_ALL_NBR_ENTRIES_END(neighbor_table_tmp);
+    } OLSR_FOR_ALL_NBR_ENTRIES_END();
 
     /* Topology */
     OLSR_FOR_ALL_TC_ENTRIES(tc) {
@@ -281,9 +281,9 @@ pcf_event(int ipc_connection, int chgs_neighborhood, int chgs_topology, int chgs
           ipc_print_tc_link(ipc_connection, tc, tc_edge);
         }
       }
-      OLSR_FOR_ALL_TC_EDGE_ENTRIES_END(tc, tc_edge);
+      OLSR_FOR_ALL_TC_EDGE_ENTRIES_END();
     }
-    OLSR_FOR_ALL_TC_ENTRIES_END(tc);
+    OLSR_FOR_ALL_TC_ENTRIES_END();
 
     /* HNA entries */
     OLSR_FOR_ALL_TC_ENTRIES(tc) {
@@ -292,7 +292,7 @@ pcf_event(int ipc_connection, int chgs_neighborhood, int chgs_topology, int chgs
       OLSR_FOR_ALL_TC_HNA_ENTRIES(tc, tmp_net) {
         ipc_print_net(ipc_connection, &tc->addr, &tmp_net->hna_prefix);
       }
-    } OLSR_FOR_ALL_TC_HNA_ENTRIES_END(tc, tmp_hna);
+    } OLSR_FOR_ALL_TC_HNA_ENTRIES_END();
     OLSR_FOR_ALL_TC_ENTRIES_END(tc);
 
     /* Local HNA entries */
index f667dce..205b129 100644 (file)
@@ -982,9 +982,9 @@ build_neigh_body(struct autobuf *abuf)
       struct ipaddr_str strbuf;
       abuf_appendf(abuf, "<option>%s</option>\n", olsr_ip_to_string(&strbuf, &connector->nbr2->nbr2_addr));
       thop_cnt++;
-    } OLSR_FOR_ALL_NBR_CON_ENTRIES_END(neigh, connector);
+    } OLSR_FOR_ALL_NBR_CON_ENTRIES_END()
     abuf_appendf(abuf, "</select> (%d)</td></tr>\n", thop_cnt);
-  } OLSR_FOR_ALL_NBR_ENTRIES_END(neigh);
+  } OLSR_FOR_ALL_NBR_ENTRIES_END()
 
   abuf_puts(abuf, "</table>\n");
 }
@@ -1012,8 +1012,8 @@ build_topo_body(struct autobuf *abuf)
                      olsr_get_linkcost_text(tc_edge->cost, false, lqbuffer, sizeof(lqbuffer)));
         abuf_puts(abuf, "</tr>\n");
       }
-    } OLSR_FOR_ALL_TC_EDGE_ENTRIES_END(tc, tc_edge);
-  } OLSR_FOR_ALL_TC_ENTRIES_END(tc);
+    } OLSR_FOR_ALL_TC_EDGE_ENTRIES_END();
+  } OLSR_FOR_ALL_TC_ENTRIES_END();
 
   abuf_puts(abuf, "</table>\n");
 }
@@ -1039,7 +1039,7 @@ build_mid_body(struct autobuf *abuf)
       abuf_appendf(abuf, "<option>%s</option>\n", olsr_ip_to_string(&strbuf, &alias->mid_alias_addr));
     } OLSR_FOR_ALL_TC_MID_ENTRIES_END(tc, alias);
     abuf_appendf(abuf, "</select> (%u)</td></tr>\n", tc->mid_tree.count);
-  } OLSR_FOR_ALL_TC_ENTRIES_END(tc);
+  } OLSR_FOR_ALL_TC_ENTRIES_END();
 
   abuf_puts(abuf, "</table>\n");
 }
index 0098a62..415141b 100644 (file)
@@ -90,7 +90,11 @@ static const char *lq_etxff_print_link_entry_lq(struct link_entry *entry, int in
 
 static struct olsr_cookie_info *default_lq_ff_timer_cookie = NULL;
 
-DEFINE_PLUGIN6_NP(PLUGIN_DESCR, PLUGIN_AUTHOR, NULL, lq_etxff_post_init, NULL, NULL, false)
+OLSR_PLUGIN6_NP() {
+  .descr = PLUGIN_DESCR,
+  .author = PLUGIN_AUTHOR,
+  .post_init = lq_etxff_post_init
+};
 
 /* etx lq plugin (freifunk fpm version) settings */
 struct lq_linkdata_type lq_etxff_linktypes[] = {
index e53e1dc..30d64d6 100644 (file)
@@ -135,7 +135,11 @@ static const struct olsrd_plugin_parameters plugin_parameters[] = {
   {.name = "LinkQualityAging",.set_plugin_parameter = &set_plugin_float,.data = &lq_aging},
 };
 
-DEFINE_PLUGIN6(PLUGIN_DESCR, PLUGIN_AUTHOR, NULL, lq_etxfloat_post_init, NULL, NULL, false, plugin_parameters)
+OLSR_PLUGIN6(plugin_parameters) {
+  .descr = PLUGIN_DESCR,
+  .author = PLUGIN_AUTHOR,
+  .post_init = lq_etxfloat_post_init
+};
 
 static int
 set_plugin_float(const char *value, void *data, set_plugin_parameter_addon addon __attribute__ ((unused)))
index 0665232..e7eb47c 100644 (file)
@@ -140,7 +140,12 @@ static const struct olsrd_plugin_parameters plugin_parameters[] = {
   {.name = "LinkQualityAging",.set_plugin_parameter = &set_plugin_aging,.data = NULL}
 };
 
-DEFINE_PLUGIN6(PLUGIN_DESCR, PLUGIN_AUTHOR, NULL, lq_etxfpm_post_init, NULL, NULL, false, plugin_parameters)
+OLSR_PLUGIN6(plugin_parameters) {
+  .descr = PLUGIN_DESCR,
+  .author = PLUGIN_AUTHOR,
+  .post_init = lq_etxfpm_post_init
+};
+
 
 static bool lq_etxfpm_post_init(void) {
   active_lq_handler = &lq_etxfpm_handler;
index 36a4809..10af554 100644 (file)
@@ -140,7 +140,11 @@ static const struct olsrd_plugin_parameters plugin_parameters[] = {
   {.name = "HystThrLow",.set_plugin_parameter = &set_plugin_float,.data = &thr_low},
 };
 
-DEFINE_PLUGIN6(PLUGIN_DESCR, PLUGIN_AUTHOR, NULL, lq_rfc_post_init, NULL, NULL, false, plugin_parameters)
+OLSR_PLUGIN6(plugin_parameters) {
+  .descr = PLUGIN_DESCR,
+  .author = PLUGIN_AUTHOR,
+  .post_init = lq_rfc_post_init
+};
 
 static bool lq_rfc_post_init(void) {
   active_lq_handler = &lq_rfc_handler;
index bc5e9ff..67f74b5 100644 (file)
@@ -194,9 +194,9 @@ mapwrite_work(FILE * fmap)
         }
       }
     }
-    OLSR_FOR_ALL_TC_EDGE_ENTRIES_END(tc, tc_edge);
+    OLSR_FOR_ALL_TC_EDGE_ENTRIES_END();
   }
-  OLSR_FOR_ALL_TC_ENTRIES_END(tc);
+  OLSR_FOR_ALL_TC_ENTRIES_END();
 }
 
 #ifndef WIN32
index 05ca619..673ba78 100644 (file)
@@ -65,15 +65,16 @@ static bool obamp_post_init(void);
 static bool obamp_pre_cleanup(void);
 
 static const struct olsrd_plugin_parameters plugin_parameters[] = {
-
   { .name = "NonOlsrIf", .set_plugin_parameter = &AddObampSniffingIf, .data = NULL },
-
 };
 
-
-//DEFINE_PLUGIN6(PLUGIN_DESCR, PLUGIN_AUTHOR, obamp_pre_init, olsrd_plugin_init, obamp_pre_cleanup, NULL, true, plugin_parameters)
-
-DEFINE_PLUGIN6(PLUGIN_DESCR, PLUGIN_AUTHOR, obamp_pre_init, obamp_post_init, obamp_pre_cleanup, NULL, true, plugin_parameters)
+OLSR_PLUGIN6(plugin_parameters) {
+  .descr = PLUGIN_DESCR,
+  .author = PLUGIN_AUTHOR,
+  .pre_init = obamp_pre_init,
+  .post_init = obamp_post_init,
+  .pre_cleanup = obamp_pre_cleanup,
+};
 
 /**
  * Constructor of plugin, called before parameters are initialized
index 8d5aada..efaaece 100644 (file)
@@ -91,7 +91,14 @@ static const struct olsrd_plugin_parameters plugin_parameters[] = {
   {.name = IP_ACL_DEFAULTPOLICY_PARAM,.set_plugin_parameter = &ip_acl_add_plugin_defaultPolicy,.data = &allowed_nets}
 };
 
-DEFINE_PLUGIN6(PLUGIN_DESCR, PLUGIN_AUTHOR, txtinfo_pre_init, txtinfo_post_init, txtinfo_pre_cleanup, NULL, true, plugin_parameters)
+OLSR_PLUGIN6(plugin_parameters) {
+  .descr = PLUGIN_DESCR,
+  .author = PLUGIN_AUTHOR,
+  .pre_init = txtinfo_pre_init,
+  .post_init = txtinfo_post_init,
+  .pre_cleanup = txtinfo_pre_cleanup,
+  .deactivate = true
+};
 
 /* command callbacks and names */
 static struct txtinfo_cmd commands[] = {
@@ -357,7 +364,7 @@ txtinfo_neigh(struct comport_connection *con,  char *cmd __attribute__ ((unused)
     if (abuf_templatef(&con->out, template, values_neigh, tmpl_indices, indexLength) < 0) {
         return ABUF_ERROR;
     }
-  } OLSR_FOR_ALL_NBR_ENTRIES_END(neigh);
+  } OLSR_FOR_ALL_NBR_ENTRIES_END()
 
   return CONTINUE;
 }
@@ -512,8 +519,8 @@ txtinfo_topology(struct comport_connection *con,  char *cmd __attribute__ ((unus
       if (abuf_templatef(&con->out, template, values_topology, tmpl_indices, indexLength) < 0) {
           return ABUF_ERROR;
       }
-    } OLSR_FOR_ALL_TC_EDGE_ENTRIES_END(tc, tc_edge);
-  } OLSR_FOR_ALL_TC_ENTRIES_END(tc)
+    } OLSR_FOR_ALL_TC_EDGE_ENTRIES_END();
+  } OLSR_FOR_ALL_TC_ENTRIES_END()
 
   return CONTINUE;
 }
@@ -571,8 +578,8 @@ txtinfo_hna(struct comport_connection *con,  char *cmd __attribute__ ((unused)),
       if (abuf_templatef(&con->out, template, values_hna, tmpl_indices, indexLength) < 0) {
           return ABUF_ERROR;
       }
-    } OLSR_FOR_ALL_TC_HNA_ENTRIES_END(tc, tmp_net);
-  } OLSR_FOR_ALL_TC_ENTRIES_END(tc);
+    } OLSR_FOR_ALL_TC_HNA_ENTRIES_END();
+  } OLSR_FOR_ALL_TC_ENTRIES_END();
 
   return CONTINUE;
 }
index 833854b..5adca5c 100644 (file)
@@ -131,14 +131,20 @@ extern int avl_comp_strcasecmp(const void *, const void *);
  * base of the datastructure. That way you save an extra data pointer.
  */
 #define AVLNODE2STRUCT(funcname, structname, avlnodename) \
-static inline structname * funcname (struct avl_node *ptr)\
+static INLINE struct structname * funcname (struct avl_node *ptr)\
 {\
-  return( \
-    ptr ? \
-      (structname *) (((size_t) ptr) - offsetof(structname, avlnodename)) : \
-      NULL); \
+  if (!ptr) return NULL; \
+  return ((struct structname *) ((char *)ptr - offsetof(struct structname,avlnodename))); \
 }
 
+#define OLSR_FOR_ALL_AVL_ENTRIES(avltreeptr, convfunc, variable) \
+{ \
+  struct avl_node *convfunc##node, *convfunc##next_node; \
+  for (convfunc##node = avl_walk_first(avltreeptr); convfunc##node; convfunc##node = convfunc##next_node) { \
+    convfunc##next_node = avl_walk_next(convfunc##node); \
+    variable = convfunc (convfunc##node);
+#define OLSR_FOR_ALL_AVL_ENTRIES_END() }}
+
 #endif /* _AVL_H */
 
 /*
index 6c5360a..e237ec3 100644 (file)
@@ -53,7 +53,7 @@
 
 static void olsr_cleanup_duplicate_entry(void *unused);
 
-static struct avl_tree forward_set, processing_set;
+struct avl_tree forward_set, processing_set;
 static struct timer_entry *duplicate_cleanup_timer;
 
 /* Some cookies for stats keeping */
@@ -122,18 +122,16 @@ olsr_cleanup_duplicate_entry(void __attribute__ ((unused)) * unused)
 {
   struct dup_entry *entry;
 
-  OLSR_FOR_ALL_DUP_ENTRIES(entry, true) {
+  OLSR_FOR_ALL_FORWARD_DUP_ENTRIES(entry) {
     if (TIMED_OUT(entry->valid_until)) {
       olsr_delete_duplicate_entry(entry, true);
     }
-  }
-  OLSR_FOR_ALL_DUP_ENTRIES_END(entry);
-  OLSR_FOR_ALL_DUP_ENTRIES(entry, false) {
+  } OLSR_FOR_ALL_FORWARD_DUP_ENTRIES_END()
+  OLSR_FOR_ALL_PROCESS_DUP_ENTRIES(entry) {
     if (TIMED_OUT(entry->valid_until)) {
       olsr_delete_duplicate_entry(entry, false);
     }
-  }
-  OLSR_FOR_ALL_DUP_ENTRIES_END(entry);
+  } OLSR_FOR_ALL_PROCESS_DUP_ENTRIES_END()
 }
 
 /**
@@ -147,12 +145,12 @@ olsr_flush_duplicate_entries(void)
   olsr_stop_timer(duplicate_cleanup_timer);
   duplicate_cleanup_timer = NULL;
 
-  OLSR_FOR_ALL_DUP_ENTRIES(entry, true) {
+  OLSR_FOR_ALL_FORWARD_DUP_ENTRIES(entry) {
     olsr_delete_duplicate_entry(entry, true);
-  } OLSR_FOR_ALL_DUP_ENTRIES_END(entry);
-  OLSR_FOR_ALL_DUP_ENTRIES(entry, false) {
+  } OLSR_FOR_ALL_FORWARD_DUP_ENTRIES_END()
+  OLSR_FOR_ALL_PROCESS_DUP_ENTRIES(entry) {
     olsr_delete_duplicate_entry(entry, false);
-  } OLSR_FOR_ALL_DUP_ENTRIES_END(entry);
+  } OLSR_FOR_ALL_PROCESS_DUP_ENTRIES_END()
 }
 
 bool
@@ -275,21 +273,21 @@ olsr_print_duplicate_table(void)
             olsr_wallclock_string());
   OLSR_INFO_NH(LOG_DUPLICATE_SET, "%-*s %8s %s\n", ipwidth, "Node IP", "DupArray", "VTime");
 
-  OLSR_FOR_ALL_DUP_ENTRIES(entry, true) {
+  OLSR_FOR_ALL_FORWARD_DUP_ENTRIES(entry) {
     struct ipaddr_str addrbuf;
     OLSR_INFO_NH(LOG_DUPLICATE_SET, "%-*s %08x %s\n",
                  ipwidth, olsr_ip_to_string(&addrbuf, entry->avl.key), entry->array, olsr_clock_string(entry->valid_until));
-  } OLSR_FOR_ALL_DUP_ENTRIES_END(entry);
+  } OLSR_FOR_ALL_FORWARD_DUP_ENTRIES_END()
 
   OLSR_INFO(LOG_DUPLICATE_SET, "\n--- %s ------------------------------------------------- DUPLICATE SET (processing)\n\n",
             olsr_wallclock_string());
   OLSR_INFO_NH(LOG_DUPLICATE_SET, "%-*s %8s %s\n", ipwidth, "Node IP", "DupArray", "VTime");
 
-  OLSR_FOR_ALL_DUP_ENTRIES(entry, false) {
+  OLSR_FOR_ALL_PROCESS_DUP_ENTRIES(entry) {
     struct ipaddr_str addrbuf;
     OLSR_INFO_NH(LOG_DUPLICATE_SET, "%-*s %08x %s\n",
                  ipwidth, olsr_ip_to_string(&addrbuf, entry->avl.key), entry->array, olsr_clock_string(entry->valid_until));
-  } OLSR_FOR_ALL_DUP_ENTRIES_END(entry);
+  } OLSR_FOR_ALL_PROCESS_DUP_ENTRIES_END()
 #endif
 }
 
index 0ec7af7..9aca646 100644 (file)
@@ -68,7 +68,6 @@ enum duplicate_status {
   TOO_OLD_OLSR_MESSAGE
 };
 
-AVLNODE2STRUCT(duptree2dupentry, struct dup_entry, avl);
 
 int EXPORT(olsr_seqno_diff)(uint16_t reference, uint16_t other);
 void olsr_init_duplicate_set(void);
@@ -76,15 +75,15 @@ bool olsr_is_duplicate_message(union olsr_message *m, bool forward_set, enum dup
 void olsr_print_duplicate_table(void);
 void olsr_flush_duplicate_entries(void);
 
-#define OLSR_FOR_ALL_DUP_ENTRIES(dup, forward) \
-{ \
-  struct avl_node *dup_tree_node, *next_dup_tree_node; \
-  for (dup_tree_node = avl_walk_first(forward ? &forward_set : &processing_set); \
-    dup_tree_node; dup_tree_node = next_dup_tree_node) { \
-    next_dup_tree_node = avl_walk_next(dup_tree_node); \
-    dup = duptree2dupentry(dup_tree_node);
-#define OLSR_FOR_ALL_DUP_ENTRIES_END(dup) }}
+AVLNODE2STRUCT(duptree2dupentry, dup_entry, avl);
 
+#define OLSR_FOR_ALL_FORWARD_DUP_ENTRIES(dup) OLSR_FOR_ALL_AVL_ENTRIES(&forward_set, duptree2dupentry, dup)
+#define OLSR_FOR_ALL_FORWARD_DUP_ENTRIES_END() OLSR_FOR_ALL_AVL_ENTRIES_END()
+
+#define OLSR_FOR_ALL_PROCESS_DUP_ENTRIES(dup) OLSR_FOR_ALL_AVL_ENTRIES(&processing_set, duptree2dupentry, dup)
+#define OLSR_FOR_ALL_PROCESS_DUP_ENTRIES_END() OLSR_FOR_ALL_AVL_ENTRIES_END()
+
+extern struct avl_tree forward_set, processing_set;
 #endif /*DUPLICATE_SET_H_ */
 
 /*
index cd6a294..17fa8e5 100644 (file)
@@ -160,7 +160,7 @@ olsr_flush_hna_nets(struct tc_entry *tc)
   OLSR_DEBUG(LOG_TC, "flush hna nets of '%s' (%u)\n", olsr_ip_to_string(&buf, &tc->addr), tc->edge_tree.count);
   OLSR_FOR_ALL_TC_HNA_ENTRIES(tc, hna_net) {
     olsr_delete_hna_net(hna_net);
-  } OLSR_FOR_ALL_TC_HNA_ENTRIES_END(tc, hna_net);
+  } OLSR_FOR_ALL_TC_HNA_ENTRIES_END()
 }
 
 /**
@@ -245,8 +245,8 @@ olsr_print_hna_set(void)
 
     OLSR_FOR_ALL_TC_HNA_ENTRIES(tc, hna_net) {
       OLSR_INFO_NH(LOG_HNA, "\t%-27s\n", olsr_ip_prefix_to_string(&prefixstr, &hna_net->hna_prefix));
-    } OLSR_FOR_ALL_TC_HNA_ENTRIES_END(tc, hna_net);
-  } OLSR_FOR_ALL_TC_ENTRIES_END(tc);
+    } OLSR_FOR_ALL_TC_HNA_ENTRIES_END();
+  } OLSR_FOR_ALL_TC_ENTRIES_END();
 #endif
 }
 
@@ -259,7 +259,7 @@ olsr_prune_hna_entries(struct tc_entry *tc)
     if (hna_net->tc_entry_seqno != tc->hna_seq) {
       olsr_delete_hna_net(hna_net);
     }
-  } OLSR_FOR_ALL_TC_HNA_ENTRIES_END(tc, hna_net);
+  } OLSR_FOR_ALL_TC_HNA_ENTRIES_END();
 }
 
 /**
index 989e91b..3da20b5 100644 (file)
@@ -56,18 +56,11 @@ struct hna_net {
   uint16_t tc_entry_seqno;             /* sequence number for cleanup */
 };
 
-AVLNODE2STRUCT(hna_tc_tree2hna, struct hna_net, hna_tc_node);
-
 #define OLSR_HNA_NET_JITTER 5   /* percent */
 
-#define OLSR_FOR_ALL_TC_HNA_ENTRIES(tc, hna_net) \
-{ \
-  struct avl_node *hna_net_node, *next_hna_net_node; \
-  for (hna_net_node = avl_walk_first(&tc->hna_tree); \
-    hna_net_node; hna_net_node = next_hna_net_node) { \
-    next_hna_net_node = avl_walk_next(hna_net_node); \
-    hna_net = hna_tc_tree2hna(hna_net_node);
-#define OLSR_FOR_ALL_TC_HNA_ENTRIES_END(tc, hna_net) }}
+AVLNODE2STRUCT(hna_tc_tree2hna, hna_net, hna_tc_node)
+#define OLSR_FOR_ALL_TC_HNA_ENTRIES(tc, hna_set) OLSR_FOR_ALL_AVL_ENTRIES(&tc->hna_tree, hna_tc_tree2hna, hna_set)
+#define OLSR_FOR_ALL_TC_HNA_ENTRIES_END() OLSR_FOR_ALL_AVL_ENTRIES_END()
 
 /* HNA msg input parser */
 void olsr_input_hna(union olsr_message *, struct interface *, union olsr_ip_addr *, enum duplicate_status);
index d4ede2d..0befdd8 100644 (file)
@@ -181,11 +181,11 @@ void destroy_interfaces(void) {
   OLSR_FOR_ALL_INTERFACES(iface) {
     struct interface **ptr = &iface;
     remove_interface(ptr);
-  } OLSR_FOR_ALL_INTERFACES_END(iface)
+  } OLSR_FOR_ALL_INTERFACES_END()
 
   OLSR_FOR_ALL_LOSTIF_ENTRIES(lost) {
     remove_lost_interface_ip(lost);
-  } OLSR_FOR_ALL_LOSTIF_ENTRIES_END(lost);
+  } OLSR_FOR_ALL_LOSTIF_ENTRIES_END();
 }
 
 /**
@@ -224,7 +224,7 @@ check_interface_updates(void *foo __attribute__ ((unused)))
     if (olsr_isTimedOut(lost->valid_until)) {
       remove_lost_interface_ip(lost);
     }
-  } OLSR_FOR_ALL_LOSTIF_ENTRIES_END(lost)
+  } OLSR_FOR_ALL_LOSTIF_ENTRIES_END()
 }
 
 /**
index c730aab..c88b40f 100644 (file)
@@ -189,16 +189,10 @@ struct interface_lost {
   uint32_t valid_until;
 };
 
-AVLNODE2STRUCT(node_tree2lostif, struct interface_lost, node);
+AVLNODE2STRUCT(node_tree2lostif, interface_lost, node);
 
-#define OLSR_FOR_ALL_LOSTIF_ENTRIES(lostif) \
-{ \
-  struct avl_node *lostif_tree_node, *next_lostif_tree_node; \
-  for (lostif_tree_node = avl_walk_first(&interface_lost_tree); \
-    lostif_tree_node; lostif_tree_node = next_lostif_tree_node) { \
-    next_lostif_tree_node = avl_walk_next(lostif_tree_node); \
-    lostif = node_tree2lostif(lostif_tree_node);
-#define OLSR_FOR_ALL_LOSTIF_ENTRIES_END(lostif) }}
+#define OLSR_FOR_ALL_LOSTIF_ENTRIES(lostif) OLSR_FOR_ALL_AVL_ENTRIES(&interface_lost_tree, node_tree2lostif, lostif)
+#define OLSR_FOR_ALL_LOSTIF_ENTRIES_END() OLSR_FOR_ALL_AVL_ENTRIES_END()
 
 #define OLSR_BUFFER_HOLD_JITTER 25      /* percent */
 #define OLSR_BUFFER_HOLD_TIME  100      /* milliseconds */
index 0139772..ee6410d 100644 (file)
@@ -77,7 +77,7 @@ olsr_calculate_lq_mpr(void)
       mpr_changes = true;
     }
 
-  } OLSR_FOR_ALL_NBR_ENTRIES_END(neigh);
+  } OLSR_FOR_ALL_NBR_ENTRIES_END();
 
   /* loop through all 2-hop neighbours */
   OLSR_FOR_ALL_NBR2_ENTRIES(nbr2) {
@@ -110,7 +110,7 @@ olsr_calculate_lq_mpr(void)
           found_better_path = true;
           break;
         }
-      } OLSR_FOR_ALL_NBR_CON_ENTRIES_END(nbr2, walker);
+      } OLSR_FOR_ALL_NBR_CON_ENTRIES_END()
 
       /* we've reached the end of the list, so we haven't found
        * a better route via an MPR - so, skip MPR selection for
@@ -127,7 +127,7 @@ olsr_calculate_lq_mpr(void)
       /* mark all 1-hop neighbours as not selected */
       OLSR_FOR_ALL_NBR2_CON_ENTRIES(nbr2, walker) {
         walker->nbr->skip = false;
-      } OLSR_FOR_ALL_NBR_CON_ENTRIES_END(nbr2, walker);
+      } OLSR_FOR_ALL_NBR_CON_ENTRIES_END();
 
       for (k = 0; k < olsr_cnf->mpr_coverage; k++) {
 
@@ -140,7 +140,7 @@ olsr_calculate_lq_mpr(void)
             neigh = walker->nbr;
             best = walker->path_linkcost;
           }
-        } OLSR_FOR_ALL_NBR2_CON_ENTRIES_END(nbr2, walker);
+        } OLSR_FOR_ALL_NBR2_CON_ENTRIES_END();
 
         /*
          * Found a 1-hop neighbor that we haven't previously selected.
@@ -162,7 +162,7 @@ olsr_calculate_lq_mpr(void)
           break;
         }
       }
-  } OLSR_FOR_ALL_NBR2_ENTRIES_END(nbr2);
+  } OLSR_FOR_ALL_NBR2_ENTRIES_END();
 
   /* ugly hack */
   OLSR_FOR_ALL_LINK_ENTRIES(lnk) {
index 7ebbd91..66d2e52 100644 (file)
@@ -518,7 +518,7 @@ olsr_shutdown(void)
   /* Flush MID database */
   OLSR_FOR_ALL_MID_ENTRIES(mid) {
     olsr_delete_mid_entry(mid);
-  } OLSR_FOR_ALL_MID_ENTRIES_END(mid);
+  } OLSR_FOR_ALL_MID_ENTRIES_END();
 
   OLSR_INFO(LOG_MAIN, "Closing sockets...\n");
 
index fef84fe..28bf4be 100644 (file)
@@ -56,26 +56,13 @@ struct mid_entry {
   uint16_t mid_entry_seqno;            /* msg seq number for change tracking */
 };
 
-AVLNODE2STRUCT(global_tree2mid, struct mid_entry, mid_node);
-AVLNODE2STRUCT(alias_tree2mid, struct mid_entry, mid_tc_node);
+AVLNODE2STRUCT(global_tree2mid, mid_entry, mid_node);
+#define OLSR_FOR_ALL_MID_ENTRIES(mid_alias) OLSR_FOR_ALL_AVL_ENTRIES(&mid_tree, global_tree2mid, mid_alias)
+#define OLSR_FOR_ALL_MID_ENTRIES_END() OLSR_FOR_ALL_AVL_ENTRIES_END()
 
-#define OLSR_FOR_ALL_MID_ENTRIES(mid_alias) \
-{ \
-  struct avl_node *mid_alias_node, *next_mid_alias_node; \
-  for (mid_alias_node = avl_walk_first(&mid_tree); \
-    mid_alias_node; mid_alias_node = next_mid_alias_node) { \
-    next_mid_alias_node = avl_walk_next(mid_alias_node); \
-    mid_alias = global_tree2mid(mid_alias_node);
-#define OLSR_FOR_ALL_MID_ENTRIES_END(mid_alias) }}
-
-#define OLSR_FOR_ALL_TC_MID_ENTRIES(tc, mid_alias) \
-{ \
-  struct avl_node *mid_alias_node, *next_mid_alias_node; \
-  for (mid_alias_node = avl_walk_first(&tc->mid_tree); \
-    mid_alias_node; mid_alias_node = next_mid_alias_node) { \
-    next_mid_alias_node = avl_walk_next(mid_alias_node); \
-    mid_alias = alias_tree2mid(mid_alias_node);
-#define OLSR_FOR_ALL_TC_MID_ENTRIES_END(tc, mid_alias) }}
+AVLNODE2STRUCT(alias_tree2mid, mid_entry, mid_tc_node);
+#define OLSR_FOR_ALL_TC_MID_ENTRIES(tc, mid_alias) OLSR_FOR_ALL_AVL_ENTRIES(&tc->mid_tree, alias_tree2mid, mid_alias)
+#define OLSR_FOR_ALL_TC_MID_ENTRIES_END(tc, mid_alias) OLSR_FOR_ALL_AVL_ENTRIES_END()
 
 #define OLSR_MID_JITTER 5       /* percent */
 
index c530156..24ecff1 100644 (file)
@@ -158,7 +158,7 @@ olsr_delete_nbr_entry(struct nbr_entry *nbr)
     if (nbr2->con_tree.count == 0) {
       olsr_delete_nbr2_entry(nbr2);
     }
-  } OLSR_FOR_ALL_NBR_CON_ENTRIES_END(nbr, connector);
+  } OLSR_FOR_ALL_NBR_CON_ENTRIES_END()
 
   /* Remove from global neighbor tree */
   avl_delete(&nbr_tree, &nbr->nbr_node);
@@ -298,7 +298,7 @@ olsr_delete_nbr2_entry(struct nbr2_entry *nbr2) {
    */
   OLSR_FOR_ALL_NBR2_CON_ENTRIES(nbr2, connector) {
     olsr_delete_nbr_con(connector);
-  } OLSR_FOR_ALL_NBR2_CON_ENTRIES_END(nbr2, connector);
+  } OLSR_FOR_ALL_NBR2_CON_ENTRIES_END();
 
   /* Remove from global neighbor tree */
   avl_delete(&nbr2_tree, &nbr2->nbr2_node);
@@ -478,7 +478,7 @@ olsr_print_neighbor_table(void)
                  nbr->is_mpr ? "YES" : "NO",
                  nbr->mprs_count == 0  ? "NO  " : "YES ",
                  nbr->willingness);
-  } OLSR_FOR_ALL_NBR_ENTRIES_END(nbr);
+  } OLSR_FOR_ALL_NBR_ENTRIES_END();
 
   OLSR_INFO(LOG_2NEIGH, "\n--- %s ----------------------- TWO-HOP NEIGHBORS\n\n"
             "IP addr (2-hop)  IP addr (1-hop)  Total cost\n", olsr_wallclock_string());
@@ -492,8 +492,8 @@ olsr_print_neighbor_table(void)
                    olsr_get_linkcost_text(connector->path_linkcost, false, lqbuffer, sizeof(lqbuffer)));
 
       first = false;
-    } OLSR_FOR_ALL_NBR2_CON_ENTRIES_END(nbr2, connector);
-  } OLSR_FOR_ALL_NBR2_ENTRIES_END(nbr2);
+    } OLSR_FOR_ALL_NBR2_CON_ENTRIES_END()
+  } OLSR_FOR_ALL_NBR2_ENTRIES_END()
 
 #endif
 }
index deb6b61..e7ff7de 100644 (file)
@@ -67,8 +67,6 @@ struct nbr_con {
   olsr_linkcost saved_path_linkcost;
 };
 
-AVLNODE2STRUCT(nbr_con_node_to_connector, struct nbr_con, nbr_tree_node);
-AVLNODE2STRUCT(nbr2_con_node_to_connector, struct nbr_con, nbr2_tree_node);
 
 #define OLSR_NBR2_LIST_JITTER 5 /* percent */
 
@@ -85,7 +83,6 @@ struct nbr_entry {
   struct avl_tree con_tree;            /* subtree for connectors to nbr2 */
 };
 
-AVLNODE2STRUCT(nbr_node_to_nbr, struct nbr_entry, nbr_node);
 
 struct nbr2_entry {
   struct avl_node nbr2_node;
@@ -95,7 +92,6 @@ struct nbr2_entry {
   struct avl_tree con_tree;            /* subtree for connectors to nbr */
 };
 
-AVLNODE2STRUCT(nbr2_node_to_nbr2, struct nbr2_entry, nbr2_node);
 
 /*
  * macros for traversing neighbors, neighbor2 and connectors.
@@ -105,23 +101,13 @@ AVLNODE2STRUCT(nbr2_node_to_nbr2, struct nbr2_entry, nbr2_node);
  * the loop prefetches the next node in order to not loose context if
  * for example the caller wants to delete the current entry.
  */
-#define OLSR_FOR_ALL_NBR_ENTRIES(nbr) \
-{ \
-  struct avl_node *nbr_tree_node, *next_nbr_tree_node; \
-  for (nbr_tree_node = avl_walk_first(&nbr_tree); \
-    nbr_tree_node; nbr_tree_node = next_nbr_tree_node) { \
-    next_nbr_tree_node = avl_walk_next(nbr_tree_node); \
-    nbr = nbr_node_to_nbr(nbr_tree_node);
-#define OLSR_FOR_ALL_NBR_ENTRIES_END(nbr) }}
-
-#define OLSR_FOR_ALL_NBR_CON_ENTRIES(nbr, nbr_con) \
-{ \
-  struct avl_node *nbr_con_node, *next_nbr_con_node; \
-  for (nbr_con_node = avl_walk_first(&nbr->con_tree); \
-    nbr_con_node; nbr_con_node = next_nbr_con_node) { \
-    next_nbr_con_node = avl_walk_next(nbr_con_node); \
-    nbr_con = nbr_con_node_to_connector(nbr_con_node);
-#define OLSR_FOR_ALL_NBR_CON_ENTRIES_END(nbr, nbr_con) }}
+AVLNODE2STRUCT(nbr_node_to_nbr, nbr_entry, nbr_node);
+#define OLSR_FOR_ALL_NBR_ENTRIES(nbr) OLSR_FOR_ALL_AVL_ENTRIES(&nbr_tree, nbr_node_to_nbr, nbr)
+#define OLSR_FOR_ALL_NBR_ENTRIES_END() OLSR_FOR_ALL_AVL_ENTRIES_END()
+
+AVLNODE2STRUCT(nbr_con_node_to_connector, nbr_con, nbr_tree_node);
+#define OLSR_FOR_ALL_NBR_CON_ENTRIES(nbr, con) OLSR_FOR_ALL_AVL_ENTRIES(&nbr->con_tree, nbr_con_node_to_connector, con)
+#define OLSR_FOR_ALL_NBR_CON_ENTRIES_END() OLSR_FOR_ALL_AVL_ENTRIES_END()
 
 /*
  * macros for traversing two-hop neighbors and neighbor ref lists.
@@ -131,23 +117,13 @@ AVLNODE2STRUCT(nbr2_node_to_nbr2, struct nbr2_entry, nbr2_node);
  * the loop prefetches the next node in order to not loose context if
  * for example the caller wants to delete the current entry.
  */
-#define OLSR_FOR_ALL_NBR2_ENTRIES(nbr2) \
-{ \
-  struct avl_node *nbr2_tree_node, *next_nbr2_tree_node; \
-  for (nbr2_tree_node = avl_walk_first(&nbr2_tree); \
-    nbr2_tree_node; nbr2_tree_node = next_nbr2_tree_node) { \
-    next_nbr2_tree_node = avl_walk_next(nbr2_tree_node); \
-    nbr2 = nbr2_node_to_nbr2(nbr2_tree_node);
-#define OLSR_FOR_ALL_NBR2_ENTRIES_END(nbr2) }}
-
-#define OLSR_FOR_ALL_NBR2_CON_ENTRIES(nbr2, nbr_con) \
-{ \
-  struct avl_node *nbr_con_node, *next_nbr_con_node; \
-  for (nbr_con_node = avl_walk_first(&nbr2->con_tree); \
-    nbr_con_node; nbr_con_node = next_nbr_con_node) { \
-    next_nbr_con_node = avl_walk_next(nbr_con_node); \
-    nbr_con = nbr2_con_node_to_connector(nbr_con_node);
-#define OLSR_FOR_ALL_NBR2_CON_ENTRIES_END(nbr2, nbr_con) }}
+AVLNODE2STRUCT(nbr2_node_to_nbr2, nbr2_entry, nbr2_node);
+#define OLSR_FOR_ALL_NBR2_ENTRIES(nbr2) OLSR_FOR_ALL_AVL_ENTRIES(&nbr2_tree, nbr2_node_to_nbr2, nbr2)
+#define OLSR_FOR_ALL_NBR2_ENTRIES_END(nbr2) OLSR_FOR_ALL_AVL_ENTRIES_END()
+
+AVLNODE2STRUCT(nbr2_con_node_to_connector, nbr_con, nbr2_tree_node);
+#define OLSR_FOR_ALL_NBR2_CON_ENTRIES(nbr2, con) OLSR_FOR_ALL_AVL_ENTRIES(&nbr2->con_tree, nbr2_con_node_to_connector, con)
+#define OLSR_FOR_ALL_NBR2_CON_ENTRIES_END() OLSR_FOR_ALL_AVL_ENTRIES_END()
 
 /*
  * The one hop neighbor and two hop neighbor trees.
index 28a4f45..562dfea 100644 (file)
@@ -120,7 +120,7 @@ deinit_netfilters(void)
   OLSR_FOR_ALL_FILTERS(filter) {
     avl_delete(&filter_tree, &filter->filter_node);
     free(filter);
-  } OLSR_FOR_ALL_FILTERS_END(filter);
+  } OLSR_FOR_ALL_FILTERS_END();
 }
 
 /**
index 7d26fe3..e386efd 100644 (file)
@@ -61,16 +61,9 @@ struct filter_entry {
   union olsr_ip_addr filter_addr;
 };
 
-AVLNODE2STRUCT(filter_tree2filter, struct filter_entry, filter_node);
-
-#define OLSR_FOR_ALL_FILTERS(filter) \
-{ \
-  struct avl_node *filter_tree_node, *next_filter_tree_node; \
-  for (filter_tree_node = avl_walk_first(&filter_tree); \
-    filter_tree_node; filter_tree_node = next_filter_tree_node) { \
-    next_filter_tree_node = avl_walk_next(filter_tree_node); \
-    filter = filter_tree2filter(filter_tree_node);
-#define OLSR_FOR_ALL_FILTERS_END(filter) }}
+AVLNODE2STRUCT(filter_tree2filter, filter_entry, filter_node);
+#define OLSR_FOR_ALL_FILTERS(filter) OLSR_FOR_ALL_AVL_ENTRIES(&filter_tree, filter_tree2filter, filter)
+#define OLSR_FOR_ALL_FILTERS_END() OLSR_FOR_ALL_AVL_ENTRIES_END()
 
 void init_net(void);
 
index 4c4ca93..29deb8d 100644 (file)
@@ -89,7 +89,7 @@ void olsr_com_destroy_http(void) {
   struct olsr_html_site *site;
   OLSR_FOR_ALL_HTML_ENTRIES(site) {
     olsr_com_remove_htmlsite(site);
-  } OLSR_FOR_ALL_HTML_ENTRIES_END(site)
+  } OLSR_FOR_ALL_HTML_ENTRIES_END()
 }
 
 struct olsr_html_site *
index d690bcc..e903f67 100644 (file)
@@ -66,16 +66,9 @@ struct olsr_html_site {
   void (*sitehandler)(struct autobuf *buf, char *path, int parameter_count, char *parameters[]);
 };
 
-AVLNODE2STRUCT(html_tree2site, struct olsr_html_site, node);
-
-#define OLSR_FOR_ALL_HTML_ENTRIES(site) \
-{ \
-  struct avl_node *site_node, *next_site_node; \
-  for (site_node = avl_walk_first(&http_handler_tree); \
-    site_node; site_node = next_site_node) { \
-    next_site_node = avl_walk_next(site_node); \
-    site = html_tree2site(site_node);
-#define OLSR_FOR_ALL_HTML_ENTRIES_END(site) }}
+AVLNODE2STRUCT(html_tree2site, olsr_html_site, node);
+#define OLSR_FOR_ALL_HTML_ENTRIES(site) OLSR_FOR_ALL_AVL_ENTRIES(&http_handler_tree, html_tree2site, site)
+#define OLSR_FOR_ALL_HTML_ENTRIES_END() OLSR_FOR_ALL_AVL_ENTRIES_END()
 
 void olsr_com_init_http(void);
 void olsr_com_destroy_http(void);
index 169dadb..e1e75b5 100644 (file)
@@ -351,10 +351,10 @@ olsr_txtcmd_plugin(struct comport_connection *con, char *cmd, char *param) {
     }
     OLSR_FOR_ALL_PLUGIN_ENTRIES(plugin) {
       if (abuf_appendf(&con->out, " %-30s\t%s\t%s\n",
-          plugin->p_name, plugin->active ? "active" : "", plugin->dlhandle == NULL ? "static" : "") < 0) {
+          plugin->name, plugin->internal_active ? "active" : "", plugin->internal_dlhandle == NULL ? "static" : "") < 0) {
         return ABUF_ERROR;
       }
-    } OLSR_FOR_ALL_PLUGIN_ENTRIES_END(plugin)
+    } OLSR_FOR_ALL_PLUGIN_ENTRIES_END()
     return CONTINUE;
   }
 
@@ -390,7 +390,7 @@ olsr_txtcmd_plugin(struct comport_connection *con, char *cmd, char *param) {
     return CONTINUE;
   }
   if (strcasecmp(param, "activate") == 0) {
-    if (plugin->active) {
+    if (plugin->internal_active) {
       abuf_appendf(&con->out, "Plugin %s already active\n", para2);
     }
     else if (olsr_activate_plugin(plugin)) {
@@ -401,7 +401,7 @@ olsr_txtcmd_plugin(struct comport_connection *con, char *cmd, char *param) {
     }
   }
   else if (strcasecmp(param, "deactivate") == 0) {
-    if (!plugin->active) {
+    if (!plugin->internal_active) {
       abuf_appendf(&con->out, "Plugin %s is not active\n", para2);
     }
     else if (olsr_deactivate_plugin(plugin)) {
@@ -412,7 +412,7 @@ olsr_txtcmd_plugin(struct comport_connection *con, char *cmd, char *param) {
     }
   }
   else if (strcasecmp(param, "unload") == 0) {
-    if (plugin->dlhandle == NULL) {
+    if (plugin->internal_dlhandle == NULL) {
       abuf_appendf(&con->out, "Plugin %s is static and cannot be unloaded\n", para2);
     }
     else if (olsr_unload_plugin(plugin)) {
index 1bee8ad..1953e98 100644 (file)
@@ -65,7 +65,7 @@ struct olsr_txtcommand {
   olsr_txthandler handler;
 };
 
-AVLNODE2STRUCT(txt_tree2cmd, struct olsr_txtcommand, node);
+AVLNODE2STRUCT(txt_tree2cmd, olsr_txtcommand, node);
 
 void olsr_com_init_txt(void);
 void olsr_com_destroy_txt(void);
index 925635e..c3d8a54 100644 (file)
@@ -142,7 +142,7 @@ olsr_delete_all_cookies(void)
    */
   OLSR_FOR_ALL_COOKIES(info) {
     olsr_free_cookie(info);
-  } OLSR_FOR_ALL_COOKIES_END(info)
+  } OLSR_FOR_ALL_COOKIES_END()
 }
 
 /*
index 1c21c6e..1573bc7 100644 (file)
@@ -75,16 +75,9 @@ struct olsr_cookie_info {
   uint16_t ci_membrand;
 };
 
-AVLNODE2STRUCT(cookie_node2cookie, struct olsr_cookie_info, node);
-
-#define OLSR_FOR_ALL_COOKIES(ci) \
-{ \
-  struct avl_node *ci_tree_node, *next_ci_tree_node; \
-  for (ci_tree_node = avl_walk_first(&olsr_cookie_tree); \
-    ci_tree_node; ci_tree_node = next_ci_tree_node) { \
-    next_ci_tree_node = avl_walk_next(ci_tree_node); \
-    ci = cookie_node2cookie(ci_tree_node);
-#define OLSR_FOR_ALL_COOKIES_END(ci) }}
+AVLNODE2STRUCT(cookie_node2cookie, olsr_cookie_info, node);
+#define OLSR_FOR_ALL_COOKIES(ci) OLSR_FOR_ALL_AVL_ENTRIES(&olsr_cookie_tree, cookie_node2cookie, ci)
+#define OLSR_FOR_ALL_COOKIES_END() OLSR_FOR_ALL_AVL_ENTRIES_END()
 
 /* Cookie flags */
 #define COOKIE_NO_MEMCLEAR  ( 1 << 0)   /* Do not clear memory */
index 8c7ae41..8fce155 100644 (file)
@@ -95,7 +95,7 @@ int olsrd_plugin_register_param(char *key, char *value);
 /**
  * Delivers the (address of the) table and the size of the parameter description
  */
-void olsrd_get_plugin_parameters(const struct olsrd_plugin_parameters **params, int *size);
+void olsrd_get_plugin_parameters(const struct olsrd_plugin_parameters **internal_params, int *size);
 
 #endif
 
index 833666b..a238a9f 100644 (file)
@@ -52,6 +52,7 @@
 #include <dlfcn.h>
 #include <errno.h>
 #include <stdlib.h>
+#include <assert.h>
 
 /* Local functions */
 static struct olsr_plugin *olsr_load_legacy_plugin(const char *, void *);
@@ -72,12 +73,13 @@ static bool olsr_internal_unload_plugin(struct olsr_plugin *plugin, bool cleanup
  */
 void
 olsr_hookup_plugin(struct olsr_plugin *pl_def) {
-  fprintf(stdout, "hookup %s\n", pl_def->p_name);
+  assert (pl_def->name);
+  fprintf(stdout, "hookup %s\n", pl_def->name);
   if (!plugin_tree_initialized) {
     avl_init(&plugin_tree, avl_comp_strcasecmp);
     plugin_tree_initialized = true;
   }
-  pl_def->p_node.key = strdup(pl_def->p_name);
+  pl_def->p_node.key = strdup(pl_def->name);
   avl_insert(&plugin_tree, &pl_def->p_node, AVL_DUP_NO);
 }
 
@@ -128,7 +130,7 @@ olsr_init_pluginsystem(bool fail_fast) {
       OLSR_WARN(LOG_PLUGINS, "Internal error in plugin storage tree, cannot find plugin %s\n", entry->name);
     }
 
-    plugin->params = entry->params;
+    plugin->internal_params = entry->params;
   }
 
   /* activate all plugins (configured and static linked ones) */
@@ -198,15 +200,15 @@ olsr_load_legacy_plugin(const char *libname, void *dlhandle) {
   plugin = (struct olsr_plugin *)olsr_cookie_malloc(plugin_mem_cookie);
   /* SOT: Hacked away the funny plugin check which fails if pathname is included */
   if (strrchr(libname, '/')) libname = strrchr(libname, '/') + 1;
-  plugin->p_name = libname;
-  plugin->p_version = plugin_interface_version;
-  plugin->p_legacy_init = init_plugin;
+  plugin->name = libname;
+  plugin->internal_version = plugin_interface_version;
+  plugin->internal_legacy_init = init_plugin;
 
-  plugin->p_node.key = strdup(plugin->p_name);
-  plugin->dlhandle = dlhandle;
+  plugin->p_node.key = strdup(plugin->name);
+  plugin->internal_dlhandle = dlhandle;
 
   /* get parameters */
-  get_plugin_parameters(&plugin->p_param, &plugin->p_param_cnt);
+  get_plugin_parameters(&plugin->internal_param, &plugin->internal_param_cnt);
 
   avl_insert(&plugin_tree, &plugin->p_node, AVL_DUP_NO);
   return plugin;
@@ -249,7 +251,7 @@ olsr_load_plugin(const char *libname)
 
   /* version 6 plugins should be in the tree now*/
   if ((plugin = olsr_get_plugin(libname)) != NULL) {
-    plugin->dlhandle = dlhandle;
+    plugin->internal_dlhandle = dlhandle;
     return plugin;
   }
 
@@ -261,26 +263,26 @@ static bool
 olsr_internal_unload_plugin(struct olsr_plugin *plugin, bool cleanup) {
   bool legacy = false;
 
-  if (plugin->active) {
+  if (plugin->internal_active) {
     olsr_deactivate_plugin(plugin);
   }
 
-  if (plugin->dlhandle == NULL && !cleanup) {
+  if (plugin->internal_dlhandle == NULL && !cleanup) {
     /* this is a static plugin, it cannot be unloaded */
     return true;
   }
 
-  OLSR_INFO(LOG_PLUGINS, "Unloading plugin %s\n", plugin->p_name);
+  OLSR_INFO(LOG_PLUGINS, "Unloading plugin %s\n", plugin->name);
 
   /* remove first from tree */
   avl_delete(&plugin_tree, &plugin->p_node);
   free(plugin->p_node.key);
 
-  legacy = plugin->p_version == 5;
+  legacy = plugin->internal_version == 5;
 
   /* cleanup */
-  if (plugin->dlhandle) {
-    dlclose(plugin->dlhandle);
+  if (plugin->internal_dlhandle) {
+    dlclose(plugin->internal_dlhandle);
   }
 
   /*
@@ -302,29 +304,29 @@ bool olsr_activate_plugin(struct olsr_plugin *plugin) {
   struct plugin_param *params;
   unsigned int i;
 
-  if (plugin->active) {
-    OLSR_DEBUG(LOG_PLUGINS, "Plugin %s is already active.\n", plugin->p_name);
+  if (plugin->internal_active) {
+    OLSR_DEBUG(LOG_PLUGINS, "Plugin %s is already active.\n", plugin->name);
     return false;
   }
 
-  if (plugin->p_pre_init != NULL) {
-    if (plugin->p_pre_init()) {
-      OLSR_WARN(LOG_PLUGINS, "Error, pre init failed for plugin %s\n", plugin->p_name);
+  if (plugin->pre_init != NULL) {
+    if (plugin->pre_init()) {
+      OLSR_WARN(LOG_PLUGINS, "Error, pre init failed for plugin %s\n", plugin->name);
       return true;
     }
-    OLSR_DEBUG(LOG_PLUGINS, "Pre initialization of plugin %s successful\n", plugin->p_name);
+    OLSR_DEBUG(LOG_PLUGINS, "Pre initialization of plugin %s successful\n", plugin->name);
   }
 
   /* initialize parameters */
-  OLSR_INFO(LOG_PLUGINS, "Activating plugin %s\n", plugin->p_name);
-  for (params = plugin->params; params != NULL; params = params->next) {
+  OLSR_INFO(LOG_PLUGINS, "Activating plugin %s\n", plugin->name);
+  for (params = plugin->internal_params; params != NULL; params = params->next) {
     OLSR_INFO_NH(LOG_PLUGINS, "    \"%s\" = \"%s\"... ", params->key, params->value);
 
-    for (i = 0; i < plugin->p_param_cnt; i++) {
-      if (0 == plugin->p_param[i].name[0] || 0 == strcasecmp(plugin->p_param[i].name, params->key)) {
+    for (i = 0; i < plugin->internal_param_cnt; i++) {
+      if (0 == plugin->internal_param[i].name[0] || 0 == strcasecmp(plugin->internal_param[i].name, params->key)) {
         /* we have found it! */
-        if (plugin->p_param[i].set_plugin_parameter(params->value, plugin->p_param[i].data,
-            0 == plugin->p_param[i].name[0] ? (set_plugin_parameter_addon) params->key : plugin->p_param[i].addon)) {
+        if (plugin->internal_param[i].set_plugin_parameter(params->value, plugin->internal_param[i].data,
+            0 == plugin->internal_param[i].name[0] ? (set_plugin_parameter_addon) params->key : plugin->internal_param[i].addon)) {
           OLSR_DEBUG(LOG_PLUGINS, "Bad plugin parameter \"%s\" = \"%s\"... ", params->key, params->value);
           return true;
         }
@@ -332,58 +334,58 @@ bool olsr_activate_plugin(struct olsr_plugin *plugin) {
       }
     }
 
-    if (i == plugin->p_param_cnt) {
+    if (i == plugin->internal_param_cnt) {
       OLSR_INFO_NH(LOG_PLUGINS, "    Ignored parameter \"%s\"\n", params->key);
     }
   }
 
-  if (plugin->p_post_init != NULL) {
-    if (plugin->p_post_init()) {
-      OLSR_WARN(LOG_PLUGINS, "Error, post init failed for plugin %s\n", plugin->p_name);
+  if (plugin->post_init != NULL) {
+    if (plugin->post_init()) {
+      OLSR_WARN(LOG_PLUGINS, "Error, post init failed for plugin %s\n", plugin->name);
       return true;
     }
-    OLSR_DEBUG(LOG_PLUGINS, "Post initialization of plugin %s successful\n", plugin->p_name);
+    OLSR_DEBUG(LOG_PLUGINS, "Post initialization of plugin %s successful\n", plugin->name);
   }
-  if (plugin->p_legacy_init != NULL) {
-    if (plugin->p_legacy_init() != 1) {
-      OLSR_WARN(LOG_PLUGINS, "Error, legacy init failed for plugin %s\n", plugin->p_name);
+  if (plugin->internal_legacy_init != NULL) {
+    if (plugin->internal_legacy_init() != 1) {
+      OLSR_WARN(LOG_PLUGINS, "Error, legacy init failed for plugin %s\n", plugin->name);
       return true;
     }
-    OLSR_DEBUG(LOG_PLUGINS, "Post initialization of plugin %s successful\n", plugin->p_name);
+    OLSR_DEBUG(LOG_PLUGINS, "Post initialization of plugin %s successful\n", plugin->name);
   }
-  plugin->active = true;
+  plugin->internal_active = true;
 
-  if (plugin->p_author != NULL && plugin->p_descr != NULL) {
+  if (plugin->author != NULL && plugin->descr != NULL) {
     OLSR_INFO(LOG_PLUGINS, "Plugin '%s' (%s) by %s activated sucessfully\n",
-        plugin->p_descr, plugin->p_name, plugin->p_author);
+        plugin->descr, plugin->name, plugin->author);
   }
   else {
     OLSR_INFO(LOG_PLUGINS, "%sPlugin '%s' activated sucessfully\n",
-        plugin->p_version != 6 ? "Legacy " : "", plugin->p_name);
+        plugin->internal_version != 6 ? "Legacy " : "", plugin->name);
   }
 
   return false;
 }
 
 bool olsr_deactivate_plugin(struct olsr_plugin *plugin) {
-  if (!plugin->active) {
-    OLSR_DEBUG(LOG_PLUGINS, "Plugin %s is not active.\n", plugin->p_name);
+  if (!plugin->internal_active) {
+    OLSR_DEBUG(LOG_PLUGINS, "Plugin %s is not active.\n", plugin->name);
     return false;
   }
 
-  OLSR_INFO(LOG_PLUGINS, "Deactivating plugin %s\n", plugin->p_name);
-  if (plugin->p_pre_cleanup != NULL) {
-    if (plugin->p_pre_cleanup()) {
-      OLSR_DEBUG(LOG_PLUGINS, "Plugin %s cannot be deactivated, error in pre cleanup\n", plugin->p_name);
+  OLSR_INFO(LOG_PLUGINS, "Deactivating plugin %s\n", plugin->name);
+  if (plugin->pre_cleanup != NULL) {
+    if (plugin->pre_cleanup()) {
+      OLSR_DEBUG(LOG_PLUGINS, "Plugin %s cannot be deactivated, error in pre cleanup\n", plugin->name);
       return true;
     }
-    OLSR_DEBUG(LOG_PLUGINS, "Pre cleanup of plugin %s successful\n", plugin->p_name);
+    OLSR_DEBUG(LOG_PLUGINS, "Pre cleanup of plugin %s successful\n", plugin->name);
   }
 
-  plugin->active = false;
+  plugin->internal_active = false;
 
-  if (plugin->p_post_cleanup != NULL) {
-    plugin->p_post_cleanup();
+  if (plugin->post_cleanup != NULL) {
+    plugin->post_cleanup();
   }
 
   return false;
index 947ab50..7ae38e3 100644 (file)
 #include "common/avl.h"
 #include "common/list.h"
 
-#define DEFINE_PLUGIN6(descr, author, pre_init, post_init, pre_cleanup, post_cleanup, deactivate, parameter) \
-static struct olsr_plugin olsr_internal_plugin_definition = { \
-  .p_name = PLUGIN_FULLNAME , .p_descr = descr, .p_author = author, \
-  .p_pre_init = pre_init, .p_post_init = post_init, .p_pre_cleanup = pre_cleanup, .p_post_cleanup = post_cleanup, \
-  .p_legacy_init = NULL, .p_deactivate = deactivate, .p_version = 6, .p_param = parameter, .p_param_cnt = ARRAYSIZE(parameter) \
-}; \
+#define OLSR_PLUGIN6_NP()   static struct olsr_plugin olsr_internal_plugin_definition; \
 static void hookup_plugin_definition (void) __attribute__ ((constructor)); \
 static void hookup_plugin_definition (void) { \
+  static const char *plname = PLUGIN_FULLNAME; \
+  olsr_internal_plugin_definition.name = plname; \
   olsr_hookup_plugin(&olsr_internal_plugin_definition); \
-}
-
-#define DEFINE_PLUGIN6_NP(descr, author, pre_init, post_init, pre_cleanup, post_cleanup, deactivate) \
-static struct olsr_plugin olsr_internal_plugin_definition = { \
-  .p_name = PLUGIN_FULLNAME , .p_descr = descr, .p_author = author, \
-  .p_pre_init = pre_init, .p_post_init = post_init, .p_pre_cleanup = pre_cleanup, .p_post_cleanup = post_cleanup, \
-  .p_deactivate = deactivate, .p_version = 6, .p_param = NULL, .p_param_cnt = 0 \
-}; \
+} \
+static struct olsr_plugin olsr_internal_plugin_definition =
+
+#define OLSR_PLUGIN6(param) static struct olsr_plugin olsr_internal_plugin_definition; \
 static void hookup_plugin_definition (void) __attribute__ ((constructor)); \
 static void hookup_plugin_definition (void) { \
+  static const char *plname = PLUGIN_FULLNAME; \
+  olsr_internal_plugin_definition.name = plname; \
+  olsr_internal_plugin_definition.internal_param = param; \
+  olsr_internal_plugin_definition.internal_param_cnt = ARRAYSIZE(param); \
   olsr_hookup_plugin(&olsr_internal_plugin_definition); \
-}
+} \
+static struct olsr_plugin olsr_internal_plugin_definition =
 
 /* version 5 */
 typedef int (*plugin_init_func) (void);
 typedef int (*get_interface_version_func) (void);
-typedef void (*get_plugin_parameters_func) (const struct olsrd_plugin_parameters ** params, unsigned int *size);
+typedef void (*get_plugin_parameters_func) (const struct olsrd_plugin_parameters ** internal_params, unsigned int *size);
 
 struct olsr_plugin {
   struct avl_node p_node;
 
   /* plugin information */
-  const char *p_name;
-  const char *p_descr;
-  const char *p_author;
-  bool p_deactivate;    /* plugin can be deactivated */
+  const char *name;
+  const char *descr;
+  const char *author;
+  bool deactivate;    /* plugin can be deactivated */
 
   /* function pointers */
-  bool (*p_pre_init) (void);
-  bool (*p_post_init) (void);
-  bool (*p_pre_cleanup) (void);
-  bool (*p_post_cleanup) (void);
-  int  (*p_legacy_init) (void);
+  bool (*pre_init) (void);
+  bool (*post_init) (void);
+  bool (*pre_cleanup) (void);
+  bool (*post_cleanup) (void);
+  int  (*internal_legacy_init) (void);
 
   /* plugin interface version */
-  int p_version;
+  int internal_version;
 
   /* plugin list of possible arguments */
-  const struct olsrd_plugin_parameters *p_param;
+  const struct olsrd_plugin_parameters *internal_param;
 
   /* number of arguments */
-  unsigned int p_param_cnt;
+  unsigned int internal_param_cnt;
 
   /* internal olsr data */
-  void *dlhandle;
-  struct plugin_param *params;
-  bool active;
+  void *internal_dlhandle;
+  struct plugin_param *internal_params;
+  bool internal_active;
 };
 
-AVLNODE2STRUCT(plugin_node2tree, struct olsr_plugin, p_node)
-
-#define OLSR_FOR_ALL_PLUGIN_ENTRIES(plugin) \
-{ \
-  struct avl_node *plugin_node, *next_plugin_node; \
-  for (plugin_node = avl_walk_first(&plugin_tree); \
-    plugin_node; plugin_node = next_plugin_node) { \
-    next_plugin_node = avl_walk_next(plugin_node); \
-    plugin = plugin_node2tree(plugin_node);
-#define OLSR_FOR_ALL_PLUGIN_ENTRIES_END(plugin) }}
+AVLNODE2STRUCT(plugin_node2tree, olsr_plugin, p_node)
+#define OLSR_FOR_ALL_PLUGIN_ENTRIES(plugin) OLSR_FOR_ALL_AVL_ENTRIES(&plugin_tree, plugin_node2tree, plugin)
+#define OLSR_FOR_ALL_PLUGIN_ENTRIES_END(plugin) OLSR_FOR_ALL_AVL_ENTRIES_END()
 
 struct olsr_plugin *EXPORT(olsr_get_plugin)(const char *libname);
 
index b1be815..b14d32b 100644 (file)
@@ -318,7 +318,7 @@ olsr_update_rib_routes(void)
     if (!rt->rt_path_tree.count) {
 
       /* oops, all routes are gone - flush the route head */
-      avl_delete(&routingtree, rt_tree_node);
+      avl_delete(&routingtree, &rt->rt_tree_node);
 
       olsr_enqueue_rt(&del_kernel_list, rt);
       continue;
@@ -342,7 +342,7 @@ olsr_update_rib_routes(void)
       }
     }
   }
-  OLSR_FOR_ALL_RT_ENTRIES_END(rt);
+  OLSR_FOR_ALL_RT_ENTRIES_END();
 }
 
 /**
index 52d73e7..a1c6655 100644 (file)
@@ -91,7 +91,6 @@ struct rt_entry {
   struct list_node rt_change_node;     /* queue for kernel FIB add/chg/del */
 };
 
-AVLNODE2STRUCT(rt_tree2rt, struct rt_entry, rt_tree_node);
 LISTNODE2STRUCT(changelist2rt, struct rt_entry, rt_change_node);
 
 /*
@@ -114,8 +113,8 @@ struct rt_path {
   uint32_t rtp_version;                /* for detection of outdated rt_paths */
 };
 
-AVLNODE2STRUCT(rtp_tree2rtp, struct rt_path, rtp_tree_node);
-AVLNODE2STRUCT(rtp_prefix_tree2rtp, struct rt_path, rtp_prefix_tree_node);
+AVLNODE2STRUCT(rtp_tree2rtp, rt_path, rtp_tree_node);
+AVLNODE2STRUCT(rtp_prefix_tree2rtp, rt_path, rtp_prefix_tree_node);
 
 /*
  * Different routes types used in olsrd.
@@ -140,14 +139,9 @@ enum olsr_rt_origin {
  * the loop prefetches the next node in order to not loose context if
  * for example the caller wants to delete the current rt_entry.
  */
-#define OLSR_FOR_ALL_RT_ENTRIES(rt) \
-{ \
-  struct avl_node *rt_tree_node, *next_rt_tree_node; \
-  for (rt_tree_node = avl_walk_first(&routingtree); \
-    rt_tree_node; rt_tree_node = next_rt_tree_node) { \
-    next_rt_tree_node = avl_walk_next(rt_tree_node); \
-    rt = rt_tree2rt(rt_tree_node);
-#define OLSR_FOR_ALL_RT_ENTRIES_END(rt) }}
+AVLNODE2STRUCT(rt_tree2rt, rt_entry, rt_tree_node);
+#define OLSR_FOR_ALL_RT_ENTRIES(rt) OLSR_FOR_ALL_AVL_ENTRIES(&routingtree, rt_tree2rt, rt)
+#define OLSR_FOR_ALL_RT_ENTRIES_END(rt) OLSR_FOR_ALL_AVL_ENTRIES_END()
 
 
 /**
index 899fa0b..f7fc0e2 100644 (file)
@@ -230,7 +230,7 @@ olsr_delete_tc_entry(struct tc_entry *tc)
   OLSR_FOR_ALL_TC_EDGE_ENTRIES(tc, tc_edge) {
     /* we don't need this edge for the tc, so let's try to remove it */
     olsr_delete_tc_edge_entry(tc_edge);
-  } OLSR_FOR_ALL_TC_EDGE_ENTRIES_END(tc, tc_edge);
+  } OLSR_FOR_ALL_TC_EDGE_ENTRIES_END();
 }
 
 /**
@@ -248,7 +248,7 @@ olsr_cleanup_tc_entry(struct tc_entry *tc) {
 
   OLSR_FOR_ALL_PREFIX_ENTRIES(tc, rtp) {
     olsr_delete_rt_path(rtp);
-  } OLSR_FOR_ALL_PREFIX_ENTRIES_END(tc, rtp);
+  } OLSR_FOR_ALL_PREFIX_ENTRIES_END();
 
   /* Flush all MID aliases and kill the MID timer */
   olsr_flush_mid_entries(tc);
@@ -527,7 +527,7 @@ delete_outdated_tc_edges(struct tc_entry *tc)
       retval = true;
     }
   }
-  OLSR_FOR_ALL_TC_EDGE_ENTRIES_END(tc, tc_edge);
+  OLSR_FOR_ALL_TC_EDGE_ENTRIES_END();
 
   if (retval)
     changes_topology = true;
@@ -571,7 +571,7 @@ olsr_delete_revoked_tc_edges(struct tc_entry *tc, uint16_t ansn, union olsr_ip_a
       retval = 1;
     }
   }
-  OLSR_FOR_ALL_TC_EDGE_ENTRIES_END(tc, tc_edge);
+  OLSR_FOR_ALL_TC_EDGE_ENTRIES_END();
 
   if (retval)
     changes_topology = true;
@@ -689,8 +689,8 @@ olsr_print_tc_table(void)
                    olsr_get_linkcost_text(tc_edge->cost, false, lqbuffer1, sizeof(lqbuffer1)),
                    olsr_get_linkcost_text(tc_edge->common_cost, false, lqbuffer2, sizeof(lqbuffer2)));
 
-    } OLSR_FOR_ALL_TC_EDGE_ENTRIES_END(tc, tc_edge);
-  } OLSR_FOR_ALL_TC_ENTRIES_END(tc);
+    } OLSR_FOR_ALL_TC_EDGE_ENTRIES_END();
+  } OLSR_FOR_ALL_TC_ENTRIES_END();
 #endif
 }
 
@@ -1069,7 +1069,7 @@ olsr_output_lq_tc_internal(void *ctx  __attribute__ ((unused)), union olsr_ip_ad
     olsr_serialize_tc_lq(&curr, link);
 
     sendTC = true;
-  } OLSR_FOR_ALL_NBR_ENTRIES_END(nbr)
+  } OLSR_FOR_ALL_NBR_ENTRIES_END()
 
   if (!sendTC && skip) {
     OLSR_DEBUG(LOG_TC, "Nothing to send for this TC...\n");
index b883b99..9ad0fe4 100644 (file)
@@ -68,8 +68,6 @@ struct tc_edge_entry {
   uint16_t ansn;                       /* ansn of this edge, used for multipart msgs */
 };
 
-AVLNODE2STRUCT(edge_tree2tc_edge, struct tc_edge_entry, edge_node);
-
 struct tc_entry {
   struct avl_node vertex_node;         /* node keyed by ip address */
   union olsr_ip_addr addr;             /* vertex_node key */
@@ -108,8 +106,7 @@ struct tc_entry {
 #define OLSR_TC_VTIME_JITTER 5 /* percent */
 
 
-AVLNODE2STRUCT(vertex_tree2tc, struct tc_entry, vertex_node);
-AVLNODE2STRUCT(cand_tree2tc, struct tc_entry, cand_tree_node);
+AVLNODE2STRUCT(cand_tree2tc, tc_entry, cand_tree_node);
 LISTNODE2STRUCT(pathlist2tc, struct tc_entry, path_list_node);
 
 /*
@@ -120,32 +117,16 @@ LISTNODE2STRUCT(pathlist2tc, struct tc_entry, path_list_node);
  * the loop prefetches the next node in order to not loose context if
  * for example the caller wants to delete the current entry.
  */
-#define OLSR_FOR_ALL_TC_ENTRIES(tc) \
-{ \
-  struct avl_node *tc_tree_node, *next_tc_tree_node; \
-  for (tc_tree_node = avl_walk_first(&tc_tree); \
-    tc_tree_node; tc_tree_node = next_tc_tree_node) { \
-    next_tc_tree_node = avl_walk_next(tc_tree_node); \
-    tc = vertex_tree2tc(tc_tree_node);
-#define OLSR_FOR_ALL_TC_ENTRIES_END(tc) }}
-
-#define OLSR_FOR_ALL_TC_EDGE_ENTRIES(tc, tc_edge) \
-{ \
-  struct avl_node *tc_edge_node, *next_tc_edge_node; \
-  for (tc_edge_node = avl_walk_first(&tc->edge_tree); \
-    tc_edge_node; tc_edge_node = next_tc_edge_node) { \
-    next_tc_edge_node = avl_walk_next(tc_edge_node); \
-    tc_edge = edge_tree2tc_edge(tc_edge_node);
-#define OLSR_FOR_ALL_TC_EDGE_ENTRIES_END(tc, tc_edge) }}
-
-#define OLSR_FOR_ALL_PREFIX_ENTRIES(tc, rtp) \
-{ \
-  struct avl_node *rtp_node, *next_rtp_node; \
-  for (rtp_node = avl_walk_first(&tc->prefix_tree); \
-    rtp_node; rtp_node = next_rtp_node) { \
-    next_rtp_node = avl_walk_next(rtp_node); \
-    rtp = rtp_prefix_tree2rtp(rtp_node);
-#define OLSR_FOR_ALL_PREFIX_ENTRIES_END(tc, rtp) }}
+AVLNODE2STRUCT(vertex_tree2tc, tc_entry, vertex_node);
+#define OLSR_FOR_ALL_TC_ENTRIES(tc) OLSR_FOR_ALL_AVL_ENTRIES(&tc_tree, vertex_tree2tc, tc)
+#define OLSR_FOR_ALL_TC_ENTRIES_END(tc) OLSR_FOR_ALL_AVL_ENTRIES_END()
+
+AVLNODE2STRUCT(edge_tree2tc_edge, tc_edge_entry, edge_node);
+#define OLSR_FOR_ALL_TC_EDGE_ENTRIES(tc, tc_edge) OLSR_FOR_ALL_AVL_ENTRIES(&tc->edge_tree, edge_tree2tc_edge, tc_edge)
+#define OLSR_FOR_ALL_TC_EDGE_ENTRIES_END() OLSR_FOR_ALL_AVL_ENTRIES_END()
+
+#define OLSR_FOR_ALL_PREFIX_ENTRIES(tc, rtp) OLSR_FOR_ALL_AVL_ENTRIES(&tc->prefix_tree, rtp_prefix_tree2rtp, rtp)
+#define OLSR_FOR_ALL_PREFIX_ENTRIES_END() OLSR_FOR_ALL_AVL_ENTRIES_END()
 
 extern struct avl_tree EXPORT(tc_tree);
 extern struct tc_entry *tc_myself;