]> git.puffer.fish Git - matthieu/frr.git/commitdiff
ospfd: fix vrf bind sock non-linux system
authorChirag Shah <chirag@cumulusnetworks.com>
Sun, 17 Sep 2017 01:08:33 +0000 (18:08 -0700)
committerChirag Shah <chirag@cumulusnetworks.com>
Tue, 3 Oct 2017 16:22:47 +0000 (09:22 -0700)
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>
ospfd/ospf_network.c
ospfd/ospf_packet.c

index f5402e7cd3f2daa0b4b30d8227bdb0c91fd36869..d1c1429054d05f692b1928369d85f6c32eb60187 100644 (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;
 }
index a9a4adf72c3f239c8855308a6c08d0b53ec28f51..015eac096ca4fb1dc24c46046343fe29e2ce6db6 100644 (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