OffloadUtils - implement getTetherIngressProgFd()
Test: build, atest
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ibbc655a483507624c2b340bdb7f3f0b311a90722
diff --git a/server/OffloadUtils.h b/server/OffloadUtils.h
index 3c578d0..f2a4dc2 100644
--- a/server/OffloadUtils.h
+++ b/server/OffloadUtils.h
@@ -57,6 +57,13 @@
return (fd == -1) ? -errno : fd;
}
+inline int getTetherIngressProgFd(bool with_ethernet_header) {
+ const int fd = bpf::bpfFdGet(
+ with_ethernet_header ? TETHER_INGRESS_PROG_ETHER_PATH : TETHER_INGRESS_PROG_RAWIP_PATH,
+ 0);
+ return (fd == -1) ? -errno : fd;
+}
+
int openNetlinkSocket(void);
int doTcQdiscClsact(int fd, int ifIndex, uint16_t nlMsgType, uint16_t nlMsgFlags);
diff --git a/server/OffloadUtilsTest.cpp b/server/OffloadUtilsTest.cpp
index a893588..e4316a7 100644
--- a/server/OffloadUtilsTest.cpp
+++ b/server/OffloadUtilsTest.cpp
@@ -121,6 +121,26 @@
close(fd);
}
+TEST_F(OffloadUtilsTest, GetTetherIngressRawIpProgFd) {
+ // Currently only implementing downstream direction offload.
+ // RX Rawip -> TX Ether requires header adjustments and thus 4.14.
+ SKIP_IF_EXTENDED_BPF_NOT_SUPPORTED;
+
+ int fd = getTetherIngressProgFd(false);
+ ASSERT_LE(3, fd);
+ close(fd);
+}
+
+TEST_F(OffloadUtilsTest, GetTetherIngressEtherProgFd) {
+ // Currently only implementing downstream direction offload.
+ // RX Ether -> TX Ether does not require header adjustments
+ SKIP_IF_BPF_NOT_SUPPORTED;
+
+ int fd = getTetherIngressProgFd(true);
+ ASSERT_LE(3, fd);
+ close(fd);
+}
+
TEST_F(OffloadUtilsTest, TryOpeningNetlinkSocket) {
int fd = openNetlinkSocket();
ASSERT_LE(3, fd);