Add a 'request_id' to TID requests and responses
[trust_router.git] / include / trp_rtable.h
1 /*
2  * Copyright (c) 2016, JANET(UK)
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  *
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * 3. Neither the name of JANET(UK) nor the names of its contributors
17  *    may be used to endorse or promote products derived from this software
18  *    without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
25  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
31  * OF THE POSSIBILITY OF SUCH DAMAGE.
32  *
33  */
34
35 #ifndef _TRP_RTABLE_H_
36 #define _TRP_RTABLE_H_
37
38 #include <glib.h>
39 #include <talloc.h>
40 #include <time.h>
41
42 #include <trp_internal.h>
43
44 typedef struct trp_route {
45   TR_NAME *comm;
46   TR_NAME *realm;
47   TR_NAME *peer;
48   unsigned int metric;
49   TR_NAME *trust_router; /* hostname */
50   unsigned int trp_port;
51   unsigned int tid_port;
52   TR_NAME *next_hop;
53   int selected;
54   unsigned int interval; /* interval from route update */
55   struct timespec *expiry;
56   int local; /* is this a local route? */
57   int triggered;
58 } TRP_ROUTE;
59
60 typedef GHashTable TRP_RTABLE;
61
62 TRP_RTABLE *trp_rtable_new(void);
63 void trp_rtable_free(TRP_RTABLE *rtbl);
64 void trp_rtable_add(TRP_RTABLE *rtbl, TRP_ROUTE *entry); /* adds or updates */
65 void trp_rtable_remove(TRP_RTABLE *rtbl, TRP_ROUTE *entry);
66 void trp_rtable_clear(TRP_RTABLE *rtbl);
67 size_t trp_rtable_size(TRP_RTABLE *rtbl);
68 size_t trp_rtable_comm_size(TRP_RTABLE *rtbl, TR_NAME *comm);
69 size_t trp_rtable_realm_size(TRP_RTABLE *rtbl, TR_NAME *comm, TR_NAME *realm);
70 TRP_ROUTE **trp_rtable_get_entries(TRP_RTABLE *rtbl, size_t *n_out);
71 TR_NAME **trp_rtable_get_comms(TRP_RTABLE *rtbl, size_t *n_out);
72 TRP_ROUTE **trp_rtable_get_comm_entries(TRP_RTABLE *rtbl, TR_NAME *comm, size_t *n_out);
73 TR_NAME **trp_rtable_get_comm_realms(TRP_RTABLE *rtbl, TR_NAME *comm, size_t *n_out);
74 TRP_ROUTE **trp_rtable_get_realm_entries(TRP_RTABLE *rtbl, TR_NAME *comm, TR_NAME *realm, size_t *n_out);
75 TR_NAME **trp_rtable_get_comm_realm_peers(TRP_RTABLE *rtbl, TR_NAME *comm, TR_NAME *realm, size_t *n_out);
76 TRP_ROUTE *trp_rtable_get_entry(TRP_RTABLE *rtbl, TR_NAME *comm, TR_NAME *realm, TR_NAME *peer);
77 TRP_ROUTE *trp_rtable_get_selected_entry(TRP_RTABLE *rtbl, TR_NAME *comm, TR_NAME *realm);
78 void trp_rtable_clear_triggered(TRP_RTABLE *rtbl);
79 char *trp_rtable_to_str(TALLOC_CTX *mem_ctx, TRP_RTABLE *rtbl, const char *sep, const char *lineterm);
80
81 TRP_ROUTE *trp_route_new(TALLOC_CTX *mem_ctx);
82 void trp_route_free(TRP_ROUTE *entry);
83 void trp_route_set_comm(TRP_ROUTE *entry, TR_NAME *comm);
84 TR_NAME *trp_route_get_comm(TRP_ROUTE *entry);
85 TR_NAME *trp_route_dup_comm(TRP_ROUTE *entry);
86 void trp_route_set_realm(TRP_ROUTE *entry, TR_NAME *realm);
87 TR_NAME *trp_route_get_realm(TRP_ROUTE *entry);
88 TR_NAME *trp_route_dup_realm(TRP_ROUTE *entry);
89 void trp_route_set_trust_router(TRP_ROUTE *entry, TR_NAME *tr);
90 TR_NAME *trp_route_get_trust_router(TRP_ROUTE *entry);
91 TR_NAME *trp_route_dup_trust_router(TRP_ROUTE *entry);
92 void trp_route_set_peer(TRP_ROUTE *entry, TR_NAME *peer);
93 TR_NAME *trp_route_get_peer(TRP_ROUTE *entry);
94 TR_NAME *trp_route_dup_peer(TRP_ROUTE *entry);
95 void trp_route_set_metric(TRP_ROUTE *entry, unsigned int metric);
96 unsigned int trp_route_get_metric(TRP_ROUTE *entry);
97 void trp_route_set_next_hop(TRP_ROUTE *entry, TR_NAME *next_hop);
98 TR_NAME *trp_route_get_next_hop(TRP_ROUTE *entry);
99 TR_NAME *trp_route_dup_next_hop(TRP_ROUTE *entry);
100 void trp_route_set_selected(TRP_ROUTE *entry, int sel);
101 int trp_route_is_selected(TRP_ROUTE *entry);
102 void trp_route_set_interval(TRP_ROUTE *entry, int interval);
103 int trp_route_get_interval(TRP_ROUTE *entry);
104 void trp_route_set_expiry(TRP_ROUTE *entry, struct timespec *exp);
105 struct timespec *trp_route_get_expiry(TRP_ROUTE *entry);
106 void trp_route_set_local(TRP_ROUTE *entry, int local);
107 int trp_route_is_local(TRP_ROUTE *entry);
108 void trp_route_set_triggered(TRP_ROUTE *entry, int trig);
109 int trp_route_is_triggered(TRP_ROUTE *entry);
110 char *trp_route_to_str(TALLOC_CTX *mem_ctx, TRP_ROUTE *entry, const char *sep);
111
112 #endif /* _TRP_RTABLE_H_ */