ebpf Clat - rename to ClatIngress throughout
The specific fields stored in the key and value structs necessitates
the use of this map only for ingress clat ipv6 -> ipv4 decoding purposes.
At some point we will want to implement ebpf clat egress, and then we'll
need new key/value pairs (and map).
Even though current implementation of eBPF program is ingress only,
it is a bad idea to name these fields src and dst since it can
quickly become confusing. It is much easier to think of things as
remote and local or simply call something a prefix.
Whether 'local' and 'remote' are 'src' or 'dst' depends on traffic
flow direction...
Test: atest netd_unit_test
Bug: 65674744
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Iaf4185a547f8dbf8f59ade286eb0fb4b8d09f368
diff --git a/bpf_progs/clatd.c b/bpf_progs/clatd.c
index fb31b36..b66591b 100644
--- a/bpf_progs/clatd.c
+++ b/bpf_progs/clatd.c
@@ -18,10 +18,10 @@
#include "bpf_helpers.h"
#include "netdbpf/bpf_shared.h"
-struct bpf_map_def SEC("maps") clat_map = {
+struct bpf_map_def SEC("maps") clat_ingress_map = {
.type = BPF_MAP_TYPE_HASH,
- .key_size = sizeof(struct ClatKey),
- .value_size = sizeof(struct ClatValue),
+ .key_size = sizeof(struct ClatIngressKey),
+ .value_size = sizeof(struct ClatIngressValue),
.max_entries = 16,
};
diff --git a/libnetdbpf/include/netdbpf/bpf_shared.h b/libnetdbpf/include/netdbpf/bpf_shared.h
index b6d78cf..d342cac 100644
--- a/libnetdbpf/include/netdbpf/bpf_shared.h
+++ b/libnetdbpf/include/netdbpf/bpf_shared.h
@@ -108,23 +108,23 @@
#define UID_RULES_CONFIGURATION_KEY 1
#define CURRENT_STATS_MAP_CONFIGURATION_KEY 2
-#define CLAT_PROG_RAWIP_NAME "prog_clatd_schedcls_ingress_clat_rawip"
-#define CLAT_PROG_ETHER_NAME "prog_clatd_schedcls_ingress_clat_ether"
+#define CLAT_INGRESS_PROG_RAWIP_NAME "prog_clatd_schedcls_ingress_clat_rawip"
+#define CLAT_INGRESS_PROG_ETHER_NAME "prog_clatd_schedcls_ingress_clat_ether"
-#define CLAT_PROG_RAWIP_PATH BPF_PATH "/" CLAT_PROG_RAWIP_NAME
-#define CLAT_PROG_ETHER_PATH BPF_PATH "/" CLAT_PROG_ETHER_NAME
+#define CLAT_INGRESS_PROG_RAWIP_PATH BPF_PATH "/" CLAT_INGRESS_PROG_RAWIP_NAME
+#define CLAT_INGRESS_PROG_ETHER_PATH BPF_PATH "/" CLAT_INGRESS_PROG_ETHER_NAME
-#define CLAT_MAP_PATH BPF_PATH "/map_clatd_clat_map"
+#define CLAT_INGRESS_MAP_PATH BPF_PATH "/map_clatd_clat_ingress_map"
-struct ClatKey {
- uint32_t iif; // The input interface index
- struct in6_addr src6; // The source /96 nat64 prefix, bottom 32 bits must be 0
- struct in6_addr dst6; // The full 128-bits of the destination IPv6 address
+struct ClatIngressKey {
+ uint32_t iif; // The input interface index
+ struct in6_addr pfx96; // The source /96 nat64 prefix, bottom 32 bits must be 0
+ struct in6_addr local6; // The full 128-bits of the destination IPv6 address
};
-struct ClatValue {
- uint32_t oif; // The output interface to redirect to (0 means don't redirect)
- struct in_addr dst4; // The destination IPv4 address
+struct ClatIngressValue {
+ uint32_t oif; // The output interface to redirect to (0 means don't redirect)
+ struct in_addr local4; // The destination IPv4 address
};
#endif // NETDBPF_BPF_SHARED_H
diff --git a/server/ClatUtils.cpp b/server/ClatUtils.cpp
index edfce57..b70155d 100644
--- a/server/ClatUtils.cpp
+++ b/server/ClatUtils.cpp
@@ -62,14 +62,14 @@
return ifr.ifr_hwaddr.sa_family;
}
-int getClatMapFd(void) {
- const int fd = bpf::bpfFdGet(CLAT_MAP_PATH, 0);
+int getClatIngressMapFd(void) {
+ const int fd = bpf::bpfFdGet(CLAT_INGRESS_MAP_PATH, 0);
return (fd == -1) ? -errno : fd;
}
-int getClatProgFd(bool with_ethernet_header) {
- const int fd =
- bpf::bpfFdGet(with_ethernet_header ? CLAT_PROG_ETHER_PATH : CLAT_PROG_RAWIP_PATH, 0);
+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;
}
@@ -231,14 +231,14 @@
// prog_clatd_schedcls_ingress_clat_rawip:[*fsobj]
// and is the name of the pinned ebpf program for ARPHRD_RAWIP interfaces.
// (also compatible with anything that has 0 size L2 header)
-#define NAME_RAWIP CLAT_PROG_RAWIP_NAME FSOBJ_SUFFIX
+#define NAME_RAWIP CLAT_INGRESS_PROG_RAWIP_NAME FSOBJ_SUFFIX
const char name_rawip[] = NAME_RAWIP;
// This macro expands (from header files) to:
// prog_clatd_schedcls_ingress_clat_ether:[*fsobj]
// and is the name of the pinned ebpf program for ARPHRD_ETHER interfaces.
// (also compatible with anything that has standard ethernet header)
-#define NAME_ETHER CLAT_PROG_ETHER_NAME FSOBJ_SUFFIX
+#define NAME_ETHER CLAT_INGRESS_PROG_ETHER_NAME FSOBJ_SUFFIX
const char name_ether[] = NAME_ETHER;
// The actual name we'll use is determined at run time via 'ethernet'
diff --git a/server/ClatUtils.h b/server/ClatUtils.h
index adf8400..9f2a28e 100644
--- a/server/ClatUtils.h
+++ b/server/ClatUtils.h
@@ -24,9 +24,9 @@
int hardwareAddressType(const std::string& interface);
-int getClatMapFd(void);
+int getClatIngressMapFd(void);
-int getClatProgFd(bool with_ethernet_header);
+int getClatIngressProgFd(bool with_ethernet_header);
int openNetlinkSocket(void);
diff --git a/server/ClatUtilsTest.cpp b/server/ClatUtilsTest.cpp
index e5c3b3f..5a902f7 100644
--- a/server/ClatUtilsTest.cpp
+++ b/server/ClatUtilsTest.cpp
@@ -68,7 +68,7 @@
TEST_F(ClatUtilsTest, GetClatMapFd) {
SKIP_IF_BPF_NOT_SUPPORTED;
- int fd = getClatMapFd();
+ int fd = getClatIngressMapFd();
ASSERT_LE(3, fd); // 0,1,2 - stdin/out/err, thus 3 <= fd
close(fd);
}
@@ -76,7 +76,7 @@
TEST_F(ClatUtilsTest, GetClatRawIpProgFd) {
SKIP_IF_BPF_NOT_SUPPORTED;
- int fd = getClatProgFd(false);
+ int fd = getClatIngressProgFd(false);
ASSERT_LE(3, fd);
close(fd);
}
@@ -84,7 +84,7 @@
TEST_F(ClatUtilsTest, GetClatEtherProgFd) {
SKIP_IF_BPF_NOT_SUPPORTED;
- int fd = getClatProgFd(true);
+ int fd = getClatIngressProgFd(true);
ASSERT_LE(3, fd);
close(fd);
}
@@ -145,7 +145,7 @@
SKIP_IF_BPF_NOT_SUPPORTED;
if (!kernelSupportsNetClsBpf()) return;
- int bpf_fd = getClatProgFd(false);
+ int bpf_fd = getClatIngressProgFd(false);
ASSERT_LE(3, bpf_fd);
int fd = openNetlinkSocket();