]> git.puffer.fish Git - matthieu/frr.git/commitdiff
ospf6d: split off ospf6_lsa_alloc()
authorDavid Lamparter <equinox@diac24.net>
Mon, 22 Mar 2021 18:24:59 +0000 (19:24 +0100)
committerDavid Lamparter <equinox@diac24.net>
Mon, 22 Mar 2021 18:26:02 +0000 (19:26 +0100)
... so we can make the MTYPEs static to ospf6_lsa.c

Signed-off-by: David Lamparter <equinox@diac24.net>
ospf6d/ospf6_lsa.c
ospf6d/ospf6_lsa.h
ospf6d/ospf6_spf.c

index e1c3b4038c0d543b78f9ef4d5004112d08cc0578..2de95ec2c4b7ccd61ad5407c02bd40f7c3106ff2 100644 (file)
@@ -657,27 +657,27 @@ void ospf6_lsa_show(struct vty *vty, struct ospf6_lsa *lsa,
                vty_out(vty, "\n");
 }
 
+struct ospf6_lsa *ospf6_lsa_alloc(size_t lsa_length)
+{
+       lsa = XCALLOC(MTYPE_OSPF6_LSA, sizeof(struct ospf6_lsa));
+       lsa->header = XMALLOC(MTYPE_OSPF6_LSA_HEADER, lsa_length);
+
+       return lsa;
+}
+
 /* OSPFv3 LSA creation/deletion function */
 struct ospf6_lsa *ospf6_lsa_create(struct ospf6_lsa_header *header)
 {
        struct ospf6_lsa *lsa = NULL;
-       struct ospf6_lsa_header *new_header = NULL;
        uint16_t lsa_size = 0;
 
        /* size of the entire LSA */
        lsa_size = ntohs(header->length); /* XXX vulnerable */
 
-       /* allocate memory for this LSA */
-       new_header = XMALLOC(MTYPE_OSPF6_LSA_HEADER, lsa_size);
+       lsa = ospf6_lsa_alloc(lsa_size);
 
        /* copy LSA from original header */
-       memcpy(new_header, header, lsa_size);
-
-       /* LSA information structure */
-       /* allocate memory */
-       lsa = XCALLOC(MTYPE_OSPF6_LSA, sizeof(struct ospf6_lsa));
-
-       lsa->header = new_header;
+       memcpy(lsa->header, header, lsa_size);
 
        /* dump string */
        ospf6_lsa_printbuf(lsa, lsa->name, sizeof(lsa->name));
@@ -691,20 +691,11 @@ struct ospf6_lsa *ospf6_lsa_create(struct ospf6_lsa_header *header)
 struct ospf6_lsa *ospf6_lsa_create_headeronly(struct ospf6_lsa_header *header)
 {
        struct ospf6_lsa *lsa = NULL;
-       struct ospf6_lsa_header *new_header = NULL;
 
-       /* allocate memory for this LSA */
-       new_header = XMALLOC(MTYPE_OSPF6_LSA_HEADER,
-                            sizeof(struct ospf6_lsa_header));
+       lsa = ospf6_lsa_alloc(sizeof(struct ospf6_lsa_header));
 
-       /* copy LSA from original header */
-       memcpy(new_header, header, sizeof(struct ospf6_lsa_header));
-
-       /* LSA information structure */
-       /* allocate memory */
-       lsa = XCALLOC(MTYPE_OSPF6_LSA, sizeof(struct ospf6_lsa));
+       memcpy(lsa->header, header, sizeof(struct ospf6_lsa_header));
 
-       lsa->header = new_header;
        SET_FLAG(lsa->flag, OSPF6_LSA_HEADERONLY);
 
        /* dump string */
index 7fa9c5fe40153370c50821c7c1707d6ca68e492c..c4d0290c0c1639b2c11acf149e926d7cc5ad5f3c 100644 (file)
@@ -217,6 +217,7 @@ extern void ospf6_lsa_show_internal(struct vty *vty, struct ospf6_lsa *lsa,
 extern void ospf6_lsa_show(struct vty *vty, struct ospf6_lsa *lsa,
                           json_object *json, bool use_json);
 
+extern struct ospf6_lsa *ospf6_lsa_alloc(size_t lsa_length);
 extern struct ospf6_lsa *ospf6_lsa_create(struct ospf6_lsa_header *header);
 extern struct ospf6_lsa *
 ospf6_lsa_create_headeronly(struct ospf6_lsa_header *header);
index d1931055a262e647047ee071ab29fa2c46edac09..d71f7629c696642a44b92f6fd6c8bf12fb804c9f 100644 (file)
@@ -1021,13 +1021,8 @@ struct ospf6_lsa *ospf6_create_single_router_lsa(struct ospf6_area *area,
                return NULL;
        }
 
-       /* Allocate memory for this LSA */
-       new_header = XMALLOC(MTYPE_OSPF6_LSA_HEADER, total_lsa_length);
-
-       /* LSA information structure */
-       lsa = XCALLOC(MTYPE_OSPF6_LSA, sizeof(struct ospf6_lsa));
-
-       lsa->header = (struct ospf6_lsa_header *)new_header;
+       lsa = ospf6_lsa_alloc(total_lsa_length);
+       new_header = (uint8_t *)lsa->header;
 
        lsa->lsdb = area->temp_router_lsa_lsdb;