summaryrefslogtreecommitdiff
path: root/server/TetherController.cpp
diff options
context:
space:
mode:
authorHungming Chen <nuccachen@google.com>2020-03-12 16:21:03 +0800
committerHungming Chen <nuccachen@google.com>2020-05-29 22:50:24 +0800
commitf40dc09cc7008ded099bd9d8a61df3ee92a23685 (patch)
tree74b793e6945f13cb42b15a211e3856ea3f464f54 /server/TetherController.cpp
parentf14b23d56eba8ed2d5c4be2a753a8444916c2069 (diff)
Add binder call tetherOffloadGetStats
This binder call is separated from the existing call tetherGetStats and used for for BPF tether stats. Note that the default value of ifIndex of TetherStatsParcel.aidl is applied for backward compatibility because it is added from this commit. Make netd modules to use netd_aidl_interface-unstable-cpp. Both netd and libnetd_server use unstable aidl for new api tetherOffload* and modified parcel TetherStatsParcel. Generated with: m netd_aidl_interface-update-api Bug: 150736748 Test: atest Change-Id: Ie03834bc40992a4abdc8ef70150569982092b386
Diffstat (limited to 'server/TetherController.cpp')
-rw-r--r--server/TetherController.cpp42
1 files changed, 13 insertions, 29 deletions
diff --git a/server/TetherController.cpp b/server/TetherController.cpp
index 50ae9661..04af0aee 100644
--- a/server/TetherController.cpp
+++ b/server/TetherController.cpp
@@ -81,10 +81,6 @@ const char IPV6_FORWARDING_PROC_FILE[] = "/proc/sys/net/ipv6/conf/all/forwarding
const char SEPARATOR[] = "|";
constexpr const char kTcpBeLiberal[] = "/proc/sys/net/netfilter/nf_conntrack_tcp_be_liberal";
-// Dummy interface name, the name needs to be longer than 16 characters so it can never conflict
-// with a real interface name. See also IFNAMSIZ.
-constexpr const char kBpfOffloadInterface[] = "BPFOffloadInterface";
-
// Chosen to match AID_DNS_TETHER, as made "friendly" by fs_config_generator.py.
constexpr const char kDnsmasqUsername[] = "dns_tether";
@@ -205,11 +201,6 @@ bool TetherController::disableForwarding(const char* requester) {
void TetherController::maybeInitMaps() {
if (!bpf::isBpfSupported()) return;
- // Used for parsing tether stats from BPF maps. If open the map failed, skip to open
- // tether BPF offload maps.
- mIfaceIndexNameMap.init(IFACE_INDEX_NAME_MAP_PATH);
- if (!mIfaceIndexNameMap.isValid()) return;
-
// Open BPF maps, ignoring errors because the device might not support BPF offload.
int fd = getTetherIngressMapFd();
if (fd >= 0) {
@@ -1027,32 +1018,25 @@ StatusOr<TetherController::TetherStatsList> TetherController::getTetherStats() {
}
}
- if (!mBpfStatsMap.isValid()) {
- return statsList;
- }
+ return statsList;
+}
- const auto processTetherStats = [this, &statsList](const uint32_t& key,
- const TetherStatsValue& value,
- const BpfMap<uint32_t, TetherStatsValue>&) {
- auto ifname = mIfaceIndexNameMap.readValue(key);
- if (!ifname.ok()) {
- // Keep on going regardless to parse as much as possible.
- return Result<void>();
- }
- // Because the same interface name can have different interface IDs over time, there might
- // already be a TetherStats in the list with this interface name. This is fine because
- // addStats will increment an existing TetherStats if there is one in the list already,
- // and add a new TetherStats to the list if there isn't.
- addStats(statsList,
- {kBpfOffloadInterface, ifname.value().name, static_cast<int64_t>(value.rxBytes),
- static_cast<int64_t>(value.rxPackets), static_cast<int64_t>(value.txBytes),
- static_cast<int64_t>(value.txPackets)});
+StatusOr<TetherController::TetherOffloadStatsList> TetherController::getTetherOffloadStats() {
+ TetherOffloadStatsList statsList;
+
+ const auto processTetherStats = [&statsList](const uint32_t& key, const TetherStatsValue& value,
+ const BpfMap<uint32_t, TetherStatsValue>&) {
+ statsList.push_back({.ifIndex = static_cast<int>(key),
+ .rxBytes = static_cast<int64_t>(value.rxBytes),
+ .rxPackets = static_cast<int64_t>(value.rxPackets),
+ .txBytes = static_cast<int64_t>(value.txBytes),
+ .txPackets = static_cast<int64_t>(value.txPackets)});
return Result<void>();
};
auto ret = mBpfStatsMap.iterateWithValue(processTetherStats);
if (!ret.ok()) {
- // Ignore error to return the non-BPF tether stats result.
+ // Ignore error to return the remaining tether stats result.
ALOGE("Error processing tether stats from BPF maps: %s", ret.error().message().c_str());
}