]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
resolve: use correct fd for UDP stub listner 16951/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 4 Sep 2020 14:08:48 +0000 (23:08 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 4 Sep 2020 14:54:35 +0000 (23:54 +0900)
src/resolve/resolved-dns-packet.h
src/resolve/resolved-dns-stub.c
src/resolve/resolved-manager.c

index 56614c4a071756ad76ca59c7f20089fe5a27a166..359cdcfd04af28e92d96748ff5f2225f5d75983c 100644 (file)
@@ -66,6 +66,7 @@ struct DnsPacket {
         DnsResourceRecord *opt;
 
         /* Packet reception metadata */
+        int fd; /* Used by UDP extra DNS stub listners */
         int ifindex;
         int family, ipproto;
         union in_addr_union sender, destination;
index 72e470533c1e6f66c6e8665817f7132e25fc93c5..132bac815361d19017f856267dbbce06a4d0d7d9 100644 (file)
@@ -14,9 +14,6 @@
  * IP and UDP header sizes */
 #define ADVERTISE_DATAGRAM_SIZE_MAX (65536U-14U-20U-8U)
 
-static int manager_dns_stub_udp_fd(Manager *m);
-static int manager_dns_stub_tcp_fd(Manager *m);
-
 int dns_stub_listener_extra_new(DNSStubListenerExtra **ret) {
         DNSStubListenerExtra *l;
 
@@ -164,17 +161,11 @@ static int dns_stub_send(Manager *m, DnsStream *s, DnsPacket *p, DnsPacket *repl
         if (s)
                 r = dns_stream_write_packet(s, reply);
         else {
-                int fd;
-
-                fd = manager_dns_stub_udp_fd(m);
-                if (fd < 0)
-                        return log_debug_errno(fd, "Failed to get reply socket: %m");
-
                 /* Note that it is essential here that we explicitly choose the source IP address for this packet. This
                  * is because otherwise the kernel will choose it automatically based on the routing table and will
                  * thus pick 127.0.0.1 rather than 127.0.0.53. */
 
-                r = manager_send(m, fd, LOOPBACK_IFINDEX, p->family, &p->sender, p->sender_port, &p->destination, reply);
+                r = manager_send(m, p->fd, p->ifindex, p->family, &p->sender, p->sender_port, &p->destination, reply);
         }
         if (r < 0)
                 return log_debug_errno(r, "Failed to send reply packet: %m");
index faf1a82155c9e513a5c633b98325ea7c07f5a654..ddd336b48971ebe80bfbd5b46debb54cce12876f 100644 (file)
@@ -790,6 +790,7 @@ int manager_recv(Manager *m, int fd, DnsProtocol protocol, DnsPacket **ret) {
 
         p->size = (size_t) l;
 
+        p->fd = fd;
         p->family = sa.sa.sa_family;
         p->ipproto = IPPROTO_UDP;
         if (p->family == AF_INET) {