BpfNetworkStats: fallback to if_indextoname() on index->name map lookup failure

(this should fix the 4 ipsec tests which don't call the right
 higher APIs that would eventually call into bpfRegisterIface)

Test: TreeHugger, atest libnetworkstats_test
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I3069f3a2f809948cd2e7755745586b78ff3362c9
This commit is contained in:
Maciej Żenczykowski 2024-01-26 15:15:44 -08:00
commit d3d144f54d

View file

@ -51,7 +51,12 @@ const BpfMapRO<uint32_t, StatsValue>& getIfaceStatsMap() {
}
Result<IfaceValue> ifindex2name(const uint32_t ifindex) {
return getIfaceIndexNameMap().readValue(ifindex);
Result<IfaceValue> v = getIfaceIndexNameMap().readValue(ifindex);
if (v.ok()) return v;
IfaceValue iv = {};
if (!if_indextoname(ifindex, iv.name)) return v;
getIfaceIndexNameMap().writeValue(ifindex, iv, BPF_ANY);
return iv;
}
void bpfRegisterIface(const char* iface) {