2 * Copyright (c) 2016, JANET(UK)
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
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.
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.
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.
40 #include <trust_router/tr_name.h>
41 #include <trust_router/tr_versioning.h>
43 #define TRP_PORT 12308
44 #define TRP_METRIC_INFINITY 0xFFFF
45 #define TRP_METRIC_INVALID 0xFFFFFFFF
46 #define trp_metric_is_finite(x) (((x)<TRP_METRIC_INFINITY) && ((x)!=TRP_METRIC_INVALID))
47 #define trp_metric_is_infinite(x) ((x)==TRP_METRIC_INFINITY)
48 #define trp_metric_is_valid(x) (((x)<=TRP_METRIC_INFINITY) && ((x)!=TRP_METRIC_INVALID))
49 #define trp_metric_is_invalid(x) (((x)>TRP_METRIC_INFINITY) || ((x)==TRP_METRIC_INVALID))
50 #define TRP_INTERVAL_INVALID 0
52 #define TRP_LINKCOST_DEFAULT 1
56 TRP_ERROR, /* generic error */
57 TRP_NOPARSE, /* parse error */
58 TRP_NOMEM, /* allocation error */
59 TRP_BADTYPE, /* typing error */
60 TRP_UNSUPPORTED, /* unsupported feature */
61 TRP_BADARG, /* bad argument */
62 TRP_CLOCKERR, /* error reading time */
65 typedef enum trp_inforec_type {
66 TRP_INFOREC_TYPE_UNKNOWN=0, /* conveniently, JSON parser returns 0 if a non-integer number is specified */
67 TRP_INFOREC_TYPE_ROUTE,
68 TRP_INFOREC_TYPE_COMMUNITY, /* not yet implemented (2016-06-14) */
71 typedef struct trp_inforec TRP_INFOREC;
73 typedef struct trp_update TRP_UPD;
74 typedef struct trp_req TRP_REQ;
76 /* Functions for TRP_UPD structures */
77 TR_EXPORT TRP_UPD *trp_upd_new(TALLOC_CTX *mem_ctx);
78 void trp_upd_free(TRP_UPD *update);
79 TR_EXPORT TRP_INFOREC *trp_upd_get_inforec(TRP_UPD *upd);
80 void trp_upd_set_inforec(TRP_UPD *upd, TRP_INFOREC *rec);
81 void trp_upd_add_inforec(TRP_UPD *upd, TRP_INFOREC *rec);
82 TR_EXPORT TR_NAME *trp_upd_get_peer(TRP_UPD *upd);
83 TR_NAME *trp_upd_dup_peer(TRP_UPD *upd);
84 void trp_upd_set_peer(TRP_UPD *upd, TR_NAME *peer);
85 void trp_upd_set_next_hop(TRP_UPD *upd, const char *hostname, unsigned int port);
86 TR_EXPORT TRP_INFOREC *trp_inforec_new(TALLOC_CTX *mem_ctx, TRP_INFOREC_TYPE type);
87 void trp_inforec_free(TRP_INFOREC *rec);
88 TR_EXPORT TRP_INFOREC *trp_inforec_get_next(TRP_INFOREC *rec);
89 void trp_inforec_set_next(TRP_INFOREC *rec, TRP_INFOREC *next_rec);
90 TR_EXPORT TRP_INFOREC_TYPE trp_inforec_get_type(TRP_INFOREC *rec);
91 void trp_inforec_set_type(TRP_INFOREC *rec, TRP_INFOREC_TYPE type);
92 TR_EXPORT TR_NAME *trp_inforec_get_comm(TRP_INFOREC *rec);
93 TR_EXPORT TR_NAME *trp_inforec_dup_comm(TRP_INFOREC *rec);
94 TRP_RC trp_inforec_set_comm(TRP_INFOREC *rec, TR_NAME *comm);
95 TR_EXPORT TR_NAME *trp_inforec_get_realm(TRP_INFOREC *rec);
96 TR_EXPORT TR_NAME *trp_inforec_dup_realm(TRP_INFOREC *rec);
97 TRP_RC trp_inforec_set_realm(TRP_INFOREC *rec, TR_NAME *realm);
98 TR_EXPORT TR_NAME *trp_inforec_get_trust_router(TRP_INFOREC *rec);
99 TR_EXPORT TR_NAME *trp_inforec_dup_trust_router(TRP_INFOREC *rec);
100 TRP_RC trp_inforec_set_trust_router(TRP_INFOREC *rec, TR_NAME *trust_router);
101 TR_EXPORT TR_NAME *trp_inforec_get_next_hop(TRP_INFOREC *rec);
102 TR_EXPORT TR_NAME *trp_inforec_dup_next_hop(TRP_INFOREC *rec);
103 TRP_RC trp_inforec_set_next_hop(TRP_INFOREC *rec, TR_NAME *next_hop);
104 TR_EXPORT unsigned int trp_inforec_get_metric(TRP_INFOREC *rec);
105 TRP_RC trp_inforec_set_metric(TRP_INFOREC *rec, unsigned int metric);
106 TR_EXPORT unsigned int trp_inforec_get_interval(TRP_INFOREC *rec);
107 TRP_RC trp_inforec_set_interval(TRP_INFOREC *rec, unsigned int interval);
108 TR_EXPORT TRP_INFOREC_TYPE trp_inforec_type_from_string(const char *s);
109 TR_EXPORT const char *trp_inforec_type_to_string(TRP_INFOREC_TYPE msgtype);
111 /* Functions for TRP_REQ structures */
112 TR_EXPORT TRP_REQ *trp_req_new(TALLOC_CTX *mem_ctx);
113 TR_EXPORT void trp_req_free(TRP_REQ *req);
114 TR_EXPORT TR_NAME *trp_req_get_comm(TRP_REQ *req);
115 void trp_req_set_comm(TRP_REQ *req, TR_NAME *comm);
116 TR_EXPORT TR_NAME *trp_req_get_realm(TRP_REQ *req);
117 void trp_req_set_realm(TRP_REQ *req, TR_NAME *realm);
118 TR_EXPORT TR_NAME *trp_req_get_peer(TRP_REQ *req);
119 void trp_req_set_peer(TRP_REQ *req, TR_NAME *peer);
120 int trp_req_is_wildcard(TRP_REQ *req);
121 TRP_RC trp_req_make_wildcard(TRP_REQ *req);