Skip to content

Commit

Permalink
code: cleanup imports - use "import what you use" model
Browse files Browse the repository at this point in the history
Currently, the C++ files are either including unused files or
heavily rely on transtive includes and doesn't define the actual
required includes.

Therefore, this commit fixes all includes so that all files are
defining their includes according to their needs - following the
model "import what you use".

See https://clangd.llvm.org/guides/include-cleaner

Advantages:

* Get rid of warnings when using clangd as LSP server
* Remove unused imports
* Define all direct imports helps understanding the code and the
  dependencies

Signed-off-by: Marco Hofstetter <[email protected]>
  • Loading branch information
mhofstetter committed Jan 3, 2025
1 parent dfaf444 commit 77609f3
Show file tree
Hide file tree
Showing 66 changed files with 969 additions and 178 deletions.
23 changes: 21 additions & 2 deletions cilium/accesslog.cc
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
#include "accesslog.h"

#include <errno.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <unistd.h>

#include <chrono>
#include <cstdint>
#include <map>
#include <memory>
#include <string>

#include "envoy/common/time.h"
#include "envoy/http/header_map.h"
#include "envoy/http/protocol.h"
#include "envoy/network/address.h"
#include "envoy/stream_info/stream_info.h"

#include "source/common/common/lock_guard.h"
#include "source/common/common/utility.h"
#include "source/common/common/logger.h"
#include "source/common/common/thread.h"
#include "source/common/protobuf/utility.h"

#include "absl/strings/numbers.h"
#include "absl/strings/string_view.h"
#include "cilium/api/accesslog.pb.h"
#include "cilium/uds_client.h"
#include "google/protobuf/struct.pb.h"

namespace Envoy {
namespace Cilium {
Expand Down
12 changes: 10 additions & 2 deletions cilium/accesslog.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
#pragma once

#include <cstdint>
#include <map>
#include <memory>
#include <string>

#include "envoy/common/time.h"
#include "envoy/http/header_map.h"
#include "envoy/network/connection.h"
#include "envoy/router/router.h"
#include "envoy/network/address.h"
#include "envoy/stream_info/filter_state.h"
#include "envoy/stream_info/stream_info.h"

#include "source/common/common/thread.h"

#include "absl/base/thread_annotations.h"
#include "absl/strings/string_view.h"
#include "cilium/api/accesslog.pb.h"
#include "cilium/uds_client.h"
#include "google/protobuf/struct.pb.h"

namespace Envoy {
namespace Cilium {
Expand Down
7 changes: 7 additions & 0 deletions cilium/bpf.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
#include "cilium/bpf.h"

#include <errno.h>
#include <unistd.h>

#include <cstdint>
#include <fstream>
#include <sstream>
#include <string>

#include "source/common/common/logger.h"
#include "source/common/common/utility.h"

#include "cilium/privileged_service_client.h"
Expand Down
6 changes: 0 additions & 6 deletions cilium/bpf.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
#pragma once

#include <string.h>
#include <unistd.h>

#include <cstdint>
#include <fstream>
#include <iostream>
#include <map>
#include <sstream>
#include <string>
#include <vector>

#include "source/common/common/logger.h"

Expand Down
38 changes: 31 additions & 7 deletions cilium/bpf_metadata.cc
Original file line number Diff line number Diff line change
@@ -1,25 +1,49 @@
#include "cilium/bpf_metadata.h"

#include <asm-generic/socket.h>
#include <fmt/format.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <sys/socket.h>

#include <chrono>
#include <cstddef>
#include <cstdint>
#include <memory>
#include <string>
#include <utility>
#include <vector>

#include "envoy/api/io_error.h"
#include "envoy/common/exception.h"
#include "envoy/network/address.h"
#include "envoy/network/filter.h"
#include "envoy/network/listen_socket.h"
#include "envoy/network/listener_filter_buffer.h"
#include "envoy/registry/registry.h"
#include "envoy/server/factory_context.h"
#include "envoy/server/filter_config.h"
#include "envoy/singleton/manager.h"
#include "envoy/stream_info/filter_state.h"

#include "source/common/common/assert.h"
#include "source/common/common/fmt.h"
#include "source/common/common/logger.h"
#include "source/common/common/utility.h"
#include "source/common/network/address_impl.h"
#include "source/common/network/socket_option_factory.h"
#include "source/common/network/upstream_socket_options_filter_state.h"

#include "cilium/api/bpf_metadata.pb.validate.h"
#include "source/common/network/utility.h"
#include "source/common/protobuf/protobuf.h"
#include "source/common/protobuf/utility.h"

#include "absl/strings/string_view.h"
#include "cilium/api/bpf_metadata.pb.h"
#include "cilium/api/bpf_metadata.pb.validate.h" // IWYU pragma: keep
#include "cilium/conntrack.h"
#include "cilium/host_map.h"
#include "cilium/ipcache.h"
#include "cilium/network_policy.h"
#include "cilium/policy_id.h"
#include "cilium/socket_option.h"
#include "network_policy.h"
#include "google/protobuf/message.h"

namespace Envoy {
namespace Server {
Expand Down Expand Up @@ -531,7 +555,7 @@ Network::FilterStatus Instance::onAccept(Network::ListenerFilterCallbacks& cb) {

// Set socket options for linger and keepalive (5 minutes).
struct ::linger lin {
true, 10
true, 10,
};
int keepalive = true;
int secs = 5 * 60; // Five minutes
Expand Down
11 changes: 9 additions & 2 deletions cilium/bpf_metadata.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
#pragma once

#include <chrono>
#include <cstddef>
#include <cstdint>
#include <memory>
#include <string>

#include "envoy/api/io_error.h"
#include "envoy/json/json_object.h"
#include "envoy/network/address.h"
#include "envoy/network/filter.h"
#include "envoy/server/filter_config.h"
#include "envoy/network/listener_filter_buffer.h"
#include "envoy/server/factory_context.h"

#include "source/common/common/logger.h"

Expand Down
13 changes: 12 additions & 1 deletion cilium/conntrack.cc
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
#include "conntrack.h"

#include <arpa/inet.h>
#include <netinet/in.h>
#include <string.h>

#include <cstdint>
#include <memory>
#include <mutex>
#include <string>
#include <utility>

#include "envoy/common/platform.h"
#include "envoy/network/address.h"

#include "source/common/common/logger.h"
#include "source/common/common/utility.h"
#include "source/common/network/address_impl.h"

#include "absl/container/flat_hash_map.h"
#include "absl/container/flat_hash_set.h"
#include "absl/numeric/int128.h"
#include "cilium/bpf.h"
#include "linux/bpf.h"
#include "linux/type_mapper.h"

namespace Envoy {
namespace Cilium {
Expand Down
5 changes: 4 additions & 1 deletion cilium/conntrack.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#pragma once

#include <cstddef>
#include <cstdint>
#include <functional>
#include <memory>
#include <mutex>
#include <string>

#include "envoy/network/address.h"
Expand All @@ -11,7 +14,7 @@

#include "absl/container/flat_hash_map.h"
#include "absl/container/flat_hash_set.h"
#include "bpf.h"
#include "cilium/bpf.h"

namespace std {
template <> class hash<const string> {
Expand Down
32 changes: 28 additions & 4 deletions cilium/grpc_subscription.cc
Original file line number Diff line number Diff line change
@@ -1,15 +1,39 @@
#include "cilium/grpc_subscription.h"

#include <fmt/format.h>

#include <chrono>
#include <memory>
#include <string>
#include <utility>
#include <vector>

#include "envoy/annotations/resource.pb.h"
#include "envoy/common/exception.h"
#include "envoy/common/random_generator.h"
#include "envoy/config/core/v3/config_source.pb.h"
#include "envoy/config/custom_config_validators.h"
#include "envoy/config/subscription.h"

#include "source/common/config/type_to_endpoint.h"
#include "envoy/config/subscription_factory.h"
#include "envoy/event/dispatcher.h"
#include "envoy/local_info/local_info.h"
#include "envoy/stats/scope.h"
#include "envoy/upstream/cluster_manager.h"

#include "source/common/common/assert.h"
#include "source/common/common/backoff_strategy.h"
#include "source/common/config/utility.h"
#include "source/common/grpc/common.h"
#include "source/common/protobuf/protobuf.h"
#include "source/extensions/config_subscription/grpc/grpc_mux_context.h"
#include "source/extensions/config_subscription/grpc/grpc_mux_impl.h"
#include "source/extensions/config_subscription/grpc/grpc_subscription_impl.h"

#include "absl/container/flat_hash_map.h"
#include "absl/status/statusor.h"
#include "absl/strings/match.h"
#include "absl/strings/string_view.h"
#include "absl/types/optional.h"
#include "google/protobuf/descriptor.h"
#include "google/protobuf/repeated_ptr_field.h"

namespace Envoy {
namespace Cilium {
Expand Down
11 changes: 8 additions & 3 deletions cilium/grpc_subscription.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
#pragma once

#include "envoy/config/grpc_mux.h"
#include <chrono>
#include <memory>
#include <string>

#include "envoy/common/random_generator.h"
#include "envoy/config/core/v3/config_source.pb.h"
#include "envoy/config/subscription.h"
#include "envoy/config/xds_resources_delegate.h"
#include "envoy/event/dispatcher.h"
#include "envoy/grpc/async_client.h"
#include "envoy/local_info/local_info.h"
#include "envoy/stats/scope.h"
#include "envoy/upstream/cluster_manager.h"

#include "source/extensions/config_subscription/grpc/grpc_mux_context.h"
#include "source/extensions/config_subscription/grpc/grpc_mux_impl.h"
#include "source/extensions/config_subscription/grpc/grpc_subscription_impl.h"

Expand Down
15 changes: 15 additions & 0 deletions cilium/health_check_sink.cc
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
#include "cilium/health_check_sink.h"

#include <map>
#include <memory>
#include <string>

#include "envoy/common/time.h"
#include "envoy/data/core/v3/health_check_event.pb.h"
#include "envoy/registry/registry.h"
#include "envoy/server/health_checker_config.h"
#include "envoy/upstream/health_check_event_sink.h"

#include "source/common/common/lock_guard.h"
#include "source/common/common/logger.h"
#include "source/common/common/thread.h"
#include "source/common/protobuf/utility.h"

#include "cilium/api/health_check_sink.pb.h"
#include "cilium/uds_client.h"
#include "google/protobuf/any.pb.h"

namespace Envoy {
namespace Cilium {

Expand Down
14 changes: 13 additions & 1 deletion cilium/health_check_sink.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
#pragma once

#include <map>
#include <memory>
#include <string>

#include "envoy/common/time.h"
#include "envoy/data/core/v3/health_check_event.pb.h"
#include "envoy/server/health_checker_config.h"
#include "envoy/upstream/health_check_event_sink.h"

#include "source/common/common/thread.h"
#include "source/common/protobuf/protobuf.h"

#include "absl/base/thread_annotations.h"
#include "cilium/api/health_check_sink.pb.h"
#include "cilium/api/health_check_sink.pb.validate.h"
#include "cilium/api/health_check_sink.pb.validate.h" // IWYU pragma: keep
#include "cilium/uds_client.h"
#include "google/protobuf/any.pb.h"

namespace Envoy {
namespace Cilium {
Expand Down
29 changes: 24 additions & 5 deletions cilium/host_map.cc
Original file line number Diff line number Diff line change
@@ -1,11 +1,30 @@
#include "cilium/host_map.h"

#include <string>
#include <unordered_set>

#include "source/common/config/utility.h"
#include "source/common/protobuf/protobuf.h"
#include <arpa/inet.h>
#include <fmt/format.h>
#include <sys/socket.h>

#include <cstdint>
#include <cstring>
#include <memory>
#include <string>
#include <utility>
#include <vector>

#include "envoy/common/exception.h"
#include "envoy/config/subscription.h"
#include "envoy/event/dispatcher.h"
#include "envoy/server/factory_context.h"
#include "envoy/thread_local/thread_local.h"
#include "envoy/thread_local/thread_local_object.h"

#include "source/common/common/logger.h"
#include "source/common/common/macros.h"

#include "absl/numeric/int128.h"
#include "absl/status/status.h"
#include "absl/strings/string_view.h"
#include "cilium/api/nphds.pb.h"
#include "cilium/grpc_subscription.h"

namespace Envoy {
Expand Down
Loading

0 comments on commit 77609f3

Please sign in to comment.