summaryrefslogtreecommitdiff
path: root/sysdep/unix/krt.c
diff options
context:
space:
mode:
authorOndrej Zajicek <santiago@crfreenet.org>2012-08-29 12:42:49 +0200
committerOndrej Zajicek <santiago@crfreenet.org>2012-08-29 12:42:49 +0200
commit0343d066dab077d1391640c53198199b16bef993 (patch)
tree971e6a3a240af07e0134788e40fab5f9d4e8bef5 /sysdep/unix/krt.c
parent8ecbaf9c70b802a1200ad37f2bfd4bc64173c5fe (diff)
Fixes a bug in primary IP selection.
Diffstat (limited to 'sysdep/unix/krt.c')
-rw-r--r--sysdep/unix/krt.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/sysdep/unix/krt.c b/sysdep/unix/krt.c
index 2bd1bc44..2128e136 100644
--- a/sysdep/unix/krt.c
+++ b/sysdep/unix/krt.c
@@ -114,12 +114,18 @@ kif_request_scan(void)
}
static inline int
-prefer_scope(struct ifa *a, struct ifa *b)
-{ return (a->scope > SCOPE_LINK) && (b->scope <= SCOPE_LINK); }
-
-static inline int
prefer_addr(struct ifa *a, struct ifa *b)
-{ return ipa_compare(a->ip, b->ip) < 0; }
+{
+ int sa = a->scope > SCOPE_LINK;
+ int sb = b->scope > SCOPE_LINK;
+
+ if (sa < sb)
+ return 0;
+ else if (sa > sb)
+ return 1;
+ else
+ return ipa_compare(a->ip, b->ip) < 0;
+}
static inline struct ifa *
find_preferred_ifa(struct iface *i, ip_addr prefix, ip_addr mask)
@@ -130,7 +136,7 @@ find_preferred_ifa(struct iface *i, ip_addr prefix, ip_addr mask)
{
if (!(a->flags & IA_SECONDARY) &&
ipa_equal(ipa_and(a->ip, mask), prefix) &&
- (!b || prefer_scope(a, b) || prefer_addr(a, b)))
+ (!b || prefer_addr(a, b)))
b = a;
}