From 30e49ecb8c1711e7dfbbcda29e4bd150ebd8cf13 Mon Sep 17 00:00:00 2001 From: Christian Giese Date: Thu, 12 Oct 2023 13:49:55 +0000 Subject: [PATCH] add support for LSA type 12 - 42 --- code/bngblaster/src/ospf/ospf_ctrl.c | 4 ++- code/bngblaster/src/ospf/ospf_def.h | 33 +++++++++++++++++++++- code/bngblaster/src/ospf/ospf_lsa.c | 36 ++++++++++++++++++------ code/bngblaster/src/ospf/ospf_mrt.c | 12 ++++---- code/bngblaster/src/ospf/ospf_mrt.h | 2 +- code/bngblaster/src/ospf/ospf_neighbor.c | 5 +++- 6 files changed, 74 insertions(+), 18 deletions(-) diff --git a/code/bngblaster/src/ospf/ospf_ctrl.c b/code/bngblaster/src/ospf/ospf_ctrl.c index cdc4a62c..0015cdf7 100644 --- a/code/bngblaster/src/ospf/ospf_ctrl.c +++ b/code/bngblaster/src/ospf/ospf_ctrl.c @@ -99,7 +99,9 @@ ospf_ctrl_database(int fd, uint32_t session_id __attribute__((unused)), json_t * database = json_array(); for(type=OSPF_LSA_TYPE_1; type < OSPF_LSA_TYPE_MAX; type++) { - ospf_ctrl_append_database_entries(ospf_instance->lsdb[type], database, &now); + if(hb_tree_count(ospf_instance->lsdb[type])) { + ospf_ctrl_append_database_entries(ospf_instance->lsdb[type], database, &now); + } } root = json_pack("{ss si so}", "status", "ok", diff --git a/code/bngblaster/src/ospf/ospf_def.h b/code/bngblaster/src/ospf/ospf_def.h index d041a0cf..e0bfc0a7 100644 --- a/code/bngblaster/src/ospf/ospf_def.h +++ b/code/bngblaster/src/ospf/ospf_def.h @@ -242,7 +242,38 @@ typedef enum ospf_lsa_type_ { OSPF_LSA_TYPE_9 = 9, OSPF_LSA_TYPE_10 = 10, OSPF_LSA_TYPE_11 = 11, - OSPF_LSA_TYPE_MAX = 12, + OSPF_LSA_TYPE_12 = 12, + OSPF_LSA_TYPE_13 = 13, + OSPF_LSA_TYPE_14 = 14, + OSPF_LSA_TYPE_15 = 15, + OSPF_LSA_TYPE_16 = 16, + OSPF_LSA_TYPE_17 = 17, + OSPF_LSA_TYPE_18 = 18, + OSPF_LSA_TYPE_19 = 19, + OSPF_LSA_TYPE_20 = 20, + OSPF_LSA_TYPE_21 = 21, + OSPF_LSA_TYPE_22 = 22, + OSPF_LSA_TYPE_23 = 23, + OSPF_LSA_TYPE_24 = 24, + OSPF_LSA_TYPE_25 = 25, + OSPF_LSA_TYPE_26 = 26, + OSPF_LSA_TYPE_27 = 27, + OSPF_LSA_TYPE_28 = 28, + OSPF_LSA_TYPE_29 = 29, + OSPF_LSA_TYPE_30 = 30, + OSPF_LSA_TYPE_31 = 31, + OSPF_LSA_TYPE_32 = 32, + OSPF_LSA_TYPE_33 = 33, + OSPF_LSA_TYPE_34 = 34, + OSPF_LSA_TYPE_35 = 35, + OSPF_LSA_TYPE_36 = 36, + OSPF_LSA_TYPE_37 = 37, + OSPF_LSA_TYPE_38 = 38, + OSPF_LSA_TYPE_39 = 39, + OSPF_LSA_TYPE_40 = 40, + OSPF_LSA_TYPE_41 = 41, + OSPF_LSA_TYPE_42 = 42, + OSPF_LSA_TYPE_MAX = 43, } ospf_lsa_type; typedef enum ospf_lsa_scope_ { diff --git a/code/bngblaster/src/ospf/ospf_lsa.c b/code/bngblaster/src/ospf/ospf_lsa.c index 8c696b65..2df6ec39 100644 --- a/code/bngblaster/src/ospf/ospf_lsa.c +++ b/code/bngblaster/src/ospf/ospf_lsa.c @@ -214,6 +214,9 @@ ospf_lsa_gc_job(timer_s *timer) dict_remove_result removed; for(type=OSPF_LSA_TYPE_1; type < OSPF_LSA_TYPE_MAX; type++) { + if(hb_tree_count(ospf_instance->lsdb[type]) == 0) { + continue; + } delete_list_len = 0; itor = hb_itor_new(ospf_instance->lsdb[type]); next = hb_itor_first(itor); @@ -460,7 +463,12 @@ ospf_lsa_purge_all_external(ospf_instance_s *ospf_instance) uint8_t type; for(type=OSPF_LSA_TYPE_1; type < OSPF_LSA_TYPE_MAX; type++) { - if(!ospf_instance->lsdb[type]) continue; + if(!ospf_instance->lsdb[type]) { + continue; + } + if(hb_tree_count(ospf_instance->lsdb[type]) == 0) { + continue; + } itor = hb_itor_new(ospf_instance->lsdb[type]); next = hb_itor_first(itor); while(next) { @@ -728,7 +736,7 @@ ospf_lsa_links_v3(ospf_lsa_s *lsa) link->reserved = 0; link->metric = htobe16(external_connection->metric); link->interface_id = external_connection->interface_id; - link->neighbor_interface_id = external_connection->router_id; + link->neighbor_interface_id = external_connection->neighbor_interface_id; link->neighbor_router_id = external_connection->router_id; lsa->lsa_len += sizeof(ospfv3_lsa_link_s); external_connection = external_connection->next; @@ -1271,6 +1279,9 @@ ospf_lsa_update_tx(ospf_interface_s *ospf_interface, if(ospf_neighbor && retry) { /* Retry. */ tree = ospf_neighbor->lsa_retry_tree[type]; + if(hb_tree_count(tree) == 0){ + continue; + } itor = hb_itor_new(tree); next = hb_itor_first(itor); while(next) { @@ -1303,6 +1314,9 @@ ospf_lsa_update_tx(ospf_interface_s *ospf_interface, } else { tree = ospf_interface->lsa_flood_tree[type]; } + if(hb_tree_count(tree) == 0){ + continue; + } search = hb_tree_search_gt(tree, &g_lsa_key_zero); while(search) { entry = *search; @@ -1370,6 +1384,9 @@ ospf_lsa_req_tx(ospf_interface_s *ospf_interface, ospf_neighbor_s *ospf_neighbor } for(type=OSPF_LSA_TYPE_1; type < OSPF_LSA_TYPE_MAX; type++) { tree = ospf_neighbor->lsa_request_tree[type]; + if(hb_tree_count(tree) == 0){ + continue; + } itor = hb_itor_new(tree); next = hb_itor_first(itor); while(next) { @@ -1457,6 +1474,9 @@ ospf_lsa_ack_tx(ospf_interface_s *ospf_interface, ospf_neighbor_s *ospf_neighbor /* Delayed LS ack */ tree = ospf_interface->lsa_ack_tree[type]; } + if(hb_tree_count(tree) == 0){ + continue; + } search = hb_tree_search_gt(tree, &g_lsa_key_zero); while(search) { entry = *search; @@ -1559,7 +1579,7 @@ ospf_lsa_update_handler_rx(ospf_interface_s *ospf_interface, lsa_id = hdr->id; lsa_router = hdr->router; - if(lsa_type < OSPF_LSA_TYPE_1 || lsa_type > OSPF_LSA_TYPE_11) { + if(lsa_type < OSPF_LSA_TYPE_1 || lsa_type > OSPF_LSA_TYPE_MAX) { ospf_rx_error(interface, pdu, "decode (invalid LSA type)"); return; } @@ -1725,7 +1745,7 @@ ospf_lsa_req_handler_rx(ospf_interface_s *ospf_interface, lsa_type = *OSPF_PDU_CURSOR(pdu); OSPF_PDU_CURSOR_INC(pdu, 1); } - if(lsa_type < OSPF_LSA_TYPE_1 || lsa_type > OSPF_LSA_TYPE_11) { + if(lsa_type < OSPF_LSA_TYPE_1 || lsa_type > OSPF_LSA_TYPE_MAX) { ospf_rx_error(interface, pdu, "decode (invalid LSA type)"); break; } @@ -1806,7 +1826,7 @@ ospf_lsa_ack_handler_rx(ospf_interface_s *ospf_interface, key = (ospf_lsa_key_s*)&hdr_a->id; OSPF_PDU_CURSOR_INC(pdu, OSPF_LSA_HDR_LEN); - if(hdr_a->type < OSPF_LSA_TYPE_1 || hdr_a->type > OSPF_LSA_TYPE_11) { + if(hdr_a->type < OSPF_LSA_TYPE_1 || hdr_a->type > OSPF_LSA_TYPE_MAX) { ospf_rx_error(interface, pdu, "invalid LSA type"); return; } @@ -1848,13 +1868,13 @@ ospf_lsa_load_external(ospf_instance_s *ospf_instance, uint16_t lsa_count, uint8 key = (ospf_lsa_key_s*)&hdr->id; lsa_type = hdr->type; - if(lsa_type < OSPF_LSA_TYPE_1 || lsa_type > OSPF_LSA_TYPE_11) { - LOG_NOARG(ERROR, "Failed to decode external OSPF LSA (invalid LSA type)\n"); + if(lsa_type < OSPF_LSA_TYPE_1 || lsa_type > OSPF_LSA_TYPE_MAX) { + LOG(ERROR, "Failed to decode external OSPF LSA (invalid LSA type %u)\n", lsa_type); return false; } lsa_len = be16toh(hdr->length); if(lsa_len > len) { - LOG_NOARG(ERROR, "Failed to decode external OSPF LSA (invalid LSA len)\n"); + LOG(ERROR, "Failed to decode external OSPF LSA (invalid LSA len %u)\n", lsa_len); return false; } diff --git a/code/bngblaster/src/ospf/ospf_mrt.c b/code/bngblaster/src/ospf/ospf_mrt.c index fe34c477..04b76697 100644 --- a/code/bngblaster/src/ospf/ospf_mrt.c +++ b/code/bngblaster/src/ospf/ospf_mrt.c @@ -46,17 +46,17 @@ ospf_mrt_load(ospf_instance_s *instance, char *file_path) if(mrt.type == OSPFv2_MRT_TYPE && mrt.length >= (OSPFv2_MRT_PDU_OFFSET+OSPF_PDU_LEN_MIN)) { if(ospf_pdu_load(&pdu, g_pdu_buf+OSPFv2_MRT_PDU_OFFSET, mrt.length-OSPFv2_MRT_PDU_OFFSET) != PROTOCOL_SUCCESS) { - LOG(ERROR, "Invalid MRT file %s (PDU load error)\n", file_path); + LOG(ERROR, "Invalid OSPFv2 MRT file %s (PDU load error)\n", file_path); fclose(mrt_file); return false; } if(pdu.pdu_version != OSPF_VERSION_2) { - LOG(ERROR, "Invalid MRT file %s (wrong PDU version)\n", file_path); + LOG(ERROR, "Invalid OSPFv2 MRT file %s (wrong PDU version)\n", file_path); fclose(mrt_file); return false; } if(pdu.pdu_len < OSPFV2_LS_UPDATE_LEN_MIN) { - LOG(ERROR, "Invalid MRT file %s (wrong PDU len)\n", file_path); + LOG(ERROR, "Invalid OSPFv2 MRT file %s (wrong PDU len)\n", file_path); fclose(mrt_file); return false; } @@ -64,17 +64,17 @@ ospf_mrt_load(ospf_instance_s *instance, char *file_path) OSPF_PDU_CURSOR_SET(&pdu, OSPFV2_OFFSET_LS_UPDATE_LSA); } else if(mrt.type == OSPFv3_MRT_TYPE && mrt.length >= (OSPFv3_MRT_PDU_OFFSET+OSPF_PDU_LEN_MIN)) { if(ospf_pdu_load(&pdu, g_pdu_buf+OSPFv3_MRT_PDU_OFFSET, mrt.length-OSPFv3_MRT_PDU_OFFSET) != PROTOCOL_SUCCESS) { - LOG(ERROR, "Invalid MRT file %s (PDU load error)\n", file_path); + LOG(ERROR, "Invalid OSPFv3 MRT file %s (PDU load error)\n", file_path); fclose(mrt_file); return false; } if(pdu.pdu_version != OSPF_VERSION_3) { - LOG(ERROR, "Invalid MRT file %s (wrong PDU version)\n", file_path); + LOG(ERROR, "Invalid OSPFv3 MRT file %s (wrong PDU version)\n", file_path); fclose(mrt_file); return false; } if(pdu.pdu_len < OSPFV3_LS_UPDATE_LEN_MIN) { - LOG(ERROR, "Invalid MRT file %s (wrong PDU len)\n", file_path); + LOG(ERROR, "Invalid OSPFv3 MRT file %s (wrong PDU len)\n", file_path); fclose(mrt_file); return false; } diff --git a/code/bngblaster/src/ospf/ospf_mrt.h b/code/bngblaster/src/ospf/ospf_mrt.h index 40eb2155..1a4e5d31 100644 --- a/code/bngblaster/src/ospf/ospf_mrt.h +++ b/code/bngblaster/src/ospf/ospf_mrt.h @@ -13,7 +13,7 @@ #define OSPFv3_MRT_TYPE 48 #define OSPFv2_MRT_PDU_OFFSET 8 -#define OSPFv3_MRT_PDU_OFFSET 36 +#define OSPFv3_MRT_PDU_OFFSET 34 typedef struct ospf_mrt_hdr_ { uint32_t timestamp; diff --git a/code/bngblaster/src/ospf/ospf_neighbor.c b/code/bngblaster/src/ospf/ospf_neighbor.c index 19f26698..a001d74c 100644 --- a/code/bngblaster/src/ospf/ospf_neighbor.c +++ b/code/bngblaster/src/ospf/ospf_neighbor.c @@ -83,6 +83,9 @@ ospf_neighbor_dbd_tx(ospf_neighbor_s *ospf_neighbor) /* Add LSA header */ ospf_neighbor->dbd_more = false; for(type = ospf_neighbor->dbd_lsa_type_start; type < OSPF_LSA_TYPE_MAX; type++) { + if(hb_tree_count(ospf_instance->lsdb[type]) == 0){ + continue; + } itor = hb_itor_new(ospf_instance->lsdb[type]); if(type == ospf_neighbor->dbd_lsa_type_start) { next = hb_itor_search_ge(itor, &ospf_neighbor->dbd_lsa_start); @@ -533,7 +536,7 @@ ospf_neighbor_dbd_rx(ospf_interface_s *ospf_interface, hdr = (ospf_lsa_header_s*)OSPF_PDU_CURSOR(pdu); OSPF_PDU_CURSOR_INC(pdu, OSPF_LSA_HDR_LEN); - if(hdr->type < OSPF_LSA_TYPE_1 || hdr->type > OSPF_LSA_TYPE_11) { + if(hdr->type < OSPF_LSA_TYPE_1 || hdr->type > OSPF_LSA_TYPE_MAX) { ospf_rx_error(interface, pdu, "decode (invalid LSA type)"); ospf_neighbor_update_state(ospf_neighbor, OSPF_NBSTATE_EXSTART); return;