Skip to content

Commit

Permalink
Merge pull request #28 from dynatrace-oss/ports_reading_bugfix
Browse files Browse the repository at this point in the history
Ports reading bugfix
  • Loading branch information
pawsten authored Nov 13, 2023
2 parents ba41e1f + 0ae76d3 commit c700759
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 33 deletions.
36 changes: 4 additions & 32 deletions bpf_program/metrics_utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,7 @@

__attribute__((always_inline))
static void update_stats(void *tuple, enum protocol proto, uint64_t sent, uint64_t received) {
void *map = NULL;
if (proto == IPV4) {
map = &stats_ipv4;
}
else if (proto == IPV6) {
map = &stats_ipv6;
}
else {
return;
}
void *map = (proto == IPV4) ? &stats_ipv4 : &stats_ipv6;

struct stats_t empty = { 0 };
bpf_map_update_elem(map, tuple, &empty, BPF_NOEXIST);
Expand All @@ -37,17 +28,7 @@ static void update_stats(void *tuple, enum protocol proto, uint64_t sent, uint64

__attribute__((always_inline))
static void update_tcp_stats(void *tuple, enum protocol proto, struct guess_status_t *status, struct sock *sk) {
void *map = NULL;
if (proto == IPV4) {
map = &tcp_stats_ipv4;
}
else if (proto == IPV6) {
map = &tcp_stats_ipv6;
}
else {
return;
}

void *map = (proto == IPV4) ? &tcp_stats_ipv4 : &tcp_stats_ipv6;
struct tcp_stats_t empty = { 0 };
bpf_map_update_elem(map, tuple, &empty, BPF_NOEXIST);
struct tcp_stats_t* stats = bpf_map_lookup_elem(map, tuple);
Expand All @@ -70,18 +51,9 @@ static void update_tcp_stats(void *tuple, enum protocol proto, struct guess_stat

__attribute__((always_inline))
static void maybe_fix_missing_connection_tuple(enum protocol proto, void* tuple) {
void *map = NULL;
if (proto == IPV4) {
map = &tuplepid_ipv4;
}
else if (proto == IPV6) {
map = &tuplepid_ipv6;
}
else {
return;
}

void *map = (proto == IPV4) ? &tuplepid_ipv4 : &tuplepid_ipv6;
uint64_t pid = bpf_get_current_pid_tgid();

if ((pid >> 32) <= 10) { // probe activated with insufficient context
return;
}
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 @@ -91,7 +91,7 @@ static int read_ipv4_tuple(struct ipv4_tuple_t *tuple, struct guess_status_t *st

tuple->saddr = saddr;
tuple->daddr = daddr;
tuple->sport = sport; // TODO pjuszczyk Check if sport doesn't need to be flipped in some cases
tuple->sport = sport;
tuple->dport = ntohs(dport);
tuple->netns = net_ns_inum;

Expand Down

0 comments on commit c700759

Please sign in to comment.