diff options
author | Jordan Augé <jordan.auge+fdio@cisco.com> | 2022-10-14 15:45:53 +0200 |
---|---|---|
committer | Jordan Augé <jordan.auge+fdio@cisco.com> | 2022-10-14 17:20:02 +0200 |
commit | d84088f79ada50fdb11b4426d7af2866104083e2 (patch) | |
tree | 4e84a6f9a06ae7ed8f619d63cbdb6622335c5284 /hicn-light/src/hicn/core | |
parent | 12d21f032e9a67b327101c42481a546a48a6ac21 (diff) |
fix(hicn-light): error handling for invalid connections + local bind/remote connect returning EINVAL in tests
Change-Id: I7398ff034ce0b96ea31bc3fa9d5ba515a5c14804
Ticket: HICN-809
Signed-off-by: Jordan Augé <jordan.auge+fdio@cisco.com>
Diffstat (limited to 'hicn-light/src/hicn/core')
-rw-r--r-- | hicn-light/src/hicn/core/listener.c | 44 |
1 files changed, 25 insertions, 19 deletions
diff --git a/hicn-light/src/hicn/core/listener.c b/hicn-light/src/hicn/core/listener.c index a3c5c8a12..58ba53fe1 100644 --- a/hicn-light/src/hicn/core/listener.c +++ b/hicn-light/src/hicn/core/listener.c @@ -189,40 +189,46 @@ unsigned listener_create_connection(listener_t *listener, assert(listener_has_valid_type(listener)); assert(pair); - connection_table_t *table = - forwarder_get_connection_table(listener->forwarder); - connection_t *connection = - connection_table_allocate(table, pair, connection_name); - unsigned connection_id = - (unsigned int)connection_table_get_connection_id(table, connection); + /* initialized so that gcc-9 does not complain */ + face_type_t connection_type = FACE_TYPE_UNDEFINED; + switch (listener->type) { + case FACE_TYPE_UDP_LISTENER: + connection_type = FACE_TYPE_UDP; + break; + case FACE_TYPE_TCP_LISTENER: + connection_type = FACE_TYPE_TCP; + break; + case FACE_TYPE_HICN: + case FACE_TYPE_HICN_LISTENER: + case FACE_TYPE_UDP: + case FACE_TYPE_TCP: + case FACE_TYPE_UNDEFINED: + case FACE_TYPE_N: + return CONNECTION_ID_UNDEFINED; + } +#ifdef USE_CONNECTED_SOCKETS /* * We create a connected connection with its own fd, instead of returning * the fd of the listener. This will allow to avoid specifying the * destination address when sending packets, and will increase performance * by avoiding a FIB lookup for each packet. */ -#ifdef USE_CONNECTED_SOCKETS int fd = listener_get_socket(listener, address_pair_get_local(pair), address_pair_get_remote(pair), listener->interface_name); + if (fd < 0) return CONNECTION_ID_UNDEFINED; #else int fd = 0; // means listener->fd; #endif bool local = address_is_local(address_pair_get_local(pair)); - face_type_t connection_type; - switch (listener->type) { - case FACE_TYPE_UDP_LISTENER: - connection_type = FACE_TYPE_UDP; - break; - case FACE_TYPE_TCP_LISTENER: - connection_type = FACE_TYPE_TCP; - break; - default: - connection_table_remove_by_id(table, connection_id); - return CONNECTION_ID_UNDEFINED; - } + connection_table_t *table = + forwarder_get_connection_table(listener->forwarder); + connection_t *connection = + connection_table_allocate(table, pair, connection_name); + unsigned connection_id = + (unsigned int)connection_table_get_connection_id(table, connection); int rc = connection_initialize(connection, connection_type, connection_name, listener->interface_name, fd, pair, local, |