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
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 void trp_upd_remove_inforec(TRP_UPD *upd, TRP_INFOREC *rec);
83 size_t trp_upd_num_inforecs(TRP_UPD *upd);
84 TR_EXPORT TR_NAME *trp_upd_get_realm(TRP_UPD *upd);
85 TR_NAME *trp_upd_dup_realm(TRP_UPD *upd);
86 void trp_upd_set_realm(TRP_UPD *upd, TR_NAME *realm);
87 TR_EXPORT TR_NAME *trp_upd_get_comm(TRP_UPD *upd);
88 TR_NAME *trp_upd_dup_comm(TRP_UPD *upd);
89 void trp_upd_set_comm(TRP_UPD *upd, TR_NAME *comm);
90 TR_EXPORT TR_NAME *trp_upd_get_peer(TRP_UPD *upd);
91 TR_NAME *trp_upd_dup_peer(TRP_UPD *upd);
92 void trp_upd_set_peer(TRP_UPD *upd, TR_NAME *peer);
93 void trp_upd_set_next_hop(TRP_UPD *upd, const char *hostname, unsigned int port);
94 void trp_upd_add_to_provenance(TRP_UPD *upd, TR_NAME *name);
96 /* Functions for TRP_REQ structures */
97 TR_EXPORT TRP_REQ *trp_req_new(TALLOC_CTX *mem_ctx);
98 TR_EXPORT void trp_req_free(TRP_REQ *req);
99 TR_EXPORT TR_NAME *trp_req_get_comm(TRP_REQ *req);
100 void trp_req_set_comm(TRP_REQ *req, TR_NAME *comm);
101 TR_EXPORT TR_NAME *trp_req_get_realm(TRP_REQ *req);
102 void trp_req_set_realm(TRP_REQ *req, TR_NAME *realm);
103 TR_EXPORT TR_NAME *trp_req_get_peer(TRP_REQ *req);
104 void trp_req_set_peer(TRP_REQ *req, TR_NAME *peer);
105 int trp_req_is_wildcard(TRP_REQ *req);
106 TRP_RC trp_req_make_wildcard(TRP_REQ *req);