summaryrefslogtreecommitdiff
path: root/java/com/android/server/ethernet
diff options
context:
space:
mode:
authorPavel Maltsev <pavelm@google.com>2018-05-30 11:20:46 -0700
committerPavel Maltsev <pavelm@google.com>2018-05-30 22:39:34 -0700
commit1e53f6b418d977186f945cd9d646f18f770db346 (patch)
tree3a5c9c6dc299819de04cee113981e12a81b7a65c /java/com/android/server/ethernet
parent3ba232bcf0c1fcefc7f573a4ca8b293054ec8e4f (diff)
downloadethernet-1e53f6b418d977186f945cd9d646f18f770db346.tar.gz
In addition to IP address, OEMs should be able to set gateway, DNS and domains. Bug: 80090920 Test: runtest -x frameworks/opt/net/ethernet/tests Change-Id: I4e3d51a6955d7bfe5ca4e8079936ea10c28832e4
Diffstat (limited to 'java/com/android/server/ethernet')
-rw-r--r--java/com/android/server/ethernet/EthernetTracker.java58
1 files changed, 52 insertions, 6 deletions
diff --git a/java/com/android/server/ethernet/EthernetTracker.java b/java/com/android/server/ethernet/EthernetTracker.java
index 688d84a..00eedd5 100644
--- a/java/com/android/server/ethernet/EthernetTracker.java
+++ b/java/com/android/server/ethernet/EthernetTracker.java
@@ -36,10 +36,13 @@ import android.text.TextUtils;
import android.util.ArrayMap;
import android.util.Log;
+import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.IndentingPrintWriter;
import com.android.server.net.BaseNetworkObserver;
import java.io.FileDescriptor;
+import java.net.InetAddress;
+import java.util.ArrayList;
import java.util.concurrent.ConcurrentHashMap;
/**
@@ -300,7 +303,7 @@ final class EthernetTracker {
mNetworkCapabilities.put(name, nc);
if (tokens.length > 2 && !TextUtils.isEmpty(tokens[2])) {
- IpConfiguration ipConfig = createStaticIpConfiguration(tokens[2]);
+ IpConfiguration ipConfig = parseStaticIpConfiguration(tokens[2]);
mIpConfigurations.put(name, ipConfig);
}
}
@@ -342,11 +345,54 @@ final class EthernetTracker {
return nc;
}
- private static IpConfiguration createStaticIpConfiguration(String strIpAddress) {
- StaticIpConfiguration staticIpConfiguration = new StaticIpConfiguration();
- staticIpConfiguration.ipAddress = new LinkAddress(strIpAddress);
- return new IpConfiguration(
- IpAssignment.STATIC, ProxySettings.NONE, staticIpConfiguration, null);
+ /**
+ * Parses static IP configuration.
+ *
+ * @param staticIpConfig represents static IP configuration in the following format: {@code
+ * ip=<ip-address/mask> gateway=<ip-address> dns=<comma-sep-ip-addresses>
+ * domains=<comma-sep-domains>}
+ */
+ @VisibleForTesting
+ static IpConfiguration parseStaticIpConfiguration(String staticIpConfig) {
+ StaticIpConfiguration ipConfig = new StaticIpConfiguration();
+
+ for (String keyValueAsString : staticIpConfig.trim().split(" ")) {
+ if (TextUtils.isEmpty(keyValueAsString)) continue;
+
+ String[] pair = keyValueAsString.split("=");
+ if (pair.length != 2) {
+ throw new IllegalArgumentException("Unexpected token: " + keyValueAsString
+ + " in " + staticIpConfig);
+ }
+
+ String key = pair[0];
+ String value = pair[1];
+
+ switch (key) {
+ case "ip":
+ ipConfig.ipAddress = new LinkAddress(value);
+ break;
+ case "domains":
+ ipConfig.domains = value;
+ break;
+ case "gateway":
+ ipConfig.gateway = InetAddress.parseNumericAddress(value);
+ break;
+ case "dns": {
+ ArrayList<InetAddress> dnsAddresses = new ArrayList<>();
+ for (String address: value.split(",")) {
+ dnsAddresses.add(InetAddress.parseNumericAddress(address));
+ }
+ ipConfig.dnsServers.addAll(dnsAddresses);
+ break;
+ }
+ default : {
+ throw new IllegalArgumentException("Unexpected key: " + key
+ + " in " + staticIpConfig);
+ }
+ }
+ }
+ return new IpConfiguration(IpAssignment.STATIC, ProxySettings.NONE, ipConfig, null);
}
private static IpConfiguration createDefaultIpConfiguration() {