add getClatEgressMapFd() with tests

Test: atest
Bug: 139396664
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ic7d952ba32228107b35f97d8b89f9667270718be
diff --git a/server/ClatUtils.cpp b/server/ClatUtils.cpp
index ed7287a..c75fcdd 100644
--- a/server/ClatUtils.cpp
+++ b/server/ClatUtils.cpp
@@ -62,6 +62,11 @@
     return ifr.ifr_hwaddr.sa_family;
 }
 
+int getClatEgressMapFd(void) {
+    const int fd = bpf::bpfFdGet(CLAT_EGRESS_MAP_PATH, 0);
+    return (fd == -1) ? -errno : fd;
+}
+
 int getClatIngressMapFd(void) {
     const int fd = bpf::bpfFdGet(CLAT_INGRESS_MAP_PATH, 0);
     return (fd == -1) ? -errno : fd;
diff --git a/server/ClatUtils.h b/server/ClatUtils.h
index 9f2a28e..f9df5c2 100644
--- a/server/ClatUtils.h
+++ b/server/ClatUtils.h
@@ -24,6 +24,8 @@
 
 int hardwareAddressType(const std::string& interface);
 
+int getClatEgressMapFd(void);
+
 int getClatIngressMapFd(void);
 
 int getClatIngressProgFd(bool with_ethernet_header);
diff --git a/server/ClatUtilsTest.cpp b/server/ClatUtilsTest.cpp
index 2a869ba..77b22a1 100644
--- a/server/ClatUtilsTest.cpp
+++ b/server/ClatUtilsTest.cpp
@@ -65,7 +65,15 @@
     ASSERT_EQ(ARPHRD_RAWIP, type);
 }
 
-TEST_F(ClatUtilsTest, GetClatMapFd) {
+TEST_F(ClatUtilsTest, GetClatEgressMapFd) {
+    SKIP_IF_BPF_NOT_SUPPORTED;
+
+    int fd = getClatEgressMapFd();
+    ASSERT_LE(3, fd);  // 0,1,2 - stdin/out/err, thus 3 <= fd
+    close(fd);
+}
+
+TEST_F(ClatUtilsTest, GetClatIngressMapFd) {
     SKIP_IF_BPF_NOT_SUPPORTED;
 
     int fd = getClatIngressMapFd();