ospfd: fix vrf bind sock non-linux system

For non GNU_LINUX like open Bsd avoid sending packet
to non vrf aware device using in_pktinfo.

Signed-off-by: Chirag Shah <chirag@cumulusnetworks.com>
This commit is contained in:
Chirag Shah 2017-09-16 18:08:33 -07:00
parent e7503eab31
commit e1b18df1ea
2 changed files with 18 additions and 2 deletions

View File

@ -153,6 +153,18 @@ int ospf_if_ipmulticast(struct ospf *top, struct prefix *p, ifindex_t ifindex)
if (ret < 0)
zlog_warn("can't setsockopt IP_MULTICAST_TTL(1) for fd %d: %s",
top->fd, safe_strerror(errno));
#ifndef GNU_LINUX
/* For GNU LINUX ospf_write uses IP_PKTINFO, in_pktinfo to send
* packet out of ifindex. Below would be used Non Linux system.
*/
ret = setsockopt_ipv4_multicast_if(top->fd, p->u.prefix4, ifindex);
if (ret < 0)
zlog_warn(
"can't setsockopt IP_MULTICAST_IF(fd %d, addr %s, "
"ifindex %u): %s",
top->fd, inet_ntoa(p->u.prefix4), ifindex,
safe_strerror(errno));
#endif
return ret;
}

View File

@ -648,9 +648,12 @@ static int ospf_write(struct thread *thread)
/* clang-format off */
#define OSPF_WRITE_IPHL_SHIFT 2
int pkt_count = 0;
#ifdef GNU_LINUX
unsigned char cmsgbuf[64] = {};
struct cmsghdr *cm = (struct cmsghdr *)cmsgbuf;
struct in_pktinfo *pi;
#endif
ospf->t_write = NULL;
@ -756,13 +759,14 @@ static int ospf_write(struct thread *thread)
msg.msg_namelen = sizeof(sa_dst);
msg.msg_iov = iov;
msg.msg_iovlen = 2;
msg.msg_control = (caddr_t)cm;
iov[0].iov_base = (char *)&iph;
iov[0].iov_len = iph.ip_hl << OSPF_WRITE_IPHL_SHIFT;
iov[1].iov_base = STREAM_PNT(op->s);
iov[1].iov_len = op->length;
#ifdef GNU_LINUX
msg.msg_control = (caddr_t)cm;
cm->cmsg_level = SOL_IP;
cm->cmsg_type = IP_PKTINFO;
cm->cmsg_len = CMSG_LEN(sizeof(struct in_pktinfo));
@ -770,7 +774,7 @@ static int ospf_write(struct thread *thread)
pi->ipi_ifindex = oi->ifp->ifindex;
msg.msg_controllen = cm->cmsg_len;
#endif
/* Sadly we can not rely on kernels to fragment packets
* because of either IP_HDRINCL and/or multicast