Skip to content

Commit

Permalink
WLAN configuration (static address): reject IPv6 addresses.
Browse files Browse the repository at this point in the history
Without this, entering an IPv6 address as the interface address (or possibly
also others, such as gateway address) will, on connection to that WLAN,
trigger an uncaught exception:

*** FATAL EXCEPTION IN SYSTEM PROCESS: WifiStateMachine
java.lang.IllegalArgumentException: command '59 interface setcfg wlan0 2001:db8::ffff 24 up' failed with '501 59 Flag unsupported'
	at com.android.server.NetworkManagementService.setInterfaceConfig(NetworkManagementService.java:546)
	at android.net.wifi.WifiStateMachine$ObtainingIpState.enter(WifiStateMachine.java:3449)
	at com.android.internal.util.StateMachine$SmHandler.invokeEnterMethods(StateMachine.java:958)
[etc.]

followed by a restart of the UI then another connection attempt. So long as
the misconfigured-for AP is present (and preferred?), this will continue to
happen.

Change-Id: I524480339c37ad079fd21d90a6b1fc5864089cb5

Conflicts:

	src/com/android/settings/wifi/WifiConfigController.java
  • Loading branch information
dsalt authored and davros- committed Apr 29, 2013
1 parent 9fd38bf commit f18c384
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/com/android/settings/wifi/WifiConfigController.java
Expand Up @@ -55,6 +55,7 @@
import com.android.settings.R;

import java.net.InetAddress;
import java.net.Inet6Address;
import java.util.Iterator;

/**
Expand Down Expand Up @@ -456,6 +457,16 @@ private boolean ipAndProxyFieldsAreValid() {
return true;
}

private InetAddress numericToInet4Address(String addrString)
throws IllegalArgumentException {
// We need IPv4 for 'legacy' wireless networking static address assignments
InetAddress inetAddr = NetworkUtils.numericToInetAddress(addrString);
if (inetAddr instanceof Inet6Address) {
throw new IllegalArgumentException("Sorry, IPv4 only");
}
return inetAddr;
}

private int validateIpConfigFields(LinkProperties linkProperties) {
if (mIpAddressView == null) return 0;

Expand All @@ -464,7 +475,7 @@ private int validateIpConfigFields(LinkProperties linkProperties) {

InetAddress inetAddr = null;
try {
inetAddr = NetworkUtils.numericToInetAddress(ipAddr);
inetAddr = numericToInet4Address(ipAddr);
} catch (IllegalArgumentException e) {
return R.string.wifi_ip_settings_invalid_ip_address;
}
Expand Down Expand Up @@ -496,7 +507,7 @@ private int validateIpConfigFields(LinkProperties linkProperties) {
} else {
InetAddress gatewayAddr = null;
try {
gatewayAddr = NetworkUtils.numericToInetAddress(gateway);
gatewayAddr = numericToInet4Address(gateway);
} catch (IllegalArgumentException e) {
return R.string.wifi_ip_settings_invalid_gateway;
}
Expand All @@ -511,7 +522,7 @@ private int validateIpConfigFields(LinkProperties linkProperties) {
mDns1View.setText(mConfigUi.getContext().getString(R.string.wifi_dns1_hint));
} else {
try {
dnsAddr = NetworkUtils.numericToInetAddress(dns);
dnsAddr = numericToInet4Address(dns);
} catch (IllegalArgumentException e) {
return R.string.wifi_ip_settings_invalid_dns;
}
Expand All @@ -521,7 +532,7 @@ private int validateIpConfigFields(LinkProperties linkProperties) {
if (mDns2View.length() > 0) {
dns = mDns2View.getText().toString();
try {
dnsAddr = NetworkUtils.numericToInetAddress(dns);
dnsAddr = numericToInet4Address(dns);
} catch (IllegalArgumentException e) {
return R.string.wifi_ip_settings_invalid_dns;
}
Expand Down

0 comments on commit f18c384

Please sign in to comment.