ospf6d: split off ospf6_lsa_alloc()

... so we can make the MTYPEs static to ospf6_lsa.c

Signed-off-by: David Lamparter <equinox@diac24.net>
This commit is contained in:
David Lamparter 2021-03-22 19:24:59 +01:00
parent c7479286ae
commit 771e1fbee0
3 changed files with 15 additions and 28 deletions

View File

@ -657,27 +657,27 @@ void ospf6_lsa_show(struct vty *vty, struct ospf6_lsa *lsa,
vty_out(vty, "\n"); 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 */ /* OSPFv3 LSA creation/deletion function */
struct ospf6_lsa *ospf6_lsa_create(struct ospf6_lsa_header *header) struct ospf6_lsa *ospf6_lsa_create(struct ospf6_lsa_header *header)
{ {
struct ospf6_lsa *lsa = NULL; struct ospf6_lsa *lsa = NULL;
struct ospf6_lsa_header *new_header = NULL;
uint16_t lsa_size = 0; uint16_t lsa_size = 0;
/* size of the entire LSA */ /* size of the entire LSA */
lsa_size = ntohs(header->length); /* XXX vulnerable */ lsa_size = ntohs(header->length); /* XXX vulnerable */
/* allocate memory for this LSA */ lsa = ospf6_lsa_alloc(lsa_size);
new_header = XMALLOC(MTYPE_OSPF6_LSA_HEADER, lsa_size);
/* copy LSA from original header */ /* copy LSA from original header */
memcpy(new_header, header, lsa_size); memcpy(lsa->header, header, lsa_size);
/* LSA information structure */
/* allocate memory */
lsa = XCALLOC(MTYPE_OSPF6_LSA, sizeof(struct ospf6_lsa));
lsa->header = new_header;
/* dump string */ /* dump string */
ospf6_lsa_printbuf(lsa, lsa->name, sizeof(lsa->name)); 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 *ospf6_lsa_create_headeronly(struct ospf6_lsa_header *header)
{ {
struct ospf6_lsa *lsa = NULL; struct ospf6_lsa *lsa = NULL;
struct ospf6_lsa_header *new_header = NULL;
/* allocate memory for this LSA */ lsa = ospf6_lsa_alloc(sizeof(struct ospf6_lsa_header));
new_header = XMALLOC(MTYPE_OSPF6_LSA_HEADER,
sizeof(struct ospf6_lsa_header));
/* copy LSA from original header */ memcpy(lsa->header, header, sizeof(struct ospf6_lsa_header));
memcpy(new_header, header, sizeof(struct ospf6_lsa_header));
/* LSA information structure */
/* allocate memory */
lsa = XCALLOC(MTYPE_OSPF6_LSA, sizeof(struct ospf6_lsa));
lsa->header = new_header;
SET_FLAG(lsa->flag, OSPF6_LSA_HEADERONLY); SET_FLAG(lsa->flag, OSPF6_LSA_HEADERONLY);
/* dump string */ /* dump string */

View 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, extern void ospf6_lsa_show(struct vty *vty, struct ospf6_lsa *lsa,
json_object *json, bool use_json); 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(struct ospf6_lsa_header *header);
extern struct ospf6_lsa * extern struct ospf6_lsa *
ospf6_lsa_create_headeronly(struct ospf6_lsa_header *header); ospf6_lsa_create_headeronly(struct ospf6_lsa_header *header);

View File

@ -1021,13 +1021,8 @@ struct ospf6_lsa *ospf6_create_single_router_lsa(struct ospf6_area *area,
return NULL; return NULL;
} }
/* Allocate memory for this LSA */ lsa = ospf6_lsa_alloc(total_lsa_length);
new_header = XMALLOC(MTYPE_OSPF6_LSA_HEADER, total_lsa_length); new_header = (uint8_t *)lsa->header;
/* LSA information structure */
lsa = XCALLOC(MTYPE_OSPF6_LSA, sizeof(struct ospf6_lsa));
lsa->header = (struct ospf6_lsa_header *)new_header;
lsa->lsdb = area->temp_router_lsa_lsdb; lsa->lsdb = area->temp_router_lsa_lsdb;