summaryrefslogtreecommitdiffstats
path: root/zebra/router-id.c
diff options
context:
space:
mode:
authorStephen Hemminger <shemminger@vyatta.com>2009-12-21 16:50:43 +0100
committerDenis Ovsienko <infrastation@yandex.ru>2009-12-21 16:50:43 +0100
commitb6516829595ed4fc47af955de8bda9ef5be14ffd (patch)
tree842806138758343d41598fded61943de51c4c363 /zebra/router-id.c
parentlib: make some structures constant (diff)
downloadfrr-b6516829595ed4fc47af955de8bda9ef5be14ffd.tar.xz
frr-b6516829595ed4fc47af955de8bda9ef5be14ffd.zip
zebra: change router-id selection algo
The router-id table looks like is supposed to be sorted in current quagga code, but the nodes are not added with the sorting function. The sorting function is host byte order dependent. The values need to converted before comparison. Fixing this causes Zebra to choose the largest IP address as router-id, rather than the last address. This probably will surprise some users. The other option would be to just remove the comparison function and keep the existing LIFO behavior. Lastly, simple subtraction works well for comparing. * zebra/router-id.c * router_id_add_address(): employ listnode_add_sort() * router_id_cmp(): employ ntohl(), then compare integers
Diffstat (limited to 'zebra/router-id.c')
-rw-r--r--zebra/router-id.c16
1 files changed, 6 insertions, 10 deletions
diff --git a/zebra/router-id.c b/zebra/router-id.c
index 41bab5456..3d6b511c5 100644
--- a/zebra/router-id.c
+++ b/zebra/router-id.c
@@ -136,7 +136,7 @@ router_id_add_address (struct connected *ifc)
l = &rid_all_sorted_list;
if (!router_id_find_node (l, ifc))
- listnode_add (l, ifc);
+ listnode_add_sort (l, ifc);
router_id_get (&after);
@@ -228,16 +228,12 @@ DEFUN (no_router_id,
static int
router_id_cmp (void *a, void *b)
{
- unsigned int A, B;
+ const struct connected *ifa = (const struct connected *)a;
+ const struct connected *ifb = (const struct connected *)b;
+ unsigned int A = ntohl(ifa->address->u.prefix4.s_addr);
+ unsigned int B = ntohl(ifb->address->u.prefix4.s_addr);
- A = ((struct connected *) a)->address->u.prefix4.s_addr;
- B = ((struct connected *) b)->address->u.prefix4.s_addr;
-
- if (A > B)
- return 1;
- else if (A < B)
- return -1;
- return 0;
+ return (int) (A - B);
}
void