Package: softflowd / 0.9.9-5

cherry-pick.softflowd-0.9.9-7-g3f8e0fc.this-commit-fix-sequence-number-in-ipfix-header.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
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 <https://github.com/irino/softflowd/commit/softflowd-0.9.9-7-g3f8e0fc>
Upstream-Author: Hitoshi Irino <hitoshi.irino@gmail.com>
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 = &param->system_boot_time;
 	u_int64_t *flows_exported = &param->flows_exported;
 	u_int64_t *packets_sent = &param->packets_sent;
+	u_int64_t *records_sent = &param->records_sent;
 	struct OPTION *option = &param->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) */