Skip to content

Commit 6cb4e56

Browse files
committed
ipcache: Try multiple maps of different sizes
Try open `cilium_ipcache_v2` and `cilium_ipcache`, in this order. Only use the first 4 bytes of the map value. Signed-off-by: Jarno Rajahalme <[email protected]>
1 parent 59604c3 commit 6cb4e56

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

cilium/ipcache.cc

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
namespace Envoy {
2525
namespace Cilium {
2626

27+
// IP cache names to look for, in the order of prefefrence
28+
static const char* ipcache_names[] = {"cilium_ipcache_v2", "cilium_ipcache"};
29+
2730
// These must be kept in sync with Cilium source code, should refactor
2831
// them to a separate include file we can include here instead of
2932
// copying them!
@@ -51,10 +54,9 @@ PACKED_STRUCT(struct ipcache_key {
5154
});
5255

5356
struct remote_endpoint_info {
54-
__u32 sec_label;
55-
__u32 tunnel_endpoint;
56-
__u16 pad;
57-
__u8 key;
57+
using SecLabelType = __u32;
58+
SecLabelType sec_label;
59+
char buf[60]; // Enough space for all fields after the 'sec_label'
5860
};
5961

6062
#define ENDPOINT_KEY_IPV4 1
@@ -80,18 +82,28 @@ IPCacheSharedPtr IPCache::GetIPCache(Server::Configuration::ServerFactoryContext
8082
}
8183

8284
IPCache::IPCache(const std::string& bpf_root)
83-
: Bpf(BPF_MAP_TYPE_LPM_TRIE, sizeof(struct ipcache_key), sizeof(struct remote_endpoint_info)),
85+
: Bpf(BPF_MAP_TYPE_LPM_TRIE, sizeof(struct ipcache_key),
86+
sizeof(remote_endpoint_info::SecLabelType), sizeof(struct remote_endpoint_info)),
8487
bpf_root_(bpf_root) {}
8588

8689
bool IPCache::Open() {
8790
// Open the bpf maps from Cilium specific paths
88-
std::string path(bpf_root_ + "/tc/globals/cilium_ipcache");
89-
if (!open(path)) {
90-
ENVOY_LOG(info, "cilium.ipcache: Cannot open ipcache map at {}", path);
91-
return false;
91+
std::string tried_paths;
92+
93+
for (const char* name : ipcache_names) {
94+
std::string path(bpf_root_ + "/tc/globals/" + name);
95+
if (!Bpf::open(path)) {
96+
if (tried_paths.length() > 0) {
97+
tried_paths += ", ";
98+
}
99+
tried_paths += path;
100+
continue;
101+
}
102+
ENVOY_LOG(debug, "cilium.ipcache: Opened ipcache at {}", path);
103+
return true;
92104
}
93-
ENVOY_LOG(debug, "cilium.ipcache: Opened ipcache.");
94-
return true;
105+
ENVOY_LOG(info, "cilium.ipcache: Cannot open ipcache at any of {}", tried_paths);
106+
return false;
95107
}
96108

97109
uint32_t IPCache::resolve(const Network::Address::Ip* ip) {

0 commit comments

Comments
 (0)