log LSA HDR on load external error

This commit is contained in:
Christian Giese
2024-02-06 08:41:25 +00:00
parent c2a53c42f8
commit 69f57ab269
4 changed files with 32 additions and 6 deletions
+3
View File
@@ -66,6 +66,7 @@
#define OSPF_LSA_MAX_AGE_DIFF 900 /* 15 minutes */
#define OSPF_LSA_SEQ_INIT 0x80000000
#define OSPF_LSA_SEQ_MAX 0x7fffffff
#define OSPF_LSA_CHECKSUM_OFFSET 16
#define OSPF_LSA_BORDER_ROUTER 0x01
#define OSPF_LSA_EXTERNAL_ROUTER 0x02
@@ -163,6 +164,8 @@
#define OSPFV2_EXT_PREFIX_TLV 1
#define OSPF_LSA_HDR_STRING_LEN sizeof("TYPE255:255.255.255.255:255.255.255.255:FFFFFFFF")
typedef struct ospf_config_ ospf_config_s;
typedef struct ospf_instance_ ospf_instance_s;
typedef struct ospf_interface_ ospf_interface_s;
+8 -6
View File
@@ -389,12 +389,14 @@ ospf_lsa_verify_checksum(ospf_lsa_header_s *hdr)
if(len < sizeof(ospf_lsa_header_s)) return false;
checksum = bbl_checksum_fletcher16(&hdr->options, len-OSPF_LSA_AGE_LEN, 14);
checksum = bbl_checksum_fletcher16(&hdr->options, len-OSPF_LSA_AGE_LEN,
OSPF_LSA_CHECKSUM_OFFSET-OSPF_LSA_AGE_LEN);
hdr->checksum = checksum_orig;
if(checksum == checksum_orig) {
return true;
} else {
LOG(ERROR, "OSPF LSA checksum error (expected %04x received %04x)\n", checksum, checksum_orig);
return false;
}
}
@@ -1962,7 +1964,7 @@ ospf_lsa_load_external(ospf_instance_s *ospf_instance, uint16_t lsa_count, uint8
uint16_t lsa_len;
uint8_t lsa_type;
struct timespec now;
struct timespec now;
clock_gettime(CLOCK_MONOTONIC, &now);
while(len >= OSPF_LSA_HDR_LEN && lsa_count) {
@@ -1971,12 +1973,12 @@ ospf_lsa_load_external(ospf_instance_s *ospf_instance, uint16_t lsa_count, uint8
lsa_type = hdr->type;
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);
LOG(ERROR, "Failed to decode external OSPF LSA %s (invalid LSA type %u)\n", ospf_lsa_hdr_string(hdr), lsa_type);
return false;
}
lsa_len = be16toh(hdr->length);
if(lsa_len > len) {
LOG(ERROR, "Failed to decode external OSPF LSA (invalid LSA len %u)\n", lsa_len);
LOG(ERROR, "Failed to decode external OSPF LSA %s (invalid LSA len %u)\n", ospf_lsa_hdr_string(hdr), lsa_len);
return false;
}
@@ -1985,7 +1987,7 @@ ospf_lsa_load_external(ospf_instance_s *ospf_instance, uint16_t lsa_count, uint8
lsa_count--;
if(!ospf_lsa_verify_checksum(hdr)) {
LOG_NOARG(ERROR, "Failed to decode external OSPF LSA (invalid LSA checksum)\n");
LOG(ERROR, "Failed to decode external OSPF LSA %s (invalid LSA checksum)\n", ospf_lsa_hdr_string(hdr));
return false;
}
@@ -2000,7 +2002,7 @@ ospf_lsa_load_external(ospf_instance_s *ospf_instance, uint16_t lsa_count, uint8
if(result.inserted) {
*result.datum_ptr = lsa;
} else {
LOG_NOARG(OSPF, "Failed to add external OSPF LSA to LSDB\n");
LOG(OSPF, "Failed to add external OSPF LSA %s to LSDB\n", ospf_lsa_hdr_string(hdr));
return false;
}
}
+18
View File
@@ -108,3 +108,21 @@ ospf_rx_error(bbl_network_interface_s *interface, ospf_pdu_s *pdu, const char *e
interface->stats.ospf_rx_error++;
}
char *
ospf_lsa_hdr_string(ospf_lsa_header_s *hdr)
{
static char buffer[8][OSPF_LSA_HDR_STRING_LEN];
static int idx = 0;
char *ret;
ret = buffer[idx];
idx = (idx+1) & 7;
uint32_t id = hdr->id;
uint32_t router = hdr->router;
snprintf(ret, OSPF_LSA_HDR_STRING_LEN, "TYPE%u:%s:%s:%04x",
hdr->type,
format_ipv4_address(&id),
format_ipv4_address(&router),
be32toh(hdr->seq));
return ret;
}
+3
View File
@@ -33,4 +33,7 @@ ospf_pdu_type_string(uint8_t type);
void
ospf_rx_error(bbl_network_interface_s *interface, ospf_pdu_s *pdu, const char *error);
char *
ospf_lsa_hdr_string(ospf_lsa_header_s *hdr);
#endif