]> git.puffer.fish Git - mirror/frr.git/commitdiff
zebra: use real MTYPEs for various objects 12432/head
authorMark Stapp <mjs@labn.net>
Fri, 2 Dec 2022 16:10:58 +0000 (11:10 -0500)
committerMark Stapp <mjs@labn.net>
Mon, 5 Dec 2022 15:55:35 +0000 (10:55 -0500)
Don't use MTYPE_TMP for many things in zebra: add specific
mem types.

Signed-off-by: Mark Stapp <mjs@labn.net>
zebra/if_netlink.c
zebra/interface.c
zebra/interface.h
zebra/irdp_interface.c
zebra/zapi_msg.c
zebra/zebra_gr.c
zebra/zebra_pbr.c
zebra/zebra_pbr.h
zebra/zserv.c
zebra/zserv.h

index b28c468a969dcb268f7a206895ba1fe7866a5adb..d628e47492a845ff41ea0f2b725995ce2c7a142d 100644 (file)
@@ -1081,8 +1081,8 @@ static int netlink_interface(struct nlmsghdr *h, ns_id_t ns_id, int startup)
        zif->link_ifindex = link_ifindex;
 
        if (desc) {
-               XFREE(MTYPE_TMP, zif->desc);
-               zif->desc = XSTRDUP(MTYPE_TMP, desc);
+               XFREE(MTYPE_ZIF_DESC, zif->desc);
+               zif->desc = XSTRDUP(MTYPE_ZIF_DESC, desc);
        }
 
        /* Hardware type and address. */
@@ -2136,9 +2136,9 @@ int netlink_link_change(struct nlmsghdr *h, ns_id_t ns_id, int startup)
 
                zif = ifp->info;
                if (zif) {
-                       XFREE(MTYPE_TMP, zif->desc);
+                       XFREE(MTYPE_ZIF_DESC, zif->desc);
                        if (desc)
-                               zif->desc = XSTRDUP(MTYPE_TMP, desc);
+                               zif->desc = XSTRDUP(MTYPE_ZIF_DESC, desc);
                }
        } else {
                /* Delete interface notification from kernel */
index 81ee995dd7cf2eb7feac0c95ca327179d487fbdc..87bb49042a30ab0df66f682475dc4037240f3a6e 100644 (file)
@@ -61,6 +61,7 @@ DEFINE_HOOK(zebra_if_extra_info, (struct vty * vty, struct interface *ifp),
 DEFINE_HOOK(zebra_if_config_wr, (struct vty * vty, struct interface *ifp),
            (vty, ifp));
 
+DEFINE_MTYPE(ZEBRA, ZIF_DESC, "Intf desc");
 
 static void if_down_del_nbr_connected(struct interface *ifp);
 
@@ -233,7 +234,7 @@ static int if_zebra_delete_hook(struct interface *ifp)
                if_nhg_dependents_release(ifp);
                zebra_if_nhg_dependents_free(zebra_if);
 
-               XFREE(MTYPE_TMP, zebra_if->desc);
+               XFREE(MTYPE_ZIF_DESC, zebra_if->desc);
 
                THREAD_OFF(zebra_if->speed_update);
 
index 801078e83d52b640a60d5fc819a5a494bc86314d..0242438dc2284a5845ced1c892fc49f69764954a 100644 (file)
@@ -109,6 +109,9 @@ enum zebra_if_flags {
 #define ZEBRA_IF_IS_PROTODOWN_ONLY_EXTERNAL(zif)                               \
        ((zif)->protodown_rc == ZEBRA_PROTODOWN_EXTERNAL)
 
+/* Mem type for zif desc */
+DECLARE_MTYPE(ZIF_DESC);
+
 /* `zebra' daemon local interface structure. */
 struct zebra_if {
        /* back pointer to the interface */
index 28db2ad87d6526619e67d79d4245fe5d8c04f9f4..36852b65b6c27f8f21c8fad231adb151cb045a33 100644 (file)
@@ -200,12 +200,12 @@ static void if_set_defaults(struct irdp_interface *irdp)
 
 static struct Adv *Adv_new(void)
 {
-       return XCALLOC(MTYPE_TMP, sizeof(struct Adv));
+       return XCALLOC(MTYPE_IRDP_IF, sizeof(struct Adv));
 }
 
 static void Adv_free(struct Adv *adv)
 {
-       XFREE(MTYPE_TMP, adv);
+       XFREE(MTYPE_IRDP_IF, adv);
 }
 
 static void irdp_if_start(struct interface *ifp, int multicast,
index d594512b3653fb29119c759cf3c590ab74922df6..a2233a6667a0e8c6fe58482904fe929263956805 100644 (file)
@@ -3698,7 +3698,7 @@ static inline void zebra_neigh_ip_del(ZAPI_HANDLER_ARGS)
 static inline void zread_iptable(ZAPI_HANDLER_ARGS)
 {
        struct zebra_pbr_iptable *zpi =
-               XCALLOC(MTYPE_TMP, sizeof(struct zebra_pbr_iptable));
+               XCALLOC(MTYPE_PBR_OBJ, sizeof(struct zebra_pbr_iptable));
        struct stream *s;
 
        s = msg;
index 56d0df569c7988ff4a9f69a3e498d7e70f9860c4..d3c104cc8054549027b90a79d7a359e3cc997db5 100644 (file)
@@ -46,6 +46,7 @@
 #include "zebra/debug.h"
 #include "zebra/zapi_msg.h"
 
+DEFINE_MTYPE_STATIC(ZEBRA, ZEBRA_GR, "GR");
 
 /*
  * Forward declaration.
@@ -111,7 +112,7 @@ static struct client_gr_info *zebra_gr_client_info_create(struct zserv *client)
 {
        struct client_gr_info *info;
 
-       info = XCALLOC(MTYPE_TMP, sizeof(struct client_gr_info));
+       info = XCALLOC(MTYPE_ZEBRA_GR, sizeof(struct client_gr_info));
 
        TAILQ_INSERT_TAIL(&(client->gr_info_queue), info, gr_info);
        return info;
@@ -127,7 +128,7 @@ static void zebra_gr_client_info_delte(struct zserv *client,
 
        THREAD_OFF(info->t_stale_removal);
 
-       XFREE(MTYPE_TMP, info->current_prefix);
+       XFREE(MTYPE_ZEBRA_GR, info->current_prefix);
 
        LOG_GR("%s: Instance info is being deleted for client %s", __func__,
               zebra_route_string(client->proto));
@@ -136,7 +137,7 @@ static void zebra_gr_client_info_delte(struct zserv *client,
        info->do_delete = true;
        zebra_gr_delete_stale_routes(info);
 
-       XFREE(MTYPE_TMP, info);
+       XFREE(MTYPE_ZEBRA_GR, info);
 }
 
 /*
@@ -222,8 +223,8 @@ static void zebra_gr_delete_stale_client(struct client_gr_info *info)
        TAILQ_INIT(&(s_client->gr_info_queue));
        listnode_delete(zrouter.stale_client_list, s_client);
        if (info->stale_client)
-               XFREE(MTYPE_TMP, s_client);
-       XFREE(MTYPE_TMP, info);
+               zserv_client_delete(s_client);
+       XFREE(MTYPE_ZEBRA_GR, info);
 }
 
 /*
@@ -288,7 +289,7 @@ void zebra_gr_client_reconnect(struct zserv *client)
        /* Delete the stale client */
        listnode_delete(zrouter.stale_client_list, old_client);
        /* Delete old client */
-       XFREE(MTYPE_TMP, old_client);
+       zserv_client_delete(old_client);
 }
 
 /*
@@ -474,7 +475,7 @@ static void zebra_gr_route_stale_delete_timer_expiry(struct thread *thread)
                LOG_GR("%s: Client %s all stale routes processed", __func__,
                       zebra_route_string(client->proto));
 
-               XFREE(MTYPE_TMP, info->current_prefix);
+               XFREE(MTYPE_ZEBRA_GR, info->current_prefix);
                info->current_afi = 0;
                zebra_gr_delete_stale_client(info);
        }
@@ -579,7 +580,7 @@ static int32_t zebra_gr_delete_stale_route(struct client_gr_info *info,
                                            && (info->do_delete == false)) {
                                                info->current_afi = afi;
                                                info->current_prefix = XCALLOC(
-                                                       MTYPE_TMP,
+                                                       MTYPE_ZEBRA_GR,
                                                        sizeof(struct prefix));
                                                prefix_copy(
                                                        info->current_prefix,
@@ -593,7 +594,7 @@ static int32_t zebra_gr_delete_stale_route(struct client_gr_info *info,
                 * Reset the current prefix to indicate processing completion
                 * of the current AFI
                 */
-               XFREE(MTYPE_TMP, info->current_prefix);
+               XFREE(MTYPE_ZEBRA_GR, info->current_prefix);
        }
        return 0;
 }
index 43e21a6d34073068ce35ece9f3e8a4484b783bd6..405241fc22808b4ea40022a9aea1426e606aba39 100644 (file)
@@ -36,6 +36,7 @@
 
 /* definitions */
 DEFINE_MTYPE_STATIC(ZEBRA, PBR_IPTABLE_IFNAME, "PBR interface list");
+DEFINE_MTYPE(ZEBRA, PBR_OBJ, "PBR");
 
 /* definitions */
 static const struct message ipset_type_msg[] = {
@@ -163,7 +164,7 @@ void zebra_pbr_rules_free(void *arg)
        rule = (struct zebra_pbr_rule *)arg;
 
        (void)dplane_pbr_rule_delete(rule);
-       XFREE(MTYPE_TMP, rule);
+       XFREE(MTYPE_PBR_OBJ, rule);
 }
 
 uint32_t zebra_pbr_rules_hash_key(const void *arg)
@@ -275,7 +276,7 @@ void zebra_pbr_ipset_free(void *arg)
 
        ipset = (struct zebra_pbr_ipset *)arg;
        hook_call(zebra_pbr_ipset_update, 0, ipset);
-       XFREE(MTYPE_TMP, ipset);
+       XFREE(MTYPE_PBR_OBJ, ipset);
 }
 
 uint32_t zebra_pbr_ipset_hash_key(const void *arg)
@@ -319,7 +320,7 @@ void zebra_pbr_ipset_entry_free(void *arg)
 
        hook_call(zebra_pbr_ipset_entry_update, 0, ipset);
 
-       XFREE(MTYPE_TMP, ipset);
+       XFREE(MTYPE_PBR_OBJ, ipset);
 }
 
 uint32_t zebra_pbr_ipset_entry_hash_key(const void *arg)
@@ -396,7 +397,7 @@ static void _zebra_pbr_iptable_free_all(void *arg, bool all)
                }
                list_delete(&iptable->interface_name_list);
        }
-       XFREE(MTYPE_TMP, iptable);
+       XFREE(MTYPE_PBR_OBJ, iptable);
 }
 
 void zebra_pbr_iptable_free(void *arg)
@@ -478,7 +479,7 @@ static void *pbr_rule_alloc_intern(void *arg)
 
        zpr = (struct zebra_pbr_rule *)arg;
 
-       new = XCALLOC(MTYPE_TMP, sizeof(*new));
+       new = XCALLOC(MTYPE_PBR_OBJ, sizeof(*new));
 
        memcpy(new, zpr, sizeof(*zpr));
 
@@ -492,7 +493,7 @@ static struct zebra_pbr_rule *pbr_rule_free(struct zebra_pbr_rule *hash_data,
                zebra_neigh_deref(hash_data);
        hash_release(zrouter.rules_hash, hash_data);
        if (free_data) {
-               XFREE(MTYPE_TMP, hash_data);
+               XFREE(MTYPE_PBR_OBJ, hash_data);
                return NULL;
        }
 
@@ -688,7 +689,7 @@ void zebra_pbr_add_rule(struct zebra_pbr_rule *rule)
                (void)dplane_pbr_rule_update(found, new);
                /* release the old hash data */
                if (old)
-                       XFREE(MTYPE_TMP, old);
+                       XFREE(MTYPE_PBR_OBJ, old);
        } else {
                if (IS_ZEBRA_DEBUG_PBR)
                        zlog_debug(
@@ -856,7 +857,7 @@ static void *pbr_ipset_alloc_intern(void *arg)
 
        zpi = (struct zebra_pbr_ipset *)arg;
 
-       new = XCALLOC(MTYPE_TMP, sizeof(struct zebra_pbr_ipset));
+       new = XCALLOC(MTYPE_PBR_OBJ, sizeof(struct zebra_pbr_ipset));
 
        memcpy(new, zpi, sizeof(*zpi));
 
@@ -877,7 +878,7 @@ void zebra_pbr_destroy_ipset(struct zebra_pbr_ipset *ipset)
        (void)dplane_pbr_ipset_delete(ipset);
        if (lookup) {
                hash_release(zrouter.ipset_hash, lookup);
-               XFREE(MTYPE_TMP, lookup);
+               XFREE(MTYPE_PBR_OBJ, lookup);
        } else
                zlog_debug(
                        "%s: IPSet Entry being deleted we know nothing about",
@@ -930,7 +931,7 @@ static void *pbr_ipset_entry_alloc_intern(void *arg)
 
        zpi = (struct zebra_pbr_ipset_entry *)arg;
 
-       new = XCALLOC(MTYPE_TMP, sizeof(struct zebra_pbr_ipset_entry));
+       new = XCALLOC(MTYPE_PBR_OBJ, sizeof(struct zebra_pbr_ipset_entry));
 
        memcpy(new, zpi, sizeof(*zpi));
 
@@ -952,7 +953,7 @@ void zebra_pbr_del_ipset_entry(struct zebra_pbr_ipset_entry *ipset)
        (void)dplane_pbr_ipset_entry_delete(ipset);
        if (lookup) {
                hash_release(zrouter.ipset_entry_hash, lookup);
-               XFREE(MTYPE_TMP, lookup);
+               XFREE(MTYPE_PBR_OBJ, lookup);
        } else
                zlog_debug("%s: IPSet being deleted we know nothing about",
                           __func__);
@@ -967,7 +968,7 @@ static void *pbr_iptable_alloc_intern(void *arg)
 
        zpi = (struct zebra_pbr_iptable *)arg;
 
-       new = XCALLOC(MTYPE_TMP, sizeof(struct zebra_pbr_iptable));
+       new = XCALLOC(MTYPE_PBR_OBJ, sizeof(struct zebra_pbr_iptable));
 
        /* Deep structure copy */
        memcpy(new, zpi, sizeof(*zpi));
@@ -1009,7 +1010,7 @@ void zebra_pbr_del_iptable(struct zebra_pbr_iptable *iptable)
                                         node);
                }
                list_delete(&iptable->interface_name_list);
-               XFREE(MTYPE_TMP, lookup);
+               XFREE(MTYPE_PBR_OBJ, lookup);
        } else
                zlog_debug("%s: IPTable being deleted we know nothing about",
                           __func__);
index baa8755fa5320e65934916ab41ff5d1c43c0e712..60457914cc2439d4e160941db0d6e506da403c29 100644 (file)
@@ -36,6 +36,9 @@
 extern "C" {
 #endif
 
+/* Memory type for PBR objects. */
+DECLARE_MTYPE(PBR_OBJ);
+
 struct zebra_pbr_action {
        afi_t afi;
 
index ebe246ffbcc127542d08c23bb89ca34353a6ebd3..d788811d3dd0274d8bda08eeca06a4ae329837b4 100644 (file)
@@ -78,6 +78,8 @@ static struct zserv *find_client_internal(uint8_t proto,
                                          unsigned short instance,
                                          uint32_t session_id);
 
+/* Mem type for zclients. */
+DEFINE_MTYPE_STATIC(ZEBRA, ZSERV_CLIENT, "ZClients");
 
 /*
  * Client thread events.
@@ -145,6 +147,14 @@ static void zserv_event(struct zserv *client, enum zserv_event event);
 
 /* Client thread lifecycle -------------------------------------------------- */
 
+/*
+ * Free a zserv client object.
+ */
+void zserv_client_delete(struct zserv *client)
+{
+       XFREE(MTYPE_ZSERV_CLIENT, client);
+}
+
 /*
  * Log zapi message to zlog.
  *
@@ -644,7 +654,7 @@ static void zserv_client_free(struct zserv *client)
                if (IS_ZEBRA_DEBUG_EVENT)
                        zlog_debug("%s: Deleting client %s", __func__,
                                   zebra_route_string(client->proto));
-               XFREE(MTYPE_TMP, client);
+               zserv_client_delete(client);
        } else {
                /* Handle cases where client has GR instance. */
                if (IS_ZEBRA_DEBUG_EVENT)
@@ -733,7 +743,7 @@ static struct zserv *zserv_client_create(int sock)
        int i;
        afi_t afi;
 
-       client = XCALLOC(MTYPE_TMP, sizeof(struct zserv));
+       client = XCALLOC(MTYPE_ZSERV_CLIENT, sizeof(struct zserv));
 
        /* Make client input/output buffer. */
        client->sock = sock;
index db7b70d7c45fe4d96d9c503ac48dc391f50c0db8..de784e382a09d94cef208bcd9839ccd0a39d8305 100644 (file)
@@ -363,6 +363,13 @@ extern void zserv_release_client(struct zserv *client);
  */
 extern void zserv_close_client(struct zserv *client);
 
+/*
+ * Free memory for a zserv client object - note that this does not
+ * clean up the internal allocations associated with the zserv client,
+ * this just free the struct's memory.
+ */
+void zserv_client_delete(struct zserv *client);
+
 /*
  * Log a ZAPI message hexdump.
  *