From: Renato Westphal Date: Sat, 18 Mar 2017 20:05:35 +0000 (-0300) Subject: ldpd: change the sorting algorithm of adjacencies X-Git-Tag: frr-3.1-dev~25^2~1 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=f2725627317af322faa926fb9098e0adb9c60ae4;p=matthieu%2Ffrr.git ldpd: change the sorting algorithm of adjacencies Now the "show mpls ldp discovery" command will display all LDP adjancencies sorted by address family, neighbor ID and then type (link or targeted). Example: vtysh# show mpls ldp discovery AF ID Type Source Holdtime ipv4 3.3.3.3 Link rt2-eth1 15 ipv4 3.3.3.3 Link rt2-eth2 15 ipv4 4.4.4.4 Link rt2-eth1 15 ipv6 1.1.1.1 Link rt2-eth0 15 ipv6 3.3.3.3 Link rt2-eth1 15 ipv6 3.3.3.3 Link rt2-eth2 15 ipv6 4.4.4.4 Link rt2-eth1 15 Signed-off-by: Renato Westphal --- 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 *);