Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 80f76aa1 authored by Mike Yu's avatar Mike Yu
Browse files

DoT quick fallback

If a DNS query that was sent to a DoT server times out, instead
of trying the next DoT server, let the query fall back to UDP.

This will be helpful when firewall blocks TCP/853 traffic, for
example captive portal re-login.

DoT quick fallback is enabled by default. It's configurable by
the flag `dot_quick_fallback`.

Bug: 228594312
Test: cd packages/modules/DnsResolver && atest
Test: On a wifi network with 2 validated DoT servers, blocked TCP/853
      traffic. DNS queries took 1x time w/ the flag enabled, and
      took 2x time w/o the flag enabled.
Change-Id: I27992baf4dd450391ab6241a5bf46b71ae656766
parent 84f5fa8b
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -107,7 +107,8 @@ std::list<DnsTlsServer> DnsTlsDispatcher::getOrderedAndUsableServerList(

DnsTlsTransport::Response DnsTlsDispatcher::query(const std::list<DnsTlsServer>& tlsServers,
                                                  ResState* statp, const Slice query,
                                                  const Slice ans, int* resplen) {
                                                  const Slice ans, int* resplen,
                                                  bool dotQuickFallback) {
    const std::list<DnsTlsServer> servers(
            getOrderedAndUsableServerList(tlsServers, statp->netid, statp->mark));

@@ -150,6 +151,9 @@ DnsTlsTransport::Response DnsTlsDispatcher::query(const std::list<DnsTlsServer>&
                // Sync from res_tls_send in res_send.cpp
                dnsQueryEvent->set_rcode(NS_R_TIMEOUT);
                resolv_stats_add(statp->netid, IPSockAddr::toIPSockAddr(server.ss), dnsQueryEvent);
                if (dotQuickFallback) {
                    return code;
                }
                break;
            case DnsTlsTransport::Response::internal_error:
                dnsQueryEvent->set_rcode(NS_R_INTERNAL_ERROR);
+2 −1
Original line number Diff line number Diff line
@@ -52,7 +52,8 @@ class DnsTlsDispatcher : public PrivateDnsValidationObserver {
    // order passed in by the caller.
    DnsTlsTransport::Response query(const std::list<DnsTlsServer>& tlsServers,
                                    ResState* _Nonnull statp, const netdutils::Slice query,
                                    const netdutils::Slice ans, int* _Nonnull resplen);
                                    const netdutils::Slice ans, int* _Nonnull resplen,
                                    bool dotQuickFallback);

    // Given a |query|, sends it to the server on the network indicated by |mark|,
    // and writes the response into |ans|, and indicates the number of bytes written in |resplen|.
+1 −0
Original line number Diff line number Diff line
@@ -59,6 +59,7 @@ class Experiments {
            "dot_revalidation_threshold",
            "dot_xport_unusable_threshold",
            "dot_query_timeout_ms",
            "dot_quick_fallback",
            "dot_validation_latency_factor",
            "dot_validation_latency_offset_ms",
            "doh",
+6 −2
Original line number Diff line number Diff line
@@ -1436,9 +1436,13 @@ int res_tls_send(const std::list<DnsTlsServer>& tlsServers, ResState* statp, con
                 const Slice answer, int* rcode, PrivateDnsMode mode) {
    if (tlsServers.empty()) return -1;
    LOG(INFO) << __func__ << ": performing query over TLS";
    const bool dotQuickFallback =
            (mode == PrivateDnsMode::STRICT)
                    ? 0
                    : Experiments::getInstance()->getFlag("dot_quick_fallback", 1);
    int resplen = 0;
    const auto response =
            DnsTlsDispatcher::getInstance().query(tlsServers, statp, query, answer, &resplen);
    const auto response = DnsTlsDispatcher::getInstance().query(tlsServers, statp, query, answer,
                                                                &resplen, dotQuickFallback);

    LOG(INFO) << __func__ << ": TLS query result: " << static_cast<int>(response);
    if (mode == PrivateDnsMode::OPPORTUNISTIC) {
+1 −0
Original line number Diff line number Diff line
@@ -58,6 +58,7 @@ class DnsTlsFrontend {
    void clearQueries() { queries_ = 0; }
    bool waitForQueries(int expected_count) const;
    int acceptConnectionsCount() const { return accept_connection_count_; }
    void clearConnectionsCount() { accept_connection_count_ = 0; }

    void set_chain_length(int length) { chain_length_ = length; }
    void setHangOnHandshakeForTesting(bool hangOnHandshake) { hangOnHandshake_ = hangOnHandshake; }
Loading