]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
resolved: always take a timestamp when first seeing a packet
authorLennart Poettering <lennart@poettering.net>
Wed, 28 Oct 2020 12:46:26 +0000 (13:46 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 16 Dec 2020 13:20:49 +0000 (14:20 +0100)
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
src/resolve/resolved-dns-stream.c
src/resolve/resolved-dns-transaction.c
src/resolve/resolved-manager.c

index 0c804d6d2bef62d018d46e851481d09bde569267..4dba96b3b86a70f6f14669ff01400f0aacabd496 100644 (file)
@@ -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;
index 1aab0899347bf41bfc47a5369fa1377276d0d1f9..cf5057ddf09e4848e655225cee716676de77e515 100644 (file)
@@ -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;
index 60e8e94e63e80053cad85905b036b2c341c3065d..b20a61a4018be8be7c8ce8d255bccee09a6f0a3c 100644 (file)
@@ -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:
index 81d043a3fa0c2a9e395c6cc44d14678df92bbd1d..cc684841693333ff098de7cd611fd4f02f2e5e72 100644 (file)
@@ -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) {