summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRemi NGUYEN VAN <reminv@google.com>2024-02-06 02:57:52 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2024-02-06 02:57:52 +0000
commitf23c8385c82217ebf73c3dc0256baf07c866c0ab (patch)
treec09018bf590f02ff20d5c47dc3f65132de0cbcb7
parent351a46234247778a3ba31b7fd3a242cc501efbc3 (diff)
downloadnetd-f23c8385c82217ebf73c3dc0256baf07c866c0ab.tar.gz
Revert "Delete mdns from netd"
This reverts commit 351a46234247778a3ba31b7fd3a242cc501efbc3. Reason for revert: main is still used for U QPR, but this should be only removed in V Bug: 322305340 Bug: 322519244 Bug: 322519244 Change-Id: I0f1bd54e97b43a7eb7c366ae494cb4207d713888
-rw-r--r--server/Android.bp2
-rw-r--r--server/MDnsService.cpp128
-rw-r--r--server/MDnsService.h44
-rw-r--r--server/main.cpp8
-rw-r--r--server/netd.rc1
5 files changed, 183 insertions, 0 deletions
diff --git a/server/Android.bp b/server/Android.bp
index 882f0f0c..2aee802f 100644
--- a/server/Android.bp
+++ b/server/Android.bp
@@ -114,6 +114,7 @@ cc_defaults {
"libselinux",
"libsysutils",
"libutils",
+ "mdns_aidl_interface-V1-cpp",
"netd_event_listener_interface-V1-cpp",
"oemnetd_aidl_interface-cpp",
],
@@ -127,6 +128,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