diff --git a/src/proto/thread_telemetry.proto b/src/proto/thread_telemetry.proto index f3f16b18b8c..a3601b96d10 100644 --- a/src/proto/thread_telemetry.proto +++ b/src/proto/thread_telemetry.proto @@ -219,34 +219,36 @@ message TelemetryData { // The counters for inbound multicast packets optional PacketsAndBytes inbound_multicast = 16; - // The counter for inbound Internet when DHCPv6 PD enabled - optional PacketsAndBytes inbound_internet = 17; - // The counters for outbound unicast packets - optional PacketsAndBytes outbound_unicast = 18; + optional PacketsAndBytes outbound_unicast = 17; // The counters for outbound multicast packets - optional PacketsAndBytes outbound_multicast = 19; - - // The counter for outbound Internet when DHCPv6 PD enabled - optional PacketsAndBytes outbound_internet = 20; + optional PacketsAndBytes outbound_multicast = 18; // The inbound and outbound NAT64 traffic through the border router - optional Nat64ProtocolCounters nat64_protocol_counters = 21; + optional Nat64ProtocolCounters nat64_protocol_counters = 19; // Error counters for NAT64 translator on the border router - optional Nat64ErrorCounters nat64_error_counters = 22; + optional Nat64ErrorCounters nat64_error_counters = 20; + + // The counter for inbound Internet when DHCPv6 PD enabled + optional PacketsAndBytes inbound_internet = 21; + + // The counter for outbound Internet when DHCPv6 PD enabled + optional PacketsAndBytes outbound_internet = 22; } enum Dhcp6PdState { + DHCP6_PD_STATE_UNSPECIFIED = 0; + // DHCPv6 PD is disabled on the border router. - DHCP6_PD_STATE_DISABLED = 0; + DHCP6_PD_STATE_DISABLED = 1; // DHCPv6 PD in enabled but won't try to request and publish a prefix. - DHCP6_PD_STATE_STOPPED = 1; + DHCP6_PD_STATE_STOPPED = 2; // DHCPv6 PD is enabled and will try to request and publish a prefix. - DHCP6_PD_STATE_RUNNING =2; + DHCP6_PD_STATE_RUNNING = 3; } message PdProcessedRaInfo { @@ -464,7 +466,7 @@ message TelemetryData { optional Dhcp6PdState dhcp6_pd_state = 8; // DHCPv6 PD prefix - optional string pd_prefix = 9; + optional bytes hashed_pd_prefix = 9; // DHCPv6 PD processed RA Info optional PdProcessedRaInfo pd_processed_ra_info= 10; diff --git a/src/utils/thread_helper.cpp b/src/utils/thread_helper.cpp index 55fb756f786..b46f821c955 100644 --- a/src/utils/thread_helper.cpp +++ b/src/utils/thread_helper.cpp @@ -187,19 +187,26 @@ void CopyNat64TrafficCounters(const otNat64Counters &from, threadnetwork::Teleme #if OTBR_ENABLE_DHCP6_PD threadnetwork::TelemetryData_Dhcp6PdState Dhcp6PdStateFromOtDhcp6PdState(otBorderRoutingDhcp6PdState dhcp6PdState) { + threadnetwork::TelemetryData_Dhcp6PdState pdState = threadnetwork::TelemetryData::DHCP6_PD_STATE_UNSPECIFIED; + switch (dhcp6PdState) { case OT_BORDER_ROUTING_DHCP6_PD_STATE_DISABLED: - return threadnetwork::TelemetryData::DHCP6_PD_STATE_DISABLED; + pdState = threadnetwork::TelemetryData::DHCP6_PD_STATE_DISABLED; + break; case OT_BORDER_ROUTING_DHCP6_PD_STATE_STOPPED: - return threadnetwork::TelemetryData::DHCP6_PD_STATE_STOPPED; + pdState = threadnetwork::TelemetryData::DHCP6_PD_STATE_STOPPED; + break; case OT_BORDER_ROUTING_DHCP6_PD_STATE_RUNNING: - return threadnetwork::TelemetryData::DHCP6_PD_STATE_RUNNING; + pdState = threadnetwork::TelemetryData::DHCP6_PD_STATE_RUNNING; + break; default: - return threadnetwork::TelemetryData::DHCP6_PD_STATE_DISABLED; + break; } + + return pdState; } -#endif // OTBR_ENABLE_DHCP6_PD +#endif // OTBR_ENABLE_DHCP6_PD void CopyMdnsResponseCounters(const MdnsResponseCounters &from, threadnetwork::TelemetryData_MdnsResponseCounters *to) { @@ -219,10 +226,10 @@ ThreadHelper::ThreadHelper(otInstance *aInstance, otbr::Ncp::ControllerOpenThrea : mInstance(aInstance) , mNcp(aNcp) { -#if OTBR_ENABLE_TELEMETRY_DATA_API && OTBR_ENABLE_NAT64 +#if OTBR_ENABLE_TELEMETRY_DATA_API && OTBR_ENABLE_NAT64 || OTBR_ENABLE_DHCP6_PD otError error; - SuccessOrExit(error = otPlatCryptoRandomGet(mNat64Ipv6AddressSalt, sizeof(mNat64Ipv6AddressSalt))); + SuccessOrExit(error = otPlatCryptoRandomGet(mNat64PdCommonSalt, sizeof(mNat64PdCommonSalt))); exit: if (error != OT_ERROR_NONE) @@ -1162,10 +1169,6 @@ otError ThreadHelper::RetrieveTelemetryData(Mdns::Publisher *aPublisher, threadn otBorderRoutingCounters->mInboundMulticast.mPackets); borderRoutingCouters->mutable_inbound_multicast()->set_byte_count( otBorderRoutingCounters->mInboundMulticast.mBytes); - borderRoutingCouters->mutable_inbound_internet()->set_packet_count( - otBorderRoutingCounters->mInboundInternet.mPackets); - borderRoutingCouters->mutable_inbound_internet()->set_byte_count( - otBorderRoutingCounters->mInboundInternet.mBytes); borderRoutingCouters->mutable_outbound_unicast()->set_packet_count( otBorderRoutingCounters->mOutboundUnicast.mPackets); borderRoutingCouters->mutable_outbound_unicast()->set_byte_count( @@ -1174,16 +1177,20 @@ otError ThreadHelper::RetrieveTelemetryData(Mdns::Publisher *aPublisher, threadn otBorderRoutingCounters->mOutboundMulticast.mPackets); borderRoutingCouters->mutable_outbound_multicast()->set_byte_count( otBorderRoutingCounters->mOutboundMulticast.mBytes); - borderRoutingCouters->mutable_outbound_internet()->set_packet_count( - otBorderRoutingCounters->mOutboundInternet.mPackets); - borderRoutingCouters->mutable_outbound_internet()->set_byte_count( - otBorderRoutingCounters->mOutboundInternet.mBytes); borderRoutingCouters->set_ra_rx(otBorderRoutingCounters->mRaRx); borderRoutingCouters->set_ra_tx_success(otBorderRoutingCounters->mRaTxSuccess); borderRoutingCouters->set_ra_tx_failure(otBorderRoutingCounters->mRaTxFailure); borderRoutingCouters->set_rs_rx(otBorderRoutingCounters->mRsRx); borderRoutingCouters->set_rs_tx_success(otBorderRoutingCounters->mRsTxSuccess); borderRoutingCouters->set_rs_tx_failure(otBorderRoutingCounters->mRsTxFailure); + borderRoutingCouters->mutable_inbound_internet()->set_packet_count( + otBorderRoutingCounters->mInboundInternet.mPackets); + borderRoutingCouters->mutable_inbound_internet()->set_byte_count( + otBorderRoutingCounters->mInboundInternet.mBytes); + borderRoutingCouters->mutable_outbound_internet()->set_packet_count( + otBorderRoutingCounters->mOutboundInternet.mPackets); + borderRoutingCouters->mutable_outbound_internet()->set_byte_count( + otBorderRoutingCounters->mOutboundInternet.mBytes); #if OTBR_ENABLE_NAT64 { @@ -1368,10 +1375,10 @@ otError ThreadHelper::RetrieveTelemetryData(Mdns::Publisher *aPublisher, threadn CopyNat64TrafficCounters(otMapping.mCounters.mIcmp, nat64MappingCounters->mutable_icmp()); { - uint8_t ipAddrShaInput[OT_IP6_ADDRESS_SIZE + kNat64SourceAddressHashSaltLength]; + uint8_t ipAddrShaInput[OT_IP6_ADDRESS_SIZE + kNat64PdCommonHashSaltLength]; memcpy(ipAddrShaInput, otMapping.mIp6.mFields.m8, sizeof(otMapping.mIp6.mFields.m8)); - memcpy(&ipAddrShaInput[sizeof(otMapping.mIp6.mFields.m8)], mNat64Ipv6AddressSalt, - sizeof(mNat64Ipv6AddressSalt)); + memcpy(&ipAddrShaInput[sizeof(otMapping.mIp6.mFields.m8)], mNat64PdCommonSalt, + sizeof(mNat64PdCommonSalt)); sha256.Start(); sha256.Update(ipAddrShaInput, sizeof(ipAddrShaInput)); @@ -1388,31 +1395,45 @@ otError ThreadHelper::RetrieveTelemetryData(Mdns::Publisher *aPublisher, threadn #if OTBR_ENABLE_DHCP6_PD // Start of Dhcp6PdState section. { - auto dhcp6PdState = wpanBorderRouter->mutable_dhcp6_pd_state(); - dhcp6PdState->set_dhcp6_pd_state(Dhcp6PdStateFromOtDhcp6PdState(otBorderRoutingDhcp6PdGetState(mInstance))); + wpanBorderRouter->set_dhcp6_pd_state( + Dhcp6PdStateFromOtDhcp6PdState(otBorderRoutingDhcp6PdGetState(mInstance))); } // End of Dhcp6PdState section. // Start of PD prefix { - char buffer[OT_IP6_PREFIX_STRING_SIZE]; - otBorderRoutingGetPdOmrPrefix(mInstance, &aPrefixInfo); - otIp6PrefixToString(aPrefixInfo.mPrefix, buffer, sizeof(string)); - wpanBorderRouter->set_pd_prefix(buffer); + otBorderRoutingPrefixTableEntry aPrefixInfo; + Sha256::Hash hash; + Sha256 sha256; + + otBorderRoutingGetPdOmrPrefix(mInstance, &aPrefixInfo); + uint8_t pdPrefixShaInput[OT_IP6_ADDRESS_SIZE + kNat64PdCommonHashSaltLength]; + memcpy(pdPrefixShaInput, aPrefixInfo.mPrefix.mPrefix.mFields.m8, + sizeof(aPrefixInfo.mPrefix.mPrefix.mFields.m8)); + memcpy(&pdPrefixShaInput[sizeof(aPrefixInfo.mPrefix.mPrefix.mFields.m8)], mNat64PdCommonSalt, + sizeof(mNat64PdCommonSalt)); + + sha256.Start(); + sha256.Update(pdPrefixShaInput, sizeof(pdPrefixShaInput)); + sha256.Finish(hash); + + wpanBorderRouter->mutable_hashed_pd_prefix()->append(reinterpret_cast(hash.GetBytes()), + sizeof(hash.GetBytes())); } // End of PD prefix // Start of DHCPv6 PD processed RA Info { - auto pdProcessedRaInfo = wpanBorderRouter->mutable_pd_processed_ra_info(); + auto pdProcessedRaInfo = wpanBorderRouter->mutable_pd_processed_ra_info(); otPdProcessedRaInfo raInfo; + otBorderRoutingGetPdProcessedRaInfo(mInstance, &raInfo); pdProcessedRaInfo->set_num_platform_ra_received(raInfo.mNumPlatformRaReceived); pdProcessedRaInfo->set_num_platform_pio_processed(raInfo.mNumPlatformPioProcessed); pdProcessedRaInfo->set_last_platform_ra_msec(raInfo.mLastPlatformRaMsec); } // End of DHCPv6 PD processed RA Info -#endif // OTBR_ENABLE_DHCP6_PD - // End of WpanBorderRouter section. +#endif // OTBR_ENABLE_DHCP6_PD + // End of WpanBorderRouter section. // Start of WpanRcp section. { diff --git a/src/utils/thread_helper.hpp b/src/utils/thread_helper.hpp index b566e6632e8..97d8a891768 100644 --- a/src/utils/thread_helper.hpp +++ b/src/utils/thread_helper.hpp @@ -332,9 +332,9 @@ class ThreadHelper UpdateMeshCopTxtHandler mUpdateMeshCopTxtHandler; #endif -#if OTBR_ENABLE_TELEMETRY_DATA_API & OTBR_ENABLE_NAT64 - static const uint8_t kNat64SourceAddressHashSaltLength = 16; - uint8_t mNat64Ipv6AddressSalt[kNat64SourceAddressHashSaltLength]; +#if OTBR_ENABLE_TELEMETRY_DATA_API & OTBR_ENABLE_NAT64 || OTBR_ENABLE_DHCP6_PD + static const uint8_t kNat64PdCommonHashSaltLength = 16; + uint8_t mNat64PdCommonSalt[kNat64PdCommonHashSaltLength]; #endif }; diff --git a/tests/dbus/test_dbus_client.cpp b/tests/dbus/test_dbus_client.cpp index 1a79ad3d26e..0b826a438d9 100644 --- a/tests/dbus/test_dbus_client.cpp +++ b/tests/dbus/test_dbus_client.cpp @@ -287,7 +287,7 @@ void CheckTelemetryData(ThreadApiDBus *aApi) threadnetwork::TelemetryData::NAT64_STATE_NOT_RUNNING); #endif #if OTBR_ENABLE_DHCP6_PD - TEST_ASSERT(telemetryData.wpan_border_router().pd_prefix() != NULL); + TEST_ASSERT(!telemetryData.wpan_border_router().hashed_pd_prefix().empty()); #endif TEST_ASSERT(telemetryData.wpan_rcp().rcp_interface_statistics().transferred_frames_count() > 0); TEST_ASSERT(telemetryData.coex_metrics().count_tx_request() > 0);