X-Git-Url: http://www.project-moonshot.org/gitweb/?p=trust_router.git;a=blobdiff_plain;f=trp%2Ftrp_upd.c;fp=trp%2Ftrp_upd.c;h=7feb77722a792c7532d1eef56b65d5d973b05744;hp=e1057f1b4e558071adaf394c1136fce9cbd99430;hb=6f65c9cce86719147d0b4dcc9823b25443c2d185;hpb=eaa1a8ceed54fbfadc2638cf383aaa12ab446a57 diff --git a/trp/trp_upd.c b/trp/trp_upd.c index e1057f1..7feb777 100644 --- a/trp/trp_upd.c +++ b/trp/trp_upd.c @@ -211,27 +211,40 @@ void trp_inforec_set_type(TRP_INFOREC *rec, TRP_INFOREC_TYPE type) TR_NAME *trp_inforec_get_trust_router(TRP_INFOREC *rec) { switch (rec->type) { - case TRP_INFOREC_TYPE_ROUTE: - if (rec->data->route!=NULL) - return rec->data->route->trust_router; - break; - default: - break; + case TRP_INFOREC_TYPE_ROUTE: + if (rec->data->route!=NULL) + return rec->data->route->trust_router; + break; + default: + break; } return NULL; } +int trp_inforec_get_trust_router_port(TRP_INFOREC *rec) +{ + switch (rec->type) { + case TRP_INFOREC_TYPE_ROUTE: + if (rec->data->route!=NULL) + return rec->data->route->trust_router_port; + /* fall through */ + default: + return -1; + } +} + TR_NAME *trp_inforec_dup_trust_router(TRP_INFOREC *rec) { return tr_dup_name(trp_inforec_get_trust_router(rec)); } -TRP_RC trp_inforec_set_trust_router(TRP_INFOREC *rec, TR_NAME *trust_router) +TRP_RC trp_inforec_set_trust_router(TRP_INFOREC *rec, TR_NAME *trust_router, int port) { switch (rec->type) { case TRP_INFOREC_TYPE_ROUTE: if (rec->data->route!=NULL) { rec->data->route->trust_router=trust_router; + rec->data->route->trust_router_port = port; return TRP_SUCCESS; } break; @@ -241,16 +254,15 @@ TRP_RC trp_inforec_set_trust_router(TRP_INFOREC *rec, TR_NAME *trust_router) return TRP_ERROR; } -/* TODO: need to return hostname/port --jlr */ TR_NAME *trp_inforec_get_next_hop(TRP_INFOREC *rec) { switch (rec->type) { - case TRP_INFOREC_TYPE_ROUTE: - if (rec->data->route!=NULL) - return rec->data->route->next_hop; - break; - default: - break; + case TRP_INFOREC_TYPE_ROUTE: + if (rec->data->route!=NULL) + return rec->data->route->next_hop; + break; + default: + break; } return NULL; } @@ -260,23 +272,48 @@ TR_NAME *trp_inforec_dup_next_hop(TRP_INFOREC *rec) return tr_dup_name(trp_inforec_get_next_hop(rec)); } -TRP_RC trp_inforec_set_next_hop(TRP_INFOREC *rec, TR_NAME *next_hop) +/** + * Set the next hop for the inforec + * + * Returns TRP_SUCCESS if it set the next hop value for the inforec. + * Returns TRP_UNSUPPORTED if the inforec does not have a next hop record but + * otherwise nothing went wrong. + * Returns TRP_ERROR or another error if there was a failure. + * + * @param rec + * @param next_hop + * @return TRP_SUCCESS if the value was set, TRP_UNSUPPORTED if the inforec does not support next hop, or an error code on failure + */ +TRP_RC trp_inforec_set_next_hop(TRP_INFOREC *rec, TR_NAME *next_hop, int port) { + /* Any inforec types that support next_hop should set it here. */ switch (rec->type) { case TRP_INFOREC_TYPE_ROUTE: if (rec->data->route==NULL) return TRP_ERROR; - rec->data->route->next_hop=next_hop; - break; - case TRP_INFOREC_TYPE_COMMUNITY: - /* next hop not used for community records */ + rec->data->route->next_hop = next_hop; + rec->data->route->next_hop_port = port; break; + default: - break; + /* next hop not used for other records */ + return TRP_UNSUPPORTED; } return TRP_SUCCESS; } +int trp_inforec_get_next_hop_port(TRP_INFOREC *rec) +{ + switch (rec->type) { + case TRP_INFOREC_TYPE_ROUTE: + if (rec->data->route!=NULL) + return rec->data->route->next_hop_port; + /* fall through */ + default: + return -1; + } +} + unsigned int trp_inforec_get_metric(TRP_INFOREC *rec) { switch (rec->type) { @@ -766,15 +803,26 @@ 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) +void trp_upd_set_next_hop(TRP_UPD *upd, const char *hostname, int port) { TRP_INFOREC *rec=NULL; TR_NAME *cpy=NULL; - + for (rec=trp_upd_get_inforec(upd); rec!=NULL; rec=trp_inforec_get_next(rec)) { - if (trp_inforec_set_next_hop(rec, cpy=tr_new_name(hostname)) != TRP_SUCCESS) { - tr_err("trp_upd_set_next_hop: error setting next hop."); - tr_free_name(cpy); + switch (trp_inforec_set_next_hop(rec, cpy=tr_new_name(hostname), port)) { + case TRP_SUCCESS: + /* Success, the TR_NAME in cpy is now stored with the inforec */ + break; + + case TRP_UNSUPPORTED: + /* No error, but the inforec does not accept a next_hop. Free our copy. */ + tr_free_name(cpy); + break; + + default: + tr_err("trp_upd_set_next_hop: error setting next hop."); + tr_free_name(cpy); + break; } } }