diff --git a/staticlibs/Android.bp b/staticlibs/Android.bp index 50cfb02b80..ea38eca46c 100644 --- a/staticlibs/Android.bp +++ b/staticlibs/Android.bp @@ -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", diff --git a/staticlibs/device/com/android/net/module/util/TcUtils.java b/staticlibs/device/com/android/net/module/util/TcUtils.java new file mode 100644 index 0000000000..14724d4628 --- /dev/null +++ b/staticlibs/device/com/android/net/module/util/TcUtils.java @@ -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; +}