Send triggered updates (not really tested).
[trust_router.git] / trp / trp_rtable.c
index 20caef7..7a519bb 100644 (file)
@@ -64,6 +64,11 @@ TR_NAME *trp_rentry_get_apc(TRP_RENTRY *entry)
   return entry->apc;
 }
 
+TR_NAME *trp_rentry_dup_apc(TRP_RENTRY *entry)
+{
+  return tr_dup_name(trp_rentry_get_apc(entry));
+}
+
 void trp_rentry_set_realm(TRP_RENTRY *entry, TR_NAME *realm)
 {
   entry->realm=realm;
@@ -74,6 +79,11 @@ TR_NAME *trp_rentry_get_realm(TRP_RENTRY *entry)
   return entry->realm;
 }
 
+TR_NAME *trp_rentry_dup_realm(TRP_RENTRY *entry)
+{
+  return tr_dup_name(trp_rentry_get_realm(entry));
+}
+
 void trp_rentry_set_trust_router(TRP_RENTRY *entry, TR_NAME *tr)
 {
   entry->trust_router=tr;
@@ -84,6 +94,11 @@ TR_NAME *trp_rentry_get_trust_router(TRP_RENTRY *entry)
   return entry->trust_router;
 }
 
+TR_NAME *trp_rentry_dup_trust_router(TRP_RENTRY *entry)
+{
+  return tr_dup_name(trp_rentry_get_trust_router(entry));
+}
+
 void trp_rentry_set_peer(TRP_RENTRY *entry, TR_NAME *peer)
 {
   entry->peer=peer;
@@ -94,6 +109,11 @@ TR_NAME *trp_rentry_get_peer(TRP_RENTRY *entry)
   return entry->peer;
 }
 
+TR_NAME *trp_rentry_dup_peer(TRP_RENTRY *entry)
+{
+  return tr_dup_name(trp_rentry_get_peer(entry));
+}
+
 void trp_rentry_set_metric(TRP_RENTRY *entry, unsigned int metric)
 {
   entry->metric=metric;
@@ -114,6 +134,11 @@ TR_NAME *trp_rentry_get_next_hop(TRP_RENTRY *entry)
   return entry->next_hop;
 }
 
+TR_NAME *trp_rentry_dup_next_hop(TRP_RENTRY *entry)
+{
+  return tr_dup_name(trp_rentry_get_next_hop(entry));
+}
+
 void trp_rentry_set_selected(TRP_RENTRY *entry, int sel)
 {
   entry->selected=sel;
@@ -146,6 +171,16 @@ struct timespec *trp_rentry_get_expiry(TRP_RENTRY *entry)
   return entry->expiry;
 }
 
+void trp_rentry_set_triggered(TRP_RENTRY *entry, int trig)
+{
+  entry->triggered=trig;
+}
+
+int trp_rentry_get_triggered(TRP_RENTRY *entry)
+{
+  return entry->triggered;
+}
+
 
 /* result must be freed with g_free */
 static gchar *tr_name_to_g_str(const TR_NAME *n)
@@ -230,6 +265,8 @@ void trp_rtable_add(TRP_RTABLE *rtbl, TRP_RENTRY *entry)
   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);
   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 */
@@ -256,6 +293,11 @@ void trp_rtable_remove(TRP_RTABLE *rtbl, TRP_RENTRY *entry)
     g_hash_table_remove(rtbl, entry->apc);
 }
 
+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)
 {
@@ -512,10 +554,11 @@ TR_NAME **trp_rtable_get_apc_realm_peers(TRP_RTABLE *rtbl, TR_NAME *apc, TR_NAME
 TRP_RENTRY *trp_rtable_get_entry(TRP_RTABLE *rtbl, TR_NAME *apc, TR_NAME *realm, TR_NAME *peer)
 {
   GHashTable *realm_tbl=NULL;
-  
+
   realm_tbl=trp_rtable_get_realm_table(rtbl, apc, realm);
   if (realm_tbl==NULL)
     return NULL;
+
   return g_hash_table_lookup(realm_tbl, peer); /* does not copy or increment ref count */
 }
 
@@ -587,6 +630,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_RENTRY **entries=trp_rtable_get_entries(rtbl, &n_entries);
+  size_t ii=0;
+
+  if (entries!=NULL) {
+    for (ii=0; ii<n_entries; ii++)
+      trp_rentry_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;