ClatUtils - implement getClatMapFd()

Test: atest netd_unit_test
Bug: 65674744
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ia5e80f7cd82f1bd40872f88e4edd4da491450cec
diff --git a/server/ClatUtils.cpp b/server/ClatUtils.cpp
index 6edc97a..727e6d7 100644
--- a/server/ClatUtils.cpp
+++ b/server/ClatUtils.cpp
@@ -27,6 +27,8 @@
 #include <log/log.h>
 
 #include "android-base/unique_fd.h"
+#include "bpf/BpfUtils.h"
+#include "netdbpf/bpf_shared.h"
 
 namespace android {
 namespace net {
@@ -54,5 +56,10 @@
     return ifr.ifr_hwaddr.sa_family;
 }
 
+int getClatMapFd(void) {
+    const int fd = bpf::bpfFdGet(CLAT_MAP_PATH, 0);
+    return (fd == -1) ? -errno : fd;
+}
+
 }  // namespace net
 }  // namespace android