1
0
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:
dmiller
2024-06-26 21:54:28 +00:00
parent 136e1c6ed7
commit 7b20a38099
5 changed files with 44 additions and 26 deletions

View File

@@ -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;
}