Skip to content

sent.sent_time - received.time yields negative results #1952

@FelixZY

Description

@FelixZY

Brief description

I'm trying to make performance measures of DNS queries. When using the sent_time property, the resulting time measure will end up negative at times.

Environment

  • Scapy version: 2.4.0, 2.4.1, 2.4.2, 2.4.3rc1
  • Python version: 3.7
  • Operating System: Ubuntu 18.04.2 LTS

How to reproduce

The problem is not consistent but tends to appear a few times per run when running the 16 "jobs" produced by the following data set:

dns_server: 8.8.8.8, 8.8.4.4, 1.1.1.1, 1.0.0.1
host: google.com, facebook.com
record: A, AAAA

Code used for query and time measurement
ans, unans = sr(
    IP(
        dst=job.dns_server
    )
    / UDP()
    / DNS(
        rd=1,
        qd=DNSQR(
            qname=job.host,
            qtype=job.record
        )
    ),
    retry=0,
    timeout=job.timeout.total_seconds(),
    verbose=False
)

query = ans[0][0]
answer = ans[0][1]

sent_time = datetime.fromtimestamp(query.sent_time)
response_time = datetime.fromtimestamp(answer.time)
rtt = response_time - sent_time

if rtt < timedelta(0):
    logger.warning(unindent(f"""Negative time for job!
    |Job: ({job})
    |
    |query.sent_time: {sent_time}
    |   timestamp: {query.sent_time}
    |
    |query.time: {datetime.fromtimestamp(query.time)}
    |   timestamp: {query.time}
    |
    |answer.time: {response_time}
    |   timestamp: {answer.time}
    |
    |rtt: {rtt.total_seconds()}
    |"""))

Actual result

2019-03-28 17:52:21 +0100 [WARNING](worker#25375): Negative time for job!
Job: (HoardJob(dns_server='8.8.4.4', host='facebook.com', record='A', timeout=datetime.timedelta(microseconds=500000)))

query.sent_time: 2019-03-28 17:52:21.329890
   timestamp: 1553791941.3298903

query.time: 2019-03-28 17:52:21.224104
   timestamp: 1553791941.224104

answer.time: 2019-03-28 17:52:21.294609
   timestamp: 1553791941.2946088

rtt: -0.035281

Expected result

  • query.sent_time < answer.time
  • rtt > 0
  • query.sent_time=query.time (Possibly? Not sure what the distinction is supposed to be)

Edit: For future reference as I found this information hard to find at the time of writing:

time should be set when the packet is created (or dissected), whereas sent_time should be when it is sent (@gpotter2)

Related resources

I believe #1791 may be related. However, this issue appears for 2.4.0 as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions