Skip to content

Commit 2a06ef4

Browse files
authored
Improve tracking of connectionless UDP syscalls (#1741)
1 parent 5518702 commit 2a06ef4

15 files changed

+1110
-5
lines changed

.editorconfig

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ trim_trailing_whitespace = true
1010
indent_style = space
1111
indent_size = 2
1212

13+
[integration-tests/**.c]
14+
indent_style = space
15+
indent_size = 2
16+
1317
[*.sh]
1418
indent_style = space
1519
indent_size = 4

collector/lib/CollectorConfig.cpp

+12-2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ BoolEnvVar use_podman_ce("ROX_COLLECTOR_CE_USE_PODMAN", false);
6060

6161
BoolEnvVar enable_introspection("ROX_COLLECTOR_INTROSPECTION_ENABLE", false);
6262

63+
BoolEnvVar track_send_recv("ROX_COLLECTOR_TRACK_SEND_RECV", false);
64+
6365
// Collector arguments alternatives
6466
StringEnvVar log_level("ROX_COLLECTOR_LOG_LEVEL");
6567
IntEnvVar scrape_interval("ROX_COLLECTOR_SCRAPE_INTERVAL");
@@ -103,9 +105,16 @@ void CollectorConfig::InitCollectorConfig(CollectorArgs* args) {
103105
use_docker_ce_ = use_docker_ce.value();
104106
use_podman_ce_ = use_podman_ce.value();
105107
enable_introspection_ = enable_introspection.value();
108+
track_send_recv_ = track_send_recv.value();
106109

107110
for (const auto& syscall : kSyscalls) {
108-
syscalls_.push_back(syscall);
111+
syscalls_.emplace_back(syscall);
112+
}
113+
114+
if (track_send_recv_) {
115+
for (const auto& syscall : kSendRecvSyscalls) {
116+
syscalls_.emplace_back(syscall);
117+
}
109118
}
110119

111120
// Get hostname
@@ -454,7 +463,8 @@ std::ostream& operator<<(std::ostream& os, const CollectorConfig& c) {
454463
<< ", set_import_users:" << c.ImportUsers()
455464
<< ", collect_connection_status:" << c.CollectConnectionStatus()
456465
<< ", enable_detailed_metrics:" << c.EnableDetailedMetrics()
457-
<< ", enable_external_ips:" << c.EnableExternalIPs();
466+
<< ", enable_external_ips:" << c.EnableExternalIPs()
467+
<< ", track_send_recv:" << c.TrackingSendRecv();
458468
}
459469

460470
// Returns size of ring buffers to be allocated.

collector/lib/CollectorConfig.h

+10
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ class CollectorConfig {
4848
#endif
4949
"vfork",
5050
};
51+
static constexpr const char* kSendRecvSyscalls[] = {
52+
"sendto",
53+
"sendmsg",
54+
"sendmmsg",
55+
"recvfrom",
56+
"recvmsg",
57+
"recvmmsg",
58+
};
5159
static const UnorderedSet<L4ProtoPortPair> kIgnoredL4ProtoPortPairs;
5260
static constexpr bool kEnableProcessesListeningOnPorts = true;
5361

@@ -82,6 +90,7 @@ class CollectorConfig {
8290
bool UseDockerCe() const { return use_docker_ce_; }
8391
bool UsePodmanCe() const { return use_podman_ce_; }
8492
bool IsIntrospectionEnabled() const { return enable_introspection_; }
93+
bool TrackingSendRecv() const { return track_send_recv_; }
8594
const std::vector<double>& GetConnectionStatsQuantiles() const { return connection_stats_quantiles_; }
8695
double GetConnectionStatsError() const { return connection_stats_error_; }
8796
unsigned int GetConnectionStatsWindow() const { return connection_stats_window_; }
@@ -122,6 +131,7 @@ class CollectorConfig {
122131
bool use_docker_ce_;
123132
bool use_podman_ce_;
124133
bool enable_introspection_;
134+
bool track_send_recv_;
125135
std::vector<double> connection_stats_quantiles_;
126136
double connection_stats_error_;
127137
unsigned int connection_stats_window_;

collector/lib/NetworkSignalHandler.cpp

+34-1
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,25 @@ EventMap<Modifier> modifiers = {
2424
{"connect<", Modifier::ADD},
2525
{"accept<", Modifier::ADD},
2626
{"getsockopt<", Modifier::ADD},
27+
{"sendto<", Modifier::ADD},
28+
{"sendto>", Modifier::ADD},
29+
{"sendmsg<", Modifier::ADD},
30+
{"sendmsg>", Modifier::ADD},
31+
{"sendmmsg<", Modifier::ADD},
32+
{"recvfrom<", Modifier::ADD},
33+
{"recvfrom>", Modifier::ADD},
34+
{"recvmsg<", Modifier::ADD},
35+
{"recvmsg>", Modifier::ADD},
36+
{"recvmmsg<", Modifier::ADD},
37+
{"recvmmsg>", Modifier::ADD},
2738
},
2839
Modifier::INVALID,
2940
};
3041

3142
} // namespace
3243

3344
NetworkSignalHandler::NetworkSignalHandler(sinsp* inspector, std::shared_ptr<ConnectionTracker> conn_tracker, system_inspector::Stats* stats)
34-
: event_extractor_(std::make_unique<system_inspector::EventExtractor>()), conn_tracker_(std::move(conn_tracker)), stats_(stats), collect_connection_status_(true) {
45+
: event_extractor_(std::make_unique<system_inspector::EventExtractor>()), conn_tracker_(std::move(conn_tracker)), stats_(stats), collect_connection_status_(true), track_send_recv_(false) {
3546
event_extractor_->Init(inspector);
3647
}
3748

@@ -141,6 +152,28 @@ SignalHandler::Result NetworkSignalHandler::HandleSignal(sinsp_evt* evt) {
141152
}
142153

143154
std::vector<std::string> NetworkSignalHandler::GetRelevantEvents() {
155+
if (track_send_recv_) {
156+
return {
157+
"close<",
158+
"shutdown<",
159+
"connect<",
160+
"accept<",
161+
"getsockopt<",
162+
"sendto<",
163+
"sendto>",
164+
"sendmsg<",
165+
"sendmsg>",
166+
"sendmmsg<",
167+
"recvfrom<",
168+
"recvfrom>",
169+
"recvmsg<",
170+
"recvmsg>",
171+
"recvmmsg<",
172+
"recvmmsg>",
173+
"recvmsg<",
174+
"recvmsg>",
175+
};
176+
}
144177
return {"close<", "shutdown<", "connect<", "accept<", "getsockopt<"};
145178
}
146179

collector/lib/NetworkSignalHandler.h

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class NetworkSignalHandler final : public SignalHandler {
2929
bool Stop() override;
3030

3131
void SetCollectConnectionStatus(bool collect_connection_status) { collect_connection_status_ = collect_connection_status; }
32+
void SetTrackSendRecv(bool track_send_recv) { track_send_recv_ = track_send_recv; }
3233

3334
private:
3435
std::optional<Connection> GetConnection(sinsp_evt* evt);
@@ -38,6 +39,7 @@ class NetworkSignalHandler final : public SignalHandler {
3839
system_inspector::Stats* stats_;
3940

4041
bool collect_connection_status_;
42+
bool track_send_recv_;
4143
};
4244

4345
} // namespace collector

collector/lib/system-inspector/Service.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ void Service::Init(const CollectorConfig& config, std::shared_ptr<ConnectionTrac
4646
auto network_signal_handler_ = MakeUnique<NetworkSignalHandler>(inspector_.get(), conn_tracker, &userspace_stats_);
4747

4848
network_signal_handler_->SetCollectConnectionStatus(config.CollectConnectionStatus());
49+
network_signal_handler_->SetTrackSendRecv(config.TrackingSendRecv());
4950

5051
AddSignalHandler(std::move(network_signal_handler_));
5152
}

integration-tests/container/QA_TAG

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.2.1
1+
2.0.0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
FROM fedora:40 AS builder
2+
3+
WORKDIR /tmp
4+
COPY udp-server.c .
5+
COPY udp-client.c .
6+
7+
RUN dnf install -y gcc && \
8+
gcc udp-server.c -Wall -Wpedantic -Werror -o udp-server && \
9+
gcc udp-client.c -Wall -Wpedantic -Werror -o udp-client
10+
11+
FROM fedora:40
12+
13+
COPY --from=builder /tmp/udp-server /usr/local/bin
14+
COPY --from=builder /tmp/udp-client /usr/local/bin
15+
EXPOSE 9090
16+
17+
ENTRYPOINT ["udp-server"]
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
BASE_PATH = .
2+
include ../Makefile-constants.mk
3+
4+
.DEFAULT_GOAL = all
5+
6+
COLLECTOR_QA_UDP_TAG := udp
7+
8+
ifneq ($(COLLECTOR_QA_TAG),)
9+
COLLECTOR_QA_UDP_TAG=udp-$(COLLECTOR_QA_TAG)
10+
endif
11+
12+
.PHONY: all
13+
all: build
14+
15+
.PHONY: build
16+
build:
17+
@docker buildx build --load --platform ${PLATFORM} \
18+
-t quay.io/rhacs-eng/qa-multi-arch:$(COLLECTOR_QA_UDP_TAG) \
19+
-f Containerfile .
20+
21+
.PHONY: build-and-push
22+
build-and-push:
23+
@docker buildx build --push --platform ${PLATFORM} \
24+
-t quay.io/rhacs-eng/qa-multi-arch:$(COLLECTOR_QA_UDP_TAG) \
25+
-f Containerfile .

0 commit comments

Comments
 (0)