]> git.proxmox.com Git - mirror_frr.git/commitdiff
*: Fixup to use proper list_cmp functions
authorDonald Sharp <sharpd@cumulusnetworks.com>
Wed, 17 Oct 2018 19:31:09 +0000 (15:31 -0400)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Fri, 19 Oct 2018 17:14:43 +0000 (13:14 -0400)
We had a variety of issues with sorted list compare functions.
This commit identifies and fixes these issues.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
ospf6d/ospf6_neighbor.c
ripd/rip_peer.c
ripngd/ripng_peer.c
zebra/zebra_vxlan.c

index 4c24f47131893ff1ea8b463088900a7ccb08fa58..bb451c239e6c3ae584aebd58b126cdf417d423b9 100644 (file)
@@ -59,7 +59,11 @@ int ospf6_neighbor_cmp(void *va, void *vb)
 {
        struct ospf6_neighbor *ona = (struct ospf6_neighbor *)va;
        struct ospf6_neighbor *onb = (struct ospf6_neighbor *)vb;
-       return (ntohl(ona->router_id) < ntohl(onb->router_id) ? -1 : 1);
+
+       if (ona->router_id == onb->router_id)
+               return 0;
+
+       return (ntohl(ona->router_id) < ntohl(onb->router_id)) ? -1 : 1;
 }
 
 struct ospf6_neighbor *ospf6_neighbor_lookup(uint32_t router_id,
index ae62835a746214fe1a64448b0919822f8a673f29..548dab9c01c70f77a87e31c4f1237af42c5d380d 100644 (file)
@@ -172,7 +172,10 @@ void rip_peer_display(struct vty *vty)
 
 static int rip_peer_list_cmp(struct rip_peer *p1, struct rip_peer *p2)
 {
-       return htonl(p1->addr.s_addr) > htonl(p2->addr.s_addr);
+       if (p2->addr.s_addr == p1->addr.s_addr)
+               return 0;
+
+       return (htonl(p2->addr.s_addr) < htonl(p1->addr.s_addr)) ? -1 : 1;
 }
 
 void rip_peer_init(void)
index 2f75898482fe059744a519d752d44ef00610c194..6b2a18353924921b6548a9ca877d567f1ef0c65e 100644 (file)
@@ -180,7 +180,7 @@ void ripng_peer_display(struct vty *vty)
 
 static int ripng_peer_list_cmp(struct ripng_peer *p1, struct ripng_peer *p2)
 {
-       return addr6_cmp(&p1->addr, &p2->addr) > 0;
+       return memcmp(&p1->addr, &p2->addr, sizeof(struct in6_addr));
 }
 
 void ripng_peer_init()
index 5078eff59016fd6b7772e7bb894d220ef56f6d8e..ab0b175cccbc491362d4b203db6bc9b0ab03b86c 100644 (file)
@@ -1268,6 +1268,14 @@ static int neigh_cmp(const void *p1, const void *p2)
        return (memcmp(&n1->ip, &n2->ip, sizeof(struct ipaddr)) == 0);
 }
 
+static int neigh_list_cmp(void *p1, void *p2)
+{
+       const zebra_neigh_t *n1 = p1;
+       const zebra_neigh_t *n2 = p2;
+
+       return memcmp(&n1->ip, &n2->ip, sizeof(struct ipaddr));
+}
+
 /*
  * Callback to allocate neighbor hash entry.
  */
@@ -2275,7 +2283,7 @@ static zebra_mac_t *zvni_mac_add(zebra_vni_t *zvni, struct ethaddr *macaddr)
        assert(mac);
 
        mac->neigh_list = list_new();
-       mac->neigh_list->cmp = (int (*)(void *, void *))neigh_cmp;
+       mac->neigh_list->cmp = neigh_list_cmp;
 
        return mac;
 }
@@ -2761,6 +2769,16 @@ static int vni_hash_cmp(const void *p1, const void *p2)
        return (zvni1->vni == zvni2->vni);
 }
 
+static int vni_list_cmp(void *p1, void *p2)
+{
+       const zebra_vni_t *zvni1 = p1;
+       const zebra_vni_t *zvni2 = p2;
+
+       if (zvni1->vni == zvni2->vni)
+               return 0;
+       return (zvni1->vni < zvni2->vni) ? -1 : 1;
+}
+
 /*
  * Callback to allocate VNI hash entry.
  */
@@ -3662,7 +3680,7 @@ static zebra_l3vni_t *zl3vni_add(vni_t vni, vrf_id_t vrf_id)
        zl3vni->svi_if = NULL;
        zl3vni->vxlan_if = NULL;
        zl3vni->l2vnis = list_new();
-       zl3vni->l2vnis->cmp = (int (*)(void *, void *))vni_hash_cmp;
+       zl3vni->l2vnis->cmp = vni_list_cmp;
 
        /* Create hash table for remote RMAC */
        zl3vni->rmac_table = hash_create(mac_hash_keymake, mac_cmp,