return talloc_asprintf(mem_ctx, "%s/%s", p1, p2); /* returns NULL on a failure */
}
+static void tr_cfg_log_json_error(const char *label, json_error_t *rc)
+{
+ tr_debug("%s: JSON parse error on line %d: %s",
+ label,
+ rc->line,
+ rc->text);
+}
+
TR_CFG_RC tr_cfg_parse_one_config_file(TR_CFG *cfg, const char *file_with_path)
{
json_t *jcfg=NULL;
if (NULL==(jcfg=json_load_file(file_with_path,
JSON_DISABLE_EOF_CHECK, &rc))) {
- tr_debug("tr_parse_one_config_file: Error parsing config file %s.",
+ tr_debug("tr_cfg_parse_one_config_file: Error parsing config file %s.",
file_with_path);
+ tr_cfg_log_json_error("tr_cfg_parse_one_config_file", &rc);
return TR_CFG_NOPARSE;
}
TR_NAME *realm;
TR_NAME *trust_router;
TR_NAME *next_hop;
+ unsigned int next_hop_port;
unsigned int metric;
unsigned int interval;
} TRP_INFOREC_ROUTE;
TR_NAME *realm;
TR_NAME *peer;
unsigned int metric;
- TR_NAME *trust_router;
+ TR_NAME *trust_router; /* hostname */
+ unsigned int trp_port;
+ unsigned int tid_port;
TR_NAME *next_hop;
int selected;
unsigned int interval; /* interval from route update */
TR_EXPORT TR_NAME *trp_upd_get_peer(TRP_UPD *upd);
TR_NAME *trp_upd_dup_peer(TRP_UPD *upd);
void trp_upd_set_peer(TRP_UPD *upd, TR_NAME *peer);
+void trp_upd_set_next_hop(TRP_UPD *upd, const char *hostname, unsigned int port);
TR_EXPORT TRP_INFOREC *trp_inforec_new(TALLOC_CTX *mem_ctx, TRP_INFOREC_TYPE type);
void trp_inforec_free(TRP_INFOREC *rec);
TR_EXPORT TRP_INFOREC *trp_inforec_get_next(TRP_INFOREC *rec);
#include <trp_internal.h>
#include <trp_rtable.h>
#include <tr_debug.h>
+#include <trust_router/trp.h>
+#include <trust_router/tid.h>
/* Note: be careful mixing talloc with glib. */
entry->comm=NULL;
entry->realm=NULL;
entry->trust_router=NULL;
+ entry->trp_port=TRP_PORT;
+ entry->tid_port=TID_PORT;
entry->peer=NULL;
entry->next_hop=NULL;
entry->selected=0;
return entry->metric;
}
+/* TODO: set the hostname and port for the next hop. Currently assume default TID port. --jlr */
void trp_route_set_next_hop(TRP_ROUTE *entry, TR_NAME *next_hop)
{
if (entry->next_hop!=NULL)
TRP_ROUTE *trp_rtable_get_selected_entry(TRP_RTABLE *rtbl, TR_NAME *comm, TR_NAME *realm)
{
size_t n=0;
+ int ii=0;
TRP_ROUTE **entry=trp_rtable_get_realm_entries(rtbl, comm, realm, &n);
TRP_ROUTE *selected=NULL;
tr_debug("trp_rtable_get_selected_entry: looking through route table entries for realm %.*s.",
realm->len, realm->buf);
- while(n-- && !trp_route_is_selected(entry[n])) { }
- tr_debug("trp_rtable_get_selected_entry: n=%d.", n);
-
- if (n>=0)
- selected=entry[n];
+ for(ii=0; ii<n; ii++) {
+ if (trp_route_is_selected(entry[ii])) {
+ selected=entry[ii];
+ break;
+ }
+ }
+ tr_debug("trp_rtable_get_selected_entry: ii=%d.", ii);
talloc_free(entry);
return selected;
new_rec->realm=NULL;
new_rec->trust_router=NULL;
new_rec->next_hop=NULL;
+ new_rec->next_hop_port=0;
new_rec->metric=TRP_METRIC_INFINITY;
new_rec->interval=0;
talloc_set_destructor((void *)new_rec, trp_inforec_route_destructor);
return TRP_ERROR;
}
+/* TODO: need to return hostname/port --jlr */
TR_NAME *trp_inforec_get_next_hop(TRP_INFOREC *rec)
{
switch (rec->type) {
void trp_upd_set_peer(TRP_UPD *upd, TR_NAME *peer)
{
+ upd->peer=peer;
+}
+
+void trp_upd_set_next_hop(TRP_UPD *upd, const char *hostname, unsigned int port)
+{
TRP_INFOREC *rec=NULL;
TR_NAME *cpy=NULL;
-
- upd->peer=peer;
+
for (rec=trp_upd_get_inforec(upd); rec!=NULL; rec=trp_inforec_get_next(rec)) {
- if (trp_inforec_set_next_hop(rec, cpy=tr_dup_name(peer)) != TRP_SUCCESS) {
+ if (trp_inforec_set_next_hop(rec, cpy=tr_new_name(hostname)) != TRP_SUCCESS) {
tr_err("trp_upd_set_peer: error setting peer.");
tr_free_name(cpy);
}
int err=0;
char *buf=NULL;
size_t buflen = 0;
- TR_NAME *peer=NULL;
+ TRP_PEER *peer=NULL; /* entry in the peer table */
+ TR_NAME *conn_peer=NULL; /* name from the TRP_CONN, which comes from the gss context */
tr_debug("trps_read_message: started");
if (err = gsscon_read_encrypted_token(trp_connection_get_fd(conn),
return TRP_ERROR;
}
- tr_debug("trps_read_message(): message received, %u bytes.", (unsigned) buflen);
- tr_debug("trps_read_message(): %.*s", buflen, buf);
+ tr_debug("trps_read_message: message received, %u bytes.", (unsigned) buflen);
+ tr_debug("trps_read_message: %.*s", buflen, buf);
*msg=tr_msg_decode(buf, buflen);
free(buf);
if (*msg==NULL)
return TRP_NOPARSE;
- peer=trp_connection_get_peer(conn);
+ conn_peer=trp_connection_get_peer(conn);
+ if (conn_peer==NULL) {
+ tr_err("trps_read_message: connection has no peer name");
+ return TRP_ERROR;
+ }
+
+ peer=trps_get_peer_by_gssname(trps, conn_peer);
+ if (peer==NULL) {
+ tr_err("trps_read_message: could not find peer with gssname=%s", trp_connection_get_gssname(conn));
+ return TRP_ERROR;
+ }
+
/* verify we received a message we support, otherwise drop it now */
switch (tr_msg_get_msg_type(*msg)) {
case TRP_UPDATE:
- trp_upd_set_peer(tr_msg_get_trp_upd(*msg), tr_dup_name(peer));
+ trp_upd_set_peer(tr_msg_get_trp_upd(*msg), tr_dup_name(conn_peer));
+ trp_upd_set_next_hop(tr_msg_get_trp_upd(*msg), trp_peer_get_server(peer), 0); /* TODO: 0 should be the configured TID port */
break;
case TRP_REQUEST:
- trp_req_set_peer(tr_msg_get_trp_req(*msg), tr_dup_name(peer));
+ trp_req_set_peer(tr_msg_get_trp_req(*msg), tr_dup_name(conn_peer));
break;
default:
- tr_debug("trps_read_message: received unsupported message from %.*s", peer->len, peer->buf);
+ tr_debug("trps_read_message: received unsupported message from %.*s", conn_peer->len, conn_peer->buf);
tr_msg_free_decoded(*msg);
*msg=NULL;
return TRP_UNSUPPORTED;
trp_route_set_peer(entry, trp_upd_dup_peer(upd));
trp_route_set_trust_router(entry, trp_inforec_dup_trust_router(rec));
trp_route_set_next_hop(entry, trp_inforec_dup_next_hop(rec));
+ /* TODO: pass next hop port (now defaults to TID_PORT) --jlr */
if ((trp_route_get_comm(entry)==NULL)
||(trp_route_get_realm(entry)==NULL)
||(trp_route_get_peer(entry)==NULL)