[lonetix/*,tools/bgpgrep/*] Correct handling of extended timestamps during filtering, decode and dump

This commit is contained in:
Lorenzo Cogotti
2021-08-20 22:37:20 +02:00
parent 39dac63d82
commit db129a0d39
5 changed files with 72 additions and 29 deletions

View File

@ -65,6 +65,12 @@ static void FixBgpAttributeTableForRib(Bgpattrtab tab, Boolean isRibv2)
}
}
static void NormalizeExtendedTimestamp(void)
{
S.timestampSecs += S.timestampMicrosecs / 1000000;
S.timestampMicrosecs %= 1000000;
}
static void OutputBgp4mp(const Mrthdr *hdr, Bgpattrtab tab)
{
S.lenientBgpErrors = TRUE;
@ -90,8 +96,10 @@ void BgpgrepD_Bgp4mp(void)
S.peerAs = BGP4MP_GETPEERADDR(hdr->subtype, &S.peerAddr, bgp4mp);
S.timestampSecs = beswap32(hdr->timestamp);
S.timestampMicrosecs = 0;
if (hdr->subtype == MRT_BGP4MP_ET)
if (hdr->type == MRT_BGP4MP_ET) {
S.timestampMicrosecs = beswap32(((const Mrthdrex *) hdr)->microsecs);
NormalizeExtendedTimestamp();
}
// Dump MRT data
Bgp_UnwrapBgp4mp(&S.rec, &S.msg, /*flags=*/BGPF_UNOWNED);

View File

@ -43,13 +43,13 @@ static Uint32 ParseFrac(const char *s, const char *p, char **ep)
if (res != NCVENOERR)
FATALF("%s: Expecting fractional portion of a second after '.'", s);
int ndigs = endp - p;
double frac = pow(10, ndigs);
int ndigs = endp - p;
long double frac = pow(10, ndigs);
if (ep)
*ep = endp;
return (Uint32) trunc((n / frac) * 100000.0);
return (Uint32) truncl(n / frac * 1000000.0L);
}
static Boolean ParseRfc3339(const char *s, Timestampop *dest)