Commit f5ea410c authored by Håvard Moås's avatar Håvard Moås
Browse files

Update IPFIXLIB to fix some new-style comments, and fix wrapover bug for...

Update IPFIXLIB to fix some new-style comments, and fix wrapover bug for sequence number checking, havard.mork@gmail.com

git-svn-id: file:///home/svn/mapi/branches/haavardm-mapi@111 8d5bb341-7cf1-0310-8cf6-ba355fef3186
parent 3a37e941
......@@ -704,11 +704,14 @@ void addPktToHash(np_ctxt_t *npctxt,
/* Calculate packets out of sequence for various transport protocols.*/
switch(proto) {
case IPPROTO_TCP:
if(bkt->src2dst_last_sequence_number > seqnum) {
// seqnum has lower ID than expected
if(bkt->src2dst_last_sequence_number > seqnum &&
!(bkt->src2dst_last_sequence_number > 0x8FFFFFFF
&& seqnum < 0x0FFFFFFF)) {
/* seqnum has lower ID than expected */
bkt->src2dst_num_packets_out_of_sequence++;
} else {
// Ordered, or early delivery.
/* Ordered, or early delivery. */
bkt->src2dst_last_sequence_number = seqnum;
}
break;
......@@ -763,15 +766,17 @@ void addPktToHash(np_ctxt_t *npctxt,
if(ttl > bkt->dst2srcMaxTTL)
bkt->dst2srcMaxTTL = ttl;
// Calculate packets out of sequence for various transport protocols.
/* Calculate packets out of sequence for various transport protocols.*/
if(bkt->dst2src_last_sequence_number != 0) {
switch(proto) {
case IPPROTO_TCP:
if(bkt->dst2src_last_sequence_number > seqnum) {
// Packet has lower ID than expected
if(bkt->dst2src_last_sequence_number > seqnum &&
!(bkt->dst2src_last_sequence_number > 0x8FFFFFFF
&& seqnum < 0x0FFFFFFF)) {
/* Packet has lower ID than expected */
bkt->dst2src_num_packets_out_of_sequence++;
} else {
// Ordered, or early delivery.
/* Ordered, or early delivery. */
bkt->dst2src_last_sequence_number = seqnum;
}
break;
......
......@@ -195,7 +195,7 @@ typedef struct ipV4Fragment {
#define TEMPLATE_LIST_LEN 32
// Bitset for bitrateCalcEnabled (in struct np_ctxt_t)
/* Bitset for bitrateCalcEnabled (in struct np_ctxt_t) */
#define BITRATECALC_NONE 0
#define BITRATECALC_1SEC 1
#define BITRATECALC_100MS 2
......@@ -240,7 +240,7 @@ typedef struct {
u_int16_t minNumFlowsPerPacket; /* FlowSets are sent when this number is hit */
u_int16_t maxNumFlowsPerPacket; /* Max size of a flowset. Not enforced! */
// Last time a FlowSet was physically sent. See also flowExportDelay.
/* Last time a FlowSet was physically sent. See also flowExportDelay. */
unsigned long long lastExportTime;
unsigned long long lastTmpltExportTime;
u_short idleTimeout;
......
......@@ -27,10 +27,10 @@
* to be resolved first).
*/
typedef struct mapid_pkthdr {
unsigned long long ts; /* 64-bit timestamp of packet*/
unsigned short ifindex; //Interface index
unsigned caplen; /* length of portion present */
unsigned wlen; /* length this packet (off wire) */
unsigned long long ts; /* 64-bit timestamp of packet*/
unsigned short ifindex; /* Interface index */
unsigned caplen; /* length of portion present */
unsigned wlen; /* length this packet (off wire) */
} mapid_pkthdr_t;
#include "npktproc.h"
......@@ -67,7 +67,7 @@ nprobeProcessPacket(void *ctxt, mapid_pkthdr_t *pkt_head, const void *pkt)
u_char isFragment = 0;
np_ctxt_t *npctxt = (np_ctxt_t *)ctxt;
u_int64_t v4_options = 0;
//u_int32_t v6_options = 0;
/*u_int32_t v6_options = 0;*/
u_int hlen=0;
#ifdef DEBUG
......@@ -125,8 +125,7 @@ nprobeProcessPacket(void *ctxt, mapid_pkthdr_t *pkt_head, const void *pkt)
off = ntohs(ip.ip_off);
//
// Parse IPv4 header options, if they exist
/* Parse IPv4 header options, if they exist */
if(hlen >= 24) {
u_int olen = 4;
if(hlen >= 28)
......
......@@ -128,14 +128,14 @@ exportBucket(np_ctxt_t *npctxt, HashBucket *myBucket)
void queueBucketToExport(np_ctxt_t *npctxt, HashBucket *myBucket) {
pthread_mutex_lock(&exportMutex);
// addToList(myBucket, &npctxt->exportQueue);
/* addToList(myBucket, &npctxt->exportQueue); */
addToListEnd(myBucket, &npctxt->exportQueue, &npctxt->exportQueueEnd);
myBucket->time_exported = time(NULL);
npctxt->exportBucketsLen++;
pthread_mutex_unlock(&exportMutex);
//signalCondvar(&npctxt->exportQueueCondvar);
// NOTE: signalling is done in calling procedure, in order to
// signal only once, after all entries have been enqueued.
/*signalCondvar(&npctxt->exportQueueCondvar); */
/* NOTE: signalling is done in calling procedure, in order to */
/* signal only once, after all entries have been enqueued. */
}
/* ****************************************************** */
......@@ -443,15 +443,14 @@ sendNetFlow(np_ctxt_t *npctxt, const void *buffer, u_int32_t bufferLength,
*/
if((npctxt->flowExportDelay > 0) && (!lastFlow)) {
#ifndef WIN32
//struct timespec timeout;
//
//timeout.tv_sec = 0;
//timeout.tv_nsec = 1000*npctxt->flowExportDelay;
//while((nanosleep(&timeout, &timeout) == -1)
// && (errno == EINTR))
// ; /* Do nothing */
//
// /* It seems that usleep has problems on some architectures */
/*struct timespec timeout;
timeout.tv_sec = 0;
timeout.tv_nsec = 1000*npctxt->flowExportDelay;
while((nanosleep(&timeout, &timeout) == -1)
&& (errno == EINTR))
;*/ /* Do nothing */
/* It seems that usleep has problems on some architectures */
usleep(npctxt->flowExportDelay);
#else
waitForNextEvent(npctxt->flowExportDelay);
......@@ -461,13 +460,13 @@ sendNetFlow(np_ctxt_t *npctxt, const void *buffer, u_int32_t bufferLength,
if(npctxt->fileexportHandle != NULL) {
u_int8_t magic = 0x7F;
// Write first magic number (for synchronization, error-checking),
// then write length of the record.
/* Write first magic number (for synchronization, error-checking), */
/* then write length of the record. */
fwrite(&magic,1,1,npctxt->fileexportHandle);
fwrite(&bufferLength,sizeof(u_int32_t),1,npctxt->fileexportHandle);
fwrite(buffer,bufferLength,1,npctxt->fileexportHandle);
// PENDING should we do the SHM write when doing this?
/* PENDING should we do the SHM write when doing this? */
}
if (npctxt->numCollectors == 0) {
......@@ -585,8 +584,8 @@ initNetFlowIPFIXHeader(np_ctxt_t *npctxt)
memset(ipfixHeader, 0, sizeof(IPFIXFlowHeader));
ipfixHeader->version = htons(0x0a);
ipfixHeader->length = 0; // set at time of export
ipfixHeader->exportTime = 0; // set at time of export
ipfixHeader->length = 0; /* set at time of export */
ipfixHeader->exportTime = 0; /* set at time of export */
ipfixHeader->flow_sequence = htonl(npctxt->flowSequence);
ipfixHeader->sourceId = htons(engineType); /* CHECK */
}
......@@ -640,7 +639,7 @@ sendNetFlowIPFIXtemplate(np_ctxt_t *npctxt)
&numElements, 1, NULL, 0, 0);
initNetFlowIPFIXHeader(npctxt);
//npctxt->ipfixHeader.count = htons(1);
/*npctxt->ipfixHeader.count = htons(1); */
/* ********************** */
......@@ -846,14 +845,14 @@ checkNetFlowExport(np_ctxt_t *npctxt, int forceExport)
initNetFlowV9Header(npctxt);
npctxt->v9Header.count = htons(npctxt->numFlows);
sendNetFlowV9(npctxt, 0);
} else { // Assume IPFIX 0x0a
} else { /* Assume IPFIX 0x0a */
if (now > (npctxt->lastTmpltExportTime +
((unsigned long long) npctxt->tmpltTimeout << 32)))
npctxt->templateSent = 0; /* Time to export templates again */
if (npctxt->templateSent == 0)
npctxt->lastTmpltExportTime = now;
initNetFlowIPFIXHeader(npctxt);
//npctxt->ipfixHeader.length = //htons(npctxt->numFlows);
/*npctxt->ipfixHeader.length = htons(npctxt->numFlows); */
sendNetFlowIPFIX(npctxt, 0);
}
npctxt->numFlows = 0, totExports++, npctxt->numExports++;
......@@ -915,8 +914,8 @@ exportBucketToNetflowV5(np_ctxt_t *npctxt, HashBucket *myBucket,
theV5Flow->flowRecord[numFlows].srcport = htons(myBucket->sport);
theV5Flow->flowRecord[numFlows].dstport = htons(myBucket->dport);
theV5Flow->flowRecord[numFlows].tos = myBucket->src2dstTos;
theV5Flow->flowRecord[numFlows].src_as = htons(ip2AS(myBucket->src)); // htons(srcAS);
theV5Flow->flowRecord[numFlows].dst_as = htons(ip2AS(myBucket->dst)); // htons(dstAS);
theV5Flow->flowRecord[numFlows].src_as = htons(ip2AS(myBucket->src));
theV5Flow->flowRecord[numFlows].dst_as = htons(ip2AS(myBucket->dst));
theV5Flow->flowRecord[numFlows].tcp_flags = myBucket->src2dstTcpFlags;
} else {
if(myBucket->pktRcvd == 0) return(0); /* Nothing to export */
......@@ -929,8 +928,8 @@ exportBucketToNetflowV5(np_ctxt_t *npctxt, HashBucket *myBucket,
theV5Flow->flowRecord[numFlows].srcport = htons(myBucket->dport);
theV5Flow->flowRecord[numFlows].dstport = htons(myBucket->sport);
theV5Flow->flowRecord[numFlows].tos = myBucket->dst2srcTos;
theV5Flow->flowRecord[numFlows].src_as = htons(ip2AS(myBucket->dst)); // htons(dstAS);
theV5Flow->flowRecord[numFlows].dst_as = htons(ip2AS(myBucket->src)); // htons(srcAS);
theV5Flow->flowRecord[numFlows].src_as = htons(ip2AS(myBucket->dst));
theV5Flow->flowRecord[numFlows].dst_as = htons(ip2AS(myBucket->src));
theV5Flow->flowRecord[numFlows].tcp_flags = myBucket->dst2srcTcpFlags;
}
......@@ -1088,21 +1087,21 @@ npInitContext(void)
npctxt->netFlowOutSocket = -1;
npctxt->fileexportName = NULL;
npctxt->fileexportHandle = NULL;
npctxt->tcpPayloadExport = 1; // 1 captures all, 2 captures only SYN pkgs
npctxt->tcpPayloadExport = 1; /* 1 captures all, 2 captures only SYN pkgs */
npctxt->udpPayloadExport = 0;
npctxt->icmpPayloadExport = 0;
npctxt->otherPayloadExport = 0;
npctxt->compressFlows = 0;
npctxt->textFormat = NULL;
npctxt->maxExportQueueLatency = 1; // Num of seconds to keep records. NEVER set to 0!
npctxt->maxExportQueueLatency = 1; /* Num of seconds to keep records. NEVER set to 0! */
// PENDING: conditionally set this, based on observed parameters.
/* PENDING: conditionally set this, based on observed parameters. */
npctxt->maxPayloadLen = 0;
npctxt->bufferLen = 0;
npctxt->numFlows = 0;
npctxt->minNumFlowsPerPacket = 40;
npctxt->maxNumFlowsPerPacket = 40; // Loosely enforced
npctxt->maxNumFlowsPerPacket = 40; /* Loosely enforced */
npctxt->lastExportTime = 0;
npctxt->lastTmpltExportTime = 0;
......@@ -1134,12 +1133,12 @@ npInitContext(void)
npctxt->exportBucketsLen = 0;
npctxt->lastMaxBucketSearch = 5; /* Don't bother with values < 5 */
// Enterprise ID used for IPFIX custom fields
// Set this to point to YOUR organization's enterprise ID, according to IPFIX proposal
/* Enterprise ID used for IPFIX custom fields
* Set this to point to YOUR organization's enterprise ID, according to IPFIX proposal */
npctxt->enterpriseId = 2428;
npctxt->histPktSizeEnabled = 0;
npctxt->histPktSizeBucket[0] = 50; // See PKTSZ_HISTOGRAM_SLOTS
npctxt->histPktSizeBucket[0] = 50; /* See PKTSZ_HISTOGRAM_SLOTS */
npctxt->histPktSizeBucket[1] = 100;
npctxt->histPktSizeBucket[2] = 200;
npctxt->histPktSizeBucket[3] = 750;
......@@ -1150,7 +1149,7 @@ npInitContext(void)
npctxt->histPktSizeBucket[8] =0xFFFF;
npctxt->histPktDistEnabled = 0;
npctxt->histPktDistBucket[0] = 25; // See PKTDIST_HISTOGRAM_SLOTS
npctxt->histPktDistBucket[0] = 25; /* See PKTDIST_HISTOGRAM_SLOTS */
npctxt->histPktDistBucket[1] = 50;
npctxt->histPktDistBucket[2] = 75;
npctxt->histPktDistBucket[3] = 100;
......@@ -1176,7 +1175,7 @@ npInitContext(void)
npctxt->ignoredPacketTotalCount = 0;
npctxt->ignoredOctetTotalCount = 0;
// Attempt to get own IP address
/* Attempt to get own IP address */
if (gethostname(ac, sizeof(ac))==0) {
struct hostent *phe = gethostbyname(ac);
if (phe != NULL) {
......
......@@ -45,14 +45,12 @@
#define FLAG_FRAGMENTED_PACKET_SRC2DST 3
#define FLAG_FRAGMENTED_PACKET_DST2SRC 4
// Packet size histogram generation
/* Packet size histogram generation */
#define PKTSZ_HISTOGRAM_SLOTS 9
//#define PKTSZ_HISTOGRAM_DISTR 256
#define PKTDIST_HISTOGRAM_SLOTS 10
//#define PKTDIST_HISTOGRAM_DISTR 50
// Number of intervals when calculating bitrate averages
// When changing this, also consider engine.c:updateBitrateCalculation.
/* Number of intervals when calculating bitrate averages */
/* When changing this, also consider engine.c:updateBitrateCalculation. */
#define BITRATE_AVERAGER_SLOTS 10
#define FLOW_END_IDLE 0x01 /* Flow exported due to idle */
......@@ -119,15 +117,15 @@ typedef struct hashBucket {
u_int16_t src2dstMinPktSize, dst2srcMinPktSize;
u_int16_t src2dstMaxPktSize, dst2srcMaxPktSize;
u_int32_t src2dstBitrateAverager1sec[BITRATE_AVERAGER_SLOTS]; // xfer last 1sec
u_int32_t src2dstBitrateAverager100ms[BITRATE_AVERAGER_SLOTS];// xfer last 100ms
u_int32_t src2dstBitrateAverager10ms[BITRATE_AVERAGER_SLOTS]; // xfer last 10ms
u_int32_t src2dstBitrateAverager1sec[BITRATE_AVERAGER_SLOTS];
u_int32_t src2dstBitrateAverager100ms[BITRATE_AVERAGER_SLOTS];
u_int32_t src2dstBitrateAverager10ms[BITRATE_AVERAGER_SLOTS];
unsigned long long src2dstBitrateLastUpdate1sec;
unsigned long long src2dstBitrateLastUpdate100ms;
unsigned long long src2dstBitrateLastUpdate10ms;
u_int32_t dst2srcBitrateAverager1sec[BITRATE_AVERAGER_SLOTS]; // xfer last 1sec
u_int32_t dst2srcBitrateAverager100ms[BITRATE_AVERAGER_SLOTS]; // xfer last 100ms
u_int32_t dst2srcBitrateAverager10ms[BITRATE_AVERAGER_SLOTS]; // xfer last 10ms
u_int32_t dst2srcBitrateAverager1sec[BITRATE_AVERAGER_SLOTS];
u_int32_t dst2srcBitrateAverager100ms[BITRATE_AVERAGER_SLOTS];
u_int32_t dst2srcBitrateAverager10ms[BITRATE_AVERAGER_SLOTS];
unsigned long long dst2srcBitrateLastUpdate1sec;
unsigned long long dst2srcBitrateLastUpdate100ms;
unsigned long long dst2srcBitrateLastUpdate10ms;
......@@ -157,7 +155,7 @@ typedef struct hashBucket {
u_int64_t optionsIPV4src2dst;
u_int64_t optionsIPV4dst2src;
u_int32_t src2dstflowid; // ID of flow locally unique to _exporter_.
u_int32_t src2dstflowid; /* ID of flow locally unique to _exporter_. */
u_int32_t dst2srcflowid;
u_int8_t flowEndReason;
......
......@@ -657,7 +657,7 @@ void nprintf(FILE *stream, char *fmt, HashBucket *theFlow, int direction) {
unsigned long long htonll(unsigned long long n) {
return (((u_int64_t)(ntohl((u_int32_t)((n << 32) >> 32))) << 32) |
(u_int32_t)ntohl(((u_int32_t)(n >> 32))));
//return (((unsigned long long)htonl(n)) << 32) + htonl(n >> 32);
/*return (((unsigned long long)htonl(n)) << 32) + htonl(n >> 32);*/
}
/* ********* NetFlow v9/IPFIX ***************************** */
......@@ -667,9 +667,9 @@ unsigned long long htonll(unsigned long long n) {
* switch statement in handleTemplate as well. */
static V9TemplateId ver9_templates[] = {
/* { 0, 0, "NOT_USED" }, */
{ 1, 4, "BYTES" }, // not ipfix
{ 1, 4, "BYTES" }, /* not ipfix */
{ 2, 4, "PKTS" },
{ 3, 4, "FLOWS" }, // not ipfix
{ 3, 4, "FLOWS" }, /* not ipfix */
{ 4, 1, "PROT" },
{ 5, 1, "TOS" },
{ 6, 1, "TCP_FLAGS" },
......@@ -689,36 +689,36 @@ static V9TemplateId ver9_templates[] = {
{ 20, 4, "MUL_DOCTETS" },
{ 21, 4, "LAST_SWITCHED" },
{ 22, 4, "FIRST_SWITCHED" },
{ 23, 4, "OUT_BYTES" }, // not ipfix
{ 24, 4, "OUT_PKTS" }, // NOTE: difference v9/ipfix
{ 23, 4, "OUT_BYTES" }, /* not ipfix */
{ 24, 4, "OUT_PKTS" }, /* NOTE: difference v9/ipfix */
{ 25, 2, "MIN_PKT_LNGTH" },
{ 26, 2, "MAX_PKT_LNGTH" },
{ 27, 16, "IPV6_SRC_ADDR" },
{ 28, 16, "IPV6_DST_ADDR" },
{ 29, 1, "IPV6_SRC_MASK" },
{ 30, 1, "IPV6_DST_MASK" },
{ 31, 3, "FLOW_LABEL" }, // !!
{ 31, 3, "FLOW_LABEL" }, /* !! */
{ 32, 2, "ICMP_TYPE" },
{ 33, 1, "IGMP_TYPE" },
{ 34, 4, "SAMPLING_INTERVAL" }, // not ipfix
{ 35, 1, "SAMPLING_ALGO" }, // not ipfix
{ 34, 4, "SAMPLING_INTERVAL" }, /* not ipfix */
{ 35, 1, "SAMPLING_ALGO" }, /* not ipfix */
{ 36, 2, "FLOW_ACTIVE_TIMEOUT" },
{ 37, 2, "FLOW_INACTIVE_TIMEOUT" },
{ 38, 1, "ENGINE_TYPE" }, // not ipfix
{ 39, 1, "ENGINE_ID" }, // not ipfix
{ 38, 1, "ENGINE_TYPE" }, /* not ipfix */
{ 39, 1, "ENGINE_ID" }, /* not ipfix */
{ 40, 8, "TOTAL_BYTES_EXP" },
{ 41, 8, "TOTAL_PKTS_EXP" },
{ 42, 8, "TOTAL_FLOWS_EXP" },
// NOT 43-59
{ 52, 1, "MIN_TTL" },
{ 53, 1, "MAX_TTL" },
{ 60, 1, "IP_PROTOCOL_VERSION" },
//{ 61, 1, "DIRECTION" },
//{ 62, 16, "IPV6_NEXT_HOP" },
//{ 63, 16, "BPG_IPV6_NEXT_HOP" },
/*
{ 61, 1, "DIRECTION" },
{ 62, 16, "IPV6_NEXT_HOP" },
{ 63, 16, "BPG_IPV6_NEXT_HOP" },
*/
{ 64, 4, "IPV6_OPTION_HEADERS" },
// NOT 65-87
/* nFlow Extensions */
/*
......@@ -730,19 +730,13 @@ static V9TemplateId ver9_templates[] = {
{ 85, 4, "APPL_LATENCY_SEC" },
{ 86, 4, "APPL_LATENCY_NSEC" },
*/
// { 87, 0 /* The length is set at runtime */, "PAYLOAD" },
{ 88, 4, "ICMP_FLAGS" },
// NOT 89-129
{130, 4, "EXPORTER_IPV4"},
{131, 16, "EXPORTER_IPV6"},
// *
{136, 1, "FLOW_END_REASON"},
// *
{145, 4, "TEMPLATE_ID"},
// *
{148, 4, "FLOW_ID"},
// *
{150, 4, "FLOW_START_SECONDS" },
{151, 4, "FLOW_END_SECONDS" },
{152, 8, "FLOW_START_MILLISECONDS" },
......@@ -751,7 +745,6 @@ static V9TemplateId ver9_templates[] = {
{155, 8, "FLOW_END_MICROSECONDS" },
{156, 8, "FLOW_START_NANOSECONDS" },
{157, 8, "FLOW_END_NANOSECONDS" },
// *
{160, 8, "SYSINIT_MILLIS"},
{161, 8, "FLOW_DUR_MILLIS"},
{162, 8, "FLOW_DUR_MICROS"},
......@@ -761,12 +754,9 @@ static V9TemplateId ver9_templates[] = {
{166, 8, "NOTSENT_FLOWS"},
{167, 8, "NOTSENT_PKTS"},
{168, 8, "NOTSENT_OCTETS"},
// *
{190, 2, "PKTLEN_IPV4"},
{191, 4, "PKTLEN_IPV6"},
// *
{204, 8, "OCTETS_64"},
//{205, 1 - postOctetDeltaCount - int
{206, 8, "OCTETS_TOT_64"},
{207, 1, "HDRLEN_IPV4"},
{208, 8, "IPV4_OPT"},
......@@ -774,7 +764,7 @@ static V9TemplateId ver9_templates[] = {
{210, 1, "PADDING"},
/* ipfixlib extensions */
// Note that 32768 is reserved (ent.mark = 1, ent.id = 0)
/* Note that 32768 is reserved (ent.mark = 1, ent.id = 0) */
{ FID_HISTOGRAM_PKT_LNGTH, PKTSZ_HISTOGRAM_SLOTS*sizeof(u_int8_t), "HISTOGRAM_PKT_LNGTH" },
{ FID_HISTOGRAM_PKT_DIST, PKTDIST_HISTOGRAM_SLOTS*sizeof(u_int8_t), "HISTOGRAM_PKT_DIST" },
{ FID_PAYLOAD, PAYLOAD_EXCERPT_MAX, "PAYLOAD" },
......@@ -784,10 +774,10 @@ static V9TemplateId ver9_templates[] = {
{ FID_RATE_100MS_MIN, 4, "MINRATE_100MS" },
{ FID_RATE_10MS_MAX, 4, "MAXRATE_10MS" },
{ FID_RATE_10MS_MIN, 4, "MINRATE_10MS" },
{ FID_VAR_PKT_DIST, 4, "VAR_PKT_DIST" }, // returns float-32
{ FID_EXPVAL_PKT_DIST, 4, "EXPVAL_PKT_DIST" }, // returns float-32
{ FID_VAR_PKT_LENGTH, 4, "VAR_PKT_LENGTH" }, // returns float-32
{ FID_EXPVAL_PKT_LENGTH,4, "EXPVAL_PKT_LENGTH" }, // returns float-32
{ FID_VAR_PKT_DIST, 4, "VAR_PKT_DIST" }, /* returns float-32 */
{ FID_EXPVAL_PKT_DIST, 4, "EXPVAL_PKT_DIST" }, /* returns float-32 */
{ FID_VAR_PKT_LENGTH, 4, "VAR_PKT_LENGTH" }, /* returns float-32 */
{ FID_EXPVAL_PKT_LENGTH,4, "EXPVAL_PKT_LENGTH" }, /* returns float-32 */
{ FID_SUM_PKT_DIST, 8, "SUM_PKT_DIST" },
{ FID_SUM_PKT_LENGTH, 8, "SUM_PKT_LENGTH" },
{ FID_QSUM_PKT_DIST, 8, "QSUM_PKT_DIST" },
......@@ -867,7 +857,7 @@ static void copyInt32ArrayToRelativeInt8(u_int32_t *_t32a, char *outBuffer,
u_int *outBufferBegin,
u_int *outBufferMax,
u_int nelements) {
u_int32_t maxNum = 1; // 1 to avoid fp errors
u_int32_t maxNum = 1; /* 1 to avoid fp errors */
u_int i;
u_int8_t *outarray = outBuffer+*outBufferBegin;
for(i=0; i<nelements; i++) {
......@@ -876,7 +866,7 @@ static void copyInt32ArrayToRelativeInt8(u_int32_t *_t32a, char *outBuffer,
}
if(maxNum > 0x7FFFFFFF) {
// Where maxNum is a huge value, take special care to get correct output
/* Where maxNum is a huge value, take special care to get correct output */
maxNum >>= 8;
for(i=0; i<nelements; i++) {
outarray[i] = _t32a[i]/maxNum;
......@@ -912,7 +902,6 @@ exportPayload(np_ctxt_t *npctxt, HashBucket *myBucket, int direction,
char *outBuffer, int *outBufferBegin,
int *outBufferMax) {
int len, payloadLen;
//u_int16_t t16;
if(direction == 0)
len = myBucket->src2dstPayloadLen;
......@@ -943,17 +932,19 @@ exportPayload(np_ctxt_t *npctxt, HashBucket *myBucket, int direction,
break;
}
//t16 = theTemplate->templateId;
//copyInt16(t16, outBuffer, outBufferBegin, outBufferMax);
//t16 = payloadLen;
//copyInt16(t16, outBuffer, outBufferBegin, outBufferMax);
/*
t16 = theTemplate->templateId;
copyInt16(t16, outBuffer, outBufferBegin, outBufferMax);
t16 = payloadLen;
copyInt16(t16, outBuffer, outBufferBegin, outBufferMax);
*/
if(payloadLen > 0)
copyLen(direction == 0 ? myBucket->src2dstPayload : myBucket->dst2srcPayload,
payloadLen,
outBuffer, outBufferBegin, outBufferMax);
// Ensure that the proper number of bytes are output
/* Ensure that the proper number of bytes are output */
payloadLen = PAYLOAD_EXCERPT_MAX-payloadLen;
while(payloadLen-- > 0)
copyInt8(0,outBuffer,outBufferBegin,outBufferMax);
......@@ -985,8 +976,8 @@ static void handleTemplate(np_ctxt_t *npctxt, V9TemplateId *theTemplate,
copyInt16(t16, outBuffer, outBufferBegin, outBufferMax);
if(npctxt->netFlowVersion == 0x0a && theTemplate->templateId > 0x7FFF) {
// If template ID is over 0x7FFF, then we also must output an enterprise
// ID for the IPFIX format.
/* If template ID is over 0x7FFF, then we also must output an enterprise
* ID for the IPFIX format. */
copyInt32(npctxt->enterpriseId, outBuffer, outBufferBegin, outBufferMax);
}
}
......@@ -1184,9 +1175,11 @@ static void handleTemplate(np_ctxt_t *npctxt, V9TemplateId *theTemplate,
case 60: /* IP_PROTOCOL_VERSION */
copyInt8(4, outBuffer, outBufferBegin, outBufferMax); /* FIX */
break;
//case 61:
// copyInt8(direction, outBuffer, outBufferBegin, outBufferMax); /* FIX */
// break;
/*
case 61:
copyInt8(direction, outBuffer, outBufferBegin, outBufferMax); / * FIX * /
break;
*/
case 64:
copyInt32(direction==0?theFlow->optionsIPV6src2dst:theFlow->optionsIPV6dst2src,
outBuffer, outBufferBegin, outBufferMax);
......@@ -1265,48 +1258,48 @@ static void handleTemplate(np_ctxt_t *npctxt, V9TemplateId *theTemplate,
outBuffer, outBufferBegin, outBufferMax);
break;
case 150: // FLOW_START_SECONDS uint32
case 150: /* FLOW_START_SECONDS uint32 */
copyInt32(direction == 1 ? (theFlow->firstSeenRcvd>>32) : (theFlow->firstSeenSent>>32), outBuffer,outBufferBegin,outBufferMax);
break;
case 151: // FLOW_END_SECONDS uint32
case 151: /* FLOW_END_SECONDS uint32 */
copyInt32(direction == 1 ? (theFlow->lastSeenRcvd>>32) : (theFlow->lastSeenSent>>32), outBuffer,outBufferBegin,outBufferMax);
break;
case 152: // FLOW_START_MILLISECONDS uint64
case 152: /* FLOW_START_MILLISECONDS uint64 */
{
u_int32_t msec = (direction == 1 ? (theFlow->firstSeenRcvd&0xFFFFFFFF) : (theFlow->firstSeenSent&0xFFFFFFFF))/TIME_MS;
u_int32_t sec = (direction == 1 ? (theFlow->firstSeenRcvd>>32) : (theFlow->firstSeenSent>>32));
copyInt64((u_int64_t)msec + (u_int64_t)sec*1000ull, outBuffer,outBufferBegin,outBufferMax);
}
break;
case 153: // FLOW_END_MILLISECONDS uint64
case 153: /* FLOW_END_MILLISECONDS uint64 */
{
u_int32_t msec = (direction == 1 ? (theFlow->lastSeenRcvd&0xFFFFFFFF) : (theFlow->lastSeenSent&0xFFFFFFFF))/TIME_MS;
u_int32_t sec = (direction == 1 ? (theFlow->lastSeenRcvd>>32) : (theFlow->lastSeenSent>>32));
copyInt64((u_int64_t)msec + (u_int64_t)sec*1000ull, outBuffer,outBufferBegin,outBufferMax);
}
break;
case 154: // FLOW_START_MICROSECONDS uint64
case 154: /* FLOW_START_MICROSECONDS uint64 */
{
u_int32_t usec = (direction == 1 ? (theFlow->firstSeenRcvd&0xFFFFFFFF) : (theFlow->firstSeenSent&0xFFFFFFFF))/TIME_US;
u_int32_t sec = (direction == 1 ? (theFlow->firstSeenRcvd>>32) : (theFlow->firstSeenSent>>32));
copyInt64((u_int64_t)usec + (u_int64_t)sec*1000000ull, outBuffer,outBufferBegin,outBufferMax);
}
break;
case 155: // FLOW_END_MICROSECONDS uint64
case 155: /* FLOW_END_MICROSECONDS uint64 */
{
u_int32_t usec = (direction == 1 ? (theFlow->lastSeenRcvd&0xFFFFFFFF) : (theFlow->lastSeenSent&0xFFFFFFFF))/TIME_US;
u_int32_t sec = (direction == 1 ? (theFlow->lastSeenRcvd>>32) : (theFlow->lastSeenSent>>32));
copyInt64((u_int64_t)usec + (u_int64_t)sec*1000000ull, outBuffer,outBufferBegin,outBufferMax);
}
break;
case 156: // FLOW_START_NANOSECONDS uint64
case 156: /* FLOW_START_NANOSECONDS uint64 */
{
u_int32_t nsec = (direction == 1 ? (theFlow->firstSeenRcvd&0xFFFFFFFF) : (theFlow->firstSeenSent&0xFFFFFFFF))/TIME_NS;
u_int32_t sec = (direction == 1 ? (theFlow->firstSeenRcvd>>32) : (theFlow->firstSeenSent>>32));
copyInt64((u_int64_t)nsec + (u_int64_t)sec*1000000000ull, outBuffer,outBufferBegin,outBufferMax);
}
break;
case 157: // FLOW_END_NANOSECONDS uint64
case 157: /* FLOW_END_NANOSECONDS uint64 */
{
u_int32_t nsec = (direction == 1 ? (theFlow->lastSeenRcvd&0xFFFFFFFF) : (theFlow->lastSeenSent&0xFFFFFFFF))/TIME_NS;
u_int32_t sec = (direction == 1 ? (theFlow->lastSeenRcvd>>32) : (theFlow->lastSeenSent>>32));
......@@ -1321,13 +1314,13 @@ static void handleTemplate(np_ctxt_t *npctxt, V9TemplateId *theTemplate,
copyInt64(initSniffTime,outBuffer, outBufferBegin, outBufferMax);
}
break;
case 161: // FLOW_DURATION_MILLISECONDS
case 161: /* FLOW_DURATION_MILLISECONDS */
if(direction==0)
copyInt64(msTimeDiff(theFlow->lastSeenSent,theFlow->firstSeenSent),outBuffer, outBufferBegin, outBufferMax);
else
copyInt64(msTimeDiff(theFlow->lastSeenRcvd,theFlow->firstSeenRcvd),outBuffer, outBufferBegin, outBufferMax);
break;
case 162: // FLOW_DURATION_MICROSECONDS
case 162: /* FLOW_DURATION_MICROSECONDS */
if(direction==0)
copyInt64(nsTimeDiff(theFlow->lastSeenSent,theFlow->firstSeenSent),outBuffer, outBufferBegin, outBufferMax);
else
......@@ -1364,8 +1357,8 @@ static void handleTemplate(np_ctxt_t *npctxt, V9TemplateId *theTemplate,
outBuffer, outBufferBegin, outBufferMax);
break;
case 206:
//copyInt64(direction==0?theFlow->src2dstOctetTotalCount:theFlow->dst2srcOctetTotalCount,
// outBuffer, outBufferBegin, outBufferMax);
/*copyInt64(direction==0?theFlow->src2dstOctetTotalCount:theFlow->dst2srcOctetTotalCount,
outBuffer, outBufferBegin, outBufferMax); */
/* For now, then number of octets are only the deltas -- we don't keep exported flows */
copyInt64(direction==0?theFlow->src2dstOctetDeltaCount:theFlow->dst2srcOctetDeltaCount,
outBuffer, outBufferBegin, outBufferMax);
......@@ -1377,16 +1370,16 @@ static void handleTemplate(np_ctxt_t *npctxt, V9TemplateId *theTemplate,
copyInt64(direction==0?theFlow->optionsIPV4src2dst:theFlow->optionsIPV4dst2src,
outBuffer, outBufferBegin, outBufferMax);
break;
case 209: //FIXME int64
case 209: /*FIXME int64 */
copyInt64(0,outBuffer, outBufferBegin, outBufferMax);
break;
case 210: // Padding, always 0
case 210: /* Padding, always 0 */
copyInt8(0,outBuffer, outBufferBegin, outBufferMax);
break;
case FID_HISTOGRAM_PKT_LNGTH: // HISTOGRAM_PKT_LNGTH