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
This commit is contained in:
Robert Schmidt
2024-06-03 14:00:49 +02:00
parent 8dc29be02f
commit 9b3ab10c20
2 changed files with 6 additions and 7 deletions
@@ -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",
+5 -6
View File
@@ -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);