[bgp/dump_isolario] Make sure BGP data is valid when dumping BGP4MP, print corruption warning when it is not

This commit is contained in:
Lorenzo Cogotti 2021-06-08 22:11:50 +02:00
parent 3ab2e69bb2
commit 6de065b5e6
1 changed files with 24 additions and 12 deletions

View File

@ -434,6 +434,17 @@ static void DumpMrtInfoTrailer(Stmbuf *sb, const Dumpfmtctx *ctx)
Bufio_Puts(sb, EOLN);
}
static void WarnCorrupted(Stmbuf *sb, const Dumpfmtctx *ctx)
{
Bufio_Putc(sb, SEP_CHAR_BAD);
if (ctx->withColors)
Bufio_Puts(sb, CORRUPT_WARN);
else
Bufio_Puts(sb, VTSGR(VTINV) CORRUPT_WARN VTSGR(VTNOINV));
Bufio_Putc(sb, SEP_CHAR_BAD);
}
static Sint32 DumpRoutesFast(char marker,
Stmbuf *sb,
Bgpmpiter *prefixes,
@ -693,13 +704,7 @@ static Judgement DumpBgp(Stmbuf *sb,
return OK;
corrupted:
Bufio_Putc(sb, SEP_CHAR_BAD);
if (ctx->withColors)
Bufio_Puts(sb, CORRUPT_WARN);
else
Bufio_Puts(sb, VTSGR(VTINV) CORRUPT_WARN VTSGR(VTNOINV));
Bufio_Putc(sb, SEP_CHAR_BAD);
WarnCorrupted(sb, ctx);
return NG;
}
@ -995,10 +1000,17 @@ static Sint64 Isolario_DumpBgp4mp(const Mrthdr *hdr,
size_t nbytes = len - offset;
nbytes = Bgp_CheckMsgHdr(msg, nbytes, /*allowExtendedSize=*/TRUE);
if (nbytes != 0) {
// Header is OK
nbytes -= BGP_HDRSIZ;
DumpBgp(&sb, msg->type, msg + 1, nbytes, table, &ctx);
} else {
// Corrupted BGP4MP with invalid BGP data
Bufio_Putc(&sb, UNKNOWN_MARKER);
Bufio_Putc(&sb, SEP_CHAR);
WarnCorrupted(&sb, &ctx);
DumpMrtInfoTrailer(&sb, &ctx);
}
} else {
// Deprecated/Unknown type
Bufio_Putc(&sb, UNKNOWN_MARKER);