Skip to content

Commit

Permalink
Merge pull request #37 from dynatrace-oss/fix_failing_rtt_offset
Browse files Browse the repository at this point in the history
Fix failing rtt offset
  • Loading branch information
pawsten authored Nov 25, 2024
2 parents 3578c9f + 242182d commit e930b6d
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 24 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
set(CMAKE_VERBOSE_MAKEFILE TRUE)
set(CMAKE_CXX_EXTENSIONS FALSE)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

if(DEFINED CONAN_DEPS)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
Expand Down
6 changes: 3 additions & 3 deletions bpf_program/probes/connections.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ int kretprobe__tcp_v4_connect(struct pt_regs *ctx)
}

status = bpf_map_lookup_elem(&nettracer_status, &zero);
if (status == NULL || status->state != GUESS_STATE_READY) {
if (status == NULL) {
return 0;
}

Expand Down Expand Up @@ -151,7 +151,7 @@ int kretprobe__inet_csk_accept(struct pt_regs *ctx)
return 0;

status = bpf_map_lookup_elem(&nettracer_status, &zero);
if (status == NULL || status->state != GUESS_STATE_READY) {
if (status == NULL) {
return 0;
}

Expand Down Expand Up @@ -219,7 +219,7 @@ int kprobe__tcp_close(struct pt_regs *ctx)
sk = (struct sock *) PT_REGS_PARM1(ctx);

status = bpf_map_lookup_elem(&nettracer_status, &zero);
if (status == NULL || status->state != GUESS_STATE_READY) {
if (status == NULL) {
return 0;
}

Expand Down
6 changes: 3 additions & 3 deletions bpf_program/probes/metrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ static int send_metric(struct sock* sk, int32_t bytes_sent) {
struct guess_status_t* status;
uint32_t zero = 0;
status = bpf_map_lookup_elem(&nettracer_status, &zero);
if (status == NULL || status->state != GUESS_STATE_READY) {
if (status == NULL) {
return 0;
}

Expand Down Expand Up @@ -96,7 +96,7 @@ int kprobe__tcp_cleanup_rbuf(struct pt_regs* ctx) {
struct guess_status_t *status;
uint32_t zero = 0;
status = bpf_map_lookup_elem(&nettracer_status, &zero);
if (status == NULL || status->state != GUESS_STATE_READY) {
if (status == NULL) {
return 0;
}

Expand Down Expand Up @@ -137,7 +137,7 @@ int kprobe__tcp_retransmit_skb(struct pt_regs* ctx) {
struct guess_status_t *status;
uint32_t zero = 0;
status = bpf_map_lookup_elem(&nettracer_status, &zero);
if (status == NULL || status->state != GUESS_STATE_READY) {
if (status == NULL) {
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion bpf_program/tuples_utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ static bool check_family(struct sock *sk, uint16_t expected_family) {
family = 0;

status = bpf_map_lookup_elem(&nettracer_status, &zero);
if (status == NULL || status->state != GUESS_STATE_READY) {
if (status == NULL) {
return 0;
}

Expand Down
28 changes: 12 additions & 16 deletions libnettracer/src/offsetguess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ bool OffsetGuessing::makeGuessingAttempt(int status_fd) {
// which in turn are called in kretprobe tcp_v(4|6)_connect

uint64_t pid_tgid = (uint64_t)getpid() << 32 | syscall(SYS_gettid);
logger->debug("guess thread pid: {:d}", pid_tgid);
logger->trace("guess thread pid: {:d}", pid_tgid);

// prepare server ipv4 and client ipv6 on this thread
localsock = startLocalSock();
Expand Down Expand Up @@ -107,7 +107,6 @@ bool OffsetGuessing::makeGuessingAttempt(int status_fd) {

// limit how many failed attempts at communicating with the BPF side are accepted
int maxRetries = 100;

unsigned rttCurrentAttempts = 0;
unsigned rttCurrentReps = 0;

Expand Down Expand Up @@ -208,13 +207,14 @@ bool OffsetGuessing::makeGuessingAttempt(int status_fd) {
return false;
}
}
logger->debug("offsets status: {:d}", status.what);
return true;
}

template<typename T>
void OffsetGuessing::guessSimpleField(T& statusValue, const T& expectedValue, uint16_t& offset, guess_status_t& status, const std::string& fieldStr, const guess_field& next) {
if (statusValue == expectedValue) {
logger->debug("{} offset: {:#010x}", fieldStr, offset);
logger->info("{} offset: {:#010x}", fieldStr, offset);
status.what = next;
}
else {
Expand All @@ -226,7 +226,7 @@ void OffsetGuessing::guessSimpleField(T& statusValue, const T& expectedValue, ui

void OffsetGuessing::guessNetns() {
if (status.netns == expected.netns) {
logger->debug("Network namespace offset: {:#010x}", status.offset_netns);
logger->info("Network namespace offset: {:#010x}", status.offset_netns);
status.what = GUESS_FIELD_DADDR_IPV6;
} else {
++status.offset_ino;
Expand Down Expand Up @@ -264,28 +264,23 @@ bool OffsetGuessing::guessRTT(unsigned& currentAttempts, unsigned& currentReps,
const unsigned maxAttempts = 10; // that many offsets may be verified
const unsigned requiredReps = 3; // value at an offset must match with the expected value at least that many times in a row

if (status.rtt == expected.rtt && status.rtt_var == expected.rtt_var) {
if (status.rtt == expected.rtt) {
if (++currentReps == requiredReps) {
logger->debug("RTT offset: {:#010x}", status.offset_rtt);
logger->debug("RTT var offset: {:#010x}", status.offset_rtt_var);
logger->info("RTT offset: {:#010x}", status.offset_rtt);
logger->info("RTT var offset: {:#010x}", status.offset_rtt_var);
status.state = GUESS_STATE_READY;
} else {
// reload expected RTT
if (!localsock->stopClient() || !localsock->startClient()) {
logger->error("Couldn't restart client for RTT guessing");
return false;
}
try {
auto expectedOpt{getExpectedValues(skipIPv6)};
if (!expectedOpt) {
return false;
}
expected = *expectedOpt;
}
catch (const std::runtime_error& ex) {
logger->error(ex.what());
auto expectedOpt{getExpectedValues(skipIPv6)};
if (!expectedOpt) {
return false;
}
logger->debug("Updating expected RTT: {:d},{:d} -> {:d},{:d} ", expected.rtt, expected.rtt_var, expectedOpt->rtt, expectedOpt->rtt_var);
expected = *expectedOpt;
status.rtt = expected.rtt;
status.rtt_var = expected.rtt_var;
status.state = GUESS_STATE_CHECKING;
Expand All @@ -307,6 +302,7 @@ bool OffsetGuessing::guessRTT(unsigned& currentAttempts, unsigned& currentReps,
status.rtt = expected.rtt;
status.rtt_var = expected.rtt_var;
status.state = GUESS_STATE_CHECKING;
logger->trace("current RTT offset: {:d}", status.offset_rtt);
}
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion version.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=1.1.10
version=1.1.11

0 comments on commit e930b6d

Please sign in to comment.