]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Use SO_BINDTODEVICE also in Linux/IPv6.
authorOndrej Zajicek <santiago@crfreenet.org>
Fri, 2 Apr 2010 14:11:46 +0000 (16:11 +0200)
committerOndrej Zajicek <santiago@crfreenet.org>
Fri, 2 Apr 2010 14:11:46 +0000 (16:11 +0200)
proto/ospf/iface.c
sysdep/bsd/sysio.h
sysdep/linux/sysio.h
sysdep/unix/io.c

index 041635539dd45b19d2dd064d29da62aaa1277c30..6931619b657ccecd42477b7de4e31a4ea13595f0 100644 (file)
@@ -66,17 +66,7 @@ ospf_sk_open(struct ospf_iface *ifa)
   sk = sk_new(p->pool);
   sk->type = SK_IP;
   sk->dport = OSPF_PROTO;
-
-#ifdef OSPFv2
-  /*
-   * In Linux IPv4, binding a raw socket to an IP address of an iface causes
-   * that the socket does not receive multicast packets, as they have
-   * different (multicast) destination IP address.
-   */
   sk->saddr = IPA_NONE;
-#else /* OSPFv3 */
-  sk->saddr = ifa->addr->ip; /* link-local addr */
-#endif
 
   sk->tos = IP_PREC_INTERNET_CONTROL;
   sk->rx_hook = ospf_rx_hook;
index 87c78fb3ed0ae18ca89be58f15567645b17b83e1..ff821a77cd304fe944518ce3c8add187b6196264 100644 (file)
@@ -22,6 +22,14 @@ get_inaddr(ip_addr *a, struct in6_addr *ia)
   ipa_ntoh(*a);
 }
 
+static inline char *
+sysio_bind_to_iface(sock *s)
+{
+  /* Unfortunately not available */
+  return NULL;
+}
+
+
 #else
 
 #include <net/if.h>
index 1cfbcc4b626eb133602d624f351f95fd72444fcb..795d0b36b0cd588da0ef94b7b0112a1ce03197d4 100644 (file)
@@ -6,6 +6,8 @@
  *     Can be freely distributed and used under the terms of the GNU GPL.
  */
 
+#include <net/if.h>
+
 #ifdef IPV6
 
 #ifndef IPV6_UNICAST_HOPS
@@ -28,9 +30,18 @@ get_inaddr(ip_addr *a, struct in6_addr *ia)
   ipa_ntoh(*a);
 }
 
-#else
+static inline char *
+sysio_bind_to_iface(sock *s)
+{
+  struct ifreq ifr;
+  strcpy(ifr.ifr_name, s->iface->name);
+  if (setsockopt(s->fd, SOL_SOCKET, SO_BINDTODEVICE, &ifr, sizeof(ifr)) < 0)
+    return "SO_BINDTODEVICE";
 
-#include <net/if.h>
+  return NULL;
+}
+
+#else
 
 static inline void
 set_inaddr(struct in_addr *ia, ip_addr a)
index abfa5c264cc42147916c75d5ea452dbfea33328a..a0dbb418a500f9ddc7f6e5a32d6e113dc104391c 100644 (file)
@@ -876,6 +876,9 @@ sk_setup_multicast(sock *s)
   if (setsockopt(s->fd, SOL_IPV6, IPV6_MULTICAST_IF, &index, sizeof(index)) < 0)
     ERR("IPV6_MULTICAST_IF");
 
+  if (err = sysio_bind_to_iface(s))
+    goto bad;
+
   return 0;
 
 bad: