Skip to content

Commit

Permalink
add support for LSA type 12 - 42
Browse files Browse the repository at this point in the history
  • Loading branch information
GIC-de committed Oct 12, 2023
1 parent a6cb23f commit 30e49ec
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 18 deletions.
4 changes: 3 additions & 1 deletion code/bngblaster/src/ospf/ospf_ctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
33 changes: 32 additions & 1 deletion code/bngblaster/src/ospf/ospf_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_ {
Expand Down
36 changes: 28 additions & 8 deletions code/bngblaster/src/ospf/ospf_lsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}

Expand Down
12 changes: 6 additions & 6 deletions code/bngblaster/src/ospf/ospf_mrt.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,35 +46,35 @@ 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;
}
lsa_count = be32toh(*(uint32_t*)OSPF_PDU_OFFSET(&pdu, OSPFV2_OFFSET_LS_UPDATE_COUNT));
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;
}
Expand Down
2 changes: 1 addition & 1 deletion code/bngblaster/src/ospf/ospf_mrt.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion code/bngblaster/src/ospf/ospf_neighbor.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 30e49ec

Please sign in to comment.