Module: kamailio Branch: master Commit: 6750e2e2f1d6c10f6b5e66897d38657a576a9732 URL: https://github.com/kamailio/kamailio/commit/6750e2e2f1d6c10f6b5e66897d38657a...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: 2025-01-20T12:58:18+01:00
core: socket info - set receive timeout for netlink socket
- GH #4098
---
Modified: src/core/socket_info.c
---
Diff: https://github.com/kamailio/kamailio/commit/6750e2e2f1d6c10f6b5e66897d38657a... Patch: https://github.com/kamailio/kamailio/commit/6750e2e2f1d6c10f6b5e66897d38657a...
---
diff --git a/src/core/socket_info.c b/src/core/socket_info.c index b431ea395db..24243fea153 100644 --- a/src/core/socket_info.c +++ b/src/core/socket_info.c @@ -1378,6 +1378,7 @@ static int nl_bound_sock(void) { int sock = -1; struct sockaddr_nl la; + struct timeval recvtimeout;
sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE); if(sock < 0) { @@ -1396,6 +1397,15 @@ static int nl_bound_sock(void) goto error; }
+ recvtimeout.tv_sec = 4; + recvtimeout.tv_usec = 0; + if(setsockopt( + sock, SOL_SOCKET, SO_RCVTIMEO, &recvtimeout, sizeof(recvtimeout)) + < 0) { + LM_ERR("failed to set receive timeout\n"); + goto error; + } + return sock; error: if(sock >= 0) @@ -1448,6 +1458,10 @@ static int get_flags(int family) goto error; } rtn = recv(nl_sock, p, sizeof(buf) - nll, 0); + if(rtn <= 0) { + LM_ERR("failed to receive data (%d/%d)\n", rtn, errno); + goto error; + } nlp = (struct nlmsghdr *)p; if(nlp->nlmsg_type == NLMSG_DONE) { LM_DBG("done\n"); @@ -1550,6 +1564,10 @@ static int build_iface_list(void) goto error; } rtn = recv(nl_sock, p, sizeof(buf) - nll, 0); + if(rtn <= 0) { + LM_ERR("failed to receive data (%d/%d)\n", rtn, errno); + goto error; + } LM_DBG("received %d byles \n", rtn); nlp = (struct nlmsghdr *)p; if(nlp->nlmsg_type == NLMSG_DONE) {