OffloadUtils - move getClat{E,In}gress{Map,Prog}Fd from .cpp to .h
There's no reason for these simple functions to be in the cpp.
Test: build, atest
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I731c1226998a2aabd070b9e979eb049f7e462dfb
diff --git a/server/OffloadUtils.h b/server/OffloadUtils.h
index f93bc61..e8a694b 100644
--- a/server/OffloadUtils.h
+++ b/server/OffloadUtils.h
@@ -16,22 +16,40 @@
#pragma once
+#include <errno.h>
#include <linux/if_ether.h>
#include <string>
+#include "bpf/BpfUtils.h"
+#include "netdbpf/bpf_shared.h"
+
namespace android {
namespace net {
int hardwareAddressType(const std::string& interface);
-int getClatEgressMapFd(void);
+static inline int getClatEgressMapFd(void) {
+ const int fd = bpf::bpfFdGet(CLAT_EGRESS_MAP_PATH, 0);
+ return (fd == -1) ? -errno : fd;
+}
-int getClatEgressProgFd(bool with_ethernet_header);
+static inline int getClatEgressProgFd(bool with_ethernet_header) {
+ const int fd = bpf::bpfFdGet(
+ with_ethernet_header ? CLAT_EGRESS_PROG_ETHER_PATH : CLAT_EGRESS_PROG_RAWIP_PATH, 0);
+ return (fd == -1) ? -errno : fd;
+}
-int getClatIngressMapFd(void);
+static inline int getClatIngressMapFd(void) {
+ const int fd = bpf::bpfFdGet(CLAT_INGRESS_MAP_PATH, 0);
+ return (fd == -1) ? -errno : fd;
+}
-int getClatIngressProgFd(bool with_ethernet_header);
+static inline int getClatIngressProgFd(bool with_ethernet_header) {
+ const int fd = bpf::bpfFdGet(
+ with_ethernet_header ? CLAT_INGRESS_PROG_ETHER_PATH : CLAT_INGRESS_PROG_RAWIP_PATH, 0);
+ return (fd == -1) ? -errno : fd;
+}
int openNetlinkSocket(void);