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

Commit 766feae1 authored by Ken Chen's avatar Ken Chen
Browse files

Add an API to flush cache on designated network

Flush entire cache on a specified network. The API acquires lock before
manipulate cache. It's thread-safe API.

Bug: 139646101
Test: atest resolv_cache_unit_test.cpp#FlushCache
Test: atest resolv_integration_test.cpp#FlushNetworkCache

Change-Id: I4ea34a256013468ceac21ce5067d6a493d8631f8
parent c7320aa3
Loading
Loading
Loading
Loading
+9 −0
Original line number Original line Diff line number Diff line
@@ -249,5 +249,14 @@ binder_status_t DnsResolverService::dump(int fd, const char**, uint32_t) {
    return statusFromErrcode(res);
    return statusFromErrcode(res);
}
}


::ndk::ScopedAStatus DnsResolverService::flushNetworkCache(int netId) {
    // Locking happens in res_cache.cpp functions.
    ENFORCE_NETWORK_STACK_PERMISSIONS();

    int res = gDnsResolv->resolverCtrl.flushNetworkCache(netId);

    return statusFromErrcode(res);
}

}  // namespace net
}  // namespace net
}  // namespace android
}  // namespace android
+1 −0
Original line number Original line Diff line number Diff line
@@ -50,6 +50,7 @@ class DnsResolverService : public aidl::android::net::BnDnsResolver {
            std::vector<int32_t>* wait_for_pending_req_timeout_count) override;
            std::vector<int32_t>* wait_for_pending_req_timeout_count) override;
    ::ndk::ScopedAStatus destroyNetworkCache(int32_t netId) override;
    ::ndk::ScopedAStatus destroyNetworkCache(int32_t netId) override;
    ::ndk::ScopedAStatus createNetworkCache(int32_t netId) override;
    ::ndk::ScopedAStatus createNetworkCache(int32_t netId) override;
    ::ndk::ScopedAStatus flushNetworkCache(int32_t netId) override;


    // DNS64-related commands
    // DNS64-related commands
    ::ndk::ScopedAStatus startPrefix64Discovery(int32_t netId) override;
    ::ndk::ScopedAStatus startPrefix64Discovery(int32_t netId) override;
+5 −0
Original line number Original line Diff line number Diff line
@@ -194,6 +194,11 @@ int ResolverController::createNetworkCache(unsigned netId) {
    return resolv_create_cache_for_net(netId);
    return resolv_create_cache_for_net(netId);
}
}


int ResolverController::flushNetworkCache(unsigned netId) {
    LOG(VERBOSE) << __func__ << ": netId = " << netId;
    return resolv_flush_cache_for_net(netId);
}

int ResolverController::setResolverConfiguration(const ResolverParamsParcel& resolverParams) {
int ResolverController::setResolverConfiguration(const ResolverParamsParcel& resolverParams) {
    using aidl::android::net::IDnsResolver;
    using aidl::android::net::IDnsResolver;


+1 −0
Original line number Original line Diff line number Diff line
@@ -38,6 +38,7 @@ class ResolverController {


    void destroyNetworkCache(unsigned netid);
    void destroyNetworkCache(unsigned netid);
    int createNetworkCache(unsigned netid);
    int createNetworkCache(unsigned netid);
    int flushNetworkCache(unsigned netid);


    int getPrefix64(unsigned netId, netdutils::IPPrefix* prefix);
    int getPrefix64(unsigned netId, netdutils::IPPrefix* prefix);


+9 −0
Original line number Original line Diff line number Diff line
@@ -161,4 +161,13 @@ interface IDnsResolver {
     *         POSIX errno.
     *         POSIX errno.
     */
     */
    void setLogSeverity(int logSeverity);
    void setLogSeverity(int logSeverity);

    /**
     * Flush cache for the given network.
     *
     * @param netId the network ID of the network to flush.
     * @throws ServiceSpecificException in case of failure, with an error code corresponding to the
     *         POSIX errno.
     */
    void flushNetworkCache(int netId);
}
}
Loading