]> git.puffer.fish Git - matthieu/frr.git/commitdiff
2004-07-23 Paul Jakma <paul@dishone.st>
authorpaul <paul>
Fri, 23 Jul 2004 15:13:48 +0000 (15:13 +0000)
committerpaul <paul>
Fri, 23 Jul 2004 15:13:48 +0000 (15:13 +0000)
        * ospf_network.c: Replace PKTINFO/RECVIF with call to
          setsockopt_pktinfo
        * ospf_packet.c: Use getsockopt_pktinfo_ifindex and
          SOPT_SIZE_CMSG_PKTINFO_IPV4.

ospfd/ChangeLog
ospfd/ospf_network.c
ospfd/ospf_packet.c

index 5702732d3310308a335beabaa398dab39a93fd37..453036ea2965ff3882e34e57d33e0c0aeb19821f 100644 (file)
@@ -1,3 +1,10 @@
+2004-07-23 Paul Jakma <paul@dishone.st>
+
+       * ospf_network.c: Replace PKTINFO/RECVIF with call to
+         setsockopt_pktinfo
+       * ospf_packet.c: Use getsockopt_pktinfo_ifindex and
+         SOPT_SIZE_CMSG_PKTINFO_IPV4.
+
 2004-07-14 Paul Jakma <paul@dishone.st>
 
        * ospf_packet.c: (ospf_ls_upd_send_queue_event) Partial fix for 
index 2766abd5444df136384620fc8c4d063fc8ac33c5..63851879e7bc637ffa330eb0f0fd4569fd3e4015 100644 (file)
@@ -201,27 +201,9 @@ ospf_sock_init (void)
   zlog_warn ("IP_HDRINCL option not available");
 #endif /* IP_HDRINCL */
 
-#if defined (IP_PKTINFO)
-  ret = setsockopt (ospf_sock, IPPROTO_IP, IP_PKTINFO, &hincl, sizeof (hincl));
-   if (ret < 0)
-     {
-       if ( ospfd_privs.change (ZPRIVS_LOWER) )
-         zlog_err ("ospf_sock_init: could not lower privs, %s",
-                   strerror (errno) );
-       zlog_warn ("Can't set IP_PKTINFO option");
-     }
-#elif defined (IP_RECVIF)
-  ret = setsockopt (ospf_sock, IPPROTO_IP, IP_RECVIF, &hincl, sizeof (hincl));
-   if (ret < 0)
-     {
-       if ( ospfd_privs.change (ZPRIVS_LOWER) )
-         zlog_err ("ospf_sock_init: could not lower privs, %s",
-                   strerror (errno) );
-       zlog_warn ("Can't set IP_RECVIF option");
-     }
-#else
-#warning "cannot be able to receive link information on this OS"
-#endif
+  ret = setsockopt_pktinfo (AF_INET, ospf_sock, 1);
+  if (ret < 0)
+     zlog_warn ("Can't set pktinfo option");
 
   if (ospfd_privs.change (ZPRIVS_LOWER))
     {
index 990fe6ab7b9f9d96e0ea79a3bc3b1ec86808512f..67215ebc2c21167d4c1ab0b8e02072ef52aaf217 100644 (file)
@@ -31,6 +31,7 @@
 #include "sockunion.h"
 #include "stream.h"
 #include "log.h"
+#include "sockopt.h"
 #include "md5-gnu.h"
 
 #include "ospfd/ospfd.h"
@@ -1880,17 +1881,17 @@ ospf_recv_packet (int fd, struct interface **ifp)
   unsigned int ifindex = 0;
   struct iovec iov;
   struct cmsghdr *cmsg;
-#if defined (IP_PKTINFO)
-  struct in_pktinfo *pktinfo;
-#elif defined (IP_RECVIF)
-  struct sockaddr_dl *pktinfo;
-#else
-  char *pktinfo; /* dummy */
-#endif
-  char buff [sizeof (*cmsg) + sizeof (*pktinfo)];
-  struct msghdr msgh = {NULL, 0, &iov, 1, buff,
-                       sizeof (*cmsg) + sizeof (*pktinfo), 0};
-    
+  char buff [sizeof (*cmsg) + SOPT_SIZE_CMSG_PKTINFO_IPV4()];
+  struct msghdr msgh;
+
+  msgh.msg_name = NULL;
+  msgh.msg_namelen = 0;
+  msgh.msg_iov = &iov;
+  msgh.msg_iovlen = 1;
+  msgh.msg_control = (caddr_t) buff;
+  msgh.msg_controllen = sizeof (buff);
+  msgh.msg_flags = 0;
+  
   ret = recvfrom (fd, (void *)&iph, sizeof (iph), MSG_PEEK, NULL, 0);
   
   if (ret != sizeof (iph))
@@ -1928,33 +1929,7 @@ ospf_recv_packet (int fd, struct interface **ifp)
   iov.iov_len = ip_len;
   ret = recvmsg (fd, &msgh, 0);
   
-  cmsg = CMSG_FIRSTHDR (&msgh);
-  
-  if (cmsg != NULL && //cmsg->cmsg_len == sizeof (*pktinfo) &&
-      cmsg->cmsg_level == IPPROTO_IP &&
-#if defined (IP_PKTINFO)
-      cmsg->cmsg_type == IP_PKTINFO
-#elif defined (IP_RECVIF)
-      cmsg->cmsg_type == IP_RECVIF
-#else
-      0
-#endif
-      )
-    {
-#if defined (IP_PKTINFO)
-      pktinfo = (struct in_pktinfo *)CMSG_DATA(cmsg);
-      ifindex = pktinfo->ipi_ifindex;
-#elif defined (IP_RECVIF)
-#ifdef SUNOS_5
-      ifindex = *(uint_t *)CMSG_DATA(cmsg);
-#else
-      pktinfo = (struct sockaddr_dl *)CMSG_DATA(cmsg);
-      ifindex = pktinfo->sdl_index;
-#endif /* SUNOS_5 */
-#else
-      ifindex = 0;
-#endif
-    }
+  ifindex = getsockopt_pktinfo_ifindex (AF_INET, &msgh);
   
   *ifp = if_lookup_by_index (ifindex);