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

Commit 9934488b authored by Ken Chen's avatar Ken Chen
Browse files

Support alternative handling on truncated DNS response

The default behavior of UDP truncated DNS response is that the DNS
resolver fallback on TCP on the same server. If the fallback retry is
failed, do TCP retry on the rest of servers. However, OEM reported
that the rest of servers may respond a valid answer on UDP connection,
but support no TCP connection. Thus, an alternative truncated response
handling mode is added for OEMs. With the alternative mode, the DNS
resolver fallback retries on TCP on the same server. If the TCP retry
is failed, do UDP retry on the next server, then TCP, and so on.

Set mode by ResolverExperimentalOptionsParcel in ResolverParamsParcel.
tcMode=0 or absent, run default behavior (TCP-only on each DNS server).
tcMode=1, run alternative mode (UDP first on each DNS server).
other values are invalid input, take no effect.

Bug: 139646101
Change-Id: I724cc54bd9fad95954de84c281dd6f1d0b764caa
parent 44a54601
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ aidl_interface {
    srcs: [
        "binder/android/net/IDnsResolver.aidl",
        "binder/android/net/ResolverHostsParcel.aidl",
        "binder/android/net/ResolverExperimentalOptionsParcel.aidl",
        "binder/android/net/ResolverParamsParcel.aidl",
    ],
    imports: [
+3 −1
Original line number Diff line number Diff line
@@ -232,7 +232,8 @@ int ResolverController::setResolverConfiguration(const ResolverParamsParcel& res
    res_params.retry_count = resolverParams.retryCount;

    return resolv_set_nameservers(resolverParams.netId, resolverParams.servers,
                                  resolverParams.domains, res_params, resolverParams.hosts);
                                  resolverParams.domains, res_params,
                                  resolverParams.experimentalOptions);
}

int ResolverController::getResolverInfo(int32_t netId, std::vector<std::string>* servers,
@@ -362,6 +363,7 @@ void ResolverController::dump(DumpWriter& dw, unsigned netId) {
        }
        dw.println("Concurrent DNS query timeout: %d", wait_for_pending_req_timeout_count[0]);
        resolv_stats_dump(dw, netId);
        resolv_oem_options_dump(dw, netId);
    }
    dw.decIndent();
}
+12 −0
Original line number Diff line number Diff line
@@ -170,4 +170,16 @@ interface IDnsResolver {
     *         POSIX errno.
     */
    void flushNetworkCache(int netId);

    /**
     * Values for {@code tcMode} of {@code ResolverExperimentalOptionsParcel}. It controls the way DNS
     * resolver handles truncated DNS response from UDP connection.
     *
     * TC_MODE_DEFAULT: resolver retries on TCP-only on each name server.
     * TC_MODE_UDP_TCP: resolver retries on TCP on the same server, falls back to UDP from next.
     * TC_MODE_MAX: any value smaller than TC_MODE_DEFAULT or greater than TC_MODE_MAX is invalid.
     */
    const int TC_MODE_DEFAULT = 0;
    const int TC_MODE_UDP_TCP = 1;
    const int TC_MODE_MAX = 2;
}
+46 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.net;

import android.net.ResolverHostsParcel;

/**
 * Knobs for OEM to control alternative behavior.
 *
 * {@hide}
 */
parcelable ResolverExperimentalOptionsParcel {
    /**
     * An IP/hostname mapping table for DNS local lookup customization.
     * WARNING: this is intended for local testing and other special situations.
     * Future versions of the DnsResolver module may break your assumptions.
     * Injecting static mappings for public hostnames is generally A VERY BAD IDEA,
     * since it makes it impossible for the domain owners to migrate the domain.
     * It is also not an effective domain blocking mechanism, because apps can
     * easily hardcode IPs or bypass the system DNS resolver.
     */
    ResolverHostsParcel[] hosts = {};

    /**
     * Truncated UDP DNS response handling mode. Handling of UDP responses with the TC (truncated)
     * bit set. The values are defined in {@code IDnsResolver.aidl}
     * 0: TC_MODE_DEFAULT
     * 1: TC_MODE_UDP_TCP
     * Other values are invalid.
     */
    int tcMode = 0;
}
+4 −10
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@

package android.net;

import android.net.ResolverHostsParcel;
import android.net.ResolverExperimentalOptionsParcel;

/**
 * Configuration for a resolver parameters.
@@ -101,13 +101,7 @@ parcelable ResolverParamsParcel {
    int tlsConnectTimeoutMs = 0;

    /**
     * An IP/hostname mapping table for DNS local lookup customization.
     * WARNING: this is intended for local testing and other special situations.
     * Future versions of the DnsResolver module may break your assumptions.
     * Injecting static mappings for public hostnames is generally A VERY BAD IDEA,
     * since it makes it impossible for the domain owners to migrate the domain.
     * It is also not an effective domain blocking mechanism, because apps can
     * easily hardcode IPs or bypass the system DNS resolver.
    * Knobs for OEM to control alternative behavior.
    */
    ResolverHostsParcel[] hosts = {};
    ResolverExperimentalOptionsParcel experimentalOptions;
}
Loading