mirror of
https://github.com/nmap/nmap.git
synced 2025-12-06 04:31:29 +00:00
Minor efficiencies: avoid multiple expansions of function calls in TIMEVAL_* macros
This commit is contained in:
16
FPEngine.cc
16
FPEngine.cc
@@ -2041,7 +2041,8 @@ int FPHost6::schedule() {
|
||||
}
|
||||
|
||||
/* Check if the probe timedout */
|
||||
if (TIMEVAL_SUBTRACT(now, this->fp_probes[i].getTimeSent()) >= this->rto) {
|
||||
struct timeval sent = this->fp_probes[i].getTimeSent();
|
||||
if (TIMEVAL_SUBTRACT(now, sent) >= this->rto) {
|
||||
|
||||
/* If we have reached the maximum number of retransmissions, mark the
|
||||
* probe as failed. Otherwise, schedule its transmission. */
|
||||
@@ -2099,10 +2100,11 @@ int FPHost6::schedule() {
|
||||
continue;
|
||||
}
|
||||
|
||||
struct timeval sent = this->fp_probes[i].getTimeSent();
|
||||
/* If there is some timed probe for which we have already scheduled its
|
||||
* retransmission but it hasn't been sent yet, break the loop. We don't
|
||||
* have to worry about retransmitting these probes yet.*/
|
||||
if (this->fp_probes[i].getTimeSent().tv_sec == 0)
|
||||
if (sent.tv_sec == 0)
|
||||
return OP_SUCCESS;
|
||||
|
||||
/* If we got a total timeout for any of the timed probes, we shouldn't
|
||||
@@ -2118,7 +2120,7 @@ int FPHost6::schedule() {
|
||||
* time out (max retransmissions done and still no answer) then mark
|
||||
* it as such. Otherwise, count it so we can retransmit the whole
|
||||
* group of timed probes later if appropriate. */
|
||||
if (TIMEVAL_SUBTRACT(now, this->fp_probes[i].getTimeSent()) >= this->rto) {
|
||||
if (TIMEVAL_SUBTRACT(now, sent) >= this->rto) {
|
||||
if (o.debugging > 3) {
|
||||
log_write(LOG_PLAIN, "[%s] timed probe %d (%s) timedout\n",
|
||||
this->target_host->targetipstr(), i, this->fp_probes[i].getProbeID());
|
||||
@@ -2318,11 +2320,13 @@ int FPHost6::callback(const u8 *pkt, size_t pkt_len, const struct timeval *tv) {
|
||||
|
||||
/* See if the received packet is a response to a probe */
|
||||
if (this->fp_probes[i].isResponse(rcvd)) {
|
||||
struct timeval now, time_sent;
|
||||
struct timeval time_sent = this->fp_probes[i].getTimeSent();
|
||||
assert(time_sent.tv_sec > 0);
|
||||
struct timeval now;
|
||||
|
||||
gettimeofday(&now, NULL);
|
||||
this->fp_responses[i] = new FPResponse(this->fp_probes[i].getProbeID(),
|
||||
pkt, pkt_len, fp_probes[i].getTimeSent(), *tv);
|
||||
pkt, pkt_len, time_sent, *tv);
|
||||
this->fp_probes[i].incrementReplies();
|
||||
match_found = true;
|
||||
|
||||
@@ -2341,8 +2345,6 @@ int FPHost6::callback(const u8 *pkt, size_t pkt_len, const struct timeval *tv) {
|
||||
}
|
||||
this->probes_answered++;
|
||||
/* Recompute the Retransmission Timeout based on this new RTT observation. */
|
||||
time_sent = this->fp_probes[i].getTimeSent();
|
||||
assert(time_sent.tv_sec > 0);
|
||||
this->update_RTO(TIMEVAL_SUBTRACT(now, time_sent), this->fp_probes[i].getRetransmissions() != 0);
|
||||
break;
|
||||
}
|
||||
|
||||
18
idle_scan.cc
18
idle_scan.cc
@@ -1058,12 +1058,18 @@ static int idlescan_countopen2(struct idle_proxy_info *proxy,
|
||||
|
||||
openports = -1;
|
||||
tries = 0;
|
||||
TIMEVAL_MSEC_ADD(probe_times[0], start, MAX(50, (target->to.srtt * 3 / 4) / 1000));
|
||||
TIMEVAL_MSEC_ADD(probe_times[1], start, target->to.srtt / 1000 );
|
||||
TIMEVAL_MSEC_ADD(probe_times[2], end, MAX(75, (2 * target->to.srtt +
|
||||
target->to.rttvar) / 1000));
|
||||
TIMEVAL_MSEC_ADD(probe_times[3], end, MIN(4000, (2 * target->to.srtt +
|
||||
(target->to.rttvar << 2 )) / 1000));
|
||||
|
||||
int tmp = (target->to.srtt * 3) / (4 * 1000);
|
||||
tmp = MAX(50, tmp);
|
||||
TIMEVAL_MSEC_ADD(probe_times[0], start, tmp);
|
||||
tmp = target->to.srtt / 1000;
|
||||
TIMEVAL_MSEC_ADD(probe_times[1], start, tmp);
|
||||
tmp = (2 * target->to.srtt + target->to.rttvar) / 1000;
|
||||
tmp = MAX(75, tmp);
|
||||
TIMEVAL_MSEC_ADD(probe_times[2], end, tmp);
|
||||
tmp = (2 * target->to.srtt + (target->to.rttvar << 2 )) / 1000;
|
||||
tmp = MIN(4000, tmp);
|
||||
TIMEVAL_MSEC_ADD(probe_times[3], end, tmp);
|
||||
|
||||
do {
|
||||
if (tries == 2)
|
||||
|
||||
@@ -301,17 +301,18 @@ bool keyWasPressed()
|
||||
option. */
|
||||
if (o.stats_interval != 0.0) {
|
||||
struct timeval now;
|
||||
time_t usec_interval = o.stats_interval * 1000000;
|
||||
|
||||
gettimeofday(&now, NULL);
|
||||
if (stats_time.tv_sec == 0) {
|
||||
/* Initialize the scheduled stats time. */
|
||||
stats_time = *o.getStartTime();
|
||||
TIMEVAL_ADD(stats_time, stats_time, (time_t) (o.stats_interval * 1000000));
|
||||
TIMEVAL_ADD(stats_time, stats_time, usec_interval);
|
||||
}
|
||||
|
||||
if (TIMEVAL_AFTER(now, stats_time)) {
|
||||
/* Advance to the next print time. */
|
||||
TIMEVAL_ADD(stats_time, stats_time, (time_t) (o.stats_interval * 1000000));
|
||||
TIMEVAL_ADD(stats_time, stats_time, usec_interval);
|
||||
/* If it's still in the past, catch it up to the present,
|
||||
* plus half a second to avoid double-printing without any progress. */
|
||||
if (TIMEVAL_AFTER(now, stats_time))
|
||||
|
||||
15
osscan2.cc
15
osscan2.cc
@@ -1276,8 +1276,9 @@ bool HostOsScan::nextTimeout(HostOsScanStats *hss, struct timeval *when) const {
|
||||
memset(&probe_to, 0, sizeof(probe_to));
|
||||
memset(&earliest_to, 0, sizeof(earliest_to));
|
||||
|
||||
unsigned long usec_to = timeProbeTimeout(hss);
|
||||
for (probeI = hss->probesActive.begin(); probeI != hss->probesActive.end(); probeI++) {
|
||||
TIMEVAL_ADD(probe_to, (*probeI)->sent, timeProbeTimeout(hss));
|
||||
TIMEVAL_ADD(probe_to, (*probeI)->sent, usec_to);
|
||||
if (firstgood || TIMEVAL_BEFORE(probe_to, earliest_to)) {
|
||||
earliest_to = probe_to;
|
||||
firstgood = false;
|
||||
@@ -1435,6 +1436,7 @@ void HostOsScan::updateActiveSeqProbes(HostOsScanStats *hss) {
|
||||
assert(hss);
|
||||
std::list<OFProbe *>::iterator probeI, nxt;
|
||||
OFProbe *probe = NULL;
|
||||
long usec_to = timeProbeTimeout(hss);
|
||||
|
||||
for (probeI = hss->probesActive.begin(); probeI != hss->probesActive.end(); probeI = nxt) {
|
||||
nxt = probeI;
|
||||
@@ -1442,7 +1444,7 @@ void HostOsScan::updateActiveSeqProbes(HostOsScanStats *hss) {
|
||||
probe = *probeI;
|
||||
|
||||
/* Is the probe timedout? */
|
||||
if (TIMEVAL_SUBTRACT(now, probe->sent) > (long) timeProbeTimeout(hss)) {
|
||||
if (TIMEVAL_SUBTRACT(now, probe->sent) > usec_to) {
|
||||
hss->removeActiveProbe(probeI);
|
||||
assert(stats->num_probes_active > 0);
|
||||
stats->num_probes_active--;
|
||||
@@ -1517,13 +1519,14 @@ void HostOsScan::updateActiveTUIProbes(HostOsScanStats *hss) {
|
||||
assert(hss);
|
||||
std::list<OFProbe *>::iterator probeI, nxt;
|
||||
OFProbe *probe = NULL;
|
||||
long usec_to = timeProbeTimeout(hss);
|
||||
|
||||
for (probeI = hss->probesActive.begin(); probeI != hss->probesActive.end(); probeI = nxt) {
|
||||
nxt = probeI;
|
||||
nxt++;
|
||||
probe = *probeI;
|
||||
|
||||
if (TIMEVAL_SUBTRACT(now, probe->sent) > (long) timeProbeTimeout(hss)) {
|
||||
if (TIMEVAL_SUBTRACT(now, probe->sent) > usec_to) {
|
||||
if (probe->tryno >= 3) {
|
||||
/* The probe is expired. */
|
||||
hss->removeActiveProbe(probeI);
|
||||
@@ -1579,8 +1582,9 @@ bool HostOsScan::hostSendOK(HostOsScanStats *hss, struct timeval *when) const {
|
||||
TIMEVAL_MSEC_ADD(earliest_to, now, 10000);
|
||||
|
||||
/* Any timeouts coming up? */
|
||||
unsigned long msec_to = timeProbeTimeout(hss) / 1000;
|
||||
for (probeI = hss->probesActive.begin(); probeI != hss->probesActive.end(); probeI++) {
|
||||
TIMEVAL_MSEC_ADD(probe_to, (*probeI)->sent, timeProbeTimeout(hss) / 1000);
|
||||
TIMEVAL_MSEC_ADD(probe_to, (*probeI)->sent, msec_to);
|
||||
if (TIMEVAL_BEFORE(probe_to, earliest_to)) {
|
||||
earliest_to = probe_to;
|
||||
}
|
||||
@@ -1652,8 +1656,9 @@ bool HostOsScan::hostSeqSendOK(HostOsScanStats *hss, struct timeval *when) const
|
||||
TIMEVAL_MSEC_ADD(earliest_to, now, 10000);
|
||||
|
||||
/* Any timeouts coming up? */
|
||||
unsigned long msec_to = timeProbeTimeout(hss) / 1000;
|
||||
for (probeI = hss->probesActive.begin(); probeI != hss->probesActive.end(); probeI++) {
|
||||
TIMEVAL_MSEC_ADD(probe_to, (*probeI)->sent, timeProbeTimeout(hss) / 1000);
|
||||
TIMEVAL_MSEC_ADD(probe_to, (*probeI)->sent, msec_to);
|
||||
if (TIMEVAL_BEFORE(probe_to, earliest_to)) {
|
||||
earliest_to = probe_to;
|
||||
}
|
||||
|
||||
@@ -298,9 +298,13 @@ void GroupScanStats::probeSent(unsigned int nbytes) {
|
||||
Recall that these have effect only when --min-rate or --max-rate is
|
||||
given. */
|
||||
|
||||
static time_t max_rate_add = o.max_packet_send_rate != 0.0 ?
|
||||
(1000000.0 / o.max_packet_send_rate) : 0;
|
||||
static time_t min_rate_add = o.min_packet_send_rate != 0.0 ?
|
||||
(1000000.0 / o.min_packet_send_rate) : 0;
|
||||
|
||||
if (o.max_packet_send_rate != 0.0)
|
||||
TIMEVAL_ADD(send_no_earlier_than, send_no_earlier_than,
|
||||
(time_t) (1000000.0 / o.max_packet_send_rate));
|
||||
TIMEVAL_ADD(send_no_earlier_than, send_no_earlier_than, max_rate_add);
|
||||
/* Allow send_no_earlier_than to slip into the past. This allows the sending
|
||||
scheduler to catch up and make up for delays in other parts of the scan
|
||||
engine. If we were to update send_no_earlier_than to the present the
|
||||
@@ -314,8 +318,7 @@ void GroupScanStats::probeSent(unsigned int nbytes) {
|
||||
present to prevent that. */
|
||||
send_no_later_than = USI->now;
|
||||
}
|
||||
TIMEVAL_ADD(send_no_later_than, send_no_later_than,
|
||||
(time_t) (1000000.0 / o.min_packet_send_rate));
|
||||
TIMEVAL_ADD(send_no_later_than, send_no_later_than, min_rate_add);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -338,7 +341,7 @@ bool GroupScanStats::sendOK(struct timeval *when) const {
|
||||
recentsends = USI->gstats->probes_sent - USI->gstats->probes_sent_at_last_wait;
|
||||
if (recentsends > 0 &&
|
||||
(USI->scantype == CONNECT_SCAN || USI->ptech.connecttcpscan || !pcap_recv_timeval_valid())) {
|
||||
int to_ms = (int) MAX(to.srtt * .75 / 1000, 50);
|
||||
int to_ms = MAX(to.srtt * 3 / 4000, 50);
|
||||
if (TIMEVAL_MSEC_SUBTRACT(USI->now, last_wait) > to_ms)
|
||||
return false;
|
||||
}
|
||||
@@ -592,10 +595,11 @@ bool HostScanStats::sendOK(struct timeval *when) const {
|
||||
TIMEVAL_MSEC_ADD(earliest_to, USI->now, 10000);
|
||||
|
||||
// Any timeouts coming up?
|
||||
unsigned long msec_to = probeTimeout() / 1000;
|
||||
for (probeI = probes_outstanding.begin(); probeI != probes_outstanding.end();
|
||||
probeI++) {
|
||||
if (!(*probeI)->timedout) {
|
||||
TIMEVAL_MSEC_ADD(probe_to, (*probeI)->sent, probeTimeout() / 1000);
|
||||
TIMEVAL_MSEC_ADD(probe_to, (*probeI)->sent, msec_to);
|
||||
if (TIMEVAL_BEFORE(probe_to, earliest_to)) {
|
||||
earliest_to = probe_to;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user