KernelUtils.h: isAtLeastKernelVersion(x,y,z) - default 'z' to 0

This seems to be the most common usecase.

Test: TreeHugger
Flag: EXEMPT PURE_REFACTOR
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I2de4d067b2f20680539cbddb31555864bcf957b1
This commit is contained in:
Maciej Żenczykowski 2025-09-12 08:19:40 -07:00
commit ee24054e2b
4 changed files with 66 additions and 66 deletions

View file

@ -61,7 +61,7 @@ static jint com_android_net_module_util_BpfMap_nativeBpfFdGet(JNIEnv *env, jclas
return -1;
}
if (bpf::isAtLeastKernelVersion(4, 14, 0)) {
if (bpf::isAtLeastKernelVersion(4, 14)) {
// These likely fail with -1 and set errno to EINVAL on <4.14
if (bpf::bpfGetFdKeySize(fd) != keySize) {
jniThrowErrnoException(env, "nativeBpfFdGet KeySize", EBADFD);

View file

@ -104,7 +104,7 @@ static int createTunTapImpl(JNIEnv *env, bool isTun, bool hasCarrier,
if (!hasCarrier) {
// Using IFF_NO_CARRIER is supported starting in kernel version >= 6.0
// Up until then, unsupported flags are ignored.
if (!bpf::isAtLeastKernelVersion(6, 0, 0)) {
if (!bpf::isAtLeastKernelVersion(6, 0)) {
throwException(env, EOPNOTSUPP, "IFF_NO_CARRIER not supported",
ifr.ifr_name);
return -1;

View file

@ -497,7 +497,7 @@ int isEthernet(const char *iface, bool &isEthernet) {
// shipped with Android S, so (for safety) let's limit ourselves to
// >5.10, ie. 5.11+ as a guarantee we're on Android T+ and thus no
// longer need this non-upstream compatibility logic
static bool is_pre_5_11_kernel = !bpf::isAtLeastKernelVersion(5, 11, 0);
static bool is_pre_5_11_kernel = !bpf::isAtLeastKernelVersion(5, 11);
if (is_pre_5_11_kernel)
return false;
}

View file

@ -82,7 +82,7 @@ TEST(LibTcUtilsTest, AddAndDeleteBpfFilter) {
// TODO: this should likely be in the tethering module, where using netd.h would be ok
static constexpr char bpfProgPath[] =
"/sys/fs/bpf/tethering/prog_offload_schedcls_tether_downstream6_ether";
const int errNOENT = bpf::isAtLeastKernelVersion(4, 19, 0) ? ENOENT : EINVAL;
const int errNOENT = bpf::isAtLeastKernelVersion(4, 19) ? ENOENT : EINVAL;
// static test values
static constexpr bool ingress = true;
@ -118,7 +118,7 @@ TEST(LibTcUtilsTest, AddAndDeleteIngressPoliceFilter) {
ASSERT_LE(3, fd);
close(fd);
const int errNOENT = bpf::isAtLeastKernelVersion(4, 19, 0) ? ENOENT : EINVAL;
const int errNOENT = bpf::isAtLeastKernelVersion(4, 19) ? ENOENT : EINVAL;
// static test values
static constexpr unsigned rateInBytesPerSec =