Initialize route table with local routes. Fix bugs.
[trust_router.git] / include / trp_rtable.h
1 #ifndef _TRP_RTABLE_H_
2 #define _TRP_RTABLE_H_
3
4 #include <glib.h>
5 #include <talloc.h>
6 #include <time.h>
7
8 #include <trp_internal.h>
9
10 typedef struct trp_rentry {
11   TR_NAME *apc;
12   TR_NAME *realm;
13   TR_NAME *peer;
14   unsigned int metric;
15   TR_NAME *trust_router;
16   TR_NAME *next_hop;
17   int selected;
18   unsigned int interval; /* interval from route update */
19   struct timespec *expiry;
20 } TRP_RENTRY;
21
22 typedef GHashTable TRP_RTABLE;
23
24 TRP_RTABLE *trp_rtable_new(void);
25 void trp_rtable_free(TRP_RTABLE *rtbl);
26 void trp_rtable_add(TRP_RTABLE *rtbl, TRP_RENTRY *entry); /* adds or updates */
27 void trp_rtable_remove(TRP_RTABLE *rtbl, TRP_RENTRY *entry);
28 void trp_rtable_clear(TRP_RTABLE *rtbl);
29 size_t trp_rtable_size(TRP_RTABLE *rtbl);
30 size_t trp_rtable_apc_size(TRP_RTABLE *rtbl, TR_NAME *apc);
31 size_t trp_rtable_realm_size(TRP_RTABLE *rtbl, TR_NAME *apc, TR_NAME *realm);
32 TRP_RENTRY **trp_rtable_get_entries(TRP_RTABLE *rtbl, size_t *n_out);
33 TR_NAME **trp_rtable_get_apcs(TRP_RTABLE *rtbl, size_t *n_out);
34 TRP_RENTRY **trp_rtable_get_apc_entries(TRP_RTABLE *rtbl, TR_NAME *apc, size_t *n_out);
35 TR_NAME **trp_rtable_get_apc_realms(TRP_RTABLE *rtbl, TR_NAME *apc, size_t *n_out);
36 TRP_RENTRY **trp_rtable_get_realm_entries(TRP_RTABLE *rtbl, TR_NAME *apc, TR_NAME *realm, size_t *n_out);
37 TR_NAME **trp_rtable_get_apc_realm_peers(TRP_RTABLE *rtbl, TR_NAME *apc, TR_NAME *realm, size_t *n_out);
38 TRP_RENTRY *trp_rtable_get_entry(TRP_RTABLE *rtbl, TR_NAME *apc, TR_NAME *realm, TR_NAME *peer);
39 TRP_RENTRY *trp_rtable_get_selected_entry(TRP_RTABLE *rtbl, TR_NAME *apc, TR_NAME *realm);
40 char *trp_rtable_to_str(TALLOC_CTX *mem_ctx, TRP_RTABLE *rtbl, const char *sep, const char *lineterm);
41
42 TRP_RENTRY *trp_rentry_new(TALLOC_CTX *mem_ctx);
43 void trp_rentry_free(TRP_RENTRY *entry);
44 void trp_rentry_set_apc(TRP_RENTRY *entry, TR_NAME *apc);
45 TR_NAME *trp_rentry_get_apc(TRP_RENTRY *entry);
46 TR_NAME *trp_rentry_dup_apc(TRP_RENTRY *entry);
47 void trp_rentry_set_realm(TRP_RENTRY *entry, TR_NAME *realm);
48 TR_NAME *trp_rentry_get_realm(TRP_RENTRY *entry);
49 TR_NAME *trp_rentry_dup_realm(TRP_RENTRY *entry);
50 void trp_rentry_set_trust_router(TRP_RENTRY *entry, TR_NAME *tr);
51 TR_NAME *trp_rentry_get_trust_router(TRP_RENTRY *entry);
52 TR_NAME *trp_rentry_dup_trust_router(TRP_RENTRY *entry);
53 void trp_rentry_set_peer(TRP_RENTRY *entry, TR_NAME *peer);
54 TR_NAME *trp_rentry_get_peer(TRP_RENTRY *entry);
55 TR_NAME *trp_rentry_dup_peer(TRP_RENTRY *entry);
56 void trp_rentry_set_metric(TRP_RENTRY *entry, unsigned int metric);
57 unsigned int trp_rentry_get_metric(TRP_RENTRY *entry);
58 void trp_rentry_set_next_hop(TRP_RENTRY *entry, TR_NAME *next_hop);
59 TR_NAME *trp_rentry_get_next_hop(TRP_RENTRY *entry);
60 TR_NAME *trp_rentry_dup_next_hop(TRP_RENTRY *entry);
61 void trp_rentry_set_selected(TRP_RENTRY *entry, int sel);
62 int trp_rentry_get_selected(TRP_RENTRY *entry);
63 void trp_rentry_set_interval(TRP_RENTRY *entry, int interval);
64 int trp_rentry_get_interval(TRP_RENTRY *entry);
65 void trp_rentry_set_expiry(TRP_RENTRY *entry, struct timespec *exp);
66 struct timespec *trp_rentry_get_expiry(TRP_RENTRY *entry);
67 char *trp_rentry_to_str(TALLOC_CTX *mem_ctx, TRP_RENTRY *entry, const char *sep);
68
69 #endif /* _TRP_RTABLE_H_ */