forked from cloudflare/ebpf_exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtcp-syn-backlog-exp2zero.bpf.c
More file actions
41 lines (32 loc) · 903 Bytes
/
tcp-syn-backlog-exp2zero.bpf.c
File metadata and controls
41 lines (32 loc) · 903 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <vmlinux.h>
#include <bpf/bpf_tracing.h>
#include <bpf/bpf_core_read.h>
#include "maps.bpf.h"
// 17 buckets, max range is 32k..64k
#define MAX_BUCKET_SLOT 17
struct key_t {
u64 bucket;
};
struct {
__uint(type, BPF_MAP_TYPE_HASH);
__uint(max_entries, MAX_BUCKET_SLOT + 2);
__type(key, struct key_t);
__type(value, u64);
} tcp_syn_backlog SEC(".maps");
static int do_count(u64 backlog)
{
struct key_t key = {};
increment_exp2zero_histogram(&tcp_syn_backlog, key, backlog, MAX_BUCKET_SLOT);
return 0;
}
SEC("kprobe/tcp_v4_syn_recv_sock")
int BPF_KPROBE(kprobe__tcp_v4_syn_recv_sock, struct sock *sk)
{
return do_count(BPF_CORE_READ(sk, sk_ack_backlog));
}
SEC("kprobe/tcp_v6_syn_recv_sock")
int BPF_KPROBE(kprobe__tcp_v6_syn_recv_sock, struct sock *sk)
{
return do_count(BPF_CORE_READ(sk, sk_ack_backlog));
}
char LICENSE[] SEC("license") = "GPL";