1 /* 2 * Copyright (C) 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package android.net.apf; 17 18 import android.annotation.NonNull; 19 import android.annotation.Nullable; 20 import android.net.LinkProperties; 21 import android.net.NattKeepalivePacketDataParcelable; 22 import android.net.TcpKeepalivePacketDataParcelable; 23 24 import com.android.internal.util.IndentingPrintWriter; 25 26 /** 27 * The interface for AndroidPacketFilter 28 */ 29 public interface AndroidPacketFilter { 30 /** 31 * Update the LinkProperties that will be used by APF. 32 */ setLinkProperties(LinkProperties lp)33 void setLinkProperties(LinkProperties lp); 34 35 /** 36 * Shutdown the APF. 37 */ shutdown()38 void shutdown(); 39 40 /** 41 * Switch for the multicast filter. 42 * @param isEnabled if the multicast filter should be enabled or not. 43 */ setMulticastFilter(boolean isEnabled)44 void setMulticastFilter(boolean isEnabled); 45 46 /** 47 * Set the APF data snapshot and return the latest counter snapshot as a String. 48 */ setDataSnapshot(byte[] data)49 String setDataSnapshot(byte[] data); 50 51 /** 52 * Add TCP keepalive ack packet filter. 53 * This will add a filter to drop acks to the keepalive packet passed as an argument. 54 * 55 * @param slot The index used to access the filter. 56 * @param sentKeepalivePacket The attributes of the sent keepalive packet. 57 */ addTcpKeepalivePacketFilter(int slot, TcpKeepalivePacketDataParcelable sentKeepalivePacket)58 void addTcpKeepalivePacketFilter(int slot, 59 TcpKeepalivePacketDataParcelable sentKeepalivePacket); 60 61 /** 62 * Add NAT-T keepalive packet filter. 63 * This will add a filter to drop NAT-T keepalive packet which is passed as an argument. 64 * 65 * @param slot The index used to access the filter. 66 * @param sentKeepalivePacket The attributes of the sent keepalive packet. 67 */ addNattKeepalivePacketFilter(int slot, NattKeepalivePacketDataParcelable sentKeepalivePacket)68 void addNattKeepalivePacketFilter(int slot, 69 NattKeepalivePacketDataParcelable sentKeepalivePacket); 70 71 /** 72 * Remove keepalive packet filter. 73 * 74 * @param slot The index used to access the filter. 75 */ removeKeepalivePacketFilter(int slot)76 void removeKeepalivePacketFilter(int slot); 77 78 /** 79 * Dump the status of APF. 80 */ dump(IndentingPrintWriter pw)81 void dump(IndentingPrintWriter pw); 82 83 /** 84 * Indicates whether the ApfFilter is currently running / paused for test and debugging 85 * purposes. 86 */ isRunning()87 boolean isRunning(); 88 89 /** 90 * Indicates whether the clat interface is added or removed. 91 */ updateClatInterfaceState(boolean add)92 default void updateClatInterfaceState(boolean add) {} 93 94 /** Pause ApfFilter updates for testing purposes. */ pause()95 void pause(); 96 97 /** Resume ApfFilter updates for testing purposes. */ resume()98 void resume(); 99 100 /** Return hex string of current APF snapshot for testing purposes. */ getDataSnapshotHexString()101 @Nullable String getDataSnapshotHexString(); 102 103 /** 104 * Determines whether the APF interpreter advertises support for the data buffer access 105 * opcodes LDDW (LoaD Data Word) and STDW (STore Data Word). 106 */ hasDataAccess(@onNull ApfCapabilities capabilities)107 default boolean hasDataAccess(@NonNull ApfCapabilities capabilities) { 108 return capabilities.apfVersionSupported > 2; 109 } 110 } 111