diff options
author | David Lamparter <equinox@opensourcerouting.org> | 2021-11-06 16:35:33 +0100 |
---|---|---|
committer | David Lamparter <equinox@opensourcerouting.org> | 2021-11-16 13:34:46 +0100 |
commit | 067967b8c74820790fbc50f1fadd0b9ed35fa9c1 (patch) | |
tree | 9ddafdda2dd5a11fb3dee9ef38af3b0cfb7bf37a /ospf6d/ospf6_lsa.c | |
parent | Merge pull request #10071 from donaldsharp/valgrind_supp_change (diff) | |
download | frr-067967b8c74820790fbc50f1fadd0b9ed35fa9c1.tar.xz frr-067967b8c74820790fbc50f1fadd0b9ed35fa9c1.zip |
ospfd6d: replace handler vector with array
No point in using the vector code for this really.
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Diffstat (limited to 'ospf6d/ospf6_lsa.c')
-rw-r--r-- | ospf6d/ospf6_lsa.c | 62 |
1 files changed, 34 insertions, 28 deletions
diff --git a/ospf6d/ospf6_lsa.c b/ospf6d/ospf6_lsa.c index 77f0f8f4e..99d0de39c 100644 --- a/ospf6d/ospf6_lsa.c +++ b/ospf6d/ospf6_lsa.c @@ -54,7 +54,7 @@ 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; +static struct ospf6_lsa_handler *lsa_handlers[OSPF6_LSTYPE_SIZE]; struct ospf6 *ospf6_get_by_lsdb(struct ospf6_lsa *lsa) { @@ -115,8 +115,13 @@ static struct ospf6_lsa_handler unknown_handler = { void ospf6_install_lsa_handler(struct ospf6_lsa_handler *handler) { /* type in handler is host byte order */ - int index = handler->lh_type & OSPF6_LSTYPE_FCODE_MASK; - vector_set_index(ospf6_lsa_handler_vector, index, (void *)handler); + unsigned int index = handler->lh_type & OSPF6_LSTYPE_FCODE_MASK; + + assertf(index < array_size(lsa_handlers), "index=%x", index); + assertf(lsa_handlers[index] == NULL, "old=%s, new=%s", + lsa_handlers[index]->lh_name, handler->lh_name); + + lsa_handlers[index] = handler; } struct ospf6_lsa_handler *ospf6_get_lsa_handler(uint16_t type) @@ -124,10 +129,8 @@ struct ospf6_lsa_handler *ospf6_get_lsa_handler(uint16_t type) struct ospf6_lsa_handler *handler = NULL; unsigned int index = ntohs(type) & OSPF6_LSTYPE_FCODE_MASK; - if (index >= vector_active(ospf6_lsa_handler_vector)) - handler = &unknown_handler; - else - handler = vector_slot(ospf6_lsa_handler_vector, index); + if (index < array_size(lsa_handlers)) + handler = lsa_handlers[index]; if (handler == NULL) handler = &unknown_handler; @@ -989,13 +992,11 @@ int ospf6_lsa_checksum_valid(struct ospf6_lsa_header *lsa_header) void ospf6_lsa_init(void) { - ospf6_lsa_handler_vector = vector_init(0); ospf6_install_lsa_handler(&unknown_handler); } void ospf6_lsa_terminate(void) { - vector_free(ospf6_lsa_handler_vector); } static char *ospf6_lsa_handler_name(const struct ospf6_lsa_handler *h) @@ -1020,27 +1021,32 @@ static char *ospf6_lsa_handler_name(const struct ospf6_lsa_handler *h) return buf; } -DEFPY (debug_ospf6_lsa_all, - debug_ospf6_lsa_all_cmd, - "[no$no] debug ospf6 lsa all", - NO_STR - DEBUG_STR - OSPF6_STR - "Debug Link State Advertisements (LSAs)\n" - "Display for all types of LSAs\n") +void ospf6_lsa_debug_set_all(bool val) { unsigned int i; struct ospf6_lsa_handler *handler = NULL; - for (i = 0; i < vector_active(ospf6_lsa_handler_vector); i++) { - handler = vector_slot(ospf6_lsa_handler_vector, i); + for (i = 0; i < array_size(lsa_handlers); i++) { + handler = lsa_handlers[i]; if (handler == NULL) continue; - if (!no) + if (val) SET_FLAG(handler->lh_debug, OSPF6_LSA_DEBUG_ALL); else UNSET_FLAG(handler->lh_debug, OSPF6_LSA_DEBUG_ALL); } +} + +DEFPY (debug_ospf6_lsa_all, + debug_ospf6_lsa_all_cmd, + "[no$no] debug ospf6 lsa all", + NO_STR + DEBUG_STR + OSPF6_STR + "Debug Link State Advertisements (LSAs)\n" + "Display for all types of LSAs\n") +{ + ospf6_lsa_debug_set_all(!no); return CMD_SUCCESS; } @@ -1092,8 +1098,8 @@ DEFUN (debug_ospf6_lsa_type, unsigned int i; struct ospf6_lsa_handler *handler = NULL; - for (i = 0; i < vector_active(ospf6_lsa_handler_vector); i++) { - handler = vector_slot(ospf6_lsa_handler_vector, i); + for (i = 0; i < array_size(lsa_handlers); i++) { + handler = lsa_handlers[i]; if (handler == NULL) continue; if (strncmp(argv[idx_lsa]->arg, ospf6_lsa_handler_name(handler), @@ -1146,8 +1152,8 @@ DEFUN (no_debug_ospf6_lsa_type, unsigned int i; struct ospf6_lsa_handler *handler = NULL; - for (i = 0; i < vector_active(ospf6_lsa_handler_vector); i++) { - handler = vector_slot(ospf6_lsa_handler_vector, i); + for (i = 0; i < array_size(lsa_handlers); i++) { + handler = lsa_handlers[i]; if (handler == NULL) continue; if (strncmp(argv[idx_lsa]->arg, ospf6_lsa_handler_name(handler), @@ -1194,8 +1200,8 @@ int config_write_ospf6_debug_lsa(struct vty *vty) const struct ospf6_lsa_handler *handler; bool debug_all = true; - for (i = 0; i < vector_active(ospf6_lsa_handler_vector); i++) { - handler = vector_slot(ospf6_lsa_handler_vector, i); + for (i = 0; i < array_size(lsa_handlers); i++) { + handler = lsa_handlers[i]; if (handler == NULL) continue; if (CHECK_FLAG(handler->lh_debug, OSPF6_LSA_DEBUG_ALL) @@ -1210,8 +1216,8 @@ int config_write_ospf6_debug_lsa(struct vty *vty) return 0; } - for (i = 0; i < vector_active(ospf6_lsa_handler_vector); i++) { - handler = vector_slot(ospf6_lsa_handler_vector, i); + for (i = 0; i < array_size(lsa_handlers); i++) { + handler = lsa_handlers[i]; if (handler == NULL) continue; if (CHECK_FLAG(handler->lh_debug, OSPF6_LSA_DEBUG)) |