From 5777c6130b2d0858df1fa9314e4e8c2441b7c1af Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 28 Oct 2020 13:46:26 +0100 Subject: [PATCH] resolved: always take a timestamp when first seeing a packet This is later useful if we want to adjust the TTLs of packets we want to propagate to clients. --- src/resolve/resolved-dns-packet.h | 1 + src/resolve/resolved-dns-stream.c | 1 + src/resolve/resolved-dns-transaction.c | 5 +---- src/resolve/resolved-manager.c | 2 ++ 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/resolve/resolved-dns-packet.h b/src/resolve/resolved-dns-packet.h index 0c804d6d2be..4dba96b3b86 100644 --- a/src/resolve/resolved-dns-packet.h +++ b/src/resolve/resolved-dns-packet.h @@ -71,6 +71,7 @@ struct DnsPacket { union in_addr_union sender, destination; uint16_t sender_port, destination_port; uint32_t ttl; + usec_t timestamp; /* CLOCK_BOOTTIME (or CLOCK_MONOTONIC if the former doesn't exist) */ /* For support of truncated packets */ DnsPacket *more; diff --git a/src/resolve/resolved-dns-stream.c b/src/resolve/resolved-dns-stream.c index 1aab0899347..cf5057ddf09 100644 --- a/src/resolve/resolved-dns-stream.c +++ b/src/resolve/resolved-dns-stream.c @@ -377,6 +377,7 @@ static int on_stream_io(sd_event_source *es, int fd, uint32_t revents, void *use s->read_packet->family = s->peer.sa.sa_family; s->read_packet->ttl = s->ttl; s->read_packet->ifindex = s->ifindex; + s->read_packet->timestamp = now(clock_boottime_or_monotonic()); if (s->read_packet->family == AF_INET) { s->read_packet->sender.in = s->peer.in.sin_addr; diff --git a/src/resolve/resolved-dns-transaction.c b/src/resolve/resolved-dns-transaction.c index 60e8e94e63e..b20a61a4018 100644 --- a/src/resolve/resolved-dns-transaction.c +++ b/src/resolve/resolved-dns-transaction.c @@ -890,7 +890,6 @@ static int dns_transaction_fix_rcode(DnsTransaction *t) { } void dns_transaction_process_reply(DnsTransaction *t, DnsPacket *p) { - usec_t ts; int r; assert(t); @@ -973,8 +972,6 @@ void dns_transaction_process_reply(DnsTransaction *t, DnsPacket *p) { } } - assert_se(sd_event_now(t->scope->manager->event, clock_boottime_or_monotonic(), &ts) >= 0); - switch (t->scope->protocol) { case DNS_PROTOCOL_DNS: @@ -1039,7 +1036,7 @@ void dns_transaction_process_reply(DnsTransaction *t, DnsPacket *p) { case DNS_PROTOCOL_LLMNR: case DNS_PROTOCOL_MDNS: - dns_scope_packet_received(t->scope, ts - t->start_usec); + dns_scope_packet_received(t->scope, p->timestamp - t->start_usec); break; default: diff --git a/src/resolve/resolved-manager.c b/src/resolve/resolved-manager.c index 81d043a3fa0..cc684841693 100644 --- a/src/resolve/resolved-manager.c +++ b/src/resolve/resolved-manager.c @@ -854,6 +854,8 @@ int manager_recv(Manager *m, int fd, DnsProtocol protocol, DnsPacket **ret) { } else return -EAFNOSUPPORT; + p->timestamp = now(clock_boottime_or_monotonic()); + CMSG_FOREACH(cmsg, &mh) { if (cmsg->cmsg_level == IPPROTO_IPV6) { -- 2.39.5