diff options
author | Treehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com> | 2024-02-06 07:24:37 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2024-02-06 07:24:37 +0000 |
commit | 62514609defa8c9c1eef29ce87f432e395fd520b (patch) | |
tree | 7873f68a36f15fb356db936e2b3512cc530c3c50 | |
parent | 2a0234a268f709bf36ecdd94989e5382e56550cd (diff) | |
parent | 901e5025b285146db2e03e67cc2de86aff7f7ec9 (diff) | |
download | netd-62514609defa8c9c1eef29ce87f432e395fd520b.tar.gz |
Merge "Revert "Delete mdns from netd"" into main am: 901e5025b2
Original change: https://android-review.googlesource.com/c/platform/system/netd/+/2952325
Change-Id: I82536b8bb4d95b10e4cd44721cfb57975e7bc17d
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r-- | server/Android.bp | 2 | ||||
-rw-r--r-- | server/MDnsService.cpp | 128 | ||||
-rw-r--r-- | server/MDnsService.h | 44 | ||||
-rw-r--r-- | server/main.cpp | 8 | ||||
-rw-r--r-- | server/netd.rc | 1 |
5 files changed, 183 insertions, 0 deletions
diff --git a/server/Android.bp b/server/Android.bp index ff60ab0b..d68950ea 100644 --- a/server/Android.bp +++ b/server/Android.bp @@ -115,6 +115,7 @@ cc_defaults { "libselinux", "libsysutils", "libutils", + "mdns_aidl_interface-V1-cpp", "netd_event_listener_interface-V1-cpp", "oemnetd_aidl_interface-cpp", ], @@ -128,6 +129,7 @@ cc_defaults { "EventReporter.cpp", "FwmarkServer.cpp", "LocalNetwork.cpp", + "MDnsService.cpp", "NetdCommand.cpp", "NetdHwAidlService.cpp", "NetdHwService.cpp", diff --git a/server/MDnsService.cpp b/server/MDnsService.cpp new file mode 100644 index 00000000..bb70550a --- /dev/null +++ b/server/MDnsService.cpp @@ -0,0 +1,128 @@ +/** + * Copyright (c) 2022, 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. + */ + +#define LOG_TAG "MDnsService" + +#include "MDnsService.h" + +#include <android-base/properties.h> +#include <binder/Status.h> +#include <binder_utils/BinderUtil.h> + +using android::net::mdns::aidl::DiscoveryInfo; +using android::net::mdns::aidl::GetAddressInfo; +using android::net::mdns::aidl::IMDnsEventListener; +using android::net::mdns::aidl::RegistrationInfo; +using android::net::mdns::aidl::ResolutionInfo; + +using std::literals::chrono_literals::operator""s; + +namespace android::net { + +#define MDNS_SERVICE_NAME "mdnsd" +#define MDNS_SERVICE_STATUS "init.svc.mdnsd" + +// TODO: DnsResolver has same macro definition but returns ScopedAStatus. Move these macros to +// BinderUtil.h to do the same permission check. +#define ENFORCE_ANY_PERMISSION(...) \ + do { \ + binder::Status status = checkAnyPermission({__VA_ARGS__}); \ + if (!status.isOk()) { \ + return status; \ + } \ + } while (0) + +#define ENFORCE_NETWORK_STACK_PERMISSIONS() \ + ENFORCE_ANY_PERMISSION(PERM_NETWORK_STACK, PERM_MAINLINE_NETWORK_STACK) + +status_t MDnsService::start() { + IPCThreadState::self()->disableBackgroundScheduling(true); + const status_t ret = BinderService<MDnsService>::publish(); + if (ret != android::OK) { + return ret; + } + return android::OK; +} + +binder::Status MDnsService::startDaemon() { + ENFORCE_NETWORK_STACK_PERMISSIONS(); + if (android::base::GetProperty(MDNS_SERVICE_STATUS, "") == "running") { + return android::binder::Status::fromServiceSpecificError(EBUSY, strerror(EBUSY)); + } + + ALOGD("Starting MDNSD"); + android::base::SetProperty("ctl.start", MDNS_SERVICE_NAME); + // To maintain the same behavior as before, the returned value is not checked. + android::base::WaitForProperty(MDNS_SERVICE_STATUS, "running", 5s); + return binder::Status::ok(); +} + +binder::Status MDnsService::stopDaemon() { + ENFORCE_NETWORK_STACK_PERMISSIONS(); + ALOGD("Stopping MDNSD"); + android::base::SetProperty("ctl.stop", MDNS_SERVICE_NAME); + android::base::WaitForProperty(MDNS_SERVICE_STATUS, "stopped", 5s); + return binder::Status::ok(); +} + +binder::Status MDnsService::registerService(const RegistrationInfo&) { + // TODO(b/298594687): switch from EX_SERVICE_SPECIFIC to DEPRECATED when tethering module + // for 2024-02 release is fully rolled out and prebuilt updated in AP1A.xxxxxx.yy build. + // Return EX_SERVICE_SPECIFIC for short-term only because callers in tethering module do not + // catch the EX_UNSUPPORTED_OPERATION. It will throw an exception and cause a fatal exception. + // The EX_UNSUPPORTED_OPERATION has been catched in tethering module since 2024-02 release. + // TODO(b/298594687): switch to DEPRECATED. + return binder::Status::fromExceptionCode(binder::Status::EX_SERVICE_SPECIFIC); + // DEPRECATED; +} + +binder::Status MDnsService::discover(const DiscoveryInfo&) { + // TODO(b/298594687): switch to DEPRECATED. + return binder::Status::fromExceptionCode(binder::Status::EX_SERVICE_SPECIFIC); + // DEPRECATED; +} + +binder::Status MDnsService::resolve(const ResolutionInfo&) { + // TODO(b/298594687): switch to DEPRECATED. + return binder::Status::fromExceptionCode(binder::Status::EX_SERVICE_SPECIFIC); + // DEPRECATED; +} + +binder::Status MDnsService::getServiceAddress(const GetAddressInfo&) { + // TODO(b/298594687): switch to DEPRECATED. + return binder::Status::fromExceptionCode(binder::Status::EX_SERVICE_SPECIFIC); + // DEPRECATED; +} + +binder::Status MDnsService::stopOperation(int32_t) { + // TODO(b/298594687): switch to DEPRECATED. + return binder::Status::fromExceptionCode(binder::Status::EX_SERVICE_SPECIFIC); + // DEPRECATED; +} + +binder::Status MDnsService::registerEventListener(const android::sp<IMDnsEventListener>&) { + // TODO(b/298594687): switch to DEPRECATED. + return binder::Status::fromExceptionCode(binder::Status::EX_SERVICE_SPECIFIC); + // DEPRECATED; +} + +binder::Status MDnsService::unregisterEventListener(const android::sp<IMDnsEventListener>&) { + // TODO(b/298594687): switch to DEPRECATED. + return binder::Status::fromExceptionCode(binder::Status::EX_SERVICE_SPECIFIC); + // DEPRECATED; +} + +} // namespace android::net diff --git a/server/MDnsService.h b/server/MDnsService.h new file mode 100644 index 00000000..b8ead656 --- /dev/null +++ b/server/MDnsService.h @@ -0,0 +1,44 @@ +/** + * Copyright (c) 2022, 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. + */ + +#pragma once + +#include <android/net/mdns/aidl/BnMDns.h> +#include <binder/BinderService.h> + +namespace android::net { + +class MDnsService : public BinderService<MDnsService>, public android::net::mdns::aidl::BnMDns { + public: + static status_t start(); + static char const* getServiceName() { return "mdns"; } + + binder::Status startDaemon() override; + binder::Status stopDaemon() override; + binder::Status registerService( + const ::android::net::mdns::aidl::RegistrationInfo& info) override; + binder::Status discover(const ::android::net::mdns::aidl::DiscoveryInfo& info) override; + binder::Status resolve(const ::android::net::mdns::aidl::ResolutionInfo& info) override; + binder::Status getServiceAddress( + const ::android::net::mdns::aidl::GetAddressInfo& info) override; + binder::Status stopOperation(int32_t id) override; + binder::Status registerEventListener( + const android::sp<android::net::mdns::aidl::IMDnsEventListener>& listener) override; + binder::Status unregisterEventListener( + const android::sp<android::net::mdns::aidl::IMDnsEventListener>& listener) override; +}; + +} // namespace android::net diff --git a/server/main.cpp b/server/main.cpp index a3a111bc..b0c5406d 100644 --- a/server/main.cpp +++ b/server/main.cpp @@ -42,6 +42,7 @@ #include "Controllers.h" #include "FwmarkServer.h" +#include "MDnsService.h" #include "NFLogListener.h" #include "NetdConstants.h" #include "NetdHwAidlService.h" @@ -61,6 +62,7 @@ using android::net::FwmarkServer; using android::net::gCtls; using android::net::gLog; using android::net::makeNFLogListener; +using android::net::MDnsService; using android::net::NetdHwService; using android::net::NetdNativeService; using android::net::NetlinkManager; @@ -202,6 +204,12 @@ int main() { } gLog.info("Registering NetdNativeService: %" PRId64 "us", subTime.getTimeAndResetUs()); + if ((ret = MDnsService::start()) != android::OK) { + ALOGE("Unable to start MDnsService: %d", ret); + exit(1); + } + gLog.info("Registering MDnsService: %" PRId64 "us", subTime.getTimeAndResetUs()); + android::net::process::ScopedPidFile pidFile(PID_FILE_PATH); // Now that netd is ready to process commands, advertise service availability for HAL clients. diff --git a/server/netd.rc b/server/netd.rc index 79dbea41..d8250c2d 100644 --- a/server/netd.rc +++ b/server/netd.rc @@ -4,6 +4,7 @@ service netd /system/bin/netd user root group root net_admin socket dnsproxyd stream 0660 root inet + socket mdns stream 0660 root system socket fwmarkd stream 0660 root inet onrestart restart zygote onrestart restart zygote_secondary |