]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
Merge pull request #6946 from poettering/synthesize-dns
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 3 Oct 2017 08:26:53 +0000 (10:26 +0200)
committerGitHub <noreply@github.com>
Tue, 3 Oct 2017 08:26:53 +0000 (10:26 +0200)
Some DNS RR synthesizing fixes

src/libsystemd/sd-bus/bus-control.c
src/libsystemd/sd-bus/bus-control.h
src/libsystemd/sd-bus/bus-internal.h
src/libsystemd/sd-bus/bus-slot.c
src/libsystemd/sd-bus/sd-bus.c
src/resolve/resolved-dns-query.c
src/resolve/resolved-dns-synthesize.c

index 1a87d3a0ee310b0a97fa84fa5cc8ae6d8801cb28..3c770a6e2e4f7d539bd4ccf36f243816afd27056 100644 (file)
@@ -650,8 +650,7 @@ int bus_add_match_internal(
                 sd_bus *bus,
                 const char *match,
                 struct bus_match_component *components,
-                unsigned n_components,
-                uint64_t cookie) {
+                unsigned n_components) {
 
         assert(bus);
 
@@ -686,8 +685,7 @@ static int bus_remove_match_internal_dbus1(
 
 int bus_remove_match_internal(
                 sd_bus *bus,
-                const char *match,
-                uint64_t cookie) {
+                const char *match) {
 
         assert(bus);
 
index 91efc68d5765672a671944ef3632fb4cee5b0bbf..01c71874db861a3fc777f9cffa2bb7508bab146c 100644 (file)
@@ -23,8 +23,5 @@
 
 #include "bus-match.h"
 
-int bus_add_match_internal(sd_bus *bus, const char *match, struct bus_match_component *components, unsigned n_components, uint64_t cookie);
-int bus_remove_match_internal(sd_bus *bus, const char *match, uint64_t cookie);
-
-int bus_add_match_internal_kernel(sd_bus *bus, struct bus_match_component *components, unsigned n_components, uint64_t cookie);
-int bus_remove_match_internal_kernel(sd_bus *bus, uint64_t cookie);
+int bus_add_match_internal(sd_bus *bus, const char *match, struct bus_match_component *components, unsigned n_components);
+int bus_remove_match_internal(sd_bus *bus, const char *match);
index 9a3bc9dd98917b2b7fe809b272d65be980328cc8..3af383e18ba15f32ea4095b522c086ee231721a0 100644 (file)
@@ -53,7 +53,6 @@ struct filter_callback {
 struct match_callback {
         sd_bus_message_handler_t callback;
 
-        uint64_t cookie;
         unsigned last_iteration;
 
         char *match_string;
@@ -287,8 +286,6 @@ struct sd_bus {
         uint64_t hello_flags;
         uint64_t attach_flags;
 
-        uint64_t match_cookie;
-
         sd_event_source *input_io_event_source;
         sd_event_source *output_io_event_source;
         sd_event_source *time_event_source;
@@ -308,9 +305,6 @@ struct sd_bus {
 
         char *description;
 
-        size_t bloom_size;
-        unsigned bloom_n_hash;
-
         sd_bus_track *track_queue;
 
         LIST_HEAD(sd_bus_slot, slots);
index 33590c31ac78764e23fc6da859ba97c92d77c194..725265b331c300f428fbf4a39424d2324ed48e67 100644 (file)
@@ -93,7 +93,7 @@ void bus_slot_disconnect(sd_bus_slot *slot) {
         case BUS_MATCH_CALLBACK:
 
                 if (slot->match_added)
-                        bus_remove_match_internal(slot->bus, slot->match_callback.match_string, slot->match_callback.cookie);
+                        bus_remove_match_internal(slot->bus, slot->match_callback.match_string);
 
                 slot->bus->match_callbacks_modified = true;
                 bus_match_remove(&slot->bus->match_callbacks, &slot->match_callback);
index 16d997c85e8bd9d9d31d19c1be78ab9fad5c979d..621fabb0155a5e22424f71483bcb283781c19dc5 100644 (file)
@@ -56,7 +56,7 @@
 #define log_debug_bus_message(m)                                         \
         do {                                                             \
                 sd_bus_message *_mm = (m);                               \
-                log_debug("Got message type=%s sender=%s destination=%s object=%s interface=%s member=%s cookie=%" PRIu64 " reply_cookie=%" PRIu64 " error=%s", \
+                log_debug("Got message type=%s sender=%s destination=%s object=%s interface=%s member=%s cookie=%" PRIu64 " reply_cookie=%" PRIu64 " error-name=%s error-message=%s", \
                           bus_message_type_to_string(_mm->header->type), \
                           strna(sd_bus_message_get_sender(_mm)),         \
                           strna(sd_bus_message_get_destination(_mm)),    \
@@ -65,6 +65,7 @@
                           strna(sd_bus_message_get_member(_mm)),         \
                           BUS_MESSAGE_COOKIE(_mm),                       \
                           _mm->reply_cookie,                             \
+                          strna(_mm->error.name),                        \
                           strna(_mm->error.message));                    \
         } while (false)
 
@@ -1465,7 +1466,7 @@ static int bus_write_message(sd_bus *bus, sd_bus_message *m, bool hint_sync_call
                 return r;
 
         if (*idx >= BUS_MESSAGE_SIZE(m))
-                log_debug("Sent message type=%s sender=%s destination=%s object=%s interface=%s member=%s cookie=%" PRIu64 " reply_cookie=%" PRIu64 " error=%s",
+                log_debug("Sent message type=%s sender=%s destination=%s object=%s interface=%s member=%s cookie=%" PRIu64 " reply_cookie=%" PRIu64 " error-name=%s error-message=%s",
                           bus_message_type_to_string(m->header->type),
                           strna(sd_bus_message_get_sender(m)),
                           strna(sd_bus_message_get_destination(m)),
@@ -1474,6 +1475,7 @@ static int bus_write_message(sd_bus *bus, sd_bus_message *m, bool hint_sync_call
                           strna(sd_bus_message_get_member(m)),
                           BUS_MESSAGE_COOKIE(m),
                           m->reply_cookie,
+                          strna(m->error.name),
                           strna(m->error.message));
 
         return r;
@@ -2856,7 +2858,6 @@ _public_ int sd_bus_add_match(
         }
 
         s->match_callback.callback = callback;
-        s->match_callback.cookie = ++bus->match_cookie;
 
         if (bus->bus_client) {
                 enum bus_match_scope scope;
@@ -2876,7 +2877,7 @@ _public_ int sd_bus_add_match(
                                 goto finish;
                         }
 
-                        r = bus_add_match_internal(bus, s->match_callback.match_string, components, n_components, s->match_callback.cookie);
+                        r = bus_add_match_internal(bus, s->match_callback.match_string, components, n_components);
                         if (r < 0)
                                 goto finish;
 
index 2b091e6c45dc57856abc7eabd754f77150efe4d4..c2b29bc45252cf94e97508203c92222b6d993563 100644 (file)
@@ -623,7 +623,18 @@ static int dns_query_synthesize_reply(DnsQuery *q, DnsTransactionState *state) {
                         q->question_utf8,
                         q->ifindex,
                         &answer);
+        if (r == -ENXIO) {
+                /* If we get ENXIO this tells us to generate NXDOMAIN unconditionally. */
 
+                dns_query_reset_answer(q);
+                q->answer_rcode = DNS_RCODE_NXDOMAIN;
+                q->answer_protocol = dns_synthesize_protocol(q->flags);
+                q->answer_family = dns_synthesize_family(q->flags);
+                q->answer_authenticated = true;
+                *state = DNS_TRANSACTION_RCODE_FAILURE;
+
+                return 0;
+        }
         if (r <= 0)
                 return r;
 
index 25d2322453b8086a3a778dc6f5967967e1f01c4b..ad38c6a5610c28d249524dcfd78b921d9fcb7ba3 100644 (file)
@@ -186,6 +186,7 @@ static int answer_add_addresses_ptr(
                 unsigned n_addresses,
                 int af, const union in_addr_union *match) {
 
+        bool added = false;
         unsigned j;
         int r;
 
@@ -215,9 +216,11 @@ static int answer_add_addresses_ptr(
                 r = dns_answer_add(*answer, rr, addresses[j].ifindex, DNS_ANSWER_AUTHENTICATED);
                 if (r < 0)
                         return r;
+
+                added = true;
         }
 
-        return 0;
+        return added;
 }
 
 static int synthesize_system_hostname_rr(Manager *m, const DnsResourceKey *key, int ifindex, DnsAnswer **answer) {
@@ -265,6 +268,7 @@ static int synthesize_system_hostname_rr(Manager *m, const DnsResourceKey *key,
 
 static int synthesize_system_hostname_ptr(Manager *m, int af, const union in_addr_union *address, int ifindex, DnsAnswer **answer) {
         _cleanup_free_ struct local_address *addresses = NULL;
+        bool added = false;
         int n, r;
 
         assert(m);
@@ -273,10 +277,13 @@ static int synthesize_system_hostname_ptr(Manager *m, int af, const union in_add
 
         if (af == AF_INET && address->in.s_addr == htobe32(0x7F000002)) {
 
-                /* Always map the IPv4 address 127.0.0.2 to the local
-                 * hostname, in addition to "localhost": */
+                /* Always map the IPv4 address 127.0.0.2 to the local hostname, in addition to "localhost": */
 
-                r = dns_answer_reserve(answer, 3);
+                r = dns_answer_reserve(answer, 4);
+                if (r < 0)
+                        return r;
+
+                r = answer_add_ptr(answer, "2.0.0.127.in-addr.arpa", m->full_hostname, dns_synthesize_ifindex(ifindex), DNS_ANSWER_AUTHENTICATED);
                 if (r < 0)
                         return r;
 
@@ -292,23 +299,37 @@ static int synthesize_system_hostname_ptr(Manager *m, int af, const union in_add
                 if (r < 0)
                         return r;
 
-                return 0;
+                return 1;
         }
 
         n = local_addresses(m->rtnl, ifindex, af, &addresses);
-        if (n < 0)
+        if (n <= 0)
                 return n;
 
+        r = answer_add_addresses_ptr(answer, m->full_hostname, addresses, n, af, address);
+        if (r < 0)
+                return r;
+        if (r > 0)
+                added = true;
+
         r = answer_add_addresses_ptr(answer, m->llmnr_hostname, addresses, n, af, address);
         if (r < 0)
                 return r;
+        if (r > 0)
+                added = true;
+
+        r = answer_add_addresses_ptr(answer, m->mdns_hostname, addresses, n, af, address);
+        if (r < 0)
+                return r;
+        if (r > 0)
+                added = true;
 
-        return answer_add_addresses_ptr(answer, m->mdns_hostname, addresses, n, af, address);
+        return added;
 }
 
 static int synthesize_gateway_rr(Manager *m, const DnsResourceKey *key, int ifindex, DnsAnswer **answer) {
         _cleanup_free_ struct local_address *addresses = NULL;
-        int n = 0, af;
+        int n = 0, af, r;
 
         assert(m);
         assert(key);
@@ -317,11 +338,15 @@ static int synthesize_gateway_rr(Manager *m, const DnsResourceKey *key, int ifin
         af = dns_type_to_af(key->type);
         if (af >= 0) {
                 n = local_gateways(m->rtnl, ifindex, af, &addresses);
-                if (n < 0)
-                        return n;
+                if (n <= 0)
+                        return n;  /* < 0 means: error; == 0 means we have no gateway */
         }
 
-        return answer_add_addresses_rr(answer, dns_resource_key_name(key), addresses, n);
+        r = answer_add_addresses_rr(answer, dns_resource_key_name(key), addresses, n);
+        if (r < 0)
+                return r;
+
+        return 1; /* > 0 means: we have some gateway */
 }
 
 static int synthesize_gateway_ptr(Manager *m, int af, const union in_addr_union *address, int ifindex, DnsAnswer **answer) {
@@ -333,7 +358,7 @@ static int synthesize_gateway_ptr(Manager *m, int af, const union in_addr_union
         assert(answer);
 
         n = local_gateways(m->rtnl, ifindex, af, &addresses);
-        if (n < 0)
+        if (n <= 0)
                 return n;
 
         return answer_add_addresses_ptr(answer, "_gateway", addresses, n, af, address);
@@ -347,7 +372,7 @@ int dns_synthesize_answer(
 
         _cleanup_(dns_answer_unrefp) DnsAnswer *answer = NULL;
         DnsResourceKey *key;
-        bool found = false;
+        bool found = false, nxdomain = false;
         int r;
 
         assert(m);
@@ -381,6 +406,10 @@ int dns_synthesize_answer(
                         r = synthesize_gateway_rr(m, key, ifindex, &answer);
                         if (r < 0)
                                 return log_error_errno(r, "Failed to synthesize gateway RRs: %m");
+                        if (r == 0) { /* if we have no gateway return NXDOMAIN */
+                                nxdomain = true;
+                                continue;
+                        }
 
                 } else if ((dns_name_endswith(name, "127.in-addr.arpa") > 0 && dns_name_equal(name, "2.0.0.127.in-addr.arpa") == 0) ||
                            dns_name_equal(name, "1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa") > 0) {
@@ -390,26 +419,35 @@ int dns_synthesize_answer(
                                 return log_error_errno(r, "Failed to synthesize localhost PTR RRs: %m");
 
                 } else if (dns_name_address(name, &af, &address) > 0) {
+                        int v, w;
 
-                        r = synthesize_system_hostname_ptr(m, af, &address, ifindex, &answer);
-                        if (r < 0)
+                        v = synthesize_system_hostname_ptr(m, af, &address, ifindex, &answer);
+                        if (v < 0)
                                 return log_error_errno(r, "Failed to synthesize system hostname PTR RR: %m");
 
-                        r = synthesize_gateway_ptr(m, af, &address, ifindex, &answer);
-                        if (r < 0)
+                        w = synthesize_gateway_ptr(m, af, &address, ifindex, &answer);
+                        if (w < 0)
                                 return log_error_errno(r, "Failed to synthesize gateway hostname PTR RR: %m");
+
+                        if (v == 0 && w == 0) /* This IP address is neither a local one nor a gateway */
+                                continue;
+
                 } else
                         continue;
 
                 found = true;
         }
 
-        r = found;
+        if (found) {
 
-        if (ret) {
-                *ret = answer;
-                answer = NULL;
-        }
+                if (ret) {
+                        *ret = answer;
+                        answer = NULL;
+                }
+
+                return 1;
+        } else if (nxdomain)
+                return -ENXIO;
 
-        return r;
+        return 0;
 }