From 6355a1bebe49691ac70cfed3964fe3ac0ab564e0 Mon Sep 17 00:00:00 2001 From: d33tah Date: Wed, 23 Jul 2014 14:43:12 +0000 Subject: [PATCH] Revert my unfinished refactoring commit I pushed by mistake. --- global_structures.h | 19 ----------- osscan2.cc | 44 +++++++++++++++---------- scan_engine.cc | 78 ++++++++++++++++++++++++++++----------------- 3 files changed, 76 insertions(+), 65 deletions(-) diff --git a/global_structures.h b/global_structures.h index ed3f68d71..fdb591b2b 100644 --- a/global_structures.h +++ b/global_structures.h @@ -238,7 +238,6 @@ struct FingerPrintDB { /* Based on TCP congestion control techniques from RFC2581. */ struct ultra_timing_vals { -private: double cwnd; /* Congestion window - in probes */ int ssthresh; /* The threshold above which mode is changed from slow start to congestion avoidance */ @@ -257,24 +256,6 @@ private: struct timeval last_drop; double cc_scale(const struct scan_performance_vars *perf); -public: - ultra_timing_vals(double cwnd_arg, int ssthresh_arg, struct timeval *now) { - cwnd = cwnd_arg; - ssthresh = ssthresh_arg; - num_replies_expected = 0; - num_replies_received = 0; - num_updates = 0; - if (now == NULL) - gettimeofday(&last_drop, NULL); - else - last_drop = *now; - } - double getCwnd() const { return cwnd; } - int getSsthresh() const { return ssthresh; } - int getNumUpdates() const { return num_updates; } - struct timeval getLastDrop() const { return last_drop; } - void incrementNumUpdates() { num_updates++; } - void incrementNumRepliesExpected() { num_replies_expected++; } void ack(const struct scan_performance_vars *perf, double scale = 1.0); void drop(unsigned in_flight, const struct scan_performance_vars *perf, const struct timeval *now); diff --git a/osscan2.cc b/osscan2.cc index a22e0f0bd..78ff04b69 100644 --- a/osscan2.cc +++ b/osscan2.cc @@ -999,9 +999,7 @@ const char *OFProbe::typestr() { * Implementation of class HostOsScanStats * ******************************************************************************/ -HostOsScanStats::HostOsScanStats(Target * t) : timing(perf.host_initial_cwnd, - perf.initial_ssthresh, NULL) { - +HostOsScanStats::HostOsScanStats(Target * t) { int i; target = t; @@ -1018,6 +1016,14 @@ HostOsScanStats::HostOsScanStats(Target * t) : timing(perf.host_initial_cwnd, sendDelayMs = MAX(o.scan_delay, OS_PROBE_DELAY); lastProbeSent = now; + /* Timing */ + timing.cwnd = perf.host_initial_cwnd; + timing.ssthresh = perf.initial_ssthresh; /* Will be reduced if any packets are dropped anyway */ + timing.num_replies_expected = 0; + timing.num_replies_received = 0; + timing.num_updates = 0; + gettimeofday(&timing.last_drop, NULL); + for (i = 0; i < NUM_FPTESTS; i++) FPtests[i] = NULL; for (i = 0; i < 6; i++) { @@ -1294,11 +1300,11 @@ void HostOsScan::adjust_times(HostOsScanStats *hss, OFProbe *probe, struct timev adjust_timeouts2(&(probe->sent), rcvdtime, &(stats->to)); } - stats->timing.incrementNumRepliesExpected(); - stats->timing.incrementNumUpdates(); + stats->timing.num_replies_expected++; + stats->timing.num_updates++; - hss->timing.incrementNumRepliesExpected(); - hss->timing.incrementNumUpdates(); + hss->timing.num_replies_expected++; + hss->timing.num_updates++; /* Notice a drop if 1. We get a response to a retransmitted probe (meaning the first reply was @@ -1314,9 +1320,9 @@ void HostOsScan::adjust_times(HostOsScanStats *hss, OFProbe *probe, struct timev hss->target->targetipstr()); } } - if (TIMEVAL_AFTER(probe->sent, hss->timing.getLastDrop())) + if (TIMEVAL_AFTER(probe->sent, hss->timing.last_drop)) hss->timing.drop(hss->numProbesActive(), &perf, &now); - if (TIMEVAL_AFTER(probe->sent, stats->timing.getLastDrop())) + if (TIMEVAL_AFTER(probe->sent, stats->timing.last_drop)) stats->timing.drop_group(stats->num_probes_active, &perf, &now); } @@ -1533,7 +1539,7 @@ bool HostOsScan::hostSendOK(HostOsScanStats *hss, struct timeval *when) { } } - if (hss->timing.getCwnd() >= hss->numProbesActive() + .5) { + if (hss->timing.cwnd >= hss->numProbesActive() + .5) { if (when) *when = now; return true; @@ -1565,7 +1571,7 @@ bool HostOsScan::hostSendOK(HostOsScanStats *hss, struct timeval *when) { if (tdiff < 0) { earliest_to = sendTime; } else { - if (tdiff > 0 && hss->timing.getCwnd() > hss->numProbesActive() + .5) { + if (tdiff > 0 && hss->timing.cwnd > hss->numProbesActive() + .5) { earliest_to = sendTime; } } @@ -1606,7 +1612,7 @@ bool HostOsScan::hostSeqSendOK(HostOsScanStats *hss, struct timeval *when) { return false; } - if (hss->timing.getCwnd() >= hss->numProbesActive() + .5) { + if (hss->timing.cwnd >= hss->numProbesActive() + .5) { if (when) *when = now; return true; @@ -1636,7 +1642,7 @@ bool HostOsScan::hostSeqSendOK(HostOsScanStats *hss, struct timeval *when) { if (tdiff < 0) { earliest_to = sendTime; } else { - if (tdiff > 0 && hss->timing.getCwnd() > hss->numProbesActive() + .5) { + if (tdiff > 0 && hss->timing.cwnd > hss->numProbesActive() + .5) { earliest_to = sendTime; } } @@ -2216,8 +2222,14 @@ int HostOsScan::send_closedudp_probe(HostOsScanStats *hss, * Implementation of class ScanStats * ******************************************************************************/ -ScanStats::ScanStats() : timing(perf.host_initial_cwnd, perf.initial_ssthresh, - NULL) { +ScanStats::ScanStats() { + /* init timing val */ + timing.cwnd = perf.group_initial_cwnd; + timing.ssthresh = perf.initial_ssthresh; /* Will be reduced if any packets are dropped anyway */ + timing.num_replies_expected = 0; + timing.num_replies_received = 0; + timing.num_updates = 0; + gettimeofday(&timing.last_drop, NULL); initialize_timeout_info(&to); @@ -2231,7 +2243,7 @@ bool ScanStats::sendOK() { if (num_probes_sent - num_probes_sent_at_last_wait >= 50) return false; - if (timing.getCwnd() < num_probes_active + 0.5) + if (timing.cwnd < num_probes_active + 0.5) return false; return true; diff --git a/scan_engine.cc b/scan_engine.cc index def523485..afe7b3e04 100644 --- a/scan_engine.cc +++ b/scan_engine.cc @@ -783,6 +783,14 @@ private: /* Whether this is storing timing stats for a whole group or an individual host */ enum ultra_timing_type { TIMING_HOST, TIMING_GROUP }; +/* Initialize the ultra_timing_vals structure timing. The utt must be + TIMING_HOST or TIMING_GROUP. If you happen to have the current + time handy, pass it as now, otherwise pass NULL */ +static void init_ultra_timing_vals(ultra_timing_vals *timing, + enum ultra_timing_type utt, + int num_hosts_in_group, + struct ultra_scan_performance_vars *perf, + struct timeval *now); /* Take a buffer, buf, of size bufsz (64 bytes is sufficient) and writes a short description of the probe (arg1) into buf. It also returns @@ -1052,12 +1060,11 @@ bool ConnectScanInfo::clearSD(int sd) { } } -GroupScanStats::GroupScanStats(UltraScanInfo *UltraSI) : timing( - UltraSI->perf.group_initial_cwnd, UltraSI->perf.initial_ssthresh, - &UltraSI->now) { +GroupScanStats::GroupScanStats(UltraScanInfo *UltraSI) { memset(&latestip, 0, sizeof(latestip)); memset(&timeout, 0, sizeof(timeout)); USI = UltraSI; + init_ultra_timing_vals(&timing, TIMING_GROUP, USI->numIncompleteHosts(), &(USI->perf), &USI->now); initialize_timeout_info(&to); /* Default timout should be much lower for arp */ if (USI->ping_scan_arp) @@ -1192,7 +1199,7 @@ bool GroupScanStats::sendOK(struct timeval *when) { return true; } - if (timing.getCwnd() >= num_probes_active + 0.5) { + if (timing.cwnd >= num_probes_active + 0.5) { if (when) *when = USI->now; return true; @@ -1233,9 +1240,7 @@ static bool pingprobe_is_appropriate(const UltraScanInfo *USI, return false; } -HostScanStats::HostScanStats(Target *t, UltraScanInfo *UltraSI) : timing( - UltraSI->perf.host_initial_cwnd, UltraSI->perf.initial_ssthresh, - &UltraSI->now) { +HostScanStats::HostScanStats(Target *t, UltraScanInfo *UltraSI) { target = t; USI = UltraSI; next_portidx = 0; @@ -1259,6 +1264,7 @@ HostScanStats::HostScanStats(Target *t, UltraScanInfo *UltraSI) : timing( ports_finished = 0; numprobes_sent = 0; memset(&completiontime, 0, sizeof(completiontime)); + init_ultra_timing_vals(&timing, TIMING_HOST, 1, &(USI->perf), &USI->now); bench_tryno = 0; memset(&sdn, 0, sizeof(sdn)); sdn.last_boost = USI->now; @@ -1332,9 +1338,7 @@ unsigned long HostScanStats::probeExpireTime(const UltraProbe *probe) { (call it again if they do). when will become now if it returns true. */ bool HostScanStats::sendOK(struct timeval *when) { - struct ultra_timing_vals tmng = ultra_timing_vals(USI->perf.group_initial_cwnd, - USI->perf.initial_ssthresh, - &USI->now); + struct ultra_timing_vals tmng; std::list::iterator probeI; struct timeval probe_to, earliest_to, sendTime; long tdiff; @@ -1377,7 +1381,7 @@ bool HostScanStats::sendOK(struct timeval *when) { } getTiming(&tmng); - if (tmng.getCwnd() >= num_probes_active + .5 && + if (tmng.cwnd >= num_probes_active + .5 && (freshPortsLeft() || num_probes_waiting_retransmit || !retry_stack.empty())) { if (when) *when = USI->now; @@ -1414,7 +1418,7 @@ bool HostScanStats::sendOK(struct timeval *when) { earliest_to = sendTime; } else { getTiming(&tmng); - if (tdiff > 0 && tmng.getCwnd() > num_probes_active + .5) { + if (tdiff > 0 && tmng.cwnd > num_probes_active + .5) { earliest_to = sendTime; } } @@ -2048,6 +2052,24 @@ int determineScanGroupSize(int hosts_scanned_so_far, return groupsize; } +/* Initialize the ultra_timing_vals structure timing. The utt must be + TIMING_HOST or TIMING_GROUP. If you happen to have the current + time handy, pass it as now, otherwise pass NULL */ +static void init_ultra_timing_vals(ultra_timing_vals *timing, + enum ultra_timing_type utt, + int num_hosts_in_group, + struct ultra_scan_performance_vars *perf, + struct timeval *now) { + timing->cwnd = (utt == TIMING_HOST) ? perf->host_initial_cwnd : perf->group_initial_cwnd; + timing->ssthresh = perf->initial_ssthresh; /* Will be reduced if any packets are dropped anyway */ + timing->num_replies_expected = 0; + timing->num_replies_received = 0; + timing->num_updates = 0; + if (now) + timing->last_drop = *now; + else gettimeofday(&timing->last_drop, NULL); +} + /* Returns the next probe to try against target. Supports many different types of probes (see probespec structure). Returns 0 and fills in pspec if there is a new probe, -1 if there are none @@ -2352,11 +2374,11 @@ static void ultrascan_adjust_timing(UltraScanInfo *USI, HostScanStats *hss, struct timeval *rcvdtime) { int ping_magnifier = (probe->isPing()) ? USI->perf.ping_magnifier : 1; - USI->gstats->timing.incrementNumRepliesExpected(); - USI->gstats->timing.incrementNumUpdates(); + USI->gstats->timing.num_replies_expected++; + USI->gstats->timing.num_updates++; - hss->timing.incrementNumRepliesExpected(); - hss->timing.incrementNumUpdates(); + hss->timing.num_replies_expected++; + hss->timing.num_updates++; /* Notice a drop if 1) We get a response to a retransmitted probe (meaning the first reply was @@ -2367,9 +2389,9 @@ static void ultrascan_adjust_timing(UltraScanInfo *USI, HostScanStats *hss, if (o.debugging > 1) log_write(LOG_PLAIN, "Ultrascan DROPPED %sprobe packet to %s detected\n", probe->isPing() ? "PING " : "", hss->target->targetipstr()); // Drops often come in big batches, but we only want one decrease per batch. - if (TIMEVAL_AFTER(probe->sent, hss->timing.getLastDrop())) + if (TIMEVAL_AFTER(probe->sent, hss->timing.last_drop)) hss->timing.drop(hss->num_probes_active, &USI->perf, &USI->now); - if (TIMEVAL_AFTER(probe->sent, USI->gstats->timing.getLastDrop())) + if (TIMEVAL_AFTER(probe->sent, USI->gstats->timing.last_drop)) USI->gstats->timing.drop_group(USI->gstats->num_probes_active, &USI->perf, &USI->now); } /* If !probe->isPing() and rcvdtime == NULL, do nothing. */ @@ -2677,15 +2699,15 @@ void HostScanStats::getTiming(struct ultra_timing_vals *tmng) { } /* Otherwise, use the global cwnd stats if it has sufficient responses */ - if (USI->gstats->timing.getNumUpdates() > 1) { + if (USI->gstats->timing.num_updates > 1) { *tmng = USI->gstats->timing; return; } - *tmng = ultra_timing_vals(USI->perf.host_initial_cwnd, - USI->perf.initial_ssthresh, NULL); - /* Last resort is to use canned values */ + tmng->cwnd = USI->perf.host_initial_cwnd; + tmng->ssthresh = USI->perf.initial_ssthresh; + tmng->num_updates = 0; return; } @@ -4105,19 +4127,15 @@ static void printAnyStats(UltraScanInfo *USI) { std::list::iterator hostI; HostScanStats *hss; - struct timeval now; - gettimeofday(&now, NULL); - struct ultra_timing_vals hosttm = ultra_timing_vals(USI->perf.group_initial_cwnd, - USI->perf.initial_ssthresh, - &now); + struct ultra_timing_vals hosttm; /* Print debugging states for each host being scanned */ if (o.debugging > 2) { log_write(LOG_PLAIN, "**TIMING STATS** (%.4fs): IP, probes active/freshportsleft/retry_stack/outstanding/retranwait/onbench, cwnd/ssthresh/delay, timeout/srtt/rttvar/\n", o.TimeSinceStart()); log_write(LOG_PLAIN, " Groupstats (%d/%d incomplete): %d/*/*/*/*/* %.2f/%d/* %d/%d/%d\n", USI->numIncompleteHosts(), USI->numInitialHosts(), - USI->gstats->num_probes_active, USI->gstats->timing.getCwnd(), - USI->gstats->timing.getSsthresh(), USI->gstats->to.timeout, + USI->gstats->num_probes_active, USI->gstats->timing.cwnd, + USI->gstats->timing.ssthresh, USI->gstats->to.timeout, USI->gstats->to.srtt, USI->gstats->to.rttvar); if (o.debugging > 3) { @@ -4130,7 +4148,7 @@ static void printAnyStats(UltraScanInfo *USI) { (int) hss->retry_stack.size(), hss->num_probes_outstanding(), hss->num_probes_waiting_retransmit, (int) hss->probe_bench.size(), - hosttm.getCwnd(), hosttm.getSsthresh(), hss->sdn.delayms, + hosttm.cwnd, hosttm.ssthresh, hss->sdn.delayms, hss->probeTimeout(), hss->target->to.srtt, hss->target->to.rttvar); }