diff options
| author | Hungming Chen <nuccachen@google.com> | 2020-03-16 13:53:19 +0800 |
|---|---|---|
| committer | Hungming Chen <nuccachen@google.com> | 2020-06-05 16:24:52 +0800 |
| commit | 0c47671990d1b1e8672f38209faa76d184089b96 (patch) | |
| tree | e908e6b0ba656f3af2309843e69e9ebcbb2384ad /server/TetherController.cpp | |
| parent | 88c3ea4cb43a9d3d374383d82d4a6885c5b34e21 (diff) | |
Add binder call tetherOffloadSetInterfaceQuota
Provide binder calls for setting the limit for the given upstream
interface.
Bug: 150736748
Test: atest
Change-Id: I5def133022ee0ae232972c9ccffccd041b4b47a6
Diffstat (limited to 'server/TetherController.cpp')
| -rw-r--r-- | server/TetherController.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/server/TetherController.cpp b/server/TetherController.cpp index 851cfecd..1844ca9e 100644 --- a/server/TetherController.cpp +++ b/server/TetherController.cpp @@ -84,6 +84,10 @@ constexpr const char kTcpBeLiberal[] = "/proc/sys/net/netfilter/nf_conntrack_tcp // Chosen to match AID_DNS_TETHER, as made "friendly" by fs_config_generator.py. constexpr const char kDnsmasqUsername[] = "dns_tether"; +// A value used by interface quota indicates there is no limit. +// Sync from frameworks/base/core/java/android/net/netstats/provider/NetworkStatsProvider.java +constexpr int64_t QUOTA_UNLIMITED = -1; + bool writeToFile(const char* filename, const char* value) { int fd = open(filename, O_WRONLY | O_CLOEXEC); if (fd < 0) { @@ -1140,6 +1144,27 @@ void TetherController::maybeStopBpf(const char* extIface) { } } +int TetherController::setTetherOffloadInterfaceQuota(int ifIndex, int64_t maxBytes) { + if (!mBpfStatsMap.isValid() || !mBpfLimitMap.isValid()) return -ENOTSUP; + + if (ifIndex <= 0) return -ENODEV; + + if (maxBytes < QUOTA_UNLIMITED) { + ALOGE("Invalid bytes value. Must be -1 (unlimited) or 0..max_int64."); + return -ERANGE; + } + + // Note that a value of unlimited quota (-1) indicates simply max_uint64. + const auto res = setBpfLimit(static_cast<uint32_t>(ifIndex), static_cast<uint64_t>(maxBytes)); + if (!res.ok()) { + ALOGE("Fail to set quota %" PRId64 " for interface index %d: %s", maxBytes, ifIndex, + strerror(res.error().code())); + return -res.error().code(); + } + + return 0; +} + void TetherController::dumpIfaces(DumpWriter& dw) { dw.println("Interface pairs:"); |
