-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathveth_drops.py
executable file
·61 lines (48 loc) · 1.37 KB
/
veth_drops.py
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/python
# Why drop? http://elixir.free-electrons.com/linux/latest/source/drivers/net/veth.c#L106
from __future__ import print_function
from bcc import BPF
bpf_text = """
#include <uapi/linux/ptrace.h>
#include <net/sock.h>
#include <bcc/proto.h>
int kretprobe__dev_forward_skb(struct pt_regs *ctx)
{
int ret = PT_REGS_RC(ctx);
if(ret != NET_RX_SUCCESS) {
bpf_trace_printk("ret_dev_forward_skb %d\\n", ret);
}
return 0;
}
int kretprobe__is_skb_forwardable(struct pt_regs *ctx)
{
bool ret = PT_REGS_RC(ctx);
if(!ret) {
bpf_trace_printk("ret_is_skb_forwardable FALSE %d\\n", ret);
}
return 0;
}
// watch for -ENOMEM
// http://elixir.free-electrons.com/linux/latest/source/include/uapi/asm-generic/errno-base.h#L15
int kretprobe__skb_copy_ubufs(struct pt_regs *ctx)
{
int ret = PT_REGS_RC(ctx);
if(ret != 0) {
bpf_trace_printk("ret_skb_copy_ubufs %d\\n", ret);
}
return 0;
}
// via http://elixir.free-electrons.com/linux/latest/source/net/core/dev.c#L3781
int kretprobe__enqueue_to_backlog(struct pt_regs *ctx)
{
int ret = PT_REGS_RC(ctx);
if(ret == NET_RX_DROP) {
bpf_trace_printk("ret_enqueue_to_backlog NET_RX_DROP %d\\n", ret);
}
return 0;
}
"""
b = BPF(text=bpf_text)
while 1:
(task, pid, cpu, flags, ts, msg) = b.trace_fields()
print("%-6d %-12.12s %16s" % (pid, task, msg))