diff options
author | Xiao Ma <xiaom@google.com> | 2021-02-24 07:29:20 +0000 |
---|---|---|
committer | Xiao Ma <xiaom@google.com> | 2021-03-08 02:36:34 +0000 |
commit | b12f588c49ed984372e6d6bd0df4742a9a6cad0e (patch) | |
tree | e0514dac157722701ad17ac4d8fdf52fa67247fb /common | |
parent | 5bb30ebaef097a52c80ca8018c650f72a8aaa4bb (diff) | |
download | net-b12f588c49ed984372e6d6bd0df4742a9a6cad0e.tar.gz |
Address the comments left in the IPv6 utils change.
This follow-up change updates EtherType name in the Ethernet header
diagram, replaces "length" filed in the IPv6 header with "payloadLength",
and also make ND options constructor as package private to encapsulate
the constant params(e.g. ICMPv6 type/code).
Bug: 168868607
Test: atest NetworkStackIntegrationTest
Change-Id: Ia0500a7020fd9a85dce2a8c67c21b00b238a4e8d
Diffstat (limited to 'common')
7 files changed, 18 insertions, 15 deletions
diff --git a/common/device/com/android/net/module/util/structs/EthernetHeader.java b/common/device/com/android/net/module/util/structs/EthernetHeader.java index d895cfaa..92ef8a7e 100644 --- a/common/device/com/android/net/module/util/structs/EthernetHeader.java +++ b/common/device/com/android/net/module/util/structs/EthernetHeader.java @@ -40,7 +40,7 @@ import com.android.net.module.util.Struct.Type; * +- -+ * | Address | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * |1 0 0 0 0 1 1 0 1 1 0 1 1 1 0 1| + * | EtherType | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ public class EthernetHeader extends Struct { diff --git a/common/device/com/android/net/module/util/structs/Ipv6Header.java b/common/device/com/android/net/module/util/structs/Ipv6Header.java index 3ad81570..a14e064d 100644 --- a/common/device/com/android/net/module/util/structs/Ipv6Header.java +++ b/common/device/com/android/net/module/util/structs/Ipv6Header.java @@ -53,7 +53,7 @@ public class Ipv6Header extends Struct { @Field(order = 0, type = Type.S32) public int vtf; @Field(order = 1, type = Type.U16) - public int length; + public int payloadLength; @Field(order = 2, type = Type.S8) public byte nextHeader; @Field(order = 3, type = Type.U8) @@ -63,10 +63,10 @@ public class Ipv6Header extends Struct { @Field(order = 5, type = Type.Ipv6Address) public Inet6Address dstIp; - public Ipv6Header(final int vtf, final int length, final byte nextHeader, final short hopLimit, - final Inet6Address srcIp, final Inet6Address dstIp) { + public Ipv6Header(final int vtf, final int payloadLength, final byte nextHeader, + final short hopLimit, final Inet6Address srcIp, final Inet6Address dstIp) { this.vtf = vtf; - this.length = length; + this.payloadLength = payloadLength; this.nextHeader = nextHeader; this.hopLimit = hopLimit; this.srcIp = srcIp; diff --git a/common/device/com/android/net/module/util/structs/LlaOption.java b/common/device/com/android/net/module/util/structs/LlaOption.java index 2cdeefb2..fbaccabc 100644 --- a/common/device/com/android/net/module/util/structs/LlaOption.java +++ b/common/device/com/android/net/module/util/structs/LlaOption.java @@ -36,14 +36,16 @@ import java.nio.ByteOrder; */ public class LlaOption extends Struct { @Field(order = 0, type = Type.S8) - // 1 for Source Link-layer Address; 2 for Target Link-layer Address. public final byte type; @Field(order = 1, type = Type.S8) public final byte length; // Length in 8-byte units @Field(order = 2, type = Type.EUI48) + // Link layer address length and format varies on different link layers, which is not + // guaranteed to be a 6-byte MAC address. However, Struct only supports 6-byte MAC + // addresses type(EUI-48) for now. public final MacAddress linkLayerAddress; - public LlaOption(final byte type, final byte length, final MacAddress linkLayerAddress) { + LlaOption(final byte type, final byte length, final MacAddress linkLayerAddress) { this.type = type; this.length = length; this.linkLayerAddress = linkLayerAddress; @@ -54,6 +56,6 @@ public class LlaOption extends Struct { */ public static ByteBuffer build(final byte type, final MacAddress linkLayerAddress) { final LlaOption option = new LlaOption(type, (byte) 1 /* option len */, linkLayerAddress); - return ByteBuffer.wrap(option.writeToBytes(ByteOrder.nativeOrder())); + return ByteBuffer.wrap(option.writeToBytes(ByteOrder.BIG_ENDIAN)); } } diff --git a/common/device/com/android/net/module/util/structs/MtuOption.java b/common/device/com/android/net/module/util/structs/MtuOption.java index a35b5763..34bc21c1 100644 --- a/common/device/com/android/net/module/util/structs/MtuOption.java +++ b/common/device/com/android/net/module/util/structs/MtuOption.java @@ -46,7 +46,7 @@ public class MtuOption extends Struct { @Field(order = 3, type = Type.U32) public final long mtu; - public MtuOption(final byte type, final byte length, final short reserved, + MtuOption(final byte type, final byte length, final short reserved, final long mtu) { this.type = type; this.length = length; @@ -60,6 +60,6 @@ public class MtuOption extends Struct { public static ByteBuffer build(final long mtu) { final MtuOption option = new MtuOption((byte) ICMPV6_ND_OPTION_MTU, (byte) 1 /* option len */, (short) 0 /* reserved */, mtu); - return ByteBuffer.wrap(option.writeToBytes(ByteOrder.nativeOrder())); + return ByteBuffer.wrap(option.writeToBytes(ByteOrder.BIG_ENDIAN)); } } diff --git a/common/device/com/android/net/module/util/structs/NaHeader.java b/common/device/com/android/net/module/util/structs/NaHeader.java index 8101b061..571d67b3 100644 --- a/common/device/com/android/net/module/util/structs/NaHeader.java +++ b/common/device/com/android/net/module/util/structs/NaHeader.java @@ -23,7 +23,7 @@ import com.android.net.module.util.Struct.Type; import java.net.Inet6Address; /** - * ICMPv6 Neighbor Advertisement header, follow [Icmpv6Header], as per + * ICMPv6 Neighbor Advertisement header, follow {@link Icmpv6Header}, as per * https://tools.ietf.org/html/rfc4861. This does not contain any option. * * 0 1 2 3 diff --git a/common/device/com/android/net/module/util/structs/PrefixInformationOption.java b/common/device/com/android/net/module/util/structs/PrefixInformationOption.java index 7dc0192f..1bdee295 100644 --- a/common/device/com/android/net/module/util/structs/PrefixInformationOption.java +++ b/common/device/com/android/net/module/util/structs/PrefixInformationOption.java @@ -70,7 +70,7 @@ public class PrefixInformationOption extends Struct { @Field(order = 7, type = Type.ByteArray, arraysize = 16) public final byte[] prefix; - public PrefixInformationOption(final byte type, final byte length, final byte prefixLen, + PrefixInformationOption(final byte type, final byte length, final byte prefixLen, final byte flags, final long validLifetime, final long preferredLifetime, final int reserved, @NonNull final byte[] prefix) { this.type = type; @@ -92,6 +92,6 @@ public class PrefixInformationOption extends Struct { (byte) ICMPV6_ND_OPTION_PIO, (byte) 4 /* option len */, (byte) prefix.getPrefixLength(), flags, validLifetime, preferredLifetime, (int) 0, prefix.getRawAddress()); - return ByteBuffer.wrap(option.writeToBytes(ByteOrder.nativeOrder())); + return ByteBuffer.wrap(option.writeToBytes(ByteOrder.BIG_ENDIAN)); } } diff --git a/common/device/com/android/net/module/util/structs/RdnssOption.java b/common/device/com/android/net/module/util/structs/RdnssOption.java index de55e660..b7c2b0c1 100644 --- a/common/device/com/android/net/module/util/structs/RdnssOption.java +++ b/common/device/com/android/net/module/util/structs/RdnssOption.java @@ -53,8 +53,7 @@ public class RdnssOption extends Struct { @Field(order = 3, type = Type.U32) public final long lifetime; - public RdnssOption(final byte type, final byte length, final short reserved, - final long lifetime) { + RdnssOption(final byte type, final byte length, final short reserved, final long lifetime) { this.type = type; this.length = length; this.reserved = reserved; @@ -79,6 +78,8 @@ public class RdnssOption extends Struct { /** * Build a RDNSS option from the required specified String parameters. + * + * @throws IllegalArgumentException if {@code servers} does not contain only numeric addresses. */ public static ByteBuffer build(final long lifetime, final String... servers) { final Inet6Address[] serverArray = new Inet6Address[servers.length]; |