]> git.puffer.fish Git - mirror/frr.git/commitdiff
2004-12-29 Greg Troxel <gdt@poblano.ir.bbn.com>
authorgdt <gdt>
Wed, 29 Dec 2004 18:53:30 +0000 (18:53 +0000)
committergdt <gdt>
Wed, 29 Dec 2004 18:53:30 +0000 (18:53 +0000)
* sockopt.c (getsockopt_ipv4_ifindex): Return 0 when passed a NULL
  cmsghdr pointer.

I believe this will avoid ospfd crashing on Solaris 8, which seems to
define IP_RECVIF but not actually implement it.

lib/ChangeLog
lib/sockopt.c

index eaf459de00edcfe65b17271c5957d8b54f02bc4c..6f2363723820899c25231944fcc5477b554a4c29 100644 (file)
@@ -1,3 +1,8 @@
+2004-12-29  Greg Troxel  <gdt@poblano.ir.bbn.com>
+
+       * sockopt.c (getsockopt_ipv4_ifindex): Return 0 when passed a NULL
+         cmsghdr pointer.
+
 2004-12-28 Andrew J. Schorr <ajschorr@alumni.princeton.edu>
 
        * sockopt.c: (setsockopt_ipv4_ifindex) Improve error message.
index 3a8033cc031f1c4f79e502872b3bb052d638b8f7..8c518f824a486adf4cc7e74710670f992e04a7bd 100644 (file)
@@ -283,11 +283,30 @@ setsockopt_ifindex (int af, int sock, int val)
 static int
 getsockopt_ipv4_ifindex (struct msghdr *msgh)
 {
+  /*
+   * XXX: This routine's semantics are ill-defined, in particular how
+   * the results "can't determine interface due to runtime behavior"
+   * and "OS has no support for how to determine behavior" are
+   * encoded.  For now, return 0 for either case; caller must handle
+   * as "don't know".
+   */
   int ifindex = -1;
+
+  /*
+   * If autoconf found a method to get ifindex, but it didn't work for
+   * this packet, or on this OS, this routine can be entered with a
+   * NULL cmsghdr pointer.  Check msgh before using in each case
+   * below, rather than here, to avoid having to ifdef twice, once for
+   * declarations and once for code.
+   */
+
 #if defined(IP_PKTINFO)
 /* Linux pktinfo based ifindex retrieval */
   struct in_pktinfo *pktinfo;
   
+  if (msgh == NULL)
+    return 0;
+
   pktinfo = 
     (struct in_pktinfo *)getsockopt_cmsg_data (msgh, IPPROTO_IP, IP_PKTINFO);
   ifindex = pktinfo->ipi_ifindex;
@@ -300,6 +319,9 @@ getsockopt_ipv4_ifindex (struct msghdr *msgh)
 #endif /* SUNOS_5 */
   /* SUNOS_5 doesn't need a structure to extract ifindex */
 
+  if (msgh == NULL)
+    return 0;
+
 #ifndef SUNOS_5
   sdl = 
     (struct sockaddr_dl *)getsockopt_cmsg_data (msgh, IPPROTO_IP, IP_RECVIF);