1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-06 04:31:29 +00:00

Use global timing structs in osscan2.

This commit is contained in:
david
2011-12-31 21:59:51 +00:00
parent b04380207a
commit 24e02a9a1a
2 changed files with 18 additions and 59 deletions

View File

@@ -148,7 +148,7 @@ u16 prbWindowSz[] = { 1, 63, 4, 4, 16, 512, 3, 128, 256, 1024, 31337, 32768, 655
static struct timeval now; static struct timeval now;
/* Global to store performance info */ /* Global to store performance info */
os_scan_performance_vars_t perf; struct scan_performance_vars perf;
/****************************************************************************** /******************************************************************************
@@ -321,12 +321,12 @@ static void init_perf_values() {
perf.max_cwnd = o.max_parallelism? o.max_parallelism : 300; perf.max_cwnd = o.max_parallelism? o.max_parallelism : 300;
perf.group_initial_cwnd = box(o.min_parallelism, perf.max_cwnd, 10); perf.group_initial_cwnd = box(o.min_parallelism, perf.max_cwnd, 10);
perf.host_initial_cwnd = perf.group_initial_cwnd; perf.host_initial_cwnd = perf.group_initial_cwnd;
perf.quick_incr = 1; perf.slow_incr = 1;
perf.cc_incr = 1; perf.ca_incr = 1;
perf.initial_ccthresh = 50; perf.initial_ssthresh = 50;
perf.group_drop_cwnd_divisor = 2.0; perf.group_drop_cwnd_divisor = 2.0;
perf.group_drop_ccthresh_divisor = (o.timing_level < 4)? 2.0 : 1.5; perf.group_drop_ssthresh_divisor = (o.timing_level < 4)? 2.0 : 1.5;
perf.host_drop_ccthresh_divisor = (o.timing_level < 4)? 2.0 : 1.5; perf.host_drop_ssthresh_divisor = (o.timing_level < 4)? 2.0 : 1.5;
} }
@@ -957,7 +957,7 @@ HostOsScanStats::HostOsScanStats(Target * t) {
/* Timing */ /* Timing */
timing.cwnd = perf.host_initial_cwnd; timing.cwnd = perf.host_initial_cwnd;
timing.ccthresh = perf.initial_ccthresh; /* Will be reduced if any packets are dropped anyway */ timing.ssthresh = perf.initial_ssthresh; /* Will be reduced if any packets are dropped anyway */
timing.num_updates = 0; timing.num_updates = 0;
gettimeofday(&timing.last_drop, NULL); gettimeofday(&timing.last_drop, NULL);
@@ -1244,33 +1244,33 @@ void HostOsScan::adjust_times(HostOsScanStats *hss, OFProbe *probe, struct timev
if (probe->tryno > 0 || !rcvdtime) { if (probe->tryno > 0 || !rcvdtime) {
if (TIMEVAL_SUBTRACT(probe->sent, hss->timing.last_drop) > 0) { if (TIMEVAL_SUBTRACT(probe->sent, hss->timing.last_drop) > 0) {
hss->timing.cwnd = perf.low_cwnd; hss->timing.cwnd = perf.low_cwnd;
hss->timing.ccthresh = (int) MAX(hss->numProbesActive() / perf.host_drop_ccthresh_divisor, 2); hss->timing.ssthresh = (int) MAX(hss->numProbesActive() / perf.host_drop_ssthresh_divisor, 2);
hss->timing.last_drop = now; hss->timing.last_drop = now;
} }
if (TIMEVAL_SUBTRACT(probe->sent, stats->timing.last_drop) > 0) { if (TIMEVAL_SUBTRACT(probe->sent, stats->timing.last_drop) > 0) {
stats->timing.cwnd = MAX(perf.low_cwnd, stats->timing.cwnd / perf.group_drop_cwnd_divisor); stats->timing.cwnd = MAX(perf.low_cwnd, stats->timing.cwnd / perf.group_drop_cwnd_divisor);
stats->timing.ccthresh = (int) MAX(stats->num_probes_active / perf.group_drop_ccthresh_divisor, 2); stats->timing.ssthresh = (int) MAX(stats->num_probes_active / perf.group_drop_ssthresh_divisor, 2);
stats->timing.last_drop = now; stats->timing.last_drop = now;
} }
} else { } else {
/* Good news -- got a response to first try. Increase window as /* Good news -- got a response to first try. Increase window as
appropriate. */ appropriate. */
if (hss->timing.cwnd <= hss->timing.ccthresh) { if (hss->timing.cwnd <= hss->timing.ssthresh) {
/* In quick start mode */ /* In quick start mode */
hss->timing.cwnd += perf.quick_incr; hss->timing.cwnd += perf.slow_incr;
} else { } else {
/* Congestion control mode */ /* Congestion control mode */
hss->timing.cwnd += perf.cc_incr / hss->timing.cwnd; hss->timing.cwnd += perf.ca_incr / hss->timing.cwnd;
} }
if (hss->timing.cwnd > perf.max_cwnd) if (hss->timing.cwnd > perf.max_cwnd)
hss->timing.cwnd = perf.max_cwnd; hss->timing.cwnd = perf.max_cwnd;
if (stats->timing.cwnd <= stats->timing.ccthresh) { if (stats->timing.cwnd <= stats->timing.ssthresh) {
/* In quick start mode */ /* In quick start mode */
stats->timing.cwnd += perf.quick_incr; stats->timing.cwnd += perf.slow_incr;
} else { } else {
/* Congestion control mode */ /* Congestion control mode */
stats->timing.cwnd += perf.cc_incr / stats->timing.cwnd; stats->timing.cwnd += perf.ca_incr / stats->timing.cwnd;
} }
if (stats->timing.cwnd > perf.max_cwnd) if (stats->timing.cwnd > perf.max_cwnd)
stats->timing.cwnd = perf.max_cwnd; stats->timing.cwnd = perf.max_cwnd;
@@ -2177,7 +2177,7 @@ int HostOsScan::send_closedudp_probe(HostOsScanStats *hss,
ScanStats::ScanStats() { ScanStats::ScanStats() {
/* init timing val */ /* init timing val */
timing.cwnd = perf.group_initial_cwnd; timing.cwnd = perf.group_initial_cwnd;
timing.ccthresh = perf.initial_ccthresh; /* Will be reduced if any packets are dropped anyway */ timing.ssthresh = perf.initial_ssthresh; /* Will be reduced if any packets are dropped anyway */
timing.num_updates = 0; timing.num_updates = 0;
gettimeofday(&timing.last_drop, NULL); gettimeofday(&timing.last_drop, NULL);

View File

@@ -133,47 +133,6 @@ using namespace std;
* TYPE AND STRUCTURE DEFINITIONS * * TYPE AND STRUCTURE DEFINITIONS *
******************************************************************************/ ******************************************************************************/
/* Performance tuning variable. */
typedef struct os_scan_performance_vars {
int low_cwnd; /* The lowest cwnd (congestion window) allowed */
int host_initial_cwnd; /* Initial congestion window for ind. hosts */
int group_initial_cwnd; /* Initial congestion window for all hosts as a group */
int max_cwnd; /* We should never have more than this many probes
outstanding */
int quick_incr; /* How many probes are incremented for each response
in quick start mode */
int cc_incr; /* How many probes are incremented per (roughly) rtt in
congestion control mode */
int initial_ccthresh;
double group_drop_cwnd_divisor; /* all-host group cwnd divided by this
value if any packet drop occurs */
double group_drop_ccthresh_divisor; /* used to drop the group ccthresh when
any drop occurs */
double host_drop_ccthresh_divisor; /* used to drop the host ccthresh when
any drop occurs */
} os_scan_performance_vars_t;
/* Some of the algorithms used here are TCP congestion control techniques from RFC2581. */
typedef struct osscan_timing_vals {
/* Congestion window - in probes */
double cwnd;
/* The threshold after which mode is changed from QUICK_START to
CONGESTION_CONTROL */
int ccthresh;
/* Number of updates to this utv (generally packet receipts ) */
int num_updates;
/* Last time values were adjusted for a drop (you usually only want
to adjust again based on probes sent after that adjustment so a
sudden batch of drops doesn't destroy timing. Init to now */
struct timeval last_drop;
} osscan_timing_vals_t;
typedef enum OFProbeType { typedef enum OFProbeType {
OFP_UNSET, OFP_UNSET,
@@ -304,7 +263,7 @@ class HostOsScanStats {
/* When the last probe is sent. */ /* When the last probe is sent. */
struct timeval lastProbeSent; struct timeval lastProbeSent;
osscan_timing_vals_t timing; struct ultra_timing_vals timing;
/* Fingerprint of this target. When a scan is completed, it'll /* Fingerprint of this target. When a scan is completed, it'll
* finally be passed to hs->target->FPR->FPs[x]. */ * finally be passed to hs->target->FPR->FPs[x]. */
@@ -348,7 +307,7 @@ class ScanStats {
ScanStats(); ScanStats();
bool sendOK(); /* Returns true if the system says that sending is OK. */ bool sendOK(); /* Returns true if the system says that sending is OK. */
osscan_timing_vals_t timing; struct ultra_timing_vals timing;
struct timeout_info to; /* rtt/timeout info */ struct timeout_info to; /* rtt/timeout info */
int num_probes_active; /* Total number of active probes */ int num_probes_active; /* Total number of active probes */
int num_probes_sent; /* Number of probes sent in total. */ int num_probes_sent; /* Number of probes sent in total. */