]> git.proxmox.com Git - mirror_frr.git/commitdiff
ripd, ripngd: fix cleaning up of offset lists
authorRenato Westphal <renato@opensourcerouting.org>
Thu, 18 Apr 2019 15:32:19 +0000 (12:32 -0300)
committerRenato Westphal <renato@opensourcerouting.org>
Fri, 19 Apr 2019 19:09:50 +0000 (16:09 -0300)
We should never attempt to remove a list item in the "del" callback
of the list. This is already performed by the list_delete() function,
doing it twice leads to crashes or memory corruption.

Introduce the offset_list_free() function so that we can separate the
removal and deallocation of offset lists into separate functions,
without code duplication. offset_list_del() will be used by the
northbound callbacks to remove offset lists, while offset_list_free()
will be used by rip_clean() to clean up all RIP offset lists using
list_delete(). Do the same for ripngd.

This is a fallout from the ripd/ripngd northbound conversion.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
ripd/rip_offset.c
ripd/ripd.c
ripd/ripd.h
ripngd/ripng_offset.c
ripngd/ripngd.c
ripngd/ripngd.h

index b3f84fe50f6a702b1ae8b54415e795c5ff9d0f16..8307a95d27b3b11a792297d8b82105b3e8247bf6 100644 (file)
@@ -50,6 +50,11 @@ struct rip_offset_list *rip_offset_list_new(struct rip *rip, const char *ifname)
 void offset_list_del(struct rip_offset_list *offset)
 {
        listnode_delete(offset->rip->offset_list_master, offset);
+       offset_list_free(offset);
+}
+
+void offset_list_free(struct rip_offset_list *offset)
+{
        if (OFFSET_LIST_IN_NAME(offset))
                free(OFFSET_LIST_IN_NAME(offset));
        if (OFFSET_LIST_OUT_NAME(offset))
index 201de9a46e0b3f46942e999f230f6ff06442c63a..3a1ffd17a6f47561d7b54a1e40f4c71e77509602 100644 (file)
@@ -2712,7 +2712,7 @@ struct rip *rip_create(const char *vrf_name, struct vrf *vrf, int socket)
        rip->passive_nondefault = vector_init(1);
        rip->offset_list_master = list_new();
        rip->offset_list_master->cmp = (int (*)(void *, void *))offset_list_cmp;
-       rip->offset_list_master->del = (void (*)(void *))offset_list_del;
+       rip->offset_list_master->del = (void (*)(void *))offset_list_free;
 
        /* Distribute list install. */
        rip->distribute_ctx = distribute_list_ctx_create(vrf);
index 7b196a16be40e13a489b05918965b6e6efd35634..44f5932fb69a2c99e0bfa27a506cac86b9ce978c 100644 (file)
@@ -507,6 +507,7 @@ extern struct rip_info *rip_ecmp_delete(struct rip *rip,
 extern struct rip_offset_list *rip_offset_list_new(struct rip *rip,
                                                   const char *ifname);
 extern void offset_list_del(struct rip_offset_list *offset);
+extern void offset_list_free(struct rip_offset_list *offset);
 extern struct rip_offset_list *rip_offset_list_lookup(struct rip *rip,
                                                      const char *ifname);
 extern int rip_offset_list_apply_in(struct prefix_ipv4 *, struct interface *,
index 41ba2360ba07d5b4510328dc23fc33efacc661d5..fe95ccfc2bdf18907fbf91fd6d2c10a58dbf20cc 100644 (file)
@@ -56,6 +56,11 @@ struct ripng_offset_list *ripng_offset_list_new(struct ripng *ripng,
 void ripng_offset_list_del(struct ripng_offset_list *offset)
 {
        listnode_delete(offset->ripng->offset_list_master, offset);
+       ripng_offset_list_free(offset);
+}
+
+void ripng_offset_list_free(struct ripng_offset_list *offset)
+{
        if (OFFSET_LIST_IN_NAME(offset))
                free(OFFSET_LIST_IN_NAME(offset));
        if (OFFSET_LIST_OUT_NAME(offset))
index b36cee2c5d5a1f156b3c0654e72d577362e0d48f..411689a7a720eeb761419d2483b55a6011d03ed7 100644 (file)
@@ -1889,7 +1889,7 @@ struct ripng *ripng_create(const char *vrf_name, struct vrf *vrf, int socket)
        ripng->offset_list_master->cmp =
                (int (*)(void *, void *))offset_list_cmp;
        ripng->offset_list_master->del =
-               (void (*)(void *))ripng_offset_list_del;
+               (void (*)(void *))ripng_offset_list_free;
        ripng->distribute_ctx = distribute_list_ctx_create(vrf);
        distribute_list_add_hook(ripng->distribute_ctx,
                                 ripng_distribute_update);
index dcc61ae58a0e6249b2d98011179a962d6961c262..dc425b6958c60228c6c0bdc331a1bdc7380300cc 100644 (file)
@@ -421,6 +421,7 @@ extern void ripng_peer_list_del(void *arg);
 extern struct ripng_offset_list *ripng_offset_list_new(struct ripng *ripng,
                                                       const char *ifname);
 extern void ripng_offset_list_del(struct ripng_offset_list *offset);
+extern void ripng_offset_list_free(struct ripng_offset_list *offset);
 extern struct ripng_offset_list *ripng_offset_list_lookup(struct ripng *ripng,
                                                          const char *ifname);
 extern int ripng_offset_list_apply_in(struct ripng *ripng,