From fd9260276c6be0f0e94318476ecd6a24aef4890b Mon Sep 17 00:00:00 2001 From: david Date: Sat, 7 Apr 2012 08:07:38 +0000 Subject: [PATCH] Don't set max parallelism when only --min-paralellism is given. Setting --min-parallelism without also setting --max-parallelism would force the max parallelism to the same value. So, for example, --min-parallelism=1 would also limit the max parallelism to 1. This patch, based on one by Chris Woodbury, allows the max parallelism to rise above this minimum, up to the maximum defined by each scan phase. --- CHANGELOG | 3 +++ NmapOps.cc | 4 ---- idle_scan.cc | 4 ++-- scan_engine.cc | 11 ++--------- service_scan.cc | 5 ++++- timing.cc | 6 +++--- 6 files changed, 14 insertions(+), 19 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index c6dc9ef0b..023d08a1f 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,8 @@ # Nmap Changelog ($Id$); -*-text-*- +o Setting --min-parallelism by itself no longer forces the maximum + parallelism to the same value. [Chris Woodbury, David Fifield] + o [NSE] Added an error message indicating script failure, when Nmap is being run in non verbose/debug mode. [Patrik Karlsson] diff --git a/NmapOps.cc b/NmapOps.cc index 741993084..07ff45005 100644 --- a/NmapOps.cc +++ b/NmapOps.cc @@ -533,10 +533,6 @@ dialog where you can start NPF if you have administrator privileges."; fatal("Sorry -- IPv6 support is currently only available for TCP, UDP, and SCTP port scans and list scan (-sL). OS detection, random targets and decoys are also not supported with IPv6. Further support is under consideration."); } - /* Prevent performance values from getting out of whack */ - if (min_parallelism > max_parallelism) - max_parallelism = min_parallelism; - if(ipoptions && osscan) error("WARNING: Ip options are NOT used while OS scanning!"); diff --git a/idle_scan.cc b/idle_scan.cc index 49f8f0884..828a5f3cb 100644 --- a/idle_scan.cc +++ b/idle_scan.cc @@ -304,8 +304,8 @@ static void initialize_idleproxy(struct idle_proxy_info *proxy, char *proxyName, initialize_proxy_struct(proxy); initialize_timeout_info(&proxy->host.to); - proxy->max_groupsz = (o.max_parallelism)? o.max_parallelism : 100; - proxy->min_groupsz = (o.min_parallelism)? o.min_parallelism : 4; + proxy->min_groupsz = o.min_parallelism ? o.min_parallelism : 4; + proxy->max_groupsz = MAX(proxy->min_groupsz, o.max_parallelism ? o.max_parallelism : 100); proxy->max_senddelay = 100000; Strncpy(name, proxyName, sizeof(name)); diff --git a/scan_engine.cc b/scan_engine.cc index d0e7b965b..e5caf2e46 100644 --- a/scan_engine.cc +++ b/scan_engine.cc @@ -5904,15 +5904,8 @@ void pos_scan(Target *target, u16 *portarray, int numports, stype scantype) { memset(&pil, 0, sizeof(pil)); - if (o.max_parallelism) { - ss.max_width = o.max_parallelism; - } else { - ss.max_width = 150; - } - - if (o.min_parallelism) { - ss.min_width = o.min_parallelism; - } else ss.min_width = 1; + ss.min_width = o.min_parallelism ? o.min_parallelism : 1; + ss.max_width = MAX(ss.min_width, o.max_parallelism ? o.max_parallelism : 150); ss.initial_packet_width = box(ss.min_width, ss.max_width, ss.initial_packet_width); ss.numqueries_ideal = ss.initial_packet_width; diff --git a/service_scan.cc b/service_scan.cc index c2b22a675..4c24f61c8 100644 --- a/service_scan.cc +++ b/service_scan.cc @@ -1880,7 +1880,10 @@ ServiceGroup::ServiceGroup(vector &Targets, AllProbes *AP) { if (o.timing_level == 4) desired_par = 30; if (o.timing_level >= 5) desired_par = 40; // TODO: Come up with better ways to determine ideal_parallelism - ideal_parallelism = box(o.min_parallelism, o.max_parallelism? o.max_parallelism : 100, desired_par); + int min_par, max_par; + min_par = o.min_parallelism; + max_par = MAX(min_par, o.max_parallelism ? o.max_parallelism : 100); + ideal_parallelism = box(min_par, max_par, desired_par); } ServiceGroup::~ServiceGroup() { diff --git a/timing.cc b/timing.cc index 2e1dda4d9..c9d848c35 100644 --- a/timing.cc +++ b/timing.cc @@ -295,9 +295,9 @@ void ultra_timing_vals::drop_group(unsigned in_flight, void scan_performance_vars::init() { /* TODO: I should revisit these values for tuning. They should probably at least be affected by -T. */ - low_cwnd = MAX(o.min_parallelism, 1); - max_cwnd = o.max_parallelism? o.max_parallelism : 300; - group_initial_cwnd = box(o.min_parallelism, max_cwnd, 10); + low_cwnd = o.min_parallelism ? o.min_parallelism : 1; + max_cwnd = MAX(low_cwnd, o.max_parallelism ? o.max_parallelism : 300); + group_initial_cwnd = box(low_cwnd, max_cwnd, 10); host_initial_cwnd = group_initial_cwnd; slow_incr = 1; /* The congestion window grows faster with more aggressive timing. */