]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Changes primary addr selection on BSD to respect SIOCGIFADDR ioctl() result.
authorOndrej Zajicek <santiago@crfreenet.org>
Mon, 25 Nov 2013 00:21:39 +0000 (01:21 +0100)
committerOndrej Zajicek <santiago@crfreenet.org>
Mon, 25 Nov 2013 00:21:39 +0000 (01:21 +0100)
Thanks to Alexander V. Chernikov for the original patch.

sysdep/bsd/krt-sock.c
sysdep/linux/krt-sys.h
sysdep/unix/krt.c
sysdep/unix/krt.h

index 0bc29458cc083e90d5bf584d40d3f1129576568e..84ce9c6059b5638f2dd1d5502b340c0b2e9acfd0 100644 (file)
@@ -1058,3 +1058,36 @@ kif_sys_shutdown(struct kif_proto *p)
   krt_buffer_release(&p->p);
 }
 
+
+struct ifa *
+kif_get_primary_ip(struct iface *i)
+{
+#ifndef IPV6
+  static int fd = -1;
+  
+  if (fd < 0)
+    fd = socket(AF_INET, SOCK_DGRAM, 0);
+
+  struct ifreq ifr;
+  memset(&ifr, 0, sizeof(ifr));
+  strncpy(ifr.ifr_name, i->name, IFNAMSIZ);
+
+  int rv = ioctl(fd, SIOCGIFADDR, (char *) &ifr);
+  if (rv < 0)
+    return NULL;
+
+  ip_addr addr;
+  struct sockaddr_in *sin = (struct sockaddr_in *) &ifr.ifr_addr;
+  memcpy(&addr, &sin->sin_addr.s_addr, sizeof(ip_addr));
+  ipa_ntoh(addr);
+
+  struct ifa *a;
+  WALK_LIST(a, i->addrs)
+  {
+    if (ipa_equal(a->ip, addr))
+      return a;
+  }
+#endif
+
+  return NULL;
+}
index 7b3043a7dc4abd8f69c8c0c57d52e634e153e127..7e97968a41dbdb49d920b1dc463f5e769089f5d9 100644 (file)
@@ -27,6 +27,8 @@ static inline void kif_sys_postconfig(struct kif_config *c UNUSED) { }
 static inline void kif_sys_init_config(struct kif_config *c UNUSED) { }
 static inline void kif_sys_copy_config(struct kif_config *d UNUSED, struct kif_config *s UNUSED) { }
 
+static inline struct ifa * kif_get_primary_ip(struct iface *i) { return NULL; }
+
 
 /* Kernel routes */
 
index 57cfe5a48fd740e56728f4314548bdf4cac62bfd..8f24cf5182fc01c836f6a9e7d67084f887199dd2 100644 (file)
@@ -159,6 +159,9 @@ kif_choose_primary(struct iface *i)
          return a;
     }
 
+  if (a = kif_get_primary_ip(i))
+    return a;
+
   return find_preferred_ifa(i, IPA_NONE, IPA_NONE);
 }
 
index 446914d2bbd13d6863b987c79daa165bb2b020c6..99983ccdec33a15a44bf55acbd511341f55cd6cc 100644 (file)
@@ -142,5 +142,6 @@ void kif_sys_copy_config(struct kif_config *, struct kif_config *);
 
 void kif_do_scan(struct kif_proto *);
 
+struct ifa *kif_get_primary_ip(struct iface *i);
 
 #endif