From 95170bf3a69597b49238bb7ff396d41f6dc94f30 Mon Sep 17 00:00:00 2001 From: Jordan Augé Date: Wed, 30 Oct 2019 17:56:08 +0100 Subject: [HICN-369] Implement reconciliation state machine in face manager incl. reattempts in case of errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ia4ecf621fbd513d9e29313d2aaa487aa65811183 Signed-off-by: Jordan Augé --- hicn-light/src/hicn/io/udpListener.c | 78 ++++++++++++++++++++++++------------ 1 file changed, 52 insertions(+), 26 deletions(-) (limited to 'hicn-light/src') diff --git a/hicn-light/src/hicn/io/udpListener.c b/hicn-light/src/hicn/io/udpListener.c index e484dc2db..ebb24022e 100644 --- a/hicn-light/src/hicn/io/udpListener.c +++ b/hicn-light/src/hicn/io/udpListener.c @@ -130,22 +130,35 @@ ListenerOps *udpListener_CreateInet6(Forwarder *forwarder, char *listenerName, if (failure == 0) { #ifdef __linux__ - int ret = setsockopt(udp->udp_socket, SOL_SOCKET, SO_BINDTODEVICE, - interfaceName, strlen(interfaceName) + 1); - if (ret < 0) { - logger_Log(udp->logger, LoggerFacility_IO, PARCLogLevel_Debug, __func__, - "setsockopt(%d, SO_BINDTODEVICE, %s) failed (%d) %s", - udp->udp_socket, interfaceName, errno, strerror(errno)); -#ifdef __ANDROID__ - ret = bindSocket(udp->udp_socket, interfaceName); + if (strncmp("lo", interfaceName, 2) != 0) { + int ret = setsockopt(udp->udp_socket, SOL_SOCKET, SO_BINDTODEVICE, + interfaceName, strlen(interfaceName) + 1); if (ret < 0) { logger_Log(udp->logger, LoggerFacility_IO, PARCLogLevel_Debug, __func__, - "bindSocket(%d, %s) failed", udp->udp_socket, interfaceName); - } else { - logger_Log(udp->logger, LoggerFacility_IO, PARCLogLevel_Debug, __func__, - "bindSocket(%d, %s) success", udp->udp_socket, interfaceName); - } + "setsockopt(%d, SO_BINDTODEVICE, %s) failed (%d) %s", + udp->udp_socket, interfaceName, errno, strerror(errno)); +#ifdef __ANDROID__ + ret = bindSocket(udp->udp_socket, interfaceName); + if (ret < 0) { + logger_Log(udp->logger, LoggerFacility_IO, PARCLogLevel_Debug, __func__, + "bindSocket(%d, %s) failed", udp->udp_socket, interfaceName); + close(udp->udp_socket); + addressDestroy(&udp->localAddress); + logger_Release(&udp->logger); + parcMemory_Deallocate((void **)&udp); + return NULL; + } else { + logger_Log(udp->logger, LoggerFacility_IO, PARCLogLevel_Debug, __func__, + "bindSocket(%d, %s) success", udp->udp_socket, interfaceName); + } +#else + close(udp->udp_socket); + addressDestroy(&udp->localAddress); + logger_Release(&udp->logger); + parcMemory_Deallocate((void **)&udp); + return NULL; #endif + } } #endif @@ -236,22 +249,35 @@ ListenerOps *udpListener_CreateInet(Forwarder *forwarder, char *listenerName, failure = bind(udp->udp_socket, (struct sockaddr *)&sin, sizeof(sin)); if (failure == 0) { #ifdef __linux__ - int ret = setsockopt(udp->udp_socket, SOL_SOCKET, SO_BINDTODEVICE, - interfaceName, strlen(interfaceName) + 1); - if (ret < 0) { - logger_Log(udp->logger, LoggerFacility_IO, PARCLogLevel_Debug, __func__, - "setsockopt(%d, SO_BINDTODEVICE, %s) failed (%d) %s", - udp->udp_socket, interfaceName, errno, strerror(errno)); -#ifdef __ANDROID__ - ret = bindSocket(udp->udp_socket, interfaceName); + if (strncmp("lo", interfaceName, 2) != 0) { + int ret = setsockopt(udp->udp_socket, SOL_SOCKET, SO_BINDTODEVICE, + interfaceName, strlen(interfaceName) + 1); if (ret < 0) { logger_Log(udp->logger, LoggerFacility_IO, PARCLogLevel_Debug, __func__, - "bindSocket(%d, %s) failed", udp->udp_socket, interfaceName); - } else { - logger_Log(udp->logger, LoggerFacility_IO, PARCLogLevel_Debug, __func__, - "bindSocket(%d, %s) success", udp->udp_socket, interfaceName); - } + "setsockopt(%d, SO_BINDTODEVICE, %s) failed (%d) %s", + udp->udp_socket, interfaceName, errno, strerror(errno)); +#ifdef __ANDROID__ + ret = bindSocket(udp->udp_socket, interfaceName); + if (ret < 0) { + logger_Log(udp->logger, LoggerFacility_IO, PARCLogLevel_Debug, __func__, + "bindSocket(%d, %s) failed", udp->udp_socket, interfaceName); + close(udp->udp_socket); + addressDestroy(&udp->localAddress); + logger_Release(&udp->logger); + parcMemory_Deallocate((void **)&udp); + return NULL; + } else { + logger_Log(udp->logger, LoggerFacility_IO, PARCLogLevel_Debug, __func__, + "bindSocket(%d, %s) success", udp->udp_socket, interfaceName); + } +#else + close(udp->udp_socket); + addressDestroy(&udp->localAddress); + logger_Release(&udp->logger); + parcMemory_Deallocate((void **)&udp); + return NULL; #endif + } } #endif ops = parcMemory_AllocateAndClear(sizeof(ListenerOps)); -- cgit 1.2.3-korg