Skip to content

Commit a628209

Browse files
committed
tidy
Signed-off-by: Jarno Rajahalme <[email protected]>
1 parent 3194356 commit a628209

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+740
-681
lines changed

cilium/accesslog.cc

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@ namespace Cilium {
2828
Thread::MutexBasicLockable AccessLog::logs_mutex;
2929
std::map<std::string, std::weak_ptr<AccessLog>> AccessLog::logs;
3030

31-
AccessLogSharedPtr AccessLog::Open(const std::string& path, TimeSource& time_source) {
31+
AccessLogSharedPtr AccessLog::open(const std::string& path, TimeSource& time_source) {
3232
Thread::LockGuard guard(logs_mutex);
3333
auto it = logs.find(path);
3434
if (it != logs.end()) {
3535
auto log = it->second.lock();
36-
if (log)
36+
if (log) {
3737
return log;
38+
}
3839
// expired, remove
3940
logs.erase(path);
4041
}
@@ -51,7 +52,7 @@ AccessLog::~AccessLog() {
5152
logs.erase(path_);
5253
}
5354

54-
void AccessLog::Log(AccessLog::Entry& log_entry, ::cilium::EntryType entry_type) {
55+
void AccessLog::log(AccessLog::Entry& log_entry, ::cilium::EntryType entry_type) {
5556
::cilium::LogEntry& entry = log_entry.entry_;
5657
entry.set_entry_type(entry_type);
5758

@@ -66,7 +67,7 @@ void AccessLog::Log(AccessLog::Entry& log_entry, ::cilium::EntryType entry_type)
6667
std::string msg;
6768
entry.SerializeToString(&msg);
6869

69-
UDSClient::Log(msg);
70+
UDSClient::log(msg);
7071
}
7172

7273
#define CONST_STRING_VIEW(NAME, STR) const absl::string_view NAME = {STR, sizeof(STR) - 1}
@@ -78,7 +79,7 @@ CONST_STRING_VIEW(xForwardedProtoSV, "x-forwarded-proto");
7879
CONST_STRING_VIEW(xRequestIdSV, "x-request-id");
7980
CONST_STRING_VIEW(statusSV, ":status");
8081

81-
void AccessLog::Entry::InitFromConnection(
82+
void AccessLog::Entry::initFromConnection(
8283
const std::string& policy_name, uint32_t proxy_id, bool ingress, uint32_t source_identity,
8384
const Network::Address::InstanceConstSharedPtr& source_address, uint32_t destination_identity,
8485
const Network::Address::InstanceConstSharedPtr& destination_address, TimeSource* time_source) {
@@ -103,7 +104,7 @@ void AccessLog::Entry::InitFromConnection(
103104
}
104105
}
105106

106-
bool AccessLog::Entry::UpdateFromMetadata(const std::string& l7proto,
107+
bool AccessLog::Entry::updateFromMetadata(const std::string& l7proto,
107108
const ProtobufWkt::Struct& metadata) {
108109
bool changed = false;
109110

@@ -140,14 +141,14 @@ bool AccessLog::Entry::UpdateFromMetadata(const std::string& l7proto,
140141
return changed;
141142
}
142143

143-
void AccessLog::Entry::InitFromRequest(const std::string& policy_name, uint32_t proxy_id,
144+
void AccessLog::Entry::initFromRequest(const std::string& policy_name, uint32_t proxy_id,
144145
bool ingress, uint32_t source_identity,
145146
const Network::Address::InstanceConstSharedPtr& src_address,
146147
uint32_t destination_identity,
147148
const Network::Address::InstanceConstSharedPtr& dst_address,
148149
const StreamInfo::StreamInfo& info,
149150
const Http::RequestHeaderMap& headers) {
150-
InitFromConnection(policy_name, proxy_id, ingress, source_identity, src_address,
151+
initFromConnection(policy_name, proxy_id, ingress, source_identity, src_address,
151152
destination_identity, dst_address, nullptr);
152153

153154
auto time = info.startTime();
@@ -170,10 +171,10 @@ void AccessLog::Entry::InitFromRequest(const std::string& policy_name, uint32_t
170171
::cilium::HttpLogEntry* http_entry = entry_.mutable_http();
171172
http_entry->set_http_protocol(proto);
172173

173-
UpdateFromRequest(destination_identity, dst_address, headers);
174+
updateFromRequest(destination_identity, dst_address, headers);
174175
}
175176

176-
void AccessLog::Entry::UpdateFromRequest(
177+
void AccessLog::Entry::updateFromRequest(
177178
uint32_t destination_identity, const Network::Address::InstanceConstSharedPtr& dst_address,
178179
const Http::RequestHeaderMap& headers) {
179180
// Destination may have changed
@@ -214,7 +215,7 @@ void AccessLog::Entry::UpdateFromRequest(
214215
});
215216
}
216217

217-
void AccessLog::Entry::UpdateFromResponse(const Http::ResponseHeaderMap& headers,
218+
void AccessLog::Entry::updateFromResponse(const Http::ResponseHeaderMap& headers,
218219
TimeSource& time_source) {
219220
auto time = time_source.systemTime();
220221
entry_.set_timestamp(
@@ -263,19 +264,23 @@ void AccessLog::Entry::UpdateFromResponse(const Http::ResponseHeaderMap& headers
263264
});
264265
}
265266

266-
void AccessLog::Entry::AddRejected(absl::string_view key, absl::string_view value) {
267-
for (auto entry : entry_.http().rejected_headers())
268-
if (entry.key() == key && entry.value() == value)
267+
void AccessLog::Entry::addRejected(absl::string_view key, absl::string_view value) {
268+
for (const auto& entry : entry_.http().rejected_headers()) {
269+
if (entry.key() == key && entry.value() == value) {
269270
return;
271+
}
272+
}
270273
::cilium::KeyValue* kv = entry_.mutable_http()->add_rejected_headers();
271274
kv->set_key(key.data(), key.size());
272275
kv->set_value(value.data(), value.size());
273276
}
274277

275-
void AccessLog::Entry::AddMissing(absl::string_view key, absl::string_view value) {
276-
for (auto entry : entry_.http().missing_headers())
277-
if (entry.key() == key && entry.value() == value)
278+
void AccessLog::Entry::addMissing(absl::string_view key, absl::string_view value) {
279+
for (const auto& entry : entry_.http().missing_headers()) {
280+
if (entry.key() == key && entry.value() == value) {
278281
return;
282+
}
283+
}
279284
::cilium::KeyValue* kv = entry_.mutable_http()->add_missing_headers();
280285
kv->set_key(key.data(), key.size());
281286
kv->set_value(value.data(), value.size());

cilium/accesslog.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,38 +26,38 @@ constexpr absl::string_view AccessLogKey = "cilium.accesslog.entry";
2626

2727
class AccessLog : public UDSClient {
2828
public:
29-
static std::shared_ptr<AccessLog> Open(const std::string& path, TimeSource& time_source);
29+
static std::shared_ptr<AccessLog> open(const std::string& path, TimeSource& time_source);
3030
~AccessLog();
3131

3232
// wrapper for protobuf
3333
class Entry : public StreamInfo::FilterState::Object {
3434
public:
35-
void InitFromRequest(const std::string& policy_name, uint32_t proxy_id, bool ingress,
35+
void initFromRequest(const std::string& policy_name, uint32_t proxy_id, bool ingress,
3636
uint32_t source_identity,
3737
const Network::Address::InstanceConstSharedPtr& source_address,
3838
uint32_t destination_identity,
3939
const Network::Address::InstanceConstSharedPtr& destination_address,
4040
const StreamInfo::StreamInfo&, const Http::RequestHeaderMap&);
41-
void UpdateFromRequest(uint32_t destination_identity,
41+
void updateFromRequest(uint32_t destination_identity,
4242
const Network::Address::InstanceConstSharedPtr& destination_address,
4343
const Http::RequestHeaderMap&);
44-
void UpdateFromResponse(const Http::ResponseHeaderMap&, TimeSource&);
44+
void updateFromResponse(const Http::ResponseHeaderMap&, TimeSource&);
4545

46-
void InitFromConnection(const std::string& policy_name, uint32_t proxy_id, bool ingress,
46+
void initFromConnection(const std::string& policy_name, uint32_t proxy_id, bool ingress,
4747
uint32_t source_identity,
4848
const Network::Address::InstanceConstSharedPtr& source_address,
4949
uint32_t destination_identity,
5050
const Network::Address::InstanceConstSharedPtr& destination_address,
5151
TimeSource* time_source);
52-
bool UpdateFromMetadata(const std::string& l7proto, const ProtobufWkt::Struct& metadata);
53-
void AddRejected(absl::string_view key, absl::string_view value);
54-
void AddMissing(absl::string_view key, absl::string_view value);
52+
bool updateFromMetadata(const std::string& l7proto, const ProtobufWkt::Struct& metadata);
53+
void addRejected(absl::string_view key, absl::string_view value);
54+
void addMissing(absl::string_view key, absl::string_view value);
5555

5656
::cilium::LogEntry entry_{};
5757
bool request_logged_ = false;
5858
};
5959

60-
void Log(Entry& entry, ::cilium::EntryType);
60+
void log(Entry& entry, ::cilium::EntryType);
6161

6262
private:
6363
explicit AccessLog(const std::string& path, TimeSource& time_source)

cilium/bpf.cc

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace Envoy {
1818
namespace Cilium {
1919

2020
enum {
21-
BPF_KEY_MAX_LEN = 64,
21+
BpfKeyMaxLen = 64,
2222
};
2323

2424
Bpf::Bpf(uint32_t map_type, uint32_t key_size, uint32_t value_size)
@@ -27,8 +27,9 @@ Bpf::Bpf(uint32_t map_type, uint32_t key_size, uint32_t value_size)
2727
Bpf::~Bpf() { close(); }
2828

2929
void Bpf::close() {
30-
if (fd_ >= 0)
30+
if (fd_ >= 0) {
3131
::close(fd_);
32+
}
3233
fd_ = -1;
3334
}
3435

@@ -39,11 +40,12 @@ bool Bpf::open(const std::string& path) {
3940
close();
4041

4142
// store the path for later
42-
if (path != path_)
43+
if (path != path_) {
4344
path_ = path;
45+
}
4446

4547
auto& cilium_calls = PrivilegedService::Singleton::get();
46-
auto ret = cilium_calls.bpf_open(path.c_str());
48+
auto ret = cilium_calls.bpfOpen(path.c_str());
4749
fd_ = ret.return_value_;
4850
if (fd_ >= 0) {
4951
// Open fdinfo to check the map type and key and value size.
@@ -116,12 +118,13 @@ bool Bpf::open(const std::string& path) {
116118
bool Bpf::lookup(const void* key, void* value) {
117119
// Try reopen if open failed previously
118120
if (fd_ < 0) {
119-
if (!open(path_))
121+
if (!open(path_)) {
120122
return false;
123+
}
121124
}
122125

123126
auto& cilium_calls = PrivilegedService::Singleton::get();
124-
auto result = cilium_calls.bpf_lookup(fd_, key, key_size_, value, value_size_);
127+
auto result = cilium_calls.bpfLookup(fd_, key, key_size_, value, value_size_);
125128

126129
if (result.return_value_ == 0) {
127130
return true;

cilium/bpf_metadata.cc

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ Config::Config(const ::cilium::BpfMetadata& config,
236236
// later.
237237
return std::make_shared<Cilium::CtMap>(bpf_root);
238238
});
239-
ipcache_ = IPCache::NewIPCache(context.serverFactoryContext(), bpf_root);
239+
ipcache_ = IPCache::newIpCache(context.serverFactoryContext(), bpf_root);
240240
if (bpf_root != ct_maps_->bpfRoot()) {
241241
// bpf root may not change during runtime
242242
throw EnvoyException(fmt::format("cilium.bpf_metadata: Invalid bpf_root: {}", bpf_root));
@@ -273,15 +273,16 @@ uint32_t Config::resolvePolicyId(const Network::Address::Ip* ip) const {
273273

274274
uint32_t Config::resolveSourceIdentity(const PolicyInstance& policy,
275275
const Network::Address::Ip* sip,
276-
const Network::Address::Ip* dip, bool ingress, bool isL7LB) {
276+
const Network::Address::Ip* dip, bool ingress,
277+
bool is_l7_lb) {
277278
uint32_t source_identity = 0;
278279

279280
// Resolve the source security ID from conntrack map, or from ip cache
280281
if (ct_maps_ != nullptr) {
281282
const std::string& ct_name = policy.conntrackName();
282283
if (ct_name.length() > 0) {
283284
source_identity = ct_maps_->lookupSrcIdentity(ct_name, sip, dip, ingress);
284-
} else if (isL7LB) {
285+
} else if (is_l7_lb) {
285286
// non-local source should be in the global conntrack
286287
source_identity = ct_maps_->lookupSrcIdentity("global", sip, dip, ingress);
287288
}
@@ -297,24 +298,24 @@ uint32_t Config::resolveSourceIdentity(const PolicyInstance& policy,
297298
// Returns a new IPAddressPair that keeps the source address and fills in the other address version
298299
// from the given IPAddressPair.
299300
IPAddressPair
300-
Config::getIPAddressPairFrom(const Network::Address::InstanceConstSharedPtr sourceAddress,
301+
Config::getIPAddressPairFrom(const Network::Address::InstanceConstSharedPtr source_address,
301302
const IPAddressPair& addresses) {
302303
auto addressPair = IPAddressPair();
303304

304-
switch (sourceAddress->ip()->version()) {
305+
switch (source_address->ip()->version()) {
305306
case Network::Address::IpVersion::v4:
306-
addressPair.ipv4_ = sourceAddress;
307+
addressPair.ipv4_ = source_address;
307308
if (addresses.ipv6_) {
308309
sockaddr_in6 sa6 = *reinterpret_cast<const sockaddr_in6*>(addresses.ipv6_->sockAddr());
309-
sa6.sin6_port = htons(sourceAddress->ip()->port());
310+
sa6.sin6_port = htons(source_address->ip()->port());
310311
addressPair.ipv6_ = std::make_shared<Network::Address::Ipv6Instance>(sa6);
311312
}
312313
break;
313314
case Network::Address::IpVersion::v6:
314-
addressPair.ipv6_ = sourceAddress;
315+
addressPair.ipv6_ = source_address;
315316
if (addresses.ipv4_) {
316317
sockaddr_in sa4 = *reinterpret_cast<const sockaddr_in*>(addresses.ipv4_->sockAddr());
317-
sa4.sin_port = htons(sourceAddress->ip()->port());
318+
sa4.sin_port = htons(source_address->ip()->port());
318319
addressPair.ipv4_ = std::make_shared<Network::Address::Ipv4Instance>(&sa4);
319320
}
320321
break;
@@ -347,11 +348,12 @@ const PolicyInstance& Config::getPolicy(const std::string& pod_ip) const {
347348
// This is the case for L7 LB listeners only. This is needed to allow traffic forwarded by Cilium
348349
// Ingress (which is implemented as an egress listener!).
349350
bool allow_egress = !enforce_policy_on_l7lb_ && !is_ingress_ && is_l7lb_;
350-
if (npmap_ == nullptr)
351-
return allow_egress ? NetworkPolicyMap::GetAllowAllEgressPolicy()
352-
: NetworkPolicyMap::GetDenyAllPolicy();
351+
if (npmap_ == nullptr) {
352+
return allow_egress ? NetworkPolicyMap::getAllowAllEgressPolicy()
353+
: NetworkPolicyMap::getDenyAllPolicy();
354+
}
353355

354-
return npmap_->GetPolicyInstance(pod_ip, allow_egress);
356+
return npmap_->getPolicyInstance(pod_ip, allow_egress);
355357
}
356358

357359
absl::optional<Cilium::BpfMetadata::SocketMetadata>
@@ -457,8 +459,9 @@ Config::extractSocketMetadata(Network::ConnectionSocket& socket) {
457459
}
458460

459461
// Enforce ingress policy on the incoming Ingress traffic?
460-
if (enforce_policy_on_l7lb_)
462+
if (enforce_policy_on_l7lb_) {
461463
ingress_source_identity = source_identity;
464+
}
462465

463466
source_identity = new_source_identity;
464467

@@ -507,11 +510,11 @@ Config::extractSocketMetadata(Network::ConnectionSocket& socket) {
507510
uint32_t identity_id = (source_identity & 0xFFFF) << 16;
508511
mark = ((is_ingress_) ? 0x0A00 : 0x0B00) | cluster_id | identity_id;
509512
}
510-
return absl::optional(Cilium::BpfMetadata::SocketMetadata(
513+
return {Cilium::BpfMetadata::SocketMetadata(
511514
mark, ingress_source_identity, source_identity, is_ingress_, is_l7lb_, dip->port(),
512515
std::move(pod_ip), std::move(src_address), std::move(source_addresses.ipv4_),
513516
std::move(source_addresses.ipv6_), std::move(dst_address), weak_from_this(), proxy_id_,
514-
std::move(proxylib_l7proto), sni));
517+
std::move(proxylib_l7proto), sni)};
515518
}
516519

517520
Network::FilterStatus Instance::onAccept(Network::ListenerFilterCallbacks& cb) {

cilium/bpf_metadata.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ struct SocketMetadata : public Logger::Loggable<Logger::Id::filter> {
6868
if (!proxylib_l7_proto_.empty()) {
6969
const auto& old_protocols = socket.requestedApplicationProtocols();
7070
std::vector<absl::string_view> protocols;
71+
protocols.reserve(old_protocols.size());
7172
for (const auto& old_protocol : old_protocols) {
7273
protocols.emplace_back(old_protocol);
7374
}
@@ -128,7 +129,7 @@ class Config : public Cilium::PolicyResolver,
128129
public:
129130
Config(const ::cilium::BpfMetadata& config,
130131
Server::Configuration::ListenerFactoryContext& context);
131-
virtual ~Config() {}
132+
~Config() override = default;
132133

133134
// PolicyResolver
134135
uint32_t resolvePolicyId(const Network::Address::Ip*) const override;
@@ -155,13 +156,13 @@ class Config : public Cilium::PolicyResolver,
155156

156157
private:
157158
uint32_t resolveSourceIdentity(const PolicyInstance& policy, const Network::Address::Ip* sip,
158-
const Network::Address::Ip* dip, bool ingress, bool isL7LB);
159+
const Network::Address::Ip* dip, bool ingress, bool is_l7_lb);
159160

160-
IPAddressPair getIPAddressPairFrom(const Network::Address::InstanceConstSharedPtr sourceAddress,
161+
IPAddressPair getIPAddressPairFrom(const Network::Address::InstanceConstSharedPtr source_address,
161162
const IPAddressPair& addresses);
162163

163164
const Network::Address::Ip* selectIPVersion(const Network::Address::IpVersion version,
164-
const IPAddressPair& sourceAddresses);
165+
const IPAddressPair& source_addresses);
165166
};
166167

167168
using ConfigSharedPtr = std::shared_ptr<Config>;

cilium/conntrack.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ PACKED_STRUCT(struct ipv4_ct_tuple {
5858
__u8 flags;
5959
});
6060

61-
struct ct_entry {
61+
struct CtEntry {
6262
__u64 rx_packets;
6363
__u64 rx_bytes;
6464
__u64 tx_packets;
@@ -82,10 +82,10 @@ struct ct_entry {
8282
};
8383

8484
CtMap::CtMap4::CtMap4()
85-
: Bpf(BPF_MAP_TYPE_HASH, sizeof(struct ipv4_ct_tuple), sizeof(struct ct_entry)) {}
85+
: Bpf(BPF_MAP_TYPE_HASH, sizeof(struct ipv4_ct_tuple), sizeof(struct CtEntry)) {}
8686

8787
CtMap::CtMap6::CtMap6()
88-
: Bpf(BPF_MAP_TYPE_HASH, sizeof(struct ipv6_ct_tuple), sizeof(struct ct_entry)) {}
88+
: Bpf(BPF_MAP_TYPE_HASH, sizeof(struct ipv6_ct_tuple), sizeof(struct CtEntry)) {}
8989

9090
CtMap::CtMaps4::CtMaps4(const std::string& bpf_root, const std::string& map_name) : ok_(false) {
9191
// Open the IPv4 bpf maps from Cilium specific paths
@@ -190,7 +190,7 @@ uint32_t CtMap::lookupSrcIdentity(const std::string& map_name, const Network::Ad
190190

191191
struct ipv4_ct_tuple key4 {};
192192
struct ipv6_ct_tuple key6 {};
193-
struct ct_entry value {};
193+
struct CtEntry value {};
194194

195195
if (sip->version() == Network::Address::IpVersion::v4 &&
196196
dip->version() == Network::Address::IpVersion::v4) {

0 commit comments

Comments
 (0)