Skip to content
Snippets Groups Projects
Commit ecda769a authored by Yan Yan's avatar Yan Yan Committed by Gerrit Code Review
Browse files

Merge "[XFRM_MSG_GETSA] Fix the class names and code locations" into main

parents 30936555 f085fadf
No related branches found
No related tags found
No related merge requests found
......@@ -191,7 +191,7 @@ java_library {
java_library {
name: "net-utils-device-common-netlink",
srcs: [
"device/com/android/net/module/util/netlink/*.java",
"device/com/android/net/module/util/netlink/**/*.java",
],
sdk_version: "module_current",
min_sdk_version: "30",
......
......@@ -13,7 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.net.module.util.netlink;
package com.android.net.module.util.netlink.xfrm;
import static com.android.net.module.util.NetworkStackConstants.IPV4_ADDR_LEN;
import android.system.OsConstants;
......@@ -41,21 +43,19 @@ import java.net.UnknownHostException;
*
* @hide
*/
public class IpSecStructXfrmAddressT extends Struct {
private static final int IPV4_ADDRESS_LEN = 4;
public class StructXfrmAddressT extends Struct {
public static final int STRUCT_SIZE = 16;
@Field(order = 0, type = Type.ByteArray, arraysize = STRUCT_SIZE)
public final byte[] address;
// Constructor that allows Strutc.parse(Class<T>, ByteBuffer) to work
public IpSecStructXfrmAddressT(@NonNull byte[] address) {
public StructXfrmAddressT(@NonNull final byte[] address) {
this.address = address.clone();
}
// Constructor to build a new message
public IpSecStructXfrmAddressT(@NonNull InetAddress inetAddress) {
public StructXfrmAddressT(@NonNull final InetAddress inetAddress) {
this.address = new byte[STRUCT_SIZE];
final byte[] addressBytes = inetAddress.getAddress();
System.arraycopy(addressBytes, 0, address, 0, addressBytes.length);
......@@ -67,7 +67,7 @@ public class IpSecStructXfrmAddressT extends Struct {
if (family == OsConstants.AF_INET6) {
addressBytes = this.address;
} else if (family == OsConstants.AF_INET) {
addressBytes = new byte[IPV4_ADDRESS_LEN];
addressBytes = new byte[IPV4_ADDR_LEN];
System.arraycopy(this.address, 0, addressBytes, 0, addressBytes.length);
} else {
throw new IllegalArgumentException("Invalid IP family " + family);
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.net.module.util.netlink;
package com.android.net.module.util.netlink.xfrm;
import androidx.annotation.NonNull;
......@@ -40,7 +40,7 @@ import java.net.InetAddress;
*
* @hide
*/
public class IpSecStructXfrmUsersaId extends Struct {
public class StructXfrmUsersaId extends Struct {
public static final int STRUCT_SIZE = 24;
@Field(order = 0, type = Type.ByteArray, arraysize = 16)
......@@ -55,23 +55,23 @@ public class IpSecStructXfrmUsersaId extends Struct {
@Field(order = 3, type = Type.U8, padding = 1)
public final short proto;
@Computed private final IpSecStructXfrmAddressT mDestXfrmAddressT;
@Computed private final StructXfrmAddressT mDestXfrmAddressT;
// Constructor that allows Strutc.parse(Class<T>, ByteBuffer) to work
public IpSecStructXfrmUsersaId(
@NonNull byte[] nestedStructDAddr, long spi, int family, short proto) {
public StructXfrmUsersaId(
@NonNull final byte[] nestedStructDAddr, long spi, int family, short proto) {
this.nestedStructDAddr = nestedStructDAddr.clone();
this.spi = spi;
this.family = family;
this.proto = proto;
mDestXfrmAddressT = new IpSecStructXfrmAddressT(this.nestedStructDAddr);
mDestXfrmAddressT = new StructXfrmAddressT(this.nestedStructDAddr);
}
// Constructor to build a new message
public IpSecStructXfrmUsersaId(
@NonNull InetAddress destAddress, long spi, int family, short proto) {
this(new IpSecStructXfrmAddressT(destAddress).writeToBytes(), spi, family, proto);
public StructXfrmUsersaId(
@NonNull final InetAddress destAddress, long spi, int family, short proto) {
this(new StructXfrmAddressT(destAddress).writeToBytes(), spi, family, proto);
}
/** Return the destination address */
......
......@@ -14,21 +14,24 @@
* limitations under the License.
*/
package com.android.net.module.util.netlink;
package com.android.net.module.util.netlink.xfrm;
import androidx.annotation.NonNull;
import com.android.net.module.util.netlink.NetlinkMessage;
import com.android.net.module.util.netlink.StructNlMsgHdr;
/** Base calss for XFRM netlink messages */
// Developer notes: The Linux kernel includes a number of XFRM structs that are not standard netlink
// attributes (e.g., xfrm_usersa_id). These structs are unlikely to change size, so this XFRM
// netlink message implementation assumes their sizes will remain stable. If any non-attribute
// struct size changes, it should be caught by CTS and then developers should add
// kernel-version-based behvaiours.
public abstract class IpSecXfrmNetlinkMessage extends NetlinkMessage {
public abstract class XfrmNetlinkMessage extends NetlinkMessage {
// TODO: STOPSHIP: b/308011229 Remove it when OsConstants.IPPROTO_ESP is exposed
public static final int IPPROTO_ESP = 50;
public IpSecXfrmNetlinkMessage(@NonNull StructNlMsgHdr header) {
public XfrmNetlinkMessage(@NonNull final StructNlMsgHdr header) {
super(header);
}
......
......@@ -14,9 +14,9 @@
* limitations under the License.
*/
package com.android.net.module.util.netlink;
package com.android.net.module.util.netlink.xfrm;
import static com.android.net.module.util.netlink.IpSecXfrmNetlinkMessage.IPPROTO_ESP;
import static com.android.net.module.util.netlink.xfrm.XfrmNetlinkMessage.IPPROTO_ESP;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
......@@ -38,7 +38,7 @@ import java.nio.ByteOrder;
@RunWith(AndroidJUnit4.class)
@SmallTest
public class IpSecStructXfrmUsersaIdTest {
public class StructXfrmUsersaIdTest {
private static final String EXPECTED_HEX_STRING =
"C0000201000000000000000000000000" + "7768440002003200";
private static final byte[] EXPECTED_HEX = HexDump.hexStringToByteArray(EXPECTED_HEX_STRING);
......@@ -50,8 +50,7 @@ public class IpSecStructXfrmUsersaIdTest {
@Test
public void testEncode() throws Exception {
final IpSecStructXfrmUsersaId struct =
new IpSecStructXfrmUsersaId(DEST_ADDRESS, SPI, FAMILY, PROTO);
final StructXfrmUsersaId struct = new StructXfrmUsersaId(DEST_ADDRESS, SPI, FAMILY, PROTO);
ByteBuffer buffer = ByteBuffer.allocate(EXPECTED_HEX.length);
buffer.order(ByteOrder.nativeOrder());
......@@ -65,8 +64,8 @@ public class IpSecStructXfrmUsersaIdTest {
final ByteBuffer buffer = ByteBuffer.wrap(EXPECTED_HEX);
buffer.order(ByteOrder.nativeOrder());
final IpSecStructXfrmUsersaId struct =
IpSecStructXfrmUsersaId.parse(IpSecStructXfrmUsersaId.class, buffer);
final StructXfrmUsersaId struct =
StructXfrmUsersaId.parse(StructXfrmUsersaId.class, buffer);
assertEquals(DEST_ADDRESS, struct.getDestAddress());
assertEquals(SPI, struct.spi);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment