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

Commit a80df105 authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 8545515 from bfe94814 to mainline-adservices-release

Change-Id: Ib6bf84167fc6d8cefb926a955ed03ad2a8d7f93b
parents c1048e94 bfe94814
Loading
Loading
Loading
Loading
+5 −1
Original line number Original line Diff line number Diff line
@@ -107,7 +107,8 @@ std::list<DnsTlsServer> DnsTlsDispatcher::getOrderedAndUsableServerList(


DnsTlsTransport::Response DnsTlsDispatcher::query(const std::list<DnsTlsServer>& tlsServers,
DnsTlsTransport::Response DnsTlsDispatcher::query(const std::list<DnsTlsServer>& tlsServers,
                                                  ResState* statp, const Slice query,
                                                  ResState* statp, const Slice query,
                                                  const Slice ans, int* resplen) {
                                                  const Slice ans, int* resplen,
                                                  bool dotQuickFallback) {
    const std::list<DnsTlsServer> servers(
    const std::list<DnsTlsServer> servers(
            getOrderedAndUsableServerList(tlsServers, statp->netid, statp->mark));
            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
                // Sync from res_tls_send in res_send.cpp
                dnsQueryEvent->set_rcode(NS_R_TIMEOUT);
                dnsQueryEvent->set_rcode(NS_R_TIMEOUT);
                resolv_stats_add(statp->netid, IPSockAddr::toIPSockAddr(server.ss), dnsQueryEvent);
                resolv_stats_add(statp->netid, IPSockAddr::toIPSockAddr(server.ss), dnsQueryEvent);
                if (dotQuickFallback) {
                    return code;
                }
                break;
                break;
            case DnsTlsTransport::Response::internal_error:
            case DnsTlsTransport::Response::internal_error:
                dnsQueryEvent->set_rcode(NS_R_INTERNAL_ERROR);
                dnsQueryEvent->set_rcode(NS_R_INTERNAL_ERROR);
+2 −1
Original line number Original line Diff line number Diff line
@@ -52,7 +52,8 @@ class DnsTlsDispatcher : public PrivateDnsValidationObserver {
    // order passed in by the caller.
    // order passed in by the caller.
    DnsTlsTransport::Response query(const std::list<DnsTlsServer>& tlsServers,
    DnsTlsTransport::Response query(const std::list<DnsTlsServer>& tlsServers,
                                    ResState* _Nonnull statp, const netdutils::Slice query,
                                    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|,
    // 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|.
    // and writes the response into |ans|, and indicates the number of bytes written in |resplen|.
+2 −0
Original line number Original line Diff line number Diff line
@@ -59,6 +59,7 @@ class Experiments {
            "dot_revalidation_threshold",
            "dot_revalidation_threshold",
            "dot_xport_unusable_threshold",
            "dot_xport_unusable_threshold",
            "dot_query_timeout_ms",
            "dot_query_timeout_ms",
            "dot_quick_fallback",
            "dot_validation_latency_factor",
            "dot_validation_latency_factor",
            "dot_validation_latency_offset_ms",
            "dot_validation_latency_offset_ms",
            "doh",
            "doh",
@@ -67,6 +68,7 @@ class Experiments {
            "doh_idle_timeout_ms",
            "doh_idle_timeout_ms",
            "doh_session_resumption",
            "doh_session_resumption",
            "mdns_resolution",
            "mdns_resolution",
            "max_queries_global",
    };
    };
    // This value is used in updateInternal as the default value if any flags can't be found.
    // This value is used in updateInternal as the default value if any flags can't be found.
    static constexpr int kFlagIntDefault = INT_MIN;
    static constexpr int kFlagIntDefault = INT_MIN;
+12 −7
Original line number Original line Diff line number Diff line
@@ -23,6 +23,8 @@
#include <android-base/logging.h>
#include <android-base/logging.h>
#include <android-base/thread_annotations.h>
#include <android-base/thread_annotations.h>


#include "Experiments.h"

namespace android {
namespace android {
namespace netdutils {
namespace netdutils {


@@ -43,8 +45,7 @@ namespace netdutils {
template <typename KeyType>
template <typename KeyType>
class OperationLimiter {
class OperationLimiter {
  public:
  public:
    OperationLimiter(int limitPerKey, int globalLimit = INT_MAX)
    OperationLimiter(int limitPerKey) : mLimitPerKey(limitPerKey) {}
        : mLimitPerKey(limitPerKey), mGlobalLimit(globalLimit) {}


    ~OperationLimiter() {
    ~OperationLimiter() {
        DCHECK(mCounters.empty()) << "Destroying OperationLimiter with active operations";
        DCHECK(mCounters.empty()) << "Destroying OperationLimiter with active operations";
@@ -57,15 +58,22 @@ class OperationLimiter {
    // finish(key).
    // finish(key).
    bool start(KeyType key) EXCLUDES(mMutex) {
    bool start(KeyType key) EXCLUDES(mMutex) {
        std::lock_guard lock(mMutex);
        std::lock_guard lock(mMutex);

        int globalLimit =
        if (mGlobalCounter >= mGlobalLimit) {
                android::net::Experiments::getInstance()->getFlag("max_queries_global", INT_MAX);
        if (globalLimit < mLimitPerKey) {
            LOG(ERROR) << "Misconfiguration on max_queries_global " << globalLimit;
            globalLimit = INT_MAX;
        }
        if (mGlobalCounter >= globalLimit) {
            // Oh, no!
            // Oh, no!
            LOG(ERROR) << "Query from " << key << " denied due to global limit: " << globalLimit;
            return false;
            return false;
        }
        }


        auto& cnt = mCounters[key];  // operator[] creates new entries as needed.
        auto& cnt = mCounters[key];  // operator[] creates new entries as needed.
        if (cnt >= mLimitPerKey) {
        if (cnt >= mLimitPerKey) {
            // Oh, no!
            // Oh, no!
            LOG(ERROR) << "Query from " << key << " denied due to limit: " << mLimitPerKey;
            return false;
            return false;
        }
        }


@@ -109,9 +117,6 @@ class OperationLimiter {


    // Maximum number of outstanding queries from a single key.
    // Maximum number of outstanding queries from a single key.
    const int mLimitPerKey;
    const int mLimitPerKey;

    // Maximum number of outstanding queries, globally.
    const int mGlobalLimit;
};
};


}  // namespace netdutils
}  // namespace netdutils
+1 −1
Original line number Original line Diff line number Diff line
{
{
  "name": "com.android.resolv",
  "name": "com.android.resolv",
  "version": 319999900
  "version": 330000000
}
}
Loading