24
24
namespace Envoy {
25
25
namespace Cilium {
26
26
27
+ // IP cache names to look for, in the order of prefefrence
28
+ static const char * ipcache_names[] = {" cilium_ipcache_v2" , " cilium_ipcache" };
29
+
27
30
// These must be kept in sync with Cilium source code, should refactor
28
31
// them to a separate include file we can include here instead of
29
32
// copying them!
@@ -51,10 +54,9 @@ PACKED_STRUCT(struct ipcache_key {
51
54
});
52
55
53
56
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'
58
60
};
59
61
60
62
#define ENDPOINT_KEY_IPV4 1
@@ -80,18 +82,28 @@ IPCacheSharedPtr IPCache::GetIPCache(Server::Configuration::ServerFactoryContext
80
82
}
81
83
82
84
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 )),
84
87
bpf_root_ (bpf_root) {}
85
88
86
89
bool IPCache::Open () {
87
90
// 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 ;
92
104
}
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 ;
95
107
}
96
108
97
109
uint32_t IPCache::resolve (const Network::Address::Ip* ip) {
0 commit comments