Skip to content

Commit

Permalink
Wire ipfix tags 150/151 - seconds accuracy first/last seen timestamps.
Browse files Browse the repository at this point in the history
  • Loading branch information
phaag committed Dec 23, 2024
1 parent 50ea00c commit 07d17e3
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/netflow/ipfix.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ enum {
STACK_ICMPCODE,
STACK_DSTPORT,
STACK_SAMPLER,
STACK_SECFIRST,
STACK_SECLAST,
STACK_MSECFIRST,
STACK_MSECLAST,
STACK_DURATION,
Expand Down Expand Up @@ -155,6 +157,8 @@ static const struct ipfixTranslationMap_s {
{IPFIX_bgpSourceAsNumber, SIZEsrcAS, NumberCopy, EXasRoutingID, OFFsrcAS, STACK_NONE, "src AS"},
{IPFIX_bgpDestinationAsNumber, SIZEdstAS, NumberCopy, EXasRoutingID, OFFdstAS, STACK_NONE, "dst AS"},
{IPFIX_bgpNextHopIPv4Address, SIZEbgp4NextIP, NumberCopy, EXbgpNextHopV4ID, OFFbgp4NextIP, STACK_NONE, "IPv4 bgp next hop"},
{IPFIX_flowStartSeconds, Stack_ONLY, NumberCopy, EXnull, 0, STACK_SECLAST, "sec first seen"},
{IPFIX_flowEndSeconds, Stack_ONLY, NumberCopy, EXnull, 0, STACK_SECFIRST, "sec last seen"},
{IPFIX_flowEndSysUpTime, Stack_ONLY, NumberCopy, EXnull, 0, STACK_MSECLAST, "msec last SysupTime"},
{IPFIX_flowStartSysUpTime, Stack_ONLY, NumberCopy, EXnull, 0, STACK_MSECFIRST, "msec first SysupTime"},
{IPFIX_SystemInitTimeMiliseconds, Stack_ONLY, NumberCopy, EXnull, 0, STACK_SYSUPTIME, "SysupTime msec"},
Expand Down Expand Up @@ -1446,6 +1450,10 @@ static void Process_ipfix_data(exporterDomain_t *exporter, uint32_t ExportTime,
dbg_printf("Calculate first/last from option SysUpTime\n");
genericFlow->msecFirst = exporter->SysUpTime + stack[STACK_MSECFIRST];
genericFlow->msecLast = exporter->SysUpTime + stack[STACK_MSECLAST];
} else if (stack[STACK_SECFIRST]) {
dbg_printf("first/last sec abs.\n");
genericFlow->msecFirst = stack[STACK_SECFIRST] * (uint64_t)1000;
genericFlow->msecLast = stack[STACK_SECLAST] * (uint64_t)1000;
}

if (genericFlow->msecFirst < fs->msecFirst) fs->msecFirst = genericFlow->msecFirst;
Expand Down
7 changes: 7 additions & 0 deletions src/netflow/netflow_v9.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ enum {
STACK_MSECFIRST,
STACK_MSECLAST,
STACK_SAMPLER,
STACK_SECFIRST,
STACK_SECLAST,
STACK_MSEC,
STACK_SYSUPTIME,
STACK_CLIENT_USEC,
Expand Down Expand Up @@ -160,6 +162,8 @@ static const struct v9TranslationMap_s {
{NF9_BGP_V4_NEXT_HOP, SIZEbgp4NextIP, NumberCopy, EXbgpNextHopV4ID, OFFbgp4NextIP, STACK_NONE, "IPv4 bgp next hop"},
{NF9_LAST_SWITCHED, Stack_ONLY, NumberCopy, EXgenericFlowID, OFFmsecLast, STACK_MSECLAST, "msec last SysupTime"},
{NF9_FIRST_SWITCHED, Stack_ONLY, NumberCopy, EXgenericFlowID, OFFmsecFirst, STACK_MSECFIRST, "msec first SysupTime"},
{NF_F_flowStartSeconds, Stack_ONLY, NumberCopy, EXnull, 0, STACK_SECLAST, "sec first seen"},
{NF_F_flowEndSeconds, Stack_ONLY, NumberCopy, EXnull, 0, STACK_SECFIRST, "sec last seen"},
{NF9_OUT_BYTES, SIZEoutBytes, NumberCopy, EXcntFlowID, OFFoutBytes, STACK_NONE, "output bytes delta counter"},
{NF9_OUT_PKTS, SIZEoutPackets, NumberCopy, EXcntFlowID, OFFoutPackets, STACK_NONE, "output packet delta counter"},
{NF9_IPV6_SRC_ADDR, SIZEsrc6Addr, NumberCopy, EXipv6FlowID, OFFsrc6Addr, STACK_NONE, "IPv6 src addr"},
Expand Down Expand Up @@ -1193,6 +1197,9 @@ static inline void Process_v9_data(exporterDomain_t *exporter, void *data_flowse

// end time in msecs
genericFlow->msecLast = (uint64_t)Last + exporter->boot_time;
} else if (stack[STACK_SECFIRST]) {
genericFlow->msecFirst = stack[STACK_SECFIRST] * (uint64_t)1000;
genericFlow->msecLast = stack[STACK_SECLAST] * (uint64_t)1000;
}

if (genericFlow->msecFirst < fs->msecFirst) fs->msecFirst = genericFlow->msecFirst;
Expand Down
2 changes: 2 additions & 0 deletions src/netflow/netflow_v9.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ typedef struct common_header_s {
// IPFIX elements in v9 ( # > 127 )
#define NF_F_BGP_ADJ_NEXT_AS 128
#define NF_F_BGP_ADJ_PREV_AS 129
#define NF_F_flowStartSeconds 150
#define NF_F_flowEndSeconds 151
#define NF_F_flowEndReason 136
#define NF_F_dot1qVlanId 243
#define NF_F_postDot1qVlanId 254
Expand Down
2 changes: 1 addition & 1 deletion src/nfcapd/nfcapd.c
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ static void run(packet_function_t receive_packet, int socket, int pfd, int rfd,
break;
default:
// data error, while reading data from socket
LogError("Ident: %s, Error reading netflow header: Unexpected netflow version %i", fs->Ident, version);
LogError("Ident: %s, Error packet %llu: reading netflow header: Unexpected netflow version %i", fs->Ident, packets, version);
fs->bad_packets++;
continue;

Expand Down

0 comments on commit 07d17e3

Please sign in to comment.