From cdac749eb08193a8821cd209920b83a4246bc151 Mon Sep 17 00:00:00 2001 From: Patrick Rohr Date: Thu, 10 Feb 2022 15:13:29 +0100 Subject: [PATCH 1/3] Fix rate limiting settings observer The obvserver accidentally observed Settings.Secure instad of Settings.Global. Test: atest CtsNetTestCases:RateLimitTest Bug: 218840346 Change-Id: If5ade0c0e269c01b76428d5635d0913330d7015e --- service/src/com/android/server/ConnectivityService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service/src/com/android/server/ConnectivityService.java b/service/src/com/android/server/ConnectivityService.java index 6024a2a45f..d6ef6df76b 100644 --- a/service/src/com/android/server/ConnectivityService.java +++ b/service/src/com/android/server/ConnectivityService.java @@ -1752,7 +1752,7 @@ public class ConnectivityService extends IConnectivityManager.Stub // Watch for ingress rate limit changes. mSettingsObserver.observe( - Settings.Secure.getUriFor( + Settings.Global.getUriFor( ConnectivitySettingsManager.INGRESS_RATE_LIMIT_BYTES_PER_SECOND), EVENT_INGRESS_RATE_LIMIT_CHANGED); } From ff3b3f8d9671877fb80c2820a8dbd31d63cef9dc Mon Sep 17 00:00:00 2001 From: Patrick Rohr Date: Wed, 9 Feb 2022 15:15:52 +0100 Subject: [PATCH 2/3] Allow test networks to be rate limited Test: atest FrameworksNetTests Change-Id: I7e6e84baf446ecf4b395f6a611e625871745a20e --- service/src/com/android/server/ConnectivityService.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/service/src/com/android/server/ConnectivityService.java b/service/src/com/android/server/ConnectivityService.java index d6ef6df76b..008f8664a5 100644 --- a/service/src/com/android/server/ConnectivityService.java +++ b/service/src/com/android/server/ConnectivityService.java @@ -10684,8 +10684,11 @@ public class ConnectivityService extends IConnectivityManager.Stub } private boolean canNetworkBeRateLimited(@NonNull final NetworkAgentInfo networkAgent) { - if (!networkAgent.networkCapabilities.hasCapability(NET_CAPABILITY_INTERNET)) { - // rate limits only apply to networks that provide internet connectivity. + final NetworkCapabilities agentCaps = networkAgent.networkCapabilities; + // Only test networks (they cannot hold NET_CAPABILITY_INTERNET) and networks that provide + // internet connectivity can be rate limited. + if (!agentCaps.hasCapability(NET_CAPABILITY_INTERNET) && !agentCaps.hasTransport( + TRANSPORT_TEST)) { return false; } From 64592df482673e1140b0093762e1c375e9608372 Mon Sep 17 00:00:00 2001 From: Patrick Rohr Date: Thu, 10 Feb 2022 15:19:31 +0100 Subject: [PATCH 3/3] Improve logging when using ingress rate limits Add some happy path logging that informs about active rate limits. Test: TreeHugger Bug: 218840346 Change-Id: Iddd50583ca2e90afe83a5c68611418fa794afb3f --- service/src/com/android/server/ConnectivityService.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/service/src/com/android/server/ConnectivityService.java b/service/src/com/android/server/ConnectivityService.java index 008f8664a5..c323f2f5d2 100644 --- a/service/src/com/android/server/ConnectivityService.java +++ b/service/src/com/android/server/ConnectivityService.java @@ -1409,6 +1409,8 @@ public class ConnectivityService extends IConnectivityManager.Stub // converting rateInBytesPerSecond from long to int is safe here because the // setting's range is limited to INT_MAX. // TODO: add long/uint64 support to tcFilterAddDevIngressPolice. + Log.i(TAG, + "enableIngressRateLimit on " + iface + ": " + rateInBytesPerSecond + "B/s"); TcUtils.tcFilterAddDevIngressPolice(params.index, TC_PRIO_POLICE, (short) ETH_P_ALL, (int) rateInBytesPerSecond, TC_POLICE_BPF_PROG_PATH); } catch (IOException e) { @@ -1430,6 +1432,8 @@ public class ConnectivityService extends IConnectivityManager.Stub return; } try { + Log.i(TAG, + "disableIngressRateLimit on " + iface); TcUtils.tcFilterDelDev(params.index, true, TC_PRIO_POLICE, (short) ETH_P_ALL); } catch (IOException e) { loge("TcUtils.tcFilterDelDev(ifaceIndex=" + params.index