Merge "Support adding NATT keepalive packet filter"

This commit is contained in:
Mark Chien
2019-04-29 15:59:16 +00:00
committed by Gerrit Code Review
5 changed files with 61 additions and 10 deletions

View File

@@ -39,6 +39,7 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.net.LinkAddress;
import android.net.LinkProperties;
import android.net.NattKeepalivePacketDataParcelable;
import android.net.TcpKeepalivePacketDataParcelable;
import android.net.apf.ApfGenerator.IllegalInstructionException;
import android.net.apf.ApfGenerator.Register;
@@ -1691,13 +1692,13 @@ public class ApfFilter {
}
/**
* Add keepalive ack packet filter.
* Add TCP keepalive ack packet filter.
* This will add a filter to drop acks to the keepalive packet passed as an argument.
*
* @param slot The index used to access the filter.
* @param sentKeepalivePacket The attributes of the sent keepalive packet.
*/
public synchronized void addKeepalivePacketFilter(final int slot,
public synchronized void addTcpKeepalivePacketFilter(final int slot,
final TcpKeepalivePacketDataParcelable sentKeepalivePacket) {
log("Adding keepalive ack(" + slot + ")");
if (null != mKeepaliveAcks.get(slot)) {
@@ -1710,6 +1711,18 @@ public class ApfFilter {
installNewProgramLocked();
}
/**
* Add NATT keepalive packet filter.
* This will add a filter to drop NATT keepalive packet which is passed as an argument.
*
* @param slot The index used to access the filter.
* @param sentKeepalivePacket The attributes of the sent keepalive packet.
*/
public synchronized void addNattKeepalivePacketFilter(final int slot,
final NattKeepalivePacketDataParcelable sentKeepalivePacket) {
Log.e(TAG, "APF add NATT keepalive filter is not implemented");
}
/**
* Remove keepalive packet filter.
*

View File

@@ -29,6 +29,7 @@ import android.net.INetd;
import android.net.IpPrefix;
import android.net.LinkAddress;
import android.net.LinkProperties;
import android.net.NattKeepalivePacketDataParcelable;
import android.net.NetworkStackIpMemoryStore;
import android.net.ProvisioningConfigurationParcelable;
import android.net.ProxyInfo;
@@ -371,6 +372,10 @@ public class IpClient extends StateMachine {
private boolean mMulticastFiltering;
private long mStartTimeMillis;
/* This must match the definition in KeepaliveTracker.KeepaliveInfo */
private static final int TYPE_NATT = 1;
private static final int TYPE_TCP = 2;
/**
* Reading the snapshot is an asynchronous operation initiated by invoking
* Callback.startReadPacketFilter() and completed when the WiFi Service responds with an
@@ -553,6 +558,11 @@ public class IpClient extends StateMachine {
IpClient.this.addKeepalivePacketFilter(slot, pkt);
}
@Override
public void addNattKeepalivePacketFilter(int slot, NattKeepalivePacketDataParcelable pkt) {
checkNetworkStackCallingPermission();
IpClient.this.addNattKeepalivePacketFilter(slot, pkt);
}
@Override
public void removeKeepalivePacketFilter(int slot) {
checkNetworkStackCallingPermission();
IpClient.this.removeKeepalivePacketFilter(slot);
@@ -691,11 +701,20 @@ public class IpClient extends StateMachine {
}
/**
* Called by WifiStateMachine to add keepalive packet filter before setting up
* Called by WifiStateMachine to add TCP keepalive packet filter before setting up
* keepalive offload.
*/
public void addKeepalivePacketFilter(int slot, @NonNull TcpKeepalivePacketDataParcelable pkt) {
sendMessage(CMD_ADD_KEEPALIVE_PACKET_FILTER_TO_APF, slot, 0 /* Unused */, pkt);
sendMessage(CMD_ADD_KEEPALIVE_PACKET_FILTER_TO_APF, slot, TYPE_TCP, pkt);
}
/**
* Called by WifiStateMachine to add NATT keepalive packet filter before setting up
* keepalive offload.
*/
public void addNattKeepalivePacketFilter(int slot,
@NonNull NattKeepalivePacketDataParcelable pkt) {
sendMessage(CMD_ADD_KEEPALIVE_PACKET_FILTER_TO_APF, slot, TYPE_NATT, pkt);
}
/**
@@ -1607,9 +1626,16 @@ public class IpClient extends StateMachine {
case CMD_ADD_KEEPALIVE_PACKET_FILTER_TO_APF: {
final int slot = msg.arg1;
final int type = msg.arg2;
if (mApfFilter != null) {
mApfFilter.addKeepalivePacketFilter(slot,
(TcpKeepalivePacketDataParcelable) msg.obj);
if (type == TYPE_NATT) {
mApfFilter.addNattKeepalivePacketFilter(slot,
(NattKeepalivePacketDataParcelable) msg.obj);
} else {
mApfFilter.addTcpKeepalivePacketFilter(slot,
(TcpKeepalivePacketDataParcelable) msg.obj);
}
}
break;
}

View File

@@ -1553,7 +1553,7 @@ public class ApfTest {
parcel.seq = seqNum;
parcel.ack = ackNum;
apfFilter.addKeepalivePacketFilter(slot1, parcel);
apfFilter.addTcpKeepalivePacketFilter(slot1, parcel);
program = cb.getApfProgram();
// Verify IPv4 keepalive ack packet is dropped
@@ -1592,7 +1592,7 @@ public class ApfTest {
ipv6Parcel.seq = seqNum;
ipv6Parcel.ack = ackNum;
apfFilter.addKeepalivePacketFilter(slot1, ipv6Parcel);
apfFilter.addTcpKeepalivePacketFilter(slot1, ipv6Parcel);
program = cb.getApfProgram();
// Verify IPv6 keepalive ack packet is dropped
@@ -1614,8 +1614,8 @@ public class ApfTest {
apfFilter.removeKeepalivePacketFilter(slot1);
// Verify multiple filters
apfFilter.addKeepalivePacketFilter(slot1, parcel);
apfFilter.addKeepalivePacketFilter(slot2, ipv6Parcel);
apfFilter.addTcpKeepalivePacketFilter(slot1, parcel);
apfFilter.addTcpKeepalivePacketFilter(slot2, ipv6Parcel);
program = cb.getApfProgram();
// Verify IPv4 keepalive ack packet is dropped

View File

@@ -17,6 +17,7 @@ package android.net.ip;
import android.net.ProxyInfo;
import android.net.ProvisioningConfigurationParcelable;
import android.net.NattKeepalivePacketDataParcelable;
import android.net.TcpKeepalivePacketDataParcelable;
/** @hide */
@@ -33,4 +34,5 @@ oneway interface IIpClient {
void addKeepalivePacketFilter(int slot, in TcpKeepalivePacketDataParcelable pkt);
void removeKeepalivePacketFilter(int slot);
void setL2KeyAndGroupHint(in String l2Key, in String groupHint);
void addNattKeepalivePacketFilter(int slot, in NattKeepalivePacketDataParcelable pkt);
}

View File

@@ -567,6 +567,16 @@ public class ConnectivityServiceTest {
protected void preventAutomaticReconnect() {
mPreventReconnectReceived.open();
}
@Override
protected void addKeepalivePacketFilter(Message msg) {
Log.i(TAG, "Add keepalive packet filter.");
}
@Override
protected void removeKeepalivePacketFilter(Message msg) {
Log.i(TAG, "Remove keepalive packet filter.");
}
};
assertEquals(mNetworkAgent.netId, nmNetworkCaptor.getValue().netId);