Move from fixed cookie array to dynamic tree
authorHenning Rogge <hrogge@googlemail.com>
Sat, 30 May 2009 17:40:08 +0000 (19:40 +0200)
committerHenning Rogge <hrogge@googlemail.com>
Sat, 30 May 2009 17:40:08 +0000 (19:40 +0200)
31 files changed:
lib/arprefresh/src/olsrd_arprefresh.c
lib/bmf/src/olsrd_plugin.c
lib/debuginfo/src/olsrd_debuginfo.c
lib/dyn_gw/src/olsrd_dyn_gw.c
lib/dyn_gw_plain/src/olsrd_dyn_gw_plain.c
lib/lq_etx_ff/src/lq_plugin_etx_ff.c
lib/nameservice/src/mapwrite.c
lib/nameservice/src/nameservice.c
lib/quagga/src/olsrd_plugin.c
lib/secure/src/olsrd_secure.c
lib/watchdog/src/olsrd_plugin.c
src/duplicate_set.c
src/hna_set.c
src/interfaces.c
src/link_set.c
src/lq_plugin_etx_ff.c
src/main.c
src/mid_set.c
src/mpr_selector_set.c
src/neighbor_table.c
src/olsr.c
src/olsr_comport.c
src/olsr_comport_txt.c
src/olsr_cookie.c
src/olsr_cookie.h
src/olsr_spf.c
src/olsr_types.h
src/scheduler.c
src/scheduler.h
src/tc_set.c
src/unix/ifnet.c

index cb5cd6a..903f395 100644 (file)
@@ -196,7 +196,7 @@ olsrd_plugin_init(void)
         0 <= set_nonblocking(arprefresh_sockfd) &&
         0 <= setsockopt(arprefresh_sockfd, SOL_SOCKET, SO_ATTACH_FILTER, &filter, sizeof(filter))) {
       /* Register the ARP refresh event */
-      olsr_start_timer(2 * MSEC_PER_SEC, 0, OLSR_TIMER_PERIODIC, &olsr_arp_event, NULL, arp_event_timer_cookie->ci_id);
+      olsr_start_timer(2 * MSEC_PER_SEC, 0, OLSR_TIMER_PERIODIC, &olsr_arp_event, NULL, arp_event_timer_cookie);
       ret = 1;
     } else {
       OLSR_WARN(LOG_PLUGINS, "*** ARPREFRESH: Cannot create non-blocking filtering packet socket: %s\n", strerror(errno));
index 8ccbab7..ff97be9 100644 (file)
@@ -108,7 +108,7 @@ olsrd_plugin_init(void)
   prune_packet_history_timer_cookie = olsr_alloc_cookie("BMF: Prune Packet History", OLSR_COOKIE_TYPE_TIMER);
 
   /* Register the duplicate registration pruning process */
-  olsr_start_timer(3 * MSEC_PER_SEC, 0, OLSR_TIMER_PERIODIC, &PrunePacketHistory, NULL, prune_packet_history_timer_cookie->ci_id);
+  olsr_start_timer(3 * MSEC_PER_SEC, 0, OLSR_TIMER_PERIODIC, &PrunePacketHistory, NULL, prune_packet_history_timer_cookie);
 
 
   return InitBmf(NULL);
index fb1e259..c3eeab7 100644 (file)
@@ -190,14 +190,14 @@ olsrd_plugin_init(void)
     commands[i].csv->acl = &allowed_nets;
   }
 
-  statistics_timer = olsr_alloc_cookie("debuginfo statistics timer", OLSR_COOKIE_TYPE_TIMER);
-  olsr_start_timer(traffic_interval * 1000, 0, true, &update_statistics_ptr, NULL, statistics_timer->ci_id);
+  statistics_timer = olsr_alloc_cookie("debuginfo timer", OLSR_COOKIE_TYPE_TIMER);
+  olsr_start_timer(traffic_interval * 1000, 0, true, &update_statistics_ptr, NULL, statistics_timer);
 
-  statistics_msg_mem = olsr_alloc_cookie("debuginfo msg statistics memory", OLSR_COOKIE_TYPE_MEMORY);
+  statistics_msg_mem = olsr_alloc_cookie("debuginfo msgstat", OLSR_COOKIE_TYPE_MEMORY);
   olsr_cookie_set_memory_size(statistics_msg_mem,
       sizeof(struct debug_msgtraffic) + sizeof(struct debug_msgtraffic_count) * traffic_slots);
 
-  statistics_pkt_mem = olsr_alloc_cookie("debuginfo pkt statistics memory", OLSR_COOKIE_TYPE_MEMORY);
+  statistics_pkt_mem = olsr_alloc_cookie("debuginfo pktstat", OLSR_COOKIE_TYPE_MEMORY);
   olsr_cookie_set_memory_size(statistics_pkt_mem,
       sizeof(struct debug_pkttraffic) + sizeof(struct debug_pkttraffic_count) * traffic_slots);
 
@@ -572,9 +572,9 @@ debuginfo_pktstat(struct comport_connection *con,  char *cmd __attribute__ ((unu
 }
 
 static INLINE bool debuginfo_print_cookies_mem(struct autobuf *buf, const char *format) {
-  int i;
-  for (i = 1; i < COOKIE_ID_MAX; i++) {
-    struct olsr_cookie_info *c = olsr_cookie_get(i);
+  struct olsr_cookie_info *c;
+
+  OLSR_FOR_ALL_COOKIES(c) {
     if (c == NULL || c->ci_type != OLSR_COOKIE_TYPE_MEMORY) {
       continue;
     }
@@ -583,13 +583,14 @@ 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)
   return false;
 }
+
 static INLINE bool debuginfo_print_cookies_timer(struct autobuf *buf, const char *format) {
-  int i;
-  for (i = 1; i < COOKIE_ID_MAX; i++) {
-    struct olsr_cookie_info *c = olsr_cookie_get(i);
+  struct olsr_cookie_info *c;
+
+  OLSR_FOR_ALL_COOKIES(c) {
     if (c == NULL || c->ci_type != OLSR_COOKIE_TYPE_TIMER) {
       continue;
     }
@@ -597,7 +598,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)
   return false;
 }
 
index f67dd9f..a496463 100644 (file)
@@ -225,7 +225,7 @@ olsrd_plugin_init(void)
   doing_hna_timer_cookie = olsr_alloc_cookie("DynGW: Doing HNS", OLSR_COOKIE_TYPE_TIMER);
 
   /* Register the GW check */
-  olsr_start_timer(3 * MSEC_PER_SEC, 0, OLSR_TIMER_PERIODIC, &olsr_event_doing_hna, NULL, doing_hna_timer_cookie->ci_id);
+  olsr_start_timer(3 * MSEC_PER_SEC, 0, OLSR_TIMER_PERIODIC, &olsr_event_doing_hna, NULL, doing_hna_timer_cookie);
 
   return 1;
 }
index 87d0615..cb2a999 100644 (file)
@@ -105,7 +105,7 @@ olsrd_plugin_init(void)
   event_timer_cookie = olsr_alloc_cookie("DynGW Plain: Event", OLSR_COOKIE_TYPE_TIMER);
 
   /* Register the GW check */
-  olsr_start_timer(3 * MSEC_PER_SEC, 0, OLSR_TIMER_PERIODIC, &olsr_event, NULL, event_timer_cookie->ci_id);
+  olsr_start_timer(3 * MSEC_PER_SEC, 0, OLSR_TIMER_PERIODIC, &olsr_event, NULL, event_timer_cookie);
 
   return 1;
 }
index d7de9cc..82f70f4 100644 (file)
@@ -238,7 +238,7 @@ lq_etxff_initialize(void)
   /* Some cookies for stats keeping */
   olsr_packetparser_add_function(&lq_etxff_packet_parser);
   default_lq_ff_timer_cookie = olsr_alloc_cookie("Default Freifunk LQ", OLSR_COOKIE_TYPE_TIMER);
-  lq_etxff_timer_struct = olsr_start_timer(1000, 0, OLSR_TIMER_PERIODIC, &lq_etxff_timer, NULL, default_lq_ff_timer_cookie->ci_id);
+  lq_etxff_timer_struct = olsr_start_timer(1000, 0, OLSR_TIMER_PERIODIC, &lq_etxff_timer, NULL, default_lq_ff_timer_cookie);
 }
 
 static void
index 8f112a8..1c5fa7c 100644 (file)
@@ -242,7 +242,7 @@ mapwrite_init(const char *fifoname)
       OLSR_WARN(LOG_PLUGINS, "mkfifo(%s): %s", fifoname, strerror(errno));
       return false;
     } else {
-      olsr_start_timer(800, 5, OLSR_TIMER_PERIODIC, &mapwrite_poll, NULL, map_poll_timer_cookie->ci_id);
+      olsr_start_timer(800, 5, OLSR_TIMER_PERIODIC, &mapwrite_poll, NULL, map_poll_timer_cookie);
     }
   }
   return true;
index 3dbb465..3ef7774 100644 (file)
@@ -425,7 +425,7 @@ name_init(void)
 
   /* periodic message generation */
   msg_gen_timer = olsr_start_timer(my_interval * MSEC_PER_SEC, EMISSION_JITTER,
-                                   OLSR_TIMER_PERIODIC, &olsr_namesvc_gen, NULL, msg_gen_timer_cookie->ci_id);
+                                   OLSR_TIMER_PERIODIC, &olsr_namesvc_gen, NULL, msg_gen_timer_cookie);
 
   mapwrite_init(my_latlon_file);
 
@@ -573,7 +573,7 @@ olsr_start_write_file_timer(void)
   }
 
   write_file_timer = olsr_start_timer(5 * MSEC_PER_SEC, 5, OLSR_TIMER_ONESHOT,
-                                      olsr_expire_write_file_timer, NULL, write_file_timer_cookie->ci_id);
+                                      olsr_expire_write_file_timer, NULL, write_file_timer_cookie);
 }
 
 /*
@@ -998,7 +998,7 @@ insert_new_name_in_list(union olsr_ip_addr *originator,
       decap_namemsg(from_packet, &entry->names, this_table_changed);
 
       olsr_set_timer(&entry->db_timer, vtime,
-                     OLSR_NAMESVC_DB_JITTER, OLSR_TIMER_ONESHOT, &olsr_nameservice_expire_db_timer, entry, db_timer_cookie->ci_id);
+                     OLSR_NAMESVC_DB_JITTER, OLSR_TIMER_ONESHOT, &olsr_nameservice_expire_db_timer, entry, db_timer_cookie);
 
       entry_found = true;
     }
@@ -1017,7 +1017,7 @@ insert_new_name_in_list(union olsr_ip_addr *originator,
     entry->originator = *originator;
 
     olsr_set_timer(&entry->db_timer, vtime,
-                   OLSR_LINK_LOSS_JITTER, OLSR_TIMER_ONESHOT, &olsr_nameservice_expire_db_timer, entry, db_timer_cookie->ci_id);
+                   OLSR_LINK_LOSS_JITTER, OLSR_TIMER_ONESHOT, &olsr_nameservice_expire_db_timer, entry, db_timer_cookie);
 
     entry->names = NULL;
 
index 2b052f8..6247925 100644 (file)
@@ -140,7 +140,7 @@ olsrd_plugin_init(void)
 
   event_timer_cookie = olsr_alloc_cookie("Quagga: Event", OLSR_COOKIE_TYPE_TIMER);
 
-  olsr_start_timer(1 * MSEC_PER_SEC, 0, OLSR_TIMER_PERIODIC, &zebra_parse, NULL, event_timer_cookie->ci_id);
+  olsr_start_timer(1 * MSEC_PER_SEC, 0, OLSR_TIMER_PERIODIC, &zebra_parse, NULL, event_timer_cookie);
 
   return 0;
 }
index a5a113d..4a0d9dd 100644 (file)
@@ -206,7 +206,7 @@ secure_plugin_init(void)
   timeout_timestamps_timer_cookie = olsr_alloc_cookie("Secure: Timeout Timestamps", OLSR_COOKIE_TYPE_TIMER);
 
   /* Register timeout - poll every 2 seconds */
-  olsr_start_timer(2 * MSEC_PER_SEC, 0, OLSR_TIMER_PERIODIC, &timeout_timestamps, NULL, timeout_timestamps_timer_cookie->ci_id);
+  olsr_start_timer(2 * MSEC_PER_SEC, 0, OLSR_TIMER_PERIODIC, &timeout_timestamps, NULL, timeout_timestamps_timer_cookie);
 
   return 1;
 }
index 7157b7f..66e7fc7 100644 (file)
@@ -133,7 +133,7 @@ olsrd_plugin_init(void)
 
   /* Register the GW check */
   olsr_start_timer(watchdog_interval * MSEC_PER_SEC, 0, OLSR_TIMER_PERIODIC,
-                   &olsr_watchdog_write_alivefile, NULL, watchdog_timer_cookie->ci_id);
+                   &olsr_watchdog_write_alivefile, NULL, watchdog_timer_cookie);
 
   return 1;
 }
index ac79e8d..153de6f 100644 (file)
@@ -77,7 +77,7 @@ olsr_init_duplicate_set(void)
   olsr_cookie_set_memory_size(duplicate_mem_cookie, sizeof(struct dup_entry));
 
   olsr_set_timer(&duplicate_cleanup_timer, DUPLICATE_CLEANUP_INTERVAL,
-                 DUPLICATE_CLEANUP_JITTER, OLSR_TIMER_PERIODIC, &olsr_cleanup_duplicate_entry, NULL, duplicate_timer_cookie->ci_id);
+                 DUPLICATE_CLEANUP_JITTER, OLSR_TIMER_PERIODIC, &olsr_cleanup_duplicate_entry, NULL, duplicate_timer_cookie);
 }
 
 static struct dup_entry *
index 17b92e1..dd39144 100644 (file)
@@ -209,7 +209,7 @@ olsr_update_hna_entry(const union olsr_ip_addr *gw, const struct olsr_ip_prefix
    * Start, or refresh the timer, whatever is appropriate.
    */
   olsr_set_timer(&net_entry->hna_net_timer, vtime,
-                 OLSR_HNA_NET_JITTER, OLSR_TIMER_ONESHOT, &olsr_expire_hna_net_entry, net_entry, hna_net_timer_cookie->ci_id);
+                 OLSR_HNA_NET_JITTER, OLSR_TIMER_ONESHOT, &olsr_expire_hna_net_entry, net_entry, hna_net_timer_cookie);
 }
 
 /**
index 543835d..452c804 100644 (file)
@@ -115,7 +115,7 @@ ifinit(void)
 
   /* Kick a periodic timer for the network interface update function */
   olsr_start_timer(olsr_cnf->nic_chgs_pollrate * MSEC_PER_SEC, 5,
-                   OLSR_TIMER_PERIODIC, &check_interface_updates, NULL, interface_poll_timer_cookie->ci_id);
+                   OLSR_TIMER_PERIODIC, &check_interface_updates, NULL, interface_poll_timer_cookie);
 
   return (!list_is_empty(&interface_head));
 }
index d5c397e..f092188 100644 (file)
@@ -409,7 +409,7 @@ static void
 olsr_set_link_timer(struct link_entry *link, unsigned int rel_timer)
 {
   olsr_set_timer(&link->link_timer, rel_timer, OLSR_LINK_JITTER,
-                 OLSR_TIMER_ONESHOT, &olsr_expire_link_entry, link, link_dead_timer_cookie->ci_id);
+                 OLSR_TIMER_ONESHOT, &olsr_expire_link_entry, link, link_dead_timer_cookie);
 }
 
 /**
@@ -484,7 +484,7 @@ add_link_entry(const union olsr_ip_addr *local,
   link->loss_helloint = htime;
 
   olsr_set_timer(&link->link_loss_timer, htime + htime / 2,
-                 OLSR_LINK_LOSS_JITTER, OLSR_TIMER_PERIODIC, &olsr_expire_link_loss_timer, link, link_loss_timer_cookie->ci_id);
+                 OLSR_LINK_LOSS_JITTER, OLSR_TIMER_PERIODIC, &olsr_expire_link_loss_timer, link, link_loss_timer_cookie);
 
   set_loss_link_multiplier(link);
 
@@ -624,7 +624,7 @@ update_link_entry(const union olsr_ip_addr *local,
 
     /* L_SYM_time = current time + validity time */
     olsr_set_timer(&entry->link_sym_timer, message->comm.vtime,
-                   OLSR_LINK_SYM_JITTER, OLSR_TIMER_ONESHOT, &olsr_expire_link_sym_timer, entry, link_sym_timer_cookie->ci_id);
+                   OLSR_LINK_SYM_JITTER, OLSR_TIMER_ONESHOT, &olsr_expire_link_sym_timer, entry, link_sym_timer_cookie);
 
     /* L_time = L_SYM_time + NEIGHB_HOLD_TIME */
     olsr_set_link_timer(entry, message->comm.vtime + NEIGHB_HOLD_TIME * MSEC_PER_SEC);
@@ -749,7 +749,7 @@ olsr_update_packet_loss(struct link_entry *entry)
 
   /* timeout for the first lost packet is 1.5 x htime */
   olsr_set_timer(&entry->link_loss_timer, entry->loss_helloint + entry->loss_helloint / 2,
-                 OLSR_LINK_LOSS_JITTER, OLSR_TIMER_PERIODIC, &olsr_expire_link_loss_timer, entry, link_loss_timer_cookie->ci_id);
+                 OLSR_LINK_LOSS_JITTER, OLSR_TIMER_PERIODIC, &olsr_expire_link_loss_timer, entry, link_loss_timer_cookie);
 }
 
 /*
index c6ac149..cd0a7b3 100644 (file)
@@ -238,7 +238,7 @@ lq_etxff_initialize(void)
   /* Some cookies for stats keeping */
   olsr_packetparser_add_function(&lq_etxff_packet_parser);
   default_lq_ff_timer_cookie = olsr_alloc_cookie("Default Freifunk LQ", OLSR_COOKIE_TYPE_TIMER);
-  lq_etxff_timer_struct = olsr_start_timer(1000, 0, OLSR_TIMER_PERIODIC, &lq_etxff_timer, NULL, default_lq_ff_timer_cookie->ci_id);
+  lq_etxff_timer_struct = olsr_start_timer(1000, 0, OLSR_TIMER_PERIODIC, &lq_etxff_timer, NULL, default_lq_ff_timer_cookie);
 }
 
 static void
index 29268db..3bb7cfc 100644 (file)
@@ -197,6 +197,9 @@ main(int argc, char *argv[])
   /* initialize logging */
   olsr_log_init();
 
+  /* initialize cookie system */
+  olsr_cookie_init();
+
   /* Initialize timers and scheduler part */
   olsr_init_timers();
 
@@ -307,7 +310,7 @@ main(int argc, char *argv[])
 #if !defined WINCE
   if (olsr_cnf->log_target_stderr > 0 && isatty(STDOUT_FILENO)) {
     pulse_timer_cookie = olsr_alloc_cookie("Pulse", OLSR_COOKIE_TYPE_TIMER);
-    olsr_start_timer(STDOUT_PULSE_INT, 0, OLSR_TIMER_PERIODIC, &generate_stdout_pulse, NULL, pulse_timer_cookie->ci_id);
+    olsr_start_timer(STDOUT_PULSE_INT, 0, OLSR_TIMER_PERIODIC, &generate_stdout_pulse, NULL, pulse_timer_cookie);
   }
 #endif
 
index 292f060..82609a7 100644 (file)
@@ -109,7 +109,7 @@ static void
 olsr_set_mid_timer(struct tc_entry *tc, olsr_reltime rel_timer)
 {
   olsr_set_timer(&tc->mid_timer, rel_timer, OLSR_MID_JITTER,
-                 OLSR_TIMER_ONESHOT, &olsr_expire_mid_entries, tc, mid_validity_timer_cookie->ci_id);
+                 OLSR_TIMER_ONESHOT, &olsr_expire_mid_entries, tc, mid_validity_timer_cookie);
 }
 
 /**
index 27245a0..da0b434 100644 (file)
@@ -148,7 +148,7 @@ olsr_update_mprs_set(const union olsr_ip_addr *addr, olsr_reltime vtime)
     rv = 0;
   }
   olsr_set_timer(&mprs->MS_timer,
-                 vtime, OLSR_MPR_SEL_JITTER, OLSR_TIMER_ONESHOT, &olsr_expire_mpr_sel_entry, mprs, mpr_sel_timer_cookie->ci_id);
+                 vtime, OLSR_MPR_SEL_JITTER, OLSR_TIMER_ONESHOT, &olsr_expire_mpr_sel_entry, mprs, mpr_sel_timer_cookie);
   return rv;
 }
 
index 2e62460..505d6e0 100644 (file)
@@ -353,7 +353,7 @@ struct nbr_con *olsr_link_nbr_nbr2(struct nbr_entry *nbr, const union olsr_ip_ad
   connector->path_linkcost = LINK_COST_BROKEN;
 
   connector->nbr2_list_timer = olsr_start_timer(vtime, OLSR_NBR2_LIST_JITTER,
-      OLSR_TIMER_ONESHOT, &olsr_expire_nbr_con, connector, nbr_connector_timer_cookie->ci_id);
+      OLSR_TIMER_ONESHOT, &olsr_expire_nbr_con, connector, nbr_connector_timer_cookie);
 
   return connector;
 }
index c2f97c7..b68cfd2 100644 (file)
@@ -240,7 +240,7 @@ olsr_init_tables(void)
   if (olsr_cnf->lq_dinter > 0.0) {
     periodic_spf_timer_cookie = olsr_alloc_cookie("Periodic SPF", OLSR_COOKIE_TYPE_TIMER);
     olsr_start_timer((unsigned int)(olsr_cnf->lq_dinter * MSEC_PER_SEC), 5,
-                     OLSR_TIMER_PERIODIC, &olsr_trigger_forced_update, NULL, periodic_spf_timer_cookie->ci_id);
+                     OLSR_TIMER_PERIODIC, &olsr_trigger_forced_update, NULL, periodic_spf_timer_cookie);
   }
 }
 
@@ -411,7 +411,7 @@ set_buffer_timer(struct interface *ifn)
    */
   ifn->buffer_hold_timer =
     olsr_start_timer(OLSR_BUFFER_HOLD_TIME, OLSR_BUFFER_HOLD_JITTER,
-                     OLSR_TIMER_ONESHOT, &olsr_expire_buffer_timer, ifn, buffer_hold_timer_cookie->ci_id);
+                     OLSR_TIMER_ONESHOT, &olsr_expire_buffer_timer, ifn, buffer_hold_timer_cookie);
 }
 
 void
@@ -427,7 +427,7 @@ olsr_init_willingness(void)
 
     willingness_timer_cookie = olsr_alloc_cookie("Update Willingness", OLSR_COOKIE_TYPE_TIMER);
     olsr_start_timer((unsigned int)olsr_cnf->will_int * MSEC_PER_SEC, 5,
-                     OLSR_TIMER_PERIODIC, &olsr_update_willingness, NULL, willingness_timer_cookie->ci_id);
+                     OLSR_TIMER_PERIODIC, &olsr_update_willingness, NULL, willingness_timer_cookie);
   }
 }
 
index f6c7e27..d5a77fe 100644 (file)
@@ -249,7 +249,7 @@ static void olsr_com_parse_request(int fd, void *data __attribute__ ((unused)),
       sock, olsr_ip_to_string(&buf, &con->addr));
 
   con->timeout = olsr_start_timer(con->timeout_value, 0, false,
-      &olsr_com_timeout_handler, con, connection_timeout->ci_id);
+      &olsr_com_timeout_handler, con, connection_timeout);
 
   add_olsr_socket(sock, &olsr_com_parse_connection, NULL, con, SP_PR_READ
       | SP_PR_WRITE);
@@ -613,18 +613,7 @@ static void olsr_com_parse_txt(struct comport_connection *con,
   }
 
   if (old_timeout != con->timeout_value) {
-    if (con->timeout) {
-      if (con->timeout_value > 0) {
-        olsr_change_timer(con->timeout, con->timeout_value, 0, false);
-      }
-      else {
-        olsr_stop_timer(con->timeout);
-        con->timeout = NULL;
-      }
-    } else if (con->timeout_value > 0) {
-      con->timeout = olsr_start_timer(con->timeout_value, 0, false,
-          &olsr_com_timeout_handler, con, connection_timeout->ci_id);
-    }
+    olsr_set_timer(&con->timeout, con->timeout_value, 0, false, &olsr_com_timeout_handler, con, connection_timeout);
   }
 
   /* print prompt */
index 6bd1629..34e759a 100644 (file)
@@ -313,7 +313,7 @@ olsr_txtcmd_repeat(struct comport_connection *con, char *cmd __attribute__ ((unu
 
   interval = atoi(param);
 
-  timer = olsr_start_timer(interval * 1000, 0, true, &olsr_txt_repeat_timer, con, txt_repeattimer_cookie->ci_id);
+  timer = olsr_start_timer(interval * 1000, 0, true, &olsr_txt_repeat_timer, con, txt_repeattimer_cookie);
   con->stop_handler = olsr_txt_repeat_stophandler;
   con->stop_data[0] = timer;
   con->stop_data[1] = strdup(ptr);
index d9e22d7..97d74b2 100644 (file)
 #include <errno.h>
 #include <stdlib.h>
 
+struct avl_tree olsr_cookie_tree;
 
-/* Root directory of the cookies we have in the system */
-static struct olsr_cookie_info *cookies[COOKIE_ID_MAX] = { 0 };
+void olsr_cookie_init(void) {
+  avl_init(&olsr_cookie_tree, &avl_comp_strcasecmp);
+}
 
 /*
  * Allocate a cookie for the next available cookie id.
@@ -60,37 +62,32 @@ static struct olsr_cookie_info *cookies[COOKIE_ID_MAX] = { 0 };
 struct olsr_cookie_info *
 olsr_alloc_cookie(const char *cookie_name, olsr_cookie_type cookie_type)
 {
-  struct olsr_cookie_info *ci;
-  int ci_index;
+  static uint16_t next_brand_id = 1;
 
-  /*
-   * Look for an unused index.
-   * For ease of troubleshooting (non-zero patterns) we start at index 1.
-   */
-  for (ci_index = 1; ci_index < COOKIE_ID_MAX; ci_index++) {
-    if (!cookies[ci_index]) {
-      break;
-    }
-  }
+  struct olsr_cookie_info *ci;
 
-  assert(ci_index < COOKIE_ID_MAX);     /* increase COOKIE_ID_MAX */
+  assert (cookie_name);
 
   ci = olsr_malloc(sizeof(struct olsr_cookie_info), "new cookie");
-  cookies[ci_index] = ci;
 
   /* Now populate the cookie info */
-  ci->ci_id = ci_index;
   ci->ci_type = cookie_type;
-  if (cookie_name) {
-    ci->ci_name = olsr_strdup(cookie_name);
-  }
+  ci->ci_name = olsr_strdup(cookie_name);
+
+  ci->node.key = ci->ci_name;
 
   /* Init the free list */
   if (cookie_type == OLSR_COOKIE_TYPE_MEMORY) {
     list_head_init(&ci->ci_free_list);
     VALGRIND_CREATE_MEMPOOL(ci, 0, 1);
+
+    ci->ci_membrand = next_brand_id++;
+  }
+  else {
+    ci->ci_membrand = 0;
   }
 
+  avl_insert(&olsr_cookie_tree, &ci->node, AVL_DUP_NO);
   return ci;
 }
 
@@ -102,8 +99,8 @@ olsr_free_cookie(struct olsr_cookie_info *ci)
 {
   struct list_node *memory_list;
 
-  /* Mark the cookie as unused */
-  cookies[ci->ci_id] = NULL;
+  /* remove from tree */
+  avl_delete(&olsr_cookie_tree, &ci->node);
 
   /* Free name */
   free(ci->ci_name);
@@ -138,17 +135,14 @@ olsr_free_cookie(struct olsr_cookie_info *ci)
 void
 olsr_delete_all_cookies(void)
 {
-  int ci_index;
+  struct olsr_cookie_info *info;
 
   /*
    * Walk the full index range and kill 'em all.
    */
-  for (ci_index = 1; ci_index < COOKIE_ID_MAX; ci_index++) {
-    if (!cookies[ci_index]) {
-      continue;
-    }
-    olsr_free_cookie(cookies[ci_index]);
-  }
+  OLSR_FOR_ALL_COOKIES(info) {
+    olsr_free_cookie(info);
+  } OLSR_FOR_ALL_COOKIES_END(info)
 }
 
 /*
@@ -207,56 +201,24 @@ olsr_cookie_set_memory_poison(struct olsr_cookie_info *ci, bool poison)
   }
 }
 
-/*
- * Basic sanity checking for a passed-in cookie-id.
- */
-static bool
-olsr_cookie_valid(olsr_cookie_t cookie_id)
-{
-  if ((cookie_id < COOKIE_ID_MAX) && cookies[cookie_id]) {
-    return true;
-  }
-  return false;
-}
-
 /*
  * Increment usage state for a given cookie.
  */
 void
-olsr_cookie_usage_incr(olsr_cookie_t cookie_id)
+olsr_cookie_usage_incr(struct olsr_cookie_info *ci)
 {
-  if (olsr_cookie_valid(cookie_id)) {
-    cookies[cookie_id]->ci_usage++;
-    cookies[cookie_id]->ci_changes++;
-  }
+  ci->ci_usage++;
+  ci->ci_changes++;
 }
 
 /*
  * Decrement usage state for a given cookie.
  */
 void
-olsr_cookie_usage_decr(olsr_cookie_t cookie_id)
-{
-  if (olsr_cookie_valid(cookie_id)) {
-    cookies[cookie_id]->ci_usage--;
-    cookies[cookie_id]->ci_changes++;
-  }
-}
-
-/*
- * Return a cookie name.
- * Mostly used for logging purposes.
- */
-char *
-olsr_cookie_name(olsr_cookie_t cookie_id)
+olsr_cookie_usage_decr(struct olsr_cookie_info *ci)
 {
-  static char unknown[] = "unknown";
-
-  if (olsr_cookie_valid(cookie_id)) {
-    return (cookies[cookie_id])->ci_name;
-  }
-
-  return unknown;
+  ci->ci_usage--;
+  ci->ci_changes++;
 }
 
 /*
@@ -349,10 +311,10 @@ olsr_cookie_malloc(struct olsr_cookie_info *ci)
   branding = (struct olsr_cookie_mem_brand *)
     ((unsigned char *)ptr + ci->ci_size);
   memcpy(&branding->cmb_sig, "cookie", 6);
-  branding->cmb_id = ci->ci_id;
+  branding->id = ci->ci_membrand;
 
   /* Stats keeping */
-  olsr_cookie_usage_incr(ci->ci_id);
+  olsr_cookie_usage_incr(ci);
 
   OLSR_DEBUG(LOG_COOKIE, "MEMORY: alloc %s, %p, %lu bytes%s\n",
              ci->ci_name, ptr, (unsigned long)ci->ci_size, reuse ? ", reuse" : "");
@@ -379,7 +341,7 @@ olsr_cookie_free(struct olsr_cookie_info *ci, void *ptr)
    * Verify if there has been a memory overrun, or
    * the wrong owner is trying to free this.
    */
-  assert(!memcmp(&branding->cmb_sig, "cookie", 6) && branding->cmb_id == ci->ci_id);
+  assert(!memcmp(&branding->cmb_sig, "cookie", 6) && branding->id == ci->ci_membrand);
 
   /* Kill the brand */
   memset(branding, 0, sizeof(*branding));
@@ -426,7 +388,7 @@ olsr_cookie_free(struct olsr_cookie_info *ci, void *ptr)
   }
 
   /* Stats keeping */
-  olsr_cookie_usage_decr(ci->ci_id);
+  olsr_cookie_usage_decr(ci);
 
   OLSR_DEBUG(LOG_COOKIE, "MEMORY: free %s, %p, %lu bytes%s\n",
              ci->ci_name, ptr, (unsigned long)ci->ci_size, reuse ? ", reuse" : "");
@@ -435,12 +397,6 @@ olsr_cookie_free(struct olsr_cookie_info *ci, void *ptr)
   VALGRIND_MAKE_MEM_NOACCESS(ptr, ci->ci_size);
 }
 
-struct olsr_cookie_info *
-olsr_cookie_get(int i)
-{
-  return cookies[i];
-}
-
 /*
  * Local Variables:
  * c-basic-offset: 2
index 8788be5..1c21c6e 100644 (file)
 
 #include "olsr_types.h"
 #include "common/list.h"
+#include "common/avl.h"
 
 #ifndef _OLSR_COOKIE_H
 #define _OLSR_COOKIE_H
 
-#define COOKIE_ID_MAX  50       /* maximum number of cookies in the system */
+extern struct avl_tree olsr_cookie_tree;
 
 typedef enum olsr_cookie_type_ {
   OLSR_COOKIE_TYPE_MIN,
@@ -60,17 +61,31 @@ typedef enum olsr_cookie_type_ {
  * for locating memory corruption.
  */
 struct olsr_cookie_info {
-  olsr_cookie_t ci_id;                 /* ID */
+  struct avl_node node;
   char *ci_name;                       /* Name */
   olsr_cookie_type ci_type;            /* Type of cookie */
-  size_t ci_size;                      /* Fixed size for block allocations */
   unsigned int ci_flags;               /* Misc. flags */
   unsigned int ci_usage;               /* Stats, resource usage */
   unsigned int ci_changes;             /* Stats, resource churn */
+
+  /* only for memory cookies */
+  size_t ci_size;                      /* Fixed size for block allocations */
   struct list_node ci_free_list;       /* List head for recyclable blocks */
   unsigned int ci_free_list_usage;     /* Length of free list */
+  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) }}
+
 /* Cookie flags */
 #define COOKIE_NO_MEMCLEAR  ( 1 << 0)   /* Do not clear memory */
 #define COOKIE_MEMPOISON    ( 2 << 0)   /* Poison memory pattern */
@@ -84,18 +99,18 @@ struct olsr_cookie_info {
  */
 struct olsr_cookie_mem_brand {
   char cmb_sig[6];
-  olsr_cookie_t cmb_id;
+  uint16_t id;
 };
 
 /* Externals. */
+void olsr_cookie_init(void);
 struct olsr_cookie_info *EXPORT(olsr_alloc_cookie) (const char *, olsr_cookie_type);
 void olsr_delete_all_cookies(void);
-char *EXPORT(olsr_cookie_name) (olsr_cookie_t);
 void EXPORT(olsr_cookie_set_memory_size) (struct olsr_cookie_info *, size_t);
 void EXPORT(olsr_cookie_set_memory_clear) (struct olsr_cookie_info *, bool);
 void EXPORT(olsr_cookie_set_memory_poison) (struct olsr_cookie_info *, bool);
-void EXPORT(olsr_cookie_usage_incr) (olsr_cookie_t);
-void EXPORT(olsr_cookie_usage_decr) (olsr_cookie_t);
+void EXPORT(olsr_cookie_usage_incr) (struct olsr_cookie_info *);
+void EXPORT(olsr_cookie_usage_decr) (struct olsr_cookie_info *);
 
 void *EXPORT(olsr_cookie_malloc) (struct olsr_cookie_info *);
 void EXPORT(olsr_cookie_free) (struct olsr_cookie_info *, void *);
index 7baf89f..94978aa 100644 (file)
@@ -289,7 +289,7 @@ olsr_calculate_routing_table(void)
   }
   spf_backoff_timer =
     olsr_start_timer(OLSR_SPF_BACKOFF_TIME, OLSR_SPF_BACKOFF_JITTER,
-                     OLSR_TIMER_ONESHOT, &olsr_expire_spf_backoff, NULL, spf_backoff_timer_cookie->ci_id);
+                     OLSR_TIMER_ONESHOT, &olsr_expire_spf_backoff, NULL, spf_backoff_timer_cookie);
 
 #ifdef SPF_PROFILING
   gettimeofday(&t1, NULL);
index d7e94a8..0a9c962 100644 (file)
@@ -83,9 +83,6 @@ typedef signed int int32_t;
 #endif
 #endif
 
-/* user defined cookies */
-typedef uint16_t olsr_cookie_t;
-
 /* OpenBSD wants this here */
 #include <sys/types.h>
 
index f14ce47..c892666 100644 (file)
@@ -592,7 +592,7 @@ walk_timers(uint32_t * last_run)
 
         OLSR_DEBUG(LOG_SCHEDULER, "TIMER: fire %s timer %p, ctx %p, "
                    "at clocktick %u (%s)\n",
-                   olsr_cookie_name(timer->timer_cookie),
+                   timer->timer_cookie->ci_name,
                    timer, timer->timer_cb_context, (unsigned int)*last_run, olsr_wallclock_string());
 
         /* This timer is expired, call into the provided callback function */
@@ -753,11 +753,11 @@ olsr_clock_string(uint32_t clk)
  */
 struct timer_entry *
 olsr_start_timer(unsigned int rel_time,
-                 uint8_t jitter_pct, bool periodical, timer_cb_func cb_func, void *context, olsr_cookie_t cookie)
+                 uint8_t jitter_pct, bool periodical, timer_cb_func cb_func, void *context, struct olsr_cookie_info *ci)
 {
   struct timer_entry *timer;
 
-  assert(cookie != 0);          /* we want timer cookies everywhere */
+  assert(ci != 0);          /* we want timer cookies everywhere */
 
   timer = olsr_cookie_malloc(timer_mem_cookie);
 
@@ -776,8 +776,8 @@ olsr_start_timer(unsigned int rel_time,
   timer->timer_flags = OLSR_TIMER_RUNNING;
 
   /* The cookie is used for debugging to traceback the originator */
-  timer->timer_cookie = cookie;
-  olsr_cookie_usage_incr(cookie);
+  timer->timer_cookie = ci;
+  olsr_cookie_usage_incr(ci);
 
   /* Singleshot or periodical timer ? */
   timer->timer_period = periodical ? rel_time : 0;
@@ -788,7 +788,7 @@ olsr_start_timer(unsigned int rel_time,
   list_add_before(&timer_wheel[timer->timer_clock & TIMER_WHEEL_MASK], &timer->timer_list);
 
   OLSR_DEBUG(LOG_SCHEDULER, "TIMER: start %s timer %p firing in %s, ctx %p\n",
-             olsr_cookie_name(timer->timer_cookie), timer, olsr_clock_string(timer->timer_clock), context);
+             ci->ci_name, timer, olsr_clock_string(timer->timer_clock), context);
 
   return timer;
 }
@@ -807,10 +807,11 @@ olsr_stop_timer(struct timer_entry *timer)
     return;
   }
 
+  assert(timer->timer_cookie);     /* we want timer cookies everywhere */
+
   OLSR_DEBUG(LOG_SCHEDULER, "TIMER: stop %s timer %p, ctx %p\n",
-             olsr_cookie_name(timer->timer_cookie), timer, timer->timer_cb_context);
+             timer->timer_cookie->ci_name, timer, timer->timer_cb_context);
 
-  assert(timer->timer_cookie != 0);     /* we want timer cookies everywhere */
 
   /*
    * Carve out of the existing wheel_slot and free.
@@ -838,7 +839,7 @@ olsr_change_timer(struct timer_entry *timer, unsigned int rel_time, uint8_t jitt
     return;
   }
 
-  assert(timer->timer_cookie != 0);     /* we want timer cookies everywhere */
+  assert(timer->timer_cookie);     /* we want timer cookies everywhere */
 
   /* Singleshot or periodical timer ? */
   timer->timer_period = periodical ? rel_time : 0;
@@ -854,7 +855,7 @@ olsr_change_timer(struct timer_entry *timer, unsigned int rel_time, uint8_t jitt
   list_add_before(&timer_wheel[timer->timer_clock & TIMER_WHEEL_MASK], &timer->timer_list);
 
   OLSR_DEBUG(LOG_SCHEDULER, "TIMER: change %s timer %p, firing to %s, ctx %p\n",
-             olsr_cookie_name(timer->timer_cookie), timer, olsr_clock_string(timer->timer_clock), timer->timer_cb_context);
+             timer->timer_cookie->ci_name, timer, olsr_clock_string(timer->timer_clock), timer->timer_cb_context);
 }
 
 /*
@@ -866,9 +867,9 @@ olsr_change_timer(struct timer_entry *timer, unsigned int rel_time, uint8_t jitt
 void
 olsr_set_timer(struct timer_entry **timer_ptr,
                unsigned int rel_time,
-               uint8_t jitter_pct, bool periodical, timer_cb_func cb_func, void *context, olsr_cookie_t cookie)
+               uint8_t jitter_pct, bool periodical, timer_cb_func cb_func, void *context, struct olsr_cookie_info *cookie)
 {
-  assert(cookie != 0);          /* we want timer cookies everywhere */
+  assert(cookie);          /* we want timer cookies everywhere */
   if (!*timer_ptr) {
     /* No timer running, kick it. */
     *timer_ptr = olsr_start_timer(rel_time, jitter_pct, periodical, cb_func, context, cookie);
index a0dd11b..c32f8d3 100644 (file)
@@ -74,7 +74,7 @@ struct timer_entry {
   struct list_node timer_list;         /* Wheel membership */
   uint32_t timer_clock;                /* when timer shall fire (absolute time) */
   unsigned int timer_period;           /* set for periodical timers (relative time) */
-  olsr_cookie_t timer_cookie;          /* used for diag stuff */
+  struct olsr_cookie_info *timer_cookie;       /* used for diag stuff */
   uint8_t timer_jitter_pct;            /* the jitter expressed in percent */
   uint8_t timer_flags;                 /* misc flags */
   unsigned int timer_random;           /* cache random() result for performance reasons */
@@ -94,8 +94,8 @@ LISTNODE2STRUCT(list2timer, struct timer_entry, timer_list);
 /* Timers */
 void olsr_init_timers(void);
 void olsr_flush_timers(void);
-void EXPORT(olsr_set_timer) (struct timer_entry **, unsigned int, uint8_t, bool, timer_cb_func, void *, olsr_cookie_t);
-struct timer_entry *EXPORT(olsr_start_timer) (unsigned int, uint8_t, bool, timer_cb_func, void *, olsr_cookie_t);
+void EXPORT(olsr_set_timer) (struct timer_entry **, unsigned int, uint8_t, bool, timer_cb_func, void *, struct olsr_cookie_info *);
+struct timer_entry *EXPORT(olsr_start_timer) (unsigned int, uint8_t, bool, timer_cb_func, void *, struct olsr_cookie_info *);
 void olsr_change_timer(struct timer_entry *, unsigned int, uint8_t, bool);
 void EXPORT(olsr_stop_timer) (struct timer_entry *);
 
index 59ed12a..f34eadb 100644 (file)
@@ -895,7 +895,7 @@ olsr_input_tc(union olsr_message * msg, struct interface * input_if __attribute_
    * Set or change the expiration timer accordingly.
    */
   olsr_set_timer(&tc->validity_timer, vtime,
-                 OLSR_TC_VTIME_JITTER, OLSR_TIMER_ONESHOT, &olsr_expire_tc_entry, tc, tc_validity_timer_cookie->ci_id);
+                 OLSR_TC_VTIME_JITTER, OLSR_TIMER_ONESHOT, &olsr_expire_tc_entry, tc, tc_validity_timer_cookie);
 
   if (borderSet) {
 
@@ -910,7 +910,7 @@ olsr_input_tc(union olsr_message * msg, struct interface * input_if __attribute_
      * all edges belonging to a multipart neighbor set will arrive.
      */
     olsr_set_timer(&tc->edge_gc_timer, OLSR_TC_EDGE_GC_TIME,
-                   OLSR_TC_EDGE_GC_JITTER, OLSR_TIMER_ONESHOT, &olsr_expire_tc_edge_gc, tc, tc_edge_gc_timer_cookie->ci_id);
+                   OLSR_TC_EDGE_GC_JITTER, OLSR_TIMER_ONESHOT, &olsr_expire_tc_edge_gc, tc, tc_edge_gc_timer_cookie);
   }
 
   /* Forward the message */
index 1f06e03..d725e71 100644 (file)
@@ -410,16 +410,16 @@ add_hemu_if(struct olsr_if_config *iface)
 
   ifp->hello_gen_timer =
     olsr_start_timer(iface->cnf->hello_params.emission_interval * MSEC_PER_SEC,
-                     HELLO_JITTER, OLSR_TIMER_PERIODIC, &olsr_output_lq_hello, ifp, hello_gen_timer_cookie->ci_id);
+                     HELLO_JITTER, OLSR_TIMER_PERIODIC, &olsr_output_lq_hello, ifp, hello_gen_timer_cookie);
   ifp->tc_gen_timer =
     olsr_start_timer(iface->cnf->tc_params.emission_interval * MSEC_PER_SEC,
-                     TC_JITTER, OLSR_TIMER_PERIODIC, &olsr_output_lq_tc, ifp, tc_gen_timer_cookie->ci_id);
+                     TC_JITTER, OLSR_TIMER_PERIODIC, &olsr_output_lq_tc, ifp, tc_gen_timer_cookie);
   ifp->mid_gen_timer =
     olsr_start_timer(iface->cnf->mid_params.emission_interval * MSEC_PER_SEC,
-                     MID_JITTER, OLSR_TIMER_PERIODIC, &generate_mid, ifp, mid_gen_timer_cookie->ci_id);
+                     MID_JITTER, OLSR_TIMER_PERIODIC, &generate_mid, ifp, mid_gen_timer_cookie);
   ifp->hna_gen_timer =
     olsr_start_timer(iface->cnf->hna_params.emission_interval * MSEC_PER_SEC,
-                     HNA_JITTER, OLSR_TIMER_PERIODIC, &generate_hna, ifp, hna_gen_timer_cookie->ci_id);
+                     HNA_JITTER, OLSR_TIMER_PERIODIC, &generate_hna, ifp, hna_gen_timer_cookie);
 
   ifp->hello_etime = (olsr_reltime) (iface->cnf->hello_params.emission_interval * MSEC_PER_SEC);
   ifp->valtimes.hello = reltime_to_me(iface->cnf->hello_params.validity_time * MSEC_PER_SEC);
@@ -715,16 +715,16 @@ chk_if_up(struct olsr_if_config *iface)
    */
   ifp->hello_gen_timer =
     olsr_start_timer(iface->cnf->hello_params.emission_interval * MSEC_PER_SEC,
-                     HELLO_JITTER, OLSR_TIMER_PERIODIC, &olsr_output_lq_hello, ifp, hello_gen_timer_cookie->ci_id);
+                     HELLO_JITTER, OLSR_TIMER_PERIODIC, &olsr_output_lq_hello, ifp, hello_gen_timer_cookie);
   ifp->tc_gen_timer =
     olsr_start_timer(iface->cnf->tc_params.emission_interval * MSEC_PER_SEC,
-                     TC_JITTER, OLSR_TIMER_PERIODIC, &olsr_output_lq_tc, ifp, tc_gen_timer_cookie->ci_id);
+                     TC_JITTER, OLSR_TIMER_PERIODIC, &olsr_output_lq_tc, ifp, tc_gen_timer_cookie);
   ifp->mid_gen_timer =
     olsr_start_timer(iface->cnf->mid_params.emission_interval * MSEC_PER_SEC,
-                     MID_JITTER, OLSR_TIMER_PERIODIC, &generate_mid, ifp, mid_gen_timer_cookie->ci_id);
+                     MID_JITTER, OLSR_TIMER_PERIODIC, &generate_mid, ifp, mid_gen_timer_cookie);
   ifp->hna_gen_timer =
     olsr_start_timer(iface->cnf->hna_params.emission_interval * MSEC_PER_SEC,
-                     HNA_JITTER, OLSR_TIMER_PERIODIC, &generate_hna, ifp, hna_gen_timer_cookie->ci_id);
+                     HNA_JITTER, OLSR_TIMER_PERIODIC, &generate_hna, ifp, hna_gen_timer_cookie);
 
   ifp->hello_etime = (olsr_reltime) (iface->cnf->hello_params.emission_interval * MSEC_PER_SEC);
   ifp->valtimes.hello = reltime_to_me(iface->cnf->hello_params.validity_time * MSEC_PER_SEC);