From 1439c2bc8a95e4b72dad45aafe4c1f7a581bcd5a Mon Sep 17 00:00:00 2001 From: Jordan Augé Date: Sat, 14 Dec 2019 01:50:16 +0100 Subject: [HICN-455] libhicnctrl incorrectly handles absence of forwarder in synchronous mode after it has connected MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I3999c4f8706d3df6a003ebf2574bc20c41ce102a Signed-off-by: Jordan Augé --- ctrl/libhicnctrl/src/api.c | 35 ++++++++++++++++++++---------- hicn-light/src/hicn/config/configuration.c | 9 ++++++-- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/ctrl/libhicnctrl/src/api.c b/ctrl/libhicnctrl/src/api.c index 23a314c0c..5e8536480 100644 --- a/ctrl/libhicnctrl/src/api.c +++ b/ctrl/libhicnctrl/src/api.c @@ -714,16 +714,22 @@ hc_sock_process(hc_sock_t * s, hc_data_t ** data) } else { int rc; rc = hc_data_ensure_available(s->cur_request->data, num_chunks); - if (rc < 0) - return -99; + if (rc < 0) { + ERROR("[hc_sock_process] Error in hc_data_ensure_available"); + return -99; + } for (int i = 0; i < num_chunks; i++) { u8 * dst = hc_data_get_next(s->cur_request->data); - if (!dst) - return -99; + if (!dst) { + ERROR("[hc_sock_process] Error in hc_data_get_next"); + return -99; + } rc = s->cur_request->parse(s->buf + s->roff + i * s->cur_request->data->in_element_size, dst); - if (rc < 0) + if (rc < 0) { + ERROR("[hc_sock_process] Error in parse"); err = -99; /* FIXME we let the loop complete (?) */ + } s->cur_request->data->size++; } } @@ -900,7 +906,7 @@ hc_execute_command(hc_sock_t * s, hc_msg_t * msg, size_t msg_len, if (n == 0) goto ERR_EOF; if (n < 0) - break; + continue; //break; int rc = hc_sock_process(s, pdata); switch(rc) { case 0: @@ -910,11 +916,11 @@ hc_execute_command(hc_sock_t * s, hc_msg_t * msg, size_t msg_len, break; case -99: ERROR("[hc_execute_command] Error processing socket results"); - goto ERR_PROCESS; + goto ERR; break; default: ERROR("[hc_execute_command] Unexpected return value"); - goto ERR_PROCESS; + goto ERR; } } @@ -930,6 +936,7 @@ ERR_EOF: ERR_PROCESS: ERR_MAP: hc_sock_request_free(request); +ERR: ERR_REQUEST: hc_data_free(data); ERR_DATA: @@ -1954,12 +1961,16 @@ hc_route_parse(void * in, hc_route_t * route) { list_routes_command * cmd = (list_routes_command *) in; - if (!IS_VALID_ADDR_TYPE(cmd->addressType)) - return -1; + if (!IS_VALID_ADDR_TYPE(cmd->addressType)) { + ERROR("[hc_route_parse] Invalid address type"); + return -1; + } int family = map_from_addr_type[cmd->addressType]; - if (!IS_VALID_FAMILY(family)) - return -1; + if (!IS_VALID_FAMILY(family)) { + ERROR("[hc_route_parse] Invalid address family"); + return -1; + } *route = (hc_route_t) { .face_id = cmd->connid, diff --git a/hicn-light/src/hicn/config/configuration.c b/hicn-light/src/hicn/config/configuration.c index e41fb3e45..8f97af3b1 100644 --- a/hicn-light/src/hicn/config/configuration.c +++ b/hicn-light/src/hicn/config/configuration.c @@ -275,6 +275,7 @@ struct iovec *configuration_ProcessRegistrationList(Configuration *config, FibEntryList *fibList = forwarder_GetFibEntries(config->forwarder); size_t payloadSize = fibEntryList_Length(fibList); + size_t effective_payloadSize = 0; size_t pointerLocation = 0; struct sockaddr_in tmpAddr; struct sockaddr_in6 tmpAddr6; @@ -288,6 +289,9 @@ struct iovec *configuration_ProcessRegistrationList(Configuration *config, NameBitvector *prefix = name_GetContentName(fibEntry_GetPrefix(entry)); const NumberSet *nexthops = fibEntry_GetNexthops(entry); + if (numberSet_Length(nexthops) == 0) + continue; + if (numberSet_Length(nexthops) > 1) { // payload extended, need reallocate, further entries via nexthops payloadSize = payloadSize + numberSet_Length(nexthops) - 1; @@ -316,6 +320,7 @@ struct iovec *configuration_ProcessRegistrationList(Configuration *config, listRouteCommand->cost = 1; // cost pointerLocation++; + effective_payloadSize++; addressDestroy(&addressEntry); } } @@ -323,7 +328,7 @@ struct iovec *configuration_ProcessRegistrationList(Configuration *config, // send response header_control_message *header = request[0].iov_base; header->messageType = RESPONSE_LIGHT; - header->length = (unsigned)payloadSize; + header->length = (unsigned)effective_payloadSize; struct iovec *response = parcMemory_AllocateAndClear(sizeof(struct iovec) * 2); @@ -331,7 +336,7 @@ struct iovec *configuration_ProcessRegistrationList(Configuration *config, response[0].iov_base = header; response[0].iov_len = sizeof(header_control_message); response[1].iov_base = payloadResponse; - response[1].iov_len = sizeof(list_routes_command) * payloadSize; + response[1].iov_len = sizeof(list_routes_command) * effective_payloadSize; fibEntryList_Destroy(&fibList); return response; -- cgit 1.2.3-korg