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

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

Snap for 11052082 from c65ca27b to mainline-media-release

Change-Id: Ifa92e9dc2cfabf9ad9532dbe35ff1f674f0e8c57
parents d5c0e88f c65ca27b
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -53,7 +53,7 @@ cc_library_headers {
    ],
}

dnsresolver_aidl_interface_lateststable_version = "V11"
dnsresolver_aidl_interface_lateststable_version = "V12"

cc_library_static {
    name: "dnsresolver_aidl_interface-lateststable-ndk",
+21 −16
Original line number Diff line number Diff line
@@ -322,9 +322,11 @@ void maybeLogQuery(int eventType, const android_net_context& netContext,

void reportDnsEvent(int eventType, const android_net_context& netContext, int latencyUs,
                    int returnCode, NetworkDnsEventReported& event, const std::string& query_name,
                    const std::vector<std::string>& ip_addrs = {}, int total_ip_addr_count = 0) {
    uint32_t rate =
            (query_name.ends_with(".local") && is_mdns_supported_network(netContext.dns_netid) &&
                    bool skipStats, const std::vector<std::string>& ip_addrs = {},
                    int total_ip_addr_count = 0) {
    int32_t rate =
            skipStats ? 0
            : (query_name.ends_with(".local") && is_mdns_supported_network(netContext.dns_netid) &&
               android::net::Experiments::getInstance()->getFlag("mdns_resolution", 1))
                    ? getDnsEventSubsamplingRate(netContext.dns_netid, returnCode, true)
                    : getDnsEventSubsamplingRate(netContext.dns_netid, returnCode, false);
@@ -706,8 +708,7 @@ bool isUidNetworkingBlocked(uid_t uid, unsigned netId) {
    // application's UID. Its DNS packets are not subject to certain network restriction features.
    if (resolv_is_enforceDnsUid_enabled_network(netId)) return false;

    // TODO: Pass metered information from CS to DNS resolver and replace the hardcode value.
    return (*ADnsHelper_isUidNetworkingBlocked)(uid, /*metered=*/false) == 1;
    return (*ADnsHelper_isUidNetworkingBlocked)(uid, resolv_is_metered_network(netId)) == 1;
}

}  // namespace
@@ -904,7 +905,8 @@ void DnsProxyListener::GetAddrInfoHandler::run() {
    int32_t rv = 0;
    NetworkDnsEventReported event;
    initDnsEvent(&event, mNetContext);
    if (isUidNetworkingBlocked(mNetContext.uid, mNetContext.dns_netid)) {
    const bool isUidBlocked = isUidNetworkingBlocked(mNetContext.uid, mNetContext.dns_netid);
    if (isUidBlocked) {
        LOG(INFO) << "GetAddrInfoHandler::run: network access blocked";
        rv = EAI_FAIL;
    } else if (startQueryLimiter(uid)) {
@@ -952,7 +954,7 @@ void DnsProxyListener::GetAddrInfoHandler::run() {
    std::vector<std::string> ip_addrs;
    const int total_ip_addr_count = extractGetAddrInfoAnswers(result, &ip_addrs);
    reportDnsEvent(INetdEventListener::EVENT_GETADDRINFO, mNetContext, latencyUs, rv, event, mHost,
                   ip_addrs, total_ip_addr_count);
                   isUidBlocked, ip_addrs, total_ip_addr_count);
    freeaddrinfo(result);
}

@@ -1116,7 +1118,8 @@ void DnsProxyListener::ResNSendHandler::run() {
    int ansLen = -1;
    NetworkDnsEventReported event;
    initDnsEvent(&event, mNetContext);
    if (isUidNetworkingBlocked(mNetContext.uid, mNetContext.dns_netid)) {
    const bool isUidBlocked = isUidNetworkingBlocked(mNetContext.uid, mNetContext.dns_netid);
    if (isUidBlocked) {
        LOG(INFO) << "ResNSendHandler::run: network access blocked";
        ansLen = -ECONNREFUSED;
    } else if (startQueryLimiter(uid)) {
@@ -1147,7 +1150,7 @@ void DnsProxyListener::ResNSendHandler::run() {
        }
        if (rr_type == ns_t_a || rr_type == ns_t_aaaa) {
            reportDnsEvent(INetdEventListener::EVENT_RES_NSEND, mNetContext, latencyUs,
                           resNSendToAiError(ansLen, rcode), event, rr_name);
                           resNSendToAiError(ansLen, rcode), event, rr_name, isUidBlocked);
        }
        return;
    }
@@ -1177,8 +1180,8 @@ void DnsProxyListener::ResNSendHandler::run() {
        const int total_ip_addr_count =
                extractResNsendAnswers(std::span(ansBuf.data(), ansLen), rr_type, &ip_addrs);
        reportDnsEvent(INetdEventListener::EVENT_RES_NSEND, mNetContext, latencyUs,
                       resNSendToAiError(ansLen, rcode), event, rr_name, ip_addrs,
                       total_ip_addr_count);
                       resNSendToAiError(ansLen, rcode), event, rr_name, /*skipStats=*/false,
                       ip_addrs, total_ip_addr_count);
    }
}

@@ -1320,7 +1323,8 @@ void DnsProxyListener::GetHostByNameHandler::run() {
    int32_t rv = 0;
    NetworkDnsEventReported event;
    initDnsEvent(&event, mNetContext);
    if (isUidNetworkingBlocked(mNetContext.uid, mNetContext.dns_netid)) {
    const bool isUidBlocked = isUidNetworkingBlocked(mNetContext.uid, mNetContext.dns_netid);
    if (isUidBlocked) {
        LOG(INFO) << "GetHostByNameHandler::run: network access blocked";
        rv = EAI_FAIL;
    } else if (startQueryLimiter(uid)) {
@@ -1364,7 +1368,7 @@ void DnsProxyListener::GetHostByNameHandler::run() {
    std::vector<std::string> ip_addrs;
    const int total_ip_addr_count = extractGetHostByNameAnswers(hp, &ip_addrs);
    reportDnsEvent(INetdEventListener::EVENT_GETHOSTBYNAME, mNetContext, latencyUs, rv, event,
                   mName, ip_addrs, total_ip_addr_count);
                   mName, isUidBlocked, ip_addrs, total_ip_addr_count);
}

std::string DnsProxyListener::GetHostByNameHandler::threadName() {
@@ -1483,7 +1487,8 @@ void DnsProxyListener::GetHostByAddrHandler::run() {
    NetworkDnsEventReported event;
    initDnsEvent(&event, mNetContext);

    if (isUidNetworkingBlocked(mNetContext.uid, mNetContext.dns_netid)) {
    const bool isUidBlocked = isUidNetworkingBlocked(mNetContext.uid, mNetContext.dns_netid);
    if (isUidBlocked) {
        LOG(INFO) << "GetHostByAddrHandler::run: network access blocked";
        rv = EAI_FAIL;
    } else if (startQueryLimiter(uid)) {
@@ -1529,7 +1534,7 @@ void DnsProxyListener::GetHostByAddrHandler::run() {
    }

    reportDnsEvent(INetdEventListener::EVENT_GETHOSTBYADDR, mNetContext, latencyUs, rv, event,
                   (hp && hp->h_name) ? hp->h_name : "null", {}, 0);
                   (hp && hp->h_name) ? hp->h_name : "null", isUidBlocked, {}, 0);
}

std::string DnsProxyListener::GetHostByAddrHandler::threadName() {
+2 −1
Original line number Diff line number Diff line
@@ -237,7 +237,8 @@ int ResolverController::setResolverConfiguration(const ResolverParamsParcel& res

    return resolv_set_nameservers(resolverParams.netId, resolverParams.servers,
                                  resolverParams.domains, res_params,
                                  resolverParams.resolverOptions, resolverParams.transportTypes);
                                  resolverParams.resolverOptions, resolverParams.transportTypes,
                                  resolverParams.meteredNetwork);
}

int ResolverController::getResolverInfo(int32_t netId, std::vector<std::string>* servers,
+12 −1
Original line number Diff line number Diff line
@@ -1065,6 +1065,7 @@ struct NetConfig {
    int tc_mode = aidl::android::net::IDnsResolver::TC_MODE_DEFAULT;
    bool enforceDnsUid = false;
    std::vector<int32_t> transportTypes;
    bool metered = false;
};

/* gets cache associated with a network, or NULL if none exists */
@@ -1642,7 +1643,7 @@ std::vector<std::string> getCustomizedTableByName(const size_t netid, const char
int resolv_set_nameservers(unsigned netid, const std::vector<std::string>& servers,
                           const std::vector<std::string>& domains, const res_params& params,
                           const std::optional<ResolverOptionsParcel> optionalResolverOptions,
                           const std::vector<int32_t>& transportTypes) {
                           const std::vector<int32_t>& transportTypes, bool metered) {
    std::vector<std::string> nameservers = filter_nameservers(servers);
    const int numservers = static_cast<int>(nameservers.size());

@@ -1709,6 +1710,7 @@ int resolv_set_nameservers(unsigned netid, const std::vector<std::string>& serve
        return -EINVAL;
    }
    netconfig->transportTypes = transportTypes;
    netconfig->metered = metered;
    if (optionalResolverOptions.has_value()) {
        const ResolverOptionsParcel& resolverOptions = optionalResolverOptions.value();
        return netconfig->setOptions(resolverOptions);
@@ -2090,6 +2092,7 @@ void resolv_netconfig_dump(DumpWriter& dw, unsigned netid) {
        // TODO: dump info->hosts
        dw.println("TC mode: %s", tc_mode_to_str(info->tc_mode));
        dw.println("TransportType: %s", transport_type_to_str(info->transportTypes));
        dw.println("Metered: %s", info->metered ? "true" : "false");
    }
}

@@ -2110,3 +2113,11 @@ bool resolv_is_enforceDnsUid_enabled_network(unsigned netid) {
    }
    return false;
}

bool resolv_is_metered_network(unsigned netid) {
    std::lock_guard guard(cache_mutex);
    if (const auto info = find_netconfig_locked(netid); info != nullptr) {
        return info->metered;
    }
    return false;
}
+4 −1
Original line number Diff line number Diff line
@@ -81,7 +81,7 @@ std::vector<std::string> getCustomizedTableByName(const size_t netid, const char
int resolv_set_nameservers(unsigned netid, const std::vector<std::string>& servers,
                           const std::vector<std::string>& domains, const res_params& params,
                           std::optional<aidl::android::net::ResolverOptionsParcel> resolverOptions,
                           const std::vector<int32_t>& transportTypes = {});
                           const std::vector<int32_t>& transportTypes = {}, bool metered = false);

// Sets options for a given network.
int resolv_set_options(unsigned netid, const aidl::android::net::ResolverOptionsParcel& options);
@@ -146,3 +146,6 @@ int resolv_get_max_cache_entries(unsigned netid);

// Return true if the enforceDnsUid is enabled on the network.
bool resolv_is_enforceDnsUid_enabled_network(unsigned netid);

// Return true if the network is metered.
bool resolv_is_metered_network(unsigned netid);
Loading