Subject: This commit fix sequence number in ipfix header. And it display number of exported data records in statistics Origin: softflowd-0.9.9-7-g3f8e0fc Upstream-Author: Hitoshi Irino Date: Sun Sep 28 20:23:07 2014 +0900 --- a/configure.ac +++ b/configure.ac @@ -93,7 +93,8 @@ AC_SEARCH_LIBS(socket, socket) AC_CHECK_LIB(pcap, pcap_open_live) -AC_CHECK_FUNCS(closefrom daemon setresuid setreuid setresgid setgid strlcpy strlcat strsep htobe64 htonll) +AC_CHECK_FUNCS(closefrom daemon setresuid setreuid setresgid setgid strlcpy strlcat strsep) +AC_CHECK_DECLS([htobe64, htonll]) AC_CHECK_TYPES([u_int64_t, int64_t, uint64_t, u_int32_t, int32_t, uint32_t]) AC_CHECK_TYPES([u_int16_t, int16_t, uint16_t, u_int8_t, int8_t, uint8_t]) --- a/ipfix.c +++ b/ipfix.c @@ -28,7 +28,7 @@ #include "treetype.h" #include "softflowd.h" -#if defined (HAVE_HTONLL) && !defined (HAVE_HTOBE64) +#if defined (HAVE_DECL_HTONLL) && !defined (HAVE_DECL_HTOBE64) #define htobe64 htonll #endif #define JAN_1970 2208988800UL /* 1970 - 1900 in seconds */ @@ -343,7 +343,7 @@ option_data.c.set_id = htons(IPFIX_SOFTFLOWD_OPTION_TEMPLATE_ID); option_data.c.length = htons(sizeof(option_data)); option_data.scope_pid = htonl((u_int32_t)option->meteringProcessId); -#if defined (_BSD_SOURCE) && defined (HAVE_ENDIAN_H) || defined (HAVE_HTOBE64) || defined (HAVE_HTONLL) +#if defined(htobe64) || defined(HAVE_DECL_HTOBE64) option_data.systemInitTimeMilliseconds = htobe64((u_int64_t)system_boot_time->tv_sec * 1000 + (u_int64_t)system_boot_time->tv_usec / 1000); #endif option_data.samplingAlgorithm = htons(PSAMP_selectorAlgorithm_count); @@ -406,22 +406,22 @@ dt[0]->u32.end = dt[1]->u32.end = htonl(flow->flow_last.tv_sec); } -#if defined (_BSD_SOURCE) && defined (HAVE_ENDIAN_H) || defined (HAVE_HTOBE64) || defined (HAVE_HTONLL) +#if defined(htobe64) || defined(HAVE_DECL_HTOBE64) else if (param->time_format == 'm') { /* milliseconds */ dt[0]->u64.start = dt[1]->u64.start = htobe64((u_int64_t)flow->flow_start.tv_sec * 1000 + (u_int64_t)flow->flow_start.tv_usec / 1000); dt[0]->u64.end = dt[1]->u64.end = htobe64((u_int64_t)flow->flow_last.tv_sec * 1000 + (u_int64_t)flow->flow_last.tv_usec / 1000); } else if (param->time_format == 'M') { /* microseconds */ - dt[0]->u64.start = dt[1]->u64.start = - htobe64(((u_int64_t)(flow->flow_start.tv_sec + JAN_1970) << 32) + (u_int64_t)((flow->flow_start.tv_usec << 32)/ 1e6)); - dt[0]->u64.end = dt[1]->u64.end = - htobe64(((u_int64_t)(flow->flow_last.tv_sec + JAN_1970) << 32) + (u_int64_t)((flow->flow_start.tv_usec << 32)/ 1e6)); + dt[0]->u64.start = dt[1]->u64.start = + htobe64(((u_int64_t)flow->flow_start.tv_sec + JAN_1970) << 32 | (u_int32_t)(((u_int64_t)flow->flow_start.tv_usec << 32) / 1e6)); + dt[0]->u64.end = dt[1]->u64.end = + htobe64(((u_int64_t)flow->flow_last.tv_sec + JAN_1970) << 32 | (u_int32_t)(((u_int64_t)flow->flow_last.tv_usec << 32) / 1e6)); } else if (param->time_format == 'n') { /* nanoseconds */ - dt[0]->u64.start = dt[1]->u64.start = - htobe64(((u_int64_t)(flow->flow_start.tv_sec + JAN_1970) << 32) + (u_int64_t)((flow->flow_start.tv_usec * 1000 << 32)/ 1e9)); - dt[0]->u64.end = dt[1]->u64.end = - htobe64(((u_int64_t)(flow->flow_last.tv_sec + JAN_1970) << 32) + (u_int64_t)((flow->flow_start.tv_usec * 1000 << 32)/ 1e9)); + dt[0]->u64.start = dt[1]->u64.start = + htobe64(((u_int64_t)flow->flow_start.tv_sec + JAN_1970) << 32 | (u_int32_t)(((u_int64_t)flow->flow_start.tv_usec << 32) / 1e9)); + dt[0]->u64.end = dt[1]->u64.end = + htobe64(((u_int64_t)flow->flow_last.tv_sec + JAN_1970) << 32 | (u_int32_t)(((u_int64_t)flow->flow_last.tv_usec << 32) / 1e9)); } #endif else { @@ -483,10 +483,12 @@ u_int offset, last_af, i, j, num_packets, inc, last_valid; socklen_t errsz; int err, r; + u_int records; u_char packet[IPFIX_SOFTFLOWD_MAX_PACKET_SIZE]; struct timeval *system_boot_time = ¶m->system_boot_time; u_int64_t *flows_exported = ¶m->flows_exported; u_int64_t *packets_sent = ¶m->packets_sent; + u_int64_t *records_sent = ¶m->records_sent; struct OPTION *option = ¶m->option; gettimeofday(&now, NULL); @@ -532,6 +534,7 @@ dh = NULL; last_af = 0; + records = 0; for (i = 0; i + j < num_flows; i++) { if (dh == NULL || flows[i + j]->af != last_af) { if (dh != NULL) { @@ -568,6 +571,7 @@ offset = last_valid; break; } + records += (u_int)r; offset += inc; dh->length += inc; last_valid = 0; /* Don't clobber this header now */ @@ -590,7 +594,8 @@ dh->length = htons(dh->length); } ipfix->length = htons(offset); - ipfix->sequence = htonl(*packets_sent + num_packets + 1); + *records_sent += records; + ipfix->sequence = htonl((u_int32_t)(*records_sent & 0x00000000ffffffff)); if (verbose_flag) logit(LOG_DEBUG, "Sending flow packet len = %d", offset); --- a/netflow1.c +++ b/netflow1.c @@ -82,6 +82,7 @@ if (j >= NF1_MAXFLOWS - 1) { if (verbose_flag) logit(LOG_DEBUG, "Sending flow packet len = %d", offset); + param->records_sent += hdr->flows; hdr->flows = htons(hdr->flows); errsz = sizeof(err); getsockopt(nfsock, SOL_SOCKET, SO_ERROR, @@ -157,6 +158,7 @@ if (j != 0) { if (verbose_flag) logit(LOG_DEBUG, "Sending flow packet len = %d", offset); + param->records_sent += hdr->flows; hdr->flows = htons(hdr->flows); errsz = sizeof(err); getsockopt(nfsock, SOL_SOCKET, SO_ERROR, --- a/netflow5.c +++ b/netflow5.c @@ -82,6 +82,7 @@ if (j >= NF5_MAXFLOWS - 1) { if (verbose_flag) logit(LOG_DEBUG, "Sending flow packet len = %d", offset); + param->records_sent += hdr->flows; hdr->flows = htons(hdr->flows); errsz = sizeof(err); getsockopt(nfsock, SOL_SOCKET, SO_ERROR, @@ -164,6 +165,7 @@ if (verbose_flag) logit(LOG_DEBUG, "Sending v5 flow packet len = %d", offset); + param->records_sent += hdr->flows; hdr->flows = htons(hdr->flows); errsz = sizeof(err); getsockopt(nfsock, SOL_SOCKET, SO_ERROR, --- a/netflow9.c +++ b/netflow9.c @@ -473,8 +473,9 @@ /* Finalise last header */ dh->c.length = htons(dh->c.length); } + param->records_sent += nf9->flows; nf9->flows = htons(nf9->flows); - nf9->package_sequence = htonl(*packets_sent + num_packets + 1); + nf9->package_sequence = htonl((u_int32_t)((*packets_sent + num_packets + 1) & 0x00000000ffffffff)); if (verbose_flag) logit(LOG_DEBUG, "Sending flow packet len = %d", offset); --- a/softflowd.c +++ b/softflowd.c @@ -989,8 +989,8 @@ ft->param.non_ip_packets + ft->param.bad_packets, ft->param.non_ip_packets, ft->param.bad_packets); fprintf(out, "Flows expired: %"PRIu64" (%"PRIu64" forced)\n", ft->param.flows_expired, ft->param.flows_force_expired); - fprintf(out, "Flows exported: %"PRIu64" in %"PRIu64" packets (%"PRIu64" failures)\n", - ft->param.flows_exported, ft->param.packets_sent, ft->param.flows_dropped); + fprintf(out, "Flows exported: %"PRIu64" (%"PRIu64" records) in %"PRIu64" packets (%"PRIu64" failures)\n", + ft->param.flows_exported, ft->param.records_sent, ft->param.packets_sent, ft->param.flows_dropped); if (pcap_stats(pcap, &ps) == 0) { fprintf(out, "Packets received by libpcap: %lu\n", --- a/softflowd.h +++ b/softflowd.h @@ -114,6 +114,7 @@ u_int64_t flows_dropped; /* # of flows dropped */ u_int64_t flows_force_expired; /* # of flows forced out */ u_int64_t packets_sent; /* # netflow packets sent */ + u_int64_t records_sent; /* # netflow records sent */ struct STATISTIC duration; /* Flow duration */ struct STATISTIC octets; /* Bytes (bidir) */ struct STATISTIC packets; /* Packets (bidir) */