[Thread] tell ot-daemon about the DNS servers on the infra link
This CL passes the DNS servers' information to ot-daemon which was
fetched from LinkProperties of the infra link. This can enable the DNS
recursive resolver feature of the Thread Border Router.
The integration test case will be covered when aosp/3259932 is merged. Currently the test case CL cannot be merged because the there's a dependency PR in GitHub hasn't been merged: https://github.com/openthread/openthread/pull/10864.
Bug: 365892457
Bug: 354868095
Test: atest ThreadNetworkIntegrationTests:android.net.thread.InternetAccessTest
Change-Id: I66e54715ecaf8e0a43324d4afd4398e8884d8738
diff --git a/thread/service/java/com/android/server/thread/ThreadNetworkControllerService.java b/thread/service/java/com/android/server/thread/ThreadNetworkControllerService.java
index d5d24ac..ba4eeaf 100644
--- a/thread/service/java/com/android/server/thread/ThreadNetworkControllerService.java
+++ b/thread/service/java/com/android/server/thread/ThreadNetworkControllerService.java
@@ -145,11 +145,13 @@
import java.io.IOException;
import java.net.Inet6Address;
+import java.net.InetAddress;
import java.security.SecureRandom;
import java.time.Clock;
import java.time.DateTimeException;
import java.time.Instant;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -1342,6 +1344,7 @@
}
setInfraLinkInterfaceName(newInfraLinkState.interfaceName);
setInfraLinkNat64Prefix(newInfraLinkState.nat64Prefix);
+ setInfraLinkDnsServers(newInfraLinkState.dnsServers);
mInfraLinkState = newInfraLinkState;
}
@@ -1375,6 +1378,16 @@
}
}
+ private void setInfraLinkDnsServers(List<String> newDnsServers) {
+ try {
+ getOtDaemon()
+ .setInfraLinkDnsServers(
+ newDnsServers, new LoggingOtStatusReceiver("setInfraLinkDnsServers"));
+ } catch (RemoteException | ThreadNetworkException e) {
+ LOG.e("Failed to set infra link DNS servers " + newDnsServers, e);
+ }
+ }
+
private void handleThreadInterfaceStateChanged(boolean isUp) {
try {
mTunIfController.setInterfaceUp(isUp);
@@ -1520,7 +1533,17 @@
}
return new InfraLinkState.Builder()
.setInterfaceName(linkProperties.getInterfaceName())
- .setNat64Prefix(nat64Prefix);
+ .setNat64Prefix(nat64Prefix)
+ .setDnsServers(addressesToStrings(linkProperties.getDnsServers()));
+ }
+
+ private static List<String> addressesToStrings(List<InetAddress> addresses) {
+ List<String> strings = new ArrayList<>();
+
+ for (InetAddress address : addresses) {
+ strings.add(address.getHostAddress());
+ }
+ return strings;
}
private static final class CallbackMetadata {