diff options
Diffstat (limited to 'ospf6d/ospf6_lsa.c')
| -rw-r--r-- | ospf6d/ospf6_lsa.c | 60 |
1 files changed, 33 insertions, 27 deletions
diff --git a/ospf6d/ospf6_lsa.c b/ospf6d/ospf6_lsa.c index f1b04c9bec..f2a933d878 100644 --- a/ospf6d/ospf6_lsa.c +++ b/ospf6d/ospf6_lsa.c @@ -43,6 +43,10 @@ #include "ospf6_flood.h" #include "ospf6d.h" +DEFINE_MTYPE_STATIC(OSPF6D, OSPF6_LSA, "OSPF6 LSA"); +DEFINE_MTYPE_STATIC(OSPF6D, OSPF6_LSA_HEADER, "OSPF6 LSA header"); +DEFINE_MTYPE_STATIC(OSPF6D, OSPF6_LSA_SUMMARY, "OSPF6 LSA summary"); + vector ospf6_lsa_handler_vector; struct ospf6 *ospf6_get_by_lsdb(struct ospf6_lsa *lsa) @@ -145,7 +149,7 @@ const char *ospf6_lstype_short_name(uint16_t type) const struct ospf6_lsa_handler *handler; handler = ospf6_get_lsa_handler(type); - if (handler && handler != &unknown_handler) + if (handler) return handler->lh_short_name; snprintf(buf, sizeof(buf), "0x%04hx", ntohs(type)); @@ -420,9 +424,10 @@ void ospf6_lsa_show_summary(struct vty *vty, struct ospf6_lsa *lsa, if (use_json) json_obj = json_object_new_object(); - if ((type == OSPF6_LSTYPE_INTER_PREFIX) - || (type == OSPF6_LSTYPE_INTER_ROUTER) - || (type == OSPF6_LSTYPE_AS_EXTERNAL)) { + switch (type) { + case OSPF6_LSTYPE_INTER_PREFIX: + case OSPF6_LSTYPE_INTER_ROUTER: + case OSPF6_LSTYPE_AS_EXTERNAL: if (use_json) { json_object_string_add( json_obj, "type", @@ -447,7 +452,13 @@ void ospf6_lsa_show_summary(struct vty *vty, struct ospf6_lsa *lsa, (unsigned long)ntohl(lsa->header->seqnum), handler->lh_get_prefix_str(lsa, buf, sizeof(buf), 0)); - } else if (type != OSPF6_LSTYPE_UNKNOWN) { + break; + case OSPF6_LSTYPE_ROUTER: + case OSPF6_LSTYPE_NETWORK: + case OSPF6_LSTYPE_GROUP_MEMBERSHIP: + case OSPF6_LSTYPE_TYPE_7: + case OSPF6_LSTYPE_LINK: + case OSPF6_LSTYPE_INTRA_PREFIX: while (handler->lh_get_prefix_str(lsa, buf, sizeof(buf), cnt) != NULL) { if (use_json) { @@ -481,7 +492,8 @@ void ospf6_lsa_show_summary(struct vty *vty, struct ospf6_lsa *lsa, } if (use_json) json_object_free(json_obj); - } else { + break; + default: if (use_json) { json_object_string_add( json_obj, "type", @@ -500,6 +512,7 @@ void ospf6_lsa_show_summary(struct vty *vty, struct ospf6_lsa *lsa, ospf6_lstype_short_name(lsa->header->type), id, adv_router, ospf6_lsa_age_current(lsa), (unsigned long)ntohl(lsa->header->seqnum)); + break; } } @@ -648,27 +661,29 @@ 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) +{ + struct ospf6_lsa *lsa; + + 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)); @@ -682,20 +697,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 */ |
