BpfNetworkStats: implement bpfRegisterIface() and wire it up
Test: TreeHugger atest libnetworkstats_test a_test --iterations=100 NetworkStackIntegrationTests:android.net.NetworkStatsIntegrationTest Bug: 292156770 Signed-off-by: Maciej Żenczykowski <maze@google.com> Change-Id: I3b1038f6fb306ed8f2d20a73d2f7c36593cbd739
This commit is contained in:
parent
f798c91551
commit
80efc3a697
3 changed files with 17 additions and 2 deletions
|
|
@ -34,11 +34,15 @@
|
|||
|
||||
using android::bpf::bpfGetUidStats;
|
||||
using android::bpf::bpfGetIfaceStats;
|
||||
using android::bpf::bpfRegisterIface;
|
||||
using android::bpf::NetworkTraceHandler;
|
||||
|
||||
namespace android {
|
||||
|
||||
static void nativeRegisterIface(JNIEnv* env, jclass clazz, jstring iface) {
|
||||
ScopedUtfChars iface8(env, iface);
|
||||
if (iface8.c_str() == nullptr) return;
|
||||
bpfRegisterIface(iface8.c_str());
|
||||
}
|
||||
|
||||
static jobject statsValueToEntry(JNIEnv* env, StatsValue* stats) {
|
||||
|
|
|
|||
|
|
@ -40,8 +40,8 @@ namespace bpf {
|
|||
|
||||
using base::Result;
|
||||
|
||||
const BpfMapRO<uint32_t, IfaceValue>& getIfaceIndexNameMap() {
|
||||
static BpfMapRO<uint32_t, IfaceValue> ifaceIndexNameMap(IFACE_INDEX_NAME_MAP_PATH);
|
||||
BpfMap<uint32_t, IfaceValue>& getIfaceIndexNameMap() {
|
||||
static BpfMap<uint32_t, IfaceValue> ifaceIndexNameMap(IFACE_INDEX_NAME_MAP_PATH);
|
||||
return ifaceIndexNameMap;
|
||||
}
|
||||
|
||||
|
|
@ -50,6 +50,16 @@ const BpfMapRO<uint32_t, StatsValue>& getIfaceStatsMap() {
|
|||
return ifaceStatsMap;
|
||||
}
|
||||
|
||||
void bpfRegisterIface(const char* iface) {
|
||||
if (!iface) return;
|
||||
if (strlen(iface) >= sizeof(IfaceValue)) return;
|
||||
uint32_t ifindex = if_nametoindex(iface);
|
||||
if (!ifindex) return;
|
||||
IfaceValue ifname = {};
|
||||
strlcpy(ifname.name, iface, sizeof(ifname.name));
|
||||
getIfaceIndexNameMap().writeValue(ifindex, ifname, BPF_ANY);
|
||||
}
|
||||
|
||||
int bpfGetUidStatsInternal(uid_t uid, StatsValue* stats,
|
||||
const BpfMapRO<uint32_t, StatsValue>& appUidStatsMap) {
|
||||
auto statsEntry = appUidStatsMap.readValue(uid);
|
||||
|
|
|
|||
|
|
@ -114,6 +114,7 @@ int parseBpfNetworkStatsDevInternal(std::vector<stats_line>& lines,
|
|||
const BpfMapRO<uint32_t, StatsValue>& statsMap,
|
||||
const BpfMapRO<uint32_t, IfaceValue>& ifaceMap);
|
||||
|
||||
void bpfRegisterIface(const char* iface);
|
||||
int bpfGetUidStats(uid_t uid, StatsValue* stats);
|
||||
int bpfGetIfaceStats(const char* iface, StatsValue* stats);
|
||||
int bpfGetIfIndexStats(int ifindex, StatsValue* stats);
|
||||
|
|
|
|||
Loading…
Reference in a new issue