Fix bug # 9666 - Broken filtering of link-local addresses.
authorTimur Bakeyev <timur@FreeBSD.org>
Thu, 28 Feb 2013 00:25:07 +0000 (16:25 -0800)
committerJeremy Allison <jra@samba.org>
Thu, 28 Feb 2013 19:56:57 +0000 (20:56 +0100)
This patch should address the problem with Link Local addresses
on FreeBSD and Linux.

Reviewed-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Richard Sharpe <rsharpe@samba.org>
Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Thu Feb 28 20:56:57 CET 2013 on sn-devel-104

lib/socket/interfaces.c

index 74c642372a24323befae23534d1f525991a96fab..e62da3c3a1f906012d61a789a6f2b12fda32c875 100644 (file)
@@ -186,6 +186,21 @@ static int _get_interfaces(TALLOC_CTX *mem_ctx, struct iface_struct **pifaces)
                memcpy(&ifaces[total].ip, ifptr->ifa_addr, copy_size);
                memcpy(&ifaces[total].netmask, ifptr->ifa_netmask, copy_size);
 
+               /* calculate broadcast address */
+#if defined(HAVE_IPV6)
+               if (ifptr->ifa_addr->sa_family == AF_INET6) {
+                       struct sockaddr_in6 *sin6 =
+                               (struct sockaddr_in6 *)ifptr->ifa_addr;
+                       struct in6_addr *in6 =
+                               (struct in6_addr *)&sin6->sin6_addr;
+
+                       if (IN6_IS_ADDR_LINKLOCAL(in6) || IN6_IS_ADDR_V4COMPAT(in6)) {
+                               continue;
+                       }
+                       /* IPv6 does not have broadcast it uses multicast. */
+                       memset(&ifaces[total].bcast, '\0', copy_size);
+               } else
+#endif
                if (ifaces[total].flags & (IFF_BROADCAST|IFF_LOOPBACK)) {
                        make_bcast(&ifaces[total].bcast,
                                &ifaces[total].ip,
@@ -195,19 +210,6 @@ static int _get_interfaces(TALLOC_CTX *mem_ctx, struct iface_struct **pifaces)
                        memcpy(&ifaces[total].bcast,
                                ifptr->ifa_dstaddr,
                                copy_size);
-#if defined(HAVE_IPV6)
-               } else if (ifptr->ifa_addr->sa_family == AF_INET6) {
-                       const struct sockaddr_in6 *sin6 =
-                               (const struct sockaddr_in6 *)ifptr->ifa_addr;
-                       const struct in6_addr *in6 =
-                               (const struct in6_addr *)&sin6->sin6_addr;
-
-                       if (IN6_IS_ADDR_LINKLOCAL(in6) || IN6_IS_ADDR_V4COMPAT(in6)) {
-                               continue;
-                       }
-                       /* IPv6 does not have broadcast it uses multicast. */
-                       memset(&ifaces[total].bcast, '\0', copy_size);
-#endif
                } else {
                        continue;
                }