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.
This commit is contained in:
paul 2004-07-23 15:13:48 +00:00
parent 4f7baa0e43
commit 2dd8bb4e9b
3 changed files with 23 additions and 59 deletions

View 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> 2004-07-14 Paul Jakma <paul@dishone.st>
* ospf_packet.c: (ospf_ls_upd_send_queue_event) Partial fix for * ospf_packet.c: (ospf_ls_upd_send_queue_event) Partial fix for

View file

@ -201,27 +201,9 @@ ospf_sock_init (void)
zlog_warn ("IP_HDRINCL option not available"); zlog_warn ("IP_HDRINCL option not available");
#endif /* IP_HDRINCL */ #endif /* IP_HDRINCL */
#if defined (IP_PKTINFO) ret = setsockopt_pktinfo (AF_INET, ospf_sock, 1);
ret = setsockopt (ospf_sock, IPPROTO_IP, IP_PKTINFO, &hincl, sizeof (hincl)); if (ret < 0)
if (ret < 0) zlog_warn ("Can't set pktinfo option");
{
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
if (ospfd_privs.change (ZPRIVS_LOWER)) if (ospfd_privs.change (ZPRIVS_LOWER))
{ {

View file

@ -31,6 +31,7 @@
#include "sockunion.h" #include "sockunion.h"
#include "stream.h" #include "stream.h"
#include "log.h" #include "log.h"
#include "sockopt.h"
#include "md5-gnu.h" #include "md5-gnu.h"
#include "ospfd/ospfd.h" #include "ospfd/ospfd.h"
@ -1880,17 +1881,17 @@ ospf_recv_packet (int fd, struct interface **ifp)
unsigned int ifindex = 0; unsigned int ifindex = 0;
struct iovec iov; struct iovec iov;
struct cmsghdr *cmsg; struct cmsghdr *cmsg;
#if defined (IP_PKTINFO) char buff [sizeof (*cmsg) + SOPT_SIZE_CMSG_PKTINFO_IPV4()];
struct in_pktinfo *pktinfo; struct msghdr msgh;
#elif defined (IP_RECVIF)
struct sockaddr_dl *pktinfo; msgh.msg_name = NULL;
#else msgh.msg_namelen = 0;
char *pktinfo; /* dummy */ msgh.msg_iov = &iov;
#endif msgh.msg_iovlen = 1;
char buff [sizeof (*cmsg) + sizeof (*pktinfo)]; msgh.msg_control = (caddr_t) buff;
struct msghdr msgh = {NULL, 0, &iov, 1, buff, msgh.msg_controllen = sizeof (buff);
sizeof (*cmsg) + sizeof (*pktinfo), 0}; msgh.msg_flags = 0;
ret = recvfrom (fd, (void *)&iph, sizeof (iph), MSG_PEEK, NULL, 0); ret = recvfrom (fd, (void *)&iph, sizeof (iph), MSG_PEEK, NULL, 0);
if (ret != sizeof (iph)) if (ret != sizeof (iph))
@ -1928,33 +1929,7 @@ ospf_recv_packet (int fd, struct interface **ifp)
iov.iov_len = ip_len; iov.iov_len = ip_len;
ret = recvmsg (fd, &msgh, 0); ret = recvmsg (fd, &msgh, 0);
cmsg = CMSG_FIRSTHDR (&msgh); ifindex = getsockopt_pktinfo_ifindex (AF_INET, &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
}
*ifp = if_lookup_by_index (ifindex); *ifp = if_lookup_by_index (ifindex);