Move BpfUtils -- add java class

Adding a TcUtils java class.

Bug: 202086915
Bug: 157552970
Test: atest TetheringTests
Change-Id: Ifb97d822bd96de6ed1a3fed547234ef32d691ad8
This commit is contained in:
Patrick Rohr 2022-01-12 21:42:24 +01:00
commit 29b0d95e1e
2 changed files with 66 additions and 0 deletions

View file

@ -112,6 +112,7 @@ java_library {
srcs: [
"device/com/android/net/module/util/BpfMap.java",
"device/com/android/net/module/util/JniUtil.java",
"device/com/android/net/module/util/TcUtils.java",
],
sdk_version: "system_current",
min_sdk_version: "29",

View file

@ -0,0 +1,65 @@
/*
* Copyright (C) 2022 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.net.module.util;
import java.io.IOException;
/**
* Contains mostly tc-related functionality.
*/
public class TcUtils {
/**
* Checks if the network interface uses an ethernet L2 header.
*
* @param iface the network interface.
* @return true if the interface uses an ethernet L2 header.
* @throws IOException
*/
public static native boolean isEthernet(String iface) throws IOException;
/**
* Attach a tc bpf filter.
*
* Equivalent to the following 'tc' command:
* tc filter add dev .. in/egress prio .. protocol ipv6/ip bpf object-pinned
* /sys/fs/bpf/... direct-action
*
* @param ifIndex the network interface index.
* @param ingress ingress or egress qdisc.
* @param prio
* @param proto
* @param bpfProgPath
* @throws IOException
*/
public static native void tcFilterAddDevBpf(int ifIndex, boolean ingress, short prio,
short proto, String bpfProgPath) throws IOException;
/**
* Delete a tc filter.
*
* Equivalent to the following 'tc' command:
* tc filter del dev .. in/egress prio .. protocol ..
*
* @param ifIndex the network interface index.
* @param ingress ingress or egress qdisc.
* @param prio the filter preference.
* @param proto protocol.
* @throws IOException
*/
public static native void tcFilterDelDev(int ifIndex, boolean ingress, short prio,
short proto) throws IOException;
}