From e1b18df1ea6b001486342e14982177531eae8e45 Mon Sep 17 00:00:00 2001 From: Chirag Shah Date: Sat, 16 Sep 2017 18:08:33 -0700 Subject: [PATCH] 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 --- ospfd/ospf_network.c | 12 ++++++++++++ ospfd/ospf_packet.c | 8 ++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/ospfd/ospf_network.c b/ospfd/ospf_network.c index f5402e7cd3..d1c1429054 100644 --- a/ospfd/ospf_network.c +++ b/ospfd/ospf_network.c @@ -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; } diff --git a/ospfd/ospf_packet.c b/ospfd/ospf_packet.c index a9a4adf72c..015eac096c 100644 --- a/ospfd/ospf_packet.c +++ b/ospfd/ospf_packet.c @@ -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 -- 2.39.5