Bugzilla – Attachment 2072 Details for
Bug 1923
periodic packet sampling function
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
sampling fuction and 2 bug fix
softflowd.c_sampling.diff (text/plain), 7.75 KB, created by
Hitoshi Irino
on 2011-07-31 16:04:10 AEST
(
hide
)
Description:
sampling fuction and 2 bug fix
Filename:
MIME Type:
Creator:
Hitoshi Irino
Created:
2011-07-31 16:04:10 AEST
Size:
7.75 KB
patch
obsolete
># HG changeset patch ># User Hitoshi Irino <irino@sfc.wide.ad.jp> ># Date 1311808510 -32400 ># Node ID 1824e1a34cecf0574a214c626803a4a50257ba47 ># Parent b35a000870ccd0dfa868dcf1fcdc676c45cc8210 >update 3 points >1) I added periodic sampling function to control load. >2) I fixed a problem missing time fields in IPv6 template. >3) I swapped llu keyword in printf to PRIu64 to quiet compile warning in 64bit CPU environment. > >diff -r b35a000870cc -r 1824e1a34cec netflow9.c >--- a/netflow9.c Mon Nov 01 12:03:41 2010 +1100 >+++ b/netflow9.c Thu Jul 28 08:15:10 2011 +0900 >@@ -79,7 +79,7 @@ > #define NF9_IP_PROTOCOL_VERSION 60 > > /* Stuff pertaining to the templates that softflowd uses */ >-#define NF9_SOFTFLOWD_TEMPLATE_NRECORDS 11 >+#define NF9_SOFTFLOWD_TEMPLATE_NRECORDS 13 > struct NF9_SOFTFLOWD_TEMPLATE { > struct NF9_TEMPLATE_FLOWSET_HEADER h; > struct NF9_TEMPLATE_FLOWSET_RECORD r[NF9_SOFTFLOWD_TEMPLATE_NRECORDS]; >@@ -167,10 +167,10 @@ > v6_template.r[4].length = htons(4); > v6_template.r[5].type = htons(NF9_IN_PACKETS); > v6_template.r[5].length = htons(4); >- v4_template.r[6].type = htons(NF9_IF_INDEX_IN); >- v4_template.r[6].length = htons(4); >- v4_template.r[7].type = htons(NF9_IF_INDEX_OUT); >- v4_template.r[7].length = htons(4); >+ v6_template.r[6].type = htons(NF9_IF_INDEX_IN); >+ v6_template.r[6].length = htons(4); >+ v6_template.r[7].type = htons(NF9_IF_INDEX_OUT); >+ v6_template.r[7].length = htons(4); > v6_template.r[8].type = htons(NF9_L4_SRC_PORT); > v6_template.r[8].length = htons(2); > v6_template.r[9].type = htons(NF9_L4_DST_PORT); >diff -r b35a000870cc -r 1824e1a34cec softflowd.c >--- a/softflowd.c Mon Nov 01 12:03:41 2010 +1100 >+++ b/softflowd.c Thu Jul 28 08:15:10 2011 +0900 >@@ -68,6 +68,7 @@ > int linktype; > int fatal; > int want_v6; >+ int sample; > }; > > /* Describes a datalink header and how to extract v4/v6 frames from it */ >@@ -270,7 +271,7 @@ > snprintf(ftime, sizeof(ftime), "%s", > format_time(flow->flow_last.tv_sec)); > >- snprintf(buf, sizeof(buf), "seq:%llu [%s]:%hu <> [%s]:%hu proto:%u " >+ snprintf(buf, sizeof(buf), "seq:%"PRIu64" [%s]:%hu <> [%s]:%hu proto:%u " > "octets>:%u packets>:%u octets<:%u packets<:%u " > "start:%s.%03ld finish:%s.%03ld tcp>:%02x tcp<:%02x " > "flowlabel>:%08x flowlabel<:%08x ", >@@ -298,7 +299,7 @@ > inet_ntop(flow->af, &flow->addr[1], addr2, sizeof(addr2)); > > snprintf(buf, sizeof(buf), >- "seq:%llu [%s]:%hu <> [%s]:%hu proto:%u", >+ "seq:%"PRIu64" [%s]:%hu <> [%s]:%hu proto:%u", > flow->flow_seq, > addr1, ntohs(flow->port[0]), addr2, ntohs(flow->port[1]), > (int)flow->protocol); >@@ -811,7 +812,7 @@ > > if (verbose_flag) > logit(LOG_DEBUG, >- "Queuing flow seq:%llu (%p) for expiry " >+ "Queuing flow seq:%"PRIu64" (%p) for expiry " > "reason %d", expiry->flow->flow_seq, > expiry->flow, expiry->reason); > >@@ -976,13 +977,13 @@ > struct pcap_stat ps; > > fprintf(out, "Number of active flows: %d\n", ft->num_flows); >- fprintf(out, "Packets processed: %llu\n", ft->total_packets); >- fprintf(out, "Fragments: %llu\n", ft->frag_packets); >- fprintf(out, "Ignored packets: %llu (%llu non-IP, %llu too short)\n", >+ fprintf(out, "Packets processed: %"PRIu64"\n", ft->total_packets); >+ fprintf(out, "Fragments: %"PRIu64"\n", ft->frag_packets); >+ fprintf(out, "Ignored packets: %"PRIu64" (%"PRIu64" non-IP, %"PRIu64" too short)\n", > ft->non_ip_packets + ft->bad_packets, ft->non_ip_packets, ft->bad_packets); >- fprintf(out, "Flows expired: %llu (%llu forced)\n", >+ fprintf(out, "Flows expired: %"PRIu64" (%"PRIu64" forced)\n", > ft->flows_expired, ft->flows_force_expired); >- fprintf(out, "Flows exported: %llu in %llu packets (%llu failures)\n", >+ fprintf(out, "Flows exported: %"PRIu64" in %"PRIu64" packets (%"PRIu64" failures)\n", > ft->flows_exported, ft->packets_sent, ft->flows_dropped); > > if (pcap_stats(pcap, &ps) == 0) { >@@ -1007,16 +1008,16 @@ > > fprintf(out, "\n"); > fprintf(out, "Expired flow reasons:\n"); >- fprintf(out, " tcp = %9llu tcp.rst = %9llu " >- "tcp.fin = %9llu\n", ft->expired_tcp, ft->expired_tcp_rst, >+ fprintf(out, " tcp = %9"PRIu64" tcp.rst = %9"PRIu64" " >+ "tcp.fin = %9"PRIu64"\n", ft->expired_tcp, ft->expired_tcp_rst, > ft->expired_tcp_fin); >- fprintf(out, " udp = %9llu icmp = %9llu " >- "general = %9llu\n", ft->expired_udp, ft->expired_icmp, >+ fprintf(out, " udp = %9"PRIu64" icmp = %9"PRIu64" " >+ "general = %9"PRIu64"\n", ft->expired_udp, ft->expired_icmp, > ft->expired_general); >- fprintf(out, " maxlife = %9llu\n", ft->expired_maxlife); >- fprintf(out, "over 2 GiB = %9llu\n", ft->expired_overbytes); >- fprintf(out, " maxflows = %9llu\n", ft->expired_maxflows); >- fprintf(out, " flushed = %9llu\n", ft->expired_flush); >+ fprintf(out, " maxlife = %9"PRIu64"\n", ft->expired_maxlife); >+ fprintf(out, "over 2 GiB = %9"PRIu64"\n", ft->expired_overbytes); >+ fprintf(out, " maxflows = %9"PRIu64"\n", ft->expired_maxflows); >+ fprintf(out, " flushed = %9"PRIu64"\n", ft->expired_flush); > > fprintf(out, "\n"); > >@@ -1027,7 +1028,7 @@ > pe = getprotobynumber(i); > snprintf(proto, sizeof(proto), "%s (%d)", > pe != NULL ? pe->p_name : "Unknown", i); >- fprintf(out, " %17s: %14llu %12llu %8.2fs " >+ fprintf(out, " %17s: %14"PRIu64" %12"PRIu64" %8.2fs " > "%10.2fs\n", proto, > ft->octets_pp[i], > ft->packets_pp[i], >@@ -1052,12 +1053,12 @@ > fprintf(out, "ACTIVE %s\n", format_flow(expiry->flow)); > if ((long int) expiry->expires_at - now < 0) { > fprintf(out, >- "EXPIRY EVENT for flow %llu now%s\n", >+ "EXPIRY EVENT for flow %"PRIu64" now%s\n", > expiry->flow->flow_seq, > expiry->expires_at == 0 ? " (FORCED)": ""); > } else { > fprintf(out, >- "EXPIRY EVENT for flow %llu in %ld seconds\n", >+ "EXPIRY EVENT for flow %"PRIu64" in %ld seconds\n", > expiry->flow->flow_seq, > (long int) expiry->expires_at - now); > } >@@ -1128,6 +1129,10 @@ > struct CB_CTXT *cb_ctxt = (struct CB_CTXT *)user_data; > struct timeval tv; > >+ if (cb_ctxt->sample && cb_ctxt->ft->total_packets % cb_ctxt->sample > 0) { >+ cb_ctxt->ft->total_packets++; >+ return; >+ } > s = datalink_check(cb_ctxt->linktype, pkt, phdr->caplen, &af); > if (s < 0 || (!cb_ctxt->want_v6 && af == AF_INET6)) { > cb_ctxt->ft->non_ip_packets++; >@@ -1681,6 +1686,7 @@ > extern int optind; > int ch, dontfork_flag, linktype, ctlsock, i, err, always_v6, r; > int stop_collection_flag, exit_request, hoplimit; >+ unsigned int sample; > pcap_t *pcap = NULL; > struct sockaddr_storage dest; > struct FLOWTRACK flowtrack; >@@ -1706,8 +1712,9 @@ > ctlsock_path = DEFAULT_CTLSOCK; > dontfork_flag = 0; > always_v6 = 0; >+ sample = 0; > >- while ((ch = getopt(argc, argv, "6hdDL:T:i:r:f:t:n:m:p:c:v:")) != -1) { >+ while ((ch = getopt(argc, argv, "6hdDL:T:i:r:f:t:n:m:p:c:v:s:")) != -1) { > switch (ch) { > case '6': > always_v6 = 1; >@@ -1807,6 +1814,12 @@ > } > target.dialect = &nf[i]; > break; >+ case 's': >+ sample = atoi(optarg); >+ if (sample < 2) { >+ sample = 0; >+ } >+ break; > default: > fprintf(stderr, "Invalid commandline option.\n"); > usage(); >@@ -1847,7 +1860,7 @@ > } else { > FILE *pidfile; > >- daemon(0, 0); >+ r = daemon(0, 0); > loginit(PROGNAME, 0); > > if ((pidfile = fopen(pidfile_path, "w")) == NULL) { >@@ -1880,6 +1893,7 @@ > cb_ctxt.ft = &flowtrack; > cb_ctxt.linktype = linktype; > cb_ctxt.want_v6 = target.dialect->v6_capable || always_v6; >+ cb_ctxt.sample = sample; > > for (r = 0; graceful_shutdown_request == 0; r = 0) { > /* >@@ -1925,6 +1939,11 @@ > pcap_geterr(pcap)); > break; > } else if (r == 0) { >+ if (capfile == NULL) { >+ logit(LOG_DEBUG, "Continueing after " >+ "pcap EOF"); >+ continue; >+ } > logit(LOG_NOTICE, "Shutting down after " > "pcap EOF"); > graceful_shutdown_request = 1;
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 1923
: 2072