cherry-pick.softflowd-0.9.9-7-g3f8e0fc.this-commit-fix-sequence-number-in-ipfix-header.patch 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. Subject: This commit fix sequence number in ipfix header. And it display number of exported data records in statistics
  2. Origin: softflowd-0.9.9-7-g3f8e0fc <https://github.com/irino/softflowd/commit/softflowd-0.9.9-7-g3f8e0fc>
  3. Upstream-Author: Hitoshi Irino <hitoshi.irino@gmail.com>
  4. Date: Sun Sep 28 20:23:07 2014 +0900
  5. --- a/configure.ac
  6. +++ b/configure.ac
  7. @@ -93,7 +93,8 @@
  8. AC_SEARCH_LIBS(socket, socket)
  9. AC_CHECK_LIB(pcap, pcap_open_live)
  10. -AC_CHECK_FUNCS(closefrom daemon setresuid setreuid setresgid setgid strlcpy strlcat strsep htobe64 htonll)
  11. +AC_CHECK_FUNCS(closefrom daemon setresuid setreuid setresgid setgid strlcpy strlcat strsep)
  12. +AC_CHECK_DECLS([htobe64, htonll])
  13. AC_CHECK_TYPES([u_int64_t, int64_t, uint64_t, u_int32_t, int32_t, uint32_t])
  14. AC_CHECK_TYPES([u_int16_t, int16_t, uint16_t, u_int8_t, int8_t, uint8_t])
  15. --- a/ipfix.c
  16. +++ b/ipfix.c
  17. @@ -28,7 +28,7 @@
  18. #include "treetype.h"
  19. #include "softflowd.h"
  20. -#if defined (HAVE_HTONLL) && !defined (HAVE_HTOBE64)
  21. +#if defined (HAVE_DECL_HTONLL) && !defined (HAVE_DECL_HTOBE64)
  22. #define htobe64 htonll
  23. #endif
  24. #define JAN_1970 2208988800UL /* 1970 - 1900 in seconds */
  25. @@ -343,7 +343,7 @@
  26. option_data.c.set_id = htons(IPFIX_SOFTFLOWD_OPTION_TEMPLATE_ID);
  27. option_data.c.length = htons(sizeof(option_data));
  28. option_data.scope_pid = htonl((u_int32_t)option->meteringProcessId);
  29. -#if defined (_BSD_SOURCE) && defined (HAVE_ENDIAN_H) || defined (HAVE_HTOBE64) || defined (HAVE_HTONLL)
  30. +#if defined(htobe64) || defined(HAVE_DECL_HTOBE64)
  31. option_data.systemInitTimeMilliseconds = htobe64((u_int64_t)system_boot_time->tv_sec * 1000 + (u_int64_t)system_boot_time->tv_usec / 1000);
  32. #endif
  33. option_data.samplingAlgorithm = htons(PSAMP_selectorAlgorithm_count);
  34. @@ -406,22 +406,22 @@
  35. dt[0]->u32.end = dt[1]->u32.end =
  36. htonl(flow->flow_last.tv_sec);
  37. }
  38. -#if defined (_BSD_SOURCE) && defined (HAVE_ENDIAN_H) || defined (HAVE_HTOBE64) || defined (HAVE_HTONLL)
  39. +#if defined(htobe64) || defined(HAVE_DECL_HTOBE64)
  40. else if (param->time_format == 'm') { /* milliseconds */
  41. dt[0]->u64.start = dt[1]->u64.start =
  42. htobe64((u_int64_t)flow->flow_start.tv_sec * 1000 + (u_int64_t)flow->flow_start.tv_usec / 1000);
  43. dt[0]->u64.end = dt[1]->u64.end =
  44. htobe64((u_int64_t)flow->flow_last.tv_sec * 1000 + (u_int64_t)flow->flow_last.tv_usec / 1000);
  45. } else if (param->time_format == 'M') { /* microseconds */
  46. - dt[0]->u64.start = dt[1]->u64.start =
  47. - htobe64(((u_int64_t)(flow->flow_start.tv_sec + JAN_1970) << 32) + (u_int64_t)((flow->flow_start.tv_usec << 32)/ 1e6));
  48. - dt[0]->u64.end = dt[1]->u64.end =
  49. - htobe64(((u_int64_t)(flow->flow_last.tv_sec + JAN_1970) << 32) + (u_int64_t)((flow->flow_start.tv_usec << 32)/ 1e6));
  50. + dt[0]->u64.start = dt[1]->u64.start =
  51. + 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));
  52. + dt[0]->u64.end = dt[1]->u64.end =
  53. + 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));
  54. } else if (param->time_format == 'n') { /* nanoseconds */
  55. - dt[0]->u64.start = dt[1]->u64.start =
  56. - htobe64(((u_int64_t)(flow->flow_start.tv_sec + JAN_1970) << 32) + (u_int64_t)((flow->flow_start.tv_usec * 1000 << 32)/ 1e9));
  57. - dt[0]->u64.end = dt[1]->u64.end =
  58. - htobe64(((u_int64_t)(flow->flow_last.tv_sec + JAN_1970) << 32) + (u_int64_t)((flow->flow_start.tv_usec * 1000 << 32)/ 1e9));
  59. + dt[0]->u64.start = dt[1]->u64.start =
  60. + 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));
  61. + dt[0]->u64.end = dt[1]->u64.end =
  62. + 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));
  63. }
  64. #endif
  65. else {
  66. @@ -483,10 +483,12 @@
  67. u_int offset, last_af, i, j, num_packets, inc, last_valid;
  68. socklen_t errsz;
  69. int err, r;
  70. + u_int records;
  71. u_char packet[IPFIX_SOFTFLOWD_MAX_PACKET_SIZE];
  72. struct timeval *system_boot_time = &param->system_boot_time;
  73. u_int64_t *flows_exported = &param->flows_exported;
  74. u_int64_t *packets_sent = &param->packets_sent;
  75. + u_int64_t *records_sent = &param->records_sent;
  76. struct OPTION *option = &param->option;
  77. gettimeofday(&now, NULL);
  78. @@ -532,6 +534,7 @@
  79. dh = NULL;
  80. last_af = 0;
  81. + records = 0;
  82. for (i = 0; i + j < num_flows; i++) {
  83. if (dh == NULL || flows[i + j]->af != last_af) {
  84. if (dh != NULL) {
  85. @@ -568,6 +571,7 @@
  86. offset = last_valid;
  87. break;
  88. }
  89. + records += (u_int)r;
  90. offset += inc;
  91. dh->length += inc;
  92. last_valid = 0; /* Don't clobber this header now */
  93. @@ -590,7 +594,8 @@
  94. dh->length = htons(dh->length);
  95. }
  96. ipfix->length = htons(offset);
  97. - ipfix->sequence = htonl(*packets_sent + num_packets + 1);
  98. + *records_sent += records;
  99. + ipfix->sequence = htonl((u_int32_t)(*records_sent & 0x00000000ffffffff));
  100. if (verbose_flag)
  101. logit(LOG_DEBUG, "Sending flow packet len = %d", offset);
  102. --- a/netflow1.c
  103. +++ b/netflow1.c
  104. @@ -82,6 +82,7 @@
  105. if (j >= NF1_MAXFLOWS - 1) {
  106. if (verbose_flag)
  107. logit(LOG_DEBUG, "Sending flow packet len = %d", offset);
  108. + param->records_sent += hdr->flows;
  109. hdr->flows = htons(hdr->flows);
  110. errsz = sizeof(err);
  111. getsockopt(nfsock, SOL_SOCKET, SO_ERROR,
  112. @@ -157,6 +158,7 @@
  113. if (j != 0) {
  114. if (verbose_flag)
  115. logit(LOG_DEBUG, "Sending flow packet len = %d", offset);
  116. + param->records_sent += hdr->flows;
  117. hdr->flows = htons(hdr->flows);
  118. errsz = sizeof(err);
  119. getsockopt(nfsock, SOL_SOCKET, SO_ERROR,
  120. --- a/netflow5.c
  121. +++ b/netflow5.c
  122. @@ -82,6 +82,7 @@
  123. if (j >= NF5_MAXFLOWS - 1) {
  124. if (verbose_flag)
  125. logit(LOG_DEBUG, "Sending flow packet len = %d", offset);
  126. + param->records_sent += hdr->flows;
  127. hdr->flows = htons(hdr->flows);
  128. errsz = sizeof(err);
  129. getsockopt(nfsock, SOL_SOCKET, SO_ERROR,
  130. @@ -164,6 +165,7 @@
  131. if (verbose_flag)
  132. logit(LOG_DEBUG, "Sending v5 flow packet len = %d",
  133. offset);
  134. + param->records_sent += hdr->flows;
  135. hdr->flows = htons(hdr->flows);
  136. errsz = sizeof(err);
  137. getsockopt(nfsock, SOL_SOCKET, SO_ERROR,
  138. --- a/netflow9.c
  139. +++ b/netflow9.c
  140. @@ -473,8 +473,9 @@
  141. /* Finalise last header */
  142. dh->c.length = htons(dh->c.length);
  143. }
  144. + param->records_sent += nf9->flows;
  145. nf9->flows = htons(nf9->flows);
  146. - nf9->package_sequence = htonl(*packets_sent + num_packets + 1);
  147. + nf9->package_sequence = htonl((u_int32_t)((*packets_sent + num_packets + 1) & 0x00000000ffffffff));
  148. if (verbose_flag)
  149. logit(LOG_DEBUG, "Sending flow packet len = %d", offset);
  150. --- a/softflowd.c
  151. +++ b/softflowd.c
  152. @@ -989,8 +989,8 @@
  153. ft->param.non_ip_packets + ft->param.bad_packets, ft->param.non_ip_packets, ft->param.bad_packets);
  154. fprintf(out, "Flows expired: %"PRIu64" (%"PRIu64" forced)\n",
  155. ft->param.flows_expired, ft->param.flows_force_expired);
  156. - fprintf(out, "Flows exported: %"PRIu64" in %"PRIu64" packets (%"PRIu64" failures)\n",
  157. - ft->param.flows_exported, ft->param.packets_sent, ft->param.flows_dropped);
  158. + fprintf(out, "Flows exported: %"PRIu64" (%"PRIu64" records) in %"PRIu64" packets (%"PRIu64" failures)\n",
  159. + ft->param.flows_exported, ft->param.records_sent, ft->param.packets_sent, ft->param.flows_dropped);
  160. if (pcap_stats(pcap, &ps) == 0) {
  161. fprintf(out, "Packets received by libpcap: %lu\n",
  162. --- a/softflowd.h
  163. +++ b/softflowd.h
  164. @@ -114,6 +114,7 @@
  165. u_int64_t flows_dropped; /* # of flows dropped */
  166. u_int64_t flows_force_expired; /* # of flows forced out */
  167. u_int64_t packets_sent; /* # netflow packets sent */
  168. + u_int64_t records_sent; /* # netflow records sent */
  169. struct STATISTIC duration; /* Flow duration */
  170. struct STATISTIC octets; /* Bytes (bidir) */
  171. struct STATISTIC packets; /* Packets (bidir) */