Loading AndroidManifest.xml +1 −1 Original line number Diff line number Diff line Loading @@ -25,7 +25,7 @@ <!-- Permissions must be defined here, and not in the base manifest, as the network stack running in the system server process does not need any permission, and having privileged permissions added would cause crashes on startup unless they are also added to the privileged permissions whitelist for that package. --> privileged permissions allowlist for that package. --> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> Loading src/android/net/apf/ApfFilter.java +1 −1 Original line number Diff line number Diff line Loading @@ -778,7 +778,7 @@ public class ApfFilter { mPacket = ByteBuffer.wrap(Arrays.copyOf(packet, length)); mLastSeen = currentTimeSeconds(); // Sanity check packet in case a packet arrives before we attach RA filter // Check packet in case a packet arrives before we attach RA filter // to our packet socket. b/29586253 if (getUint16(mPacket, ETH_ETHERTYPE_OFFSET) != ETH_P_IPV6 || getUint8(mPacket, IPV6_NEXT_HEADER_OFFSET) != IPPROTO_ICMPV6 || Loading src/android/net/dhcp/DhcpServer.java +7 −1 Original line number Diff line number Diff line Loading @@ -99,6 +99,7 @@ public class DhcpServer extends StateMachine { private static final int CMD_UPDATE_PARAMS = 3; @VisibleForTesting protected static final int CMD_RECEIVE_PACKET = 4; private static final int CMD_TERMINATE_AFTER_STOP = 5; @NonNull private final Context mContext; Loading Loading @@ -362,10 +363,12 @@ public class DhcpServer extends StateMachine { * Stop listening for packets. * * <p>As the server is stopped asynchronously, some packets may still be processed shortly after * calling this method. * calling this method. The server will also be cleaned up and can't be started again, even if * it was already stopped. */ void stop(@Nullable INetworkStackStatusCallback cb) { sendMessage(CMD_STOP_DHCP_SERVER, cb); sendMessage(CMD_TERMINATE_AFTER_STOP); } private void maybeNotifyStatus(@Nullable INetworkStackStatusCallback cb, int statusCode) { Loading Loading @@ -407,6 +410,9 @@ public class DhcpServer extends StateMachine { mEventCallbacks = obj.second; transitionTo(mRunningState); return HANDLED; case CMD_TERMINATE_AFTER_STOP: quit(); return HANDLED; default: return NOT_HANDLED; } Loading tests/integration/src/android/net/ip/IpClientIntegrationTest.java +11 −7 Original line number Diff line number Diff line Loading @@ -1012,7 +1012,7 @@ public class IpClientIntegrationTest { assertNotNull(params.macAddr); assertTrue(params.hasMacAddress); // Sanity check. // Check interface "lo". params = InterfaceParams.getByName("lo"); assertNotNull(params); assertEquals("lo", params.name); Loading Loading @@ -1239,12 +1239,16 @@ public class IpClientIntegrationTest { == (byte) ICMPV6_ROUTER_SOLICITATION; } private void waitForRouterSolicitation() throws ParseException { byte[] packet; while ((packet = mPacketReader.popPacket(PACKET_TIMEOUT_MS)) != null) { if (isRouterSolicitation(packet)) return; } fail("No router solicitation received on interface within timeout"); /** * Wait for any router solicitation to have arrived since the packet reader was received. * * This method does not affect packets obtained via mPacketReader.popPacket. After any router * solicitation has been received, calls to this method will just return immediately. */ private void waitForRouterSolicitation() { assertNotNull("No router solicitation received on interface within timeout", mPacketReader.getReceivedPackets().poll( PACKET_TIMEOUT_MS, 0 /* pos */, this::isRouterSolicitation)); } private void sendRouterAdvertisement(boolean waitForRs, short lifetime) throws Exception { Loading tests/lib/src/com/android/testutils/TapPacketReader.java +8 −0 Original line number Diff line number Diff line Loading @@ -72,6 +72,14 @@ public class TapPacketReader extends PacketReader { return mReadHead.getValue().poll(timeoutMs, filter::test); } /** * Get the {@link ArrayTrackRecord} that records all packets received by the reader since its * creation. */ public ArrayTrackRecord<byte[]> getReceivedPackets() { return mReceivedPackets; } public void sendResponse(final ByteBuffer packet) throws IOException { try (FileOutputStream out = new FileOutputStream(mTapFd)) { byte[] packetBytes = new byte[packet.limit()]; Loading Loading
AndroidManifest.xml +1 −1 Original line number Diff line number Diff line Loading @@ -25,7 +25,7 @@ <!-- Permissions must be defined here, and not in the base manifest, as the network stack running in the system server process does not need any permission, and having privileged permissions added would cause crashes on startup unless they are also added to the privileged permissions whitelist for that package. --> privileged permissions allowlist for that package. --> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> Loading
src/android/net/apf/ApfFilter.java +1 −1 Original line number Diff line number Diff line Loading @@ -778,7 +778,7 @@ public class ApfFilter { mPacket = ByteBuffer.wrap(Arrays.copyOf(packet, length)); mLastSeen = currentTimeSeconds(); // Sanity check packet in case a packet arrives before we attach RA filter // Check packet in case a packet arrives before we attach RA filter // to our packet socket. b/29586253 if (getUint16(mPacket, ETH_ETHERTYPE_OFFSET) != ETH_P_IPV6 || getUint8(mPacket, IPV6_NEXT_HEADER_OFFSET) != IPPROTO_ICMPV6 || Loading
src/android/net/dhcp/DhcpServer.java +7 −1 Original line number Diff line number Diff line Loading @@ -99,6 +99,7 @@ public class DhcpServer extends StateMachine { private static final int CMD_UPDATE_PARAMS = 3; @VisibleForTesting protected static final int CMD_RECEIVE_PACKET = 4; private static final int CMD_TERMINATE_AFTER_STOP = 5; @NonNull private final Context mContext; Loading Loading @@ -362,10 +363,12 @@ public class DhcpServer extends StateMachine { * Stop listening for packets. * * <p>As the server is stopped asynchronously, some packets may still be processed shortly after * calling this method. * calling this method. The server will also be cleaned up and can't be started again, even if * it was already stopped. */ void stop(@Nullable INetworkStackStatusCallback cb) { sendMessage(CMD_STOP_DHCP_SERVER, cb); sendMessage(CMD_TERMINATE_AFTER_STOP); } private void maybeNotifyStatus(@Nullable INetworkStackStatusCallback cb, int statusCode) { Loading Loading @@ -407,6 +410,9 @@ public class DhcpServer extends StateMachine { mEventCallbacks = obj.second; transitionTo(mRunningState); return HANDLED; case CMD_TERMINATE_AFTER_STOP: quit(); return HANDLED; default: return NOT_HANDLED; } Loading
tests/integration/src/android/net/ip/IpClientIntegrationTest.java +11 −7 Original line number Diff line number Diff line Loading @@ -1012,7 +1012,7 @@ public class IpClientIntegrationTest { assertNotNull(params.macAddr); assertTrue(params.hasMacAddress); // Sanity check. // Check interface "lo". params = InterfaceParams.getByName("lo"); assertNotNull(params); assertEquals("lo", params.name); Loading Loading @@ -1239,12 +1239,16 @@ public class IpClientIntegrationTest { == (byte) ICMPV6_ROUTER_SOLICITATION; } private void waitForRouterSolicitation() throws ParseException { byte[] packet; while ((packet = mPacketReader.popPacket(PACKET_TIMEOUT_MS)) != null) { if (isRouterSolicitation(packet)) return; } fail("No router solicitation received on interface within timeout"); /** * Wait for any router solicitation to have arrived since the packet reader was received. * * This method does not affect packets obtained via mPacketReader.popPacket. After any router * solicitation has been received, calls to this method will just return immediately. */ private void waitForRouterSolicitation() { assertNotNull("No router solicitation received on interface within timeout", mPacketReader.getReceivedPackets().poll( PACKET_TIMEOUT_MS, 0 /* pos */, this::isRouterSolicitation)); } private void sendRouterAdvertisement(boolean waitForRs, short lifetime) throws Exception { Loading
tests/lib/src/com/android/testutils/TapPacketReader.java +8 −0 Original line number Diff line number Diff line Loading @@ -72,6 +72,14 @@ public class TapPacketReader extends PacketReader { return mReadHead.getValue().poll(timeoutMs, filter::test); } /** * Get the {@link ArrayTrackRecord} that records all packets received by the reader since its * creation. */ public ArrayTrackRecord<byte[]> getReceivedPackets() { return mReceivedPackets; } public void sendResponse(final ByteBuffer packet) throws IOException { try (FileOutputStream out = new FileOutputStream(mTapFd)) { byte[] packetBytes = new byte[packet.limit()]; Loading