[quagga-dev 8497] Re: [PATCH 3/3] ospfd: use setsockopt_so_bindtodevice to specify out interface.

Joakim Tjernlund joakim.tjernlund at transmode.se
Mon Feb 7 13:10:05 GMT 2011


paul at jakma.org wrote on 2011/02/04 11:50:47:
>
> On Fri, 4 Feb 2011, Joakim Tjernlund wrote:
>
> > +  static int out_fd = -1;
>
> Why not put this in struct ospf alongside the other fd, and rename
> that fd to in_fd?

Oh well, did that except renaming fd to in_fd.

 Jocke

>From 879a54cdd857b684d478c46273eb87d96de70b8b Mon Sep 17 00:00:00 2001
From: Joakim Tjernlund <Joakim.Tjernlund at transmode.se>
Date: Fri, 4 Feb 2011 11:07:43 +0100
Subject: [PATCH] ospfd: use setsockopt_so_bindtodevice to specify out interface.

When using multiple interfaces with the same IP address one
needs to specify the interface to transmit OSPF protocol msgs on.
Otherwise you end up with a permanent retransmission list which
can be seen with:
ospfd> show ip ospf neighbor
    Neighbor ID Pri State           Dead Time Address         Interface            RXmtL RqstL DBsmL
192.168.46.10     1 Full/DROther      39.320s 192.168.46.10   p1-6-19-6-20:192.168.21.20     0     0     0
192.168.1.10      1 Full/DROther      39.910s 192.168.1.10    p1-4-13-4-14:192.168.21.20     0     0     0
192.168.45.10     1 Full/DROther      39.900s 192.168.45.10   p1-3-15-3-16:192.168.21.20     0     0     0
192.168.1.10      1 Full/DROther      39.910s 192.168.1.10    p1-4-15-4-16:192.168.21.20     1     0     0
192.168.45.10     1 Full/DROther      35.030s 192.168.45.10   p1-6-17-6-18:192.168.21.20     1     0     0
192.168.45.11     1 Full/DROther      30.090s 192.168.45.11   p1-8-13-8-14:192.168.21.20     0     0     0
192.168.45.10     1 Full/DROther      37.830s 192.168.45.10   p1-3-13-3-14:192.168.21.20     1     0     0

Signed-off-by: Joakim Tjernlund <Joakim.Tjernlund at transmode.se>
---
 ospfd/ospf_packet.c |    9 +++++----
 ospfd/ospfd.c       |    8 +++++++-
 ospfd/ospfd.h       |    1 +
 3 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/ospfd/ospf_packet.c b/ospfd/ospf_packet.c
index 10bfbc1..0cd5ac0 100644
--- a/ospfd/ospf_packet.c
+++ b/ospfd/ospf_packet.c
@@ -680,19 +680,20 @@ ospf_write (struct thread *thread)
   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;
-
+  /* set outgoing interface */
+  ret = setsockopt_so_bindtodevice (ospf->out_fd, oi->ifp->name);
   /* Sadly we can not rely on kernels to fragment packets because of either
    * IP_HDRINCL and/or multicast destination being set.
    */
 #ifdef WANT_OSPF_WRITE_FRAGMENT
   if ( op->length > maxdatasize )
-    ospf_write_frags (ospf->fd, op, &iph, &msg, maxdatasize,
+    ospf_write_frags (ospf->out_fd, op, &iph, &msg, maxdatasize,
                       oi->ifp->mtu, flags, type);
 #endif /* WANT_OSPF_WRITE_FRAGMENT */

   /* send final fragment (could be first) */
   sockopt_iphdrincl_swab_htosys (&iph);
-  ret = sendmsg (ospf->fd, &msg, flags);
+  ret = sendmsg (ospf->out_fd, &msg, flags);
   sockopt_iphdrincl_swab_systoh (&iph);

   if (ret < 0)
@@ -732,7 +733,7 @@ ospf_write (struct thread *thread)
   /* If packets still remain in queue, call write thread. */
   if (!list_isempty (ospf->oi_write_q))
     ospf->t_write =
-      thread_add_write (master, ospf_write, ospf, ospf->fd);
+      thread_add_write (master, ospf_write, ospf, ospf->out_fd);

   return 0;
 }
diff --git a/ospfd/ospfd.c b/ospfd/ospfd.c
index b1ece52..1420897 100644
--- a/ospfd/ospfd.c
+++ b/ospfd/ospfd.c
@@ -217,7 +217,13 @@ ospf_new (void)
 	       "a socket");
       exit(1);
     }
-  new->maxsndbuflen = getsockopt_so_sendbuf (new->fd);
+  if ((new->out_fd = ospf_sock_init()) < 0)
+    {
+      zlog_err("ospf_new: fatal error: ospf_sock_init was unable to open "
+	       "an out socket");
+      exit(1);
+    }
+  new->maxsndbuflen = getsockopt_so_sendbuf (new->out_fd);
   if (IS_DEBUG_OSPF (zebra, ZEBRA_INTERFACE))
     zlog_debug ("%s: starting with OSPF send buffer size %d",
       __func__, new->maxsndbuflen);
diff --git a/ospfd/ospfd.h b/ospfd/ospfd.h
index 6a60e86..b233b88 100644
--- a/ospfd/ospfd.h
+++ b/ospfd/ospfd.h
@@ -266,6 +266,7 @@ struct ospf
   struct thread *t_write;
   struct thread *t_read;
   int fd;
+  int out_fd;
   int maxsndbuflen;
   struct stream *ibuf;
   struct list *oi_write_q;
--
1.7.3.4




More information about the Quagga-dev mailing list