From a61398ad90acdfa4ea0ac03f3d2b9bcbfd7a6dd3 Mon Sep 17 00:00:00 2001 From: Jordan Augé Date: Fri, 30 Sep 2022 12:29:05 +0200 Subject: refactor(hicn-light): cleanup and optimizations to UDP socket face MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ticket: HICN-771 Change-Id: Ie84dc2f61888c3fdd7b3728b2a13cacbac503d1a Signed-off-by: Jordan Augé --- hicn-light/src/hicn/cli/hicnc.c | 54 +++-------------------------------- hicn-light/src/hicn/config/commands.c | 11 +++++-- hicn-light/src/hicn/core/connection.c | 11 +++++-- hicn-light/src/hicn/core/fib.c | 2 +- hicn-light/src/hicn/core/msgbuf.h | 1 + hicn-light/src/hicn/io/udp.c | 9 ++---- 6 files changed, 26 insertions(+), 62 deletions(-) (limited to 'hicn-light') diff --git a/hicn-light/src/hicn/cli/hicnc.c b/hicn-light/src/hicn/cli/hicnc.c index b4a6e8191..ed8d4ed97 100644 --- a/hicn-light/src/hicn/cli/hicnc.c +++ b/hicn-light/src/hicn/cli/hicnc.c @@ -60,55 +60,6 @@ void signal_handler(int sig) { stop = true; } -#if 0 -int hc_active_interface_snprintf(char *buf, size_t size, - hc_event_active_interface_update_t *event) { - int rc; - char *pos = buf; - - rc = ip_prefix_snprintf(pos, size, &event->prefix); - if ((rc < 0) || (rc >= size)) return rc; - pos += rc; - size -= rc; - - for (netdevice_type_t type = NETDEVICE_TYPE_UNDEFINED + 1; - type < NETDEVICE_TYPE_N; type++) { - if (!netdevice_flags_has(event->interface_type, type)) continue; - rc = snprintf(pos, size, " %s", netdevice_type_str(type)); - if ((rc < 0) || (rc >= size)) return pos - buf + rc; - - pos += rc; - size -= rc; - } - return pos - buf; -} - -// XXX hc_object_snprintf -void hc_subscription_display(command_type_t command_type, - const uint8_t *buffer) { - char buf[65535]; - - switch (command_type) { - case COMMAND_TYPE_CONNECTION_ADD: - case COMMAND_TYPE_CONNECTION_REMOVE: - case COMMAND_TYPE_CONNECTION_UPDATE: - hc_connection_snprintf(buf, sizeof(buf), (hc_connection_t *)buffer); - break; - case COMMAND_TYPE_ACTIVE_INTERFACE_UPDATE: - hc_active_interface_snprintf( - buf, sizeof(buf), (hc_event_active_interface_update_t *)buffer); - break; - case COMMAND_TYPE_ROUTE_LIST: - hc_route_snprintf(buf, sizeof(buf), (hc_route_t *)buffer); - break; - default: - INFO("Unknown event received"); - return; - } - INFO("%s %s", command_type_str(command_type), buf); -} -#endif - int main(int argc, char *const *argv) { log_conf.log_level = LOG_INFO; @@ -126,10 +77,13 @@ int main(int argc, char *const *argv) { // getopt_long stores the option index here. int optind = 0; - int c = getopt_long(argc, argv, "hS:P:", longFormOptions, &optind); + int c = getopt_long(argc, argv, "dhS:P:", longFormOptions, &optind); if (c == -1) break; switch (c) { + case 'd': + log_conf.log_level = LOG_DEBUG; + break; case 'S': server_ip = optarg; break; diff --git a/hicn-light/src/hicn/config/commands.c b/hicn-light/src/hicn/config/commands.c index e1d25367f..c6212aaf4 100644 --- a/hicn-light/src/hicn/config/commands.c +++ b/hicn-light/src/hicn/config/commands.c @@ -147,7 +147,9 @@ uint8_t *configuration_on_listener_add(forwarder_t *forwarder, uint8_t *packet, case FACE_TYPE_TCP_LISTENER: case FACE_TYPE_HICN_LISTENER: break; - default: + case FACE_TYPE_UDP: + case FACE_TYPE_TCP: + case FACE_TYPE_HICN: ERROR("Wrong listener type"); goto NACK; } @@ -388,7 +390,11 @@ uint8_t *configuration_on_connection_add(forwarder_t *forwarder, case FACE_TYPE_TCP: case FACE_TYPE_HICN: break; - default: + case FACE_TYPE_UDP_LISTENER: + case FACE_TYPE_TCP_LISTENER: + case FACE_TYPE_HICN_LISTENER: + case FACE_TYPE_UNDEFINED: + case FACE_TYPE_N: goto NACK; } @@ -1650,6 +1656,7 @@ void commands_notify_route(const forwarder_t *forwarder, fill_route_command(entry, &msg->payload); commands_notify(forwarder, TOPIC_ROUTE, (uint8_t *)&msg, sizeof(msg)); + free(msg); } void commands_notify_active_interface_update(const forwarder_t *forwarder, diff --git a/hicn-light/src/hicn/core/connection.c b/hicn-light/src/hicn/core/connection.c index 69edc7265..40802368f 100644 --- a/hicn-light/src/hicn/core/connection.c +++ b/hicn-light/src/hicn/core/connection.c @@ -37,7 +37,8 @@ connection_t *connection_create(face_type_t type, const char *name, assert(pair); assert(forwarder); - face_type_t listener_type; + /* initialized so that gcc-9 does not complain */ + face_type_t listener_type = FACE_TYPE_UNDEFINED; switch (type) { case FACE_TYPE_UDP: listener_type = FACE_TYPE_UDP_LISTENER; @@ -45,7 +46,13 @@ connection_t *connection_create(face_type_t type, const char *name, case FACE_TYPE_TCP: listener_type = FACE_TYPE_TCP_LISTENER; break; - default: + case FACE_TYPE_HICN: + return NULL; /* Not implemented */ + case FACE_TYPE_HICN_LISTENER: + case FACE_TYPE_UDP_LISTENER: + case FACE_TYPE_TCP_LISTENER: + case FACE_TYPE_UNDEFINED: + case FACE_TYPE_N: return NULL; } diff --git a/hicn-light/src/hicn/core/fib.c b/hicn-light/src/hicn/core/fib.c index b3b5d4036..2e8492457 100644 --- a/hicn-light/src/hicn/core/fib.c +++ b/hicn-light/src/hicn/core/fib.c @@ -360,7 +360,7 @@ END: #if 0 fib_dump(fib); #endif - ; /* required for clang */ + ; /* required by clang */ } /* diff --git a/hicn-light/src/hicn/core/msgbuf.h b/hicn-light/src/hicn/core/msgbuf.h index 26fd47540..ee9337225 100644 --- a/hicn-light/src/hicn/core/msgbuf.h +++ b/hicn-light/src/hicn/core/msgbuf.h @@ -76,6 +76,7 @@ static inline const hicn_name_t *msgbuf_get_name(const msgbuf_t *msgbuf) { } #define msgbuf_get_connection_id(M) ((M)->connection_id) +#define msgbuf_set_connection_id(M, ID) (M)->connection_id = (ID) #define msgbuf_get_packet(M) ((M)->packet) #define msgbuf_get_command_type(M) ((M)->command.type) #if WITH_WLDR diff --git a/hicn-light/src/hicn/io/udp.c b/hicn-light/src/hicn/io/udp.c index d704a64f1..d881b4b01 100644 --- a/hicn-light/src/hicn/io/udp.c +++ b/hicn-light/src/hicn/io/udp.c @@ -261,15 +261,10 @@ DECLARE_LISTENER(udp); #define RING_LEN 5 * MAX_MSG typedef struct { - /* - * Ring buffer - * - * This is sized to more than a batch to cope with transient failures of - * sendmmsg. - */ +#ifdef __linux__ + /* Ring buffer */ off_t *ring; -#ifdef __linux__ struct mmsghdr msghdr[MAX_MSG]; struct iovec iovecs[MAX_MSG]; #endif /* __linux__ */ -- cgit 1.2.3-korg