Module: kamailio
Branch: 5.8
Commit: 9b26093fa5cdf05cf664fa3a03619634ed226a47
URL: 
https://github.com/kamailio/kamailio/commit/9b26093fa5cdf05cf664fa3a03619634ed226a47

Author: Daniel-Constantin Mierla <mico...@gmail.com>
Committer: Daniel-Constantin Mierla <mico...@gmail.com>
Date: 2025-01-22T10:48:40+01:00

core: socket info - set receive timeout for netlink socket

- GH #4098

(cherry picked from commit 6750e2e2f1d6c10f6b5e66897d38657a576a9732)

---

Modified: src/core/socket_info.c

---

Diff:  
https://github.com/kamailio/kamailio/commit/9b26093fa5cdf05cf664fa3a03619634ed226a47.diff
Patch: 
https://github.com/kamailio/kamailio/commit/9b26093fa5cdf05cf664fa3a03619634ed226a47.patch

---

diff --git a/src/core/socket_info.c b/src/core/socket_info.c
index 44f33027c75..8efa594618f 100644
--- a/src/core/socket_info.c
+++ b/src/core/socket_info.c
@@ -1332,6 +1332,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) {
@@ -1350,6 +1351,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)
@@ -1402,6 +1412,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");
@@ -1504,6 +1518,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) {

_______________________________________________
Kamailio - Development Mailing List -- sr-dev@lists.kamailio.org
To unsubscribe send an email to sr-dev-le...@lists.kamailio.org
Important: keep the mailing list in the recipients, do not reply only to the 
sender!

Reply via email to