ospfd6d: replace handler vector with array

No point in using the vector code for this really.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
This commit is contained in:
David Lamparter 2021-11-06 16:35:33 +01:00
parent 7022e70d74
commit 067967b8c7
3 changed files with 37 additions and 39 deletions

View File

@ -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,6 +1021,22 @@ static char *ospf6_lsa_handler_name(const struct ospf6_lsa_handler *h)
return buf;
}
void ospf6_lsa_debug_set_all(bool val)
{
unsigned int i;
struct ospf6_lsa_handler *handler = NULL;
for (i = 0; i < array_size(lsa_handlers); i++) {
handler = lsa_handlers[i];
if (handler == NULL)
continue;
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",
@ -1029,18 +1046,7 @@ DEFPY (debug_ospf6_lsa_all,
"Debug Link State Advertisements (LSAs)\n"
"Display for all types of LSAs\n")
{
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);
if (handler == NULL)
continue;
if (!no)
SET_FLAG(handler->lh_debug, OSPF6_LSA_DEBUG_ALL);
else
UNSET_FLAG(handler->lh_debug, OSPF6_LSA_DEBUG_ALL);
}
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))

View File

@ -173,8 +173,6 @@ struct ospf6_lsa_handler {
#define OSPF6_LSA_IS_KNOWN(t) \
(ospf6_get_lsa_handler(t)->lh_type != OSPF6_LSTYPE_UNKNOWN ? 1 : 0)
extern vector ospf6_lsa_handler_vector;
/* Macro for LSA Origination */
/* addr is (struct prefix *) */
#define CONTINUE_IF_ADDRESS_LINKLOCAL(debug, addr) \
@ -268,6 +266,7 @@ extern int ospf6_lsa_prohibited_duration(uint16_t type, uint32_t id,
extern void ospf6_install_lsa_handler(struct ospf6_lsa_handler *handler);
extern struct ospf6_lsa_handler *ospf6_get_lsa_handler(uint16_t type);
extern void ospf6_lsa_debug_set_all(bool val);
extern void ospf6_lsa_init(void);
extern void ospf6_lsa_terminate(void);

View File

@ -1254,7 +1254,6 @@ DEFUN (no_debug_ospf6,
OSPF6_STR)
{
unsigned int i;
struct ospf6_lsa_handler *handler = NULL;
OSPF6_DEBUG_ABR_OFF();
OSPF6_DEBUG_ASBR_OFF();
@ -1264,13 +1263,7 @@ DEFUN (no_debug_ospf6,
OSPF6_DEBUG_FLOODING_OFF();
OSPF6_DEBUG_INTERFACE_OFF();
for (i = 0; i < vector_active(ospf6_lsa_handler_vector); i++) {
handler = vector_slot(ospf6_lsa_handler_vector, i);
if (handler != NULL) {
UNSET_FLAG(handler->lh_debug, OSPF6_LSA_DEBUG);
}
}
ospf6_lsa_debug_set_all(false);
for (i = 0; i < 6; i++)
OSPF6_DEBUG_MESSAGE_OFF(i,