diff --git a/Tethering/apishim/31/com/android/networkstack/tethering/apishim/api31/BpfCoordinatorShimImpl.java b/Tethering/apishim/31/com/android/networkstack/tethering/apishim/api31/BpfCoordinatorShimImpl.java index d7868e3e0d..d53fc95725 100644 --- a/Tethering/apishim/31/com/android/networkstack/tethering/apishim/api31/BpfCoordinatorShimImpl.java +++ b/Tethering/apishim/31/com/android/networkstack/tethering/apishim/api31/BpfCoordinatorShimImpl.java @@ -34,6 +34,7 @@ import com.android.net.module.util.IBpfMap; import com.android.net.module.util.IBpfMap.ThrowingBiConsumer; import com.android.net.module.util.SharedLog; import com.android.net.module.util.Struct.S32; +import com.android.net.module.util.Struct.S64; import com.android.net.module.util.bpf.Tether4Key; import com.android.net.module.util.bpf.Tether4Value; import com.android.net.module.util.bpf.TetherStatsValue; @@ -43,7 +44,6 @@ import com.android.networkstack.tethering.BpfCoordinator.Ipv6UpstreamRule; import com.android.networkstack.tethering.BpfUtils; import com.android.networkstack.tethering.Tether6Value; import com.android.networkstack.tethering.TetherDownstream6Key; -import com.android.networkstack.tethering.TetherLimitValue; import com.android.networkstack.tethering.TetherUpstream6Key; import java.io.FileDescriptor; @@ -86,7 +86,7 @@ public class BpfCoordinatorShimImpl // BPF map of per-interface quota for tethering offload. @Nullable - private final IBpfMap mBpfLimitMap; + private final IBpfMap mBpfLimitMap; // BPF map of interface index mapping for XDP. @Nullable @@ -302,7 +302,7 @@ public class BpfCoordinatorShimImpl if (newLimit < rxBytes + txBytes) newLimit = QUOTA_UNLIMITED; try { - mBpfLimitMap.updateEntry(new S32(ifIndex), new TetherLimitValue(newLimit)); + mBpfLimitMap.updateEntry(new S32(ifIndex), new S64(newLimit)); } catch (ErrnoException e) { mLog.e("Fail to set quota " + quotaBytes + " for interface index " + ifIndex + ": ", e); return false; diff --git a/Tethering/src/com/android/networkstack/tethering/BpfCoordinator.java b/Tethering/src/com/android/networkstack/tethering/BpfCoordinator.java index c2226ccf19..412da9bc61 100644 --- a/Tethering/src/com/android/networkstack/tethering/BpfCoordinator.java +++ b/Tethering/src/com/android/networkstack/tethering/BpfCoordinator.java @@ -74,6 +74,7 @@ import com.android.net.module.util.InterfaceParams; import com.android.net.module.util.NetworkStackConstants; import com.android.net.module.util.SharedLog; import com.android.net.module.util.Struct.S32; +import com.android.net.module.util.Struct.S64; import com.android.net.module.util.bpf.Tether4Key; import com.android.net.module.util.bpf.Tether4Value; import com.android.net.module.util.bpf.TetherStatsValue; @@ -459,11 +460,11 @@ public class BpfCoordinator { } /** Get limit BPF map. */ - @Nullable public IBpfMap getBpfLimitMap() { + @Nullable public IBpfMap getBpfLimitMap() { if (!isAtLeastS()) return null; try { return new BpfMap<>(TETHER_LIMIT_MAP_PATH, - S32.class, TetherLimitValue.class); + S32.class, S64.class); } catch (ErrnoException e) { Log.e(TAG, "Cannot create limit map: " + e); return null; diff --git a/Tethering/src/com/android/networkstack/tethering/TetherLimitValue.java b/Tethering/src/com/android/networkstack/tethering/TetherLimitValue.java deleted file mode 100644 index 00dfcc6718..0000000000 --- a/Tethering/src/com/android/networkstack/tethering/TetherLimitValue.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (C) 2020 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.networkstack.tethering; - -import com.android.net.module.util.Struct; -import com.android.net.module.util.Struct.Field; -import com.android.net.module.util.Struct.Type; - -/** The value of BpfMap which is used for tethering per-interface limit. */ -public class TetherLimitValue extends Struct { - // Use the signed long variable to store the int64 limit on limit BPF map. - // S64 is enough for each interface limit even at 5Gbps for ~468 years. - // 2^63 / (5 * 1000 * 1000 * 1000) * 8 / 86400 / 365 = 468. - // Note that QUOTA_UNLIMITED (-1) indicates there is no limit. - @Field(order = 0, type = Type.S64) - public final long limit; - - public TetherLimitValue(final long limit) { - this.limit = limit; - } -} diff --git a/Tethering/tests/unit/src/com/android/networkstack/tethering/BpfCoordinatorTest.java b/Tethering/tests/unit/src/com/android/networkstack/tethering/BpfCoordinatorTest.java index 40de913747..1205f7bbed 100644 --- a/Tethering/tests/unit/src/com/android/networkstack/tethering/BpfCoordinatorTest.java +++ b/Tethering/tests/unit/src/com/android/networkstack/tethering/BpfCoordinatorTest.java @@ -122,6 +122,7 @@ import com.android.net.module.util.InterfaceParams; import com.android.net.module.util.NetworkStackConstants; import com.android.net.module.util.SharedLog; import com.android.net.module.util.Struct.S32; +import com.android.net.module.util.Struct.S64; import com.android.net.module.util.bpf.Tether4Key; import com.android.net.module.util.bpf.Tether4Value; import com.android.net.module.util.bpf.TetherStatsValue; @@ -481,8 +482,8 @@ public class BpfCoordinatorTest { spy(new TestBpfMap<>(TetherUpstream6Key.class, Tether6Value.class)); private final IBpfMap mBpfStatsMap = spy(new TestBpfMap<>(S32.class, TetherStatsValue.class)); - private final IBpfMap mBpfLimitMap = - spy(new TestBpfMap<>(S32.class, TetherLimitValue.class)); + private final IBpfMap mBpfLimitMap = + spy(new TestBpfMap<>(S32.class, S64.class)); private final IBpfMap mBpfDevMap = spy(new TestBpfMap<>(S32.class, S32.class)); private final IBpfMap mBpfErrorMap = @@ -558,7 +559,7 @@ public class BpfCoordinatorTest { } @Nullable - public IBpfMap getBpfLimitMap() { + public IBpfMap getBpfLimitMap() { return mBpfLimitMap; } @@ -932,7 +933,7 @@ public class BpfCoordinatorTest { 0L /* txPackets */, 0L /* txBytes */, 0L /* txErrors */)); } verifyWithOrder(inOrder, mBpfLimitMap).updateEntry(new S32(ifIndex), - new TetherLimitValue(quotaBytes)); + new S64(quotaBytes)); } else { verifyWithOrder(inOrder, mNetd).tetherOffloadSetInterfaceQuota(ifIndex, quotaBytes); }