Home | History | Annotate | Download | only in apf
      1 /*
      2  * Copyright (C) 2016 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 
     17 package android.net.apf;
     18 
     19 /**
     20  * APF program support capabilities.
     21  *
     22  * @hide
     23  */
     24 public class ApfCapabilities {
     25     /**
     26      * Version of APF instruction set supported for packet filtering. 0 indicates no support for
     27      * packet filtering using APF programs.
     28      */
     29     public final int apfVersionSupported;
     30 
     31     /**
     32      * Maximum size of APF program allowed.
     33      */
     34     public final int maximumApfProgramSize;
     35 
     36     /**
     37      * Format of packets passed to APF filter. Should be one of ARPHRD_*
     38      */
     39     public final int apfPacketFormat;
     40 
     41     public ApfCapabilities(int apfVersionSupported, int maximumApfProgramSize, int apfPacketFormat)
     42     {
     43         this.apfVersionSupported = apfVersionSupported;
     44         this.maximumApfProgramSize = maximumApfProgramSize;
     45         this.apfPacketFormat = apfPacketFormat;
     46     }
     47 
     48     public String toString() {
     49         return String.format("%s{version: %d, maxSize: %d, format: %d}", getClass().getSimpleName(),
     50                 apfVersionSupported, maximumApfProgramSize, apfPacketFormat);
     51     }
     52 
     53     /**
     54      * Returns true if the APF interpreter advertises support for the data buffer access opcodes
     55      * LDDW and STDW.
     56      *
     57      * Full LDDW and STDW support is present from APFv4 on.
     58      */
     59     public boolean hasDataAccess() {
     60         return apfVersionSupported >= 4;
     61     }
     62 }
     63