From 9b3ab10c2078bda8614402552c26a09462d0a34e Mon Sep 17 00:00:00 2001 From: Robert Schmidt Date: Sat, 13 Apr 2024 12:32:29 +0200 Subject: [PATCH] Make failed TUN socket operation non-fatal It might be desirable to run the UE without superuser rights. More concretely, it might run without NET_ADMIN. In this case, various corresponding operations on the TUN socket fd might fail. In this commit, - improve error reports to make them more clear - do not automatically exit(1), but return from the function to ensure continuity of the softmodem --- openair1/SIMULATION/ETH_TRANSPORT/netlink_init.c | 2 +- openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.c | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/openair1/SIMULATION/ETH_TRANSPORT/netlink_init.c b/openair1/SIMULATION/ETH_TRANSPORT/netlink_init.c index 837d977f65..75f5e83632 100644 --- a/openair1/SIMULATION/ETH_TRANSPORT/netlink_init.c +++ b/openair1/SIMULATION/ETH_TRANSPORT/netlink_init.c @@ -144,7 +144,7 @@ int netlink_init_tun(char *ifprefix, int num_if, int id) {//for UE, id = 1, 2, . if (nas_sock_fd[i] == -1) { LOG_E(PDCP, "TUN: Error opening socket %s (%d:%s)\n",ifname,errno, strerror(errno)); - exit(1); + return 0; } LOG_I(PDCP, "TUN: Opened socket %s with fd nas_sock_fd[%d]=%d\n", diff --git a/openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.c b/openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.c index c2e49f7856..58adc41a65 100644 --- a/openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.c +++ b/openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.c @@ -406,8 +406,7 @@ static void reblock_tun_socket(void) f = fcntl(nas_sock_fd[0], F_GETFL, 0); f &= ~(O_NONBLOCK); if (fcntl(nas_sock_fd[0], F_SETFL, f) == -1) { - LOG_E(PDCP, "reblock_tun_socket failed\n"); - exit(1); + LOG_E(PDCP, "fcntl(F_SETFL) failed on fd %d: errno %d, %s\n", nas_sock_fd[0], errno, strerror(errno)); } } @@ -425,8 +424,8 @@ static void *enb_tun_read_thread(void *_) while (1) { len = read(nas_sock_fd[0], &rx_buf, NL_MAX_PAYLOAD); if (len == -1) { - LOG_E(PDCP, "%s:%d:%s: fatal\n", __FILE__, __LINE__, __FUNCTION__); - exit(1); + LOG_E(PDCP, "could not read(): errno %d %s\n", errno, strerror(errno)); + return NULL; } LOG_D(PDCP, "%s(): nas_sock_fd read returns len %d\n", __func__, len); @@ -483,8 +482,8 @@ static void *ue_tun_read_thread(void *_) while (1) { len = read(nas_sock_fd[0], &rx_buf, NL_MAX_PAYLOAD); if (len == -1) { - LOG_E(PDCP, "%s:%d:%s: fatal\n", __FILE__, __LINE__, __FUNCTION__); - exit(1); + LOG_E(PDCP, "error: cannot read() from fd %d: errno %d, %s\n", nas_sock_fd[0], errno, strerror(errno)); + return NULL; /* exit thread */ } LOG_D(PDCP, "%s(): nas_sock_fd read returns len %d\n", __func__, len);