]> git.puffer.fish Git - matthieu/frr.git/commitdiff
pimd: Modify pim_sock_read to read 3 times before yielding
authorDonald Sharp <sharpd@cumulusnetworks.com>
Thu, 17 Nov 2016 15:50:05 +0000 (10:50 -0500)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Thu, 22 Dec 2016 01:26:16 +0000 (20:26 -0500)
Modify pim_sock_read to read up to 3 packets before yielding
the cpu to something else.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
pimd/pim_pim.c

index 96d2111ce2cbd7eb2bf68387983a79a185a01e56..775293ce60a2cef9a36747bd3ca5a01dd263ef9a 100644 (file)
@@ -289,51 +289,73 @@ static int pim_sock_read(struct thread *t)
   int len;
   ifindex_t ifindex = -1;
   int result = -1; /* defaults to bad */
+  static long long count = 0;
+  int cont = 1;
 
   ifp = THREAD_ARG(t);
   fd = THREAD_FD(t);
 
   pim_ifp = ifp->info;
 
-  len = pim_socket_recvfromto(fd, buf, sizeof(buf),
-                             &from, &fromlen,
-                             &to, &tolen,
-                             &ifindex);
+  while (cont)
+    {
+      len = pim_socket_recvfromto(fd, buf, sizeof(buf),
+                                 &from, &fromlen,
+                                 &to, &tolen,
+                                 &ifindex);
+      if (len < 0)
+       {
+         if (errno == EINTR)
+           continue;
+         if (errno == EWOULDBLOCK || errno == EAGAIN)
+           {
+             cont = 0;
+             break;
+           }
+         if (PIM_DEBUG_PIM_PACKETS)
+           zlog_debug ("Received errno: %d %s", errno, safe_strerror (errno));
+         goto done;
+       }
 
 #ifdef PIM_CHECK_RECV_IFINDEX_SANITY
-  /* ifindex sanity check */
-  if (ifindex != (int) ifp->ifindex) {
-    char from_str[INET_ADDRSTRLEN];
-    char to_str[INET_ADDRSTRLEN];
-    struct interface *recv_ifp;
-
-    if (!inet_ntop(AF_INET, &from.sin_addr, from_str , sizeof(from_str)))
-      sprintf(from_str, "<from?>");
-    if (!inet_ntop(AF_INET, &to.sin_addr, to_str , sizeof(to_str)))
-      sprintf(to_str, "<to?>");
-
-    recv_ifp = if_lookup_by_index(ifindex);
-    if (recv_ifp) {
-      zassert(ifindex == (int) recv_ifp->ifindex);
-    }
+      /* ifindex sanity check */
+      if (ifindex != (int) ifp->ifindex) {
+       char from_str[INET_ADDRSTRLEN];
+       char to_str[INET_ADDRSTRLEN];
+       struct interface *recv_ifp;
+
+       if (!inet_ntop(AF_INET, &from.sin_addr, from_str , sizeof(from_str)))
+         sprintf(from_str, "<from?>");
+       if (!inet_ntop(AF_INET, &to.sin_addr, to_str , sizeof(to_str)))
+         sprintf(to_str, "<to?>");
+
+       recv_ifp = if_lookup_by_index(ifindex);
+       if (recv_ifp) {
+         zassert(ifindex == (int) recv_ifp->ifindex);
+       }
 
 #ifdef PIM_REPORT_RECV_IFINDEX_MISMATCH
-    zlog_warn("Interface mismatch: recv PIM pkt from %s to %s on fd=%d: recv_ifindex=%d (%s) sock_ifindex=%d (%s)",
-             from_str, to_str, fd,
-             ifindex, recv_ifp ? recv_ifp->name : "<if-notfound>",
-             ifp->ifindex, ifp->name);
+       zlog_warn("Interface mismatch: recv PIM pkt from %s to %s on fd=%d: recv_ifindex=%d (%s) sock_ifindex=%d (%s)",
+                 from_str, to_str, fd,
+                 ifindex, recv_ifp ? recv_ifp->name : "<if-notfound>",
+                 ifp->ifindex, ifp->name);
 #endif
-    goto done;
-  }
+       goto done;
+      }
 #endif
 
-  int fail = pim_pim_packet(ifp, buf, len);
-  if (fail) {
-    if (PIM_DEBUG_PIM_PACKETS)
-      zlog_debug("%s: pim_pim_packet() return=%d",
-                __PRETTY_FUNCTION__, fail);
-    goto done;
-  }
+      int fail = pim_pim_packet(ifp, buf, len);
+      if (fail) {
+       if (PIM_DEBUG_PIM_PACKETS)
+         zlog_debug("%s: pim_pim_packet() return=%d",
+                    __PRETTY_FUNCTION__, fail);
+       goto done;
+      }
+
+      count++;
+      if (count % 3 == 0)
+        cont = 0;
+    }
 
   result = 0; /* good */