From fa94ca02f55f2035b3ffda428d2822ad12c3147b Mon Sep 17 00:00:00 2001 From: "Lo,Chin-Ran" Date: Thu, 24 Oct 2024 11:15:33 +0800 Subject: [PATCH] Restart DnssdServer on connectivity change, not only on ipv4, but also on ipv6 Signed-off-by: Lo,Chin-Ran --- .../Linux/ConnectivityManagerImpl.cpp | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/platform/Linux/ConnectivityManagerImpl.cpp b/src/platform/Linux/ConnectivityManagerImpl.cpp index c4989b0011d3c8..027fbbc06734f6 100644 --- a/src/platform/Linux/ConnectivityManagerImpl.cpp +++ b/src/platform/Linux/ConnectivityManagerImpl.cpp @@ -1781,19 +1781,29 @@ void ConnectivityManagerImpl::PostNetworkConnect() strncmp(ifName, sWiFiIfName, sizeof(ifName)) == 0) { chip::Inet::IPAddress addr; - if ((it.GetAddress(addr) == CHIP_NO_ERROR) && addr.IsIPv4()) + if (it.GetAddress(addr) != CHIP_NO_ERROR) { - ChipDeviceEvent event{ .Type = DeviceEventType::kInternetConnectivityChange, - .InternetConnectivityChange = { - .IPv4 = kConnectivity_Established, .IPv6 = kConnectivity_NoChange, .ipAddress = addr } }; - - char ipStrBuf[chip::Inet::IPAddress::kMaxStringLength] = { 0 }; - addr.ToString(ipStrBuf); - - ChipLogDetail(DeviceLayer, "Got IP address on interface: %s IP: %s", ifName, ipStrBuf); + ChipLogError(DeviceLayer, "Failed to got IP address on interface: %s", ifName); + continue; + } + ChipDeviceEvent event{ .Type = DeviceEventType::kInternetConnectivityChange, + .InternetConnectivityChange = { .ipAddress = addr } }; - PlatformMgr().PostEventOrDie(&event); + if (addr.IsIPv4()) + { + event.InternetConnectivityChange.IPv4 = kConnectivity_Established; + event.InternetConnectivityChange.IPv6 = kConnectivity_NoChange; } + else if (addr.IsIPv6()) + { + event.InternetConnectivityChange.IPv4 = kConnectivity_NoChange; + event.InternetConnectivityChange.IPv6 = kConnectivity_Established; + } + + char ipStrBuf[chip::Inet::IPAddress::kMaxStringLength] = { 0 }; + addr.ToString(ipStrBuf); + ChipLogDetail(DeviceLayer, "Got IP address on interface: %s IP: %s", ifName, ipStrBuf); + PlatformMgr().PostEventOrDie(&event); } }