From 8905d4926968ca355fc8e46499524da5cedb90ed Mon Sep 17 00:00:00 2001 From: Handa Wang Date: Thu, 16 Jan 2025 08:24:54 +0000 Subject: [PATCH] [Don't review] [dnssd-plat] integrate DnssdPlatform into Application Also add a workflow for testing this configuration. --- .github/workflows/border_router.yml | 12 +++++++++++- etc/cmake/options.cmake | 7 +++++++ etc/docker/Dockerfile | 2 ++ script/_otbr | 11 ++++++++++- src/agent/application.cpp | 20 ++++++++++++++++++++ src/agent/application.hpp | 6 ++++++ src/sdp_proxy/advertising_proxy.cpp | 4 ++++ third_party/openthread/CMakeLists.txt | 8 +++++++- 8 files changed, 67 insertions(+), 3 deletions(-) diff --git a/.github/workflows/border_router.yml b/.github/workflows/border_router.yml index e18ab4e9e49..450f8d87408 100644 --- a/.github/workflows/border_router.yml +++ b/.github/workflows/border_router.yml @@ -48,6 +48,7 @@ jobs: strategy: fail-fast: false matrix: + dnssd_plat: [0] include: - name: "Border Router (mDNSResponder)" otbr_options: "-DOT_DUA=ON -DOT_ECDSA=ON -DOT_MLR=ON -DOT_SERVICE=ON -DOT_SRP_SERVER=ON -DOTBR_COVERAGE=ON -DOTBR_DUA_ROUTING=ON -DOTBR_TREL=OFF -DOTBR_DNS_UPSTREAM_QUERY=ON" @@ -105,7 +106,14 @@ jobs: otbr_mdns: "avahi" cert_scripts: ./tests/scripts/thread-cert/border_router/*.py packet_verification: 2 - + - name: "Border Router with OT Core Advertising Proxy" + otbr_options: "-DOT_DUA=ON -DOT_ECDSA=ON -DOT_MLR=ON -DOT_SERVICE=ON -DOT_SRP_SERVER=ON -DOTBR_COVERAGE=ON -DOTBR_DUA_ROUTING=ON -DOTBR_TREL=ON -DOTBR_DNS_UPSTREAM_QUERY=ON" + border_routing: 1 + internet: 0 + otbr_mdns: "avahi" + dnssd_plat: 1 + cert_scripts: ./tests/scripts/thread-cert/border_router/*.py + packet_verification: 1 name: ${{ matrix.name }} env: @@ -120,6 +128,7 @@ jobs: INTER_OP_BBR: 0 BORDER_ROUTING: ${{ matrix.border_routing }} NAT64: ${{ matrix.internet }} + DNSSD_PLAT: ${{ matrix.dnssd_plat }} MAX_JOBS: 3 steps: - uses: actions/checkout@v4 @@ -153,6 +162,7 @@ jobs: --build-arg NAT64_SERVICE=openthread \ --build-arg DNS64="${{ matrix.internet }}" \ --build-arg MDNS="${{ matrix.otbr_mdns }}" \ + --build-arg DNSSD_PLAT="${{ matrix.dnssd_plat }}" \ --build-arg OTBR_OPTIONS="${otbr_options} -DCMAKE_CXX_FLAGS='-DOPENTHREAD_CONFIG_DNSSD_SERVER_BIND_UNSPECIFIED_NETIF=1'" - name: Bootstrap OpenThread Test if: ${{ success() && steps.check_cache_result.outputs.cache-hit != 'true' }} diff --git a/etc/cmake/options.cmake b/etc/cmake/options.cmake index c495d0ce9e2..dfac05869cf 100644 --- a/etc/cmake/options.cmake +++ b/etc/cmake/options.cmake @@ -171,3 +171,10 @@ if (OTBR_POWER_CALIBRATION) else() target_compile_definitions(otbr-config INTERFACE OTBR_ENABLE_POWER_CALIBRATION=0) endif() + +option(OTBR_DNSSD_PLAT "Enable OTBR DNS-SD platform implementation" OFF) +if (OTBR_DNSSD_PLAT) + target_compile_definitions(otbr-config INTERFACE OTBR_ENABLE_DNSSD_PLAT=1) +else() + target_compile_definitions(otbr-config INTERFACE OTBR_ENABLE_DNSSD_PLAT=0) +endif() diff --git a/etc/docker/Dockerfile b/etc/docker/Dockerfile index b4eed1f92cd..1e54b191518 100644 --- a/etc/docker/Dockerfile +++ b/etc/docker/Dockerfile @@ -43,6 +43,7 @@ ARG REST_API ARG WEB_GUI ARG MDNS ARG FIREWALL +ARG DNSSD_PLAT ENV INFRA_IF_NAME=${INFRA_IF_NAME:-eth0} ENV BORDER_ROUTING=${BORDER_ROUTING:-1} @@ -61,6 +62,7 @@ ENV DNS64=${DNS64:-0} ENV WEB_GUI=${WEB_GUI:-1} ENV REST_API=${REST_API:-1} ENV FIREWALL=${FIREWALL:-1} +ENV DNSSD_PLAT=${DNSSD_PLAT:-0} ENV DOCKER 1 RUN env diff --git a/script/_otbr b/script/_otbr index a6228a9d6ad..52748cd7cab 100644 --- a/script/_otbr +++ b/script/_otbr @@ -72,7 +72,6 @@ otbr_install() "-DCMAKE_INSTALL_PREFIX=/usr" "-DOTBR_DBUS=ON" "-DOTBR_DNSSD_DISCOVERY_PROXY=ON" - "-DOTBR_SRP_ADVERTISING_PROXY=ON" "-DOTBR_INFRA_IF_NAME=${INFRA_IF_NAME}" "-DOTBR_MDNS=${OTBR_MDNS:=mDNSResponder}" # Force re-evaluation of version strings @@ -81,6 +80,16 @@ otbr_install() "${otbr_options[@]}" ) + if with DNSSD_PLAT; then + otbr_options+=( + "-DOTBR_DNSSD_PLAT=ON" + ) + else + otbr_options+=( + "-DOTBR_SRP_ADVERTISING_PROXY=ON" + ) + fi + if with WEB_GUI; then otbr_options+=("-DOTBR_WEB=ON") fi diff --git a/src/agent/application.cpp b/src/agent/application.cpp index 1efa8478fb4..b54b56320a7 100644 --- a/src/agent/application.cpp +++ b/src/agent/application.cpp @@ -40,6 +40,7 @@ #include "agent/application.hpp" #include "common/code_utils.hpp" #include "common/mainloop_manager.hpp" +#include "host/posix/dnssd.hpp" #include "utils/infra_link_selector.hpp" namespace otbr { @@ -63,6 +64,9 @@ Application::Application(Host::ThreadHost &aHost, , mPublisher( Mdns::Publisher::Create([this](Mdns::Publisher::State aState) { mMdnsStateSubject.UpdateState(aState); })) #endif +#if OTBR_ENABLE_DNSSD_PLAT + , mDnssdPlatform(*mPublisher) +#endif #if OTBR_ENABLE_DBUS_SERVER && OTBR_ENABLE_BORDER_AGENT , mDBusAgent(MakeUnique(mHost, *mPublisher)) #endif @@ -221,6 +225,9 @@ void Application::CreateRcpMode(const std::string &aRestListenAddress, int aRest void Application::InitRcpMode(void) { + Host::RcpHost &rcpHost = static_cast(mHost); + OTBR_UNUSED_VARIABLE(rcpHost); + #if OTBR_ENABLE_BORDER_AGENT mMdnsStateSubject.AddObserver(*mBorderAgent); #endif @@ -233,6 +240,13 @@ void Application::InitRcpMode(void) #if OTBR_ENABLE_TREL mMdnsStateSubject.AddObserver(*mTrelDnssd); #endif +#if OTBR_ENABLE_DNSSD_PLAT + mMdnsStateSubject.AddObserver(mDnssdPlatform); + mDnssdPlatform.SetDnssdStateChangedCallback(([&rcpHost](otPlatDnssdState aState) { + OTBR_UNUSED_VARIABLE(aState); + otPlatDnssdStateHandleStateChange(rcpHost.GetInstance()); + })); +#endif #if OTBR_ENABLE_MDNS mPublisher->Start(); @@ -267,10 +281,16 @@ void Application::InitRcpMode(void) #if OTBR_ENABLE_VENDOR_SERVER mVendorServer->Init(); #endif +#if OTBR_ENABLE_DNSSD_PLAT + mDnssdPlatform.Start(); +#endif } void Application::DeinitRcpMode(void) { +#if OTBR_ENABLE_DNSSD_PLAT + mDnssdPlatform.Stop(); +#endif #if OTBR_ENABLE_SRP_ADVERTISING_PROXY mAdvertisingProxy->SetEnabled(false); #endif diff --git a/src/agent/application.hpp b/src/agent/application.hpp index 1ea905f4299..85aca7c35f7 100644 --- a/src/agent/application.hpp +++ b/src/agent/application.hpp @@ -61,6 +61,9 @@ #if OTBR_ENABLE_VENDOR_SERVER #include "agent/vendor.hpp" #endif +#if OTBR_ENABLE_DNSSD_PLAT +#include "host/posix/dnssd.hpp" +#endif #include "utils/infra_link_selector.hpp" namespace otbr { @@ -268,6 +271,9 @@ class Application : private NonCopyable Mdns::StateSubject mMdnsStateSubject; std::unique_ptr mPublisher; #endif +#if OTBR_ENABLE_DNSSD_PLAT + DnssdPlatform mDnssdPlatform; +#endif #if OTBR_ENABLE_BORDER_AGENT std::unique_ptr mBorderAgent; #endif diff --git a/src/sdp_proxy/advertising_proxy.cpp b/src/sdp_proxy/advertising_proxy.cpp index d59efcebeb3..c8f464e33d1 100644 --- a/src/sdp_proxy/advertising_proxy.cpp +++ b/src/sdp_proxy/advertising_proxy.cpp @@ -37,6 +37,10 @@ #if OTBR_ENABLE_SRP_ADVERTISING_PROXY +#if OPENTHREAD_CONFIG_SRP_SERVER_ADVERTISING_PROXY_ENABLE +#error "The Advertising Proxy is already enabled in OpenThread" +#endif + #if !OTBR_ENABLE_MDNS_AVAHI && !OTBR_ENABLE_MDNS_MDNSSD && !OTBR_ENABLE_MDNS_MOJO #error "The Advertising Proxy requires OTBR_ENABLE_MDNS_AVAHI, OTBR_ENABLE_MDNS_MDNSSD or OTBR_ENABLE_MDNS_MOJO" #endif diff --git a/third_party/openthread/CMakeLists.txt b/third_party/openthread/CMakeLists.txt index eab6e7c6007..330331308df 100644 --- a/third_party/openthread/CMakeLists.txt +++ b/third_party/openthread/CMakeLists.txt @@ -62,22 +62,28 @@ set(OT_NAT64_TRANSLATOR ${OTBR_NAT64} CACHE STRING "enable NAT64 translator" FOR set(OT_NETDATA_PUBLISHER ON CACHE STRING "enable netdata publisher" FORCE) set(OT_NETDIAG_CLIENT ON CACHE STRING "enable Network Diagnostic client" FORCE) set(OT_PLATFORM "posix" CACHE STRING "use posix platform" FORCE) +set(OT_PLATFORM_DNSSD ${OTBR_DNSSD_PLAT} CACHE STRING "enable platform DNSSD" FORCE) set(OT_PLATFORM_NETIF ON CACHE STRING "enable platform netif" FORCE) set(OT_PLATFORM_UDP ON CACHE STRING "enable platform UDP" FORCE) set(OT_SERVICE ON CACHE STRING "enable service" FORCE) set(OT_SLAAC ON CACHE STRING "enable SLAAC" FORCE) set(OT_SRP_CLIENT ON CACHE STRING "enable SRP client" FORCE) +set(OT_SRP_ADV_PROXY ${OTBR_DNSSD_PLAT} CACHE STRING "enable SRP Advertising Proxy" FORCE) set(OT_TARGET_OPENWRT ${OTBR_OPENWRT} CACHE STRING "target on OpenWRT" FORCE) set(OT_TCP OFF CACHE STRING "disable TCP") set(OT_TREL ${OTBR_TREL} CACHE STRING "enable TREL" FORCE) set(OT_UDP_FORWARD OFF CACHE STRING "disable udp forward" FORCE) set(OT_UPTIME ON CACHE STRING "enable uptime" FORCE) -if (OTBR_SRP_ADVERTISING_PROXY) +if (OTBR_DNSSD_PLAT OR OTBR_SRP_ADVERTISING_PROXY) set(OT_SRP_SERVER ON CACHE STRING "enable SRP server" FORCE) set(OT_EXTERNAL_HEAP ON CACHE STRING "enable external heap" FORCE) endif() +if (OT_SRP_ADV_PROXY AND OTBR_SRP_ADVERTISING_PROXY) + message(FATAL_ERROR "Only one Advertising Proxy can be enabled. ${OTBR_DNSSD_PLAT} ") +endif() + if (NOT OT_THREAD_VERSION STREQUAL "1.1") if (OT_REFERENCE_DEVICE) set(OT_DUA ON CACHE STRING "Enable Thread 1.2 DUA for reference devices")