boot time test of queryProgram()
Test: TreeHugger
Bug: 292156770
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I6e4527a8cb5b5bfc033c5a4d09f0b78080c163c9
diff --git a/netd/BpfHandler.cpp b/netd/BpfHandler.cpp
index a090a54..fa92f10 100644
--- a/netd/BpfHandler.cpp
+++ b/netd/BpfHandler.cpp
@@ -129,6 +129,15 @@
RETURN_IF_NOT_OK(
attachProgramToCgroup(CGROUP_SOCKET_PROG_PATH, cg_fd, BPF_CGROUP_INET_SOCK_CREATE));
}
+
+ // This should trivially pass, since we just attached up above,
+ // but BPF_PROG_QUERY is only implemented on 4.19+ kernels.
+ if (bpf::isAtLeastKernelVersion(4, 19, 0)) {
+ if (bpf::queryProgram(cg_fd, BPF_CGROUP_INET_EGRESS) <= 0) abort();
+ if (bpf::queryProgram(cg_fd, BPF_CGROUP_INET_INGRESS) <= 0) abort();
+ if (bpf::queryProgram(cg_fd, BPF_CGROUP_INET_SOCK_CREATE) <= 0) abort();
+ }
+
return netdutils::status::ok;
}