]> git.puffer.fish Git - mirror/frr.git/commitdiff
2005-02-17 Andrew J. Schorr <ajschorr@alumni.princeton.edu>
authorajs <ajs>
Thu, 17 Feb 2005 19:55:59 +0000 (19:55 +0000)
committerajs <ajs>
Thu, 17 Feb 2005 19:55:59 +0000 (19:55 +0000)
* ospf_packet.c: (ospf_recv_packet) If there is somehow a runt
  packet in the queue, it must be discarded.  Improve warning messages.
  Fix scope to static.
  (ospf_read) Fix bug: should reset the read thread in all cases
  to make sure we continue to get incoming messages.

ospfd/ChangeLog
ospfd/ospf_packet.c

index c6607e0c3acf3b9cc98f1327debf55699b3ccc30..9737854a11a8bee39814b1fd4e72020bf328d391 100644 (file)
@@ -1,3 +1,11 @@
+2005-02-17 Andrew J. Schorr <ajschorr@alumni.princeton.edu>
+
+       * ospf_packet.c: (ospf_recv_packet) If there is somehow a runt
+         packet in the queue, it must be discarded.  Improve warning messages.
+         Fix scope to static.
+         (ospf_read) Fix bug: should reset the read thread in all cases
+         to make sure we continue to get incoming messages.
+
 2005-02-15 Paul Jakma <paul.jakma@sun.com>
 
        * ospf_packet.c: (ospf_recv_packet) Fix silly error wrt allocating
index 58369250cf4c8571591bdededf8c913a51ecc451..038fd657572de4630921614b89a7c5a151865a76 100644 (file)
@@ -2043,7 +2043,7 @@ ospf_ls_ack (struct ip *iph, struct ospf_header *ospfh,
 #endif /* HAVE_OPAQUE_LSA */
 }
 \f
-struct stream *
+static struct stream *
 ospf_recv_packet (int fd, struct interface **ifp)
 {
   int ret;
@@ -2062,12 +2062,24 @@ ospf_recv_packet (int fd, struct interface **ifp)
   msgh.msg_control = (caddr_t) buff;
   msgh.msg_controllen = sizeof (buff);
   
+  /* XXX Is there an upper limit on the size of these packets?  If there is,
+     it would be more efficient to read the whole packet in one shot without
+     peeking (this would cut down from 2 system calls to 1).  And this would
+     make the error-handling logic a bit more robust. */
   ret = recvfrom (fd, (void *)&iph, sizeof (iph), MSG_PEEK, NULL, 0);
   
   if (ret != sizeof (iph))
     {
-      zlog_warn ("ospf_recv_packet packet smaller than ip header");
-      /* XXX: We peeked, and thus perhaps should discard this packet. */
+      if (ret > 0)
+        {
+         zlog_warn("ospf_recv_packet: discarding runt packet of length %d "
+                   "(ip header size is %u)",
+                   ret, (u_int)sizeof(iph));
+         recvfrom (fd, (void *)&iph, ret, 0, NULL, 0);
+        }
+      else
+       zlog_warn("ospf_recv_packet: recvfrom returned %d: %s",
+                 ret, safe_strerror(errno));
       return NULL;
     }
   
@@ -2354,7 +2366,9 @@ ospf_read (struct thread *thread)
 
   /* first of all get interface pointer. */
   ospf = THREAD_ARG (thread);
-  ospf->t_read = NULL;
+
+  /* prepare for next packet. */
+  ospf->t_read = thread_add_read (master, ospf_read, ospf, ospf->fd);
 
   /* read OSPF packet. */
   ibuf = ospf_recv_packet (ospf->fd, &ifp);
@@ -2375,9 +2389,6 @@ ospf_read (struct thread *thread)
       stream_free (ibuf);
       return 0;
     }
-  
-  /* prepare for next packet. */
-  ospf->t_read = thread_add_read (master, ospf_read, ospf, ospf->fd);
 
   /* IP Header dump. */
     if (IS_DEBUG_OSPF_PACKET(0, RECV))