ClatUtilsTest - fix to correctly require 4.9-Q for clsact qdisc

Test: libbpf_android_test netd_unit_test netd_integration_test
Bug: 65674744
Bug: 124361845
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I9cb11cad6f9cd529037fce9edc35de8a8ea6b08a
diff --git a/server/ClatUtilsTest.cpp b/server/ClatUtilsTest.cpp
index 5a902f7..6be5529 100644
--- a/server/ClatUtilsTest.cpp
+++ b/server/ClatUtilsTest.cpp
@@ -95,6 +95,45 @@
     close(fd);
 }
 
+// The SKIP_IF_BPF_NOT_SUPPORTED macro is effectively a check for 4.9+ kernel
+// combined with a launched on P device.  Ie. it's a test for 4.9-P or better.
+
+// NET_SCH_INGRESS is only enabled starting with 4.9-Q and as such we need
+// a separate way to test for this...
+int doKernelSupportsNetSchIngress(void) {
+    return system("zcat /proc/config.gz | egrep -q '^CONFIG_NET_SCH_INGRESS=[my]$'");
+}
+
+// NET_CLS_BPF is only enabled starting with 4.9-Q...
+int doKernelSupportsNetClsBpf(void) {
+    return system("zcat /proc/config.gz | egrep -q '^CONFIG_NET_CLS_BPF=[my]$'");
+}
+
+// Make sure the above functions actually execute correctly rather than failing
+// due to missing binary or execution failure...
+TEST_F(ClatUtilsTest, KernelSupportsNetFuncs) {
+    // Make sure the file is present and readable and decompressable.
+    ASSERT_EQ(W_EXITCODE(0, 0), system("zcat /proc/config.gz > /dev/null"));
+
+    int v = doKernelSupportsNetSchIngress();
+    int w = doKernelSupportsNetClsBpf();
+
+    // They should always either return 0 (match) or 1 (no match),
+    // anything else is some sort of exec/environment/etc failure.
+    if (v != W_EXITCODE(1, 0)) ASSERT_EQ(v, W_EXITCODE(0, 0));
+    if (w != W_EXITCODE(1, 0)) ASSERT_EQ(w, W_EXITCODE(0, 0));
+}
+
+// True iff CONFIG_NET_SCH_INGRESS is enabled in /proc/config.gz
+bool kernelSupportsNetSchIngress(void) {
+    return doKernelSupportsNetSchIngress() == W_EXITCODE(0, 0);
+}
+
+// True iff CONFIG_NET_CLS_BPF is enabled in /proc/config.gz
+bool kernelSupportsNetClsBpf(void) {
+    return doKernelSupportsNetClsBpf() == W_EXITCODE(0, 0);
+}
+
 // See Linux kernel source in include/net/flow.h
 #define LOOPBACK_IFINDEX 1
 
@@ -102,6 +141,7 @@
     // Technically does not depend on ebpf, but does depend on clsact,
     // and we do not really care if it works on pre-4.9-Q anyway.
     SKIP_IF_BPF_NOT_SUPPORTED;
+    if (!kernelSupportsNetSchIngress()) return;
 
     int fd = openNetlinkSocket();
     ASSERT_LE(3, fd);
@@ -114,35 +154,10 @@
     close(fd);
 }
 
-// The SKIP_IF_BPF_NOT_SUPPORTED macro is effectively a check for 4.9+ kernel
-// combined with a launched on P device.  Ie. it's a test for 4.9-P or better.
-// NET_CLS_BPF is only enabled starting with 4.9-Q and as such we need
-// a separate way to test for this...
-int doKernelSupportsNetClsBpf(void) {
-    return system("zcat /proc/config.gz | egrep -q '^CONFIG_NET_CLS_BPF=[my]$'");
-}
-
-// Make sure the above function actually executes correctly rather than failing
-// due to missing binary or execution failure...
-TEST_F(ClatUtilsTest, KernelSupportsNetClsBpf) {
-    // Make sure the file is present and readable and decompressable.
-    ASSERT_EQ(W_EXITCODE(0, 0), system("zcat /proc/config.gz > /dev/null"));
-
-    int v = doKernelSupportsNetClsBpf();
-
-    // It should always either return 0 (match) or 1 (no match),
-    // anything else is some sort of exec/environment/etc failure.
-    if (v != W_EXITCODE(1, 0)) ASSERT_EQ(v, W_EXITCODE(0, 0));
-}
-
-// True iff CONFIG_NET_CLS_BPF is enabled in /proc/config.gz
-bool kernelSupportsNetClsBpf(void) {
-    return doKernelSupportsNetClsBpf() == W_EXITCODE(0, 0);
-}
-
 void checkAttachBpfFilterClsactLo(const bool ethernet) {
     // This test requires kernel 4.9-Q or better
     SKIP_IF_BPF_NOT_SUPPORTED;
+    if (!kernelSupportsNetSchIngress()) return;
     if (!kernelSupportsNetClsBpf()) return;
 
     int bpf_fd = getClatIngressProgFd(false);