Peer organizations now parsed and added to peer table.
[trust_router.git] / trp / trp_rtable.c
index 6fbbd6f..fc11506 100644 (file)
 
 /* Note: be careful mixing talloc with glib. */
 
-static int trp_rentry_destructor(void *obj)
+static int trp_route_destructor(void *obj)
 {
-  TRP_RENTRY *entry=talloc_get_type_abort(obj, TRP_RENTRY);
-  if (entry->apc!=NULL)
-    tr_free_name(entry->apc);
+  TRP_ROUTE *entry=talloc_get_type_abort(obj, TRP_ROUTE);
+  if (entry->comm!=NULL)
+    tr_free_name(entry->comm);
   if (entry->realm!=NULL)
     tr_free_name(entry->realm);
   if (entry->trust_router!=NULL)
@@ -27,11 +27,11 @@ static int trp_rentry_destructor(void *obj)
   return 0;
 }
 
-TRP_RENTRY *trp_rentry_new(TALLOC_CTX *mem_ctx)
+TRP_ROUTE *trp_route_new(TALLOC_CTX *mem_ctx)
 {
-  TRP_RENTRY *entry=talloc(mem_ctx, TRP_RENTRY);
+  TRP_ROUTE *entry=talloc(mem_ctx, TRP_ROUTE);
   if (entry!=NULL) {
-    entry->apc=NULL;
+    entry->comm=NULL;
     entry->realm=NULL;
     entry->trust_router=NULL;
     entry->peer=NULL;
@@ -43,139 +43,174 @@ TRP_RENTRY *trp_rentry_new(TALLOC_CTX *mem_ctx)
       talloc_free(entry);
       return NULL;
     }
-    talloc_set_destructor((void *)entry, trp_rentry_destructor);
+    *(entry->expiry)=(struct timespec){0,0};
+    entry->local=0;
+    entry->triggered=0;
+    talloc_set_destructor((void *)entry, trp_route_destructor);
   }
   return entry;
 }
 
-void trp_rentry_free(TRP_RENTRY *entry)
+void trp_route_free(TRP_ROUTE *entry)
 {
   if (entry!=NULL)
     talloc_free(entry);
 }
 
-void trp_rentry_set_apc(TRP_RENTRY *entry, TR_NAME *apc)
+void trp_route_set_comm(TRP_ROUTE *entry, TR_NAME *comm)
 {
-  entry->apc=apc;
+  if (entry->comm!=NULL)
+    tr_free_name(entry->comm);
+  entry->comm=comm;
 }
 
-TR_NAME *trp_rentry_get_apc(TRP_RENTRY *entry)
+TR_NAME *trp_route_get_comm(TRP_ROUTE *entry)
 {
-  return entry->apc;
+  return entry->comm;
 }
 
-TR_NAME *trp_rentry_dup_apc(TRP_RENTRY *entry)
+TR_NAME *trp_route_dup_comm(TRP_ROUTE *entry)
 {
-  return tr_dup_name(trp_rentry_get_apc(entry));
+  return tr_dup_name(trp_route_get_comm(entry));
 }
 
-void trp_rentry_set_realm(TRP_RENTRY *entry, TR_NAME *realm)
+void trp_route_set_realm(TRP_ROUTE *entry, TR_NAME *realm)
 {
+  if (entry->realm!=NULL)
+    tr_free_name(entry->realm);
   entry->realm=realm;
 }
 
-TR_NAME *trp_rentry_get_realm(TRP_RENTRY *entry)
+TR_NAME *trp_route_get_realm(TRP_ROUTE *entry)
 {
   return entry->realm;
 }
 
-TR_NAME *trp_rentry_dup_realm(TRP_RENTRY *entry)
+TR_NAME *trp_route_dup_realm(TRP_ROUTE *entry)
 {
-  return tr_dup_name(trp_rentry_get_realm(entry));
+  return tr_dup_name(trp_route_get_realm(entry));
 }
 
-void trp_rentry_set_trust_router(TRP_RENTRY *entry, TR_NAME *tr)
+void trp_route_set_trust_router(TRP_ROUTE *entry, TR_NAME *tr)
 {
+  if (entry->trust_router!=NULL)
+    tr_free_name(entry->trust_router);
   entry->trust_router=tr;
 }
 
-TR_NAME *trp_rentry_get_trust_router(TRP_RENTRY *entry)
+TR_NAME *trp_route_get_trust_router(TRP_ROUTE *entry)
 {
   return entry->trust_router;
 }
 
-TR_NAME *trp_rentry_dup_trust_router(TRP_RENTRY *entry)
+TR_NAME *trp_route_dup_trust_router(TRP_ROUTE *entry)
 {
-  return tr_dup_name(trp_rentry_get_trust_router(entry));
+  return tr_dup_name(trp_route_get_trust_router(entry));
 }
 
-void trp_rentry_set_peer(TRP_RENTRY *entry, TR_NAME *peer)
+void trp_route_set_peer(TRP_ROUTE *entry, TR_NAME *peer)
 {
+  if (entry->peer!=NULL)
+    tr_free_name(entry->peer);
   entry->peer=peer;
 }
 
-TR_NAME *trp_rentry_get_peer(TRP_RENTRY *entry)
+TR_NAME *trp_route_get_peer(TRP_ROUTE *entry)
 {
   return entry->peer;
 }
 
-TR_NAME *trp_rentry_dup_peer(TRP_RENTRY *entry)
+TR_NAME *trp_route_dup_peer(TRP_ROUTE *entry)
 {
-  return tr_dup_name(trp_rentry_get_peer(entry));
+  return tr_dup_name(trp_route_get_peer(entry));
 }
 
-void trp_rentry_set_metric(TRP_RENTRY *entry, unsigned int metric)
+void trp_route_set_metric(TRP_ROUTE *entry, unsigned int metric)
 {
   entry->metric=metric;
 }
 
-unsigned int trp_rentry_get_metric(TRP_RENTRY *entry)
+unsigned int trp_route_get_metric(TRP_ROUTE *entry)
 {
   return entry->metric;
 }
 
-void trp_rentry_set_next_hop(TRP_RENTRY *entry, TR_NAME *next_hop)
+void trp_route_set_next_hop(TRP_ROUTE *entry, TR_NAME *next_hop)
 {
+  if (entry->next_hop!=NULL)
+    tr_free_name(entry->next_hop);
   entry->next_hop=next_hop;
 }
 
-TR_NAME *trp_rentry_get_next_hop(TRP_RENTRY *entry)
+TR_NAME *trp_route_get_next_hop(TRP_ROUTE *entry)
 {
   return entry->next_hop;
 }
 
-TR_NAME *trp_rentry_dup_next_hop(TRP_RENTRY *entry)
+TR_NAME *trp_route_dup_next_hop(TRP_ROUTE *entry)
 {
-  return tr_dup_name(trp_rentry_get_next_hop(entry));
+  return tr_dup_name(trp_route_get_next_hop(entry));
 }
 
-void trp_rentry_set_selected(TRP_RENTRY *entry, int sel)
+void trp_route_set_selected(TRP_ROUTE *entry, int sel)
 {
   entry->selected=sel;
 }
 
-int trp_rentry_get_selected(TRP_RENTRY *entry)
+int trp_route_is_selected(TRP_ROUTE *entry)
 {
   return entry->selected;
 }
 
-void trp_rentry_set_interval(TRP_RENTRY *entry, int interval)
+void trp_route_set_interval(TRP_ROUTE *entry, int interval)
 {
   entry->interval=interval;
 }
 
-int trp_rentry_get_interval(TRP_RENTRY *entry)
+int trp_route_get_interval(TRP_ROUTE *entry)
 {
   return entry->interval;
 }
 
 /* copies incoming value, does not assume responsibility for freeing */
-void trp_rentry_set_expiry(TRP_RENTRY *entry, struct timespec *exp)
+void trp_route_set_expiry(TRP_ROUTE *entry, struct timespec *exp)
 {
   entry->expiry->tv_sec=exp->tv_sec;
   entry->expiry->tv_nsec=exp->tv_nsec;
 }
 
-struct timespec *trp_rentry_get_expiry(TRP_RENTRY *entry)
+struct timespec *trp_route_get_expiry(TRP_ROUTE *entry)
 {
   return entry->expiry;
 }
 
+void trp_route_set_local(TRP_ROUTE *entry, int local)
+{
+  entry->local=local;
+}
+
+int trp_route_is_local(TRP_ROUTE *entry)
+{
+  return entry->local;
+}
+
+void trp_route_set_triggered(TRP_ROUTE *entry, int trig)
+{
+  entry->triggered=trig;
+}
+
+int trp_route_is_triggered(TRP_ROUTE *entry)
+{
+  return entry->triggered;
+}
+
 
 /* result must be freed with g_free */
 static gchar *tr_name_to_g_str(const TR_NAME *n)
 {
   gchar *s=g_strndup(n->buf, n->len);
+  if (s==NULL)
+    tr_debug("tr_name_to_g_str: allocation failure.");
   return s;
 }
 
@@ -202,7 +237,7 @@ static gboolean trp_tr_name_equal(gconstpointer key1, gconstpointer key2)
   return equal;
 }
 
-/* free a value to the top level rtable (a hash of all entries in the apc) */
+/* free a value to the top level rtable (a hash of all entries in the comm) */
 static void trp_rtable_destroy_table(gpointer data)
 {
   g_hash_table_destroy(data);
@@ -210,7 +245,7 @@ static void trp_rtable_destroy_table(gpointer data)
 
 static void trp_rtable_destroy_rentry(gpointer data)
 {
-  trp_rentry_free(data);
+  trp_route_free(data);
 }
 
 static void trp_rtable_destroy_tr_name(gpointer data)
@@ -247,27 +282,29 @@ static GHashTable *trp_rtbl_get_or_add_table(GHashTable *tbl, TR_NAME *key, GDes
   return val_tbl;
 }
 
-void trp_rtable_add(TRP_RTABLE *rtbl, TRP_RENTRY *entry)
+void trp_rtable_add(TRP_RTABLE *rtbl, TRP_ROUTE *entry)
 {
-  GHashTable *apc_tbl=NULL;
+  GHashTable *comm_tbl=NULL;
   GHashTable *realm_tbl=NULL;
 
-  apc_tbl=trp_rtbl_get_or_add_table(rtbl, entry->apc, trp_rtable_destroy_table);
-  realm_tbl=trp_rtbl_get_or_add_table(apc_tbl, entry->realm, trp_rtable_destroy_rentry);
+  comm_tbl=trp_rtbl_get_or_add_table(rtbl, entry->comm, trp_rtable_destroy_table);
+  realm_tbl=trp_rtbl_get_or_add_table(comm_tbl, entry->realm, trp_rtable_destroy_rentry);
   g_hash_table_insert(realm_tbl, tr_dup_name(entry->peer), entry); /* destroys and replaces a duplicate */
+  /* the route entry should not belong to any context, we will manage it ourselves */
+  talloc_steal(NULL, entry);
 }
 
 /* note: the entry pointer passed in is invalid after calling this because the entry is freed */
-void trp_rtable_remove(TRP_RTABLE *rtbl, TRP_RENTRY *entry)
+void trp_rtable_remove(TRP_RTABLE *rtbl, TRP_ROUTE *entry)
 {
-  GHashTable *apc_tbl=NULL;
+  GHashTable *comm_tbl=NULL;
   GHashTable *realm_tbl=NULL;
 
-  apc_tbl=g_hash_table_lookup(rtbl, entry->apc);
-  if (apc_tbl==NULL)
+  comm_tbl=g_hash_table_lookup(rtbl, entry->comm);
+  if (comm_tbl==NULL)
     return;
 
-  realm_tbl=g_hash_table_lookup(apc_tbl, entry->realm);
+  realm_tbl=g_hash_table_lookup(comm_tbl, entry->realm);
   if (realm_tbl==NULL)
     return;
 
@@ -275,26 +312,31 @@ void trp_rtable_remove(TRP_RTABLE *rtbl, TRP_RENTRY *entry)
   g_hash_table_remove(realm_tbl, entry->peer);
   /* if that was the last entry in the realm, remove the realm table */
   if (g_hash_table_size(realm_tbl)==0)
-    g_hash_table_remove(apc_tbl, entry->realm);
-  /* if that was the last realm in the apc, remove the apc table */
-  if (g_hash_table_size(apc_tbl)==0)
-    g_hash_table_remove(rtbl, entry->apc);
+    g_hash_table_remove(comm_tbl, entry->realm);
+  /* if that was the last realm in the comm, remove the comm table */
+  if (g_hash_table_size(comm_tbl)==0)
+    g_hash_table_remove(rtbl, entry->comm);
+}
+
+void trp_rtable_clear(TRP_RTABLE *rtbl)
+{
+  g_hash_table_remove_all(rtbl); /* destructors should do all the cleanup */
 }
 
 /* gets the actual hash table, for internal use only */
-static GHashTable *trp_rtable_get_apc_table(TRP_RTABLE *rtbl, TR_NAME *apc)
+static GHashTable *trp_rtable_get_comm_table(TRP_RTABLE *rtbl, TR_NAME *comm)
 {
-  return g_hash_table_lookup(rtbl, apc);
+  return g_hash_table_lookup(rtbl, comm);
 }
 
 /* gets the actual hash table, for internal use only */
-static GHashTable *trp_rtable_get_realm_table(TRP_RTABLE *rtbl, TR_NAME *apc, TR_NAME *realm)
+static GHashTable *trp_rtable_get_realm_table(TRP_RTABLE *rtbl, TR_NAME *comm, TR_NAME *realm)
 {
-  GHashTable *apc_tbl=trp_rtable_get_apc_table(rtbl, apc);
-  if (apc_tbl==NULL)
+  GHashTable *comm_tbl=trp_rtable_get_comm_table(rtbl, comm);
+  if (comm_tbl==NULL)
     return NULL;
   else
-    return g_hash_table_lookup(apc_tbl, realm);
+    return g_hash_table_lookup(comm_tbl, realm);
 }
 
 struct table_size_cookie {
@@ -304,7 +346,7 @@ struct table_size_cookie {
 static void trp_rtable_size_helper(gpointer key, gpointer value, gpointer user_data)
 {
   struct table_size_cookie *data=(struct table_size_cookie *)user_data;
-  data->size += trp_rtable_apc_size(data->rtbl, (TR_NAME *)key);
+  data->size += trp_rtable_comm_size(data->rtbl, (TR_NAME *)key);
 };
 size_t trp_rtable_size(TRP_RTABLE *rtbl)
 {
@@ -313,46 +355,46 @@ size_t trp_rtable_size(TRP_RTABLE *rtbl)
   return data.size;
 }
 
-struct table_apc_size_cookie {
-  TR_NAME *apc;
+struct table_comm_size_cookie {
+  TR_NAME *comm;
   TRP_RTABLE *rtbl;
   size_t size;
 };
-static void table_apc_size_helper(gpointer key, gpointer value, gpointer user_data)
+static void table_comm_size_helper(gpointer key, gpointer value, gpointer user_data)
 {
-  struct table_apc_size_cookie *data=(struct table_apc_size_cookie *)user_data;
-  data->size += trp_rtable_realm_size(data->rtbl, data->apc, (TR_NAME *)key);
+  struct table_comm_size_cookie *data=(struct table_comm_size_cookie *)user_data;
+  data->size += trp_rtable_realm_size(data->rtbl, data->comm, (TR_NAME *)key);
 }
-size_t trp_rtable_apc_size(TRP_RTABLE *rtbl, TR_NAME *apc)
+size_t trp_rtable_comm_size(TRP_RTABLE *rtbl, TR_NAME *comm)
 {
-  struct table_apc_size_cookie data={apc, rtbl, 0};
-  GHashTable *apc_tbl=trp_rtable_get_apc_table(rtbl, apc);
-  if (apc_tbl==NULL)
+  struct table_comm_size_cookie data={comm, rtbl, 0};
+  GHashTable *comm_tbl=trp_rtable_get_comm_table(rtbl, comm);
+  if (comm_tbl==NULL)
     return 0;;
-  g_hash_table_foreach(apc_tbl, table_apc_size_helper, &data);
+  g_hash_table_foreach(comm_tbl, table_comm_size_helper, &data);
   return data.size;
 }
 
-size_t trp_rtable_realm_size(TRP_RTABLE *rtbl, TR_NAME *apc, TR_NAME *realm)
+size_t trp_rtable_realm_size(TRP_RTABLE *rtbl, TR_NAME *comm, TR_NAME *realm)
 {
-  GHashTable *realm_tbl=trp_rtable_get_realm_table(rtbl, apc, realm);
+  GHashTable *realm_tbl=trp_rtable_get_realm_table(rtbl, comm, realm);
   if (realm_tbl==NULL)
     return 0;
   else
     return g_hash_table_size(g_hash_table_lookup(
-                               g_hash_table_lookup(rtbl, apc),
+                               g_hash_table_lookup(rtbl, comm),
                                realm));
 }
 
-/* Returns an array of pointers to TRP_RENTRY, length of array in n_out.
+/* Returns an array of pointers to TRP_ROUTE, length of array in n_out.
  * Caller must free the array (in the talloc NULL context), but must
  * not free its contents. */
-TRP_RENTRY **trp_rtable_get_entries(TRP_RTABLE *rtbl, size_t *n_out)
+TRP_ROUTE **trp_rtable_get_entries(TRP_RTABLE *rtbl, size_t *n_out)
 {
-  TRP_RENTRY **ret=NULL;
-  TR_NAME **apc=NULL;
-  size_t n_apc=0;
-  TRP_RENTRY **apc_entries=NULL;
+  TRP_ROUTE **ret=NULL;
+  TR_NAME **comm=NULL;
+  size_t n_comm=0;
+  TRP_ROUTE **comm_entries=NULL;
   size_t n_entries=0;
   size_t ii_ret=0;
 
@@ -360,7 +402,7 @@ TRP_RENTRY **trp_rtable_get_entries(TRP_RTABLE *rtbl, size_t *n_out)
   if (*n_out==0)
     return NULL;
 
-  ret=talloc_array(NULL, TRP_RENTRY *, *n_out);
+  ret=talloc_array(NULL, TRP_ROUTE *, *n_out);
   if (ret==NULL) {
     tr_crit("trp_rtable_get_entries: unable to allocate return array.");
     *n_out=0;
@@ -368,14 +410,14 @@ TRP_RENTRY **trp_rtable_get_entries(TRP_RTABLE *rtbl, size_t *n_out)
   }
 
   ii_ret=0; /* counts output entries */
-  apc=trp_rtable_get_apcs(rtbl, &n_apc);
-  while(n_apc--) {
-    apc_entries=trp_rtable_get_apc_entries(rtbl, apc[n_apc], &n_entries);
+  comm=trp_rtable_get_comms(rtbl, &n_comm);
+  while(n_comm--) {
+    comm_entries=trp_rtable_get_comm_entries(rtbl, comm[n_comm], &n_entries);
     while (n_entries--)
-      ret[ii_ret++]=apc_entries[n_entries];
-    talloc_free(apc_entries);
+      ret[ii_ret++]=comm_entries[n_entries];
+    talloc_free(comm_entries);
   }
-  talloc_free(apc);
+  talloc_free(comm);
 
   if (ii_ret!=*n_out) {
     tr_crit("trp_rtable_get_entries: found incorrect number of entries.");
@@ -388,11 +430,11 @@ TRP_RENTRY **trp_rtable_get_entries(TRP_RTABLE *rtbl, size_t *n_out)
 
 /* Returns an array of pointers to TR_NAME, length of array in n_out.
  * Caller must free the array (in the talloc NULL context). */
-TR_NAME **trp_rtable_get_apcs(TRP_RTABLE *rtbl, size_t *n_out)
+TR_NAME **trp_rtable_get_comms(TRP_RTABLE *rtbl, size_t *n_out)
 {
-  size_t len=g_hash_table_size(rtbl); /* known apcs are keys in top level hash table */
+  size_t len=g_hash_table_size(rtbl); /* known comms are keys in top level hash table */
   size_t ii=0;
-  GList *apcs=NULL;;
+  GList *comms=NULL;;
   GList *p=NULL;
   TR_NAME **ret=NULL;
 
@@ -403,15 +445,15 @@ TR_NAME **trp_rtable_get_apcs(TRP_RTABLE *rtbl, size_t *n_out)
     
   ret=talloc_array(NULL, TR_NAME *, len);
   if (ret==NULL) {
-    tr_crit("trp_rtable_get_apcs: unable to allocate return array.");
+    tr_crit("trp_rtable_get_comms: unable to allocate return array.");
     *n_out=0;
     return NULL;
   }
-  apcs=g_hash_table_get_keys(rtbl);
-  for (ii=0,p=apcs; p!=NULL; ii++,p=g_list_next(p))
+  comms=g_hash_table_get_keys(rtbl);
+  for (ii=0,p=comms; p!=NULL; ii++,p=g_list_next(p))
     ret[ii]=(TR_NAME *)p->data;
 
-  g_list_free(apcs);
+  g_list_free(comms);
 
   *n_out=len;
   return ret;
@@ -419,21 +461,21 @@ TR_NAME **trp_rtable_get_apcs(TRP_RTABLE *rtbl, size_t *n_out)
 
 /* Returns an array of pointers to TR_NAME, length of array in n_out.
  * Caller must free the array (in the talloc NULL context). */
-TR_NAME **trp_rtable_get_apc_realms(TRP_RTABLE *rtbl, TR_NAME *apc, size_t *n_out)
+TR_NAME **trp_rtable_get_comm_realms(TRP_RTABLE *rtbl, TR_NAME *comm, size_t *n_out)
 {
   size_t ii=0;
-  TRP_RTABLE *apc_tbl=g_hash_table_lookup(rtbl, apc);;
+  TRP_RTABLE *comm_tbl=g_hash_table_lookup(rtbl, comm);;
   GList *entries=NULL;
   GList *p=NULL;
   TR_NAME **ret=NULL;
 
-  if (apc_tbl==NULL) {
+  if (comm_tbl==NULL) {
     *n_out=0;
     return NULL;
   }
-  *n_out=g_hash_table_size(apc_tbl); /* set output length */
+  *n_out=g_hash_table_size(comm_tbl); /* set output length */
   ret=talloc_array(NULL, TR_NAME *, *n_out);
-  entries=g_hash_table_get_keys(apc_tbl);
+  entries=g_hash_table_get_keys(comm_tbl);
   for (ii=0,p=entries; p!=NULL; ii++,p=g_list_next(p))
     ret[ii]=(TR_NAME *)p->data;
 
@@ -441,34 +483,34 @@ TR_NAME **trp_rtable_get_apc_realms(TRP_RTABLE *rtbl, TR_NAME *apc, size_t *n_ou
   return ret;
 }
 
-/* Get all entries in an apc. Returns an array of pointers in NULL talloc context.
+/* Get all entries in an comm. Returns an array of pointers in NULL talloc context.
  * Caller must free this list with talloc_free, but must not free the entries in the
  * list.. */
-TRP_RENTRY **trp_rtable_get_apc_entries(TRP_RTABLE *rtbl, TR_NAME *apc, size_t *n_out)
+TRP_ROUTE **trp_rtable_get_comm_entries(TRP_RTABLE *rtbl, TR_NAME *comm, size_t *n_out)
 {
   size_t ii=0, jj=0;
   TR_NAME **realm=NULL;
   size_t n_realms=0;
-  TRP_RENTRY **realm_entries=NULL;
+  TRP_ROUTE **realm_entries=NULL;
   size_t n_entries=0;
-  TRP_RENTRY **ret=NULL;
+  TRP_ROUTE **ret=NULL;
   size_t ii_ret=0;
 
-  *n_out=trp_rtable_apc_size(rtbl, apc);
+  *n_out=trp_rtable_comm_size(rtbl, comm);
   if (*n_out==0)
     return NULL;
 
-  ret=talloc_array(NULL, TRP_RENTRY *, *n_out);
+  ret=talloc_array(NULL, TRP_ROUTE *, *n_out);
   if (ret==NULL) {
-    tr_crit("trp_rtable_get_apc_entries: could not allocate return array.");
+    tr_crit("trp_rtable_get_comm_entries: could not allocate return array.");
     *n_out=0;
     return NULL;
   }
   
   ii_ret=0; /* counts entries in the output array */
-  realm=trp_rtable_get_apc_realms(rtbl, apc, &n_realms);
+  realm=trp_rtable_get_comm_realms(rtbl, comm, &n_realms);
   for (ii=0; ii<n_realms; ii++) {
-    realm_entries=trp_rtable_get_realm_entries(rtbl, apc, realm[ii], &n_entries);
+    realm_entries=trp_rtable_get_realm_entries(rtbl, comm, realm[ii], &n_entries);
     for (jj=0; jj<n_entries; jj++)
       ret[ii_ret++]=realm_entries[jj];
     talloc_free(realm_entries);
@@ -476,7 +518,7 @@ TRP_RENTRY **trp_rtable_get_apc_entries(TRP_RTABLE *rtbl, TR_NAME *apc, size_t *
   talloc_free(realm);
 
   if (ii_ret!=*n_out) {
-    tr_crit("trp_rtable_get_apc_entries: found incorrect number of entries.");
+    tr_crit("trp_rtable_get_comm_entries: found incorrect number of entries.");
     talloc_free(ret);
     *n_out=0;
     return NULL;
@@ -485,17 +527,17 @@ TRP_RENTRY **trp_rtable_get_apc_entries(TRP_RTABLE *rtbl, TR_NAME *apc, size_t *
   return ret;
 }
 
-/* Get all entries in an apc/realm. Returns an array of pointers in NULL talloc context.
+/* Get all entries in an comm/realm. Returns an array of pointers in NULL talloc context.
  * Caller must free this list with talloc_free, but must not free the entries in the
  * list.. */
-TRP_RENTRY **trp_rtable_get_realm_entries(TRP_RTABLE *rtbl, TR_NAME *apc, TR_NAME *realm, size_t *n_out)
+TRP_ROUTE **trp_rtable_get_realm_entries(TRP_RTABLE *rtbl, TR_NAME *comm, TR_NAME *realm, size_t *n_out)
 {
   size_t ii=0;
-  TRP_RENTRY **ret=NULL;
+  TRP_ROUTE **ret=NULL;
   TR_NAME **peer=NULL;
 
-  peer=trp_rtable_get_apc_realm_peers(rtbl, apc, realm, n_out);
-  ret=talloc_array(NULL, TRP_RENTRY *, *n_out);
+  peer=trp_rtable_get_comm_realm_peers(rtbl, comm, realm, n_out);
+  ret=talloc_array(NULL, TRP_ROUTE *, *n_out);
   if (ret==NULL) {
     tr_crit("trp_rtable_get_realm_entries: could not allocate return array.");
     talloc_free(peer);
@@ -503,12 +545,12 @@ TRP_RENTRY **trp_rtable_get_realm_entries(TRP_RTABLE *rtbl, TR_NAME *apc, TR_NAM
     return NULL;
   }
   for (ii=0; ii<*n_out; ii++)
-    ret[ii]=trp_rtable_get_entry(rtbl, apc, realm, peer[ii]);
+    ret[ii]=trp_rtable_get_entry(rtbl, comm, realm, peer[ii]);
   talloc_free(peer);
   return ret;
 }
 
-TR_NAME **trp_rtable_get_apc_realm_peers(TRP_RTABLE *rtbl, TR_NAME *apc, TR_NAME *realm, size_t *n_out)
+TR_NAME **trp_rtable_get_comm_realm_peers(TRP_RTABLE *rtbl, TR_NAME *comm, TR_NAME *realm, size_t *n_out)
 {
   TR_NAME **ret=NULL;
   GHashTable *realm_tbl=NULL;
@@ -516,13 +558,13 @@ TR_NAME **trp_rtable_get_apc_realm_peers(TRP_RTABLE *rtbl, TR_NAME *apc, TR_NAME
   GList *p=NULL;
   size_t ii=0;
 
-  *n_out=trp_rtable_realm_size(rtbl, apc, realm);
+  *n_out=trp_rtable_realm_size(rtbl, comm, realm);
   if (*n_out==0)
     return NULL;
-  realm_tbl=trp_rtable_get_realm_table(rtbl, apc, realm);
+  realm_tbl=trp_rtable_get_realm_table(rtbl, comm, realm);
   ret=talloc_array(NULL, TR_NAME *, *n_out);
   if (ret==NULL) {
-    tr_crit("trp_rtable_get_apc_realm_peers: could not allocate return array.");
+    tr_crit("trp_rtable_get_comm_realm_peers: could not allocate return array.");
     *n_out=0;
     return NULL;
   }
@@ -534,13 +576,14 @@ TR_NAME **trp_rtable_get_apc_realm_peers(TRP_RTABLE *rtbl, TR_NAME *apc, TR_NAME
 }
 
 /* Gets a single entry. Do not free it. */
-TRP_RENTRY *trp_rtable_get_entry(TRP_RTABLE *rtbl, TR_NAME *apc, TR_NAME *realm, TR_NAME *peer)
+TRP_ROUTE *trp_rtable_get_entry(TRP_RTABLE *rtbl, TR_NAME *comm, TR_NAME *realm, TR_NAME *peer)
 {
   GHashTable *realm_tbl=NULL;
-  
-  realm_tbl=trp_rtable_get_realm_table(rtbl, apc, realm);
+
+  realm_tbl=trp_rtable_get_realm_table(rtbl, comm, realm);
   if (realm_tbl==NULL)
     return NULL;
+
   return g_hash_table_lookup(realm_tbl, peer); /* does not copy or increment ref count */
 }
 
@@ -563,16 +606,16 @@ static char *timespec_to_str(struct timespec *ts)
   return s;
 }
 
-TRP_RENTRY *trp_rtable_get_selected_entry(TRP_RTABLE *rtbl, TR_NAME *apc, TR_NAME *realm)
+TRP_ROUTE *trp_rtable_get_selected_entry(TRP_RTABLE *rtbl, TR_NAME *comm, TR_NAME *realm)
 {
   size_t n=0;
-  TRP_RENTRY **entry=trp_rtable_get_realm_entries(rtbl, apc, realm, &n);
-  TRP_RENTRY *selected=NULL;
+  TRP_ROUTE **entry=trp_rtable_get_realm_entries(rtbl, comm, realm, &n);
+  TRP_ROUTE *selected=NULL;
 
   if (n==0)
     return NULL;
 
-  while(n-- && !trp_rentry_get_selected(entry[n])) { }
+  while(n-- && !trp_route_is_selected(entry[n])) { }
   selected=entry[n];
   talloc_free(entry);
   return selected;
@@ -580,9 +623,9 @@ TRP_RENTRY *trp_rtable_get_selected_entry(TRP_RTABLE *rtbl, TR_NAME *apc, TR_NAM
 
 /* Pretty print a route table entry to a newly allocated string. If sep is NULL,
  * returns comma+space separated string. */
-char *trp_rentry_to_str(TALLOC_CTX *mem_ctx, TRP_RENTRY *entry, const char *sep)
+char *trp_route_to_str(TALLOC_CTX *mem_ctx, TRP_ROUTE *entry, const char *sep)
 {
-  char *apc=tr_name_strdup(entry->apc);
+  char *comm=tr_name_strdup(entry->comm);
   char *realm=tr_name_strdup(entry->realm);
   char *peer=tr_name_strdup(entry->peer);
   char *trust_router=tr_name_strdup(entry->trust_router);
@@ -594,16 +637,18 @@ char *trp_rentry_to_str(TALLOC_CTX *mem_ctx, TRP_RENTRY *entry, const char *sep)
     sep=", ";
 
   result=talloc_asprintf(mem_ctx,
-                         "%s%s%s%s%s%s%u%s%s%s%s%s%d%s%s",
-                         apc, sep,
+                         "%s%s%s%s%s%s%u%s%s%s%s%s%u%s%u%s%s%s%u",
+                         comm, sep,
                          realm, sep,
                          peer, sep,
                          entry->metric, sep,
                          trust_router, sep,
                          next_hop, sep,
                          entry->selected, sep,
-                         expiry);
-  free(apc);
+                         entry->local, sep,
+                         expiry, sep,
+                         entry->triggered);
+  free(comm);
   free(realm);
   free(peer);
   free(trust_router);
@@ -612,6 +657,19 @@ char *trp_rentry_to_str(TALLOC_CTX *mem_ctx, TRP_RENTRY *entry, const char *sep)
   return result;
 }
 
+void trp_rtable_clear_triggered(TRP_RTABLE *rtbl)
+{
+  size_t n_entries=0;
+  TRP_ROUTE **entries=trp_rtable_get_entries(rtbl, &n_entries);
+  size_t ii=0;
+
+  if (entries!=NULL) {
+    for (ii=0; ii<n_entries; ii++)
+      trp_route_set_triggered(entries[ii], 0);
+    talloc_free(entries);
+  }
+}
+
 static int sort_tr_names_cmp(const void *a, const void *b)
 {
   TR_NAME **n1=(TR_NAME **)a;
@@ -627,11 +685,11 @@ static void sort_tr_names(TR_NAME **names, size_t n_names)
 char *trp_rtable_to_str(TALLOC_CTX *mem_ctx, TRP_RTABLE *rtbl, const char *sep, const char *lineterm)
 {
   TALLOC_CTX *tmp_ctx=talloc_new(NULL);
-  TR_NAME **apcs=NULL;
-  size_t n_apcs=0;
+  TR_NAME **comms=NULL;
+  size_t n_comms=0;
   TR_NAME **realms=NULL;
   size_t n_realms=0;
-  TRP_RENTRY **entries=NULL;
+  TRP_ROUTE **entries=NULL;
   size_t n_entries=0;
   char **tbl_strings=NULL;
   size_t ii_tbl=0; /* counts tbl_strings */
@@ -656,20 +714,20 @@ char *trp_rtable_to_str(TALLOC_CTX *mem_ctx, TRP_RTABLE *rtbl, const char *sep,
     goto cleanup;
   }
   
-  apcs=trp_rtable_get_apcs(rtbl, &n_apcs);
-  talloc_steal(tmp_ctx, apcs);
-  sort_tr_names(apcs, n_apcs);
+  comms=trp_rtable_get_comms(rtbl, &n_comms);
+  talloc_steal(tmp_ctx, comms);
+  sort_tr_names(comms, n_comms);
   ii_tbl=0;
   len=0;
-  for (ii=0; ii<n_apcs; ii++) {
-    realms=trp_rtable_get_apc_realms(rtbl, apcs[ii], &n_realms);
+  for (ii=0; ii<n_comms; ii++) {
+    realms=trp_rtable_get_comm_realms(rtbl, comms[ii], &n_realms);
     talloc_steal(tmp_ctx, realms);
     sort_tr_names(realms, n_realms);
     for (jj=0; jj<n_realms; jj++) {
-      entries=trp_rtable_get_realm_entries(rtbl, apcs[ii], realms[jj], &n_entries);
+      entries=trp_rtable_get_realm_entries(rtbl, comms[ii], realms[jj], &n_entries);
       talloc_steal(tmp_ctx, entries);
       for (kk=0; kk<n_entries; kk++) {
-        tbl_strings[ii_tbl]=trp_rentry_to_str(tmp_ctx, entries[kk], sep);
+        tbl_strings[ii_tbl]=trp_route_to_str(tmp_ctx, entries[kk], sep);
         len+=strlen(tbl_strings[ii_tbl]);
         ii_tbl++;
       }
@@ -677,7 +735,7 @@ char *trp_rtable_to_str(TALLOC_CTX *mem_ctx, TRP_RTABLE *rtbl, const char *sep,
     }
     talloc_free(realms);
   }
-  talloc_free(apcs);
+  talloc_free(comms);
 
   /* now combine all the strings */
   len += tbl_size*strlen(lineterm); /* space for line terminations*/