summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/java/android/net/LinkAddress.java24
-rw-r--r--core/java/android/server/BluetoothService.java5
-rw-r--r--core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/AccessPointParserHelper.java24
-rw-r--r--services/java/com/android/server/connectivity/Tethering.java5
4 files changed, 15 insertions, 43 deletions
diff --git a/core/java/android/net/LinkAddress.java b/core/java/android/net/LinkAddress.java
index 3f03a2a..9c36b12 100644
--- a/core/java/android/net/LinkAddress.java
+++ b/core/java/android/net/LinkAddress.java
@@ -19,6 +19,7 @@ package android.net;
import android.os.Parcel;
import android.os.Parcelable;
+import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.InterfaceAddress;
import java.net.UnknownHostException;
@@ -38,12 +39,13 @@ public class LinkAddress implements Parcelable {
*/
private final int prefixLength;
- public LinkAddress(InetAddress address, InetAddress mask) {
- this.address = address;
- this.prefixLength = computeprefixLength(mask);
- }
-
public LinkAddress(InetAddress address, int prefixLength) {
+ if (address == null || prefixLength < 0 ||
+ ((address instanceof Inet4Address) && prefixLength > 32) ||
+ (prefixLength > 128)) {
+ throw new IllegalArgumentException("Bad LinkAddress params " + address +
+ prefixLength);
+ }
this.address = address;
this.prefixLength = prefixLength;
}
@@ -53,18 +55,6 @@ public class LinkAddress implements Parcelable {
this.prefixLength = interfaceAddress.getNetworkPrefixLength();
}
- private static int computeprefixLength(InetAddress mask) {
- int count = 0;
- for (byte b : mask.getAddress()) {
- for (int i = 0; i < 8; ++i) {
- if ((b & (1 << i)) != 0) {
- ++count;
- }
- }
- }
- return count;
- }
-
@Override
public String toString() {
return (address == null ? "" : (address.getHostAddress() + "/" + prefixLength));
diff --git a/core/java/android/server/BluetoothService.java b/core/java/android/server/BluetoothService.java
index df5097e..b6101b2 100644
--- a/core/java/android/server/BluetoothService.java
+++ b/core/java/android/server/BluetoothService.java
@@ -130,7 +130,7 @@ public class BluetoothService extends IBluetooth.Stub {
private static final String BLUETOOTH_IFACE_ADDR_START= "192.168.44.1";
private static final int BLUETOOTH_MAX_PAN_CONNECTIONS = 5;
- private static final String BLUETOOTH_NETMASK = "255.255.255.0";
+ private static final int BLUETOOTH_PREFIX_LENGTH = 24;
// The timeout used to sent the UUIDs Intent
// This timeout should be greater than the page timeout
@@ -1704,7 +1704,6 @@ public class BluetoothService extends IBluetooth.Stub {
try {
ifcg = service.getInterfaceConfig(iface);
if (ifcg != null) {
- InetAddress mask = InetAddress.getByName(BLUETOOTH_NETMASK);
InetAddress addr = null;
if (ifcg.addr == null || (addr = ifcg.addr.getAddress()) == null ||
addr.equals(InetAddress.getByName("0.0.0.0")) ||
@@ -1712,7 +1711,7 @@ public class BluetoothService extends IBluetooth.Stub {
addr = InetAddress.getByName(address);
}
ifcg.interfaceFlags = ifcg.interfaceFlags.replace("down", "up");
- ifcg.addr = new LinkAddress(addr, mask);
+ ifcg.addr = new LinkAddress(addr, BLUETOOTH_PREFIX_LENGTH);
ifcg.interfaceFlags = ifcg.interfaceFlags.replace("running", "");
ifcg.interfaceFlags = ifcg.interfaceFlags.replace(" "," ");
service.setInterfaceConfig(iface, ifcg);
diff --git a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/AccessPointParserHelper.java b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/AccessPointParserHelper.java
index 1ecf103..3667c7b 100644
--- a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/AccessPointParserHelper.java
+++ b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/AccessPointParserHelper.java
@@ -46,8 +46,8 @@ import java.util.List;
* <accesspoint></accesspoint>. The supported configuration includes: ssid,
* security, eap, phase2, identity, password, anonymousidentity, cacert, usercert,
* in which each is included in the corresponding tags. Static IP setting is also supported.
- * Tags that can be used include: ip, gateway, netmask, dns1, dns2. All access points have to be
- * enclosed in tags of <resources></resources>.
+ * Tags that can be used include: ip, gateway, networkprefixlength, dns1, dns2. All access points
+ * have to be enclosed in tags of <resources></resources>.
*
* The following is a sample configuration file for an access point using EAP-PEAP with MSCHAP2.
* <resources>
@@ -62,7 +62,8 @@ import java.util.List;
* </resources>
*
* Note:ssid and security have to be the first two tags
- * for static ip setting, tag "ip" should be listed before other fields: dns, gateway, netmask.
+ * for static ip setting, tag "ip" should be listed before other fields: dns, gateway,
+ * networkprefixlength.
*/
public class AccessPointParserHelper {
private static final String KEYSTORE_SPACE = "keystore://";
@@ -106,7 +107,6 @@ public class AccessPointParserHelper {
boolean ip = false;
boolean gateway = false;
boolean networkprefix = false;
- boolean netmask = false;
boolean dns1 = false;
boolean dns2 = false;
boolean eap = false;
@@ -163,9 +163,6 @@ public class AccessPointParserHelper {
if (tagName.equalsIgnoreCase("networkprefixlength")) {
networkprefix = true;
}
- if (tagName.equalsIgnoreCase("netmask")) {
- netmask = true;
- }
if (tagName.equalsIgnoreCase("dns1")) {
dns1 = true;
}
@@ -321,19 +318,6 @@ public class AccessPointParserHelper {
}
networkprefix = false;
}
- if (netmask) {
- try {
- String netMaskStr = new String(ch, start, length);
- if (!InetAddress.isNumeric(netMaskStr)) {
- throw new SAXException();
- }
- InetAddress netMaskAddr = InetAddress.getByName(netMaskStr);
- mLinkProperties.addLinkAddress(new LinkAddress(mInetAddr, netMaskAddr));
- } catch (UnknownHostException e) {
- throw new SAXException();
- }
- netmask = false;
- }
if (dns1) {
try {
String dnsAddr = new String(ch, start, length);
diff --git a/services/java/com/android/server/connectivity/Tethering.java b/services/java/com/android/server/connectivity/Tethering.java
index ff5f989..f24f96c 100644
--- a/services/java/com/android/server/connectivity/Tethering.java
+++ b/services/java/com/android/server/connectivity/Tethering.java
@@ -90,7 +90,7 @@ public class Tethering extends INetworkManagementEventObserver.Stub {
private BroadcastReceiver mStateReceiver;
private static final String USB_NEAR_IFACE_ADDR = "192.168.42.129";
- private static final String USB_NETMASK = "255.255.255.0";
+ private static final int USB_PREFIX_LENGTH = 24;
// USB is 192.168.42.1 and 255.255.255.0
// Wifi is 192.168.43.1 and 255.255.255.0
@@ -568,8 +568,7 @@ public class Tethering extends INetworkManagementEventObserver.Stub {
ifcg = service.getInterfaceConfig(iface);
if (ifcg != null) {
InetAddress addr = InetAddress.getByName(USB_NEAR_IFACE_ADDR);
- InetAddress mask = InetAddress.getByName(USB_NETMASK);
- ifcg.addr = new LinkAddress(addr, mask);
+ ifcg.addr = new LinkAddress(addr, USB_PREFIX_LENGTH);
if (enabled) {
ifcg.interfaceFlags = ifcg.interfaceFlags.replace("down", "up");
} else {