NetBpfLoad: don't call bpfGetFdMapId in kernels < 4.14

The function is not available in older kernels.

But when we do call it, fail on error - should not happen.

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I2695bf01762abcbc087a3bd67f1718e0e326576a
This commit is contained in:
Maciej Żenczykowski 2025-02-13 16:08:18 -08:00
commit a003ace532

View file

@ -859,11 +859,13 @@ static int createMaps(const char* elfPath, ifstream& elfFile, vector<unique_fd>&
}
}
int mapId = bpfGetFdMapId(fd);
if (mapId == -1) {
if (isAtLeastKernelVersion(4, 14, 0))
ALOGE("bpfGetFdMapId failed, ret: %d [%d]", mapId, errno);
} else {
if (isAtLeastKernelVersion(4, 14, 0)) {
int mapId = bpfGetFdMapId(fd);
if (mapId == -1) {
const int err = errno;
ALOGE("bpfGetFdMapId failed, errno: %d", err);
return -err;
}
ALOGI("map %s id %d", mapPinLoc.c_str(), mapId);
}