[quagga-dev 7793] Re: IPv6 Multicast Hop Limit for OSPFv3

Mike Pontillo pontillo at gmail.com
Thu Feb 11 07:50:28 GMT 2010


Nick, all,

On Wed, Feb 10, 2010 at 2:10 PM, Mike Pontillo <pontillo at gmail.com> wrote:
> Thanks for the feedback. Looks like there is currently a
> sockopt_ttl(family, sock, ttl) in sockunion.c, but it only sets the
> unicast TTL.I'm thinking we create a sockopt_mcast_ttl(family, sock,
> ttl), then, and have it set IP_MULTICAST_TTL and IPV6_MULTICAST_HOPS,
> depending on the family. Sound good?
>
> What do you think about the #ifdef? I would rather remove it, but I am
> only testing on a relatively recent Linux distribution, so I'm not
> sure how pervasive support is for those socket options. I can change
> the #ifdef strategy to be more like the one in sockunion.c, where it
> checks for #ifdef IP_TTL and #ifdef HAVE_IPV6, which seems cleaner.>

   I went ahead and took this approach; patch attached. I went ahead
and removed a little bit of dead code while I was in there.

   I tested the IPv6 version of the new sockopt_mcast_ttl() call via
OSPFv3. The IPv4 version remains untested, but I don't see why it
won't work. =)

Regards,
Mike
-------------- next part --------------
diff --git a/lib/sockunion.c b/lib/sockunion.c
index 6a40f33..4670392 100644
--- a/lib/sockunion.c
+++ b/lib/sockunion.c
@@ -527,6 +527,42 @@ sockopt_ttl (int family, int sock, int ttl)
   return 0;
 }
 
+int
+sockopt_mcast_ttl (int family, int sock, int ttl)
+{
+  int ret;
+
+#ifdef IP_MULTICAST_TTL
+  if (family == AF_INET)
+    {
+      ret = setsockopt (sock, IPPROTO_IP, IP_MULTICAST_TTL, 
+			(void *) &ttl, sizeof (int));
+      if (ret < 0)
+	{
+	  zlog (NULL, LOG_WARNING, "can't set sockopt IP_MULTICAST_TTL %d to socket %d", ttl, sock);
+	  return -1;
+	}
+      return 0;
+    }
+#endif /* IP_MULTICAST_TTL */
+#ifdef HAVE_IPV6
+  if (family == AF_INET6)
+    {
+      ret = setsockopt (sock, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, 
+			(void *) &ttl, sizeof (int));
+      if (ret < 0)
+	{
+	  zlog (NULL, LOG_WARNING, "can't set sockopt IPV6_MULTICAST_HOPS %d to socket %d",
+		    ttl, sock);
+	  return -1;
+	}
+      return 0;
+    }
+#endif /* HAVE_IPV6 */
+  return 0;
+}
+
+
 /* If same family and same prefix return 1. */
 int
 sockunion_same (union sockunion *su1, union sockunion *su2)
diff --git a/ospf6d/ospf6_network.c b/ospf6d/ospf6_network.c
index 96b82af..8a87ef5 100644
--- a/ospf6d/ospf6_network.c
+++ b/ospf6d/ospf6_network.c
@@ -36,16 +36,6 @@ int  ospf6_sock;
 struct in6_addr allspfrouters6;
 struct in6_addr alldrouters6;
 
-/* setsockopt ReUseAddr to on */
-void
-ospf6_set_reuseaddr (void)
-{
-  u_int on = 0;
-  if (setsockopt (ospf6_sock, SOL_SOCKET, SO_REUSEADDR, &on,
-                  sizeof (u_int)) < 0)
-    zlog_warn ("Network: set SO_REUSEADDR failed: %s", safe_strerror (errno));
-}
-
 /* setsockopt MulticastLoop to off */
 void
 ospf6_reset_mcastloop (void)
@@ -95,11 +85,13 @@ ospf6_serv_sock (void)
       zlog_err ("ospf_sock_init: could not lower privs");
 
   /* set socket options */
-#if 1
   sockopt_reuseaddr (ospf6_sock);
-#else
-  ospf6_set_reuseaddr ();
-#endif /*1*/
+
+  /* 
+   * RFC 5340 Appendix A.1 - the default hop limit for outgoing multicast 
+   * packets should be set to 1
+   */
+  sockopt_mcast_ttl(AF_INET6, ospf6_sock, 1);
   ospf6_reset_mcastloop ();
   ospf6_set_pktinfo ();
   ospf6_set_checksum ();


More information about the Quagga-dev mailing list