aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYan Yan <evitayan@google.com>2019-10-31 17:40:49 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2019-10-31 17:40:49 +0000
commit0fe9e1f63424afaa5dcac2075d7edad0c04eeb7b (patch)
tree395dd736def26af21ff3c23ecb16b1ae09c362c9
parentdd35ecf8c697edf325538df9c4544e1914156a2c (diff)
parent630e023e06c4fc2ed27360bfe5634637a79bfca8 (diff)
downloadike-0fe9e1f63424afaa5dcac2075d7edad0c04eeb7b.tar.gz
Merge "Adding interface for requesting DHCPv4 server"
-rw-r--r--src/java/com/android/ike/ikev2/TunnelModeChildSessionOptions.java56
-rw-r--r--tests/iketests/src/java/com/android/ike/ikev2/TunnelModeChildSessionOptionsTest.java78
2 files changed, 109 insertions, 25 deletions
diff --git a/src/java/com/android/ike/ikev2/TunnelModeChildSessionOptions.java b/src/java/com/android/ike/ikev2/TunnelModeChildSessionOptions.java
index f43a6eaf..541930eb 100644
--- a/src/java/com/android/ike/ikev2/TunnelModeChildSessionOptions.java
+++ b/src/java/com/android/ike/ikev2/TunnelModeChildSessionOptions.java
@@ -24,6 +24,7 @@ import android.net.LinkAddress;
import com.android.ike.ikev2.message.IkeConfigPayload.ConfigAttribute;
import com.android.ike.ikev2.message.IkeConfigPayload.ConfigAttributeIpv4Address;
+import com.android.ike.ikev2.message.IkeConfigPayload.ConfigAttributeIpv4Dhcp;
import com.android.ike.ikev2.message.IkeConfigPayload.ConfigAttributeIpv4Dns;
import com.android.ike.ikev2.message.IkeConfigPayload.ConfigAttributeIpv4Netmask;
import com.android.ike.ikev2.message.IkeConfigPayload.ConfigAttributeIpv4Subnet;
@@ -85,10 +86,10 @@ public final class TunnelModeChildSessionOptions extends ChildSessionOptions {
}
/**
- * Adds internal address requests to TunnelModeChildSessionOptions being built.
+ * Adds internal IP address requests to TunnelModeChildSessionOptions being built.
*
- * @param addressFamily the address family. Only OsConstants.AF_INET and
- * OsConstants.AF_INET6 are allowed.
+ * @param addressFamily the address family. Only {@link OsConstants.AF_INET} and {@link
+ * OsConstants.AF_INET6} are allowed.
* @param numOfRequest the number of requests for this type of address.
* @return Builder this, to facilitate chaining.
*/
@@ -110,7 +111,7 @@ public final class TunnelModeChildSessionOptions extends ChildSessionOptions {
}
/**
- * Adds specific internal address request to TunnelModeChildSessionOptions being built.
+ * Adds specific internal IP address request to TunnelModeChildSessionOptions being built.
*
* @param address the requested address.
* @param prefixLen length of the InetAddress prefix. When requesting an IPv4 address,
@@ -137,8 +138,8 @@ public final class TunnelModeChildSessionOptions extends ChildSessionOptions {
/**
* Adds internal DNS server requests to TunnelModeChildSessionOptions being built.
*
- * @param addressFamily the address family. Only OsConstants.AF_INET and
- * OsConstants.AF_INET6 are allowed.
+ * @param addressFamily the address family. Only {@link OsConstants.AF_INET} and {@link
+ * OsConstants.AF_INET6} are allowed.
* @param numOfRequest the number of requests for this type of address.
* @return Builder this, to facilitate chaining.
*/
@@ -179,8 +180,8 @@ public final class TunnelModeChildSessionOptions extends ChildSessionOptions {
/**
* Adds internal subnet requests to TunnelModeChildSessionOptions being built.
*
- * @param addressFamily the address family. Only OsConstants.AF_INET and
- * OsConstants.AF_INET6 are allowed.
+ * @param addressFamily the address family. Only {@link OsConstants.AF_INET} and {@link
+ * OsConstants.AF_INET6} are allowed.
* @param numOfRequest the number of requests for this type of address.
* @return Builder this, to facilitate chaining.
*/
@@ -201,6 +202,43 @@ public final class TunnelModeChildSessionOptions extends ChildSessionOptions {
}
/**
+ * Adds internal DHCP server requests to TunnelModeChildSessionOptions being built.
+ *
+ * <p>Only DHCP4 server requests are supported.
+ *
+ * @param addressFamily the address family. Only {@link OsConstants.AF_INET} is allowed.
+ * @param numOfRequest the number of requests for this type of address.
+ * @return Builder this, to facilitate chaining.
+ */
+ public Builder addInternalDhcpServerRequest(int addressFamily, int numOfRequest) {
+ if (addressFamily == AF_INET) {
+ for (int i = 0; i < numOfRequest; i++) {
+ mConfigRequestList.add(new ConfigAttributeIpv4Dhcp());
+ }
+ return this;
+ } else {
+ throw new IllegalArgumentException("Invalid address family: " + addressFamily);
+ }
+ }
+
+ /**
+ * Adds internal DHCP server requests to TunnelModeChildSessionOptions being built.
+ *
+ * <p>Only DHCP4 server requests are supported.
+ *
+ * @param address the requested DHCP server address.
+ * @return Builder this, to facilitate chaining.
+ */
+ public Builder addInternalDhcpServerRequest(@NonNull InetAddress address) {
+ if (address instanceof Inet4Address) {
+ mConfigRequestList.add(new ConfigAttributeIpv4Dhcp((Inet4Address) address));
+ return this;
+ } else {
+ throw new IllegalArgumentException("Invalid address " + address);
+ }
+ }
+
+ /**
* Validates, builds and returns the TunnelModeChildSessionOptions.
*
* @return the validated TunnelModeChildSessionOptions.
@@ -220,6 +258,4 @@ public final class TunnelModeChildSessionOptions extends ChildSessionOptions {
mConfigRequestList.toArray(new ConfigAttribute[mConfigRequestList.size()]));
}
}
-
- // TODO: b/140644654 Add API for configuration requests.
}
diff --git a/tests/iketests/src/java/com/android/ike/ikev2/TunnelModeChildSessionOptionsTest.java b/tests/iketests/src/java/com/android/ike/ikev2/TunnelModeChildSessionOptionsTest.java
index 5ed6480c..e14e6e86 100644
--- a/tests/iketests/src/java/com/android/ike/ikev2/TunnelModeChildSessionOptionsTest.java
+++ b/tests/iketests/src/java/com/android/ike/ikev2/TunnelModeChildSessionOptionsTest.java
@@ -20,6 +20,7 @@ import static android.system.OsConstants.AF_INET;
import static android.system.OsConstants.AF_INET6;
import static com.android.ike.ikev2.message.IkeConfigPayload.CONFIG_ATTR_INTERNAL_IP4_ADDRESS;
+import static com.android.ike.ikev2.message.IkeConfigPayload.CONFIG_ATTR_INTERNAL_IP4_DHCP;
import static com.android.ike.ikev2.message.IkeConfigPayload.CONFIG_ATTR_INTERNAL_IP4_DNS;
import static com.android.ike.ikev2.message.IkeConfigPayload.CONFIG_ATTR_INTERNAL_IP4_NETMASK;
import static com.android.ike.ikev2.message.IkeConfigPayload.CONFIG_ATTR_INTERNAL_IP4_SUBNET;
@@ -51,6 +52,8 @@ public final class TunnelModeChildSessionOptionsTest {
private static final int IP4_PREFIX_LEN = 32;
private static final int IP6_PREFIX_LEN = 64;
+ private static final int INVALID_ADDR_FAMILY = 5;
+
private static final Inet4Address IPV4_ADDRESS =
(Inet4Address) (InetAddressUtils.parseNumericAddress("192.0.2.100"));
private static final Inet6Address IPV6_ADDRESS =
@@ -61,6 +64,8 @@ public final class TunnelModeChildSessionOptionsTest {
private static final Inet6Address IPV6_DNS_SERVER =
(Inet6Address) (InetAddressUtils.parseNumericAddress("2001:4860:4860::8888"));
+ private static final Inet4Address IPV4_DHCP_SERVER =
+ (Inet4Address) (InetAddressUtils.parseNumericAddress("192.0.2.200"));
private ChildSaProposal mSaProposal;
@Before
@@ -81,10 +86,10 @@ public final class TunnelModeChildSessionOptionsTest {
}
private void verifyAttrTypes(
- SparseArray exptectedAttrCntMap, TunnelModeChildSessionOptions childOptions) {
+ SparseArray expectedAttrCntMap, TunnelModeChildSessionOptions childOptions) {
ConfigAttribute[] configAttributes = childOptions.getConfigurationRequests();
- SparseArray<Integer> atrrCntMap = exptectedAttrCntMap.clone();
+ SparseArray<Integer> atrrCntMap = expectedAttrCntMap.clone();
for (int i = 0; i < configAttributes.length; i++) {
int attType = configAttributes[i].attributeType;
@@ -119,12 +124,12 @@ public final class TunnelModeChildSessionOptionsTest {
verifyCommon(childOptions);
- SparseArray<Integer> exptectedAttrCntMap = new SparseArray<>();
- exptectedAttrCntMap.put(CONFIG_ATTR_INTERNAL_IP4_ADDRESS, 2);
- exptectedAttrCntMap.put(CONFIG_ATTR_INTERNAL_IP6_ADDRESS, 3);
- exptectedAttrCntMap.put(CONFIG_ATTR_INTERNAL_IP4_NETMASK, 1);
+ SparseArray<Integer> expectedAttrCntMap = new SparseArray<>();
+ expectedAttrCntMap.put(CONFIG_ATTR_INTERNAL_IP4_ADDRESS, 2);
+ expectedAttrCntMap.put(CONFIG_ATTR_INTERNAL_IP6_ADDRESS, 3);
+ expectedAttrCntMap.put(CONFIG_ATTR_INTERNAL_IP4_NETMASK, 1);
- verifyAttrTypes(exptectedAttrCntMap, childOptions);
+ verifyAttrTypes(expectedAttrCntMap, childOptions);
}
@Test
@@ -153,11 +158,11 @@ public final class TunnelModeChildSessionOptionsTest {
verifyCommon(childOptions);
- SparseArray<Integer> exptectedAttrCntMap = new SparseArray<>();
- exptectedAttrCntMap.put(CONFIG_ATTR_INTERNAL_IP4_DNS, 2);
- exptectedAttrCntMap.put(CONFIG_ATTR_INTERNAL_IP6_DNS, 2);
+ SparseArray<Integer> expectedAttrCntMap = new SparseArray<>();
+ expectedAttrCntMap.put(CONFIG_ATTR_INTERNAL_IP4_DNS, 2);
+ expectedAttrCntMap.put(CONFIG_ATTR_INTERNAL_IP6_DNS, 2);
- verifyAttrTypes(exptectedAttrCntMap, childOptions);
+ verifyAttrTypes(expectedAttrCntMap, childOptions);
}
@Test
@@ -171,11 +176,54 @@ public final class TunnelModeChildSessionOptionsTest {
verifyCommon(childOptions);
- SparseArray<Integer> exptectedAttrCntMap = new SparseArray<>();
- exptectedAttrCntMap.put(CONFIG_ATTR_INTERNAL_IP4_SUBNET, 1);
- exptectedAttrCntMap.put(CONFIG_ATTR_INTERNAL_IP6_SUBNET, 1);
+ SparseArray<Integer> expectedAttrCntMap = new SparseArray<>();
+ expectedAttrCntMap.put(CONFIG_ATTR_INTERNAL_IP4_SUBNET, 1);
+ expectedAttrCntMap.put(CONFIG_ATTR_INTERNAL_IP6_SUBNET, 1);
+
+ verifyAttrTypes(expectedAttrCntMap, childOptions);
+ }
+
+ @Test
+ public void testBuildChildSessionOptionsWithDhcpServerReq() {
+ TunnelModeChildSessionOptions childOptions =
+ new TunnelModeChildSessionOptions.Builder()
+ .addSaProposal(mSaProposal)
+ .addInternalDhcpServerRequest(AF_INET, 3)
+ .addInternalDhcpServerRequest(IPV4_DHCP_SERVER)
+ .build();
+
+ verifyCommon(childOptions);
+
+ SparseArray<Integer> expectedAttrCntMap = new SparseArray<>();
+ expectedAttrCntMap.put(CONFIG_ATTR_INTERNAL_IP4_DHCP, 4);
+
+ verifyAttrTypes(expectedAttrCntMap, childOptions);
+ }
+
+ @Test
+ public void testBuildChildSessionOptionsWithDhcp6SeverReq() {
+ try {
+ new TunnelModeChildSessionOptions.Builder()
+ .addSaProposal(mSaProposal)
+ .addInternalDhcpServerRequest(AF_INET6, 3)
+ .build();
+ fail("Expected to fail because DHCP6 is not supported.");
+ } catch (IllegalArgumentException expected) {
+
+ }
+ }
+
+ @Test
+ public void testBuildChildSessionOptionsWithInvalidDhcpReq() {
+ try {
+ new TunnelModeChildSessionOptions.Builder()
+ .addSaProposal(mSaProposal)
+ .addInternalDhcpServerRequest(INVALID_ADDR_FAMILY, 3)
+ .build();
+ fail("Expected to fail due to invalid address family value");
+ } catch (IllegalArgumentException expected) {
- verifyAttrTypes(exptectedAttrCntMap, childOptions);
+ }
}
}