diff --git a/ldpd/adjacency.c b/ldpd/adjacency.c index 2e7b43296a..244d0f55a2 100644 --- a/ldpd/adjacency.c +++ b/ldpd/adjacency.c @@ -41,6 +41,16 @@ RB_GENERATE(tnbr_head, tnbr, entry, tnbr_compare) static __inline int adj_compare(struct adj *a, struct adj *b) { + if (adj_get_af(a) < adj_get_af(b)) + return (-1); + if (adj_get_af(a) > adj_get_af(b)) + return (1); + + if (ntohl(a->lsr_id.s_addr) < ntohl(b->lsr_id.s_addr)) + return (-1); + if (ntohl(a->lsr_id.s_addr) > ntohl(b->lsr_id.s_addr)) + return (1); + if (a->source.type < b->source.type) return (-1); if (a->source.type > b->source.type) @@ -54,21 +64,13 @@ adj_compare(struct adj *a, struct adj *b) if (strcmp(a->source.link.ia->iface->name, b->source.link.ia->iface->name) > 0) return (1); - if (a->source.link.ia->af < b->source.link.ia->af) - return (-1); - if (a->source.link.ia->af > b->source.link.ia->af) - return (1); return (ldp_addrcmp(a->source.link.ia->af, &a->source.link.src_addr, &b->source.link.src_addr)); case HELLO_TARGETED: - if (a->source.target->af < b->source.target->af) - return (-1); - if (a->source.target->af > b->source.target->af) - return (1); return (ldp_addrcmp(a->source.target->af, &a->source.target->addr, &b->source.target->addr)); default: - fatalx("adj_get_af: unknown hello type"); + fatalx("adj_compare: unknown hello type"); } return (0); @@ -150,9 +152,10 @@ adj_del(struct adj *adj, uint32_t notif_status) } struct adj * -adj_find(struct hello_source *source) +adj_find(struct in_addr lsr_id, struct hello_source *source) { struct adj adj; + adj.lsr_id = lsr_id; adj.source = *source; return (RB_FIND(global_adj_head, &global.adj_tree, &adj)); } diff --git a/ldpd/hello.c b/ldpd/hello.c index e7935899b7..19e3013bb8 100644 --- a/ldpd/hello.c +++ b/ldpd/hello.c @@ -291,7 +291,7 @@ recv_hello(struct in_addr lsr_id, struct ldp_msg *msg, int af, source.link.src_addr = *src; } - adj = adj_find(&source); + adj = adj_find(lsr_id, &source); nbr = nbr_find_ldpid(lsr_id.s_addr); /* check dual-stack tlv */ diff --git a/ldpd/ldpe.h b/ldpd/ldpe.h index 8f2d1931d9..4cac18f0b9 100644 --- a/ldpd/ldpe.h +++ b/ldpd/ldpe.h @@ -232,7 +232,7 @@ in_addr_t if_get_ipv4_addr(struct iface *); struct adj *adj_new(struct in_addr, struct hello_source *, union ldpd_addr *); void adj_del(struct adj *, uint32_t); -struct adj *adj_find(struct hello_source *); +struct adj *adj_find(struct in_addr, struct hello_source *); int adj_get_af(struct adj *adj); void adj_start_itimer(struct adj *); void adj_stop_itimer(struct adj *);